irttp.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
  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. {
  530. IRDA_ERROR("%s: SAR enabled, but data is larger than TxMaxSduSize!\n",
  531. __func__);
  532. ret = -EMSGSIZE;
  533. goto err;
  534. }
  535. /*
  536. * Check if transmit queue is full
  537. */
  538. if (skb_queue_len(&self->tx_queue) >= TTP_TX_MAX_QUEUE) {
  539. /*
  540. * Give it a chance to empty itself
  541. */
  542. irttp_run_tx_queue(self);
  543. /* Drop packet. This error code should trigger the caller
  544. * to resend the data in the client code - Jean II */
  545. ret = -ENOBUFS;
  546. goto err;
  547. }
  548. /* Queue frame, or queue frame segments */
  549. if ((self->tx_max_sdu_size == 0) || (skb->len < self->max_seg_size)) {
  550. /* Queue frame */
  551. IRDA_ASSERT(skb_headroom(skb) >= TTP_HEADER, return -1;);
  552. frame = skb_push(skb, TTP_HEADER);
  553. frame[0] = 0x00; /* Clear more bit */
  554. skb_queue_tail(&self->tx_queue, skb);
  555. } else {
  556. /*
  557. * Fragment the frame, this function will also queue the
  558. * fragments, we don't care about the fact the transmit
  559. * queue may be overfilled by all the segments for a little
  560. * while
  561. */
  562. irttp_fragment_skb(self, skb);
  563. }
  564. /* Check if we can accept more data from client */
  565. if ((!self->tx_sdu_busy) &&
  566. (skb_queue_len(&self->tx_queue) > TTP_TX_HIGH_THRESHOLD)) {
  567. /* Tx queue filling up, so stop client. */
  568. if (self->notify.flow_indication) {
  569. self->notify.flow_indication(self->notify.instance,
  570. self, FLOW_STOP);
  571. }
  572. /* self->tx_sdu_busy is the state of the client.
  573. * Update state after notifying client to avoid
  574. * race condition with irttp_flow_indication().
  575. * If the queue empty itself after our test but before
  576. * we set the flag, we will fix ourselves below in
  577. * irttp_run_tx_queue().
  578. * Jean II */
  579. self->tx_sdu_busy = TRUE;
  580. }
  581. /* Try to make some progress */
  582. irttp_run_tx_queue(self);
  583. return 0;
  584. err:
  585. dev_kfree_skb(skb);
  586. return ret;
  587. }
  588. EXPORT_SYMBOL(irttp_data_request);
  589. /*
  590. * Function irttp_run_tx_queue (self)
  591. *
  592. * Transmit packets queued for transmission (if possible)
  593. *
  594. */
  595. static void irttp_run_tx_queue(struct tsap_cb *self)
  596. {
  597. struct sk_buff *skb;
  598. unsigned long flags;
  599. int n;
  600. IRDA_DEBUG(2, "%s() : send_credit = %d, queue_len = %d\n",
  601. __func__,
  602. self->send_credit, skb_queue_len(&self->tx_queue));
  603. /* Get exclusive access to the tx queue, otherwise don't touch it */
  604. if (irda_lock(&self->tx_queue_lock) == FALSE)
  605. return;
  606. /* Try to send out frames as long as we have credits
  607. * and as long as LAP is not full. If LAP is full, it will
  608. * poll us through irttp_flow_indication() - Jean II */
  609. while ((self->send_credit > 0) &&
  610. (!irlmp_lap_tx_queue_full(self->lsap)) &&
  611. (skb = skb_dequeue(&self->tx_queue)))
  612. {
  613. /*
  614. * Since we can transmit and receive frames concurrently,
  615. * the code below is a critical region and we must assure that
  616. * nobody messes with the credits while we update them.
  617. */
  618. spin_lock_irqsave(&self->lock, flags);
  619. n = self->avail_credit;
  620. self->avail_credit = 0;
  621. /* Only room for 127 credits in frame */
  622. if (n > 127) {
  623. self->avail_credit = n-127;
  624. n = 127;
  625. }
  626. self->remote_credit += n;
  627. self->send_credit--;
  628. spin_unlock_irqrestore(&self->lock, flags);
  629. /*
  630. * More bit must be set by the data_request() or fragment()
  631. * functions
  632. */
  633. skb->data[0] |= (n & 0x7f);
  634. /* Detach from socket.
  635. * The current skb has a reference to the socket that sent
  636. * it (skb->sk). When we pass it to IrLMP, the skb will be
  637. * stored in in IrLAP (self->wx_list). When we are within
  638. * IrLAP, we lose the notion of socket, so we should not
  639. * have a reference to a socket. So, we drop it here.
  640. *
  641. * Why does it matter ?
  642. * When the skb is freed (kfree_skb), if it is associated
  643. * with a socket, it release buffer space on the socket
  644. * (through sock_wfree() and sock_def_write_space()).
  645. * If the socket no longer exist, we may crash. Hard.
  646. * When we close a socket, we make sure that associated packets
  647. * in IrTTP are freed. However, we have no way to cancel
  648. * the packet that we have passed to IrLAP. So, if a packet
  649. * remains in IrLAP (retry on the link or else) after we
  650. * close the socket, we are dead !
  651. * Jean II */
  652. if (skb->sk != NULL) {
  653. /* IrSOCK application, IrOBEX, ... */
  654. skb_orphan(skb);
  655. }
  656. /* IrCOMM over IrTTP, IrLAN, ... */
  657. /* Pass the skb to IrLMP - done */
  658. irlmp_data_request(self->lsap, skb);
  659. self->stats.tx_packets++;
  660. }
  661. /* Check if we can accept more frames from client.
  662. * We don't want to wait until the todo timer to do that, and we
  663. * can't use tasklets (grr...), so we are obliged to give control
  664. * to client. That's ok, this test will be true not too often
  665. * (max once per LAP window) and we are called from places
  666. * where we can spend a bit of time doing stuff. - Jean II */
  667. if ((self->tx_sdu_busy) &&
  668. (skb_queue_len(&self->tx_queue) < TTP_TX_LOW_THRESHOLD) &&
  669. (!self->close_pend))
  670. {
  671. if (self->notify.flow_indication)
  672. self->notify.flow_indication(self->notify.instance,
  673. self, FLOW_START);
  674. /* self->tx_sdu_busy is the state of the client.
  675. * We don't really have a race here, but it's always safer
  676. * to update our state after the client - Jean II */
  677. self->tx_sdu_busy = FALSE;
  678. }
  679. /* Reset lock */
  680. self->tx_queue_lock = 0;
  681. }
  682. /*
  683. * Function irttp_give_credit (self)
  684. *
  685. * Send a dataless flowdata TTP-PDU and give available credit to peer
  686. * TSAP
  687. */
  688. static inline void irttp_give_credit(struct tsap_cb *self)
  689. {
  690. struct sk_buff *tx_skb = NULL;
  691. unsigned long flags;
  692. int n;
  693. IRDA_ASSERT(self != NULL, return;);
  694. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  695. IRDA_DEBUG(4, "%s() send=%d,avail=%d,remote=%d\n",
  696. __func__,
  697. self->send_credit, self->avail_credit, self->remote_credit);
  698. /* Give credit to peer */
  699. tx_skb = alloc_skb(TTP_MAX_HEADER, GFP_ATOMIC);
  700. if (!tx_skb)
  701. return;
  702. /* Reserve space for LMP, and LAP header */
  703. skb_reserve(tx_skb, LMP_MAX_HEADER);
  704. /*
  705. * Since we can transmit and receive frames concurrently,
  706. * the code below is a critical region and we must assure that
  707. * nobody messes with the credits while we update them.
  708. */
  709. spin_lock_irqsave(&self->lock, flags);
  710. n = self->avail_credit;
  711. self->avail_credit = 0;
  712. /* Only space for 127 credits in frame */
  713. if (n > 127) {
  714. self->avail_credit = n - 127;
  715. n = 127;
  716. }
  717. self->remote_credit += n;
  718. spin_unlock_irqrestore(&self->lock, flags);
  719. skb_put(tx_skb, 1);
  720. tx_skb->data[0] = (__u8) (n & 0x7f);
  721. irlmp_data_request(self->lsap, tx_skb);
  722. self->stats.tx_packets++;
  723. }
  724. /*
  725. * Function irttp_udata_indication (instance, sap, skb)
  726. *
  727. * Received some unit-data (unreliable)
  728. *
  729. */
  730. static int irttp_udata_indication(void *instance, void *sap,
  731. struct sk_buff *skb)
  732. {
  733. struct tsap_cb *self;
  734. int err;
  735. IRDA_DEBUG(4, "%s()\n", __func__);
  736. self = instance;
  737. IRDA_ASSERT(self != NULL, return -1;);
  738. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  739. IRDA_ASSERT(skb != NULL, return -1;);
  740. self->stats.rx_packets++;
  741. /* Just pass data to layer above */
  742. if (self->notify.udata_indication) {
  743. err = self->notify.udata_indication(self->notify.instance,
  744. self,skb);
  745. /* Same comment as in irttp_do_data_indication() */
  746. if (!err)
  747. return 0;
  748. }
  749. /* Either no handler, or handler returns an error */
  750. dev_kfree_skb(skb);
  751. return 0;
  752. }
  753. /*
  754. * Function irttp_data_indication (instance, sap, skb)
  755. *
  756. * Receive segment from IrLMP.
  757. *
  758. */
  759. static int irttp_data_indication(void *instance, void *sap,
  760. struct sk_buff *skb)
  761. {
  762. struct tsap_cb *self;
  763. unsigned long flags;
  764. int n;
  765. self = instance;
  766. n = skb->data[0] & 0x7f; /* Extract the credits */
  767. self->stats.rx_packets++;
  768. /* Deal with inbound credit
  769. * Since we can transmit and receive frames concurrently,
  770. * the code below is a critical region and we must assure that
  771. * nobody messes with the credits while we update them.
  772. */
  773. spin_lock_irqsave(&self->lock, flags);
  774. self->send_credit += n;
  775. if (skb->len > 1)
  776. self->remote_credit--;
  777. spin_unlock_irqrestore(&self->lock, flags);
  778. /*
  779. * Data or dataless packet? Dataless frames contains only the
  780. * TTP_HEADER.
  781. */
  782. if (skb->len > 1) {
  783. /*
  784. * We don't remove the TTP header, since we must preserve the
  785. * more bit, so the defragment routing knows what to do
  786. */
  787. skb_queue_tail(&self->rx_queue, skb);
  788. } else {
  789. /* Dataless flowdata TTP-PDU */
  790. dev_kfree_skb(skb);
  791. }
  792. /* Push data to the higher layer.
  793. * We do it synchronously because running the todo timer for each
  794. * receive packet would be too much overhead and latency.
  795. * By passing control to the higher layer, we run the risk that
  796. * it may take time or grab a lock. Most often, the higher layer
  797. * will only put packet in a queue.
  798. * Anyway, packets are only dripping through the IrDA, so we can
  799. * have time before the next packet.
  800. * Further, we are run from NET_BH, so the worse that can happen is
  801. * us missing the optimal time to send back the PF bit in LAP.
  802. * Jean II */
  803. irttp_run_rx_queue(self);
  804. /* We now give credits to peer in irttp_run_rx_queue().
  805. * We need to send credit *NOW*, otherwise we are going
  806. * to miss the next Tx window. The todo timer may take
  807. * a while before it's run... - Jean II */
  808. /*
  809. * If the peer device has given us some credits and we didn't have
  810. * anyone from before, then we need to shedule the tx queue.
  811. * We need to do that because our Tx have stopped (so we may not
  812. * get any LAP flow indication) and the user may be stopped as
  813. * well. - Jean II
  814. */
  815. if (self->send_credit == n) {
  816. /* Restart pushing stuff to LAP */
  817. irttp_run_tx_queue(self);
  818. /* Note : we don't want to schedule the todo timer
  819. * because it has horrible latency. No tasklets
  820. * because the tasklet API is broken. - Jean II */
  821. }
  822. return 0;
  823. }
  824. /*
  825. * Function irttp_status_indication (self, reason)
  826. *
  827. * Status_indication, just pass to the higher layer...
  828. *
  829. */
  830. static void irttp_status_indication(void *instance,
  831. LINK_STATUS link, LOCK_STATUS lock)
  832. {
  833. struct tsap_cb *self;
  834. IRDA_DEBUG(4, "%s()\n", __func__);
  835. self = instance;
  836. IRDA_ASSERT(self != NULL, return;);
  837. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  838. /* Check if client has already closed the TSAP and gone away */
  839. if (self->close_pend)
  840. return;
  841. /*
  842. * Inform service user if he has requested it
  843. */
  844. if (self->notify.status_indication != NULL)
  845. self->notify.status_indication(self->notify.instance,
  846. link, lock);
  847. else
  848. IRDA_DEBUG(2, "%s(), no handler\n", __func__);
  849. }
  850. /*
  851. * Function irttp_flow_indication (self, reason)
  852. *
  853. * Flow_indication : IrLAP tells us to send more data.
  854. *
  855. */
  856. static void irttp_flow_indication(void *instance, void *sap, LOCAL_FLOW flow)
  857. {
  858. struct tsap_cb *self;
  859. self = instance;
  860. IRDA_ASSERT(self != NULL, return;);
  861. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  862. IRDA_DEBUG(4, "%s(instance=%p)\n", __func__, self);
  863. /* We are "polled" directly from LAP, and the LAP want to fill
  864. * its Tx window. We want to do our best to send it data, so that
  865. * we maximise the window. On the other hand, we want to limit the
  866. * amount of work here so that LAP doesn't hang forever waiting
  867. * for packets. - Jean II */
  868. /* Try to send some packets. Currently, LAP calls us every time
  869. * there is one free slot, so we will send only one packet.
  870. * This allow the scheduler to do its round robin - Jean II */
  871. irttp_run_tx_queue(self);
  872. /* Note regarding the interraction with higher layer.
  873. * irttp_run_tx_queue() may call the client when its queue
  874. * start to empty, via notify.flow_indication(). Initially.
  875. * I wanted this to happen in a tasklet, to avoid client
  876. * grabbing the CPU, but we can't use tasklets safely. And timer
  877. * is definitely too slow.
  878. * This will happen only once per LAP window, and usually at
  879. * the third packet (unless window is smaller). LAP is still
  880. * doing mtt and sending first packet so it's sort of OK
  881. * to do that. Jean II */
  882. /* If we need to send disconnect. try to do it now */
  883. if(self->disconnect_pend)
  884. irttp_start_todo_timer(self, 0);
  885. }
  886. /*
  887. * Function irttp_flow_request (self, command)
  888. *
  889. * This function could be used by the upper layers to tell IrTTP to stop
  890. * delivering frames if the receive queues are starting to get full, or
  891. * to tell IrTTP to start delivering frames again.
  892. */
  893. void irttp_flow_request(struct tsap_cb *self, LOCAL_FLOW flow)
  894. {
  895. IRDA_DEBUG(1, "%s()\n", __func__);
  896. IRDA_ASSERT(self != NULL, return;);
  897. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  898. switch (flow) {
  899. case FLOW_STOP:
  900. IRDA_DEBUG(1, "%s(), flow stop\n", __func__);
  901. self->rx_sdu_busy = TRUE;
  902. break;
  903. case FLOW_START:
  904. IRDA_DEBUG(1, "%s(), flow start\n", __func__);
  905. self->rx_sdu_busy = FALSE;
  906. /* Client say he can accept more data, try to free our
  907. * queues ASAP - Jean II */
  908. irttp_run_rx_queue(self);
  909. break;
  910. default:
  911. IRDA_DEBUG(1, "%s(), Unknown flow command!\n", __func__);
  912. }
  913. }
  914. EXPORT_SYMBOL(irttp_flow_request);
  915. /*
  916. * Function irttp_connect_request (self, dtsap_sel, daddr, qos)
  917. *
  918. * Try to connect to remote destination TSAP selector
  919. *
  920. */
  921. int irttp_connect_request(struct tsap_cb *self, __u8 dtsap_sel,
  922. __u32 saddr, __u32 daddr,
  923. struct qos_info *qos, __u32 max_sdu_size,
  924. struct sk_buff *userdata)
  925. {
  926. struct sk_buff *tx_skb;
  927. __u8 *frame;
  928. __u8 n;
  929. IRDA_DEBUG(4, "%s(), max_sdu_size=%d\n", __func__, max_sdu_size);
  930. IRDA_ASSERT(self != NULL, return -EBADR;);
  931. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -EBADR;);
  932. if (self->connected) {
  933. if(userdata)
  934. dev_kfree_skb(userdata);
  935. return -EISCONN;
  936. }
  937. /* Any userdata supplied? */
  938. if (userdata == NULL) {
  939. tx_skb = alloc_skb(TTP_MAX_HEADER + TTP_SAR_HEADER,
  940. GFP_ATOMIC);
  941. if (!tx_skb)
  942. return -ENOMEM;
  943. /* Reserve space for MUX_CONTROL and LAP header */
  944. skb_reserve(tx_skb, TTP_MAX_HEADER + TTP_SAR_HEADER);
  945. } else {
  946. tx_skb = userdata;
  947. /*
  948. * Check that the client has reserved enough space for
  949. * headers
  950. */
  951. IRDA_ASSERT(skb_headroom(userdata) >= TTP_MAX_HEADER,
  952. { dev_kfree_skb(userdata); return -1; } );
  953. }
  954. /* Initialize connection parameters */
  955. self->connected = FALSE;
  956. self->avail_credit = 0;
  957. self->rx_max_sdu_size = max_sdu_size;
  958. self->rx_sdu_size = 0;
  959. self->rx_sdu_busy = FALSE;
  960. self->dtsap_sel = dtsap_sel;
  961. n = self->initial_credit;
  962. self->remote_credit = 0;
  963. self->send_credit = 0;
  964. /*
  965. * Give away max 127 credits for now
  966. */
  967. if (n > 127) {
  968. self->avail_credit=n-127;
  969. n = 127;
  970. }
  971. self->remote_credit = n;
  972. /* SAR enabled? */
  973. if (max_sdu_size > 0) {
  974. IRDA_ASSERT(skb_headroom(tx_skb) >= (TTP_MAX_HEADER + TTP_SAR_HEADER),
  975. { dev_kfree_skb(tx_skb); return -1; } );
  976. /* Insert SAR parameters */
  977. frame = skb_push(tx_skb, TTP_HEADER+TTP_SAR_HEADER);
  978. frame[0] = TTP_PARAMETERS | n;
  979. frame[1] = 0x04; /* Length */
  980. frame[2] = 0x01; /* MaxSduSize */
  981. frame[3] = 0x02; /* Value length */
  982. put_unaligned(cpu_to_be16((__u16) max_sdu_size),
  983. (__be16 *)(frame+4));
  984. } else {
  985. /* Insert plain TTP header */
  986. frame = skb_push(tx_skb, TTP_HEADER);
  987. /* Insert initial credit in frame */
  988. frame[0] = n & 0x7f;
  989. }
  990. /* Connect with IrLMP. No QoS parameters for now */
  991. return irlmp_connect_request(self->lsap, dtsap_sel, saddr, daddr, qos,
  992. tx_skb);
  993. }
  994. EXPORT_SYMBOL(irttp_connect_request);
  995. /*
  996. * Function irttp_connect_confirm (handle, qos, skb)
  997. *
  998. * Service user confirms TSAP connection with peer.
  999. *
  1000. */
  1001. static void irttp_connect_confirm(void *instance, void *sap,
  1002. struct qos_info *qos, __u32 max_seg_size,
  1003. __u8 max_header_size, struct sk_buff *skb)
  1004. {
  1005. struct tsap_cb *self;
  1006. int parameters;
  1007. int ret;
  1008. __u8 plen;
  1009. __u8 n;
  1010. IRDA_DEBUG(4, "%s()\n", __func__);
  1011. self = instance;
  1012. IRDA_ASSERT(self != NULL, return;);
  1013. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  1014. IRDA_ASSERT(skb != NULL, return;);
  1015. self->max_seg_size = max_seg_size - TTP_HEADER;
  1016. self->max_header_size = max_header_size + TTP_HEADER;
  1017. /*
  1018. * Check if we have got some QoS parameters back! This should be the
  1019. * negotiated QoS for the link.
  1020. */
  1021. if (qos) {
  1022. IRDA_DEBUG(4, "IrTTP, Negotiated BAUD_RATE: %02x\n",
  1023. qos->baud_rate.bits);
  1024. IRDA_DEBUG(4, "IrTTP, Negotiated BAUD_RATE: %d bps.\n",
  1025. qos->baud_rate.value);
  1026. }
  1027. n = skb->data[0] & 0x7f;
  1028. IRDA_DEBUG(4, "%s(), Initial send_credit=%d\n", __func__, n);
  1029. self->send_credit = n;
  1030. self->tx_max_sdu_size = 0;
  1031. self->connected = TRUE;
  1032. parameters = skb->data[0] & 0x80;
  1033. IRDA_ASSERT(skb->len >= TTP_HEADER, return;);
  1034. skb_pull(skb, TTP_HEADER);
  1035. if (parameters) {
  1036. plen = skb->data[0];
  1037. ret = irda_param_extract_all(self, skb->data+1,
  1038. IRDA_MIN(skb->len-1, plen),
  1039. &param_info);
  1040. /* Any errors in the parameter list? */
  1041. if (ret < 0) {
  1042. IRDA_WARNING("%s: error extracting parameters\n",
  1043. __func__);
  1044. dev_kfree_skb(skb);
  1045. /* Do not accept this connection attempt */
  1046. return;
  1047. }
  1048. /* Remove parameters */
  1049. skb_pull(skb, IRDA_MIN(skb->len, plen+1));
  1050. }
  1051. IRDA_DEBUG(4, "%s() send=%d,avail=%d,remote=%d\n", __func__,
  1052. self->send_credit, self->avail_credit, self->remote_credit);
  1053. IRDA_DEBUG(2, "%s(), MaxSduSize=%d\n", __func__,
  1054. self->tx_max_sdu_size);
  1055. if (self->notify.connect_confirm) {
  1056. self->notify.connect_confirm(self->notify.instance, self, qos,
  1057. self->tx_max_sdu_size,
  1058. self->max_header_size, skb);
  1059. } else
  1060. dev_kfree_skb(skb);
  1061. }
  1062. /*
  1063. * Function irttp_connect_indication (handle, skb)
  1064. *
  1065. * Some other device is connecting to this TSAP
  1066. *
  1067. */
  1068. static void irttp_connect_indication(void *instance, void *sap,
  1069. struct qos_info *qos, __u32 max_seg_size, __u8 max_header_size,
  1070. struct sk_buff *skb)
  1071. {
  1072. struct tsap_cb *self;
  1073. struct lsap_cb *lsap;
  1074. int parameters;
  1075. int ret;
  1076. __u8 plen;
  1077. __u8 n;
  1078. self = instance;
  1079. IRDA_ASSERT(self != NULL, return;);
  1080. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  1081. IRDA_ASSERT(skb != NULL, return;);
  1082. lsap = sap;
  1083. self->max_seg_size = max_seg_size - TTP_HEADER;
  1084. self->max_header_size = max_header_size+TTP_HEADER;
  1085. IRDA_DEBUG(4, "%s(), TSAP sel=%02x\n", __func__, self->stsap_sel);
  1086. /* Need to update dtsap_sel if its equal to LSAP_ANY */
  1087. self->dtsap_sel = lsap->dlsap_sel;
  1088. n = skb->data[0] & 0x7f;
  1089. self->send_credit = n;
  1090. self->tx_max_sdu_size = 0;
  1091. parameters = skb->data[0] & 0x80;
  1092. IRDA_ASSERT(skb->len >= TTP_HEADER, return;);
  1093. skb_pull(skb, TTP_HEADER);
  1094. if (parameters) {
  1095. plen = skb->data[0];
  1096. ret = irda_param_extract_all(self, skb->data+1,
  1097. IRDA_MIN(skb->len-1, plen),
  1098. &param_info);
  1099. /* Any errors in the parameter list? */
  1100. if (ret < 0) {
  1101. IRDA_WARNING("%s: error extracting parameters\n",
  1102. __func__);
  1103. dev_kfree_skb(skb);
  1104. /* Do not accept this connection attempt */
  1105. return;
  1106. }
  1107. /* Remove parameters */
  1108. skb_pull(skb, IRDA_MIN(skb->len, plen+1));
  1109. }
  1110. if (self->notify.connect_indication) {
  1111. self->notify.connect_indication(self->notify.instance, self,
  1112. qos, self->tx_max_sdu_size,
  1113. self->max_header_size, skb);
  1114. } else
  1115. dev_kfree_skb(skb);
  1116. }
  1117. /*
  1118. * Function irttp_connect_response (handle, userdata)
  1119. *
  1120. * Service user is accepting the connection, just pass it down to
  1121. * IrLMP!
  1122. *
  1123. */
  1124. int irttp_connect_response(struct tsap_cb *self, __u32 max_sdu_size,
  1125. struct sk_buff *userdata)
  1126. {
  1127. struct sk_buff *tx_skb;
  1128. __u8 *frame;
  1129. int ret;
  1130. __u8 n;
  1131. IRDA_ASSERT(self != NULL, return -1;);
  1132. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  1133. IRDA_DEBUG(4, "%s(), Source TSAP selector=%02x\n", __func__,
  1134. self->stsap_sel);
  1135. /* Any userdata supplied? */
  1136. if (userdata == NULL) {
  1137. tx_skb = alloc_skb(TTP_MAX_HEADER + TTP_SAR_HEADER,
  1138. GFP_ATOMIC);
  1139. if (!tx_skb)
  1140. return -ENOMEM;
  1141. /* Reserve space for MUX_CONTROL and LAP header */
  1142. skb_reserve(tx_skb, TTP_MAX_HEADER + TTP_SAR_HEADER);
  1143. } else {
  1144. tx_skb = userdata;
  1145. /*
  1146. * Check that the client has reserved enough space for
  1147. * headers
  1148. */
  1149. IRDA_ASSERT(skb_headroom(userdata) >= TTP_MAX_HEADER,
  1150. { dev_kfree_skb(userdata); return -1; } );
  1151. }
  1152. self->avail_credit = 0;
  1153. self->remote_credit = 0;
  1154. self->rx_max_sdu_size = max_sdu_size;
  1155. self->rx_sdu_size = 0;
  1156. self->rx_sdu_busy = FALSE;
  1157. n = self->initial_credit;
  1158. /* Frame has only space for max 127 credits (7 bits) */
  1159. if (n > 127) {
  1160. self->avail_credit = n - 127;
  1161. n = 127;
  1162. }
  1163. self->remote_credit = n;
  1164. self->connected = TRUE;
  1165. /* SAR enabled? */
  1166. if (max_sdu_size > 0) {
  1167. IRDA_ASSERT(skb_headroom(tx_skb) >= (TTP_MAX_HEADER + TTP_SAR_HEADER),
  1168. { dev_kfree_skb(tx_skb); return -1; } );
  1169. /* Insert TTP header with SAR parameters */
  1170. frame = skb_push(tx_skb, TTP_HEADER+TTP_SAR_HEADER);
  1171. frame[0] = TTP_PARAMETERS | n;
  1172. frame[1] = 0x04; /* Length */
  1173. /* irda_param_insert(self, IRTTP_MAX_SDU_SIZE, frame+1, */
  1174. /* TTP_SAR_HEADER, &param_info) */
  1175. frame[2] = 0x01; /* MaxSduSize */
  1176. frame[3] = 0x02; /* Value length */
  1177. put_unaligned(cpu_to_be16((__u16) max_sdu_size),
  1178. (__be16 *)(frame+4));
  1179. } else {
  1180. /* Insert TTP header */
  1181. frame = skb_push(tx_skb, TTP_HEADER);
  1182. frame[0] = n & 0x7f;
  1183. }
  1184. ret = irlmp_connect_response(self->lsap, tx_skb);
  1185. return ret;
  1186. }
  1187. EXPORT_SYMBOL(irttp_connect_response);
  1188. /*
  1189. * Function irttp_dup (self, instance)
  1190. *
  1191. * Duplicate TSAP, can be used by servers to confirm a connection on a
  1192. * new TSAP so it can keep listening on the old one.
  1193. */
  1194. struct tsap_cb *irttp_dup(struct tsap_cb *orig, void *instance)
  1195. {
  1196. struct tsap_cb *new;
  1197. unsigned long flags;
  1198. IRDA_DEBUG(1, "%s()\n", __func__);
  1199. /* Protect our access to the old tsap instance */
  1200. spin_lock_irqsave(&irttp->tsaps->hb_spinlock, flags);
  1201. /* Find the old instance */
  1202. if (!hashbin_find(irttp->tsaps, (long) orig, NULL)) {
  1203. IRDA_DEBUG(0, "%s(), unable to find TSAP\n", __func__);
  1204. spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
  1205. return NULL;
  1206. }
  1207. /* Allocate a new instance */
  1208. new = kmemdup(orig, sizeof(struct tsap_cb), GFP_ATOMIC);
  1209. if (!new) {
  1210. IRDA_DEBUG(0, "%s(), unable to kmalloc\n", __func__);
  1211. spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
  1212. return NULL;
  1213. }
  1214. spin_lock_init(&new->lock);
  1215. /* We don't need the old instance any more */
  1216. spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
  1217. /* Try to dup the LSAP (may fail if we were too slow) */
  1218. new->lsap = irlmp_dup(orig->lsap, new);
  1219. if (!new->lsap) {
  1220. IRDA_DEBUG(0, "%s(), dup failed!\n", __func__);
  1221. kfree(new);
  1222. return NULL;
  1223. }
  1224. /* Not everything should be copied */
  1225. new->notify.instance = instance;
  1226. /* Initialize internal objects */
  1227. irttp_init_tsap(new);
  1228. /* This is locked */
  1229. hashbin_insert(irttp->tsaps, (irda_queue_t *) new, (long) new, NULL);
  1230. return new;
  1231. }
  1232. EXPORT_SYMBOL(irttp_dup);
  1233. /*
  1234. * Function irttp_disconnect_request (self)
  1235. *
  1236. * Close this connection please! If priority is high, the queued data
  1237. * segments, if any, will be deallocated first
  1238. *
  1239. */
  1240. int irttp_disconnect_request(struct tsap_cb *self, struct sk_buff *userdata,
  1241. int priority)
  1242. {
  1243. int ret;
  1244. IRDA_ASSERT(self != NULL, return -1;);
  1245. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
  1246. /* Already disconnected? */
  1247. if (!self->connected) {
  1248. IRDA_DEBUG(4, "%s(), already disconnected!\n", __func__);
  1249. if (userdata)
  1250. dev_kfree_skb(userdata);
  1251. return -1;
  1252. }
  1253. /* Disconnect already pending ?
  1254. * We need to use an atomic operation to prevent reentry. This
  1255. * function may be called from various context, like user, timer
  1256. * for following a disconnect_indication() (i.e. net_bh).
  1257. * Jean II */
  1258. if(test_and_set_bit(0, &self->disconnect_pend)) {
  1259. IRDA_DEBUG(0, "%s(), disconnect already pending\n",
  1260. __func__);
  1261. if (userdata)
  1262. dev_kfree_skb(userdata);
  1263. /* Try to make some progress */
  1264. irttp_run_tx_queue(self);
  1265. return -1;
  1266. }
  1267. /*
  1268. * Check if there is still data segments in the transmit queue
  1269. */
  1270. if (!skb_queue_empty(&self->tx_queue)) {
  1271. if (priority == P_HIGH) {
  1272. /*
  1273. * No need to send the queued data, if we are
  1274. * disconnecting right now since the data will
  1275. * not have any usable connection to be sent on
  1276. */
  1277. IRDA_DEBUG(1, "%s(): High priority!!()\n", __func__);
  1278. irttp_flush_queues(self);
  1279. } else if (priority == P_NORMAL) {
  1280. /*
  1281. * Must delay disconnect until after all data segments
  1282. * have been sent and the tx_queue is empty
  1283. */
  1284. /* We'll reuse this one later for the disconnect */
  1285. self->disconnect_skb = userdata; /* May be NULL */
  1286. irttp_run_tx_queue(self);
  1287. irttp_start_todo_timer(self, HZ/10);
  1288. return -1;
  1289. }
  1290. }
  1291. /* Note : we don't need to check if self->rx_queue is full and the
  1292. * state of self->rx_sdu_busy because the disconnect response will
  1293. * be sent at the LMP level (so even if the peer has its Tx queue
  1294. * full of data). - Jean II */
  1295. IRDA_DEBUG(1, "%s(), Disconnecting ...\n", __func__);
  1296. self->connected = FALSE;
  1297. if (!userdata) {
  1298. struct sk_buff *tx_skb;
  1299. tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
  1300. if (!tx_skb)
  1301. return -ENOMEM;
  1302. /*
  1303. * Reserve space for MUX and LAP header
  1304. */
  1305. skb_reserve(tx_skb, LMP_MAX_HEADER);
  1306. userdata = tx_skb;
  1307. }
  1308. ret = irlmp_disconnect_request(self->lsap, userdata);
  1309. /* The disconnect is no longer pending */
  1310. clear_bit(0, &self->disconnect_pend); /* FALSE */
  1311. return ret;
  1312. }
  1313. EXPORT_SYMBOL(irttp_disconnect_request);
  1314. /*
  1315. * Function irttp_disconnect_indication (self, reason)
  1316. *
  1317. * Disconnect indication, TSAP disconnected by peer?
  1318. *
  1319. */
  1320. static void irttp_disconnect_indication(void *instance, void *sap,
  1321. LM_REASON reason, struct sk_buff *skb)
  1322. {
  1323. struct tsap_cb *self;
  1324. IRDA_DEBUG(4, "%s()\n", __func__);
  1325. self = instance;
  1326. IRDA_ASSERT(self != NULL, return;);
  1327. IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
  1328. /* Prevent higher layer to send more data */
  1329. self->connected = FALSE;
  1330. /* Check if client has already tried to close the TSAP */
  1331. if (self->close_pend) {
  1332. /* In this case, the higher layer is probably gone. Don't
  1333. * bother it and clean up the remains - Jean II */
  1334. if (skb)
  1335. dev_kfree_skb(skb);
  1336. irttp_close_tsap(self);
  1337. return;
  1338. }
  1339. /* If we are here, we assume that is the higher layer is still
  1340. * waiting for the disconnect notification and able to process it,
  1341. * even if he tried to disconnect. Otherwise, it would have already
  1342. * attempted to close the tsap and self->close_pend would be TRUE.
  1343. * Jean II */
  1344. /* No need to notify the client if has already tried to disconnect */
  1345. if(self->notify.disconnect_indication)
  1346. self->notify.disconnect_indication(self->notify.instance, self,
  1347. reason, skb);
  1348. else
  1349. if (skb)
  1350. dev_kfree_skb(skb);
  1351. }
  1352. /*
  1353. * Function irttp_do_data_indication (self, skb)
  1354. *
  1355. * Try to deliver reassembled skb to layer above, and requeue it if that
  1356. * for some reason should fail. We mark rx sdu as busy to apply back
  1357. * pressure is necessary.
  1358. */
  1359. static void irttp_do_data_indication(struct tsap_cb *self, struct sk_buff *skb)
  1360. {
  1361. int err;
  1362. /* Check if client has already closed the TSAP and gone away */
  1363. if (self->close_pend) {
  1364. dev_kfree_skb(skb);
  1365. return;
  1366. }
  1367. err = self->notify.data_indication(self->notify.instance, self, skb);
  1368. /* Usually the layer above will notify that it's input queue is
  1369. * starting to get filled by using the flow request, but this may
  1370. * be difficult, so it can instead just refuse to eat it and just
  1371. * give an error back
  1372. */
  1373. if (err) {
  1374. IRDA_DEBUG(0, "%s() requeueing skb!\n", __func__);
  1375. /* Make sure we take a break */
  1376. self->rx_sdu_busy = TRUE;
  1377. /* Need to push the header in again */
  1378. skb_push(skb, TTP_HEADER);
  1379. skb->data[0] = 0x00; /* Make sure MORE bit is cleared */
  1380. /* Put skb back on queue */
  1381. skb_queue_head(&self->rx_queue, skb);
  1382. }
  1383. }
  1384. /*
  1385. * Function irttp_run_rx_queue (self)
  1386. *
  1387. * Check if we have any frames to be transmitted, or if we have any
  1388. * available credit to give away.
  1389. */
  1390. static void irttp_run_rx_queue(struct tsap_cb *self)
  1391. {
  1392. struct sk_buff *skb;
  1393. int more = 0;
  1394. IRDA_DEBUG(2, "%s() send=%d,avail=%d,remote=%d\n", __func__,
  1395. self->send_credit, self->avail_credit, self->remote_credit);
  1396. /* Get exclusive access to the rx queue, otherwise don't touch it */
  1397. if (irda_lock(&self->rx_queue_lock) == FALSE)
  1398. return;
  1399. /*
  1400. * Reassemble all frames in receive queue and deliver them
  1401. */
  1402. while (!self->rx_sdu_busy && (skb = skb_dequeue(&self->rx_queue))) {
  1403. /* This bit will tell us if it's the last fragment or not */
  1404. more = skb->data[0] & 0x80;
  1405. /* Remove TTP header */
  1406. skb_pull(skb, TTP_HEADER);
  1407. /* Add the length of the remaining data */
  1408. self->rx_sdu_size += skb->len;
  1409. /*
  1410. * If SAR is disabled, or user has requested no reassembly
  1411. * of received fragments then we just deliver them
  1412. * immediately. This can be requested by clients that
  1413. * implements byte streams without any message boundaries
  1414. */
  1415. if (self->rx_max_sdu_size == TTP_SAR_DISABLE) {
  1416. irttp_do_data_indication(self, skb);
  1417. self->rx_sdu_size = 0;
  1418. continue;
  1419. }
  1420. /* Check if this is a fragment, and not the last fragment */
  1421. if (more) {
  1422. /*
  1423. * Queue the fragment if we still are within the
  1424. * limits of the maximum size of the rx_sdu
  1425. */
  1426. if (self->rx_sdu_size <= self->rx_max_sdu_size) {
  1427. IRDA_DEBUG(4, "%s(), queueing frag\n",
  1428. __func__);
  1429. skb_queue_tail(&self->rx_fragments, skb);
  1430. } else {
  1431. /* Free the part of the SDU that is too big */
  1432. dev_kfree_skb(skb);
  1433. }
  1434. continue;
  1435. }
  1436. /*
  1437. * This is the last fragment, so time to reassemble!
  1438. */
  1439. if ((self->rx_sdu_size <= self->rx_max_sdu_size) ||
  1440. (self->rx_max_sdu_size == TTP_SAR_UNBOUND))
  1441. {
  1442. /*
  1443. * A little optimizing. Only queue the fragment if
  1444. * there are other fragments. Since if this is the
  1445. * last and only fragment, there is no need to
  1446. * reassemble :-)
  1447. */
  1448. if (!skb_queue_empty(&self->rx_fragments)) {
  1449. skb_queue_tail(&self->rx_fragments,
  1450. skb);
  1451. skb = irttp_reassemble_skb(self);
  1452. }
  1453. /* Now we can deliver the reassembled skb */
  1454. irttp_do_data_indication(self, skb);
  1455. } else {
  1456. IRDA_DEBUG(1, "%s(), Truncated frame\n", __func__);
  1457. /* Free the part of the SDU that is too big */
  1458. dev_kfree_skb(skb);
  1459. /* Deliver only the valid but truncated part of SDU */
  1460. skb = irttp_reassemble_skb(self);
  1461. irttp_do_data_indication(self, skb);
  1462. }
  1463. self->rx_sdu_size = 0;
  1464. }
  1465. /*
  1466. * It's not trivial to keep track of how many credits are available
  1467. * by incrementing at each packet, because delivery may fail
  1468. * (irttp_do_data_indication() may requeue the frame) and because
  1469. * we need to take care of fragmentation.
  1470. * We want the other side to send up to initial_credit packets.
  1471. * We have some frames in our queues, and we have already allowed it
  1472. * to send remote_credit.
  1473. * No need to spinlock, write is atomic and self correcting...
  1474. * Jean II
  1475. */
  1476. self->avail_credit = (self->initial_credit -
  1477. (self->remote_credit +
  1478. skb_queue_len(&self->rx_queue) +
  1479. skb_queue_len(&self->rx_fragments)));
  1480. /* Do we have too much credits to send to peer ? */
  1481. if ((self->remote_credit <= TTP_RX_MIN_CREDIT) &&
  1482. (self->avail_credit > 0)) {
  1483. /* Send explicit credit frame */
  1484. irttp_give_credit(self);
  1485. /* Note : do *NOT* check if tx_queue is non-empty, that
  1486. * will produce deadlocks. I repeat : send a credit frame
  1487. * even if we have something to send in our Tx queue.
  1488. * If we have credits, it means that our Tx queue is blocked.
  1489. *
  1490. * Let's suppose the peer can't keep up with our Tx. He will
  1491. * flow control us by not sending us any credits, and we
  1492. * will stop Tx and start accumulating credits here.
  1493. * Up to the point where the peer will stop its Tx queue,
  1494. * for lack of credits.
  1495. * Let's assume the peer application is single threaded.
  1496. * It will block on Tx and never consume any Rx buffer.
  1497. * Deadlock. Guaranteed. - Jean II
  1498. */
  1499. }
  1500. /* Reset lock */
  1501. self->rx_queue_lock = 0;
  1502. }
  1503. #ifdef CONFIG_PROC_FS
  1504. struct irttp_iter_state {
  1505. int id;
  1506. };
  1507. static void *irttp_seq_start(struct seq_file *seq, loff_t *pos)
  1508. {
  1509. struct irttp_iter_state *iter = seq->private;
  1510. struct tsap_cb *self;
  1511. /* Protect our access to the tsap list */
  1512. spin_lock_irq(&irttp->tsaps->hb_spinlock);
  1513. iter->id = 0;
  1514. for (self = (struct tsap_cb *) hashbin_get_first(irttp->tsaps);
  1515. self != NULL;
  1516. self = (struct tsap_cb *) hashbin_get_next(irttp->tsaps)) {
  1517. if (iter->id == *pos)
  1518. break;
  1519. ++iter->id;
  1520. }
  1521. return self;
  1522. }
  1523. static void *irttp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  1524. {
  1525. struct irttp_iter_state *iter = seq->private;
  1526. ++*pos;
  1527. ++iter->id;
  1528. return (void *) hashbin_get_next(irttp->tsaps);
  1529. }
  1530. static void irttp_seq_stop(struct seq_file *seq, void *v)
  1531. {
  1532. spin_unlock_irq(&irttp->tsaps->hb_spinlock);
  1533. }
  1534. static int irttp_seq_show(struct seq_file *seq, void *v)
  1535. {
  1536. const struct irttp_iter_state *iter = seq->private;
  1537. const struct tsap_cb *self = v;
  1538. seq_printf(seq, "TSAP %d, ", iter->id);
  1539. seq_printf(seq, "stsap_sel: %02x, ",
  1540. self->stsap_sel);
  1541. seq_printf(seq, "dtsap_sel: %02x\n",
  1542. self->dtsap_sel);
  1543. seq_printf(seq, " connected: %s, ",
  1544. self->connected? "TRUE":"FALSE");
  1545. seq_printf(seq, "avail credit: %d, ",
  1546. self->avail_credit);
  1547. seq_printf(seq, "remote credit: %d, ",
  1548. self->remote_credit);
  1549. seq_printf(seq, "send credit: %d\n",
  1550. self->send_credit);
  1551. seq_printf(seq, " tx packets: %lu, ",
  1552. self->stats.tx_packets);
  1553. seq_printf(seq, "rx packets: %lu, ",
  1554. self->stats.rx_packets);
  1555. seq_printf(seq, "tx_queue len: %u ",
  1556. skb_queue_len(&self->tx_queue));
  1557. seq_printf(seq, "rx_queue len: %u\n",
  1558. skb_queue_len(&self->rx_queue));
  1559. seq_printf(seq, " tx_sdu_busy: %s, ",
  1560. self->tx_sdu_busy? "TRUE":"FALSE");
  1561. seq_printf(seq, "rx_sdu_busy: %s\n",
  1562. self->rx_sdu_busy? "TRUE":"FALSE");
  1563. seq_printf(seq, " max_seg_size: %u, ",
  1564. self->max_seg_size);
  1565. seq_printf(seq, "tx_max_sdu_size: %u, ",
  1566. self->tx_max_sdu_size);
  1567. seq_printf(seq, "rx_max_sdu_size: %u\n",
  1568. self->rx_max_sdu_size);
  1569. seq_printf(seq, " Used by (%s)\n\n",
  1570. self->notify.name);
  1571. return 0;
  1572. }
  1573. static const struct seq_operations irttp_seq_ops = {
  1574. .start = irttp_seq_start,
  1575. .next = irttp_seq_next,
  1576. .stop = irttp_seq_stop,
  1577. .show = irttp_seq_show,
  1578. };
  1579. static int irttp_seq_open(struct inode *inode, struct file *file)
  1580. {
  1581. return seq_open_private(file, &irttp_seq_ops,
  1582. sizeof(struct irttp_iter_state));
  1583. }
  1584. const struct file_operations irttp_seq_fops = {
  1585. .owner = THIS_MODULE,
  1586. .open = irttp_seq_open,
  1587. .read = seq_read,
  1588. .llseek = seq_lseek,
  1589. .release = seq_release_private,
  1590. };
  1591. #endif /* PROC_FS */