1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef IRLAP_H
28#define IRLAP_H
29
30#include <linux/types.h>
31#include <linux/skbuff.h>
32#include <linux/netdevice.h>
33#include <linux/timer.h>
34
35#include <net/irda/irqueue.h>
36#include <net/irda/qos.h>
37#include <net/irda/discovery.h>
38#include <net/irda/irlap_event.h>
39#include <net/irda/irmod.h>
40
41#define CONFIG_IRDA_DYNAMIC_WINDOW 1
42
43#define LAP_RELIABLE 1
44#define LAP_UNRELIABLE 0
45
46#define LAP_ADDR_HEADER 1
47#define LAP_CTRL_HEADER 1
48
49
50#define LAP_MAX_HEADER (LAP_ADDR_HEADER + LAP_CTRL_HEADER)
51
52
53#define LAP_ALEN 4
54
55#define BROADCAST 0xffffffff
56#define CBROADCAST 0xfe
57#define XID_FORMAT 0x01
58
59
60#define LAP_WINDOW_SIZE 8
61
62
63
64
65
66
67
68#define LAP_HIGH_THRESHOLD 2
69
70
71
72
73
74#define LAP_MAX_QUEUE 10
75
76
77
78
79
80
81
82
83
84
85
86#define NR_EXPECTED 1
87#define NR_UNEXPECTED 0
88#define NR_INVALID -1
89
90#define NS_EXPECTED 1
91#define NS_UNEXPECTED 0
92#define NS_INVALID -1
93
94
95
96
97struct irlap_info {
98 __u8 caddr;
99 __u8 control;
100 __u8 cmd;
101
102 __u32 saddr;
103 __u32 daddr;
104
105 int pf;
106
107 __u8 nr;
108 __u8 ns;
109
110 int S;
111 int slot;
112 int s;
113
114 discovery_t *discovery;
115};
116
117
118struct irlap_cb {
119 irda_queue_t q;
120 magic_t magic;
121
122
123 struct net_device *netdev;
124 char hw_name[2*IFNAMSIZ + 1];
125
126
127 volatile IRLAP_STATE state;
128
129
130 struct timer_list query_timer;
131 struct timer_list slot_timer;
132 struct timer_list discovery_timer;
133 struct timer_list final_timer;
134 struct timer_list poll_timer;
135 struct timer_list wd_timer;
136 struct timer_list backoff_timer;
137
138
139 struct timer_list media_busy_timer;
140 int media_busy;
141
142
143 int slot_timeout;
144 int poll_timeout;
145 int final_timeout;
146 int wd_timeout;
147
148 struct sk_buff_head txq;
149 struct sk_buff_head txq_ultra;
150
151 __u8 caddr;
152 __u32 saddr;
153 __u32 daddr;
154
155 int retry_count;
156 int add_wait;
157
158 __u8 connect_pending;
159 __u8 disconnect_pending;
160
161
162#ifdef CONFIG_IRDA_FAST_RR
163 int fast_RR_timeout;
164 int fast_RR;
165#endif
166
167 int N1;
168 int N2;
169 int N3;
170
171 int local_busy;
172 int remote_busy;
173 int xmitflag;
174
175 __u8 vs;
176 __u8 vr;
177 __u8 va;
178 int window;
179 int window_size;
180
181#ifdef CONFIG_IRDA_DYNAMIC_WINDOW
182 __u32 line_capacity;
183 __u32 bytes_left;
184#endif
185
186 struct sk_buff_head wx_list;
187
188 __u8 ack_required;
189
190
191 __u8 S;
192 __u8 slot;
193 __u8 s;
194 int frame_sent;
195
196 hashbin_t *discovery_log;
197 discovery_t *discovery_cmd;
198
199 __u32 speed;
200
201 struct qos_info qos_tx;
202 struct qos_info qos_rx;
203 struct qos_info *qos_dev;
204
205 notify_t notify;
206
207 int mtt_required;
208 int xbofs_delay;
209 int bofs_count;
210 int next_bofs;
211
212 int mode;
213};
214
215
216
217
218int irlap_init(void);
219void irlap_cleanup(void);
220
221struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
222 const char *hw_name);
223void irlap_close(struct irlap_cb *self);
224
225void irlap_connect_request(struct irlap_cb *self, __u32 daddr,
226 struct qos_info *qos, int sniff);
227void irlap_connect_response(struct irlap_cb *self, struct sk_buff *skb);
228void irlap_connect_indication(struct irlap_cb *self, struct sk_buff *skb);
229void irlap_connect_confirm(struct irlap_cb *, struct sk_buff *skb);
230
231void irlap_data_indication(struct irlap_cb *, struct sk_buff *, int unreliable);
232void irlap_data_request(struct irlap_cb *, struct sk_buff *, int unreliable);
233
234#ifdef CONFIG_IRDA_ULTRA
235void irlap_unitdata_request(struct irlap_cb *, struct sk_buff *);
236void irlap_unitdata_indication(struct irlap_cb *, struct sk_buff *);
237#endif
238
239void irlap_disconnect_request(struct irlap_cb *);
240void irlap_disconnect_indication(struct irlap_cb *, LAP_REASON reason);
241
242void irlap_status_indication(struct irlap_cb *, int quality_of_link);
243
244void irlap_test_request(__u8 *info, int len);
245
246void irlap_discovery_request(struct irlap_cb *, discovery_t *discovery);
247void irlap_discovery_confirm(struct irlap_cb *, hashbin_t *discovery_log);
248void irlap_discovery_indication(struct irlap_cb *, discovery_t *discovery);
249
250void irlap_reset_indication(struct irlap_cb *self);
251void irlap_reset_confirm(void);
252
253void irlap_update_nr_received(struct irlap_cb *, int nr);
254int irlap_validate_nr_received(struct irlap_cb *, int nr);
255int irlap_validate_ns_received(struct irlap_cb *, int ns);
256
257int irlap_generate_rand_time_slot(int S, int s);
258void irlap_initiate_connection_state(struct irlap_cb *);
259void irlap_flush_all_queues(struct irlap_cb *);
260void irlap_wait_min_turn_around(struct irlap_cb *, struct qos_info *);
261
262void irlap_apply_default_connection_parameters(struct irlap_cb *self);
263void irlap_apply_connection_parameters(struct irlap_cb *self, int now);
264
265#define IRLAP_GET_HEADER_SIZE(self) (LAP_MAX_HEADER)
266#define IRLAP_GET_TX_QUEUE_LEN(self) skb_queue_len(&self->txq)
267
268
269
270static inline int irlap_is_primary(struct irlap_cb *self)
271{
272 int ret;
273 switch(self->state) {
274 case LAP_XMIT_P:
275 case LAP_NRM_P:
276 ret = 1;
277 break;
278 case LAP_XMIT_S:
279 case LAP_NRM_S:
280 ret = 0;
281 break;
282 default:
283 ret = -1;
284 }
285 return ret;
286}
287
288
289static inline void irlap_clear_disconnect(struct irlap_cb *self)
290{
291 self->disconnect_pending = FALSE;
292}
293
294
295
296
297
298
299
300static inline void irlap_next_state(struct irlap_cb *self, IRLAP_STATE state)
301{
302
303
304
305
306
307
308 self->state = state;
309}
310
311#endif
312