netrom.h 7.6 KB

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