Loading...
1/*
2 * LAPB release 002
3 *
4 * This code REQUIRES 2.1.15 or higher/ NET3.038
5 *
6 * This module:
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.
11 *
12 * History
13 * LAPB 001 Jonathan Naylor Started Coding
14 * LAPB 002 Jonathan Naylor New timer architecture.
15 */
16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
19#include <linux/errno.h>
20#include <linux/types.h>
21#include <linux/socket.h>
22#include <linux/in.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>
31#include <net/sock.h>
32#include <asm/uaccess.h>
33#include <linux/fcntl.h>
34#include <linux/mm.h>
35#include <linux/interrupt.h>
36#include <net/lapb.h>
37
38static void lapb_t1timer_expiry(unsigned long);
39static void lapb_t2timer_expiry(unsigned long);
40
41void lapb_start_t1timer(struct lapb_cb *lapb)
42{
43 del_timer(&lapb->t1timer);
44
45 lapb->t1timer.data = (unsigned long)lapb;
46 lapb->t1timer.function = &lapb_t1timer_expiry;
47 lapb->t1timer.expires = jiffies + lapb->t1;
48
49 add_timer(&lapb->t1timer);
50}
51
52void lapb_start_t2timer(struct lapb_cb *lapb)
53{
54 del_timer(&lapb->t2timer);
55
56 lapb->t2timer.data = (unsigned long)lapb;
57 lapb->t2timer.function = &lapb_t2timer_expiry;
58 lapb->t2timer.expires = jiffies + lapb->t2;
59
60 add_timer(&lapb->t2timer);
61}
62
63void lapb_stop_t1timer(struct lapb_cb *lapb)
64{
65 del_timer(&lapb->t1timer);
66}
67
68void lapb_stop_t2timer(struct lapb_cb *lapb)
69{
70 del_timer(&lapb->t2timer);
71}
72
73int lapb_t1timer_running(struct lapb_cb *lapb)
74{
75 return timer_pending(&lapb->t1timer);
76}
77
78static void lapb_t2timer_expiry(unsigned long param)
79{
80 struct lapb_cb *lapb = (struct lapb_cb *)param;
81
82 if (lapb->condition & LAPB_ACK_PENDING_CONDITION) {
83 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
84 lapb_timeout_response(lapb);
85 }
86}
87
88static void lapb_t1timer_expiry(unsigned long param)
89{
90 struct lapb_cb *lapb = (struct lapb_cb *)param;
91
92 switch (lapb->state) {
93
94 /*
95 * If we are a DCE, keep going DM .. DM .. DM
96 */
97 case LAPB_STATE_0:
98 if (lapb->mode & LAPB_DCE)
99 lapb_send_control(lapb, LAPB_DM, LAPB_POLLOFF, LAPB_RESPONSE);
100 break;
101
102 /*
103 * Awaiting connection state, send SABM(E), up to N2 times.
104 */
105 case LAPB_STATE_1:
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);
111 return;
112 } else {
113 lapb->n2count++;
114 if (lapb->mode & LAPB_EXTENDED) {
115 lapb_dbg(1, "(%p) S1 TX SABME(1)\n",
116 lapb->dev);
117 lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
118 } else {
119 lapb_dbg(1, "(%p) S1 TX SABM(1)\n",
120 lapb->dev);
121 lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
122 }
123 }
124 break;
125
126 /*
127 * Awaiting disconnection state, send DISC, up to N2 times.
128 */
129 case LAPB_STATE_2:
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);
135 return;
136 } else {
137 lapb->n2count++;
138 lapb_dbg(1, "(%p) S2 TX DISC(1)\n", lapb->dev);
139 lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
140 }
141 break;
142
143 /*
144 * Data transfer state, restransmit I frames, up to N2 times.
145 */
146 case LAPB_STATE_3:
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);
153 return;
154 } else {
155 lapb->n2count++;
156 lapb_requeue_frames(lapb);
157 lapb_kick(lapb);
158 }
159 break;
160
161 /*
162 * Frame reject state, restransmit FRMR frames, up to N2 times.
163 */
164 case LAPB_STATE_4:
165 if (lapb->n2count == lapb->n2) {
166 lapb_clear_queues(lapb);
167 lapb->state = LAPB_STATE_0;
168 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
169 lapb_dbg(0, "(%p) S4 -> S0\n", lapb->dev);
170 return;
171 } else {
172 lapb->n2count++;
173 lapb_transmit_frmr(lapb);
174 }
175 break;
176 }
177
178 lapb_start_t1timer(lapb);
179}
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * LAPB release 002
4 *
5 * This code REQUIRES 2.1.15 or higher/ NET3.038
6 *
7 * History
8 * LAPB 001 Jonathan Naylor Started Coding
9 * LAPB 002 Jonathan Naylor New timer architecture.
10 */
11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14#include <linux/errno.h>
15#include <linux/types.h>
16#include <linux/socket.h>
17#include <linux/in.h>
18#include <linux/kernel.h>
19#include <linux/jiffies.h>
20#include <linux/timer.h>
21#include <linux/string.h>
22#include <linux/sockios.h>
23#include <linux/net.h>
24#include <linux/inet.h>
25#include <linux/skbuff.h>
26#include <net/sock.h>
27#include <linux/uaccess.h>
28#include <linux/fcntl.h>
29#include <linux/mm.h>
30#include <linux/interrupt.h>
31#include <net/lapb.h>
32
33static void lapb_t1timer_expiry(struct timer_list *);
34static void lapb_t2timer_expiry(struct timer_list *);
35
36void lapb_start_t1timer(struct lapb_cb *lapb)
37{
38 del_timer(&lapb->t1timer);
39
40 lapb->t1timer.function = lapb_t1timer_expiry;
41 lapb->t1timer.expires = jiffies + lapb->t1;
42
43 add_timer(&lapb->t1timer);
44}
45
46void lapb_start_t2timer(struct lapb_cb *lapb)
47{
48 del_timer(&lapb->t2timer);
49
50 lapb->t2timer.function = lapb_t2timer_expiry;
51 lapb->t2timer.expires = jiffies + lapb->t2;
52
53 add_timer(&lapb->t2timer);
54}
55
56void lapb_stop_t1timer(struct lapb_cb *lapb)
57{
58 del_timer(&lapb->t1timer);
59}
60
61void lapb_stop_t2timer(struct lapb_cb *lapb)
62{
63 del_timer(&lapb->t2timer);
64}
65
66int lapb_t1timer_running(struct lapb_cb *lapb)
67{
68 return timer_pending(&lapb->t1timer);
69}
70
71static void lapb_t2timer_expiry(struct timer_list *t)
72{
73 struct lapb_cb *lapb = from_timer(lapb, t, t2timer);
74
75 if (lapb->condition & LAPB_ACK_PENDING_CONDITION) {
76 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
77 lapb_timeout_response(lapb);
78 }
79}
80
81static void lapb_t1timer_expiry(struct timer_list *t)
82{
83 struct lapb_cb *lapb = from_timer(lapb, t, t1timer);
84
85 switch (lapb->state) {
86
87 /*
88 * If we are a DCE, keep going DM .. DM .. DM
89 */
90 case LAPB_STATE_0:
91 if (lapb->mode & LAPB_DCE)
92 lapb_send_control(lapb, LAPB_DM, LAPB_POLLOFF, LAPB_RESPONSE);
93 break;
94
95 /*
96 * Awaiting connection state, send SABM(E), up to N2 times.
97 */
98 case LAPB_STATE_1:
99 if (lapb->n2count == lapb->n2) {
100 lapb_clear_queues(lapb);
101 lapb->state = LAPB_STATE_0;
102 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
103 lapb_dbg(0, "(%p) S1 -> S0\n", lapb->dev);
104 return;
105 } else {
106 lapb->n2count++;
107 if (lapb->mode & LAPB_EXTENDED) {
108 lapb_dbg(1, "(%p) S1 TX SABME(1)\n",
109 lapb->dev);
110 lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
111 } else {
112 lapb_dbg(1, "(%p) S1 TX SABM(1)\n",
113 lapb->dev);
114 lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
115 }
116 }
117 break;
118
119 /*
120 * Awaiting disconnection state, send DISC, up to N2 times.
121 */
122 case LAPB_STATE_2:
123 if (lapb->n2count == lapb->n2) {
124 lapb_clear_queues(lapb);
125 lapb->state = LAPB_STATE_0;
126 lapb_disconnect_confirmation(lapb, LAPB_TIMEDOUT);
127 lapb_dbg(0, "(%p) S2 -> S0\n", lapb->dev);
128 return;
129 } else {
130 lapb->n2count++;
131 lapb_dbg(1, "(%p) S2 TX DISC(1)\n", lapb->dev);
132 lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
133 }
134 break;
135
136 /*
137 * Data transfer state, restransmit I frames, up to N2 times.
138 */
139 case LAPB_STATE_3:
140 if (lapb->n2count == lapb->n2) {
141 lapb_clear_queues(lapb);
142 lapb->state = LAPB_STATE_0;
143 lapb_stop_t2timer(lapb);
144 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
145 lapb_dbg(0, "(%p) S3 -> S0\n", lapb->dev);
146 return;
147 } else {
148 lapb->n2count++;
149 lapb_requeue_frames(lapb);
150 lapb_kick(lapb);
151 }
152 break;
153
154 /*
155 * Frame reject state, restransmit FRMR frames, up to N2 times.
156 */
157 case LAPB_STATE_4:
158 if (lapb->n2count == lapb->n2) {
159 lapb_clear_queues(lapb);
160 lapb->state = LAPB_STATE_0;
161 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
162 lapb_dbg(0, "(%p) S4 -> S0\n", lapb->dev);
163 return;
164 } else {
165 lapb->n2count++;
166 lapb_transmit_frmr(lapb);
167 }
168 break;
169 }
170
171 lapb_start_t1timer(lapb);
172}