diff options
Diffstat (limited to 'include/net/irda/irlap.h')
-rw-r--r-- | include/net/irda/irlap.h | 290 |
1 files changed, 290 insertions, 0 deletions
diff --git a/include/net/irda/irlap.h b/include/net/irda/irlap.h new file mode 100644 index 000000000000..f55e86e75030 --- /dev/null +++ b/include/net/irda/irlap.h | |||
@@ -0,0 +1,290 @@ | |||
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-2002 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/irqueue.h> /* irda_queue_t */ | ||
37 | #include <net/irda/qos.h> /* struct qos_info */ | ||
38 | #include <net/irda/discovery.h> /* discovery_t */ | ||
39 | #include <net/irda/irlap_event.h> /* IRLAP_STATE, ... */ | ||
40 | #include <net/irda/irmod.h> /* struct notify_t */ | ||
41 | |||
42 | #define CONFIG_IRDA_DYNAMIC_WINDOW 1 | ||
43 | |||
44 | #define LAP_RELIABLE 1 | ||
45 | #define LAP_UNRELIABLE 0 | ||
46 | |||
47 | #define LAP_ADDR_HEADER 1 /* IrLAP Address Header */ | ||
48 | #define LAP_CTRL_HEADER 1 /* IrLAP Control Header */ | ||
49 | |||
50 | /* May be different when we get VFIR */ | ||
51 | #define LAP_MAX_HEADER (LAP_ADDR_HEADER + LAP_CTRL_HEADER) | ||
52 | |||
53 | #define BROADCAST 0xffffffff /* Broadcast device address */ | ||
54 | #define CBROADCAST 0xfe /* Connection broadcast address */ | ||
55 | #define XID_FORMAT 0x01 /* Discovery XID format */ | ||
56 | |||
57 | /* Nobody seems to use this constant. */ | ||
58 | #define LAP_WINDOW_SIZE 8 | ||
59 | /* We keep the LAP queue very small to minimise the amount of buffering. | ||
60 | * this improve latency and reduce resource consumption. | ||
61 | * This work only because we have synchronous refilling of IrLAP through | ||
62 | * the flow control mechanism (via scheduler and IrTTP). | ||
63 | * 2 buffers is the minimum we can work with, one that we send while polling | ||
64 | * IrTTP, and another to know that we should not send the pf bit. | ||
65 | * Jean II */ | ||
66 | #define LAP_HIGH_THRESHOLD 2 | ||
67 | /* Some rare non TTP clients don't implement flow control, and | ||
68 | * so don't comply with the above limit (and neither with this one). | ||
69 | * For IAP and management, it doesn't matter, because they never transmit much. | ||
70 | *.For IrLPT, this should be fixed. | ||
71 | * - Jean II */ | ||
72 | #define LAP_MAX_QUEUE 10 | ||
73 | /* Please note that all IrDA management frames (LMP/TTP conn req/disc and | ||
74 | * IAS queries) fall in the second category and are sent to LAP even if TTP | ||
75 | * is stopped. This means that those frames will wait only a maximum of | ||
76 | * two (2) data frames before beeing sent on the "wire", which speed up | ||
77 | * new socket setup when the link is saturated. | ||
78 | * Same story for two sockets competing for the medium : if one saturates | ||
79 | * the LAP, when the other want to transmit it only has to wait for | ||
80 | * maximum three (3) packets (2 + one scheduling), which improve performance | ||
81 | * of delay sensitive applications. | ||
82 | * Jean II */ | ||
83 | |||
84 | #define NR_EXPECTED 1 | ||
85 | #define NR_UNEXPECTED 0 | ||
86 | #define NR_INVALID -1 | ||
87 | |||
88 | #define NS_EXPECTED 1 | ||
89 | #define NS_UNEXPECTED 0 | ||
90 | #define NS_INVALID -1 | ||
91 | |||
92 | /* | ||
93 | * Meta information passed within the IrLAP state machine | ||
94 | */ | ||
95 | struct irlap_info { | ||
96 | __u8 caddr; /* Connection address */ | ||
97 | __u8 control; /* Frame type */ | ||
98 | __u8 cmd; | ||
99 | |||
100 | __u32 saddr; | ||
101 | __u32 daddr; | ||
102 | |||
103 | int pf; /* Poll/final bit set */ | ||
104 | |||
105 | __u8 nr; /* Sequence number of next frame expected */ | ||
106 | __u8 ns; /* Sequence number of frame sent */ | ||
107 | |||
108 | int S; /* Number of slots */ | ||
109 | int slot; /* Random chosen slot */ | ||
110 | int s; /* Current slot */ | ||
111 | |||
112 | discovery_t *discovery; /* Discovery information */ | ||
113 | }; | ||
114 | |||
115 | /* Main structure of IrLAP */ | ||
116 | struct irlap_cb { | ||
117 | irda_queue_t q; /* Must be first */ | ||
118 | magic_t magic; | ||
119 | |||
120 | /* Device we are attached to */ | ||
121 | struct net_device *netdev; | ||
122 | char hw_name[2*IFNAMSIZ + 1]; | ||
123 | |||
124 | /* Connection state */ | ||
125 | volatile IRLAP_STATE state; /* Current state */ | ||
126 | |||
127 | /* Timers used by IrLAP */ | ||
128 | struct timer_list query_timer; | ||
129 | struct timer_list slot_timer; | ||
130 | struct timer_list discovery_timer; | ||
131 | struct timer_list final_timer; | ||
132 | struct timer_list poll_timer; | ||
133 | struct timer_list wd_timer; | ||
134 | struct timer_list backoff_timer; | ||
135 | |||
136 | /* Media busy stuff */ | ||
137 | struct timer_list media_busy_timer; | ||
138 | int media_busy; | ||
139 | |||
140 | /* Timeouts which will be different with different turn time */ | ||
141 | int slot_timeout; | ||
142 | int poll_timeout; | ||
143 | int final_timeout; | ||
144 | int wd_timeout; | ||
145 | |||
146 | struct sk_buff_head txq; /* Frames to be transmitted */ | ||
147 | struct sk_buff_head txq_ultra; | ||
148 | |||
149 | __u8 caddr; /* Connection address */ | ||
150 | __u32 saddr; /* Source device address */ | ||
151 | __u32 daddr; /* Destination device address */ | ||
152 | |||
153 | int retry_count; /* Times tried to establish connection */ | ||
154 | int add_wait; /* True if we are waiting for frame */ | ||
155 | |||
156 | __u8 connect_pending; | ||
157 | __u8 disconnect_pending; | ||
158 | |||
159 | /* To send a faster RR if tx queue empty */ | ||
160 | #ifdef CONFIG_IRDA_FAST_RR | ||
161 | int fast_RR_timeout; | ||
162 | int fast_RR; | ||
163 | #endif /* CONFIG_IRDA_FAST_RR */ | ||
164 | |||
165 | int N1; /* N1 * F-timer = Negitiated link disconnect warning threshold */ | ||
166 | int N2; /* N2 * F-timer = Negitiated link disconnect time */ | ||
167 | int N3; /* Connection retry count */ | ||
168 | |||
169 | int local_busy; | ||
170 | int remote_busy; | ||
171 | int xmitflag; | ||
172 | |||
173 | __u8 vs; /* Next frame to be sent */ | ||
174 | __u8 vr; /* Next frame to be received */ | ||
175 | __u8 va; /* Last frame acked */ | ||
176 | int window; /* Nr of I-frames allowed to send */ | ||
177 | int window_size; /* Current negotiated window size */ | ||
178 | |||
179 | #ifdef CONFIG_IRDA_DYNAMIC_WINDOW | ||
180 | __u32 line_capacity; /* Number of bytes allowed to send */ | ||
181 | __u32 bytes_left; /* Number of bytes still allowed to transmit */ | ||
182 | #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */ | ||
183 | |||
184 | struct sk_buff_head wx_list; | ||
185 | |||
186 | __u8 ack_required; | ||
187 | |||
188 | /* XID parameters */ | ||
189 | __u8 S; /* Number of slots */ | ||
190 | __u8 slot; /* Random chosen slot */ | ||
191 | __u8 s; /* Current slot */ | ||
192 | int frame_sent; /* Have we sent reply? */ | ||
193 | |||
194 | hashbin_t *discovery_log; | ||
195 | discovery_t *discovery_cmd; | ||
196 | |||
197 | __u32 speed; /* Link speed */ | ||
198 | |||
199 | struct qos_info qos_tx; /* QoS requested by peer */ | ||
200 | struct qos_info qos_rx; /* QoS requested by self */ | ||
201 | struct qos_info *qos_dev; /* QoS supported by device */ | ||
202 | |||
203 | notify_t notify; /* Callbacks to IrLMP */ | ||
204 | |||
205 | int mtt_required; /* Minumum turnaround time required */ | ||
206 | int xbofs_delay; /* Nr of XBOF's used to MTT */ | ||
207 | int bofs_count; /* Negotiated extra BOFs */ | ||
208 | int next_bofs; /* Negotiated extra BOFs after next frame */ | ||
209 | }; | ||
210 | |||
211 | /* | ||
212 | * Function prototypes | ||
213 | */ | ||
214 | int irlap_init(void); | ||
215 | void irlap_cleanup(void); | ||
216 | |||
217 | struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos, | ||
218 | const char *hw_name); | ||
219 | void irlap_close(struct irlap_cb *self); | ||
220 | |||
221 | void irlap_connect_request(struct irlap_cb *self, __u32 daddr, | ||
222 | struct qos_info *qos, int sniff); | ||
223 | void irlap_connect_response(struct irlap_cb *self, struct sk_buff *skb); | ||
224 | void irlap_connect_indication(struct irlap_cb *self, struct sk_buff *skb); | ||
225 | void irlap_connect_confirm(struct irlap_cb *, struct sk_buff *skb); | ||
226 | |||
227 | void irlap_data_indication(struct irlap_cb *, struct sk_buff *, int unreliable); | ||
228 | void irlap_data_request(struct irlap_cb *, struct sk_buff *, int unreliable); | ||
229 | |||
230 | #ifdef CONFIG_IRDA_ULTRA | ||
231 | void irlap_unitdata_request(struct irlap_cb *, struct sk_buff *); | ||
232 | void irlap_unitdata_indication(struct irlap_cb *, struct sk_buff *); | ||
233 | #endif /* CONFIG_IRDA_ULTRA */ | ||
234 | |||
235 | void irlap_disconnect_request(struct irlap_cb *); | ||
236 | void irlap_disconnect_indication(struct irlap_cb *, LAP_REASON reason); | ||
237 | |||
238 | void irlap_status_indication(struct irlap_cb *, int quality_of_link); | ||
239 | |||
240 | void irlap_test_request(__u8 *info, int len); | ||
241 | |||
242 | void irlap_discovery_request(struct irlap_cb *, discovery_t *discovery); | ||
243 | void irlap_discovery_confirm(struct irlap_cb *, hashbin_t *discovery_log); | ||
244 | void irlap_discovery_indication(struct irlap_cb *, discovery_t *discovery); | ||
245 | |||
246 | void irlap_reset_indication(struct irlap_cb *self); | ||
247 | void irlap_reset_confirm(void); | ||
248 | |||
249 | void irlap_update_nr_received(struct irlap_cb *, int nr); | ||
250 | int irlap_validate_nr_received(struct irlap_cb *, int nr); | ||
251 | int irlap_validate_ns_received(struct irlap_cb *, int ns); | ||
252 | |||
253 | int irlap_generate_rand_time_slot(int S, int s); | ||
254 | void irlap_initiate_connection_state(struct irlap_cb *); | ||
255 | void irlap_flush_all_queues(struct irlap_cb *); | ||
256 | void irlap_wait_min_turn_around(struct irlap_cb *, struct qos_info *); | ||
257 | |||
258 | void irlap_apply_default_connection_parameters(struct irlap_cb *self); | ||
259 | void irlap_apply_connection_parameters(struct irlap_cb *self, int now); | ||
260 | |||
261 | #define IRLAP_GET_HEADER_SIZE(self) (LAP_MAX_HEADER) | ||
262 | #define IRLAP_GET_TX_QUEUE_LEN(self) skb_queue_len(&self->txq) | ||
263 | |||
264 | /* Return TRUE if the node is in primary mode (i.e. master) | ||
265 | * - Jean II */ | ||
266 | static inline int irlap_is_primary(struct irlap_cb *self) | ||
267 | { | ||
268 | int ret; | ||
269 | switch(self->state) { | ||
270 | case LAP_XMIT_P: | ||
271 | case LAP_NRM_P: | ||
272 | ret = 1; | ||
273 | break; | ||
274 | case LAP_XMIT_S: | ||
275 | case LAP_NRM_S: | ||
276 | ret = 0; | ||
277 | break; | ||
278 | default: | ||
279 | ret = -1; | ||
280 | } | ||
281 | return(ret); | ||
282 | } | ||
283 | |||
284 | /* Clear a pending IrLAP disconnect. - Jean II */ | ||
285 | static inline void irlap_clear_disconnect(struct irlap_cb *self) | ||
286 | { | ||
287 | self->disconnect_pending = FALSE; | ||
288 | } | ||
289 | |||
290 | #endif | ||