summaryrefslogtreecommitdiffstats
path: root/wsutil/802_11-utils.h
blob: 887faddb27ffd1c8c61da9374718f733650ecdfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* 802_11-utils.h
 * 802.11 utility definitions
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 2007 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef __802_11_UTILS_H__
#define __802_11_UTILS_H__

#include <wireshark.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
int
ieee80211_mhz_to_chan(unsigned 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
unsigned
ieee80211_chan_to_mhz(int chan, bool 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
char*
ieee80211_mhz_to_str(unsigned freq);

/* Should this be "(freq < 4920)", or something else? */
#define FREQ_IS_BG(freq) ((freq) <= 2484)
#define CHAN_IS_BG(chan) ((chan) <= 14)

/*
 * Test whether a data rate is an {HR}/DSSS (legacy DSSS/11b) data rate
 * and whether it's an OFDM (11a/11g OFDM mode) data rate.
 *
 * rate is in units of 500 Kb/s.
 *
 * The 22 and 33 Mb/s rates for DSSS use Packet Binary Convolutional
 * Coding (PBCC).  That was provided by Texas Instruments as 11b+,
 * and was in section 19.6 "ERP-PBCC operation specifications" of
 * IEEE Std 802.11g-2003, and sections 18.4.6.6 "DSSS/PBCC data modulation
 * and modulation rate (optional)" and 19.6 "ERP-PBCC operation
 * specifications" of IEEE Std 802.11-2007, and sections 17.4.6.7 "DSSS/PBCC
 * data modulation and modulation rate (optional)" and 19.6 "ERP-PBCC
 * operation specifications" of IEEE Std 802.11-2012, marked as optional
 * in both cases, but is not present in IEEE Std 802.11-2016.
 *
 * (Note: not to be confused with "peanut butter and chocolate chips":
 *
 *    https://www.bigoven.com/recipe/peanut-butter-chocolate-chip-cookies-pbcc-cookies/186266
 *
 * :-))
 */
#define RATE_IS_DSSS(rate) \
    ((rate) == 2 /* 1 Mb/s */ || \
     (rate) == 4 /* 2 Mb/s */ || \
     (rate) == 11 /* 5.5 Mb/s */ || \
     (rate) == 22 /* 11 Mb/s */ || \
     (rate) == 44 /* 22 Mb/s */ || \
     (rate) == 66 /* 33 Mb/s */)

#define RATE_IS_OFDM(rate) \
    ((rate) == 12 /* 6 Mb/s */ || \
     (rate) == 18 /* 9 Mb/s */ || \
     (rate) == 24 /* 12 Mb/s */ || \
     (rate) == 36 /* 18 Mb/s */ || \
     (rate) == 48 /* 24 Mb/s */ || \
     (rate) == 72 /* 36 Mb/s */ || \
     (rate) == 96 /* 48 Mb/s */ || \
     (rate) == 108 /* 54 Mb/s */)

#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:
 */