xref: /openbmc/linux/include/net/netrom.h (revision b88a762b6062f06d431af0045de4854a758646c0)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *	Declarations of NET/ROM type objects.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *	Jonathan Naylor G4KLX	9/4/95
51da177e4SLinus Torvalds  */
61da177e4SLinus Torvalds 
71da177e4SLinus Torvalds #ifndef _NETROM_H
81da177e4SLinus Torvalds #define _NETROM_H
9*b88a762bSRalf Baechle 
101da177e4SLinus Torvalds #include <linux/netrom.h>
111da177e4SLinus Torvalds #include <linux/list.h>
121da177e4SLinus Torvalds #include <net/sock.h>
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #define	NR_NETWORK_LEN			15
151da177e4SLinus Torvalds #define	NR_TRANSPORT_LEN		5
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds #define	NR_PROTO_IP			0x0C
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #define	NR_PROTOEXT			0x00
201da177e4SLinus Torvalds #define	NR_CONNREQ			0x01
211da177e4SLinus Torvalds #define	NR_CONNACK			0x02
221da177e4SLinus Torvalds #define	NR_DISCREQ			0x03
231da177e4SLinus Torvalds #define	NR_DISCACK			0x04
241da177e4SLinus Torvalds #define	NR_INFO				0x05
251da177e4SLinus Torvalds #define	NR_INFOACK			0x06
26e21ce8c7SRalf Baechle #define	NR_RESET			0x07
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #define	NR_CHOKE_FLAG			0x80
291da177e4SLinus Torvalds #define	NR_NAK_FLAG			0x40
301da177e4SLinus Torvalds #define	NR_MORE_FLAG			0x20
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds /* Define Link State constants. */
331da177e4SLinus Torvalds enum {
341da177e4SLinus Torvalds 	NR_STATE_0,
351da177e4SLinus Torvalds 	NR_STATE_1,
361da177e4SLinus Torvalds 	NR_STATE_2,
371da177e4SLinus Torvalds 	NR_STATE_3
381da177e4SLinus Torvalds };
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds #define	NR_COND_ACK_PENDING		0x01
411da177e4SLinus Torvalds #define	NR_COND_REJECT			0x02
421da177e4SLinus Torvalds #define	NR_COND_PEER_RX_BUSY		0x04
431da177e4SLinus Torvalds #define	NR_COND_OWN_RX_BUSY		0x08
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds #define NR_DEFAULT_T1			(120 * HZ)	/* Outstanding frames - 120 seconds */
461da177e4SLinus Torvalds #define NR_DEFAULT_T2			(5   * HZ)	/* Response delay     - 5 seconds */
471da177e4SLinus Torvalds #define NR_DEFAULT_N2			3		/* Number of Retries - 3 */
481da177e4SLinus Torvalds #define	NR_DEFAULT_T4			(180 * HZ)	/* Busy Delay - 180 seconds */
491da177e4SLinus Torvalds #define	NR_DEFAULT_IDLE			(0 * 60 * HZ)	/* No Activity Timeout - none */
501da177e4SLinus Torvalds #define	NR_DEFAULT_WINDOW		4		/* Default Window Size - 4 */
511da177e4SLinus Torvalds #define	NR_DEFAULT_OBS			6		/* Default Obsolescence Count - 6 */
521da177e4SLinus Torvalds #define	NR_DEFAULT_QUAL			10		/* Default Neighbour Quality - 10 */
531da177e4SLinus Torvalds #define	NR_DEFAULT_TTL			16		/* Default Time To Live - 16 */
541da177e4SLinus Torvalds #define	NR_DEFAULT_ROUTING		1		/* Is routing enabled ? */
551da177e4SLinus Torvalds #define	NR_DEFAULT_FAILS		2		/* Link fails until route fails */
56e21ce8c7SRalf Baechle #define	NR_DEFAULT_RESET		0		/* Sent / accept reset cmds? */
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds #define NR_MODULUS 			256
591da177e4SLinus Torvalds #define NR_MAX_WINDOW_SIZE		127			/* Maximum Window Allowable - 127 */
601da177e4SLinus Torvalds #define	NR_MAX_PACKET_SIZE		236			/* Maximum Packet Length - 236 */
611da177e4SLinus Torvalds 
62*b88a762bSRalf Baechle struct nr_private {
63*b88a762bSRalf Baechle 	struct net_device_stats	stats;
64*b88a762bSRalf Baechle };
65*b88a762bSRalf Baechle 
661da177e4SLinus Torvalds struct nr_sock {
671da177e4SLinus Torvalds 	struct sock		sock;
681da177e4SLinus Torvalds 	ax25_address		user_addr, source_addr, dest_addr;
691da177e4SLinus Torvalds 	struct net_device		*device;
701da177e4SLinus Torvalds 	unsigned char		my_index,   my_id;
711da177e4SLinus Torvalds 	unsigned char		your_index, your_id;
721da177e4SLinus Torvalds 	unsigned char		state, condition, bpqext, window;
731da177e4SLinus Torvalds 	unsigned short		vs, vr, va, vl;
741da177e4SLinus Torvalds 	unsigned char		n2, n2count;
751da177e4SLinus Torvalds 	unsigned long		t1, t2, t4, idle;
761da177e4SLinus Torvalds 	unsigned short		fraglen;
771da177e4SLinus Torvalds 	struct timer_list	t1timer;
781da177e4SLinus Torvalds 	struct timer_list	t2timer;
791da177e4SLinus Torvalds 	struct timer_list	t4timer;
801da177e4SLinus Torvalds 	struct timer_list	idletimer;
811da177e4SLinus Torvalds 	struct sk_buff_head	ack_queue;
821da177e4SLinus Torvalds 	struct sk_buff_head	reseq_queue;
831da177e4SLinus Torvalds 	struct sk_buff_head	frag_queue;
841da177e4SLinus Torvalds };
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds #define nr_sk(sk) ((struct nr_sock *)(sk))
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds struct nr_neigh {
891da177e4SLinus Torvalds 	struct hlist_node	neigh_node;
901da177e4SLinus Torvalds 	ax25_address		callsign;
911da177e4SLinus Torvalds 	ax25_digi		*digipeat;
921da177e4SLinus Torvalds 	ax25_cb			*ax25;
931da177e4SLinus Torvalds 	struct net_device	*dev;
941da177e4SLinus Torvalds 	unsigned char		quality;
951da177e4SLinus Torvalds 	unsigned char		locked;
961da177e4SLinus Torvalds 	unsigned short		count;
971da177e4SLinus Torvalds 	unsigned int		number;
981da177e4SLinus Torvalds 	unsigned char		failed;
991da177e4SLinus Torvalds 	atomic_t		refcount;
1001da177e4SLinus Torvalds };
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds struct nr_route {
1031da177e4SLinus Torvalds 	unsigned char   quality;
1041da177e4SLinus Torvalds 	unsigned char   obs_count;
1051da177e4SLinus Torvalds 	struct nr_neigh *neighbour;
1061da177e4SLinus Torvalds };
1071da177e4SLinus Torvalds 
1081da177e4SLinus Torvalds struct nr_node {
1091da177e4SLinus Torvalds 	struct hlist_node	node_node;
1101da177e4SLinus Torvalds 	ax25_address		callsign;
1111da177e4SLinus Torvalds 	char			mnemonic[7];
1121da177e4SLinus Torvalds 	unsigned char		which;
1131da177e4SLinus Torvalds 	unsigned char		count;
1141da177e4SLinus Torvalds 	struct nr_route		routes[3];
1151da177e4SLinus Torvalds 	atomic_t		refcount;
1161da177e4SLinus Torvalds 	spinlock_t		node_lock;
1171da177e4SLinus Torvalds };
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds /*********************************************************************
1201da177e4SLinus Torvalds  *	nr_node & nr_neigh lists, refcounting and locking
1211da177e4SLinus Torvalds  *********************************************************************/
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds #define nr_node_hold(__nr_node) \
1241da177e4SLinus Torvalds 	atomic_inc(&((__nr_node)->refcount))
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds static __inline__ void nr_node_put(struct nr_node *nr_node)
1271da177e4SLinus Torvalds {
1281da177e4SLinus Torvalds 	if (atomic_dec_and_test(&nr_node->refcount)) {
1291da177e4SLinus Torvalds 		kfree(nr_node);
1301da177e4SLinus Torvalds 	}
1311da177e4SLinus Torvalds }
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds #define nr_neigh_hold(__nr_neigh) \
1341da177e4SLinus Torvalds 	atomic_inc(&((__nr_neigh)->refcount))
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds static __inline__ void nr_neigh_put(struct nr_neigh *nr_neigh)
1371da177e4SLinus Torvalds {
1381da177e4SLinus Torvalds 	if (atomic_dec_and_test(&nr_neigh->refcount)) {
1391da177e4SLinus Torvalds 		if (nr_neigh->digipeat != NULL)
1401da177e4SLinus Torvalds 			kfree(nr_neigh->digipeat);
1411da177e4SLinus Torvalds 		kfree(nr_neigh);
1421da177e4SLinus Torvalds 	}
1431da177e4SLinus Torvalds }
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds /* nr_node_lock and nr_node_unlock also hold/put the node's refcounter.
1461da177e4SLinus Torvalds  */
1471da177e4SLinus Torvalds static __inline__ void nr_node_lock(struct nr_node *nr_node)
1481da177e4SLinus Torvalds {
1491da177e4SLinus Torvalds 	nr_node_hold(nr_node);
1501da177e4SLinus Torvalds 	spin_lock_bh(&nr_node->node_lock);
1511da177e4SLinus Torvalds }
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds static __inline__ void nr_node_unlock(struct nr_node *nr_node)
1541da177e4SLinus Torvalds {
1551da177e4SLinus Torvalds 	spin_unlock_bh(&nr_node->node_lock);
1561da177e4SLinus Torvalds 	nr_node_put(nr_node);
1571da177e4SLinus Torvalds }
1581da177e4SLinus Torvalds 
1591da177e4SLinus Torvalds #define nr_neigh_for_each(__nr_neigh, node, list) \
1601da177e4SLinus Torvalds 	hlist_for_each_entry(__nr_neigh, node, list, neigh_node)
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds #define nr_neigh_for_each_safe(__nr_neigh, node, node2, list) \
1631da177e4SLinus Torvalds 	hlist_for_each_entry_safe(__nr_neigh, node, node2, list, neigh_node)
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds #define nr_node_for_each(__nr_node, node, list) \
1661da177e4SLinus Torvalds 	hlist_for_each_entry(__nr_node, node, list, node_node)
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds #define nr_node_for_each_safe(__nr_node, node, node2, list) \
1691da177e4SLinus Torvalds 	hlist_for_each_entry_safe(__nr_node, node, node2, list, node_node)
1701da177e4SLinus Torvalds 
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds /*********************************************************************/
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds /* af_netrom.c */
1751da177e4SLinus Torvalds extern int  sysctl_netrom_default_path_quality;
1761da177e4SLinus Torvalds extern int  sysctl_netrom_obsolescence_count_initialiser;
1771da177e4SLinus Torvalds extern int  sysctl_netrom_network_ttl_initialiser;
1781da177e4SLinus Torvalds extern int  sysctl_netrom_transport_timeout;
1791da177e4SLinus Torvalds extern int  sysctl_netrom_transport_maximum_tries;
1801da177e4SLinus Torvalds extern int  sysctl_netrom_transport_acknowledge_delay;
1811da177e4SLinus Torvalds extern int  sysctl_netrom_transport_busy_delay;
1821da177e4SLinus Torvalds extern int  sysctl_netrom_transport_requested_window_size;
1831da177e4SLinus Torvalds extern int  sysctl_netrom_transport_no_activity_timeout;
1841da177e4SLinus Torvalds extern int  sysctl_netrom_routing_control;
1851da177e4SLinus Torvalds extern int  sysctl_netrom_link_fails_count;
186e21ce8c7SRalf Baechle extern int  sysctl_netrom_reset_circuit;
187e21ce8c7SRalf Baechle 
1881da177e4SLinus Torvalds extern int  nr_rx_frame(struct sk_buff *, struct net_device *);
1891da177e4SLinus Torvalds extern void nr_destroy_socket(struct sock *);
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds /* nr_dev.c */
1921da177e4SLinus Torvalds extern int  nr_rx_ip(struct sk_buff *, struct net_device *);
1931da177e4SLinus Torvalds extern void nr_setup(struct net_device *);
1941da177e4SLinus Torvalds 
1951da177e4SLinus Torvalds /* nr_in.c */
1961da177e4SLinus Torvalds extern int  nr_process_rx_frame(struct sock *, struct sk_buff *);
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds /* nr_loopback.c */
1991da177e4SLinus Torvalds extern void nr_loopback_init(void);
2001da177e4SLinus Torvalds extern void nr_loopback_clear(void);
2011da177e4SLinus Torvalds extern int  nr_loopback_queue(struct sk_buff *);
2021da177e4SLinus Torvalds 
2031da177e4SLinus Torvalds /* nr_out.c */
2041da177e4SLinus Torvalds extern void nr_output(struct sock *, struct sk_buff *);
2051da177e4SLinus Torvalds extern void nr_send_nak_frame(struct sock *);
2061da177e4SLinus Torvalds extern void nr_kick(struct sock *);
2071da177e4SLinus Torvalds extern void nr_transmit_buffer(struct sock *, struct sk_buff *);
2081da177e4SLinus Torvalds extern void nr_establish_data_link(struct sock *);
2091da177e4SLinus Torvalds extern void nr_enquiry_response(struct sock *);
2101da177e4SLinus Torvalds extern void nr_check_iframes_acked(struct sock *, unsigned short);
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds /* nr_route.c */
2131da177e4SLinus Torvalds extern void nr_rt_device_down(struct net_device *);
2141da177e4SLinus Torvalds extern struct net_device *nr_dev_first(void);
2151da177e4SLinus Torvalds extern struct net_device *nr_dev_get(ax25_address *);
2161da177e4SLinus Torvalds extern int  nr_rt_ioctl(unsigned int, void __user *);
2171da177e4SLinus Torvalds extern void nr_link_failed(ax25_cb *, int);
2181da177e4SLinus Torvalds extern int  nr_route_frame(struct sk_buff *, ax25_cb *);
2191da177e4SLinus Torvalds extern struct file_operations nr_nodes_fops;
2201da177e4SLinus Torvalds extern struct file_operations nr_neigh_fops;
2211da177e4SLinus Torvalds extern void nr_rt_free(void);
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds /* nr_subr.c */
2241da177e4SLinus Torvalds extern void nr_clear_queues(struct sock *);
2251da177e4SLinus Torvalds extern void nr_frames_acked(struct sock *, unsigned short);
2261da177e4SLinus Torvalds extern void nr_requeue_frames(struct sock *);
2271da177e4SLinus Torvalds extern int  nr_validate_nr(struct sock *, unsigned short);
2281da177e4SLinus Torvalds extern int  nr_in_rx_window(struct sock *, unsigned short);
2291da177e4SLinus Torvalds extern void nr_write_internal(struct sock *, int);
230e21ce8c7SRalf Baechle 
231e21ce8c7SRalf Baechle extern void __nr_transmit_reply(struct sk_buff *skb, int mine,
232e21ce8c7SRalf Baechle 	unsigned char cmdflags);
233e21ce8c7SRalf Baechle 
234e21ce8c7SRalf Baechle /*
235e21ce8c7SRalf Baechle  * This routine is called when a Connect Acknowledge with the Choke Flag
236e21ce8c7SRalf Baechle  * set is needed to refuse a connection.
237e21ce8c7SRalf Baechle  */
238e21ce8c7SRalf Baechle #define nr_transmit_refusal(skb, mine)					\
239e21ce8c7SRalf Baechle do {									\
240e21ce8c7SRalf Baechle 	__nr_transmit_reply((skb), (mine), NR_CONNACK | NR_CHOKE_FLAG);	\
241e21ce8c7SRalf Baechle } while (0)
242e21ce8c7SRalf Baechle 
243e21ce8c7SRalf Baechle /*
244e21ce8c7SRalf Baechle  * This routine is called when we don't have a circuit matching an incoming
245e21ce8c7SRalf Baechle  * NET/ROM packet.  This is an G8PZT Xrouter extension.
246e21ce8c7SRalf Baechle  */
247e21ce8c7SRalf Baechle #define nr_transmit_reset(skb, mine)					\
248e21ce8c7SRalf Baechle do {									\
249e21ce8c7SRalf Baechle 	__nr_transmit_reply((skb), (mine), NR_RESET);			\
250e21ce8c7SRalf Baechle } while (0)
251e21ce8c7SRalf Baechle 
2521da177e4SLinus Torvalds extern void nr_disconnect(struct sock *, int);
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds /* nr_timer.c */
2551da177e4SLinus Torvalds extern void nr_init_timers(struct sock *sk);
2561da177e4SLinus Torvalds extern void nr_start_heartbeat(struct sock *);
2571da177e4SLinus Torvalds extern void nr_start_t1timer(struct sock *);
2581da177e4SLinus Torvalds extern void nr_start_t2timer(struct sock *);
2591da177e4SLinus Torvalds extern void nr_start_t4timer(struct sock *);
2601da177e4SLinus Torvalds extern void nr_start_idletimer(struct sock *);
2611da177e4SLinus Torvalds extern void nr_stop_heartbeat(struct sock *);
2621da177e4SLinus Torvalds extern void nr_stop_t1timer(struct sock *);
2631da177e4SLinus Torvalds extern void nr_stop_t2timer(struct sock *);
2641da177e4SLinus Torvalds extern void nr_stop_t4timer(struct sock *);
2651da177e4SLinus Torvalds extern void nr_stop_idletimer(struct sock *);
2661da177e4SLinus Torvalds extern int  nr_t1timer_running(struct sock *);
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds /* sysctl_net_netrom.c */
2691da177e4SLinus Torvalds extern void nr_register_sysctl(void);
2701da177e4SLinus Torvalds extern void nr_unregister_sysctl(void);
2711da177e4SLinus Torvalds 
2721da177e4SLinus Torvalds #endif
273