iriap_event.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /*********************************************************************
  2. *
  3. * Filename: iriap_event.c
  4. * Version: 0.1
  5. * Description: IAP Finite State Machine
  6. * Status: Experimental.
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Thu Aug 21 00:02:07 1997
  9. * Modified at: Wed Mar 1 11:28:34 2000
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1997, 1999-2000 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 <net/irda/irda.h>
  27. #include <net/irda/irlmp.h>
  28. #include <net/irda/iriap.h>
  29. #include <net/irda/iriap_event.h>
  30. static void state_s_disconnect (struct iriap_cb *self, IRIAP_EVENT event,
  31. struct sk_buff *skb);
  32. static void state_s_connecting (struct iriap_cb *self, IRIAP_EVENT event,
  33. struct sk_buff *skb);
  34. static void state_s_call (struct iriap_cb *self, IRIAP_EVENT event,
  35. struct sk_buff *skb);
  36. static void state_s_make_call (struct iriap_cb *self, IRIAP_EVENT event,
  37. struct sk_buff *skb);
  38. static void state_s_calling (struct iriap_cb *self, IRIAP_EVENT event,
  39. struct sk_buff *skb);
  40. static void state_s_outstanding (struct iriap_cb *self, IRIAP_EVENT event,
  41. struct sk_buff *skb);
  42. static void state_s_replying (struct iriap_cb *self, IRIAP_EVENT event,
  43. struct sk_buff *skb);
  44. static void state_s_wait_for_call(struct iriap_cb *self, IRIAP_EVENT event,
  45. struct sk_buff *skb);
  46. static void state_s_wait_active (struct iriap_cb *self, IRIAP_EVENT event,
  47. struct sk_buff *skb);
  48. static void state_r_disconnect (struct iriap_cb *self, IRIAP_EVENT event,
  49. struct sk_buff *skb);
  50. static void state_r_call (struct iriap_cb *self, IRIAP_EVENT event,
  51. struct sk_buff *skb);
  52. static void state_r_waiting (struct iriap_cb *self, IRIAP_EVENT event,
  53. struct sk_buff *skb);
  54. static void state_r_wait_active (struct iriap_cb *self, IRIAP_EVENT event,
  55. struct sk_buff *skb);
  56. static void state_r_receiving (struct iriap_cb *self, IRIAP_EVENT event,
  57. struct sk_buff *skb);
  58. static void state_r_execute (struct iriap_cb *self, IRIAP_EVENT event,
  59. struct sk_buff *skb);
  60. static void state_r_returning (struct iriap_cb *self, IRIAP_EVENT event,
  61. struct sk_buff *skb);
  62. static void (*iriap_state[])(struct iriap_cb *self, IRIAP_EVENT event,
  63. struct sk_buff *skb) = {
  64. /* Client FSM */
  65. state_s_disconnect,
  66. state_s_connecting,
  67. state_s_call,
  68. /* S-Call FSM */
  69. state_s_make_call,
  70. state_s_calling,
  71. state_s_outstanding,
  72. state_s_replying,
  73. state_s_wait_for_call,
  74. state_s_wait_active,
  75. /* Server FSM */
  76. state_r_disconnect,
  77. state_r_call,
  78. /* R-Connect FSM */
  79. state_r_waiting,
  80. state_r_wait_active,
  81. state_r_receiving,
  82. state_r_execute,
  83. state_r_returning,
  84. };
  85. void iriap_next_client_state(struct iriap_cb *self, IRIAP_STATE state)
  86. {
  87. IRDA_ASSERT(self != NULL, return;);
  88. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  89. self->client_state = state;
  90. }
  91. void iriap_next_call_state(struct iriap_cb *self, IRIAP_STATE state)
  92. {
  93. IRDA_ASSERT(self != NULL, return;);
  94. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  95. self->call_state = state;
  96. }
  97. void iriap_next_server_state(struct iriap_cb *self, IRIAP_STATE state)
  98. {
  99. IRDA_ASSERT(self != NULL, return;);
  100. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  101. self->server_state = state;
  102. }
  103. void iriap_next_r_connect_state(struct iriap_cb *self, IRIAP_STATE state)
  104. {
  105. IRDA_ASSERT(self != NULL, return;);
  106. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  107. self->r_connect_state = state;
  108. }
  109. void iriap_do_client_event(struct iriap_cb *self, IRIAP_EVENT event,
  110. struct sk_buff *skb)
  111. {
  112. IRDA_ASSERT(self != NULL, return;);
  113. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  114. (*iriap_state[ self->client_state]) (self, event, skb);
  115. }
  116. void iriap_do_call_event(struct iriap_cb *self, IRIAP_EVENT event,
  117. struct sk_buff *skb)
  118. {
  119. IRDA_ASSERT(self != NULL, return;);
  120. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  121. (*iriap_state[ self->call_state]) (self, event, skb);
  122. }
  123. void iriap_do_server_event(struct iriap_cb *self, IRIAP_EVENT event,
  124. struct sk_buff *skb)
  125. {
  126. IRDA_ASSERT(self != NULL, return;);
  127. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  128. (*iriap_state[ self->server_state]) (self, event, skb);
  129. }
  130. void iriap_do_r_connect_event(struct iriap_cb *self, IRIAP_EVENT event,
  131. struct sk_buff *skb)
  132. {
  133. IRDA_ASSERT(self != NULL, return;);
  134. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  135. (*iriap_state[ self->r_connect_state]) (self, event, skb);
  136. }
  137. /*
  138. * Function state_s_disconnect (event, skb)
  139. *
  140. * S-Disconnect, The device has no LSAP connection to a particular
  141. * remote device.
  142. */
  143. static void state_s_disconnect(struct iriap_cb *self, IRIAP_EVENT event,
  144. struct sk_buff *skb)
  145. {
  146. IRDA_ASSERT(self != NULL, return;);
  147. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  148. switch (event) {
  149. case IAP_CALL_REQUEST_GVBC:
  150. iriap_next_client_state(self, S_CONNECTING);
  151. IRDA_ASSERT(self->request_skb == NULL, return;);
  152. /* Don't forget to refcount it -
  153. * see iriap_getvaluebyclass_request(). */
  154. skb_get(skb);
  155. self->request_skb = skb;
  156. iriap_connect_request(self);
  157. break;
  158. case IAP_LM_DISCONNECT_INDICATION:
  159. break;
  160. default:
  161. IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__, event);
  162. break;
  163. }
  164. }
  165. /*
  166. * Function state_s_connecting (self, event, skb)
  167. *
  168. * S-Connecting
  169. *
  170. */
  171. static void state_s_connecting(struct iriap_cb *self, IRIAP_EVENT event,
  172. struct sk_buff *skb)
  173. {
  174. IRDA_ASSERT(self != NULL, return;);
  175. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  176. switch (event) {
  177. case IAP_LM_CONNECT_CONFIRM:
  178. /*
  179. * Jump to S-Call FSM
  180. */
  181. iriap_do_call_event(self, IAP_CALL_REQUEST, skb);
  182. /* iriap_call_request(self, 0,0,0); */
  183. iriap_next_client_state(self, S_CALL);
  184. break;
  185. case IAP_LM_DISCONNECT_INDICATION:
  186. /* Abort calls */
  187. iriap_next_call_state(self, S_MAKE_CALL);
  188. iriap_next_client_state(self, S_DISCONNECT);
  189. break;
  190. default:
  191. IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__, event);
  192. break;
  193. }
  194. }
  195. /*
  196. * Function state_s_call (self, event, skb)
  197. *
  198. * S-Call, The device can process calls to a specific remote
  199. * device. Whenever the LSAP connection is disconnected, this state
  200. * catches that event and clears up
  201. */
  202. static void state_s_call(struct iriap_cb *self, IRIAP_EVENT event,
  203. struct sk_buff *skb)
  204. {
  205. IRDA_ASSERT(self != NULL, return;);
  206. switch (event) {
  207. case IAP_LM_DISCONNECT_INDICATION:
  208. /* Abort calls */
  209. iriap_next_call_state(self, S_MAKE_CALL);
  210. iriap_next_client_state(self, S_DISCONNECT);
  211. break;
  212. default:
  213. IRDA_DEBUG(0, "state_s_call: Unknown event %d\n", event);
  214. break;
  215. }
  216. }
  217. /*
  218. * Function state_s_make_call (event, skb)
  219. *
  220. * S-Make-Call
  221. *
  222. */
  223. static void state_s_make_call(struct iriap_cb *self, IRIAP_EVENT event,
  224. struct sk_buff *skb)
  225. {
  226. struct sk_buff *tx_skb;
  227. IRDA_ASSERT(self != NULL, return;);
  228. switch (event) {
  229. case IAP_CALL_REQUEST:
  230. /* Already refcounted - see state_s_disconnect() */
  231. tx_skb = self->request_skb;
  232. self->request_skb = NULL;
  233. irlmp_data_request(self->lsap, tx_skb);
  234. iriap_next_call_state(self, S_OUTSTANDING);
  235. break;
  236. default:
  237. IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__, event);
  238. break;
  239. }
  240. }
  241. /*
  242. * Function state_s_calling (event, skb)
  243. *
  244. * S-Calling
  245. *
  246. */
  247. static void state_s_calling(struct iriap_cb *self, IRIAP_EVENT event,
  248. struct sk_buff *skb)
  249. {
  250. IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
  251. }
  252. /*
  253. * Function state_s_outstanding (event, skb)
  254. *
  255. * S-Outstanding, The device is waiting for a response to a command
  256. *
  257. */
  258. static void state_s_outstanding(struct iriap_cb *self, IRIAP_EVENT event,
  259. struct sk_buff *skb)
  260. {
  261. IRDA_ASSERT(self != NULL, return;);
  262. switch (event) {
  263. case IAP_RECV_F_LST:
  264. /*iriap_send_ack(self);*/
  265. /*LM_Idle_request(idle); */
  266. iriap_next_call_state(self, S_WAIT_FOR_CALL);
  267. break;
  268. default:
  269. IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__, event);
  270. break;
  271. }
  272. }
  273. /*
  274. * Function state_s_replying (event, skb)
  275. *
  276. * S-Replying, The device is collecting a multiple part response
  277. */
  278. static void state_s_replying(struct iriap_cb *self, IRIAP_EVENT event,
  279. struct sk_buff *skb)
  280. {
  281. IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
  282. }
  283. /*
  284. * Function state_s_wait_for_call (event, skb)
  285. *
  286. * S-Wait-for-Call
  287. *
  288. */
  289. static void state_s_wait_for_call(struct iriap_cb *self, IRIAP_EVENT event,
  290. struct sk_buff *skb)
  291. {
  292. IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
  293. }
  294. /*
  295. * Function state_s_wait_active (event, skb)
  296. *
  297. * S-Wait-Active
  298. *
  299. */
  300. static void state_s_wait_active(struct iriap_cb *self, IRIAP_EVENT event,
  301. struct sk_buff *skb)
  302. {
  303. IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
  304. }
  305. /**************************************************************************
  306. *
  307. * Server FSM
  308. *
  309. **************************************************************************/
  310. /*
  311. * Function state_r_disconnect (self, event, skb)
  312. *
  313. * LM-IAS server is disconnected (not processing any requests!)
  314. *
  315. */
  316. static void state_r_disconnect(struct iriap_cb *self, IRIAP_EVENT event,
  317. struct sk_buff *skb)
  318. {
  319. struct sk_buff *tx_skb;
  320. switch (event) {
  321. case IAP_LM_CONNECT_INDICATION:
  322. tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
  323. if (tx_skb == NULL) {
  324. IRDA_WARNING("%s: unable to malloc!\n", __FUNCTION__);
  325. return;
  326. }
  327. /* Reserve space for MUX_CONTROL and LAP header */
  328. skb_reserve(tx_skb, LMP_MAX_HEADER);
  329. irlmp_connect_response(self->lsap, tx_skb);
  330. /*LM_Idle_request(idle); */
  331. iriap_next_server_state(self, R_CALL);
  332. /*
  333. * Jump to R-Connect FSM, we skip R-Waiting since we do not
  334. * care about LM_Idle_request()!
  335. */
  336. iriap_next_r_connect_state(self, R_RECEIVING);
  337. break;
  338. default:
  339. IRDA_DEBUG(0, "%s(), unknown event %d\n", __FUNCTION__, event);
  340. break;
  341. }
  342. }
  343. /*
  344. * Function state_r_call (self, event, skb)
  345. */
  346. static void state_r_call(struct iriap_cb *self, IRIAP_EVENT event,
  347. struct sk_buff *skb)
  348. {
  349. IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
  350. switch (event) {
  351. case IAP_LM_DISCONNECT_INDICATION:
  352. /* Abort call */
  353. iriap_next_server_state(self, R_DISCONNECT);
  354. iriap_next_r_connect_state(self, R_WAITING);
  355. break;
  356. default:
  357. IRDA_DEBUG(0, "%s(), unknown event!\n", __FUNCTION__);
  358. break;
  359. }
  360. }
  361. /*
  362. * R-Connect FSM
  363. */
  364. /*
  365. * Function state_r_waiting (self, event, skb)
  366. */
  367. static void state_r_waiting(struct iriap_cb *self, IRIAP_EVENT event,
  368. struct sk_buff *skb)
  369. {
  370. IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
  371. }
  372. static void state_r_wait_active(struct iriap_cb *self, IRIAP_EVENT event,
  373. struct sk_buff *skb)
  374. {
  375. IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
  376. }
  377. /*
  378. * Function state_r_receiving (self, event, skb)
  379. *
  380. * We are receiving a command
  381. *
  382. */
  383. static void state_r_receiving(struct iriap_cb *self, IRIAP_EVENT event,
  384. struct sk_buff *skb)
  385. {
  386. IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
  387. switch (event) {
  388. case IAP_RECV_F_LST:
  389. iriap_next_r_connect_state(self, R_EXECUTE);
  390. iriap_call_indication(self, skb);
  391. break;
  392. default:
  393. IRDA_DEBUG(0, "%s(), unknown event!\n", __FUNCTION__);
  394. break;
  395. }
  396. }
  397. /*
  398. * Function state_r_execute (self, event, skb)
  399. *
  400. * The server is processing the request
  401. *
  402. */
  403. static void state_r_execute(struct iriap_cb *self, IRIAP_EVENT event,
  404. struct sk_buff *skb)
  405. {
  406. IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
  407. IRDA_ASSERT(skb != NULL, return;);
  408. IRDA_ASSERT(self != NULL, return;);
  409. IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
  410. switch (event) {
  411. case IAP_CALL_RESPONSE:
  412. /*
  413. * Since we don't implement the Waiting state, we return
  414. * to state Receiving instead, DB.
  415. */
  416. iriap_next_r_connect_state(self, R_RECEIVING);
  417. /* Don't forget to refcount it - see
  418. * iriap_getvaluebyclass_response(). */
  419. skb_get(skb);
  420. irlmp_data_request(self->lsap, skb);
  421. break;
  422. default:
  423. IRDA_DEBUG(0, "%s(), unknown event!\n", __FUNCTION__);
  424. break;
  425. }
  426. }
  427. static void state_r_returning(struct iriap_cb *self, IRIAP_EVENT event,
  428. struct sk_buff *skb)
  429. {
  430. IRDA_DEBUG(0, "%s(), event=%d\n", __FUNCTION__, event);
  431. switch (event) {
  432. case IAP_RECV_F_LST:
  433. break;
  434. default:
  435. break;
  436. }
  437. }