ircomm_ttp.c 9.5 KB

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