Clarification on WAKE_ON_MEDIA_DISCONNECT event and Low power on Media Disconnect Event

Hello all,
I am new to windows driver development, especially power management related stuffs, So please correct me If I am wrong.

In Windows, I could see that various wake events are supported to wake the system. In that I came across, these 3 events mainly,

  1. Magic Packet
  2. Pattern Match
  3. Wake-On-Link Change (WAKE_ON_MEDIA_CONNECT, WAKE_ON_MEDIA_DISCONNECT).

Besides this, I came to know that there is a one more feature called, Low Power on Media Disconnect. This feature can be used to put the device to low power state when the media is disconnected. After that Media Connect event from Wake-On-Link Change can be used to wake the device. This is what I understood from the below article: Low Power on Media Disconnect - Windows drivers | Microsoft Learn

  1. If I understood the things correctly, the Low Power on Media Disconnect and WAKE_ON_MEDIA_DISCONNECT both are different and used for different purposes, respectively sleep and wake. Am I right?

Also from the above article, I understood that “D3 on disconnect is only available while the computer is fully powered in the working state (S0). This feature is canceled when the computer enters a sleep state“.

I am using the below setups in my case:
Node1 : USB (MAC-PHY) device With RPi4, which sends some kind of pulse signal to the PHY which will be used to wake the another node
Node2: USB (MAC-PHY) with Windows machine, which receives the signal.

If I put my Windows machine to sleep state, my node2 also goes to Dx sleep state. So Whenever my Node2 receives the pulse signal, the PHY link will be in up state. So I would like to use the WAKE_ON_MEDIA_CONNECT event here as my wake-up event source. And for my case I am not interested in WAKE_ON_MEDIA_DISCONNECT event. So I won’t use that event.

If I do the above things I am facing the below problems/Or the confusions I have:

  1. I can’t use the Low Power on Media Disconnect feature to put my device into sleep state. But I am doubting that only in that mode only, “NDIS uses OID_PM_PARAMETERS to disable Wake-on-LAN and to enable wake on media connect (NDIS_PM_WAKE_ON_LINK_CHANGE_ENABLED is set in the WakeUpFlags member”, after detecting the device disconnect event. Is it so?
    Because, the WakeUpFlags is 0 in my case.

  2. If I put my system into sleep state, The device goes to D3 Device power state when the Wake-On-Link Change feature is enabled. (I am using WakeMediaConDisConnect INF keyword).

  3. With the same setup from step number 3, If I check the option in power management tab “Only Allow a magic packet to wake the computer“ the device goes to D2 Device power state. I am confused about the D3 and D2 states of the devices in this scenario. Can anyone have an idea what is happening over there?

  4. I must use the Low Power on Media Disconnect feature with WAKE_ON_MEDIA_CONNECT event. So that Wake will happen properly. Is it so?
    Can’t I use the WAKE_ON_MEDIA_CONNECT event alone to achieve my goal as described above?

To add more information about power management capabilities and device capabilities:

10: kd> !ndiskd.miniport ffffce0f0f4901a0 -pm
POWER MANAGEMENT
Bus Capabilities (IRP_MN_QUERY_CAPABILITIES):

SystemWake PowerSystemHibernate
DeviceWake D2

System state Device state How to read this table?

Working D0
S1 D2
S2 D2
S3 D2
S4 (Hibernate) D2
S5 (Shutdown) D3

Cached DEVICE_CAPABILITIES structure ffffce0f0f490668

Device Capabilities (OID_PM_HARDWARE_CAPABILITIES):
Flags [No flags set]
WoL patterns WOL_BITMAP
Protocol offloads [No flags set]
Num patterns 8

Wake events WAKE_ON_MEDIA_CONNECT
Wake event Minimum power required
Magic packet Not supported
Bitmap pattern D3
Link change D3

Current Capabilities (OID_PM_CURRENT_CAPABILITIES):
Flags [No flags set]
WoL patterns [No flags set]
Protocol offloads [No flags set]
Num patterns 8

Wake events WAKE_ON_MEDIA_CONNECT
Wake event Minimum power required
Magic packet Not supported
Bitmap pattern Not supported
Link change D3

Active Capabilities (OID_PM_PARAMETERS):
WoL patterns [No flags set]
Protocol offloads [No flags set]
Wake flags WAKE_ON_LINK_CHANGE

Active WoL patterns
Active protocol offloads
Selective Suspend details
AOAC details

10: kd> dt _DEVICE_CAPABILITIES ffffce0f0f490668

nt!_DEVICE_CAPABILITIES

+0x000 Size : 0x40
+0x002 Version : 1
+0x004 DeviceD1 : 0y1
+0x004 DeviceD2 : 0y1
+0x004 LockSupported : 0y0
+0x004 EjectSupported : 0y0
+0x004 Removable : 0y1
+0x004 DockDevice : 0y0
+0x004 UniqueID : 0y1
+0x004 SilentInstall : 0y0
+0x004 RawDeviceOK : 0y0
+0x004 SurpriseRemovalOK : 0y0
+0x004 WakeFromD0 : 0y1
+0x004 WakeFromD1 : 0y1
+0x004 WakeFromD2 : 0y1
+0x004 WakeFromD3 : 0y0
+0x004 HardwareDisabled : 0y0
+0x004 NonDynamic : 0y0
+0x004 WarmEjectSupported : 0y0
+0x004 NoDisplayInUI : 0y0
+0x004 Reserved1 : 0y0
+0x004 WakeFromInterrupt : 0y0
+0x004 SecureDevice : 0y0
+0x004 ChildOfVgaEnabledBridge : 0y0
+0x004 DecodeIoOnBoot : 0y0
+0x004 Reserved : 0y000000000 (0)
+0x008 Address : 1
+0x00c UINumber : 0xffffffff
+0x010 DeviceState : [7] 0 ( PowerDeviceUnspecified )
+0x02c SystemWake : 5 ( PowerSystemHibernate )
+0x030 DeviceWake : 3 ( PowerDeviceD2 )
+0x034 D1Latency : 0
+0x038 D2Latency : 0
+0x03c D3Latency : 0