- mISDNport->upper_id = li.id;
- ret = mISDN_register_layer(mISDNdevice, mISDNport->d_stid, mISDNport->upper_id);
- if (ret)
- {
- PERROR("Cannot register layer %d of port %d\n", nt?2:4, port);
- goto closeport;
- }
- mISDNport->lower_id = mISDN_get_layerid(mISDNdevice, mISDNport->d_stid, nt?1:3); // id of lower layer (nt=1, te=3)
- if (mISDNport->lower_id < 0)
- {
- PERROR("Cannot get layer(%d) id of port %d\n", nt?1:3, port);
- goto closeport;
- }
- mISDNport->upper_id = mISDN_get_layerid(mISDNdevice, mISDNport->d_stid, nt?2:4); // id of uppermost layer (nt=2, te=4)
- if (mISDNport->upper_id < 0)
- {
- PERROR("Cannot get layer(%d) id of port %d\n", nt?2:4, port);
- goto closeport;
- }
- PDEBUG(DEBUG_ISDN, "Layer %d of port %d added.\n", nt?2:4, port);
-
- /* if ntmode, establish L1 to send the tei removal during start */
- if (mISDNport->ntmode)
- {
- iframe_t act;
- /* L1 */
- act.prim = PH_ACTIVATE | REQUEST;
- act.addr = mISDNport->upper_id | FLG_MSG_DOWN;
- printf("UPPER ID 0x%x, addr 0x%x\n",mISDNport->upper_id, act.addr);
- act.dinfo = 0;
- act.len = 0;
- mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
- usleep(10000); /* to be sure, that l1 is up */
- }
-
- /* create nst (nt-mode only) */
- if (nt)
- {
- mgr = &mISDNport->mgr;
- nst = &mISDNport->nst;
-
- mgr->nst = nst;
- nst->manager = mgr;
-
- nst->l3_manager = stack2manager_nt; /* messages from nt-mode */
- nst->device = mISDNdevice;
- nst->cardnr = port;
- nst->d_stid = mISDNport->d_stid;
-
- nst->feature = FEATURE_NET_HOLD;
- if (ptp)
- nst->feature |= FEATURE_NET_PTP;
- if (pri)
- nst->feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID;
-#if 0
- i = 0;
- while(i < mISDNport->b_num)
- {
- nst->b_stid[i] = mISDNport->b_stid[i];
- i++;
- }
-#endif
- nst->l1_id = mISDNport->lower_id;
- nst->l2_id = mISDNport->upper_id;
-
- /* phd */
- msg_queue_init(&nst->down_queue);
-
- Isdnl2Init(nst);
- Isdnl3Init(nst);
- }
-
- /* if te-mode, query state link */
- if (!mISDNport->ntmode)
- {
- iframe_t act;
- /* L2 */
- PDEBUG(DEBUG_ISDN, "sending short status request for port %d.\n", port);
- act.prim = MGR_SHORTSTATUS | REQUEST;
- act.addr = mISDNport->upper_id | MSG_BROADCAST;
- act.dinfo = SSTATUS_BROADCAST_BIT | SSTATUS_ALL;
- act.len = 0;
- mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
- }
- /* if ptp AND te-mode, pull up the link */
- if (mISDNport->ptp && !mISDNport->ntmode)
- {
- iframe_t act;
- /* L2 */
- act.prim = DL_ESTABLISH | REQUEST;
- act.addr = (mISDNport->upper_id & ~LAYER_ID_MASK) | 4 | FLG_MSG_DOWN;
- act.dinfo = 0;
- act.len = 0;
- mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
- }
- /* if ptp AND nt-mode, pull up the link */
- if (mISDNport->ptp && mISDNport->ntmode)
- {
- msg_t *dmsg;
- /* L2 */
- dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0);
- if (mISDNport->nst.manager_l3(&mISDNport->nst, dmsg))
- free_msg(dmsg);
- }
- /* initially, we assume that the link is down, exept for nt-ptmp */
- mISDNport->l2link = (mISDNport->ntmode && !mISDNport->ptp)?1:0;