blob: 11634e119053e0c70f5c2b876c2d14ddeebb74bf [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.
// The helper function to build a WLAN packet in 'wlan_tx_packet_t'.
#include <fuchsia/hardware/wlan/mac/c/banjo.h>
#include <stdint.h>
#include <memory>
#include <zxtest/zxtest.h>
#include "src/iwlwifi/platform/ieee80211.h"
namespace wlan::testing {
// This builder class is used to help test cases to generate WLAN packet.
// The 'build()' function will return a WlanPkt object, which is a smart pointer and will be
// released when it is no longer referred. Currently, the returned packet is just an arbitray WLAN
// packet with IP packet as its payload.
class WlanPktBuilder {
// The WlanPkt class is the container to manage the allocated resource.
// Call 'pkt()' to retrieve the 'wlan_tx_packet_t' object it holds.
// Call 'len()' to get the WLAN packet length.
class WlanPkt {
explicit WlanPkt(const uint8_t* buf, size_t len);
WlanPkt(const WlanPkt&) = delete; // copy constructor
WlanPkt(WlanPkt&&) = delete; // move constructor
WlanPkt& operator=(const WlanPkt&) = delete; // copy assignment
WlanPkt& operator=(WlanPkt&&) = delete; // move assignment
ieee80211_mac_packet* mac_pkt();
const ieee80211_mac_packet* mac_pkt() const;
wlan_tx_packet_t* wlan_pkt();
const wlan_tx_packet_t* wlan_pkt() const;
size_t len() const;
std::unique_ptr<ieee80211_mac_packet> mac_pkt_;
std::unique_ptr<wlan_tx_packet_t> wlan_pkt_;
std::shared_ptr<uint8_t[]> buf_;
size_t len_;
WlanPktBuilder(const WlanPktBuilder&) = delete; // copy constructor
WlanPktBuilder(WlanPktBuilder&&) = delete; // move constructor
WlanPktBuilder& operator=(const WlanPktBuilder&) = delete; // copy assignment
WlanPktBuilder& operator=(WlanPktBuilder&&) = delete; // move assignment
std::shared_ptr<WlanPkt> build();
} // namespace wlan::testing