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