Tue Sep 30 01:19:58 2008

Asterisk developer's documentation


isdn_lib.c File Reference

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

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)
struct misdn_bchannelfind_bc_by_confid (unsigned long confid)
struct 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)
struct misdn_stackget_misdn_stack (void)
void get_show_stack_details (int port, char *buf)
struct 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)
struct misdn_bchannelmanager_find_bc_by_pid (int pid)
struct 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)
struct 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)
struct misdn_bchannelstack_holder_find (struct misdn_stack *stack, unsigned long l3id)
struct misdn_bchannelstack_holder_find_bychan (struct misdn_stack *stack, int chan)
void stack_holder_remove (struct misdn_stack *stack, struct misdn_bchannel *holder)
struct misdn_stackstack_init (int midev, int port, int ptp)
void te_lib_destroy (int midev)
int te_lib_init (void)
static int test_inuse (struct misdn_bchannel *bc)

Variables

static int entity
static char flip_table [256]
static struct misdn_libglob_mgr
static enum global_states global_state = MISDN_INITIALIZING
sem_t handler_started
struct isdn_msg msgs_g []
static int mypid = 1
static int newteid = 0
static int nt_err_cnt = 0
char tone_425_flip [TONE_425_SIZE]
char tone_silence_flip [TONE_SILENCE_SIZE]


Define Documentation

#define ECHOCAN_OFF   124

Definition at line 192 of file isdn_lib.c.

Referenced by manager_ec_disable().

#define ECHOCAN_ON   123

Definition at line 191 of file isdn_lib.c.

Referenced by manager_ec_enable().

#define ISDN_PID_L3_B_USER   0x430000ff

Definition at line 214 of file isdn_lib.c.

Referenced by setup_bc().

#define ISDN_PID_L4_B_USER   0x440000ff

Definition at line 215 of file isdn_lib.c.

Referenced by setup_bc().

#define MAXPROCS   0x100

Definition at line 765 of file isdn_lib.c.

Referenced by create_process().

#define MISDN_DEBUG   0

Definition at line 195 of file isdn_lib.c.

#define MISDN_DSP

#define MISDN_GEN_SILENCE

#define MISDN_IBUF_SIZE   512

Definition at line 218 of file isdn_lib.c.

Referenced by init_bc().

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

Definition at line 3268 of file isdn_lib.c.

Referenced by misdn_lib_send_event().

#define TONE_ALERT_CNT   41

Definition at line 221 of file isdn_lib.c.

#define TONE_ALERT_SILENCE_CNT   200

Definition at line 222 of file isdn_lib.c.

#define TONE_BUSY_CNT   20

Definition at line 224 of file isdn_lib.c.

#define TONE_BUSY_SILENCE_CNT   48

Definition at line 225 of file isdn_lib.c.


Enumeration Type Documentation

Enumerator:
MISDN_INITIALIZING 
MISDN_INITIALIZED 

Definition at line 155 of file isdn_lib.c.

00155                    {
00156    MISDN_INITIALIZING,
00157    MISDN_INITIALIZED
00158 } ;


Function Documentation

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

Definition at line 602 of file isdn_lib.c.

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

Referenced by misdn_lib_bridge().

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

char* bc_state2str ( enum bchannel_state  state  ) 

Definition at line 553 of file isdn_lib.c.

References BCHAN_ACTIVATED, BCHAN_ACTIVE, BCHAN_BRIDGE, BCHAN_BRIDGED, BCHAN_CLEAN, BCHAN_CLEAN_REQUEST, BCHAN_CLEANED, BCHAN_EMPTY, BCHAN_ERROR, BCHAN_RELEASE, BCHAN_RELEASED, BCHAN_SETUP, BCHAN_SETUPED, and s.

Referenced by bc_next_state_change(), bc_state_change(), cb_events(), handle_bchan(), handle_err(), misdn_lib_send_event(), misdn_lib_split_bridge(), misdn_lib_tx2misdn_frm(), print_bc_info(), and setup_bc().

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

void bc_state_change ( struct misdn_bchannel bc,
enum bchannel_state  state 
)

Definition at line 582 of file isdn_lib.c.

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

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

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

int bchdev_echocancel_activate ( struct misdn_bchannel dev  ) 

void bchdev_echocancel_deactivate ( struct misdn_bchannel dev  ) 

static char* bearer2str ( int  cap  )  [static]

Definition at line 263 of file isdn_lib.c.

References INFO_CAPABILITY_AUDIO_3_1K, INFO_CAPABILITY_DIGITAL_RESTRICTED, INFO_CAPABILITY_DIGITAL_UNRESTRICTED, and INFO_CAPABILITY_SPEECH.

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

static int clean_up_bc ( struct misdn_bchannel bc  )  [static]

Definition at line 709 of file isdn_lib.c.

References misdn_bchannel::b_stid, misdn_bchannel::bc_state, bc_state_change(), BCHAN_CLEANED, cb_log, get_stack_by_bc(), misdn_bchannel::layer_id, manager_bchannel_deactivate(), manager_ec_disable(), misdn_stack::midev, misdn_bchannel::pid, misdn_stack::port, and misdn_bchannel::port.

Referenced by clear_l3(), handle_bchan(), handle_cr(), handle_event_nt(), handle_frm(), manager_event_handler(), misdn_lib_release(), misdn_lib_send_event(), misdn_lib_send_restart(), and misdn_lib_setup_bc().

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

static void clear_l3 ( struct misdn_stack stack  )  [static]

Definition at line 747 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, cb_event, clean_up_bc(), empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, global_state, misdn_bchannel::in_use, and MISDN_INITIALIZED.

Referenced by handle_mgmt(), and misdn_lib_port_restart().

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

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

Definition at line 322 of file isdn_lib.c.

Referenced by misdn_lib_get_l2_down(), and misdn_lib_get_l2_up().

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

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

Definition at line 344 of file isdn_lib.c.

Referenced by build_alerting(), build_connect(), build_connect_acknowledge(), build_disconnect(), build_facility(), build_hold(), build_hold_acknowledge(), build_hold_reject(), build_information(), build_notify(), build_proceeding(), build_progress(), build_release(), build_release_complete(), build_restart(), build_resume(), build_resume_acknowledge(), build_resume_reject(), build_retrieve(), build_retrieve_acknowledge(), build_retrieve_reject(), build_setup(), build_setup_acknowledge(), build_status(), build_status_enquiry(), build_suspend(), build_suspend_acknowledge(), build_suspend_reject(), build_timeout(), build_user_information(), and handle_event_nt().

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

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

Definition at line 879 of file isdn_lib.c.

References 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, newteid, misdn_stack::nt, misdn_stack::port, misdn_stack::procids, misdn_stack::ptp, misdn_bchannel::te_choose_channel, and misdn_stack::upper_id.

Referenced by misdn_lib_send_event().

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

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

Definition at line 2195 of file isdn_lib.c.

References cb_event, EVENT_TONE_GENERATE, misdn_bchannel::generate_tone, misdn_tx_jitter(), misdn_bchannel::nojitter, misdn_bchannel::tone_cnt, and misdn_lib::user_data.

Referenced by handle_bchan().

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

static void dump_chan_list ( struct misdn_stack stack  )  [static]

Definition at line 437 of file isdn_lib.c.

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

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

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

void ec_chunk ( struct misdn_bchannel bc,
unsigned char *  rxchunk,
unsigned char *  txchunk,
int  chunk_size 
)

static void empty_bc ( struct misdn_bchannel bc  )  [static]

Set Default Bearer Caps

Definition at line 612 of file isdn_lib.c.

References misdn_bchannel::active, misdn_bchannel::bframe_len, misdn_bchannel::cad, misdn_bchannel::capability, misdn_bchannel::cause, misdn_bchannel::channel, misdn_bchannel::channel_found, misdn_bchannel::conf_id, misdn_bchannel::cpnnumplan, misdn_bchannel::crypt, misdn_bchannel::crypt_key, misdn_bchannel::curprx, misdn_bchannel::curptx, misdn_bchannel::cw, misdn_bchannel::dad, misdn_bchannel::dec, misdn_bchannel::display, misdn_bchannel::dnumplan, misdn_bchannel::dummy, misdn_bchannel::early_bconnect, misdn_bchannel::ec_deftaps, misdn_bchannel::ec_enable, EVENT_NOTHING, misdn_bchannel::evq, misdn_bchannel::fac_in, misdn_bchannel::fac_out, misdn_bchannel::generate_tone, misdn_bchannel::hdlc, INFO_CAPABILITY_SPEECH, INFO_CODEC_ALAW, misdn_bchannel::info_dad, misdn_bchannel::infos_pending, misdn_bchannel::last_used, misdn_bchannel::law, misdn_bchannel::mode, misdn_bchannel::need_more_infos, misdn_bchannel::nodsp, misdn_bchannel::nojitter, NUMPLAN_UNKNOWN, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_bchannel::orig, misdn_bchannel::orig_dad, misdn_bchannel::out_cause, misdn_bchannel::pres, misdn_bchannel::progress_coding, misdn_bchannel::progress_indicator, misdn_bchannel::progress_location, misdn_bchannel::rad, misdn_bchannel::rate, misdn_bchannel::restart_channel, misdn_bchannel::rnumplan, misdn_bchannel::rxgain, misdn_bchannel::send_dtmf, misdn_bchannel::sending_complete, misdn_bchannel::te_choose_channel, misdn_bchannel::time_usec, misdn_bchannel::tone_cnt, misdn_bchannel::txgain, misdn_bchannel::urate, misdn_bchannel::user1, misdn_bchannel::uu, and misdn_bchannel::uulen.

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

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

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

Definition at line 540 of file isdn_lib.c.

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

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

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

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

Definition at line 3214 of file isdn_lib.c.

References s.

Referenced by misdn_lib_log_ies().

03215 {
03216    struct arr_el { 
03217       enum FacFunction p; 
03218       char *s ; 
03219    } arr[] = {
03220       { Fac_None, "Fac_None" },
03221       { Fac_CD, "Fac_CD"},
03222    };
03223    
03224    int i;
03225    
03226    for (i=0; i < sizeof(arr)/sizeof( struct arr_el) ; i ++)
03227       if ( arr[i].p==func) return arr[i].s;
03228    
03229    return "unknown";
03230 }

static msg_t* fetch_msg ( int  midev  )  [static]

Definition at line 2935 of file isdn_lib.c.

References cb_log, and errno.

Referenced by misdn_lib_isdn_event_catcher().

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

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

Definition at line 1463 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::layer_id, misdn_stack::next, and misdn_lib::stack_list.

Referenced by handle_bchan().

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

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

Definition at line 1499 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::channel, and find_stack_by_port().

Referenced by handle_err().

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

struct misdn_bchannel * find_bc_by_confid ( unsigned long  confid  )  [read]

Definition at line 1481 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::conf_id, misdn_stack::next, and misdn_lib::stack_list.

Referenced by misdn_lib_send_event().

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

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

Definition at line 1444 of file isdn_lib.c.

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

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

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

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

Definition at line 1434 of file isdn_lib.c.

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

Referenced by handle_event_nt().

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

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

Definition at line 1453 of file isdn_lib.c.

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

Referenced by manager_find_bc_holded().

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

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

Definition at line 478 of file isdn_lib.c.

References misdn_stack::b_num, cb_log, misdn_bchannel::channel, misdn_bchannel::channel_found, misdn_stack::channels, dump_chan_list(), MAX_BCHANS, misdn_bchannel::out_cause, misdn_stack::port, misdn_stack::pri, and set_chan_in_stack().

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

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

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

Definition at line 1395 of file isdn_lib.c.

References misdn_stack::next, misdn_lib::stack_list, and misdn_stack::upper_id.

Referenced by handle_frm(), handle_frm_nt(), handle_l1(), handle_l2(), and handle_mgmt().

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

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

Definition at line 1422 of file isdn_lib.c.

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

Referenced by handle_event_nt().

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

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

Definition at line 1410 of file isdn_lib.c.

References misdn_stack::next, misdn_stack::port, and misdn_lib::stack_list.

Referenced by find_bc_by_channel(), handle_err(), manager_event_handler(), misdn_lib_get_port_info(), misdn_lib_port_restart(), misdn_lib_reinit_nt_stack(), and misdn_lib_send_restart().

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

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

Definition at line 307 of file isdn_lib.c.

References flip_table.

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

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

struct misdn_stack * get_misdn_stack ( void   )  [read]

void get_show_stack_details ( int  port,
char *  buf 
)

Definition at line 135 of file isdn_lib.c.

References misdn_stack::blocked, get_misdn_stack(), misdn_stack::l1link, misdn_stack::l2link, misdn_stack::next, misdn_stack::nt, misdn_stack::port, and misdn_stack::ptp.

Referenced by misdn_show_port(), and misdn_show_stacks().

00136 {
00137    struct misdn_stack *stack=get_misdn_stack();
00138    
00139    for ( ; stack; stack=stack->next) {
00140       if (stack->port == port) break;
00141    }
00142    
00143    if (stack) {
00144       sprintf(buf, "* Port %d Type %s Prot. %s L2Link %s L1Link:%s Blocked:%d", stack->port, stack->nt?"NT":"TE", stack->ptp?"PTP":"PMP", stack->l2link?"UP":"DOWN", stack->l1link?"UP":"DOWN",stack->blocked);
00145 
00146    } else {
00147       buf[0]=0;
00148    }
00149    
00150 }

struct misdn_stack* get_stack_by_bc ( struct misdn_bchannel bc  )  [read]

Definition at line 118 of file isdn_lib.c.

References misdn_stack::b_num, get_misdn_stack(), misdn_stack::next, misdn_stack::port, and misdn_bchannel::port.

Referenced by clean_up_bc(), create_process(), dec_ie_channel_id(), enc_ie_channel_id(), handle_bchan(), handle_event(), manager_bchannel_activate(), manager_bchannel_deactivate(), manager_clean_bc(), manager_ec_disable(), manager_ec_enable(), manager_find_bc_holded(), misdn_lib_log_ies(), misdn_lib_release(), misdn_lib_send_event(), misdn_lib_tx2misdn_frm(), parse_release_complete(), parse_restart(), send_msg(), and setup_bc().

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

static int handle_bchan ( msg_t *  msg  )  [static]

Anyway flip the bufbits

Definition at line 2298 of file isdn_lib.c.

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

Referenced by handle_err(), and manager_isdn_handler().

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

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

Definition at line 1602 of file isdn_lib.c.

References cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), dump_chan_list(), empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, find_bc_by_l3id(), free, misdn_bchannel::in_use, misdn_bchannel::l3_id, make_dummy(), misdn_lib_get_free_bc(), misdn_bchannel::need_disconnect, misdn_bchannel::need_release, misdn_bchannel::need_release_complete, misdn_stack::nt, misdn_stack::port, misdn_bchannel::stack_holder, stack_holder_remove(), and misdn_lib::user_data.

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

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

static int handle_err ( msg_t *  msg  )  [static]

Definition at line 3503 of file isdn_lib.c.

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

03504 {
03505    iframe_t *frm = (iframe_t*) msg->data;
03506 
03507 
03508    if (!frm->addr) {
03509       static int cnt=0;
03510       if (!cnt)
03511          cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo);
03512       cnt++;
03513       if (cnt>100) {
03514          cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo);
03515          cnt=0;
03516       }
03517       
03518       free_msg(msg);
03519       return 1;
03520       
03521    }
03522    
03523    switch (frm->prim) {
03524       case MGR_SETSTACK|INDICATION:
03525          return handle_bchan(msg);
03526       break;
03527 
03528       case MGR_SETSTACK|CONFIRM:
03529       case MGR_CLEARSTACK|CONFIRM:
03530          free_msg(msg) ; 
03531          return 1;
03532       break;
03533 
03534       case DL_DATA|CONFIRM:
03535          cb_log(4,0,"DL_DATA|CONFIRM\n");
03536          free_msg(msg);
03537          return 1;
03538 
03539       case PH_CONTROL|CONFIRM:
03540          cb_log(4,0,"PH_CONTROL|CONFIRM\n");
03541          free_msg(msg);
03542          return 1;
03543 
03544       case DL_DATA|INDICATION:
03545       {
03546          struct misdn_bchannel *bc;
03547          int port=(frm->addr&MASTER_ID_MASK) >> 8;
03548          int channel=(frm->addr&CHILD_ID_MASK) >> 16;
03549 
03550          /*we flush the read buffer here*/
03551          
03552          cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel);
03553          
03554          free_msg(msg) ; 
03555          return 1;
03556          
03557          
03558          bc=find_bc_by_channel( port , channel);
03559 
03560          if (!bc) {
03561             struct misdn_stack *stack=find_stack_by_port( port );
03562 
03563             if (!stack) {
03564                cb_log(0,0," --> stack not found\n");
03565                free_msg(msg);
03566                return 1;
03567             }
03568             
03569             cb_log(0,0," --> bc not found by channel\n");
03570             if (stack->l2link)
03571                misdn_lib_get_l2_down(stack);
03572 
03573             if (stack->l1link)
03574                misdn_lib_get_l1_down(stack);
03575 
03576             free_msg(msg);
03577             return 1;
03578          }
03579          
03580          cb_log(3,port," --> BC in state:%s\n", bc_state2str(bc->bc_state));
03581       }
03582    }
03583 
03584    return 0;
03585 }

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

NT MODE

Definition at line 1519 of file isdn_lib.c.

References misdn_bchannel::capability, cb_log, misdn_bchannel::channel, misdn_bchannel::crypt_key, misdn_bchannel::cw, misdn_bchannel::dad, misdn_bchannel::dnumplan, EVENT_ALERTING, EVENT_CONNECT, EVENT_CONNECT_ACKNOWLEDGE, EVENT_PROCEEDING, EVENT_PROGRESS, EVENT_RELEASE, EVENT_RELEASE_COMPLETE, EVENT_SETUP, EVENT_SETUP_ACKNOWLEDGE, find_free_chan_in_stack(), get_stack_by_bc(), manager_ec_enable(), manager_ph_control(), manager_ph_control_block(), misdn_cap_is_speech(), misdn_lib_send_event(), misdn_bchannel::nodsp, misdn_stack::nt, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_stack::port, misdn_stack::pri, misdn_stack::ptp, misdn_bchannel::rxgain, setup_bc(), and misdn_bchannel::txgain.

Referenced by handle_frm().

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

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

Definition at line 1813 of file isdn_lib.c.

References misdn_bchannel::b_stid, misdn_stack::bc, misdn_bchannel::cause, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), create_l3msg(), empty_bc(), empty_chan_in_stack(), event, EVENT_NEW_L3ID, EVENT_PORT_ALARM, EVENT_RELEASE, EVENT_RELEASE_COMPLETE, EVENT_SETUP, find_bc_by_l3id(), find_bc_by_masked_l3id(), find_free_chan_in_stack(), find_stack_by_mgr(), free, 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(), and stack_init().

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

static int handle_frm ( msg_t *  msg  )  [static]

Preprocess some Events

Definition at line 2594 of file isdn_lib.c.

References bc_state_change(), BCHAN_CLEANED, misdn_bchannel::cause, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), empty_bc(), empty_chan_in_stack(), event, EVENT_RELEASE_COMPLETE, EVENT_RESTART, EVENT_SETUP, find_bc_by_l3id(), find_stack_by_addr(), handle_cr(), handle_event(), misdn_bchannel::in_use, isdn_get_info(), isdn_msg_get_event(), isdn_msg_parse_event(), misdn_bchannel::l3_id, make_dummy(), misdn_lib_send_event(), misdn_lib_send_restart(), msgs_g, misdn_bchannel::out_cause, misdn_bchannel::port, RESPONSE_IGNORE_SETUP, RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE, RESPONSE_OK, RESPONSE_RELEASE_SETUP, misdn_bchannel::restart_channel, set_chan_in_stack(), and misdn_lib::user_data.

Referenced by manager_event_handler(), and manager_isdn_handler().

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

static int handle_frm_nt ( msg_t *  msg  )  [static]

Definition at line 2559 of file isdn_lib.c.

References cb_log, find_stack_by_addr(), and nt_err_cnt.

Referenced by manager_event_handler(), and manager_isdn_handler().

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

static int handle_l1 ( msg_t *  msg  )  [static]

Definition at line 2734 of file isdn_lib.c.

References cb_event, cb_log, EVENT_CLEANUP, EVENT_NOTHING, find_stack_by_addr(), 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().

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

static int handle_l2 ( msg_t *  msg  )  [static]

Definition at line 2806 of file isdn_lib.c.

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

Referenced by manager_isdn_handler().

02807 {
02808    iframe_t *frm = (iframe_t*) msg->data;
02809 
02810    struct misdn_stack *stack = find_stack_by_addr(frm->addr);
02811    
02812    if (!stack) {
02813       return 0 ;
02814    }
02815    
02816    switch(frm->prim) {
02817 
02818    case DL_ESTABLISH | REQUEST:
02819       cb_log(1,stack->port,"DL_ESTABLISH|REQUEST \n");
02820       return 1;
02821    case DL_RELEASE | REQUEST:
02822       cb_log(1,stack->port,"DL_RELEASE|REQUEST \n");
02823       return 1;
02824       
02825    case DL_ESTABLISH | INDICATION:
02826    case DL_ESTABLISH | CONFIRM:
02827    {
02828       cb_log (3, stack->port, "L2: L2Link Up! \n");
02829       if (stack->ptp && stack->l2link) {
02830          cb_log (-1, stack->port, "L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n"); 
02831          cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data);
02832       }
02833       stack->l2link=1;
02834       free_msg(msg);
02835       return 1;
02836    }
02837    break;
02838     
02839    case DL_RELEASE | INDICATION:
02840    case DL_RELEASE | CONFIRM:
02841    {
02842       cb_log (3, stack->port, "L2: L2Link Down! \n");
02843       stack->l2link=0;
02844       
02845       free_msg(msg);
02846       return 1;
02847    }
02848    break;
02849    }
02850    return 0;
02851 }

static int handle_mgmt ( msg_t *  msg  )  [static]

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

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

static int handle_timers ( msg_t *  msg  )  [static]

Definition at line 2130 of file isdn_lib.c.

References cb_log, misdn_stack::next, and misdn_lib::stack_list.

Referenced by manager_isdn_handler().

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

int init_bc ( struct misdn_stack stack,
struct misdn_bchannel bc,
int  midev,
int  port,
int  bidx,
char *  msn,
int  firsttime 
)

IFACE

Definition at line 1128 of file isdn_lib.c.

References misdn_bchannel::astbuf, bc_state_change(), BCHAN_CLEANED, cb_log, empty_bc(), send_lock::lock, malloc, MISDN_IBUF_SIZE, misdn_bchannel::msn, misdn_stack::nt, misdn_bchannel::nt, misdn_stack::port, misdn_bchannel::port, misdn_stack::pri, misdn_bchannel::pri, pthread_mutex_init, and misdn_bchannel::send_lock.

Referenced by misdn_lib_init().

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

static void init_flip_bits ( void   )  [static]

Definition at line 294 of file isdn_lib.c.

References flip_table.

Referenced by misdn_lib_init().

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

void isdn_lib_stop_dtmf ( struct misdn_bchannel bc  ) 

Definition at line 4241 of file isdn_lib.c.

References manager_ph_control().

Referenced by process_ast_dsp().

04242 {
04243    manager_ph_control(bc, DTMF_TONE_STOP, 0);
04244 }

void isdn_lib_update_ec ( struct misdn_bchannel bc  ) 

Definition at line 4229 of file isdn_lib.c.

References misdn_bchannel::ec_enable, manager_ec_disable(), and manager_ec_enable().

Referenced by process_ast_dsp().

04230 {
04231 #ifdef MISDN_1_2
04232    if (*bc->pipeline)
04233 #else
04234    if (bc->ec_enable)
04235 #endif
04236       manager_ec_enable(bc);
04237    else
04238       manager_ec_disable(bc);
04239 }

void isdn_lib_update_rxgain ( struct misdn_bchannel bc  ) 

Definition at line 4219 of file isdn_lib.c.

References manager_ph_control(), and misdn_bchannel::rxgain.

Referenced by process_ast_dsp().

04220 {
04221    manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
04222 }

void isdn_lib_update_txgain ( struct misdn_bchannel bc  ) 

Definition at line 4224 of file isdn_lib.c.

References manager_ph_control(), and misdn_bchannel::txgain.

Referenced by process_ast_dsp().

04225 {
04226    manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
04227 }

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

Definition at line 47 of file isdn_lib.c.

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

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

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

void manager_bchannel_activate ( struct misdn_bchannel bc  ) 

Definition at line 4100 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_bchannel::astbuf, cb_log, get_stack_by_bc(), misdn_stack::midev, misdn_stack::port, and misdn_bchannel::port.

Referenced by setup_bc().

04101 {
04102    char buf[128];
04103 
04104    struct misdn_stack *stack=get_stack_by_bc(bc);
04105 
04106    if (!stack) {
04107       cb_log(0, bc->port, "bchannel_activate: Stack not found !");
04108       return ;
04109    }
04110    
04111    /* we must activate if we are deactivated */
04112    clear_ibuffer(bc->astbuf);
04113    
04114    cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr);
04115    
04116    mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN,  DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC);
04117 
04118    return ;
04119 }

void manager_bchannel_cleanup ( struct misdn_bchannel bc  ) 

void manager_bchannel_deactivate ( struct misdn_bchannel bc  ) 

Definition at line 4122 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_bchannel::astbuf, 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_stack::port, and misdn_bchannel::port.

Referenced by clean_up_bc().

04123 {
04124    char buf[128]; 
04125    iframe_t dact;
04126    struct misdn_stack *stack=get_stack_by_bc(bc);
04127 
04128    switch (bc->bc_state) {
04129       case BCHAN_ACTIVATED:
04130          break;
04131       case BCHAN_BRIDGED:
04132          misdn_split_conf(bc,bc->conf_id);
04133          break;
04134       default:
04135          cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n");
04136          return ;
04137 
04138    }
04139    
04140    cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr);
04141    
04142    bc->generate_tone=0;
04143    
04144    dact.prim = DL_RELEASE | REQUEST;
04145    dact.addr = bc->addr | FLG_MSG_DOWN;
04146    dact.dinfo = 0;
04147    dact.len = 0;
04148    mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC);
04149 
04150    clear_ibuffer(bc->astbuf);
04151    
04152    bc_state_change(bc,BCHAN_RELEASE);
04153   
04154    return;
04155 }

void manager_bchannel_setup ( struct misdn_bchannel bc  ) 

void manager_clean_bc ( struct misdn_bchannel bc  ) 

Definition at line 4268 of file isdn_lib.c.

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

04269 {
04270    struct misdn_stack *stack=get_stack_by_bc(bc);
04271    
04272    if (bc->channel>0)
04273       empty_chan_in_stack(stack, bc->channel);
04274    empty_bc(bc);
04275    bc->in_use=0;
04276 
04277    cb_event(EVENT_CLEANUP, bc, NULL); 
04278 }

void manager_ec_disable ( struct misdn_bchannel bc  ) 

Definition at line 4463 of file isdn_lib.c.

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

04464 {
04465    struct misdn_stack *stack=get_stack_by_bc(bc);
04466    
04467    cb_log(4, stack?stack->port:0," --> ec_disable\n");
04468 
04469    if (!misdn_cap_is_speech(bc->capability)) {
04470       cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n");
04471       return;
04472    }
04473 
04474 #ifdef MISDN_1_2
04475    manager_ph_control_block(bc, PIPELINE_CFG, "", 0);
04476 #else
04477    if ( ! bc->ec_enable) {
04478       cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n");
04479       manager_ph_control(bc,  ECHOCAN_OFF, 0);
04480    }
04481 #endif
04482 }

void manager_ec_enable ( struct misdn_bchannel bc  ) 

Definition at line 4414 of file isdn_lib.c.

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

04415 {
04416    struct misdn_stack *stack=get_stack_by_bc(bc);
04417    
04418    cb_log(4, stack?stack->port:0,"ec_enable\n");
04419 
04420    if (!misdn_cap_is_speech(bc->capability)) {
04421       cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n");
04422    } else {
04423 
04424 #ifdef MISDN_1_2
04425    if (*bc->pipeline) {
04426       cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline);
04427       manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1);
04428    }
04429 #else
04430    int ec_arr[2];
04431 
04432    if (bc->ec_enable) {
04433       cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps);
04434    
04435       switch (bc->ec_deftaps) {
04436       case 4:
04437       case 8:
04438       case 16:
04439       case 32:
04440       case 64:
04441       case 128:
04442       case 256:
04443       case 512:
04444       case 1024:
04445          cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps);
04446          break;
04447       default:
04448          cb_log(0, stack->port, "Taps should be power of 2\n");
04449          bc->ec_deftaps=128;
04450       }
04451    
04452       ec_arr[0]=bc->ec_deftaps;
04453       ec_arr[1]=0;
04454       
04455       manager_ph_control_block(bc,  ECHOCAN_ON,  ec_arr, sizeof(ec_arr));
04456    }
04457 #endif
04458    }
04459 }

static void manager_event_handler ( void *  arg  )  [static]

wait for events

Handle L2/3 Signalling after bchans

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

Referenced by misdn_lib_init().

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

struct misdn_bchannel * manager_find_bc_by_pid ( int  pid  )  [read]

Definition at line 3085 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, misdn_stack::next, misdn_bchannel::pid, and misdn_lib::stack_list.

Referenced by misdn_lib_pid_restart().

03086 {
03087    struct misdn_stack *stack;
03088    int i;
03089   
03090    for (stack=glob_mgr->stack_list;
03091         stack;
03092         stack=stack->next) {
03093       for (i=0; i<=stack->b_num; i++)
03094          if (stack->bc[i].pid == pid) return &stack->bc[i];
03095    }
03096   
03097    return NULL;
03098 }

struct misdn_bchannel * manager_find_bc_holded ( struct misdn_bchannel bc  )  [read]

Definition at line 3100 of file isdn_lib.c.

References find_bc_holded(), and get_stack_by_bc().

03101 {
03102    struct misdn_stack *stack=get_stack_by_bc(bc);
03103    return find_bc_holded(stack);
03104 }

char* manager_isdn_get_info ( enum event_e  event  ) 

Definition at line 4095 of file isdn_lib.c.

References isdn_get_info(), and msgs_g.

Referenced by cb_events().

04096 {
04097    return isdn_get_info(msgs_g , event, 0);
04098 }

int manager_isdn_handler ( iframe_t *  frm,
msg_t *  msg 
)

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

03606 {  
03607 
03608    if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) {
03609       cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n");
03610    }
03611 
03612    if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) {
03613       static int unhandled_bmsg_count=1000;
03614       if (handle_bchan(msg)) {
03615          return 0 ;
03616       }
03617          
03618       if (unhandled_bmsg_count==1000) {
03619          cb_log(0, 0, "received 1k Unhandled Bchannel Messages: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo);     
03620          unhandled_bmsg_count=0;
03621       }
03622 
03623       unhandled_bmsg_count++;
03624       free_msg(msg);
03625       return 0;
03626    }  
03627 
03628 #ifdef RECV_FRM_SYSLOG_DEBUG
03629    syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo);
03630 #endif
03631 
03632    if (handle_timers(msg)) 
03633       return 0 ;
03634 
03635    
03636    if (handle_mgmt(msg)) 
03637       return 0 ; 
03638    
03639    if (handle_l2(msg)) 
03640       return 0 ;
03641 
03642    /* Its important to handle l1 AFTER l2  */
03643    if (handle_l1(msg)) 
03644       return 0 ;
03645    
03646    if (handle_frm_nt(msg)) {
03647       return 0;
03648    }
03649 
03650    if (handle_frm(msg)) {
03651       return 0;
03652    }
03653 
03654    if (handle_err(msg)) {
03655       return 0 ;
03656    }
03657 
03658    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);      
03659    free_msg(msg);
03660    
03661 
03662    return 0;
03663 }

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

Definition at line 4198 of file isdn_lib.c.

References misdn_bchannel::addr, cb_log, 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().

04199 {
04200    unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)];
04201    iframe_t *ctrl = (iframe_t *)buffer; /* preload data */
04202    unsigned int *d = (unsigned int*)&ctrl->data.p;
04203    /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
04204    
04205    cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2);
04206    
04207    ctrl->prim = PH_CONTROL | REQUEST;
04208    ctrl->addr = bc->addr | FLG_MSG_DOWN;
04209    ctrl->dinfo = 0;
04210    ctrl->len = sizeof(unsigned int)*2;
04211    *d++ = c1;
04212    *d++ = c2;
04213    mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
04214 }

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

Definition at line 4249 of file isdn_lib.c.

References misdn_bchannel::addr, and misdn_lib::midev.

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

04250 {
04251    unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len];
04252    iframe_t *ctrl = (iframe_t *)buffer;
04253    unsigned int *d = (unsigned int *)&ctrl->data.p;
04254    /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
04255    
04256    ctrl->prim = PH_CONTROL | REQUEST;
04257    ctrl->addr = bc->addr | FLG_MSG_DOWN;
04258    ctrl->dinfo = 0;
04259    ctrl->len = sizeof(unsigned int) + c2_len;
04260    *d++ = c1;
04261    memcpy(d, c2, c2_len);
04262    mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
04263 }

int misdn_cap_is_speech ( int  cap  ) 

void misdn_dump_chanlist ( void   ) 

Definition at line 447 of file isdn_lib.c.

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

Referenced by misdn_show_cls().

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

int misdn_inband_avail ( struct misdn_bchannel bc  ) 

Definition at line 419 of file isdn_lib.c.

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

Referenced by cb_events(), and misdn_indication().

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

void misdn_join_conf ( struct misdn_bchannel bc,
int  conf_id 
)

Definition at line 4490 of file isdn_lib.c.

References misdn_bchannel::addr, 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().

04491 {
04492    char data[16];
04493    int len=15;
04494 
04495    bc_state_change(bc,BCHAN_BRIDGED);
04496    manager_ph_control(bc, CMX_RECEIVE_OFF, 0);
04497    manager_ph_control(bc, CMX_CONF_JOIN, conf_id);
04498 
04499    cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id);
04500 
04501    memset(data,0,15);
04502    
04503    misdn_lib_tx2misdn_frm(bc, data, len);
04504 
04505 }

void misdn_lib_bridge ( struct misdn_bchannel bc1,
struct misdn_bchannel bc2 
)

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

04518 {
04519    int conf_id=bc1->pid +1;
04520    struct misdn_bchannel *bc_list[]={
04521       bc1,bc2,NULL
04522    };
04523    struct misdn_bchannel **bc;
04524 
04525    cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port);
04526    
04527    for (bc=bc_list; *bc;  bc++) { 
04528       (*bc)->conf_id=conf_id;
04529       cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr);
04530    
04531       switch((*bc)->bc_state) {
04532          case BCHAN_ACTIVATED:
04533             misdn_join_conf(*bc,conf_id);
04534             break;
04535          default:
04536             bc_next_state_change(*bc,BCHAN_BRIDGED);
04537             break;
04538       }
04539    }
04540 }

void misdn_lib_destroy ( void   ) 

Definition at line 4062 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, global_state, misdn_lib::midev, misdn_stack::midev, MISDN_INITIALIZED, misdn_stack::next, misdn_stack::port, stack_destroy(), misdn_lib::stack_list, and te_lib_destroy().

Referenced by unload_module().

04063 {
04064    struct misdn_stack *help;
04065    int i;
04066   
04067    for ( help=glob_mgr->stack_list; help; help=help->next ) {
04068       for(i=0;i<=help->b_num; i++) {
04069          char buf[1024];
04070          mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
04071          help->bc[i].addr = 0;
04072       }
04073       cb_log (1, help->port, "Destroying this port.\n");
04074       stack_destroy(help);
04075    }
04076    
04077    if (global_state == MISDN_INITIALIZED) {
04078       cb_log(4, 0, "Killing Handler Thread\n");
04079       if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) {
04080          cb_log(4, 0, "Joining Handler Thread\n");
04081          pthread_join(glob_mgr->event_handler_thread, NULL);
04082       }
04083      
04084       cb_log(4, 0, "Killing Main Thread\n");
04085       if ( pthread_cancel(glob_mgr->event_thread) == 0 ) {
04086          cb_log(4, 0, "Joining Main Thread\n");
04087          pthread_join(glob_mgr->event_thread, NULL);
04088       }
04089    }
04090   
04091    cb_log(1, 0, "Closing mISDN device\n");
04092    te_lib_destroy(glob_mgr->midev);
04093 }

void misdn_lib_echo ( struct misdn_bchannel bc,
int  onoff 
)

Definition at line 4562 of file isdn_lib.c.

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

04563 {
04564    cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF");
04565    manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0);
04566 }

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

Definition at line 3142 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, MAX_BCHANS, misdn_stack::next, misdn_stack::port, prepare_bc(), misdn_stack::pri, misdn_stack::ptp, misdn_lib::stack_list, and test_inuse().

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

03143 {
03144    struct misdn_stack *stack;
03145    int i;
03146    
03147    if (channel < 0 || channel > MAX_BCHANS) {
03148       cb_log(0,port,"Requested channel out of bounds (%d)\n",channel);
03149       return NULL;
03150    }
03151 
03152    usleep(1000);
03153 
03154    for (stack=glob_mgr->stack_list; stack; stack=stack->next) {
03155     
03156       if (stack->port == port) {
03157          int maxnum;
03158          if (stack->blocked) {
03159             cb_log(0,port,"Port is blocked\n");
03160             return NULL;
03161          }
03162       
03163          if (channel > 0) {
03164             if (channel <= stack->b_num) {
03165                for (i = 0; i < stack->b_num; i++) {
03166                   if ( test_inuse(&stack->bc[i]) && stack->bc[i].channel == channel) {
03167                      cb_log(0,port,"Requested channel:%d on port:%d is already in use\n",channel, port);
03168                      return NULL;
03169                   }
03170                }
03171             } else {
03172                cb_log(0,port,"Requested channel:%d is out of bounds on port:%d\n",channel, port);
03173                return NULL;
03174             }
03175          }
03176 
03177          maxnum=inout&&!stack->pri&&!stack->ptp?stack->b_num+1:stack->b_num;
03178 
03179          if (dec) {
03180             for (i = maxnum-1; i>=0; i--) {
03181                if (test_inuse(&stack->bc[i])) {
03182                   /* 3. channel on bri means CW*/
03183                   if (!stack->pri && i==stack->b_num)
03184                      stack->bc[i].cw=1;
03185                      
03186                   prepare_bc(&stack->bc[i], channel);
03187                   stack->bc[i].dec=1;
03188                   return &stack->bc[i];
03189                }
03190             }
03191          } else {
03192             for (i = 0; i <maxnum; i++) {
03193                if (test_inuse(&stack->bc[i])) {
03194                   /* 3. channel on bri means CW*/
03195                   if (!stack->pri && i==stack->b_num)
03196                      stack->bc[i].cw=1;
03197 
03198                   prepare_bc(&stack->bc[i], channel);
03199                   return &stack->bc[i];
03200                }
03201             }
03202          }
03203 
03204          cb_log(1,port,"There is no free channel on port (%d)\n",port);
03205          return NULL;
03206       }
03207    }
03208 
03209    cb_log(0,port,"Port is not configured (%d)\n",port);
03210    return NULL;
03211 }

static int misdn_lib_get_l1_down ( struct misdn_stack stack  )  [static]

Definition at line 767 of file isdn_lib.c.

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

Referenced by handle_err(), and misdn_lib_get_port_down().

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

static int misdn_lib_get_l1_up ( struct misdn_stack stack  )  [static]

Definition at line 807 of file isdn_lib.c.

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

Referenced by misdn_lib_get_port_up(), misdn_lib_isdn_l1watcher(), misdn_lib_reinit_nt_stack(), misdn_lib_send_event(), and stack_init().

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

static int misdn_lib_get_l2_down ( struct misdn_stack stack  )  [static]

Definition at line 781 of file isdn_lib.c.

References create_l2msg(), misdn_stack::midev, misdn_stack::nst, misdn_stack::nt, misdn_stack::ptp, and misdn_stack::upper_id.

Referenced by handle_err(), and misdn_lib_get_port_down().

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

int misdn_lib_get_l2_up ( struct misdn_stack stack  ) 

Definition at line 822 of file isdn_lib.c.

References create_l2msg(), misdn_stack::midev, misdn_stack::nst, misdn_stack::nt, misdn_stack::ptp, and misdn_stack::upper_id.

Referenced by handle_event_nt(), handle_l1(), misdn_lib_get_port_up(), misdn_lib_isdn_l1watcher(), misdn_lib_reinit_nt_stack(), and stack_init().

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

int misdn_lib_get_maxchans ( int  port  ) 

Definition at line 103 of file isdn_lib.c.

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

Referenced by misdn_request().

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

int misdn_lib_get_port_down ( int  port  ) 

Definition at line 1724 of file isdn_lib.c.

References misdn_stack::l2link, misdn_lib_get_l1_down(), misdn_lib_get_l2_down(), misdn_stack::next, misdn_stack::port, and misdn_lib::stack_list.

Referenced by misdn_port_down().

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

int misdn_lib_get_port_info ( int  port  ) 

Definition at line 3668 of file isdn_lib.c.

References misdn_lib::activatequeue, cb_log, find_stack_by_port(), misdn_lib::new_msg, and misdn_stack::upper_id.

03669 {
03670    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03671    iframe_t *frm;
03672    struct misdn_stack *stack=find_stack_by_port(port);
03673    if (!msg) {
03674       cb_log(0, port, "misgn_lib_get_port: alloc_msg failed!\n");
03675       return -1;
03676    }
03677    frm=(iframe_t*)msg->data;
03678    if (!stack ) {
03679       cb_log(0, port, "There is no Stack for this port.\n");
03680       return -1;
03681    }
03682    /* activate bchannel */
03683    frm->prim = CC_STATUS_ENQUIRY | REQUEST;
03684 
03685    frm->addr = stack->upper_id| FLG_MSG_DOWN;
03686 
03687    frm->dinfo = 0;
03688    frm->len = 0;
03689   
03690    msg_queue_tail(&glob_mgr->activatequeue, msg);
03691    sem_post(&glob_mgr->new_msg);
03692 
03693   
03694    return 0; 
03695 }

int misdn_lib_get_port_up ( int  port  ) 

Definition at line 1702 of file isdn_lib.c.

References misdn_stack::l1link, misdn_stack::l2link, misdn_lib_get_l1_up(), misdn_lib_get_l2_up(), misdn_stack::next, misdn_stack::port, and misdn_lib::stack_list.

Referenced by misdn_check_l2l1(), and misdn_port_up().

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

static int misdn_lib_get_short_status ( struct misdn_stack stack  )  [static]

Definition at line 862 of file isdn_lib.c.

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

Referenced by misdn_lib_isdn_l1watcher(), and stack_init().

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

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

Definition at line 3954 of file isdn_lib.c.

References misdn_lib::activatequeue, misdn_stack::b_num, misdn_stack::bc, calloc, misdn_lib_iface::cb_event, cb_event, misdn_lib_iface::cb_jb_empty, cb_jb_empty, misdn_lib_iface::cb_log, cb_log, misdn_lib::event_handler_thread, misdn_lib::event_thread, flip_buf_bits(), global_state, init_bc(), init_flip_bits(), manager_event_handler(), misdn_stack::midev, misdn_lib::midev, MISDN_INITIALIZED, misdn_lib_isdn_event_catcher(), misdn_lib_nt_debug_init(), misdn_lib::new_msg, misdn_stack::next, pthread_create, ptp, stack_init(), misdn_lib::stack_list, te_lib_init(), tone_425_flip, and tone_silence_flip.

Referenced by load_module().

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

int misdn_lib_is_port_blocked ( int  port  ) 

Definition at line 83 of file isdn_lib.c.

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

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

int misdn_lib_is_ptp ( int  port  ) 

Definition at line 94 of file isdn_lib.c.

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

Referenced by cb_events(), and do_immediate_setup().

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

static void misdn_lib_isdn_event_catcher ( void *  arg  )  [static]

When we make a call from NT2Ast we get this frames

I get this sometimes after setup_bc

Definition at line 2991 of file isdn_lib.c.

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

Referenced by misdn_lib_init().

02992 {
02993    struct misdn_lib *mgr = arg;
02994    int zero_frm=0 , fff_frm=0 ;
02995    int midev= mgr->midev;
02996    int port=0;
02997    
02998    while (1) {
02999       msg_t *msg = fetch_msg(midev); 
03000       iframe_t *frm;
03001       
03002       
03003       if (!msg) continue;
03004       
03005       frm = (iframe_t*) msg->data;
03006       
03007       /** When we make a call from NT2Ast we get this frames **/
03008       if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) {
03009          zero_frm++; 
03010          free_msg(msg);
03011          continue;
03012       } else {
03013          if (zero_frm) {
03014             cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm);
03015             zero_frm = 0 ;
03016          }
03017       }
03018       
03019       /** I get this sometimes after setup_bc **/
03020       if (frm->len == 0 &&  frm->dinfo == 0 && frm->prim == 0xffffffff ) {
03021          fff_frm++; 
03022          free_msg(msg);
03023          continue;
03024       } else {
03025          if (fff_frm) {
03026             cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm);
03027             fff_frm = 0 ;
03028          }
03029       }
03030       
03031       manager_isdn_handler(frm, msg);
03032    }
03033 
03034 }

void misdn_lib_isdn_l1watcher ( int  port  ) 

Definition at line 2973 of file isdn_lib.c.

References cb_log, 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().

02974 {
02975    struct misdn_stack *stack;
02976 
02977    for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next)
02978       ;
02979 
02980    if (stack) {
02981       cb_log(4, port, "Checking L1 State\n");   
02982       if (!stack->l1link) {
02983          cb_log(4, port, "L1 State Down, trying to get it up again\n"); 
02984          misdn_lib_get_short_status(stack);
02985          misdn_lib_get_l1_up(stack); 
02986          misdn_lib_get_l2_up(stack); 
02987       }
02988    }
02989 }

void misdn_lib_log_ies ( struct misdn_bchannel bc  ) 

Definition at line 3232 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_bchannel::b_stid, 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().

03233 {
03234    struct misdn_stack *stack;
03235    if (!bc) return;
03236 
03237    stack=get_stack_by_bc(bc);
03238 
03239    if (!stack) return;
03240 
03241    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);
03242    
03243    cb_log(2, stack->port,
03244           " --> info_dad:%s onumplan:%c dnumplan:%c rnumplan:%c cpnnumplan:%c\n",
03245           bc->info_dad,
03246           bc->onumplan>=0?'0'+bc->onumplan:' ',
03247           bc->dnumplan>=0?'0'+bc->dnumplan:' ',
03248           bc->rnumplan>=0?'0'+bc->rnumplan:' ',
03249           bc->cpnnumplan>=0?'0'+bc->cpnnumplan:' '
03250       );
03251    
03252    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);
03253    cb_log(4, stack->port, " --> screen:%d --> pres:%d\n",
03254          bc->screen, bc->pres);
03255    
03256    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);
03257    
03258    cb_log(4, stack->port, " --> facility:%s out_facility:%s\n",fac2str(bc->fac_in.Function),fac2str(bc->fac_out.Function));
03259 
03260    cb_log(5, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1);
03261    
03262    cb_log(5, stack->port, " --> bc:%x h:%d sh:%d\n", bc, bc->holded, bc->stack_holder);
03263 }

int misdn_lib_maxports_get ( void   ) 

BE AWARE WE HAVE NO CB_LOG HERE!

Definition at line 3906 of file isdn_lib.c.

Referenced by load_module().

03906                              { /** BE AWARE WE HAVE NO CB_LOG HERE! **/
03907    
03908    int i = mISDN_open();
03909    int max=0;
03910    
03911    if (i<0)
03912       return -1;
03913 
03914    max = mISDN_get_stack_count(i);
03915    
03916    mISDN_close(i);
03917    
03918    return max;
03919 }

void misdn_lib_nt_debug_init ( int  flags,
char *  file 
)

Definition at line 3934 of file isdn_lib.c.

References f.

Referenced by load_module(), and misdn_lib_init().

03935 {
03936    int static init=0;
03937    char *f;
03938    
03939    if (!flags) 
03940       f=NULL;
03941    else
03942       f=file;
03943 
03944    if (!init) {
03945       debug_init( flags , f, f, f);
03946       init=1;
03947    } else {
03948       debug_close();
03949       debug_init( flags , f, f, f);
03950    }
03951 }

void misdn_lib_nt_keepcalls ( int  kc  ) 

Definition at line 3922 of file isdn_lib.c.

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

Referenced by load_module().

03923 {
03924 #ifdef FEATURE_NET_KEEPCALLS
03925    if (kc) {
03926       struct misdn_stack *stack=get_misdn_stack();
03927       for ( ; stack; stack=stack->next) {
03928          stack->nst.feature |= FEATURE_NET_KEEPCALLS;
03929       }
03930    }
03931 #endif
03932 }

int misdn_lib_pid_restart ( int  pid  ) 

Definition at line 3723 of file isdn_lib.c.

References manager_clean_bc(), and manager_find_bc_by_pid().

Referenced by misdn_restart_pid().

03724 {
03725    struct misdn_bchannel *bc=manager_find_bc_by_pid(pid);
03726 
03727    if (bc) {
03728       manager_clean_bc(bc);
03729    }
03730    return 0;
03731 }

int misdn_lib_port_block ( int  port  ) 

Definition at line 57 of file isdn_lib.c.

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

Referenced by cb_events(), and misdn_port_block().

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

int misdn_lib_port_is_pri ( int  port  ) 

Definition at line 35 of file isdn_lib.c.

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

Referenced by misdn_new(), and update_name().

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

int misdn_lib_port_restart ( int  port  ) 

Definition at line 3772 of file isdn_lib.c.

References misdn_lib::activatequeue, cb_log, clear_l3(), find_stack_by_port(), 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().

03773 {
03774    struct misdn_stack *stack=find_stack_by_port(port);
03775  
03776    cb_log(0, port, "Restarting this port.\n");
03777    if (stack) {
03778       cb_log(0, port, "Stack:%p\n",stack);
03779          
03780       clear_l3(stack);
03781       {
03782          msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03783          iframe_t *frm;
03784 
03785          if (!msg) {
03786             cb_log(0, port, "port_restart: alloc_msg failed\n");
03787             return -1;
03788          }
03789          
03790          frm=(iframe_t*)msg->data;
03791          /* we must activate if we are deactivated */
03792          /* activate bchannel */
03793          frm->prim = DL_RELEASE | REQUEST;
03794          frm->addr = stack->upper_id | FLG_MSG_DOWN;
03795 
03796          frm->dinfo = 0;
03797          frm->len = 0;
03798          msg_queue_tail(&glob_mgr->activatequeue, msg);
03799          sem_post(&glob_mgr->new_msg);
03800       }
03801 
03802       if (stack->nt)
03803          misdn_lib_reinit_nt_stack(stack->port);
03804     
03805    }
03806 
03807    return 0;
03808 }

int misdn_lib_port_unblock ( int  port  ) 

Definition at line 70 of file isdn_lib.c.

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

Referenced by misdn_port_unblock().

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

int misdn_lib_port_up ( int  port,
int  check 
)

Definition at line 1740 of file isdn_lib.c.

References misdn_stack::blocked, cb_log, misdn_stack::l1link, misdn_stack::l2link, misdn_stack::next, misdn_stack::port, misdn_stack::ptp, and misdn_lib::stack_list.

Referenced by misdn_check_l2l1(), and misdn_request().

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

void misdn_lib_reinit_nt_stack ( int  port  ) 

Definition at line 4570 of file isdn_lib.c.

References misdn_stack::blocked, misdn_stack::d_stid, find_stack_by_port(), 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().

04571 {
04572    struct misdn_stack *stack=find_stack_by_port(port);
04573    
04574    if (stack) {
04575       stack->l2link=0;
04576       stack->blocked=0;
04577    
04578       cleanup_Isdnl3(&stack->nst);
04579       cleanup_Isdnl2(&stack->nst);
04580 
04581 
04582       memset(&stack->nst, 0, sizeof(net_stack_t));
04583       memset(&stack->mgr, 0, sizeof(manager_t));
04584    
04585       stack->mgr.nst = &stack->nst;
04586       stack->nst.manager = &stack->mgr;
04587     
04588       stack->nst.l3_manager = handle_event_nt;
04589       stack->nst.device = glob_mgr->midev;
04590       stack->nst.cardnr = port;
04591       stack->nst.d_stid = stack->d_stid;
04592    
04593       stack->nst.feature = FEATURE_NET_HOLD;
04594       if (stack->ptp)
04595          stack->nst.feature |= FEATURE_NET_PTP;
04596       if (stack->pri)
04597          stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
04598       
04599       stack->nst.l1_id = stack->lower_id;
04600       stack->nst.l2_id = stack->upper_id;
04601       
04602       msg_queue_init(&stack->nst.down_queue);
04603    
04604       Isdnl2Init(&stack->nst);
04605       Isdnl3Init(&stack->nst);
04606 
04607       if (!stack->ptp)
04608          misdn_lib_get_l1_up(stack);
04609       misdn_lib_get_l2_up(stack);
04610    }
04611 }

void misdn_lib_release ( struct misdn_bchannel bc  ) 

Definition at line 1682 of file isdn_lib.c.

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

Referenced by misdn_hangup().

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

int misdn_lib_send_event ( struct misdn_bchannel bc,
enum event_e  event 
)

Queue Event

Definition at line 3284 of file isdn_lib.c.

References 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(), 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_bchannel::nt, misdn_stack::nt, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_bchannel::out_cause, misdn_bchannel::pid, misdn_stack::port, misdn_bchannel::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().

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

int misdn_lib_send_restart ( int  port,
int  channel 
)

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

03735 {
03736    struct misdn_bchannel dummybc;
03737    struct misdn_stack *stack=find_stack_by_port(port);
03738    cb_log(0, port, "Sending Restarts on this port.\n");
03739    
03740    make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0);
03741 
03742    /*default is all channels*/
03743    if (channel <0) {
03744       dummybc.channel=-1;
03745       cb_log(0, port, "Restarting and all Interfaces\n");
03746       misdn_lib_send_event(&dummybc, EVENT_RESTART);
03747 
03748       return 0;
03749    }
03750 
03751    /*if a channel is specified we restart only this one*/
03752    if (channel >0) {
03753       int cnt;
03754       dummybc.channel=channel;
03755       cb_log(0, port, "Restarting and cleaning channel %d\n",channel);
03756       misdn_lib_send_event(&dummybc, EVENT_RESTART);
03757       /* clean up chan in stack, to be sure we don't think it's
03758        * in use anymore */
03759       for (cnt=0; cnt<=stack->b_num; cnt++) {
03760          if (stack->bc[cnt].channel == channel) {
03761             empty_bc(&stack->bc[cnt]);
03762             clean_up_bc(&stack->bc[cnt]);
03763             stack->bc[cnt].in_use=0;
03764          }
03765       }
03766    }
03767 
03768    return 0;
03769 }

void misdn_lib_send_tone ( struct misdn_bchannel bc,
enum tone_e  tone 
)

Definition at line 4379 of file isdn_lib.c.

References misdn_bchannel::addr, manager_ph_control(), misdn_lib::midev, TONE_ALERTING, TONE_DIAL, TONE_HANGUP, and TONE_NONE.

Referenced by hanguptone_indicate().

04380 {
04381    char buf[mISDN_HEADER_LEN+128];
04382    iframe_t *frm;
04383 
04384    switch(tone) {
04385    case TONE_DIAL:
04386       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE); 
04387    break;
04388    
04389    case TONE_ALERTING:
04390       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_RINGING);  
04391    break;
04392    
04393    case TONE_HANGUP:
04394       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_HANGUP);   
04395    break;
04396 
04397    case TONE_NONE:
04398    default:
04399       manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP);  
04400    }
04401 
04402    frm=(iframe_t*)buf;
04403    memset(buf,0,mISDN_HEADER_LEN+128);
04404 
04405    frm->prim=DL_DATA|REQUEST;
04406    frm->addr=bc->addr|FLG_MSG_DOWN;
04407    frm->dinfo=0;
04408    frm->len=128;
04409    
04410    mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
04411 }

void misdn_lib_setup_bc ( struct misdn_bchannel bc  ) 

Definition at line 945 of file isdn_lib.c.

References clean_up_bc(), and setup_bc().

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

void misdn_lib_split_bridge ( struct misdn_bchannel bc1,
struct misdn_bchannel bc2 
)

Definition at line 4542 of file isdn_lib.c.

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

Referenced by misdn_bridge().

04543 {
04544 
04545    struct misdn_bchannel *bc_list[]={
04546       bc1,bc2,NULL
04547    };
04548    struct misdn_bchannel **bc;
04549       
04550    for (bc=bc_list; *bc;  bc++) { 
04551       if ( (*bc)->bc_state == BCHAN_BRIDGED){
04552          misdn_split_conf( *bc, (*bc)->conf_id);
04553       } else {
04554          cb_log( 2, (*bc)->port, "BC not bridged (state:%s) so not splitting it\n",bc_state2str((*bc)->bc_state));
04555       }
04556    }
04557    
04558 }

void misdn_lib_tone_generator_start ( struct misdn_bchannel bc  ) 

Definition at line 2184 of file isdn_lib.c.

References misdn_bchannel::generate_tone.

Referenced by misdn_write().

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

void misdn_lib_tone_generator_stop ( struct misdn_bchannel bc  ) 

Definition at line 2189 of file isdn_lib.c.

References misdn_bchannel::generate_tone.

Referenced by start_bc_tones(), and stop_indicate().

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

void misdn_lib_transfer ( struct misdn_bchannel holded_bc  ) 

Definition at line 3080 of file isdn_lib.c.

References misdn_bchannel::holded.

03081 {
03082    holded_bc->holded=0;
03083 }

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

Definition at line 4158 of file isdn_lib.c.

References misdn_bchannel::addr, 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_stack::port, and misdn_bchannel::port.

Referenced by misdn_join_conf(), and misdn_write().

04159 {
04160    char buf[4096 + mISDN_HEADER_LEN];
04161    iframe_t *frm;
04162    int  r;
04163    struct misdn_stack *stack=get_stack_by_bc(bc);
04164 
04165    switch (bc->bc_state) {
04166       case BCHAN_ACTIVATED:
04167       case BCHAN_BRIDGED:
04168          break;
04169       default:
04170          cb_log(3, bc->port, "BC not yet activated (state:%s)\n",bc_state2str(bc->bc_state));
04171          return -1;
04172    }
04173    
04174    frm= (iframe_t*)buf;
04175    
04176    frm->prim = DL_DATA|REQUEST;
04177    frm->dinfo = 0;
04178    frm->addr = bc->addr | FLG_MSG_DOWN ;
04179    
04180    frm->len = len;
04181    memcpy(&buf[mISDN_HEADER_LEN], data,len);
04182       
04183    if ( misdn_cap_is_speech(bc->capability) ) 
04184       flip_buf_bits( &buf[mISDN_HEADER_LEN], len);
04185    else
04186       cb_log(6, stack->port, "Writing %d data bytes\n",len);
04187    
04188    cb_log(9, stack->port, "Writing %d bytes 2 mISDN\n",len);
04189    r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT);
04190    return 0;
04191 }

void misdn_send_lock ( struct misdn_bchannel bc  ) 

Definition at line 3270 of file isdn_lib.c.

References send_lock::lock, pthread_mutex_lock, and misdn_bchannel::send_lock.

Referenced by misdn_lib_send_event().

03271 {
03272    //cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid);
03273    if (bc->send_lock)
03274       pthread_mutex_lock(&bc->send_lock->lock);
03275 }

void misdn_send_unlock ( struct misdn_bchannel bc  ) 

Definition at line 3277 of file isdn_lib.c.

References send_lock::lock, pthread_mutex_unlock, and misdn_bchannel::send_lock.

Referenced by misdn_lib_send_event().

03278 {
03279    //cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid);
03280    if (bc->send_lock)
03281       pthread_mutex_unlock(&bc->send_lock->lock);
03282 }

void misdn_split_conf ( struct misdn_bchannel bc,
int  conf_id 
)

Definition at line 4508 of file isdn_lib.c.

References misdn_bchannel::addr, 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().

04509 {
04510    bc_state_change(bc,BCHAN_ACTIVATED);
04511    manager_ph_control(bc, CMX_RECEIVE_ON, 0);
04512    manager_ph_control(bc, CMX_CONF_SPLIT, conf_id);
04513 
04514    cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id);
04515 }

void misdn_tx_jitter ( struct misdn_bchannel bc,
int  len 
)

Definition at line 2238 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_bchannel::bframe, misdn_bchannel::bframe_len, cb_jb_empty, cb_log, misdn_bchannel::channel, flip_buf_bits(), misdn_lib::midev, misdn_bchannel::port, and tone_silence_flip.

Referenced by do_tone(), and handle_bchan().

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

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

Definition at line 3122 of file isdn_lib.c.

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

Referenced by misdn_lib_get_free_bc().

03123 {
03124    bc->channel = channel;
03125    bc->channel_preselected = channel?1:0;
03126    bc->in_use = 1;
03127    bc->need_disconnect=1;
03128    bc->need_release=1;
03129    bc->need_release_complete=1;
03130    bc->cause=16;
03131 
03132    if (++mypid>5000) mypid=1;
03133    bc->pid=mypid;
03134 
03135 #if 0
03136    bc->addr=0;
03137    bc->b_stid=0;
03138    bc->layer_id=0;
03139 #endif
03140 }

int queue_cleanup_bc ( struct misdn_bchannel bc  ) 

Definition at line 3698 of file isdn_lib.c.

References misdn_lib::activatequeue, cb_log, misdn_bchannel::l3_id, misdn_lib::new_msg, and misdn_bchannel::port.

03699 {
03700    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03701    iframe_t *frm;
03702    if (!msg) {
03703       cb_log(0, bc->port, "misgn_lib_get_port: alloc_msg failed!\n");
03704       return -1;
03705    }
03706    frm=(iframe_t*)msg->data;
03707 
03708    /* activate bchannel */
03709    frm->prim = MGR_CLEARSTACK| REQUEST;
03710 
03711    frm->addr = bc->l3_id;
03712 
03713    frm->dinfo = bc->port;
03714    frm->len = 0;
03715   
03716    msg_queue_tail(&glob_mgr->activatequeue, msg);
03717    sem_post(&glob_mgr->new_msg);
03718 
03719    return 0; 
03720 
03721 }

int release_cr ( struct misdn_stack stack,
mISDNuser_head_t *  hh 
)

removing procid

Definition at line 1780 of file isdn_lib.c.

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

Referenced by handle_event_nt().

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

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

Definition at line 383 of file isdn_lib.c.

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

Referenced by manager_event_handler().

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

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

Definition at line 456 of file isdn_lib.c.

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

Referenced by find_free_chan_in_stack(), and handle_frm().

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

int setup_bc ( struct misdn_bchannel bc  ) 

Definition at line 952 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_stack::b_num, misdn_bchannel::b_stid, misdn_stack::b_stids, misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), bc_state_change(), BCHAN_ACTIVATED, BCHAN_CLEANED, BCHAN_ERROR, cb_event, cb_log, misdn_bchannel::channel, errno, EVENT_BCHAN_ERROR, get_stack_by_bc(), misdn_bchannel::hdlc, ISDN_PID_L3_B_USER, ISDN_PID_L4_B_USER, misdn_bchannel::layer, misdn_bchannel::layer_id, manager_bchannel_activate(), misdn_stack::midev, misdn_bchannel::nodsp, misdn_stack::port, misdn_bchannel::port, and misdn_lib::user_data.

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

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

void stack_destroy ( struct misdn_stack stack  ) 

Definition at line 1377 of file isdn_lib.c.

References misdn_stack::lower_id, misdn_stack::midev, misdn_stack::nst, misdn_stack::nt, and misdn_stack::upper_id.

Referenced by misdn_lib_destroy().

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

void stack_holder_add ( struct misdn_stack stack,
struct misdn_bchannel holder 
)

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

04282 {
04283    struct misdn_bchannel *help;
04284    cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id);
04285    
04286    holder->stack_holder=1;
04287 
04288    if (!stack ) return ;
04289    
04290    holder->next=NULL;
04291    
04292    if (!stack->holding) {
04293       stack->holding = holder;
04294       return;
04295    }
04296   
04297    for (help=stack->holding;
04298         help;
04299         help=help->next) {
04300       if (!help->next) {
04301          help->next=holder;
04302          break;
04303       }
04304    }
04305   
04306 }

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

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

04357 {
04358    struct misdn_bchannel *help;
04359 
04360    cb_log(4,stack?stack->port:0, "*HOLDER: find %x\n",l3id);
04361    
04362    if (!stack) return NULL;
04363    
04364    for (help=stack->holding;
04365         help;
04366         help=help->next) {
04367       if (help->l3_id == l3id) {
04368          cb_log(4,stack->port, "*HOLDER: found bc\n");
04369          return help;
04370       }
04371    }
04372 
04373    cb_log(4,stack->port, "*HOLDER: find nothing\n");
04374    return NULL;
04375 }

struct misdn_bchannel * stack_holder_find_bychan ( struct misdn_stack stack,
int  chan 
) [read]

Definition at line 4334 of file isdn_lib.c.

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

04335 {
04336    struct misdn_bchannel *help;
04337 
04338    cb_log(4,stack?stack->port:0, "*HOLDER: find_bychan %c\n", chan);
04339    
04340    if (!stack) return NULL;
04341    
04342    for (help=stack->holding;
04343         help;
04344         help=help->next) {
04345       if (help->channel == chan) {
04346          cb_log(4,stack->port, "*HOLDER: found_bychan bc\n");
04347          return help;
04348       }
04349    }
04350 
04351    cb_log(4,stack->port, "*HOLDER: find_bychan nothing\n");
04352    return NULL;
04353 
04354 }

void stack_holder_remove ( struct misdn_stack stack,
struct misdn_bchannel holder 
)

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

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

struct misdn_stack * stack_init ( int  midev,
int  port,
int  ptp 
) [read]

Definition at line 1192 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::b_stids, cb_log, misdn_stack::channels, misdn_stack::d_stid, misdn_stack::downqueue, handle_event_nt(), misdn_stack::holding, misdn_stack::l1link, misdn_stack::l2link, misdn_stack::lower_id, malloc, MAX_BCHANS, misdn_stack::mgr, misdn_stack::midev, misdn_lib_get_l1_up(), misdn_lib_get_l2_up(), misdn_lib_get_short_status(), misdn_stack::nst, misdn_stack::nt, misdn_stack::port, misdn_stack::pri, misdn_stack::ptp, misdn_stack::upper_id, and misdn_stack::upqueue.

Referenced by misdn_lib_init().

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

void te_lib_destroy ( int  midev  ) 

Definition at line 3068 of file isdn_lib.c.

References cb_log, and entity.

Referenced by misdn_lib_destroy().

03069 {
03070    char buf[1024];
03071    mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC);
03072 
03073    cb_log(4, 0, "Entetity deleted\n");
03074    mISDN_close(midev);
03075    cb_log(4, 0, "midev closed\n");
03076 }

int te_lib_init (  ) 

App Interface

Definition at line 3039 of file isdn_lib.c.

References entity, errno, and misdn_lib::midev.

Referenced by misdn_lib_init().

03039                   {
03040    char buff[1025];
03041    iframe_t *frm=(iframe_t*)buff;
03042    int midev=mISDN_open();
03043    int ret;
03044 
03045    memset(buff,0,1025);
03046   
03047    if  (midev<=0) return midev;
03048   
03049 /* create entity for layer 3 TE-mode */
03050    mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
03051    ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC);
03052   
03053    if (ret < mISDN_HEADER_LEN) {
03054    noentity:
03055       fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n",strerror(errno));
03056       exit(-1);
03057    }
03058   
03059    entity = frm->dinfo & 0xffff ;
03060   
03061    if (!entity)
03062       goto noentity;
03063 
03064    return midev;
03065   
03066 }

static int test_inuse ( struct misdn_bchannel bc  )  [static]

Definition at line 3108 of file isdn_lib.c.

References misdn_bchannel::b_stid, cb_log, misdn_bchannel::in_use, misdn_bchannel::last_used, and misdn_bchannel::port.

Referenced by misdn_lib_get_free_bc().

03109 {
03110    struct timeval now;
03111    gettimeofday(&now, NULL);
03112    if (!bc->in_use) {
03113       if (bc->last_used.tv_sec < now.tv_sec) {
03114          cb_log(0,bc->port, "channel with stid:%x for one second still in use!\n", bc->b_stid);
03115          return 1;
03116       }
03117    }
03118    return 0;
03119 }


Variable Documentation

int entity [static]

Definition at line 227 of file isdn_lib.c.

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

char flip_table[256] [static]

Definition at line 292 of file isdn_lib.c.

Referenced by flip_buf_bits(), and init_flip_bits().

struct misdn_lib* glob_mgr [static]

Definition at line 229 of file isdn_lib.c.

enum global_states global_state = MISDN_INITIALIZING [static]

Definition at line 160 of file isdn_lib.c.

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

Definition at line 3812 of file isdn_lib.c.

struct isdn_msg msgs_g[]

int mypid = 1 [static]

Definition at line 408 of file isdn_lib.c.

Referenced by prepare_bc().

int newteid = 0 [static]

Definition at line 763 of file isdn_lib.c.

Referenced by create_process().

int nt_err_cnt = 0 [static]

Definition at line 153 of file isdn_lib.c.

Referenced by handle_frm_nt().

char tone_425_flip[TONE_425_SIZE]

Definition at line 231 of file isdn_lib.c.

Referenced by misdn_lib_init().

char tone_silence_flip[TONE_SILENCE_SIZE]

Definition at line 232 of file isdn_lib.c.

Referenced by misdn_lib_init(), and misdn_tx_jitter().


Generated on Tue Sep 30 01:19:59 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.6