xref: /openbmc/linux/include/net/netrom.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  *	Declarations of NET/ROM type objects.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *	Jonathan Naylor G4KLX	9/4/95
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #ifndef _NETROM_H
91da177e4SLinus Torvalds #define _NETROM_H
10b88a762bSRalf Baechle 
111da177e4SLinus Torvalds #include <linux/netrom.h>
121da177e4SLinus Torvalds #include <linux/list.h>
135a0e3ad6STejun Heo #include <linux/slab.h>
141da177e4SLinus Torvalds #include <net/sock.h>
15af420749SReshetova, Elena #include <linux/refcount.h>
16fddda2b7SChristoph Hellwig #include <linux/seq_file.h>
17*949d6b40SJakub Kicinski #include <net/ax25.h>
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #define	NR_NETWORK_LEN			15
201da177e4SLinus Torvalds #define	NR_TRANSPORT_LEN		5
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #define	NR_PROTO_IP			0x0C
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds #define	NR_PROTOEXT			0x00
251da177e4SLinus Torvalds #define	NR_CONNREQ			0x01
261da177e4SLinus Torvalds #define	NR_CONNACK			0x02
271da177e4SLinus Torvalds #define	NR_DISCREQ			0x03
281da177e4SLinus Torvalds #define	NR_DISCACK			0x04
291da177e4SLinus Torvalds #define	NR_INFO				0x05
301da177e4SLinus Torvalds #define	NR_INFOACK			0x06
31e21ce8c7SRalf Baechle #define	NR_RESET			0x07
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #define	NR_CHOKE_FLAG			0x80
341da177e4SLinus Torvalds #define	NR_NAK_FLAG			0x40
351da177e4SLinus Torvalds #define	NR_MORE_FLAG			0x20
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds /* Define Link State constants. */
381da177e4SLinus Torvalds enum {
391da177e4SLinus Torvalds 	NR_STATE_0,
401da177e4SLinus Torvalds 	NR_STATE_1,
411da177e4SLinus Torvalds 	NR_STATE_2,
421da177e4SLinus Torvalds 	NR_STATE_3
431da177e4SLinus Torvalds };
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds #define	NR_COND_ACK_PENDING		0x01
461da177e4SLinus Torvalds #define	NR_COND_REJECT			0x02
471da177e4SLinus Torvalds #define	NR_COND_PEER_RX_BUSY		0x04
481da177e4SLinus Torvalds #define	NR_COND_OWN_RX_BUSY		0x08
491da177e4SLinus Torvalds 
504d8937d0SRalf Baechle #define NR_DEFAULT_T1			120000		/* Outstanding frames - 120 seconds */
514d8937d0SRalf Baechle #define NR_DEFAULT_T2			5000		/* Response delay     - 5 seconds */
521da177e4SLinus Torvalds #define NR_DEFAULT_N2			3		/* Number of Retries - 3 */
534d8937d0SRalf Baechle #define	NR_DEFAULT_T4			180000		/* Busy Delay - 180 seconds */
544d8937d0SRalf Baechle #define	NR_DEFAULT_IDLE			0		/* No Activity Timeout - none */
551da177e4SLinus Torvalds #define	NR_DEFAULT_WINDOW		4		/* Default Window Size - 4 */
561da177e4SLinus Torvalds #define	NR_DEFAULT_OBS			6		/* Default Obsolescence Count - 6 */
571da177e4SLinus Torvalds #define	NR_DEFAULT_QUAL			10		/* Default Neighbour Quality - 10 */
581da177e4SLinus Torvalds #define	NR_DEFAULT_TTL			16		/* Default Time To Live - 16 */
591da177e4SLinus Torvalds #define	NR_DEFAULT_ROUTING		1		/* Is routing enabled ? */
601da177e4SLinus Torvalds #define	NR_DEFAULT_FAILS		2		/* Link fails until route fails */
61e21ce8c7SRalf Baechle #define	NR_DEFAULT_RESET		0		/* Sent / accept reset cmds? */
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds #define NR_MODULUS 			256
641da177e4SLinus Torvalds #define NR_MAX_WINDOW_SIZE		127			/* Maximum Window Allowable - 127 */
651da177e4SLinus Torvalds #define	NR_MAX_PACKET_SIZE		236			/* Maximum Packet Length - 236 */
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds struct nr_sock {
681da177e4SLinus Torvalds 	struct sock		sock;
691da177e4SLinus Torvalds 	ax25_address		user_addr, source_addr, dest_addr;
701da177e4SLinus Torvalds 	struct net_device		*device;
711da177e4SLinus Torvalds 	unsigned char		my_index,   my_id;
721da177e4SLinus Torvalds 	unsigned char		your_index, your_id;
731da177e4SLinus Torvalds 	unsigned char		state, condition, bpqext, window;
741da177e4SLinus Torvalds 	unsigned short		vs, vr, va, vl;
751da177e4SLinus Torvalds 	unsigned char		n2, n2count;
761da177e4SLinus Torvalds 	unsigned long		t1, t2, t4, idle;
771da177e4SLinus Torvalds 	unsigned short		fraglen;
781da177e4SLinus Torvalds 	struct timer_list	t1timer;
791da177e4SLinus Torvalds 	struct timer_list	t2timer;
801da177e4SLinus Torvalds 	struct timer_list	t4timer;
811da177e4SLinus Torvalds 	struct timer_list	idletimer;
821da177e4SLinus Torvalds 	struct sk_buff_head	ack_queue;
831da177e4SLinus Torvalds 	struct sk_buff_head	reseq_queue;
841da177e4SLinus Torvalds 	struct sk_buff_head	frag_queue;
851da177e4SLinus Torvalds };
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds #define nr_sk(sk) ((struct nr_sock *)(sk))
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds struct nr_neigh {
901da177e4SLinus Torvalds 	struct hlist_node	neigh_node;
911da177e4SLinus Torvalds 	ax25_address		callsign;
921da177e4SLinus Torvalds 	ax25_digi		*digipeat;
931da177e4SLinus Torvalds 	ax25_cb			*ax25;
941da177e4SLinus Torvalds 	struct net_device	*dev;
951da177e4SLinus Torvalds 	unsigned char		quality;
961da177e4SLinus Torvalds 	unsigned char		locked;
971da177e4SLinus Torvalds 	unsigned short		count;
981da177e4SLinus Torvalds 	unsigned int		number;
991da177e4SLinus Torvalds 	unsigned char		failed;
100af420749SReshetova, Elena 	refcount_t		refcount;
1011da177e4SLinus Torvalds };
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds struct nr_route {
1041da177e4SLinus Torvalds 	unsigned char   quality;
1051da177e4SLinus Torvalds 	unsigned char   obs_count;
1061da177e4SLinus Torvalds 	struct nr_neigh *neighbour;
1071da177e4SLinus Torvalds };
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds struct nr_node {
1101da177e4SLinus Torvalds 	struct hlist_node	node_node;
1111da177e4SLinus Torvalds 	ax25_address		callsign;
1121da177e4SLinus Torvalds 	char			mnemonic[7];
1131da177e4SLinus Torvalds 	unsigned char		which;
1141da177e4SLinus Torvalds 	unsigned char		count;
1151da177e4SLinus Torvalds 	struct nr_route		routes[3];
116156be7edSReshetova, Elena 	refcount_t		refcount;
1171da177e4SLinus Torvalds 	spinlock_t		node_lock;
1181da177e4SLinus Torvalds };
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds /*********************************************************************
1211da177e4SLinus Torvalds  *	nr_node & nr_neigh lists, refcounting and locking
1221da177e4SLinus Torvalds  *********************************************************************/
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds #define nr_node_hold(__nr_node) \
125156be7edSReshetova, Elena 	refcount_inc(&((__nr_node)->refcount))
1261da177e4SLinus Torvalds 
nr_node_put(struct nr_node * nr_node)1271da177e4SLinus Torvalds static __inline__ void nr_node_put(struct nr_node *nr_node)
1281da177e4SLinus Torvalds {
129156be7edSReshetova, Elena 	if (refcount_dec_and_test(&nr_node->refcount)) {
1301da177e4SLinus Torvalds 		kfree(nr_node);
1311da177e4SLinus Torvalds 	}
1321da177e4SLinus Torvalds }
1331da177e4SLinus Torvalds 
1341da177e4SLinus Torvalds #define nr_neigh_hold(__nr_neigh) \
135af420749SReshetova, Elena 	refcount_inc(&((__nr_neigh)->refcount))
1361da177e4SLinus Torvalds 
nr_neigh_put(struct nr_neigh * nr_neigh)1371da177e4SLinus Torvalds static __inline__ void nr_neigh_put(struct nr_neigh *nr_neigh)
1381da177e4SLinus Torvalds {
139af420749SReshetova, Elena 	if (refcount_dec_and_test(&nr_neigh->refcount)) {
140d00c362fSJarek Poplawski 		if (nr_neigh->ax25)
141d00c362fSJarek Poplawski 			ax25_cb_put(nr_neigh->ax25);
1421da177e4SLinus Torvalds 		kfree(nr_neigh->digipeat);
1431da177e4SLinus Torvalds 		kfree(nr_neigh);
1441da177e4SLinus Torvalds 	}
1451da177e4SLinus Torvalds }
1461da177e4SLinus Torvalds 
1471da177e4SLinus Torvalds /* nr_node_lock and nr_node_unlock also hold/put the node's refcounter.
1481da177e4SLinus Torvalds  */
nr_node_lock(struct nr_node * nr_node)1491da177e4SLinus Torvalds static __inline__ void nr_node_lock(struct nr_node *nr_node)
1501da177e4SLinus Torvalds {
1511da177e4SLinus Torvalds 	nr_node_hold(nr_node);
1521da177e4SLinus Torvalds 	spin_lock_bh(&nr_node->node_lock);
1531da177e4SLinus Torvalds }
1541da177e4SLinus Torvalds 
nr_node_unlock(struct nr_node * nr_node)1551da177e4SLinus Torvalds static __inline__ void nr_node_unlock(struct nr_node *nr_node)
1561da177e4SLinus Torvalds {
1571da177e4SLinus Torvalds 	spin_unlock_bh(&nr_node->node_lock);
1581da177e4SLinus Torvalds 	nr_node_put(nr_node);
1591da177e4SLinus Torvalds }
1601da177e4SLinus Torvalds 
161b67bfe0dSSasha Levin #define nr_neigh_for_each(__nr_neigh, list) \
162b67bfe0dSSasha Levin 	hlist_for_each_entry(__nr_neigh, list, neigh_node)
1631da177e4SLinus Torvalds 
164b67bfe0dSSasha Levin #define nr_neigh_for_each_safe(__nr_neigh, node2, list) \
165b67bfe0dSSasha Levin 	hlist_for_each_entry_safe(__nr_neigh, node2, list, neigh_node)
1661da177e4SLinus Torvalds 
167b67bfe0dSSasha Levin #define nr_node_for_each(__nr_node, list) \
168b67bfe0dSSasha Levin 	hlist_for_each_entry(__nr_node, list, node_node)
1691da177e4SLinus Torvalds 
170b67bfe0dSSasha Levin #define nr_node_for_each_safe(__nr_node, node2, list) \
171b67bfe0dSSasha Levin 	hlist_for_each_entry_safe(__nr_node, node2, list, node_node)
1721da177e4SLinus Torvalds 
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds /*********************************************************************/
1751da177e4SLinus Torvalds 
1761da177e4SLinus Torvalds /* af_netrom.c */
1771da177e4SLinus Torvalds extern int  sysctl_netrom_default_path_quality;
1781da177e4SLinus Torvalds extern int  sysctl_netrom_obsolescence_count_initialiser;
1791da177e4SLinus Torvalds extern int  sysctl_netrom_network_ttl_initialiser;
1801da177e4SLinus Torvalds extern int  sysctl_netrom_transport_timeout;
1811da177e4SLinus Torvalds extern int  sysctl_netrom_transport_maximum_tries;
1821da177e4SLinus Torvalds extern int  sysctl_netrom_transport_acknowledge_delay;
1831da177e4SLinus Torvalds extern int  sysctl_netrom_transport_busy_delay;
1841da177e4SLinus Torvalds extern int  sysctl_netrom_transport_requested_window_size;
1851da177e4SLinus Torvalds extern int  sysctl_netrom_transport_no_activity_timeout;
1861da177e4SLinus Torvalds extern int  sysctl_netrom_routing_control;
1871da177e4SLinus Torvalds extern int  sysctl_netrom_link_fails_count;
188e21ce8c7SRalf Baechle extern int  sysctl_netrom_reset_circuit;
189e21ce8c7SRalf Baechle 
19096496127SJoe Perches int nr_rx_frame(struct sk_buff *, struct net_device *);
19196496127SJoe Perches void nr_destroy_socket(struct sock *);
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds /* nr_dev.c */
19496496127SJoe Perches int nr_rx_ip(struct sk_buff *, struct net_device *);
19596496127SJoe Perches void nr_setup(struct net_device *);
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds /* nr_in.c */
19896496127SJoe Perches int nr_process_rx_frame(struct sock *, struct sk_buff *);
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds /* nr_loopback.c */
20196496127SJoe Perches void nr_loopback_init(void);
20296496127SJoe Perches void nr_loopback_clear(void);
20396496127SJoe Perches int nr_loopback_queue(struct sk_buff *);
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds /* nr_out.c */
20696496127SJoe Perches void nr_output(struct sock *, struct sk_buff *);
20796496127SJoe Perches void nr_send_nak_frame(struct sock *);
20896496127SJoe Perches void nr_kick(struct sock *);
20996496127SJoe Perches void nr_transmit_buffer(struct sock *, struct sk_buff *);
21096496127SJoe Perches void nr_establish_data_link(struct sock *);
21196496127SJoe Perches void nr_enquiry_response(struct sock *);
21296496127SJoe Perches void nr_check_iframes_acked(struct sock *, unsigned short);
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds /* nr_route.c */
21596496127SJoe Perches void nr_rt_device_down(struct net_device *);
21696496127SJoe Perches struct net_device *nr_dev_first(void);
21796496127SJoe Perches struct net_device *nr_dev_get(ax25_address *);
21896496127SJoe Perches int nr_rt_ioctl(unsigned int, void __user *);
21996496127SJoe Perches void nr_link_failed(ax25_cb *, int);
22096496127SJoe Perches int nr_route_frame(struct sk_buff *, ax25_cb *);
221fddda2b7SChristoph Hellwig extern const struct seq_operations nr_node_seqops;
222fddda2b7SChristoph Hellwig extern const struct seq_operations nr_neigh_seqops;
22396496127SJoe Perches void nr_rt_free(void);
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds /* nr_subr.c */
22696496127SJoe Perches void nr_clear_queues(struct sock *);
22796496127SJoe Perches void nr_frames_acked(struct sock *, unsigned short);
22896496127SJoe Perches void nr_requeue_frames(struct sock *);
22996496127SJoe Perches int nr_validate_nr(struct sock *, unsigned short);
23096496127SJoe Perches int nr_in_rx_window(struct sock *, unsigned short);
23196496127SJoe Perches void nr_write_internal(struct sock *, int);
232e21ce8c7SRalf Baechle 
23396496127SJoe Perches void __nr_transmit_reply(struct sk_buff *skb, int mine, unsigned char cmdflags);
234e21ce8c7SRalf Baechle 
235e21ce8c7SRalf Baechle /*
236e21ce8c7SRalf Baechle  * This routine is called when a Connect Acknowledge with the Choke Flag
237e21ce8c7SRalf Baechle  * set is needed to refuse a connection.
238e21ce8c7SRalf Baechle  */
239e21ce8c7SRalf Baechle #define nr_transmit_refusal(skb, mine)					\
240e21ce8c7SRalf Baechle do {									\
241e21ce8c7SRalf Baechle 	__nr_transmit_reply((skb), (mine), NR_CONNACK | NR_CHOKE_FLAG);	\
242e21ce8c7SRalf Baechle } while (0)
243e21ce8c7SRalf Baechle 
244e21ce8c7SRalf Baechle /*
245e21ce8c7SRalf Baechle  * This routine is called when we don't have a circuit matching an incoming
246e21ce8c7SRalf Baechle  * NET/ROM packet.  This is an G8PZT Xrouter extension.
247e21ce8c7SRalf Baechle  */
248e21ce8c7SRalf Baechle #define nr_transmit_reset(skb, mine)					\
249e21ce8c7SRalf Baechle do {									\
250e21ce8c7SRalf Baechle 	__nr_transmit_reply((skb), (mine), NR_RESET);			\
251e21ce8c7SRalf Baechle } while (0)
252e21ce8c7SRalf Baechle 
25396496127SJoe Perches void nr_disconnect(struct sock *, int);
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds /* nr_timer.c */
25696496127SJoe Perches void nr_init_timers(struct sock *sk);
25796496127SJoe Perches void nr_start_heartbeat(struct sock *);
25896496127SJoe Perches void nr_start_t1timer(struct sock *);
25996496127SJoe Perches void nr_start_t2timer(struct sock *);
26096496127SJoe Perches void nr_start_t4timer(struct sock *);
26196496127SJoe Perches void nr_start_idletimer(struct sock *);
26296496127SJoe Perches void nr_stop_heartbeat(struct sock *);
26396496127SJoe Perches void nr_stop_t1timer(struct sock *);
26496496127SJoe Perches void nr_stop_t2timer(struct sock *);
26596496127SJoe Perches void nr_stop_t4timer(struct sock *);
26696496127SJoe Perches void nr_stop_idletimer(struct sock *);
26796496127SJoe Perches int nr_t1timer_running(struct sock *);
2681da177e4SLinus Torvalds 
2691da177e4SLinus Torvalds /* sysctl_net_netrom.c */
270d3706566SYueHaibing int nr_register_sysctl(void);
27196496127SJoe Perches void nr_unregister_sysctl(void);
2721da177e4SLinus Torvalds 
2731da177e4SLinus Torvalds #endif
274