#include <syslog.h>
#include <sys/time.h>
#include <mISDNuser/isdn_debug.h>
#include "isdn_lib_intern.h"
#include "isdn_lib.h"
#include <mISDNuser/net_l2.h>
#include <mISDNuser/tone.h>
#include <unistd.h>
#include <semaphore.h>
#include <pthread.h>
#include <signal.h>
Go to the source code of this file.
Data Structures | |
struct | misdn_lib |
Defines | |
#define | ECHOCAN_OFF 124 |
#define | ECHOCAN_ON 123 |
#define | ISDN_PID_L3_B_USER 0x430000ff |
#define | ISDN_PID_L4_B_USER 0x440000ff |
#define | MAXPROCS 0x100 |
#define | MISDN_DEBUG 0 |
#define | MISDN_DSP |
#define | MISDN_GEN_SILENCE |
#define | MISDN_IBUF_SIZE 512 |
#define | RETURN(a, b) {retval=a; goto b;} |
#define | TONE_ALERT_CNT 41 |
#define | TONE_ALERT_SILENCE_CNT 200 |
#define | TONE_BUSY_CNT 20 |
#define | TONE_BUSY_SILENCE_CNT 48 |
Enumerations | |
enum | global_states { MISDN_INITIALIZING, MISDN_INITIALIZED } |
Functions | |
static void | bc_next_state_change (struct misdn_bchannel *bc, enum bchannel_state state) |
char * | bc_state2str (enum bchannel_state state) |
void | bc_state_change (struct misdn_bchannel *bc, enum bchannel_state state) |
int | bchdev_echocancel_activate (struct misdn_bchannel *dev) |
void | bchdev_echocancel_deactivate (struct misdn_bchannel *dev) |
static char * | bearer2str (int cap) |
static int | clean_up_bc (struct misdn_bchannel *bc) |
static void | clear_l3 (struct misdn_stack *stack) |
static msg_t * | create_l2msg (int prim, int dinfo, int size) |
msg_t * | create_l3msg (int prim, int mt, int dinfo, int size, int ntmode) |
static int | create_process (int midev, struct misdn_bchannel *bc) |
static int | do_tone (struct misdn_bchannel *bc, int len) |
static void | dump_chan_list (struct misdn_stack *stack) |
void | ec_chunk (struct misdn_bchannel *bc, unsigned char *rxchunk, unsigned char *txchunk, int chunk_size) |
static void | empty_bc (struct misdn_bchannel *bc) |
static int | empty_chan_in_stack (struct misdn_stack *stack, int channel) |
static char * | fac2str (enum FacFunction func) |
static msg_t * | fetch_msg (int midev) |
static struct misdn_bchannel * | find_bc_by_addr (unsigned long addr) |
static struct misdn_bchannel * | find_bc_by_channel (int port, int channel) |
misdn_bchannel * | find_bc_by_confid (unsigned long confid) |
misdn_bchannel * | find_bc_by_l3id (struct misdn_stack *stack, unsigned long l3id) |
static struct misdn_bchannel * | find_bc_by_masked_l3id (struct misdn_stack *stack, unsigned long l3id, unsigned long mask) |
static struct misdn_bchannel * | find_bc_holded (struct misdn_stack *stack) |
static int | find_free_chan_in_stack (struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec) |
static struct misdn_stack * | find_stack_by_addr (int addr) |
static struct misdn_stack * | find_stack_by_mgr (manager_t *mgr_nt) |
static struct misdn_stack * | find_stack_by_port (int port) |
static char * | flip_buf_bits (char *buf, int len) |
misdn_stack * | get_misdn_stack (void) |
void | get_show_stack_details (int port, char *buf) |
misdn_stack * | get_stack_by_bc (struct misdn_bchannel *bc) |
static int | handle_bchan (msg_t *msg) |
static int | handle_cr (struct misdn_stack *stack, iframe_t *frm) |
static int | handle_err (msg_t *msg) |
static int | handle_event (struct misdn_bchannel *bc, enum event_e event, iframe_t *frm) |
static int | handle_event_nt (void *dat, void *arg) |
static int | handle_frm (msg_t *msg) |
static int | handle_frm_nt (msg_t *msg) |
static int | handle_l1 (msg_t *msg) |
static int | handle_l2 (msg_t *msg) |
static int | handle_mgmt (msg_t *msg) |
static int | handle_timers (msg_t *msg) |
int | init_bc (struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, int port, int bidx, char *msn, int firsttime) |
static void | init_flip_bits (void) |
void | isdn_lib_stop_dtmf (struct misdn_bchannel *bc) |
void | isdn_lib_update_ec (struct misdn_bchannel *bc) |
void | isdn_lib_update_rxgain (struct misdn_bchannel *bc) |
void | isdn_lib_update_txgain (struct misdn_bchannel *bc) |
void | manager_bchannel_activate (struct misdn_bchannel *bc) |
void | manager_bchannel_cleanup (struct misdn_bchannel *bc) |
void | manager_bchannel_deactivate (struct misdn_bchannel *bc) |
void | manager_bchannel_setup (struct misdn_bchannel *bc) |
void | manager_clean_bc (struct misdn_bchannel *bc) |
void | manager_ec_disable (struct misdn_bchannel *bc) |
void | manager_ec_enable (struct misdn_bchannel *bc) |
static void | manager_event_handler (void *arg) |
misdn_bchannel * | manager_find_bc_by_pid (int pid) |
misdn_bchannel * | manager_find_bc_holded (struct misdn_bchannel *bc) |
char * | manager_isdn_get_info (enum event_e event) |
int | manager_isdn_handler (iframe_t *frm, msg_t *msg) |
void | manager_ph_control (struct misdn_bchannel *bc, int c1, int c2) |
void | manager_ph_control_block (struct misdn_bchannel *bc, int c1, void *c2, int c2_len) |
int | misdn_cap_is_speech (int cap) |
void | misdn_dump_chanlist () |
int | misdn_inband_avail (struct misdn_bchannel *bc) |
void | misdn_join_conf (struct misdn_bchannel *bc, int conf_id) |
void | misdn_lib_bridge (struct misdn_bchannel *bc1, struct misdn_bchannel *bc2) |
void | misdn_lib_destroy () |
void | misdn_lib_echo (struct misdn_bchannel *bc, int onoff) |
misdn_bchannel * | misdn_lib_get_free_bc (int port, int channel, int inout, int dec) |
static int | misdn_lib_get_l1_down (struct misdn_stack *stack) |
static int | misdn_lib_get_l1_up (struct misdn_stack *stack) |
static int | misdn_lib_get_l2_down (struct misdn_stack *stack) |
int | misdn_lib_get_l2_up (struct misdn_stack *stack) |
int | misdn_lib_get_maxchans (int port) |
int | misdn_lib_get_port_down (int port) |
int | misdn_lib_get_port_info (int port) |
int | misdn_lib_get_port_up (int port) |
static int | misdn_lib_get_short_status (struct misdn_stack *stack) |
int | misdn_lib_init (char *portlist, struct misdn_lib_iface *iface, void *user_data) |
int | misdn_lib_is_port_blocked (int port) |
int | misdn_lib_is_ptp (int port) |
static void | misdn_lib_isdn_event_catcher (void *arg) |
void | misdn_lib_isdn_l1watcher (int port) |
void | misdn_lib_log_ies (struct misdn_bchannel *bc) |
int | misdn_lib_maxports_get () |
void | misdn_lib_nt_debug_init (int flags, char *file) |
void | misdn_lib_nt_keepcalls (int kc) |
int | misdn_lib_pid_restart (int pid) |
int | misdn_lib_port_block (int port) |
int | misdn_lib_port_is_nt (int port) |
int | misdn_lib_port_is_pri (int port) |
int | misdn_lib_port_restart (int port) |
int | misdn_lib_port_unblock (int port) |
int | misdn_lib_port_up (int port, int check) |
void | misdn_lib_reinit_nt_stack (int port) |
void | misdn_lib_release (struct misdn_bchannel *bc) |
int | misdn_lib_send_event (struct misdn_bchannel *bc, enum event_e event) |
int | misdn_lib_send_restart (int port, int channel) |
void | misdn_lib_send_tone (struct misdn_bchannel *bc, enum tone_e tone) |
void | misdn_lib_setup_bc (struct misdn_bchannel *bc) |
void | misdn_lib_split_bridge (struct misdn_bchannel *bc1, struct misdn_bchannel *bc2) |
void | misdn_lib_tone_generator_start (struct misdn_bchannel *bc) |
void | misdn_lib_tone_generator_stop (struct misdn_bchannel *bc) |
void | misdn_lib_transfer (struct misdn_bchannel *holded_bc) |
int | misdn_lib_tx2misdn_frm (struct misdn_bchannel *bc, void *data, int len) |
void | misdn_make_dummy (struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel) |
void | misdn_send_lock (struct misdn_bchannel *bc) |
void | misdn_send_unlock (struct misdn_bchannel *bc) |
void | misdn_split_conf (struct misdn_bchannel *bc, int conf_id) |
void | misdn_tx_jitter (struct misdn_bchannel *bc, int len) |
static void | prepare_bc (struct misdn_bchannel *bc, int channel) |
int | queue_cleanup_bc (struct misdn_bchannel *bc) |
int | release_cr (struct misdn_stack *stack, mISDNuser_head_t *hh) |
static int | send_msg (int midev, struct misdn_bchannel *bc, msg_t *dmsg) |
static int | set_chan_in_stack (struct misdn_stack *stack, int channel) |
int | setup_bc (struct misdn_bchannel *bc) |
void | stack_destroy (struct misdn_stack *stack) |
void | stack_holder_add (struct misdn_stack *stack, struct misdn_bchannel *holder) |
misdn_bchannel * | stack_holder_find (struct misdn_stack *stack, unsigned long l3id) |
misdn_bchannel * | stack_holder_find_bychan (struct misdn_stack *stack, int chan) |
void | stack_holder_remove (struct misdn_stack *stack, struct misdn_bchannel *holder) |
misdn_stack * | stack_init (int midev, int port, int ptp) |
void | te_lib_destroy (int midev) |
int | te_lib_init (void) |
static int | test_inuse (struct misdn_bchannel *bc) |
Variables | |
static int | entity |
static char | flip_table [256] |
static struct misdn_lib * | glob_mgr |
static enum global_states | global_state = MISDN_INITIALIZING |
sem_t | handler_started |
isdn_msg | msgs_g [] |
static int | mypid = 1 |
static int | new_te_id = 0 |
static int | nt_err_cnt = 0 |
char | tone_425_flip [TONE_425_SIZE] |
char | tone_silence_flip [TONE_SILENCE_SIZE] |
Definition in file isdn_lib.c.
#define ECHOCAN_OFF 124 |
#define ECHOCAN_ON 123 |
#define ISDN_PID_L3_B_USER 0x430000ff |
Definition at line 236 of file isdn_lib.c.
#define ISDN_PID_L4_B_USER 0x440000ff |
Definition at line 237 of file isdn_lib.c.
#define MAXPROCS 0x100 |
#define MISDN_DEBUG 0 |
Definition at line 217 of file isdn_lib.c.
#define MISDN_DSP |
#define MISDN_GEN_SILENCE |
#define MISDN_IBUF_SIZE 512 |
#define RETURN | ( | a, | |||
b | ) | {retval=a; goto b;} |
#define TONE_ALERT_CNT 41 |
Definition at line 243 of file isdn_lib.c.
#define TONE_ALERT_SILENCE_CNT 200 |
Definition at line 244 of file isdn_lib.c.
#define TONE_BUSY_CNT 20 |
Definition at line 246 of file isdn_lib.c.
#define TONE_BUSY_SILENCE_CNT 48 |
Definition at line 247 of file isdn_lib.c.
enum global_states |
Definition at line 177 of file isdn_lib.c.
00177 { 00178 MISDN_INITIALIZING, 00179 MISDN_INITIALIZED 00180 } ;
static void bc_next_state_change | ( | struct misdn_bchannel * | bc, | |
enum bchannel_state | state | |||
) | [static] |
Definition at line 619 of file isdn_lib.c.
References bc_state2str(), cb_log, misdn_bchannel::next_bc_state, and misdn_bchannel::port.
Referenced by misdn_lib_bridge().
00620 { 00621 cb_log(5,bc->port,"BC_NEXT_STATE_CHANGE: from:%s to:%s\n", 00622 bc_state2str(bc->next_bc_state), 00623 bc_state2str(state) ); 00624 00625 bc->next_bc_state=state; 00626 }
char* bc_state2str | ( | enum bchannel_state | state | ) |
Definition at line 570 of file isdn_lib.c.
References BCHAN_ACTIVATED, BCHAN_ACTIVE, BCHAN_BRIDGE, BCHAN_BRIDGED, BCHAN_CLEAN, BCHAN_CLEAN_REQUEST, BCHAN_CLEANED, BCHAN_EMPTY, BCHAN_ERROR, BCHAN_RELEASE, BCHAN_RELEASED, BCHAN_SETUP, BCHAN_SETUPED, and s.
Referenced by bc_next_state_change(), bc_state_change(), cb_events(), handle_bchan(), handle_err(), misdn_lib_send_event(), misdn_lib_split_bridge(), misdn_lib_tx2misdn_frm(), print_bc_info(), and setup_bc().
00570 { 00571 int i; 00572 00573 struct bchan_state_s { 00574 char *n; 00575 enum bchannel_state s; 00576 } states[] = { 00577 {"BCHAN_CLEANED", BCHAN_CLEANED }, 00578 {"BCHAN_EMPTY", BCHAN_EMPTY}, 00579 {"BCHAN_SETUP", BCHAN_SETUP}, 00580 {"BCHAN_SETUPED", BCHAN_SETUPED}, 00581 {"BCHAN_ACTIVE", BCHAN_ACTIVE}, 00582 {"BCHAN_ACTIVATED", BCHAN_ACTIVATED}, 00583 {"BCHAN_BRIDGE", BCHAN_BRIDGE}, 00584 {"BCHAN_BRIDGED", BCHAN_BRIDGED}, 00585 {"BCHAN_RELEASE", BCHAN_RELEASE}, 00586 {"BCHAN_RELEASED", BCHAN_RELEASED}, 00587 {"BCHAN_CLEAN", BCHAN_CLEAN}, 00588 {"BCHAN_CLEAN_REQUEST", BCHAN_CLEAN_REQUEST}, 00589 {"BCHAN_ERROR", BCHAN_ERROR} 00590 }; 00591 00592 for (i=0; i< sizeof(states)/sizeof(struct bchan_state_s); i++) 00593 if ( states[i].s == state) 00594 return states[i].n; 00595 00596 return "UNKNOWN"; 00597 }
void bc_state_change | ( | struct misdn_bchannel * | bc, | |
enum bchannel_state | state | |||
) |
Definition at line 599 of file isdn_lib.c.
References misdn_bchannel::bc_state, bc_state2str(), BCHAN_ACTIVATED, BCHAN_BRIDGED, BCHAN_EMPTY, cb_log, misdn_bchannel::conf_id, misdn_bchannel::l3_id, misdn_join_conf(), misdn_bchannel::next_bc_state, and misdn_bchannel::port.
Referenced by clean_up_bc(), handle_bchan(), handle_frm(), init_bc(), manager_bchannel_deactivate(), misdn_join_conf(), misdn_lib_send_event(), and misdn_split_conf().
00600 { 00601 cb_log(5,bc->port,"BC_STATE_CHANGE: l3id:%x from:%s to:%s\n", 00602 bc->l3_id, 00603 bc_state2str(bc->bc_state), 00604 bc_state2str(state) ); 00605 00606 switch (state) { 00607 case BCHAN_ACTIVATED: 00608 if (bc->next_bc_state == BCHAN_BRIDGED) { 00609 misdn_join_conf(bc, bc->conf_id); 00610 bc->next_bc_state = BCHAN_EMPTY; 00611 return; 00612 } 00613 default: 00614 bc->bc_state=state; 00615 break; 00616 } 00617 }
int bchdev_echocancel_activate | ( | struct misdn_bchannel * | dev | ) |
void bchdev_echocancel_deactivate | ( | struct misdn_bchannel * | dev | ) |
static char* bearer2str | ( | int | cap | ) | [static] |
Definition at line 285 of file isdn_lib.c.
References INFO_CAPABILITY_AUDIO_3_1K, INFO_CAPABILITY_DIGITAL_RESTRICTED, INFO_CAPABILITY_DIGITAL_UNRESTRICTED, and INFO_CAPABILITY_SPEECH.
00285 { 00286 static char *bearers[]={ 00287 "Speech", 00288 "Audio 3.1k", 00289 "Unres Digital", 00290 "Res Digital", 00291 "Unknown Bearer" 00292 }; 00293 00294 switch (cap) { 00295 case INFO_CAPABILITY_SPEECH: 00296 return bearers[0]; 00297 break; 00298 case INFO_CAPABILITY_AUDIO_3_1K: 00299 return bearers[1]; 00300 break; 00301 case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: 00302 return bearers[2]; 00303 break; 00304 case INFO_CAPABILITY_DIGITAL_RESTRICTED: 00305 return bearers[3]; 00306 break; 00307 default: 00308 return bearers[4]; 00309 break; 00310 } 00311 }
static int clean_up_bc | ( | struct misdn_bchannel * | bc | ) | [static] |
Definition at line 728 of file isdn_lib.c.
References misdn_bchannel::b_stid, misdn_stack::bc, misdn_bchannel::bc_state, bc_state_change(), BCHAN_CLEANED, buff, cb_log, get_stack_by_bc(), misdn_bchannel::layer_id, manager_bchannel_deactivate(), manager_ec_disable(), misdn_stack::midev, misdn_bchannel::pid, misdn_stack::port, and misdn_bchannel::port.
Referenced by clear_l3(), handle_bchan(), handle_cr(), handle_event_nt(), handle_frm(), manager_event_handler(), misdn_lib_release(), misdn_lib_send_event(), misdn_lib_send_restart(), and misdn_lib_setup_bc().
00729 { 00730 int ret=0; 00731 unsigned char buff[32]; 00732 struct misdn_stack * stack; 00733 00734 cb_log(3, bc?bc->port:0, "$$$ CLEANUP CALLED pid:%d\n", bc?bc->pid:-1); 00735 00736 if (!bc ) return -1; 00737 stack=get_stack_by_bc(bc); 00738 00739 if (!stack) return -1; 00740 00741 switch (bc->bc_state ) { 00742 case BCHAN_CLEANED: 00743 cb_log(5, stack->port, "$$$ Already cleaned up bc with stid :%x\n", bc->b_stid); 00744 return -1; 00745 00746 default: 00747 break; 00748 } 00749 00750 cb_log(2, stack->port, "$$$ Cleaning up bc with stid :%x pid:%d\n", bc->b_stid, bc->pid); 00751 00752 manager_ec_disable(bc); 00753 00754 manager_bchannel_deactivate(bc); 00755 00756 mISDN_write_frame(stack->midev, buff, bc->layer_id|FLG_MSG_TARGET|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 00757 00758 bc->b_stid = 0; 00759 bc_state_change(bc, BCHAN_CLEANED); 00760 00761 return ret; 00762 }
static void clear_l3 | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 766 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, cb_event, clean_up_bc(), empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, global_state, and MISDN_INITIALIZED.
Referenced by handle_mgmt(), and misdn_lib_port_restart().
00767 { 00768 int i; 00769 00770 for (i=0; i<=stack->b_num; i++) { 00771 if (global_state == MISDN_INITIALIZED) { 00772 cb_event(EVENT_CLEANUP, &stack->bc[i], NULL); 00773 empty_chan_in_stack(stack,i+1); 00774 empty_bc(&stack->bc[i]); 00775 clean_up_bc(&stack->bc[i]); 00776 stack->bc[i].in_use = 0; 00777 } 00778 00779 } 00780 }
static msg_t* create_l2msg | ( | int | prim, | |
int | dinfo, | |||
int | size | |||
) | [static] |
Definition at line 344 of file isdn_lib.c.
Referenced by misdn_lib_get_l2_down(), and misdn_lib_get_l2_up().
00345 { 00346 int i = 0; 00347 msg_t *dmsg; 00348 00349 while(i < 10) 00350 { 00351 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); 00352 if (dmsg) 00353 return(dmsg); 00354 00355 if (!i) 00356 printf("cannot allocate memory, trying again...\n"); 00357 i++; 00358 usleep(300000); 00359 } 00360 printf("cannot allocate memory, system overloaded.\n"); 00361 exit(-1); 00362 }
msg_t* create_l3msg | ( | int | prim, | |
int | mt, | |||
int | dinfo, | |||
int | size, | |||
int | ntmode | |||
) |
Definition at line 366 of file isdn_lib.c.
Referenced by build_alerting(), build_connect(), build_connect_acknowledge(), build_disconnect(), build_facility(), build_hold(), build_hold_acknowledge(), build_hold_reject(), build_information(), build_notify(), build_proceeding(), build_progress(), build_release(), build_release_complete(), build_restart(), build_resume(), build_resume_acknowledge(), build_resume_reject(), build_retrieve(), build_retrieve_acknowledge(), build_retrieve_reject(), build_setup(), build_setup_acknowledge(), build_status(), build_status_enquiry(), build_suspend(), build_suspend_acknowledge(), build_suspend_reject(), build_timeout(), build_user_information(), and handle_event_nt().
00367 { 00368 int i = 0; 00369 msg_t *dmsg; 00370 Q931_info_t *qi; 00371 iframe_t *frm; 00372 00373 if (!ntmode) 00374 size = sizeof(Q931_info_t)+2; 00375 00376 while(i < 10) { 00377 if (ntmode) { 00378 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); 00379 if (dmsg) { 00380 return(dmsg); 00381 } 00382 } else { 00383 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM); 00384 if (dmsg) 00385 { 00386 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN); 00387 frm = (iframe_t *)dmsg->data; 00388 frm->prim = prim; 00389 frm->dinfo = dinfo; 00390 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN); 00391 qi->type = mt; 00392 return(dmsg); 00393 } 00394 } 00395 00396 if (!i) printf("cannot allocate memory, trying again...\n"); 00397 i++; 00398 usleep(300000); 00399 } 00400 printf("cannot allocate memory, system overloaded.\n"); 00401 exit(-1); 00402 }
static int create_process | ( | int | midev, | |
struct misdn_bchannel * | bc | |||
) | [static] |
Definition at line 898 of file isdn_lib.c.
References misdn_stack::bc, cb_log, misdn_bchannel::channel, misdn_bchannel::channel_preselected, find_free_chan_in_stack(), get_stack_by_bc(), misdn_bchannel::l3_id, MAXPROCS, misdn_stack::nt, misdn_stack::port, and misdn_stack::procids.
Referenced by misdn_lib_send_event().
00899 { 00900 iframe_t ncr; 00901 int l3_id; 00902 int proc_id; 00903 struct misdn_stack *stack; 00904 00905 stack = get_stack_by_bc(bc); 00906 if (stack->nt) { 00907 if (find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, 0) < 0) { 00908 return -1; 00909 } 00910 cb_log(4, stack->port, " --> found channel: %d\n", bc->channel); 00911 00912 for (proc_id = 0; proc_id < MAXPROCS; ++proc_id) { 00913 if (stack->procids[proc_id] == 0) { 00914 break; 00915 } 00916 } /* end for */ 00917 if (proc_id == MAXPROCS) { 00918 cb_log(0, stack->port, "Couldnt Create New ProcId.\n"); 00919 return -1; 00920 } 00921 00922 stack->procids[proc_id] = 1; 00923 00924 l3_id = 0xff00 | proc_id; 00925 bc->l3_id = l3_id; 00926 cb_log(3, stack->port, " --> new_l3id %x\n", l3_id); 00927 } else { 00928 if ((stack->pri && stack->ptp) || bc->te_choose_channel) { 00929 /* we know exactly which channels are in use */ 00930 if (find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, bc->dec) < 0) { 00931 return -1; 00932 } 00933 cb_log(2, stack->port, " --> found channel: %d\n", bc->channel); 00934 } else { 00935 /* other phones could have made a call also on this port (ptmp) */ 00936 bc->channel = 0xff; 00937 } 00938 00939 /* if we are in te-mode, we need to create a process first */ 00940 if (++new_te_id > 0xffff) { 00941 new_te_id = 0x0001; 00942 } 00943 00944 l3_id = (entity << 16) | new_te_id; 00945 bc->l3_id = l3_id; 00946 cb_log(3, stack->port, "--> new_l3id %x\n", l3_id); 00947 00948 /* send message */ 00949 ncr.prim = CC_NEW_CR | REQUEST; 00950 ncr.addr = (stack->upper_id | FLG_MSG_DOWN); 00951 ncr.dinfo = l3_id; 00952 ncr.len = 0; 00953 mISDN_write(midev, &ncr, mISDN_HEADER_LEN + ncr.len, TIMEOUT_1SEC); 00954 } 00955 00956 return l3_id; 00957 }
static int do_tone | ( | struct misdn_bchannel * | bc, | |
int | len | |||
) | [static] |
Definition at line 2202 of file isdn_lib.c.
References cb_event, EVENT_TONE_GENERATE, misdn_bchannel::generate_tone, glob_mgr, misdn_tx_jitter(), misdn_bchannel::nojitter, misdn_bchannel::tone_cnt, and misdn_lib::user_data.
Referenced by handle_bchan().
02203 { 02204 bc->tone_cnt=len; 02205 02206 if (bc->generate_tone) { 02207 cb_event(EVENT_TONE_GENERATE, bc, glob_mgr->user_data); 02208 02209 if ( !bc->nojitter ) { 02210 misdn_tx_jitter(bc,len); 02211 } 02212 02213 return 1; 02214 } 02215 02216 return 0; 02217 }
static void dump_chan_list | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 457 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, cb_log, misdn_stack::channels, misdn_bchannel::in_use, and misdn_stack::port.
Referenced by empty_chan_in_stack(), handle_cr(), misdn_dump_chanlist(), and set_chan_in_stack().
00458 { 00459 int i; 00460 00461 for (i=0; i <= stack->b_num; i++) { 00462 cb_log(6, stack->port, "Idx:%d stack->cchan:%d in_use:%d Chan:%d\n",i,stack->channels[i], stack->bc[i].in_use, i+1); 00463 } 00464 }
void ec_chunk | ( | struct misdn_bchannel * | bc, | |
unsigned char * | rxchunk, | |||
unsigned char * | txchunk, | |||
int | chunk_size | |||
) |
static void empty_bc | ( | struct misdn_bchannel * | bc | ) | [static] |
Definition at line 629 of file isdn_lib.c.
References misdn_bchannel::active, misdn_bchannel::AOCD_need_export, misdn_bchannel::bframe_len, misdn_bchannel::cad, misdn_bchannel::capability, misdn_bchannel::cause, misdn_bchannel::channel, misdn_bchannel::channel_found, misdn_bchannel::conf_id, misdn_bchannel::cpnnumplan, misdn_bchannel::crypt, misdn_bchannel::crypt_key, misdn_bchannel::curprx, misdn_bchannel::curptx, misdn_bchannel::cw, misdn_bchannel::dad, misdn_bchannel::dec, misdn_bchannel::display, misdn_bchannel::dnumplan, misdn_bchannel::dummy, misdn_bchannel::early_bconnect, misdn_bchannel::ec_deftaps, misdn_bchannel::ec_enable, EVENT_NOTHING, misdn_bchannel::evq, misdn_bchannel::fac_in, misdn_bchannel::fac_out, misdn_bchannel::generate_tone, misdn_bchannel::hdlc, INFO_CAPABILITY_SPEECH, INFO_CODEC_ALAW, misdn_bchannel::info_dad, misdn_bchannel::infos_pending, misdn_bchannel::last_used, misdn_bchannel::law, misdn_bchannel::mode, misdn_bchannel::need_more_infos, misdn_bchannel::nodsp, misdn_bchannel::nojitter, NUMPLAN_UNKNOWN, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_bchannel::orig, misdn_bchannel::orig_dad, misdn_bchannel::out_cause, misdn_bchannel::pres, misdn_bchannel::progress_coding, misdn_bchannel::progress_indicator, misdn_bchannel::progress_location, misdn_bchannel::rad, misdn_bchannel::rate, misdn_bchannel::restart_channel, misdn_bchannel::rnumplan, misdn_bchannel::rxgain, misdn_bchannel::send_dtmf, misdn_bchannel::sending_complete, misdn_bchannel::te_choose_channel, misdn_bchannel::time_usec, misdn_bchannel::tone_cnt, misdn_bchannel::txgain, misdn_bchannel::urate, misdn_bchannel::user1, misdn_bchannel::uu, and misdn_bchannel::uulen.
Referenced by clear_l3(), handle_cr(), handle_event_nt(), handle_frm(), init_bc(), manager_clean_bc(), misdn_lib_release(), misdn_lib_send_event(), and misdn_lib_send_restart().
00630 { 00631 bc->dummy=0; 00632 00633 bc->bframe_len=0; 00634 00635 bc->cw= 0; 00636 00637 bc->dec=0; 00638 bc->channel = 0; 00639 00640 bc->sending_complete = 0; 00641 00642 bc->restart_channel=0; 00643 00644 bc->conf_id = 0; 00645 00646 bc->need_more_infos = 0; 00647 00648 bc->send_dtmf=0; 00649 bc->nodsp=0; 00650 bc->nojitter=0; 00651 00652 bc->time_usec=0; 00653 00654 bc->rxgain=0; 00655 bc->txgain=0; 00656 00657 bc->crypt=0; 00658 bc->curptx=0; bc->curprx=0; 00659 00660 bc->crypt_key[0] = 0; 00661 00662 bc->generate_tone=0; 00663 bc->tone_cnt=0; 00664 00665 bc->dnumplan=NUMPLAN_UNKNOWN; 00666 bc->onumplan=NUMPLAN_UNKNOWN; 00667 bc->rnumplan=NUMPLAN_UNKNOWN; 00668 bc->cpnnumplan=NUMPLAN_UNKNOWN; 00669 00670 00671 bc->active = 0; 00672 00673 bc->early_bconnect = 1; 00674 00675 #ifdef MISDN_1_2 00676 *bc->pipeline = 0; 00677 #else 00678 bc->ec_enable = 0; 00679 bc->ec_deftaps = 128; 00680 #endif 00681 00682 bc->AOCD_need_export = 0; 00683 00684 bc->orig=0; 00685 00686 bc->cause=16; 00687 bc->out_cause=16; 00688 bc->pres=0 ; /* screened */ 00689 00690 bc->evq=EVENT_NOTHING; 00691 00692 bc->progress_coding=0; 00693 bc->progress_location=0; 00694 bc->progress_indicator=0; 00695 00696 /** Set Default Bearer Caps **/ 00697 bc->capability=INFO_CAPABILITY_SPEECH; 00698 bc->law=INFO_CODEC_ALAW; 00699 bc->mode=0; 00700 bc->rate=0x10; 00701 bc->user1=0; 00702 bc->urate=0; 00703 00704 bc->hdlc=0; 00705 00706 00707 bc->info_dad[0] = 0; 00708 bc->display[0] = 0; 00709 bc->infos_pending[0] = 0; 00710 bc->cad[0] = 0; 00711 bc->oad[0] = 0; 00712 bc->dad[0] = 0; 00713 bc->rad[0] = 0; 00714 bc->orig_dad[0] = 0; 00715 bc->uu[0]=0; 00716 bc->uulen=0; 00717 00718 bc->fac_in.Function = Fac_None; 00719 bc->fac_out.Function = Fac_None; 00720 00721 bc->te_choose_channel = 0; 00722 bc->channel_found= 0; 00723 00724 gettimeofday(&bc->last_used, NULL); 00725 }
static int empty_chan_in_stack | ( | struct misdn_stack * | stack, | |
int | channel | |||
) | [static] |
Definition at line 557 of file isdn_lib.c.
References cb_log, misdn_stack::channels, dump_chan_list(), MAX_BCHANS, and misdn_stack::port.
Referenced by clear_l3(), handle_cr(), handle_event_nt(), handle_frm(), manager_clean_bc(), misdn_lib_release(), and misdn_lib_send_event().
00558 { 00559 if (channel<=0 || channel>MAX_BCHANS) { 00560 cb_log(0,stack?stack->port:0, "empty_chan_in_stack: cannot empty channel %d\n",channel); 00561 return -1; 00562 } 00563 00564 cb_log (4, stack?stack->port:0, "empty_chan_in_stack: %d\n",channel); 00565 stack->channels[channel-1] = 0; 00566 dump_chan_list(stack); 00567 return 0; 00568 }
static char* fac2str | ( | enum FacFunction | func | ) | [static] |
Definition at line 3252 of file isdn_lib.c.
References s.
Referenced by misdn_lib_log_ies().
03253 { 03254 struct arr_el { 03255 enum FacFunction p; 03256 char *s ; 03257 } arr[] = { 03258 { Fac_None, "Fac_None" }, 03259 { Fac_CD, "Fac_CD"}, 03260 }; 03261 03262 int i; 03263 03264 for (i=0; i < sizeof(arr)/sizeof( struct arr_el) ; i ++) 03265 if ( arr[i].p==func) return arr[i].s; 03266 03267 return "unknown"; 03268 }
static msg_t* fetch_msg | ( | int | midev | ) | [static] |
Definition at line 2962 of file isdn_lib.c.
References cb_log, errno, and msg.
Referenced by misdn_lib_isdn_event_catcher().
02963 { 02964 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 02965 int r; 02966 02967 if (!msg) { 02968 cb_log(0, 0, "fetch_msg: alloc msg failed !!"); 02969 return NULL; 02970 } 02971 02972 AGAIN: 02973 r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC); 02974 msg->len=r; 02975 02976 if (r==0) { 02977 free_msg(msg); /* danger, cauz usualy freeing in main_loop */ 02978 cb_log(6,0,"Got empty Msg..\n"); 02979 return NULL; 02980 } 02981 02982 if (r<0) { 02983 if (errno == EAGAIN) { 02984 /*we wait for mISDN here*/ 02985 cb_log(4,0,"mISDN_read wants us to wait\n"); 02986 usleep(5000); 02987 goto AGAIN; 02988 } 02989 02990 cb_log(0,0,"mISDN_read returned :%d error:%s (%d)\n",r,strerror(errno),errno); 02991 } 02992 02993 #if 0 02994 if (!(frm->prim == (DL_DATA|INDICATION) )|| (frm->prim == (PH_DATA|INDICATION))) 02995 cb_log(0,0,"prim: %x dinfo:%x addr:%x msglen:%d frm->len:%d\n",frm->prim, frm->dinfo, frm->addr, msg->len,frm->len ); 02996 #endif 02997 return msg; 02998 }
static struct misdn_bchannel* find_bc_by_addr | ( | unsigned long | addr | ) | [static] |
Definition at line 1472 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::b_num, misdn_stack::bc, glob_mgr, misdn_bchannel::layer_id, misdn_stack::next, and misdn_lib::stack_list.
Referenced by handle_bchan().
01473 { 01474 struct misdn_stack* stack; 01475 int i; 01476 01477 for (stack=glob_mgr->stack_list; 01478 stack; 01479 stack=stack->next) { 01480 for (i=0; i<=stack->b_num; i++) { 01481 if ( (stack->bc[i].addr&STACK_ID_MASK)==(addr&STACK_ID_MASK) || stack->bc[i].layer_id== addr ) { 01482 return &stack->bc[i]; 01483 } 01484 } 01485 } 01486 01487 return NULL; 01488 }
static struct misdn_bchannel* find_bc_by_channel | ( | int | port, | |
int | channel | |||
) | [static] |
Definition at line 1508 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::channel, and find_stack_by_port().
Referenced by handle_err().
01509 { 01510 struct misdn_stack* stack=find_stack_by_port(port); 01511 int i; 01512 01513 if (!stack) return NULL; 01514 01515 for (i=0; i<=stack->b_num; i++) { 01516 if ( stack->bc[i].channel== channel ) { 01517 return &stack->bc[i]; 01518 } 01519 } 01520 01521 return NULL; 01522 }
struct misdn_bchannel * find_bc_by_confid | ( | unsigned long | confid | ) |
Definition at line 1490 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::conf_id, glob_mgr, misdn_stack::next, and misdn_lib::stack_list.
Referenced by misdn_lib_send_event().
01491 { 01492 struct misdn_stack* stack; 01493 int i; 01494 01495 for (stack=glob_mgr->stack_list; 01496 stack; 01497 stack=stack->next) { 01498 for (i=0; i<=stack->b_num; i++) { 01499 if ( stack->bc[i].conf_id==confid ) { 01500 return &stack->bc[i]; 01501 } 01502 } 01503 } 01504 return NULL; 01505 }
struct misdn_bchannel * find_bc_by_l3id | ( | struct misdn_stack * | stack, | |
unsigned long | l3id | |||
) |
Definition at line 1453 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::l3_id, and stack_holder_find().
Referenced by handle_cr(), handle_event_nt(), handle_frm(), manager_event_handler(), and release_cr().
01454 { 01455 int i; 01456 for (i=0; i<=stack->b_num; i++) { 01457 if (stack->bc[i].l3_id == l3id) return &stack->bc[i] ; 01458 } 01459 return stack_holder_find(stack,l3id); 01460 }
static struct misdn_bchannel* find_bc_by_masked_l3id | ( | struct misdn_stack * | stack, | |
unsigned long | l3id, | |||
unsigned long | mask | |||
) | [static] |
Definition at line 1443 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::l3_id, and stack_holder_find().
Referenced by handle_event_nt().
01444 { 01445 int i; 01446 for (i=0; i<=stack->b_num; i++) { 01447 if ( (stack->bc[i].l3_id & mask) == (l3id & mask)) return &stack->bc[i] ; 01448 } 01449 return stack_holder_find(stack,l3id); 01450 }
static struct misdn_bchannel* find_bc_holded | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 1462 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, and misdn_bchannel::holded.
Referenced by manager_find_bc_holded().
01463 { 01464 int i; 01465 for (i=0; i<=stack->b_num; i++) { 01466 if (stack->bc[i].holded ) return &stack->bc[i] ; 01467 } 01468 return NULL; 01469 }
static int find_free_chan_in_stack | ( | struct misdn_stack * | stack, | |
struct misdn_bchannel * | bc, | |||
int | channel, | |||
int | dec | |||
) | [static] |
Definition at line 498 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, cb_log, chan, misdn_bchannel::channel_found, misdn_stack::channels, MAX_BCHANS, misdn_stack::port, and misdn_stack::pri.
Referenced by create_process(), handle_event(), handle_event_nt(), and misdn_lib_send_event().
00499 { 00500 int i; 00501 int chan=0; 00502 int bnums = stack->pri ? stack->b_num : stack->b_num - 1; 00503 00504 if (bc->channel_found) 00505 return 0; 00506 00507 bc->channel_found=1; 00508 00509 cb_log(5,stack->port,"find_free_chan: req_chan:%d\n",channel); 00510 00511 if (channel < 0 || channel > MAX_BCHANS) { 00512 cb_log(0, stack->port, " !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel); 00513 return 0; 00514 } 00515 00516 channel--; 00517 00518 if (dec) { 00519 for (i = bnums; i >=0; i--) { 00520 if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */ 00521 if (!stack->channels[i]) { 00522 cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1); 00523 chan=i+1; 00524 break; 00525 } 00526 } 00527 } 00528 } else { 00529 for (i = 0; i <= bnums; i++) { 00530 if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */ 00531 if (!stack->channels[i]) { 00532 cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1); 00533 chan=i+1; 00534 break; 00535 } 00536 } 00537 } 00538 } 00539 00540 if (!chan) { 00541 cb_log (1, stack->port, " !! NO FREE CHAN IN STACK\n"); 00542 dump_chan_list(stack); 00543 bc->out_cause=34; 00544 return -1; 00545 } 00546 00547 if (set_chan_in_stack(stack, chan)<0) { 00548 cb_log (0, stack->port, "Channel Already in use:%d\n", chan); 00549 bc->out_cause=44; 00550 return -1; 00551 } 00552 00553 bc->channel=chan; 00554 return 0; 00555 }
static struct misdn_stack* find_stack_by_addr | ( | int | addr | ) | [static] |
Definition at line 1404 of file isdn_lib.c.
References glob_mgr, misdn_stack::next, misdn_lib::stack_list, and misdn_stack::upper_id.
Referenced by handle_frm(), handle_frm_nt(), handle_l1(), handle_l2(), and handle_mgmt().
01405 { 01406 struct misdn_stack *stack; 01407 01408 for (stack=glob_mgr->stack_list; 01409 stack; 01410 stack=stack->next) { 01411 if ( (stack->upper_id&STACK_ID_MASK) == (addr&STACK_ID_MASK)) return stack; 01412 01413 } 01414 01415 return NULL; 01416 }
static struct misdn_stack* find_stack_by_mgr | ( | manager_t * | mgr_nt | ) | [static] |
Definition at line 1431 of file isdn_lib.c.
References glob_mgr, misdn_stack::mgr, misdn_stack::next, and misdn_lib::stack_list.
Referenced by handle_event_nt().
01432 { 01433 struct misdn_stack *stack; 01434 01435 for (stack=glob_mgr->stack_list; 01436 stack; 01437 stack=stack->next) 01438 if ( &stack->mgr == mgr_nt) return stack; 01439 01440 return NULL; 01441 }
static struct misdn_stack* find_stack_by_port | ( | int | port | ) | [static] |
Definition at line 1419 of file isdn_lib.c.
References glob_mgr, misdn_stack::next, misdn_stack::port, and misdn_lib::stack_list.
Referenced by find_bc_by_channel(), handle_err(), manager_event_handler(), misdn_lib_get_port_info(), misdn_lib_port_restart(), misdn_lib_reinit_nt_stack(), and misdn_lib_send_restart().
01420 { 01421 struct misdn_stack *stack; 01422 01423 for (stack=glob_mgr->stack_list; 01424 stack; 01425 stack=stack->next) 01426 if (stack->port == port) return stack; 01427 01428 return NULL; 01429 }
static char* flip_buf_bits | ( | char * | buf, | |
int | len | |||
) | [static] |
Definition at line 329 of file isdn_lib.c.
References flip_table.
Referenced by handle_bchan(), misdn_lib_init(), misdn_lib_tx2misdn_frm(), and misdn_tx_jitter().
00330 { 00331 int i; 00332 char * start = buf; 00333 00334 for (i = 0 ; i < len; i++) { 00335 buf[i] = flip_table[(unsigned char)buf[i]]; 00336 } 00337 00338 return start; 00339 }
struct misdn_stack * get_misdn_stack | ( | void | ) |
Definition at line 4525 of file isdn_lib.c.
References glob_mgr, and misdn_lib::stack_list.
Referenced by get_show_stack_details(), get_stack_by_bc(), misdn_dump_chanlist(), misdn_lib_get_maxchans(), misdn_lib_is_port_blocked(), misdn_lib_is_ptp(), misdn_lib_nt_keepcalls(), misdn_lib_port_block(), misdn_lib_port_is_nt(), misdn_lib_port_is_pri(), and misdn_lib_port_unblock().
04525 { 04526 return glob_mgr->stack_list; 04527 }
void get_show_stack_details | ( | int | port, | |
char * | buf | |||
) |
Definition at line 157 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, and misdn_stack::port.
Referenced by handle_cli_misdn_show_port(), and handle_cli_misdn_show_stacks().
00158 { 00159 struct misdn_stack *stack=get_misdn_stack(); 00160 00161 for ( ; stack; stack=stack->next) { 00162 if (stack->port == port) break; 00163 } 00164 00165 if (stack) { 00166 sprintf(buf, "* Port %d Type %s Prot. %s L2Link %s L1Link:%s Blocked:%d", stack->port, stack->nt?"NT":"TE", stack->ptp?"PTP":"PMP", stack->l2link?"UP":"DOWN", stack->l1link?"UP":"DOWN",stack->blocked); 00167 00168 } else { 00169 buf[0]=0; 00170 } 00171 00172 }
struct misdn_stack* get_stack_by_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 140 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, get_misdn_stack(), misdn_stack::next, misdn_bchannel::port, and misdn_stack::port.
Referenced by clean_up_bc(), create_process(), dec_ie_channel_id(), enc_ie_channel_id(), handle_bchan(), handle_event(), manager_bchannel_activate(), manager_bchannel_deactivate(), manager_clean_bc(), manager_ec_disable(), manager_ec_enable(), manager_find_bc_holded(), misdn_lib_log_ies(), misdn_lib_release(), misdn_lib_send_event(), misdn_lib_tx2misdn_frm(), parse_release_complete(), parse_restart(), send_msg(), and setup_bc().
00141 { 00142 struct misdn_stack *stack=get_misdn_stack(); 00143 00144 if (!bc) return NULL; 00145 00146 for ( ; stack; stack=stack->next) { 00147 int i; 00148 for (i=0; i <=stack->b_num; i++) { 00149 if ( bc->port == stack->port) return stack; 00150 } 00151 } 00152 00153 return NULL; 00154 }
static int handle_bchan | ( | msg_t * | msg | ) | [static] |
Definition at line 2311 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::b_stid, misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), bc_state_change(), BCHAN_ACTIVATED, BCHAN_CLEAN_REQUEST, BCHAN_SETUP, BCHAN_SETUPED, misdn_bchannel::bframe, misdn_bchannel::bframe_len, buf, misdn_bchannel::capability, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), misdn_bchannel::dad, misdn_bchannel::dnumplan, do_tone(), misdn_bchannel::dtmf, errno, EVENT_BCHAN_DATA, EVENT_DTMF_TONE, find_bc_by_addr(), flip_buf_bits(), get_stack_by_bc(), glob_mgr, misdn_bchannel::layer, misdn_stack::midev, misdn_cap_is_speech(), misdn_tx_jitter(), misdn_bchannel::nojitter, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_bchannel::pid, misdn_stack::port, misdn_bchannel::port, and misdn_lib::user_data.
Referenced by handle_err(), and manager_isdn_handler().
02312 { 02313 iframe_t *frm= (iframe_t*)msg->data; 02314 struct misdn_bchannel *bc=find_bc_by_addr(frm->addr); 02315 struct misdn_stack *stack; 02316 02317 if (!bc) { 02318 cb_log(1,0,"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo); 02319 return 0 ; 02320 } 02321 02322 stack = get_stack_by_bc(bc); 02323 02324 if (!stack) { 02325 cb_log(0, bc->port,"handle_bchan: STACK not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo); 02326 return 0; 02327 } 02328 02329 switch (frm->prim) { 02330 02331 case MGR_SETSTACK| CONFIRM: 02332 cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|CONFIRM pid:%d\n",bc->pid); 02333 break; 02334 02335 case MGR_SETSTACK| INDICATION: 02336 cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->pid); 02337 break; 02338 #if 0 02339 AGAIN: 02340 bc->addr = mISDN_get_layerid(stack->midev, bc->b_stid, bc->layer); 02341 if (!bc->addr) { 02342 02343 if (errno == EAGAIN) { 02344 usleep(1000); 02345 goto AGAIN; 02346 } 02347 02348 cb_log(0,stack->port,"$$$ Get Layer (%d) Id Error: %s\n",bc->layer,strerror(errno)); 02349 02350 /* we kill the channel later, when we received some 02351 data. */ 02352 bc->addr= frm->addr; 02353 } else if ( bc->addr < 0) { 02354 cb_log(0, stack->port,"$$$ bc->addr <0 Error:%s\n",strerror(errno)); 02355 bc->addr=0; 02356 } 02357 02358 cb_log(4, stack->port," --> Got Adr %x\n", bc->addr); 02359 02360 free_msg(msg); 02361 02362 02363 switch(bc->bc_state) { 02364 case BCHAN_SETUP: 02365 bc_state_change(bc,BCHAN_SETUPED); 02366 break; 02367 02368 case BCHAN_CLEAN_REQUEST: 02369 default: 02370 cb_log(0, stack->port," --> STATE WASN'T SETUP (but %s) in SETSTACK|IND pid:%d\n",bc_state2str(bc->bc_state), bc->pid); 02371 clean_up_bc(bc); 02372 } 02373 return 1; 02374 #endif 02375 02376 case MGR_DELLAYER| INDICATION: 02377 cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->pid); 02378 break; 02379 02380 case MGR_DELLAYER| CONFIRM: 02381 cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|CNF pid:%d\n",bc->pid); 02382 02383 bc->pid=0; 02384 bc->addr=0; 02385 02386 free_msg(msg); 02387 return 1; 02388 02389 case PH_ACTIVATE | INDICATION: 02390 case DL_ESTABLISH | INDICATION: 02391 cb_log(3, stack->port, "BCHAN: ACT Ind pid:%d\n", bc->pid); 02392 02393 free_msg(msg); 02394 return 1; 02395 02396 case PH_ACTIVATE | CONFIRM: 02397 case DL_ESTABLISH | CONFIRM: 02398 02399 cb_log(3, stack->port, "BCHAN: bchan ACT Confirm pid:%d\n",bc->pid); 02400 free_msg(msg); 02401 02402 return 1; 02403 02404 case DL_ESTABLISH | REQUEST: 02405 { 02406 char buf[128]; 02407 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_ESTABLISH | CONFIRM, 0,0, NULL, TIMEOUT_1SEC); 02408 } 02409 free_msg(msg); 02410 return 1; 02411 02412 case DL_RELEASE|REQUEST: 02413 { 02414 char buf[128]; 02415 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_RELEASE| CONFIRM, 0,0, NULL, TIMEOUT_1SEC); 02416 } 02417 free_msg(msg); 02418 return 1; 02419 02420 case PH_DEACTIVATE | INDICATION: 02421 case DL_RELEASE | INDICATION: 02422 cb_log (3, stack->port, "BCHAN: DeACT Ind pid:%d\n",bc->pid); 02423 02424 free_msg(msg); 02425 return 1; 02426 02427 case PH_DEACTIVATE | CONFIRM: 02428 case DL_RELEASE | CONFIRM: 02429 cb_log(3, stack->port, "BCHAN: DeACT Conf pid:%d\n",bc->pid); 02430 02431 free_msg(msg); 02432 return 1; 02433 02434 case PH_CONTROL|INDICATION: 02435 { 02436 unsigned int *cont = (unsigned int *) &frm->data.p; 02437 02438 cb_log(4, stack->port, "PH_CONTROL: channel:%d oad%d:%s dad%d:%s \n", bc->channel, bc->onumplan,bc->oad, bc->dnumplan,bc->dad); 02439 02440 if ((*cont & ~DTMF_TONE_MASK) == DTMF_TONE_VAL) { 02441 int dtmf = *cont & DTMF_TONE_MASK; 02442 cb_log(4, stack->port, " --> DTMF TONE: %c\n",dtmf); 02443 bc->dtmf=dtmf; 02444 cb_event(EVENT_DTMF_TONE, bc, glob_mgr->user_data); 02445 02446 free_msg(msg); 02447 return 1; 02448 } 02449 if (*cont == BF_REJECT) { 02450 cb_log(4, stack->port, " --> BF REJECT\n"); 02451 free_msg(msg); 02452 return 1; 02453 } 02454 if (*cont == BF_ACCEPT) { 02455 cb_log(4, stack->port, " --> BF ACCEPT\n"); 02456 free_msg(msg); 02457 return 1; 02458 } 02459 } 02460 break; 02461 02462 case PH_DATA|REQUEST: 02463 case DL_DATA|REQUEST: 02464 cb_log(0, stack->port, "DL_DATA REQUEST \n"); 02465 do_tone(bc, 64); 02466 02467 free_msg(msg); 02468 return 1; 02469 02470 02471 case PH_DATA|INDICATION: 02472 case DL_DATA|INDICATION: 02473 { 02474 bc->bframe = (void*)&frm->data.i; 02475 bc->bframe_len = frm->len; 02476 02477 /** Anyway flip the bufbits **/ 02478 if ( misdn_cap_is_speech(bc->capability) ) 02479 flip_buf_bits(bc->bframe, bc->bframe_len); 02480 02481 02482 if (!bc->bframe_len) { 02483 cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); 02484 free_msg(msg); 02485 return 1; 02486 } 02487 02488 if ( (bc->addr&STACK_ID_MASK) != (frm->addr&STACK_ID_MASK) ) { 02489 cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); 02490 free_msg(msg); 02491 return 1; 02492 } 02493 02494 #if MISDN_DEBUG 02495 cb_log(0, stack->port, "DL_DATA INDICATION Len %d\n", frm->len); 02496 02497 #endif 02498 02499 if ( (bc->bc_state == BCHAN_ACTIVATED) && frm->len > 0) { 02500 int t; 02501 02502 #ifdef MISDN_B_DEBUG 02503 cb_log(0,bc->port,"do_tone START\n"); 02504 #endif 02505 t=do_tone(bc,frm->len); 02506 02507 #ifdef MISDN_B_DEBUG 02508 cb_log(0,bc->port,"do_tone STOP (%d)\n",t); 02509 #endif 02510 if ( !t ) { 02511 int i; 02512 02513 if ( misdn_cap_is_speech(bc->capability)) { 02514 if ( !bc->nojitter ) { 02515 #ifdef MISDN_B_DEBUG 02516 cb_log(0,bc->port,"tx_jitter START\n"); 02517 #endif 02518 misdn_tx_jitter(bc,frm->len); 02519 #ifdef MISDN_B_DEBUG 02520 cb_log(0,bc->port,"tx_jitter STOP\n"); 02521 #endif 02522 } 02523 } 02524 02525 #ifdef MISDN_B_DEBUG 02526 cb_log(0,bc->port,"EVENT_B_DATA START\n"); 02527 #endif 02528 02529 i = cb_event(EVENT_BCHAN_DATA, bc, glob_mgr->user_data); 02530 #ifdef MISDN_B_DEBUG 02531 cb_log(0,bc->port,"EVENT_B_DATA STOP\n"); 02532 #endif 02533 02534 if (i<0) { 02535 cb_log(10,stack->port,"cb_event returned <0\n"); 02536 /*clean_up_bc(bc);*/ 02537 } 02538 } 02539 } 02540 free_msg(msg); 02541 return 1; 02542 } 02543 02544 02545 case PH_CONTROL | CONFIRM: 02546 cb_log(4, stack->port, "PH_CONTROL|CNF bc->addr:%x\n", frm->addr); 02547 free_msg(msg); 02548 return 1; 02549 02550 case PH_DATA | CONFIRM: 02551 case DL_DATA|CONFIRM: 02552 #if MISDN_DEBUG 02553 02554 cb_log(0, stack->port, "Data confirmed\n"); 02555 02556 #endif 02557 free_msg(msg); 02558 return 1; 02559 case DL_DATA|RESPONSE: 02560 #if MISDN_DEBUG 02561 cb_log(0, stack->port, "Data response\n"); 02562 02563 #endif 02564 break; 02565 } 02566 02567 return 0; 02568 }
static int handle_cr | ( | struct misdn_stack * | stack, | |
iframe_t * | frm | |||
) | [static] |
Definition at line 1611 of file isdn_lib.c.
References cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), dump_chan_list(), empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, find_bc_by_l3id(), free, glob_mgr, misdn_bchannel::in_use, misdn_bchannel::l3_id, misdn_lib_get_free_bc(), misdn_make_dummy(), misdn_bchannel::need_disconnect, misdn_bchannel::need_release, misdn_bchannel::need_release_complete, misdn_stack::nt, misdn_stack::port, misdn_bchannel::stack_holder, stack_holder_remove(), and misdn_lib::user_data.
Referenced by handle_event_nt(), handle_frm(), and release_cr().
01612 { 01613 struct misdn_bchannel *bc; 01614 01615 if (!stack) return -1; 01616 01617 switch (frm->prim) { 01618 case CC_NEW_CR|INDICATION: 01619 cb_log(7, stack->port, " --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo); 01620 01621 bc = misdn_lib_get_free_bc(stack->port, 0, 1, 0); 01622 if (!bc) { 01623 cb_log(0, stack->port, " --> !! lib: No free channel!\n"); 01624 return -1; 01625 } 01626 01627 cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo); 01628 bc->l3_id=frm->dinfo; 01629 return 1; 01630 case CC_NEW_CR|CONFIRM: 01631 return 1; 01632 case CC_NEW_CR|REQUEST: 01633 return 1; 01634 case CC_RELEASE_CR|REQUEST: 01635 return 1; 01636 case CC_RELEASE_CR|CONFIRM: 01637 break; 01638 case CC_RELEASE_CR|INDICATION: 01639 cb_log(4, stack->port, " --> lib: RELEASE_CR Ind with l3id:%x\n",frm->dinfo); 01640 { 01641 struct misdn_bchannel *bc=find_bc_by_l3id(stack, frm->dinfo); 01642 struct misdn_bchannel dummybc; 01643 01644 if (!bc) { 01645 cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo); 01646 misdn_make_dummy(&dummybc, stack->port, frm->dinfo, stack->nt, 0); 01647 01648 bc=&dummybc; 01649 } 01650 01651 if (bc) { 01652 int channel = bc->channel; 01653 cb_log(4, stack->port, " --> lib: CLEANING UP l3id: %x\n",frm->dinfo); 01654 01655 /*bc->pid = 0;*/ 01656 bc->need_disconnect=0; 01657 bc->need_release=0; 01658 bc->need_release_complete=0; 01659 01660 cb_event(EVENT_CLEANUP, bc, glob_mgr->user_data); 01661 01662 empty_bc(bc); 01663 clean_up_bc(bc); 01664 01665 if (channel>0) 01666 empty_chan_in_stack(stack,channel); 01667 bc->in_use=0; 01668 01669 dump_chan_list(stack); 01670 01671 if (bc->stack_holder) { 01672 cb_log(4,stack->port, "REMOVEING Holder\n"); 01673 stack_holder_remove( stack, bc); 01674 free(bc); 01675 } 01676 } 01677 else { 01678 if (stack->nt) 01679 cb_log(4, stack->port, "BC with dinfo: %x not found.. (prim was %x and addr %x)\n",frm->dinfo, frm->prim, frm->addr); 01680 } 01681 01682 return 1; 01683 } 01684 break; 01685 } 01686 01687 return 0; 01688 }
static int handle_err | ( | msg_t * | msg | ) | [static] |
Definition at line 3543 of file isdn_lib.c.
References misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), cb_log, misdn_bchannel::channel, find_bc_by_channel(), find_stack_by_port(), handle_bchan(), misdn_stack::l1link, misdn_stack::l2link, misdn_lib_get_l1_down(), misdn_lib_get_l2_down(), and misdn_bchannel::port.
Referenced by manager_isdn_handler().
03544 { 03545 iframe_t *frm = (iframe_t*) msg->data; 03546 03547 03548 if (!frm->addr) { 03549 static int cnt=0; 03550 if (!cnt) 03551 cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo); 03552 cnt++; 03553 if (cnt>100) { 03554 cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo); 03555 cnt=0; 03556 } 03557 03558 free_msg(msg); 03559 return 1; 03560 03561 } 03562 03563 switch (frm->prim) { 03564 case MGR_SETSTACK|INDICATION: 03565 return handle_bchan(msg); 03566 break; 03567 03568 case MGR_SETSTACK|CONFIRM: 03569 case MGR_CLEARSTACK|CONFIRM: 03570 free_msg(msg) ; 03571 return 1; 03572 break; 03573 03574 case DL_DATA|CONFIRM: 03575 cb_log(4,0,"DL_DATA|CONFIRM\n"); 03576 free_msg(msg); 03577 return 1; 03578 03579 case PH_CONTROL|CONFIRM: 03580 cb_log(4,0,"PH_CONTROL|CONFIRM\n"); 03581 free_msg(msg); 03582 return 1; 03583 03584 case DL_DATA|INDICATION: 03585 { 03586 int port=(frm->addr&MASTER_ID_MASK) >> 8; 03587 int channel=(frm->addr&CHILD_ID_MASK) >> 16; 03588 struct misdn_bchannel *bc; 03589 03590 /*we flush the read buffer here*/ 03591 03592 cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel); 03593 03594 free_msg(msg); 03595 return 1; 03596 03597 03598 bc = find_bc_by_channel(port, channel); 03599 03600 if (!bc) { 03601 struct misdn_stack *stack = find_stack_by_port(port); 03602 03603 if (!stack) { 03604 cb_log(0,0," --> stack not found\n"); 03605 free_msg(msg); 03606 return 1; 03607 } 03608 03609 cb_log(0,0," --> bc not found by channel\n"); 03610 if (stack->l2link) 03611 misdn_lib_get_l2_down(stack); 03612 03613 if (stack->l1link) 03614 misdn_lib_get_l1_down(stack); 03615 03616 free_msg(msg); 03617 return 1; 03618 } 03619 03620 cb_log(3,port," --> BC in state:%s\n", bc_state2str(bc->bc_state)); 03621 } 03622 } 03623 03624 return 0; 03625 }
static int handle_event | ( | struct misdn_bchannel * | bc, | |
enum event_e | event, | |||
iframe_t * | frm | |||
) | [static] |
Definition at line 1528 of file isdn_lib.c.
References misdn_stack::bc, cb_log, EVENT_ALERTING, EVENT_CONNECT, EVENT_CONNECT_ACKNOWLEDGE, EVENT_PROCEEDING, EVENT_PROGRESS, EVENT_RELEASE, EVENT_RELEASE_COMPLETE, EVENT_SETUP, EVENT_SETUP_ACKNOWLEDGE, find_free_chan_in_stack(), get_stack_by_bc(), manager_ec_enable(), manager_ph_control(), manager_ph_control_block(), misdn_cap_is_speech(), misdn_lib_send_event(), misdn_stack::nt, misdn_stack::port, misdn_stack::pri, misdn_stack::ptp, and setup_bc().
01529 { 01530 struct misdn_stack *stack=get_stack_by_bc(bc); 01531 01532 if (!stack->nt) { 01533 01534 switch (event) { 01535 01536 case EVENT_CONNECT_ACKNOWLEDGE: 01537 setup_bc(bc); 01538 01539 if ( *bc->crypt_key ) { 01540 cb_log(4, stack->port, "ENABLING BLOWFISH channel:%d oad%d:%s dad%d:%s\n", bc->channel, bc->onumplan,bc->oad, bc->dnumplan,bc->dad); 01541 manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); 01542 } 01543 01544 if (misdn_cap_is_speech(bc->capability)) { 01545 if ( !bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0); 01546 manager_ec_enable(bc); 01547 01548 if ( bc->txgain != 0 ) { 01549 cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); 01550 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 01551 } 01552 if ( bc->rxgain != 0 ) { 01553 cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); 01554 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 01555 } 01556 } 01557 01558 break; 01559 case EVENT_CONNECT: 01560 01561 if ( *bc->crypt_key ) { 01562 cb_log(4, stack->port, "ENABLING BLOWFISH channel:%d oad%d:%s dad%d:%s\n", bc->channel, bc->onumplan,bc->oad, bc->dnumplan,bc->dad); 01563 manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); 01564 } 01565 case EVENT_ALERTING: 01566 case EVENT_PROGRESS: 01567 case EVENT_PROCEEDING: 01568 case EVENT_SETUP_ACKNOWLEDGE: 01569 case EVENT_SETUP: 01570 { 01571 if (bc->channel == 0xff || bc->channel<=0) 01572 bc->channel=0; 01573 01574 if (find_free_chan_in_stack(stack, bc, bc->channel, 0)<0){ 01575 if (!stack->pri && !stack->ptp) { 01576 bc->cw=1; 01577 break; 01578 } 01579 01580 if (!bc->channel) 01581 cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n"); 01582 else 01583 cb_log(0, stack->port, "Requested Channel Already in Use releasing this call with cause 34!!!!\n"); 01584 01585 /* when the channel is already in use, we can't 01586 * simply clear it, we need to make sure that 01587 * it will still be marked as in_use in the 01588 * available channels list.*/ 01589 bc->channel=0; 01590 01591 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 01592 return -1; 01593 } 01594 } 01595 01596 setup_bc(bc); 01597 break; 01598 01599 case EVENT_RELEASE_COMPLETE: 01600 case EVENT_RELEASE: 01601 break; 01602 default: 01603 break; 01604 } 01605 } else { /** NT MODE **/ 01606 01607 } 01608 return 0; 01609 }
int handle_event_nt | ( | void * | dat, | |
void * | arg | |||
) | [static] |
Definition at line 1823 of file isdn_lib.c.
References misdn_stack::bc, misdn_bchannel::cause, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), create_l3msg(), empty_bc(), empty_chan_in_stack(), EVENT_NEW_L3ID, EVENT_PORT_ALARM, EVENT_RELEASE, EVENT_RELEASE_COMPLETE, EVENT_SETUP, find_bc_by_l3id(), find_bc_by_masked_l3id(), find_free_chan_in_stack(), find_stack_by_mgr(), free, glob_mgr, handle_cr(), misdn_bchannel::in_use, isdn_get_info(), isdn_msg_get_event(), isdn_msg_parse_event(), misdn_stack::l1link, misdn_stack::l2link, misdn_stack::l2upcnt, misdn_bchannel::l3_id, misdn_lib_get_free_bc(), misdn_lib_get_l2_up(), misdn_lib_reinit_nt_stack(), misdn_lib_send_event(), misdn_lib_send_restart(), misdn_make_dummy(), mISDNUSER_HEAD_SIZE, msg, msgs_g, misdn_stack::nst, misdn_stack::nt, misdn_bchannel::port, misdn_stack::port, misdn_stack::procids, misdn_stack::ptp, release_cr(), misdn_stack::restart_sent, stack_holder_find(), stack_holder_remove(), misdn_stack::upper_id, and misdn_lib::user_data.
Referenced by misdn_lib_reinit_nt_stack().
01824 { 01825 manager_t *mgr = (manager_t *)dat; 01826 msg_t *msg = (msg_t *)arg; 01827 mISDNuser_head_t *hh; 01828 int reject=0; 01829 01830 struct misdn_stack *stack=find_stack_by_mgr(mgr); 01831 int port; 01832 01833 if (!msg || !mgr) 01834 return(-EINVAL); 01835 01836 hh=(mISDNuser_head_t*)msg->data; 01837 port=stack->port; 01838 01839 cb_log(5, stack->port, " --> lib: prim %x dinfo %x\n",hh->prim, hh->dinfo); 01840 { 01841 switch(hh->prim){ 01842 case CC_RETRIEVE|INDICATION: 01843 { 01844 struct misdn_bchannel *bc, *hold_bc; 01845 01846 iframe_t frm; /* fake te frm to add callref to global callreflist */ 01847 frm.dinfo = hh->dinfo; 01848 01849 frm.addr=stack->upper_id | FLG_MSG_DOWN; 01850 01851 frm.prim = CC_NEW_CR|INDICATION; 01852 01853 if (handle_cr( stack, &frm)< 0) { 01854 msg_t *dmsg; 01855 cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo); 01856 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01857 stack->nst.manager_l3(&stack->nst, dmsg); 01858 free_msg(msg); 01859 return 0; 01860 } 01861 01862 bc = find_bc_by_l3id(stack, hh->dinfo); 01863 hold_bc = stack_holder_find(stack, bc->l3_id); 01864 cb_log(4, stack->port, "bc_l3id:%x holded_bc_l3id:%x\n",bc->l3_id, hold_bc->l3_id); 01865 01866 if (hold_bc) { 01867 cb_log(4, stack->port, "REMOVEING Holder\n"); 01868 01869 /*swap the backup to our new channel back*/ 01870 stack_holder_remove(stack, hold_bc); 01871 memcpy(bc, hold_bc, sizeof(*bc)); 01872 free(hold_bc); 01873 01874 bc->holded=0; 01875 bc->b_stid=0; 01876 } 01877 01878 } 01879 01880 break; 01881 01882 case CC_SETUP|CONFIRM: 01883 { 01884 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01885 int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE)); 01886 cb_log(4, stack->port, " --> lib: Event_ind:SETUP CONFIRM [NT] : new L3ID is %x\n",l3id ); 01887 01888 if (!bc) { cb_log(4, stack->port, "Bc Not found (after SETUP CONFIRM)\n"); return 0; } 01889 cb_log (2,bc->port,"I IND :CC_SETUP|CONFIRM: old l3id:%x new l3id:%x\n", bc->l3_id, l3id); 01890 bc->l3_id=l3id; 01891 cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data); 01892 } 01893 free_msg(msg); 01894 return 0; 01895 01896 case CC_SETUP|INDICATION: 01897 { 01898 struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0); 01899 if (!bc) 01900 ERR_NO_CHANNEL: 01901 { 01902 msg_t *dmsg; 01903 cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo); 01904 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01905 stack->nst.manager_l3(&stack->nst, dmsg); 01906 free_msg(msg); 01907 return 0; 01908 } 01909 01910 cb_log(4, stack->port, " --> new_process: New L3Id: %x\n",hh->dinfo); 01911 bc->l3_id=hh->dinfo; 01912 } 01913 break; 01914 01915 case CC_CONNECT_ACKNOWLEDGE|INDICATION: 01916 break; 01917 01918 case CC_ALERTING|INDICATION: 01919 case CC_PROCEEDING|INDICATION: 01920 case CC_SETUP_ACKNOWLEDGE|INDICATION: 01921 if(!stack->ptp) break; 01922 case CC_CONNECT|INDICATION: 01923 break; 01924 case CC_DISCONNECT|INDICATION: 01925 { 01926 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01927 if (!bc) { 01928 bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000); 01929 if (bc) { 01930 int myprocid=bc->l3_id&0x0000ffff; 01931 hh->dinfo=(hh->dinfo&0xffff0000)|myprocid; 01932 cb_log(3,stack->port,"Reject dinfo: %x cause:%d\n",hh->dinfo,bc->cause); 01933 reject=1; 01934 } 01935 } 01936 } 01937 break; 01938 01939 case CC_FACILITY|INDICATION: 01940 { 01941 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01942 if (!bc) { 01943 bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000); 01944 if (bc) { 01945 int myprocid=bc->l3_id&0x0000ffff; 01946 hh->dinfo=(hh->dinfo&0xffff0000)|myprocid; 01947 cb_log(4,bc->port,"Repaired reject Bug, new dinfo: %x\n",hh->dinfo); 01948 } 01949 } 01950 } 01951 break; 01952 01953 case CC_RELEASE_COMPLETE|INDICATION: 01954 break; 01955 01956 case CC_SUSPEND|INDICATION: 01957 { 01958 msg_t *dmsg; 01959 cb_log(4, stack->port, " --> Got Suspend, sending Reject for now\n"); 01960 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST,MT_SUSPEND_REJECT, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01961 stack->nst.manager_l3(&stack->nst, dmsg); 01962 free_msg(msg); 01963 return 0; 01964 } 01965 break; 01966 case CC_RESUME|INDICATION: 01967 break; 01968 01969 case CC_RELEASE|CONFIRM: 01970 { 01971 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01972 01973 if (bc) { 01974 cb_log(1, stack->port, "CC_RELEASE|CONFIRM (l3id:%x), sending RELEASE_COMPLETE\n", hh->dinfo); 01975 misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE); 01976 } 01977 } 01978 break; 01979 01980 case CC_RELEASE|INDICATION: 01981 break; 01982 01983 case CC_RELEASE_CR|INDICATION: 01984 release_cr(stack, hh); 01985 free_msg(msg); 01986 return 0 ; 01987 break; 01988 01989 case CC_NEW_CR|INDICATION: 01990 /* Got New CR for bchan, for now I handle this one in */ 01991 /* connect_ack, Need to be changed */ 01992 { 01993 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01994 int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE)); 01995 if (!bc) { cb_log(0, stack->port, " --> In NEW_CR: didn't found bc ??\n"); return -1;}; 01996 if (((l3id&0xff00)!=0xff00) && ((bc->l3_id&0xff00)==0xff00)) { 01997 cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", 0xff&bc->l3_id); 01998 stack->procids[bc->l3_id&0xff] = 0 ; 01999 } 02000 cb_log(4, stack->port, "lib: Event_ind:CC_NEW_CR : very new L3ID is %x\n",l3id ); 02001 02002 bc->l3_id =l3id; 02003 cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data); 02004 02005 free_msg(msg); 02006 return 0; 02007 } 02008 02009 case DL_ESTABLISH | INDICATION: 02010 case DL_ESTABLISH | CONFIRM: 02011 { 02012 cb_log(3, stack->port, "%% GOT L2 Activate Info.\n"); 02013 02014 if (stack->ptp && stack->l2link) { 02015 cb_log(0, stack->port, "%% GOT L2 Activate Info. but we're activated already.. this l2 is faulty, blocking port\n"); 02016 cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data); 02017 } 02018 02019 if (stack->ptp && !stack->restart_sent) { 02020 /* make sure we restart the interface of the 02021 * other side */ 02022 stack->restart_sent=1; 02023 misdn_lib_send_restart(stack->port, -1); 02024 02025 } 02026 02027 /* when we get the L2 UP, the L1 is UP definitely too*/ 02028 stack->l2link = 1; 02029 stack->l2upcnt=0; 02030 02031 free_msg(msg); 02032 return 0; 02033 } 02034 break; 02035 02036 02037 case DL_RELEASE | INDICATION: 02038 case DL_RELEASE | CONFIRM: 02039 { 02040 if (stack->ptp) { 02041 cb_log(3 , stack->port, "%% GOT L2 DeActivate Info.\n"); 02042 02043 if (stack->l2upcnt>3) { 02044 cb_log(0 , stack->port, "!!! Could not Get the L2 up after 3 Attemps!!!\n"); 02045 } else { 02046 #if 0 02047 if (stack->nt) misdn_lib_reinit_nt_stack(stack->port); 02048 #endif 02049 if (stack->l1link) { 02050 misdn_lib_get_l2_up(stack); 02051 stack->l2upcnt++; 02052 } 02053 } 02054 02055 } else 02056 cb_log(3, stack->port, "%% GOT L2 DeActivate Info.\n"); 02057 02058 stack->l2link = 0; 02059 free_msg(msg); 02060 return 0; 02061 } 02062 break; 02063 } 02064 } 02065 02066 { 02067 /* Parse Events and fire_up to App. */ 02068 struct misdn_bchannel *bc; 02069 struct misdn_bchannel dummybc; 02070 02071 enum event_e event = isdn_msg_get_event(msgs_g, msg, 1); 02072 02073 bc=find_bc_by_l3id(stack, hh->dinfo); 02074 02075 if (!bc) { 02076 cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x).\n", hh->dinfo); 02077 misdn_make_dummy(&dummybc, stack->port, hh->dinfo, stack->nt, 0); 02078 bc=&dummybc; 02079 } 02080 if (bc ) { 02081 isdn_msg_parse_event(msgs_g,msg,bc, 1); 02082 02083 switch (event) { 02084 case EVENT_SETUP: 02085 if (bc->channel<=0 || bc->channel==0xff) 02086 bc->channel=0; 02087 02088 if (find_free_chan_in_stack(stack,bc, bc->channel,0)<0) 02089 goto ERR_NO_CHANNEL; 02090 break; 02091 case EVENT_RELEASE: 02092 case EVENT_RELEASE_COMPLETE: 02093 { 02094 int channel=bc->channel; 02095 int tmpcause=bc->cause; 02096 empty_bc(bc); 02097 bc->cause=tmpcause; 02098 clean_up_bc(bc); 02099 02100 if (channel>0) 02101 empty_chan_in_stack(stack,channel); 02102 bc->in_use=0; 02103 } 02104 break; 02105 02106 default: 02107 break; 02108 } 02109 02110 if(!isdn_get_info(msgs_g,event,1)) { 02111 cb_log(4, stack->port, "Unknown Event Ind: prim %x dinfo %x\n",hh->prim, hh->dinfo); 02112 } else { 02113 if (reject) { 02114 switch(bc->cause){ 02115 case 17: 02116 cb_log(1, stack->port, "Siemens Busy reject..\n"); 02117 02118 break; 02119 default: 02120 break; 02121 } 02122 } 02123 cb_event(event, bc, glob_mgr->user_data); 02124 } 02125 } else { 02126 cb_log(4, stack->port, "No BC found with l3id: prim %x dinfo %x\n",hh->prim, hh->dinfo); 02127 } 02128 02129 free_msg(msg); 02130 } 02131 02132 02133 return 0; 02134 }
static int handle_frm | ( | msg_t * | msg | ) | [static] |
Definition at line 2607 of file isdn_lib.c.
References bc_state_change(), BCHAN_CLEANED, misdn_bchannel::cause, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), empty_bc(), empty_chan_in_stack(), EVENT_RELEASE_COMPLETE, EVENT_RESTART, EVENT_SETUP, find_bc_by_l3id(), find_stack_by_addr(), glob_mgr, handle_cr(), handle_event(), misdn_bchannel::in_use, isdn_get_info(), isdn_msg_get_event(), isdn_msg_parse_event(), misdn_lib_send_event(), misdn_lib_send_restart(), misdn_make_dummy(), msgs_g, misdn_bchannel::out_cause, misdn_bchannel::port, RESPONSE_IGNORE_SETUP, RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE, RESPONSE_OK, RESPONSE_RELEASE_SETUP, misdn_bchannel::restart_channel, set_chan_in_stack(), and misdn_lib::user_data.
Referenced by manager_event_handler(), and manager_isdn_handler().
02608 { 02609 iframe_t *frm = (iframe_t*) msg->data; 02610 02611 struct misdn_stack *stack=find_stack_by_addr(frm->addr); 02612 02613 if (!stack || stack->nt) { 02614 return 0; 02615 } 02616 02617 cb_log(4,stack?stack->port:0,"handle_frm: frm->addr:%x frm->prim:%x\n",frm->addr,frm->prim); 02618 02619 { 02620 struct misdn_bchannel dummybc; 02621 struct misdn_bchannel *bc; 02622 int ret=handle_cr(stack, frm); 02623 02624 if (ret<0) { 02625 cb_log(3,stack?stack->port:0,"handle_frm: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr); 02626 02627 02628 } 02629 02630 if(ret) { 02631 free_msg(msg); 02632 return 1; 02633 } 02634 02635 bc=find_bc_by_l3id(stack, frm->dinfo); 02636 02637 if (!bc && (frm->prim==(CC_RESTART|CONFIRM)) ) { 02638 misdn_make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0); 02639 bc=&dummybc; 02640 } 02641 02642 if (!bc && (frm->prim==(CC_SETUP|INDICATION)) ) { 02643 misdn_make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0); 02644 dummybc.port=stack->port; 02645 dummybc.l3_id=frm->dinfo; 02646 bc=&dummybc; 02647 02648 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 02649 02650 free_msg(msg); 02651 return 1; 02652 } 02653 02654 02655 handle_frm_bc: 02656 if (bc ) { 02657 enum event_e event = isdn_msg_get_event(msgs_g, msg, 0); 02658 enum event_response_e response=RESPONSE_OK; 02659 int ret; 02660 02661 isdn_msg_parse_event(msgs_g,msg,bc, 0); 02662 02663 /** Preprocess some Events **/ 02664 ret = handle_event(bc, event, frm); 02665 if (ret<0) { 02666 cb_log(0,stack->port,"couldn't handle event\n"); 02667 free_msg(msg); 02668 return 1; 02669 } 02670 /* shoot up event to App: */ 02671 cb_log(5, stack->port, "lib Got Prim: Addr %x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo); 02672 02673 if(!isdn_get_info(msgs_g,event,0)) 02674 cb_log(0, stack->port, "Unknown Event Ind: Addr:%x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo); 02675 else 02676 response=cb_event(event, bc, glob_mgr->user_data); 02677 #if 1 02678 if (event == EVENT_SETUP) { 02679 switch (response) { 02680 case RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE: 02681 02682 cb_log(0, stack->port, "TOTALY IGNORING SETUP \n"); 02683 02684 break; 02685 case RESPONSE_IGNORE_SETUP: 02686 /* I think we should send CC_RELEASE_CR, but am not sure*/ 02687 bc->out_cause=16; 02688 02689 case RESPONSE_RELEASE_SETUP: 02690 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 02691 if (bc->channel>0) 02692 empty_chan_in_stack(stack, bc->channel); 02693 empty_bc(bc); 02694 bc_state_change(bc,BCHAN_CLEANED); 02695 bc->in_use=0; 02696 02697 cb_log(0, stack->port, "GOT IGNORE SETUP\n"); 02698 break; 02699 case RESPONSE_OK: 02700 cb_log(4, stack->port, "GOT SETUP OK\n"); 02701 02702 02703 break; 02704 default: 02705 break; 02706 } 02707 } 02708 02709 if (event == EVENT_RELEASE_COMPLETE) { 02710 /* release bchannel only after we've anounced the RELEASE_COMPLETE */ 02711 int channel=bc->channel; 02712 int tmpcause=bc->cause; 02713 int tmp_out_cause=bc->out_cause; 02714 empty_bc(bc); 02715 bc->cause=tmpcause; 02716 bc->out_cause=tmp_out_cause; 02717 clean_up_bc(bc); 02718 02719 if (tmpcause == 44) { 02720 cb_log(0,stack->port,"**** Received CAUSE:44, so not cleaning up channel %d\n", channel); 02721 cb_log(0,stack->port,"**** This channel is now no longer available,\nplease try to restart it with 'misdn send restart <port> <channel>'\n"); 02722 set_chan_in_stack(stack, channel); 02723 bc->channel=channel; 02724 misdn_lib_send_restart(stack->port, channel); 02725 } else { 02726 if (channel>0) 02727 empty_chan_in_stack(stack, channel); 02728 } 02729 bc->in_use=0; 02730 } 02731 02732 if (event == EVENT_RESTART) { 02733 cb_log(0, stack->port, "**** Received RESTART_ACK channel:%d\n", bc->restart_channel); 02734 empty_chan_in_stack(stack, bc->restart_channel); 02735 } 02736 02737 cb_log(5, stack->port, "Freeing Msg on prim:%x \n",frm->prim); 02738 02739 02740 free_msg(msg); 02741 return 1; 02742 #endif 02743 02744 } else { 02745 struct misdn_bchannel dummybc; 02746 if (frm->prim!=(CC_FACILITY|INDICATION)) 02747 cb_log(0, stack->port, " --> Didn't find BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo); 02748 else 02749 cb_log(5, stack->port, " --> Using Dummy BC for FACILITy\n"); 02750 02751 memset (&dummybc,0,sizeof(dummybc)); 02752 dummybc.port=stack->port; 02753 dummybc.l3_id=frm->dinfo; 02754 bc=&dummybc; 02755 goto handle_frm_bc; 02756 } 02757 } 02758 02759 cb_log(4, stack->port, "TE_FRM_HANDLER: Returning 0 on prim:%x \n",frm->prim); 02760 return 0; 02761 }
static int handle_frm_nt | ( | msg_t * | msg | ) | [static] |
Definition at line 2572 of file isdn_lib.c.
References cb_log, find_stack_by_addr(), and nt_err_cnt.
Referenced by manager_event_handler(), and manager_isdn_handler().
02573 { 02574 iframe_t *frm= (iframe_t*)msg->data; 02575 struct misdn_stack *stack; 02576 int err=0; 02577 02578 stack=find_stack_by_addr( frm->addr ); 02579 02580 02581 02582 if (!stack || !stack->nt) { 02583 return 0; 02584 } 02585 02586 02587 if ((err=stack->nst.l1_l2(&stack->nst,msg))) { 02588 02589 if (nt_err_cnt > 0 ) { 02590 if (nt_err_cnt < 100) { 02591 nt_err_cnt++; 02592 cb_log(0, stack->port, "NT Stack sends us error: %d \n", err); 02593 } else if (nt_err_cnt < 105){ 02594 cb_log(0, stack->port, "NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err); 02595 nt_err_cnt = - 1; 02596 } 02597 } 02598 free_msg(msg); 02599 return 1; 02600 02601 } 02602 02603 return 1; 02604 }
static int handle_l1 | ( | msg_t * | msg | ) | [static] |
Definition at line 2764 of file isdn_lib.c.
References cb_event, cb_log, EVENT_CLEANUP, EVENT_NOTHING, find_stack_by_addr(), glob_mgr, global_state, isdn_get_info(), MISDN_INITIALIZED, misdn_lib_get_l2_up(), misdn_lib_send_event(), msgs_g, and misdn_lib::user_data.
Referenced by manager_isdn_handler().
02765 { 02766 iframe_t *frm = (iframe_t*) msg->data; 02767 struct misdn_stack *stack = find_stack_by_addr(frm->addr); 02768 int i ; 02769 02770 if (!stack) return 0 ; 02771 02772 switch (frm->prim) { 02773 case PH_ACTIVATE | CONFIRM: 02774 case PH_ACTIVATE | INDICATION: 02775 cb_log (3, stack->port, "L1: PH L1Link Up!\n"); 02776 stack->l1link=1; 02777 02778 if (stack->nt) { 02779 02780 if (stack->nst.l1_l2(&stack->nst, msg)) 02781 free_msg(msg); 02782 02783 if (stack->ptp) 02784 misdn_lib_get_l2_up(stack); 02785 } else { 02786 free_msg(msg); 02787 } 02788 02789 for (i=0;i<=stack->b_num; i++) { 02790 if (stack->bc[i].evq != EVENT_NOTHING) { 02791 cb_log(4, stack->port, "Fireing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0)); 02792 misdn_lib_send_event(&stack->bc[i],stack->bc[i].evq); 02793 stack->bc[i].evq=EVENT_NOTHING; 02794 } 02795 02796 } 02797 return 1; 02798 02799 case PH_ACTIVATE | REQUEST: 02800 free_msg(msg); 02801 cb_log(3,stack->port,"L1: PH_ACTIVATE|REQUEST \n"); 02802 return 1; 02803 02804 case PH_DEACTIVATE | REQUEST: 02805 free_msg(msg); 02806 cb_log(3,stack->port,"L1: PH_DEACTIVATE|REQUEST \n"); 02807 return 1; 02808 02809 case PH_DEACTIVATE | CONFIRM: 02810 case PH_DEACTIVATE | INDICATION: 02811 cb_log (3, stack->port, "L1: PH L1Link Down! \n"); 02812 02813 #if 0 02814 for (i=0; i<=stack->b_num; i++) { 02815 if (global_state == MISDN_INITIALIZED) { 02816 cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data); 02817 } 02818 } 02819 #endif 02820 02821 if (stack->nt) { 02822 if (stack->nst.l1_l2(&stack->nst, msg)) 02823 free_msg(msg); 02824 } else { 02825 free_msg(msg); 02826 } 02827 02828 stack->l1link=0; 02829 stack->l2link=0; 02830 return 1; 02831 } 02832 02833 return 0; 02834 }
static int handle_l2 | ( | msg_t * | msg | ) | [static] |
Definition at line 2836 of file isdn_lib.c.
References cb_event, cb_log, EVENT_PORT_ALARM, find_stack_by_addr(), glob_mgr, and misdn_lib::user_data.
Referenced by manager_isdn_handler().
02837 { 02838 iframe_t *frm = (iframe_t*) msg->data; 02839 02840 struct misdn_stack *stack = find_stack_by_addr(frm->addr); 02841 02842 if (!stack) { 02843 return 0 ; 02844 } 02845 02846 switch(frm->prim) { 02847 02848 case DL_ESTABLISH | REQUEST: 02849 cb_log(1,stack->port,"DL_ESTABLISH|REQUEST \n"); 02850 return 1; 02851 case DL_RELEASE | REQUEST: 02852 cb_log(1,stack->port,"DL_RELEASE|REQUEST \n"); 02853 return 1; 02854 02855 case DL_ESTABLISH | INDICATION: 02856 case DL_ESTABLISH | CONFIRM: 02857 { 02858 cb_log (3, stack->port, "L2: L2Link Up! \n"); 02859 if (stack->ptp && stack->l2link) { 02860 cb_log (-1, stack->port, "L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n"); 02861 cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data); 02862 } 02863 stack->l2link=1; 02864 free_msg(msg); 02865 return 1; 02866 } 02867 break; 02868 02869 case DL_RELEASE | INDICATION: 02870 case DL_RELEASE | CONFIRM: 02871 { 02872 cb_log (3, stack->port, "L2: L2Link Down! \n"); 02873 stack->l2link=0; 02874 02875 free_msg(msg); 02876 return 1; 02877 } 02878 break; 02879 } 02880 return 0; 02881 }
static int handle_mgmt | ( | msg_t * | msg | ) | [static] |
Definition at line 2883 of file isdn_lib.c.
References cb_log, clear_l3(), and find_stack_by_addr().
Referenced by manager_isdn_handler().
02884 { 02885 iframe_t *frm = (iframe_t*) msg->data; 02886 struct misdn_stack *stack; 02887 02888 if ( (frm->addr == 0) && (frm->prim == (MGR_DELLAYER|CONFIRM)) ) { 02889 cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: 0 !\n") ; 02890 free_msg(msg); 02891 return 1; 02892 } 02893 02894 stack = find_stack_by_addr(frm->addr); 02895 02896 if (!stack) { 02897 if (frm->prim == (MGR_DELLAYER|CONFIRM)) { 02898 cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: %x !\n", 02899 frm->addr) ; 02900 free_msg(msg); 02901 return 1; 02902 } 02903 02904 return 0; 02905 } 02906 02907 switch(frm->prim) { 02908 case MGR_SHORTSTATUS | INDICATION: 02909 case MGR_SHORTSTATUS | CONFIRM: 02910 cb_log(5, 0, "MGMT: Short status dinfo %x\n",frm->dinfo); 02911 02912 switch (frm->dinfo) { 02913 case SSTATUS_L1_ACTIVATED: 02914 cb_log(3, 0, "MGMT: SSTATUS: L1_ACTIVATED \n"); 02915 stack->l1link=1; 02916 02917 break; 02918 case SSTATUS_L1_DEACTIVATED: 02919 cb_log(3, 0, "MGMT: SSTATUS: L1_DEACTIVATED \n"); 02920 stack->l1link=0; 02921 #if 0 02922 clear_l3(stack); 02923 #endif 02924 break; 02925 02926 case SSTATUS_L2_ESTABLISHED: 02927 cb_log(3, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n"); 02928 stack->l2link=1; 02929 break; 02930 02931 case SSTATUS_L2_RELEASED: 02932 cb_log(3, stack->port, "MGMT: SSTATUS: L2_RELEASED \n"); 02933 stack->l2link=0; 02934 break; 02935 } 02936 02937 free_msg(msg); 02938 return 1; 02939 02940 case MGR_SETSTACK | INDICATION: 02941 cb_log(4, stack->port, "MGMT: SETSTACK|IND dinfo %x\n",frm->dinfo); 02942 free_msg(msg); 02943 return 1; 02944 case MGR_DELLAYER | CONFIRM: 02945 cb_log(4, stack->port, "MGMT: DELLAYER|CNF dinfo %x\n",frm->dinfo) ; 02946 free_msg(msg); 02947 return 1; 02948 02949 } 02950 02951 /* 02952 if ( (frm->prim & 0x0f0000) == 0x0f0000) { 02953 cb_log(5, 0, "$$$ MGMT FRAME: prim %x addr %x dinfo %x\n",frm->prim, frm->addr, frm->dinfo) ; 02954 free_msg(msg); 02955 return 1; 02956 } */ 02957 02958 return 0; 02959 }
static int handle_timers | ( | msg_t * | msg | ) | [static] |
Definition at line 2137 of file isdn_lib.c.
References cb_log, glob_mgr, misdn_stack::midev, misdn_stack::next, misdn_stack::nst, misdn_stack::nt, and misdn_lib::stack_list.
Referenced by manager_isdn_handler().
02138 { 02139 iframe_t *frm= (iframe_t*)msg->data; 02140 struct misdn_stack *stack; 02141 02142 /* Timer Stuff */ 02143 switch (frm->prim) { 02144 case MGR_INITTIMER | CONFIRM: 02145 case MGR_ADDTIMER | CONFIRM: 02146 case MGR_DELTIMER | CONFIRM: 02147 case MGR_REMOVETIMER | CONFIRM: 02148 free_msg(msg); 02149 return(1); 02150 } 02151 02152 02153 02154 if (frm->prim==(MGR_TIMER | INDICATION) ) { 02155 for (stack = glob_mgr->stack_list; 02156 stack; 02157 stack = stack->next) { 02158 itimer_t *it; 02159 02160 if (!stack->nt) continue; 02161 02162 it = stack->nst.tlist; 02163 /* find timer */ 02164 for(it=stack->nst.tlist; 02165 it; 02166 it=it->next) { 02167 if (it->id == (int)frm->addr) 02168 break; 02169 } 02170 if (it) { 02171 int ret; 02172 ret = mISDN_write_frame(stack->midev, msg->data, frm->addr, 02173 MGR_TIMER | RESPONSE, 0, 0, NULL, TIMEOUT_1SEC); 02174 test_and_clear_bit(FLG_TIMER_RUNING, (long unsigned int *)&it->Flags); 02175 ret = it->function(it->data); 02176 free_msg(msg); 02177 return 1; 02178 } 02179 } 02180 02181 cb_log(0, 0, "Timer Msg without Timer ??\n"); 02182 free_msg(msg); 02183 return 1; 02184 } 02185 02186 return 0; 02187 }
int init_bc | ( | struct misdn_stack * | stack, | |
struct misdn_bchannel * | bc, | |||
int | midev, | |||
int | port, | |||
int | bidx, | |||
char * | msn, | |||
int | firsttime | |||
) |
IFACE
Definition at line 1137 of file isdn_lib.c.
References misdn_bchannel::astbuf, misdn_stack::bc, bc_state_change(), BCHAN_CLEANED, buff, cb_log, empty_bc(), send_lock::lock, malloc, MISDN_IBUF_SIZE, misdn_bchannel::msn, misdn_stack::nt, misdn_bchannel::nt, misdn_stack::port, misdn_bchannel::port, misdn_stack::pri, misdn_bchannel::pri, pthread_mutex_init, and misdn_bchannel::send_lock.
Referenced by misdn_lib_init().
01138 { 01139 unsigned char buff[1025] = ""; 01140 iframe_t *frm = (iframe_t *)buff; 01141 int ret; 01142 01143 if (!bc) return -1; 01144 01145 cb_log(8, port, "Init.BC %d.\n",bidx); 01146 01147 memset(bc, 0,sizeof(struct misdn_bchannel)); 01148 01149 bc->send_lock=malloc(sizeof(struct send_lock)); 01150 01151 pthread_mutex_init(&bc->send_lock->lock, NULL); 01152 01153 if (msn) { 01154 int l = sizeof(bc->msn); 01155 strncpy(bc->msn,msn, l); 01156 bc->msn[l-1] = 0; 01157 } 01158 01159 01160 empty_bc(bc); 01161 bc_state_change(bc, BCHAN_CLEANED); 01162 01163 bc->port=stack->port; 01164 bc->nt=stack->nt?1:0; 01165 bc->pri=stack->pri; 01166 01167 { 01168 ibuffer_t* ibuf= init_ibuffer(MISDN_IBUF_SIZE); 01169 01170 if (!ibuf) return -1; 01171 01172 clear_ibuffer( ibuf); 01173 01174 ibuf->rsem=malloc(sizeof(sem_t)); 01175 01176 bc->astbuf=ibuf; 01177 01178 if (sem_init(ibuf->rsem,1,0)<0) 01179 sem_init(ibuf->rsem,0,0); 01180 01181 } 01182 01183 { 01184 stack_info_t *stinf; 01185 ret = mISDN_get_stack_info(midev, stack->port, buff, sizeof(buff)); 01186 if (ret < 0) { 01187 cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret); 01188 return -1; 01189 } 01190 01191 stinf = (stack_info_t *)&frm->data.p; 01192 01193 cb_log(8, port, " --> Child %x\n",stinf->child[bidx]); 01194 } 01195 01196 return 0; 01197 }
static void init_flip_bits | ( | void | ) | [static] |
Definition at line 316 of file isdn_lib.c.
References flip_table.
Referenced by misdn_lib_init().
00317 { 00318 int i,k; 00319 00320 for (i = 0 ; i < 256 ; i++) { 00321 unsigned char sample = 0 ; 00322 for (k = 0; k<8; k++) { 00323 if ( i & 1 << k ) sample |= 0x80 >> k; 00324 } 00325 flip_table[i] = sample; 00326 } 00327 }
void isdn_lib_stop_dtmf | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4285 of file isdn_lib.c.
References misdn_stack::bc, and manager_ph_control().
Referenced by process_ast_dsp().
04286 { 04287 manager_ph_control(bc, DTMF_TONE_STOP, 0); 04288 }
void isdn_lib_update_ec | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4273 of file isdn_lib.c.
References misdn_stack::bc, misdn_bchannel::ec_enable, manager_ec_disable(), and manager_ec_enable().
Referenced by process_ast_dsp().
04274 { 04275 #ifdef MISDN_1_2 04276 if (*bc->pipeline) 04277 #else 04278 if (bc->ec_enable) 04279 #endif 04280 manager_ec_enable(bc); 04281 else 04282 manager_ec_disable(bc); 04283 }
void isdn_lib_update_rxgain | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4263 of file isdn_lib.c.
References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::rxgain.
Referenced by process_ast_dsp().
04264 { 04265 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 04266 }
void isdn_lib_update_txgain | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4268 of file isdn_lib.c.
References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::txgain.
Referenced by process_ast_dsp().
04269 { 04270 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 04271 }
void manager_bchannel_activate | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4145 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::astbuf, misdn_stack::bc, buf, cb_log, get_stack_by_bc(), misdn_stack::midev, misdn_bchannel::port, and misdn_stack::port.
04146 { 04147 char buf[128]; 04148 04149 struct misdn_stack *stack=get_stack_by_bc(bc); 04150 04151 if (!stack) { 04152 cb_log(0, bc->port, "bchannel_activate: Stack not found !"); 04153 return ; 04154 } 04155 04156 /* we must activate if we are deactivated */ 04157 clear_ibuffer(bc->astbuf); 04158 04159 cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr); 04160 04161 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC); 04162 04163 return ; 04164 }
void manager_bchannel_cleanup | ( | struct misdn_bchannel * | bc | ) |
void manager_bchannel_deactivate | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4167 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::astbuf, misdn_stack::bc, misdn_bchannel::bc_state, bc_state_change(), BCHAN_ACTIVATED, BCHAN_BRIDGED, BCHAN_RELEASE, buf, cb_log, misdn_bchannel::conf_id, misdn_bchannel::generate_tone, get_stack_by_bc(), misdn_stack::midev, misdn_split_conf(), misdn_bchannel::port, and misdn_stack::port.
Referenced by clean_up_bc().
04168 { 04169 04170 struct misdn_stack *stack=get_stack_by_bc(bc); 04171 iframe_t dact; 04172 char buf[128]; 04173 04174 switch (bc->bc_state) { 04175 case BCHAN_ACTIVATED: 04176 break; 04177 case BCHAN_BRIDGED: 04178 misdn_split_conf(bc,bc->conf_id); 04179 break; 04180 default: 04181 cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n"); 04182 return ; 04183 04184 } 04185 04186 cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr); 04187 04188 bc->generate_tone=0; 04189 04190 dact.prim = DL_RELEASE | REQUEST; 04191 dact.addr = bc->addr | FLG_MSG_DOWN; 04192 dact.dinfo = 0; 04193 dact.len = 0; 04194 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC); 04195 04196 clear_ibuffer(bc->astbuf); 04197 04198 bc_state_change(bc,BCHAN_RELEASE); 04199 04200 return; 04201 }
void manager_bchannel_setup | ( | struct misdn_bchannel * | bc | ) |
void manager_clean_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4312 of file isdn_lib.c.
References misdn_stack::bc, cb_event, misdn_bchannel::channel, empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, get_stack_by_bc(), and misdn_bchannel::in_use.
Referenced by misdn_lib_pid_restart().
04313 { 04314 struct misdn_stack *stack=get_stack_by_bc(bc); 04315 04316 if (bc->channel>0) 04317 empty_chan_in_stack(stack, bc->channel); 04318 empty_bc(bc); 04319 bc->in_use=0; 04320 04321 cb_event(EVENT_CLEANUP, bc, NULL); 04322 }
void manager_ec_disable | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4504 of file isdn_lib.c.
References misdn_stack::bc, misdn_bchannel::capability, cb_log, misdn_bchannel::ec_enable, ECHOCAN_OFF, get_stack_by_bc(), manager_ph_control(), manager_ph_control_block(), misdn_cap_is_speech(), and misdn_stack::port.
Referenced by clean_up_bc(), handle_cli_misdn_toggle_echocancel(), and isdn_lib_update_ec().
04505 { 04506 struct misdn_stack *stack=get_stack_by_bc(bc); 04507 04508 cb_log(4, stack?stack->port:0," --> ec_disable\n"); 04509 04510 if (!misdn_cap_is_speech(bc->capability)) { 04511 cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n"); 04512 return; 04513 } 04514 04515 #ifdef MISDN_1_2 04516 manager_ph_control_block(bc, PIPELINE_CFG, "", 0); 04517 #else 04518 if ( ! bc->ec_enable) { 04519 cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n"); 04520 manager_ph_control(bc, ECHOCAN_OFF, 0); 04521 } 04522 #endif 04523 }
void manager_ec_enable | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4455 of file isdn_lib.c.
References misdn_stack::bc, misdn_bchannel::capability, cb_log, misdn_bchannel::ec_deftaps, misdn_bchannel::ec_enable, ECHOCAN_ON, get_stack_by_bc(), manager_ph_control_block(), misdn_cap_is_speech(), and misdn_stack::port.
Referenced by handle_cli_misdn_toggle_echocancel(), handle_event(), isdn_lib_update_ec(), and misdn_lib_send_event().
04456 { 04457 struct misdn_stack *stack=get_stack_by_bc(bc); 04458 04459 cb_log(4, stack?stack->port:0,"ec_enable\n"); 04460 04461 if (!misdn_cap_is_speech(bc->capability)) { 04462 cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n"); 04463 } else { 04464 04465 #ifdef MISDN_1_2 04466 if (*bc->pipeline) { 04467 cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline); 04468 manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1); 04469 } 04470 #else 04471 int ec_arr[2]; 04472 04473 if (bc->ec_enable) { 04474 cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps); 04475 04476 switch (bc->ec_deftaps) { 04477 case 4: 04478 case 8: 04479 case 16: 04480 case 32: 04481 case 64: 04482 case 128: 04483 case 256: 04484 case 512: 04485 case 1024: 04486 cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps); 04487 break; 04488 default: 04489 cb_log(0, stack->port, "Taps should be power of 2\n"); 04490 bc->ec_deftaps=128; 04491 } 04492 04493 ec_arr[0]=bc->ec_deftaps; 04494 ec_arr[1]=0; 04495 04496 manager_ph_control_block(bc, ECHOCAN_ON, ec_arr, sizeof(ec_arr)); 04497 } 04498 #endif 04499 } 04500 }
static void manager_event_handler | ( | void * | arg | ) | [static] |
Definition at line 3855 of file isdn_lib.c.
References misdn_lib::activatequeue, cb_log, clean_up_bc(), misdn_stack::downqueue, find_bc_by_l3id(), find_stack_by_port(), glob_mgr, handle_frm(), handle_frm_nt(), misdn_lib::midev, misdn_make_dummy(), misdn_lib::new_msg, misdn_stack::next, misdn_stack::nst, misdn_stack::nt, misdn_stack::port, misdn_bchannel::port, send_msg(), misdn_lib::stack_list, and misdn_stack::upqueue.
03856 { 03857 sem_post(&handler_started); 03858 while (1) { 03859 struct misdn_stack *stack; 03860 msg_t *msg; 03861 03862 /** wait for events **/ 03863 sem_wait(&glob_mgr->new_msg); 03864 03865 for (msg=msg_dequeue(&glob_mgr->activatequeue); 03866 msg; 03867 msg=msg_dequeue(&glob_mgr->activatequeue) 03868 ) 03869 { 03870 03871 iframe_t *frm = (iframe_t*) msg->data ; 03872 03873 switch ( frm->prim) { 03874 03875 case MGR_CLEARSTACK | REQUEST: 03876 /*a queued bchannel cleanup*/ 03877 { 03878 struct misdn_stack *stack=find_stack_by_port(frm->dinfo); 03879 struct misdn_bchannel *bc; 03880 if (!stack) { 03881 cb_log(0,0,"no stack found with port [%d]!! so we cannot cleanup the bc\n",frm->dinfo); 03882 free_msg(msg); 03883 break; 03884 } 03885 03886 bc = find_bc_by_l3id(stack, frm->addr); 03887 if (bc) { 03888 cb_log(1,bc->port,"CLEARSTACK queued, cleaning up\n"); 03889 clean_up_bc(bc); 03890 } else { 03891 cb_log(0,stack->port,"bc could not be cleaned correctly !! addr [%x]\n",frm->addr); 03892 } 03893 } 03894 free_msg(msg); 03895 break; 03896 case MGR_SETSTACK | REQUEST : 03897 break; 03898 default: 03899 mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); 03900 free_msg(msg); 03901 } 03902 } 03903 03904 for (stack=glob_mgr->stack_list; 03905 stack; 03906 stack=stack->next ) { 03907 03908 while ( (msg=msg_dequeue(&stack->upqueue)) ) { 03909 /** Handle L2/3 Signalling after bchans **/ 03910 if (!handle_frm_nt(msg)) { 03911 /* Maybe it's TE */ 03912 if (!handle_frm(msg)) { 03913 /* wow none! */ 03914 cb_log(0,stack->port,"Wow we've got a strange issue while dequeueing a Frame\n"); 03915 } 03916 } 03917 } 03918 03919 /* Here we should check if we really want to 03920 send all the messages we've queued, lets 03921 assume we've queued a Disconnect, but 03922 received it already from the other side!*/ 03923 03924 while ( (msg=msg_dequeue(&stack->downqueue)) ) { 03925 if (stack->nt ) { 03926 if (stack->nst.manager_l3(&stack->nst, msg)) 03927 cb_log(0, stack->port, "Error@ Sending Message in NT-Stack.\n"); 03928 03929 } else { 03930 iframe_t *frm = (iframe_t *)msg->data; 03931 struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo); 03932 if (bc) 03933 send_msg(glob_mgr->midev, bc, msg); 03934 else { 03935 if (frm->dinfo == MISDN_ID_GLOBAL || frm->dinfo == MISDN_ID_DUMMY ) { 03936 struct misdn_bchannel dummybc; 03937 cb_log(5,0," --> GLOBAL/DUMMY\n"); 03938 misdn_make_dummy(&dummybc, stack->port, frm->dinfo, stack->nt, 0); 03939 send_msg(glob_mgr->midev, &dummybc, msg); 03940 } else { 03941 cb_log(0,0,"No bc for Message\n"); 03942 } 03943 } 03944 } 03945 } 03946 } 03947 } 03948 }
struct misdn_bchannel * manager_find_bc_by_pid | ( | int | pid | ) |
Definition at line 3110 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, glob_mgr, misdn_stack::next, misdn_bchannel::pid, and misdn_lib::stack_list.
Referenced by misdn_lib_pid_restart().
03111 { 03112 struct misdn_stack *stack; 03113 int i; 03114 03115 for (stack=glob_mgr->stack_list; 03116 stack; 03117 stack=stack->next) { 03118 for (i=0; i<=stack->b_num; i++) 03119 if (stack->bc[i].pid == pid) return &stack->bc[i]; 03120 } 03121 03122 return NULL; 03123 }
struct misdn_bchannel * manager_find_bc_holded | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3125 of file isdn_lib.c.
References misdn_stack::bc, find_bc_holded(), and get_stack_by_bc().
03126 { 03127 struct misdn_stack *stack=get_stack_by_bc(bc); 03128 return find_bc_holded(stack); 03129 }
char* manager_isdn_get_info | ( | enum event_e | event | ) |
Definition at line 4140 of file isdn_lib.c.
References isdn_get_info(), and msgs_g.
Referenced by cb_events().
04141 { 04142 return isdn_get_info(msgs_g , event, 0); 04143 }
int manager_isdn_handler | ( | iframe_t * | frm, | |
msg_t * | msg | |||
) |
Definition at line 3645 of file isdn_lib.c.
References cb_log, handle_bchan(), handle_err(), handle_frm(), handle_frm_nt(), handle_l1(), handle_l2(), handle_mgmt(), handle_timers(), and LOG_NOTICE.
Referenced by misdn_lib_isdn_event_catcher().
03646 { 03647 03648 if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) { 03649 cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n"); 03650 } 03651 03652 if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) { 03653 static int unhandled_bmsg_count=1000; 03654 if (handle_bchan(msg)) { 03655 return 0 ; 03656 } 03657 03658 if (unhandled_bmsg_count==1000) { 03659 cb_log(0, 0, "received 1k Unhandled Bchannel Messages: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo); 03660 unhandled_bmsg_count=0; 03661 } 03662 03663 unhandled_bmsg_count++; 03664 free_msg(msg); 03665 return 0; 03666 } 03667 03668 #ifdef RECV_FRM_SYSLOG_DEBUG 03669 syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo); 03670 #endif 03671 03672 if (handle_timers(msg)) 03673 return 0 ; 03674 03675 03676 if (handle_mgmt(msg)) 03677 return 0 ; 03678 03679 if (handle_l2(msg)) 03680 return 0 ; 03681 03682 /* Its important to handle l1 AFTER l2 */ 03683 if (handle_l1(msg)) 03684 return 0 ; 03685 03686 if (handle_frm_nt(msg)) { 03687 return 0; 03688 } 03689 03690 if (handle_frm(msg)) { 03691 return 0; 03692 } 03693 03694 if (handle_err(msg)) { 03695 return 0 ; 03696 } 03697 03698 cb_log(0, 0, "Unhandled Message: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo); 03699 free_msg(msg); 03700 03701 03702 return 0; 03703 }
void manager_ph_control | ( | struct misdn_bchannel * | bc, | |
int | c1, | |||
int | c2 | |||
) |
Definition at line 4242 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::bc, glob_mgr, misdn_lib::midev, and misdn_bchannel::port.
Referenced by handle_event(), isdn_lib_stop_dtmf(), isdn_lib_update_rxgain(), isdn_lib_update_txgain(), manager_ec_disable(), misdn_join_conf(), misdn_lib_echo(), misdn_lib_send_event(), misdn_lib_send_tone(), and misdn_split_conf().
04243 { 04244 unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)]; 04245 iframe_t *ctrl = (iframe_t *)buffer; /* preload data */ 04246 unsigned int *d = (unsigned int*)&ctrl->data.p; 04247 /*struct misdn_stack *stack=get_stack_by_bc(bc);*/ 04248 04249 cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2); 04250 04251 ctrl->prim = PH_CONTROL | REQUEST; 04252 ctrl->addr = bc->addr | FLG_MSG_DOWN; 04253 ctrl->dinfo = 0; 04254 ctrl->len = sizeof(unsigned int)*2; 04255 *d++ = c1; 04256 *d++ = c2; 04257 mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); 04258 }
void manager_ph_control_block | ( | struct misdn_bchannel * | bc, | |
int | c1, | |||
void * | c2, | |||
int | c2_len | |||
) |
Definition at line 4293 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::bc, glob_mgr, and misdn_lib::midev.
Referenced by handle_event(), manager_ec_disable(), manager_ec_enable(), and misdn_lib_send_event().
04294 { 04295 unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len]; 04296 iframe_t *ctrl = (iframe_t *)buffer; 04297 unsigned int *d = (unsigned int *)&ctrl->data.p; 04298 /*struct misdn_stack *stack=get_stack_by_bc(bc);*/ 04299 04300 ctrl->prim = PH_CONTROL | REQUEST; 04301 ctrl->addr = bc->addr | FLG_MSG_DOWN; 04302 ctrl->dinfo = 0; 04303 ctrl->len = sizeof(unsigned int) + c2_len; 04304 *d++ = c1; 04305 memcpy(d, c2, c2_len); 04306 mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); 04307 }
int misdn_cap_is_speech | ( | int | cap | ) |
Poor mans version
Definition at line 431 of file isdn_lib.c.
References INFO_CAPABILITY_DIGITAL_RESTRICTED, and INFO_CAPABILITY_DIGITAL_UNRESTRICTED.
Referenced by cb_events(), handle_bchan(), handle_event(), manager_ec_disable(), manager_ec_enable(), misdn_lib_send_event(), and misdn_lib_tx2misdn_frm().
00433 { 00434 if ( (cap != INFO_CAPABILITY_DIGITAL_UNRESTRICTED) && 00435 (cap != INFO_CAPABILITY_DIGITAL_RESTRICTED) ) return 1; 00436 return 0; 00437 }
void misdn_dump_chanlist | ( | void | ) |
Definition at line 467 of file isdn_lib.c.
References dump_chan_list(), get_misdn_stack(), and misdn_stack::next.
Referenced by handle_cli_misdn_show_channels().
00468 { 00469 struct misdn_stack *stack=get_misdn_stack(); 00470 for ( ; stack; stack=stack->next) { 00471 dump_chan_list(stack); 00472 } 00473 00474 }
int misdn_inband_avail | ( | struct misdn_bchannel * | bc | ) |
Definition at line 439 of file isdn_lib.c.
References misdn_bchannel::early_bconnect, INFO_PI_CALL_NOT_E2E_ISDN, INFO_PI_CALLED_NOT_ISDN, INFO_PI_INBAND_AVAILABLE, and misdn_bchannel::progress_indicator.
Referenced by cb_events(), and misdn_indication().
00440 { 00441 00442 /*if ! early_bconnect we have never inband available*/ 00443 if ( ! bc->early_bconnect ) return 0; 00444 00445 switch (bc->progress_indicator) { 00446 case INFO_PI_INBAND_AVAILABLE: 00447 case INFO_PI_CALL_NOT_E2E_ISDN: 00448 case INFO_PI_CALLED_NOT_ISDN: 00449 return 1; 00450 default: 00451 return 0; 00452 } 00453 return 0; 00454 }
void misdn_join_conf | ( | struct misdn_bchannel * | bc, | |
int | conf_id | |||
) |
Definition at line 4531 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::bc, bc_state_change(), BCHAN_BRIDGED, cb_log, manager_ph_control(), misdn_lib_tx2misdn_frm(), and misdn_bchannel::port.
Referenced by bc_state_change(), and misdn_lib_bridge().
04532 { 04533 char data[16] = ""; 04534 04535 bc_state_change(bc,BCHAN_BRIDGED); 04536 manager_ph_control(bc, CMX_RECEIVE_OFF, 0); 04537 manager_ph_control(bc, CMX_CONF_JOIN, conf_id); 04538 04539 cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id); 04540 04541 misdn_lib_tx2misdn_frm(bc, data, sizeof(data) - 1); 04542 }
void misdn_lib_bridge | ( | struct misdn_bchannel * | bc1, | |
struct misdn_bchannel * | bc2 | |||
) |
Definition at line 4554 of file isdn_lib.c.
References bc_next_state_change(), BCHAN_ACTIVATED, BCHAN_BRIDGED, cb_log, misdn_join_conf(), misdn_bchannel::pid, and misdn_bchannel::port.
Referenced by misdn_bridge().
04554 { 04555 int conf_id = bc1->pid + 1; 04556 struct misdn_bchannel *bc_list[] = { bc1, bc2, NULL }; 04557 struct misdn_bchannel **bc; 04558 04559 cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port); 04560 04561 for (bc=bc_list; *bc; bc++) { 04562 (*bc)->conf_id=conf_id; 04563 cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr); 04564 04565 switch((*bc)->bc_state) { 04566 case BCHAN_ACTIVATED: 04567 misdn_join_conf(*bc,conf_id); 04568 break; 04569 default: 04570 bc_next_state_change(*bc,BCHAN_BRIDGED); 04571 break; 04572 } 04573 } 04574 }
void misdn_lib_destroy | ( | void | ) |
Definition at line 4107 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::b_num, misdn_stack::bc, buf, cb_log, misdn_lib::event_handler_thread, misdn_lib::event_thread, glob_mgr, global_state, misdn_stack::midev, misdn_lib::midev, MISDN_INITIALIZED, misdn_stack::next, misdn_stack::port, stack_destroy(), misdn_lib::stack_list, and te_lib_destroy().
Referenced by unload_module().
04108 { 04109 struct misdn_stack *help; 04110 int i; 04111 04112 for ( help=glob_mgr->stack_list; help; help=help->next ) { 04113 for(i=0;i<=help->b_num; i++) { 04114 char buf[1024]; 04115 mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 04116 help->bc[i].addr = 0; 04117 } 04118 cb_log (1, help->port, "Destroying this port.\n"); 04119 stack_destroy(help); 04120 } 04121 04122 if (global_state == MISDN_INITIALIZED) { 04123 cb_log(4, 0, "Killing Handler Thread\n"); 04124 if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) { 04125 cb_log(4, 0, "Joining Handler Thread\n"); 04126 pthread_join(glob_mgr->event_handler_thread, NULL); 04127 } 04128 04129 cb_log(4, 0, "Killing Main Thread\n"); 04130 if ( pthread_cancel(glob_mgr->event_thread) == 0 ) { 04131 cb_log(4, 0, "Joining Main Thread\n"); 04132 pthread_join(glob_mgr->event_thread, NULL); 04133 } 04134 } 04135 04136 cb_log(1, 0, "Closing mISDN device\n"); 04137 te_lib_destroy(glob_mgr->midev); 04138 }
void misdn_lib_echo | ( | struct misdn_bchannel * | bc, | |
int | onoff | |||
) |
Definition at line 4596 of file isdn_lib.c.
References cb_log, manager_ph_control(), and misdn_bchannel::port.
04597 { 04598 cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF"); 04599 manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0); 04600 }
struct misdn_bchannel* misdn_lib_get_free_bc | ( | int | port, | |
int | channel, | |||
int | inout, | |||
int | dec | |||
) |
Definition at line 3173 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, misdn_stack::blocked, cb_log, misdn_bchannel::channel, misdn_bchannel::cw, misdn_bchannel::dec, glob_mgr, MAX_BCHANS, misdn_stack::next, misdn_stack::port, prepare_bc(), misdn_stack::pri, misdn_stack::ptp, misdn_lib::stack_list, and test_inuse().
Referenced by handle_cr(), handle_event_nt(), and misdn_request().
03174 { 03175 struct misdn_stack *stack; 03176 int i; 03177 03178 if (channel < 0 || channel > MAX_BCHANS) { 03179 cb_log(0,port,"Requested channel out of bounds (%d)\n",channel); 03180 return NULL; 03181 } 03182 03183 usleep(1000); 03184 03185 for (stack=glob_mgr->stack_list; stack; stack=stack->next) { 03186 03187 if (stack->port == port) { 03188 int maxnum; 03189 03190 if (stack->blocked) { 03191 cb_log(0,port,"Port is blocked\n"); 03192 return NULL; 03193 } 03194 03195 if (channel > 0) { 03196 if (channel <= stack->b_num) { 03197 for (i = 0; i < stack->b_num; i++) { 03198 if ( stack->bc[i].channel == channel) { 03199 if (test_inuse(&stack->bc[i])) { 03200 cb_log(0,port,"Requested channel:%d on port:%d is already in use\n",channel, port); 03201 return NULL; 03202 03203 } else { 03204 prepare_bc(&stack->bc[i], channel); 03205 return &stack->bc[i]; 03206 } 03207 } 03208 } 03209 } else { 03210 cb_log(0,port,"Requested channel:%d is out of bounds on port:%d\n",channel, port); 03211 return NULL; 03212 } 03213 } 03214 03215 maxnum = inout && !stack->pri && !stack->ptp ? stack->b_num + 1 : stack->b_num; 03216 03217 if (dec) { 03218 for (i = maxnum-1; i>=0; i--) { 03219 if (!test_inuse(&stack->bc[i])) { 03220 /* 3. channel on bri means CW*/ 03221 if (!stack->pri && i==stack->b_num) 03222 stack->bc[i].cw=1; 03223 03224 prepare_bc(&stack->bc[i], channel); 03225 stack->bc[i].dec=1; 03226 return &stack->bc[i]; 03227 } 03228 } 03229 } else { 03230 for (i = 0; i <maxnum; i++) { 03231 if (!test_inuse(&stack->bc[i])) { 03232 /* 3. channel on bri means CW*/ 03233 if (!stack->pri && i==stack->b_num) 03234 stack->bc[i].cw=1; 03235 03236 prepare_bc(&stack->bc[i], channel); 03237 return &stack->bc[i]; 03238 } 03239 } 03240 } 03241 03242 cb_log(1,port,"There is no free channel on port (%d)\n",port); 03243 return NULL; 03244 } 03245 } 03246 03247 cb_log(0,port,"Port is not configured (%d)\n",port); 03248 return NULL; 03249 }
static int misdn_lib_get_l1_down | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 786 of file isdn_lib.c.
References cb_log, misdn_stack::lower_id, misdn_stack::midev, and misdn_stack::port.
Referenced by handle_err(), and misdn_lib_get_port_down().
00787 { 00788 /* Pull Up L1 */ 00789 iframe_t act; 00790 act.prim = PH_DEACTIVATE | REQUEST; 00791 act.addr = stack->lower_id|FLG_MSG_DOWN; 00792 act.dinfo = 0; 00793 act.len = 0; 00794 00795 cb_log(1, stack->port, "SENDING PH_DEACTIVATE | REQ\n"); 00796 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00797 }
static int misdn_lib_get_l1_up | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 826 of file isdn_lib.c.
References misdn_stack::midev, and misdn_stack::upper_id.
Referenced by misdn_lib_get_port_up(), misdn_lib_isdn_l1watcher(), misdn_lib_reinit_nt_stack(), and misdn_lib_send_event().
00827 { 00828 /* Pull Up L1 */ 00829 iframe_t act; 00830 act.prim = PH_ACTIVATE | REQUEST; 00831 act.addr = (stack->upper_id | FLG_MSG_DOWN) ; 00832 00833 00834 act.dinfo = 0; 00835 act.len = 0; 00836 00837 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00838 00839 }
static int misdn_lib_get_l2_down | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 800 of file isdn_lib.c.
References create_l2msg(), misdn_stack::midev, misdn_stack::nst, misdn_stack::nt, misdn_stack::ptp, and misdn_stack::upper_id.
Referenced by handle_err(), and misdn_lib_get_port_down().
00801 { 00802 00803 if (stack->ptp && (stack->nt) ) { 00804 msg_t *dmsg; 00805 /* L2 */ 00806 dmsg = create_l2msg(DL_RELEASE| REQUEST, 0, 0); 00807 00808 if (stack->nst.manager_l3(&stack->nst, dmsg)) 00809 free_msg(dmsg); 00810 00811 } else { 00812 iframe_t act; 00813 00814 act.prim = DL_RELEASE| REQUEST; 00815 act.addr = (stack->upper_id |FLG_MSG_DOWN) ; 00816 00817 act.dinfo = 0; 00818 act.len = 0; 00819 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00820 } 00821 00822 return 0; 00823 }
int misdn_lib_get_l2_up | ( | struct misdn_stack * | stack | ) |
Definition at line 841 of file isdn_lib.c.
References create_l2msg(), misdn_stack::midev, misdn_stack::nst, misdn_stack::nt, misdn_stack::ptp, and misdn_stack::upper_id.
Referenced by handle_event_nt(), handle_l1(), misdn_lib_get_port_up(), misdn_lib_isdn_l1watcher(), and misdn_lib_reinit_nt_stack().
00842 { 00843 00844 if (stack->ptp && (stack->nt) ) { 00845 msg_t *dmsg; 00846 /* L2 */ 00847 dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0); 00848 00849 if (stack->nst.manager_l3(&stack->nst, dmsg)) 00850 free_msg(dmsg); 00851 00852 } else { 00853 iframe_t act; 00854 00855 act.prim = DL_ESTABLISH | REQUEST; 00856 act.addr = (stack->upper_id |FLG_MSG_DOWN) ; 00857 00858 act.dinfo = 0; 00859 act.len = 0; 00860 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00861 } 00862 00863 return 0; 00864 }
int misdn_lib_get_maxchans | ( | int | port | ) |
Definition at line 125 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_stack::pri.
Referenced by misdn_request().
00126 { 00127 struct misdn_stack *stack=get_misdn_stack(); 00128 for ( ; stack; stack=stack->next) { 00129 if (stack->port == port) { 00130 if (stack->pri) 00131 return 30; 00132 else 00133 return 2; 00134 } 00135 } 00136 return -1; 00137 }
int misdn_lib_get_port_down | ( | int | port | ) |
Definition at line 1734 of file isdn_lib.c.
References glob_mgr, misdn_stack::l2link, misdn_lib_get_l1_down(), misdn_lib_get_l2_down(), misdn_stack::next, misdn_stack::port, and misdn_lib::stack_list.
Referenced by handle_cli_misdn_port_down().
01735 { /* Pull Down L1 */ 01736 struct misdn_stack *stack; 01737 for (stack=glob_mgr->stack_list; 01738 stack; 01739 stack=stack->next) { 01740 if (stack->port == port) { 01741 if (stack->l2link) 01742 misdn_lib_get_l2_down(stack); 01743 misdn_lib_get_l1_down(stack); 01744 return 0; 01745 } 01746 } 01747 return 0; 01748 }
int misdn_lib_get_port_info | ( | int | port | ) |
Definition at line 3708 of file isdn_lib.c.
References misdn_lib::activatequeue, cb_log, find_stack_by_port(), glob_mgr, misdn_lib::new_msg, and misdn_stack::upper_id.
03709 { 03710 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03711 iframe_t *frm; 03712 struct misdn_stack *stack=find_stack_by_port(port); 03713 if (!msg) { 03714 cb_log(0, port, "misgn_lib_get_port: alloc_msg failed!\n"); 03715 return -1; 03716 } 03717 frm=(iframe_t*)msg->data; 03718 if (!stack ) { 03719 cb_log(0, port, "There is no Stack for this port.\n"); 03720 return -1; 03721 } 03722 /* activate bchannel */ 03723 frm->prim = CC_STATUS_ENQUIRY | REQUEST; 03724 03725 frm->addr = stack->upper_id| FLG_MSG_DOWN; 03726 03727 frm->dinfo = 0; 03728 frm->len = 0; 03729 03730 msg_queue_tail(&glob_mgr->activatequeue, msg); 03731 sem_post(&glob_mgr->new_msg); 03732 03733 03734 return 0; 03735 }
int misdn_lib_get_port_up | ( | int | port | ) |
Definition at line 1712 of file isdn_lib.c.
References glob_mgr, misdn_stack::l1link, misdn_stack::l2link, misdn_lib_get_l1_up(), misdn_lib_get_l2_up(), misdn_stack::next, misdn_stack::port, and misdn_lib::stack_list.
Referenced by handle_cli_misdn_port_up(), and misdn_check_l2l1().
01713 { /* Pull Up L1 */ 01714 struct misdn_stack *stack; 01715 01716 for (stack=glob_mgr->stack_list; 01717 stack; 01718 stack=stack->next) { 01719 01720 if (stack->port == port) { 01721 01722 if (!stack->l1link) 01723 misdn_lib_get_l1_up(stack); 01724 if (!stack->l2link) 01725 misdn_lib_get_l2_up(stack); 01726 01727 return 0; 01728 } 01729 } 01730 return 0; 01731 }
static int misdn_lib_get_short_status | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 881 of file isdn_lib.c.
References misdn_stack::midev, and misdn_stack::upper_id.
Referenced by misdn_lib_isdn_l1watcher().
00882 { 00883 iframe_t act; 00884 00885 00886 act.prim = MGR_SHORTSTATUS | REQUEST; 00887 00888 act.addr = (stack->upper_id | MSG_BROADCAST) ; 00889 00890 act.dinfo = SSTATUS_BROADCAST_BIT | SSTATUS_ALL; 00891 00892 act.len = 0; 00893 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00894 }
int misdn_lib_init | ( | char * | portlist, | |
struct misdn_lib_iface * | iface, | |||
void * | user_data | |||
) |
Definition at line 3999 of file isdn_lib.c.
References misdn_lib::activatequeue, misdn_stack::b_num, misdn_stack::bc, calloc, cb_event, misdn_lib_iface::cb_event, cb_jb_empty, misdn_lib_iface::cb_jb_empty, misdn_lib_iface::cb_log, cb_log, first, flip_buf_bits(), glob_mgr, init_bc(), init_flip_bits(), misdn_stack::mgr, misdn_lib::midev, misdn_stack::midev, misdn_lib_nt_debug_init(), misdn_lib::new_msg, misdn_stack::next, misdn_stack::port, ptp, stack_init(), te_lib_init(), tone_425_flip, and tone_silence_flip.
Referenced by load_module().
04000 { 04001 struct misdn_lib *mgr=calloc(1, sizeof(struct misdn_lib)); 04002 char *tok, *tokb; 04003 char plist[1024]; 04004 int midev; 04005 int port_count=0; 04006 04007 cb_log = iface->cb_log; 04008 cb_event = iface->cb_event; 04009 cb_jb_empty = iface->cb_jb_empty; 04010 04011 glob_mgr = mgr; 04012 04013 msg_init(); 04014 04015 misdn_lib_nt_debug_init(0,NULL); 04016 04017 if (!portlist || (*portlist == 0) ) return 1; 04018 04019 init_flip_bits(); 04020 04021 { 04022 strncpy(plist,portlist, 1024); 04023 plist[1023] = 0; 04024 } 04025 04026 memcpy(tone_425_flip,tone_425,TONE_425_SIZE); 04027 flip_buf_bits(tone_425_flip,TONE_425_SIZE); 04028 04029 memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE); 04030 flip_buf_bits(tone_silence_flip,TONE_SILENCE_SIZE); 04031 04032 midev=te_lib_init(); 04033 mgr->midev=midev; 04034 04035 port_count=mISDN_get_stack_count(midev); 04036 04037 msg_queue_init(&mgr->activatequeue); 04038 04039 if (sem_init(&mgr->new_msg, 1, 0)<0) 04040 sem_init(&mgr->new_msg, 0, 0); 04041 04042 for (tok=strtok_r(plist," ,",&tokb ); 04043 tok; 04044 tok=strtok_r(NULL," ,",&tokb)) { 04045 int port = atoi(tok); 04046 struct misdn_stack *stack; 04047 static int first=1; 04048 int ptp=0; 04049 04050 if (strstr(tok, "ptp")) 04051 ptp=1; 04052 04053 if (port > port_count) { 04054 cb_log(0, port, "Couldn't Initialize this port since we have only %d ports\n", port_count); 04055 exit(1); 04056 } 04057 stack=stack_init(midev, port, ptp); 04058 04059 if (!stack) { 04060 perror("init_stack"); 04061 exit(1); 04062 } 04063 04064 { 04065 int i; 04066 for(i=0;i<=stack->b_num; i++) { 04067 int r; 04068 if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) { 04069 cb_log(0, port, "Got Err @ init_bc :%d\n",r); 04070 exit(1); 04071 } 04072 } 04073 } 04074 04075 if (stack && first) { 04076 mgr->stack_list=stack; 04077 first=0; 04078 continue; 04079 } 04080 04081 if (stack) { 04082 struct misdn_stack * help; 04083 for ( help=mgr->stack_list; help; help=help->next ) 04084 if (help->next == NULL) break; 04085 help->next=stack; 04086 } 04087 04088 } 04089 04090 if (sem_init(&handler_started, 1, 0)<0) 04091 sem_init(&handler_started, 0, 0); 04092 04093 cb_log(8, 0, "Starting Event Handler\n"); 04094 pthread_create( &mgr->event_handler_thread, NULL,(void*)manager_event_handler, mgr); 04095 04096 sem_wait(&handler_started) ; 04097 cb_log(8, 0, "Starting Event Catcher\n"); 04098 pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr); 04099 04100 cb_log(8, 0, "Event Catcher started\n"); 04101 04102 global_state= MISDN_INITIALIZED; 04103 04104 return (mgr == NULL); 04105 }
int misdn_lib_is_port_blocked | ( | int | port | ) |
Definition at line 105 of file isdn_lib.c.
References misdn_stack::blocked, get_misdn_stack(), misdn_stack::next, and misdn_stack::port.
00106 { 00107 struct misdn_stack *stack=get_misdn_stack(); 00108 for ( ; stack; stack=stack->next) { 00109 if (stack->port == port) { 00110 return stack->blocked; 00111 } 00112 } 00113 return -1; 00114 }
int misdn_lib_is_ptp | ( | int | port | ) |
Definition at line 116 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_stack::ptp.
Referenced by cb_events(), and do_immediate_setup().
00117 { 00118 struct misdn_stack *stack=get_misdn_stack(); 00119 for ( ; stack; stack=stack->next) { 00120 if (stack->port == port) return stack->ptp; 00121 } 00122 return -1; 00123 }
static void misdn_lib_isdn_event_catcher | ( | void * | arg | ) | [static] |
Definition at line 3018 of file isdn_lib.c.
References cb_log, fetch_msg(), manager_isdn_handler(), misdn_lib::midev, and msg.
03019 { 03020 struct misdn_lib *mgr = arg; 03021 int zero_frm=0 , fff_frm=0 ; 03022 int midev= mgr->midev; 03023 int port=0; 03024 03025 while (1) { 03026 msg_t *msg = fetch_msg(midev); 03027 iframe_t *frm; 03028 03029 03030 if (!msg) continue; 03031 03032 frm = (iframe_t*) msg->data; 03033 03034 /** When we make a call from NT2Ast we get this frames **/ 03035 if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) { 03036 zero_frm++; 03037 free_msg(msg); 03038 continue; 03039 } else { 03040 if (zero_frm) { 03041 cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm); 03042 zero_frm = 0 ; 03043 } 03044 } 03045 03046 /** I get this sometimes after setup_bc **/ 03047 if (frm->len == 0 && frm->dinfo == 0 && frm->prim == 0xffffffff ) { 03048 fff_frm++; 03049 free_msg(msg); 03050 continue; 03051 } else { 03052 if (fff_frm) { 03053 cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm); 03054 fff_frm = 0 ; 03055 } 03056 } 03057 03058 manager_isdn_handler(frm, msg); 03059 } 03060 03061 }
void misdn_lib_isdn_l1watcher | ( | int | port | ) |
Definition at line 3000 of file isdn_lib.c.
References cb_log, glob_mgr, misdn_stack::l1link, misdn_lib_get_l1_up(), misdn_lib_get_l2_up(), misdn_lib_get_short_status(), misdn_stack::next, misdn_stack::port, and misdn_lib::stack_list.
Referenced by misdn_l1_task().
03001 { 03002 struct misdn_stack *stack; 03003 03004 for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next) 03005 ; 03006 03007 if (stack) { 03008 cb_log(4, port, "Checking L1 State\n"); 03009 if (!stack->l1link) { 03010 cb_log(4, port, "L1 State Down, trying to get it up again\n"); 03011 misdn_lib_get_short_status(stack); 03012 misdn_lib_get_l1_up(stack); 03013 misdn_lib_get_l2_up(stack); 03014 } 03015 } 03016 }
void misdn_lib_log_ies | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3270 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::b_stid, misdn_stack::bc, bearer2str(), misdn_bchannel::cad, misdn_bchannel::capability, misdn_bchannel::cause, cb_log, misdn_bchannel::channel, misdn_bchannel::cpnnumplan, misdn_bchannel::dnumplan, fac2str(), misdn_bchannel::fac_in, misdn_bchannel::fac_out, get_stack_by_bc(), misdn_bchannel::holded, misdn_bchannel::info_dad, misdn_bchannel::keypad, misdn_bchannel::l3_id, misdn_bchannel::layer_id, misdn_bchannel::mode, misdn_stack::nt, misdn_bchannel::onumplan, misdn_bchannel::out_cause, misdn_stack::port, misdn_bchannel::pres, misdn_bchannel::progress_indicator, misdn_bchannel::rad, misdn_bchannel::rate, misdn_bchannel::rnumplan, misdn_bchannel::screen, misdn_bchannel::sending_complete, misdn_bchannel::stack_holder, misdn_bchannel::urate, and misdn_bchannel::user1.
Referenced by cb_events(), and misdn_lib_send_event().
03271 { 03272 struct misdn_stack *stack; 03273 03274 if (!bc) return; 03275 03276 stack = get_stack_by_bc(bc); 03277 03278 if (!stack) return; 03279 03280 cb_log(2, stack->port, " --> channel:%d mode:%s cause:%d ocause:%d rad:%s cad:%s\n", bc->channel, stack->nt?"NT":"TE", bc->cause, bc->out_cause, bc->rad, bc->cad); 03281 03282 cb_log(2, stack->port, 03283 " --> info_dad:%s onumplan:%c dnumplan:%c rnumplan:%c cpnnumplan:%c\n", 03284 bc->info_dad, 03285 bc->onumplan>=0?'0'+bc->onumplan:' ', 03286 bc->dnumplan>=0?'0'+bc->dnumplan:' ', 03287 bc->rnumplan>=0?'0'+bc->rnumplan:' ', 03288 bc->cpnnumplan>=0?'0'+bc->cpnnumplan:' ' 03289 ); 03290 03291 cb_log(3, stack->port, " --> caps:%s pi:%x keypad:%s sending_complete:%d\n", bearer2str(bc->capability),bc->progress_indicator, bc->keypad, bc->sending_complete); 03292 cb_log(4, stack->port, " --> screen:%d --> pres:%d\n", 03293 bc->screen, bc->pres); 03294 03295 cb_log(4, stack->port, " --> addr:%x l3id:%x b_stid:%x layer_id:%x\n", bc->addr, bc->l3_id, bc->b_stid, bc->layer_id); 03296 03297 cb_log(4, stack->port, " --> facility:%s out_facility:%s\n",fac2str(bc->fac_in.Function),fac2str(bc->fac_out.Function)); 03298 03299 cb_log(5, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1); 03300 03301 cb_log(5, stack->port, " --> bc:%p h:%d sh:%d\n", bc, bc->holded, bc->stack_holder); 03302 }
int misdn_lib_maxports_get | ( | void | ) |
Definition at line 3951 of file isdn_lib.c.
Referenced by load_module().
03951 { /** BE AWARE WE HAVE NO CB_LOG HERE! **/ 03952 03953 int i = mISDN_open(); 03954 int max=0; 03955 03956 if (i<0) 03957 return -1; 03958 03959 max = mISDN_get_stack_count(i); 03960 03961 mISDN_close(i); 03962 03963 return max; 03964 }
void misdn_lib_nt_debug_init | ( | int | flags, | |
char * | file | |||
) |
Definition at line 3979 of file isdn_lib.c.
References f.
Referenced by load_module(), and misdn_lib_init().
03980 { 03981 static int init=0; 03982 char *f; 03983 03984 if (!flags) 03985 f=NULL; 03986 else 03987 f=file; 03988 03989 if (!init) { 03990 debug_init( flags , f, f, f); 03991 init=1; 03992 } else { 03993 debug_close(); 03994 debug_init( flags , f, f, f); 03995 } 03996 }
void misdn_lib_nt_keepcalls | ( | int | kc | ) |
Definition at line 3967 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, and misdn_stack::nst.
Referenced by load_module().
03968 { 03969 #ifdef FEATURE_NET_KEEPCALLS 03970 if (kc) { 03971 struct misdn_stack *stack=get_misdn_stack(); 03972 for ( ; stack; stack=stack->next) { 03973 stack->nst.feature |= FEATURE_NET_KEEPCALLS; 03974 } 03975 } 03976 #endif 03977 }
int misdn_lib_pid_restart | ( | int | pid | ) |
Definition at line 3763 of file isdn_lib.c.
References manager_clean_bc(), and manager_find_bc_by_pid().
Referenced by handle_cli_misdn_restart_pid().
03764 { 03765 struct misdn_bchannel *bc=manager_find_bc_by_pid(pid); 03766 03767 if (bc) { 03768 manager_clean_bc(bc); 03769 } 03770 return 0; 03771 }
int misdn_lib_port_block | ( | int | port | ) |
Definition at line 79 of file isdn_lib.c.
References misdn_stack::blocked, get_misdn_stack(), misdn_stack::next, and misdn_stack::port.
Referenced by cb_events(), and handle_cli_misdn_port_block().
00080 { 00081 struct misdn_stack *stack=get_misdn_stack(); 00082 for ( ; stack; stack=stack->next) { 00083 if (stack->port == port) { 00084 stack->blocked=1; 00085 return 0; 00086 } 00087 } 00088 return -1; 00089 00090 }
int misdn_lib_port_is_nt | ( | int | port | ) |
Definition at line 53 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, misdn_stack::nt, and misdn_stack::port.
Referenced by handle_cli_misdn_send_facility().
00054 { 00055 struct misdn_stack *stack=get_misdn_stack(); 00056 for ( ; stack; stack=stack->next) { 00057 if (stack->port == port) { 00058 return stack->nt; 00059 } 00060 } 00061 00062 return -1; 00063 }
int misdn_lib_port_is_pri | ( | int | port | ) |
Definition at line 41 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_stack::pri.
Referenced by misdn_new(), test_inuse(), and update_name().
00042 { 00043 struct misdn_stack *stack=get_misdn_stack(); 00044 for ( ; stack; stack=stack->next) { 00045 if (stack->port == port) { 00046 return stack->pri; 00047 } 00048 } 00049 00050 return -1; 00051 }
int misdn_lib_port_restart | ( | int | port | ) |
Definition at line 3813 of file isdn_lib.c.
References misdn_lib::activatequeue, cb_log, clear_l3(), find_stack_by_port(), glob_mgr, misdn_lib_reinit_nt_stack(), misdn_lib::new_msg, misdn_stack::nt, misdn_stack::port, and misdn_stack::upper_id.
Referenced by handle_cli_misdn_restart_port().
03814 { 03815 struct misdn_stack *stack=find_stack_by_port(port); 03816 03817 cb_log(0, port, "Restarting this port.\n"); 03818 if (stack) { 03819 cb_log(0, port, "Stack:%p\n",stack); 03820 03821 clear_l3(stack); 03822 { 03823 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03824 iframe_t *frm; 03825 03826 if (!msg) { 03827 cb_log(0, port, "port_restart: alloc_msg failed\n"); 03828 return -1; 03829 } 03830 03831 frm=(iframe_t*)msg->data; 03832 /* we must activate if we are deactivated */ 03833 /* activate bchannel */ 03834 frm->prim = DL_RELEASE | REQUEST; 03835 frm->addr = stack->upper_id | FLG_MSG_DOWN; 03836 03837 frm->dinfo = 0; 03838 frm->len = 0; 03839 msg_queue_tail(&glob_mgr->activatequeue, msg); 03840 sem_post(&glob_mgr->new_msg); 03841 } 03842 03843 if (stack->nt) 03844 misdn_lib_reinit_nt_stack(stack->port); 03845 03846 } 03847 03848 return 0; 03849 }
int misdn_lib_port_unblock | ( | int | port | ) |
Definition at line 92 of file isdn_lib.c.
References misdn_stack::blocked, get_misdn_stack(), misdn_stack::next, and misdn_stack::port.
Referenced by handle_cli_misdn_port_unblock().
00093 { 00094 struct misdn_stack *stack=get_misdn_stack(); 00095 for ( ; stack; stack=stack->next) { 00096 if (stack->port == port) { 00097 stack->blocked=0; 00098 return 0; 00099 } 00100 } 00101 return -1; 00102 00103 }
int misdn_lib_port_up | ( | int | port, | |
int | check | |||
) |
Definition at line 1750 of file isdn_lib.c.
References misdn_stack::blocked, cb_log, glob_mgr, misdn_stack::l1link, misdn_stack::l2link, misdn_stack::next, misdn_stack::port, misdn_stack::ptp, and misdn_lib::stack_list.
Referenced by misdn_check_l2l1(), and misdn_request().
01751 { 01752 struct misdn_stack *stack; 01753 01754 01755 for (stack=glob_mgr->stack_list; 01756 stack; 01757 stack=stack->next) { 01758 01759 if (stack->port == port) { 01760 01761 if (stack->blocked) { 01762 cb_log(0,port, "Port Blocked:%d L2:%d L1:%d\n", stack->blocked, stack->l2link, stack->l1link); 01763 return -1; 01764 } 01765 01766 if (stack->ptp ) { 01767 01768 if (stack->l1link && stack->l2link) { 01769 return 1; 01770 } else { 01771 cb_log(1,port, "Port Down L2:%d L1:%d\n", 01772 stack->l2link, stack->l1link); 01773 return 0; 01774 } 01775 } else { 01776 if ( !check || stack->l1link ) 01777 return 1; 01778 else { 01779 cb_log(1,port, "Port down PMP\n"); 01780 return 0; 01781 } 01782 } 01783 } 01784 } 01785 01786 return -1; 01787 }
void misdn_lib_reinit_nt_stack | ( | int | port | ) |
Definition at line 4604 of file isdn_lib.c.
References misdn_stack::blocked, misdn_stack::d_stid, find_stack_by_port(), glob_mgr, handle_event_nt(), misdn_stack::l2link, misdn_stack::lower_id, misdn_stack::mgr, misdn_lib::midev, misdn_lib_get_l1_up(), misdn_lib_get_l2_up(), misdn_stack::nst, misdn_stack::pri, misdn_stack::ptp, and misdn_stack::upper_id.
Referenced by handle_event_nt(), and misdn_lib_port_restart().
04605 { 04606 struct misdn_stack *stack=find_stack_by_port(port); 04607 04608 if (stack) { 04609 stack->l2link=0; 04610 stack->blocked=0; 04611 04612 cleanup_Isdnl3(&stack->nst); 04613 cleanup_Isdnl2(&stack->nst); 04614 04615 04616 memset(&stack->nst, 0, sizeof(net_stack_t)); 04617 memset(&stack->mgr, 0, sizeof(manager_t)); 04618 04619 stack->mgr.nst = &stack->nst; 04620 stack->nst.manager = &stack->mgr; 04621 04622 stack->nst.l3_manager = handle_event_nt; 04623 stack->nst.device = glob_mgr->midev; 04624 stack->nst.cardnr = port; 04625 stack->nst.d_stid = stack->d_stid; 04626 04627 stack->nst.feature = FEATURE_NET_HOLD; 04628 if (stack->ptp) 04629 stack->nst.feature |= FEATURE_NET_PTP; 04630 if (stack->pri) 04631 stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID; 04632 04633 stack->nst.l1_id = stack->lower_id; 04634 stack->nst.l2_id = stack->upper_id; 04635 04636 msg_queue_init(&stack->nst.down_queue); 04637 04638 Isdnl2Init(&stack->nst); 04639 Isdnl3Init(&stack->nst); 04640 04641 if (!stack->ptp) 04642 misdn_lib_get_l1_up(stack); 04643 misdn_lib_get_l2_up(stack); 04644 } 04645 }
void misdn_lib_release | ( | struct misdn_bchannel * | bc | ) |
Definition at line 1692 of file isdn_lib.c.
References misdn_stack::bc, cb_log, misdn_bchannel::channel, clean_up_bc(), empty_bc(), empty_chan_in_stack(), get_stack_by_bc(), and misdn_bchannel::in_use.
Referenced by misdn_hangup().
01693 { 01694 struct misdn_stack *stack=get_stack_by_bc(bc); 01695 01696 if (!stack) { 01697 cb_log(1,0,"misdn_release: No Stack found\n"); 01698 return; 01699 } 01700 01701 if (bc->channel>0) 01702 empty_chan_in_stack(stack,bc->channel); 01703 01704 empty_bc(bc); 01705 clean_up_bc(bc); 01706 bc->in_use=0; 01707 }
int misdn_lib_send_event | ( | struct misdn_bchannel * | bc, | |
enum event_e | event | |||
) |
Definition at line 3323 of file isdn_lib.c.
References misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), bc_state_change(), BCHAN_BRIDGED, BCHAN_CLEANED, misdn_bchannel::capability, misdn_bchannel::cause, cb_log, misdn_bchannel::channel, clean_up_bc(), misdn_bchannel::conf_id, create_process(), misdn_bchannel::crypt_key, misdn_bchannel::dad, misdn_bchannel::dnumplan, misdn_stack::downqueue, empty_bc(), empty_chan_in_stack(), ENOCHAN, EVENT_ALERTING, EVENT_CONNECT, EVENT_CONNECT_ACKNOWLEDGE, EVENT_DISCONNECT, EVENT_HOLD_ACKNOWLEDGE, EVENT_PROCEEDING, EVENT_PROGRESS, EVENT_RELEASE, EVENT_RELEASE_COMPLETE, EVENT_RETRIEVE_ACKNOWLEDGE, EVENT_SETUP, EVENT_SETUP_ACKNOWLEDGE, misdn_bchannel::evq, find_bc_by_confid(), find_free_chan_in_stack(), get_stack_by_bc(), glob_mgr, misdn_bchannel::holded, misdn_bchannel::in_use, isdn_get_info(), isdn_msg_build_event(), misdn_stack::l1link, malloc, manager_ec_enable(), manager_ph_control(), manager_ph_control_block(), misdn_lib::midev, misdn_cap_is_speech(), misdn_lib_get_l1_up(), misdn_lib_log_ies(), misdn_send_lock(), misdn_send_unlock(), misdn_split_conf(), msg, msgs_g, misdn_bchannel::need_disconnect, misdn_bchannel::need_release, misdn_bchannel::need_release_complete, misdn_lib::new_msg, misdn_bchannel::nodsp, misdn_stack::nt, misdn_bchannel::nt, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_bchannel::out_cause, misdn_bchannel::pid, misdn_bchannel::port, misdn_stack::port, RETURN, misdn_bchannel::rxgain, setup_bc(), stack_holder_add(), misdn_bchannel::txgain, and misdn_stack::upper_id.
Referenced by cb_events(), do_immediate_setup(), handle_cli_misdn_send_display(), handle_cli_misdn_send_facility(), handle_event(), handle_event_nt(), handle_frm(), handle_l1(), misdn_answer(), misdn_call(), misdn_digit_end(), misdn_facility_exec(), misdn_hangup(), misdn_indication(), misdn_lib_send_restart(), misdn_overlap_dial_task(), misdn_send_text(), start_pbx(), and wait_for_digits().
03324 { 03325 msg_t *msg; 03326 int retval=0; 03327 struct misdn_stack *stack; 03328 03329 if (!bc) RETURN(-1,OUT_POST_UNLOCK); 03330 03331 stack = get_stack_by_bc(bc); 03332 03333 if (!stack) { 03334 cb_log(0,bc->port,"SENDEVENT: no Stack for event:%s oad:%s dad:%s \n", isdn_get_info(msgs_g, event, 0), bc->oad, bc->dad); 03335 RETURN(-1,OUT); 03336 } 03337 03338 misdn_send_lock(bc); 03339 03340 03341 cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->uperid:%x\n",stack->nt, stack->upper_id); 03342 03343 if ( stack->nt && !stack->l1link) { 03344 /** Queue Event **/ 03345 bc->evq=event; 03346 cb_log(1, stack->port, "Queueing Event %s because L1 is down (btw. Activating L1)\n", isdn_get_info(msgs_g, event, 0)); 03347 misdn_lib_get_l1_up(stack); 03348 RETURN(0,OUT); 03349 } 03350 03351 cb_log(1, stack->port, "I SEND:%s oad:%s dad:%s pid:%d\n", isdn_get_info(msgs_g, event, 0), bc->oad, bc->dad, bc->pid); 03352 cb_log(4, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state)); 03353 misdn_lib_log_ies(bc); 03354 03355 switch (event) { 03356 case EVENT_SETUP: 03357 if (create_process(glob_mgr->midev, bc)<0) { 03358 cb_log(0, stack->port, " No free channel at the moment @ send_event\n"); 03359 03360 RETURN(-ENOCHAN,OUT); 03361 } 03362 break; 03363 03364 case EVENT_PROGRESS: 03365 case EVENT_ALERTING: 03366 case EVENT_PROCEEDING: 03367 case EVENT_SETUP_ACKNOWLEDGE: 03368 case EVENT_CONNECT: 03369 if (!stack->nt) break; 03370 03371 case EVENT_RETRIEVE_ACKNOWLEDGE: 03372 03373 if (stack->nt) { 03374 if (bc->channel <=0 ) { /* else we have the channel already */ 03375 if (find_free_chan_in_stack(stack, bc, 0, 0)<0) { 03376 cb_log(0, stack->port, " No free channel at the moment\n"); 03377 /*FIXME: add disconnect*/ 03378 RETURN(-ENOCHAN,OUT); 03379 } 03380 } 03381 /* Its that i generate channels */ 03382 } 03383 03384 retval=setup_bc(bc); 03385 if (retval == -EINVAL) { 03386 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03387 } 03388 03389 if (misdn_cap_is_speech(bc->capability)) { 03390 if ((event==EVENT_CONNECT)||(event==EVENT_RETRIEVE_ACKNOWLEDGE)) { 03391 if ( *bc->crypt_key ) { 03392 cb_log(4, stack->port, " --> ENABLING BLOWFISH channel:%d oad%d:%s dad%d:%s \n", bc->channel, bc->onumplan,bc->oad, bc->dnumplan,bc->dad); 03393 03394 manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); 03395 } 03396 03397 if (!bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0); 03398 manager_ec_enable(bc); 03399 03400 if (bc->txgain != 0) { 03401 cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); 03402 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 03403 } 03404 03405 if ( bc->rxgain != 0 ) { 03406 cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); 03407 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 03408 } 03409 } 03410 } 03411 break; 03412 03413 case EVENT_HOLD_ACKNOWLEDGE: 03414 { 03415 struct misdn_bchannel *holded_bc=malloc(sizeof(struct misdn_bchannel)); 03416 if (!holded_bc) { 03417 cb_log(0,bc->port, "Could not allocate holded_bc!!!\n"); 03418 RETURN(-1,OUT); 03419 } 03420 03421 /*backup the bc*/ 03422 memcpy(holded_bc,bc,sizeof(struct misdn_bchannel)); 03423 holded_bc->holded=1; 03424 bc_state_change(holded_bc,BCHAN_CLEANED); 03425 03426 stack_holder_add(stack,holded_bc); 03427 03428 /*kill the bridge and clean the bchannel*/ 03429 if (stack->nt) { 03430 int channel; 03431 if (bc->bc_state == BCHAN_BRIDGED) { 03432 struct misdn_bchannel *bc2; 03433 03434 misdn_split_conf(bc,bc->conf_id); 03435 bc2 = find_bc_by_confid(bc->conf_id); 03436 if (!bc2) { 03437 cb_log(0,bc->port,"We have no second bc in bridge???\n"); 03438 } else { 03439 misdn_split_conf(bc2,bc->conf_id); 03440 } 03441 } 03442 03443 channel = bc->channel; 03444 03445 empty_bc(bc); 03446 clean_up_bc(bc); 03447 03448 if (channel>0) 03449 empty_chan_in_stack(stack,channel); 03450 03451 bc->in_use=0; 03452 } 03453 03454 } 03455 break; 03456 03457 /* finishing the channel eh ? */ 03458 case EVENT_DISCONNECT: 03459 if (!bc->need_disconnect) { 03460 cb_log(0,bc->port," --> we have already send Disconnect\n"); 03461 RETURN(-1,OUT); 03462 } 03463 03464 bc->need_disconnect=0; 03465 break; 03466 case EVENT_RELEASE: 03467 if (!bc->need_release) { 03468 cb_log(0,bc->port," --> we have already send Release\n"); 03469 RETURN(-1,OUT); 03470 } 03471 bc->need_disconnect=0; 03472 bc->need_release=0; 03473 break; 03474 case EVENT_RELEASE_COMPLETE: 03475 if (!bc->need_release_complete) { 03476 cb_log(0,bc->port," --> we have already send Release_complete\n"); 03477 RETURN(-1,OUT); 03478 } 03479 bc->need_disconnect=0; 03480 bc->need_release=0; 03481 bc->need_release_complete=0; 03482 03483 if (!stack->nt) { 03484 /*create clenaup in TE*/ 03485 int channel=bc->channel; 03486 03487 int tmpcause=bc->cause; 03488 int tmp_out_cause=bc->out_cause; 03489 empty_bc(bc); 03490 bc->cause=tmpcause; 03491 bc->out_cause=tmp_out_cause; 03492 clean_up_bc(bc); 03493 03494 if (channel>0) 03495 empty_chan_in_stack(stack,channel); 03496 03497 bc->in_use=0; 03498 } 03499 break; 03500 03501 case EVENT_CONNECT_ACKNOWLEDGE: 03502 03503 if ( bc->nt || misdn_cap_is_speech(bc->capability)) { 03504 int retval=setup_bc(bc); 03505 if (retval == -EINVAL){ 03506 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03507 03508 } 03509 } 03510 03511 if (misdn_cap_is_speech(bc->capability)) { 03512 if ( !bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0); 03513 manager_ec_enable(bc); 03514 03515 if ( bc->txgain != 0 ) { 03516 cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); 03517 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 03518 } 03519 if ( bc->rxgain != 0 ) { 03520 cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); 03521 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 03522 } 03523 } 03524 break; 03525 03526 default: 03527 break; 03528 } 03529 03530 /* Later we should think about sending bchannel data directly to misdn. */ 03531 msg = isdn_msg_build_event(msgs_g, bc, event, stack->nt); 03532 msg_queue_tail(&stack->downqueue, msg); 03533 sem_post(&glob_mgr->new_msg); 03534 03535 OUT: 03536 misdn_send_unlock(bc); 03537 03538 OUT_POST_UNLOCK: 03539 return retval; 03540 }
int misdn_lib_send_restart | ( | int | port, | |
int | channel | |||
) |
Definition at line 3774 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, cb_log, misdn_bchannel::channel, clean_up_bc(), empty_bc(), EVENT_RESTART, find_stack_by_port(), misdn_bchannel::in_use, misdn_lib_send_event(), misdn_make_dummy(), misdn_stack::nt, and misdn_stack::port.
Referenced by handle_cli_misdn_send_restart(), handle_event_nt(), and handle_frm().
03775 { 03776 struct misdn_stack *stack=find_stack_by_port(port); 03777 struct misdn_bchannel dummybc; 03778 /*default is all channels*/ 03779 cb_log(0, port, "Sending Restarts on this port.\n"); 03780 03781 misdn_make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0); 03782 03783 /*default is all channels*/ 03784 if (channel <0) { 03785 dummybc.channel=-1; 03786 cb_log(0, port, "Restarting and all Interfaces\n"); 03787 misdn_lib_send_event(&dummybc, EVENT_RESTART); 03788 03789 return 0; 03790 } 03791 03792 /*if a channel is specified we restart only this one*/ 03793 if (channel >0) { 03794 int cnt; 03795 dummybc.channel=channel; 03796 cb_log(0, port, "Restarting and cleaning channel %d\n",channel); 03797 misdn_lib_send_event(&dummybc, EVENT_RESTART); 03798 /* clean up chan in stack, to be sure we don't think it's 03799 * in use anymore */ 03800 for (cnt=0; cnt<=stack->b_num; cnt++) { 03801 if (stack->bc[cnt].channel == channel) { 03802 empty_bc(&stack->bc[cnt]); 03803 clean_up_bc(&stack->bc[cnt]); 03804 stack->bc[cnt].in_use=0; 03805 } 03806 } 03807 } 03808 03809 return 0; 03810 }
void misdn_lib_send_tone | ( | struct misdn_bchannel * | bc, | |
enum tone_e | tone | |||
) |
Definition at line 4423 of file isdn_lib.c.
References misdn_bchannel::addr, buf, glob_mgr, manager_ph_control(), misdn_lib::midev, TONE_ALERTING, TONE_DIAL, TONE_HANGUP, and TONE_NONE.
Referenced by hanguptone_indicate().
04424 { 04425 char buf[mISDN_HEADER_LEN + 128] = ""; 04426 iframe_t *frm = (iframe_t*)buf; 04427 04428 switch(tone) { 04429 case TONE_DIAL: 04430 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE); 04431 break; 04432 04433 case TONE_ALERTING: 04434 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_RINGING); 04435 break; 04436 04437 case TONE_HANGUP: 04438 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_HANGUP); 04439 break; 04440 04441 case TONE_NONE: 04442 default: 04443 manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP); 04444 } 04445 04446 frm->prim=DL_DATA|REQUEST; 04447 frm->addr=bc->addr|FLG_MSG_DOWN; 04448 frm->dinfo=0; 04449 frm->len=128; 04450 04451 mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); 04452 }
void misdn_lib_setup_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 960 of file isdn_lib.c.
References misdn_stack::bc, clean_up_bc(), and setup_bc().
00961 { 00962 clean_up_bc(bc); 00963 setup_bc(bc); 00964 }
void misdn_lib_split_bridge | ( | struct misdn_bchannel * | bc1, | |
struct misdn_bchannel * | bc2 | |||
) |
Definition at line 4576 of file isdn_lib.c.
References bc_state2str(), BCHAN_BRIDGED, cb_log, misdn_bchannel::conf_id, and misdn_split_conf().
Referenced by misdn_bridge().
04577 { 04578 04579 struct misdn_bchannel *bc_list[]={ 04580 bc1,bc2,NULL 04581 }; 04582 struct misdn_bchannel **bc; 04583 04584 for (bc=bc_list; *bc; bc++) { 04585 if ( (*bc)->bc_state == BCHAN_BRIDGED){ 04586 misdn_split_conf( *bc, (*bc)->conf_id); 04587 } else { 04588 cb_log( 2, (*bc)->port, "BC not bridged (state:%s) so not splitting it\n",bc_state2str((*bc)->bc_state)); 04589 } 04590 } 04591 04592 }
void misdn_lib_tone_generator_start | ( | struct misdn_bchannel * | bc | ) |
Definition at line 2191 of file isdn_lib.c.
References misdn_bchannel::generate_tone.
Referenced by misdn_write().
02192 { 02193 bc->generate_tone=1; 02194 }
void misdn_lib_tone_generator_stop | ( | struct misdn_bchannel * | bc | ) |
Definition at line 2196 of file isdn_lib.c.
References misdn_bchannel::generate_tone.
Referenced by start_bc_tones(), and stop_indicate().
02197 { 02198 bc->generate_tone=0; 02199 }
void misdn_lib_transfer | ( | struct misdn_bchannel * | holded_bc | ) |
Definition at line 3105 of file isdn_lib.c.
References misdn_bchannel::holded.
03106 { 03107 holded_bc->holded=0; 03108 }
int misdn_lib_tx2misdn_frm | ( | struct misdn_bchannel * | bc, | |
void * | data, | |||
int | len | |||
) |
Definition at line 4204 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), BCHAN_ACTIVATED, BCHAN_BRIDGED, buf, misdn_bchannel::capability, cb_log, flip_buf_bits(), get_stack_by_bc(), misdn_stack::midev, misdn_cap_is_speech(), misdn_bchannel::port, and misdn_stack::port.
Referenced by misdn_join_conf().
04205 { 04206 struct misdn_stack *stack=get_stack_by_bc(bc); 04207 char buf[4096 + mISDN_HEADER_LEN]; 04208 iframe_t *frm = (iframe_t*)buf; 04209 int r; 04210 04211 switch (bc->bc_state) { 04212 case BCHAN_ACTIVATED: 04213 case BCHAN_BRIDGED: 04214 break; 04215 default: 04216 cb_log(3, bc->port, "BC not yet activated (state:%s)\n",bc_state2str(bc->bc_state)); 04217 return -1; 04218 } 04219 04220 frm->prim = DL_DATA|REQUEST; 04221 frm->dinfo = 0; 04222 frm->addr = bc->addr | FLG_MSG_DOWN ; 04223 04224 frm->len = len; 04225 memcpy(&buf[mISDN_HEADER_LEN], data,len); 04226 04227 if ( misdn_cap_is_speech(bc->capability) ) 04228 flip_buf_bits( &buf[mISDN_HEADER_LEN], len); 04229 else 04230 cb_log(6, stack->port, "Writing %d data bytes\n",len); 04231 04232 cb_log(9, stack->port, "Writing %d bytes 2 mISDN\n",len); 04233 r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT); 04234 return 0; 04235 }
void misdn_make_dummy | ( | struct misdn_bchannel * | dummybc, | |
int | port, | |||
int | l3id, | |||
int | nt, | |||
int | channel | |||
) |
Definition at line 65 of file isdn_lib.c.
References misdn_bchannel::channel, misdn_bchannel::dummy, misdn_bchannel::l3_id, misdn_bchannel::nt, and misdn_bchannel::port.
Referenced by handle_cli_misdn_send_facility(), handle_cr(), handle_event_nt(), handle_frm(), manager_event_handler(), misdn_lib_send_restart(), and release_cr().
00066 { 00067 memset (dummybc,0,sizeof(struct misdn_bchannel)); 00068 dummybc->port=port; 00069 if (l3id==0) 00070 dummybc->l3_id = MISDN_ID_DUMMY; 00071 else 00072 dummybc->l3_id=l3id; 00073 00074 dummybc->nt=nt; 00075 dummybc->dummy=1; 00076 dummybc->channel=channel; 00077 }
void misdn_send_lock | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3309 of file isdn_lib.c.
References misdn_stack::bc, send_lock::lock, pthread_mutex_lock, and misdn_bchannel::send_lock.
Referenced by misdn_lib_send_event().
03310 { 03311 //cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid); 03312 if (bc->send_lock) 03313 pthread_mutex_lock(&bc->send_lock->lock); 03314 }
void misdn_send_unlock | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3316 of file isdn_lib.c.
References misdn_stack::bc, send_lock::lock, pthread_mutex_unlock, and misdn_bchannel::send_lock.
Referenced by misdn_lib_send_event().
03317 { 03318 //cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid); 03319 if (bc->send_lock) 03320 pthread_mutex_unlock(&bc->send_lock->lock); 03321 }
void misdn_split_conf | ( | struct misdn_bchannel * | bc, | |
int | conf_id | |||
) |
Definition at line 4545 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::bc, bc_state_change(), BCHAN_ACTIVATED, cb_log, manager_ph_control(), and misdn_bchannel::port.
Referenced by manager_bchannel_deactivate(), misdn_lib_send_event(), and misdn_lib_split_bridge().
04546 { 04547 bc_state_change(bc,BCHAN_ACTIVATED); 04548 manager_ph_control(bc, CMX_RECEIVE_ON, 0); 04549 manager_ph_control(bc, CMX_CONF_SPLIT, conf_id); 04550 04551 cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id); 04552 }
void misdn_tx_jitter | ( | struct misdn_bchannel * | bc, | |
int | len | |||
) |
Definition at line 2246 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::bframe, misdn_bchannel::bframe_len, buf, cb_jb_empty, cb_log, misdn_bchannel::channel, errno, flip_buf_bits(), glob_mgr, misdn_lib::midev, misdn_bchannel::port, and tone_silence_flip.
Referenced by do_tone(), and handle_bchan().
02247 { 02248 char buf[4096 + mISDN_HEADER_LEN]; 02249 char *data=&buf[mISDN_HEADER_LEN]; 02250 iframe_t *txfrm= (iframe_t*)buf; 02251 int jlen, r; 02252 02253 jlen=cb_jb_empty(bc,data,len); 02254 02255 if (jlen) { 02256 #ifdef MISDN_SAVE_DATA 02257 misdn_save_data((bc->port*100+bc->channel), data, jlen, bc->bframe, bc->bframe_len); 02258 #endif 02259 flip_buf_bits( data, jlen); 02260 02261 if (jlen < len) { 02262 cb_log(1, bc->port, "Jitterbuffer Underrun. Got %d of expected %d\n", jlen, len); 02263 } 02264 02265 txfrm->prim = DL_DATA|REQUEST; 02266 02267 txfrm->dinfo = 0; 02268 02269 txfrm->addr = bc->addr|FLG_MSG_DOWN; /* | IF_DOWN; */ 02270 02271 txfrm->len =jlen; 02272 cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len); 02273 02274 r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); 02275 } else { 02276 #define MISDN_GEN_SILENCE 02277 #ifdef MISDN_GEN_SILENCE 02278 int cnt=len/TONE_SILENCE_SIZE; 02279 int rest=len%TONE_SILENCE_SIZE; 02280 int i; 02281 02282 for (i=0; i<cnt; i++) { 02283 memcpy(data, tone_silence_flip, TONE_SILENCE_SIZE ); 02284 data +=TONE_SILENCE_SIZE; 02285 } 02286 02287 if (rest) { 02288 memcpy(data, tone_silence_flip, rest); 02289 } 02290 02291 txfrm->prim = DL_DATA|REQUEST; 02292 02293 txfrm->dinfo = 0; 02294 02295 txfrm->addr = bc->addr|FLG_MSG_DOWN; /* | IF_DOWN; */ 02296 02297 txfrm->len =len; 02298 cb_log(5, bc->port, "Transmitting %d samples of silence to misdn\n", len); 02299 02300 r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); 02301 #else 02302 r = 0; 02303 #endif 02304 } 02305 02306 if (r < 0) { 02307 cb_log(1, bc->port, "Error in mISDN_write (%s)\n", strerror(errno)); 02308 } 02309 }
static void prepare_bc | ( | struct misdn_bchannel * | bc, | |
int | channel | |||
) | [static] |
Definition at line 3153 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::b_stid, misdn_bchannel::cause, misdn_bchannel::channel, misdn_bchannel::channel_preselected, misdn_bchannel::in_use, misdn_bchannel::layer_id, mypid, misdn_bchannel::need_disconnect, misdn_bchannel::need_release, misdn_bchannel::need_release_complete, and misdn_bchannel::pid.
Referenced by misdn_lib_get_free_bc().
03154 { 03155 bc->channel = channel; 03156 bc->channel_preselected = channel?1:0; 03157 bc->in_use = 1; 03158 bc->need_disconnect=1; 03159 bc->need_release=1; 03160 bc->need_release_complete=1; 03161 bc->cause=16; 03162 03163 if (++mypid>5000) mypid=1; 03164 bc->pid=mypid; 03165 03166 #if 0 03167 bc->addr=0; 03168 bc->b_stid=0; 03169 bc->layer_id=0; 03170 #endif 03171 }
int queue_cleanup_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3738 of file isdn_lib.c.
References misdn_lib::activatequeue, misdn_stack::bc, cb_log, glob_mgr, misdn_bchannel::l3_id, misdn_lib::new_msg, and misdn_bchannel::port.
03739 { 03740 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03741 iframe_t *frm; 03742 if (!msg) { 03743 cb_log(0, bc->port, "misgn_lib_get_port: alloc_msg failed!\n"); 03744 return -1; 03745 } 03746 frm=(iframe_t*)msg->data; 03747 03748 /* activate bchannel */ 03749 frm->prim = MGR_CLEARSTACK| REQUEST; 03750 03751 frm->addr = bc->l3_id; 03752 03753 frm->dinfo = bc->port; 03754 frm->len = 0; 03755 03756 msg_queue_tail(&glob_mgr->activatequeue, msg); 03757 sem_post(&glob_mgr->new_msg); 03758 03759 return 0; 03760 03761 }
int release_cr | ( | struct misdn_stack * | stack, | |
mISDNuser_head_t * | hh | |||
) |
Definition at line 1790 of file isdn_lib.c.
References misdn_bchannel::addr, cb_log, find_bc_by_l3id(), handle_cr(), misdn_bchannel::l3_id, misdn_make_dummy(), misdn_stack::nt, misdn_stack::port, misdn_stack::procids, and misdn_stack::upper_id.
Referenced by handle_event_nt().
01791 { 01792 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01793 struct misdn_bchannel dummybc; 01794 iframe_t frm; /* fake te frm to remove callref from global callreflist */ 01795 frm.dinfo = hh->dinfo; 01796 01797 frm.addr=stack->upper_id | FLG_MSG_DOWN; 01798 01799 frm.prim = CC_RELEASE_CR|INDICATION; 01800 cb_log(4, stack->port, " --> CC_RELEASE_CR: Faking Realease_cr for %x l3id:%x\n",frm.addr, frm.dinfo); 01801 /** removing procid **/ 01802 if (!bc) { 01803 cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", hh->dinfo); 01804 misdn_make_dummy(&dummybc, stack->port, hh->dinfo, stack->nt, 0); 01805 bc=&dummybc; 01806 } 01807 01808 if (bc) { 01809 if ( (bc->l3_id & 0xff00) == 0xff00) { 01810 cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", bc->l3_id&0xff); 01811 stack->procids[bc->l3_id&0xff] = 0 ; 01812 } 01813 } 01814 else cb_log(0, stack->port, "Couldnt find BC so I couldnt remove the Process!!!! this is a bad port.\n"); 01815 01816 if (handle_cr(stack, &frm)<0) { 01817 } 01818 01819 return 0 ; 01820 }
static int send_msg | ( | int | midev, | |
struct misdn_bchannel * | bc, | |||
msg_t * | dmsg | |||
) | [static] |
Definition at line 405 of file isdn_lib.c.
References cb_log, get_stack_by_bc(), misdn_bchannel::l3_id, and misdn_bchannel::port.
Referenced by manager_event_handler().
00406 { 00407 iframe_t *frm = (iframe_t *)dmsg->data; 00408 struct misdn_stack *stack=get_stack_by_bc(bc); 00409 00410 if (!stack) { 00411 cb_log(0,bc->port,"send_msg: IEK!! no stack\n "); 00412 return -1; 00413 } 00414 00415 frm->addr = (stack->upper_id | FLG_MSG_DOWN); 00416 frm->dinfo = bc->l3_id; 00417 frm->len = (dmsg->len) - mISDN_HEADER_LEN; 00418 00419 cb_log(4,stack->port,"Sending msg, prim:%x addr:%x dinfo:%x\n",frm->prim,frm->addr,frm->dinfo); 00420 00421 mISDN_write(midev, dmsg->data, dmsg->len, TIMEOUT_1SEC); 00422 free_msg(dmsg); 00423 00424 return 0; 00425 }
int set_chan_in_stack | ( | struct misdn_stack * | stack, | |
int | channel | |||
) | [static] |
Definition at line 476 of file isdn_lib.c.
References cb_log, misdn_stack::channels, dump_chan_list(), MAX_BCHANS, and misdn_stack::port.
Referenced by handle_frm().
00477 { 00478 00479 cb_log(4,stack->port,"set_chan_in_stack: %d\n",channel); 00480 dump_chan_list(stack); 00481 if (channel >=1 && channel <= MAX_BCHANS) { 00482 if (!stack->channels[channel-1]) 00483 stack->channels[channel-1] = 1; 00484 else { 00485 cb_log(4,stack->port,"channel already in use:%d\n", channel ); 00486 return -1; 00487 } 00488 } else { 00489 cb_log(0,stack->port,"couldn't set channel %d in\n", channel ); 00490 return -1; 00491 } 00492 00493 return 0; 00494 }
int setup_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 967 of file isdn_lib.c.
References misdn_stack::b_num, misdn_bchannel::b_stid, misdn_stack::b_stids, misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), BCHAN_CLEANED, buff, cb_log, misdn_bchannel::channel, get_stack_by_bc(), misdn_stack::midev, misdn_stack::port, and misdn_bchannel::port.
Referenced by handle_event(), misdn_lib_send_event(), and misdn_lib_setup_bc().
00968 { 00969 unsigned char buff[1025]; 00970 int midev, channel, b_stid, i; 00971 mISDN_pid_t pid; 00972 int ret; 00973 00974 struct misdn_stack *stack=get_stack_by_bc(bc); 00975 00976 if (!stack) { 00977 cb_log(0, bc->port, "setup_bc: NO STACK FOUND!!\n"); 00978 return -1; 00979 } 00980 00981 midev = stack->midev; 00982 channel = bc->channel - 1 - (bc->channel > 16); 00983 b_stid = stack->b_stids[channel >= 0 ? channel : 0]; 00984 00985 switch (bc->bc_state) { 00986 case BCHAN_CLEANED: 00987 break; 00988 default: 00989 cb_log(4, stack->port, "$$$ bc already upsetted stid :%x (state:%s)\n", b_stid, bc_state2str(bc->bc_state) ); 00990 return -1; 00991 } 00992 00993 cb_log(5, stack->port, "$$$ Setting up bc with stid :%x\n", b_stid); 00994 00995 /*check if the b_stid is alread initialized*/ 00996 for (i=0; i <= stack->b_num; i++) { 00997 if (stack->bc[i].b_stid == b_stid) { 00998 cb_log(0, bc->port, "setup_bc: b_stid:%x already in use !!!\n", b_stid); 00999 return -1; 01000 } 01001 } 01002 01003 if (b_stid <= 0) { 01004 cb_log(0, stack->port," -- Stid <=0 at the moment in channel:%d\n",channel); 01005 01006 bc_state_change(bc,BCHAN_ERROR); 01007 return 1; 01008 } 01009 01010 bc->b_stid = b_stid; 01011 01012 { 01013 layer_info_t li; 01014 memset(&li, 0, sizeof(li)); 01015 01016 li.object_id = -1; 01017 li.extentions = 0; 01018 01019 li.st = bc->b_stid; /* given idx */ 01020 01021 01022 #define MISDN_DSP 01023 #ifndef MISDN_DSP 01024 bc->nodsp=1; 01025 #endif 01026 if ( bc->hdlc || bc->nodsp) { 01027 cb_log(4, stack->port,"setup_bc: without dsp\n"); 01028 { 01029 int l = sizeof(li.name); 01030 strncpy(li.name, "B L3", l); 01031 li.name[l-1] = 0; 01032 } 01033 li.pid.layermask = ISDN_LAYER((3)); 01034 li.pid.protocol[3] = ISDN_PID_L3_B_USER; 01035 01036 bc->layer=3; 01037 } else { 01038 cb_log(4, stack->port,"setup_bc: with dsp\n"); 01039 { 01040 int l = sizeof(li.name); 01041 strncpy(li.name, "B L4", l); 01042 li.name[l-1] = 0; 01043 } 01044 li.pid.layermask = ISDN_LAYER((4)); 01045 li.pid.protocol[4] = ISDN_PID_L4_B_USER 01046 ; 01047 bc->layer=4; 01048 01049 } 01050 01051 ret = mISDN_new_layer(midev, &li); 01052 if (ret ) { 01053 cb_log(0, stack->port,"New Layer Err: %d %s\n",ret,strerror(errno)); 01054 01055 bc_state_change(bc,BCHAN_ERROR); 01056 return(-EINVAL); 01057 } 01058 01059 bc->layer_id = li.id; 01060 } 01061 01062 memset(&pid, 0, sizeof(pid)); 01063 01064 01065 01066 cb_log(4, stack->port," --> Channel is %d\n", bc->channel); 01067 01068 if (bc->nodsp) { 01069 cb_log(2, stack->port," --> TRANSPARENT Mode (no DSP, no HDLC)\n"); 01070 pid.protocol[1] = ISDN_PID_L1_B_64TRANS; 01071 pid.protocol[2] = ISDN_PID_L2_B_TRANS; 01072 pid.protocol[3] = ISDN_PID_L3_B_USER; 01073 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)); 01074 01075 } else if ( bc->hdlc ) { 01076 cb_log(2, stack->port," --> HDLC Mode\n"); 01077 pid.protocol[1] = ISDN_PID_L1_B_64HDLC ; 01078 pid.protocol[2] = ISDN_PID_L2_B_TRANS ; 01079 pid.protocol[3] = ISDN_PID_L3_B_USER; 01080 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) ; 01081 } else { 01082 cb_log(2, stack->port," --> TRANSPARENT Mode\n"); 01083 pid.protocol[1] = ISDN_PID_L1_B_64TRANS; 01084 pid.protocol[2] = ISDN_PID_L2_B_TRANS; 01085 pid.protocol[3] = ISDN_PID_L3_B_DSP; 01086 pid.protocol[4] = ISDN_PID_L4_B_USER; 01087 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) | ISDN_LAYER((4)); 01088 01089 } 01090 01091 ret = mISDN_set_stack(midev, bc->b_stid, &pid); 01092 01093 if (ret){ 01094 cb_log(0, stack->port,"$$$ Set Stack Err: %d %s\n",ret,strerror(errno)); 01095 01096 mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01097 01098 bc_state_change(bc,BCHAN_ERROR); 01099 cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data); 01100 return(-EINVAL); 01101 } 01102 01103 ret = mISDN_get_setstack_ind(midev, bc->layer_id); 01104 01105 if (ret) { 01106 cb_log(0, stack->port,"$$$ Set StackIND Err: %d %s\n",ret,strerror(errno)); 01107 mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01108 01109 bc_state_change(bc,BCHAN_ERROR); 01110 cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data); 01111 return(-EINVAL); 01112 } 01113 01114 ret = mISDN_get_layerid(midev, bc->b_stid, bc->layer) ; 01115 01116 bc->addr = ret>0? ret : 0; 01117 01118 if (!bc->addr) { 01119 cb_log(0, stack->port,"$$$ Get Layerid Err: %d %s\n",ret,strerror(errno)); 01120 mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01121 01122 bc_state_change(bc,BCHAN_ERROR); 01123 cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data); 01124 return (-EINVAL); 01125 } 01126 01127 manager_bchannel_activate(bc); 01128 01129 bc_state_change(bc,BCHAN_ACTIVATED); 01130 01131 return 0; 01132 }
void stack_destroy | ( | struct misdn_stack * | stack | ) |
Definition at line 1386 of file isdn_lib.c.
References buf, misdn_stack::lower_id, misdn_stack::midev, misdn_stack::nst, misdn_stack::nt, and misdn_stack::upper_id.
Referenced by misdn_lib_destroy().
01387 { 01388 char buf[1024]; 01389 if (!stack) return; 01390 01391 if (stack->nt) { 01392 cleanup_Isdnl2(&stack->nst); 01393 cleanup_Isdnl3(&stack->nst); 01394 } 01395 01396 if (stack->lower_id) 01397 mISDN_write_frame(stack->midev, buf, stack->lower_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01398 01399 if (stack->upper_id) 01400 mISDN_write_frame(stack->midev, buf, stack->upper_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01401 }
void stack_holder_add | ( | struct misdn_stack * | stack, | |
struct misdn_bchannel * | holder | |||
) |
Definition at line 4325 of file isdn_lib.c.
References cb_log, misdn_stack::holding, misdn_bchannel::l3_id, misdn_bchannel::next, misdn_stack::port, and misdn_bchannel::stack_holder.
Referenced by misdn_lib_send_event().
04326 { 04327 struct misdn_bchannel *help; 04328 cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id); 04329 04330 holder->stack_holder=1; 04331 04332 if (!stack ) return ; 04333 04334 holder->next=NULL; 04335 04336 if (!stack->holding) { 04337 stack->holding = holder; 04338 return; 04339 } 04340 04341 for (help=stack->holding; 04342 help; 04343 help=help->next) { 04344 if (!help->next) { 04345 help->next=holder; 04346 break; 04347 } 04348 } 04349 04350 }
struct misdn_bchannel * stack_holder_find | ( | struct misdn_stack * | stack, | |
unsigned long | l3id | |||
) |
Definition at line 4400 of file isdn_lib.c.
References cb_log, misdn_stack::holding, misdn_bchannel::l3_id, misdn_bchannel::next, and misdn_stack::port.
Referenced by find_bc_by_l3id(), find_bc_by_masked_l3id(), and handle_event_nt().
04401 { 04402 struct misdn_bchannel *help; 04403 04404 cb_log(4,stack?stack->port:0, "*HOLDER: find %lx\n",l3id); 04405 04406 if (!stack) return NULL; 04407 04408 for (help=stack->holding; 04409 help; 04410 help=help->next) { 04411 if (help->l3_id == l3id) { 04412 cb_log(4,stack->port, "*HOLDER: found bc\n"); 04413 return help; 04414 } 04415 } 04416 04417 cb_log(4,stack->port, "*HOLDER: find nothing\n"); 04418 return NULL; 04419 }
struct misdn_bchannel * stack_holder_find_bychan | ( | struct misdn_stack * | stack, | |
int | chan | |||
) |
Definition at line 4378 of file isdn_lib.c.
References cb_log, misdn_bchannel::channel, misdn_stack::holding, misdn_bchannel::next, and misdn_stack::port.
04379 { 04380 struct misdn_bchannel *help; 04381 04382 cb_log(4,stack?stack->port:0, "*HOLDER: find_bychan %c\n", chan); 04383 04384 if (!stack) return NULL; 04385 04386 for (help=stack->holding; 04387 help; 04388 help=help->next) { 04389 if (help->channel == chan) { 04390 cb_log(4,stack->port, "*HOLDER: found_bychan bc\n"); 04391 return help; 04392 } 04393 } 04394 04395 cb_log(4,stack->port, "*HOLDER: find_bychan nothing\n"); 04396 return NULL; 04397 04398 }
void stack_holder_remove | ( | struct misdn_stack * | stack, | |
struct misdn_bchannel * | holder | |||
) |
Definition at line 4352 of file isdn_lib.c.
References cb_log, misdn_stack::holding, misdn_bchannel::l3_id, misdn_bchannel::next, misdn_stack::port, and misdn_bchannel::stack_holder.
Referenced by handle_cr(), and handle_event_nt().
04353 { 04354 struct misdn_bchannel *h1; 04355 04356 if (!holder->stack_holder) return; 04357 04358 holder->stack_holder=0; 04359 04360 cb_log(4,stack->port, "*HOLDER: remove %x\n",holder->l3_id); 04361 if (!stack || ! stack->holding) return; 04362 04363 if (holder == stack->holding) { 04364 stack->holding = stack->holding->next; 04365 return; 04366 } 04367 04368 for (h1=stack->holding; 04369 h1; 04370 h1=h1->next) { 04371 if (h1->next == holder) { 04372 h1->next=h1->next->next; 04373 return ; 04374 } 04375 } 04376 }
struct misdn_stack * stack_init | ( | int | midev, | |
int | port, | |||
int | ptp | |||
) |
Definition at line 1201 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::b_stids, buff, cb_log, misdn_stack::channels, misdn_stack::d_stid, misdn_stack::downqueue, misdn_stack::holding, malloc, MAX_BCHANS, misdn_stack::midev, misdn_stack::nt, misdn_stack::port, misdn_stack::pri, misdn_stack::ptp, and misdn_stack::upqueue.
Referenced by misdn_lib_init().
01202 { 01203 int ret; 01204 unsigned char buff[1025]; 01205 iframe_t *frm = (iframe_t *)buff; 01206 stack_info_t *stinf; 01207 int i; 01208 layer_info_t li; 01209 01210 struct misdn_stack *stack = malloc(sizeof(struct misdn_stack)); 01211 if (!stack ) return NULL; 01212 01213 01214 cb_log(8, port, "Init. Stack.\n"); 01215 01216 memset(stack,0,sizeof(struct misdn_stack)); 01217 01218 for (i=0; i<MAX_BCHANS + 1; i++ ) stack->channels[i]=0; 01219 01220 stack->port=port; 01221 stack->midev=midev; 01222 stack->ptp=ptp; 01223 01224 stack->holding=NULL; 01225 stack->pri=0; 01226 01227 msg_queue_init(&stack->downqueue); 01228 msg_queue_init(&stack->upqueue); 01229 01230 /* query port's requirements */ 01231 ret = mISDN_get_stack_info(midev, port, buff, sizeof(buff)); 01232 if (ret < 0) { 01233 cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret); 01234 return(NULL); 01235 } 01236 01237 stinf = (stack_info_t *)&frm->data.p; 01238 01239 stack->d_stid = stinf->id; 01240 stack->b_num = stinf->childcnt; 01241 01242 for (i=0; i<=stinf->childcnt; i++) 01243 stack->b_stids[i] = stinf->child[i]; 01244 01245 switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK) { 01246 case ISDN_PID_L0_TE_S0: 01247 stack->nt=0; 01248 break; 01249 case ISDN_PID_L0_NT_S0: 01250 cb_log(8, port, "NT Stack\n"); 01251 01252 stack->nt=1; 01253 break; 01254 case ISDN_PID_L0_TE_E1: 01255 cb_log(8, port, "TE S2M Stack\n"); 01256 stack->nt=0; 01257 stack->pri=1; 01258 break; 01259 case ISDN_PID_L0_NT_E1: 01260 cb_log(8, port, "TE S2M Stack\n"); 01261 stack->nt=1; 01262 stack->pri=1; 01263 01264 break; 01265 default: 01266 cb_log(0, port, "this is a unknown port type 0x%08x\n", stinf->pid.protocol[0]); 01267 01268 } 01269 01270 if (!stack->nt) { 01271 if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP ) { 01272 stack->ptp = 1; 01273 } else { 01274 stack->ptp = 0; 01275 } 01276 } 01277 01278 { 01279 int ret; 01280 int nt=stack->nt; 01281 01282 cb_log(8, port, "Init. Stack.\n"); 01283 01284 memset(&li, 0, sizeof(li)); 01285 { 01286 int l = sizeof(li.name); 01287 strncpy(li.name,nt?"net l2":"user l4", l); 01288 li.name[l-1] = 0; 01289 } 01290 li.object_id = -1; 01291 li.extentions = 0; 01292 li.pid.protocol[nt?2:4] = nt?ISDN_PID_L2_LAPD_NET:ISDN_PID_L4_CAPI20; 01293 li.pid.layermask = ISDN_LAYER((nt?2:4)); 01294 li.st = stack->d_stid; 01295 01296 01297 ret = mISDN_new_layer(midev, &li); 01298 if (ret) { 01299 cb_log(0, port, "%s: Cannot add layer %d to this port.\n", __FUNCTION__, nt?2:4); 01300 return(NULL); 01301 } 01302 01303 01304 stack->upper_id = li.id; 01305 ret = mISDN_register_layer(midev, stack->d_stid, stack->upper_id); 01306 if (ret) 01307 { 01308 cb_log(0,port,"Cannot register layer %d of this port.\n", nt?2:4); 01309 return(NULL); 01310 } 01311 01312 stack->lower_id = mISDN_get_layerid(midev, stack->d_stid, nt?1:3); 01313 if (stack->lower_id < 0) { 01314 cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, nt?1:3); 01315 return(NULL); 01316 } 01317 01318 stack->upper_id = mISDN_get_layerid(midev, stack->d_stid, nt?2:4); 01319 if (stack->upper_id < 0) { 01320 cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, 2); 01321 return(NULL); 01322 } 01323 01324 cb_log(8, port, "NT Stacks upper_id %x\n",stack->upper_id); 01325 01326 01327 /* create nst (nt-mode only) */ 01328 if (nt) { 01329 01330 memset(&stack->nst, 0, sizeof(net_stack_t)); 01331 memset(&stack->mgr, 0, sizeof(manager_t)); 01332 01333 stack->mgr.nst = &stack->nst; 01334 stack->nst.manager = &stack->mgr; 01335 01336 stack->nst.l3_manager = handle_event_nt; 01337 stack->nst.device = midev; 01338 stack->nst.cardnr = port; 01339 stack->nst.d_stid = stack->d_stid; 01340 01341 stack->nst.feature = FEATURE_NET_HOLD; 01342 if (stack->ptp) 01343 stack->nst.feature |= FEATURE_NET_PTP; 01344 if (stack->pri) 01345 stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID; 01346 01347 stack->nst.l1_id = stack->lower_id; 01348 stack->nst.l2_id = stack->upper_id; 01349 01350 msg_queue_init(&stack->nst.down_queue); 01351 01352 Isdnl2Init(&stack->nst); 01353 Isdnl3Init(&stack->nst); 01354 01355 } 01356 01357 if (!stack->nt) { 01358 /*assume L1 is up, we'll get DEACTIVATES soon, for non 01359 * up L1s*/ 01360 stack->l1link=0; 01361 } 01362 stack->l1link=0; 01363 stack->l2link=0; 01364 #if 0 01365 if (!stack->nt) { 01366 misdn_lib_get_short_status(stack); 01367 } else { 01368 misdn_lib_get_l1_up(stack); 01369 if (!stack->ptp) misdn_lib_get_l1_up(stack); 01370 misdn_lib_get_l2_up(stack); 01371 } 01372 #endif 01373 01374 misdn_lib_get_short_status(stack); 01375 misdn_lib_get_l1_up(stack); 01376 misdn_lib_get_l2_up(stack); 01377 01378 } 01379 01380 cb_log(8,0,"stack_init: port:%d lowerId:%x upperId:%x\n",stack->port,stack->lower_id, stack->upper_id); 01381 01382 return stack; 01383 }
void te_lib_destroy | ( | int | midev | ) |
Definition at line 3093 of file isdn_lib.c.
References buf, cb_log, and entity.
Referenced by misdn_lib_destroy().
03094 { 03095 char buf[1024]; 03096 mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC); 03097 03098 cb_log(4, 0, "Entetity deleted\n"); 03099 mISDN_close(midev); 03100 cb_log(4, 0, "midev closed\n"); 03101 }
int te_lib_init | ( | void | ) |
App Interface
Definition at line 3066 of file isdn_lib.c.
References buff, entity, errno, and misdn_lib::midev.
Referenced by misdn_lib_init().
03066 { 03067 char buff[1025] = ""; 03068 iframe_t *frm=(iframe_t*)buff; 03069 int midev=mISDN_open(); 03070 int ret; 03071 03072 if (midev<=0) return midev; 03073 03074 /* create entity for layer 3 TE-mode */ 03075 mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 03076 ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC); 03077 03078 if (ret < mISDN_HEADER_LEN) { 03079 noentity: 03080 fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n",strerror(errno)); 03081 exit(-1); 03082 } 03083 03084 entity = frm->dinfo & 0xffff ; 03085 03086 if (!entity) 03087 goto noentity; 03088 03089 return midev; 03090 03091 }
static int test_inuse | ( | struct misdn_bchannel * | bc | ) | [static] |
Definition at line 3133 of file isdn_lib.c.
References misdn_bchannel::b_stid, cb_log, misdn_bchannel::in_use, misdn_bchannel::last_used, misdn_lib_port_is_pri(), and misdn_bchannel::port.
Referenced by misdn_lib_get_free_bc().
03134 { 03135 struct timeval now; 03136 gettimeofday(&now, NULL); 03137 if (!bc->in_use) { 03138 if (misdn_lib_port_is_pri(bc->port) && bc->last_used.tv_sec == now.tv_sec ) { 03139 cb_log(2,bc->port, "channel with stid:%x for one second still in use! (n:%d lu:%d)\n", bc->b_stid, (int) now.tv_sec, (int) bc->last_used.tv_sec); 03140 return 1; 03141 } 03142 03143 03144 cb_log(3,bc->port, "channel with stid:%x not in use!\n", bc->b_stid); 03145 return 0; 03146 } 03147 03148 cb_log(2,bc->port, "channel with stid:%x in use!\n", bc->b_stid); 03149 return 1; 03150 }
int entity [static] |
char flip_table[256] [static] |
Definition at line 251 of file isdn_lib.c.
Referenced by do_tone(), find_bc_by_addr(), find_bc_by_confid(), find_stack_by_addr(), find_stack_by_mgr(), find_stack_by_port(), get_misdn_stack(), handle_bchan(), handle_cr(), handle_event_nt(), handle_frm(), handle_l1(), handle_l2(), handle_timers(), manager_event_handler(), manager_find_bc_by_pid(), manager_ph_control(), manager_ph_control_block(), misdn_lib_destroy(), misdn_lib_get_free_bc(), misdn_lib_get_port_down(), misdn_lib_get_port_info(), misdn_lib_get_port_up(), misdn_lib_init(), misdn_lib_isdn_l1watcher(), misdn_lib_port_restart(), misdn_lib_port_up(), misdn_lib_reinit_nt_stack(), misdn_lib_send_event(), misdn_lib_send_tone(), misdn_tx_jitter(), and queue_cleanup_bc().
enum global_states global_state = MISDN_INITIALIZING [static] |
Definition at line 182 of file isdn_lib.c.
Referenced by clear_l3(), handle_l1(), and misdn_lib_destroy().
sem_t handler_started |
Definition at line 3853 of file isdn_lib.c.
Msg Array
Definition at line 1163 of file isdn_msg_parser.c.
Referenced by handle_event_nt(), handle_frm(), handle_l1(), manager_isdn_get_info(), and misdn_lib_send_event().
int mypid = 1 [static] |
int new_te_id = 0 [static] |
Definition at line 782 of file isdn_lib.c.
int nt_err_cnt = 0 [static] |
char tone_425_flip[TONE_425_SIZE] |
char tone_silence_flip[TONE_SILENCE_SIZE] |