25 #include <mISDNuser/isdn_debug.h> 33 __attribute__ ((
format (printf, 3, 4)));
42 #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0])) 56 for ( ; stack; stack=stack->
next) {
57 if (stack->
port == port) {
68 for ( ; stack; stack=stack->
next) {
69 if (stack->
port == port) {
82 dummybc->
l3_id = MISDN_ID_DUMMY;
94 for ( ; stack; stack=stack->
next) {
95 if (stack->
port == port) {
107 for ( ; stack; stack=stack->
next) {
108 if (stack->
port == port) {
120 for ( ; stack; stack=stack->
next) {
121 if (stack->
port == port) {
131 for ( ; stack; stack=stack->
next) {
132 if (stack->
port == port)
return stack->
ptp;
140 for ( ; stack; stack=stack->
next) {
141 if (stack->
port == port) {
159 for ( ; stack; stack = stack->
next) {
172 for (; stack; stack = stack->
next) {
173 if (stack->
port == port) {
179 sprintf(buf,
"* Port %2d Type %s Prot. %s L2Link %s L1Link:%s Blocked:%d",
181 stack->
nt ?
"NT" :
"TE",
182 stack->
ptp ?
"PTP" :
"PMP",
183 (stack->
nt && !stack->
ptp) ?
"UNKN" : stack->
l2link ?
"UP " :
"DOWN",
184 stack->
l1link ?
"UP " :
"DOWN",
202 #include <mISDNuser/net_l2.h> 203 #include <mISDNuser/tone.h> 205 #include <semaphore.h> 229 #define ECHOCAN_ON 123 230 #define ECHOCAN_OFF 124 233 #define MISDN_DEBUG 0 246 #define ISDN_PID_L3_B_USER 0x430000ff 247 #define ISDN_PID_L4_B_USER 0x440000ff 250 #define MISDN_IBUF_SIZE 512 253 #define TONE_ALERT_CNT 41 254 #define TONE_ALERT_SILENCE_CNT 200 256 #define TONE_BUSY_CNT 20 257 #define TONE_BUSY_SILENCE_CNT 48 283 void ec_chunk(
struct misdn_bchannel *bc,
unsigned char *rxchunk,
unsigned char *txchunk,
int chunk_size);
291 static char *bearers[]={
325 for (i = 0 ; i < 256 ; i++) {
326 unsigned char sample = 0 ;
327 for (k = 0; k<8; k++) {
328 if ( i & 1 << k ) sample |= 0x80 >> k;
330 flip_table[i] = sample;
339 for (i = 0 ; i <
len; i++) {
340 buf[i] = flip_table[(
unsigned char)buf[i]];
356 dmsg = prep_l3data_msg(prim, dinfo, size, 256,
NULL);
361 printf(
"cannot allocate memory, trying again...\n");
365 printf(
"cannot allocate memory, system overloaded.\n");
379 size =
sizeof(Q931_info_t)+2;
383 dmsg = prep_l3data_msg(prim, dinfo, size, 256,
NULL);
388 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
391 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
392 frm = (iframe_t *)dmsg->data;
395 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
401 if (!i) printf(
"cannot allocate memory, trying again...\n");
405 printf(
"cannot allocate memory, system overloaded.\n");
412 iframe_t *frm = (iframe_t *)dmsg->data;
416 cb_log(0,bc->
port,
"send_msg: IEK!! no stack\n ");
420 frm->addr = (stack->upper_id | FLG_MSG_DOWN);
421 frm->dinfo = bc->
l3_id;
422 frm->len = (dmsg->len) - mISDN_HEADER_LEN;
424 cb_log(4,stack->port,
"Sending msg, prim:%x addr:%x dinfo:%x\n",frm->prim,frm->addr,frm->dinfo);
426 mISDN_write(midev, dmsg->data, dmsg->len, TIMEOUT_1SEC);
468 for (i = 0; i <= stack->
b_num; ++i) {
469 cb_log(6, stack->
port,
"Idx:%d stack->cchan:%d in_use:%d Chan:%d\n",
472 #if defined(AST_MISDN_ENHANCEMENTS) 475 cb_log(6, stack->
port,
"Idx:%d stack->cchan:%d REGISTER Chan:%d in_use\n",
486 for ( ; stack; stack=stack->
next) {
494 cb_log(4,stack->
port,
"set_chan_in_stack: %d\n",channel);
500 cb_log(4,stack->
port,
"channel already in use:%d\n", channel );
504 cb_log(0,stack->
port,
"couldn't set channel %d in\n", channel );
525 #if defined(AST_MISDN_ENHANCEMENTS) 531 cb_log(3, stack->
port,
" --> found REGISTER chan: %d\n", chan);
538 cb_log(5, stack->
port,
"find_free_chan: req_chan:%d\n", channel);
541 cb_log(0, stack->
port,
" !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel);
550 for (i = bnums; i >= 0; --i) {
551 if (i != 15 && (channel < 0 || i == channel)) {
554 cb_log(3, stack->
port,
" --> found chan%s: %d\n", channel >= 0 ?
" (preselected)" :
"", chan);
560 for (i = 0; i <= bnums; ++i) {
561 if (i != 15 && (channel < 0 || i == channel)) {
564 cb_log(3, stack->
port,
" --> found chan%s: %d\n", channel >= 0 ?
" (preselected)" :
"", chan);
574 cb_log(1, stack->
port,
" !! NO FREE CHAN IN STACK\n");
582 cb_log(0, stack->
port,
"Channel Already in use:%d\n", chan);
608 cb_log(0, stack->
port,
"empty_chan_in_stack: cannot empty channel %d\n", channel);
612 cb_log(4, stack->
port,
"empty_chan_in_stack: %d\n", channel);
620 struct bchan_state_s {
632 for (i=0; i<
sizeof(states)/
sizeof(
struct bchan_state_s); i++)
633 if ( states[i].s == state)
641 cb_log(5,bc->
port,
"BC_STATE_CHANGE: l3id:%x from:%s to:%s\n",
661 cb_log(5,bc->
port,
"BC_NEXT_STATE_CHANGE: from:%s to:%s\n",
779 #if defined(AST_MISDN_ENHANCEMENTS) 780 bc->div_leg_3_rx_wanted = 0;
781 bc->div_leg_3_tx_pending = 0;
805 bc->
fac_in.Function = Fac_None;
806 bc->
fac_out.Function = Fac_None;
818 unsigned char buff[32];
825 if (!stack)
return -1;
829 cb_log(5, stack->
port,
"$$$ Already cleaned up bc with stid :%x\n", bc->
b_stid);
842 mISDN_write_frame(stack->
midev, buff, bc->
layer_id|FLG_MSG_TARGET|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0,
NULL, TIMEOUT_1SEC);
857 for (i = 0; i <= stack->
b_num; ++i) {
864 #if defined(AST_MISDN_ENHANCEMENTS) 880 act.prim = PH_DEACTIVATE | REQUEST;
881 act.addr = stack->
upper_id | FLG_MSG_DOWN;
885 cb_log(1, stack->
port,
"SENDING PH_DEACTIVATE | REQ\n");
886 return mISDN_write(stack->
midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
893 if (stack->
ptp && stack->
nt) {
899 if (stack->
nst.manager_l3(&stack->
nst, dmsg))
902 }
else if (!stack->
nt) {
905 act.prim = DL_RELEASE| REQUEST;
906 act.addr = (stack->
upper_id |FLG_MSG_DOWN) ;
910 return mISDN_write(stack->
midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
922 act.prim = PH_ACTIVATE | REQUEST;
923 act.addr = stack->
upper_id | FLG_MSG_DOWN;
928 cb_log(1, stack->
port,
"SENDING PH_ACTIVATE | REQ\n");
929 return mISDN_write(stack->
midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
935 if (stack->
ptp && stack->
nt) {
941 if (stack->
nst.manager_l3(&stack->
nst, dmsg))
944 }
else if (!stack->
nt) {
947 act.prim = DL_ESTABLISH | REQUEST;
948 act.addr = (stack->
upper_id |FLG_MSG_DOWN) ;
952 return mISDN_write(stack->
midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
964 act.prim = MGR_SHORTSTATUS | REQUEST;
966 act.addr = (stack->
upper_id | MSG_BROADCAST) ;
968 act.dinfo = SSTATUS_BROADCAST_BIT | SSTATUS_ALL;
971 return mISDN_write(stack->
midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
990 for (proc_id = 0; proc_id <
MAXPROCS; ++proc_id) {
991 if (stack->
procids[proc_id] == 0) {
995 if (proc_id == MAXPROCS) {
996 cb_log(0, stack->
port,
"Couldn't Create New ProcId.\n");
1002 l3_id = 0xff00 | proc_id;
1004 cb_log(3, stack->
port,
" --> new_l3id %x\n", l3_id);
1018 if (++new_te_id > 0xffff) {
1022 l3_id = (entity << 16) | new_te_id;
1024 cb_log(3, stack->
port,
"--> new_l3id %x\n", l3_id);
1027 ncr.prim = CC_NEW_CR | REQUEST;
1028 ncr.addr = (stack->
upper_id | FLG_MSG_DOWN);
1031 mISDN_write(midev, &ncr, mISDN_HEADER_LEN + ncr.len, TIMEOUT_1SEC);
1040 unsigned char buff[1025];
1051 cb_log(0, bc->
port,
"setup_bc: NO STACK FOUND!!\n");
1055 midev = stack->
midev;
1057 b_stid = stack->
b_stids[channel >= 0 ? channel : 0];
1067 cb_log(5, stack->
port,
"$$$ Setting up bc with stid :%x\n", b_stid);
1070 for (i=0; i <= stack->
b_num; i++) {
1071 if (stack->
bc[i].
b_stid == b_stid) {
1072 cb_log(0, bc->
port,
"setup_bc: b_stid:%x already in use !!!\n", b_stid);
1078 cb_log(0, stack->
port,
" -- Stid <=0 at the moment in channel:%d\n",channel);
1088 memset(&li, 0,
sizeof(li));
1101 cb_log(4, stack->
port,
"setup_bc: without dsp\n");
1103 int l =
sizeof(li.name);
1104 strncpy(li.name,
"B L3", l);
1107 li.pid.layermask = ISDN_LAYER((3));
1112 cb_log(4, stack->
port,
"setup_bc: with dsp\n");
1114 int l =
sizeof(li.name);
1115 strncpy(li.name,
"B L4", l);
1118 li.pid.layermask = ISDN_LAYER((4));
1124 ret = mISDN_new_layer(midev, &li);
1135 memset(&pid, 0,
sizeof(pid));
1142 cb_log(2, stack->
port,
" --> TRANSPARENT Mode (no DSP, no HDLC)\n");
1143 pid.protocol[1] = ISDN_PID_L1_B_64TRANS;
1144 pid.protocol[2] = ISDN_PID_L2_B_TRANS;
1146 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3));
1148 }
else if ( bc->
hdlc ) {
1150 pid.protocol[1] = ISDN_PID_L1_B_64HDLC ;
1151 pid.protocol[2] = ISDN_PID_L2_B_TRANS ;
1153 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) ;
1155 cb_log(2, stack->
port,
" --> TRANSPARENT Mode\n");
1156 pid.protocol[1] = ISDN_PID_L1_B_64TRANS;
1157 pid.protocol[2] = ISDN_PID_L2_B_TRANS;
1158 pid.protocol[3] = ISDN_PID_L3_B_DSP;
1160 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) | ISDN_LAYER((4));
1164 ret = mISDN_set_stack(midev, bc->
b_stid, &pid);
1167 cb_log(0, stack->
port,
"$$$ Set Stack Err: %d %s\n",ret,strerror(
errno));
1169 mISDN_write_frame(midev, buff, bc->
layer_id, MGR_DELLAYER | REQUEST, 0, 0,
NULL, TIMEOUT_1SEC);
1176 ret = mISDN_get_setstack_ind(midev, bc->
layer_id);
1179 cb_log(0, stack->
port,
"$$$ Set StackIND Err: %d %s\n",ret,strerror(
errno));
1180 mISDN_write_frame(midev, buff, bc->
layer_id, MGR_DELLAYER | REQUEST, 0, 0,
NULL, TIMEOUT_1SEC);
1187 ret = mISDN_get_layerid(midev, bc->
b_stid, bc->
layer) ;
1189 bc->
addr = ret>0? ret : 0;
1192 cb_log(0, stack->
port,
"$$$ Get Layerid Err: %d %s\n",ret,strerror(
errno));
1193 mISDN_write_frame(midev, buff, bc->
layer_id, MGR_DELLAYER | REQUEST, 0, 0,
NULL, TIMEOUT_1SEC);
1216 cb_log(8, port,
"Init.BC %d.\n",bidx);
1228 bc->
nt=stack->
nt?1:0;
1234 if (!ibuf)
return -1;
1236 clear_ibuffer( ibuf);
1238 ibuf->rsem=
malloc(
sizeof(sem_t));
1245 if (sem_init(ibuf->rsem,1,0)<0)
1246 sem_init(ibuf->rsem,0,0);
1251 if (bidx <= stack->
b_num) {
1252 unsigned char buff[1025];
1253 iframe_t *frm = (iframe_t *) buff;
1254 stack_info_t *stinf;
1257 ret = mISDN_get_stack_info(midev, stack->
port, buff,
sizeof(buff));
1259 cb_log(0, port,
"%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret);
1263 stinf = (stack_info_t *)&frm->data.p;
1265 cb_log(8, port,
" --> Child %x\n",stinf->child[bidx]);
1277 unsigned char buff[1025];
1278 iframe_t *frm = (iframe_t *)buff;
1279 stack_info_t *stinf;
1289 cb_log(8, port,
"Init. Stack.\n");
1303 ret = mISDN_get_stack_info(midev, port, buff,
sizeof(buff));
1305 cb_log(0, port,
"%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret);
1310 stinf = (stack_info_t *)&frm->data.p;
1312 stack->
d_stid = stinf->id;
1313 stack->
b_num = stinf->childcnt;
1315 for (i=0; i<=stinf->childcnt; i++)
1316 stack->
b_stids[i] = stinf->child[i];
1318 switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK) {
1319 case ISDN_PID_L0_TE_S0:
1320 cb_log(8, port,
"TE Stack\n");
1323 case ISDN_PID_L0_NT_S0:
1324 cb_log(8, port,
"NT Stack\n");
1327 case ISDN_PID_L0_TE_E1:
1328 cb_log(8, port,
"TE S2M Stack\n");
1332 case ISDN_PID_L0_NT_E1:
1333 cb_log(8, port,
"NT S2M Stack\n");
1338 cb_log(0, port,
"this is a unknown port type 0x%08x\n", stinf->pid.protocol[0]);
1343 if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP ) {
1354 memset(&li, 0,
sizeof(li));
1356 int l =
sizeof(li.name);
1357 strncpy(li.name,nt?
"net l2":
"user l4", l);
1362 li.pid.protocol[nt?2:4] = nt?ISDN_PID_L2_LAPD_NET:ISDN_PID_L4_CAPI20;
1363 li.pid.layermask = ISDN_LAYER((nt?2:4));
1367 ret = mISDN_new_layer(midev, &li);
1369 cb_log(0, port,
"%s: Cannot add layer %d to this port.\n", __FUNCTION__, nt?2:4);
1375 ret = mISDN_register_layer(midev, stack->
d_stid, li.id);
1378 cb_log(0,port,
"Cannot register layer %d of this port.\n", nt?2:4);
1383 stack->
lower_id = mISDN_get_layerid(midev, stack->
d_stid, nt?1:3);
1385 cb_log(0, port,
"%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, nt?1:3);
1390 stack->
upper_id = mISDN_get_layerid(midev, stack->
d_stid, nt?2:4);
1392 cb_log(0, port,
"%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, nt?2:4);
1400 memset(&stack->
nst, 0,
sizeof(net_stack_t));
1401 memset(&stack->
mgr, 0,
sizeof(manager_t));
1403 stack->
mgr.nst = &stack->
nst;
1404 stack->
nst.manager = &stack->
mgr;
1411 stack->
nst.feature = FEATURE_NET_HOLD;
1413 stack->
nst.feature |= FEATURE_NET_PTP;
1415 stack->
nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
1420 msg_queue_init(&stack->
nst.down_queue);
1423 Isdnl2Init(&stack->
nst);
1424 Isdnl3Init(&stack->
nst);
1461 cleanup_Isdnl2(&stack->
nst);
1462 cleanup_Isdnl3(&stack->
nst);
1466 mISDN_write_frame(stack->
midev, buf, stack->
upper_id, MGR_DELLAYER | REQUEST, 0, 0,
NULL, TIMEOUT_1SEC);
1477 if ((stack->
upper_id & STACK_ID_MASK) == (addr & STACK_ID_MASK)) {
1492 if (stack->
port == port) {
1506 if (&stack->
mgr == mgr_nt) {
1519 for (i = 0; i <= stack->
b_num; ++i) {
1520 if (stack->
bc[i].
in_use && (stack->
bc[i].
l3_id & mask) == (l3id & mask)) {
1521 return &stack->
bc[i];
1524 #if defined(AST_MISDN_ENHANCEMENTS) 1527 if (stack->
bc[i].
in_use && (stack->
bc[i].
l3_id & mask) == (l3id & mask)) {
1528 return &stack->
bc[i];
1540 for (i = 0; i <= stack->
b_num; ++i) {
1542 return &stack->
bc[i];
1545 #if defined(AST_MISDN_ENHANCEMENTS) 1549 return &stack->
bc[i];
1562 for (i = 0; i <= stack->
b_num; i++) {
1564 && ((stack->
bc[i].
addr & STACK_ID_MASK) == (addr & STACK_ID_MASK)
1566 return &stack->
bc[i];
1580 for (i = 0; i <= stack->
b_num; i++) {
1582 return &stack->
bc[i];
1600 "ENABLING BLOWFISH channel:%d caller%d:\"%s\" <%s> dialed%d:%s\n",
1629 "ENABLING BLOWFISH channel:%d caller%d:\"%s\" <%s> dialed%d:%s\n",
1648 if (!stack->
pri && !stack->
ptp) {
1654 cb_log(0, stack->
port,
"Any Channel Requested, but we have no more!!\n");
1657 "Requested Channel Already in Use releasing this call with cause %d!!!!\n",
1692 if (!stack)
return -1;
1694 switch (frm->prim) {
1695 case CC_NEW_CR|INDICATION:
1696 cb_log(7, stack->
port,
" --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo);
1700 cb_log(0, stack->
port,
" --> !! lib: No free channel!\n");
1704 cb_log(7, stack->
port,
" --> new_process: New L3Id: %x\n",frm->dinfo);
1705 bc->
l3_id=frm->dinfo;
1707 case CC_NEW_CR|CONFIRM:
1709 case CC_NEW_CR|REQUEST:
1711 case CC_RELEASE_CR|REQUEST:
1713 case CC_RELEASE_CR|CONFIRM:
1715 case CC_RELEASE_CR|INDICATION:
1716 cb_log(4, stack->
port,
" --> lib: RELEASE_CR Ind with l3id:%x\n", frm->dinfo);
1719 cb_log(4, stack->
port,
" --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
1725 cb_log(4, stack->
port,
" --> lib: CLEANING UP l3id: %x\n", frm->dinfo);
1765 cb_log(1,0,
"misdn_release: No Stack found\n");
1787 stack=stack->
next) {
1789 if (stack->
port == port) {
1794 if (!stack->
l2link && !stack->
nt) {
1810 stack=stack->
next) {
1811 if (stack->
port == port) {
1828 stack=stack->
next) {
1830 if (stack->
port == port) {
1842 cb_log(1,port,
"Port Down L2:%d L1:%d\n",
1847 if ( !check || stack->
l1link )
1850 cb_log(1,port,
"Port down PMP\n");
1867 frm.dinfo = hh->dinfo;
1869 frm.prim = CC_RELEASE_CR|INDICATION;
1870 cb_log(4, stack->
port,
" --> CC_RELEASE_CR: Faking Release_cr for %x l3id:%x\n",frm.addr, frm.dinfo);
1874 cb_log(4, stack->
port,
" --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", hh->dinfo);
1879 if ((bc->
l3_id & 0xff00) == 0xff00) {
1880 cb_log(4, stack->
port,
" --> Removing Process Id:%x on this port.\n", bc->
l3_id & 0xff);
1894 manager_t *mgr = (manager_t *)dat;
1895 msg_t *msg = (msg_t *)arg;
1897 mISDNuser_head_t *hh;
1909 hh=(mISDNuser_head_t*)msg->data;
1918 cb_log(5, stack->
port,
" --> lib: prim %x dinfo %x\n",hh->prim, hh->dinfo);
1920 case CC_RETRIEVE|INDICATION:
1925 frm.dinfo = hh->dinfo;
1927 frm.prim = CC_NEW_CR|INDICATION;
1929 goto ERR_NO_CHANNEL;
1941 memcpy(bc, hold_bc,
sizeof(*bc));
1950 case CC_SETUP | CONFIRM:
1953 cb_log(4, stack->
port,
" --> lib: Event_ind:SETUP CONFIRM [NT] : new L3ID is %x\n", l3id);
1957 cb_log (2, bc->
port,
"I IND :CC_SETUP|CONFIRM: old l3id:%x new l3id:%x\n", bc->
l3_id, l3id);
1961 cb_log(4, stack->
port,
"Bc Not found (after SETUP CONFIRM)\n");
1967 case CC_SETUP | INDICATION:
1970 goto ERR_NO_CHANNEL;
1973 cb_log(4, stack->
port,
" --> new_process: New L3Id: %x\n",hh->dinfo);
1974 bc->
l3_id=hh->dinfo;
1977 #if defined(AST_MISDN_ENHANCEMENTS) 1978 case CC_REGISTER | CONFIRM:
1981 cb_log(4, stack->
port,
" --> lib: Event_ind:REGISTER CONFIRM [NT] : new L3ID is %x\n", l3id);
1985 cb_log (2, bc->
port,
"I IND :CC_REGISTER|CONFIRM: old l3id:%x new l3id:%x\n", bc->
l3_id, l3id);
1988 cb_log(4, stack->
port,
"Bc Not found (after REGISTER CONFIRM)\n");
1995 #if defined(AST_MISDN_ENHANCEMENTS) 1996 case CC_REGISTER | INDICATION:
1997 bc = misdn_lib_get_register_bc(stack->
port);
1999 goto ERR_NO_CHANNEL;
2002 cb_log(4, stack->
port,
" --> new_process: New L3Id: %x\n",hh->dinfo);
2003 bc->
l3_id=hh->dinfo;
2007 case CC_CONNECT_ACKNOWLEDGE|INDICATION:
2010 case CC_ALERTING|INDICATION:
2011 case CC_PROCEEDING|INDICATION:
2012 case CC_SETUP_ACKNOWLEDGE|INDICATION:
2013 case CC_CONNECT|INDICATION:
2015 case CC_DISCONNECT|INDICATION:
2020 int myprocid=bc->
l3_id&0x0000ffff;
2022 hh->dinfo=(hh->dinfo&0xffff0000)|myprocid;
2023 cb_log(3,stack->
port,
"Reject dinfo: %x cause:%d\n",hh->dinfo,bc->
cause);
2029 case CC_FACILITY|INDICATION:
2034 int myprocid=bc->
l3_id&0x0000ffff;
2036 hh->dinfo=(hh->dinfo&0xffff0000)|myprocid;
2037 cb_log(4,bc->
port,
"Repaired reject Bug, new dinfo: %x\n",hh->dinfo);
2042 case CC_RELEASE_COMPLETE|INDICATION:
2045 case CC_SUSPEND|INDICATION:
2046 cb_log(4, stack->
port,
" --> Got Suspend, sending Reject for now\n");
2047 dmsg =
create_l3msg(CC_SUSPEND_REJECT | REQUEST,MT_SUSPEND_REJECT, hh->dinfo,
sizeof(RELEASE_COMPLETE_t), 1);
2049 stack->
nst.manager_l3(&stack->
nst, dmsg);
2053 case CC_RESUME|INDICATION:
2056 case CC_RELEASE|CONFIRM:
2059 cb_log(1, stack->
port,
"CC_RELEASE|CONFIRM (l3id:%x), sending RELEASE_COMPLETE\n", hh->dinfo);
2064 case CC_RELEASE|INDICATION:
2067 case CC_RELEASE_CR|INDICATION:
2073 case CC_NEW_CR|INDICATION:
2080 cb_log(0, stack->
port,
" --> In NEW_CR: didn't found bc ??\n");
2084 if (((l3id&0xff00)!=0xff00) && ((bc->
l3_id&0xff00)==0xff00)) {
2085 cb_log(4, stack->
port,
" --> Removing Process Id:%x on this port.\n", 0xff&bc->
l3_id);
2088 cb_log(4, stack->
port,
"lib: Event_ind:CC_NEW_CR : very new L3ID is %x\n",l3id );
2099 case DL_ESTABLISH | INDICATION:
2100 case DL_ESTABLISH | CONFIRM:
2101 cb_log(3, stack->
port,
"%% GOT L2 Activate Info.\n");
2104 cb_log(0, stack->
port,
"%% GOT L2 Activate Info. but we're activated already.. this l2 is faulty, blocking port\n");
2124 case DL_RELEASE | INDICATION:
2125 case DL_RELEASE | CONFIRM:
2126 cb_log(3, stack->
port,
"%% GOT L2 DeActivate Info.\n");
2130 cb_log(0 , stack->
port,
"!!! Could not Get the L2 up after 3 Attempts!!!\n");
2153 cb_log(4, stack->
port,
" --> Didn't find BC so temporarily creating dummy BC (l3id:%x).\n", hh->dinfo);
2167 goto ERR_NO_CHANNEL;
2173 tmpcause = bc->
cause;
2176 bc->
cause = tmpcause;
2188 cb_log(4, stack->
port,
"Unknown Event Ind: prim %x dinfo %x\n", hh->prim, hh->dinfo);
2193 cb_log(1, stack->
port,
"Siemens Busy reject..\n");
2207 cb_log(4, stack->
port,
"Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo);
2208 dmsg =
create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo,
sizeof(RELEASE_COMPLETE_t), 1);
2210 stack->
nst.manager_l3(&stack->
nst, dmsg);
2218 iframe_t *frm= (iframe_t*)msg->data;
2222 switch (frm->prim) {
2223 case MGR_INITTIMER | CONFIRM:
2224 case MGR_ADDTIMER | CONFIRM:
2225 case MGR_DELTIMER | CONFIRM:
2226 case MGR_REMOVETIMER | CONFIRM:
2233 if (frm->prim==(MGR_TIMER | INDICATION) ) {
2236 stack = stack->
next) {
2239 if (!stack->nt)
continue;
2241 it = stack->nst.tlist;
2243 for(it=stack->nst.tlist;
2246 if (it->id == (
int)frm->addr)
2250 mISDN_write_frame(stack->midev, msg->data, frm->addr,
2251 MGR_TIMER | RESPONSE, 0, 0,
NULL, TIMEOUT_1SEC);
2252 test_and_clear_bit(FLG_TIMER_RUNING, (
long unsigned int *)&it->Flags);
2254 it->function(it->data);
2261 cb_log(0, 0,
"Timer Msg without Timer ??\n");
2300 #ifdef MISDN_SAVE_DATA 2301 static void misdn_save_data(
int id,
char *p1,
int l1,
char *p2,
int l2)
2306 sprintf(n1,
"/tmp/misdn-rx-%d.raw",
id);
2307 sprintf(n2,
"/tmp/misdn-tx-%d.raw",
id);
2309 rx = fopen(n1,
"a+");
2310 tx = fopen(n2,
"a+");
2313 cb_log(0,0,
"Couldn't open files: %s\n",strerror(
errno));
2332 char buf[4096 + mISDN_HEADER_LEN];
2333 char *data=&buf[mISDN_HEADER_LEN];
2334 iframe_t *txfrm= (iframe_t*)buf;
2340 #ifdef MISDN_SAVE_DATA 2346 cb_log(1, bc->
port,
"Jitterbuffer Underrun. Got %d of expected %d\n", jlen, len);
2349 txfrm->prim = DL_DATA|REQUEST;
2353 txfrm->addr = bc->
addr|FLG_MSG_DOWN;
2356 cb_log(9, bc->
port,
"Transmitting %d samples 2 misdn\n", txfrm->len);
2358 r=mISDN_write( glob_mgr->
midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 );
2360 #define MISDN_GEN_SILENCE 2361 #ifdef MISDN_GEN_SILENCE 2362 int cnt=len/TONE_SILENCE_SIZE;
2363 int rest=len%TONE_SILENCE_SIZE;
2366 for (i=0; i<cnt; i++) {
2367 memcpy(data, tone_silence_flip, TONE_SILENCE_SIZE );
2368 data +=TONE_SILENCE_SIZE;
2372 memcpy(data, tone_silence_flip, rest);
2375 txfrm->prim = DL_DATA|REQUEST;
2379 txfrm->addr = bc->
addr|FLG_MSG_DOWN;
2382 cb_log(5, bc->
port,
"Transmitting %d samples of silence to misdn\n", len);
2384 r=mISDN_write( glob_mgr->
midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 );
2397 iframe_t *frm= (iframe_t*)msg->data;
2402 cb_log(1,0,
"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo);
2409 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);
2413 switch (frm->prim) {
2415 case MGR_SETSTACK| CONFIRM:
2416 cb_log(3, stack->
port,
"BCHAN: MGR_SETSTACK|CONFIRM pid:%d\n",bc->
pid);
2419 case MGR_SETSTACK| INDICATION:
2420 cb_log(3, stack->
port,
"BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->
pid);
2423 case MGR_DELLAYER| INDICATION:
2424 cb_log(3, stack->
port,
"BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->
pid);
2427 case MGR_DELLAYER| CONFIRM:
2428 cb_log(3, stack->
port,
"BCHAN: MGR_DELLAYER|CNF pid:%d\n",bc->
pid);
2436 case PH_ACTIVATE | INDICATION:
2437 case DL_ESTABLISH | INDICATION:
2443 case PH_ACTIVATE | CONFIRM:
2444 case DL_ESTABLISH | CONFIRM:
2446 cb_log(3, stack->
port,
"BCHAN: bchan ACT Confirm pid:%d\n",bc->
pid);
2451 case DL_ESTABLISH | REQUEST:
2454 mISDN_write_frame(stack->
midev, buf, bc->
addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_ESTABLISH | CONFIRM, 0,0,
NULL, TIMEOUT_1SEC);
2459 case DL_RELEASE|REQUEST:
2462 mISDN_write_frame(stack->
midev, buf, bc->
addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_RELEASE| CONFIRM, 0,0,
NULL, TIMEOUT_1SEC);
2467 case PH_DEACTIVATE | INDICATION:
2468 case DL_RELEASE | INDICATION:
2469 cb_log (3, stack->
port,
"BCHAN: DeACT Ind pid:%d\n",bc->
pid);
2474 case PH_DEACTIVATE | CONFIRM:
2475 case DL_RELEASE | CONFIRM:
2476 cb_log(3, stack->
port,
"BCHAN: DeACT Conf pid:%d\n",bc->
pid);
2481 case PH_CONTROL|INDICATION:
2483 unsigned int *cont = (
unsigned int *) &frm->data.p;
2486 "PH_CONTROL: channel:%d caller%d:\"%s\" <%s> dialed%d:%s \n",
2494 if ((*cont & ~DTMF_TONE_MASK) == DTMF_TONE_VAL) {
2495 int dtmf = *cont & DTMF_TONE_MASK;
2496 cb_log(4, stack->
port,
" --> DTMF TONE: %c\n",dtmf);
2503 if (*cont == BF_REJECT) {
2508 if (*cont == BF_ACCEPT) {
2516 case PH_DATA|REQUEST:
2517 case DL_DATA|REQUEST:
2518 cb_log(0, stack->
port,
"DL_DATA REQUEST \n");
2525 case PH_DATA|INDICATION:
2526 case DL_DATA|INDICATION:
2528 bc->
bframe = (
void*)&frm->data.i;
2537 cb_log(2, stack->
port,
"DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->
addr, frm->addr);
2542 if ( (bc->
addr&STACK_ID_MASK) != (frm->addr&STACK_ID_MASK) ) {
2543 cb_log(2, stack->
port,
"DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->
addr, frm->addr);
2549 cb_log(0, stack->
port,
"DL_DATA INDICATION Len %d\n", frm->len);
2556 #ifdef MISDN_B_DEBUG 2561 #ifdef MISDN_B_DEBUG 2569 #ifdef MISDN_B_DEBUG 2573 #ifdef MISDN_B_DEBUG 2579 #ifdef MISDN_B_DEBUG 2584 #ifdef MISDN_B_DEBUG 2589 cb_log(10,stack->
port,
"cb_event returned <0\n");
2599 case PH_CONTROL | CONFIRM:
2600 cb_log(4, stack->
port,
"PH_CONTROL|CNF bc->addr:%x\n", frm->addr);
2604 case PH_DATA | CONFIRM:
2605 case DL_DATA|CONFIRM:
2613 case DL_DATA|RESPONSE:
2628 iframe_t *frm= (iframe_t*)msg->data;
2636 if (!stack || !stack->nt) {
2642 if ((err=stack->nst.l1_l2(&stack->nst,msg))) {
2644 if (nt_err_cnt > 0 ) {
2645 if (nt_err_cnt < 100) {
2647 cb_log(0, stack->port,
"NT Stack sends us error: %d \n", err);
2648 }
else if (nt_err_cnt < 105){
2649 cb_log(0, stack->port,
"NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err);
2674 frm = (iframe_t*) msg->data;
2676 if (!stack || stack->
nt) {
2680 cb_log(4, stack->
port,
"handle_frm_te: frm->addr:%x frm->prim:%x\n", frm->addr, frm->prim);
2684 cb_log(3, stack->
port,
"handle_frm_te: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr);
2694 switch (frm->prim) {
2695 case CC_RESTART | CONFIRM:
2696 dummybc.
l3_id = MISDN_ID_GLOBAL;
2699 case CC_SETUP | INDICATION:
2700 dummybc.
l3_id = frm->dinfo;
2712 if (frm->prim == (CC_FACILITY | INDICATION)) {
2713 cb_log(5, stack->
port,
" --> Using Dummy BC for FACILITY\n");
2715 cb_log(0, stack->
port,
" --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
2716 dummybc.
l3_id = frm->dinfo;
2729 cb_log(0, stack->
port,
"couldn't handle event\n");
2735 cb_log(5, stack->
port,
"lib Got Prim: Addr %x prim %x dinfo %x\n", frm->addr, frm->prim, frm->dinfo);
2738 cb_log(0, stack->
port,
"Unknown Event Ind: Addr:%x prim %x dinfo %x\n", frm->addr, frm->prim, frm->dinfo);
2748 cb_log(0, stack->
port,
"TOTALLY IGNORING SETUP\n");
2751 cb_log(0, stack->
port,
"GOT IGNORE SETUP\n");
2757 cb_log(0, stack->
port,
"GOT RELEASE SETUP\n");
2765 cb_log(0, stack->
port,
"GOT UNKNOWN SETUP RESPONSE\n");
2772 tmpcause = bc->
cause;
2776 bc->
cause = tmpcause;
2797 cb_log(5, stack->
port,
"Freeing Msg on prim:%x \n", frm->prim);
2805 iframe_t *frm = (iframe_t*) msg->data;
2808 if (!stack)
return 0 ;
2810 switch (frm->prim) {
2811 case PH_ACTIVATE | CONFIRM:
2814 cb_log (3, stack->port,
"L1: PH_ACTIVATE|REQUEST returned error!\n");
2819 case PH_ACTIVATE | INDICATION:
2820 cb_log (3, stack->port,
"L1: PH L1Link Up!\n");
2826 if (stack->nst.l1_l2(&stack->nst, msg))
2837 case PH_ACTIVATE | REQUEST:
2839 cb_log(3,stack->port,
"L1: PH_ACTIVATE|REQUEST \n");
2842 case PH_DEACTIVATE | REQUEST:
2844 cb_log(3,stack->port,
"L1: PH_DEACTIVATE|REQUEST \n");
2847 case PH_DEACTIVATE | CONFIRM:
2850 cb_log (3, stack->port,
"L1: PH_DEACTIVATE|REQUEST returned error!\n");
2855 case PH_DEACTIVATE | INDICATION:
2856 cb_log (3, stack->port,
"L1: PH L1Link Down! \n");
2859 for (i=0; i<=stack->b_num; i++) {
2868 if (stack->nst.l1_l2(&stack->nst, msg))
2885 iframe_t *frm = (iframe_t*) msg->data;
2895 case DL_ESTABLISH | REQUEST:
2896 cb_log(1,stack->port,
"DL_ESTABLISH|REQUEST \n");
2899 case DL_RELEASE | REQUEST:
2900 cb_log(1,stack->port,
"DL_RELEASE|REQUEST \n");
2904 case DL_ESTABLISH | INDICATION:
2905 case DL_ESTABLISH | CONFIRM:
2907 cb_log (3, stack->port,
"L2: L2Link Up! \n");
2908 if (stack->ptp && stack->l2link) {
2909 cb_log (-1, stack->port,
"L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n");
2918 case DL_RELEASE | INDICATION:
2919 case DL_RELEASE | CONFIRM:
2921 cb_log (3, stack->port,
"L2: L2Link Down! \n");
2934 iframe_t *frm = (iframe_t*) msg->data;
2937 if ( (frm->addr == 0) && (frm->prim == (MGR_DELLAYER|CONFIRM)) ) {
2938 cb_log(2, 0,
"MGMT: DELLAYER|CONFIRM Addr: 0 !\n") ;
2946 if (frm->prim == (MGR_DELLAYER|CONFIRM)) {
2947 cb_log(2, 0,
"MGMT: DELLAYER|CONFIRM Addr: %x !\n",
2957 case MGR_SHORTSTATUS | INDICATION:
2958 case MGR_SHORTSTATUS | CONFIRM:
2959 cb_log(5, stack->port,
"MGMT: Short status dinfo %x\n",frm->dinfo);
2961 switch (frm->dinfo) {
2962 case SSTATUS_L1_ACTIVATED:
2963 cb_log(3, stack->port,
"MGMT: SSTATUS: L1_ACTIVATED \n");
2967 case SSTATUS_L1_DEACTIVATED:
2968 cb_log(3, stack->port,
"MGMT: SSTATUS: L1_DEACTIVATED \n");
2975 case SSTATUS_L2_ESTABLISHED:
2976 cb_log(3, stack->port,
"MGMT: SSTATUS: L2_ESTABLISH \n");
2980 case SSTATUS_L2_RELEASED:
2981 cb_log(3, stack->port,
"MGMT: SSTATUS: L2_RELEASED \n");
2989 case MGR_SETSTACK | INDICATION:
2990 cb_log(4, stack->port,
"MGMT: SETSTACK|IND dinfo %x\n",frm->dinfo);
2993 case MGR_DELLAYER | CONFIRM:
2994 cb_log(4, stack->port,
"MGMT: DELLAYER|CNF dinfo %x\n",frm->dinfo) ;
3013 msg_t *msg=alloc_msg(MAX_MSG_SIZE);
3017 cb_log(0, 0,
"fetch_msg: alloc msg failed !!");
3022 r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC);
3027 cb_log(6,0,
"Got empty Msg..\n");
3032 if (
errno == EAGAIN) {
3034 cb_log(4,0,
"mISDN_read wants us to wait\n");
3039 cb_log(0,0,
"mISDN_read returned :%d error:%s (%d)\n",r,strerror(
errno),
errno);
3043 if (!(frm->prim == (DL_DATA|INDICATION) )|| (frm->prim == (PH_DATA|INDICATION)))
3044 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 );
3053 for (stack = glob_mgr->
stack_list; stack && (stack->
port != port); stack = stack->
next)
3057 cb_log(4, port,
"Checking L1 State\n");
3059 cb_log(4, port,
"L1 State Down, trying to get it up again\n");
3071 int zero_frm=0 , fff_frm=0 ;
3082 frm = (iframe_t*) msg->data;
3085 if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) {
3091 cb_log(0, port,
"*** Alert: %d zero_frms caught\n", zero_frm);
3097 if (frm->len == 0 && frm->dinfo == 0 && frm->prim == 0xffffffff ) {
3103 cb_log(0, port,
"*** Alert: %d fff_frms caught\n", fff_frm);
3118 char buff[1025] =
"";
3119 iframe_t *frm = (iframe_t *) buff;
3123 midev = mISDN_open();
3129 mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0,
NULL, TIMEOUT_1SEC);
3131 ret = mISDN_read_frame(midev, frm,
sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC);
3132 entity = frm->dinfo & 0xffff;
3133 if (ret < mISDN_HEADER_LEN || !entity) {
3134 fprintf(stderr,
"cannot request MGR_NEWENTITY from mISDN: %s\n", strerror(
errno));
3145 mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0,
NULL, TIMEOUT_1SEC);
3147 cb_log(4, 0,
"Entity deleted\n");
3149 cb_log(4, 0,
"midev closed\n");
3158 for (i = 0; i <= stack->
b_num; i++) {
3160 return &stack->
bc[i];
3173 gettimeofday(&now,
NULL);
3176 cb_log(2, bc->
port,
"channel with stid:%x for one second still in use! (n:%d lu:%d)\n",
3199 if (++mypid>5000) mypid=1;
3212 cb_log(0, port,
"Requested channel out of bounds (%d)\n", channel);
3219 cb_log(0, port,
"Port is not configured (%d)\n", port);
3224 cb_log(0, port,
"Port is blocked\n");
3231 for (i = 0; i < stack->
b_num; i++) {
3235 cb_log(0, port,
"Requested channel:%d on port:%d is already in use\n", channel, port);
3240 return &stack->
bc[i];
3246 cb_log(0, port,
"Requested channel:%d is out of bounds on port:%d\n", channel, port);
3252 maxnum = (inout && !stack->
pri && !stack->
ptp) ? stack->
b_num + 1 : stack->
b_num;
3254 for (i = maxnum - 1; i >= 0; --i) {
3257 if (!stack->
pri && i == stack->
b_num) {
3258 stack->
bc[i].
cw = 1;
3262 stack->
bc[i].
dec = 1;
3264 return &stack->
bc[i];
3268 for (i = 0; i < maxnum; ++i) {
3271 if (!stack->
pri && i == stack->
b_num) {
3272 stack->
bc[i].
cw = 1;
3277 return &stack->
bc[i];
3283 cb_log(1, port,
"There is no free channel on port (%d)\n", port);
3287 #if defined(AST_MISDN_ENHANCEMENTS) 3305 cb_log(0, port,
"Port is not configured (%d)\n", port);
3310 cb_log(0, port,
"Port is blocked\n");
3316 bc = &stack->
bc[index];
3327 cb_log(1, port,
"There is no free REGISTER link on port (%d)\n", port);
3338 static const char *
fac2str(
enum FacFunction facility)
3340 static const struct {
3341 enum FacFunction facility;
3345 { Fac_None,
"Fac_None" },
3346 #if defined(AST_MISDN_ENHANCEMENTS) 3347 { Fac_ERROR,
"Fac_ERROR" },
3348 { Fac_RESULT,
"Fac_RESULT" },
3349 { Fac_REJECT,
"Fac_REJECT" },
3351 { Fac_ActivationDiversion,
"Fac_ActivationDiversion" },
3352 { Fac_DeactivationDiversion,
"Fac_DeactivationDiversion" },
3353 { Fac_ActivationStatusNotificationDiv,
"Fac_ActivationStatusNotificationDiv" },
3354 { Fac_DeactivationStatusNotificationDiv,
"Fac_DeactivationStatusNotificationDiv" },
3355 { Fac_InterrogationDiversion,
"Fac_InterrogationDiversion" },
3356 { Fac_DiversionInformation,
"Fac_DiversionInformation" },
3357 { Fac_CallDeflection,
"Fac_CallDeflection" },
3358 { Fac_CallRerouteing,
"Fac_CallRerouteing" },
3359 { Fac_DivertingLegInformation2,
"Fac_DivertingLegInformation2" },
3360 { Fac_InterrogateServedUserNumbers,
"Fac_InterrogateServedUserNumbers" },
3361 { Fac_DivertingLegInformation1,
"Fac_DivertingLegInformation1" },
3362 { Fac_DivertingLegInformation3,
"Fac_DivertingLegInformation3" },
3364 { Fac_EctExecute,
"Fac_EctExecute" },
3365 { Fac_ExplicitEctExecute,
"Fac_ExplicitEctExecute" },
3366 { Fac_RequestSubaddress,
"Fac_RequestSubaddress" },
3367 { Fac_SubaddressTransfer,
"Fac_SubaddressTransfer" },
3368 { Fac_EctLinkIdRequest,
"Fac_EctLinkIdRequest" },
3369 { Fac_EctInform,
"Fac_EctInform" },
3370 { Fac_EctLoopTest,
"Fac_EctLoopTest" },
3372 { Fac_ChargingRequest,
"Fac_ChargingRequest" },
3373 { Fac_AOCSCurrency,
"Fac_AOCSCurrency" },
3374 { Fac_AOCSSpecialArr,
"Fac_AOCSSpecialArr" },
3375 { Fac_AOCDCurrency,
"Fac_AOCDCurrency" },
3376 { Fac_AOCDChargingUnit,
"Fac_AOCDChargingUnit" },
3377 { Fac_AOCECurrency,
"Fac_AOCECurrency" },
3378 { Fac_AOCEChargingUnit,
"Fac_AOCEChargingUnit" },
3380 { Fac_StatusRequest,
"Fac_StatusRequest" },
3382 { Fac_CallInfoRetain,
"Fac_CallInfoRetain" },
3383 { Fac_EraseCallLinkageID,
"Fac_EraseCallLinkageID" },
3384 { Fac_CCBSDeactivate,
"Fac_CCBSDeactivate" },
3385 { Fac_CCBSErase,
"Fac_CCBSErase" },
3386 { Fac_CCBSRemoteUserFree,
"Fac_CCBSRemoteUserFree" },
3387 { Fac_CCBSCall,
"Fac_CCBSCall" },
3388 { Fac_CCBSStatusRequest,
"Fac_CCBSStatusRequest" },
3389 { Fac_CCBSBFree,
"Fac_CCBSBFree" },
3390 { Fac_CCBSStopAlerting,
"Fac_CCBSStopAlerting" },
3392 { Fac_CCBSRequest,
"Fac_CCBSRequest" },
3393 { Fac_CCBSInterrogate,
"Fac_CCBSInterrogate" },
3395 { Fac_CCNRRequest,
"Fac_CCNRRequest" },
3396 { Fac_CCNRInterrogate,
"Fac_CCNRInterrogate" },
3398 { Fac_CCBS_T_Call,
"Fac_CCBS_T_Call" },
3399 { Fac_CCBS_T_Suspend,
"Fac_CCBS_T_Suspend" },
3400 { Fac_CCBS_T_Resume,
"Fac_CCBS_T_Resume" },
3401 { Fac_CCBS_T_RemoteUserFree,
"Fac_CCBS_T_RemoteUserFree" },
3402 { Fac_CCBS_T_Available,
"Fac_CCBS_T_Available" },
3404 { Fac_CCBS_T_Request,
"Fac_CCBS_T_Request" },
3406 { Fac_CCNR_T_Request,
"Fac_CCNR_T_Request" },
3410 { Fac_CFActivate,
"Fac_CFActivate" },
3411 { Fac_CFDeactivate,
"Fac_CFDeactivate" },
3412 { Fac_CD,
"Fac_CD" },
3414 { Fac_AOCDCurrency,
"Fac_AOCDCurrency" },
3415 { Fac_AOCDChargingUnit,
"Fac_AOCDChargingUnit" },
3422 for (index = 0; index <
ARRAY_LEN(arr); ++index) {
3423 if (arr[index].facility == facility) {
3424 return arr[index].name;
3442 " --> channel:%d mode:%s cause:%d ocause:%d\n",
3444 stack->
nt ?
"NT" :
"TE",
3449 " --> info_dad:%s dialed numtype:%d plan:%d\n",
3455 " --> caller:\"%s\" <%s> type:%d plan:%d pres:%d screen:%d\n",
3464 " --> redirecting-from:\"%s\" <%s> type:%d plan:%d pres:%d screen:%d\n",
3472 " --> redirecting-to:\"%s\" <%s> type:%d plan:%d pres:%d screen:%d\n",
3480 " --> redirecting reason:%d count:%d\n",
3485 " --> connected:\"%s\" <%s> type:%d plan:%d pres:%d screen:%d\n",
3507 #define RETURN(a,b) {retval=a; goto b;} 3535 RETURN(-1,OUT_POST_UNLOCK);
3540 "SENDEVENT: no Stack for event:%s caller:\"%s\" <%s> dialed:%s \n",
3551 cb_log(6,stack->
port,
"SENDEVENT: stack->nt:%d stack->upperid:%x\n",stack->
nt, stack->
upper_id);
3553 if ( stack->
nt && !stack->
l1link) {
3558 "I SEND:%s caller:\"%s\" <%s> dialed:%s pid:%d\n",
3571 cb_log(0, stack->
port,
" No free channel at the moment @ send_event\n");
3594 cb_log(0, stack->
port,
" No free channel at the moment\n");
3603 if (retval == -EINVAL) {
3604 cb_log(0,bc->
port,
"send_event: setup_bc failed\n");
3611 " --> ENABLING BLOWFISH channel:%d caller%d:\"%s\" <%s> dialed%d:%s\n",
3641 cb_log(0, bc->
port,
"Could not allocate held_bc!!!\n");
3660 cb_log(0,bc->
port,
"We have no second bc in bridge???\n");
3681 cb_log(0, bc->
port,
" --> we have already sent DISCONNECT\n");
3694 cb_log(0, bc->
port,
" --> we have already sent RELEASE\n");
3702 cb_log(0, bc->
port,
" --> we have already sent RELEASE_COMPLETE\n");
3712 tmpcause = bc->
cause;
3730 if (retval == -EINVAL){
3731 cb_log(0,bc->
port,
"send_event: setup_bc failed\n");
3781 iframe_t *frm = (iframe_t*) msg->data;
3787 cb_log(0,0,
"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo);
3790 cb_log(0,0,
"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo);
3799 switch (frm->prim) {
3800 case MGR_SETSTACK|INDICATION:
3804 case MGR_SETSTACK|CONFIRM:
3805 case MGR_CLEARSTACK|CONFIRM:
3810 case DL_DATA|CONFIRM:
3811 cb_log(4,0,
"DL_DATA|CONFIRM\n");
3815 case PH_CONTROL|CONFIRM:
3816 cb_log(4,0,
"PH_CONTROL|CONFIRM\n");
3820 case DL_DATA|INDICATION:
3822 int port=(frm->addr&MASTER_ID_MASK) >> 8;
3823 int channel=(frm->addr&CHILD_ID_MASK) >> 16;
3827 cb_log(9,0,
"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel);
3840 if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) {
3841 cb_log(0,0,
"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n");
3851 if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) {
3852 static int unhandled_bmsg_count=1000;
3857 if (unhandled_bmsg_count==1000) {
3858 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);
3859 unhandled_bmsg_count=0;
3862 unhandled_bmsg_count++;
3867 #ifdef RECV_FRM_SYSLOG_DEBUG 3868 syslog(
LOG_NOTICE,
"mISDN recv: ADDR:%x PRIM:%x DINFO:%x\n", frm->addr, frm->prim, frm->dinfo);
3893 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);
3905 msg_t *msg=alloc_msg(MAX_MSG_SIZE);
3909 cb_log(0, port,
"misdn_lib_get_port_info: alloc_msg failed!\n");
3912 frm=(iframe_t*)msg->data;
3914 cb_log(0, port,
"There is no Stack for this port.\n");
3918 frm->prim = CC_STATUS_ENQUIRY | REQUEST;
3920 frm->addr = stack->
upper_id| FLG_MSG_DOWN;
3948 cb_log(0, port,
"Sending Restarts on this port.\n");
3955 cb_log(0, port,
"Restarting and all Interfaces\n");
3965 cb_log(0, port,
"Restarting and cleaning channel %d\n",channel);
3969 for (cnt=0; cnt<=stack->
b_num; cnt++) {
3986 cb_log(0, port,
"Restarting this port.\n");
3988 cb_log(0, port,
"Stack:%p\n",stack);
3992 msg_t *msg=alloc_msg(MAX_MSG_SIZE);
3996 cb_log(0, port,
"port_restart: alloc_msg failed\n");
4000 frm=(iframe_t*)msg->data;
4003 frm->prim = DL_RELEASE | REQUEST;
4004 frm->addr = stack->
upper_id | FLG_MSG_DOWN;
4027 sem_post(&handler_started);
4041 iframe_t *frm = (iframe_t*) msg->data ;
4043 switch ( frm->prim) {
4044 case MGR_SETSTACK | REQUEST :
4048 mISDN_write(glob_mgr->
midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
4055 stack=stack->
next ) {
4061 while ( (msg=msg_dequeue(&stack->
downqueue)) ) {
4064 if (stack->
nst.manager_l3(&stack->
nst, msg))
4065 cb_log(0, stack->
port,
"Error@ Sending Message in NT-Stack.\n");
4068 iframe_t *frm = (iframe_t *)msg->data;
4076 if (frm->dinfo == MISDN_ID_GLOBAL || frm->dinfo == MISDN_ID_DUMMY ) {
4077 cb_log(5,0,
" --> GLOBAL/DUMMY\n");
4083 cb_log(0,0,
"No bc for Message. Using dummy_bc\n");
4098 int i = mISDN_open();
4104 max = mISDN_get_stack_count(i);
4114 #ifdef FEATURE_NET_KEEPCALLS 4117 for ( ; stack; stack=stack->
next) {
4118 stack->
nst.feature |= FEATURE_NET_KEEPCALLS;
4135 debug_init( flags , f, f, f);
4139 debug_init( flags , f, f, f);
4155 if (!portlist || (*portlist == 0)) {
4159 mgr =
calloc(1,
sizeof(*mgr));
4171 strncpy(plist, portlist, 1024);
4174 memcpy(tone_425_flip,tone_425,TONE_425_SIZE);
4177 memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE);
4188 port_count=mISDN_get_stack_count(midev);
4192 if (sem_init(&mgr->
new_msg, 1, 0)<0)
4193 sem_init(&mgr->
new_msg, 0, 0);
4195 for (tok=strtok_r(plist,
" ,",&tokb );
4197 tok=strtok_r(
NULL,
" ,",&tokb)) {
4198 int port = atoi(tok);
4205 if (strstr(tok,
"ptp"))
4208 if (port > port_count) {
4209 cb_log(0, port,
"Couldn't Initialize this port since we have only %d ports\n", port_count);
4215 cb_log(0, port,
"stack_init() failed for this port\n");
4220 for (i = 0; i <= stack->
b_num; i++) {
4223 cb_log(0, port,
"Got Err @ init_bc :%d\n", r);
4227 if (i <= stack->
b_num) {
4232 #if defined(AST_MISDN_ENHANCEMENTS) 4237 cb_log(0, port,
"Got Err @ init_bc :%d\n", r);
4254 while (help->
next) {
4268 if (sem_init(&handler_started, 1, 0)<0)
4269 sem_init(&handler_started, 0, 0);
4271 cb_log(8, 0,
"Starting Event Handler\n");
4274 sem_wait(&handler_started) ;
4275 cb_log(8, 0,
"Starting Event Catcher\n");
4278 cb_log(8, 0,
"Event Catcher started\n");
4282 return (mgr ==
NULL);
4291 for(i=0;i<=help->
b_num; i++) {
4293 mISDN_write_frame(help->
midev, buf, help->
bc[i].
addr, MGR_DELLAYER | REQUEST, 0, 0,
NULL, TIMEOUT_1SEC);
4296 cb_log (1, help->
port,
"Destroying this port.\n");
4301 cb_log(4, 0,
"Killing Handler Thread\n");
4303 cb_log(4, 0,
"Joining Handler Thread\n");
4307 cb_log(4, 0,
"Killing Main Thread\n");
4309 cb_log(4, 0,
"Joining Main Thread\n");
4314 cb_log(1, 0,
"Closing mISDN device\n");
4336 cb_log(0, bc->
port,
"bchannel_activate: Stack not found !");
4341 clear_ibuffer(bc->
astbuf);
4343 cb_log(5, stack->
port,
"$$$ Bchan Activated addr %x\n", bc->
addr);
4345 mISDN_write_frame(stack->
midev, buf, bc->
addr | FLG_MSG_DOWN, DL_ESTABLISH | REQUEST, 0,0,
NULL, TIMEOUT_1SEC);
4363 cb_log( 4, bc->
port,
"bchan_deactivate: called but not activated\n");
4368 cb_log(5, stack->
port,
"$$$ Bchan deActivated addr %x\n", bc->
addr);
4372 mISDN_write_frame(stack->
midev, buf, bc->
addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,
NULL, TIMEOUT_1SEC);
4374 clear_ibuffer(bc->
astbuf);
4385 char buf[4096 + mISDN_HEADER_LEN];
4386 iframe_t *frm = (iframe_t*)buf;
4397 frm->prim = DL_DATA|REQUEST;
4399 frm->addr = bc->
addr | FLG_MSG_DOWN ;
4402 memcpy(&buf[mISDN_HEADER_LEN], data,len);
4407 cb_log(6, stack->
port,
"Writing %d data bytes\n",len);
4409 cb_log(9, stack->
port,
"Writing %d bytes 2 mISDN\n",len);
4410 mISDN_write(stack->
midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT);
4421 unsigned char buffer[mISDN_HEADER_LEN+2*
sizeof(int)];
4422 iframe_t *ctrl = (iframe_t *)buffer;
4423 unsigned int *
d = (
unsigned int*)&ctrl->data.p;
4426 cb_log(4,bc->
port,
"ph_control: c1:%x c2:%x\n",c1,c2);
4428 ctrl->prim = PH_CONTROL | REQUEST;
4429 ctrl->addr = bc->
addr | FLG_MSG_DOWN;
4431 ctrl->len =
sizeof(
unsigned int)*2;
4434 mISDN_write(glob_mgr->
midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
4472 unsigned char buffer[mISDN_HEADER_LEN+
sizeof(int)+c2_len];
4473 iframe_t *ctrl = (iframe_t *)buffer;
4474 unsigned int *
d = (
unsigned int *)&ctrl->data.p;
4477 ctrl->prim = PH_CONTROL | REQUEST;
4478 ctrl->addr = bc->
addr | FLG_MSG_DOWN;
4480 ctrl->len =
sizeof(
unsigned int) + c2_len;
4482 memcpy(d, c2, c2_len);
4483 mISDN_write(glob_mgr->
midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
4493 if (stack && bc->
channel > 0) {
4536 if (!stack || ! stack->
holding)
return;
4538 if (holder == stack->
holding) {
4546 if (h1->
next == holder) {
4557 cb_log(4, stack->
port,
"*HOLDER: find %lx\n",l3id);
4562 if (help->
l3_id == l3id) {
4563 cb_log(4,stack->
port,
"*HOLDER: found bc\n");
4568 cb_log(4,stack->
port,
"*HOLDER: find nothing\n");
4587 if (stack->
port == port) {
4598 char buf[mISDN_HEADER_LEN + 128] =
"";
4599 iframe_t *frm = (iframe_t*)buf;
4619 frm->prim=DL_DATA|REQUEST;
4620 frm->addr=bc->
addr|FLG_MSG_DOWN;
4624 mISDN_write(glob_mgr->
midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
4632 cb_log(4, stack?stack->
port:0,
"ec_enable\n");
4635 cb_log(1, stack?stack->
port:0,
" --> no speech? cannot enable EC\n");
4639 if (*bc->pipeline) {
4640 cb_log(3, stack?stack->
port:0,
"Sending Control PIPELINE_CFG %s\n",bc->pipeline);
4662 cb_log(0, stack->
port,
"Taps should be power of 2\n");
4681 cb_log(4, stack?stack->
port:0,
" --> ec_disable\n");
4684 cb_log(1, stack?stack->
port:0,
" --> no speech? cannot disable EC\n");
4692 cb_log(3, stack?stack->
port:0,
"Sending Control ECHOCAN_OFF\n");
4713 cb_log(3,bc->
port,
"Joining bc:%x in conf:%d\n",bc->
addr,conf_id);
4725 cb_log(4,bc->
port,
"Splitting bc:%x in conf:%d\n",bc->
addr,conf_id);
4730 int conf_id = bc1->
pid + 1;
4736 for (bc=bc_list; *
bc; bc++) {
4738 cb_log(4, (*bc)->port,
" --> bc_addr:%x\n",(*bc)->addr);
4740 switch((*bc)->bc_state) {
4759 for (bc=bc_list; *
bc; bc++) {
4763 cb_log( 2, (*bc)->port,
"BC not bridged (state:%s) so not splitting it\n",
bc_state2str((*bc)->bc_state));
4773 cb_log(3,bc->
port,
" --> ECHO %s\n", onoff?
"ON":
"OFF");
4787 cleanup_Isdnl3(&stack->
nst);
4788 cleanup_Isdnl2(&stack->
nst);
4791 memset(&stack->
nst, 0,
sizeof(net_stack_t));
4792 memset(&stack->
mgr, 0,
sizeof(manager_t));
4794 stack->
mgr.nst = &stack->
nst;
4795 stack->
nst.manager = &stack->
mgr;
4798 stack->
nst.device = glob_mgr->
midev;
4802 stack->
nst.feature = FEATURE_NET_HOLD;
4804 stack->
nst.feature |= FEATURE_NET_PTP;
4806 stack->
nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
4811 msg_queue_init(&stack->
nst.down_queue);
4813 Isdnl2Init(&stack->
nst);
4814 Isdnl3Init(&stack->
nst);
static char tone_silence_flip[TONE_SILENCE_SIZE]
int misdn_lib_maxports_get(void)
static int misdn_lib_get_l2_down(struct misdn_stack *stack)
int misdn_lib_init(char *portlist, struct misdn_lib_iface *iface, void *user_data)
static msg_t * fetch_msg(int midev)
static void empty_chan_in_stack(struct misdn_stack *stack, int channel)
struct misdn_stack * get_misdn_stack(void)
char keypad[MISDN_MAX_KEYPAD_LEN]
Q.931 Keypad Facility IE contents.
int upper_id
Upper layer mISDN ID (addr) (Layer 2/4)
enum sip_cc_notify_state state
int display_setup
Put a display ie in the SETUP message.
#define pthread_mutex_init
static void clear_l3(struct misdn_stack *stack)
struct FacParm fac_out
Outbound FACILITY message function type and contents.
void manager_bchannel_deactivate(struct misdn_bchannel *bc)
void manager_bchannel_cleanup(struct misdn_bchannel *bc)
char number[MISDN_MAX_NUMBER_LEN]
Phone number (Address)
static int handle_cr(struct misdn_stack *stack, iframe_t *frm)
void misdn_lib_nt_debug_init(int flags, char *file)
int procids[MAXPROCS]
CR Process ID allocation table. TRUE if ID allocated.
int misdn_lib_pid_restart(int pid)
void stack_holder_add(struct misdn_stack *stack, struct misdn_bchannel *holder)
int layer
B channel layer; set to 3 or 4.
char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
static char * bearer2str(int cap)
int nodsp
TRUE if we will not use jollys dsp.
static int handle_mgmt(msg_t *msg)
static int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, int port, int bidx)
int txgain
Tx gain setting (range -8 to 8)
static void init_flip_bits(void)
int ec_enable
TRUE if the echo cancellor is enabled.
static int handle_event_te(struct misdn_bchannel *bc, enum event_e event, iframe_t *frm)
int tone_cnt
Number of tone samples to generate.
void misdn_tx_jitter(struct misdn_bchannel *bc, int len)
int midev
mISDN device handle returned by mISDN_open()
int presentation
User set presentation restriction code 0=Allowed, 1=Restricted, 2=Unavailable.
int uulen
User-User information string length in uu[].
char uu[256]
User-User information string.
static int do_tone(struct misdn_bchannel *bc, int len)
static int clean_up_bc(struct misdn_bchannel *bc)
int midev
mISDN device handle returned by mISDN_open()
int dummy
TRUE if this is a dummy BC record.
void misdn_dump_chanlist(void)
#define mISDNUSER_HEAD_SIZE
int stack_holder
TRUE if this channel is on the misdn_stack->holding list.
int restart_channel
B channel to restart if received a RESTART message.
int bframe_len
B channel speech sample data buffer size.
void manager_ec_enable(struct misdn_bchannel *bc)
char * manager_isdn_get_info(enum event_e event)
static char flip_table[256]
int mode
Q.931 Bearer Capability IE Transfer Mode field. Initialized to 0 (Circuit). Altered by incoming SETUP...
static struct misdn_stack * find_stack_by_mgr(manager_t *mgr_nt)
int cw
TRUE if call waiting.
void(* cb_log)(int level, int port, char *tmpl,...)
void misdn_make_dummy(struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel)
int hdlc
TRUE if call made in digital HDLC mode.
void misdn_lib_tone_generator_start(struct misdn_bchannel *bc)
struct misdn_bchannel * stack_holder_find(struct misdn_stack *stack, unsigned long l3id)
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
B channel control structure.
int outgoing_colp
Select what to do with outgoing COLP information.
int presentation
Number presentation restriction code 0=Allowed, 1=Restricted, 2=Unavailable.
#define ISDN_PID_L4_B_USER
int sending_complete
TRUE if all digits necessary to complete the call are available. No more INFORMATION messages are nee...
static int handle_l1(msg_t *msg)
static enum global_states global_state
char crypt_key[255]
Blowfish encryption key string (secret)
void misdn_lib_reinit_nt_stack(int port)
static struct misdn_bchannel * find_bc_by_confid(unsigned long confid)
struct send_lock * send_lock
B channel send locking structure.
static struct misdn_stack * stack_init(int midev, int port, int ptp)
static int setup_bc(struct misdn_bchannel *bc)
int capability
SETUP message bearer capability field code value.
void misdn_lib_tone_generator_stop(struct misdn_bchannel *bc)
void misdn_lib_destroy(void)
void * astbuf
Not used. Contents are setup but not used.
struct misdn_bchannel * misdn_lib_find_held_bc(int port, int l3_id)
Find a held call's B channel record.
static void misdn_lib_isdn_event_catcher(void *arg)
static struct misdn_bchannel * find_bc_by_addr(unsigned long addr)
int AOCD_need_export
TRUE if AOCDtype and AOCD data are ready to export to Asterisk.
static void bc_next_state_change(struct misdn_bchannel *bc, enum bchannel_state state)
#define AST_CAUSE_NORMAL_CIRCUIT_CONGESTION
void manager_clean_bc(struct misdn_bchannel *bc)
static msg_t * create_l2msg(int prim, int dinfo, int size)
int misdn_lib_get_maxchans(int port)
void isdn_lib_update_rxgain(struct misdn_bchannel *bc)
struct misdn_party_id to
Where the call is being redirected toward (Sent to the calling party)
int progress_location
Progress Indicator IE location field.
struct misdn_bchannel * find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id)
static int handle_bchan(msg_t *msg)
struct misdn_bchannel * next
Next node in the misdn_stack.holding list.
void isdn_lib_update_txgain(struct misdn_bchannel *bc)
int misdn_cap_is_speech(int cap)
void isdn_lib_update_ec(struct misdn_bchannel *bc)
void get_show_stack_details(int port, char *buf)
int misdn_lib_is_port_blocked(int port)
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
int misdn_lib_get_port_info(int port)
enum event_e isdn_msg_get_event(struct isdn_msg msgs[], msg_t *frm, int nt)
msg_t * create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
int pri
TRUE if ISDN-PRI (ISDN-BRI otherwise)
int l1link
TRUE if Layer 1 is UP.
static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec)
int misdn_lib_get_l2_up(struct misdn_stack *stack)
int layer_id
B Channel mISDN driver layer ID from mISDN_new_layer()
#define pthread_mutex_destroy
int misdn_inband_avail(struct misdn_bchannel *bc)
void misdn_lib_split_bridge(struct misdn_bchannel *bc1, struct misdn_bchannel *bc2)
int set_presentation
TRUE if the user set the presentation restriction code.
msg_t * isdn_msg_build_event(struct isdn_msg msgs[], struct misdn_bchannel *bc, enum event_e event, int nt)
char number[MISDN_MAX_NUMBER_LEN]
Dialed/Called Phone Number (Address)
void manager_ec_disable(struct misdn_bchannel *bc)
char display[84]
Display message that can be displayed by the user phone.
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
int pri
TRUE if ISDN-PRI (ISDN-BRI otherwise)
#define pthread_mutex_lock
static int release_cr(struct misdn_stack *stack, mISDNuser_head_t *hh)
int misdn_lib_port_block(int port)
int lower_id
Lower layer mISDN ID (addr) (Layer 1/3)
static int handle_err(msg_t *msg)
int conf_id
Bridging conference ID.
char subaddress[MISDN_MAX_SUBADDRESS_LEN]
Dialed/Called Subaddress number.
int need_release_complete
TRUE if RELEASE_COMPLETE needs to be sent to clear a call.
static void prepare_bc(struct misdn_bchannel *bc, int channel)
static int handle_frm_nt(msg_t *msg)
int manager_isdn_handler(iframe_t *frm, msg_t *msg)
void misdn_lib_release(struct misdn_bchannel *bc)
#define AST_CAUSE_NORMAL_CLEARING
int d_stid
D Channel mISDN driver stack ID (Parent stack ID)
void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2)
static void misdn_send_unlock(struct misdn_bchannel *bc)
int nt
TRUE if NT side of protocol (TE otherwise)
enum mISDN_NUMBER_TYPE number_type
Type-of-number in ISDN terms for the number.
void misdn_lib_log_ies(struct misdn_bchannel *bc)
int holded
TRUE if this channel is on hold.
void manager_bchannel_activate(struct misdn_bchannel *bc)
void bc_state_change(struct misdn_bchannel *bc, enum bchannel_state state)
int display_connected
Put a display ie in the CONNECT message.
int nojitter
TRUE if we will not use the jitter buffer system.
char infos_pending[MISDN_MAX_NUMBER_LEN]
Collected digits to go into info_dad[] while waiting for a SETUP_ACKNOWLEDGE to come in...
struct misdn_party_id caller
Originating/Caller ID information struct.
static char tone_425_flip[TONE_425_SIZE]
char name[MISDN_MAX_NAME_LEN]
Subscriber Name.
void misdn_split_conf(struct misdn_bchannel *bc, int conf_id)
static void empty_bc(struct misdn_bchannel *bc)
int rxgain
Rx gain setting (range -8 to 8)
static void misdn_send_lock(struct misdn_bchannel *bc)
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
char * bc_state2str(enum bchannel_state state)
static int misdn_lib_get_l1_down(struct misdn_stack *stack)
Syslog support functions for Asterisk logging.
int(* cb_jb_empty)(struct misdn_bchannel *bc, char *buffer, int len)
int progress_coding
Progress Indicator IE coding standard field.
int restart_sent
TRUE if restart has been sent to the other side after stack startup.
int b_stid
B Channel mISDN driver stack ID.
int misdn_lib_port_unblock(int port)
void misdn_lib_nt_keepcalls(int kc)
int misdn_lib_is_ptp(int port)
enum bchannel_state next_bc_state
This is used as a pending bridge join request for when bc_state becomes BCHAN_ACTIVATED.
struct misdn_party_id connected
Connected-Party/Connected-Line ID information struct.
static int set_chan_in_stack(struct misdn_stack *stack, int channel)
int pid
B channel process ID (1-5000)
void stack_holder_remove(struct misdn_stack *stack, struct misdn_bchannel *holder)
int misdn_lib_tx2misdn_frm(struct misdn_bchannel *bc, void *data, int len)
struct misdn_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
int dec
TRUE if allocate higher B channels first.
void ec_chunk(struct misdn_bchannel *bc, unsigned char *rxchunk, unsigned char *txchunk, int chunk_size)
enum mISDN_NUMBER_TYPE number_type
Type-of-number in ISDN terms for the dialed/called number.
static int send_msg(int midev, struct misdn_bchannel *bc, msg_t *dmsg)
int in_use
TRUE if B channel record is in use.
static struct misdn_lib * glob_mgr
void manager_ph_control_block(struct misdn_bchannel *bc, int c1, void *c2, int c2_len)
int misdn_lib_send_restart(int port, int channel)
int l2link
TRUE if Layer 2 is UP.
void bchdev_echocancel_deactivate(struct misdn_bchannel *dev)
char subaddress[MISDN_MAX_SUBADDRESS_LEN]
Subaddress number.
void misdn_lib_echo(struct misdn_bchannel *bc, int onoff)
msg_queue_t downqueue
Queue of Event messages to send to mISDN.
int channel_found
TRUE if the channel was allocated from the available B channels.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int send_dtmf
TRUE if we should produce DTMF tones ourselves.
static int handle_event_nt(void *dat, void *arg)
int l2upcnt
Number of consecutive times PTP Layer 2 declared down.
struct misdn_party_redirecting redirecting
Redirecting information struct (Where a call diversion or transfer was invoked)
int ptp
TRUE if Point-To-Point(PTP) (Point-To-Multipoint(PTMP) otherwise)
char channels[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
Array of B channels in use (a[0] = B1). TRUE if B channel in use. (Must be dimensioned the same as st...
int port
Logical Layer 1 port associated with this B channel.
int urate
Q.931 Bearer Capability IE Layer 1 User Rate field.
struct misdn_party_dialing dialed
Dialed/Called information struct.
int is_register_pool
TRUE if the B channel is allocated from the REGISTER pool.
static int create_process(int midev, struct misdn_bchannel *bc)
int misdn_lib_get_port_up(int port)
int addr
B Channel mISDN driver layer ID from mISDN_get_layerid()
void misdn_lib_send_tone(struct misdn_bchannel *bc, enum tone_e tone)
int nt
TRUE if NT side of protocol (TE otherwise)
int(* cb_jb_empty)(struct misdn_bchannel *bc, char *buffer, int len)
int active
Seems to have been intended for something to do with the jitter buffer.
struct misdn_bchannel * misdn_lib_get_free_bc(int port, int channel, int inout, int dec)
int misdn_lib_port_up(int port, int check)
int misdn_lib_port_is_nt(int port)
int to_changed
TRUE if the redirecting.to information has changed.
void manager_bchannel_setup(struct misdn_bchannel *bc)
void misdn_join_conf(struct misdn_bchannel *bc, int conf_id)
static struct misdn_stack * find_stack_by_port(int port)
int channel
Assigned B channel number B1, B2... 0 if not assigned.
struct misdn_stack * next
Next stack in the list of stacks.
struct misdn_bchannel * holding
List of held channels.
int out_cause
Q.931 Cause for disconnection code (sent)
void te_lib_destroy(int midev)
static int misdn_lib_get_short_status(struct misdn_stack *stack)
#define AST_CAUSE_REQUESTED_CHAN_UNAVAIL
static void stack_destroy(struct misdn_stack *stack)
enum mISDN_REDIRECTING_REASON reason
Reason a call is being redirected (Q.931 field value)
static char * flip_buf_bits(char *buf, int len)
pthread_t event_handler_thread
void misdn_lib_isdn_l1watcher(int port)
int need_release
TRUE if RELEASE needs to be sent to clear a call.
int need_more_infos
TRUE if we send SETUP_ACKNOWLEDGE on incoming calls anyway (instead of PROCEEDING).
int dtmf
Last decoded DTMF digit from mISDN driver.
enum bchannel_state bc_state
Current B Channel state.
int blocked
TRUE if port is blocked.
static struct misdn_stack * find_stack_by_addr(int addr)
static unsigned char * buff
static void dump_chan_list(struct misdn_stack *stack)
int need_disconnect
TRUE if DISCONNECT needs to be sent to clear a call.
int misdn_lib_port_is_pri(int port)
#define AST_CAUSE_USER_BUSY
int misdn_lib_get_port_down(int port)
int user1
Q.931 Bearer Capability IE User Information Layer 1 Protocol field code.
enum mISDN_NOTIFY_CODE notify_description_code
Notification indicator ie description code.
void isdn_lib_stop_dtmf(struct misdn_bchannel *bc)
int progress_indicator
Progress Indicator IE progress description field. Used to determine if there is an inband audio messa...
Internal Asterisk hangup causes.
int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event)
int rate
Q.931 Bearer Capability IE Information Transfer Rate field. Initialized to 0x10 (64kbit). Altered by incoming SETUP messages.
int ec_deftaps
Number of taps in the echo cancellor when enabled.
static int handle_timers(msg_t *msg)
int channel_preselected
TRUE if the B channel number is preselected.
int misdn_lib_port_restart(int port)
#define ISDN_PID_L3_B_USER
static struct misdn_bchannel * find_bc_by_masked_l3id(struct misdn_stack *stack, unsigned long l3id, unsigned long mask)
char * bframe
B channel speech sample data buffer.
#define pthread_mutex_unlock
static int misdn_lib_get_l1_up(struct misdn_stack *stack)
static int handle_l2(msg_t *msg)
struct misdn_bchannel * manager_find_bc_by_pid(int pid)
int cause
Q.931 Cause for disconnection code (received)
char info_dad[MISDN_MAX_NUMBER_LEN]
Current overlap dialing digits to/from INFORMATION messages.
void misdn_lib_bridge(struct misdn_bchannel *bc1, struct misdn_bchannel *bc2)
int te_choose_channel
TRUE if the TE side should choose the B channel to use.
struct timeval last_used
Time when empty_bc() last called on this record.
static void manager_event_handler(void *arg)
static int test_inuse(struct misdn_bchannel *bc)
int port
Logical Layer 1 port associated with this stack.
int bchdev_echocancel_activate(struct misdn_bchannel *dev)
int screening
Number screening code 0=Unscreened, 1=Passed Screen, 2=Failed Screen, 3=Network Number.
msg_queue_t activatequeue
struct misdn_stack * stack_list
int law
Companding ALaw/uLaw encoding (INFO_CODEC_ALAW / INFO_CODEC_ULAW)
static snd_pcm_format_t format
static const char * fac2str(enum FacFunction facility)
void(* cb_log)(int level, int port, char *tmpl,...)
int orig
Who originated the call (ORG_AST, ORG_MISDN)
struct FacParm fac_in
Inbound FACILITY message function type and contents.
int generate_tone
TRUE if tone generator allowed to start.
int isdn_msg_parse_event(struct isdn_msg msgs[], msg_t *frm, struct misdn_bchannel *bc, int nt)
enum mISDN_NUMBER_PLAN number_plan
Type-of-number numbering plan.
int b_stids[MAX_BCHANS+1]
B Channel mISDN driver stack IDs (Child stack IDs)
static sem_t handler_started
pthread_mutex_t st_lock
Stack struct critical section lock.
int count
Number of times the call has been redirected.
static int handle_frm_te(msg_t *msg)
enum mISDN_NUMBER_PLAN number_plan
Type-of-number numbering plan.
int l3_id
Layer 3 process ID.
static int te_lib_init(void)
int early_bconnect
TRUE if the call progress indicators can indicate an inband audio message for the user to listen to...