1 /*****************************************************************************\
3 ** Linux Call Router **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** mISDN port abstraction for dss1 **
10 \*****************************************************************************/
14 #include <mISDN/q931.h>
17 #ifdef __compiler_offsetof
18 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
20 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
24 #define container_of(ptr, type, member) ({ \
25 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
26 (type *)( (char *)__mptr - offsetof(type,member) );})
29 // timeouts if activating/deactivating response from mISDN got lost
30 #define B_TIMER_ACTIVATING 1 // seconds
31 #define B_TIMER_DEACTIVATING 1 // seconds
33 /* list of mISDN ports */
34 struct mISDNport *mISDNport_first;
36 /* noise randomizer */
37 unsigned char mISDN_rand[256];
38 int mISDN_rand_count = 0;
41 unsigned int mt_assign_pid = ~0;
45 static int upqueue_pipe[2];
46 static struct lcr_fd upqueue_fd;
47 int upqueue_avail = 0;
49 static int mISDN_upqueue(struct lcr_fd *fd, unsigned int what, void *instance, int i);
50 static int mISDN_timeout(struct lcr_timer *timer, void *instance, int i);
52 static int my_mISDNlib_debug(const char *file, int line, const char *func, int level, const char *fmt, va_list va)
57 ret = vfprintf(debug_fp, fmt, va);
61 static struct mi_ext_fn_s myfn;
63 int mISDN_initialize(void)
68 /* try to open raw socket to check kernel */
69 mISDNsocket = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
70 if (mISDNsocket < 0) {
71 fprintf(stderr, "Cannot open mISDN due to '%s'. (Does your Kernel support socket based mISDN? Protocol family is %d.)\n", strerror(errno), PF_ISDN);
76 // set debug printout function
77 myfn.prt_debug = my_mISDNlib_debug;
79 ver = init_layer3(4, &myfn); // buffer of 4
81 /* open debug, if enabled and not only stack debugging */
83 SPRINT(filename, "%s/debug.log", LOG_DIR);
84 debug_fp = fopen(filename, "a");
87 if (options.deb & DEBUG_STACK)
88 mISDN_set_debug_level(0xfffffeff);
90 mISDN_set_debug_level(0);
92 if (pipe(upqueue_pipe) < 0)
93 FATAL("Failed to open pipe\n");
94 memset(&upqueue_fd, 0, sizeof(upqueue_fd));
95 upqueue_fd.fd = upqueue_pipe[0];
96 register_fd(&upqueue_fd, LCR_FD_READ, mISDN_upqueue, NULL, 0);
101 void mISDN_deinitialize(void)
109 if (mISDNsocket > -1)
112 if (upqueue_fd.inuse) {
113 unregister_fd(&upqueue_fd);
114 close(upqueue_pipe[0]);
115 close(upqueue_pipe[1]);
120 static int load_timer(struct lcr_timer *timer, void *instance, int index);
125 PmISDN::PmISDN(int type, mISDNport *mISDNport, char *portname, struct port_settings *settings, struct interface *interface, int channel, int exclusive, int mode) : Port(type, portname, settings, interface)
127 p_m_mISDNport = mISDNport;
128 p_m_portnum = mISDNport->portnum;
135 p_m_tx_gain = mISDNport->ifport->interface->tx_gain;
136 p_m_rx_gain = mISDNport->ifport->interface->rx_gain;
142 p_m_preload = ISDN_LOAD;
143 p_m_disable_dejitter = 0;
147 p_m_inband_send_on = 0;
148 p_m_inband_receive_on = 0;
149 p_m_dtmf = !mISDNport->ifport->nodtmf;
150 memset(&p_m_timeout, 0, sizeof(p_m_timeout));
151 add_timer(&p_m_timeout, mISDN_timeout, this, 0);
152 SCPY(p_m_pipeline, mISDNport->ifport->interface->pipeline);
155 memset(&p_m_loadtimer, 0, sizeof(p_m_loadtimer));
156 add_timer(&p_m_loadtimer, load_timer, this, 0);
162 p_m_crypt_listen = 0;
163 p_m_crypt_msg_loops = 0;
164 p_m_crypt_msg_loops = 0;
165 p_m_crypt_msg_len = 0;
166 p_m_crypt_msg[0] = '\0';
167 p_m_crypt_msg_current = 0;
168 p_m_crypt_key_len = 0;
169 p_m_crypt_listen = 0;
170 p_m_crypt_listen_state = 0;
171 p_m_crypt_listen_len = 0;
172 p_m_crypt_listen_msg[0] = '\0';
173 p_m_crypt_listen_crc = 0;
174 if (mISDNport->ifport->interface->bf_len >= 4 && mISDNport->ifport->interface->bf_len <= 56) {
175 memcpy(p_m_crypt_key, mISDNport->ifport->interface->bf_key, p_m_crypt_key_len);
176 p_m_crypt_key_len = mISDNport->ifport->interface->bf_len;
180 /* if any channel requested by constructor */
181 if (channel == CHANNEL_ANY) {
182 /* reserve channel */
184 mISDNport->b_reserved++;
187 /* reserve channel */
188 if (channel > 0) // only if constructor was called with a channel resevation
189 seize_bchannel(channel, exclusive);
191 /* we increase the number of objects: */
193 PDEBUG(DEBUG_ISDN, "Created new mISDNPort(%s). Currently %d objects use, port #%d\n", portname, mISDNport->use, p_m_portnum);
194 //inband_receive_on();
203 struct lcr_msg *message;
205 del_timer(&p_m_timeout);
206 del_timer(&p_m_loadtimer);
208 /* remove bchannel relation */
212 while (p_epointlist) {
213 PDEBUG(DEBUG_ISDN, "destroy mISDNPort(%s). endpoint still exists, releaseing.\n", p_name);
214 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
215 message->param.disconnectinfo.cause = 16;
216 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
217 message_put(message);
218 /* remove from list */
219 free_epointlist(p_epointlist);
222 /* we decrease the number of objects: */
223 p_m_mISDNport->use--;
224 PDEBUG(DEBUG_ISDN, "destroyed mISDNPort(%s). Currently %d objects\n", p_name, p_m_mISDNport->use);
231 void chan_trace_header(struct mISDNport *mISDNport, class PmISDN *port, const char *msgtext, int direction)
233 /* init trace with given values */
234 start_trace(mISDNport?mISDNport->portnum:-1,
235 (mISDNport)?((mISDNport->ifport)?mISDNport->ifport->interface:NULL):NULL,
236 port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype, options.national, options.international):NULL,
237 port?port->p_dialinginfo.id:NULL,
240 port?port->p_serial:0,
248 static struct isdn_message {
252 {"PH_ACTIVATE", L1_ACTIVATE_REQ},
253 {"PH_DEACTIVATE", L1_DEACTIVATE_REQ},
254 {"DL_ESTABLISH", L2_ESTABLISH_REQ},
255 {"DL_RELEASE", L2_RELEASE_REQ},
256 {"UNKNOWN", L3_UNKNOWN_REQ},
257 {"MT_TIMEOUT", L3_TIMEOUT_REQ},
258 {"MT_SETUP", L3_SETUP_REQ},
259 {"MT_SETUP_ACK", L3_SETUP_ACKNOWLEDGE_REQ},
260 {"MT_PROCEEDING", L3_PROCEEDING_REQ},
261 {"MT_ALERTING", L3_ALERTING_REQ},
262 {"MT_CONNECT", L3_CONNECT_REQ},
263 {"MT_CONNECT_ACK", L3_CONNECT_ACKNOWLEDGE_REQ},
264 {"MT_DISCONNECT", L3_DISCONNECT_REQ},
265 {"MT_RELEASE", L3_RELEASE_REQ},
266 {"MT_RELEASE_COMP", L3_RELEASE_COMPLETE_REQ},
267 {"MT_INFORMATION", L3_INFORMATION_REQ},
268 {"MT_PROGRESS", L3_PROGRESS_REQ},
269 {"MT_NOTIFY", L3_NOTIFY_REQ},
270 {"MT_SUSPEND", L3_SUSPEND_REQ},
271 {"MT_SUSPEND_ACK", L3_SUSPEND_ACKNOWLEDGE_REQ},
272 {"MT_SUSPEND_REJ", L3_SUSPEND_REJECT_REQ},
273 {"MT_RESUME", L3_RESUME_REQ},
274 {"MT_RESUME_ACK", L3_RESUME_ACKNOWLEDGE_REQ},
275 {"MT_RESUME_REJ", L3_RESUME_REJECT_REQ},
276 {"MT_HOLD", L3_HOLD_REQ},
277 {"MT_HOLD_ACK", L3_HOLD_ACKNOWLEDGE_REQ},
278 {"MT_HOLD_REJ", L3_HOLD_REJECT_REQ},
279 {"MT_RETRIEVE", L3_RETRIEVE_REQ},
280 {"MT_RETRIEVE_ACK", L3_RETRIEVE_ACKNOWLEDGE_REQ},
281 {"MT_RETRIEVE_REJ", L3_RETRIEVE_REJECT_REQ},
282 {"MT_FACILITY", L3_FACILITY_REQ},
283 {"MT_STATUS", L3_STATUS_REQ},
284 {"MT_RESTART", L3_RESTART_REQ},
285 {"MT_NEW_L3ID", L3_NEW_L3ID_REQ},
286 {"MT_RELEASE_L3ID", L3_RELEASE_L3ID_REQ},
289 static const char *isdn_prim[4] = {
295 void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsigned int msg, int direction)
300 SCPY(msgtext, "<<UNKNOWN MESSAGE>>");
301 /* select message and primitive text */
303 while(isdn_message[i].name) {
304 // if (msg == L3_NOTIFY_REQ) printf("val = %x %s\n", isdn_message[i].value, isdn_message[i].name);
305 if (isdn_message[i].value == (msg&0xffffff00)) {
306 SCPY(msgtext, isdn_message[i].name);
311 SCAT(msgtext, isdn_prim[msg&0x00000003]);
314 if (direction && (msg&0xffffff00)!=L3_NEW_L3ID_REQ && (msg&0xffffff00)!=L3_RELEASE_L3ID_REQ) {
316 if (mISDNport->ntmode) {
317 if (direction == DIRECTION_OUT)
318 SCAT(msgtext, " N->U");
320 SCAT(msgtext, " N<-U");
322 if (direction == DIRECTION_OUT)
323 SCAT(msgtext, " U->N");
325 SCAT(msgtext, " U<-N");
330 /* init trace with given values */
331 start_trace(mISDNport?mISDNport->portnum:-1,
332 mISDNport?(mISDNport->ifport?mISDNport->ifport->interface:NULL):NULL,
333 port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype, options.national, options.international):NULL,
334 port?port->p_dialinginfo.id:NULL,
337 port?port->p_serial:0,
343 * send control information to the channel (dsp-module)
345 void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, unsigned int c1, unsigned int c2, const char *trace_name, int trace_value)
347 unsigned char buffer[MISDN_HEADER_LEN+sizeof(int)+sizeof(int)];
348 struct mISDNhead *ctrl = (struct mISDNhead *)buffer;
349 unsigned int *d = (unsigned int *)(buffer+MISDN_HEADER_LEN);
355 ctrl->prim = PH_CONTROL_REQ;
359 ret = sendto(sock, buffer, MISDN_HEADER_LEN+sizeof(int)*2, 0, NULL, 0);
361 PERROR("Failed to send to socket %d\n", sock);
362 chan_trace_header(mISDNport, isdnport, "BCHANNEL control", DIRECTION_OUT);
363 if (c1 == DSP_CONF_JOIN)
364 add_trace(trace_name, NULL, "0x%08x", trace_value);
366 add_trace(trace_name, NULL, "%d", trace_value);
370 void ph_control_block(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, unsigned int c1, void *c2, int c2_len, const char *trace_name, int trace_value)
372 unsigned char buffer[MISDN_HEADER_LEN+sizeof(int)+c2_len];
373 struct mISDNhead *ctrl = (struct mISDNhead *)buffer;
374 unsigned int *d = (unsigned int *)(buffer+MISDN_HEADER_LEN);
380 ctrl->prim = PH_CONTROL_REQ;
383 memcpy(d, c2, c2_len);
384 ret = sendto(sock, buffer, MISDN_HEADER_LEN+sizeof(int)+c2_len, 0, NULL, 0);
386 PERROR("Failed to send to socket %d\n", sock);
387 chan_trace_header(mISDNport, isdnport, "BCHANNEL control", DIRECTION_OUT);
388 add_trace(trace_name, NULL, "%d", trace_value);
392 static int b_sock_callback(struct lcr_fd *fd, unsigned int what, void *instance, int i);
395 * subfunction for bchannel_event
398 static int _bchannel_create(struct mISDNport *mISDNport, int i)
401 struct sockaddr_mISDN addr;
403 if (mISDNport->b_sock[i].inuse) {
404 PERROR("Error: Socket already created for index %d\n", i);
409 //#warning testing without DSP
410 // mISDNport->b_sock[i].fd = socket(PF_ISDN, SOCK_DGRAM, (mISDNport->b_mode[i]==B_MODE_HDLC)?ISDN_P_B_HDLC:ISDN_P_B_RAW);
411 mISDNport->b_sock[i].fd = socket(PF_ISDN, SOCK_DGRAM, (mISDNport->b_mode[i]==B_MODE_HDLC)?ISDN_P_B_L2DSPHDLC:ISDN_P_B_L2DSP);
412 if (mISDNport->b_sock[i].fd < 0) {
413 PERROR("Error: Failed to open bchannel-socket for index %d with mISDN-DSP layer. Did you load mISDN_dsp.ko?\n", i);
417 /* register callback for read */
418 register_fd(&mISDNport->b_sock[i], LCR_FD_READ, b_sock_callback, mISDNport, i);
420 /* bind socket to bchannel */
421 addr.family = AF_ISDN;
422 addr.dev = mISDNport->portnum;
423 addr.channel = i+1+(i>=15);
424 ret = bind(mISDNport->b_sock[i].fd, (struct sockaddr *)&addr, sizeof(addr));
426 PERROR("Error: Failed to bind bchannel-socket for index %d with mISDN-DSP layer (errno=%d). Did you load mISDN_dsp.ko?\n", i, errno);
427 close(mISDNport->b_sock[i].fd);
428 unregister_fd(&mISDNport->b_sock[i]);
432 chan_trace_header(mISDNport, mISDNport->b_port[i], "BCHANNEL create socket", DIRECTION_OUT);
433 add_trace("channel", NULL, "%d", i+1+(i>=15));
434 add_trace("socket", NULL, "%d", mISDNport->b_sock[i].fd);
442 * subfunction for bchannel_event
443 * activate / deactivate request
445 static void _bchannel_activate(struct mISDNport *mISDNport, int i, int activate, int timeout)
447 struct mISDNhead act;
450 if (!mISDNport->b_sock[i].inuse)
452 act.prim = (activate)?PH_ACTIVATE_REQ:PH_DEACTIVATE_REQ;
454 ret = sendto(mISDNport->b_sock[i].fd, &act, MISDN_HEADER_LEN, 0, NULL, 0);
456 PERROR("Failed to send to socket %d\n", mISDNport->b_sock[i].fd);
459 chan_trace_header(mISDNport, mISDNport->b_port[i], activate ? "BCHANNEL activate" : "BCHANNEL deactivate", DIRECTION_OUT);
460 add_trace("channel", NULL, "%d", i+1+(i>=15));
462 add_trace("event", NULL, "timeout recovery");
468 * subfunction for bchannel_event
471 static void _bchannel_configure(struct mISDNport *mISDNport, int i)
476 if (!mISDNport->b_sock[i].inuse)
478 handle = mISDNport->b_sock[i].fd;
479 port = mISDNport->b_port[i];
480 mode = mISDNport->b_mode[i];
482 PERROR("bchannel index i=%d not associated with a port object\n", i);
486 /* set dsp features */
487 if (port->p_m_txdata)
488 ph_control(mISDNport, port, handle, (port->p_m_txdata)?DSP_TXDATA_ON:DSP_TXDATA_OFF, 0, "DSP-TXDATA", port->p_m_txdata);
489 if (port->p_m_delay && mode == B_MODE_TRANSPARENT)
490 ph_control(mISDNport, port, handle, DSP_DELAY, port->p_m_delay, "DSP-DELAY", port->p_m_delay);
491 if (port->p_m_tx_dejitter && mode == B_MODE_TRANSPARENT)
492 ph_control(mISDNport, port, handle, DSP_TX_DEJITTER, port->p_m_tx_dejitter, "DSP-TX_DEJITTER", port->p_m_tx_dejitter);
493 if (port->p_m_tx_gain && mode == B_MODE_TRANSPARENT)
494 ph_control(mISDNport, port, handle, DSP_VOL_CHANGE_TX, port->p_m_tx_gain, "DSP-TX_GAIN", port->p_m_tx_gain);
495 if (port->p_m_rx_gain && mode == B_MODE_TRANSPARENT)
496 ph_control(mISDNport, port, handle, DSP_VOL_CHANGE_RX, port->p_m_rx_gain, "DSP-RX_GAIN", port->p_m_rx_gain);
497 if (port->p_m_pipeline[0] && mode == B_MODE_TRANSPARENT)
498 ph_control_block(mISDNport, port, handle, DSP_PIPELINE_CFG, port->p_m_pipeline, strlen(port->p_m_pipeline)+1, "DSP-PIPELINE", 0);
499 if (port->p_m_conf && !port->p_m_mute)
500 ph_control(mISDNport, port, handle, DSP_CONF_JOIN, port->p_m_conf, "DSP-CONF", port->p_m_conf);
502 ph_control(mISDNport, port, handle, DSP_ECHO_ON, 0, "DSP-ECHO", 1);
503 if (port->p_m_tone && mode == B_MODE_TRANSPARENT)
504 ph_control(mISDNport, port, handle, DSP_TONE_PATT_ON, port->p_m_tone, "DSP-TONE", port->p_m_tone);
506 ph_control(mISDNport, port, handle, DSP_RECEIVE_OFF, 0, "DSP-RXOFF", 1);
507 // if (port->p_m_txmix && mode == B_MODE_TRANSPARENT)
508 // ph_control(mISDNport, port, handle, DSP_MIX_ON, 0, "DSP-MIX", 1);
509 if (port->p_m_dtmf && mode == B_MODE_TRANSPARENT)
510 ph_control(mISDNport, port, handle, DTMF_TONE_START, 0, "DSP-DTMF", 1);
511 if (port->p_m_crypt && mode == B_MODE_TRANSPARENT)
512 ph_control_block(mISDNport, port, handle, DSP_BF_ENABLE_KEY, port->p_m_crypt_key, port->p_m_crypt_key_len, "DSP-CRYPT", port->p_m_crypt_key_len);
516 void PmISDN::set_conf(int oldconf, int newconf)
518 if (oldconf != newconf) {
519 PDEBUG(DEBUG_BCHANNEL, "we change conference from conf=%d to conf=%d.\n", oldconf, newconf);
520 if (p_m_b_index > -1)
521 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
522 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, (newconf)?DSP_CONF_JOIN:DSP_CONF_SPLIT, newconf, "DSP-CONF", newconf);
524 PDEBUG(DEBUG_BCHANNEL, "we already have conf=%d.\n", newconf);
529 * subfunction for bchannel_event
532 static void _bchannel_destroy(struct mISDNport *mISDNport, int i)
534 if (!mISDNport->b_sock[i].inuse)
536 chan_trace_header(mISDNport, mISDNport->b_port[i], "BCHANNEL remove socket", DIRECTION_OUT);
537 add_trace("channel", NULL, "%d", i+1+(i>=15));
538 add_trace("socket", NULL, "%d", mISDNport->b_sock[i].fd);
540 close(mISDNport->b_sock[i].fd);
541 unregister_fd(&mISDNport->b_sock[i]);
549 A bchannel goes through the following states in this order:
552 No one is using the bchannel.
553 It is available and not linked to Port class, nor reserved.
556 The bchannel stack is created and an activation request is sent.
557 It MAY be linked to Port class, but already unlinked due to Port class removal.
560 The bchannel is active and cofigured to the Port class needs.
561 Also it is linked to a Port class, otherwhise it would be deactivated.
563 - B_STATE_DEACTIVATING
564 The bchannel is in deactivating state, due to deactivation request.
565 It may be linked to a Port class, that likes to reactivate it.
569 After deactivating bchannel, and if not used, the bchannel becomes idle again.
571 A bchannel can have the following events:
574 A bchannel is required by a Port class.
577 The bchannel beomes active.
580 The bchannel is not required by Port class anymore
582 - B_EVENT_DEACTIVATED
583 The bchannel becomes inactive.
585 All actions taken on these events depend on the current bchannel's state and if it is linked to a Port class.
590 * process bchannel events
591 * - mISDNport is a pointer to the port's structure
592 * - i is the index of the bchannel
593 * - event is the B_EVENT_* value
594 * - port is the PmISDN class pointer
596 void bchannel_event(struct mISDNport *mISDNport, int i, int event)
598 class PmISDN *b_port = mISDNport->b_port[i];
599 int state = mISDNport->b_state[i];
600 int timer = -1; // no change
603 char *p_m_pipeline = NULL;
604 unsigned char *p_m_crypt_key = NULL;
605 int p_m_crypt_key_len = 0;
606 int p_m_crypt_key_type = 0;
609 p_m_tx_gain = b_port->p_m_tx_gain;
610 p_m_rx_gain = b_port->p_m_rx_gain;
611 p_m_pipeline = b_port->p_m_pipeline;
612 p_m_crypt_key = b_port->p_m_crypt_key;
613 p_m_crypt_key_len = b_port->p_m_crypt_key_len;
614 p_m_crypt_key_type = /*b_port->p_m_crypt_key_type*/1;
619 /* port must be linked in order to allow activation */
621 FATAL("bchannel must be linked to a Port class\n");
624 /* create stack and send activation request */
625 if (_bchannel_create(mISDNport, i)) {
626 _bchannel_activate(mISDNport, i, 1, 0);
627 state = B_STATE_ACTIVATING;
628 timer = B_TIMER_ACTIVATING;
632 case B_STATE_ACTIVATING:
633 /* do nothing, because it is already activating */
637 /* problems that might ocurr:
638 * B_EVENT_USE is received when channel already in use.
640 PERROR("Illegal event %d at state %d, please correct.\n", event, state);
645 case B_EVENT_ACTIVATED:
648 case B_STATE_ACTIVATING:
650 /* bchannel is active and used by Port class, so we configure bchannel */
651 _bchannel_configure(mISDNport, i);
652 state = B_STATE_ACTIVE;
653 b_port->p_m_load = 0;
654 b_port->update_load();
656 /* bchannel is active, but not used anymore (or has wrong stack config), so we deactivate */
657 _bchannel_activate(mISDNport, i, 0, 0);
658 state = B_STATE_DEACTIVATING;
659 timer = B_TIMER_DEACTIVATING;
664 PERROR("Illegal event %d at state %d, please correct.\n", event, state);
670 FATAL("bchannel must be linked to a Port class\n");
673 /* bchannel is idle due to an error, so we do nothing */
676 case B_STATE_ACTIVATING:
677 /* do nothing because we must wait until bchanenl is active before deactivating */
681 /* bchannel is active, so we deactivate */
682 _bchannel_activate(mISDNport, i, 0, 0);
683 state = B_STATE_DEACTIVATING;
684 timer = B_TIMER_DEACTIVATING;
687 case B_STATE_DEACTIVATING:
688 /* we may have taken an already deactivating bchannel, but do not require it anymore, so we do nothing */
692 PERROR("Illegal event %d at state %d, please correct.\n", event, state);
696 case B_EVENT_DEACTIVATED:
700 /* ignore due to deactivation confirm after unloading */
703 case B_STATE_DEACTIVATING:
704 _bchannel_destroy(mISDNport, i);
705 state = B_STATE_IDLE;
707 /* bchannel is now deactivate, but is requied by Port class, so we reactivate */
708 if (_bchannel_create(mISDNport, i)) {
709 _bchannel_activate(mISDNport, i, 1, 0);
710 state = B_STATE_ACTIVATING;
711 timer = B_TIMER_ACTIVATING;
717 PERROR("Illegal event %d at state %d, please correct.\n", event, state);
721 case B_EVENT_TIMEOUT:
725 /* ignore due to deactivation confirm after unloading */
728 case B_STATE_ACTIVATING:
729 _bchannel_activate(mISDNport, i, 1, 1);
730 timer = B_TIMER_ACTIVATING;
733 case B_STATE_DEACTIVATING:
734 _bchannel_activate(mISDNport, i, 0, 1);
735 timer = B_TIMER_DEACTIVATING;
739 PERROR("Illegal event %d at state %d, please correct.\n", event, state);
744 PERROR("Illegal event %d, please correct.\n", event);
747 mISDNport->b_state[i] = state;
749 unsched_timer(&mISDNport->b_timer[i]);
751 schedule_timer(&mISDNport->b_timer[i], timer, 0);
758 * check for available channel and reserve+set it.
759 * give channel number or SEL_CHANNEL_ANY or SEL_CHANNEL_NO
761 * returns -(cause value) or x = channel x or 0 = no channel
762 * NOTE: no activation is done here
764 int PmISDN::seize_bchannel(int channel, int exclusive)
768 /* the channel is what we have */
769 if (p_m_b_channel == channel)
772 /* if channel already in use, release it */
777 if (channel==CHANNEL_NO || channel==0)
780 /* is channel in range ? */
782 || (channel>p_m_mISDNport->b_num && channel<16)
783 || ((channel-1)>p_m_mISDNport->b_num && channel>16)) /* channel-1 because channel 16 is not counted */
784 return(-6); /* channel unacceptable */
786 /* request exclusive channel */
787 if (exclusive && channel>0) {
788 i = channel-1-(channel>16);
789 if (p_m_mISDNport->b_port[i])
790 return(-44); /* requested channel not available */
794 /* ask for channel */
796 i = channel-1-(channel>16);
797 if (p_m_mISDNport->b_port[i] == NULL)
801 /* search for channel */
803 while(i < p_m_mISDNport->b_num) {
804 if (!p_m_mISDNport->b_port[i]) {
805 channel = i+1+(i>=15);
810 return(-34); /* no free channel */
813 PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) seizing bchannel %d (index %d)\n", p_name, channel, i);
815 /* link Port, set parameters */
816 p_m_mISDNport->b_port[i] = this;
818 p_m_b_channel = channel;
819 p_m_b_exclusive = exclusive;
820 p_m_mISDNport->b_mode[i] = p_m_b_mode;
822 /* reserve channel */
823 if (!p_m_b_reserve) {
825 p_m_mISDNport->b_reserved++;
832 * drop reserved channel and unset it.
833 * deactivation is also done
835 void PmISDN::drop_bchannel(void)
837 /* unreserve channel */
839 p_m_mISDNport->b_reserved--;
848 PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) dropping bchannel\n", p_name);
850 if (p_m_mISDNport->b_state[p_m_b_index] != B_STATE_IDLE)
851 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_DROP);
852 p_m_mISDNport->b_port[p_m_b_index] = NULL;
853 p_m_mISDNport->b_mode[p_m_b_index] = 0;
863 audio transmission procedure:
864 -----------------------------
867 three sources of audio transmission:
868 - crypto-data high priority
869 - tones high priority (also high)
870 - remote-data low priority
873 a variable that temporarily shows the number of samples elapsed since last transmission process.
874 p_m_last_tv_* is used to store that last timestamp. this is used to calculate the time elapsed.
877 a variable that is increased whenever data is transmitted.
878 it is decreased while time elapses. it stores the number of samples that
879 are currently loaded to dsp module.
880 since clock in dsp module is the same clock for user space process, these
884 there are two levels:
885 p_m_preload will give the load that have to be kept in dsp.
886 ISDN_MAXLOAD (2*p_m_preload) will give the maximum load before dropping.
888 * procedure for low priority data
889 see txfromup() for procedure
890 in short: remote data is ignored during high priority tones
892 * procedure for high priority data
893 whenever load is below p_m_preload, load is filled up to p_m_preload
894 if no more data is available, load becomes empty again.
897 0 p_m_preload ISDN_MAXLOAD
898 +--------------------+----------------------+
900 +--------------------+----------------------+
902 on empty load or on load below p_m_preload, the load is inceased to p_m_preload:
903 0 p_m_preload ISDN_MAXLOAD
904 +--------------------+----------------------+
905 |TTTTTTTTTTTTTTTTTTTT| |
906 +--------------------+----------------------+
908 on empty load, remote-audio causes the load with the remote audio to be increased to p_m_preload.
909 0 p_m_preload ISDN_MAXLOAD
910 +--------------------+----------------------+
911 |TTTTTTTTTTTTTTTTTTTTRRRRR |
912 +--------------------+----------------------+
915 void PmISDN::update_load(void)
917 /* don't trigger load event if event already active */
918 if (p_m_loadtimer.active)
921 schedule_timer(&p_m_loadtimer, 0, 0); /* no delay the first time */
924 static int load_timer(struct lcr_timer *timer, void *instance, int index)
926 class PmISDN *isdnport = (class PmISDN *)instance;
933 void PmISDN::load_tx(void)
937 struct timeval current_time;
940 gettimeofday(¤t_time, NULL);
941 if (p_m_last_tv_sec) {
942 elapsed = 8000 * (current_time.tv_sec - p_m_last_tv_sec)
943 + 8 * (current_time.tv_usec/1000 - p_m_last_tv_msec);
945 /* set clock of last process! */
946 p_m_last_tv_sec = current_time.tv_sec;
947 p_m_last_tv_msec = current_time.tv_usec/1000;
949 /* process only if we have samples and we are active */
950 if (p_m_mISDNport->b_state[p_m_b_index] != B_STATE_ACTIVE)
955 if (elapsed < p_m_load)
960 /* to send data, tone must be on */
961 if ((p_tone_name[0] || p_m_crypt_msg_loops || p_m_inband_send_on) /* what tones? */
962 && (p_m_load < p_m_preload) /* not too much load? */
963 && (p_state==PORT_STATE_CONNECT || p_m_mISDNport->tones || p_m_inband_send_on)) { /* connected or inband-tones? */
964 int tosend = p_m_preload - p_m_load, length;
965 unsigned char buf[MISDN_HEADER_LEN+tosend];
966 struct mISDNhead *frm = (struct mISDNhead *)buf;
967 unsigned char *p = buf+MISDN_HEADER_LEN;
969 /* copy inband signalling (e.g. used by ss5) */
970 if (p_m_inband_send_on && tosend) {
971 tosend -= inband_send(p, tosend);
974 /* copy crypto loops */
975 while (p_m_crypt_msg_loops && tosend) {
976 /* how much do we have to send */
977 length = p_m_crypt_msg_len - p_m_crypt_msg_current;
983 /* copy message (part) to buffer */
984 memcpy(p, p_m_crypt_msg+p_m_crypt_msg_current, length);
987 p_m_crypt_msg_current += length;
988 if (p_m_crypt_msg_current == p_m_crypt_msg_len) {
990 p_m_crypt_msg_current = 0;
991 p_m_crypt_msg_loops--;
992 if (!p_m_crypt_msg_loops)
994 // puts("eine loop weniger");
1002 if (p_tone_name[0] && tosend) {
1003 tosend -= read_audio(p, tosend);
1007 if (p_m_preload - p_m_load - tosend > 0) {
1008 frm->prim = PH_DATA_REQ;
1010 ret = sendto(p_m_mISDNport->b_sock[p_m_b_index].fd, buf, MISDN_HEADER_LEN+p_m_preload-p_m_load-tosend, 0, NULL, 0);
1012 PERROR("Failed to send to socket %d (samples = %d)\n", p_m_mISDNport->b_sock[p_m_b_index].fd, p_m_preload-p_m_load-tosend);
1013 p_m_load += p_m_preload - p_m_load - tosend;
1018 schedule_timer(&p_m_loadtimer, 0, PORT_TRANSMIT * 125);
1021 /* handle timeouts */
1022 static int mISDN_timeout(struct lcr_timer *timer, void *instance, int i)
1024 class PmISDN *isdnport = (class PmISDN *)instance;
1025 struct lcr_msg *message;
1027 PDEBUG(DEBUG_ISDN, "(%s) timeout after %d seconds detected (state=%d).\n", isdnport->p_name, isdnport->p_m_timeout.timeout.tv_sec, isdnport->p_state);
1028 /* send timeout to endpoint */
1029 message = message_create(isdnport->p_serial, ACTIVE_EPOINT(isdnport->p_epointlist), PORT_TO_EPOINT, MESSAGE_TIMEOUT);
1030 message->param.state = isdnport->p_state;
1031 message_put(message);
1038 * whenever we get audio data from bchannel, we process it here
1040 void PmISDN::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len)
1042 unsigned int cont = *((unsigned int *)data);
1043 struct lcr_msg *message;
1047 if (hh->prim == PH_CONTROL_IND) {
1049 PERROR("SHORT READ OF PH_CONTROL INDICATION\n");
1052 if ((cont&(~DTMF_TONE_MASK)) == DTMF_TONE_VAL) {
1053 chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
1054 add_trace("DTMF", NULL, "%c", cont & DTMF_TONE_MASK);
1056 add_trace("info", NULL, "DTMF is disabled");
1060 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DTMF);
1061 message->param.dtmf = cont & DTMF_TONE_MASK;
1062 PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION DTMF digit '%c'\n", p_name, message->param.dtmf);
1063 message_put(message);
1068 chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
1069 add_trace("DSP-CRYPT", NULL, "error");
1071 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CRYPT);
1072 message->param.crypt.type = CC_ERROR_IND;
1073 PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION reject of blowfish.\n", p_name);
1074 message_put(message);
1078 chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
1079 add_trace("DSP-CRYPT", NULL, "ok");
1081 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CRYPT);
1082 message->param.crypt.type = CC_ACTBF_CONF;
1083 PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION accept of blowfish.\n", p_name);
1084 message_put(message);
1088 chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
1089 add_trace("unknown", NULL, "0x%x", cont);
1094 if (hh->prim == PH_CONTROL_IND) {
1097 chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
1098 add_trace("unknown", NULL, "0x%x", hh->id);
1103 if (hh->prim == PH_DATA_REQ || hh->prim == DL_DATA_REQ) {
1105 /* if tx is off, it may happen that fifos send us pending informations, we just ignore them */
1106 PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) ignoring tx data, because 'txdata' is turned off\n", p_name);
1109 /* see below (same condition) */
1110 if (p_state!=PORT_STATE_CONNECT
1111 && !p_m_mISDNport->tones)
1113 // printf(".");fflush(stdout);return;
1115 record(data, len, 1); // from up
1117 tap(data, len, 1); // from up
1120 if (hh->prim != PH_DATA_IND && hh->prim != DL_DATA_IND) {
1121 PERROR("Bchannel received unknown primitve: 0x%x\n", hh->prim);
1125 /* inband is processed */
1126 if (p_m_inband_receive_on)
1127 inband_receive(data, len);
1129 /* send to remote, if bridged */
1130 bridge_tx(data, len);
1132 /* calls will not process any audio data unless
1133 * the call is connected OR tones feature is enabled.
1135 #ifndef DEBUG_COREBRIDGE
1136 if (p_state!=PORT_STATE_CONNECT
1137 && !p_m_mISDNport->tones)
1142 /* the bearer capability must be audio in order to send and receive
1143 * audio prior or after connect.
1145 if (!(p_bearerinfo.capability&CLASS_CAPABILITY_AUDIO) && p_state!=PORT_STATE_CONNECT)
1149 /* if rx is off, it may happen that fifos send us pending informations, we just ignore them */
1151 PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) ignoring data, because rx is turned off\n", p_name);
1157 record(data, len, 0); // from down
1159 tap(data, len, 0); // from down
1161 /* randomize and listen to crypt message if enabled */
1162 if (p_m_crypt_listen) {
1163 /* the noisy randomizer */
1167 mISDN_rand[mISDN_rand_count & 0xff] += *p++;
1169 cryptman_listen_bch(data, len);
1177 void PmISDN::set_echotest(int echo)
1179 if (p_m_echo != echo) {
1181 PDEBUG(DEBUG_ISDN, "we set echo to echo=%d.\n", p_m_echo);
1183 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
1184 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, p_m_echo?DSP_ECHO_ON:DSP_ECHO_OFF, 0, "DSP-ECHO", p_m_echo);
1191 void PmISDN::set_tone(const char *dir, const char *tone)
1196 /* if no directory is given (by extension), we use interface.conf or options.conf */
1197 if (!dir || !dir[0]) {
1198 if (p_m_mISDNport->ifport->tones_dir[0])
1199 dir = p_m_mISDNport->ifport->tones_dir;
1200 else if (options.tones_dir[0])
1201 dir = options.tones_dir;
1206 PDEBUG(DEBUG_ISDN, "isdn port now plays tone:'%s'.\n", tone);
1212 /* check for dsp tones */
1213 if (!strcmp(dir, "american"))
1215 if (!strcmp(dir, "german"))
1217 if (!strcmp(dir, "oldgerman"))
1218 dsp = DSP_OLDGERMAN;
1220 /* check if we NOT really have to use a dsp-tone */
1221 if (dsp == DSP_NONE) {
1224 if (p_m_b_index > -1)
1225 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE && p_m_mISDNport->b_mode[p_m_b_index] == B_MODE_TRANSPARENT) {
1226 PDEBUG(DEBUG_ISDN, "we reset tone from id=%d to OFF.\n", p_m_tone);
1227 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_TONE_PATT_OFF, 0, "DSP-TONE", 0);
1230 Port::set_tone(dir, tone);
1234 /* now we USE dsp-tone, convert name */
1235 if (!strcmp(tone, "dialtone")) {
1237 case DSP_AMERICAN: id = TONE_AMERICAN_DIALTONE; break;
1238 case DSP_GERMAN: id = TONE_GERMAN_DIALTONE; break;
1239 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDDIALTONE; break;
1241 } else if (!strcmp(tone, "dialpbx")) {
1243 case DSP_AMERICAN: id = TONE_AMERICAN_DIALPBX; break;
1244 case DSP_GERMAN: id = TONE_GERMAN_DIALPBX; break;
1245 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDDIALPBX; break;
1247 } else if (!strcmp(tone, "ringing")) {
1249 case DSP_AMERICAN: id = TONE_AMERICAN_RINGING; break;
1250 case DSP_GERMAN: id = TONE_GERMAN_RINGING; break;
1251 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDRINGING; break;
1253 } else if (!strcmp(tone, "ringpbx")) {
1255 case DSP_AMERICAN: id = TONE_AMERICAN_RINGPBX; break;
1256 case DSP_GERMAN: id = TONE_GERMAN_RINGPBX; break;
1257 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDRINGPBX; break;
1259 } else if (!strcmp(tone, "busy")) {
1262 case DSP_AMERICAN: id = TONE_AMERICAN_BUSY; break;
1263 case DSP_GERMAN: id = TONE_GERMAN_BUSY; break;
1264 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDBUSY; break;
1266 } else if (!strcmp(tone, "release")) {
1269 case DSP_AMERICAN: id = TONE_AMERICAN_HANGUP; break;
1270 case DSP_GERMAN: id = TONE_GERMAN_HANGUP; break;
1271 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDHANGUP; break;
1273 } else if (!strcmp(tone, "cause_10"))
1275 else if (!strcmp(tone, "cause_11"))
1277 else if (!strcmp(tone, "cause_22")) {
1279 case DSP_AMERICAN: id = TONE_SPECIAL_INFO; break;
1280 case DSP_GERMAN: id = TONE_GERMAN_GASSENBESETZT; break;
1281 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDBUSY; break;
1283 } else if (!strncmp(tone, "cause_", 6))
1284 id = TONE_SPECIAL_INFO;
1288 /* if we have a tone that is not supported by dsp */
1289 if (id==TONE_OFF && tone[0])
1293 if (p_m_tone != id) {
1296 PDEBUG(DEBUG_ISDN, "we set tone to id=%d.\n", p_m_tone);
1297 if (p_m_b_index > -1)
1298 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE && p_m_mISDNport->b_mode[p_m_b_index] == B_MODE_TRANSPARENT)
1299 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, p_m_tone?DSP_TONE_PATT_ON:DSP_TONE_PATT_OFF, p_m_tone, "DSP-TONE", p_m_tone);
1301 /* turn user-space tones off in cases of no tone OR dsp tone */
1302 Port::set_tone("",NULL);
1306 /* MESSAGE_mISDNSIGNAL */
1307 //extern struct lcr_msg *dddebug;
1308 void PmISDN::message_mISDNsignal(unsigned int epoint_id, int message_id, union parameter *param)
1310 int oldconf, newconf;
1311 switch(param->mISDNsignal.message) {
1312 case mISDNSIGNAL_VOLUME:
1313 if (p_m_tx_gain != param->mISDNsignal.tx_gain) {
1314 p_m_tx_gain = param->mISDNsignal.tx_gain;
1315 PDEBUG(DEBUG_BCHANNEL, "we change tx-volume to shift=%d.\n", p_m_tx_gain);
1316 if (p_m_b_index > -1)
1317 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE && p_m_mISDNport->b_mode[p_m_b_index] == B_MODE_TRANSPARENT)
1318 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_VOL_CHANGE_TX, p_m_tx_gain, "DSP-TX_GAIN", p_m_tx_gain);
1320 PDEBUG(DEBUG_BCHANNEL, "we already have tx-volume shift=%d.\n", p_m_rx_gain);
1321 if (p_m_rx_gain != param->mISDNsignal.rx_gain) {
1322 p_m_rx_gain = param->mISDNsignal.rx_gain;
1323 PDEBUG(DEBUG_BCHANNEL, "we change rx-volume to shift=%d.\n", p_m_rx_gain);
1324 if (p_m_b_index > -1)
1325 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE && p_m_mISDNport->b_mode[p_m_b_index] == B_MODE_TRANSPARENT)
1326 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_VOL_CHANGE_RX, p_m_rx_gain, "DSP-RX_GAIN", p_m_rx_gain);
1328 PDEBUG(DEBUG_BCHANNEL, "we already have rx-volume shift=%d.\n", p_m_rx_gain);
1331 case mISDNSIGNAL_CONF:
1332 oldconf = p_m_mute?0:p_m_conf;
1333 p_m_conf = param->mISDNsignal.conf;
1334 newconf = p_m_mute?0:p_m_conf;
1335 set_conf(oldconf, newconf);
1338 case mISDNSIGNAL_DELAY:
1339 if (p_m_delay != param->mISDNsignal.delay) {
1340 p_m_delay = param->mISDNsignal.delay;
1341 PDEBUG(DEBUG_BCHANNEL, "we change delay mode to delay=%d.\n", p_m_delay);
1342 if (p_m_b_index > -1)
1343 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE && p_m_mISDNport->b_mode[p_m_b_index] == B_MODE_TRANSPARENT)
1344 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, p_m_delay?DSP_DELAY:DSP_JITTER, p_m_delay, "DSP-DELAY", p_m_delay);
1346 PDEBUG(DEBUG_BCHANNEL, "we already have delay=%d.\n", p_m_delay);
1350 PERROR("PmISDN(%s) unsupported signal message %d.\n", p_name, param->mISDNsignal.message);
1355 void PmISDN::message_crypt(unsigned int epoint_id, int message_id, union parameter *param)
1357 struct lcr_msg *message;
1359 switch(param->crypt.type) {
1360 case CC_ACTBF_REQ: /* activate blowfish */
1362 p_m_crypt_key_len = param->crypt.len;
1363 if (p_m_crypt_key_len > (int)sizeof(p_m_crypt_key)) {
1364 PERROR("PmISDN(%s) key too long %d > %d\n", p_name, p_m_crypt_key_len, sizeof(p_m_crypt_key));
1365 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CRYPT);
1366 message->param.crypt.type = CC_ERROR_IND;
1367 message_put(message);
1370 memcpy(p_m_crypt_key, param->crypt.data, p_m_crypt_key_len);
1372 PDEBUG(DEBUG_BCHANNEL, "we set encryption to crypt=%d. (0 means OFF)\n", p_m_crypt);
1373 if (p_m_b_index > -1)
1374 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE && p_m_mISDNport->b_mode[p_m_b_index] == B_MODE_TRANSPARENT)
1375 ph_control_block(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, p_m_crypt?DSP_BF_ENABLE_KEY:DSP_BF_DISABLE, p_m_crypt_key, p_m_crypt_key_len, "DSP-CRYPT", p_m_crypt_key_len);
1378 case CC_DACT_REQ: /* deactivate session encryption */
1383 case CR_LISTEN_REQ: /* start listening to messages */
1384 p_m_crypt_listen = 1;
1386 p_m_crypt_listen_state = 0;
1389 case CR_UNLISTEN_REQ: /* stop listening to messages */
1390 p_m_crypt_listen = 0;
1394 case CR_MESSAGE_REQ: /* send message */
1395 p_m_crypt_msg_len = cryptman_encode_bch(param->crypt.data, param->crypt.len, p_m_crypt_msg, sizeof(p_m_crypt_msg));
1396 if (!p_m_crypt_msg_len) {
1397 PERROR("PmISDN(%s) message too long %d > %d\n", p_name, param->crypt.len-1, sizeof(p_m_crypt_msg));
1400 p_m_crypt_msg_current = 0; /* reset */
1401 p_m_crypt_msg_loops = 6; /* enable */
1404 /* disable txmix, or we get corrupt data due to audio process */
1405 if (p_m_txmix && p_m_b_index>=0 && p_m_mISDNport->b_mode[p_m_b_index] == B_MODE_TRANSPARENT) {
1406 PDEBUG(DEBUG_BCHANNEL, "for sending CR_MESSAGE_REQ, we reset txmix from txmix=%d.\n", p_m_txmix);
1407 ph_control(p_m_mISDNport, this, p_mISDNport->b_sock[p_m_b_index].fd, DSP_MIX_OFF, 0, "DSP-TXMIX", 0);
1413 PERROR("PmISDN(%s) unknown crypt message %d\n", p_name, param->crypt.type);
1419 * endpoint sends messages to the port
1421 int PmISDN::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
1423 if (Port::message_epoint(epoint_id, message_id, param)) {
1424 if (message_id == MESSAGE_BRIDGE)
1429 switch(message_id) {
1430 case MESSAGE_mISDNSIGNAL: /* user command */
1431 PDEBUG(DEBUG_ISDN, "PmISDN(%s) received special ISDN SIGNAL %d.\n", p_name, param->mISDNsignal.message);
1432 message_mISDNsignal(epoint_id, message_id, param);
1435 case MESSAGE_CRYPT: /* crypt control command */
1436 PDEBUG(DEBUG_ISDN, "PmISDN(%s) received encryption command '%d'.\n", p_name, param->crypt.type);
1437 message_crypt(epoint_id, message_id, param);
1440 case MESSAGE_DISABLE_DEJITTER:
1441 PDEBUG(DEBUG_ISDN, "PmISDN(%s) received de-jitter disable order.\n", p_name);
1442 p_m_disable_dejitter = 1;
1443 p_m_preload = param->queue;
1451 void PmISDN::update_rxoff(void)
1453 int tx_dejitter = 0;
1455 /* call bridges in user space OR crypto OR recording */
1456 if (p_bridge || p_m_crypt_msg_loops || p_m_crypt_listen || p_record || p_tap || p_m_inband_receive_on) {
1457 /* rx IS required */
1461 PDEBUG(DEBUG_BCHANNEL, "%s: receive data is required, so we turn them on\n", __FUNCTION__);
1462 if (p_m_b_index > -1)
1463 if (p_m_mISDNport->b_port[p_m_b_index] && p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
1464 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_RECEIVE_ON, 0, "DSP-RXOFF", 0);
1467 /* rx NOT required */
1471 PDEBUG(DEBUG_BCHANNEL, "%s: receive data is not required, so we turn them off\n", __FUNCTION__);
1472 if (p_m_b_index > -1)
1473 if (p_m_mISDNport->b_port[p_m_b_index] && p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
1474 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_RECEIVE_OFF, 0, "DSP-RXOFF", 1);
1477 /* recording / tapping */
1478 if (p_record || p_tap) {
1479 /* txdata IS required */
1483 PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is required, so we turn them on\n", __FUNCTION__);
1484 if (p_m_b_index > -1)
1485 if (p_m_mISDNport->b_port[p_m_b_index] && p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
1486 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_TXDATA_ON, 0, "DSP-TXDATA", 1);
1489 /* txdata NOT required */
1493 PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is not required, so we turn them off\n", __FUNCTION__);
1494 if (p_m_b_index > -1)
1495 if (p_m_mISDNport->b_port[p_m_b_index] && p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
1496 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_TXDATA_OFF, 0, "DSP-TXDATA", 0);
1499 /* dejitter on bridge */
1500 if (p_bridge && !p_m_disable_dejitter)
1502 if (p_m_tx_dejitter != tx_dejitter) {
1503 p_m_tx_dejitter = tx_dejitter;
1504 PDEBUG(DEBUG_BCHANNEL, "we change dejitter mode to %s.\n", (p_m_tx_dejitter) ? "on" : "off");
1505 if (p_m_b_index > -1)
1506 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE && p_m_mISDNport->b_mode[p_m_b_index] == B_MODE_TRANSPARENT)
1507 ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_TX_DEJITTER, p_m_tx_dejitter, "DSP-TX_DEJITTER", p_m_tx_dejitter);
1511 static int mISDN_upqueue(struct lcr_fd *fd, unsigned int what, void *instance, int i)
1513 struct mISDNport *mISDNport;
1519 /* unset global semaphore */
1521 // with a very small incident, upqueue_avail may be set by mISDN thread and
1522 // another byte may be sent to the pipe, which causes a call to this function
1523 // again with nothing in the upqueue. this is no problem.
1524 ret = read(fd->fd, &byte, 1);
1526 /* process all ports */
1527 mISDNport = mISDNport_first;
1529 /* handle queued up-messages (d-channel) */
1530 while ((mb = mdequeue(&mISDNport->upqueue))) {
1533 case MPH_ACTIVATE_IND:
1534 if (mISDNport->l1link != 1) {
1535 l1l2l3_trace_header(mISDNport, NULL, L1_ACTIVATE_IND, DIRECTION_IN);
1537 mISDNport->l1link = 1;
1541 case MPH_DEACTIVATE_IND:
1542 if (mISDNport->l1link != 0) {
1543 l1l2l3_trace_header(mISDNport, NULL, L1_DEACTIVATE_IND, DIRECTION_IN);
1545 mISDNport->l1link = 0;
1549 case MPH_INFORMATION_IND:
1550 PDEBUG(DEBUG_ISDN, "Received MPH_INFORMATION_IND for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
1552 case L1_SIGNAL_LOS_ON:
1555 case L1_SIGNAL_LOS_OFF:
1558 case L1_SIGNAL_AIS_ON:
1561 case L1_SIGNAL_AIS_OFF:
1564 case L1_SIGNAL_RDI_ON:
1567 case L1_SIGNAL_RDI_OFF:
1570 case L1_SIGNAL_SLIP_TX:
1571 mISDNport->slip_tx++;
1573 case L1_SIGNAL_SLIP_RX:
1574 mISDNport->slip_rx++;
1579 case MT_L2ESTABLISH:
1580 l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_IND, DIRECTION_IN);
1581 add_trace("tei", NULL, "%d", l3m->pid);
1583 mISDNport->l2link = 1;
1585 mISDNport->l2mask[l3m->pid >> 3] |= (1 << (l3m->pid & 7));
1586 if ((!mISDNport->ntmode || mISDNport->ptp) && l3m->pid < 127) {
1587 if (mISDNport->l2establish.active) {
1588 unsched_timer(&mISDNport->l2establish);
1589 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
1596 mISDNport->l2mask[l3m->pid >> 3] &= ~(1 << (l3m->pid & 7));
1597 if (!mISDNport->l2establish.active) {
1598 l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_IND, DIRECTION_IN);
1599 add_trace("tei", NULL, "%d", l3m->pid);
1601 /* down if not nt-ptmp */
1602 if (!mISDNport->ntmode || mISDNport->ptp)
1603 mISDNport->l2link = 0;
1605 if ((!mISDNport->ntmode || mISDNport->ptp) && l3m->pid < 127) {
1606 if (!mISDNport->l2establish.active && mISDNport->l2hold) {
1607 PDEBUG(DEBUG_ISDN, "set timer and establish.\n");
1608 schedule_timer(&mISDNport->l2establish, 5, 0);
1609 mISDNport->ml3->to_layer3(mISDNport->ml3, MT_L2ESTABLISH, 0, NULL);
1615 /* l3-data is sent to LCR */
1616 stack2manager(mISDNport, l3m->type, l3m->pid, l3m);
1621 mISDNport = mISDNport->next;
1626 /* l2 establish timer fires */
1627 static int l2establish_timeout(struct lcr_timer *timer, void *instance, int i)
1629 struct mISDNport *mISDNport = (struct mISDNport *)instance;
1631 if (mISDNport->l2hold && (mISDNport->ptp || !mISDNport->ntmode)) {
1632 PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link portnum=%d.\n", mISDNport->portnum);
1633 mISDNport->ml3->to_layer3(mISDNport->ml3, MT_L2ESTABLISH, 0, NULL);
1634 schedule_timer(&mISDNport->l2establish, 5, 0); /* 5 seconds */
1640 /* handle frames from bchannel */
1641 static int b_sock_callback(struct lcr_fd *fd, unsigned int what, void *instance, int i)
1643 struct mISDNport *mISDNport = (struct mISDNport *)instance;
1644 unsigned char buffer[2048+MISDN_HEADER_LEN];
1645 struct mISDNhead *hh = (struct mISDNhead *)buffer;
1648 ret = recv(fd->fd, buffer, sizeof(buffer), 0);
1650 PERROR("read error frame, errno %d\n", errno);
1653 if (ret < (int)MISDN_HEADER_LEN) {
1654 PERROR("read short frame, got %d, expected %d\n", ret, (int)MISDN_HEADER_LEN);
1658 /* we don't care about confirms, we use rx data to sync tx */
1662 /* we receive audio data, we respond to it AND we send tones */
1667 case PH_CONTROL_IND:
1668 if (mISDNport->b_port[i])
1669 mISDNport->b_port[i]->bchannel_receive(hh, buffer+MISDN_HEADER_LEN, ret-MISDN_HEADER_LEN);
1671 PDEBUG(DEBUG_BCHANNEL, "b-channel is not associated to an ISDNPort (socket %d), ignoring.\n", fd->fd);
1674 case PH_ACTIVATE_IND:
1675 case DL_ESTABLISH_IND:
1676 case PH_ACTIVATE_CNF:
1677 case DL_ESTABLISH_CNF:
1678 PDEBUG(DEBUG_BCHANNEL, "DL_ESTABLISH confirm: bchannel is now activated (socket %d).\n", fd->fd);
1679 bchannel_event(mISDNport, i, B_EVENT_ACTIVATED);
1682 case PH_DEACTIVATE_IND:
1683 case DL_RELEASE_IND:
1684 case PH_DEACTIVATE_CNF:
1685 case DL_RELEASE_CNF:
1686 PDEBUG(DEBUG_BCHANNEL, "DL_RELEASE confirm: bchannel is now de-activated (socket %d).\n", fd->fd);
1687 bchannel_event(mISDNport, i, B_EVENT_DEACTIVATED);
1691 PERROR("child message not handled: prim(0x%x) socket(%d) msg->len(%d)\n", hh->prim, fd->fd, ret-MISDN_HEADER_LEN);
1697 /* process timer events for bchannel handling */
1698 static int b_timer_timeout(struct lcr_timer *timer, void *instance, int i)
1700 struct mISDNport *mISDNport = (struct mISDNport *)instance;
1702 bchannel_event(mISDNport, i, B_EVENT_TIMEOUT);
1708 int do_layer3(struct mlayer3 *ml3, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1712 * l3m must be queued, except for MT_ASSIGN
1715 struct mISDNport *mISDNport = (struct mISDNport *)ml3->priv;
1718 #ifdef OLD_MT_ASSIGN
1719 /* special MT_ASSIGN handling:
1721 * if we request a PID from mlayer, we always do it while lcr is locked.
1722 * therefore we must check the MT_ASSIGN reply first before we lock.
1723 * this is because the MT_ASSIGN reply is received with the requesting
1724 * process, not by the mlayer thread!
1725 * this means, that the reply is sent during call of the request.
1726 * we must check if we get a reply and we know that we lcr is currently
1729 if (cmd==MT_ASSIGN && (pid&MISDN_PID_CR_FLAG) && (pid>>16)==MISDN_CES_MASTER) {
1730 /* let's do some checking if someone changes stack behaviour */
1731 if (mt_assign_pid != 0)
1732 FATAL("someone played with the mISDNuser stack. MT_ASSIGN not currently expected.\n");
1733 mt_assign_pid = pid;
1737 /* queue message, create, if required */
1739 l3m = alloc_l3_msg();
1741 FATAL("No memory for layer 3 message\n");
1743 mb = container_of(l3m, struct mbuffer, l3);
1746 mqueue_tail(&mISDNport->upqueue, mb);
1747 if (!upqueue_avail) {
1748 // multiple threads may cause multiple calls of this section, but this
1749 // results only in multiple processing of the upqueue read.
1750 // this is no problem.
1754 ret = write(upqueue_pipe[1], &byte, 1);
1759 int mISDN_getportbyname(int sock, int cnt, char *portname)
1761 struct mISDN_devinfo devinfo;
1765 while (port < cnt) {
1767 ret = ioctl(sock, IMGETDEVINFO, &devinfo);
1770 if (!strcasecmp(devinfo.name, portname))
1781 * global function to add a new card (port)
1783 struct mISDNport *mISDNport_open(struct interface_port *ifport)
1786 struct mISDNport *mISDNport, **mISDNportp;
1787 int port = ifport->portnum;
1788 int ptp = ifport->ptp;
1789 int force_nt = ifport->nt;
1790 int l1hold = ifport->l1hold;
1791 int l2hold = ifport->l2hold;
1792 int ss5 = ifport->ss5;
1796 // struct mlayer3 *ml3;
1797 struct mISDN_devinfo devinfo;
1798 unsigned int protocol, prop;
1800 /* check port counts */
1801 ret = ioctl(mISDNsocket, IMGETCOUNT, &cnt);
1803 fprintf(stderr, "Cannot get number of mISDN devices. (ioctl IMGETCOUNT failed ret=%d)\n", ret);
1808 PERROR_RUNTIME("Found no card. Please be sure to load card drivers.\n");
1812 port = mISDN_getportbyname(mISDNsocket, cnt, ifport->portname);
1814 PERROR_RUNTIME("Port name '%s' not found, use 'misdn_info' tool to list all existing ports.\n", ifport->portname);
1817 // note: 'port' has still the port number
1819 if (port>cnt || port<0) {
1820 PERROR_RUNTIME("Port (%d) given at 'ports' (options.conf) is out of existing port range (%d-%d)\n", port, 0, cnt);
1824 /* get port attributes */
1825 pri = bri = pots = nt = te = 0;
1827 ret = ioctl(mISDNsocket, IMGETDEVINFO, &devinfo);
1829 PERROR_RUNTIME("Cannot get device information for port %d. (ioctl IMGETDEVINFO failed ret=%d)\n", port, ret);
1832 if (devinfo.Dprotocols & (1 << ISDN_P_TE_S0)) {
1836 if (devinfo.Dprotocols & (1 << ISDN_P_NT_S0)) {
1840 if (devinfo.Dprotocols & (1 << ISDN_P_TE_E1)) {
1844 if (devinfo.Dprotocols & (1 << ISDN_P_NT_E1)) {
1849 if (devinfo.Dprotocols & (1 << ISDN_P_FXS)) {
1855 if (devinfo.Dprotocols & (1 << ISDN_P_FXO)) {
1860 if (force_nt && !nt) {
1861 PERROR_RUNTIME("Port %d does not support NT-mode\n", port);
1865 PERROR_RUNTIME("Port %d supports BRI and PRI?? What kind of controller is that?. (Can't use this!)\n", port);
1868 if (pots && !bri && !pri) {
1869 PERROR_RUNTIME("Port %d supports POTS, LCR does not!\n", port);
1873 PERROR_RUNTIME("Port %d does not support BRI nor PRI!\n", port);
1877 PERROR_RUNTIME("Port %d does not support NT-mode nor TE-mode!\n", port);
1880 /* set NT by turning off TE */
1883 /* if TE an NT is supported (and not forced to NT), turn off NT */
1887 /* check for double use of port */
1889 mISDNport = mISDNport_first;
1891 if (mISDNport->portnum == port)
1893 mISDNport = mISDNport->next;
1896 PERROR_RUNTIME("Port %d already in use by LCR. You can't use a NT port multiple times.\n", port);
1901 /* check for continous channelmap with no bchannel on slot 16 */
1902 if (test_channelmap(0, devinfo.channelmap)) {
1903 PERROR_RUNTIME("Port %d provides channel 0, but we cannot access it!\n", port);
1907 while(i < (int)devinfo.nrbchan + 1) {
1909 if (test_channelmap(i, devinfo.channelmap)) {
1910 PERROR("Port %d provides bchannel 16. Pleas upgrade mISDN, if this port is mISDN loopback interface.\n", port);
1914 if (!test_channelmap(i, devinfo.channelmap)) {
1915 PERROR_RUNTIME("Port %d has no channel on slot %d!\n", port, i);
1922 /* add mISDNport structure */
1923 mISDNportp = &mISDNport_first;
1925 mISDNportp = &((*mISDNportp)->next);
1926 mISDNport = (struct mISDNport *)MALLOC(sizeof(struct mISDNport));
1927 add_timer(&mISDNport->l2establish, l2establish_timeout, mISDNport, 0);
1929 /* ss5 link is always active */
1930 mISDNport->l1link = 1;
1931 mISDNport->l2link = 1;
1933 mISDNport->l1link = -1;
1934 mISDNport->l2link = -1;
1937 *mISDNportp = mISDNport;
1939 /* if pri, must set PTP */
1943 /* set ss5 params */
1945 /* try to keep interface enabled */
1965 /* allocate ressources of port */
1966 protocol = (nt)?L3_PROTOCOL_DSS1_NET:L3_PROTOCOL_DSS1_USER;
1967 prop = (1 << MISDN_FLG_L2_CLEAN);
1968 if (ptp) // ptp forced
1969 prop |= (1 << MISDN_FLG_PTP);
1970 if (nt) // supports hold/retrieve on nt-mode
1971 prop |= (1 << MISDN_FLG_NET_HOLD);
1972 if (l1hold) // supports layer 1 hold
1973 prop |= (1 << MISDN_FLG_L1_HOLD);
1974 if (l2hold) // supports layer 2 hold
1975 prop |= (1 << MISDN_FLG_L2_HOLD);
1976 /* open layer 3 and init upqueue */
1977 /* queue must be initializes, because l3-thread may send messages during open_layer3() */
1978 mqueue_init(&mISDNport->upqueue);
1979 mISDNport->ml3 = open_layer3(port, protocol, prop , do_layer3, mISDNport);
1980 if (!mISDNport->ml3) {
1981 mqueue_purge(&mISDNport->upqueue);
1982 PERROR_RUNTIME("open_layer3() failed for port %d\n", port);
1990 "PORT (open failed)");
1992 mISDNport_close(mISDNport);
1996 SCPY(mISDNport->name, devinfo.name);
1997 mISDNport->b_num = devinfo.nrbchan;
1998 mISDNport->portnum = port;
1999 mISDNport->ntmode = nt;
2000 mISDNport->tespecial = ifport->tespecial;
2001 mISDNport->pri = pri;
2002 mISDNport->ptp = ptp;
2003 mISDNport->l1hold = l1hold;
2004 mISDNport->l2hold = l2hold;
2005 mISDNport->ss5 = ss5;
2006 PDEBUG(DEBUG_ISDN, "Port has %d b-channels.\n", mISDNport->b_num);
2008 while(i < mISDNport->b_num) {
2009 mISDNport->b_state[i] = B_STATE_IDLE;
2010 add_timer(&mISDNport->b_timer[i], b_timer_timeout, mISDNport, i);
2014 /* if ptp, pull up the link */
2015 if (mISDNport->l2hold && (mISDNport->ptp || !mISDNport->ntmode)) {
2016 mISDNport->ml3->to_layer3(mISDNport->ml3, MT_L2ESTABLISH, 0, NULL);
2017 l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_REQ, DIRECTION_OUT);
2018 add_trace("tei", NULL, "%d", 0);
2020 schedule_timer(&mISDNport->l2establish, 5, 0); /* 5 seconds */
2023 /* for nt-mode ptmp the link is always up */
2024 if (mISDNport->ntmode && !mISDNport->ptp)
2025 mISDNport->l2link = 1;
2027 PDEBUG(DEBUG_BCHANNEL, "using 'mISDN_dsp.o' module\n");
2029 start_trace(mISDNport->portnum,
2037 add_trace("mode", NULL, (mISDNport->ntmode)?"network":"terminal");
2038 add_trace("channels", NULL, "%d", mISDNport->b_num);
2040 add_trace("ccitt#5", NULL, "enabled");
2048 * load static port instances, if required by mISDNport
2050 void mISDNport_static(struct mISDNport *mISDNport)
2055 while(i < mISDNport->b_num) {
2058 ss5_create_channel(mISDNport, i);
2066 * function to free ALL cards (ports)
2068 void mISDNport_close_all(void)
2070 /* free all ports */
2071 while(mISDNport_first)
2072 mISDNport_close(mISDNport_first);
2076 * free only one port
2078 void mISDNport_close(struct mISDNport *mISDNport)
2080 struct mISDNport **mISDNportp;
2082 class PmISDN *isdnport;
2085 /* remove all port instance that are linked to this mISDNport */
2089 if ((port->p_type&PORT_CLASS_MASK) == PORT_CLASS_mISDN) {
2090 isdnport = (class PmISDN *)port;
2091 if (isdnport->p_m_mISDNport && isdnport->p_m_mISDNport == mISDNport) {
2092 PDEBUG(DEBUG_ISDN, "port %s uses mISDNport %d, destroying it.\n", isdnport->p_name, mISDNport->portnum);
2100 /* only if we are already part of interface */
2101 if (mISDNport->ifport) {
2102 start_trace(mISDNport->portnum,
2103 mISDNport->ifport->interface,
2113 /* free bchannels */
2115 while(i < mISDNport->b_num) {
2116 if (mISDNport->b_sock[i].inuse) {
2117 _bchannel_destroy(mISDNport, i);
2118 PDEBUG(DEBUG_BCHANNEL, "freeing %s port %d bchannel (index %d).\n", (mISDNport->ntmode)?"NT":"TE", mISDNport->portnum, i);
2120 if (mISDNport->b_timer[i].inuse) {
2121 del_timer(&mISDNport->b_timer[i]);
2125 del_timer(&mISDNport->l2establish);
2127 /* close layer 3, if open */
2128 if (mISDNport->ml3) {
2129 close_layer3(mISDNport->ml3);
2133 mqueue_purge(&mISDNport->upqueue);
2135 /* remove from list */
2136 mISDNportp = &mISDNport_first;
2137 while(*mISDNportp) {
2138 if (*mISDNportp == mISDNport) {
2139 *mISDNportp = (*mISDNportp)->next;
2143 mISDNportp = &((*mISDNportp)->next);
2147 FATAL("mISDNport not in list\n");
2149 FREE(mISDNport, sizeof(struct mISDNport));
2156 * enque data from remote port
2158 int PmISDN::bridge_rx(unsigned char *data, int length)
2160 unsigned char buf[MISDN_HEADER_LEN+((length>p_m_preload)?length:p_m_preload)];
2161 struct mISDNhead *hh = (struct mISDNhead *)buf;
2164 if (p_m_b_index < 0)
2166 if (p_m_mISDNport->b_state[p_m_b_index] != B_STATE_ACTIVE)
2169 /* check if high priority tones exist
2170 * ignore data in this case
2172 if (p_tone_name[0] || p_m_crypt_msg_loops || p_m_inband_send_on)
2175 /* preload procedure
2176 * if transmit buffer in DSP module is empty,
2177 * preload it to DSP_LOAD to prevent jitter gaps.
2179 * if load runs empty, preload again.
2181 if (p_m_disable_dejitter && p_m_load == 0 && p_m_preload > 0) {
2182 //printf("preload=%d\n", p_m_preload);
2183 hh->prim = PH_DATA_REQ;
2185 memset(buf+MISDN_HEADER_LEN, silence, p_m_preload);
2186 ret = sendto(p_m_mISDNport->b_sock[p_m_b_index].fd, buf, MISDN_HEADER_LEN+p_m_preload, 0, NULL, 0);
2188 PERROR("Failed to send to socket %d\n", p_m_mISDNport->b_sock[p_m_b_index].fd);
2189 p_m_load += p_m_preload;
2190 schedule_timer(&p_m_loadtimer, 0, PORT_TRANSMIT * 125);
2193 /* drop if load would exceed ISDN_MAXLOAD
2194 * this keeps the delay not too high
2196 //printf("load=%d len=%d 2*preload=%d\n", p_m_load, length, p_m_preload << 1);
2197 if (p_m_disable_dejitter && p_m_preload > 0 && p_m_load+length > (p_m_preload << 1))
2200 /* make and send frame */
2201 hh->prim = PH_DATA_REQ;
2203 memcpy(buf+MISDN_HEADER_LEN, data, length);
2204 ret = sendto(p_m_mISDNport->b_sock[p_m_b_index].fd, buf, MISDN_HEADER_LEN+length, 0, NULL, 0);
2206 PERROR("Failed to send to socket %d\n", p_m_mISDNport->b_sock[p_m_b_index].fd);
2212 int PmISDN::inband_send(unsigned char *buffer, int len)
2214 PERROR("this function must be derived to function!\n");
2218 void PmISDN::inband_send_on(void)
2220 PDEBUG(DEBUG_PORT, "turning inband signalling send on.\n");
2221 p_m_inband_send_on = 1;
2224 void PmISDN::inband_send_off(void)
2226 PDEBUG(DEBUG_PORT, "turning inband signalling send off.\n");
2227 p_m_inband_send_on = 0;
2230 void PmISDN::inband_receive(unsigned char *buffer, int len)
2233 // if (len >= SS5_DECODER_NPOINTS)
2234 // ss5_decode(buffer, SS5_DECODER_NPOINTS);
2235 PERROR("this function must be derived to function!\n");
2238 void PmISDN::inband_receive_on(void)
2240 /* this must work during constructor, see ss5.cpp */
2241 PDEBUG(DEBUG_PORT, "turning inband signalling receive on.\n");
2242 p_m_inband_receive_on = 1;
2246 void PmISDN::inband_receive_off(void)
2248 PDEBUG(DEBUG_PORT, "turning inband signalling receive off.\n");
2249 p_m_inband_receive_on = 0;
2253 void PmISDN::mute_on(void)
2257 PDEBUG(DEBUG_PORT, "turning mute on.\n");
2259 set_conf(p_m_conf, 0);
2262 void PmISDN::mute_off(void)
2266 PDEBUG(DEBUG_PORT, "turning mute off.\n");
2268 set_conf(0, p_m_conf);