/kernel/2.6.32_froyo_photon_nightly/net/irda/iriap.c

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