x25.h 9.4 KB

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