x25.h 9.5 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. 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 /* Deafult 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. static inline struct x25_sock *x25_sk(const struct sock *sk)
  154. {
  155. return (struct x25_sock *)sk;
  156. }
  157. /* af_x25.c */
  158. extern int sysctl_x25_restart_request_timeout;
  159. extern int sysctl_x25_call_request_timeout;
  160. extern int sysctl_x25_reset_request_timeout;
  161. extern int sysctl_x25_clear_request_timeout;
  162. extern int sysctl_x25_ack_holdback_timeout;
  163. extern int sysctl_x25_forward;
  164. int x25_parse_address_block(struct sk_buff *skb,
  165. struct x25_address *called_addr,
  166. struct x25_address *calling_addr);
  167. int x25_addr_ntoa(unsigned char *, struct x25_address *, struct x25_address *);
  168. int x25_addr_aton(unsigned char *, struct x25_address *, struct x25_address *);
  169. struct sock *x25_find_socket(unsigned int, struct x25_neigh *);
  170. void x25_destroy_socket_from_timer(struct sock *);
  171. int x25_rx_call_request(struct sk_buff *, struct x25_neigh *, unsigned int);
  172. void x25_kill_by_neigh(struct x25_neigh *);
  173. /* x25_dev.c */
  174. void x25_send_frame(struct sk_buff *, struct x25_neigh *);
  175. int x25_lapb_receive_frame(struct sk_buff *, struct net_device *,
  176. struct packet_type *, struct net_device *);
  177. void x25_establish_link(struct x25_neigh *);
  178. void x25_terminate_link(struct x25_neigh *);
  179. /* x25_facilities.c */
  180. int x25_parse_facilities(struct sk_buff *, struct x25_facilities *,
  181. struct x25_dte_facilities *, unsigned long *);
  182. int x25_create_facilities(unsigned char *, struct x25_facilities *,
  183. struct x25_dte_facilities *, unsigned long);
  184. int x25_negotiate_facilities(struct sk_buff *, struct sock *,
  185. struct x25_facilities *,
  186. struct x25_dte_facilities *);
  187. void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
  188. /* x25_forward.c */
  189. void x25_clear_forward_by_lci(unsigned int lci);
  190. void x25_clear_forward_by_dev(struct net_device *);
  191. int x25_forward_data(int, struct x25_neigh *, struct sk_buff *);
  192. int x25_forward_call(struct x25_address *, struct x25_neigh *, struct sk_buff *,
  193. int);
  194. /* x25_in.c */
  195. int x25_process_rx_frame(struct sock *, struct sk_buff *);
  196. int x25_backlog_rcv(struct sock *, struct sk_buff *);
  197. /* x25_link.c */
  198. void x25_link_control(struct sk_buff *, struct x25_neigh *, unsigned short);
  199. void x25_link_device_up(struct net_device *);
  200. void x25_link_device_down(struct net_device *);
  201. void x25_link_established(struct x25_neigh *);
  202. void x25_link_terminated(struct x25_neigh *);
  203. void x25_transmit_clear_request(struct x25_neigh *, unsigned int,
  204. unsigned char);
  205. void x25_transmit_link(struct sk_buff *, struct x25_neigh *);
  206. int x25_subscr_ioctl(unsigned int, void __user *);
  207. struct x25_neigh *x25_get_neigh(struct net_device *);
  208. void x25_link_free(void);
  209. /* x25_neigh.c */
  210. static __inline__ void x25_neigh_hold(struct x25_neigh *nb)
  211. {
  212. refcount_inc(&nb->refcnt);
  213. }
  214. static __inline__ void x25_neigh_put(struct x25_neigh *nb)
  215. {
  216. if (refcount_dec_and_test(&nb->refcnt))
  217. kfree(nb);
  218. }
  219. /* x25_out.c */
  220. int x25_output(struct sock *, struct sk_buff *);
  221. void x25_kick(struct sock *);
  222. void x25_enquiry_response(struct sock *);
  223. /* x25_route.c */
  224. struct x25_route *x25_get_route(struct x25_address *addr);
  225. struct net_device *x25_dev_get(char *);
  226. void x25_route_device_down(struct net_device *dev);
  227. int x25_route_ioctl(unsigned int, void __user *);
  228. void x25_route_free(void);
  229. static __inline__ void x25_route_hold(struct x25_route *rt)
  230. {
  231. refcount_inc(&rt->refcnt);
  232. }
  233. static __inline__ void x25_route_put(struct x25_route *rt)
  234. {
  235. if (refcount_dec_and_test(&rt->refcnt))
  236. kfree(rt);
  237. }
  238. /* x25_subr.c */
  239. void x25_clear_queues(struct sock *);
  240. void x25_frames_acked(struct sock *, unsigned short);
  241. void x25_requeue_frames(struct sock *);
  242. int x25_validate_nr(struct sock *, unsigned short);
  243. void x25_write_internal(struct sock *, int);
  244. int x25_decode(struct sock *, struct sk_buff *, int *, int *, int *, int *,
  245. int *);
  246. void x25_disconnect(struct sock *, int, unsigned char, unsigned char);
  247. /* x25_timer.c */
  248. void x25_init_timers(struct sock *sk);
  249. void x25_start_heartbeat(struct sock *);
  250. void x25_start_t2timer(struct sock *);
  251. void x25_start_t21timer(struct sock *);
  252. void x25_start_t22timer(struct sock *);
  253. void x25_start_t23timer(struct sock *);
  254. void x25_stop_heartbeat(struct sock *);
  255. void x25_stop_timer(struct sock *);
  256. unsigned long x25_display_timer(struct sock *);
  257. void x25_check_rbuf(struct sock *);
  258. /* sysctl_net_x25.c */
  259. #ifdef CONFIG_SYSCTL
  260. int x25_register_sysctl(void);
  261. void x25_unregister_sysctl(void);
  262. #else
  263. static inline int x25_register_sysctl(void) { return 0; };
  264. static inline void x25_unregister_sysctl(void) {};
  265. #endif /* CONFIG_SYSCTL */
  266. struct x25_skb_cb {
  267. unsigned int flags;
  268. };
  269. #define X25_SKB_CB(s) ((struct x25_skb_cb *) ((s)->cb))
  270. extern struct hlist_head x25_list;
  271. extern rwlock_t x25_list_lock;
  272. extern struct list_head x25_route_list;
  273. extern rwlock_t x25_route_list_lock;
  274. extern struct list_head x25_forward_list;
  275. extern rwlock_t x25_forward_list_lock;
  276. extern struct list_head x25_neigh_list;
  277. extern rwlock_t x25_neigh_list_lock;
  278. int x25_proc_init(void);
  279. void x25_proc_exit(void);
  280. #endif