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 #include <linux/config.h>
18 #if defined(CONFIG_LAPB) || defined(CONFIG_LAPB_MODULE)
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/sched.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 <asm/system.h>
34 #include <linux/fcntl.h>
35 #include <linux/mm.h>
36 #include <linux/interrupt.h>
37 #include <net/lapb.h>
38
39 /*
40 * This procedure is passed a buffer descriptor for an iframe. It builds
41 * the rest of the control part of the frame and then writes it out.
42 */
43 static void lapb_send_iframe(lapb_cb *lapb, struct sk_buff *skb, int poll_bit)
44 {
45 unsigned char *frame;
46
47 if (skb == NULL)
48 return;
49
50 if (lapb->mode & LAPB_EXTENDED) {
51 frame = skb_push(skb, 2);
52
53 frame[0] = LAPB_I;
54 frame[0] |= (lapb->vs << 1);
55 frame[1] = (poll_bit) ? LAPB_EPF : 0;
56 frame[1] |= (lapb->vr << 1);
57 } else {
58 frame = skb_push(skb, 1);
59
60 *frame = LAPB_I;
61 *frame |= (poll_bit) ? LAPB_SPF : 0;
62 *frame |= (lapb->vr << 5);
63 *frame |= (lapb->vs << 1);
64 }
65
66 #if LAPB_DEBUG > 1
67 printk(KERN_DEBUG "lapb: (%p) S%d TX I(%d) S%d R%d\n", lapb->token, lapb->state, poll_bit, lapb->vs, lapb->vr);
68 #endif
69
70 lapb_transmit_buffer(lapb, skb, LAPB_COMMAND);
71 }
72
73 void lapb_kick(lapb_cb *lapb)
74 {
75 struct sk_buff *skb, *skbn;
76 unsigned short modulus, start, end;
77
78 modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS : LAPB_SMODULUS;
79
80 start = (skb_peek(&lapb->ack_queue) == NULL) ? lapb->va : lapb->vs;
81 end = (lapb->va + lapb->window) % modulus;
82
83 if (!(lapb->condition & LAPB_PEER_RX_BUSY_CONDITION) &&
84 start != end &&
85 skb_peek(&lapb->write_queue) != NULL) {
86
87 lapb->vs = start;
88
89 /*
90 * Dequeue the frame and copy it.
91 */
92 skb = skb_dequeue(&lapb->write_queue);
93
94 do {
95 if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
96 skb_queue_head(&lapb->write_queue, skb);
97 break;
98 }
99
100 if (skb->sk != NULL)
101 skb_set_owner_w(skbn, skb->sk);
102
103 /*
104 * Transmit the frame copy.
105 */
106 lapb_send_iframe(lapb, skbn, LAPB_POLLOFF);
107
108 lapb->vs = (lapb->vs + 1) % modulus;
109
110 /*
111 * Requeue the original data frame.
112 */
113 skb_queue_tail(&lapb->ack_queue, skb);
114
115 } while (lapb->vs != end && (skb = skb_dequeue(&lapb->write_queue)) != NULL);
116
117 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
118
119 if (!lapb_t1timer_running(lapb))
120 lapb_start_t1timer(lapb);
121 }
122 }
123
124 void lapb_transmit_buffer(lapb_cb *lapb, struct sk_buff *skb, int type)
125 {
126 unsigned char *ptr;
127
128 ptr = skb_push(skb, 1);
129
130 if (lapb->mode & LAPB_MLP) {
131 if (lapb->mode & LAPB_DCE) {
132 if (type == LAPB_COMMAND)
133 *ptr = LAPB_ADDR_C;
134 if (type == LAPB_RESPONSE)
135 *ptr = LAPB_ADDR_D;
136 } else {
137 if (type == LAPB_COMMAND)
138 *ptr = LAPB_ADDR_D;
139 if (type == LAPB_RESPONSE)
140 *ptr = LAPB_ADDR_C;
141 }
142 } else {
143 if (lapb->mode & LAPB_DCE) {
144 if (type == LAPB_COMMAND)
145 *ptr = LAPB_ADDR_A;
146 if (type == LAPB_RESPONSE)
147 *ptr = LAPB_ADDR_B;
148 } else {
149 if (type == LAPB_COMMAND)
150 *ptr = LAPB_ADDR_B;
151 if (type == LAPB_RESPONSE)
152 *ptr = LAPB_ADDR_A;
153 }
154 }
155
156 #if LAPB_DEBUG > 2
157 printk(KERN_DEBUG "lapb: (%p) S%d TX %02X %02X %02X\n", lapb->token, lapb->state, skb->data[0], skb->data[1], skb->data[2]);
158 #endif
159
160 if (!lapb_data_transmit(lapb, skb))
161 kfree_skb(skb);
162 }
163
164 void lapb_establish_data_link(lapb_cb *lapb)
165 {
166 lapb->condition = 0x00;
167 lapb->n2count = 0;
168
169 if (lapb->mode & LAPB_EXTENDED) {
170 #if LAPB_DEBUG > 1
171 printk(KERN_DEBUG "lapb: (%p) S%d TX SABME(1)\n", lapb->token, lapb->state);
172 #endif
173 lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
174 } else {
175 #if LAPB_DEBUG > 1
176 printk(KERN_DEBUG "lapb: (%p) S%d TX SABM(1)\n", lapb->token, lapb->state);
177 #endif
178 lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
179 }
180
181 lapb_start_t1timer(lapb);
182 lapb_stop_t2timer(lapb);
183 }
184
185 void lapb_enquiry_response(lapb_cb *lapb)
186 {
187 #if LAPB_DEBUG > 1
188 printk(KERN_DEBUG "lapb: (%p) S%d TX RR(1) R%d\n", lapb->token, lapb->state, lapb->vr);
189 #endif
190
191 lapb_send_control(lapb, LAPB_RR, LAPB_POLLON, LAPB_RESPONSE);
192
193 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
194 }
195
196 void lapb_timeout_response(lapb_cb *lapb)
197 {
198 #if LAPB_DEBUG > 1
199 printk(KERN_DEBUG "lapb: (%p) S%d TX RR(0) R%d\n", lapb->token, lapb->state, lapb->vr);
200 #endif
201
202 lapb_send_control(lapb, LAPB_RR, LAPB_POLLOFF, LAPB_RESPONSE);
203
204 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
205 }
206
207 void lapb_check_iframes_acked(lapb_cb *lapb, unsigned short nr)
208 {
209 if (lapb->vs == nr) {
210 lapb_frames_acked(lapb, nr);
211 lapb_stop_t1timer(lapb);
212 lapb->n2count = 0;
213 } else {
214 if (lapb->va != nr) {
215 lapb_frames_acked(lapb, nr);
216 lapb_start_t1timer(lapb);
217 }
218 }
219 }
220
221 void lapb_check_need_response(lapb_cb *lapb, int type, int pf)
222 {
223 if (type == LAPB_COMMAND && pf)
224 lapb_enquiry_response(lapb);
225 }
226
227 #endif
228
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.