0
votes

I am trying to pass AddressChnage test case in WHQL test for my virtual miniport driver . During the test i can see the error log like :

Check network addresses on the test adapter after modifying the registry with new network address 
-------------------------------------------------------------------------------
Name: Test open for receiving
- RequestType: QueryInformation
- OID: OID_802_3_CURRENT_ADDRESS
- RequestId: 0
- BufferLength: 6
- Flags: 0x00000000
- PortNumber: 0 
Results 
- Status: NDIS_STATUS_SUCCESS (0x0) 
- Bytes Written: 6 
- Bytes Needed: 1737485104

Current address from test adapter is 0a-1b-3c-4d-5e-6f 
New network address under test is 02-02-04-06-08-02 

50009 **Current network address did not change after driver was reloaded. The driver should have picked up a new network address from the registry**.

For dummy mac , i am intiallty setting the MAC address . 0a-1b-3c-4d-5e-6f

PermenentAddress[0] = 0x0a
PermenentAddress[1] = 0x1b
PermenentAddress[2] = 0x3c
PermenentAddress[3] = 0x4d
PermenentAddress[4] = 0x5e
PermenentAddress[5] = 0x6f

But i am handling all the required calls during miniport initialization .

 NDIS_STATUS InitializeEx(
    __in NDIS_HANDLE MiniportAdapterHandle,
    __in NDIS_HANDLE MiniportDriverContext ,
    __in PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters 
   ) {

    NDIS_CONFIGURATION_OBJECT ndisConfigurationObject;
    NdisZeroMemory(&ndisConfigurationObject, sizeof(NDIS_CONFIGURATION_OBJECT));

    C_ASSERT(sizeof(NDIS_CONFIGURATION_OBJECT) >= NDIS_SIZEOF_CONFIGURATION_OBJECT_REVISION_1);
    ndisConfigurationObject.Header.Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT;
    ndisConfigurationObject.Header.Size = NDIS_SIZEOF_CONFIGURATION_OBJECT_REVISION_1;
    ndisConfigurationObject.Header.Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1;

    ndisConfigurationObject.NdisHandle = MiniportAdapterHandle;
    ndisConfigurationObject.Flags = 0;

    NDIS_HANDLE Configuration = NULL;

   status = NdisOpenConfigurationEx(&ndisConfigurationObject, &Configuration);
   if (status != NDIS_STATUS_SUCCESS) {
            return NDIS_STATUS_FAILURE;
   }

   //getting mac address from registry

   UCHAR* MacAddress = NULL;
   UINT MacAddressLength = 0;
   NdisReadNetworkAddress(&status, (PVOID*) &MacAddress, &MacAddressLength, Configuration);
   if ((status == NDIS_STATUS_SUCCESS) && (MacAddressLength == 6)) {
      NdisMoveMemory(CurrentAddress, MacAddress, 6);
   }

   NdisCloseConfiguration(Configuration);

}

and adding to the miniort adapter :

NdisMoveMemory(ndisMiniportAdapterGeneralAttributes.PermanentMacAddress, PermenentAddress, 6);
    NdisMoveMemory(ndisMiniportAdapterGeneralAttributes.CurrentMacAddress, CurrentAddress, 6);

Finally during the OID query request , i am passing the CurrentAddress and PermenentAddress values .

case OID_802_3_PERMANENT_ADDRESS:
            Information = &PermenentAddress ;
            InformationLength = sizeof(PermenentAddress);
            break;
case OID_802_3_CURRENT_ADDRESS:
            Information = &CurrentAddress ;
            InformationLength = sizeof(CurrentAddress );
            break;

This is the exact problem i am facing during the test . I don't know why i am facing the problem . I am handling NdisReadNetworkAddress handler to get the registry values of the configuration . miniport initialize will invoke after the driver restart and set the registry values to the currentaddress . isn't ?

Then why this is failing ? Any other alternative method to invoke and getting mac address of the adapter ? I am using NDIS 6.2 miniport with Windows 7 and higher OS .

1

1 Answers

0
votes

I don't see anything obviously wrong with the code -- you have the right idea. One red flag is that it looks like PermanentAddress and CurrentAddress are global variables in your driver. If so, they should be moved to hang off a per-adapter context.

You can see what NDIS thinks your MAC address is with !ndiskd.miniport. (If the test zooms past too quickly to catch it in the debugger, you can set a breakpoint on your MiniportRestartHandler. By the time NDIS calls your datapath restart handler, the MAC addresses you put into the General Attributes will have been plumbed throughout the system.) Anyway, check with !ndiskd.miniport if your MAC address comes up correctly. If not, check exactly what goes into the ndisMiniportAdapterGeneralAttributes before you give it to NDIS.

Unrelated notes:

  • Don't forget to check the MAC address for validity -- if you're implementing an IEEE 802 interface, you should never allow someone to set the local MAC address to a multicast or broadcast address. Refer to NICSetMacAddress in the netvmini sample driver.

  • NDIS 6.x miniport drivers don't have to respond to OID_802_3_PERMANENT_ADDRESS or OID_802_3_CURRENT_ADDRESS. NDIS responds to those on the miniport's behalf. Those OID handlers are dead code; you can remove them.