Mon Nov 24 15:34:41 2008

Asterisk developer's documentation


isdn_lib.c File Reference

#include <syslog.h>
#include <sys/time.h>
#include <mISDNuser/isdn_debug.h>
#include "isdn_lib_intern.h"
#include "isdn_lib.h"
#include <mISDNuser/net_l2.h>
#include <mISDNuser/tone.h>
#include <unistd.h>
#include <semaphore.h>
#include <pthread.h>
#include <signal.h>

Go to the source code of this file.

Data Structures

struct  misdn_lib

Defines

#define ECHOCAN_OFF   124
#define ECHOCAN_ON   123
#define ISDN_PID_L3_B_USER   0x430000ff
#define ISDN_PID_L4_B_USER   0x440000ff
#define MAXPROCS   0x100
#define MISDN_DEBUG   0
#define MISDN_DSP
#define MISDN_GEN_SILENCE
#define MISDN_IBUF_SIZE   512
#define RETURN(a, b)   {retval=a; goto b;}
#define TONE_ALERT_CNT   41
#define TONE_ALERT_SILENCE_CNT   200
#define TONE_BUSY_CNT   20
#define TONE_BUSY_SILENCE_CNT   48

Enumerations

enum  global_states { MISDN_INITIALIZING, MISDN_INITIALIZED }

Functions

static void bc_next_state_change (struct misdn_bchannel *bc, enum bchannel_state state)
char * bc_state2str (enum bchannel_state state)
void bc_state_change (struct misdn_bchannel *bc, enum bchannel_state state)
int bchdev_echocancel_activate (struct misdn_bchannel *dev)
void bchdev_echocancel_deactivate (struct misdn_bchannel *dev)
static char * bearer2str (int cap)
static int clean_up_bc (struct misdn_bchannel *bc)
static void clear_l3 (struct misdn_stack *stack)
static msg_t * create_l2msg (int prim, int dinfo, int size)
msg_t * create_l3msg (int prim, int mt, int dinfo, int size, int ntmode)
static int create_process (int midev, struct misdn_bchannel *bc)
static int do_tone (struct misdn_bchannel *bc, int len)
static void dump_chan_list (struct misdn_stack *stack)
void ec_chunk (struct misdn_bchannel *bc, unsigned char *rxchunk, unsigned char *txchunk, int chunk_size)
static void empty_bc (struct misdn_bchannel *bc)
static int empty_chan_in_stack (struct misdn_stack *stack, int channel)
static char * fac2str (enum FacFunction func)
static msg_t * fetch_msg (int midev)
static struct misdn_bchannelfind_bc_by_addr (unsigned long addr)
static struct misdn_bchannelfind_bc_by_channel (int port, int channel)
misdn_bchannelfind_bc_by_confid (unsigned long confid)
misdn_bchannelfind_bc_by_l3id (struct misdn_stack *stack, unsigned long l3id)
static struct misdn_bchannelfind_bc_by_masked_l3id (struct misdn_stack *stack, unsigned long l3id, unsigned long mask)
static struct misdn_bchannelfind_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_stackfind_stack_by_addr (int addr)
static struct misdn_stackfind_stack_by_mgr (manager_t *mgr_nt)
static struct misdn_stackfind_stack_by_port (int port)
static char * flip_buf_bits (char *buf, int len)
misdn_stackget_misdn_stack (void)
void get_show_stack_details (int port, char *buf)
misdn_stackget_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)
static void make_dummy (struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel)
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_bchannelmanager_find_bc_by_pid (int pid)
misdn_bchannelmanager_find_bc_holded (struct misdn_bchannel *bc)
char * manager_isdn_get_info (enum event_e event)
int manager_isdn_handler (iframe_t *frm, msg_t *msg)
void manager_ph_control (struct misdn_bchannel *bc, int c1, int c2)
void manager_ph_control_block (struct misdn_bchannel *bc, int c1, void *c2, int c2_len)
int misdn_cap_is_speech (int cap)
void misdn_dump_chanlist ()
int misdn_inband_avail (struct misdn_bchannel *bc)
void misdn_join_conf (struct misdn_bchannel *bc, int conf_id)
void misdn_lib_bridge (struct misdn_bchannel *bc1, struct misdn_bchannel *bc2)
void misdn_lib_destroy ()
void misdn_lib_echo (struct misdn_bchannel *bc, int onoff)
misdn_bchannelmisdn_lib_get_free_bc (int port, int channel, int inout, int dec)
static int misdn_lib_get_l1_down (struct misdn_stack *stack)
static int misdn_lib_get_l1_up (struct misdn_stack *stack)
static int misdn_lib_get_l2_down (struct misdn_stack *stack)
int misdn_lib_get_l2_up (struct misdn_stack *stack)
int misdn_lib_get_maxchans (int port)
int misdn_lib_get_port_down (int port)
int misdn_lib_get_port_info (int port)
int misdn_lib_get_port_up (int port)
static int misdn_lib_get_short_status (struct misdn_stack *stack)
int misdn_lib_init (char *portlist, struct misdn_lib_iface *iface, void *user_data)
int misdn_lib_is_port_blocked (int port)
int misdn_lib_is_ptp (int port)
static void misdn_lib_isdn_event_catcher (void *arg)
void misdn_lib_isdn_l1watcher (int port)
void misdn_lib_log_ies (struct misdn_bchannel *bc)
int misdn_lib_maxports_get ()
void misdn_lib_nt_debug_init (int flags, char *file)
void misdn_lib_nt_keepcalls (int kc)
int misdn_lib_pid_restart (int pid)
int misdn_lib_port_block (int port)
int misdn_lib_port_is_pri (int port)
int misdn_lib_port_restart (int port)
int misdn_lib_port_unblock (int port)
int misdn_lib_port_up (int port, int check)
void misdn_lib_reinit_nt_stack (int port)
void misdn_lib_release (struct misdn_bchannel *bc)
int misdn_lib_send_event (struct misdn_bchannel *bc, enum event_e event)
int misdn_lib_send_restart (int port, int channel)
void misdn_lib_send_tone (struct misdn_bchannel *bc, enum tone_e tone)
void misdn_lib_setup_bc (struct misdn_bchannel *bc)
void misdn_lib_split_bridge (struct misdn_bchannel *bc1, struct misdn_bchannel *bc2)
void misdn_lib_tone_generator_start (struct misdn_bchannel *bc)
void misdn_lib_tone_generator_stop (struct misdn_bchannel *bc)
void misdn_lib_transfer (struct misdn_bchannel *holded_bc)
int misdn_lib_tx2misdn_frm (struct misdn_bchannel *bc, void *data, int len)
void misdn_send_lock (struct misdn_bchannel *bc)
void misdn_send_unlock (struct misdn_bchannel *bc)
void misdn_split_conf (struct misdn_bchannel *bc, int conf_id)
void misdn_tx_jitter (struct misdn_bchannel *bc, int len)
static void prepare_bc (struct misdn_bchannel *bc, int channel)
int queue_cleanup_bc (struct misdn_bchannel *bc)
int release_cr (struct misdn_stack *stack, mISDNuser_head_t *hh)
static int send_msg (int midev, struct misdn_bchannel *bc, msg_t *dmsg)
static int set_chan_in_stack (struct misdn_stack *stack, int channel)
int setup_bc (struct misdn_bchannel *bc)
void stack_destroy (struct misdn_stack *stack)
void stack_holder_add (struct misdn_stack *stack, struct misdn_bchannel *holder)
misdn_bchannelstack_holder_find (struct misdn_stack *stack, unsigned long l3id)
misdn_bchannelstack_holder_find_bychan (struct misdn_stack *stack, int chan)
void stack_holder_remove (struct misdn_stack *stack, struct misdn_bchannel *holder)
misdn_stackstack_init (int midev, int port, int ptp)
void te_lib_destroy (int midev)
int te_lib_init (void)
static int test_inuse (struct misdn_bchannel *bc)

Variables

static int entity
static char flip_table [256]
static struct misdn_libglob_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 Documentation

#define ECHOCAN_OFF   124

Definition at line 192 of file isdn_lib.c.

Referenced by manager_ec_disable().

#define ECHOCAN_ON   123

Definition at line 191 of file isdn_lib.c.

Referenced by manager_ec_enable().

#define ISDN_PID_L3_B_USER   0x430000ff

Definition at line 214 of file isdn_lib.c.

#define ISDN_PID_L4_B_USER   0x440000ff

Definition at line 215 of file isdn_lib.c.

#define MAXPROCS   0x100

Definition at line 765 of file isdn_lib.c.

Referenced by create_process().

#define MISDN_DEBUG   0

Definition at line 195 of file isdn_lib.c.

#define MISDN_DSP

#define MISDN_GEN_SILENCE

#define MISDN_IBUF_SIZE   512

Definition at line 218 of file isdn_lib.c.

Referenced by init_bc().

#define RETURN ( a,
 )     {retval=a; goto b;}

Definition at line 3293 of file isdn_lib.c.

Referenced by misdn_lib_send_event().

#define TONE_ALERT_CNT   41

Definition at line 221 of file isdn_lib.c.

#define TONE_ALERT_SILENCE_CNT   200

Definition at line 222 of file isdn_lib.c.

#define TONE_BUSY_CNT   20

Definition at line 224 of file isdn_lib.c.

#define TONE_BUSY_SILENCE_CNT   48

Definition at line 225 of file isdn_lib.c.


Enumeration Type Documentation

enum global_states

Enumerator:
MISDN_INITIALIZING 
MISDN_INITIALIZED 

Definition at line 155 of file isdn_lib.c.

00155                    {
00156    MISDN_INITIALIZING,
00157    MISDN_INITIALIZED
00158 } ;


Function Documentation

static void bc_next_state_change ( struct misdn_bchannel bc,
enum bchannel_state  state 
) [static]

Definition at line 602 of file isdn_lib.c.

References bc_state2str(), cb_log, misdn_bchannel::next_bc_state, and misdn_bchannel::port.

Referenced by misdn_lib_bridge().

00603 {
00604    cb_log(5,bc->port,"BC_NEXT_STATE_CHANGE: from:%s to:%s\n",
00605           bc_state2str(bc->next_bc_state),
00606           bc_state2str(state) );
00607 
00608    bc->next_bc_state=state;
00609 }

char* bc_state2str ( enum bchannel_state  state  ) 

Definition at line 553 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().

00553                                               {
00554    int i;
00555    
00556    struct bchan_state_s {
00557       char *n;
00558       enum bchannel_state s;
00559    } states[] = {
00560       {"BCHAN_CLEANED", BCHAN_CLEANED },
00561       {"BCHAN_EMPTY", BCHAN_EMPTY},
00562       {"BCHAN_SETUP", BCHAN_SETUP},
00563       {"BCHAN_SETUPED", BCHAN_SETUPED},
00564       {"BCHAN_ACTIVE", BCHAN_ACTIVE},
00565       {"BCHAN_ACTIVATED", BCHAN_ACTIVATED},
00566       {"BCHAN_BRIDGE",  BCHAN_BRIDGE},
00567       {"BCHAN_BRIDGED", BCHAN_BRIDGED},
00568       {"BCHAN_RELEASE", BCHAN_RELEASE},
00569       {"BCHAN_RELEASED", BCHAN_RELEASED},
00570       {"BCHAN_CLEAN", BCHAN_CLEAN},
00571       {"BCHAN_CLEAN_REQUEST", BCHAN_CLEAN_REQUEST},
00572       {"BCHAN_ERROR", BCHAN_ERROR}
00573    };
00574    
00575    for (i=0; i< sizeof(states)/sizeof(struct bchan_state_s); i++)
00576       if ( states[i].s == state)
00577          return states[i].n;
00578 
00579    return "UNKNOWN";
00580 }

void bc_state_change ( struct misdn_bchannel bc,
enum bchannel_state  state 
)

Definition at line 582 of file isdn_lib.c.

References misdn_bchannel::bc_state, bc_state2str(), BCHAN_ACTIVATED, BCHAN_BRIDGED, BCHAN_EMPTY, cb_log, misdn_bchannel::conf_id, misdn_bchannel::l3_id, misdn_join_conf(), misdn_bchannel::next_bc_state, and misdn_bchannel::port.

Referenced by clean_up_bc(), handle_bchan(), handle_frm(), init_bc(), manager_bchannel_deactivate(), misdn_join_conf(), misdn_lib_send_event(), and misdn_split_conf().

00583 {
00584    cb_log(5,bc->port,"BC_STATE_CHANGE: l3id:%x from:%s to:%s\n",
00585       bc->l3_id,
00586           bc_state2str(bc->bc_state),
00587           bc_state2str(state) );
00588    
00589    switch (state) {
00590       case BCHAN_ACTIVATED:
00591          if (bc->next_bc_state ==  BCHAN_BRIDGED) {
00592             misdn_join_conf(bc, bc->conf_id);
00593             bc->next_bc_state = BCHAN_EMPTY;
00594             return;
00595          }
00596       default:
00597          bc->bc_state=state;
00598          break;
00599    }
00600 }

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 263 of file isdn_lib.c.

References INFO_CAPABILITY_AUDIO_3_1K, INFO_CAPABILITY_DIGITAL_RESTRICTED, INFO_CAPABILITY_DIGITAL_UNRESTRICTED, and INFO_CAPABILITY_SPEECH.

00263                                  {
00264    static char *bearers[]={
00265       "Speech",
00266       "Audio 3.1k",
00267       "Unres Digital",
00268       "Res Digital",
00269       "Unknown Bearer"
00270    };
00271    
00272    switch (cap) {
00273    case INFO_CAPABILITY_SPEECH:
00274       return bearers[0];
00275       break;
00276    case INFO_CAPABILITY_AUDIO_3_1K:
00277       return bearers[1];
00278       break;
00279    case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:
00280       return bearers[2];
00281       break;
00282    case INFO_CAPABILITY_DIGITAL_RESTRICTED:
00283       return bearers[3];
00284       break;
00285    default:
00286       return bearers[4];
00287       break;
00288    }
00289 }

static int clean_up_bc ( struct misdn_bchannel bc  )  [static]

Definition at line 709 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(), misdn_lib_send_restart(), and misdn_lib_setup_bc().

00710 {
00711    int ret=0;
00712    unsigned char buff[32];
00713    struct misdn_stack * stack;
00714 
00715    cb_log(3, bc?bc->port:0, "$$$ CLEANUP CALLED pid:%d\n", bc?bc->pid:-1);
00716    
00717    if (!bc  ) return -1;
00718    stack=get_stack_by_bc(bc);
00719    
00720    if (!stack) return -1;
00721    
00722    switch (bc->bc_state ) {
00723    case BCHAN_CLEANED:
00724       cb_log(5, stack->port, "$$$ Already cleaned up bc with stid :%x\n", bc->b_stid);
00725       return -1;
00726       
00727    default:
00728       break;
00729    }
00730    
00731    cb_log(2, stack->port, "$$$ Cleaning up bc with stid :%x pid:%d\n", bc->b_stid, bc->pid);
00732    
00733    manager_ec_disable(bc);
00734 
00735    manager_bchannel_deactivate(bc);
00736 
00737    mISDN_write_frame(stack->midev, buff, bc->layer_id|FLG_MSG_TARGET|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
00738    
00739    bc->b_stid = 0;
00740    bc_state_change(bc, BCHAN_CLEANED);
00741    
00742    return ret;
00743 }

static void clear_l3 ( struct misdn_stack stack  )  [static]

Definition at line 747 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().

00748 {
00749    int i;
00750 
00751    for (i=0; i<=stack->b_num; i++) {
00752       if (global_state == MISDN_INITIALIZED)  {
00753          cb_event(EVENT_CLEANUP, &stack->bc[i], NULL); 
00754          empty_chan_in_stack(stack,i+1);
00755          empty_bc(&stack->bc[i]);
00756          clean_up_bc(&stack->bc[i]);
00757          stack->bc[i].in_use = 0;
00758       }
00759       
00760    } 
00761 }

static msg_t* create_l2msg ( int  prim,
int  dinfo,
int  size 
) [static]

Definition at line 322 of file isdn_lib.c.

Referenced by misdn_lib_get_l2_down(), and misdn_lib_get_l2_up().

00323 {
00324    int i = 0;
00325    msg_t *dmsg;
00326   
00327    while(i < 10)
00328    {
00329       dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
00330       if (dmsg)
00331          return(dmsg);
00332       
00333       if (!i)
00334          printf("cannot allocate memory, trying again...\n");
00335       i++;
00336       usleep(300000);
00337    }
00338    printf("cannot allocate memory, system overloaded.\n");
00339    exit(-1);
00340 }

msg_t* create_l3msg ( int  prim,
int  mt,
int  dinfo,
int  size,
int  ntmode 
)

Definition at line 344 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().

00345 {
00346    int i = 0;
00347    msg_t *dmsg;
00348    Q931_info_t *qi;
00349    iframe_t *frm;
00350   
00351    if (!ntmode)
00352       size = sizeof(Q931_info_t)+2;
00353   
00354    while(i < 10) {
00355       if (ntmode) {
00356          dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
00357          if (dmsg) {
00358             return(dmsg);
00359          }
00360       } else {
00361          dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
00362          if (dmsg)
00363          {
00364             memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
00365             frm = (iframe_t *)dmsg->data;
00366             frm->prim = prim;
00367             frm->dinfo = dinfo;
00368             qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
00369             qi->type = mt;
00370             return(dmsg);
00371          }
00372       }
00373     
00374       if (!i) printf("cannot allocate memory, trying again...\n");
00375       i++;
00376       usleep(300000);
00377    }
00378    printf("cannot allocate memory, system overloaded.\n");
00379    exit(-1);
00380 }

static int create_process ( int  midev,
struct misdn_bchannel bc 
) [static]

Definition at line 879 of file isdn_lib.c.

References misdn_stack::bc, cb_log, misdn_bchannel::channel, misdn_bchannel::channel_preselected, misdn_bchannel::dec, 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, misdn_bchannel::te_choose_channel, and misdn_stack::upper_id.

Referenced by misdn_lib_send_event().

00879                                                                  {
00880    iframe_t ncr;
00881    int l3_id;
00882    int i;
00883    struct misdn_stack *stack=get_stack_by_bc(bc);
00884   
00885    if (stack->nt) {
00886       if (find_free_chan_in_stack(stack, bc, bc->channel_preselected?bc->channel:0, 0)<0) return -1;
00887       cb_log(4,stack->port, " -->  found channel: %d\n",bc->channel);
00888     
00889       for (i=0; i <= MAXPROCS; i++)
00890          if (stack->procids[i]==0) break;
00891     
00892       if (i== MAXPROCS) {
00893          cb_log(0, stack->port, "Couldnt Create New ProcId.\n");
00894          return -1;
00895       }
00896       stack->procids[i]=1;
00897 
00898       l3_id = 0xff00 | i;
00899     
00900       ncr.prim = CC_NEW_CR | REQUEST; 
00901 
00902       ncr.addr = (stack->upper_id | FLG_MSG_DOWN)  ;
00903 
00904       ncr.dinfo = l3_id;
00905       ncr.len = 0;
00906 
00907       bc->l3_id = l3_id;
00908       cb_log(3, stack->port, " --> new_l3id %x\n",l3_id);
00909     
00910    } else { 
00911       if (stack->ptp || bc->te_choose_channel) {
00912          /* we know exactly which channels are in use */
00913          if (find_free_chan_in_stack(stack, bc, bc->channel_preselected?bc->channel:0, bc->dec)<0) return -1;
00914          cb_log(2,stack->port, " -->  found channel: %d\n",bc->channel);
00915       } else {
00916          /* other phones could have made a call also on this port (ptmp) */
00917          bc->channel=0xff;
00918       }
00919     
00920     
00921       /* if we are in te-mode, we need to create a process first */
00922       if (newteid++ > 0xffff)
00923          newteid = 0x0001;
00924     
00925       l3_id = (entity<<16) | newteid;
00926       /* preparing message */
00927       ncr.prim = CC_NEW_CR | REQUEST; 
00928 
00929       ncr.addr = (stack->upper_id | FLG_MSG_DOWN)  ;
00930 
00931       ncr.dinfo =l3_id;
00932       ncr.len = 0;
00933       /* send message */
00934 
00935       bc->l3_id = l3_id;
00936       cb_log(3, stack->port, "--> new_l3id %x\n",l3_id);
00937     
00938       mISDN_write(midev, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
00939    }
00940   
00941    return l3_id;
00942 }

static int do_tone ( struct misdn_bchannel bc,
int  len 
) [static]

Definition at line 2195 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().

02196 {
02197    bc->tone_cnt=len;
02198    
02199    if (bc->generate_tone) {
02200       cb_event(EVENT_TONE_GENERATE, bc, glob_mgr->user_data);
02201       
02202       if ( !bc->nojitter ) {
02203          misdn_tx_jitter(bc,len);
02204       }
02205       
02206       return 1;
02207    }
02208    
02209    return 0;
02210 }

static void dump_chan_list ( struct misdn_stack stack  )  [static]

Definition at line 437 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, cb_log, misdn_stack::channels, misdn_bchannel::in_use, and misdn_stack::port.

Referenced by empty_chan_in_stack(), handle_cr(), misdn_dump_chanlist(), and set_chan_in_stack().

00438 {
00439    int i;
00440 
00441    for (i=0; i <= stack->b_num; i++) {
00442       cb_log(6, stack->port, "Idx:%d stack->cchan:%d in_use:%d Chan:%d\n",i,stack->channels[i], stack->bc[i].in_use, i+1);
00443    }
00444 }

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 612 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::channel_found, misdn_bchannel::conf_id, misdn_bchannel::cpnnumplan, misdn_bchannel::crypt, misdn_bchannel::crypt_key, misdn_bchannel::curprx, misdn_bchannel::curptx, misdn_bchannel::cw, misdn_bchannel::dad, misdn_bchannel::dec, misdn_bchannel::display, misdn_bchannel::dnumplan, misdn_bchannel::dummy, misdn_bchannel::early_bconnect, misdn_bchannel::ec_deftaps, misdn_bchannel::ec_enable, EVENT_NOTHING, misdn_bchannel::evq, misdn_bchannel::fac_in, misdn_bchannel::fac_out, misdn_bchannel::generate_tone, misdn_bchannel::hdlc, INFO_CAPABILITY_SPEECH, INFO_CODEC_ALAW, misdn_bchannel::info_dad, misdn_bchannel::infos_pending, misdn_bchannel::last_used, misdn_bchannel::law, misdn_bchannel::mode, misdn_bchannel::need_more_infos, misdn_bchannel::nodsp, misdn_bchannel::nojitter, NUMPLAN_UNKNOWN, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_bchannel::orig, misdn_bchannel::orig_dad, misdn_bchannel::out_cause, misdn_bchannel::pres, misdn_bchannel::progress_coding, misdn_bchannel::progress_indicator, misdn_bchannel::progress_location, misdn_bchannel::rad, misdn_bchannel::rate, misdn_bchannel::restart_channel, misdn_bchannel::rnumplan, misdn_bchannel::rxgain, misdn_bchannel::send_dtmf, misdn_bchannel::sending_complete, misdn_bchannel::te_choose_channel, misdn_bchannel::time_usec, misdn_bchannel::tone_cnt, misdn_bchannel::txgain, misdn_bchannel::urate, misdn_bchannel::user1, misdn_bchannel::uu, and misdn_bchannel::uulen.

Referenced by clear_l3(), handle_cr(), handle_event_nt(), handle_frm(), init_bc(), manager_clean_bc(), misdn_lib_release(), misdn_lib_send_event(), and misdn_lib_send_restart().

00613 {
00614    bc->dummy=0;
00615 
00616    bc->bframe_len=0;
00617 
00618    bc->cw= 0;
00619 
00620    bc->dec=0;
00621    bc->channel = 0;
00622 
00623    bc->sending_complete = 0;
00624 
00625    bc->restart_channel=0;
00626    
00627    bc->conf_id = 0;
00628 
00629    bc->need_more_infos = 0;
00630    
00631    bc->send_dtmf=0;
00632    bc->nodsp=0;
00633    bc->nojitter=0;
00634 
00635    bc->time_usec=0;
00636    
00637    bc->rxgain=0;
00638    bc->txgain=0;
00639 
00640    bc->crypt=0;
00641    bc->curptx=0; bc->curprx=0;
00642    
00643    bc->crypt_key[0] = 0;
00644    
00645    bc->generate_tone=0;
00646    bc->tone_cnt=0;
00647   
00648    bc->dnumplan=NUMPLAN_UNKNOWN;
00649    bc->onumplan=NUMPLAN_UNKNOWN;
00650    bc->rnumplan=NUMPLAN_UNKNOWN;
00651    bc->cpnnumplan=NUMPLAN_UNKNOWN;
00652    
00653 
00654    bc->active = 0;
00655 
00656    bc->early_bconnect = 1;
00657    
00658 #ifdef MISDN_1_2
00659    *bc->pipeline = 0;
00660 #else
00661    bc->ec_enable = 0;
00662    bc->ec_deftaps = 128;
00663 #endif
00664 
00665    bc->orig=0;
00666   
00667    bc->cause=16;
00668    bc->out_cause=16;
00669    bc->pres=0 ; /* screened */
00670    
00671    bc->evq=EVENT_NOTHING;
00672 
00673    bc->progress_coding=0;
00674    bc->progress_location=0;
00675    bc->progress_indicator=0;
00676    
00677 /** Set Default Bearer Caps **/
00678    bc->capability=INFO_CAPABILITY_SPEECH;
00679    bc->law=INFO_CODEC_ALAW;
00680    bc->mode=0;
00681    bc->rate=0x10;
00682    bc->user1=0;
00683    bc->urate=0;
00684    
00685    bc->hdlc=0;
00686    
00687    
00688    bc->info_dad[0] = 0;
00689    bc->display[0] = 0;
00690    bc->infos_pending[0] = 0;
00691    bc->cad[0] = 0;
00692    bc->oad[0] = 0;
00693    bc->dad[0] = 0;
00694    bc->rad[0] = 0;
00695    bc->orig_dad[0] = 0;
00696    bc->uu[0]=0;
00697    bc->uulen=0;
00698    
00699    bc->fac_in.Function = Fac_None;
00700    bc->fac_out.Function = Fac_None;
00701    
00702    bc->te_choose_channel = 0;
00703    bc->channel_found= 0;
00704 
00705    gettimeofday(&bc->last_used, NULL);
00706 }

static int empty_chan_in_stack ( struct misdn_stack stack,
int  channel 
) [static]

Definition at line 540 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().

00541 {
00542    if (channel<=0 || channel>MAX_BCHANS) {
00543       cb_log(0,stack?stack->port:0, "empty_chan_in_stack: cannot empty channel %d\n",channel);
00544       return -1;
00545    }
00546    
00547    cb_log (4, stack?stack->port:0, "empty_chan_in_stack: %d\n",channel); 
00548    stack->channels[channel-1] = 0;
00549    dump_chan_list(stack);
00550    return 0;
00551 }

static char* fac2str ( enum FacFunction  func  )  [static]

Definition at line 3239 of file isdn_lib.c.

References s.

Referenced by misdn_lib_log_ies().

03240 {
03241    struct arr_el { 
03242       enum FacFunction p; 
03243       char *s ; 
03244    } arr[] = {
03245       { Fac_None, "Fac_None" },
03246       { Fac_CD, "Fac_CD"},
03247    };
03248    
03249    int i;
03250    
03251    for (i=0; i < sizeof(arr)/sizeof( struct arr_el) ; i ++)
03252       if ( arr[i].p==func) return arr[i].s;
03253    
03254    return "unknown";
03255 }

static msg_t* fetch_msg ( int  midev  )  [static]

Definition at line 2948 of file isdn_lib.c.

References cb_log, and errno.

Referenced by misdn_lib_isdn_event_catcher().

02949 {
02950    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
02951    int r;
02952 
02953    if (!msg) {
02954       cb_log(0, 0, "fetch_msg: alloc msg failed !!");
02955       return NULL;
02956    }
02957 
02958    AGAIN:
02959       r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC);
02960       msg->len=r;
02961     
02962       if (r==0) {
02963          free_msg(msg); /* danger, cauz usualy freeing in main_loop */
02964          cb_log(6,0,"Got empty Msg..\n");
02965          return NULL;
02966       }
02967 
02968       if (r<0) {
02969          if (errno == EAGAIN) {
02970             /*we wait for mISDN here*/
02971             cb_log(4,0,"mISDN_read wants us to wait\n");
02972             usleep(5000);
02973             goto AGAIN;
02974          }
02975          
02976          cb_log(0,0,"mISDN_read returned :%d error:%s (%d)\n",r,strerror(errno),errno); 
02977       }
02978 
02979 #if 0
02980                if  (!(frm->prim == (DL_DATA|INDICATION) )|| (frm->prim == (PH_DATA|INDICATION)))
02981                        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 );
02982 #endif
02983       return msg;
02984 }

static struct misdn_bchannel* find_bc_by_addr ( unsigned long  addr  )  [static]

Definition at line 1463 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().

01464 {
01465    struct misdn_stack* stack;
01466    int i;
01467 
01468    for (stack=glob_mgr->stack_list;
01469         stack;
01470         stack=stack->next) {
01471       for (i=0; i<=stack->b_num; i++) {
01472          if ( (stack->bc[i].addr&STACK_ID_MASK)==(addr&STACK_ID_MASK) ||  stack->bc[i].layer_id== addr ) {
01473             return &stack->bc[i];
01474          }
01475       }
01476    }
01477    
01478    return NULL;
01479 }

static struct misdn_bchannel* find_bc_by_channel ( int  port,
int  channel 
) [static]

Definition at line 1499 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().

01500 {
01501    struct misdn_stack* stack=find_stack_by_port(port);
01502    int i;
01503 
01504    if (!stack) return NULL;   
01505    
01506    for (i=0; i<=stack->b_num; i++) {
01507       if ( stack->bc[i].channel== channel ) {
01508          return &stack->bc[i];
01509       }
01510    }
01511       
01512    return NULL;
01513 }

struct misdn_bchannel * find_bc_by_confid ( unsigned long  confid  ) 

Definition at line 1481 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().

01482 {
01483    struct misdn_stack* stack;
01484    int i;
01485    
01486    for (stack=glob_mgr->stack_list;
01487         stack;
01488         stack=stack->next) {
01489       for (i=0; i<=stack->b_num; i++) {
01490          if ( stack->bc[i].conf_id==confid ) {
01491             return &stack->bc[i];
01492          }
01493       }
01494    }
01495    return NULL;
01496 }

struct misdn_bchannel * find_bc_by_l3id ( struct misdn_stack stack,
unsigned long  l3id 
)

Definition at line 1444 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::l3_id, and stack_holder_find().

Referenced by handle_cr(), handle_event_nt(), handle_frm(), manager_event_handler(), and release_cr().

01445 {
01446    int i;
01447    for (i=0; i<=stack->b_num; i++) {
01448       if (stack->bc[i].l3_id == l3id) return &stack->bc[i] ;
01449    }
01450    return stack_holder_find(stack,l3id);
01451 }

static struct misdn_bchannel* find_bc_by_masked_l3id ( struct misdn_stack stack,
unsigned long  l3id,
unsigned long  mask 
) [static]

Definition at line 1434 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().

01435 {
01436    int i;
01437    for (i=0; i<=stack->b_num; i++) {
01438       if ( (stack->bc[i].l3_id & mask)  ==  (l3id & mask)) return &stack->bc[i] ;
01439    }
01440    return stack_holder_find(stack,l3id);
01441 }

static struct misdn_bchannel* find_bc_holded ( struct misdn_stack stack  )  [static]

Definition at line 1453 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, and misdn_bchannel::holded.

Referenced by manager_find_bc_holded().

01454 {
01455    int i;
01456    for (i=0; i<=stack->b_num; i++) {
01457       if (stack->bc[i].holded ) return &stack->bc[i] ;
01458    }
01459    return NULL;
01460 }

static int find_free_chan_in_stack ( struct misdn_stack stack,
struct misdn_bchannel bc,
int  channel,
int  dec 
) [static]

Definition at line 478 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, cb_log, misdn_bchannel::channel_found, misdn_stack::channels, MAX_BCHANS, misdn_stack::port, and misdn_stack::pri.

Referenced by create_process(), handle_event(), handle_event_nt(), and misdn_lib_send_event().

00479 {
00480    int i;
00481    int bnums;
00482    int chan=0;
00483 
00484    if (bc->channel_found)  
00485       return 0;
00486    
00487    bc->channel_found=1;
00488 
00489    cb_log(5,stack->port,"find_free_chan: req_chan:%d\n",channel);
00490 
00491 
00492    if (channel < 0 || channel > MAX_BCHANS) {
00493       cb_log(0, stack->port, " !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel);
00494       return 0;
00495    }
00496    
00497    channel--;
00498 
00499    bnums=stack->pri?stack->b_num:stack->b_num-1;
00500  
00501    if (dec) {
00502       for (i = bnums; i >=0; i--) {
00503          if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
00504             if (!stack->channels[i]) {
00505                cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
00506                chan=i+1;
00507                break;
00508             }
00509          }
00510       }
00511    } else {
00512       for (i = 0; i <= bnums; i++) {
00513          if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
00514             if (!stack->channels[i]) {
00515                cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
00516                chan=i+1;
00517                break;
00518             }
00519          }
00520       }
00521    }
00522 
00523    if (!chan) {
00524       cb_log (1, stack->port, " !! NO FREE CHAN IN STACK\n");
00525       dump_chan_list(stack);
00526       bc->out_cause=34;
00527       return -1;
00528    }  
00529 
00530    if (set_chan_in_stack(stack, chan)<0) {
00531       cb_log (0, stack->port, "Channel Already in use:%d\n", chan);
00532       bc->out_cause=44;
00533       return -1;
00534    }
00535 
00536    bc->channel=chan;
00537    return 0;
00538 }

static struct misdn_stack* find_stack_by_addr ( int  addr  )  [static]

Definition at line 1395 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().

01396 {
01397    struct misdn_stack *stack;
01398    
01399    for (stack=glob_mgr->stack_list;
01400         stack;
01401         stack=stack->next) {
01402       if ( (stack->upper_id&STACK_ID_MASK) == (addr&STACK_ID_MASK)) return stack;
01403 
01404    }
01405   
01406    return NULL;
01407 }

static struct misdn_stack* find_stack_by_mgr ( manager_t *  mgr_nt  )  [static]

Definition at line 1422 of file isdn_lib.c.

References glob_mgr, misdn_stack::mgr, misdn_stack::next, and misdn_lib::stack_list.

Referenced by handle_event_nt().

01423 {
01424    struct misdn_stack *stack;
01425   
01426    for (stack=glob_mgr->stack_list;
01427         stack;
01428         stack=stack->next) 
01429       if ( &stack->mgr == mgr_nt) return stack;
01430   
01431    return NULL;
01432 }

static struct misdn_stack* find_stack_by_port ( int  port  )  [static]

Definition at line 1410 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().

01411 {
01412    struct misdn_stack *stack;
01413   
01414    for (stack=glob_mgr->stack_list;
01415         stack;
01416         stack=stack->next) 
01417       if (stack->port == port) return stack;
01418   
01419    return NULL;
01420 }

static char* flip_buf_bits ( char *  buf,
int  len 
) [static]

Definition at line 307 of file isdn_lib.c.

References flip_table.

Referenced by handle_bchan(), misdn_lib_init(), misdn_lib_tx2misdn_frm(), and misdn_tx_jitter().

00308 {
00309    int i;
00310    char * start = buf;
00311    
00312    for (i = 0 ; i < len; i++) {
00313       buf[i] = flip_table[(unsigned char)buf[i]];
00314    }
00315    
00316    return start;
00317 }

struct misdn_stack * get_misdn_stack ( void   ) 

Definition at line 4509 of file isdn_lib.c.

References glob_mgr, and misdn_lib::stack_list.

Referenced by get_show_stack_details(), get_stack_by_bc(), misdn_dump_chanlist(), misdn_lib_get_maxchans(), misdn_lib_is_port_blocked(), misdn_lib_is_ptp(), misdn_lib_nt_keepcalls(), misdn_lib_port_block(), misdn_lib_port_is_pri(), and misdn_lib_port_unblock().

04509                                       {
04510    return glob_mgr->stack_list;
04511 }

void get_show_stack_details ( int  port,
char *  buf 
)

Definition at line 135 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().

00136 {
00137    struct misdn_stack *stack=get_misdn_stack();
00138    
00139    for ( ; stack; stack=stack->next) {
00140       if (stack->port == port) break;
00141    }
00142    
00143    if (stack) {
00144       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);
00145 
00146    } else {
00147       buf[0]=0;
00148    }
00149    
00150 }

struct misdn_stack* get_stack_by_bc ( struct misdn_bchannel bc  ) 

Definition at line 118 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().

00119 {
00120    struct misdn_stack *stack=get_misdn_stack();
00121 
00122    if (!bc) return NULL;
00123    
00124    for ( ; stack; stack=stack->next) {
00125       int i;
00126       for (i=0; i <=stack->b_num; i++) {
00127          if ( bc->port == stack->port) return stack;
00128       }
00129    }
00130 
00131    return NULL;
00132 }

static int handle_bchan ( msg_t *  msg  )  [static]

Definition at line 2298 of file isdn_lib.c.

References bc_state2str(), bc_state_change(), BCHAN_ACTIVATED, BCHAN_CLEAN_REQUEST, BCHAN_SETUP, BCHAN_SETUPED, cb_event, cb_log, clean_up_bc(), do_tone(), misdn_bchannel::dtmf, errno, EVENT_BCHAN_DATA, EVENT_DTMF_TONE, find_bc_by_addr(), flip_buf_bits(), get_stack_by_bc(), glob_mgr, misdn_cap_is_speech(), misdn_tx_jitter(), t, and misdn_lib::user_data.

Referenced by handle_err(), and manager_isdn_handler().

02299 {
02300    iframe_t *frm= (iframe_t*)msg->data;
02301    struct misdn_stack *stack;
02302    struct misdn_bchannel *bc=find_bc_by_addr(frm->addr);
02303    
02304    if (!bc) {
02305       cb_log(1,0,"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo);
02306       return 0 ;
02307    }
02308    
02309    stack=get_stack_by_bc(bc);
02310    
02311    if (!stack) {
02312       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);
02313       return 0;
02314    }
02315    
02316    switch (frm->prim) {
02317 
02318    case MGR_SETSTACK| CONFIRM:
02319       cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|CONFIRM pid:%d\n",bc->pid);
02320       break;
02321       
02322    case MGR_SETSTACK| INDICATION:
02323       cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->pid);
02324    break;
02325 #if 0
02326    AGAIN:
02327       bc->addr = mISDN_get_layerid(stack->midev, bc->b_stid, bc->layer);
02328       if (!bc->addr) {
02329 
02330          if (errno == EAGAIN) {
02331             usleep(1000);
02332             goto AGAIN;
02333          }
02334          
02335          cb_log(0,stack->port,"$$$ Get Layer (%d) Id Error: %s\n",bc->layer,strerror(errno));
02336          
02337          /* we kill the channel later, when we received some
02338             data. */
02339          bc->addr= frm->addr;
02340       } else if ( bc->addr < 0) {
02341          cb_log(0, stack->port,"$$$ bc->addr <0 Error:%s\n",strerror(errno));
02342          bc->addr=0;
02343       }
02344       
02345       cb_log(4, stack->port," --> Got Adr %x\n", bc->addr);
02346 
02347       free_msg(msg);
02348    
02349       
02350       switch(bc->bc_state) {
02351       case BCHAN_SETUP:
02352          bc_state_change(bc,BCHAN_SETUPED);
02353       break;
02354 
02355       case BCHAN_CLEAN_REQUEST:
02356       default:
02357          cb_log(0, stack->port," --> STATE WASN'T SETUP (but %s) in SETSTACK|IND pid:%d\n",bc_state2str(bc->bc_state), bc->pid);
02358          clean_up_bc(bc);
02359       }
02360       return 1;
02361 #endif
02362 
02363    case MGR_DELLAYER| INDICATION:
02364       cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->pid);
02365       break;
02366       
02367    case MGR_DELLAYER| CONFIRM:
02368       cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|CNF pid:%d\n",bc->pid);
02369       
02370       bc->pid=0;
02371       bc->addr=0;
02372       
02373       free_msg(msg);
02374       return 1;
02375       
02376    case PH_ACTIVATE | INDICATION:
02377    case DL_ESTABLISH | INDICATION:
02378       cb_log(3, stack->port, "BCHAN: ACT Ind pid:%d\n", bc->pid);
02379 
02380       free_msg(msg);
02381       return 1;    
02382 
02383    case PH_ACTIVATE | CONFIRM:
02384    case DL_ESTABLISH | CONFIRM:
02385       
02386       cb_log(3, stack->port, "BCHAN: bchan ACT Confirm pid:%d\n",bc->pid);
02387       free_msg(msg);
02388       
02389       return 1;    
02390 
02391    case DL_ESTABLISH | REQUEST:
02392       {
02393          char buf[128];
02394          mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN,  DL_ESTABLISH | CONFIRM, 0,0, NULL, TIMEOUT_1SEC);
02395       }
02396       free_msg(msg);
02397       return 1;
02398 
02399    case DL_RELEASE|REQUEST:
02400       {
02401          char buf[128];
02402          mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN,  DL_RELEASE| CONFIRM, 0,0, NULL, TIMEOUT_1SEC);
02403       }
02404       free_msg(msg);
02405       return 1;
02406       
02407    case PH_DEACTIVATE | INDICATION:
02408    case DL_RELEASE | INDICATION:
02409       cb_log (3, stack->port, "BCHAN: DeACT Ind pid:%d\n",bc->pid);
02410       
02411       free_msg(msg);
02412       return 1;
02413     
02414    case PH_DEACTIVATE | CONFIRM:
02415    case DL_RELEASE | CONFIRM:
02416       cb_log(3, stack->port, "BCHAN: DeACT Conf pid:%d\n",bc->pid);
02417       
02418       free_msg(msg);
02419       return 1;
02420     
02421    case PH_CONTROL|INDICATION:
02422    {
02423       unsigned int *cont = (unsigned int *) &frm->data.p;
02424       
02425       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);
02426 
02427       if ((*cont & ~DTMF_TONE_MASK) == DTMF_TONE_VAL) {
02428          int dtmf = *cont & DTMF_TONE_MASK;
02429          cb_log(4, stack->port, " --> DTMF TONE: %c\n",dtmf);
02430          bc->dtmf=dtmf;
02431          cb_event(EVENT_DTMF_TONE, bc, glob_mgr->user_data);
02432    
02433          free_msg(msg);
02434          return 1;
02435       }
02436       if (*cont == BF_REJECT) {
02437          cb_log(4, stack->port, " --> BF REJECT\n");
02438          free_msg(msg);
02439          return 1;
02440       }
02441       if (*cont == BF_ACCEPT) {
02442          cb_log(4, stack->port, " --> BF ACCEPT\n");
02443          free_msg(msg);
02444          return 1;
02445       }
02446    }
02447    break;
02448 
02449    case PH_DATA|REQUEST:
02450    case DL_DATA|REQUEST:
02451       cb_log(0, stack->port, "DL_DATA REQUEST \n");
02452       do_tone(bc, 64);
02453       
02454       free_msg(msg);
02455       return 1;
02456    
02457    
02458    case PH_DATA|INDICATION:
02459    case DL_DATA|INDICATION:
02460    {
02461       bc->bframe = (void*)&frm->data.i;
02462       bc->bframe_len = frm->len;
02463 
02464       /** Anyway flip the bufbits **/
02465       if ( misdn_cap_is_speech(bc->capability) ) 
02466          flip_buf_bits(bc->bframe, bc->bframe_len);
02467    
02468 
02469       if (!bc->bframe_len) {
02470          cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr);
02471          free_msg(msg);
02472          return 1;
02473       }
02474 
02475       if ( (bc->addr&STACK_ID_MASK) != (frm->addr&STACK_ID_MASK) ) {
02476          cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr);
02477          free_msg(msg);
02478          return 1;
02479       }
02480       
02481 #if MISDN_DEBUG
02482       cb_log(0, stack->port, "DL_DATA INDICATION Len %d\n", frm->len);
02483 
02484 #endif
02485       
02486       if ( (bc->bc_state == BCHAN_ACTIVATED) && frm->len > 0) {
02487          int t;
02488 
02489 #ifdef MISDN_B_DEBUG
02490          cb_log(0,bc->port,"do_tone START\n");
02491 #endif
02492          t=do_tone(bc,frm->len);
02493 
02494 #ifdef MISDN_B_DEBUG
02495          cb_log(0,bc->port,"do_tone STOP (%d)\n",t);
02496 #endif
02497          if (  !t ) {
02498             int i;
02499             
02500             if ( misdn_cap_is_speech(bc->capability)) {
02501                if ( !bc->nojitter ) {
02502 #ifdef MISDN_B_DEBUG
02503                   cb_log(0,bc->port,"tx_jitter START\n");
02504 #endif
02505                   misdn_tx_jitter(bc,frm->len);
02506 #ifdef MISDN_B_DEBUG
02507                   cb_log(0,bc->port,"tx_jitter STOP\n");
02508 #endif
02509                }
02510             }
02511 
02512 #ifdef MISDN_B_DEBUG 
02513             cb_log(0,bc->port,"EVENT_B_DATA START\n");
02514 #endif
02515             
02516             i=cb_event( EVENT_BCHAN_DATA, bc, glob_mgr->user_data);
02517 #ifdef MISDN_B_DEBUG 
02518             cb_log(0,bc->port,"EVENT_B_DATA STOP\n");
02519 #endif
02520             
02521             if (i<0) {
02522                cb_log(10,stack->port,"cb_event returned <0\n");
02523                /*clean_up_bc(bc);*/
02524             }
02525          }
02526       }
02527       free_msg(msg);
02528       return 1;
02529    }
02530 
02531 
02532    case PH_CONTROL | CONFIRM:
02533       cb_log(4, stack->port, "PH_CONTROL|CNF bc->addr:%x\n", frm->addr);
02534       free_msg(msg);
02535       return 1;
02536 
02537    case PH_DATA | CONFIRM:
02538    case DL_DATA|CONFIRM:
02539 #if MISDN_DEBUG
02540 
02541       cb_log(0, stack->port, "Data confirmed\n");
02542 
02543 #endif
02544       free_msg(msg);
02545       return 1;
02546    case DL_DATA|RESPONSE:
02547 #if MISDN_DEBUG
02548       cb_log(0, stack->port, "Data response\n");
02549 
02550 #endif
02551       break;
02552    }
02553   
02554    return 0;
02555 }

static int handle_cr ( struct misdn_stack stack,
iframe_t *  frm 
) [static]

Definition at line 1602 of file isdn_lib.c.

References cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), dump_chan_list(), empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, find_bc_by_l3id(), free, glob_mgr, misdn_bchannel::in_use, misdn_bchannel::l3_id, make_dummy(), 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(), handle_frm(), and release_cr().

01603 {
01604    struct misdn_bchannel* bc;
01605    if (!stack) return -1;
01606   
01607    switch (frm->prim) {
01608    case CC_NEW_CR|INDICATION:
01609       cb_log(7, stack->port, " --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo);
01610 
01611       bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0);
01612       if (!bc) {
01613          cb_log(0, stack->port, " --> !! lib: No free channel!\n");
01614          return -1;
01615       }
01616   
01617       cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo);
01618       bc->l3_id=frm->dinfo;
01619       return 1;
01620    case CC_NEW_CR|CONFIRM:
01621       return 1;
01622    case CC_NEW_CR|REQUEST:
01623       return 1;
01624    case CC_RELEASE_CR|REQUEST:
01625       return 1;
01626    case CC_RELEASE_CR|CONFIRM:
01627       break;
01628    case CC_RELEASE_CR|INDICATION:
01629       cb_log(4, stack->port, " --> lib: RELEASE_CR Ind with l3id:%x\n",frm->dinfo);
01630       {
01631          struct misdn_bchannel *bc=find_bc_by_l3id(stack, frm->dinfo);
01632          struct misdn_bchannel dummybc;
01633       
01634          if (!bc) {
01635             cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
01636             make_dummy(&dummybc, stack->port, frm->dinfo, stack->nt, 0);
01637             
01638             bc=&dummybc; 
01639          }
01640       
01641          if (bc) {
01642             int channel = bc->channel;
01643             cb_log(4, stack->port, " --> lib: CLEANING UP l3id: %x\n",frm->dinfo);
01644 
01645             /*bc->pid = 0;*/
01646             bc->need_disconnect=0;
01647             bc->need_release=0;
01648             bc->need_release_complete=0;
01649 
01650             cb_event(EVENT_CLEANUP, bc, glob_mgr->user_data);
01651 
01652             empty_bc(bc);
01653             clean_up_bc(bc);
01654 
01655             if (channel>0)
01656                empty_chan_in_stack(stack,channel);
01657             bc->in_use=0;
01658 
01659             dump_chan_list(stack);
01660 
01661             if (bc->stack_holder) {
01662                cb_log(4,stack->port, "REMOVEING Holder\n");
01663                stack_holder_remove( stack, bc);
01664                free(bc);
01665             }
01666          }
01667          else {
01668             if (stack->nt) 
01669                cb_log(4, stack->port, "BC with dinfo: %x  not found.. (prim was %x and addr %x)\n",frm->dinfo, frm->prim, frm->addr);
01670          }
01671       
01672          return 1;
01673       }
01674       break;
01675    }
01676   
01677    return 0;
01678 }

static int handle_err ( msg_t *  msg  )  [static]

Definition at line 3528 of file isdn_lib.c.

References misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), cb_log, misdn_bchannel::channel, find_bc_by_channel(), find_stack_by_port(), handle_bchan(), misdn_stack::l1link, misdn_stack::l2link, misdn_lib_get_l1_down(), misdn_lib_get_l2_down(), and misdn_bchannel::port.

Referenced by manager_isdn_handler().

03529 {
03530    iframe_t *frm = (iframe_t*) msg->data;
03531 
03532 
03533    if (!frm->addr) {
03534       static int cnt=0;
03535       if (!cnt)
03536          cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo);
03537       cnt++;
03538       if (cnt>100) {
03539          cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo);
03540          cnt=0;
03541       }
03542       
03543       free_msg(msg);
03544       return 1;
03545       
03546    }
03547    
03548    switch (frm->prim) {
03549       case MGR_SETSTACK|INDICATION:
03550          return handle_bchan(msg);
03551       break;
03552 
03553       case MGR_SETSTACK|CONFIRM:
03554       case MGR_CLEARSTACK|CONFIRM:
03555          free_msg(msg) ; 
03556          return 1;
03557       break;
03558 
03559       case DL_DATA|CONFIRM:
03560          cb_log(4,0,"DL_DATA|CONFIRM\n");
03561          free_msg(msg);
03562          return 1;
03563 
03564       case PH_CONTROL|CONFIRM:
03565          cb_log(4,0,"PH_CONTROL|CONFIRM\n");
03566          free_msg(msg);
03567          return 1;
03568 
03569       case DL_DATA|INDICATION:
03570       {
03571          struct misdn_bchannel *bc;
03572          int port=(frm->addr&MASTER_ID_MASK) >> 8;
03573          int channel=(frm->addr&CHILD_ID_MASK) >> 16;
03574 
03575          /*we flush the read buffer here*/
03576          
03577          cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel);
03578          
03579          free_msg(msg) ; 
03580          return 1;
03581          
03582          
03583          bc=find_bc_by_channel( port , channel);
03584 
03585          if (!bc) {
03586             struct misdn_stack *stack=find_stack_by_port( port );
03587 
03588             if (!stack) {
03589                cb_log(0,0," --> stack not found\n");
03590                free_msg(msg);
03591                return 1;
03592             }
03593             
03594             cb_log(0,0," --> bc not found by channel\n");
03595             if (stack->l2link)
03596                misdn_lib_get_l2_down(stack);
03597 
03598             if (stack->l1link)
03599                misdn_lib_get_l1_down(stack);
03600 
03601             free_msg(msg);
03602             return 1;
03603          }
03604          
03605          cb_log(3,port," --> BC in state:%s\n", bc_state2str(bc->bc_state));
03606       }
03607    }
03608 
03609    return 0;
03610 }

static int handle_event ( struct misdn_bchannel bc,
enum event_e  event,
iframe_t *  frm 
) [static]

Definition at line 1519 of file isdn_lib.c.

References misdn_stack::bc, cb_log, EVENT_ALERTING, EVENT_CONNECT, EVENT_CONNECT_ACKNOWLEDGE, EVENT_PROCEEDING, EVENT_PROGRESS, EVENT_RELEASE, EVENT_RELEASE_COMPLETE, EVENT_SETUP, EVENT_SETUP_ACKNOWLEDGE, find_free_chan_in_stack(), get_stack_by_bc(), manager_ec_enable(), manager_ph_control(), manager_ph_control_block(), misdn_cap_is_speech(), misdn_lib_send_event(), misdn_stack::nt, misdn_stack::port, misdn_stack::pri, misdn_stack::ptp, and setup_bc().

Referenced by handle_frm().

01520 {
01521    struct misdn_stack *stack=get_stack_by_bc(bc);
01522    
01523    if (!stack->nt) {
01524       
01525       switch (event) {
01526 
01527       case EVENT_CONNECT_ACKNOWLEDGE:
01528          setup_bc(bc);
01529 
01530          if ( *bc->crypt_key ) {
01531             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);
01532             manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
01533          }
01534 
01535          if (misdn_cap_is_speech(bc->capability)) {
01536             if (  !bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0);
01537             manager_ec_enable(bc);
01538 
01539             if ( bc->txgain != 0 ) {
01540                cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain);
01541                manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
01542             }
01543             if ( bc->rxgain != 0 ) {
01544                cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain);
01545                manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
01546             }
01547          }
01548 
01549          break;
01550       case EVENT_CONNECT:
01551 
01552          if ( *bc->crypt_key ) {
01553             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);
01554             manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
01555          }
01556       case EVENT_ALERTING:
01557       case EVENT_PROGRESS:
01558       case EVENT_PROCEEDING:
01559       case EVENT_SETUP_ACKNOWLEDGE:
01560       case EVENT_SETUP:
01561       {
01562          if (bc->channel == 0xff || bc->channel<=0)
01563             bc->channel=0;
01564 
01565          if (find_free_chan_in_stack(stack, bc, bc->channel, 0)<0){
01566             if (!stack->pri && !stack->ptp)  {
01567                bc->cw=1;
01568                break;
01569             }
01570 
01571             if (!bc->channel)
01572                cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n");
01573             else 
01574                cb_log(0, stack->port, "Requested Channel Already in Use releasing this call with cause 34!!!!\n");
01575 
01576             /* when the channel is already in use, we can't
01577              * simply clear it, we need to make sure that 
01578              * it will still be marked as in_use in the 
01579              * available channels list.*/
01580             bc->channel=0;
01581 
01582             misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
01583             return -1;
01584          }
01585       }
01586 
01587       setup_bc(bc);
01588       break;
01589 
01590       case EVENT_RELEASE_COMPLETE:
01591       case EVENT_RELEASE:
01592          break;
01593       default:
01594          break;
01595       }
01596    } else {    /** NT MODE **/
01597       
01598    }
01599    return 0;
01600 }

int handle_event_nt ( void *  dat,
void *  arg 
) [static]

Definition at line 1813 of file isdn_lib.c.

References misdn_bchannel::b_stid, misdn_stack::bc, misdn_bchannel::cause, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), create_l3msg(), empty_bc(), empty_chan_in_stack(), event, 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, misdn_bchannel::in_use, isdn_get_info(), isdn_msg_get_event(), isdn_msg_parse_event(), misdn_stack::l1link, misdn_stack::l2link, misdn_stack::l2upcnt, misdn_bchannel::l3_id, make_dummy(), misdn_lib_get_free_bc(), misdn_lib_get_l2_up(), misdn_lib_reinit_nt_stack(), misdn_lib_send_event(), misdn_lib_send_restart(), mISDNUSER_HEAD_SIZE, msgs_g, misdn_stack::nst, misdn_stack::nt, misdn_bchannel::port, misdn_stack::port, misdn_stack::procids, misdn_stack::ptp, release_cr(), misdn_stack::restart_sent, stack_holder_find(), stack_holder_remove(), misdn_stack::upper_id, and misdn_lib::user_data.

Referenced by misdn_lib_reinit_nt_stack().

01814 {
01815    manager_t *mgr = (manager_t *)dat;
01816    msg_t *msg = (msg_t *)arg;
01817    mISDNuser_head_t *hh;
01818    int reject=0;
01819 
01820    struct misdn_stack *stack=find_stack_by_mgr(mgr);
01821    int port;
01822 
01823    if (!msg || !mgr)
01824       return(-EINVAL);
01825 
01826    hh=(mISDNuser_head_t*)msg->data;
01827    port=stack->port;
01828    
01829    cb_log(5, stack->port, " --> lib: prim %x dinfo %x\n",hh->prim, hh->dinfo);
01830    {
01831       switch(hh->prim){
01832       case CC_RETRIEVE|INDICATION:
01833       {
01834          struct misdn_bchannel *bc;
01835          struct misdn_bchannel *hold_bc;
01836          iframe_t frm; /* fake te frm to add callref to global callreflist */
01837          frm.dinfo = hh->dinfo;
01838 
01839          frm.addr=stack->upper_id | FLG_MSG_DOWN;
01840 
01841          frm.prim = CC_NEW_CR|INDICATION;
01842          
01843          if (handle_cr( stack, &frm)< 0) {
01844             msg_t *dmsg;
01845             cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo);
01846             dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
01847             stack->nst.manager_l3(&stack->nst, dmsg);
01848             free_msg(msg);
01849             return 0;
01850          }
01851          
01852          bc=find_bc_by_l3id(stack, hh->dinfo);
01853          hold_bc=stack_holder_find(stack,bc->l3_id);
01854          cb_log(4, stack->port, "bc_l3id:%x holded_bc_l3id:%x\n",bc->l3_id, hold_bc->l3_id);
01855 
01856          if (hold_bc) {
01857             cb_log(4, stack->port, "REMOVEING Holder\n");
01858 
01859             /*swap the backup to our new channel back*/
01860             stack_holder_remove(stack, hold_bc);
01861             memcpy(bc,hold_bc,sizeof(struct misdn_bchannel));
01862             free(hold_bc);
01863 
01864             bc->holded=0;
01865             bc->b_stid=0;
01866          }
01867          
01868       }
01869          
01870          break;
01871          
01872       case CC_SETUP|CONFIRM:
01873       {
01874          struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
01875          int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE));
01876          cb_log(4, stack->port, " --> lib: Event_ind:SETUP CONFIRM [NT] : new L3ID  is %x\n",l3id );
01877    
01878          if (!bc) { cb_log(4, stack->port, "Bc Not found (after SETUP CONFIRM)\n"); return 0; }
01879          cb_log (2,bc->port,"I IND :CC_SETUP|CONFIRM: old l3id:%x new l3id:%x\n", bc->l3_id, l3id);
01880          bc->l3_id=l3id;
01881          cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data);
01882       }
01883       free_msg(msg);
01884       return 0;
01885       
01886       case CC_SETUP|INDICATION:
01887       {
01888          struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0);
01889          if (!bc) 
01890          ERR_NO_CHANNEL:
01891          {
01892             msg_t *dmsg;
01893             cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo);
01894             dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
01895             stack->nst.manager_l3(&stack->nst, dmsg);
01896             free_msg(msg);
01897             return 0;
01898          }
01899   
01900          cb_log(4, stack->port, " --> new_process: New L3Id: %x\n",hh->dinfo);
01901          bc->l3_id=hh->dinfo;
01902       }
01903       break;
01904 
01905       case CC_CONNECT_ACKNOWLEDGE|INDICATION:
01906       break;
01907       
01908       case CC_ALERTING|INDICATION:
01909       case CC_PROCEEDING|INDICATION:
01910       case CC_SETUP_ACKNOWLEDGE|INDICATION:
01911          if(!stack->ptp) break;  
01912       case CC_CONNECT|INDICATION:
01913       break;
01914       case CC_DISCONNECT|INDICATION:
01915       {
01916          struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
01917          if (!bc) {
01918             bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000);
01919             if (bc) { 
01920                int myprocid=bc->l3_id&0x0000ffff;
01921                hh->dinfo=(hh->dinfo&0xffff0000)|myprocid;
01922                cb_log(3,stack->port,"Reject dinfo: %x cause:%d\n",hh->dinfo,bc->cause);
01923                reject=1;      
01924             }
01925          }
01926       }
01927       break;
01928       
01929       case CC_FACILITY|INDICATION:
01930       {
01931          struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
01932          if (!bc) {
01933             bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000);
01934             if (bc) { 
01935                int myprocid=bc->l3_id&0x0000ffff;
01936                hh->dinfo=(hh->dinfo&0xffff0000)|myprocid;
01937                cb_log(4,bc->port,"Repaired reject Bug, new dinfo: %x\n",hh->dinfo);
01938             }
01939          }
01940       }
01941       break;
01942       
01943       case CC_RELEASE_COMPLETE|INDICATION:
01944          break;
01945 
01946       case CC_SUSPEND|INDICATION:
01947       {
01948          msg_t *dmsg;
01949          cb_log(4, stack->port, " --> Got Suspend, sending Reject for now\n");
01950          dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST,MT_SUSPEND_REJECT, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
01951          stack->nst.manager_l3(&stack->nst, dmsg);
01952          free_msg(msg);
01953          return 0;
01954       }
01955       break;
01956       case CC_RESUME|INDICATION:
01957          break;
01958 
01959       case CC_RELEASE|CONFIRM:
01960          {
01961             struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
01962 
01963             if (bc) { 
01964                cb_log(1, stack->port, "CC_RELEASE|CONFIRM (l3id:%x), sending RELEASE_COMPLETE\n", hh->dinfo);
01965                misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE);
01966             }
01967          }
01968          break;
01969          
01970       case CC_RELEASE|INDICATION:
01971          break;
01972 
01973       case CC_RELEASE_CR|INDICATION:
01974          release_cr(stack, hh);
01975          free_msg(msg);
01976          return 0 ;
01977       break;
01978       
01979       case CC_NEW_CR|INDICATION:
01980          /*  Got New CR for bchan, for now I handle this one in */
01981          /*  connect_ack, Need to be changed */
01982       {
01983          struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
01984          int l3id = *((int *)(((u_char *)msg->data)+ mISDNUSER_HEAD_SIZE));
01985          if (!bc) { cb_log(0, stack->port, " --> In NEW_CR: didn't found bc ??\n"); return -1;};
01986          if (((l3id&0xff00)!=0xff00) && ((bc->l3_id&0xff00)==0xff00)) {
01987             cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", 0xff&bc->l3_id);
01988             stack->procids[bc->l3_id&0xff] = 0 ;
01989          }
01990          cb_log(4, stack->port, "lib: Event_ind:CC_NEW_CR : very new L3ID  is %x\n",l3id );
01991    
01992          bc->l3_id =l3id;
01993          cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data);
01994    
01995          free_msg(msg);
01996          return 0;
01997       }
01998       
01999       case DL_ESTABLISH | INDICATION:
02000       case DL_ESTABLISH | CONFIRM:
02001       {
02002          cb_log(3, stack->port, "%% GOT L2 Activate Info.\n");
02003          
02004          if (stack->ptp && stack->l2link) {
02005             cb_log(0, stack->port, "%% GOT L2 Activate Info. but we're activated already.. this l2 is faulty, blocking port\n");
02006             cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data);
02007          }
02008 
02009          if (stack->ptp && !stack->restart_sent) {
02010             /* make sure we restart the interface of the 
02011              * other side */
02012             stack->restart_sent=1;
02013             misdn_lib_send_restart(stack->port, -1);
02014 
02015          }
02016       
02017          /* when we get the L2 UP, the L1 is UP definitely too*/
02018          stack->l1link = 1;
02019          stack->l2link = 1;
02020          stack->l2upcnt=0;
02021          
02022          free_msg(msg);
02023          return 0;
02024       }
02025       break;
02026 
02027 
02028       case DL_RELEASE | INDICATION:
02029       case DL_RELEASE | CONFIRM:
02030       {
02031          if (stack->ptp) {
02032             cb_log(3 , stack->port, "%% GOT L2 DeActivate Info.\n");
02033 
02034             if (stack->l2upcnt>3) {
02035                cb_log(0 , stack->port, "!!! Could not Get the L2 up after 3 Attemps!!!\n");
02036             }  else {
02037 #if 0
02038                if (stack->nt) misdn_lib_reinit_nt_stack(stack->port);
02039 #endif
02040                if (stack->l1link) {
02041                   misdn_lib_get_l2_up(stack);
02042                   stack->l2upcnt++;
02043                }
02044             }
02045             
02046          } else 
02047             cb_log(3, stack->port, "%% GOT L2 DeActivate Info.\n");
02048          
02049          stack->l2link = 0;
02050          free_msg(msg);
02051          return 0;
02052       }
02053       break;
02054       }
02055    }
02056    
02057    {
02058       /*  Parse Events and fire_up to App. */
02059       struct misdn_bchannel *bc;
02060       struct misdn_bchannel dummybc;
02061       
02062       enum event_e event = isdn_msg_get_event(msgs_g, msg, 1);
02063     
02064       bc=find_bc_by_l3id(stack, hh->dinfo);
02065     
02066       if (!bc) {
02067          cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x).\n", hh->dinfo);
02068          make_dummy(&dummybc, stack->port,  hh->dinfo, stack->nt, 0);
02069          bc=&dummybc; 
02070       }
02071       if (bc ) {
02072          isdn_msg_parse_event(msgs_g,msg,bc, 1);
02073 
02074          switch (event) {
02075             int channel;
02076             int tmpcause;  
02077             case EVENT_SETUP:
02078                if (bc->channel<=0 || bc->channel==0xff) 
02079                   bc->channel=0;
02080             
02081                if (find_free_chan_in_stack(stack,bc, bc->channel,0)<0) 
02082                   goto ERR_NO_CHANNEL;
02083                break;
02084             case EVENT_RELEASE:
02085             case EVENT_RELEASE_COMPLETE:
02086                {
02087                channel=bc->channel;
02088                tmpcause=bc->cause;  
02089                          empty_bc(bc);
02090                bc->cause=tmpcause;
02091                clean_up_bc(bc);
02092 
02093                if (channel>0)
02094                                  empty_chan_in_stack(stack,channel);
02095                bc->in_use=0;
02096                }
02097                break;
02098 
02099             default:
02100             break;
02101          }
02102          
02103          if(!isdn_get_info(msgs_g,event,1)) {
02104             cb_log(4, stack->port, "Unknown Event Ind: prim %x dinfo %x\n",hh->prim, hh->dinfo);
02105          } else {
02106             if (reject) {
02107                switch(bc->cause){
02108                   case 17:
02109                      cb_log(1, stack->port, "Siemens Busy reject..\n");
02110 
02111                      break;
02112                   default:
02113                      break;
02114                }
02115             }
02116             cb_event(event, bc, glob_mgr->user_data);
02117          }
02118       } else {
02119          cb_log(4, stack->port, "No BC found with l3id: prim %x dinfo %x\n",hh->prim, hh->dinfo);
02120       }
02121 
02122       free_msg(msg);
02123    }
02124 
02125 
02126    return 0;
02127 }

static int handle_frm ( msg_t *  msg  )  [static]

Definition at line 2594 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_RESTART, EVENT_SETUP, find_bc_by_l3id(), find_stack_by_addr(), glob_mgr, handle_cr(), handle_event(), misdn_bchannel::in_use, isdn_get_info(), isdn_msg_get_event(), isdn_msg_parse_event(), make_dummy(), misdn_lib_send_event(), misdn_lib_send_restart(), msgs_g, misdn_bchannel::out_cause, misdn_bchannel::port, RESPONSE_IGNORE_SETUP, RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE, RESPONSE_OK, RESPONSE_RELEASE_SETUP, misdn_bchannel::restart_channel, set_chan_in_stack(), and misdn_lib::user_data.

Referenced by manager_event_handler(), and manager_isdn_handler().

02595 {
02596    iframe_t *frm = (iframe_t*) msg->data;
02597    
02598    struct misdn_stack *stack=find_stack_by_addr(frm->addr);
02599 
02600    if (!stack || stack->nt) {
02601       return 0;
02602    }
02603    
02604    cb_log(4,stack?stack->port:0,"handle_frm: frm->addr:%x frm->prim:%x\n",frm->addr,frm->prim);
02605 
02606    {
02607       struct misdn_bchannel dummybc;
02608       struct misdn_bchannel *bc;
02609       int ret=handle_cr(stack, frm);
02610 
02611       if (ret<0) {
02612          cb_log(3,stack?stack->port:0,"handle_frm: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr);
02613 
02614 
02615       }
02616 
02617       if(ret) {
02618          free_msg(msg);
02619          return 1;
02620       }
02621     
02622       bc=find_bc_by_l3id(stack, frm->dinfo);
02623 
02624       if (!bc && (frm->prim==(CC_RESTART|CONFIRM)) ) {
02625          make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0);
02626          bc=&dummybc;
02627       }
02628 
02629       if (!bc && (frm->prim==(CC_SETUP|INDICATION)) ) {
02630          make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0);
02631          dummybc.port=stack->port;
02632          dummybc.l3_id=frm->dinfo;
02633          bc=&dummybc;
02634 
02635          misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
02636 
02637          free_msg(msg);
02638          return 1;
02639       }
02640 
02641     
02642 handle_frm_bc:
02643       if (bc ) {
02644          int ret;
02645          enum event_e event = isdn_msg_get_event(msgs_g, msg, 0);
02646          enum event_response_e response=RESPONSE_OK;
02647       
02648          isdn_msg_parse_event(msgs_g,msg,bc, 0);
02649          
02650          /** Preprocess some Events **/
02651          ret=handle_event(bc, event, frm);
02652          if (ret<0) {
02653             cb_log(0,stack->port,"couldn't handle event\n");
02654             free_msg(msg);
02655             return 1;
02656          }
02657          /*  shoot up event to App: */
02658          cb_log(5, stack->port, "lib Got Prim: Addr %x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo);
02659       
02660          if(!isdn_get_info(msgs_g,event,0)) 
02661             cb_log(0, stack->port, "Unknown Event Ind: Addr:%x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo);
02662          else
02663             response=cb_event(event, bc, glob_mgr->user_data);
02664 #if 1
02665          if (event == EVENT_SETUP) {
02666             switch (response) {
02667             case RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE:
02668 
02669                cb_log(0, stack->port, "TOTALY IGNORING SETUP \n");               
02670                
02671                break;
02672             case RESPONSE_IGNORE_SETUP:
02673                /* I think we should send CC_RELEASE_CR, but am not sure*/
02674                bc->out_cause=16;
02675             
02676             case RESPONSE_RELEASE_SETUP:
02677                misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
02678                if (bc->channel>0)
02679                   empty_chan_in_stack(stack, bc->channel);
02680                empty_bc(bc);
02681                bc_state_change(bc,BCHAN_CLEANED);
02682                bc->in_use=0;
02683 
02684                cb_log(0, stack->port, "GOT IGNORE SETUP\n");
02685                break;
02686             case RESPONSE_OK:
02687                cb_log(4, stack->port, "GOT SETUP OK\n");
02688 
02689                
02690                break;
02691             default:
02692                break;
02693             }
02694          }
02695 
02696          if (event == EVENT_RELEASE_COMPLETE) {
02697             /* release bchannel only after we've anounced the RELEASE_COMPLETE */
02698             int channel=bc->channel;
02699             int tmpcause=bc->cause; 
02700             int tmp_out_cause=bc->out_cause; 
02701             empty_bc(bc);
02702             bc->cause=tmpcause;
02703             bc->out_cause=tmp_out_cause;
02704             clean_up_bc(bc);
02705             
02706             if (tmpcause == 44) {
02707                cb_log(0,stack->port,"**** Received CAUSE:44, so not cleaning up channel %d\n", channel);
02708                cb_log(0,stack->port,"**** This channel is now no longer available,\nplease try to restart it with 'misdn send restart <port> <channel>'\n");
02709                set_chan_in_stack(stack, channel);
02710                bc->channel=channel;
02711                misdn_lib_send_restart(stack->port, channel);
02712             } else {
02713                if (channel>0)
02714                   empty_chan_in_stack(stack, channel);
02715             }
02716             bc->in_use=0;
02717          }
02718 
02719          if (event == EVENT_RESTART) {
02720             cb_log(0, stack->port, "**** Received RESTART_ACK channel:%d\n", bc->restart_channel);
02721             empty_chan_in_stack(stack, bc->restart_channel);
02722          }
02723 
02724          cb_log(5, stack->port, "Freeing Msg on prim:%x \n",frm->prim);
02725 
02726          
02727          free_msg(msg);
02728          return 1;
02729 #endif
02730       
02731       } else {
02732          struct misdn_bchannel dummybc;
02733          cb_log(0, stack->port, " --> Didn't find BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
02734          memset (&dummybc,0,sizeof(dummybc));
02735          dummybc.port=stack->port;
02736          dummybc.l3_id=frm->dinfo;
02737          bc=&dummybc; 
02738          goto handle_frm_bc;
02739       }
02740    }
02741 
02742    cb_log(4, stack->port, "TE_FRM_HANDLER: Returning 0 on prim:%x \n",frm->prim);
02743    return 0;
02744 }

static int handle_frm_nt ( msg_t *  msg  )  [static]

Definition at line 2559 of file isdn_lib.c.

References cb_log, find_stack_by_addr(), and nt_err_cnt.

Referenced by manager_event_handler(), and manager_isdn_handler().

02560 {
02561    iframe_t *frm= (iframe_t*)msg->data;
02562    struct misdn_stack *stack;
02563    int err=0;
02564 
02565    stack=find_stack_by_addr( frm->addr );
02566 
02567    
02568   
02569    if (!stack || !stack->nt) {
02570       return 0;
02571    }
02572 
02573    
02574    if ((err=stack->nst.l1_l2(&stack->nst,msg))) {
02575     
02576       if (nt_err_cnt > 0 ) {
02577          if (nt_err_cnt < 100) {
02578             nt_err_cnt++; 
02579             cb_log(0, stack->port, "NT Stack sends us error: %d \n", err);
02580          } else if (nt_err_cnt < 105){
02581             cb_log(0, stack->port, "NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err);
02582             nt_err_cnt = - 1; 
02583          }
02584       }
02585       free_msg(msg);
02586       return 1;
02587       
02588    }
02589    
02590    return 1;
02591 }

static int handle_l1 ( msg_t *  msg  )  [static]

Definition at line 2747 of file isdn_lib.c.

References cb_event, cb_log, EVENT_CLEANUP, EVENT_NOTHING, find_stack_by_addr(), glob_mgr, global_state, isdn_get_info(), MISDN_INITIALIZED, misdn_lib_get_l2_up(), misdn_lib_send_event(), msgs_g, and misdn_lib::user_data.

Referenced by manager_isdn_handler().

02748 {
02749    iframe_t *frm = (iframe_t*) msg->data;
02750    struct misdn_stack *stack = find_stack_by_addr(frm->addr);
02751    int i ;
02752    
02753    if (!stack) return 0 ;
02754 
02755    switch (frm->prim) {
02756    case PH_ACTIVATE | CONFIRM:
02757    case PH_ACTIVATE | INDICATION:
02758       cb_log (3, stack->port, "L1: PH L1Link Up!\n");
02759       stack->l1link=1;
02760       
02761       if (stack->nt) {
02762          
02763          if (stack->nst.l1_l2(&stack->nst, msg))
02764             free_msg(msg);
02765 
02766          if (stack->ptp)
02767             misdn_lib_get_l2_up(stack);
02768       } else {
02769          free_msg(msg);
02770       }
02771       
02772       for (i=0;i<=stack->b_num; i++) {
02773          if (stack->bc[i].evq != EVENT_NOTHING) {
02774             cb_log(4, stack->port, "Fireing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0));
02775             misdn_lib_send_event(&stack->bc[i],stack->bc[i].evq);
02776             stack->bc[i].evq=EVENT_NOTHING;
02777          }
02778          
02779       }
02780       return 1;
02781 
02782    case PH_ACTIVATE | REQUEST:
02783       free_msg(msg);
02784       cb_log(3,stack->port,"L1: PH_ACTIVATE|REQUEST \n");
02785       return 1;
02786       
02787    case PH_DEACTIVATE | REQUEST:
02788       free_msg(msg);
02789       cb_log(3,stack->port,"L1: PH_DEACTIVATE|REQUEST \n");
02790       return 1;
02791       
02792    case PH_DEACTIVATE | CONFIRM:
02793    case PH_DEACTIVATE | INDICATION:
02794       cb_log (3, stack->port, "L1: PH L1Link Down! \n");
02795    
02796 #if 0
02797       for (i=0; i<=stack->b_num; i++) {
02798          if (global_state == MISDN_INITIALIZED)  {
02799             cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data);
02800          }
02801       }
02802 #endif
02803       
02804       if (stack->nt) {
02805          if (stack->nst.l1_l2(&stack->nst, msg))
02806             free_msg(msg);
02807       } else {
02808          free_msg(msg);
02809       }
02810       
02811       stack->l1link=0;
02812       stack->l2link=0;
02813       return 1;
02814    }
02815   
02816    return 0;
02817 }

static int handle_l2 ( msg_t *  msg  )  [static]

Definition at line 2819 of file isdn_lib.c.

References cb_event, cb_log, EVENT_PORT_ALARM, find_stack_by_addr(), glob_mgr, and misdn_lib::user_data.

Referenced by manager_isdn_handler().

02820 {
02821    iframe_t *frm = (iframe_t*) msg->data;
02822 
02823    struct misdn_stack *stack = find_stack_by_addr(frm->addr);
02824    
02825    if (!stack) {
02826       return 0 ;
02827    }
02828    
02829    switch(frm->prim) {
02830 
02831    case DL_ESTABLISH | REQUEST:
02832       cb_log(1,stack->port,"DL_ESTABLISH|REQUEST \n");
02833       return 1;
02834    case DL_RELEASE | REQUEST:
02835       cb_log(1,stack->port,"DL_RELEASE|REQUEST \n");
02836       return 1;
02837       
02838    case DL_ESTABLISH | INDICATION:
02839    case DL_ESTABLISH | CONFIRM:
02840    {
02841       cb_log (3, stack->port, "L2: L2Link Up! \n");
02842       if (stack->ptp && stack->l2link) {
02843          cb_log (-1, stack->port, "L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n"); 
02844          cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data);
02845       }
02846       stack->l2link=1;
02847       free_msg(msg);
02848       return 1;
02849    }
02850    break;
02851     
02852    case DL_RELEASE | INDICATION:
02853    case DL_RELEASE | CONFIRM:
02854    {
02855       cb_log (3, stack->port, "L2: L2Link Down! \n");
02856       stack->l2link=0;
02857       
02858       free_msg(msg);
02859       return 1;
02860    }
02861    break;
02862    }
02863    return 0;
02864 }

static int handle_mgmt ( msg_t *  msg  )  [static]

Definition at line 2866 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().

02867 {
02868    struct misdn_stack *stack;
02869    iframe_t *frm = (iframe_t*) msg->data;
02870 
02871    if ( (frm->addr == 0) && (frm->prim == (MGR_DELLAYER|CONFIRM)) ) {
02872       cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: 0 !\n") ;
02873       free_msg(msg);
02874       return 1;
02875    }
02876    
02877    stack=find_stack_by_addr(frm->addr);
02878    
02879    if (!stack) {
02880       if (frm->prim == (MGR_DELLAYER|CONFIRM)) {
02881          cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: %x !\n",
02882                frm->addr) ;
02883          free_msg(msg);
02884          return 1;
02885       }
02886       
02887       return 0;
02888    }
02889    
02890    switch(frm->prim) {
02891    case MGR_SHORTSTATUS | INDICATION:
02892    case MGR_SHORTSTATUS | CONFIRM:
02893       cb_log(5, 0, "MGMT: Short status dinfo %x\n",frm->dinfo);
02894       
02895       switch (frm->dinfo) {
02896       case SSTATUS_L1_ACTIVATED:
02897          cb_log(3, 0, "MGMT: SSTATUS: L1_ACTIVATED \n");
02898          stack->l1link=1;
02899       
02900          break;
02901       case SSTATUS_L1_DEACTIVATED:
02902          cb_log(3, 0, "MGMT: SSTATUS: L1_DEACTIVATED \n");
02903          stack->l1link=0;
02904 #if 0
02905          clear_l3(stack);
02906 #endif
02907          break;
02908 
02909       case SSTATUS_L2_ESTABLISHED:
02910          cb_log(3, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n");
02911 
02912          /*when the L2 goes UP, L1 needs to be UP too*/
02913          stack->l1link=1;
02914          stack->l2link=1;
02915          break;
02916          
02917       case SSTATUS_L2_RELEASED:
02918          cb_log(3, stack->port, "MGMT: SSTATUS: L2_RELEASED \n");
02919          stack->l2link=0;
02920          break;
02921       }
02922       
02923       free_msg(msg);
02924       return 1;
02925       
02926    case MGR_SETSTACK | INDICATION:
02927       cb_log(4, stack->port, "MGMT: SETSTACK|IND dinfo %x\n",frm->dinfo);
02928       free_msg(msg);
02929       return 1;
02930    case MGR_DELLAYER | CONFIRM:
02931       cb_log(4, stack->port, "MGMT: DELLAYER|CNF dinfo %x\n",frm->dinfo) ;
02932       free_msg(msg);
02933       return 1;
02934       
02935    }
02936    
02937    /*
02938    if ( (frm->prim & 0x0f0000) ==  0x0f0000) {
02939    cb_log(5, 0, "$$$ MGMT FRAME: prim %x addr %x dinfo %x\n",frm->prim, frm->addr, frm->dinfo) ;
02940    free_msg(msg);
02941    return 1;
02942    } */
02943     
02944    return 0;
02945 }

static int handle_timers ( msg_t *  msg  )  [static]

Definition at line 2130 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().

02131 {
02132    iframe_t *frm= (iframe_t*)msg->data;
02133    struct misdn_stack *stack; 
02134   
02135    /* Timer Stuff */
02136    switch (frm->prim) {
02137    case MGR_INITTIMER | CONFIRM:
02138    case MGR_ADDTIMER | CONFIRM:
02139    case MGR_DELTIMER | CONFIRM:
02140    case MGR_REMOVETIMER | CONFIRM:
02141       free_msg(msg);
02142       return(1);
02143    }
02144   
02145   
02146   
02147    if (frm->prim==(MGR_TIMER | INDICATION) ) {
02148       for (stack = glob_mgr->stack_list;
02149            stack;
02150            stack = stack->next) {
02151          itimer_t *it;
02152       
02153          if (!stack->nt) continue;
02154       
02155          it = stack->nst.tlist;
02156          /* find timer */
02157          for(it=stack->nst.tlist;
02158              it;
02159              it=it->next) {
02160             if (it->id == (int)frm->addr)
02161                break;
02162          }
02163          if (it) {
02164             int ret;
02165             ret = mISDN_write_frame(stack->midev, msg->data, frm->addr,
02166                      MGR_TIMER | RESPONSE, 0, 0, NULL, TIMEOUT_1SEC);
02167             test_and_clear_bit(FLG_TIMER_RUNING, (long unsigned int *)&it->Flags);
02168             ret = it->function(it->data);
02169             free_msg(msg);
02170             return 1;
02171          }
02172       }
02173     
02174       cb_log(0, 0, "Timer Msg without Timer ??\n");
02175       free_msg(msg);
02176       return 1;
02177    }
02178   
02179    return 0;
02180 }

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 1128 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, misdn_stack::pri, misdn_bchannel::pri, pthread_mutex_init, and misdn_bchannel::send_lock.

Referenced by misdn_lib_init().

01129 {
01130    unsigned char buff[1025] = "";
01131    iframe_t *frm = (iframe_t *)buff;
01132    int ret;
01133   
01134    if (!bc) return -1;
01135   
01136    cb_log(8, port, "Init.BC %d.\n",bidx);
01137    
01138    memset(bc, 0,sizeof(struct misdn_bchannel));
01139 
01140    bc->send_lock=malloc(sizeof(struct send_lock));
01141 
01142    pthread_mutex_init(&bc->send_lock->lock, NULL);
01143    
01144    if (msn) {
01145       int l = sizeof(bc->msn);
01146       strncpy(bc->msn,msn, l);
01147       bc->msn[l-1] = 0;
01148    }
01149    
01150    
01151    empty_bc(bc);
01152    bc_state_change(bc, BCHAN_CLEANED);
01153    
01154    bc->port=stack->port;
01155    bc->nt=stack->nt?1:0;
01156    bc->pri=stack->pri;
01157    
01158    {
01159       ibuffer_t* ibuf= init_ibuffer(MISDN_IBUF_SIZE);
01160 
01161       if (!ibuf) return -1;
01162       
01163       clear_ibuffer( ibuf);
01164       
01165       ibuf->rsem=malloc(sizeof(sem_t));
01166       
01167       bc->astbuf=ibuf;
01168 
01169       if (sem_init(ibuf->rsem,1,0)<0)
01170          sem_init(ibuf->rsem,0,0);
01171       
01172    }
01173    
01174    {
01175       stack_info_t *stinf;
01176       ret = mISDN_get_stack_info(midev, stack->port, buff, sizeof(buff));
01177       if (ret < 0) {
01178          cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret);
01179          return -1;
01180       }
01181     
01182       stinf = (stack_info_t *)&frm->data.p;
01183     
01184       cb_log(8, port, " --> Child %x\n",stinf->child[bidx]);
01185    }
01186   
01187    return 0;
01188 }

static void init_flip_bits ( void   )  [static]

Definition at line 294 of file isdn_lib.c.

References flip_table.

Referenced by misdn_lib_init().

00295 {
00296    int i,k;
00297    
00298    for (i = 0 ; i < 256 ; i++) {
00299       unsigned char sample = 0 ;
00300       for (k = 0; k<8; k++) {
00301          if ( i & 1 << k ) sample |= 0x80 >>  k;
00302       }
00303       flip_table[i] = sample;
00304    }
00305 }

void isdn_lib_stop_dtmf ( struct misdn_bchannel bc  ) 

Definition at line 4266 of file isdn_lib.c.

References misdn_stack::bc, and manager_ph_control().

Referenced by process_ast_dsp().

04267 {
04268    manager_ph_control(bc, DTMF_TONE_STOP, 0);
04269 }

void isdn_lib_update_ec ( struct misdn_bchannel bc  ) 

Definition at line 4254 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().

04255 {
04256 #ifdef MISDN_1_2
04257    if (*bc->pipeline)
04258 #else
04259    if (bc->ec_enable)
04260 #endif
04261       manager_ec_enable(bc);
04262    else
04263       manager_ec_disable(bc);
04264 }

void isdn_lib_update_rxgain ( struct misdn_bchannel bc  ) 

Definition at line 4244 of file isdn_lib.c.

References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::rxgain.

Referenced by process_ast_dsp().

04245 {
04246    manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
04247 }

void isdn_lib_update_txgain ( struct misdn_bchannel bc  ) 

Definition at line 4249 of file isdn_lib.c.

References misdn_stack::bc, manager_ph_control(), and misdn_bchannel::txgain.

Referenced by process_ast_dsp().

04250 {
04251    manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
04252 }

static void make_dummy ( struct misdn_bchannel dummybc,
int  port,
int  l3id,
int  nt,
int  channel 
) [static]

Definition at line 47 of file isdn_lib.c.

References misdn_bchannel::channel, misdn_bchannel::dummy, misdn_bchannel::l3_id, misdn_bchannel::nt, and misdn_bchannel::port.

Referenced by handle_cr(), handle_event_nt(), handle_frm(), manager_event_handler(), misdn_lib_send_restart(), and release_cr().

00048 {
00049    memset (dummybc,0,sizeof(struct misdn_bchannel));
00050    dummybc->port=port;
00051    dummybc->l3_id=l3id;
00052    dummybc->nt=nt;
00053    dummybc->dummy=1;
00054    dummybc->channel=channel;
00055 }

void manager_bchannel_activate ( struct misdn_bchannel bc  ) 

Definition at line 4125 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.

04126 {
04127    char buf[128];
04128 
04129    struct misdn_stack *stack=get_stack_by_bc(bc);
04130 
04131    if (!stack) {
04132       cb_log(0, bc->port, "bchannel_activate: Stack not found !");
04133       return ;
04134    }
04135    
04136    /* we must activate if we are deactivated */
04137    clear_ibuffer(bc->astbuf);
04138    
04139    cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr);
04140    
04141    mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN,  DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC);
04142 
04143    return ;
04144 }

void manager_bchannel_cleanup ( struct misdn_bchannel bc  ) 

void manager_bchannel_deactivate ( struct misdn_bchannel bc  ) 

Definition at line 4147 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().

04148 {
04149    char buf[128]; 
04150    iframe_t dact;
04151    struct misdn_stack *stack=get_stack_by_bc(bc);
04152 
04153    switch (bc->bc_state) {
04154       case BCHAN_ACTIVATED:
04155          break;
04156       case BCHAN_BRIDGED:
04157          misdn_split_conf(bc,bc->conf_id);
04158          break;
04159       default:
04160          cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n");
04161          return ;
04162 
04163    }
04164    
04165    cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr);
04166    
04167    bc->generate_tone=0;
04168    
04169    dact.prim = DL_RELEASE | REQUEST;
04170    dact.addr = bc->addr | FLG_MSG_DOWN;
04171    dact.dinfo = 0;
04172    dact.len = 0;
04173    mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC);
04174 
04175    clear_ibuffer(bc->astbuf);
04176    
04177    bc_state_change(bc,BCHAN_RELEASE);
04178   
04179    return;
04180 }

void manager_bchannel_setup ( struct misdn_bchannel bc  ) 

void manager_clean_bc ( struct misdn_bchannel bc  ) 

Definition at line 4293 of file isdn_lib.c.

References misdn_stack::bc, cb_event, misdn_bchannel::channel, empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, get_stack_by_bc(), and misdn_bchannel::in_use.

Referenced by misdn_lib_pid_restart().

04294 {
04295    struct misdn_stack *stack=get_stack_by_bc(bc);
04296    
04297    if (bc->channel>0)
04298       empty_chan_in_stack(stack, bc->channel);
04299    empty_bc(bc);
04300    bc->in_use=0;
04301 
04302    cb_event(EVENT_CLEANUP, bc, NULL); 
04303 }

void manager_ec_disable ( struct misdn_bchannel bc  ) 

Definition at line 4488 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().

04489 {
04490    struct misdn_stack *stack=get_stack_by_bc(bc);
04491    
04492    cb_log(4, stack?stack->port:0," --> ec_disable\n");
04493 
04494    if (!misdn_cap_is_speech(bc->capability)) {
04495       cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n");
04496       return;
04497    }
04498 
04499 #ifdef MISDN_1_2
04500    manager_ph_control_block(bc, PIPELINE_CFG, "", 0);
04501 #else
04502    if ( ! bc->ec_enable) {
04503       cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n");
04504       manager_ph_control(bc,  ECHOCAN_OFF, 0);
04505    }
04506 #endif
04507 }

void manager_ec_enable ( struct misdn_bchannel bc  ) 

Definition at line 4439 of file isdn_lib.c.

References misdn_stack::bc, misdn_bchannel::capability, cb_log, misdn_bchannel::ec_deftaps, misdn_bchannel::ec_enable, ECHOCAN_ON, get_stack_by_bc(), manager_ph_control_block(), misdn_cap_is_speech(), and misdn_stack::port.

Referenced by handle_event(), isdn_lib_update_ec(), misdn_lib_send_event(), and misdn_toggle_echocancel().

04440 {
04441    struct misdn_stack *stack=get_stack_by_bc(bc);
04442    
04443    cb_log(4, stack?stack->port:0,"ec_enable\n");
04444 
04445    if (!misdn_cap_is_speech(bc->capability)) {
04446       cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n");
04447    } else {
04448 
04449 #ifdef MISDN_1_2
04450    if (*bc->pipeline) {
04451       cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline);
04452       manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1);
04453    }
04454 #else
04455    int ec_arr[2];
04456 
04457    if (bc->ec_enable) {
04458       cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps);
04459    
04460       switch (bc->ec_deftaps) {
04461       case 4:
04462       case 8:
04463       case 16:
04464       case 32:
04465       case 64:
04466       case 128:
04467       case 256:
04468       case 512:
04469       case 1024:
04470          cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps);
04471          break;
04472       default:
04473          cb_log(0, stack->port, "Taps should be power of 2\n");
04474          bc->ec_deftaps=128;
04475       }
04476    
04477       ec_arr[0]=bc->ec_deftaps;
04478       ec_arr[1]=0;
04479       
04480       manager_ph_control_block(bc,  ECHOCAN_ON,  ec_arr, sizeof(ec_arr));
04481    }
04482 #endif
04483    }
04484 }

static void manager_event_handler ( void *  arg  )  [static]

Definition at line 3839 of file isdn_lib.c.

References misdn_lib::activatequeue, misdn_stack::bc, cb_log, clean_up_bc(), misdn_stack::downqueue, find_bc_by_l3id(), find_stack_by_port(), glob_mgr, handle_frm(), handle_frm_nt(), make_dummy(), 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.

03840 {
03841    sem_post(&handler_started); 
03842    while (1) {
03843       struct misdn_stack *stack;
03844       msg_t *msg;
03845     
03846       /** wait for events **/
03847       sem_wait(&glob_mgr->new_msg);
03848     
03849       for (msg=msg_dequeue(&glob_mgr->activatequeue);
03850            msg;
03851            msg=msg_dequeue(&glob_mgr->activatequeue)
03852          )
03853       {
03854    
03855          iframe_t *frm =  (iframe_t*) msg->data ;
03856 
03857          switch ( frm->prim) {
03858 
03859          case MGR_CLEARSTACK | REQUEST:
03860             /*a queued bchannel cleanup*/
03861             {
03862                struct misdn_bchannel *bc;
03863                struct misdn_stack *stack=find_stack_by_port(frm->dinfo);
03864                if (!stack) {
03865                   cb_log(0,0,"no stack found with port [%d]!! so we cannot cleanup the bc\n",frm->dinfo);
03866                   free_msg(msg);
03867                   break;
03868                }
03869                
03870                bc=find_bc_by_l3id(stack,frm->addr);
03871                if (bc) {
03872                   cb_log(1,bc->port,"CLEARSTACK queued, cleaning up\n");
03873                   clean_up_bc(bc);
03874                } else {
03875                   cb_log(0,stack->port,"bc could not be cleaned correctly !! addr [%x]\n",frm->addr);
03876                }
03877             }
03878             free_msg(msg); 
03879             break;
03880          case MGR_SETSTACK | REQUEST :
03881             break;
03882          default:
03883             mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
03884             free_msg(msg);
03885          }
03886       }
03887 
03888       for (stack=glob_mgr->stack_list;
03889            stack;
03890            stack=stack->next ) { 
03891 
03892          while ( (msg=msg_dequeue(&stack->upqueue)) ) {
03893             /** Handle L2/3 Signalling after bchans **/ 
03894             if (!handle_frm_nt(msg)) {
03895                /* Maybe it's TE */
03896                if (!handle_frm(msg)) {
03897                   /* wow none! */
03898                   cb_log(0,stack->port,"Wow we've got a strange issue while dequeueing a Frame\n");
03899                }
03900             }
03901          }
03902 
03903          /* Here we should check if we really want to 
03904             send all the messages we've queued, lets 
03905             assume we've queued a Disconnect, but 
03906             received it already from the other side!*/
03907            
03908          while ( (msg=msg_dequeue(&stack->downqueue)) ) {
03909             if (stack->nt ) {
03910                if (stack->nst.manager_l3(&stack->nst, msg))
03911                   cb_log(0, stack->port, "Error@ Sending Message in NT-Stack.\n");
03912      
03913             } else {
03914                iframe_t *frm = (iframe_t *)msg->data;
03915                struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo);
03916                if (bc) send_msg(glob_mgr->midev, bc, msg);
03917                else  {
03918                   if (frm->dinfo == MISDN_ID_GLOBAL) {
03919                      struct misdn_bchannel dummybc;
03920                      make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0);
03921                      send_msg(glob_mgr->midev, &dummybc, msg);
03922                   }
03923                }
03924             }
03925          }
03926       }
03927    }
03928 }

struct misdn_bchannel * manager_find_bc_by_pid ( int  pid  ) 

Definition at line 3098 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().

03099 {
03100    struct misdn_stack *stack;
03101    int i;
03102   
03103    for (stack=glob_mgr->stack_list;
03104         stack;
03105         stack=stack->next) {
03106       for (i=0; i<=stack->b_num; i++)
03107          if (stack->bc[i].pid == pid) return &stack->bc[i];
03108    }
03109   
03110    return NULL;
03111 }

struct misdn_bchannel * manager_find_bc_holded ( struct misdn_bchannel bc  ) 

Definition at line 3113 of file isdn_lib.c.

References misdn_stack::bc, find_bc_holded(), and get_stack_by_bc().

03114 {
03115    struct misdn_stack *stack=get_stack_by_bc(bc);
03116    return find_bc_holded(stack);
03117 }

char* manager_isdn_get_info ( enum event_e  event  ) 

Definition at line 4120 of file isdn_lib.c.

References isdn_get_info(), and msgs_g.

Referenced by cb_events().

04121 {
04122    return isdn_get_info(msgs_g , event, 0);
04123 }

int manager_isdn_handler ( iframe_t *  frm,
msg_t *  msg 
)

Definition at line 3630 of file isdn_lib.c.

References cb_log, handle_bchan(), handle_err(), handle_frm(), handle_frm_nt(), handle_l1(), handle_l2(), handle_mgmt(), handle_timers(), and LOG_NOTICE.

Referenced by misdn_lib_isdn_event_catcher().

03631 {  
03632 
03633    if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) {
03634       cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n");
03635    }
03636 
03637    if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) {
03638       static int unhandled_bmsg_count=1000;
03639       if (handle_bchan(msg)) {
03640          return 0 ;
03641       }
03642          
03643       if (unhandled_bmsg_count==1000) {
03644          cb_log(0, 0, "received 1k Unhandled Bchannel Messages: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo);     
03645          unhandled_bmsg_count=0;
03646       }
03647 
03648       unhandled_bmsg_count++;
03649       free_msg(msg);
03650       return 0;
03651    }  
03652 
03653 #ifdef RECV_FRM_SYSLOG_DEBUG
03654    syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo);
03655 #endif
03656 
03657    if (handle_timers(msg)) 
03658       return 0 ;
03659 
03660    
03661    if (handle_mgmt(msg)) 
03662       return 0 ; 
03663    
03664    if (handle_l2(msg)) 
03665       return 0 ;
03666 
03667    /* Its important to handle l1 AFTER l2  */
03668    if (handle_l1(msg)) 
03669       return 0 ;
03670    
03671    if (handle_frm_nt(msg)) {
03672       return 0;
03673    }
03674 
03675    if (handle_frm(msg)) {
03676       return 0;
03677    }
03678 
03679    if (handle_err(msg)) {
03680       return 0 ;
03681    }
03682 
03683 // 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);      
03684    free_msg(msg);
03685    
03686 
03687    return 0;
03688 }

void manager_ph_control ( struct misdn_bchannel bc,
int  c1,
int  c2 
)

Definition at line 4223 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_stack::bc, glob_mgr, misdn_lib::midev, and misdn_bchannel::port.

Referenced by handle_event(), isdn_lib_stop_dtmf(), isdn_lib_update_rxgain(), isdn_lib_update_txgain(), manager_ec_disable(), misdn_join_conf(), misdn_lib_echo(), misdn_lib_send_event(), misdn_lib_send_tone(), and misdn_split_conf().

04224 {
04225    unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)];
04226    iframe_t *ctrl = (iframe_t *)buffer; /* preload data */
04227    unsigned int *d = (unsigned int*)&ctrl->data.p;
04228    /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
04229    
04230    cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2);
04231    
04232    ctrl->prim = PH_CONTROL | REQUEST;
04233    ctrl->addr = bc->addr | FLG_MSG_DOWN;
04234    ctrl->dinfo = 0;
04235    ctrl->len = sizeof(unsigned int)*2;
04236    *d++ = c1;
04237    *d++ = c2;
04238    mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
04239 }

void manager_ph_control_block ( struct misdn_bchannel bc,
int  c1,
void *  c2,
int  c2_len 
)

Definition at line 4274 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().

04275 {
04276    unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len];
04277    iframe_t *ctrl = (iframe_t *)buffer;
04278    unsigned int *d = (unsigned int *)&ctrl->data.p;
04279    /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
04280    
04281    ctrl->prim = PH_CONTROL | REQUEST;
04282    ctrl->addr = bc->addr | FLG_MSG_DOWN;
04283    ctrl->dinfo = 0;
04284    ctrl->len = sizeof(unsigned int) + c2_len;
04285    *d++ = c1;
04286    memcpy(d, c2, c2_len);
04287    mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
04288 }

int misdn_cap_is_speech ( int  cap  ) 

Poor mans version

Definition at line 411 of file isdn_lib.c.

References INFO_CAPABILITY_DIGITAL_RESTRICTED, and INFO_CAPABILITY_DIGITAL_UNRESTRICTED.

Referenced by cb_events(), handle_bchan(), handle_event(), manager_ec_disable(), manager_ec_enable(), misdn_lib_send_event(), and misdn_lib_tx2misdn_frm().

00413 {
00414    if ( (cap != INFO_CAPABILITY_DIGITAL_UNRESTRICTED) &&
00415         (cap != INFO_CAPABILITY_DIGITAL_RESTRICTED) ) return 1;
00416    return 0;
00417 }

void misdn_dump_chanlist ( void   ) 

Definition at line 447 of file isdn_lib.c.

References dump_chan_list(), get_misdn_stack(), and misdn_stack::next.

Referenced by misdn_show_cls().

00448 {
00449    struct misdn_stack *stack=get_misdn_stack();
00450    for ( ; stack; stack=stack->next) {
00451       dump_chan_list(stack);
00452    }
00453 
00454 }

int misdn_inband_avail ( struct misdn_bchannel bc  ) 

Definition at line 419 of file isdn_lib.c.

References misdn_stack::bc, misdn_bchannel::early_bconnect, INFO_PI_CALL_NOT_E2E_ISDN, INFO_PI_CALLED_NOT_ISDN, INFO_PI_INBAND_AVAILABLE, and misdn_bchannel::progress_indicator.

Referenced by cb_events(), and misdn_indication().

00420 {
00421 
00422    /*if ! early_bconnect we have never inband available*/
00423    if ( ! bc->early_bconnect ) return 0;
00424    
00425    switch (bc->progress_indicator) {
00426    case INFO_PI_INBAND_AVAILABLE:
00427    case INFO_PI_CALL_NOT_E2E_ISDN:
00428    case INFO_PI_CALLED_NOT_ISDN:
00429       return 1;
00430    default:
00431       return 0;
00432    }
00433    return 0;
00434 }

void misdn_join_conf ( struct misdn_bchannel bc,
int  conf_id 
)

Definition at line 4515 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().

04516 {
04517    char data[16];
04518    int len=15;
04519 
04520    bc_state_change(bc,BCHAN_BRIDGED);
04521    manager_ph_control(bc, CMX_RECEIVE_OFF, 0);
04522    manager_ph_control(bc, CMX_CONF_JOIN, conf_id);
04523 
04524    cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id);
04525 
04526    memset(data,0,15);
04527    
04528    misdn_lib_tx2misdn_frm(bc, data, len);
04529 
04530 }

void misdn_lib_bridge ( struct misdn_bchannel bc1,
struct misdn_bchannel bc2 
)

Definition at line 4542 of file isdn_lib.c.

References bc_next_state_change(), BCHAN_ACTIVATED, BCHAN_BRIDGED, cb_log, misdn_join_conf(), misdn_bchannel::pid, and misdn_bchannel::port.

Referenced by misdn_bridge().

04543 {
04544    int conf_id=bc1->pid +1;
04545    struct misdn_bchannel *bc_list[]={
04546       bc1,bc2,NULL
04547    };
04548    struct misdn_bchannel **bc;
04549 
04550    cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port);
04551    
04552    for (bc=bc_list; *bc;  bc++) { 
04553       (*bc)->conf_id=conf_id;
04554       cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr);
04555    
04556       switch((*bc)->bc_state) {
04557          case BCHAN_ACTIVATED:
04558             misdn_join_conf(*bc,conf_id);
04559             break;
04560          default:
04561             bc_next_state_change(*bc,BCHAN_BRIDGED);
04562             break;
04563       }
04564    }
04565 }

void misdn_lib_destroy ( void   ) 

Definition at line 4087 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().

04088 {
04089    struct misdn_stack *help;
04090    int i;
04091   
04092    for ( help=glob_mgr->stack_list; help; help=help->next ) {
04093       for(i=0;i<=help->b_num; i++) {
04094          char buf[1024];
04095          mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
04096          help->bc[i].addr = 0;
04097       }
04098       cb_log (1, help->port, "Destroying this port.\n");
04099       stack_destroy(help);
04100    }
04101    
04102    if (global_state == MISDN_INITIALIZED) {
04103       cb_log(4, 0, "Killing Handler Thread\n");
04104       if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) {
04105          cb_log(4, 0, "Joining Handler Thread\n");
04106          pthread_join(glob_mgr->event_handler_thread, NULL);
04107       }
04108      
04109       cb_log(4, 0, "Killing Main Thread\n");
04110       if ( pthread_cancel(glob_mgr->event_thread) == 0 ) {
04111          cb_log(4, 0, "Joining Main Thread\n");
04112          pthread_join(glob_mgr->event_thread, NULL);
04113       }
04114    }
04115   
04116    cb_log(1, 0, "Closing mISDN device\n");
04117    te_lib_destroy(glob_mgr->midev);
04118 }

void misdn_lib_echo ( struct misdn_bchannel bc,
int  onoff 
)

Definition at line 4587 of file isdn_lib.c.

References cb_log, manager_ph_control(), and misdn_bchannel::port.

04588 {
04589    cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF");
04590    manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0);
04591 }

struct misdn_bchannel* misdn_lib_get_free_bc ( int  port,
int  channel,
int  inout,
int  dec 
)

Definition at line 3161 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, misdn_stack::blocked, cb_log, misdn_bchannel::channel, misdn_bchannel::cw, misdn_bchannel::dec, glob_mgr, MAX_BCHANS, misdn_stack::next, misdn_stack::port, prepare_bc(), misdn_stack::pri, misdn_stack::ptp, misdn_lib::stack_list, and test_inuse().

Referenced by handle_cr(), handle_event_nt(), and misdn_request().

03162 {
03163    struct misdn_stack *stack;
03164    int i;
03165    
03166    if (channel < 0 || channel > MAX_BCHANS) {
03167       cb_log(0,port,"Requested channel out of bounds (%d)\n",channel);
03168       return NULL;
03169    }
03170 
03171    usleep(1000);
03172 
03173    for (stack=glob_mgr->stack_list; stack; stack=stack->next) {
03174     
03175       if (stack->port == port) {
03176          int maxnum;
03177          if (stack->blocked) {
03178             cb_log(0,port,"Port is blocked\n");
03179             return NULL;
03180          }
03181       
03182          if (channel > 0) {
03183             if (channel <= stack->b_num) {
03184                for (i = 0; i < stack->b_num; i++) {
03185                   if ( stack->bc[i].channel == channel) {
03186                      if (test_inuse(&stack->bc[i])) { 
03187                         cb_log(0,port,"Requested channel:%d on port:%d is already in use\n",channel, port);
03188                         return NULL;
03189 
03190                      } else {
03191                         prepare_bc(&stack->bc[i], channel);
03192                         return &stack->bc[i];
03193                      }
03194                   }
03195                }
03196             } else {
03197                cb_log(0,port,"Requested channel:%d is out of bounds on port:%d\n",channel, port);
03198                return NULL;
03199             }
03200          }
03201 
03202          maxnum=inout&&!stack->pri&&!stack->ptp?stack->b_num+1:stack->b_num;
03203 
03204          if (dec) {
03205             for (i = maxnum-1; i>=0; i--) {
03206                if (!test_inuse(&stack->bc[i])) {
03207                   /* 3. channel on bri means CW*/
03208                   if (!stack->pri && i==stack->b_num)
03209                      stack->bc[i].cw=1;
03210                      
03211                   prepare_bc(&stack->bc[i], channel);
03212                   stack->bc[i].dec=1;
03213                   return &stack->bc[i];
03214                }
03215             }
03216          } else {
03217             for (i = 0; i <maxnum; i++) {
03218                if (!test_inuse(&stack->bc[i])) {
03219                   /* 3. channel on bri means CW*/
03220                   if (!stack->pri && i==stack->b_num)
03221                      stack->bc[i].cw=1;
03222 
03223                   prepare_bc(&stack->bc[i], channel);
03224                   return &stack->bc[i];
03225                }
03226             }
03227          }
03228 
03229          cb_log(1,port,"There is no free channel on port (%d)\n",port);
03230          return NULL;
03231       }
03232    }
03233 
03234    cb_log(0,port,"Port is not configured (%d)\n",port);
03235    return NULL;
03236 }

static int misdn_lib_get_l1_down ( struct misdn_stack stack  )  [static]

Definition at line 767 of file isdn_lib.c.

References cb_log, misdn_stack::lower_id, misdn_stack::midev, and misdn_stack::port.

Referenced by handle_err(), and misdn_lib_get_port_down().

00768 {
00769    /* Pull Up L1 */ 
00770    iframe_t act;
00771    act.prim = PH_DEACTIVATE | REQUEST; 
00772    act.addr = stack->lower_id|FLG_MSG_DOWN;
00773    act.dinfo = 0;
00774    act.len = 0;
00775 
00776    cb_log(1, stack->port, "SENDING PH_DEACTIVATE | REQ\n");
00777    return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00778 }

static int misdn_lib_get_l1_up ( struct misdn_stack stack  )  [static]

Definition at line 807 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().

00808 {
00809    /* Pull Up L1 */ 
00810    iframe_t act;
00811    act.prim = PH_ACTIVATE | REQUEST; 
00812    act.addr = (stack->upper_id | FLG_MSG_DOWN)  ;
00813 
00814    
00815    act.dinfo = 0;
00816    act.len = 0;
00817 
00818    return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00819 
00820 }

static int misdn_lib_get_l2_down ( struct misdn_stack stack  )  [static]

Definition at line 781 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().

00782 {
00783    
00784    if (stack->ptp && (stack->nt) ) {
00785       msg_t *dmsg;
00786       /* L2 */
00787       dmsg = create_l2msg(DL_RELEASE| REQUEST, 0, 0);
00788       
00789       if (stack->nst.manager_l3(&stack->nst, dmsg))
00790          free_msg(dmsg);
00791       
00792    } else {
00793       iframe_t act;
00794       
00795       act.prim = DL_RELEASE| REQUEST;
00796       act.addr = (stack->upper_id |FLG_MSG_DOWN)  ;
00797       
00798       act.dinfo = 0;
00799       act.len = 0;
00800       return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00801    }
00802    
00803    return 0;
00804 }

int misdn_lib_get_l2_up ( struct misdn_stack stack  ) 

Definition at line 822 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().

00823 {
00824    
00825    if (stack->ptp && (stack->nt) ) {
00826       msg_t *dmsg;
00827       /* L2 */
00828       dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0);
00829       
00830       if (stack->nst.manager_l3(&stack->nst, dmsg))
00831          free_msg(dmsg);
00832       
00833    } else {
00834       iframe_t act;
00835       
00836       act.prim = DL_ESTABLISH | REQUEST;
00837       act.addr = (stack->upper_id |FLG_MSG_DOWN)  ;
00838       
00839       act.dinfo = 0;
00840       act.len = 0;
00841       return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00842    }
00843    
00844    return 0;
00845 }

int misdn_lib_get_maxchans ( int  port  ) 

Definition at line 103 of file isdn_lib.c.

References get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_stack::pri.

Referenced by misdn_request().

00104 {
00105    struct misdn_stack *stack=get_misdn_stack();
00106    for ( ; stack; stack=stack->next) {
00107       if (stack->port == port) {
00108          if (stack->pri) 
00109             return 30;
00110          else
00111             return 2;
00112       }
00113    }
00114    return -1;
00115 }

int misdn_lib_get_port_down ( int  port  ) 

Definition at line 1724 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().

01725 { /* Pull Down L1 */ 
01726    struct misdn_stack *stack;
01727    for (stack=glob_mgr->stack_list;
01728         stack;
01729         stack=stack->next) {
01730       if (stack->port == port) {
01731             if (stack->l2link)
01732                misdn_lib_get_l2_down(stack);
01733             misdn_lib_get_l1_down(stack);
01734          return 0;
01735       }
01736    }
01737    return 0;
01738 }

int misdn_lib_get_port_info ( int  port  ) 

Definition at line 3693 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.

03694 {
03695    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03696    iframe_t *frm;
03697    struct misdn_stack *stack=find_stack_by_port(port);
03698    if (!msg) {
03699       cb_log(0, port, "misgn_lib_get_port: alloc_msg failed!\n");
03700       return -1;
03701    }
03702    frm=(iframe_t*)msg->data;
03703    if (!stack ) {
03704       cb_log(0, port, "There is no Stack for this port.\n");
03705       return -1;
03706    }
03707    /* activate bchannel */
03708    frm->prim = CC_STATUS_ENQUIRY | REQUEST;
03709 
03710    frm->addr = stack->upper_id| FLG_MSG_DOWN;
03711 
03712    frm->dinfo = 0;
03713    frm->len = 0;
03714   
03715    msg_queue_tail(&glob_mgr->activatequeue, msg);
03716    sem_post(&glob_mgr->new_msg);
03717 
03718   
03719    return 0; 
03720 }

int misdn_lib_get_port_up ( int  port  ) 

Definition at line 1702 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().

01703 { /* Pull Up L1 */ 
01704    struct misdn_stack *stack;
01705    
01706    for (stack=glob_mgr->stack_list;
01707         stack;
01708         stack=stack->next) {
01709       
01710       if (stack->port == port) {
01711 
01712          if (!stack->l1link)
01713             misdn_lib_get_l1_up(stack);
01714          if (!stack->l2link)
01715             misdn_lib_get_l2_up(stack);
01716          
01717          return 0;
01718       }
01719    }
01720    return 0;
01721 }

static int misdn_lib_get_short_status ( struct misdn_stack stack  )  [static]

Definition at line 862 of file isdn_lib.c.

References misdn_stack::midev, and misdn_stack::upper_id.

Referenced by misdn_lib_isdn_l1watcher().

00863 {
00864    iframe_t act;
00865    
00866    
00867    act.prim = MGR_SHORTSTATUS | REQUEST; 
00868    
00869    act.addr = (stack->upper_id | MSG_BROADCAST)  ;
00870 
00871    act.dinfo = SSTATUS_BROADCAST_BIT | SSTATUS_ALL;
00872    
00873    act.len = 0;
00874    return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00875 }

int misdn_lib_init ( char *  portlist,
struct misdn_lib_iface iface,
void *  user_data 
)

Definition at line 3979 of file isdn_lib.c.

References misdn_lib::activatequeue, misdn_stack::b_num, misdn_stack::bc, calloc, cb_event, misdn_lib_iface::cb_event, cb_jb_empty, misdn_lib_iface::cb_jb_empty, misdn_lib_iface::cb_log, cb_log, 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().

03980 {
03981    struct misdn_lib *mgr=calloc(1, sizeof(struct misdn_lib));
03982    char *tok, *tokb;
03983    char plist[1024];
03984    int midev;
03985    int port_count=0;
03986  
03987    cb_log = iface->cb_log;
03988    cb_event = iface->cb_event;
03989    cb_jb_empty = iface->cb_jb_empty;
03990    
03991    glob_mgr = mgr;
03992   
03993    msg_init();
03994 
03995    misdn_lib_nt_debug_init(0,NULL);
03996    
03997    if (!portlist || (*portlist == 0) ) return 1;
03998    
03999    init_flip_bits();
04000    
04001    {
04002       strncpy(plist,portlist, 1024);
04003       plist[1023] = 0;
04004    }
04005   
04006    memcpy(tone_425_flip,tone_425,TONE_425_SIZE);
04007    flip_buf_bits(tone_425_flip,TONE_425_SIZE);
04008 
04009    memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE);
04010    flip_buf_bits(tone_silence_flip,TONE_SILENCE_SIZE);
04011   
04012    midev=te_lib_init();
04013    mgr->midev=midev;
04014 
04015    port_count=mISDN_get_stack_count(midev);
04016   
04017    msg_queue_init(&mgr->activatequeue);
04018   
04019    if (sem_init(&mgr->new_msg, 1, 0)<0)
04020       sem_init(&mgr->new_msg, 0, 0);
04021  
04022    for (tok=strtok_r(plist," ,",&tokb );
04023         tok; 
04024         tok=strtok_r(NULL," ,",&tokb)) {
04025       int port = atoi(tok);
04026       struct misdn_stack *stack;
04027       static int first=1;
04028       int ptp=0;
04029     
04030       if (strstr(tok, "ptp"))
04031          ptp=1;
04032 
04033       if (port > port_count) {
04034          cb_log(0, port, "Couldn't Initialize this port since we have only %d ports\n", port_count);
04035          exit(1);
04036       }
04037       stack=stack_init(midev, port, ptp);
04038     
04039       if (!stack) {
04040          perror("init_stack");
04041          exit(1);
04042       }
04043     
04044       {
04045          int i;
04046          for(i=0;i<=stack->b_num; i++) {
04047             int r;
04048             if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) {
04049                cb_log(0, port, "Got Err @ init_bc :%d\n",r);
04050                exit(1);
04051             }
04052          }
04053       }
04054 
04055       if (stack && first) {
04056          mgr->stack_list=stack;
04057          first=0;
04058          continue;
04059       }
04060     
04061       if (stack) {
04062          struct misdn_stack * help;
04063          for ( help=mgr->stack_list; help; help=help->next ) 
04064             if (help->next == NULL) break;
04065          help->next=stack;
04066       }
04067     
04068    }
04069   
04070    if (sem_init(&handler_started, 1, 0)<0)
04071       sem_init(&handler_started, 0, 0);
04072   
04073    cb_log(8, 0, "Starting Event Handler\n");
04074    pthread_create( &mgr->event_handler_thread, NULL,(void*)manager_event_handler, mgr);
04075   
04076    sem_wait(&handler_started) ;
04077    cb_log(8, 0, "Starting Event Catcher\n");
04078    pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr);
04079   
04080    cb_log(8, 0, "Event Catcher started\n");
04081 
04082    global_state= MISDN_INITIALIZED; 
04083   
04084    return (mgr == NULL);
04085 }

int misdn_lib_is_port_blocked ( int  port  ) 

Definition at line 83 of file isdn_lib.c.

References misdn_stack::blocked, get_misdn_stack(), misdn_stack::next, and misdn_stack::port.

00084 {  
00085    struct misdn_stack *stack=get_misdn_stack();
00086    for ( ; stack; stack=stack->next) {
00087       if (stack->port == port) {
00088          return stack->blocked;
00089       }
00090    }
00091    return -1;
00092 }

int misdn_lib_is_ptp ( int  port  ) 

Definition at line 94 of file isdn_lib.c.

References get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_stack::ptp.

Referenced by cb_events(), and do_immediate_setup().

00095 {
00096    struct misdn_stack *stack=get_misdn_stack();
00097    for ( ; stack; stack=stack->next) {
00098       if (stack->port == port) return stack->ptp;
00099    }
00100    return -1;
00101 }

static void misdn_lib_isdn_event_catcher ( void *  arg  )  [static]

Definition at line 3004 of file isdn_lib.c.

References cb_log, fetch_msg(), manager_isdn_handler(), and misdn_lib::midev.

03005 {
03006    struct misdn_lib *mgr = arg;
03007    int zero_frm=0 , fff_frm=0 ;
03008    int midev= mgr->midev;
03009    int port=0;
03010    
03011    while (1) {
03012       msg_t *msg = fetch_msg(midev); 
03013       iframe_t *frm;
03014       
03015       
03016       if (!msg) continue;
03017       
03018       frm = (iframe_t*) msg->data;
03019       
03020       /** When we make a call from NT2Ast we get this frames **/
03021       if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) {
03022          zero_frm++; 
03023          free_msg(msg);
03024          continue;
03025       } else {
03026          if (zero_frm) {
03027             cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm);
03028             zero_frm = 0 ;
03029          }
03030       }
03031       
03032       /** I get this sometimes after setup_bc **/
03033       if (frm->len == 0 &&  frm->dinfo == 0 && frm->prim == 0xffffffff ) {
03034          fff_frm++; 
03035          free_msg(msg);
03036          continue;
03037       } else {
03038          if (fff_frm) {
03039             cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm);
03040             fff_frm = 0 ;
03041          }
03042       }
03043       
03044       manager_isdn_handler(frm, msg);
03045    }
03046 
03047 }

void misdn_lib_isdn_l1watcher ( int  port  ) 

Definition at line 2986 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().

02987 {
02988    struct misdn_stack *stack;
02989 
02990    for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next)
02991       ;
02992 
02993    if (stack) {
02994       cb_log(4, port, "Checking L1 State\n");   
02995       if (!stack->l1link) {
02996          cb_log(4, port, "L1 State Down, trying to get it up again\n"); 
02997          misdn_lib_get_short_status(stack);
02998          misdn_lib_get_l1_up(stack); 
02999          misdn_lib_get_l2_up(stack); 
03000       }
03001    }
03002 }

void misdn_lib_log_ies ( struct misdn_bchannel bc  ) 

Definition at line 3257 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().

03258 {
03259    struct misdn_stack *stack;
03260    if (!bc) return;
03261 
03262    stack=get_stack_by_bc(bc);
03263 
03264    if (!stack) return;
03265 
03266    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);
03267    
03268    cb_log(2, stack->port,
03269           " --> info_dad:%s onumplan:%c dnumplan:%c rnumplan:%c cpnnumplan:%c\n",
03270           bc->info_dad,
03271           bc->onumplan>=0?'0'+bc->onumplan:' ',
03272           bc->dnumplan>=0?'0'+bc->dnumplan:' ',
03273           bc->rnumplan>=0?'0'+bc->rnumplan:' ',
03274           bc->cpnnumplan>=0?'0'+bc->cpnnumplan:' '
03275       );
03276    
03277    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);
03278    cb_log(4, stack->port, " --> screen:%d --> pres:%d\n",
03279          bc->screen, bc->pres);
03280    
03281    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);
03282    
03283    cb_log(4, stack->port, " --> facility:%s out_facility:%s\n",fac2str(bc->fac_in.Function),fac2str(bc->fac_out.Function));
03284 
03285    cb_log(5, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1);
03286    
03287    cb_log(5, stack->port, " --> bc:%x h:%d sh:%d\n", bc, bc->holded, bc->stack_holder);
03288 }

int misdn_lib_maxports_get ( void   ) 

Definition at line 3931 of file isdn_lib.c.

Referenced by load_module().

03931                              { /** BE AWARE WE HAVE NO CB_LOG HERE! **/
03932    
03933    int i = mISDN_open();
03934    int max=0;
03935    
03936    if (i<0)
03937       return -1;
03938 
03939    max = mISDN_get_stack_count(i);
03940    
03941    mISDN_close(i);
03942    
03943    return max;
03944 }

void misdn_lib_nt_debug_init ( int  flags,
char *  file 
)

Definition at line 3959 of file isdn_lib.c.

References f.

Referenced by load_module(), and misdn_lib_init().

03960 {
03961    int static init=0;
03962    char *f;
03963    
03964    if (!flags) 
03965       f=NULL;
03966    else
03967       f=file;
03968 
03969    if (!init) {
03970       debug_init( flags , f, f, f);
03971       init=1;
03972    } else {
03973       debug_close();
03974       debug_init( flags , f, f, f);
03975    }
03976 }

void misdn_lib_nt_keepcalls ( int  kc  ) 

Definition at line 3947 of file isdn_lib.c.

References get_misdn_stack(), misdn_stack::next, and misdn_stack::nst.

Referenced by load_module().

03948 {
03949 #ifdef FEATURE_NET_KEEPCALLS
03950    if (kc) {
03951       struct misdn_stack *stack=get_misdn_stack();
03952       for ( ; stack; stack=stack->next) {
03953          stack->nst.feature |= FEATURE_NET_KEEPCALLS;
03954       }
03955    }
03956 #endif
03957 }

int misdn_lib_pid_restart ( int  pid  ) 

Definition at line 3748 of file isdn_lib.c.

References manager_clean_bc(), and manager_find_bc_by_pid().

Referenced by misdn_restart_pid().

03749 {
03750    struct misdn_bchannel *bc=manager_find_bc_by_pid(pid);
03751 
03752    if (bc) {
03753       manager_clean_bc(bc);
03754    }
03755    return 0;
03756 }

int misdn_lib_port_block ( int  port  ) 

Definition at line 57 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().

00058 {
00059    struct misdn_stack *stack=get_misdn_stack();
00060    for ( ; stack; stack=stack->next) {
00061       if (stack->port == port) {
00062          stack->blocked=1;
00063          return 0;
00064       }
00065    }
00066    return -1;
00067 
00068 }

int misdn_lib_port_is_pri ( int  port  ) 

Definition at line 35 of file isdn_lib.c.

References get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_stack::pri.

Referenced by misdn_new(), test_inuse(), and update_name().

00036 {
00037    struct misdn_stack *stack=get_misdn_stack();
00038    for ( ; stack; stack=stack->next) {
00039       if (stack->port == port) {
00040          return stack->pri;
00041       }
00042    }
00043    
00044    return -1;
00045 }

int misdn_lib_port_restart ( int  port  ) 

Definition at line 3797 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().

03798 {
03799    struct misdn_stack *stack=find_stack_by_port(port);
03800  
03801    cb_log(0, port, "Restarting this port.\n");
03802    if (stack) {
03803       cb_log(0, port, "Stack:%p\n",stack);
03804          
03805       clear_l3(stack);
03806       {
03807          msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03808          iframe_t *frm;
03809 
03810          if (!msg) {
03811             cb_log(0, port, "port_restart: alloc_msg failed\n");
03812             return -1;
03813          }
03814          
03815          frm=(iframe_t*)msg->data;
03816          /* we must activate if we are deactivated */
03817          /* activate bchannel */
03818          frm->prim = DL_RELEASE | REQUEST;
03819          frm->addr = stack->upper_id | FLG_MSG_DOWN;
03820 
03821          frm->dinfo = 0;
03822          frm->len = 0;
03823          msg_queue_tail(&glob_mgr->activatequeue, msg);
03824          sem_post(&glob_mgr->new_msg);
03825       }
03826 
03827       if (stack->nt)
03828          misdn_lib_reinit_nt_stack(stack->port);
03829     
03830    }
03831 
03832    return 0;
03833 }

int misdn_lib_port_unblock ( int  port  ) 

Definition at line 70 of file isdn_lib.c.

References misdn_stack::blocked, get_misdn_stack(), misdn_stack::next, and misdn_stack::port.

Referenced by misdn_port_unblock().

00071 {
00072    struct misdn_stack *stack=get_misdn_stack();
00073    for ( ; stack; stack=stack->next) {
00074       if (stack->port == port) {
00075          stack->blocked=0;
00076          return 0;
00077       }
00078    }
00079    return -1;
00080 
00081 }

int misdn_lib_port_up ( int  port,
int  check 
)

Definition at line 1740 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().

01741 {
01742    struct misdn_stack *stack;
01743 
01744 
01745    for (stack=glob_mgr->stack_list;
01746         stack;
01747         stack=stack->next) {
01748       
01749       if (stack->port == port) {
01750 
01751          if (stack->blocked) {
01752             cb_log(0,port, "Port Blocked:%d L2:%d L1:%d\n", stack->blocked, stack->l2link, stack->l1link);
01753             return -1;
01754          }
01755 
01756          if (stack->ptp ) {
01757 
01758             if (stack->l1link && stack->l2link) {
01759                return 1;
01760             } else {
01761                cb_log(1,port, "Port Down L2:%d L1:%d\n",
01762                   stack->l2link, stack->l1link);
01763                return 0;
01764             }
01765          } else {
01766             if ( !check || stack->l1link )
01767                return 1;
01768             else {
01769                cb_log(1,port, "Port down PMP\n");
01770                return 0;
01771             }
01772          }
01773       }
01774    }
01775   
01776    return -1;
01777 }

void misdn_lib_reinit_nt_stack ( int  port  ) 

Definition at line 4595 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().

04596 {
04597    struct misdn_stack *stack=find_stack_by_port(port);
04598    
04599    if (stack) {
04600       stack->l2link=0;
04601       stack->blocked=0;
04602    
04603       cleanup_Isdnl3(&stack->nst);
04604       cleanup_Isdnl2(&stack->nst);
04605 
04606 
04607       memset(&stack->nst, 0, sizeof(net_stack_t));
04608       memset(&stack->mgr, 0, sizeof(manager_t));
04609    
04610       stack->mgr.nst = &stack->nst;
04611       stack->nst.manager = &stack->mgr;
04612     
04613       stack->nst.l3_manager = handle_event_nt;
04614       stack->nst.device = glob_mgr->midev;
04615       stack->nst.cardnr = port;
04616       stack->nst.d_stid = stack->d_stid;
04617    
04618       stack->nst.feature = FEATURE_NET_HOLD;
04619       if (stack->ptp)
04620          stack->nst.feature |= FEATURE_NET_PTP;
04621       if (stack->pri)
04622          stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
04623       
04624       stack->nst.l1_id = stack->lower_id;
04625       stack->nst.l2_id = stack->upper_id;
04626       
04627       msg_queue_init(&stack->nst.down_queue);
04628    
04629       Isdnl2Init(&stack->nst);
04630       Isdnl3Init(&stack->nst);
04631 
04632       if (!stack->ptp)
04633          misdn_lib_get_l1_up(stack);
04634       misdn_lib_get_l2_up(stack);
04635    }
04636 }

void misdn_lib_release ( struct misdn_bchannel bc  ) 

Definition at line 1682 of file isdn_lib.c.

References misdn_stack::bc, cb_log, misdn_bchannel::channel, clean_up_bc(), empty_bc(), empty_chan_in_stack(), get_stack_by_bc(), and misdn_bchannel::in_use.

Referenced by misdn_hangup().

01683 {
01684    struct misdn_stack *stack=get_stack_by_bc(bc);
01685 
01686    if (!stack) {
01687       cb_log(1,0,"misdn_release: No Stack found\n");
01688       return;
01689    }
01690    
01691    if (bc->channel>0) 
01692       empty_chan_in_stack(stack,bc->channel);
01693    
01694    empty_bc(bc);
01695    clean_up_bc(bc);
01696    bc->in_use=0;
01697 }

int misdn_lib_send_event ( struct misdn_bchannel bc,
enum event_e  event 
)

Definition at line 3309 of file isdn_lib.c.

References misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), bc_state_change(), BCHAN_BRIDGED, BCHAN_CLEANED, misdn_bchannel::capability, misdn_bchannel::cause, cb_log, misdn_bchannel::channel, clean_up_bc(), misdn_bchannel::conf_id, create_process(), misdn_bchannel::crypt_key, misdn_bchannel::dad, misdn_bchannel::dnumplan, misdn_stack::downqueue, empty_bc(), empty_chan_in_stack(), ENOCHAN, EVENT_ALERTING, EVENT_CONNECT, EVENT_CONNECT_ACKNOWLEDGE, EVENT_DISCONNECT, EVENT_HOLD_ACKNOWLEDGE, EVENT_PROCEEDING, EVENT_PROGRESS, EVENT_RELEASE, EVENT_RELEASE_COMPLETE, EVENT_RETRIEVE_ACKNOWLEDGE, EVENT_SETUP, EVENT_SETUP_ACKNOWLEDGE, misdn_bchannel::evq, find_bc_by_confid(), find_free_chan_in_stack(), get_stack_by_bc(), glob_mgr, misdn_bchannel::holded, misdn_bchannel::in_use, isdn_get_info(), isdn_msg_build_event(), misdn_stack::l1link, malloc, manager_ec_enable(), manager_ph_control(), manager_ph_control_block(), misdn_lib::midev, misdn_cap_is_speech(), misdn_lib_get_l1_up(), misdn_lib_log_ies(), misdn_send_lock(), misdn_send_unlock(), misdn_split_conf(), msgs_g, misdn_bchannel::need_disconnect, misdn_bchannel::need_release, misdn_bchannel::need_release_complete, misdn_lib::new_msg, misdn_bchannel::nodsp, misdn_stack::nt, misdn_bchannel::nt, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_bchannel::out_cause, misdn_bchannel::pid, misdn_bchannel::port, misdn_stack::port, RETURN, misdn_bchannel::rxgain, setup_bc(), stack_holder_add(), misdn_bchannel::txgain, and misdn_stack::upper_id.

Referenced by cb_events(), do_immediate_setup(), handle_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(), misdn_send_text(), start_pbx(), and wait_for_digits().

03310 {
03311    msg_t *msg; 
03312    struct misdn_stack *stack;
03313    int retval=0;
03314   
03315    if (!bc) RETURN(-1,OUT_POST_UNLOCK);
03316    
03317    stack=get_stack_by_bc(bc);
03318    
03319    if (!stack) {
03320       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);
03321       RETURN(-1,OUT);
03322    }
03323    
03324    misdn_send_lock(bc);
03325 
03326 
03327    cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->uperid:%x\n",stack->nt, stack->upper_id);
03328 
03329    if ( stack->nt && !stack->l1link) {
03330       /** Queue Event **/
03331       bc->evq=event;
03332       cb_log(1, stack->port, "Queueing Event %s because L1 is down (btw. Activating L1)\n", isdn_get_info(msgs_g, event, 0));
03333       misdn_lib_get_l1_up(stack);
03334       RETURN(0,OUT);
03335    }
03336    
03337    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);
03338    cb_log(4, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state));
03339    misdn_lib_log_ies(bc);
03340    
03341    switch (event) {
03342    case EVENT_SETUP:
03343       if (create_process(glob_mgr->midev, bc)<0) {
03344          cb_log(0,  stack->port, " No free channel at the moment @ send_event\n");
03345 
03346          RETURN(-ENOCHAN,OUT);
03347       }
03348       break;
03349 
03350    case EVENT_PROGRESS:
03351    case EVENT_ALERTING:
03352    case EVENT_PROCEEDING:
03353    case EVENT_SETUP_ACKNOWLEDGE:
03354    case EVENT_CONNECT:
03355       if (!stack->nt) break;
03356 
03357    case EVENT_RETRIEVE_ACKNOWLEDGE:
03358 
03359       if (stack->nt) {
03360          if (bc->channel <=0 ) { /*  else we have the channel already */
03361             if (find_free_chan_in_stack(stack, bc, 0, 0)<0) {
03362                cb_log(0, stack->port, " No free channel at the moment\n");
03363                /*FIXME: add disconnect*/
03364                RETURN(-ENOCHAN,OUT);
03365             }
03366          }
03367          /* Its that i generate channels */
03368       }
03369 
03370       retval=setup_bc(bc);
03371       if (retval == -EINVAL) {
03372          cb_log(0,bc->port,"send_event: setup_bc failed\n");
03373       }
03374 
03375       if (misdn_cap_is_speech(bc->capability)) {
03376          if ((event==EVENT_CONNECT)||(event==EVENT_RETRIEVE_ACKNOWLEDGE)) {
03377             if ( *bc->crypt_key ) {
03378                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);
03379                
03380                manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
03381             }
03382             
03383             if (!bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0);
03384             manager_ec_enable(bc);
03385             
03386             if (bc->txgain != 0) {
03387                cb_log(4, stack->port,  "--> Changing txgain to %d\n", bc->txgain);
03388                manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
03389             }
03390             
03391             if ( bc->rxgain != 0 ) {
03392                cb_log(4, stack->port,  "--> Changing rxgain to %d\n", bc->rxgain);
03393                manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
03394             }
03395          }
03396       }
03397       break;
03398 
03399    case EVENT_HOLD_ACKNOWLEDGE:
03400    {
03401       struct misdn_bchannel *holded_bc=malloc(sizeof(struct misdn_bchannel));
03402       if (!holded_bc) {
03403          cb_log(0,bc->port, "Could not allocate holded_bc!!!\n");
03404          RETURN(-1,OUT);
03405       }
03406 
03407       /*backup the bc*/
03408       memcpy(holded_bc,bc,sizeof(struct misdn_bchannel));
03409       holded_bc->holded=1;
03410       bc_state_change(holded_bc,BCHAN_CLEANED);
03411 
03412       stack_holder_add(stack,holded_bc);
03413    
03414       /*kill the bridge and clean the bchannel*/
03415       if (stack->nt) {
03416          int channel;
03417          if (bc->bc_state == BCHAN_BRIDGED) {
03418             struct misdn_bchannel *bc2;
03419             misdn_split_conf(bc,bc->conf_id);
03420             bc2=find_bc_by_confid(bc->conf_id);
03421             if (!bc2) {
03422                cb_log(0,bc->port,"We have no second bc in bridge???\n");
03423             } else {
03424                misdn_split_conf(bc2,bc->conf_id);
03425             }
03426          }
03427          
03428          channel=bc->channel;
03429 
03430          empty_bc(bc);
03431          clean_up_bc(bc);
03432 
03433          if (channel>0)
03434             empty_chan_in_stack(stack,channel);
03435 
03436          bc->in_use=0;  
03437       }
03438       
03439    }
03440    break;
03441 
03442    /* finishing the channel eh ? */
03443    case EVENT_DISCONNECT:
03444       if (!bc->need_disconnect) {
03445          cb_log(0,bc->port," --> we have already send Disconnect\n");
03446          RETURN(-1,OUT);
03447       }
03448       
03449       bc->need_disconnect=0;
03450       break;
03451    case EVENT_RELEASE:
03452       if (!bc->need_release) {
03453          cb_log(0,bc->port," --> we have already send Release\n");
03454          RETURN(-1,OUT);
03455       }
03456       bc->need_disconnect=0;
03457       bc->need_release=0;
03458       break;
03459    case EVENT_RELEASE_COMPLETE:
03460       if (!bc->need_release_complete) {
03461          cb_log(0,bc->port," --> we have already send Release_complete\n");
03462          RETURN(-1,OUT);
03463       }
03464       bc->need_disconnect=0;
03465       bc->need_release=0;
03466       bc->need_release_complete=0;
03467 
03468       if (!stack->nt) {
03469          /*create clenaup in TE*/
03470          int channel=bc->channel;
03471 
03472          int tmpcause=bc->cause; 
03473          int tmp_out_cause=bc->out_cause; 
03474          empty_bc(bc);
03475          bc->cause=tmpcause;
03476          bc->out_cause=tmp_out_cause;
03477          clean_up_bc(bc);
03478          
03479          if (channel>0)
03480             empty_chan_in_stack(stack,channel);
03481          
03482          bc->in_use=0;
03483       }
03484       break;
03485     
03486    case EVENT_CONNECT_ACKNOWLEDGE:
03487 
03488       if ( bc->nt || misdn_cap_is_speech(bc->capability)) {
03489          int retval=setup_bc(bc);
03490          if (retval == -EINVAL){
03491             cb_log(0,bc->port,"send_event: setup_bc failed\n");
03492             
03493          }
03494       }
03495       
03496       if (misdn_cap_is_speech(bc->capability)) {
03497          if (  !bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0);
03498          manager_ec_enable(bc);
03499 
03500          if ( bc->txgain != 0 ) {
03501             cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain);
03502             manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
03503          }
03504          if ( bc->rxgain != 0 ) {
03505             cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain);
03506             manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
03507          }
03508       }
03509       break;
03510     
03511    default:
03512       break;
03513    }
03514   
03515    /* Later we should think about sending bchannel data directly to misdn. */
03516    msg = isdn_msg_build_event(msgs_g, bc, event, stack->nt);
03517    msg_queue_tail(&stack->downqueue, msg);
03518    sem_post(&glob_mgr->new_msg);
03519   
03520 OUT:
03521    misdn_send_unlock(bc);
03522 
03523 OUT_POST_UNLOCK:
03524    return retval; 
03525 }

int misdn_lib_send_restart ( int  port,
int  channel 
)

Definition at line 3759 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, cb_log, misdn_bchannel::channel, clean_up_bc(), empty_bc(), EVENT_RESTART, find_stack_by_port(), misdn_bchannel::in_use, make_dummy(), misdn_lib_send_event(), misdn_stack::nt, and misdn_stack::port.

Referenced by handle_event_nt(), handle_frm(), and misdn_send_restart().

03760 {
03761    struct misdn_bchannel dummybc;
03762    struct misdn_stack *stack=find_stack_by_port(port);
03763    cb_log(0, port, "Sending Restarts on this port.\n");
03764    
03765    make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0);
03766 
03767    /*default is all channels*/
03768    if (channel <0) {
03769       dummybc.channel=-1;
03770       cb_log(0, port, "Restarting and all Interfaces\n");
03771       misdn_lib_send_event(&dummybc, EVENT_RESTART);
03772 
03773       return 0;
03774    }
03775 
03776    /*if a channel is specified we restart only this one*/
03777    if (channel >0) {
03778       int cnt;
03779       dummybc.channel=channel;
03780       cb_log(0, port, "Restarting and cleaning channel %d\n",channel);
03781       misdn_lib_send_event(&dummybc, EVENT_RESTART);
03782       /* clean up chan in stack, to be sure we don't think it's
03783        * in use anymore */
03784       for (cnt=0; cnt<=stack->b_num; cnt++) {
03785          if (stack->bc[cnt].channel == channel) {
03786             empty_bc(&stack->bc[cnt]);
03787             clean_up_bc(&stack->bc[cnt]);
03788             stack->bc[cnt].in_use=0;
03789          }
03790       }
03791    }
03792 
03793    return 0;
03794 }

void misdn_lib_send_tone ( struct misdn_bchannel bc,
enum tone_e  tone 
)

Definition at line 4404 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().

04405 {
04406    char buf[mISDN_HEADER_LEN+128];
04407    iframe_t *frm;
04408 
04409    switch(tone) {
04410    case TONE_DIAL:
04411       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE); 
04412    break;
04413    
04414    case TONE_ALERTING:
04415       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_RINGING);  
04416    break;
04417    
04418    case TONE_HANGUP:
04419       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_HANGUP);   
04420    break;
04421 
04422    case TONE_NONE:
04423    default:
04424       manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP);  
04425    }
04426 
04427    frm=(iframe_t*)buf;
04428    memset(buf,0,mISDN_HEADER_LEN+128);
04429 
04430    frm->prim=DL_DATA|REQUEST;
04431    frm->addr=bc->addr|FLG_MSG_DOWN;
04432    frm->dinfo=0;
04433    frm->len=128;
04434    
04435    mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
04436 }

void misdn_lib_setup_bc ( struct misdn_bchannel bc  ) 

Definition at line 945 of file isdn_lib.c.

References misdn_stack::bc, clean_up_bc(), and setup_bc().

00946 {
00947    clean_up_bc(bc);
00948    setup_bc(bc);
00949 }

void misdn_lib_split_bridge ( struct misdn_bchannel bc1,
struct misdn_bchannel bc2 
)

Definition at line 4567 of file isdn_lib.c.

References bc_state2str(), BCHAN_BRIDGED, cb_log, misdn_bchannel::conf_id, and misdn_split_conf().

Referenced by misdn_bridge().

04568 {
04569 
04570    struct misdn_bchannel *bc_list[]={
04571       bc1,bc2,NULL
04572    };
04573    struct misdn_bchannel **bc;
04574       
04575    for (bc=bc_list; *bc;  bc++) { 
04576       if ( (*bc)->bc_state == BCHAN_BRIDGED){
04577          misdn_split_conf( *bc, (*bc)->conf_id);
04578       } else {
04579          cb_log( 2, (*bc)->port, "BC not bridged (state:%s) so not splitting it\n",bc_state2str((*bc)->bc_state));
04580       }
04581    }
04582    
04583 }

void misdn_lib_tone_generator_start ( struct misdn_bchannel bc  ) 

Definition at line 2184 of file isdn_lib.c.

References misdn_bchannel::generate_tone.

Referenced by misdn_write().

02185 {
02186    bc->generate_tone=1;
02187 }

void misdn_lib_tone_generator_stop ( struct misdn_bchannel bc  ) 

Definition at line 2189 of file isdn_lib.c.

References misdn_bchannel::generate_tone.

Referenced by start_bc_tones(), and stop_indicate().

02190 {
02191    bc->generate_tone=0;
02192 }

void misdn_lib_transfer ( struct misdn_bchannel holded_bc  ) 

Definition at line 3093 of file isdn_lib.c.

References misdn_bchannel::holded.

03094 {
03095    holded_bc->holded=0;
03096 }

int misdn_lib_tx2misdn_frm ( struct misdn_bchannel bc,
void *  data,
int  len 
)

Definition at line 4183 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().

04184 {
04185    char buf[4096 + mISDN_HEADER_LEN];
04186    iframe_t *frm;
04187    int  r;
04188    struct misdn_stack *stack=get_stack_by_bc(bc);
04189 
04190    switch (bc->bc_state) {
04191       case BCHAN_ACTIVATED:
04192       case BCHAN_BRIDGED:
04193          break;
04194       default:
04195          cb_log(3, bc->port, "BC not yet activated (state:%s)\n",bc_state2str(bc->bc_state));
04196          return -1;
04197    }
04198    
04199    frm= (iframe_t*)buf;
04200    
04201    frm->prim = DL_DATA|REQUEST;
04202    frm->dinfo = 0;
04203    frm->addr = bc->addr | FLG_MSG_DOWN ;
04204    
04205    frm->len = len;
04206    memcpy(&buf[mISDN_HEADER_LEN], data,len);
04207       
04208    if ( misdn_cap_is_speech(bc->capability) ) 
04209       flip_buf_bits( &buf[mISDN_HEADER_LEN], len);
04210    else
04211       cb_log(6, stack->port, "Writing %d data bytes\n",len);
04212    
04213    cb_log(9, stack->port, "Writing %d bytes 2 mISDN\n",len);
04214    r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT);
04215    return 0;
04216 }

void misdn_send_lock ( struct misdn_bchannel bc  ) 

Definition at line 3295 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().

03296 {
03297    //cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid);
03298    if (bc->send_lock)
03299       pthread_mutex_lock(&bc->send_lock->lock);
03300 }

void misdn_send_unlock ( struct misdn_bchannel bc  ) 

Definition at line 3302 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().

03303 {
03304    //cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid);
03305    if (bc->send_lock)
03306       pthread_mutex_unlock(&bc->send_lock->lock);
03307 }

void misdn_split_conf ( struct misdn_bchannel bc,
int  conf_id 
)

Definition at line 4533 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().

04534 {
04535    bc_state_change(bc,BCHAN_ACTIVATED);
04536    manager_ph_control(bc, CMX_RECEIVE_ON, 0);
04537    manager_ph_control(bc, CMX_CONF_SPLIT, conf_id);
04538 
04539    cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id);
04540 }

void misdn_tx_jitter ( struct misdn_bchannel bc,
int  len 
)

Definition at line 2238 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().

02239 {
02240    char buf[4096 + mISDN_HEADER_LEN];
02241    char *data=&buf[mISDN_HEADER_LEN];
02242    iframe_t *txfrm= (iframe_t*)buf;
02243    int jlen, r;
02244    
02245    jlen=cb_jb_empty(bc,data,len);
02246    
02247    if (jlen) {
02248 #ifdef MISDN_SAVE_DATA
02249       misdn_save_data((bc->port*100+bc->channel), data, jlen, bc->bframe, bc->bframe_len);
02250 #endif
02251       flip_buf_bits( data, jlen);
02252       
02253       if (jlen < len) {
02254          cb_log(7,bc->port,"Jitterbuffer Underrun.\n");
02255       }
02256       
02257       txfrm->prim = DL_DATA|REQUEST;
02258       
02259       txfrm->dinfo = 0;
02260       
02261       txfrm->addr = bc->addr|FLG_MSG_DOWN; /*  | IF_DOWN; */
02262       
02263       txfrm->len =jlen;
02264       cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len);
02265 
02266       r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 );
02267    } else {
02268 #define MISDN_GEN_SILENCE
02269 #ifdef MISDN_GEN_SILENCE
02270       int cnt=len/TONE_SILENCE_SIZE;
02271       int rest=len%TONE_SILENCE_SIZE;
02272       int i;
02273 
02274       for (i=0; i<cnt; i++) {
02275          memcpy(data, tone_silence_flip, TONE_SILENCE_SIZE );
02276          data +=TONE_SILENCE_SIZE;
02277       }
02278 
02279       if (rest) {
02280          memcpy(data, tone_silence_flip, rest);
02281       }
02282 
02283       txfrm->prim = DL_DATA|REQUEST;
02284 
02285       txfrm->dinfo = 0;
02286 
02287       txfrm->addr = bc->addr|FLG_MSG_DOWN; /*  | IF_DOWN; */
02288 
02289       txfrm->len =len;
02290       cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len);
02291 
02292       r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 );
02293 #endif
02294 
02295    }
02296 }

static void prepare_bc ( struct misdn_bchannel bc,
int  channel 
) [static]

Definition at line 3141 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_bchannel::b_stid, misdn_bchannel::cause, misdn_bchannel::channel, misdn_bchannel::channel_preselected, misdn_bchannel::in_use, misdn_bchannel::layer_id, mypid, misdn_bchannel::need_disconnect, misdn_bchannel::need_release, misdn_bchannel::need_release_complete, and misdn_bchannel::pid.

Referenced by misdn_lib_get_free_bc().

03142 {
03143    bc->channel = channel;
03144    bc->channel_preselected = channel?1:0;
03145    bc->in_use = 1;
03146    bc->need_disconnect=1;
03147    bc->need_release=1;
03148    bc->need_release_complete=1;
03149    bc->cause=16;
03150 
03151    if (++mypid>5000) mypid=1;
03152    bc->pid=mypid;
03153 
03154 #if 0
03155    bc->addr=0;
03156    bc->b_stid=0;
03157    bc->layer_id=0;
03158 #endif
03159 }

int queue_cleanup_bc ( struct misdn_bchannel bc  ) 

Definition at line 3723 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.

03724 {
03725    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03726    iframe_t *frm;
03727    if (!msg) {
03728       cb_log(0, bc->port, "misgn_lib_get_port: alloc_msg failed!\n");
03729       return -1;
03730    }
03731    frm=(iframe_t*)msg->data;
03732 
03733    /* activate bchannel */
03734    frm->prim = MGR_CLEARSTACK| REQUEST;
03735 
03736    frm->addr = bc->l3_id;
03737 
03738    frm->dinfo = bc->port;
03739    frm->len = 0;
03740   
03741    msg_queue_tail(&glob_mgr->activatequeue, msg);
03742    sem_post(&glob_mgr->new_msg);
03743 
03744    return 0; 
03745 
03746 }

int release_cr ( struct misdn_stack stack,
mISDNuser_head_t *  hh 
)

Definition at line 1780 of file isdn_lib.c.

References misdn_bchannel::addr, cb_log, find_bc_by_l3id(), handle_cr(), misdn_bchannel::l3_id, make_dummy(), misdn_stack::nt, misdn_stack::port, misdn_stack::procids, and misdn_stack::upper_id.

Referenced by handle_event_nt().

01781 {
01782    struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
01783    struct misdn_bchannel dummybc;
01784    iframe_t frm; /* fake te frm to remove callref from global callreflist */
01785    frm.dinfo = hh->dinfo;
01786 
01787    frm.addr=stack->upper_id | FLG_MSG_DOWN;
01788 
01789    frm.prim = CC_RELEASE_CR|INDICATION;
01790    cb_log(4, stack->port, " --> CC_RELEASE_CR: Faking Realease_cr for %x l3id:%x\n",frm.addr, frm.dinfo);
01791    /** removing procid **/
01792    if (!bc) {
01793       cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", hh->dinfo);
01794       make_dummy(&dummybc, stack->port, hh->dinfo, stack->nt, 0);
01795       bc=&dummybc; 
01796    }
01797 
01798    if (bc) {
01799       if ( (bc->l3_id & 0xff00) == 0xff00) {
01800          cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", bc->l3_id&0xff);
01801          stack->procids[bc->l3_id&0xff] = 0 ;
01802       }
01803    }
01804    else cb_log(0, stack->port, "Couldnt find BC so I couldnt remove the Process!!!! this is a bad port.\n");
01805 
01806    if (handle_cr(stack, &frm)<0) {
01807    }
01808 
01809    return 0 ;
01810 }

static int send_msg ( int  midev,
struct misdn_bchannel bc,
msg_t *  dmsg 
) [static]

Definition at line 383 of file isdn_lib.c.

References misdn_stack::bc, cb_log, get_stack_by_bc(), misdn_bchannel::l3_id, misdn_stack::port, misdn_bchannel::port, and misdn_stack::upper_id.

Referenced by manager_event_handler().

00384 {
00385    struct misdn_stack *stack;
00386    iframe_t *frm;
00387    frm = (iframe_t *)dmsg->data;
00388    stack=get_stack_by_bc(bc);
00389 
00390    if (!stack) {
00391       cb_log(0,bc->port,"send_msg: IEK!! no stack\n ");
00392       return -1;
00393    }
00394    
00395    frm->addr = (stack->upper_id | FLG_MSG_DOWN);
00396    frm->dinfo = bc->l3_id;
00397    frm->len = (dmsg->len) - mISDN_HEADER_LEN;
00398             
00399    cb_log(4,stack->port,"Sending msg, prim:%x addr:%x dinfo:%x\n",frm->prim,frm->addr,frm->dinfo);
00400 
00401    mISDN_write(midev, dmsg->data, dmsg->len, TIMEOUT_1SEC);
00402    free_msg(dmsg);
00403 
00404    return 0;
00405 }

int set_chan_in_stack ( struct misdn_stack stack,
int  channel 
) [static]

Definition at line 456 of file isdn_lib.c.

References cb_log, misdn_stack::channels, dump_chan_list(), MAX_BCHANS, and misdn_stack::port.

Referenced by handle_frm().

00457 {
00458 
00459    cb_log(4,stack->port,"set_chan_in_stack: %d\n",channel);
00460    dump_chan_list(stack);
00461    if (channel >=1 && channel <= MAX_BCHANS) {
00462       if (!stack->channels[channel-1])
00463          stack->channels[channel-1] = 1;
00464       else {
00465          cb_log(4,stack->port,"channel already in use:%d\n", channel );
00466          return -1;
00467       }
00468    } else {
00469       cb_log(0,stack->port,"couldn't set channel %d in\n", channel );
00470       return -1;
00471    }
00472   
00473    return 0;
00474 }

int setup_bc ( struct misdn_bchannel bc  ) 

Definition at line 952 of file isdn_lib.c.

References misdn_stack::b_num, misdn_bchannel::b_stid, misdn_stack::b_stids, misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), BCHAN_CLEANED, cb_log, misdn_bchannel::channel, get_stack_by_bc(), misdn_stack::midev, misdn_stack::port, and misdn_bchannel::port.

Referenced by handle_event(), misdn_lib_send_event(), and misdn_lib_setup_bc().

00953 {
00954    unsigned char buff[1025];
00955    int midev, i;
00956    int channel;
00957    int b_stid;
00958   
00959    mISDN_pid_t pid;
00960    int ret;
00961    
00962 
00963    struct misdn_stack *stack=get_stack_by_bc(bc);
00964 
00965    if (!stack) {
00966       cb_log(0, bc->port, "setup_bc: NO STACK FOUND!!\n");
00967       return -1;
00968    }
00969    
00970    midev=stack->midev;
00971    channel=bc->channel-1-(bc->channel>16);
00972    b_stid=stack->b_stids[channel>=0?channel:0];
00973 
00974    
00975    switch (bc->bc_state) {
00976       case BCHAN_CLEANED:
00977          break;
00978       default:
00979          cb_log(4, stack->port, "$$$ bc already upsetted stid :%x (state:%s)\n", b_stid, bc_state2str(bc->bc_state) );
00980          return -1;
00981    }
00982    
00983    cb_log(5, stack->port, "$$$ Setting up bc with stid :%x\n", b_stid);
00984    
00985    /*check if the b_stid is alread initialized*/
00986    for (i=0; i <= stack->b_num; i++) {
00987       if (stack->bc[i].b_stid == b_stid) {
00988          cb_log(0, bc->port, "setup_bc: b_stid:%x already in use !!!\n", b_stid);
00989          return -1;
00990       }
00991    }
00992    
00993    if (b_stid <= 0) {
00994       cb_log(0, stack->port," -- Stid <=0 at the moment in channel:%d\n",channel);
00995       
00996       bc_state_change(bc,BCHAN_ERROR);
00997       return 1;
00998    }
00999    
01000    
01001    bc->b_stid = b_stid;
01002    
01003    {
01004       layer_info_t li;
01005       memset(&li, 0, sizeof(li));
01006     
01007       li.object_id = -1;
01008       li.extentions = 0;
01009       
01010       li.st = bc->b_stid; /*  given idx */
01011 
01012 
01013 #define MISDN_DSP
01014 #ifndef MISDN_DSP
01015       bc->nodsp=1;
01016 #endif
01017       if ( bc->hdlc || bc->nodsp) {
01018          cb_log(4, stack->port,"setup_bc: without dsp\n");
01019          { 
01020             int l = sizeof(li.name);
01021             strncpy(li.name, "B L3", l);
01022             li.name[l-1] = 0;
01023          }
01024          li.pid.layermask = ISDN_LAYER((3));
01025          li.pid.protocol[3] = ISDN_PID_L3_B_USER;
01026          
01027          bc->layer=3;
01028       } else {
01029          cb_log(4, stack->port,"setup_bc: with dsp\n");
01030          { 
01031             int l = sizeof(li.name);
01032             strncpy(li.name, "B L4", l);
01033             li.name[l-1] = 0;
01034          }
01035          li.pid.layermask = ISDN_LAYER((4));
01036          li.pid.protocol[4] = ISDN_PID_L4_B_USER
01037 ;
01038          bc->layer=4;
01039          
01040       }  
01041       
01042       ret = mISDN_new_layer(midev, &li);
01043       if (ret ) {
01044          cb_log(0, stack->port,"New Layer Err: %d %s\n",ret,strerror(errno));
01045 
01046          bc_state_change(bc,BCHAN_ERROR);
01047          return(-EINVAL);
01048       }
01049       
01050       bc->layer_id = li.id;
01051    }
01052    
01053    memset(&pid, 0, sizeof(pid));
01054    
01055    
01056    
01057    cb_log(4, stack->port," --> Channel is %d\n", bc->channel);
01058    
01059    if (bc->nodsp) {
01060       cb_log(2, stack->port," --> TRANSPARENT Mode (no DSP, no HDLC)\n");
01061       pid.protocol[1] = ISDN_PID_L1_B_64TRANS;
01062       pid.protocol[2] = ISDN_PID_L2_B_TRANS;
01063       pid.protocol[3] = ISDN_PID_L3_B_USER;
01064       pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3));
01065       
01066    } else if ( bc->hdlc ) {
01067       cb_log(2, stack->port," --> HDLC Mode\n");
01068       pid.protocol[1] = ISDN_PID_L1_B_64HDLC ;
01069       pid.protocol[2] = ISDN_PID_L2_B_TRANS  ;
01070       pid.protocol[3] = ISDN_PID_L3_B_USER;
01071       pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) ;
01072    } else {
01073       cb_log(2, stack->port," --> TRANSPARENT Mode\n");
01074       pid.protocol[1] = ISDN_PID_L1_B_64TRANS;
01075       pid.protocol[2] = ISDN_PID_L2_B_TRANS;
01076       pid.protocol[3] = ISDN_PID_L3_B_DSP;
01077       pid.protocol[4] = ISDN_PID_L4_B_USER;
01078       pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) | ISDN_LAYER((4));
01079       
01080    } 
01081 
01082    ret = mISDN_set_stack(midev, bc->b_stid, &pid);
01083 
01084    if (ret){
01085       cb_log(0, stack->port,"$$$ Set Stack Err: %d %s\n",ret,strerror(errno));
01086       
01087       mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
01088       
01089       bc_state_change(bc,BCHAN_ERROR);
01090       cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data);
01091       return(-EINVAL);
01092    }
01093 
01094    ret = mISDN_get_setstack_ind(midev, bc->layer_id);
01095 
01096    if (ret) {
01097       cb_log(0, stack->port,"$$$ Set StackIND Err: %d %s\n",ret,strerror(errno));
01098       mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
01099       
01100       bc_state_change(bc,BCHAN_ERROR);
01101       cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data);
01102       return(-EINVAL);
01103    }
01104 
01105    ret = mISDN_get_layerid(midev, bc->b_stid, bc->layer) ;
01106 
01107    bc->addr = ret>0? ret : 0;
01108 
01109    if (!bc->addr) {
01110       cb_log(0, stack->port,"$$$ Get Layerid Err: %d %s\n",ret,strerror(errno));
01111       mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
01112       
01113       bc_state_change(bc,BCHAN_ERROR);
01114       cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data);
01115       return (-EINVAL);
01116    }
01117 
01118    manager_bchannel_activate(bc);
01119    
01120    bc_state_change(bc,BCHAN_ACTIVATED);
01121 
01122    return 0;
01123 }

void stack_destroy ( struct misdn_stack stack  ) 

Definition at line 1377 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().

01378 {
01379    char buf[1024];
01380    if (!stack) return;
01381 
01382    if (stack->nt) {
01383       cleanup_Isdnl2(&stack->nst);
01384       cleanup_Isdnl3(&stack->nst);
01385    }
01386   
01387    if (stack->lower_id) 
01388       mISDN_write_frame(stack->midev, buf, stack->lower_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
01389 
01390    if (stack->upper_id) 
01391       mISDN_write_frame(stack->midev, buf, stack->upper_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
01392 }

void stack_holder_add ( struct misdn_stack stack,
struct misdn_bchannel holder 
)

Definition at line 4306 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().

04307 {
04308    struct misdn_bchannel *help;
04309    cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id);
04310    
04311    holder->stack_holder=1;
04312 
04313    if (!stack ) return ;
04314    
04315    holder->next=NULL;
04316    
04317    if (!stack->holding) {
04318       stack->holding = holder;
04319       return;
04320    }
04321   
04322    for (help=stack->holding;
04323         help;
04324         help=help->next) {
04325       if (!help->next) {
04326          help->next=holder;
04327          break;
04328       }
04329    }
04330   
04331 }

struct misdn_bchannel * stack_holder_find ( struct misdn_stack stack,
unsigned long  l3id 
)

Definition at line 4381 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().

04382 {
04383    struct misdn_bchannel *help;
04384 
04385    cb_log(4,stack?stack->port:0, "*HOLDER: find %x\n",l3id);
04386    
04387    if (!stack) return NULL;
04388    
04389    for (help=stack->holding;
04390         help;
04391         help=help->next) {
04392       if (help->l3_id == l3id) {
04393          cb_log(4,stack->port, "*HOLDER: found bc\n");
04394          return help;
04395       }
04396    }
04397 
04398    cb_log(4,stack->port, "*HOLDER: find nothing\n");
04399    return NULL;
04400 }

struct misdn_bchannel * stack_holder_find_bychan ( struct misdn_stack stack,
int  chan 
)

Definition at line 4359 of file isdn_lib.c.

References cb_log, misdn_bchannel::channel, misdn_stack::holding, misdn_bchannel::next, and misdn_stack::port.

04360 {
04361    struct misdn_bchannel *help;
04362 
04363    cb_log(4,stack?stack->port:0, "*HOLDER: find_bychan %c\n", chan);
04364    
04365    if (!stack) return NULL;
04366    
04367    for (help=stack->holding;
04368         help;
04369         help=help->next) {
04370       if (help->channel == chan) {
04371          cb_log(4,stack->port, "*HOLDER: found_bychan bc\n");
04372          return help;
04373       }
04374    }
04375 
04376    cb_log(4,stack->port, "*HOLDER: find_bychan nothing\n");
04377    return NULL;
04378 
04379 }

void stack_holder_remove ( struct misdn_stack stack,
struct misdn_bchannel holder 
)

Definition at line 4333 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().

04334 {
04335    struct misdn_bchannel *h1;
04336 
04337    if (!holder->stack_holder) return;
04338    
04339    holder->stack_holder=0;
04340    
04341    cb_log(4,stack->port, "*HOLDER: remove %x\n",holder->l3_id);
04342    if (!stack || ! stack->holding) return;
04343   
04344    if (holder == stack->holding) {
04345       stack->holding = stack->holding->next;
04346       return;
04347    }
04348    
04349    for (h1=stack->holding;
04350         h1;
04351         h1=h1->next) {
04352       if (h1->next == holder) {
04353          h1->next=h1->next->next;
04354          return ;
04355       }
04356    }
04357 }

struct misdn_stack * stack_init ( int  midev,
int  port,
int  ptp 
)

Definition at line 1192 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().

01193 {
01194    int ret;
01195    unsigned char buff[1025];
01196    iframe_t *frm = (iframe_t *)buff;
01197    stack_info_t *stinf;
01198    int i; 
01199    layer_info_t li;
01200 
01201    struct misdn_stack *stack = malloc(sizeof(struct misdn_stack));
01202    if (!stack ) return NULL;
01203 
01204 
01205    cb_log(8, port, "Init. Stack.\n");
01206   
01207    memset(stack,0,sizeof(struct misdn_stack));
01208   
01209    for (i=0; i<MAX_BCHANS + 1; i++ ) stack->channels[i]=0;
01210    
01211    stack->port=port;
01212    stack->midev=midev;
01213    stack->ptp=ptp;
01214   
01215    stack->holding=NULL;
01216    stack->pri=0;
01217   
01218    msg_queue_init(&stack->downqueue);
01219    msg_queue_init(&stack->upqueue);
01220   
01221    /* query port's requirements */
01222    ret = mISDN_get_stack_info(midev, port, buff, sizeof(buff));
01223    if (ret < 0) {
01224       cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret);
01225       return(NULL);
01226    }
01227   
01228    stinf = (stack_info_t *)&frm->data.p;
01229 
01230    stack->d_stid = stinf->id;
01231    stack->b_num = stinf->childcnt;
01232 
01233    for (i=0; i<=stinf->childcnt; i++)
01234       stack->b_stids[i] = stinf->child[i];
01235   
01236    switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK) {
01237    case ISDN_PID_L0_TE_S0:
01238       stack->nt=0;
01239       break;
01240    case ISDN_PID_L0_NT_S0:
01241       cb_log(8, port, "NT Stack\n");
01242 
01243       stack->nt=1;
01244       break;
01245    case ISDN_PID_L0_TE_E1:
01246       cb_log(8, port, "TE S2M Stack\n");
01247       stack->nt=0;
01248       stack->pri=1;
01249       break;
01250    case ISDN_PID_L0_NT_E1:
01251       cb_log(8, port, "TE S2M Stack\n");
01252       stack->nt=1;
01253       stack->pri=1;
01254       
01255       break;
01256    default:
01257       cb_log(0, port, "this is a unknown port type 0x%08x\n", stinf->pid.protocol[0]);
01258 
01259    }
01260 
01261    if (!stack->nt) {
01262       if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP ) { 
01263          stack->ptp = 1;
01264       } else {
01265          stack->ptp = 0;
01266       }
01267    }
01268    
01269    {
01270       int ret;
01271       int nt=stack->nt;
01272 
01273       cb_log(8, port, "Init. Stack.\n");
01274       
01275       memset(&li, 0, sizeof(li));
01276       {
01277          int l = sizeof(li.name);
01278          strncpy(li.name,nt?"net l2":"user l4", l);
01279          li.name[l-1] = 0;
01280       }
01281       li.object_id = -1;
01282       li.extentions = 0;
01283       li.pid.protocol[nt?2:4] = nt?ISDN_PID_L2_LAPD_NET:ISDN_PID_L4_CAPI20;
01284       li.pid.layermask = ISDN_LAYER((nt?2:4));
01285       li.st = stack->d_stid;
01286       
01287       
01288       ret = mISDN_new_layer(midev, &li);
01289       if (ret) {
01290          cb_log(0, port, "%s: Cannot add layer %d to this port.\n", __FUNCTION__, nt?2:4);
01291          return(NULL);
01292       }
01293       
01294       
01295       stack->upper_id = li.id;
01296       ret = mISDN_register_layer(midev, stack->d_stid, stack->upper_id);
01297       if (ret)
01298       {
01299          cb_log(0,port,"Cannot register layer %d of this port.\n", nt?2:4);
01300          return(NULL);
01301       }
01302       
01303       stack->lower_id = mISDN_get_layerid(midev, stack->d_stid, nt?1:3); 
01304       if (stack->lower_id < 0) {
01305          cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, nt?1:3);
01306          return(NULL);
01307       }
01308       
01309       stack->upper_id = mISDN_get_layerid(midev, stack->d_stid, nt?2:4);
01310       if (stack->upper_id < 0) {
01311          cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, 2);
01312          return(NULL);
01313       }
01314       
01315       cb_log(8, port, "NT Stacks upper_id %x\n",stack->upper_id);
01316       
01317       
01318       /* create nst (nt-mode only) */
01319       if (nt) {
01320          
01321          memset(&stack->nst, 0, sizeof(net_stack_t));
01322          memset(&stack->mgr, 0, sizeof(manager_t));
01323     
01324          stack->mgr.nst = &stack->nst;
01325          stack->nst.manager = &stack->mgr;
01326     
01327          stack->nst.l3_manager = handle_event_nt;
01328          stack->nst.device = midev;
01329          stack->nst.cardnr = port;
01330          stack->nst.d_stid = stack->d_stid;
01331     
01332          stack->nst.feature = FEATURE_NET_HOLD;
01333          if (stack->ptp)
01334             stack->nst.feature |= FEATURE_NET_PTP;
01335          if (stack->pri)
01336             stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
01337          
01338          stack->nst.l1_id = stack->lower_id;
01339          stack->nst.l2_id = stack->upper_id;
01340          
01341          msg_queue_init(&stack->nst.down_queue);
01342          
01343          Isdnl2Init(&stack->nst);
01344          Isdnl3Init(&stack->nst);
01345          
01346       } 
01347       
01348       if (!stack->nt) {
01349          /*assume L1 is up, we'll get DEACTIVATES soon, for non
01350           * up L1s*/
01351          stack->l1link=0;
01352       }
01353       stack->l1link=0;
01354       stack->l2link=0;
01355 #if 0 
01356       if (!stack->nt) {
01357          misdn_lib_get_short_status(stack);
01358       } else {
01359          misdn_lib_get_l1_up(stack);
01360          if (!stack->ptp) misdn_lib_get_l1_up(stack);
01361          misdn_lib_get_l2_up(stack);
01362       }
01363 #endif
01364 
01365       misdn_lib_get_short_status(stack);
01366       misdn_lib_get_l1_up(stack);
01367       misdn_lib_get_l2_up(stack); 
01368       
01369    }
01370 
01371    cb_log(8,0,"stack_init: port:%d lowerId:%x  upperId:%x\n",stack->port,stack->lower_id, stack->upper_id);
01372    
01373    return stack;
01374 }

void te_lib_destroy ( int  midev  ) 

Definition at line 3081 of file isdn_lib.c.

References cb_log, and entity.

Referenced by misdn_lib_destroy().

03082 {
03083    char buf[1024];
03084    mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC);
03085 
03086    cb_log(4, 0, "Entetity deleted\n");
03087    mISDN_close(midev);
03088    cb_log(4, 0, "midev closed\n");
03089 }

int te_lib_init ( void   ) 

App Interface

Definition at line 3052 of file isdn_lib.c.

References entity, errno, and misdn_lib::midev.

Referenced by misdn_lib_init().

03052                   {
03053    char buff[1025];
03054    iframe_t *frm=(iframe_t*)buff;
03055    int midev=mISDN_open();
03056    int ret;
03057 
03058    memset(buff,0,1025);
03059   
03060    if  (midev<=0) return midev;
03061   
03062 /* create entity for layer 3 TE-mode */
03063    mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
03064    ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC);
03065   
03066    if (ret < mISDN_HEADER_LEN) {
03067    noentity:
03068       fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n",strerror(errno));
03069       exit(-1);
03070    }
03071   
03072    entity = frm->dinfo & 0xffff ;
03073   
03074    if (!entity)
03075       goto noentity;
03076 
03077    return midev;
03078   
03079 }

static int test_inuse ( struct misdn_bchannel bc  )  [static]

Definition at line 3121 of file isdn_lib.c.

References misdn_bchannel::b_stid, cb_log, misdn_bchannel::in_use, misdn_bchannel::last_used, misdn_lib_port_is_pri(), and misdn_bchannel::port.

Referenced by misdn_lib_get_free_bc().

03122 {
03123    struct timeval now;
03124    gettimeofday(&now, NULL);
03125    if (!bc->in_use) {
03126       if (misdn_lib_port_is_pri(bc->port) && bc->last_used.tv_sec == now.tv_sec ) {
03127          cb_log(2,bc->port, "channel with stid:%x for one second still in use! (n:%d lu:%d)\n", bc->b_stid, now.tv_sec, bc->last_used.tv_sec);
03128          return 1;
03129       }
03130       
03131 
03132       cb_log(3,bc->port, "channel with stid:%x not in use!\n", bc->b_stid);
03133       return 0;
03134    }
03135    
03136    cb_log(2,bc->port, "channel with stid:%x in use!\n", bc->b_stid);
03137    return 1;
03138 }


Variable Documentation

int entity [static]

Definition at line 227 of file isdn_lib.c.

Referenced by create_process(), te_lib_destroy(), and te_lib_init().

char flip_table[256] [static]

Definition at line 292 of file isdn_lib.c.

Referenced by flip_buf_bits(), and init_flip_bits().

struct misdn_lib* glob_mgr [static]

Definition at line 229 of file isdn_lib.c.

Referenced by do_tone(), find_bc_by_addr(), find_bc_by_confid(), find_stack_by_addr(), find_stack_by_mgr(), find_stack_by_port(), get_misdn_stack(), handle_bchan(), handle_cr(), handle_event_nt(), handle_frm(), handle_l1(), handle_l2(), handle_timers(), manager_event_handler(), manager_find_bc_by_pid(), manager_ph_control(), manager_ph_control_block(), misdn_lib_destroy(), misdn_lib_get_free_bc(), misdn_lib_get_port_down(), misdn_lib_get_port_info(), misdn_lib_get_port_up(), misdn_lib_init(), misdn_lib_isdn_l1watcher(), misdn_lib_port_restart(), misdn_lib_port_up(), misdn_lib_reinit_nt_stack(), misdn_lib_send_event(), misdn_lib_send_tone(), misdn_tx_jitter(), and queue_cleanup_bc().

enum global_states global_state = MISDN_INITIALIZING [static]

Definition at line 160 of file isdn_lib.c.

Referenced by clear_l3(), handle_l1(), and misdn_lib_destroy().

sem_t handler_started

Definition at line 3837 of file isdn_lib.c.

struct isdn_msg msgs_g[]

Msg Array

Definition at line 1158 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]

Definition at line 408 of file isdn_lib.c.

Referenced by prepare_bc().

int newteid = 0 [static]

Definition at line 763 of file isdn_lib.c.

int nt_err_cnt = 0 [static]

Definition at line 153 of file isdn_lib.c.

Referenced by handle_frm_nt().

char tone_425_flip[TONE_425_SIZE]

Definition at line 231 of file isdn_lib.c.

Referenced by misdn_lib_init().

char tone_silence_flip[TONE_SILENCE_SIZE]

Definition at line 232 of file isdn_lib.c.

Referenced by misdn_lib_init(), and misdn_tx_jitter().


Generated on Mon Nov 24 15:34:43 2008 for Asterisk - the Open Source PBX by  doxygen 1.4.7