irttp.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  1. /*********************************************************************
  2. *
  3. * Filename: irttp.c
  4. * Version: 1.2
  5. * Description: Tiny Transport Protocol (TTP) implementation
  6. * Status: Stable
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Sun Aug 31 20:14:31 1997
  9. * Modified at: Wed Jan 5 11:31:27 2000
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1998-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 <linux/skbuff.h>
  27. #include <linux/init.h>
  28. #include <linux/fs.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/slab.h>
  31. #include <linux/export.h>
  32. #include <asm/byteorder.h>
  33. #include <asm/unaligned.h>
  34. #include <net/irda/irda.h>
  35. #include <net/irda/irlap.h>
  36. #include <net/irda/irlmp.h>
  37. #include <net/irda/parameters.h>
  38. #include <net/irda/irttp.h>
  39. static struct irttp_cb *irttp;
  40. static void __irttp_close_tsap(struct tsap_cb *self);
  41. static int irttp_data_indication(void *instance, void *sap,
  42. struct sk_buff *skb);
  43. static int irttp_udata_indication(void *instance, void *sap,
  44. struct sk_buff *skb);
  45. static void irttp_disconnect_indication(void *instance, void *sap,
  46. LM_REASON reason, struct sk_buff *);
  47. static void irttp_connect_indication(void *instance, void *sap,
  48. struct qos_info *qos, __u32 max_sdu_size,
  49. __u8 header_size, struct sk_buff *skb);
  50. static void irttp_connect_confirm(void *instance, void *sap,
  51. struct qos_info *qos, __u32 max_sdu_size,
  52. __u8 header_size, struct sk_buff *skb);
  53. static void irttp_run_tx_queue(struct tsap_cb *self);
  54. static void irttp_run_rx_queue(struct tsap_cb *self);
  55. static void irttp_flush_queues(struct tsap_cb *self);
  56. static void irttp_fragment_skb(struct tsap_cb *self, struct sk_buff *skb);
  57. static struct sk_buff *irttp_reassemble_skb(struct tsap_cb *self);
  58. static void irttp_todo_expired(unsigned long data);
  59. static int irttp_param_max_sdu_size(void *instance, irda_param_t *param,
  60. int get);
  61. static void irttp_flow_indication(void *instance, void *sap, LOCAL_FLOW flow);
  62. static void irttp_status_indication(void *instance,
  63. LINK_STATUS link, LOCK_STATUS lock);
  64. /* Information for parsing parameters in IrTTP */
  65. static pi_minor_info_t pi_minor_call_table[] = {
  66. { NULL, 0 }, /* 0x00 */
  67. { irttp_param_max_sdu_size, PV_INTEGER | PV_BIG_ENDIAN } /* 0x01 */
  68. };
  69. static pi_major_info_t pi_major_call_table[] = { { pi_minor_call_table, 2 } };
  70. static pi_param_info_t param_info = { pi_major_call_table, 1, 0x0f, 4 };
  71. /************************ GLOBAL PROCEDURES ************************/
  72. /*
  73. * Function irttp_init (void)
  74. *
  75. * Initialize the IrTTP layer. Called by module initialization code
  76. *
  77. */
  78. int __init irttp_init(void)
  79. {
  80. irttp = kzalloc(sizeof(struct irttp_cb), GFP_KERNEL);
  81. if (irttp == NULL)
  82. return -ENOMEM;
  83. irttp->magic = TTP_MAGIC;
  84. irttp->tsaps = hashbin_new(HB_LOCK);
  85. if (!irttp->tsaps) {
  86. IRDA_ERROR("%s: can't allocate IrTTP hashbin!\n",
  87. __func__);
  88. kfree(irttp);
  89. return -ENOMEM;
  90. }
  91. return 0;
  92. }
  93. /*
  94. * Function irttp_cleanup (void)
  95. *
  96. * Called by module destruction/cleanup code
  97. *
  98. */
  99. void irttp_cleanup(void)
  100. {
  101. /* Check for main structure */
  102. IRDA_ASSERT(irttp->magic == TTP_MAGIC, return;);
  103. /*
  104. * Delete hashbin and close all TSAP instances in it
  105. */
  106. hashbin_delete(irttp->tsaps, (FREE_FUNC) __irttp_close_tsap);
  107. irttp->magic = 0;
  108. /* De-allocate main structure */
  109. kfree(irttp);
  110. irttp = NULL;
  111. }
  112. /*************************** SUBROUTINES ***************************/
  113. /*
  114. * Function irttp_start_todo_timer (self, timeout)
  115. *
  116. * Start todo timer.
  117. *
  118. * Made it more effient and unsensitive to race conditions - Jean II
  119. */
  120. static inline void irttp_start_todo_timer(struct tsap_cb *self, int timeout)
  121. {
  122. /* Set new value for timer */
  123. mod_timer(&self->todo_timer, jiffies + timeout);
  124. }
  125. /*
  126. * Function irttp_todo_expired (data)
  127. *
  128. * Todo timer has expired!
  129. *
  130. * One of the restriction of the timer is that it is run only on the timer
  131. * interrupt which run every 10ms. This mean that even if you set the timer
  132. * with a delay of 0, it may take up to 10ms before it's run.
  133. * So, to minimise latency and keep cache fresh, we try to avoid using
  134. * it as much as possible.
  135. * Note : we can't use tasklets, because they can't be asynchronously
  136. * killed (need user context), and we can't guarantee that here...
  137. * Jean II
  138. */
  139. static void irttp_todo_expired(unsigned long data)
  140. {
  141. struct tsap_cb *self = (struct tsap_cb *) data;
  142. /* Check that we still exist */
  143. if (!self || self->magic != TTP_TSAP_MAGIC)
  144. return;
  145. IRDA_DEBUG(4, "%s(instance=%p)\n", __func__, self);
  146. /* Try to make some progress, especially on Tx side - Jean II */
  147. irttp_run_rx_queue(self);
  148. irttp_run_tx_queue(self);
  149. /* Check if time for disconnect */
  150. if (test_bit(0, &self->disconnect_pend)) {
  151. /* Check if it's possible to disconnect yet */
  152. if (skb_queue_empty(&self->tx_queue)) {
  153. /* Make sure disconnect is not pending anymore */
  154. clear_bit(0, &self->disconnect_pend); /* FALSE */
  155. /* Note : self->disconnect_skb may be NULL */
  156. irttp_disconnect_request(self, self->disconnect_skb,
  157. P_NORMAL);
  158. self->disconnect_skb = NULL;
  159. } else {
  160. /* Try again later */
  161. irttp_start_todo_timer(self, HZ/10);
  162. /* No reason to try and close now */
  163. return;
  164. }
  165. }
  166. /* Check if it's closing time */
  167. if (self->close_pend)
  168. /* Finish cleanup */
  169. irttp_close_tsap(self);
  170. }
  171. /*
  172. * Function irttp_flush_queues (self)
  173. *
  174. * Flushes (removes all frames) in transitt-buffer (tx_list)
  175. */
  176. static void irttp_flush_queues(struct tsap_cb *self)
  177. {
  178. struct sk_buff *skb;
  179. IRDA_DEBUG(4, "%s()\n", __func__);
  180. IRDA_ASSERT(self != NULL, return;);
  181. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  182. /* Deallocate frames waiting to be sent */
  183. while ((skb = skb_dequeue(&self->tx_queue)) != NULL)
  184. dev_kfree_skb(skb);
  185. /* Deallocate received frames */
  186. while ((skb = skb_dequeue(&self->rx_queue)) != NULL)
  187. dev_kfree_skb(skb);
  188. /* Deallocate received fragments */
  189. while ((skb = skb_dequeue(&self->rx_fragments)) != NULL)
  190. dev_kfree_skb(skb);
  191. }
  192. /*
  193. * Function irttp_reassemble (self)
  194. *
  195. * Makes a new (continuous) skb of all the fragments in the fragment
  196. * queue
  197. *
  198. */
  199. static struct sk_buff *irttp_reassemble_skb(struct tsap_cb *self)
  200. {
  201. struct sk_buff *skb, *frag;
  202. int n = 0; /* Fragment index */
  203. IRDA_ASSERT(self != NULL, return NULL;);
  204. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return NULL;);
  205. IRDA_DEBUG(2, "%s(), self->rx_sdu_size=%d\n", __func__,
  206. self->rx_sdu_size);
  207. skb = dev_alloc_skb(TTP_HEADER + self->rx_sdu_size);
  208. if (!skb)
  209. return NULL;
  210. /*
  211. * Need to reserve space for TTP header in case this skb needs to
  212. * be requeued in case delivery failes
  213. */
  214. skb_reserve(skb, TTP_HEADER);
  215. skb_put(skb, self->rx_sdu_size);
  216. /*
  217. * Copy all fragments to a new buffer
  218. */
  219. while ((frag = skb_dequeue(&self->rx_fragments)) != NULL) {
  220. skb_copy_to_linear_data_offset(skb, n, frag->data, frag->len);
  221. n += frag->len;
  222. dev_kfree_skb(frag);
  223. }
  224. IRDA_DEBUG(2,
  225. "%s(), frame len=%d, rx_sdu_size=%d, rx_max_sdu_size=%d\n",
  226. __func__, n, self->rx_sdu_size, self->rx_max_sdu_size);
  227. /* Note : irttp_run_rx_queue() calculate self->rx_sdu_size
  228. * by summing the size of all fragments, so we should always
  229. * have n == self->rx_sdu_size, except in cases where we
  230. * droped the last fragment (when self->rx_sdu_size exceed
  231. * self->rx_max_sdu_size), where n < self->rx_sdu_size.
  232. * Jean II */
  233. IRDA_ASSERT(n <= self->rx_sdu_size, n = self->rx_sdu_size;);
  234. /* Set the new length */
  235. skb_trim(skb, n);
  236. self->rx_sdu_size = 0;
  237. return skb;
  238. }
  239. /*
  240. * Function irttp_fragment_skb (skb)
  241. *
  242. * Fragments a frame and queues all the fragments for transmission
  243. *
  244. */
  245. static inline void irttp_fragment_skb(struct tsap_cb *self,
  246. struct sk_buff *skb)
  247. {
  248. struct sk_buff *frag;
  249. __u8 *frame;
  250. IRDA_DEBUG(2, "%s()\n", __func__);
  251. IRDA_ASSERT(self != NULL, return;);
  252. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  253. IRDA_ASSERT(skb != NULL, return;);
  254. /*
  255. * Split frame into a number of segments
  256. */
  257. while (skb->len > self->max_seg_size) {
  258. IRDA_DEBUG(2, "%s(), fragmenting ...\n", __func__);
  259. /* Make new segment */
  260. frag = alloc_skb(self->max_seg_size+self->max_header_size,
  261. GFP_ATOMIC);
  262. if (!frag)
  263. return;
  264. skb_reserve(frag, self->max_header_size);
  265. /* Copy data from the original skb into this fragment. */
  266. skb_copy_from_linear_data(skb, skb_put(frag, self->max_seg_size),
  267. self->max_seg_size);
  268. /* Insert TTP header, with the more bit set */
  269. frame = skb_push(frag, TTP_HEADER);
  270. frame[0] = TTP_MORE;
  271. /* Hide the copied data from the original skb */
  272. skb_pull(skb, self->max_seg_size);
  273. /* Queue fragment */
  274. skb_queue_tail(&self->tx_queue, frag);
  275. }
  276. /* Queue what is left of the original skb */
  277. IRDA_DEBUG(2, "%s(), queuing last segment\n", __func__);
  278. frame = skb_push(skb, TTP_HEADER);
  279. frame[0] = 0x00; /* Clear more bit */
  280. /* Queue fragment */
  281. skb_queue_tail(&self->tx_queue, skb);
  282. }
  283. /*
  284. * Function irttp_param_max_sdu_size (self, param)
  285. *
  286. * Handle the MaxSduSize parameter in the connect frames, this function
  287. * will be called both when this parameter needs to be inserted into, and
  288. * extracted from the connect frames
  289. */
  290. static int irttp_param_max_sdu_size(void *instance, irda_param_t *param,
  291. int get)
  292. {
  293. struct tsap_cb *self;
  294. self = instance;
  295. IRDA_ASSERT(self != NULL, return -1;);
  296. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  297. if (get)
  298. param->pv.i = self->tx_max_sdu_size;
  299. else
  300. self->tx_max_sdu_size = param->pv.i;
  301. IRDA_DEBUG(1, "%s(), MaxSduSize=%d\n", __func__, param->pv.i);
  302. return 0;
  303. }
  304. /*************************** CLIENT CALLS ***************************/
  305. /************************** LMP CALLBACKS **************************/
  306. /* Everything is happily mixed up. Waiting for next clean up - Jean II */
  307. /*
  308. * Initialization, that has to be done on new tsap
  309. * instance allocation and on duplication
  310. */
  311. static void irttp_init_tsap(struct tsap_cb *tsap)
  312. {
  313. spin_lock_init(&tsap->lock);
  314. init_timer(&tsap->todo_timer);
  315. skb_queue_head_init(&tsap->rx_queue);
  316. skb_queue_head_init(&tsap->tx_queue);
  317. skb_queue_head_init(&tsap->rx_fragments);
  318. }
  319. /*
  320. * Function irttp_open_tsap (stsap, notify)
  321. *
  322. * Create TSAP connection endpoint,
  323. */
  324. struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
  325. {
  326. struct tsap_cb *self;
  327. struct lsap_cb *lsap;
  328. notify_t ttp_notify;
  329. IRDA_ASSERT(irttp->magic == TTP_MAGIC, return NULL;);
  330. /* The IrLMP spec (IrLMP 1.1 p10) says that we have the right to
  331. * use only 0x01-0x6F. Of course, we can use LSAP_ANY as well.
  332. * JeanII */
  333. if ((stsap_sel != LSAP_ANY) &&
  334. ((stsap_sel < 0x01) || (stsap_sel >= 0x70))) {
  335. IRDA_DEBUG(0, "%s(), invalid tsap!\n", __func__);
  336. return NULL;
  337. }
  338. self = kzalloc(sizeof(struct tsap_cb), GFP_ATOMIC);
  339. if (self == NULL) {
  340. IRDA_DEBUG(0, "%s(), unable to kmalloc!\n", __func__);
  341. return NULL;
  342. }
  343. /* Initialize internal objects */
  344. irttp_init_tsap(self);
  345. /* Initialise todo timer */
  346. self->todo_timer.data = (unsigned long) self;
  347. self->todo_timer.function = &irttp_todo_expired;
  348. /* Initialize callbacks for IrLMP to use */
  349. irda_notify_init(&ttp_notify);
  350. ttp_notify.connect_confirm = irttp_connect_confirm;
  351. ttp_notify.connect_indication = irttp_connect_indication;
  352. ttp_notify.disconnect_indication = irttp_disconnect_indication;
  353. ttp_notify.data_indication = irttp_data_indication;
  354. ttp_notify.udata_indication = irttp_udata_indication;
  355. ttp_notify.flow_indication = irttp_flow_indication;
  356. if (notify->status_indication != NULL)
  357. ttp_notify.status_indication = irttp_status_indication;
  358. ttp_notify.instance = self;
  359. strncpy(ttp_notify.name, notify->name, NOTIFY_MAX_NAME);
  360. self->magic = TTP_TSAP_MAGIC;
  361. self->connected = FALSE;
  362. /*
  363. * Create LSAP at IrLMP layer
  364. */
  365. lsap = irlmp_open_lsap(stsap_sel, &ttp_notify, 0);
  366. if (lsap == NULL) {
  367. IRDA_DEBUG(0, "%s: unable to allocate LSAP!!\n", __func__);
  368. __irttp_close_tsap(self);
  369. return NULL;
  370. }
  371. /*
  372. * If user specified LSAP_ANY as source TSAP selector, then IrLMP
  373. * will replace it with whatever source selector which is free, so
  374. * the stsap_sel we have might not be valid anymore
  375. */
  376. self->stsap_sel = lsap->slsap_sel;
  377. IRDA_DEBUG(4, "%s(), stsap_sel=%02x\n", __func__, self->stsap_sel);
  378. self->notify = *notify;
  379. self->lsap = lsap;
  380. hashbin_insert(irttp->tsaps, (irda_queue_t *) self, (long) self, NULL);
  381. if (credit > TTP_RX_MAX_CREDIT)
  382. self->initial_credit = TTP_RX_MAX_CREDIT;
  383. else
  384. self->initial_credit = credit;
  385. return self;
  386. }
  387. EXPORT_SYMBOL(irttp_open_tsap);
  388. /*
  389. * Function irttp_close (handle)
  390. *
  391. * Remove an instance of a TSAP. This function should only deal with the
  392. * deallocation of the TSAP, and resetting of the TSAPs values;
  393. *
  394. */
  395. static void __irttp_close_tsap(struct tsap_cb *self)
  396. {
  397. /* First make sure we're connected. */
  398. IRDA_ASSERT(self != NULL, return;);
  399. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  400. irttp_flush_queues(self);
  401. del_timer(&self->todo_timer);
  402. /* This one won't be cleaned up if we are disconnect_pend + close_pend
  403. * and we receive a disconnect_indication */
  404. if (self->disconnect_skb)
  405. dev_kfree_skb(self->disconnect_skb);
  406. self->connected = FALSE;
  407. self->magic = ~TTP_TSAP_MAGIC;
  408. kfree(self);
  409. }
  410. /*
  411. * Function irttp_close (self)
  412. *
  413. * Remove TSAP from list of all TSAPs and then deallocate all resources
  414. * associated with this TSAP
  415. *
  416. * Note : because we *free* the tsap structure, it is the responsibility
  417. * of the caller to make sure we are called only once and to deal with
  418. * possible race conditions. - Jean II
  419. */
  420. int irttp_close_tsap(struct tsap_cb *self)
  421. {
  422. struct tsap_cb *tsap;
  423. IRDA_DEBUG(4, "%s()\n", __func__);
  424. IRDA_ASSERT(self != NULL, return -1;);
  425. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  426. /* Make sure tsap has been disconnected */
  427. if (self->connected) {
  428. /* Check if disconnect is not pending */
  429. if (!test_bit(0, &self->disconnect_pend)) {
  430. IRDA_WARNING("%s: TSAP still connected!\n",
  431. __func__);
  432. irttp_disconnect_request(self, NULL, P_NORMAL);
  433. }
  434. self->close_pend = TRUE;
  435. irttp_start_todo_timer(self, HZ/10);
  436. return 0; /* Will be back! */
  437. }
  438. tsap = hashbin_remove(irttp->tsaps, (long) self, NULL);
  439. IRDA_ASSERT(tsap == self, return -1;);
  440. /* Close corresponding LSAP */
  441. if (self->lsap) {
  442. irlmp_close_lsap(self->lsap);
  443. self->lsap = NULL;
  444. }
  445. __irttp_close_tsap(self);
  446. return 0;
  447. }
  448. EXPORT_SYMBOL(irttp_close_tsap);
  449. /*
  450. * Function irttp_udata_request (self, skb)
  451. *
  452. * Send unreliable data on this TSAP
  453. *
  454. */
  455. int irttp_udata_request(struct tsap_cb *self, struct sk_buff *skb)
  456. {
  457. int ret;
  458. IRDA_ASSERT(self != NULL, return -1;);
  459. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  460. IRDA_ASSERT(skb != NULL, return -1;);
  461. IRDA_DEBUG(4, "%s()\n", __func__);
  462. /* Take shortcut on zero byte packets */
  463. if (skb->len == 0) {
  464. ret = 0;
  465. goto err;
  466. }
  467. /* Check that nothing bad happens */
  468. if (!self->connected) {
  469. IRDA_WARNING("%s(), Not connected\n", __func__);
  470. ret = -ENOTCONN;
  471. goto err;
  472. }
  473. if (skb->len > self->max_seg_size) {
  474. IRDA_ERROR("%s(), UData is too large for IrLAP!\n", __func__);
  475. ret = -EMSGSIZE;
  476. goto err;
  477. }
  478. irlmp_udata_request(self->lsap, skb);
  479. self->stats.tx_packets++;
  480. return 0;
  481. err:
  482. dev_kfree_skb(skb);
  483. return ret;
  484. }
  485. EXPORT_SYMBOL(irttp_udata_request);
  486. /*
  487. * Function irttp_data_request (handle, skb)
  488. *
  489. * Queue frame for transmission. If SAR is enabled, fragement the frame
  490. * and queue the fragments for transmission
  491. */
  492. int irttp_data_request(struct tsap_cb *self, struct sk_buff *skb)
  493. {
  494. __u8 *frame;
  495. int ret;
  496. IRDA_ASSERT(self != NULL, return -1;);
  497. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  498. IRDA_ASSERT(skb != NULL, return -1;);
  499. IRDA_DEBUG(2, "%s() : queue len = %d\n", __func__,
  500. skb_queue_len(&self->tx_queue));
  501. /* Take shortcut on zero byte packets */
  502. if (skb->len == 0) {
  503. ret = 0;
  504. goto err;
  505. }
  506. /* Check that nothing bad happens */
  507. if (!self->connected) {
  508. IRDA_WARNING("%s: Not connected\n", __func__);
  509. ret = -ENOTCONN;
  510. goto err;
  511. }
  512. /*
  513. * Check if SAR is disabled, and the frame is larger than what fits
  514. * inside an IrLAP frame
  515. */
  516. if ((self->tx_max_sdu_size == 0) && (skb->len > self->max_seg_size)) {
  517. IRDA_ERROR("%s: SAR disabled, and data is too large for IrLAP!\n",
  518. __func__);
  519. ret = -EMSGSIZE;
  520. goto err;
  521. }
  522. /*
  523. * Check if SAR is enabled, and the frame is larger than the
  524. * TxMaxSduSize
  525. */
  526. if ((self->tx_max_sdu_size != 0) &&
  527. (self->tx_max_sdu_size != TTP_SAR_UNBOUND) &&
  528. (skb->len > self->tx_max_sdu_size)) {
  529. IRDA_ERROR("%s: SAR enabled, but data is larger than TxMaxSduSize!\n",
  530. __func__);
  531. ret = -EMSGSIZE;
  532. goto err;
  533. }
  534. /*
  535. * Check if transmit queue is full
  536. */
  537. if (skb_queue_len(&self->tx_queue) >= TTP_TX_MAX_QUEUE) {
  538. /*
  539. * Give it a chance to empty itself
  540. */
  541. irttp_run_tx_queue(self);
  542. /* Drop packet. This error code should trigger the caller
  543. * to resend the data in the client code - Jean II */
  544. ret = -ENOBUFS;
  545. goto err;
  546. }
  547. /* Queue frame, or queue frame segments */
  548. if ((self->tx_max_sdu_size == 0) || (skb->len < self->max_seg_size)) {
  549. /* Queue frame */
  550. IRDA_ASSERT(skb_headroom(skb) >= TTP_HEADER, return -1;);
  551. frame = skb_push(skb, TTP_HEADER);
  552. frame[0] = 0x00; /* Clear more bit */
  553. skb_queue_tail(&self->tx_queue, skb);
  554. } else {
  555. /*
  556. * Fragment the frame, this function will also queue the
  557. * fragments, we don't care about the fact the transmit
  558. * queue may be overfilled by all the segments for a little
  559. * while
  560. */
  561. irttp_fragment_skb(self, skb);
  562. }
  563. /* Check if we can accept more data from client */
  564. if ((!self->tx_sdu_busy) &&
  565. (skb_queue_len(&self->tx_queue) > TTP_TX_HIGH_THRESHOLD)) {
  566. /* Tx queue filling up, so stop client. */
  567. if (self->notify.flow_indication) {
  568. self->notify.flow_indication(self->notify.instance,
  569. self, FLOW_STOP);
  570. }
  571. /* self->tx_sdu_busy is the state of the client.
  572. * Update state after notifying client to avoid
  573. * race condition with irttp_flow_indication().
  574. * If the queue empty itself after our test but before
  575. * we set the flag, we will fix ourselves below in
  576. * irttp_run_tx_queue().
  577. * Jean II */
  578. self->tx_sdu_busy = TRUE;
  579. }
  580. /* Try to make some progress */
  581. irttp_run_tx_queue(self);
  582. return 0;
  583. err:
  584. dev_kfree_skb(skb);
  585. return ret;
  586. }
  587. EXPORT_SYMBOL(irttp_data_request);
  588. /*
  589. * Function irttp_run_tx_queue (self)
  590. *
  591. * Transmit packets queued for transmission (if possible)
  592. *
  593. */
  594. static void irttp_run_tx_queue(struct tsap_cb *self)
  595. {
  596. struct sk_buff *skb;
  597. unsigned long flags;
  598. int n;
  599. IRDA_DEBUG(2, "%s() : send_credit = %d, queue_len = %d\n",
  600. __func__,
  601. self->send_credit, skb_queue_len(&self->tx_queue));
  602. /* Get exclusive access to the tx queue, otherwise don't touch it */
  603. if (irda_lock(&self->tx_queue_lock) == FALSE)
  604. return;
  605. /* Try to send out frames as long as we have credits
  606. * and as long as LAP is not full. If LAP is full, it will
  607. * poll us through irttp_flow_indication() - Jean II */
  608. while ((self->send_credit > 0) &&
  609. (!irlmp_lap_tx_queue_full(self->lsap)) &&
  610. (skb = skb_dequeue(&self->tx_queue))) {
  611. /*
  612. * Since we can transmit and receive frames concurrently,
  613. * the code below is a critical region and we must assure that
  614. * nobody messes with the credits while we update them.
  615. */
  616. spin_lock_irqsave(&self->lock, flags);
  617. n = self->avail_credit;
  618. self->avail_credit = 0;
  619. /* Only room for 127 credits in frame */
  620. if (n > 127) {
  621. self->avail_credit = n-127;
  622. n = 127;
  623. }
  624. self->remote_credit += n;
  625. self->send_credit--;
  626. spin_unlock_irqrestore(&self->lock, flags);
  627. /*
  628. * More bit must be set by the data_request() or fragment()
  629. * functions
  630. */
  631. skb->data[0] |= (n & 0x7f);
  632. /* Detach from socket.
  633. * The current skb has a reference to the socket that sent
  634. * it (skb->sk). When we pass it to IrLMP, the skb will be
  635. * stored in in IrLAP (self->wx_list). When we are within
  636. * IrLAP, we lose the notion of socket, so we should not
  637. * have a reference to a socket. So, we drop it here.
  638. *
  639. * Why does it matter ?
  640. * When the skb is freed (kfree_skb), if it is associated
  641. * with a socket, it release buffer space on the socket
  642. * (through sock_wfree() and sock_def_write_space()).
  643. * If the socket no longer exist, we may crash. Hard.
  644. * When we close a socket, we make sure that associated packets
  645. * in IrTTP are freed. However, we have no way to cancel
  646. * the packet that we have passed to IrLAP. So, if a packet
  647. * remains in IrLAP (retry on the link or else) after we
  648. * close the socket, we are dead !
  649. * Jean II */
  650. if (skb->sk != NULL) {
  651. /* IrSOCK application, IrOBEX, ... */
  652. skb_orphan(skb);
  653. }
  654. /* IrCOMM over IrTTP, IrLAN, ... */
  655. /* Pass the skb to IrLMP - done */
  656. irlmp_data_request(self->lsap, skb);
  657. self->stats.tx_packets++;
  658. }
  659. /* Check if we can accept more frames from client.
  660. * We don't want to wait until the todo timer to do that, and we
  661. * can't use tasklets (grr...), so we are obliged to give control
  662. * to client. That's ok, this test will be true not too often
  663. * (max once per LAP window) and we are called from places
  664. * where we can spend a bit of time doing stuff. - Jean II */
  665. if ((self->tx_sdu_busy) &&
  666. (skb_queue_len(&self->tx_queue) < TTP_TX_LOW_THRESHOLD) &&
  667. (!self->close_pend)) {
  668. if (self->notify.flow_indication)
  669. self->notify.flow_indication(self->notify.instance,
  670. self, FLOW_START);
  671. /* self->tx_sdu_busy is the state of the client.
  672. * We don't really have a race here, but it's always safer
  673. * to update our state after the client - Jean II */
  674. self->tx_sdu_busy = FALSE;
  675. }
  676. /* Reset lock */
  677. self->tx_queue_lock = 0;
  678. }
  679. /*
  680. * Function irttp_give_credit (self)
  681. *
  682. * Send a dataless flowdata TTP-PDU and give available credit to peer
  683. * TSAP
  684. */
  685. static inline void irttp_give_credit(struct tsap_cb *self)
  686. {
  687. struct sk_buff *tx_skb = NULL;
  688. unsigned long flags;
  689. int n;
  690. IRDA_ASSERT(self != NULL, return;);
  691. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  692. IRDA_DEBUG(4, "%s() send=%d,avail=%d,remote=%d\n",
  693. __func__,
  694. self->send_credit, self->avail_credit, self->remote_credit);
  695. /* Give credit to peer */
  696. tx_skb = alloc_skb(TTP_MAX_HEADER, GFP_ATOMIC);
  697. if (!tx_skb)
  698. return;
  699. /* Reserve space for LMP, and LAP header */
  700. skb_reserve(tx_skb, LMP_MAX_HEADER);
  701. /*
  702. * Since we can transmit and receive frames concurrently,
  703. * the code below is a critical region and we must assure that
  704. * nobody messes with the credits while we update them.
  705. */
  706. spin_lock_irqsave(&self->lock, flags);
  707. n = self->avail_credit;
  708. self->avail_credit = 0;
  709. /* Only space for 127 credits in frame */
  710. if (n > 127) {
  711. self->avail_credit = n - 127;
  712. n = 127;
  713. }
  714. self->remote_credit += n;
  715. spin_unlock_irqrestore(&self->lock, flags);
  716. skb_put(tx_skb, 1);
  717. tx_skb->data[0] = (__u8) (n & 0x7f);
  718. irlmp_data_request(self->lsap, tx_skb);
  719. self->stats.tx_packets++;
  720. }
  721. /*
  722. * Function irttp_udata_indication (instance, sap, skb)
  723. *
  724. * Received some unit-data (unreliable)
  725. *
  726. */
  727. static int irttp_udata_indication(void *instance, void *sap,
  728. struct sk_buff *skb)
  729. {
  730. struct tsap_cb *self;
  731. int err;
  732. IRDA_DEBUG(4, "%s()\n", __func__);
  733. self = instance;
  734. IRDA_ASSERT(self != NULL, return -1;);
  735. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  736. IRDA_ASSERT(skb != NULL, return -1;);
  737. self->stats.rx_packets++;
  738. /* Just pass data to layer above */
  739. if (self->notify.udata_indication) {
  740. err = self->notify.udata_indication(self->notify.instance,
  741. self, skb);
  742. /* Same comment as in irttp_do_data_indication() */
  743. if (!err)
  744. return 0;
  745. }
  746. /* Either no handler, or handler returns an error */
  747. dev_kfree_skb(skb);
  748. return 0;
  749. }
  750. /*
  751. * Function irttp_data_indication (instance, sap, skb)
  752. *
  753. * Receive segment from IrLMP.
  754. *
  755. */
  756. static int irttp_data_indication(void *instance, void *sap,
  757. struct sk_buff *skb)
  758. {
  759. struct tsap_cb *self;
  760. unsigned long flags;
  761. int n;
  762. self = instance;
  763. n = skb->data[0] & 0x7f; /* Extract the credits */
  764. self->stats.rx_packets++;
  765. /* Deal with inbound credit
  766. * Since we can transmit and receive frames concurrently,
  767. * the code below is a critical region and we must assure that
  768. * nobody messes with the credits while we update them.
  769. */
  770. spin_lock_irqsave(&self->lock, flags);
  771. self->send_credit += n;
  772. if (skb->len > 1)
  773. self->remote_credit--;
  774. spin_unlock_irqrestore(&self->lock, flags);
  775. /*
  776. * Data or dataless packet? Dataless frames contains only the
  777. * TTP_HEADER.
  778. */
  779. if (skb->len > 1) {
  780. /*
  781. * We don't remove the TTP header, since we must preserve the
  782. * more bit, so the defragment routing knows what to do
  783. */
  784. skb_queue_tail(&self->rx_queue, skb);
  785. } else {
  786. /* Dataless flowdata TTP-PDU */
  787. dev_kfree_skb(skb);
  788. }
  789. /* Push data to the higher layer.
  790. * We do it synchronously because running the todo timer for each
  791. * receive packet would be too much overhead and latency.
  792. * By passing control to the higher layer, we run the risk that
  793. * it may take time or grab a lock. Most often, the higher layer
  794. * will only put packet in a queue.
  795. * Anyway, packets are only dripping through the IrDA, so we can
  796. * have time before the next packet.
  797. * Further, we are run from NET_BH, so the worse that can happen is
  798. * us missing the optimal time to send back the PF bit in LAP.
  799. * Jean II */
  800. irttp_run_rx_queue(self);
  801. /* We now give credits to peer in irttp_run_rx_queue().
  802. * We need to send credit *NOW*, otherwise we are going
  803. * to miss the next Tx window. The todo timer may take
  804. * a while before it's run... - Jean II */
  805. /*
  806. * If the peer device has given us some credits and we didn't have
  807. * anyone from before, then we need to shedule the tx queue.
  808. * We need to do that because our Tx have stopped (so we may not
  809. * get any LAP flow indication) and the user may be stopped as
  810. * well. - Jean II
  811. */
  812. if (self->send_credit == n) {
  813. /* Restart pushing stuff to LAP */
  814. irttp_run_tx_queue(self);
  815. /* Note : we don't want to schedule the todo timer
  816. * because it has horrible latency. No tasklets
  817. * because the tasklet API is broken. - Jean II */
  818. }
  819. return 0;
  820. }
  821. /*
  822. * Function irttp_status_indication (self, reason)
  823. *
  824. * Status_indication, just pass to the higher layer...
  825. *
  826. */
  827. static void irttp_status_indication(void *instance,
  828. LINK_STATUS link, LOCK_STATUS lock)
  829. {
  830. struct tsap_cb *self;
  831. IRDA_DEBUG(4, "%s()\n", __func__);
  832. self = instance;
  833. IRDA_ASSERT(self != NULL, return;);
  834. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  835. /* Check if client has already closed the TSAP and gone away */
  836. if (self->close_pend)
  837. return;
  838. /*
  839. * Inform service user if he has requested it
  840. */
  841. if (self->notify.status_indication != NULL)
  842. self->notify.status_indication(self->notify.instance,
  843. link, lock);
  844. else
  845. IRDA_DEBUG(2, "%s(), no handler\n", __func__);
  846. }
  847. /*
  848. * Function irttp_flow_indication (self, reason)
  849. *
  850. * Flow_indication : IrLAP tells us to send more data.
  851. *
  852. */
  853. static void irttp_flow_indication(void *instance, void *sap, LOCAL_FLOW flow)
  854. {
  855. struct tsap_cb *self;
  856. self = instance;
  857. IRDA_ASSERT(self != NULL, return;);
  858. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  859. IRDA_DEBUG(4, "%s(instance=%p)\n", __func__, self);
  860. /* We are "polled" directly from LAP, and the LAP want to fill
  861. * its Tx window. We want to do our best to send it data, so that
  862. * we maximise the window. On the other hand, we want to limit the
  863. * amount of work here so that LAP doesn't hang forever waiting
  864. * for packets. - Jean II */
  865. /* Try to send some packets. Currently, LAP calls us every time
  866. * there is one free slot, so we will send only one packet.
  867. * This allow the scheduler to do its round robin - Jean II */
  868. irttp_run_tx_queue(self);
  869. /* Note regarding the interraction with higher layer.
  870. * irttp_run_tx_queue() may call the client when its queue
  871. * start to empty, via notify.flow_indication(). Initially.
  872. * I wanted this to happen in a tasklet, to avoid client
  873. * grabbing the CPU, but we can't use tasklets safely. And timer
  874. * is definitely too slow.
  875. * This will happen only once per LAP window, and usually at
  876. * the third packet (unless window is smaller). LAP is still
  877. * doing mtt and sending first packet so it's sort of OK
  878. * to do that. Jean II */
  879. /* If we need to send disconnect. try to do it now */
  880. if (self->disconnect_pend)
  881. irttp_start_todo_timer(self, 0);
  882. }
  883. /*
  884. * Function irttp_flow_request (self, command)
  885. *
  886. * This function could be used by the upper layers to tell IrTTP to stop
  887. * delivering frames if the receive queues are starting to get full, or
  888. * to tell IrTTP to start delivering frames again.
  889. */
  890. void irttp_flow_request(struct tsap_cb *self, LOCAL_FLOW flow)
  891. {
  892. IRDA_DEBUG(1, "%s()\n", __func__);
  893. IRDA_ASSERT(self != NULL, return;);
  894. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  895. switch (flow) {
  896. case FLOW_STOP:
  897. IRDA_DEBUG(1, "%s(), flow stop\n", __func__);
  898. self->rx_sdu_busy = TRUE;
  899. break;
  900. case FLOW_START:
  901. IRDA_DEBUG(1, "%s(), flow start\n", __func__);
  902. self->rx_sdu_busy = FALSE;
  903. /* Client say he can accept more data, try to free our
  904. * queues ASAP - Jean II */
  905. irttp_run_rx_queue(self);
  906. break;
  907. default:
  908. IRDA_DEBUG(1, "%s(), Unknown flow command!\n", __func__);
  909. }
  910. }
  911. EXPORT_SYMBOL(irttp_flow_request);
  912. /*
  913. * Function irttp_connect_request (self, dtsap_sel, daddr, qos)
  914. *
  915. * Try to connect to remote destination TSAP selector
  916. *
  917. */
  918. int irttp_connect_request(struct tsap_cb *self, __u8 dtsap_sel,
  919. __u32 saddr, __u32 daddr,
  920. struct qos_info *qos, __u32 max_sdu_size,
  921. struct sk_buff *userdata)
  922. {
  923. struct sk_buff *tx_skb;
  924. __u8 *frame;
  925. __u8 n;
  926. IRDA_DEBUG(4, "%s(), max_sdu_size=%d\n", __func__, max_sdu_size);
  927. IRDA_ASSERT(self != NULL, return -EBADR;);
  928. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -EBADR;);
  929. if (self->connected) {
  930. if (userdata)
  931. dev_kfree_skb(userdata);
  932. return -EISCONN;
  933. }
  934. /* Any userdata supplied? */
  935. if (userdata == NULL) {
  936. tx_skb = alloc_skb(TTP_MAX_HEADER + TTP_SAR_HEADER,
  937. GFP_ATOMIC);
  938. if (!tx_skb)
  939. return -ENOMEM;
  940. /* Reserve space for MUX_CONTROL and LAP header */
  941. skb_reserve(tx_skb, TTP_MAX_HEADER + TTP_SAR_HEADER);
  942. } else {
  943. tx_skb = userdata;
  944. /*
  945. * Check that the client has reserved enough space for
  946. * headers
  947. */
  948. IRDA_ASSERT(skb_headroom(userdata) >= TTP_MAX_HEADER,
  949. { dev_kfree_skb(userdata); return -1; });
  950. }
  951. /* Initialize connection parameters */
  952. self->connected = FALSE;
  953. self->avail_credit = 0;
  954. self->rx_max_sdu_size = max_sdu_size;
  955. self->rx_sdu_size = 0;
  956. self->rx_sdu_busy = FALSE;
  957. self->dtsap_sel = dtsap_sel;
  958. n = self->initial_credit;
  959. self->remote_credit = 0;
  960. self->send_credit = 0;
  961. /*
  962. * Give away max 127 credits for now
  963. */
  964. if (n > 127) {
  965. self->avail_credit = n - 127;
  966. n = 127;
  967. }
  968. self->remote_credit = n;
  969. /* SAR enabled? */
  970. if (max_sdu_size > 0) {
  971. IRDA_ASSERT(skb_headroom(tx_skb) >= (TTP_MAX_HEADER + TTP_SAR_HEADER),
  972. { dev_kfree_skb(tx_skb); return -1; });
  973. /* Insert SAR parameters */
  974. frame = skb_push(tx_skb, TTP_HEADER + TTP_SAR_HEADER);
  975. frame[0] = TTP_PARAMETERS | n;
  976. frame[1] = 0x04; /* Length */
  977. frame[2] = 0x01; /* MaxSduSize */
  978. frame[3] = 0x02; /* Value length */
  979. put_unaligned(cpu_to_be16((__u16) max_sdu_size),
  980. (__be16 *)(frame+4));
  981. } else {
  982. /* Insert plain TTP header */
  983. frame = skb_push(tx_skb, TTP_HEADER);
  984. /* Insert initial credit in frame */
  985. frame[0] = n & 0x7f;
  986. }
  987. /* Connect with IrLMP. No QoS parameters for now */
  988. return irlmp_connect_request(self->lsap, dtsap_sel, saddr, daddr, qos,
  989. tx_skb);
  990. }
  991. EXPORT_SYMBOL(irttp_connect_request);
  992. /*
  993. * Function irttp_connect_confirm (handle, qos, skb)
  994. *
  995. * Service user confirms TSAP connection with peer.
  996. *
  997. */
  998. static void irttp_connect_confirm(void *instance, void *sap,
  999. struct qos_info *qos, __u32 max_seg_size,
  1000. __u8 max_header_size, struct sk_buff *skb)
  1001. {
  1002. struct tsap_cb *self;
  1003. int parameters;
  1004. int ret;
  1005. __u8 plen;
  1006. __u8 n;
  1007. IRDA_DEBUG(4, "%s()\n", __func__);
  1008. self = instance;
  1009. IRDA_ASSERT(self != NULL, return;);
  1010. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  1011. IRDA_ASSERT(skb != NULL, return;);
  1012. self->max_seg_size = max_seg_size - TTP_HEADER;
  1013. self->max_header_size = max_header_size + TTP_HEADER;
  1014. /*
  1015. * Check if we have got some QoS parameters back! This should be the
  1016. * negotiated QoS for the link.
  1017. */
  1018. if (qos) {
  1019. IRDA_DEBUG(4, "IrTTP, Negotiated BAUD_RATE: %02x\n",
  1020. qos->baud_rate.bits);
  1021. IRDA_DEBUG(4, "IrTTP, Negotiated BAUD_RATE: %d bps.\n",
  1022. qos->baud_rate.value);
  1023. }
  1024. n = skb->data[0] & 0x7f;
  1025. IRDA_DEBUG(4, "%s(), Initial send_credit=%d\n", __func__, n);
  1026. self->send_credit = n;
  1027. self->tx_max_sdu_size = 0;
  1028. self->connected = TRUE;
  1029. parameters = skb->data[0] & 0x80;
  1030. IRDA_ASSERT(skb->len >= TTP_HEADER, return;);
  1031. skb_pull(skb, TTP_HEADER);
  1032. if (parameters) {
  1033. plen = skb->data[0];
  1034. ret = irda_param_extract_all(self, skb->data+1,
  1035. IRDA_MIN(skb->len-1, plen),
  1036. &param_info);
  1037. /* Any errors in the parameter list? */
  1038. if (ret < 0) {
  1039. IRDA_WARNING("%s: error extracting parameters\n",
  1040. __func__);
  1041. dev_kfree_skb(skb);
  1042. /* Do not accept this connection attempt */
  1043. return;
  1044. }
  1045. /* Remove parameters */
  1046. skb_pull(skb, IRDA_MIN(skb->len, plen+1));
  1047. }
  1048. IRDA_DEBUG(4, "%s() send=%d,avail=%d,remote=%d\n", __func__,
  1049. self->send_credit, self->avail_credit, self->remote_credit);
  1050. IRDA_DEBUG(2, "%s(), MaxSduSize=%d\n", __func__,
  1051. self->tx_max_sdu_size);
  1052. if (self->notify.connect_confirm) {
  1053. self->notify.connect_confirm(self->notify.instance, self, qos,
  1054. self->tx_max_sdu_size,
  1055. self->max_header_size, skb);
  1056. } else
  1057. dev_kfree_skb(skb);
  1058. }
  1059. /*
  1060. * Function irttp_connect_indication (handle, skb)
  1061. *
  1062. * Some other device is connecting to this TSAP
  1063. *
  1064. */
  1065. static void irttp_connect_indication(void *instance, void *sap,
  1066. struct qos_info *qos, __u32 max_seg_size, __u8 max_header_size,
  1067. struct sk_buff *skb)
  1068. {
  1069. struct tsap_cb *self;
  1070. struct lsap_cb *lsap;
  1071. int parameters;
  1072. int ret;
  1073. __u8 plen;
  1074. __u8 n;
  1075. self = instance;
  1076. IRDA_ASSERT(self != NULL, return;);
  1077. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  1078. IRDA_ASSERT(skb != NULL, return;);
  1079. lsap = sap;
  1080. self->max_seg_size = max_seg_size - TTP_HEADER;
  1081. self->max_header_size = max_header_size+TTP_HEADER;
  1082. IRDA_DEBUG(4, "%s(), TSAP sel=%02x\n", __func__, self->stsap_sel);
  1083. /* Need to update dtsap_sel if its equal to LSAP_ANY */
  1084. self->dtsap_sel = lsap->dlsap_sel;
  1085. n = skb->data[0] & 0x7f;
  1086. self->send_credit = n;
  1087. self->tx_max_sdu_size = 0;
  1088. parameters = skb->data[0] & 0x80;
  1089. IRDA_ASSERT(skb->len >= TTP_HEADER, return;);
  1090. skb_pull(skb, TTP_HEADER);
  1091. if (parameters) {
  1092. plen = skb->data[0];
  1093. ret = irda_param_extract_all(self, skb->data+1,
  1094. IRDA_MIN(skb->len-1, plen),
  1095. &param_info);
  1096. /* Any errors in the parameter list? */
  1097. if (ret < 0) {
  1098. IRDA_WARNING("%s: error extracting parameters\n",
  1099. __func__);
  1100. dev_kfree_skb(skb);
  1101. /* Do not accept this connection attempt */
  1102. return;
  1103. }
  1104. /* Remove parameters */
  1105. skb_pull(skb, IRDA_MIN(skb->len, plen+1));
  1106. }
  1107. if (self->notify.connect_indication) {
  1108. self->notify.connect_indication(self->notify.instance, self,
  1109. qos, self->tx_max_sdu_size,
  1110. self->max_header_size, skb);
  1111. } else
  1112. dev_kfree_skb(skb);
  1113. }
  1114. /*
  1115. * Function irttp_connect_response (handle, userdata)
  1116. *
  1117. * Service user is accepting the connection, just pass it down to
  1118. * IrLMP!
  1119. *
  1120. */
  1121. int irttp_connect_response(struct tsap_cb *self, __u32 max_sdu_size,
  1122. struct sk_buff *userdata)
  1123. {
  1124. struct sk_buff *tx_skb;
  1125. __u8 *frame;
  1126. int ret;
  1127. __u8 n;
  1128. IRDA_ASSERT(self != NULL, return -1;);
  1129. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  1130. IRDA_DEBUG(4, "%s(), Source TSAP selector=%02x\n", __func__,
  1131. self->stsap_sel);
  1132. /* Any userdata supplied? */
  1133. if (userdata == NULL) {
  1134. tx_skb = alloc_skb(TTP_MAX_HEADER + TTP_SAR_HEADER,
  1135. GFP_ATOMIC);
  1136. if (!tx_skb)
  1137. return -ENOMEM;
  1138. /* Reserve space for MUX_CONTROL and LAP header */
  1139. skb_reserve(tx_skb, TTP_MAX_HEADER + TTP_SAR_HEADER);
  1140. } else {
  1141. tx_skb = userdata;
  1142. /*
  1143. * Check that the client has reserved enough space for
  1144. * headers
  1145. */
  1146. IRDA_ASSERT(skb_headroom(userdata) >= TTP_MAX_HEADER,
  1147. { dev_kfree_skb(userdata); return -1; });
  1148. }
  1149. self->avail_credit = 0;
  1150. self->remote_credit = 0;
  1151. self->rx_max_sdu_size = max_sdu_size;
  1152. self->rx_sdu_size = 0;
  1153. self->rx_sdu_busy = FALSE;
  1154. n = self->initial_credit;
  1155. /* Frame has only space for max 127 credits (7 bits) */
  1156. if (n > 127) {
  1157. self->avail_credit = n - 127;
  1158. n = 127;
  1159. }
  1160. self->remote_credit = n;
  1161. self->connected = TRUE;
  1162. /* SAR enabled? */
  1163. if (max_sdu_size > 0) {
  1164. IRDA_ASSERT(skb_headroom(tx_skb) >= (TTP_MAX_HEADER + TTP_SAR_HEADER),
  1165. { dev_kfree_skb(tx_skb); return -1; });
  1166. /* Insert TTP header with SAR parameters */
  1167. frame = skb_push(tx_skb, TTP_HEADER + TTP_SAR_HEADER);
  1168. frame[0] = TTP_PARAMETERS | n;
  1169. frame[1] = 0x04; /* Length */
  1170. /* irda_param_insert(self, IRTTP_MAX_SDU_SIZE, frame+1, */
  1171. /* TTP_SAR_HEADER, &param_info) */
  1172. frame[2] = 0x01; /* MaxSduSize */
  1173. frame[3] = 0x02; /* Value length */
  1174. put_unaligned(cpu_to_be16((__u16) max_sdu_size),
  1175. (__be16 *)(frame+4));
  1176. } else {
  1177. /* Insert TTP header */
  1178. frame = skb_push(tx_skb, TTP_HEADER);
  1179. frame[0] = n & 0x7f;
  1180. }
  1181. ret = irlmp_connect_response(self->lsap, tx_skb);
  1182. return ret;
  1183. }
  1184. EXPORT_SYMBOL(irttp_connect_response);
  1185. /*
  1186. * Function irttp_dup (self, instance)
  1187. *
  1188. * Duplicate TSAP, can be used by servers to confirm a connection on a
  1189. * new TSAP so it can keep listening on the old one.
  1190. */
  1191. struct tsap_cb *irttp_dup(struct tsap_cb *orig, void *instance)
  1192. {
  1193. struct tsap_cb *new;
  1194. unsigned long flags;
  1195. IRDA_DEBUG(1, "%s()\n", __func__);
  1196. /* Protect our access to the old tsap instance */
  1197. spin_lock_irqsave(&irttp->tsaps->hb_spinlock, flags);
  1198. /* Find the old instance */
  1199. if (!hashbin_find(irttp->tsaps, (long) orig, NULL)) {
  1200. IRDA_DEBUG(0, "%s(), unable to find TSAP\n", __func__);
  1201. spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
  1202. return NULL;
  1203. }
  1204. /* Allocate a new instance */
  1205. new = kmemdup(orig, sizeof(struct tsap_cb), GFP_ATOMIC);
  1206. if (!new) {
  1207. IRDA_DEBUG(0, "%s(), unable to kmalloc\n", __func__);
  1208. spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
  1209. return NULL;
  1210. }
  1211. spin_lock_init(&new->lock);
  1212. /* We don't need the old instance any more */
  1213. spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
  1214. /* Try to dup the LSAP (may fail if we were too slow) */
  1215. new->lsap = irlmp_dup(orig->lsap, new);
  1216. if (!new->lsap) {
  1217. IRDA_DEBUG(0, "%s(), dup failed!\n", __func__);
  1218. kfree(new);
  1219. return NULL;
  1220. }
  1221. /* Not everything should be copied */
  1222. new->notify.instance = instance;
  1223. /* Initialize internal objects */
  1224. irttp_init_tsap(new);
  1225. /* This is locked */
  1226. hashbin_insert(irttp->tsaps, (irda_queue_t *) new, (long) new, NULL);
  1227. return new;
  1228. }
  1229. EXPORT_SYMBOL(irttp_dup);
  1230. /*
  1231. * Function irttp_disconnect_request (self)
  1232. *
  1233. * Close this connection please! If priority is high, the queued data
  1234. * segments, if any, will be deallocated first
  1235. *
  1236. */
  1237. int irttp_disconnect_request(struct tsap_cb *self, struct sk_buff *userdata,
  1238. int priority)
  1239. {
  1240. int ret;
  1241. IRDA_ASSERT(self != NULL, return -1;);
  1242. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  1243. /* Already disconnected? */
  1244. if (!self->connected) {
  1245. IRDA_DEBUG(4, "%s(), already disconnected!\n", __func__);
  1246. if (userdata)
  1247. dev_kfree_skb(userdata);
  1248. return -1;
  1249. }
  1250. /* Disconnect already pending ?
  1251. * We need to use an atomic operation to prevent reentry. This
  1252. * function may be called from various context, like user, timer
  1253. * for following a disconnect_indication() (i.e. net_bh).
  1254. * Jean II */
  1255. if (test_and_set_bit(0, &self->disconnect_pend)) {
  1256. IRDA_DEBUG(0, "%s(), disconnect already pending\n",
  1257. __func__);
  1258. if (userdata)
  1259. dev_kfree_skb(userdata);
  1260. /* Try to make some progress */
  1261. irttp_run_tx_queue(self);
  1262. return -1;
  1263. }
  1264. /*
  1265. * Check if there is still data segments in the transmit queue
  1266. */
  1267. if (!skb_queue_empty(&self->tx_queue)) {
  1268. if (priority == P_HIGH) {
  1269. /*
  1270. * No need to send the queued data, if we are
  1271. * disconnecting right now since the data will
  1272. * not have any usable connection to be sent on
  1273. */
  1274. IRDA_DEBUG(1, "%s(): High priority!!()\n", __func__);
  1275. irttp_flush_queues(self);
  1276. } else if (priority == P_NORMAL) {
  1277. /*
  1278. * Must delay disconnect until after all data segments
  1279. * have been sent and the tx_queue is empty
  1280. */
  1281. /* We'll reuse this one later for the disconnect */
  1282. self->disconnect_skb = userdata; /* May be NULL */
  1283. irttp_run_tx_queue(self);
  1284. irttp_start_todo_timer(self, HZ/10);
  1285. return -1;
  1286. }
  1287. }
  1288. /* Note : we don't need to check if self->rx_queue is full and the
  1289. * state of self->rx_sdu_busy because the disconnect response will
  1290. * be sent at the LMP level (so even if the peer has its Tx queue
  1291. * full of data). - Jean II */
  1292. IRDA_DEBUG(1, "%s(), Disconnecting ...\n", __func__);
  1293. self->connected = FALSE;
  1294. if (!userdata) {
  1295. struct sk_buff *tx_skb;
  1296. tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
  1297. if (!tx_skb)
  1298. return -ENOMEM;
  1299. /*
  1300. * Reserve space for MUX and LAP header
  1301. */
  1302. skb_reserve(tx_skb, LMP_MAX_HEADER);
  1303. userdata = tx_skb;
  1304. }
  1305. ret = irlmp_disconnect_request(self->lsap, userdata);
  1306. /* The disconnect is no longer pending */
  1307. clear_bit(0, &self->disconnect_pend); /* FALSE */
  1308. return ret;
  1309. }
  1310. EXPORT_SYMBOL(irttp_disconnect_request);
  1311. /*
  1312. * Function irttp_disconnect_indication (self, reason)
  1313. *
  1314. * Disconnect indication, TSAP disconnected by peer?
  1315. *
  1316. */
  1317. static void irttp_disconnect_indication(void *instance, void *sap,
  1318. LM_REASON reason, struct sk_buff *skb)
  1319. {
  1320. struct tsap_cb *self;
  1321. IRDA_DEBUG(4, "%s()\n", __func__);
  1322. self = instance;
  1323. IRDA_ASSERT(self != NULL, return;);
  1324. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  1325. /* Prevent higher layer to send more data */
  1326. self->connected = FALSE;
  1327. /* Check if client has already tried to close the TSAP */
  1328. if (self->close_pend) {
  1329. /* In this case, the higher layer is probably gone. Don't
  1330. * bother it and clean up the remains - Jean II */
  1331. if (skb)
  1332. dev_kfree_skb(skb);
  1333. irttp_close_tsap(self);
  1334. return;
  1335. }
  1336. /* If we are here, we assume that is the higher layer is still
  1337. * waiting for the disconnect notification and able to process it,
  1338. * even if he tried to disconnect. Otherwise, it would have already
  1339. * attempted to close the tsap and self->close_pend would be TRUE.
  1340. * Jean II */
  1341. /* No need to notify the client if has already tried to disconnect */
  1342. if (self->notify.disconnect_indication)
  1343. self->notify.disconnect_indication(self->notify.instance, self,
  1344. reason, skb);
  1345. else
  1346. if (skb)
  1347. dev_kfree_skb(skb);
  1348. }
  1349. /*
  1350. * Function irttp_do_data_indication (self, skb)
  1351. *
  1352. * Try to deliver reassembled skb to layer above, and requeue it if that
  1353. * for some reason should fail. We mark rx sdu as busy to apply back
  1354. * pressure is necessary.
  1355. */
  1356. static void irttp_do_data_indication(struct tsap_cb *self, struct sk_buff *skb)
  1357. {
  1358. int err;
  1359. /* Check if client has already closed the TSAP and gone away */
  1360. if (self->close_pend) {
  1361. dev_kfree_skb(skb);
  1362. return;
  1363. }
  1364. err = self->notify.data_indication(self->notify.instance, self, skb);
  1365. /* Usually the layer above will notify that it's input queue is
  1366. * starting to get filled by using the flow request, but this may
  1367. * be difficult, so it can instead just refuse to eat it and just
  1368. * give an error back
  1369. */
  1370. if (err) {
  1371. IRDA_DEBUG(0, "%s() requeueing skb!\n", __func__);
  1372. /* Make sure we take a break */
  1373. self->rx_sdu_busy = TRUE;
  1374. /* Need to push the header in again */
  1375. skb_push(skb, TTP_HEADER);
  1376. skb->data[0] = 0x00; /* Make sure MORE bit is cleared */
  1377. /* Put skb back on queue */
  1378. skb_queue_head(&self->rx_queue, skb);
  1379. }
  1380. }
  1381. /*
  1382. * Function irttp_run_rx_queue (self)
  1383. *
  1384. * Check if we have any frames to be transmitted, or if we have any
  1385. * available credit to give away.
  1386. */
  1387. static void irttp_run_rx_queue(struct tsap_cb *self)
  1388. {
  1389. struct sk_buff *skb;
  1390. int more = 0;
  1391. IRDA_DEBUG(2, "%s() send=%d,avail=%d,remote=%d\n", __func__,
  1392. self->send_credit, self->avail_credit, self->remote_credit);
  1393. /* Get exclusive access to the rx queue, otherwise don't touch it */
  1394. if (irda_lock(&self->rx_queue_lock) == FALSE)
  1395. return;
  1396. /*
  1397. * Reassemble all frames in receive queue and deliver them
  1398. */
  1399. while (!self->rx_sdu_busy && (skb = skb_dequeue(&self->rx_queue))) {
  1400. /* This bit will tell us if it's the last fragment or not */
  1401. more = skb->data[0] & 0x80;
  1402. /* Remove TTP header */
  1403. skb_pull(skb, TTP_HEADER);
  1404. /* Add the length of the remaining data */
  1405. self->rx_sdu_size += skb->len;
  1406. /*
  1407. * If SAR is disabled, or user has requested no reassembly
  1408. * of received fragments then we just deliver them
  1409. * immediately. This can be requested by clients that
  1410. * implements byte streams without any message boundaries
  1411. */
  1412. if (self->rx_max_sdu_size == TTP_SAR_DISABLE) {
  1413. irttp_do_data_indication(self, skb);
  1414. self->rx_sdu_size = 0;
  1415. continue;
  1416. }
  1417. /* Check if this is a fragment, and not the last fragment */
  1418. if (more) {
  1419. /*
  1420. * Queue the fragment if we still are within the
  1421. * limits of the maximum size of the rx_sdu
  1422. */
  1423. if (self->rx_sdu_size <= self->rx_max_sdu_size) {
  1424. IRDA_DEBUG(4, "%s(), queueing frag\n",
  1425. __func__);
  1426. skb_queue_tail(&self->rx_fragments, skb);
  1427. } else {
  1428. /* Free the part of the SDU that is too big */
  1429. dev_kfree_skb(skb);
  1430. }
  1431. continue;
  1432. }
  1433. /*
  1434. * This is the last fragment, so time to reassemble!
  1435. */
  1436. if ((self->rx_sdu_size <= self->rx_max_sdu_size) ||
  1437. (self->rx_max_sdu_size == TTP_SAR_UNBOUND)) {
  1438. /*
  1439. * A little optimizing. Only queue the fragment if
  1440. * there are other fragments. Since if this is the
  1441. * last and only fragment, there is no need to
  1442. * reassemble :-)
  1443. */
  1444. if (!skb_queue_empty(&self->rx_fragments)) {
  1445. skb_queue_tail(&self->rx_fragments,
  1446. skb);
  1447. skb = irttp_reassemble_skb(self);
  1448. }
  1449. /* Now we can deliver the reassembled skb */
  1450. irttp_do_data_indication(self, skb);
  1451. } else {
  1452. IRDA_DEBUG(1, "%s(), Truncated frame\n", __func__);
  1453. /* Free the part of the SDU that is too big */
  1454. dev_kfree_skb(skb);
  1455. /* Deliver only the valid but truncated part of SDU */
  1456. skb = irttp_reassemble_skb(self);
  1457. irttp_do_data_indication(self, skb);
  1458. }
  1459. self->rx_sdu_size = 0;
  1460. }
  1461. /*
  1462. * It's not trivial to keep track of how many credits are available
  1463. * by incrementing at each packet, because delivery may fail
  1464. * (irttp_do_data_indication() may requeue the frame) and because
  1465. * we need to take care of fragmentation.
  1466. * We want the other side to send up to initial_credit packets.
  1467. * We have some frames in our queues, and we have already allowed it
  1468. * to send remote_credit.
  1469. * No need to spinlock, write is atomic and self correcting...
  1470. * Jean II
  1471. */
  1472. self->avail_credit = (self->initial_credit -
  1473. (self->remote_credit +
  1474. skb_queue_len(&self->rx_queue) +
  1475. skb_queue_len(&self->rx_fragments)));
  1476. /* Do we have too much credits to send to peer ? */
  1477. if ((self->remote_credit <= TTP_RX_MIN_CREDIT) &&
  1478. (self->avail_credit > 0)) {
  1479. /* Send explicit credit frame */
  1480. irttp_give_credit(self);
  1481. /* Note : do *NOT* check if tx_queue is non-empty, that
  1482. * will produce deadlocks. I repeat : send a credit frame
  1483. * even if we have something to send in our Tx queue.
  1484. * If we have credits, it means that our Tx queue is blocked.
  1485. *
  1486. * Let's suppose the peer can't keep up with our Tx. He will
  1487. * flow control us by not sending us any credits, and we
  1488. * will stop Tx and start accumulating credits here.
  1489. * Up to the point where the peer will stop its Tx queue,
  1490. * for lack of credits.
  1491. * Let's assume the peer application is single threaded.
  1492. * It will block on Tx and never consume any Rx buffer.
  1493. * Deadlock. Guaranteed. - Jean II
  1494. */
  1495. }
  1496. /* Reset lock */
  1497. self->rx_queue_lock = 0;
  1498. }
  1499. #ifdef CONFIG_PROC_FS
  1500. struct irttp_iter_state {
  1501. int id;
  1502. };
  1503. static void *irttp_seq_start(struct seq_file *seq, loff_t *pos)
  1504. {
  1505. struct irttp_iter_state *iter = seq->private;
  1506. struct tsap_cb *self;
  1507. /* Protect our access to the tsap list */
  1508. spin_lock_irq(&irttp->tsaps->hb_spinlock);
  1509. iter->id = 0;
  1510. for (self = (struct tsap_cb *) hashbin_get_first(irttp->tsaps);
  1511. self != NULL;
  1512. self = (struct tsap_cb *) hashbin_get_next(irttp->tsaps)) {
  1513. if (iter->id == *pos)
  1514. break;
  1515. ++iter->id;
  1516. }
  1517. return self;
  1518. }
  1519. static void *irttp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  1520. {
  1521. struct irttp_iter_state *iter = seq->private;
  1522. ++*pos;
  1523. ++iter->id;
  1524. return (void *) hashbin_get_next(irttp->tsaps);
  1525. }
  1526. static void irttp_seq_stop(struct seq_file *seq, void *v)
  1527. {
  1528. spin_unlock_irq(&irttp->tsaps->hb_spinlock);
  1529. }
  1530. static int irttp_seq_show(struct seq_file *seq, void *v)
  1531. {
  1532. const struct irttp_iter_state *iter = seq->private;
  1533. const struct tsap_cb *self = v;
  1534. seq_printf(seq, "TSAP %d, ", iter->id);
  1535. seq_printf(seq, "stsap_sel: %02x, ",
  1536. self->stsap_sel);
  1537. seq_printf(seq, "dtsap_sel: %02x\n",
  1538. self->dtsap_sel);
  1539. seq_printf(seq, " connected: %s, ",
  1540. self->connected ? "TRUE" : "FALSE");
  1541. seq_printf(seq, "avail credit: %d, ",
  1542. self->avail_credit);
  1543. seq_printf(seq, "remote credit: %d, ",
  1544. self->remote_credit);
  1545. seq_printf(seq, "send credit: %d\n",
  1546. self->send_credit);
  1547. seq_printf(seq, " tx packets: %lu, ",
  1548. self->stats.tx_packets);
  1549. seq_printf(seq, "rx packets: %lu, ",
  1550. self->stats.rx_packets);
  1551. seq_printf(seq, "tx_queue len: %u ",
  1552. skb_queue_len(&self->tx_queue));
  1553. seq_printf(seq, "rx_queue len: %u\n",
  1554. skb_queue_len(&self->rx_queue));
  1555. seq_printf(seq, " tx_sdu_busy: %s, ",
  1556. self->tx_sdu_busy ? "TRUE" : "FALSE");
  1557. seq_printf(seq, "rx_sdu_busy: %s\n",
  1558. self->rx_sdu_busy ? "TRUE" : "FALSE");
  1559. seq_printf(seq, " max_seg_size: %u, ",
  1560. self->max_seg_size);
  1561. seq_printf(seq, "tx_max_sdu_size: %u, ",
  1562. self->tx_max_sdu_size);
  1563. seq_printf(seq, "rx_max_sdu_size: %u\n",
  1564. self->rx_max_sdu_size);
  1565. seq_printf(seq, " Used by (%s)\n\n",
  1566. self->notify.name);
  1567. return 0;
  1568. }
  1569. static const struct seq_operations irttp_seq_ops = {
  1570. .start = irttp_seq_start,
  1571. .next = irttp_seq_next,
  1572. .stop = irttp_seq_stop,
  1573. .show = irttp_seq_show,
  1574. };
  1575. static int irttp_seq_open(struct inode *inode, struct file *file)
  1576. {
  1577. return seq_open_private(file, &irttp_seq_ops,
  1578. sizeof(struct irttp_iter_state));
  1579. }
  1580. const struct file_operations irttp_seq_fops = {
  1581. .owner = THIS_MODULE,
  1582. .open = irttp_seq_open,
  1583. .read = seq_read,
  1584. .llseek = seq_lseek,
  1585. .release = seq_release_private,
  1586. };
  1587. #endif /* PROC_FS */