x25.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. };
  57. enum {
  58. X25_LINK_STATE_0,
  59. X25_LINK_STATE_1,
  60. X25_LINK_STATE_2,
  61. X25_LINK_STATE_3
  62. };
  63. #define X25_DEFAULT_T20 (180 * HZ) /* Default T20 value */
  64. #define X25_DEFAULT_T21 (200 * HZ) /* Default T21 value */
  65. #define X25_DEFAULT_T22 (180 * HZ) /* Default T22 value */
  66. #define X25_DEFAULT_T23 (180 * HZ) /* Default T23 value */
  67. #define X25_DEFAULT_T2 (3 * HZ) /* Default ack holdback value */
  68. #define X25_DEFAULT_WINDOW_SIZE 2 /* Default Window Size */
  69. #define X25_DEFAULT_PACKET_SIZE X25_PS128 /* Default Packet Size */
  70. #define X25_DEFAULT_THROUGHPUT 0x0A /* Deafult Throughput */
  71. #define X25_DEFAULT_REVERSE 0x00 /* Default Reverse Charging */
  72. #define X25_SMODULUS 8
  73. #define X25_EMODULUS 128
  74. /*
  75. * X.25 Facilities constants.
  76. */
  77. #define X25_FAC_CLASS_MASK 0xC0
  78. #define X25_FAC_CLASS_A 0x00
  79. #define X25_FAC_CLASS_B 0x40
  80. #define X25_FAC_CLASS_C 0x80
  81. #define X25_FAC_CLASS_D 0xC0
  82. #define X25_FAC_REVERSE 0x01 /* also fast select */
  83. #define X25_FAC_THROUGHPUT 0x02
  84. #define X25_FAC_PACKET_SIZE 0x42
  85. #define X25_FAC_WINDOW_SIZE 0x43
  86. #define X25_MAX_FAC_LEN 60
  87. #define X25_MAX_CUD_LEN 128
  88. #define X25_FAC_CALLING_AE 0xCB
  89. #define X25_FAC_CALLED_AE 0xC9
  90. #define X25_MARKER 0x00
  91. #define X25_DTE_SERVICES 0x0F
  92. #define X25_MAX_AE_LEN 40 /* Max num of semi-octets in AE - OSI Nw */
  93. #define X25_MAX_DTE_FACIL_LEN 21 /* Max length of DTE facility params */
  94. /* Bitset in x25_sock->flags for misc flags */
  95. #define X25_Q_BIT_FLAG 0
  96. #define X25_INTERRUPT_FLAG 1
  97. #define X25_ACCPT_APPRV_FLAG 2
  98. /**
  99. * struct x25_route - x25 routing entry
  100. * @node - entry in x25_list_lock
  101. * @address - Start of address range
  102. * @sigdigits - Number of sig digits
  103. * @dev - More than one for MLP
  104. * @refcnt - reference counter
  105. */
  106. struct x25_route {
  107. struct list_head node;
  108. struct x25_address address;
  109. unsigned int sigdigits;
  110. struct net_device *dev;
  111. refcount_t refcnt;
  112. };
  113. struct x25_neigh {
  114. struct list_head node;
  115. struct net_device *dev;
  116. unsigned int state;
  117. unsigned int extended;
  118. struct sk_buff_head queue;
  119. unsigned long t20;
  120. struct timer_list t20timer;
  121. unsigned long global_facil_mask;
  122. refcount_t refcnt;
  123. };
  124. struct x25_sock {
  125. struct sock sk;
  126. struct x25_address source_addr, dest_addr;
  127. struct x25_neigh *neighbour;
  128. unsigned int lci, cudmatchlength;
  129. unsigned char state, condition;
  130. unsigned short vs, vr, va, vl;
  131. unsigned long t2, t21, t22, t23;
  132. unsigned short fraglen;
  133. unsigned long flags;
  134. struct sk_buff_head ack_queue;
  135. struct sk_buff_head fragment_queue;
  136. struct sk_buff_head interrupt_in_queue;
  137. struct sk_buff_head interrupt_out_queue;
  138. struct timer_list timer;
  139. struct x25_causediag causediag;
  140. struct x25_facilities facilities;
  141. struct x25_dte_facilities dte_facilities;
  142. struct x25_calluserdata calluserdata;
  143. unsigned long vc_facil_mask; /* inc_call facilities mask */
  144. };
  145. struct x25_forward {
  146. struct list_head node;
  147. unsigned int lci;
  148. struct net_device *dev1;
  149. struct net_device *dev2;
  150. atomic_t refcnt;
  151. };
  152. static inline struct x25_sock *x25_sk(const struct sock *sk)
  153. {
  154. return (struct x25_sock *)sk;
  155. }
  156. /* af_x25.c */
  157. extern int sysctl_x25_restart_request_timeout;
  158. extern int sysctl_x25_call_request_timeout;
  159. extern int sysctl_x25_reset_request_timeout;
  160. extern int sysctl_x25_clear_request_timeout;
  161. extern int sysctl_x25_ack_holdback_timeout;
  162. extern int sysctl_x25_forward;
  163. int x25_parse_address_block(struct sk_buff *skb,
  164. struct x25_address *called_addr,
  165. struct x25_address *calling_addr);
  166. int x25_addr_ntoa(unsigned char *, struct x25_address *, struct x25_address *);
  167. int x25_addr_aton(unsigned char *, struct x25_address *, struct x25_address *);
  168. struct sock *x25_find_socket(unsigned int, struct x25_neigh *);
  169. void x25_destroy_socket_from_timer(struct sock *);
  170. int x25_rx_call_request(struct sk_buff *, struct x25_neigh *, unsigned int);
  171. void x25_kill_by_neigh(struct x25_neigh *);
  172. /* x25_dev.c */
  173. void x25_send_frame(struct sk_buff *, struct x25_neigh *);
  174. int x25_lapb_receive_frame(struct sk_buff *, struct net_device *,
  175. struct packet_type *, struct net_device *);
  176. void x25_establish_link(struct x25_neigh *);
  177. void x25_terminate_link(struct x25_neigh *);
  178. /* x25_facilities.c */
  179. int x25_parse_facilities(struct sk_buff *, struct x25_facilities *,
  180. struct x25_dte_facilities *, unsigned long *);
  181. int x25_create_facilities(unsigned char *, struct x25_facilities *,
  182. struct x25_dte_facilities *, unsigned long);
  183. int x25_negotiate_facilities(struct sk_buff *, struct sock *,
  184. struct x25_facilities *,
  185. struct x25_dte_facilities *);
  186. void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
  187. /* x25_forward.c */
  188. void x25_clear_forward_by_lci(unsigned int lci);
  189. void x25_clear_forward_by_dev(struct net_device *);
  190. int x25_forward_data(int, struct x25_neigh *, struct sk_buff *);
  191. int x25_forward_call(struct x25_address *, struct x25_neigh *, struct sk_buff *,
  192. int);
  193. /* x25_in.c */
  194. int x25_process_rx_frame(struct sock *, struct sk_buff *);
  195. int x25_backlog_rcv(struct sock *, struct sk_buff *);
  196. /* x25_link.c */
  197. void x25_link_control(struct sk_buff *, struct x25_neigh *, unsigned short);
  198. void x25_link_device_up(struct net_device *);
  199. void x25_link_device_down(struct net_device *);
  200. void x25_link_established(struct x25_neigh *);
  201. void x25_link_terminated(struct x25_neigh *);
  202. void x25_transmit_clear_request(struct x25_neigh *, unsigned int,
  203. unsigned char);
  204. void x25_transmit_link(struct sk_buff *, struct x25_neigh *);
  205. int x25_subscr_ioctl(unsigned int, void __user *);
  206. struct x25_neigh *x25_get_neigh(struct net_device *);
  207. void x25_link_free(void);
  208. /* x25_neigh.c */
  209. static __inline__ void x25_neigh_hold(struct x25_neigh *nb)
  210. {
  211. refcount_inc(&nb->refcnt);
  212. }
  213. static __inline__ void x25_neigh_put(struct x25_neigh *nb)
  214. {
  215. if (refcount_dec_and_test(&nb->refcnt))
  216. kfree(nb);
  217. }
  218. /* x25_out.c */
  219. int x25_output(struct sock *, struct sk_buff *);
  220. void x25_kick(struct sock *);
  221. void x25_enquiry_response(struct sock *);
  222. /* x25_route.c */
  223. struct x25_route *x25_get_route(struct x25_address *addr);
  224. struct net_device *x25_dev_get(char *);
  225. void x25_route_device_down(struct net_device *dev);
  226. int x25_route_ioctl(unsigned int, void __user *);
  227. void x25_route_free(void);
  228. static __inline__ void x25_route_hold(struct x25_route *rt)
  229. {
  230. refcount_inc(&rt->refcnt);
  231. }
  232. static __inline__ void x25_route_put(struct x25_route *rt)
  233. {
  234. if (refcount_dec_and_test(&rt->refcnt))
  235. kfree(rt);
  236. }
  237. /* x25_subr.c */
  238. void x25_clear_queues(struct sock *);
  239. void x25_frames_acked(struct sock *, unsigned short);
  240. void x25_requeue_frames(struct sock *);
  241. int x25_validate_nr(struct sock *, unsigned short);
  242. void x25_write_internal(struct sock *, int);
  243. int x25_decode(struct sock *, struct sk_buff *, int *, int *, int *, int *,
  244. int *);
  245. void x25_disconnect(struct sock *, int, unsigned char, unsigned char);
  246. /* x25_timer.c */
  247. void x25_init_timers(struct sock *sk);
  248. void x25_start_heartbeat(struct sock *);
  249. void x25_start_t2timer(struct sock *);
  250. void x25_start_t21timer(struct sock *);
  251. void x25_start_t22timer(struct sock *);
  252. void x25_start_t23timer(struct sock *);
  253. void x25_stop_heartbeat(struct sock *);
  254. void x25_stop_timer(struct sock *);
  255. unsigned long x25_display_timer(struct sock *);
  256. void x25_check_rbuf(struct sock *);
  257. /* sysctl_net_x25.c */
  258. #ifdef CONFIG_SYSCTL
  259. int x25_register_sysctl(void);
  260. void x25_unregister_sysctl(void);
  261. #else
  262. static inline int x25_register_sysctl(void) { return 0; };
  263. static inline void x25_unregister_sysctl(void) {};
  264. #endif /* CONFIG_SYSCTL */
  265. struct x25_skb_cb {
  266. unsigned int flags;
  267. };
  268. #define X25_SKB_CB(s) ((struct x25_skb_cb *) ((s)->cb))
  269. extern struct hlist_head x25_list;
  270. extern rwlock_t x25_list_lock;
  271. extern struct list_head x25_route_list;
  272. extern rwlock_t x25_route_list_lock;
  273. extern struct list_head x25_forward_list;
  274. extern rwlock_t x25_forward_list_lock;
  275. extern struct list_head x25_neigh_list;
  276. extern rwlock_t x25_neigh_list_lock;
  277. int x25_proc_init(void);
  278. void x25_proc_exit(void);
  279. #endif