From: sudheer on
Hi

I have written a basic SDIO Driver. Its working fine and got loaded
when i connect my SDIO device. I want to write a NDIS Driver and load
both (NDIS & SDIO) drivers when i connect my SDIO device. I have gone
through some forums for how to write NDIS-WDM driver. From that i got
info that we can register a WDM device object in a NDIS driver but
cannot call any NDIS functions in a WDM driver (correct me if i am
wrong). I dont have any previous experience on NDIS driver. I have
gone through the sample of NDIS-WDM driver provided in latest DDK
(3790.1830). But it is given that NDISPROT related code should be
removed to work for USB or any WDM. Can any one tell me what is the
code to be modified in NDIS-WDM sample to register my SDIO device
object using NdisMRegisterDevice.

>From Doron's discussion on NDIS-WDM, i came to know that it is easier
to use KMDF than WDM for writing NDIS-WDM. But according to him i have
understood that WDM function driver (in my case SDIO driver) will load
first and then NDIS driver (correct me if i am wrong). we can register
IoRegisterPlugPlayNotification in the SDIOAddEvent function and i am
confused that how can that call will load (or enumerate) NDIS driver
stack. Can any one please explain this. If this is possible, please
tell me what are the changes to be made in KMDF samples.

Thanks in advance
Regards
Sudheer

From: Rahul Bansal on
On May 16, 9:46 am, sudheer <sudheer.papo...(a)gmail.com> wrote:
> Hi
>
> I have written a basicSDIODriver. Its working fine and got loaded
> when i connect mySDIOdevice. I want to write a NDIS Driver and load
> both (NDIS &SDIO) drivers when i connect mySDIOdevice. I have gone
> through some forums for how to write NDIS-WDM driver. From that i got
> info that we can register a WDM device object in a NDIS driver but
> cannot call any NDIS functions in a WDM driver (correct me if i am
> wrong). I dont have any previous experience on NDIS driver. I have
> gone through the sample of NDIS-WDM driver provided in latest DDK
> (3790.1830). But it is given that NDISPROT related code should be
> removed to work for USB or any WDM. Can any one tell me what is the
> code to be modified in NDIS-WDM sample to register mySDIOdevice
> object using NdisMRegisterDevice.
>
> >From Doron's discussion on NDIS-WDM, i came to know that it is easier
>
> to use KMDF than WDM for writing NDIS-WDM. But according to him i have
> understood that WDM function driver (in my caseSDIOdriver) will load
> first and then NDIS driver (correct me if i am wrong). we can register
> IoRegisterPlugPlayNotification in the SDIOAddEvent function and i am
> confused that how can that call will load (or enumerate) NDIS driver
> stack. Can any one please explain this. If this is possible, please
> tell me what are the changes to be made in KMDF samples.
>
> Thanks in advance
> Regards
> Sudheer



hi,
after you have loaded ur sdio driver as streams interface, do this to
register it as miniport -


DWORD SDI_Init(DWORD dwContext)
{
BOOL fRetVal = TRUE;
DWORD dwRet;

PWSTR pSDRegPath; // Registry Path
SD_DEVICE_HANDLE hSDDevice;

DBG_ENTER(gDbgInfo);

hSDDevice = SDGetDeviceHandle(dwContext, &pSDRegPath);

if (hSDDevice == NULL || dwContext == 0 || pSDRegPath== NULL)
{
fRetVal = FALSE;
goto exit;
}

g_dwSDContext = dwContext;
g_hSDDevice = hSDDevice;
g_pSDRegPath = pSDRegPath;


exit:

if(fRetVal == TRUE)
{
ULONG i=0;

dwRet = 1;

//Add registry keys
for (i = 0; i < (sizeof(SDIOKeyNames)/sizeof(LPWSTR)); i++)
{
if (!AddKeyValues(SDIOKeyNames[i], SDIOValues[i]))
{
for (i = 0; i < (sizeof(SDIOKeyNames)/sizeof(LPWSTR)); i++)
{
RegDeleteKey(HKEY_LOCAL_MACHINE,SDIOKeyNames[i]);
}
return 0;
}
}

CreateThread(NULL, 0, RegisterAdapterThread, NULL, 0, NULL);
}
else
{
dwRet = 0;
}

return (DWORD) hSDDevice;
}

#define BASE_NAME _T("DLLNAME")
#define DEFAULT_DEVICE_DESC _T("Wireless LAN 802.11
Adapter")
#define VER_SDIO_FILE_NAME_STR _T("DLLNAME.dll")
#define BUS_NUMBER_KEY "BusNumber"
#define BUS_NUMBER_DEFAULT 0

REG_VALUE_DESCR SDIOCommKeyValues[] = {
(TXT("DisplayName")), REG_SZ,
(PBYTE)DEFAULT_DEVICE_DESC,
(TXT("Group")), REG_SZ, (PBYTE)(TXT("NDIS")),
(TXT("ImagePath")), REG_SZ,
(PBYTE)VER_SDIO_FILE_NAME_STR,
NULL, 0, NULL
};

// Values for [HKEY_LOCAL_MACHINE\Comm\DLLNAMExx\Linkage]
REG_VALUE_DESCR SDIOLinkageKeyValues[] = {
(TXT("Route")), REG_MULTI_SZ, (PBYTE)(BASE_NAME
TXT("_1")),
NULL, 0, NULL
};


// Values for [HKEY_LOCAL_MACHINE\Comm\DLLNAME\Parms]
REG_VALUE_DESCR SDIOParmKeyValues[] = {
(TXT(BUS_NUMBER_KEY)), REG_DWORD, (PBYTE)BUS_NUMBER_DEFAULT,
(TXT("NeverLoopbackPackets")), REG_DWORD, (PBYTE)1,
(TXT("AllMiniportsDeserialized")), REG_DWORD, (PBYTE)1,
(TXT("OptimizeReceiveHandling")), REG_DWORD, (PBYTE)1,
NULL, 0, NULL
};

// Values for [HKEY_LOCAL_MACHINE\Comm\DLLNAME\Parms]
REG_VALUE_DESCR SDIOKeyValues[] = {
(TXT(BUS_TYPE_KEY)), REG_DWORD,
(PBYTE)NdisInterfaceInternal,
NULL, 0, NULL
};


LPWSTR SDIOKeyNames[] = {
(TXT("Comm\\")BASE_NAME),
(TXT("Comm\\")BASE_NAME TXT("\\Linkage")),
(TXT("Comm\\")BASE_NAME TXT("_1")),
(TXT("Comm\\")BASE_NAME TXT("\\Parms"))
};

PREG_VALUE_DESCR SDIOValues[] = {
SDIOCommKeyValues,
SDIOLinkageKeyValues,
SDIOCommKeyValues,
SDIOParmKeyValues,
SDIOKeyValues
};

DWORD WINAPI RegisterAdapterThread(
IN void* lpThreadParameter
)
{
NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
HINSTANCE hModuleNdis;
PNDISREGISTERADAPTER pNdisRegisterAdapter;
PWCHAR MiniportName;
PWCHAR AdapterInstanceName;

NdisMSleep(1000);

hModuleNdis = GetModuleHandle(TXT("ndis.dll"));
pNdisRegisterAdapter = (PNDISREGISTERADAPTER)GetProcAddress(
hModuleNdis, TXT("NdisRegisterAdapter"));
if (pNdisRegisterAdapter)
{

MiniportName = TXT("DLLNAME");
AdapterInstanceName = TXT("DLLNAME_1");



pNdisRegisterAdapter(&NdisStatus,
MiniportName,
AdapterInstanceName);
}
else
{
NdisStatus = NDIS_STATUS_NOT_SUPPORTED;
}

return(NdisStatus);
}



AS SOON YOUR REGISTRATION is over, DriverEntry (of your DLL - which
will NdisMInitializeWrapper and NdisMRegisterMiniport)

regards,
-rahul bansal.




From: Stephan Wolf [MVP] on
On May 16, 6:46 am, sudheer <sudheer.papo...(a)gmail.com> wrote:
[..]
> Can any one tell me what is the
> code to be modified in NDIS-WDM sample to register my SDIO device
> object using NdisMRegisterDevice.

Do a search for "NDISEDGE" in file "...\src\general\pcidrv\pcidrv.htm"
in the DDK and in this forum.

Stephan

From: sudheer on
Thanks Stephan

I have already gone through NDISEDGE and PCIDrv sample codes. NDISEDGE
explains with NDISPROT as lower edge WDM driver, but given information
that PCIDrv can also be used.

In WDK/6001/src/kmdf/ndisedge/ndiswdm.htm it is has mentioned under
"Adapting this driver for an USB device" the following points:

1. "Inf file has to be modified"

------ done that

2. "Remove all the code that are specific to interacting with
NDISPROT."

------- Modified in sources file - -DINTERFACE_WITH_NDISPROT=0 and
#define INTERFACE_WITH_NDISPROT already present in the sample code

3. "You don't have to open a USB device by calling Zw function. Your
driver will be part of the USB device stack and your
TargetDeviceObject will be the NextDeviceObject received from
NdisGetDeviceProperty call."

------- This point is not clear. Can you please brief on this as how
the NDIS NextDeviceObject points to USB Stack

"In the NICInitAdapterWorker routine, right before you allocate send &
receive side resources, configure your USB device."

------- As my device is SDIO, i have called
"NdisMRegisterDevice" (correct me if am wrong)

Can you let me know the further modifications to NDISEDGE and SDIO
driver requried to work properly

Thanks in advance
Regards
Sudheer

From: Stephan Wolf [MVP] on
On May 16, 2:26 pm, sudheer <sudheer.papo...(a)gmail.com> wrote:
[..]
> Can you let me know the further modifications to NDISEDGE and SDIO
> driver requried to work properly

Umm, I am not a USB expert, sorry. Someone else has to jump in here.

As I said, search this group for discussions on NDISEDGE, e.g.

http://groups.google.com/group/microsoft.public.development.device.drivers/search?q=NDISEDGE

...or with USB:

http://groups.google.com/group/microsoft.public.development.device.drivers/search?q=NDISEDGE+usb

SDIO has already been discussed in this context:

http://groups.google.com/group/microsoft.public.development.device.drivers/search?q=NDISEDGE+sdio

Stephan


Stephan