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