Skip to content

Commit

Permalink
Added support to show security info in Wi-Fi Advanced settings. (#210)
Browse files Browse the repository at this point in the history
- Moved `get_security_type` to Api.c
	- Rearranged network list to fetch all items (including sta) so we can get security info.
  • Loading branch information
ErrorErrorError authored Jan 14, 2021
1 parent 68a9cd5 commit fcbf4b9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 48 deletions.
86 changes: 79 additions & 7 deletions ClientKit/Api.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,42 @@

static pthread_mutex_t* api_mutex = NULL;

enum itl80211_security get_security_type(struct ioctl_network_info info) {
if ((info.supported_rsnprotos & ITL80211_PROTO_RSN) != 0) {
//wpa2
if ((info.rsn_akms & ITL80211_AKM_8021X) != 0) {
if ((info.supported_rsnprotos & ITL80211_PROTO_WPA) != 0) {
return ITL80211_SECURITY_WPA_ENTERPRISE_MIXED;
}
return ITL80211_SECURITY_WPA2_ENTERPRISE;
} else if ((info.rsn_akms & ITL80211_AKM_PSK) != 0) {
if ((info.supported_rsnprotos & ITL80211_PROTO_WPA) != 0) {
return ITL80211_SECURITY_WPA_PERSONAL_MIXED;
}
return ITL80211_SECURITY_WPA2_PERSONAL;
} else if ((info.rsn_akms & ITL80211_AKM_SHA256_8021X) != 0) {
return ITL80211_SECURITY_WPA2_ENTERPRISE;
} else if ((info.rsn_akms & ITL80211_AKM_SHA256_PSK) != 0) {
return ITL80211_SECURITY_PERSONAL;
}
} else if ((info.supported_rsnprotos & ITL80211_PROTO_WPA) != 0) {
//wpa
if ((info.rsn_akms & ITL80211_AKM_8021X) != 0) {
return ITL80211_SECURITY_WPA_ENTERPRISE;
} else if ((info.rsn_akms & ITL80211_AKM_PSK) != 0) {
return ITL80211_SECURITY_WPA_PERSONAL;
} else if ((info.rsn_akms & ITL80211_AKM_SHA256_8021X) != 0) {
return ITL80211_SECURITY_WPA_ENTERPRISE;
} else if ((info.rsn_akms & ITL80211_AKM_SHA256_PSK) != 0) {
return ITL80211_SECURITY_ENTERPRISE;
}
} else if (info.supported_rsnprotos == 0) {
return ITL80211_SECURITY_NONE;
}
//TODO wpa3
return ITL80211_SECURITY_UNKNOWN;
}

bool get_platform_info(platform_info_t *info) {
memset(info, 0, sizeof(platform_info_t));

Expand Down Expand Up @@ -65,17 +101,14 @@ bool get_80211_state(uint32_t *state) {
return false;
}

bool get_network_list(network_info_list_t *list) {
bool get_networks(network_info_list_t *list) {
memset(list, 0, sizeof(network_info_list_t));

struct ioctl_scan scan;
struct ioctl_network_info network_info_ret;
io_connect_t con;
struct ioctl_sta_info sta_info;
scan.version = IOCTL_VERSION;

get_station_info(&sta_info);

if (!open_adapter(&con)) {
goto error;
}
Expand All @@ -84,9 +117,6 @@ bool get_network_list(network_info_list_t *list) {
if (list->count >= MAX_NETWORK_LIST_LENGTH) {
break;
}
if (strlen(sta_info.ssid) > 0 && memcmp(sta_info.bssid, network_info_ret.bssid, ETHER_ADDR_LEN) == 0) {
continue;
}
struct ioctl_network_info *info = &list->networks[list->count++];
memcpy(info, &network_info_ret, sizeof(struct ioctl_network_info));
}
Expand All @@ -101,6 +131,48 @@ bool get_network_list(network_info_list_t *list) {
return false;
}

bool get_network_list(network_info_list_t *list) {
bool return_value = get_networks(list);

if (return_value) {
// Remove sta from list if available
struct ioctl_sta_info sta_info;
get_station_info(&sta_info);
for (int i = 0; i < list->count; i++) {
struct ioctl_network_info* info = &list->networks[i];
if (strlen(sta_info.ssid) > 0 && memcmp(sta_info.bssid, info->bssid, ETHER_ADDR_LEN) == 0) {
// Replace sta network with last element in list and replace the last element in array with zero.
memset(info, 0, sizeof(struct ioctl_network_info));
if (i + 1 < list->count) {
struct ioctl_network_info replaceWith = list->networks[list->count - 1];
list->networks[i] = replaceWith;
memset(&list->networks[list->count - 1], 0, sizeof(struct ioctl_network_info));
}
list->count--;
break;
}
}
}

return return_value;
}

enum itl80211_security get_security_info_sta(station_info_t *sta_info) {
enum itl80211_security security = ITL80211_SECURITY_UNKNOWN;
network_info_list_t *list = (network_info_list_t *) malloc(sizeof(network_info_list_t));
if (get_networks(list)) {
for (int i = 0; i < list->count; i++) {
struct ioctl_network_info info = list->networks[i];
if (strlen(sta_info->ssid) > 0 && memcmp(sta_info->bssid, info.bssid, ETHER_ADDR_LEN) == 0) {
security = get_security_type(info);
break;
}
}
}
free(list);
return security;
}

bool connect_network(const char *ssid, const char *pwd) {
if (associate_ssid(ssid, pwd) != KERN_SUCCESS) {
goto error;
Expand Down
4 changes: 4 additions & 0 deletions ClientKit/Api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ typedef struct {

typedef struct ioctl_sta_info station_info_t;

enum itl80211_security get_security_info_sta(station_info_t *sta_info);

enum itl80211_security get_security_type(struct ioctl_network_info info);

bool open_adapter(io_connect_t *connection_t);

void close_adapter(io_connect_t connection);
Expand Down
5 changes: 2 additions & 3 deletions HeliPort/Appearance/StatusMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ final class StatusMenu: NSMenu, NSMenuDelegate {
enableLoggingItem,
diagnoseItem,

securityItem,
countryCodeItem,
nssItem,

Expand Down Expand Up @@ -506,7 +505,7 @@ final class StatusMenu: NSMenu, NSMenuDelegate {
ipAddr = ipAddress ?? .unknown
routerAddr = routerAddress ?? .unknown
internet = isReachable ? .reachable : .unreachable
security = .unknown
security = "\(get_security_info_sta(&staInfo))"
bssid = String(format: "%02x:%02x:%02x:%02x:%02x:%02x",
staInfo.bssid.0,
staInfo.bssid.1,
Expand All @@ -520,7 +519,7 @@ final class StatusMenu: NSMenu, NSMenuDelegate {
rssi = "\(staInfo.rssi) dBm"
noise = "\(staInfo.noise) dBm"
txRate = "\(staInfo.rate) Mbps"
phyMode = staInfo.op_mode.description
phyMode = "\(staInfo.op_mode)"
mcsIndex = "\(staInfo.cur_mcs)"
nss = .unknown
}
Expand Down
38 changes: 1 addition & 37 deletions HeliPort/NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ final class NetworkManager {
ssid: ssid,
rssi: Int(network.rssi)
)
networkInfo.auth.security = getSecurityType(network)
networkInfo.auth.security = get_security_type(network)
result.insert(networkInfo)
}

Expand Down Expand Up @@ -253,40 +253,4 @@ final class NetworkManager {
// ipV4 has priority
return ipV4 ?? ipV6
}

class func getSecurityType(_ info: ioctl_network_info) -> itl80211_security {
if info.supported_rsnprotos & ITL80211_PROTO_RSN.rawValue != 0 {
//wpa2
if info.rsn_akms & ITL80211_AKM_8021X.rawValue != 0 {
if info.supported_rsnprotos & ITL80211_PROTO_WPA.rawValue != 0 {
return ITL80211_SECURITY_WPA_ENTERPRISE_MIXED
}
return ITL80211_SECURITY_WPA2_ENTERPRISE
} else if info.rsn_akms & ITL80211_AKM_PSK.rawValue != 0 {
if info.supported_rsnprotos & ITL80211_PROTO_WPA.rawValue != 0 {
return ITL80211_SECURITY_WPA_PERSONAL_MIXED
}
return ITL80211_SECURITY_WPA2_PERSONAL
} else if info.rsn_akms & ITL80211_AKM_SHA256_8021X.rawValue != 0 {
return ITL80211_SECURITY_WPA2_ENTERPRISE
} else if info.rsn_akms & ITL80211_AKM_SHA256_PSK.rawValue != 0 {
return ITL80211_SECURITY_PERSONAL
}
} else if info.supported_rsnprotos & ITL80211_PROTO_WPA.rawValue != 0 {
//wpa
if info.rsn_akms & ITL80211_AKM_8021X.rawValue != 0 {
return ITL80211_SECURITY_WPA_ENTERPRISE
} else if info.rsn_akms & ITL80211_AKM_PSK.rawValue != 0 {
return ITL80211_SECURITY_WPA_PERSONAL
} else if info.rsn_akms & ITL80211_AKM_SHA256_8021X.rawValue != 0 {
return ITL80211_SECURITY_WPA_ENTERPRISE
} else if info.rsn_akms & ITL80211_AKM_SHA256_PSK.rawValue != 0 {
return ITL80211_SECURITY_ENTERPRISE
}
} else if info.supported_rsnprotos == 0 {
return ITL80211_SECURITY_NONE
}
//TODO wpa3
return ITL80211_SECURITY_UNKNOWN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension itl80211_security: CustomStringConvertible {
case ITL80211_SECURITY_WPA3_TRANSITION:
return "WPA3 Transition"
default:
return "Unknown"
return NSLocalizedString("Unknown")
}
}
}
Expand Down

0 comments on commit fcbf4b9

Please # to comment.