blob: ed1acc3044ace48ecd0db0dfe1b7ac3fce23c3fa [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Declarations of X.25 Packet Layer type objects.
4 *
5 * History
6 * nov/17/96 Jonathan Naylor Initial version.
7 * mar/20/00 Daniela Squassoni Disabling/enabling of facilities
8 * negotiation.
9 */
10
11#ifndef _X25_H
12#define _X25_H
13#include <linux/x25.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Reshetova, Elena5f9ccf62017-07-04 15:53:19 +030015#include <linux/refcount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <net/sock.h>
17
18#define X25_ADDR_LEN 16
19
20#define X25_MAX_L2_LEN 18 /* 802.2 LLC */
21
22#define X25_STD_MIN_LEN 3
23#define X25_EXT_MIN_LEN 4
24
25#define X25_GFI_SEQ_MASK 0x30
26#define X25_GFI_STDSEQ 0x10
27#define X25_GFI_EXTSEQ 0x20
28
29#define X25_Q_BIT 0x80
30#define X25_D_BIT 0x40
31#define X25_STD_M_BIT 0x10
32#define X25_EXT_M_BIT 0x01
33
34#define X25_CALL_REQUEST 0x0B
35#define X25_CALL_ACCEPTED 0x0F
36#define X25_CLEAR_REQUEST 0x13
37#define X25_CLEAR_CONFIRMATION 0x17
38#define X25_DATA 0x00
39#define X25_INTERRUPT 0x23
40#define X25_INTERRUPT_CONFIRMATION 0x27
41#define X25_RR 0x01
42#define X25_RNR 0x05
43#define X25_REJ 0x09
44#define X25_RESET_REQUEST 0x1B
45#define X25_RESET_CONFIRMATION 0x1F
46#define X25_REGISTRATION_REQUEST 0xF3
47#define X25_REGISTRATION_CONFIRMATION 0xF7
48#define X25_RESTART_REQUEST 0xFB
49#define X25_RESTART_CONFIRMATION 0xFF
50#define X25_DIAGNOSTIC 0xF1
51#define X25_ILLEGAL 0xFD
52
53/* Define the various conditions that may exist */
54
55#define X25_COND_ACK_PENDING 0x01
56#define X25_COND_OWN_RX_BUSY 0x02
57#define X25_COND_PEER_RX_BUSY 0x04
58
59/* Define Link State constants. */
60enum {
61 X25_STATE_0, /* Ready */
62 X25_STATE_1, /* Awaiting Call Accepted */
63 X25_STATE_2, /* Awaiting Clear Confirmation */
64 X25_STATE_3, /* Data Transfer */
65 X25_STATE_4 /* Awaiting Reset Confirmation */
66};
67
68enum {
69 X25_LINK_STATE_0,
70 X25_LINK_STATE_1,
71 X25_LINK_STATE_2,
72 X25_LINK_STATE_3
73};
74
75#define X25_DEFAULT_T20 (180 * HZ) /* Default T20 value */
76#define X25_DEFAULT_T21 (200 * HZ) /* Default T21 value */
77#define X25_DEFAULT_T22 (180 * HZ) /* Default T22 value */
78#define X25_DEFAULT_T23 (180 * HZ) /* Default T23 value */
79#define X25_DEFAULT_T2 (3 * HZ) /* Default ack holdback value */
80
81#define X25_DEFAULT_WINDOW_SIZE 2 /* Default Window Size */
82#define X25_DEFAULT_PACKET_SIZE X25_PS128 /* Default Packet Size */
83#define X25_DEFAULT_THROUGHPUT 0x0A /* Deafult Throughput */
84#define X25_DEFAULT_REVERSE 0x00 /* Default Reverse Charging */
85
86#define X25_SMODULUS 8
87#define X25_EMODULUS 128
88
89/*
90 * X.25 Facilities constants.
91 */
92
93#define X25_FAC_CLASS_MASK 0xC0
94
95#define X25_FAC_CLASS_A 0x00
96#define X25_FAC_CLASS_B 0x40
97#define X25_FAC_CLASS_C 0x80
98#define X25_FAC_CLASS_D 0xC0
99
Shaun Pereiraebc3f642005-06-22 22:16:17 -0700100#define X25_FAC_REVERSE 0x01 /* also fast select */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define X25_FAC_THROUGHPUT 0x02
102#define X25_FAC_PACKET_SIZE 0x42
103#define X25_FAC_WINDOW_SIZE 0x43
104
Shaun Pereiraa64b7b92006-03-22 00:01:31 -0800105#define X25_MAX_FAC_LEN 60
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#define X25_MAX_CUD_LEN 128
107
Shaun Pereiraa64b7b92006-03-22 00:01:31 -0800108#define X25_FAC_CALLING_AE 0xCB
109#define X25_FAC_CALLED_AE 0xC9
110
111#define X25_MARKER 0x00
112#define X25_DTE_SERVICES 0x0F
113#define X25_MAX_AE_LEN 40 /* Max num of semi-octets in AE - OSI Nw */
114#define X25_MAX_DTE_FACIL_LEN 21 /* Max length of DTE facility params */
115
andrew hendrycb863ff2010-05-16 22:59:41 +0000116/* Bitset in x25_sock->flags for misc flags */
117#define X25_Q_BIT_FLAG 0
andrew hendryb7792e32010-05-16 23:00:02 +0000118#define X25_INTERRUPT_FLAG 1
andrew hendry37cda782010-05-16 23:00:27 +0000119#define X25_ACCPT_APPRV_FLAG 2
andrew hendrycb863ff2010-05-16 22:59:41 +0000120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121/**
122 * struct x25_route - x25 routing entry
123 * @node - entry in x25_list_lock
124 * @address - Start of address range
125 * @sigdigits - Number of sig digits
126 * @dev - More than one for MLP
127 * @refcnt - reference counter
128 */
129struct x25_route {
130 struct list_head node;
131 struct x25_address address;
132 unsigned int sigdigits;
133 struct net_device *dev;
Reshetova, Elena5f9ccf62017-07-04 15:53:19 +0300134 refcount_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
137struct x25_neigh {
138 struct list_head node;
139 struct net_device *dev;
140 unsigned int state;
141 unsigned int extended;
142 struct sk_buff_head queue;
143 unsigned long t20;
144 struct timer_list t20timer;
145 unsigned long global_facil_mask;
Reshetova, Elena5534a512017-07-04 15:53:20 +0300146 refcount_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149struct x25_sock {
150 struct sock sk;
151 struct x25_address source_addr, dest_addr;
152 struct x25_neigh *neighbour;
Shaun Pereiracb65d502005-06-22 22:15:01 -0700153 unsigned int lci, cudmatchlength;
andrew hendry37cda782010-05-16 23:00:27 +0000154 unsigned char state, condition;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 unsigned short vs, vr, va, vl;
156 unsigned long t2, t21, t22, t23;
157 unsigned short fraglen;
andrew hendrycb863ff2010-05-16 22:59:41 +0000158 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 struct sk_buff_head ack_queue;
160 struct sk_buff_head fragment_queue;
161 struct sk_buff_head interrupt_in_queue;
162 struct sk_buff_head interrupt_out_queue;
163 struct timer_list timer;
164 struct x25_causediag causediag;
165 struct x25_facilities facilities;
Shaun Pereiraa64b7b92006-03-22 00:01:31 -0800166 struct x25_dte_facilities dte_facilities;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 struct x25_calluserdata calluserdata;
168 unsigned long vc_facil_mask; /* inc_call facilities mask */
169};
170
Andrew Hendry95a9dc42007-02-08 13:34:02 -0800171struct x25_forward {
172 struct list_head node;
173 unsigned int lci;
174 struct net_device *dev1;
175 struct net_device *dev2;
176 atomic_t refcnt;
177};
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179static inline struct x25_sock *x25_sk(const struct sock *sk)
180{
181 return (struct x25_sock *)sk;
182}
183
184/* af_x25.c */
185extern int sysctl_x25_restart_request_timeout;
186extern int sysctl_x25_call_request_timeout;
187extern int sysctl_x25_reset_request_timeout;
188extern int sysctl_x25_clear_request_timeout;
189extern int sysctl_x25_ack_holdback_timeout;
Andrew Hendry39e21c02007-02-08 13:34:36 -0800190extern int sysctl_x25_forward;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Joe Perches5db50ee2013-09-23 11:33:49 -0700192int x25_parse_address_block(struct sk_buff *skb,
193 struct x25_address *called_addr,
194 struct x25_address *calling_addr);
John Hughesf5eb9172010-04-07 21:29:25 -0700195
Joe Perches5db50ee2013-09-23 11:33:49 -0700196int x25_addr_ntoa(unsigned char *, struct x25_address *, struct x25_address *);
197int x25_addr_aton(unsigned char *, struct x25_address *, struct x25_address *);
198struct sock *x25_find_socket(unsigned int, struct x25_neigh *);
199void x25_destroy_socket_from_timer(struct sock *);
200int x25_rx_call_request(struct sk_buff *, struct x25_neigh *, unsigned int);
201void x25_kill_by_neigh(struct x25_neigh *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203/* x25_dev.c */
Joe Perches5db50ee2013-09-23 11:33:49 -0700204void x25_send_frame(struct sk_buff *, struct x25_neigh *);
205int x25_lapb_receive_frame(struct sk_buff *, struct net_device *,
206 struct packet_type *, struct net_device *);
207void x25_establish_link(struct x25_neigh *);
208void x25_terminate_link(struct x25_neigh *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210/* x25_facilities.c */
Joe Perches5db50ee2013-09-23 11:33:49 -0700211int x25_parse_facilities(struct sk_buff *, struct x25_facilities *,
212 struct x25_dte_facilities *, unsigned long *);
213int x25_create_facilities(unsigned char *, struct x25_facilities *,
214 struct x25_dte_facilities *, unsigned long);
215int x25_negotiate_facilities(struct sk_buff *, struct sock *,
216 struct x25_facilities *,
217 struct x25_dte_facilities *);
218void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Andrew Hendry95a9dc42007-02-08 13:34:02 -0800220/* x25_forward.c */
Joe Perches5db50ee2013-09-23 11:33:49 -0700221void x25_clear_forward_by_lci(unsigned int lci);
222void x25_clear_forward_by_dev(struct net_device *);
223int x25_forward_data(int, struct x25_neigh *, struct sk_buff *);
224int x25_forward_call(struct x25_address *, struct x25_neigh *, struct sk_buff *,
225 int);
Andrew Hendry95a9dc42007-02-08 13:34:02 -0800226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/* x25_in.c */
Joe Perches5db50ee2013-09-23 11:33:49 -0700228int x25_process_rx_frame(struct sock *, struct sk_buff *);
229int x25_backlog_rcv(struct sock *, struct sk_buff *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231/* x25_link.c */
Joe Perches5db50ee2013-09-23 11:33:49 -0700232void x25_link_control(struct sk_buff *, struct x25_neigh *, unsigned short);
233void x25_link_device_up(struct net_device *);
234void x25_link_device_down(struct net_device *);
235void x25_link_established(struct x25_neigh *);
236void x25_link_terminated(struct x25_neigh *);
237void x25_transmit_clear_request(struct x25_neigh *, unsigned int,
238 unsigned char);
239void x25_transmit_link(struct sk_buff *, struct x25_neigh *);
240int x25_subscr_ioctl(unsigned int, void __user *);
241struct x25_neigh *x25_get_neigh(struct net_device *);
242void x25_link_free(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244/* x25_neigh.c */
245static __inline__ void x25_neigh_hold(struct x25_neigh *nb)
246{
Reshetova, Elena5534a512017-07-04 15:53:20 +0300247 refcount_inc(&nb->refcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
250static __inline__ void x25_neigh_put(struct x25_neigh *nb)
251{
Reshetova, Elena5534a512017-07-04 15:53:20 +0300252 if (refcount_dec_and_test(&nb->refcnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 kfree(nb);
254}
255
256/* x25_out.c */
Joe Perches5db50ee2013-09-23 11:33:49 -0700257int x25_output(struct sock *, struct sk_buff *);
258void x25_kick(struct sock *);
259void x25_enquiry_response(struct sock *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261/* x25_route.c */
Joe Perches5db50ee2013-09-23 11:33:49 -0700262struct x25_route *x25_get_route(struct x25_address *addr);
263struct net_device *x25_dev_get(char *);
264void x25_route_device_down(struct net_device *dev);
265int x25_route_ioctl(unsigned int, void __user *);
266void x25_route_free(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268static __inline__ void x25_route_hold(struct x25_route *rt)
269{
Reshetova, Elena5f9ccf62017-07-04 15:53:19 +0300270 refcount_inc(&rt->refcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
272
273static __inline__ void x25_route_put(struct x25_route *rt)
274{
Reshetova, Elena5f9ccf62017-07-04 15:53:19 +0300275 if (refcount_dec_and_test(&rt->refcnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 kfree(rt);
277}
278
279/* x25_subr.c */
Joe Perches5db50ee2013-09-23 11:33:49 -0700280void x25_clear_queues(struct sock *);
281void x25_frames_acked(struct sock *, unsigned short);
282void x25_requeue_frames(struct sock *);
283int x25_validate_nr(struct sock *, unsigned short);
284void x25_write_internal(struct sock *, int);
285int x25_decode(struct sock *, struct sk_buff *, int *, int *, int *, int *,
286 int *);
287void x25_disconnect(struct sock *, int, unsigned char, unsigned char);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289/* x25_timer.c */
Joe Perches5db50ee2013-09-23 11:33:49 -0700290void x25_init_timers(struct sock *sk);
291void x25_start_heartbeat(struct sock *);
292void x25_start_t2timer(struct sock *);
293void x25_start_t21timer(struct sock *);
294void x25_start_t22timer(struct sock *);
295void x25_start_t23timer(struct sock *);
296void x25_stop_heartbeat(struct sock *);
297void x25_stop_timer(struct sock *);
298unsigned long x25_display_timer(struct sock *);
299void x25_check_rbuf(struct sock *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301/* sysctl_net_x25.c */
andrew hendry2f5517a2009-11-24 15:15:26 +0000302#ifdef CONFIG_SYSCTL
linzhang64df6d52017-05-17 12:05:07 +0800303int x25_register_sysctl(void);
Joe Perches5db50ee2013-09-23 11:33:49 -0700304void x25_unregister_sysctl(void);
andrew hendry2f5517a2009-11-24 15:15:26 +0000305#else
linzhang64df6d52017-05-17 12:05:07 +0800306static inline int x25_register_sysctl(void) { return 0; };
andrew hendry2f5517a2009-11-24 15:15:26 +0000307static inline void x25_unregister_sysctl(void) {};
308#endif /* CONFIG_SYSCTL */
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310struct x25_skb_cb {
Eric Dumazet95c96172012-04-15 05:58:06 +0000311 unsigned int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312};
313#define X25_SKB_CB(s) ((struct x25_skb_cb *) ((s)->cb))
314
315extern struct hlist_head x25_list;
316extern rwlock_t x25_list_lock;
317extern struct list_head x25_route_list;
318extern rwlock_t x25_route_list_lock;
Andrew Hendry95a9dc42007-02-08 13:34:02 -0800319extern struct list_head x25_forward_list;
320extern rwlock_t x25_forward_list_lock;
andrew hendry5595a1a2010-11-25 02:18:15 +0000321extern struct list_head x25_neigh_list;
322extern rwlock_t x25_neigh_list_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Joe Perches5db50ee2013-09-23 11:33:49 -0700324int x25_proc_init(void);
325void x25_proc_exit(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#endif