Microsoft KB Archive/304296

= How To Use NDIS IOCTLs to Manage Adapters and Bindings =

Article ID: 304296

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Encarta Reference Suite 2001
 * Microsoft Windows CE 3.0 for the Handheld PC

-



This article was previously published under Q304296



SUMMARY
This article describes how an application can instruct Windows CE to add or remove a miniport adapter, or bind, unbind, or rebind adapters to protocol drivers. This is done through the use of I/O controls (IOCTLs) to the network driver interface specification (NDIS) component. Note that at the time of this writing (8/1/2001), these IOCTLs are not supported in Pocket PC.

The rebinding of network adapters will force registry entries to be reapplied. This is helpful, for example, if you want to update miscellaneous TCP/IP or miniport registry settings dynamically. A useful application of these IOCTLs might be to move a Windows CE-based computer from a Dynamic Host Configuration Protocol (DHCP) to a static IP environment without rebooting the device since this cannot be achieved through the IPHELPER APIs.



MORE INFORMATION
The specific IOCTLs supported are defined in the header file Ddk\Inc\Ntddndis.h. They include:

IOCTL_NDIS_REGISTER_ADAPTER - register a new adapter with NDIS

IOCTL_NDIS_DEREGISTER_ADAPTER - deregister an existing adapter

IOCTL_NDIS_REBIND_ADAPTER - unbind then bind an adapter from protocols

IOCTL_NDIS_BIND_ADAPTER - bind an adapter to protocols

IOCTL_NDIS_UNBIND_ADAPTER - unbind an adapter from protocols

Each IOCTL must be issued to the device with the name DD_NDIS_DEVICE_NAME (defined in Ntddndis.h). A handle to this device can be created like this: HANDLE hNdis; hNdis = CreateFile(DD_NDIS_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE,               FILE_SHARE_READ | FILE_SHARE_WRITE,                NULL, OPEN_ALWAYS, 0, NULL);
 * 1) include 

If successful, the returned handle can be used to perform the DeviceIoControl like this: bResult = DeviceIoControl(hNdis,                 dwCommand,                  pInBuffer,                  cbInBuffer,                  NULL,                  NULL,                  NULL,                  NULL); The dwCommand parameter is one of the IOCTL codes listed earlier. The pInBuffer parameter is a multi_wsz. That is, it is zero or more L'\0' terminated strings concatenated together, terminated with a double L'\0'. The interpretation of the multi_wsz strings depends upon which IOCTL is being executed, as detailed below. CbInBuffer is the number of bytes (including the size of L'\0' characters) in pInBuffer.

IOCTL Details
IOCTL_NDIS_REGISTER_ADAPTER

PInBuffer consists of two strings: The name of the miniport driver followed by the name of the adapter instance to create. For example: L&quot;NE2000\0NE20001\0\0&quot;.

This IOCTL causes the adapter instance to be created and bound to protocols just as if a new PnP adapter had been inserted into the system. Prior to invoking the IOCTL all registry settings for the miniport and the adapter instance should have been created as for any NDIS miniport adapter.

This IOCTL should NOT be used with PCMCIA adapters.

IOCTL_NDIS_DEREGISTER_ADAPTER

PInBuffer consists of one string: The name of the adapter instance to delete. For example: L&quot;NE20001\0\0&quot;.

This IOCTL causes the adapter instance to be unbound from any protocols it is bound to and then deleted.

This IOCTL should not be used with PCMCIA adapters.

'''IOCTL_BIND_ADAPTER

IOCTL_UNBIND_ADAPTER

IOCTL_REBIND_ADAPTER'''

These three IOCTLs all take the same format for pInBuffer. PInBuffer consists of the adapter name for the operation followed optionally by a protocol name. If the optional protocol name is present, then the operation will be performed only for the binding between the adapter and that protocol. Otherwise, the operation is performed between the adapter and all protocols registered with NDIS. For example: L&quot;NE20001\0TCPSTK\0\0&quot;.

IOCTL_BIND_ADAPTER

This IOCTL creates bindings between the adapter and protocol drivers. Note that in order for a binding to be created the protocol driver must have a medium type compatible with the adapter, otherwise the protocol driver will reject it.

IOCTL_UNBIND_ADAPTER

This IOCTL deletes existing bindings between the adapter and protocol drivers.

IOCTL_REBIND_ADAPTER

This IOCTL performs an unbind operation followed by a binding. This is sometimes useful to cause the protocol driver to perform initialization activities, such as TCP/IP running DHCP as if the adapter had just been inserted.

Additional query words: NDIS IOCTLS REBIND TCP/IP DYNAMIC ADDRESS DHCP

Keywords: kbhowto KB304296

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.