1
2
3
4
5
6
7
8#ifndef _NETROM_H
9#define _NETROM_H
10
11#include <linux/netrom.h>
12#include <linux/list.h>
13#include <linux/slab.h>
14#include <net/sock.h>
15#include <linux/refcount.h>
16#include <linux/seq_file.h>
17
18#define NR_NETWORK_LEN 15
19#define NR_TRANSPORT_LEN 5
20
21#define NR_PROTO_IP 0x0C
22
23#define NR_PROTOEXT 0x00
24#define NR_CONNREQ 0x01
25#define NR_CONNACK 0x02
26#define NR_DISCREQ 0x03
27#define NR_DISCACK 0x04
28#define NR_INFO 0x05
29#define NR_INFOACK 0x06
30#define NR_RESET 0x07
31
32#define NR_CHOKE_FLAG 0x80
33#define NR_NAK_FLAG 0x40
34#define NR_MORE_FLAG 0x20
35
36
37enum {
38 NR_STATE_0,
39 NR_STATE_1,
40 NR_STATE_2,
41 NR_STATE_3
42};
43
44#define NR_COND_ACK_PENDING 0x01
45#define NR_COND_REJECT 0x02
46#define NR_COND_PEER_RX_BUSY 0x04
47#define NR_COND_OWN_RX_BUSY 0x08
48
49#define NR_DEFAULT_T1 120000
50#define NR_DEFAULT_T2 5000
51#define NR_DEFAULT_N2 3
52#define NR_DEFAULT_T4 180000
53#define NR_DEFAULT_IDLE 0
54#define NR_DEFAULT_WINDOW 4
55#define NR_DEFAULT_OBS 6
56#define NR_DEFAULT_QUAL 10
57#define NR_DEFAULT_TTL 16
58#define NR_DEFAULT_ROUTING 1
59#define NR_DEFAULT_FAILS 2
60#define NR_DEFAULT_RESET 0
61
62#define NR_MODULUS 256
63#define NR_MAX_WINDOW_SIZE 127
64#define NR_MAX_PACKET_SIZE 236
65
66struct 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 refcount_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 refcount_t refcount;
116 spinlock_t node_lock;
117};
118
119
120
121
122
123#define nr_node_hold(__nr_node) \
124 refcount_inc(&((__nr_node)->refcount))
125
126static __inline__ void nr_node_put(struct nr_node *nr_node)
127{
128 if (refcount_dec_and_test(&nr_node->refcount)) {
129 kfree(nr_node);
130 }
131}
132
133#define nr_neigh_hold(__nr_neigh) \
134 refcount_inc(&((__nr_neigh)->refcount))
135
136static __inline__ void nr_neigh_put(struct nr_neigh *nr_neigh)
137{
138 if (refcount_dec_and_test(&nr_neigh->refcount)) {
139 if (nr_neigh->ax25)
140 ax25_cb_put(nr_neigh->ax25);
141 kfree(nr_neigh->digipeat);
142 kfree(nr_neigh);
143 }
144}
145
146
147
148static __inline__ void nr_node_lock(struct nr_node *nr_node)
149{
150 nr_node_hold(nr_node);
151 spin_lock_bh(&nr_node->node_lock);
152}
153
154static __inline__ void nr_node_unlock(struct nr_node *nr_node)
155{
156 spin_unlock_bh(&nr_node->node_lock);
157 nr_node_put(nr_node);
158}
159
160#define nr_neigh_for_each(__nr_neigh, list) \
161 hlist_for_each_entry(__nr_neigh, list, neigh_node)
162
163#define nr_neigh_for_each_safe(__nr_neigh, node2, list) \
164 hlist_for_each_entry_safe(__nr_neigh, node2, list, neigh_node)
165
166#define nr_node_for_each(__nr_node, list) \
167 hlist_for_each_entry(__nr_node, list, node_node)
168
169#define nr_node_for_each_safe(__nr_node, node2, list) \
170 hlist_for_each_entry_safe(__nr_node, node2, list, node_node)
171
172
173
174
175
176extern int sysctl_netrom_default_path_quality;
177extern int sysctl_netrom_obsolescence_count_initialiser;
178extern int sysctl_netrom_network_ttl_initialiser;
179extern int sysctl_netrom_transport_timeout;
180extern int sysctl_netrom_transport_maximum_tries;
181extern int sysctl_netrom_transport_acknowledge_delay;
182extern int sysctl_netrom_transport_busy_delay;
183extern int sysctl_netrom_transport_requested_window_size;
184extern int sysctl_netrom_transport_no_activity_timeout;
185extern int sysctl_netrom_routing_control;
186extern int sysctl_netrom_link_fails_count;
187extern int sysctl_netrom_reset_circuit;
188
189int nr_rx_frame(struct sk_buff *, struct net_device *);
190void nr_destroy_socket(struct sock *);
191
192
193int nr_rx_ip(struct sk_buff *, struct net_device *);
194void nr_setup(struct net_device *);
195
196
197int nr_process_rx_frame(struct sock *, struct sk_buff *);
198
199
200void nr_loopback_init(void);
201void nr_loopback_clear(void);
202int nr_loopback_queue(struct sk_buff *);
203
204
205void nr_output(struct sock *, struct sk_buff *);
206void nr_send_nak_frame(struct sock *);
207void nr_kick(struct sock *);
208void nr_transmit_buffer(struct sock *, struct sk_buff *);
209void nr_establish_data_link(struct sock *);
210void nr_enquiry_response(struct sock *);
211void nr_check_iframes_acked(struct sock *, unsigned short);
212
213
214void nr_rt_device_down(struct net_device *);
215struct net_device *nr_dev_first(void);
216struct net_device *nr_dev_get(ax25_address *);
217int nr_rt_ioctl(unsigned int, void __user *);
218void nr_link_failed(ax25_cb *, int);
219int nr_route_frame(struct sk_buff *, ax25_cb *);
220extern const struct seq_operations nr_node_seqops;
221extern const struct seq_operations nr_neigh_seqops;
222void nr_rt_free(void);
223
224
225void nr_clear_queues(struct sock *);
226void nr_frames_acked(struct sock *, unsigned short);
227void nr_requeue_frames(struct sock *);
228int nr_validate_nr(struct sock *, unsigned short);
229int nr_in_rx_window(struct sock *, unsigned short);
230void nr_write_internal(struct sock *, int);
231
232void __nr_transmit_reply(struct sk_buff *skb, int mine, unsigned char cmdflags);
233
234
235
236
237
238#define nr_transmit_refusal(skb, mine) \
239do { \
240 __nr_transmit_reply((skb), (mine), NR_CONNACK | NR_CHOKE_FLAG); \
241} while (0)
242
243
244
245
246
247#define nr_transmit_reset(skb, mine) \
248do { \
249 __nr_transmit_reply((skb), (mine), NR_RESET); \
250} while (0)
251
252void nr_disconnect(struct sock *, int);
253
254
255void nr_init_timers(struct sock *sk);
256void nr_start_heartbeat(struct sock *);
257void nr_start_t1timer(struct sock *);
258void nr_start_t2timer(struct sock *);
259void nr_start_t4timer(struct sock *);
260void nr_start_idletimer(struct sock *);
261void nr_stop_heartbeat(struct sock *);
262void nr_stop_t1timer(struct sock *);
263void nr_stop_t2timer(struct sock *);
264void nr_stop_t4timer(struct sock *);
265void nr_stop_idletimer(struct sock *);
266int nr_t1timer_running(struct sock *);
267
268
269void nr_register_sysctl(void);
270void nr_unregister_sysctl(void);
271
272#endif
273