0

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 .

user2986042
  • 1,098
  • 2
  • 16
  • 37

1 Answers1

0

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.

Jeffrey Tippet
  • 3,146
  • 1
  • 14
  • 15
  • Thanks for your suggestions . PermanentAddress and CurrentAddress are per-adapter context . these are not global variables . – user2986042 Feb 25 '17 at 06:43
  • What does !ndiskd.miniport show as the MAC address after you've queried the registry? – Jeffrey Tippet Feb 26 '17 at 19:07
  • My application is a VPN . So when i connect , the server will provide a MAC address and it will write to the registry . I can see that miniport setting current MAC address same as HLK test provided during miniport initialization time . But again connecting with my server , i will get the new MAC address . So at the time of HLK test verification , it will check whether the current address is added or not . Now It will get new MAC address provided by server instead of HLK MAC . This is cause of this problem i think . Any solution for this test ? – user2986042 Feb 27 '17 at 06:14
  • Oh, uh, that's a strange thing to do. NICs in general shouldn't write to their own configuration like that. One problem is that the Current MAC address doesn't really take effect until next time your NIC starts... at which point it'll have gotten a new MAC address. – Jeffrey Tippet Mar 02 '17 at 07:00
  • In Windows 10, I added the ability to dynamically change your MAC address at runtime. Prior to Windows 10, you can't really do this in a clean way. – Jeffrey Tippet Mar 02 '17 at 07:11