4 * This code REQUIRES 2.1.15 or higher/ NET3.038
7 * This module is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 * LAPB 001 Jonathan Naylor Started Coding
14 * LAPB 002 Jonathan Naylor New timer architecture.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/errno.h>
20 #include <linux/types.h>
21 #include <linux/socket.h>
23 #include <linux/kernel.h>
24 #include <linux/jiffies.h>
25 #include <linux/timer.h>
26 #include <linux/string.h>
27 #include <linux/sockios.h>
28 #include <linux/net.h>
29 #include <linux/inet.h>
30 #include <linux/skbuff.h>
32 #include <asm/uaccess.h>
33 #include <linux/fcntl.h>
35 #include <linux/interrupt.h>
38 static void lapb_t1timer_expiry(unsigned long);
39 static void lapb_t2timer_expiry(unsigned long);
41 void lapb_start_t1timer(struct lapb_cb *lapb)
43 del_timer(&lapb->t1timer);
45 lapb->t1timer.data = (unsigned long)lapb;
46 lapb->t1timer.function = &lapb_t1timer_expiry;
47 lapb->t1timer.expires = jiffies + lapb->t1;
49 add_timer(&lapb->t1timer);
52 void lapb_start_t2timer(struct lapb_cb *lapb)
54 del_timer(&lapb->t2timer);
56 lapb->t2timer.data = (unsigned long)lapb;
57 lapb->t2timer.function = &lapb_t2timer_expiry;
58 lapb->t2timer.expires = jiffies + lapb->t2;
60 add_timer(&lapb->t2timer);
63 void lapb_stop_t1timer(struct lapb_cb *lapb)
65 del_timer(&lapb->t1timer);
68 void lapb_stop_t2timer(struct lapb_cb *lapb)
70 del_timer(&lapb->t2timer);
73 int lapb_t1timer_running(struct lapb_cb *lapb)
75 return timer_pending(&lapb->t1timer);
78 static void lapb_t2timer_expiry(unsigned long param)
80 struct lapb_cb *lapb = (struct lapb_cb *)param;
82 if (lapb->condition & LAPB_ACK_PENDING_CONDITION) {
83 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
84 lapb_timeout_response(lapb);
88 static void lapb_t1timer_expiry(unsigned long param)
90 struct lapb_cb *lapb = (struct lapb_cb *)param;
92 switch (lapb->state) {
95 * If we are a DCE, keep going DM .. DM .. DM
98 if (lapb->mode & LAPB_DCE)
99 lapb_send_control(lapb, LAPB_DM, LAPB_POLLOFF, LAPB_RESPONSE);
103 * Awaiting connection state, send SABM(E), up to N2 times.
106 if (lapb->n2count == lapb->n2) {
107 lapb_clear_queues(lapb);
108 lapb->state = LAPB_STATE_0;
109 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
110 lapb_dbg(0, "(%p) S1 -> S0\n", lapb->dev);
114 if (lapb->mode & LAPB_EXTENDED) {
115 lapb_dbg(1, "(%p) S1 TX SABME(1)\n",
117 lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
119 lapb_dbg(1, "(%p) S1 TX SABM(1)\n",
121 lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
127 * Awaiting disconnection state, send DISC, up to N2 times.
130 if (lapb->n2count == lapb->n2) {
131 lapb_clear_queues(lapb);
132 lapb->state = LAPB_STATE_0;
133 lapb_disconnect_confirmation(lapb, LAPB_TIMEDOUT);
134 lapb_dbg(0, "(%p) S2 -> S0\n", lapb->dev);
138 lapb_dbg(1, "(%p) S2 TX DISC(1)\n", lapb->dev);
139 lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
144 * Data transfer state, restransmit I frames, up to N2 times.
147 if (lapb->n2count == lapb->n2) {
148 lapb_clear_queues(lapb);
149 lapb->state = LAPB_STATE_0;
150 lapb_stop_t2timer(lapb);
151 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
152 lapb_dbg(0, "(%p) S3 -> S0\n", lapb->dev);
156 lapb_requeue_frames(lapb);
161 * Frame reject state, restransmit FRMR frames, up to N2 times.
164 if (lapb->n2count == lapb->n2) {
165 lapb_clear_queues(lapb);
166 lapb->state = LAPB_STATE_0;
167 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
168 lapb_dbg(0, "(%p) S4 -> S0\n", lapb->dev);
172 lapb_transmit_frmr(lapb);
177 lapb_start_t1timer(lapb);