|  | 
| 4 | 4 | 
 | 
| 5 | 5 | #import <CoreWLAN/CoreWLAN.h> | 
| 6 | 6 | 
 | 
| 7 |  | -struct Apple80211; // https://code.google.com/archive/p/iphone-wireless/wikis/Apple80211.wiki | 
| 8 |  | - | 
| 9 |  | -// 0 is successful; < 0 is failure | 
| 10 |  | -int Apple80211GetInfoCopy(struct Apple80211 *handle, CFDictionaryRef *info) __attribute__((weak_import)); | 
| 11 |  | - | 
| 12 |  | -@interface CWInterface() | 
| 13 |  | -@property (readonly) struct Apple80211* device; | 
| 14 |  | -@end | 
| 15 |  | - | 
| 16 |  | -inline static NSDictionary* getWifiInfoByApple80211(CWInterface* inf) | 
| 17 |  | -{ | 
| 18 |  | -    if (!inf.device || !Apple80211GetInfoCopy) return NULL; | 
| 19 |  | -    CFDictionaryRef result = NULL; | 
| 20 |  | -    if (Apple80211GetInfoCopy(inf.device, &result) < 0) return NULL; | 
| 21 |  | -    return CFBridgingRelease(result); | 
| 22 |  | -} | 
| 23 |  | - | 
| 24 | 7 | static bool queryIpconfig(const char* ifName, FFstrbuf* result) | 
| 25 | 8 | { | 
| 26 | 9 |     return ffProcessAppendStdOut(result, (char* const[]) { | 
| @@ -89,22 +72,17 @@ static bool getWifiInfoByIpconfig(FFstrbuf* ipconfig, const char* prefix, FFstrb | 
| 89 | 72 |         if(inf.interfaceMode == kCWInterfaceModeNone) | 
| 90 | 73 |             continue; | 
| 91 | 74 | 
 | 
| 92 |  | -        NSDictionary* apple = nil; // For getWifiInfoByApple80211 | 
| 93 | 75 |         FF_STRBUF_AUTO_DESTROY ipconfig = ffStrbufCreate(); | 
| 94 | 76 | 
 | 
| 95 | 77 |         if (inf.ssid) // https://developer.apple.com/forums/thread/732431 | 
| 96 | 78 |             ffStrbufAppendS(&item->conn.ssid, inf.ssid.UTF8String); | 
| 97 |  | -        else if (apple || (apple = getWifiInfoByApple80211(inf))) | 
| 98 |  | -            ffStrbufAppendS(&item->conn.ssid, [apple[@"SSID_STR"] UTF8String]); | 
| 99 | 79 |         else if (ipconfig.length || (queryIpconfig(item->inf.description.chars, &ipconfig))) | 
| 100 | 80 |             getWifiInfoByIpconfig(&ipconfig, "\n  SSID : ", &item->conn.ssid); | 
| 101 | 81 |         else | 
| 102 | 82 |             ffStrbufSetStatic(&item->conn.ssid, "<unknown ssid>"); // https://developer.apple.com/forums/thread/732431 | 
| 103 | 83 | 
 | 
| 104 | 84 |         if (inf.bssid) | 
| 105 | 85 |             ffStrbufAppendS(&item->conn.bssid, inf.bssid.UTF8String); | 
| 106 |  | -        else if (apple || (apple = getWifiInfoByApple80211(inf))) | 
| 107 |  | -            ffStrbufAppendS(&item->conn.bssid, [apple[@"BSSID"] UTF8String]); | 
| 108 | 86 |         else if (ipconfig.length || (queryIpconfig(item->inf.description.chars, &ipconfig))) | 
| 109 | 87 |             getWifiInfoByIpconfig(&ipconfig, "\n  BSSID : ", &item->conn.bssid); | 
| 110 | 88 | 
 | 
| @@ -193,63 +171,8 @@ static bool getWifiInfoByIpconfig(FFstrbuf* ipconfig, const char* prefix, FFstrb | 
| 193 | 171 |                 ffStrbufSetStatic(&item->conn.security, "OWE Transition"); | 
| 194 | 172 |                 break; | 
| 195 | 173 |             case kCWSecurityUnknown: | 
| 196 |  | -                // Sonoma... | 
| 197 |  | -                if (apple || (apple = getWifiInfoByApple80211(inf))) | 
| 198 |  | -                { | 
| 199 |  | -                    NSDictionary* authType = apple[@"AUTH_TYPE"]; | 
| 200 |  | -                    if (authType) | 
| 201 |  | -                    { | 
| 202 |  | -                        // AUTH_LOWER seems useless. `airport` verifies if its value is between 1 and 3, and prints `unknown` if not | 
| 203 |  | - | 
| 204 |  | -                        NSNumber* authUpper = authType[@"AUTH_UPPER"]; | 
| 205 |  | -                        if (!authUpper) | 
| 206 |  | -                            ffStrbufSetStatic(&item->conn.security, "Insecure"); | 
| 207 |  | -                        else | 
| 208 |  | -                        { | 
| 209 |  | -                            int authUpperValue = authUpper.intValue; | 
| 210 |  | -                            switch (authUpperValue) | 
| 211 |  | -                            { | 
| 212 |  | -                                case 1: | 
| 213 |  | -                                    ffStrbufSetStatic(&item->conn.security, "WPA"); | 
| 214 |  | -                                    break; | 
| 215 |  | -                                case 2: | 
| 216 |  | -                                    ffStrbufSetStatic(&item->conn.security, "WPA-PSK"); | 
| 217 |  | -                                    break; | 
| 218 |  | -                                case 4: | 
| 219 |  | -                                    ffStrbufSetStatic(&item->conn.security, "WPA2"); | 
| 220 |  | -                                    break; | 
| 221 |  | -                                case 8: | 
| 222 |  | -                                    ffStrbufSetStatic(&item->conn.security, "WPA2-PSK"); | 
| 223 |  | -                                    break; | 
| 224 |  | -                                case 16: | 
| 225 |  | -                                    ffStrbufSetStatic(&item->conn.security, "FT-WPA2-PSK"); | 
| 226 |  | -                                    break; | 
| 227 |  | -                                case 32: | 
| 228 |  | -                                    ffStrbufSetStatic(&item->conn.security, "LEAP"); | 
| 229 |  | -                                    break; | 
| 230 |  | -                                case 64: | 
| 231 |  | -                                    ffStrbufSetStatic(&item->conn.security, "802.1X"); | 
| 232 |  | -                                    break; | 
| 233 |  | -                                case 128: | 
| 234 |  | -                                    ffStrbufSetStatic(&item->conn.security, "FT-WPA2"); | 
| 235 |  | -                                    break; | 
| 236 |  | -                                case 256: | 
| 237 |  | -                                    ffStrbufSetStatic(&item->conn.security, "WPS"); | 
| 238 |  | -                                    break; | 
| 239 |  | -                                case 4096: | 
| 240 |  | -                                    ffStrbufSetStatic(&item->conn.security, "WPA3-SAE"); | 
| 241 |  | -                                    break; | 
| 242 |  | -                                case 8192: | 
| 243 |  | -                                    ffStrbufSetStatic(&item->conn.security, "WPA3-FT-SAE"); | 
| 244 |  | -                                    break; | 
| 245 |  | -                                default: // TODO: support more auth types | 
| 246 |  | -                                    ffStrbufAppendF(&item->conn.security, "To be supported (%d)", authUpperValue); | 
| 247 |  | -                                    break; | 
| 248 |  | -                            } | 
| 249 |  | -                        } | 
| 250 |  | -                    } | 
| 251 |  | -                } | 
| 252 |  | -                else if (ipconfig.length || (queryIpconfig(item->inf.description.chars, &ipconfig))) | 
|  | 174 | +                // Sonoma? | 
|  | 175 | +                if (ipconfig.length || (queryIpconfig(item->inf.description.chars, &ipconfig))) | 
| 253 | 176 |                     getWifiInfoByIpconfig(&ipconfig, "\n  Security : ", &item->conn.security); | 
| 254 | 177 |                 break; | 
| 255 | 178 |             default: | 
|  | 
0 commit comments