Lines Matching +full:ctrl +full:- +full:ids

1 // SPDX-License-Identifier: GPL-2.0-only
72 struct manager *mgr = fi->userdata; in da_debug()
84 printk(KERN_DEBUG "mgr(%d): %pV\n", mgr->ch.st->dev->id, &vaf); in da_debug()
92 struct manager *mgr = fi->userdata; in da_activate()
94 if (fi->state == ST_L1_DEACT_PENDING) in da_activate()
95 mISDN_FsmDelTimer(&mgr->datimer, 1); in da_activate()
108 struct manager *mgr = fi->userdata; in da_deactivate()
112 read_lock_irqsave(&mgr->lock, flags); in da_deactivate()
113 list_for_each_entry(l2, &mgr->layer2, list) { in da_deactivate()
114 if (l2->l2m.state > ST_L2_4) { in da_deactivate()
116 read_unlock_irqrestore(&mgr->lock, flags); in da_deactivate()
120 read_unlock_irqrestore(&mgr->lock, flags); in da_deactivate()
122 if (!test_bit(OPTION_L1_HOLD, &mgr->options)) { in da_deactivate()
123 mISDN_FsmAddTimer(&mgr->datimer, DATIMER_VAL, EV_DATIMER, in da_deactivate()
132 struct manager *mgr = fi->userdata; in da_ui()
135 if (!test_bit(OPTION_L1_HOLD, &mgr->options)) { in da_ui()
136 mISDN_FsmDelTimer(&mgr->datimer, 2); in da_ui()
137 mISDN_FsmAddTimer(&mgr->datimer, DATIMER_VAL, EV_DATIMER, in da_ui()
145 struct manager *mgr = fi->userdata; in da_timer()
150 read_lock_irqsave(&mgr->lock, flags); in da_timer()
151 list_for_each_entry(l2, &mgr->layer2, list) { in da_timer()
152 if (l2->l2m.state > ST_L2_4) { in da_timer()
154 read_unlock_irqrestore(&mgr->lock, flags); in da_timer()
159 read_unlock_irqrestore(&mgr->lock, flags); in da_timer()
162 _queue_data(&mgr->ch, PH_DEACTIVATE_REQ, MISDN_ID_ANY, 0, NULL, in da_timer()
221 struct teimgr *tm = fi->userdata; in tei_debug()
234 tm->l2->sapi, tm->l2->tei, &vaf); in tei_debug()
244 DECLARE_BITMAP(ids, 64) = { [0 ... BITS_TO_LONGS(64) - 1] = 0 }; in get_free_id()
248 list_for_each_entry(l2, &mgr->layer2, list) { in get_free_id()
249 if (l2->ch.nr > 63) { in get_free_id()
253 return -EBUSY; in get_free_id()
255 __set_bit(l2->ch.nr, ids); in get_free_id()
257 i = find_next_zero_bit(ids, 64, 1); in get_free_id()
262 return -EBUSY; in get_free_id()
268 DECLARE_BITMAP(ids, 64) = { [0 ... BITS_TO_LONGS(64) - 1] = 0 }; in get_free_tei()
272 list_for_each_entry(l2, &mgr->layer2, list) { in get_free_tei()
273 if (l2->ch.nr == 0) in get_free_tei()
275 if ((l2->ch.addr & 0xff) != 0) in get_free_tei()
277 i = l2->ch.addr >> 8; in get_free_tei()
280 i -= 64; in get_free_tei()
282 __set_bit(i, ids); in get_free_tei()
284 i = find_first_zero_bit(ids, 64); in get_free_tei()
289 return -1; in get_free_tei()
303 hh->prim = prim; in teiup_create()
304 hh->id = (mgr->ch.nr << 16) | mgr->ch.addr; in teiup_create()
307 err = mgr->up->send(mgr->up, skb); in teiup_create()
319 id = mgr->nextid++; in new_id()
321 mgr->nextid = 1; in new_id()
331 if (!test_bit(MGR_PH_ACTIVE, &mgr->options)) in do_send()
334 if (!test_and_set_bit(MGR_PH_NOTREADY, &mgr->options)) { in do_send()
335 struct sk_buff *skb = skb_dequeue(&mgr->sendq); in do_send()
338 test_and_clear_bit(MGR_PH_NOTREADY, &mgr->options); in do_send()
341 mgr->lastid = mISDN_HEAD_ID(skb); in do_send()
342 mISDN_FsmEvent(&mgr->deact, EV_UI, NULL); in do_send()
343 if (mgr->ch.recv(mgr->ch.peer, skb)) { in do_send()
345 test_and_clear_bit(MGR_PH_NOTREADY, &mgr->options); in do_send()
346 mgr->lastid = MISDN_ID_NONE; in do_send()
354 if (test_bit(MGR_PH_NOTREADY, &mgr->options)) { in do_ack()
355 if (id == mgr->lastid) { in do_ack()
356 if (test_bit(MGR_PH_ACTIVE, &mgr->options)) { in do_ack()
359 skb = skb_dequeue(&mgr->sendq); in do_ack()
361 mgr->lastid = mISDN_HEAD_ID(skb); in do_ack()
362 if (!mgr->ch.recv(mgr->ch.peer, skb)) in do_ack()
367 mgr->lastid = MISDN_ID_NONE; in do_ack()
368 test_and_clear_bit(MGR_PH_NOTREADY, &mgr->options); in do_ack()
376 skb_queue_tail(&mgr->sendq, skb); in mgr_send_down()
377 if (!test_bit(MGR_PH_ACTIVE, &mgr->options)) { in mgr_send_down()
378 _queue_data(&mgr->ch, PH_ACTIVATE_REQ, MISDN_ID_ANY, 0, in mgr_send_down()
388 if (!test_bit(MGR_OPT_NETWORK, &mgr->options)) /* only net send UI */ in dl_unit_data()
389 return -EINVAL; in dl_unit_data()
390 if (!test_bit(MGR_PH_ACTIVE, &mgr->options)) in dl_unit_data()
391 _queue_data(&mgr->ch, PH_ACTIVATE_REQ, MISDN_ID_ANY, 0, in dl_unit_data()
394 skb->data[0] = 0x02; /* SAPI 0 C/R = 1 */ in dl_unit_data()
395 skb->data[1] = 0xff; /* TEI 127 */ in dl_unit_data()
396 skb->data[2] = UI; /* UI frame */ in dl_unit_data()
399 skb_queue_tail(&mgr->sendq, skb); in dl_unit_data()
419 read_lock_irqsave(&mgr->lock, flags); in findtei()
420 list_for_each_entry(l2, &mgr->layer2, list) { in findtei()
421 if ((l2->sapi == 0) && (l2->tei > 0) && in findtei()
422 (l2->tei != GROUP_TEI) && (l2->tei == tei)) in findtei()
427 read_unlock_irqrestore(&mgr->lock, flags); in findtei()
438 if (test_bit(MGR_OPT_NETWORK, &mgr->options)) in put_tei_msg()
458 struct teimgr *tm = fi->userdata; in tei_id_request()
460 if (tm->l2->tei != GROUP_TEI) { in tei_id_request()
461 tm->tei_m.printdebug(&tm->tei_m, in tei_id_request()
463 tm->l2->tei); in tei_id_request()
466 tm->ri = random_ri(); in tei_id_request()
468 tm->tei_m.printdebug(&tm->tei_m, in tei_id_request()
469 "assign request ri %d", tm->ri); in tei_id_request()
470 put_tei_msg(tm->mgr, ID_REQUEST, tm->ri, GROUP_TEI); in tei_id_request()
472 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 1); in tei_id_request()
473 tm->nval = 3; in tei_id_request()
479 struct teimgr *tm = fi->userdata; in tei_id_assign()
489 tm->tei_m.printdebug(fi, "identity assign ri %d tei %d", in tei_id_assign()
491 l2 = findtei(tm->mgr, tei); in tei_id_assign()
493 if (ri != l2->tm->ri) { in tei_id_assign()
494 tm->tei_m.printdebug(fi, in tei_id_assign()
498 } else if (ri == tm->ri) { in tei_id_assign()
499 mISDN_FsmDelTimer(&tm->timer, 1); in tei_id_assign()
501 tei_l2(tm->l2, MDL_ASSIGN_REQ, tei); in tei_id_assign()
508 struct teimgr *tm = fi->userdata; in tei_id_test_dup()
518 tm->tei_m.printdebug(fi, "foreign identity assign ri %d tei %d", in tei_id_test_dup()
520 l2 = findtei(tm->mgr, tei); in tei_id_test_dup()
522 if (ri != l2->tm->ri) { /* and it wasn't our request */ in tei_id_test_dup()
523 tm->tei_m.printdebug(fi, in tei_id_test_dup()
525 mISDN_FsmEvent(&l2->tm->tei_m, EV_VERIFY, NULL); in tei_id_test_dup()
533 struct teimgr *tm = fi->userdata; in tei_id_denied()
542 tm->tei_m.printdebug(fi, "identity denied ri %d tei %d", in tei_id_denied()
549 struct teimgr *tm = fi->userdata; in tei_id_chk_req()
555 tm->tei_m.printdebug(fi, "identity check req tei %d", tei); in tei_id_chk_req()
556 if ((tm->l2->tei != GROUP_TEI) && ((tei == GROUP_TEI) || in tei_id_chk_req()
557 (tei == tm->l2->tei))) { in tei_id_chk_req()
558 mISDN_FsmDelTimer(&tm->timer, 4); in tei_id_chk_req()
559 mISDN_FsmChangeState(&tm->tei_m, ST_TEI_NOP); in tei_id_chk_req()
560 put_tei_msg(tm->mgr, ID_CHK_RES, random_ri(), tm->l2->tei); in tei_id_chk_req()
567 struct teimgr *tm = fi->userdata; in tei_id_remove()
573 tm->tei_m.printdebug(fi, "identity remove tei %d", tei); in tei_id_remove()
574 if ((tm->l2->tei != GROUP_TEI) && in tei_id_remove()
575 ((tei == GROUP_TEI) || (tei == tm->l2->tei))) { in tei_id_remove()
576 mISDN_FsmDelTimer(&tm->timer, 5); in tei_id_remove()
577 mISDN_FsmChangeState(&tm->tei_m, ST_TEI_NOP); in tei_id_remove()
578 tei_l2(tm->l2, MDL_REMOVE_REQ, 0); in tei_id_remove()
585 struct teimgr *tm = fi->userdata; in tei_id_verify()
588 tm->tei_m.printdebug(fi, "id verify request for tei %d", in tei_id_verify()
589 tm->l2->tei); in tei_id_verify()
590 put_tei_msg(tm->mgr, ID_VERIFY, 0, tm->l2->tei); in tei_id_verify()
591 mISDN_FsmChangeState(&tm->tei_m, ST_TEI_IDVERIFY); in tei_id_verify()
592 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 2); in tei_id_verify()
593 tm->nval = 2; in tei_id_verify()
599 struct teimgr *tm = fi->userdata; in tei_id_req_tout()
601 if (--tm->nval) { in tei_id_req_tout()
602 tm->ri = random_ri(); in tei_id_req_tout()
604 tm->tei_m.printdebug(fi, "assign req(%d) ri %d", in tei_id_req_tout()
605 4 - tm->nval, tm->ri); in tei_id_req_tout()
606 put_tei_msg(tm->mgr, ID_REQUEST, tm->ri, GROUP_TEI); in tei_id_req_tout()
607 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 3); in tei_id_req_tout()
609 tm->tei_m.printdebug(fi, "assign req failed"); in tei_id_req_tout()
610 tei_l2(tm->l2, MDL_ERROR_RSP, 0); in tei_id_req_tout()
618 struct teimgr *tm = fi->userdata; in tei_id_ver_tout()
620 if (--tm->nval) { in tei_id_ver_tout()
622 tm->tei_m.printdebug(fi, in tei_id_ver_tout()
624 3 - tm->nval, tm->l2->tei); in tei_id_ver_tout()
625 put_tei_msg(tm->mgr, ID_VERIFY, 0, tm->l2->tei); in tei_id_ver_tout()
626 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 4); in tei_id_ver_tout()
628 tm->tei_m.printdebug(fi, "verify req for tei %d failed", in tei_id_ver_tout()
629 tm->l2->tei); in tei_id_ver_tout()
630 tei_l2(tm->l2, MDL_REMOVE_REQ, 0); in tei_id_ver_tout()
653 put_tei_msg(l2->tm->mgr, ID_REMOVE, 0, l2->tei); in tei_l2remove()
655 list_del(&l2->ch.list); in tei_l2remove()
656 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL); in tei_l2remove()
662 struct teimgr *tm = fi->userdata; in tei_assign_req()
665 if (tm->l2->tei == GROUP_TEI) { in tei_assign_req()
666 tm->tei_m.printdebug(&tm->tei_m, in tei_assign_req()
670 tm->ri = ((unsigned int) *dp++ << 8); in tei_assign_req()
671 tm->ri += *dp++; in tei_assign_req()
673 tm->tei_m.printdebug(&tm->tei_m, in tei_assign_req()
674 "net assign request ri %d teim %d", tm->ri, *dp); in tei_assign_req()
675 put_tei_msg(tm->mgr, ID_ASSIGNED, tm->ri, tm->l2->tei); in tei_assign_req()
682 struct teimgr *tm = fi->userdata; in tei_id_chk_req_net()
685 tm->tei_m.printdebug(fi, "id check request for tei %d", in tei_id_chk_req_net()
686 tm->l2->tei); in tei_id_chk_req_net()
687 tm->rcnt = 0; in tei_id_chk_req_net()
688 put_tei_msg(tm->mgr, ID_CHK_REQ, 0, tm->l2->tei); in tei_id_chk_req_net()
689 mISDN_FsmChangeState(&tm->tei_m, ST_TEI_IDVERIFY); in tei_id_chk_req_net()
690 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 2); in tei_id_chk_req_net()
691 tm->nval = 2; in tei_id_chk_req_net()
697 struct teimgr *tm = fi->userdata; in tei_id_chk_resp()
703 tm->tei_m.printdebug(fi, "identity check resp tei %d", tei); in tei_id_chk_resp()
704 if (tei == tm->l2->tei) in tei_id_chk_resp()
705 tm->rcnt++; in tei_id_chk_resp()
711 struct teimgr *tm = fi->userdata; in tei_id_verify_net()
717 tm->tei_m.printdebug(fi, "identity verify req tei %d/%d", in tei_id_verify_net()
718 tei, tm->l2->tei); in tei_id_verify_net()
719 if (tei == tm->l2->tei) in tei_id_verify_net()
726 struct teimgr *tm = fi->userdata; in tei_id_ver_tout_net()
728 if (tm->rcnt == 1) { in tei_id_ver_tout_net()
730 tm->tei_m.printdebug(fi, in tei_id_ver_tout_net()
731 "check req for tei %d successful\n", tm->l2->tei); in tei_id_ver_tout_net()
733 } else if (tm->rcnt > 1) { in tei_id_ver_tout_net()
735 tei_l2remove(tm->l2); in tei_id_ver_tout_net()
736 } else if (--tm->nval) { in tei_id_ver_tout_net()
738 tm->tei_m.printdebug(fi, in tei_id_ver_tout_net()
740 3 - tm->nval, tm->l2->tei); in tei_id_ver_tout_net()
741 put_tei_msg(tm->mgr, ID_CHK_REQ, 0, tm->l2->tei); in tei_id_ver_tout_net()
742 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 4); in tei_id_ver_tout_net()
744 tm->tei_m.printdebug(fi, "check req for tei %d failed", in tei_id_ver_tout_net()
745 tm->l2->tei); in tei_id_ver_tout_net()
747 tei_l2remove(tm->l2); in tei_id_ver_tout_net()
763 if (test_bit(FLG_FIXED_TEI, &tm->l2->flag)) in tei_ph_data_ind()
766 tm->tei_m.printdebug(&tm->tei_m, "tei handler mt %x", mt); in tei_ph_data_ind()
768 mISDN_FsmEvent(&tm->tei_m, EV_ASSIGN, dp); in tei_ph_data_ind()
770 mISDN_FsmEvent(&tm->tei_m, EV_DENIED, dp); in tei_ph_data_ind()
772 mISDN_FsmEvent(&tm->tei_m, EV_CHKREQ, dp); in tei_ph_data_ind()
774 mISDN_FsmEvent(&tm->tei_m, EV_REMOVE, dp); in tei_ph_data_ind()
776 mISDN_FsmEvent(&tm->tei_m, EV_VERIFY, dp); in tei_ph_data_ind()
778 mISDN_FsmEvent(&tm->tei_m, EV_CHKRESP, dp); in tei_ph_data_ind()
790 if (!mgr->up) in create_new_tei()
794 if (mgr->ch.st->dev->Dprotocols & ((1 << ISDN_P_TE_E1) | in create_new_tei()
801 l2 = create_l2(mgr->up, ISDN_P_LAPD_NT, opt, tei, sapi); in create_new_tei()
806 l2->tm = kzalloc(sizeof(struct teimgr), GFP_KERNEL); in create_new_tei()
807 if (!l2->tm) { in create_new_tei()
812 l2->tm->mgr = mgr; in create_new_tei()
813 l2->tm->l2 = l2; in create_new_tei()
814 l2->tm->tei_m.debug = *debug & DEBUG_L2_TEIFSM; in create_new_tei()
815 l2->tm->tei_m.userdata = l2->tm; in create_new_tei()
816 l2->tm->tei_m.printdebug = tei_debug; in create_new_tei()
817 l2->tm->tei_m.fsm = &teifsmn; in create_new_tei()
818 l2->tm->tei_m.state = ST_TEI_NOP; in create_new_tei()
819 l2->tm->tval = 2000; /* T202 2 sec */ in create_new_tei()
820 mISDN_FsmInitTimer(&l2->tm->tei_m, &l2->tm->timer); in create_new_tei()
821 write_lock_irqsave(&mgr->lock, flags); in create_new_tei()
823 list_add_tail(&l2->list, &mgr->layer2); in create_new_tei()
824 write_unlock_irqrestore(&mgr->lock, flags); in create_new_tei()
826 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL); in create_new_tei()
830 l2->ch.nr = id; in create_new_tei()
831 __add_layer2(&l2->ch, mgr->ch.st); in create_new_tei()
832 l2->ch.recv = mgr->ch.recv; in create_new_tei()
833 l2->ch.peer = mgr->ch.peer; in create_new_tei()
834 l2->ch.ctrl(&l2->ch, OPEN_CHANNEL, NULL); in create_new_tei()
836 rq.adr.dev = mgr->ch.st->dev->id; in create_new_tei()
837 id = mgr->ch.st->own.ctrl(&mgr->ch.st->own, OPEN_CHANNEL, &rq); in create_new_tei()
840 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL); in create_new_tei()
855 if (!mgr->up) in new_tei_req()
871 mISDN_FsmEvent(&l2->tm->tei_m, EV_ASSIGN_REQ, dp); in new_tei_req()
880 int ret = -EINVAL; in ph_data_ind()
884 if (skb->len < 8) { in ph_data_ind()
887 __func__, skb->len); in ph_data_ind()
891 if ((skb->data[0] >> 2) != TEI_SAPI) /* not for us */ in ph_data_ind()
893 if (skb->data[0] & 1) /* EA0 formal error */ in ph_data_ind()
895 if (!(skb->data[1] & 1)) /* EA1 formal error */ in ph_data_ind()
897 if ((skb->data[1] >> 1) != GROUP_TEI) /* not for us */ in ph_data_ind()
899 if ((skb->data[2] & 0xef) != UI) /* not UI */ in ph_data_ind()
901 if (skb->data[3] != TEI_ENTITY_ID) /* not tei entity */ in ph_data_ind()
903 mt = skb->data[6]; in ph_data_ind()
908 if (!test_bit(MGR_OPT_NETWORK, &mgr->options)) in ph_data_ind()
915 if (test_bit(MGR_OPT_NETWORK, &mgr->options)) in ph_data_ind()
923 new_tei_req(mgr, &skb->data[4]); in ph_data_ind()
926 list_for_each_entry_safe(l2, nl2, &mgr->layer2, list) { in ph_data_ind()
927 tei_ph_data_ind(l2->tm, mt, &skb->data[4], skb->len - 4); in ph_data_ind()
936 struct teimgr *tm = l2->tm; in l2_tei()
938 if (test_bit(FLG_FIXED_TEI, &l2->flag)) in l2_tei()
944 mISDN_FsmEvent(&tm->tei_m, EV_IDREQ, NULL); in l2_tei()
947 if (test_bit(MGR_OPT_NETWORK, &tm->mgr->options)) in l2_tei()
948 mISDN_FsmEvent(&tm->tei_m, EV_CHKREQ, &l2->tei); in l2_tei()
949 if (test_bit(MGR_OPT_USER, &tm->mgr->options)) in l2_tei()
950 mISDN_FsmEvent(&tm->tei_m, EV_VERIFY, NULL); in l2_tei()
953 if (test_bit(MGR_OPT_NETWORK, &tm->mgr->options)) in l2_tei()
954 mISDN_FsmEvent(&tm->mgr->deact, EV_ACTIVATE, NULL); in l2_tei()
957 if (test_bit(MGR_OPT_NETWORK, &tm->mgr->options)) in l2_tei()
958 mISDN_FsmEvent(&tm->mgr->deact, EV_DEACTIVATE, NULL); in l2_tei()
961 if (test_bit(MGR_OPT_NETWORK, &tm->mgr->options)) in l2_tei()
962 mISDN_FsmEvent(&tm->mgr->deact, EV_UI, NULL); in l2_tei()
971 struct teimgr *tm = l2->tm; in TEIrelease()
974 mISDN_FsmDelTimer(&tm->timer, 1); in TEIrelease()
975 write_lock_irqsave(&tm->mgr->lock, flags); in TEIrelease()
976 list_del(&l2->list); in TEIrelease()
977 write_unlock_irqrestore(&tm->mgr->lock, flags); in TEIrelease()
978 l2->tm = NULL; in TEIrelease()
993 __func__, dev_name(&mgr->ch.st->dev->dev), in create_teimgr()
994 crq->protocol, crq->adr.dev, crq->adr.channel, in create_teimgr()
995 crq->adr.sapi, crq->adr.tei); in create_teimgr()
996 if (crq->adr.tei > GROUP_TEI) in create_teimgr()
997 return -EINVAL; in create_teimgr()
998 if (crq->adr.tei < 64) in create_teimgr()
1000 if (crq->adr.tei == 0) in create_teimgr()
1002 if (test_bit(MGR_OPT_NETWORK, &mgr->options)) { in create_teimgr()
1003 if (crq->protocol == ISDN_P_LAPD_TE) in create_teimgr()
1004 return -EPROTONOSUPPORT; in create_teimgr()
1005 if ((crq->adr.tei != 0) && (crq->adr.tei != 127)) in create_teimgr()
1006 return -EINVAL; in create_teimgr()
1007 if (mgr->up) { in create_teimgr()
1011 return -EBUSY; in create_teimgr()
1013 } else if (test_bit(MGR_OPT_USER, &mgr->options)) { in create_teimgr()
1014 if (crq->protocol == ISDN_P_LAPD_NT) in create_teimgr()
1015 return -EPROTONOSUPPORT; in create_teimgr()
1016 if ((crq->adr.tei >= 64) && (crq->adr.tei < GROUP_TEI)) in create_teimgr()
1017 return -EINVAL; /* dyn tei */ in create_teimgr()
1019 if (crq->protocol == ISDN_P_LAPD_NT) in create_teimgr()
1020 test_and_set_bit(MGR_OPT_NETWORK, &mgr->options); in create_teimgr()
1021 if (crq->protocol == ISDN_P_LAPD_TE) in create_teimgr()
1022 test_and_set_bit(MGR_OPT_USER, &mgr->options); in create_teimgr()
1024 l1rq.adr = crq->adr; in create_teimgr()
1025 if (mgr->ch.st->dev->Dprotocols in create_teimgr()
1028 if ((crq->protocol == ISDN_P_LAPD_NT) && (crq->adr.tei == 127)) { in create_teimgr()
1029 mgr->up = crq->ch; in create_teimgr()
1032 if (test_bit(MGR_PH_ACTIVE, &mgr->options)) in create_teimgr()
1034 crq->ch = NULL; in create_teimgr()
1035 if (!list_empty(&mgr->layer2)) { in create_teimgr()
1036 read_lock_irqsave(&mgr->lock, flags); in create_teimgr()
1037 list_for_each_entry(l2, &mgr->layer2, list) { in create_teimgr()
1038 l2->up = mgr->up; in create_teimgr()
1039 l2->ch.ctrl(&l2->ch, OPEN_CHANNEL, NULL); in create_teimgr()
1041 read_unlock_irqrestore(&mgr->lock, flags); in create_teimgr()
1045 l2 = create_l2(crq->ch, crq->protocol, opt, in create_teimgr()
1046 crq->adr.tei, crq->adr.sapi); in create_teimgr()
1048 return -ENOMEM; in create_teimgr()
1049 l2->tm = kzalloc(sizeof(struct teimgr), GFP_KERNEL); in create_teimgr()
1050 if (!l2->tm) { in create_teimgr()
1053 return -ENOMEM; in create_teimgr()
1055 l2->tm->mgr = mgr; in create_teimgr()
1056 l2->tm->l2 = l2; in create_teimgr()
1057 l2->tm->tei_m.debug = *debug & DEBUG_L2_TEIFSM; in create_teimgr()
1058 l2->tm->tei_m.userdata = l2->tm; in create_teimgr()
1059 l2->tm->tei_m.printdebug = tei_debug; in create_teimgr()
1060 if (crq->protocol == ISDN_P_LAPD_TE) { in create_teimgr()
1061 l2->tm->tei_m.fsm = &teifsmu; in create_teimgr()
1062 l2->tm->tei_m.state = ST_TEI_NOP; in create_teimgr()
1063 l2->tm->tval = 1000; /* T201 1 sec */ in create_teimgr()
1069 l2->tm->tei_m.fsm = &teifsmn; in create_teimgr()
1070 l2->tm->tei_m.state = ST_TEI_NOP; in create_teimgr()
1071 l2->tm->tval = 2000; /* T202 2 sec */ in create_teimgr()
1077 mISDN_FsmInitTimer(&l2->tm->tei_m, &l2->tm->timer); in create_teimgr()
1078 write_lock_irqsave(&mgr->lock, flags); in create_teimgr()
1080 list_add_tail(&l2->list, &mgr->layer2); in create_teimgr()
1081 write_unlock_irqrestore(&mgr->lock, flags); in create_teimgr()
1083 l2->ch.nr = id; in create_teimgr()
1084 l2->up->nr = id; in create_teimgr()
1085 crq->ch = &l2->ch; in create_teimgr()
1087 id = mgr->ch.st->own.ctrl(&mgr->ch.st->own, OPEN_CHANNEL, in create_teimgr()
1091 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL); in create_teimgr()
1100 int ret = -EINVAL; in mgr_send()
1105 __func__, hh->prim, hh->id); in mgr_send()
1106 switch (hh->prim) { in mgr_send()
1108 mISDN_FsmEvent(&mgr->deact, EV_UI, NULL); in mgr_send()
1112 do_ack(mgr, hh->id); in mgr_send()
1116 test_and_set_bit(MGR_PH_ACTIVE, &mgr->options); in mgr_send()
1117 if (mgr->up) in mgr_send()
1119 mISDN_FsmEvent(&mgr->deact, EV_ACTIVATE_IND, NULL); in mgr_send()
1124 test_and_clear_bit(MGR_PH_ACTIVE, &mgr->options); in mgr_send()
1125 if (mgr->up) in mgr_send()
1127 mISDN_FsmEvent(&mgr->deact, EV_DEACTIVATE_IND, NULL); in mgr_send()
1143 test_and_clear_bit(OPTION_L1_HOLD, &mgr->options); in free_teimanager()
1144 if (test_bit(MGR_OPT_NETWORK, &mgr->options)) { in free_teimanager()
1146 mgr->up = NULL; in free_teimanager()
1147 if (test_bit(OPTION_L2_CLEANUP, &mgr->options)) { in free_teimanager()
1148 list_for_each_entry_safe(l2, nl2, &mgr->layer2, list) { in free_teimanager()
1149 put_tei_msg(mgr, ID_REMOVE, 0, l2->tei); in free_teimanager()
1150 mutex_lock(&mgr->ch.st->lmutex); in free_teimanager()
1151 list_del(&l2->ch.list); in free_teimanager()
1152 mutex_unlock(&mgr->ch.st->lmutex); in free_teimanager()
1153 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL); in free_teimanager()
1155 test_and_clear_bit(MGR_OPT_NETWORK, &mgr->options); in free_teimanager()
1157 list_for_each_entry_safe(l2, nl2, &mgr->layer2, list) { in free_teimanager()
1158 l2->up = NULL; in free_teimanager()
1162 if (test_bit(MGR_OPT_USER, &mgr->options)) { in free_teimanager()
1163 if (list_empty(&mgr->layer2)) in free_teimanager()
1164 test_and_clear_bit(MGR_OPT_USER, &mgr->options); in free_teimanager()
1166 mgr->ch.st->dev->D.ctrl(&mgr->ch.st->dev->D, CLOSE_CHANNEL, NULL); in free_teimanager()
1179 test_and_set_bit(OPTION_L2_CLEANUP, &mgr->options); in ctrl_teimanager()
1181 test_and_clear_bit(OPTION_L2_CLEANUP, &mgr->options); in ctrl_teimanager()
1185 test_and_set_bit(OPTION_L1_HOLD, &mgr->options); in ctrl_teimanager()
1187 test_and_clear_bit(OPTION_L1_HOLD, &mgr->options); in ctrl_teimanager()
1190 return -EINVAL; in ctrl_teimanager()
1205 __func__, hh->prim, hh->id); in check_data()
1206 if (test_bit(MGR_OPT_USER, &mgr->options)) in check_data()
1207 return -ENOTCONN; in check_data()
1208 if (hh->prim != PH_DATA_IND) in check_data()
1209 return -ENOTCONN; in check_data()
1210 if (skb->len != 3) in check_data()
1211 return -ENOTCONN; in check_data()
1212 if (skb->data[0] & 3) /* EA0 and CR must be 0 */ in check_data()
1213 return -EINVAL; in check_data()
1214 sapi = skb->data[0] >> 2; in check_data()
1215 if (!(skb->data[1] & 1)) /* invalid EA1 */ in check_data()
1216 return -EINVAL; in check_data()
1217 tei = skb->data[1] >> 1; in check_data()
1219 return -ENOTCONN; in check_data()
1220 if ((skb->data[2] & ~0x10) != SABME) in check_data()
1221 return -ENOTCONN; in check_data()
1231 return -ENOMEM; in check_data()
1233 ret = l2->ch.send(&l2->ch, skb); in check_data()
1245 list_for_each_entry_safe(l2, nl2, &mgr->layer2, list) { in delete_teimanager()
1246 mutex_lock(&mgr->ch.st->lmutex); in delete_teimanager()
1247 list_del(&l2->ch.list); in delete_teimanager()
1248 mutex_unlock(&mgr->ch.st->lmutex); in delete_teimanager()
1249 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL); in delete_teimanager()
1251 list_del(&mgr->ch.list); in delete_teimanager()
1252 list_del(&mgr->bcast.list); in delete_teimanager()
1253 skb_queue_purge(&mgr->sendq); in delete_teimanager()
1261 int ret = -EINVAL; in mgr_ctrl()
1293 read_lock_irqsave(&mgr->lock, flags); in mgr_bcast()
1294 list_for_each_entry(l2, &mgr->layer2, list) { in mgr_bcast()
1295 if ((hh->id & MISDN_ID_SAPI_MASK) == in mgr_bcast()
1296 (l2->ch.addr & MISDN_ID_SAPI_MASK)) { in mgr_bcast()
1297 if (list_is_last(&l2->list, &mgr->layer2)) { in mgr_bcast()
1309 hhc--; in mgr_bcast()
1310 hhc->prim = DL_INTERN_MSG; in mgr_bcast()
1311 hhc->id = l2->ch.nr; in mgr_bcast()
1312 ret = ch->st->own.recv(&ch->st->own, cskb); in mgr_bcast()
1318 __func__, l2->ch.nr, in mgr_bcast()
1319 hh->prim, l2->ch.addr, ret); in mgr_bcast()
1324 __func__, ch->nr, ch->addr); in mgr_bcast()
1330 read_unlock_irqrestore(&mgr->lock, flags); in mgr_bcast()
1340 return -EINVAL; in mgr_bcast_ctrl()
1350 return -ENOMEM; in create_teimanager()
1351 INIT_LIST_HEAD(&mgr->layer2); in create_teimanager()
1352 rwlock_init(&mgr->lock); in create_teimanager()
1353 skb_queue_head_init(&mgr->sendq); in create_teimanager()
1354 mgr->nextid = 1; in create_teimanager()
1355 mgr->lastid = MISDN_ID_NONE; in create_teimanager()
1356 mgr->ch.send = mgr_send; in create_teimanager()
1357 mgr->ch.ctrl = mgr_ctrl; in create_teimanager()
1358 mgr->ch.st = dev->D.st; in create_teimanager()
1359 set_channel_address(&mgr->ch, TEI_SAPI, GROUP_TEI); in create_teimanager()
1360 add_layer2(&mgr->ch, dev->D.st); in create_teimanager()
1361 mgr->bcast.send = mgr_bcast; in create_teimanager()
1362 mgr->bcast.ctrl = mgr_bcast_ctrl; in create_teimanager()
1363 mgr->bcast.st = dev->D.st; in create_teimanager()
1364 set_channel_address(&mgr->bcast, 0, GROUP_TEI); in create_teimanager()
1365 add_layer2(&mgr->bcast, dev->D.st); in create_teimanager()
1366 mgr->deact.debug = *debug & DEBUG_MANAGER; in create_teimanager()
1367 mgr->deact.userdata = mgr; in create_teimanager()
1368 mgr->deact.printdebug = da_debug; in create_teimanager()
1369 mgr->deact.fsm = &deactfsm; in create_teimanager()
1370 mgr->deact.state = ST_L1_DEACT; in create_teimanager()
1371 mISDN_FsmInitTimer(&mgr->deact, &mgr->datimer); in create_teimanager()
1372 dev->teimgr = &mgr->ch; in create_teimanager()