-#else
-int mISDN_handler(void)
-{
- int ret;
- struct mISDNport *mISDNport;
- class PmISDN *isdnport;
- int i;
- msg_t *msg;
- iframe_t *frm;
- msg_t *dmsg;
- mISDNuser_head_t *hh;
- net_stack_t *nst;
-
- /* the que avoids loopbacks when replying to stack after receiving
- * from stack. */
- mISDNport = mISDNport_first;
- while(mISDNport)
- {
- /* process turning on/off rx */
- i = 0;
- while(i < mISDNport->b_num)
- {
- /* process timer events for bchannel handling */
- if (mISDNport->b_timer[i])
- {
- if (mISDNport->b_timer[i] <= now_d)
- bchannel_event(mISDNport, i, B_EVENT_TIMEOUT);
- }
- isdnport=mISDNport->b_port[i];
- if (isdnport)
- {
- /* call bridges in user space OR crypto OR recording */
- if (isdnport->p_m_joindata || isdnport->p_m_crypt_msg_loops || isdnport->p_m_crypt_listen || isdnport->p_record)
- {
- /* rx IS required */
- if (isdnport->p_m_rxoff)
- {
- /* turn on RX */
- isdnport->p_m_rxoff = 0;
- PDEBUG(DEBUG_BCHANNEL, "%s: receive data is required, so we turn them on\n", __FUNCTION__);
- if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
- ph_control(mISDNport, isdnport, mISDNport->b_addr[isdnport->p_m_b_index], CMX_RECEIVE_ON, 0, "DSP-RXOFF", 0);
- return(1);
- }
- } else
- {
- /* rx NOT required */
- if (!isdnport->p_m_rxoff)
- {
- /* turn off RX */
- isdnport->p_m_rxoff = 1;
- PDEBUG(DEBUG_BCHANNEL, "%s: receive data is not required, so we turn them off\n", __FUNCTION__);
- if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
- ph_control(mISDNport, isdnport, mISDNport->b_addr[isdnport->p_m_b_index], CMX_RECEIVE_OFF, 0, "DSP-RXOFF", 1);
- return(1);
- }
- }
- /* recording */
- if (isdnport->p_record)
- {
- /* txdata IS required */
- if (!isdnport->p_m_txdata)
- {
- /* turn on RX */
- isdnport->p_m_txdata = 1;
- PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is required, so we turn them on\n", __FUNCTION__);
-#ifndef OLD_MISDN
- if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
- ph_control(mISDNport, isdnport, mISDNport->b_addr[isdnport->p_m_b_index], CMX_TXDATA_ON, 0, "DSP-TXDATA", 1);
-#endif
- return(1);
- }
- } else
- {
- /* txdata NOT required */
- if (isdnport->p_m_txdata)
- {
- /* turn off RX */
- isdnport->p_m_txdata = 0;
- PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is not required, so we turn them off\n", __FUNCTION__);
-#ifndef OLD_MISDN
- if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
- ph_control(mISDNport, isdnport, mISDNport->b_addr[isdnport->p_m_b_index], CMX_TXDATA_OFF, 0, "DSP-TXDATA", 0);
-#endif
- return(1);
- }
- }
- }
- i++;
- }
-#if 0
- if (mISDNport->l1timeout && now>mISDNport->l1timeout)
- { ---}
- PDEBUG(DEBUG_ISDN, "the L1 establish timer expired, we release all pending messages.\n", mISDNport->portnum);
- mISDNport->l1timeout = 0;
-#endif
-
- if (mISDNport->l2establish)
- {
- if (now-mISDNport->l2establish > 5)
- {
- mISDNport->l2establish = 0;
- if (mISDNport->l2hold && (mISDNport->ptp || !mISDNport->ntmode))
- {
- if (mISDNport->ntmode)
- {
- PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link NT portnum=%d.\n", mISDNport->portnum);
- time(&mISDNport->l2establish);
- /* establish */
- dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0);
- if (mISDNport->nst.manager_l3(&mISDNport->nst, dmsg))
- free_msg(dmsg);
- } else {
- iframe_t act;
-
- PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link TE portnum=%d.\n", mISDNport->portnum);
- time(&mISDNport->l2establish);
- /* establish */
- act.prim = DL_ESTABLISH | REQUEST;
- act.addr = (mISDNport->upper_id & ~LAYER_ID_MASK) | 3 | FLG_MSG_DOWN;
- act.dinfo = 0;
- act.len = 0;
- mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
- }
- l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_REQ, DIRECTION_OUT);
- add_trace("tei", NULL, "%d", 0);
- end_trace();
- time(&mISDNport->l2establish);
- return(1);
- }
- }
- }
- if ((dmsg = msg_dequeue(&mISDNport->downqueue)))
- {
- if (mISDNport->ntmode)
- {
- hh = (mISDNuser_head_t *)dmsg->data;
- 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);
- if (mISDNport->nst.manager_l3(&mISDNport->nst, dmsg))
- free_msg(dmsg);
- } else
- {
- frm = (iframe_t *)dmsg->data;
- frm->addr = mISDNport->upper_id | FLG_MSG_DOWN;
- frm->len = (dmsg->len) - mISDN_HEADER_LEN;
- 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);
- mISDN_write(mISDNdevice, dmsg->data, dmsg->len, TIMEOUT_1SEC);
- free_msg(dmsg);
- }
- return(1);
- }
- mISDNport = mISDNport->next;
- }
-
- /* no device, no read */
- if (mISDNdevice < 0)
- return(0);
-
- /* get message from kernel */
- if (!(msg = alloc_msg(MAX_MSG_SIZE)))
- return(1);
- ret = mISDN_read(mISDNdevice, msg->data, MAX_MSG_SIZE, 0);
- if (ret < 0)
- {
- free_msg(msg);
- if (errno == EAGAIN)
- return(0);
- FATAL("Failed to do mISDN_read()\n");
- }
- if (!ret)
- {
- free_msg(msg);
-// printf("%s: ERROR: mISDN_read() returns nothing\n");
- return(0);
- }
- msg->len = ret;
- frm = (iframe_t *)msg->data;
-
- /* global prim */
- switch(frm->prim)
- {
- case MGR_DELLAYER | CONFIRM:
- case MGR_INITTIMER | CONFIRM:
- case MGR_ADDTIMER | CONFIRM:
- case MGR_DELTIMER | CONFIRM:
- case MGR_REMOVETIMER | CONFIRM:
- free_msg(msg);
- return(1);
- }
-
- /* handle timer events from mISDN for NT-stack
- * note: they do not associate with a stack */
- if (frm->prim == (MGR_TIMER | INDICATION))
- {
- itimer_t *it;
-
- /* find mISDNport */
- mISDNport = mISDNport_first;
- while(mISDNport)
- {
- /* nt mode only */
- if (mISDNport->ntmode)
- {
- it = mISDNport->nst.tlist;
- /* find timer */
- while(it)
- {
- if (it->id == (int)frm->addr)
- break;
- it = it->next;
- }
- if (it)
- break;
- }
- mISDNport = mISDNport->next;
- }
- if (mISDNport)
- {
- mISDN_write_frame(mISDNdevice, msg->data, mISDNport->upper_id | FLG_MSG_DOWN,
- MGR_TIMER | RESPONSE, 0, 0, NULL, TIMEOUT_1SEC);
-
- PDEBUG(DEBUG_ISDN, "timer-indication port %d it=%p\n", mISDNport->portnum, it);
- test_and_clear_bit(FLG_TIMER_RUNING, (long unsigned int *)&it->Flags);
- ret = it->function(it->data);
- } else
- {
- PDEBUG(DEBUG_ISDN, "timer-indication not handled\n");
- }
- goto out;
- }