blob: 4c0170375dc8c92474528af2f4c9bf2e06a69393 [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fuchsia/hardware/wlan/info/c/banjo.h>
#include <fuchsia/wlan/common/c/banjo.h>
#include <fuchsia/wlan/common/cpp/fidl.h>
#include <cstdint>
#include <string>
#include <fuchsia/hardware/wlanphyinfo/c/banjo.h>
bool operator==(const wlan_channel_t& lhs, const wlan_channel_t& rhs);
bool operator!=(const wlan_channel_t& lhs, const wlan_channel_t& rhs);
namespace wlan {
namespace common {
typedef uint16_t Mhz;
// IEEE Std 802.11-2016, Annex E
// Note the distinction of index for primary20 and index for center frequency.
// Fuchsia OS minimizes the use of the notion of center frequency,
// with following exceptions:
// - CBW80P80's secondary frequency segment
// - Frequency conversion at device drivers
constexpr Mhz kBaseFreq2Ghz = 2407;
constexpr Mhz kBaseFreq5Ghz = 5000;
// TODO(porce): Replace all channel > 14 test throughout the codes
bool Is5Ghz(uint8_t channel_number);
bool Is2Ghz(uint8_t channel_number);
bool Is5Ghz(const wlan_channel_t& channel);
bool Is2Ghz(const wlan_channel_t& channel);
bool IsValidChan2Ghz(const wlan_channel_t& channel);
bool IsValidChan5Ghz(const wlan_channel_t& channel);
bool IsValidChan(const wlan_channel_t& channel);
Mhz GetCenterFreq(const wlan_channel_t& channel);
uint8_t GetCenterChanIdx(const wlan_channel_t& channel);
std::string ChanStr(const wlan_channel_t& channel);
std::string ChanStrLong(const wlan_channel_t& channel);
std::string GetPhyStr(wlan_info_phy_type_t phy);
struct Channel {
wlan_channel_t channel;
// TODO(porce): Validation
// TODO(porce): Notation string.
// TODO(porce): Center frequencies.
// Define the rule to translsate center frequency to/from channel numbering.
// See IEEE Std 802.11-2016 19.3.15
wlan_channel_t FromFidl(const fuchsia::wlan::common::WlanChannel& fidl_channel);
fuchsia::wlan::common::WlanChannel ToFidl(const wlan_channel_t& channel);
wlan_info_phy_type_t FromFidl(fuchsia::wlan::common::PHY phy);
fuchsia::wlan::common::PHY ToFidl(wlan_info_phy_type_t phy);
const char* CbwSuffix(channel_bandwidth_t cbw);
const char* CbwStr(channel_bandwidth_t cbw);
} // namespace common
} // namespace wlan