Windows 10 does not detect Wi-Fi as metered connection
I want Windows Wi-Fi client to detect wireless connection as metered connection. I found that 802.11 protocol supports vendor-specific information elements (IEs). Those IEs are injected into beacon and probe response wireless frames.
I found that Microsoft defined It's own vendor-specific IE to inform clients about metered connection over Wi-Fi (Network Cost Element) and my access point's hostapd supports vendor-specific features.
According to documentation for (Network Cost Element), I added vendor-specific field to hostapd
on my OpenWRT router:
0xDD (Vendor-specific record)
0x08 (Record length : 8 bytes)
0x00 0x50 0xF2 (Vendor: Microsoft)
0x11 (OUI Type: Network Cost)
0x00 0x00 0x00 0x02 (Portable Hotspot Default: Metered network; limit unknown or not yet reached; matches Windows default for mobile broadband connections.)
hostapd on openwrt commands:
ubus call hostapd.wlan24 set_vendor_elements '{"vendor_elements": "dd080050f21100000002"}'
ubus call hostapd.wlan24 update_beacon
Using CommView, I capture wireless traffic and I see that in Probe Response and Beacon frames there is data I supplied to hostapd (last 10 bytes).
0x0000 80 00 00 00 FF FF FF FF-FF FF XX XX XX XX XX XX €...ÿÿÿÿÿÿXXXXXX
0x0010 EC 41 18 50 A7 35 00 8E-99 81 50 23 98 00 00 00 ìA.P§5.Ž™.P#˜...
0x0020 64 00 31 04 00 1B YY YY-YY YY YY YY YY YY YY YY d.1...YYYYYYYYYY
0x0030 YY YY YY YY YY YY YY YY-YY YY YY YY YY YY YY YY YYYYYYYYYYYYYYYY
0x0040 XX 01 08 82 84 8B 96 0C-12 18 24 03 01 0B 05 04 Y..‚„‹–...$.....
0x0050 00 02 00 00 2A 01 00 32-04 30 48 60 6C 30 14 01 ....*..2.0H`l0..
0x0060 00 00 0F AC 04 01 00 00-0F AC 04 01 00 00 0F AC ...¬.....¬.....¬
0x0070 02 0C 00 0B 05 04 00 08-00 00 3B 02 51 00 2D 1A ..........;.Q.-.
0x0080 EC 01 17 FF FF 00 00 00-00 00 00 00 00 00 00 01 ì..ÿÿ...........
0x0090 00 00 00 00 00 00 00 00-00 00 3D 16 0B 00 04 00 ..........=.....
0x00A0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0x00B0 00 00 7F 08 04 00 00 00-00 00 01 40 DD 18 00 50 ...........@Ý..P
0x00C0 F2 02 01 01 01 00 03 A4-00 00 27 A4 00 00 42 43 ò......¤..'¤..BC
0x00D0 5E 00 62 32 2F 00 DD 08-00 50 F2 11 00 00 00 02 ^.b2/.Ý..Pò.....
I connect to this AP and check if connection is metered using MS Powershell on Windows PC:
[void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
[Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost()
And get response
ApproachingDataLimit : False
NetworkCostType : Unrestricted
OverDataLimit : False
Roaming : False
BackgroundDataUsageRestricted : False
Where NetworkCostType
is either Unrestricted
or Unknown
instead of expected Fixed
.
When I manually set on Windows PC this connection as metered, powershell says NetworkCostType : Fixed
Some time later I found another AP (not mine, hidden) that is broadcasting beacons.
In those beacons, I found that same vendor-specific extension 0x11
by Microsoft
is 16 bytes length and is
DD 10 00 50 F2 11 | 01 10 02 28 2C 30 00 00 00 01 00 00
or
DD 10 00 50 F2 11 | 01 10 02 28 2C 30 00 00 00 00 00 00 (deffers 3rd byte from the end)
0x0000 80 00 00 00 FF FF FF FF-FF FF 62 45 BD 07 36 9A €...ÿÿÿÿÿÿbE½.6š
0x0010 62 45 BD 07 36 9A 80 71-87 80 70 00 00 00 00 00 bE½.6š€q‡€p.....
0x0020 64 00 31 C6 00 00 DD 10-00 50 F2 11 01 10 02 28 d.1Æ..Ý..Pò....(
0x0030 2C 30 00 00 00 01 00 00- ,0......
---
0x0000 80 00 00 00 FF FF FF FF-FF FF 62 45 BD 07 36 9A €...ÿÿÿÿÿÿbE½.6š
0x0010 62 45 BD 07 36 9A D0 B4-16 FE 38 03 00 00 00 00 bE½.6šÐ´.þ8.....
0x0020 64 00 31 C6 00 00 DD 10-00 50 F2 11 01 10 02 28 d.1Æ..Ý..Pò....(
0x0030 2C 30 00 00 00 00 00 00- ,0......
I found that OUI 0x11
and Vendor 0x00 0x50 0xF2
are same - maybe MS Docs are wrong?
I've tried same on my access point with same result - data is in wireless frames, but Windows 10 does not sets connection as metered.
Any help? Maybe I made mistake somewhere? Maybe It is Wireless driver-dependent? Maybe MS have docs but did not implemented it in desktop systems?
Setting Metered connection
manually is not the way I want to solve this problem.
Solution 1:
- There is a mistake in MS Docs:
Correct packet is
DD080050F211??00**00
, where??
isCost Level
and**
isCost Flags
Cost Levels:
-
00 Unknown
- The connection cost is unknown. -
01 Unrestricted
- The connection is unlimited and has unrestricted usage constraints. -
02 Fixed
- Usage counts toward a fixed allotment of data which the user has already paid for (or agreed to pay for). -
04 Variable
- The connection cost is on a per-byte basis.
Cost Flags:
-
00 Unknown
- The usage is unknown or unrestricted. -
01 Over Data Limit
- Usage has exceeded the data limit of the metered network; different network costs or conditions might apply. -
02 Congested
- The network operator is experiencing or expecting heavy load. -
04 Roaming
- The tethering connection is roaming outside the provider's home network or affiliates. -
08 Approaching Data Limit
- Usage is near the data limit of the metered network; different network costs or conditions might apply once the limit is reached.
Correct MS Docs MS-NCT
- Seems that when you manually trigger the
Metered connection
switch, Windows ignores 802.11 IE until you forget network (or maybe not).
For OpenWRT access point my epic issue resulting in 4 commands
uci add_list wireless.radio0.hostapd_options='vendor_elements=DD080050F21102000200'
uci add_list wireless.radio1.hostapd_options='vendor_elements=DD080050F21102000200'
uci commit
reboot
I've added Fixed
cost level with Congested
flag. Don't know if Congested affects anything.
hostapd_options
is undocumented parameter in /etc/config/wireless (or uci radio?.hostapd_options
), but it exists since 2017