Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wifi #660

Merged
merged 5 commits into from
Oct 11, 2018
Merged

Wifi #660

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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