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/errno.h>
23 #include <linux/types.h>
24 #include <linux/socket.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/inet.h>
33 #include <linux/netdevice.h>
34 #include <linux/skbuff.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,
47 struct x25_facilities *facilities,
48 unsigned long *vc_fac_mask)
50 unsigned char *p = skb->data;
51 unsigned int len = *p++;
56 switch (*p & X25_FAC_CLASS_MASK) {
60 facilities->reverse = p[1] & 0x01;
61 *vc_fac_mask |= X25_MASK_REVERSE;
63 case X25_FAC_THROUGHPUT:
64 facilities->throughput = p[1];
65 *vc_fac_mask |= X25_MASK_THROUGHPUT;
68 printk(KERN_DEBUG "X.25: unknown facility "
78 case X25_FAC_PACKET_SIZE:
79 facilities->pacsize_in = p[1];
80 facilities->pacsize_out = p[2];
81 *vc_fac_mask |= X25_MASK_PACKET_SIZE;
83 case X25_FAC_WINDOW_SIZE:
84 facilities->winsize_in = p[1];
85 facilities->winsize_out = p[2];
86 *vc_fac_mask |= X25_MASK_WINDOW_SIZE;
89 printk(KERN_DEBUG "X.25: unknown facility "
90 "%02X, values %02X, %02X\n",
98 printk(KERN_DEBUG "X.25: unknown facility %02X, "
99 "values %02X, %02X, %02X\n",
100 p[0], p[1], p[2], p[3]);
104 case X25_FAC_CLASS_D:
105 printk(KERN_DEBUG "X.25: unknown facility %02X, "
106 "length %d, values %02X, %02X, %02X, %02X\n",
107 p[0], p[1], p[2], p[3], p[4], p[5]);
114 return p - skb->data;
118 * Create a set of facilities.
120 int x25_create_facilities(unsigned char *buffer,
121 struct x25_facilities *facilities,
122 unsigned long facil_mask)
124 unsigned char *p = buffer + 1;
129 * Length of the facilities field in call_req or
130 * call_accept packets
133 len = 1; /* 1 byte for the length field */
137 if (facilities->reverse && (facil_mask & X25_MASK_REVERSE)) {
138 *p++ = X25_FAC_REVERSE;
139 *p++ = !!facilities->reverse;
142 if (facilities->throughput && (facil_mask & X25_MASK_THROUGHPUT)) {
143 *p++ = X25_FAC_THROUGHPUT;
144 *p++ = facilities->throughput;
147 if ((facilities->pacsize_in || facilities->pacsize_out) &&
148 (facil_mask & X25_MASK_PACKET_SIZE)) {
149 *p++ = X25_FAC_PACKET_SIZE;
150 *p++ = facilities->pacsize_in ? : facilities->pacsize_out;
151 *p++ = facilities->pacsize_out ? : facilities->pacsize_in;
154 if ((facilities->winsize_in || facilities->winsize_out) &&
155 (facil_mask & X25_MASK_WINDOW_SIZE)) {
156 *p++ = X25_FAC_WINDOW_SIZE;
157 *p++ = facilities->winsize_in ? : facilities->winsize_out;
158 *p++ = facilities->winsize_out ? : facilities->winsize_in;
168 * Try to reach a compromise on a set of facilities.
170 * The only real problem is with reverse charging.
172 int x25_negotiate_facilities(struct sk_buff *skb, struct sock *sk,
173 struct x25_facilities *new)
175 struct x25_opt *x25 = x25_sk(sk);
176 struct x25_facilities *ours = &x25->facilities;
177 struct x25_facilities theirs;
180 memset(&theirs, 0, sizeof(theirs));
181 memcpy(new, ours, sizeof(*new));
183 len = x25_parse_facilities(skb, &theirs, &x25->vc_facil_mask);
186 * They want reverse charging, we won't accept it.
188 if (theirs.reverse && ours->reverse) {
189 SOCK_DEBUG(sk, "X.25: rejecting reverse charging request");
193 new->reverse = theirs.reverse;
195 if (theirs.throughput) {
196 if (theirs.throughput < ours->throughput) {
197 SOCK_DEBUG(sk, "X.25: throughput negotiated down");
198 new->throughput = theirs.throughput;
202 if (theirs.pacsize_in && theirs.pacsize_out) {
203 if (theirs.pacsize_in < ours->pacsize_in) {
204 SOCK_DEBUG(sk, "X.25: packet size inwards negotiated down");
205 new->pacsize_in = theirs.pacsize_in;
207 if (theirs.pacsize_out < ours->pacsize_out) {
208 SOCK_DEBUG(sk, "X.25: packet size outwards negotiated down");
209 new->pacsize_out = theirs.pacsize_out;
213 if (theirs.winsize_in && theirs.winsize_out) {
214 if (theirs.winsize_in < ours->winsize_in) {
215 SOCK_DEBUG(sk, "X.25: window size inwards negotiated down");
216 new->winsize_in = theirs.winsize_in;
218 if (theirs.winsize_out < ours->winsize_out) {
219 SOCK_DEBUG(sk, "X.25: window size outwards negotiated down");
220 new->winsize_out = theirs.winsize_out;
228 * Limit values of certain facilities according to the capability of the
229 * currently attached x25 link.
231 void x25_limit_facilities(struct x25_facilities *facilities,
232 struct x25_neigh *nb)
236 if (facilities->winsize_in > 7) {
237 printk(KERN_DEBUG "X.25: incoming winsize limited to 7\n");
238 facilities->winsize_in = 7;
240 if (facilities->winsize_out > 7) {
241 facilities->winsize_out = 7;
242 printk( KERN_DEBUG "X.25: outgoing winsize limited to 7\n");