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