x25.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  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. #ifndef _X25_H
  11. #define _X25_H
  12. #include <linux/x25.h>
  13. #include <linux/slab.h>
  14. #include <linux/refcount.h>
  15. #include <net/sock.h>
  16. #define X25_ADDR_LEN 16
  17. #define X25_MAX_L2_LEN 18 /* 802.2 LLC */
  18. #define X25_STD_MIN_LEN 3
  19. #define X25_EXT_MIN_LEN 4
  20. #define X25_GFI_SEQ_MASK 0x30
  21. #define X25_GFI_STDSEQ 0x10
  22. #define X25_GFI_EXTSEQ 0x20
  23. #define X25_Q_BIT 0x80
  24. #define X25_D_BIT 0x40
  25. #define X25_STD_M_BIT 0x10
  26. #define X25_EXT_M_BIT 0x01
  27. #define X25_CALL_REQUEST 0x0B
  28. #define X25_CALL_ACCEPTED 0x0F
  29. #define X25_CLEAR_REQUEST 0x13
  30. #define X25_CLEAR_CONFIRMATION 0x17
  31. #define X25_DATA 0x00
  32. #define X25_INTERRUPT 0x23
  33. #define X25_INTERRUPT_CONFIRMATION 0x27
  34. #define X25_RR 0x01
  35. #define X25_RNR 0x05
  36. #define X25_REJ 0x09
  37. #define X25_RESET_REQUEST 0x1B
  38. #define X25_RESET_CONFIRMATION 0x1F
  39. #define X25_REGISTRATION_REQUEST 0xF3
  40. #define X25_REGISTRATION_CONFIRMATION 0xF7
  41. #define X25_RESTART_REQUEST 0xFB
  42. #define X25_RESTART_CONFIRMATION 0xFF
  43. #define X25_DIAGNOSTIC 0xF1
  44. #define X25_ILLEGAL 0xFD
  45. /* Define the various conditions that may exist */
  46. #define X25_COND_ACK_PENDING 0x01
  47. #define X25_COND_OWN_RX_BUSY 0x02
  48. #define X25_COND_PEER_RX_BUSY 0x04
  49. /* Define Link State constants. */
  50. enum {
  51. X25_STATE_0, /* Ready */
  52. X25_STATE_1, /* Awaiting Call Accepted */
  53. X25_STATE_2, /* Awaiting Clear Confirmation */
  54. X25_STATE_3, /* Data Transfer */
  55. X25_STATE_4, /* Awaiting Reset Confirmation */
  56. X25_STATE_5 /* Call Accepted / Call Connected pending */
  57. };
  58. enum {
  59. X25_LINK_STATE_0,
  60. X25_LINK_STATE_1,
  61. X25_LINK_STATE_2,
  62. X25_LINK_STATE_3
  63. };
  64. #define X25_DEFAULT_T20 (180 * HZ) /* Default T20 value */
  65. #define X25_DEFAULT_T21 (200 * HZ) /* Default T21 value */
  66. #define X25_DEFAULT_T22 (180 * HZ) /* Default T22 value */
  67. #define X25_DEFAULT_T23 (180 * HZ) /* Default T23 value */
  68. #define X25_DEFAULT_T2 (3 * HZ) /* Default ack holdback value */
  69. #define X25_DEFAULT_WINDOW_SIZE 2 /* Default Window Size */
  70. #define X25_DEFAULT_PACKET_SIZE X25_PS128 /* Default Packet Size */
  71. #define X25_DEFAULT_THROUGHPUT 0x0A /* Default Throughput */
  72. #define X25_DEFAULT_REVERSE 0x00 /* Default Reverse Charging */
  73. #define X25_SMODULUS 8
  74. #define X25_EMODULUS 128
  75. /*
  76. * X.25 Facilities constants.
  77. */
  78. #define X25_FAC_CLASS_MASK 0xC0
  79. #define X25_FAC_CLASS_A 0x00
  80. #define X25_FAC_CLASS_B 0x40
  81. #define X25_FAC_CLASS_C 0x80
  82. #define X25_FAC_CLASS_D 0xC0
  83. #define X25_FAC_REVERSE 0x01 /* also fast select */
  84. #define X25_FAC_THROUGHPUT 0x02
  85. #define X25_FAC_PACKET_SIZE 0x42
  86. #define X25_FAC_WINDOW_SIZE 0x43
  87. #define X25_MAX_FAC_LEN 60
  88. #define X25_MAX_CUD_LEN 128
  89. #define X25_FAC_CALLING_AE 0xCB
  90. #define X25_FAC_CALLED_AE 0xC9
  91. #define X25_MARKER 0x00
  92. #define X25_DTE_SERVICES 0x0F
  93. #define X25_MAX_AE_LEN 40 /* Max num of semi-octets in AE - OSI Nw */
  94. #define X25_MAX_DTE_FACIL_LEN 21 /* Max length of DTE facility params */
  95. /* Bitset in x25_sock->flags for misc flags */
  96. #define X25_Q_BIT_FLAG 0
  97. #define X25_INTERRUPT_FLAG 1
  98. #define X25_ACCPT_APPRV_FLAG 2
  99. /**
  100. * struct x25_route - x25 routing entry
  101. * @node - entry in x25_list_lock
  102. * @address - Start of address range
  103. * @sigdigits - Number of sig digits
  104. * @dev - More than one for MLP
  105. * @refcnt - reference counter
  106. */
  107. struct x25_route {
  108. struct list_head node;
  109. struct x25_address address;
  110. unsigned int sigdigits;
  111. struct net_device *dev;
  112. refcount_t refcnt;
  113. };
  114. struct x25_neigh {
  115. struct list_head node;
  116. struct net_device *dev;
  117. unsigned int state;
  118. unsigned int extended;
  119. struct sk_buff_head queue;
  120. unsigned long t20;
  121. struct timer_list t20timer;
  122. unsigned long global_facil_mask;
  123. refcount_t refcnt;
  124. };
  125. struct x25_sock {
  126. struct sock sk;
  127. struct x25_address source_addr, dest_addr;
  128. struct x25_neigh *neighbour;
  129. unsigned int lci, cudmatchlength;
  130. unsigned char state, condition;
  131. unsigned short vs, vr, va, vl;
  132. unsigned long t2, t21, t22, t23;
  133. unsigned short fraglen;
  134. unsigned long flags;
  135. struct sk_buff_head ack_queue;
  136. struct sk_buff_head fragment_queue;
  137. struct sk_buff_head interrupt_in_queue;
  138. struct sk_buff_head interrupt_out_queue;
  139. struct timer_list timer;
  140. struct x25_causediag causediag;
  141. struct x25_facilities facilities;
  142. struct x25_dte_facilities dte_facilities;
  143. struct x25_calluserdata calluserdata;
  144. unsigned long vc_facil_mask; /* inc_call facilities mask */
  145. };
  146. struct x25_forward {
  147. struct list_head node;
  148. unsigned int lci;
  149. struct net_device *dev1;
  150. struct net_device *dev2;
  151. atomic_t refcnt;
  152. };
  153. #define x25_sk(ptr) container_of_const(ptr, struct x25_sock, sk)
  154. /* af_x25.c */
  155. extern int sysctl_x25_restart_request_timeout;
  156. extern int sysctl_x25_call_request_timeout;
  157. extern int sysctl_x25_reset_request_timeout;
  158. extern int sysctl_x25_clear_request_timeout;
  159. extern int sysctl_x25_ack_holdback_timeout;
  160. extern int sysctl_x25_forward;
  161. int x25_parse_address_block(struct sk_buff *skb,
  162. struct x25_address *called_addr,
  163. struct x25_address *calling_addr);
  164. int x25_addr_ntoa(unsigned char *, struct x25_address *, struct x25_address *);
  165. int x25_addr_aton(unsigned char *, struct x25_address *, struct x25_address *);
  166. struct sock *x25_find_socket(unsigned int, struct x25_neigh *);
  167. void x25_destroy_socket_from_timer(struct sock *);
  168. int x25_rx_call_request(struct sk_buff *, struct x25_neigh *, unsigned int);
  169. void x25_kill_by_neigh(struct x25_neigh *);
  170. /* x25_dev.c */
  171. void x25_send_frame(struct sk_buff *, struct x25_neigh *);
  172. int x25_lapb_receive_frame(struct sk_buff *, struct net_device *,
  173. struct packet_type *, struct net_device *);
  174. void x25_establish_link(struct x25_neigh *);
  175. /* x25_facilities.c */
  176. int x25_parse_facilities(struct sk_buff *, struct x25_facilities *,
  177. struct x25_dte_facilities *, unsigned long *);
  178. int x25_create_facilities(unsigned char *, struct x25_facilities *,
  179. struct x25_dte_facilities *, unsigned long);
  180. int x25_negotiate_facilities(struct sk_buff *, struct sock *,
  181. struct x25_facilities *,
  182. struct x25_dte_facilities *);
  183. void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
  184. /* x25_forward.c */
  185. void x25_clear_forward_by_lci(unsigned int lci);
  186. void x25_clear_forward_by_dev(struct net_device *);
  187. int x25_forward_data(int, struct x25_neigh *, struct sk_buff *);
  188. int x25_forward_call(struct x25_address *, struct x25_neigh *, struct sk_buff *,
  189. int);
  190. /* x25_in.c */
  191. int x25_process_rx_frame(struct sock *, struct sk_buff *);
  192. int x25_backlog_rcv(struct sock *, struct sk_buff *);
  193. /* x25_link.c */
  194. void x25_link_control(struct sk_buff *, struct x25_neigh *, unsigned short);
  195. void x25_link_device_up(struct net_device *);
  196. void x25_link_device_down(struct net_device *);
  197. void x25_link_established(struct x25_neigh *);
  198. void x25_link_terminated(struct x25_neigh *);
  199. void x25_transmit_clear_request(struct x25_neigh *, unsigned int,
  200. unsigned char);
  201. void x25_transmit_link(struct sk_buff *, struct x25_neigh *);
  202. int x25_subscr_ioctl(unsigned int, void __user *);
  203. struct x25_neigh *x25_get_neigh(struct net_device *);
  204. void x25_link_free(void);
  205. /* x25_neigh.c */
  206. static __inline__ void x25_neigh_hold(struct x25_neigh *nb)
  207. {
  208. refcount_inc(&nb->refcnt);
  209. }
  210. static __inline__ void x25_neigh_put(struct x25_neigh *nb)
  211. {
  212. if (refcount_dec_and_test(&nb->refcnt))
  213. kfree(nb);
  214. }
  215. /* x25_out.c */
  216. int x25_output(struct sock *, struct sk_buff *);
  217. void x25_kick(struct sock *);
  218. void x25_enquiry_response(struct sock *);
  219. /* x25_route.c */
  220. struct x25_route *x25_get_route(struct x25_address *addr);
  221. struct net_device *x25_dev_get(char *);
  222. void x25_route_device_down(struct net_device *dev);
  223. int x25_route_ioctl(unsigned int, void __user *);
  224. void x25_route_free(void);
  225. static __inline__ void x25_route_hold(struct x25_route *rt)
  226. {
  227. refcount_inc(&rt->refcnt);
  228. }
  229. static __inline__ void x25_route_put(struct x25_route *rt)
  230. {
  231. if (refcount_dec_and_test(&rt->refcnt))
  232. kfree(rt);
  233. }
  234. /* x25_subr.c */
  235. void x25_clear_queues(struct sock *);
  236. void x25_frames_acked(struct sock *, unsigned short);
  237. void x25_requeue_frames(struct sock *);
  238. int x25_validate_nr(struct sock *, unsigned short);
  239. void x25_write_internal(struct sock *, int);
  240. int x25_decode(struct sock *, struct sk_buff *, int *, int *, int *, int *,
  241. int *);
  242. void x25_disconnect(struct sock *, int, unsigned char, unsigned char);
  243. /* x25_timer.c */
  244. void x25_init_timers(struct sock *sk);
  245. void x25_start_heartbeat(struct sock *);
  246. void x25_start_t2timer(struct sock *);
  247. void x25_start_t21timer(struct sock *);
  248. void x25_start_t22timer(struct sock *);
  249. void x25_start_t23timer(struct sock *);
  250. void x25_stop_heartbeat(struct sock *);
  251. void x25_stop_timer(struct sock *);
  252. unsigned long x25_display_timer(struct sock *);
  253. void x25_check_rbuf(struct sock *);
  254. /* sysctl_net_x25.c */
  255. #ifdef CONFIG_SYSCTL
  256. int x25_register_sysctl(void);
  257. void x25_unregister_sysctl(void);
  258. #else
  259. static inline int x25_register_sysctl(void) { return 0; };
  260. static inline void x25_unregister_sysctl(void) {};
  261. #endif /* CONFIG_SYSCTL */
  262. struct x25_skb_cb {
  263. unsigned int flags;
  264. };
  265. #define X25_SKB_CB(s) ((struct x25_skb_cb *) ((s)->cb))
  266. extern struct hlist_head x25_list;
  267. extern rwlock_t x25_list_lock;
  268. extern struct list_head x25_route_list;
  269. extern rwlock_t x25_route_list_lock;
  270. extern struct list_head x25_forward_list;
  271. extern rwlock_t x25_forward_list_lock;
  272. extern struct list_head x25_neigh_list;
  273. extern rwlock_t x25_neigh_list_lock;
  274. int x25_proc_init(void);
  275. void x25_proc_exit(void);
  276. #endif