patch-2.1.92 linux/drivers/isdn/hisax/isdnl2.c
Next file: linux/drivers/isdn/hisax/isdnl3.c
Previous file: linux/drivers/isdn/hisax/isdnl1.h
Back to the patch index
Back to the overall index
- Lines: 2137
- Date:
Wed Apr 1 16:20:58 1998
- Orig file:
v2.1.91/linux/drivers/isdn/hisax/isdnl2.c
- Orig date:
Thu Feb 12 20:56:06 1998
diff -u --recursive --new-file v2.1.91/linux/drivers/isdn/hisax/isdnl2.c linux/drivers/isdn/hisax/isdnl2.c
@@ -1,4 +1,4 @@
-/* $Id: isdnl2.c,v 1.10 1997/05/06 09:38:13 keil Exp $
+/* $Id: isdnl2.c,v 2.7 1998/02/12 23:07:47 keil Exp $
* Author Karsten Keil (keil@temic-ech.spacenet.de)
* based on the teles driver from Jan den Ouden
@@ -7,56 +7,51 @@
* Fritz Elfert
*
* $Log: isdnl2.c,v $
- * Revision 1.10 1997/05/06 09:38:13 keil
- * Bugfixes: - clear ack queue entries after resend
- * - acknowlege each frame to linklevel
- * - UA for SABM is Response, not command
- * - only RR was send as supervisor frame (X.75 hangs after a
- * sequence error)
+ * Revision 2.7 1998/02/12 23:07:47 keil
+ * change for 2.1.86 (removing FREE_READ/FREE_WRITE from [dev]_kfree_skb()
*
- * Revision 1.9 1997/04/07 23:02:11 keil
- * missing braces
+ * Revision 2.6 1998/02/02 13:36:15 keil
+ * bugfix X.75 win calculation
*
- * Revision 1.8 1997/04/06 22:59:59 keil
- * Using SKB's; changing function names; some minor changes
+ * Revision 2.5 1997/11/06 17:09:22 keil
+ * New 2.1 init code
*
- * Revision 1.7 1997/02/09 00:25:44 keil
- * new interface handling, one interface per card
+ * Revision 2.4 1997/10/29 19:02:01 keil
+ * new LL interface
*
- * Revision 1.6 1997/01/21 22:23:42 keil
- * D-channel log changed
+ * Revision 2.3 1997/10/01 09:21:39 fritz
+ * Removed old compatibility stuff for 2.0.X kernels.
+ * From now on, this code is for 2.1.X ONLY!
+ * Old stuff is still in the separate branch.
*
- * Revision 1.5 1997/01/04 13:47:06 keil
- * handling of MDL_REMOVE added (Thanks to Sim Yskes)
+ * Revision 2.2 1997/07/31 11:49:05 keil
+ * Eroor handling for no TEI assign
*
- * Revision 1.4 1996/12/08 19:51:51 keil
- * many fixes from Pekka Sarnila
+ * Revision 2.1 1997/07/27 21:34:38 keil
+ * cosmetics
*
- * Revision 1.3 1996/11/05 19:39:12 keil
- * X.75 bugfixes Thank to Martin Maurer
- *
- * Revision 1.2 1996/10/30 10:20:58 keil
- * X.75 answer of SABMX fixed to response address (AVM X.75 problem)
- *
- * Revision 1.1 1996/10/13 20:04:54 keil
- * Initial revision
+ * Revision 2.0 1997/06/26 11:07:29 keil
+ * New q.921 and X.75 Layer2
*
*
+ * Old log removed KKe
*
*/
#define __NO_VERSION__
#include "hisax.h"
#include "isdnl2.h"
-const char *l2_revision = "$Revision: 1.10 $";
+const char *l2_revision = "$Revision: 2.7 $";
static void l2m_debug(struct FsmInst *fi, char *s);
+static
struct Fsm l2fsm =
{NULL, 0, 0, NULL, NULL};
enum {
ST_L2_1,
+ ST_L2_2,
ST_L2_3,
ST_L2_4,
ST_L2_5,
@@ -70,6 +65,7 @@
static char *strL2State[] =
{
"ST_L2_1",
+ "ST_L2_2",
"ST_L2_3",
"ST_L2_4",
"ST_L2_5",
@@ -81,53 +77,53 @@
enum {
EV_L2_UI,
EV_L2_SABMX,
- EV_L2_UA,
EV_L2_DISC,
- EV_L2_I,
- EV_L2_RR,
- EV_L2_REJ,
+ EV_L2_DM,
+ EV_L2_UA,
EV_L2_FRMR,
+ EV_L2_SUPER,
+ EV_L2_I,
EV_L2_DL_DATA,
+ EV_L2_ACK_PULL,
+ EV_L2_DL_UNIT_DATA,
EV_L2_DL_ESTABLISH,
+ EV_L2_DL_RELEASE,
EV_L2_MDL_ASSIGN,
EV_L2_MDL_REMOVE,
- EV_L2_DL_UNIT_DATA,
- EV_L2_DL_RELEASE,
+ EV_L2_MDL_ERROR,
EV_L2_MDL_NOTEIPROC,
+ EV_L1_DEACTIVATE,
EV_L2_T200,
- EV_L2_ACK_PULL,
EV_L2_T203,
- EV_L2_RNR,
};
-#define L2_EVENT_COUNT (EV_L2_RNR+1)
+#define L2_EVENT_COUNT (EV_L2_T203+1)
static char *strL2Event[] =
{
"EV_L2_UI",
"EV_L2_SABMX",
- "EV_L2_UA",
"EV_L2_DISC",
- "EV_L2_I",
- "EV_L2_RR",
- "EV_L2_REJ",
+ "EV_L2_DM",
+ "EV_L2_UA",
"EV_L2_FRMR",
+ "EV_L2_SUPER",
+ "EV_L2_I",
"EV_L2_DL_DATA",
+ "EV_L2_ACK_PULL",
+ "EV_L2_DL_UNIT_DATA",
"EV_L2_DL_ESTABLISH",
+ "EV_L2_DL_RELEASE",
"EV_L2_MDL_ASSIGN",
"EV_L2_MDL_REMOVE",
- "EV_L2_DL_UNIT_DATA",
- "EV_L2_DL_RELEASE",
+ "EV_L2_MDL_ERROR",
"EV_L2_MDL_NOTEIPROC",
+ "EV_L1_DEACTIVATE",
"EV_L2_T200",
- "EV_L2_ACK_PULL",
"EV_L2_T203",
- "EV_L2_RNR",
};
-int errcount = 0;
-
-static int l2addrsize(struct Layer2 *tsp);
+static int l2addrsize(struct Layer2 *l2);
static void
InitWin(struct Layer2 *l2)
@@ -143,11 +139,9 @@
{
int i, cnt = 0;
-
for (i = 0; i < MAX_WINDOW; i++) {
if (l2->windowar[i]) {
cnt++;
- SET_SKB_FREE(l2->windowar[i]);
dev_kfree_skb(l2->windowar[i]);
l2->windowar[i] = NULL;
}
@@ -156,13 +150,15 @@
printk(KERN_WARNING "isdl2 freed %d skbuffs in release\n", cnt);
}
-static int
+inline int
cansend(struct PStack *st)
{
int p1;
- p1 = (st->l2.va + st->l2.window) % (st->l2.extended ? 128 : 8);
- return (st->l2.vs != p1);
+ p1 = st->l2.vs - st->l2.va;
+ if (p1 < 0)
+ p1 += (test_bit(FLG_MOD128, &st->l2.flag) ? 128 : 8);
+ return ((p1 < st->l2.window) && !test_bit(FLG_PEER_BUSY, &st->l2.flag));
}
static void
@@ -171,40 +167,54 @@
struct sk_buff *skb;
while ((skb = skb_dequeue(&st->l2.i_queue))) {
- SET_SKB_FREE(skb);
dev_kfree_skb(skb);
}
}
-int
-l2headersize(struct Layer2 *tsp, int ui)
+static void
+discard_ui_queue(struct PStack *st)
+{
+ struct sk_buff *skb;
+
+ while ((skb = skb_dequeue(&st->l2.ui_queue))) {
+ dev_kfree_skb(skb);
+ }
+}
+
+inline void
+clear_exception(struct Layer2 *l2)
+{
+ test_and_clear_bit(FLG_ACK_PEND, &l2->flag);
+ test_and_clear_bit(FLG_REJEXC, &l2->flag);
+ test_and_clear_bit(FLG_OWN_BUSY, &l2->flag);
+ test_and_clear_bit(FLG_PEER_BUSY, &l2->flag);
+}
+
+inline int
+l2headersize(struct Layer2 *l2, int ui)
{
- return ((tsp->extended && (!ui) ? 2 : 1) + (tsp->laptype == LAPD ? 2 : 1));
+ return (((test_bit(FLG_MOD128, &l2->flag) && (!ui)) ? 2 : 1) +
+ (test_bit(FLG_LAPD, &l2->flag) ? 2 : 1));
}
-int
-l2addrsize(struct Layer2 *tsp)
+inline int
+l2addrsize(struct Layer2 *l2)
{
- return (tsp->laptype == LAPD ? 2 : 1);
+ return (test_bit(FLG_LAPD, &l2->flag) ? 2 : 1);
}
static int
-sethdraddr(struct Layer2 *tsp,
- u_char * header, int rsp)
+sethdraddr(struct Layer2 *l2, u_char * header, int rsp)
{
u_char *ptr = header;
- int crbit;
+ int crbit = rsp;
- if (tsp->laptype == LAPD) {
- crbit = rsp;
- if (!tsp->orig)
- crbit = !crbit;
- *ptr++ = (tsp->sap << 2) | (crbit ? 2 : 0);
- *ptr++ = (tsp->tei << 1) | 1;
+ if (test_bit(FLG_LAPD, &l2->flag)) {
+ *ptr++ = (l2->sap << 2) | (rsp ? 2 : 0);
+ *ptr++ = (l2->tei << 1) | 1;
return (2);
} else {
- crbit = rsp;
- if (tsp->orig)
+ if (test_bit(FLG_ORIG, &l2->flag))
crbit = !crbit;
if (crbit)
*ptr++ = 1;
@@ -218,79 +228,107 @@
enqueue_ui(struct PStack *st,
struct sk_buff *skb)
{
- st->l2.l2l1(st, PH_DATA, skb);
+ st->l2.l2l1(st, PH_DATA_REQ, skb);
}
static void
enqueue_super(struct PStack *st,
struct sk_buff *skb)
{
- st->l2.l2l1(st, PH_DATA, skb);
+ st->l2.l2l1(st, PH_DATA_REQ, skb);
}
-static int
-legalnr(struct PStack *st, int nr)
+inline int
+IsUI(u_char * data, int ext)
{
- struct Layer2 *l2 = &st->l2;
- int lnr, lvs;
+ return ((data[0] & 0xef) == UI);
+}
- lvs = (l2->vs >= l2->va) ? l2->vs : (l2->vs + l2->extended ? 128 : 8);
- lnr = (nr >= l2->va) ? nr : (nr + l2->extended ? 128 : 8);
- return (lnr <= lvs);
+inline int
+IsUA(u_char * data, int ext)
+{
+ return ((data[0] & 0xef) == UA);
}
-static void
-setva(struct PStack *st, int nr)
+inline int
+IsDM(u_char * data, int ext)
{
- struct Layer2 *l2 = &st->l2;
+ return ((data[0] & 0xef) == DM);
+}
- if (l2->va != nr) {
- while (l2->va != nr) {
- l2->va = (l2->va + 1) % (l2->extended ? 128 : 8);
- SET_SKB_FREE(l2->windowar[l2->sow]);
- dev_kfree_skb(l2->windowar[l2->sow]);
- l2->windowar[l2->sow] = NULL;
- l2->sow = (l2->sow + 1) % l2->window;
- if (st->l4.l2writewakeup)
- st->l4.l2writewakeup(st);
- }
- }
+inline int
+IsDISC(u_char * data, int ext)
+{
+ return ((data[0] & 0xef) == DISC);
}
-static void
-l2s1(struct FsmInst *fi, int event, void *arg)
+inline int
+IsRR(u_char * data, int ext)
{
- struct PStack *st = fi->userdata;
+ if (ext)
+ return (data[0] == RR);
+ else
+ return ((data[0] & 0xf) == 1);
+}
+
+inline int
+IsSABMX(u_char * data, int ext)
+{
+ u_char d = data[0] & ~0x10;
- st->l2.l2tei(st, MDL_ASSIGN, (void *) st->l2.ces);
- FsmChangeState(fi, ST_L2_3);
+ return (ext ? d == SABME : d == SABM);
}
-static void
-l2_send_ui(struct FsmInst *fi, int event, void *arg)
+inline int
+IsREJ(u_char * data, int ext)
{
- struct PStack *st = fi->userdata;
- struct sk_buff *skb = arg;
- u_char header[MAX_HEADER_LEN];
- int i;
+ return (ext ? data[0] == REJ : (data[0] & 0xf) == REJ);
+}
- i = sethdraddr(&(st->l2), header, CMD);
- header[i++] = UI;
- memcpy(skb_push(skb, i), header, i);
- enqueue_ui(st, skb);
+inline int
+IsFRMR(u_char * data, int ext)
+{
+ return ((data[0] & 0xef) == FRMR);
+}
+
+inline int
+IsRNR(u_char * data, int ext)
+{
+ return (ext ? data[0] == RNR : (data[0] & 0xf) == RNR);
+}
+
+static int
+legalnr(struct PStack *st, int nr)
+{
+ struct Layer2 *l2 = &st->l2;
+ int lnr, lvs;
+
+ lvs = (l2->vs >= l2->va) ? l2->vs :
+ (l2->vs + (test_bit(FLG_MOD128, &l2->flag) ? 128 : 8));
+ lnr = (nr >= l2->va) ? nr : (test_bit(FLG_MOD128, &l2->flag) ? 128 : 8);
+ return (lnr <= lvs);
}
static void
-l2_receive_ui(struct FsmInst *fi, int event, void *arg)
+setva(struct PStack *st, int nr)
{
- struct PStack *st = fi->userdata;
- struct sk_buff *skb = arg;
+ struct Layer2 *l2 = &st->l2;
+ int len;
- skb_pull(skb, l2headersize(&st->l2, 1));
- st->l2.l2l3(st, DL_UNIT_DATA, skb);
+ while (l2->va != nr) {
+ l2->va = (l2->va + 1) % (test_bit(FLG_MOD128, &l2->flag) ? 128 : 8);
+ len = l2->windowar[l2->sow]->len;
+ if (PACKET_NOACK == l2->windowar[l2->sow]->pkt_type)
+ len = -1;
+ dev_kfree_skb(l2->windowar[l2->sow]);
+ l2->windowar[l2->sow] = NULL;
+ l2->sow = (l2->sow + 1) % l2->window;
+ if (st->lli.l2writewakeup && (len >=0))
+ st->lli.l2writewakeup(st, len);
+ }
}
-inline void
+static void
send_uframe(struct PStack *st, u_char cmd, u_char cr)
{
struct sk_buff *skb;
@@ -307,53 +345,156 @@
enqueue_super(st, skb);
}
+inline u_char
+get_PollFlag(struct PStack * st, struct sk_buff * skb)
+{
+ return (skb->data[l2addrsize(&(st->l2))] & 0x10);
+}
+
+inline void
+FreeSkb(struct sk_buff *skb)
+{
+ dev_kfree_skb(skb);
+}
+
+
+inline u_char
+get_PollFlagFree(struct PStack *st, struct sk_buff *skb)
+{
+ u_char PF;
+
+ PF = get_PollFlag(st, skb);
+ FreeSkb(skb);
+ return (PF);
+}
+
static void
establishlink(struct FsmInst *fi)
{
struct PStack *st = fi->userdata;
u_char cmd;
- FsmChangeState(fi, ST_L2_5);
+ clear_exception(&st->l2);
st->l2.rc = 0;
+ cmd = (test_bit(FLG_MOD128, &st->l2.flag) ? SABME : SABM) | 0x10;
+ send_uframe(st, cmd, CMD);
+ FsmDelTimer(&st->l2.t203, 1);
+ FsmRestartTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 1);
+ test_and_set_bit(FLG_T200_RUN, &st->l2.flag);
+ FsmChangeState(fi, ST_L2_5);
+}
- if (FsmAddTimer(&st->l2.t200_timer, st->l2.t200, EV_L2_T200, NULL, 1))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 1");
+static void
+l2_mdl_error(struct FsmInst *fi, int event, void *arg)
+{
+ struct sk_buff *skb = arg;
+ struct PStack *st = fi->userdata;
+ switch (event) {
+ case EV_L2_UA:
+ if (get_PollFlagFree(st, skb))
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'C');
+ else
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'D');
+ break;
+ case EV_L2_DM:
+ if (get_PollFlagFree(st, skb))
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'B');
+ else {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'E');
+ establishlink(fi);
+ test_and_clear_bit(FLG_L3_INIT, &st->l2.flag);
+ }
+ break;
+ }
+}
- cmd = (st->l2.extended ? SABME : SABM) | 0x10;
- send_uframe(st, cmd, CMD);
+static void
+l2_dl_establish(struct FsmInst *fi, int event, void *arg)
+{
+ struct PStack *st = fi->userdata;
+ int state = fi->state;
+
+ FsmChangeState(fi, ST_L2_3);
+ if (state == ST_L2_1)
+ st->l2.l2tei(st, MDL_ASSIGN_IND, NULL);
}
static void
-l2_establish(struct FsmInst *fi, int event, void *arg)
+l2_send_ui(struct PStack *st)
{
- establishlink(fi);
+ struct sk_buff *skb;
+ u_char header[MAX_HEADER_LEN];
+ int i;
+
+ i = sethdraddr(&(st->l2), header, CMD);
+ header[i++] = UI;
+ while ((skb = skb_dequeue(&st->l2.ui_queue))) {
+ memcpy(skb_push(skb, i), header, i);
+ enqueue_ui(st, skb);
+ }
}
static void
-l2_send_disconn(struct FsmInst *fi, int event, void *arg)
+l2_put_ui(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
- struct Channel *chanp = st->l4.userdata;
-
- FsmChangeState(fi, ST_L2_6);
+ struct sk_buff *skb = arg;
- FsmDelTimer(&st->l2.t203_timer, 1);
- if (st->l2.t200_running) {
- FsmDelTimer(&st->l2.t200_timer, 2);
- st->l2.t200_running = 0;
+ skb_queue_tail(&st->l2.ui_queue, skb);
+ if (fi->state == ST_L2_1) {
+ FsmChangeState(fi, ST_L2_2);
+ st->l2.l2tei(st, MDL_ASSIGN_IND, NULL);
}
- st->l2.rc = 0;
- if (FsmAddTimer(&st->l2.t200_timer, st->l2.t200, EV_L2_T200, NULL, 2))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 2");
+ if (fi->state > ST_L2_3)
+ l2_send_ui(st);
+}
+static void
+l2_got_ui(struct FsmInst *fi, int event, void *arg)
+{
+ struct PStack *st = fi->userdata;
+ struct sk_buff *skb = arg;
- if (!((chanp->impair == 2) && (st->l2.laptype == LAPB)))
- send_uframe(st, DISC | 0x10, CMD);
+ skb_pull(skb, l2headersize(&st->l2, 1));
+ if (skb->len > st->l2.maxlen) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'O');
+ FreeSkb(skb);
+ } else
+ st->l2.l2l3(st, DL_UNIT_DATA, skb);
+}
+
+static void
+l2_establish(struct FsmInst *fi, int event, void *arg)
+{
+ struct PStack *st = fi->userdata;
+
+ if (fi->state != ST_L2_4)
+ discard_i_queue(st);
+ if (fi->state != ST_L2_5)
+ establishlink(fi);
+ test_and_set_bit(FLG_L3_INIT, &st->l2.flag);
+}
+
+static void
+l2_dl_release(struct FsmInst *fi, int event, void *arg)
+{
+ struct PStack *st = fi->userdata;
+ if (fi->state == ST_L2_4) {
+ st->l2.l2man(st, DL_RELEASE, NULL);
+ return;
+ } else if (fi->state == ST_L2_5) {
+ test_and_set_bit(FLG_PEND_REL, &st->l2.flag);
+ return;
+ }
discard_i_queue(st);
+ FsmChangeState(fi, ST_L2_6);
+ st->l2.rc = 0;
+ send_uframe(st, DISC | 0x10, CMD);
+ FsmDelTimer(&st->l2.t203, 1);
+ FsmRestartTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 2);
+ test_and_set_bit(FLG_T200_RUN, &st->l2.flag);
}
static void
@@ -361,46 +502,59 @@
{
struct PStack *st = fi->userdata;
struct sk_buff *skb = arg;
- int est = 1, state;
+ int est = 1, state, rsp;
u_char PollFlag;
state = fi->state;
-
- skb_pull(skb, l2addrsize(&(st->l2)));
- PollFlag = *skb->data & 0x10;
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
-
- if (ST_L2_4 != state)
+ rsp = *skb->data & 0x2;
+ if (test_bit(FLG_ORIG, &st->l2.flag))
+ rsp = !rsp;
+ if (rsp) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'L');
+ FreeSkb(skb);
+ if ((state == ST_L2_7) || (state == ST_L2_8))
+ establishlink(fi);
+ return;
+ }
+ if (skb->len != (l2addrsize(&st->l2) + 1)) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ if ((state == ST_L2_7) || (state == ST_L2_8))
+ establishlink(fi);
+ return;
+ }
+ PollFlag = get_PollFlagFree(st, skb);
+ if (ST_L2_6 == state) {
+ send_uframe(st, DM | PollFlag, RSP);
+ return;
+ } else
+ send_uframe(st, UA | PollFlag, RSP);
+ if (ST_L2_5 == state)
+ return;
+ if (ST_L2_4 != state) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'F');
if (st->l2.vs != st->l2.va) {
discard_i_queue(st);
est = 1;
} else
est = 0;
-
+ }
+ clear_exception(&st->l2);
st->l2.vs = 0;
st->l2.va = 0;
st->l2.vr = 0;
st->l2.sow = 0;
- if (ST_L2_7 != state)
- FsmChangeState(fi, ST_L2_7);
-
- send_uframe(st, UA | PollFlag, RSP);
-
- if (st->l2.t200_running) {
- FsmDelTimer(&st->l2.t200_timer, 15);
- st->l2.t200_running = 0;
- }
- if (FsmAddTimer(&st->l2.t203_timer, st->l2.t203, EV_L2_T203, NULL, 3))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 3");
+ FsmChangeState(fi, ST_L2_7);
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 2);
+ FsmAddTimer(&st->l2.t203, st->l2.T203, EV_L2_T203, NULL, 3);
if (est)
st->l2.l2man(st, DL_ESTABLISH, NULL);
if (ST_L2_8 == state)
if (skb_queue_len(&st->l2.i_queue) && cansend(st))
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
+ st->l2.l2l1(st, PH_PULL_REQ, NULL);
}
static void
@@ -408,87 +562,152 @@
{
struct PStack *st = fi->userdata;
struct sk_buff *skb = arg;
- struct Channel *chanp = st->l4.userdata;
- u_char PollFlag;
+ u_char PollFlag, cmd = UA;
+ int state, rel = 1, cst = 1, rsp;
- skb_pull(skb, l2addrsize(&(st->l2)));
- PollFlag = *skb->data & 0x10;
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
-
- FsmChangeState(fi, ST_L2_4);
+ state = fi->state;
+ rsp = *skb->data & 0x2;
+ if (test_bit(FLG_ORIG, &st->l2.flag))
+ rsp = !rsp;
- FsmDelTimer(&st->l2.t203_timer, 3);
- if (st->l2.t200_running) {
- FsmDelTimer(&st->l2.t200_timer, 4);
- st->l2.t200_running = 0;
+ if (rsp) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'L');
+ FreeSkb(skb);
+ if ((state == ST_L2_7) || (state == ST_L2_8))
+ establishlink(fi);
+ return;
+ }
+ if (skb->len != (l2addrsize(&st->l2) + 1)) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ if ((state == ST_L2_7) || (state == ST_L2_8))
+ establishlink(fi);
+ return;
}
- if (!((chanp->impair == 1) && (st->l2.laptype == LAPB)))
- send_uframe(st, UA | PollFlag, RSP);
-
- st->l2.l2man(st, DL_RELEASE, NULL);
+ PollFlag = get_PollFlagFree(st, skb);
+ if ((state == ST_L2_4) || (state == ST_L2_5)) {
+ rel = 0;
+ cst = 0;
+ cmd = DM;
+ } else if (state == ST_L2_6) {
+ rel = 0;
+ cst = 0;
+ }
+ if (cst) {
+ FsmChangeState(fi, ST_L2_4);
+ FsmDelTimer(&st->l2.t203, 3);
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 2);
+ }
+ send_uframe(st, cmd | PollFlag, RSP);
+ if (rel)
+ st->l2.l2man(st, DL_RELEASE, NULL);
}
+
static void
-l2_got_st4_disc(struct FsmInst *fi, int event, void *arg)
+l2_got_ua(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
struct sk_buff *skb = arg;
- struct Channel *chanp = st->l4.userdata;
- u_char PollFlag;
+ u_char PollFlag, est = 1;
+ int state,rsp;
- skb_pull(skb, l2addrsize(&(st->l2)));
- PollFlag = *skb->data & 0x10;
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
+ state = fi->state;
+ rsp = *skb->data & 0x2;
+ if (test_bit(FLG_ORIG, &st->l2.flag))
+ rsp = !rsp;
- if (!((chanp->impair == 1) && (st->l2.laptype == LAPB)))
- send_uframe(st, DM | (PollFlag ? 0x10 : 0x0), RSP);
+ if (!rsp) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'L');
+ FreeSkb(skb);
+ if ((state == ST_L2_7) || (state == ST_L2_8))
+ establishlink(fi);
+ return;
+ }
+ if (skb->len != (l2addrsize(&st->l2) + 1)) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ if ((fi->state == ST_L2_7) || (fi->state == ST_L2_8))
+ establishlink(fi);
+ return;
+ }
+ PollFlag = get_PollFlag(st, skb);
+ if (!PollFlag) {
+ l2_mdl_error(fi, event, arg);
+ return;
+ }
+ FreeSkb(skb);
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 2);
+ if (fi->state == ST_L2_5) {
+ if (test_and_clear_bit(FLG_PEND_REL, &st->l2.flag)) {
+ discard_i_queue(st);
+ st->l2.rc = 0;
+ send_uframe(st, DISC | 0x10, CMD);
+ FsmChangeState(fi, ST_L2_6);
+ FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 4);
+ test_and_set_bit(FLG_T200_RUN, &st->l2.flag);
+ } else {
+ if (!test_and_clear_bit(FLG_L3_INIT, &st->l2.flag))
+ if (st->l2.vs != st->l2.va)
+ discard_i_queue(st);
+ else
+ est = 0;
+ st->l2.vs = 0;
+ st->l2.va = 0;
+ st->l2.vr = 0;
+ st->l2.sow = 0;
+ FsmChangeState(fi, ST_L2_7);
+ FsmAddTimer(&st->l2.t203, st->l2.T203, EV_L2_T203, NULL, 4);
+ if (est)
+ st->l2.l2man(st, DL_ESTABLISH, NULL);
+ }
+ } else { /* ST_L2_6 */
+ st->l2.l2man(st, DL_RELEASE, NULL);
+ FsmChangeState(fi, ST_L2_4);
+ }
}
static void
-l2_got_ua_establish(struct FsmInst *fi, int event, void *arg)
+l2_got_dm(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
struct sk_buff *skb = arg;
- u_char f;
+ u_char PollFlag;
+ int state,rsp;
- skb_pull(skb, l2addrsize(&(st->l2)));
- f = *skb->data & 0x10;
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
- if (f) {
- st->l2.vs = 0;
- st->l2.va = 0;
- st->l2.vr = 0;
- st->l2.sow = 0;
- FsmChangeState(fi, ST_L2_7);
-
- FsmDelTimer(&st->l2.t200_timer, 5);
- if (FsmAddTimer(&st->l2.t203_timer, st->l2.t203, EV_L2_T203, NULL, 4))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 4");
+ state = fi->state;
+ rsp = *skb->data & 0x2;
+ if (test_bit(FLG_ORIG, &st->l2.flag))
+ rsp = !rsp;
- st->l2.l2man(st, DL_ESTABLISH, NULL);
+ if (!rsp) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'L');
+ FreeSkb(skb);
+ if ((state == ST_L2_7) || (state == ST_L2_8))
+ establishlink(fi);
+ return;
+ }
+ if (skb->len != (l2addrsize(&st->l2) + 1)) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ if ((fi->state == ST_L2_7) || (fi->state == ST_L2_8))
+ establishlink(fi);
+ return;
}
-}
-
-static void
-l2_got_ua_disconn(struct FsmInst *fi, int event, void *arg)
-{
- struct PStack *st = fi->userdata;
- struct sk_buff *skb = arg;
- u_char f;
-
- skb_pull(skb, l2addrsize(&(st->l2)));
- f = *skb->data & 0x10;
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
- if (f) {
- FsmDelTimer(&st->l2.t200_timer, 6);
- FsmChangeState(fi, ST_L2_4);
+ PollFlag = get_PollFlagFree(st, skb);
+ if (!PollFlag) {
+ establishlink(fi);
+ test_and_clear_bit(FLG_L3_INIT, &st->l2.flag);
+ } else {
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 2);
+ if (fi->state == ST_L2_5 && !test_bit(FLG_L3_INIT, &st->l2.flag))
+ discard_i_queue(st);
st->l2.l2man(st, DL_RELEASE, NULL);
+ FsmChangeState(fi, ST_L2_4);
}
}
@@ -502,7 +721,7 @@
l2 = &st->l2;
i = sethdraddr(l2, tmp, cr);
- if (l2->extended) {
+ if (test_bit(FLG_MOD128, &l2->flag)) {
tmp[i++] = typ;
tmp[i++] = (l2->vr << 1) | (pf ? 1 : 0);
} else
@@ -516,77 +735,133 @@
}
inline void
-enquiry_response(struct PStack *st, u_char typ, u_char final)
+enquiry_response(struct PStack *st)
{
- enquiry_cr(st, typ, RSP, final);
+ if (test_bit(FLG_OWN_BUSY, &st->l2.flag))
+ enquiry_cr(st, RNR, RSP, 1);
+ else
+ enquiry_cr(st, RR, RSP, 1);
+ test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag);
}
inline void
-enquiry_command(struct PStack *st, u_char typ, u_char poll)
+transmit_enquiry(struct PStack *st)
{
- enquiry_cr(st, typ, CMD, poll);
+ if (test_bit(FLG_OWN_BUSY, &st->l2.flag))
+ enquiry_cr(st, RNR, CMD, 1);
+ else
+ enquiry_cr(st, RR, CMD, 1);
+ test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag);
+ FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 12);
+ test_and_set_bit(FLG_T200_RUN, &st->l2.flag);
}
+
static void
nrerrorrecovery(struct FsmInst *fi)
{
- /* should log error here */
+ struct PStack *st = fi->userdata;
+
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'J');
establishlink(fi);
}
static void
-l2_got_st7_RR(struct FsmInst *fi, int event, void *arg)
+invoke_retransmission(struct PStack *st, int nr)
+{
+ struct Layer2 *l2 = &st->l2;
+ int p1;
+ long flags;
+
+ if (l2->vs != nr) {
+ save_flags(flags);
+ cli();
+ while (l2->vs != nr) {
+ l2->vs = l2->vs - 1;
+ if (l2->vs < 0)
+ l2->vs += (test_bit(FLG_MOD128, &l2->flag) ? 128 : 8);
+ p1 = l2->vs - l2->va;
+ if (p1 < 0)
+ p1 += (test_bit(FLG_MOD128, &l2->flag) ? 128 : 8);
+ p1 = (p1 + l2->sow) % l2->window;
+ skb_queue_head(&l2->i_queue, l2->windowar[p1]);
+ l2->windowar[p1] = NULL;
+ }
+ restore_flags(flags);
+ st->l2.l2l1(st, PH_PULL_REQ, NULL);
+ }
+}
+
+static void
+l2_got_st7_super(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
- struct Channel *chanp = st->l4.userdata;
struct sk_buff *skb = arg;
- int PollFlag, seq, rsp;
- struct Layer2 *l2;
+ int PollFlag, nr, rsp, typ = RR;
+ struct Layer2 *l2 = &st->l2;
- l2 = &st->l2;
- if (l2->laptype == LAPD)
- rsp = *skb->data & 0x2;
- else
- rsp = *skb->data == 0x3;
- if (l2->orig)
+ rsp = *skb->data & 0x2;
+ if (test_bit(FLG_ORIG, &l2->flag))
rsp = !rsp;
skb_pull(skb, l2addrsize(l2));
- if (l2->extended) {
- PollFlag = (skb->data[1] & 0x1) == 0x1;
- seq = skb->data[1] >> 1;
+ if (IsRNR(skb->data, test_bit(FLG_MOD128, &l2->flag))) {
+ test_and_set_bit(FLG_PEER_BUSY, &l2->flag);
+ typ = RNR;
+ } else
+ test_and_clear_bit(FLG_PEER_BUSY, &l2->flag);
+ if (IsREJ(skb->data, test_bit(FLG_MOD128, &l2->flag)))
+ typ = REJ;
+ if (test_bit(FLG_MOD128, &l2->flag)) {
+ if (skb->len == 2) {
+ PollFlag = (skb->data[1] & 0x1) == 0x1;
+ nr = skb->data[1] >> 1;
+ } else {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ establishlink(fi);
+ return;
+ }
} else {
- PollFlag = (skb->data[0] & 0x10);
- seq = (skb->data[0] >> 5) & 0x7;
+ if (skb->len == 1) {
+ PollFlag = (skb->data[0] & 0x10);
+ nr = (skb->data[0] >> 5) & 0x7;
+ } else {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ establishlink(fi);
+ return;
+ }
}
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
+ FreeSkb(skb);
- if (!((chanp->impair == 4) && (st->l2.laptype == LAPB)))
- if ((!rsp) && PollFlag)
- enquiry_response(st, RR, PollFlag);
-
- if (legalnr(st, seq)) {
- if (seq == l2->vs) {
- setva(st, seq);
- FsmDelTimer(&l2->t200_timer, 7);
- l2->t200_running = 0;
- FsmDelTimer(&l2->t203_timer, 8);
- if (FsmAddTimer(&l2->t203_timer, l2->t203, EV_L2_T203, NULL, 5))
- if (l2->l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 5");
-
- if (skb_queue_len(&st->l2.i_queue))
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
- } else if (l2->va != seq) {
- setva(st, seq);
- FsmDelTimer(&st->l2.t200_timer, 9);
- if (FsmAddTimer(&st->l2.t200_timer, st->l2.t200, EV_L2_T200, NULL, 6))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 6");
- if (skb_queue_len(&st->l2.i_queue))
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
+ if ((!rsp) && PollFlag)
+ enquiry_response(st);
+ if (rsp && PollFlag)
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'A');
+ if (legalnr(st, nr)) {
+ if (typ == REJ) {
+ setva(st, nr);
+ invoke_retransmission(st, nr);
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 9);
+ if (FsmAddTimer(&st->l2.t203, st->l2.T203,
+ EV_L2_T203, NULL, 6))
+ l2m_debug(&st->l2.l2m, "Restart T203 ST7 REJ");
+ } else if ((nr == l2->vs) && (typ == RR)) {
+ setva(st, nr);
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 9);
+ FsmRestartTimer(&st->l2.t203, st->l2.T203,
+ EV_L2_T203, NULL, 7);
+ } else if ((l2->va != nr) || (typ == RNR)) {
+ setva(st, nr);
+ FsmDelTimer(&st->l2.t203, 9);
+ FsmRestartTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 6);
+ test_and_set_bit(FLG_T200_RUN, &st->l2.flag);
}
+ if (skb_queue_len(&st->l2.i_queue) && (typ == RR))
+ st->l2.l2l1(st, PH_PULL_REQ, NULL);
} else
nrerrorrecovery(fi);
@@ -602,122 +877,121 @@
struct PStack *st = fi->userdata;
struct sk_buff *skb = arg;
- skb_queue_tail(&st->l2.i_queue, skb);
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
+ if (test_bit(FLG_LAPB, &st->l2.flag))
+ st->l1.bcs->tx_cnt += skb->len + l2headersize(&st->l2, 0);
+ if (!((fi->state == ST_L2_5) && test_bit(FLG_L3_INIT, &st->l2.flag)))
+ skb_queue_tail(&st->l2.i_queue, skb);
+ if (fi->state == ST_L2_7)
+ st->l2.l2l1(st, PH_PULL_REQ, NULL);
}
-static int
-icommandreceived(struct FsmInst *fi, int event, void *arg, int *nr)
+static void
+l2_got_iframe(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
- struct Channel *chanp = st->l4.userdata;
struct sk_buff *skb = arg;
struct IsdnCardState *sp = st->l1.hardware;
struct Layer2 *l2 = &(st->l2);
- int i, p, seq, wasok;
+ int PollFlag, ns, nr, i, hs, rsp;
char str[64];
+ rsp = *skb->data & 0x2;
+ if (test_bit(FLG_ORIG, &l2->flag))
+ rsp = !rsp;
+
+ if (rsp) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'L');
+ FreeSkb(skb);
+ establishlink(fi);
+ return;
+ }
i = l2addrsize(l2);
- if (l2->extended) {
- p = (skb->data[i + 1] & 0x1) == 0x1;
- seq = skb->data[i] >> 1;
- *nr = (skb->data[i + 1] >> 1) & 0x7f;
+ if (test_bit(FLG_MOD128, &l2->flag)) {
+ if (skb->len <= (i + 1)) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ establishlink(fi);
+ return;
+ } else if ((skb->len - i - 1) > l2->maxlen) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'O');
+ FreeSkb(skb);
+ establishlink(fi);
+ return;
+ }
+ PollFlag = ((skb->data[i + 1] & 0x1) == 0x1);
+ ns = skb->data[i] >> 1;
+ nr = (skb->data[i + 1] >> 1) & 0x7f;
} else {
- p = (skb->data[i] & 0x10);
- seq = (skb->data[i] >> 1) & 0x7;
- *nr = (skb->data[i] >> 5) & 0x7;
- }
-
- if (l2->vr == seq) {
- wasok = !0;
-
- l2->vr = (l2->vr + 1) % (l2->extended ? 128 : 8);
- l2->rejexp = 0;
-
- if (st->l2.laptype == LAPD)
+ if (skb->len <= i) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ establishlink(fi);
+ return;
+ } else if ((skb->len - i) > l2->maxlen) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'O');
+ FreeSkb(skb);
+ establishlink(fi);
+ return;
+ }
+ PollFlag = (skb->data[i] & 0x10);
+ ns = (skb->data[i] >> 1) & 0x7;
+ nr = (skb->data[i] >> 5) & 0x7;
+ }
+ if (test_bit(FLG_OWN_BUSY, &l2->flag)) {
+ FreeSkb(skb);
+ enquiry_response(st);
+ } else if (l2->vr == ns) {
+ l2->vr = (l2->vr + 1) % (test_bit(FLG_MOD128, &l2->flag) ? 128 : 8);
+ test_and_clear_bit(FLG_REJEXC, &l2->flag);
+ if (test_bit(FLG_LAPD, &l2->flag))
if (sp->dlogflag) {
+ hs = l2headersize(l2, 0);
LogFrame(st->l1.hardware, skb->data, skb->len);
sprintf(str, "Q.931 frame network->user tei %d", st->l2.tei);
- dlogframe(st->l1.hardware, skb->data + l2->ihsize,
- skb->len - l2->ihsize, str);
+ dlogframe(st->l1.hardware, skb->data + hs,
+ skb->len - hs, str);
}
- if (!((chanp->impair == 3) && (st->l2.laptype == LAPB)))
- if (p || (!skb_queue_len(&st->l2.i_queue)))
- enquiry_response(st, RR, p);
+ if (PollFlag)
+ enquiry_response(st);
+ else
+ test_and_set_bit(FLG_ACK_PEND, &l2->flag);
skb_pull(skb, l2headersize(l2, 0));
+ st->l2.l2l3(st, DL_DATA, skb);
} else {
/* n(s)!=v(r) */
- wasok = 0;
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
- if (st->l2.rejexp) {
- if (p)
- if (!((chanp->impair == 3) && (st->l2.laptype == LAPB)))
- enquiry_response(st, RR, p);
+ FreeSkb(skb);
+ if (test_and_set_bit(FLG_REJEXC, &l2->flag)) {
+ if (PollFlag)
+ enquiry_response(st);
} else {
- st->l2.rejexp = !0;
- enquiry_command(st, REJ, 1);
+ enquiry_cr(st, REJ, RSP, PollFlag);
+ test_and_clear_bit(FLG_ACK_PEND, &l2->flag);
}
}
- return wasok;
-}
-
-static void
-l2_got_st7_data(struct FsmInst *fi, int event, void *arg)
-{
- struct PStack *st = fi->userdata;
- struct sk_buff *skb = arg;
- int nr, wasok;
-
- wasok = icommandreceived(fi, event, arg, &nr);
-
- if (legalnr(st, nr)) {
- if (nr == st->l2.vs) {
- setva(st, nr);
- FsmDelTimer(&st->l2.t200_timer, 10);
- st->l2.t200_running = 0;
- FsmDelTimer(&st->l2.t203_timer, 11);
- if (FsmAddTimer(&st->l2.t203_timer, st->l2.t203, EV_L2_T203, NULL, 7))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 5");
-
- if (skb_queue_len(&st->l2.i_queue))
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
- } else if (nr != st->l2.va) {
- setva(st, nr);
- FsmDelTimer(&st->l2.t200_timer, 12);
- if (FsmAddTimer(&st->l2.t200_timer, st->l2.t200, EV_L2_T200, NULL, 8))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 6");
-
- if (skb_queue_len(&st->l2.i_queue))
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
- }
- } else
- nrerrorrecovery(fi);
-
- if (wasok)
- st->l2.l2l3(st, DL_DATA, skb);
-}
-
-static void
-l2_got_st8_data(struct FsmInst *fi, int event, void *arg)
-{
- struct PStack *st = fi->userdata;
- struct sk_buff *skb = arg;
- int nr, wasok;
-
- wasok = icommandreceived(fi, event, arg, &nr);
if (legalnr(st, nr)) {
setva(st, nr);
- if (skb_queue_len(&st->l2.i_queue))
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
- } else
+ if (!test_bit(FLG_PEER_BUSY, &st->l2.flag) && (fi->state == ST_L2_7)) {
+ if (nr == st->l2.vs) {
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 10);
+ FsmRestartTimer(&st->l2.t203, st->l2.T203,
+ EV_L2_T203, NULL, 7);
+ } else if (nr != st->l2.va) {
+ FsmRestartTimer(&st->l2.t200, st->l2.T200, EV_L2_T200,
+ NULL, 8);
+ test_and_set_bit(FLG_T200_RUN, &st->l2.flag);
+ }
+ }
+ } else {
nrerrorrecovery(fi);
+ return;
+ }
- if (wasok)
- st->l2.l2l3(st, DL_DATA, skb);
+ if (skb_queue_len(&st->l2.i_queue) && (fi->state == ST_L2_7))
+ st->l2.l2l1(st, PH_PULL_REQ, NULL);
+ if (test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag))
+ enquiry_cr(st, RR, RSP, 0);
}
static void
@@ -726,69 +1000,14 @@
struct PStack *st = fi->userdata;
st->l2.tei = (int) arg;
- establishlink(fi);
-}
-
-static void
-invoke_retransmission(struct PStack *st, int nr)
-{
- struct Layer2 *l2 = &st->l2;
- int p1;
-
- if (l2->vs != nr) {
- while (l2->vs != nr) {
-
- l2->vs = l2->vs - 1;
- if (l2->vs < 0)
- l2->vs += l2->extended ? 128 : 8;
-
- p1 = l2->vs - l2->va;
- if (p1 < 0)
- p1 += l2->extended ? 128 : 8;
- p1 = (p1 + l2->sow) % l2->window;
-
- skb_queue_head(&l2->i_queue, l2->windowar[p1]);
- l2->windowar[p1] = NULL;
- }
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
- }
-}
-
-static void
-l2_got_st7_rej(struct FsmInst *fi, int event, void *arg)
-{
- struct PStack *st = fi->userdata;
- struct sk_buff *skb = arg;
- int PollFlag, seq, rsp;
- struct Layer2 *l2;
-
- l2 = &st->l2;
- if (l2->laptype == LAPD)
- rsp = *skb->data & 0x2;
- else
- rsp = *skb->data == 0x3;
- if (l2->orig)
- rsp = !rsp;
-
- skb_pull(skb, l2addrsize(l2));
- if (l2->extended) {
- PollFlag = (skb->data[1] & 0x1) == 0x1;
- seq = skb->data[1] >> 1;
- } else {
- PollFlag = (skb->data[0] & 0x10);
- seq = (skb->data[0] >> 5) & 0x7;
- }
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
-
- if ((!rsp) && PollFlag)
- enquiry_response(st, RR, PollFlag);
- if (!legalnr(st, seq))
- return;
-
- setva(st, seq);
- invoke_retransmission(st, seq);
+ if (fi->state == ST_L2_3) {
+ establishlink(fi);
+ test_and_set_bit(FLG_L3_INIT, &st->l2.flag);
+ } else
+ FsmChangeState(fi, ST_L2_4);
+ if (skb_queue_len(&st->l2.ui_queue))
+ l2_send_ui(st);
}
static void
@@ -801,21 +1020,21 @@
l2_st5_tout_200(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
- u_char cmd;
- if (st->l2.rc == st->l2.n200) {
+ if (test_bit(FLG_LAPD, &st->l2.flag) &&
+ test_bit(FLG_DCHAN_BUSY, &st->l2.flag)) {
+ FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 9);
+ } else if (st->l2.rc == st->l2.N200) {
FsmChangeState(fi, ST_L2_4);
- st->l2.l2tei(st, MDL_VERIFY, (void *) st->l2.tei);
+ test_and_clear_bit(FLG_T200_RUN, &st->l2.flag);
+ discard_i_queue(st);
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'G');
st->l2.l2man(st, DL_RELEASE, NULL);
} else {
st->l2.rc++;
-
- if (FsmAddTimer(&st->l2.t200_timer, st->l2.t200, EV_L2_T200, NULL, 9))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 7");
-
- cmd = (st->l2.extended ? SABME : SABM) | 0x10;
- send_uframe(st, cmd, CMD);
+ FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 9);
+ send_uframe(st, (test_bit(FLG_MOD128, &st->l2.flag) ? SABME : SABM)
+ | 0x10, CMD);
}
}
@@ -823,30 +1042,65 @@
l2_st6_tout_200(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
- struct Channel *chanp = st->l4.userdata;
- if (st->l2.rc == st->l2.n200) {
+ if (test_bit(FLG_LAPD, &st->l2.flag) &&
+ test_bit(FLG_DCHAN_BUSY, &st->l2.flag)) {
+ FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 9);
+ } else if (st->l2.rc == st->l2.N200) {
FsmChangeState(fi, ST_L2_4);
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'H');
st->l2.l2man(st, DL_RELEASE, NULL);
} else {
st->l2.rc++;
+ FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200,
+ NULL, 9);
+ send_uframe(st, DISC | 0x10, CMD);
+ }
+}
- if (FsmAddTimer(&st->l2.t200_timer, st->l2.t200, EV_L2_T200, NULL, 10))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 8");
+static void
+l2_st78_tout_200(struct FsmInst *fi, int event, void *arg)
+{
+ struct PStack *st = fi->userdata;
+ if (test_bit(FLG_LAPD, &st->l2.flag) &&
+ test_bit(FLG_DCHAN_BUSY, &st->l2.flag)) {
+ FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 9);
+ return;
+ }
+ test_and_clear_bit(FLG_T200_RUN, &st->l2.flag);
+ if (fi->state == ST_L2_7) {
+ st->l2.rc = 0;
+ FsmChangeState(fi, ST_L2_8);
+ }
+ if (st->l2.rc == st->l2.N200) {
+ establishlink(fi);
+ } else {
+ transmit_enquiry(st);
+ st->l2.rc++;
+ }
+}
- if (!((chanp->impair == 2) && (st->l2.laptype == LAPB)))
- send_uframe(st, DISC | 0x10, CMD);
+static void
+l2_st7_tout_203(struct FsmInst *fi, int event, void *arg)
+{
+ struct PStack *st = fi->userdata;
+ if (test_bit(FLG_LAPD, &st->l2.flag) &&
+ test_bit(FLG_DCHAN_BUSY, &st->l2.flag)) {
+ FsmAddTimer(&st->l2.t203, st->l2.T203, EV_L2_T203, NULL, 9);
+ return;
}
+ FsmChangeState(fi, ST_L2_8);
+ transmit_enquiry(st);
+ st->l2.rc = 0;
}
static void
l2_pull_iqueue(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
- struct sk_buff *skb;
+ struct sk_buff *skb, *oskb;
struct Layer2 *l2 = &st->l2;
u_char header[MAX_HEADER_LEN];
int p1, i;
@@ -860,19 +1114,18 @@
p1 = l2->vs - l2->va;
if (p1 < 0)
- p1 += l2->extended ? 128 : 8;
+ p1 += test_bit(FLG_MOD128, &l2->flag) ? 128 : 8;
p1 = (p1 + l2->sow) % l2->window;
if (l2->windowar[p1]) {
printk(KERN_WARNING "isdnl2 try overwrite ack queue entry %d\n",
p1);
- SET_SKB_FREE(l2->windowar[p1]);
dev_kfree_skb(l2->windowar[p1]);
}
l2->windowar[p1] = skb_clone(skb, GFP_ATOMIC);
i = sethdraddr(&st->l2, header, CMD);
- if (l2->extended) {
+ if (test_bit(FLG_MOD128, &l2->flag)) {
header[i++] = l2->vs << 1;
header[i++] = l2->vr << 1;
l2->vs = (l2->vs + 1) % 128;
@@ -880,88 +1133,86 @@
header[i++] = (l2->vr << 5) | (l2->vs << 1);
l2->vs = (l2->vs + 1) % 8;
}
-
- memcpy(skb_push(skb, i), header, i);
- st->l2.l2l1(st, PH_DATA_PULLED, skb);
- if (!st->l2.t200_running) {
- FsmDelTimer(&st->l2.t203_timer, 13);
- if (FsmAddTimer(&st->l2.t200_timer, st->l2.t200, EV_L2_T200, NULL, 11))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 9");
-
- st->l2.t200_running = !0;
+ p1 = skb->data - skb->head;
+ if (p1 >= i)
+ memcpy(skb_push(skb, i), header, i);
+ else {
+ printk(KERN_WARNING
+ "isdl2 pull_iqueue skb header(%d/%d) too short\n", i, p1);
+ oskb = skb;
+ skb = alloc_skb(oskb->len + i, GFP_ATOMIC);
+ memcpy(skb_put(skb, i), header, i);
+ memcpy(skb_put(skb, oskb->len), oskb->data, oskb->len);
+ FreeSkb(oskb);
+ }
+ st->l2.l2l1(st, PH_PULL_IND, skb);
+ test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag);
+ if (!test_and_set_bit(FLG_T200_RUN, &st->l2.flag)) {
+ FsmDelTimer(&st->l2.t203, 13);
+ FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 11);
}
if (skb_queue_len(&l2->i_queue) && cansend(st))
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
+ st->l2.l2l1(st, PH_PULL_REQ, NULL);
}
static void
-transmit_enquiry(struct PStack *st)
-{
-
- enquiry_command(st, RR, 1);
- if (FsmAddTimer(&st->l2.t200_timer, st->l2.t200, EV_L2_T200, NULL, 12))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 10");
-
- st->l2.t200_running = !0;
-}
-
-static void
-l2_st7_tout_200(struct FsmInst *fi, int event, void *arg)
-{
- struct PStack *st = fi->userdata;
-
- st->l2.t200_running = 0;
-
- st->l2.rc = 1;
- FsmChangeState(fi, ST_L2_8);
- transmit_enquiry(st);
-}
-
-static void
-l2_got_st8_rr_rej(struct FsmInst *fi, int event, void *arg)
+l2_got_st8_super(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
struct sk_buff *skb = arg;
- int PollFlag, seq, rsp;
- struct Layer2 *l2;
+ int PollFlag, nr, rsp, rnr = 0;
+ struct Layer2 *l2 = &st->l2;
- l2 = &st->l2;
- if (l2->laptype == LAPD)
- rsp = *skb->data & 0x2;
- else
- rsp = *skb->data == 0x3;
- if (l2->orig)
+ rsp = *skb->data & 0x2;
+ if (test_bit(FLG_ORIG, &l2->flag))
rsp = !rsp;
-
skb_pull(skb, l2addrsize(l2));
- if (l2->extended) {
- PollFlag = (skb->data[1] & 0x1) == 0x1;
- seq = skb->data[1] >> 1;
+
+ if (IsRNR(skb->data, test_bit(FLG_MOD128, &l2->flag))) {
+ test_and_set_bit(FLG_PEER_BUSY, &l2->flag);
+ rnr = 1;
+ } else
+ test_and_clear_bit(FLG_PEER_BUSY, &l2->flag);
+ if (test_bit(FLG_MOD128, &l2->flag)) {
+ if (skb->len == 2) {
+ PollFlag = (skb->data[1] & 0x1) == 0x1;
+ nr = skb->data[1] >> 1;
+ } else {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ establishlink(fi);
+ return;
+ }
} else {
- PollFlag = (skb->data[0] & 0x10);
- seq = (skb->data[0] >> 5) & 0x7;
+ if (skb->len == 1) {
+ PollFlag = (skb->data[0] & 0x10);
+ nr = (skb->data[0] >> 5) & 0x7;
+ } else {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ establishlink(fi);
+ return;
+ }
}
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
+ FreeSkb(skb);
if (rsp && PollFlag) {
- if (legalnr(st, seq)) {
+ if (legalnr(st, nr)) {
+ setva(st, nr);
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 7);
+ FsmDelTimer(&l2->t203, 8);
+ if (rnr) {
+ FsmRestartTimer(&l2->t200, l2->T200,
+ EV_L2_T200, NULL, 14);
+ test_and_set_bit(FLG_T200_RUN, &st->l2.flag);
+ } else
+ FsmAddTimer(&l2->t203, l2->T203,
+ EV_L2_T203, NULL, 5);
+ invoke_retransmission(st, nr);
FsmChangeState(fi, ST_L2_7);
- setva(st, seq);
- if (st->l2.t200_running) {
- FsmDelTimer(&st->l2.t200_timer, 14);
- st->l2.t200_running = 0;
- }
- if (FsmAddTimer(&st->l2.t203_timer, st->l2.t203, EV_L2_T203, NULL, 13))
- if (st->l2.l2m.debug)
- l2m_debug(&st->l2.l2m, "FAT 11");
-
- invoke_retransmission(st, seq);
-
if (skb_queue_len(&l2->i_queue) && cansend(st))
- st->l2.l2l1(st, PH_REQUEST_PULL, NULL);
+ st->l2.l2l1(st, PH_PULL_REQ, NULL);
else if (fi->userint & LC_FLUSH_WAIT) {
fi->userint &= ~LC_FLUSH_WAIT;
st->l2.l2man(st, DL_FLUSH, NULL);
@@ -969,57 +1220,46 @@
}
} else {
if (!rsp && PollFlag)
- enquiry_response(st, RR, PollFlag);
- if (legalnr(st, seq)) {
- setva(st, seq);
+ enquiry_response(st);
+ if (legalnr(st, nr)) {
+ setva(st, nr);
}
}
}
static void
-l2_st7_tout_203(struct FsmInst *fi, int event, void *arg)
-{
- struct PStack *st = fi->userdata;
-
- st->l2.rc = 0;
- FsmChangeState(fi, ST_L2_8);
- transmit_enquiry(st);
-}
-
-static void
-l2_st8_tout_200(struct FsmInst *fi, int event, void *arg)
-{
- struct PStack *st = fi->userdata;
-
- if (st->l2.rc == st->l2.n200) {
- establishlink(fi);
- } else {
- st->l2.rc++;
- transmit_enquiry(st);
- }
-}
-
-static void
l2_got_FRMR(struct FsmInst *fi, int event, void *arg)
{
struct PStack *st = fi->userdata;
struct sk_buff *skb = arg;
char tmp[64];
- skb_pull(skb, l2addrsize(&st->l2));
- if (st->l2.l2m.debug) {
- if (st->l2.extended)
+ skb_pull(skb, l2addrsize(&st->l2) + 1);
+ if (test_bit(FLG_MOD128, &st->l2.flag)) {
+ if (skb->len < 5)
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ else {
sprintf(tmp, "FRMR information %2x %2x %2x %2x %2x",
skb->data[0], skb->data[1], skb->data[2],
skb->data[3], skb->data[4]);
- else
+ l2m_debug(&st->l2.l2m, tmp);
+ }
+ } else {
+ if (skb->len < 3)
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ else {
sprintf(tmp, "FRMR information %2x %2x %2x",
skb->data[0], skb->data[1], skb->data[2]);
-
- l2m_debug(&st->l2.l2m, tmp);
+ l2m_debug(&st->l2.l2m, tmp);
+ }
}
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
+ if (!(skb->data[0] & 1) || ((skb->data[0] & 3) == 1) || /* I or S */
+ (IsUA(skb->data, 0) && (fi->state == ST_L2_7))) {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'K');
+ establishlink(fi);
+ test_and_clear_bit(FLG_L3_INIT, &st->l2.flag);
+ }
+ FreeSkb(skb);
}
static void
@@ -1027,135 +1267,126 @@
{
struct PStack *st = fi->userdata;
-/*TODO
- if( DL_RELEASE.req outstanding ) {
- ... issue DL_RELEASE.confirm
- } else {
- if( fi->state != ST_L2_4 ) {
- ... issue DL_RELEASE.indication
- }
- }
- TODO */
- discard_i_queue(st); /* There is no UI queue in layer 2 */
- st->l2.tei = 255;
- if (st->l2.t200_running) {
- FsmDelTimer(&st->l2.t200_timer, 18);
- st->l2.t200_running = 0;
- }
- FsmDelTimer(&st->l2.t203_timer, 19);
- st->l2.l2man(st, DL_RELEASE, NULL); /* TEMP */
+ discard_i_queue(st);
+ discard_ui_queue(st);
+ st->l2.tei = -1;
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 18);
+ FsmDelTimer(&st->l2.t203, 19);
+ if (fi->state != ST_L2_4)
+ st->l2.l2man(st, DL_RELEASE, NULL);
FsmChangeState(fi, ST_L2_1);
}
-inline int
-IsUI(u_char * data, int ext)
-{
- return ((data[0] & 0xef) == UI);
-}
-
-inline int
-IsUA(u_char * data, int ext)
-{
- return ((data[0] & 0xef) == UA);
-}
-
-inline int
-IsDISC(u_char * data, int ext)
-{
- return ((data[0] & 0xef) == DISC);
-}
-
-inline int
-IsRR(u_char * data, int ext)
-{
- if (ext)
- return (data[0] == RR);
- else
- return ((data[0] & 0xf) == 1);
-}
-
-inline int
-IsI(u_char * data, int ext)
-{
- return ((data[0] & 0x1) == 0x0);
-}
-
-inline int
-IsSABMX(u_char * data, int ext)
+static void
+l2_persistant_da(struct FsmInst *fi, int event, void *arg)
{
- u_char d = data[0] & ~0x10;
+ struct PStack *st = fi->userdata;
- return (ext ? d == SABME : d == SABM);
-}
-
-inline int
-IsREJ(u_char * data, int ext)
-{
- return (ext ? data[0] == REJ : (data[0] & 0xf) == 0x9);
-}
-
-inline int
-IsFRMR(u_char * data, int ext)
-{
- return ((data[0] & 0xef) == FRMR);
-}
-
-inline int
-IsRNR(u_char * data, int ext)
-{
- if (ext)
- return (data[0] == RNR);
- else
- return ((data[0] & 0xf) == 5);
+ discard_i_queue(st);
+ discard_ui_queue(st);
+ if (test_and_clear_bit(FLG_T200_RUN, &st->l2.flag))
+ FsmDelTimer(&st->l2.t200, 18);
+ FsmDelTimer(&st->l2.t203, 19);
+ test_and_clear_bit(FLG_PEND_REL, &st->l2.flag);
+ clear_exception(&st->l2);
+ switch (fi->state) {
+ case ST_L2_3:
+ st->l2.l2man(st, DL_RELEASE, NULL);
+ case ST_L2_2:
+ FsmChangeState(fi, ST_L2_1);
+ break;
+ case ST_L2_5:
+ case ST_L2_6:
+ case ST_L2_7:
+ case ST_L2_8:
+ st->l2.l2man(st, DL_RELEASE, NULL);
+ FsmChangeState(fi, ST_L2_4);
+ break;
+ }
}
-static struct FsmNode L2FnList[] =
+static struct FsmNode L2FnList[] HISAX_INITDATA =
{
- {ST_L2_1, EV_L2_DL_ESTABLISH, l2s1},
{ST_L2_1, EV_L2_MDL_NOTEIPROC, l2_no_tei},
- {ST_L2_3, EV_L2_MDL_ASSIGN, l2_got_tei},
- {ST_L2_4, EV_L2_DL_UNIT_DATA, l2_send_ui},
+ {ST_L2_1, EV_L2_DL_ESTABLISH, l2_dl_establish},
+ {ST_L2_2, EV_L2_DL_ESTABLISH, l2_dl_establish},
{ST_L2_4, EV_L2_DL_ESTABLISH, l2_establish},
- {ST_L2_7, EV_L2_DL_UNIT_DATA, l2_send_ui},
+ {ST_L2_5, EV_L2_DL_ESTABLISH, l2_establish},
+ {ST_L2_7, EV_L2_DL_ESTABLISH, l2_establish},
+ {ST_L2_8, EV_L2_DL_ESTABLISH, l2_establish},
+ {ST_L2_4, EV_L2_DL_RELEASE, l2_dl_release},
+ {ST_L2_5, EV_L2_DL_RELEASE, l2_dl_release},
+ {ST_L2_7, EV_L2_DL_RELEASE, l2_dl_release},
+ {ST_L2_8, EV_L2_DL_RELEASE, l2_dl_release},
+ {ST_L2_5, EV_L2_DL_DATA, l2_feed_iqueue},
{ST_L2_7, EV_L2_DL_DATA, l2_feed_iqueue},
- {ST_L2_7, EV_L2_DL_RELEASE, l2_send_disconn},
- {ST_L2_7, EV_L2_ACK_PULL, l2_pull_iqueue},
{ST_L2_8, EV_L2_DL_DATA, l2_feed_iqueue},
- {ST_L2_8, EV_L2_DL_RELEASE, l2_send_disconn},
-
- {ST_L2_1, EV_L2_UI, l2_receive_ui},
- {ST_L2_4, EV_L2_UI, l2_receive_ui},
+ {ST_L2_1, EV_L2_DL_UNIT_DATA, l2_put_ui},
+ {ST_L2_2, EV_L2_DL_UNIT_DATA, l2_put_ui},
+ {ST_L2_3, EV_L2_DL_UNIT_DATA, l2_put_ui},
+ {ST_L2_4, EV_L2_DL_UNIT_DATA, l2_put_ui},
+ {ST_L2_5, EV_L2_DL_UNIT_DATA, l2_put_ui},
+ {ST_L2_6, EV_L2_DL_UNIT_DATA, l2_put_ui},
+ {ST_L2_7, EV_L2_DL_UNIT_DATA, l2_put_ui},
+ {ST_L2_8, EV_L2_DL_UNIT_DATA, l2_put_ui},
+ {ST_L2_1, EV_L2_MDL_ASSIGN, l2_got_tei},
+ {ST_L2_2, EV_L2_MDL_ASSIGN, l2_got_tei},
+ {ST_L2_3, EV_L2_MDL_ASSIGN, l2_got_tei},
+ {ST_L2_2, EV_L2_MDL_ERROR, l2_tei_remove},
+ {ST_L2_3, EV_L2_MDL_ERROR, l2_tei_remove},
+ {ST_L2_4, EV_L2_MDL_REMOVE, l2_tei_remove},
+ {ST_L2_5, EV_L2_MDL_REMOVE, l2_tei_remove},
+ {ST_L2_6, EV_L2_MDL_REMOVE, l2_tei_remove},
+ {ST_L2_7, EV_L2_MDL_REMOVE, l2_tei_remove},
+ {ST_L2_8, EV_L2_MDL_REMOVE, l2_tei_remove},
{ST_L2_4, EV_L2_SABMX, l2_got_SABMX},
- {ST_L2_4, EV_L2_DISC, l2_got_st4_disc},
- {ST_L2_5, EV_L2_UA, l2_got_ua_establish},
- {ST_L2_6, EV_L2_UA, l2_got_ua_disconn},
- {ST_L2_7, EV_L2_UI, l2_receive_ui},
- {ST_L2_7, EV_L2_DISC, l2_got_disconn},
- {ST_L2_7, EV_L2_I, l2_got_st7_data},
- {ST_L2_7, EV_L2_RR, l2_got_st7_RR},
- {ST_L2_7, EV_L2_REJ, l2_got_st7_rej},
+ {ST_L2_5, EV_L2_SABMX, l2_got_SABMX},
+ {ST_L2_6, EV_L2_SABMX, l2_got_SABMX},
{ST_L2_7, EV_L2_SABMX, l2_got_SABMX},
- {ST_L2_7, EV_L2_FRMR, l2_got_FRMR},
- {ST_L2_8, EV_L2_RR, l2_got_st8_rr_rej},
- {ST_L2_8, EV_L2_REJ, l2_got_st8_rr_rej},
{ST_L2_8, EV_L2_SABMX, l2_got_SABMX},
+ {ST_L2_4, EV_L2_DISC, l2_got_disconn},
+ {ST_L2_5, EV_L2_DISC, l2_got_disconn},
+ {ST_L2_6, EV_L2_DISC, l2_got_disconn},
+ {ST_L2_7, EV_L2_DISC, l2_got_disconn},
{ST_L2_8, EV_L2_DISC, l2_got_disconn},
+ {ST_L2_4, EV_L2_UA, l2_mdl_error},
+ {ST_L2_5, EV_L2_UA, l2_got_ua},
+ {ST_L2_6, EV_L2_UA, l2_got_ua},
+ {ST_L2_7, EV_L2_UA, l2_mdl_error},
+ {ST_L2_8, EV_L2_UA, l2_mdl_error},
+ {ST_L2_4, EV_L2_DM, l2_got_dm},
+ {ST_L2_5, EV_L2_DM, l2_got_dm},
+ {ST_L2_6, EV_L2_DM, l2_got_dm},
+ {ST_L2_7, EV_L2_DM, l2_mdl_error},
+ {ST_L2_8, EV_L2_DM, l2_mdl_error},
+ {ST_L2_1, EV_L2_UI, l2_got_ui},
+ {ST_L2_2, EV_L2_UI, l2_got_ui},
+ {ST_L2_3, EV_L2_UI, l2_got_ui},
+ {ST_L2_4, EV_L2_UI, l2_got_ui},
+ {ST_L2_5, EV_L2_UI, l2_got_ui},
+ {ST_L2_6, EV_L2_UI, l2_got_ui},
+ {ST_L2_7, EV_L2_UI, l2_got_ui},
+ {ST_L2_8, EV_L2_UI, l2_got_ui},
+ {ST_L2_7, EV_L2_FRMR, l2_got_FRMR},
{ST_L2_8, EV_L2_FRMR, l2_got_FRMR},
- {ST_L2_8, EV_L2_I, l2_got_st8_data},
-
+ {ST_L2_7, EV_L2_SUPER, l2_got_st7_super},
+ {ST_L2_8, EV_L2_SUPER, l2_got_st8_super},
+ {ST_L2_7, EV_L2_I, l2_got_iframe},
+ {ST_L2_8, EV_L2_I, l2_got_iframe},
{ST_L2_5, EV_L2_T200, l2_st5_tout_200},
{ST_L2_6, EV_L2_T200, l2_st6_tout_200},
- {ST_L2_7, EV_L2_T200, l2_st7_tout_200},
+ {ST_L2_7, EV_L2_T200, l2_st78_tout_200},
+ {ST_L2_8, EV_L2_T200, l2_st78_tout_200},
{ST_L2_7, EV_L2_T203, l2_st7_tout_203},
- {ST_L2_8, EV_L2_T200, l2_st8_tout_200},
-
- {ST_L2_1, EV_L2_MDL_REMOVE, l2_tei_remove},
- {ST_L2_3, EV_L2_MDL_REMOVE, l2_tei_remove},
- {ST_L2_4, EV_L2_MDL_REMOVE, l2_tei_remove},
- {ST_L2_5, EV_L2_MDL_REMOVE, l2_tei_remove},
- {ST_L2_6, EV_L2_MDL_REMOVE, l2_tei_remove},
- {ST_L2_7, EV_L2_MDL_REMOVE, l2_tei_remove},
- {ST_L2_8, EV_L2_MDL_REMOVE, l2_tei_remove},
+ {ST_L2_7, EV_L2_ACK_PULL, l2_pull_iqueue},
+ {ST_L2_2, EV_L1_DEACTIVATE, l2_persistant_da},
+ {ST_L2_3, EV_L1_DEACTIVATE, l2_persistant_da},
+ {ST_L2_4, EV_L1_DEACTIVATE, l2_persistant_da},
+ {ST_L2_5, EV_L1_DEACTIVATE, l2_persistant_da},
+ {ST_L2_6, EV_L1_DEACTIVATE, l2_persistant_da},
+ {ST_L2_7, EV_L1_DEACTIVATE, l2_persistant_da},
+ {ST_L2_8, EV_L1_DEACTIVATE, l2_persistant_da},
};
#define L2_FN_COUNT (sizeof(L2FnList)/sizeof(struct FsmNode))
@@ -1165,40 +1396,53 @@
{
struct sk_buff *skb = arg;
u_char *datap;
- int ret = !0;
+ int ret = 1, len;
switch (pr) {
- case (PH_DATA):
+ case (PH_DATA_IND):
datap = skb->data;
- datap += l2addrsize(&st->l2);
-
- if (IsI(datap, st->l2.extended))
+ len = l2addrsize(&st->l2);
+ if (skb->len > len)
+ datap += len;
+ else {
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'N');
+ FreeSkb(skb);
+ return;
+ }
+ if (!(*datap & 1)) /* I-Frame */
ret = FsmEvent(&st->l2.l2m, EV_L2_I, skb);
- else if (IsRR(datap, st->l2.extended))
- ret = FsmEvent(&st->l2.l2m, EV_L2_RR, skb);
- else if (IsUI(datap, st->l2.extended))
+ else if ((*datap & 3) == 1) /* S-Frame */
+ ret = FsmEvent(&st->l2.l2m, EV_L2_SUPER, skb);
+ else if (IsUI(datap, test_bit(FLG_MOD128, &st->l2.flag)))
ret = FsmEvent(&st->l2.l2m, EV_L2_UI, skb);
- else if (IsSABMX(datap, st->l2.extended))
+ else if (IsSABMX(datap, test_bit(FLG_MOD128, &st->l2.flag)))
ret = FsmEvent(&st->l2.l2m, EV_L2_SABMX, skb);
- else if (IsUA(datap, st->l2.extended))
+ else if (IsUA(datap, test_bit(FLG_MOD128, &st->l2.flag)))
ret = FsmEvent(&st->l2.l2m, EV_L2_UA, skb);
- else if (IsDISC(datap, st->l2.extended))
+ else if (IsDISC(datap, test_bit(FLG_MOD128, &st->l2.flag)))
ret = FsmEvent(&st->l2.l2m, EV_L2_DISC, skb);
- else if (IsREJ(datap, st->l2.extended))
- ret = FsmEvent(&st->l2.l2m, EV_L2_REJ, skb);
- else if (IsFRMR(datap, st->l2.extended))
+ else if (IsDM(datap, test_bit(FLG_MOD128, &st->l2.flag)))
+ ret = FsmEvent(&st->l2.l2m, EV_L2_DM, skb);
+ else if (IsFRMR(datap, test_bit(FLG_MOD128, &st->l2.flag)))
ret = FsmEvent(&st->l2.l2m, EV_L2_FRMR, skb);
- else if (IsRNR(datap, st->l2.extended))
- ret = FsmEvent(&st->l2.l2m, EV_L2_RNR, skb);
-
+ else {
+ ret = 0;
+ st->ma.layer(st, MDL_ERROR_IND, (void *) 'L');
+ FreeSkb(skb);
+ }
if (ret) {
- SET_SKB_FREE(skb);
- dev_kfree_skb(skb);
+ FreeSkb(skb);
}
break;
- case (PH_PULL_ACK):
+ case (PH_PULL_CNF):
FsmEvent(&st->l2.l2m, EV_L2_ACK_PULL, arg);
break;
+ case (PH_PAUSE_IND):
+ test_and_set_bit(FLG_DCHAN_BUSY, &st->l2.flag);
+ break;
+ case (PH_PAUSE_CNF):
+ test_and_clear_bit(FLG_DCHAN_BUSY, &st->l2.flag);
+ break;
}
}
@@ -1208,13 +1452,11 @@
switch (pr) {
case (DL_DATA):
if (FsmEvent(&st->l2.l2m, EV_L2_DL_DATA, arg)) {
- SET_SKB_FREE(((struct sk_buff *) arg));
dev_kfree_skb((struct sk_buff *) arg);
}
break;
case (DL_UNIT_DATA):
if (FsmEvent(&st->l2.l2m, EV_L2_DL_UNIT_DATA, arg)) {
- SET_SKB_FREE(((struct sk_buff *) arg));
dev_kfree_skb((struct sk_buff *) arg);
}
break;
@@ -1237,28 +1479,28 @@
case (DL_FLUSH):
(&st->l2.l2m)->userint |= LC_FLUSH_WAIT;
break;
- }
-}
-
-static void
-isdnl2_teil2(struct PStack *st, int pr, void *arg)
-{
- switch (pr) {
- case (MDL_ASSIGN):
+ case (PH_DEACTIVATE_IND):
+ FsmEvent(&st->l2.l2m, EV_L1_DEACTIVATE, arg);
+ break;
+ case (MDL_ASSIGN_REQ):
FsmEvent(&st->l2.l2m, EV_L2_MDL_ASSIGN, arg);
break;
- case (MDL_REMOVE):
+ case (MDL_REMOVE_REQ):
FsmEvent(&st->l2.l2m, EV_L2_MDL_REMOVE, arg);
break;
+ case (MDL_ERROR_REQ):
+ FsmEvent(&st->l2.l2m, EV_L2_MDL_ERROR, arg);
+ break;
}
}
void
releasestack_isdnl2(struct PStack *st)
{
- FsmDelTimer(&st->l2.t200_timer, 15);
- FsmDelTimer(&st->l2.t203_timer, 16);
+ FsmDelTimer(&st->l2.t200, 15);
+ FsmDelTimer(&st->l2.t203, 16);
discard_i_queue(st);
+ discard_ui_queue(st);
ReleaseWin(&st->l2);
}
@@ -1279,13 +1521,10 @@
st->l1.l1l2 = isdnl2_l1l2;
st->l3.l3l2 = isdnl2_l3l2;
st->ma.manl2 = isdnl2_manl2;
- st->ma.teil2 = isdnl2_teil2;
- st->l2.uihsize = l2headersize(&st->l2, !0);
- st->l2.ihsize = l2headersize(&st->l2, 0);
skb_queue_head_init(&st->l2.i_queue);
+ skb_queue_head_init(&st->l2.ui_queue);
InitWin(&st->l2);
- st->l2.rejexp = 0;
st->l2.debug = 0;
st->l2.l2m.fsm = &l2fsm;
@@ -1296,9 +1535,8 @@
st->l2.l2m.printdebug = l2m_debug;
strcpy(st->l2.debug_id, debug_id);
- FsmInitTimer(&st->l2.l2m, &st->l2.t200_timer);
- FsmInitTimer(&st->l2.l2m, &st->l2.t203_timer);
- st->l2.t200_running = 0;
+ FsmInitTimer(&st->l2.l2m, &st->l2.t200);
+ FsmInitTimer(&st->l2.l2m, &st->l2.t203);
}
void
@@ -1311,8 +1549,8 @@
{
}
-void
-Isdnl2New(void)
+HISAX_INITFUNC(void
+Isdnl2New(void))
{
l2fsm.state_count = L2_STATE_COUNT;
l2fsm.event_count = L2_EVENT_COUNT;
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov