Skip to content

Commit e025f28

Browse files
committed
Wifi (macOS): removes wdutil-based Wi-Fi detection code
Let's stop this hide and seek game.
1 parent 3ece4e3 commit e025f28

File tree

1 file changed

+1
-189
lines changed

1 file changed

+1
-189
lines changed

src/detection/wifi/wifi_apple.m

Lines changed: 1 addition & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -52,184 +52,7 @@ static bool getWifiInfoByIpconfig(FFstrbuf* ipconfig, const char* prefix, FFstrb
5252
return true;
5353
}
5454

55-
static const char* detectByWdutil(FFlist* result)
56-
{
57-
FF_STRBUF_AUTO_DESTROY wdutil = ffStrbufCreate();
58-
59-
if (geteuid() != 0)
60-
return "wdutil requires root privileges to run";
61-
62-
bool ok = ffProcessAppendStdOut(&wdutil, (char* const[]) {
63-
"/usr/bin/wdutil",
64-
"info",
65-
NULL
66-
}) == NULL;
67-
if (!ok) return "Failed to run wdutil info command";
68-
69-
// ...
70-
// ————————————————————————————————————————————————————————————————————
71-
// WIFI
72-
// ————————————————————————————————————————————————————————————————————
73-
// <WIFI INFO>
74-
// ————————————————————————————————————————————————————————————————————
75-
// ...
76-
77-
{
78-
// Remove unrelated lines
79-
uint32_t start = ffStrbufFirstIndexS(&wdutil, "\nWIFI\n");
80-
if (start >= wdutil.length)
81-
return "wdutil info command did not return WIFI section (1)";
82-
83-
start += 6; // Skip "\nWIFI\n"
84-
start = ffStrbufNextIndexC(&wdutil, start, '\n');
85-
if (start >= wdutil.length)
86-
return "wdutil info command did not return WIFI section (2)";
87-
start++;
88-
89-
uint32_t end = ffStrbufNextIndexS(&wdutil, start, "\n——————————");
90-
91-
ffStrbufSubstr(&wdutil, start, end);
92-
}
93-
94-
95-
// `wdutil info <interface>` returns a string like this:
96-
// MAC Address : xx:xx:xx:xx:xx:xx (hw=xx:xx:xx:xx:xx:xx)
97-
// Interface Name : en0
98-
// Power : On [On]
99-
// Op Mode : STA
100-
// SSID : XXX-XXX
101-
// BSSID : xx:xx:xx:xx:xx:xx
102-
// RSSI : -58 dBm
103-
// CCA : 29 %
104-
// Noise : -96 dBm
105-
// Tx Rate : 173.0 Mbps
106-
// Security : WPA2 Enterprise
107-
// 802.1X Mode : User
108-
// 802.1X Supplicant : Authenticated
109-
// PHY Mode : 11ac
110-
// MCS Index : 8
111-
// Guard Interval : 400
112-
// NSS : 2
113-
// Channel : 5g165/20
114-
// Country Code : CN
115-
// Scan Cache Count : 28
116-
// NetworkServiceID : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
117-
// IPv4 Config Method : DHCP
118-
// IPv4 Address : xx.xx.xx.xx
119-
// IPv4 Router : xx.xx.xx.x
120-
// IPv6 Config Method : Automatic
121-
// IPv6 Address : xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
122-
// IPv6 Router : None
123-
// DNS : xxx.xxx.xxx.xxx
124-
// : xxx.xxx.xxx.xxx
125-
// BTC Mode : Off
126-
// Desense :
127-
// Chain Ack : []
128-
// BTC Profile 2.4GHz : Disabled
129-
// BTC Profile 5GHz : Disabled
130-
// Sniffer Supported : YES
131-
// Supports 6e : No
132-
// Supported Channels : 2g1/20,2g2/20,2g3/20,2g4/20,2g5/20,2g6/20,2g7/20,2g8/20,2g9/20,2g10/20,2g11/20,2g12/20,2g13/20,5g36/20,5g40/20,5g44/20,5g48/20,5g52/20,5g56/20,5g60/20,5g64/20,5g149/20,5g153/20,5g157/20,5g161/20,5g165/20,5g36/40,5g40/40,5g44/40,5g48/40,5g52/40,5g56/40,5g60/40,5g64/40,5g149/40,5g153/40,5g157/40,5g161/40,5g36/80,5g40/80,5g44/80,5g48/80,5g52/80,5g56/80,5g60/80,5g64/80,5g149/80,5g153/80,5g157/80,5g161/80
133-
134-
FFWifiResult* item = (FFWifiResult*) ffListAdd(result);
135-
ffStrbufInit(&item->inf.description);
136-
ffStrbufInit(&item->inf.status);
137-
ffStrbufInit(&item->conn.status);
138-
ffStrbufInit(&item->conn.ssid);
139-
ffStrbufInit(&item->conn.bssid);
140-
ffStrbufInit(&item->conn.protocol);
141-
ffStrbufInit(&item->conn.security);
142-
item->conn.signalQuality = -DBL_MAX;
143-
item->conn.rxRate = -DBL_MAX;
144-
item->conn.txRate = -DBL_MAX;
145-
item->conn.channel = 0;
146-
item->conn.frequency = 0;
147-
148-
char* line = NULL;
149-
size_t len = 0;
150-
while (ffStrbufGetline(&line, &len, &wdutil))
151-
{
152-
const char* key = line + 4; // Skip " "
153-
const char* value = key + strlen("MAC Address : ");
154-
switch (key[0] << 24 | key[1] << 16 | key[2] << 8 | key[3])
155-
{
156-
case 'Inte': // Interface Name
157-
ffStrbufAppendS(&item->inf.description, value);
158-
break;
159-
case 'Powe': // Power
160-
if (ffStrStartsWith(value, "On "))
161-
ffStrbufSetStatic(&item->inf.status, "Power On");
162-
else
163-
ffStrbufSetStatic(&item->inf.status, "Power Off");
164-
break;
165-
case 'SSID': // SSID
166-
ffStrbufAppendS(&item->conn.ssid, value);
167-
break;
168-
case 'BSSI': // BSSID
169-
if (ffStrEquals(value, "None") && ffStrbufEqualS(&item->conn.ssid, "None"))
170-
{
171-
ffStrbufSetStatic(&item->conn.status, "Inactive");
172-
ffStrbufClear(&item->conn.ssid); // None
173-
return NULL;
174-
}
175-
ffStrbufSetStatic(&item->conn.status, "Active");
176-
ffStrbufAppendS(&item->conn.bssid, value);
177-
break;
178-
case 'RSSI': // RSSI
179-
item->conn.signalQuality = rssiToSignalQuality((int) strtol(value, NULL, 10));
180-
break;
181-
case 'Tx R': // Tx Rate
182-
item->conn.txRate = strtod(value, NULL);
183-
break;
184-
case 'Secu': // Security
185-
if (ffStrEquals(value, "None"))
186-
ffStrbufSetStatic(&item->conn.security, "Insecure");
187-
else
188-
ffStrbufAppendS(&item->conn.security, value);
189-
break;
190-
case 'PHY ': // PHY Mode
191-
if (ffStrEquals(value, "None"))
192-
ffStrbufSetStatic(&item->conn.protocol, "none");
193-
else if (ffStrEquals(value, "11a"))
194-
ffStrbufSetStatic(&item->conn.protocol, "802.11a");
195-
else if (ffStrEquals(value, "11b"))
196-
ffStrbufSetStatic(&item->conn.protocol, "802.11b");
197-
else if (ffStrEquals(value, "11g"))
198-
ffStrbufSetStatic(&item->conn.protocol, "802.11g");
199-
else if (ffStrEquals(value, "11n"))
200-
ffStrbufSetStatic(&item->conn.protocol, "802.11n (Wi-Fi 4)");
201-
else if (ffStrEquals(value, "11ac"))
202-
ffStrbufSetStatic(&item->conn.protocol, "802.11ac (Wi-Fi 5)");
203-
else if (ffStrEquals(value, "11ax"))
204-
ffStrbufSetStatic(&item->conn.protocol, "802.11ax (Wi-Fi 6)");
205-
else if (ffStrEquals(value, "11be"))
206-
ffStrbufSetStatic(&item->conn.protocol, "802.11be (Wi-Fi 7)");
207-
else
208-
ffStrbufAppendS(&item->conn.protocol, value);
209-
break;
210-
case 'Chan': // Channel
211-
{
212-
int band, channel;
213-
if (sscanf(value, "%dg%d", &band, &channel) == 2)
214-
{
215-
item->conn.channel = (uint16_t) channel;
216-
switch (band)
217-
{
218-
case 2: item->conn.frequency = 2400; break;
219-
case 5: item->conn.frequency = 5400; break;
220-
case 6: item->conn.frequency = 6400; break;
221-
default: item->conn.frequency = 0; break;
222-
}
223-
}
224-
break;
225-
}
226-
}
227-
}
228-
229-
return NULL;
230-
}
231-
232-
static const char* detectByCoreWlan(FFlist* result)
55+
const char* ffDetectWifi(FFlist* result)
23356
{
23457
NSArray<CWInterface*>* interfaces = CWWiFiClient.sharedWiFiClient.interfaces;
23558
if (!interfaces)
@@ -382,14 +205,3 @@ static bool getWifiInfoByIpconfig(FFstrbuf* ipconfig, const char* prefix, FFstrb
382205

383206
return NULL;
384207
}
385-
386-
const char* ffDetectWifi(FFlist* result)
387-
{
388-
if (@available(macOS 15.6, *))
389-
{
390-
if (detectByWdutil(result) == NULL)
391-
return NULL;
392-
}
393-
394-
return detectByCoreWlan(result);
395-
}

0 commit comments

Comments
 (0)