From 25d44cde11ab1b80bb74e9655a2dd60b3780124d Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 4 Mar 2021 15:41:00 -0800 Subject: wsutil: rename frequency-utils.[ch] to 802_11-utils.[ch]. It's 802.11-specific, and may include non-frequency/channel-related items in the future. --- caputils/airpcap_loader.c | 2 +- epan/dissectors/packet-ieee80211-netmon.c | 2 +- epan/dissectors/packet-ieee80211-radiotap.c | 2 +- epan/dissectors/packet-ieee80211-wlancap.c | 2 +- epan/dissectors/packet-ppi.c | 2 +- ui/qt/wireless_frame.cpp | 2 +- wiretap/commview.c | 2 +- wiretap/peektagged.c | 2 +- wsutil/802_11-utils.c | 117 ++++++++++++++++++++++++++++ wsutil/802_11-utils.h | 74 ++++++++++++++++++ wsutil/CMakeLists.txt | 4 +- wsutil/frequency-utils.c | 117 ---------------------------- wsutil/frequency-utils.h | 72 ----------------- 13 files changed, 201 insertions(+), 199 deletions(-) create mode 100644 wsutil/802_11-utils.c create mode 100644 wsutil/802_11-utils.h delete mode 100644 wsutil/frequency-utils.c delete mode 100644 wsutil/frequency-utils.h diff --git a/caputils/airpcap_loader.c b/caputils/airpcap_loader.c index c5c8bb867e..191e8a7e19 100644 --- a/caputils/airpcap_loader.c +++ b/caputils/airpcap_loader.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/epan/dissectors/packet-ieee80211-netmon.c b/epan/dissectors/packet-ieee80211-netmon.c index 92038381f4..da0708ef8b 100644 --- a/epan/dissectors/packet-ieee80211-netmon.c +++ b/epan/dissectors/packet-ieee80211-netmon.c @@ -15,7 +15,7 @@ #include -#include +#include void proto_register_netmon_802_11(void); void proto_reg_handoff_netmon_802_11(void); diff --git a/epan/dissectors/packet-ieee80211-radiotap.c b/epan/dissectors/packet-ieee80211-radiotap.c index c573b09ed6..4dd9aa81c6 100644 --- a/epan/dissectors/packet-ieee80211-radiotap.c +++ b/epan/dissectors/packet-ieee80211-radiotap.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/epan/dissectors/packet-ieee80211-wlancap.c b/epan/dissectors/packet-ieee80211-wlancap.c index 6f11e900dc..411d0946b9 100644 --- a/epan/dissectors/packet-ieee80211-wlancap.c +++ b/epan/dissectors/packet-ieee80211-wlancap.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "packet-ieee80211.h" diff --git a/epan/dissectors/packet-ppi.c b/epan/dissectors/packet-ppi.c index 732a189c51..741057c306 100644 --- a/epan/dissectors/packet-ppi.c +++ b/epan/dissectors/packet-ppi.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include diff --git a/ui/qt/wireless_frame.cpp b/ui/qt/wireless_frame.cpp index 0a5fb7b125..df47d78b14 100644 --- a/ui/qt/wireless_frame.cpp +++ b/ui/qt/wireless_frame.cpp @@ -21,7 +21,7 @@ #include "ui/ws_ui_util.h" #include -#include +#include #include "wireshark_application.h" #include diff --git a/wiretap/commview.c b/wiretap/commview.c index 55b25f94b5..b7ebcf3ae3 100644 --- a/wiretap/commview.c +++ b/wiretap/commview.c @@ -31,7 +31,7 @@ #include "file_wrappers.h" #include "commview.h" -#include +#include typedef struct commview_header { guint16 data_len; diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c index 873d22e2c4..ed2bfd0eb7 100644 --- a/wiretap/peektagged.c +++ b/wiretap/peektagged.c @@ -25,7 +25,7 @@ #include "wtap-int.h" #include "file_wrappers.h" #include "peektagged.h" -#include +#include /* CREDITS * diff --git a/wsutil/802_11-utils.c b/wsutil/802_11-utils.c new file mode 100644 index 0000000000..9900bcbd28 --- /dev/null +++ b/wsutil/802_11-utils.c @@ -0,0 +1,117 @@ +/* 802_11-utils.c + * 802.11 utility definitions + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 2007 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "config.h" + +#include + +#include "802_11-utils.h" + +typedef struct freq_cvt_s { + guint fmin; /* Minimum frequency in MHz */ + guint fmax; /* Maximum frequency in MHz */ + gint cmin; /* Minimum/base channel */ + gboolean is_bg; /* B/G channel? */ +} freq_cvt_t; + +#define FREQ_STEP 5 /* MHz. This seems to be consistent, thankfully */ + +/* + * From IEEE Std 802.11-2012: + * + * section 16.4.6.3 "Channel Numbering of operating channels"; + * + * section 17.4.6.3 "Channel Numbering of operating channels"; + * + * section 18.3.8.4.2 "Channel numbering"; + * + * Annex E. + * + * XXX - Japanese channels 182 through 196 actually have center + * frequencies that are off by 2.5 MHz from these values, according + * to the IEEE standard, although the table in ARIB STD T-71 version 5.2: + * + * http://www.arib.or.jp/english/html/overview/doc/1-STD-T71v5_2.pdf + * + * section 5.3.8.3.3 doesn't show that. + * + * XXX - what about the U.S. public safety 4.9 GHz band? + * + * XXX - what about 802.11ad? + */ +static freq_cvt_t freq_cvt[] = { + { 2412, 2472, 1, TRUE }, + { 2484, 2484, 14, TRUE }, + { 5000, 5995, 0, FALSE }, + { 4910, 4980, 182, FALSE } +}; + +#define NUM_FREQ_CVT (sizeof(freq_cvt) / sizeof(freq_cvt_t)) +#define MAX_CHANNEL(fc) ( (gint) ((fc.fmax - fc.fmin) / FREQ_STEP) + fc.cmin ) + +/* + * Get channel number given a Frequency + */ +gint +ieee80211_mhz_to_chan(guint freq) { + guint i; + + for (i = 0; i < NUM_FREQ_CVT; i++) { + if (freq >= freq_cvt[i].fmin && freq <= freq_cvt[i].fmax) { + return ((freq - freq_cvt[i].fmin) / FREQ_STEP) + freq_cvt[i].cmin; + } + } + return -1; +} + +/* + * Get Frequency given a Channel number + */ +guint +ieee80211_chan_to_mhz(gint chan, gboolean is_bg) { + guint i; + + for (i = 0; i < NUM_FREQ_CVT; i++) { + if (is_bg == freq_cvt[i].is_bg && + chan >= freq_cvt[i].cmin && chan <= MAX_CHANNEL(freq_cvt[i])) { + return ((chan - freq_cvt[i].cmin) * FREQ_STEP) + freq_cvt[i].fmin; + } + } + return 0; +} + +/* + * Get channel representation string given a Frequency + */ +gchar* +ieee80211_mhz_to_str(guint freq){ + gint chan = ieee80211_mhz_to_chan(freq); + gboolean is_bg = FREQ_IS_BG(freq); + + if (chan < 0) { + return g_strdup_printf("%u", freq); + } else { + return g_strdup_printf("%u [%s %u]", freq, is_bg ? "BG" : "A", + chan); + } +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/wsutil/802_11-utils.h b/wsutil/802_11-utils.h new file mode 100644 index 0000000000..43db61248c --- /dev/null +++ b/wsutil/802_11-utils.h @@ -0,0 +1,74 @@ +/* 802_11-utils.h + * 802.11 utility definitions + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 2007 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __802_11_UTILS_H__ +#define __802_11_UTILS_H__ + +#include "ws_symbol_export.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** @file + * 802.11 utilities. + */ + +/** + * Given a center frequency in MHz, return a channel number. + * @param freq Frequency in MHz. + * @return The equivalent channel or -1 if no match is found. + */ +WS_DLL_PUBLIC +gint +ieee80211_mhz_to_chan(guint freq); + +/** + * Given an 802.11 channel number and a band type, return a center frequency. + * @param chan Channel number + * @param is_bg TRUE if the channel is a b/g channel, FALSE otherwise. + * @return The equivalent frequency or 0 if no match is found. + */ +WS_DLL_PUBLIC +guint +ieee80211_chan_to_mhz(gint chan, gboolean is_bg); + +/** + * Given an 802.11 channel center frequency in MHz, return a string + * representation. + * @param freq Frequench in MHz. + * @return A string showing the frequency, channel number, and type. + * The string must be freed with g_free() after use. + */ +WS_DLL_PUBLIC +gchar* +ieee80211_mhz_to_str(guint freq); + +/* Should this be "(freq < 4920)", or something else? */ +#define FREQ_IS_BG(freq) (freq <= 2484) + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __802_11_UTILS_H__ */ + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index ce53962803..207b1dce81 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -12,6 +12,7 @@ add_definitions(-DEXTCAP_DIR=\"${CMAKE_INSTALL_PREFIX}/${EXTCAP_INSTALL_LIBDIR}\ add_definitions(-DDATA_DIR=\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}\") set(WSUTIL_PUBLIC_HEADERS + 802_11-utils.h adler32.h base32.h bits_count_ones.h @@ -36,7 +37,6 @@ set(WSUTIL_PUBLIC_HEADERS eax.h epochs.h filesystem.h - frequency-utils.h g711.h inet_addr.h inet_ipv4.h @@ -75,6 +75,7 @@ set(WSUTIL_PUBLIC_HEADERS ) set(WSUTIL_COMMON_FILES + 802_11-utils.c adler32.c base32.c bitswap.c @@ -95,7 +96,6 @@ set(WSUTIL_COMMON_FILES dot11decrypt_wep.c eax.c filesystem.c - frequency-utils.c g711.c inet_addr.c interface.c diff --git a/wsutil/frequency-utils.c b/wsutil/frequency-utils.c deleted file mode 100644 index 3c6d157423..0000000000 --- a/wsutil/frequency-utils.c +++ /dev/null @@ -1,117 +0,0 @@ -/* frequency-utils.c - * Frequency conversion utility definitions - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 2007 Gerald Combs - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#include "config.h" - -#include - -#include "frequency-utils.h" - -typedef struct freq_cvt_s { - guint fmin; /* Minimum frequency in MHz */ - guint fmax; /* Maximum frequency in MHz */ - gint cmin; /* Minimum/base channel */ - gboolean is_bg; /* B/G channel? */ -} freq_cvt_t; - -#define FREQ_STEP 5 /* MHz. This seems to be consistent, thankfully */ - -/* - * From IEEE Std 802.11-2012: - * - * section 16.4.6.3 "Channel Numbering of operating channels"; - * - * section 17.4.6.3 "Channel Numbering of operating channels"; - * - * section 18.3.8.4.2 "Channel numbering"; - * - * Annex E. - * - * XXX - Japanese channels 182 through 196 actually have center - * frequencies that are off by 2.5 MHz from these values, according - * to the IEEE standard, although the table in ARIB STD T-71 version 5.2: - * - * http://www.arib.or.jp/english/html/overview/doc/1-STD-T71v5_2.pdf - * - * section 5.3.8.3.3 doesn't show that. - * - * XXX - what about the U.S. public safety 4.9 GHz band? - * - * XXX - what about 802.11ad? - */ -static freq_cvt_t freq_cvt[] = { - { 2412, 2472, 1, TRUE }, - { 2484, 2484, 14, TRUE }, - { 5000, 5995, 0, FALSE }, - { 4910, 4980, 182, FALSE } -}; - -#define NUM_FREQ_CVT (sizeof(freq_cvt) / sizeof(freq_cvt_t)) -#define MAX_CHANNEL(fc) ( (gint) ((fc.fmax - fc.fmin) / FREQ_STEP) + fc.cmin ) - -/* - * Get channel number given a Frequency - */ -gint -ieee80211_mhz_to_chan(guint freq) { - guint i; - - for (i = 0; i < NUM_FREQ_CVT; i++) { - if (freq >= freq_cvt[i].fmin && freq <= freq_cvt[i].fmax) { - return ((freq - freq_cvt[i].fmin) / FREQ_STEP) + freq_cvt[i].cmin; - } - } - return -1; -} - -/* - * Get Frequency given a Channel number - */ -guint -ieee80211_chan_to_mhz(gint chan, gboolean is_bg) { - guint i; - - for (i = 0; i < NUM_FREQ_CVT; i++) { - if (is_bg == freq_cvt[i].is_bg && - chan >= freq_cvt[i].cmin && chan <= MAX_CHANNEL(freq_cvt[i])) { - return ((chan - freq_cvt[i].cmin) * FREQ_STEP) + freq_cvt[i].fmin; - } - } - return 0; -} - -/* - * Get channel representation string given a Frequency - */ -gchar* -ieee80211_mhz_to_str(guint freq){ - gint chan = ieee80211_mhz_to_chan(freq); - gboolean is_bg = FREQ_IS_BG(freq); - - if (chan < 0) { - return g_strdup_printf("%u", freq); - } else { - return g_strdup_printf("%u [%s %u]", freq, is_bg ? "BG" : "A", - chan); - } -} - -/* - * Editor modelines - * - * Local Variables: - * c-basic-offset: 4 - * tab-width: 8 - * indent-tabs-mode: nil - * End: - * - * ex: set shiftwidth=4 tabstop=8 expandtab: - * :indentSize=4:tabSize=8:noTabs=true: - */ diff --git a/wsutil/frequency-utils.h b/wsutil/frequency-utils.h deleted file mode 100644 index e7367ee3cf..0000000000 --- a/wsutil/frequency-utils.h +++ /dev/null @@ -1,72 +0,0 @@ -/* frequency-utils.h - * Frequency conversion utility definitions - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 2007 Gerald Combs - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#ifndef __FREQUENCY_UTILS_H__ -#define __FREQUENCY_UTILS_H__ - -#include "ws_symbol_export.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** @file - * Frequency and channel conversion utilities. - */ - -/** - * Given a center frequency in MHz, return a channel number. - * @param freq Frequency in MHz. - * @return The equivalent channel or -1 if no match is found. - */ -WS_DLL_PUBLIC -gint -ieee80211_mhz_to_chan(guint freq); - -/** - * Given a channel number and a band type, return a center frequency. - * @param chan Channel number - * @param is_bg TRUE if the channel is a b/g channel, FALSE otherwise. - * @return The equivalent frequency or 0 if no match is found. - */ -WS_DLL_PUBLIC -guint -ieee80211_chan_to_mhz(gint chan, gboolean is_bg); - -/** - * Given a frequency in MHz, return a string representation. - * @param freq Frequench in MHz. - * @return A string showing the frequency, channel number, and type. The string must be freed with g_free() after use. - */ -WS_DLL_PUBLIC -gchar* -ieee80211_mhz_to_str(guint freq); - -/* Should this be "(freq < 4920)", or something else? */ -#define FREQ_IS_BG(freq) (freq <= 2484) - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __FREQUENCY_UTILS_H__ */ - -/* - * Editor modelines - * - * Local Variables: - * c-basic-offset: 4 - * tab-width: 8 - * indent-tabs-mode: nil - * End: - * - * vi: set shiftwidth=4 tabstop=8 expandtab: - * :indentSize=4:tabSize=8:noTabs=true: - */ -- cgit v1.2.3