netrom.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Declarations of NET/ROM type objects.
  4. *
  5. * Jonathan Naylor G4KLX 9/4/95
  6. */
  7. #ifndef _NETROM_H
  8. #define _NETROM_H
  9. #include <linux/netrom.h>
  10. #include <linux/list.h>
  11. #include <linux/slab.h>
  12. #include <net/sock.h>
  13. #include <linux/refcount.h>
  14. #include <linux/seq_file.h>
  15. #include <net/ax25.h>
  16. #define NR_NETWORK_LEN 15
  17. #define NR_TRANSPORT_LEN 5
  18. #define NR_PROTO_IP 0x0C
  19. #define NR_PROTOEXT 0x00
  20. #define NR_CONNREQ 0x01
  21. #define NR_CONNACK 0x02
  22. #define NR_DISCREQ 0x03
  23. #define NR_DISCACK 0x04
  24. #define NR_INFO 0x05
  25. #define NR_INFOACK 0x06
  26. #define NR_RESET 0x07
  27. #define NR_CHOKE_FLAG 0x80
  28. #define NR_NAK_FLAG 0x40
  29. #define NR_MORE_FLAG 0x20
  30. /* Define Link State constants. */
  31. enum {
  32. NR_STATE_0,
  33. NR_STATE_1,
  34. NR_STATE_2,
  35. NR_STATE_3
  36. };
  37. #define NR_COND_ACK_PENDING 0x01
  38. #define NR_COND_REJECT 0x02
  39. #define NR_COND_PEER_RX_BUSY 0x04
  40. #define NR_COND_OWN_RX_BUSY 0x08
  41. #define NR_DEFAULT_T1 120000 /* Outstanding frames - 120 seconds */
  42. #define NR_DEFAULT_T2 5000 /* Response delay - 5 seconds */
  43. #define NR_DEFAULT_N2 3 /* Number of Retries - 3 */
  44. #define NR_DEFAULT_T4 180000 /* Busy Delay - 180 seconds */
  45. #define NR_DEFAULT_IDLE 0 /* No Activity Timeout - none */
  46. #define NR_DEFAULT_WINDOW 4 /* Default Window Size - 4 */
  47. #define NR_DEFAULT_OBS 6 /* Default Obsolescence Count - 6 */
  48. #define NR_DEFAULT_QUAL 10 /* Default Neighbour Quality - 10 */
  49. #define NR_DEFAULT_TTL 16 /* Default Time To Live - 16 */
  50. #define NR_DEFAULT_ROUTING 1 /* Is routing enabled ? */
  51. #define NR_DEFAULT_FAILS 2 /* Link fails until route fails */
  52. #define NR_DEFAULT_RESET 0 /* Sent / accept reset cmds? */
  53. #define NR_MODULUS 256
  54. #define NR_MAX_WINDOW_SIZE 127 /* Maximum Window Allowable - 127 */
  55. #define NR_MAX_PACKET_SIZE 236 /* Maximum Packet Length - 236 */
  56. struct nr_sock {
  57. struct sock sock;
  58. ax25_address user_addr, source_addr, dest_addr;
  59. struct net_device *device;
  60. unsigned char my_index, my_id;
  61. unsigned char your_index, your_id;
  62. unsigned char state, condition, bpqext, window;
  63. unsigned short vs, vr, va, vl;
  64. unsigned char n2, n2count;
  65. unsigned long t1, t2, t4, idle;
  66. unsigned short fraglen;
  67. struct timer_list t1timer;
  68. struct timer_list t2timer;
  69. struct timer_list t4timer;
  70. struct timer_list idletimer;
  71. struct sk_buff_head ack_queue;
  72. struct sk_buff_head reseq_queue;
  73. struct sk_buff_head frag_queue;
  74. };
  75. #define nr_sk(sk) ((struct nr_sock *)(sk))
  76. struct nr_neigh {
  77. struct hlist_node neigh_node;
  78. ax25_address callsign;
  79. ax25_digi *digipeat;
  80. ax25_cb *ax25;
  81. struct net_device *dev;
  82. unsigned char quality;
  83. unsigned char locked;
  84. unsigned short count;
  85. unsigned int number;
  86. unsigned char failed;
  87. refcount_t refcount;
  88. };
  89. struct nr_route {
  90. unsigned char quality;
  91. unsigned char obs_count;
  92. struct nr_neigh *neighbour;
  93. };
  94. struct nr_node {
  95. struct hlist_node node_node;
  96. ax25_address callsign;
  97. char mnemonic[7];
  98. unsigned char which;
  99. unsigned char count;
  100. struct nr_route routes[3];
  101. refcount_t refcount;
  102. spinlock_t node_lock;
  103. };
  104. /*********************************************************************
  105. * nr_node & nr_neigh lists, refcounting and locking
  106. *********************************************************************/
  107. #define nr_node_hold(__nr_node) \
  108. refcount_inc(&((__nr_node)->refcount))
  109. static __inline__ void nr_node_put(struct nr_node *nr_node)
  110. {
  111. if (refcount_dec_and_test(&nr_node->refcount)) {
  112. kfree(nr_node);
  113. }
  114. }
  115. #define nr_neigh_hold(__nr_neigh) \
  116. refcount_inc(&((__nr_neigh)->refcount))
  117. static __inline__ void nr_neigh_put(struct nr_neigh *nr_neigh)
  118. {
  119. if (refcount_dec_and_test(&nr_neigh->refcount)) {
  120. if (nr_neigh->ax25)
  121. ax25_cb_put(nr_neigh->ax25);
  122. kfree(nr_neigh->digipeat);
  123. kfree(nr_neigh);
  124. }
  125. }
  126. /* nr_node_lock and nr_node_unlock also hold/put the node's refcounter.
  127. */
  128. static __inline__ void nr_node_lock(struct nr_node *nr_node)
  129. {
  130. nr_node_hold(nr_node);
  131. spin_lock_bh(&nr_node->node_lock);
  132. }
  133. static __inline__ void nr_node_unlock(struct nr_node *nr_node)
  134. {
  135. spin_unlock_bh(&nr_node->node_lock);
  136. nr_node_put(nr_node);
  137. }
  138. #define nr_neigh_for_each(__nr_neigh, list) \
  139. hlist_for_each_entry(__nr_neigh, list, neigh_node)
  140. #define nr_neigh_for_each_safe(__nr_neigh, node2, list) \
  141. hlist_for_each_entry_safe(__nr_neigh, node2, list, neigh_node)
  142. #define nr_node_for_each(__nr_node, list) \
  143. hlist_for_each_entry(__nr_node, list, node_node)
  144. #define nr_node_for_each_safe(__nr_node, node2, list) \
  145. hlist_for_each_entry_safe(__nr_node, node2, list, node_node)
  146. /*********************************************************************/
  147. /* af_netrom.c */
  148. extern int sysctl_netrom_default_path_quality;
  149. extern int sysctl_netrom_obsolescence_count_initialiser;
  150. extern int sysctl_netrom_network_ttl_initialiser;
  151. extern int sysctl_netrom_transport_timeout;
  152. extern int sysctl_netrom_transport_maximum_tries;
  153. extern int sysctl_netrom_transport_acknowledge_delay;
  154. extern int sysctl_netrom_transport_busy_delay;
  155. extern int sysctl_netrom_transport_requested_window_size;
  156. extern int sysctl_netrom_transport_no_activity_timeout;
  157. extern int sysctl_netrom_routing_control;
  158. extern int sysctl_netrom_link_fails_count;
  159. extern int sysctl_netrom_reset_circuit;
  160. int nr_rx_frame(struct sk_buff *, struct net_device *);
  161. void nr_destroy_socket(struct sock *);
  162. /* nr_dev.c */
  163. int nr_rx_ip(struct sk_buff *, struct net_device *);
  164. void nr_setup(struct net_device *);
  165. /* nr_in.c */
  166. int nr_process_rx_frame(struct sock *, struct sk_buff *);
  167. /* nr_loopback.c */
  168. void nr_loopback_init(void);
  169. void nr_loopback_clear(void);
  170. int nr_loopback_queue(struct sk_buff *);
  171. /* nr_out.c */
  172. void nr_output(struct sock *, struct sk_buff *);
  173. void nr_send_nak_frame(struct sock *);
  174. void nr_kick(struct sock *);
  175. void nr_transmit_buffer(struct sock *, struct sk_buff *);
  176. void nr_establish_data_link(struct sock *);
  177. void nr_enquiry_response(struct sock *);
  178. void nr_check_iframes_acked(struct sock *, unsigned short);
  179. /* nr_route.c */
  180. void nr_rt_device_down(struct net_device *);
  181. struct net_device *nr_dev_first(void);
  182. struct net_device *nr_dev_get(ax25_address *);
  183. int nr_rt_ioctl(unsigned int, void __user *);
  184. void nr_link_failed(ax25_cb *, int);
  185. int nr_route_frame(struct sk_buff *, ax25_cb *);
  186. extern const struct seq_operations nr_node_seqops;
  187. extern const struct seq_operations nr_neigh_seqops;
  188. void nr_rt_free(void);
  189. /* nr_subr.c */
  190. void nr_clear_queues(struct sock *);
  191. void nr_frames_acked(struct sock *, unsigned short);
  192. void nr_requeue_frames(struct sock *);
  193. int nr_validate_nr(struct sock *, unsigned short);
  194. int nr_in_rx_window(struct sock *, unsigned short);
  195. void nr_write_internal(struct sock *, int);
  196. void __nr_transmit_reply(struct sk_buff *skb, int mine, unsigned char cmdflags);
  197. /*
  198. * This routine is called when a Connect Acknowledge with the Choke Flag
  199. * set is needed to refuse a connection.
  200. */
  201. #define nr_transmit_refusal(skb, mine) \
  202. do { \
  203. __nr_transmit_reply((skb), (mine), NR_CONNACK | NR_CHOKE_FLAG); \
  204. } while (0)
  205. /*
  206. * This routine is called when we don't have a circuit matching an incoming
  207. * NET/ROM packet. This is an G8PZT Xrouter extension.
  208. */
  209. #define nr_transmit_reset(skb, mine) \
  210. do { \
  211. __nr_transmit_reply((skb), (mine), NR_RESET); \
  212. } while (0)
  213. void nr_disconnect(struct sock *, int);
  214. /* nr_timer.c */
  215. void nr_init_timers(struct sock *sk);
  216. void nr_start_heartbeat(struct sock *);
  217. void nr_start_t1timer(struct sock *);
  218. void nr_start_t2timer(struct sock *);
  219. void nr_start_t4timer(struct sock *);
  220. void nr_start_idletimer(struct sock *);
  221. void nr_stop_heartbeat(struct sock *);
  222. void nr_stop_t1timer(struct sock *);
  223. void nr_stop_t2timer(struct sock *);
  224. void nr_stop_t4timer(struct sock *);
  225. void nr_stop_idletimer(struct sock *);
  226. int nr_t1timer_running(struct sock *);
  227. /* sysctl_net_netrom.c */
  228. int nr_register_sysctl(void);
  229. void nr_unregister_sysctl(void);
  230. #endif