netrom.h 7.7 KB

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