11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IrNET protocol module : Synchronous PPP over an IrDA socket. 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Jean II - HPL `00 - <jt@hpl.hp.com> 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This file contains definitions and declarations global to the IrNET module, 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * all grouped in one place... 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This file is a *private* header, so other modules don't want to know 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * what's in there... 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note : as most part of the Linux kernel, this module is available 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * under the GNU General Public License (GPL). 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef IRNET_H 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define IRNET_H 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/************************** DOCUMENTATION ***************************/ 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * What is IrNET 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ------------- 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IrNET is a protocol allowing to carry TCP/IP traffic between two 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IrDA peers in an efficient fashion. It is a thin layer, passing PPP 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * packets to IrTTP and vice versa. It uses PPP in synchronous mode, 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * because IrTTP offer a reliable sequenced packet service (as opposed 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to a byte stream). In fact, you could see IrNET as carrying TCP/IP 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * in a IrDA socket, using PPP to provide the glue. 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The main difference with traditional PPP over IrCOMM is that we 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * avoid the framing and serial emulation which are a performance 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * bottleneck. It also allows multipoint communications in a sensible 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fashion. 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The main difference with IrLAN is that we use PPP for the link 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * management, which is more standard, interoperable and flexible than 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the IrLAN protocol. For example, PPP adds authentication, 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * encryption, compression, header compression and automated routing 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * setup. And, as IrNET let PPP do the hard work, the implementation 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * is much simpler than IrLAN. 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The Linux implementation 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ------------------------ 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IrNET is written on top of the Linux-IrDA stack, and interface with 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the generic Linux PPP driver. Because IrNET depend on recent 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * changes of the PPP driver interface, IrNET will work only with very 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * recent kernel (2.3.99-pre6 and up). 476819bc2e1e46c71711a8dddf4040e706b02973c0YOSHIFUJI Hideaki * 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The present implementation offer the following features : 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o simple user interface using pppd 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o efficient implementation (interface directly to PPP and IrTTP) 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o addressing (you can specify the name of the IrNET recipient) 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o multipoint operation (limited by IrLAP specification) 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o information in /proc/net/irda/irnet 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o IrNET events on /dev/irnet (for user space daemon) 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o IrNET daemon (irnetd) to automatically handle incoming requests 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Windows 2000 compatibility (tested, but need more work) 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Currently missing : 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Lot's of testing (that's your job) 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Connection retries (may be too hard to do) 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Check pppd persist mode 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o User space daemon (to automatically handle incoming requests) 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The setup is not currently the most easy, but this should get much 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * better when everything will get integrated... 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Acknowledgements 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ---------------- 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This module is based on : 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o The PPP driver (ppp_synctty/ppp_generic) by Paul Mackerras 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o The IrLAN protocol (irlan_common/XXX) by Dag Brattli 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o The IrSock interface (af_irda) by Dag Brattli 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Some other bits from the kernel and my drivers... 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Infinite thanks to those brave souls for providing the infrastructure 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * upon which IrNET is built. 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 7625985edcedea6396277003854657b5f3cb31a628Lucas De Marchi * Thanks to all my colleagues in HP for helping me. In particular, 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * thanks to Salil Pradhan and Bill Serra for W2k testing... 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Thanks to Luiz Magalhaes for irnetd and much testing... 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Thanks to Alan Cox for answering lot's of my stupid questions, and 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to Paul Mackerras answering my questions on how to best integrate 821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IrNET and pppd. 831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Jean II 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note on some implementations choices... 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ------------------------------------ 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1) Direct interface vs tty/socket 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * I could have used a tty interface to hook to ppp and use the full 901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * socket API to connect to IrDA. The code would have been easier to 911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * maintain, and maybe the code would have been smaller... 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Instead, we hook directly to ppp_generic and to IrTTP, which make 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * things more complicated... 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The first reason is flexibility : this allow us to create IrNET 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * instances on demand (no /dev/ircommX crap) and to allow linkname 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * specification on pppd command line... 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Second reason is speed optimisation. If you look closely at the 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * transmit and receive paths, you will notice that they are "super lean" 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (that's why they look ugly), with no function calls and as little data 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * copy and modification as I could... 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2) irnetd in user space 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * irnetd is implemented in user space, which is necessary to call pppd. 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This also give maximum benefits in term of flexibility and customability, 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and allow to offer the event channel, useful for other stuff like debug. 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * On the other hand, this require a loose coordination between the 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * present module and irnetd. One critical area is how incoming request 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * are handled. 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * When irnet receive an incoming request, it send an event to irnetd and 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * drop the incoming IrNET socket. 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * irnetd start a pppd instance, which create a new IrNET socket. This new 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * socket is then connected in the originating node to the pppd instance. 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * At this point, in the originating node, the first socket is closed. 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * I admit, this is a bit messy and waste some resources. The alternative 1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * is caching incoming socket, and that's also quite messy and waste 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * resources. 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * We also make connection time slower. For example, on a 115 kb/s link it 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * adds 60ms to the connection time (770 ms). However, this is slower than 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the time it takes to fire up pppd on my P133... 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * History : 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ------- 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v1 - 15.5.00 - Jean II 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Basic IrNET (hook to ppp_generic & IrTTP - incl. multipoint) 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o control channel on /dev/irnet (set name/address) 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o event channel on /dev/irnet (for user space daemon) 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v2 - 5.6.00 - Jean II 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Enable DROP_NOT_READY to avoid PPP timeouts & other weirdness... 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Add DISCONNECT_TO event and rename DISCONNECT_FROM. 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Set official device number alloaction on /dev/irnet 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v3 - 30.8.00 - Jean II 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Update to latest Linux-IrDA changes : 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * - queue_t => irda_queue_t 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Update to ppp-2.4.0 : 1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * - move irda_irnet_connect from PPPIOCATTACH to TIOCSETD 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Add EXPIRE event (depend on new IrDA-Linux patch) 1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Switch from `hashbin_remove' to `hashbin_remove_this' to fix 1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * a multilink bug... (depend on new IrDA-Linux patch) 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o fix a self->daddr to self->raddr in irda_irnet_connect to fix 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * another multilink bug (darn !) 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Remove LINKNAME_IOCTL cruft 1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v3b - 31.8.00 - Jean II 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Dump discovery log at event channel startup 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v4 - 28.9.00 - Jean II 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Fix interaction between poll/select and dump discovery log 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Add IRNET_BLOCKED_LINK event (depend on new IrDA-Linux patch) 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Add IRNET_NOANSWER_FROM event (mostly to help support) 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Release flow control in disconnect_indication 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Block packets while connecting (speed up connections) 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v5 - 11.01.01 - Jean II 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Init self->max_header_size, just in case... 1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Set up ap->chan.hdrlen, to get zero copy on tx side working. 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o avoid tx->ttp->flow->ppp->tx->... loop, by checking flow state 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Thanks to Christian Gennerat for finding this bug ! 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * --- 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Declare the proper MTU/MRU that we can support 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (but PPP doesn't read the MTU value :-() 1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Declare hashbin HB_NOLOCK instead of HB_LOCAL to avoid 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * disabling and enabling irq twice 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v6 - 31.05.01 - Jean II 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Print source address in Found, Discovery, Expiry & Request events 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Print requested source address in /proc/net/irnet 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Change control channel input. Allow multiple commands in one line. 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Add saddr command to change ap->rsaddr (and use that in IrDA) 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * --- 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Make the IrDA connection procedure totally asynchronous. 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Heavy rewrite of the IAS query code and the whole connection 1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * procedure. Now, irnet_connect() no longer need to be called from 1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * a process context... 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Enable IrDA connect retries in ppp_irnet_send(). The good thing 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * is that IrDA connect retries are directly driven by PPP LCP 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * retries (we retry for each LCP packet), so that everything 1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * is transparently controlled from pppd lcp-max-configure. 1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Add ttp_connect flag to prevent rentry on the connect procedure 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Test and fixups to eliminate side effects of retries 1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v7 - 22.08.01 - Jean II 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Cleanup : Change "saddr = 0x0" to "saddr = DEV_ADDR_ANY" 1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Fix bug in BLOCK_WHEN_CONNECT introduced in v6 : due to the 1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * asynchronous IAS query, self->tsap is NULL when PPP send the 1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * first packet. This was preventing "connect-delay 0" to work. 1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Change the test in ppp_irnet_send() to self->ttp_connect. 1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v8 - 1.11.01 - Jean II 1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Tighten the use of self->ttp_connect and self->ttp_open to 1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * prevent various race conditions. 1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Avoid leaking discovery log and skb 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Replace "self" with "server" in irnet_connect_indication() to 2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * better detect cut'n'paste error ;-) 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v9 - 29.11.01 - Jean II 2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Fix event generation in disconnect indication that I broke in v8 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * It was always generation "No-Answer" because I was testing ttp_open 2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * just after clearing it. *blush*. 2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Use newly created irttp_listen() to fix potential crash when LAP 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * destroyed before irnet module removed. 2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v10 - 4.3.2 - Jean II 2111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o When receiving a disconnect indication, don't reenable the 2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PPP Tx queue, this will trigger a reconnect. Instead, close 2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the channel, which will kill pppd... 2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v11 - 20.3.02 - Jean II 2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Oops ! v10 fix disabled IrNET retries and passive behaviour. 2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Better fix in irnet_disconnect_indication() : 2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * - if connected, kill pppd via hangup. 2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * - if not connected, reenable ppp Tx, which trigger IrNET retry. 2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v12 - 10.4.02 - Jean II 2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Fix race condition in irnet_connect_indication(). 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If the socket was already trying to connect, drop old connection 2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and use new one only if acting as primary. See comments. 2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v13 - 30.5.02 - Jean II 2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Update module init code 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v14 - 20.2.03 - Jean II 2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Add discovery hint bits in the control channel. 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Remove obsolete MOD_INC/DEC_USE_COUNT in favor of .owner 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * v15 - 7.4.03 - Jean II 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Replace spin_lock_irqsave() with spin_lock_bh() so that we can 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * use ppp_unit_number(). It's probably also better overall... 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Disable call to ppp_unregister_channel(), because we can't do it. 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/***************************** INCLUDES *****************************/ 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/kernel.h> 2441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/skbuff.h> 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/tty.h> 2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/proc_fs.h> 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/netdevice.h> 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/miscdevice.h> 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/poll.h> 2504fc268d24ceb9f4150777c1b5b2b8e6214e56b2bRandy Dunlap#include <linux/capability.h> 2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/ctype.h> /* isspace() */ 252e7d2860b690d4f3bed6824757c540579638e3d1eAndré Goddard Rosa#include <linux/string.h> /* skip_spaces() */ 2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/uaccess.h> 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/ppp_defs.h> 2574b32da2bcf1de2b7a196a0e48389d231b4472c36Paul Mackerras#include <linux/ppp-ioctl.h> 2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/ppp_channel.h> 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <net/irda/irda.h> 2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <net/irda/iriap.h> 2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <net/irda/irias_object.h> 2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <net/irda/irlmp.h> 2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <net/irda/irttp.h> 2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <net/irda/discovery.h> 2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/***************************** OPTIONS *****************************/ 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Define or undefine to compile or not some optional part of the 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IrNET driver... 2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note : the present defaults make sense, play with that at your 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * own risk... 2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* IrDA side of the business... */ 2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISCOVERY_NOMASK /* To enable W2k compatibility... */ 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADVERTISE_HINT /* Advertise IrLAN hint bit */ 2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ALLOW_SIMULT_CONNECT /* This seem to work, cross fingers... */ 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DISCOVERY_EVENTS /* Query the discovery log to post events */ 2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define INITIAL_DISCOVERY /* Dump current discovery log as events */ 2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef STREAM_COMPAT /* Not needed - potentially messy */ 2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef CONNECT_INDIC_KICK /* Might mess IrDA, not needed */ 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef FAIL_SEND_DISCONNECT /* Might mess IrDA, not needed */ 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef PASS_CONNECT_PACKETS /* Not needed ? Safe */ 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef MISSING_PPP_API /* Stuff I wish I could do */ 2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* PPP side of the business */ 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define BLOCK_WHEN_CONNECT /* Block packets when connecting */ 2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CONNECT_IN_SEND /* Retry IrDA connection procedure */ 2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef FLUSH_TO_PPP /* Not sure about this one, let's play safe */ 2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef SECURE_DEVIRNET /* Bah... */ 2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/****************************** DEBUG ******************************/ 2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This set of flags enable and disable all the various warning, 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * error and debug message of this driver. 2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Each section can be enabled and disabled independently 2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* In the PPP part */ 3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_CTRL_TRACE 0 /* Control channel */ 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_CTRL_INFO 0 /* various info */ 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_CTRL_ERROR 1 /* problems */ 3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_FS_TRACE 0 /* filesystem callbacks */ 3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_FS_INFO 0 /* various info */ 3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_FS_ERROR 1 /* problems */ 3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_PPP_TRACE 0 /* PPP related functions */ 3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_PPP_INFO 0 /* various info */ 3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_PPP_ERROR 1 /* problems */ 3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_MODULE_TRACE 0 /* module insertion/removal */ 3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_MODULE_ERROR 1 /* problems */ 3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* In the IrDA part */ 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_SR_TRACE 0 /* IRDA subroutines */ 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_SR_INFO 0 /* various info */ 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_SR_ERROR 1 /* problems */ 3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_SOCK_TRACE 0 /* IRDA main socket functions */ 3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_SOCK_INFO 0 /* various info */ 3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_SOCK_ERROR 1 /* problems */ 3191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_SERV_TRACE 0 /* The IrNET server */ 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_SERV_INFO 0 /* various info */ 3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_SERV_ERROR 1 /* problems */ 3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_TCB_TRACE 0 /* IRDA IrTTP callbacks */ 3231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_CB_INFO 0 /* various info */ 3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_CB_ERROR 1 /* problems */ 3251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_OCB_TRACE 0 /* IRDA other callbacks */ 3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_OCB_INFO 0 /* various info */ 3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_IRDA_OCB_ERROR 1 /* problems */ 3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG_ASSERT 0 /* Verify all assertions */ 3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3316819bc2e1e46c71711a8dddf4040e706b02973c0YOSHIFUJI Hideaki/* 3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * These are the macros we are using to actually print the debug 3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * statements. Don't look at it, it's ugly... 3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * One of the trick is that, as the DEBUG_XXX are constant, the 3361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * compiler will optimise away the if() in all cases. 3371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* All error messages (will show up in the normal logs) */ 3391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DERROR(dbg, format, args...) \ 3401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds {if(DEBUG_##dbg) \ 3410dc47877a3de00ceadea0005189656ae8dc52669Harvey Harrison printk(KERN_INFO "irnet: %s(): " format, __func__ , ##args);} 3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Normal debug message (will show up in /var/log/debug) */ 3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG(dbg, format, args...) \ 3451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds {if(DEBUG_##dbg) \ 3460dc47877a3de00ceadea0005189656ae8dc52669Harvey Harrison printk(KERN_DEBUG "irnet: %s(): " format, __func__ , ##args);} 3471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Entering a function (trace) */ 3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DENTER(dbg, format, args...) \ 3501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds {if(DEBUG_##dbg) \ 3510dc47877a3de00ceadea0005189656ae8dc52669Harvey Harrison printk(KERN_DEBUG "irnet: -> %s" format, __func__ , ##args);} 3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Entering and exiting a function in one go (trace) */ 3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DPASS(dbg, format, args...) \ 3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds {if(DEBUG_##dbg) \ 3560dc47877a3de00ceadea0005189656ae8dc52669Harvey Harrison printk(KERN_DEBUG "irnet: <>%s" format, __func__ , ##args);} 3571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Exiting a function (trace) */ 3591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEXIT(dbg, format, args...) \ 3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds {if(DEBUG_##dbg) \ 3610dc47877a3de00ceadea0005189656ae8dc52669Harvey Harrison printk(KERN_DEBUG "irnet: <-%s()" format, __func__ , ##args);} 3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Exit a function with debug */ 3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DRETURN(ret, dbg, args...) \ 3651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds {DEXIT(dbg, ": " args);\ 3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ret; } 3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Exit a function on failed condition */ 3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DABORT(cond, ret, dbg, args...) \ 3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds {if(cond) {\ 3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DERROR(dbg, args);\ 3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ret; }} 3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Invalid assertion, print out an error and exit... */ 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DASSERT(cond, ret, dbg, args...) \ 3761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds {if((DEBUG_ASSERT) && !(cond)) {\ 3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DERROR(dbg, "Invalid assertion: " args);\ 3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ret; }} 3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/************************ CONSTANTS & MACROS ************************/ 3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Paranoia */ 3831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define IRNET_MAGIC 0xB00754 3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Number of control events in the control channel buffer... */ 3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define IRNET_MAX_EVENTS 8 /* Should be more than enough... */ 3871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/****************************** TYPES ******************************/ 3891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This is the main structure where we store all the data pertaining to 3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * one instance of irnet. 3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note : in irnet functions, a pointer this structure is usually called 3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * "ap" or "self". If the code is borrowed from the IrDA stack, it tend 3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to be called "self", and if it is borrowed from the PPP driver it is 3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * "ap". Apart from that, it's exactly the same structure ;-) 3971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef struct irnet_socket 3991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* ------------------- Instance management ------------------- */ 4011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We manage a linked list of IrNET socket instances */ 4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds irda_queue_t q; /* Must be first - for hasbin */ 4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int magic; /* Paranoia */ 4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* --------------------- FileSystem part --------------------- */ 4061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* "pppd" interact directly with us on a /dev/ file */ 4071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct file * file; /* File descriptor of this instance */ 4081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* TTY stuff - to keep "pppd" happy */ 4098c7230f781749cd7261b504c0bfa188bb96e77eeDavid S. Miller struct ktermios termios; /* Various tty flags */ 4101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Stuff for the control channel */ 4111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int event_index; /* Last read in the event log */ 4121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* ------------------------- PPP part ------------------------- */ 4141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We interface directly to the ppp_generic driver in the kernel */ 4151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int ppp_open; /* registered with ppp_generic */ 4161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct ppp_channel chan; /* Interface to generic ppp layer */ 4171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int mru; /* Max size of PPP payload */ 4191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 xaccm[8]; /* Asynchronous character map (just */ 4201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 raccm; /* to please pppd - dummy) */ 4211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int flags; /* PPP flags (compression, ...) */ 4221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int rbits; /* Unused receive flags ??? */ 423c577c2b99387b5ff8607d42d6eaff9ec024d4773Samuel Ortiz struct work_struct disconnect_work; /* Process context disconnection */ 4241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* ------------------------ IrTTP part ------------------------ */ 4251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We create a pseudo "socket" over the IrDA tranport */ 4261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long ttp_open; /* Set when IrTTP is ready */ 4271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long ttp_connect; /* Set when IrTTP is connecting */ 4281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct tsap_cb * tsap; /* IrTTP instance (the connection) */ 4291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char rname[NICKNAME_MAX_LEN + 1]; 4311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* IrDA nickname of destination */ 4321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 rdaddr; /* Requested peer IrDA address */ 4331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 rsaddr; /* Requested local IrDA address */ 4341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 daddr; /* actual peer IrDA address */ 4351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 saddr; /* my local IrDA address */ 4361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u8 dtsap_sel; /* Remote TSAP selector */ 4371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u8 stsap_sel; /* Local TSAP selector */ 4381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 max_sdu_size_rx;/* Socket parameters used for IrTTP */ 4401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 max_sdu_size_tx; 4411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 max_data_size; 4421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u8 max_header_size; 4431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds LOCAL_FLOW tx_flow; /* State of the Tx path in IrTTP */ 4441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* ------------------- IrLMP and IrIAS part ------------------- */ 4461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Used for IrDA Discovery and socket name resolution */ 4471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds void * ckey; /* IrLMP client handle */ 4481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u16 mask; /* Hint bits mask (filter discov.)*/ 4491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int nslots; /* Number of slots for discovery */ 4501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct iriap_cb * iriap; /* Used to query remote IAS */ 4521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int errno; /* status of the IAS query */ 4531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* -------------------- Discovery log part -------------------- */ 4551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Used by initial discovery on the control channel 4561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and by irnet_discover_daddr_and_lsap_sel() */ 4571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct irda_device_info *discoveries; /* Copy of the discovery log */ 4581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int disco_index; /* Last read in the discovery log */ 4591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int disco_number; /* Size of the discovery log */ 4601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 461f8cba16cad68c9b9ee7fecae48a1b91708e8e482Samuel Ortiz struct mutex lock; 462f8cba16cad68c9b9ee7fecae48a1b91708e8e482Samuel Ortiz 4631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} irnet_socket; 4641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 4661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This is the various event that we will generate on the control channel 4671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 4681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef enum irnet_event 4691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds IRNET_DISCOVER, /* New IrNET node discovered */ 4711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds IRNET_EXPIRE, /* IrNET node expired */ 4721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds IRNET_CONNECT_TO, /* IrNET socket has connected to other node */ 4731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds IRNET_CONNECT_FROM, /* Other node has connected to IrNET socket */ 4741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds IRNET_REQUEST_FROM, /* Non satisfied connection request */ 4751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds IRNET_NOANSWER_FROM, /* Failed connection request */ 4761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds IRNET_BLOCKED_LINK, /* Link (IrLAP) is blocked for > 3s */ 4771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds IRNET_DISCONNECT_FROM, /* IrNET socket has disconnected */ 4781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds IRNET_DISCONNECT_TO /* Closing IrNET socket */ 4791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} irnet_event; 4801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 4821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This is the storage for an event and its arguments 4831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 4841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef struct irnet_log 4851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds irnet_event event; 4871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int unit; 4881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 saddr; 4891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 daddr; 4901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char name[NICKNAME_MAX_LEN + 1]; /* 21 + 1 */ 4911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u16_host_order hints; /* Discovery hint bits */ 4921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} irnet_log; 4931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 4951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This is the storage for all events and related stuff... 4961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 4971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef struct irnet_ctrl_channel 4981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds irnet_log log[IRNET_MAX_EVENTS]; /* Event log */ 5001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int index; /* Current index in log */ 5011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spinlock_t spinlock; /* Serialize access to the event log */ 5021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_head_t rwait; /* processes blocked on read (or poll) */ 5031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} irnet_ctrl_channel; 5041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**************************** PROTOTYPES ****************************/ 5061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 5071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Global functions of the IrNET module 5081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note : we list here also functions called from one file to the other. 5091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 5101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* -------------------------- IRDA PART -------------------------- */ 512c1b1203d65955c179fec617ff17a21273f33a414Joe Perchesint irda_irnet_create(irnet_socket *); /* Initialise an IrNET socket */ 513c1b1203d65955c179fec617ff17a21273f33a414Joe Perchesint irda_irnet_connect(irnet_socket *); /* Try to connect over IrDA */ 514c1b1203d65955c179fec617ff17a21273f33a414Joe Perchesvoid irda_irnet_destroy(irnet_socket *); /* Teardown an IrNET socket */ 515c1b1203d65955c179fec617ff17a21273f33a414Joe Perchesint irda_irnet_init(void); /* Initialise IrDA part of IrNET */ 516c1b1203d65955c179fec617ff17a21273f33a414Joe Perchesvoid irda_irnet_cleanup(void); /* Teardown IrDA part of IrNET */ 5171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**************************** VARIABLES ****************************/ 5191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Control channel stuff - allocated in irnet_irda.h */ 5211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern struct irnet_ctrl_channel irnet_events; 5221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* IRNET_H */ 524