irttp.c 51 KB

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