PageRenderTime 33ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/net/irda/iriap.c

https://github.com/mstsirkin/kvm
C | 1104 lines | 691 code | 195 blank | 218 comment | 98 complexity | f547027f9b28f8ef1ce6fc1a64003bc6 MD5 | raw file
  1. /*********************************************************************
  2. *
  3. * Filename: iriap.c
  4. * Version: 0.8
  5. * Description: Information Access Protocol (IAP)
  6. * Status: Experimental.
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Thu Aug 21 00:02:07 1997
  9. * Modified at: Sat Dec 25 16:42:42 1999
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
  13. * All Rights Reserved.
  14. * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * Neither Dag Brattli nor University of Tromsø admit liability nor
  22. * provide warranty for any of this software. This material is
  23. * provided "AS-IS" and at no charge.
  24. *
  25. ********************************************************************/
  26. #include <linux/module.h>
  27. #include <linux/types.h>
  28. #include <linux/skbuff.h>
  29. #include <linux/fs.h>
  30. #include <linux/string.h>
  31. #include <linux/init.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/slab.h>
  34. #include <asm/byteorder.h>
  35. #include <asm/unaligned.h>
  36. #include <net/irda/irda.h>
  37. #include <net/irda/irttp.h>
  38. #include <net/irda/irlmp.h>
  39. #include <net/irda/irias_object.h>
  40. #include <net/irda/iriap_event.h>
  41. #include <net/irda/iriap.h>
  42. #ifdef CONFIG_IRDA_DEBUG
  43. /* FIXME: This one should go in irlmp.c */
  44. static const char *const ias_charset_types[] = {
  45. "CS_ASCII",
  46. "CS_ISO_8859_1",
  47. "CS_ISO_8859_2",
  48. "CS_ISO_8859_3",
  49. "CS_ISO_8859_4",
  50. "CS_ISO_8859_5",
  51. "CS_ISO_8859_6",
  52. "CS_ISO_8859_7",
  53. "CS_ISO_8859_8",
  54. "CS_ISO_8859_9",
  55. "CS_UNICODE"
  56. };
  57. #endif /* CONFIG_IRDA_DEBUG */
  58. static hashbin_t *iriap = NULL;
  59. static void *service_handle;
  60. static void __iriap_close(struct iriap_cb *self);
  61. static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode);
  62. static void iriap_disconnect_indication(void *instance, void *sap,
  63. LM_REASON reason, struct sk_buff *skb);
  64. static void iriap_connect_indication(void *instance, void *sap,
  65. struct qos_info *qos, __u32 max_sdu_size,
  66. __u8 max_header_size,
  67. struct sk_buff *skb);
  68. static void iriap_connect_confirm(void *instance, void *sap,
  69. struct qos_info *qos,
  70. __u32 max_sdu_size, __u8 max_header_size,
  71. struct sk_buff *skb);
  72. static int iriap_data_indication(void *instance, void *sap,
  73. struct sk_buff *skb);
  74. static void iriap_watchdog_timer_expired(void *data);
  75. static inline void iriap_start_watchdog_timer(struct iriap_cb *self,
  76. int timeout)
  77. {
  78. irda_start_timer(&self->watchdog_timer, timeout, self,
  79. iriap_watchdog_timer_expired);
  80. }
  81. static struct lock_class_key irias_objects_key;
  82. /*
  83. * Function iriap_init (void)
  84. *
  85. * Initializes the IrIAP layer, called by the module initialization code
  86. * in irmod.c
  87. */
  88. int __init iriap_init(void)
  89. {
  90. struct ias_object *obj;
  91. struct iriap_cb *server;
  92. __u8 oct_seq[6];
  93. __u16 hints;
  94. /* Allocate master array */
  95. iriap = hashbin_new(HB_LOCK);
  96. if (!iriap)
  97. return -ENOMEM;
  98. /* Object repository - defined in irias_object.c */
  99. irias_objects = hashbin_new(HB_LOCK);
  100. if (!irias_objects) {
  101. IRDA_WARNING("%s: Can't allocate irias_objects hashbin!\n",
  102. __func__);
  103. hashbin_delete(iriap, NULL);
  104. return -ENOMEM;
  105. }
  106. lockdep_set_class_and_name(&irias_objects->hb_spinlock, &irias_objects_key,
  107. "irias_objects");
  108. /*
  109. * Register some default services for IrLMP
  110. */
  111. hints = irlmp_service_to_hint(S_COMPUTER);
  112. service_handle = irlmp_register_service(hints);
  113. /* Register the Device object with LM-IAS */
  114. obj = irias_new_object("Device", IAS_DEVICE_ID);
  115. irias_add_string_attrib(obj, "DeviceName", "Linux", IAS_KERNEL_ATTR);
  116. oct_seq[0] = 0x01; /* Version 1 */
  117. oct_seq[1] = 0x00; /* IAS support bits */
  118. oct_seq[2] = 0x00; /* LM-MUX support bits */
  119. #ifdef CONFIG_IRDA_ULTRA
  120. oct_seq[2] |= 0x04; /* Connectionless Data support */
  121. #endif
  122. irias_add_octseq_attrib(obj, "IrLMPSupport", oct_seq, 3,
  123. IAS_KERNEL_ATTR);
  124. irias_insert_object(obj);
  125. /*
  126. * Register server support with IrLMP so we can accept incoming
  127. * connections
  128. */
  129. server = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
  130. if (!server) {
  131. IRDA_DEBUG(0, "%s(), unable to open server\n", __func__);
  132. return -1;
  133. }
  134. iriap_register_lsap(server, LSAP_IAS, IAS_SERVER);
  135. return 0;
  136. }
  137. /*
  138. * Function iriap_cleanup (void)
  139. *
  140. * Initializes the IrIAP layer, called by the module cleanup code in
  141. * irmod.c
  142. */
  143. void iriap_cleanup(void)
  144. {
  145. irlmp_unregister_service(service_handle);
  146. hashbin_delete(iriap, (FREE_FUNC) __iriap_close);
  147. hashbin_delete(irias_objects, (FREE_FUNC) __irias_delete_object);
  148. }
  149. /*
  150. * Function iriap_open (void)
  151. *
  152. * Opens an instance of the IrIAP layer, and registers with IrLMP
  153. */
  154. struct iriap_cb *iriap_open(__u8 slsap_sel, int mode, void *priv,
  155. CONFIRM_CALLBACK callback)
  156. {
  157. struct iriap_cb *self;
  158. IRDA_DEBUG(2, "%s()\n", __func__);
  159. self = kzalloc(sizeof(*self), GFP_ATOMIC);
  160. if (!self) {
  161. IRDA_WARNING("%s: Unable to kmalloc!\n", __func__);
  162. return NULL;
  163. }
  164. /*
  165. * Initialize instance
  166. */
  167. self->magic = IAS_MAGIC;
  168. self->mode = mode;
  169. if (mode == IAS_CLIENT)
  170. iriap_register_lsap(self, slsap_sel, mode);
  171. self->confirm = callback;
  172. self->priv = priv;
  173. /* iriap_getvaluebyclass_request() will construct packets before
  174. * we connect, so this must have a sane value... Jean II */
  175. self->max_header_size = LMP_MAX_HEADER;
  176. init_timer(&self->watchdog_timer);
  177. hashbin_insert(iriap, (irda_queue_t *) self, (long) self, NULL);
  178. /* Initialize state machines */
  179. iriap_next_client_state(self, S_DISCONNECT);
  180. iriap_next_call_state(self, S_MAKE_CALL);
  181. iriap_next_server_state(self, R_DISCONNECT);
  182. iriap_next_r_connect_state(self, R_WAITING);
  183. return self;
  184. }
  185. EXPORT_SYMBOL(iriap_open);
  186. /*
  187. * Function __iriap_close (self)
  188. *
  189. * Removes (deallocates) the IrIAP instance
  190. *
  191. */
  192. static void __iriap_close(struct iriap_cb *self)
  193. {
  194. IRDA_DEBUG(4, "%s()\n", __func__);
  195. IRDA_ASSERT(self != NULL, return;);
  196. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  197. del_timer(&self->watchdog_timer);
  198. if (self->request_skb)
  199. dev_kfree_skb(self->request_skb);
  200. self->magic = 0;
  201. kfree(self);
  202. }
  203. /*
  204. * Function iriap_close (void)
  205. *
  206. * Closes IrIAP and deregisters with IrLMP
  207. */
  208. void iriap_close(struct iriap_cb *self)
  209. {
  210. struct iriap_cb *entry;
  211. IRDA_DEBUG(2, "%s()\n", __func__);
  212. IRDA_ASSERT(self != NULL, return;);
  213. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  214. if (self->lsap) {
  215. irlmp_close_lsap(self->lsap);
  216. self->lsap = NULL;
  217. }
  218. entry = (struct iriap_cb *) hashbin_remove(iriap, (long) self, NULL);
  219. IRDA_ASSERT(entry == self, return;);
  220. __iriap_close(self);
  221. }
  222. EXPORT_SYMBOL(iriap_close);
  223. static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode)
  224. {
  225. notify_t notify;
  226. IRDA_DEBUG(2, "%s()\n", __func__);
  227. irda_notify_init(&notify);
  228. notify.connect_confirm = iriap_connect_confirm;
  229. notify.connect_indication = iriap_connect_indication;
  230. notify.disconnect_indication = iriap_disconnect_indication;
  231. notify.data_indication = iriap_data_indication;
  232. notify.instance = self;
  233. if (mode == IAS_CLIENT)
  234. strcpy(notify.name, "IrIAS cli");
  235. else
  236. strcpy(notify.name, "IrIAS srv");
  237. self->lsap = irlmp_open_lsap(slsap_sel, &notify, 0);
  238. if (self->lsap == NULL) {
  239. IRDA_ERROR("%s: Unable to allocated LSAP!\n", __func__);
  240. return -1;
  241. }
  242. self->slsap_sel = self->lsap->slsap_sel;
  243. return 0;
  244. }
  245. /*
  246. * Function iriap_disconnect_indication (handle, reason)
  247. *
  248. * Got disconnect, so clean up everything associated with this connection
  249. *
  250. */
  251. static void iriap_disconnect_indication(void *instance, void *sap,
  252. LM_REASON reason,
  253. struct sk_buff *skb)
  254. {
  255. struct iriap_cb *self;
  256. IRDA_DEBUG(4, "%s(), reason=%s\n", __func__, irlmp_reasons[reason]);
  257. self = instance;
  258. IRDA_ASSERT(self != NULL, return;);
  259. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  260. IRDA_ASSERT(iriap != NULL, return;);
  261. del_timer(&self->watchdog_timer);
  262. /* Not needed */
  263. if (skb)
  264. dev_kfree_skb(skb);
  265. if (self->mode == IAS_CLIENT) {
  266. IRDA_DEBUG(4, "%s(), disconnect as client\n", __func__);
  267. iriap_do_client_event(self, IAP_LM_DISCONNECT_INDICATION,
  268. NULL);
  269. /*
  270. * Inform service user that the request failed by sending
  271. * it a NULL value. Warning, the client might close us, so
  272. * remember no to use self anymore after calling confirm
  273. */
  274. if (self->confirm)
  275. self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
  276. } else {
  277. IRDA_DEBUG(4, "%s(), disconnect as server\n", __func__);
  278. iriap_do_server_event(self, IAP_LM_DISCONNECT_INDICATION,
  279. NULL);
  280. iriap_close(self);
  281. }
  282. }
  283. /*
  284. * Function iriap_disconnect_request (handle)
  285. */
  286. static void iriap_disconnect_request(struct iriap_cb *self)
  287. {
  288. struct sk_buff *tx_skb;
  289. IRDA_DEBUG(4, "%s()\n", __func__);
  290. IRDA_ASSERT(self != NULL, return;);
  291. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  292. tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
  293. if (tx_skb == NULL) {
  294. IRDA_DEBUG(0,
  295. "%s(), Could not allocate an sk_buff of length %d\n",
  296. __func__, LMP_MAX_HEADER);
  297. return;
  298. }
  299. /*
  300. * Reserve space for MUX control and LAP header
  301. */
  302. skb_reserve(tx_skb, LMP_MAX_HEADER);
  303. irlmp_disconnect_request(self->lsap, tx_skb);
  304. }
  305. /*
  306. * Function iriap_getvaluebyclass (addr, name, attr)
  307. *
  308. * Retrieve all values from attribute in all objects with given class
  309. * name
  310. */
  311. int iriap_getvaluebyclass_request(struct iriap_cb *self,
  312. __u32 saddr, __u32 daddr,
  313. char *name, char *attr)
  314. {
  315. struct sk_buff *tx_skb;
  316. int name_len, attr_len, skb_len;
  317. __u8 *frame;
  318. IRDA_ASSERT(self != NULL, return -1;);
  319. IRDA_ASSERT(self->magic == IAS_MAGIC, return -1;);
  320. /* Client must supply the destination device address */
  321. if (!daddr)
  322. return -1;
  323. self->daddr = daddr;
  324. self->saddr = saddr;
  325. /*
  326. * Save operation, so we know what the later indication is about
  327. */
  328. self->operation = GET_VALUE_BY_CLASS;
  329. /* Give ourselves 10 secs to finish this operation */
  330. iriap_start_watchdog_timer(self, 10*HZ);
  331. name_len = strlen(name); /* Up to IAS_MAX_CLASSNAME = 60 */
  332. attr_len = strlen(attr); /* Up to IAS_MAX_ATTRIBNAME = 60 */
  333. skb_len = self->max_header_size+2+name_len+1+attr_len+4;
  334. tx_skb = alloc_skb(skb_len, GFP_ATOMIC);
  335. if (!tx_skb)
  336. return -ENOMEM;
  337. /* Reserve space for MUX and LAP header */
  338. skb_reserve(tx_skb, self->max_header_size);
  339. skb_put(tx_skb, 3+name_len+attr_len);
  340. frame = tx_skb->data;
  341. /* Build frame */
  342. frame[0] = IAP_LST | GET_VALUE_BY_CLASS;
  343. frame[1] = name_len; /* Insert length of name */
  344. memcpy(frame+2, name, name_len); /* Insert name */
  345. frame[2+name_len] = attr_len; /* Insert length of attr */
  346. memcpy(frame+3+name_len, attr, attr_len); /* Insert attr */
  347. iriap_do_client_event(self, IAP_CALL_REQUEST_GVBC, tx_skb);
  348. /* Drop reference count - see state_s_disconnect(). */
  349. dev_kfree_skb(tx_skb);
  350. return 0;
  351. }
  352. EXPORT_SYMBOL(iriap_getvaluebyclass_request);
  353. /*
  354. * Function iriap_getvaluebyclass_confirm (self, skb)
  355. *
  356. * Got result from GetValueByClass command. Parse it and return result
  357. * to service user.
  358. *
  359. */
  360. static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
  361. struct sk_buff *skb)
  362. {
  363. struct ias_value *value;
  364. int charset;
  365. __u32 value_len;
  366. __u32 tmp_cpu32;
  367. __u16 obj_id;
  368. __u16 len;
  369. __u8 type;
  370. __u8 *fp;
  371. int n;
  372. IRDA_ASSERT(self != NULL, return;);
  373. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  374. IRDA_ASSERT(skb != NULL, return;);
  375. /* Initialize variables */
  376. fp = skb->data;
  377. n = 2;
  378. /* Get length, MSB first */
  379. len = get_unaligned_be16(fp + n);
  380. n += 2;
  381. IRDA_DEBUG(4, "%s(), len=%d\n", __func__, len);
  382. /* Get object ID, MSB first */
  383. obj_id = get_unaligned_be16(fp + n);
  384. n += 2;
  385. type = fp[n++];
  386. IRDA_DEBUG(4, "%s(), Value type = %d\n", __func__, type);
  387. switch (type) {
  388. case IAS_INTEGER:
  389. memcpy(&tmp_cpu32, fp+n, 4); n += 4;
  390. be32_to_cpus(&tmp_cpu32);
  391. value = irias_new_integer_value(tmp_cpu32);
  392. /* Legal values restricted to 0x01-0x6f, page 15 irttp */
  393. IRDA_DEBUG(4, "%s(), lsap=%d\n", __func__, value->t.integer);
  394. break;
  395. case IAS_STRING:
  396. charset = fp[n++];
  397. switch (charset) {
  398. case CS_ASCII:
  399. break;
  400. /* case CS_ISO_8859_1: */
  401. /* case CS_ISO_8859_2: */
  402. /* case CS_ISO_8859_3: */
  403. /* case CS_ISO_8859_4: */
  404. /* case CS_ISO_8859_5: */
  405. /* case CS_ISO_8859_6: */
  406. /* case CS_ISO_8859_7: */
  407. /* case CS_ISO_8859_8: */
  408. /* case CS_ISO_8859_9: */
  409. /* case CS_UNICODE: */
  410. default:
  411. IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
  412. __func__, ias_charset_types[charset]);
  413. /* Aborting, close connection! */
  414. iriap_disconnect_request(self);
  415. return;
  416. /* break; */
  417. }
  418. value_len = fp[n++];
  419. IRDA_DEBUG(4, "%s(), strlen=%d\n", __func__, value_len);
  420. /* Make sure the string is null-terminated */
  421. if (n + value_len < skb->len)
  422. fp[n + value_len] = 0x00;
  423. IRDA_DEBUG(4, "Got string %s\n", fp+n);
  424. /* Will truncate to IAS_MAX_STRING bytes */
  425. value = irias_new_string_value(fp+n);
  426. break;
  427. case IAS_OCT_SEQ:
  428. value_len = get_unaligned_be16(fp + n);
  429. n += 2;
  430. /* Will truncate to IAS_MAX_OCTET_STRING bytes */
  431. value = irias_new_octseq_value(fp+n, value_len);
  432. break;
  433. default:
  434. value = irias_new_missing_value();
  435. break;
  436. }
  437. /* Finished, close connection! */
  438. iriap_disconnect_request(self);
  439. /* Warning, the client might close us, so remember no to use self
  440. * anymore after calling confirm
  441. */
  442. if (self->confirm)
  443. self->confirm(IAS_SUCCESS, obj_id, value, self->priv);
  444. else {
  445. IRDA_DEBUG(0, "%s(), missing handler!\n", __func__);
  446. irias_delete_value(value);
  447. }
  448. }
  449. /*
  450. * Function iriap_getvaluebyclass_response ()
  451. *
  452. * Send answer back to remote LM-IAS
  453. *
  454. */
  455. static void iriap_getvaluebyclass_response(struct iriap_cb *self,
  456. __u16 obj_id,
  457. __u8 ret_code,
  458. struct ias_value *value)
  459. {
  460. struct sk_buff *tx_skb;
  461. int n;
  462. __be32 tmp_be32;
  463. __be16 tmp_be16;
  464. __u8 *fp;
  465. IRDA_DEBUG(4, "%s()\n", __func__);
  466. IRDA_ASSERT(self != NULL, return;);
  467. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  468. IRDA_ASSERT(value != NULL, return;);
  469. IRDA_ASSERT(value->len <= 1024, return;);
  470. /* Initialize variables */
  471. n = 0;
  472. /*
  473. * We must adjust the size of the response after the length of the
  474. * value. We add 32 bytes because of the 6 bytes for the frame and
  475. * max 5 bytes for the value coding.
  476. */
  477. tx_skb = alloc_skb(value->len + self->max_header_size + 32,
  478. GFP_ATOMIC);
  479. if (!tx_skb)
  480. return;
  481. /* Reserve space for MUX and LAP header */
  482. skb_reserve(tx_skb, self->max_header_size);
  483. skb_put(tx_skb, 6);
  484. fp = tx_skb->data;
  485. /* Build frame */
  486. fp[n++] = GET_VALUE_BY_CLASS | IAP_LST;
  487. fp[n++] = ret_code;
  488. /* Insert list length (MSB first) */
  489. tmp_be16 = htons(0x0001);
  490. memcpy(fp+n, &tmp_be16, 2); n += 2;
  491. /* Insert object identifier ( MSB first) */
  492. tmp_be16 = cpu_to_be16(obj_id);
  493. memcpy(fp+n, &tmp_be16, 2); n += 2;
  494. switch (value->type) {
  495. case IAS_STRING:
  496. skb_put(tx_skb, 3 + value->len);
  497. fp[n++] = value->type;
  498. fp[n++] = 0; /* ASCII */
  499. fp[n++] = (__u8) value->len;
  500. memcpy(fp+n, value->t.string, value->len); n+=value->len;
  501. break;
  502. case IAS_INTEGER:
  503. skb_put(tx_skb, 5);
  504. fp[n++] = value->type;
  505. tmp_be32 = cpu_to_be32(value->t.integer);
  506. memcpy(fp+n, &tmp_be32, 4); n += 4;
  507. break;
  508. case IAS_OCT_SEQ:
  509. skb_put(tx_skb, 3 + value->len);
  510. fp[n++] = value->type;
  511. tmp_be16 = cpu_to_be16(value->len);
  512. memcpy(fp+n, &tmp_be16, 2); n += 2;
  513. memcpy(fp+n, value->t.oct_seq, value->len); n+=value->len;
  514. break;
  515. case IAS_MISSING:
  516. IRDA_DEBUG( 3, "%s: sending IAS_MISSING\n", __func__);
  517. skb_put(tx_skb, 1);
  518. fp[n++] = value->type;
  519. break;
  520. default:
  521. IRDA_DEBUG(0, "%s(), type not implemented!\n", __func__);
  522. break;
  523. }
  524. iriap_do_r_connect_event(self, IAP_CALL_RESPONSE, tx_skb);
  525. /* Drop reference count - see state_r_execute(). */
  526. dev_kfree_skb(tx_skb);
  527. }
  528. /*
  529. * Function iriap_getvaluebyclass_indication (self, skb)
  530. *
  531. * getvaluebyclass is requested from peer LM-IAS
  532. *
  533. */
  534. static void iriap_getvaluebyclass_indication(struct iriap_cb *self,
  535. struct sk_buff *skb)
  536. {
  537. struct ias_object *obj;
  538. struct ias_attrib *attrib;
  539. int name_len;
  540. int attr_len;
  541. char name[IAS_MAX_CLASSNAME + 1]; /* 60 bytes */
  542. char attr[IAS_MAX_ATTRIBNAME + 1]; /* 60 bytes */
  543. __u8 *fp;
  544. int n;
  545. IRDA_DEBUG(4, "%s()\n", __func__);
  546. IRDA_ASSERT(self != NULL, return;);
  547. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  548. IRDA_ASSERT(skb != NULL, return;);
  549. fp = skb->data;
  550. n = 1;
  551. name_len = fp[n++];
  552. IRDA_ASSERT(name_len < IAS_MAX_CLASSNAME + 1, return;);
  553. memcpy(name, fp+n, name_len); n+=name_len;
  554. name[name_len] = '\0';
  555. attr_len = fp[n++];
  556. IRDA_ASSERT(attr_len < IAS_MAX_ATTRIBNAME + 1, return;);
  557. memcpy(attr, fp+n, attr_len); n+=attr_len;
  558. attr[attr_len] = '\0';
  559. IRDA_DEBUG(4, "LM-IAS: Looking up %s: %s\n", name, attr);
  560. obj = irias_find_object(name);
  561. if (obj == NULL) {
  562. IRDA_DEBUG(2, "LM-IAS: Object %s not found\n", name);
  563. iriap_getvaluebyclass_response(self, 0x1235, IAS_CLASS_UNKNOWN,
  564. &irias_missing);
  565. return;
  566. }
  567. IRDA_DEBUG(4, "LM-IAS: found %s, id=%d\n", obj->name, obj->id);
  568. attrib = irias_find_attrib(obj, attr);
  569. if (attrib == NULL) {
  570. IRDA_DEBUG(2, "LM-IAS: Attribute %s not found\n", attr);
  571. iriap_getvaluebyclass_response(self, obj->id,
  572. IAS_ATTRIB_UNKNOWN,
  573. &irias_missing);
  574. return;
  575. }
  576. /* We have a match; send the value. */
  577. iriap_getvaluebyclass_response(self, obj->id, IAS_SUCCESS,
  578. attrib->value);
  579. }
  580. /*
  581. * Function iriap_send_ack (void)
  582. *
  583. * Currently not used
  584. *
  585. */
  586. void iriap_send_ack(struct iriap_cb *self)
  587. {
  588. struct sk_buff *tx_skb;
  589. __u8 *frame;
  590. IRDA_DEBUG(2, "%s()\n", __func__);
  591. IRDA_ASSERT(self != NULL, return;);
  592. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  593. tx_skb = alloc_skb(LMP_MAX_HEADER + 1, GFP_ATOMIC);
  594. if (!tx_skb)
  595. return;
  596. /* Reserve space for MUX and LAP header */
  597. skb_reserve(tx_skb, self->max_header_size);
  598. skb_put(tx_skb, 1);
  599. frame = tx_skb->data;
  600. /* Build frame */
  601. frame[0] = IAP_LST | IAP_ACK | self->operation;
  602. irlmp_data_request(self->lsap, tx_skb);
  603. }
  604. void iriap_connect_request(struct iriap_cb *self)
  605. {
  606. int ret;
  607. IRDA_ASSERT(self != NULL, return;);
  608. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  609. ret = irlmp_connect_request(self->lsap, LSAP_IAS,
  610. self->saddr, self->daddr,
  611. NULL, NULL);
  612. if (ret < 0) {
  613. IRDA_DEBUG(0, "%s(), connect failed!\n", __func__);
  614. self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
  615. }
  616. }
  617. /*
  618. * Function iriap_connect_confirm (handle, skb)
  619. *
  620. * LSAP connection confirmed!
  621. *
  622. */
  623. static void iriap_connect_confirm(void *instance, void *sap,
  624. struct qos_info *qos, __u32 max_seg_size,
  625. __u8 max_header_size,
  626. struct sk_buff *skb)
  627. {
  628. struct iriap_cb *self;
  629. self = instance;
  630. IRDA_ASSERT(self != NULL, return;);
  631. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  632. IRDA_ASSERT(skb != NULL, return;);
  633. self->max_data_size = max_seg_size;
  634. self->max_header_size = max_header_size;
  635. del_timer(&self->watchdog_timer);
  636. iriap_do_client_event(self, IAP_LM_CONNECT_CONFIRM, skb);
  637. /* Drop reference count - see state_s_make_call(). */
  638. dev_kfree_skb(skb);
  639. }
  640. /*
  641. * Function iriap_connect_indication ( handle, skb)
  642. *
  643. * Remote LM-IAS is requesting connection
  644. *
  645. */
  646. static void iriap_connect_indication(void *instance, void *sap,
  647. struct qos_info *qos, __u32 max_seg_size,
  648. __u8 max_header_size,
  649. struct sk_buff *skb)
  650. {
  651. struct iriap_cb *self, *new;
  652. IRDA_DEBUG(1, "%s()\n", __func__);
  653. self = instance;
  654. IRDA_ASSERT(skb != NULL, return;);
  655. IRDA_ASSERT(self != NULL, goto out;);
  656. IRDA_ASSERT(self->magic == IAS_MAGIC, goto out;);
  657. /* Start new server */
  658. new = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
  659. if (!new) {
  660. IRDA_DEBUG(0, "%s(), open failed\n", __func__);
  661. goto out;
  662. }
  663. /* Now attach up the new "socket" */
  664. new->lsap = irlmp_dup(self->lsap, new);
  665. if (!new->lsap) {
  666. IRDA_DEBUG(0, "%s(), dup failed!\n", __func__);
  667. goto out;
  668. }
  669. new->max_data_size = max_seg_size;
  670. new->max_header_size = max_header_size;
  671. /* Clean up the original one to keep it in listen state */
  672. irlmp_listen(self->lsap);
  673. iriap_do_server_event(new, IAP_LM_CONNECT_INDICATION, skb);
  674. out:
  675. /* Drop reference count - see state_r_disconnect(). */
  676. dev_kfree_skb(skb);
  677. }
  678. /*
  679. * Function iriap_data_indication (handle, skb)
  680. *
  681. * Receives data from connection identified by handle from IrLMP
  682. *
  683. */
  684. static int iriap_data_indication(void *instance, void *sap,
  685. struct sk_buff *skb)
  686. {
  687. struct iriap_cb *self;
  688. __u8 *frame;
  689. __u8 opcode;
  690. IRDA_DEBUG(3, "%s()\n", __func__);
  691. self = instance;
  692. IRDA_ASSERT(skb != NULL, return 0;);
  693. IRDA_ASSERT(self != NULL, goto out;);
  694. IRDA_ASSERT(self->magic == IAS_MAGIC, goto out;);
  695. frame = skb->data;
  696. if (self->mode == IAS_SERVER) {
  697. /* Call server */
  698. IRDA_DEBUG(4, "%s(), Calling server!\n", __func__);
  699. iriap_do_r_connect_event(self, IAP_RECV_F_LST, skb);
  700. goto out;
  701. }
  702. opcode = frame[0];
  703. if (~opcode & IAP_LST) {
  704. IRDA_WARNING("%s:, IrIAS multiframe commands or "
  705. "results is not implemented yet!\n",
  706. __func__);
  707. goto out;
  708. }
  709. /* Check for ack frames since they don't contain any data */
  710. if (opcode & IAP_ACK) {
  711. IRDA_DEBUG(0, "%s() Got ack frame!\n", __func__);
  712. goto out;
  713. }
  714. opcode &= ~IAP_LST; /* Mask away LST bit */
  715. switch (opcode) {
  716. case GET_INFO_BASE:
  717. IRDA_DEBUG(0, "IrLMP GetInfoBaseDetails not implemented!\n");
  718. break;
  719. case GET_VALUE_BY_CLASS:
  720. iriap_do_call_event(self, IAP_RECV_F_LST, NULL);
  721. switch (frame[1]) {
  722. case IAS_SUCCESS:
  723. iriap_getvaluebyclass_confirm(self, skb);
  724. break;
  725. case IAS_CLASS_UNKNOWN:
  726. IRDA_DEBUG(1, "%s(), No such class!\n", __func__);
  727. /* Finished, close connection! */
  728. iriap_disconnect_request(self);
  729. /*
  730. * Warning, the client might close us, so remember
  731. * no to use self anymore after calling confirm
  732. */
  733. if (self->confirm)
  734. self->confirm(IAS_CLASS_UNKNOWN, 0, NULL,
  735. self->priv);
  736. break;
  737. case IAS_ATTRIB_UNKNOWN:
  738. IRDA_DEBUG(1, "%s(), No such attribute!\n", __func__);
  739. /* Finished, close connection! */
  740. iriap_disconnect_request(self);
  741. /*
  742. * Warning, the client might close us, so remember
  743. * no to use self anymore after calling confirm
  744. */
  745. if (self->confirm)
  746. self->confirm(IAS_ATTRIB_UNKNOWN, 0, NULL,
  747. self->priv);
  748. break;
  749. }
  750. break;
  751. default:
  752. IRDA_DEBUG(0, "%s(), Unknown op-code: %02x\n", __func__,
  753. opcode);
  754. break;
  755. }
  756. out:
  757. /* Cleanup - sub-calls will have done skb_get() as needed. */
  758. dev_kfree_skb(skb);
  759. return 0;
  760. }
  761. /*
  762. * Function iriap_call_indication (self, skb)
  763. *
  764. * Received call to server from peer LM-IAS
  765. *
  766. */
  767. void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
  768. {
  769. __u8 *fp;
  770. __u8 opcode;
  771. IRDA_DEBUG(4, "%s()\n", __func__);
  772. IRDA_ASSERT(self != NULL, return;);
  773. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  774. IRDA_ASSERT(skb != NULL, return;);
  775. fp = skb->data;
  776. opcode = fp[0];
  777. if (~opcode & 0x80) {
  778. IRDA_WARNING("%s: IrIAS multiframe commands or results "
  779. "is not implemented yet!\n", __func__);
  780. return;
  781. }
  782. opcode &= 0x7f; /* Mask away LST bit */
  783. switch (opcode) {
  784. case GET_INFO_BASE:
  785. IRDA_WARNING("%s: GetInfoBaseDetails not implemented yet!\n",
  786. __func__);
  787. break;
  788. case GET_VALUE_BY_CLASS:
  789. iriap_getvaluebyclass_indication(self, skb);
  790. break;
  791. }
  792. /* skb will be cleaned up in iriap_data_indication */
  793. }
  794. /*
  795. * Function iriap_watchdog_timer_expired (data)
  796. *
  797. * Query has taken too long time, so abort
  798. *
  799. */
  800. static void iriap_watchdog_timer_expired(void *data)
  801. {
  802. struct iriap_cb *self = (struct iriap_cb *) data;
  803. IRDA_ASSERT(self != NULL, return;);
  804. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  805. /* iriap_close(self); */
  806. }
  807. #ifdef CONFIG_PROC_FS
  808. static const char *const ias_value_types[] = {
  809. "IAS_MISSING",
  810. "IAS_INTEGER",
  811. "IAS_OCT_SEQ",
  812. "IAS_STRING"
  813. };
  814. static inline struct ias_object *irias_seq_idx(loff_t pos)
  815. {
  816. struct ias_object *obj;
  817. for (obj = (struct ias_object *) hashbin_get_first(irias_objects);
  818. obj; obj = (struct ias_object *) hashbin_get_next(irias_objects)) {
  819. if (pos-- == 0)
  820. break;
  821. }
  822. return obj;
  823. }
  824. static void *irias_seq_start(struct seq_file *seq, loff_t *pos)
  825. {
  826. spin_lock_irq(&irias_objects->hb_spinlock);
  827. return *pos ? irias_seq_idx(*pos - 1) : SEQ_START_TOKEN;
  828. }
  829. static void *irias_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  830. {
  831. ++*pos;
  832. return (v == SEQ_START_TOKEN)
  833. ? (void *) hashbin_get_first(irias_objects)
  834. : (void *) hashbin_get_next(irias_objects);
  835. }
  836. static void irias_seq_stop(struct seq_file *seq, void *v)
  837. {
  838. spin_unlock_irq(&irias_objects->hb_spinlock);
  839. }
  840. static int irias_seq_show(struct seq_file *seq, void *v)
  841. {
  842. if (v == SEQ_START_TOKEN)
  843. seq_puts(seq, "LM-IAS Objects:\n");
  844. else {
  845. struct ias_object *obj = v;
  846. struct ias_attrib *attrib;
  847. IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return -EINVAL;);
  848. seq_printf(seq, "name: %s, id=%d\n",
  849. obj->name, obj->id);
  850. /* Careful for priority inversions here !
  851. * All other uses of attrib spinlock are independent of
  852. * the object spinlock, so we are safe. Jean II */
  853. spin_lock(&obj->attribs->hb_spinlock);
  854. /* List all attributes for this object */
  855. for (attrib = (struct ias_attrib *) hashbin_get_first(obj->attribs);
  856. attrib != NULL;
  857. attrib = (struct ias_attrib *) hashbin_get_next(obj->attribs)) {
  858. IRDA_ASSERT(attrib->magic == IAS_ATTRIB_MAGIC,
  859. goto outloop; );
  860. seq_printf(seq, " - Attribute name: \"%s\", ",
  861. attrib->name);
  862. seq_printf(seq, "value[%s]: ",
  863. ias_value_types[attrib->value->type]);
  864. switch (attrib->value->type) {
  865. case IAS_INTEGER:
  866. seq_printf(seq, "%d\n",
  867. attrib->value->t.integer);
  868. break;
  869. case IAS_STRING:
  870. seq_printf(seq, "\"%s\"\n",
  871. attrib->value->t.string);
  872. break;
  873. case IAS_OCT_SEQ:
  874. seq_printf(seq, "octet sequence (%d bytes)\n",
  875. attrib->value->len);
  876. break;
  877. case IAS_MISSING:
  878. seq_puts(seq, "missing\n");
  879. break;
  880. default:
  881. seq_printf(seq, "type %d?\n",
  882. attrib->value->type);
  883. }
  884. seq_putc(seq, '\n');
  885. }
  886. IRDA_ASSERT_LABEL(outloop:)
  887. spin_unlock(&obj->attribs->hb_spinlock);
  888. }
  889. return 0;
  890. }
  891. static const struct seq_operations irias_seq_ops = {
  892. .start = irias_seq_start,
  893. .next = irias_seq_next,
  894. .stop = irias_seq_stop,
  895. .show = irias_seq_show,
  896. };
  897. static int irias_seq_open(struct inode *inode, struct file *file)
  898. {
  899. IRDA_ASSERT( irias_objects != NULL, return -EINVAL;);
  900. return seq_open(file, &irias_seq_ops);
  901. }
  902. const struct file_operations irias_seq_fops = {
  903. .owner = THIS_MODULE,
  904. .open = irias_seq_open,
  905. .read = seq_read,
  906. .llseek = seq_lseek,
  907. .release = seq_release,
  908. };
  909. #endif /* PROC_FS */