1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Move frequency (channel) utils into their own file

This commit is contained in:
Matias Fontanini
2017-04-30 12:06:42 -07:00
parent c83cff36d8
commit 500ef1088b
6 changed files with 103 additions and 23 deletions

View File

@@ -40,6 +40,7 @@
#include "pdu.h"
#include "detail/type_traits.h"
#include "utils/checksum_utils.h"
#include "utils/frequency_utils.h"
// Fix for Windows interface define on combaseapi.h
#undef interface
@@ -216,20 +217,6 @@ TINS_API std::vector<RouteEntry> route_entries();
*/
TINS_API std::vector<Route6Entry> route6_entries();
/**
* \brief Converts a channel number to its mhz representation.
* \param channel The channel number.
* \return The channel's mhz representation.
*/
TINS_API uint16_t channel_to_mhz(uint16_t channel);
/**
* \brief Converts mhz units to the appropriate channel number.
* \param mhz The mhz units to be converted.
* \return The channel number.
*/
TINS_API uint16_t mhz_to_channel(uint16_t mhz);
/**
* \brief Converts a PDUType to a string.
* \param pduType The PDUType to be converted.

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2017, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef TINS_FREQUENCY_UTILS_H
#define TINS_FREQUENCY_UTILS_H
#include <stdint.h>
#include "../macros.h"
namespace Tins {
namespace Utils {
/**
* \brief Converts a channel number to its mhz representation.
* \param channel The channel number.
* \return The channel's mhz representation.
*/
TINS_API uint16_t channel_to_mhz(uint16_t channel);
/**
* \brief Converts mhz units to the appropriate channel number.
* \param mhz The mhz units to be converted.
* \return The channel number.
*/
TINS_API uint16_t mhz_to_channel(uint16_t mhz);
} // Utils
} // Tins
#endif // TINS_FREQUENCY_UTILS_H

View File

@@ -73,6 +73,7 @@ set(SOURCES
dot11/dot11_probe.cpp
dot11/dot11_control.cpp
utils/checksum_utils.cpp
utils/frequency_utils.cpp
)
SET(PCAP_DEPENDENT_SOURCES

View File

@@ -44,11 +44,11 @@
#include <net/ethernet.h>
#endif
#include "dot11/dot11_base.h"
#include "utils.h"
#include "packet_sender.h"
#include "exceptions.h"
#include "memory_helpers.h"
#include "utils/checksum_utils.h"
#include "utils/frequency_utils.h"
using std::memcpy;

View File

@@ -524,14 +524,6 @@ set<string> network_interfaces() {
return output;
}
#endif // _WIN32
uint16_t channel_to_mhz(uint16_t channel) {
return 2407 + (channel * 5);
}
uint16_t mhz_to_channel(uint16_t mhz) {
return (mhz - 2407) / 5;
}
string to_string(PDU::PDUType pduType) {
#define ENUM_TEXT(p) case(PDU::p): return #p;

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2017, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "utils/frequency_utils.h"
namespace Tins {
namespace Utils {
uint16_t channel_to_mhz(uint16_t channel) {
return 2407 + (channel * 5);
}
uint16_t mhz_to_channel(uint16_t mhz) {
return (mhz - 2407) / 5;
}
} // Utils
} // Tins