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