ax25.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /*
  2. * Declarations of AX.25 type objects.
  3. *
  4. * Alan Cox (GW4PTS) 10/11/93
  5. */
  6. #ifndef _AX25_H
  7. #define _AX25_H
  8. #include <linux/ax25.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/timer.h>
  11. #include <linux/list.h>
  12. #include <linux/slab.h>
  13. #include <asm/atomic.h>
  14. #define AX25_T1CLAMPLO 1
  15. #define AX25_T1CLAMPHI (30 * HZ)
  16. #define AX25_BPQ_HEADER_LEN 16
  17. #define AX25_KISS_HEADER_LEN 1
  18. #define AX25_HEADER_LEN 17
  19. #define AX25_ADDR_LEN 7
  20. #define AX25_DIGI_HEADER_LEN (AX25_MAX_DIGIS * AX25_ADDR_LEN)
  21. #define AX25_MAX_HEADER_LEN (AX25_HEADER_LEN + AX25_DIGI_HEADER_LEN)
  22. /* AX.25 Protocol IDs */
  23. #define AX25_P_ROSE 0x01
  24. #define AX25_P_VJCOMP 0x06 /* Compressed TCP/IP packet */
  25. /* Van Jacobsen (RFC 1144) */
  26. #define AX25_P_VJUNCOMP 0x07 /* Uncompressed TCP/IP packet */
  27. /* Van Jacobsen (RFC 1144) */
  28. #define AX25_P_SEGMENT 0x08 /* Segmentation fragment */
  29. #define AX25_P_TEXNET 0xc3 /* TEXTNET datagram protocol */
  30. #define AX25_P_LQ 0xc4 /* Link Quality Protocol */
  31. #define AX25_P_ATALK 0xca /* Appletalk */
  32. #define AX25_P_ATALK_ARP 0xcb /* Appletalk ARP */
  33. #define AX25_P_IP 0xcc /* ARPA Internet Protocol */
  34. #define AX25_P_ARP 0xcd /* ARPA Address Resolution */
  35. #define AX25_P_FLEXNET 0xce /* FlexNet */
  36. #define AX25_P_NETROM 0xcf /* NET/ROM */
  37. #define AX25_P_TEXT 0xF0 /* No layer 3 protocol impl. */
  38. /* AX.25 Segment control values */
  39. #define AX25_SEG_REM 0x7F
  40. #define AX25_SEG_FIRST 0x80
  41. #define AX25_CBIT 0x80 /* Command/Response bit */
  42. #define AX25_EBIT 0x01 /* HDLC Address Extension bit */
  43. #define AX25_HBIT 0x80 /* Has been repeated bit */
  44. #define AX25_SSSID_SPARE 0x60 /* Unused bits in SSID for standard AX.25 */
  45. #define AX25_ESSID_SPARE 0x20 /* Unused bits in SSID for extended AX.25 */
  46. #define AX25_DAMA_FLAG 0x20 /* Well, it is *NOT* unused! (dl1bke 951121 */
  47. #define AX25_COND_ACK_PENDING 0x01
  48. #define AX25_COND_REJECT 0x02
  49. #define AX25_COND_PEER_RX_BUSY 0x04
  50. #define AX25_COND_OWN_RX_BUSY 0x08
  51. #define AX25_COND_DAMA_MODE 0x10
  52. #ifndef _LINUX_NETDEVICE_H
  53. #include <linux/netdevice.h>
  54. #endif
  55. /* Upper sub-layer (LAPB) definitions */
  56. /* Control field templates */
  57. #define AX25_I 0x00 /* Information frames */
  58. #define AX25_S 0x01 /* Supervisory frames */
  59. #define AX25_RR 0x01 /* Receiver ready */
  60. #define AX25_RNR 0x05 /* Receiver not ready */
  61. #define AX25_REJ 0x09 /* Reject */
  62. #define AX25_U 0x03 /* Unnumbered frames */
  63. #define AX25_SABM 0x2f /* Set Asynchronous Balanced Mode */
  64. #define AX25_SABME 0x6f /* Set Asynchronous Balanced Mode Extended */
  65. #define AX25_DISC 0x43 /* Disconnect */
  66. #define AX25_DM 0x0f /* Disconnected mode */
  67. #define AX25_UA 0x63 /* Unnumbered acknowledge */
  68. #define AX25_FRMR 0x87 /* Frame reject */
  69. #define AX25_UI 0x03 /* Unnumbered information */
  70. #define AX25_XID 0xaf /* Exchange information */
  71. #define AX25_TEST 0xe3 /* Test */
  72. #define AX25_PF 0x10 /* Poll/final bit for standard AX.25 */
  73. #define AX25_EPF 0x01 /* Poll/final bit for extended AX.25 */
  74. #define AX25_ILLEGAL 0x100 /* Impossible to be a real frame type */
  75. #define AX25_POLLOFF 0
  76. #define AX25_POLLON 1
  77. /* AX25 L2 C-bit */
  78. #define AX25_COMMAND 1
  79. #define AX25_RESPONSE 2
  80. /* Define Link State constants. */
  81. enum {
  82. AX25_STATE_0, /* Listening */
  83. AX25_STATE_1, /* SABM sent */
  84. AX25_STATE_2, /* DISC sent */
  85. AX25_STATE_3, /* Established */
  86. AX25_STATE_4 /* Recovery */
  87. };
  88. #define AX25_MODULUS 8 /* Standard AX.25 modulus */
  89. #define AX25_EMODULUS 128 /* Extended AX.25 modulus */
  90. enum {
  91. AX25_PROTO_STD_SIMPLEX,
  92. AX25_PROTO_STD_DUPLEX,
  93. #ifdef CONFIG_AX25_DAMA_SLAVE
  94. AX25_PROTO_DAMA_SLAVE,
  95. #ifdef CONFIG_AX25_DAMA_MASTER
  96. AX25_PROTO_DAMA_MASTER,
  97. #define AX25_PROTO_MAX AX25_PROTO_DAMA_MASTER
  98. #endif
  99. #endif
  100. __AX25_PROTO_MAX,
  101. AX25_PROTO_MAX = __AX25_PROTO_MAX -1
  102. };
  103. enum {
  104. AX25_VALUES_IPDEFMODE, /* 0=DG 1=VC */
  105. AX25_VALUES_AXDEFMODE, /* 0=Normal 1=Extended Seq Nos */
  106. AX25_VALUES_BACKOFF, /* 0=None 1=Linear 2=Exponential */
  107. AX25_VALUES_CONMODE, /* Allow connected modes - 0=No 1=no "PID text" 2=all PIDs */
  108. AX25_VALUES_WINDOW, /* Default window size for standard AX.25 */
  109. AX25_VALUES_EWINDOW, /* Default window size for extended AX.25 */
  110. AX25_VALUES_T1, /* Default T1 timeout value */
  111. AX25_VALUES_T2, /* Default T2 timeout value */
  112. AX25_VALUES_T3, /* Default T3 timeout value */
  113. AX25_VALUES_IDLE, /* Connected mode idle timer */
  114. AX25_VALUES_N2, /* Default N2 value */
  115. AX25_VALUES_PACLEN, /* AX.25 MTU */
  116. AX25_VALUES_PROTOCOL, /* Std AX.25, DAMA Slave, DAMA Master */
  117. AX25_VALUES_DS_TIMEOUT, /* DAMA Slave timeout */
  118. AX25_MAX_VALUES /* THIS MUST REMAIN THE LAST ENTRY OF THIS LIST */
  119. };
  120. #define AX25_DEF_IPDEFMODE 0 /* Datagram */
  121. #define AX25_DEF_AXDEFMODE 0 /* Normal */
  122. #define AX25_DEF_BACKOFF 1 /* Linear backoff */
  123. #define AX25_DEF_CONMODE 2 /* Connected mode allowed */
  124. #define AX25_DEF_WINDOW 2 /* Window=2 */
  125. #define AX25_DEF_EWINDOW 32 /* Module-128 Window=32 */
  126. #define AX25_DEF_T1 10000 /* T1=10s */
  127. #define AX25_DEF_T2 3000 /* T2=3s */
  128. #define AX25_DEF_T3 300000 /* T3=300s */
  129. #define AX25_DEF_N2 10 /* N2=10 */
  130. #define AX25_DEF_IDLE 0 /* Idle=None */
  131. #define AX25_DEF_PACLEN 256 /* Paclen=256 */
  132. #define AX25_DEF_PROTOCOL AX25_PROTO_STD_SIMPLEX /* Standard AX.25 */
  133. #define AX25_DEF_DS_TIMEOUT 180000 /* DAMA timeout 3 minutes */
  134. typedef struct ax25_uid_assoc {
  135. struct hlist_node uid_node;
  136. atomic_t refcount;
  137. uid_t uid;
  138. ax25_address call;
  139. } ax25_uid_assoc;
  140. #define ax25_uid_for_each(__ax25, node, list) \
  141. hlist_for_each_entry(__ax25, node, list, uid_node)
  142. #define ax25_uid_hold(ax25) \
  143. atomic_inc(&((ax25)->refcount))
  144. static inline void ax25_uid_put(ax25_uid_assoc *assoc)
  145. {
  146. if (atomic_dec_and_test(&assoc->refcount)) {
  147. kfree(assoc);
  148. }
  149. }
  150. typedef struct {
  151. ax25_address calls[AX25_MAX_DIGIS];
  152. unsigned char repeated[AX25_MAX_DIGIS];
  153. unsigned char ndigi;
  154. signed char lastrepeat;
  155. } ax25_digi;
  156. typedef struct ax25_route {
  157. struct ax25_route *next;
  158. atomic_t refcount;
  159. ax25_address callsign;
  160. struct net_device *dev;
  161. ax25_digi *digipeat;
  162. char ip_mode;
  163. } ax25_route;
  164. static inline void ax25_hold_route(ax25_route *ax25_rt)
  165. {
  166. atomic_inc(&ax25_rt->refcount);
  167. }
  168. extern void __ax25_put_route(ax25_route *ax25_rt);
  169. static inline void ax25_put_route(ax25_route *ax25_rt)
  170. {
  171. if (atomic_dec_and_test(&ax25_rt->refcount))
  172. __ax25_put_route(ax25_rt);
  173. }
  174. typedef struct {
  175. char slave; /* slave_mode? */
  176. struct timer_list slave_timer; /* timeout timer */
  177. unsigned short slave_timeout; /* when? */
  178. } ax25_dama_info;
  179. struct ctl_table;
  180. typedef struct ax25_dev {
  181. struct ax25_dev *next;
  182. struct net_device *dev;
  183. struct net_device *forward;
  184. struct ctl_table *systable;
  185. int values[AX25_MAX_VALUES];
  186. #if defined(CONFIG_AX25_DAMA_SLAVE) || defined(CONFIG_AX25_DAMA_MASTER)
  187. ax25_dama_info dama;
  188. #endif
  189. } ax25_dev;
  190. typedef struct ax25_cb {
  191. struct hlist_node ax25_node;
  192. ax25_address source_addr, dest_addr;
  193. ax25_digi *digipeat;
  194. ax25_dev *ax25_dev;
  195. unsigned char iamdigi;
  196. unsigned char state, modulus, pidincl;
  197. unsigned short vs, vr, va;
  198. unsigned char condition, backoff;
  199. unsigned char n2, n2count;
  200. struct timer_list t1timer, t2timer, t3timer, idletimer;
  201. unsigned long t1, t2, t3, idle, rtt;
  202. unsigned short paclen, fragno, fraglen;
  203. struct sk_buff_head write_queue;
  204. struct sk_buff_head reseq_queue;
  205. struct sk_buff_head ack_queue;
  206. struct sk_buff_head frag_queue;
  207. unsigned char window;
  208. struct timer_list timer, dtimer;
  209. struct sock *sk; /* Backlink to socket */
  210. atomic_t refcount;
  211. } ax25_cb;
  212. #define ax25_sk(__sk) ((ax25_cb *)(__sk)->sk_protinfo)
  213. #define ax25_for_each(__ax25, node, list) \
  214. hlist_for_each_entry(__ax25, node, list, ax25_node)
  215. #define ax25_cb_hold(__ax25) \
  216. atomic_inc(&((__ax25)->refcount))
  217. static __inline__ void ax25_cb_put(ax25_cb *ax25)
  218. {
  219. if (atomic_dec_and_test(&ax25->refcount)) {
  220. kfree(ax25->digipeat);
  221. kfree(ax25);
  222. }
  223. }
  224. static inline __be16 ax25_type_trans(struct sk_buff *skb, struct net_device *dev)
  225. {
  226. skb->dev = dev;
  227. skb_reset_mac_header(skb);
  228. skb->pkt_type = PACKET_HOST;
  229. return htons(ETH_P_AX25);
  230. }
  231. /* af_ax25.c */
  232. extern struct hlist_head ax25_list;
  233. extern spinlock_t ax25_list_lock;
  234. extern void ax25_cb_add(ax25_cb *);
  235. struct sock *ax25_find_listener(ax25_address *, int, struct net_device *, int);
  236. struct sock *ax25_get_socket(ax25_address *, ax25_address *, int);
  237. extern ax25_cb *ax25_find_cb(ax25_address *, ax25_address *, ax25_digi *, struct net_device *);
  238. extern void ax25_send_to_raw(ax25_address *, struct sk_buff *, int);
  239. extern void ax25_destroy_socket(ax25_cb *);
  240. extern ax25_cb * __must_check ax25_create_cb(void);
  241. extern void ax25_fillin_cb(ax25_cb *, ax25_dev *);
  242. extern struct sock *ax25_make_new(struct sock *, struct ax25_dev *);
  243. /* ax25_addr.c */
  244. extern const ax25_address ax25_bcast;
  245. extern const ax25_address ax25_defaddr;
  246. extern const ax25_address null_ax25_address;
  247. extern char *ax2asc(char *buf, const ax25_address *);
  248. extern void asc2ax(ax25_address *addr, const char *callsign);
  249. extern int ax25cmp(const ax25_address *, const ax25_address *);
  250. extern int ax25digicmp(const ax25_digi *, const ax25_digi *);
  251. extern const unsigned char *ax25_addr_parse(const unsigned char *, int,
  252. ax25_address *, ax25_address *, ax25_digi *, int *, int *);
  253. extern int ax25_addr_build(unsigned char *, const ax25_address *,
  254. const ax25_address *, const ax25_digi *, int, int);
  255. extern int ax25_addr_size(const ax25_digi *);
  256. extern void ax25_digi_invert(const ax25_digi *, ax25_digi *);
  257. /* ax25_dev.c */
  258. extern ax25_dev *ax25_dev_list;
  259. extern spinlock_t ax25_dev_lock;
  260. static inline ax25_dev *ax25_dev_ax25dev(struct net_device *dev)
  261. {
  262. return dev->ax25_ptr;
  263. }
  264. extern ax25_dev *ax25_addr_ax25dev(ax25_address *);
  265. extern void ax25_dev_device_up(struct net_device *);
  266. extern void ax25_dev_device_down(struct net_device *);
  267. extern int ax25_fwd_ioctl(unsigned int, struct ax25_fwd_struct *);
  268. extern struct net_device *ax25_fwd_dev(struct net_device *);
  269. extern void ax25_dev_free(void);
  270. /* ax25_ds_in.c */
  271. extern int ax25_ds_frame_in(ax25_cb *, struct sk_buff *, int);
  272. /* ax25_ds_subr.c */
  273. extern void ax25_ds_nr_error_recovery(ax25_cb *);
  274. extern void ax25_ds_enquiry_response(ax25_cb *);
  275. extern void ax25_ds_establish_data_link(ax25_cb *);
  276. extern void ax25_dev_dama_off(ax25_dev *);
  277. extern void ax25_dama_on(ax25_cb *);
  278. extern void ax25_dama_off(ax25_cb *);
  279. /* ax25_ds_timer.c */
  280. extern void ax25_ds_setup_timer(ax25_dev *);
  281. extern void ax25_ds_set_timer(ax25_dev *);
  282. extern void ax25_ds_del_timer(ax25_dev *);
  283. extern void ax25_ds_timer(ax25_cb *);
  284. extern void ax25_ds_t1_timeout(ax25_cb *);
  285. extern void ax25_ds_heartbeat_expiry(ax25_cb *);
  286. extern void ax25_ds_t3timer_expiry(ax25_cb *);
  287. extern void ax25_ds_idletimer_expiry(ax25_cb *);
  288. /* ax25_iface.c */
  289. struct ax25_protocol {
  290. struct ax25_protocol *next;
  291. unsigned int pid;
  292. int (*func)(struct sk_buff *, ax25_cb *);
  293. };
  294. extern void ax25_register_pid(struct ax25_protocol *ap);
  295. extern void ax25_protocol_release(unsigned int);
  296. struct ax25_linkfail {
  297. struct hlist_node lf_node;
  298. void (*func)(ax25_cb *, int);
  299. };
  300. extern void ax25_linkfail_register(struct ax25_linkfail *lf);
  301. extern void ax25_linkfail_release(struct ax25_linkfail *lf);
  302. extern int __must_check ax25_listen_register(ax25_address *,
  303. struct net_device *);
  304. extern void ax25_listen_release(ax25_address *, struct net_device *);
  305. extern int (*ax25_protocol_function(unsigned int))(struct sk_buff *, ax25_cb *);
  306. extern int ax25_listen_mine(ax25_address *, struct net_device *);
  307. extern void ax25_link_failed(ax25_cb *, int);
  308. extern int ax25_protocol_is_registered(unsigned int);
  309. /* ax25_in.c */
  310. extern int ax25_rx_iframe(ax25_cb *, struct sk_buff *);
  311. extern int ax25_kiss_rcv(struct sk_buff *, struct net_device *, struct packet_type *, struct net_device *);
  312. /* ax25_ip.c */
  313. extern int ax25_hard_header(struct sk_buff *, struct net_device *,
  314. unsigned short, const void *,
  315. const void *, unsigned int);
  316. extern int ax25_rebuild_header(struct sk_buff *);
  317. extern const struct header_ops ax25_header_ops;
  318. /* ax25_out.c */
  319. extern ax25_cb *ax25_send_frame(struct sk_buff *, int, ax25_address *, ax25_address *, ax25_digi *, struct net_device *);
  320. extern void ax25_output(ax25_cb *, int, struct sk_buff *);
  321. extern void ax25_kick(ax25_cb *);
  322. extern void ax25_transmit_buffer(ax25_cb *, struct sk_buff *, int);
  323. extern void ax25_queue_xmit(struct sk_buff *skb, struct net_device *dev);
  324. extern int ax25_check_iframes_acked(ax25_cb *, unsigned short);
  325. /* ax25_route.c */
  326. extern void ax25_rt_device_down(struct net_device *);
  327. extern int ax25_rt_ioctl(unsigned int, void __user *);
  328. extern const struct file_operations ax25_route_fops;
  329. extern ax25_route *ax25_get_route(ax25_address *addr, struct net_device *dev);
  330. extern int ax25_rt_autobind(ax25_cb *, ax25_address *);
  331. extern struct sk_buff *ax25_rt_build_path(struct sk_buff *, ax25_address *, ax25_address *, ax25_digi *);
  332. extern void ax25_rt_free(void);
  333. /* ax25_std_in.c */
  334. extern int ax25_std_frame_in(ax25_cb *, struct sk_buff *, int);
  335. /* ax25_std_subr.c */
  336. extern void ax25_std_nr_error_recovery(ax25_cb *);
  337. extern void ax25_std_establish_data_link(ax25_cb *);
  338. extern void ax25_std_transmit_enquiry(ax25_cb *);
  339. extern void ax25_std_enquiry_response(ax25_cb *);
  340. extern void ax25_std_timeout_response(ax25_cb *);
  341. /* ax25_std_timer.c */
  342. extern void ax25_std_heartbeat_expiry(ax25_cb *);
  343. extern void ax25_std_t1timer_expiry(ax25_cb *);
  344. extern void ax25_std_t2timer_expiry(ax25_cb *);
  345. extern void ax25_std_t3timer_expiry(ax25_cb *);
  346. extern void ax25_std_idletimer_expiry(ax25_cb *);
  347. /* ax25_subr.c */
  348. extern void ax25_clear_queues(ax25_cb *);
  349. extern void ax25_frames_acked(ax25_cb *, unsigned short);
  350. extern void ax25_requeue_frames(ax25_cb *);
  351. extern int ax25_validate_nr(ax25_cb *, unsigned short);
  352. extern int ax25_decode(ax25_cb *, struct sk_buff *, int *, int *, int *);
  353. extern void ax25_send_control(ax25_cb *, int, int, int);
  354. extern void ax25_return_dm(struct net_device *, ax25_address *, ax25_address *, ax25_digi *);
  355. extern void ax25_calculate_t1(ax25_cb *);
  356. extern void ax25_calculate_rtt(ax25_cb *);
  357. extern void ax25_disconnect(ax25_cb *, int);
  358. /* ax25_timer.c */
  359. extern void ax25_setup_timers(ax25_cb *);
  360. extern void ax25_start_heartbeat(ax25_cb *);
  361. extern void ax25_start_t1timer(ax25_cb *);
  362. extern void ax25_start_t2timer(ax25_cb *);
  363. extern void ax25_start_t3timer(ax25_cb *);
  364. extern void ax25_start_idletimer(ax25_cb *);
  365. extern void ax25_stop_heartbeat(ax25_cb *);
  366. extern void ax25_stop_t1timer(ax25_cb *);
  367. extern void ax25_stop_t2timer(ax25_cb *);
  368. extern void ax25_stop_t3timer(ax25_cb *);
  369. extern void ax25_stop_idletimer(ax25_cb *);
  370. extern int ax25_t1timer_running(ax25_cb *);
  371. extern unsigned long ax25_display_timer(struct timer_list *);
  372. /* ax25_uid.c */
  373. extern int ax25_uid_policy;
  374. extern ax25_uid_assoc *ax25_findbyuid(uid_t);
  375. extern int __must_check ax25_uid_ioctl(int, struct sockaddr_ax25 *);
  376. extern const struct file_operations ax25_uid_fops;
  377. extern void ax25_uid_free(void);
  378. /* sysctl_net_ax25.c */
  379. #ifdef CONFIG_SYSCTL
  380. extern void ax25_register_sysctl(void);
  381. extern void ax25_unregister_sysctl(void);
  382. #else
  383. static inline void ax25_register_sysctl(void) {};
  384. static inline void ax25_unregister_sysctl(void) {};
  385. #endif /* CONFIG_SYSCTL */
  386. #endif