Fri Jul 3 20:38:35 2009

Asterisk developer's documentation


isdn_lib.c File Reference

Interface to mISDN. More...

#include <syslog.h>
#include <sys/time.h>
#include <mISDNuser/isdn_debug.h>
#include "isdn_lib_intern.h"
#include "isdn_lib.h"
#include "asterisk/causes.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 ARRAY_LEN(a)   (sizeof(a) / sizeof(a[0]))
#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 const char * fac2str (enum FacFunction facility)
static msg_t * fetch_msg (int midev)
static struct misdn_bchannel * find_bc_by_addr (unsigned long addr)
static struct misdn_bchannel * find_bc_by_channel (int port, int channel)
struct misdn_bchannel * find_bc_by_confid (unsigned long confid)
struct misdn_bchannel * find_bc_by_l3id (struct misdn_stack *stack, unsigned long l3id)
static struct misdn_bchannel * find_bc_by_masked_l3id (struct misdn_stack *stack, unsigned long l3id, unsigned long mask)
static struct misdn_bchannel * find_bc_holded (struct misdn_stack *stack)
static int find_free_chan_in_stack (struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec)
static struct misdn_stack * find_stack_by_addr (int addr)
static struct misdn_stack * find_stack_by_mgr (manager_t *mgr_nt)
static struct misdn_stack * find_stack_by_port (int port)
static char * flip_buf_bits (char *buf, int len)
struct misdn_stack * get_misdn_stack (void)
void get_show_stack_details (int port, char *buf)
struct misdn_stack * get_stack_by_bc (struct misdn_bchannel *bc)
static int handle_bchan (msg_t *msg)
static int handle_cr (struct misdn_stack *stack, iframe_t *frm)
static int handle_err (msg_t *msg)
static int handle_event (struct misdn_bchannel *bc, enum event_e event, iframe_t *frm)
static int handle_event_nt (void *dat, void *arg)
static int handle_frm (msg_t *msg)
static int handle_frm_nt (msg_t *msg)
static int handle_l1 (msg_t *msg)
static int handle_l2 (msg_t *msg)
static int handle_mgmt (msg_t *msg)
static int handle_timers (msg_t *msg)
static int init_bc (struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, int port, int bidx, char *msn, int firsttime)
static void init_flip_bits (void)
void isdn_lib_stop_dtmf (struct misdn_bchannel *bc)
void isdn_lib_update_ec (struct misdn_bchannel *bc)
void isdn_lib_update_rxgain (struct misdn_bchannel *bc)
void isdn_lib_update_txgain (struct misdn_bchannel *bc)
void manager_bchannel_activate (struct misdn_bchannel *bc)
void manager_bchannel_cleanup (struct misdn_bchannel *bc)
void manager_bchannel_deactivate (struct misdn_bchannel *bc)
void manager_bchannel_setup (struct misdn_bchannel *bc)
void manager_clean_bc (struct misdn_bchannel *bc)
void manager_ec_disable (struct misdn_bchannel *bc)
void manager_ec_enable (struct misdn_bchannel *bc)
static void manager_event_handler (void *arg)
struct misdn_bchannel * manager_find_bc_by_pid (int pid)
struct misdn_bchannel * manager_find_bc_holded (struct misdn_bchannel *bc)
char * manager_isdn_get_info (enum event_e event)
int manager_isdn_handler (iframe_t *frm, msg_t *msg)
void manager_ph_control (struct misdn_bchannel *bc, int c1, int c2)
void manager_ph_control_block (struct misdn_bchannel *bc, int c1, void *c2, int c2_len)
int misdn_cap_is_speech (int cap)
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)
void misdn_lib_echo (struct misdn_bchannel *bc, int onoff)
struct misdn_bchannel * misdn_lib_get_free_bc (int port, int channel, int inout, int dec)
static int misdn_lib_get_l1_down (struct misdn_stack *stack)
static int misdn_lib_get_l1_up (struct misdn_stack *stack)
static int misdn_lib_get_l2_down (struct misdn_stack *stack)
int misdn_lib_get_l2_up (struct misdn_stack *stack)
int misdn_lib_get_maxchans (int port)
int misdn_lib_get_port_down (int port)
int misdn_lib_get_port_info (int port)
int misdn_lib_get_port_up (int port)
static int misdn_lib_get_short_status (struct misdn_stack *stack)
int misdn_lib_init (char *portlist, struct misdn_lib_iface *iface, void *user_data)
int misdn_lib_is_port_blocked (int port)
int misdn_lib_is_ptp (int port)
static void misdn_lib_isdn_event_catcher (void *arg)
void misdn_lib_isdn_l1watcher (int port)
void misdn_lib_log_ies (struct misdn_bchannel *bc)
int misdn_lib_maxports_get (void)
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)
static void misdn_make_dummy (struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel)
static void misdn_send_lock (struct misdn_bchannel *bc)
static 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)
static void stack_destroy (struct misdn_stack *stack)
void stack_holder_add (struct misdn_stack *stack, struct misdn_bchannel *holder)
struct misdn_bchannel * stack_holder_find (struct misdn_stack *stack, unsigned long l3id)
struct misdn_bchannel * stack_holder_find_bychan (struct misdn_stack *stack, int chan)
void stack_holder_remove (struct misdn_stack *stack, struct misdn_bchannel *holder)
static struct misdn_stack * stack_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_lib * glob_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]


Detailed Description

Interface to mISDN.

Author:
Christian Richter <crich@beronet.com>

Definition in file isdn_lib.c.


Define Documentation

#define ARRAY_LEN ( a   )     (sizeof(a) / sizeof(a[0]))

Definition at line 32 of file isdn_lib.c.

#define ECHOCAN_OFF   124

Definition at line 207 of file isdn_lib.c.

Referenced by manager_ec_disable().

#define ECHOCAN_ON   123

Definition at line 206 of file isdn_lib.c.

Referenced by manager_ec_enable().

#define ISDN_PID_L3_B_USER   0x430000ff

Definition at line 229 of file isdn_lib.c.

Referenced by setup_bc().

#define ISDN_PID_L4_B_USER   0x440000ff

Definition at line 230 of file isdn_lib.c.

Referenced by setup_bc().

#define MAXPROCS   0x100

Definition at line 774 of file isdn_lib.c.

Referenced by create_process().

#define MISDN_DEBUG   0

Definition at line 210 of file isdn_lib.c.

#define MISDN_DSP

#define MISDN_GEN_SILENCE

#define MISDN_IBUF_SIZE   512

Definition at line 233 of file isdn_lib.c.

Referenced by init_bc().

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

Definition at line 3327 of file isdn_lib.c.

Referenced by misdn_lib_send_event().

#define TONE_ALERT_CNT   41

Definition at line 236 of file isdn_lib.c.

#define TONE_ALERT_SILENCE_CNT   200

Definition at line 237 of file isdn_lib.c.

#define TONE_BUSY_CNT   20

Definition at line 239 of file isdn_lib.c.

#define TONE_BUSY_SILENCE_CNT   48

Definition at line 240 of file isdn_lib.c.


Enumeration Type Documentation

Enumerator:
MISDN_INITIALIZING 
MISDN_INITIALIZED 

Definition at line 169 of file isdn_lib.c.

00169                    {
00170    MISDN_INITIALIZING,
00171    MISDN_INITIALIZED
00172 } ;


Function Documentation

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

Definition at line 611 of file isdn_lib.c.

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

Referenced by misdn_lib_bridge().

00612 {
00613    cb_log(5,bc->port,"BC_NEXT_STATE_CHANGE: from:%s to:%s\n",
00614           bc_state2str(bc->next_bc_state),
00615           bc_state2str(state) );
00616 
00617    bc->next_bc_state=state;
00618 }

char* bc_state2str ( enum bchannel_state  state  ) 

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

00562                                               {
00563    int i;
00564    
00565    struct bchan_state_s {
00566       char *n;
00567       enum bchannel_state s;
00568    } states[] = {
00569       {"BCHAN_CLEANED", BCHAN_CLEANED },
00570       {"BCHAN_EMPTY", BCHAN_EMPTY},
00571       {"BCHAN_SETUP", BCHAN_SETUP},
00572       {"BCHAN_SETUPED", BCHAN_SETUPED},
00573       {"BCHAN_ACTIVE", BCHAN_ACTIVE},
00574       {"BCHAN_ACTIVATED", BCHAN_ACTIVATED},
00575       {"BCHAN_BRIDGE",  BCHAN_BRIDGE},
00576       {"BCHAN_BRIDGED", BCHAN_BRIDGED},
00577       {"BCHAN_RELEASE", BCHAN_RELEASE},
00578       {"BCHAN_RELEASED", BCHAN_RELEASED},
00579       {"BCHAN_CLEAN", BCHAN_CLEAN},
00580       {"BCHAN_CLEAN_REQUEST", BCHAN_CLEAN_REQUEST},
00581       {"BCHAN_ERROR", BCHAN_ERROR}
00582    };
00583    
00584    for (i=0; i< sizeof(states)/sizeof(struct bchan_state_s); i++)
00585       if ( states[i].s == state)
00586          return states[i].n;
00587 
00588    return "UNKNOWN";
00589 }

void bc_state_change ( struct misdn_bchannel *  bc,
enum bchannel_state  state 
)

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

00592 {
00593    cb_log(5,bc->port,"BC_STATE_CHANGE: l3id:%x from:%s to:%s\n",
00594       bc->l3_id,
00595           bc_state2str(bc->bc_state),
00596           bc_state2str(state) );
00597    
00598    switch (state) {
00599       case BCHAN_ACTIVATED:
00600          if (bc->next_bc_state ==  BCHAN_BRIDGED) {
00601             misdn_join_conf(bc, bc->conf_id);
00602             bc->next_bc_state = BCHAN_EMPTY;
00603             return;
00604          }
00605       default:
00606          bc->bc_state=state;
00607          break;
00608    }
00609 }

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

References INFO_CAPABILITY_AUDIO_3_1K, INFO_CAPABILITY_DIGITAL_RESTRICTED, INFO_CAPABILITY_DIGITAL_UNRESTRICTED, and INFO_CAPABILITY_SPEECH.

Referenced by misdn_lib_log_ies().

00275                                  {
00276    static char *bearers[]={
00277       "Speech",
00278       "Audio 3.1k",
00279       "Unres Digital",
00280       "Res Digital",
00281       "Unknown Bearer"
00282    };
00283    
00284    switch (cap) {
00285    case INFO_CAPABILITY_SPEECH:
00286       return bearers[0];
00287       break;
00288    case INFO_CAPABILITY_AUDIO_3_1K:
00289       return bearers[1];
00290       break;
00291    case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:
00292       return bearers[2];
00293       break;
00294    case INFO_CAPABILITY_DIGITAL_RESTRICTED:
00295       return bearers[3];
00296       break;
00297    default:
00298       return bearers[4];
00299       break;
00300    }
00301 }

static int clean_up_bc ( struct misdn_bchannel *  bc  )  [static]

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

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

static void clear_l3 ( struct misdn_stack *  stack  )  [static]

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

00757 {
00758    int i;
00759 
00760    for (i=0; i<=stack->b_num; i++) {
00761       if (global_state == MISDN_INITIALIZED)  {
00762          cb_event(EVENT_CLEANUP, &stack->bc[i], NULL); 
00763          empty_chan_in_stack(stack,i+1);
00764          empty_bc(&stack->bc[i]);
00765          clean_up_bc(&stack->bc[i]);
00766          stack->bc[i].in_use = 0;
00767       }
00768       
00769    } 
00770 }

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

Definition at line 334 of file isdn_lib.c.

Referenced by misdn_lib_get_l2_down(), and misdn_lib_get_l2_up().

00335 {
00336    int i = 0;
00337    msg_t *dmsg;
00338   
00339    while(i < 10)
00340    {
00341       dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
00342       if (dmsg)
00343          return(dmsg);
00344       
00345       if (!i)
00346          printf("cannot allocate memory, trying again...\n");
00347       i++;
00348       usleep(300000);
00349    }
00350    printf("cannot allocate memory, system overloaded.\n");
00351    exit(-1);
00352 }

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

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

00357 {
00358    int i = 0;
00359    msg_t *dmsg;
00360    Q931_info_t *qi;
00361    iframe_t *frm;
00362   
00363    if (!ntmode)
00364       size = sizeof(Q931_info_t)+2;
00365   
00366    while(i < 10) {
00367       if (ntmode) {
00368          dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
00369          if (dmsg) {
00370             return(dmsg);
00371          }
00372       } else {
00373          dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
00374          if (dmsg)
00375          {
00376             memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
00377             frm = (iframe_t *)dmsg->data;
00378             frm->prim = prim;
00379             frm->dinfo = dinfo;
00380             qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
00381             qi->type = mt;
00382             return(dmsg);
00383          }
00384       }
00385     
00386       if (!i) printf("cannot allocate memory, trying again...\n");
00387       i++;
00388       usleep(300000);
00389    }
00390    printf("cannot allocate memory, system overloaded.\n");
00391    exit(-1);
00392 }

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

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

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

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

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

02206 {
02207    bc->tone_cnt=len;
02208    
02209    if (bc->generate_tone) {
02210       cb_event(EVENT_TONE_GENERATE, bc, glob_mgr->user_data);
02211       
02212       if ( !bc->nojitter ) {
02213          misdn_tx_jitter(bc,len);
02214       }
02215       
02216       return 1;
02217    }
02218    
02219    return 0;
02220 }

static void dump_chan_list ( struct misdn_stack *  stack  )  [static]

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

00450 {
00451    int i;
00452 
00453    for (i=0; i <= stack->b_num; i++) {
00454       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);
00455    }
00456 }

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

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

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

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

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

00550 {
00551    if (channel<=0 || channel>MAX_BCHANS) {
00552       cb_log(0,stack?stack->port:0, "empty_chan_in_stack: cannot empty channel %d\n",channel);
00553       return -1;
00554    }
00555    
00556    cb_log (4, stack?stack->port:0, "empty_chan_in_stack: %d\n",channel); 
00557    stack->channels[channel-1] = 0;
00558    dump_chan_list(stack);
00559    return 0;
00560 }

static const char* fac2str ( enum FacFunction  facility  )  [static]

Definition at line 3259 of file isdn_lib.c.

References ARRAY_LEN, and name.

Referenced by misdn_lib_log_ies().

03260 {
03261    static const struct { 
03262       enum FacFunction facility; 
03263       char *name;
03264    } arr[] = {
03265 /* *INDENT-OFF* */
03266       { Fac_None, "Fac_None" },
03267       { Fac_GetSupportedServices, "Fac_GetSupportedServices" },
03268       { Fac_Listen, "Fac_Listen" },
03269       { Fac_Suspend, "Fac_Suspend" },
03270       { Fac_Resume, "Fac_Resume" },
03271       { Fac_CFActivate, "Fac_CFActivate" },
03272       { Fac_CFDeactivate, "Fac_CFDeactivate" },
03273       { Fac_CFInterrogateParameters, "Fac_CFInterrogateParameters" },
03274       { Fac_CFInterrogateNumbers, "Fac_CFInterrogateNumbers" },
03275       { Fac_CD, "Fac_CD" },
03276       { Fac_AOCDCurrency, "Fac_AOCDCurrency" },
03277       { Fac_AOCDChargingUnit, "Fac_AOCDChargingUnit" },
03278 /* *INDENT-ON* */
03279    };
03280    
03281    unsigned index;
03282    
03283    for (index = 0; index < ARRAY_LEN(arr); ++index) {
03284       if (arr[index].facility == facility) {
03285          return arr[index].name;
03286       }
03287    }  /* end for */
03288 
03289    return "unknown";
03290 }  /* end fac2str() */

static msg_t* fetch_msg ( int  midev  )  [static]

Definition at line 2959 of file isdn_lib.c.

References cb_log, and errno.

Referenced by misdn_lib_isdn_event_catcher().

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

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

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

01474 {
01475    struct misdn_stack* stack;
01476    int i;
01477 
01478    for (stack=glob_mgr->stack_list;
01479         stack;
01480         stack=stack->next) {
01481       for (i=0; i<=stack->b_num; i++) {
01482          if ( (stack->bc[i].addr&STACK_ID_MASK)==(addr&STACK_ID_MASK) ||  stack->bc[i].layer_id== addr ) {
01483             return &stack->bc[i];
01484          }
01485       }
01486    }
01487    
01488    return NULL;
01489 }

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

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

01510 {
01511    struct misdn_stack* stack=find_stack_by_port(port);
01512    int i;
01513 
01514    if (!stack) return NULL;   
01515    
01516    for (i=0; i<=stack->b_num; i++) {
01517       if ( stack->bc[i].channel== channel ) {
01518          return &stack->bc[i];
01519       }
01520    }
01521       
01522    return NULL;
01523 }

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

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

01492 {
01493    struct misdn_stack* stack;
01494    int i;
01495    
01496    for (stack=glob_mgr->stack_list;
01497         stack;
01498         stack=stack->next) {
01499       for (i=0; i<=stack->b_num; i++) {
01500          if ( stack->bc[i].conf_id==confid ) {
01501             return &stack->bc[i];
01502          }
01503       }
01504    }
01505    return NULL;
01506 }

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

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

01455 {
01456    int i;
01457    for (i=0; i<=stack->b_num; i++) {
01458       if (stack->bc[i].l3_id == l3id) return &stack->bc[i] ;
01459    }
01460    return stack_holder_find(stack,l3id);
01461 }

static struct misdn_bchannel* find_bc_by_masked_l3id ( struct misdn_stack *  stack,
unsigned long  l3id,
unsigned long  mask 
) [static, 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_event_nt().

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

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

Definition at line 1463 of file isdn_lib.c.

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

Referenced by manager_find_bc_holded().

01464 {
01465    int i;
01466    for (i=0; i<=stack->b_num; i++) {
01467       if (stack->bc[i].holded ) return &stack->bc[i] ;
01468    }
01469    return NULL;
01470 }

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

Definition at line 490 of file isdn_lib.c.

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

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

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

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

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

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

Definition at line 1432 of file isdn_lib.c.

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

Referenced by handle_event_nt().

01433 {
01434    struct misdn_stack *stack;
01435   
01436    for (stack=glob_mgr->stack_list;
01437         stack;
01438         stack=stack->next) 
01439       if ( &stack->mgr == mgr_nt) return stack;
01440   
01441    return NULL;
01442 }

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

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

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

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

Definition at line 319 of file isdn_lib.c.

References flip_table.

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

00320 {
00321    int i;
00322    char * start = buf;
00323    
00324    for (i = 0 ; i < len; i++) {
00325       buf[i] = flip_table[(unsigned char)buf[i]];
00326    }
00327    
00328    return start;
00329 }

struct misdn_stack * get_misdn_stack ( void   )  [read]

void get_show_stack_details ( int  port,
char *  buf 
)

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

00149 {
00150    struct misdn_stack *stack=get_misdn_stack();
00151    
00152    for ( ; stack; stack=stack->next) {
00153       if (stack->port == port) break;
00154    }
00155    
00156    if (stack) {
00157       sprintf(buf, "* Port %d Type %s Prot. %s L2Link %s L1Link:%s Blocked:%d",
00158          stack->port, stack->nt ? "NT" : "TE", stack->ptp ? "PTP" : "PMP",
00159          stack->l2link ? "UP" : "DOWN", stack->l1link ? "UP" : "DOWN",
00160          stack->blocked);
00161    } else {
00162       buf[0]=0;
00163    }
00164 }

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

static int handle_bchan ( msg_t *  msg  )  [static]

Anyway flip the bufbits

Definition at line 2309 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_bchannel::b_stid, misdn_stack::bc, misdn_bchannel::bc_state, bc_state2str(), bc_state_change(), BCHAN_ACTIVATED, BCHAN_CLEAN_REQUEST, BCHAN_SETUP, BCHAN_SETUPED, misdn_bchannel::bframe, misdn_bchannel::bframe_len, misdn_bchannel::capability, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), misdn_bchannel::dad, misdn_bchannel::dnumplan, do_tone(), misdn_bchannel::dtmf, errno, EVENT_BCHAN_DATA, EVENT_DTMF_TONE, find_bc_by_addr(), flip_buf_bits(), get_stack_by_bc(), misdn_bchannel::layer, misdn_stack::midev, misdn_cap_is_speech(), misdn_tx_jitter(), misdn_bchannel::nojitter, misdn_bchannel::oad, misdn_bchannel::onumplan, misdn_bchannel::pid, misdn_stack::port, misdn_bchannel::port, t, and misdn_lib::user_data.

Referenced by handle_err(), and manager_isdn_handler().

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

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

Definition at line 1612 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, misdn_lib_get_free_bc(), misdn_make_dummy(), 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().

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

static int handle_err ( msg_t *  msg  )  [static]

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

03564 {
03565    iframe_t *frm = (iframe_t*) msg->data;
03566 
03567 
03568    if (!frm->addr) {
03569       static int cnt=0;
03570       if (!cnt)
03571          cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo);
03572       cnt++;
03573       if (cnt>100) {
03574          cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo);
03575          cnt=0;
03576       }
03577       
03578       free_msg(msg);
03579       return 1;
03580       
03581    }
03582    
03583    switch (frm->prim) {
03584       case MGR_SETSTACK|INDICATION:
03585          return handle_bchan(msg);
03586       break;
03587 
03588       case MGR_SETSTACK|CONFIRM:
03589       case MGR_CLEARSTACK|CONFIRM:
03590          free_msg(msg) ; 
03591          return 1;
03592       break;
03593 
03594       case DL_DATA|CONFIRM:
03595          cb_log(4,0,"DL_DATA|CONFIRM\n");
03596          free_msg(msg);
03597          return 1;
03598 
03599       case PH_CONTROL|CONFIRM:
03600          cb_log(4,0,"PH_CONTROL|CONFIRM\n");
03601          free_msg(msg);
03602          return 1;
03603 
03604       case DL_DATA|INDICATION:
03605       {
03606          int port=(frm->addr&MASTER_ID_MASK) >> 8;
03607          int channel=(frm->addr&CHILD_ID_MASK) >> 16;
03608          struct misdn_bchannel *bc;
03609 
03610          /*we flush the read buffer here*/
03611          
03612          cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel);
03613          
03614          free_msg(msg); 
03615          return 1;
03616          
03617          
03618          bc = find_bc_by_channel(port, channel);
03619 
03620          if (!bc) {
03621             struct misdn_stack *stack = find_stack_by_port(port);
03622 
03623             if (!stack) {
03624                cb_log(0,0," --> stack not found\n");
03625                free_msg(msg);
03626                return 1;
03627             }
03628             
03629             cb_log(0,0," --> bc not found by channel\n");
03630             if (stack->l2link)
03631                misdn_lib_get_l2_down(stack);
03632 
03633             if (stack->l1link)
03634                misdn_lib_get_l1_down(stack);
03635 
03636             free_msg(msg);
03637             return 1;
03638          }
03639          
03640          cb_log(3,port," --> BC in state:%s\n", bc_state2str(bc->bc_state));
03641       }
03642    }
03643 
03644    return 0;
03645 }

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

NT MODE

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

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

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

Definition at line 1824 of file isdn_lib.c.

References AST_CAUSE_USER_BUSY, 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_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, misdn_lib_get_free_bc(), misdn_lib_get_l2_up(), misdn_lib_reinit_nt_stack(), misdn_lib_send_event(), misdn_lib_send_restart(), misdn_make_dummy(), 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().

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

static int handle_frm ( msg_t *  msg  )  [static]

Preprocess some Events

Definition at line 2605 of file isdn_lib.c.

References AST_CAUSE_NORMAL_CLEARING, AST_CAUSE_REQUESTED_CHAN_UNAVAIL, 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_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, misdn_lib_send_event(), misdn_lib_send_restart(), misdn_make_dummy(), 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().

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

static int handle_frm_nt ( msg_t *  msg  )  [static]

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

02571 {
02572    iframe_t *frm= (iframe_t*)msg->data;
02573    struct misdn_stack *stack;
02574    int err=0;
02575 
02576    stack=find_stack_by_addr( frm->addr );
02577 
02578    
02579   
02580    if (!stack || !stack->nt) {
02581       return 0;
02582    }
02583 
02584    
02585    if ((err=stack->nst.l1_l2(&stack->nst,msg))) {
02586     
02587       if (nt_err_cnt > 0 ) {
02588          if (nt_err_cnt < 100) {
02589             nt_err_cnt++; 
02590             cb_log(0, stack->port, "NT Stack sends us error: %d \n", err);
02591          } else if (nt_err_cnt < 105){
02592             cb_log(0, stack->port, "NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err);
02593             nt_err_cnt = - 1; 
02594          }
02595       }
02596       free_msg(msg);
02597       return 1;
02598       
02599    }
02600    
02601    return 1;
02602 }

static int handle_l1 ( msg_t *  msg  )  [static]

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

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

static int handle_l2 ( msg_t *  msg  )  [static]

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

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

static int handle_mgmt ( msg_t *  msg  )  [static]

Definition at line 2877 of file isdn_lib.c.

References cb_log, clear_l3(), and find_stack_by_addr().

Referenced by manager_isdn_handler().

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

static int handle_timers ( msg_t *  msg  )  [static]

Definition at line 2140 of file isdn_lib.c.

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

Referenced by manager_isdn_handler().

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

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

IFACE

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

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

static void init_flip_bits ( void   )  [static]

Definition at line 306 of file isdn_lib.c.

References flip_table.

Referenced by misdn_lib_init().

00307 {
00308    int i,k;
00309    
00310    for (i = 0 ; i < 256 ; i++) {
00311       unsigned char sample = 0 ;
00312       for (k = 0; k<8; k++) {
00313          if ( i & 1 << k ) sample |= 0x80 >>  k;
00314       }
00315       flip_table[i] = sample;
00316    }
00317 }

void isdn_lib_stop_dtmf ( struct misdn_bchannel *  bc  ) 

Definition at line 4305 of file isdn_lib.c.

References manager_ph_control().

Referenced by process_ast_dsp().

04306 {
04307    manager_ph_control(bc, DTMF_TONE_STOP, 0);
04308 }

void isdn_lib_update_ec ( struct misdn_bchannel *  bc  ) 

Definition at line 4293 of file isdn_lib.c.

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

Referenced by process_ast_dsp().

04294 {
04295 #ifdef MISDN_1_2
04296    if (*bc->pipeline)
04297 #else
04298    if (bc->ec_enable)
04299 #endif
04300       manager_ec_enable(bc);
04301    else
04302       manager_ec_disable(bc);
04303 }

void isdn_lib_update_rxgain ( struct misdn_bchannel *  bc  ) 

Definition at line 4283 of file isdn_lib.c.

References manager_ph_control(), and misdn_bchannel::rxgain.

Referenced by process_ast_dsp().

04284 {
04285    manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
04286 }

void isdn_lib_update_txgain ( struct misdn_bchannel *  bc  ) 

Definition at line 4288 of file isdn_lib.c.

References manager_ph_control(), and misdn_bchannel::txgain.

Referenced by process_ast_dsp().

04289 {
04290    manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
04291 }

void manager_bchannel_activate ( struct misdn_bchannel *  bc  ) 

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

04167 {
04168    char buf[128];
04169 
04170    struct misdn_stack *stack=get_stack_by_bc(bc);
04171 
04172    if (!stack) {
04173       cb_log(0, bc->port, "bchannel_activate: Stack not found !");
04174       return ;
04175    }
04176    
04177    /* we must activate if we are deactivated */
04178    clear_ibuffer(bc->astbuf);
04179    
04180    cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr);
04181    
04182    mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN,  DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC);
04183 
04184    return ;
04185 }

void manager_bchannel_cleanup ( struct misdn_bchannel *  bc  ) 

void manager_bchannel_deactivate ( struct misdn_bchannel *  bc  ) 

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

04189 {
04190    struct misdn_stack *stack=get_stack_by_bc(bc);
04191    iframe_t dact;
04192    char buf[128]; 
04193 
04194    switch (bc->bc_state) {
04195       case BCHAN_ACTIVATED:
04196          break;
04197       case BCHAN_BRIDGED:
04198          misdn_split_conf(bc,bc->conf_id);
04199          break;
04200       default:
04201          cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n");
04202          return ;
04203 
04204    }
04205    
04206    cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr);
04207    
04208    bc->generate_tone=0;
04209    
04210    dact.prim = DL_RELEASE | REQUEST;
04211    dact.addr = bc->addr | FLG_MSG_DOWN;
04212    dact.dinfo = 0;
04213    dact.len = 0;
04214    mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC);
04215 
04216    clear_ibuffer(bc->astbuf);
04217    
04218    bc_state_change(bc,BCHAN_RELEASE);
04219   
04220    return;
04221 }

void manager_bchannel_setup ( struct misdn_bchannel *  bc  ) 

void manager_clean_bc ( struct misdn_bchannel *  bc  ) 

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

04333 {
04334    struct misdn_stack *stack=get_stack_by_bc(bc);
04335    
04336    if (bc->channel>0)
04337       empty_chan_in_stack(stack, bc->channel);
04338    empty_bc(bc);
04339    bc->in_use=0;
04340 
04341    cb_event(EVENT_CLEANUP, bc, NULL); 
04342 }

void manager_ec_disable ( struct misdn_bchannel *  bc  ) 

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

04522 {
04523    struct misdn_stack *stack=get_stack_by_bc(bc);
04524    
04525    cb_log(4, stack?stack->port:0," --> ec_disable\n");
04526 
04527    if (!misdn_cap_is_speech(bc->capability)) {
04528       cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n");
04529       return;
04530    }
04531 
04532 #ifdef MISDN_1_2
04533    manager_ph_control_block(bc, PIPELINE_CFG, "", 0);
04534 #else
04535    if ( ! bc->ec_enable) {
04536       cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n");
04537       manager_ph_control(bc,  ECHOCAN_OFF, 0);
04538    }
04539 #endif
04540 }

void manager_ec_enable ( struct misdn_bchannel *  bc  ) 

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

04473 {
04474    struct misdn_stack *stack=get_stack_by_bc(bc);
04475    
04476    cb_log(4, stack?stack->port:0,"ec_enable\n");
04477 
04478    if (!misdn_cap_is_speech(bc->capability)) {
04479       cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n");
04480    } else {
04481 
04482 #ifdef MISDN_1_2
04483    if (*bc->pipeline) {
04484       cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline);
04485       manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1);
04486    }
04487 #else
04488    int ec_arr[2];
04489 
04490    if (bc->ec_enable) {
04491       cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps);
04492    
04493       switch (bc->ec_deftaps) {
04494       case 4:
04495       case 8:
04496       case 16:
04497       case 32:
04498       case 64:
04499       case 128:
04500       case 256:
04501       case 512:
04502       case 1024:
04503          cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps);
04504          break;
04505       default:
04506          cb_log(0, stack->port, "Taps should be power of 2\n");
04507          bc->ec_deftaps=128;
04508       }
04509    
04510       ec_arr[0]=bc->ec_deftaps;
04511       ec_arr[1]=0;
04512       
04513       manager_ph_control_block(bc,  ECHOCAN_ON,  ec_arr, sizeof(ec_arr));
04514    }
04515 #endif
04516    }
04517 }

static void manager_event_handler ( void *  arg  )  [static]

wait for events

Handle L2/3 Signalling after bchans

Definition at line 3876 of file isdn_lib.c.

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

03877 {
03878    sem_post(&handler_started); 
03879    while (1) {
03880       struct misdn_stack *stack;
03881       msg_t *msg;
03882     
03883       /** wait for events **/
03884       sem_wait(&glob_mgr->new_msg);
03885     
03886       for (msg=msg_dequeue(&glob_mgr->activatequeue);
03887            msg;
03888            msg=msg_dequeue(&glob_mgr->activatequeue)
03889          )
03890       {
03891    
03892          iframe_t *frm =  (iframe_t*) msg->data ;
03893 
03894          switch ( frm->prim) {
03895 
03896          case MGR_CLEARSTACK | REQUEST:
03897             /*a queued bchannel cleanup*/
03898             {
03899                struct misdn_stack *stack=find_stack_by_port(frm->dinfo);
03900                struct misdn_bchannel *bc;
03901                if (!stack) {
03902                   cb_log(0,0,"no stack found with port [%d]!! so we cannot cleanup the bc\n",frm->dinfo);
03903                   free_msg(msg);
03904                   break;
03905                }
03906                
03907                bc = find_bc_by_l3id(stack, frm->addr);
03908                if (bc) {
03909                   cb_log(1,bc->port,"CLEARSTACK queued, cleaning up\n");
03910                   clean_up_bc(bc);
03911                } else {
03912                   cb_log(0,stack->port,"bc could not be cleaned correctly !! addr [%x]\n",frm->addr);
03913                }
03914             }
03915             free_msg(msg); 
03916             break;
03917          case MGR_SETSTACK | REQUEST :
03918             /* Warning: memory leak here if we get this message */
03919             break;
03920          default:
03921             mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
03922             free_msg(msg);
03923          }
03924       }
03925 
03926       for (stack=glob_mgr->stack_list;
03927            stack;
03928            stack=stack->next ) { 
03929 
03930          while ( (msg=msg_dequeue(&stack->upqueue)) ) {
03931             /** Handle L2/3 Signalling after bchans **/ 
03932             if (!handle_frm_nt(msg)) {
03933                /* Maybe it's TE */
03934                if (!handle_frm(msg)) {
03935                   /* wow none! */
03936                   cb_log(0,stack->port,"Wow we've got a strange issue while dequeueing a Frame\n");
03937                }
03938             }
03939          }
03940 
03941          /* Here we should check if we really want to 
03942             send all the messages we've queued, lets 
03943             assume we've queued a Disconnect, but 
03944             received it already from the other side!*/
03945            
03946          while ( (msg=msg_dequeue(&stack->downqueue)) ) {
03947             if (stack->nt ) {
03948                if (stack->nst.manager_l3(&stack->nst, msg))
03949                   cb_log(0, stack->port, "Error@ Sending Message in NT-Stack.\n");
03950      
03951             } else {
03952                iframe_t *frm = (iframe_t *)msg->data;
03953                struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo);
03954                if (bc)
03955                   send_msg(glob_mgr->midev, bc, msg);
03956                else  {
03957                   if (frm->dinfo == MISDN_ID_GLOBAL) {
03958                      struct misdn_bchannel dummybc;
03959                      misdn_make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0);
03960                      send_msg(glob_mgr->midev, &dummybc, msg);
03961                   }
03962                }
03963             }
03964          }
03965       }
03966    }
03967 }

struct misdn_bchannel * manager_find_bc_by_pid ( int  pid  )  [read]

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

03109 {
03110    struct misdn_stack *stack;
03111    int i;
03112   
03113    for (stack=glob_mgr->stack_list;
03114         stack;
03115         stack=stack->next) {
03116       for (i=0; i<=stack->b_num; i++)
03117          if (stack->bc[i].pid == pid) return &stack->bc[i];
03118    }
03119   
03120    return NULL;
03121 }

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

Definition at line 3123 of file isdn_lib.c.

References find_bc_holded(), and get_stack_by_bc().

03124 {
03125    struct misdn_stack *stack=get_stack_by_bc(bc);
03126    return find_bc_holded(stack);
03127 }

char* manager_isdn_get_info ( enum event_e  event  ) 

Definition at line 4161 of file isdn_lib.c.

References isdn_get_info(), and msgs_g.

Referenced by cb_events().

04162 {
04163    return isdn_get_info(msgs_g , event, 0);
04164 }

int manager_isdn_handler ( iframe_t *  frm,
msg_t *  msg 
)

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

03666 {  
03667 
03668    if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) {
03669       cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n");
03670    }
03671 
03672    if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) {
03673       static int unhandled_bmsg_count=1000;
03674       if (handle_bchan(msg)) {
03675          return 0 ;
03676       }
03677          
03678       if (unhandled_bmsg_count==1000) {
03679          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);     
03680          unhandled_bmsg_count=0;
03681       }
03682 
03683       unhandled_bmsg_count++;
03684       free_msg(msg);
03685       return 0;
03686    }  
03687 
03688 #ifdef RECV_FRM_SYSLOG_DEBUG
03689    syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo);
03690 #endif
03691 
03692    if (handle_timers(msg)) 
03693       return 0 ;
03694 
03695    
03696    if (handle_mgmt(msg)) 
03697       return 0 ; 
03698    
03699    if (handle_l2(msg)) 
03700       return 0 ;
03701 
03702    /* Its important to handle l1 AFTER l2  */
03703    if (handle_l1(msg)) 
03704       return 0 ;
03705    
03706    if (handle_frm_nt(msg)) {
03707       return 0;
03708    }
03709 
03710    if (handle_frm(msg)) {
03711       return 0;
03712    }
03713 
03714    if (handle_err(msg)) {
03715       return 0 ;
03716    }
03717 
03718    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);      
03719    free_msg(msg);
03720    
03721 
03722    return 0;
03723 }

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

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

04263 {
04264    unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)];
04265    iframe_t *ctrl = (iframe_t *)buffer; /* preload data */
04266    unsigned int *d = (unsigned int*)&ctrl->data.p;
04267    /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
04268    
04269    cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2);
04270    
04271    ctrl->prim = PH_CONTROL | REQUEST;
04272    ctrl->addr = bc->addr | FLG_MSG_DOWN;
04273    ctrl->dinfo = 0;
04274    ctrl->len = sizeof(unsigned int)*2;
04275    *d++ = c1;
04276    *d++ = c2;
04277    mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
04278 }

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

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

04314 {
04315    unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len];
04316    iframe_t *ctrl = (iframe_t *)buffer;
04317    unsigned int *d = (unsigned int *)&ctrl->data.p;
04318    /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
04319    
04320    ctrl->prim = PH_CONTROL | REQUEST;
04321    ctrl->addr = bc->addr | FLG_MSG_DOWN;
04322    ctrl->dinfo = 0;
04323    ctrl->len = sizeof(unsigned int) + c2_len;
04324    *d++ = c1;
04325    memcpy(d, c2, c2_len);
04326    mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
04327 }

int misdn_cap_is_speech ( int  cap  ) 

void misdn_dump_chanlist ( void   ) 

Definition at line 459 of file isdn_lib.c.

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

Referenced by misdn_show_cls().

00460 {
00461    struct misdn_stack *stack=get_misdn_stack();
00462    for ( ; stack; stack=stack->next) {
00463       dump_chan_list(stack);
00464    }
00465 
00466 }

int misdn_inband_avail ( struct misdn_bchannel *  bc  ) 

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

00430 {
00431 
00432    if (!bc->early_bconnect) {
00433       /* We have opted to never receive any available inband recorded messages */
00434       return 0;
00435    }
00436    
00437    switch (bc->progress_indicator) {
00438    case INFO_PI_INBAND_AVAILABLE:
00439    case INFO_PI_CALL_NOT_E2E_ISDN:
00440    case INFO_PI_CALLED_NOT_ISDN:
00441       return 1;
00442    default:
00443       return 0;
00444    }
00445    return 0;
00446 }

void misdn_join_conf ( struct misdn_bchannel *  bc,
int  conf_id 
)

Definition at line 4548 of file isdn_lib.c.

References misdn_bchannel::addr, bc_state_change(), BCHAN_BRIDGED, cb_log, manager_ph_control(), misdn_lib_tx2misdn_frm(), and misdn_bchannel::port.

Referenced by bc_state_change(), and misdn_lib_bridge().

04549 {
04550    char data[16] = "";
04551 
04552    bc_state_change(bc,BCHAN_BRIDGED);
04553    manager_ph_control(bc, CMX_RECEIVE_OFF, 0);
04554    manager_ph_control(bc, CMX_CONF_JOIN, conf_id);
04555 
04556    cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id);
04557 
04558    misdn_lib_tx2misdn_frm(bc, data, sizeof(data) - 1);
04559 }

void misdn_lib_bridge ( struct misdn_bchannel *  bc1,
struct misdn_bchannel *  bc2 
)

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

04572 {
04573    int conf_id = bc1->pid + 1;
04574    struct misdn_bchannel *bc_list[] = { bc1, bc2, NULL };
04575    struct misdn_bchannel **bc;
04576 
04577    cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port);
04578 
04579    for (bc=bc_list; *bc;  bc++) { 
04580       (*bc)->conf_id=conf_id;
04581       cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr);
04582    
04583       switch((*bc)->bc_state) {
04584          case BCHAN_ACTIVATED:
04585             misdn_join_conf(*bc,conf_id);
04586             break;
04587          default:
04588             bc_next_state_change(*bc,BCHAN_BRIDGED);
04589             break;
04590       }
04591    }
04592 }

void misdn_lib_destroy ( void   ) 

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

04129 {
04130    struct misdn_stack *help;
04131    int i;
04132   
04133    for ( help=glob_mgr->stack_list; help; help=help->next ) {
04134       for(i=0;i<=help->b_num; i++) {
04135          char buf[1024];
04136          mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
04137          help->bc[i].addr = 0;
04138       }
04139       cb_log (1, help->port, "Destroying this port.\n");
04140       stack_destroy(help);
04141    }
04142    
04143    if (global_state == MISDN_INITIALIZED) {
04144       cb_log(4, 0, "Killing Handler Thread\n");
04145       if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) {
04146          cb_log(4, 0, "Joining Handler Thread\n");
04147          pthread_join(glob_mgr->event_handler_thread, NULL);
04148       }
04149      
04150       cb_log(4, 0, "Killing Main Thread\n");
04151       if ( pthread_cancel(glob_mgr->event_thread) == 0 ) {
04152          cb_log(4, 0, "Joining Main Thread\n");
04153          pthread_join(glob_mgr->event_thread, NULL);
04154       }
04155    }
04156   
04157    cb_log(1, 0, "Closing mISDN device\n");
04158    te_lib_destroy(glob_mgr->midev);
04159 }

void misdn_lib_echo ( struct misdn_bchannel *  bc,
int  onoff 
)

Definition at line 4614 of file isdn_lib.c.

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

04615 {
04616    cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF");
04617    manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0);
04618 }

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

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

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

static int misdn_lib_get_l1_down ( struct misdn_stack *  stack  )  [static]

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

00777 {
00778    /* Pull Up L1 */ 
00779    iframe_t act;
00780    act.prim = PH_DEACTIVATE | REQUEST; 
00781    act.addr = stack->lower_id|FLG_MSG_DOWN;
00782    act.dinfo = 0;
00783    act.len = 0;
00784 
00785    cb_log(1, stack->port, "SENDING PH_DEACTIVATE | REQ\n");
00786    return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00787 }

static int misdn_lib_get_l1_up ( struct misdn_stack *  stack  )  [static]

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

00817 {
00818    /* Pull Up L1 */ 
00819    iframe_t act;
00820    act.prim = PH_ACTIVATE | REQUEST; 
00821    act.addr = (stack->upper_id | FLG_MSG_DOWN)  ;
00822 
00823    
00824    act.dinfo = 0;
00825    act.len = 0;
00826 
00827    return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00828 
00829 }

static int misdn_lib_get_l2_down ( struct misdn_stack *  stack  )  [static]

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

00791 {
00792    
00793    if (stack->ptp && (stack->nt) ) {
00794       msg_t *dmsg;
00795       /* L2 */
00796       dmsg = create_l2msg(DL_RELEASE| REQUEST, 0, 0);
00797       
00798       if (stack->nst.manager_l3(&stack->nst, dmsg))
00799          free_msg(dmsg);
00800       
00801    } else {
00802       iframe_t act;
00803       
00804       act.prim = DL_RELEASE| REQUEST;
00805       act.addr = (stack->upper_id |FLG_MSG_DOWN)  ;
00806       
00807       act.dinfo = 0;
00808       act.len = 0;
00809       return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00810    }
00811    
00812    return 0;
00813 }

int misdn_lib_get_l2_up ( struct misdn_stack *  stack  ) 

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

00832 {
00833    
00834    if (stack->ptp && (stack->nt) ) {
00835       msg_t *dmsg;
00836       /* L2 */
00837       dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0);
00838       
00839       if (stack->nst.manager_l3(&stack->nst, dmsg))
00840          free_msg(dmsg);
00841       
00842    } else {
00843       iframe_t act;
00844       
00845       act.prim = DL_ESTABLISH | REQUEST;
00846       act.addr = (stack->upper_id |FLG_MSG_DOWN)  ;
00847       
00848       act.dinfo = 0;
00849       act.len = 0;
00850       return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00851    }
00852    
00853    return 0;
00854 }

int misdn_lib_get_maxchans ( int  port  ) 

Definition at line 117 of file isdn_lib.c.

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

Referenced by misdn_request().

00118 {
00119    struct misdn_stack *stack=get_misdn_stack();
00120    for ( ; stack; stack=stack->next) {
00121       if (stack->port == port) {
00122          if (stack->pri) 
00123             return 30;
00124          else
00125             return 2;
00126       }
00127    }
00128    return -1;
00129 }

int misdn_lib_get_port_down ( int  port  ) 

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

01736 { /* Pull Down L1 */ 
01737    struct misdn_stack *stack;
01738    for (stack=glob_mgr->stack_list;
01739         stack;
01740         stack=stack->next) {
01741       if (stack->port == port) {
01742             if (stack->l2link)
01743                misdn_lib_get_l2_down(stack);
01744             misdn_lib_get_l1_down(stack);
01745          return 0;
01746       }
01747    }
01748    return 0;
01749 }

int misdn_lib_get_port_info ( int  port  ) 

Definition at line 3728 of file isdn_lib.c.

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

03729 {
03730    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03731    iframe_t *frm;
03732    struct misdn_stack *stack=find_stack_by_port(port);
03733    if (!msg) {
03734       cb_log(0, port, "misdn_lib_get_port_info: alloc_msg failed!\n");
03735       return -1;
03736    }
03737    frm=(iframe_t*)msg->data;
03738    if (!stack ) {
03739       cb_log(0, port, "There is no Stack for this port.\n");
03740       return -1;
03741    }
03742    /* activate bchannel */
03743    frm->prim = CC_STATUS_ENQUIRY | REQUEST;
03744 
03745    frm->addr = stack->upper_id| FLG_MSG_DOWN;
03746 
03747    frm->dinfo = 0;
03748    frm->len = 0;
03749   
03750    msg_queue_tail(&glob_mgr->activatequeue, msg);
03751    sem_post(&glob_mgr->new_msg);
03752 
03753   
03754    return 0; 
03755 }

int misdn_lib_get_port_up ( int  port  ) 

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

01714 { /* Pull Up L1 */ 
01715    struct misdn_stack *stack;
01716    
01717    for (stack=glob_mgr->stack_list;
01718         stack;
01719         stack=stack->next) {
01720       
01721       if (stack->port == port) {
01722 
01723          if (!stack->l1link)
01724             misdn_lib_get_l1_up(stack);
01725          if (!stack->l2link)
01726             misdn_lib_get_l2_up(stack);
01727          
01728          return 0;
01729       }
01730    }
01731    return 0;
01732 }

static int misdn_lib_get_short_status ( struct misdn_stack *  stack  )  [static]

Definition at line 871 of file isdn_lib.c.

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

Referenced by misdn_lib_isdn_l1watcher(), and stack_init().

00872 {
00873    iframe_t act;
00874    
00875    
00876    act.prim = MGR_SHORTSTATUS | REQUEST; 
00877    
00878    act.addr = (stack->upper_id | MSG_BROADCAST)  ;
00879 
00880    act.dinfo = SSTATUS_BROADCAST_BIT | SSTATUS_ALL;
00881    
00882    act.len = 0;
00883    return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
00884 }

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

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

04021 {
04022    struct misdn_lib *mgr=calloc(1, sizeof(struct misdn_lib));
04023    char *tok, *tokb;
04024    char plist[1024];
04025    int midev;
04026    int port_count=0;
04027  
04028    cb_log = iface->cb_log;
04029    cb_event = iface->cb_event;
04030    cb_jb_empty = iface->cb_jb_empty;
04031    
04032    glob_mgr = mgr;
04033   
04034    msg_init();
04035 
04036    misdn_lib_nt_debug_init(0,NULL);
04037    
04038    if (!portlist || (*portlist == 0) ) return 1;
04039    
04040    init_flip_bits();
04041    
04042    {
04043       strncpy(plist,portlist, 1024);
04044       plist[1023] = 0;
04045    }
04046   
04047    memcpy(tone_425_flip,tone_425,TONE_425_SIZE);
04048    flip_buf_bits(tone_425_flip,TONE_425_SIZE);
04049 
04050    memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE);
04051    flip_buf_bits(tone_silence_flip,TONE_SILENCE_SIZE);
04052   
04053    midev=te_lib_init();
04054    mgr->midev=midev;
04055 
04056    port_count=mISDN_get_stack_count(midev);
04057   
04058    msg_queue_init(&mgr->activatequeue);
04059   
04060    if (sem_init(&mgr->new_msg, 1, 0)<0)
04061       sem_init(&mgr->new_msg, 0, 0);
04062  
04063    for (tok=strtok_r(plist," ,",&tokb );
04064         tok; 
04065         tok=strtok_r(NULL," ,",&tokb)) {
04066       int port = atoi(tok);
04067       struct misdn_stack *stack;
04068       static int first=1;
04069       int ptp=0;
04070     
04071       if (strstr(tok, "ptp"))
04072          ptp=1;
04073 
04074       if (port > port_count) {
04075          cb_log(0, port, "Couldn't Initialize this port since we have only %d ports\n", port_count);
04076          exit(1);
04077       }
04078       stack=stack_init(midev, port, ptp);
04079     
04080       if (!stack) {
04081          perror("stack_init");
04082          exit(1);
04083       }
04084     
04085       {
04086          int i;
04087          for(i=0;i<=stack->b_num; i++) {
04088             int r;
04089             if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) {
04090                cb_log(0, port, "Got Err @ init_bc :%d\n",r);
04091                exit(1);
04092             }
04093          }
04094       }
04095 
04096       if (stack && first) {
04097          mgr->stack_list=stack;
04098          first=0;
04099          continue;
04100       }
04101     
04102       if (stack) {
04103          struct misdn_stack * help;
04104          for ( help=mgr->stack_list; help; help=help->next ) 
04105             if (help->next == NULL) break;
04106          help->next=stack;
04107       }
04108     
04109    }
04110   
04111    if (sem_init(&handler_started, 1, 0)<0)
04112       sem_init(&handler_started, 0, 0);
04113   
04114    cb_log(8, 0, "Starting Event Handler\n");
04115    pthread_create( &mgr->event_handler_thread, NULL,(void*)manager_event_handler, mgr);
04116   
04117    sem_wait(&handler_started) ;
04118    cb_log(8, 0, "Starting Event Catcher\n");
04119    pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr);
04120   
04121    cb_log(8, 0, "Event Catcher started\n");
04122 
04123    global_state= MISDN_INITIALIZED; 
04124   
04125    return (mgr == NULL);
04126 }

int misdn_lib_is_port_blocked ( int  port  ) 

Definition at line 97 of file isdn_lib.c.

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

00098 {  
00099    struct misdn_stack *stack=get_misdn_stack();
00100    for ( ; stack; stack=stack->next) {
00101       if (stack->port == port) {
00102          return stack->blocked;
00103       }
00104    }
00105    return -1;
00106 }

int misdn_lib_is_ptp ( int  port  ) 

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

00109 {
00110    struct misdn_stack *stack=get_misdn_stack();
00111    for ( ; stack; stack=stack->next) {
00112       if (stack->port == port) return stack->ptp;
00113    }
00114    return -1;
00115 }

static void misdn_lib_isdn_event_catcher ( void *  arg  )  [static]

When we make a call from NT2Ast we get these frames

I get this sometimes after setup_bc

Definition at line 3016 of file isdn_lib.c.

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

Referenced by misdn_lib_init().

03017 {
03018    struct misdn_lib *mgr = arg;
03019    int zero_frm=0 , fff_frm=0 ;
03020    int midev= mgr->midev;
03021    int port=0;
03022    
03023    while (1) {
03024       msg_t *msg = fetch_msg(midev); 
03025       iframe_t *frm;
03026       
03027       
03028       if (!msg) continue;
03029       
03030       frm = (iframe_t*) msg->data;
03031       
03032       /** When we make a call from NT2Ast we get these frames **/
03033       if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) {
03034          zero_frm++; 
03035          free_msg(msg);
03036          continue;
03037       } else {
03038          if (zero_frm) {
03039             cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm);
03040             zero_frm = 0 ;
03041          }
03042       }
03043       
03044       /** I get this sometimes after setup_bc **/
03045       if (frm->len == 0 &&  frm->dinfo == 0 && frm->prim == 0xffffffff ) {
03046          fff_frm++; 
03047          free_msg(msg);
03048          continue;
03049       } else {
03050          if (fff_frm) {
03051             cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm);
03052             fff_frm = 0 ;
03053          }
03054       }
03055       
03056       manager_isdn_handler(frm, msg);
03057    }
03058 
03059 }

void misdn_lib_isdn_l1watcher ( int  port  ) 

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

02998 {
02999    struct misdn_stack *stack;
03000 
03001    for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next)
03002       ;
03003 
03004    if (stack) {
03005       cb_log(4, port, "Checking L1 State\n");   
03006       if (!stack->l1link) {
03007          cb_log(4, port, "L1 State Down, trying to get it up again\n"); 
03008          misdn_lib_get_short_status(stack);
03009          misdn_lib_get_l1_up(stack); 
03010          misdn_lib_get_l2_up(stack); 
03011       }
03012    }
03013 }

void misdn_lib_log_ies ( struct misdn_bchannel *  bc  ) 

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

03293 {
03294    struct misdn_stack *stack;
03295 
03296    if (!bc) return;
03297 
03298    stack = get_stack_by_bc(bc);
03299 
03300    if (!stack) return;
03301 
03302    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);
03303    
03304    cb_log(2, stack->port,
03305           " --> info_dad:%s onumplan:%c dnumplan:%c rnumplan:%c cpnnumplan:%c\n",
03306           bc->info_dad,
03307           bc->onumplan>=0?'0'+bc->onumplan:' ',
03308           bc->dnumplan>=0?'0'+bc->dnumplan:' ',
03309           bc->rnumplan>=0?'0'+bc->rnumplan:' ',
03310           bc->cpnnumplan>=0?'0'+bc->cpnnumplan:' '
03311       );
03312    
03313    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);
03314    cb_log(4, stack->port, " --> screen:%d --> pres:%d\n",
03315          bc->screen, bc->pres);
03316    
03317    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);
03318    
03319    cb_log(4, stack->port, " --> facility:%s out_facility:%s\n",fac2str(bc->fac_in.Function),fac2str(bc->fac_out.Function));
03320 
03321    cb_log(5, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1);
03322    
03323    cb_log(5, stack->port, " --> bc:%p h:%d sh:%d\n", bc, bc->holded, bc->stack_holder);
03324 }

int misdn_lib_maxports_get ( void   ) 

Definition at line 3970 of file isdn_lib.c.

Referenced by load_module().

03971 {
03972    /* BE AWARE WE HAVE NO cb_log() HERE! */
03973 
03974    int i = mISDN_open();
03975    int max=0;
03976    
03977    if (i<0)
03978       return -1;
03979 
03980    max = mISDN_get_stack_count(i);
03981    
03982    mISDN_close(i);
03983    
03984    return max;
03985 }

void misdn_lib_nt_debug_init ( int  flags,
char *  file 
)

Definition at line 4000 of file isdn_lib.c.

References f.

Referenced by load_module(), and misdn_lib_init().

04001 {
04002    static int init=0;
04003    char *f;
04004    
04005    if (!flags) 
04006       f=NULL;
04007    else
04008       f=file;
04009 
04010    if (!init) {
04011       debug_init( flags , f, f, f);
04012       init=1;
04013    } else {
04014       debug_close();
04015       debug_init( flags , f, f, f);
04016    }
04017 }

void misdn_lib_nt_keepcalls ( int  kc  ) 

Definition at line 3988 of file isdn_lib.c.

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

Referenced by load_module().

03989 {
03990 #ifdef FEATURE_NET_KEEPCALLS
03991    if (kc) {
03992       struct misdn_stack *stack=get_misdn_stack();
03993       for ( ; stack; stack=stack->next) {
03994          stack->nst.feature |= FEATURE_NET_KEEPCALLS;
03995       }
03996    }
03997 #endif
03998 }

int misdn_lib_pid_restart ( int  pid  ) 

Definition at line 3783 of file isdn_lib.c.

References manager_clean_bc(), and manager_find_bc_by_pid().

Referenced by misdn_restart_pid().

03784 {
03785    struct misdn_bchannel *bc=manager_find_bc_by_pid(pid);
03786 
03787    if (bc) {
03788       manager_clean_bc(bc);
03789    }
03790    return 0;
03791 }

int misdn_lib_port_block ( int  port  ) 

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

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

int misdn_lib_port_is_pri ( int  port  ) 

Definition at line 49 of file isdn_lib.c.

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

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

00050 {
00051    struct misdn_stack *stack=get_misdn_stack();
00052    for ( ; stack; stack=stack->next) {
00053       if (stack->port == port) {
00054          return stack->pri;
00055       }
00056    }
00057    
00058    return -1;
00059 }

int misdn_lib_port_restart ( int  port  ) 

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

03834 {
03835    struct misdn_stack *stack=find_stack_by_port(port);
03836  
03837    cb_log(0, port, "Restarting this port.\n");
03838    if (stack) {
03839       cb_log(0, port, "Stack:%p\n",stack);
03840          
03841       clear_l3(stack);
03842       {
03843          msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03844          iframe_t *frm;
03845 
03846          if (!msg) {
03847             cb_log(0, port, "port_restart: alloc_msg failed\n");
03848             return -1;
03849          }
03850          
03851          frm=(iframe_t*)msg->data;
03852          /* we must activate if we are deactivated */
03853          /* activate bchannel */
03854          frm->prim = DL_RELEASE | REQUEST;
03855          frm->addr = stack->upper_id | FLG_MSG_DOWN;
03856 
03857          frm->dinfo = 0;
03858          frm->len = 0;
03859          msg_queue_tail(&glob_mgr->activatequeue, msg);
03860          sem_post(&glob_mgr->new_msg);
03861       }
03862 
03863       if (stack->nt)
03864          misdn_lib_reinit_nt_stack(stack->port);
03865     
03866    }
03867 
03868    return 0;
03869 }

int misdn_lib_port_unblock ( int  port  ) 

Definition at line 84 of file isdn_lib.c.

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

Referenced by misdn_port_unblock().

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

int misdn_lib_port_up ( int  port,
int  check 
)

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

01752 {
01753    struct misdn_stack *stack;
01754 
01755 
01756    for (stack=glob_mgr->stack_list;
01757         stack;
01758         stack=stack->next) {
01759       
01760       if (stack->port == port) {
01761 
01762          if (stack->blocked) {
01763             cb_log(0,port, "Port Blocked:%d L2:%d L1:%d\n", stack->blocked, stack->l2link, stack->l1link);
01764             return -1;
01765          }
01766 
01767          if (stack->ptp ) {
01768 
01769             if (stack->l1link && stack->l2link) {
01770                return 1;
01771             } else {
01772                cb_log(1,port, "Port Down L2:%d L1:%d\n",
01773                   stack->l2link, stack->l1link);
01774                return 0;
01775             }
01776          } else {
01777             if ( !check || stack->l1link )
01778                return 1;
01779             else {
01780                cb_log(1,port, "Port down PMP\n");
01781                return 0;
01782             }
01783          }
01784       }
01785    }
01786   
01787    return -1;
01788 }

void misdn_lib_reinit_nt_stack ( int  port  ) 

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

04623 {
04624    struct misdn_stack *stack=find_stack_by_port(port);
04625    
04626    if (stack) {
04627       stack->l2link=0;
04628       stack->blocked=0;
04629    
04630       cleanup_Isdnl3(&stack->nst);
04631       cleanup_Isdnl2(&stack->nst);
04632 
04633 
04634       memset(&stack->nst, 0, sizeof(net_stack_t));
04635       memset(&stack->mgr, 0, sizeof(manager_t));
04636    
04637       stack->mgr.nst = &stack->nst;
04638       stack->nst.manager = &stack->mgr;
04639     
04640       stack->nst.l3_manager = handle_event_nt;
04641       stack->nst.device = glob_mgr->midev;
04642       stack->nst.cardnr = port;
04643       stack->nst.d_stid = stack->d_stid;
04644    
04645       stack->nst.feature = FEATURE_NET_HOLD;
04646       if (stack->ptp)
04647          stack->nst.feature |= FEATURE_NET_PTP;
04648       if (stack->pri)
04649          stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
04650       
04651       stack->nst.l1_id = stack->lower_id;
04652       stack->nst.l2_id = stack->upper_id;
04653       
04654       msg_queue_init(&stack->nst.down_queue);
04655    
04656       Isdnl2Init(&stack->nst);
04657       Isdnl3Init(&stack->nst);
04658 
04659       if (!stack->ptp)
04660          misdn_lib_get_l1_up(stack);
04661       misdn_lib_get_l2_up(stack);
04662    }
04663 }

void misdn_lib_release ( struct misdn_bchannel *  bc  ) 

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

01694 {
01695    struct misdn_stack *stack=get_stack_by_bc(bc);
01696 
01697    if (!stack) {
01698       cb_log(1,0,"misdn_release: No Stack found\n");
01699       return;
01700    }
01701    
01702    if (bc->channel>0) 
01703       empty_chan_in_stack(stack,bc->channel);
01704    
01705    empty_bc(bc);
01706    clean_up_bc(bc);
01707    bc->in_use=0;
01708 }

int misdn_lib_send_event ( struct misdn_bchannel *  bc,
enum event_e  event 
)

Queue Event

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

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

int misdn_lib_send_restart ( int  port,
int  channel 
)

Definition at line 3794 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, misdn_lib_send_event(), misdn_make_dummy(), misdn_stack::nt, and misdn_stack::port.

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

03795 {
03796    struct misdn_stack *stack=find_stack_by_port(port);
03797    struct misdn_bchannel dummybc;
03798    /*default is all channels*/
03799    cb_log(0, port, "Sending Restarts on this port.\n");
03800    
03801    misdn_make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0);
03802 
03803    /*default is all channels*/
03804    if (channel <0) {
03805       dummybc.channel=-1;
03806       cb_log(0, port, "Restarting and all Interfaces\n");
03807       misdn_lib_send_event(&dummybc, EVENT_RESTART);
03808 
03809       return 0;
03810    }
03811 
03812    /*if a channel is specified we restart only this one*/
03813    if (channel >0) {
03814       int cnt;
03815       dummybc.channel=channel;
03816       cb_log(0, port, "Restarting and cleaning channel %d\n",channel);
03817       misdn_lib_send_event(&dummybc, EVENT_RESTART);
03818       /* clean up chan in stack, to be sure we don't think it's
03819        * in use anymore */
03820       for (cnt=0; cnt<=stack->b_num; cnt++) {
03821          if (stack->bc[cnt].channel == channel) {
03822             empty_bc(&stack->bc[cnt]);
03823             clean_up_bc(&stack->bc[cnt]);
03824             stack->bc[cnt].in_use=0;
03825          }
03826       }
03827    }
03828 
03829    return 0;
03830 }

void misdn_lib_send_tone ( struct misdn_bchannel *  bc,
enum tone_e  tone 
)

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

04441 {
04442    char buf[mISDN_HEADER_LEN + 128] = "";
04443    iframe_t *frm = (iframe_t*)buf;
04444 
04445    switch(tone) {
04446    case TONE_DIAL:
04447       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE); 
04448    break;
04449    
04450    case TONE_ALERTING:
04451       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_RINGING);  
04452    break;
04453    
04454    case TONE_HANGUP:
04455       manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_HANGUP);   
04456    break;
04457 
04458    case TONE_NONE:
04459    default:
04460       manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP);  
04461    }
04462 
04463    frm->prim=DL_DATA|REQUEST;
04464    frm->addr=bc->addr|FLG_MSG_DOWN;
04465    frm->dinfo=0;
04466    frm->len=128;
04467    
04468    mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
04469 }

void misdn_lib_setup_bc ( struct misdn_bchannel *  bc  ) 

Definition at line 954 of file isdn_lib.c.

References clean_up_bc(), and setup_bc().

00955 {
00956    clean_up_bc(bc);
00957    setup_bc(bc);
00958 }

void misdn_lib_split_bridge ( struct misdn_bchannel *  bc1,
struct misdn_bchannel *  bc2 
)

Definition at line 4594 of file isdn_lib.c.

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

Referenced by misdn_bridge().

04595 {
04596 
04597    struct misdn_bchannel *bc_list[]={
04598       bc1,bc2,NULL
04599    };
04600    struct misdn_bchannel **bc;
04601       
04602    for (bc=bc_list; *bc;  bc++) { 
04603       if ( (*bc)->bc_state == BCHAN_BRIDGED){
04604          misdn_split_conf( *bc, (*bc)->conf_id);
04605       } else {
04606          cb_log( 2, (*bc)->port, "BC not bridged (state:%s) so not splitting it\n",bc_state2str((*bc)->bc_state));
04607       }
04608    }
04609    
04610 }

void misdn_lib_tone_generator_start ( struct misdn_bchannel *  bc  ) 

Definition at line 2194 of file isdn_lib.c.

References misdn_bchannel::generate_tone.

Referenced by misdn_write().

02195 {
02196    bc->generate_tone=1;
02197 }

void misdn_lib_tone_generator_stop ( struct misdn_bchannel *  bc  ) 

Definition at line 2199 of file isdn_lib.c.

References misdn_bchannel::generate_tone.

Referenced by start_bc_tones(), and stop_indicate().

02200 {
02201    bc->generate_tone=0;
02202 }

void misdn_lib_transfer ( struct misdn_bchannel *  holded_bc  ) 

Definition at line 3103 of file isdn_lib.c.

References misdn_bchannel::holded.

03104 {
03105    holded_bc->holded=0;
03106 }

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

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

04225 {
04226    struct misdn_stack *stack=get_stack_by_bc(bc);
04227    char buf[4096 + mISDN_HEADER_LEN];
04228    iframe_t *frm = (iframe_t*)buf;
04229    int r;
04230 
04231    switch (bc->bc_state) {
04232       case BCHAN_ACTIVATED:
04233       case BCHAN_BRIDGED:
04234          break;
04235       default:
04236          cb_log(3, bc->port, "BC not yet activated (state:%s)\n",bc_state2str(bc->bc_state));
04237          return -1;
04238    }
04239    
04240    frm->prim = DL_DATA|REQUEST;
04241    frm->dinfo = 0;
04242    frm->addr = bc->addr | FLG_MSG_DOWN ;
04243    
04244    frm->len = len;
04245    memcpy(&buf[mISDN_HEADER_LEN], data,len);
04246       
04247    if ( misdn_cap_is_speech(bc->capability) ) 
04248       flip_buf_bits( &buf[mISDN_HEADER_LEN], len);
04249    else
04250       cb_log(6, stack->port, "Writing %d data bytes\n",len);
04251    
04252    cb_log(9, stack->port, "Writing %d bytes 2 mISDN\n",len);
04253    r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT);
04254    return 0;
04255 }

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

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

00062 {
00063    memset (dummybc,0,sizeof(struct misdn_bchannel));
00064    dummybc->port=port;
00065    dummybc->l3_id=l3id;
00066    dummybc->nt=nt;
00067    dummybc->dummy=1;
00068    dummybc->channel=channel;
00069 }

static void misdn_send_lock ( struct misdn_bchannel *  bc  )  [static]

Definition at line 3329 of file isdn_lib.c.

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

Referenced by misdn_lib_send_event().

03330 {
03331    //cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid);
03332    if (bc->send_lock)
03333       pthread_mutex_lock(&bc->send_lock->lock);
03334 }

static void misdn_send_unlock ( struct misdn_bchannel *  bc  )  [static]

Definition at line 3336 of file isdn_lib.c.

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

Referenced by misdn_lib_send_event().

03337 {
03338    //cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid);
03339    if (bc->send_lock)
03340       pthread_mutex_unlock(&bc->send_lock->lock);
03341 }

void misdn_split_conf ( struct misdn_bchannel *  bc,
int  conf_id 
)

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

04563 {
04564    bc_state_change(bc,BCHAN_ACTIVATED);
04565    manager_ph_control(bc, CMX_RECEIVE_ON, 0);
04566    manager_ph_control(bc, CMX_CONF_SPLIT, conf_id);
04567 
04568    cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id);
04569 }

void misdn_tx_jitter ( struct misdn_bchannel *  bc,
int  len 
)

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

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

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

Definition at line 3151 of file isdn_lib.c.

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

03152 {
03153    bc->channel = channel;
03154    bc->channel_preselected = channel?1:0;
03155    bc->in_use = 1;
03156    bc->need_disconnect=1;
03157    bc->need_release=1;
03158    bc->need_release_complete=1;
03159    bc->cause = AST_CAUSE_NORMAL_CLEARING;
03160 
03161    if (++mypid>5000) mypid=1;
03162    bc->pid=mypid;
03163 
03164 #if 0
03165    bc->addr=0;
03166    bc->b_stid=0;
03167    bc->layer_id=0;
03168 #endif
03169 }

int queue_cleanup_bc ( struct misdn_bchannel *  bc  ) 

Definition at line 3758 of file isdn_lib.c.

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

03759 {
03760    msg_t *msg=alloc_msg(MAX_MSG_SIZE);
03761    iframe_t *frm;
03762    if (!msg) {
03763       cb_log(0, bc->port, "queue_cleanup_bc: alloc_msg failed!\n");
03764       return -1;
03765    }
03766    frm=(iframe_t*)msg->data;
03767 
03768    /* activate bchannel */
03769    frm->prim = MGR_CLEARSTACK| REQUEST;
03770 
03771    frm->addr = bc->l3_id;
03772 
03773    frm->dinfo = bc->port;
03774    frm->len = 0;
03775   
03776    msg_queue_tail(&glob_mgr->activatequeue, msg);
03777    sem_post(&glob_mgr->new_msg);
03778 
03779    return 0; 
03780 
03781 }

int release_cr ( struct misdn_stack *  stack,
mISDNuser_head_t *  hh 
)

removing procid

Definition at line 1791 of file isdn_lib.c.

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

Referenced by handle_event_nt().

01792 {
01793    struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
01794    struct misdn_bchannel dummybc;
01795    iframe_t frm; /* fake te frm to remove callref from global callreflist */
01796    frm.dinfo = hh->dinfo;
01797 
01798    frm.addr=stack->upper_id | FLG_MSG_DOWN;
01799 
01800    frm.prim = CC_RELEASE_CR|INDICATION;
01801    cb_log(4, stack->port, " --> CC_RELEASE_CR: Faking Release_cr for %x l3id:%x\n",frm.addr, frm.dinfo);
01802    /** removing procid **/
01803    if (!bc) {
01804       cb_log(4, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", hh->dinfo);
01805       misdn_make_dummy(&dummybc, stack->port, hh->dinfo, stack->nt, 0);
01806       bc=&dummybc; 
01807    }
01808 
01809    if (bc) {
01810       if ( (bc->l3_id & 0xff00) == 0xff00) {
01811          cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", bc->l3_id&0xff);
01812          stack->procids[bc->l3_id&0xff] = 0 ;
01813       }
01814    }
01815    else cb_log(0, stack->port, "Couldn't find BC so I couldn't remove the Process!!!! this is a bad port.\n");
01816 
01817    if (handle_cr(stack, &frm)<0) {
01818    }
01819 
01820    return 0 ;
01821 }

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

Definition at line 395 of file isdn_lib.c.

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

Referenced by manager_event_handler().

00396 {
00397    iframe_t *frm = (iframe_t *)dmsg->data;
00398    struct misdn_stack *stack=get_stack_by_bc(bc);
00399 
00400    if (!stack) {
00401       cb_log(0,bc->port,"send_msg: IEK!! no stack\n ");
00402       return -1;
00403    }
00404    
00405    frm->addr = (stack->upper_id | FLG_MSG_DOWN);
00406    frm->dinfo = bc->l3_id;
00407    frm->len = (dmsg->len) - mISDN_HEADER_LEN;
00408             
00409    cb_log(4,stack->port,"Sending msg, prim:%x addr:%x dinfo:%x\n",frm->prim,frm->addr,frm->dinfo);
00410 
00411    mISDN_write(midev, dmsg->data, dmsg->len, TIMEOUT_1SEC);
00412    free_msg(dmsg);
00413 
00414    return 0;
00415 }

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

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

00469 {
00470 
00471    cb_log(4,stack->port,"set_chan_in_stack: %d\n",channel);
00472    dump_chan_list(stack);
00473    if (channel >=1 && channel <= MAX_BCHANS) {
00474       if (!stack->channels[channel-1])
00475          stack->channels[channel-1] = 1;
00476       else {
00477          cb_log(4,stack->port,"channel already in use:%d\n", channel );
00478          return -1;
00479       }
00480    } else {
00481       cb_log(0,stack->port,"couldn't set channel %d in\n", channel );
00482       return -1;
00483    }
00484   
00485    return 0;
00486 }

int setup_bc ( struct misdn_bchannel *  bc  ) 

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

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

static void stack_destroy ( struct misdn_stack *  stack  )  [static]

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

01388 {
01389    char buf[1024];
01390    if (!stack) return;
01391 
01392    if (stack->nt) {
01393       cleanup_Isdnl2(&stack->nst);
01394       cleanup_Isdnl3(&stack->nst);
01395    }
01396   
01397    if (stack->lower_id) 
01398       mISDN_write_frame(stack->midev, buf, stack->lower_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
01399 
01400    if (stack->upper_id) 
01401       mISDN_write_frame(stack->midev, buf, stack->upper_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
01402 }

void stack_holder_add ( struct misdn_stack *  stack,
struct misdn_bchannel *  holder 
)

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

04346 {
04347    struct misdn_bchannel *help;
04348    cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id);
04349    
04350    holder->stack_holder=1;
04351    holder->next=NULL;
04352    
04353    if (!stack->holding) {
04354       stack->holding = holder;
04355       return;
04356    }
04357   
04358    for (help=stack->holding;
04359         help;
04360         help=help->next) {
04361       if (!help->next) {
04362          help->next=holder;
04363          break;
04364       }
04365    }
04366   
04367 }

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

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

04418 {
04419    struct misdn_bchannel *help;
04420 
04421    cb_log(4,stack?stack->port:0, "*HOLDER: find %lx\n",l3id);
04422    
04423    if (!stack) return NULL;
04424    
04425    for (help=stack->holding;
04426         help;
04427         help=help->next) {
04428       if (help->l3_id == l3id) {
04429          cb_log(4,stack->port, "*HOLDER: found bc\n");
04430          return help;
04431       }
04432    }
04433 
04434    cb_log(4,stack->port, "*HOLDER: find nothing\n");
04435    return NULL;
04436 }

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

Definition at line 4395 of file isdn_lib.c.

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

04396 {
04397    struct misdn_bchannel *help;
04398 
04399    cb_log(4,stack?stack->port:0, "*HOLDER: find_bychan %c\n", chan);
04400    
04401    if (!stack) return NULL;
04402    
04403    for (help=stack->holding;
04404         help;
04405         help=help->next) {
04406       if (help->channel == chan) {
04407          cb_log(4,stack->port, "*HOLDER: found_bychan bc\n");
04408          return help;
04409       }
04410    }
04411 
04412    cb_log(4,stack->port, "*HOLDER: find_bychan nothing\n");
04413    return NULL;
04414 
04415 }

void stack_holder_remove ( struct misdn_stack *  stack,
struct misdn_bchannel *  holder 
)

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

04370 {
04371    struct misdn_bchannel *h1;
04372 
04373    if (!holder->stack_holder) return;
04374    
04375    holder->stack_holder=0;
04376    
04377    cb_log(4,stack->port, "*HOLDER: remove %x\n",holder->l3_id);
04378    if (!stack || ! stack->holding) return;
04379   
04380    if (holder == stack->holding) {
04381       stack->holding = stack->holding->next;
04382       return;
04383    }
04384    
04385    for (h1=stack->holding;
04386         h1;
04387         h1=h1->next) {
04388       if (h1->next == holder) {
04389          h1->next=h1->next->next;
04390          return ;
04391       }
04392    }
04393 }

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

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

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

void te_lib_destroy ( int  midev  ) 

Definition at line 3091 of file isdn_lib.c.

References cb_log, and entity.

Referenced by misdn_lib_destroy().

03092 {
03093    char buf[1024];
03094    mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC);
03095 
03096    cb_log(4, 0, "Entity deleted\n");
03097    mISDN_close(midev);
03098    cb_log(4, 0, "midev closed\n");
03099 }

int te_lib_init (  ) 

App Interface

Definition at line 3064 of file isdn_lib.c.

References entity, errno, and misdn_lib::midev.

Referenced by misdn_lib_init().

03064                   {
03065    char buff[1025] = "";
03066    iframe_t *frm=(iframe_t*)buff;
03067    int midev=mISDN_open();
03068    int ret;
03069 
03070    if  (midev<=0) return midev;
03071   
03072 /* create entity for layer 3 TE-mode */
03073    mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
03074    ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC);
03075   
03076    if (ret < mISDN_HEADER_LEN) {
03077    noentity:
03078       fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n",strerror(errno));
03079       exit(-1);
03080    }
03081   
03082    entity = frm->dinfo & 0xffff ;
03083   
03084    if (!entity)
03085       goto noentity;
03086 
03087    return midev;
03088   
03089 }

static int test_inuse ( struct misdn_bchannel *  bc  )  [static]

Definition at line 3131 of file isdn_lib.c.

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

Referenced by misdn_lib_get_free_bc().

03132 {
03133    struct timeval now;
03134    gettimeofday(&now, NULL);
03135    if (!bc->in_use) {
03136       if (misdn_lib_port_is_pri(bc->port) && bc->last_used.tv_sec == now.tv_sec ) {
03137          cb_log(2,bc->port, "channel with stid:%x for one second still in use! (n:%d lu:%d)\n", bc->b_stid, (int) now.tv_sec, (int) bc->last_used.tv_sec);
03138          return 1;
03139       }
03140       
03141 
03142       cb_log(3,bc->port, "channel with stid:%x not in use!\n", bc->b_stid);
03143       return 0;
03144    }
03145    
03146    cb_log(2,bc->port, "channel with stid:%x in use!\n", bc->b_stid);
03147    return 1;
03148 }


Variable Documentation

int entity [static]

Definition at line 242 of file isdn_lib.c.

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

char flip_table[256] [static]

Definition at line 304 of file isdn_lib.c.

Referenced by flip_buf_bits(), and init_flip_bits().

struct misdn_lib* glob_mgr [static]

Definition at line 244 of file isdn_lib.c.

enum global_states global_state = MISDN_INITIALIZING [static]

Definition at line 174 of file isdn_lib.c.

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

Definition at line 3873 of file isdn_lib.c.

struct isdn_msg msgs_g[]

int mypid = 1 [static]

Definition at line 418 of file isdn_lib.c.

Referenced by prepare_bc().

int newteid = 0 [static]

Definition at line 772 of file isdn_lib.c.

Referenced by create_process().

int nt_err_cnt = 0 [static]

Definition at line 167 of file isdn_lib.c.

Referenced by handle_frm_nt().

char tone_425_flip[TONE_425_SIZE]

Definition at line 246 of file isdn_lib.c.

Referenced by misdn_lib_init().

char tone_silence_flip[TONE_SILENCE_SIZE]

Definition at line 247 of file isdn_lib.c.

Referenced by misdn_lib_init(), and misdn_tx_jitter().


Generated on Fri Jul 3 20:38:35 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.9