Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

irlmp.h

Go to the documentation of this file.
00001 /*********************************************************************
00002  *                
00003  * Filename:      irlmp.h
00004  * Version:       0.9
00005  * Description:   IrDA Link Management Protocol (LMP) layer
00006  * Status:        Experimental.
00007  * Author:        Dag Brattli <dagb@cs.uit.no>
00008  * Created at:    Sun Aug 17 20:54:32 1997
00009  * Modified at:   Fri Dec 10 13:23:01 1999
00010  * Modified by:   Dag Brattli <dagb@cs.uit.no>
00011  * 
00012  *     Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>, 
00013  *     All Rights Reserved.
00014  *     
00015  *     This program is free software; you can redistribute it and/or 
00016  *     modify it under the terms of the GNU General Public License as 
00017  *     published by the Free Software Foundation; either version 2 of 
00018  *     the License, or (at your option) any later version.
00019  *
00020  *     Neither Dag Brattli nor University of Tromsų admit liability nor
00021  *     provide warranty for any of this software. This material is 
00022  *     provided "AS-IS" and at no charge.
00023  *
00024  ********************************************************************/
00025 
00026 #ifndef IRLMP_H
00027 #define IRLMP_H
00028 
00029 #include <asm/param.h>  /* for HZ */
00030 
00031 #include <linux/config.h>
00032 #include <linux/types.h>
00033 
00034 #include <net/irda/irda.h>
00035 #include <net/irda/qos.h>
00036 #include <net/irda/irlap.h>
00037 #include <net/irda/irlmp_event.h>
00038 #include <net/irda/irqueue.h>
00039 #include <net/irda/discovery.h>
00040 
00041 /* LSAP-SEL's */
00042 #define LSAP_MASK     0x7f
00043 #define LSAP_IAS      0x00
00044 #define LSAP_ANY      0xff
00045 #define LSAP_MAX      0x6f /* 0x70-0x7f are reserved */
00046 #define LSAP_CONNLESS 0x70 /* Connectionless LSAP, mostly used for Ultra */
00047 
00048 #define DEV_ADDR_ANY  0xffffffff
00049 
00050 #define LMP_HEADER          2    /* Dest LSAP + Source LSAP */
00051 #define LMP_CONTROL_HEADER  4
00052 #define LMP_PID_HEADER      1    /* Used by Ultra */
00053 #define LMP_MAX_HEADER      (LMP_CONTROL_HEADER+LAP_MAX_HEADER)
00054 
00055 #define LM_MAX_CONNECTIONS  10
00056 
00057 #define LM_IDLE_TIMEOUT     2*HZ /* 2 seconds for now */
00058 
00059 typedef enum {
00060         S_PNP,
00061         S_PDA,
00062         S_COMPUTER,
00063         S_PRINTER,
00064         S_MODEM,
00065         S_FAX,
00066         S_LAN,
00067         S_TELEPHONY,
00068         S_COMM,
00069         S_OBEX,
00070         S_ANY,
00071         S_END,
00072 } SERVICE;
00073 
00074 typedef void (*DISCOVERY_CALLBACK1) (discovery_t *);
00075 typedef void (*DISCOVERY_CALLBACK2) (hashbin_t *);
00076 
00077 typedef struct {
00078         queue_t queue; /* Must be first */
00079 
00080         __u16 hints; /* Hint bits */
00081 } irlmp_service_t;
00082 
00083 typedef struct {
00084         queue_t queue; /* Must be first */
00085 
00086         __u16 hint_mask;
00087 
00088         DISCOVERY_CALLBACK1 callback1;
00089         DISCOVERY_CALLBACK2 callback2;
00090 } irlmp_client_t;
00091 
00092 struct lap_cb; /* Forward decl. */
00093 
00094 /*
00095  *  Information about each logical LSAP connection
00096  */
00097 struct lsap_cb {
00098         queue_t queue;      /* Must be first */
00099         magic_t magic;
00100 
00101         int  connected;
00102         int  persistent;
00103 
00104         __u8 slsap_sel;   /* Source (this) LSAP address */
00105         __u8 dlsap_sel;   /* Destination LSAP address (if connected) */
00106 #ifdef CONFIG_IRDA_ULTRA
00107         __u8 pid;         /* Used by connectionless LSAP */
00108 #endif /* CONFIG_IRDA_ULTRA */
00109         struct sk_buff *conn_skb; /* Store skb here while connecting */
00110 
00111         struct timer_list watchdog_timer;
00112 
00113         IRLMP_STATE     lsap_state;  /* Connection state */
00114         notify_t        notify;      /* Indication/Confirm entry points */
00115         struct qos_info qos;         /* QoS for this connection */
00116 
00117         struct lap_cb *lap; /* Pointer to LAP connection structure */
00118 };
00119 
00120 /*
00121  *  Information about each registred IrLAP layer
00122  */
00123 struct lap_cb {
00124         queue_t queue; /* Must be first */
00125         magic_t magic;
00126 
00127         int reason;    /* LAP disconnect reason */
00128 
00129         IRLMP_STATE lap_state;
00130 
00131         struct irlap_cb *irlap;   /* Instance of IrLAP layer */
00132         hashbin_t *lsaps;         /* LSAP associated with this link */
00133         int refcount;
00134 
00135         __u8  caddr;  /* Connection address */
00136         __u32 saddr;  /* Source device address */
00137         __u32 daddr;  /* Destination device address */
00138         
00139         struct qos_info *qos;  /* LAP QoS for this session */
00140         struct timer_list idle_timer;
00141 };
00142 
00143 /*
00144  *  Used for caching the last slsap->dlsap->handle mapping
00145  */
00146 typedef struct {
00147         int valid;
00148 
00149         __u8 slsap_sel;
00150         __u8 dlsap_sel;
00151         struct lsap_cb *lsap;
00152 } CACHE_ENTRY;
00153 
00154 /*
00155  *  Main structure for IrLMP
00156  */
00157 struct irlmp_cb {
00158         magic_t magic;
00159 
00160         __u8 conflict_flag;
00161         
00162         discovery_t discovery_cmd; /* Discovery command to use by IrLAP */
00163         discovery_t discovery_rsp; /* Discovery response to use by IrLAP */
00164 
00165         int free_lsap_sel;
00166 
00167 #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
00168         CACHE_ENTRY cache;  /* Caching last slsap->dlsap->handle mapping */
00169 #endif
00170         struct timer_list discovery_timer;
00171 
00172         hashbin_t *links;         /* IrLAP connection table */
00173         hashbin_t *unconnected_lsaps;
00174         hashbin_t *clients;
00175         hashbin_t *services;
00176 
00177         hashbin_t *cachelog;
00178         int running;
00179 
00180         spinlock_t lock;
00181 
00182         __u16_host_order hints; /* Hint bits */
00183 };
00184 
00185 /* Prototype declarations */
00186 int  irlmp_init(void);
00187 void irlmp_cleanup(void);
00188 struct lsap_cb *irlmp_open_lsap(__u8 slsap, notify_t *notify, __u8 pid);
00189 void irlmp_close_lsap( struct lsap_cb *self);
00190 
00191 __u16 irlmp_service_to_hint(int service);
00192 __u32 irlmp_register_service(__u16 hints);
00193 int irlmp_unregister_service(__u32 handle);
00194 __u32 irlmp_register_client(__u16 hint_mask, DISCOVERY_CALLBACK1 callback1,
00195                             DISCOVERY_CALLBACK2 callback2);
00196 int irlmp_unregister_client(__u32 handle);
00197 int irlmp_update_client(__u32 handle, __u16 hint_mask, 
00198                         DISCOVERY_CALLBACK1, DISCOVERY_CALLBACK2);
00199 
00200 void irlmp_register_link(struct irlap_cb *, __u32 saddr, notify_t *);
00201 void irlmp_unregister_link(__u32 saddr);
00202 
00203 int  irlmp_connect_request(struct lsap_cb *, __u8 dlsap_sel, 
00204                            __u32 saddr, __u32 daddr,
00205                            struct qos_info *, struct sk_buff *);
00206 void irlmp_connect_indication(struct lsap_cb *self, struct sk_buff *skb);
00207 int  irlmp_connect_response(struct lsap_cb *, struct sk_buff *);
00208 void irlmp_connect_confirm(struct lsap_cb *, struct sk_buff *);
00209 struct lsap_cb *irlmp_dup(struct lsap_cb *self, void *instance);
00210 
00211 void irlmp_disconnect_indication(struct lsap_cb *self, LM_REASON reason, 
00212                                  struct sk_buff *userdata);
00213 int  irlmp_disconnect_request(struct lsap_cb *, struct sk_buff *userdata);
00214 
00215 void irlmp_discovery_confirm(hashbin_t *discovery_log);
00216 void irlmp_discovery_request(int nslots);
00217 void irlmp_do_discovery(int nslots);
00218 discovery_t *irlmp_get_discovery_response(void);
00219 
00220 int  irlmp_data_request(struct lsap_cb *, struct sk_buff *);
00221 void irlmp_data_indication(struct lsap_cb *, struct sk_buff *);
00222 
00223 int  irlmp_udata_request(struct lsap_cb *, struct sk_buff *);
00224 void irlmp_udata_indication(struct lsap_cb *, struct sk_buff *);
00225 
00226 #ifdef CONFIG_IRDA_ULTRA
00227 int  irlmp_connless_data_request(struct lsap_cb *, struct sk_buff *);
00228 void irlmp_connless_data_indication(struct lsap_cb *, struct sk_buff *);
00229 #endif /* CONFIG_IRDA_ULTRA */
00230 
00231 void irlmp_status_request(void);
00232 void irlmp_status_indication(LINK_STATUS link, LOCK_STATUS lock);
00233 
00234 int  irlmp_slsap_inuse(__u8 slsap);
00235 __u8 irlmp_find_free_slsap(void);
00236 LM_REASON irlmp_convert_lap_reason(LAP_REASON);
00237 
00238 __u32 irlmp_get_saddr(struct lsap_cb *self);
00239 __u32 irlmp_get_daddr(struct lsap_cb *self);
00240 
00241 extern char *lmp_reasons[];
00242 extern int sysctl_discovery_timeout;
00243 extern int sysctl_discovery_slots;
00244 extern int sysctl_discovery;
00245 extern struct irlmp_cb *irlmp;
00246 
00247 static inline hashbin_t *irlmp_get_cachelog(void) { return irlmp->cachelog; }
00248 
00249 static inline int irlmp_get_lap_tx_queue_len(struct lsap_cb *self)
00250 {
00251         ASSERT(self != NULL, return 0;);
00252         ASSERT(self->lap != NULL, return 0;);
00253         ASSERT(self->lap->irlap != NULL, return 0;);
00254 
00255         return IRLAP_GET_TX_QUEUE_LEN(self->lap->irlap);
00256 }
00257 
00258 #endif