/*
 * About the wrapper handle and the intermediate handle...
 * The wrapper handle, obtained from NDIS, is the original of the driver.
 * Without this wrapper handle, we cannot do anything.
 * Unfortunately, we cannot get sufficient argument from USB loader to
 * ask one wrapper handle.
 * Current alternative is, to put this driver into NDIS registry as
 * it is a 'static' driver, thus, we can get the wrapper handle.
 * This wrapper handle should not be cleared even the USB device is plug'd
 * out. Or we cannot restart the NDIS function anymore.
 *
 */
#include <Usbdrv.h>

NIC_DRIVER_USB::NIC_DRIVER_USB(
		NDIS_HANDLE 			MiniportHandle, 
		NDIS_HANDLE 			WrapperConfigHandle,
		USB_HANDLE 				hDevice, 
		LPCUSB_FUNCS			lpUsbFuncs, 
		LPCUSB_DEVICE			lpUsbDevice,
		LPCUSB_INTERFACE 		lpInterface)
		: NIC_DRIVER_OBJECT(MiniportHandle,WrapperConfigHandle)
{
	m_hUsbHandle = hDevice;
	m_lpUsbFuncs = lpUsbFuncs;
	m_lpUsbDevice = lpUsbDevice;
	m_lpUsbInterface = lpInterface;
}

NIC_DRIVER_USB::~NIC_DRIVER_USB(void)
{
	PRINTF(_T("usb deconstructor.\n"));
}


void NIC_DRIVER_USB::MiniportInitialize(
	OUT PNDIS_STATUS OpenErrorStatus,
	OUT PUINT SelectedMediaIndex, 
	IN PNDIS_MEDIUM MediaArray, 
	IN UINT MediaArraySize)
{
	SETFNAME("NIC_DRIVER_USB::MiniportInitialize");
	FUNCTION_ENTER_MSG();

	if(!m_pLower)
		m_pLower = DeviceEntry(this,NULL);

	if(!m_pLower)
		THROW((ERR_STRING("NIC_DRIVER_USB::MiniportInitialize - Error in creating device\r\n")));

	m_pLower->InitialUsbParameters(m_hUsbHandle,m_lpUsbFuncs,m_lpUsbInterface);
	NIC_DRIVER_OBJECT::MiniportInitialize(
		OpenErrorStatus,
		SelectedMediaIndex, 
		MediaArray, 
		MediaArraySize);
	FUNCTION_LEAVE_MSG();
}

void NIC_DRIVER_USB::DriverOnUsbNotify(U32 uCode)
{
	NdisIMDeInitializeDeviceInstance(m_hMiniportAdapter);
}




