Using NDIS in Windows CE

Download the sample code

Network Driver Interface Specification (NDIS) is an API to communicate with Network Interface Cards (NIC) developed by Microsoft and 3Com Corporation. It is library of functions (wrapper) to hide the complexity of the network cards. Using NDIS developers can create device drivers that communicate with the NICs and enables the developer to create protocol stacks that send and receive data packets. These packets are usually called frame.

The sample program presented here lists the adapters present and the protocol names that are associated with each adapters. The application first opens the NDIS device driver. This is done by using the API CreateFile. The first parameter is the device name which will be NDS0: most of the time. The following snippet opens the “NDS0:” device:

m_hDevice = CreateFile(TEXT("NDS0:"),GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, INVALID_HANDLE_VALUE);

After opening the device, the application retrieves all the adapters present and lists the names in a combobox. This is done using the API DeviceIoControl with IOCTL_NDIS_GET_ADAPTER_NAMES control code. Following code shows the operation:

DeviceIoControl(m_hDevice,IOCTL_NDIS_GET_ADAPTER_NAMES,NULL,0,LPVOID)szBuffer,MAX_ADAPTER_BUFFER,&dwSize,NULL);

When completed successfully the szBuffer will have the names of the adapters separated by NULL. The end of the buffer is represented by two NULLs.

When an adapter is selected the protocol names that are associated with it are displayed in a listbox. To retrieve the protocol names, first we have to bind the selected adapter, this is done by using the DeviceIoControl API with IOCTL_NDIS_BIND_ADAPTER control code:

DeviceIoControl(m_hDevice,IOCTL_NDIS_BIND_ADAPTER,(LPVOID)lpszAdapter,wcslen(lpszAdapter),NULL,0,NULL,NULL);

The pszAdapter parameter is the name of the adapter to bind. After binding the adapter we can retrieve the protocol list by using the IOCTL_NDIS_GET_PROTOCOL_NAMES control code:

DeviceIoControl(m_hDevice,IOCTL_NDIS_GET_PROTOCOL_NAMES,NULL,0,LPVOID)szBuffer,MAX_ADAPTER_BUFFER,&dwSize,NULL);

Again the szBuffer will be multi-string that contains all the protocol names associated with the adapter. This a very simple application and I hope this will give you an introduction to NIDS. I am working on more samples and will post here whenever it is completed.

1 Comment

Add yours →

  1. Hello,Could you please give me some advice to develop a miniport driver in Win CE. I have already known how to finish a miniport driver in PC ,such as windows xp. But I have no idea in Win CE. Thanks so much!

Leave a Reply