2 * X.25 Packet Layer release 002
4 * This is ALPHA test software. This code may break your machine,
5 * randomly fail to work with new releases, misbehave and/or generally
6 * screw up. It might even work.
8 * This code REQUIRES 2.1.15 or higher
11 * This module is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 * X.25 001 Split from x25_subr.c
18 * mar/20/00 Daniela Squassoni Disabling/enabling of facilities
20 * apr/14/05 Shaun Pereira - Allow fast select with no restriction
24 #define pr_fmt(fmt) "X25: " fmt
26 #include <linux/kernel.h>
27 #include <linux/string.h>
28 #include <linux/skbuff.h>
33 * x25_parse_facilities - Parse facilities from skb into the facilities structs
35 * @skb: sk_buff to parse
36 * @facilities: Regular facilities, updated as facilities are found
37 * @dte_facs: ITU DTE facilities, updated as DTE facilities are found
38 * @vc_fac_mask: mask is updated with all facilities found
41 * -1 - Parsing error, caller should drop call and clean up
42 * 0 - Parse OK, this skb has no facilities
43 * >0 - Parse OK, returns the length of the facilities header
46 int x25_parse_facilities(struct sk_buff
*skb
, struct x25_facilities
*facilities
,
47 struct x25_dte_facilities
*dte_facs
, unsigned long *vc_fac_mask
)
55 * The kernel knows which facilities were set on an incoming call but
56 * currently this information is not available to userspace. Here we
57 * give userspace who read incoming call facilities 0 length to indicate
60 dte_facs
->calling_len
= 0;
61 dte_facs
->called_len
= 0;
62 memset(dte_facs
->called_ae
, '\0', sizeof(dte_facs
->called_ae
));
63 memset(dte_facs
->calling_ae
, '\0', sizeof(dte_facs
->calling_ae
));
65 if (!pskb_may_pull(skb
, 1))
70 if (!pskb_may_pull(skb
, 1 + len
))
76 switch (*p
& X25_FAC_CLASS_MASK
) {
82 if((p
[1] & 0x81) == 0x81) {
83 facilities
->reverse
= p
[1] & 0x81;
84 *vc_fac_mask
|= X25_MASK_REVERSE
;
88 if((p
[1] & 0x01) == 0x01) {
89 facilities
->reverse
= p
[1] & 0x01;
90 *vc_fac_mask
|= X25_MASK_REVERSE
;
94 if((p
[1] & 0x80) == 0x80) {
95 facilities
->reverse
= p
[1] & 0x80;
96 *vc_fac_mask
|= X25_MASK_REVERSE
;
102 = X25_DEFAULT_REVERSE
;
103 *vc_fac_mask
|= X25_MASK_REVERSE
;
107 case X25_FAC_THROUGHPUT
:
108 facilities
->throughput
= p
[1];
109 *vc_fac_mask
|= X25_MASK_THROUGHPUT
;
114 pr_debug("unknown facility "
115 "%02X, value %02X\n",
122 case X25_FAC_CLASS_B
:
126 case X25_FAC_PACKET_SIZE
:
127 facilities
->pacsize_in
= p
[1];
128 facilities
->pacsize_out
= p
[2];
129 *vc_fac_mask
|= X25_MASK_PACKET_SIZE
;
131 case X25_FAC_WINDOW_SIZE
:
132 facilities
->winsize_in
= p
[1];
133 facilities
->winsize_out
= p
[2];
134 *vc_fac_mask
|= X25_MASK_WINDOW_SIZE
;
137 pr_debug("unknown facility "
138 "%02X, values %02X, %02X\n",
145 case X25_FAC_CLASS_C
:
148 pr_debug("unknown facility %02X, "
149 "values %02X, %02X, %02X\n",
150 p
[0], p
[1], p
[2], p
[3]);
154 case X25_FAC_CLASS_D
:
158 case X25_FAC_CALLING_AE
:
159 if (p
[1] > X25_MAX_DTE_FACIL_LEN
|| p
[1] <= 1)
161 if (p
[2] > X25_MAX_AE_LEN
)
163 dte_facs
->calling_len
= p
[2];
164 memcpy(dte_facs
->calling_ae
, &p
[3], p
[1] - 1);
165 *vc_fac_mask
|= X25_MASK_CALLING_AE
;
167 case X25_FAC_CALLED_AE
:
168 if (p
[1] > X25_MAX_DTE_FACIL_LEN
|| p
[1] <= 1)
170 if (p
[2] > X25_MAX_AE_LEN
)
172 dte_facs
->called_len
= p
[2];
173 memcpy(dte_facs
->called_ae
, &p
[3], p
[1] - 1);
174 *vc_fac_mask
|= X25_MASK_CALLED_AE
;
177 pr_debug("unknown facility %02X,"
178 "length %d\n", p
[0], p
[1]);
187 return p
- skb
->data
;
191 * Create a set of facilities.
193 int x25_create_facilities(unsigned char *buffer
,
194 struct x25_facilities
*facilities
,
195 struct x25_dte_facilities
*dte_facs
, unsigned long facil_mask
)
197 unsigned char *p
= buffer
+ 1;
202 * Length of the facilities field in call_req or
203 * call_accept packets
206 len
= 1; /* 1 byte for the length field */
210 if (facilities
->reverse
&& (facil_mask
& X25_MASK_REVERSE
)) {
211 *p
++ = X25_FAC_REVERSE
;
212 *p
++ = facilities
->reverse
;
215 if (facilities
->throughput
&& (facil_mask
& X25_MASK_THROUGHPUT
)) {
216 *p
++ = X25_FAC_THROUGHPUT
;
217 *p
++ = facilities
->throughput
;
220 if ((facilities
->pacsize_in
|| facilities
->pacsize_out
) &&
221 (facil_mask
& X25_MASK_PACKET_SIZE
)) {
222 *p
++ = X25_FAC_PACKET_SIZE
;
223 *p
++ = facilities
->pacsize_in
? : facilities
->pacsize_out
;
224 *p
++ = facilities
->pacsize_out
? : facilities
->pacsize_in
;
227 if ((facilities
->winsize_in
|| facilities
->winsize_out
) &&
228 (facil_mask
& X25_MASK_WINDOW_SIZE
)) {
229 *p
++ = X25_FAC_WINDOW_SIZE
;
230 *p
++ = facilities
->winsize_in
? : facilities
->winsize_out
;
231 *p
++ = facilities
->winsize_out
? : facilities
->winsize_in
;
234 if (facil_mask
& (X25_MASK_CALLING_AE
|X25_MASK_CALLED_AE
)) {
236 *p
++ = X25_DTE_SERVICES
;
239 if (dte_facs
->calling_len
&& (facil_mask
& X25_MASK_CALLING_AE
)) {
240 unsigned int bytecount
= (dte_facs
->calling_len
+ 1) >> 1;
241 *p
++ = X25_FAC_CALLING_AE
;
242 *p
++ = 1 + bytecount
;
243 *p
++ = dte_facs
->calling_len
;
244 memcpy(p
, dte_facs
->calling_ae
, bytecount
);
248 if (dte_facs
->called_len
&& (facil_mask
& X25_MASK_CALLED_AE
)) {
249 unsigned int bytecount
= (dte_facs
->called_len
% 2) ?
250 dte_facs
->called_len
/ 2 + 1 :
251 dte_facs
->called_len
/ 2;
252 *p
++ = X25_FAC_CALLED_AE
;
253 *p
++ = 1 + bytecount
;
254 *p
++ = dte_facs
->called_len
;
255 memcpy(p
, dte_facs
->called_ae
, bytecount
);
266 * Try to reach a compromise on a set of facilities.
268 * The only real problem is with reverse charging.
270 int x25_negotiate_facilities(struct sk_buff
*skb
, struct sock
*sk
,
271 struct x25_facilities
*new, struct x25_dte_facilities
*dte
)
273 struct x25_sock
*x25
= x25_sk(sk
);
274 struct x25_facilities
*ours
= &x25
->facilities
;
275 struct x25_facilities theirs
;
278 memset(&theirs
, 0, sizeof(theirs
));
279 memcpy(new, ours
, sizeof(*new));
280 memset(dte
, 0, sizeof(*dte
));
282 len
= x25_parse_facilities(skb
, &theirs
, dte
, &x25
->vc_facil_mask
);
287 * They want reverse charging, we won't accept it.
289 if ((theirs
.reverse
& 0x01 ) && (ours
->reverse
& 0x01)) {
290 SOCK_DEBUG(sk
, "X.25: rejecting reverse charging request\n");
294 new->reverse
= theirs
.reverse
;
296 if (theirs
.throughput
) {
297 int theirs_in
= theirs
.throughput
& 0x0f;
298 int theirs_out
= theirs
.throughput
& 0xf0;
299 int ours_in
= ours
->throughput
& 0x0f;
300 int ours_out
= ours
->throughput
& 0xf0;
301 if (!ours_in
|| theirs_in
< ours_in
) {
302 SOCK_DEBUG(sk
, "X.25: inbound throughput negotiated\n");
303 new->throughput
= (new->throughput
& 0xf0) | theirs_in
;
305 if (!ours_out
|| theirs_out
< ours_out
) {
307 "X.25: outbound throughput negotiated\n");
308 new->throughput
= (new->throughput
& 0x0f) | theirs_out
;
312 if (theirs
.pacsize_in
&& theirs
.pacsize_out
) {
313 if (theirs
.pacsize_in
< ours
->pacsize_in
) {
314 SOCK_DEBUG(sk
, "X.25: packet size inwards negotiated down\n");
315 new->pacsize_in
= theirs
.pacsize_in
;
317 if (theirs
.pacsize_out
< ours
->pacsize_out
) {
318 SOCK_DEBUG(sk
, "X.25: packet size outwards negotiated down\n");
319 new->pacsize_out
= theirs
.pacsize_out
;
323 if (theirs
.winsize_in
&& theirs
.winsize_out
) {
324 if (theirs
.winsize_in
< ours
->winsize_in
) {
325 SOCK_DEBUG(sk
, "X.25: window size inwards negotiated down\n");
326 new->winsize_in
= theirs
.winsize_in
;
328 if (theirs
.winsize_out
< ours
->winsize_out
) {
329 SOCK_DEBUG(sk
, "X.25: window size outwards negotiated down\n");
330 new->winsize_out
= theirs
.winsize_out
;
338 * Limit values of certain facilities according to the capability of the
339 * currently attached x25 link.
341 void x25_limit_facilities(struct x25_facilities
*facilities
,
342 struct x25_neigh
*nb
)
346 if (facilities
->winsize_in
> 7) {
347 pr_debug("incoming winsize limited to 7\n");
348 facilities
->winsize_in
= 7;
350 if (facilities
->winsize_out
> 7) {
351 facilities
->winsize_out
= 7;
352 pr_debug("outgoing winsize limited to 7\n");