X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=mISDN.cpp;h=3c4c23d44608bbddf2bd55a391bcd9e14531c807;hp=63b2c2a9d1dba67b60cf14e001cde98aeacd487b;hb=e01d4caa3eef0f4d17e5513cb793e19fecd2b051;hpb=ce197cab91d66c14f11d818f343720a785dd616e diff --git a/mISDN.cpp b/mISDN.cpp index 63b2c2a..3c4c23d 100644 --- a/mISDN.cpp +++ b/mISDN.cpp @@ -28,7 +28,7 @@ #include #else extern "C" { -#include +#include } #endif @@ -780,9 +780,9 @@ void bchannel_event(struct mISDNport *mISDNport, int i, int event) unsigned long p_m_remote_ref = 0; unsigned long p_m_remote_id = 0; #ifdef SOCKET_MISDN - unsigned long handle = mISDNport->b_addr[i]; + unsigned long portid = (mISDNport->portnum<<8) + i+1+(i>=15); #else - int handle = mISDNport->b_addr[i]; + unsigned long portid = mISDNport->b_addr[i]; #endif if (b_port) @@ -803,13 +803,13 @@ void bchannel_event(struct mISDNport *mISDNport, int i, int event) if (p_m_remote_ref) { /* export bchannel */ - message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, handle); + message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid); chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE); add_trace("type", NULL, "assign"); #ifdef SOCKET_MISDN - add_trace("stack", "address", "%x", handle); + add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff); #else - add_trace("socket", "id", "%d", handle); + add_trace("socket", "id", "%d", portid); #endif end_trace(); state = B_STATE_EXPORTING; @@ -858,13 +858,13 @@ void bchannel_event(struct mISDNport *mISDNport, int i, int event) /* in case, the bchannel is exported right after seize_bchannel */ /* export bchannel */ /* p_m_remote_id is set, when this event happens. */ - message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, handle); + message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid); chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE); add_trace("type", NULL, "assign"); #ifdef SOCKET_MISDN - add_trace("stack", "address", "%x", handle); + add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff); #else - add_trace("socket", "id", "%d", handle); + add_trace("socket", "id", "%d", portid); #endif end_trace(); state = B_STATE_EXPORTING; @@ -933,13 +933,13 @@ void bchannel_event(struct mISDNport *mISDNport, int i, int event) * OR bchannel is not used anymore * OR bchannel has been exported to an obsolete ref, * so reimport, to later export to new remote */ - message_bchannel_to_join(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, handle); + message_bchannel_to_join(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, portid); chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE); add_trace("type", NULL, "remove"); #ifdef SOCKET_MISDN - add_trace("stack", "address", "%x", handle); + add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff); #else - add_trace("socket", "id", "%d", handle); + add_trace("socket", "id", "%d", portid); #endif end_trace(); state = B_STATE_IMPORTING; @@ -973,13 +973,13 @@ void bchannel_event(struct mISDNport *mISDNport, int i, int event) case B_STATE_REMOTE: /* bchannel is exported, so we re-import */ - message_bchannel_to_join(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, handle); + message_bchannel_to_join(mISDNport->b_remote_id[i], 0, BCHANNEL_REMOVE, portid); chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE); add_trace("type", NULL, "remove"); #ifdef SOCKET_MISDN - add_trace("stack", "address", "%x", handle); + add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff); #else - add_trace("socket", "id", "%d", handle); + add_trace("socket", "id", "%d", portid); #endif end_trace(); state = B_STATE_IMPORTING; @@ -1010,13 +1010,13 @@ void bchannel_event(struct mISDNport *mISDNport, int i, int event) /* bchannel is now deactivate, but is requied by Port class, so we reactivate / export */ if (p_m_remote_ref) { - message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, handle); + message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid); chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE); add_trace("type", NULL, "assign"); #ifdef SOCKET_MISDN - add_trace("stack", "address", "%x", handle); + add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff); #else - add_trace("socket", "id", "%d", handle); + add_trace("socket", "id", "%d", portid); #endif end_trace(); state = B_STATE_EXPORTING; @@ -1050,13 +1050,13 @@ void bchannel_event(struct mISDNport *mISDNport, int i, int event) /* bchannel is now imported, but is requied by Port class, so we reactivate / export */ if (p_m_remote_ref) { - message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, handle); + message_bchannel_to_join(p_m_remote_id, p_m_remote_ref, BCHANNEL_ASSIGN, portid); chan_trace_header(mISDNport, b_port, "MESSAGE_BCHANNEL (to remote application)", DIRECTION_NONE); add_trace("type", NULL, "assign"); #ifdef SOCKET_MISDN - add_trace("stack", "address", "%x", handle); + add_trace("channel", NULL, "%d.%d", portid>>8, portid&0xff); #else - add_trace("socket", "id", "%d", handle); + add_trace("socket", "id", "%d", portid); #endif end_trace(); state = B_STATE_EXPORTING; @@ -1173,15 +1173,14 @@ seize: */ void PmISDN::drop_bchannel(void) { - if (p_m_b_index < 0) - return; - /* unreserve channel */ if (p_m_b_reserve) p_m_mISDNport->b_reserved--; p_m_b_reserve = 0; /* if not in use */ + if (p_m_b_index < 0) + return; if (!p_m_b_channel) return; @@ -1265,7 +1264,7 @@ void message_bchannel_from_join(class JoinRemote *joinremote, int type, unsigned #ifdef SOCKET_MISDN if (mISDNport->b_socket[i] == handle) #else - if (mISDNport->b_addr[i] == handle) + if ((unsigned long)(mISDNport->portnum<<8)+i+1+(i>=15) == handle) #endif break; i++; @@ -1383,7 +1382,9 @@ int PmISDN::handler(void) p_m_load = 0; /* to send data, tone must be active OR crypt messages must be on */ - if ((p_tone_name[0] || p_m_crypt_msg_loops) && p_m_load < ISDN_LOAD) + if ((p_tone_name[0] || p_m_crypt_msg_loops) + && (p_m_load < ISDN_LOAD) + && (p_state==PORT_STATE_CONNECT || p_m_mISDNport->tones)) { int tosend = ISDN_LOAD - p_m_load, length; #ifdef SOCKET_MISDN @@ -1416,6 +1417,7 @@ int PmISDN::handler(void) /* next loop */ p_m_crypt_msg_current = 0; p_m_crypt_msg_loops--; +// puts("eine loop weniger"); } /* new length */ @@ -1532,6 +1534,21 @@ void PmISDN::bchannel_receive(iframe_t *frm) message_put(message); break; + default: + chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN); + add_trace("unknown", NULL, "0x%x", cont); + end_trace(); + } + return; + } +#ifdef SOCKET_MISDN + if (hh->prim == PH_SIGNAL_IND) +#else + if (frm->prim == (PH_SIGNAL | INDICATION)) +#endif + { + switch(frm->dinfo) + { case CMX_TX_DATA: if (!p_m_txdata) { @@ -1539,13 +1556,18 @@ void PmISDN::bchannel_receive(iframe_t *frm) PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) ignoring tx data, because 'txdata' is turned off\n", p_name); return; } + /* see below (same condition) */ + if (p_state!=PORT_STATE_CONNECT + && !p_m_mISDNport->tones) + break; +// printf(".");fflush(stdout);return; if (p_record) - record((unsigned char *)(cont+1), len - 4, 1); // from up + record(data, len, 1); // from up break; default: - chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN); - add_trace("unknown", NULL, "0x%x", cont); + chan_trace_header(p_m_mISDNport, this, "BCHANNEL signal", DIRECTION_IN); + add_trace("unknown", NULL, "0x%x", frm->dinfo); end_trace(); } return; @@ -1561,14 +1583,13 @@ void PmISDN::bchannel_receive(iframe_t *frm) #endif return; } - /* calls will not process any audio data unless * the call is connected OR interface features audio during call setup. */ //printf("%d -> %d prim=%x joindata=%d tones=%d\n", p_serial, ACTIVE_EPOINT(p_epointlist), frm->prim, p_m_joindata, p_m_mISDNport->earlyb); #ifndef DEBUG_COREBRIDGE if (p_state!=PORT_STATE_CONNECT - && !p_m_mISDNport->earlyb) + && !p_m_mISDNport->tones) return; #endif @@ -1896,7 +1917,7 @@ void PmISDN::message_crypt(unsigned long epoint_id, int message_id, union parame break; } p_m_crypt_msg_current = 0; /* reset */ - p_m_crypt_msg_loops = 3; /* enable */ + p_m_crypt_msg_loops = 6; /* enable */ #if 0 /* disable txmix, or we get corrupt data due to audio process */ if (p_m_txmix && p_m_b_index>=0) @@ -1947,19 +1968,177 @@ int PmISDN::message_epoint(unsigned long epoint_id, int message_id, union parame /* - * main loop for processing messages from mISDN device + * main loop for processing messages from mISDN */ +#ifdef SOCKET_MISDN +int mISDN_handler(void) +{ + int ret, work = 0; + struct mISDNport *mISDNport; + class PmISDN *isdnport; + int i; + char buffer[2048+MISDN_HEADER_LEN]; + struct mISDNhead *hh = (struct mISDNhead *)buffer; + + /* process all ports */ + mISDNport = mISDNport_first; + while(mISDNport) + { + /* process all bchannels */ + i = 0; + while(i < mISDNport->b_num) + { + /* handle port of bchannel */ + isdnport=mISDNport->b_port[i]; + if (isdnport) + { + /* call bridges in user space OR crypto OR recording */ + if (isdnport->p_m_joindata || isdnport->p_m_crypt_msg_loops || isdnport->p_m_crypt_listen || isdnport->p_record) + { + /* rx IS required */ + if (isdnport->p_m_rxoff) + { + /* turn on RX */ + isdnport->p_m_rxoff = 0; + PDEBUG(DEBUG_BCHANNEL, "%s: receive data is required, so we turn them on\n"); + if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE) + ph_control(mISDNport, isdnport, mISDNport->b_socket[isdnport->p_m_b_index], CMX_RECEIVE_ON, 0, "DSP-RXOFF", 0); + return(1); + } + } else + { + /* rx NOT required */ + if (!isdnport->p_m_rxoff) + { + /* turn off RX */ + isdnport->p_m_rxoff = 1; + PDEBUG(DEBUG_BCHANNEL, "%s: receive data is not required, so we turn them off\n"); + if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE) + ph_control(mISDNport, isdnport, mISDNport->b_socket[isdnport->p_m_b_index], CMX_RECEIVE_OFF, 0, "DSP-RXOFF", 1); + return(1); + } + } + /* recording */ + if (isdnport->p_record) + { + /* txdata IS required */ + if (!isdnport->p_m_txdata) + { + /* turn on RX */ + isdnport->p_m_txdata = 1; + PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is required, so we turn them on\n"); + if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE) + ph_control(mISDNport, isdnport, mISDNport->b_socket[isdnport->p_m_b_index], CMX_TXDATA_ON, 0, "DSP-TXDATA", 1); + return(1); + } + } else + { + /* txdata NOT required */ + if (isdnport->p_m_txdata) + { + /* turn off RX */ + isdnport->p_m_txdata = 0; + PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is not required, so we turn them off\n"); + if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE) + ph_control(mISDNport, isdnport, mISDNport->b_socket[isdnport->p_m_b_index], CMX_TXDATA_OFF, 0, "DSP-TXDATA", 0); + return(1); + } + } + } + + /* handle message from bchannel */ + if (mISDNport->b_stack[i] > -1) + { + ret = recv(mISDNport->b_stack[i], buffer, sizeof(buffer), 0); + if (ret >= MISDN_HEADER_LEN) + { + work = 1; + switch(hh->prim) + { + /* we don't care about confirms, we use rx data to sync tx */ + case PH_DATA_CONF: + case DL_DATA_CONF: + break; + + /* we receive audio data, we respond to it AND we send tones */ + case PH_DATA_IND: + case DL_DATA_IND: + case PH_SIGNAL_IND: + case PH_CONTROL_IND: + if (mISDNport->b_port[i]) + mISDNport->b_port[i]->bchannel_receive(hh, buffer+MISDN_HEADER_LEN, ret-MISDN_HEADER_LEN); + else + PDEBUG(DEBUG_BCHANNEL, "b-channel is not associated to an ISDNPort (socket %d), ignoring.\n", mISDNport->b_stack[i]); + break; + + case PH_ACTIVATE_IND: + case DL_ESTABLISH_IND: + case PH_ACTIVATE_CONF: + case DL_ESTABLISH_CONF: + PDEBUG(DEBUG_BCHANNEL, "DL_ESTABLISH confirm: bchannel is now activated (socket %d).\n", mISDNport->b_socket[i]); + bchannel_event(mISDNport, i, B_EVENT_ACTIVATED); + break; + + case PH_DEACTIVATE_IND: + case DL_RELEASE_IND: + case PH_DEACTIVATE_CONF: + case DL_RELEASE_CONF: + PDEBUG(DEBUG_BCHANNEL, "DL_RELEASE confirm: bchannel is now de-activated (socket %d).\n", mISDNport->b_socket[i]); + bchannel_event(mISDNport, i, B_EVENT_DEACTIVATED); + break; + + default: + PERROR("child message not handled: prim(0x%x) socket(%d) msg->len(%d)\n", hh->prim, mISDNport->b_socket[i], msg->len); + } + } else + { + if (ret < 0 && errno != EWOULDBLOCK) + PERROR("Read from port %d, index %d failed with return code %d\n", mISDNport->portnum, i, ret); + } + } + + i++; + } +#if 0 + if (mISDNport->l1timeout && now>mISDNport->l1timeout) + { ---} + PDEBUG(DEBUG_ISDN, "the L1 establish timer expired, we release all pending messages.\n", mISDNport->portnum); + mISDNport->l1timeout = 0; +#endif + + /* layer 2 establish timer */ + if (mISDNport->l2establish) + { + if (now-mISDNport->l2establish > 5) + { + + PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link portnum=%d.\n", mISDNport->portnum); + mISDNport->ml3->to_layer2(mISDNport->ml3, DL_ESTABLISH_REQ); + l1l2l3_trace_header(mISDNport, NULL, DL_ESTABLISH_REQ, DIRECTION_OUT); + end_trace(); + return(1); + } + } + + + mISDNport = mISDNport->next; + } + + /* if we received at least one b-frame, we will return 1 */ + return(work); +} +#else int mISDN_handler(void) { int ret; - msg_t *msg; - iframe_t *frm; struct mISDNport *mISDNport; class PmISDN *isdnport; - net_stack_t *nst; + int i; + msg_t *msg; + iframe_t *frm; msg_t *dmsg; mISDNuser_head_t *hh; - int i; + net_stack_t *nst; /* the que avoids loopbacks when replying to stack after receiving * from stack. */ @@ -2030,7 +2209,7 @@ int mISDN_handler(void) } #if 0 if (mISDNport->l1timeout && now>mISDNport->l1timeout) - { + { ---} PDEBUG(DEBUG_ISDN, "the L1 establish timer expired, we release all pending messages.\n", mISDNport->portnum); mISDNport->l1timeout = 0; #endif @@ -2048,10 +2227,11 @@ int mISDN_handler(void) if (mISDNport->nst.manager_l3(&mISDNport->nst, dmsg)) free_msg(dmsg); } else { + iframe_t act; + PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link TE portnum=%d.\n", mISDNport->portnum); time(&mISDNport->l2establish); /* establish */ - iframe_t act; act.prim = DL_ESTABLISH | REQUEST; act.addr = (mISDNport->upper_id & ~LAYER_ID_MASK) | 3 | FLG_MSG_DOWN; act.dinfo = 0; @@ -2305,6 +2485,7 @@ int mISDN_handler(void) case PH_DATA | INDICATION: case DL_DATA | INDICATION: case PH_CONTROL | INDICATION: + case PH_SIGNAL | INDICATION: i = 0; while(i < mISDNport->b_num) { @@ -2374,6 +2555,119 @@ int mISDN_handler(void) free_msg(msg); return(1); } +#endif + +#ifdef SOCKET_MISDN +int do_layer3(struct mlayer3 *ml3, unsigned int cmd, unsigned int pid, struct l3_msg *l3m) +{ + struct mISDNport *mISDNport = ml3->private; + + if (cmd == MT_ASSIGN) + { + ueberdenken!!! + } + + /* lock LCR */ + achtung MT_ASSIGN kommt hier an + lock it baby + + /* d-message */ + switch(cmd) + { + case MGR_SHORTSTATUS_IND: + case MGR_SHORTSTATUS_CONF: + switch(frm->dinfo) { + case SSTATUS_L1_ACTIVATED: + l1l2l3_trace_header(mISDNport, NULL, PH_ACTIVATE_IND, DIRECTION_IN); + end_trace(); + goto ss_act; + case SSTATUS_L1_DEACTIVATED: + l1l2l3_trace_header(mISDNport, NULL, PH_DEACTIVATE_IND, DIRECTION_IN); + end_trace(); + goto ss_deact; + case SSTATUS_L2_ESTABLISHED: + l1l2l3_trace_header(mISDNport, NULL, DL_ESTABLISH_IND, DIRECTION_IN); + end_trace(); + goto ss_estab; + case SSTATUS_L2_RELEASED: + l1l2l3_trace_header(mISDNport, NULL, DL_RELEASE_IND, DIRECTION_IN); + end_trace(); + goto ss_rel; + } + break; + + case PH_ACTIVATE_CONF: + case PH_ACTIVATE_IND: + l1l2l3_trace_header(mISDNport, NULL, cmd, DIRECTION_IN); + end_trace(); + ss_act: + mISDNport->l1link = 1; +#if 0 + if (mISDNport->ntmode) + setup_queue(mISDNport, 1); +#endif + break; + + case PH_DEACTIVATE | CONFIRM: + case PH_DEACTIVATE | INDICATION: + l1l2l3_trace_header(mISDNport, NULL, cmd, DIRECTION_IN); + end_trace(); + ss_deact: + mISDNport->l1link = 0; +raus mit der setup-queue, da dies im stack geschieht +#if 0 + if (mISDNport->ntmode) + setup_queue(mISDNport, 0); +#endif + break; + + case PH_CONTROL_CONFIRM: + case PH_CONTROL_INDICATION: + PDEBUG(DEBUG_ISDN, "Received PH_CONTROL for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name); + break; + + case DL_ESTABLISH_IND: + case DL_ESTABLISH_CONF: + l1l2l3_trace_header(mISDNport, NULL, cmd, DIRECTION_IN); + end_trace(); + if (!mISDNport->ntmode) break; /* !!!!!!!!!!!!!!!! */ + ss_estab: + if (mISDNport->l2establish) + { + mISDNport->l2establish = 0; + PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n"); + } + mISDNport->l2link = 1; + break; + + case DL_RELEASE_IND: + case DL_RELEASE_CONF: + l1l2l3_trace_header(mISDNport, NULL, cmd, DIRECTION_IN); + end_trace(); + ss_rel: + mISDNport->l2link = 0; + if (mISDNport->ptp) + { + time(&mISDNport->l2establish); + PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n"); + } + break; + + default: + /* l3-data is sent to LCR */ + message_from_mlayer3(mISDNport, cmd, pid, l3m); + } + + /* unlock LCR */ + unlock it baby + + /* free message */ + if (l3m) + free_l3_msg(l3m); + return(0); + +} +#endif /* @@ -3187,13 +3481,23 @@ done: */ void PmISDN::txfromup(unsigned char *data, int length) { +#ifdef SOCKET_MISDN + unsigned char buf[MISDN_HEADER_LEN+((length>ISDN_LOAD)?length:ISDN_LOAD)]; + struct mISDNhead *frm = (struct mISDNhead *)buf; + + if (p_m_b_index < 0) + return; + if (!p_m_mISDNport->b_socket[p_m_b_index]) + return; +#else unsigned char buf[mISDN_HEADER_LEN+((length>ISDN_LOAD)?length:ISDN_LOAD)]; iframe_t *frm = (iframe_t *)buf; - /* configure frame */ - frm->prim = DL_DATA | REQUEST; - frm->addr = p_m_mISDNport->b_addr[p_m_b_index] | FLG_MSG_DOWN; - frm->dinfo = 0; + if (p_m_b_index < 0) + return; + if (!p_m_mISDNport->b_addr[p_m_b_index]) + return; +#endif /* check if high priority tones exist * ignore data in this case @@ -3220,11 +3524,22 @@ void PmISDN::txfromup(unsigned char *data, int length) if (p_m_load+length > ISDN_MAXLOAD) return; - /* load data to buffer - */ - memcpy(buf+mISDN_HEADER_LEN, data, length); + /* make and send frame */ +#ifdef SOCKET_MISDN + frm->prim = DL_DATA_REQ; + frm->id = 0; + memcpy(buf+MISDN_HEADER_LEN, data, length); + ret = sendto(p_m_mISDNport->b_socket[p_m_b_index], buf, MISDN_HEADER_LEN+length, 0, NULL, 0); + if (!ret) + PERROR("Failed to send to socket %d\n", handle); +#else + frm->prim = DL_DATA | REQUEST; + frm->addr = p_m_mISDNport->b_addr[p_m_b_index] | FLG_MSG_DOWN; + frm->dinfo = 0; frm->len = length; + memcpy(buf+mISDN_HEADER_LEN, data, length); mISDN_write(mISDNdevice, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); - p_m_load += frm->len; +#endif + p_m_load += length; }