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