3      Copyright (C) Dean Camera, 2009. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, and distribute this software 
  13   and its documentation for any purpose and without fee is hereby 
  14   granted, provided that the above copyright notice appear in all 
  15   copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting 
  17   documentation, and that the name of the author not be used in 
  18   advertising or publicity pertaining to distribution of the 
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  33  *  Header file for RNDIS.c. 
  43                 #include "RNDISEthernet.h" 
  44                 #include "RNDISConstants.h" 
  48                 /** Physical MAC Address of the USB network adapter */ 
  49                 #define ADAPTER_MAC_ADDRESS                   {0x02, 0x00, 0x02, 0x00, 0x02, 0x00} 
  51                 /** Implemented RNDIS Version Major */ 
  52                 #define REMOTE_NDIS_VERSION_MAJOR             0x01 
  54                 /** Implemented RNDIS Version Minor */ 
  55                 #define REMOTE_NDIS_VERSION_MINOR             0x00 
  57                 /** RNDIS request to issue a host-to-device NDIS command */ 
  58                 #define REQ_SendEncapsulatedCommand           0x00 
  60                 /** RNDIS request to issue a device-to-host NDIS response */ 
  61                 #define REQ_GetEncapsulatedResponse           0x01 
  64                 /** Enum for the possible NDIS adapter states. */ 
  67                         RNDIS_Uninitialized    
= 0, /**< Adapter currently uninitialized */ 
  68                         RNDIS_Initialized      
= 1, /**< Adapter currently initialized but not ready for data transfers */ 
  69                         RNDIS_Data_Initialized 
= 2, /**< Adapter currently initialized and ready for data transfers */ 
  72                 /** Enum for the NDIS hardware states */ 
  73                 enum NDIS_Hardware_Status_t
 
  75                         NdisHardwareStatusReady
, /**< Hardware Ready to accept commands from the host */ 
  76                         NdisHardwareStatusInitializing
, /**< Hardware busy initializing */ 
  77                         NdisHardwareStatusReset
, /**< Hardware reset */ 
  78                         NdisHardwareStatusClosing
, /**< Hardware currently closing */ 
  79                         NdisHardwareStatusNotReady 
/**< Hardware not ready to accept commands from the host */ 
  83                 /** Type define for a RNDIS message header, sent before RNDIS messages */ 
  86                         uint32_t MessageType
; /**< RNDIS message type, a REMOTE_NDIS_*_MSG constant */ 
  87                         uint32_t MessageLength
; /**< Total length of the RNDIS message, in bytes */ 
  88                 } RNDIS_Message_Header_t
; 
  90                 /** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */ 
  94                         uint32_t MessageLength
; 
  97                         uint32_t OOBDataOffset
; 
  98                         uint32_t OOBDataLength
; 
  99                         uint32_t NumOOBDataElements
; 
 100                         uint32_t PerPacketInfoOffset
; 
 101                         uint32_t PerPacketInfoLength
; 
 104                 } RNDIS_Packet_Message_t
; 
 106                 /** Type define for a RNDIS Initialize command message */ 
 109                         uint32_t MessageType
; 
 110                         uint32_t MessageLength
; 
 113                         uint32_t MajorVersion
; 
 114                         uint32_t MinorVersion
; 
 115                         uint32_t MaxTransferSize
; 
 116                 } RNDIS_Initialize_Message_t
; 
 118                 /** Type define for a RNDIS Initialize complete response message */ 
 121                         uint32_t MessageType
; 
 122                         uint32_t MessageLength
; 
 126                         uint32_t MajorVersion
; 
 127                         uint32_t MinorVersion
; 
 128                         uint32_t DeviceFlags
; 
 130                         uint32_t MaxPacketsPerTransfer
; 
 131                         uint32_t MaxTransferSize
; 
 132                         uint32_t PacketAlignmentFactor
; 
 133                         uint32_t AFListOffset
; 
 135                 } RNDIS_Initialize_Complete_t
; 
 137                 /** Type define for a RNDIS Keepalive command message */ 
 140                         uint32_t MessageType
; 
 141                         uint32_t MessageLength
; 
 143                 } RNDIS_KeepAlive_Message_t
; 
 145                 /** Type define for a RNDIS Keepalive complete message */ 
 148                         uint32_t MessageType
; 
 149                         uint32_t MessageLength
; 
 152                 } RNDIS_KeepAlive_Complete_t
; 
 154                 /** Type define for a RNDIS Reset complete message */ 
 157                         uint32_t MessageType
; 
 158                         uint32_t MessageLength
; 
 161                         uint32_t AddressingReset
; 
 162                 } RNDIS_Reset_Complete_t
; 
 164                 /** Type define for a RNDIS Set command message */ 
 167                         uint32_t MessageType
; 
 168                         uint32_t MessageLength
; 
 172                         uint32_t InformationBufferLength
; 
 173                         uint32_t InformationBufferOffset
; 
 174                         uint32_t DeviceVcHandle
; 
 175                 } RNDIS_Set_Message_t
; 
 177                 /** Type define for a RNDIS Set complete response message */ 
 180                         uint32_t MessageType
; 
 181                         uint32_t MessageLength
; 
 184                 } RNDIS_Set_Complete_t
; 
 186                 /** Type define for a RNDIS Query command message */ 
 189                         uint32_t MessageType
; 
 190                         uint32_t MessageLength
; 
 194                         uint32_t InformationBufferLength
; 
 195                         uint32_t InformationBufferOffset
; 
 196                         uint32_t DeviceVcHandle
; 
 197                 } RNDIS_Query_Message_t
; 
 199                 /** Type define for a RNDIS Query complete response message */ 
 202                         uint32_t MessageType
; 
 203                         uint32_t MessageLength
; 
 207                         uint32_t InformationBufferLength
; 
 208                         uint32_t InformationBufferOffset
; 
 209                 } RNDIS_Query_Complete_t
; 
 211         /* External Variables: */ 
 212                 extern uint8_t                 RNDISMessageBuffer
[]; 
 213                 extern RNDIS_Message_Header_t
* MessageHeader
; 
 214                 extern bool                    ResponseReady
; 
 215                 extern uint8_t                 CurrRNDISState
; 
 217         /* Function Prototypes: */ 
 218                 void ProcessRNDISControlMessage(void); 
 220                 #if defined(INCLUDE_FROM_RNDIS_C) 
 221                         static bool ProcessNDISQuery(uint32_t OId
, void* QueryData
, uint16_t QuerySize
, 
 222                                                                                  void* ResponseData
, uint16_t* ResponseSize
); 
 223                         static bool ProcessNDISSet(uint32_t OId
, void* SetData
, uint16_t SetSize
);