Mon Mar 31 07:41:08 2008

Asterisk developer's documentation


isdn_lib.c File Reference

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

Include dependency graph for isdn_lib.c:

Go to the source code of this file.

Data Structures

struct  misdn_lib

Defines

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

Enumerations

enum  global_states { MISDN_INITIALIZING, MISDN_INITIALIZED }

Functions

static void bc_next_state_change (struct misdn_bchannel *bc, enum bchannel_state state)
char * bc_state2str (enum bchannel_state state)
void bc_state_change (struct misdn_bchannel *bc, enum bchannel_state state)
int bchdev_echocancel_activate (struct misdn_bchannel *dev)
void bchdev_echocancel_deactivate (struct misdn_bchannel *dev)
static char * bearer2str (int cap)
static int clean_up_bc (struct misdn_bchannel *bc)
static void clear_l3 (struct misdn_stack *stack)
static msg_t * create_l2msg (int prim, int dinfo, int size)
msg_t * create_l3msg (int prim, int mt, int dinfo, int size, int ntmode)
static int create_process (int midev, struct misdn_bchannel *bc)
static int do_tone (struct misdn_bchannel *bc, int len)
static void dump_chan_list (struct misdn_stack *stack)
void ec_chunk (struct misdn_bchannel *bc, unsigned char *rxchunk, unsigned char *txchunk, int chunk_size)
static void empty_bc (struct misdn_bchannel *bc)
static int empty_chan_in_stack (struct misdn_stack *stack, int channel)
static char * fac2str (enum FacFunction func)
static msg_t * fetch_msg (int midev)
static struct misdn_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)

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

Referenced by manager_ec_disable().

#define ECHOCAN_ON   123

Definition at line 190 of file isdn_lib.c.

Referenced by manager_ec_enable().

#define ISDN_PID_L3_B_USER   0x430000ff

Definition at line 213 of file isdn_lib.c.

#define ISDN_PID_L4_B_USER   0x440000ff

Definition at line 214 of file isdn_lib.c.

#define MAXPROCS   0x100

Definition at line 762 of file isdn_lib.c.

Referenced by create_process().

#define MISDN_DEBUG   0

Definition at line 194 of file isdn_lib.c.

#define MISDN_DSP

#define MISDN_GEN_SILENCE

#define MISDN_IBUF_SIZE   512

Definition at line 217 of file isdn_lib.c.

Referenced by init_bc().

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

Definition at line 3239 of file isdn_lib.c.

Referenced by misdn_lib_send_event().

#define TONE_ALERT_CNT   41

Definition at line 220 of file isdn_lib.c.

#define TONE_ALERT_SILENCE_CNT   200

Definition at line 221 of file isdn_lib.c.

#define TONE_BUSY_CNT   20

Definition at line 223 of file isdn_lib.c.

#define TONE_BUSY_SILENCE_CNT   48

Definition at line 224 of file isdn_lib.c.


Enumeration Type Documentation

enum global_states

Enumerator:
MISDN_INITIALIZING 
MISDN_INITIALIZED 

Definition at line 154 of file isdn_lib.c.

00154                    {
00155    MISDN_INITIALIZING,
00156    MISDN_INITIALIZED
00157 } ;


Function Documentation

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

Definition at line 601 of file isdn_lib.c.

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

Referenced by misdn_lib_bridge().

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

char* bc_state2str ( enum bchannel_state  state  ) 

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

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

void bc_state_change ( struct misdn_bchannel bc,
enum bchannel_state  state 
)

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

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

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

References INFO_CAPABILITY_AUDIO_3_1K, INFO_CAPABILITY_DIGITAL_RESTRICTED, INFO_CAPABILITY_DIGITAL_UNRESTRICTED, and INFO_CAPABILITY_SPEECH.

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

static int clean_up_bc ( struct misdn_bchannel bc  )  [static]

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

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

static void clear_l3 ( struct misdn_stack stack  )  [static]

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

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

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

Definition at line 321 of file isdn_lib.c.

Referenced by misdn_lib_get_l2_down(), and misdn_lib_get_l2_up().

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

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

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

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

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

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

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

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

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

02183 {
02184    bc->tone_cnt=len;
02185    
02186    if (bc->generate_tone) {
02187       cb_event(EVENT_TONE_GENERATE, bc, glob_mgr->user_data);
02188       
02189       if ( !bc->nojitter ) {
02190          misdn_tx_jitter(bc,len);
02191       }
02192       
02193       return 1;
02194    }
02195    
02196    return 0;
02197 }

static void dump_chan_list ( struct misdn_stack stack  )  [static]

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

00437 {
00438    int i;
00439 
00440    for (i=0; i <= stack->b_num; i++) {
00441       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);
00442    }
00443 }

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 611 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::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().

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

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

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

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

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

Definition at line 3185 of file isdn_lib.c.

References s.

Referenced by misdn_lib_log_ies().

03186 {
03187    struct arr_el { 
03188       enum FacFunction p; 
03189       char *s ; 
03190    } arr[] = {
03191       { Fac_None, "Fac_None" },
03192       { Fac_CD, "Fac_CD"},
03193    };
03194    
03195    int i;
03196    
03197    for (i=0; i < sizeof(arr)/sizeof( struct arr_el) ; i ++)
03198       if ( arr[i].p==func) return arr[i].s;
03199    
03200    return "unknown";
03201 }

static msg_t* fetch_msg ( int  midev  )  [static]

Definition at line 2922 of file isdn_lib.c.

References cb_log, and errno.

Referenced by misdn_lib_isdn_event_catcher().

02923 {
02924    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
02925    int r;
02926 
02927    if (!msg) {
02928       cb_log(0, 0, "fetch_msg: alloc msg failed !!");
02929       return NULL;
02930    }
02931 
02932    AGAIN:
02933       r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC);
02934       msg->len=r;
02935     
02936       if (r==0) {
02937          free_msg(msg); /* danger, cauz usualy freeing in main_loop */
02938          cb_log(6,0,"Got empty Msg..\n");
02939          return NULL;
02940       }
02941 
02942       if (r<0) {
02943          if (errno == EAGAIN) {
02944             /*we wait for mISDN here*/
02945             cb_log(4,0,"mISDN_read wants us to wait\n");
02946             usleep(5000);
02947             goto AGAIN;
02948          }
02949          
02950          cb_log(0,0,"mISDN_read returned :%d error:%s (%d)\n",r,strerror(errno),errno); 
02951       }
02952 
02953 #if 0
02954                if  (!(frm->prim == (DL_DATA|INDICATION) )|| (frm->prim == (PH_DATA|INDICATION)))
02955                        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 );
02956 #endif
02957       return msg;
02958 }

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

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

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

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

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

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

struct misdn_bchannel * find_bc_by_confid ( unsigned long  confid  ) 

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

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

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

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

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

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

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

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

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

Definition at line 1450 of file isdn_lib.c.

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

Referenced by manager_find_bc_holded().

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

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

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

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

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

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

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

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

Definition at line 1419 of file isdn_lib.c.

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

Referenced by handle_event_nt().

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

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

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

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

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

Definition at line 306 of file isdn_lib.c.

References flip_table.

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

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

struct misdn_stack * get_misdn_stack ( void   ) 

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

04445                                       {
04446    return glob_mgr->stack_list;
04447 }

void get_show_stack_details ( int  port,
char *  buf 
)

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

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

struct misdn_stack* get_stack_by_bc ( struct misdn_bchannel bc  ) 

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

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

static int handle_bchan ( msg_t *  msg  )  [static]

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

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

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

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

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

static int handle_err ( msg_t *  msg  )  [static]

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

03475 {
03476    iframe_t *frm = (iframe_t*) msg->data;
03477 
03478 
03479    if (!frm->addr) {
03480       static int cnt=0;
03481       if (!cnt)
03482          cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo);
03483       cnt++;
03484       if (cnt>100) {
03485          cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo);
03486          cnt=0;
03487       }
03488       
03489       free_msg(msg);
03490       return 1;
03491       
03492    }
03493    
03494    switch (frm->prim) {
03495       case MGR_SETSTACK|INDICATION:
03496          return handle_bchan(msg);
03497       break;
03498 
03499       case MGR_SETSTACK|CONFIRM:
03500       case MGR_CLEARSTACK|CONFIRM:
03501          free_msg(msg) ; 
03502          return 1;
03503       break;
03504 
03505       case DL_DATA|CONFIRM:
03506          cb_log(4,0,"DL_DATA|CONFIRM\n");
03507          free_msg(msg);
03508          return 1;
03509 
03510       case PH_CONTROL|CONFIRM:
03511          cb_log(4,0,"PH_CONTROL|CONFIRM\n");
03512          free_msg(msg);
03513          return 1;
03514 
03515       case DL_DATA|INDICATION:
03516       {
03517          struct misdn_bchannel *bc;
03518          int port=(frm->addr&MASTER_ID_MASK) >> 8;
03519          int channel=(frm->addr&CHILD_ID_MASK) >> 16;
03520 
03521          /*we flush the read buffer here*/
03522          
03523          cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel);
03524          
03525          free_msg(msg) ; 
03526          return 1;
03527          
03528          
03529          bc=find_bc_by_channel( port , channel);
03530 
03531          if (!bc) {
03532             struct misdn_stack *stack=find_stack_by_port( port );
03533 
03534             if (!stack) {
03535                cb_log(0,0," --> stack not found\n");
03536                free_msg(msg);
03537                return 1;
03538             }
03539             
03540             cb_log(0,0," --> bc not found by channel\n");
03541             if (stack->l2link)
03542                misdn_lib_get_l2_down(stack);
03543 
03544             if (stack->l1link)
03545                misdn_lib_get_l1_down(stack);
03546 
03547             free_msg(msg);
03548             return 1;
03549          }
03550          
03551          cb_log(3,port," --> BC in state:%s\n", bc_state2str(bc->bc_state));
03552       }
03553    }
03554 
03555    return 0;
03556 }

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

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

01517 {
01518    struct misdn_stack *stack=get_stack_by_bc(bc);
01519    
01520    if (!stack->nt) {
01521       
01522       switch (event) {
01523 
01524       case EVENT_CONNECT_ACKNOWLEDGE:
01525          setup_bc(bc);
01526 
01527          if ( *bc->crypt_key ) {
01528             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);
01529             manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
01530          }
01531 
01532          if (misdn_cap_is_speech(bc->capability)) {
01533             if (  !bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0);
01534             manager_ec_enable(bc);
01535 
01536             if ( bc->txgain != 0 ) {
01537                cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain);
01538                manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
01539             }
01540             if ( bc->rxgain != 0 ) {
01541                cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain);
01542                manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
01543             }
01544          }
01545 
01546          break;
01547       case EVENT_CONNECT:
01548 
01549          if ( *bc->crypt_key ) {
01550             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);
01551             manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
01552          }
01553       case EVENT_ALERTING:
01554       case EVENT_PROGRESS:
01555       case EVENT_PROCEEDING:
01556       case EVENT_SETUP_ACKNOWLEDGE:
01557       case EVENT_SETUP:
01558       {
01559          if (bc->channel == 0xff || bc->channel<=0)
01560             bc->channel=0;
01561 
01562          if (find_free_chan_in_stack(stack, bc, bc->channel, 0)<0){
01563             if (!stack->pri && !stack->ptp)  {
01564                bc->cw=1;
01565                break;
01566             }
01567 
01568             cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n");
01569             misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
01570             return -1;
01571          }
01572       }
01573 
01574       setup_bc(bc);
01575       break;
01576 
01577       case EVENT_RELEASE_COMPLETE:
01578       case EVENT_RELEASE:
01579          break;
01580       default:
01581          break;
01582       }
01583    } else {    /** NT MODE **/
01584       
01585    }
01586    return 0;
01587 }

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

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

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

static int handle_frm ( msg_t *  msg  )  [static]

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

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

static int handle_frm_nt ( msg_t *  msg  )  [static]

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

02547 {
02548    iframe_t *frm= (iframe_t*)msg->data;
02549    struct misdn_stack *stack;
02550    int err=0;
02551 
02552    stack=find_stack_by_addr( frm->addr );
02553 
02554    
02555   
02556    if (!stack || !stack->nt) {
02557       return 0;
02558    }
02559 
02560    
02561    if ((err=stack->nst.l1_l2(&stack->nst,msg))) {
02562     
02563       if (nt_err_cnt > 0 ) {
02564          if (nt_err_cnt < 100) {
02565             nt_err_cnt++; 
02566             cb_log(0, stack->port, "NT Stack sends us error: %d \n", err);
02567          } else if (nt_err_cnt < 105){
02568             cb_log(0, stack->port, "NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err);
02569             nt_err_cnt = - 1; 
02570          }
02571       }
02572       free_msg(msg);
02573       return 1;
02574       
02575    }
02576    
02577    return 1;
02578 }

static int handle_l1 ( msg_t *  msg  )  [static]

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

02722 {
02723    iframe_t *frm = (iframe_t*) msg->data;
02724    struct misdn_stack *stack = find_stack_by_addr(frm->addr);
02725    int i ;
02726    
02727    if (!stack) return 0 ;
02728 
02729    switch (frm->prim) {
02730    case PH_ACTIVATE | CONFIRM:
02731    case PH_ACTIVATE | INDICATION:
02732       cb_log (3, stack->port, "L1: PH L1Link Up!\n");
02733       stack->l1link=1;
02734       
02735       if (stack->nt) {
02736          
02737          if (stack->nst.l1_l2(&stack->nst, msg))
02738             free_msg(msg);
02739 
02740          if (stack->ptp)
02741             misdn_lib_get_l2_up(stack);
02742       } else {
02743          free_msg(msg);
02744       }
02745       
02746       for (i=0;i<=stack->b_num; i++) {
02747          if (stack->bc[i].evq != EVENT_NOTHING) {
02748             cb_log(4, stack->port, "Fireing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0));
02749             misdn_lib_send_event(&stack->bc[i],stack->bc[i].evq);
02750             stack->bc[i].evq=EVENT_NOTHING;
02751          }
02752          
02753       }
02754       return 1;
02755 
02756    case PH_ACTIVATE | REQUEST:
02757       free_msg(msg);
02758       cb_log(3,stack->port,"L1: PH_ACTIVATE|REQUEST \n");
02759       return 1;
02760       
02761    case PH_DEACTIVATE | REQUEST:
02762       free_msg(msg);
02763       cb_log(3,stack->port,"L1: PH_DEACTIVATE|REQUEST \n");
02764       return 1;
02765       
02766    case PH_DEACTIVATE | CONFIRM:
02767    case PH_DEACTIVATE | INDICATION:
02768       cb_log (3, stack->port, "L1: PH L1Link Down! \n");
02769    
02770 #if 0
02771       for (i=0; i<=stack->b_num; i++) {
02772          if (global_state == MISDN_INITIALIZED)  {
02773             cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data);
02774          }
02775       }
02776 #endif
02777       
02778       if (stack->nt) {
02779          if (stack->nst.l1_l2(&stack->nst, msg))
02780             free_msg(msg);
02781       } else {
02782          free_msg(msg);
02783       }
02784       
02785       stack->l1link=0;
02786       stack->l2link=0;
02787       return 1;
02788    }
02789   
02790    return 0;
02791 }

static int handle_l2 ( msg_t *  msg  )  [static]

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

02794 {
02795    iframe_t *frm = (iframe_t*) msg->data;
02796 
02797    struct misdn_stack *stack = find_stack_by_addr(frm->addr);
02798    
02799    if (!stack) {
02800       return 0 ;
02801    }
02802    
02803    switch(frm->prim) {
02804 
02805    case DL_ESTABLISH | REQUEST:
02806       cb_log(1,stack->port,"DL_ESTABLISH|REQUEST \n");
02807       return 1;
02808    case DL_RELEASE | REQUEST:
02809       cb_log(1,stack->port,"DL_RELEASE|REQUEST \n");
02810       return 1;
02811       
02812    case DL_ESTABLISH | INDICATION:
02813    case DL_ESTABLISH | CONFIRM:
02814    {
02815       cb_log (3, stack->port, "L2: L2Link Up! \n");
02816       if (stack->ptp && stack->l2link) {
02817          cb_log (-1, stack->port, "L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n"); 
02818          cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data);
02819       }
02820       stack->l2link=1;
02821       free_msg(msg);
02822       return 1;
02823    }
02824    break;
02825     
02826    case DL_RELEASE | INDICATION:
02827    case DL_RELEASE | CONFIRM:
02828    {
02829       cb_log (3, stack->port, "L2: L2Link Down! \n");
02830       stack->l2link=0;
02831       
02832       free_msg(msg);
02833       return 1;
02834    }
02835    break;
02836    }
02837    return 0;
02838 }

static int handle_mgmt ( msg_t *  msg  )  [static]

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

02841 {
02842    struct misdn_stack *stack;
02843    iframe_t *frm = (iframe_t*) msg->data;
02844 
02845    if ( (frm->addr == 0) && (frm->prim == (MGR_DELLAYER|CONFIRM)) ) {
02846       cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: 0 !\n") ;
02847       free_msg(msg);
02848       return 1;
02849    }
02850    
02851    stack=find_stack_by_addr(frm->addr);
02852    
02853    if (!stack) {
02854       if (frm->prim == (MGR_DELLAYER|CONFIRM)) {
02855          cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: %x !\n",
02856                frm->addr) ;
02857          free_msg(msg);
02858          return 1;
02859       }
02860       
02861       return 0;
02862    }
02863    
02864    switch(frm->prim) {
02865    case MGR_SHORTSTATUS | INDICATION:
02866    case MGR_SHORTSTATUS | CONFIRM:
02867       cb_log(5, 0, "MGMT: Short status dinfo %x\n",frm->dinfo);
02868       
02869       switch (frm->dinfo) {
02870       case SSTATUS_L1_ACTIVATED:
02871          cb_log(3, 0, "MGMT: SSTATUS: L1_ACTIVATED \n");
02872          stack->l1link=1;
02873       
02874          break;
02875       case SSTATUS_L1_DEACTIVATED:
02876          cb_log(3, 0, "MGMT: SSTATUS: L1_DEACTIVATED \n");
02877          stack->l1link=0;
02878 #if 0
02879          clear_l3(stack);
02880 #endif
02881          break;
02882 
02883       case SSTATUS_L2_ESTABLISHED:
02884          cb_log(3, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n");
02885 
02886          /*when the L2 goes UP, L1 needs to be UP too*/
02887          stack->l1link=1;
02888          stack->l2link=1;
02889          break;
02890          
02891       case SSTATUS_L2_RELEASED:
02892          cb_log(3, stack->port, "MGMT: SSTATUS: L2_RELEASED \n");
02893          stack->l2link=0;
02894          break;
02895       }
02896       
02897       free_msg(msg);
02898       return 1;
02899       
02900    case MGR_SETSTACK | INDICATION:
02901       cb_log(4, stack->port, "MGMT: SETSTACK|IND dinfo %x\n",frm->dinfo);
02902       free_msg(msg);
02903       return 1;
02904    case MGR_DELLAYER | CONFIRM:
02905       cb_log(4, stack->port, "MGMT: DELLAYER|CNF dinfo %x\n",frm->dinfo) ;
02906       free_msg(msg);
02907       return 1;
02908       
02909    }
02910    
02911    /*
02912    if ( (frm->prim & 0x0f0000) ==  0x0f0000) {
02913    cb_log(5, 0, "$$$ MGMT FRAME: prim %x addr %x dinfo %x\n",frm->prim, frm->addr, frm->dinfo) ;
02914    free_msg(msg);
02915    return 1;
02916    } */
02917     
02918    return 0;
02919 }

static int handle_timers ( msg_t *  msg  )  [static]

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

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

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 1125 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().

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

static void init_flip_bits ( void   )  [static]

Definition at line 293 of file isdn_lib.c.

References flip_table.

Referenced by misdn_lib_init().

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

void isdn_lib_stop_dtmf ( struct misdn_bchannel bc  ) 

Definition at line 4202 of file isdn_lib.c.

References misdn_stack::bc, and manager_ph_control().

Referenced by process_ast_dsp().

04203 {
04204    manager_ph_control(bc, DTMF_TONE_STOP, 0);
04205 }

void isdn_lib_update_ec ( struct misdn_bchannel bc  ) 

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

04191 {
04192 #ifdef MISDN_1_2
04193    if (*bc->pipeline)
04194 #else
04195    if (bc->ec_enable)
04196 #endif
04197       manager_ec_enable(bc);
04198    else
04199       manager_ec_disable(bc);
04200 }

void isdn_lib_update_rxgain ( struct misdn_bchannel bc  ) 

Definition at line 4180 of file isdn_lib.c.

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

Referenced by process_ast_dsp().

04181 {
04182    manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
04183 }

void isdn_lib_update_txgain ( struct misdn_bchannel bc  ) 

Definition at line 4185 of file isdn_lib.c.

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

Referenced by process_ast_dsp().

04186 {
04187    manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
04188 }

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

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

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

void manager_bchannel_activate ( struct misdn_bchannel bc  ) 

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

04062 {
04063    char buf[128];
04064 
04065    struct misdn_stack *stack=get_stack_by_bc(bc);
04066 
04067    if (!stack) {
04068       cb_log(0, bc->port, "bchannel_activate: Stack not found !");
04069       return ;
04070    }
04071    
04072    /* we must activate if we are deactivated */
04073    clear_ibuffer(bc->astbuf);
04074    
04075    cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr);
04076    
04077    mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN,  DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC);
04078 
04079    return ;
04080 }

void manager_bchannel_cleanup ( struct misdn_bchannel bc  ) 

void manager_bchannel_deactivate ( struct misdn_bchannel bc  ) 

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

04084 {
04085    char buf[128]; 
04086    iframe_t dact;
04087    struct misdn_stack *stack=get_stack_by_bc(bc);
04088 
04089    switch (bc->bc_state) {
04090       case BCHAN_ACTIVATED:
04091          break;
04092       case BCHAN_BRIDGED:
04093          misdn_split_conf(bc,bc->conf_id);
04094          break;
04095       default:
04096          cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n");
04097          return ;
04098 
04099    }
04100    
04101    cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr);
04102    
04103    bc->generate_tone=0;
04104    
04105    dact.prim = DL_RELEASE | REQUEST;
04106    dact.addr = bc->addr | FLG_MSG_DOWN;
04107    dact.dinfo = 0;
04108    dact.len = 0;
04109    mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC);
04110 
04111    clear_ibuffer(bc->astbuf);
04112    
04113    bc_state_change(bc,BCHAN_RELEASE);
04114   
04115    return;
04116 }

void manager_bchannel_setup ( struct misdn_bchannel bc  ) 

void manager_clean_bc ( struct misdn_bchannel bc  ) 

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

04230 {
04231    struct misdn_stack *stack=get_stack_by_bc(bc);
04232    
04233    if (bc->channel>0)
04234       empty_chan_in_stack(stack, bc->channel);
04235    empty_bc(bc);
04236    bc->in_use=0;
04237 
04238    cb_event(EVENT_CLEANUP, bc, NULL); 
04239 }

void manager_ec_disable ( struct misdn_bchannel bc  ) 

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

04425 {
04426    struct misdn_stack *stack=get_stack_by_bc(bc);
04427    
04428    cb_log(4, stack?stack->port:0," --> ec_disable\n");
04429 
04430    if (!misdn_cap_is_speech(bc->capability)) {
04431       cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n");
04432       return;
04433    }
04434 
04435 #ifdef MISDN_1_2
04436    manager_ph_control_block(bc, PIPELINE_CFG, "", 0);
04437 #else
04438    if ( ! bc->ec_enable) {
04439       cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n");
04440       manager_ph_control(bc,  ECHOCAN_OFF, 0);
04441    }
04442 #endif
04443 }

void manager_ec_enable ( struct misdn_bchannel bc  ) 

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

04376 {
04377    struct misdn_stack *stack=get_stack_by_bc(bc);
04378    
04379    cb_log(4, stack?stack->port:0,"ec_enable\n");
04380 
04381    if (!misdn_cap_is_speech(bc->capability)) {
04382       cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n");
04383    } else {
04384 
04385 #ifdef MISDN_1_2
04386    if (*bc->pipeline) {
04387       cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline);
04388       manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1);
04389    }
04390 #else
04391    int ec_arr[2];
04392 
04393    if (bc->ec_enable) {
04394       cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps);
04395    
04396       switch (bc->ec_deftaps) {
04397       case 4:
04398       case 8:
04399       case 16:
04400       case 32:
04401       case 64:
04402       case 128:
04403       case 256:
04404       case 512:
04405       case 1024:
04406          cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps);
04407          break;
04408       default:
04409          cb_log(0, stack->port, "Taps should be power of 2\n");
04410          bc->ec_deftaps=128;
04411       }
04412    
04413       ec_arr[0]=bc->ec_deftaps;
04414       ec_arr[1]=0;
04415       
04416       manager_ph_control_block(bc,  ECHOCAN_ON,  ec_arr, sizeof(ec_arr));
04417    }
04418 #endif
04419    }
04420 }

static void manager_event_handler ( void *  arg  )  [static]

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

03776 {
03777    sem_post(&handler_started); 
03778    while (1) {
03779       struct misdn_stack *stack;
03780       msg_t *msg;
03781     
03782       /** wait for events **/
03783       sem_wait(&glob_mgr->new_msg);
03784     
03785       for (msg=msg_dequeue(&glob_mgr->activatequeue);
03786            msg;
03787            msg=msg_dequeue(&glob_mgr->activatequeue)
03788          )
03789       {
03790    
03791          iframe_t *frm =  (iframe_t*) msg->data ;
03792 
03793          switch ( frm->prim) {
03794 
03795          case MGR_CLEARSTACK | REQUEST:
03796             /*a queued bchannel cleanup*/
03797             {
03798                struct misdn_bchannel *bc;
03799                struct misdn_stack *stack=find_stack_by_port(frm->dinfo);
03800                if (!stack) {
03801                   cb_log(0,0,"no stack found with port [%d]!! so we cannot cleanup the bc\n",frm->dinfo);
03802                   free_msg(msg);
03803                   break;
03804                }
03805                
03806                bc=find_bc_by_l3id(stack,frm->addr);
03807                if (bc) {
03808                   cb_log(1,bc->port,"CLEARSTACK queued, cleaning up\n");
03809                   clean_up_bc(bc);
03810                } else {
03811                   cb_log(0,stack->port,"bc could not be cleaned correctly !! addr [%x]\n",frm->addr);
03812                }
03813             }
03814             free_msg(msg); 
03815             break;
03816          case MGR_SETSTACK | REQUEST :
03817             break;
03818          default:
03819             mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
03820             free_msg(msg);
03821          }
03822       }
03823 
03824       for (stack=glob_mgr->stack_list;
03825            stack;
03826            stack=stack->next ) { 
03827 
03828          while ( (msg=msg_dequeue(&stack->upqueue)) ) {
03829             /** Handle L2/3 Signalling after bchans **/ 
03830             if (!handle_frm_nt(msg)) {
03831                /* Maybe it's TE */
03832                if (!handle_frm(msg)) {
03833                   /* wow none! */
03834                   cb_log(0,stack->port,"Wow we've got a strange issue while dequeueing a Frame\n");
03835                }
03836             }
03837          }
03838 
03839          /* Here we should check if we really want to 
03840             send all the messages we've queued, lets 
03841             assume we've queued a Disconnect, but 
03842             received it already from the other side!*/
03843            
03844          while ( (msg=msg_dequeue(&stack->downqueue)) ) {
03845             if (stack->nt ) {
03846                if (stack->nst.manager_l3(&stack->nst, msg))
03847                   cb_log(0, stack->port, "Error@ Sending Message in NT-Stack.\n");
03848      
03849             } else {
03850                iframe_t *frm = (iframe_t *)msg->data;
03851                struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo);
03852                if (bc) send_msg(glob_mgr->midev, bc, msg);
03853                else  {
03854                   if (frm->dinfo == MISDN_ID_GLOBAL) {
03855                      struct misdn_bchannel dummybc;
03856                      make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0);
03857                      send_msg(glob_mgr->midev, &dummybc, msg);
03858                   }
03859                }
03860             }
03861          }
03862       }
03863    }
03864 }

struct misdn_bchannel * manager_find_bc_by_pid ( int  pid  ) 

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

03073 {
03074    struct misdn_stack *stack;
03075    int i;
03076   
03077    for (stack=glob_mgr->stack_list;
03078         stack;
03079         stack=stack->next) {
03080       for (i=0; i<=stack->b_num; i++)
03081          if (stack->bc[i].pid == pid) return &stack->bc[i];
03082    }
03083   
03084    return NULL;
03085 }

struct misdn_bchannel * manager_find_bc_holded ( struct misdn_bchannel bc  ) 

Definition at line 3087 of file isdn_lib.c.

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

03088 {
03089    struct misdn_stack *stack=get_stack_by_bc(bc);
03090    return find_bc_holded(stack);
03091 }

char* manager_isdn_get_info ( enum event_e  event  ) 

Definition at line 4056 of file isdn_lib.c.

References isdn_get_info(), and msgs_g.

Referenced by cb_events().

04057 {
04058    return isdn_get_info(msgs_g , event, 0);
04059 }

int manager_isdn_handler ( iframe_t *  frm,
msg_t *  msg 
)

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

03577 {  
03578 
03579    if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) {
03580       cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n");
03581    }
03582 
03583    if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) {
03584       if (handle_bchan(msg)) {
03585          return 0 ;
03586       }
03587    }  
03588 
03589 #ifdef RECV_FRM_SYSLOG_DEBUG
03590    syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo);
03591 #endif
03592 
03593    if (handle_timers(msg)) 
03594       return 0 ;
03595 
03596    
03597    if (handle_mgmt(msg)) 
03598       return 0 ; 
03599    
03600    if (handle_l2(msg)) 
03601       return 0 ;
03602 
03603    /* Its important to handle l1 AFTER l2  */
03604    if (handle_l1(msg)) 
03605       return 0 ;
03606    
03607    if (handle_frm_nt(msg)) {
03608       return 0;
03609    }
03610 
03611    if (handle_frm(msg)) {
03612       return 0;
03613    }
03614 
03615    if (handle_err(msg)) {
03616       return 0 ;
03617    }
03618 
03619    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);      
03620    free_msg(msg);
03621    
03622 
03623    return 0;
03624 }

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

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

04160 {
04161    unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)];
04162    iframe_t *ctrl = (iframe_t *)buffer; /* preload data */
04163    unsigned int *d = (unsigned int*)&ctrl->data.p;
04164    /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
04165    
04166    cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2);
04167    
04168    ctrl->prim = PH_CONTROL | REQUEST;
04169    ctrl->addr = bc->addr | FLG_MSG_DOWN;
04170    ctrl->dinfo = 0;
04171    ctrl->len = sizeof(unsigned int)*2;
04172    *d++ = c1;
04173    *d++ = c2;
04174    mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
04175 }

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

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

04211 {
04212    unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len];
04213    iframe_t *ctrl = (iframe_t *)buffer;
04214    unsigned int *d = (unsigned int *)&ctrl->data.p;
04215    /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
04216    
04217    ctrl->prim = PH_CONTROL | REQUEST;
04218    ctrl->addr = bc->addr | FLG_MSG_DOWN;
04219    ctrl->dinfo = 0;
04220    ctrl->len = sizeof(unsigned int) + c2_len;
04221    *d++ = c1;
04222    memcpy(d, c2, c2_len);
04223    mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
04224 }

int misdn_cap_is_speech ( int  cap  ) 

Poor mans version

Definition at line 410 of file isdn_lib.c.

References INFO_CAPABILITY_DIGITAL_RESTRICTED, and INFO_CAPABILITY_DIGITAL_UNRESTRICTED.

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

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

void misdn_dump_chanlist ( void   ) 

Definition at line 446 of file isdn_lib.c.

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

Referenced by misdn_show_cls().

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

int misdn_inband_avail ( struct misdn_bchannel bc  ) 

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

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

void misdn_join_conf ( struct misdn_bchannel bc,
int  conf_id 
)

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

04452 {
04453    char data[16];
04454    int len=15;
04455 
04456    bc_state_change(bc,BCHAN_BRIDGED);
04457    manager_ph_control(bc, CMX_RECEIVE_OFF, 0);
04458    manager_ph_control(bc, CMX_CONF_JOIN, conf_id);
04459 
04460    cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id);
04461 
04462    memset(data,0,15);
04463    
04464    misdn_lib_tx2misdn_frm(bc, data, len);
04465 
04466 }

void misdn_lib_bridge ( struct misdn_bchannel bc1,
struct misdn_bchannel bc2 
)

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

04479 {
04480    int conf_id=bc1->pid +1;
04481    struct misdn_bchannel *bc_list[]={
04482       bc1,bc2,NULL
04483    };
04484    struct misdn_bchannel **bc;
04485 
04486    cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port);
04487    
04488    for (bc=bc_list; *bc;  bc++) { 
04489       (*bc)->conf_id=conf_id;
04490       cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr);
04491    
04492       switch((*bc)->bc_state) {
04493          case BCHAN_ACTIVATED:
04494             misdn_join_conf(*bc,conf_id);
04495             break;
04496          default:
04497             bc_next_state_change(*bc,BCHAN_BRIDGED);
04498             break;
04499       }
04500    }
04501 }

void misdn_lib_destroy ( void   ) 

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

04024 {
04025    struct misdn_stack *help;
04026    int i;
04027   
04028    for ( help=glob_mgr->stack_list; help; help=help->next ) {
04029       for(i=0;i<=help->b_num; i++) {
04030          char buf[1024];
04031          mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
04032          help->bc[i].addr = 0;
04033       }
04034       cb_log (1, help->port, "Destroying this port.\n");
04035       stack_destroy(help);
04036    }
04037    
04038    if (global_state == MISDN_INITIALIZED) {
04039       cb_log(4, 0, "Killing Handler Thread\n");
04040       if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) {
04041          cb_log(4, 0, "Joining Handler Thread\n");
04042          pthread_join(glob_mgr->event_handler_thread, NULL);
04043       }
04044      
04045       cb_log(4, 0, "Killing Main Thread\n");
04046       if ( pthread_cancel(glob_mgr->event_thread) == 0 ) {
04047          cb_log(4, 0, "Joining Main Thread\n");
04048          pthread_join(glob_mgr->event_thread, NULL);
04049       }
04050    }
04051   
04052    cb_log(1, 0, "Closing mISDN device\n");
04053    te_lib_destroy(glob_mgr->midev);
04054 }

void misdn_lib_echo ( struct misdn_bchannel bc,
int  onoff 
)

Definition at line 4523 of file isdn_lib.c.

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

04524 {
04525    cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF");
04526    manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0);
04527 }

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

Definition at line 3115 of file isdn_lib.c.

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

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

03116 {
03117    struct misdn_stack *stack;
03118    int i;
03119    
03120    if (channel < 0 || channel > MAX_BCHANS) {
03121       cb_log(0,port,"Requested channel out of bounds (%d)\n",channel);
03122       return NULL;
03123    }
03124 
03125    for (stack=glob_mgr->stack_list; stack; stack=stack->next) {
03126     
03127       if (stack->port == port) {
03128          int maxnum;
03129          if (stack->blocked) {
03130             cb_log(0,port,"Port is blocked\n");
03131             return NULL;
03132          }
03133       
03134          if (channel > 0) {
03135             if (channel <= stack->b_num) {
03136                for (i = 0; i < stack->b_num; i++) {
03137                   if (stack->bc[i].in_use && stack->bc[i].channel == channel) {
03138                      cb_log(0,port,"Requested channel:%d on port:%d is already in use\n",channel, port);
03139                      return NULL;
03140                   }
03141                }
03142             } else {
03143                cb_log(0,port,"Requested channel:%d is out of bounds on port:%d\n",channel, port);
03144                return NULL;
03145             }
03146          }
03147 
03148          maxnum=inout&&!stack->pri&&!stack->ptp?stack->b_num+1:stack->b_num;
03149 
03150          if (dec) {
03151             for (i = maxnum-1; i>=0; i--) {
03152                if (!stack->bc[i].in_use) {
03153                   /* 3. channel on bri means CW*/
03154                   if (!stack->pri && i==stack->b_num)
03155                      stack->bc[i].cw=1;
03156                      
03157                   prepare_bc(&stack->bc[i], channel);
03158                   stack->bc[i].dec=1;
03159                   return &stack->bc[i];
03160                }
03161             }
03162          } else {
03163             for (i = 0; i <maxnum; i++) {
03164                if (!stack->bc[i].in_use) {
03165                   /* 3. channel on bri means CW*/
03166                   if (!stack->pri && i==stack->b_num)
03167                      stack->bc[i].cw=1;
03168 
03169                   prepare_bc(&stack->bc[i], channel);
03170                   return &stack->bc[i];
03171                }
03172             }
03173          }
03174 
03175          cb_log(1,port,"There is no free channel on port (%d)\n",port);
03176          return NULL;
03177       }
03178    }
03179 
03180    cb_log(0,port,"Port is not configured (%d)\n",port);
03181    return NULL;
03182 }

static int misdn_lib_get_l1_down ( struct misdn_stack stack  )  [static]

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

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

static int misdn_lib_get_l1_up ( struct misdn_stack stack  )  [static]

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

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

static int misdn_lib_get_l2_down ( struct misdn_stack stack  )  [static]

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

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

int misdn_lib_get_l2_up ( struct misdn_stack stack  ) 

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

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

int misdn_lib_get_maxchans ( int  port  ) 

Definition at line 102 of file isdn_lib.c.

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

Referenced by misdn_request().

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

int misdn_lib_get_port_down ( int  port  ) 

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

01712 { /* Pull Down L1 */ 
01713    struct misdn_stack *stack;
01714    for (stack=glob_mgr->stack_list;
01715         stack;
01716         stack=stack->next) {
01717       if (stack->port == port) {
01718             if (stack->l2link)
01719                misdn_lib_get_l2_down(stack);
01720             misdn_lib_get_l1_down(stack);
01721          return 0;
01722       }
01723    }
01724    return 0;
01725 }

int misdn_lib_get_port_info ( int  port  ) 

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

03630 {
03631    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03632    iframe_t *frm;
03633    struct misdn_stack *stack=find_stack_by_port(port);
03634    if (!msg) {
03635       cb_log(0, port, "misgn_lib_get_port: alloc_msg failed!\n");
03636       return -1;
03637    }
03638    frm=(iframe_t*)msg->data;
03639    if (!stack ) {
03640       cb_log(0, port, "There is no Stack for this port.\n");
03641       return -1;
03642    }
03643    /* activate bchannel */
03644    frm->prim = CC_STATUS_ENQUIRY | REQUEST;
03645 
03646    frm->addr = stack->upper_id| FLG_MSG_DOWN;
03647 
03648    frm->dinfo = 0;
03649    frm->len = 0;
03650   
03651    msg_queue_tail(&glob_mgr->activatequeue, msg);
03652    sem_post(&glob_mgr->new_msg);
03653 
03654   
03655    return 0; 
03656 }

int misdn_lib_get_port_up ( int  port  ) 

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

01690 { /* Pull Up L1 */ 
01691    struct misdn_stack *stack;
01692    
01693    for (stack=glob_mgr->stack_list;
01694         stack;
01695         stack=stack->next) {
01696       
01697       if (stack->port == port) {
01698 
01699          if (!stack->l1link)
01700             misdn_lib_get_l1_up(stack);
01701          if (!stack->l2link)
01702             misdn_lib_get_l2_up(stack);
01703          
01704          return 0;
01705       }
01706    }
01707    return 0;
01708 }

static int misdn_lib_get_short_status ( struct misdn_stack stack  )  [static]

Definition at line 859 of file isdn_lib.c.

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

Referenced by misdn_lib_isdn_l1watcher().

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

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

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

03916 {
03917    struct misdn_lib *mgr=calloc(1, sizeof(struct misdn_lib));
03918    char *tok, *tokb;
03919    char plist[1024];
03920    int midev;
03921    int port_count=0;
03922  
03923    cb_log = iface->cb_log;
03924    cb_event = iface->cb_event;
03925    cb_jb_empty = iface->cb_jb_empty;
03926    
03927    glob_mgr = mgr;
03928   
03929    msg_init();
03930 
03931    misdn_lib_nt_debug_init(0,NULL);
03932    
03933    if (!portlist || (*portlist == 0) ) return 1;
03934    
03935    init_flip_bits();
03936    
03937    {
03938       strncpy(plist,portlist, 1024);
03939       plist[1023] = 0;
03940    }
03941   
03942    memcpy(tone_425_flip,tone_425,TONE_425_SIZE);
03943    flip_buf_bits(tone_425_flip,TONE_425_SIZE);
03944 
03945    memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE);
03946    flip_buf_bits(tone_silence_flip,TONE_SILENCE_SIZE);
03947   
03948    midev=te_lib_init();
03949    mgr->midev=midev;
03950 
03951    port_count=mISDN_get_stack_count(midev);
03952   
03953    msg_queue_init(&mgr->activatequeue);
03954   
03955    if (sem_init(&mgr->new_msg, 1, 0)<0)
03956       sem_init(&mgr->new_msg, 0, 0);
03957  
03958    for (tok=strtok_r(plist," ,",&tokb );
03959         tok; 
03960         tok=strtok_r(NULL," ,",&tokb)) {
03961       int port = atoi(tok);
03962       struct misdn_stack *stack;
03963       static int first=1;
03964       int ptp=0;
03965     
03966       if (strstr(tok, "ptp"))
03967          ptp=1;
03968 
03969       if (port > port_count) {
03970          cb_log(0, port, "Couldn't Initialize this port since we have only %d ports\n", port_count);
03971          exit(1);
03972       }
03973       stack=stack_init(midev, port, ptp);
03974     
03975       if (!stack) {
03976          perror("init_stack");
03977          exit(1);
03978       }
03979     
03980       {
03981          int i;
03982          for(i=0;i<=stack->b_num; i++) {
03983             int r;
03984             if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) {
03985                cb_log(0, port, "Got Err @ init_bc :%d\n",r);
03986                exit(1);
03987             }
03988          }
03989       }
03990 
03991       if (stack && first) {
03992          mgr->stack_list=stack;
03993          first=0;
03994          continue;
03995       }
03996     
03997       if (stack) {
03998          struct misdn_stack * help;
03999          for ( help=mgr->stack_list; help; help=help->next ) 
04000             if (help->next == NULL) break;
04001          help->next=stack;
04002       }
04003     
04004    }
04005   
04006    if (sem_init(&handler_started, 1, 0)<0)
04007       sem_init(&handler_started, 0, 0);
04008   
04009    cb_log(8, 0, "Starting Event Handler\n");
04010    pthread_create( &mgr->event_handler_thread, NULL,(void*)manager_event_handler, mgr);
04011   
04012    sem_wait(&handler_started) ;
04013    cb_log(8, 0, "Starting Event Catcher\n");
04014    pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr);
04015   
04016    cb_log(8, 0, "Event Catcher started\n");
04017 
04018    global_state= MISDN_INITIALIZED; 
04019   
04020    return (mgr == NULL);
04021 }

int misdn_lib_is_port_blocked ( int  port  ) 

Definition at line 82 of file isdn_lib.c.

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

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

int misdn_lib_is_ptp ( int  port  ) 

Definition at line 93 of file isdn_lib.c.

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

Referenced by do_immediate_setup().

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

static void misdn_lib_isdn_event_catcher ( void *  arg  )  [static]

Definition at line 2978 of file isdn_lib.c.

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

02979 {
02980    struct misdn_lib *mgr = arg;
02981    int zero_frm=0 , fff_frm=0 ;
02982    int midev= mgr->midev;
02983    int port=0;
02984    
02985    while (1) {
02986       msg_t *msg = fetch_msg(midev); 
02987       iframe_t *frm;
02988       
02989       
02990       if (!msg) continue;
02991       
02992       frm = (iframe_t*) msg->data;
02993       
02994       /** When we make a call from NT2Ast we get this frames **/
02995       if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) {
02996          zero_frm++; 
02997          free_msg(msg);
02998          continue;
02999       } else {
03000          if (zero_frm) {
03001             cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm);
03002             zero_frm = 0 ;
03003          }
03004       }
03005       
03006       /** I get this sometimes after setup_bc **/
03007       if (frm->len == 0 &&  frm->dinfo == 0 && frm->prim == 0xffffffff ) {
03008          fff_frm++; 
03009          free_msg(msg);
03010          continue;
03011       } else {
03012          if (fff_frm) {
03013             cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm);
03014             fff_frm = 0 ;
03015          }
03016       }
03017       
03018       manager_isdn_handler(frm, msg);
03019    }
03020 
03021 }

void misdn_lib_isdn_l1watcher ( int  port  ) 

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

02961 {
02962    struct misdn_stack *stack;
02963 
02964    for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next)
02965       ;
02966 
02967    if (stack) {
02968       cb_log(4, port, "Checking L1 State\n");   
02969       if (!stack->l1link) {
02970          cb_log(4, port, "L1 State Down, trying to get it up again\n"); 
02971          misdn_lib_get_short_status(stack);
02972          misdn_lib_get_l1_up(stack); 
02973          misdn_lib_get_l2_up(stack); 
02974       }
02975    }
02976 }

void misdn_lib_log_ies ( struct misdn_bchannel bc  ) 

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

03204 {
03205    struct misdn_stack *stack;
03206    if (!bc) return;
03207 
03208    stack=get_stack_by_bc(bc);
03209 
03210    if (!stack) return;
03211 
03212    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);
03213    
03214    cb_log(2, stack->port,
03215           " --> info_dad:%s onumplan:%c dnumplan:%c rnumplan:%c cpnnumplan:%c\n",
03216           bc->info_dad,
03217           bc->onumplan>=0?'0'+bc->onumplan:' ',
03218           bc->dnumplan>=0?'0'+bc->dnumplan:' ',
03219           bc->rnumplan>=0?'0'+bc->rnumplan:' ',
03220           bc->cpnnumplan>=0?'0'+bc->cpnnumplan:' '
03221       );
03222    
03223    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);
03224    cb_log(4, stack->port, " --> screen:%d --> pres:%d\n",
03225          bc->screen, bc->pres);
03226    
03227    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);
03228    
03229    cb_log(4, stack->port, " --> facility:%s out_facility:%s\n",fac2str(bc->fac_in.Function),fac2str(bc->fac_out.Function));
03230 
03231    cb_log(5, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1);
03232    
03233    cb_log(5, stack->port, " --> bc:%x h:%d sh:%d\n", bc, bc->holded, bc->stack_holder);
03234 }

int misdn_lib_maxports_get ( void   ) 

Definition at line 3867 of file isdn_lib.c.

Referenced by load_module().

03867                              { /** BE AWARE WE HAVE NO CB_LOG HERE! **/
03868    
03869    int i = mISDN_open();
03870    int max=0;
03871    
03872    if (i<0)
03873       return -1;
03874 
03875    max = mISDN_get_stack_count(i);
03876    
03877    mISDN_close(i);
03878    
03879    return max;
03880 }

void misdn_lib_nt_debug_init ( int  flags,
char *  file 
)

Definition at line 3895 of file isdn_lib.c.

References f.

Referenced by load_module(), and misdn_lib_init().

03896 {
03897    int static init=0;
03898    char *f;
03899    
03900    if (!flags) 
03901       f=NULL;
03902    else
03903       f=file;
03904 
03905    if (!init) {
03906       debug_init( flags , f, f, f);
03907       init=1;
03908    } else {
03909       debug_close();
03910       debug_init( flags , f, f, f);
03911    }
03912 }

void misdn_lib_nt_keepcalls ( int  kc  ) 

Definition at line 3883 of file isdn_lib.c.

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

Referenced by load_module().

03884 {
03885 #ifdef FEATURE_NET_KEEPCALLS
03886    if (kc) {
03887       struct misdn_stack *stack=get_misdn_stack();
03888       for ( ; stack; stack=stack->next) {
03889          stack->nst.feature |= FEATURE_NET_KEEPCALLS;
03890       }
03891    }
03892 #endif
03893 }

int misdn_lib_pid_restart ( int  pid  ) 

Definition at line 3684 of file isdn_lib.c.

References manager_clean_bc(), and manager_find_bc_by_pid().

Referenced by misdn_restart_pid().

03685 {
03686    struct misdn_bchannel *bc=manager_find_bc_by_pid(pid);
03687 
03688    if (bc) {
03689       manager_clean_bc(bc);
03690    }
03691    return 0;
03692 }

int misdn_lib_port_block ( int  port  ) 

Definition at line 56 of file isdn_lib.c.

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

Referenced by cb_events(), and misdn_port_block().

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

int misdn_lib_port_is_pri ( int  port  ) 

Definition at line 34 of file isdn_lib.c.

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

Referenced by misdn_new(), and update_name().

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

int misdn_lib_port_restart ( int  port  ) 

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

03734 {
03735    struct misdn_stack *stack=find_stack_by_port(port);
03736  
03737    cb_log(0, port, "Restarting this port.\n");
03738    if (stack) {
03739       cb_log(0, port, "Stack:%p\n",stack);
03740          
03741       clear_l3(stack);
03742       {
03743          msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03744          iframe_t *frm;
03745 
03746          if (!msg) {
03747             cb_log(0, port, "port_restart: alloc_msg failed\n");
03748             return -1;
03749          }
03750          
03751          frm=(iframe_t*)msg->data;
03752          /* we must activate if we are deactivated */
03753          /* activate bchannel */
03754          frm->prim = DL_RELEASE | REQUEST;
03755          frm->addr = stack->upper_id | FLG_MSG_DOWN;
03756 
03757          frm->dinfo = 0;
03758          frm->len = 0;
03759          msg_queue_tail(&glob_mgr->activatequeue, msg);
03760          sem_post(&glob_mgr->new_msg);
03761       }
03762 
03763       if (stack->nt)
03764          misdn_lib_reinit_nt_stack(stack->port);
03765     
03766    }
03767 
03768    return 0;
03769 }

int misdn_lib_port_unblock ( int  port  ) 

Definition at line 69 of file isdn_lib.c.

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

Referenced by misdn_port_unblock().

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

int misdn_lib_port_up ( int  port,
int  check 
)

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

01728 {
01729    struct misdn_stack *stack;
01730 
01731 
01732    for (stack=glob_mgr->stack_list;
01733         stack;
01734         stack=stack->next) {
01735       
01736       if (stack->port == port) {
01737 
01738          if (stack->blocked) {
01739             cb_log(0,port, "Port Blocked:%d L2:%d L1:%d\n", stack->blocked, stack->l2link, stack->l1link);
01740             return -1;
01741          }
01742 
01743          if (stack->ptp ) {
01744 
01745             if (stack->l1link && stack->l2link) {
01746                return 1;
01747             } else {
01748                cb_log(1,port, "Port Down L2:%d L1:%d\n",
01749                   stack->l2link, stack->l1link);
01750                return 0;
01751             }
01752          } else {
01753             if ( !check || stack->l1link )
01754                return 1;
01755             else {
01756                cb_log(1,port, "Port down PMP\n");
01757                return 0;
01758             }
01759          }
01760       }
01761    }
01762   
01763    return -1;
01764 }

void misdn_lib_reinit_nt_stack ( int  port  ) 

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

04532 {
04533    struct misdn_stack *stack=find_stack_by_port(port);
04534    
04535    if (stack) {
04536       stack->l2link=0;
04537       stack->blocked=0;
04538    
04539       cleanup_Isdnl3(&stack->nst);
04540       cleanup_Isdnl2(&stack->nst);
04541 
04542 
04543       memset(&stack->nst, 0, sizeof(net_stack_t));
04544       memset(&stack->mgr, 0, sizeof(manager_t));
04545    
04546       stack->mgr.nst = &stack->nst;
04547       stack->nst.manager = &stack->mgr;
04548     
04549       stack->nst.l3_manager = handle_event_nt;
04550       stack->nst.device = glob_mgr->midev;
04551       stack->nst.cardnr = port;
04552       stack->nst.d_stid = stack->d_stid;
04553    
04554       stack->nst.feature = FEATURE_NET_HOLD;
04555       if (stack->ptp)
04556          stack->nst.feature |= FEATURE_NET_PTP;
04557       if (stack->pri)
04558          stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
04559       
04560       stack->nst.l1_id = stack->lower_id;
04561       stack->nst.l2_id = stack->upper_id;
04562       
04563       msg_queue_init(&stack->nst.down_queue);
04564    
04565       Isdnl2Init(&stack->nst);
04566       Isdnl3Init(&stack->nst);
04567 
04568       if (!stack->ptp)
04569          misdn_lib_get_l1_up(stack);
04570       misdn_lib_get_l2_up(stack);
04571    }
04572 }

void misdn_lib_release ( struct misdn_bchannel bc  ) 

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

01670 {
01671    struct misdn_stack *stack=get_stack_by_bc(bc);
01672 
01673    if (!stack) {
01674       cb_log(1,0,"misdn_release: No Stack found\n");
01675       return;
01676    }
01677    
01678    if (bc->channel>0) 
01679       empty_chan_in_stack(stack,bc->channel);
01680    
01681    empty_bc(bc);
01682    clean_up_bc(bc);
01683    bc->in_use=0;
01684 }

int misdn_lib_send_event ( struct misdn_bchannel bc,
enum event_e  event 
)

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

03256 {
03257    msg_t *msg; 
03258    struct misdn_stack *stack;
03259    int retval=0;
03260   
03261    if (!bc) RETURN(-1,OUT_POST_UNLOCK);
03262    
03263    stack=get_stack_by_bc(bc);
03264    
03265    if (!stack) {
03266       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);
03267       RETURN(-1,OUT);
03268    }
03269    
03270    misdn_send_lock(bc);
03271 
03272 
03273    cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->uperid:%x\n",stack->nt, stack->upper_id);
03274 
03275    if ( stack->nt && !stack->l1link) {
03276       /** Queue Event **/
03277       bc->evq=event;
03278       cb_log(1, stack->port, "Queueing Event %s because L1 is down (btw. Activating L1)\n", isdn_get_info(msgs_g, event, 0));
03279       misdn_lib_get_l1_up(stack);
03280       RETURN(0,OUT);
03281    }
03282    
03283    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);
03284    cb_log(4, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state));
03285    misdn_lib_log_ies(bc);
03286    
03287    switch (event) {
03288    case EVENT_SETUP:
03289       if (create_process(glob_mgr->midev, bc)<0) {
03290          cb_log(0,  stack->port, " No free channel at the moment @ send_event\n");
03291 
03292          RETURN(-ENOCHAN,OUT);
03293       }
03294       break;
03295 
03296    case EVENT_PROGRESS:
03297    case EVENT_ALERTING:
03298    case EVENT_PROCEEDING:
03299    case EVENT_SETUP_ACKNOWLEDGE:
03300    case EVENT_CONNECT:
03301       if (!stack->nt) break;
03302 
03303    case EVENT_RETRIEVE_ACKNOWLEDGE:
03304 
03305       if (stack->nt) {
03306          if (bc->channel <=0 ) { /*  else we have the channel already */
03307             if (find_free_chan_in_stack(stack, bc, 0, 0)<0) {
03308                cb_log(0, stack->port, " No free channel at the moment\n");
03309                /*FIXME: add disconnect*/
03310                RETURN(-ENOCHAN,OUT);
03311             }
03312          }
03313          /* Its that i generate channels */
03314       }
03315 
03316       retval=setup_bc(bc);
03317       if (retval == -EINVAL) {
03318          cb_log(0,bc->port,"send_event: setup_bc failed\n");
03319       }
03320 
03321       if (misdn_cap_is_speech(bc->capability)) {
03322          if ((event==EVENT_CONNECT)||(event==EVENT_RETRIEVE_ACKNOWLEDGE)) {
03323             if ( *bc->crypt_key ) {
03324                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);
03325                
03326                manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
03327             }
03328             
03329             if (!bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0);
03330             manager_ec_enable(bc);
03331             
03332             if (bc->txgain != 0) {
03333                cb_log(4, stack->port,  "--> Changing txgain to %d\n", bc->txgain);
03334                manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
03335             }
03336             
03337             if ( bc->rxgain != 0 ) {
03338                cb_log(4, stack->port,  "--> Changing rxgain to %d\n", bc->rxgain);
03339                manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
03340             }
03341          }
03342       }
03343       break;
03344 
03345    case EVENT_HOLD_ACKNOWLEDGE:
03346    {
03347       struct misdn_bchannel *holded_bc=malloc(sizeof(struct misdn_bchannel));
03348       if (!holded_bc) {
03349          cb_log(0,bc->port, "Could not allocate holded_bc!!!\n");
03350          RETURN(-1,OUT);
03351       }
03352 
03353       /*backup the bc*/
03354       memcpy(holded_bc,bc,sizeof(struct misdn_bchannel));
03355       holded_bc->holded=1;
03356       bc_state_change(holded_bc,BCHAN_CLEANED);
03357 
03358       stack_holder_add(stack,holded_bc);
03359    
03360       /*kill the bridge and clean the bchannel*/
03361       if (stack->nt) {
03362          int channel;
03363          if (bc->bc_state == BCHAN_BRIDGED) {
03364             struct misdn_bchannel *bc2;
03365             misdn_split_conf(bc,bc->conf_id);
03366             bc2=find_bc_by_confid(bc->conf_id);
03367             if (!bc2) {
03368                cb_log(0,bc->port,"We have no second bc in bridge???\n");
03369             } else {
03370                misdn_split_conf(bc2,bc->conf_id);
03371             }
03372          }
03373          
03374          channel=bc->channel;
03375 
03376          empty_bc(bc);
03377          clean_up_bc(bc);
03378 
03379          if (channel>0)
03380             empty_chan_in_stack(stack,channel);
03381 
03382          bc->in_use=0;  
03383       }
03384       
03385    }
03386    break;
03387 
03388    /* finishing the channel eh ? */
03389    case EVENT_DISCONNECT:
03390       if (!bc->need_disconnect) {
03391          cb_log(0,bc->port," --> we have already send Disconnect\n");
03392          RETURN(-1,OUT);
03393       }
03394       
03395       bc->need_disconnect=0;
03396       break;
03397    case EVENT_RELEASE:
03398       if (!bc->need_release) {
03399          cb_log(0,bc->port," --> we have already send Release\n");
03400          RETURN(-1,OUT);
03401       }
03402       bc->need_disconnect=0;
03403       bc->need_release=0;
03404       break;
03405    case EVENT_RELEASE_COMPLETE:
03406       if (!bc->need_release_complete) {
03407          cb_log(0,bc->port," --> we have already send Release_complete\n");
03408          RETURN(-1,OUT);
03409       }
03410       bc->need_disconnect=0;
03411       bc->need_release=0;
03412       bc->need_release_complete=0;
03413 
03414       if (!stack->nt) {
03415          /*create clenaup in TE*/
03416          int channel=bc->channel;
03417 
03418          int tmpcause=bc->cause; 
03419          int tmp_out_cause=bc->out_cause; 
03420          empty_bc(bc);
03421          bc->cause=tmpcause;
03422          bc->out_cause=tmp_out_cause;
03423          clean_up_bc(bc);
03424          
03425          if (channel>0)
03426             empty_chan_in_stack(stack,channel);
03427          
03428          bc->in_use=0;
03429       }
03430       break;
03431     
03432    case EVENT_CONNECT_ACKNOWLEDGE:
03433 
03434       if ( bc->nt || misdn_cap_is_speech(bc->capability)) {
03435          int retval=setup_bc(bc);
03436          if (retval == -EINVAL){
03437             cb_log(0,bc->port,"send_event: setup_bc failed\n");
03438             
03439          }
03440       }
03441       
03442       if (misdn_cap_is_speech(bc->capability)) {
03443          if (  !bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0);
03444          manager_ec_enable(bc);
03445 
03446          if ( bc->txgain != 0 ) {
03447             cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain);
03448             manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
03449          }
03450          if ( bc->rxgain != 0 ) {
03451             cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain);
03452             manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
03453          }
03454       }
03455       break;
03456     
03457    default:
03458       break;
03459    }
03460   
03461    /* Later we should think about sending bchannel data directly to misdn. */
03462    msg = isdn_msg_build_event(msgs_g, bc, event, stack->nt);
03463    msg_queue_tail(&stack->downqueue, msg);
03464    sem_post(&glob_mgr->new_msg);
03465   
03466 OUT:
03467    misdn_send_unlock(bc);
03468 
03469 OUT_POST_UNLOCK:
03470    return retval; 
03471 }

int misdn_lib_send_restart ( int  port,
int  channel 
)

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

03696 {
03697    struct misdn_bchannel dummybc;
03698    struct misdn_stack *stack=find_stack_by_port(port);
03699    cb_log(0, port, "Sending Restarts on this port.\n");
03700    
03701    make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0);
03702 
03703    /*default is all channels*/
03704    if (channel <0) {
03705       dummybc.channel=-1;
03706       cb_log(0, port, "Restarting and all Interfaces\n");
03707       misdn_lib_send_event(&dummybc, EVENT_RESTART);
03708 
03709       return 0;
03710    }
03711 
03712    /*if a channel is specified we restart only this one*/
03713    if (channel >0) {
03714       int cnt;
03715       dummybc.channel=channel;
03716       cb_log(0, port, "Restarting and cleaning channel %d\n",channel);
03717       misdn_lib_send_event(&dummybc, EVENT_RESTART);
03718       /* clean up chan in stack, to be sure we don't think it's
03719        * in use anymore */
03720       for (cnt=0; cnt<=stack->b_num; cnt++) {
03721          if (stack->bc[cnt].channel == channel) {
03722             empty_bc(&stack->bc[cnt]);
03723             clean_up_bc(&stack->bc[cnt]);
03724             stack->bc[cnt].in_use=0;
03725          }
03726       }
03727    }
03728 
03729    return 0;
03730 }

void misdn_lib_send_tone ( struct misdn_bchannel bc,
enum tone_e  tone 
)

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

04341 {
04342    char buf[mISDN_HEADER_LEN+128];
04343    iframe_t *frm;
04344 
04345    switch(tone) {
04346    case TONE_DIAL:
04347       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE); 
04348    break;
04349    
04350    case TONE_ALERTING:
04351       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_RINGING);  
04352    break;
04353    
04354    case TONE_HANGUP:
04355       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_HANGUP);   
04356    break;
04357 
04358    case TONE_NONE:
04359    default:
04360       manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP);  
04361    }
04362 
04363    frm=(iframe_t*)buf;
04364    memset(buf,0,mISDN_HEADER_LEN+128);
04365 
04366    frm->prim=DL_DATA|REQUEST;
04367    frm->addr=bc->addr|FLG_MSG_DOWN;
04368    frm->dinfo=0;
04369    frm->len=128;
04370    
04371    mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
04372 }

void misdn_lib_setup_bc ( struct misdn_bchannel bc  ) 

Definition at line 942 of file isdn_lib.c.

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

00943 {
00944    clean_up_bc(bc);
00945    setup_bc(bc);
00946 }

void misdn_lib_split_bridge ( struct misdn_bchannel bc1,
struct misdn_bchannel bc2 
)

Definition at line 4503 of file isdn_lib.c.

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

Referenced by misdn_bridge().

04504 {
04505 
04506    struct misdn_bchannel *bc_list[]={
04507       bc1,bc2,NULL
04508    };
04509    struct misdn_bchannel **bc;
04510       
04511    for (bc=bc_list; *bc;  bc++) { 
04512       if ( (*bc)->bc_state == BCHAN_BRIDGED){
04513          misdn_split_conf( *bc, (*bc)->conf_id);
04514       } else {
04515          cb_log( 2, (*bc)->port, "BC not bridged (state:%s) so not splitting it\n",bc_state2str((*bc)->bc_state));
04516       }
04517    }
04518    
04519 }

void misdn_lib_tone_generator_start ( struct misdn_bchannel bc  ) 

Definition at line 2171 of file isdn_lib.c.

References misdn_bchannel::generate_tone.

Referenced by misdn_write().

02172 {
02173    bc->generate_tone=1;
02174 }

void misdn_lib_tone_generator_stop ( struct misdn_bchannel bc  ) 

Definition at line 2176 of file isdn_lib.c.

References misdn_bchannel::generate_tone.

Referenced by start_bc_tones(), and stop_indicate().

02177 {
02178    bc->generate_tone=0;
02179 }

void misdn_lib_transfer ( struct misdn_bchannel holded_bc  ) 

Definition at line 3067 of file isdn_lib.c.

References misdn_bchannel::holded.

03068 {
03069    holded_bc->holded=0;
03070 }

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

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

04120 {
04121    char buf[4096 + mISDN_HEADER_LEN];
04122    iframe_t *frm;
04123    int  r;
04124    struct misdn_stack *stack=get_stack_by_bc(bc);
04125 
04126    switch (bc->bc_state) {
04127       case BCHAN_ACTIVATED:
04128       case BCHAN_BRIDGED:
04129          break;
04130       default:
04131          cb_log(3, bc->port, "BC not yet activated (state:%s)\n",bc_state2str(bc->bc_state));
04132          return -1;
04133    }
04134    
04135    frm= (iframe_t*)buf;
04136    
04137    frm->prim = DL_DATA|REQUEST;
04138    frm->dinfo = 0;
04139    frm->addr = bc->addr | FLG_MSG_DOWN ;
04140    
04141    frm->len = len;
04142    memcpy(&buf[mISDN_HEADER_LEN], data,len);
04143       
04144    if ( misdn_cap_is_speech(bc->capability) ) 
04145       flip_buf_bits( &buf[mISDN_HEADER_LEN], len);
04146    else
04147       cb_log(6, stack->port, "Writing %d data bytes\n",len);
04148    
04149    cb_log(9, stack->port, "Writing %d bytes 2 mISDN\n",len);
04150    r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT);
04151    return 0;
04152 }

void misdn_send_lock ( struct misdn_bchannel bc  ) 

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

03242 {
03243    //cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid);
03244    if (bc->send_lock)
03245       pthread_mutex_lock(&bc->send_lock->lock);
03246 }

void misdn_send_unlock ( struct misdn_bchannel bc  ) 

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

03249 {
03250    //cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid);
03251    if (bc->send_lock)
03252       pthread_mutex_unlock(&bc->send_lock->lock);
03253 }

void misdn_split_conf ( struct misdn_bchannel bc,
int  conf_id 
)

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

04470 {
04471    bc_state_change(bc,BCHAN_ACTIVATED);
04472    manager_ph_control(bc, CMX_RECEIVE_ON, 0);
04473    manager_ph_control(bc, CMX_CONF_SPLIT, conf_id);
04474 
04475    cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id);
04476 }

void misdn_tx_jitter ( struct misdn_bchannel bc,
int  len 
)

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

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

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

Definition at line 3095 of file isdn_lib.c.

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

Referenced by misdn_lib_get_free_bc().

03096 {
03097    bc->channel = channel;
03098    bc->channel_preselected = channel?1:0;
03099    bc->in_use = 1;
03100    bc->need_disconnect=1;
03101    bc->need_release=1;
03102    bc->need_release_complete=1;
03103    bc->cause=16;
03104 
03105    if (++mypid>5000) mypid=1;
03106    bc->pid=mypid;
03107 
03108 #if 0
03109    bc->addr=0;
03110    bc->b_stid=0;
03111    bc->layer_id=0;
03112 #endif
03113 }

int queue_cleanup_bc ( struct misdn_bchannel bc  ) 

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

03660 {
03661    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03662    iframe_t *frm;
03663    if (!msg) {
03664       cb_log(0, bc->port, "misgn_lib_get_port: alloc_msg failed!\n");
03665       return -1;
03666    }
03667    frm=(iframe_t*)msg->data;
03668 
03669    /* activate bchannel */
03670    frm->prim = MGR_CLEARSTACK| REQUEST;
03671 
03672    frm->addr = bc->l3_id;
03673 
03674    frm->dinfo = bc->port;
03675    frm->len = 0;
03676   
03677    msg_queue_tail(&glob_mgr->activatequeue, msg);
03678    sem_post(&glob_mgr->new_msg);
03679 
03680    return 0; 
03681 
03682 }

int release_cr ( struct misdn_stack stack,
mISDNuser_head_t *  hh 
)

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

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

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

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

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

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

Definition at line 455 of file isdn_lib.c.

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

Referenced by handle_frm().

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

int setup_bc ( struct misdn_bchannel bc  ) 

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

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

void stack_destroy ( struct misdn_stack stack  ) 

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

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

void stack_holder_add ( struct misdn_stack stack,
struct misdn_bchannel holder 
)

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

04243 {
04244    struct misdn_bchannel *help;
04245    cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id);
04246    
04247    holder->stack_holder=1;
04248 
04249    if (!stack ) return ;
04250    
04251    holder->next=NULL;
04252    
04253    if (!stack->holding) {
04254       stack->holding = holder;
04255       return;
04256    }
04257   
04258    for (help=stack->holding;
04259         help;
04260         help=help->next) {
04261       if (!help->next) {
04262          help->next=holder;
04263          break;
04264       }
04265    }
04266   
04267 }

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

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

04318 {
04319    struct misdn_bchannel *help;
04320 
04321    cb_log(4,stack?stack->port:0, "*HOLDER: find %x\n",l3id);
04322    
04323    if (!stack) return NULL;
04324    
04325    for (help=stack->holding;
04326         help;
04327         help=help->next) {
04328       if (help->l3_id == l3id) {
04329          cb_log(4,stack->port, "*HOLDER: found bc\n");
04330          return help;
04331       }
04332    }
04333 
04334    cb_log(4,stack->port, "*HOLDER: find nothing\n");
04335    return NULL;
04336 }

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

Definition at line 4295 of file isdn_lib.c.

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

04296 {
04297    struct misdn_bchannel *help;
04298 
04299    cb_log(4,stack?stack->port:0, "*HOLDER: find_bychan %c\n", chan);
04300    
04301    if (!stack) return NULL;
04302    
04303    for (help=stack->holding;
04304         help;
04305         help=help->next) {
04306       if (help->channel == chan) {
04307          cb_log(4,stack->port, "*HOLDER: found_bychan bc\n");
04308          return help;
04309       }
04310    }
04311 
04312    cb_log(4,stack->port, "*HOLDER: find_bychan nothing\n");
04313    return NULL;
04314 
04315 }

void stack_holder_remove ( struct misdn_stack stack,
struct misdn_bchannel holder 
)

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

04270 {
04271    struct misdn_bchannel *h1;
04272 
04273    if (!holder->stack_holder) return;
04274    
04275    holder->stack_holder=0;
04276    
04277    cb_log(4,stack->port, "*HOLDER: remove %x\n",holder->l3_id);
04278    if (!stack || ! stack->holding) return;
04279   
04280    if (holder == stack->holding) {
04281       stack->holding = stack->holding->next;
04282       return;
04283    }
04284    
04285    for (h1=stack->holding;
04286         h1;
04287         h1=h1->next) {
04288       if (h1->next == holder) {
04289          h1->next=h1->next->next;
04290          return ;
04291       }
04292    }
04293 }

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

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

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

void te_lib_destroy ( int  midev  ) 

Definition at line 3055 of file isdn_lib.c.

References cb_log, and entity.

Referenced by misdn_lib_destroy().

03056 {
03057    char buf[1024];
03058    mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC);
03059 
03060    cb_log(4, 0, "Entetity deleted\n");
03061    mISDN_close(midev);
03062    cb_log(4, 0, "midev closed\n");
03063 }

int te_lib_init (  ) 

App Interface

Definition at line 3026 of file isdn_lib.c.

References entity, errno, and misdn_lib::midev.

Referenced by misdn_lib_init().

03026                   {
03027    char buff[1025];
03028    iframe_t *frm=(iframe_t*)buff;
03029    int midev=mISDN_open();
03030    int ret;
03031 
03032    memset(buff,0,1025);
03033   
03034    if  (midev<=0) return midev;
03035   
03036 /* create entity for layer 3 TE-mode */
03037    mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
03038    ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC);
03039   
03040    if (ret < mISDN_HEADER_LEN) {
03041    noentity:
03042       fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n",strerror(errno));
03043       exit(-1);
03044    }
03045   
03046    entity = frm->dinfo & 0xffff ;
03047   
03048    if (!entity)
03049       goto noentity;
03050 
03051    return midev;
03052   
03053 }


Variable Documentation

int entity [static]

Definition at line 226 of file isdn_lib.c.

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

char flip_table[256] [static]

Definition at line 291 of file isdn_lib.c.

Referenced by flip_buf_bits(), and init_flip_bits().

struct misdn_lib* glob_mgr [static]

Definition at line 228 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 159 of file isdn_lib.c.

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

sem_t handler_started

Definition at line 3773 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 407 of file isdn_lib.c.

Referenced by prepare_bc().

int newteid = 0 [static]

Definition at line 760 of file isdn_lib.c.

int nt_err_cnt = 0 [static]

Definition at line 152 of file isdn_lib.c.

Referenced by handle_frm_nt().

char tone_425_flip[TONE_425_SIZE]

Definition at line 230 of file isdn_lib.c.

Referenced by misdn_lib_init().

char tone_silence_flip[TONE_SILENCE_SIZE]

Definition at line 231 of file isdn_lib.c.

Referenced by misdn_lib_init(), and misdn_tx_jitter().


Generated on Mon Mar 31 07:41:08 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.1