summaryrefslogtreecommitdiff
path: root/src/print_wireless_info.c
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@users.noreply.github.com>2020-04-21 09:52:13 +0200
committerGitHub <noreply@github.com>2020-04-21 09:52:13 +0200
commit57218e98de20ef2a779f4b33a6d742d52a0bf0f8 (patch)
treeba7ce22a314c266a7160b77f42cf5822dccf920f /src/print_wireless_info.c
parentd088baea4f295974ff7e705283cf979eebc58c46 (diff)
parent7191cce8e9eed4350d0e3087a81aa6dfcb662f7b (diff)
Merge pull request #408 from TimonAlex/freebsd-wifi-bitrate
Fix rendering wireless bitrate and support bitrate on FreeBSD
Diffstat (limited to 'src/print_wireless_info.c')
-rw-r--r--src/print_wireless_info.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/print_wireless_info.c b/src/print_wireless_info.c
index ad20645..cfb51b6 100644
--- a/src/print_wireless_info.c
+++ b/src/print_wireless_info.c
@@ -97,7 +97,7 @@ typedef struct {
double frequency;
} wireless_info_t;
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
// Like iw_print_bitrate, but without the dependency on libiw.
static void print_bitrate(char *buffer, int buflen, int bitrate, const char *format_bitrate) {
const int kilo = 1e3;
@@ -120,7 +120,9 @@ static void print_bitrate(char *buffer, int buflen, int bitrate, const char *for
}
snprintf(buffer, buflen, format_bitrate, rate / divisor, scale);
}
+#endif
+#ifdef __linux__
// Based on NetworkManager/src/platform/wifi/wifi-utils-nl80211.c
static uint32_t nl80211_xbm_to_percent(int32_t xbm, int32_t divisor) {
#define NOISE_FLOOR_DBM -90
@@ -408,6 +410,9 @@ error1:
info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
info->noise_level = u.req.info[0].isi_noise;
info->flags |= WIRELESS_INFO_FLAG_HAS_NOISE;
+ // isi_txmbps is specified in units of 500 Kbit/s
+ // Convert them to bit/s
+ info->bitrate = u.req.info[0].isi_txmbps * 500 * 1000;
}
return 1;
@@ -599,9 +604,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
snprintf(string_ip, STRING_SIZE, "%s", ip_address);
-#ifdef __linux__
- char br_buffer[128];
- print_bitrate(br_buffer, sizeof(br_buffer), info.bitrate, format_bitrate);
+#if defined(__linux__) || defined(__FreeBSD__)
+ print_bitrate(string_bitrate, sizeof(string_bitrate), info.bitrate, format_bitrate);
#endif
placeholder_t placeholders[] = {