Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  Declarations of NET/ROM type objects.
0004  *
0005  *  Jonathan Naylor G4KLX   9/4/95
0006  */
0007 
0008 #ifndef _NETROM_H
0009 #define _NETROM_H 
0010 
0011 #include <linux/netrom.h>
0012 #include <linux/list.h>
0013 #include <linux/slab.h>
0014 #include <net/sock.h>
0015 #include <linux/refcount.h>
0016 #include <linux/seq_file.h>
0017 #include <net/ax25.h>
0018 
0019 #define NR_NETWORK_LEN          15
0020 #define NR_TRANSPORT_LEN        5
0021 
0022 #define NR_PROTO_IP         0x0C
0023 
0024 #define NR_PROTOEXT         0x00
0025 #define NR_CONNREQ          0x01
0026 #define NR_CONNACK          0x02
0027 #define NR_DISCREQ          0x03
0028 #define NR_DISCACK          0x04
0029 #define NR_INFO             0x05
0030 #define NR_INFOACK          0x06
0031 #define NR_RESET            0x07
0032 
0033 #define NR_CHOKE_FLAG           0x80
0034 #define NR_NAK_FLAG         0x40
0035 #define NR_MORE_FLAG            0x20
0036 
0037 /* Define Link State constants. */
0038 enum {
0039     NR_STATE_0,
0040     NR_STATE_1,
0041     NR_STATE_2,
0042     NR_STATE_3
0043 };
0044 
0045 #define NR_COND_ACK_PENDING     0x01
0046 #define NR_COND_REJECT          0x02
0047 #define NR_COND_PEER_RX_BUSY        0x04
0048 #define NR_COND_OWN_RX_BUSY     0x08
0049 
0050 #define NR_DEFAULT_T1           120000      /* Outstanding frames - 120 seconds */
0051 #define NR_DEFAULT_T2           5000        /* Response delay     - 5 seconds */
0052 #define NR_DEFAULT_N2           3       /* Number of Retries - 3 */
0053 #define NR_DEFAULT_T4           180000      /* Busy Delay - 180 seconds */
0054 #define NR_DEFAULT_IDLE         0       /* No Activity Timeout - none */
0055 #define NR_DEFAULT_WINDOW       4       /* Default Window Size - 4 */
0056 #define NR_DEFAULT_OBS          6       /* Default Obsolescence Count - 6 */
0057 #define NR_DEFAULT_QUAL         10      /* Default Neighbour Quality - 10 */
0058 #define NR_DEFAULT_TTL          16      /* Default Time To Live - 16 */
0059 #define NR_DEFAULT_ROUTING      1       /* Is routing enabled ? */
0060 #define NR_DEFAULT_FAILS        2       /* Link fails until route fails */
0061 #define NR_DEFAULT_RESET        0       /* Sent / accept reset cmds? */
0062 
0063 #define NR_MODULUS          256
0064 #define NR_MAX_WINDOW_SIZE      127         /* Maximum Window Allowable - 127 */
0065 #define NR_MAX_PACKET_SIZE      236         /* Maximum Packet Length - 236 */
0066 
0067 struct nr_sock {
0068     struct sock     sock;
0069     ax25_address        user_addr, source_addr, dest_addr;
0070     struct net_device       *device;
0071     unsigned char       my_index,   my_id;
0072     unsigned char       your_index, your_id;
0073     unsigned char       state, condition, bpqext, window;
0074     unsigned short      vs, vr, va, vl;
0075     unsigned char       n2, n2count;
0076     unsigned long       t1, t2, t4, idle;
0077     unsigned short      fraglen;
0078     struct timer_list   t1timer;
0079     struct timer_list   t2timer;
0080     struct timer_list   t4timer;
0081     struct timer_list   idletimer;
0082     struct sk_buff_head ack_queue;
0083     struct sk_buff_head reseq_queue;
0084     struct sk_buff_head frag_queue;
0085 };
0086 
0087 #define nr_sk(sk) ((struct nr_sock *)(sk))
0088 
0089 struct nr_neigh {
0090     struct hlist_node   neigh_node;
0091     ax25_address        callsign;
0092     ax25_digi       *digipeat;
0093     ax25_cb         *ax25;
0094     struct net_device   *dev;
0095     unsigned char       quality;
0096     unsigned char       locked;
0097     unsigned short      count;
0098     unsigned int        number;
0099     unsigned char       failed;
0100     refcount_t      refcount;
0101 };
0102 
0103 struct nr_route {
0104     unsigned char   quality;
0105     unsigned char   obs_count;
0106     struct nr_neigh *neighbour;
0107 };
0108 
0109 struct nr_node {
0110     struct hlist_node   node_node;
0111     ax25_address        callsign;
0112     char            mnemonic[7];
0113     unsigned char       which;
0114     unsigned char       count;
0115     struct nr_route     routes[3];
0116     refcount_t      refcount;
0117     spinlock_t      node_lock;
0118 };
0119 
0120 /*********************************************************************
0121  *  nr_node & nr_neigh lists, refcounting and locking
0122  *********************************************************************/
0123 
0124 #define nr_node_hold(__nr_node) \
0125     refcount_inc(&((__nr_node)->refcount))
0126 
0127 static __inline__ void nr_node_put(struct nr_node *nr_node)
0128 {
0129     if (refcount_dec_and_test(&nr_node->refcount)) {
0130         kfree(nr_node);
0131     }
0132 }
0133 
0134 #define nr_neigh_hold(__nr_neigh) \
0135     refcount_inc(&((__nr_neigh)->refcount))
0136 
0137 static __inline__ void nr_neigh_put(struct nr_neigh *nr_neigh)
0138 {
0139     if (refcount_dec_and_test(&nr_neigh->refcount)) {
0140         if (nr_neigh->ax25)
0141             ax25_cb_put(nr_neigh->ax25);
0142         kfree(nr_neigh->digipeat);
0143         kfree(nr_neigh);
0144     }
0145 }
0146 
0147 /* nr_node_lock and nr_node_unlock also hold/put the node's refcounter.
0148  */
0149 static __inline__ void nr_node_lock(struct nr_node *nr_node)
0150 {
0151     nr_node_hold(nr_node);
0152     spin_lock_bh(&nr_node->node_lock);
0153 }
0154 
0155 static __inline__ void nr_node_unlock(struct nr_node *nr_node)
0156 {
0157     spin_unlock_bh(&nr_node->node_lock);
0158     nr_node_put(nr_node);
0159 }
0160 
0161 #define nr_neigh_for_each(__nr_neigh, list) \
0162     hlist_for_each_entry(__nr_neigh, list, neigh_node)
0163 
0164 #define nr_neigh_for_each_safe(__nr_neigh, node2, list) \
0165     hlist_for_each_entry_safe(__nr_neigh, node2, list, neigh_node)
0166 
0167 #define nr_node_for_each(__nr_node, list) \
0168     hlist_for_each_entry(__nr_node, list, node_node)
0169 
0170 #define nr_node_for_each_safe(__nr_node, node2, list) \
0171     hlist_for_each_entry_safe(__nr_node, node2, list, node_node)
0172 
0173 
0174 /*********************************************************************/
0175 
0176 /* af_netrom.c */
0177 extern int  sysctl_netrom_default_path_quality;
0178 extern int  sysctl_netrom_obsolescence_count_initialiser;
0179 extern int  sysctl_netrom_network_ttl_initialiser;
0180 extern int  sysctl_netrom_transport_timeout;
0181 extern int  sysctl_netrom_transport_maximum_tries;
0182 extern int  sysctl_netrom_transport_acknowledge_delay;
0183 extern int  sysctl_netrom_transport_busy_delay;
0184 extern int  sysctl_netrom_transport_requested_window_size;
0185 extern int  sysctl_netrom_transport_no_activity_timeout;
0186 extern int  sysctl_netrom_routing_control;
0187 extern int  sysctl_netrom_link_fails_count;
0188 extern int  sysctl_netrom_reset_circuit;
0189 
0190 int nr_rx_frame(struct sk_buff *, struct net_device *);
0191 void nr_destroy_socket(struct sock *);
0192 
0193 /* nr_dev.c */
0194 int nr_rx_ip(struct sk_buff *, struct net_device *);
0195 void nr_setup(struct net_device *);
0196 
0197 /* nr_in.c */
0198 int nr_process_rx_frame(struct sock *, struct sk_buff *);
0199 
0200 /* nr_loopback.c */
0201 void nr_loopback_init(void);
0202 void nr_loopback_clear(void);
0203 int nr_loopback_queue(struct sk_buff *);
0204 
0205 /* nr_out.c */
0206 void nr_output(struct sock *, struct sk_buff *);
0207 void nr_send_nak_frame(struct sock *);
0208 void nr_kick(struct sock *);
0209 void nr_transmit_buffer(struct sock *, struct sk_buff *);
0210 void nr_establish_data_link(struct sock *);
0211 void nr_enquiry_response(struct sock *);
0212 void nr_check_iframes_acked(struct sock *, unsigned short);
0213 
0214 /* nr_route.c */
0215 void nr_rt_device_down(struct net_device *);
0216 struct net_device *nr_dev_first(void);
0217 struct net_device *nr_dev_get(ax25_address *);
0218 int nr_rt_ioctl(unsigned int, void __user *);
0219 void nr_link_failed(ax25_cb *, int);
0220 int nr_route_frame(struct sk_buff *, ax25_cb *);
0221 extern const struct seq_operations nr_node_seqops;
0222 extern const struct seq_operations nr_neigh_seqops;
0223 void nr_rt_free(void);
0224 
0225 /* nr_subr.c */
0226 void nr_clear_queues(struct sock *);
0227 void nr_frames_acked(struct sock *, unsigned short);
0228 void nr_requeue_frames(struct sock *);
0229 int nr_validate_nr(struct sock *, unsigned short);
0230 int nr_in_rx_window(struct sock *, unsigned short);
0231 void nr_write_internal(struct sock *, int);
0232 
0233 void __nr_transmit_reply(struct sk_buff *skb, int mine, unsigned char cmdflags);
0234 
0235 /*
0236  * This routine is called when a Connect Acknowledge with the Choke Flag
0237  * set is needed to refuse a connection.
0238  */
0239 #define nr_transmit_refusal(skb, mine)                  \
0240 do {                                    \
0241     __nr_transmit_reply((skb), (mine), NR_CONNACK | NR_CHOKE_FLAG); \
0242 } while (0)
0243 
0244 /*
0245  * This routine is called when we don't have a circuit matching an incoming
0246  * NET/ROM packet.  This is an G8PZT Xrouter extension.
0247  */
0248 #define nr_transmit_reset(skb, mine)                    \
0249 do {                                    \
0250     __nr_transmit_reply((skb), (mine), NR_RESET);           \
0251 } while (0)
0252 
0253 void nr_disconnect(struct sock *, int);
0254 
0255 /* nr_timer.c */
0256 void nr_init_timers(struct sock *sk);
0257 void nr_start_heartbeat(struct sock *);
0258 void nr_start_t1timer(struct sock *);
0259 void nr_start_t2timer(struct sock *);
0260 void nr_start_t4timer(struct sock *);
0261 void nr_start_idletimer(struct sock *);
0262 void nr_stop_heartbeat(struct sock *);
0263 void nr_stop_t1timer(struct sock *);
0264 void nr_stop_t2timer(struct sock *);
0265 void nr_stop_t4timer(struct sock *);
0266 void nr_stop_idletimer(struct sock *);
0267 int nr_t1timer_running(struct sock *);
0268 
0269 /* sysctl_net_netrom.c */
0270 int nr_register_sysctl(void);
0271 void nr_unregister_sysctl(void);
0272 
0273 #endif