1 /*
2 * X.25 Packet Layer release 002
3 *
4 * This is ALPHA test software. This code may break your machine, randomly fail to work with new
5 * releases, misbehave and/or generally screw up. It might even work.
6 *
7 * This code REQUIRES 2.1.15 or higher
8 *
9 * This module:
10 * This module is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 *
15 * History
16 * X.25 001 Jonathan Naylor Started coding.
17 * 2000-09-04 Henner Eisen Prevent freeing a dangling skb.
18 */
19
20 #include <linux/config.h>
21 #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
22 #include <linux/errno.h>
23 #include <linux/types.h>
24 #include <linux/socket.h>
25 #include <linux/in.h>
26 #include <linux/kernel.h>
27 #include <linux/sched.h>
28 #include <linux/timer.h>
29 #include <linux/string.h>
30 #include <linux/sockios.h>
31 #include <linux/net.h>
32 #include <linux/stat.h>
33 #include <linux/inet.h>
34 #include <linux/netdevice.h>
35 #include <linux/skbuff.h>
36 #include <net/sock.h>
37 #include <asm/segment.h>
38 #include <asm/system.h>
39 #include <asm/uaccess.h>
40 #include <linux/fcntl.h>
41 #include <linux/termios.h> /* For TIOCINQ/OUTQ */
42 #include <linux/mm.h>
43 #include <linux/interrupt.h>
44 #include <linux/notifier.h>
45 #include <linux/proc_fs.h>
46 #include <linux/if_arp.h>
47 #include <net/x25.h>
48
49 static int x25_receive_data(struct sk_buff *skb, struct x25_neigh *neigh)
50 {
51 struct sock *sk;
52 unsigned short frametype;
53 unsigned int lci;
54
55 frametype = skb->data[2];
56 lci = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF);
57
58 /*
59 * LCI of zero is always for us, and its always a link control
60 * frame.
61 */
62 if (lci == 0) {
63 x25_link_control(skb, neigh, frametype);
64 return 0;
65 }
66
67 /*
68 * Find an existing socket.
69 */
70 if ((sk = x25_find_socket(lci, neigh)) != NULL) {
71 int queued = 1;
72
73 skb->h.raw = skb->data;
74 bh_lock_sock(sk);
75 if (!sk->lock.users) {
76 queued = x25_process_rx_frame(sk, skb);
77 } else {
78 sk_add_backlog(sk, skb);
79 }
80 bh_unlock_sock(sk);
81 return queued;
82 }
83
84 /*
85 * Is is a Call Request ? if so process it.
86 */
87 if (frametype == X25_CALL_REQUEST)
88 return x25_rx_call_request(skb, neigh, lci);
89
90 /*
91 * Its not a Call Request, nor is it a control frame.
92 * Let caller throw it away.
93 */
94 /*
95 x25_transmit_clear_request(neigh, lci, 0x0D);
96 */
97 printk(KERN_DEBUG "x25_receive_data(): unknown frame type %2x\n",frametype);
98
99 return 0;
100 }
101
102 int x25_lapb_receive_frame(struct sk_buff *skb, struct net_device *dev, struct packet_type *ptype)
103 {
104 struct x25_neigh *neigh;
105 int queued;
106
107 skb->sk = NULL;
108
109 /*
110 * Packet received from unrecognised device, throw it away.
111 */
112 if ((neigh = x25_get_neigh(dev)) == NULL) {
113 printk(KERN_DEBUG "X.25: unknown neighbour - %s\n", dev->name);
114 kfree_skb(skb);
115 return 0;
116 }
117
118 switch (skb->data[0]) {
119 case 0x00:
120 skb_pull(skb, 1);
121 queued = x25_receive_data(skb, neigh);
122 if( ! queued )
123 /* We need to free the skb ourselves because
124 * net_bh() won't care about our return code.
125 */
126 kfree_skb(skb);
127 return 0;
128
129 case 0x01:
130 x25_link_established(neigh);
131 kfree_skb(skb);
132 return 0;
133
134 case 0x02:
135 x25_link_terminated(neigh);
136 kfree_skb(skb);
137 return 0;
138
139 case 0x03:
140 kfree_skb(skb);
141 return 0;
142
143 default:
144 kfree_skb(skb);
145 return 0;
146 }
147 }
148
149 int x25_llc_receive_frame(struct sk_buff *skb, struct net_device *dev, struct packet_type *ptype)
150 {
151 struct x25_neigh *neigh;
152
153 skb->sk = NULL;
154
155 /*
156 * Packet received from unrecognised device, throw it away.
157 */
158 if ((neigh = x25_get_neigh(dev)) == NULL) {
159 printk(KERN_DEBUG "X.25: unknown_neighbour - %s\n", dev->name);
160 kfree_skb(skb);
161 return 0;
162 }
163
164 return x25_receive_data(skb, neigh);
165 }
166
167 void x25_establish_link(struct x25_neigh *neigh)
168 {
169 struct sk_buff *skb;
170 unsigned char *ptr;
171
172 switch (neigh->dev->type) {
173 case ARPHRD_X25:
174 if ((skb = alloc_skb(1, GFP_ATOMIC)) == NULL) {
175 printk(KERN_ERR "x25_dev: out of memory\n");
176 return;
177 }
178 ptr = skb_put(skb, 1);
179 *ptr = 0x01;
180 break;
181
182 #if defined(CONFIG_LLC) || defined(CONFIG_LLC_MODULE)
183 case ARPHRD_ETHER:
184 return;
185 #endif
186 default:
187 return;
188 }
189
190 skb->protocol = htons(ETH_P_X25);
191 skb->dev = neigh->dev;
192
193 dev_queue_xmit(skb);
194 }
195
196 void x25_terminate_link(struct x25_neigh *neigh)
197 {
198 struct sk_buff *skb;
199 unsigned char *ptr;
200
201 switch (neigh->dev->type) {
202 case ARPHRD_X25:
203 if ((skb = alloc_skb(1, GFP_ATOMIC)) == NULL) {
204 printk(KERN_ERR "x25_dev: out of memory\n");
205 return;
206 }
207 ptr = skb_put(skb, 1);
208 *ptr = 0x02;
209 break;
210
211 #if defined(CONFIG_LLC) || defined(CONFIG_LLC_MODULE)
212 case ARPHRD_ETHER:
213 return;
214 #endif
215 default:
216 return;
217 }
218
219 skb->protocol = htons(ETH_P_X25);
220 skb->dev = neigh->dev;
221
222 dev_queue_xmit(skb);
223 }
224
225 void x25_send_frame(struct sk_buff *skb, struct x25_neigh *neigh)
226 {
227 unsigned char *dptr;
228
229 skb->nh.raw = skb->data;
230
231 switch (neigh->dev->type) {
232 case ARPHRD_X25:
233 dptr = skb_push(skb, 1);
234 *dptr = 0x00;
235 break;
236
237 #if defined(CONFIG_LLC) || defined(CONFIG_LLC_MODULE)
238 case ARPHRD_ETHER:
239 kfree_skb(skb);
240 return;
241 #endif
242 default:
243 kfree_skb(skb);
244 return;
245 }
246
247 skb->protocol = htons(ETH_P_X25);
248 skb->dev = neigh->dev;
249
250 dev_queue_xmit(skb);
251 }
252
253 #endif
254
255
256
257
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.