1/* 2 * IrNET protocol module : Synchronous PPP over an IrDA socket. 3 * 4 * Jean II - HPL `00 - <jt@hpl.hp.com> 5 * 6 * This file contains definitions and declarations global to the IrNET module, 7 * all grouped in one place... 8 * This file is a *private* header, so other modules don't want to know 9 * what's in there... 10 * 11 * Note : as most part of the Linux kernel, this module is available 12 * under the GNU General Public License (GPL). 13 */ 14 15#ifndef IRNET_H 16#define IRNET_H 17 18/************************** DOCUMENTATION ***************************/ 19 20/***************************** INCLUDES *****************************/ 21 22#include <linux/module.h> 23 24#include <linux/kernel.h> 25#include <linux/skbuff.h> 26#include <linux/tty.h> 27#include <linux/proc_fs.h> 28#include <linux/netdevice.h> 29#include <linux/miscdevice.h> 30#include <linux/poll.h> 31#include <linux/capability.h> 32#include <linux/ctype.h> /* isspace() */ 33#include <asm/uaccess.h> 34#include <linux/init.h> 35 36#include <linux/ppp_defs.h> 37#include <linux/if_ppp.h> 38#include <linux/ppp_channel.h> 39 40#include <net/irda/irda.h> 41#include <net/irda/iriap.h> 42#include <net/irda/irias_object.h> 43#include <net/irda/irlmp.h> 44#include <net/irda/irttp.h> 45#include <net/irda/discovery.h> 46 47/***************************** OPTIONS *****************************/ 48/* 49 * Define or undefine to compile or not some optional part of the 50 * IrNET driver... 51 * Note : the present defaults make sense, play with that at your 52 * own risk... 53 */ 54/* IrDA side of the business... */ 55#define DISCOVERY_NOMASK /* To enable W2k compatibility... */ 56#define ADVERTISE_HINT /* Advertise IrLAN hint bit */ 57#define ALLOW_SIMULT_CONNECT /* This seem to work, cross fingers... */ 58#define DISCOVERY_EVENTS /* Query the discovery log to post events */ 59#define INITIAL_DISCOVERY /* Dump current discovery log as events */ 60#undef STREAM_COMPAT /* Not needed - potentially messy */ 61#undef CONNECT_INDIC_KICK /* Might mess IrDA, not needed */ 62#undef FAIL_SEND_DISCONNECT /* Might mess IrDA, not needed */ 63#undef PASS_CONNECT_PACKETS /* Not needed ? Safe */ 64#undef MISSING_PPP_API /* Stuff I wish I could do */ 65 66/* PPP side of the business */ 67#define BLOCK_WHEN_CONNECT /* Block packets when connecting */ 68#define CONNECT_IN_SEND /* Retry IrDA connection procedure */ 69#undef FLUSH_TO_PPP /* Not sure about this one, let's play safe */ 70#undef SECURE_DEVIRNET /* Bah... */ 71 72/****************************** DEBUG ******************************/ 73 74/* 75 * This set of flags enable and disable all the various warning, 76 * error and debug message of this driver. 77 * Each section can be enabled and disabled independently 78 */ 79/* In the PPP part */ 80#define DEBUG_CTRL_TRACE 0 /* Control channel */ 81#define DEBUG_CTRL_INFO 0 /* various info */ 82#define DEBUG_CTRL_ERROR 1 /* problems */ 83#define DEBUG_FS_TRACE 0 /* filesystem callbacks */ 84#define DEBUG_FS_INFO 0 /* various info */ 85#define DEBUG_FS_ERROR 1 /* problems */ 86#define DEBUG_PPP_TRACE 0 /* PPP related functions */ 87#define DEBUG_PPP_INFO 0 /* various info */ 88#define DEBUG_PPP_ERROR 1 /* problems */ 89#define DEBUG_MODULE_TRACE 0 /* module insertion/removal */ 90#define DEBUG_MODULE_ERROR 1 /* problems */ 91 92/* In the IrDA part */ 93#define DEBUG_IRDA_SR_TRACE 0 /* IRDA subroutines */ 94#define DEBUG_IRDA_SR_INFO 0 /* various info */ 95#define DEBUG_IRDA_SR_ERROR 1 /* problems */ 96#define DEBUG_IRDA_SOCK_TRACE 0 /* IRDA main socket functions */ 97#define DEBUG_IRDA_SOCK_INFO 0 /* various info */ 98#define DEBUG_IRDA_SOCK_ERROR 1 /* problems */ 99#define DEBUG_IRDA_SERV_TRACE 0 /* The IrNET server */ 100#define DEBUG_IRDA_SERV_INFO 0 /* various info */ 101#define DEBUG_IRDA_SERV_ERROR 1 /* problems */ 102#define DEBUG_IRDA_TCB_TRACE 0 /* IRDA IrTTP callbacks */ 103#define DEBUG_IRDA_CB_INFO 0 /* various info */ 104#define DEBUG_IRDA_CB_ERROR 1 /* problems */ 105#define DEBUG_IRDA_OCB_TRACE 0 /* IRDA other callbacks */ 106#define DEBUG_IRDA_OCB_INFO 0 /* various info */ 107#define DEBUG_IRDA_OCB_ERROR 1 /* problems */ 108 109#define DEBUG_ASSERT 0 /* Verify all assertions */ 110 111/* 112 * These are the macros we are using to actually print the debug 113 * statements. Don't look at it, it's ugly... 114 * 115 * One of the trick is that, as the DEBUG_XXX are constant, the 116 * compiler will optimise away the if() in all cases. 117 */ 118/* All error messages (will show up in the normal logs) */ 119#define DERROR(dbg, format, args...) \ 120 {if(DEBUG_##dbg) \ 121 printk(KERN_INFO "irnet: %s(): " format, __FUNCTION__ , ##args);} 122 123/* Normal debug message (will show up in /var/log/debug) */ 124#define DEBUG(dbg, format, args...) \ 125 {if(DEBUG_##dbg) \ 126 printk(KERN_DEBUG "irnet: %s(): " format, __FUNCTION__ , ##args);} 127 128/* Entering a function (trace) */ 129#define DENTER(dbg, format, args...) \ 130 {if(DEBUG_##dbg) \ 131 printk(KERN_DEBUG "irnet: -> %s" format, __FUNCTION__ , ##args);} 132 133/* Entering and exiting a function in one go (trace) */ 134#define DPASS(dbg, format, args...) \ 135 {if(DEBUG_##dbg) \ 136 printk(KERN_DEBUG "irnet: <>%s" format, __FUNCTION__ , ##args);} 137 138/* Exiting a function (trace) */ 139#define DEXIT(dbg, format, args...) \ 140 {if(DEBUG_##dbg) \ 141 printk(KERN_DEBUG "irnet: <-%s()" format, __FUNCTION__ , ##args);} 142 143/* Exit a function with debug */ 144#define DRETURN(ret, dbg, args...) \ 145 {DEXIT(dbg, ": " args);\ 146 return ret; } 147 148/* Exit a function on failed condition */ 149#define DABORT(cond, ret, dbg, args...) \ 150 {if(cond) {\ 151 DERROR(dbg, args);\ 152 return ret; }} 153 154/* Invalid assertion, print out an error and exit... */ 155#define DASSERT(cond, ret, dbg, args...) \ 156 {if((DEBUG_ASSERT) && !(cond)) {\ 157 DERROR(dbg, "Invalid assertion: " args);\ 158 return ret; }} 159 160/************************ CONSTANTS & MACROS ************************/ 161 162/* Paranoia */ 163#define IRNET_MAGIC 0xB00754 164 165/* Number of control events in the control channel buffer... */ 166#define IRNET_MAX_EVENTS 8 /* Should be more than enough... */ 167 168/****************************** TYPES ******************************/ 169 170/* 171 * This is the main structure where we store all the data pertaining to 172 * one instance of irnet. 173 * Note : in irnet functions, a pointer this structure is usually called 174 * "ap" or "self". If the code is borrowed from the IrDA stack, it tend 175 * to be called "self", and if it is borrowed from the PPP driver it is 176 * "ap". Apart from that, it's exactly the same structure ;-) 177 */ 178typedef struct irnet_socket 179{ 180 /* ------------------- Instance management ------------------- */ 181 /* We manage a linked list of IrNET socket instances */ 182 irda_queue_t q; /* Must be first - for hasbin */ 183 int magic; /* Paranoia */ 184 185 /* --------------------- FileSystem part --------------------- */ 186 /* "pppd" interact directly with us on a /dev/ file */ 187 struct file * file; /* File descriptor of this instance */ 188 /* TTY stuff - to keep "pppd" happy */ 189 struct termios termios; /* Various tty flags */ 190 /* Stuff for the control channel */ 191 int event_index; /* Last read in the event log */ 192 193 /* ------------------------- PPP part ------------------------- */ 194 /* We interface directly to the ppp_generic driver in the kernel */ 195 int ppp_open; /* registered with ppp_generic */ 196 struct ppp_channel chan; /* Interface to generic ppp layer */ 197 198 int mru; /* Max size of PPP payload */ 199 u32 xaccm[8]; /* Asynchronous character map (just */ 200 u32 raccm; /* to please pppd - dummy) */ 201 unsigned int flags; /* PPP flags (compression, ...) */ 202 unsigned int rbits; /* Unused receive flags ??? */ 203 struct work_struct disconnect_work; /* Process context disconnection */ 204 /* ------------------------ IrTTP part ------------------------ */ 205 /* We create a pseudo "socket" over the IrDA tranport */ 206 unsigned long ttp_open; /* Set when IrTTP is ready */ 207 unsigned long ttp_connect; /* Set when IrTTP is connecting */ 208 struct tsap_cb * tsap; /* IrTTP instance (the connection) */ 209 210 char rname[NICKNAME_MAX_LEN + 1]; 211 /* IrDA nickname of destination */ 212 __u32 rdaddr; /* Requested peer IrDA address */ 213 __u32 rsaddr; /* Requested local IrDA address */ 214 __u32 daddr; /* actual peer IrDA address */ 215 __u32 saddr; /* my local IrDA address */ 216 __u8 dtsap_sel; /* Remote TSAP selector */ 217 __u8 stsap_sel; /* Local TSAP selector */ 218 219 __u32 max_sdu_size_rx;/* Socket parameters used for IrTTP */ 220 __u32 max_sdu_size_tx; 221 __u32 max_data_size; 222 __u8 max_header_size; 223 LOCAL_FLOW tx_flow; /* State of the Tx path in IrTTP */ 224 225 /* ------------------- IrLMP and IrIAS part ------------------- */ 226 /* Used for IrDA Discovery and socket name resolution */ 227 void * ckey; /* IrLMP client handle */ 228 __u16 mask; /* Hint bits mask (filter discov.)*/ 229 int nslots; /* Number of slots for discovery */ 230 231 struct iriap_cb * iriap; /* Used to query remote IAS */ 232 int errno; /* status of the IAS query */ 233 234 /* -------------------- Discovery log part -------------------- */ 235 /* Used by initial discovery on the control channel 236 * and by irnet_discover_daddr_and_lsap_sel() */ 237 struct irda_device_info *discoveries; /* Copy of the discovery log */ 238 int disco_index; /* Last read in the discovery log */ 239 int disco_number; /* Size of the discovery log */ 240 241} irnet_socket; 242 243/* 244 * This is the various event that we will generate on the control channel 245 */ 246typedef enum irnet_event 247{ 248 IRNET_DISCOVER, /* New IrNET node discovered */ 249 IRNET_EXPIRE, /* IrNET node expired */ 250 IRNET_CONNECT_TO, /* IrNET socket has connected to other node */ 251 IRNET_CONNECT_FROM, /* Other node has connected to IrNET socket */ 252 IRNET_REQUEST_FROM, /* Non satisfied connection request */ 253 IRNET_NOANSWER_FROM, /* Failed connection request */ 254 IRNET_BLOCKED_LINK, /* Link (IrLAP) is blocked for > 3s */ 255 IRNET_DISCONNECT_FROM, /* IrNET socket has disconnected */ 256 IRNET_DISCONNECT_TO /* Closing IrNET socket */ 257} irnet_event; 258 259/* 260 * This is the storage for an event and its arguments 261 */ 262typedef struct irnet_log 263{ 264 irnet_event event; 265 int unit; 266 __u32 saddr; 267 __u32 daddr; 268 char name[NICKNAME_MAX_LEN + 1]; /* 21 + 1 */ 269 __u16_host_order hints; /* Discovery hint bits */ 270} irnet_log; 271 272/* 273 * This is the storage for all events and related stuff... 274 */ 275typedef struct irnet_ctrl_channel 276{ 277 irnet_log log[IRNET_MAX_EVENTS]; /* Event log */ 278 int index; /* Current index in log */ 279 spinlock_t spinlock; /* Serialize access to the event log */ 280 wait_queue_head_t rwait; /* processes blocked on read (or poll) */ 281} irnet_ctrl_channel; 282 283/**************************** PROTOTYPES ****************************/ 284/* 285 * Global functions of the IrNET module 286 * Note : we list here also functions called from one file to the other. 287 */ 288 289/* -------------------------- IRDA PART -------------------------- */ 290extern int 291 irda_irnet_create(irnet_socket *); /* Initialise a IrNET socket */ 292extern int 293 irda_irnet_connect(irnet_socket *); /* Try to connect over IrDA */ 294extern void 295 irda_irnet_destroy(irnet_socket *); /* Teardown a IrNET socket */ 296extern int 297 irda_irnet_init(void); /* Initialise IrDA part of IrNET */ 298extern void 299 irda_irnet_cleanup(void); /* Teardown IrDA part of IrNET */ 300 301/**************************** VARIABLES ****************************/ 302 303/* Control channel stuff - allocated in irnet_irda.h */ 304extern struct irnet_ctrl_channel irnet_events; 305 306#endif /* IRNET_H */ 307