Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lasers authored and brndnmtthws committed Oct 11, 2018
1 parent 30c19a1 commit 1e2a296
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmake/ConkyPlatformChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 59 additions & 1 deletion src/darwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1e2a296

Please sign in to comment.