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