~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/lapb/lapb_out.c

Version: ~ [ linux-5.3 ] ~ [ linux-5.2.15 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.73 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.144 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.193 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.193 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.73 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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/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>
 31 #include <net/sock.h>
 32 #include <linux/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  *  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.
 41  */
 42 static void lapb_send_iframe(struct lapb_cb *lapb, struct sk_buff *skb, int poll_bit)
 43 {
 44         unsigned char *frame;
 45 
 46         if (!skb)
 47                 return;
 48 
 49         if (lapb->mode & LAPB_EXTENDED) {
 50                 frame = skb_push(skb, 2);
 51 
 52                 frame[0] = LAPB_I;
 53                 frame[0] |= lapb->vs << 1;
 54                 frame[1] = poll_bit ? LAPB_EPF : 0;
 55                 frame[1] |= lapb->vr << 1;
 56         } else {
 57                 frame = skb_push(skb, 1);
 58 
 59                 *frame = LAPB_I;
 60                 *frame |= poll_bit ? LAPB_SPF : 0;
 61                 *frame |= lapb->vr << 5;
 62                 *frame |= lapb->vs << 1;
 63         }
 64 
 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);
 67 
 68         lapb_transmit_buffer(lapb, skb, LAPB_COMMAND);
 69 }
 70 
 71 void lapb_kick(struct lapb_cb *lapb)
 72 {
 73         struct sk_buff *skb, *skbn;
 74         unsigned short modulus, start, end;
 75 
 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;
 79 
 80         if (!(lapb->condition & LAPB_PEER_RX_BUSY_CONDITION) &&
 81             start != end && skb_peek(&lapb->write_queue)) {
 82                 lapb->vs = start;
 83 
 84                 /*
 85                  * Dequeue the frame and copy it.
 86                  */
 87                 skb = skb_dequeue(&lapb->write_queue);
 88 
 89                 do {
 90                         if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
 91                                 skb_queue_head(&lapb->write_queue, skb);
 92                                 break;
 93                         }
 94 
 95                         if (skb->sk)
 96                                 skb_set_owner_w(skbn, skb->sk);
 97 
 98                         /*
 99                          * Transmit the frame copy.
100                          */
101                         lapb_send_iframe(lapb, skbn, LAPB_POLLOFF);
102 
103                         lapb->vs = (lapb->vs + 1) % modulus;
104 
105                         /*
106                          * Requeue the original data frame.
107                          */
108                         skb_queue_tail(&lapb->ack_queue, skb);
109 
110                 } while (lapb->vs != end && (skb = skb_dequeue(&lapb->write_queue)) != NULL);
111 
112                 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
113 
114                 if (!lapb_t1timer_running(lapb))
115                         lapb_start_t1timer(lapb);
116         }
117 }
118 
119 void lapb_transmit_buffer(struct lapb_cb *lapb, struct sk_buff *skb, int type)
120 {
121         unsigned char *ptr;
122 
123         ptr = skb_push(skb, 1);
124 
125         if (lapb->mode & LAPB_MLP) {
126                 if (lapb->mode & LAPB_DCE) {
127                         if (type == LAPB_COMMAND)
128                                 *ptr = LAPB_ADDR_C;
129                         if (type == LAPB_RESPONSE)
130                                 *ptr = LAPB_ADDR_D;
131                 } else {
132                         if (type == LAPB_COMMAND)
133                                 *ptr = LAPB_ADDR_D;
134                         if (type == LAPB_RESPONSE)
135                                 *ptr = LAPB_ADDR_C;
136                 }
137         } else {
138                 if (lapb->mode & LAPB_DCE) {
139                         if (type == LAPB_COMMAND)
140                                 *ptr = LAPB_ADDR_A;
141                         if (type == LAPB_RESPONSE)
142                                 *ptr = LAPB_ADDR_B;
143                 } else {
144                         if (type == LAPB_COMMAND)
145                                 *ptr = LAPB_ADDR_B;
146                         if (type == LAPB_RESPONSE)
147                                 *ptr = LAPB_ADDR_A;
148                 }
149         }
150 
151         lapb_dbg(2, "(%p) S%d TX %3ph\n", lapb->dev, lapb->state, skb->data);
152 
153         if (!lapb_data_transmit(lapb, skb))
154                 kfree_skb(skb);
155 }
156 
157 void lapb_establish_data_link(struct lapb_cb *lapb)
158 {
159         lapb->condition = 0x00;
160         lapb->n2count   = 0;
161 
162         if (lapb->mode & LAPB_EXTENDED) {
163                 lapb_dbg(1, "(%p) S%d TX SABME(1)\n", lapb->dev, lapb->state);
164                 lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
165         } else {
166                 lapb_dbg(1, "(%p) S%d TX SABM(1)\n", lapb->dev, lapb->state);
167                 lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
168         }
169 
170         lapb_start_t1timer(lapb);
171         lapb_stop_t2timer(lapb);
172 }
173 
174 void lapb_enquiry_response(struct lapb_cb *lapb)
175 {
176         lapb_dbg(1, "(%p) S%d TX RR(1) R%d\n",
177                  lapb->dev, lapb->state, lapb->vr);
178 
179         lapb_send_control(lapb, LAPB_RR, LAPB_POLLON, LAPB_RESPONSE);
180 
181         lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
182 }
183 
184 void lapb_timeout_response(struct lapb_cb *lapb)
185 {
186         lapb_dbg(1, "(%p) S%d TX RR(0) R%d\n",
187                  lapb->dev, lapb->state, lapb->vr);
188         lapb_send_control(lapb, LAPB_RR, LAPB_POLLOFF, LAPB_RESPONSE);
189 
190         lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
191 }
192 
193 void lapb_check_iframes_acked(struct lapb_cb *lapb, unsigned short nr)
194 {
195         if (lapb->vs == nr) {
196                 lapb_frames_acked(lapb, nr);
197                 lapb_stop_t1timer(lapb);
198                 lapb->n2count = 0;
199         } else if (lapb->va != nr) {
200                 lapb_frames_acked(lapb, nr);
201                 lapb_start_t1timer(lapb);
202         }
203 }
204 
205 void lapb_check_need_response(struct lapb_cb *lapb, int type, int pf)
206 {
207         if (type == LAPB_COMMAND && pf)
208                 lapb_enquiry_response(lapb);
209 }
210 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp