25 static void l2m_debug(
struct FsmInst *fi,
char *
fmt, ...);
27 static struct Fsm l2fsm;
40 #define L2_STATE_COUNT (ST_L2_8 + 1)
42 static char *strL2State[] =
79 #define L2_EVENT_COUNT (EV_L2_FRAME_ERROR + 1)
81 static char *strL2Event[] =
94 "EV_L2_DL_ESTABLISH_REQ",
95 "EV_L2_DL_RELEASE_REQ",
102 "EV_L2_SET_OWN_BUSY",
103 "EV_L2_CLEAR_OWN_BUSY",
110 set_peer_busy(
struct Layer2 *
l2) {
112 if (!skb_queue_empty(&l2->i_queue) ||
113 !skb_queue_empty(&l2->ui_queue))
118 clear_peer_busy(
struct Layer2 *l2) {
124 InitWin(
struct Layer2 *l2)
129 l2->windowar[i] =
NULL;
133 freewin1(
struct Layer2 *l2)
138 if (l2->windowar[i]) {
140 dev_kfree_skb(l2->windowar[i]);
141 l2->windowar[
i] =
NULL;
148 freewin(
struct PStack *
st)
154 ReleaseWin(
struct Layer2 *l2)
158 if ((cnt = freewin1(l2)))
162 static inline unsigned int
168 p1 = (st->l2.vs - st->l2.va) % 128;
170 p1 = (st->l2.vs - st->l2.va) % 8;
203 *ptr++ = (l2->sap << 2) | (rsp ? 2 : 0);
204 *ptr++ = (l2->tei << 1) | 1;
218 enqueue_super(
struct PStack *st,
222 st->l1.bcs->tx_cnt += skb->
len;
226 #define enqueue_ui(a, b) enqueue_super(a, b)
231 return ((data[0] & 0xef) ==
UI);
237 return ((data[0] & 0xef) ==
UA);
243 return ((data[0] & 0xef) ==
DM);
249 return ((data[0] & 0xef) ==
DISC);
259 return (((d & 0xf3) == 1) && ((d & 0x0c) != 0x0c));
265 u_char d = data[0] & ~0x10;
279 return ((data[0] & 0xef) ==
FRMR);
289 iframe_error(
struct PStack *st,
struct sk_buff *skb)
292 int rsp = *skb->
data & 0x2;
304 if ((skb->
len - i) > st->l2.maxlen)
312 super_error(
struct PStack *st,
struct sk_buff *skb)
322 unnum_error(
struct PStack *st,
struct sk_buff *skb,
int wantrsp)
324 int rsp = (*skb->
data & 0x2) >> 1;
338 UI_error(
struct PStack *st,
struct sk_buff *skb)
340 int rsp = *skb->
data & 0x2;
354 FRMR_error(
struct PStack *st,
struct sk_buff *skb)
358 int rsp = *skb->
data & 0x2;
367 if (skb->
len < headers + 5)
370 l2m_debug(&st->l2.l2m,
"FRMR information %2x %2x %2x %2x %2x",
371 datap[0], datap[1], datap[2],
374 if (skb->
len < headers + 3)
377 l2m_debug(&st->l2.l2m,
"FRMR information %2x %2x %2x",
378 datap[0], datap[1], datap[2]);
385 legalnr(
struct PStack *st,
unsigned int nr)
387 struct Layer2 *l2 = &st->l2;
390 return ((nr - l2->va) % 128) <= ((l2->vs - l2->va) % 128);
392 return ((nr - l2->va) % 8) <= ((l2->vs - l2->va) % 8);
396 setva(
struct PStack *st,
unsigned int nr)
398 struct Layer2 *l2 = &st->l2;
403 while (l2->va != nr) {
409 len = l2->windowar[l2->sow]->len;
410 if (PACKET_NOACK == l2->windowar[l2->sow]->pkt_type)
412 dev_kfree_skb(l2->windowar[l2->sow]);
413 l2->windowar[l2->sow] =
NULL;
414 l2->sow = (l2->sow + 1) % l2->window;
415 spin_unlock_irqrestore(&l2->lock, flags);
416 if (
test_bit(FLG_LLI_L2WAKEUP, &st->lli.flag) && (len >= 0))
420 spin_unlock_irqrestore(&l2->lock, flags);
430 i = sethdraddr(&st->l2, tmp, cr);
437 enqueue_super(st, skb);
487 st->l2.l2l3(st, pr,
NULL);
499 establishlink(
struct FsmInst *fi)
507 send_uframe(st, cmd,
CMD);
528 l2_mdl_error_dm(
struct FsmInst *fi,
int event,
void *arg)
543 l2_st8_mdl_error_dm(
struct FsmInst *fi,
int event,
void *arg)
558 l2_go_st3(
struct FsmInst *fi,
int event,
void *arg)
564 l2_mdl_assign(
struct FsmInst *fi,
int event,
void *arg)
573 l2_queue_ui_assign(
struct FsmInst *fi,
int event,
void *arg)
584 l2_queue_ui(
struct FsmInst *fi,
int event,
void *arg)
593 tx_ui(
struct PStack *st)
596 u_char header[MAX_HEADER_LEN];
599 i = sethdraddr(&(st->l2), header,
CMD);
608 l2_send_ui(
struct FsmInst *fi,
int event,
void *arg)
618 l2_got_ui(
struct FsmInst *fi,
int event,
void *arg)
633 l2_establish(
struct FsmInst *fi,
int event,
void *arg)
642 l2_discard_i_setl3(
struct FsmInst *fi,
int event,
void *arg)
652 l2_l3_reestablish(
struct FsmInst *fi,
int event,
void *arg)
662 l2_release(
struct FsmInst *fi,
int event,
void *arg)
670 l2_pend_rel(
struct FsmInst *fi,
int event,
void *arg)
678 l2_disconnect(
struct FsmInst *fi,
int event,
void *arg)
686 send_uframe(st,
DISC | 0x10,
CMD);
692 l2_start_multi(
struct FsmInst *fi,
int event,
void *arg)
711 l2_send_UA(
struct FsmInst *fi,
int event,
void *arg)
720 l2_send_DM(
struct FsmInst *fi,
int event,
void *arg)
729 l2_restart_multi(
struct FsmInst *fi,
int event,
void *arg)
741 if (st->l2.vs != st->l2.va) {
759 if (!skb_queue_empty(&st->l2.i_queue) &&
cansend(st))
764 l2_stop_multi(
struct FsmInst *fi,
int event,
void *arg)
781 l2_connected(
struct FsmInst *fi,
int event,
void *arg)
788 l2_mdl_error_ua(fi, event, arg);
794 l2_disconnect(fi, event, arg);
798 }
else if (st->l2.vs != st->l2.va) {
813 st->l2.l2l3(st, pr,
NULL);
815 if (!skb_queue_empty(&st->l2.i_queue) &&
cansend(st))
820 l2_released(
struct FsmInst *fi,
int event,
void *arg)
826 l2_mdl_error_ua(fi, event, arg);
837 l2_reestablish(
struct FsmInst *fi,
int event,
void *arg)
849 l2_st5_dm_release(
struct FsmInst *fi,
int event,
void *arg)
866 l2_st6_dm_release(
struct FsmInst *fi,
int event,
void *arg)
883 u_char tmp[MAX_HEADER_LEN];
887 i = sethdraddr(l2, tmp, cr);
890 tmp[i++] = (l2->vr << 1) | (pf ? 1 : 0);
892 tmp[i++] = (l2->vr << 5) | typ | (pf ? 0x10 : 0);
898 enqueue_super(st, skb);
905 enquiry_cr(st,
RNR,
RSP, 1);
907 enquiry_cr(st,
RR,
RSP, 1);
915 enquiry_cr(st,
RNR,
CMD, 1);
917 enquiry_cr(st,
RR,
CMD, 1);
924 nrerrorrecovery(
struct FsmInst *fi)
934 invoke_retransmission(
struct PStack *st,
unsigned int nr)
936 struct Layer2 *l2 = &st->l2;
942 while (l2->vs != nr) {
946 p1 = (l2->vs - l2->va) % 128;
949 p1 = (l2->vs - l2->va) % 8;
951 p1 = (p1 + l2->sow) % l2->window;
953 st->l1.bcs->tx_cnt += l2->windowar[p1]->len +
l2headersize(l2, 0);
957 spin_unlock_irqrestore(&l2->lock, flags);
961 spin_unlock_irqrestore(&l2->lock, flags);
965 l2_st7_got_super(
struct FsmInst *fi,
int event,
void *arg)
969 int PollFlag,
rsp, typ =
RR;
971 struct Layer2 *l2 = &st->l2;
973 rsp = *skb->
data & 0x2;
987 PollFlag = (skb->
data[1] & 0x1) == 0x1;
988 nr = skb->
data[1] >> 1;
990 PollFlag = (skb->
data[0] & 0x10);
991 nr = (skb->
data[0] >> 5) & 0x7;
1001 if (legalnr(st, nr)) {
1004 invoke_retransmission(st, nr);
1008 l2m_debug(&st->l2.l2m,
"Restart T203 ST7 REJ");
1009 }
else if ((nr == l2->vs) && (typ ==
RR)) {
1014 }
else if ((l2->va != nr) || (typ ==
RNR)) {
1019 if (!skb_queue_empty(&st->l2.i_queue) && (typ ==
RR))
1022 nrerrorrecovery(fi);
1026 l2_feed_i_if_reest(
struct FsmInst *fi,
int event,
void *arg)
1040 l2_feed_i_pull(
struct FsmInst *fi,
int event,
void *arg)
1052 l2_feed_iqueue(
struct FsmInst *fi,
int event,
void *arg)
1063 l2_got_iframe(
struct FsmInst *fi,
int event,
void *arg)
1067 struct Layer2 *l2 = &(st->l2);
1068 int PollFlag,
ns,
i;
1073 PollFlag = ((skb->
data[i + 1] & 0x1) == 0x1);
1074 ns = skb->
data[
i] >> 1;
1075 nr = (skb->
data[i + 1] >> 1) & 0x7f;
1077 PollFlag = (skb->
data[
i] & 0x10);
1078 ns = (skb->
data[
i] >> 1) & 0x7;
1079 nr = (skb->
data[
i] >> 5) & 0x7;
1084 }
else if (l2->vr == ns) {
1105 enquiry_cr(st,
REJ,
RSP, PollFlag);
1110 if (legalnr(st, nr)) {
1112 if (nr == st->l2.vs) {
1116 }
else if (nr != st->l2.va)
1121 nrerrorrecovery(fi);
1125 if (!skb_queue_empty(&st->l2.i_queue) && (fi->
state ==
ST_L2_7))
1128 enquiry_cr(st,
RR,
RSP, 0);
1132 l2_got_tei(
struct FsmInst *fi,
int event,
void *arg)
1136 st->l2.tei = (
long) arg;
1143 if (!skb_queue_empty(&st->l2.ui_queue))
1148 l2_st5_tout_200(
struct FsmInst *fi,
int event,
void *arg)
1155 }
else if (st->l2.rc == st->l2.N200) {
1172 l2_st6_tout_200(
struct FsmInst *fi,
int event,
void *arg)
1179 }
else if (st->l2.rc == st->l2.N200) {
1188 send_uframe(st,
DISC | 0x10,
CMD);
1193 l2_st7_tout_200(
struct FsmInst *fi,
int event,
void *arg)
1211 l2_st8_tout_200(
struct FsmInst *fi,
int event,
void *arg)
1221 if (st->l2.rc == st->l2.N200) {
1232 l2_st7_tout_203(
struct FsmInst *fi,
int event,
void *arg)
1247 l2_pull_iqueue(
struct FsmInst *fi,
int event,
void *arg)
1251 struct Layer2 *l2 = &st->l2;
1252 u_char header[MAX_HEADER_LEN];
1253 int i, hdr_space_needed;
1265 if (hdr_space_needed > skb_headroom(skb)) {
1270 dev_kfree_skb(orig_skb);
1276 p1 = (l2->vs - l2->va) % 128;
1278 p1 = (l2->vs - l2->va) % 8;
1279 p1 = (p1 + l2->sow) % l2->window;
1280 if (l2->windowar[p1]) {
1283 dev_kfree_skb(l2->windowar[p1]);
1287 i = sethdraddr(&st->l2, header,
CMD);
1290 header[i++] = l2->vs << 1;
1291 header[i++] = l2->vr << 1;
1292 l2->vs = (l2->vs + 1) % 128;
1294 header[i++] = (l2->vr << 5) | (l2->vs << 1);
1295 l2->vs = (l2->vs + 1) % 8;
1297 spin_unlock_irqrestore(&l2->lock, flags);
1305 if (!skb_queue_empty(&l2->i_queue) &&
cansend(st))
1310 l2_st8_got_super(
struct FsmInst *fi,
int event,
void *arg)
1314 int PollFlag,
rsp, rnr = 0;
1316 struct Layer2 *l2 = &st->l2;
1318 rsp = *skb->
data & 0x2;
1328 clear_peer_busy(l2);
1331 PollFlag = (skb->
data[1] & 0x1) == 0x1;
1332 nr = skb->
data[1] >> 1;
1334 PollFlag = (skb->
data[0] & 0x10);
1335 nr = (skb->
data[0] >> 5) & 0x7;
1339 if (rsp && PollFlag) {
1340 if (legalnr(st, nr)) {
1349 invoke_retransmission(st, nr);
1351 if (!skb_queue_empty(&l2->i_queue) &&
cansend(st))
1354 nrerrorrecovery(fi);
1356 if (!rsp && PollFlag)
1358 if (legalnr(st, nr)) {
1361 nrerrorrecovery(fi);
1366 l2_got_FRMR(
struct FsmInst *fi,
int event,
void *arg)
1373 if (!(skb->
data[0] & 1) || ((skb->
data[0] & 3) == 1) ||
1383 l2_st24_tei_remove(
struct FsmInst *fi,
int event,
void *arg)
1393 l2_st3_tei_remove(
struct FsmInst *fi,
int event,
void *arg)
1404 l2_st5_tei_remove(
struct FsmInst *fi,
int event,
void *arg)
1418 l2_st6_tei_remove(
struct FsmInst *fi,
int event,
void *arg)
1430 l2_tei_remove(
struct FsmInst *fi,
int event,
void *arg)
1445 l2_st14_persistent_da(
struct FsmInst *fi,
int event,
void *arg)
1456 l2_st5_persistent_da(
struct FsmInst *fi,
int event,
void *arg)
1469 l2_st6_persistent_da(
struct FsmInst *fi,
int event,
void *arg)
1480 l2_persistent_da(
struct FsmInst *fi,
int event,
void *arg)
1494 l2_set_own_busy(
struct FsmInst *fi,
int event,
void *arg)
1499 enquiry_cr(st,
RNR,
RSP, 0);
1505 l2_clear_own_busy(
struct FsmInst *fi,
int event,
void *arg)
1510 enquiry_cr(st,
RR,
RSP, 0);
1516 l2_frame_error(
struct FsmInst *fi,
int event,
void *arg)
1524 l2_frame_error_reest(
struct FsmInst *fi,
int event,
void *arg)
1626 isdnl2_l1l2(
struct PStack *st,
int pr,
void *arg)
1644 if (!(*datap & 1)) {
1645 if (!(c = iframe_error(st, skb)))
1648 if (!(c = super_error(st, skb)))
1650 }
else if (
IsUI(datap)) {
1651 if (!(c = UI_error(st, skb)))
1653 }
else if (
IsSABME(datap, st)) {
1654 if (!(c = unnum_error(st, skb,
CMD)))
1656 }
else if (
IsUA(datap)) {
1657 if (!(c = unnum_error(st, skb,
RSP)))
1659 }
else if (
IsDISC(datap)) {
1660 if (!(c = unnum_error(st, skb,
CMD)))
1662 }
else if (
IsDM(datap)) {
1663 if (!(c = unnum_error(st, skb,
RSP)))
1665 }
else if (
IsFRMR(datap)) {
1666 if (!(c = FRMR_error(st, skb)))
1702 l2m_debug(&st->l2.l2m,
"l2 unknown pr %04x", pr);
1708 isdnl2_l3l2(
struct PStack *st,
int pr,
void *arg)
1713 dev_kfree_skb((
struct sk_buff *) arg);
1718 dev_kfree_skb((
struct sk_buff *) arg);
1760 ReleaseWin(&st->l2);
1764 l2m_debug(
struct FsmInst *fi,
char *
fmt, ...)
1778 st->l1.l1l2 = isdnl2_l1l2;
1779 st->l3.l3l2 = isdnl2_l3l2;
1781 skb_queue_head_init(&st->l2.i_queue);
1782 skb_queue_head_init(&st->l2.ui_queue);
1786 st->l2.l2m.fsm = &l2fsm;
1791 st->l2.l2m.debug = 0;
1792 st->l2.l2m.userdata =
st;
1793 st->l2.l2m.userint = 0;
1794 st->l2.l2m.printdebug = l2m_debug;
1795 strcpy(st->l2.debug_id, debug_id);
1802 transl2_l3l2(
struct PStack *st,
int pr,
void *arg)
1821 st->l3.l3l2 = transl2_l3l2;
1834 l2fsm.strEvent = strL2Event;
1835 l2fsm.strState = strL2State;