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
22 #include <linux/kernel.h>
23 #include <linux/string.h>
24 #include <linux/skbuff.h>
29 * Parse a set of facilities into the facilities structure. Unrecognised
30 * facilities are written to the debug log file.
32 int x25_parse_facilities(struct sk_buff
*skb
,
33 struct x25_facilities
*facilities
,
34 unsigned long *vc_fac_mask
)
36 unsigned char *p
= skb
->data
;
37 unsigned int len
= *p
++;
42 switch (*p
& X25_FAC_CLASS_MASK
) {
46 facilities
->reverse
= p
[1] & 0x01;
47 *vc_fac_mask
|= X25_MASK_REVERSE
;
49 case X25_FAC_THROUGHPUT
:
50 facilities
->throughput
= p
[1];
51 *vc_fac_mask
|= X25_MASK_THROUGHPUT
;
54 printk(KERN_DEBUG
"X.25: unknown facility "
64 case X25_FAC_PACKET_SIZE
:
65 facilities
->pacsize_in
= p
[1];
66 facilities
->pacsize_out
= p
[2];
67 *vc_fac_mask
|= X25_MASK_PACKET_SIZE
;
69 case X25_FAC_WINDOW_SIZE
:
70 facilities
->winsize_in
= p
[1];
71 facilities
->winsize_out
= p
[2];
72 *vc_fac_mask
|= X25_MASK_WINDOW_SIZE
;
75 printk(KERN_DEBUG
"X.25: unknown facility "
76 "%02X, values %02X, %02X\n",
84 printk(KERN_DEBUG
"X.25: unknown facility %02X, "
85 "values %02X, %02X, %02X\n",
86 p
[0], p
[1], p
[2], p
[3]);
91 printk(KERN_DEBUG
"X.25: unknown facility %02X, "
92 "length %d, values %02X, %02X, %02X, %02X\n",
93 p
[0], p
[1], p
[2], p
[3], p
[4], p
[5]);
100 return p
- skb
->data
;
104 * Create a set of facilities.
106 int x25_create_facilities(unsigned char *buffer
,
107 struct x25_facilities
*facilities
,
108 unsigned long facil_mask
)
110 unsigned char *p
= buffer
+ 1;
115 * Length of the facilities field in call_req or
116 * call_accept packets
119 len
= 1; /* 1 byte for the length field */
123 if (facilities
->reverse
&& (facil_mask
& X25_MASK_REVERSE
)) {
124 *p
++ = X25_FAC_REVERSE
;
125 *p
++ = !!facilities
->reverse
;
128 if (facilities
->throughput
&& (facil_mask
& X25_MASK_THROUGHPUT
)) {
129 *p
++ = X25_FAC_THROUGHPUT
;
130 *p
++ = facilities
->throughput
;
133 if ((facilities
->pacsize_in
|| facilities
->pacsize_out
) &&
134 (facil_mask
& X25_MASK_PACKET_SIZE
)) {
135 *p
++ = X25_FAC_PACKET_SIZE
;
136 *p
++ = facilities
->pacsize_in
? : facilities
->pacsize_out
;
137 *p
++ = facilities
->pacsize_out
? : facilities
->pacsize_in
;
140 if ((facilities
->winsize_in
|| facilities
->winsize_out
) &&
141 (facil_mask
& X25_MASK_WINDOW_SIZE
)) {
142 *p
++ = X25_FAC_WINDOW_SIZE
;
143 *p
++ = facilities
->winsize_in
? : facilities
->winsize_out
;
144 *p
++ = facilities
->winsize_out
? : facilities
->winsize_in
;
154 * Try to reach a compromise on a set of facilities.
156 * The only real problem is with reverse charging.
158 int x25_negotiate_facilities(struct sk_buff
*skb
, struct sock
*sk
,
159 struct x25_facilities
*new)
161 struct x25_sock
*x25
= x25_sk(sk
);
162 struct x25_facilities
*ours
= &x25
->facilities
;
163 struct x25_facilities theirs
;
166 memset(&theirs
, 0, sizeof(theirs
));
167 memcpy(new, ours
, sizeof(*new));
169 len
= x25_parse_facilities(skb
, &theirs
, &x25
->vc_facil_mask
);
172 * They want reverse charging, we won't accept it.
174 if (theirs
.reverse
&& ours
->reverse
) {
175 SOCK_DEBUG(sk
, "X.25: rejecting reverse charging request");
179 new->reverse
= theirs
.reverse
;
181 if (theirs
.throughput
) {
182 if (theirs
.throughput
< ours
->throughput
) {
183 SOCK_DEBUG(sk
, "X.25: throughput negotiated down");
184 new->throughput
= theirs
.throughput
;
188 if (theirs
.pacsize_in
&& theirs
.pacsize_out
) {
189 if (theirs
.pacsize_in
< ours
->pacsize_in
) {
190 SOCK_DEBUG(sk
, "X.25: packet size inwards negotiated down");
191 new->pacsize_in
= theirs
.pacsize_in
;
193 if (theirs
.pacsize_out
< ours
->pacsize_out
) {
194 SOCK_DEBUG(sk
, "X.25: packet size outwards negotiated down");
195 new->pacsize_out
= theirs
.pacsize_out
;
199 if (theirs
.winsize_in
&& theirs
.winsize_out
) {
200 if (theirs
.winsize_in
< ours
->winsize_in
) {
201 SOCK_DEBUG(sk
, "X.25: window size inwards negotiated down");
202 new->winsize_in
= theirs
.winsize_in
;
204 if (theirs
.winsize_out
< ours
->winsize_out
) {
205 SOCK_DEBUG(sk
, "X.25: window size outwards negotiated down");
206 new->winsize_out
= theirs
.winsize_out
;
214 * Limit values of certain facilities according to the capability of the
215 * currently attached x25 link.
217 void x25_limit_facilities(struct x25_facilities
*facilities
,
218 struct x25_neigh
*nb
)
222 if (facilities
->winsize_in
> 7) {
223 printk(KERN_DEBUG
"X.25: incoming winsize limited to 7\n");
224 facilities
->winsize_in
= 7;
226 if (facilities
->winsize_out
> 7) {
227 facilities
->winsize_out
= 7;
228 printk( KERN_DEBUG
"X.25: outgoing winsize limited to 7\n");