blob: 3750884094daf2996b04d89c2de7970cf7247113 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*********************************************************************
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09002 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Filename: irlmp_frame.c
4 * Version: 0.9
5 * Description: IrLMP frame implementation
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Tue Aug 19 02:09:59 1997
9 * Modified at: Mon Dec 13 13:41:12 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>
13 * All Rights Reserved.
14 * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090015 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * the License, or (at your option) any later version.
20 *
Jan Engelhardt96de0e22007-10-19 23:21:04 +020021 * Neither Dag Brattli nor University of Tromsø admit liability nor
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090022 * provide warranty for any of this software. This material is
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 * provided "AS-IS" and at no charge.
24 *
25 ********************************************************************/
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/skbuff.h>
28#include <linux/kernel.h>
29
30#include <net/irda/irda.h>
31#include <net/irda/irlap.h>
32#include <net/irda/timer.h>
33#include <net/irda/irlmp.h>
34#include <net/irda/irlmp_frame.h>
35#include <net/irda/discovery.h>
36
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090037static struct lsap_cb *irlmp_find_lsap(struct lap_cb *self, __u8 dlsap,
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 __u8 slsap, int status, hashbin_t *);
39
40inline void irlmp_send_data_pdu(struct lap_cb *self, __u8 dlsap, __u8 slsap,
41 int expedited, struct sk_buff *skb)
42{
43 skb->data[0] = dlsap;
44 skb->data[1] = slsap;
45
46 if (expedited) {
Harvey Harrison0dc47872008-03-05 20:47:47 -080047 IRDA_DEBUG(4, "%s(), sending expedited data\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 irlap_data_request(self->irlap, skb, TRUE);
49 } else
50 irlap_data_request(self->irlap, skb, FALSE);
51}
52
53/*
54 * Function irlmp_send_lcf_pdu (dlsap, slsap, opcode,skb)
55 *
56 * Send Link Control Frame to IrLAP
57 */
58void irlmp_send_lcf_pdu(struct lap_cb *self, __u8 dlsap, __u8 slsap,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090059 __u8 opcode, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 __u8 *frame;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090062
Harvey Harrison0dc47872008-03-05 20:47:47 -080063 IRDA_DEBUG(2, "%s()\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 IRDA_ASSERT(self != NULL, return;);
66 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
67 IRDA_ASSERT(skb != NULL, return;);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 frame = skb->data;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 frame[0] = dlsap | CONTROL_BIT;
72 frame[1] = slsap;
73
74 frame[2] = opcode;
75
76 if (opcode == DISCONNECT)
77 frame[3] = 0x01; /* Service user request */
78 else
79 frame[3] = 0x00; /* rsvd */
80
81 irlap_data_request(self->irlap, skb, FALSE);
82}
83
84/*
85 * Function irlmp_input (skb)
86 *
87 * Used by IrLAP to pass received data frames to IrLMP layer
88 *
89 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090090void irlmp_link_data_indication(struct lap_cb *self, struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 int unreliable)
92{
93 struct lsap_cb *lsap;
94 __u8 slsap_sel; /* Source (this) LSAP address */
95 __u8 dlsap_sel; /* Destination LSAP address */
96 __u8 *fp;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090097
Harvey Harrison0dc47872008-03-05 20:47:47 -080098 IRDA_DEBUG(4, "%s()\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 IRDA_ASSERT(self != NULL, return;);
101 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
102 IRDA_ASSERT(skb->len > 2, return;);
103
104 fp = skb->data;
105
106 /*
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900107 * The next statements may be confusing, but we do this so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * destination LSAP of received frame is source LSAP in our view
109 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900110 slsap_sel = fp[0] & LSAP_MASK;
111 dlsap_sel = fp[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 /*
114 * Check if this is an incoming connection, since we must deal with
115 * it in a different way than other established connections.
116 */
117 if ((fp[0] & CONTROL_BIT) && (fp[2] == CONNECT_CMD)) {
118 IRDA_DEBUG(3, "%s(), incoming connection, "
119 "source LSAP=%d, dest LSAP=%d\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800120 __func__, slsap_sel, dlsap_sel);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 /* Try to find LSAP among the unconnected LSAPs */
123 lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, CONNECT_CMD,
124 irlmp->unconnected_lsaps);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 /* Maybe LSAP was already connected, so try one more time */
127 if (!lsap) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800128 IRDA_DEBUG(1, "%s(), incoming connection for LSAP already connected\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, 0,
130 self->lsaps);
131 }
132 } else
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900133 lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 self->lsaps);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 if (lsap == NULL) {
137 IRDA_DEBUG(2, "IrLMP, Sorry, no LSAP for received frame!\n");
138 IRDA_DEBUG(2, "%s(), slsap_sel = %02x, dlsap_sel = %02x\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800139 __func__, slsap_sel, dlsap_sel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (fp[0] & CONTROL_BIT) {
141 IRDA_DEBUG(2, "%s(), received control frame %02x\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800142 __func__, fp[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 } else {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800144 IRDA_DEBUG(2, "%s(), received data frame\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
146 return;
147 }
148
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900149 /*
150 * Check if we received a control frame?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 */
152 if (fp[0] & CONTROL_BIT) {
153 switch (fp[2]) {
154 case CONNECT_CMD:
155 lsap->lap = self;
156 irlmp_do_lsap_event(lsap, LM_CONNECT_INDICATION, skb);
157 break;
158 case CONNECT_CNF:
159 irlmp_do_lsap_event(lsap, LM_CONNECT_CONFIRM, skb);
160 break;
161 case DISCONNECT:
162 IRDA_DEBUG(4, "%s(), Disconnect indication!\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800163 __func__);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900164 irlmp_do_lsap_event(lsap, LM_DISCONNECT_INDICATION,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 skb);
166 break;
167 case ACCESSMODE_CMD:
168 IRDA_DEBUG(0, "Access mode cmd not implemented!\n");
169 break;
170 case ACCESSMODE_CNF:
171 IRDA_DEBUG(0, "Access mode cnf not implemented!\n");
172 break;
173 default:
174 IRDA_DEBUG(0, "%s(), Unknown control frame %02x\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800175 __func__, fp[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 break;
177 }
178 } else if (unreliable) {
179 /* Optimize and bypass the state machine if possible */
180 if (lsap->lsap_state == LSAP_DATA_TRANSFER_READY)
181 irlmp_udata_indication(lsap, skb);
182 else
183 irlmp_do_lsap_event(lsap, LM_UDATA_INDICATION, skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900184 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 /* Optimize and bypass the state machine if possible */
186 if (lsap->lsap_state == LSAP_DATA_TRANSFER_READY)
187 irlmp_data_indication(lsap, skb);
188 else
189 irlmp_do_lsap_event(lsap, LM_DATA_INDICATION, skb);
190 }
191}
192
193/*
194 * Function irlmp_link_unitdata_indication (self, skb)
195 *
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900196 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 *
198 */
199#ifdef CONFIG_IRDA_ULTRA
200void irlmp_link_unitdata_indication(struct lap_cb *self, struct sk_buff *skb)
201{
202 struct lsap_cb *lsap;
203 __u8 slsap_sel; /* Source (this) LSAP address */
204 __u8 dlsap_sel; /* Destination LSAP address */
205 __u8 pid; /* Protocol identifier */
206 __u8 *fp;
207 unsigned long flags;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900208
Harvey Harrison0dc47872008-03-05 20:47:47 -0800209 IRDA_DEBUG(4, "%s()\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 IRDA_ASSERT(self != NULL, return;);
212 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
213 IRDA_ASSERT(skb->len > 2, return;);
214
215 fp = skb->data;
216
217 /*
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900218 * The next statements may be confusing, but we do this so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 * destination LSAP of received frame is source LSAP in our view
220 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900221 slsap_sel = fp[0] & LSAP_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 dlsap_sel = fp[1];
223 pid = fp[2];
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 if (pid & 0x80) {
226 IRDA_DEBUG(0, "%s(), extension in PID not supp!\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800227 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return;
229 }
230
231 /* Check if frame is addressed to the connectionless LSAP */
232 if ((slsap_sel != LSAP_CONNLESS) || (dlsap_sel != LSAP_CONNLESS)) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800233 IRDA_DEBUG(0, "%s(), dropping frame!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return;
235 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 /* Search the connectionless LSAP */
238 spin_lock_irqsave(&irlmp->unconnected_lsaps->hb_spinlock, flags);
239 lsap = (struct lsap_cb *) hashbin_get_first(irlmp->unconnected_lsaps);
240 while (lsap != NULL) {
241 /*
242 * Check if source LSAP and dest LSAP selectors and PID match.
243 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900244 if ((lsap->slsap_sel == slsap_sel) &&
245 (lsap->dlsap_sel == dlsap_sel) &&
246 (lsap->pid == pid))
247 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 break;
249 }
250 lsap = (struct lsap_cb *) hashbin_get_next(irlmp->unconnected_lsaps);
251 }
252 spin_unlock_irqrestore(&irlmp->unconnected_lsaps->hb_spinlock, flags);
253
254 if (lsap)
255 irlmp_connless_data_indication(lsap, skb);
256 else {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800257 IRDA_DEBUG(0, "%s(), found no matching LSAP!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
259}
260#endif /* CONFIG_IRDA_ULTRA */
261
262/*
263 * Function irlmp_link_disconnect_indication (reason, userdata)
264 *
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900265 * IrLAP has disconnected
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 *
267 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900268void irlmp_link_disconnect_indication(struct lap_cb *lap,
269 struct irlap_cb *irlap,
270 LAP_REASON reason,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 struct sk_buff *skb)
272{
Harvey Harrison0dc47872008-03-05 20:47:47 -0800273 IRDA_DEBUG(2, "%s()\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275 IRDA_ASSERT(lap != NULL, return;);
276 IRDA_ASSERT(lap->magic == LMP_LAP_MAGIC, return;);
277
278 lap->reason = reason;
279 lap->daddr = DEV_ADDR_ANY;
280
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900281 /* FIXME: must do something with the skb if any */
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 /*
284 * Inform station state machine
285 */
286 irlmp_do_lap_event(lap, LM_LAP_DISCONNECT_INDICATION, NULL);
287}
288
289/*
290 * Function irlmp_link_connect_indication (qos)
291 *
292 * Incoming LAP connection!
293 *
294 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900295void irlmp_link_connect_indication(struct lap_cb *self, __u32 saddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 __u32 daddr, struct qos_info *qos,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900297 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Harvey Harrison0dc47872008-03-05 20:47:47 -0800299 IRDA_DEBUG(4, "%s()\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 /* Copy QoS settings for this session */
302 self->qos = qos;
303
304 /* Update destination device address */
305 self->daddr = daddr;
306 IRDA_ASSERT(self->saddr == saddr, return;);
307
308 irlmp_do_lap_event(self, LM_LAP_CONNECT_INDICATION, skb);
309}
310
311/*
312 * Function irlmp_link_connect_confirm (qos)
313 *
314 * LAP connection confirmed!
315 *
316 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900317void irlmp_link_connect_confirm(struct lap_cb *self, struct qos_info *qos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 struct sk_buff *skb)
319{
Harvey Harrison0dc47872008-03-05 20:47:47 -0800320 IRDA_DEBUG(4, "%s()\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 IRDA_ASSERT(self != NULL, return;);
323 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
324 IRDA_ASSERT(qos != NULL, return;);
325
326 /* Don't need use the skb for now */
327
328 /* Copy QoS settings for this session */
329 self->qos = qos;
330
331 irlmp_do_lap_event(self, LM_LAP_CONNECT_CONFIRM, NULL);
332}
333
334/*
335 * Function irlmp_link_discovery_indication (self, log)
336 *
337 * Device is discovering us
338 *
339 * It's not an answer to our own discoveries, just another device trying
340 * to perform discovery, but we don't want to miss the opportunity
341 * to exploit this information, because :
342 * o We may not actively perform discovery (just passive discovery)
343 * o This type of discovery is much more reliable. In some cases, it
344 * seem that less than 50% of our discoveries get an answer, while
345 * we always get ~100% of these.
346 * o Make faster discovery, statistically divide time of discovery
347 * events by 2 (important for the latency aspect and user feel)
348 * o Even is we do active discovery, the other node might not
349 * answer our discoveries (ex: Palm). The Palm will just perform
350 * one active discovery and connect directly to us.
351 *
352 * However, when both devices discover each other, they might attempt to
353 * connect to each other following the discovery event, and it would create
354 * collisions on the medium (SNRM battle).
355 * The "fix" for that is to disable all connection requests in IrLAP
356 * for 100ms after a discovery indication by setting the media_busy flag.
357 * Previously, we used to postpone the event which was quite ugly. Now
358 * that IrLAP takes care of this problem, just pass the event up...
359 *
360 * Jean II
361 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900362void irlmp_link_discovery_indication(struct lap_cb *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 discovery_t *discovery)
364{
365 IRDA_ASSERT(self != NULL, return;);
366 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
367
368 /* Add to main log, cleanup */
369 irlmp_add_discovery(irlmp->cachelog, discovery);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* Just handle it the same way as a discovery confirm,
372 * bypass the LM_LAP state machine (see below) */
373 irlmp_discovery_confirm(irlmp->cachelog, DISCOVERY_PASSIVE);
374}
375
376/*
377 * Function irlmp_link_discovery_confirm (self, log)
378 *
379 * Called by IrLAP with a list of discoveries after the discovery
380 * request has been carried out. A NULL log is received if IrLAP
381 * was unable to carry out the discovery request
382 *
383 */
384void irlmp_link_discovery_confirm(struct lap_cb *self, hashbin_t *log)
385{
Harvey Harrison0dc47872008-03-05 20:47:47 -0800386 IRDA_DEBUG(4, "%s()\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 IRDA_ASSERT(self != NULL, return;);
389 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 /* Add to main log, cleanup */
392 irlmp_add_discovery_log(irlmp->cachelog, log);
393
394 /* Propagate event to various LSAPs registered for it.
395 * We bypass the LM_LAP state machine because
396 * 1) We do it regardless of the LM_LAP state
397 * 2) It doesn't affect the LM_LAP state
398 * 3) Faster, slimer, simpler, ...
399 * Jean II */
400 irlmp_discovery_confirm(irlmp->cachelog, DISCOVERY_ACTIVE);
401}
402
403#ifdef CONFIG_IRDA_CACHE_LAST_LSAP
404static inline void irlmp_update_cache(struct lap_cb *lap,
405 struct lsap_cb *lsap)
406{
407 /* Prevent concurrent read to get garbage */
408 lap->cache.valid = FALSE;
409 /* Update cache entry */
410 lap->cache.dlsap_sel = lsap->dlsap_sel;
411 lap->cache.slsap_sel = lsap->slsap_sel;
412 lap->cache.lsap = lsap;
413 lap->cache.valid = TRUE;
414}
415#endif
416
417/*
418 * Function irlmp_find_handle (self, dlsap_sel, slsap_sel, status, queue)
419 *
420 * Find handle associated with destination and source LSAP
421 *
422 * Any IrDA connection (LSAP/TSAP) is uniquely identified by
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900423 * 3 parameters, the local lsap, the remote lsap and the remote address.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 * We may initiate multiple connections to the same remote service
425 * (they will have different local lsap), a remote device may initiate
426 * multiple connections to the same local service (they will have
427 * different remote lsap), or multiple devices may connect to the same
428 * service and may use the same remote lsap (and they will have
429 * different remote address).
430 * So, where is the remote address ? Each LAP connection is made with
431 * a single remote device, so imply a specific remote address.
432 * Jean II
433 */
434static struct lsap_cb *irlmp_find_lsap(struct lap_cb *self, __u8 dlsap_sel,
435 __u8 slsap_sel, int status,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900436 hashbin_t *queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 struct lsap_cb *lsap;
439 unsigned long flags;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900440
441 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 * Optimize for the common case. We assume that the last frame
443 * received is in the same connection as the last one, so check in
444 * cache first to avoid the linear search
445 */
446#ifdef CONFIG_IRDA_CACHE_LAST_LSAP
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900447 if ((self->cache.valid) &&
448 (self->cache.slsap_sel == slsap_sel) &&
449 (self->cache.dlsap_sel == dlsap_sel))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 {
451 return (self->cache.lsap);
452 }
453#endif
454
455 spin_lock_irqsave(&queue->hb_spinlock, flags);
456
457 lsap = (struct lsap_cb *) hashbin_get_first(queue);
458 while (lsap != NULL) {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900459 /*
460 * If this is an incoming connection, then the destination
461 * LSAP selector may have been specified as LM_ANY so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 * any client can connect. In that case we only need to check
463 * if the source LSAP (in our view!) match!
464 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900465 if ((status == CONNECT_CMD) &&
466 (lsap->slsap_sel == slsap_sel) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 (lsap->dlsap_sel == LSAP_ANY)) {
468 /* This is where the dest lsap sel is set on incoming
469 * lsaps */
470 lsap->dlsap_sel = dlsap_sel;
471 break;
472 }
473 /*
474 * Check if source LSAP and dest LSAP selectors match.
475 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900476 if ((lsap->slsap_sel == slsap_sel) &&
477 (lsap->dlsap_sel == dlsap_sel))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 break;
479
480 lsap = (struct lsap_cb *) hashbin_get_next(queue);
481 }
482#ifdef CONFIG_IRDA_CACHE_LAST_LSAP
483 if(lsap)
484 irlmp_update_cache(self, lsap);
485#endif
486 spin_unlock_irqrestore(&queue->hb_spinlock, flags);
487
488 /* Return what we've found or NULL */
489 return lsap;
490}