Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

irlap.h

Go to the documentation of this file.
00001 /*********************************************************************
00002  *                
00003  * Filename:      irlap.h
00004  * Version:       0.8
00005  * Description:   An IrDA LAP driver for Linux
00006  * Status:        Experimental.
00007  * Author:        Dag Brattli <dagb@cs.uit.no>
00008  * Created at:    Mon Aug  4 20:40:53 1997
00009  * Modified at:   Fri Dec 10 13:21:17 1999
00010  * Modified by:   Dag Brattli <dagb@cs.uit.no>
00011  * 
00012  *     Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>, 
00013  *     All Rights Reserved.
00014  *     
00015  *     This program is free software; you can redistribute it and/or 
00016  *     modify it under the terms of the GNU General Public License as 
00017  *     published by the Free Software Foundation; either version 2 of 
00018  *     the License, or (at your option) any later version.
00019  *
00020  *     Neither Dag Brattli nor University of Tromsų admit liability nor
00021  *     provide warranty for any of this software. This material is 
00022  *     provided "AS-IS" and at no charge.
00023  *
00024  ********************************************************************/
00025 
00026 #ifndef IRLAP_H
00027 #define IRLAP_H
00028 
00029 #include <linux/config.h>
00030 #include <linux/types.h>
00031 #include <linux/skbuff.h>
00032 #include <linux/netdevice.h>
00033 #include <linux/ppp_defs.h>
00034 #include <linux/ppp-comp.h>
00035 #include <linux/timer.h>
00036 
00037 #include <net/irda/irlap_event.h>
00038 
00039 #define CONFIG_IRDA_DYNAMIC_WINDOW 1
00040 
00041 #define LAP_RELIABLE   1
00042 #define LAP_UNRELIABLE 0
00043 
00044 #define LAP_ADDR_HEADER 1  /* IrLAP Address Header */
00045 #define LAP_CTRL_HEADER 1  /* IrLAP Control Header */
00046 #define LAP_COMP_HEADER 1  /* IrLAP Compression Header */
00047 
00048 #ifdef CONFIG_IRDA_COMPRESSION
00049 #  define LAP_MAX_HEADER  (LAP_ADDR_HEADER + LAP_CTRL_HEADER + LAP_COMP_HEADER)
00050 #  define IRDA_COMPRESSED 1
00051 #  define IRDA_NORMAL     0
00052 #else
00053 #define LAP_MAX_HEADER (LAP_ADDR_HEADER + LAP_CTRL_HEADER)
00054 #endif
00055 
00056 #define BROADCAST  0xffffffff /* Broadcast device address */
00057 #define CBROADCAST 0xfe       /* Connection broadcast address */
00058 #define XID_FORMAT 0x01       /* Discovery XID format */
00059 
00060 #define LAP_WINDOW_SIZE 8
00061 #define LAP_MAX_QUEUE  10
00062 
00063 #define NR_EXPECTED     1
00064 #define NR_UNEXPECTED   0
00065 #define NR_INVALID     -1
00066 
00067 #define NS_EXPECTED     1
00068 #define NS_UNEXPECTED   0
00069 #define NS_INVALID     -1
00070 
00071 #ifdef CONFIG_IRDA_COMPRESSION
00072 
00073 /*  
00074  *  Just some shortcuts (may give you strange compiler errors if you change 
00075  *  them :-)
00076  */
00077 #define irda_compress    (*self->compessor.cp->compress)
00078 #define irda_comp_free   (*self->compressor.cp->comp_free)
00079 #define irda_decompress  (*self->decompressor.cp->decompress)
00080 #define irda_decomp_free (*self->decompressor.cp->decomp_free)
00081 #define irda_incomp      (*self->decompressor.cp->incomp)
00082 
00083 struct irda_compressor {
00084         queue_t q;
00085 
00086         struct compressor *cp;
00087         void *state; /* Not used by IrDA */
00088 };
00089 #endif
00090 
00091 /* Main structure of IrLAP */
00092 struct irlap_cb {
00093         queue_t q;     /* Must be first */
00094         magic_t magic;
00095 
00096         struct device  *netdev;
00097 
00098         /* Connection state */
00099         volatile IRLAP_STATE state;       /* Current state */
00100 
00101         /* Timers used by IrLAP */
00102         struct timer_list query_timer;
00103         struct timer_list slot_timer;
00104         struct timer_list discovery_timer;
00105         struct timer_list final_timer;
00106         struct timer_list poll_timer;
00107         struct timer_list wd_timer;
00108         struct timer_list backoff_timer;
00109 
00110         /* Media busy stuff */
00111         struct timer_list media_busy_timer;
00112         int media_busy;
00113 
00114         /* Timeouts which will be different with different turn time */
00115         int slot_timeout;
00116         int poll_timeout;
00117         int final_timeout;
00118         int wd_timeout;
00119 
00120         struct sk_buff_head txq;  /* Frames to be transmitted */
00121         struct sk_buff_head txq_ultra;
00122 
00123         __u8    caddr;        /* Connection address */
00124         __u32   saddr;        /* Source device address */
00125         __u32   daddr;        /* Destination device address */
00126 
00127         int     retry_count;  /* Times tried to establish connection */
00128         int     add_wait;     /* True if we are waiting for frame */
00129 
00130         __u8    connect_pending;
00131         __u8    disconnect_pending;
00132 
00133         /*  To send a faster RR if tx queue empty */
00134 #ifdef CONFIG_IRDA_FAST_RR
00135         int     fast_RR_timeout;
00136         int     fast_RR;      
00137 #endif /* CONFIG_IRDA_FAST_RR */
00138         
00139         int N1; /* N1 * F-timer = Negitiated link disconnect warning threshold */
00140         int N2; /* N2 * F-timer = Negitiated link disconnect time */
00141         int N3; /* Connection retry count */
00142 
00143         int     local_busy;
00144         int     remote_busy;
00145         int     xmitflag;
00146 
00147         __u8    vs;            /* Next frame to be sent */
00148         __u8    vr;            /* Next frame to be received */
00149         __u8    va;            /* Last frame acked */
00150         int     window;        /* Nr of I-frames allowed to send */
00151         int     window_size;   /* Current negotiated window size */
00152 
00153 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
00154         __u32   line_capacity; /* Number of bytes allowed to send */
00155         __u32   bytes_left;    /* Number of bytes still allowed to transmit */
00156 #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
00157 
00158         struct sk_buff_head wx_list;
00159 
00160         __u8    ack_required;
00161         
00162         /* XID parameters */
00163         __u8    S;           /* Number of slots */
00164         __u8    slot;        /* Random chosen slot */
00165         __u8    s;           /* Current slot */
00166         int     frame_sent;  /* Have we sent reply? */
00167 
00168         hashbin_t   *discovery_log;
00169         discovery_t *discovery_cmd;
00170 
00171         __u32 speed; 
00172 
00173         struct qos_info  qos_tx;   /* QoS requested by peer */
00174         struct qos_info  qos_rx;   /* QoS requested by self */
00175         struct qos_info *qos_dev;  /* QoS supported by device */
00176 
00177         notify_t notify; /* Callbacks to IrLMP */
00178 
00179         int    mtt_required;  /* Minumum turnaround time required */
00180         int    xbofs_delay;   /* Nr of XBOF's used to MTT */
00181         int    bofs_count;    /* Negotiated extra BOFs */
00182 
00183 #ifdef CONFIG_IRDA_COMPRESSION
00184         struct irda_compressor compressor;
00185         struct irda_compressor decompressor;
00186 #endif /* CONFIG_IRDA_COMPRESSION */
00187 };
00188 
00189 extern hashbin_t *irlap;
00190 
00191 /* 
00192  *  Function prototypes 
00193  */
00194 int irlap_init(void);
00195 void irlap_cleanup(void);
00196 
00197 struct irlap_cb *irlap_open(struct device *dev, struct qos_info *qos);
00198 void irlap_close(struct irlap_cb *self);
00199 
00200 void irlap_connect_request(struct irlap_cb *self, __u32 daddr, 
00201                            struct qos_info *qos, int sniff);
00202 void irlap_connect_response(struct irlap_cb *self, struct sk_buff *skb);
00203 void irlap_connect_indication(struct irlap_cb *self, struct sk_buff *skb);
00204 void irlap_connect_confirm(struct irlap_cb *, struct sk_buff *skb);
00205 
00206 void irlap_data_indication(struct irlap_cb *, struct sk_buff *, int unreliable);
00207 void irlap_data_request(struct irlap_cb *, struct sk_buff *, int unreliable);
00208 
00209 #ifdef CONFIG_IRDA_ULTRA
00210 void irlap_unitdata_request(struct irlap_cb *, struct sk_buff *);
00211 void irlap_unitdata_indication(struct irlap_cb *, struct sk_buff *);
00212 #endif /* CONFIG_IRDA_ULTRA */
00213 
00214 void irlap_disconnect_request(struct irlap_cb *);
00215 void irlap_disconnect_indication(struct irlap_cb *, LAP_REASON reason);
00216 
00217 void irlap_status_indication(int quality_of_link);
00218 
00219 void irlap_test_request(__u8 *info, int len);
00220 
00221 void irlap_discovery_request(struct irlap_cb *, discovery_t *discovery);
00222 void irlap_discovery_confirm(struct irlap_cb *, hashbin_t *discovery_log);
00223 void irlap_discovery_indication(struct irlap_cb *, discovery_t *discovery);
00224 
00225 void irlap_reset_indication(struct irlap_cb *self);
00226 void irlap_reset_confirm(void);
00227 
00228 void irlap_update_nr_received(struct irlap_cb *, int nr);
00229 int irlap_validate_nr_received(struct irlap_cb *, int nr);
00230 int irlap_validate_ns_received(struct irlap_cb *, int ns);
00231 
00232 int  irlap_generate_rand_time_slot(int S, int s);
00233 void irlap_initiate_connection_state(struct irlap_cb *);
00234 void irlap_flush_all_queues(struct irlap_cb *);
00235 void irlap_change_speed(struct irlap_cb *self, __u32 speed, int now);
00236 void irlap_wait_min_turn_around(struct irlap_cb *, struct qos_info *);
00237 
00238 void irlap_init_qos_capabilities(struct irlap_cb *, struct qos_info *);
00239 void irlap_apply_default_connection_parameters(struct irlap_cb *self);
00240 void irlap_apply_connection_parameters(struct irlap_cb *self);
00241 void irlap_set_local_busy(struct irlap_cb *self, int status);
00242 
00243 #define IRLAP_GET_HEADER_SIZE(self) 2 /* Will be different when we get VFIR */
00244 #define IRLAP_GET_TX_QUEUE_LEN(self) skb_queue_len(&self->txq)
00245 
00246 #endif