irttp.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*********************************************************************
  2. *
  3. * Filename: irttp.h
  4. * Version: 1.0
  5. * Description: Tiny Transport Protocol (TTP) definitions
  6. * Status: Experimental.
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Sun Aug 31 20:14:31 1997
  9. * Modified at: Sun Dec 12 13:09:07 1999
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
  13. * All Rights Reserved.
  14. * Copyright (c) 2000-2002 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. #ifndef IRTTP_H
  27. #define IRTTP_H
  28. #include <linux/types.h>
  29. #include <linux/skbuff.h>
  30. #include <linux/spinlock.h>
  31. #include <net/irda/irda.h>
  32. #include <net/irda/irlmp.h> /* struct lsap_cb */
  33. #include <net/irda/qos.h> /* struct qos_info */
  34. #include <net/irda/irqueue.h>
  35. #define TTP_MAX_CONNECTIONS LM_MAX_CONNECTIONS
  36. #define TTP_HEADER 1
  37. #define TTP_MAX_HEADER (TTP_HEADER + LMP_MAX_HEADER)
  38. #define TTP_SAR_HEADER 5
  39. #define TTP_PARAMETERS 0x80
  40. #define TTP_MORE 0x80
  41. /* Transmission queue sizes */
  42. /* Worst case scenario, two window of data - Jean II */
  43. #define TTP_TX_MAX_QUEUE 14
  44. /* We need to keep at least 5 frames to make sure that we can refill
  45. * appropriately the LAP layer. LAP keeps only two buffers, and we need
  46. * to have 7 to make a full window - Jean II */
  47. #define TTP_TX_LOW_THRESHOLD 5
  48. /* Most clients are synchronous with respect to flow control, so we can
  49. * keep a low number of Tx buffers in TTP - Jean II */
  50. #define TTP_TX_HIGH_THRESHOLD 7
  51. /* Receive queue sizes */
  52. /* Minimum of credit that the peer should hold.
  53. * If the peer has less credits than 9 frames, we will explicitly send
  54. * him some credits (through irttp_give_credit() and a specific frame).
  55. * Note that when we give credits it's likely that it won't be sent in
  56. * this LAP window, but in the next one. So, we make sure that the peer
  57. * has something to send while waiting for credits (one LAP window == 7
  58. * + 1 frames while he process the credits). - Jean II */
  59. #define TTP_RX_MIN_CREDIT 8
  60. /* This is the default maximum number of credits held by the peer, so the
  61. * default maximum number of frames he can send us before needing flow
  62. * control answer from us (this may be negociated differently at TSAP setup).
  63. * We want to minimise the number of times we have to explicitly send some
  64. * credit to the peer, hoping we can piggyback it on the return data. In
  65. * particular, it doesn't make sense for us to send credit more than once
  66. * per LAP window.
  67. * Moreover, giving credits has some latency, so we need strictly more than
  68. * a LAP window, otherwise we may already have credits in our Tx queue.
  69. * But on the other hand, we don't want to keep too many Rx buffer here
  70. * before starting to flow control the other end, so make it exactly one
  71. * LAP window + 1 + MIN_CREDITS. - Jean II */
  72. #define TTP_RX_DEFAULT_CREDIT 16
  73. /* Maximum number of credits we can allow the peer to have, and therefore
  74. * maximum Rx queue size.
  75. * Note that we try to deliver packets to the higher layer every time we
  76. * receive something, so in normal mode the Rx queue will never contains
  77. * more than one or two packets. - Jean II */
  78. #define TTP_RX_MAX_CREDIT 21
  79. /* What clients should use when calling ttp_open_tsap() */
  80. #define DEFAULT_INITIAL_CREDIT TTP_RX_DEFAULT_CREDIT
  81. /* Some priorities for disconnect requests */
  82. #define P_NORMAL 0
  83. #define P_HIGH 1
  84. #define TTP_SAR_DISABLE 0
  85. #define TTP_SAR_UNBOUND 0xffffffff
  86. /* Parameters */
  87. #define TTP_MAX_SDU_SIZE 0x01
  88. /*
  89. * This structure contains all data associated with one instance of a TTP
  90. * connection.
  91. */
  92. struct tsap_cb {
  93. irda_queue_t q; /* Must be first */
  94. magic_t magic; /* Just in case */
  95. __u8 stsap_sel; /* Source TSAP */
  96. __u8 dtsap_sel; /* Destination TSAP */
  97. struct lsap_cb *lsap; /* Corresponding LSAP to this TSAP */
  98. __u8 connected; /* TSAP connected */
  99. __u8 initial_credit; /* Initial credit to give peer */
  100. int avail_credit; /* Available credit to return to peer */
  101. int remote_credit; /* Credit held by peer TTP entity */
  102. int send_credit; /* Credit held by local TTP entity */
  103. struct sk_buff_head tx_queue; /* Frames to be transmitted */
  104. struct sk_buff_head rx_queue; /* Received frames */
  105. struct sk_buff_head rx_fragments;
  106. int tx_queue_lock;
  107. int rx_queue_lock;
  108. spinlock_t lock;
  109. notify_t notify; /* Callbacks to client layer */
  110. struct net_device_stats stats;
  111. struct timer_list todo_timer;
  112. __u32 max_seg_size; /* Max data that fit into an IrLAP frame */
  113. __u8 max_header_size;
  114. int rx_sdu_busy; /* RxSdu.busy */
  115. __u32 rx_sdu_size; /* Current size of a partially received frame */
  116. __u32 rx_max_sdu_size; /* Max receive user data size */
  117. int tx_sdu_busy; /* TxSdu.busy */
  118. __u32 tx_max_sdu_size; /* Max transmit user data size */
  119. int close_pend; /* Close, but disconnect_pend */
  120. unsigned long disconnect_pend; /* Disconnect, but still data to send */
  121. struct sk_buff *disconnect_skb;
  122. };
  123. struct irttp_cb {
  124. magic_t magic;
  125. hashbin_t *tsaps;
  126. };
  127. int irttp_init(void);
  128. void irttp_cleanup(void);
  129. struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify);
  130. int irttp_close_tsap(struct tsap_cb *self);
  131. int irttp_data_request(struct tsap_cb *self, struct sk_buff *skb);
  132. int irttp_udata_request(struct tsap_cb *self, struct sk_buff *skb);
  133. int irttp_connect_request(struct tsap_cb *self, __u8 dtsap_sel,
  134. __u32 saddr, __u32 daddr,
  135. struct qos_info *qos, __u32 max_sdu_size,
  136. struct sk_buff *userdata);
  137. int irttp_connect_response(struct tsap_cb *self, __u32 max_sdu_size,
  138. struct sk_buff *userdata);
  139. int irttp_disconnect_request(struct tsap_cb *self, struct sk_buff *skb,
  140. int priority);
  141. void irttp_flow_request(struct tsap_cb *self, LOCAL_FLOW flow);
  142. struct tsap_cb *irttp_dup(struct tsap_cb *self, void *instance);
  143. static inline __u32 irttp_get_saddr(struct tsap_cb *self)
  144. {
  145. return irlmp_get_saddr(self->lsap);
  146. }
  147. static inline __u32 irttp_get_daddr(struct tsap_cb *self)
  148. {
  149. return irlmp_get_daddr(self->lsap);
  150. }
  151. static inline __u32 irttp_get_max_seg_size(struct tsap_cb *self)
  152. {
  153. return self->max_seg_size;
  154. }
  155. /* After doing a irttp_dup(), this get one of the two socket back into
  156. * a state where it's waiting incoming connections.
  157. * Note : this can be used *only* if the socket is not yet connected
  158. * (i.e. NO irttp_connect_response() done on this socket).
  159. * - Jean II */
  160. static inline void irttp_listen(struct tsap_cb *self)
  161. {
  162. irlmp_listen(self->lsap);
  163. self->dtsap_sel = LSAP_ANY;
  164. }
  165. /* Return TRUE if the node is in primary mode (i.e. master)
  166. * - Jean II */
  167. static inline int irttp_is_primary(struct tsap_cb *self)
  168. {
  169. if ((self == NULL) ||
  170. (self->lsap == NULL) ||
  171. (self->lsap->lap == NULL) ||
  172. (self->lsap->lap->irlap == NULL))
  173. return -2;
  174. return irlap_is_primary(self->lsap->lap->irlap);
  175. }
  176. #endif /* IRTTP_H */