ircomm_ttp.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. *
  30. ********************************************************************/
  31. #include <linux/init.h>
  32. #include <net/irda/irda.h>
  33. #include <net/irda/irlmp.h>
  34. #include <net/irda/iriap.h>
  35. #include <net/irda/irttp.h>
  36. #include <net/irda/ircomm_event.h>
  37. #include <net/irda/ircomm_ttp.h>
  38. static int ircomm_ttp_data_indication(void *instance, void *sap,
  39. struct sk_buff *skb);
  40. static void ircomm_ttp_connect_confirm(void *instance, void *sap,
  41. struct qos_info *qos,
  42. __u32 max_sdu_size,
  43. __u8 max_header_size,
  44. struct sk_buff *skb);
  45. static void ircomm_ttp_connect_indication(void *instance, void *sap,
  46. struct qos_info *qos,
  47. __u32 max_sdu_size,
  48. __u8 max_header_size,
  49. struct sk_buff *skb);
  50. static void ircomm_ttp_flow_indication(void *instance, void *sap,
  51. LOCAL_FLOW cmd);
  52. static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
  53. LM_REASON reason,
  54. struct sk_buff *skb);
  55. static int ircomm_ttp_data_request(struct ircomm_cb *self,
  56. struct sk_buff *skb,
  57. int clen);
  58. static int ircomm_ttp_connect_request(struct ircomm_cb *self,
  59. struct sk_buff *userdata,
  60. struct ircomm_info *info);
  61. static int ircomm_ttp_connect_response(struct ircomm_cb *self,
  62. struct sk_buff *userdata);
  63. static int ircomm_ttp_disconnect_request(struct ircomm_cb *self,
  64. struct sk_buff *userdata,
  65. struct ircomm_info *info);
  66. /*
  67. * Function ircomm_open_tsap (self)
  68. *
  69. *
  70. *
  71. */
  72. int ircomm_open_tsap(struct ircomm_cb *self)
  73. {
  74. notify_t notify;
  75. IRDA_DEBUG(4, "%s()\n", __func__ );
  76. /* Register callbacks */
  77. irda_notify_init(&notify);
  78. notify.data_indication = ircomm_ttp_data_indication;
  79. notify.connect_confirm = ircomm_ttp_connect_confirm;
  80. notify.connect_indication = ircomm_ttp_connect_indication;
  81. notify.flow_indication = ircomm_ttp_flow_indication;
  82. notify.disconnect_indication = ircomm_ttp_disconnect_indication;
  83. notify.instance = self;
  84. strlcpy(notify.name, "IrCOMM", sizeof(notify.name));
  85. self->tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT,
  86. &notify);
  87. if (!self->tsap) {
  88. IRDA_DEBUG(0, "%sfailed to allocate tsap\n", __func__ );
  89. return -1;
  90. }
  91. self->slsap_sel = self->tsap->stsap_sel;
  92. /*
  93. * Initialize the call-table for issuing commands
  94. */
  95. self->issue.data_request = ircomm_ttp_data_request;
  96. self->issue.connect_request = ircomm_ttp_connect_request;
  97. self->issue.connect_response = ircomm_ttp_connect_response;
  98. self->issue.disconnect_request = ircomm_ttp_disconnect_request;
  99. return 0;
  100. }
  101. /*
  102. * Function ircomm_ttp_connect_request (self, userdata)
  103. *
  104. *
  105. *
  106. */
  107. static int ircomm_ttp_connect_request(struct ircomm_cb *self,
  108. struct sk_buff *userdata,
  109. struct ircomm_info *info)
  110. {
  111. int ret = 0;
  112. IRDA_DEBUG(4, "%s()\n", __func__ );
  113. /* Don't forget to refcount it - should be NULL anyway */
  114. if(userdata)
  115. skb_get(userdata);
  116. ret = irttp_connect_request(self->tsap, info->dlsap_sel,
  117. info->saddr, info->daddr, NULL,
  118. TTP_SAR_DISABLE, userdata);
  119. return ret;
  120. }
  121. /*
  122. * Function ircomm_ttp_connect_response (self, skb)
  123. *
  124. *
  125. *
  126. */
  127. static int ircomm_ttp_connect_response(struct ircomm_cb *self,
  128. struct sk_buff *userdata)
  129. {
  130. int ret;
  131. IRDA_DEBUG(4, "%s()\n", __func__ );
  132. /* Don't forget to refcount it - should be NULL anyway */
  133. if(userdata)
  134. skb_get(userdata);
  135. ret = irttp_connect_response(self->tsap, TTP_SAR_DISABLE, userdata);
  136. return ret;
  137. }
  138. /*
  139. * Function ircomm_ttp_data_request (self, userdata)
  140. *
  141. * Send IrCOMM data to IrTTP layer. Currently we do not try to combine
  142. * control data with pure data, so they will be sent as separate frames.
  143. * Should not be a big problem though, since control frames are rare. But
  144. * some of them are sent after connection establishment, so this can
  145. * increase the latency a bit.
  146. */
  147. static int ircomm_ttp_data_request(struct ircomm_cb *self,
  148. struct sk_buff *skb,
  149. int clen)
  150. {
  151. int ret;
  152. IRDA_ASSERT(skb != NULL, return -1;);
  153. IRDA_DEBUG(2, "%s(), clen=%d\n", __func__ , clen);
  154. /*
  155. * Insert clen field, currently we either send data only, or control
  156. * only frames, to make things easier and avoid queueing
  157. */
  158. IRDA_ASSERT(skb_headroom(skb) >= IRCOMM_HEADER_SIZE, return -1;);
  159. /* Don't forget to refcount it - see ircomm_tty_do_softint() */
  160. skb_get(skb);
  161. skb_push(skb, IRCOMM_HEADER_SIZE);
  162. skb->data[0] = clen;
  163. ret = irttp_data_request(self->tsap, skb);
  164. if (ret) {
  165. IRDA_ERROR("%s(), failed\n", __func__);
  166. /* irttp_data_request already free the packet */
  167. }
  168. return ret;
  169. }
  170. /*
  171. * Function ircomm_ttp_data_indication (instance, sap, skb)
  172. *
  173. * Incoming data
  174. *
  175. */
  176. static int ircomm_ttp_data_indication(void *instance, void *sap,
  177. struct sk_buff *skb)
  178. {
  179. struct ircomm_cb *self = (struct ircomm_cb *) instance;
  180. IRDA_DEBUG(4, "%s()\n", __func__ );
  181. IRDA_ASSERT(self != NULL, return -1;);
  182. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return -1;);
  183. IRDA_ASSERT(skb != NULL, return -1;);
  184. ircomm_do_event(self, IRCOMM_TTP_DATA_INDICATION, skb, NULL);
  185. /* Drop reference count - see ircomm_tty_data_indication(). */
  186. dev_kfree_skb(skb);
  187. return 0;
  188. }
  189. static void ircomm_ttp_connect_confirm(void *instance, void *sap,
  190. struct qos_info *qos,
  191. __u32 max_sdu_size,
  192. __u8 max_header_size,
  193. struct sk_buff *skb)
  194. {
  195. struct ircomm_cb *self = (struct ircomm_cb *) instance;
  196. struct ircomm_info info;
  197. IRDA_DEBUG(4, "%s()\n", __func__ );
  198. IRDA_ASSERT(self != NULL, return;);
  199. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
  200. IRDA_ASSERT(skb != NULL, return;);
  201. IRDA_ASSERT(qos != NULL, goto out;);
  202. if (max_sdu_size != TTP_SAR_DISABLE) {
  203. IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n",
  204. __func__);
  205. goto out;
  206. }
  207. info.max_data_size = irttp_get_max_seg_size(self->tsap)
  208. - IRCOMM_HEADER_SIZE;
  209. info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
  210. info.qos = qos;
  211. ircomm_do_event(self, IRCOMM_TTP_CONNECT_CONFIRM, skb, &info);
  212. out:
  213. /* Drop reference count - see ircomm_tty_connect_confirm(). */
  214. dev_kfree_skb(skb);
  215. }
  216. /*
  217. * Function ircomm_ttp_connect_indication (instance, sap, qos, max_sdu_size,
  218. * max_header_size, skb)
  219. *
  220. *
  221. *
  222. */
  223. static void ircomm_ttp_connect_indication(void *instance, void *sap,
  224. struct qos_info *qos,
  225. __u32 max_sdu_size,
  226. __u8 max_header_size,
  227. struct sk_buff *skb)
  228. {
  229. struct ircomm_cb *self = (struct ircomm_cb *)instance;
  230. struct ircomm_info info;
  231. IRDA_DEBUG(4, "%s()\n", __func__ );
  232. IRDA_ASSERT(self != NULL, return;);
  233. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
  234. IRDA_ASSERT(skb != NULL, return;);
  235. IRDA_ASSERT(qos != NULL, goto out;);
  236. if (max_sdu_size != TTP_SAR_DISABLE) {
  237. IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n",
  238. __func__);
  239. goto out;
  240. }
  241. info.max_data_size = irttp_get_max_seg_size(self->tsap)
  242. - IRCOMM_HEADER_SIZE;
  243. info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
  244. info.qos = qos;
  245. ircomm_do_event(self, IRCOMM_TTP_CONNECT_INDICATION, skb, &info);
  246. out:
  247. /* Drop reference count - see ircomm_tty_connect_indication(). */
  248. dev_kfree_skb(skb);
  249. }
  250. /*
  251. * Function ircomm_ttp_disconnect_request (self, userdata, info)
  252. *
  253. *
  254. *
  255. */
  256. static int ircomm_ttp_disconnect_request(struct ircomm_cb *self,
  257. struct sk_buff *userdata,
  258. struct ircomm_info *info)
  259. {
  260. int ret;
  261. /* Don't forget to refcount it - should be NULL anyway */
  262. if(userdata)
  263. skb_get(userdata);
  264. ret = irttp_disconnect_request(self->tsap, userdata, P_NORMAL);
  265. return ret;
  266. }
  267. /*
  268. * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
  269. *
  270. *
  271. *
  272. */
  273. static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
  274. LM_REASON reason,
  275. struct sk_buff *skb)
  276. {
  277. struct ircomm_cb *self = (struct ircomm_cb *) instance;
  278. struct ircomm_info info;
  279. IRDA_DEBUG(2, "%s()\n", __func__ );
  280. IRDA_ASSERT(self != NULL, return;);
  281. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
  282. info.reason = reason;
  283. ircomm_do_event(self, IRCOMM_TTP_DISCONNECT_INDICATION, skb, &info);
  284. /* Drop reference count - see ircomm_tty_disconnect_indication(). */
  285. if(skb)
  286. dev_kfree_skb(skb);
  287. }
  288. /*
  289. * Function ircomm_ttp_flow_indication (instance, sap, cmd)
  290. *
  291. * Layer below is telling us to start or stop the flow of data
  292. *
  293. */
  294. static void ircomm_ttp_flow_indication(void *instance, void *sap,
  295. LOCAL_FLOW cmd)
  296. {
  297. struct ircomm_cb *self = (struct ircomm_cb *) instance;
  298. IRDA_DEBUG(4, "%s()\n", __func__ );
  299. IRDA_ASSERT(self != NULL, return;);
  300. IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
  301. if (self->notify.flow_indication)
  302. self->notify.flow_indication(self->notify.instance, self, cmd);
  303. }