1 /*********************************************************************
2 *
3 * Filename: irlap.h
4 * Version: 0.8
5 * Description: An IrDA LAP driver for Linux
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Mon Aug 4 20:40:53 1997
9 * Modified at: Fri Dec 10 13:21:17 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 *
12 * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
13 * All Rights Reserved.
14 * Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com>
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
20 *
21 * Neither Dag Brattli nor University of Troms� admit liability nor
22 * provide warranty for any of this software. This material is
23 * provided "AS-IS" and at no charge.
24 *
25 ********************************************************************/
26
27 #ifndef IRLAP_H
28 #define IRLAP_H
29
30 #include <linux/config.h>
31 #include <linux/types.h>
32 #include <linux/skbuff.h>
33 #include <linux/netdevice.h>
34 #include <linux/timer.h>
35
36 #include <net/irda/irlap_event.h>
37
38 #define CONFIG_IRDA_DYNAMIC_WINDOW 1
39
40 #define LAP_RELIABLE 1
41 #define LAP_UNRELIABLE 0
42
43 #define LAP_ADDR_HEADER 1 /* IrLAP Address Header */
44 #define LAP_CTRL_HEADER 1 /* IrLAP Control Header */
45
46 /* May be different when we get VFIR */
47 #define LAP_MAX_HEADER (LAP_ADDR_HEADER + LAP_CTRL_HEADER)
48
49 #define BROADCAST 0xffffffff /* Broadcast device address */
50 #define CBROADCAST 0xfe /* Connection broadcast address */
51 #define XID_FORMAT 0x01 /* Discovery XID format */
52
53 /* Nobody seems to use this constant. */
54 #define LAP_WINDOW_SIZE 8
55 /* We keep the LAP queue very small to minimise the amount of buffering.
56 * this improve latency and reduce resource consumption.
57 * This work only because we have synchronous refilling of IrLAP through
58 * the flow control mechanism (via scheduler and IrTTP).
59 * 2 buffers is the minimum we can work with, one that we send while polling
60 * IrTTP, and another to know that we should not send the pf bit.
61 * Jean II */
62 #define LAP_HIGH_THRESHOLD 2
63 /* Some rare non TTP clients don't implement flow control, and
64 * so don't comply with the above limit (and neither with this one).
65 * For IAP and management, it doesn't matter, because they never transmit much.
66 *.For IrLPT, this should be fixed.
67 * - Jean II */
68 #define LAP_MAX_QUEUE 10
69 /* Please note that all IrDA management frames (LMP/TTP conn req/disc and
70 * IAS queries) fall in the second category and are sent to LAP even if TTP
71 * is stopped. This means that those frames will wait only a maximum of
72 * two (2) data frames before beeing sent on the "wire", which speed up
73 * new socket setup when the link is saturated.
74 * Same story for two sockets competing for the medium : if one saturates
75 * the LAP, when the other want to transmit it only has to wait for
76 * maximum three (3) packets (2 + one scheduling), which improve performance
77 * of delay sensitive applications.
78 * Jean II */
79
80 #define NR_EXPECTED 1
81 #define NR_UNEXPECTED 0
82 #define NR_INVALID -1
83
84 #define NS_EXPECTED 1
85 #define NS_UNEXPECTED 0
86 #define NS_INVALID -1
87
88 /* Main structure of IrLAP */
89 struct irlap_cb {
90 irda_queue_t q; /* Must be first */
91 magic_t magic;
92
93 /* Device we are attached to */
94 struct net_device *netdev;
95 char hw_name[2*IFNAMSIZ + 1];
96
97 /* Connection state */
98 volatile IRLAP_STATE state; /* Current state */
99
100 /* Timers used by IrLAP */
101 struct timer_list query_timer;
102 struct timer_list slot_timer;
103 struct timer_list discovery_timer;
104 struct timer_list final_timer;
105 struct timer_list poll_timer;
106 struct timer_list wd_timer;
107 struct timer_list backoff_timer;
108
109 /* Media busy stuff */
110 struct timer_list media_busy_timer;
111 int media_busy;
112
113 /* Timeouts which will be different with different turn time */
114 int slot_timeout;
115 int poll_timeout;
116 int final_timeout;
117 int wd_timeout;
118
119 struct sk_buff_head txq; /* Frames to be transmitted */
120 struct sk_buff_head txq_ultra;
121
122 __u8 caddr; /* Connection address */
123 __u32 saddr; /* Source device address */
124 __u32 daddr; /* Destination device address */
125
126 int retry_count; /* Times tried to establish connection */
127 int add_wait; /* True if we are waiting for frame */
128
129 __u8 connect_pending;
130 __u8 disconnect_pending;
131
132 /* To send a faster RR if tx queue empty */
133 #ifdef CONFIG_IRDA_FAST_RR
134 int fast_RR_timeout;
135 int fast_RR;
136 #endif /* CONFIG_IRDA_FAST_RR */
137
138 int N1; /* N1 * F-timer = Negitiated link disconnect warning threshold */
139 int N2; /* N2 * F-timer = Negitiated link disconnect time */
140 int N3; /* Connection retry count */
141
142 int local_busy;
143 int remote_busy;
144 int xmitflag;
145
146 __u8 vs; /* Next frame to be sent */
147 __u8 vr; /* Next frame to be received */
148 __u8 va; /* Last frame acked */
149 int window; /* Nr of I-frames allowed to send */
150 int window_size; /* Current negotiated window size */
151
152 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
153 __u32 line_capacity; /* Number of bytes allowed to send */
154 __u32 bytes_left; /* Number of bytes still allowed to transmit */
155 #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
156
157 struct sk_buff_head wx_list;
158
159 __u8 ack_required;
160
161 /* XID parameters */
162 __u8 S; /* Number of slots */
163 __u8 slot; /* Random chosen slot */
164 __u8 s; /* Current slot */
165 int frame_sent; /* Have we sent reply? */
166
167 hashbin_t *discovery_log;
168 discovery_t *discovery_cmd;
169
170 __u32 speed; /* Link speed */
171
172 struct qos_info qos_tx; /* QoS requested by peer */
173 struct qos_info qos_rx; /* QoS requested by self */
174 struct qos_info *qos_dev; /* QoS supported by device */
175
176 notify_t notify; /* Callbacks to IrLMP */
177
178 int mtt_required; /* Minumum turnaround time required */
179 int xbofs_delay; /* Nr of XBOF's used to MTT */
180 int bofs_count; /* Negotiated extra BOFs */
181 int next_bofs; /* Negotiated extra BOFs after next frame */
182 };
183
184 extern hashbin_t *irlap;
185
186 /*
187 * Function prototypes
188 */
189 int irlap_init(void);
190 void irlap_cleanup(void);
191
192 struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
193 char * hw_name);
194 void irlap_close(struct irlap_cb *self);
195
196 void irlap_connect_request(struct irlap_cb *self, __u32 daddr,
197 struct qos_info *qos, int sniff);
198 void irlap_connect_response(struct irlap_cb *self, struct sk_buff *skb);
199 void irlap_connect_indication(struct irlap_cb *self, struct sk_buff *skb);
200 void irlap_connect_confirm(struct irlap_cb *, struct sk_buff *skb);
201
202 void irlap_data_indication(struct irlap_cb *, struct sk_buff *, int unreliable);
203 void irlap_data_request(struct irlap_cb *, struct sk_buff *, int unreliable);
204
205 #ifdef CONFIG_IRDA_ULTRA
206 void irlap_unitdata_request(struct irlap_cb *, struct sk_buff *);
207 void irlap_unitdata_indication(struct irlap_cb *, struct sk_buff *);
208 #endif /* CONFIG_IRDA_ULTRA */
209
210 void irlap_disconnect_request(struct irlap_cb *);
211 void irlap_disconnect_indication(struct irlap_cb *, LAP_REASON reason);
212
213 void irlap_status_indication(struct irlap_cb *, int quality_of_link);
214
215 void irlap_test_request(__u8 *info, int len);
216
217 void irlap_discovery_request(struct irlap_cb *, discovery_t *discovery);
218 void irlap_discovery_confirm(struct irlap_cb *, hashbin_t *discovery_log);
219 void irlap_discovery_indication(struct irlap_cb *, discovery_t *discovery);
220
221 void irlap_reset_indication(struct irlap_cb *self);
222 void irlap_reset_confirm(void);
223
224 void irlap_update_nr_received(struct irlap_cb *, int nr);
225 int irlap_validate_nr_received(struct irlap_cb *, int nr);
226 int irlap_validate_ns_received(struct irlap_cb *, int ns);
227
228 int irlap_generate_rand_time_slot(int S, int s);
229 void irlap_initiate_connection_state(struct irlap_cb *);
230 void irlap_flush_all_queues(struct irlap_cb *);
231 void irlap_change_speed(struct irlap_cb *self, __u32 speed, int now);
232 void irlap_wait_min_turn_around(struct irlap_cb *, struct qos_info *);
233
234 void irlap_init_qos_capabilities(struct irlap_cb *, struct qos_info *);
235 void irlap_apply_default_connection_parameters(struct irlap_cb *self);
236 void irlap_apply_connection_parameters(struct irlap_cb *self, int now);
237
238 #define IRLAP_GET_HEADER_SIZE(self) (LAP_MAX_HEADER)
239 #define IRLAP_GET_TX_QUEUE_LEN(self) skb_queue_len(&self->txq)
240
241 /* Return TRUE if the node is in primary mode (i.e. master)
242 * - Jean II */
irlap_is_primary(struct irlap_cb * self)243 static inline int irlap_is_primary(struct irlap_cb *self)
244 {
245 int ret;
246 switch(self->state) {
247 case LAP_XMIT_P:
248 case LAP_NRM_P:
249 ret = 1;
250 break;
251 case LAP_XMIT_S:
252 case LAP_NRM_S:
253 ret = 0;
254 break;
255 default:
256 ret = -1;
257 }
258 return(ret);
259 }
260
261 #endif
262