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 Naulor Started Coding
14 * LAPB 002 Jonathan Naylor New timer architecture.
15 * 2000-10-29 Henner Eisen lapb_data_indication() return status.
16 */
17
18 #include <linux/errno.h>
19 #include <linux/types.h>
20 #include <linux/socket.h>
21 #include <linux/in.h>
22 #include <linux/kernel.h>
23 #include <linux/timer.h>
24 #include <linux/string.h>
25 #include <linux/sockios.h>
26 #include <linux/net.h>
27 #include <linux/inet.h>
28 #include <linux/netdevice.h>
29 #include <linux/skbuff.h>
30 #include <linux/slab.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
38 /*
39 * State machine for state 0, Disconnected State.
40 * The handling of the timer(s) is in file lapb_timer.c.
41 */
lapb_state0_machine(struct lapb_cb * lapb,struct sk_buff * skb,struct lapb_frame * frame)42 static void lapb_state0_machine(struct lapb_cb *lapb, struct sk_buff *skb,
43 struct lapb_frame *frame)
44 {
45 switch (frame->type) {
46 case LAPB_SABM:
47 #if LAPB_DEBUG > 1
48 printk(KERN_DEBUG "lapb: (%p) S0 RX SABM(%d)\n",
49 lapb->dev, frame->pf);
50 #endif
51 if (lapb->mode & LAPB_EXTENDED) {
52 #if LAPB_DEBUG > 1
53 printk(KERN_DEBUG "lapb: (%p) S0 TX DM(%d)\n",
54 lapb->dev, frame->pf);
55 #endif
56 lapb_send_control(lapb, LAPB_DM, frame->pf,
57 LAPB_RESPONSE);
58 } else {
59 #if LAPB_DEBUG > 1
60 printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n",
61 lapb->dev, frame->pf);
62 #endif
63 #if LAPB_DEBUG > 0
64 printk(KERN_DEBUG "lapb: (%p) S0 -> S3\n", lapb->dev);
65 #endif
66 lapb_send_control(lapb, LAPB_UA, frame->pf,
67 LAPB_RESPONSE);
68 lapb_stop_t1timer(lapb);
69 lapb_stop_t2timer(lapb);
70 lapb->state = LAPB_STATE_3;
71 lapb->condition = 0x00;
72 lapb->n2count = 0;
73 lapb->vs = 0;
74 lapb->vr = 0;
75 lapb->va = 0;
76 lapb_connect_indication(lapb, LAPB_OK);
77 }
78 break;
79
80 case LAPB_SABME:
81 #if LAPB_DEBUG > 1
82 printk(KERN_DEBUG "lapb: (%p) S0 RX SABME(%d)\n",
83 lapb->dev, frame->pf);
84 #endif
85 if (lapb->mode & LAPB_EXTENDED) {
86 #if LAPB_DEBUG > 1
87 printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n",
88 lapb->dev, frame->pf);
89 #endif
90 #if LAPB_DEBUG > 0
91 printk(KERN_DEBUG "lapb: (%p) S0 -> S3\n", lapb->dev);
92 #endif
93 lapb_send_control(lapb, LAPB_UA, frame->pf,
94 LAPB_RESPONSE);
95 lapb_stop_t1timer(lapb);
96 lapb_stop_t2timer(lapb);
97 lapb->state = LAPB_STATE_3;
98 lapb->condition = 0x00;
99 lapb->n2count = 0;
100 lapb->vs = 0;
101 lapb->vr = 0;
102 lapb->va = 0;
103 lapb_connect_indication(lapb, LAPB_OK);
104 } else {
105 #if LAPB_DEBUG > 1
106 printk(KERN_DEBUG "lapb: (%p) S0 TX DM(%d)\n",
107 lapb->dev, frame->pf);
108 #endif
109 lapb_send_control(lapb, LAPB_DM, frame->pf,
110 LAPB_RESPONSE);
111 }
112 break;
113
114 case LAPB_DISC:
115 #if LAPB_DEBUG > 1
116 printk(KERN_DEBUG "lapb: (%p) S0 RX DISC(%d)\n",
117 lapb->dev, frame->pf);
118 printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n",
119 lapb->dev, frame->pf);
120 #endif
121 lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE);
122 break;
123
124 default:
125 break;
126 }
127
128 kfree_skb(skb);
129 }
130
131 /*
132 * State machine for state 1, Awaiting Connection State.
133 * The handling of the timer(s) is in file lapb_timer.c.
134 */
lapb_state1_machine(struct lapb_cb * lapb,struct sk_buff * skb,struct lapb_frame * frame)135 static void lapb_state1_machine(struct lapb_cb *lapb, struct sk_buff *skb,
136 struct lapb_frame *frame)
137 {
138 switch (frame->type) {
139 case LAPB_SABM:
140 #if LAPB_DEBUG > 1
141 printk(KERN_DEBUG "lapb: (%p) S1 RX SABM(%d)\n",
142 lapb->dev, frame->pf);
143 #endif
144 if (lapb->mode & LAPB_EXTENDED) {
145 #if LAPB_DEBUG > 1
146 printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n",
147 lapb->dev, frame->pf);
148 #endif
149 lapb_send_control(lapb, LAPB_DM, frame->pf,
150 LAPB_RESPONSE);
151 } else {
152 #if LAPB_DEBUG > 1
153 printk(KERN_DEBUG "lapb: (%p) S1 TX UA(%d)\n",
154 lapb->dev, frame->pf);
155 #endif
156 lapb_send_control(lapb, LAPB_UA, frame->pf,
157 LAPB_RESPONSE);
158 }
159 break;
160
161 case LAPB_SABME:
162 #if LAPB_DEBUG > 1
163 printk(KERN_DEBUG "lapb: (%p) S1 RX SABME(%d)\n",
164 lapb->dev, frame->pf);
165 #endif
166 if (lapb->mode & LAPB_EXTENDED) {
167 #if LAPB_DEBUG > 1
168 printk(KERN_DEBUG "lapb: (%p) S1 TX UA(%d)\n",
169 lapb->dev, frame->pf);
170 #endif
171 lapb_send_control(lapb, LAPB_UA, frame->pf,
172 LAPB_RESPONSE);
173 } else {
174 #if LAPB_DEBUG > 1
175 printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n",
176 lapb->dev, frame->pf);
177 #endif
178 lapb_send_control(lapb, LAPB_DM, frame->pf,
179 LAPB_RESPONSE);
180 }
181 break;
182
183 case LAPB_DISC:
184 #if LAPB_DEBUG > 1
185 printk(KERN_DEBUG "lapb: (%p) S1 RX DISC(%d)\n",
186 lapb->dev, frame->pf);
187 printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n",
188 lapb->dev, frame->pf);
189 #endif
190 lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE);
191 break;
192
193 case LAPB_UA:
194 #if LAPB_DEBUG > 1
195 printk(KERN_DEBUG "lapb: (%p) S1 RX UA(%d)\n",
196 lapb->dev, frame->pf);
197 #endif
198 if (frame->pf) {
199 #if LAPB_DEBUG > 0
200 printk(KERN_DEBUG "lapb: (%p) S1 -> S3\n", lapb->dev);
201 #endif
202 lapb_stop_t1timer(lapb);
203 lapb_stop_t2timer(lapb);
204 lapb->state = LAPB_STATE_3;
205 lapb->condition = 0x00;
206 lapb->n2count = 0;
207 lapb->vs = 0;
208 lapb->vr = 0;
209 lapb->va = 0;
210 lapb_connect_confirmation(lapb, LAPB_OK);
211 }
212 break;
213
214 case LAPB_DM:
215 #if LAPB_DEBUG > 1
216 printk(KERN_DEBUG "lapb: (%p) S1 RX DM(%d)\n",
217 lapb->dev, frame->pf);
218 #endif
219 if (frame->pf) {
220 #if LAPB_DEBUG > 0
221 printk(KERN_DEBUG "lapb: (%p) S1 -> S0\n", lapb->dev);
222 #endif
223 lapb_clear_queues(lapb);
224 lapb->state = LAPB_STATE_0;
225 lapb_start_t1timer(lapb);
226 lapb_stop_t2timer(lapb);
227 lapb_disconnect_indication(lapb, LAPB_REFUSED);
228 }
229 break;
230 }
231
232 kfree_skb(skb);
233 }
234
235 /*
236 * State machine for state 2, Awaiting Release State.
237 * The handling of the timer(s) is in file lapb_timer.c
238 */
lapb_state2_machine(struct lapb_cb * lapb,struct sk_buff * skb,struct lapb_frame * frame)239 static void lapb_state2_machine(struct lapb_cb *lapb, struct sk_buff *skb,
240 struct lapb_frame *frame)
241 {
242 switch (frame->type) {
243 case LAPB_SABM:
244 case LAPB_SABME:
245 #if LAPB_DEBUG > 1
246 printk(KERN_DEBUG "lapb: (%p) S2 RX {SABM,SABME}(%d)\n",
247 lapb->dev, frame->pf);
248 printk(KERN_DEBUG "lapb: (%p) S2 TX DM(%d)\n",
249 lapb->dev, frame->pf);
250 #endif
251 lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE);
252 break;
253
254 case LAPB_DISC:
255 #if LAPB_DEBUG > 1
256 printk(KERN_DEBUG "lapb: (%p) S2 RX DISC(%d)\n",
257 lapb->dev, frame->pf);
258 printk(KERN_DEBUG "lapb: (%p) S2 TX UA(%d)\n",
259 lapb->dev, frame->pf);
260 #endif
261 lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE);
262 break;
263
264 case LAPB_UA:
265 #if LAPB_DEBUG > 1
266 printk(KERN_DEBUG "lapb: (%p) S2 RX UA(%d)\n",
267 lapb->dev, frame->pf);
268 #endif
269 if (frame->pf) {
270 #if LAPB_DEBUG > 0
271 printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n", lapb->dev);
272 #endif
273 lapb->state = LAPB_STATE_0;
274 lapb_start_t1timer(lapb);
275 lapb_stop_t2timer(lapb);
276 lapb_disconnect_confirmation(lapb, LAPB_OK);
277 }
278 break;
279
280 case LAPB_DM:
281 #if LAPB_DEBUG > 1
282 printk(KERN_DEBUG "lapb: (%p) S2 RX DM(%d)\n",
283 lapb->dev, frame->pf);
284 #endif
285 if (frame->pf) {
286 #if LAPB_DEBUG > 0
287 printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n", lapb->dev);
288 #endif
289 lapb->state = LAPB_STATE_0;
290 lapb_start_t1timer(lapb);
291 lapb_stop_t2timer(lapb);
292 lapb_disconnect_confirmation(lapb, LAPB_NOTCONNECTED);
293 }
294 break;
295
296 case LAPB_I:
297 case LAPB_REJ:
298 case LAPB_RNR:
299 case LAPB_RR:
300 #if LAPB_DEBUG > 1
301 printk(KERN_DEBUG "lapb: (%p) S2 RX {I,REJ,RNR,RR}(%d)\n",
302 lapb->dev, frame->pf);
303 printk(KERN_DEBUG "lapb: (%p) S2 RX DM(%d)\n",
304 lapb->dev, frame->pf);
305 #endif
306 if (frame->pf)
307 lapb_send_control(lapb, LAPB_DM, frame->pf,
308 LAPB_RESPONSE);
309 break;
310 }
311
312 kfree_skb(skb);
313 }
314
315 /*
316 * State machine for state 3, Connected State.
317 * The handling of the timer(s) is in file lapb_timer.c
318 */
lapb_state3_machine(struct lapb_cb * lapb,struct sk_buff * skb,struct lapb_frame * frame)319 static void lapb_state3_machine(struct lapb_cb *lapb, struct sk_buff *skb,
320 struct lapb_frame *frame)
321 {
322 int queued = 0;
323 int modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS :
324 LAPB_SMODULUS;
325
326 switch (frame->type) {
327 case LAPB_SABM:
328 #if LAPB_DEBUG > 1
329 printk(KERN_DEBUG "lapb: (%p) S3 RX SABM(%d)\n",
330 lapb->dev, frame->pf);
331 #endif
332 if (lapb->mode & LAPB_EXTENDED) {
333 #if LAPB_DEBUG > 1
334 printk(KERN_DEBUG "lapb: (%p) S3 TX DM(%d)\n",
335 lapb->dev, frame->pf);
336 #endif
337 lapb_send_control(lapb, LAPB_DM, frame->pf,
338 LAPB_RESPONSE);
339 } else {
340 #if LAPB_DEBUG > 1
341 printk(KERN_DEBUG "lapb: (%p) S3 TX UA(%d)\n",
342 lapb->dev, frame->pf);
343 #endif
344 lapb_send_control(lapb, LAPB_UA, frame->pf,
345 LAPB_RESPONSE);
346 lapb_stop_t1timer(lapb);
347 lapb_stop_t2timer(lapb);
348 lapb->condition = 0x00;
349 lapb->n2count = 0;
350 lapb->vs = 0;
351 lapb->vr = 0;
352 lapb->va = 0;
353 lapb_requeue_frames(lapb);
354 }
355 break;
356
357 case LAPB_SABME:
358 #if LAPB_DEBUG > 1
359 printk(KERN_DEBUG "lapb: (%p) S3 RX SABME(%d)\n",
360 lapb->dev, frame->pf);
361 #endif
362 if (lapb->mode & LAPB_EXTENDED) {
363 #if LAPB_DEBUG > 1
364 printk(KERN_DEBUG "lapb: (%p) S3 TX UA(%d)\n",
365 lapb->dev, frame->pf);
366 #endif
367 lapb_send_control(lapb, LAPB_UA, frame->pf,
368 LAPB_RESPONSE);
369 lapb_stop_t1timer(lapb);
370 lapb_stop_t2timer(lapb);
371 lapb->condition = 0x00;
372 lapb->n2count = 0;
373 lapb->vs = 0;
374 lapb->vr = 0;
375 lapb->va = 0;
376 lapb_requeue_frames(lapb);
377 } else {
378 #if LAPB_DEBUG > 1
379 printk(KERN_DEBUG "lapb: (%p) S3 TX DM(%d)\n",
380 lapb->dev, frame->pf);
381 #endif
382 lapb_send_control(lapb, LAPB_DM, frame->pf,
383 LAPB_RESPONSE);
384 }
385 break;
386
387 case LAPB_DISC:
388 #if LAPB_DEBUG > 1
389 printk(KERN_DEBUG "lapb: (%p) S3 RX DISC(%d)\n",
390 lapb->dev, frame->pf);
391 #endif
392 #if LAPB_DEBUG > 0
393 printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n", lapb->dev);
394 #endif
395 lapb_clear_queues(lapb);
396 lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE);
397 lapb_start_t1timer(lapb);
398 lapb_stop_t2timer(lapb);
399 lapb->state = LAPB_STATE_0;
400 lapb_disconnect_indication(lapb, LAPB_OK);
401 break;
402
403 case LAPB_DM:
404 #if LAPB_DEBUG > 1
405 printk(KERN_DEBUG "lapb: (%p) S3 RX DM(%d)\n",
406 lapb->dev, frame->pf);
407 #endif
408 #if LAPB_DEBUG > 0
409 printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n", lapb->dev);
410 #endif
411 lapb_clear_queues(lapb);
412 lapb->state = LAPB_STATE_0;
413 lapb_start_t1timer(lapb);
414 lapb_stop_t2timer(lapb);
415 lapb_disconnect_indication(lapb, LAPB_NOTCONNECTED);
416 break;
417
418 case LAPB_RNR:
419 #if LAPB_DEBUG > 1
420 printk(KERN_DEBUG "lapb: (%p) S3 RX RNR(%d) R%d\n",
421 lapb->dev, frame->pf, frame->nr);
422 #endif
423 lapb->condition |= LAPB_PEER_RX_BUSY_CONDITION;
424 lapb_check_need_response(lapb, frame->cr, frame->pf);
425 if (lapb_validate_nr(lapb, frame->nr)) {
426 lapb_check_iframes_acked(lapb, frame->nr);
427 } else {
428 lapb->frmr_data = *frame;
429 lapb->frmr_type = LAPB_FRMR_Z;
430 lapb_transmit_frmr(lapb);
431 #if LAPB_DEBUG > 0
432 printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
433 #endif
434 lapb_start_t1timer(lapb);
435 lapb_stop_t2timer(lapb);
436 lapb->state = LAPB_STATE_4;
437 lapb->n2count = 0;
438 }
439 break;
440
441 case LAPB_RR:
442 #if LAPB_DEBUG > 1
443 printk(KERN_DEBUG "lapb: (%p) S3 RX RR(%d) R%d\n",
444 lapb->dev, frame->pf, frame->nr);
445 #endif
446 lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION;
447 lapb_check_need_response(lapb, frame->cr, frame->pf);
448 if (lapb_validate_nr(lapb, frame->nr)) {
449 lapb_check_iframes_acked(lapb, frame->nr);
450 } else {
451 lapb->frmr_data = *frame;
452 lapb->frmr_type = LAPB_FRMR_Z;
453 lapb_transmit_frmr(lapb);
454 #if LAPB_DEBUG > 0
455 printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
456 #endif
457 lapb_start_t1timer(lapb);
458 lapb_stop_t2timer(lapb);
459 lapb->state = LAPB_STATE_4;
460 lapb->n2count = 0;
461 }
462 break;
463
464 case LAPB_REJ:
465 #if LAPB_DEBUG > 1
466 printk(KERN_DEBUG "lapb: (%p) S3 RX REJ(%d) R%d\n",
467 lapb->dev, frame->pf, frame->nr);
468 #endif
469 lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION;
470 lapb_check_need_response(lapb, frame->cr, frame->pf);
471 if (lapb_validate_nr(lapb, frame->nr)) {
472 lapb_frames_acked(lapb, frame->nr);
473 lapb_stop_t1timer(lapb);
474 lapb->n2count = 0;
475 lapb_requeue_frames(lapb);
476 } else {
477 lapb->frmr_data = *frame;
478 lapb->frmr_type = LAPB_FRMR_Z;
479 lapb_transmit_frmr(lapb);
480 #if LAPB_DEBUG > 0
481 printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
482 #endif
483 lapb_start_t1timer(lapb);
484 lapb_stop_t2timer(lapb);
485 lapb->state = LAPB_STATE_4;
486 lapb->n2count = 0;
487 }
488 break;
489
490 case LAPB_I:
491 #if LAPB_DEBUG > 1
492 printk(KERN_DEBUG "lapb: (%p) S3 RX I(%d) S%d R%d\n",
493 lapb->dev, frame->pf, frame->ns, frame->nr);
494 #endif
495 if (!lapb_validate_nr(lapb, frame->nr)) {
496 lapb->frmr_data = *frame;
497 lapb->frmr_type = LAPB_FRMR_Z;
498 lapb_transmit_frmr(lapb);
499 #if LAPB_DEBUG > 0
500 printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
501 #endif
502 lapb_start_t1timer(lapb);
503 lapb_stop_t2timer(lapb);
504 lapb->state = LAPB_STATE_4;
505 lapb->n2count = 0;
506 break;
507 }
508 if (lapb->condition & LAPB_PEER_RX_BUSY_CONDITION)
509 lapb_frames_acked(lapb, frame->nr);
510 else
511 lapb_check_iframes_acked(lapb, frame->nr);
512
513 if (frame->ns == lapb->vr) {
514 int cn;
515 cn = lapb_data_indication(lapb, skb);
516 queued = 1;
517 /*
518 * If upper layer has dropped the frame, we
519 * basically ignore any further protocol
520 * processing. This will cause the peer
521 * to re-transmit the frame later like
522 * a frame lost on the wire.
523 */
524 if (cn == NET_RX_DROP) {
525 printk(KERN_DEBUG "LAPB: rx congestion\n");
526 break;
527 }
528 lapb->vr = (lapb->vr + 1) % modulus;
529 lapb->condition &= ~LAPB_REJECT_CONDITION;
530 if (frame->pf)
531 lapb_enquiry_response(lapb);
532 else {
533 if (!(lapb->condition &
534 LAPB_ACK_PENDING_CONDITION)) {
535 lapb->condition |= LAPB_ACK_PENDING_CONDITION;
536 lapb_start_t2timer(lapb);
537 }
538 }
539 } else {
540 if (lapb->condition & LAPB_REJECT_CONDITION) {
541 if (frame->pf)
542 lapb_enquiry_response(lapb);
543 } else {
544 #if LAPB_DEBUG > 1
545 printk(KERN_DEBUG
546 "lapb: (%p) S3 TX REJ(%d) R%d\n",
547 lapb->dev, frame->pf, lapb->vr);
548 #endif
549 lapb->condition |= LAPB_REJECT_CONDITION;
550 lapb_send_control(lapb, LAPB_REJ, frame->pf,
551 LAPB_RESPONSE);
552 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
553 }
554 }
555 break;
556
557 case LAPB_FRMR:
558 #if LAPB_DEBUG > 1
559 printk(KERN_DEBUG "lapb: (%p) S3 RX FRMR(%d) %02X "
560 "%02X %02X %02X %02X\n", lapb->dev, frame->pf,
561 skb->data[0], skb->data[1], skb->data[2],
562 skb->data[3], skb->data[4]);
563 #endif
564 lapb_establish_data_link(lapb);
565 #if LAPB_DEBUG > 0
566 printk(KERN_DEBUG "lapb: (%p) S3 -> S1\n", lapb->dev);
567 #endif
568 lapb_requeue_frames(lapb);
569 lapb->state = LAPB_STATE_1;
570 break;
571
572 case LAPB_ILLEGAL:
573 #if LAPB_DEBUG > 1
574 printk(KERN_DEBUG "lapb: (%p) S3 RX ILLEGAL(%d)\n",
575 lapb->dev, frame->pf);
576 #endif
577 lapb->frmr_data = *frame;
578 lapb->frmr_type = LAPB_FRMR_W;
579 lapb_transmit_frmr(lapb);
580 #if LAPB_DEBUG > 0
581 printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
582 #endif
583 lapb_start_t1timer(lapb);
584 lapb_stop_t2timer(lapb);
585 lapb->state = LAPB_STATE_4;
586 lapb->n2count = 0;
587 break;
588 }
589
590 if (!queued)
591 kfree_skb(skb);
592 }
593
594 /*
595 * State machine for state 4, Frame Reject State.
596 * The handling of the timer(s) is in file lapb_timer.c.
597 */
lapb_state4_machine(struct lapb_cb * lapb,struct sk_buff * skb,struct lapb_frame * frame)598 static void lapb_state4_machine(struct lapb_cb *lapb, struct sk_buff *skb,
599 struct lapb_frame *frame)
600 {
601 switch (frame->type) {
602 case LAPB_SABM:
603 #if LAPB_DEBUG > 1
604 printk(KERN_DEBUG "lapb: (%p) S4 RX SABM(%d)\n",
605 lapb->dev, frame->pf);
606 #endif
607 if (lapb->mode & LAPB_EXTENDED) {
608 #if LAPB_DEBUG > 1
609 printk(KERN_DEBUG "lapb: (%p) S4 TX DM(%d)\n",
610 lapb->dev, frame->pf);
611 #endif
612 lapb_send_control(lapb, LAPB_DM, frame->pf,
613 LAPB_RESPONSE);
614 } else {
615 #if LAPB_DEBUG > 1
616 printk(KERN_DEBUG "lapb: (%p) S4 TX UA(%d)\n",
617 lapb->dev, frame->pf);
618 #endif
619 #if LAPB_DEBUG > 0
620 printk(KERN_DEBUG "lapb: (%p) S4 -> S3\n", lapb->dev);
621 #endif
622 lapb_send_control(lapb, LAPB_UA, frame->pf,
623 LAPB_RESPONSE);
624 lapb_stop_t1timer(lapb);
625 lapb_stop_t2timer(lapb);
626 lapb->state = LAPB_STATE_3;
627 lapb->condition = 0x00;
628 lapb->n2count = 0;
629 lapb->vs = 0;
630 lapb->vr = 0;
631 lapb->va = 0;
632 lapb_connect_indication(lapb, LAPB_OK);
633 }
634 break;
635
636 case LAPB_SABME:
637 #if LAPB_DEBUG > 1
638 printk(KERN_DEBUG "lapb: (%p) S4 RX SABME(%d)\n",
639 lapb->dev, frame->pf);
640 #endif
641 if (lapb->mode & LAPB_EXTENDED) {
642 #if LAPB_DEBUG > 1
643 printk(KERN_DEBUG "lapb: (%p) S4 TX UA(%d)\n",
644 lapb->dev, frame->pf);
645 #endif
646 #if LAPB_DEBUG > 0
647 printk(KERN_DEBUG "lapb: (%p) S4 -> S3\n", lapb->dev);
648 #endif
649 lapb_send_control(lapb, LAPB_UA, frame->pf,
650 LAPB_RESPONSE);
651 lapb_stop_t1timer(lapb);
652 lapb_stop_t2timer(lapb);
653 lapb->state = LAPB_STATE_3;
654 lapb->condition = 0x00;
655 lapb->n2count = 0;
656 lapb->vs = 0;
657 lapb->vr = 0;
658 lapb->va = 0;
659 lapb_connect_indication(lapb, LAPB_OK);
660 } else {
661 #if LAPB_DEBUG > 1
662 printk(KERN_DEBUG "lapb: (%p) S4 TX DM(%d)\n",
663 lapb->dev, frame->pf);
664 #endif
665 lapb_send_control(lapb, LAPB_DM, frame->pf,
666 LAPB_RESPONSE);
667 }
668 break;
669 }
670
671 kfree_skb(skb);
672 }
673
674 /*
675 * Process an incoming LAPB frame
676 */
lapb_data_input(struct lapb_cb * lapb,struct sk_buff * skb)677 void lapb_data_input(struct lapb_cb *lapb, struct sk_buff *skb)
678 {
679 struct lapb_frame frame;
680
681 if (lapb_decode(lapb, skb, &frame) < 0) {
682 kfree_skb(skb);
683 return;
684 }
685
686 switch (lapb->state) {
687 case LAPB_STATE_0:
688 lapb_state0_machine(lapb, skb, &frame); break;
689 case LAPB_STATE_1:
690 lapb_state1_machine(lapb, skb, &frame); break;
691 case LAPB_STATE_2:
692 lapb_state2_machine(lapb, skb, &frame); break;
693 case LAPB_STATE_3:
694 lapb_state3_machine(lapb, skb, &frame); break;
695 case LAPB_STATE_4:
696 lapb_state4_machine(lapb, skb, &frame); break;
697 }
698
699 lapb_kick(lapb);
700 }
701