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