#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 3256 of file isdn_lib.c.
References s.
Referenced by misdn_lib_log_ies().
03257 { 03258 struct arr_el { 03259 enum FacFunction p; 03260 char *s ; 03261 } arr[] = { 03262 { Fac_None, "Fac_None" }, 03263 { Fac_CD, "Fac_CD"}, 03264 }; 03265 03266 int i; 03267 03268 for (i=0; i < sizeof(arr)/sizeof( struct arr_el) ; i ++) 03269 if ( arr[i].p==func) return arr[i].s; 03270 03271 return "unknown"; 03272 }
static msg_t* fetch_msg | ( | int | midev | ) | [static] |
Definition at line 2966 of file isdn_lib.c.
References cb_log, errno, and msg.
Referenced by misdn_lib_isdn_event_catcher().
02967 { 02968 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 02969 int r; 02970 02971 if (!msg) { 02972 cb_log(0, 0, "fetch_msg: alloc msg failed !!"); 02973 return NULL; 02974 } 02975 02976 AGAIN: 02977 r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC); 02978 msg->len=r; 02979 02980 if (r==0) { 02981 free_msg(msg); /* danger, cauz usualy freeing in main_loop */ 02982 cb_log(6,0,"Got empty Msg..\n"); 02983 return NULL; 02984 } 02985 02986 if (r<0) { 02987 if (errno == EAGAIN) { 02988 /*we wait for mISDN here*/ 02989 cb_log(4,0,"mISDN_read wants us to wait\n"); 02990 usleep(5000); 02991 goto AGAIN; 02992 } 02993 02994 cb_log(0,0,"mISDN_read returned :%d error:%s (%d)\n",r,strerror(errno),errno); 02995 } 02996 02997 #if 0 02998 if (!(frm->prim == (DL_DATA|INDICATION) )|| (frm->prim == (PH_DATA|INDICATION))) 02999 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 ); 03000 #endif 03001 return msg; 03002 }
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 4529 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().
04529 { 04530 return glob_mgr->stack_list; 04531 }
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 2315 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().
02316 { 02317 iframe_t *frm= (iframe_t*)msg->data; 02318 struct misdn_bchannel *bc=find_bc_by_addr(frm->addr); 02319 struct misdn_stack *stack; 02320 02321 if (!bc) { 02322 cb_log(1,0,"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo); 02323 return 0 ; 02324 } 02325 02326 stack = get_stack_by_bc(bc); 02327 02328 if (!stack) { 02329 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); 02330 return 0; 02331 } 02332 02333 switch (frm->prim) { 02334 02335 case MGR_SETSTACK| CONFIRM: 02336 cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|CONFIRM pid:%d\n",bc->pid); 02337 break; 02338 02339 case MGR_SETSTACK| INDICATION: 02340 cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->pid); 02341 break; 02342 #if 0 02343 AGAIN: 02344 bc->addr = mISDN_get_layerid(stack->midev, bc->b_stid, bc->layer); 02345 if (!bc->addr) { 02346 02347 if (errno == EAGAIN) { 02348 usleep(1000); 02349 goto AGAIN; 02350 } 02351 02352 cb_log(0,stack->port,"$$$ Get Layer (%d) Id Error: %s\n",bc->layer,strerror(errno)); 02353 02354 /* we kill the channel later, when we received some 02355 data. */ 02356 bc->addr= frm->addr; 02357 } else if ( bc->addr < 0) { 02358 cb_log(0, stack->port,"$$$ bc->addr <0 Error:%s\n",strerror(errno)); 02359 bc->addr=0; 02360 } 02361 02362 cb_log(4, stack->port," --> Got Adr %x\n", bc->addr); 02363 02364 free_msg(msg); 02365 02366 02367 switch(bc->bc_state) { 02368 case BCHAN_SETUP: 02369 bc_state_change(bc,BCHAN_SETUPED); 02370 break; 02371 02372 case BCHAN_CLEAN_REQUEST: 02373 default: 02374 cb_log(0, stack->port," --> STATE WASN'T SETUP (but %s) in SETSTACK|IND pid:%d\n",bc_state2str(bc->bc_state), bc->pid); 02375 clean_up_bc(bc); 02376 } 02377 return 1; 02378 #endif 02379 02380 case MGR_DELLAYER| INDICATION: 02381 cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->pid); 02382 break; 02383 02384 case MGR_DELLAYER| CONFIRM: 02385 cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|CNF pid:%d\n",bc->pid); 02386 02387 bc->pid=0; 02388 bc->addr=0; 02389 02390 free_msg(msg); 02391 return 1; 02392 02393 case PH_ACTIVATE | INDICATION: 02394 case DL_ESTABLISH | INDICATION: 02395 cb_log(3, stack->port, "BCHAN: ACT Ind pid:%d\n", bc->pid); 02396 02397 free_msg(msg); 02398 return 1; 02399 02400 case PH_ACTIVATE | CONFIRM: 02401 case DL_ESTABLISH | CONFIRM: 02402 02403 cb_log(3, stack->port, "BCHAN: bchan ACT Confirm pid:%d\n",bc->pid); 02404 free_msg(msg); 02405 02406 return 1; 02407 02408 case DL_ESTABLISH | REQUEST: 02409 { 02410 char buf[128]; 02411 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_ESTABLISH | CONFIRM, 0,0, NULL, TIMEOUT_1SEC); 02412 } 02413 free_msg(msg); 02414 return 1; 02415 02416 case DL_RELEASE|REQUEST: 02417 { 02418 char buf[128]; 02419 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_RELEASE| CONFIRM, 0,0, NULL, TIMEOUT_1SEC); 02420 } 02421 free_msg(msg); 02422 return 1; 02423 02424 case PH_DEACTIVATE | INDICATION: 02425 case DL_RELEASE | INDICATION: 02426 cb_log (3, stack->port, "BCHAN: DeACT Ind pid:%d\n",bc->pid); 02427 02428 free_msg(msg); 02429 return 1; 02430 02431 case PH_DEACTIVATE | CONFIRM: 02432 case DL_RELEASE | CONFIRM: 02433 cb_log(3, stack->port, "BCHAN: DeACT Conf pid:%d\n",bc->pid); 02434 02435 free_msg(msg); 02436 return 1; 02437 02438 case PH_CONTROL|INDICATION: 02439 { 02440 unsigned int *cont = (unsigned int *) &frm->data.p; 02441 02442 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); 02443 02444 if ((*cont & ~DTMF_TONE_MASK) == DTMF_TONE_VAL) { 02445 int dtmf = *cont & DTMF_TONE_MASK; 02446 cb_log(4, stack->port, " --> DTMF TONE: %c\n",dtmf); 02447 bc->dtmf=dtmf; 02448 cb_event(EVENT_DTMF_TONE, bc, glob_mgr->user_data); 02449 02450 free_msg(msg); 02451 return 1; 02452 } 02453 if (*cont == BF_REJECT) { 02454 cb_log(4, stack->port, " --> BF REJECT\n"); 02455 free_msg(msg); 02456 return 1; 02457 } 02458 if (*cont == BF_ACCEPT) { 02459 cb_log(4, stack->port, " --> BF ACCEPT\n"); 02460 free_msg(msg); 02461 return 1; 02462 } 02463 } 02464 break; 02465 02466 case PH_DATA|REQUEST: 02467 case DL_DATA|REQUEST: 02468 cb_log(0, stack->port, "DL_DATA REQUEST \n"); 02469 do_tone(bc, 64); 02470 02471 free_msg(msg); 02472 return 1; 02473 02474 02475 case PH_DATA|INDICATION: 02476 case DL_DATA|INDICATION: 02477 { 02478 bc->bframe = (void*)&frm->data.i; 02479 bc->bframe_len = frm->len; 02480 02481 /** Anyway flip the bufbits **/ 02482 if ( misdn_cap_is_speech(bc->capability) ) 02483 flip_buf_bits(bc->bframe, bc->bframe_len); 02484 02485 02486 if (!bc->bframe_len) { 02487 cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); 02488 free_msg(msg); 02489 return 1; 02490 } 02491 02492 if ( (bc->addr&STACK_ID_MASK) != (frm->addr&STACK_ID_MASK) ) { 02493 cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); 02494 free_msg(msg); 02495 return 1; 02496 } 02497 02498 #if MISDN_DEBUG 02499 cb_log(0, stack->port, "DL_DATA INDICATION Len %d\n", frm->len); 02500 02501 #endif 02502 02503 if ( (bc->bc_state == BCHAN_ACTIVATED) && frm->len > 0) { 02504 int t; 02505 02506 #ifdef MISDN_B_DEBUG 02507 cb_log(0,bc->port,"do_tone START\n"); 02508 #endif 02509 t=do_tone(bc,frm->len); 02510 02511 #ifdef MISDN_B_DEBUG 02512 cb_log(0,bc->port,"do_tone STOP (%d)\n",t); 02513 #endif 02514 if ( !t ) { 02515 int i; 02516 02517 if ( misdn_cap_is_speech(bc->capability)) { 02518 if ( !bc->nojitter ) { 02519 #ifdef MISDN_B_DEBUG 02520 cb_log(0,bc->port,"tx_jitter START\n"); 02521 #endif 02522 misdn_tx_jitter(bc,frm->len); 02523 #ifdef MISDN_B_DEBUG 02524 cb_log(0,bc->port,"tx_jitter STOP\n"); 02525 #endif 02526 } 02527 } 02528 02529 #ifdef MISDN_B_DEBUG 02530 cb_log(0,bc->port,"EVENT_B_DATA START\n"); 02531 #endif 02532 02533 i = cb_event(EVENT_BCHAN_DATA, bc, glob_mgr->user_data); 02534 #ifdef MISDN_B_DEBUG 02535 cb_log(0,bc->port,"EVENT_B_DATA STOP\n"); 02536 #endif 02537 02538 if (i<0) { 02539 cb_log(10,stack->port,"cb_event returned <0\n"); 02540 /*clean_up_bc(bc);*/ 02541 } 02542 } 02543 } 02544 free_msg(msg); 02545 return 1; 02546 } 02547 02548 02549 case PH_CONTROL | CONFIRM: 02550 cb_log(4, stack->port, "PH_CONTROL|CNF bc->addr:%x\n", frm->addr); 02551 free_msg(msg); 02552 return 1; 02553 02554 case PH_DATA | CONFIRM: 02555 case DL_DATA|CONFIRM: 02556 #if MISDN_DEBUG 02557 02558 cb_log(0, stack->port, "Data confirmed\n"); 02559 02560 #endif 02561 free_msg(msg); 02562 return 1; 02563 case DL_DATA|RESPONSE: 02564 #if MISDN_DEBUG 02565 cb_log(0, stack->port, "Data response\n"); 02566 02567 #endif 02568 break; 02569 } 02570 02571 return 0; 02572 }
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 3547 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().
03548 { 03549 iframe_t *frm = (iframe_t*) msg->data; 03550 03551 03552 if (!frm->addr) { 03553 static int cnt=0; 03554 if (!cnt) 03555 cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo); 03556 cnt++; 03557 if (cnt>100) { 03558 cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo); 03559 cnt=0; 03560 } 03561 03562 free_msg(msg); 03563 return 1; 03564 03565 } 03566 03567 switch (frm->prim) { 03568 case MGR_SETSTACK|INDICATION: 03569 return handle_bchan(msg); 03570 break; 03571 03572 case MGR_SETSTACK|CONFIRM: 03573 case MGR_CLEARSTACK|CONFIRM: 03574 free_msg(msg) ; 03575 return 1; 03576 break; 03577 03578 case DL_DATA|CONFIRM: 03579 cb_log(4,0,"DL_DATA|CONFIRM\n"); 03580 free_msg(msg); 03581 return 1; 03582 03583 case PH_CONTROL|CONFIRM: 03584 cb_log(4,0,"PH_CONTROL|CONFIRM\n"); 03585 free_msg(msg); 03586 return 1; 03587 03588 case DL_DATA|INDICATION: 03589 { 03590 int port=(frm->addr&MASTER_ID_MASK) >> 8; 03591 int channel=(frm->addr&CHILD_ID_MASK) >> 16; 03592 struct misdn_bchannel *bc; 03593 03594 /*we flush the read buffer here*/ 03595 03596 cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel); 03597 03598 free_msg(msg); 03599 return 1; 03600 03601 03602 bc = find_bc_by_channel(port, channel); 03603 03604 if (!bc) { 03605 struct misdn_stack *stack = find_stack_by_port(port); 03606 03607 if (!stack) { 03608 cb_log(0,0," --> stack not found\n"); 03609 free_msg(msg); 03610 return 1; 03611 } 03612 03613 cb_log(0,0," --> bc not found by channel\n"); 03614 if (stack->l2link) 03615 misdn_lib_get_l2_down(stack); 03616 03617 if (stack->l1link) 03618 misdn_lib_get_l1_down(stack); 03619 03620 free_msg(msg); 03621 return 1; 03622 } 03623 03624 cb_log(3,port," --> BC in state:%s\n", bc_state2str(bc->bc_state)); 03625 } 03626 } 03627 03628 return 0; 03629 }
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().
Referenced by handle_frm().
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 2611 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().
02612 { 02613 iframe_t *frm = (iframe_t*) msg->data; 02614 02615 struct misdn_stack *stack=find_stack_by_addr(frm->addr); 02616 02617 if (!stack || stack->nt) { 02618 return 0; 02619 } 02620 02621 cb_log(4,stack?stack->port:0,"handle_frm: frm->addr:%x frm->prim:%x\n",frm->addr,frm->prim); 02622 02623 { 02624 struct misdn_bchannel dummybc; 02625 struct misdn_bchannel *bc; 02626 int ret=handle_cr(stack, frm); 02627 02628 if (ret<0) { 02629 cb_log(3,stack?stack->port:0,"handle_frm: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr); 02630 02631 02632 } 02633 02634 if(ret) { 02635 free_msg(msg); 02636 return 1; 02637 } 02638 02639 bc=find_bc_by_l3id(stack, frm->dinfo); 02640 02641 if (!bc && (frm->prim==(CC_RESTART|CONFIRM)) ) { 02642 misdn_make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0); 02643 bc=&dummybc; 02644 } 02645 02646 if (!bc && (frm->prim==(CC_SETUP|INDICATION)) ) { 02647 misdn_make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0); 02648 dummybc.port=stack->port; 02649 dummybc.l3_id=frm->dinfo; 02650 bc=&dummybc; 02651 02652 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 02653 02654 free_msg(msg); 02655 return 1; 02656 } 02657 02658 02659 handle_frm_bc: 02660 if (bc ) { 02661 enum event_e event = isdn_msg_get_event(msgs_g, msg, 0); 02662 enum event_response_e response=RESPONSE_OK; 02663 int ret; 02664 02665 isdn_msg_parse_event(msgs_g,msg,bc, 0); 02666 02667 /** Preprocess some Events **/ 02668 ret = handle_event(bc, event, frm); 02669 if (ret<0) { 02670 cb_log(0,stack->port,"couldn't handle event\n"); 02671 free_msg(msg); 02672 return 1; 02673 } 02674 /* shoot up event to App: */ 02675 cb_log(5, stack->port, "lib Got Prim: Addr %x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo); 02676 02677 if(!isdn_get_info(msgs_g,event,0)) 02678 cb_log(0, stack->port, "Unknown Event Ind: Addr:%x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo); 02679 else 02680 response=cb_event(event, bc, glob_mgr->user_data); 02681 #if 1 02682 if (event == EVENT_SETUP) { 02683 switch (response) { 02684 case RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE: 02685 02686 cb_log(0, stack->port, "TOTALY IGNORING SETUP \n"); 02687 02688 break; 02689 case RESPONSE_IGNORE_SETUP: 02690 /* I think we should send CC_RELEASE_CR, but am not sure*/ 02691 bc->out_cause=16; 02692 02693 case RESPONSE_RELEASE_SETUP: 02694 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 02695 if (bc->channel>0) 02696 empty_chan_in_stack(stack, bc->channel); 02697 empty_bc(bc); 02698 bc_state_change(bc,BCHAN_CLEANED); 02699 bc->in_use=0; 02700 02701 cb_log(0, stack->port, "GOT IGNORE SETUP\n"); 02702 break; 02703 case RESPONSE_OK: 02704 cb_log(4, stack->port, "GOT SETUP OK\n"); 02705 02706 02707 break; 02708 default: 02709 break; 02710 } 02711 } 02712 02713 if (event == EVENT_RELEASE_COMPLETE) { 02714 /* release bchannel only after we've anounced the RELEASE_COMPLETE */ 02715 int channel=bc->channel; 02716 int tmpcause=bc->cause; 02717 int tmp_out_cause=bc->out_cause; 02718 empty_bc(bc); 02719 bc->cause=tmpcause; 02720 bc->out_cause=tmp_out_cause; 02721 clean_up_bc(bc); 02722 02723 if (tmpcause == 44) { 02724 cb_log(0,stack->port,"**** Received CAUSE:44, so not cleaning up channel %d\n", channel); 02725 cb_log(0,stack->port,"**** This channel is now no longer available,\nplease try to restart it with 'misdn send restart <port> <channel>'\n"); 02726 set_chan_in_stack(stack, channel); 02727 bc->channel=channel; 02728 misdn_lib_send_restart(stack->port, channel); 02729 } else { 02730 if (channel>0) 02731 empty_chan_in_stack(stack, channel); 02732 } 02733 bc->in_use=0; 02734 } 02735 02736 if (event == EVENT_RESTART) { 02737 cb_log(0, stack->port, "**** Received RESTART_ACK channel:%d\n", bc->restart_channel); 02738 empty_chan_in_stack(stack, bc->restart_channel); 02739 } 02740 02741 cb_log(5, stack->port, "Freeing Msg on prim:%x \n",frm->prim); 02742 02743 02744 free_msg(msg); 02745 return 1; 02746 #endif 02747 02748 } else { 02749 struct misdn_bchannel dummybc; 02750 if (frm->prim!=(CC_FACILITY|INDICATION)) 02751 cb_log(0, stack->port, " --> Didn't find BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo); 02752 else 02753 cb_log(5, stack->port, " --> Using Dummy BC for FACILITy\n"); 02754 02755 memset (&dummybc,0,sizeof(dummybc)); 02756 dummybc.port=stack->port; 02757 dummybc.l3_id=frm->dinfo; 02758 bc=&dummybc; 02759 goto handle_frm_bc; 02760 } 02761 } 02762 02763 cb_log(4, stack->port, "TE_FRM_HANDLER: Returning 0 on prim:%x \n",frm->prim); 02764 return 0; 02765 }
static int handle_frm_nt | ( | msg_t * | msg | ) | [static] |
Definition at line 2576 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().
02577 { 02578 iframe_t *frm= (iframe_t*)msg->data; 02579 struct misdn_stack *stack; 02580 int err=0; 02581 02582 stack=find_stack_by_addr( frm->addr ); 02583 02584 02585 02586 if (!stack || !stack->nt) { 02587 return 0; 02588 } 02589 02590 02591 if ((err=stack->nst.l1_l2(&stack->nst,msg))) { 02592 02593 if (nt_err_cnt > 0 ) { 02594 if (nt_err_cnt < 100) { 02595 nt_err_cnt++; 02596 cb_log(0, stack->port, "NT Stack sends us error: %d \n", err); 02597 } else if (nt_err_cnt < 105){ 02598 cb_log(0, stack->port, "NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err); 02599 nt_err_cnt = - 1; 02600 } 02601 } 02602 free_msg(msg); 02603 return 1; 02604 02605 } 02606 02607 return 1; 02608 }
static int handle_l1 | ( | msg_t * | msg | ) | [static] |
Definition at line 2768 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().
02769 { 02770 iframe_t *frm = (iframe_t*) msg->data; 02771 struct misdn_stack *stack = find_stack_by_addr(frm->addr); 02772 int i ; 02773 02774 if (!stack) return 0 ; 02775 02776 switch (frm->prim) { 02777 case PH_ACTIVATE | CONFIRM: 02778 case PH_ACTIVATE | INDICATION: 02779 cb_log (3, stack->port, "L1: PH L1Link Up!\n"); 02780 stack->l1link=1; 02781 02782 if (stack->nt) { 02783 02784 if (stack->nst.l1_l2(&stack->nst, msg)) 02785 free_msg(msg); 02786 02787 if (stack->ptp) 02788 misdn_lib_get_l2_up(stack); 02789 } else { 02790 free_msg(msg); 02791 } 02792 02793 for (i=0;i<=stack->b_num; i++) { 02794 if (stack->bc[i].evq != EVENT_NOTHING) { 02795 cb_log(4, stack->port, "Fireing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0)); 02796 misdn_lib_send_event(&stack->bc[i],stack->bc[i].evq); 02797 stack->bc[i].evq=EVENT_NOTHING; 02798 } 02799 02800 } 02801 return 1; 02802 02803 case PH_ACTIVATE | REQUEST: 02804 free_msg(msg); 02805 cb_log(3,stack->port,"L1: PH_ACTIVATE|REQUEST \n"); 02806 return 1; 02807 02808 case PH_DEACTIVATE | REQUEST: 02809 free_msg(msg); 02810 cb_log(3,stack->port,"L1: PH_DEACTIVATE|REQUEST \n"); 02811 return 1; 02812 02813 case PH_DEACTIVATE | CONFIRM: 02814 case PH_DEACTIVATE | INDICATION: 02815 cb_log (3, stack->port, "L1: PH L1Link Down! \n"); 02816 02817 #if 0 02818 for (i=0; i<=stack->b_num; i++) { 02819 if (global_state == MISDN_INITIALIZED) { 02820 cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data); 02821 } 02822 } 02823 #endif 02824 02825 if (stack->nt) { 02826 if (stack->nst.l1_l2(&stack->nst, msg)) 02827 free_msg(msg); 02828 } else { 02829 free_msg(msg); 02830 } 02831 02832 stack->l1link=0; 02833 stack->l2link=0; 02834 return 1; 02835 } 02836 02837 return 0; 02838 }
static int handle_l2 | ( | msg_t * | msg | ) | [static] |
Definition at line 2840 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().
02841 { 02842 iframe_t *frm = (iframe_t*) msg->data; 02843 02844 struct misdn_stack *stack = find_stack_by_addr(frm->addr); 02845 02846 if (!stack) { 02847 return 0 ; 02848 } 02849 02850 switch(frm->prim) { 02851 02852 case DL_ESTABLISH | REQUEST: 02853 cb_log(1,stack->port,"DL_ESTABLISH|REQUEST \n"); 02854 return 1; 02855 case DL_RELEASE | REQUEST: 02856 cb_log(1,stack->port,"DL_RELEASE|REQUEST \n"); 02857 return 1; 02858 02859 case DL_ESTABLISH | INDICATION: 02860 case DL_ESTABLISH | CONFIRM: 02861 { 02862 cb_log (3, stack->port, "L2: L2Link Up! \n"); 02863 if (stack->ptp && stack->l2link) { 02864 cb_log (-1, stack->port, "L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n"); 02865 cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data); 02866 } 02867 stack->l2link=1; 02868 free_msg(msg); 02869 return 1; 02870 } 02871 break; 02872 02873 case DL_RELEASE | INDICATION: 02874 case DL_RELEASE | CONFIRM: 02875 { 02876 cb_log (3, stack->port, "L2: L2Link Down! \n"); 02877 stack->l2link=0; 02878 02879 free_msg(msg); 02880 return 1; 02881 } 02882 break; 02883 } 02884 return 0; 02885 }
static int handle_mgmt | ( | msg_t * | msg | ) | [static] |
Definition at line 2887 of file isdn_lib.c.
References cb_log, clear_l3(), and find_stack_by_addr().
Referenced by manager_isdn_handler().
02888 { 02889 iframe_t *frm = (iframe_t*) msg->data; 02890 struct misdn_stack *stack; 02891 02892 if ( (frm->addr == 0) && (frm->prim == (MGR_DELLAYER|CONFIRM)) ) { 02893 cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: 0 !\n") ; 02894 free_msg(msg); 02895 return 1; 02896 } 02897 02898 stack = find_stack_by_addr(frm->addr); 02899 02900 if (!stack) { 02901 if (frm->prim == (MGR_DELLAYER|CONFIRM)) { 02902 cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: %x !\n", 02903 frm->addr) ; 02904 free_msg(msg); 02905 return 1; 02906 } 02907 02908 return 0; 02909 } 02910 02911 switch(frm->prim) { 02912 case MGR_SHORTSTATUS | INDICATION: 02913 case MGR_SHORTSTATUS | CONFIRM: 02914 cb_log(5, 0, "MGMT: Short status dinfo %x\n",frm->dinfo); 02915 02916 switch (frm->dinfo) { 02917 case SSTATUS_L1_ACTIVATED: 02918 cb_log(3, 0, "MGMT: SSTATUS: L1_ACTIVATED \n"); 02919 stack->l1link=1; 02920 02921 break; 02922 case SSTATUS_L1_DEACTIVATED: 02923 cb_log(3, 0, "MGMT: SSTATUS: L1_DEACTIVATED \n"); 02924 stack->l1link=0; 02925 #if 0 02926 clear_l3(stack); 02927 #endif 02928 break; 02929 02930 case SSTATUS_L2_ESTABLISHED: 02931 cb_log(3, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n"); 02932 stack->l2link=1; 02933 break; 02934 02935 case SSTATUS_L2_RELEASED: 02936 cb_log(3, stack->port, "MGMT: SSTATUS: L2_RELEASED \n"); 02937 stack->l2link=0; 02938 break; 02939 } 02940 02941 free_msg(msg); 02942 return 1; 02943 02944 case MGR_SETSTACK | INDICATION: 02945 cb_log(4, stack->port, "MGMT: SETSTACK|IND dinfo %x\n",frm->dinfo); 02946 free_msg(msg); 02947 return 1; 02948 case MGR_DELLAYER | CONFIRM: 02949 cb_log(4, stack->port, "MGMT: DELLAYER|CNF dinfo %x\n",frm->dinfo) ; 02950 free_msg(msg); 02951 return 1; 02952 02953 } 02954 02955 /* 02956 if ( (frm->prim & 0x0f0000) == 0x0f0000) { 02957 cb_log(5, 0, "$$$ MGMT FRAME: prim %x addr %x dinfo %x\n",frm->prim, frm->addr, frm->dinfo) ; 02958 free_msg(msg); 02959 return 1; 02960 } */ 02961 02962 return 0; 02963 }
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 4289 of file isdn_lib.c.
References misdn_stack::bc, and manager_ph_control().
Referenced by process_ast_dsp().
04290 { 04291 manager_ph_control(bc, DTMF_TONE_STOP, 0); 04292 }
void isdn_lib_update_ec | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4277 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().
04278 { 04279 #ifdef MISDN_1_2 04280 if (*bc->pipeline) 04281 #else 04282 if (bc->ec_enable) 04283 #endif 04284 manager_ec_enable(bc); 04285 else 04286 manager_ec_disable(bc); 04287 }
void isdn_lib_update_rxgain | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4267 of file isdn_lib.c.
References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::rxgain.
Referenced by process_ast_dsp().
04268 { 04269 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 04270 }
void isdn_lib_update_txgain | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4272 of file isdn_lib.c.
References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::txgain.
Referenced by process_ast_dsp().
04273 { 04274 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 04275 }
void manager_bchannel_activate | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4149 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.
04150 { 04151 char buf[128]; 04152 04153 struct misdn_stack *stack=get_stack_by_bc(bc); 04154 04155 if (!stack) { 04156 cb_log(0, bc->port, "bchannel_activate: Stack not found !"); 04157 return ; 04158 } 04159 04160 /* we must activate if we are deactivated */ 04161 clear_ibuffer(bc->astbuf); 04162 04163 cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr); 04164 04165 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC); 04166 04167 return ; 04168 }
void manager_bchannel_cleanup | ( | struct misdn_bchannel * | bc | ) |
void manager_bchannel_deactivate | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4171 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().
04172 { 04173 04174 struct misdn_stack *stack=get_stack_by_bc(bc); 04175 iframe_t dact; 04176 char buf[128]; 04177 04178 switch (bc->bc_state) { 04179 case BCHAN_ACTIVATED: 04180 break; 04181 case BCHAN_BRIDGED: 04182 misdn_split_conf(bc,bc->conf_id); 04183 break; 04184 default: 04185 cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n"); 04186 return ; 04187 04188 } 04189 04190 cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr); 04191 04192 bc->generate_tone=0; 04193 04194 dact.prim = DL_RELEASE | REQUEST; 04195 dact.addr = bc->addr | FLG_MSG_DOWN; 04196 dact.dinfo = 0; 04197 dact.len = 0; 04198 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC); 04199 04200 clear_ibuffer(bc->astbuf); 04201 04202 bc_state_change(bc,BCHAN_RELEASE); 04203 04204 return; 04205 }
void manager_bchannel_setup | ( | struct misdn_bchannel * | bc | ) |
void manager_clean_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4316 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().
04317 { 04318 struct misdn_stack *stack=get_stack_by_bc(bc); 04319 04320 if (bc->channel>0) 04321 empty_chan_in_stack(stack, bc->channel); 04322 empty_bc(bc); 04323 bc->in_use=0; 04324 04325 cb_event(EVENT_CLEANUP, bc, NULL); 04326 }
void manager_ec_disable | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4508 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().
04509 { 04510 struct misdn_stack *stack=get_stack_by_bc(bc); 04511 04512 cb_log(4, stack?stack->port:0," --> ec_disable\n"); 04513 04514 if (!misdn_cap_is_speech(bc->capability)) { 04515 cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n"); 04516 return; 04517 } 04518 04519 #ifdef MISDN_1_2 04520 manager_ph_control_block(bc, PIPELINE_CFG, "", 0); 04521 #else 04522 if ( ! bc->ec_enable) { 04523 cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n"); 04524 manager_ph_control(bc, ECHOCAN_OFF, 0); 04525 } 04526 #endif 04527 }
void manager_ec_enable | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4459 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().
04460 { 04461 struct misdn_stack *stack=get_stack_by_bc(bc); 04462 04463 cb_log(4, stack?stack->port:0,"ec_enable\n"); 04464 04465 if (!misdn_cap_is_speech(bc->capability)) { 04466 cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n"); 04467 } else { 04468 04469 #ifdef MISDN_1_2 04470 if (*bc->pipeline) { 04471 cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline); 04472 manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1); 04473 } 04474 #else 04475 int ec_arr[2]; 04476 04477 if (bc->ec_enable) { 04478 cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps); 04479 04480 switch (bc->ec_deftaps) { 04481 case 4: 04482 case 8: 04483 case 16: 04484 case 32: 04485 case 64: 04486 case 128: 04487 case 256: 04488 case 512: 04489 case 1024: 04490 cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps); 04491 break; 04492 default: 04493 cb_log(0, stack->port, "Taps should be power of 2\n"); 04494 bc->ec_deftaps=128; 04495 } 04496 04497 ec_arr[0]=bc->ec_deftaps; 04498 ec_arr[1]=0; 04499 04500 manager_ph_control_block(bc, ECHOCAN_ON, ec_arr, sizeof(ec_arr)); 04501 } 04502 #endif 04503 } 04504 }
static void manager_event_handler | ( | void * | arg | ) | [static] |
Definition at line 3859 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.
03860 { 03861 sem_post(&handler_started); 03862 while (1) { 03863 struct misdn_stack *stack; 03864 msg_t *msg; 03865 03866 /** wait for events **/ 03867 sem_wait(&glob_mgr->new_msg); 03868 03869 for (msg=msg_dequeue(&glob_mgr->activatequeue); 03870 msg; 03871 msg=msg_dequeue(&glob_mgr->activatequeue) 03872 ) 03873 { 03874 03875 iframe_t *frm = (iframe_t*) msg->data ; 03876 03877 switch ( frm->prim) { 03878 03879 case MGR_CLEARSTACK | REQUEST: 03880 /*a queued bchannel cleanup*/ 03881 { 03882 struct misdn_stack *stack=find_stack_by_port(frm->dinfo); 03883 struct misdn_bchannel *bc; 03884 if (!stack) { 03885 cb_log(0,0,"no stack found with port [%d]!! so we cannot cleanup the bc\n",frm->dinfo); 03886 free_msg(msg); 03887 break; 03888 } 03889 03890 bc = find_bc_by_l3id(stack, frm->addr); 03891 if (bc) { 03892 cb_log(1,bc->port,"CLEARSTACK queued, cleaning up\n"); 03893 clean_up_bc(bc); 03894 } else { 03895 cb_log(0,stack->port,"bc could not be cleaned correctly !! addr [%x]\n",frm->addr); 03896 } 03897 } 03898 free_msg(msg); 03899 break; 03900 case MGR_SETSTACK | REQUEST : 03901 break; 03902 default: 03903 mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); 03904 free_msg(msg); 03905 } 03906 } 03907 03908 for (stack=glob_mgr->stack_list; 03909 stack; 03910 stack=stack->next ) { 03911 03912 while ( (msg=msg_dequeue(&stack->upqueue)) ) { 03913 /** Handle L2/3 Signalling after bchans **/ 03914 if (!handle_frm_nt(msg)) { 03915 /* Maybe it's TE */ 03916 if (!handle_frm(msg)) { 03917 /* wow none! */ 03918 cb_log(0,stack->port,"Wow we've got a strange issue while dequeueing a Frame\n"); 03919 } 03920 } 03921 } 03922 03923 /* Here we should check if we really want to 03924 send all the messages we've queued, lets 03925 assume we've queued a Disconnect, but 03926 received it already from the other side!*/ 03927 03928 while ( (msg=msg_dequeue(&stack->downqueue)) ) { 03929 if (stack->nt ) { 03930 if (stack->nst.manager_l3(&stack->nst, msg)) 03931 cb_log(0, stack->port, "Error@ Sending Message in NT-Stack.\n"); 03932 03933 } else { 03934 iframe_t *frm = (iframe_t *)msg->data; 03935 struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo); 03936 if (bc) 03937 send_msg(glob_mgr->midev, bc, msg); 03938 else { 03939 if (frm->dinfo == MISDN_ID_GLOBAL || frm->dinfo == MISDN_ID_DUMMY ) { 03940 struct misdn_bchannel dummybc; 03941 cb_log(5,0," --> GLOBAL/DUMMY\n"); 03942 misdn_make_dummy(&dummybc, stack->port, frm->dinfo, stack->nt, 0); 03943 send_msg(glob_mgr->midev, &dummybc, msg); 03944 } else { 03945 cb_log(0,0,"No bc for Message\n"); 03946 } 03947 } 03948 } 03949 } 03950 } 03951 } 03952 }
struct misdn_bchannel * manager_find_bc_by_pid | ( | int | pid | ) |
Definition at line 3114 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().
03115 { 03116 struct misdn_stack *stack; 03117 int i; 03118 03119 for (stack=glob_mgr->stack_list; 03120 stack; 03121 stack=stack->next) { 03122 for (i=0; i<=stack->b_num; i++) 03123 if (stack->bc[i].pid == pid) return &stack->bc[i]; 03124 } 03125 03126 return NULL; 03127 }
struct misdn_bchannel * manager_find_bc_holded | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3129 of file isdn_lib.c.
References misdn_stack::bc, find_bc_holded(), and get_stack_by_bc().
03130 { 03131 struct misdn_stack *stack=get_stack_by_bc(bc); 03132 return find_bc_holded(stack); 03133 }
char* manager_isdn_get_info | ( | enum event_e | event | ) |
Definition at line 4144 of file isdn_lib.c.
References isdn_get_info(), and msgs_g.
Referenced by cb_events().
04145 { 04146 return isdn_get_info(msgs_g , event, 0); 04147 }
int manager_isdn_handler | ( | iframe_t * | frm, | |
msg_t * | msg | |||
) |
Definition at line 3649 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().
03650 { 03651 03652 if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) { 03653 cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n"); 03654 } 03655 03656 if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) { 03657 static int unhandled_bmsg_count=1000; 03658 if (handle_bchan(msg)) { 03659 return 0 ; 03660 } 03661 03662 if (unhandled_bmsg_count==1000) { 03663 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); 03664 unhandled_bmsg_count=0; 03665 } 03666 03667 unhandled_bmsg_count++; 03668 free_msg(msg); 03669 return 0; 03670 } 03671 03672 #ifdef RECV_FRM_SYSLOG_DEBUG 03673 syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo); 03674 #endif 03675 03676 if (handle_timers(msg)) 03677 return 0 ; 03678 03679 03680 if (handle_mgmt(msg)) 03681 return 0 ; 03682 03683 if (handle_l2(msg)) 03684 return 0 ; 03685 03686 /* Its important to handle l1 AFTER l2 */ 03687 if (handle_l1(msg)) 03688 return 0 ; 03689 03690 if (handle_frm_nt(msg)) { 03691 return 0; 03692 } 03693 03694 if (handle_frm(msg)) { 03695 return 0; 03696 } 03697 03698 if (handle_err(msg)) { 03699 return 0 ; 03700 } 03701 03702 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); 03703 free_msg(msg); 03704 03705 03706 return 0; 03707 }
void manager_ph_control | ( | struct misdn_bchannel * | bc, | |
int | c1, | |||
int | c2 | |||
) |
Definition at line 4246 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().
04247 { 04248 unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)]; 04249 iframe_t *ctrl = (iframe_t *)buffer; /* preload data */ 04250 unsigned int *d = (unsigned int*)&ctrl->data.p; 04251 /*struct misdn_stack *stack=get_stack_by_bc(bc);*/ 04252 04253 cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2); 04254 04255 ctrl->prim = PH_CONTROL | REQUEST; 04256 ctrl->addr = bc->addr | FLG_MSG_DOWN; 04257 ctrl->dinfo = 0; 04258 ctrl->len = sizeof(unsigned int)*2; 04259 *d++ = c1; 04260 *d++ = c2; 04261 mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); 04262 }
void manager_ph_control_block | ( | struct misdn_bchannel * | bc, | |
int | c1, | |||
void * | c2, | |||
int | c2_len | |||
) |
Definition at line 4297 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().
04298 { 04299 unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len]; 04300 iframe_t *ctrl = (iframe_t *)buffer; 04301 unsigned int *d = (unsigned int *)&ctrl->data.p; 04302 /*struct misdn_stack *stack=get_stack_by_bc(bc);*/ 04303 04304 ctrl->prim = PH_CONTROL | REQUEST; 04305 ctrl->addr = bc->addr | FLG_MSG_DOWN; 04306 ctrl->dinfo = 0; 04307 ctrl->len = sizeof(unsigned int) + c2_len; 04308 *d++ = c1; 04309 memcpy(d, c2, c2_len); 04310 mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); 04311 }
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 4535 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().
04536 { 04537 char data[16] = ""; 04538 04539 bc_state_change(bc,BCHAN_BRIDGED); 04540 manager_ph_control(bc, CMX_RECEIVE_OFF, 0); 04541 manager_ph_control(bc, CMX_CONF_JOIN, conf_id); 04542 04543 cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id); 04544 04545 misdn_lib_tx2misdn_frm(bc, data, sizeof(data) - 1); 04546 }
void misdn_lib_bridge | ( | struct misdn_bchannel * | bc1, | |
struct misdn_bchannel * | bc2 | |||
) |
Definition at line 4558 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().
04558 { 04559 int conf_id = bc1->pid + 1; 04560 struct misdn_bchannel *bc_list[] = { bc1, bc2, NULL }; 04561 struct misdn_bchannel **bc; 04562 04563 cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port); 04564 04565 for (bc=bc_list; *bc; bc++) { 04566 (*bc)->conf_id=conf_id; 04567 cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr); 04568 04569 switch((*bc)->bc_state) { 04570 case BCHAN_ACTIVATED: 04571 misdn_join_conf(*bc,conf_id); 04572 break; 04573 default: 04574 bc_next_state_change(*bc,BCHAN_BRIDGED); 04575 break; 04576 } 04577 } 04578 }
void misdn_lib_destroy | ( | void | ) |
Definition at line 4111 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().
04112 { 04113 struct misdn_stack *help; 04114 int i; 04115 04116 for ( help=glob_mgr->stack_list; help; help=help->next ) { 04117 for(i=0;i<=help->b_num; i++) { 04118 char buf[1024]; 04119 mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 04120 help->bc[i].addr = 0; 04121 } 04122 cb_log (1, help->port, "Destroying this port.\n"); 04123 stack_destroy(help); 04124 } 04125 04126 if (global_state == MISDN_INITIALIZED) { 04127 cb_log(4, 0, "Killing Handler Thread\n"); 04128 if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) { 04129 cb_log(4, 0, "Joining Handler Thread\n"); 04130 pthread_join(glob_mgr->event_handler_thread, NULL); 04131 } 04132 04133 cb_log(4, 0, "Killing Main Thread\n"); 04134 if ( pthread_cancel(glob_mgr->event_thread) == 0 ) { 04135 cb_log(4, 0, "Joining Main Thread\n"); 04136 pthread_join(glob_mgr->event_thread, NULL); 04137 } 04138 } 04139 04140 cb_log(1, 0, "Closing mISDN device\n"); 04141 te_lib_destroy(glob_mgr->midev); 04142 }
void misdn_lib_echo | ( | struct misdn_bchannel * | bc, | |
int | onoff | |||
) |
Definition at line 4600 of file isdn_lib.c.
References cb_log, manager_ph_control(), and misdn_bchannel::port.
04601 { 04602 cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF"); 04603 manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0); 04604 }
struct misdn_bchannel* misdn_lib_get_free_bc | ( | int | port, | |
int | channel, | |||
int | inout, | |||
int | dec | |||
) |
Definition at line 3177 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().
03178 { 03179 struct misdn_stack *stack; 03180 int i; 03181 03182 if (channel < 0 || channel > MAX_BCHANS) { 03183 cb_log(0,port,"Requested channel out of bounds (%d)\n",channel); 03184 return NULL; 03185 } 03186 03187 usleep(1000); 03188 03189 for (stack=glob_mgr->stack_list; stack; stack=stack->next) { 03190 03191 if (stack->port == port) { 03192 int maxnum; 03193 03194 if (stack->blocked) { 03195 cb_log(0,port,"Port is blocked\n"); 03196 return NULL; 03197 } 03198 03199 if (channel > 0) { 03200 if (channel <= stack->b_num) { 03201 for (i = 0; i < stack->b_num; i++) { 03202 if ( stack->bc[i].channel == channel) { 03203 if (test_inuse(&stack->bc[i])) { 03204 cb_log(0,port,"Requested channel:%d on port:%d is already in use\n",channel, port); 03205 return NULL; 03206 03207 } else { 03208 prepare_bc(&stack->bc[i], channel); 03209 return &stack->bc[i]; 03210 } 03211 } 03212 } 03213 } else { 03214 cb_log(0,port,"Requested channel:%d is out of bounds on port:%d\n",channel, port); 03215 return NULL; 03216 } 03217 } 03218 03219 maxnum = inout && !stack->pri && !stack->ptp ? stack->b_num + 1 : stack->b_num; 03220 03221 if (dec) { 03222 for (i = maxnum-1; i>=0; i--) { 03223 if (!test_inuse(&stack->bc[i])) { 03224 /* 3. channel on bri means CW*/ 03225 if (!stack->pri && i==stack->b_num) 03226 stack->bc[i].cw=1; 03227 03228 prepare_bc(&stack->bc[i], channel); 03229 stack->bc[i].dec=1; 03230 return &stack->bc[i]; 03231 } 03232 } 03233 } else { 03234 for (i = 0; i <maxnum; i++) { 03235 if (!test_inuse(&stack->bc[i])) { 03236 /* 3. channel on bri means CW*/ 03237 if (!stack->pri && i==stack->b_num) 03238 stack->bc[i].cw=1; 03239 03240 prepare_bc(&stack->bc[i], channel); 03241 return &stack->bc[i]; 03242 } 03243 } 03244 } 03245 03246 cb_log(1,port,"There is no free channel on port (%d)\n",port); 03247 return NULL; 03248 } 03249 } 03250 03251 cb_log(0,port,"Port is not configured (%d)\n",port); 03252 return NULL; 03253 }
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 3712 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.
03713 { 03714 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03715 iframe_t *frm; 03716 struct misdn_stack *stack=find_stack_by_port(port); 03717 if (!msg) { 03718 cb_log(0, port, "misgn_lib_get_port: alloc_msg failed!\n"); 03719 return -1; 03720 } 03721 frm=(iframe_t*)msg->data; 03722 if (!stack ) { 03723 cb_log(0, port, "There is no Stack for this port.\n"); 03724 return -1; 03725 } 03726 /* activate bchannel */ 03727 frm->prim = CC_STATUS_ENQUIRY | REQUEST; 03728 03729 frm->addr = stack->upper_id| FLG_MSG_DOWN; 03730 03731 frm->dinfo = 0; 03732 frm->len = 0; 03733 03734 msg_queue_tail(&glob_mgr->activatequeue, msg); 03735 sem_post(&glob_mgr->new_msg); 03736 03737 03738 return 0; 03739 }
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 4003 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().
04004 { 04005 struct misdn_lib *mgr=calloc(1, sizeof(struct misdn_lib)); 04006 char *tok, *tokb; 04007 char plist[1024]; 04008 int midev; 04009 int port_count=0; 04010 04011 cb_log = iface->cb_log; 04012 cb_event = iface->cb_event; 04013 cb_jb_empty = iface->cb_jb_empty; 04014 04015 glob_mgr = mgr; 04016 04017 msg_init(); 04018 04019 misdn_lib_nt_debug_init(0,NULL); 04020 04021 if (!portlist || (*portlist == 0) ) return 1; 04022 04023 init_flip_bits(); 04024 04025 { 04026 strncpy(plist,portlist, 1024); 04027 plist[1023] = 0; 04028 } 04029 04030 memcpy(tone_425_flip,tone_425,TONE_425_SIZE); 04031 flip_buf_bits(tone_425_flip,TONE_425_SIZE); 04032 04033 memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE); 04034 flip_buf_bits(tone_silence_flip,TONE_SILENCE_SIZE); 04035 04036 midev=te_lib_init(); 04037 mgr->midev=midev; 04038 04039 port_count=mISDN_get_stack_count(midev); 04040 04041 msg_queue_init(&mgr->activatequeue); 04042 04043 if (sem_init(&mgr->new_msg, 1, 0)<0) 04044 sem_init(&mgr->new_msg, 0, 0); 04045 04046 for (tok=strtok_r(plist," ,",&tokb ); 04047 tok; 04048 tok=strtok_r(NULL," ,",&tokb)) { 04049 int port = atoi(tok); 04050 struct misdn_stack *stack; 04051 static int first=1; 04052 int ptp=0; 04053 04054 if (strstr(tok, "ptp")) 04055 ptp=1; 04056 04057 if (port > port_count) { 04058 cb_log(0, port, "Couldn't Initialize this port since we have only %d ports\n", port_count); 04059 exit(1); 04060 } 04061 stack=stack_init(midev, port, ptp); 04062 04063 if (!stack) { 04064 perror("init_stack"); 04065 exit(1); 04066 } 04067 04068 { 04069 int i; 04070 for(i=0;i<=stack->b_num; i++) { 04071 int r; 04072 if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) { 04073 cb_log(0, port, "Got Err @ init_bc :%d\n",r); 04074 exit(1); 04075 } 04076 } 04077 } 04078 04079 if (stack && first) { 04080 mgr->stack_list=stack; 04081 first=0; 04082 continue; 04083 } 04084 04085 if (stack) { 04086 struct misdn_stack * help; 04087 for ( help=mgr->stack_list; help; help=help->next ) 04088 if (help->next == NULL) break; 04089 help->next=stack; 04090 } 04091 04092 } 04093 04094 if (sem_init(&handler_started, 1, 0)<0) 04095 sem_init(&handler_started, 0, 0); 04096 04097 cb_log(8, 0, "Starting Event Handler\n"); 04098 pthread_create( &mgr->event_handler_thread, NULL,(void*)manager_event_handler, mgr); 04099 04100 sem_wait(&handler_started) ; 04101 cb_log(8, 0, "Starting Event Catcher\n"); 04102 pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr); 04103 04104 cb_log(8, 0, "Event Catcher started\n"); 04105 04106 global_state= MISDN_INITIALIZED; 04107 04108 return (mgr == NULL); 04109 }
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 3022 of file isdn_lib.c.
References cb_log, fetch_msg(), manager_isdn_handler(), misdn_lib::midev, and msg.
03023 { 03024 struct misdn_lib *mgr = arg; 03025 int zero_frm=0 , fff_frm=0 ; 03026 int midev= mgr->midev; 03027 int port=0; 03028 03029 while (1) { 03030 msg_t *msg = fetch_msg(midev); 03031 iframe_t *frm; 03032 03033 03034 if (!msg) continue; 03035 03036 frm = (iframe_t*) msg->data; 03037 03038 /** When we make a call from NT2Ast we get this frames **/ 03039 if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) { 03040 zero_frm++; 03041 free_msg(msg); 03042 continue; 03043 } else { 03044 if (zero_frm) { 03045 cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm); 03046 zero_frm = 0 ; 03047 } 03048 } 03049 03050 /** I get this sometimes after setup_bc **/ 03051 if (frm->len == 0 && frm->dinfo == 0 && frm->prim == 0xffffffff ) { 03052 fff_frm++; 03053 free_msg(msg); 03054 continue; 03055 } else { 03056 if (fff_frm) { 03057 cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm); 03058 fff_frm = 0 ; 03059 } 03060 } 03061 03062 manager_isdn_handler(frm, msg); 03063 } 03064 03065 }
void misdn_lib_isdn_l1watcher | ( | int | port | ) |
Definition at line 3004 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().
03005 { 03006 struct misdn_stack *stack; 03007 03008 for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next) 03009 ; 03010 03011 if (stack) { 03012 cb_log(4, port, "Checking L1 State\n"); 03013 if (!stack->l1link) { 03014 cb_log(4, port, "L1 State Down, trying to get it up again\n"); 03015 misdn_lib_get_short_status(stack); 03016 misdn_lib_get_l1_up(stack); 03017 misdn_lib_get_l2_up(stack); 03018 } 03019 } 03020 }
void misdn_lib_log_ies | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3274 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().
03275 { 03276 struct misdn_stack *stack; 03277 03278 if (!bc) return; 03279 03280 stack = get_stack_by_bc(bc); 03281 03282 if (!stack) return; 03283 03284 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); 03285 03286 cb_log(2, stack->port, 03287 " --> info_dad:%s onumplan:%c dnumplan:%c rnumplan:%c cpnnumplan:%c\n", 03288 bc->info_dad, 03289 bc->onumplan>=0?'0'+bc->onumplan:' ', 03290 bc->dnumplan>=0?'0'+bc->dnumplan:' ', 03291 bc->rnumplan>=0?'0'+bc->rnumplan:' ', 03292 bc->cpnnumplan>=0?'0'+bc->cpnnumplan:' ' 03293 ); 03294 03295 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); 03296 cb_log(4, stack->port, " --> screen:%d --> pres:%d\n", 03297 bc->screen, bc->pres); 03298 03299 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); 03300 03301 cb_log(4, stack->port, " --> facility:%s out_facility:%s\n",fac2str(bc->fac_in.Function),fac2str(bc->fac_out.Function)); 03302 03303 cb_log(5, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1); 03304 03305 cb_log(5, stack->port, " --> bc:%p h:%d sh:%d\n", bc, bc->holded, bc->stack_holder); 03306 }
int misdn_lib_maxports_get | ( | void | ) |
Definition at line 3955 of file isdn_lib.c.
Referenced by load_module().
03955 { /** BE AWARE WE HAVE NO CB_LOG HERE! **/ 03956 03957 int i = mISDN_open(); 03958 int max=0; 03959 03960 if (i<0) 03961 return -1; 03962 03963 max = mISDN_get_stack_count(i); 03964 03965 mISDN_close(i); 03966 03967 return max; 03968 }
void misdn_lib_nt_debug_init | ( | int | flags, | |
char * | file | |||
) |
Definition at line 3983 of file isdn_lib.c.
References f.
Referenced by load_module(), and misdn_lib_init().
03984 { 03985 int static init=0; 03986 char *f; 03987 03988 if (!flags) 03989 f=NULL; 03990 else 03991 f=file; 03992 03993 if (!init) { 03994 debug_init( flags , f, f, f); 03995 init=1; 03996 } else { 03997 debug_close(); 03998 debug_init( flags , f, f, f); 03999 } 04000 }
void misdn_lib_nt_keepcalls | ( | int | kc | ) |
Definition at line 3971 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, and misdn_stack::nst.
Referenced by load_module().
03972 { 03973 #ifdef FEATURE_NET_KEEPCALLS 03974 if (kc) { 03975 struct misdn_stack *stack=get_misdn_stack(); 03976 for ( ; stack; stack=stack->next) { 03977 stack->nst.feature |= FEATURE_NET_KEEPCALLS; 03978 } 03979 } 03980 #endif 03981 }
int misdn_lib_pid_restart | ( | int | pid | ) |
Definition at line 3767 of file isdn_lib.c.
References manager_clean_bc(), and manager_find_bc_by_pid().
Referenced by handle_cli_misdn_restart_pid().
03768 { 03769 struct misdn_bchannel *bc=manager_find_bc_by_pid(pid); 03770 03771 if (bc) { 03772 manager_clean_bc(bc); 03773 } 03774 return 0; 03775 }
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 3817 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().
03818 { 03819 struct misdn_stack *stack=find_stack_by_port(port); 03820 03821 cb_log(0, port, "Restarting this port.\n"); 03822 if (stack) { 03823 cb_log(0, port, "Stack:%p\n",stack); 03824 03825 clear_l3(stack); 03826 { 03827 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03828 iframe_t *frm; 03829 03830 if (!msg) { 03831 cb_log(0, port, "port_restart: alloc_msg failed\n"); 03832 return -1; 03833 } 03834 03835 frm=(iframe_t*)msg->data; 03836 /* we must activate if we are deactivated */ 03837 /* activate bchannel */ 03838 frm->prim = DL_RELEASE | REQUEST; 03839 frm->addr = stack->upper_id | FLG_MSG_DOWN; 03840 03841 frm->dinfo = 0; 03842 frm->len = 0; 03843 msg_queue_tail(&glob_mgr->activatequeue, msg); 03844 sem_post(&glob_mgr->new_msg); 03845 } 03846 03847 if (stack->nt) 03848 misdn_lib_reinit_nt_stack(stack->port); 03849 03850 } 03851 03852 return 0; 03853 }
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 4608 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().
04609 { 04610 struct misdn_stack *stack=find_stack_by_port(port); 04611 04612 if (stack) { 04613 stack->l2link=0; 04614 stack->blocked=0; 04615 04616 cleanup_Isdnl3(&stack->nst); 04617 cleanup_Isdnl2(&stack->nst); 04618 04619 04620 memset(&stack->nst, 0, sizeof(net_stack_t)); 04621 memset(&stack->mgr, 0, sizeof(manager_t)); 04622 04623 stack->mgr.nst = &stack->nst; 04624 stack->nst.manager = &stack->mgr; 04625 04626 stack->nst.l3_manager = handle_event_nt; 04627 stack->nst.device = glob_mgr->midev; 04628 stack->nst.cardnr = port; 04629 stack->nst.d_stid = stack->d_stid; 04630 04631 stack->nst.feature = FEATURE_NET_HOLD; 04632 if (stack->ptp) 04633 stack->nst.feature |= FEATURE_NET_PTP; 04634 if (stack->pri) 04635 stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID; 04636 04637 stack->nst.l1_id = stack->lower_id; 04638 stack->nst.l2_id = stack->upper_id; 04639 04640 msg_queue_init(&stack->nst.down_queue); 04641 04642 Isdnl2Init(&stack->nst); 04643 Isdnl3Init(&stack->nst); 04644 04645 if (!stack->ptp) 04646 misdn_lib_get_l1_up(stack); 04647 misdn_lib_get_l2_up(stack); 04648 } 04649 }
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 3327 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().
03328 { 03329 msg_t *msg; 03330 int retval=0; 03331 struct misdn_stack *stack; 03332 03333 if (!bc) RETURN(-1,OUT_POST_UNLOCK); 03334 03335 stack = get_stack_by_bc(bc); 03336 03337 if (!stack) { 03338 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); 03339 RETURN(-1,OUT); 03340 } 03341 03342 misdn_send_lock(bc); 03343 03344 03345 cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->uperid:%x\n",stack->nt, stack->upper_id); 03346 03347 if ( stack->nt && !stack->l1link) { 03348 /** Queue Event **/ 03349 bc->evq=event; 03350 cb_log(1, stack->port, "Queueing Event %s because L1 is down (btw. Activating L1)\n", isdn_get_info(msgs_g, event, 0)); 03351 misdn_lib_get_l1_up(stack); 03352 RETURN(0,OUT); 03353 } 03354 03355 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); 03356 cb_log(4, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state)); 03357 misdn_lib_log_ies(bc); 03358 03359 switch (event) { 03360 case EVENT_SETUP: 03361 if (create_process(glob_mgr->midev, bc)<0) { 03362 cb_log(0, stack->port, " No free channel at the moment @ send_event\n"); 03363 03364 RETURN(-ENOCHAN,OUT); 03365 } 03366 break; 03367 03368 case EVENT_PROGRESS: 03369 case EVENT_ALERTING: 03370 case EVENT_PROCEEDING: 03371 case EVENT_SETUP_ACKNOWLEDGE: 03372 case EVENT_CONNECT: 03373 if (!stack->nt) break; 03374 03375 case EVENT_RETRIEVE_ACKNOWLEDGE: 03376 03377 if (stack->nt) { 03378 if (bc->channel <=0 ) { /* else we have the channel already */ 03379 if (find_free_chan_in_stack(stack, bc, 0, 0)<0) { 03380 cb_log(0, stack->port, " No free channel at the moment\n"); 03381 /*FIXME: add disconnect*/ 03382 RETURN(-ENOCHAN,OUT); 03383 } 03384 } 03385 /* Its that i generate channels */ 03386 } 03387 03388 retval=setup_bc(bc); 03389 if (retval == -EINVAL) { 03390 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03391 } 03392 03393 if (misdn_cap_is_speech(bc->capability)) { 03394 if ((event==EVENT_CONNECT)||(event==EVENT_RETRIEVE_ACKNOWLEDGE)) { 03395 if ( *bc->crypt_key ) { 03396 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); 03397 03398 manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); 03399 } 03400 03401 if (!bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0); 03402 manager_ec_enable(bc); 03403 03404 if (bc->txgain != 0) { 03405 cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); 03406 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 03407 } 03408 03409 if ( bc->rxgain != 0 ) { 03410 cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); 03411 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 03412 } 03413 } 03414 } 03415 break; 03416 03417 case EVENT_HOLD_ACKNOWLEDGE: 03418 { 03419 struct misdn_bchannel *holded_bc=malloc(sizeof(struct misdn_bchannel)); 03420 if (!holded_bc) { 03421 cb_log(0,bc->port, "Could not allocate holded_bc!!!\n"); 03422 RETURN(-1,OUT); 03423 } 03424 03425 /*backup the bc*/ 03426 memcpy(holded_bc,bc,sizeof(struct misdn_bchannel)); 03427 holded_bc->holded=1; 03428 bc_state_change(holded_bc,BCHAN_CLEANED); 03429 03430 stack_holder_add(stack,holded_bc); 03431 03432 /*kill the bridge and clean the bchannel*/ 03433 if (stack->nt) { 03434 int channel; 03435 if (bc->bc_state == BCHAN_BRIDGED) { 03436 struct misdn_bchannel *bc2; 03437 03438 misdn_split_conf(bc,bc->conf_id); 03439 bc2 = find_bc_by_confid(bc->conf_id); 03440 if (!bc2) { 03441 cb_log(0,bc->port,"We have no second bc in bridge???\n"); 03442 } else { 03443 misdn_split_conf(bc2,bc->conf_id); 03444 } 03445 } 03446 03447 channel = bc->channel; 03448 03449 empty_bc(bc); 03450 clean_up_bc(bc); 03451 03452 if (channel>0) 03453 empty_chan_in_stack(stack,channel); 03454 03455 bc->in_use=0; 03456 } 03457 03458 } 03459 break; 03460 03461 /* finishing the channel eh ? */ 03462 case EVENT_DISCONNECT: 03463 if (!bc->need_disconnect) { 03464 cb_log(0,bc->port," --> we have already send Disconnect\n"); 03465 RETURN(-1,OUT); 03466 } 03467 03468 bc->need_disconnect=0; 03469 break; 03470 case EVENT_RELEASE: 03471 if (!bc->need_release) { 03472 cb_log(0,bc->port," --> we have already send Release\n"); 03473 RETURN(-1,OUT); 03474 } 03475 bc->need_disconnect=0; 03476 bc->need_release=0; 03477 break; 03478 case EVENT_RELEASE_COMPLETE: 03479 if (!bc->need_release_complete) { 03480 cb_log(0,bc->port," --> we have already send Release_complete\n"); 03481 RETURN(-1,OUT); 03482 } 03483 bc->need_disconnect=0; 03484 bc->need_release=0; 03485 bc->need_release_complete=0; 03486 03487 if (!stack->nt) { 03488 /*create clenaup in TE*/ 03489 int channel=bc->channel; 03490 03491 int tmpcause=bc->cause; 03492 int tmp_out_cause=bc->out_cause; 03493 empty_bc(bc); 03494 bc->cause=tmpcause; 03495 bc->out_cause=tmp_out_cause; 03496 clean_up_bc(bc); 03497 03498 if (channel>0) 03499 empty_chan_in_stack(stack,channel); 03500 03501 bc->in_use=0; 03502 } 03503 break; 03504 03505 case EVENT_CONNECT_ACKNOWLEDGE: 03506 03507 if ( bc->nt || misdn_cap_is_speech(bc->capability)) { 03508 int retval=setup_bc(bc); 03509 if (retval == -EINVAL){ 03510 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03511 03512 } 03513 } 03514 03515 if (misdn_cap_is_speech(bc->capability)) { 03516 if ( !bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0); 03517 manager_ec_enable(bc); 03518 03519 if ( bc->txgain != 0 ) { 03520 cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); 03521 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 03522 } 03523 if ( bc->rxgain != 0 ) { 03524 cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); 03525 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 03526 } 03527 } 03528 break; 03529 03530 default: 03531 break; 03532 } 03533 03534 /* Later we should think about sending bchannel data directly to misdn. */ 03535 msg = isdn_msg_build_event(msgs_g, bc, event, stack->nt); 03536 msg_queue_tail(&stack->downqueue, msg); 03537 sem_post(&glob_mgr->new_msg); 03538 03539 OUT: 03540 misdn_send_unlock(bc); 03541 03542 OUT_POST_UNLOCK: 03543 return retval; 03544 }
int misdn_lib_send_restart | ( | int | port, | |
int | channel | |||
) |
Definition at line 3778 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().
03779 { 03780 struct misdn_stack *stack=find_stack_by_port(port); 03781 struct misdn_bchannel dummybc; 03782 /*default is all channels*/ 03783 cb_log(0, port, "Sending Restarts on this port.\n"); 03784 03785 misdn_make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0); 03786 03787 /*default is all channels*/ 03788 if (channel <0) { 03789 dummybc.channel=-1; 03790 cb_log(0, port, "Restarting and all Interfaces\n"); 03791 misdn_lib_send_event(&dummybc, EVENT_RESTART); 03792 03793 return 0; 03794 } 03795 03796 /*if a channel is specified we restart only this one*/ 03797 if (channel >0) { 03798 int cnt; 03799 dummybc.channel=channel; 03800 cb_log(0, port, "Restarting and cleaning channel %d\n",channel); 03801 misdn_lib_send_event(&dummybc, EVENT_RESTART); 03802 /* clean up chan in stack, to be sure we don't think it's 03803 * in use anymore */ 03804 for (cnt=0; cnt<=stack->b_num; cnt++) { 03805 if (stack->bc[cnt].channel == channel) { 03806 empty_bc(&stack->bc[cnt]); 03807 clean_up_bc(&stack->bc[cnt]); 03808 stack->bc[cnt].in_use=0; 03809 } 03810 } 03811 } 03812 03813 return 0; 03814 }
void misdn_lib_send_tone | ( | struct misdn_bchannel * | bc, | |
enum tone_e | tone | |||
) |
Definition at line 4427 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().
04428 { 04429 char buf[mISDN_HEADER_LEN + 128] = ""; 04430 iframe_t *frm = (iframe_t*)buf; 04431 04432 switch(tone) { 04433 case TONE_DIAL: 04434 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE); 04435 break; 04436 04437 case TONE_ALERTING: 04438 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_RINGING); 04439 break; 04440 04441 case TONE_HANGUP: 04442 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_HANGUP); 04443 break; 04444 04445 case TONE_NONE: 04446 default: 04447 manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP); 04448 } 04449 04450 frm->prim=DL_DATA|REQUEST; 04451 frm->addr=bc->addr|FLG_MSG_DOWN; 04452 frm->dinfo=0; 04453 frm->len=128; 04454 04455 mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); 04456 }
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 4580 of file isdn_lib.c.
References bc_state2str(), BCHAN_BRIDGED, cb_log, misdn_bchannel::conf_id, and misdn_split_conf().
Referenced by misdn_bridge().
04581 { 04582 04583 struct misdn_bchannel *bc_list[]={ 04584 bc1,bc2,NULL 04585 }; 04586 struct misdn_bchannel **bc; 04587 04588 for (bc=bc_list; *bc; bc++) { 04589 if ( (*bc)->bc_state == BCHAN_BRIDGED){ 04590 misdn_split_conf( *bc, (*bc)->conf_id); 04591 } else { 04592 cb_log( 2, (*bc)->port, "BC not bridged (state:%s) so not splitting it\n",bc_state2str((*bc)->bc_state)); 04593 } 04594 } 04595 04596 }
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 3109 of file isdn_lib.c.
References misdn_bchannel::holded.
03110 { 03111 holded_bc->holded=0; 03112 }
int misdn_lib_tx2misdn_frm | ( | struct misdn_bchannel * | bc, | |
void * | data, | |||
int | len | |||
) |
Definition at line 4208 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().
04209 { 04210 struct misdn_stack *stack=get_stack_by_bc(bc); 04211 char buf[4096 + mISDN_HEADER_LEN]; 04212 iframe_t *frm = (iframe_t*)buf; 04213 int r; 04214 04215 switch (bc->bc_state) { 04216 case BCHAN_ACTIVATED: 04217 case BCHAN_BRIDGED: 04218 break; 04219 default: 04220 cb_log(3, bc->port, "BC not yet activated (state:%s)\n",bc_state2str(bc->bc_state)); 04221 return -1; 04222 } 04223 04224 frm->prim = DL_DATA|REQUEST; 04225 frm->dinfo = 0; 04226 frm->addr = bc->addr | FLG_MSG_DOWN ; 04227 04228 frm->len = len; 04229 memcpy(&buf[mISDN_HEADER_LEN], data,len); 04230 04231 if ( misdn_cap_is_speech(bc->capability) ) 04232 flip_buf_bits( &buf[mISDN_HEADER_LEN], len); 04233 else 04234 cb_log(6, stack->port, "Writing %d data bytes\n",len); 04235 04236 cb_log(9, stack->port, "Writing %d bytes 2 mISDN\n",len); 04237 r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT); 04238 return 0; 04239 }
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 3313 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().
03314 { 03315 //cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid); 03316 if (bc->send_lock) 03317 pthread_mutex_lock(&bc->send_lock->lock); 03318 }
void misdn_send_unlock | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3320 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().
03321 { 03322 //cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid); 03323 if (bc->send_lock) 03324 pthread_mutex_unlock(&bc->send_lock->lock); 03325 }
void misdn_split_conf | ( | struct misdn_bchannel * | bc, | |
int | conf_id | |||
) |
Definition at line 4549 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().
04550 { 04551 bc_state_change(bc,BCHAN_ACTIVATED); 04552 manager_ph_control(bc, CMX_RECEIVE_ON, 0); 04553 manager_ph_control(bc, CMX_CONF_SPLIT, conf_id); 04554 04555 cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id); 04556 }
void misdn_tx_jitter | ( | struct misdn_bchannel * | bc, | |
int | len | |||
) |
Definition at line 2250 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().
02251 { 02252 char buf[4096 + mISDN_HEADER_LEN]; 02253 char *data=&buf[mISDN_HEADER_LEN]; 02254 iframe_t *txfrm= (iframe_t*)buf; 02255 int jlen, r; 02256 02257 jlen=cb_jb_empty(bc,data,len); 02258 02259 if (jlen) { 02260 #ifdef MISDN_SAVE_DATA 02261 misdn_save_data((bc->port*100+bc->channel), data, jlen, bc->bframe, bc->bframe_len); 02262 #endif 02263 flip_buf_bits( data, jlen); 02264 02265 if (jlen < len) { 02266 cb_log(1, bc->port, "Jitterbuffer Underrun. Got %d of expected %d\n", jlen, len); 02267 } 02268 02269 txfrm->prim = DL_DATA|REQUEST; 02270 02271 txfrm->dinfo = 0; 02272 02273 txfrm->addr = bc->addr|FLG_MSG_DOWN; /* | IF_DOWN; */ 02274 02275 txfrm->len =jlen; 02276 cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len); 02277 02278 r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); 02279 } else { 02280 #define MISDN_GEN_SILENCE 02281 #ifdef MISDN_GEN_SILENCE 02282 int cnt=len/TONE_SILENCE_SIZE; 02283 int rest=len%TONE_SILENCE_SIZE; 02284 int i; 02285 02286 for (i=0; i<cnt; i++) { 02287 memcpy(data, tone_silence_flip, TONE_SILENCE_SIZE ); 02288 data +=TONE_SILENCE_SIZE; 02289 } 02290 02291 if (rest) { 02292 memcpy(data, tone_silence_flip, rest); 02293 } 02294 02295 txfrm->prim = DL_DATA|REQUEST; 02296 02297 txfrm->dinfo = 0; 02298 02299 txfrm->addr = bc->addr|FLG_MSG_DOWN; /* | IF_DOWN; */ 02300 02301 txfrm->len =len; 02302 cb_log(5, bc->port, "Transmitting %d samples of silence to misdn\n", len); 02303 02304 r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); 02305 #else 02306 r = 0; 02307 #endif 02308 } 02309 02310 if (r < 0) { 02311 cb_log(1, bc->port, "Error in mISDN_write (%s)\n", strerror(errno)); 02312 } 02313 }
static void prepare_bc | ( | struct misdn_bchannel * | bc, | |
int | channel | |||
) | [static] |
Definition at line 3157 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().
03158 { 03159 bc->channel = channel; 03160 bc->channel_preselected = channel?1:0; 03161 bc->in_use = 1; 03162 bc->need_disconnect=1; 03163 bc->need_release=1; 03164 bc->need_release_complete=1; 03165 bc->cause=16; 03166 03167 if (++mypid>5000) mypid=1; 03168 bc->pid=mypid; 03169 03170 #if 0 03171 bc->addr=0; 03172 bc->b_stid=0; 03173 bc->layer_id=0; 03174 #endif 03175 }
int queue_cleanup_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3742 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.
03743 { 03744 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03745 iframe_t *frm; 03746 if (!msg) { 03747 cb_log(0, bc->port, "misgn_lib_get_port: alloc_msg failed!\n"); 03748 return -1; 03749 } 03750 frm=(iframe_t*)msg->data; 03751 03752 /* activate bchannel */ 03753 frm->prim = MGR_CLEARSTACK| REQUEST; 03754 03755 frm->addr = bc->l3_id; 03756 03757 frm->dinfo = bc->port; 03758 frm->len = 0; 03759 03760 msg_queue_tail(&glob_mgr->activatequeue, msg); 03761 sem_post(&glob_mgr->new_msg); 03762 03763 return 0; 03764 03765 }
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 4329 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().
04330 { 04331 struct misdn_bchannel *help; 04332 cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id); 04333 04334 holder->stack_holder=1; 04335 04336 if (!stack ) return ; 04337 04338 holder->next=NULL; 04339 04340 if (!stack->holding) { 04341 stack->holding = holder; 04342 return; 04343 } 04344 04345 for (help=stack->holding; 04346 help; 04347 help=help->next) { 04348 if (!help->next) { 04349 help->next=holder; 04350 break; 04351 } 04352 } 04353 04354 }
struct misdn_bchannel * stack_holder_find | ( | struct misdn_stack * | stack, | |
unsigned long | l3id | |||
) |
Definition at line 4404 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().
04405 { 04406 struct misdn_bchannel *help; 04407 04408 cb_log(4,stack?stack->port:0, "*HOLDER: find %lx\n",l3id); 04409 04410 if (!stack) return NULL; 04411 04412 for (help=stack->holding; 04413 help; 04414 help=help->next) { 04415 if (help->l3_id == l3id) { 04416 cb_log(4,stack->port, "*HOLDER: found bc\n"); 04417 return help; 04418 } 04419 } 04420 04421 cb_log(4,stack->port, "*HOLDER: find nothing\n"); 04422 return NULL; 04423 }
struct misdn_bchannel * stack_holder_find_bychan | ( | struct misdn_stack * | stack, | |
int | chan | |||
) |
Definition at line 4382 of file isdn_lib.c.
References cb_log, misdn_bchannel::channel, misdn_stack::holding, misdn_bchannel::next, and misdn_stack::port.
04383 { 04384 struct misdn_bchannel *help; 04385 04386 cb_log(4,stack?stack->port:0, "*HOLDER: find_bychan %c\n", chan); 04387 04388 if (!stack) return NULL; 04389 04390 for (help=stack->holding; 04391 help; 04392 help=help->next) { 04393 if (help->channel == chan) { 04394 cb_log(4,stack->port, "*HOLDER: found_bychan bc\n"); 04395 return help; 04396 } 04397 } 04398 04399 cb_log(4,stack->port, "*HOLDER: find_bychan nothing\n"); 04400 return NULL; 04401 04402 }
void stack_holder_remove | ( | struct misdn_stack * | stack, | |
struct misdn_bchannel * | holder | |||
) |
Definition at line 4356 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().
04357 { 04358 struct misdn_bchannel *h1; 04359 04360 if (!holder->stack_holder) return; 04361 04362 holder->stack_holder=0; 04363 04364 cb_log(4,stack->port, "*HOLDER: remove %x\n",holder->l3_id); 04365 if (!stack || ! stack->holding) return; 04366 04367 if (holder == stack->holding) { 04368 stack->holding = stack->holding->next; 04369 return; 04370 } 04371 04372 for (h1=stack->holding; 04373 h1; 04374 h1=h1->next) { 04375 if (h1->next == holder) { 04376 h1->next=h1->next->next; 04377 return ; 04378 } 04379 } 04380 }
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 3097 of file isdn_lib.c.
References buf, cb_log, and entity.
Referenced by misdn_lib_destroy().
03098 { 03099 char buf[1024]; 03100 mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC); 03101 03102 cb_log(4, 0, "Entetity deleted\n"); 03103 mISDN_close(midev); 03104 cb_log(4, 0, "midev closed\n"); 03105 }
int te_lib_init | ( | void | ) |
App Interface
Definition at line 3070 of file isdn_lib.c.
References buff, entity, errno, and misdn_lib::midev.
Referenced by misdn_lib_init().
03070 { 03071 char buff[1025] = ""; 03072 iframe_t *frm=(iframe_t*)buff; 03073 int midev=mISDN_open(); 03074 int ret; 03075 03076 if (midev<=0) return midev; 03077 03078 /* create entity for layer 3 TE-mode */ 03079 mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 03080 ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC); 03081 03082 if (ret < mISDN_HEADER_LEN) { 03083 noentity: 03084 fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n",strerror(errno)); 03085 exit(-1); 03086 } 03087 03088 entity = frm->dinfo & 0xffff ; 03089 03090 if (!entity) 03091 goto noentity; 03092 03093 return midev; 03094 03095 }
static int test_inuse | ( | struct misdn_bchannel * | bc | ) | [static] |
Definition at line 3137 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().
03138 { 03139 struct timeval now; 03140 gettimeofday(&now, NULL); 03141 if (!bc->in_use) { 03142 if (misdn_lib_port_is_pri(bc->port) && bc->last_used.tv_sec == now.tv_sec ) { 03143 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); 03144 return 1; 03145 } 03146 03147 03148 cb_log(3,bc->port, "channel with stid:%x not in use!\n", bc->b_stid); 03149 return 0; 03150 } 03151 03152 cb_log(2,bc->port, "channel with stid:%x in use!\n", bc->b_stid); 03153 return 1; 03154 }
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 3857 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] |