

//   vim:tw=110:ts=4:
#ifndef HCFCFG_H
#define HCFCFG_H 1
/* add to readme.txt o.i.d
 		replace IN_PORT_STRING and OUT_PORT_STRING with repeated
		IN_PORT_WORD and OUT_PORT_WORD to simplify end user customization. Due
		to the chosen strategy to implement WPA and resolve the shortcomings
		in the Hermes Byte I/O, there is no noticeable performance gain in the
		STRING macros anymore.
	add a default IN_/OUT_PORT_STRING to hcfcfg.h, so the MSF programmer can decide what he/she likes the best
*/

/*************************************************************************************************************
*
* FILE	 : hcfcfg.tpl // hcfcfg.h
*
* DATE   : $Date: 2004/02/16 19:31:27 $   $Revision: 1.32 $
* Original: 2004/02/11 13:15:29    Revision: 1.218      Tag: t20040213_01
*
* AUTHOR : Nico Valster
*
* DESC   : HCF Customization Macros
*
**************************************************************************************************************
 *
 *
 * SOFTWARE LICENSE
 *
 * This software is provided subject to the following terms and conditions,
 * which you should read carefully before using the software.  Using this
 * software indicates your acceptance of these terms and conditions.  If you do
 * not agree with these terms and conditions, do not use the software.
 *
 * COPYRIGHT © 1994 - 1995	by AT&T.				All Rights Reserved
 * COPYRIGHT © 1996 - 2000 by Lucent Technologies.	All Rights Reserved
 * COPYRIGHT © 2001 - 2004	by Agere Systems Inc.	All Rights Reserved
 * All rights reserved.
 *
 * Redistribution and use in source or binary forms, with or without
 * modifications, are permitted provided that the following conditions are met:
 *
 * . Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following Disclaimer as comments in the code as
 *    well as in the documentation and/or other materials provided with the
 *    distribution.
 *
 * . Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following Disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * . Neither the name of Agere Systems Inc. nor the names of the contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * Disclaimer
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  ANY
 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 *
**************************************************************************************************************
*
* hcfcfg.tpl list all #defines which must be specified to:
*    I:	adjust the HCF functions defined in HCF.CPP to the characteristics of a specific environment
*		o maximum sizes for messages and notification frames, persistent configuration storage
*		o Endianess
*
*	II:	Compiler specific macros
*		o port I/O macros
*		o type definitions
*
*  III:	Environment specific ASSERT macro
*
*   IV: Compiler specific
*
*    V: ;? specific
*
*
* By copying HCFCFG.TPL to HCFCFG.H and -if needed- modifying the #defines the WCI functionality can be
* tailored
*
* Supported environments:
WVLAN_41	Miniport								NDIS 3.1
WVLAN_42	Packet									Microsoft Visual C 1.5
WVLAN_43	16 bits DOS ODI							Microsoft Visual C 1.5
WVLAN_44	32 bits ODI (__NETWARE_386__)			WATCOM
WVLAN_45	MAC_OS									MPW?, Symantec?
WVLAN_46	Windows CE (_WIN32_WCE)					Microsoft ?
WVLAN_47	LINUX  (__LINUX__)						GCC
WVLAN_48	Miniport								NDIS 5
WVLAN_51	Miniport USB							NDIS 5
WVLAN_52	Miniport								NDIS 4
WVLAN_53	VxWorks END Station driver
WVLAN_54	VxWorks END Access Point driver
WVLAN_81	WavePoint								BORLAND C
WCITST		Inhouse test tool						Microsoft Visual C 1.5
WSU			WaveLAN Station Update					Microsoft Visual C ??
SCO UNIX	not yet actually used ?					?
__ppc		OEM supplied							?
_AM29K		OEM supplied							?
?			OEM supplied							Microtec Research 80X86 Compiler



*****************************    IN_PORT_STRING_16  S a m p l e s ********************************************

		// C implementation which let the processor handle the word-at-byte-boundary problem
#define IN_PORT_STRING_16( prt, addr, n)				\
	while ( n-- ) { *(hcf_16 FAR*)addr = IN_PORT_WORD( prt ); addr += 2; }

		// C implementation which handles the word-at-byte-boundary problem
#define IN_PORT_STRING_16( prt, addr, n)				\
	while ( n-- ) { int i = IN_PORT_WORD( prt ); *addr++ = (char)i; *addr++ = (char)(i >> 8); }


		// Assembler implementation
#define IN_PORT_STRING_16( port, dest, len) __asm	\
{													\
	__asm push di									\
	__asm push es									\
	__asm mov cx,len								\
	__asm les di,dest								\
	__asm mov dx,port								\
	__asm rep insw									\
	__asm pop es									\
	__asm pop di									\
}


*****************************   OUT_PORT_STRING_16  S a m p l e s ********************************************

		// C implementation which let the processor handle the word-at-byte-boundary problem
#define OUT_PORT_STRING_16( prt, addr, n)			\
	while ( n-- ) { OUT_PORT_WORD( prt, *(hcf_16 FAR*)addr ) ; addr  += 2; }

		// C implementation which handles the word-at-byte-boundary problem
#define OUT_PORT_STRING_16( prt, addr, n)			\
	while ( n-- ) { OUT_PORT_WORD( prt, *addr | *(addr+1)<<8  ) ; addr  += 2; }
//;?  WHY hcf_16 FAR*)addr and not unsigned char FAR*)addr


												// Assembler implementation
#define OUT_PORT_STRING_16( port, addr, len) __asm	\
{													\
	__asm push si									\
	__asm push ds									\
	__asm mov cx,len								\
	__asm lds si,addr								\
	__asm mov dx,port								\
	__asm rep outsw									\
	__asm pop ds									\
	__asm pop si									\
}

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


/* * * * * * * * * * * * * * * * * * * * * * *  I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*	Alignment
 *	Some platforms can access words on odd boundaries (with possibly an performance impact), at other
 *	platforms such an access may result in a memory access violation.
 *	It is assumed that everywhere where the HCF casts a char pointer into a word pointer, the alignment
 *	criteria are met. This put some restrictions on the MSF, which are assumed to be "automatically" fulfilled
 *	at the applicable platforms
 *	To assert this assumption, the macro HCF_ALIGN can be defined. The default value is 0, meaning no
 *	alignment, a value of 2 means word alignment, other values are invalid
 */

/*  * * * * * * * * * * * * * * * * * * * * * * II * * * * * * * * * * * * * * * * * * * * * * */



/************************************************************************************************/
/******************  C O M P I L E R   S P E C I F I C   M A C R O S  ***************************/
/************************************************************************************************/
/*************************************************************************************************
*
* The platforms supported by this version are:
*	- Microsoft Visual C 1.5 (16 bits platform)
*	- Microsoft Visual C 2.0 (32 bits platform)
*	- Watcom C/C++ 9.5
*	- SCO UNIX
*
* In this version of hcfcfg.tpl all macros except the MSVC 1.5 versions are either dependent on
* compiler/environment supplied macros (e.g. _MSC_VER or "def-ed out"
*
* By selecting the appropriate Macro definitions by means of modifying the "#ifdef 0/1" lines, the HCF can be
* adjusted for the I/O characteristics of a specific compiler
*
* If needed the macros can be modified or replaced with definitions appropriate for your personal platform.
* If you need to make such changes it is appreciated if you inform Agere Systems
* That way the changes can become part of the next release of the WCI
*
*
*	The prototypes and functional description of the macros are:
*
*	hcf_16	IN_PORT_WORD(  hcf_16 port)
*			Reads a word (16 bits) from the specified port
*
*	void	OUT_PORT_WORD( hcf_16 port, hcf_16 value)
*			Writes a word (16 bits) to the specified port
*
*	void	IN_PORT_STRING_16( port, dest, len)
*			Reads len number of words from the specified port to the (FAR) address dest in PC-RAM
*			Note that len specifies the number of words, NOT the number of bytes
*			!!!NOTE, although len specifies the number of words, dest MUST be a char pointer NOTE!!!
*			See also the common notes for IN_PORT_STRING_16 and OUT_PORT_STRING
*
*	void	OUT_PORT_STRING_16( port, addr, len)
*			Writes len number of words from the (FAR) address addr in PC-RAM to the specified port
*			Note that len specifies the number of words, NOT the number of bytes.
*			!!!NOTE, although len specifies the number of words, addr MUST be a char pointer NOTE!!!
*
*			The peculiar combination of word-length and char pointers for IN_PORT_STRING_16 as well as
*			OUT_PORT_STRING_16 is justified by the assumption that it offers a more optimal algorithm
*
*			Note to the HCF-implementor:
*			Due to the passing of the parameters to compiler specific blabla.........
*			do not use "expressions" as parameters, e.g. don't use "ifbp->IFB_IOBase + HREG_AUX_DATA" but
*			assign this to a temporary variable.
*
*
*  NOTE!!	For convenience of the MSF-programmer, all {IN|OUT}_PORT_{BYTE|WORD|STRING} macros are allowed to
*			modify their parameters (although some might argue that this would constitute bad coding
*			practice). This has its implications on the HCF, e.g. as a consequence these macros should not
*			be called with parameters which have side effects, e.g auto-increment.
*
*  NOTE!!	in the Microsoft implementation of inline assembly it is O.K. to corrupt all flags except
*			the direction flag and to corrupt all registers except the segment registers and EDI, ESI,
*			ESP and EBP (or their 16 bits equivalents).
*			Other environments may have other constraints
*
*  NOTE!!	in the Intel environment it is O.K to have a word (as a 16 bits quantity) at a byte boundary,
*			hence IN_/OUT_PORT_STRING_16 can move words between PC-memory and NIC-memory with as only
*			constraint that the words are on a word boundary in NIC-memory. This does not hold true
*			for all conceivable environments, e.g. an Motorola 68xxx does not allow this, in other
*			words whenever there is a move from address in 2*n in one memory type to address 2*m+1 in the
*			other type, the current templates for IN_/OUT_PORT_STRING_16 are unsuitable. Probably the
*			boundary conditions imposed by these type of platforms prevent this case from materializing
*
*************************************************************************************************/

// Note:
// Visual C++ 1.5 : _MSC_VER ==  800
// Visual C++ 4.0 : _MSC_VER == 1000
// Visual C++ 4.2 : _MSC_VER == 1020

typedef unsigned char		hcf_8;
typedef unsigned short		hcf_16;
typedef unsigned long		hcf_32;


/****************************** #define HCF_TYPE ******************************/
//#define HCF_TYPE_HI_PRE_SSN	0x0000	// Hermes-I F/W without SSN support
#define HCF_TYPE_NONE		0x0000	// No type
#define HCF_TYPE_WPA		0x0001	// WPA support
#define HCF_TYPE_SSN  HCF_TYPE_WPA	// SSN support (original name for SSN)
#define HCF_TYPE_USB		0x0002	// Host side for Internally developed USB Dongle driver support
#define HCF_TYPE_HII		0x0004	// Hermes-II
#define HCF_TYPE_AP			0x0010	// Access Point
//#define HCF_TYPE_STA		0x0020	// legacy: Station
#define HCF_TYPE_PRELOADED	0x0040	// pre-loaded F/W
#define HCF_TYPE_HII5		0x0080	// Hermes-2.5
#define HCF_TYPE_CCX		0x0100	// CKIP


/************************************************************************************************/
/******************************  M I N I P O R T    N D I S *************************************/
/************************************************************************************************/

#if defined WVLAN_41 || defined WVLAN_48 || defined WVLAN_51 || defined WVLAN_52 || defined _WIN32_WCE

#define HCF_DLV 1
// HCF_MONITOR_MODE is needed FOR ATE testing
#define HCF_MONITOR_MODE		1

#if _BLDTYPE == 64
#if _VARIANT == 5 || _VARIANT == 6
#define _WARP
#define support_32bits 1
#endif // _VARIANT == 5 || _VARIANT == 6
#endif // _BLDTYPE == 64

#if _BLDTYPE == 16
#ifdef HERMES2
#if defined WVLAN_48
#if _VARIANT == 4
#define _CCX
#define _FUNK
#endif // _VARIANT==4
#endif // WVLAN_48
#endif // HERMES2
#endif // _BLDTYPE == 16


#if defined _WIN32_WCE
#define HCF_INTERFACE_CONNECT(ifbp)			InitializeCriticalSection(&(ifbp->IFB_CritSec));
#define HCF_INTERFACE_DISCONNECT(ifbp)		DeleteCriticalSection(&(ifbp->IFB_CritSec));
#define HCF_ENTER_INTERFACE_FUNCT(ibfb)		EnterCriticalSection(&(ifbp->IFB_CritSec));
#define HCF_LEAVE_INTERFACE_FUNCT(ifbp)		LeaveCriticalSection(&(ifbp->IFB_CritSec));
#define HCF_ALIGN	2
#define HCF_MEM_IO	1					// overrule standard Port I/O with Memory mapped I/O

#else
#define HCF_INTERFACE_CONNECT(ifbp)
#define HCF_INTERFACE_DISCONNECT(ifbp)
#define HCF_ENTER_INTERFACE_FUNCT(ibfb)
#define HCF_LEAVE_INTERFACE_FUNCT(ifbp)
#endif // _WIN32_WCE

#if defined WVLAN_41
#define	MSF_COMPONENT_ID			COMP_ID_MINIPORT_NDIS_31
#endif // WVLAN_41
#if defined WVLAN_48 && !defined _WIN32_WCE
#define	MSF_COMPONENT_ID			COMP_ID_MINIPORT_NDIS_50
#endif // WVLAN_48 / _WIN32_WCE
#if defined WVLAN_51
#define HCF_INT_ON					0
#define	MSF_COMPONENT_ID			COMP_ID_MINIPORT_NDIS_50_USB
#endif // WVLAN_51
#if defined WVLAN_52 && !defined _WIN32_WCE
#define	MSF_COMPONENT_ID			COMP_ID_MINIPORT_NDIS_40
#endif // WVLAN_52 / _WIN32_WCE
#if defined _WIN32_WCE
#define	MSF_COMPONENT_ID			COMP_ID_WIN_CE
#endif // _WIN32_WCE

#define	MSF_COMPONENT_VAR			_VARIANT

#ifdef HERMES2
#define	T1__HCF_TYPE					(HCF_TYPE_HII)
#else // WVLAN_51
#define	T1__HCF_TYPE					(HCF_TYPE_NONE)
#endif // HERMES2

#ifdef WVLAN_51
#define T2__HCF_TYPE					(T1__HCF_TYPE | HCF_TYPE_USB)
#else // WVLAN_51
#define T2__HCF_TYPE					(T1__HCF_TYPE)
#endif // WVLAN_51

#ifdef _WARP
#define T3__HCF_TYPE					(T2__HCF_TYPE | HCF_TYPE_HII5)
#else // _WARP
#define T3__HCF_TYPE					(T2__HCF_TYPE)
#endif // WARP

#ifdef _CCX
#define T4__HCF_TYPE					(T3__HCF_TYPE | HCF_TYPE_CCX)
#else // _WARP
#define T4__HCF_TYPE					(T3__HCF_TYPE)
#endif // _CCX

#define HCF_CFG_STA_1_BOTTOM        	16

#define T5__HCF_TYPE					(T4__HCF_TYPE)

// Default to TYPE_AP + SSN!
#define HCF_TYPE						(T5__HCF_TYPE | HCF_TYPE_AP | HCF_TYPE_WPA)

#if (defined DBG && DBG != 0)
#ifndef HCF_STATIC
#define HCF_STATIC
#endif // HCF_STATIC
#endif // DBG

#if !defined SOFTRONICS_CODE && !defined _APIDLL && !defined _WIN32_WCE
#include <ndis.h>
#endif // SOFTRONICS_CODE / _APIDLL / _WIN32_WCE
#if defined _WIN32_WCE
#include <windows.h>
#include <winnt.h>
#endif  // _WIN32_WCE
#include "version.h"

#define	MSF_COMPONENT_MAJOR_VER		TPI_MAJOR_VERSION
#define	MSF_COMPONENT_MINOR_VER		TPI_MINOR_VERSION

#if !defined _APIDLL && !defined WVLAN_51 && !defined _WIN32_WCE

__inline UCHAR NDIS_IN_BYTE( ULONG port )
{
    UCHAR value;
    NdisRawReadPortUchar(port , &value);
    return (value);
}

__inline ULONG NDIS_IN_LONG( ULONG port )
{
    ULONG value;
    NdisRawReadPortUlong(port , &value);
    return (value);
}
__inline USHORT NDIS_IN_WORD( ULONG port )
{
    USHORT value;
    NdisRawReadPortUshort(port , &value);
    return (value);
}

#define IN_PORT_HCF32(port)			NDIS_IN_LONG( (ULONG) (port) )
#define IN_PORT_WORD(port)			NDIS_IN_WORD( (ULONG) (port) )
#define OUT_PORT_HCF32(port, value)	NdisRawWritePortUlong((ULONG) (port) , value)
#define OUT_PORT_WORD(port, value)	NdisRawWritePortUshort((ULONG) (port) , (USHORT) (value))

#ifdef BUSMASTER
validate this section;
extern void ooiInPortString(IN PULONG Port, OUT PUSHORT  Buffer, IN ULONG  Length);
extern void ooiOutPortString(IN PULONG Port, OUT PUSHORT  Buffer, IN ULONG  Length);

#define IN_PORT_STRING_16(port, addr, len) \
{                                                                    \
	if (len < 100 || (port != TpiMac.Hw->PortOffset + HREG_DATA_0 && \
					  port != TpiMac.Hw->PortOffset + HREG_DATA_1)){ \
		NdisRawReadPortBufferUshort(port, addr, (len));              \
	}                                                                \
	else {															 \
        ooiInPortString(port, (PUSHORT)addr, len);					 \
    }                                                                \
}

#define OUT_PORT_STRING_16(port, addr, len) \
{                                                                    \
	if (len < 100 || (port != TpiMac.Hw->PortOffset + HREG_DATA_0 && \
					  port != TpiMac.Hw->PortOffset + HREG_DATA_1)){ \
		NdisRawWritePortBufferUshort(port, addr, (len));             \
	}                                                                \
	else {															 \
        ooiOutPortString(port, (PUSHORT)addr, len);					 \
    }                                                                \
}

#else // !BUSMASTER

#define IN_PORT_STRING_32(port, addr, len)		{									\
	NdisRawReadPortBufferUlong(port, addr, (len)/2);							\
	NdisRawReadPortBufferUshort(port, (addr) + (len&0xFFFE)*2, (len)&1);		\
}
#define OUT_PORT_STRING_32(port, addr, len)	{									\
	NdisRawWritePortBufferUlong(port, addr, (len)/2);							\
	NdisRawWritePortBufferUshort(port, (addr) + (len&0xFFFE)*2, (len)&1);		\
}
#define IN_PORT_STRING_16(port, addr, len)		NdisRawReadPortBufferUshort(port, addr, (len));
#define OUT_PORT_STRING_16(port, addr, len)	NdisRawWritePortBufferUshort(port, addr, (len));

#endif // BUSMASTER

#endif //  _APIDLL / WVLAN_51 / _WIN32_WCE

#if defined _WIN32_WCE
extern hcf_8  IN_PORT_BYTE(hcf_32 port);
extern void   OUT_PORT_BYTE(hcf_32 port, hcf_8 value);
extern hcf_16 IN_PORT_WORD(hcf_32 port);
extern void   OUT_PORT_WORD(hcf_32 port, hcf_16 value);
extern void   IN_PORT_STRING(hcf_32 port, void *dest, hcf_16 len);
extern void   OUT_PORT_STRING(hcf_32 port, void *addr, hcf_16 len);
#endif

#ifdef WVLAN_51
// Added for building a USB driver in the HCF
#define _WVLAN_USB
#endif // WVLAN_51

#if defined _DEBUG || (defined DBG && DBG != 0)
#define HCF_ASSERT                  0xC001
#endif // _DEBUG || DBG

#if defined DEBUG || defined _DEBUG || (defined DBG && DBG != 0)
#ifdef _WIN32_WCE
#define DBGA2W(DBGSTR)	CeConvertAnsiToUnicodeLen(szDbgConvertBuffer, DBGSTR,  256)
#define OUTPUTDEBUGMSG(dprintf_exp)					ce_debug_msg dprintf_exp // (void)(DEBUGMSG(ZONE_INIT, dprintf_exp)) //((void) (DbgPrint dprintf_exp))
#define ASSERTDEBUGMSG(cond, dprintf_exp)			cond ? 0:ce_debug_msg dprintf_exp
#else // !(_WIN32_WCE)
#define OUTPUTDEBUGMSG(dprintf_exp)					((void) (DbgPrint dprintf_exp))
// the assertdebugmsg macro will print filename, line followed by a caller-defined text, when cond == 0
#define ASSERTDEBUGMSG(cond, dprintf_exp)	((void)((cond) ? 0: (DbgPrint("%s:%d - ", __FILE__, __LINE__), DbgPrint dprintf_exp)))
#endif // _WIN32_WCE
#ifndef DBGA2W
#define DBGA2W
#endif	// DBGA2W

#else // !(defined DEBUG || defined _DEBUG || (defined DBG && DBG != 0) )
#define OUTPUTDEBUGMSG(dprintf_exp)
#define ASSERTDEBUGMSG(cond, dprintf_exp)
#endif // DEBUG / DBG

#if (( (HCF_TYPE) & HCF_TYPE_HII ) && ((HCF_TYPE) & HCF_TYPE_USB ) )
// predefines
struct _UHS_LIBCOMMON;
typedef struct _UHS_LIBCOMMON UHS_LIBCOMMON;
typedef struct _UHS_LIBCOMMON *PUHS_LIBCOMMON;


#define HCF_USB_RID_IFS_TIMEOUT_MSEC 900	// 500
#define HCF_USB_SOLLICITED_TIMEOUT_MSEC 900	// 500
#define HCF_USB_ACTION_TIMEOUT_MSEC 900	// 500
#define HCF_USB_PROGRAM_TIMEOUT_MSEC 900	// 500

#endif // HCF_TYPE_HII / HCF_TYPE_USB

#endif //WVLAN_41 / WVLAN_48 / WVLAN_51 / WVLAN_52 / _WIN32_WCE


/************************************************************************************************/
/****************************  P A C K E T   D R I V E R  ***************************************/
/**********************************  D O S   O D I  *********************************************/
/************************************************************************************************/

#if defined WVLAN_42 || defined WVLAN_43
#define HCF_PROT_TIME				49	//49*10240 microseconds H/W failure protection timer
//#define HCF_PROT_TIME		0 		// number of 2**n times 10K microseconds protection timer against H/W malfunction
//#define HCF_DDS 1
#if 0 //!!temporarily to determine sizes
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To ease testing the different options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//#define HCF_TYPE HCF_TYPE_WPA						 // Hermes-I F/W with SSN support
//#define HCF_TYPE HCF_TYPE_USB						 // Host side internally developed USB Dongle driver
#define HCF_TYPE (HCF_TYPE_HII | HCF_TYPE_PRELOADED) // Hermes-II
#undef HCF_TYPE										 // Hermes-I Station F/W without SSN support
#endif // temporarily

//#define HCF_ASSERT		0x0002			//assert (also) via S/W Supp Register
//#define HCF_ASSERT		0x0004			//assert (also) in Mailbox
//#define HCF_ASSERT		0x4000			//support dynamic linking of msf_assert routine
//#define HCF_ASSERT		0x8000			//link msf_assert routine statically

//#define HCF_ENCAPSULATION 0
//#define HCF_MB_ON			0
//#define HCF_INT_ON		0
//#define HCF_EX_INT (HCF_EX_INT_TX_EX|HCF_EX_INT_TX_OK)	//log transmissions in Mailbox
//#define HCF_DLNV
//#define HCF_DLV
//#define HCF_ALIGN			2
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To ease testing the different options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#pragma warning ( disable: 4001 )

#define HCF_DEEPSLEEP				1
#if defined HCF_DEEPSLEEP
#define MSF_WAIT( n )  /*NOP*/;				// MSF-defined function to wait n microseconds.
#endif // HCF_DEEPSLEEP

#if defined WVLAN_43
#define	MSF_COMPONENT_ID			COMP_ID_ODI_16	///;?it might be a good idea to test without this but that
													//   conflicts with current DUI_TST setup
#define	MSF_COMPONENT_VAR			1
#define	MSF_COMPONENT_MAJOR_VER		6
#define	MSF_COMPONENT_MINOR_VER		10

#define BASED __based(__segname("_CODE"))	/* Packet driver can live without BASED
											 * Apparently due to its diffrent segment setup
											 * If you want to investigate, check CGROUP and DGROUP
											 * definitions in 42 and 43
											 */

#elif defined WVLAN_42
#define	MSF_COMPONENT_ID			COMP_ID_PACKET
#define	MSF_COMPONENT_VAR			1
#define	MSF_COMPONENT_MAJOR_VER		6
#define	MSF_COMPONENT_MINOR_VER		12

#define BASED __based(__segname("_CODE"))	/* Apparently Packet driver can not live either without BASED
											 * although accocrding to its map-file, everything ends
											 * up in a single segment
											 */

#endif //WVLAN_43 / WVLAN_42

#define FAR  __far					// segmented 16 bits mode

#ifndef H_2_INC
#include <stdio.h>
#include <conio.h>
#ifndef _DEBUG
#pragma intrinsic( _inp, _inpw, _outp, _outpw )
#endif // _DEBUG

#define IN_PORT_WORD(port)			((hcf_16)_inpw( (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)	((void)_outpw( (hcf_io)(port), value ))

#if 1		// C implementation which let the processor handle the word-at-byte-boundary problem
#define IN_PORT_STRING_16( prt, addr, n)	while ( n-- ) { *(hcf_16 FAR*)addr = IN_PORT_WORD( prt ); addr += 2; }
#define OUT_PORT_STRING_16( prt, addr, n)	while ( n-- ) { OUT_PORT_WORD( prt, *(hcf_16 FAR*)addr ) ; addr  += 2; }
//#elif 0		// C implementation which handles the word-at-byte-boundary problem
//#define IN_PORT_STRING_16( prt, addr, n)	while ( n-- ) { int i = IN_PORT_WORD( prt ); *addr++ = (char)i; *addr++ = (char)(i >> 8); }
//#define OUT_PORT_STRING_16( prt, addr, n)	while ( n-- ) { OUT_PORT_WORD( prt, *addr | *(addr+1)<<8  ) ; addr  += 2; }
////;?  WHY hcf_16 FAR*)addr and not unsigned char FAR*)addr
#else		// Assembler implementation
#define IN_PORT_STRING_16( port, addr, n) __asm		\
{													\
	__asm push di									\
	__asm push es									\
	__asm mov cx,n									\
	__asm les di,addr								\
	__asm mov dx,port								\
	__asm rep insw									\
	__asm pop es									\
	__asm pop di									\
}

#define OUT_PORT_STRING_16( port, addr, n) __asm	\
{													\
	__asm push si									\
	__asm push ds									\
	__asm mov cx,n									\
	__asm lds si,addr								\
	__asm mov dx,port								\
	__asm rep outsw									\
	__asm pop ds									\
	__asm pop si									\
}

#endif	// Asm or C implementation
#endif // H_2_INC

#endif	// WVLAN_42 / WVLAN_43



/************************************************************************************************/
/****************************  D O S  H - I / II  L O A D E R  **********************************/
/************************************************************************************************/

#if defined H0_LDR || defined H1_LDR || defined H2_LDR

#if defined H0_LDR
#define HCF_DLV		0
#define HCF_DLNV	1
#endif // H0_LDR

#if defined H1_LDR || defined H2_LDR
#define HCF_DLV		1
#define HCF_DLNV	0
#endif // H1_LDR / H2_LDR

#define HCF_ASSERT			0x8002	//link msf_assert routine statically and assert via S/W Supp Register
//#define HCF_ASSERT		0x4000	//support dynamic linking of msf_assert routine

#define HCF_ENCAPSULATION	0
#define HCF_MB_ON			0
#define HCF_INT_ON			0
#define HCF_TALLIES			0

#define	MSF_COMPONENT_ID			COMP_ID_ODI_16 //;?By lack of any better
#define	MSF_COMPONENT_VAR			1
#define	MSF_COMPONENT_MAJOR_VER		0
#define	MSF_COMPONENT_MINOR_VER		0

#define FAR
#define BASED

#include <stdio.h>
#include <conio.h>
#if defined NDEBUG
#pragma intrinsic( _inp, _inpw, _outp, _outpw )
#endif // NDEBUG

#if 0						//use 0 to replace I/O Macros with logging facility
#define IN_PORT_WORD(port)			((hcf_16)_inpw( (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)	((void)_outpw( (hcf_io)(port), value ))
#define IN_PORT_STRING_16( port, addr, n)	while ( n-- ) { *(hcf_16 FAR*)addr = IN_PORT_WORD( port ); (cast)addr += 2; }
#define OUT_PORT_STRING_16( port, addr, n)	while ( n-- ) { OUT_PORT_WORD( port, *(hcf_16 FAR*)addr ) ; (cast)addr  += 2; }
#endif						//use 0 to replace I/O Macros with logging facility

#endif	// H0_LDR / H1_LDR / H2_LDR



/************************************************************************************************/
/****************************  H C F  D E M O  P R O G R A M  ***********************************/
/************************************************************************************************/

#if defined HCF_DEMO

#define HCF_DLV		1				//;?should become the default !defaults to 1 anyway for H-II
//#define HCF_DLNV	0				//defaults to 0 anyway for H-II

#define HCF_ASSERT	0x4000			//support dynamic linking of msf_assert routine

#define HCF_ENCAPSULATION	0
#define HCF_MB_ON			0
#define HCF_INT_ON			0
#define HCF_TALLIES			3

//#define	MSF_COMPONENT_ID		NO configuration management

#define FAR
#define BASED

#include <stdio.h>
#include <conio.h>
#if defined NDEBUG
#pragma intrinsic( _inp, _inpw, _outp, _outpw )
#endif // NDEBUG

#if 0						//use 0 to replace I/O Macros with logging facility
#define IN_PORT_WORD(port)			((hcf_16)_inpw( (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)	((void)_outpw( (hcf_io)(port), value ))
#define IN_PORT_STRING_16( port, addr, n)	while ( n-- ) { *(hcf_16 FAR*)addr = IN_PORT_WORD( port ); (cast)addr += 2; }
#define OUT_PORT_STRING_16( port, addr, n)	while ( n-- ) { OUT_PORT_WORD( port, *(hcf_16 FAR*)addr ) ; (cast)addr  += 2; }
#endif						//use 0 to replace I/O Macros with logging facility

#endif	// HCF_DEMO



/************************************************************************************************/
/***********************************  M A C  O S   **********************************************/
/************************************************************************************************/

#if defined WVLAN_45

#include "Version.h"

#define MSF_COMPONENT_ID            COMP_ID_MAC_OS
#define MSF_COMPONENT_VAR           VARIANT
#define MSF_COMPONENT_MAJOR_VER     VERSION_MAJOR
#define MSF_COMPONENT_MINOR_VER     VERSION_MINOR

#define MAC_OS                      1

#define HCF_BIG_ENDIAN 1             // selects Big Endian (a.k.a. Motorola), most significant byte first

#if defined DEBUG
#define HCF_ASSERT	4
#endif // DEBUG

#ifdef  __cplusplus
extern "C" {
#endif // __cplusplus
extern volatile unsigned char *MacIOaddr;
extern hcf_16 IN_PORT_WORD(hcf_16 port);
extern void   OUT_PORT_WORD(hcf_16 port, hcf_16 value);
extern void   IN_PORT_STRING_16(hcf_16 port, void *addr, hcf_16 len);
extern void   OUT_PORT_STRING_16(hcf_16 port, void *addr, hcf_16 len);

#define SwapBytes(t)    (((t) >> 8) + (((t) & 0xff) << 8))

#ifdef  __cplusplus
}
#endif // __cplusplus

#endif  // WVLAN_45



/************************************************************************************************/
/******************************************  L I N U X  *****************************************/
/************************************************************************************************/

#if defined WVLAN_47 || defined WVLAN_49

#include <asm/io.h>
#include <linux/module.h>
#include <wireless/wl_version.h>

/* The following macro ensures that no symbols are exported, minimizing the chance of a symbol
   collision in the kernel */
EXPORT_NO_SYMBOLS;


/* The Linux MSF still uses HCF_TYPE_STA; define it here until it's removed */
#ifndef HCF_TYPE_STA
#define HCF_TYPE_STA 0x0020
#endif  // HCF_TYPE_STA


// NEW - DO I NEED THESE DEFINITIONS? TAKEN FROM THE NDIS 5.0 SECTION
#define HCF_DLV 1

#ifdef HERMES2
#if _BLDTYPE == 64
#define _WARP
#define support_32bits 1
#endif // _BLDTYPE == 64
#endif // HERMES2

#if _BLDTYPE == 16
#define _CCX
#define _NEW_SCAN
#define _WPA
#endif // _BLDTYPE == 16

#define HCF_INTERFACE_CONNECT(ifbp)
#define HCF_INTERFACE_DISCONNECT(ifbp)
#define HCF_ENTER_INTERFACE_FUNCT(ibfb)
#define HCF_LEAVE_INTERFACE_FUNCT(ifbp)

// NEW - END


/* The following sets the Hermes Type, as well as STA/AP functionality that will be included */

#if defined STA_ONLY && defined AP_ONLY
#error 	Cannot have STA_ONLY and AP_ONLY defined simultaneously!!!
#endif

#ifdef HERMES2

#if defined STA_ONLY
#if defined USE_WPA
#define HCF_TYPE    (HCF_TYPE_STA|HCF_TYPE_SSN|HCF_TYPE_HII)
#else
#define HCF_TYPE    (HCF_TYPE_STA|HCF_TYPE_HII)
#endif  // USE_WPA

#if defined USE_WDS
#error WDS is not supported in STA only builds!!!
#endif  /* USE_WDS */

#elif defined AP_ONLY
#if defined USE_WPA
#define HCF_TYPE    (HCF_TYPE_AP|HCF_TYPE_SSN|HCF_TYPE_HII)
#else
#define HCF_TYPE    (HCF_TYPE_AP|HCF_TYPE_HII)
#endif  // USE_WPA
#else
#if defined USE_WPA
#define HCF_TYPE    (HCF_TYPE_STA|HCF_TYPE_AP|HCF_TYPE_SSN|HCF_TYPE_HII)
#else
#define HCF_TYPE    (HCF_TYPE_STA|HCF_TYPE_AP|HCF_TYPE_HII)
#endif  // USE_WPA
#endif  // STA-AP_ONLY

#else

#ifdef USE_RTS
#error RTS mode only supported for Hermes-II !!!
#endif  /* USE_RTS */

/* NOTE: For Hermes-I, HCF_TYPE_SSN must be defined */
#if defined STA_ONLY
#define HCF_TYPE    (HCF_TYPE_STA|HCF_TYPE_SSN)

#if defined USE_WDS
#error WDS is not supported in STA only builds!!!
#endif  /* USE_WDS */

#elif defined AP_ONLY
#define HCF_TYPE    (HCF_TYPE_AP|HCF_TYPE_SSN)
#else
#define HCF_TYPE    (HCF_TYPE_NONE|HCF_TYPE_AP|HCF_TYPE_STA|HCF_TYPE_SSN)
#endif // STA-AP_ONLY

/* Define the following to workaround a potential data corruption issue with H1 */
#define HCMD_DCP_WORKAROUND_H1

#endif // HERMES2

/* The following sets the component ID, as well as the versioning. See also wl_version.h */
#if defined WVLAN_47
#define	MSF_COMPONENT_ID	COMP_ID_LINUX_PD
#endif // WVLAN_47

#if defined WVLAN_49
#define	MSF_COMPONENT_ID	COMP_ID_LINUX_LIB
#endif // WVLAN_49

#define	MSF_COMPONENT_VAR			DRV_VARIANT
#define MSF_COMPONENT_MAJOR_VER     DRV_MAJOR_VERSION
#define MSF_COMPONENT_MINOR_VER     DRV_MINOR_VERSION


/* Define the following to turn on assertions in the HCF */
//#define HCF_ASSERT  0x8000

#ifdef USE_BIG_ENDIAN
#define HCF_BIG_ENDIAN
#endif  /* USE_BIG_ENDIAN */

/* Define the following if your system uses memory-mapped IO */
//#define HCF_MEM_IO

/* The following defines the standard macros required by the HCF to move data to/from the card */
#define IN_PORT_BYTE(port)			((hcf_8)inb( (hcf_io)(port) ))
#define IN_PORT_WORD(port)			((hcf_16)inw( (hcf_io)(port) ))
#define OUT_PORT_BYTE(port, value)	(outb( (hcf_8) (value), (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)	(outw((hcf_16) (value), (hcf_io)(port) ))

#define IN_PORT_STRING_16(port, dst, n)    insw((hcf_io)(port), dst, n)
#define OUT_PORT_STRING_16(port, src, n)   outsw((hcf_io)(port), src, n)
#define IN_PORT_STRINGL(port, dst, n)   insl((port), (dst), (n))
#define OUT_PORT_STRINGL(port, src, n)  outsl((port), (src), (n))
#define IN_PORT_HCF32(port)          inl( (hcf_io)(port) )
#define OUT_PORT_HCF32(port, value)  outl((hcf_32)(value), (hcf_io)(port) )


#ifndef OUTPUTDEBUGMSG
#define OUTPUTDEBUGMSG(dprintf_exp)
#endif 


#ifndef ASSERTDEBUGMSG
#define ASSERTDEBUGMSG(cond, dprintf_exp)
#endif 

#ifndef CFG_SCAN_CHANNELS_2GHZ
#define CFG_SCAN_CHANNELS_2GHZ 0xFCC2
#endif /* CFG_SCAN_CHANNELS_2GHZ */

#endif	/* LINUX */



/************************************************************************************************/
/*********************************************  Q N X  ******************************************/
/************************************************************************************************/

#if defined  __QNX__ || defined WVLAN_50

#define MSF_COMPONENT_ID		0   //Although there is no DUI support, we need this to get ...
#define MSF_COMPONENT_VAR		0	//...compatibilty check to function
#define MSF_COMPONENT_MAJOR_VER	0	//...;?this is worth looking into to make this a more
#define MSF_COMPONENT_MINOR_VER	0	//..."defined" I/F so OEMers can figure out what to do

#include <conio.h>

#define IN_PORT_WORD(port)			((hcf_16)inpw( (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)	(outpw( (hcf_io)(port), (hcf_16) (value) ))
//#define IN_PORT_STRING_16( prt, addr, n)	while ( n-- ) { *(hcf_16*)addr = IN_PORT_WORD( prt ); addr += 2; }
//#define OUT_PORT_STRING_16( prt, addr, n)	while ( n-- ) { OUT_PORT_WORD( prt, *(hcf_16*)addr ) ; addr  += 2; }

#endif	// QNX / WVLAN_50



/************************************************************************************************/
/*********************************************  B E O S  ****************************************/
/************************************************************************************************/

#if defined  __BEOS__

#define MSF_COMPONENT_ID		0   //Although there is no DUI support, we need this to get ...
#define MSF_COMPONENT_VAR		0	//...compatibilty check to function
#define MSF_COMPONENT_MAJOR_VER	0	//...;?this is worth looking into to make this a more
#define MSF_COMPONENT_MINOR_VER	0	//..."defined" I/F so OEMers can figure out what to do

#include <drivers/Drivers.h>
#include <drivers/KernelExport.h>

uint8 read_io_8 (int);
void write_io_8 (int, uint8);
uint16 read_io_16 (int);
void write_io_16 (int, uint16);

#define IN_PORT_WORD(port)			((hcf_16)read_io_16( (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)	(write_io_16( (hcf_io)(port), (hcf_16) (value) ))
//#define OUT_PORT_WORD(port, value)	dprintf( "OPW %04x %04x", port, value)//(write_io_16( (hcf_io)(port), (hcf_16) (value) ))
//#define IN_PORT_STRING_16( prt, addr, n)	while ( n-- ) { *(hcf_16*)addr = IN_PORT_WORD( prt ); addr += 2; }
//#define OUT_PORT_STRING_16( prt, addr, n)	while ( n-- ) { OUT_PORT_WORD( prt, *(hcf_16*)addr ) ; addr  += 2; }

#endif	// __BEOS__



/************************************************************************************************/
/********************************  U S B   D O N G L E  *****************************************/
/************************************************************************************************/

#if defined USB
#include "gpif.h"

#define	MSF_COMPONENT_MAJOR_VER		0
#define	MSF_COMPONENT_MINOR_VER		1

#define IN_PORT_WORD(port)			(Hermes_IO_Read( (hcf_8)(port)))
#define OUT_PORT_WORD(port, value)	(Hermes_IO_Write( (hcf_8)port, /*(hcf_16)*/(value) ) )
/* !!!! NOTE USB supports only 16-bits I/O and no 8-bits I/O
 * as a consequence the IN_/OUT_PORT_STRING_16 macros use hcf_16* rather than hcf_8 pointers
 * to get more optimal code
 * therefore the pointers are incremented by 1 (which means two "bytes") rather than by 2
 */
#define IN_PORT_STRING_16( prt, addr, n)	while ( n-- ) { *addr++ = IN_PORT_WORD( prt ); }
#define OUT_PORT_STRING_16( prt, addr, n)	while ( n-- ) { OUT_PORT_WORD( prt, *addr++ ); }

#define HCF_TYPE	HCF_TYPE_AP | HCF_TYPE_WPA

#define HCF_EX_INT  0

#endif	// USB



/************************************************************************************************/
/******************************************  FreeBSD  *******************************************/
/************************************************************************************************/

#if defined __FREE_BSD__

#define	MSF_COMPONENT_ID			COMP_ID_FreeBSD
#define	MSF_COMPONENT_VAR			1
#define	MSF_COMPONENT_MAJOR_VER		1
#define	MSF_COMPONENT_MINOR_VER		0

#define HCF_MAX_MSG					2048			// overrule standard WaveLAN Packet Size of 1514 with 2048
#define HCF_MEM_IO					1				// overrule standard Port I/O with Memory mapped I/O

#include <machine/cpufunc.h>

#define IN_PORT_WORD(port)			((hcf_16)inw( (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)	(outw((hcf_io)(port), (hcf_16)(value)))

//#define IN_PORT_STRING_16( prt, addr, n)	while ( n-- ) { *(hcf_16*)addr = IN_PORT_WORD( prt ); addr += 2; }
//#define OUT_PORT_STRING_16( prt, addr, n)	while ( n-- ) { OUT_PORT_WORD( prt, *(hcf_16*)addr ) ; addr  += 2; }

#endif	// __FREE_BSD__



/************************************************************************************************/
/*********************************  W A V E P O I N T  ******************************************/
/************************************************************************************************/

#if defined WVLAN_81	/* BORLANDC */

#define EXTERN_C  extern	// needed because DHF uses this instead of 'extern'

#define	MSF_COMPONENT_ID	COMP_ID_AP1
#define	MSF_COMPONENT_VAR			1
#define	MSF_COMPONENT_MAJOR_VER		4
#define	MSF_COMPONENT_MINOR_VER		0

#define HCF_PROT_TIME				49	//49*10240 microseconds H/W failure protection timer

//#define HCF_ASSERT					4  /* debug build only */

#if !defined FAR
#define FAR  far						// segmented 16 bits mode
#endif // FAR

#define IN_PORT_WORD(port)					(inport( (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)			(outport( (hcf_io)(port), value ))

#define IN_PORT_STRING_16(port, addr, len)	\
	asm { push di; push es; mov cx,len; les di,addr; mov dx,port; rep insw; pop es; pop di }

#define OUT_PORT_STRING_16(port, addr, len)	\
	asm { push si; push ds; mov cx,len; lds si,addr; mov dx,port; rep outsw; pop ds; pop si }

#endif // WVLAN_81


/************************************************************************************************/
/********************************  W A V E L A U N C H  *****************************************/
/************************************************************************************************/

#if defined WVLAUNCH

#include "DriverX.h"
extern HWDEVICE*	g_pDevice;

//#define	MSF_COMPONENT_ID			0  //;? to get around browser problem

#define IN_PORT_WORD(port)	HwInpw( g_pDevice, port )
#define OUT_PORT_WORD(port, value)	HwOutpw( g_pDevice, port, value )


// C implementation which let the processor handle the word-at-byte-boundary problem
//#define IN_PORT_STRING_16( prt, addr, n)	while ( n-- ) { *(hcf_16 FAR*)addr = IN_PORT_WORD( prt ); addr += 2; }
//#define OUT_PORT_STRING_16( prt, addr, n)	while ( n-- ) { OUT_PORT_WORD( prt, *(hcf_16 FAR*)addr ) ; addr  += 2; }

#endif //WVLAUNCH



/************************************************************************************************/
/*************************************  W C I T S T *********************************************/
/************************************************************************************************/

#if defined WCITST
#define MSF_COMPONENT_ID		0   //Although there is no DUI support, we need this to get ...
#define MSF_COMPONENT_VAR		0	//...compatibilty check to function
#define MSF_COMPONENT_MAJOR_VER	0	//...;?this is worth looking into to make this a more
#define MSF_COMPONENT_MINOR_VER	0	//..."defined" I/F so OEMers can figure out what to do

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To ease testing the different options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//#define	HCF_TYPE HCF_TYPE_AP
//#undef HCF_TYPE					// Hermes-I Station F/W without SSN support
//#define HCF_TYPE  HCF_TYPE_WPA		// Hermes-I F/W with SSN support
#define HCF_TYPE (HCF_TYPE_WPA | HCF_TYPE_PRELOADED) // Hermes-I
//#define HCF_ALIGN 2
#define HCF_EX_INT (HCF_EX_INT_TX_EX | HCF_EX_INT_TX_OK)	//log transmissions in Mailbox
#define HCF_DLV		1			//just to change memory layout ????;?
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To ease testing the different options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#pragma warning ( disable: 4001 )


//#define HCF_ASSERT                  2	//assert (also) via S/W Supp Register
#define HCF_ASSERT                  4	//assert (also) in Mailbox

//#define HCF_MB_ON 0

#define FAR  __far					// segmented 16 bits mode
//#define BASED __based(__segname("_CODE"))

#include <stdio.h>
#include <conio.h>
#ifndef _DEBUG
#pragma intrinsic( _inp, _inpw, _outp, _outpw )
#endif // _DEBUG

#ifdef LOG
extern FILE* utm_logfile;
hcf_16	ipw( hcf_16 port );
hcf_8	ipb( hcf_16 port );
void	opw( hcf_16 port, hcf_16 value );
void	opb( hcf_16 port, hcf_8 value );

#define IN_PORT_WORD(port)			ipw( (hcf_io)(port) )
#define OUT_PORT_WORD(port, value)	opw( (hcf_io)(port), (hcf_16)(value) )
#else //LOG
#define IN_PORT_WORD(port)			((hcf_16)_inpw( (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)	((void)_outpw( (hcf_io)(port), value ))
#endif //LOG

#define	toch_maar_geen_asm
#ifdef toch_maar_asm
#define IN_PORT_STRING_16( port, addr, len) __asm		\
{													\
	__asm push di									\
	__asm push es									\
	__asm mov cx,len								\
	__asm les di,addr									\
	__asm mov dx,port								\
	__asm rep insw									\
	__asm pop es									\
	__asm pop di									\
}

#define OUT_PORT_STRING_16( port, addr, len) __asm		\
{													\
	__asm push si									\
	__asm push ds									\
	__asm mov cx,len								\
	__asm lds si,addr								\
	__asm mov dx,port								\
	__asm rep outsw									\
	__asm pop ds									\
	__asm pop si									\
}

#else	//toch_maar_asm
#define IN_PORT_STRING_16( prt, addr, n)  while (n--) { *(hcf_16 FAR*)addr = IN_PORT_WORD( prt ); addr += 2/*1*/; }
#define OUT_PORT_STRING_16( prt, addr, n) while (n--) { OUT_PORT_WORD( prt, *(hcf_16 FAR*)addr ) ; addr  += 2/*1*/; }
#endif	//toch_maar_asm

#endif	// WCITST



/************************************************************************************************/
/*******************************  Motorola Power PC 800 family  *********************************/
/************************************************************************************************/
/* known users: LH@I
 */

#if defined I_MPC8XX

#define	HCF_TYPE HCF_TYPE_AP //AccesPoint characteristics
#define MSF_COMPONENT_VAR		0
#define MSF_COMPONENT_ID		0
#define MSF_COMPONENT_MAJOR_VER	1
#define MSF_COMPONENT_MINOR_VER	0

#define HCF_HSI_VAR				1

#define HCF_BIG_ENDIAN			1
#define HCF_MEM_IO				1

#include "o_portbl.h"
#include "ipcmcia.h"
typedef o_uint8_t  hcf_8;
typedef o_uint16_t hcf_16;
typedef o_uint32_t hcf_32;

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


#ifdef _lint
#else
asm hcf_16 IN_PORT_WORD(int port)
{
% reg port
    lhbrx r3,r0,port
    eieio
}
#endif // _lint


#ifdef _lint
#else
asm void OUT_PORT_WORD(int port, hcf_16 value)
{
% reg port, value
    sthbrx value,r0,port
    eieio
}
#endif // _lint

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

#define IN_PORT_STRING_16(port, addr, len)               \
   {                                                  \
      unsigned l = (len);                             \
      hcf_16 *d = (volatile hcf_16 *)(addr);          \
      while (l--)                                     \
      {                                               \
         *d++ = *(volatile hcf_16 *)(port);           \
         EIEIO();                                     \
      }                                               \
   }

#define OUT_PORT_STRING_16(port, addr, len)               \
   {                                                  \
      unsigned l = (len);                             \
      hcf_16 *s = (volatile hcf_16 *)(addr);           \
      while (l--)                                     \
      {                                               \
         *(volatile hcf_16 *)(port) = *s++;           \
         EIEIO();                                     \
      }                                               \
   }

#endif	// I_MPC8XX



/************************************************************************************************/
/**********************************   Diab or High C 29K   **************************************/
/************************************************************************************************/
/* known users: GK@C
 */

#if defined _AM29K

#define	HCF_TYPE HCF_TYPE_AP /*AccesPoint characteristics */
#define MSF_COMPONENT_VAR		0
#define MSF_COMPONENT_ID		COMP_ID_AP1
#define MSF_COMPONENT_MAJOR_VER	1
#define MSF_COMPONENT_MINOR_VER	0

#define HCF_BIG_ENDIAN			1
#define HCF_MEM_IO				1

#define SwapBytes(t)    /*lint -e572*/(((t) >> 8) + (((t) & 0xff) << 8))/*lint +e572*/

#if defined __ppc
    #ifndef __GNUC__
        #define __asm__     asm
    #endif

    #if ! defined _lint
        #define EIEIO()     __asm__(" eieio")
    #else
        #define EIEIO()
    #endif

    static hcf_16 IN_PORT_WORD(int port) {
        hcf_16 value = *(volatile hcf_16 *)(port); EIEIO();
        value = SwapBytes(value);
        return value;
    }

    #define OUT_PORT_WORD(port, value)      \
            { *(volatile hcf_16 *)(port) = SwapBytes(value); EIEIO(); }
#else
    #define IN_PORT_WORD(port) (*(volatile hcf_16 *)(port))
    #define OUT_PORT_WORD(port, value) (*(volatile hcf_16 *)(port) = (value))
#endif // __ppc

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

#define IN_PORT_STRING_16( port, addr, len)        {                       \
                        unsigned l = (len);                             \
                        hcf_16 t, *d = (volatile hcf_16 *)(addr);       \
                        while (l--) {                                   \
                            t = IN_PORT_WORD(port);                     \
                            *d++ = SwapBytes(t);                        \
                        }                                               \
                                                }

#define OUT_PORT_STRING_16( port, addr, len)        {                       \
                        unsigned l = (len);                             \
                        hcf_16 t, *s = (volatile hcf_16 *)(addr);        \
                        while (l--) {                                   \
                            t = *s++;                                   \
                            OUT_PORT_WORD(port, SwapBytes(t));          \
                        }                                               \
                                                }

#if PRODUCT == 9150
#define	HCF_TYPE HCF_TYPE_AP
    #define HCF_ASSERT	4
    #undef MSF_COMPONENT_ID
#endif // HCF_TYPE_AP

#endif	// _AM29K



/************************************************************************************************/
/*****************************************  MPC860 **********************************************/
/************************************************************************************************/
/* known users: RR
 */

#if defined CPU
#if CPU == PPC860

#define	HCF_TYPE HCF_TYPE_AP	//AccesPoint characteristics
#define MSF_COMPONENT_VAR		0
#define MSF_COMPONENT_ID		0
#define MSF_COMPONENT_MAJOR_VER	1
#define MSF_COMPONENT_MINOR_VER	0

#define HCF_BIG_ENDIAN			1
#define HCF_MEM_IO				1

#define SwapBytes(t)    /*lint -e572*/(((t) >> 8) + (((t) & 0xff) << 8))/*lint +e572*/

#ifndef __GNUC__
    #define __asm__     asm
#endif

#if ! defined _lint
    #define EIEIO()     __asm__(" eieio")
#else
    #define EIEIO()
#endif

static hcf_16 IN_PORT_WORD(int port) {
    hcf_16 value = *(volatile hcf_16 *)(port); EIEIO();
    value = SwapBytes(value);
    return value;
    #ifdef __GNUC__
        /* the following serves to avoid the compiler warnings that
         * IN_PORT_WORD() is not used in some files */
        (void)IN_PORT_WORD;
    #endif
}

#define OUT_PORT_WORD(port, value)      \
        { *(volatile hcf_16 *)(port) = SwapBytes(value); EIEIO(); }

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

#define IN_PORT_STRING_16( port, addr, len)        {                       \
                        unsigned l = (len);                             \
                        hcf_16 t;                                       \
                        volatile hcf_16 *d = (volatile hcf_16 *)(addr); \
                        while (l--) {                                   \
                            t = IN_PORT_WORD(port);                     \
                            *d++ = SwapBytes(t);                        \
                        }                                               \
                                                }

#define OUT_PORT_STRING_16( port, addr, len)        {                       \
                        unsigned l = (len);                             \
                        hcf_16 t;                                       \
                        volatile hcf_16 *s = (volatile hcf_16 *)(addr);  \
                        while (l--) {                                   \
                            t = *s++;                                   \
                            OUT_PORT_WORD(port, SwapBytes(t));          \
                        }                                               \
                                                }

#if PRODUCT == 9150
//?    #define	HCF_TYPE HCF_TYPE_AP
    #define HCF_ASSERT	4
    #undef MSF_COMPONENT_ID
#endif

#endif	/* PPC860 */
#endif	/* CPU */



/************************************************************************************************/
/****************************  Microtec Research 80X86 Compiler *********************************/
/************************************************************************************************/

#if 0

//#undef HCF_TYPE									// Hermes-I Station F/W without SSN support

#define MSF_COMPONENT_VAR       0
#define MSF_COMPONENT_ID        0
#define MSF_COMPONENT_MAJOR_VER 1
#define MSF_COMPONENT_MINOR_VER 0

extern int far inp( int );
extern void far outp( int, int );
extern int far inpw( int );
extern void far outpw( int, int );

#define IN_PORT_WORD(port)		((hcf_16)inpw( (hcf_io)(port) ))
#define OUT_PORT_WORD(port, value)	((void)outpw( (hcf_io)(port), value ))

#define IN_PORT_STRING_16( port, addr, len)        {                       \
                        unsigned l = (len);                             \
                        hcf_16 *d = (hcf_16 *)(addr);                   \
                        while (l--) *d++ =  IN_PORT_WORD(port);         \
                                                }

#define OUT_PORT_STRING_16( port, addr, len)        {                       \
                        unsigned l = (len);                             \
                        hcf_16 *s = (hcf_16 *)(addr);                    \
                        while (l--) OUT_PORT_WORD(port, *s++);          \
                                                }
#endif	/* Microtec 80X86 C Compiler */



/************************************************************************************************/
/******************************  W A V E L A N  E C  ********************************************/
/************************************************************************************************/
/* known users: KM
 */

#ifdef mc68302

#define	MSF_COMPONENT_ID			COMP_ID_EC

#include <version.h>

#define	MSF_COMPONENT_VAR			1
#define	MSF_COMPONENT_MAJOR_VER		MAJOR_VERSION
#define	MSF_COMPONENT_MINOR_VER		MINOR_VERSION

#define HCF_BIG_ENDIAN				1
#define HCF_MEM_IO					1

#define SwapBytes(t)	/*lint -e572*/(((t) >> 8) + (((t) & 0xff) << 8))/*lint +e572*/

#define PCMCIA_ADDRESS 0xc80000UL

#define IN_PORT_2BYTES(port)			 (*(hcf_16 *)(port))
#if 0
static hcf_16 IN_PORT_WORD(hcf_32 port) // should be hcf_io, not hcf_32
{
  hcf_16 word = IN_PORT_2BYTES(port);
  return SwapBytes(word);
}
#else
static hcf_16 swap_var;
#define IN_PORT_WORD(port) \
  (((swap_var = IN_PORT_2BYTES(port)) >> 8) + (((swap_var) & 0xff) << 8))
#endif
#define OUT_PORT_2BYTES(port, value)	 (*(hcf_16 *)(port) = (hcf_16)(value))
#define OUT_PORT_WORD(port, value)		 OUT_PORT_2BYTES(port, SwapBytes(value))

//#define IN_PORT_STRING_16(port, dest, len)	  while ((len)--) {*(hcf_16 *)(dest) = IN_PORT_2BYTES(port); (dest) += 2; }
//#define OUT_PORT_STRING_16(port, addr, len)	  while ((len)--) {OUT_PORT_2BYTES((port), *(hcf_16 *)(addr)) ; (addr)  += 2; }

#endif	/* mc68302 */



/************************************************************************************************/
/*******************************************  NGAP **********************************************/
/************************************************************************************************/

#if defined __VX_WORKS__	/* VxWorks */

#if defined WLC_STATION
//#undef HCF_TYPE 				/* Hermes-I Station F/W without SSN support */
#define MSF_COMPONENT_ID	COMP_ID_VX_WORKS_ENDSTA
#else
#define	HCF_TYPE HCF_TYPE_AP	/* Access point characteristics */
#define MSF_COMPONENT_ID	COMP_ID_VX_WORKS_ENDAP
#endif	// WLC_STATION

#define HCF_YIELD (taskDelay(0) == 0)

#define    MSF_COMPONENT_VAR              1
#define    MSF_COMPONENT_MAJOR_VER        1
#define    MSF_COMPONENT_MINOR_VER        0

/* #define HCF_ASSERT            4   debug build only */

#if defined PC486BSP

#define IN_PORT_WORD(port)            (sysInWord ((hcf_io)(port)))
#define OUT_PORT_WORD(port, value)        (sysOutWord ((hcf_io)(port), (hcf_16) (value)))
#define IN_PORT_STRING_16(port, addr, n)        (sysInWordString ((hcf_io)(port), addr, n))
#define OUT_PORT_STRING_16(port, addr, n)        (sysOutWordString ((hcf_io)(port), addr, n))

#elif defined AS2000BSP

#define HCF_MEM_IO				1

/* Define PCI stuff here. */
unsigned short sysRead16( unsigned short *port );
void sysWrite16( unsigned short *port, unsigned short value );

#define PCI_IN_BYTE( port ) \
	*(unsigned char *)( port )

#define PCI_IN_WORD( port ) \
	sysRead16( (unsigned short *)( port ) )

#define PCI_OUT_BYTE( port, value ) \
	*(unsigned char *)( port ) = (unsigned char)( value )

#define PCI_OUT_WORD( port, value ) \
	sysWrite16( (unsigned short *)( port ), (unsigned short)( value ) )

#define IN_PORT_WORD( port ) \
	PCI_IN_WORD( port )

#define OUT_PORT_WORD( port, value ) \
	PCI_OUT_WORD( port, value )

#define IN_PORT_STRING_16( port, buf, len ) \
	do { \
		hcf_16 *p; \
	 \
	 	for ( p = (hcf_16 *)(buf); p < &( (hcf_16 *)(buf) )[ (int)len ]; p++ ) { \
			*p = PCI_IN_WORD( port ); \
		} \
	} while ( 0 )

#define OUT_PORT_STRING_16( port, buf, len ) \
	do { \
		const hcf_16 *p; \
	 \
	 	for ( p = (const hcf_16 *)( buf ); p < &( (const hcf_16 *)(buf) )[ (int)len ]; p++ ) { \
			PCI_OUT_WORD( port, *p ); \
		} \
	} while ( 0 )

#elif defined FADS860BSP /* elif defined AS2000BSP */

#define HCF_BIG_ENDIAN 1

#define HCF_MEM_IO				1

#ifndef __GNUC__
    #define __asm__     asm
#endif

#if ! defined _lint
    #define EIEIO()     __asm__(" eieio")
#else
    #define EIEIO()
#endif

static hcf_16 IN_PORT_WORD(int port) {
    hcf_16 value = *(volatile hcf_16 *)(port); EIEIO();
    value = ((value & 0xff00) >> 8) + ((value & 0x00ff) << 8);
/*  value = CNV_LITTLE_TO_INT(value); */
    return value;
    #ifdef __GNUC__
        /* the following serves to avoid the compiler warnings that
         * IN_PORT_WORD() is not used in some files */
        (void)IN_PORT_WORD;
    #endif
}

#define OUT_PORT_WORD(port, value)                                      \
        { *(volatile hcf_16 *)(port) = CNV_INT_TO_LITTLE(value); EIEIO(); }

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

#define IN_PORT_STRING_16( port, addr, len)        {                       \
                        unsigned l = (len);                             \
                        volatile hcf_16 *d = (volatile hcf_16 *)(addr); \
                        while (l--) {                                   \
                            *d++ = *(volatile hcf_16 *)(port);          \
                            EIEIO();                                    \
                        }                                               \
                                                }

#define OUT_PORT_STRING_16( port, addr, len)        {                       \
                        unsigned l = (len);                             \
                        volatile hcf_16 *s = (volatile hcf_16 *)(addr);  \
                        while (l--) {                                   \
                            *(volatile hcf_16 *)(port) = *s++;          \
                            EIEIO();                                    \
                        }                                               \
                                                }

#elif defined DAYTONABSP

#define HCF_BIG_ENDIAN 1

#ifdef HCF_PORT_IO
#undef HCF_PORT_IO
#endif  /* ifdef HCF_PORT_IO */

#define HCF_MEM_IO					1

#ifndef __GNUC__
    #define __asm__     asm
#endif

#define IN_PORT_BYTE(port)              (sysOrinocoInByte((unsigned long)(port)))
#define IN_PORT_WORD(port)              (sysOrinocoInWord((unsigned long)(port)))

#define OUT_PORT_BYTE(port,value)       (sysOrinocoOutByte((unsigned long)(port), (unsigned char)(value)))
#define OUT_PORT_WORD(port,value)       (sysOrinocoOutWord((unsigned long)(port), (unsigned short)(value)))

#define IN_PORT_STRING_16(port,addr,len)   (sysOrinocoInString((port), (addr), (len)))
#define OUT_PORT_STRING_16(port,addr,len)   (sysOrinocoOutString((port), (addr), (len)))

extern unsigned char    sysOrinocoInByte    (unsigned long port);
extern unsigned short   sysOrinocoInWord    (unsigned long port);
extern void             sysOrinocoInString  (unsigned long port, void *addr, unsigned short len);

extern void             sysOrinocoOutByte   (unsigned long port, unsigned char value);
extern void             sysOrinocoOutWord   (unsigned long port, unsigned short value);
extern void             sysOrinocoOutString (unsigned long port, void *addr, unsigned short len);

#elif defined ALPHA_BSP

#define HCF_BIG_ENDIAN 1

#ifdef HCF_PORT_IO
#undef HCF_PORT_IO
#endif  /* ifdef HCF_PORT_IO */

#define HCF_MEM_IO					1

#ifndef __GNUC__
    #define __asm__     asm
#endif

#define IN_PORT_BYTE(port)              (sysOrinocoInByte((unsigned long)(port)))
#define IN_PORT_WORD(port)              (sysOrinocoInWord((unsigned long)(port)))

#define OUT_PORT_BYTE(port,value)       (sysOrinocoOutByte((unsigned long)(port), (unsigned char)(value)))
#define OUT_PORT_WORD(port,value)       (sysOrinocoOutWord((unsigned long)(port), (unsigned short)(value)))

#define IN_PORT_STRING_16(port,addr,len)   (sysOrinocoInString((port), (addr), (len)))
#define OUT_PORT_STRING_16(port,addr,len)   (sysOrinocoOutString((port), (addr), (len)))

extern unsigned char    sysOrinocoInByte    (unsigned long port);
extern unsigned short   sysOrinocoInWord    (unsigned long port);
extern void             sysOrinocoInString  (unsigned long port, void *addr, unsigned short len);

extern void             sysOrinocoOutByte   (unsigned long port, unsigned char value);
extern void             sysOrinocoOutWord   (unsigned long port, unsigned short value);
extern void             sysOrinocoOutString (unsigned long port, void *addr, unsigned short len);

#else

error; /* commented here */ /*	"BSP is not defined..." */

#endif	/* else PC486BSP */

#endif	// __VX_WORKS__



/*  * * * * * * * * * * * * * * * * * * * * * *  IV  * * * * * * * * * * * * * * * * * * * * * * */

/***************************************Compiler specific ****************************************/

#if !defined EXTERN_C
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif //__cplusplus
#endif //EXTERN_C

/************************************************************************************************/
/********** M A C R O S derived of C O M P I L E R   S P E C I F I C   M A C R O S  *************/
/************************************************************************************************/

#if !defined FAR
#define FAR								// default to flat 32-bits code
#endif // FAR

typedef hcf_8  FAR *wci_bufp;			// segmented 16-bits or flat 32-bits pointer to 8 bits unit
typedef hcf_16 FAR *wci_recordp;		// segmented 16-bits or flat 32-bits pointer to 16 bits unit

/*  * * * * * * * * * * * * * * * * * * * * * *  V  * * * * * * * * * * * * * * * * * * * * * * */


/*	I/O Address size
 *	Platforms which use port mapped I/O will (in general) have a 64k I/O space, conveniently expressed in a
 *	16-bits quantity
 *	Platforms which use memory mapped I/O will (in general) have an I/O space much larger than 64k, and need a
 *	32-bits quantity to express the I/O base
 *	To accommodate this the macro HCF_MEM_IO is available. If HCF_MEM_IO is not defined, the HCF uses an
 *	hcf_16 to express I/O base and store in the IFB. If HCF_MEM_IO is defined, an hcf_32 is used.
 */
#if defined		HCF_MEM_IO
#undef			HCF_MEM_IO
#define			HCF_MEM_IO	1
#else
#define			HCF_MEM_IO	0
#endif //		HCF_MEM_IO

#if HCF_MEM_IO
typedef hcf_32 hcf_io;
#else
typedef hcf_16 hcf_io;
#endif //HCF_MEM_IO



/************************************************************************************************/
/*******************  Common code to faciltate I/O logging in the DOS Environment ***************/
/**************************** Intended for engineering purposes only ****************************/
/************************* Feel free to leverage from this as an example ************************/
/************************************************************************************************/
#if ! defined IN_PORT_WORD			//replace I/O Macros with logging facility
#if defined WVLAN_42	|| defined WVLAN_43 || 		\
    defined WCITST 		|| defined HCF_DEMO	||		\
    defined H0_LDR 		|| defined H1_LDR 	|| defined H2_LDR

#define IN_PORT_WORD_RTN			//replace I/O Macros with logging facility
	
hcf_16	in_port_word		( hcf_io port );
void	in_port_string_16	( hcf_io port, hcf_16 FAR * dst, int n );
void	out_port_word		( hcf_io port, hcf_16 value );
void	out_port_string_16	( hcf_io port, hcf_16 FAR * src, int n );

#define IN_PORT_WORD(port)					in_port_word(    	(hcf_io)(port) )
#define OUT_PORT_WORD(port, value)			out_port_word(   	(hcf_io)(port), (hcf_16)(value) )
#define IN_PORT_STRING_16(port, dst, n)  	in_port_string_16(	(hcf_io)(port), (hcf_16 FAR *)(dst), (int)(n) )
#define OUT_PORT_STRING_16(port, src, n) 	out_port_string_16( (hcf_io)(port), (hcf_16 FAR *)(src), (int)(n) )

extern FILE *log_file;

#endif // WVLAN_42 / WVLAN_43 / WCITST / HCF_DEMO / H0_LDR / H1_LDR / H2_LDR
#endif // IN_PORT_WORD


/************************************************************************************************/
/*******************  ***************/
/************************************************************************************************/
#if ! defined IN_PORT_STRING_16

#define IN_PORT_STRING_16( port, addr, len) {		\
	unsigned l = len;								\
	hcf_16  *d = (hcf_16 *)(addr);					\
	hcf_16   t;										\
	while (l--) {									\
		t = IN_PORT_WORD(port);						\
		*d++ = CNV_LITTLE_TO_INT(t);				\
	}												\
} // IN_PORT_STRING_16

#define OUT_PORT_STRING_16( port, addr, len) {		\
	unsigned l = (len);								\
	hcf_16  *s = (hcf_16 *)(addr);					\
	hcf_16   t;										\
	while (l--) {									\
		t = *s++;									\
		t = CNV_LITTLE_TO_INT(t);					\
		OUT_PORT_WORD(port, t);						\
	}												\
} // OUT_PORT_STRING_16

#endif // IN_PORT_STRING_16


/* MSF_COMPONENT_ID is used to define the CFG_IDENTITY_STRCT in HCF.C
 * CFG_IDENTITY_STRCT is defined in HCF.C purely based on convenience arguments.
 * The HCF can not have the knowledge to determine the ComponentId field of the Identity record (aka as
 * Version Record), therefore the MSF part of the Drivers must supply this value via the System Constant
 * MSF_COMPONENT_ID.
 * There is a set of values predefined in MDD.H (format COMP_ID_.....)
 *
 * Note that taking MSF_COMPONENT_ID as a default value for DUI_COMPAT_VAR is purely an implementation
 * convenience, the numerical values of these two quantities have none functional relationship whatsoever.
 * Originally there was only a single DUI-variant with value 1.  Then it was considered advantageous to have
 * unique DUI-variant per driver and - as said before - out of convenience these variants where chosen to have
 * the same numerical value as the component id of the driver.
 * Again later, it was decided that there would be two Miniport 3.1 drivers, the old one continuing to have
 * DUI-variant and component ID 41, the new one (the STAP or HomeLAN driver) having component ID 41 but
 * DUI-variant 2 (since 1 was already used in the past)
 */

#if defined	MSF_COMPONENT_ID
#if !defined DUI_COMPAT_VAR
#define	DUI_COMPAT_VAR				MSF_COMPONENT_ID
#endif // DUI_COMPAT_VAR

#if ! defined DUI_COMPAT_BOT		//;?this way utilities can lower as well raise the bottom
#define	DUI_COMPAT_BOT              8
#endif // DUI_COMPAT_BOT

#if ! defined DUI_COMPAT_TOP		//;?this way utilities can lower as well raise the top
#define	DUI_COMPAT_TOP              8
#endif // DUI_COMPAT_TOP

#endif // MSF_COMPONENT_ID

#if (HCF_TYPE) & HCF_TYPE_HII
#if (HCF_TYPE) & HCF_TYPE_HII5 //_WARP
#if ! defined HCF_HSI_VAR_5
#define HCF_HSI_VAR_5				//Hermes-II all types (for the time being!)
#endif // HCF_HSI_VAR_5
#if defined HCF_HSI_VAR_1 || defined HCF_HSI_VAR_2 || defined HCF_HSI_VAR_3 || defined HCF_HSI_VAR_4
error, HSI variants 1, 2, 3 and 4 correspond with H-I or HII ;
#endif // HCF_HSI_VAR_1, HCF_HSI_VAR_2, HCF_HSI_VAR_3, HCF_HSI_VAR_4
#else // No _WARP
#if ! defined HCF_HSI_VAR_4
#define HCF_HSI_VAR_4				//Hermes-II all types (for the time being!)
#endif // HCF_HSI_VAR_4
#if defined HCF_HSI_VAR_1 || defined HCF_HSI_VAR_2 || defined HCF_HSI_VAR_3
error, HSI variants 1, 2 and 3 correspond with H-I only;
#endif // HCF_HSI_VAR_1, HCF_HSI_VAR_2, HCF_HSI_VAR_3
#endif // _WARP
#else // !HCF_TYPE_HII
#if ! defined HCF_HSI_VAR_0 && !defined HCF_HSI_VAR_1 && !defined HCF_HSI_VAR_2 && !defined HCF_HSI_VAR_3
#define HCF_HSI_VAR_1				//PCCard
#define HCF_HSI_VAR_2				//MiniPCI
#define HCF_HSI_VAR_3				//Personal PCCard
#endif // HCF_HSI_VAR_0/1/2/3
#if defined HCF_HSI_VAR_4
error, HSI variants 4 correspond with H-II only;
#endif // HCF_HSI_VAR_4
#endif // HCF_TYPE_HII


#if (HCF_TYPE) & HCF_TYPE_HII
#if ! defined HCF_PRI_VAR_3
#define HCF_PRI_VAR_3
#endif // HCF_PRI_VAR_3
#if defined HCF_PRI_VAR_1 || defined HCF_PRI_VAR_2
error, primary variants 1 and 2 correspond with H-I only;
#endif // HCF_PRI_VAR_1, HCF_PRI_VAR_2
#else // !HCF_TYPE_HII
#if ! defined HCF_PRI_VAR_1 && !defined HCF_PRI_VAR_2
#define HCF_PRI_VAR_1
#define HCF_PRI_VAR_2
#endif //HCF_PRI_VAR_1/2
#if defined HCF_PRI_VAR_3
error, primary variant 3 correspond with H-II only;
#endif // HCF_PRI_VAR_3
#endif //HCF_TYPE_HII

#if (HCF_TYPE) & HCF_TYPE_HII
#if (HCF_TYPE) & HCF_TYPE_HII5 //_WARP
#if ! defined HCF_APF_VAR_4
#define HCF_APF_VAR_4
#endif // HCF_APF_VAR_4
#else // No _WAPP
#if ! defined HCF_APF_VAR_2
#define HCF_APF_VAR_2
#endif // HCF_APF_VAR_2
#endif // _WARP
#else // !HCF_TYPE_HII
#if ! defined HCF_APF_VAR_1
#define HCF_APF_VAR_1
#endif //HCF_APF_VAR_1
#endif //HCF_TYPE_HII

#if (HCF_TYPE) & HCF_TYPE_HII
#if (HCF_TYPE) & HCF_TYPE_HII5 //_WARP
#if ! defined HCF_STA_VAR_4
#define HCF_STA_VAR_4
#endif // HCF_STA_VAR_4
#else // No _WARP
#if ! defined HCF_STA_VAR_2
#define HCF_STA_VAR_2
#endif // HCF_STA_VAR_2
#endif // WARP
#else // !HCF_TYPE_HII
#if ! defined HCF_STA_VAR_1
#define HCF_STA_VAR_1
#endif //HCF_STA_VAR_1
#endif //HCF_TYPE_HII


/************************************************************************************************/
/******  M S F    S U P P O R T    F U N C T I O N S    P R O T O T Y P E S   *******************/
/************************************************************************************************/

//****************************************** A L I G N M E N T  **********************************************
#if !defined HCF_ALIGN
#define HCF_ALIGN 1			//default to no alignment
#endif // HCF_ALIGN

#define HCF_8P(p)				((hcf_8*)p)
#define HCF_DEREF_WORDP(wp)		(hcf_16)( *HCF_8P( wp) ) | (hcf_16)((*(HCF_8P( wp)+1)) << 8)
#define HCF_DEREF_DWORDP(dwp)	(hcf_32)( *HCF_8P(dwp) ) | (hcf_32)((*(HCF_8P(dwp)+1)) << 8)  | \
								(hcf_32)( (*(HCF_8P(dwp)+2)) << 16) | (hcf_32)( (*(HCF_8P(dwp)+3)) << 24)


#if HCF_ALIGN != 1 && HCF_ALIGN != 2 && HCF_ALIGN != 4 && HCF_ALIGN != 8
	error;
#endif // HCF_ALIGN != 0 && HCF_ALIGN != 2 etc

#if !defined HCF_MAX_MSG
#define HCF_MAX_MSG			1514	// WaveLAN Packet Size in bytes
#endif

#if !defined HCF_MAX_LTV
#define HCF_MAX_LTV			0x1001	// ;?requires some thought, this copes with "default" DownLoadBufferLenght
#endif

#if !defined	HCF_PROT_TIME
#define 		HCF_PROT_TIME	100	// number of 10K microseconds protection timer against H/W malfunction
#endif // 		HCF_PROT_TIME

#if HCF_PROT_TIME != 0 && ( HCF_PROT_TIME < 19 || 256 < HCF_PROT_TIME )
error;								// below minimum .08 second required by Hermes or possibly above hcf_32 capacity
#endif // HCF_PROT_TIME

#if 	HCF_PROT_TIME > 128
#define HCF_PROT_TIME_SHFT	3
#define HCF_PROT_TIME_DIV	8
#elif 	HCF_PROT_TIME > 64
#define HCF_PROT_TIME_SHFT	2
#define HCF_PROT_TIME_DIV	4
#elif 	HCF_PROT_TIME > 32
#define HCF_PROT_TIME_SHFT	1
#define HCF_PROT_TIME_DIV	2
#else //HCF_PROT_TIME >= 19
#define HCF_PROT_TIME_SHFT	0
#define HCF_PROT_TIME_DIV	1
#endif

#define HCF_PROT_TIME_CNT (HCF_PROT_TIME / HCF_PROT_TIME_DIV)


/************************************************************************************************************/
/******************************************* . . . . . . . . .  *********************************************/
/************************************************************************************************************/


/* The BASED customization macro is used to resolves the SS!=DS conflict for the Interrupt Service logic in
 * DOS Drivers. Due to the cumbersomeness of mixing C and assembler local BASED variables still end up in the
 * wrong segment. The workaround is that the HCF uses only global BASED variables or IFB-based variables.
 * The "BASED" construction (supposedly) only amounts to something in the small memory model.
 *
 * Note that the whole BASED rigmarole is needlessly complicated because both the Microsoft Compiler and
 * Linker are unnecessary restrictive in what far pointer manipulation they allow
 */

#if !defined BASED
#define BASED
#endif

#if !defined NULL
#define NULL ((void *) 0)
#endif

#if !defined TEXT
#define TEXT(x) x
#endif

#if !defined _TCHAR_DEFINED
#define TCHAR char
#endif

/************************************************************************************************************/
/*********************************** M I G R A T I O N   A S P E C T S **************************************/
/************************************************************************************************************/
#if !defined 	HCF_TYPE
#define 		HCF_TYPE 				HCF_TYPE_HII		//default to Hermes-II
#endif //		HCF_TYPE

#if ! defined 	HCF_ASSERT
#define 		HCF_ASSERT				0
#endif			// HCF_ASSERT

#if !defined	HCF_TALLIES
#define			HCF_TALLIES				0x0003
#endif //		HCF_TALLIES

#if ! defined	HCF_DEEPSLEEP
#define			HCF_DEEPSLEEP			0
#endif //		HCF_DEEPSLEEP

#if ! defined	HCF_DDS
#define			HCF_DDS					0
#endif //		HCF_DDS

#if !defined	HCF_ENCAPSULATION
#define			HCF_ENCAPSULATION		1
#endif //		HCF_ENCAPSULATION

#if ((HCF_TYPE) & ( HCF_TYPE_HII | HCF_TYPE_PRELOADED ) ) == HCF_TYPE_HII
#undef  HCF_DLV
#define HCF_DLV		1
#endif //HCF_TYPE_HII


/************************************************************************************************************/
/*********************** C O N F L I C T   D E T E C T I O N  &  R E S O L U T I O N ************************/
/************************************************************************************************************/
#if defined HCF_BIG_ENDIAN && defined HCF_LITTLE_ENDIAN
err;
#endif // 	HCF_BIG_ENDIAN / HCF_LITTLE_ENDIAN

#if defined HCF_BIG_ENDIAN
#undef		HCF_BIG_ENDIAN
#define		HCF_BIG_ENDIAN 1
#endif	//	HCF_BIG_ENDIAN

#if defined HCF_LITTLE_ENDIAN
#define		HCF_BIG_ENDIAN 0
#endif //	HCF_LITTLE_ENDIAN

//#if HCF_ASSERT & 0x0002 && (HCF_TYPE) & HCF_TYPE_USB
#if HCF_ASSERT & 0x0002
#if (HCF_TYPE) & HCF_TYPE_USB
#pragma err: conflict in assert which performs direct I/O in this case
#endif // HCF_TYPE_USB
#endif // HCF_ASSERT

#if HCF_ASSERT & 0x0004 //resolve potential conflict
#undef	HCF_MB_OFF
#undef	HCF_MB_ON
#define	HCF_MB_ON 1
#endif // HCF_ASSERT

#if HCF_EX_INT & 0x0006 //resolve potential conflict
#undef	HCF_MB_OFF
#undef	HCF_MB_ON
#define	HCF_MB_ON 1
#endif // HCF_EX_INT

#if ! defined	HCF_DLV
#define			HCF_DLV		0
#endif //		HCF_DLV

#if				HCF_DLV
#undef			HCF_DLV
#define			HCF_DLV		1
#endif //		HCF_DLV

#if ! defined	HCF_DLNV
#define			HCF_DLNV	0
#endif //		HCF_DLNV

#if				HCF_DLNV
#undef			HCF_DLNV
#define			HCF_DLNV	2
#endif //		HCF_DLNV

#if defined HCF_INT_OFF && defined HCF_INT_ON
error: at most 1 of these macros should be defined;
#endif //HCF_INT_OFF /HCF_INT_ON

#if defined		HCF_INT_ON
#if				HCF_INT_ON
#undef			HCF_INT_ON
#define			HCF_INT_ON	1
#endif //		HCF_INT_ON
#endif //		HCF_INT_ON

#if defined		HCF_INT_OFF
#undef			HCF_INT_OFF
#undef			HCF_INT_ON
#define			HCF_INT_ON	0
#endif //		HCF_INT_OFF

#if !defined	HCF_INT_ON
#define			HCF_INT_ON	1
#endif //		HCF_INT_ON

#if !defined	HCF_MONITOR_MODE
#define			HCF_MONITOR_MODE	0
#endif //		HCF_MONITOR_MODE

#if !defined	HCF_ENTRY
#define			HCF_ENTRY( ifbp )
#endif //		HCF_ENTRY

#if !defined	HCF_EXIT
#define			HCF_EXIT( ifbp )
#endif //		HCF_EXIT

#if !defined	HCF_LEGACY_ON
#define			HCF_LEGACY_ON	1
#endif //		HCF_LEGACY_ON

#if HCF_DLV == 1 && ( (HCF_TYPE) & HCF_TYPE_PRELOADED )
#pragma err: conflict;
#endif // HCF_DLV / HCF_TYPE_PRELOADED

#endif //HCFCFG_H


