From 4dc375a068e7d117968ffdea0b598c1c4fc88084 Mon Sep 17 00:00:00 2001 From: Andy Kling Date: Wed, 20 Feb 2019 13:23:26 +0100 Subject: libnm-core: add nm_utils_wifi_freq_to_band allow to retrieve wifi band from frequency. [lkundrak@v3.sk: formatting fixes, move the prototype to a private header] --- libnm-core/nm-core-internal.h | 2 ++ libnm-core/nm-utils.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 912ce1b46e..d263900d1a 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -866,4 +866,6 @@ void _nm_bridge_vlan_str_append_rest (const NMBridgeVlan *vlan, gboolean nm_utils_connection_is_adhoc_wpa (NMConnection *connection); +const char *nm_utils_wifi_freq_to_band (guint32 freq); + #endif diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 68da624818..55b004c816 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -3724,6 +3724,25 @@ nm_utils_wifi_freq_to_channel (guint32 freq) return 0; } +/** + * nm_utils_wifi_freq_to_band: + * @freq: frequency + * + * Utility function to translate a Wi-Fi frequency to its corresponding band. + * + * Returns: the band containing the frequency or NULL if freq is invalid + **/ +const char * +nm_utils_wifi_freq_to_band (guint32 freq) +{ + if (freq >= 4915 && freq <= 5825) + return "a"; + else if (freq >= 2412 && freq <= 2484) + return "bg"; + + return NULL; +} + /** * nm_utils_wifi_channel_to_freq: * @channel: channel -- cgit v1.2.1