irlap.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*********************************************************************
  2. *
  3. * Filename: irlap.h
  4. * Version: 0.8
  5. * Description: An IrDA LAP driver for Linux
  6. * Status: Experimental.
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Mon Aug 4 20:40:53 1997
  9. * Modified at: Fri Dec 10 13:21:17 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 IRLAP_H
  27. #define IRLAP_H
  28. #include <linux/types.h>
  29. #include <linux/skbuff.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/timer.h>
  32. #include <net/irda/irqueue.h> /* irda_queue_t */
  33. #include <net/irda/qos.h> /* struct qos_info */
  34. #include <net/irda/discovery.h> /* discovery_t */
  35. #include <net/irda/irlap_event.h> /* IRLAP_STATE, ... */
  36. #include <net/irda/irmod.h> /* struct notify_t */
  37. #define CONFIG_IRDA_DYNAMIC_WINDOW 1
  38. #define LAP_RELIABLE 1
  39. #define LAP_UNRELIABLE 0
  40. #define LAP_ADDR_HEADER 1 /* IrLAP Address Header */
  41. #define LAP_CTRL_HEADER 1 /* IrLAP Control Header */
  42. /* May be different when we get VFIR */
  43. #define LAP_MAX_HEADER (LAP_ADDR_HEADER + LAP_CTRL_HEADER)
  44. /* Each IrDA device gets a random 32 bits IRLAP device address */
  45. #define LAP_ALEN 4
  46. #define BROADCAST 0xffffffff /* Broadcast device address */
  47. #define CBROADCAST 0xfe /* Connection broadcast address */
  48. #define XID_FORMAT 0x01 /* Discovery XID format */
  49. /* Nobody seems to use this constant. */
  50. #define LAP_WINDOW_SIZE 8
  51. /* We keep the LAP queue very small to minimise the amount of buffering.
  52. * this improve latency and reduce resource consumption.
  53. * This work only because we have synchronous refilling of IrLAP through
  54. * the flow control mechanism (via scheduler and IrTTP).
  55. * 2 buffers is the minimum we can work with, one that we send while polling
  56. * IrTTP, and another to know that we should not send the pf bit.
  57. * Jean II */
  58. #define LAP_HIGH_THRESHOLD 2
  59. /* Some rare non TTP clients don't implement flow control, and
  60. * so don't comply with the above limit (and neither with this one).
  61. * For IAP and management, it doesn't matter, because they never transmit much.
  62. *.For IrLPT, this should be fixed.
  63. * - Jean II */
  64. #define LAP_MAX_QUEUE 10
  65. /* Please note that all IrDA management frames (LMP/TTP conn req/disc and
  66. * IAS queries) fall in the second category and are sent to LAP even if TTP
  67. * is stopped. This means that those frames will wait only a maximum of
  68. * two (2) data frames before beeing sent on the "wire", which speed up
  69. * new socket setup when the link is saturated.
  70. * Same story for two sockets competing for the medium : if one saturates
  71. * the LAP, when the other want to transmit it only has to wait for
  72. * maximum three (3) packets (2 + one scheduling), which improve performance
  73. * of delay sensitive applications.
  74. * Jean II */
  75. #define NR_EXPECTED 1
  76. #define NR_UNEXPECTED 0
  77. #define NR_INVALID -1
  78. #define NS_EXPECTED 1
  79. #define NS_UNEXPECTED 0
  80. #define NS_INVALID -1
  81. /*
  82. * Meta information passed within the IrLAP state machine
  83. */
  84. struct irlap_info {
  85. __u8 caddr; /* Connection address */
  86. __u8 control; /* Frame type */
  87. __u8 cmd;
  88. __u32 saddr;
  89. __u32 daddr;
  90. int pf; /* Poll/final bit set */
  91. __u8 nr; /* Sequence number of next frame expected */
  92. __u8 ns; /* Sequence number of frame sent */
  93. int S; /* Number of slots */
  94. int slot; /* Random chosen slot */
  95. int s; /* Current slot */
  96. discovery_t *discovery; /* Discovery information */
  97. };
  98. /* Main structure of IrLAP */
  99. struct irlap_cb {
  100. irda_queue_t q; /* Must be first */
  101. magic_t magic;
  102. /* Device we are attached to */
  103. struct net_device *netdev;
  104. char hw_name[2*IFNAMSIZ + 1];
  105. /* Connection state */
  106. volatile IRLAP_STATE state; /* Current state */
  107. /* Timers used by IrLAP */
  108. struct timer_list query_timer;
  109. struct timer_list slot_timer;
  110. struct timer_list discovery_timer;
  111. struct timer_list final_timer;
  112. struct timer_list poll_timer;
  113. struct timer_list wd_timer;
  114. struct timer_list backoff_timer;
  115. /* Media busy stuff */
  116. struct timer_list media_busy_timer;
  117. int media_busy;
  118. /* Timeouts which will be different with different turn time */
  119. int slot_timeout;
  120. int poll_timeout;
  121. int final_timeout;
  122. int wd_timeout;
  123. struct sk_buff_head txq; /* Frames to be transmitted */
  124. struct sk_buff_head txq_ultra;
  125. __u8 caddr; /* Connection address */
  126. __u32 saddr; /* Source device address */
  127. __u32 daddr; /* Destination device address */
  128. int retry_count; /* Times tried to establish connection */
  129. int add_wait; /* True if we are waiting for frame */
  130. __u8 connect_pending;
  131. __u8 disconnect_pending;
  132. /* To send a faster RR if tx queue empty */
  133. #ifdef CONFIG_IRDA_FAST_RR
  134. int fast_RR_timeout;
  135. int fast_RR;
  136. #endif /* CONFIG_IRDA_FAST_RR */
  137. int N1; /* N1 * F-timer = Negitiated link disconnect warning threshold */
  138. int N2; /* N2 * F-timer = Negitiated link disconnect time */
  139. int N3; /* Connection retry count */
  140. int local_busy;
  141. int remote_busy;
  142. int xmitflag;
  143. __u8 vs; /* Next frame to be sent */
  144. __u8 vr; /* Next frame to be received */
  145. __u8 va; /* Last frame acked */
  146. int window; /* Nr of I-frames allowed to send */
  147. int window_size; /* Current negotiated window size */
  148. #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
  149. __u32 line_capacity; /* Number of bytes allowed to send */
  150. __u32 bytes_left; /* Number of bytes still allowed to transmit */
  151. #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
  152. struct sk_buff_head wx_list;
  153. __u8 ack_required;
  154. /* XID parameters */
  155. __u8 S; /* Number of slots */
  156. __u8 slot; /* Random chosen slot */
  157. __u8 s; /* Current slot */
  158. int frame_sent; /* Have we sent reply? */
  159. hashbin_t *discovery_log;
  160. discovery_t *discovery_cmd;
  161. __u32 speed; /* Link speed */
  162. struct qos_info qos_tx; /* QoS requested by peer */
  163. struct qos_info qos_rx; /* QoS requested by self */
  164. struct qos_info *qos_dev; /* QoS supported by device */
  165. notify_t notify; /* Callbacks to IrLMP */
  166. int mtt_required; /* Minimum turnaround time required */
  167. int xbofs_delay; /* Nr of XBOF's used to MTT */
  168. int bofs_count; /* Negotiated extra BOFs */
  169. int next_bofs; /* Negotiated extra BOFs after next frame */
  170. int mode; /* IrLAP mode (primary, secondary or monitor) */
  171. };
  172. /*
  173. * Function prototypes
  174. */
  175. int irlap_init(void);
  176. void irlap_cleanup(void);
  177. struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
  178. const char *hw_name);
  179. void irlap_close(struct irlap_cb *self);
  180. void irlap_connect_request(struct irlap_cb *self, __u32 daddr,
  181. struct qos_info *qos, int sniff);
  182. void irlap_connect_response(struct irlap_cb *self, struct sk_buff *skb);
  183. void irlap_connect_indication(struct irlap_cb *self, struct sk_buff *skb);
  184. void irlap_connect_confirm(struct irlap_cb *, struct sk_buff *skb);
  185. void irlap_data_indication(struct irlap_cb *, struct sk_buff *, int unreliable);
  186. void irlap_data_request(struct irlap_cb *, struct sk_buff *, int unreliable);
  187. #ifdef CONFIG_IRDA_ULTRA
  188. void irlap_unitdata_request(struct irlap_cb *, struct sk_buff *);
  189. void irlap_unitdata_indication(struct irlap_cb *, struct sk_buff *);
  190. #endif /* CONFIG_IRDA_ULTRA */
  191. void irlap_disconnect_request(struct irlap_cb *);
  192. void irlap_disconnect_indication(struct irlap_cb *, LAP_REASON reason);
  193. void irlap_status_indication(struct irlap_cb *, int quality_of_link);
  194. void irlap_test_request(__u8 *info, int len);
  195. void irlap_discovery_request(struct irlap_cb *, discovery_t *discovery);
  196. void irlap_discovery_confirm(struct irlap_cb *, hashbin_t *discovery_log);
  197. void irlap_discovery_indication(struct irlap_cb *, discovery_t *discovery);
  198. void irlap_reset_indication(struct irlap_cb *self);
  199. void irlap_reset_confirm(void);
  200. void irlap_update_nr_received(struct irlap_cb *, int nr);
  201. int irlap_validate_nr_received(struct irlap_cb *, int nr);
  202. int irlap_validate_ns_received(struct irlap_cb *, int ns);
  203. int irlap_generate_rand_time_slot(int S, int s);
  204. void irlap_initiate_connection_state(struct irlap_cb *);
  205. void irlap_flush_all_queues(struct irlap_cb *);
  206. void irlap_wait_min_turn_around(struct irlap_cb *, struct qos_info *);
  207. void irlap_apply_default_connection_parameters(struct irlap_cb *self);
  208. void irlap_apply_connection_parameters(struct irlap_cb *self, int now);
  209. #define IRLAP_GET_HEADER_SIZE(self) (LAP_MAX_HEADER)
  210. #define IRLAP_GET_TX_QUEUE_LEN(self) skb_queue_len(&self->txq)
  211. /* Return TRUE if the node is in primary mode (i.e. master)
  212. * - Jean II */
  213. static inline int irlap_is_primary(struct irlap_cb *self)
  214. {
  215. int ret;
  216. switch(self->state) {
  217. case LAP_XMIT_P:
  218. case LAP_NRM_P:
  219. ret = 1;
  220. break;
  221. case LAP_XMIT_S:
  222. case LAP_NRM_S:
  223. ret = 0;
  224. break;
  225. default:
  226. ret = -1;
  227. }
  228. return ret;
  229. }
  230. /* Clear a pending IrLAP disconnect. - Jean II */
  231. static inline void irlap_clear_disconnect(struct irlap_cb *self)
  232. {
  233. self->disconnect_pending = FALSE;
  234. }
  235. /*
  236. * Function irlap_next_state (self, state)
  237. *
  238. * Switches state and provides debug information
  239. *
  240. */
  241. static inline void irlap_next_state(struct irlap_cb *self, IRLAP_STATE state)
  242. {
  243. /*
  244. if (!self || self->magic != LAP_MAGIC)
  245. return;
  246. pr_debug("next LAP state = %s\n", irlap_state[state]);
  247. */
  248. self->state = state;
  249. }
  250. #endif