blob: 1479cb4a41fc988fba91183c512c950f07db71d2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Declarations of X.25 Packet Layer type objects.
3 *
4 * History
5 * nov/17/96 Jonathan Naylor Initial version.
6 * mar/20/00 Daniela Squassoni Disabling/enabling of facilities
7 * negotiation.
8 */
9
10#ifndef _X25_H
11#define _X25_H
12#include <linux/x25.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <net/sock.h>
15
16#define X25_ADDR_LEN 16
17
18#define X25_MAX_L2_LEN 18 /* 802.2 LLC */
19
20#define X25_STD_MIN_LEN 3
21#define X25_EXT_MIN_LEN 4
22
23#define X25_GFI_SEQ_MASK 0x30
24#define X25_GFI_STDSEQ 0x10
25#define X25_GFI_EXTSEQ 0x20
26
27#define X25_Q_BIT 0x80
28#define X25_D_BIT 0x40
29#define X25_STD_M_BIT 0x10
30#define X25_EXT_M_BIT 0x01
31
32#define X25_CALL_REQUEST 0x0B
33#define X25_CALL_ACCEPTED 0x0F
34#define X25_CLEAR_REQUEST 0x13
35#define X25_CLEAR_CONFIRMATION 0x17
36#define X25_DATA 0x00
37#define X25_INTERRUPT 0x23
38#define X25_INTERRUPT_CONFIRMATION 0x27
39#define X25_RR 0x01
40#define X25_RNR 0x05
41#define X25_REJ 0x09
42#define X25_RESET_REQUEST 0x1B
43#define X25_RESET_CONFIRMATION 0x1F
44#define X25_REGISTRATION_REQUEST 0xF3
45#define X25_REGISTRATION_CONFIRMATION 0xF7
46#define X25_RESTART_REQUEST 0xFB
47#define X25_RESTART_CONFIRMATION 0xFF
48#define X25_DIAGNOSTIC 0xF1
49#define X25_ILLEGAL 0xFD
50
51/* Define the various conditions that may exist */
52
53#define X25_COND_ACK_PENDING 0x01
54#define X25_COND_OWN_RX_BUSY 0x02
55#define X25_COND_PEER_RX_BUSY 0x04
56
57/* Define Link State constants. */
58enum {
59 X25_STATE_0, /* Ready */
60 X25_STATE_1, /* Awaiting Call Accepted */
61 X25_STATE_2, /* Awaiting Clear Confirmation */
62 X25_STATE_3, /* Data Transfer */
63 X25_STATE_4 /* Awaiting Reset Confirmation */
64};
65
66enum {
67 X25_LINK_STATE_0,
68 X25_LINK_STATE_1,
69 X25_LINK_STATE_2,
70 X25_LINK_STATE_3
71};
72
73#define X25_DEFAULT_T20 (180 * HZ) /* Default T20 value */
74#define X25_DEFAULT_T21 (200 * HZ) /* Default T21 value */
75#define X25_DEFAULT_T22 (180 * HZ) /* Default T22 value */
76#define X25_DEFAULT_T23 (180 * HZ) /* Default T23 value */
77#define X25_DEFAULT_T2 (3 * HZ) /* Default ack holdback value */
78
79#define X25_DEFAULT_WINDOW_SIZE 2 /* Default Window Size */
80#define X25_DEFAULT_PACKET_SIZE X25_PS128 /* Default Packet Size */
81#define X25_DEFAULT_THROUGHPUT 0x0A /* Deafult Throughput */
82#define X25_DEFAULT_REVERSE 0x00 /* Default Reverse Charging */
83
84#define X25_SMODULUS 8
85#define X25_EMODULUS 128
86
87/*
88 * X.25 Facilities constants.
89 */
90
91#define X25_FAC_CLASS_MASK 0xC0
92
93#define X25_FAC_CLASS_A 0x00
94#define X25_FAC_CLASS_B 0x40
95#define X25_FAC_CLASS_C 0x80
96#define X25_FAC_CLASS_D 0xC0
97
Shaun Pereiraebc3f642005-06-22 22:16:17 -070098#define X25_FAC_REVERSE 0x01 /* also fast select */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#define X25_FAC_THROUGHPUT 0x02
100#define X25_FAC_PACKET_SIZE 0x42
101#define X25_FAC_WINDOW_SIZE 0x43
102
Shaun Pereiraa64b7b92006-03-22 00:01:31 -0800103#define X25_MAX_FAC_LEN 60
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#define X25_MAX_CUD_LEN 128
105
Shaun Pereiraa64b7b92006-03-22 00:01:31 -0800106#define X25_FAC_CALLING_AE 0xCB
107#define X25_FAC_CALLED_AE 0xC9
108
109#define X25_MARKER 0x00
110#define X25_DTE_SERVICES 0x0F
111#define X25_MAX_AE_LEN 40 /* Max num of semi-octets in AE - OSI Nw */
112#define X25_MAX_DTE_FACIL_LEN 21 /* Max length of DTE facility params */
113
andrew hendrycb863ff2010-05-16 22:59:41 +0000114/* Bitset in x25_sock->flags for misc flags */
115#define X25_Q_BIT_FLAG 0
andrew hendryb7792e32010-05-16 23:00:02 +0000116#define X25_INTERRUPT_FLAG 1
andrew hendry37cda782010-05-16 23:00:27 +0000117#define X25_ACCPT_APPRV_FLAG 2
andrew hendrycb863ff2010-05-16 22:59:41 +0000118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/**
120 * struct x25_route - x25 routing entry
121 * @node - entry in x25_list_lock
122 * @address - Start of address range
123 * @sigdigits - Number of sig digits
124 * @dev - More than one for MLP
125 * @refcnt - reference counter
126 */
127struct x25_route {
128 struct list_head node;
129 struct x25_address address;
130 unsigned int sigdigits;
131 struct net_device *dev;
132 atomic_t refcnt;
133};
134
135struct x25_neigh {
136 struct list_head node;
137 struct net_device *dev;
138 unsigned int state;
139 unsigned int extended;
140 struct sk_buff_head queue;
141 unsigned long t20;
142 struct timer_list t20timer;
143 unsigned long global_facil_mask;
144 atomic_t refcnt;
145};
146
147struct x25_sock {
148 struct sock sk;
149 struct x25_address source_addr, dest_addr;
150 struct x25_neigh *neighbour;
Shaun Pereiracb65d502005-06-22 22:15:01 -0700151 unsigned int lci, cudmatchlength;
andrew hendry37cda782010-05-16 23:00:27 +0000152 unsigned char state, condition;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 unsigned short vs, vr, va, vl;
154 unsigned long t2, t21, t22, t23;
155 unsigned short fraglen;
andrew hendrycb863ff2010-05-16 22:59:41 +0000156 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 struct sk_buff_head ack_queue;
158 struct sk_buff_head fragment_queue;
159 struct sk_buff_head interrupt_in_queue;
160 struct sk_buff_head interrupt_out_queue;
161 struct timer_list timer;
162 struct x25_causediag causediag;
163 struct x25_facilities facilities;
Shaun Pereiraa64b7b92006-03-22 00:01:31 -0800164 struct x25_dte_facilities dte_facilities;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 struct x25_calluserdata calluserdata;
166 unsigned long vc_facil_mask; /* inc_call facilities mask */
167};
168
Andrew Hendry95a9dc42007-02-08 13:34:02 -0800169struct x25_forward {
170 struct list_head node;
171 unsigned int lci;
172 struct net_device *dev1;
173 struct net_device *dev2;
174 atomic_t refcnt;
175};
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177static inline struct x25_sock *x25_sk(const struct sock *sk)
178{
179 return (struct x25_sock *)sk;
180}
181
182/* af_x25.c */
183extern int sysctl_x25_restart_request_timeout;
184extern int sysctl_x25_call_request_timeout;
185extern int sysctl_x25_reset_request_timeout;
186extern int sysctl_x25_clear_request_timeout;
187extern int sysctl_x25_ack_holdback_timeout;
Andrew Hendry39e21c02007-02-08 13:34:36 -0800188extern int sysctl_x25_forward;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
John Hughesf5eb9172010-04-07 21:29:25 -0700190extern int x25_parse_address_block(struct sk_buff *skb,
191 struct x25_address *called_addr,
192 struct x25_address *calling_addr);
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194extern int x25_addr_ntoa(unsigned char *, struct x25_address *,
195 struct x25_address *);
196extern int x25_addr_aton(unsigned char *, struct x25_address *,
197 struct x25_address *);
198extern struct sock *x25_find_socket(unsigned int, struct x25_neigh *);
David S. Miller14ebaf82009-06-16 05:40:30 -0700199extern void x25_destroy_socket_from_timer(struct sock *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200extern int x25_rx_call_request(struct sk_buff *, struct x25_neigh *, unsigned int);
201extern void x25_kill_by_neigh(struct x25_neigh *);
202
203/* x25_dev.c */
204extern void x25_send_frame(struct sk_buff *, struct x25_neigh *);
David S. Millerf2ccd8f2005-08-09 19:34:12 -0700205extern int x25_lapb_receive_frame(struct sk_buff *, struct net_device *, struct packet_type *, struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206extern void x25_establish_link(struct x25_neigh *);
207extern void x25_terminate_link(struct x25_neigh *);
208
209/* x25_facilities.c */
Shaun Pereiraa64b7b92006-03-22 00:01:31 -0800210extern int x25_parse_facilities(struct sk_buff *, struct x25_facilities *,
211 struct x25_dte_facilities *, unsigned long *);
212extern int x25_create_facilities(unsigned char *, struct x25_facilities *,
213 struct x25_dte_facilities *, unsigned long);
214extern int x25_negotiate_facilities(struct sk_buff *, struct sock *,
215 struct x25_facilities *,
216 struct x25_dte_facilities *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217extern void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
218
Andrew Hendry95a9dc42007-02-08 13:34:02 -0800219/* x25_forward.c */
220extern void x25_clear_forward_by_lci(unsigned int lci);
221extern void x25_clear_forward_by_dev(struct net_device *);
222extern int x25_forward_data(int, struct x25_neigh *, struct sk_buff *);
223extern int x25_forward_call(struct x25_address *, struct x25_neigh *,
224 struct sk_buff *, int);
225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226/* x25_in.c */
227extern int x25_process_rx_frame(struct sock *, struct sk_buff *);
228extern int x25_backlog_rcv(struct sock *, struct sk_buff *);
229
230/* x25_link.c */
231extern void x25_link_control(struct sk_buff *, struct x25_neigh *, unsigned short);
232extern void x25_link_device_up(struct net_device *);
233extern void x25_link_device_down(struct net_device *);
234extern void x25_link_established(struct x25_neigh *);
235extern void x25_link_terminated(struct x25_neigh *);
236extern void x25_transmit_clear_request(struct x25_neigh *, unsigned int, unsigned char);
237extern void x25_transmit_link(struct sk_buff *, struct x25_neigh *);
238extern int x25_subscr_ioctl(unsigned int, void __user *);
239extern struct x25_neigh *x25_get_neigh(struct net_device *);
240extern void x25_link_free(void);
241
242/* x25_neigh.c */
243static __inline__ void x25_neigh_hold(struct x25_neigh *nb)
244{
245 atomic_inc(&nb->refcnt);
246}
247
248static __inline__ void x25_neigh_put(struct x25_neigh *nb)
249{
250 if (atomic_dec_and_test(&nb->refcnt))
251 kfree(nb);
252}
253
254/* x25_out.c */
255extern int x25_output(struct sock *, struct sk_buff *);
256extern void x25_kick(struct sock *);
257extern void x25_enquiry_response(struct sock *);
258
259/* x25_route.c */
260extern struct x25_route *x25_get_route(struct x25_address *addr);
261extern struct net_device *x25_dev_get(char *);
262extern void x25_route_device_down(struct net_device *dev);
263extern int x25_route_ioctl(unsigned int, void __user *);
264extern void x25_route_free(void);
265
266static __inline__ void x25_route_hold(struct x25_route *rt)
267{
268 atomic_inc(&rt->refcnt);
269}
270
271static __inline__ void x25_route_put(struct x25_route *rt)
272{
273 if (atomic_dec_and_test(&rt->refcnt))
274 kfree(rt);
275}
276
277/* x25_subr.c */
278extern void x25_clear_queues(struct sock *);
279extern void x25_frames_acked(struct sock *, unsigned short);
280extern void x25_requeue_frames(struct sock *);
281extern int x25_validate_nr(struct sock *, unsigned short);
282extern void x25_write_internal(struct sock *, int);
283extern int x25_decode(struct sock *, struct sk_buff *, int *, int *, int *, int *, int *);
284extern void x25_disconnect(struct sock *, int, unsigned char, unsigned char);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286/* x25_timer.c */
Adrian Bunk7f18ba62007-01-03 18:48:13 -0800287extern void x25_init_timers(struct sock *sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288extern void x25_start_heartbeat(struct sock *);
289extern void x25_start_t2timer(struct sock *);
290extern void x25_start_t21timer(struct sock *);
291extern void x25_start_t22timer(struct sock *);
292extern void x25_start_t23timer(struct sock *);
293extern void x25_stop_heartbeat(struct sock *);
294extern void x25_stop_timer(struct sock *);
295extern unsigned long x25_display_timer(struct sock *);
296extern void x25_check_rbuf(struct sock *);
297
298/* sysctl_net_x25.c */
andrew hendry2f5517a2009-11-24 15:15:26 +0000299#ifdef CONFIG_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300extern void x25_register_sysctl(void);
301extern void x25_unregister_sysctl(void);
andrew hendry2f5517a2009-11-24 15:15:26 +0000302#else
303static inline void x25_register_sysctl(void) {};
304static inline void x25_unregister_sysctl(void) {};
305#endif /* CONFIG_SYSCTL */
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307struct x25_skb_cb {
308 unsigned flags;
309};
310#define X25_SKB_CB(s) ((struct x25_skb_cb *) ((s)->cb))
311
312extern struct hlist_head x25_list;
313extern rwlock_t x25_list_lock;
314extern struct list_head x25_route_list;
315extern rwlock_t x25_route_list_lock;
Andrew Hendry95a9dc42007-02-08 13:34:02 -0800316extern struct list_head x25_forward_list;
317extern rwlock_t x25_forward_list_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319extern int x25_proc_init(void);
320extern void x25_proc_exit(void);
321#endif