/******************************************************************************

 ZG2100 Driver registers/bits
 Module for Microchip TCP/IP Stack
  -Provides access to ZG2100 WiFi controller
  -Reference: ZG2100 Data sheet, IEEE 802.11 Standard

*******************************************************************************
 FileName:		ZG2100.h
 Dependencies:	TCP/IP Stack header files
 Processor:		PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32
 Compiler:		Microchip C32 v1.10b or higher
				Microchip C30 v3.22 or higher
				Microchip C18 v3.34 or higher
 Company:		Microchip Technology, Inc.

 Software License Agreement

 Copyright (C) 2002-2010 Microchip Technology Inc.  All rights reserved.

 Microchip licenses to you the right to use, modify, copy, and distribute:
 (i)  the Software when embedded on a Microchip microcontroller or digital 
      signal controller product ("Device") which is integrated into 
      Licensee's product; or
 (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h,
      ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device used in 
	  conjunction with a Microchip ethernet controller for the sole purpose 
	  of interfacing with the ethernet controller.

 You should refer to the license agreement accompanying this Software for 
 additional information regarding your rights and obligations.

 THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
 NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR ANY INCIDENTAL,
 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST
 OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS BY
 THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS
 FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON
 THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR
 OTHERWISE.


 Author				Date		Comment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Michael Palladino	10/13/07	Original
 KO					31 Oct 2008	Port to PIC24F and PIC32 for TCP/IP stack v4.52
******************************************************************************/
#ifndef __ZG2100_H
#define __ZG2100_H

//============================================================================
//                                  Include files
//============================================================================

#include "GenericTypeDefs.h"
#include "Compiler.h"
#include "TCPIP Stack/ZGDriverTypes.h"
#include "TCPIP Stack/ZGDriverAccessHal.h"
#include "TCPIP Stack/ZGDriverIfaceHal.h"
#include "TCPIP Stack/ZGDriverAccessApp.h"
#include "TCPIP Stack/ZGDriverIfaceApp.h"
#include "TCPIP Stack/ZGDriverConstants.h"
#include "TCPIP Stack/ZGDriverPrv.h"
#include "TCPIP Stack/ZGAccessSys.h"
#include "TCPIP Stack/ZGDriverIfaceApp.h"
#include "TCPIP Stack/ZGDriverAccessSys.h"



//============================================================================
//                                  RAW msg Constants
//============================================================================
// indexes where msg data starts
#define  kRawSetParamMsgStartIndex   (4)  /* start index for Raw SetParam message */
#define  kRawScanMsgStartIndex       (2)  /* start index for RAW Scan message     */
#define  kRawJoinMsgStartIndex       (2)  /* start index for RAW Join message     */
#define  kRawAuthMsgStartIndex       (2)  /* start index for RAW Auth message     */
#define  kRawAssocMsgStartIndex      (2)  /* start index for RAW Assoc message    */
#define  kRawSecKeyMsgStartIndex     (2)  /* start index for RAW Sec Key message  */
#define  kRAWSetPMKKeyStartIndex     (2)  /* start index for RAW Set PMK Key msg  */
#define  kRAWPskCalcCnfStartIndex    (2)  /* start index for received PSK Calc Cnf msg */

//============================================================================
//                                  RAW Constants
//============================================================================
#define kZGRawId0                       (0u)
#define kZGRawId1                       (1u)

// RAW0 used for Rx, RAW1 used for Tx
#define kRxPipeRAW          kZGRawId0
#define kTxPipeRAW          kZGRawId1


// Source/Destination objects on the G2100
#define kZGRawSrcDestCmdProcessor       (0x00u)   /* Cmd processor (aka G2100 MAC)                  */
#define kZGRawSrcDestManagementPool     (0x10u)   /* For 802.11 Management packets                  */
#define kZGRawSrcDestDataPool           (0x20u)   /* Data Memory pool used for tx and rx operations */
#define kZGRawSrcDestScratchPool        (0x30u)   /* Scratch object                                 */
#define kZGRawSrcDestMemory             (0x40u)   /* single level stack to save state of RAW        */
#define kZGRawSrcDestRawDataCopy        (0x70u)   /* RAW to RAW copy                                */

//typedef void (*tZGCallbackFuncPtr)(tZGU16 data);

//#define USE_TICK_TIMEOUT

extern DWORD zgGetTickDuration(DWORD initTickCnt);

extern tZGMsgQueueID driverDataQueueID, driverMgmtQueueID;

extern Boolean gHostRAWDataPacketReceived;

extern void zgMakeInitialConnection(void);
tZGVoidReturn zgEintISR(tZGVoidInput);
Boolean ZGSendRAWDataFrame(tZGU16 bufLen);

tZGU16 ZGRawMove(tZGU16 rawId, tZGU16 srcDest, Boolean rawIsDestination, tZGU16 size);
Boolean ZGRawSetIndex(tZGU16 rawId, tZGU16 index);
tZGU16 ZGRawGetIndex(tZGU16 rawId);
Boolean ZGRawGetByte(tZGU16 rawId, tZGU8 *pBuffer, tZGU16 length);
Boolean ZGRawSetByte(tZGU16 rawId, tZGU8 *pBuffer, tZGU16 length);
Boolean ZGRawSetByteROM(tZGU16 rawId, ROM tZGU8 *pBuffer, tZGU16 length);

tZGU16 ZGMACIFService(tZGVoidInput);
Boolean ZGSendRAWDataFrame(tZGU16 bufLen);
void ZGTransportRegisterRead(tZGU8  zgReg,
                             tZGU8  *pBuffer,
                             tZGU16 length);


tZGBool ZGisTxMgmtReady(tZGVoidInput);


tZGVoidReturn ZGFreeMgmtTx(tZGVoidInput);
Boolean ZGSendRAWManagementFrame(tZGU16 bufLen);



Boolean ZGRawGetMgmtRxBuffer(tZGU16 *p_numBytes);
tZGVoidReturn ZGRawFreeRxMgmtBuffer(tZGVoidInput);
tZGVoidReturn ZGSetRawRxMgmtInProgress(Boolean action);
Boolean ZGisRawRxMgmtInProgress(tZGVoidInput);

tZGReturnStatus ZGRawSendUntamperedData(tZGU8 *pReq, tZGU16 len);

#endif // __ZG2100_H

