summaryrefslogtreecommitdiff
path: root/src/print_wireless_info.c
diff options
context:
space:
mode:
authorAleksandr Matveev <13134605+TimonAlex@users.noreply.github.com>2020-04-11 22:29:03 +0300
committerAleksandr Matveev <13134605+TimonAlex@users.noreply.github.com>2020-04-11 22:29:03 +0300
commit18eb04d02d55c88f3809084cf82410591f479569 (patch)
treeedab32870d1a4ade8bdf8846d3533e0c7a50cf38 /src/print_wireless_info.c
parentd088baea4f295974ff7e705283cf979eebc58c46 (diff)
wireless: support connection bitrate on FreeBSD
Diffstat (limited to 'src/print_wireless_info.c')
-rw-r--r--src/print_wireless_info.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/print_wireless_info.c b/src/print_wireless_info.c
index ad20645..2403089 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,7 +604,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
snprintf(string_ip, STRING_SIZE, "%s", ip_address);
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
char br_buffer[128];
print_bitrate(br_buffer, sizeof(br_buffer), info.bitrate, format_bitrate);
#endif