Blame view

net/irda/irlmp_frame.c 13.7 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*********************************************************************
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
2
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
6
7
8
9
10
   * Filename:      irlmp_frame.c
   * Version:       0.9
   * Description:   IrLMP frame implementation
   * Status:        Experimental.
   * Author:        Dag Brattli <dagb@cs.uit.no>
   * Created at:    Tue Aug 19 02:09:59 1997
   * Modified at:   Mon Dec 13 13:41:12 1999
   * Modified by:   Dag Brattli <dagb@cs.uit.no>
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
11
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12
13
14
   *     Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>
   *     All Rights Reserved.
   *     Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
15
16
17
18
   *
   *     This program is free software; you can redistribute it and/or
   *     modify it under the terms of the GNU General Public License as
   *     published by the Free Software Foundation; either version 2 of
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
   *     the License, or (at your option) any later version.
   *
96de0e252   Jan Engelhardt   Convert files to ...
21
   *     Neither Dag Brattli nor University of Tromsø admit liability nor
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
22
   *     provide warranty for any of this software. This material is
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
   *     provided "AS-IS" and at no charge.
   *
   ********************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
27
28
29
30
31
32
33
34
  #include <linux/skbuff.h>
  #include <linux/kernel.h>
  
  #include <net/irda/irda.h>
  #include <net/irda/irlap.h>
  #include <net/irda/timer.h>
  #include <net/irda/irlmp.h>
  #include <net/irda/irlmp_frame.h>
  #include <net/irda/discovery.h>
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
35
  static struct lsap_cb *irlmp_find_lsap(struct lap_cb *self, __u8 dlsap,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
39
40
41
42
43
44
  				       __u8 slsap, int status, hashbin_t *);
  
  inline void irlmp_send_data_pdu(struct lap_cb *self, __u8 dlsap, __u8 slsap,
  				int expedited, struct sk_buff *skb)
  {
  	skb->data[0] = dlsap;
  	skb->data[1] = slsap;
  
  	if (expedited) {
955a9d202   Joe Perches   irda: Convert IRD...
45
46
  		pr_debug("%s(), sending expedited data
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
48
49
50
51
52
53
54
55
56
57
  		irlap_data_request(self->irlap, skb, TRUE);
  	} else
  		irlap_data_request(self->irlap, skb, FALSE);
  }
  
  /*
   * Function irlmp_send_lcf_pdu (dlsap, slsap, opcode,skb)
   *
   *    Send Link Control Frame to IrLAP
   */
  void irlmp_send_lcf_pdu(struct lap_cb *self, __u8 dlsap, __u8 slsap,
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
58
  			__u8 opcode, struct sk_buff *skb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
  {
  	__u8 *frame;
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
61

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
64
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
  	IRDA_ASSERT(skb != NULL, return;);
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
65

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
  	frame = skb->data;
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
67

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  	frame[0] = dlsap | CONTROL_BIT;
  	frame[1] = slsap;
  
  	frame[2] = opcode;
  
  	if (opcode == DISCONNECT)
  		frame[3] = 0x01; /* Service user request */
  	else
  		frame[3] = 0x00; /* rsvd */
  
  	irlap_data_request(self->irlap, skb, FALSE);
  }
  
  /*
   * Function irlmp_input (skb)
   *
   *    Used by IrLAP to pass received data frames to IrLMP layer
   *
   */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
87
  void irlmp_link_data_indication(struct lap_cb *self, struct sk_buff *skb,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
89
90
91
92
93
  				int unreliable)
  {
  	struct lsap_cb *lsap;
  	__u8   slsap_sel;   /* Source (this) LSAP address */
  	__u8   dlsap_sel;   /* Destination LSAP address */
  	__u8   *fp;
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
94

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
96
97
98
99
100
101
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
  	IRDA_ASSERT(skb->len > 2, return;);
  
  	fp = skb->data;
  
  	/*
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
102
  	 *  The next statements may be confusing, but we do this so that
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
  	 *  destination LSAP of received frame is source LSAP in our view
  	 */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
105
106
  	slsap_sel = fp[0] & LSAP_MASK;
  	dlsap_sel = fp[1];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
108
109
110
111
112
  
  	/*
  	 *  Check if this is an incoming connection, since we must deal with
  	 *  it in a different way than other established connections.
  	 */
  	if ((fp[0] & CONTROL_BIT) && (fp[2] == CONNECT_CMD)) {
955a9d202   Joe Perches   irda: Convert IRD...
113
114
115
  		pr_debug("%s(), incoming connection, source LSAP=%d, dest LSAP=%d
  ",
  			 __func__, slsap_sel, dlsap_sel);
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
116

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
119
  		/* Try to find LSAP among the unconnected LSAPs */
  		lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, CONNECT_CMD,
  				       irlmp->unconnected_lsaps);
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
120

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
122
  		/* Maybe LSAP was already connected, so try one more time */
  		if (!lsap) {
955a9d202   Joe Perches   irda: Convert IRD...
123
124
125
  			pr_debug("%s(), incoming connection for LSAP already connected
  ",
  				 __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
127
128
129
  			lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, 0,
  					       self->lsaps);
  		}
  	} else
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
130
  		lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, 0,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
  				       self->lsaps);
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
132

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133
  	if (lsap == NULL) {
955a9d202   Joe Perches   irda: Convert IRD...
134
135
136
137
138
  		pr_debug("IrLMP, Sorry, no LSAP for received frame!
  ");
  		pr_debug("%s(), slsap_sel = %02x, dlsap_sel = %02x
  ",
  			 __func__, slsap_sel, dlsap_sel);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139
  		if (fp[0] & CONTROL_BIT) {
955a9d202   Joe Perches   irda: Convert IRD...
140
141
142
  			pr_debug("%s(), received control frame %02x
  ",
  				 __func__, fp[2]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
143
  		} else {
955a9d202   Joe Perches   irda: Convert IRD...
144
145
  			pr_debug("%s(), received data frame
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146
147
148
  		}
  		return;
  	}
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
149
150
  	/*
  	 *  Check if we received a control frame?
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
151
152
153
154
155
156
157
158
159
160
161
  	 */
  	if (fp[0] & CONTROL_BIT) {
  		switch (fp[2]) {
  		case CONNECT_CMD:
  			lsap->lap = self;
  			irlmp_do_lsap_event(lsap, LM_CONNECT_INDICATION, skb);
  			break;
  		case CONNECT_CNF:
  			irlmp_do_lsap_event(lsap, LM_CONNECT_CONFIRM, skb);
  			break;
  		case DISCONNECT:
955a9d202   Joe Perches   irda: Convert IRD...
162
163
164
  			pr_debug("%s(), Disconnect indication!
  ",
  				 __func__);
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
165
  			irlmp_do_lsap_event(lsap, LM_DISCONNECT_INDICATION,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
166
167
168
  					    skb);
  			break;
  		case ACCESSMODE_CMD:
955a9d202   Joe Perches   irda: Convert IRD...
169
170
  			pr_debug("Access mode cmd not implemented!
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
172
  			break;
  		case ACCESSMODE_CNF:
955a9d202   Joe Perches   irda: Convert IRD...
173
174
  			pr_debug("Access mode cnf not implemented!
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175
176
  			break;
  		default:
955a9d202   Joe Perches   irda: Convert IRD...
177
178
179
  			pr_debug("%s(), Unknown control frame %02x
  ",
  				 __func__, fp[2]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
181
182
183
184
185
186
187
  			break;
  		}
  	} else if (unreliable) {
  		/* Optimize and bypass the state machine if possible */
  		if (lsap->lsap_state == LSAP_DATA_TRANSFER_READY)
  			irlmp_udata_indication(lsap, skb);
  		else
  			irlmp_do_lsap_event(lsap, LM_UDATA_INDICATION, skb);
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
188
  	} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
190
191
192
193
194
195
196
197
198
199
  		/* Optimize and bypass the state machine if possible */
  		if (lsap->lsap_state == LSAP_DATA_TRANSFER_READY)
  			irlmp_data_indication(lsap, skb);
  		else
  			irlmp_do_lsap_event(lsap, LM_DATA_INDICATION, skb);
  	}
  }
  
  /*
   * Function irlmp_link_unitdata_indication (self, skb)
   *
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
200
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
201
202
203
204
205
206
207
208
209
210
211
   *
   */
  #ifdef CONFIG_IRDA_ULTRA
  void irlmp_link_unitdata_indication(struct lap_cb *self, struct sk_buff *skb)
  {
  	struct lsap_cb *lsap;
  	__u8   slsap_sel;   /* Source (this) LSAP address */
  	__u8   dlsap_sel;   /* Destination LSAP address */
  	__u8   pid;         /* Protocol identifier */
  	__u8   *fp;
  	unsigned long flags;
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
212

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
213
214
215
216
217
218
219
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
  	IRDA_ASSERT(skb->len > 2, return;);
  
  	fp = skb->data;
  
  	/*
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
220
  	 *  The next statements may be confusing, but we do this so that
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221
222
  	 *  destination LSAP of received frame is source LSAP in our view
  	 */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
223
  	slsap_sel = fp[0] & LSAP_MASK;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224
225
  	dlsap_sel = fp[1];
  	pid       = fp[2];
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
226

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
  	if (pid & 0x80) {
955a9d202   Joe Perches   irda: Convert IRD...
228
229
230
  		pr_debug("%s(), extension in PID not supp!
  ",
  			 __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
231
232
233
234
235
  		return;
  	}
  
  	/* Check if frame is addressed to the connectionless LSAP */
  	if ((slsap_sel != LSAP_CONNLESS) || (dlsap_sel != LSAP_CONNLESS)) {
955a9d202   Joe Perches   irda: Convert IRD...
236
237
  		pr_debug("%s(), dropping frame!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
238
239
  		return;
  	}
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
240

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
241
242
243
244
245
246
247
  	/* Search the connectionless LSAP */
  	spin_lock_irqsave(&irlmp->unconnected_lsaps->hb_spinlock, flags);
  	lsap = (struct lsap_cb *) hashbin_get_first(irlmp->unconnected_lsaps);
  	while (lsap != NULL) {
  		/*
  		 *  Check if source LSAP and dest LSAP selectors and PID match.
  		 */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
248
249
250
251
  		if ((lsap->slsap_sel == slsap_sel) &&
  		    (lsap->dlsap_sel == dlsap_sel) &&
  		    (lsap->pid == pid))
  		{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
252
253
254
255
256
257
258
259
260
  			break;
  		}
  		lsap = (struct lsap_cb *) hashbin_get_next(irlmp->unconnected_lsaps);
  	}
  	spin_unlock_irqrestore(&irlmp->unconnected_lsaps->hb_spinlock, flags);
  
  	if (lsap)
  		irlmp_connless_data_indication(lsap, skb);
  	else {
955a9d202   Joe Perches   irda: Convert IRD...
261
262
  		pr_debug("%s(), found no matching LSAP!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
263
264
265
266
267
268
269
  	}
  }
  #endif /* CONFIG_IRDA_ULTRA */
  
  /*
   * Function irlmp_link_disconnect_indication (reason, userdata)
   *
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
270
   *    IrLAP has disconnected
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
271
272
   *
   */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
273
274
275
  void irlmp_link_disconnect_indication(struct lap_cb *lap,
  				      struct irlap_cb *irlap,
  				      LAP_REASON reason,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
276
277
  				      struct sk_buff *skb)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
278
279
280
281
282
  	IRDA_ASSERT(lap != NULL, return;);
  	IRDA_ASSERT(lap->magic == LMP_LAP_MAGIC, return;);
  
  	lap->reason = reason;
  	lap->daddr = DEV_ADDR_ANY;
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
283
  	/* FIXME: must do something with the skb if any */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
285
286
287
288
289
290
291
292
293
294
295
  	/*
  	 *  Inform station state machine
  	 */
  	irlmp_do_lap_event(lap, LM_LAP_DISCONNECT_INDICATION, NULL);
  }
  
  /*
   * Function irlmp_link_connect_indication (qos)
   *
   *    Incoming LAP connection!
   *
   */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
296
  void irlmp_link_connect_indication(struct lap_cb *self, __u32 saddr,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
297
  				   __u32 daddr, struct qos_info *qos,
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
298
  				   struct sk_buff *skb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
  	/* Copy QoS settings for this session */
  	self->qos = qos;
  
  	/* Update destination device address */
  	self->daddr = daddr;
  	IRDA_ASSERT(self->saddr == saddr, return;);
  
  	irlmp_do_lap_event(self, LM_LAP_CONNECT_INDICATION, skb);
  }
  
  /*
   * Function irlmp_link_connect_confirm (qos)
   *
   *    LAP connection confirmed!
   *
   */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
316
  void irlmp_link_connect_confirm(struct lap_cb *self, struct qos_info *qos,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
318
  				struct sk_buff *skb)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
  	IRDA_ASSERT(qos != NULL, return;);
  
  	/* Don't need use the skb for now */
  
  	/* Copy QoS settings for this session */
  	self->qos = qos;
  
  	irlmp_do_lap_event(self, LM_LAP_CONNECT_CONFIRM, NULL);
  }
  
  /*
   * Function irlmp_link_discovery_indication (self, log)
   *
   *    Device is discovering us
   *
   * It's not an answer to our own discoveries, just another device trying
   * to perform discovery, but we don't want to miss the opportunity
   * to exploit this information, because :
   *	o We may not actively perform discovery (just passive discovery)
   *	o This type of discovery is much more reliable. In some cases, it
   *	  seem that less than 50% of our discoveries get an answer, while
   *	  we always get ~100% of these.
   *	o Make faster discovery, statistically divide time of discovery
   *	  events by 2 (important for the latency aspect and user feel)
   *	o Even is we do active discovery, the other node might not
   *	  answer our discoveries (ex: Palm). The Palm will just perform
   *	  one active discovery and connect directly to us.
   *
   * However, when both devices discover each other, they might attempt to
   * connect to each other following the discovery event, and it would create
   * collisions on the medium (SNRM battle).
   * The "fix" for that is to disable all connection requests in IrLAP
   * for 100ms after a discovery indication by setting the media_busy flag.
   * Previously, we used to postpone the event which was quite ugly. Now
   * that IrLAP takes care of this problem, just pass the event up...
   *
   * Jean II
   */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
359
  void irlmp_link_discovery_indication(struct lap_cb *self,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
360
361
362
363
364
365
366
  				     discovery_t *discovery)
  {
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
  
  	/* Add to main log, cleanup */
  	irlmp_add_discovery(irlmp->cachelog, discovery);
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
367

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
  	/* Just handle it the same way as a discovery confirm,
  	 * bypass the LM_LAP state machine (see below) */
  	irlmp_discovery_confirm(irlmp->cachelog, DISCOVERY_PASSIVE);
  }
  
  /*
   * Function irlmp_link_discovery_confirm (self, log)
   *
   *    Called by IrLAP with a list of discoveries after the discovery
   *    request has been carried out. A NULL log is received if IrLAP
   *    was unable to carry out the discovery request
   *
   */
  void irlmp_link_discovery_confirm(struct lap_cb *self, hashbin_t *log)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
385

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
  	/* Add to main log, cleanup */
  	irlmp_add_discovery_log(irlmp->cachelog, log);
  
  	/* Propagate event to various LSAPs registered for it.
  	 * We bypass the LM_LAP state machine because
  	 *	1) We do it regardless of the LM_LAP state
  	 *	2) It doesn't affect the LM_LAP state
  	 *	3) Faster, slimer, simpler, ...
  	 * Jean II */
  	irlmp_discovery_confirm(irlmp->cachelog, DISCOVERY_ACTIVE);
  }
  
  #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
  static inline void irlmp_update_cache(struct lap_cb *lap,
  				      struct lsap_cb *lsap)
  {
  	/* Prevent concurrent read to get garbage */
  	lap->cache.valid = FALSE;
  	/* Update cache entry */
  	lap->cache.dlsap_sel = lsap->dlsap_sel;
  	lap->cache.slsap_sel = lsap->slsap_sel;
  	lap->cache.lsap = lsap;
  	lap->cache.valid = TRUE;
  }
  #endif
  
  /*
   * Function irlmp_find_handle (self, dlsap_sel, slsap_sel, status, queue)
   *
   *    Find handle associated with destination and source LSAP
   *
   * Any IrDA connection (LSAP/TSAP) is uniquely identified by
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
418
   * 3 parameters, the local lsap, the remote lsap and the remote address.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
419
420
421
422
423
424
425
426
427
428
429
430
   * We may initiate multiple connections to the same remote service
   * (they will have different local lsap), a remote device may initiate
   * multiple connections to the same local service (they will have
   * different remote lsap), or multiple devices may connect to the same
   * service and may use the same remote lsap (and they will have
   * different remote address).
   * So, where is the remote address ? Each LAP connection is made with
   * a single remote device, so imply a specific remote address.
   * Jean II
   */
  static struct lsap_cb *irlmp_find_lsap(struct lap_cb *self, __u8 dlsap_sel,
  				       __u8 slsap_sel, int status,
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
431
  				       hashbin_t *queue)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
432
433
434
  {
  	struct lsap_cb *lsap;
  	unsigned long flags;
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
435
436
  
  	/*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437
438
439
440
441
  	 *  Optimize for the common case. We assume that the last frame
  	 *  received is in the same connection as the last one, so check in
  	 *  cache first to avoid the linear search
  	 */
  #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
442
443
444
  	if ((self->cache.valid) &&
  	    (self->cache.slsap_sel == slsap_sel) &&
  	    (self->cache.dlsap_sel == dlsap_sel))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
445
  	{
a02cec215   Eric Dumazet   net: return opera...
446
  		return self->cache.lsap;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
447
448
449
450
451
452
453
  	}
  #endif
  
  	spin_lock_irqsave(&queue->hb_spinlock, flags);
  
  	lsap = (struct lsap_cb *) hashbin_get_first(queue);
  	while (lsap != NULL) {
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
454
455
456
  		/*
  		 *  If this is an incoming connection, then the destination
  		 *  LSAP selector may have been specified as LM_ANY so that
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
457
458
459
  		 *  any client can connect. In that case we only need to check
  		 *  if the source LSAP (in our view!) match!
  		 */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
460
461
  		if ((status == CONNECT_CMD) &&
  		    (lsap->slsap_sel == slsap_sel) &&
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
462
463
464
465
466
467
468
469
470
  		    (lsap->dlsap_sel == LSAP_ANY)) {
  			/* This is where the dest lsap sel is set on incoming
  			 * lsaps */
  			lsap->dlsap_sel = dlsap_sel;
  			break;
  		}
  		/*
  		 *  Check if source LSAP and dest LSAP selectors match.
  		 */
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
471
472
  		if ((lsap->slsap_sel == slsap_sel) &&
  		    (lsap->dlsap_sel == dlsap_sel))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
473
474
475
476
477
478
479
480
481
482
483
484
485
  			break;
  
  		lsap = (struct lsap_cb *) hashbin_get_next(queue);
  	}
  #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
  	if(lsap)
  		irlmp_update_cache(self, lsap);
  #endif
  	spin_unlock_irqrestore(&queue->hb_spinlock, flags);
  
  	/* Return what we've found or NULL */
  	return lsap;
  }