- 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;
- }
-
- /* find the mISDNport that belongs to the stack */
- mISDNport = mISDNport_first;
- while(mISDNport)
- {
- if ((frm->addr&MASTER_ID_MASK) == (unsigned int)(mISDNport->upper_id&MASTER_ID_MASK))
- break;
- mISDNport = mISDNport->next;
- }
- if (!mISDNport)
- {
- PERROR("message belongs to no mISDNport: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, msg->len);
- goto out;
- }
-
- /* master stack */
- if (!(frm->addr&FLG_CHILD_STACK))
- {
- /* d-message */
- switch(frm->prim)
- {
- case MGR_SHORTSTATUS | INDICATION:
- case MGR_SHORTSTATUS | CONFIRM:
- switch(frm->dinfo) {
- case SSTATUS_L1_ACTIVATED:
- l1l2l3_trace_header(mISDNport, NULL, PH_ACTIVATE | (frm->prim & 0x3), DIRECTION_IN);
- end_trace();
- goto ss_act;
- case SSTATUS_L1_DEACTIVATED:
- l1l2l3_trace_header(mISDNport, NULL, PH_DEACTIVATE | (frm->prim & 0x3), DIRECTION_IN);
- end_trace();
- goto ss_deact;
- case SSTATUS_L2_ESTABLISHED:
- l1l2l3_trace_header(mISDNport, NULL, DL_ESTABLISH | (frm->prim & 0x3), DIRECTION_IN);
- end_trace();
- goto ss_estab;
- case SSTATUS_L2_RELEASED:
- l1l2l3_trace_header(mISDNport, NULL, DL_RELEASE | (frm->prim & 0x3), DIRECTION_IN);
- end_trace();
- goto ss_rel;
- }
- break;
-
- case PH_ACTIVATE | CONFIRM:
- case PH_ACTIVATE | INDICATION:
- l1l2l3_trace_header(mISDNport, NULL, frm->prim, DIRECTION_IN);
- end_trace();
- if (mISDNport->ntmode)
- {
- mISDNport->l1link = 1;
- setup_queue(mISDNport, 1);
- goto l1_msg;
- }
- ss_act:
- mISDNport->l1link = 1;
- setup_queue(mISDNport, 1);
- break;
-
- case PH_DEACTIVATE | CONFIRM:
- case PH_DEACTIVATE | INDICATION:
- l1l2l3_trace_header(mISDNport, NULL, frm->prim, DIRECTION_IN);
- end_trace();
- if (mISDNport->ntmode)
- {
- mISDNport->l1link = 0;
- setup_queue(mISDNport, 0);
- goto l1_msg;
- }
- ss_deact:
- mISDNport->l1link = 0;
- setup_queue(mISDNport, 0);
- break;
-
- case PH_CONTROL | CONFIRM:
- case PH_CONTROL | INDICATION:
- PDEBUG(DEBUG_ISDN, "Received PH_CONTROL for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
- break;
-
- case DL_ESTABLISH | INDICATION:
- case DL_ESTABLISH | CONFIRM:
- l1l2l3_trace_header(mISDNport, NULL, frm->prim, DIRECTION_IN);
- end_trace();
- if (!mISDNport->ntmode) break; /* !!!!!!!!!!!!!!!! */
- ss_estab:
- if (mISDNport->l2establish)
- {
- mISDNport->l2establish = 0;
- PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
- }
- mISDNport->l2link = 1;
- break;
-
- case DL_RELEASE | INDICATION:
- case DL_RELEASE | CONFIRM:
- l1l2l3_trace_header(mISDNport, NULL, frm->prim, DIRECTION_IN);
- end_trace();
- if (!mISDNport->ntmode) break; /* !!!!!!!!!!!!!!!! */
- ss_rel:
- mISDNport->l2link = 0;
- if (mISDNport->ptp)
- {
- time(&mISDNport->l2establish);
- PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
- }
- break;
-
- default:
- l1_msg:
- 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);
- if (frm->dinfo==(signed long)0xffffffff && frm->prim==(PH_DATA|CONFIRM))
- {
- PERROR("SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n");
- }
- /* d-message */
- if (mISDNport->ntmode)
- {
- /* l1-data enters the nt-mode library */
- nst = &mISDNport->nst;
- if (nst->l1_l2(nst, msg))
- free_msg(msg);
- return(1);
- } else
- {
- /* l3-data is sent to pbx */
- if (stack2manager_te(mISDNport, msg))
- free_msg(msg);
- return(1);
- }
- }
- } else
- /* child stack */
- {
- /* b-message */
- switch(frm->prim)
- {
- /* we don't care about confirms, we use rx data to sync tx */
- case PH_DATA | CONFIRM:
- case DL_DATA | CONFIRM:
- break;
-
- /* we receive audio data, we respond to it AND we send tones */
- case PH_DATA | INDICATION:
- case DL_DATA | INDICATION:
- case PH_CONTROL | INDICATION:
- case PH_SIGNAL | INDICATION:
- i = 0;
- while(i < mISDNport->b_num)
- {
- if ((unsigned int)(mISDNport->b_addr[i]&STACK_ID_MASK) == (frm->addr&STACK_ID_MASK))
- break;
- i++;
- }
- if (i == mISDNport->b_num)
- {
- PERROR("unhandled b-message (prim 0x%x address 0x%x).\n", frm->prim, frm->addr);
- break;
- }
- if (mISDNport->b_port[i])
- {
-//PERROR("port sech: %s data\n", mISDNport->b_port[i]->p_name);
- mISDNport->b_port[i]->bchannel_receive(frm);
- } else
- PDEBUG(DEBUG_BCHANNEL, "b-channel is not associated to an ISDNPort (address 0x%x), ignoring.\n", frm->addr);
- break;
-
- case PH_ACTIVATE | INDICATION:
- case DL_ESTABLISH | INDICATION:
- case PH_ACTIVATE | CONFIRM:
- case DL_ESTABLISH | CONFIRM:
- PDEBUG(DEBUG_BCHANNEL, "DL_ESTABLISH confirm: bchannel is now activated (address 0x%x).\n", frm->addr);
- i = 0;
- while(i < mISDNport->b_num)
- {
- if ((unsigned int)(mISDNport->b_addr[i]&STACK_ID_MASK) == (frm->addr&STACK_ID_MASK))
- break;
- i++;
- }
- if (i == mISDNport->b_num)
- {
- PERROR("unhandled b-establish (prim 0x%x address 0x%x).\n", frm->prim, frm->addr);
- break;
- }
- bchannel_event(mISDNport, i, B_EVENT_ACTIVATED);
- break;