1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Declarations of X.25 Packet Layer type objects.
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * History
61da177e4SLinus Torvalds * nov/17/96 Jonathan Naylor Initial version.
71da177e4SLinus Torvalds * mar/20/00 Daniela Squassoni Disabling/enabling of facilities
81da177e4SLinus Torvalds * negotiation.
91da177e4SLinus Torvalds */
101da177e4SLinus Torvalds
111da177e4SLinus Torvalds #ifndef _X25_H
121da177e4SLinus Torvalds #define _X25_H
131da177e4SLinus Torvalds #include <linux/x25.h>
145a0e3ad6STejun Heo #include <linux/slab.h>
155f9ccf6fSReshetova, Elena #include <linux/refcount.h>
161da177e4SLinus Torvalds #include <net/sock.h>
171da177e4SLinus Torvalds
181da177e4SLinus Torvalds #define X25_ADDR_LEN 16
191da177e4SLinus Torvalds
201da177e4SLinus Torvalds #define X25_MAX_L2_LEN 18 /* 802.2 LLC */
211da177e4SLinus Torvalds
221da177e4SLinus Torvalds #define X25_STD_MIN_LEN 3
231da177e4SLinus Torvalds #define X25_EXT_MIN_LEN 4
241da177e4SLinus Torvalds
251da177e4SLinus Torvalds #define X25_GFI_SEQ_MASK 0x30
261da177e4SLinus Torvalds #define X25_GFI_STDSEQ 0x10
271da177e4SLinus Torvalds #define X25_GFI_EXTSEQ 0x20
281da177e4SLinus Torvalds
291da177e4SLinus Torvalds #define X25_Q_BIT 0x80
301da177e4SLinus Torvalds #define X25_D_BIT 0x40
311da177e4SLinus Torvalds #define X25_STD_M_BIT 0x10
321da177e4SLinus Torvalds #define X25_EXT_M_BIT 0x01
331da177e4SLinus Torvalds
341da177e4SLinus Torvalds #define X25_CALL_REQUEST 0x0B
351da177e4SLinus Torvalds #define X25_CALL_ACCEPTED 0x0F
361da177e4SLinus Torvalds #define X25_CLEAR_REQUEST 0x13
371da177e4SLinus Torvalds #define X25_CLEAR_CONFIRMATION 0x17
381da177e4SLinus Torvalds #define X25_DATA 0x00
391da177e4SLinus Torvalds #define X25_INTERRUPT 0x23
401da177e4SLinus Torvalds #define X25_INTERRUPT_CONFIRMATION 0x27
411da177e4SLinus Torvalds #define X25_RR 0x01
421da177e4SLinus Torvalds #define X25_RNR 0x05
431da177e4SLinus Torvalds #define X25_REJ 0x09
441da177e4SLinus Torvalds #define X25_RESET_REQUEST 0x1B
451da177e4SLinus Torvalds #define X25_RESET_CONFIRMATION 0x1F
461da177e4SLinus Torvalds #define X25_REGISTRATION_REQUEST 0xF3
471da177e4SLinus Torvalds #define X25_REGISTRATION_CONFIRMATION 0xF7
481da177e4SLinus Torvalds #define X25_RESTART_REQUEST 0xFB
491da177e4SLinus Torvalds #define X25_RESTART_CONFIRMATION 0xFF
501da177e4SLinus Torvalds #define X25_DIAGNOSTIC 0xF1
511da177e4SLinus Torvalds #define X25_ILLEGAL 0xFD
521da177e4SLinus Torvalds
531da177e4SLinus Torvalds /* Define the various conditions that may exist */
541da177e4SLinus Torvalds
551da177e4SLinus Torvalds #define X25_COND_ACK_PENDING 0x01
561da177e4SLinus Torvalds #define X25_COND_OWN_RX_BUSY 0x02
571da177e4SLinus Torvalds #define X25_COND_PEER_RX_BUSY 0x04
581da177e4SLinus Torvalds
591da177e4SLinus Torvalds /* Define Link State constants. */
601da177e4SLinus Torvalds enum {
611da177e4SLinus Torvalds X25_STATE_0, /* Ready */
621da177e4SLinus Torvalds X25_STATE_1, /* Awaiting Call Accepted */
631da177e4SLinus Torvalds X25_STATE_2, /* Awaiting Clear Confirmation */
641da177e4SLinus Torvalds X25_STATE_3, /* Data Transfer */
65f8fc57e8SMartin Schiller X25_STATE_4, /* Awaiting Reset Confirmation */
66f8fc57e8SMartin Schiller X25_STATE_5 /* Call Accepted / Call Connected pending */
671da177e4SLinus Torvalds };
681da177e4SLinus Torvalds
691da177e4SLinus Torvalds enum {
701da177e4SLinus Torvalds X25_LINK_STATE_0,
711da177e4SLinus Torvalds X25_LINK_STATE_1,
721da177e4SLinus Torvalds X25_LINK_STATE_2,
731da177e4SLinus Torvalds X25_LINK_STATE_3
741da177e4SLinus Torvalds };
751da177e4SLinus Torvalds
761da177e4SLinus Torvalds #define X25_DEFAULT_T20 (180 * HZ) /* Default T20 value */
771da177e4SLinus Torvalds #define X25_DEFAULT_T21 (200 * HZ) /* Default T21 value */
781da177e4SLinus Torvalds #define X25_DEFAULT_T22 (180 * HZ) /* Default T22 value */
791da177e4SLinus Torvalds #define X25_DEFAULT_T23 (180 * HZ) /* Default T23 value */
801da177e4SLinus Torvalds #define X25_DEFAULT_T2 (3 * HZ) /* Default ack holdback value */
811da177e4SLinus Torvalds
821da177e4SLinus Torvalds #define X25_DEFAULT_WINDOW_SIZE 2 /* Default Window Size */
831da177e4SLinus Torvalds #define X25_DEFAULT_PACKET_SIZE X25_PS128 /* Default Packet Size */
841da177e4SLinus Torvalds #define X25_DEFAULT_THROUGHPUT 0x0A /* Deafult Throughput */
851da177e4SLinus Torvalds #define X25_DEFAULT_REVERSE 0x00 /* Default Reverse Charging */
861da177e4SLinus Torvalds
871da177e4SLinus Torvalds #define X25_SMODULUS 8
881da177e4SLinus Torvalds #define X25_EMODULUS 128
891da177e4SLinus Torvalds
901da177e4SLinus Torvalds /*
911da177e4SLinus Torvalds * X.25 Facilities constants.
921da177e4SLinus Torvalds */
931da177e4SLinus Torvalds
941da177e4SLinus Torvalds #define X25_FAC_CLASS_MASK 0xC0
951da177e4SLinus Torvalds
961da177e4SLinus Torvalds #define X25_FAC_CLASS_A 0x00
971da177e4SLinus Torvalds #define X25_FAC_CLASS_B 0x40
981da177e4SLinus Torvalds #define X25_FAC_CLASS_C 0x80
991da177e4SLinus Torvalds #define X25_FAC_CLASS_D 0xC0
1001da177e4SLinus Torvalds
101ebc3f64bSShaun Pereira #define X25_FAC_REVERSE 0x01 /* also fast select */
1021da177e4SLinus Torvalds #define X25_FAC_THROUGHPUT 0x02
1031da177e4SLinus Torvalds #define X25_FAC_PACKET_SIZE 0x42
1041da177e4SLinus Torvalds #define X25_FAC_WINDOW_SIZE 0x43
1051da177e4SLinus Torvalds
106a64b7b93SShaun Pereira #define X25_MAX_FAC_LEN 60
1071da177e4SLinus Torvalds #define X25_MAX_CUD_LEN 128
1081da177e4SLinus Torvalds
109a64b7b93SShaun Pereira #define X25_FAC_CALLING_AE 0xCB
110a64b7b93SShaun Pereira #define X25_FAC_CALLED_AE 0xC9
111a64b7b93SShaun Pereira
112a64b7b93SShaun Pereira #define X25_MARKER 0x00
113a64b7b93SShaun Pereira #define X25_DTE_SERVICES 0x0F
114a64b7b93SShaun Pereira #define X25_MAX_AE_LEN 40 /* Max num of semi-octets in AE - OSI Nw */
115a64b7b93SShaun Pereira #define X25_MAX_DTE_FACIL_LEN 21 /* Max length of DTE facility params */
116a64b7b93SShaun Pereira
117cb863ffdSandrew hendry /* Bitset in x25_sock->flags for misc flags */
118cb863ffdSandrew hendry #define X25_Q_BIT_FLAG 0
119b7792e34Sandrew hendry #define X25_INTERRUPT_FLAG 1
12037cda787Sandrew hendry #define X25_ACCPT_APPRV_FLAG 2
121cb863ffdSandrew hendry
1221da177e4SLinus Torvalds /**
1231da177e4SLinus Torvalds * struct x25_route - x25 routing entry
1241da177e4SLinus Torvalds * @node - entry in x25_list_lock
1251da177e4SLinus Torvalds * @address - Start of address range
1261da177e4SLinus Torvalds * @sigdigits - Number of sig digits
1271da177e4SLinus Torvalds * @dev - More than one for MLP
1281da177e4SLinus Torvalds * @refcnt - reference counter
1291da177e4SLinus Torvalds */
1301da177e4SLinus Torvalds struct x25_route {
1311da177e4SLinus Torvalds struct list_head node;
1321da177e4SLinus Torvalds struct x25_address address;
1331da177e4SLinus Torvalds unsigned int sigdigits;
1341da177e4SLinus Torvalds struct net_device *dev;
1355f9ccf6fSReshetova, Elena refcount_t refcnt;
1361da177e4SLinus Torvalds };
1371da177e4SLinus Torvalds
1381da177e4SLinus Torvalds struct x25_neigh {
1391da177e4SLinus Torvalds struct list_head node;
1401da177e4SLinus Torvalds struct net_device *dev;
1411da177e4SLinus Torvalds unsigned int state;
1421da177e4SLinus Torvalds unsigned int extended;
1431da177e4SLinus Torvalds struct sk_buff_head queue;
1441da177e4SLinus Torvalds unsigned long t20;
1451da177e4SLinus Torvalds struct timer_list t20timer;
1461da177e4SLinus Torvalds unsigned long global_facil_mask;
1475534a51aSReshetova, Elena refcount_t refcnt;
1481da177e4SLinus Torvalds };
1491da177e4SLinus Torvalds
1501da177e4SLinus Torvalds struct x25_sock {
1511da177e4SLinus Torvalds struct sock sk;
1521da177e4SLinus Torvalds struct x25_address source_addr, dest_addr;
1531da177e4SLinus Torvalds struct x25_neigh *neighbour;
154cb65d506SShaun Pereira unsigned int lci, cudmatchlength;
15537cda787Sandrew hendry unsigned char state, condition;
1561da177e4SLinus Torvalds unsigned short vs, vr, va, vl;
1571da177e4SLinus Torvalds unsigned long t2, t21, t22, t23;
1581da177e4SLinus Torvalds unsigned short fraglen;
159cb863ffdSandrew hendry unsigned long flags;
1601da177e4SLinus Torvalds struct sk_buff_head ack_queue;
1611da177e4SLinus Torvalds struct sk_buff_head fragment_queue;
1621da177e4SLinus Torvalds struct sk_buff_head interrupt_in_queue;
1631da177e4SLinus Torvalds struct sk_buff_head interrupt_out_queue;
1641da177e4SLinus Torvalds struct timer_list timer;
1651da177e4SLinus Torvalds struct x25_causediag causediag;
1661da177e4SLinus Torvalds struct x25_facilities facilities;
167a64b7b93SShaun Pereira struct x25_dte_facilities dte_facilities;
1681da177e4SLinus Torvalds struct x25_calluserdata calluserdata;
1691da177e4SLinus Torvalds unsigned long vc_facil_mask; /* inc_call facilities mask */
1701da177e4SLinus Torvalds };
1711da177e4SLinus Torvalds
17295a9dc43SAndrew Hendry struct x25_forward {
17395a9dc43SAndrew Hendry struct list_head node;
17495a9dc43SAndrew Hendry unsigned int lci;
17595a9dc43SAndrew Hendry struct net_device *dev1;
17695a9dc43SAndrew Hendry struct net_device *dev2;
17795a9dc43SAndrew Hendry atomic_t refcnt;
17895a9dc43SAndrew Hendry };
17995a9dc43SAndrew Hendry
180*c7154ca8SEric Dumazet #define x25_sk(ptr) container_of_const(ptr, struct x25_sock, sk)
1811da177e4SLinus Torvalds
1821da177e4SLinus Torvalds /* af_x25.c */
1831da177e4SLinus Torvalds extern int sysctl_x25_restart_request_timeout;
1841da177e4SLinus Torvalds extern int sysctl_x25_call_request_timeout;
1851da177e4SLinus Torvalds extern int sysctl_x25_reset_request_timeout;
1861da177e4SLinus Torvalds extern int sysctl_x25_clear_request_timeout;
1871da177e4SLinus Torvalds extern int sysctl_x25_ack_holdback_timeout;
18839e21c0dSAndrew Hendry extern int sysctl_x25_forward;
1891da177e4SLinus Torvalds
1905db50ee6SJoe Perches int x25_parse_address_block(struct sk_buff *skb,
191f5eb917bSJohn Hughes struct x25_address *called_addr,
192f5eb917bSJohn Hughes struct x25_address *calling_addr);
193f5eb917bSJohn Hughes
1945db50ee6SJoe Perches int x25_addr_ntoa(unsigned char *, struct x25_address *, struct x25_address *);
1955db50ee6SJoe Perches int x25_addr_aton(unsigned char *, struct x25_address *, struct x25_address *);
1965db50ee6SJoe Perches struct sock *x25_find_socket(unsigned int, struct x25_neigh *);
1975db50ee6SJoe Perches void x25_destroy_socket_from_timer(struct sock *);
1985db50ee6SJoe Perches int x25_rx_call_request(struct sk_buff *, struct x25_neigh *, unsigned int);
1995db50ee6SJoe Perches void x25_kill_by_neigh(struct x25_neigh *);
2001da177e4SLinus Torvalds
2011da177e4SLinus Torvalds /* x25_dev.c */
2025db50ee6SJoe Perches void x25_send_frame(struct sk_buff *, struct x25_neigh *);
2035db50ee6SJoe Perches int x25_lapb_receive_frame(struct sk_buff *, struct net_device *,
2045db50ee6SJoe Perches struct packet_type *, struct net_device *);
2055db50ee6SJoe Perches void x25_establish_link(struct x25_neigh *);
2065db50ee6SJoe Perches void x25_terminate_link(struct x25_neigh *);
2071da177e4SLinus Torvalds
2081da177e4SLinus Torvalds /* x25_facilities.c */
2095db50ee6SJoe Perches int x25_parse_facilities(struct sk_buff *, struct x25_facilities *,
210a64b7b93SShaun Pereira struct x25_dte_facilities *, unsigned long *);
2115db50ee6SJoe Perches int x25_create_facilities(unsigned char *, struct x25_facilities *,
212a64b7b93SShaun Pereira struct x25_dte_facilities *, unsigned long);
2135db50ee6SJoe Perches int x25_negotiate_facilities(struct sk_buff *, struct sock *,
214a64b7b93SShaun Pereira struct x25_facilities *,
215a64b7b93SShaun Pereira struct x25_dte_facilities *);
2165db50ee6SJoe Perches void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
2171da177e4SLinus Torvalds
21895a9dc43SAndrew Hendry /* x25_forward.c */
2195db50ee6SJoe Perches void x25_clear_forward_by_lci(unsigned int lci);
2205db50ee6SJoe Perches void x25_clear_forward_by_dev(struct net_device *);
2215db50ee6SJoe Perches int x25_forward_data(int, struct x25_neigh *, struct sk_buff *);
2225db50ee6SJoe Perches int x25_forward_call(struct x25_address *, struct x25_neigh *, struct sk_buff *,
2235db50ee6SJoe Perches int);
22495a9dc43SAndrew Hendry
2251da177e4SLinus Torvalds /* x25_in.c */
2265db50ee6SJoe Perches int x25_process_rx_frame(struct sock *, struct sk_buff *);
2275db50ee6SJoe Perches int x25_backlog_rcv(struct sock *, struct sk_buff *);
2281da177e4SLinus Torvalds
2291da177e4SLinus Torvalds /* x25_link.c */
2305db50ee6SJoe Perches void x25_link_control(struct sk_buff *, struct x25_neigh *, unsigned short);
2315db50ee6SJoe Perches void x25_link_device_up(struct net_device *);
2325db50ee6SJoe Perches void x25_link_device_down(struct net_device *);
2335db50ee6SJoe Perches void x25_link_established(struct x25_neigh *);
2345db50ee6SJoe Perches void x25_link_terminated(struct x25_neigh *);
2355db50ee6SJoe Perches void x25_transmit_clear_request(struct x25_neigh *, unsigned int,
2365db50ee6SJoe Perches unsigned char);
2375db50ee6SJoe Perches void x25_transmit_link(struct sk_buff *, struct x25_neigh *);
2385db50ee6SJoe Perches int x25_subscr_ioctl(unsigned int, void __user *);
2395db50ee6SJoe Perches struct x25_neigh *x25_get_neigh(struct net_device *);
2405db50ee6SJoe Perches void x25_link_free(void);
2411da177e4SLinus Torvalds
2421da177e4SLinus Torvalds /* x25_neigh.c */
x25_neigh_hold(struct x25_neigh * nb)2431da177e4SLinus Torvalds static __inline__ void x25_neigh_hold(struct x25_neigh *nb)
2441da177e4SLinus Torvalds {
2455534a51aSReshetova, Elena refcount_inc(&nb->refcnt);
2461da177e4SLinus Torvalds }
2471da177e4SLinus Torvalds
x25_neigh_put(struct x25_neigh * nb)2481da177e4SLinus Torvalds static __inline__ void x25_neigh_put(struct x25_neigh *nb)
2491da177e4SLinus Torvalds {
2505534a51aSReshetova, Elena if (refcount_dec_and_test(&nb->refcnt))
2511da177e4SLinus Torvalds kfree(nb);
2521da177e4SLinus Torvalds }
2531da177e4SLinus Torvalds
2541da177e4SLinus Torvalds /* x25_out.c */
2555db50ee6SJoe Perches int x25_output(struct sock *, struct sk_buff *);
2565db50ee6SJoe Perches void x25_kick(struct sock *);
2575db50ee6SJoe Perches void x25_enquiry_response(struct sock *);
2581da177e4SLinus Torvalds
2591da177e4SLinus Torvalds /* x25_route.c */
2605db50ee6SJoe Perches struct x25_route *x25_get_route(struct x25_address *addr);
2615db50ee6SJoe Perches struct net_device *x25_dev_get(char *);
2625db50ee6SJoe Perches void x25_route_device_down(struct net_device *dev);
2635db50ee6SJoe Perches int x25_route_ioctl(unsigned int, void __user *);
2645db50ee6SJoe Perches void x25_route_free(void);
2651da177e4SLinus Torvalds
x25_route_hold(struct x25_route * rt)2661da177e4SLinus Torvalds static __inline__ void x25_route_hold(struct x25_route *rt)
2671da177e4SLinus Torvalds {
2685f9ccf6fSReshetova, Elena refcount_inc(&rt->refcnt);
2691da177e4SLinus Torvalds }
2701da177e4SLinus Torvalds
x25_route_put(struct x25_route * rt)2711da177e4SLinus Torvalds static __inline__ void x25_route_put(struct x25_route *rt)
2721da177e4SLinus Torvalds {
2735f9ccf6fSReshetova, Elena if (refcount_dec_and_test(&rt->refcnt))
2741da177e4SLinus Torvalds kfree(rt);
2751da177e4SLinus Torvalds }
2761da177e4SLinus Torvalds
2771da177e4SLinus Torvalds /* x25_subr.c */
2785db50ee6SJoe Perches void x25_clear_queues(struct sock *);
2795db50ee6SJoe Perches void x25_frames_acked(struct sock *, unsigned short);
2805db50ee6SJoe Perches void x25_requeue_frames(struct sock *);
2815db50ee6SJoe Perches int x25_validate_nr(struct sock *, unsigned short);
2825db50ee6SJoe Perches void x25_write_internal(struct sock *, int);
2835db50ee6SJoe Perches int x25_decode(struct sock *, struct sk_buff *, int *, int *, int *, int *,
2845db50ee6SJoe Perches int *);
2855db50ee6SJoe Perches void x25_disconnect(struct sock *, int, unsigned char, unsigned char);
2861da177e4SLinus Torvalds
2871da177e4SLinus Torvalds /* x25_timer.c */
2885db50ee6SJoe Perches void x25_init_timers(struct sock *sk);
2895db50ee6SJoe Perches void x25_start_heartbeat(struct sock *);
2905db50ee6SJoe Perches void x25_start_t2timer(struct sock *);
2915db50ee6SJoe Perches void x25_start_t21timer(struct sock *);
2925db50ee6SJoe Perches void x25_start_t22timer(struct sock *);
2935db50ee6SJoe Perches void x25_start_t23timer(struct sock *);
2945db50ee6SJoe Perches void x25_stop_heartbeat(struct sock *);
2955db50ee6SJoe Perches void x25_stop_timer(struct sock *);
2965db50ee6SJoe Perches unsigned long x25_display_timer(struct sock *);
2975db50ee6SJoe Perches void x25_check_rbuf(struct sock *);
2981da177e4SLinus Torvalds
2991da177e4SLinus Torvalds /* sysctl_net_x25.c */
3002f5517aeSandrew hendry #ifdef CONFIG_SYSCTL
30164df6d52Slinzhang int x25_register_sysctl(void);
3025db50ee6SJoe Perches void x25_unregister_sysctl(void);
3032f5517aeSandrew hendry #else
x25_register_sysctl(void)30464df6d52Slinzhang static inline int x25_register_sysctl(void) { return 0; };
x25_unregister_sysctl(void)3052f5517aeSandrew hendry static inline void x25_unregister_sysctl(void) {};
3062f5517aeSandrew hendry #endif /* CONFIG_SYSCTL */
3072f5517aeSandrew hendry
3081da177e4SLinus Torvalds struct x25_skb_cb {
30995c96174SEric Dumazet unsigned int flags;
3101da177e4SLinus Torvalds };
3111da177e4SLinus Torvalds #define X25_SKB_CB(s) ((struct x25_skb_cb *) ((s)->cb))
3121da177e4SLinus Torvalds
3131da177e4SLinus Torvalds extern struct hlist_head x25_list;
3141da177e4SLinus Torvalds extern rwlock_t x25_list_lock;
3151da177e4SLinus Torvalds extern struct list_head x25_route_list;
3161da177e4SLinus Torvalds extern rwlock_t x25_route_list_lock;
31795a9dc43SAndrew Hendry extern struct list_head x25_forward_list;
31895a9dc43SAndrew Hendry extern rwlock_t x25_forward_list_lock;
3195595a1a5Sandrew hendry extern struct list_head x25_neigh_list;
3205595a1a5Sandrew hendry extern rwlock_t x25_neigh_list_lock;
3211da177e4SLinus Torvalds
3225db50ee6SJoe Perches int x25_proc_init(void);
3235db50ee6SJoe Perches void x25_proc_exit(void);
3241da177e4SLinus Torvalds #endif
325