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/timer.h>
25 #include <linux/string.h>
26 #include <linux/sockios.h>
27 #include <linux/net.h>
28 #include <linux/inet.h>
29 #include <linux/skbuff.h>
30 #include <linux/slab.h>
32 #include <linux/uaccess.h>
33 #include <linux/fcntl.h>
35 #include <linux/interrupt.h>
39 * This procedure is passed a buffer descriptor for an iframe. It builds
40 * the rest of the control part of the frame and then writes it out.
42 static void lapb_send_iframe(struct lapb_cb *lapb, struct sk_buff *skb, int poll_bit)
49 if (lapb->mode & LAPB_EXTENDED) {
50 frame = skb_push(skb, 2);
53 frame[0] |= lapb->vs << 1;
54 frame[1] = poll_bit ? LAPB_EPF : 0;
55 frame[1] |= lapb->vr << 1;
57 frame = skb_push(skb, 1);
60 *frame |= poll_bit ? LAPB_SPF : 0;
61 *frame |= lapb->vr << 5;
62 *frame |= lapb->vs << 1;
65 lapb_dbg(1, "(%p) S%d TX I(%d) S%d R%d\n",
66 lapb->dev, lapb->state, poll_bit, lapb->vs, lapb->vr);
68 lapb_transmit_buffer(lapb, skb, LAPB_COMMAND);
71 void lapb_kick(struct lapb_cb *lapb)
73 struct sk_buff *skb, *skbn;
74 unsigned short modulus, start, end;
76 modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS : LAPB_SMODULUS;
77 start = !skb_peek(&lapb->ack_queue) ? lapb->va : lapb->vs;
78 end = (lapb->va + lapb->window) % modulus;
80 if (!(lapb->condition & LAPB_PEER_RX_BUSY_CONDITION) &&
81 start != end && skb_peek(&lapb->write_queue)) {
85 * Dequeue the frame and copy it.
87 skb = skb_dequeue(&lapb->write_queue);
90 skbn = skb_copy(skb, GFP_ATOMIC);
92 skb_queue_head(&lapb->write_queue, skb);
97 skb_set_owner_w(skbn, skb->sk);
100 * Transmit the frame copy.
102 lapb_send_iframe(lapb, skbn, LAPB_POLLOFF);
104 lapb->vs = (lapb->vs + 1) % modulus;
107 * Requeue the original data frame.
109 skb_queue_tail(&lapb->ack_queue, skb);
111 } while (lapb->vs != end && (skb = skb_dequeue(&lapb->write_queue)) != NULL);
113 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
115 if (!lapb_t1timer_running(lapb))
116 lapb_start_t1timer(lapb);
120 void lapb_transmit_buffer(struct lapb_cb *lapb, struct sk_buff *skb, int type)
124 ptr = skb_push(skb, 1);
126 if (lapb->mode & LAPB_MLP) {
127 if (lapb->mode & LAPB_DCE) {
128 if (type == LAPB_COMMAND)
130 if (type == LAPB_RESPONSE)
133 if (type == LAPB_COMMAND)
135 if (type == LAPB_RESPONSE)
139 if (lapb->mode & LAPB_DCE) {
140 if (type == LAPB_COMMAND)
142 if (type == LAPB_RESPONSE)
145 if (type == LAPB_COMMAND)
147 if (type == LAPB_RESPONSE)
152 lapb_dbg(2, "(%p) S%d TX %3ph\n", lapb->dev, lapb->state, skb->data);
154 if (!lapb_data_transmit(lapb, skb))
158 void lapb_establish_data_link(struct lapb_cb *lapb)
160 lapb->condition = 0x00;
163 if (lapb->mode & LAPB_EXTENDED) {
164 lapb_dbg(1, "(%p) S%d TX SABME(1)\n", lapb->dev, lapb->state);
165 lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
167 lapb_dbg(1, "(%p) S%d TX SABM(1)\n", lapb->dev, lapb->state);
168 lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
171 lapb_start_t1timer(lapb);
172 lapb_stop_t2timer(lapb);
175 void lapb_enquiry_response(struct lapb_cb *lapb)
177 lapb_dbg(1, "(%p) S%d TX RR(1) R%d\n",
178 lapb->dev, lapb->state, lapb->vr);
180 lapb_send_control(lapb, LAPB_RR, LAPB_POLLON, LAPB_RESPONSE);
182 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
185 void lapb_timeout_response(struct lapb_cb *lapb)
187 lapb_dbg(1, "(%p) S%d TX RR(0) R%d\n",
188 lapb->dev, lapb->state, lapb->vr);
189 lapb_send_control(lapb, LAPB_RR, LAPB_POLLOFF, LAPB_RESPONSE);
191 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
194 void lapb_check_iframes_acked(struct lapb_cb *lapb, unsigned short nr)
196 if (lapb->vs == nr) {
197 lapb_frames_acked(lapb, nr);
198 lapb_stop_t1timer(lapb);
200 } else if (lapb->va != nr) {
201 lapb_frames_acked(lapb, nr);
202 lapb_start_t1timer(lapb);
206 void lapb_check_need_response(struct lapb_cb *lapb, int type, int pf)
208 if (type == LAPB_COMMAND && pf)
209 lapb_enquiry_response(lapb);