blob: 38b0f994bc7b60664e8d5409fc375be64cd7eafc [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) {
Joe Perches955a9d202014-11-11 14:44:57 -080047 pr_debug("%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
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 IRDA_ASSERT(self != NULL, return;);
64 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
65 IRDA_ASSERT(skb != NULL, return;);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 frame = skb->data;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 frame[0] = dlsap | CONTROL_BIT;
70 frame[1] = slsap;
71
72 frame[2] = opcode;
73
74 if (opcode == DISCONNECT)
75 frame[3] = 0x01; /* Service user request */
76 else
77 frame[3] = 0x00; /* rsvd */
78
79 irlap_data_request(self->irlap, skb, FALSE);
80}
81
82/*
83 * Function irlmp_input (skb)
84 *
85 * Used by IrLAP to pass received data frames to IrLMP layer
86 *
87 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090088void irlmp_link_data_indication(struct lap_cb *self, struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 int unreliable)
90{
91 struct lsap_cb *lsap;
92 __u8 slsap_sel; /* Source (this) LSAP address */
93 __u8 dlsap_sel; /* Destination LSAP address */
94 __u8 *fp;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 IRDA_ASSERT(self != NULL, return;);
97 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
98 IRDA_ASSERT(skb->len > 2, return;);
99
100 fp = skb->data;
101
102 /*
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900103 * The next statements may be confusing, but we do this so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 * destination LSAP of received frame is source LSAP in our view
105 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900106 slsap_sel = fp[0] & LSAP_MASK;
107 dlsap_sel = fp[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 /*
110 * Check if this is an incoming connection, since we must deal with
111 * it in a different way than other established connections.
112 */
113 if ((fp[0] & CONTROL_BIT) && (fp[2] == CONNECT_CMD)) {
Joe Perches955a9d202014-11-11 14:44:57 -0800114 pr_debug("%s(), incoming connection, source LSAP=%d, dest LSAP=%d\n",
115 __func__, slsap_sel, dlsap_sel);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 /* Try to find LSAP among the unconnected LSAPs */
118 lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, CONNECT_CMD,
119 irlmp->unconnected_lsaps);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 /* Maybe LSAP was already connected, so try one more time */
122 if (!lsap) {
Joe Perches955a9d202014-11-11 14:44:57 -0800123 pr_debug("%s(), incoming connection for LSAP already connected\n",
124 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, 0,
126 self->lsaps);
127 }
128 } else
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900129 lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 self->lsaps);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 if (lsap == NULL) {
Joe Perches955a9d202014-11-11 14:44:57 -0800133 pr_debug("IrLMP, Sorry, no LSAP for received frame!\n");
134 pr_debug("%s(), slsap_sel = %02x, dlsap_sel = %02x\n",
135 __func__, slsap_sel, dlsap_sel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 if (fp[0] & CONTROL_BIT) {
Joe Perches955a9d202014-11-11 14:44:57 -0800137 pr_debug("%s(), received control frame %02x\n",
138 __func__, fp[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 } else {
Joe Perches955a9d202014-11-11 14:44:57 -0800140 pr_debug("%s(), received data frame\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142 return;
143 }
144
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900145 /*
146 * Check if we received a control frame?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 */
148 if (fp[0] & CONTROL_BIT) {
149 switch (fp[2]) {
150 case CONNECT_CMD:
151 lsap->lap = self;
152 irlmp_do_lsap_event(lsap, LM_CONNECT_INDICATION, skb);
153 break;
154 case CONNECT_CNF:
155 irlmp_do_lsap_event(lsap, LM_CONNECT_CONFIRM, skb);
156 break;
157 case DISCONNECT:
Joe Perches955a9d202014-11-11 14:44:57 -0800158 pr_debug("%s(), Disconnect indication!\n",
159 __func__);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900160 irlmp_do_lsap_event(lsap, LM_DISCONNECT_INDICATION,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 skb);
162 break;
163 case ACCESSMODE_CMD:
Joe Perches955a9d202014-11-11 14:44:57 -0800164 pr_debug("Access mode cmd not implemented!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 break;
166 case ACCESSMODE_CNF:
Joe Perches955a9d202014-11-11 14:44:57 -0800167 pr_debug("Access mode cnf not implemented!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 break;
169 default:
Joe Perches955a9d202014-11-11 14:44:57 -0800170 pr_debug("%s(), Unknown control frame %02x\n",
171 __func__, fp[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 break;
173 }
174 } else if (unreliable) {
175 /* Optimize and bypass the state machine if possible */
176 if (lsap->lsap_state == LSAP_DATA_TRANSFER_READY)
177 irlmp_udata_indication(lsap, skb);
178 else
179 irlmp_do_lsap_event(lsap, LM_UDATA_INDICATION, skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900180 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 /* Optimize and bypass the state machine if possible */
182 if (lsap->lsap_state == LSAP_DATA_TRANSFER_READY)
183 irlmp_data_indication(lsap, skb);
184 else
185 irlmp_do_lsap_event(lsap, LM_DATA_INDICATION, skb);
186 }
187}
188
189/*
190 * Function irlmp_link_unitdata_indication (self, skb)
191 *
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900192 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 *
194 */
195#ifdef CONFIG_IRDA_ULTRA
196void irlmp_link_unitdata_indication(struct lap_cb *self, struct sk_buff *skb)
197{
198 struct lsap_cb *lsap;
199 __u8 slsap_sel; /* Source (this) LSAP address */
200 __u8 dlsap_sel; /* Destination LSAP address */
201 __u8 pid; /* Protocol identifier */
202 __u8 *fp;
203 unsigned long flags;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 IRDA_ASSERT(self != NULL, return;);
206 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
207 IRDA_ASSERT(skb->len > 2, return;);
208
209 fp = skb->data;
210
211 /*
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900212 * The next statements may be confusing, but we do this so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 * destination LSAP of received frame is source LSAP in our view
214 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900215 slsap_sel = fp[0] & LSAP_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 dlsap_sel = fp[1];
217 pid = fp[2];
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 if (pid & 0x80) {
Joe Perches955a9d202014-11-11 14:44:57 -0800220 pr_debug("%s(), extension in PID not supp!\n",
221 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 return;
223 }
224
225 /* Check if frame is addressed to the connectionless LSAP */
226 if ((slsap_sel != LSAP_CONNLESS) || (dlsap_sel != LSAP_CONNLESS)) {
Joe Perches955a9d202014-11-11 14:44:57 -0800227 pr_debug("%s(), dropping frame!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return;
229 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 /* Search the connectionless LSAP */
232 spin_lock_irqsave(&irlmp->unconnected_lsaps->hb_spinlock, flags);
233 lsap = (struct lsap_cb *) hashbin_get_first(irlmp->unconnected_lsaps);
234 while (lsap != NULL) {
235 /*
236 * Check if source LSAP and dest LSAP selectors and PID match.
237 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900238 if ((lsap->slsap_sel == slsap_sel) &&
239 (lsap->dlsap_sel == dlsap_sel) &&
240 (lsap->pid == pid))
241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 break;
243 }
244 lsap = (struct lsap_cb *) hashbin_get_next(irlmp->unconnected_lsaps);
245 }
246 spin_unlock_irqrestore(&irlmp->unconnected_lsaps->hb_spinlock, flags);
247
248 if (lsap)
249 irlmp_connless_data_indication(lsap, skb);
250 else {
Joe Perches955a9d202014-11-11 14:44:57 -0800251 pr_debug("%s(), found no matching LSAP!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253}
254#endif /* CONFIG_IRDA_ULTRA */
255
256/*
257 * Function irlmp_link_disconnect_indication (reason, userdata)
258 *
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900259 * IrLAP has disconnected
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 *
261 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900262void irlmp_link_disconnect_indication(struct lap_cb *lap,
263 struct irlap_cb *irlap,
264 LAP_REASON reason,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 struct sk_buff *skb)
266{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 IRDA_ASSERT(lap != NULL, return;);
268 IRDA_ASSERT(lap->magic == LMP_LAP_MAGIC, return;);
269
270 lap->reason = reason;
271 lap->daddr = DEV_ADDR_ANY;
272
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900273 /* FIXME: must do something with the skb if any */
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 /*
276 * Inform station state machine
277 */
278 irlmp_do_lap_event(lap, LM_LAP_DISCONNECT_INDICATION, NULL);
279}
280
281/*
282 * Function irlmp_link_connect_indication (qos)
283 *
284 * Incoming LAP connection!
285 *
286 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900287void irlmp_link_connect_indication(struct lap_cb *self, __u32 saddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 __u32 daddr, struct qos_info *qos,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900289 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 /* Copy QoS settings for this session */
292 self->qos = qos;
293
294 /* Update destination device address */
295 self->daddr = daddr;
296 IRDA_ASSERT(self->saddr == saddr, return;);
297
298 irlmp_do_lap_event(self, LM_LAP_CONNECT_INDICATION, skb);
299}
300
301/*
302 * Function irlmp_link_connect_confirm (qos)
303 *
304 * LAP connection confirmed!
305 *
306 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900307void irlmp_link_connect_confirm(struct lap_cb *self, struct qos_info *qos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 struct sk_buff *skb)
309{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 IRDA_ASSERT(self != NULL, return;);
311 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
312 IRDA_ASSERT(qos != NULL, return;);
313
314 /* Don't need use the skb for now */
315
316 /* Copy QoS settings for this session */
317 self->qos = qos;
318
319 irlmp_do_lap_event(self, LM_LAP_CONNECT_CONFIRM, NULL);
320}
321
322/*
323 * Function irlmp_link_discovery_indication (self, log)
324 *
325 * Device is discovering us
326 *
327 * It's not an answer to our own discoveries, just another device trying
328 * to perform discovery, but we don't want to miss the opportunity
329 * to exploit this information, because :
330 * o We may not actively perform discovery (just passive discovery)
331 * o This type of discovery is much more reliable. In some cases, it
332 * seem that less than 50% of our discoveries get an answer, while
333 * we always get ~100% of these.
334 * o Make faster discovery, statistically divide time of discovery
335 * events by 2 (important for the latency aspect and user feel)
336 * o Even is we do active discovery, the other node might not
337 * answer our discoveries (ex: Palm). The Palm will just perform
338 * one active discovery and connect directly to us.
339 *
340 * However, when both devices discover each other, they might attempt to
341 * connect to each other following the discovery event, and it would create
342 * collisions on the medium (SNRM battle).
343 * The "fix" for that is to disable all connection requests in IrLAP
344 * for 100ms after a discovery indication by setting the media_busy flag.
345 * Previously, we used to postpone the event which was quite ugly. Now
346 * that IrLAP takes care of this problem, just pass the event up...
347 *
348 * Jean II
349 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900350void irlmp_link_discovery_indication(struct lap_cb *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 discovery_t *discovery)
352{
353 IRDA_ASSERT(self != NULL, return;);
354 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
355
356 /* Add to main log, cleanup */
357 irlmp_add_discovery(irlmp->cachelog, discovery);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 /* Just handle it the same way as a discovery confirm,
360 * bypass the LM_LAP state machine (see below) */
361 irlmp_discovery_confirm(irlmp->cachelog, DISCOVERY_PASSIVE);
362}
363
364/*
365 * Function irlmp_link_discovery_confirm (self, log)
366 *
367 * Called by IrLAP with a list of discoveries after the discovery
368 * request has been carried out. A NULL log is received if IrLAP
369 * was unable to carry out the discovery request
370 *
371 */
372void irlmp_link_discovery_confirm(struct lap_cb *self, hashbin_t *log)
373{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 IRDA_ASSERT(self != NULL, return;);
375 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 /* Add to main log, cleanup */
378 irlmp_add_discovery_log(irlmp->cachelog, log);
379
380 /* Propagate event to various LSAPs registered for it.
381 * We bypass the LM_LAP state machine because
382 * 1) We do it regardless of the LM_LAP state
383 * 2) It doesn't affect the LM_LAP state
384 * 3) Faster, slimer, simpler, ...
385 * Jean II */
386 irlmp_discovery_confirm(irlmp->cachelog, DISCOVERY_ACTIVE);
387}
388
389#ifdef CONFIG_IRDA_CACHE_LAST_LSAP
390static inline void irlmp_update_cache(struct lap_cb *lap,
391 struct lsap_cb *lsap)
392{
393 /* Prevent concurrent read to get garbage */
394 lap->cache.valid = FALSE;
395 /* Update cache entry */
396 lap->cache.dlsap_sel = lsap->dlsap_sel;
397 lap->cache.slsap_sel = lsap->slsap_sel;
398 lap->cache.lsap = lsap;
399 lap->cache.valid = TRUE;
400}
401#endif
402
403/*
404 * Function irlmp_find_handle (self, dlsap_sel, slsap_sel, status, queue)
405 *
406 * Find handle associated with destination and source LSAP
407 *
408 * Any IrDA connection (LSAP/TSAP) is uniquely identified by
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900409 * 3 parameters, the local lsap, the remote lsap and the remote address.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 * We may initiate multiple connections to the same remote service
411 * (they will have different local lsap), a remote device may initiate
412 * multiple connections to the same local service (they will have
413 * different remote lsap), or multiple devices may connect to the same
414 * service and may use the same remote lsap (and they will have
415 * different remote address).
416 * So, where is the remote address ? Each LAP connection is made with
417 * a single remote device, so imply a specific remote address.
418 * Jean II
419 */
420static struct lsap_cb *irlmp_find_lsap(struct lap_cb *self, __u8 dlsap_sel,
421 __u8 slsap_sel, int status,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900422 hashbin_t *queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
424 struct lsap_cb *lsap;
425 unsigned long flags;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900426
427 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 * Optimize for the common case. We assume that the last frame
429 * received is in the same connection as the last one, so check in
430 * cache first to avoid the linear search
431 */
432#ifdef CONFIG_IRDA_CACHE_LAST_LSAP
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900433 if ((self->cache.valid) &&
434 (self->cache.slsap_sel == slsap_sel) &&
435 (self->cache.dlsap_sel == dlsap_sel))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 {
Eric Dumazeta02cec22010-09-22 20:43:57 +0000437 return self->cache.lsap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
439#endif
440
441 spin_lock_irqsave(&queue->hb_spinlock, flags);
442
443 lsap = (struct lsap_cb *) hashbin_get_first(queue);
444 while (lsap != NULL) {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900445 /*
446 * If this is an incoming connection, then the destination
447 * LSAP selector may have been specified as LM_ANY so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 * any client can connect. In that case we only need to check
449 * if the source LSAP (in our view!) match!
450 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900451 if ((status == CONNECT_CMD) &&
452 (lsap->slsap_sel == slsap_sel) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 (lsap->dlsap_sel == LSAP_ANY)) {
454 /* This is where the dest lsap sel is set on incoming
455 * lsaps */
456 lsap->dlsap_sel = dlsap_sel;
457 break;
458 }
459 /*
460 * Check if source LSAP and dest LSAP selectors match.
461 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900462 if ((lsap->slsap_sel == slsap_sel) &&
463 (lsap->dlsap_sel == dlsap_sel))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 break;
465
466 lsap = (struct lsap_cb *) hashbin_get_next(queue);
467 }
468#ifdef CONFIG_IRDA_CACHE_LAST_LSAP
469 if(lsap)
470 irlmp_update_cache(self, lsap);
471#endif
472 spin_unlock_irqrestore(&queue->hb_spinlock, flags);
473
474 /* Return what we've found or NULL */
475 return lsap;
476}