Blame view

net/irda/iriap.c 25.9 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /*********************************************************************
   *
   * Filename:      iriap.c
   * Version:       0.8
   * Description:   Information Access Protocol (IAP)
   * Status:        Experimental.
   * Author:        Dag Brattli <dagb@cs.uit.no>
   * Created at:    Thu Aug 21 00:02:07 1997
   * Modified at:   Sat Dec 25 16:42:42 1999
   * Modified by:   Dag Brattli <dagb@cs.uit.no>
   *
   *     Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
   *     All Rights Reserved.
   *     Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
   *
   *     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
   *     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
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
24
25
   *     provide warranty for any of this software. This material is
   *     provided "AS-IS" and at no charge.
   *
   ********************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
27
28
  #include <linux/module.h>
  #include <linux/types.h>
  #include <linux/skbuff.h>
d7fe0f241   Al Viro   [PATCH] severing ...
29
  #include <linux/fs.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
31
32
  #include <linux/string.h>
  #include <linux/init.h>
  #include <linux/seq_file.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
33
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
35
36
37
38
39
40
41
42
43
  
  #include <asm/byteorder.h>
  #include <asm/unaligned.h>
  
  #include <net/irda/irda.h>
  #include <net/irda/irttp.h>
  #include <net/irda/irlmp.h>
  #include <net/irda/irias_object.h>
  #include <net/irda/iriap_event.h>
  #include <net/irda/iriap.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
  /* FIXME: This one should go in irlmp.c */
a768851f9   Joe Perches   irda: Fix build f...
45
  static const char *const ias_charset_types[] __maybe_unused = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
50
51
52
53
54
55
56
57
  	"CS_ASCII",
  	"CS_ISO_8859_1",
  	"CS_ISO_8859_2",
  	"CS_ISO_8859_3",
  	"CS_ISO_8859_4",
  	"CS_ISO_8859_5",
  	"CS_ISO_8859_6",
  	"CS_ISO_8859_7",
  	"CS_ISO_8859_8",
  	"CS_ISO_8859_9",
  	"CS_UNICODE"
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  
  static hashbin_t *iriap = NULL;
  static void *service_handle;
  
  static void __iriap_close(struct iriap_cb *self);
  static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode);
  static void iriap_disconnect_indication(void *instance, void *sap,
  					LM_REASON reason, struct sk_buff *skb);
  static void iriap_connect_indication(void *instance, void *sap,
  				     struct qos_info *qos, __u32 max_sdu_size,
  				     __u8 max_header_size,
  				     struct sk_buff *skb);
  static void iriap_connect_confirm(void *instance, void *sap,
  				  struct qos_info *qos,
  				  __u32 max_sdu_size, __u8 max_header_size,
  				  struct sk_buff *skb);
  static int iriap_data_indication(void *instance, void *sap,
  				 struct sk_buff *skb);
  
  static void iriap_watchdog_timer_expired(void *data);
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
78
79
  static inline void iriap_start_watchdog_timer(struct iriap_cb *self,
  					      int timeout)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
  {
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
81
  	irda_start_timer(&self->watchdog_timer, timeout, self,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
  			 iriap_watchdog_timer_expired);
  }
79b389158   David S. Miller   irda: iriap: Use ...
84
  static struct lock_class_key irias_objects_key;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  /*
   * Function iriap_init (void)
   *
   *    Initializes the IrIAP layer, called by the module initialization code
   *    in irmod.c
   */
  int __init iriap_init(void)
  {
  	struct ias_object *obj;
  	struct iriap_cb *server;
  	__u8 oct_seq[6];
  	__u16 hints;
  
  	/* Allocate master array */
  	iriap = hashbin_new(HB_LOCK);
  	if (!iriap)
  		return -ENOMEM;
  
  	/* Object repository - defined in irias_object.c */
  	irias_objects = hashbin_new(HB_LOCK);
  	if (!irias_objects) {
6c91023dc   Joe Perches   irda: Remove IRDA...
106
107
108
  		net_warn_ratelimited("%s: Can't allocate irias_objects hashbin!
  ",
  				     __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
111
  		hashbin_delete(iriap, NULL);
  		return -ENOMEM;
  	}
79b389158   David S. Miller   irda: iriap: Use ...
112
113
  	lockdep_set_class_and_name(&irias_objects->hb_spinlock, &irias_objects_key,
  				   "irias_objects");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  	/*
  	 *  Register some default services for IrLMP
  	 */
  	hints  = irlmp_service_to_hint(S_COMPUTER);
  	service_handle = irlmp_register_service(hints);
  
  	/* Register the Device object with LM-IAS */
  	obj = irias_new_object("Device", IAS_DEVICE_ID);
  	irias_add_string_attrib(obj, "DeviceName", "Linux", IAS_KERNEL_ATTR);
  
  	oct_seq[0] = 0x01;  /* Version 1 */
  	oct_seq[1] = 0x00;  /* IAS support bits */
  	oct_seq[2] = 0x00;  /* LM-MUX support bits */
  #ifdef CONFIG_IRDA_ULTRA
  	oct_seq[2] |= 0x04; /* Connectionless Data support */
  #endif
  	irias_add_octseq_attrib(obj, "IrLMPSupport", oct_seq, 3,
  				IAS_KERNEL_ATTR);
  	irias_insert_object(obj);
  
  	/*
  	 *  Register server support with IrLMP so we can accept incoming
  	 *  connections
  	 */
  	server = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
  	if (!server) {
955a9d202   Joe Perches   irda: Convert IRD...
140
141
  		pr_debug("%s(), unable to open server
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
143
144
145
146
147
148
149
150
151
152
153
154
  		return -1;
  	}
  	iriap_register_lsap(server, LSAP_IAS, IAS_SERVER);
  
  	return 0;
  }
  
  /*
   * Function iriap_cleanup (void)
   *
   *    Initializes the IrIAP layer, called by the module cleanup code in
   *    irmod.c
   */
75a69ac6d   Samuel Ortiz   [IrDA]: Fix IrDA ...
155
  void iriap_cleanup(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
  {
  	irlmp_unregister_service(service_handle);
  
  	hashbin_delete(iriap, (FREE_FUNC) __iriap_close);
  	hashbin_delete(irias_objects, (FREE_FUNC) __irias_delete_object);
  }
  
  /*
   * Function iriap_open (void)
   *
   *    Opens an instance of the IrIAP layer, and registers with IrLMP
   */
  struct iriap_cb *iriap_open(__u8 slsap_sel, int mode, void *priv,
  			    CONFIRM_CALLBACK callback)
  {
  	struct iriap_cb *self;
b3ab09f9e   Arnaldo Carvalho de Melo   [IRDA]: Use kmemd...
172
  	self = kzalloc(sizeof(*self), GFP_ATOMIC);
6c91023dc   Joe Perches   irda: Remove IRDA...
173
  	if (!self)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
174
  		return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175
176
177
178
  
  	/*
  	 *  Initialize instance
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  
  	self->magic = IAS_MAGIC;
  	self->mode = mode;
  	if (mode == IAS_CLIENT)
  		iriap_register_lsap(self, slsap_sel, mode);
  
  	self->confirm = callback;
  	self->priv = priv;
  
  	/* iriap_getvaluebyclass_request() will construct packets before
  	 * we connect, so this must have a sane value... Jean II */
  	self->max_header_size = LMP_MAX_HEADER;
  
  	init_timer(&self->watchdog_timer);
  
  	hashbin_insert(iriap, (irda_queue_t *) self, (long) self, NULL);
  
  	/* Initialize state machines */
  	iriap_next_client_state(self, S_DISCONNECT);
  	iriap_next_call_state(self, S_MAKE_CALL);
  	iriap_next_server_state(self, R_DISCONNECT);
  	iriap_next_r_connect_state(self, R_WAITING);
  
  	return self;
  }
  EXPORT_SYMBOL(iriap_open);
  
  /*
   * Function __iriap_close (self)
   *
   *    Removes (deallocates) the IrIAP instance
   *
   */
  static void __iriap_close(struct iriap_cb *self)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  
  	del_timer(&self->watchdog_timer);
  
  	if (self->request_skb)
  		dev_kfree_skb(self->request_skb);
  
  	self->magic = 0;
  
  	kfree(self);
  }
  
  /*
   * Function iriap_close (void)
   *
   *    Closes IrIAP and deregisters with IrLMP
   */
  void iriap_close(struct iriap_cb *self)
  {
  	struct iriap_cb *entry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  
  	if (self->lsap) {
  		irlmp_close_lsap(self->lsap);
  		self->lsap = NULL;
  	}
  
  	entry = (struct iriap_cb *) hashbin_remove(iriap, (long) self, NULL);
  	IRDA_ASSERT(entry == self, return;);
  
  	__iriap_close(self);
  }
  EXPORT_SYMBOL(iriap_close);
  
  static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode)
  {
  	notify_t notify;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
253
254
255
256
257
258
259
260
261
262
263
264
265
  	irda_notify_init(&notify);
  	notify.connect_confirm       = iriap_connect_confirm;
  	notify.connect_indication    = iriap_connect_indication;
  	notify.disconnect_indication = iriap_disconnect_indication;
  	notify.data_indication       = iriap_data_indication;
  	notify.instance = self;
  	if (mode == IAS_CLIENT)
  		strcpy(notify.name, "IrIAS cli");
  	else
  		strcpy(notify.name, "IrIAS srv");
  
  	self->lsap = irlmp_open_lsap(slsap_sel, &notify, 0);
  	if (self->lsap == NULL) {
6c91023dc   Joe Perches   irda: Remove IRDA...
266
267
268
  		net_err_ratelimited("%s: Unable to allocated LSAP!
  ",
  				    __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
  		return -1;
  	}
  	self->slsap_sel = self->lsap->slsap_sel;
  
  	return 0;
  }
  
  /*
   * Function iriap_disconnect_indication (handle, reason)
   *
   *    Got disconnect, so clean up everything associated with this connection
   *
   */
  static void iriap_disconnect_indication(void *instance, void *sap,
  					LM_REASON reason,
  					struct sk_buff *skb)
  {
  	struct iriap_cb *self;
955a9d202   Joe Perches   irda: Convert IRD...
287
288
289
  	pr_debug("%s(), reason=%s [%d]
  ", __func__,
  		 irlmp_reason_str(reason), reason);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290

ea1107338   Joe Perches   net: Remove casts...
291
  	self = instance;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
293
294
295
296
297
298
299
300
301
302
303
304
  
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  
  	IRDA_ASSERT(iriap != NULL, return;);
  
  	del_timer(&self->watchdog_timer);
  
  	/* Not needed */
  	if (skb)
  		dev_kfree_skb(skb);
  
  	if (self->mode == IAS_CLIENT) {
955a9d202   Joe Perches   irda: Convert IRD...
305
306
  		pr_debug("%s(), disconnect as client
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
307
308
309
310
311
312
313
314
315
316
317
318
  
  
  		iriap_do_client_event(self, IAP_LM_DISCONNECT_INDICATION,
  				      NULL);
  		/*
  		 * Inform service user that the request failed by sending
  		 * it a NULL value. Warning, the client might close us, so
  		 * remember no to use self anymore after calling confirm
  		 */
  		if (self->confirm)
  			self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
  	} else {
955a9d202   Joe Perches   irda: Convert IRD...
319
320
  		pr_debug("%s(), disconnect as server
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
321
322
323
324
325
326
327
328
329
330
331
332
  		iriap_do_server_event(self, IAP_LM_DISCONNECT_INDICATION,
  				      NULL);
  		iriap_close(self);
  	}
  }
  
  /*
   * Function iriap_disconnect_request (handle)
   */
  static void iriap_disconnect_request(struct iriap_cb *self)
  {
  	struct sk_buff *tx_skb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
333
334
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
1b0fee7d6   Samuel Ortiz   [IrDA]: Memory al...
335
  	tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
336
  	if (tx_skb == NULL) {
955a9d202   Joe Perches   irda: Convert IRD...
337
338
339
  		pr_debug("%s(), Could not allocate an sk_buff of length %d
  ",
  			 __func__, LMP_MAX_HEADER);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340
341
342
343
344
345
346
347
348
349
350
351
352
353
  		return;
  	}
  
  	/*
  	 *  Reserve space for MUX control and LAP header
  	 */
  	skb_reserve(tx_skb, LMP_MAX_HEADER);
  
  	irlmp_disconnect_request(self->lsap, tx_skb);
  }
  
  /*
   * Function iriap_getvaluebyclass (addr, name, attr)
   *
4a4efbdee   Matt Mackall   s/retreiv/retriev/g
354
   *    Retrieve all values from attribute in all objects with given class
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
   *    name
   */
  int iriap_getvaluebyclass_request(struct iriap_cb *self,
  				  __u32 saddr, __u32 daddr,
  				  char *name, char *attr)
  {
  	struct sk_buff *tx_skb;
  	int name_len, attr_len, skb_len;
  	__u8 *frame;
  
  	IRDA_ASSERT(self != NULL, return -1;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return -1;);
  
  	/* Client must supply the destination device address */
  	if (!daddr)
  		return -1;
  
  	self->daddr = daddr;
  	self->saddr = saddr;
  
  	/*
  	 *  Save operation, so we know what the later indication is about
  	 */
  	self->operation = GET_VALUE_BY_CLASS;
  
  	/* Give ourselves 10 secs to finish this operation */
  	iriap_start_watchdog_timer(self, 10*HZ);
  
  	name_len = strlen(name);	/* Up to IAS_MAX_CLASSNAME = 60 */
  	attr_len = strlen(attr);	/* Up to IAS_MAX_ATTRIBNAME = 60 */
  
  	skb_len = self->max_header_size+2+name_len+1+attr_len+4;
485fb2c99   Samuel Ortiz   [IrDA]: Use alloc...
387
  	tx_skb = alloc_skb(skb_len, GFP_ATOMIC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
  	if (!tx_skb)
  		return -ENOMEM;
  
  	/* Reserve space for MUX and LAP header */
  	skb_reserve(tx_skb, self->max_header_size);
  	skb_put(tx_skb, 3+name_len+attr_len);
  	frame = tx_skb->data;
  
  	/* Build frame */
  	frame[0] = IAP_LST | GET_VALUE_BY_CLASS;
  	frame[1] = name_len;                       /* Insert length of name */
  	memcpy(frame+2, name, name_len);           /* Insert name */
  	frame[2+name_len] = attr_len;              /* Insert length of attr */
  	memcpy(frame+3+name_len, attr, attr_len);  /* Insert attr */
  
  	iriap_do_client_event(self, IAP_CALL_REQUEST_GVBC, tx_skb);
  
  	/* Drop reference count - see state_s_disconnect(). */
  	dev_kfree_skb(tx_skb);
  
  	return 0;
  }
  EXPORT_SYMBOL(iriap_getvaluebyclass_request);
  
  /*
   * Function iriap_getvaluebyclass_confirm (self, skb)
   *
   *    Got result from GetValueByClass command. Parse it and return result
   *    to service user.
   *
   */
  static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
  					  struct sk_buff *skb)
  {
  	struct ias_value *value;
  	int charset;
  	__u32 value_len;
  	__u32 tmp_cpu32;
  	__u16 obj_id;
  	__u16 len;
  	__u8  type;
  	__u8 *fp;
  	int n;
  
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  	IRDA_ASSERT(skb != NULL, return;);
  
  	/* Initialize variables */
  	fp = skb->data;
  	n = 2;
  
  	/* Get length, MSB first */
260ffeed3   Harvey Harrison   irda: use get_una...
441
442
  	len = get_unaligned_be16(fp + n);
  	n += 2;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
443

955a9d202   Joe Perches   irda: Convert IRD...
444
445
  	pr_debug("%s(), len=%d
  ", __func__, len);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
446
447
  
  	/* Get object ID, MSB first */
260ffeed3   Harvey Harrison   irda: use get_una...
448
449
  	obj_id = get_unaligned_be16(fp + n);
  	n += 2;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
450
451
  
  	type = fp[n++];
955a9d202   Joe Perches   irda: Convert IRD...
452
453
  	pr_debug("%s(), Value type = %d
  ", __func__, type);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
454
455
456
457
458
459
460
461
  
  	switch (type) {
  	case IAS_INTEGER:
  		memcpy(&tmp_cpu32, fp+n, 4); n += 4;
  		be32_to_cpus(&tmp_cpu32);
  		value = irias_new_integer_value(tmp_cpu32);
  
  		/*  Legal values restricted to 0x01-0x6f, page 15 irttp */
955a9d202   Joe Perches   irda: Convert IRD...
462
463
  		pr_debug("%s(), lsap=%d
  ", __func__, value->t.integer);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
  		break;
  	case IAS_STRING:
  		charset = fp[n++];
  
  		switch (charset) {
  		case CS_ASCII:
  			break;
  /*		case CS_ISO_8859_1: */
  /*		case CS_ISO_8859_2: */
  /*		case CS_ISO_8859_3: */
  /*		case CS_ISO_8859_4: */
  /*		case CS_ISO_8859_5: */
  /*		case CS_ISO_8859_6: */
  /*		case CS_ISO_8859_7: */
  /*		case CS_ISO_8859_8: */
  /*		case CS_ISO_8859_9: */
  /*		case CS_UNICODE: */
  		default:
955a9d202   Joe Perches   irda: Convert IRD...
482
483
484
485
486
487
  			pr_debug("%s(), charset [%d] %s, not supported
  ",
  				 __func__, charset,
  				 charset < ARRAY_SIZE(ias_charset_types) ?
  				 ias_charset_types[charset] :
  				 "(unknown)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
488
489
490
491
492
493
494
  
  			/* Aborting, close connection! */
  			iriap_disconnect_request(self);
  			return;
  			/* break; */
  		}
  		value_len = fp[n++];
955a9d202   Joe Perches   irda: Convert IRD...
495
496
  		pr_debug("%s(), strlen=%d
  ", __func__, value_len);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
497
498
  
  		/* Make sure the string is null-terminated */
37f9fc452   Samuel Ortiz   irda: Fix heap me...
499
500
  		if (n + value_len < skb->len)
  			fp[n + value_len] = 0x00;
955a9d202   Joe Perches   irda: Convert IRD...
501
502
  		pr_debug("Got string %s
  ", fp+n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
503
504
505
506
507
  
  		/* Will truncate to IAS_MAX_STRING bytes */
  		value = irias_new_string_value(fp+n);
  		break;
  	case IAS_OCT_SEQ:
260ffeed3   Harvey Harrison   irda: use get_una...
508
  		value_len = get_unaligned_be16(fp + n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
  		n += 2;
  
  		/* Will truncate to IAS_MAX_OCTET_STRING bytes */
  		value = irias_new_octseq_value(fp+n, value_len);
  		break;
  	default:
  		value = irias_new_missing_value();
  		break;
  	}
  
  	/* Finished, close connection! */
  	iriap_disconnect_request(self);
  
  	/* Warning, the client might close us, so remember no to use self
  	 * anymore after calling confirm
  	 */
  	if (self->confirm)
  		self->confirm(IAS_SUCCESS, obj_id, value, self->priv);
  	else {
955a9d202   Joe Perches   irda: Convert IRD...
528
529
  		pr_debug("%s(), missing handler!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
  		irias_delete_value(value);
  	}
  }
  
  /*
   * Function iriap_getvaluebyclass_response ()
   *
   *    Send answer back to remote LM-IAS
   *
   */
  static void iriap_getvaluebyclass_response(struct iriap_cb *self,
  					   __u16 obj_id,
  					   __u8 ret_code,
  					   struct ias_value *value)
  {
  	struct sk_buff *tx_skb;
  	int n;
448c31aa3   Al Viro   [IRDA]: Trivial a...
547
  	__be32 tmp_be32;
405a42c5c   Alexey Dobriyan   [IRDA]: fix 16/32...
548
  	__be16 tmp_be16;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
549
  	__u8 *fp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
550
551
552
553
554
555
556
557
558
559
560
561
562
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  	IRDA_ASSERT(value != NULL, return;);
  	IRDA_ASSERT(value->len <= 1024, return;);
  
  	/* Initialize variables */
  	n = 0;
  
  	/*
  	 *  We must adjust the size of the response after the length of the
  	 *  value. We add 32 bytes because of the 6 bytes for the frame and
  	 *  max 5 bytes for the value coding.
  	 */
485fb2c99   Samuel Ortiz   [IrDA]: Use alloc...
563
564
  	tx_skb = alloc_skb(value->len + self->max_header_size + 32,
  			   GFP_ATOMIC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
565
566
567
568
569
570
571
572
573
574
575
576
577
578
  	if (!tx_skb)
  		return;
  
  	/* Reserve space for MUX and LAP header */
  	skb_reserve(tx_skb, self->max_header_size);
  	skb_put(tx_skb, 6);
  
  	fp = tx_skb->data;
  
  	/* Build frame */
  	fp[n++] = GET_VALUE_BY_CLASS | IAP_LST;
  	fp[n++] = ret_code;
  
  	/* Insert list length (MSB first) */
6d82de9e5   YOSHIFUJI Hideaki   [IRDA]: Use htons...
579
  	tmp_be16 = htons(0x0001);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
  	memcpy(fp+n, &tmp_be16, 2);  n += 2;
  
  	/* Insert object identifier ( MSB first) */
  	tmp_be16 = cpu_to_be16(obj_id);
  	memcpy(fp+n, &tmp_be16, 2); n += 2;
  
  	switch (value->type) {
  	case IAS_STRING:
  		skb_put(tx_skb, 3 + value->len);
  		fp[n++] = value->type;
  		fp[n++] = 0; /* ASCII */
  		fp[n++] = (__u8) value->len;
  		memcpy(fp+n, value->t.string, value->len); n+=value->len;
  		break;
  	case IAS_INTEGER:
  		skb_put(tx_skb, 5);
  		fp[n++] = value->type;
  
  		tmp_be32 = cpu_to_be32(value->t.integer);
  		memcpy(fp+n, &tmp_be32, 4); n += 4;
  		break;
  	case IAS_OCT_SEQ:
  		skb_put(tx_skb, 3 + value->len);
  		fp[n++] = value->type;
  
  		tmp_be16 = cpu_to_be16(value->len);
  		memcpy(fp+n, &tmp_be16, 2); n += 2;
  		memcpy(fp+n, value->t.oct_seq, value->len); n+=value->len;
  		break;
  	case IAS_MISSING:
955a9d202   Joe Perches   irda: Convert IRD...
610
611
  		pr_debug("%s: sending IAS_MISSING
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
612
613
614
615
  		skb_put(tx_skb, 1);
  		fp[n++] = value->type;
  		break;
  	default:
955a9d202   Joe Perches   irda: Convert IRD...
616
617
  		pr_debug("%s(), type not implemented!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
  		break;
  	}
  	iriap_do_r_connect_event(self, IAP_CALL_RESPONSE, tx_skb);
  
  	/* Drop reference count - see state_r_execute(). */
  	dev_kfree_skb(tx_skb);
  }
  
  /*
   * Function iriap_getvaluebyclass_indication (self, skb)
   *
   *    getvaluebyclass is requested from peer LM-IAS
   *
   */
  static void iriap_getvaluebyclass_indication(struct iriap_cb *self,
  					     struct sk_buff *skb)
  {
  	struct ias_object *obj;
  	struct ias_attrib *attrib;
  	int name_len;
  	int attr_len;
  	char name[IAS_MAX_CLASSNAME + 1];	/* 60 bytes */
  	char attr[IAS_MAX_ATTRIBNAME + 1];	/* 60 bytes */
  	__u8 *fp;
  	int n;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
643
644
645
646
647
648
649
650
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  	IRDA_ASSERT(skb != NULL, return;);
  
  	fp = skb->data;
  	n = 1;
  
  	name_len = fp[n++];
d370af0ef   Dan Rosenberg   irda: validate pe...
651
652
  
  	IRDA_ASSERT(name_len < IAS_MAX_CLASSNAME + 1, return;);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
653
654
655
656
  	memcpy(name, fp+n, name_len); n+=name_len;
  	name[name_len] = '\0';
  
  	attr_len = fp[n++];
d370af0ef   Dan Rosenberg   irda: validate pe...
657
658
  
  	IRDA_ASSERT(attr_len < IAS_MAX_ATTRIBNAME + 1, return;);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
659
660
  	memcpy(attr, fp+n, attr_len); n+=attr_len;
  	attr[attr_len] = '\0';
955a9d202   Joe Perches   irda: Convert IRD...
661
662
  	pr_debug("LM-IAS: Looking up %s: %s
  ", name, attr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
663
664
665
  	obj = irias_find_object(name);
  
  	if (obj == NULL) {
955a9d202   Joe Perches   irda: Convert IRD...
666
667
  		pr_debug("LM-IAS: Object %s not found
  ", name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
668
669
670
671
  		iriap_getvaluebyclass_response(self, 0x1235, IAS_CLASS_UNKNOWN,
  					       &irias_missing);
  		return;
  	}
955a9d202   Joe Perches   irda: Convert IRD...
672
673
  	pr_debug("LM-IAS: found %s, id=%d
  ", obj->name, obj->id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
674
675
676
  
  	attrib = irias_find_attrib(obj, attr);
  	if (attrib == NULL) {
955a9d202   Joe Perches   irda: Convert IRD...
677
678
  		pr_debug("LM-IAS: Attribute %s not found
  ", attr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
679
  		iriap_getvaluebyclass_response(self, obj->id,
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
680
  					       IAS_ATTRIB_UNKNOWN,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
681
682
683
684
685
686
687
  					       &irias_missing);
  		return;
  	}
  
  	/* We have a match; send the value.  */
  	iriap_getvaluebyclass_response(self, obj->id, IAS_SUCCESS,
  				       attrib->value);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
688
689
690
691
692
693
694
695
696
697
698
699
  }
  
  /*
   * Function iriap_send_ack (void)
   *
   *    Currently not used
   *
   */
  void iriap_send_ack(struct iriap_cb *self)
  {
  	struct sk_buff *tx_skb;
  	__u8 *frame;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
700
701
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
1b0fee7d6   Samuel Ortiz   [IrDA]: Memory al...
702
  	tx_skb = alloc_skb(LMP_MAX_HEADER + 1, GFP_ATOMIC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
  	if (!tx_skb)
  		return;
  
  	/* Reserve space for MUX and LAP header */
  	skb_reserve(tx_skb, self->max_header_size);
  	skb_put(tx_skb, 1);
  	frame = tx_skb->data;
  
  	/* Build frame */
  	frame[0] = IAP_LST | IAP_ACK | self->operation;
  
  	irlmp_data_request(self->lsap, tx_skb);
  }
  
  void iriap_connect_request(struct iriap_cb *self)
  {
  	int ret;
  
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  
  	ret = irlmp_connect_request(self->lsap, LSAP_IAS,
  				    self->saddr, self->daddr,
  				    NULL, NULL);
  	if (ret < 0) {
955a9d202   Joe Perches   irda: Convert IRD...
728
729
  		pr_debug("%s(), connect failed!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
  		self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
  	}
  }
  
  /*
   * Function iriap_connect_confirm (handle, skb)
   *
   *    LSAP connection confirmed!
   *
   */
  static void iriap_connect_confirm(void *instance, void *sap,
  				  struct qos_info *qos, __u32 max_seg_size,
  				  __u8 max_header_size,
  				  struct sk_buff *skb)
  {
  	struct iriap_cb *self;
ea1107338   Joe Perches   net: Remove casts...
746
  	self = instance;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
  
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  	IRDA_ASSERT(skb != NULL, return;);
  
  	self->max_data_size = max_seg_size;
  	self->max_header_size = max_header_size;
  
  	del_timer(&self->watchdog_timer);
  
  	iriap_do_client_event(self, IAP_LM_CONNECT_CONFIRM, skb);
  
  	/* Drop reference count - see state_s_make_call(). */
  	dev_kfree_skb(skb);
  }
  
  /*
   * Function iriap_connect_indication ( handle, skb)
   *
   *    Remote LM-IAS is requesting connection
   *
   */
  static void iriap_connect_indication(void *instance, void *sap,
  				     struct qos_info *qos, __u32 max_seg_size,
  				     __u8 max_header_size,
  				     struct sk_buff *skb)
  {
  	struct iriap_cb *self, *new;
ea1107338   Joe Perches   net: Remove casts...
775
  	self = instance;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
776
777
778
779
780
781
782
783
  
  	IRDA_ASSERT(skb != NULL, return;);
  	IRDA_ASSERT(self != NULL, goto out;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, goto out;);
  
  	/* Start new server */
  	new = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
  	if (!new) {
955a9d202   Joe Perches   irda: Convert IRD...
784
785
  		pr_debug("%s(), open failed
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
786
787
788
789
790
791
  		goto out;
  	}
  
  	/* Now attach up the new "socket" */
  	new->lsap = irlmp_dup(self->lsap, new);
  	if (!new->lsap) {
955a9d202   Joe Perches   irda: Convert IRD...
792
793
  		pr_debug("%s(), dup failed!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
  		goto out;
  	}
  
  	new->max_data_size = max_seg_size;
  	new->max_header_size = max_header_size;
  
  	/* Clean up the original one to keep it in listen state */
  	irlmp_listen(self->lsap);
  
  	iriap_do_server_event(new, IAP_LM_CONNECT_INDICATION, skb);
  
  out:
  	/* Drop reference count - see state_r_disconnect(). */
  	dev_kfree_skb(skb);
  }
  
  /*
   * Function iriap_data_indication (handle, skb)
   *
   *    Receives data from connection identified by handle from IrLMP
   *
   */
  static int iriap_data_indication(void *instance, void *sap,
  				 struct sk_buff *skb)
  {
  	struct iriap_cb *self;
  	__u8  *frame;
  	__u8  opcode;
ea1107338   Joe Perches   net: Remove casts...
822
  	self = instance;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
823
824
825
826
827
828
829
830
831
  
  	IRDA_ASSERT(skb != NULL, return 0;);
  	IRDA_ASSERT(self != NULL, goto out;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, goto out;);
  
  	frame = skb->data;
  
  	if (self->mode == IAS_SERVER) {
  		/* Call server */
955a9d202   Joe Perches   irda: Convert IRD...
832
833
  		pr_debug("%s(), Calling server!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
834
835
836
837
838
  		iriap_do_r_connect_event(self, IAP_RECV_F_LST, skb);
  		goto out;
  	}
  	opcode = frame[0];
  	if (~opcode & IAP_LST) {
6c91023dc   Joe Perches   irda: Remove IRDA...
839
840
841
  		net_warn_ratelimited("%s:, IrIAS multiframe commands or results is not implemented yet!
  ",
  				     __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
842
843
844
845
846
  		goto out;
  	}
  
  	/* Check for ack frames since they don't contain any data */
  	if (opcode & IAP_ACK) {
955a9d202   Joe Perches   irda: Convert IRD...
847
848
  		pr_debug("%s() Got ack frame!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
849
850
851
852
853
854
855
  		goto out;
  	}
  
  	opcode &= ~IAP_LST; /* Mask away LST bit */
  
  	switch (opcode) {
  	case GET_INFO_BASE:
955a9d202   Joe Perches   irda: Convert IRD...
856
857
  		pr_debug("IrLMP GetInfoBaseDetails not implemented!
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
858
859
860
861
862
863
864
865
866
  		break;
  	case GET_VALUE_BY_CLASS:
  		iriap_do_call_event(self, IAP_RECV_F_LST, NULL);
  
  		switch (frame[1]) {
  		case IAS_SUCCESS:
  			iriap_getvaluebyclass_confirm(self, skb);
  			break;
  		case IAS_CLASS_UNKNOWN:
955a9d202   Joe Perches   irda: Convert IRD...
867
868
  			pr_debug("%s(), No such class!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
869
870
871
872
873
874
875
876
877
878
879
880
  			/* Finished, close connection! */
  			iriap_disconnect_request(self);
  
  			/*
  			 * Warning, the client might close us, so remember
  			 * no to use self anymore after calling confirm
  			 */
  			if (self->confirm)
  				self->confirm(IAS_CLASS_UNKNOWN, 0, NULL,
  					      self->priv);
  			break;
  		case IAS_ATTRIB_UNKNOWN:
955a9d202   Joe Perches   irda: Convert IRD...
881
882
  			pr_debug("%s(), No such attribute!
  ", __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
883
884
885
886
887
888
889
890
891
892
893
894
895
896
  			/* Finished, close connection! */
  			iriap_disconnect_request(self);
  
  			/*
  			 * Warning, the client might close us, so remember
  			 * no to use self anymore after calling confirm
  			 */
  			if (self->confirm)
  				self->confirm(IAS_ATTRIB_UNKNOWN, 0, NULL,
  					      self->priv);
  			break;
  		}
  		break;
  	default:
955a9d202   Joe Perches   irda: Convert IRD...
897
898
899
  		pr_debug("%s(), Unknown op-code: %02x
  ", __func__,
  			 opcode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
  		break;
  	}
  
  out:
  	/* Cleanup - sub-calls will have done skb_get() as needed. */
  	dev_kfree_skb(skb);
  	return 0;
  }
  
  /*
   * Function iriap_call_indication (self, skb)
   *
   *    Received call to server from peer LM-IAS
   *
   */
  void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
  {
  	__u8 *fp;
  	__u8 opcode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
919
920
921
922
923
924
925
926
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  	IRDA_ASSERT(skb != NULL, return;);
  
  	fp = skb->data;
  
  	opcode = fp[0];
  	if (~opcode & 0x80) {
6c91023dc   Joe Perches   irda: Remove IRDA...
927
928
929
  		net_warn_ratelimited("%s: IrIAS multiframe commands or results is not implemented yet!
  ",
  				     __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
930
931
932
933
934
935
  		return;
  	}
  	opcode &= 0x7f; /* Mask away LST bit */
  
  	switch (opcode) {
  	case GET_INFO_BASE:
6c91023dc   Joe Perches   irda: Remove IRDA...
936
937
938
  		net_warn_ratelimited("%s: GetInfoBaseDetails not implemented yet!
  ",
  				     __func__);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
  		break;
  	case GET_VALUE_BY_CLASS:
  		iriap_getvaluebyclass_indication(self, skb);
  		break;
  	}
  	/* skb will be cleaned up in iriap_data_indication */
  }
  
  /*
   * Function iriap_watchdog_timer_expired (data)
   *
   *    Query has taken too long time, so abort
   *
   */
  static void iriap_watchdog_timer_expired(void *data)
  {
  	struct iriap_cb *self = (struct iriap_cb *) data;
  
  	IRDA_ASSERT(self != NULL, return;);
  	IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  
  	/* iriap_close(self); */
  }
  
  #ifdef CONFIG_PROC_FS
36cbd3dcc   Jan Engelhardt   net: mark read-on...
964
  static const char *const ias_value_types[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
965
966
967
968
969
  	"IAS_MISSING",
  	"IAS_INTEGER",
  	"IAS_OCT_SEQ",
  	"IAS_STRING"
  };
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
970
  static inline struct ias_object *irias_seq_idx(loff_t pos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
971
972
973
974
975
976
977
978
  {
  	struct ias_object *obj;
  
  	for (obj = (struct ias_object *) hashbin_get_first(irias_objects);
  	     obj; obj = (struct ias_object *) hashbin_get_next(irias_objects)) {
  		if (pos-- == 0)
  			break;
  	}
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
979

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
980
981
982
983
984
985
986
987
988
989
990
991
992
  	return obj;
  }
  
  static void *irias_seq_start(struct seq_file *seq, loff_t *pos)
  {
  	spin_lock_irq(&irias_objects->hb_spinlock);
  
  	return *pos ? irias_seq_idx(*pos - 1) : SEQ_START_TOKEN;
  }
  
  static void *irias_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  {
  	++*pos;
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
993
  	return (v == SEQ_START_TOKEN)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
  		? (void *) hashbin_get_first(irias_objects)
  		: (void *) hashbin_get_next(irias_objects);
  }
  
  static void irias_seq_stop(struct seq_file *seq, void *v)
  {
  	spin_unlock_irq(&irias_objects->hb_spinlock);
  }
  
  static int irias_seq_show(struct seq_file *seq, void *v)
  {
  	if (v == SEQ_START_TOKEN)
  		seq_puts(seq, "LM-IAS Objects:
  ");
  	else {
  		struct ias_object *obj = v;
  		struct ias_attrib *attrib;
  
  		IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return -EINVAL;);
  
  		seq_printf(seq, "name: %s, id=%d
  ",
  			   obj->name, obj->id);
  
  		/* Careful for priority inversions here !
  		 * All other uses of attrib spinlock are independent of
  		 * the object spinlock, so we are safe. Jean II */
  		spin_lock(&obj->attribs->hb_spinlock);
  
  		/* List all attributes for this object */
  		for (attrib = (struct ias_attrib *) hashbin_get_first(obj->attribs);
  		     attrib != NULL;
  		     attrib = (struct ias_attrib *) hashbin_get_next(obj->attribs)) {
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
1027

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
  			IRDA_ASSERT(attrib->magic == IAS_ATTRIB_MAGIC,
  				    goto outloop; );
  
  			seq_printf(seq, " - Attribute name: \"%s\", ",
  				   attrib->name);
  			seq_printf(seq, "value[%s]: ",
  				   ias_value_types[attrib->value->type]);
  
  			switch (attrib->value->type) {
  			case IAS_INTEGER:
  				seq_printf(seq, "%d
  ",
  					   attrib->value->t.integer);
  				break;
  			case IAS_STRING:
  				seq_printf(seq, "\"%s\"
  ",
  					   attrib->value->t.string);
  				break;
  			case IAS_OCT_SEQ:
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
1048
1049
  				seq_printf(seq, "octet sequence (%d bytes)
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1050
1051
1052
1053
1054
1055
1056
  					   attrib->value->len);
  				break;
  			case IAS_MISSING:
  				seq_puts(seq, "missing
  ");
  				break;
  			default:
6819bc2e1   YOSHIFUJI Hideaki   [NET] IRDA: Fix w...
1057
1058
  				seq_printf(seq, "type %d?
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
  					   attrib->value->type);
  			}
  			seq_putc(seq, '
  ');
  
  		}
  	IRDA_ASSERT_LABEL(outloop:)
  		spin_unlock(&obj->attribs->hb_spinlock);
  	}
  
  	return 0;
  }
56b3d975b   Philippe De Muyter   [NET]: Make all i...
1071
  static const struct seq_operations irias_seq_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
  	.start  = irias_seq_start,
  	.next   = irias_seq_next,
  	.stop   = irias_seq_stop,
  	.show   = irias_seq_show,
  };
  
  static int irias_seq_open(struct inode *inode, struct file *file)
  {
  	IRDA_ASSERT( irias_objects != NULL, return -EINVAL;);
  
  	return seq_open(file, &irias_seq_ops);
  }
da7071d7e   Arjan van de Ven   [PATCH] mark stru...
1084
  const struct file_operations irias_seq_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1085
1086
1087
1088
1089
1090
1091
1092
  	.owner		= THIS_MODULE,
  	.open           = irias_seq_open,
  	.read           = seq_read,
  	.llseek         = seq_lseek,
  	.release	= seq_release,
  };
  
  #endif /* PROC_FS */