Files
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now
came from the colleague's microbu-esp32c5 tree beside the repository and was
not tracked here, so a clone of this repository could not build the firmware
it ships. The library alone is now part of obu-firmware, as
obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit
cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from
there by default; -DVANETZA_IDF_DIR still points the build elsewhere.

The rest of the colleague's tree (their own VAM firmware, PKI tooling,
station-link Python tools, the V2X2MAP bridge) stays out of this repository
and gitignored; nothing is pushed to their repository. NOTES.md, docs/06,
TODO.md and the pcap verifier's usage line point at the new location.
2026-09-24 10:56:05 +02:00

105 lines
2.6 KiB
C++

#ifndef MAC_ADDRESS_HPP_FDINBLBS
#define MAC_ADDRESS_HPP_FDINBLBS
#include <vanetza/common/serialization.hpp>
#include <boost/operators.hpp>
#include <boost/optional.hpp>
#include <array>
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <functional>
#include <ostream>
#include <string>
namespace vanetza
{
class MacAddress : public boost::totally_ordered<MacAddress>
{
public:
static constexpr std::size_t length_bytes = 6;
MacAddress();
MacAddress(std::initializer_list<uint8_t> args);
MacAddress(const MacAddress&) = default;
MacAddress& operator=(const MacAddress&) = default;
MacAddress(MacAddress&&) = default;
MacAddress& operator=(MacAddress&&) = default;
std::array<uint8_t, length_bytes> octets;
};
extern const MacAddress cBroadcastMacAddress;
bool operator==(const MacAddress& lhs, const MacAddress& rhs);
bool operator<(const MacAddress& lhs, const MacAddress& rhs);
std::ostream& operator<<(std::ostream& os, const MacAddress&);
/**
* Try to parse MAC address from string
* \param str source string with "XX:XX:XX:XX:XX:XX" format
* \param addr pass parsed address by reference
* \return true if successfully parsed
*/
bool parse_mac_address(const std::string& str, MacAddress& addr);
/**
* Try to parse MAC address from string
* \param str source string with "XX:XX:XX:XX:XX:XX" format
* \return parsed address if successful
*/
boost::optional<MacAddress> parse_mac_address(const std::string& str);
/**
* Derive a MAC address from an arbitrary integral value.
* \param value used to derive MAC address, it's size does not matter
* \return New MAC address
*/
template<typename T>
MacAddress create_mac_address(T value)
{
MacAddress mac;
const std::size_t octets = std::min(mac.octets.size(), sizeof(T));
for (std::size_t i = 0; i < octets; ++i) {
mac.octets[i] = value >> (8 * (octets - i - 1)) & 0xff;
}
return mac;
}
/**
* Serialize MAC address
* \param out output sink
* \param addr MAC address
*/
void serialize(OutputArchive& out, const MacAddress& addr);
/**
* Deserialize MAC address
* \param in input source
* \param addr deserialize into this object
*/
void deserialize(InputArchive& in, MacAddress& addr);
} // namespace vanetza
// specialization
namespace std {
template<>
struct hash<vanetza::MacAddress>
{
size_t operator()(const vanetza::MacAddress& addr) const
{
size_t tmp = 0;
for (auto octet : addr.octets) {
tmp ^= hash<decltype(octet)>()(octet);
}
return tmp;
}
};
} // namespace std
#endif /* MAC_ADDRESS_HPP_FDINBLBS */