irttp.c 51 KB

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