#include <syslog.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>Include dependency graph for isdn_lib.c:

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 | 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) |
| 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) |
| int | misdn_lib_pid_restart (int pid) |
| int | misdn_lib_port_block (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) |
| 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_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) |
| 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) |
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 | newteid = 0 |
| static int | nt_err_cnt = 0 |
| char | tone_425_flip [TONE_425_SIZE] |
| char | tone_silence_flip [TONE_SILENCE_SIZE] |
| #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 |
Definition at line 181 of file isdn_lib.c.
| #define MISDN_DSP |
| #define MISDN_GEN_SILENCE |
| #define MISDN_IBUF_SIZE 512 |
| #define TONE_ALERT_CNT 41 |
Definition at line 207 of file isdn_lib.c.
| #define TONE_ALERT_SILENCE_CNT 200 |
Definition at line 208 of file isdn_lib.c.
| #define TONE_BUSY_CNT 20 |
Definition at line 210 of file isdn_lib.c.
| #define TONE_BUSY_SILENCE_CNT 48 |
Definition at line 211 of file isdn_lib.c.
| enum global_states |
Definition at line 141 of file isdn_lib.c.
00141 { 00142 MISDN_INITIALIZING, 00143 MISDN_INITIALIZED 00144 } ;
| static void bc_next_state_change | ( | struct misdn_bchannel * | bc, | |
| enum bchannel_state | state | |||
| ) | [static] |
Definition at line 539 of file isdn_lib.c.
References bc_state2str(), cb_log, misdn_bchannel::next_bc_state, and misdn_bchannel::port.
Referenced by misdn_lib_bridge().
00540 { 00541 cb_log(5,bc->port,"BC_NEXT_STATE_CHANGE: from:%s to:%s\n", 00542 bc_state2str(bc->next_bc_state), 00543 bc_state2str(state) ); 00544 00545 bc->next_bc_state=state; 00546 }
| char* bc_state2str | ( | enum bchannel_state | state | ) |
Definition at line 490 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().
00490 { 00491 int i; 00492 00493 struct bchan_state_s { 00494 char *n; 00495 enum bchannel_state s; 00496 } states[] = { 00497 {"BCHAN_CLEANED", BCHAN_CLEANED }, 00498 {"BCHAN_EMPTY", BCHAN_EMPTY}, 00499 {"BCHAN_SETUP", BCHAN_SETUP}, 00500 {"BCHAN_SETUPED", BCHAN_SETUPED}, 00501 {"BCHAN_ACTIVE", BCHAN_ACTIVE}, 00502 {"BCHAN_ACTIVATED", BCHAN_ACTIVATED}, 00503 {"BCHAN_BRIDGE", BCHAN_BRIDGE}, 00504 {"BCHAN_BRIDGED", BCHAN_BRIDGED}, 00505 {"BCHAN_RELEASE", BCHAN_RELEASE}, 00506 {"BCHAN_RELEASED", BCHAN_RELEASED}, 00507 {"BCHAN_CLEAN", BCHAN_CLEAN}, 00508 {"BCHAN_CLEAN_REQUEST", BCHAN_CLEAN_REQUEST}, 00509 {"BCHAN_ERROR", BCHAN_ERROR} 00510 }; 00511 00512 for (i=0; i< sizeof(states)/sizeof(struct bchan_state_s); i++) 00513 if ( states[i].s == state) 00514 return states[i].n; 00515 00516 return "UNKNOWN"; 00517 }
| void bc_state_change | ( | struct misdn_bchannel * | bc, | |
| enum bchannel_state | state | |||
| ) |
Definition at line 519 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(), misdn_split_conf(), and setup_bc().
00520 { 00521 cb_log(5,bc->port,"BC_STATE_CHANGE: l3id:%x from:%s to:%s\n", 00522 bc->l3_id, 00523 bc_state2str(bc->bc_state), 00524 bc_state2str(state) ); 00525 00526 switch (state) { 00527 case BCHAN_ACTIVATED: 00528 if (bc->next_bc_state == BCHAN_BRIDGED) { 00529 misdn_join_conf(bc, bc->conf_id); 00530 bc->next_bc_state = BCHAN_EMPTY; 00531 return; 00532 } 00533 default: 00534 bc->bc_state=state; 00535 break; 00536 } 00537 }
| 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 249 of file isdn_lib.c.
References INFO_CAPABILITY_AUDIO_3_1K, INFO_CAPABILITY_DIGITAL_RESTRICTED, INFO_CAPABILITY_DIGITAL_UNRESTRICTED, and INFO_CAPABILITY_SPEECH.
00249 { 00250 static char *bearers[]={ 00251 "Speech", 00252 "Audio 3.1k", 00253 "Unres Digital", 00254 "Res Digital", 00255 "Unknown Bearer" 00256 }; 00257 00258 switch (cap) { 00259 case INFO_CAPABILITY_SPEECH: 00260 return bearers[0]; 00261 break; 00262 case INFO_CAPABILITY_AUDIO_3_1K: 00263 return bearers[1]; 00264 break; 00265 case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: 00266 return bearers[2]; 00267 break; 00268 case INFO_CAPABILITY_DIGITAL_RESTRICTED: 00269 return bearers[3]; 00270 break; 00271 default: 00272 return bearers[4]; 00273 break; 00274 } 00275 }
| static int clean_up_bc | ( | struct misdn_bchannel * | bc | ) | [static] |
Definition at line 643 of file isdn_lib.c.
References misdn_bchannel::b_stid, misdn_stack::bc, misdn_bchannel::bc_state, bc_state_change(), BCHAN_CLEANED, 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(), handle_event_nt(), manager_event_handler(), misdn_lib_release(), misdn_lib_send_event(), and misdn_lib_setup_bc().
00644 { 00645 int ret=0; 00646 unsigned char buff[32]; 00647 struct misdn_stack * stack; 00648 00649 cb_log(3, bc?bc->port:0, "$$$ CLEANUP CALLED pid:%d\n", bc?bc->pid:-1); 00650 00651 if (!bc ) return -1; 00652 stack=get_stack_by_bc(bc); 00653 00654 if (!stack) return -1; 00655 00656 switch (bc->bc_state ) { 00657 case BCHAN_CLEANED: 00658 cb_log(5, stack->port, "$$$ Already cleaned up bc with stid :%x\n", bc->b_stid); 00659 return -1; 00660 00661 default: 00662 break; 00663 } 00664 00665 cb_log(2, stack->port, "$$$ Cleaning up bc with stid :%x pid:%d\n", bc->b_stid, bc->pid); 00666 00667 manager_ec_disable(bc); 00668 00669 manager_bchannel_deactivate(bc); 00670 00671 mISDN_write_frame(stack->midev, buff, bc->layer_id|FLG_MSG_TARGET|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 00672 00673 bc->b_stid = 0; 00674 bc_state_change(bc, BCHAN_CLEANED); 00675 00676 return ret; 00677 }
| static void clear_l3 | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 681 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().
00682 { 00683 int i; 00684 00685 for (i=0; i<=stack->b_num; i++) { 00686 if (global_state == MISDN_INITIALIZED) { 00687 cb_event(EVENT_CLEANUP, &stack->bc[i], NULL); 00688 empty_chan_in_stack(stack,i+1); 00689 empty_bc(&stack->bc[i]); 00690 clean_up_bc(&stack->bc[i]); 00691 } 00692 00693 } 00694 }
| static msg_t* create_l2msg | ( | int | prim, | |
| int | dinfo, | |||
| int | size | |||
| ) | [static] |
Definition at line 308 of file isdn_lib.c.
Referenced by misdn_lib_get_l2_down(), and misdn_lib_get_l2_up().
00309 { 00310 int i = 0; 00311 msg_t *dmsg; 00312 00313 while(i < 10) 00314 { 00315 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); 00316 if (dmsg) 00317 return(dmsg); 00318 00319 if (!i) 00320 printf("cannot allocate memory, trying again...\n"); 00321 i++; 00322 usleep(300000); 00323 } 00324 printf("cannot allocate memory, system overloaded.\n"); 00325 exit(-1); 00326 }
| msg_t* create_l3msg | ( | int | prim, | |
| int | mt, | |||
| int | dinfo, | |||
| int | size, | |||
| int | ntmode | |||
| ) |
Definition at line 330 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().
00331 { 00332 int i = 0; 00333 msg_t *dmsg; 00334 Q931_info_t *qi; 00335 iframe_t *frm; 00336 00337 if (!ntmode) 00338 size = sizeof(Q931_info_t)+2; 00339 00340 while(i < 10) { 00341 if (ntmode) { 00342 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); 00343 if (dmsg) { 00344 return(dmsg); 00345 } 00346 } else { 00347 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM); 00348 if (dmsg) 00349 { 00350 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN); 00351 frm = (iframe_t *)dmsg->data; 00352 frm->prim = prim; 00353 frm->dinfo = dinfo; 00354 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN); 00355 qi->type = mt; 00356 return(dmsg); 00357 } 00358 } 00359 00360 if (!i) printf("cannot allocate memory, trying again...\n"); 00361 i++; 00362 usleep(300000); 00363 } 00364 printf("cannot allocate memory, system overloaded.\n"); 00365 exit(-1); 00366 }
| static int create_process | ( | int | midev, | |
| struct misdn_bchannel * | bc | |||
| ) | [static] |
Definition at line 846 of file isdn_lib.c.
References misdn_stack::bc, cb_log, misdn_bchannel::channel, misdn_bchannel::channel_preselected, entity, find_free_chan_in_stack(), get_stack_by_bc(), misdn_bchannel::l3_id, MAXPROCS, misdn_stack::nt, misdn_stack::port, misdn_stack::procids, misdn_stack::ptp, set_chan_in_stack(), misdn_bchannel::te_choose_channel, and misdn_stack::upper_id.
Referenced by misdn_lib_send_event().
00846 { 00847 iframe_t ncr; 00848 int l3_id; 00849 int i; 00850 struct misdn_stack *stack=get_stack_by_bc(bc); 00851 00852 if (stack->nt) { 00853 if (!find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, 0)) 00854 return -1; 00855 /*bc->channel=free_chan;*/ 00856 00857 if (set_chan_in_stack(stack ,bc->channel)<0) return -1; 00858 00859 cb_log(4,stack->port, " --> found channel: %d\n", bc->channel); 00860 00861 for (i=0; i <= MAXPROCS; i++) 00862 if (stack->procids[i]==0) break; 00863 00864 if (i== MAXPROCS) { 00865 cb_log(0, stack->port, "Couldnt Create New ProcId.\n"); 00866 return -1; 00867 } 00868 stack->procids[i]=1; 00869 00870 l3_id = 0xff00 | i; 00871 00872 ncr.prim = CC_NEW_CR | REQUEST; 00873 00874 ncr.addr = (stack->upper_id | FLG_MSG_DOWN) ; 00875 00876 ncr.dinfo = l3_id; 00877 ncr.len = 0; 00878 00879 bc->l3_id = l3_id; 00880 cb_log(3, stack->port, " --> new_l3id %x\n",l3_id); 00881 00882 } else { 00883 if (stack->ptp || bc->te_choose_channel) { 00884 /* we know exactly which channels are in use */ 00885 if (!find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, 0)) 00886 return -1; 00887 /*bc->channel=free_chan;*/ 00888 cb_log(2,stack->port, " --> found channel: %d\n", bc->channel); 00889 00890 if (set_chan_in_stack(stack ,bc->channel)<0) return -1; 00891 } else { 00892 /* other phones could have made a call also on this port (ptmp) */ 00893 bc->channel=0xff; 00894 } 00895 00896 00897 /* if we are in te-mode, we need to create a process first */ 00898 if (newteid++ > 0xffff) 00899 newteid = 0x0001; 00900 00901 l3_id = (entity<<16) | newteid; 00902 /* preparing message */ 00903 ncr.prim = CC_NEW_CR | REQUEST; 00904 00905 ncr.addr = (stack->upper_id | FLG_MSG_DOWN) ; 00906 00907 ncr.dinfo =l3_id; 00908 ncr.len = 0; 00909 /* send message */ 00910 00911 bc->l3_id = l3_id; 00912 cb_log(3, stack->port, "--> new_l3id %x\n",l3_id); 00913 00914 mISDN_write(midev, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC); 00915 } 00916 00917 return l3_id; 00918 }
| static int do_tone | ( | struct misdn_bchannel * | bc, | |
| int | len | |||
| ) | [static] |
Definition at line 2178 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().
02179 { 02180 bc->tone_cnt=len; 02181 02182 if (bc->generate_tone) { 02183 cb_event(EVENT_TONE_GENERATE, bc, glob_mgr->user_data); 02184 02185 if ( !bc->nojitter ) { 02186 misdn_tx_jitter(bc,len); 02187 } 02188 02189 return 1; 02190 } 02191 02192 return 0; 02193 }
| static void dump_chan_list | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 422 of file isdn_lib.c.
References misdn_stack::b_num, cb_log, misdn_stack::channels, and misdn_stack::port.
Referenced by empty_chan_in_stack(), handle_cr(), and set_chan_in_stack().
00423 { 00424 int i; 00425 00426 for (i=0; i <= stack->b_num; i++) { 00427 cb_log(6, stack->port, "Idx:%d stack->cchan:%d Chan:%d\n",i,stack->channels[i], i+1); 00428 } 00429 }
| 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 549 of file isdn_lib.c.
References misdn_bchannel::active, misdn_bchannel::bframe_len, misdn_bchannel::cad, misdn_bchannel::capability, misdn_bchannel::cause, misdn_bchannel::channel, 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::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, misdn_bchannel::in_use, INFO_CAPABILITY_SPEECH, INFO_CODEC_ALAW, misdn_bchannel::info_dad, misdn_bchannel::infos_pending, 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(), handle_event_nt(), handle_frm(), init_bc(), manager_clean_bc(), misdn_lib_release(), and misdn_lib_send_event().
00550 { 00551 bc->bframe_len=0; 00552 00553 00554 bc->in_use= 0; 00555 bc->cw= 0; 00556 00557 bc->dec=0; 00558 bc->channel = 0; 00559 00560 bc->sending_complete = 0; 00561 00562 bc->restart_channel=0; 00563 00564 bc->conf_id = 0; 00565 00566 bc->need_more_infos = 0; 00567 00568 bc->send_dtmf=0; 00569 bc->nodsp=0; 00570 bc->nojitter=0; 00571 00572 bc->time_usec=0; 00573 00574 bc->rxgain=0; 00575 bc->txgain=0; 00576 00577 bc->crypt=0; 00578 bc->curptx=0; bc->curprx=0; 00579 00580 bc->crypt_key[0] = 0; 00581 00582 bc->generate_tone=0; 00583 bc->tone_cnt=0; 00584 00585 bc->dnumplan=NUMPLAN_UNKNOWN; 00586 bc->onumplan=NUMPLAN_UNKNOWN; 00587 bc->rnumplan=NUMPLAN_UNKNOWN; 00588 bc->cpnnumplan=NUMPLAN_UNKNOWN; 00589 00590 00591 bc->active = 0; 00592 00593 bc->early_bconnect = 1; 00594 00595 #ifdef MISDN_1_2 00596 *bc->pipeline = 0; 00597 #else 00598 bc->ec_enable = 0; 00599 bc->ec_deftaps = 128; 00600 #endif 00601 00602 bc->orig=0; 00603 00604 bc->cause=16; 00605 bc->out_cause=16; 00606 bc->pres=0 ; /* screened */ 00607 00608 bc->evq=EVENT_NOTHING; 00609 00610 bc->progress_coding=0; 00611 bc->progress_location=0; 00612 bc->progress_indicator=0; 00613 00614 /** Set Default Bearer Caps **/ 00615 bc->capability=INFO_CAPABILITY_SPEECH; 00616 bc->law=INFO_CODEC_ALAW; 00617 bc->mode=0; 00618 bc->rate=0x10; 00619 bc->user1=0; 00620 bc->urate=0; 00621 00622 bc->hdlc=0; 00623 00624 00625 bc->info_dad[0] = 0; 00626 bc->display[0] = 0; 00627 bc->infos_pending[0] = 0; 00628 bc->cad[0] = 0; 00629 bc->oad[0] = 0; 00630 bc->dad[0] = 0; 00631 bc->rad[0] = 0; 00632 bc->orig_dad[0] = 0; 00633 bc->uu[0]=0; 00634 bc->uulen=0; 00635 00636 bc->fac_in.Function = Fac_None; 00637 bc->fac_out.Function = Fac_None; 00638 00639 bc->te_choose_channel = 0; 00640 }
| static int empty_chan_in_stack | ( | struct misdn_stack * | stack, | |
| int | channel | |||
| ) | [static] |
Definition at line 477 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(), handle_event_nt(), handle_frm(), manager_clean_bc(), misdn_lib_release(), and misdn_lib_send_event().
00478 { 00479 if (channel<=0 || channel>MAX_BCHANS) { 00480 cb_log(0,stack?stack->port:0, "empty_chan_in_stack: cannot empty channel %d\n",channel); 00481 return -1; 00482 } 00483 00484 cb_log (4, stack?stack->port:0, "empty_chan_in_stack: %d\n",channel); 00485 stack->channels[channel-1] = 0; 00486 dump_chan_list(stack); 00487 return 0; 00488 }
| static char* fac2str | ( | enum FacFunction | func | ) | [static] |
Definition at line 3142 of file isdn_lib.c.
References s.
Referenced by misdn_lib_log_ies().
03143 { 03144 struct arr_el { 03145 enum FacFunction p; 03146 char *s ; 03147 } arr[] = { 03148 { Fac_None, "Fac_None" }, 03149 { Fac_CD, "Fac_CD"}, 03150 }; 03151 03152 int i; 03153 03154 for (i=0; i < sizeof(arr)/sizeof( struct arr_el) ; i ++) 03155 if ( arr[i].p==func) return arr[i].s; 03156 03157 return "unknown"; 03158 }
| static msg_t* fetch_msg | ( | int | midev | ) | [static] |
Definition at line 2880 of file isdn_lib.c.
References cb_log.
Referenced by misdn_lib_isdn_event_catcher().
02881 { 02882 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 02883 int r; 02884 02885 if (!msg) { 02886 cb_log(0, 0, "fetch_msg: alloc msg failed !!"); 02887 return NULL; 02888 } 02889 02890 AGAIN: 02891 r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC); 02892 msg->len=r; 02893 02894 if (r==0) { 02895 free_msg(msg); /* danger, cauz usualy freeing in main_loop */ 02896 cb_log(6,0,"Got empty Msg..\n"); 02897 return NULL; 02898 } 02899 02900 if (r<0) { 02901 if (errno == EAGAIN) { 02902 /*we wait for mISDN here*/ 02903 cb_log(4,0,"mISDN_read wants us to wait\n"); 02904 usleep(5000); 02905 goto AGAIN; 02906 } 02907 02908 cb_log(0,0,"mISDN_read returned :%d error:%s (%d)\n",r,strerror(errno),errno); 02909 } 02910 02911 #if 0 02912 if (!(frm->prim == (DL_DATA|INDICATION) )|| (frm->prim == (PH_DATA|INDICATION))) 02913 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 ); 02914 #endif 02915 return msg; 02916 }
| static struct misdn_bchannel* find_bc_by_addr | ( | unsigned long | addr | ) | [static] |
Definition at line 1435 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().
01436 { 01437 struct misdn_stack* stack; 01438 int i; 01439 01440 for (stack=glob_mgr->stack_list; 01441 stack; 01442 stack=stack->next) { 01443 for (i=0; i<=stack->b_num; i++) { 01444 if ( (stack->bc[i].addr&STACK_ID_MASK)==(addr&STACK_ID_MASK) || stack->bc[i].layer_id== addr ) { 01445 return &stack->bc[i]; 01446 } 01447 } 01448 } 01449 01450 return NULL; 01451 }
| static struct misdn_bchannel* find_bc_by_channel | ( | int | port, | |
| int | channel | |||
| ) | [static] |
Definition at line 1471 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().
01472 { 01473 struct misdn_stack* stack=find_stack_by_port(port); 01474 int i; 01475 01476 if (!stack) return NULL; 01477 01478 for (i=0; i<=stack->b_num; i++) { 01479 if ( stack->bc[i].channel== channel ) { 01480 return &stack->bc[i]; 01481 } 01482 } 01483 01484 return NULL; 01485 }
| struct misdn_bchannel * find_bc_by_confid | ( | unsigned long | confid | ) |
Definition at line 1453 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().
01454 { 01455 struct misdn_stack* stack; 01456 int i; 01457 01458 for (stack=glob_mgr->stack_list; 01459 stack; 01460 stack=stack->next) { 01461 for (i=0; i<=stack->b_num; i++) { 01462 if ( stack->bc[i].conf_id==confid ) { 01463 return &stack->bc[i]; 01464 } 01465 } 01466 } 01467 return NULL; 01468 }
| struct misdn_bchannel * find_bc_by_l3id | ( | struct misdn_stack * | stack, | |
| unsigned long | l3id | |||
| ) |
Definition at line 1416 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(), and manager_event_handler().
01417 { 01418 int i; 01419 for (i=0; i<=stack->b_num; i++) { 01420 if (stack->bc[i].l3_id == l3id) return &stack->bc[i] ; 01421 } 01422 return stack_holder_find(stack,l3id); 01423 }
| static struct misdn_bchannel* find_bc_by_masked_l3id | ( | struct misdn_stack * | stack, | |
| unsigned long | l3id, | |||
| unsigned long | mask | |||
| ) | [static] |
Definition at line 1406 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().
01407 { 01408 int i; 01409 for (i=0; i<=stack->b_num; i++) { 01410 if ( (stack->bc[i].l3_id & mask) == (l3id & mask)) return &stack->bc[i] ; 01411 } 01412 return stack_holder_find(stack,l3id); 01413 }
| static struct misdn_bchannel* find_bc_holded | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 1425 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, and misdn_bchannel::holded.
Referenced by manager_find_bc_holded().
01426 { 01427 int i; 01428 for (i=0; i<=stack->b_num; i++) { 01429 if (stack->bc[i].holded ) return &stack->bc[i] ; 01430 } 01431 return NULL; 01432 }
| static int find_free_chan_in_stack | ( | struct misdn_stack * | stack, | |
| struct misdn_bchannel * | bc, | |||
| int | channel, | |||
| int | dec | |||
| ) | [static] |
Definition at line 434 of file isdn_lib.c.
References misdn_stack::b_num, cb_log, misdn_bchannel::channel, 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().
00435 { 00436 int i; 00437 00438 cb_log(5,stack->port,"find_free_chan: req_chan:%d\n",channel); 00439 00440 if (channel < 0 || channel > MAX_BCHANS) { 00441 cb_log(0, stack->port, " !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel); 00442 return 0; 00443 } 00444 00445 channel--; 00446 00447 int bnums=stack->pri?stack->b_num:stack->b_num-1; 00448 00449 if (dec) { 00450 for (i = bnums; i >=0; i--) { 00451 if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */ 00452 if (!stack->channels[i]) { 00453 cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1); 00454 bc->channel=i+1; 00455 return i+1; 00456 } 00457 } 00458 } 00459 } else { 00460 for (i = 0; i <= bnums; i++) { 00461 if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */ 00462 if (!stack->channels[i]) { 00463 cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1); 00464 bc->channel=i+1; 00465 return i+1; 00466 } 00467 } 00468 } 00469 } 00470 00471 cb_log (1, stack->port, " !! NO FREE CHAN IN STACK\n"); 00472 dump_chan_list(stack); 00473 00474 return 0; 00475 }
| static struct misdn_stack* find_stack_by_addr | ( | int | addr | ) | [static] |
Definition at line 1367 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().
01368 { 01369 struct misdn_stack *stack; 01370 01371 for (stack=glob_mgr->stack_list; 01372 stack; 01373 stack=stack->next) { 01374 if ( (stack->upper_id&STACK_ID_MASK) == (addr&STACK_ID_MASK)) return stack; 01375 01376 } 01377 01378 return NULL; 01379 }
| static struct misdn_stack* find_stack_by_mgr | ( | manager_t * | mgr_nt | ) | [static] |
Definition at line 1394 of file isdn_lib.c.
References glob_mgr, misdn_stack::mgr, misdn_stack::next, and misdn_lib::stack_list.
Referenced by handle_event_nt().
01395 { 01396 struct misdn_stack *stack; 01397 01398 for (stack=glob_mgr->stack_list; 01399 stack; 01400 stack=stack->next) 01401 if ( &stack->mgr == mgr_nt) return stack; 01402 01403 return NULL; 01404 }
| static struct misdn_stack* find_stack_by_port | ( | int | port | ) | [static] |
Definition at line 1382 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().
01383 { 01384 struct misdn_stack *stack; 01385 01386 for (stack=glob_mgr->stack_list; 01387 stack; 01388 stack=stack->next) 01389 if (stack->port == port) return stack; 01390 01391 return NULL; 01392 }
| static char* flip_buf_bits | ( | char * | buf, | |
| int | len | |||
| ) | [static] |
Definition at line 293 of file isdn_lib.c.
References flip_table.
Referenced by handle_bchan(), misdn_lib_init(), misdn_lib_tx2misdn_frm(), and misdn_tx_jitter().
00294 { 00295 int i; 00296 char * start = buf; 00297 00298 for (i = 0 ; i < len; i++) { 00299 buf[i] = flip_table[(unsigned char)buf[i]]; 00300 } 00301 00302 return start; 00303 }
| struct misdn_stack * get_misdn_stack | ( | void | ) |
Definition at line 4356 of file isdn_lib.c.
References glob_mgr, and misdn_lib::stack_list.
Referenced by get_show_stack_details(), get_stack_by_bc(), misdn_lib_get_maxchans(), misdn_lib_is_port_blocked(), misdn_lib_is_ptp(), misdn_lib_port_block(), misdn_lib_port_is_pri(), and misdn_lib_port_unblock().
04356 { 04357 return glob_mgr->stack_list; 04358 }
| void get_show_stack_details | ( | int | port, | |
| char * | buf | |||
| ) |
Definition at line 121 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, and misdn_stack::port.
Referenced by misdn_show_port(), and misdn_show_stacks().
00122 { 00123 struct misdn_stack *stack=get_misdn_stack(); 00124 00125 for ( ; stack; stack=stack->next) { 00126 if (stack->port == port) break; 00127 } 00128 00129 if (stack) { 00130 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); 00131 00132 } else { 00133 buf[0]=0; 00134 } 00135 00136 }
| struct misdn_stack* get_stack_by_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 104 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().
00105 { 00106 struct misdn_stack *stack=get_misdn_stack(); 00107 00108 if (!bc) return NULL; 00109 00110 for ( ; stack; stack=stack->next) { 00111 int i; 00112 for (i=0; i <=stack->b_num; i++) { 00113 if ( bc->port == stack->port) return stack; 00114 } 00115 } 00116 00117 return NULL; 00118 }
| static int handle_bchan | ( | msg_t * | msg | ) | [static] |
Definition at line 2281 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, misdn_bchannel::capability, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), misdn_bchannel::dad, misdn_bchannel::dnumplan, do_tone(), misdn_bchannel::dtmf, 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, t, and misdn_lib::user_data.
Referenced by handle_err(), and manager_isdn_handler().
02282 { 02283 iframe_t *frm= (iframe_t*)msg->data; 02284 02285 02286 struct misdn_bchannel *bc=find_bc_by_addr(frm->addr); 02287 02288 if (!bc) { 02289 cb_log(1,0,"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo); 02290 return 0 ; 02291 } 02292 02293 struct misdn_stack *stack=get_stack_by_bc(bc); 02294 02295 if (!stack) { 02296 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); 02297 return 0; 02298 } 02299 02300 switch (frm->prim) { 02301 02302 case MGR_SETSTACK| CONFIRM: 02303 cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|CONFIRM pid:%d\n",bc->pid); 02304 break; 02305 02306 case MGR_SETSTACK| INDICATION: 02307 cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->pid); 02308 break; 02309 #if 0 02310 AGAIN: 02311 bc->addr = mISDN_get_layerid(stack->midev, bc->b_stid, bc->layer); 02312 if (!bc->addr) { 02313 02314 if (errno == EAGAIN) { 02315 usleep(1000); 02316 goto AGAIN; 02317 } 02318 02319 cb_log(0,stack->port,"$$$ Get Layer (%d) Id Error: %s\n",bc->layer,strerror(errno)); 02320 02321 /* we kill the channel later, when we received some 02322 data. */ 02323 bc->addr= frm->addr; 02324 } else if ( bc->addr < 0) { 02325 cb_log(0, stack->port,"$$$ bc->addr <0 Error:%s\n",strerror(errno)); 02326 bc->addr=0; 02327 } 02328 02329 cb_log(4, stack->port," --> Got Adr %x\n", bc->addr); 02330 02331 free_msg(msg); 02332 02333 02334 switch(bc->bc_state) { 02335 case BCHAN_SETUP: 02336 bc_state_change(bc,BCHAN_SETUPED); 02337 break; 02338 02339 case BCHAN_CLEAN_REQUEST: 02340 default: 02341 cb_log(0, stack->port," --> STATE WASN'T SETUP (but %s) in SETSTACK|IND pid:%d\n",bc_state2str(bc->bc_state), bc->pid); 02342 clean_up_bc(bc); 02343 } 02344 return 1; 02345 #endif 02346 02347 case MGR_DELLAYER| INDICATION: 02348 cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->pid); 02349 break; 02350 02351 case MGR_DELLAYER| CONFIRM: 02352 cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|CNF pid:%d\n",bc->pid); 02353 02354 bc->pid=0; 02355 bc->addr=0; 02356 02357 free_msg(msg); 02358 return 1; 02359 02360 case PH_ACTIVATE | INDICATION: 02361 case DL_ESTABLISH | INDICATION: 02362 cb_log(3, stack->port, "BCHAN: ACT Ind pid:%d\n", bc->pid); 02363 02364 free_msg(msg); 02365 return 1; 02366 02367 case PH_ACTIVATE | CONFIRM: 02368 case DL_ESTABLISH | CONFIRM: 02369 02370 cb_log(3, stack->port, "BCHAN: bchan ACT Confirm pid:%d\n",bc->pid); 02371 free_msg(msg); 02372 02373 return 1; 02374 02375 case DL_ESTABLISH | REQUEST: 02376 { 02377 char buf[128]; 02378 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_ESTABLISH | CONFIRM, 0,0, NULL, TIMEOUT_1SEC); 02379 } 02380 free_msg(msg); 02381 return 1; 02382 02383 case DL_RELEASE|REQUEST: 02384 { 02385 char buf[128]; 02386 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_RELEASE| CONFIRM, 0,0, NULL, TIMEOUT_1SEC); 02387 } 02388 free_msg(msg); 02389 return 1; 02390 02391 case PH_DEACTIVATE | INDICATION: 02392 case DL_RELEASE | INDICATION: 02393 cb_log (3, stack->port, "BCHAN: DeACT Ind pid:%d\n",bc->pid); 02394 02395 free_msg(msg); 02396 return 1; 02397 02398 case PH_DEACTIVATE | CONFIRM: 02399 case DL_RELEASE | CONFIRM: 02400 cb_log(3, stack->port, "BCHAN: DeACT Conf pid:%d\n",bc->pid); 02401 02402 free_msg(msg); 02403 return 1; 02404 02405 case PH_CONTROL|INDICATION: 02406 { 02407 unsigned int cont = *((unsigned int *)&frm->data.p); 02408 02409 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); 02410 02411 if ((cont&~DTMF_TONE_MASK) == DTMF_TONE_VAL) { 02412 int dtmf = cont & DTMF_TONE_MASK; 02413 cb_log(4, stack->port, " --> DTMF TONE: %c\n",dtmf); 02414 bc->dtmf=dtmf; 02415 cb_event(EVENT_DTMF_TONE, bc, glob_mgr->user_data); 02416 02417 free_msg(msg); 02418 return 1; 02419 } 02420 if (cont == BF_REJECT) { 02421 cb_log(4, stack->port, " --> BF REJECT\n"); 02422 free_msg(msg); 02423 return 1; 02424 } 02425 if (cont == BF_ACCEPT) { 02426 cb_log(4, stack->port, " --> BF ACCEPT\n"); 02427 free_msg(msg); 02428 return 1; 02429 } 02430 } 02431 break; 02432 02433 case PH_DATA|REQUEST: 02434 case DL_DATA|REQUEST: 02435 cb_log(0, stack->port, "DL_DATA REQUEST \n"); 02436 do_tone(bc, 64); 02437 02438 free_msg(msg); 02439 return 1; 02440 02441 02442 case PH_DATA|INDICATION: 02443 case DL_DATA|INDICATION: 02444 { 02445 bc->bframe = (void*)&frm->data.i; 02446 bc->bframe_len = frm->len; 02447 02448 /** Anyway flip the bufbits **/ 02449 if ( misdn_cap_is_speech(bc->capability) ) 02450 flip_buf_bits(bc->bframe, bc->bframe_len); 02451 02452 02453 if (!bc->bframe_len) { 02454 cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); 02455 free_msg(msg); 02456 return 1; 02457 } 02458 02459 if ( (bc->addr&STACK_ID_MASK) != (frm->addr&STACK_ID_MASK) ) { 02460 cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); 02461 free_msg(msg); 02462 return 1; 02463 } 02464 02465 #if MISDN_DEBUG 02466 cb_log(0, stack->port, "DL_DATA INDICATION Len %d\n", frm->len); 02467 02468 #endif 02469 02470 if ( (bc->bc_state == BCHAN_ACTIVATED) && frm->len > 0) { 02471 int t; 02472 02473 #ifdef MISDN_B_DEBUG 02474 cb_log(0,bc->port,"do_tone START\n"); 02475 #endif 02476 t=do_tone(bc,frm->len); 02477 02478 #ifdef MISDN_B_DEBUG 02479 cb_log(0,bc->port,"do_tone STOP (%d)\n",t); 02480 #endif 02481 if ( !t ) { 02482 02483 if ( misdn_cap_is_speech(bc->capability)) { 02484 if ( !bc->nojitter ) { 02485 #ifdef MISDN_B_DEBUG 02486 cb_log(0,bc->port,"tx_jitter START\n"); 02487 #endif 02488 misdn_tx_jitter(bc,frm->len); 02489 #ifdef MISDN_B_DEBUG 02490 cb_log(0,bc->port,"tx_jitter STOP\n"); 02491 #endif 02492 } 02493 } 02494 02495 #ifdef MISDN_B_DEBUG 02496 cb_log(0,bc->port,"EVENT_B_DATA START\n"); 02497 #endif 02498 02499 int i=cb_event( EVENT_BCHAN_DATA, bc, glob_mgr->user_data); 02500 #ifdef MISDN_B_DEBUG 02501 cb_log(0,bc->port,"EVENT_B_DATA STOP\n"); 02502 #endif 02503 02504 if (i<0) { 02505 cb_log(10,stack->port,"cb_event returned <0\n"); 02506 /*clean_up_bc(bc);*/ 02507 } 02508 } 02509 } 02510 free_msg(msg); 02511 return 1; 02512 } 02513 02514 02515 case PH_CONTROL | CONFIRM: 02516 cb_log(4, stack->port, "PH_CONTROL|CNF bc->addr:%x\n", frm->addr); 02517 free_msg(msg); 02518 return 1; 02519 02520 case PH_DATA | CONFIRM: 02521 case DL_DATA|CONFIRM: 02522 #if MISDN_DEBUG 02523 02524 cb_log(0, stack->port, "Data confirmed\n"); 02525 02526 #endif 02527 free_msg(msg); 02528 return 1; 02529 case DL_DATA|RESPONSE: 02530 #if MISDN_DEBUG 02531 cb_log(0, stack->port, "Data response\n"); 02532 02533 #endif 02534 break; 02535 } 02536 02537 return 0; 02538 }
| static int handle_cr | ( | struct misdn_stack * | stack, | |
| iframe_t * | frm | |||
| ) | [static] |
Definition at line 1566 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::l3_id, misdn_lib_get_free_bc(), 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(), and handle_frm().
01567 { 01568 if (!stack) return -1; 01569 01570 switch (frm->prim) { 01571 case CC_NEW_CR|INDICATION: 01572 cb_log(7, stack->port, " --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo); 01573 01574 struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0); 01575 if (!bc) { 01576 cb_log(0, stack->port, " --> !! lib: No free channel!\n"); 01577 return -1; 01578 } 01579 01580 cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo); 01581 bc->l3_id=frm->dinfo; 01582 return 1; 01583 case CC_NEW_CR|CONFIRM: 01584 return 1; 01585 case CC_NEW_CR|REQUEST: 01586 return 1; 01587 case CC_RELEASE_CR|REQUEST: 01588 return 1; 01589 case CC_RELEASE_CR|CONFIRM: 01590 break; 01591 case CC_RELEASE_CR|INDICATION: 01592 cb_log(4, stack->port, " --> lib: RELEASE_CR Ind with l3id:%x\n",frm->dinfo); 01593 { 01594 struct misdn_bchannel *bc=find_bc_by_l3id(stack, frm->dinfo); 01595 struct misdn_bchannel dummybc; 01596 01597 if (!bc) { 01598 cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo); 01599 memset (&dummybc,0,sizeof(dummybc)); 01600 dummybc.port=stack->port; 01601 dummybc.l3_id=frm->dinfo; 01602 dummybc.nt=stack->nt; 01603 bc=&dummybc; 01604 } 01605 01606 if (bc) { 01607 cb_log(4, stack->port, " --> lib: CLEANING UP l3id: %x\n",frm->dinfo); 01608 if (bc->channel>0) 01609 empty_chan_in_stack(stack,bc->channel); 01610 empty_bc(bc); 01611 01612 clean_up_bc(bc); 01613 01614 dump_chan_list(stack); 01615 /*bc->pid = 0;*/ 01616 bc->need_disconnect=0; 01617 bc->need_release=0; 01618 bc->need_release_complete=0; 01619 01620 cb_event(EVENT_CLEANUP, bc, glob_mgr->user_data); 01621 if (bc->stack_holder) { 01622 cb_log(4,stack->port, "REMOVEING Holder\n"); 01623 stack_holder_remove( stack, bc); 01624 free(bc); 01625 } 01626 } 01627 else { 01628 if (stack->nt) 01629 cb_log(4, stack->port, "BC with dinfo: %x not found.. (prim was %x and addr %x)\n",frm->dinfo, frm->prim, frm->addr); 01630 } 01631 01632 return 1; 01633 } 01634 break; 01635 } 01636 01637 return 0; 01638 }
| static int handle_err | ( | msg_t * | msg | ) | [static] |
Definition at line 3411 of file isdn_lib.c.
References misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), cb_log, 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().
03412 { 03413 iframe_t *frm = (iframe_t*) msg->data; 03414 03415 03416 if (!frm->addr) { 03417 static int cnt=0; 03418 if (!cnt) 03419 cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo); 03420 cnt++; 03421 if (cnt>100) { 03422 cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo); 03423 cnt=0; 03424 } 03425 03426 free_msg(msg); 03427 return 1; 03428 03429 } 03430 03431 switch (frm->prim) { 03432 case MGR_SETSTACK|INDICATION: 03433 return handle_bchan(msg); 03434 break; 03435 03436 case MGR_SETSTACK|CONFIRM: 03437 case MGR_CLEARSTACK|CONFIRM: 03438 free_msg(msg) ; 03439 return 1; 03440 break; 03441 03442 case DL_DATA|CONFIRM: 03443 cb_log(4,0,"DL_DATA|CONFIRM\n"); 03444 free_msg(msg); 03445 return 1; 03446 03447 case PH_CONTROL|CONFIRM: 03448 cb_log(4,0,"PH_CONTROL|CONFIRM\n"); 03449 free_msg(msg); 03450 return 1; 03451 03452 case DL_DATA|INDICATION: 03453 { 03454 int port=(frm->addr&MASTER_ID_MASK) >> 8; 03455 int channel=(frm->addr&CHILD_ID_MASK) >> 16; 03456 03457 /*we flush the read buffer here*/ 03458 03459 cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel); 03460 03461 free_msg(msg) ; 03462 return 1; 03463 03464 03465 struct misdn_bchannel *bc=find_bc_by_channel( port , channel); 03466 03467 if (!bc) { 03468 struct misdn_stack *stack=find_stack_by_port( port ); 03469 03470 if (!stack) { 03471 cb_log(0,0," --> stack not found\n"); 03472 free_msg(msg); 03473 return 1; 03474 } 03475 03476 cb_log(0,0," --> bc not found by channel\n"); 03477 if (stack->l2link) 03478 misdn_lib_get_l2_down(stack); 03479 03480 if (stack->l1link) 03481 misdn_lib_get_l1_down(stack); 03482 03483 free_msg(msg); 03484 return 1; 03485 } 03486 03487 cb_log(3,port," --> BC in state:%s\n", bc_state2str(bc->bc_state)); 03488 } 03489 } 03490 03491 return 0; 03492 }
| static int handle_event | ( | struct misdn_bchannel * | bc, | |
| enum event_e | event, | |||
| iframe_t * | frm | |||
| ) | [static] |
Definition at line 1491 of file isdn_lib.c.
References misdn_stack::bc, misdn_bchannel::capability, misdn_bchannel::cause, cb_log, misdn_bchannel::channel, clean_up_bc(), misdn_bchannel::crypt_key, misdn_bchannel::dad, misdn_bchannel::dnumplan, empty_bc(), empty_chan_in_stack(), 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_ph_control_block(), misdn_cap_is_speech(), misdn_lib_send_event(), misdn_stack::nt, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_bchannel::out_cause, misdn_stack::port, misdn_bchannel::port, set_chan_in_stack(), and setup_bc().
Referenced by handle_frm().
01492 { 01493 struct misdn_stack *stack=get_stack_by_bc(bc); 01494 01495 if (!stack->nt) { 01496 01497 switch (event) { 01498 01499 case EVENT_CONNECT_ACKNOWLEDGE: 01500 #if 0 01501 if ( !misdn_cap_is_speech(bc->capability)) { 01502 int ret=setup_bc(bc); 01503 if (ret == -EINVAL){ 01504 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 01505 } 01506 } 01507 #endif 01508 break; 01509 case EVENT_CONNECT: 01510 01511 if ( *bc->crypt_key ) { 01512 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); 01513 manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); 01514 } 01515 case EVENT_ALERTING: 01516 case EVENT_PROGRESS: 01517 case EVENT_PROCEEDING: 01518 case EVENT_SETUP_ACKNOWLEDGE: 01519 01520 setup_bc(bc); 01521 01522 case EVENT_SETUP: 01523 { 01524 if (bc->channel == 0xff) { 01525 if (!find_free_chan_in_stack(stack, bc, 0, 0)) { 01526 cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n"); 01527 bc->out_cause=34; 01528 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 01529 return -1; 01530 } 01531 } 01532 01533 if (bc->channel >0 && bc->channel<255) { 01534 int ret=set_chan_in_stack(stack ,bc->channel); 01535 if (event == EVENT_SETUP && ret<0){ 01536 /* empty bchannel */ 01537 bc->channel=0; 01538 bc->out_cause=44; 01539 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 01540 return -1; 01541 } 01542 } 01543 } 01544 break; 01545 01546 case EVENT_RELEASE_COMPLETE: 01547 case EVENT_RELEASE: 01548 if (bc->channel>0) 01549 empty_chan_in_stack(stack,bc->channel); 01550 int tmpcause=bc->cause; 01551 int tmp_out_cause=bc->out_cause; 01552 empty_bc(bc); 01553 bc->cause=tmpcause; 01554 bc->out_cause=tmp_out_cause; 01555 clean_up_bc(bc); 01556 break; 01557 default: 01558 break; 01559 } 01560 } else { /** NT MODE **/ 01561 01562 } 01563 return 0; 01564 }
| int handle_event_nt | ( | void * | dat, | |
| void * | arg | |||
| ) | [static] |
Definition at line 1740 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::bc, misdn_bchannel::capability, misdn_bchannel::cause, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), create_l3msg(), empty_bc(), empty_chan_in_stack(), event, 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::holded, 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_stack::mgr, misdn_cap_is_speech(), misdn_lib_get_free_bc(), misdn_lib_get_l2_up(), misdn_lib_reinit_nt_stack(), misdn_lib_send_event(), mISDNUSER_HEAD_SIZE, msgs_g, misdn_stack::nst, misdn_stack::nt, misdn_bchannel::out_cause, misdn_bchannel::port, misdn_stack::port, misdn_stack::procids, misdn_stack::ptp, set_chan_in_stack(), setup_bc(), stack_holder_find(), stack_holder_remove(), misdn_stack::upper_id, and misdn_lib::user_data.
Referenced by misdn_lib_reinit_nt_stack().
01741 { 01742 manager_t *mgr = (manager_t *)dat; 01743 msg_t *msg = (msg_t *)arg; 01744 mISDNuser_head_t *hh; 01745 int reject=0; 01746 01747 struct misdn_stack *stack=find_stack_by_mgr(mgr); 01748 int port; 01749 01750 if (!msg || !mgr) 01751 return(-EINVAL); 01752 01753 hh=(mISDNuser_head_t*)msg->data; 01754 port=stack->port; 01755 01756 cb_log(5, stack->port, " --> lib: prim %x dinfo %x\n",hh->prim, hh->dinfo); 01757 { 01758 switch(hh->prim){ 01759 case CC_RETRIEVE|INDICATION: 01760 { 01761 iframe_t frm; /* fake te frm to add callref to global callreflist */ 01762 frm.dinfo = hh->dinfo; 01763 01764 frm.addr=stack->upper_id | FLG_MSG_DOWN; 01765 01766 frm.prim = CC_NEW_CR|INDICATION; 01767 01768 if (handle_cr( stack, &frm)< 0) { 01769 msg_t *dmsg; 01770 cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo); 01771 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01772 stack->nst.manager_l3(&stack->nst, dmsg); 01773 free_msg(msg); 01774 return 0; 01775 } 01776 01777 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01778 struct misdn_bchannel *hold_bc=stack_holder_find(stack,bc->l3_id); 01779 cb_log(4, stack->port, "bc_l3id:%x holded_bc_l3id:%x\n",bc->l3_id, hold_bc->l3_id); 01780 01781 if (hold_bc) { 01782 cb_log(4, stack->port, "REMOVEING Holder\n"); 01783 01784 /*swap the backup to our new channel back*/ 01785 stack_holder_remove(stack, hold_bc); 01786 memcpy(bc,hold_bc,sizeof(struct misdn_bchannel)); 01787 free(hold_bc); 01788 01789 bc->holded=0; 01790 } 01791 01792 } 01793 01794 break; 01795 01796 case CC_SETUP|CONFIRM: 01797 { 01798 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01799 int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE)); 01800 cb_log(4, stack->port, " --> lib: Event_ind:SETUP CONFIRM [NT] : new L3ID is %x\n",l3id ); 01801 01802 if (!bc) { cb_log(4, stack->port, "Bc Not found (after SETUP CONFIRM)\n"); return 0; } 01803 cb_log (2,bc->port,"I IND :CC_SETUP|CONFIRM: old l3id:%x new l3id:%x\n", bc->l3_id, l3id); 01804 bc->l3_id=l3id; 01805 cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data); 01806 } 01807 free_msg(msg); 01808 return 0; 01809 01810 case CC_SETUP|INDICATION: 01811 { 01812 struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0); 01813 if (!bc) 01814 ERR_NO_CHANNEL: 01815 { 01816 msg_t *dmsg; 01817 cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo); 01818 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01819 stack->nst.manager_l3(&stack->nst, dmsg); 01820 free_msg(msg); 01821 return 0; 01822 } 01823 01824 cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",hh->dinfo); 01825 bc->l3_id=hh->dinfo; 01826 } 01827 break; 01828 01829 case CC_CONNECT_ACKNOWLEDGE|INDICATION: 01830 #if 0 01831 { 01832 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01833 if (bc) { 01834 if ( !misdn_cap_is_speech(bc->capability)) { 01835 int ret=setup_bc(bc); 01836 if (ret == -EINVAL){ 01837 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 01838 01839 } 01840 } 01841 } 01842 } 01843 #endif 01844 break; 01845 01846 case CC_ALERTING|INDICATION: 01847 case CC_PROCEEDING|INDICATION: 01848 case CC_SETUP_ACKNOWLEDGE|INDICATION: 01849 if(!stack->ptp) break; 01850 case CC_CONNECT|INDICATION: 01851 { 01852 #if 0 01853 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01854 01855 if (!bc) { 01856 msg_t *dmsg; 01857 cb_log(0, stack->port,"!!!! We didn't found our bc, dinfo:%x on this port.\n",hh->dinfo); 01858 01859 cb_log(0, stack->port, "Releaseing call %x (No free Chan for you..)\n", hh->dinfo); 01860 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01861 stack->nst.manager_l3(&stack->nst, dmsg); 01862 free_msg(msg); 01863 return 0; 01864 01865 } 01866 int ret=setup_bc(bc); 01867 if (ret == -EINVAL){ 01868 cb_log(0,bc->port,"handle_event_nt: setup_bc failed\n"); 01869 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 01870 } 01871 #endif 01872 } 01873 break; 01874 case CC_DISCONNECT|INDICATION: 01875 { 01876 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01877 if (!bc) { 01878 bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000); 01879 if (bc) { 01880 int myprocid=bc->l3_id&0x0000ffff; 01881 hh->dinfo=(hh->dinfo&0xffff0000)|myprocid; 01882 cb_log(3,stack->port,"Reject dinfo: %x cause:%d\n",hh->dinfo,bc->cause); 01883 reject=1; 01884 } 01885 } 01886 } 01887 break; 01888 01889 case CC_FACILITY|INDICATION: 01890 { 01891 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01892 if (!bc) { 01893 bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000); 01894 if (bc) { 01895 int myprocid=bc->l3_id&0x0000ffff; 01896 hh->dinfo=(hh->dinfo&0xffff0000)|myprocid; 01897 cb_log(4,bc->port,"Repaired reject Bug, new dinfo: %x\n",hh->dinfo); 01898 } 01899 } 01900 } 01901 break; 01902 01903 case CC_RELEASE_COMPLETE|INDICATION: 01904 break; 01905 01906 case CC_SUSPEND|INDICATION: 01907 { 01908 msg_t *dmsg; 01909 cb_log(4, stack->port, " --> Got Suspend, sending Reject for now\n"); 01910 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST,MT_SUSPEND_REJECT, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01911 stack->nst.manager_l3(&stack->nst, dmsg); 01912 free_msg(msg); 01913 return 0; 01914 } 01915 break; 01916 case CC_RESUME|INDICATION: 01917 break; 01918 01919 case CC_RELEASE|CONFIRM: 01920 break; 01921 01922 case CC_RELEASE|INDICATION: 01923 break; 01924 01925 case CC_RELEASE_CR|INDICATION: 01926 { 01927 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01928 struct misdn_bchannel dummybc; 01929 iframe_t frm; /* fake te frm to remove callref from global callreflist */ 01930 frm.dinfo = hh->dinfo; 01931 01932 frm.addr=stack->upper_id | FLG_MSG_DOWN; 01933 01934 frm.prim = CC_RELEASE_CR|INDICATION; 01935 cb_log(4, stack->port, " --> Faking Realease_cr for %x\n",frm.addr); 01936 /** removing procid **/ 01937 if (!bc) { 01938 cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", hh->dinfo); 01939 memset (&dummybc,0,sizeof(dummybc)); 01940 dummybc.port=stack->port; 01941 dummybc.l3_id=hh->dinfo; 01942 dummybc.nt=stack->nt; 01943 bc=&dummybc; 01944 } 01945 01946 if (bc) { 01947 if ( (bc->l3_id & 0xff00) == 0xff00) { 01948 cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", bc->l3_id&0xff); 01949 stack->procids[bc->l3_id&0xff] = 0 ; 01950 } 01951 } 01952 else cb_log(0, stack->port, "Couldnt find BC so I couldnt remove the Process!!!! this is a bad port.\n"); 01953 01954 if (handle_cr(stack, &frm)<0) { 01955 } 01956 01957 free_msg(msg); 01958 return 0 ; 01959 } 01960 break; 01961 01962 case CC_NEW_CR|INDICATION: 01963 /* Got New CR for bchan, for now I handle this one in */ 01964 /* connect_ack, Need to be changed */ 01965 { 01966 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01967 int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE)); 01968 if (!bc) { cb_log(0, stack->port, " --> In NEW_CR: didn't found bc ??\n"); return -1;}; 01969 if (((l3id&0xff00)!=0xff00) && ((bc->l3_id&0xff00)==0xff00)) { 01970 cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", 0xff&bc->l3_id); 01971 stack->procids[bc->l3_id&0xff] = 0 ; 01972 } 01973 cb_log(4, stack->port, "lib: Event_ind:CC_NEW_CR : very new L3ID is %x\n",l3id ); 01974 01975 bc->l3_id =l3id; 01976 cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data); 01977 01978 free_msg(msg); 01979 return 0; 01980 } 01981 01982 case DL_ESTABLISH | INDICATION: 01983 case DL_ESTABLISH | CONFIRM: 01984 { 01985 cb_log(3, stack->port, "%% GOT L2 Activate Info.\n"); 01986 01987 if (stack->ptp && stack->l2link) { 01988 cb_log(0, stack->port, "%% GOT L2 Activate Info. but we're activated already.. this l2 is faulty, blocking port\n"); 01989 cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data); 01990 } 01991 01992 /* when we get the L2 UP, the L1 is UP definitely too*/ 01993 stack->l1link = 1; 01994 stack->l2link = 1; 01995 stack->l2upcnt=0; 01996 01997 free_msg(msg); 01998 return 0; 01999 } 02000 break; 02001 02002 02003 case DL_RELEASE | INDICATION: 02004 case DL_RELEASE | CONFIRM: 02005 { 02006 if (stack->ptp) { 02007 cb_log(3 , stack->port, "%% GOT L2 DeActivate Info.\n"); 02008 02009 if (stack->l2upcnt>3) { 02010 cb_log(0 , stack->port, "!!! Could not Get the L2 up after 3 Attemps!!!\n"); 02011 } else { 02012 #if 0 02013 if (stack->nt) misdn_lib_reinit_nt_stack(stack->port); 02014 #endif 02015 if (stack->l1link) { 02016 misdn_lib_get_l2_up(stack); 02017 stack->l2upcnt++; 02018 } 02019 } 02020 02021 } else 02022 cb_log(3, stack->port, "%% GOT L2 DeActivate Info.\n"); 02023 02024 stack->l2link = 0; 02025 free_msg(msg); 02026 return 0; 02027 } 02028 break; 02029 } 02030 } 02031 02032 { 02033 /* Parse Events and fire_up to App. */ 02034 struct misdn_bchannel *bc; 02035 struct misdn_bchannel dummybc; 02036 02037 enum event_e event = isdn_msg_get_event(msgs_g, msg, 1); 02038 02039 bc=find_bc_by_l3id(stack, hh->dinfo); 02040 02041 if (!bc) { 02042 02043 cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x).\n", hh->dinfo); 02044 memset (&dummybc,0,sizeof(dummybc)); 02045 dummybc.port=stack->port; 02046 dummybc.l3_id=hh->dinfo; 02047 dummybc.nt=stack->nt; 02048 bc=&dummybc; 02049 } 02050 if (bc ) { 02051 isdn_msg_parse_event(msgs_g,msg,bc, 1); 02052 02053 switch (event) { 02054 case EVENT_SETUP: 02055 if (bc->channel<=0 || bc->channel==0xff) { 02056 bc->channel=find_free_chan_in_stack(stack,bc, 0,0); 02057 if (bc->channel<=0) 02058 goto ERR_NO_CHANNEL; 02059 } else if (!stack->ptp) 02060 cb_log(3,stack->port," --> PTMP but channel requested\n"); 02061 02062 int ret=set_chan_in_stack(stack, bc->channel); 02063 if (event==EVENT_SETUP && ret<0){ 02064 /* empty bchannel */ 02065 bc->channel=0; 02066 bc->out_cause=44; 02067 02068 goto ERR_NO_CHANNEL; 02069 } 02070 break; 02071 case EVENT_RELEASE: 02072 case EVENT_RELEASE_COMPLETE: 02073 if (bc->channel>0) 02074 empty_chan_in_stack(stack, bc->channel); 02075 int tmpcause=bc->cause; 02076 empty_bc(bc); 02077 bc->cause=tmpcause; 02078 clean_up_bc(bc); 02079 break; 02080 02081 default: 02082 break; 02083 } 02084 02085 if(!isdn_get_info(msgs_g,event,1)) { 02086 cb_log(4, stack->port, "Unknown Event Ind: prim %x dinfo %x\n",hh->prim, hh->dinfo); 02087 } else { 02088 if (reject) { 02089 switch(bc->cause){ 02090 case 17: 02091 cb_log(1, stack->port, "Siemens Busy reject..\n"); 02092 02093 break; 02094 default: 02095 break; 02096 } 02097 } 02098 cb_event(event, bc, glob_mgr->user_data); 02099 } 02100 02101 } else { 02102 cb_log(4, stack->port, "No BC found with l3id: prim %x dinfo %x\n",hh->prim, hh->dinfo); 02103 } 02104 02105 free_msg(msg); 02106 } 02107 02108 02109 return 0; 02110 }
| static int handle_frm | ( | msg_t * | msg | ) | [static] |
Definition at line 2577 of file isdn_lib.c.
References bc_state_change(), BCHAN_CLEANED, cb_event, cb_log, misdn_bchannel::channel, empty_bc(), empty_chan_in_stack(), event, EVENT_RELEASE_COMPLETE, EVENT_SETUP, find_bc_by_l3id(), find_stack_by_addr(), glob_mgr, handle_cr(), handle_event(), isdn_get_info(), isdn_msg_get_event(), isdn_msg_parse_event(), misdn_lib_send_event(), msgs_g, misdn_stack::nt, misdn_bchannel::out_cause, misdn_stack::port, RESPONSE_IGNORE_SETUP, RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE, RESPONSE_OK, RESPONSE_RELEASE_SETUP, and misdn_lib::user_data.
Referenced by manager_event_handler(), and manager_isdn_handler().
02578 { 02579 iframe_t *frm = (iframe_t*) msg->data; 02580 02581 struct misdn_stack *stack=find_stack_by_addr(frm->addr); 02582 02583 if (!stack || stack->nt) { 02584 return 0; 02585 } 02586 02587 cb_log(4,stack?stack->port:0,"handle_frm: frm->addr:%x frm->prim:%x\n",frm->addr,frm->prim); 02588 02589 { 02590 struct misdn_bchannel *bc; 02591 int ret=handle_cr(stack, frm); 02592 02593 if (ret<0) { 02594 cb_log(3,stack?stack->port:0,"handle_frm: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr); 02595 02596 02597 } 02598 02599 if(ret) { 02600 free_msg(msg); 02601 return 1; 02602 } 02603 02604 bc=find_bc_by_l3id(stack, frm->dinfo); 02605 02606 handle_frm_bc: 02607 if (bc ) { 02608 enum event_e event = isdn_msg_get_event(msgs_g, msg, 0); 02609 enum event_response_e response=RESPONSE_OK; 02610 02611 isdn_msg_parse_event(msgs_g,msg,bc, 0); 02612 02613 /** Preprocess some Events **/ 02614 int ret=handle_event(bc, event, frm); 02615 if (ret<0) { 02616 cb_log(0,stack->port,"couldn't handle event\n"); 02617 free_msg(msg); 02618 return 1; 02619 } 02620 /* shoot up event to App: */ 02621 cb_log(5, stack->port, "lib Got Prim: Addr %x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo); 02622 02623 if(!isdn_get_info(msgs_g,event,0)) 02624 cb_log(0, stack->port, "Unknown Event Ind: Addr:%x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo); 02625 else 02626 response=cb_event(event, bc, glob_mgr->user_data); 02627 #if 1 02628 if (event == EVENT_SETUP) { 02629 switch (response) { 02630 case RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE: 02631 02632 cb_log(0, stack->port, "TOTALY IGNORING SETUP \n"); 02633 02634 break; 02635 case RESPONSE_IGNORE_SETUP: 02636 /* I think we should send CC_RELEASE_CR, but am not sure*/ 02637 bc->out_cause=16; 02638 02639 case RESPONSE_RELEASE_SETUP: 02640 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 02641 if (bc->channel>0) 02642 empty_chan_in_stack(stack, bc->channel); 02643 empty_bc(bc); 02644 bc_state_change(bc,BCHAN_CLEANED); 02645 02646 cb_log(0, stack->port, "GOT IGNORE SETUP\n"); 02647 02648 02649 break; 02650 case RESPONSE_OK: 02651 cb_log(4, stack->port, "GOT SETUP OK\n"); 02652 02653 02654 break; 02655 default: 02656 break; 02657 } 02658 } 02659 02660 cb_log(5, stack->port, "Freeing Msg on prim:%x \n",frm->prim); 02661 02662 02663 free_msg(msg); 02664 return 1; 02665 #endif 02666 02667 } else { 02668 cb_log(0, stack->port, " --> Didn't find BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo); 02669 struct misdn_bchannel dummybc; 02670 memset (&dummybc,0,sizeof(dummybc)); 02671 dummybc.port=stack->port; 02672 dummybc.l3_id=frm->dinfo; 02673 bc=&dummybc; 02674 goto handle_frm_bc; 02675 } 02676 } 02677 02678 cb_log(4, stack->port, "TE_FRM_HANDLER: Returning 0 on prim:%x \n",frm->prim); 02679 return 0; 02680 }
| static int handle_frm_nt | ( | msg_t * | msg | ) | [static] |
Definition at line 2542 of file isdn_lib.c.
References cb_log, find_stack_by_addr(), misdn_stack::nst, misdn_stack::nt, nt_err_cnt, and misdn_stack::port.
Referenced by manager_event_handler(), and manager_isdn_handler().
02543 { 02544 iframe_t *frm= (iframe_t*)msg->data; 02545 struct misdn_stack *stack; 02546 int err=0; 02547 02548 stack=find_stack_by_addr( frm->addr ); 02549 02550 02551 02552 if (!stack || !stack->nt) { 02553 return 0; 02554 } 02555 02556 02557 if ((err=stack->nst.l1_l2(&stack->nst,msg))) { 02558 02559 if (nt_err_cnt > 0 ) { 02560 if (nt_err_cnt < 100) { 02561 nt_err_cnt++; 02562 cb_log(0, stack->port, "NT Stack sends us error: %d \n", err); 02563 } else if (nt_err_cnt < 105){ 02564 cb_log(0, stack->port, "NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err); 02565 nt_err_cnt = - 1; 02566 } 02567 } 02568 free_msg(msg); 02569 return 1; 02570 02571 } 02572 02573 return 1; 02574 }
| static int handle_l1 | ( | msg_t * | msg | ) | [static] |
Definition at line 2683 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, cb_event, cb_log, EVENT_CLEANUP, EVENT_NOTHING, misdn_bchannel::evq, find_stack_by_addr(), glob_mgr, global_state, isdn_get_info(), misdn_stack::l1link, MISDN_INITIALIZED, misdn_lib_get_l2_up(), misdn_lib_send_event(), msgs_g, misdn_stack::nst, misdn_stack::nt, misdn_stack::port, misdn_stack::ptp, and misdn_lib::user_data.
Referenced by manager_isdn_handler().
02684 { 02685 iframe_t *frm = (iframe_t*) msg->data; 02686 struct misdn_stack *stack = find_stack_by_addr(frm->addr); 02687 int i ; 02688 02689 if (!stack) return 0 ; 02690 02691 switch (frm->prim) { 02692 case PH_ACTIVATE | CONFIRM: 02693 case PH_ACTIVATE | INDICATION: 02694 cb_log (3, stack->port, "L1: PH L1Link Up!\n"); 02695 stack->l1link=1; 02696 02697 if (stack->nt) { 02698 02699 if (stack->nst.l1_l2(&stack->nst, msg)) 02700 free_msg(msg); 02701 02702 if (stack->ptp) 02703 misdn_lib_get_l2_up(stack); 02704 } else { 02705 free_msg(msg); 02706 } 02707 02708 for (i=0;i<=stack->b_num; i++) { 02709 if (stack->bc[i].evq != EVENT_NOTHING) { 02710 cb_log(4, stack->port, "Fireing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0)); 02711 misdn_lib_send_event(&stack->bc[i],stack->bc[i].evq); 02712 stack->bc[i].evq=EVENT_NOTHING; 02713 } 02714 02715 } 02716 return 1; 02717 02718 case PH_ACTIVATE | REQUEST: 02719 free_msg(msg); 02720 cb_log(3,stack->port,"L1: PH_ACTIVATE|REQUEST \n"); 02721 return 1; 02722 02723 case PH_DEACTIVATE | REQUEST: 02724 free_msg(msg); 02725 cb_log(3,stack->port,"L1: PH_DEACTIVATE|REQUEST \n"); 02726 return 1; 02727 02728 case PH_DEACTIVATE | CONFIRM: 02729 case PH_DEACTIVATE | INDICATION: 02730 cb_log (3, stack->port, "L1: PH L1Link Down! \n"); 02731 02732 for (i=0; i<=stack->b_num; i++) { 02733 if (global_state == MISDN_INITIALIZED) { 02734 cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data); 02735 } 02736 } 02737 02738 if (stack->nt) { 02739 if (stack->nst.l1_l2(&stack->nst, msg)) 02740 free_msg(msg); 02741 } else { 02742 free_msg(msg); 02743 } 02744 02745 stack->l1link=0; 02746 stack->l2link=0; 02747 return 1; 02748 } 02749 02750 return 0; 02751 }
| static int handle_l2 | ( | msg_t * | msg | ) | [static] |
Definition at line 2753 of file isdn_lib.c.
References misdn_stack::bc, cb_event, cb_log, EVENT_PORT_ALARM, find_stack_by_addr(), glob_mgr, misdn_stack::l2link, misdn_stack::port, misdn_stack::ptp, and misdn_lib::user_data.
Referenced by manager_isdn_handler().
02754 { 02755 iframe_t *frm = (iframe_t*) msg->data; 02756 02757 struct misdn_stack *stack = find_stack_by_addr(frm->addr); 02758 02759 if (!stack) { 02760 return 0 ; 02761 } 02762 02763 switch(frm->prim) { 02764 02765 case DL_ESTABLISH | REQUEST: 02766 cb_log(1,stack->port,"DL_ESTABLISH|REQUEST \n"); 02767 return 1; 02768 case DL_RELEASE | REQUEST: 02769 cb_log(1,stack->port,"DL_RELEASE|REQUEST \n"); 02770 return 1; 02771 02772 case DL_ESTABLISH | INDICATION: 02773 case DL_ESTABLISH | CONFIRM: 02774 { 02775 cb_log (3, stack->port, "L2: L2Link Up! \n"); 02776 if (stack->ptp && stack->l2link) { 02777 cb_log (-1, stack->port, "L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n"); 02778 cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data); 02779 } 02780 stack->l2link=1; 02781 free_msg(msg); 02782 return 1; 02783 } 02784 break; 02785 02786 case DL_RELEASE | INDICATION: 02787 case DL_RELEASE | CONFIRM: 02788 { 02789 cb_log (3, stack->port, "L2: L2Link Down! \n"); 02790 stack->l2link=0; 02791 02792 free_msg(msg); 02793 return 1; 02794 } 02795 break; 02796 } 02797 return 0; 02798 }
| static int handle_mgmt | ( | msg_t * | msg | ) | [static] |
Definition at line 2800 of file isdn_lib.c.
References cb_log, clear_l3(), find_stack_by_addr(), misdn_stack::l1link, misdn_stack::l2link, and misdn_stack::port.
Referenced by manager_isdn_handler().
02801 { 02802 iframe_t *frm = (iframe_t*) msg->data; 02803 02804 if ( (frm->addr == 0) && (frm->prim == (MGR_DELLAYER|CONFIRM)) ) { 02805 cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: 0 !\n") ; 02806 free_msg(msg); 02807 return 1; 02808 } 02809 02810 struct misdn_stack * stack=find_stack_by_addr(frm->addr); 02811 02812 if (!stack) { 02813 if (frm->prim == (MGR_DELLAYER|CONFIRM)) { 02814 cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: %x !\n", 02815 frm->addr) ; 02816 free_msg(msg); 02817 return 1; 02818 } 02819 02820 return 0; 02821 } 02822 02823 switch(frm->prim) { 02824 case MGR_SHORTSTATUS | INDICATION: 02825 case MGR_SHORTSTATUS | CONFIRM: 02826 cb_log(5, 0, "MGMT: Short status dinfo %x\n",frm->dinfo); 02827 02828 switch (frm->dinfo) { 02829 case SSTATUS_L1_ACTIVATED: 02830 cb_log(3, 0, "MGMT: SSTATUS: L1_ACTIVATED \n"); 02831 stack->l1link=1; 02832 02833 break; 02834 case SSTATUS_L1_DEACTIVATED: 02835 cb_log(3, 0, "MGMT: SSTATUS: L1_DEACTIVATED \n"); 02836 stack->l1link=0; 02837 02838 clear_l3(stack); 02839 break; 02840 02841 case SSTATUS_L2_ESTABLISHED: 02842 cb_log(3, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n"); 02843 02844 /*when the L2 goes UP, L1 needs to be UP too*/ 02845 stack->l1link=1; 02846 stack->l2link=1; 02847 break; 02848 02849 case SSTATUS_L2_RELEASED: 02850 cb_log(3, stack->port, "MGMT: SSTATUS: L2_RELEASED \n"); 02851 stack->l2link=0; 02852 break; 02853 } 02854 02855 free_msg(msg); 02856 return 1; 02857 02858 case MGR_SETSTACK | INDICATION: 02859 cb_log(4, stack->port, "MGMT: SETSTACK|IND dinfo %x\n",frm->dinfo); 02860 free_msg(msg); 02861 return 1; 02862 case MGR_DELLAYER | CONFIRM: 02863 cb_log(4, stack->port, "MGMT: DELLAYER|CNF dinfo %x\n",frm->dinfo) ; 02864 free_msg(msg); 02865 return 1; 02866 02867 } 02868 02869 /* 02870 if ( (frm->prim & 0x0f0000) == 0x0f0000) { 02871 cb_log(5, 0, "$$$ MGMT FRAME: prim %x addr %x dinfo %x\n",frm->prim, frm->addr, frm->dinfo) ; 02872 free_msg(msg); 02873 return 1; 02874 } */ 02875 02876 return 0; 02877 }
| static int handle_timers | ( | msg_t * | msg | ) | [static] |
Definition at line 2113 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().
02114 { 02115 iframe_t *frm= (iframe_t*)msg->data; 02116 struct misdn_stack *stack; 02117 02118 /* Timer Stuff */ 02119 switch (frm->prim) { 02120 case MGR_INITTIMER | CONFIRM: 02121 case MGR_ADDTIMER | CONFIRM: 02122 case MGR_DELTIMER | CONFIRM: 02123 case MGR_REMOVETIMER | CONFIRM: 02124 free_msg(msg); 02125 return(1); 02126 } 02127 02128 02129 02130 if (frm->prim==(MGR_TIMER | INDICATION) ) { 02131 for (stack = glob_mgr->stack_list; 02132 stack; 02133 stack = stack->next) { 02134 itimer_t *it; 02135 02136 if (!stack->nt) continue; 02137 02138 it = stack->nst.tlist; 02139 /* find timer */ 02140 for(it=stack->nst.tlist; 02141 it; 02142 it=it->next) { 02143 if (it->id == (int)frm->addr) 02144 break; 02145 } 02146 if (it) { 02147 int ret; 02148 ret = mISDN_write_frame(stack->midev, msg->data, frm->addr, 02149 MGR_TIMER | RESPONSE, 0, 0, NULL, TIMEOUT_1SEC); 02150 test_and_clear_bit(FLG_TIMER_RUNING, (long unsigned int *)&it->Flags); 02151 ret = it->function(it->data); 02152 free_msg(msg); 02153 return 1; 02154 } 02155 } 02156 02157 cb_log(0, 0, "Timer Msg without Timer ??\n"); 02158 free_msg(msg); 02159 return 1; 02160 } 02161 02162 return 0; 02163 }
| 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 1093 of file isdn_lib.c.
References misdn_bchannel::astbuf, misdn_stack::bc, bc_state_change(), BCHAN_CLEANED, cb_log, empty_bc(), malloc, MISDN_IBUF_SIZE, misdn_bchannel::msn, misdn_stack::nt, misdn_bchannel::nt, misdn_stack::port, and misdn_bchannel::port.
Referenced by misdn_lib_init().
01094 { 01095 unsigned char buff[1025]; 01096 iframe_t *frm = (iframe_t *)buff; 01097 int ret; 01098 01099 if (!bc) return -1; 01100 01101 cb_log(8, port, "Init.BC %d.\n",bidx); 01102 01103 memset(bc, 0,sizeof(struct misdn_bchannel)); 01104 01105 if (msn) { 01106 int l = sizeof(bc->msn); 01107 strncpy(bc->msn,msn, l); 01108 bc->msn[l-1] = 0; 01109 } 01110 01111 01112 empty_bc(bc); 01113 bc_state_change(bc, BCHAN_CLEANED); 01114 01115 bc->port=stack->port; 01116 bc->nt=stack->nt?1:0; 01117 01118 { 01119 ibuffer_t* ibuf= init_ibuffer(MISDN_IBUF_SIZE); 01120 01121 if (!ibuf) return -1; 01122 01123 clear_ibuffer( ibuf); 01124 01125 ibuf->rsem=malloc(sizeof(sem_t)); 01126 01127 bc->astbuf=ibuf; 01128 01129 if (sem_init(ibuf->rsem,1,0)<0) 01130 sem_init(ibuf->rsem,0,0); 01131 01132 } 01133 01134 01135 01136 01137 { 01138 stack_info_t *stinf; 01139 ret = mISDN_get_stack_info(midev, stack->port, buff, sizeof(buff)); 01140 if (ret < 0) { 01141 cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret); 01142 return -1; 01143 } 01144 01145 stinf = (stack_info_t *)&frm->data.p; 01146 01147 cb_log(8, port, " --> Child %x\n",stinf->child[bidx]); 01148 } 01149 01150 return 0; 01151 }
| static void init_flip_bits | ( | void | ) | [static] |
Definition at line 280 of file isdn_lib.c.
References flip_table.
Referenced by misdn_lib_init().
00281 { 00282 int i,k; 00283 00284 for (i = 0 ; i < 256 ; i++) { 00285 unsigned char sample = 0 ; 00286 for (k = 0; k<8; k++) { 00287 if ( i & 1 << k ) sample |= 0x80 >> k; 00288 } 00289 flip_table[i] = sample; 00290 } 00291 }
| void isdn_lib_stop_dtmf | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4115 of file isdn_lib.c.
References misdn_stack::bc, and manager_ph_control().
Referenced by process_ast_dsp().
04116 { 04117 manager_ph_control(bc, DTMF_TONE_STOP, 0); 04118 }
| void isdn_lib_update_ec | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4103 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().
04104 { 04105 #ifdef MISDN_1_2 04106 if (*bc->pipeline) 04107 #else 04108 if (bc->ec_enable) 04109 #endif 04110 manager_ec_enable(bc); 04111 else 04112 manager_ec_disable(bc); 04113 }
| void isdn_lib_update_rxgain | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4093 of file isdn_lib.c.
References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::rxgain.
Referenced by process_ast_dsp().
04094 { 04095 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 04096 }
| void isdn_lib_update_txgain | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4098 of file isdn_lib.c.
References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::txgain.
Referenced by process_ast_dsp().
04099 { 04100 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 04101 }
| void manager_bchannel_activate | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3973 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::astbuf, misdn_stack::bc, cb_log, get_stack_by_bc(), misdn_stack::midev, misdn_bchannel::port, and misdn_stack::port.
Referenced by setup_bc().
03974 { 03975 char buf[128]; 03976 03977 struct misdn_stack *stack=get_stack_by_bc(bc); 03978 03979 if (!stack) { 03980 cb_log(0, bc->port, "bchannel_activate: Stack not found !"); 03981 return ; 03982 } 03983 03984 /* we must activate if we are deactivated */ 03985 clear_ibuffer(bc->astbuf); 03986 03987 cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr); 03988 03989 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC); 03990 03991 return ; 03992 }
| void manager_bchannel_cleanup | ( | struct misdn_bchannel * | bc | ) |
| void manager_bchannel_deactivate | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3995 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, 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().
03996 { 03997 03998 struct misdn_stack *stack=get_stack_by_bc(bc); 03999 04000 04001 switch (bc->bc_state) { 04002 case BCHAN_ACTIVATED: 04003 break; 04004 case BCHAN_BRIDGED: 04005 misdn_split_conf(bc,bc->conf_id); 04006 break; 04007 default: 04008 cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n"); 04009 return ; 04010 04011 } 04012 04013 cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr); 04014 04015 bc->generate_tone=0; 04016 04017 iframe_t dact; 04018 dact.prim = DL_RELEASE | REQUEST; 04019 dact.addr = bc->addr | FLG_MSG_DOWN; 04020 dact.dinfo = 0; 04021 dact.len = 0; 04022 char buf[128]; 04023 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC); 04024 04025 clear_ibuffer(bc->astbuf); 04026 04027 bc_state_change(bc,BCHAN_RELEASE); 04028 04029 return; 04030 }
| void manager_bchannel_setup | ( | struct misdn_bchannel * | bc | ) |
| void manager_clean_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4142 of file isdn_lib.c.
References misdn_stack::bc, cb_event, misdn_bchannel::channel, empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, and get_stack_by_bc().
Referenced by misdn_lib_pid_restart().
04143 { 04144 struct misdn_stack *stack=get_stack_by_bc(bc); 04145 04146 if (bc->channel>0) 04147 empty_chan_in_stack(stack, bc->channel); 04148 empty_bc(bc); 04149 04150 cb_event(EVENT_CLEANUP, bc, NULL); 04151 }
| void manager_ec_disable | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4335 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(), isdn_lib_update_ec(), and misdn_toggle_echocancel().
04336 { 04337 struct misdn_stack *stack=get_stack_by_bc(bc); 04338 04339 cb_log(4, stack?stack->port:0," --> ec_disable\n"); 04340 04341 if (!misdn_cap_is_speech(bc->capability)) { 04342 cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n"); 04343 return; 04344 } 04345 04346 #ifdef MISDN_1_2 04347 manager_ph_control_block(bc, PIPELINE_CFG, "", 0); 04348 #else 04349 if ( ! bc->ec_enable) { 04350 cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n"); 04351 manager_ph_control(bc, ECHOCAN_OFF, 0); 04352 } 04353 #endif 04354 }
| void manager_ec_enable | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4286 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 isdn_lib_update_ec(), misdn_lib_send_event(), and misdn_toggle_echocancel().
04287 { 04288 struct misdn_stack *stack=get_stack_by_bc(bc); 04289 04290 cb_log(4, stack?stack->port:0,"ec_enable\n"); 04291 04292 if (!misdn_cap_is_speech(bc->capability)) { 04293 cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n"); 04294 } else { 04295 04296 #ifdef MISDN_1_2 04297 if (*bc->pipeline) { 04298 cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline); 04299 manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1); 04300 } 04301 #else 04302 int ec_arr[2]; 04303 04304 if (bc->ec_enable) { 04305 cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps); 04306 04307 switch (bc->ec_deftaps) { 04308 case 4: 04309 case 8: 04310 case 16: 04311 case 32: 04312 case 64: 04313 case 128: 04314 case 256: 04315 case 512: 04316 case 1024: 04317 cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps); 04318 break; 04319 default: 04320 cb_log(0, stack->port, "Taps should be power of 2\n"); 04321 bc->ec_deftaps=128; 04322 } 04323 04324 ec_arr[0]=bc->ec_deftaps; 04325 ec_arr[1]=0; 04326 04327 manager_ph_control_block(bc, ECHOCAN_ON, ec_arr, sizeof(ec_arr)); 04328 } 04329 #endif 04330 } 04331 }
| static void manager_event_handler | ( | void * | arg | ) | [static] |
Definition at line 3697 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_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.
03698 { 03699 sem_post(&handler_started); 03700 while (1) { 03701 struct misdn_stack *stack; 03702 msg_t *msg; 03703 03704 /** wait for events **/ 03705 sem_wait(&glob_mgr->new_msg); 03706 03707 for (msg=msg_dequeue(&glob_mgr->activatequeue); 03708 msg; 03709 msg=msg_dequeue(&glob_mgr->activatequeue) 03710 ) 03711 { 03712 03713 iframe_t *frm = (iframe_t*) msg->data ; 03714 03715 switch ( frm->prim) { 03716 03717 case MGR_CLEARSTACK | REQUEST: 03718 /*a queued bchannel cleanup*/ 03719 { 03720 struct misdn_stack *stack=find_stack_by_port(frm->dinfo); 03721 if (!stack) { 03722 cb_log(0,0,"no stack found with port [%d]!! so we cannot cleanup the bc\n",frm->dinfo); 03723 free_msg(msg); 03724 break; 03725 } 03726 03727 struct misdn_bchannel *bc=find_bc_by_l3id(stack,frm->addr); 03728 if (bc) { 03729 cb_log(1,bc->port,"CLEARSTACK queued, cleaning up\n"); 03730 clean_up_bc(bc); 03731 } else { 03732 cb_log(0,stack->port,"bc could not be cleaned correctly !! addr [%x]\n",frm->addr); 03733 } 03734 } 03735 free_msg(msg); 03736 break; 03737 case MGR_SETSTACK | REQUEST : 03738 break; 03739 default: 03740 mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); 03741 free_msg(msg); 03742 } 03743 } 03744 03745 for (stack=glob_mgr->stack_list; 03746 stack; 03747 stack=stack->next ) { 03748 03749 while ( (msg=msg_dequeue(&stack->upqueue)) ) { 03750 /** Handle L2/3 Signalling after bchans **/ 03751 if (!handle_frm_nt(msg)) { 03752 /* Maybe it's TE */ 03753 if (!handle_frm(msg)) { 03754 /* wow none! */ 03755 cb_log(0,stack->port,"Wow we've got a strange issue while dequeueing a Frame\n"); 03756 } 03757 } 03758 } 03759 03760 /* Here we should check if we really want to 03761 send all the messages we've queued, lets 03762 assume we've queued a Disconnect, but 03763 received it already from the other side!*/ 03764 03765 while ( (msg=msg_dequeue(&stack->downqueue)) ) { 03766 if (stack->nt ) { 03767 if (stack->nst.manager_l3(&stack->nst, msg)) 03768 cb_log(0, stack->port, "Error@ Sending Message in NT-Stack.\n"); 03769 03770 } else { 03771 iframe_t *frm = (iframe_t *)msg->data; 03772 struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo); 03773 if (bc) send_msg(glob_mgr->midev, bc, msg); 03774 else { 03775 if (frm->dinfo == MISDN_ID_GLOBAL) { 03776 struct misdn_bchannel dummybc; 03777 memset (&dummybc,0,sizeof(dummybc)); 03778 dummybc.port=stack->port; 03779 dummybc.l3_id=MISDN_ID_GLOBAL; 03780 dummybc.nt=stack->nt; 03781 send_msg(glob_mgr->midev, &dummybc, msg); 03782 } 03783 } 03784 } 03785 } 03786 } 03787 } 03788 }
| struct misdn_bchannel * manager_find_bc_by_pid | ( | int | pid | ) |
Definition at line 3030 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().
03031 { 03032 struct misdn_stack *stack; 03033 int i; 03034 03035 for (stack=glob_mgr->stack_list; 03036 stack; 03037 stack=stack->next) { 03038 for (i=0; i<=stack->b_num; i++) 03039 if (stack->bc[i].pid == pid) return &stack->bc[i]; 03040 } 03041 03042 return NULL; 03043 }
| struct misdn_bchannel * manager_find_bc_holded | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3045 of file isdn_lib.c.
References misdn_stack::bc, find_bc_holded(), and get_stack_by_bc().
03046 { 03047 struct misdn_stack *stack=get_stack_by_bc(bc); 03048 return find_bc_holded(stack); 03049 }
| char* manager_isdn_get_info | ( | enum event_e | event | ) |
Definition at line 3968 of file isdn_lib.c.
References isdn_get_info(), and msgs_g.
Referenced by cb_events().
03969 { 03970 return isdn_get_info(msgs_g , event, 0); 03971 }
| int manager_isdn_handler | ( | iframe_t * | frm, | |
| msg_t * | msg | |||
| ) |
Definition at line 3512 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(), LOG_NOTICE, and misdn_stack::port.
Referenced by misdn_lib_isdn_event_catcher().
03513 { 03514 03515 if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) { 03516 cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n"); 03517 } 03518 03519 if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) { 03520 if (handle_bchan(msg)) { 03521 return 0 ; 03522 } 03523 } 03524 03525 #ifdef RECV_FRM_SYSLOG_DEBUG 03526 syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo); 03527 #endif 03528 03529 if (handle_timers(msg)) 03530 return 0 ; 03531 03532 03533 if (handle_mgmt(msg)) 03534 return 0 ; 03535 03536 if (handle_l2(msg)) 03537 return 0 ; 03538 03539 /* Its important to handle l1 AFTER l2 */ 03540 if (handle_l1(msg)) 03541 return 0 ; 03542 03543 if (handle_frm_nt(msg)) { 03544 return 0; 03545 } 03546 03547 if (handle_frm(msg)) { 03548 return 0; 03549 } 03550 03551 if (handle_err(msg)) { 03552 return 0 ; 03553 } 03554 03555 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); 03556 free_msg(msg); 03557 03558 03559 return 0; 03560 }
| void manager_ph_control | ( | struct misdn_bchannel * | bc, | |
| int | c1, | |||
| int | c2 | |||
| ) |
Definition at line 4072 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::bc, cb_log, glob_mgr, misdn_lib::midev, and misdn_bchannel::port.
Referenced by 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().
04073 { 04074 unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)]; 04075 iframe_t *ctrl = (iframe_t *)buffer; /* preload data */ 04076 unsigned int *d = (unsigned int*)&ctrl->data.p; 04077 /*struct misdn_stack *stack=get_stack_by_bc(bc);*/ 04078 04079 cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2); 04080 04081 ctrl->prim = PH_CONTROL | REQUEST; 04082 ctrl->addr = bc->addr | FLG_MSG_DOWN; 04083 ctrl->dinfo = 0; 04084 ctrl->len = sizeof(unsigned int)*2; 04085 *d++ = c1; 04086 *d++ = c2; 04087 mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); 04088 }
| void manager_ph_control_block | ( | struct misdn_bchannel * | bc, | |
| int | c1, | |||
| void * | c2, | |||
| int | c2_len | |||
| ) |
Definition at line 4123 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().
04124 { 04125 unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len]; 04126 iframe_t *ctrl = (iframe_t *)buffer; 04127 unsigned int *d = (unsigned int *)&ctrl->data.p; 04128 /*struct misdn_stack *stack=get_stack_by_bc(bc);*/ 04129 04130 ctrl->prim = PH_CONTROL | REQUEST; 04131 ctrl->addr = bc->addr | FLG_MSG_DOWN; 04132 ctrl->dinfo = 0; 04133 ctrl->len = sizeof(unsigned int) + c2_len; 04134 *d++ = c1; 04135 memcpy(d, c2, c2_len); 04136 mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); 04137 }
| int misdn_cap_is_speech | ( | int | cap | ) |
Poor mans version
Definition at line 396 of file isdn_lib.c.
References INFO_CAPABILITY_DIGITAL_RESTRICTED, and INFO_CAPABILITY_DIGITAL_UNRESTRICTED.
Referenced by handle_bchan(), handle_event(), handle_event_nt(), manager_ec_disable(), manager_ec_enable(), misdn_lib_send_event(), and misdn_lib_tx2misdn_frm().
00398 { 00399 if ( (cap != INFO_CAPABILITY_DIGITAL_UNRESTRICTED) && 00400 (cap != INFO_CAPABILITY_DIGITAL_RESTRICTED) ) return 1; 00401 return 0; 00402 }
| int misdn_inband_avail | ( | struct misdn_bchannel * | bc | ) |
Definition at line 404 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 misdn_indication().
00405 { 00406 00407 /*if ! early_bconnect we have never inband available*/ 00408 if ( ! bc->early_bconnect ) return 0; 00409 00410 switch (bc->progress_indicator) { 00411 case INFO_PI_INBAND_AVAILABLE: 00412 case INFO_PI_CALL_NOT_E2E_ISDN: 00413 case INFO_PI_CALLED_NOT_ISDN: 00414 return 1; 00415 default: 00416 return 0; 00417 } 00418 return 0; 00419 }
| void misdn_join_conf | ( | struct misdn_bchannel * | bc, | |
| int | conf_id | |||
| ) |
Definition at line 4362 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::bc, bc_state_change(), BCHAN_BRIDGED, cb_log, len, manager_ph_control(), misdn_lib_tx2misdn_frm(), and misdn_bchannel::port.
Referenced by bc_state_change(), and misdn_lib_bridge().
04363 { 04364 bc_state_change(bc,BCHAN_BRIDGED); 04365 manager_ph_control(bc, CMX_RECEIVE_OFF, 0); 04366 manager_ph_control(bc, CMX_CONF_JOIN, conf_id); 04367 04368 cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id); 04369 04370 char data[16]; 04371 int len=15; 04372 04373 memset(data,0,15); 04374 04375 misdn_lib_tx2misdn_frm(bc, data, len); 04376 04377 }
| void misdn_lib_bridge | ( | struct misdn_bchannel * | bc1, | |
| struct misdn_bchannel * | bc2 | |||
| ) |
Definition at line 4389 of file isdn_lib.c.
References bc_next_state_change(), BCHAN_ACTIVATED, BCHAN_BRIDGED, cb_log, misdn_bchannel::conf_id, misdn_join_conf(), misdn_bchannel::pid, and misdn_bchannel::port.
Referenced by misdn_bridge().
04389 { 04390 int conf_id=bc1->pid +1; 04391 04392 cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port); 04393 04394 struct misdn_bchannel *bc_list[]={ 04395 bc1,bc2,NULL 04396 }; 04397 struct misdn_bchannel **bc; 04398 04399 for (bc=bc_list; *bc; bc++) { 04400 (*bc)->conf_id=conf_id; 04401 cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr); 04402 04403 switch((*bc)->bc_state) { 04404 case BCHAN_ACTIVATED: 04405 misdn_join_conf(*bc,conf_id); 04406 break; 04407 default: 04408 bc_next_state_change(*bc,BCHAN_BRIDGED); 04409 break; 04410 } 04411 } 04412 }
| void misdn_lib_destroy | ( | void | ) |
Definition at line 3935 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::b_num, misdn_stack::bc, 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().
03936 { 03937 struct misdn_stack *help; 03938 int i; 03939 03940 for ( help=glob_mgr->stack_list; help; help=help->next ) { 03941 for(i=0;i<=help->b_num; i++) { 03942 char buf[1024]; 03943 mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 03944 help->bc[i].addr = 0; 03945 } 03946 cb_log (1, help->port, "Destroying this port.\n"); 03947 stack_destroy(help); 03948 } 03949 03950 if (global_state == MISDN_INITIALIZED) { 03951 cb_log(4, 0, "Killing Handler Thread\n"); 03952 if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) { 03953 cb_log(4, 0, "Joining Handler Thread\n"); 03954 pthread_join(glob_mgr->event_handler_thread, NULL); 03955 } 03956 03957 cb_log(4, 0, "Killing Main Thread\n"); 03958 if ( pthread_cancel(glob_mgr->event_thread) == 0 ) { 03959 cb_log(4, 0, "Joining Main Thread\n"); 03960 pthread_join(glob_mgr->event_thread, NULL); 03961 } 03962 } 03963 03964 cb_log(1, 0, "Closing mISDN device\n"); 03965 te_lib_destroy(glob_mgr->midev); 03966 }
| void misdn_lib_echo | ( | struct misdn_bchannel * | bc, | |
| int | onoff | |||
| ) |
Definition at line 4434 of file isdn_lib.c.
References cb_log, manager_ph_control(), and misdn_bchannel::port.
04435 { 04436 cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF"); 04437 manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0); 04438 }
| struct misdn_bchannel* misdn_lib_get_free_bc | ( | int | port, | |
| int | channel, | |||
| int | inout, | |||
| int | dec | |||
| ) |
Definition at line 3073 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, misdn_bchannel::in_use, MAX_BCHANS, misdn_stack::next, misdn_stack::port, prepare_bc(), misdn_stack::pri, misdn_stack::ptp, and misdn_lib::stack_list.
Referenced by handle_cr(), handle_event_nt(), and misdn_request().
03074 { 03075 struct misdn_stack *stack; 03076 int i; 03077 03078 if (channel < 0 || channel > MAX_BCHANS) { 03079 cb_log(0,port,"Requested channel out of bounds (%d)\n",channel); 03080 return NULL; 03081 } 03082 03083 for (stack=glob_mgr->stack_list; stack; stack=stack->next) { 03084 03085 if (stack->port == port) { 03086 if (stack->blocked) { 03087 cb_log(0,port,"Port is blocked\n"); 03088 return NULL; 03089 } 03090 03091 if (channel > 0) { 03092 if (channel <= stack->b_num) { 03093 for (i = 0; i < stack->b_num; i++) { 03094 if (stack->bc[i].in_use && stack->bc[i].channel == channel) { 03095 cb_log(0,port,"Requested channel:%d on port:%d is already in use\n",channel, port); 03096 return NULL; 03097 } 03098 } 03099 } else { 03100 cb_log(0,port,"Requested channel:%d is out of bounds on port:%d\n",channel, port); 03101 return NULL; 03102 } 03103 } 03104 03105 int maxnum=inout&&!stack->pri&&!stack->ptp?stack->b_num+1:stack->b_num; 03106 03107 if (dec) { 03108 for (i = maxnum-1; i>=0; i--) { 03109 if (!stack->bc[i].in_use) { 03110 /* 3. channel on bri means CW*/ 03111 if (!stack->pri && i==stack->b_num) 03112 stack->bc[i].cw=1; 03113 03114 prepare_bc(&stack->bc[i], channel); 03115 stack->bc[i].dec=1; 03116 return &stack->bc[i]; 03117 } 03118 } 03119 } else { 03120 for (i = 0; i <maxnum; i++) { 03121 if (!stack->bc[i].in_use) { 03122 /* 3. channel on bri means CW*/ 03123 if (!stack->pri && i==stack->b_num) 03124 stack->bc[i].cw=1; 03125 03126 prepare_bc(&stack->bc[i], channel); 03127 return &stack->bc[i]; 03128 } 03129 } 03130 } 03131 03132 cb_log(1,port,"There is no free channel on port (%d)\n",port); 03133 return NULL; 03134 } 03135 } 03136 03137 cb_log(0,port,"Port is not configured (%d)\n",port); 03138 return NULL; 03139 }
| static int misdn_lib_get_l1_down | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 731 of file isdn_lib.c.
References misdn_stack::midev, and misdn_stack::upper_id.
Referenced by handle_err(), and misdn_lib_get_port_down().
00732 { 00733 /* Pull Up L1 */ 00734 iframe_t act; 00735 act.prim = PH_DEACTIVATE | REQUEST; 00736 act.addr = (stack->upper_id | FLG_MSG_DOWN) ; 00737 00738 00739 act.dinfo = 0; 00740 act.len = 0; 00741 00742 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00743 00744 00745 }
| static int misdn_lib_get_l1_up | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 774 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().
00775 { 00776 /* Pull Up L1 */ 00777 iframe_t act; 00778 act.prim = PH_ACTIVATE | REQUEST; 00779 act.addr = (stack->upper_id | FLG_MSG_DOWN) ; 00780 00781 00782 act.dinfo = 0; 00783 act.len = 0; 00784 00785 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00786 00787 }
| static int misdn_lib_get_l2_down | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 748 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().
00749 { 00750 00751 if (stack->ptp && (stack->nt) ) { 00752 msg_t *dmsg; 00753 /* L2 */ 00754 dmsg = create_l2msg(DL_RELEASE| REQUEST, 0, 0); 00755 00756 if (stack->nst.manager_l3(&stack->nst, dmsg)) 00757 free_msg(dmsg); 00758 00759 } else { 00760 iframe_t act; 00761 00762 act.prim = DL_RELEASE| REQUEST; 00763 act.addr = (stack->upper_id |FLG_MSG_DOWN) ; 00764 00765 act.dinfo = 0; 00766 act.len = 0; 00767 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00768 } 00769 00770 return 0; 00771 }
| int misdn_lib_get_l2_up | ( | struct misdn_stack * | stack | ) |
Definition at line 789 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().
00790 { 00791 00792 if (stack->ptp && (stack->nt) ) { 00793 msg_t *dmsg; 00794 /* L2 */ 00795 dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0); 00796 00797 if (stack->nst.manager_l3(&stack->nst, dmsg)) 00798 free_msg(dmsg); 00799 00800 } else { 00801 iframe_t act; 00802 00803 act.prim = DL_ESTABLISH | REQUEST; 00804 act.addr = (stack->upper_id |FLG_MSG_DOWN) ; 00805 00806 act.dinfo = 0; 00807 act.len = 0; 00808 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00809 } 00810 00811 return 0; 00812 }
| int misdn_lib_get_maxchans | ( | int | port | ) |
Definition at line 89 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_stack::pri.
Referenced by misdn_request().
00090 { 00091 struct misdn_stack *stack=get_misdn_stack(); 00092 for ( ; stack; stack=stack->next) { 00093 if (stack->port == port) { 00094 if (stack->pri) 00095 return 30; 00096 else 00097 return 2; 00098 } 00099 } 00100 return -1; 00101 }
| int misdn_lib_get_port_down | ( | int | port | ) |
Definition at line 1683 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 misdn_port_down().
01684 { /* Pull Down L1 */ 01685 struct misdn_stack *stack; 01686 for (stack=glob_mgr->stack_list; 01687 stack; 01688 stack=stack->next) { 01689 if (stack->port == port) { 01690 if (stack->l2link) 01691 misdn_lib_get_l2_down(stack); 01692 misdn_lib_get_l1_down(stack); 01693 return 0; 01694 } 01695 } 01696 return 0; 01697 }
| int misdn_lib_get_port_info | ( | int | port | ) |
Definition at line 3565 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.
03566 { 03567 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03568 iframe_t *frm; 03569 struct misdn_stack *stack=find_stack_by_port(port); 03570 if (!msg) { 03571 cb_log(0, port, "misgn_lib_get_port: alloc_msg failed!\n"); 03572 return -1; 03573 } 03574 frm=(iframe_t*)msg->data; 03575 if (!stack ) { 03576 cb_log(0, port, "There is no Stack for this port.\n"); 03577 return -1; 03578 } 03579 /* activate bchannel */ 03580 frm->prim = CC_STATUS_ENQUIRY | REQUEST; 03581 03582 frm->addr = stack->upper_id| FLG_MSG_DOWN; 03583 03584 frm->dinfo = 0; 03585 frm->len = 0; 03586 03587 msg_queue_tail(&glob_mgr->activatequeue, msg); 03588 sem_post(&glob_mgr->new_msg); 03589 03590 03591 return 0; 03592 }
| int misdn_lib_get_port_up | ( | int | port | ) |
Definition at line 1661 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 misdn_port_up().
01662 { /* Pull Up L1 */ 01663 struct misdn_stack *stack; 01664 01665 for (stack=glob_mgr->stack_list; 01666 stack; 01667 stack=stack->next) { 01668 01669 if (stack->port == port) { 01670 01671 if (!stack->l1link) 01672 misdn_lib_get_l1_up(stack); 01673 if (!stack->l2link) 01674 misdn_lib_get_l2_up(stack); 01675 01676 return 0; 01677 } 01678 } 01679 return 0; 01680 }
| static int misdn_lib_get_short_status | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 829 of file isdn_lib.c.
References misdn_stack::midev, and misdn_stack::upper_id.
Referenced by misdn_lib_isdn_l1watcher().
00830 { 00831 iframe_t act; 00832 00833 00834 act.prim = MGR_SHORTSTATUS | REQUEST; 00835 00836 act.addr = (stack->upper_id | MSG_BROADCAST) ; 00837 00838 act.dinfo = SSTATUS_BROADCAST_BIT | SSTATUS_ALL; 00839 00840 act.len = 0; 00841 return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); 00842 }
| int misdn_lib_init | ( | char * | portlist, | |
| struct misdn_lib_iface * | iface, | |||
| void * | user_data | |||
| ) |
Definition at line 3827 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, cb_log, misdn_lib_iface::cb_log, 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().
03828 { 03829 struct misdn_lib *mgr=calloc(1, sizeof(struct misdn_lib)); 03830 char *tok, *tokb; 03831 char plist[1024]; 03832 int midev; 03833 int port_count=0; 03834 03835 cb_log = iface->cb_log; 03836 cb_event = iface->cb_event; 03837 cb_jb_empty = iface->cb_jb_empty; 03838 03839 glob_mgr = mgr; 03840 03841 msg_init(); 03842 03843 misdn_lib_nt_debug_init(0,NULL); 03844 03845 if (!portlist || (*portlist == 0) ) return 1; 03846 03847 init_flip_bits(); 03848 03849 { 03850 strncpy(plist,portlist, 1024); 03851 plist[1023] = 0; 03852 } 03853 03854 memcpy(tone_425_flip,tone_425,TONE_425_SIZE); 03855 flip_buf_bits(tone_425_flip,TONE_425_SIZE); 03856 03857 memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE); 03858 flip_buf_bits(tone_silence_flip,TONE_SILENCE_SIZE); 03859 03860 midev=te_lib_init(); 03861 mgr->midev=midev; 03862 03863 port_count=mISDN_get_stack_count(midev); 03864 03865 msg_queue_init(&mgr->activatequeue); 03866 03867 if (sem_init(&mgr->new_msg, 1, 0)<0) 03868 sem_init(&mgr->new_msg, 0, 0); 03869 03870 for (tok=strtok_r(plist," ,",&tokb ); 03871 tok; 03872 tok=strtok_r(NULL," ,",&tokb)) { 03873 int port = atoi(tok); 03874 struct misdn_stack *stack; 03875 static int first=1; 03876 int ptp=0; 03877 03878 if (strstr(tok, "ptp")) 03879 ptp=1; 03880 03881 if (port > port_count) { 03882 cb_log(0, port, "Couldn't Initialize this port since we have only %d ports\n", port_count); 03883 exit(1); 03884 } 03885 stack=stack_init(midev, port, ptp); 03886 03887 if (!stack) { 03888 perror("init_stack"); 03889 exit(1); 03890 } 03891 03892 { 03893 int i; 03894 for(i=0;i<=stack->b_num; i++) { 03895 int r; 03896 if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) { 03897 cb_log(0, port, "Got Err @ init_bc :%d\n",r); 03898 exit(1); 03899 } 03900 } 03901 } 03902 03903 if (stack && first) { 03904 mgr->stack_list=stack; 03905 first=0; 03906 continue; 03907 } 03908 03909 if (stack) { 03910 struct misdn_stack * help; 03911 for ( help=mgr->stack_list; help; help=help->next ) 03912 if (help->next == NULL) break; 03913 help->next=stack; 03914 } 03915 03916 } 03917 03918 if (sem_init(&handler_started, 1, 0)<0) 03919 sem_init(&handler_started, 0, 0); 03920 03921 cb_log(8, 0, "Starting Event Handler\n"); 03922 pthread_create( &mgr->event_handler_thread, NULL,(void*)manager_event_handler, mgr); 03923 03924 sem_wait(&handler_started) ; 03925 cb_log(8, 0, "Starting Event Catcher\n"); 03926 pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr); 03927 03928 cb_log(8, 0, "Event Catcher started\n"); 03929 03930 global_state= MISDN_INITIALIZED; 03931 03932 return (mgr == NULL); 03933 }
| int misdn_lib_is_port_blocked | ( | int | port | ) |
Definition at line 69 of file isdn_lib.c.
References misdn_stack::blocked, get_misdn_stack(), misdn_stack::next, and misdn_stack::port.
00070 { 00071 struct misdn_stack *stack=get_misdn_stack(); 00072 for ( ; stack; stack=stack->next) { 00073 if (stack->port == port) { 00074 return stack->blocked; 00075 } 00076 } 00077 return -1; 00078 }
| int misdn_lib_is_ptp | ( | int | port | ) |
Definition at line 80 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_stack::ptp.
Referenced by do_immediate_setup().
00081 { 00082 struct misdn_stack *stack=get_misdn_stack(); 00083 for ( ; stack; stack=stack->next) { 00084 if (stack->port == port) return stack->ptp; 00085 } 00086 return -1; 00087 }
| static void misdn_lib_isdn_event_catcher | ( | void * | arg | ) | [static] |
Definition at line 2936 of file isdn_lib.c.
References cb_log, fetch_msg(), manager_isdn_handler(), and misdn_lib::midev.
02937 { 02938 struct misdn_lib *mgr = arg; 02939 int zero_frm=0 , fff_frm=0 ; 02940 int midev= mgr->midev; 02941 int port=0; 02942 02943 while (1) { 02944 msg_t *msg = fetch_msg(midev); 02945 iframe_t *frm; 02946 02947 02948 if (!msg) continue; 02949 02950 frm = (iframe_t*) msg->data; 02951 02952 /** When we make a call from NT2Ast we get this frames **/ 02953 if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) { 02954 zero_frm++; 02955 free_msg(msg); 02956 continue; 02957 } else { 02958 if (zero_frm) { 02959 cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm); 02960 zero_frm = 0 ; 02961 } 02962 } 02963 02964 /** I get this sometimes after setup_bc **/ 02965 if (frm->len == 0 && frm->dinfo == 0 && frm->prim == 0xffffffff ) { 02966 fff_frm++; 02967 free_msg(msg); 02968 continue; 02969 } else { 02970 if (fff_frm) { 02971 cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm); 02972 fff_frm = 0 ; 02973 } 02974 } 02975 02976 manager_isdn_handler(frm, msg); 02977 } 02978 02979 }
| void misdn_lib_isdn_l1watcher | ( | int | port | ) |
Definition at line 2918 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().
02919 { 02920 struct misdn_stack *stack; 02921 02922 for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next) 02923 ; 02924 02925 if (stack) { 02926 cb_log(4, port, "Checking L1 State\n"); 02927 if (!stack->l1link) { 02928 cb_log(4, port, "L1 State Down, trying to get it up again\n"); 02929 misdn_lib_get_short_status(stack); 02930 misdn_lib_get_l1_up(stack); 02931 misdn_lib_get_l2_up(stack); 02932 } 02933 } 02934 }
| void misdn_lib_log_ies | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3160 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().
03161 { 03162 if (!bc) return; 03163 03164 struct misdn_stack *stack=get_stack_by_bc(bc); 03165 03166 if (!stack) return; 03167 03168 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); 03169 03170 cb_log(2, stack->port, 03171 " --> info_dad:%s onumplan:%c dnumplan:%c rnumplan:%c cpnnumplan:%c\n", 03172 bc->info_dad, 03173 bc->onumplan>=0?'0'+bc->onumplan:' ', 03174 bc->dnumplan>=0?'0'+bc->dnumplan:' ', 03175 bc->rnumplan>=0?'0'+bc->rnumplan:' ', 03176 bc->cpnnumplan>=0?'0'+bc->cpnnumplan:' ' 03177 ); 03178 03179 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); 03180 cb_log(4, stack->port, " --> screen:%d --> pres:%d\n", 03181 bc->screen, bc->pres); 03182 03183 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); 03184 03185 cb_log(4, stack->port, " --> facility:%s out_facility:%s\n",fac2str(bc->fac_in.Function),fac2str(bc->fac_out.Function)); 03186 03187 cb_log(5, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1); 03188 03189 cb_log(5, stack->port, " --> bc:%x h:%d sh:%d\n", bc, bc->holded, bc->stack_holder); 03190 }
| int misdn_lib_maxports_get | ( | void | ) |
Definition at line 3791 of file isdn_lib.c.
Referenced by load_module().
03791 { /** BE AWARE WE HAVE NO CB_LOG HERE! **/ 03792 03793 int i = mISDN_open(); 03794 int max=0; 03795 03796 if (i<0) 03797 return -1; 03798 03799 max = mISDN_get_stack_count(i); 03800 03801 mISDN_close(i); 03802 03803 return max; 03804 }
| void misdn_lib_nt_debug_init | ( | int | flags, | |
| char * | file | |||
| ) |
Definition at line 3807 of file isdn_lib.c.
References f.
Referenced by load_module(), and misdn_lib_init().
03808 { 03809 int static init=0; 03810 char *f; 03811 03812 if (!flags) 03813 f=NULL; 03814 else 03815 f=file; 03816 03817 if (!init) { 03818 debug_init( flags , f, f, f); 03819 init=1; 03820 } else { 03821 debug_close(); 03822 debug_init( flags , f, f, f); 03823 } 03824 }
| int misdn_lib_pid_restart | ( | int | pid | ) |
Definition at line 3620 of file isdn_lib.c.
References manager_clean_bc(), and manager_find_bc_by_pid().
Referenced by misdn_restart_pid().
03621 { 03622 struct misdn_bchannel *bc=manager_find_bc_by_pid(pid); 03623 03624 if (bc) { 03625 manager_clean_bc(bc); 03626 } 03627 return 0; 03628 }
| int misdn_lib_port_block | ( | int | port | ) |
Definition at line 43 of file isdn_lib.c.
References misdn_stack::blocked, get_misdn_stack(), misdn_stack::next, and misdn_stack::port.
Referenced by cb_events(), and misdn_port_block().
00044 { 00045 struct misdn_stack *stack=get_misdn_stack(); 00046 for ( ; stack; stack=stack->next) { 00047 if (stack->port == port) { 00048 stack->blocked=1; 00049 return 0; 00050 } 00051 } 00052 return -1; 00053 00054 }
| int misdn_lib_port_is_pri | ( | int | port | ) |
Definition at line 30 of file isdn_lib.c.
References get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_stack::pri.
Referenced by misdn_new(), and update_name().
00031 { 00032 struct misdn_stack *stack=get_misdn_stack(); 00033 for ( ; stack; stack=stack->next) { 00034 if (stack->port == port) { 00035 return stack->pri; 00036 } 00037 } 00038 00039 return -1; 00040 }
| int misdn_lib_port_restart | ( | int | port | ) |
Definition at line 3655 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 misdn_restart_port().
03656 { 03657 struct misdn_stack *stack=find_stack_by_port(port); 03658 03659 cb_log(0, port, "Restarting this port.\n"); 03660 if (stack) { 03661 cb_log(0, port, "Stack:%p\n",stack); 03662 03663 clear_l3(stack); 03664 { 03665 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03666 iframe_t *frm; 03667 03668 if (!msg) { 03669 cb_log(0, port, "port_restart: alloc_msg failed\n"); 03670 return -1; 03671 } 03672 03673 frm=(iframe_t*)msg->data; 03674 /* we must activate if we are deactivated */ 03675 /* activate bchannel */ 03676 frm->prim = DL_RELEASE | REQUEST; 03677 frm->addr = stack->upper_id | FLG_MSG_DOWN; 03678 03679 frm->dinfo = 0; 03680 frm->len = 0; 03681 msg_queue_tail(&glob_mgr->activatequeue, msg); 03682 sem_post(&glob_mgr->new_msg); 03683 } 03684 03685 if (stack->nt) 03686 misdn_lib_reinit_nt_stack(stack->port); 03687 03688 } 03689 03690 return 0; 03691 }
| int misdn_lib_port_unblock | ( | int | port | ) |
Definition at line 56 of file isdn_lib.c.
References misdn_stack::blocked, get_misdn_stack(), misdn_stack::next, and misdn_stack::port.
Referenced by misdn_port_unblock().
00057 { 00058 struct misdn_stack *stack=get_misdn_stack(); 00059 for ( ; stack; stack=stack->next) { 00060 if (stack->port == port) { 00061 stack->blocked=0; 00062 return 0; 00063 } 00064 } 00065 return -1; 00066 00067 }
| int misdn_lib_port_up | ( | int | port, | |
| int | check | |||
| ) |
Definition at line 1699 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_request().
01700 { 01701 struct misdn_stack *stack; 01702 01703 01704 for (stack=glob_mgr->stack_list; 01705 stack; 01706 stack=stack->next) { 01707 01708 if (stack->port == port) { 01709 01710 if (stack->blocked) { 01711 cb_log(0,port, "Port Blocked:%d L2:%d L1:%d\n", stack->blocked, stack->l2link, stack->l1link); 01712 return -1; 01713 } 01714 01715 if (stack->ptp ) { 01716 01717 if (stack->l1link && stack->l2link) { 01718 return 1; 01719 } else { 01720 cb_log(0,port, "Port Down L2:%d L1:%d\n", 01721 stack->l2link, stack->l1link); 01722 return 0; 01723 } 01724 } else { 01725 if ( !check || stack->l1link ) 01726 return 1; 01727 else { 01728 cb_log(0,port, "Port down PMP\n"); 01729 return 0; 01730 } 01731 } 01732 } 01733 } 01734 01735 return -1; 01736 }
| void misdn_lib_reinit_nt_stack | ( | int | port | ) |
Definition at line 4442 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().
04443 { 04444 struct misdn_stack *stack=find_stack_by_port(port); 04445 04446 if (stack) { 04447 stack->l2link=0; 04448 stack->blocked=0; 04449 04450 cleanup_Isdnl3(&stack->nst); 04451 cleanup_Isdnl2(&stack->nst); 04452 04453 04454 memset(&stack->nst, 0, sizeof(net_stack_t)); 04455 memset(&stack->mgr, 0, sizeof(manager_t)); 04456 04457 stack->mgr.nst = &stack->nst; 04458 stack->nst.manager = &stack->mgr; 04459 04460 stack->nst.l3_manager = handle_event_nt; 04461 stack->nst.device = glob_mgr->midev; 04462 stack->nst.cardnr = port; 04463 stack->nst.d_stid = stack->d_stid; 04464 04465 stack->nst.feature = FEATURE_NET_HOLD; 04466 if (stack->ptp) 04467 stack->nst.feature |= FEATURE_NET_PTP; 04468 if (stack->pri) 04469 stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID; 04470 04471 stack->nst.l1_id = stack->lower_id; 04472 stack->nst.l2_id = stack->upper_id; 04473 04474 msg_queue_init(&stack->nst.down_queue); 04475 04476 Isdnl2Init(&stack->nst); 04477 Isdnl3Init(&stack->nst); 04478 04479 if (!stack->ptp) 04480 misdn_lib_get_l1_up(stack); 04481 misdn_lib_get_l2_up(stack); 04482 } 04483 }
| void misdn_lib_release | ( | struct misdn_bchannel * | bc | ) |
Definition at line 1642 of file isdn_lib.c.
References misdn_stack::bc, cb_log, misdn_bchannel::channel, clean_up_bc(), empty_bc(), empty_chan_in_stack(), and get_stack_by_bc().
Referenced by misdn_hangup().
01643 { 01644 struct misdn_stack *stack=get_stack_by_bc(bc); 01645 01646 if (!stack) { 01647 cb_log(1,0,"misdn_release: No Stack found\n"); 01648 return; 01649 } 01650 01651 if (bc->channel>0) { 01652 empty_chan_in_stack(stack,bc->channel); 01653 } 01654 empty_bc(bc); 01655 clean_up_bc(bc); 01656 }
| int misdn_lib_send_event | ( | struct misdn_bchannel * | bc, | |
| enum event_e | event | |||
| ) |
Definition at line 3192 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, 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_split_conf(), 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, misdn_stack::ptp, misdn_bchannel::rxgain, set_chan_in_stack(), setup_bc(), stack_holder_add(), misdn_bchannel::txgain, and misdn_stack::upper_id.
Referenced by cb_events(), do_immediate_setup(), 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_cd(), misdn_send_display(), and misdn_send_text().
03193 { 03194 msg_t *msg; 03195 int err = -1 ; 03196 int ret=0; 03197 03198 if (!bc) goto ERR; 03199 03200 struct misdn_stack *stack=get_stack_by_bc(bc); 03201 03202 if (!stack) { 03203 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); 03204 return -1; 03205 } 03206 03207 cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->uperid:%x\n",stack->nt, stack->upper_id); 03208 03209 if ( stack->nt && !stack->l1link) { 03210 /** Queue Event **/ 03211 bc->evq=event; 03212 cb_log(1, stack->port, "Queueing Event %s because L1 is down (btw. Activating L1)\n", isdn_get_info(msgs_g, event, 0)); 03213 misdn_lib_get_l1_up(stack); 03214 return 0; 03215 } 03216 03217 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); 03218 cb_log(4, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state)); 03219 misdn_lib_log_ies(bc); 03220 03221 switch (event) { 03222 case EVENT_SETUP: 03223 if (create_process(glob_mgr->midev, bc)<0) { 03224 cb_log(0, stack->port, " No free channel at the moment @ send_event\n"); 03225 03226 err=-ENOCHAN; 03227 goto ERR; 03228 } 03229 #if 0 03230 if (stack->nt) { 03231 ret=setup_bc(bc); 03232 if (ret == -EINVAL) { 03233 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03234 } 03235 } 03236 #endif 03237 break; 03238 03239 case EVENT_PROGRESS: 03240 case EVENT_ALERTING: 03241 case EVENT_PROCEEDING: 03242 case EVENT_SETUP_ACKNOWLEDGE: 03243 if (!bc->nt && !stack->ptp) break; 03244 03245 case EVENT_CONNECT: 03246 case EVENT_RETRIEVE_ACKNOWLEDGE: 03247 03248 if (stack->nt) { 03249 if (bc->channel <=0 ) { /* else we have the channel already */ 03250 if (!find_free_chan_in_stack(stack, bc, 0,0)) { 03251 cb_log(0, stack->port, " No free channel at the moment\n"); 03252 /*FIXME: add disconnect*/ 03253 err=-ENOCHAN; 03254 goto ERR; 03255 } 03256 03257 if (set_chan_in_stack(stack ,bc->channel)<0) { 03258 /*FIXME: add disconnect*/ 03259 err=-ENOCHAN; 03260 goto ERR; 03261 } 03262 } 03263 /* Its that i generate channels */ 03264 } 03265 03266 ret=setup_bc(bc); 03267 if (ret == -EINVAL) { 03268 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03269 } 03270 03271 if (misdn_cap_is_speech(bc->capability)) { 03272 if ((event==EVENT_CONNECT)||(event==EVENT_RETRIEVE_ACKNOWLEDGE)) { 03273 if ( *bc->crypt_key ) { 03274 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); 03275 03276 manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); 03277 } 03278 03279 if (!bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0); 03280 manager_ec_enable(bc); 03281 03282 if (bc->txgain != 0) { 03283 cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); 03284 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 03285 } 03286 03287 if ( bc->rxgain != 0 ) { 03288 cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); 03289 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 03290 } 03291 } 03292 } 03293 break; 03294 03295 case EVENT_HOLD_ACKNOWLEDGE: 03296 { 03297 struct misdn_bchannel *holded_bc=malloc(sizeof(struct misdn_bchannel)); 03298 if (!holded_bc) { 03299 cb_log(0,bc->port, "Could not allocate holded_bc!!!\n"); 03300 return -1; 03301 } 03302 03303 /*backup the bc*/ 03304 memcpy(holded_bc,bc,sizeof(struct misdn_bchannel)); 03305 holded_bc->holded=1; 03306 bc_state_change(holded_bc,BCHAN_CLEANED); 03307 03308 stack_holder_add(stack,holded_bc); 03309 03310 /*kill the bridge and clean the bchannel*/ 03311 if (stack->nt) { 03312 if (bc->bc_state == BCHAN_BRIDGED) { 03313 misdn_split_conf(bc,bc->conf_id); 03314 struct misdn_bchannel *bc2=find_bc_by_confid(bc->conf_id); 03315 if (!bc2) 03316 cb_log(0,bc->port,"We have no second bc in bridge???\n"); 03317 else 03318 misdn_split_conf(bc2,bc->conf_id); 03319 } 03320 03321 if (bc->channel>0) 03322 empty_chan_in_stack(stack,bc->channel); 03323 empty_bc(bc); 03324 clean_up_bc(bc); 03325 } 03326 03327 } 03328 break; 03329 03330 /* finishing the channel eh ? */ 03331 case EVENT_DISCONNECT: 03332 if (!bc->need_disconnect) { 03333 cb_log(0,bc->port," --> we have already send Disconnect\n"); 03334 return -1; 03335 } 03336 03337 bc->need_disconnect=0; 03338 break; 03339 case EVENT_RELEASE: 03340 if (!bc->need_release) { 03341 cb_log(0,bc->port," --> we have already send Release\n"); 03342 return -1; 03343 } 03344 bc->need_disconnect=0; 03345 bc->need_release=0; 03346 break; 03347 case EVENT_RELEASE_COMPLETE: 03348 if (!bc->need_release_complete) { 03349 cb_log(0,bc->port," --> we have already send Release_complete\n"); 03350 return -1; 03351 } 03352 bc->need_disconnect=0; 03353 bc->need_release=0; 03354 bc->need_release_complete=0; 03355 03356 if (!stack->nt) { 03357 /*create clenaup in TE*/ 03358 if (bc->channel>0) 03359 empty_chan_in_stack(stack,bc->channel); 03360 int tmpcause=bc->cause; 03361 int tmp_out_cause=bc->out_cause; 03362 empty_bc(bc); 03363 bc->cause=tmpcause; 03364 bc->out_cause=tmp_out_cause; 03365 clean_up_bc(bc); 03366 } 03367 break; 03368 03369 case EVENT_CONNECT_ACKNOWLEDGE: 03370 03371 if ( bc->nt || misdn_cap_is_speech(bc->capability)) { 03372 int ret=setup_bc(bc); 03373 if (ret == -EINVAL){ 03374 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03375 03376 } 03377 } 03378 03379 03380 if (misdn_cap_is_speech(bc->capability)) { 03381 if ( !bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0); 03382 manager_ec_enable(bc); 03383 03384 if ( bc->txgain != 0 ) { 03385 cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); 03386 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 03387 } 03388 if ( bc->rxgain != 0 ) { 03389 cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); 03390 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 03391 } 03392 } 03393 break; 03394 03395 default: 03396 break; 03397 } 03398 03399 /* Later we should think about sending bchannel data directly to misdn. */ 03400 msg = isdn_msg_build_event(msgs_g, bc, event, stack->nt); 03401 msg_queue_tail(&stack->downqueue, msg); 03402 sem_post(&glob_mgr->new_msg); 03403 03404 return 0; 03405 03406 ERR: 03407 return -1; 03408 }
| int misdn_lib_send_restart | ( | int | port | ) |
Definition at line 3631 of file isdn_lib.c.
References cb_log, EVENT_RESTART, find_stack_by_port(), misdn_lib_send_event(), misdn_stack::nt, misdn_stack::port, and misdn_stack::pri.
Referenced by misdn_send_restart().
03632 { 03633 struct misdn_stack *stack=find_stack_by_port(port); 03634 cb_log(0, port, "Sending Restarts on this port.\n"); 03635 03636 struct misdn_bchannel dummybc; 03637 memset (&dummybc,0,sizeof(dummybc)); 03638 dummybc.port=stack->port; 03639 dummybc.l3_id=MISDN_ID_GLOBAL; 03640 dummybc.nt=stack->nt; 03641 03642 int max=stack->pri?30:2; 03643 int i; 03644 for (i=1;i<=max;i++) { 03645 dummybc.channel=i; 03646 cb_log(0, port, "Restarting channel %d\n",i); 03647 misdn_lib_send_event(&dummybc, EVENT_RESTART); 03648 /*do we need to wait before we get an EVENT_RESTART_ACK ?*/ 03649 } 03650 03651 return 0; 03652 }
| void misdn_lib_send_tone | ( | struct misdn_bchannel * | bc, | |
| enum tone_e | tone | |||
| ) |
Definition at line 4252 of file isdn_lib.c.
References misdn_bchannel::addr, glob_mgr, manager_ph_control(), misdn_lib::midev, TONE_ALERTING, TONE_DIAL, TONE_HANGUP, and TONE_NONE.
Referenced by hanguptone_indicate().
04253 { 04254 04255 switch(tone) { 04256 case TONE_DIAL: 04257 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE); 04258 break; 04259 04260 case TONE_ALERTING: 04261 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_RINGING); 04262 break; 04263 04264 case TONE_HANGUP: 04265 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_HANGUP); 04266 break; 04267 04268 case TONE_NONE: 04269 default: 04270 manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP); 04271 } 04272 04273 char buf[mISDN_HEADER_LEN+128]; 04274 iframe_t *frm=(iframe_t*)buf; 04275 memset(buf,0,mISDN_HEADER_LEN+128); 04276 04277 frm->prim=DL_DATA|REQUEST; 04278 frm->addr=bc->addr|FLG_MSG_DOWN; 04279 frm->dinfo=0; 04280 frm->len=128; 04281 04282 mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); 04283 }
| void misdn_lib_setup_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 921 of file isdn_lib.c.
References misdn_stack::bc, clean_up_bc(), and setup_bc().
Referenced by misdn_set_opt_exec().
00922 { 00923 clean_up_bc(bc); 00924 setup_bc(bc); 00925 }
| void misdn_lib_split_bridge | ( | struct misdn_bchannel * | bc1, | |
| struct misdn_bchannel * | bc2 | |||
| ) |
Definition at line 4414 of file isdn_lib.c.
References bc_state2str(), BCHAN_BRIDGED, cb_log, misdn_bchannel::conf_id, and misdn_split_conf().
Referenced by misdn_bridge().
04415 { 04416 04417 struct misdn_bchannel *bc_list[]={ 04418 bc1,bc2,NULL 04419 }; 04420 struct misdn_bchannel **bc; 04421 04422 for (bc=bc_list; *bc; bc++) { 04423 if ( (*bc)->bc_state == BCHAN_BRIDGED){ 04424 misdn_split_conf( *bc, (*bc)->conf_id); 04425 } else { 04426 cb_log( 2, (*bc)->port, "BC not bridged (state:%s) so not splitting it\n",bc_state2str((*bc)->bc_state)); 04427 } 04428 } 04429 04430 }
| void misdn_lib_tone_generator_start | ( | struct misdn_bchannel * | bc | ) |
Definition at line 2167 of file isdn_lib.c.
References misdn_bchannel::generate_tone.
Referenced by dialtone_indicate().
02168 { 02169 bc->generate_tone=1; 02170 }
| void misdn_lib_tone_generator_stop | ( | struct misdn_bchannel * | bc | ) |
Definition at line 2172 of file isdn_lib.c.
References misdn_bchannel::generate_tone.
Referenced by start_bc_tones(), and stop_indicate().
02173 { 02174 bc->generate_tone=0; 02175 }
| void misdn_lib_transfer | ( | struct misdn_bchannel * | holded_bc | ) |
Definition at line 3025 of file isdn_lib.c.
References misdn_bchannel::holded.
03026 { 03027 holded_bc->holded=0; 03028 }
| int misdn_lib_tx2misdn_frm | ( | struct misdn_bchannel * | bc, | |
| void * | data, | |||
| int | len | |||
| ) |
Definition at line 4033 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), BCHAN_ACTIVATED, BCHAN_BRIDGED, 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().
04034 { 04035 struct misdn_stack *stack=get_stack_by_bc(bc); 04036 04037 switch (bc->bc_state) { 04038 case BCHAN_ACTIVATED: 04039 case BCHAN_BRIDGED: 04040 break; 04041 default: 04042 cb_log(3, bc->port, "BC not yet activated (state:%s)\n",bc_state2str(bc->bc_state)); 04043 return -1; 04044 } 04045 04046 char buf[4096 + mISDN_HEADER_LEN]; 04047 iframe_t *frm= (iframe_t*)buf; 04048 int r; 04049 04050 frm->prim = DL_DATA|REQUEST; 04051 frm->dinfo = 0; 04052 frm->addr = bc->addr | FLG_MSG_DOWN ; 04053 04054 frm->len = len; 04055 memcpy(&buf[mISDN_HEADER_LEN], data,len); 04056 04057 if ( misdn_cap_is_speech(bc->capability) ) 04058 flip_buf_bits( &buf[mISDN_HEADER_LEN], len); 04059 else 04060 cb_log(6, stack->port, "Writing %d data bytes\n",len); 04061 04062 cb_log(9, stack->port, "Writing %d bytes 2 mISDN\n",len); 04063 r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT); 04064 return 0; 04065 }
| void misdn_split_conf | ( | struct misdn_bchannel * | bc, | |
| int | conf_id | |||
| ) |
Definition at line 4380 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().
04381 { 04382 bc_state_change(bc,BCHAN_ACTIVATED); 04383 manager_ph_control(bc, CMX_RECEIVE_ON, 0); 04384 manager_ph_control(bc, CMX_CONF_SPLIT, conf_id); 04385 04386 cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id); 04387 }
| void misdn_tx_jitter | ( | struct misdn_bchannel * | bc, | |
| int | len | |||
| ) |
Definition at line 2221 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::bframe, misdn_bchannel::bframe_len, cb_jb_empty, cb_log, misdn_bchannel::channel, flip_buf_bits(), glob_mgr, misdn_lib::midev, misdn_bchannel::port, and tone_silence_flip.
Referenced by do_tone(), and handle_bchan().
02222 { 02223 char buf[4096 + mISDN_HEADER_LEN]; 02224 char *data=&buf[mISDN_HEADER_LEN]; 02225 iframe_t *txfrm= (iframe_t*)buf; 02226 int jlen, r; 02227 02228 jlen=cb_jb_empty(bc,data,len); 02229 02230 if (jlen) { 02231 #ifdef MISDN_SAVE_DATA 02232 misdn_save_data((bc->port*100+bc->channel), data, jlen, bc->bframe, bc->bframe_len); 02233 #endif 02234 flip_buf_bits( data, jlen); 02235 02236 if (jlen < len) { 02237 cb_log(7,bc->port,"Jitterbuffer Underrun.\n"); 02238 } 02239 02240 txfrm->prim = DL_DATA|REQUEST; 02241 02242 txfrm->dinfo = 0; 02243 02244 txfrm->addr = bc->addr|FLG_MSG_DOWN; /* | IF_DOWN; */ 02245 02246 txfrm->len =jlen; 02247 cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len); 02248 02249 r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); 02250 } else { 02251 #define MISDN_GEN_SILENCE 02252 #ifdef MISDN_GEN_SILENCE 02253 int cnt=len/TONE_SILENCE_SIZE; 02254 int rest=len%TONE_SILENCE_SIZE; 02255 int i; 02256 02257 for (i=0; i<cnt; i++) { 02258 memcpy(data, tone_silence_flip, TONE_SILENCE_SIZE ); 02259 data +=TONE_SILENCE_SIZE; 02260 } 02261 02262 if (rest) { 02263 memcpy(data, tone_silence_flip, rest); 02264 } 02265 02266 txfrm->prim = DL_DATA|REQUEST; 02267 02268 txfrm->dinfo = 0; 02269 02270 txfrm->addr = bc->addr|FLG_MSG_DOWN; /* | IF_DOWN; */ 02271 02272 txfrm->len =len; 02273 cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len); 02274 02275 r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); 02276 #endif 02277 02278 } 02279 }
| static void prepare_bc | ( | struct misdn_bchannel * | bc, | |
| int | channel | |||
| ) | [static] |
Definition at line 3053 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::b_stid, misdn_stack::bc, 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().
03054 { 03055 bc->channel = channel; 03056 bc->channel_preselected = channel?1:0; 03057 bc->in_use = 1; 03058 bc->need_disconnect=1; 03059 bc->need_release=1; 03060 bc->need_release_complete=1; 03061 bc->cause=16; 03062 03063 if (++mypid>5000) mypid=1; 03064 bc->pid=mypid; 03065 03066 #if 0 03067 bc->addr=0; 03068 bc->b_stid=0; 03069 bc->layer_id=0; 03070 #endif 03071 }
| int queue_cleanup_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3595 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.
03596 { 03597 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03598 iframe_t *frm; 03599 if (!msg) { 03600 cb_log(0, bc->port, "misgn_lib_get_port: alloc_msg failed!\n"); 03601 return -1; 03602 } 03603 frm=(iframe_t*)msg->data; 03604 03605 /* activate bchannel */ 03606 frm->prim = MGR_CLEARSTACK| REQUEST; 03607 03608 frm->addr = bc->l3_id; 03609 03610 frm->dinfo = bc->port; 03611 frm->len = 0; 03612 03613 msg_queue_tail(&glob_mgr->activatequeue, msg); 03614 sem_post(&glob_mgr->new_msg); 03615 03616 return 0; 03617 03618 }
| static int send_msg | ( | int | midev, | |
| struct misdn_bchannel * | bc, | |||
| msg_t * | dmsg | |||
| ) | [static] |
Definition at line 369 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().
00370 { 00371 iframe_t *frm; 00372 frm = (iframe_t *)dmsg->data; 00373 struct misdn_stack *stack=get_stack_by_bc(bc); 00374 00375 if (!stack) { 00376 cb_log(0,bc->port,"send_msg: IEK!! no stack\n "); 00377 return -1; 00378 } 00379 00380 frm->addr = (stack->upper_id | FLG_MSG_DOWN); 00381 frm->dinfo = bc->l3_id; 00382 frm->len = (dmsg->len) - mISDN_HEADER_LEN; 00383 00384 cb_log(4,stack->port,"Sending msg, prim:%x addr:%x dinfo:%x\n",frm->prim,frm->addr,frm->dinfo); 00385 00386 mISDN_write(midev, dmsg->data, dmsg->len, TIMEOUT_1SEC); 00387 free_msg(dmsg); 00388 00389 return 0; 00390 }
| static int set_chan_in_stack | ( | struct misdn_stack * | stack, | |
| int | channel | |||
| ) | [static] |
Definition at line 696 of file isdn_lib.c.
References cb_log, misdn_stack::channels, dump_chan_list(), MAX_BCHANS, and misdn_stack::port.
Referenced by create_process(), handle_event(), handle_event_nt(), and misdn_lib_send_event().
00697 { 00698 00699 cb_log(4,stack->port,"set_chan_in_stack: %d\n",channel); 00700 dump_chan_list(stack); 00701 if (channel >=1 && channel <= MAX_BCHANS) { 00702 if (!stack->channels[channel-1]) 00703 stack->channels[channel-1] = 1; 00704 else { 00705 cb_log(4,stack->port,"channel already in use:%d\n", channel ); 00706 return -1; 00707 } 00708 } else { 00709 cb_log(0,stack->port,"couldn't set channel %d in\n", channel ); 00710 return -1; 00711 } 00712 00713 return 0; 00714 }
| int setup_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 928 of file isdn_lib.c.
References misdn_bchannel::addr, misdn_bchannel::b_stid, misdn_stack::b_stids, misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), bc_state_change(), BCHAN_ACTIVATED, BCHAN_CLEANED, BCHAN_ERROR, cb_event, cb_log, misdn_bchannel::channel, EVENT_BCHAN_ERROR, get_stack_by_bc(), glob_mgr, misdn_bchannel::hdlc, ISDN_PID_L3_B_USER, ISDN_PID_L4_B_USER, misdn_bchannel::layer, misdn_bchannel::layer_id, manager_bchannel_activate(), misdn_stack::midev, misdn_bchannel::nodsp, misdn_stack::port, misdn_bchannel::port, and misdn_lib::user_data.
Referenced by handle_event(), handle_event_nt(), misdn_lib_send_event(), and misdn_lib_setup_bc().
00929 { 00930 unsigned char buff[1025]; 00931 00932 mISDN_pid_t pid; 00933 int ret; 00934 00935 00936 struct misdn_stack *stack=get_stack_by_bc(bc); 00937 00938 if (!stack) { 00939 cb_log(0, bc->port, "setup_bc: NO STACK FOUND!!\n"); 00940 return -1; 00941 } 00942 00943 int midev=stack->midev; 00944 int channel=bc->channel-1-(bc->channel>16); 00945 int b_stid=stack->b_stids[channel>=0?channel:0]; 00946 00947 00948 switch (bc->bc_state) { 00949 case BCHAN_CLEANED: 00950 break; 00951 default: 00952 cb_log(4, stack->port, "$$$ bc already upsetted stid :%x (state:%s)\n", b_stid, bc_state2str(bc->bc_state) ); 00953 return -1; 00954 } 00955 00956 cb_log(5, stack->port, "$$$ Setting up bc with stid :%x\n", b_stid); 00957 00958 if (b_stid <= 0) { 00959 cb_log(0, stack->port," -- Stid <=0 at the moment in channel:%d\n",channel); 00960 00961 bc_state_change(bc,BCHAN_ERROR); 00962 return 1; 00963 } 00964 00965 00966 bc->b_stid = b_stid; 00967 00968 { 00969 layer_info_t li; 00970 memset(&li, 0, sizeof(li)); 00971 00972 li.object_id = -1; 00973 li.extentions = 0; 00974 00975 li.st = bc->b_stid; /* given idx */ 00976 00977 00978 #define MISDN_DSP 00979 #ifndef MISDN_DSP 00980 bc->nodsp=1; 00981 #endif 00982 if ( bc->hdlc || bc->nodsp) { 00983 cb_log(4, stack->port,"setup_bc: without dsp\n"); 00984 { 00985 int l = sizeof(li.name); 00986 strncpy(li.name, "B L3", l); 00987 li.name[l-1] = 0; 00988 } 00989 li.pid.layermask = ISDN_LAYER((3)); 00990 li.pid.protocol[3] = ISDN_PID_L3_B_USER; 00991 00992 bc->layer=3; 00993 } else { 00994 cb_log(4, stack->port,"setup_bc: with dsp\n"); 00995 { 00996 int l = sizeof(li.name); 00997 strncpy(li.name, "B L4", l); 00998 li.name[l-1] = 0; 00999 } 01000 li.pid.layermask = ISDN_LAYER((4)); 01001 li.pid.protocol[4] = ISDN_PID_L4_B_USER 01002 ; 01003 bc->layer=4; 01004 01005 } 01006 01007 ret = mISDN_new_layer(midev, &li); 01008 if (ret ) { 01009 cb_log(0, stack->port,"New Layer Err: %d %s\n",ret,strerror(errno)); 01010 01011 bc_state_change(bc,BCHAN_ERROR); 01012 return(-EINVAL); 01013 } 01014 01015 bc->layer_id = li.id; 01016 } 01017 01018 memset(&pid, 0, sizeof(pid)); 01019 01020 01021 01022 cb_log(4, stack->port," --> Channel is %d\n", bc->channel); 01023 01024 if (bc->nodsp) { 01025 cb_log(2, stack->port," --> TRANSPARENT Mode (no DSP, no HDLC)\n"); 01026 pid.protocol[1] = ISDN_PID_L1_B_64TRANS; 01027 pid.protocol[2] = ISDN_PID_L2_B_TRANS; 01028 pid.protocol[3] = ISDN_PID_L3_B_USER; 01029 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)); 01030 01031 } else if ( bc->hdlc ) { 01032 cb_log(2, stack->port," --> HDLC Mode\n"); 01033 pid.protocol[1] = ISDN_PID_L1_B_64HDLC ; 01034 pid.protocol[2] = ISDN_PID_L2_B_TRANS ; 01035 pid.protocol[3] = ISDN_PID_L3_B_USER; 01036 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) ; 01037 } else { 01038 cb_log(2, stack->port," --> TRANSPARENT Mode\n"); 01039 pid.protocol[1] = ISDN_PID_L1_B_64TRANS; 01040 pid.protocol[2] = ISDN_PID_L2_B_TRANS; 01041 pid.protocol[3] = ISDN_PID_L3_B_DSP; 01042 pid.protocol[4] = ISDN_PID_L4_B_USER; 01043 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) | ISDN_LAYER((4)); 01044 01045 } 01046 01047 ret = mISDN_set_stack(midev, bc->b_stid, &pid); 01048 01049 if (ret){ 01050 cb_log(0, stack->port,"$$$ Set Stack Err: %d %s\n",ret,strerror(errno)); 01051 01052 mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01053 01054 bc_state_change(bc,BCHAN_ERROR); 01055 cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data); 01056 return(-EINVAL); 01057 } 01058 01059 ret = mISDN_get_setstack_ind(midev, bc->layer_id); 01060 01061 if (ret) { 01062 cb_log(0, stack->port,"$$$ Set StackIND Err: %d %s\n",ret,strerror(errno)); 01063 mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01064 01065 bc_state_change(bc,BCHAN_ERROR); 01066 cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data); 01067 return(-EINVAL); 01068 } 01069 01070 ret = mISDN_get_layerid(midev, bc->b_stid, bc->layer) ; 01071 01072 bc->addr = ret>0? ret : 0; 01073 01074 if (!bc->addr) { 01075 cb_log(0, stack->port,"$$$ Get Layerid Err: %d %s\n",ret,strerror(errno)); 01076 mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01077 01078 bc_state_change(bc,BCHAN_ERROR); 01079 cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data); 01080 return (-EINVAL); 01081 } 01082 01083 manager_bchannel_activate(bc); 01084 01085 bc_state_change(bc,BCHAN_ACTIVATED); 01086 01087 return 0; 01088 }
| void stack_destroy | ( | struct misdn_stack * | stack | ) |
Definition at line 1349 of file isdn_lib.c.
References misdn_stack::lower_id, misdn_stack::midev, misdn_stack::nst, misdn_stack::nt, and misdn_stack::upper_id.
Referenced by misdn_lib_destroy().
01350 { 01351 char buf[1024]; 01352 if (!stack) return; 01353 01354 if (stack->nt) { 01355 cleanup_Isdnl2(&stack->nst); 01356 cleanup_Isdnl3(&stack->nst); 01357 } 01358 01359 if (stack->lower_id) 01360 mISDN_write_frame(stack->midev, buf, stack->lower_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01361 01362 if (stack->upper_id) 01363 mISDN_write_frame(stack->midev, buf, stack->upper_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01364 }
| void stack_holder_add | ( | struct misdn_stack * | stack, | |
| struct misdn_bchannel * | holder | |||
| ) |
Definition at line 4154 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().
04155 { 04156 struct misdn_bchannel *help; 04157 cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id); 04158 04159 holder->stack_holder=1; 04160 04161 if (!stack ) return ; 04162 04163 holder->next=NULL; 04164 04165 if (!stack->holding) { 04166 stack->holding = holder; 04167 return; 04168 } 04169 04170 for (help=stack->holding; 04171 help; 04172 help=help->next) { 04173 if (!help->next) { 04174 help->next=holder; 04175 break; 04176 } 04177 } 04178 04179 }
| struct misdn_bchannel * stack_holder_find | ( | struct misdn_stack * | stack, | |
| unsigned long | l3id | |||
| ) |
Definition at line 4229 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().
04230 { 04231 struct misdn_bchannel *help; 04232 04233 cb_log(4,stack?stack->port:0, "*HOLDER: find %x\n",l3id); 04234 04235 if (!stack) return NULL; 04236 04237 for (help=stack->holding; 04238 help; 04239 help=help->next) { 04240 if (help->l3_id == l3id) { 04241 cb_log(4,stack->port, "*HOLDER: found bc\n"); 04242 return help; 04243 } 04244 } 04245 04246 cb_log(4,stack->port, "*HOLDER: find nothing\n"); 04247 return NULL; 04248 }
| struct misdn_bchannel * stack_holder_find_bychan | ( | struct misdn_stack * | stack, | |
| int | chan | |||
| ) |
Definition at line 4207 of file isdn_lib.c.
References cb_log, misdn_bchannel::channel, misdn_stack::holding, misdn_bchannel::next, and misdn_stack::port.
04208 { 04209 struct misdn_bchannel *help; 04210 04211 cb_log(4,stack?stack->port:0, "*HOLDER: find_bychan %c\n", chan); 04212 04213 if (!stack) return NULL; 04214 04215 for (help=stack->holding; 04216 help; 04217 help=help->next) { 04218 if (help->channel == chan) { 04219 cb_log(4,stack->port, "*HOLDER: found_bychan bc\n"); 04220 return help; 04221 } 04222 } 04223 04224 cb_log(4,stack->port, "*HOLDER: find_bychan nothing\n"); 04225 return NULL; 04226 04227 }
| void stack_holder_remove | ( | struct misdn_stack * | stack, | |
| struct misdn_bchannel * | holder | |||
| ) |
Definition at line 4181 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().
04182 { 04183 struct misdn_bchannel *h1; 04184 04185 if (!holder->stack_holder) return; 04186 04187 holder->stack_holder=0; 04188 04189 cb_log(4,stack->port, "*HOLDER: remove %x\n",holder->l3_id); 04190 if (!stack || ! stack->holding) return; 04191 04192 if (holder == stack->holding) { 04193 stack->holding = stack->holding->next; 04194 return; 04195 } 04196 04197 for (h1=stack->holding; 04198 h1; 04199 h1=h1->next) { 04200 if (h1->next == holder) { 04201 h1->next=h1->next->next; 04202 return ; 04203 } 04204 } 04205 }
| struct misdn_stack * stack_init | ( | int | midev, | |
| int | port, | |||
| int | ptp | |||
| ) |
Definition at line 1155 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::b_stids, 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().
01156 { 01157 int ret; 01158 unsigned char buff[1025]; 01159 iframe_t *frm = (iframe_t *)buff; 01160 stack_info_t *stinf; 01161 int i; 01162 layer_info_t li; 01163 01164 struct misdn_stack *stack = malloc(sizeof(struct misdn_stack)); 01165 if (!stack ) return NULL; 01166 01167 01168 cb_log(8, port, "Init. Stack.\n"); 01169 01170 memset(stack,0,sizeof(struct misdn_stack)); 01171 01172 for (i=0; i<MAX_BCHANS + 1; i++ ) stack->channels[i]=0; 01173 01174 stack->port=port; 01175 stack->midev=midev; 01176 stack->ptp=ptp; 01177 01178 stack->holding=NULL; 01179 stack->pri=0; 01180 01181 msg_queue_init(&stack->downqueue); 01182 msg_queue_init(&stack->upqueue); 01183 01184 /* query port's requirements */ 01185 ret = mISDN_get_stack_info(midev, 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(NULL); 01189 } 01190 01191 stinf = (stack_info_t *)&frm->data.p; 01192 01193 stack->d_stid = stinf->id; 01194 stack->b_num = stinf->childcnt; 01195 01196 for (i=0; i<=stinf->childcnt; i++) 01197 stack->b_stids[i] = stinf->child[i]; 01198 01199 switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK) { 01200 case ISDN_PID_L0_TE_S0: 01201 stack->nt=0; 01202 break; 01203 case ISDN_PID_L0_NT_S0: 01204 cb_log(8, port, "NT Stack\n"); 01205 01206 stack->nt=1; 01207 break; 01208 01209 case ISDN_PID_L0_TE_U: 01210 break; 01211 case ISDN_PID_L0_NT_U: 01212 break; 01213 case ISDN_PID_L0_TE_UP2: 01214 break; 01215 case ISDN_PID_L0_NT_UP2: 01216 break; 01217 case ISDN_PID_L0_TE_E1: 01218 cb_log(8, port, "TE S2M Stack\n"); 01219 stack->nt=0; 01220 stack->pri=1; 01221 break; 01222 case ISDN_PID_L0_NT_E1: 01223 cb_log(8, port, "TE S2M Stack\n"); 01224 stack->nt=1; 01225 stack->pri=1; 01226 01227 break; 01228 default: 01229 cb_log(0, port, "this is a unknown port type 0x%08x\n", stinf->pid.protocol[0]); 01230 01231 } 01232 01233 if (!stack->nt) { 01234 if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP ) { 01235 stack->ptp = 1; 01236 } else { 01237 stack->ptp = 0; 01238 } 01239 } 01240 01241 { 01242 int ret; 01243 int nt=stack->nt; 01244 01245 cb_log(8, port, "Init. Stack.\n"); 01246 01247 memset(&li, 0, sizeof(li)); 01248 { 01249 int l = sizeof(li.name); 01250 strncpy(li.name,nt?"net l2":"user l4", l); 01251 li.name[l-1] = 0; 01252 } 01253 li.object_id = -1; 01254 li.extentions = 0; 01255 li.pid.protocol[nt?2:4] = nt?ISDN_PID_L2_LAPD_NET:ISDN_PID_L4_CAPI20; 01256 li.pid.layermask = ISDN_LAYER((nt?2:4)); 01257 li.st = stack->d_stid; 01258 01259 01260 ret = mISDN_new_layer(midev, &li); 01261 if (ret) { 01262 cb_log(0, port, "%s: Cannot add layer %d to this port.\n", __FUNCTION__, nt?2:4); 01263 return(NULL); 01264 } 01265 01266 01267 stack->upper_id = li.id; 01268 ret = mISDN_register_layer(midev, stack->d_stid, stack->upper_id); 01269 if (ret) 01270 { 01271 cb_log(0,port,"Cannot register layer %d of this port.\n", nt?2:4); 01272 return(NULL); 01273 } 01274 01275 stack->lower_id = mISDN_get_layerid(midev, stack->d_stid, nt?1:3); 01276 if (stack->lower_id < 0) { 01277 cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, nt?1:3); 01278 return(NULL); 01279 } 01280 01281 stack->upper_id = mISDN_get_layerid(midev, stack->d_stid, nt?2:4); 01282 if (stack->upper_id < 0) { 01283 cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, 2); 01284 return(NULL); 01285 } 01286 01287 cb_log(8, port, "NT Stacks upper_id %x\n",stack->upper_id); 01288 01289 01290 /* create nst (nt-mode only) */ 01291 if (nt) { 01292 01293 memset(&stack->nst, 0, sizeof(net_stack_t)); 01294 memset(&stack->mgr, 0, sizeof(manager_t)); 01295 01296 stack->mgr.nst = &stack->nst; 01297 stack->nst.manager = &stack->mgr; 01298 01299 stack->nst.l3_manager = handle_event_nt; 01300 stack->nst.device = midev; 01301 stack->nst.cardnr = port; 01302 stack->nst.d_stid = stack->d_stid; 01303 01304 stack->nst.feature = FEATURE_NET_HOLD; 01305 if (stack->ptp) 01306 stack->nst.feature |= FEATURE_NET_PTP; 01307 if (stack->pri) 01308 stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID; 01309 01310 stack->nst.l1_id = stack->lower_id; 01311 stack->nst.l2_id = stack->upper_id; 01312 01313 msg_queue_init(&stack->nst.down_queue); 01314 01315 Isdnl2Init(&stack->nst); 01316 Isdnl3Init(&stack->nst); 01317 01318 } 01319 01320 if (!stack->nt) { 01321 /*assume L1 is up, we'll get DEACTIVATES soon, for non 01322 * up L1s*/ 01323 stack->l1link=0; 01324 } 01325 stack->l1link=0; 01326 stack->l2link=0; 01327 #if 0 01328 if (!stack->nt) { 01329 misdn_lib_get_short_status(stack); 01330 } else { 01331 misdn_lib_get_l1_up(stack); 01332 if (!stack->ptp) misdn_lib_get_l1_up(stack); 01333 misdn_lib_get_l2_up(stack); 01334 } 01335 #endif 01336 01337 misdn_lib_get_short_status(stack); 01338 misdn_lib_get_l1_up(stack); 01339 misdn_lib_get_l2_up(stack); 01340 01341 } 01342 01343 cb_log(8,0,"stack_init: port:%d lowerId:%x upperId:%x\n",stack->port,stack->lower_id, stack->upper_id); 01344 01345 return stack; 01346 }
| void te_lib_destroy | ( | int | midev | ) |
Definition at line 3013 of file isdn_lib.c.
References cb_log, and entity.
Referenced by misdn_lib_destroy().
03014 { 03015 char buf[1024]; 03016 mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC); 03017 03018 cb_log(4, 0, "Entetity deleted\n"); 03019 mISDN_close(midev); 03020 cb_log(4, 0, "midev closed\n"); 03021 }
| int te_lib_init | ( | ) |
App Interface
Definition at line 2984 of file isdn_lib.c.
References entity, and misdn_lib::midev.
Referenced by misdn_lib_init().
02984 { 02985 char buff[1025]; 02986 iframe_t *frm=(iframe_t*)buff; 02987 int midev=mISDN_open(); 02988 int ret; 02989 02990 memset(buff,0,1025); 02991 02992 if (midev<=0) return midev; 02993 02994 /* create entity for layer 3 TE-mode */ 02995 mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 02996 ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC); 02997 02998 if (ret < mISDN_HEADER_LEN) { 02999 noentity: 03000 fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n",strerror(errno)); 03001 exit(-1); 03002 } 03003 03004 entity = frm->dinfo & 0xffff ; 03005 03006 if (!entity) 03007 goto noentity; 03008 03009 return midev; 03010 03011 }
int entity [static] |
Definition at line 213 of file isdn_lib.c.
Referenced by create_process(), te_lib_destroy(), and te_lib_init().
char flip_table[256] [static] |
Definition at line 215 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(), queue_cleanup_bc(), and setup_bc().
enum global_states global_state = MISDN_INITIALIZING [static] |
Definition at line 146 of file isdn_lib.c.
Referenced by clear_l3(), handle_l1(), and misdn_lib_destroy().
| sem_t handler_started |
Definition at line 3695 of file isdn_lib.c.
Msg Array
Definition at line 1136 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 newteid = 0 [static] |
Definition at line 727 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] |
1.5.1