irlmp.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*********************************************************************
  2. *
  3. * Filename: irlmp.h
  4. * Version: 0.9
  5. * Description: IrDA Link Management Protocol (LMP) layer
  6. * Status: Experimental.
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Sun Aug 17 20:54:32 1997
  9. * Modified at: Fri Dec 10 13:23:01 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 IRLMP_H
  27. #define IRLMP_H
  28. #include <asm/param.h> /* for HZ */
  29. #include <linux/types.h>
  30. #include <net/irda/irda.h>
  31. #include <net/irda/qos.h>
  32. #include <net/irda/irlap.h> /* LAP_MAX_HEADER, ... */
  33. #include <net/irda/irlmp_event.h>
  34. #include <net/irda/irqueue.h>
  35. #include <net/irda/discovery.h>
  36. /* LSAP-SEL's */
  37. #define LSAP_MASK 0x7f
  38. #define LSAP_IAS 0x00
  39. #define LSAP_ANY 0xff
  40. #define LSAP_MAX 0x6f /* 0x70-0x7f are reserved */
  41. #define LSAP_CONNLESS 0x70 /* Connectionless LSAP, mostly used for Ultra */
  42. #define DEV_ADDR_ANY 0xffffffff
  43. #define LMP_HEADER 2 /* Dest LSAP + Source LSAP */
  44. #define LMP_CONTROL_HEADER 4 /* LMP_HEADER + opcode + parameter */
  45. #define LMP_PID_HEADER 1 /* Used by Ultra */
  46. #define LMP_MAX_HEADER (LMP_CONTROL_HEADER+LAP_MAX_HEADER)
  47. #define LM_MAX_CONNECTIONS 10
  48. #define LM_IDLE_TIMEOUT 2*HZ /* 2 seconds for now */
  49. typedef enum {
  50. S_PNP = 0,
  51. S_PDA,
  52. S_COMPUTER,
  53. S_PRINTER,
  54. S_MODEM,
  55. S_FAX,
  56. S_LAN,
  57. S_TELEPHONY,
  58. S_COMM,
  59. S_OBEX,
  60. S_ANY,
  61. S_END,
  62. } SERVICE;
  63. /* For selective discovery */
  64. typedef void (*DISCOVERY_CALLBACK1) (discinfo_t *, DISCOVERY_MODE, void *);
  65. /* For expiry (the same) */
  66. typedef void (*DISCOVERY_CALLBACK2) (discinfo_t *, DISCOVERY_MODE, void *);
  67. typedef struct {
  68. irda_queue_t queue; /* Must be first */
  69. __u16_host_order hints; /* Hint bits */
  70. } irlmp_service_t;
  71. typedef struct {
  72. irda_queue_t queue; /* Must be first */
  73. __u16_host_order hint_mask;
  74. DISCOVERY_CALLBACK1 disco_callback; /* Selective discovery */
  75. DISCOVERY_CALLBACK2 expir_callback; /* Selective expiration */
  76. void *priv; /* Used to identify client */
  77. } irlmp_client_t;
  78. /*
  79. * Information about each logical LSAP connection
  80. */
  81. struct lsap_cb {
  82. irda_queue_t queue; /* Must be first */
  83. magic_t magic;
  84. unsigned long connected; /* set_bit used on this */
  85. int persistent;
  86. __u8 slsap_sel; /* Source (this) LSAP address */
  87. __u8 dlsap_sel; /* Destination LSAP address (if connected) */
  88. #ifdef CONFIG_IRDA_ULTRA
  89. __u8 pid; /* Used by connectionless LSAP */
  90. #endif /* CONFIG_IRDA_ULTRA */
  91. struct sk_buff *conn_skb; /* Store skb here while connecting */
  92. struct timer_list watchdog_timer;
  93. LSAP_STATE lsap_state; /* Connection state */
  94. notify_t notify; /* Indication/Confirm entry points */
  95. struct qos_info qos; /* QoS for this connection */
  96. struct lap_cb *lap; /* Pointer to LAP connection structure */
  97. };
  98. /*
  99. * Used for caching the last slsap->dlsap->handle mapping
  100. *
  101. * We don't need to keep/match the remote address in the cache because
  102. * we are associated with a specific LAP (which implies it).
  103. * Jean II
  104. */
  105. typedef struct {
  106. int valid;
  107. __u8 slsap_sel;
  108. __u8 dlsap_sel;
  109. struct lsap_cb *lsap;
  110. } CACHE_ENTRY;
  111. /*
  112. * Information about each registered IrLAP layer
  113. */
  114. struct lap_cb {
  115. irda_queue_t queue; /* Must be first */
  116. magic_t magic;
  117. int reason; /* LAP disconnect reason */
  118. IRLMP_STATE lap_state;
  119. struct irlap_cb *irlap; /* Instance of IrLAP layer */
  120. hashbin_t *lsaps; /* LSAP associated with this link */
  121. struct lsap_cb *flow_next; /* Next lsap to be polled for Tx */
  122. __u8 caddr; /* Connection address */
  123. __u32 saddr; /* Source device address */
  124. __u32 daddr; /* Destination device address */
  125. struct qos_info *qos; /* LAP QoS for this session */
  126. struct timer_list idle_timer;
  127. #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
  128. /* The lsap cache was moved from struct irlmp_cb to here because
  129. * it must be associated with the specific LAP. Also, this
  130. * improves performance. - Jean II */
  131. CACHE_ENTRY cache; /* Caching last slsap->dlsap->handle mapping */
  132. #endif
  133. };
  134. /*
  135. * Main structure for IrLMP
  136. */
  137. struct irlmp_cb {
  138. magic_t magic;
  139. __u8 conflict_flag;
  140. discovery_t discovery_cmd; /* Discovery command to use by IrLAP */
  141. discovery_t discovery_rsp; /* Discovery response to use by IrLAP */
  142. /* Last lsap picked automatically by irlmp_find_free_slsap() */
  143. int last_lsap_sel;
  144. struct timer_list discovery_timer;
  145. hashbin_t *links; /* IrLAP connection table */
  146. hashbin_t *unconnected_lsaps;
  147. hashbin_t *clients;
  148. hashbin_t *services;
  149. hashbin_t *cachelog; /* Current discovery log */
  150. int running;
  151. __u16_host_order hints; /* Hint bits */
  152. };
  153. /* Prototype declarations */
  154. int irlmp_init(void);
  155. void irlmp_cleanup(void);
  156. struct lsap_cb *irlmp_open_lsap(__u8 slsap, notify_t *notify, __u8 pid);
  157. void irlmp_close_lsap( struct lsap_cb *self);
  158. __u16 irlmp_service_to_hint(int service);
  159. void *irlmp_register_service(__u16 hints);
  160. int irlmp_unregister_service(void *handle);
  161. void *irlmp_register_client(__u16 hint_mask, DISCOVERY_CALLBACK1 disco_clb,
  162. DISCOVERY_CALLBACK2 expir_clb, void *priv);
  163. int irlmp_unregister_client(void *handle);
  164. int irlmp_update_client(void *handle, __u16 hint_mask,
  165. DISCOVERY_CALLBACK1 disco_clb,
  166. DISCOVERY_CALLBACK2 expir_clb, void *priv);
  167. void irlmp_register_link(struct irlap_cb *, __u32 saddr, notify_t *);
  168. void irlmp_unregister_link(__u32 saddr);
  169. int irlmp_connect_request(struct lsap_cb *, __u8 dlsap_sel,
  170. __u32 saddr, __u32 daddr,
  171. struct qos_info *, struct sk_buff *);
  172. void irlmp_connect_indication(struct lsap_cb *self, struct sk_buff *skb);
  173. int irlmp_connect_response(struct lsap_cb *, struct sk_buff *);
  174. void irlmp_connect_confirm(struct lsap_cb *, struct sk_buff *);
  175. struct lsap_cb *irlmp_dup(struct lsap_cb *self, void *instance);
  176. void irlmp_disconnect_indication(struct lsap_cb *self, LM_REASON reason,
  177. struct sk_buff *userdata);
  178. int irlmp_disconnect_request(struct lsap_cb *, struct sk_buff *userdata);
  179. void irlmp_discovery_confirm(hashbin_t *discovery_log, DISCOVERY_MODE mode);
  180. void irlmp_discovery_request(int nslots);
  181. discinfo_t *irlmp_get_discoveries(int *pn, __u16 mask, int nslots);
  182. void irlmp_do_expiry(void);
  183. void irlmp_do_discovery(int nslots);
  184. discovery_t *irlmp_get_discovery_response(void);
  185. void irlmp_discovery_expiry(discinfo_t *expiry, int number);
  186. int irlmp_data_request(struct lsap_cb *, struct sk_buff *);
  187. void irlmp_data_indication(struct lsap_cb *, struct sk_buff *);
  188. int irlmp_udata_request(struct lsap_cb *, struct sk_buff *);
  189. void irlmp_udata_indication(struct lsap_cb *, struct sk_buff *);
  190. #ifdef CONFIG_IRDA_ULTRA
  191. int irlmp_connless_data_request(struct lsap_cb *, struct sk_buff *, __u8);
  192. void irlmp_connless_data_indication(struct lsap_cb *, struct sk_buff *);
  193. #endif /* CONFIG_IRDA_ULTRA */
  194. void irlmp_status_indication(struct lap_cb *, LINK_STATUS link, LOCK_STATUS lock);
  195. void irlmp_flow_indication(struct lap_cb *self, LOCAL_FLOW flow);
  196. LM_REASON irlmp_convert_lap_reason(LAP_REASON);
  197. static inline __u32 irlmp_get_saddr(const struct lsap_cb *self)
  198. {
  199. return (self && self->lap) ? self->lap->saddr : 0;
  200. }
  201. static inline __u32 irlmp_get_daddr(const struct lsap_cb *self)
  202. {
  203. return (self && self->lap) ? self->lap->daddr : 0;
  204. }
  205. const char *irlmp_reason_str(LM_REASON reason);
  206. extern int sysctl_discovery_timeout;
  207. extern int sysctl_discovery_slots;
  208. extern int sysctl_discovery;
  209. extern int sysctl_lap_keepalive_time; /* in ms, default is LM_IDLE_TIMEOUT */
  210. extern struct irlmp_cb *irlmp;
  211. /* Check if LAP queue is full.
  212. * Used by IrTTP for low control, see comments in irlap.h - Jean II */
  213. static inline int irlmp_lap_tx_queue_full(struct lsap_cb *self)
  214. {
  215. if (self == NULL)
  216. return 0;
  217. if (self->lap == NULL)
  218. return 0;
  219. if (self->lap->irlap == NULL)
  220. return 0;
  221. return IRLAP_GET_TX_QUEUE_LEN(self->lap->irlap) >= LAP_HIGH_THRESHOLD;
  222. }
  223. /* After doing a irlmp_dup(), this get one of the two socket back into
  224. * a state where it's waiting incoming connections.
  225. * Note : this can be used *only* if the socket is not yet connected
  226. * (i.e. NO irlmp_connect_response() done on this socket).
  227. * - Jean II */
  228. static inline void irlmp_listen(struct lsap_cb *self)
  229. {
  230. self->dlsap_sel = LSAP_ANY;
  231. self->lap = NULL;
  232. self->lsap_state = LSAP_DISCONNECTED;
  233. /* Started when we received the LM_CONNECT_INDICATION */
  234. del_timer(&self->watchdog_timer);
  235. }
  236. #endif