18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *	Declarations of NET/ROM type objects.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *	Jonathan Naylor G4KLX	9/4/95
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _NETROM_H
98c2ecf20Sopenharmony_ci#define _NETROM_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/netrom.h>
128c2ecf20Sopenharmony_ci#include <linux/list.h>
138c2ecf20Sopenharmony_ci#include <linux/slab.h>
148c2ecf20Sopenharmony_ci#include <net/sock.h>
158c2ecf20Sopenharmony_ci#include <linux/refcount.h>
168c2ecf20Sopenharmony_ci#include <linux/seq_file.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define	NR_NETWORK_LEN			15
198c2ecf20Sopenharmony_ci#define	NR_TRANSPORT_LEN		5
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define	NR_PROTO_IP			0x0C
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define	NR_PROTOEXT			0x00
248c2ecf20Sopenharmony_ci#define	NR_CONNREQ			0x01
258c2ecf20Sopenharmony_ci#define	NR_CONNACK			0x02
268c2ecf20Sopenharmony_ci#define	NR_DISCREQ			0x03
278c2ecf20Sopenharmony_ci#define	NR_DISCACK			0x04
288c2ecf20Sopenharmony_ci#define	NR_INFO				0x05
298c2ecf20Sopenharmony_ci#define	NR_INFOACK			0x06
308c2ecf20Sopenharmony_ci#define	NR_RESET			0x07
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define	NR_CHOKE_FLAG			0x80
338c2ecf20Sopenharmony_ci#define	NR_NAK_FLAG			0x40
348c2ecf20Sopenharmony_ci#define	NR_MORE_FLAG			0x20
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* Define Link State constants. */
378c2ecf20Sopenharmony_cienum {
388c2ecf20Sopenharmony_ci	NR_STATE_0,
398c2ecf20Sopenharmony_ci	NR_STATE_1,
408c2ecf20Sopenharmony_ci	NR_STATE_2,
418c2ecf20Sopenharmony_ci	NR_STATE_3
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define	NR_COND_ACK_PENDING		0x01
458c2ecf20Sopenharmony_ci#define	NR_COND_REJECT			0x02
468c2ecf20Sopenharmony_ci#define	NR_COND_PEER_RX_BUSY		0x04
478c2ecf20Sopenharmony_ci#define	NR_COND_OWN_RX_BUSY		0x08
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define NR_DEFAULT_T1			120000		/* Outstanding frames - 120 seconds */
508c2ecf20Sopenharmony_ci#define NR_DEFAULT_T2			5000		/* Response delay     - 5 seconds */
518c2ecf20Sopenharmony_ci#define NR_DEFAULT_N2			3		/* Number of Retries - 3 */
528c2ecf20Sopenharmony_ci#define	NR_DEFAULT_T4			180000		/* Busy Delay - 180 seconds */
538c2ecf20Sopenharmony_ci#define	NR_DEFAULT_IDLE			0		/* No Activity Timeout - none */
548c2ecf20Sopenharmony_ci#define	NR_DEFAULT_WINDOW		4		/* Default Window Size - 4 */
558c2ecf20Sopenharmony_ci#define	NR_DEFAULT_OBS			6		/* Default Obsolescence Count - 6 */
568c2ecf20Sopenharmony_ci#define	NR_DEFAULT_QUAL			10		/* Default Neighbour Quality - 10 */
578c2ecf20Sopenharmony_ci#define	NR_DEFAULT_TTL			16		/* Default Time To Live - 16 */
588c2ecf20Sopenharmony_ci#define	NR_DEFAULT_ROUTING		1		/* Is routing enabled ? */
598c2ecf20Sopenharmony_ci#define	NR_DEFAULT_FAILS		2		/* Link fails until route fails */
608c2ecf20Sopenharmony_ci#define	NR_DEFAULT_RESET		0		/* Sent / accept reset cmds? */
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define NR_MODULUS 			256
638c2ecf20Sopenharmony_ci#define NR_MAX_WINDOW_SIZE		127			/* Maximum Window Allowable - 127 */
648c2ecf20Sopenharmony_ci#define	NR_MAX_PACKET_SIZE		236			/* Maximum Packet Length - 236 */
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistruct nr_sock {
678c2ecf20Sopenharmony_ci	struct sock		sock;
688c2ecf20Sopenharmony_ci	ax25_address		user_addr, source_addr, dest_addr;
698c2ecf20Sopenharmony_ci	struct net_device		*device;
708c2ecf20Sopenharmony_ci	unsigned char		my_index,   my_id;
718c2ecf20Sopenharmony_ci	unsigned char		your_index, your_id;
728c2ecf20Sopenharmony_ci	unsigned char		state, condition, bpqext, window;
738c2ecf20Sopenharmony_ci	unsigned short		vs, vr, va, vl;
748c2ecf20Sopenharmony_ci	unsigned char		n2, n2count;
758c2ecf20Sopenharmony_ci	unsigned long		t1, t2, t4, idle;
768c2ecf20Sopenharmony_ci	unsigned short		fraglen;
778c2ecf20Sopenharmony_ci	struct timer_list	t1timer;
788c2ecf20Sopenharmony_ci	struct timer_list	t2timer;
798c2ecf20Sopenharmony_ci	struct timer_list	t4timer;
808c2ecf20Sopenharmony_ci	struct timer_list	idletimer;
818c2ecf20Sopenharmony_ci	struct sk_buff_head	ack_queue;
828c2ecf20Sopenharmony_ci	struct sk_buff_head	reseq_queue;
838c2ecf20Sopenharmony_ci	struct sk_buff_head	frag_queue;
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define nr_sk(sk) ((struct nr_sock *)(sk))
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistruct nr_neigh {
898c2ecf20Sopenharmony_ci	struct hlist_node	neigh_node;
908c2ecf20Sopenharmony_ci	ax25_address		callsign;
918c2ecf20Sopenharmony_ci	ax25_digi		*digipeat;
928c2ecf20Sopenharmony_ci	ax25_cb			*ax25;
938c2ecf20Sopenharmony_ci	struct net_device	*dev;
948c2ecf20Sopenharmony_ci	unsigned char		quality;
958c2ecf20Sopenharmony_ci	unsigned char		locked;
968c2ecf20Sopenharmony_ci	unsigned short		count;
978c2ecf20Sopenharmony_ci	unsigned int		number;
988c2ecf20Sopenharmony_ci	unsigned char		failed;
998c2ecf20Sopenharmony_ci	refcount_t		refcount;
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistruct nr_route {
1038c2ecf20Sopenharmony_ci	unsigned char   quality;
1048c2ecf20Sopenharmony_ci	unsigned char   obs_count;
1058c2ecf20Sopenharmony_ci	struct nr_neigh *neighbour;
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistruct nr_node {
1098c2ecf20Sopenharmony_ci	struct hlist_node	node_node;
1108c2ecf20Sopenharmony_ci	ax25_address		callsign;
1118c2ecf20Sopenharmony_ci	char			mnemonic[7];
1128c2ecf20Sopenharmony_ci	unsigned char		which;
1138c2ecf20Sopenharmony_ci	unsigned char		count;
1148c2ecf20Sopenharmony_ci	struct nr_route		routes[3];
1158c2ecf20Sopenharmony_ci	refcount_t		refcount;
1168c2ecf20Sopenharmony_ci	spinlock_t		node_lock;
1178c2ecf20Sopenharmony_ci};
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/*********************************************************************
1208c2ecf20Sopenharmony_ci *	nr_node & nr_neigh lists, refcounting and locking
1218c2ecf20Sopenharmony_ci *********************************************************************/
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define nr_node_hold(__nr_node) \
1248c2ecf20Sopenharmony_ci	refcount_inc(&((__nr_node)->refcount))
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic __inline__ void nr_node_put(struct nr_node *nr_node)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	if (refcount_dec_and_test(&nr_node->refcount)) {
1298c2ecf20Sopenharmony_ci		kfree(nr_node);
1308c2ecf20Sopenharmony_ci	}
1318c2ecf20Sopenharmony_ci}
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define nr_neigh_hold(__nr_neigh) \
1348c2ecf20Sopenharmony_ci	refcount_inc(&((__nr_neigh)->refcount))
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_cistatic __inline__ void nr_neigh_put(struct nr_neigh *nr_neigh)
1378c2ecf20Sopenharmony_ci{
1388c2ecf20Sopenharmony_ci	if (refcount_dec_and_test(&nr_neigh->refcount)) {
1398c2ecf20Sopenharmony_ci		if (nr_neigh->ax25)
1408c2ecf20Sopenharmony_ci			ax25_cb_put(nr_neigh->ax25);
1418c2ecf20Sopenharmony_ci		kfree(nr_neigh->digipeat);
1428c2ecf20Sopenharmony_ci		kfree(nr_neigh);
1438c2ecf20Sopenharmony_ci	}
1448c2ecf20Sopenharmony_ci}
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci/* nr_node_lock and nr_node_unlock also hold/put the node's refcounter.
1478c2ecf20Sopenharmony_ci */
1488c2ecf20Sopenharmony_cistatic __inline__ void nr_node_lock(struct nr_node *nr_node)
1498c2ecf20Sopenharmony_ci{
1508c2ecf20Sopenharmony_ci	nr_node_hold(nr_node);
1518c2ecf20Sopenharmony_ci	spin_lock_bh(&nr_node->node_lock);
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistatic __inline__ void nr_node_unlock(struct nr_node *nr_node)
1558c2ecf20Sopenharmony_ci{
1568c2ecf20Sopenharmony_ci	spin_unlock_bh(&nr_node->node_lock);
1578c2ecf20Sopenharmony_ci	nr_node_put(nr_node);
1588c2ecf20Sopenharmony_ci}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#define nr_neigh_for_each(__nr_neigh, list) \
1618c2ecf20Sopenharmony_ci	hlist_for_each_entry(__nr_neigh, list, neigh_node)
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#define nr_neigh_for_each_safe(__nr_neigh, node2, list) \
1648c2ecf20Sopenharmony_ci	hlist_for_each_entry_safe(__nr_neigh, node2, list, neigh_node)
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#define nr_node_for_each(__nr_node, list) \
1678c2ecf20Sopenharmony_ci	hlist_for_each_entry(__nr_node, list, node_node)
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci#define nr_node_for_each_safe(__nr_node, node2, list) \
1708c2ecf20Sopenharmony_ci	hlist_for_each_entry_safe(__nr_node, node2, list, node_node)
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/*********************************************************************/
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci/* af_netrom.c */
1768c2ecf20Sopenharmony_ciextern int  sysctl_netrom_default_path_quality;
1778c2ecf20Sopenharmony_ciextern int  sysctl_netrom_obsolescence_count_initialiser;
1788c2ecf20Sopenharmony_ciextern int  sysctl_netrom_network_ttl_initialiser;
1798c2ecf20Sopenharmony_ciextern int  sysctl_netrom_transport_timeout;
1808c2ecf20Sopenharmony_ciextern int  sysctl_netrom_transport_maximum_tries;
1818c2ecf20Sopenharmony_ciextern int  sysctl_netrom_transport_acknowledge_delay;
1828c2ecf20Sopenharmony_ciextern int  sysctl_netrom_transport_busy_delay;
1838c2ecf20Sopenharmony_ciextern int  sysctl_netrom_transport_requested_window_size;
1848c2ecf20Sopenharmony_ciextern int  sysctl_netrom_transport_no_activity_timeout;
1858c2ecf20Sopenharmony_ciextern int  sysctl_netrom_routing_control;
1868c2ecf20Sopenharmony_ciextern int  sysctl_netrom_link_fails_count;
1878c2ecf20Sopenharmony_ciextern int  sysctl_netrom_reset_circuit;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ciint nr_rx_frame(struct sk_buff *, struct net_device *);
1908c2ecf20Sopenharmony_civoid nr_destroy_socket(struct sock *);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/* nr_dev.c */
1938c2ecf20Sopenharmony_ciint nr_rx_ip(struct sk_buff *, struct net_device *);
1948c2ecf20Sopenharmony_civoid nr_setup(struct net_device *);
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci/* nr_in.c */
1978c2ecf20Sopenharmony_ciint nr_process_rx_frame(struct sock *, struct sk_buff *);
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/* nr_loopback.c */
2008c2ecf20Sopenharmony_civoid nr_loopback_init(void);
2018c2ecf20Sopenharmony_civoid nr_loopback_clear(void);
2028c2ecf20Sopenharmony_ciint nr_loopback_queue(struct sk_buff *);
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* nr_out.c */
2058c2ecf20Sopenharmony_civoid nr_output(struct sock *, struct sk_buff *);
2068c2ecf20Sopenharmony_civoid nr_send_nak_frame(struct sock *);
2078c2ecf20Sopenharmony_civoid nr_kick(struct sock *);
2088c2ecf20Sopenharmony_civoid nr_transmit_buffer(struct sock *, struct sk_buff *);
2098c2ecf20Sopenharmony_civoid nr_establish_data_link(struct sock *);
2108c2ecf20Sopenharmony_civoid nr_enquiry_response(struct sock *);
2118c2ecf20Sopenharmony_civoid nr_check_iframes_acked(struct sock *, unsigned short);
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci/* nr_route.c */
2148c2ecf20Sopenharmony_civoid nr_rt_device_down(struct net_device *);
2158c2ecf20Sopenharmony_cistruct net_device *nr_dev_first(void);
2168c2ecf20Sopenharmony_cistruct net_device *nr_dev_get(ax25_address *);
2178c2ecf20Sopenharmony_ciint nr_rt_ioctl(unsigned int, void __user *);
2188c2ecf20Sopenharmony_civoid nr_link_failed(ax25_cb *, int);
2198c2ecf20Sopenharmony_ciint nr_route_frame(struct sk_buff *, ax25_cb *);
2208c2ecf20Sopenharmony_ciextern const struct seq_operations nr_node_seqops;
2218c2ecf20Sopenharmony_ciextern const struct seq_operations nr_neigh_seqops;
2228c2ecf20Sopenharmony_civoid nr_rt_free(void);
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci/* nr_subr.c */
2258c2ecf20Sopenharmony_civoid nr_clear_queues(struct sock *);
2268c2ecf20Sopenharmony_civoid nr_frames_acked(struct sock *, unsigned short);
2278c2ecf20Sopenharmony_civoid nr_requeue_frames(struct sock *);
2288c2ecf20Sopenharmony_ciint nr_validate_nr(struct sock *, unsigned short);
2298c2ecf20Sopenharmony_ciint nr_in_rx_window(struct sock *, unsigned short);
2308c2ecf20Sopenharmony_civoid nr_write_internal(struct sock *, int);
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_civoid __nr_transmit_reply(struct sk_buff *skb, int mine, unsigned char cmdflags);
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci/*
2358c2ecf20Sopenharmony_ci * This routine is called when a Connect Acknowledge with the Choke Flag
2368c2ecf20Sopenharmony_ci * set is needed to refuse a connection.
2378c2ecf20Sopenharmony_ci */
2388c2ecf20Sopenharmony_ci#define nr_transmit_refusal(skb, mine)					\
2398c2ecf20Sopenharmony_cido {									\
2408c2ecf20Sopenharmony_ci	__nr_transmit_reply((skb), (mine), NR_CONNACK | NR_CHOKE_FLAG);	\
2418c2ecf20Sopenharmony_ci} while (0)
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci/*
2448c2ecf20Sopenharmony_ci * This routine is called when we don't have a circuit matching an incoming
2458c2ecf20Sopenharmony_ci * NET/ROM packet.  This is an G8PZT Xrouter extension.
2468c2ecf20Sopenharmony_ci */
2478c2ecf20Sopenharmony_ci#define nr_transmit_reset(skb, mine)					\
2488c2ecf20Sopenharmony_cido {									\
2498c2ecf20Sopenharmony_ci	__nr_transmit_reply((skb), (mine), NR_RESET);			\
2508c2ecf20Sopenharmony_ci} while (0)
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_civoid nr_disconnect(struct sock *, int);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci/* nr_timer.c */
2558c2ecf20Sopenharmony_civoid nr_init_timers(struct sock *sk);
2568c2ecf20Sopenharmony_civoid nr_start_heartbeat(struct sock *);
2578c2ecf20Sopenharmony_civoid nr_start_t1timer(struct sock *);
2588c2ecf20Sopenharmony_civoid nr_start_t2timer(struct sock *);
2598c2ecf20Sopenharmony_civoid nr_start_t4timer(struct sock *);
2608c2ecf20Sopenharmony_civoid nr_start_idletimer(struct sock *);
2618c2ecf20Sopenharmony_civoid nr_stop_heartbeat(struct sock *);
2628c2ecf20Sopenharmony_civoid nr_stop_t1timer(struct sock *);
2638c2ecf20Sopenharmony_civoid nr_stop_t2timer(struct sock *);
2648c2ecf20Sopenharmony_civoid nr_stop_t4timer(struct sock *);
2658c2ecf20Sopenharmony_civoid nr_stop_idletimer(struct sock *);
2668c2ecf20Sopenharmony_ciint nr_t1timer_running(struct sock *);
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci/* sysctl_net_netrom.c */
2698c2ecf20Sopenharmony_ciint nr_register_sysctl(void);
2708c2ecf20Sopenharmony_civoid nr_unregister_sysctl(void);
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci#endif
273