18 #include <linux/random.h>
19 #include <linux/slab.h>
30 #define TEI_ENTITY_ID 0xf
32 #define MGR_PH_ACTIVE 16
33 #define MGR_PH_NOTREADY 17
35 #define DATIMER_VAL 10000
39 static struct Fsm deactfsm = {
NULL, 0, 0,
NULL, NULL};
40 static struct Fsm teifsmu = {
NULL, 0, 0,
NULL, NULL};
41 static struct Fsm teifsmn = {
NULL, 0, 0,
NULL, NULL};
48 #define DEACT_STATE_COUNT (ST_L1_ACTIV + 1)
50 static char *strDeactState[] =
53 "ST_L1_DEACT_PENDING",
66 #define DEACT_EVENT_COUNT (EV_DATIMER + 1)
68 static char *strDeactEvent[] =
85 if (!(*
debug & DEBUG_L2_TEIFSM))
109 da_deactivate_ind(
struct FsmInst *fi,
int event,
void *arg)
115 da_deactivate(
struct FsmInst *fi,
int event,
void *arg)
139 da_ui(
struct FsmInst *fi,
int event,
void *arg)
152 da_timer(
struct FsmInst *fi,
int event,
void *arg)
175 static struct FsmNode DeactFnList[] =
191 #define TEI_STATE_COUNT (ST_TEI_IDVERIFY + 1)
193 static char *strTeiState[] =
212 #define TEI_EVENT_COUNT (EV_TIMER + 1)
214 static char *strTeiEvent[] =
228 tei_debug(
struct FsmInst *fi,
char *fmt, ...)
234 if (!(*
debug & DEBUG_L2_TEIFSM))
243 tm->
l2->sapi, tm->
l2->tei, &vaf);
251 get_free_id(
struct manager *mgr)
258 if (l2->
ch.nr > 63) {
260 "%s: more as 63 layer2 for one device\n",
266 for (i = 1; i < 64; i++)
275 get_free_tei(
struct manager *mgr)
284 if ((l2->
ch.addr & 0xff) != 0)
286 i = l2->
ch.addr >> 8;
293 for (i = 0; i < 64; i++)
311 hh = mISDN_HEAD_P(skb);
313 hh->
id = (mgr->
ch.nr << 16) | mgr->
ch.addr;
316 err = mgr->
up->send(mgr->
up, skb);
350 mgr->
lastid = mISDN_HEAD_ID(skb);
352 if (mgr->
ch.recv(mgr->
ch.peer, skb)) {
370 mgr->
lastid = mISDN_HEAD_ID(skb);
371 if (!mgr->
ch.recv(mgr->
ch.peer, skb))
407 mISDN_HEAD_ID(skb) = new_id(mgr);
430 if ((l2->
sapi == 0) && (l2->
tei > 0) &&
441 put_tei_msg(
struct manager *mgr,
u_char m_id,
unsigned int ri,
int tei)
455 bp[7] = ((tei << 1) & 0xff) | 1;
461 mgr_send_down(mgr, skb);
465 tei_id_request(
struct FsmInst *fi,
int event,
void *arg)
471 "assign request for already assigned tei %d",
475 tm->
ri = random_ri();
476 if (*
debug & DEBUG_L2_TEI)
478 "assign request ri %d", tm->
ri);
486 tei_id_assign(
struct FsmInst *fi,
int event,
void *arg)
493 ri = ((
unsigned int) *dp++ << 8);
497 if (*
debug & DEBUG_L2_TEI)
498 tm->
tei_m.printdebug(fi,
"identity assign ri %d tei %d",
500 l2 = findtei(tm->
mgr, tei);
502 if (ri != l2->
tm->ri) {
503 tm->
tei_m.printdebug(fi,
504 "possible duplicate assignment tei %d", tei);
507 }
else if (ri == tm->
ri) {
515 tei_id_test_dup(
struct FsmInst *fi,
int event,
void *arg)
522 ri = ((
unsigned int) *dp++ << 8);
526 if (*
debug & DEBUG_L2_TEI)
527 tm->
tei_m.printdebug(fi,
"foreign identity assign ri %d tei %d",
529 l2 = findtei(tm->
mgr, tei);
531 if (ri != l2->
tm->ri) {
532 tm->
tei_m.printdebug(fi,
533 "possible duplicate assignment tei %d", tei);
540 tei_id_denied(
struct FsmInst *fi,
int event,
void *arg)
546 ri = ((
unsigned int) *dp++ << 8);
550 if (*
debug & DEBUG_L2_TEI)
551 tm->
tei_m.printdebug(fi,
"identity denied ri %d tei %d",
556 tei_id_chk_req(
struct FsmInst *fi,
int event,
void *arg)
562 tei = *(dp + 3) >> 1;
563 if (*
debug & DEBUG_L2_TEI)
564 tm->
tei_m.printdebug(fi,
"identity check req tei %d", tei);
566 (tei == tm->
l2->tei))) {
574 tei_id_remove(
struct FsmInst *fi,
int event,
void *arg)
580 tei = *(dp + 3) >> 1;
581 if (*
debug & DEBUG_L2_TEI)
582 tm->
tei_m.printdebug(fi,
"identity remove tei %d", tei);
592 tei_id_verify(
struct FsmInst *fi,
int event,
void *arg)
596 if (*
debug & DEBUG_L2_TEI)
597 tm->
tei_m.printdebug(fi,
"id verify request for tei %d",
606 tei_id_req_tout(
struct FsmInst *fi,
int event,
void *arg)
611 tm->
ri = random_ri();
612 if (*
debug & DEBUG_L2_TEI)
613 tm->
tei_m.printdebug(fi,
"assign req(%d) ri %d",
618 tm->
tei_m.printdebug(fi,
"assign req failed");
625 tei_id_ver_tout(
struct FsmInst *fi,
int event,
void *arg)
630 if (*
debug & DEBUG_L2_TEI)
631 tm->
tei_m.printdebug(fi,
632 "id verify req(%d) for tei %d",
633 3 - tm->
nval, tm->
l2->tei);
637 tm->
tei_m.printdebug(fi,
"verify req for tei %d failed",
644 static struct FsmNode TeiFnListUser[] =
660 tei_l2remove(
struct layer2 *l2)
669 tei_assign_req(
struct FsmInst *fi,
int event,
void *arg)
676 "net tei assign request without tei");
679 tm->
ri = ((
unsigned int) *dp++ << 8);
681 if (*
debug & DEBUG_L2_TEI)
683 "net assign request ri %d teim %d", tm->
ri, *dp);
689 tei_id_chk_req_net(
struct FsmInst *fi,
int event,
void *arg)
693 if (*
debug & DEBUG_L2_TEI)
694 tm->
tei_m.printdebug(fi,
"id check request for tei %d",
704 tei_id_chk_resp(
struct FsmInst *fi,
int event,
void *arg)
711 if (*
debug & DEBUG_L2_TEI)
712 tm->
tei_m.printdebug(fi,
"identity check resp tei %d", tei);
713 if (tei == tm->
l2->tei)
718 tei_id_verify_net(
struct FsmInst *fi,
int event,
void *arg)
725 if (*
debug & DEBUG_L2_TEI)
726 tm->
tei_m.printdebug(fi,
"identity verify req tei %d/%d",
728 if (tei == tm->
l2->tei)
729 tei_id_chk_req_net(fi, event, arg);
733 tei_id_ver_tout_net(
struct FsmInst *fi,
int event,
void *arg)
738 if (*
debug & DEBUG_L2_TEI)
739 tm->
tei_m.printdebug(fi,
740 "check req for tei %d successful\n", tm->
l2->tei);
742 }
else if (tm->
rcnt > 1) {
744 tei_l2remove(tm->
l2);
745 }
else if (--tm->
nval) {
746 if (*
debug & DEBUG_L2_TEI)
747 tm->
tei_m.printdebug(fi,
748 "id check req(%d) for tei %d",
749 3 - tm->
nval, tm->
l2->tei);
753 tm->
tei_m.printdebug(fi,
"check req for tei %d failed",
756 tei_l2remove(tm->
l2);
760 static struct FsmNode TeiFnListNet[] =
774 if (*
debug & DEBUG_L2_TEI)
775 tm->
tei_m.printdebug(&tm->
tei_m,
"tei handler mt %x", mt);
791 create_new_tei(
struct manager *mgr,
int tei,
int sapi)
793 unsigned long opt = 0;
797 struct channel_req
rq;
801 if ((tei >= 0) && (tei < 64))
823 l2->
tm->tei_m.debug = *
debug & DEBUG_L2_TEIFSM;
824 l2->
tm->tei_m.userdata = l2->
tm;
825 l2->
tm->tei_m.printdebug = tei_debug;
826 l2->
tm->tei_m.fsm = &teifsmn;
831 id = get_free_id(mgr);
841 l2->
ch.recv = mgr->
ch.recv;
842 l2->
ch.peer = mgr->
ch.peer;
845 rq.adr.dev = mgr->
ch.st->dev->id;
871 tei = get_free_tei(mgr);
876 l2 = create_new_tei(mgr, tei,
CTRL_SAPI);
894 if (*
debug & DEBUG_L2_TEI)
902 if (skb->
data[0] & 1)
904 if (!(skb->
data[1] & 1))
908 if ((skb->
data[2] & 0xef) != UI)
932 new_tei_req(mgr, &skb->
data[4]);
936 tei_ph_data_ind(l2->
tm, mt, &skb->
data[4], skb->
len - 4);
949 if (*
debug & DEBUG_L2_TEI)
992 create_teimgr(
struct manager *mgr,
struct channel_req *crq)
995 unsigned long opt = 0;
998 struct channel_req l1rq;
1000 if (*
debug & DEBUG_L2_TEI)
1002 __func__, dev_name(&mgr->
ch.st->dev->dev),
1003 crq->protocol, crq->adr.dev, crq->adr.channel,
1004 crq->adr.sapi, crq->adr.tei);
1007 if (crq->adr.tei < 64)
1009 if (crq->adr.tei == 0)
1014 if ((crq->adr.tei != 0) && (crq->adr.tei != 127))
1018 "%s: only one network manager is allowed\n",
1025 if ((crq->adr.tei >= 64) && (crq->adr.tei <
GROUP_TEI))
1033 l1rq.adr = crq->adr;
1034 if (mgr->
ch.st->dev->Dprotocols
1037 if ((crq->protocol ==
ISDN_P_LAPD_NT) && (crq->adr.tei == 127)) {
1044 if (!list_empty(&mgr->
layer2)) {
1054 l2 =
create_l2(crq->ch, crq->protocol, opt,
1055 crq->adr.tei, crq->adr.sapi);
1066 l2->
tm->tei_m.debug = *
debug & DEBUG_L2_TEIFSM;
1067 l2->
tm->tei_m.userdata = l2->
tm;
1068 l2->
tm->tei_m.printdebug = tei_debug;
1070 l2->
tm->tei_m.fsm = &teifsmu;
1072 l2->
tm->tval = 1000;
1078 l2->
tm->tei_m.fsm = &teifsmn;
1080 l2->
tm->tval = 2000;
1088 id = get_free_id(mgr);
1105 mgr_send(
struct mISDNchannel *ch,
struct sk_buff *skb)
1108 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1112 if (*
debug & DEBUG_L2_RECV)
1114 __func__, hh->
prim, hh->
id);
1118 ret = ph_data_ind(mgr, skb);
1121 do_ack(mgr, hh->
id);
1140 return dl_unit_data(mgr, skb);
1148 free_teimanager(
struct manager *mgr)
1172 if (list_empty(&mgr->
layer2))
1180 ctrl_teimanager(
struct manager *mgr,
void *arg)
1183 int *
val = (
int *)arg;
1209 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1213 if (*
debug & DEBUG_L2_CTRL)
1215 __func__, hh->
prim, hh->
id);
1222 if (skb->
data[0] & 3)
1224 sapi = skb->
data[0] >> 2;
1225 if (!(skb->
data[1] & 1))
1227 tei = skb->
data[1] >> 1;
1233 if (*
debug & DEBUG_L2_CTRL)
1235 __func__, sapi, tei);
1236 l2 = create_new_tei(mgr, tei, sapi);
1238 if (*
debug & DEBUG_L2_CTRL)
1243 ret = l2->
ch.send(&l2->
ch, skb);
1268 mgr_ctrl(
struct mISDNchannel *ch,
u_int cmd,
void *arg)
1274 if (*
debug & DEBUG_L2_CTRL)
1278 ret = create_teimgr(mgr, arg);
1281 ret = free_teimanager(mgr);
1284 ret = ctrl_teimanager(mgr, arg);
1287 ret = check_data(mgr, arg);
1294 mgr_bcast(
struct mISDNchannel *ch,
struct sk_buff *skb)
1297 struct mISDNhead *hhc, *hh = mISDN_HEAD_P(skb);
1315 hhc = mISDN_HEAD_P(cskb);
1321 hhc->
id = l2->
ch.nr;
1322 ret = ch->st->own.recv(&ch->st->own, cskb);
1324 if (*
debug & DEBUG_SEND_ERR)
1326 "%s ch%d prim(%x) addr(%x)"
1328 __func__, l2->
ch.nr,
1329 hh->
prim, l2->
ch.addr, ret);
1334 __func__, ch->nr, ch->addr);
1342 dev_kfree_skb(cskb);
1349 mgr_bcast_ctrl(
struct mISDNchannel *ch,
u_int cmd,
void *arg)
1363 INIT_LIST_HEAD(&mgr->
layer2);
1365 skb_queue_head_init(&mgr->
sendq);
1368 mgr->
ch.send = mgr_send;
1369 mgr->
ch.ctrl = mgr_ctrl;
1370 mgr->
ch.st = dev->D.st;
1373 mgr->
bcast.send = mgr_bcast;
1374 mgr->
bcast.ctrl = mgr_bcast_ctrl;
1375 mgr->
bcast.st = dev->D.st;
1379 mgr->
deact.userdata = mgr;
1380 mgr->
deact.printdebug = da_debug;
1381 mgr->
deact.fsm = &deactfsm;
1384 dev->teimgr = &mgr->
ch;