2 * X.25 Packet Layer release 002
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.
7 * This code REQUIRES 2.1.15 or higher
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.
16 * X.25 001 Split from x25_subr.c
19 #include <linux/config.h>
20 #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
21 #include <linux/errno.h>
22 #include <linux/types.h>
23 #include <linux/socket.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/timer.h>
28 #include <linux/string.h>
29 #include <linux/sockios.h>
30 #include <linux/net.h>
31 #include <linux/inet.h>
32 #include <linux/netdevice.h>
33 #include <linux/skbuff.h>
35 #include <asm/segment.h>
36 #include <asm/system.h>
37 #include <linux/fcntl.h>
39 #include <linux/interrupt.h>
43 * Parse a set of facilities into the facilities structure. Unrecognised
44 * facilities are written to the debug log file.
46 int x25_parse_facilities(struct sk_buff
*skb
, struct x25_facilities
*facilities
)
49 unsigned char *p
= skb
->data
;
54 switch (*p
& X25_FAC_CLASS_MASK
) {
58 facilities
->reverse
= (p
[1] & 0x01);
60 case X25_FAC_THROUGHPUT
:
61 facilities
->throughput
= p
[1];
64 printk(KERN_DEBUG
"X.25: unknown facility %02X, value %02X\n", p
[0], p
[1]);
73 case X25_FAC_PACKET_SIZE
:
74 facilities
->pacsize_in
= p
[1];
75 facilities
->pacsize_out
= p
[2];
77 case X25_FAC_WINDOW_SIZE
:
78 facilities
->winsize_in
= p
[1];
79 facilities
->winsize_out
= p
[2];
82 printk(KERN_DEBUG
"X.25: unknown facility %02X, values %02X, %02X\n", p
[0], p
[1], p
[2]);
90 printk(KERN_DEBUG
"X.25: unknown facility %02X, values %02X, %02X, %02X\n", p
[0], p
[1], p
[2], p
[3]);
96 printk(KERN_DEBUG
"X.25: unknown facility %02X, length %d, values %02X, %02X, %02X, %02X\n", p
[0], p
[1], p
[2], p
[3], p
[4], p
[5]);
103 return p
- skb
->data
;
107 * Create a set of facilities.
109 int x25_create_facilities(unsigned char *buffer
, struct x25_facilities
*facilities
)
111 unsigned char *p
= buffer
+ 1;
114 if (facilities
->reverse
!= 0) {
115 *p
++ = X25_FAC_REVERSE
;
116 *p
++ = (facilities
->reverse
) ? 0x01 : 0x00;
119 if (facilities
->throughput
!= 0) {
120 *p
++ = X25_FAC_THROUGHPUT
;
121 *p
++ = facilities
->throughput
;
124 if (facilities
->pacsize_in
!= 0 || facilities
->pacsize_out
!= 0) {
125 *p
++ = X25_FAC_PACKET_SIZE
;
126 *p
++ = (facilities
->pacsize_in
== 0) ? facilities
->pacsize_out
: facilities
->pacsize_in
;
127 *p
++ = (facilities
->pacsize_out
== 0) ? facilities
->pacsize_in
: facilities
->pacsize_out
;
130 if (facilities
->winsize_in
!= 0 || facilities
->winsize_out
!= 0) {
131 *p
++ = X25_FAC_WINDOW_SIZE
;
132 *p
++ = (facilities
->winsize_in
== 0) ? facilities
->winsize_out
: facilities
->winsize_in
;
133 *p
++ = (facilities
->winsize_out
== 0) ? facilities
->winsize_in
: facilities
->winsize_out
;
143 * Try to reach a compromise on a set of facilities.
145 * The only real problem is with reverse charging.
147 int x25_negotiate_facilities(struct sk_buff
*skb
, struct sock
*sk
, struct x25_facilities
*new)
149 struct x25_facilities
*ours
;
150 struct x25_facilities theirs
;
153 memset(&theirs
, 0x00, sizeof(struct x25_facilities
));
155 ours
= &sk
->protinfo
.x25
->facilities
;
159 len
= x25_parse_facilities(skb
, &theirs
);
162 * They want reverse charging, we won't accept it.
164 if (theirs
.reverse
!= 0 && ours
->reverse
== 0) {
165 SOCK_DEBUG(sk
, "X.25: rejecting reverse charging request");
169 new->reverse
= theirs
.reverse
;
171 if (theirs
.throughput
!= 0) {
172 if (theirs
.throughput
< ours
->throughput
) {
173 SOCK_DEBUG(sk
, "X.25: throughput negotiated down");
174 new->throughput
= theirs
.throughput
;
178 if (theirs
.pacsize_in
!= 0 && theirs
.pacsize_out
!= 0) {
179 if (theirs
.pacsize_in
< ours
->pacsize_in
) {
180 SOCK_DEBUG(sk
, "X.25: packet size inwards negotiated down");
181 new->pacsize_in
= theirs
.pacsize_in
;
183 if (theirs
.pacsize_out
< ours
->pacsize_out
) {
184 SOCK_DEBUG(sk
, "X.25: packet size outwards negotiated down");
185 new->pacsize_out
= theirs
.pacsize_out
;
189 if (theirs
.winsize_in
!= 0 && theirs
.winsize_out
!= 0) {
190 if (theirs
.winsize_in
< ours
->winsize_in
) {
191 SOCK_DEBUG(sk
, "X.25: window size inwards negotiated down");
192 new->winsize_in
= theirs
.winsize_in
;
194 if (theirs
.winsize_out
< ours
->winsize_out
) {
195 SOCK_DEBUG(sk
, "X.25: window size outwards negotiated down");
196 new->winsize_out
= theirs
.winsize_out
;
204 * Limit values of certain facilities according to the capability of the
205 * currently attached x25 link.
207 void x25_limit_facilities(struct x25_facilities
*facilities
,
208 struct x25_neigh
*neighbour
)
211 if( ! neighbour
->extended
){
212 if( facilities
->winsize_in
> 7 ){
213 printk(KERN_DEBUG
"X.25: incoming winsize limited to 7\n");
214 facilities
->winsize_in
= 7;
216 if( facilities
->winsize_out
> 7 ){
217 facilities
->winsize_out
= 7;
218 printk( KERN_DEBUG
"X.25: outgoing winsize limited to 7\n");