1/* IrDAComm.h - This file contains glue to IrDA and the IrComm client */ 2 3#ifndef _IRDACOMM_ 4#define _IRDACOMM_ 5 6#include <kern/thread_call.h> 7 8#include "AppleIrDA.h" 9#include "IrDAUserClient.h" // for status 10 11class TIrGlue; 12class IrComm; 13class IOCommandGate; 14class CTimer; 15class IrDATimerEventSource; 16 17enum { // private irdacomm states 18 kIrDACommStateStart, // starting up and doing initial connect attempts 19 kIrDACommStateIdle, // not doing much 20 kIrDACommStateConnecting, // trying to connect 21 kIrDACommStateListening, // waiting for peer to connect to us 22 kIrDACommStateStoppingListen, // waiting for listen abort to finish 23 kIrDACommStateDisconnecting, // waiting for a disconnect request to finish 24 kIrDACommStateConnected, // ircomm channel open, data can flow 25 kIrDACommStateStopping2, // stopping, need two callbacks 26 kIrDACommStateStopping, // stopping, need one callback 27 kIrDACommStateStopped // all stopped 28}; 29 30enum { // private irdacomm events 31 kIrDACommEventTimer, // main irdacomm timer fired 32 kIrDACommEventConnected, // ircomm callback with state of connected 33 kIrDACommEventDisconnected, // ircomm callback with state of disconnected 34 kIrDACommEventStop // Want to disconnect and stop 35}; 36 37class IrDAComm : public OSObject 38{ 39 OSDeclareDefaultStructors( IrDAComm ) ; /* Constructor & Destructor stuff */ 40 41public: 42 /**** IrDAComm Methods ****/ 43 44 static IrDAComm * irDAComm(AppleIrDASerial *driver, AppleIrDA *appleirda); // IOKit style creation/init pair 45 bool init(AppleIrDASerial *driver, AppleIrDA *appleirda); // Set up to start 46 //IOReturn Start(); // Start trying to connect 47 void free(); 48 49 //***** 50 // The following are safe to call from outside our workloop -- they get the 51 // command gate before getting to IrDA. 52 //***** 53 54 IOReturn Stop(); // Disconnect and stop 55 56 // Pseudo tty wants to send data to peer over IrCOMM 57 size_t TXBufferAvailable(); // Return max tx size available to write to ircomm 58 size_t Write( UInt8 *Buf, size_t Length ); // Send data over the ircomm channel 59 60 // Hardware driver has a packet to send to IrLAP 61 IOReturn ReadComplete( UInt8 *Buf, size_t Length ); // Call with the incoming data 62 63 // Sending back flow-control to the peer (pseudo tty consumed the data) 64 void ReturnCredit(size_t byte_count); // serial client has consumed count bytes of data 65 66 // Hardware driver calls this when the transmit to the pod has finished 67 void Transmit_Complete(Boolean worked); 68 69 // Hardware driver calls this when SetSpeed completes 70 void SetSpeedComplete(Boolean worked); 71 72 //***** 73 // The following routines are for IrComm layer back to us and 74 // assume we're already running in our workloop 75 //***** 76 77 void ConnectionStatus(Boolean connected); // ircomm calls this to tell us of connection states 78 void IrCommDataRead(UInt8 *buf, UInt32 length); // ircomm data to pass back to the tty 79 void BackEnable(); // our tinytp peer can handle some more data sent to it now 80 81 static void TimerRoutine(OSObject *owner, IrDATimerEventSource *iotimer); // our state engine CTimer callback 82 83 // For user-client status interface, maybe should get the gate, but ok if race condition - it's just status 84 void GetIrDAStatus(IrDAStatus *status); // connnected status and statistics for user-client 85 86 // bsd pseudo tty open calls this while stalling for initial connect attempt 87 bool Starting(); // returns true for initial few connection attempts 88 89private: 90 UInt8 fState; // our state 91 AppleIrDASerial *fDriver; // back to scc/usb driver 92 //IOTimerEventSource *fTimerSrc; // our listen/discover timer 93 CTimer *fTimer; // our state-engine timer 94 USBIrDAQoS *fQoS; // driver supplied qos 95 TIrGlue *fIrDA; // the stack, we make and free 96 IrComm *fIrComm; // ircomm protocol layer 97 Boolean fWriteBusy; // last txbufferavailable returned zero 98 IOCommandGate *fGate; // my command gate to serialize to irda 99 UInt8 fStartCounter; // counter for initial connection attempts 100 thread_call_t fStop_thread; // non-gated stop 101 102 void StateChange(int event); // handle a change in status or timer firing 103 static IOReturn DoSomething(OSObject *owner, void *a, void *b, void *c, void *d); // run command in command gate 104 static void stop_thread(thread_call_param_t param0, thread_call_param_t param1); 105 106}; /* end class IrDAComm */ 107 108#endif 109