From 1e2a29654fefc85e66cbae91808f7d37b96c6b14 Mon Sep 17 00:00:00 2001 From: lasers Date: Thu, 11 Oct 2018 07:45:43 -0500 Subject: [PATCH] Wifi (#660) * Work for #17 : Now we have ssid * Since we are using Objective-C++ NSStrings, we need to link to Foundation.framework, too! * If interface is UP use the interface SSID; otherwise "off/any" following the Linux implementation. Add more * More * cleanup --- cmake/ConkyPlatformChecks.cmake | 2 ++ src/darwin.mm | 60 ++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index b373f3e41..2596e2953 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -139,7 +139,9 @@ endif(BUILD_NCURSES AND OS_DARWIN) if(BUILD_WLAN AND OS_DARWIN) find_library(CW CoreWLAN) + find_library(NS Foundation) set(conky_libs ${conky_libs} ${CW}) + set(conky_libs ${conky_libs} ${NS}) endif(BUILD_WLAN AND OS_DARWIN) if(OS_DARWIN AND BUILD_IPGFREQ) diff --git a/src/darwin.mm b/src/darwin.mm index 84402749c..4cbd28f6f 100644 --- a/src/darwin.mm +++ b/src/darwin.mm @@ -652,10 +652,68 @@ int update_meminfo() { #ifdef BUILD_WLAN void update_wlan_stats(struct net_stat *ns) { + CWWiFiClient *client = [CWWiFiClient sharedWiFiClient]; + CWInterface *interface = [client interfaceWithName:[NSString stringWithUTF8String:ns->dev]]; + if (!interface) + return; + + const char *essid = (ns->up) ? [interface ssid].UTF8String : "off/any"; + const char *freq = "Unknown"; + const char *bitrate = [NSString stringWithFormat:@"%f", [interface transmitRate]].UTF8String; + const char *mode = "Unknown"; + const char *ap = [interface hardwareAddress].UTF8String; + + if (essid == nullptr || bitrate == nullptr || ap == nullptr) + return; + + /* + * Freq + */ + switch ([interface wlanChannel].channelBand) { + case kCWChannelBand2GHz: + freq = "2 GHz"; + break; + case kCWChannelBand5GHz: + freq = "5 GHz"; + break; + case kCWChannelBandUnknown: + default: + break; + } + + /* + * Mode + */ + switch ([interface interfaceMode]) { + case kCWInterfaceModeStation: + mode = "Managed"; + break; + case kCWInterfaceModeIBSS: + mode = "Ad-Hoc"; + break; + case kCWInterfaceModeHostAP: + mode = "Master"; + break; + case kCWInterfaceModeNone: + default: + break; + } + + /* + * Setup + */ + memcpy(ns->essid, essid, sizeof(char)*strlen(essid)); + ns->channel = interface.wlanChannel.channelNumber; + memcpy(ns->freq, freq, sizeof(char)*strlen(freq)); + memcpy(ns->bitrate, bitrate, sizeof(char)*strlen(bitrate)); + memcpy(ns->mode, mode, sizeof(char)*strlen(mode)); + ns->link_qual = 0; + ns->link_qual_max = 0; + memcpy(ns->ap, ap, sizeof(char)*strlen(ap)); } -#endif +#endif /* BUILD_WLAN */ int update_net_stats() { struct net_stat *ns;