blob: 443a4ffca7aafd9818c056bbd9aee261bd504a6f [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <net/sock.h>
Reshetova, Elenaaf420742017-07-04 15:53:11 +030014#include <linux/refcount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#define NR_NETWORK_LEN 15
17#define NR_TRANSPORT_LEN 5
18
19#define NR_PROTO_IP 0x0C
20
21#define NR_PROTOEXT 0x00
22#define NR_CONNREQ 0x01
23#define NR_CONNACK 0x02
24#define NR_DISCREQ 0x03
25#define NR_DISCACK 0x04
26#define NR_INFO 0x05
27#define NR_INFOACK 0x06
Ralf Baechlee21ce8c2005-09-12 14:27:37 -070028#define NR_RESET 0x07
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#define NR_CHOKE_FLAG 0x80
31#define NR_NAK_FLAG 0x40
32#define NR_MORE_FLAG 0x20
33
34/* Define Link State constants. */
35enum {
36 NR_STATE_0,
37 NR_STATE_1,
38 NR_STATE_2,
39 NR_STATE_3
40};
41
42#define NR_COND_ACK_PENDING 0x01
43#define NR_COND_REJECT 0x02
44#define NR_COND_PEER_RX_BUSY 0x04
45#define NR_COND_OWN_RX_BUSY 0x08
46
Ralf Baechle4d8937d2006-05-03 23:27:47 -070047#define NR_DEFAULT_T1 120000 /* Outstanding frames - 120 seconds */
48#define NR_DEFAULT_T2 5000 /* Response delay - 5 seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define NR_DEFAULT_N2 3 /* Number of Retries - 3 */
Ralf Baechle4d8937d2006-05-03 23:27:47 -070050#define NR_DEFAULT_T4 180000 /* Busy Delay - 180 seconds */
51#define NR_DEFAULT_IDLE 0 /* No Activity Timeout - none */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define NR_DEFAULT_WINDOW 4 /* Default Window Size - 4 */
53#define NR_DEFAULT_OBS 6 /* Default Obsolescence Count - 6 */
54#define NR_DEFAULT_QUAL 10 /* Default Neighbour Quality - 10 */
55#define NR_DEFAULT_TTL 16 /* Default Time To Live - 16 */
56#define NR_DEFAULT_ROUTING 1 /* Is routing enabled ? */
57#define NR_DEFAULT_FAILS 2 /* Link fails until route fails */
Ralf Baechlee21ce8c2005-09-12 14:27:37 -070058#define NR_DEFAULT_RESET 0 /* Sent / accept reset cmds? */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NR_MODULUS 256
61#define NR_MAX_WINDOW_SIZE 127 /* Maximum Window Allowable - 127 */
62#define NR_MAX_PACKET_SIZE 236 /* Maximum Packet Length - 236 */
63
64struct nr_sock {
65 struct sock sock;
66 ax25_address user_addr, source_addr, dest_addr;
67 struct net_device *device;
68 unsigned char my_index, my_id;
69 unsigned char your_index, your_id;
70 unsigned char state, condition, bpqext, window;
71 unsigned short vs, vr, va, vl;
72 unsigned char n2, n2count;
73 unsigned long t1, t2, t4, idle;
74 unsigned short fraglen;
75 struct timer_list t1timer;
76 struct timer_list t2timer;
77 struct timer_list t4timer;
78 struct timer_list idletimer;
79 struct sk_buff_head ack_queue;
80 struct sk_buff_head reseq_queue;
81 struct sk_buff_head frag_queue;
82};
83
84#define nr_sk(sk) ((struct nr_sock *)(sk))
85
86struct nr_neigh {
87 struct hlist_node neigh_node;
88 ax25_address callsign;
89 ax25_digi *digipeat;
90 ax25_cb *ax25;
91 struct net_device *dev;
92 unsigned char quality;
93 unsigned char locked;
94 unsigned short count;
95 unsigned int number;
96 unsigned char failed;
Reshetova, Elenaaf420742017-07-04 15:53:11 +030097 refcount_t refcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
100struct nr_route {
101 unsigned char quality;
102 unsigned char obs_count;
103 struct nr_neigh *neighbour;
104};
105
106struct nr_node {
107 struct hlist_node node_node;
108 ax25_address callsign;
109 char mnemonic[7];
110 unsigned char which;
111 unsigned char count;
112 struct nr_route routes[3];
Reshetova, Elena156be7e2017-07-04 15:53:12 +0300113 refcount_t refcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 spinlock_t node_lock;
115};
116
117/*********************************************************************
118 * nr_node & nr_neigh lists, refcounting and locking
119 *********************************************************************/
120
121#define nr_node_hold(__nr_node) \
Reshetova, Elena156be7e2017-07-04 15:53:12 +0300122 refcount_inc(&((__nr_node)->refcount))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124static __inline__ void nr_node_put(struct nr_node *nr_node)
125{
Reshetova, Elena156be7e2017-07-04 15:53:12 +0300126 if (refcount_dec_and_test(&nr_node->refcount)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 kfree(nr_node);
128 }
129}
130
131#define nr_neigh_hold(__nr_neigh) \
Reshetova, Elenaaf420742017-07-04 15:53:11 +0300132 refcount_inc(&((__nr_neigh)->refcount))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134static __inline__ void nr_neigh_put(struct nr_neigh *nr_neigh)
135{
Reshetova, Elenaaf420742017-07-04 15:53:11 +0300136 if (refcount_dec_and_test(&nr_neigh->refcount)) {
Jarek Poplawskid00c3622010-01-16 01:04:04 -0800137 if (nr_neigh->ax25)
138 ax25_cb_put(nr_neigh->ax25);
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
Sasha Levinb67bfe02013-02-27 17:06:00 -0800158#define nr_neigh_for_each(__nr_neigh, list) \
159 hlist_for_each_entry(__nr_neigh, list, neigh_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Sasha Levinb67bfe02013-02-27 17:06:00 -0800161#define nr_neigh_for_each_safe(__nr_neigh, node2, list) \
162 hlist_for_each_entry_safe(__nr_neigh, node2, list, neigh_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Sasha Levinb67bfe02013-02-27 17:06:00 -0800164#define nr_node_for_each(__nr_node, list) \
165 hlist_for_each_entry(__nr_node, list, node_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Sasha Levinb67bfe02013-02-27 17:06:00 -0800167#define nr_node_for_each_safe(__nr_node, node2, list) \
168 hlist_for_each_entry_safe(__nr_node, node2, list, node_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
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
Joe Perches96496122013-09-21 10:22:51 -0700187int nr_rx_frame(struct sk_buff *, struct net_device *);
188void nr_destroy_socket(struct sock *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190/* nr_dev.c */
Joe Perches96496122013-09-21 10:22:51 -0700191int nr_rx_ip(struct sk_buff *, struct net_device *);
192void nr_setup(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194/* nr_in.c */
Joe Perches96496122013-09-21 10:22:51 -0700195int nr_process_rx_frame(struct sock *, struct sk_buff *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197/* nr_loopback.c */
Joe Perches96496122013-09-21 10:22:51 -0700198void nr_loopback_init(void);
199void nr_loopback_clear(void);
200int nr_loopback_queue(struct sk_buff *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202/* nr_out.c */
Joe Perches96496122013-09-21 10:22:51 -0700203void nr_output(struct sock *, struct sk_buff *);
204void nr_send_nak_frame(struct sock *);
205void nr_kick(struct sock *);
206void nr_transmit_buffer(struct sock *, struct sk_buff *);
207void nr_establish_data_link(struct sock *);
208void nr_enquiry_response(struct sock *);
209void nr_check_iframes_acked(struct sock *, unsigned short);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211/* nr_route.c */
Joe Perches96496122013-09-21 10:22:51 -0700212void nr_rt_device_down(struct net_device *);
213struct net_device *nr_dev_first(void);
214struct net_device *nr_dev_get(ax25_address *);
215int nr_rt_ioctl(unsigned int, void __user *);
216void nr_link_failed(ax25_cb *, int);
217int nr_route_frame(struct sk_buff *, ax25_cb *);
Arjan van de Ven54047322007-02-12 00:55:28 -0800218extern const struct file_operations nr_nodes_fops;
219extern const struct file_operations nr_neigh_fops;
Joe Perches96496122013-09-21 10:22:51 -0700220void nr_rt_free(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222/* nr_subr.c */
Joe Perches96496122013-09-21 10:22:51 -0700223void nr_clear_queues(struct sock *);
224void nr_frames_acked(struct sock *, unsigned short);
225void nr_requeue_frames(struct sock *);
226int nr_validate_nr(struct sock *, unsigned short);
227int nr_in_rx_window(struct sock *, unsigned short);
228void nr_write_internal(struct sock *, int);
Ralf Baechlee21ce8c2005-09-12 14:27:37 -0700229
Joe Perches96496122013-09-21 10:22:51 -0700230void __nr_transmit_reply(struct sk_buff *skb, int mine, unsigned char cmdflags);
Ralf Baechlee21ce8c2005-09-12 14:27:37 -0700231
232/*
233 * This routine is called when a Connect Acknowledge with the Choke Flag
234 * set is needed to refuse a connection.
235 */
236#define nr_transmit_refusal(skb, mine) \
237do { \
238 __nr_transmit_reply((skb), (mine), NR_CONNACK | NR_CHOKE_FLAG); \
239} while (0)
240
241/*
242 * This routine is called when we don't have a circuit matching an incoming
243 * NET/ROM packet. This is an G8PZT Xrouter extension.
244 */
245#define nr_transmit_reset(skb, mine) \
246do { \
247 __nr_transmit_reply((skb), (mine), NR_RESET); \
248} while (0)
249
Joe Perches96496122013-09-21 10:22:51 -0700250void nr_disconnect(struct sock *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252/* nr_timer.c */
Joe Perches96496122013-09-21 10:22:51 -0700253void nr_init_timers(struct sock *sk);
254void nr_start_heartbeat(struct sock *);
255void nr_start_t1timer(struct sock *);
256void nr_start_t2timer(struct sock *);
257void nr_start_t4timer(struct sock *);
258void nr_start_idletimer(struct sock *);
259void nr_stop_heartbeat(struct sock *);
260void nr_stop_t1timer(struct sock *);
261void nr_stop_t2timer(struct sock *);
262void nr_stop_t4timer(struct sock *);
263void nr_stop_idletimer(struct sock *);
264int nr_t1timer_running(struct sock *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266/* sysctl_net_netrom.c */
Joe Perches96496122013-09-21 10:22:51 -0700267void nr_register_sysctl(void);
268void nr_unregister_sysctl(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270#endif