ircomm_ttp.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*********************************************************************
  2. *
  3. * Filename: ircomm_ttp.c
  4. * Version: 1.0
  5. * Description: Interface between IrCOMM and IrTTP
  6. * Status: Stable
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Sun Jun 6 20:48:27 1999
  9. * Modified at: Mon Dec 13 11:35:13 1999
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1999 Dag Brattli, All Rights Reserved.
  13. * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  27. *
  28. ********************************************************************/
  29. #include <linux/init.h>
  30. #include <net/irda/irda.h>
  31. #include <net/irda/irlmp.h>
  32. #include <net/irda/iriap.h>
  33. #include <net/irda/irttp.h>
  34. #include <net/irda/ircomm_event.h>
  35. #include <net/irda/ircomm_ttp.h>
  36. static int ircomm_ttp_data_indication(void *instance, void *sap,
  37. struct sk_buff *skb);
  38. static void ircomm_ttp_connect_confirm(void *instance, void *sap,
  39. struct qos_info *qos,
  40. __u32 max_sdu_size,
  41. __u8 max_header_size,
  42. struct sk_buff *skb);
  43. static void ircomm_ttp_connect_indication(void *instance, void *sap,
  44. struct qos_info *qos,
  45. __u32 max_sdu_size,
  46. __u8 max_header_size,
  47. struct sk_buff *skb);
  48. static void ircomm_ttp_flow_indication(void *instance, void *sap,
  49. LOCAL_FLOW cmd);
  50. static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
  51. LM_REASON reason,
  52. struct sk_buff *skb);
  53. static int ircomm_ttp_data_request(struct ircomm_cb *self,
  54. struct sk_buff *skb,
  55. int clen);
  56. static int ircomm_ttp_connect_request(struct ircomm_cb *self,
  57. struct sk_buff *userdata,
  58. struct ircomm_info *info);
  59. static int ircomm_ttp_connect_response(struct ircomm_cb *self,
  60. struct sk_buff *userdata);
  61. static int ircomm_ttp_disconnect_request(struct ircomm_cb *self,
  62. struct sk_buff *userdata,
  63. struct ircomm_info *info);
  64. /*
  65. * Function ircomm_open_tsap (self)
  66. *
  67. *
  68. *
  69. */
  70. int ircomm_open_tsap(struct ircomm_cb *self)
  71. {
  72. notify_t notify;
  73. IRDA_DEBUG(4, "%s()\n", __func__ );
  74. /* Register callbacks */
  75. irda_notify_init(&notify);
  76. notify.data_indication = ircomm_ttp_data_indication;
  77. notify.connect_confirm = ircomm_ttp_connect_confirm;
  78. notify.connect_indication = ircomm_ttp_connect_indication;
  79. notify.flow_indication = ircomm_ttp_flow_indication;
  80. notify.disconnect_indication = ircomm_ttp_disconnect_indication;
  81. notify.instance = self;
  82. strlcpy(notify.name, "IrCOMM", sizeof(notify.name));
  83. self->tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT,
  84. &notify);
  85. if (!self->tsap) {
  86. IRDA_DEBUG(0, "%sfailed to allocate tsap\n", __func__ );
  87. return -1;
  88. }
  89. self->slsap_sel = self->tsap->stsap_sel;
  90. /*
  91. * Initialize the call-table for issuing commands
  92. */
  93. self->issue.data_request = ircomm_ttp_data_request;
  94. self->issue.connect_request = ircomm_ttp_connect_request;
  95. self->issue.connect_response = ircomm_ttp_connect_response;
  96. self->issue.disconnect_request = ircomm_ttp_disconnect_request;
  97. return 0;
  98. }
  99. /*
  100. * Function ircomm_ttp_connect_request (self, userdata)
  101. *
  102. *
  103. *
  104. */
  105. static int ircomm_ttp_connect_request(struct ircomm_cb *self,
  106. struct sk_buff *userdata,
  107. struct ircomm_info *info)
  108. {
  109. int ret = 0;
  110. IRDA_DEBUG(4, "%s()\n", __func__ );
  111. /* Don't forget to refcount it - should be NULL anyway */
  112. if(userdata)
  113. skb_get(userdata);
  114. ret = irttp_connect_request(self->tsap, info->dlsap_sel,
  115. info->saddr, info->daddr, NULL,
  116. TTP_SAR_DISABLE, userdata);
  117. return ret;
  118. }
  119. /*
  120. * Function ircomm_ttp_connect_response (self, skb)
  121. *
  122. *
  123. *
  124. */
  125. static int ircomm_ttp_connect_response(struct ircomm_cb *self,
  126. struct sk_buff *userdata)
  127. {
  128. int ret;
  129. IRDA_DEBUG(4, "%s()\n", __func__ );
  130. /* Don't forget to refcount it - should be NULL anyway */
  131. if(userdata)
  132. skb_get(userdata);
  133. ret = irttp_connect_response(self->tsap, TTP_SAR_DISABLE, userdata);
  134. return ret;
  135. }
  136. /*
  137. * Function ircomm_ttp_data_request (self, userdata)
  138. *
  139. * Send IrCOMM data to IrTTP layer. Currently we do not try to combine
  140. * control data with pure data, so they will be sent as separate frames.
  141. * Should not be a big problem though, since control frames are rare. But
  142. * some of them are sent after connection establishment, so this can
  143. * increase the latency a bit.
  144. */
  145. static int ircomm_ttp_data_request(struct ircomm_cb *self,
  146. struct sk_buff *skb,
  147. int clen)
  148. {
  149. int ret;
  150. IRDA_ASSERT(skb != NULL, return -1;);
  151. IRDA_DEBUG(2, "%s(), clen=%d\n", __func__ , clen);
  152. /*
  153. * Insert clen field, currently we either send data only, or control
  154. * only frames, to make things easier and avoid queueing
  155. */
  156. IRDA_ASSERT(skb_headroom(skb) >= IRCOMM_HEADER_SIZE, return -1;);
  157. /* Don't forget to refcount it - see ircomm_tty_do_softint() */
  158. skb_get(skb);
  159. skb_push(skb, IRCOMM_HEADER_SIZE);
  160. skb->data[0] = clen;
  161. ret = irttp_data_request(self->tsap, skb);
  162. if (ret) {
  163. IRDA_ERROR("%s(), failed\n", __func__);
  164. /* irttp_data_request already free the packet */
  165. }
  166. return ret;
  167. }
  168. /*
  169. * Function ircomm_ttp_data_indication (instance, sap, skb)
  170. *
  171. * Incoming data
  172. *
  173. */
  174. static int ircomm_ttp_data_indication(void *instance, void *sap,
  175. struct sk_buff *skb)
  176. {
  177. struct ircomm_cb *self = (struct ircomm_cb *) instance;
  178. IRDA_DEBUG(4, "%s()\n", __func__ );
  179. IRDA_ASSERT(self != NULL, return -1;);
  180. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return -1;);
  181. IRDA_ASSERT(skb != NULL, return -1;);
  182. ircomm_do_event(self, IRCOMM_TTP_DATA_INDICATION, skb, NULL);
  183. /* Drop reference count - see ircomm_tty_data_indication(). */
  184. dev_kfree_skb(skb);
  185. return 0;
  186. }
  187. static void ircomm_ttp_connect_confirm(void *instance, void *sap,
  188. struct qos_info *qos,
  189. __u32 max_sdu_size,
  190. __u8 max_header_size,
  191. struct sk_buff *skb)
  192. {
  193. struct ircomm_cb *self = (struct ircomm_cb *) instance;
  194. struct ircomm_info info;
  195. IRDA_DEBUG(4, "%s()\n", __func__ );
  196. IRDA_ASSERT(self != NULL, return;);
  197. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
  198. IRDA_ASSERT(skb != NULL, return;);
  199. IRDA_ASSERT(qos != NULL, goto out;);
  200. if (max_sdu_size != TTP_SAR_DISABLE) {
  201. IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n",
  202. __func__);
  203. goto out;
  204. }
  205. info.max_data_size = irttp_get_max_seg_size(self->tsap)
  206. - IRCOMM_HEADER_SIZE;
  207. info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
  208. info.qos = qos;
  209. ircomm_do_event(self, IRCOMM_TTP_CONNECT_CONFIRM, skb, &info);
  210. out:
  211. /* Drop reference count - see ircomm_tty_connect_confirm(). */
  212. dev_kfree_skb(skb);
  213. }
  214. /*
  215. * Function ircomm_ttp_connect_indication (instance, sap, qos, max_sdu_size,
  216. * max_header_size, skb)
  217. *
  218. *
  219. *
  220. */
  221. static void ircomm_ttp_connect_indication(void *instance, void *sap,
  222. struct qos_info *qos,
  223. __u32 max_sdu_size,
  224. __u8 max_header_size,
  225. struct sk_buff *skb)
  226. {
  227. struct ircomm_cb *self = (struct ircomm_cb *)instance;
  228. struct ircomm_info info;
  229. IRDA_DEBUG(4, "%s()\n", __func__ );
  230. IRDA_ASSERT(self != NULL, return;);
  231. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
  232. IRDA_ASSERT(skb != NULL, return;);
  233. IRDA_ASSERT(qos != NULL, goto out;);
  234. if (max_sdu_size != TTP_SAR_DISABLE) {
  235. IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n",
  236. __func__);
  237. goto out;
  238. }
  239. info.max_data_size = irttp_get_max_seg_size(self->tsap)
  240. - IRCOMM_HEADER_SIZE;
  241. info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
  242. info.qos = qos;
  243. ircomm_do_event(self, IRCOMM_TTP_CONNECT_INDICATION, skb, &info);
  244. out:
  245. /* Drop reference count - see ircomm_tty_connect_indication(). */
  246. dev_kfree_skb(skb);
  247. }
  248. /*
  249. * Function ircomm_ttp_disconnect_request (self, userdata, info)
  250. *
  251. *
  252. *
  253. */
  254. static int ircomm_ttp_disconnect_request(struct ircomm_cb *self,
  255. struct sk_buff *userdata,
  256. struct ircomm_info *info)
  257. {
  258. int ret;
  259. /* Don't forget to refcount it - should be NULL anyway */
  260. if(userdata)
  261. skb_get(userdata);
  262. ret = irttp_disconnect_request(self->tsap, userdata, P_NORMAL);
  263. return ret;
  264. }
  265. /*
  266. * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
  267. *
  268. *
  269. *
  270. */
  271. static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
  272. LM_REASON reason,
  273. struct sk_buff *skb)
  274. {
  275. struct ircomm_cb *self = (struct ircomm_cb *) instance;
  276. struct ircomm_info info;
  277. IRDA_DEBUG(2, "%s()\n", __func__ );
  278. IRDA_ASSERT(self != NULL, return;);
  279. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
  280. info.reason = reason;
  281. ircomm_do_event(self, IRCOMM_TTP_DISCONNECT_INDICATION, skb, &info);
  282. /* Drop reference count - see ircomm_tty_disconnect_indication(). */
  283. if(skb)
  284. dev_kfree_skb(skb);
  285. }
  286. /*
  287. * Function ircomm_ttp_flow_indication (instance, sap, cmd)
  288. *
  289. * Layer below is telling us to start or stop the flow of data
  290. *
  291. */
  292. static void ircomm_ttp_flow_indication(void *instance, void *sap,
  293. LOCAL_FLOW cmd)
  294. {
  295. struct ircomm_cb *self = (struct ircomm_cb *) instance;
  296. IRDA_DEBUG(4, "%s()\n", __func__ );
  297. IRDA_ASSERT(self != NULL, return;);
  298. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
  299. if (self->notify.flow_indication)
  300. self->notify.flow_indication(self->notify.instance, self, cmd);
  301. }