1: /*
     2:         
     3:         File:			WiFiController.h
     4:         Program:		GTDriver
     5: 	Author:			Michael Ro├čberg
     6: 				mick@binaervarianz.de
     7: 	Description:		GTDriver is a free driver for PrismGT based cards under OS X.
     8:                 
     9:         This file is part of GTDriver.
    10: 
    11:     GTDriver is free software; you can redistribute it and/or modify
    12:     it under the terms of the GNU General Public License as published by
    13:     the Free Software Foundation; either version 2 of the License, or
    14:     (at your option) any later version.
    15: 
    16:     GTDriver is distributed in the hope that it will be useful,
    17:     but WITHOUT ANY WARRANTY; without even the implied warranty of
    18:     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19:     GNU General Public License for more details.
    20: 
    21:     You should have received a copy of the GNU General Public License
    22:     along with GTDriver; if not, write to the Free Software
    23:     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24: */
    25: 
    26: #include <IOKit/network/IOEthernetController.h> 
    27: #include <IOKit/network/IOEthernetInterface.h> 
    28: #include <IOKit/network/IOGatedOutputQueue.h> 
    29: #include <IOKit/network/IOMbufMemoryCursor.h> 
    30: #include <IOKit/network/IOPacketQueue.h> 
    31: #include <IOKit/network/IONetworkMedium.h> 
    32: #include <IOKit/IOTimerEventSource.h> 
    33: #include <IOKit/IODeviceMemory.h> 
    34: #include <IOKit/IOInterruptEventSource.h> 
    35: #include <IOKit/IOBufferMemoryDescriptor.h> 
    36: #include <IOKit/assert.h> 
    37: #include <IOKit/IODataQueue.h> 
    38: #include "WiFiLogger.h" 
    39: #include "WiFiUserInterface.h" 
    40: //#include "BIWiFiInterface.h"
    41: 
    42: typedef enum {
    43:     MEDIUM_TYPE_NONE = 0,
    44:     MEDIUM_TYPE_AUTO,
    45:     MEDIUM_TYPE_1MBIT,
    46:     MEDIUM_TYPE_2MBIT,
    47:     MEDIUM_TYPE_5MBIT,
    48:     MEDIUM_TYPE_11MBIT,
    49:     MEDIUM_TYPE_54MBIT,
    50:     MEDIUM_TYPE_INVALID
    51: } mediumType_t;
    52: 
    53: #define TRANSMIT_QUEUE_SIZE		1024 
    54: 
    55: class WiFiController : public IOEthernetController {
    56:     OSDeclareDefaultStructors(WiFiController)
    57: 
    58: public:
    59:     virtual bool         createWorkLoop();
    60:     virtual IOWorkLoop  *getWorkLoop()         const;
    61: 
    62:     virtual bool startProvider(IOService *provider);
    63:     virtual bool openProvider();
    64:     virtual bool closeProvider();
    65:     virtual bool freeProvider();
    66:     
    67:     virtual bool startHardware();
    68:     virtual bool initHardware();
    69:     virtual bool freeHardware();
    70:     virtual bool enableHardware();
    71:     virtual bool disableHardware();
    72:     virtual bool handleEjectionHardware();
    73:     virtual bool getReadyForSleep();
    74:     virtual bool handleInterrupt();
    75:     virtual bool handleTimer();
    76:     virtual bool setMediumHardware(mediumType_t medium);
    77:     
    78:     virtual UInt32 outputPacket(mbuf_t m, void * param);
    79:     virtual IOReturn outputPacketHardware(mbuf_t m);
    80:     virtual IOReturn setHardwareAddressHardware(UInt8 *addr);
    81: 
    82:     virtual bool enableAdapter();
    83:     virtual bool disableAdapter();
    84: 
    85:     virtual bool start(IOService * provider);
    86:     virtual bool configureInterface(IONetworkInterface * netif);
    87:     virtual IOReturn selectMedium(const IONetworkMedium * medium);
    88:     virtual void free();
    89:     virtual IOReturn enable(IONetworkInterface * /*netif*/);
    90:     virtual IOReturn disable(IONetworkInterface * /*netif*/);
    91:     
    92:     virtual const OSString *newVendorString()  const;
    93:     virtual const OSString *newModelString()   const;
    94: 
    95:     virtual IOReturn getHardwareAddress(IOEthernetAddress *addr);
    96:     virtual IOReturn setHardwareAddress(const void * addr, UInt32 addrBytes);
    97: 
    98:     virtual void getPacketBufferConstraints(IOPacketBufferConstraints *constraints) const;
    99:     virtual IOOutputQueue * createOutputQueue();
   100: 
   101: 	static void interruptOccurred(OSObject * owner, IOInterruptEventSource * src, int count);
   102:     static void timeoutOccurred(OSObject * owner, IOTimerEventSource * timer);
   103: 
   104:     virtual IOReturn message(UInt32 type, IOService *provider, void *argument = 0);
   105: 
   106:     virtual UInt32          getLinkSpeed();
   107:     virtual wirelessState   getConnectionState();
   108:     virtual bool            getBSSNodesInRange(UInt32 *count, UInt8* data);
   109:     virtual bool            setSSID(UInt32 length, UInt8* ssid);
   110:     virtual bool            setKey(UInt32 length, UInt8* key);
   111:     virtual bool            setMode(wirelessMode mode);
   112:     virtual bool            setFrequency(UInt32 frequency);
   113:     virtual UInt32          getFrequency();
   114:    
   115:     virtual IOReturn setMulticastMode(bool active);
   116:     virtual IOReturn setMulticastList(IOEthernetAddress * addrs, UInt32 count);
   117: 
   118:     //-----------------------------------------------------------------------
   119:     // Power management support.
   120:     //-----------------------------------------------------------------------
   121: 
   122:     virtual IOReturn registerWithPolicyMaker(IOService * policyMaker);
   123:     virtual IOReturn setPowerState(unsigned long powerStateOrdinal, IOService *policyMaker);
   124:  
   125:     void setPowerStateOff(void);
   126:     void setPowerStateOn(void);
   127:     
   128:     //for monitor mode
   129:     virtual IODataQueue* getPacketQueue() { return _packetQueue; }
   130: protected:
   131:     //virtual IONetworkInterface * createRawInterface();
   132:     //virtual bool attachRawInterface(IONetworkInterface ** interfaceP, bool  doRegister);
   133: 
   134:     virtual bool _initDriver(IOService * provider);
   135:     virtual bool _addMediumType(UInt32 type, UInt32 speed, UInt32 code, char* name = 0);
   136:     virtual IONetworkMedium *_getMediumWithType(UInt32 type);
   137:     
   138:     IOWorkLoop              *_workLoop;
   139:     IOEthernetInterface     *_netif;
   140: 	//BIWiFiInterface			*_rawNetif;
   141:     IOEthernetAddress       _myAddress;
   142:     bool                    _enabledForNetif;
   143:     bool                    _cardGone;
   144:     mediumType_t            _currentMediumType;
   145:     OSDictionary            *_mediumDict;
   146:     IONetworkMedium         *_mediumTable[MEDIUM_TYPE_INVALID];
   147: 
   148:     IOInterruptEventSource  *_interruptSrc;
   149:     IOTimerEventSource      *_timerSrc;
   150:     IOOutputQueue           *_transmitQueue;
   151:     IODataQueue             *_packetQueue;
   152:     
   153:     IONetworkStats          *_netStats;
   154:     IOEthernetStats         *_etherStats;
   155:     
   156:     IOService *             _pmPolicyMaker;
   157:     UInt32                  _pmPowerState;
   158:     thread_call_t           _powerOffThreadCall;
   159:     thread_call_t           _powerOnThreadCall;
   160:     
   161:     wirelessState           _currentState;
   162:     wirelessMode            _currentMode;
   163:     UInt32                  _currentFrequency;
   164:     UInt16                  _linkSpeed;
   165:     UInt8                   _ssid[MAX_SSID_LENGTH];
   166:     UInt8                   _ssidLength;
   167:     UInt8                   _bssListCount;
   168:     bssItem                 _bssList[MAX_BSS_COUNT];
   169:     UInt8                   _currentBSSID[6];
   170: };
   171: