#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 | RETURN(a, b) {retval=a; goto b;} |
#define | TONE_ALERT_CNT 41 |
#define | TONE_ALERT_SILENCE_CNT 200 |
#define | TONE_BUSY_CNT 20 |
#define | TONE_BUSY_SILENCE_CNT 48 |
Enumerations | |
enum | global_states { MISDN_INITIALIZING, MISDN_INITIALIZED } |
Functions | |
static void | bc_next_state_change (struct misdn_bchannel *bc, enum bchannel_state state) |
char * | bc_state2str (enum bchannel_state state) |
void | bc_state_change (struct misdn_bchannel *bc, enum bchannel_state state) |
int | bchdev_echocancel_activate (struct misdn_bchannel *dev) |
void | bchdev_echocancel_deactivate (struct misdn_bchannel *dev) |
static char * | bearer2str (int cap) |
static int | clean_up_bc (struct misdn_bchannel *bc) |
static void | clear_l3 (struct misdn_stack *stack) |
static msg_t * | create_l2msg (int prim, int dinfo, int size) |
msg_t * | create_l3msg (int prim, int mt, int dinfo, int size, int ntmode) |
static int | create_process (int midev, struct misdn_bchannel *bc) |
static int | do_tone (struct misdn_bchannel *bc, int len) |
static void | dump_chan_list (struct misdn_stack *stack) |
void | ec_chunk (struct misdn_bchannel *bc, unsigned char *rxchunk, unsigned char *txchunk, int chunk_size) |
static void | empty_bc (struct misdn_bchannel *bc) |
static int | empty_chan_in_stack (struct misdn_stack *stack, int channel) |
static char * | fac2str (enum FacFunction func) |
static msg_t * | fetch_msg (int midev) |
static struct misdn_bchannel * | find_bc_by_addr (unsigned long addr) |
static struct misdn_bchannel * | find_bc_by_channel (int port, int channel) |
misdn_bchannel * | find_bc_by_confid (unsigned long confid) |
misdn_bchannel * | find_bc_by_l3id (struct misdn_stack *stack, unsigned long l3id) |
static struct misdn_bchannel * | find_bc_by_masked_l3id (struct misdn_stack *stack, unsigned long l3id, unsigned long mask) |
static struct misdn_bchannel * | find_bc_holded (struct misdn_stack *stack) |
static int | find_free_chan_in_stack (struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec) |
static struct misdn_stack * | find_stack_by_addr (int addr) |
static struct misdn_stack * | find_stack_by_mgr (manager_t *mgr_nt) |
static struct misdn_stack * | find_stack_by_port (int port) |
static char * | flip_buf_bits (char *buf, int len) |
misdn_stack * | get_misdn_stack (void) |
void | get_show_stack_details (int port, char *buf) |
misdn_stack * | get_stack_by_bc (struct misdn_bchannel *bc) |
static int | handle_bchan (msg_t *msg) |
static int | handle_cr (struct misdn_stack *stack, iframe_t *frm) |
static int | handle_err (msg_t *msg) |
static int | handle_event (struct misdn_bchannel *bc, enum event_e event, iframe_t *frm) |
static int | handle_event_nt (void *dat, void *arg) |
static int | handle_frm (msg_t *msg) |
static int | handle_frm_nt (msg_t *msg) |
static int | handle_l1 (msg_t *msg) |
static int | handle_l2 (msg_t *msg) |
static int | handle_mgmt (msg_t *msg) |
static int | handle_timers (msg_t *msg) |
int | init_bc (struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, int port, int bidx, char *msn, int firsttime) |
static void | init_flip_bits (void) |
void | isdn_lib_stop_dtmf (struct misdn_bchannel *bc) |
void | isdn_lib_update_ec (struct misdn_bchannel *bc) |
void | isdn_lib_update_rxgain (struct misdn_bchannel *bc) |
void | isdn_lib_update_txgain (struct misdn_bchannel *bc) |
void | manager_bchannel_activate (struct misdn_bchannel *bc) |
void | manager_bchannel_cleanup (struct misdn_bchannel *bc) |
void | manager_bchannel_deactivate (struct misdn_bchannel *bc) |
void | manager_bchannel_setup (struct misdn_bchannel *bc) |
void | manager_clean_bc (struct misdn_bchannel *bc) |
void | manager_ec_disable (struct misdn_bchannel *bc) |
void | manager_ec_enable (struct misdn_bchannel *bc) |
static void | manager_event_handler (void *arg) |
misdn_bchannel * | manager_find_bc_by_pid (int pid) |
misdn_bchannel * | manager_find_bc_holded (struct misdn_bchannel *bc) |
char * | manager_isdn_get_info (enum event_e event) |
int | manager_isdn_handler (iframe_t *frm, msg_t *msg) |
void | manager_ph_control (struct misdn_bchannel *bc, int c1, int c2) |
void | manager_ph_control_block (struct misdn_bchannel *bc, int c1, void *c2, int c2_len) |
int | misdn_cap_is_speech (int cap) |
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_send_lock (struct misdn_bchannel *bc) |
void | misdn_send_unlock (struct misdn_bchannel *bc) |
void | misdn_split_conf (struct misdn_bchannel *bc, int conf_id) |
void | misdn_tx_jitter (struct misdn_bchannel *bc, int len) |
static void | prepare_bc (struct misdn_bchannel *bc, int channel) |
int | queue_cleanup_bc (struct misdn_bchannel *bc) |
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 RETURN | ( | a, | |||
b | ) | {retval=a; goto b;} |
#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_nt(), handle_frm(), 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 2177 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().
02178 { 02179 bc->tone_cnt=len; 02180 02181 if (bc->generate_tone) { 02182 cb_event(EVENT_TONE_GENERATE, bc, glob_mgr->user_data); 02183 02184 if ( !bc->nojitter ) { 02185 misdn_tx_jitter(bc,len); 02186 } 02187 02188 return 1; 02189 } 02190 02191 return 0; 02192 }
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_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_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 3153 of file isdn_lib.c.
References s.
Referenced by misdn_lib_log_ies().
03154 { 03155 struct arr_el { 03156 enum FacFunction p; 03157 char *s ; 03158 } arr[] = { 03159 { Fac_None, "Fac_None" }, 03160 { Fac_CD, "Fac_CD"}, 03161 }; 03162 03163 int i; 03164 03165 for (i=0; i < sizeof(arr)/sizeof( struct arr_el) ; i ++) 03166 if ( arr[i].p==func) return arr[i].s; 03167 03168 return "unknown"; 03169 }
static msg_t* fetch_msg | ( | int | midev | ) | [static] |
Definition at line 2891 of file isdn_lib.c.
References cb_log.
Referenced by misdn_lib_isdn_event_catcher().
02892 { 02893 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 02894 int r; 02895 02896 if (!msg) { 02897 cb_log(0, 0, "fetch_msg: alloc msg failed !!"); 02898 return NULL; 02899 } 02900 02901 AGAIN: 02902 r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC); 02903 msg->len=r; 02904 02905 if (r==0) { 02906 free_msg(msg); /* danger, cauz usualy freeing in main_loop */ 02907 cb_log(6,0,"Got empty Msg..\n"); 02908 return NULL; 02909 } 02910 02911 if (r<0) { 02912 if (errno == EAGAIN) { 02913 /*we wait for mISDN here*/ 02914 cb_log(4,0,"mISDN_read wants us to wait\n"); 02915 usleep(5000); 02916 goto AGAIN; 02917 } 02918 02919 cb_log(0,0,"mISDN_read returned :%d error:%s (%d)\n",r,strerror(errno),errno); 02920 } 02921 02922 #if 0 02923 if (!(frm->prim == (DL_DATA|INDICATION) )|| (frm->prim == (PH_DATA|INDICATION))) 02924 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 ); 02925 #endif 02926 return msg; 02927 }
static struct misdn_bchannel* find_bc_by_addr | ( | unsigned long | addr | ) | [static] |
Definition at line 1441 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().
01442 { 01443 struct misdn_stack* stack; 01444 int i; 01445 01446 for (stack=glob_mgr->stack_list; 01447 stack; 01448 stack=stack->next) { 01449 for (i=0; i<=stack->b_num; i++) { 01450 if ( (stack->bc[i].addr&STACK_ID_MASK)==(addr&STACK_ID_MASK) || stack->bc[i].layer_id== addr ) { 01451 return &stack->bc[i]; 01452 } 01453 } 01454 } 01455 01456 return NULL; 01457 }
static struct misdn_bchannel* find_bc_by_channel | ( | int | port, | |
int | channel | |||
) | [static] |
Definition at line 1477 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().
01478 { 01479 struct misdn_stack* stack=find_stack_by_port(port); 01480 int i; 01481 01482 if (!stack) return NULL; 01483 01484 for (i=0; i<=stack->b_num; i++) { 01485 if ( stack->bc[i].channel== channel ) { 01486 return &stack->bc[i]; 01487 } 01488 } 01489 01490 return NULL; 01491 }
struct misdn_bchannel * find_bc_by_confid | ( | unsigned long | confid | ) |
Definition at line 1459 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().
01460 { 01461 struct misdn_stack* stack; 01462 int i; 01463 01464 for (stack=glob_mgr->stack_list; 01465 stack; 01466 stack=stack->next) { 01467 for (i=0; i<=stack->b_num; i++) { 01468 if ( stack->bc[i].conf_id==confid ) { 01469 return &stack->bc[i]; 01470 } 01471 } 01472 } 01473 return NULL; 01474 }
struct misdn_bchannel * find_bc_by_l3id | ( | struct misdn_stack * | stack, | |
unsigned long | l3id | |||
) |
Definition at line 1422 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().
01423 { 01424 int i; 01425 for (i=0; i<=stack->b_num; i++) { 01426 if (stack->bc[i].l3_id == l3id) return &stack->bc[i] ; 01427 } 01428 return stack_holder_find(stack,l3id); 01429 }
static struct misdn_bchannel* find_bc_by_masked_l3id | ( | struct misdn_stack * | stack, | |
unsigned long | l3id, | |||
unsigned long | mask | |||
) | [static] |
Definition at line 1412 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().
01413 { 01414 int i; 01415 for (i=0; i<=stack->b_num; i++) { 01416 if ( (stack->bc[i].l3_id & mask) == (l3id & mask)) return &stack->bc[i] ; 01417 } 01418 return stack_holder_find(stack,l3id); 01419 }
static struct misdn_bchannel* find_bc_holded | ( | struct misdn_stack * | stack | ) | [static] |
Definition at line 1431 of file isdn_lib.c.
References misdn_stack::b_num, misdn_stack::bc, and misdn_bchannel::holded.
Referenced by manager_find_bc_holded().
01432 { 01433 int i; 01434 for (i=0; i<=stack->b_num; i++) { 01435 if (stack->bc[i].holded ) return &stack->bc[i] ; 01436 } 01437 return NULL; 01438 }
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 1373 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().
01374 { 01375 struct misdn_stack *stack; 01376 01377 for (stack=glob_mgr->stack_list; 01378 stack; 01379 stack=stack->next) { 01380 if ( (stack->upper_id&STACK_ID_MASK) == (addr&STACK_ID_MASK)) return stack; 01381 01382 } 01383 01384 return NULL; 01385 }
static struct misdn_stack* find_stack_by_mgr | ( | manager_t * | mgr_nt | ) | [static] |
Definition at line 1400 of file isdn_lib.c.
References glob_mgr, misdn_stack::mgr, misdn_stack::next, and misdn_lib::stack_list.
Referenced by handle_event_nt().
01401 { 01402 struct misdn_stack *stack; 01403 01404 for (stack=glob_mgr->stack_list; 01405 stack; 01406 stack=stack->next) 01407 if ( &stack->mgr == mgr_nt) return stack; 01408 01409 return NULL; 01410 }
static struct misdn_stack* find_stack_by_port | ( | int | port | ) | [static] |
Definition at line 1388 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().
01389 { 01390 struct misdn_stack *stack; 01391 01392 for (stack=glob_mgr->stack_list; 01393 stack; 01394 stack=stack->next) 01395 if (stack->port == port) return stack; 01396 01397 return NULL; 01398 }
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 4382 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().
04382 { 04383 return glob_mgr->stack_list; 04384 }
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 2280 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().
02281 { 02282 iframe_t *frm= (iframe_t*)msg->data; 02283 02284 02285 struct misdn_bchannel *bc=find_bc_by_addr(frm->addr); 02286 02287 if (!bc) { 02288 cb_log(1,0,"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo); 02289 return 0 ; 02290 } 02291 02292 struct misdn_stack *stack=get_stack_by_bc(bc); 02293 02294 if (!stack) { 02295 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); 02296 return 0; 02297 } 02298 02299 switch (frm->prim) { 02300 02301 case MGR_SETSTACK| CONFIRM: 02302 cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|CONFIRM pid:%d\n",bc->pid); 02303 break; 02304 02305 case MGR_SETSTACK| INDICATION: 02306 cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->pid); 02307 break; 02308 #if 0 02309 AGAIN: 02310 bc->addr = mISDN_get_layerid(stack->midev, bc->b_stid, bc->layer); 02311 if (!bc->addr) { 02312 02313 if (errno == EAGAIN) { 02314 usleep(1000); 02315 goto AGAIN; 02316 } 02317 02318 cb_log(0,stack->port,"$$$ Get Layer (%d) Id Error: %s\n",bc->layer,strerror(errno)); 02319 02320 /* we kill the channel later, when we received some 02321 data. */ 02322 bc->addr= frm->addr; 02323 } else if ( bc->addr < 0) { 02324 cb_log(0, stack->port,"$$$ bc->addr <0 Error:%s\n",strerror(errno)); 02325 bc->addr=0; 02326 } 02327 02328 cb_log(4, stack->port," --> Got Adr %x\n", bc->addr); 02329 02330 free_msg(msg); 02331 02332 02333 switch(bc->bc_state) { 02334 case BCHAN_SETUP: 02335 bc_state_change(bc,BCHAN_SETUPED); 02336 break; 02337 02338 case BCHAN_CLEAN_REQUEST: 02339 default: 02340 cb_log(0, stack->port," --> STATE WASN'T SETUP (but %s) in SETSTACK|IND pid:%d\n",bc_state2str(bc->bc_state), bc->pid); 02341 clean_up_bc(bc); 02342 } 02343 return 1; 02344 #endif 02345 02346 case MGR_DELLAYER| INDICATION: 02347 cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->pid); 02348 break; 02349 02350 case MGR_DELLAYER| CONFIRM: 02351 cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|CNF pid:%d\n",bc->pid); 02352 02353 bc->pid=0; 02354 bc->addr=0; 02355 02356 free_msg(msg); 02357 return 1; 02358 02359 case PH_ACTIVATE | INDICATION: 02360 case DL_ESTABLISH | INDICATION: 02361 cb_log(3, stack->port, "BCHAN: ACT Ind pid:%d\n", bc->pid); 02362 02363 free_msg(msg); 02364 return 1; 02365 02366 case PH_ACTIVATE | CONFIRM: 02367 case DL_ESTABLISH | CONFIRM: 02368 02369 cb_log(3, stack->port, "BCHAN: bchan ACT Confirm pid:%d\n",bc->pid); 02370 free_msg(msg); 02371 02372 return 1; 02373 02374 case DL_ESTABLISH | REQUEST: 02375 { 02376 char buf[128]; 02377 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_ESTABLISH | CONFIRM, 0,0, NULL, TIMEOUT_1SEC); 02378 } 02379 free_msg(msg); 02380 return 1; 02381 02382 case DL_RELEASE|REQUEST: 02383 { 02384 char buf[128]; 02385 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_RELEASE| CONFIRM, 0,0, NULL, TIMEOUT_1SEC); 02386 } 02387 free_msg(msg); 02388 return 1; 02389 02390 case PH_DEACTIVATE | INDICATION: 02391 case DL_RELEASE | INDICATION: 02392 cb_log (3, stack->port, "BCHAN: DeACT Ind pid:%d\n",bc->pid); 02393 02394 free_msg(msg); 02395 return 1; 02396 02397 case PH_DEACTIVATE | CONFIRM: 02398 case DL_RELEASE | CONFIRM: 02399 cb_log(3, stack->port, "BCHAN: DeACT Conf pid:%d\n",bc->pid); 02400 02401 free_msg(msg); 02402 return 1; 02403 02404 case PH_CONTROL|INDICATION: 02405 { 02406 unsigned int cont = *((unsigned int *)&frm->data.p); 02407 02408 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); 02409 02410 if ((cont&~DTMF_TONE_MASK) == DTMF_TONE_VAL) { 02411 int dtmf = cont & DTMF_TONE_MASK; 02412 cb_log(4, stack->port, " --> DTMF TONE: %c\n",dtmf); 02413 bc->dtmf=dtmf; 02414 cb_event(EVENT_DTMF_TONE, bc, glob_mgr->user_data); 02415 02416 free_msg(msg); 02417 return 1; 02418 } 02419 if (cont == BF_REJECT) { 02420 cb_log(4, stack->port, " --> BF REJECT\n"); 02421 free_msg(msg); 02422 return 1; 02423 } 02424 if (cont == BF_ACCEPT) { 02425 cb_log(4, stack->port, " --> BF ACCEPT\n"); 02426 free_msg(msg); 02427 return 1; 02428 } 02429 } 02430 break; 02431 02432 case PH_DATA|REQUEST: 02433 case DL_DATA|REQUEST: 02434 cb_log(0, stack->port, "DL_DATA REQUEST \n"); 02435 do_tone(bc, 64); 02436 02437 free_msg(msg); 02438 return 1; 02439 02440 02441 case PH_DATA|INDICATION: 02442 case DL_DATA|INDICATION: 02443 { 02444 bc->bframe = (void*)&frm->data.i; 02445 bc->bframe_len = frm->len; 02446 02447 /** Anyway flip the bufbits **/ 02448 if ( misdn_cap_is_speech(bc->capability) ) 02449 flip_buf_bits(bc->bframe, bc->bframe_len); 02450 02451 02452 if (!bc->bframe_len) { 02453 cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); 02454 free_msg(msg); 02455 return 1; 02456 } 02457 02458 if ( (bc->addr&STACK_ID_MASK) != (frm->addr&STACK_ID_MASK) ) { 02459 cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); 02460 free_msg(msg); 02461 return 1; 02462 } 02463 02464 #if MISDN_DEBUG 02465 cb_log(0, stack->port, "DL_DATA INDICATION Len %d\n", frm->len); 02466 02467 #endif 02468 02469 if ( (bc->bc_state == BCHAN_ACTIVATED) && frm->len > 0) { 02470 int t; 02471 02472 #ifdef MISDN_B_DEBUG 02473 cb_log(0,bc->port,"do_tone START\n"); 02474 #endif 02475 t=do_tone(bc,frm->len); 02476 02477 #ifdef MISDN_B_DEBUG 02478 cb_log(0,bc->port,"do_tone STOP (%d)\n",t); 02479 #endif 02480 if ( !t ) { 02481 02482 if ( misdn_cap_is_speech(bc->capability)) { 02483 if ( !bc->nojitter ) { 02484 #ifdef MISDN_B_DEBUG 02485 cb_log(0,bc->port,"tx_jitter START\n"); 02486 #endif 02487 misdn_tx_jitter(bc,frm->len); 02488 #ifdef MISDN_B_DEBUG 02489 cb_log(0,bc->port,"tx_jitter STOP\n"); 02490 #endif 02491 } 02492 } 02493 02494 #ifdef MISDN_B_DEBUG 02495 cb_log(0,bc->port,"EVENT_B_DATA START\n"); 02496 #endif 02497 02498 int i=cb_event( EVENT_BCHAN_DATA, bc, glob_mgr->user_data); 02499 #ifdef MISDN_B_DEBUG 02500 cb_log(0,bc->port,"EVENT_B_DATA STOP\n"); 02501 #endif 02502 02503 if (i<0) { 02504 cb_log(10,stack->port,"cb_event returned <0\n"); 02505 /*clean_up_bc(bc);*/ 02506 } 02507 } 02508 } 02509 free_msg(msg); 02510 return 1; 02511 } 02512 02513 02514 case PH_CONTROL | CONFIRM: 02515 cb_log(4, stack->port, "PH_CONTROL|CNF bc->addr:%x\n", frm->addr); 02516 free_msg(msg); 02517 return 1; 02518 02519 case PH_DATA | CONFIRM: 02520 case DL_DATA|CONFIRM: 02521 #if MISDN_DEBUG 02522 02523 cb_log(0, stack->port, "Data confirmed\n"); 02524 02525 #endif 02526 free_msg(msg); 02527 return 1; 02528 case DL_DATA|RESPONSE: 02529 #if MISDN_DEBUG 02530 cb_log(0, stack->port, "Data response\n"); 02531 02532 #endif 02533 break; 02534 } 02535 02536 return 0; 02537 }
static int handle_cr | ( | struct misdn_stack * | stack, | |
iframe_t * | frm | |||
) | [static] |
Definition at line 1564 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().
01565 { 01566 if (!stack) return -1; 01567 01568 switch (frm->prim) { 01569 case CC_NEW_CR|INDICATION: 01570 cb_log(7, stack->port, " --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo); 01571 01572 struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0); 01573 if (!bc) { 01574 cb_log(0, stack->port, " --> !! lib: No free channel!\n"); 01575 return -1; 01576 } 01577 01578 cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo); 01579 bc->l3_id=frm->dinfo; 01580 return 1; 01581 case CC_NEW_CR|CONFIRM: 01582 return 1; 01583 case CC_NEW_CR|REQUEST: 01584 return 1; 01585 case CC_RELEASE_CR|REQUEST: 01586 return 1; 01587 case CC_RELEASE_CR|CONFIRM: 01588 break; 01589 case CC_RELEASE_CR|INDICATION: 01590 cb_log(4, stack->port, " --> lib: RELEASE_CR Ind with l3id:%x\n",frm->dinfo); 01591 { 01592 struct misdn_bchannel *bc=find_bc_by_l3id(stack, frm->dinfo); 01593 struct misdn_bchannel dummybc; 01594 01595 if (!bc) { 01596 cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo); 01597 memset (&dummybc,0,sizeof(dummybc)); 01598 dummybc.port=stack->port; 01599 dummybc.l3_id=frm->dinfo; 01600 dummybc.nt=stack->nt; 01601 bc=&dummybc; 01602 } 01603 01604 if (bc) { 01605 cb_log(4, stack->port, " --> lib: CLEANING UP l3id: %x\n",frm->dinfo); 01606 if (bc->channel>0) 01607 empty_chan_in_stack(stack,bc->channel); 01608 01609 /*bc->pid = 0;*/ 01610 bc->need_disconnect=0; 01611 bc->need_release=0; 01612 bc->need_release_complete=0; 01613 01614 cb_event(EVENT_CLEANUP, bc, glob_mgr->user_data); 01615 01616 empty_bc(bc); 01617 clean_up_bc(bc); 01618 dump_chan_list(stack); 01619 01620 if (bc->stack_holder) { 01621 cb_log(4,stack->port, "REMOVEING Holder\n"); 01622 stack_holder_remove( stack, bc); 01623 free(bc); 01624 } 01625 } 01626 else { 01627 if (stack->nt) 01628 cb_log(4, stack->port, "BC with dinfo: %x not found.. (prim was %x and addr %x)\n",frm->dinfo, frm->prim, frm->addr); 01629 } 01630 01631 return 1; 01632 } 01633 break; 01634 } 01635 01636 return 0; 01637 }
static int handle_err | ( | msg_t * | msg | ) | [static] |
Definition at line 3437 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().
03438 { 03439 iframe_t *frm = (iframe_t*) msg->data; 03440 03441 03442 if (!frm->addr) { 03443 static int cnt=0; 03444 if (!cnt) 03445 cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo); 03446 cnt++; 03447 if (cnt>100) { 03448 cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo); 03449 cnt=0; 03450 } 03451 03452 free_msg(msg); 03453 return 1; 03454 03455 } 03456 03457 switch (frm->prim) { 03458 case MGR_SETSTACK|INDICATION: 03459 return handle_bchan(msg); 03460 break; 03461 03462 case MGR_SETSTACK|CONFIRM: 03463 case MGR_CLEARSTACK|CONFIRM: 03464 free_msg(msg) ; 03465 return 1; 03466 break; 03467 03468 case DL_DATA|CONFIRM: 03469 cb_log(4,0,"DL_DATA|CONFIRM\n"); 03470 free_msg(msg); 03471 return 1; 03472 03473 case PH_CONTROL|CONFIRM: 03474 cb_log(4,0,"PH_CONTROL|CONFIRM\n"); 03475 free_msg(msg); 03476 return 1; 03477 03478 case DL_DATA|INDICATION: 03479 { 03480 int port=(frm->addr&MASTER_ID_MASK) >> 8; 03481 int channel=(frm->addr&CHILD_ID_MASK) >> 16; 03482 03483 /*we flush the read buffer here*/ 03484 03485 cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel); 03486 03487 free_msg(msg) ; 03488 return 1; 03489 03490 03491 struct misdn_bchannel *bc=find_bc_by_channel( port , channel); 03492 03493 if (!bc) { 03494 struct misdn_stack *stack=find_stack_by_port( port ); 03495 03496 if (!stack) { 03497 cb_log(0,0," --> stack not found\n"); 03498 free_msg(msg); 03499 return 1; 03500 } 03501 03502 cb_log(0,0," --> bc not found by channel\n"); 03503 if (stack->l2link) 03504 misdn_lib_get_l2_down(stack); 03505 03506 if (stack->l1link) 03507 misdn_lib_get_l1_down(stack); 03508 03509 free_msg(msg); 03510 return 1; 03511 } 03512 03513 cb_log(3,port," --> BC in state:%s\n", bc_state2str(bc->bc_state)); 03514 } 03515 } 03516 03517 return 0; 03518 }
static int handle_event | ( | struct misdn_bchannel * | bc, | |
enum event_e | event, | |||
iframe_t * | frm | |||
) | [static] |
Definition at line 1497 of file isdn_lib.c.
References misdn_stack::bc, misdn_bchannel::capability, cb_log, misdn_bchannel::channel, misdn_bchannel::crypt_key, misdn_bchannel::dad, misdn_bchannel::dnumplan, 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().
01498 { 01499 struct misdn_stack *stack=get_stack_by_bc(bc); 01500 01501 if (!stack->nt) { 01502 01503 switch (event) { 01504 01505 case EVENT_CONNECT_ACKNOWLEDGE: 01506 #if 0 01507 if ( !misdn_cap_is_speech(bc->capability)) { 01508 int ret=setup_bc(bc); 01509 if (ret == -EINVAL){ 01510 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 01511 } 01512 } 01513 #endif 01514 break; 01515 case EVENT_CONNECT: 01516 01517 if ( *bc->crypt_key ) { 01518 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); 01519 manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); 01520 } 01521 case EVENT_ALERTING: 01522 case EVENT_PROGRESS: 01523 case EVENT_PROCEEDING: 01524 case EVENT_SETUP_ACKNOWLEDGE: 01525 01526 setup_bc(bc); 01527 01528 case EVENT_SETUP: 01529 { 01530 if (bc->channel == 0xff) { 01531 if (!find_free_chan_in_stack(stack, bc, 0, 0)) { 01532 cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n"); 01533 bc->out_cause=34; 01534 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 01535 return -1; 01536 } 01537 } 01538 01539 if (bc->channel >0 && bc->channel<255) { 01540 int ret=set_chan_in_stack(stack ,bc->channel); 01541 if (event == EVENT_SETUP && ret<0){ 01542 /* empty bchannel */ 01543 bc->channel=0; 01544 bc->out_cause=44; 01545 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 01546 return -1; 01547 } 01548 } 01549 } 01550 break; 01551 01552 case EVENT_RELEASE_COMPLETE: 01553 case EVENT_RELEASE: 01554 break; 01555 default: 01556 break; 01557 } 01558 } else { /** NT MODE **/ 01559 01560 } 01561 return 0; 01562 }
int handle_event_nt | ( | void * | dat, | |
void * | arg | |||
) | [static] |
Definition at line 1739 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().
01740 { 01741 manager_t *mgr = (manager_t *)dat; 01742 msg_t *msg = (msg_t *)arg; 01743 mISDNuser_head_t *hh; 01744 int reject=0; 01745 01746 struct misdn_stack *stack=find_stack_by_mgr(mgr); 01747 int port; 01748 01749 if (!msg || !mgr) 01750 return(-EINVAL); 01751 01752 hh=(mISDNuser_head_t*)msg->data; 01753 port=stack->port; 01754 01755 cb_log(5, stack->port, " --> lib: prim %x dinfo %x\n",hh->prim, hh->dinfo); 01756 { 01757 switch(hh->prim){ 01758 case CC_RETRIEVE|INDICATION: 01759 { 01760 iframe_t frm; /* fake te frm to add callref to global callreflist */ 01761 frm.dinfo = hh->dinfo; 01762 01763 frm.addr=stack->upper_id | FLG_MSG_DOWN; 01764 01765 frm.prim = CC_NEW_CR|INDICATION; 01766 01767 if (handle_cr( stack, &frm)< 0) { 01768 msg_t *dmsg; 01769 cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo); 01770 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01771 stack->nst.manager_l3(&stack->nst, dmsg); 01772 free_msg(msg); 01773 return 0; 01774 } 01775 01776 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01777 struct misdn_bchannel *hold_bc=stack_holder_find(stack,bc->l3_id); 01778 cb_log(4, stack->port, "bc_l3id:%x holded_bc_l3id:%x\n",bc->l3_id, hold_bc->l3_id); 01779 01780 if (hold_bc) { 01781 cb_log(4, stack->port, "REMOVEING Holder\n"); 01782 01783 /*swap the backup to our new channel back*/ 01784 stack_holder_remove(stack, hold_bc); 01785 memcpy(bc,hold_bc,sizeof(struct misdn_bchannel)); 01786 free(hold_bc); 01787 01788 bc->holded=0; 01789 } 01790 01791 } 01792 01793 break; 01794 01795 case CC_SETUP|CONFIRM: 01796 { 01797 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01798 int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE)); 01799 cb_log(4, stack->port, " --> lib: Event_ind:SETUP CONFIRM [NT] : new L3ID is %x\n",l3id ); 01800 01801 if (!bc) { cb_log(4, stack->port, "Bc Not found (after SETUP CONFIRM)\n"); return 0; } 01802 cb_log (2,bc->port,"I IND :CC_SETUP|CONFIRM: old l3id:%x new l3id:%x\n", bc->l3_id, l3id); 01803 bc->l3_id=l3id; 01804 cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data); 01805 } 01806 free_msg(msg); 01807 return 0; 01808 01809 case CC_SETUP|INDICATION: 01810 { 01811 struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0); 01812 if (!bc) 01813 ERR_NO_CHANNEL: 01814 { 01815 msg_t *dmsg; 01816 cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo); 01817 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01818 stack->nst.manager_l3(&stack->nst, dmsg); 01819 free_msg(msg); 01820 return 0; 01821 } 01822 01823 cb_log(4, stack->port, " --> new_process: New L3Id: %x\n",hh->dinfo); 01824 bc->l3_id=hh->dinfo; 01825 } 01826 break; 01827 01828 case CC_CONNECT_ACKNOWLEDGE|INDICATION: 01829 #if 0 01830 { 01831 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01832 if (bc) { 01833 if ( !misdn_cap_is_speech(bc->capability)) { 01834 int ret=setup_bc(bc); 01835 if (ret == -EINVAL){ 01836 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 01837 01838 } 01839 } 01840 } 01841 } 01842 #endif 01843 break; 01844 01845 case CC_ALERTING|INDICATION: 01846 case CC_PROCEEDING|INDICATION: 01847 case CC_SETUP_ACKNOWLEDGE|INDICATION: 01848 if(!stack->ptp) break; 01849 case CC_CONNECT|INDICATION: 01850 { 01851 #if 0 01852 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01853 01854 if (!bc) { 01855 msg_t *dmsg; 01856 cb_log(0, stack->port,"!!!! We didn't found our bc, dinfo:%x on this port.\n",hh->dinfo); 01857 01858 cb_log(0, stack->port, "Releaseing call %x (No free Chan for you..)\n", hh->dinfo); 01859 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01860 stack->nst.manager_l3(&stack->nst, dmsg); 01861 free_msg(msg); 01862 return 0; 01863 01864 } 01865 int ret=setup_bc(bc); 01866 if (ret == -EINVAL){ 01867 cb_log(0,bc->port,"handle_event_nt: setup_bc failed\n"); 01868 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 01869 } 01870 #endif 01871 } 01872 break; 01873 case CC_DISCONNECT|INDICATION: 01874 { 01875 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01876 if (!bc) { 01877 bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000); 01878 if (bc) { 01879 int myprocid=bc->l3_id&0x0000ffff; 01880 hh->dinfo=(hh->dinfo&0xffff0000)|myprocid; 01881 cb_log(3,stack->port,"Reject dinfo: %x cause:%d\n",hh->dinfo,bc->cause); 01882 reject=1; 01883 } 01884 } 01885 } 01886 break; 01887 01888 case CC_FACILITY|INDICATION: 01889 { 01890 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01891 if (!bc) { 01892 bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000); 01893 if (bc) { 01894 int myprocid=bc->l3_id&0x0000ffff; 01895 hh->dinfo=(hh->dinfo&0xffff0000)|myprocid; 01896 cb_log(4,bc->port,"Repaired reject Bug, new dinfo: %x\n",hh->dinfo); 01897 } 01898 } 01899 } 01900 break; 01901 01902 case CC_RELEASE_COMPLETE|INDICATION: 01903 break; 01904 01905 case CC_SUSPEND|INDICATION: 01906 { 01907 msg_t *dmsg; 01908 cb_log(4, stack->port, " --> Got Suspend, sending Reject for now\n"); 01909 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST,MT_SUSPEND_REJECT, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); 01910 stack->nst.manager_l3(&stack->nst, dmsg); 01911 free_msg(msg); 01912 return 0; 01913 } 01914 break; 01915 case CC_RESUME|INDICATION: 01916 break; 01917 01918 case CC_RELEASE|CONFIRM: 01919 break; 01920 01921 case CC_RELEASE|INDICATION: 01922 break; 01923 01924 case CC_RELEASE_CR|INDICATION: 01925 { 01926 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01927 struct misdn_bchannel dummybc; 01928 iframe_t frm; /* fake te frm to remove callref from global callreflist */ 01929 frm.dinfo = hh->dinfo; 01930 01931 frm.addr=stack->upper_id | FLG_MSG_DOWN; 01932 01933 frm.prim = CC_RELEASE_CR|INDICATION; 01934 cb_log(4, stack->port, " --> Faking Realease_cr for %x\n",frm.addr); 01935 /** removing procid **/ 01936 if (!bc) { 01937 cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", hh->dinfo); 01938 memset (&dummybc,0,sizeof(dummybc)); 01939 dummybc.port=stack->port; 01940 dummybc.l3_id=hh->dinfo; 01941 dummybc.nt=stack->nt; 01942 bc=&dummybc; 01943 } 01944 01945 if (bc) { 01946 if ( (bc->l3_id & 0xff00) == 0xff00) { 01947 cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", bc->l3_id&0xff); 01948 stack->procids[bc->l3_id&0xff] = 0 ; 01949 } 01950 } 01951 else cb_log(0, stack->port, "Couldnt find BC so I couldnt remove the Process!!!! this is a bad port.\n"); 01952 01953 if (handle_cr(stack, &frm)<0) { 01954 } 01955 01956 free_msg(msg); 01957 return 0 ; 01958 } 01959 break; 01960 01961 case CC_NEW_CR|INDICATION: 01962 /* Got New CR for bchan, for now I handle this one in */ 01963 /* connect_ack, Need to be changed */ 01964 { 01965 struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); 01966 int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE)); 01967 if (!bc) { cb_log(0, stack->port, " --> In NEW_CR: didn't found bc ??\n"); return -1;}; 01968 if (((l3id&0xff00)!=0xff00) && ((bc->l3_id&0xff00)==0xff00)) { 01969 cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", 0xff&bc->l3_id); 01970 stack->procids[bc->l3_id&0xff] = 0 ; 01971 } 01972 cb_log(4, stack->port, "lib: Event_ind:CC_NEW_CR : very new L3ID is %x\n",l3id ); 01973 01974 bc->l3_id =l3id; 01975 cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data); 01976 01977 free_msg(msg); 01978 return 0; 01979 } 01980 01981 case DL_ESTABLISH | INDICATION: 01982 case DL_ESTABLISH | CONFIRM: 01983 { 01984 cb_log(3, stack->port, "%% GOT L2 Activate Info.\n"); 01985 01986 if (stack->ptp && stack->l2link) { 01987 cb_log(0, stack->port, "%% GOT L2 Activate Info. but we're activated already.. this l2 is faulty, blocking port\n"); 01988 cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data); 01989 } 01990 01991 /* when we get the L2 UP, the L1 is UP definitely too*/ 01992 stack->l1link = 1; 01993 stack->l2link = 1; 01994 stack->l2upcnt=0; 01995 01996 free_msg(msg); 01997 return 0; 01998 } 01999 break; 02000 02001 02002 case DL_RELEASE | INDICATION: 02003 case DL_RELEASE | CONFIRM: 02004 { 02005 if (stack->ptp) { 02006 cb_log(3 , stack->port, "%% GOT L2 DeActivate Info.\n"); 02007 02008 if (stack->l2upcnt>3) { 02009 cb_log(0 , stack->port, "!!! Could not Get the L2 up after 3 Attemps!!!\n"); 02010 } else { 02011 #if 0 02012 if (stack->nt) misdn_lib_reinit_nt_stack(stack->port); 02013 #endif 02014 if (stack->l1link) { 02015 misdn_lib_get_l2_up(stack); 02016 stack->l2upcnt++; 02017 } 02018 } 02019 02020 } else 02021 cb_log(3, stack->port, "%% GOT L2 DeActivate Info.\n"); 02022 02023 stack->l2link = 0; 02024 free_msg(msg); 02025 return 0; 02026 } 02027 break; 02028 } 02029 } 02030 02031 { 02032 /* Parse Events and fire_up to App. */ 02033 struct misdn_bchannel *bc; 02034 struct misdn_bchannel dummybc; 02035 02036 enum event_e event = isdn_msg_get_event(msgs_g, msg, 1); 02037 02038 bc=find_bc_by_l3id(stack, hh->dinfo); 02039 02040 if (!bc) { 02041 02042 cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x).\n", hh->dinfo); 02043 memset (&dummybc,0,sizeof(dummybc)); 02044 dummybc.port=stack->port; 02045 dummybc.l3_id=hh->dinfo; 02046 dummybc.nt=stack->nt; 02047 bc=&dummybc; 02048 } 02049 if (bc ) { 02050 isdn_msg_parse_event(msgs_g,msg,bc, 1); 02051 02052 switch (event) { 02053 case EVENT_SETUP: 02054 if (bc->channel<=0 || bc->channel==0xff) { 02055 bc->channel=find_free_chan_in_stack(stack,bc, 0,0); 02056 if (bc->channel<=0) 02057 goto ERR_NO_CHANNEL; 02058 } else if (!stack->ptp) 02059 cb_log(3,stack->port," --> PTMP but channel requested\n"); 02060 02061 int ret=set_chan_in_stack(stack, bc->channel); 02062 if (event==EVENT_SETUP && ret<0){ 02063 /* empty bchannel */ 02064 bc->channel=0; 02065 bc->out_cause=44; 02066 02067 goto ERR_NO_CHANNEL; 02068 } 02069 break; 02070 case EVENT_RELEASE: 02071 case EVENT_RELEASE_COMPLETE: 02072 if (bc->channel>0) 02073 empty_chan_in_stack(stack, bc->channel); 02074 int tmpcause=bc->cause; 02075 empty_bc(bc); 02076 bc->cause=tmpcause; 02077 clean_up_bc(bc); 02078 break; 02079 02080 default: 02081 break; 02082 } 02083 02084 if(!isdn_get_info(msgs_g,event,1)) { 02085 cb_log(4, stack->port, "Unknown Event Ind: prim %x dinfo %x\n",hh->prim, hh->dinfo); 02086 } else { 02087 if (reject) { 02088 switch(bc->cause){ 02089 case 17: 02090 cb_log(1, stack->port, "Siemens Busy reject..\n"); 02091 02092 break; 02093 default: 02094 break; 02095 } 02096 } 02097 cb_event(event, bc, glob_mgr->user_data); 02098 } 02099 02100 } else { 02101 cb_log(4, stack->port, "No BC found with l3id: prim %x dinfo %x\n",hh->prim, hh->dinfo); 02102 } 02103 02104 free_msg(msg); 02105 } 02106 02107 02108 return 0; 02109 }
static int handle_frm | ( | msg_t * | msg | ) | [static] |
Definition at line 2576 of file isdn_lib.c.
References bc_state_change(), BCHAN_CLEANED, misdn_bchannel::cause, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), empty_bc(), empty_chan_in_stack(), event, 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().
02577 { 02578 iframe_t *frm = (iframe_t*) msg->data; 02579 02580 struct misdn_stack *stack=find_stack_by_addr(frm->addr); 02581 02582 if (!stack || stack->nt) { 02583 return 0; 02584 } 02585 02586 cb_log(4,stack?stack->port:0,"handle_frm: frm->addr:%x frm->prim:%x\n",frm->addr,frm->prim); 02587 02588 { 02589 struct misdn_bchannel *bc; 02590 int ret=handle_cr(stack, frm); 02591 02592 if (ret<0) { 02593 cb_log(3,stack?stack->port:0,"handle_frm: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr); 02594 02595 02596 } 02597 02598 if(ret) { 02599 free_msg(msg); 02600 return 1; 02601 } 02602 02603 bc=find_bc_by_l3id(stack, frm->dinfo); 02604 02605 handle_frm_bc: 02606 if (bc ) { 02607 enum event_e event = isdn_msg_get_event(msgs_g, msg, 0); 02608 enum event_response_e response=RESPONSE_OK; 02609 02610 isdn_msg_parse_event(msgs_g,msg,bc, 0); 02611 02612 /** Preprocess some Events **/ 02613 int ret=handle_event(bc, event, frm); 02614 if (ret<0) { 02615 cb_log(0,stack->port,"couldn't handle event\n"); 02616 free_msg(msg); 02617 return 1; 02618 } 02619 /* shoot up event to App: */ 02620 cb_log(5, stack->port, "lib Got Prim: Addr %x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo); 02621 02622 if(!isdn_get_info(msgs_g,event,0)) 02623 cb_log(0, stack->port, "Unknown Event Ind: Addr:%x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo); 02624 else 02625 response=cb_event(event, bc, glob_mgr->user_data); 02626 #if 1 02627 if (event == EVENT_SETUP) { 02628 switch (response) { 02629 case RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE: 02630 02631 cb_log(0, stack->port, "TOTALY IGNORING SETUP \n"); 02632 02633 break; 02634 case RESPONSE_IGNORE_SETUP: 02635 /* I think we should send CC_RELEASE_CR, but am not sure*/ 02636 bc->out_cause=16; 02637 02638 case RESPONSE_RELEASE_SETUP: 02639 misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); 02640 if (bc->channel>0) 02641 empty_chan_in_stack(stack, bc->channel); 02642 empty_bc(bc); 02643 bc_state_change(bc,BCHAN_CLEANED); 02644 02645 cb_log(0, stack->port, "GOT IGNORE SETUP\n"); 02646 02647 02648 break; 02649 case RESPONSE_OK: 02650 cb_log(4, stack->port, "GOT SETUP OK\n"); 02651 02652 02653 break; 02654 default: 02655 break; 02656 } 02657 } 02658 02659 if (event == EVENT_RELEASE_COMPLETE) { 02660 /* release bchannel only after we've anounced the RELEASE_COMPLETE */ 02661 if (bc->channel>0) 02662 empty_chan_in_stack(stack,bc->channel); 02663 int tmpcause=bc->cause; 02664 int tmp_out_cause=bc->out_cause; 02665 empty_bc(bc); 02666 bc->cause=tmpcause; 02667 bc->out_cause=tmp_out_cause; 02668 clean_up_bc(bc); 02669 } 02670 02671 cb_log(5, stack->port, "Freeing Msg on prim:%x \n",frm->prim); 02672 02673 02674 free_msg(msg); 02675 return 1; 02676 #endif 02677 02678 } else { 02679 cb_log(0, stack->port, " --> Didn't find BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo); 02680 struct misdn_bchannel dummybc; 02681 memset (&dummybc,0,sizeof(dummybc)); 02682 dummybc.port=stack->port; 02683 dummybc.l3_id=frm->dinfo; 02684 bc=&dummybc; 02685 goto handle_frm_bc; 02686 } 02687 } 02688 02689 cb_log(4, stack->port, "TE_FRM_HANDLER: Returning 0 on prim:%x \n",frm->prim); 02690 return 0; 02691 }
static int handle_frm_nt | ( | msg_t * | msg | ) | [static] |
Definition at line 2541 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().
02542 { 02543 iframe_t *frm= (iframe_t*)msg->data; 02544 struct misdn_stack *stack; 02545 int err=0; 02546 02547 stack=find_stack_by_addr( frm->addr ); 02548 02549 02550 02551 if (!stack || !stack->nt) { 02552 return 0; 02553 } 02554 02555 02556 if ((err=stack->nst.l1_l2(&stack->nst,msg))) { 02557 02558 if (nt_err_cnt > 0 ) { 02559 if (nt_err_cnt < 100) { 02560 nt_err_cnt++; 02561 cb_log(0, stack->port, "NT Stack sends us error: %d \n", err); 02562 } else if (nt_err_cnt < 105){ 02563 cb_log(0, stack->port, "NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err); 02564 nt_err_cnt = - 1; 02565 } 02566 } 02567 free_msg(msg); 02568 return 1; 02569 02570 } 02571 02572 return 1; 02573 }
static int handle_l1 | ( | msg_t * | msg | ) | [static] |
Definition at line 2694 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().
02695 { 02696 iframe_t *frm = (iframe_t*) msg->data; 02697 struct misdn_stack *stack = find_stack_by_addr(frm->addr); 02698 int i ; 02699 02700 if (!stack) return 0 ; 02701 02702 switch (frm->prim) { 02703 case PH_ACTIVATE | CONFIRM: 02704 case PH_ACTIVATE | INDICATION: 02705 cb_log (3, stack->port, "L1: PH L1Link Up!\n"); 02706 stack->l1link=1; 02707 02708 if (stack->nt) { 02709 02710 if (stack->nst.l1_l2(&stack->nst, msg)) 02711 free_msg(msg); 02712 02713 if (stack->ptp) 02714 misdn_lib_get_l2_up(stack); 02715 } else { 02716 free_msg(msg); 02717 } 02718 02719 for (i=0;i<=stack->b_num; i++) { 02720 if (stack->bc[i].evq != EVENT_NOTHING) { 02721 cb_log(4, stack->port, "Fireing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0)); 02722 misdn_lib_send_event(&stack->bc[i],stack->bc[i].evq); 02723 stack->bc[i].evq=EVENT_NOTHING; 02724 } 02725 02726 } 02727 return 1; 02728 02729 case PH_ACTIVATE | REQUEST: 02730 free_msg(msg); 02731 cb_log(3,stack->port,"L1: PH_ACTIVATE|REQUEST \n"); 02732 return 1; 02733 02734 case PH_DEACTIVATE | REQUEST: 02735 free_msg(msg); 02736 cb_log(3,stack->port,"L1: PH_DEACTIVATE|REQUEST \n"); 02737 return 1; 02738 02739 case PH_DEACTIVATE | CONFIRM: 02740 case PH_DEACTIVATE | INDICATION: 02741 cb_log (3, stack->port, "L1: PH L1Link Down! \n"); 02742 02743 for (i=0; i<=stack->b_num; i++) { 02744 if (global_state == MISDN_INITIALIZED) { 02745 cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data); 02746 } 02747 } 02748 02749 if (stack->nt) { 02750 if (stack->nst.l1_l2(&stack->nst, msg)) 02751 free_msg(msg); 02752 } else { 02753 free_msg(msg); 02754 } 02755 02756 stack->l1link=0; 02757 stack->l2link=0; 02758 return 1; 02759 } 02760 02761 return 0; 02762 }
static int handle_l2 | ( | msg_t * | msg | ) | [static] |
Definition at line 2764 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().
02765 { 02766 iframe_t *frm = (iframe_t*) msg->data; 02767 02768 struct misdn_stack *stack = find_stack_by_addr(frm->addr); 02769 02770 if (!stack) { 02771 return 0 ; 02772 } 02773 02774 switch(frm->prim) { 02775 02776 case DL_ESTABLISH | REQUEST: 02777 cb_log(1,stack->port,"DL_ESTABLISH|REQUEST \n"); 02778 return 1; 02779 case DL_RELEASE | REQUEST: 02780 cb_log(1,stack->port,"DL_RELEASE|REQUEST \n"); 02781 return 1; 02782 02783 case DL_ESTABLISH | INDICATION: 02784 case DL_ESTABLISH | CONFIRM: 02785 { 02786 cb_log (3, stack->port, "L2: L2Link Up! \n"); 02787 if (stack->ptp && stack->l2link) { 02788 cb_log (-1, stack->port, "L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n"); 02789 cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data); 02790 } 02791 stack->l2link=1; 02792 free_msg(msg); 02793 return 1; 02794 } 02795 break; 02796 02797 case DL_RELEASE | INDICATION: 02798 case DL_RELEASE | CONFIRM: 02799 { 02800 cb_log (3, stack->port, "L2: L2Link Down! \n"); 02801 stack->l2link=0; 02802 02803 free_msg(msg); 02804 return 1; 02805 } 02806 break; 02807 } 02808 return 0; 02809 }
static int handle_mgmt | ( | msg_t * | msg | ) | [static] |
Definition at line 2811 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().
02812 { 02813 iframe_t *frm = (iframe_t*) msg->data; 02814 02815 if ( (frm->addr == 0) && (frm->prim == (MGR_DELLAYER|CONFIRM)) ) { 02816 cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: 0 !\n") ; 02817 free_msg(msg); 02818 return 1; 02819 } 02820 02821 struct misdn_stack * stack=find_stack_by_addr(frm->addr); 02822 02823 if (!stack) { 02824 if (frm->prim == (MGR_DELLAYER|CONFIRM)) { 02825 cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: %x !\n", 02826 frm->addr) ; 02827 free_msg(msg); 02828 return 1; 02829 } 02830 02831 return 0; 02832 } 02833 02834 switch(frm->prim) { 02835 case MGR_SHORTSTATUS | INDICATION: 02836 case MGR_SHORTSTATUS | CONFIRM: 02837 cb_log(5, 0, "MGMT: Short status dinfo %x\n",frm->dinfo); 02838 02839 switch (frm->dinfo) { 02840 case SSTATUS_L1_ACTIVATED: 02841 cb_log(3, 0, "MGMT: SSTATUS: L1_ACTIVATED \n"); 02842 stack->l1link=1; 02843 02844 break; 02845 case SSTATUS_L1_DEACTIVATED: 02846 cb_log(3, 0, "MGMT: SSTATUS: L1_DEACTIVATED \n"); 02847 stack->l1link=0; 02848 02849 clear_l3(stack); 02850 break; 02851 02852 case SSTATUS_L2_ESTABLISHED: 02853 cb_log(3, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n"); 02854 02855 /*when the L2 goes UP, L1 needs to be UP too*/ 02856 stack->l1link=1; 02857 stack->l2link=1; 02858 break; 02859 02860 case SSTATUS_L2_RELEASED: 02861 cb_log(3, stack->port, "MGMT: SSTATUS: L2_RELEASED \n"); 02862 stack->l2link=0; 02863 break; 02864 } 02865 02866 free_msg(msg); 02867 return 1; 02868 02869 case MGR_SETSTACK | INDICATION: 02870 cb_log(4, stack->port, "MGMT: SETSTACK|IND dinfo %x\n",frm->dinfo); 02871 free_msg(msg); 02872 return 1; 02873 case MGR_DELLAYER | CONFIRM: 02874 cb_log(4, stack->port, "MGMT: DELLAYER|CNF dinfo %x\n",frm->dinfo) ; 02875 free_msg(msg); 02876 return 1; 02877 02878 } 02879 02880 /* 02881 if ( (frm->prim & 0x0f0000) == 0x0f0000) { 02882 cb_log(5, 0, "$$$ MGMT FRAME: prim %x addr %x dinfo %x\n",frm->prim, frm->addr, frm->dinfo) ; 02883 free_msg(msg); 02884 return 1; 02885 } */ 02886 02887 return 0; 02888 }
static int handle_timers | ( | msg_t * | msg | ) | [static] |
Definition at line 2112 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().
02113 { 02114 iframe_t *frm= (iframe_t*)msg->data; 02115 struct misdn_stack *stack; 02116 02117 /* Timer Stuff */ 02118 switch (frm->prim) { 02119 case MGR_INITTIMER | CONFIRM: 02120 case MGR_ADDTIMER | CONFIRM: 02121 case MGR_DELTIMER | CONFIRM: 02122 case MGR_REMOVETIMER | CONFIRM: 02123 free_msg(msg); 02124 return(1); 02125 } 02126 02127 02128 02129 if (frm->prim==(MGR_TIMER | INDICATION) ) { 02130 for (stack = glob_mgr->stack_list; 02131 stack; 02132 stack = stack->next) { 02133 itimer_t *it; 02134 02135 if (!stack->nt) continue; 02136 02137 it = stack->nst.tlist; 02138 /* find timer */ 02139 for(it=stack->nst.tlist; 02140 it; 02141 it=it->next) { 02142 if (it->id == (int)frm->addr) 02143 break; 02144 } 02145 if (it) { 02146 int ret; 02147 ret = mISDN_write_frame(stack->midev, msg->data, frm->addr, 02148 MGR_TIMER | RESPONSE, 0, 0, NULL, TIMEOUT_1SEC); 02149 test_and_clear_bit(FLG_TIMER_RUNING, (long unsigned int *)&it->Flags); 02150 ret = it->function(it->data); 02151 free_msg(msg); 02152 return 1; 02153 } 02154 } 02155 02156 cb_log(0, 0, "Timer Msg without Timer ??\n"); 02157 free_msg(msg); 02158 return 1; 02159 } 02160 02161 return 0; 02162 }
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(), send_lock::lock, malloc, MISDN_IBUF_SIZE, misdn_bchannel::msn, misdn_stack::nt, misdn_bchannel::nt, misdn_stack::port, misdn_bchannel::port, pthread_mutex_init, and misdn_bchannel::send_lock.
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 bc->send_lock=malloc(sizeof(struct send_lock)); 01106 01107 pthread_mutex_init(&bc->send_lock->lock, NULL); 01108 01109 if (msn) { 01110 int l = sizeof(bc->msn); 01111 strncpy(bc->msn,msn, l); 01112 bc->msn[l-1] = 0; 01113 } 01114 01115 01116 empty_bc(bc); 01117 bc_state_change(bc, BCHAN_CLEANED); 01118 01119 bc->port=stack->port; 01120 bc->nt=stack->nt?1:0; 01121 01122 { 01123 ibuffer_t* ibuf= init_ibuffer(MISDN_IBUF_SIZE); 01124 01125 if (!ibuf) return -1; 01126 01127 clear_ibuffer( ibuf); 01128 01129 ibuf->rsem=malloc(sizeof(sem_t)); 01130 01131 bc->astbuf=ibuf; 01132 01133 if (sem_init(ibuf->rsem,1,0)<0) 01134 sem_init(ibuf->rsem,0,0); 01135 01136 } 01137 01138 01139 01140 01141 { 01142 stack_info_t *stinf; 01143 ret = mISDN_get_stack_info(midev, stack->port, buff, sizeof(buff)); 01144 if (ret < 0) { 01145 cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret); 01146 return -1; 01147 } 01148 01149 stinf = (stack_info_t *)&frm->data.p; 01150 01151 cb_log(8, port, " --> Child %x\n",stinf->child[bidx]); 01152 } 01153 01154 return 0; 01155 }
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 4141 of file isdn_lib.c.
References misdn_stack::bc, and manager_ph_control().
Referenced by process_ast_dsp().
04142 { 04143 manager_ph_control(bc, DTMF_TONE_STOP, 0); 04144 }
void isdn_lib_update_ec | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4129 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().
04130 { 04131 #ifdef MISDN_1_2 04132 if (*bc->pipeline) 04133 #else 04134 if (bc->ec_enable) 04135 #endif 04136 manager_ec_enable(bc); 04137 else 04138 manager_ec_disable(bc); 04139 }
void isdn_lib_update_rxgain | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4119 of file isdn_lib.c.
References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::rxgain.
Referenced by process_ast_dsp().
04120 { 04121 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 04122 }
void isdn_lib_update_txgain | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4124 of file isdn_lib.c.
References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::txgain.
Referenced by process_ast_dsp().
04125 { 04126 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 04127 }
void manager_bchannel_activate | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3999 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().
04000 { 04001 char buf[128]; 04002 04003 struct misdn_stack *stack=get_stack_by_bc(bc); 04004 04005 if (!stack) { 04006 cb_log(0, bc->port, "bchannel_activate: Stack not found !"); 04007 return ; 04008 } 04009 04010 /* we must activate if we are deactivated */ 04011 clear_ibuffer(bc->astbuf); 04012 04013 cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr); 04014 04015 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC); 04016 04017 return ; 04018 }
void manager_bchannel_cleanup | ( | struct misdn_bchannel * | bc | ) |
void manager_bchannel_deactivate | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4021 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().
04022 { 04023 04024 struct misdn_stack *stack=get_stack_by_bc(bc); 04025 04026 04027 switch (bc->bc_state) { 04028 case BCHAN_ACTIVATED: 04029 break; 04030 case BCHAN_BRIDGED: 04031 misdn_split_conf(bc,bc->conf_id); 04032 break; 04033 default: 04034 cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n"); 04035 return ; 04036 04037 } 04038 04039 cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr); 04040 04041 bc->generate_tone=0; 04042 04043 iframe_t dact; 04044 dact.prim = DL_RELEASE | REQUEST; 04045 dact.addr = bc->addr | FLG_MSG_DOWN; 04046 dact.dinfo = 0; 04047 dact.len = 0; 04048 char buf[128]; 04049 mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC); 04050 04051 clear_ibuffer(bc->astbuf); 04052 04053 bc_state_change(bc,BCHAN_RELEASE); 04054 04055 return; 04056 }
void manager_bchannel_setup | ( | struct misdn_bchannel * | bc | ) |
void manager_clean_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4168 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().
04169 { 04170 struct misdn_stack *stack=get_stack_by_bc(bc); 04171 04172 if (bc->channel>0) 04173 empty_chan_in_stack(stack, bc->channel); 04174 empty_bc(bc); 04175 04176 cb_event(EVENT_CLEANUP, bc, NULL); 04177 }
void manager_ec_disable | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4361 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().
04362 { 04363 struct misdn_stack *stack=get_stack_by_bc(bc); 04364 04365 cb_log(4, stack?stack->port:0," --> ec_disable\n"); 04366 04367 if (!misdn_cap_is_speech(bc->capability)) { 04368 cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n"); 04369 return; 04370 } 04371 04372 #ifdef MISDN_1_2 04373 manager_ph_control_block(bc, PIPELINE_CFG, "", 0); 04374 #else 04375 if ( ! bc->ec_enable) { 04376 cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n"); 04377 manager_ph_control(bc, ECHOCAN_OFF, 0); 04378 } 04379 #endif 04380 }
void manager_ec_enable | ( | struct misdn_bchannel * | bc | ) |
Definition at line 4312 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().
04313 { 04314 struct misdn_stack *stack=get_stack_by_bc(bc); 04315 04316 cb_log(4, stack?stack->port:0,"ec_enable\n"); 04317 04318 if (!misdn_cap_is_speech(bc->capability)) { 04319 cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n"); 04320 } else { 04321 04322 #ifdef MISDN_1_2 04323 if (*bc->pipeline) { 04324 cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline); 04325 manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1); 04326 } 04327 #else 04328 int ec_arr[2]; 04329 04330 if (bc->ec_enable) { 04331 cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps); 04332 04333 switch (bc->ec_deftaps) { 04334 case 4: 04335 case 8: 04336 case 16: 04337 case 32: 04338 case 64: 04339 case 128: 04340 case 256: 04341 case 512: 04342 case 1024: 04343 cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps); 04344 break; 04345 default: 04346 cb_log(0, stack->port, "Taps should be power of 2\n"); 04347 bc->ec_deftaps=128; 04348 } 04349 04350 ec_arr[0]=bc->ec_deftaps; 04351 ec_arr[1]=0; 04352 04353 manager_ph_control_block(bc, ECHOCAN_ON, ec_arr, sizeof(ec_arr)); 04354 } 04355 #endif 04356 } 04357 }
static void manager_event_handler | ( | void * | arg | ) | [static] |
Definition at line 3723 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.
03724 { 03725 sem_post(&handler_started); 03726 while (1) { 03727 struct misdn_stack *stack; 03728 msg_t *msg; 03729 03730 /** wait for events **/ 03731 sem_wait(&glob_mgr->new_msg); 03732 03733 for (msg=msg_dequeue(&glob_mgr->activatequeue); 03734 msg; 03735 msg=msg_dequeue(&glob_mgr->activatequeue) 03736 ) 03737 { 03738 03739 iframe_t *frm = (iframe_t*) msg->data ; 03740 03741 switch ( frm->prim) { 03742 03743 case MGR_CLEARSTACK | REQUEST: 03744 /*a queued bchannel cleanup*/ 03745 { 03746 struct misdn_stack *stack=find_stack_by_port(frm->dinfo); 03747 if (!stack) { 03748 cb_log(0,0,"no stack found with port [%d]!! so we cannot cleanup the bc\n",frm->dinfo); 03749 free_msg(msg); 03750 break; 03751 } 03752 03753 struct misdn_bchannel *bc=find_bc_by_l3id(stack,frm->addr); 03754 if (bc) { 03755 cb_log(1,bc->port,"CLEARSTACK queued, cleaning up\n"); 03756 clean_up_bc(bc); 03757 } else { 03758 cb_log(0,stack->port,"bc could not be cleaned correctly !! addr [%x]\n",frm->addr); 03759 } 03760 } 03761 free_msg(msg); 03762 break; 03763 case MGR_SETSTACK | REQUEST : 03764 break; 03765 default: 03766 mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); 03767 free_msg(msg); 03768 } 03769 } 03770 03771 for (stack=glob_mgr->stack_list; 03772 stack; 03773 stack=stack->next ) { 03774 03775 while ( (msg=msg_dequeue(&stack->upqueue)) ) { 03776 /** Handle L2/3 Signalling after bchans **/ 03777 if (!handle_frm_nt(msg)) { 03778 /* Maybe it's TE */ 03779 if (!handle_frm(msg)) { 03780 /* wow none! */ 03781 cb_log(0,stack->port,"Wow we've got a strange issue while dequeueing a Frame\n"); 03782 } 03783 } 03784 } 03785 03786 /* Here we should check if we really want to 03787 send all the messages we've queued, lets 03788 assume we've queued a Disconnect, but 03789 received it already from the other side!*/ 03790 03791 while ( (msg=msg_dequeue(&stack->downqueue)) ) { 03792 if (stack->nt ) { 03793 if (stack->nst.manager_l3(&stack->nst, msg)) 03794 cb_log(0, stack->port, "Error@ Sending Message in NT-Stack.\n"); 03795 03796 } else { 03797 iframe_t *frm = (iframe_t *)msg->data; 03798 struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo); 03799 if (bc) send_msg(glob_mgr->midev, bc, msg); 03800 else { 03801 if (frm->dinfo == MISDN_ID_GLOBAL) { 03802 struct misdn_bchannel dummybc; 03803 memset (&dummybc,0,sizeof(dummybc)); 03804 dummybc.port=stack->port; 03805 dummybc.l3_id=MISDN_ID_GLOBAL; 03806 dummybc.nt=stack->nt; 03807 send_msg(glob_mgr->midev, &dummybc, msg); 03808 } 03809 } 03810 } 03811 } 03812 } 03813 } 03814 }
struct misdn_bchannel * manager_find_bc_by_pid | ( | int | pid | ) |
Definition at line 3041 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().
03042 { 03043 struct misdn_stack *stack; 03044 int i; 03045 03046 for (stack=glob_mgr->stack_list; 03047 stack; 03048 stack=stack->next) { 03049 for (i=0; i<=stack->b_num; i++) 03050 if (stack->bc[i].pid == pid) return &stack->bc[i]; 03051 } 03052 03053 return NULL; 03054 }
struct misdn_bchannel * manager_find_bc_holded | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3056 of file isdn_lib.c.
References misdn_stack::bc, find_bc_holded(), and get_stack_by_bc().
03057 { 03058 struct misdn_stack *stack=get_stack_by_bc(bc); 03059 return find_bc_holded(stack); 03060 }
char* manager_isdn_get_info | ( | enum event_e | event | ) |
Definition at line 3994 of file isdn_lib.c.
References isdn_get_info(), and msgs_g.
Referenced by cb_events().
03995 { 03996 return isdn_get_info(msgs_g , event, 0); 03997 }
int manager_isdn_handler | ( | iframe_t * | frm, | |
msg_t * | msg | |||
) |
Definition at line 3538 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().
03539 { 03540 03541 if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) { 03542 cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n"); 03543 } 03544 03545 if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) { 03546 if (handle_bchan(msg)) { 03547 return 0 ; 03548 } 03549 } 03550 03551 #ifdef RECV_FRM_SYSLOG_DEBUG 03552 syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo); 03553 #endif 03554 03555 if (handle_timers(msg)) 03556 return 0 ; 03557 03558 03559 if (handle_mgmt(msg)) 03560 return 0 ; 03561 03562 if (handle_l2(msg)) 03563 return 0 ; 03564 03565 /* Its important to handle l1 AFTER l2 */ 03566 if (handle_l1(msg)) 03567 return 0 ; 03568 03569 if (handle_frm_nt(msg)) { 03570 return 0; 03571 } 03572 03573 if (handle_frm(msg)) { 03574 return 0; 03575 } 03576 03577 if (handle_err(msg)) { 03578 return 0 ; 03579 } 03580 03581 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); 03582 free_msg(msg); 03583 03584 03585 return 0; 03586 }
void manager_ph_control | ( | struct misdn_bchannel * | bc, | |
int | c1, | |||
int | c2 | |||
) |
Definition at line 4098 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().
04099 { 04100 unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)]; 04101 iframe_t *ctrl = (iframe_t *)buffer; /* preload data */ 04102 unsigned int *d = (unsigned int*)&ctrl->data.p; 04103 /*struct misdn_stack *stack=get_stack_by_bc(bc);*/ 04104 04105 cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2); 04106 04107 ctrl->prim = PH_CONTROL | REQUEST; 04108 ctrl->addr = bc->addr | FLG_MSG_DOWN; 04109 ctrl->dinfo = 0; 04110 ctrl->len = sizeof(unsigned int)*2; 04111 *d++ = c1; 04112 *d++ = c2; 04113 mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); 04114 }
void manager_ph_control_block | ( | struct misdn_bchannel * | bc, | |
int | c1, | |||
void * | c2, | |||
int | c2_len | |||
) |
Definition at line 4149 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().
04150 { 04151 unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len]; 04152 iframe_t *ctrl = (iframe_t *)buffer; 04153 unsigned int *d = (unsigned int *)&ctrl->data.p; 04154 /*struct misdn_stack *stack=get_stack_by_bc(bc);*/ 04155 04156 ctrl->prim = PH_CONTROL | REQUEST; 04157 ctrl->addr = bc->addr | FLG_MSG_DOWN; 04158 ctrl->dinfo = 0; 04159 ctrl->len = sizeof(unsigned int) + c2_len; 04160 *d++ = c1; 04161 memcpy(d, c2, c2_len); 04162 mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); 04163 }
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 4388 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().
04389 { 04390 bc_state_change(bc,BCHAN_BRIDGED); 04391 manager_ph_control(bc, CMX_RECEIVE_OFF, 0); 04392 manager_ph_control(bc, CMX_CONF_JOIN, conf_id); 04393 04394 cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id); 04395 04396 char data[16]; 04397 int len=15; 04398 04399 memset(data,0,15); 04400 04401 misdn_lib_tx2misdn_frm(bc, data, len); 04402 04403 }
void misdn_lib_bridge | ( | struct misdn_bchannel * | bc1, | |
struct misdn_bchannel * | bc2 | |||
) |
Definition at line 4415 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().
04415 { 04416 int conf_id=bc1->pid +1; 04417 04418 cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port); 04419 04420 struct misdn_bchannel *bc_list[]={ 04421 bc1,bc2,NULL 04422 }; 04423 struct misdn_bchannel **bc; 04424 04425 for (bc=bc_list; *bc; bc++) { 04426 (*bc)->conf_id=conf_id; 04427 cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr); 04428 04429 switch((*bc)->bc_state) { 04430 case BCHAN_ACTIVATED: 04431 misdn_join_conf(*bc,conf_id); 04432 break; 04433 default: 04434 bc_next_state_change(*bc,BCHAN_BRIDGED); 04435 break; 04436 } 04437 } 04438 }
void misdn_lib_destroy | ( | void | ) |
Definition at line 3961 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().
03962 { 03963 struct misdn_stack *help; 03964 int i; 03965 03966 for ( help=glob_mgr->stack_list; help; help=help->next ) { 03967 for(i=0;i<=help->b_num; i++) { 03968 char buf[1024]; 03969 mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 03970 help->bc[i].addr = 0; 03971 } 03972 cb_log (1, help->port, "Destroying this port.\n"); 03973 stack_destroy(help); 03974 } 03975 03976 if (global_state == MISDN_INITIALIZED) { 03977 cb_log(4, 0, "Killing Handler Thread\n"); 03978 if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) { 03979 cb_log(4, 0, "Joining Handler Thread\n"); 03980 pthread_join(glob_mgr->event_handler_thread, NULL); 03981 } 03982 03983 cb_log(4, 0, "Killing Main Thread\n"); 03984 if ( pthread_cancel(glob_mgr->event_thread) == 0 ) { 03985 cb_log(4, 0, "Joining Main Thread\n"); 03986 pthread_join(glob_mgr->event_thread, NULL); 03987 } 03988 } 03989 03990 cb_log(1, 0, "Closing mISDN device\n"); 03991 te_lib_destroy(glob_mgr->midev); 03992 }
void misdn_lib_echo | ( | struct misdn_bchannel * | bc, | |
int | onoff | |||
) |
Definition at line 4460 of file isdn_lib.c.
References cb_log, manager_ph_control(), and misdn_bchannel::port.
04461 { 04462 cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF"); 04463 manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0); 04464 }
struct misdn_bchannel* misdn_lib_get_free_bc | ( | int | port, | |
int | channel, | |||
int | inout, | |||
int | dec | |||
) |
Definition at line 3084 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().
03085 { 03086 struct misdn_stack *stack; 03087 int i; 03088 03089 if (channel < 0 || channel > MAX_BCHANS) { 03090 cb_log(0,port,"Requested channel out of bounds (%d)\n",channel); 03091 return NULL; 03092 } 03093 03094 for (stack=glob_mgr->stack_list; stack; stack=stack->next) { 03095 03096 if (stack->port == port) { 03097 if (stack->blocked) { 03098 cb_log(0,port,"Port is blocked\n"); 03099 return NULL; 03100 } 03101 03102 if (channel > 0) { 03103 if (channel <= stack->b_num) { 03104 for (i = 0; i < stack->b_num; i++) { 03105 if (stack->bc[i].in_use && stack->bc[i].channel == channel) { 03106 cb_log(0,port,"Requested channel:%d on port:%d is already in use\n",channel, port); 03107 return NULL; 03108 } 03109 } 03110 } else { 03111 cb_log(0,port,"Requested channel:%d is out of bounds on port:%d\n",channel, port); 03112 return NULL; 03113 } 03114 } 03115 03116 int maxnum=inout&&!stack->pri&&!stack->ptp?stack->b_num+1:stack->b_num; 03117 03118 if (dec) { 03119 for (i = maxnum-1; i>=0; i--) { 03120 if (!stack->bc[i].in_use) { 03121 /* 3. channel on bri means CW*/ 03122 if (!stack->pri && i==stack->b_num) 03123 stack->bc[i].cw=1; 03124 03125 prepare_bc(&stack->bc[i], channel); 03126 stack->bc[i].dec=1; 03127 return &stack->bc[i]; 03128 } 03129 } 03130 } else { 03131 for (i = 0; i <maxnum; i++) { 03132 if (!stack->bc[i].in_use) { 03133 /* 3. channel on bri means CW*/ 03134 if (!stack->pri && i==stack->b_num) 03135 stack->bc[i].cw=1; 03136 03137 prepare_bc(&stack->bc[i], channel); 03138 return &stack->bc[i]; 03139 } 03140 } 03141 } 03142 03143 cb_log(1,port,"There is no free channel on port (%d)\n",port); 03144 return NULL; 03145 } 03146 } 03147 03148 cb_log(0,port,"Port is not configured (%d)\n",port); 03149 return NULL; 03150 }
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 1682 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().
01683 { /* Pull Down L1 */ 01684 struct misdn_stack *stack; 01685 for (stack=glob_mgr->stack_list; 01686 stack; 01687 stack=stack->next) { 01688 if (stack->port == port) { 01689 if (stack->l2link) 01690 misdn_lib_get_l2_down(stack); 01691 misdn_lib_get_l1_down(stack); 01692 return 0; 01693 } 01694 } 01695 return 0; 01696 }
int misdn_lib_get_port_info | ( | int | port | ) |
Definition at line 3591 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.
03592 { 03593 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03594 iframe_t *frm; 03595 struct misdn_stack *stack=find_stack_by_port(port); 03596 if (!msg) { 03597 cb_log(0, port, "misgn_lib_get_port: alloc_msg failed!\n"); 03598 return -1; 03599 } 03600 frm=(iframe_t*)msg->data; 03601 if (!stack ) { 03602 cb_log(0, port, "There is no Stack for this port.\n"); 03603 return -1; 03604 } 03605 /* activate bchannel */ 03606 frm->prim = CC_STATUS_ENQUIRY | REQUEST; 03607 03608 frm->addr = stack->upper_id| FLG_MSG_DOWN; 03609 03610 frm->dinfo = 0; 03611 frm->len = 0; 03612 03613 msg_queue_tail(&glob_mgr->activatequeue, msg); 03614 sem_post(&glob_mgr->new_msg); 03615 03616 03617 return 0; 03618 }
int misdn_lib_get_port_up | ( | int | port | ) |
Definition at line 1660 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_check_l2l1(), and misdn_port_up().
01661 { /* Pull Up L1 */ 01662 struct misdn_stack *stack; 01663 01664 for (stack=glob_mgr->stack_list; 01665 stack; 01666 stack=stack->next) { 01667 01668 if (stack->port == port) { 01669 01670 if (!stack->l1link) 01671 misdn_lib_get_l1_up(stack); 01672 if (!stack->l2link) 01673 misdn_lib_get_l2_up(stack); 01674 01675 return 0; 01676 } 01677 } 01678 return 0; 01679 }
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 3853 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().
03854 { 03855 struct misdn_lib *mgr=calloc(1, sizeof(struct misdn_lib)); 03856 char *tok, *tokb; 03857 char plist[1024]; 03858 int midev; 03859 int port_count=0; 03860 03861 cb_log = iface->cb_log; 03862 cb_event = iface->cb_event; 03863 cb_jb_empty = iface->cb_jb_empty; 03864 03865 glob_mgr = mgr; 03866 03867 msg_init(); 03868 03869 misdn_lib_nt_debug_init(0,NULL); 03870 03871 if (!portlist || (*portlist == 0) ) return 1; 03872 03873 init_flip_bits(); 03874 03875 { 03876 strncpy(plist,portlist, 1024); 03877 plist[1023] = 0; 03878 } 03879 03880 memcpy(tone_425_flip,tone_425,TONE_425_SIZE); 03881 flip_buf_bits(tone_425_flip,TONE_425_SIZE); 03882 03883 memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE); 03884 flip_buf_bits(tone_silence_flip,TONE_SILENCE_SIZE); 03885 03886 midev=te_lib_init(); 03887 mgr->midev=midev; 03888 03889 port_count=mISDN_get_stack_count(midev); 03890 03891 msg_queue_init(&mgr->activatequeue); 03892 03893 if (sem_init(&mgr->new_msg, 1, 0)<0) 03894 sem_init(&mgr->new_msg, 0, 0); 03895 03896 for (tok=strtok_r(plist," ,",&tokb ); 03897 tok; 03898 tok=strtok_r(NULL," ,",&tokb)) { 03899 int port = atoi(tok); 03900 struct misdn_stack *stack; 03901 static int first=1; 03902 int ptp=0; 03903 03904 if (strstr(tok, "ptp")) 03905 ptp=1; 03906 03907 if (port > port_count) { 03908 cb_log(0, port, "Couldn't Initialize this port since we have only %d ports\n", port_count); 03909 exit(1); 03910 } 03911 stack=stack_init(midev, port, ptp); 03912 03913 if (!stack) { 03914 perror("init_stack"); 03915 exit(1); 03916 } 03917 03918 { 03919 int i; 03920 for(i=0;i<=stack->b_num; i++) { 03921 int r; 03922 if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) { 03923 cb_log(0, port, "Got Err @ init_bc :%d\n",r); 03924 exit(1); 03925 } 03926 } 03927 } 03928 03929 if (stack && first) { 03930 mgr->stack_list=stack; 03931 first=0; 03932 continue; 03933 } 03934 03935 if (stack) { 03936 struct misdn_stack * help; 03937 for ( help=mgr->stack_list; help; help=help->next ) 03938 if (help->next == NULL) break; 03939 help->next=stack; 03940 } 03941 03942 } 03943 03944 if (sem_init(&handler_started, 1, 0)<0) 03945 sem_init(&handler_started, 0, 0); 03946 03947 cb_log(8, 0, "Starting Event Handler\n"); 03948 pthread_create( &mgr->event_handler_thread, NULL,(void*)manager_event_handler, mgr); 03949 03950 sem_wait(&handler_started) ; 03951 cb_log(8, 0, "Starting Event Catcher\n"); 03952 pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr); 03953 03954 cb_log(8, 0, "Event Catcher started\n"); 03955 03956 global_state= MISDN_INITIALIZED; 03957 03958 return (mgr == NULL); 03959 }
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 2947 of file isdn_lib.c.
References cb_log, fetch_msg(), manager_isdn_handler(), and misdn_lib::midev.
02948 { 02949 struct misdn_lib *mgr = arg; 02950 int zero_frm=0 , fff_frm=0 ; 02951 int midev= mgr->midev; 02952 int port=0; 02953 02954 while (1) { 02955 msg_t *msg = fetch_msg(midev); 02956 iframe_t *frm; 02957 02958 02959 if (!msg) continue; 02960 02961 frm = (iframe_t*) msg->data; 02962 02963 /** When we make a call from NT2Ast we get this frames **/ 02964 if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) { 02965 zero_frm++; 02966 free_msg(msg); 02967 continue; 02968 } else { 02969 if (zero_frm) { 02970 cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm); 02971 zero_frm = 0 ; 02972 } 02973 } 02974 02975 /** I get this sometimes after setup_bc **/ 02976 if (frm->len == 0 && frm->dinfo == 0 && frm->prim == 0xffffffff ) { 02977 fff_frm++; 02978 free_msg(msg); 02979 continue; 02980 } else { 02981 if (fff_frm) { 02982 cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm); 02983 fff_frm = 0 ; 02984 } 02985 } 02986 02987 manager_isdn_handler(frm, msg); 02988 } 02989 02990 }
void misdn_lib_isdn_l1watcher | ( | int | port | ) |
Definition at line 2929 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().
02930 { 02931 struct misdn_stack *stack; 02932 02933 for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next) 02934 ; 02935 02936 if (stack) { 02937 cb_log(4, port, "Checking L1 State\n"); 02938 if (!stack->l1link) { 02939 cb_log(4, port, "L1 State Down, trying to get it up again\n"); 02940 misdn_lib_get_short_status(stack); 02941 misdn_lib_get_l1_up(stack); 02942 misdn_lib_get_l2_up(stack); 02943 } 02944 } 02945 }
void misdn_lib_log_ies | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3171 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().
03172 { 03173 if (!bc) return; 03174 03175 struct misdn_stack *stack=get_stack_by_bc(bc); 03176 03177 if (!stack) return; 03178 03179 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); 03180 03181 cb_log(2, stack->port, 03182 " --> info_dad:%s onumplan:%c dnumplan:%c rnumplan:%c cpnnumplan:%c\n", 03183 bc->info_dad, 03184 bc->onumplan>=0?'0'+bc->onumplan:' ', 03185 bc->dnumplan>=0?'0'+bc->dnumplan:' ', 03186 bc->rnumplan>=0?'0'+bc->rnumplan:' ', 03187 bc->cpnnumplan>=0?'0'+bc->cpnnumplan:' ' 03188 ); 03189 03190 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); 03191 cb_log(4, stack->port, " --> screen:%d --> pres:%d\n", 03192 bc->screen, bc->pres); 03193 03194 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); 03195 03196 cb_log(4, stack->port, " --> facility:%s out_facility:%s\n",fac2str(bc->fac_in.Function),fac2str(bc->fac_out.Function)); 03197 03198 cb_log(5, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1); 03199 03200 cb_log(5, stack->port, " --> bc:%x h:%d sh:%d\n", bc, bc->holded, bc->stack_holder); 03201 }
int misdn_lib_maxports_get | ( | void | ) |
Definition at line 3817 of file isdn_lib.c.
Referenced by load_module().
03817 { /** BE AWARE WE HAVE NO CB_LOG HERE! **/ 03818 03819 int i = mISDN_open(); 03820 int max=0; 03821 03822 if (i<0) 03823 return -1; 03824 03825 max = mISDN_get_stack_count(i); 03826 03827 mISDN_close(i); 03828 03829 return max; 03830 }
void misdn_lib_nt_debug_init | ( | int | flags, | |
char * | file | |||
) |
Definition at line 3833 of file isdn_lib.c.
References f.
Referenced by load_module(), and misdn_lib_init().
03834 { 03835 int static init=0; 03836 char *f; 03837 03838 if (!flags) 03839 f=NULL; 03840 else 03841 f=file; 03842 03843 if (!init) { 03844 debug_init( flags , f, f, f); 03845 init=1; 03846 } else { 03847 debug_close(); 03848 debug_init( flags , f, f, f); 03849 } 03850 }
int misdn_lib_pid_restart | ( | int | pid | ) |
Definition at line 3646 of file isdn_lib.c.
References manager_clean_bc(), and manager_find_bc_by_pid().
Referenced by misdn_restart_pid().
03647 { 03648 struct misdn_bchannel *bc=manager_find_bc_by_pid(pid); 03649 03650 if (bc) { 03651 manager_clean_bc(bc); 03652 } 03653 return 0; 03654 }
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 3681 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().
03682 { 03683 struct misdn_stack *stack=find_stack_by_port(port); 03684 03685 cb_log(0, port, "Restarting this port.\n"); 03686 if (stack) { 03687 cb_log(0, port, "Stack:%p\n",stack); 03688 03689 clear_l3(stack); 03690 { 03691 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03692 iframe_t *frm; 03693 03694 if (!msg) { 03695 cb_log(0, port, "port_restart: alloc_msg failed\n"); 03696 return -1; 03697 } 03698 03699 frm=(iframe_t*)msg->data; 03700 /* we must activate if we are deactivated */ 03701 /* activate bchannel */ 03702 frm->prim = DL_RELEASE | REQUEST; 03703 frm->addr = stack->upper_id | FLG_MSG_DOWN; 03704 03705 frm->dinfo = 0; 03706 frm->len = 0; 03707 msg_queue_tail(&glob_mgr->activatequeue, msg); 03708 sem_post(&glob_mgr->new_msg); 03709 } 03710 03711 if (stack->nt) 03712 misdn_lib_reinit_nt_stack(stack->port); 03713 03714 } 03715 03716 return 0; 03717 }
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 1698 of file isdn_lib.c.
References misdn_stack::blocked, cb_log, glob_mgr, misdn_stack::l1link, misdn_stack::l2link, misdn_stack::next, misdn_stack::port, misdn_stack::ptp, and misdn_lib::stack_list.
Referenced by misdn_check_l2l1(), and misdn_request().
01699 { 01700 struct misdn_stack *stack; 01701 01702 01703 for (stack=glob_mgr->stack_list; 01704 stack; 01705 stack=stack->next) { 01706 01707 if (stack->port == port) { 01708 01709 if (stack->blocked) { 01710 cb_log(0,port, "Port Blocked:%d L2:%d L1:%d\n", stack->blocked, stack->l2link, stack->l1link); 01711 return -1; 01712 } 01713 01714 if (stack->ptp ) { 01715 01716 if (stack->l1link && stack->l2link) { 01717 return 1; 01718 } else { 01719 cb_log(1,port, "Port Down L2:%d L1:%d\n", 01720 stack->l2link, stack->l1link); 01721 return 0; 01722 } 01723 } else { 01724 if ( !check || stack->l1link ) 01725 return 1; 01726 else { 01727 cb_log(1,port, "Port down PMP\n"); 01728 return 0; 01729 } 01730 } 01731 } 01732 } 01733 01734 return -1; 01735 }
void misdn_lib_reinit_nt_stack | ( | int | port | ) |
Definition at line 4468 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().
04469 { 04470 struct misdn_stack *stack=find_stack_by_port(port); 04471 04472 if (stack) { 04473 stack->l2link=0; 04474 stack->blocked=0; 04475 04476 cleanup_Isdnl3(&stack->nst); 04477 cleanup_Isdnl2(&stack->nst); 04478 04479 04480 memset(&stack->nst, 0, sizeof(net_stack_t)); 04481 memset(&stack->mgr, 0, sizeof(manager_t)); 04482 04483 stack->mgr.nst = &stack->nst; 04484 stack->nst.manager = &stack->mgr; 04485 04486 stack->nst.l3_manager = handle_event_nt; 04487 stack->nst.device = glob_mgr->midev; 04488 stack->nst.cardnr = port; 04489 stack->nst.d_stid = stack->d_stid; 04490 04491 stack->nst.feature = FEATURE_NET_HOLD; 04492 if (stack->ptp) 04493 stack->nst.feature |= FEATURE_NET_PTP; 04494 if (stack->pri) 04495 stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID; 04496 04497 stack->nst.l1_id = stack->lower_id; 04498 stack->nst.l2_id = stack->upper_id; 04499 04500 msg_queue_init(&stack->nst.down_queue); 04501 04502 Isdnl2Init(&stack->nst); 04503 Isdnl3Init(&stack->nst); 04504 04505 if (!stack->ptp) 04506 misdn_lib_get_l1_up(stack); 04507 misdn_lib_get_l2_up(stack); 04508 } 04509 }
void misdn_lib_release | ( | struct misdn_bchannel * | bc | ) |
Definition at line 1641 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().
01642 { 01643 struct misdn_stack *stack=get_stack_by_bc(bc); 01644 01645 if (!stack) { 01646 cb_log(1,0,"misdn_release: No Stack found\n"); 01647 return; 01648 } 01649 01650 if (bc->channel>0) { 01651 empty_chan_in_stack(stack,bc->channel); 01652 } 01653 empty_bc(bc); 01654 clean_up_bc(bc); 01655 }
int misdn_lib_send_event | ( | struct misdn_bchannel * | bc, | |
enum event_e | event | |||
) |
Definition at line 3220 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_send_lock(), misdn_send_unlock(), 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, RETURN, 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().
03221 { 03222 msg_t *msg; 03223 int retval=0; 03224 03225 if (!bc) RETURN(-1,OUT_POST_UNLOCK); 03226 03227 struct misdn_stack *stack=get_stack_by_bc(bc); 03228 03229 if (!stack) { 03230 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); 03231 RETURN(-1,OUT); 03232 } 03233 03234 misdn_send_lock(bc); 03235 03236 03237 cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->uperid:%x\n",stack->nt, stack->upper_id); 03238 03239 if ( stack->nt && !stack->l1link) { 03240 /** Queue Event **/ 03241 bc->evq=event; 03242 cb_log(1, stack->port, "Queueing Event %s because L1 is down (btw. Activating L1)\n", isdn_get_info(msgs_g, event, 0)); 03243 misdn_lib_get_l1_up(stack); 03244 RETURN(0,OUT); 03245 } 03246 03247 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); 03248 cb_log(4, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state)); 03249 misdn_lib_log_ies(bc); 03250 03251 switch (event) { 03252 case EVENT_SETUP: 03253 if (create_process(glob_mgr->midev, bc)<0) { 03254 cb_log(0, stack->port, " No free channel at the moment @ send_event\n"); 03255 03256 RETURN(-ENOCHAN,OUT); 03257 } 03258 #if 0 03259 if (stack->nt) { 03260 ret=setup_bc(bc); 03261 if (ret == -EINVAL) { 03262 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03263 } 03264 } 03265 #endif 03266 break; 03267 03268 case EVENT_PROGRESS: 03269 case EVENT_ALERTING: 03270 case EVENT_PROCEEDING: 03271 case EVENT_SETUP_ACKNOWLEDGE: 03272 case EVENT_CONNECT: 03273 case EVENT_RETRIEVE_ACKNOWLEDGE: 03274 03275 if (stack->nt) { 03276 if (bc->channel <=0 ) { /* else we have the channel already */ 03277 if (!find_free_chan_in_stack(stack, bc, 0,0)) { 03278 cb_log(0, stack->port, " No free channel at the moment\n"); 03279 /*FIXME: add disconnect*/ 03280 RETURN(-ENOCHAN,OUT); 03281 } 03282 03283 if (set_chan_in_stack(stack ,bc->channel)<0) { 03284 /*FIXME: add disconnect*/ 03285 RETURN(-ENOCHAN,OUT); 03286 } 03287 } 03288 /* Its that i generate channels */ 03289 } 03290 03291 retval=setup_bc(bc); 03292 if (retval == -EINVAL) { 03293 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03294 } 03295 03296 if (misdn_cap_is_speech(bc->capability)) { 03297 if ((event==EVENT_CONNECT)||(event==EVENT_RETRIEVE_ACKNOWLEDGE)) { 03298 if ( *bc->crypt_key ) { 03299 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); 03300 03301 manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); 03302 } 03303 03304 if (!bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0); 03305 manager_ec_enable(bc); 03306 03307 if (bc->txgain != 0) { 03308 cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); 03309 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 03310 } 03311 03312 if ( bc->rxgain != 0 ) { 03313 cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); 03314 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 03315 } 03316 } 03317 } 03318 break; 03319 03320 case EVENT_HOLD_ACKNOWLEDGE: 03321 { 03322 struct misdn_bchannel *holded_bc=malloc(sizeof(struct misdn_bchannel)); 03323 if (!holded_bc) { 03324 cb_log(0,bc->port, "Could not allocate holded_bc!!!\n"); 03325 RETURN(-1,OUT); 03326 } 03327 03328 /*backup the bc*/ 03329 memcpy(holded_bc,bc,sizeof(struct misdn_bchannel)); 03330 holded_bc->holded=1; 03331 bc_state_change(holded_bc,BCHAN_CLEANED); 03332 03333 stack_holder_add(stack,holded_bc); 03334 03335 /*kill the bridge and clean the bchannel*/ 03336 if (stack->nt) { 03337 if (bc->bc_state == BCHAN_BRIDGED) { 03338 misdn_split_conf(bc,bc->conf_id); 03339 struct misdn_bchannel *bc2=find_bc_by_confid(bc->conf_id); 03340 if (!bc2) { 03341 cb_log(0,bc->port,"We have no second bc in bridge???\n"); 03342 } else { 03343 misdn_split_conf(bc2,bc->conf_id); 03344 } 03345 } 03346 03347 if (bc->channel>0) 03348 empty_chan_in_stack(stack,bc->channel); 03349 empty_bc(bc); 03350 clean_up_bc(bc); 03351 } 03352 03353 } 03354 break; 03355 03356 /* finishing the channel eh ? */ 03357 case EVENT_DISCONNECT: 03358 if (!bc->need_disconnect) { 03359 cb_log(0,bc->port," --> we have already send Disconnect\n"); 03360 RETURN(-1,OUT); 03361 } 03362 03363 bc->need_disconnect=0; 03364 break; 03365 case EVENT_RELEASE: 03366 if (!bc->need_release) { 03367 cb_log(0,bc->port," --> we have already send Release\n"); 03368 RETURN(-1,OUT); 03369 } 03370 bc->need_disconnect=0; 03371 bc->need_release=0; 03372 break; 03373 case EVENT_RELEASE_COMPLETE: 03374 if (!bc->need_release_complete) { 03375 cb_log(0,bc->port," --> we have already send Release_complete\n"); 03376 RETURN(-1,OUT); 03377 } 03378 bc->need_disconnect=0; 03379 bc->need_release=0; 03380 bc->need_release_complete=0; 03381 03382 if (!stack->nt) { 03383 /*create clenaup in TE*/ 03384 if (bc->channel>0) 03385 empty_chan_in_stack(stack,bc->channel); 03386 int tmpcause=bc->cause; 03387 int tmp_out_cause=bc->out_cause; 03388 empty_bc(bc); 03389 bc->cause=tmpcause; 03390 bc->out_cause=tmp_out_cause; 03391 clean_up_bc(bc); 03392 } 03393 break; 03394 03395 case EVENT_CONNECT_ACKNOWLEDGE: 03396 03397 if ( bc->nt || misdn_cap_is_speech(bc->capability)) { 03398 int retval=setup_bc(bc); 03399 if (retval == -EINVAL){ 03400 cb_log(0,bc->port,"send_event: setup_bc failed\n"); 03401 03402 } 03403 } 03404 03405 if (misdn_cap_is_speech(bc->capability)) { 03406 if ( !bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0); 03407 manager_ec_enable(bc); 03408 03409 if ( bc->txgain != 0 ) { 03410 cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); 03411 manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); 03412 } 03413 if ( bc->rxgain != 0 ) { 03414 cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); 03415 manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); 03416 } 03417 } 03418 break; 03419 03420 default: 03421 break; 03422 } 03423 03424 /* Later we should think about sending bchannel data directly to misdn. */ 03425 msg = isdn_msg_build_event(msgs_g, bc, event, stack->nt); 03426 msg_queue_tail(&stack->downqueue, msg); 03427 sem_post(&glob_mgr->new_msg); 03428 03429 OUT: 03430 misdn_send_unlock(bc); 03431 03432 OUT_POST_UNLOCK: 03433 return retval; 03434 }
int misdn_lib_send_restart | ( | int | port | ) |
Definition at line 3657 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().
03658 { 03659 struct misdn_stack *stack=find_stack_by_port(port); 03660 cb_log(0, port, "Sending Restarts on this port.\n"); 03661 03662 struct misdn_bchannel dummybc; 03663 memset (&dummybc,0,sizeof(dummybc)); 03664 dummybc.port=stack->port; 03665 dummybc.l3_id=MISDN_ID_GLOBAL; 03666 dummybc.nt=stack->nt; 03667 03668 int max=stack->pri?30:2; 03669 int i; 03670 for (i=1;i<=max;i++) { 03671 dummybc.channel=i; 03672 cb_log(0, port, "Restarting channel %d\n",i); 03673 misdn_lib_send_event(&dummybc, EVENT_RESTART); 03674 /*do we need to wait before we get an EVENT_RESTART_ACK ?*/ 03675 } 03676 03677 return 0; 03678 }
void misdn_lib_send_tone | ( | struct misdn_bchannel * | bc, | |
enum tone_e | tone | |||
) |
Definition at line 4278 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().
04279 { 04280 04281 switch(tone) { 04282 case TONE_DIAL: 04283 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE); 04284 break; 04285 04286 case TONE_ALERTING: 04287 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_RINGING); 04288 break; 04289 04290 case TONE_HANGUP: 04291 manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_HANGUP); 04292 break; 04293 04294 case TONE_NONE: 04295 default: 04296 manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP); 04297 } 04298 04299 char buf[mISDN_HEADER_LEN+128]; 04300 iframe_t *frm=(iframe_t*)buf; 04301 memset(buf,0,mISDN_HEADER_LEN+128); 04302 04303 frm->prim=DL_DATA|REQUEST; 04304 frm->addr=bc->addr|FLG_MSG_DOWN; 04305 frm->dinfo=0; 04306 frm->len=128; 04307 04308 mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); 04309 }
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 4440 of file isdn_lib.c.
References bc_state2str(), BCHAN_BRIDGED, cb_log, misdn_bchannel::conf_id, and misdn_split_conf().
Referenced by misdn_bridge().
04441 { 04442 04443 struct misdn_bchannel *bc_list[]={ 04444 bc1,bc2,NULL 04445 }; 04446 struct misdn_bchannel **bc; 04447 04448 for (bc=bc_list; *bc; bc++) { 04449 if ( (*bc)->bc_state == BCHAN_BRIDGED){ 04450 misdn_split_conf( *bc, (*bc)->conf_id); 04451 } else { 04452 cb_log( 2, (*bc)->port, "BC not bridged (state:%s) so not splitting it\n",bc_state2str((*bc)->bc_state)); 04453 } 04454 } 04455 04456 }
void misdn_lib_tone_generator_start | ( | struct misdn_bchannel * | bc | ) |
Definition at line 2166 of file isdn_lib.c.
References misdn_bchannel::generate_tone.
Referenced by dialtone_indicate().
02167 { 02168 bc->generate_tone=1; 02169 }
void misdn_lib_tone_generator_stop | ( | struct misdn_bchannel * | bc | ) |
Definition at line 2171 of file isdn_lib.c.
References misdn_bchannel::generate_tone.
Referenced by start_bc_tones(), and stop_indicate().
02172 { 02173 bc->generate_tone=0; 02174 }
void misdn_lib_transfer | ( | struct misdn_bchannel * | holded_bc | ) |
Definition at line 3036 of file isdn_lib.c.
References misdn_bchannel::holded.
03037 { 03038 holded_bc->holded=0; 03039 }
int misdn_lib_tx2misdn_frm | ( | struct misdn_bchannel * | bc, | |
void * | data, | |||
int | len | |||
) |
Definition at line 4059 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().
04060 { 04061 struct misdn_stack *stack=get_stack_by_bc(bc); 04062 04063 switch (bc->bc_state) { 04064 case BCHAN_ACTIVATED: 04065 case BCHAN_BRIDGED: 04066 break; 04067 default: 04068 cb_log(3, bc->port, "BC not yet activated (state:%s)\n",bc_state2str(bc->bc_state)); 04069 return -1; 04070 } 04071 04072 char buf[4096 + mISDN_HEADER_LEN]; 04073 iframe_t *frm= (iframe_t*)buf; 04074 int r; 04075 04076 frm->prim = DL_DATA|REQUEST; 04077 frm->dinfo = 0; 04078 frm->addr = bc->addr | FLG_MSG_DOWN ; 04079 04080 frm->len = len; 04081 memcpy(&buf[mISDN_HEADER_LEN], data,len); 04082 04083 if ( misdn_cap_is_speech(bc->capability) ) 04084 flip_buf_bits( &buf[mISDN_HEADER_LEN], len); 04085 else 04086 cb_log(6, stack->port, "Writing %d data bytes\n",len); 04087 04088 cb_log(9, stack->port, "Writing %d bytes 2 mISDN\n",len); 04089 r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT); 04090 return 0; 04091 }
void misdn_send_lock | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3208 of file isdn_lib.c.
References misdn_stack::bc, send_lock::lock, pthread_mutex_lock, and misdn_bchannel::send_lock.
Referenced by misdn_lib_send_event().
03209 { 03210 //cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid); 03211 pthread_mutex_lock(&bc->send_lock->lock); 03212 }
void misdn_send_unlock | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3214 of file isdn_lib.c.
References misdn_stack::bc, send_lock::lock, pthread_mutex_unlock, and misdn_bchannel::send_lock.
Referenced by misdn_lib_send_event().
03215 { 03216 //cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid); 03217 pthread_mutex_unlock(&bc->send_lock->lock); 03218 }
void misdn_split_conf | ( | struct misdn_bchannel * | bc, | |
int | conf_id | |||
) |
Definition at line 4406 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().
04407 { 04408 bc_state_change(bc,BCHAN_ACTIVATED); 04409 manager_ph_control(bc, CMX_RECEIVE_ON, 0); 04410 manager_ph_control(bc, CMX_CONF_SPLIT, conf_id); 04411 04412 cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id); 04413 }
void misdn_tx_jitter | ( | struct misdn_bchannel * | bc, | |
int | len | |||
) |
Definition at line 2220 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().
02221 { 02222 char buf[4096 + mISDN_HEADER_LEN]; 02223 char *data=&buf[mISDN_HEADER_LEN]; 02224 iframe_t *txfrm= (iframe_t*)buf; 02225 int jlen, r; 02226 02227 jlen=cb_jb_empty(bc,data,len); 02228 02229 if (jlen) { 02230 #ifdef MISDN_SAVE_DATA 02231 misdn_save_data((bc->port*100+bc->channel), data, jlen, bc->bframe, bc->bframe_len); 02232 #endif 02233 flip_buf_bits( data, jlen); 02234 02235 if (jlen < len) { 02236 cb_log(7,bc->port,"Jitterbuffer Underrun.\n"); 02237 } 02238 02239 txfrm->prim = DL_DATA|REQUEST; 02240 02241 txfrm->dinfo = 0; 02242 02243 txfrm->addr = bc->addr|FLG_MSG_DOWN; /* | IF_DOWN; */ 02244 02245 txfrm->len =jlen; 02246 cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len); 02247 02248 r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); 02249 } else { 02250 #define MISDN_GEN_SILENCE 02251 #ifdef MISDN_GEN_SILENCE 02252 int cnt=len/TONE_SILENCE_SIZE; 02253 int rest=len%TONE_SILENCE_SIZE; 02254 int i; 02255 02256 for (i=0; i<cnt; i++) { 02257 memcpy(data, tone_silence_flip, TONE_SILENCE_SIZE ); 02258 data +=TONE_SILENCE_SIZE; 02259 } 02260 02261 if (rest) { 02262 memcpy(data, tone_silence_flip, rest); 02263 } 02264 02265 txfrm->prim = DL_DATA|REQUEST; 02266 02267 txfrm->dinfo = 0; 02268 02269 txfrm->addr = bc->addr|FLG_MSG_DOWN; /* | IF_DOWN; */ 02270 02271 txfrm->len =len; 02272 cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len); 02273 02274 r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); 02275 #endif 02276 02277 } 02278 }
static void prepare_bc | ( | struct misdn_bchannel * | bc, | |
int | channel | |||
) | [static] |
Definition at line 3064 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().
03065 { 03066 bc->channel = channel; 03067 bc->channel_preselected = channel?1:0; 03068 bc->in_use = 1; 03069 bc->need_disconnect=1; 03070 bc->need_release=1; 03071 bc->need_release_complete=1; 03072 bc->cause=16; 03073 03074 if (++mypid>5000) mypid=1; 03075 bc->pid=mypid; 03076 03077 #if 0 03078 bc->addr=0; 03079 bc->b_stid=0; 03080 bc->layer_id=0; 03081 #endif 03082 }
int queue_cleanup_bc | ( | struct misdn_bchannel * | bc | ) |
Definition at line 3621 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.
03622 { 03623 msg_t *msg=alloc_msg(MAX_MSG_SIZE); 03624 iframe_t *frm; 03625 if (!msg) { 03626 cb_log(0, bc->port, "misgn_lib_get_port: alloc_msg failed!\n"); 03627 return -1; 03628 } 03629 frm=(iframe_t*)msg->data; 03630 03631 /* activate bchannel */ 03632 frm->prim = MGR_CLEARSTACK| REQUEST; 03633 03634 frm->addr = bc->l3_id; 03635 03636 frm->dinfo = bc->port; 03637 frm->len = 0; 03638 03639 msg_queue_tail(&glob_mgr->activatequeue, msg); 03640 sem_post(&glob_mgr->new_msg); 03641 03642 return 0; 03643 03644 }
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 1355 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().
01356 { 01357 char buf[1024]; 01358 if (!stack) return; 01359 01360 if (stack->nt) { 01361 cleanup_Isdnl2(&stack->nst); 01362 cleanup_Isdnl3(&stack->nst); 01363 } 01364 01365 if (stack->lower_id) 01366 mISDN_write_frame(stack->midev, buf, stack->lower_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01367 01368 if (stack->upper_id) 01369 mISDN_write_frame(stack->midev, buf, stack->upper_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 01370 }
void stack_holder_add | ( | struct misdn_stack * | stack, | |
struct misdn_bchannel * | holder | |||
) |
Definition at line 4180 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().
04181 { 04182 struct misdn_bchannel *help; 04183 cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id); 04184 04185 holder->stack_holder=1; 04186 04187 if (!stack ) return ; 04188 04189 holder->next=NULL; 04190 04191 if (!stack->holding) { 04192 stack->holding = holder; 04193 return; 04194 } 04195 04196 for (help=stack->holding; 04197 help; 04198 help=help->next) { 04199 if (!help->next) { 04200 help->next=holder; 04201 break; 04202 } 04203 } 04204 04205 }
struct misdn_bchannel * stack_holder_find | ( | struct misdn_stack * | stack, | |
unsigned long | l3id | |||
) |
Definition at line 4255 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().
04256 { 04257 struct misdn_bchannel *help; 04258 04259 cb_log(4,stack?stack->port:0, "*HOLDER: find %x\n",l3id); 04260 04261 if (!stack) return NULL; 04262 04263 for (help=stack->holding; 04264 help; 04265 help=help->next) { 04266 if (help->l3_id == l3id) { 04267 cb_log(4,stack->port, "*HOLDER: found bc\n"); 04268 return help; 04269 } 04270 } 04271 04272 cb_log(4,stack->port, "*HOLDER: find nothing\n"); 04273 return NULL; 04274 }
struct misdn_bchannel * stack_holder_find_bychan | ( | struct misdn_stack * | stack, | |
int | chan | |||
) |
Definition at line 4233 of file isdn_lib.c.
References cb_log, misdn_bchannel::channel, misdn_stack::holding, misdn_bchannel::next, and misdn_stack::port.
04234 { 04235 struct misdn_bchannel *help; 04236 04237 cb_log(4,stack?stack->port:0, "*HOLDER: find_bychan %c\n", chan); 04238 04239 if (!stack) return NULL; 04240 04241 for (help=stack->holding; 04242 help; 04243 help=help->next) { 04244 if (help->channel == chan) { 04245 cb_log(4,stack->port, "*HOLDER: found_bychan bc\n"); 04246 return help; 04247 } 04248 } 04249 04250 cb_log(4,stack->port, "*HOLDER: find_bychan nothing\n"); 04251 return NULL; 04252 04253 }
void stack_holder_remove | ( | struct misdn_stack * | stack, | |
struct misdn_bchannel * | holder | |||
) |
Definition at line 4207 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().
04208 { 04209 struct misdn_bchannel *h1; 04210 04211 if (!holder->stack_holder) return; 04212 04213 holder->stack_holder=0; 04214 04215 cb_log(4,stack->port, "*HOLDER: remove %x\n",holder->l3_id); 04216 if (!stack || ! stack->holding) return; 04217 04218 if (holder == stack->holding) { 04219 stack->holding = stack->holding->next; 04220 return; 04221 } 04222 04223 for (h1=stack->holding; 04224 h1; 04225 h1=h1->next) { 04226 if (h1->next == holder) { 04227 h1->next=h1->next->next; 04228 return ; 04229 } 04230 } 04231 }
struct misdn_stack * stack_init | ( | int | midev, | |
int | port, | |||
int | ptp | |||
) |
Definition at line 1159 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().
01160 { 01161 int ret; 01162 unsigned char buff[1025]; 01163 iframe_t *frm = (iframe_t *)buff; 01164 stack_info_t *stinf; 01165 int i; 01166 layer_info_t li; 01167 01168 struct misdn_stack *stack = malloc(sizeof(struct misdn_stack)); 01169 if (!stack ) return NULL; 01170 01171 01172 cb_log(8, port, "Init. Stack.\n"); 01173 01174 memset(stack,0,sizeof(struct misdn_stack)); 01175 01176 for (i=0; i<MAX_BCHANS + 1; i++ ) stack->channels[i]=0; 01177 01178 stack->port=port; 01179 stack->midev=midev; 01180 stack->ptp=ptp; 01181 01182 stack->holding=NULL; 01183 stack->pri=0; 01184 01185 msg_queue_init(&stack->downqueue); 01186 msg_queue_init(&stack->upqueue); 01187 01188 /* query port's requirements */ 01189 ret = mISDN_get_stack_info(midev, port, buff, sizeof(buff)); 01190 if (ret < 0) { 01191 cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret); 01192 return(NULL); 01193 } 01194 01195 stinf = (stack_info_t *)&frm->data.p; 01196 01197 stack->d_stid = stinf->id; 01198 stack->b_num = stinf->childcnt; 01199 01200 for (i=0; i<=stinf->childcnt; i++) 01201 stack->b_stids[i] = stinf->child[i]; 01202 01203 switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK) { 01204 case ISDN_PID_L0_TE_S0: 01205 stack->nt=0; 01206 break; 01207 case ISDN_PID_L0_NT_S0: 01208 cb_log(8, port, "NT Stack\n"); 01209 01210 stack->nt=1; 01211 break; 01212 01213 #ifndef MISDN_1_2 01214 case ISDN_PID_L0_TE_U: 01215 break; 01216 case ISDN_PID_L0_NT_U: 01217 break; 01218 case ISDN_PID_L0_TE_UP2: 01219 break; 01220 case ISDN_PID_L0_NT_UP2: 01221 break; 01222 #endif 01223 case ISDN_PID_L0_TE_E1: 01224 cb_log(8, port, "TE S2M Stack\n"); 01225 stack->nt=0; 01226 stack->pri=1; 01227 break; 01228 case ISDN_PID_L0_NT_E1: 01229 cb_log(8, port, "TE S2M Stack\n"); 01230 stack->nt=1; 01231 stack->pri=1; 01232 01233 break; 01234 default: 01235 cb_log(0, port, "this is a unknown port type 0x%08x\n", stinf->pid.protocol[0]); 01236 01237 } 01238 01239 if (!stack->nt) { 01240 if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP ) { 01241 stack->ptp = 1; 01242 } else { 01243 stack->ptp = 0; 01244 } 01245 } 01246 01247 { 01248 int ret; 01249 int nt=stack->nt; 01250 01251 cb_log(8, port, "Init. Stack.\n"); 01252 01253 memset(&li, 0, sizeof(li)); 01254 { 01255 int l = sizeof(li.name); 01256 strncpy(li.name,nt?"net l2":"user l4", l); 01257 li.name[l-1] = 0; 01258 } 01259 li.object_id = -1; 01260 li.extentions = 0; 01261 li.pid.protocol[nt?2:4] = nt?ISDN_PID_L2_LAPD_NET:ISDN_PID_L4_CAPI20; 01262 li.pid.layermask = ISDN_LAYER((nt?2:4)); 01263 li.st = stack->d_stid; 01264 01265 01266 ret = mISDN_new_layer(midev, &li); 01267 if (ret) { 01268 cb_log(0, port, "%s: Cannot add layer %d to this port.\n", __FUNCTION__, nt?2:4); 01269 return(NULL); 01270 } 01271 01272 01273 stack->upper_id = li.id; 01274 ret = mISDN_register_layer(midev, stack->d_stid, stack->upper_id); 01275 if (ret) 01276 { 01277 cb_log(0,port,"Cannot register layer %d of this port.\n", nt?2:4); 01278 return(NULL); 01279 } 01280 01281 stack->lower_id = mISDN_get_layerid(midev, stack->d_stid, nt?1:3); 01282 if (stack->lower_id < 0) { 01283 cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, nt?1:3); 01284 return(NULL); 01285 } 01286 01287 stack->upper_id = mISDN_get_layerid(midev, stack->d_stid, nt?2:4); 01288 if (stack->upper_id < 0) { 01289 cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, 2); 01290 return(NULL); 01291 } 01292 01293 cb_log(8, port, "NT Stacks upper_id %x\n",stack->upper_id); 01294 01295 01296 /* create nst (nt-mode only) */ 01297 if (nt) { 01298 01299 memset(&stack->nst, 0, sizeof(net_stack_t)); 01300 memset(&stack->mgr, 0, sizeof(manager_t)); 01301 01302 stack->mgr.nst = &stack->nst; 01303 stack->nst.manager = &stack->mgr; 01304 01305 stack->nst.l3_manager = handle_event_nt; 01306 stack->nst.device = midev; 01307 stack->nst.cardnr = port; 01308 stack->nst.d_stid = stack->d_stid; 01309 01310 stack->nst.feature = FEATURE_NET_HOLD; 01311 if (stack->ptp) 01312 stack->nst.feature |= FEATURE_NET_PTP; 01313 if (stack->pri) 01314 stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID; 01315 01316 stack->nst.l1_id = stack->lower_id; 01317 stack->nst.l2_id = stack->upper_id; 01318 01319 msg_queue_init(&stack->nst.down_queue); 01320 01321 Isdnl2Init(&stack->nst); 01322 Isdnl3Init(&stack->nst); 01323 01324 } 01325 01326 if (!stack->nt) { 01327 /*assume L1 is up, we'll get DEACTIVATES soon, for non 01328 * up L1s*/ 01329 stack->l1link=0; 01330 } 01331 stack->l1link=0; 01332 stack->l2link=0; 01333 #if 0 01334 if (!stack->nt) { 01335 misdn_lib_get_short_status(stack); 01336 } else { 01337 misdn_lib_get_l1_up(stack); 01338 if (!stack->ptp) misdn_lib_get_l1_up(stack); 01339 misdn_lib_get_l2_up(stack); 01340 } 01341 #endif 01342 01343 misdn_lib_get_short_status(stack); 01344 misdn_lib_get_l1_up(stack); 01345 misdn_lib_get_l2_up(stack); 01346 01347 } 01348 01349 cb_log(8,0,"stack_init: port:%d lowerId:%x upperId:%x\n",stack->port,stack->lower_id, stack->upper_id); 01350 01351 return stack; 01352 }
void te_lib_destroy | ( | int | midev | ) |
Definition at line 3024 of file isdn_lib.c.
References cb_log, and entity.
Referenced by misdn_lib_destroy().
03025 { 03026 char buf[1024]; 03027 mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC); 03028 03029 cb_log(4, 0, "Entetity deleted\n"); 03030 mISDN_close(midev); 03031 cb_log(4, 0, "midev closed\n"); 03032 }
int te_lib_init | ( | ) |
App Interface
Definition at line 2995 of file isdn_lib.c.
References entity, and misdn_lib::midev.
Referenced by misdn_lib_init().
02995 { 02996 char buff[1025]; 02997 iframe_t *frm=(iframe_t*)buff; 02998 int midev=mISDN_open(); 02999 int ret; 03000 03001 memset(buff,0,1025); 03002 03003 if (midev<=0) return midev; 03004 03005 /* create entity for layer 3 TE-mode */ 03006 mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); 03007 ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC); 03008 03009 if (ret < mISDN_HEADER_LEN) { 03010 noentity: 03011 fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n",strerror(errno)); 03012 exit(-1); 03013 } 03014 03015 entity = frm->dinfo & 0xffff ; 03016 03017 if (!entity) 03018 goto noentity; 03019 03020 return midev; 03021 03022 }
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 3721 of file isdn_lib.c.
Msg Array
Definition at line 1140 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] |