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