1 /*
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>
13 
14 #define	X25_ADDR_LEN			16
15 
16 #define	X25_MAX_L2_LEN			18	/* 802.2 LLC */
17 
18 #define	X25_STD_MIN_LEN			3
19 #define	X25_EXT_MIN_LEN			4
20 
21 #define	X25_GFI_SEQ_MASK		0x30
22 #define	X25_GFI_STDSEQ			0x10
23 #define	X25_GFI_EXTSEQ			0x20
24 
25 #define	X25_Q_BIT			0x80
26 #define	X25_D_BIT			0x40
27 #define	X25_STD_M_BIT			0x10
28 #define	X25_EXT_M_BIT			0x01
29 
30 #define	X25_CALL_REQUEST		0x0B
31 #define	X25_CALL_ACCEPTED		0x0F
32 #define	X25_CLEAR_REQUEST		0x13
33 #define	X25_CLEAR_CONFIRMATION		0x17
34 #define	X25_DATA			0x00
35 #define	X25_INTERRUPT			0x23
36 #define	X25_INTERRUPT_CONFIRMATION	0x27
37 #define	X25_RR				0x01
38 #define	X25_RNR				0x05
39 #define	X25_REJ				0x09
40 #define	X25_RESET_REQUEST		0x1B
41 #define	X25_RESET_CONFIRMATION		0x1F
42 #define	X25_REGISTRATION_REQUEST	0xF3
43 #define	X25_REGISTRATION_CONFIRMATION	0xF7
44 #define	X25_RESTART_REQUEST		0xFB
45 #define	X25_RESTART_CONFIRMATION	0xFF
46 #define	X25_DIAGNOSTIC			0xF1
47 #define	X25_ILLEGAL			0xFD
48 
49 /* Define the various conditions that may exist */
50 
51 #define	X25_COND_ACK_PENDING	0x01
52 #define	X25_COND_OWN_RX_BUSY	0x02
53 #define	X25_COND_PEER_RX_BUSY	0x04
54 
55 /* Define Link State constants. */
56 enum {
57 	X25_STATE_0,		/* Ready */
58 	X25_STATE_1,		/* Awaiting Call Accepted */
59 	X25_STATE_2,		/* Awaiting Clear Confirmation */
60 	X25_STATE_3,		/* Data Transfer */
61 	X25_STATE_4		/* Awaiting Reset Confirmation */
62 };
63 
64 enum {
65 	X25_LINK_STATE_0,
66 	X25_LINK_STATE_1,
67 	X25_LINK_STATE_2,
68 	X25_LINK_STATE_3
69 };
70 
71 #define X25_DEFAULT_T20		(180 * HZ)		/* Default T20 value */
72 #define X25_DEFAULT_T21		(200 * HZ)		/* Default T21 value */
73 #define X25_DEFAULT_T22		(180 * HZ)		/* Default T22 value */
74 #define	X25_DEFAULT_T23		(180 * HZ)		/* Default T23 value */
75 #define	X25_DEFAULT_T2		(3   * HZ)		/* Default ack holdback value */
76 
77 #define	X25_DEFAULT_WINDOW_SIZE	2			/* Default Window Size	*/
78 #define	X25_DEFAULT_PACKET_SIZE	X25_PS128		/* Default Packet Size */
79 #define	X25_DEFAULT_THROUGHPUT	0x0A			/* Deafult Throughput */
80 #define	X25_DEFAULT_REVERSE	0x00			/* Default Reverse Charging */
81 
82 #define X25_SMODULUS 		8
83 #define	X25_EMODULUS		128
84 
85 /*
86  *	X.25 Facilities constants.
87  */
88 
89 #define	X25_FAC_CLASS_MASK	0xC0
90 
91 #define	X25_FAC_CLASS_A		0x00
92 #define	X25_FAC_CLASS_B		0x40
93 #define	X25_FAC_CLASS_C		0x80
94 #define	X25_FAC_CLASS_D		0xC0
95 
96 #define	X25_FAC_REVERSE		0x01
97 #define	X25_FAC_THROUGHPUT	0x02
98 #define	X25_FAC_PACKET_SIZE	0x42
99 #define	X25_FAC_WINDOW_SIZE	0x43
100 
101 #define	X25_MAX_FAC_LEN		20		/* Plenty to spare */
102 #define	X25_MAX_CUD_LEN		128
103 
104 struct x25_route {
105 	struct x25_route	*next;
106 	x25_address		address;	/* Start of address range */
107 	unsigned int		sigdigits;	/* Number of sig digits */
108 	struct net_device		*dev;		/* More than one for MLP */
109 };
110 
111 struct x25_neigh {
112 	struct x25_neigh	*next;
113 	struct net_device		*dev;
114 	unsigned int		state;
115 	unsigned int		extended;
116 	struct sk_buff_head	queue;
117 	unsigned long		t20;
118 	struct timer_list	t20timer;
119 	unsigned long		global_facil_mask;
120 };
121 
122 typedef struct {
123 	x25_address		source_addr, dest_addr;
124 	struct x25_neigh	*neighbour;
125 	unsigned int		lci;
126 	unsigned char		state, condition, qbitincl, intflag;
127 	unsigned short		vs, vr, va, vl;
128 	unsigned long		t2, t21, t22, t23;
129 	unsigned short		fraglen;
130 	struct sk_buff_head	ack_queue;
131 	struct sk_buff_head	fragment_queue;
132 	struct sk_buff_head	interrupt_in_queue;
133 	struct sk_buff_head	interrupt_out_queue;
134 	struct sock		*sk;		/* Backlink to socket */
135 	struct timer_list	timer;
136 	struct x25_causediag	causediag;
137 	struct x25_facilities	facilities;
138 	struct x25_calluserdata	calluserdata;
139 	unsigned long 		vc_facil_mask;	/* inc_call facilities mask */
140 } x25_cb;
141 
142 /* af_x25.c */
143 extern int  sysctl_x25_restart_request_timeout;
144 extern int  sysctl_x25_call_request_timeout;
145 extern int  sysctl_x25_reset_request_timeout;
146 extern int  sysctl_x25_clear_request_timeout;
147 extern int  sysctl_x25_ack_holdback_timeout;
148 
149 extern int  x25_addr_ntoa(unsigned char *, x25_address *, x25_address *);
150 extern int  x25_addr_aton(unsigned char *, x25_address *, x25_address *);
151 extern unsigned int x25_new_lci(struct x25_neigh *);
152 extern struct sock *x25_find_socket(unsigned int, struct x25_neigh *);
153 extern void x25_destroy_socket(struct sock *);
154 extern int  x25_rx_call_request(struct sk_buff *, struct x25_neigh *, unsigned int);
155 extern void x25_kill_by_neigh(struct x25_neigh *);
156 
157 /* x25_dev.c */
158 extern void x25_send_frame(struct sk_buff *, struct x25_neigh *);
159 extern int  x25_lapb_receive_frame(struct sk_buff *, struct net_device *, struct packet_type *);
160 extern int  x25_llc_receive_frame(struct sk_buff *, struct net_device *, struct packet_type *);
161 extern void x25_establish_link(struct x25_neigh *);
162 extern void x25_terminate_link(struct x25_neigh *);
163 
164 /* x25_facilities.c */
165 extern int  x25_parse_facilities(struct sk_buff *, struct x25_facilities *, unsigned long *);
166 extern int  x25_create_facilities(unsigned char *, struct x25_facilities *, unsigned long);
167 extern int  x25_negotiate_facilities(struct sk_buff *, struct sock *, struct x25_facilities *);
168 extern void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
169 
170 /* x25_in.c */
171 extern int  x25_process_rx_frame(struct sock *, struct sk_buff *);
172 extern int  x25_backlog_rcv(struct sock *, struct sk_buff *);
173 
174 /* x25_link.c */
175 extern void x25_link_control(struct sk_buff *, struct x25_neigh *, unsigned short);
176 extern void x25_link_device_up(struct net_device *);
177 extern void x25_link_device_down(struct net_device *);
178 extern void x25_link_established(struct x25_neigh *);
179 extern void x25_link_terminated(struct x25_neigh *);
180 extern void x25_transmit_restart_request(struct x25_neigh *);
181 extern void x25_transmit_restart_confirmation(struct x25_neigh *);
182 extern void x25_transmit_diagnostic(struct x25_neigh *, unsigned char);
183 extern void x25_transmit_clear_request(struct x25_neigh *, unsigned int, unsigned char);
184 extern void x25_transmit_link(struct sk_buff *, struct x25_neigh *);
185 extern int  x25_subscr_ioctl(unsigned int, void *);
186 extern struct x25_neigh *x25_get_neigh(struct net_device *);
187 extern void x25_link_free(void);
188 
189 /* x25_out.c */
190 extern  int x25_output(struct sock *, struct sk_buff *);
191 extern void x25_kick(struct sock *);
192 extern void x25_enquiry_response(struct sock *);
193 
194 /* x25_route.c */
195 extern struct net_device *x25_get_route(x25_address *);
196 extern struct net_device *x25_dev_get(char *);
197 extern void x25_route_device_down(struct net_device *);
198 extern int  x25_route_ioctl(unsigned int, void *);
199 extern int  x25_routes_get_info(char *, char **, off_t, int);
200 extern void x25_route_free(void);
201 
202 /* x25_subr.c */
203 extern void x25_clear_queues(struct sock *);
204 extern void x25_frames_acked(struct sock *, unsigned short);
205 extern void x25_requeue_frames(struct sock *);
206 extern int  x25_validate_nr(struct sock *, unsigned short);
207 extern void x25_write_internal(struct sock *, int);
208 extern int  x25_decode(struct sock *, struct sk_buff *, int *, int *, int *, int *, int *);
209 extern void x25_disconnect(struct sock *, int, unsigned char, unsigned char);
210 
211 /* x25_timer.c */
212 extern void x25_start_heartbeat(struct sock *);
213 extern void x25_start_t2timer(struct sock *);
214 extern void x25_start_t21timer(struct sock *);
215 extern void x25_start_t22timer(struct sock *);
216 extern void x25_start_t23timer(struct sock *);
217 extern void x25_stop_heartbeat(struct sock *);
218 extern void x25_stop_timer(struct sock *);
219 extern unsigned long x25_display_timer(struct sock *);
220 extern void x25_check_rbuf(struct sock *);
221 
222 /* sysctl_net_x25.c */
223 extern void x25_register_sysctl(void);
224 extern void x25_unregister_sysctl(void);
225 struct x25_skb_cb {
226 	unsigned flags;
227 };
228 #define X25_SKB_CB(s) ((struct x25_skb_cb *) ((s)->cb))
229 #endif
230