irttp.c 51 KB

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