1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** mISDN port abstraction for dss1 and sip **
10 \*****************************************************************************/
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
28 #define ISDN_PID_L2_B_USER 0x420000ff
29 #define ISDN_PID_L3_B_USER 0x430000ff
30 #define ISDN_PID_L4_B_USER 0x440000ff
32 /* used for udevice */
35 /* noise randomizer */
36 unsigned char mISDN_rand[256];
37 int mISDN_rand_count = 0;
39 /* the device handler and port list */
42 /* list of mISDN ports */
43 struct mISDNport *mISDNport_first;
48 PmISDN::PmISDN(int type, mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive) : Port(type, portname, settings)
50 p_m_mISDNport = mISDNport;
51 p_m_portnum = mISDNport->portnum;
61 p_m_txvol = p_m_rxvol = 0;
64 #warning set delay by routing parameter or interface config
70 p_m_dtmf = !options.nodtmf;
71 sollen wir daraus eine interface-option machen?:
74 #warning denke auch an die andere seite. also das setup sollte dies weitertragen
78 p_m_crypt_msg_loops = 0;
79 p_m_crypt_msg_loops = 0;
80 p_m_crypt_msg_len = 0;
81 p_m_crypt_msg[0] = '\0';
82 p_m_crypt_msg_current = 0;
83 p_m_crypt_key[0] = '\0';
84 p_m_crypt_key_len = 0;
86 p_m_crypt_listen_state = 0;
87 p_m_crypt_listen_len = 0;
88 p_m_crypt_listen_msg[0] = '\0';
89 p_m_crypt_listen_crc = 0;
91 /* if any channel requested by constructor */
92 if (channel == CHANNEL_ANY)
96 mISDNport->b_reserved++;
100 /* reserve channel */
101 if (channel) // only if constructor was called with a channel resevation
102 seize_bchannel(channel, exclusive);
104 /* we increase the number of objects: */
106 PDEBUG(DEBUG_ISDN, "Created new mISDNPort(%s). Currently %d objects use, port #%d\n", portname, mISDNport->use, p_m_portnum);
115 struct message *message;
117 /* remove bchannel relation */
123 PDEBUG(DEBUG_ISDN, "destroy mISDNPort(%s). endpoint still exists, releaseing.\n", p_name);
124 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
125 message->param.disconnectinfo.cause = 16;
126 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
127 message_put(message);
128 /* remove from list */
129 free_epointlist(p_epointlist);
132 /* we decrease the number of objects: */
133 p_m_mISDNport->use--;
134 PDEBUG(DEBUG_ISDN, "destroyed mISDNPort(%s). Currently %d objects\n", p_name, p_m_mISDNport->use);
139 * send control information to the channel (dsp-module)
141 void ph_control(unsigned long b_addr, int c1, int c2)
143 unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+sizeof(int)];
144 iframe_t *ctrl = (iframe_t *)buffer;
145 unsigned long *d = (unsigned long *)&ctrl->data.p;
147 ctrl->prim = PH_CONTROL | REQUEST;
148 ctrl->addr = b_addr | FLG_MSG_DOWN;
150 ctrl->len = sizeof(int)*2;
153 mISDN_write(mISDNdevice, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
156 void ph_control_block(unsigned long b_addr, int c1, void *c2, int c2_len)
158 unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len];
159 iframe_t *ctrl = (iframe_t *)buffer;
160 unsigned long *d = (unsigned long *)&ctrl->data.p;
162 ctrl->prim = PH_CONTROL | REQUEST;
163 ctrl->addr = b_addr | FLG_MSG_DOWN;
165 ctrl->len = sizeof(int)+c2_len;
167 memcpy(d, c2, c2_len);
168 mISDN_write(mISDNdevice, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
173 * activate / deactivate bchannel
175 static void bchannel_activate(struct mISDNport *mISDNport, int i)
179 /* we must activate if we are deactivated */
180 if (mISDNport->b_state[i] == B_STATE_IDLE)
182 /* activate bchannel */
183 PDEBUG(DEBUG_BCHANNEL, "activating bchannel (index %d), because currently idle (address 0x%x).\n", i, mISDNport->b_addr[i]);
184 act.prim = DL_ESTABLISH | REQUEST;
185 act.addr = mISDNport->b_addr[i] | FLG_MSG_DOWN;
188 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
189 mISDNport->b_state[i] = B_STATE_ACTIVATING;
193 /* if we are active, we configure our channel */
194 if (mISDNport->b_state[i] == B_STATE_ACTIVE)
196 unsigned char buffer[mISDN_HEADER_LEN+(ISDN_PRELOAD<<3)];
197 iframe_t *pre = (iframe_t *)buffer; /* preload data */
198 unsigned char *p = (unsigned char *)&pre->data.p;
200 /* it is an error if this channel is not associated with a port object */
201 if (!mISDNport->b_port[i])
203 PERROR("bchannel index i=%d not associated with a port object\n", i);
207 /* configure dsp features */
208 if (mISDNport->b_port[i]->p_m_txdata)
210 PDEBUG(DEBUG_BCHANNEL, "during activation, we set txdata to txdata=%d.\n", mISDNport->b_port[i]->p_m_txdata);
211 ph_control(mISDNport->b_addr[i], (mISDNport->b_port[i]->p_m_txdata)?CMX_TXDATA_ON:CMX_TXDATA_OFF);
213 if (mISDNport->b_port[i]->p_m_delay)
215 PDEBUG(DEBUG_BCHANNEL, "during activation, we set delay to delay=%d.\n", mISDNport->b_port[i]->p_m_delay);
216 ph_control(mISDNport->b_addr[i], CMX_DELAY, mISDNport->b_port[i]->p_m_delay);
218 if (mISDNport->b_port[i]->p_m_txvol)
220 PDEBUG(DEBUG_BCHANNEL, "during activation, we change tx-volume to shift=%d.\n", mISDNport->b_port[i]->p_m_txvol);
221 ph_control(mISDNport->b_addr[i], VOL_CHANGE_TX, mISDNport->b_port[i]->p_m_txvol);
223 if (mISDNport->b_port[i]->p_m_rxvol)
225 PDEBUG(DEBUG_BCHANNEL, "during activation, we change rx-volume to shift=%d.\n", mISDNport->b_port[i]->p_m_rxvol);
226 ph_control(mISDNport->b_addr[i], VOL_CHANGE_RX, mISDNport->b_port[i]->p_m_rxvol);
228 //tone if (mISDNport->b_port[i]->p_m_conf && !mISDNport->b_port[i]->p_m_tone)
229 if (mISDNport->b_port[i]->p_m_conf)
231 PDEBUG(DEBUG_BCHANNEL, "during activation, we change conference to conf=%d.\n", mISDNport->b_port[i]->p_m_conf);
232 ph_control(mISDNport->b_addr[i], CMX_CONF_JOIN, mISDNport->b_port[i]->p_m_conf);
234 if (mISDNport->b_port[i]->p_m_echo)
236 PDEBUG(DEBUG_BCHANNEL, "during activation, we set echo to echo=%d.\n", mISDNport->b_port[i]->p_m_echo);
237 ph_control(mISDNport->b_addr[i], CMX_ECHO_ON, 0);
239 if (mISDNport->b_port[i]->p_m_tone)
241 PDEBUG(DEBUG_BCHANNEL, "during activation, we set tone to tone=%d.\n", mISDNport->b_port[i]->p_m_tone);
242 ph_control(mISDNport->b_addr[i], TONE_PATT_ON, mISDNport->b_port[i]->p_m_tone);
244 if (mISDNport->b_port[i]->p_m_rxoff)
246 PDEBUG(DEBUG_BCHANNEL, "during activation, we set rxoff to rxoff=%d.\n", mISDNport->b_port[i]->p_m_rxoff);
247 ph_control(mISDNport->b_addr[i], CMX_RECEIVE_OFF, 0);
250 if (mISDNport->b_port[i]->p_m_txmix)
252 PDEBUG(DEBUG_BCHANNEL, "during activation, we set txmix to txmix=%d.\n", mISDNport->b_port[i]->p_m_txmix);
253 ph_control(mISDNport->b_addr[i], CMX_MIX_ON, 0);
256 if (mISDNport->b_port[i]->p_m_dtmf)
258 PDEBUG(DEBUG_BCHANNEL, "during activation, we set dtmf to dtmf=%d.\n", mISDNport->b_port[i]->p_m_dtmf);
259 ph_control(mISDNport->b_addr[i], DTMF_TONE_START, 0);
261 if (mISDNport->b_port[i]->p_m_crypt)
263 PDEBUG(DEBUG_BCHANNEL, "during activation, we set crypt to crypt=%d.\n", mISDNport->b_port[i]->p_m_crypt);
264 ph_control_block(mISDNport->b_addr[i], BF_ENABLE_KEY, mISDNport->b_port[i]->p_m_crypt_key, mISDNport->b_port[i]->p_m_crypt_key_len);
266 todo: wer startet/stoppt eigentlich den audio-transmit
270 static void bchannel_deactivate(struct mISDNport *mISDNport, int i)
274 if (mISDNport->b_state[i] == B_STATE_ACTIVE)
276 /* reset dsp features */
277 if (mISDNport->b_port[i])
279 if (mISDNport->b_port[i]->p_m_txdata)
281 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset txdata from txdata=%d.\n", mISDNport->b_port[i]->p_m_txdata);
282 ph_control(mISDNport->b_addr[i], CMX_TXDATA_OFF, 0);
284 if (mISDNport->b_port[i]->p_m_delay)
286 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset delay from delay=%d.\n", mISDNport->b_port[i]->p_m_delay);
287 ph_control(mISDNport->b_addr[i], CMX_JITTER, 0);
289 if (mISDNport->b_port[i]->p_m_txvol)
291 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset tx-volume from shift=%d.\n", mISDNport->b_port[i]->p_m_txvol);
292 ph_control(mISDNport->b_addr[i], VOL_CHANGE_TX, 0);
294 if (mISDNport->b_port[i]->p_m_rxvol)
296 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset rx-volume from shift=%d.\n", mISDNport->b_port[i]->p_m_rxvol);
297 ph_control(mISDNport->b_addr[i], VOL_CHANGE_RX, 0);
299 if (mISDNport->b_port[i]->p_m_conf)
301 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we release conference from conf=%d.\n", mISDNport->b_port[i]->p_m_conf);
302 ph_control(mISDNport->b_addr[i], CMX_CONF_SPLIT, 0);
304 if (mISDNport->b_port[i]->p_m_echo)
306 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset echo from echo=%d.\n", mISDNport->b_port[i]->p_m_echo);
307 ph_control(mISDNport->b_addr[i], CMX_ECHO_OFF, 0);
309 if (mISDNport->b_port[i]->p_m_tone)
311 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset tone from tone=%d.\n", mISDNport->b_port[i]->p_m_tone);
312 ph_control(mISDNport->b_addr[i], TONE_PATT_OFF, 0);
314 if (mISDNport->b_port[i]->p_m_rxoff)
316 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset rxoff from rxoff=%d.\n", mISDNport->b_port[i]->p_m_rxoff);
317 ph_control(mISDNport->b_addr[i], CMX_RECEIVE_ON, 0);
320 if (mISDNport->b_port[i]->p_m_txmix)
322 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset txmix from txmix=%d.\n", mISDNport->b_port[i]->p_m_txmix);
323 ph_control(mISDNport->b_addr[i], CMX_MIX_OFF, 0);
326 if (mISDNport->b_port[i]->p_m_dtmf)
328 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset dtmf from dtmf=%d.\n", mISDNport->b_port[i]->p_m_dtmf);
329 ph_control(mISDNport->b_addr[i], DTMF_TONE_STOP, 0);
331 if (mISDNport->b_port[i]->p_m_crypt)
333 PDEBUG(DEBUG_BCHANNEL, "during deactivation, we reset crypt from crypt=%d.\n", mISDNport->b_port[i]->p_m_dtmf);
334 ph_control(mISDNport->b_addr[i], BF_DISABLE, 0);
337 /* deactivate bchannel */
338 PDEBUG(DEBUG_BCHANNEL, "deactivating bchannel (index %d), because currently active.\n", i);
339 dact.prim = DL_RELEASE | REQUEST;
340 dact.addr = mISDNport->b_addr[i] | FLG_MSG_DOWN;
343 mISDN_write(mISDNdevice, &dact, mISDN_HEADER_LEN+dact.len, TIMEOUT_1SEC);
344 mISDNport->b_state[i] = B_STATE_DEACTIVATING;
351 * check for available channel and reserve+set it.
352 * give channel number or SEL_CHANNEL_ANY or SEL_CHANNEL_NO
354 * returns -(cause value) or x = channel x or 0 = no channel
356 denke ans aktivieren und deaktivieren
357 int PmISDN::seize_bchannel(int channel, int exclusive)
361 /* the channel is what we have */
362 if (p_m_b_channel == channel)
365 /* if channel already in use, release it */
370 if (channel==CHANNEL_NO || channel==0)
373 /* is channel in range ? */
375 || (channel>p_m_mISDNport->b_num && channel<16)
376 || ((channel-1)>p_m_mISDNport->b_num && channel>16)) /* channel-1 because channel 16 is not counted */
377 return(-6); /* channel unacceptable */
379 /* request exclusive channel */
380 if (exclusive && channel>0)
382 i = channel-1-(channel>16);
383 if (p_m_mISDNport->b_port[i])
384 return(-44); /* requested channel not available */
388 /* ask for channel */
391 i = channel-1-(channel>16);
392 if (p_m_mISDNport->b_port[i] == NULL)
396 /* search for channel */
398 while(i < p_m_mISDNport->b_num)
400 if (!p_m_mISDNport->b_port[i])
402 channel = i+1+(i>=15);
407 return(-34); /* no free channel */
411 p_m_mISDNport->b_port[i] = this;
413 p_m_b_channel = channel;
414 p_m_b_exclusive = exclusive;
415 p_m_b_stid = p_m_mISDNport->b_stid[i];
416 p_m_b_addr = p_m_mISDNport->b_addr[i];
419 /* reserve channel */
420 if (p_m_b_reserve == 0) // already reserved
423 mISDNport->b_reserved++;
426 PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) seizing bchannel %d (index %d)\n", p_name, channel, i);
432 * drop reserved channel and unset it.
434 void PmISDN::drop_bchannel(void)
436 /* unreserve channel */
438 p_m_mISDNport->b_reserved--;
445 PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) dropping bchannel\n", p_name);
447 p_m_mISDNport->b_port[p_m_b_index] = NULL;
457 * data is to be transmitted to the remote
459 wech void Port::transmit(unsigned char *buffer, int length, int tonelength)
461 /* send tone data to isdn device only if we have data, otherwhise we send nothing */
462 if (tonelength>0 && (p_tone_fh>=0 || p_tone_fetched || p_m_crypt_msg_loops))
464 unsigned char buf[mISDN_HEADER_LEN+tonelength];
465 iframe_t *frm = (iframe_t *)buf;
467 if (p_m_crypt_msg_loops)
469 /* send pending message */
472 tosend = p_m_crypt_msg_len - p_m_crypt_msg_current;
475 memcpy(p, p_m_crypt_msg+p_m_crypt_msg_current, tosend);
476 p_m_crypt_msg_current += tosend;
477 if (p_m_crypt_msg_current == p_m_crypt_msg_len)
479 p_m_crypt_msg_current = 0;
480 p_m_crypt_msg_loops--;
483 frm->prim = DL_DATA | REQUEST;
484 frm->addr = p_m_b_addr | FLG_MSG_DOWN;
486 frm->len = tonelength;
487 memcpy(&frm->data.p, buffer, tonelength);
488 mISDN_write(mISDNdevice, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
490 if (p_debug_nothingtosend)
492 p_debug_nothingtosend = 0;
493 PDEBUG((DEBUG_PORT | DEBUG_BCHANNEL), "PmISDN(%s) start sending, because we have tones and/or remote audio.\n", p_name);
497 if (!p_debug_nothingtosend)
499 p_debug_nothingtosend = 1;
500 PDEBUG((DEBUG_PORT | DEBUG_BCHANNEL), "PmISDN(%s) stop sending, because we have only silence.\n", p_name);
509 int PmISDN::handler(void)
511 struct message *message;
514 if ((ret = Port::handler()))
517 inbuffer = (p_fromup_buffer_writep - p_fromup_buffer_readp) & FROMUP_BUFFER_MASK
518 /* send tone data to isdn device only if we have data */
519 if (p_tone_fh>=0 || p_tone_fetched || p_m_crypt_msg_loops || inbuffer)
521 /* calculate how much to transmit */
524 elapsed = ISDN_PRELOAD << 3; /* preload for the first time */
527 elapsed = 1000 * (now_tv.sec - p_last_tv_sec)
528 + (now_tv.usec/1000) - p_last_tv_msec;
529 /* gap was greater preload, so only fill up to preload level */
530 if (elapsed > (ISDN_PRELOAD<<3))
532 elapsed = ISDN_PRELOAD << 3
535 if (elapsed >= ISDN_TRANSMIT)
537 unsigned char buf[mISDN_HEADER_LEN+(ISDN_PRELOAD<<3)], *p = buf;
538 iframe_t *frm = (iframe_t *)buf;
540 p_last_tv_sec = now_tv.sec;
541 p_last_tv_msec = now_tv.usec/1000;
544 length = read_audio(buffer, elapsed);
548 * the fromup_buffer data is written to the beginning of the buffer
549 * the part that is filles with tones (length) is skipped, so tones have priority
550 * the length value is increased by the number of data copied from fromup_buffer
554 /* inbuffer might be less than we skip due to audio */
555 if (inbuffer <= length)
558 p_fromup_buffer_readp = p_fromup_buffer_writep;
562 /* skip what we already have with tones */
563 p_fromup_buffer_readp = (p_fromup_buffer_readp + length) & FROMUP_BUFFER_MASK;
566 /* if we have more in buffer, than we send this time */
567 if (inbuffer > (elapsed-length))
568 inbuffer = elapsed - length;
569 /* set length to what we actually have */
570 length = length + inbuffer;
571 /* now fill up with fromup_buffer */
574 *p++ = p_fromup_buffer[p_fromup_buffer_readp];
575 p_fromup_buffer_readp = (p_fromup_buffer_readp + 1) & FROMUP_BUFFER_MASK;
580 /* overwrite buffer with crypto stuff */
581 if (p_m_crypt_msg_loops)
583 /* send pending message */
586 /* we need full length */
589 tosend = p_m_crypt_msg_len - p_m_crypt_msg_current;
592 memcpy(buffer, p_m_crypt_msg+p_m_crypt_msg_current, tosend);
593 p_m_crypt_msg_current += tosend;
594 if (p_m_crypt_msg_current == p_m_crypt_msg_len)
596 p_m_crypt_msg_current = 0;
597 p_m_crypt_msg_loops--;
600 frm->prim = DL_DATA | REQUEST;
601 frm->addr = p_m_b_addr | FLG_MSG_DOWN;
604 memcpy(&frm->data.p, buffer, length);
605 mISDN_write(mISDNdevice, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
607 if (p_debug_nothingtosend)
609 p_debug_nothingtosend = 0;
610 PDEBUG((DEBUG_PORT | DEBUG_BCHANNEL), "PmISDN(%s) start sending, because we have tones and/or remote audio.\n", p_name);
616 if (!cwp_debug_nothingtosend)
618 p_debug_nothingtosend = 1;
619 PDEBUG((DEBUG_PORT | DEBUG_BCHANNEL), "PmISDN(%s) stop sending, because we have only silence.\n", p_name);
623 // NOTE: deletion is done by the child class
625 /* handle timeouts */
628 if (p_m_timer+p_m_timeout < now_d)
630 PDEBUG(DEBUG_ISDN, "(%s) timeout after %d seconds detected (state=%d).\n", p_name, p_m_timeout, p_state);
632 /* send timeout to endpoint */
633 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TIMEOUT);
634 message->param.state = p_state;
635 message_put(message);
640 return(0); /* nothing done */
645 * whenever we get audio data from bchannel, we process it here
647 void PmISDN::bchannel_receive(iframe_t *frm)
649 unsigned char *data_temp;
650 unsigned long length_temp;
651 struct message *message;
654 long long jitter_now;
659 // iframe_t rsp; /* response to possible indication */
661 #warning BCHANNEL-DEBUG
663 // check if we are part of all ports */
664 class Port *port = port_first;
673 PERROR_RUNTIME("**************************************************\n");
674 PERROR_RUNTIME("*** BCHANNEL-DEBUG: !this! is not in list of ports\n");
675 PERROR_RUNTIME("**************************************************\n");
682 if (frm->prim == (PH_CONTROL | INDICATION))
686 PERROR("SHORT READ OF PH_CONTROL INDICATION\n");
689 cont = *((unsigned long *)&frm->data.p);
690 // PDEBUG(DEBUG_PORT, "PmISDN(%s) received a PH_CONTROL INDICATION 0x%x\n", p_name, cont);
691 if ((cont&(~DTMF_TONE_MASK)) == DTMF_TONE_VAL)
693 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DTMF);
694 message->param.dtmf = cont & DTMF_TONE_MASK;
695 PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION DTMF digit '%c'\n", p_name, message->param.dtmf);
696 message_put(message);
702 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CRYPT);
703 message->param.crypt.type = CC_ERROR_IND;
704 PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION reject of blowfish.\n", p_name);
705 message_put(message);
709 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CRYPT);
710 message->param.crypt.type = CC_ACTBF_CONF;
711 PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION accept of blowfish.\n", p_name);
712 message_put(message);
718 /* if rx is off, it may happen that fifos send us pending informations, we just ignore them */
719 PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) ignoring rx data, because 'txdata' is turned off\n", p_name);
723 record(&(cont+1), frm->len - 4, 1); // from up
727 PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION unknown 0x%x.\n", p_name, cont);
731 if (frm->prim != (PH_DATA | INDICATION))
733 PERROR("Bchannel received unknown primitve: 0x%x\n", frm->prim);
737 /* calls will not process any audio data unless
738 * the call is connected OR tones feature is enabled.
740 if (p_state!=PORT_STATE_CONNECT
741 && !p_m_mISDNport->is_tones)
745 /* the bearer capability must be audio in order to send and receive
746 * audio prior or after connect.
748 if (!(p_bearerinfo.capability&CLASS_CAPABILITY_AUDIO) && p_state!=PORT_STATE_CONNECT)
752 /* if rx is off, it may happen that fifos send us pending informations, we just ignore them */
755 PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) ignoring data, because rx is turned off\n", p_name);
761 record((unsigned char *)&frm->data.p, frm->len, 0); // from down
763 /* randomize and listen to crypt message if enabled */
764 if (p_m_crypt_listen)
766 /* the noisy randomizer */
767 p = (unsigned char *)&frm->data.p;
770 mISDN_rand[mISDN_rand_count & 0xff] += *p++;
772 cryptman_listen_bch((unsigned char *)&frm->data.p, frm->len);
775 p = (unsigned char *)&frm->data.p;
777 /* send data to epoint */
778 if (p_m_calldata && ACTIVE_EPOINT(p_epointlist)) /* only if we have an epoint object */
780 //printf("we are port %s and sending to epoint %d\n", p_m_cardname, p_epoint->serial);
781 length_temp = frm->len;
785 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DATA);
786 message->param.data.len = (length_temp>sizeof(message->param.data.data))?sizeof(message->param.data.data):length_temp;
787 memcpy(message->param.data.data, data_temp, message->param.data.len);
788 message->param.data.compressed = 1;
789 message->param.data.port_id = p_serial;
790 message->param.data.port_type = p_type;
791 message_put(message);
792 if (length_temp <= sizeof(message->param.data.data))
794 data_temp += sizeof(message->param.data.data);
795 length_temp -= sizeof(message->param.data.data);
799 /* response to the data indication */
800 rsp.prim = frm->prim & 0xfffffffc | RESPONSE;
801 rsp.addr = frm->addr & INST_ID_MASK | FLG_MSG_DOWN;
802 rsp.dinfo = frm->dinfo;
804 mISDN_write(mISDNdevice, &rsp, mISDN_HEADER_LEN+rsp.len, TIMEOUT_1SEC);
805 //PDEBUG(DEBUG_ISDN, "written %d bytes.\n", length);
813 void PmISDN::set_echotest(int echo)
815 if (p_m_echo != echo)
818 PDEBUG(DEBUG_ISDN, "we set echo to echo=%d.\n", p_m_echo);
820 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
821 ph_control(p_m_b_addr, p_m_echo?CMX_ECHO_ON:CMX_ECHO_OFF, 0);
828 void PmISDN::set_tone(char *dir, char *tone)
834 PDEBUG(DEBUG_ISDN, "isdn port now plays tone:'%s'.\n", tone);
841 /* check if we NOT really have to use a dsp-tone */
842 if (!options.dsptones)
846 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
848 PDEBUG(DEBUG_ISDN, "we reset tone from id=%d to OFF.\n", p_m_tone);
849 ph_control(p_m_b_addr, TONE_PATT_OFF, 0);
852 Port::set_tone(dir, tone);
858 /* now we USE dsp-tone, convert name */
859 else if (!strcmp(tone, "dialtone"))
861 switch(options.dsptones) {
862 case DSP_AMERICAN: id = TONE_AMERICAN_DIALTONE; break;
863 case DSP_GERMAN: id = TONE_GERMAN_DIALTONE; break;
864 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDDIALTONE; break;
866 } else if (!strcmp(tone, "dialpbx"))
868 switch(options.dsptones) {
869 case DSP_AMERICAN: id = TONE_AMERICAN_DIALPBX; break;
870 case DSP_GERMAN: id = TONE_GERMAN_DIALPBX; break;
871 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDDIALPBX; break;
873 } else if (!strcmp(tone, "ringing"))
875 switch(options.dsptones) {
876 case DSP_AMERICAN: id = TONE_AMERICAN_RINGING; break;
877 case DSP_GERMAN: id = TONE_GERMAN_RINGING; break;
878 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDRINGING; break;
880 } else if (!strcmp(tone, "ringpbx"))
882 switch(options.dsptones) {
883 case DSP_AMERICAN: id = TONE_AMERICAN_RINGPBX; break;
884 case DSP_GERMAN: id = TONE_GERMAN_RINGPBX; break;
885 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDRINGPBX; break;
887 } else if (!strcmp(tone, "busy"))
890 switch(options.dsptones) {
891 case DSP_AMERICAN: id = TONE_AMERICAN_BUSY; break;
892 case DSP_GERMAN: id = TONE_GERMAN_BUSY; break;
893 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDBUSY; break;
895 } else if (!strcmp(tone, "release"))
898 switch(options.dsptones) {
899 case DSP_AMERICAN: id = TONE_AMERICAN_HANGUP; break;
900 case DSP_GERMAN: id = TONE_GERMAN_HANGUP; break;
901 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDHANGUP; break;
903 } else if (!strcmp(tone, "cause_10"))
905 else if (!strcmp(tone, "cause_11"))
907 else if (!strcmp(tone, "cause_22"))
909 switch(options.dsptones) {
910 case DSP_AMERICAN: id = TONE_SPECIAL_INFO; break;
911 case DSP_GERMAN: id = TONE_GERMAN_GASSENBESETZT; break;
912 case DSP_OLDGERMAN: id = TONE_GERMAN_OLDBUSY; break;
914 } else if (!strncmp(tone, "cause_", 6))
915 id = TONE_SPECIAL_INFO;
919 /* if we have a tone that is not supported by dsp */
920 if (id==TONE_OFF && tone[0])
928 PDEBUG(DEBUG_ISDN, "we set tone to id=%d.\n", p_m_tone);
930 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
931 ph_control(p_m_b_addr, p_m_tone?TONE_PATT_ON:TONE_PATT_OFF, p_m_tone);
933 /* turn user-space tones off in cases of no tone OR dsp tone */
934 Port::set_tone("",NULL);
938 /* MESSAGE_mISDNSIGNAL */
939 //extern struct message *dddebug;
940 void PmISDN::message_mISDNsignal(unsigned long epoint_id, int message_id, union parameter *param)
942 switch(param->mISDNsignal.message)
944 case mISDNSIGNAL_VOLUME:
945 if (p_m_txvol != param->mISDNsignal.txvol)
947 p_m_txvol = param->mISDNsignal.txvol;
948 PDEBUG(DEBUG_BCHANNEL, "we change tx-volume to shift=%d.\n", p_m_txvol);
950 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
951 ph_control(p_m_b_addr, VOL_CHANGE_TX, p_m_txvol);
953 if (p_m_rxvol != param->mISDNsignal.rxvol)
955 p_m_rxvol = param->mISDNsignal.rxvol;
956 PDEBUG(DEBUG_BCHANNEL, "we change rx-volume to shift=%d.\n", p_m_rxvol);
958 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
959 ph_control(p_m_b_addr, VOL_CHANGE_RX, p_m_rxvol);
963 case mISDNSIGNAL_CONF:
964 //if (dddebug) PDEBUG(DEBUG_ISDN, "dddebug = %d\n", dddebug->type);
965 //tone if (!p_m_tone && p_m_conf!=param->mISDNsignal.conf)
966 if (p_m_conf != param->mISDNsignal.conf)
968 p_m_conf = param->mISDNsignal.conf;
969 PDEBUG(DEBUG_BCHANNEL, "we change conference to conf=%d.\n", p_m_conf);
971 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
972 ph_control(p_m_b_addr, (p_m_conf)?CMX_CONF_JOIN:CMX_CONF_SPLIT, p_m_conf);
974 /* we must set, even if currently tone forbids conf */
975 p_m_conf = param->mISDNsignal.conf;
976 //if (dddebug) PDEBUG(DEBUG_ISDN, "dddebug = %d\n", dddebug->type);
979 case mISDNSIGNAL_CALLDATA:
980 if (p_m_calldata != param->mISDNsignal.calldata)
982 p_m_calldata = param->mISDNsignal.calldata;
983 PDEBUG(DEBUG_BCHANNEL, "we change to calldata=%d.\n", p_m_calldata);
989 case mISDNSIGNAL_NODATA:
990 p_m_nodata = param->mISDNsignal.nodata;
991 if (p_m_txmix == p_m_nodata) /* txmix != !nodata */
993 p_m_txmix = !p_m_nodata;
994 PDEBUG(DEBUG_BCHANNEL, "we change mix mode to txmix=%d (nodata=%d).\n", p_m_txmix, p_m_nodata);
996 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
997 ph_control(p_m_b_addr, p_m_txmix?CMX_MIX_ON:CMX_MIX_OFF, 0);
1003 case mISDNSIGNAL_RXOFF:
1004 if (p_m_rxoff != param->mISDNsignal.rxoff)
1006 p_m_rxoff = param->mISDNsignal.rxoff;
1007 PDEBUG(DEBUG_BCHANNEL, "we change receive mode to rxoff=%d.\n", p_m_rxoff);
1009 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
1010 ph_control(p_m_b_addr, p_m_rxoff?CMX_RECEIVE_OFF:CMX_RECEIVE_ON, 0);
1014 case mISDNSIGNAL_DTMF:
1015 if (p_m_dtmf != param->mISDNsignal.dtmf)
1017 p_m_dtmf = param->mISDNsignal.dtmf;
1018 PDEBUG(DEBUG_BCHANNEL, "we change dtmf mode to dtmf=%d.\n", p_m_dtmf);
1020 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
1021 ph_control(p_m_b_addr, p_m_dtmf?DTMF_TONE_START:DTMF_TONE_STOP, 0);
1027 PERROR("PmISDN(%s) unsupported signal message %d.\n", p_name, param->mISDNsignal.message);
1032 void PmISDN::message_crypt(unsigned long epoint_id, int message_id, union parameter *param)
1034 struct message *message;
1036 switch(param->crypt.type)
1038 case CC_ACTBF_REQ: /* activate blowfish */
1040 p_m_crypt_key_len = param->crypt.len;
1041 if (p_m_crypt_key_len > (int)sizeof(p_m_crypt_key))
1043 PERROR("PmISDN(%s) key too long %d > %d\n", p_name, p_m_crypt_key_len, sizeof(p_m_crypt_key));
1044 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CRYPT);
1045 message->param.crypt.type = CC_ERROR_IND;
1046 message_put(message);
1049 memcpy(p_m_crypt_key, param->crypt.data, p_m_crypt_key_len);
1051 PDEBUG(DEBUG_BCHANNEL, "we set encryption to crypt=%d. (0 means OFF)\n", p_m_crypt);
1053 if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
1054 ph_control_block(p_m_b_addr, p_m_crypt?BF_ENABLE_KEY:BF_DISABLE, p_m_crypt_key, p_m_crypt_key_len);
1057 case CC_DACT_REQ: /* deactivate session encryption */
1062 case CR_LISTEN_REQ: /* start listening to messages */
1063 p_m_crypt_listen = 1;
1064 p_m_crypt_listen_state = 0;
1067 case CR_UNLISTEN_REQ: /* stop listening to messages */
1068 p_m_crypt_listen = 0;
1071 case CR_MESSAGE_REQ: /* send message */
1072 p_m_crypt_msg_len = cryptman_encode_bch(param->crypt.data, param->crypt.len, p_m_crypt_msg, sizeof(p_m_crypt_msg));
1073 if (!p_m_crypt_msg_len)
1075 PERROR("PmISDN(%s) message too long %d > %d\n", p_name, param->crypt.len-1, sizeof(p_m_crypt_msg));
1078 p_m_crypt_msg_current = 0; /* reset */
1079 p_m_crypt_msg_loops = 3; /* enable */
1081 /* disable txmix, or we get corrupt data due to audio process */
1084 PDEBUG(DEBUG_BCHANNEL, "for sending CR_MESSAGE_REQ, we reset txmix from txmix=%d.\n", p_m_txmix);
1085 ph_control(p_m_b_addr, CMX_MIX_OFF, 0);
1091 PERROR("PmISDN(%s) unknown crypt message %d\n", p_name, param->crypt.type);
1097 * endpoint sends messages to the port
1099 int PmISDN::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
1101 if (Port::message_epoint(epoint_id, message_id, param))
1106 case MESSAGE_mISDNSIGNAL: /* user command */
1107 PDEBUG(DEBUG_ISDN, "PmISDN(%s) received special ISDN SIGNAL %d.\n", p_name, param->mISDNsignal.message);
1108 message_mISDNsignal(epoint_id, message_id, param);
1111 case MESSAGE_CRYPT: /* crypt control command */
1112 PDEBUG(DEBUG_ISDN, "PmISDN(%s) received encryption command '%d'.\n", p_name, param->crypt.type);
1113 message_crypt(epoint_id, message_id, param);
1122 * transmit function for data to mISDN b-channel
1124 void Port::transmit(unsigned char *buffer, int length)
1130 * main loop for processing messages from mISDN device
1132 int mISDN_handler(void)
1137 struct mISDNport *mISDNport;
1138 class PmISDN *isdnport;
1141 mISDNuser_head_t *hh;
1144 /* the que avoids loopbacks when replying to stack after receiving
1146 mISDNport = mISDNport_first;
1149 /* process turning on/off rx */
1151 while(i < mISDNport->b_num)
1153 isdnport=mISDNport->b_port[i];
1154 /* call bridges in user space OR crypto OR recording */
1155 if (isdnport->p_m_calldata || isdnport->p_m_crypt_msg_loops || isdnport->p_m_crypt_listen || isdnport->p_record)
1157 /* rx IS required */
1158 if (isdnport->p_m_rxoff)
1161 isdnport->p_m_rxoff = 0;
1162 PDEBUG(DEBUG_BCHANNEL, "%s: receive data is required, so we turn them on\n");
1163 if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
1164 ph_control(isdnport->p_m_b_addr, CMX_RECEIVE_ON, 0);
1169 /* rx NOT required */
1170 if (!isdnport->p_m_rxoff)
1173 isdnport->p_m_rxoff = 1;
1174 PDEBUG(DEBUG_BCHANNEL, "%s: receive data is not required, so we turn them off\n");
1175 if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
1176 ph_control(isdnport->p_m_b_addr, CMX_RECEIVE_OFF, 0);
1181 if (isdnport->p_record)
1183 /* txdata IS required */
1184 if (!isdnport->p_m_txdata)
1187 isdnport->p_m_txdata = 1;
1188 PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is required, so we turn them on\n");
1189 if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
1190 ph_control(isdnport->p_m_b_addr, CMX_TXDATA_ON, 0);
1195 /* txdata NOT required */
1196 if (isdnport->p_m_txdata)
1199 isdnport->p_m_txdata = 0;
1200 PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is not required, so we turn them off\n");
1201 if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
1202 ph_control(isdnport->p_m_b_addr, CMX_TXDATA_OFF, 0);
1208 if (mISDNport->l1timeout && now>mISDNport->l1timeout)
1210 PDEBUG(DEBUG_ISDN, "the L1 establish timer expired, we release all pending messages.\n", mISDNport->portnum);
1211 mISDNport->l1timeout = 0;
1214 if (mISDNport->l2establish)
1216 if (now-mISDNport->l2establish > 5)
1218 if (mISDNport->ntmode)
1220 PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link NT portnum=%d.\n", mISDNport->portnum);
1221 time(&mISDNport->l2establish);
1223 dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0);
1224 if (mISDNport->nst.manager_l3(&mISDNport->nst, dmsg))
1227 PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link TE portnum=%d.\n", mISDNport->portnum);
1228 time(&mISDNport->l2establish);
1231 act.prim = DL_ESTABLISH | REQUEST;
1232 act.addr = (mISDNport->upper_id & ~LAYER_ID_MASK) | 3 | FLG_MSG_DOWN;
1235 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
1240 if ((dmsg = msg_dequeue(&mISDNport->downqueue)))
1242 if (mISDNport->ntmode)
1244 hh = (mISDNuser_head_t *)dmsg->data;
1245 PDEBUG(DEBUG_ISDN, "sending queued NT l3-down-message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, dmsg->len);
1246 if (mISDNport->nst.manager_l3(&mISDNport->nst, dmsg))
1250 frm = (iframe_t *)dmsg->data;
1251 frm->addr = mISDNport->upper_id | FLG_MSG_DOWN;
1252 frm->len = (dmsg->len) - mISDN_HEADER_LEN;
1253 PDEBUG(DEBUG_ISDN, "sending queued TE l3-down-message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, dmsg->len);
1254 mISDN_write(mISDNdevice, dmsg->data, dmsg->len, TIMEOUT_1SEC);
1259 mISDNport = mISDNport->next;
1262 /* get message from kernel */
1263 if (!(msg = alloc_msg(MAX_MSG_SIZE)))
1265 ret = mISDN_read(mISDNdevice, msg->data, MAX_MSG_SIZE, 0);
1269 if (errno == EAGAIN)
1271 PERROR("FATAL ERROR: failed to do mISDN_read()\n");
1277 // printf("%s: ERROR: mISDN_read() returns nothing\n");
1281 frm = (iframe_t *)msg->data;
1286 case MGR_INITTIMER | CONFIRM:
1287 case MGR_ADDTIMER | CONFIRM:
1288 case MGR_DELTIMER | CONFIRM:
1289 case MGR_REMOVETIMER | CONFIRM:
1290 // if (options.deb & DEBUG_ISDN)
1291 // PDEBUG(DEBUG_ISDN, "timer-confirm\n");
1297 mISDNport = mISDNport_first;
1300 if ((frm->prim==(MGR_TIMER | INDICATION)) && mISDNport->ntmode)
1302 itimer_t *it = mISDNport->nst.tlist;
1307 if (it->id == (int)frm->addr)
1313 mISDN_write_frame(mISDNdevice, msg->data, mISDNport->upper_id | FLG_MSG_DOWN,
1314 MGR_TIMER | RESPONSE, 0, 0, NULL, TIMEOUT_1SEC);
1316 PDEBUG(DEBUG_ISDN, "timer-indication %s port %d it=%p\n", (mISDNport->ntmode)?"NT":"TE", mISDNport->portnum, it);
1317 test_and_clear_bit(FLG_TIMER_RUNING, (long unsigned int *)&it->Flags);
1318 ret = it->function(it->data);
1321 /* we will continue here because we have a timer for a different mISDNport */
1323 //printf("comparing frm->addr %x with upper_id %x\n", frm->addr, mISDNport->upper_id);
1324 if ((frm->addr&STACK_ID_MASK) == (unsigned int)(mISDNport->upper_id&STACK_ID_MASK))
1329 case MGR_SHORTSTATUS | INDICATION:
1330 case MGR_SHORTSTATUS | CONFIRM:
1331 switch(frm->dinfo) {
1332 case SSTATUS_L1_ACTIVATED:
1333 PDEBUG(DEBUG_ISDN, "Received SSTATUS_L1_ACTIVATED for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
1335 case SSTATUS_L1_DEACTIVATED:
1336 PDEBUG(DEBUG_ISDN, "Received SSTATUS_L1_DEACTIVATED for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
1338 case SSTATUS_L2_ESTABLISHED:
1339 PDEBUG(DEBUG_ISDN, "Received SSTATUS_L2_ESTABLISHED for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
1341 case SSTATUS_L2_RELEASED:
1342 PDEBUG(DEBUG_ISDN, "Received SSTATUS_L2_RELEASED for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
1347 case PH_ACTIVATE | CONFIRM:
1348 case PH_ACTIVATE | INDICATION:
1349 PDEBUG(DEBUG_ISDN, "Received PH_ACTIVATED for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
1350 if (mISDNport->ntmode)
1352 mISDNport->l1link = 1;
1353 setup_queue(mISDNport, 1);
1357 mISDNport->l1link = 1;
1358 setup_queue(mISDNport, 1);
1361 case PH_DEACTIVATE | CONFIRM:
1362 case PH_DEACTIVATE | INDICATION:
1363 PDEBUG(DEBUG_ISDN, "Received PH_DEACTIVATED for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
1364 if (mISDNport->ntmode)
1366 mISDNport->l1link = 0;
1367 setup_queue(mISDNport, 0);
1371 mISDNport->l1link = 0;
1372 setup_queue(mISDNport, 0);
1375 case PH_CONTROL | CONFIRM:
1376 case PH_CONTROL | INDICATION:
1377 PDEBUG(DEBUG_ISDN, "Received PH_CONTROL for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
1380 case DL_ESTABLISH | INDICATION:
1381 case DL_ESTABLISH | CONFIRM:
1382 // PDEBUG(DEBUG_ISDN, "addr 0x%x established data link (DL) TE portnum=%d (DL_ESTABLISH)\n", frm->addr, mISDNport->portnum);
1383 if (!mISDNport->ntmode) break; /* !!!!!!!!!!!!!!!! */
1385 // if (mISDNport->ntmode)
1387 if (mISDNport->l2establish)
1389 mISDNport->l2establish = 0;
1390 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
1392 mISDNport->l2link = 1;
1395 case DL_RELEASE | INDICATION:
1396 case DL_RELEASE | CONFIRM:
1397 // PDEBUG(DEBUG_ISDN, "addr 0x%x released data link (DL) TE portnum=%d (DL_RELEASE)\n", frm->addr, mISDNport->portnum);
1398 if (!mISDNport->ntmode) break; /* !!!!!!!!!!!!!!!! */
1400 // if (mISDNport->ntmode)
1402 mISDNport->l2link = 0;
1405 time(&mISDNport->l2establish);
1406 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
1412 PDEBUG(DEBUG_STACK, "GOT d-msg from %s port %d prim 0x%x dinfo 0x%x addr 0x%x\n", (mISDNport->ntmode)?"NT":"TE", mISDNport->portnum, frm->prim, frm->dinfo, frm->addr);
1413 if (frm->dinfo==(signed long)0xffffffff && frm->prim==(PH_DATA|CONFIRM))
1415 PERROR("SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n");
1418 if (mISDNport->ntmode)
1420 /* l1-data enters the nt-mode library */
1421 nst = &mISDNport->nst;
1422 if (nst->l1_l2(nst, msg))
1427 /* l3-data is sent to pbx */
1428 if (stack2manager_te(mISDNport, msg))
1435 //PDEBUG(DEBUG_ISDN, "flg:%d upper_id=%x addr=%x\n", (frm->addr&FLG_CHILD_STACK), (mISDNport->b_addr[0])&(~IF_CHILDMASK), (frm->addr)&(~IF_CHILDMASK));
1436 /* check if child, and if parent stack match */
1437 if ((frm->addr&FLG_CHILD_STACK) && (((unsigned int)(mISDNport->b_addr[0])&(~CHILD_ID_MASK)&STACK_ID_MASK) == ((frm->addr)&(~CHILD_ID_MASK)&STACK_ID_MASK)))
1442 /* we don't care about confirms, we use rx data to sync tx */
1443 case PH_DATA | CONFIRM:
1444 case DL_DATA | CONFIRM:
1447 /* we receive audio data, we respond to it AND we send tones */
1448 case PH_DATA | INDICATION:
1449 case DL_DATA | INDICATION:
1450 case PH_CONTROL | INDICATION:
1452 while(i < mISDNport->b_num)
1454 if ((unsigned int)(mISDNport->b_addr[i]&STACK_ID_MASK) == (frm->addr&STACK_ID_MASK))
1458 if (i == mISDNport->b_num)
1460 PERROR("unhandled b-message (address 0x%x).\n", frm->addr);
1463 if (mISDNport->b_port[i])
1465 //PERROR("port sech: %s data\n", mISDNport->b_port[i]->p_name);
1466 mISDNport->b_port[i]->bchannel_receive(frm);
1468 PDEBUG(DEBUG_BCHANNEL, "b-channel is not associated to an ISDNPort (address 0x%x), ignoring.\n", frm->addr);
1471 case PH_ACTIVATE | INDICATION:
1472 case DL_ESTABLISH | INDICATION:
1473 case PH_ACTIVATE | CONFIRM:
1474 case DL_ESTABLISH | CONFIRM:
1475 PDEBUG(DEBUG_BCHANNEL, "DL_ESTABLISH confirm: bchannel is now activated (address 0x%x).\n", frm->addr);
1477 while(i < mISDNport->b_num)
1479 if ((unsigned int)(mISDNport->b_addr[i]&STACK_ID_MASK) == (frm->addr&STACK_ID_MASK))
1483 if (i == mISDNport->b_num)
1485 PERROR("unhandled b-establish (address 0x%x).\n", frm->addr);
1488 mISDNport->b_state[i] = B_STATE_ACTIVE;
1489 if (!mISDNport->b_port[i])
1490 bchannel_deactivate(mISDNport, i);
1492 bchannel_activate(mISDNport, i);
1495 case PH_DEACTIVATE | INDICATION:
1496 case DL_RELEASE | INDICATION:
1497 case PH_DEACTIVATE | CONFIRM:
1498 case DL_RELEASE | CONFIRM:
1499 PDEBUG(DEBUG_BCHANNEL, "DL_RELEASE confirm: bchannel is now de-activated (address 0x%x).\n", frm->addr);
1501 while(i < mISDNport->b_num)
1503 if ((unsigned int)(mISDNport->b_addr[i]&STACK_ID_MASK) == (frm->addr&STACK_ID_MASK))
1507 if (i == mISDNport->b_num)
1509 PERROR("unhandled b-release (address 0x%x).\n", frm->addr);
1512 mISDNport->b_state[i] = B_STATE_IDLE;
1513 if (mISDNport->b_port[i])
1514 bchannel_activate(mISDNport, i);
1516 bchannel_deactivate(mISDNport, i);
1522 mISDNport = mISDNport->next;
1526 if (frm->prim == (MGR_TIMER | INDICATION))
1527 PERROR("unhandled timer indication message: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, msg->len);
1529 PERROR("unhandled message: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, msg->len);
1530 // PERROR("test: is_child: %x of stack %x == %x (baddr %x frm %x)\n", (frm->addr&FLG_CHILD_STACK), ((unsigned int)(mISDNport_first->b_addr[0])&(~CHILD_ID_MASK)&STACK_ID_MASK), ((frm->addr)&(~CHILD_ID_MASK)&STACK_ID_MASK), mISDNport_first->b_addr[0], frm->addr);
1539 * global function to add a new card (port)
1541 struct mISDNport *mISDN_port_open(int port, int ptp, int ptmp)
1544 unsigned char buff[1025];
1545 iframe_t *frm = (iframe_t *)buff;
1546 stack_info_t *stinf;
1547 struct mISDNport *mISDNport, **mISDNportp;
1550 // interface_info_t ii;
1558 /* open mISDNdevice if not already open */
1559 if (mISDNdevice < 0)
1564 PERROR("cannot open mISDN device ret=%d errno=%d (%s) Check for mISDN modules!\nAlso did you create \"/dev/mISDN\"? Do: \"mknod /dev/mISDN c 46 0\"\n", ret, errno, strerror(errno));
1568 PDEBUG(DEBUG_ISDN, "mISDN device opened.\n");
1570 /* create entity for layer 3 TE-mode */
1571 mISDN_write_frame(mISDNdevice, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
1572 ret = mISDN_read_frame(mISDNdevice, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC);
1573 if (ret < (int)mISDN_HEADER_LEN)
1576 fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN. Exitting due to software bug.");
1579 entity = frm->dinfo & 0xffff;
1582 PDEBUG(DEBUG_ISDN, "our entity for l3-processes is %d.\n", entity);
1585 /* query port's requirements */
1586 cnt = mISDN_get_stack_count(mISDNdevice);
1589 PERROR("Found no card. Please be sure to load card drivers.\n");
1592 if (port>cnt || port<1)
1594 PERROR("Port (%d) given at 'ports' (options.conf) is out of existing port range (%d-%d)\n", port, 1, cnt);
1597 ret = mISDN_get_stack_info(mISDNdevice, port, buff, sizeof(buff));
1600 PERROR("Cannot get stack info for port %d (ret=%d)\n", port, ret);
1603 stinf = (stack_info_t *)&frm->data.p;
1604 switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK)
1606 case ISDN_PID_L0_TE_S0:
1607 PDEBUG(DEBUG_ISDN, "TE-mode BRI S/T interface line\n");
1609 case ISDN_PID_L0_NT_S0:
1610 PDEBUG(DEBUG_ISDN, "NT-mode BRI S/T interface port\n");
1613 case ISDN_PID_L0_TE_E1:
1614 PDEBUG(DEBUG_ISDN, "TE-mode PRI E1 interface line\n");
1617 case ISDN_PID_L0_NT_E1:
1618 PDEBUG(DEBUG_ISDN, "LT-mode PRI E1 interface port\n");
1623 PERROR("unknown port(%d) type 0x%08x\n", port, stinf->pid.protocol[0]);
1629 if (stinf->pid.protocol[1] == 0)
1631 PERROR("Given port %d: Missing layer 1 NT-mode protocol.\n", port);
1634 if (stinf->pid.protocol[2])
1636 PERROR("Given port %d: Layer 2 protocol 0x%08x is detected, but not allowed for NT lib.\n", port, stinf->pid.protocol[2]);
1642 if (stinf->pid.protocol[1] == 0)
1644 PERROR("Given port %d: Missing layer 1 protocol.\n", port);
1647 if (stinf->pid.protocol[2] == 0)
1649 PERROR("Given port %d: Missing layer 2 protocol.\n", port);
1652 if (stinf->pid.protocol[3] == 0)
1654 PERROR("Given port %d: Missing layer 3 protocol.\n", port);
1658 switch(stinf->pid.protocol[3] & ~ISDN_PID_FEATURE_MASK)
1660 case ISDN_PID_L3_DSS1USER:
1664 PERROR("Given port %d: own protocol 0x%08x", port,stinf->pid.protocol[3]);
1668 if (stinf->pid.protocol[4])
1670 PERROR("Given port %d: Layer 4 protocol not allowed.\n", port);
1675 /* add mISDNport structure */
1676 mISDNportp = &mISDNport_first;
1678 mISDNportp = &mISDNport->next;
1679 mISDNport = (struct mISDNport *)calloc(1, sizeof(struct mISDNport));
1682 PERROR("Cannot alloc mISDNport structure\n");
1686 memset(mISDNport, 0, sizeof(mISDNport));
1687 *mISDNportp = mISDNport;
1689 /* allocate ressources of port */
1690 msg_queue_init(&mISDNport->downqueue);
1691 // SCPY(mISDNport->name, "noname");
1692 mISDNport->portnum = port;
1693 mISDNport->ntmode = nt;
1694 mISDNport->pri = pri;
1695 mISDNport->d_stid = stinf->id;
1696 PDEBUG(DEBUG_ISDN, "d_stid = 0x%x.\n", mISDNport->d_stid);
1697 mISDNport->b_num = stinf->childcnt;
1698 PDEBUG(DEBUG_ISDN, "Port has %d b-channels.\n", mISDNport->b_num);
1699 if ((stinf->pid.protocol[2]&ISDN_PID_L2_DF_PTP) || (nt&&ptp) || pri)
1701 PDEBUG(DEBUG_ISDN, "Port is point-to-point.\n");
1702 mISDNport->ptp = ptp = 1;
1705 PDEBUG(DEBUG_ISDN, "Port is forced to point-to-multipoint.\n");
1706 mISDNport->ptp = ptp = 0;
1710 while(i < stinf->childcnt)
1712 mISDNport->b_stid[i] = stinf->child[i];
1713 PDEBUG(DEBUG_ISDN, "b_stid[%d] = 0x%x.\n", i, mISDNport->b_stid[i]);
1716 memset(&li, 0, sizeof(li));
1717 UCPY(&li.name[0], (nt)?"net l2":"pbx l4");
1720 li.pid.protocol[nt?2:4] = (nt)?ISDN_PID_L2_LAPD_NET:ISDN_PID_L4_CAPI20;
1721 li.pid.layermask = ISDN_LAYER((nt?2:4));
1722 li.st = mISDNport->d_stid;
1723 ret = mISDN_new_layer(mISDNdevice, &li);
1726 PERROR("Cannot add layer %d of port %d (ret %d)\n", nt?2:4, port, ret);
1728 mISDNport_close(mISDNport);
1731 mISDNport->upper_id = li.id;
1732 ret = mISDN_register_layer(mISDNdevice, mISDNport->d_stid, mISDNport->upper_id);
1735 PERROR("Cannot register layer %d of port %d\n", nt?2:4, port);
1738 mISDNport->lower_id = mISDN_get_layerid(mISDNdevice, mISDNport->d_stid, nt?1:3); // id of lower layer (nt=1, te=3)
1739 if (mISDNport->lower_id < 0)
1741 PERROR("Cannot get layer(%d) id of port %d\n", nt?1:3, port);
1744 mISDNport->upper_id = mISDN_get_layerid(mISDNdevice, mISDNport->d_stid, nt?2:4); // id of uppermost layer (nt=2, te=4)
1745 if (mISDNport->upper_id < 0)
1747 PERROR("Cannot get layer(%d) id of port %d\n", nt?2:4, port);
1750 PDEBUG(DEBUG_ISDN, "Layer %d of port %d added.\n", nt?2:4, port);
1752 /* if ntmode, establish L1 to send the tei removal during start */
1753 if (mISDNport->ntmode)
1757 act.prim = PH_ACTIVATE | REQUEST;
1758 act.addr = mISDNport->upper_id | FLG_MSG_DOWN;
1759 printf("UPPER ID 0x%x, addr 0x%x\n",mISDNport->upper_id, act.addr);
1762 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
1763 usleep(10000); /* to be sure, that l1 is up */
1766 /* create nst (nt-mode only) */
1769 mgr = &mISDNport->mgr;
1770 nst = &mISDNport->nst;
1775 nst->l3_manager = stack2manager_nt; /* messages from nt-mode */
1776 nst->device = mISDNdevice;
1778 nst->d_stid = mISDNport->d_stid;
1780 nst->feature = FEATURE_NET_HOLD;
1782 nst->feature |= FEATURE_NET_PTP;
1784 nst->feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
1787 while(i < mISDNport->b_num)
1789 nst->b_stid[i] = mISDNport->b_stid[i];
1793 nst->l1_id = mISDNport->lower_id;
1794 nst->l2_id = mISDNport->upper_id;
1797 msg_queue_init(&nst->down_queue);
1803 /* if te-mode, query state link */
1804 if (!mISDNport->ntmode)
1808 PDEBUG(DEBUG_ISDN, "sending short status request for port %d.\n", port);
1809 act.prim = MGR_SHORTSTATUS | REQUEST;
1810 act.addr = mISDNport->upper_id | MSG_BROADCAST;
1811 act.dinfo = SSTATUS_BROADCAST_BIT | SSTATUS_ALL;
1813 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
1815 /* if ptp AND te-mode, pull up the link */
1816 if (mISDNport->ptp && !mISDNport->ntmode)
1820 act.prim = DL_ESTABLISH | REQUEST;
1821 act.addr = (mISDNport->upper_id & ~LAYER_ID_MASK) | 4 | FLG_MSG_DOWN;
1824 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
1826 /* if ptp AND nt-mode, pull up the link */
1827 if (mISDNport->ptp && mISDNport->ntmode)
1831 dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0);
1832 if (mISDNport->nst.manager_l3(&mISDNport->nst, dmsg))
1835 /* initially, we assume that the link is down, exept for nt-ptmp */
1836 mISDNport->l2link = (mISDNport->ntmode && !mISDNport->ptp)?1:0;
1838 PDEBUG(DEBUG_BCHANNEL, "using 'mISDN_dsp.o' module\n");
1840 /* add all bchannel layers */
1842 while(i < mISDNport->b_num)
1844 /* create new layer */
1845 PDEBUG(DEBUG_BCHANNEL, "creating bchannel %d (index %d).\n" , i+1+(i>=15), i);
1846 memset(&li, 0, sizeof(li));
1847 memset(&pid, 0, sizeof(pid));
1850 li.st = mISDNport->b_stid[i];
1851 UCPY(li.name, "B L4");
1852 li.pid.layermask = ISDN_LAYER((4));
1853 li.pid.protocol[4] = ISDN_PID_L4_B_USER;
1854 ret = mISDN_new_layer(mISDNdevice, &li);
1858 PERROR("mISDN_new_layer() failed to add bchannel %d (index %d)\n", i+1+(i>=15), i);
1861 mISDNport->b_addr[i] = li.id;
1864 goto failed_new_layer;
1866 PDEBUG(DEBUG_BCHANNEL, "new layer (b_addr=0x%x)\n", mISDNport->b_addr[i]);
1868 /* create new stack */
1869 pid.protocol[1] = ISDN_PID_L1_B_64TRANS;
1870 pid.protocol[2] = ISDN_PID_L2_B_TRANS;
1871 pid.protocol[3] = ISDN_PID_L3_B_DSP;
1872 pid.protocol[4] = ISDN_PID_L4_B_USER;
1873 pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) | ISDN_LAYER((4));
1874 ret = mISDN_set_stack(mISDNdevice, mISDNport->b_stid[i], &pid);
1878 PERROR("mISDN_set_stack() failed (ret=%d) to add bchannel (index %d) stid=0x%x\n", ret, i, mISDNport->b_stid[i]);
1879 mISDN_write_frame(mISDNdevice, buff, mISDNport->b_addr[i], MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
1880 mISDNport->b_addr[i] = 0;
1881 // mISDNport->b_addr_low[i] = 0;
1884 ret = mISDN_get_setstack_ind(mISDNdevice, mISDNport->b_addr[i]);
1889 mISDNport->b_addr[i] = mISDN_get_layerid(mISDNdevice, mISDNport->b_stid[i], 4);
1890 if (!mISDNport->b_addr[i])
1892 /* deactivate bchannel if already enabled due to crash */
1893 PDEBUG(DEBUG_BCHANNEL, "deactivating bchannel (index %d) as a precaution.\n", i);
1894 dact.prim = DL_RELEASE | REQUEST;
1895 dact.addr = mISDNport->b_addr[i] | FLG_MSG_DOWN;
1898 mISDN_write(mISDNdevice, &dact, mISDN_HEADER_LEN+dact.len, TIMEOUT_1SEC);
1902 PDEBUG(DEBUG_ISDN, "- port %d %s (%s) %d b-channels\n", mISDNport->portnum, (mISDNport->ntmode)?"NT-mode":"TE-mode", (mISDNport->ptp)?"Point-To-Point":"Multipoint", mISDNport->b_num);
1903 printlog("opening port %d %s (%s) %d b-channels\n", mISDNport->portnum, (mISDNport->ntmode)?"NT-mode":"TE-mode", (mISDNport->ptp)?"Point-To-Point":"Multipoint", mISDNport->b_num);
1909 * function to free ALL cards (ports)
1911 void mISDNport_close_all(void)
1913 /* free all ports */
1914 while(mISDNport_first)
1915 mISDNport_close(mISDNport_first);
1919 * free only one port
1921 void mISDNport_close(struct mISDNport *mISDNport)
1923 struct mISDNport **mISDNportp;
1925 classs PmISDN *pmISDN;
1927 unsigned char buf[32];
1930 /* remove all port instance that are linked to this mISDNport */
1934 if ((port->p_type&PORT_CLASS_MASK) == PORT_CLASS_mISDN)
1936 pmISDN = (class PmISDN)*port;
1937 if (pmISDN->p_m_mISDNport)
1939 PDEBUG(DEBUG_ISDN, "port %s uses mISDNport %d, destroying it.\n", pnISDN->p_name, mISDNport->portnum);
1946 printlog("closing port %d\n", mISDNport->portnum);
1948 /* free bchannels */
1950 while(i < mISDNport->b_num)
1952 bchannel_deactivate(mISDNport, i);
1953 PDEBUG(DEBUG_BCHANNEL, "freeing %s port %d bchannel (index %d).\n", (mISDNport->ntmode)?"NT":"TE", mISDNport->portnum, i);
1954 if (mISDNport->b_stid[i])
1956 mISDN_clear_stack(mISDNdevice, mISDNport->b_stid[i]);
1957 if (mISDNport->b_addr[i])
1958 mISDN_write_frame(mISDNdevice, buf, mISDNport->b_addr[i] | FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
1963 /* free ressources of port */
1964 msg_queue_purge(&mISDNport->downqueue);
1967 if (mISDNport->ntmode)
1969 nst = &mISDNport->nst;
1970 if (nst->manager) /* to see if initialized */
1972 PDEBUG(DEBUG_STACK, "the following messages are ok: one L3 process always exists (broadcast process) and some L2 instances (broadcast + current telephone's instances)\n");
1973 cleanup_Isdnl3(nst);
1974 cleanup_Isdnl2(nst);
1977 msg_queue_purge(&nst->down_queue);
1978 if (nst->phd_down_msg)
1979 free(nst->phd_down_msg);
1983 PDEBUG(DEBUG_BCHANNEL, "freeing d-stack.\n");
1984 if (mISDNport->d_stid)
1986 // mISDN_clear_stack(mISDNdevice, mISDNport->d_stid);
1987 if (mISDNport->lower_id)
1988 mISDN_write_frame(mISDNdevice, buf, mISDNport->lower_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
1991 /* remove from list */
1992 mISDNportp = &mISDNport_first;
1995 if (*mISDNportp == mISDNport)
1997 *mISDNportp = (*mISDNportp)->next;
2000 mISDNportp = &((*mISDNportp)->next);
2005 PERROR("software error, mISDNport not in list\n");
2009 memset(mISDNport, 0, sizeof(struct mISDNport));
2013 /* close mISDNdevice, if no port */
2014 if (mISDNdevice>=0 && mISDNport_first==NULL)
2017 mISDN_write_frame(mISDNdevice, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC);
2019 mISDN_close(mISDNdevice);
2021 PDEBUG(DEBUG_ISDN, "mISDN device closed.\n");
2027 * global function to show all available isdn ports
2029 void mISDN_port_info(void)
2033 int useable, nt, pri;
2034 unsigned char buff[1025];
2035 iframe_t *frm = (iframe_t *)buff;
2036 stack_info_t *stinf;
2040 if ((device = mISDN_open()) < 0)
2042 fprintf(stderr, "cannot open mISDN device ret=%d errno=%d (%s) Check for mISDN modules!\nAlso did you create \"/dev/mISDN\"? Do: \"mknod /dev/mISDN c 46 0\"\n", device, errno, strerror(errno));
2046 /* get number of stacks */
2048 ii = mISDN_get_stack_count(device);
2052 printf("Found no card. Please be sure to load card drivers.\n");
2055 /* loop the number of cards and get their info */
2058 err = mISDN_get_stack_info(device, i, buff, sizeof(buff));
2061 fprintf(stderr, "mISDN_get_stack_info() failed: port=%d err=%d\n", i, err);
2064 stinf = (stack_info_t *)&frm->data.p;
2069 /* output the port info */
2070 printf("Port %2d: ", i);
2071 switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK)
2073 case ISDN_PID_L0_TE_S0:
2074 printf("TE-mode BRI S/T interface line (for phone lines)");
2076 if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_S0_HFC & ISDN_PID_FEATURE_MASK)
2077 printf(" HFC multiport card");
2080 case ISDN_PID_L0_NT_S0:
2082 printf("NT-mode BRI S/T interface port (for phones)");
2084 if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_S0_HFC & ISDN_PID_FEATURE_MASK)
2085 printf(" HFC multiport card");
2088 case ISDN_PID_L0_TE_E1:
2090 printf("TE-mode PRI E1 interface line (for phone lines)");
2092 if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_E1_HFC & ISDN_PID_FEATURE_MASK)
2093 printf(" HFC-E1 card");
2096 case ISDN_PID_L0_NT_E1:
2099 printf("NT-mode PRI E1 interface port (for phones)");
2101 if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_E1_HFC & ISDN_PID_FEATURE_MASK)
2102 printf(" HFC-E1 card");
2107 printf("unknown type 0x%08x",stinf->pid.protocol[0]);
2113 if (stinf->pid.protocol[1] == 0)
2116 printf(" -> Missing layer 1 NT-mode protocol.\n");
2119 while(p <= MAX_LAYER_NR) {
2120 if (stinf->pid.protocol[p])
2123 printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for NT lib.\n", p, stinf->pid.protocol[p]);
2130 printf(" -> Interface is Point-To-Point (PRI).\n");
2132 printf(" -> Interface can be Poin-To-Point/Multipoint.\n");
2136 if (stinf->pid.protocol[1] == 0)
2139 printf(" -> Missing layer 1 protocol.\n");
2141 if (stinf->pid.protocol[2] == 0)
2144 printf(" -> Missing layer 2 protocol.\n");
2146 if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP)
2148 printf(" -> Interface is Poin-To-Point.\n");
2150 if (stinf->pid.protocol[3] == 0)
2153 printf(" -> Missing layer 3 protocol.\n");
2156 printf(" -> Protocol: ");
2157 switch(stinf->pid.protocol[3] & ~ISDN_PID_FEATURE_MASK)
2159 case ISDN_PID_L3_DSS1USER:
2160 printf("DSS1 (Euro ISDN)");
2165 printf("unknown protocol 0x%08x",stinf->pid.protocol[3]);
2170 while(p <= MAX_LAYER_NR) {
2171 if (stinf->pid.protocol[p])
2174 printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for TE lib.\n", p, stinf->pid.protocol[p]);
2179 printf(" - %d B-channels\n", stinf->childcnt);
2182 printf(" * Port NOT useable for PBX\n");
2184 printf("--------\n");
2191 if ((err = mISDN_close(device)))
2193 fprintf(stderr, "mISDN_close() failed: err=%d '%s'\n", err, strerror(err));