1 /* 802_11-utils.h
2  * 802.11 utility definitions
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 2007 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #ifndef __802_11_UTILS_H__
12 #define __802_11_UTILS_H__
13 
14 #include "ws_symbol_export.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
19 
20 /** @file
21  * 802.11 utilities.
22  */
23 
24 /**
25  * Given a center frequency in MHz, return a channel number.
26  * @param freq Frequency in MHz.
27  * @return The equivalent channel or -1 if no match is found.
28  */
29 WS_DLL_PUBLIC
30 gint
31 ieee80211_mhz_to_chan(guint freq);
32 
33 /**
34  * Given an 802.11 channel number and a band type, return a center frequency.
35  * @param chan Channel number
36  * @param is_bg TRUE if the channel is a b/g channel, FALSE otherwise.
37  * @return The equivalent frequency or 0 if no match is found.
38  */
39 WS_DLL_PUBLIC
40 guint
41 ieee80211_chan_to_mhz(gint chan, gboolean is_bg);
42 
43 /**
44  * Given an 802.11 channel center frequency in MHz, return a string
45  * representation.
46  * @param freq Frequench in MHz.
47  * @return A string showing the frequency, channel number, and type.
48  * The string must be freed with g_free() after use.
49  */
50 WS_DLL_PUBLIC
51 gchar*
52 ieee80211_mhz_to_str(guint freq);
53 
54 /* Should this be "(freq < 4920)", or something else? */
55 #define FREQ_IS_BG(freq) ((freq) <= 2484)
56 #define CHAN_IS_BG(chan) ((chan) <= 14)
57 
58 /*
59  * Test whether a data rate is an {HR}/DSSS (legacy DSSS/11b) data rate
60  * and whether it's an OFDM (11a/11g OFDM mode) data rate.
61  *
62  * rate is in units of 500 Kb/s.
63  *
64  * The 22 and 33 Mb/s rates for DSSS use Packet Binary Convolutional
65  * Coding (PBCC).  That was provided by Texas Instruments as 11b+,
66  * and was in section 19.6 "ERP-PBCC operation specifications" of
67  * IEEE Std 802.11g-2003, and sections 18.4.6.6 "DSSS/PBCC data modulation
68  * and modulation rate (optional)" and 19.6 "ERP-PBCC operation
69  * specifications" of IEEE Std 802.11-2007, and sections 17.4.6.7 "DSSS/PBCC
70  * data modulation and modulation rate (optional)" and 19.6 "ERP-PBCC
71  * operation specifications" of IEEE Std 802.11-2012, marked as optional
72  * in both cases, but is not present in IEEE Std 802.11-2016.
73  *
74  * (Note: not to be confused with "peanut butter and chocolate chips":
75  *
76  *    https://www.bigoven.com/recipe/peanut-butter-chocolate-chip-cookies-pbcc-cookies/186266
77  *
78  * :-))
79  */
80 #define RATE_IS_DSSS(rate) \
81     ((rate) == 2 /* 1 Mb/s */ || \
82      (rate) == 4 /* 2 Mb/s */ || \
83      (rate) == 11 /* 5.5 Mb/s */ || \
84      (rate) == 22 /* 11 Mb/s */ || \
85      (rate) == 44 /* 22 Mb/s */ || \
86      (rate) == 66 /* 33 Mb/s */)
87 
88 #define RATE_IS_OFDM(rate) \
89     ((rate) == 12 /* 6 Mb/s */ || \
90      (rate) == 18 /* 9 Mb/s */ || \
91      (rate) == 24 /* 12 Mb/s */ || \
92      (rate) == 36 /* 18 Mb/s */ || \
93      (rate) == 48 /* 24 Mb/s */ || \
94      (rate) == 72 /* 36 Mb/s */ || \
95      (rate) == 96 /* 48 Mb/s */ || \
96      (rate) == 108 /* 54 Mb/s */)
97 
98 #ifdef __cplusplus
99 }
100 #endif /* __cplusplus */
101 
102 #endif /* __802_11_UTILS_H__ */
103 
104 /*
105  * Editor modelines
106  *
107  * Local Variables:
108  * c-basic-offset: 4
109  * tab-width: 8
110  * indent-tabs-mode: nil
111  * End:
112  *
113  * vi: set shiftwidth=4 tabstop=8 expandtab:
114  * :indentSize=4:tabSize=8:noTabs=true:
115  */
116