Merge pull request #4244 from wwylele/swap-enum
common/swap: add swap template for enum
This commit is contained in:
commit
eb494c574d
10 changed files with 111 additions and 60 deletions
|
@ -235,7 +235,7 @@ private:
|
|||
struct SegmentEntry {
|
||||
u32_le offset;
|
||||
u32_le size;
|
||||
SegmentType type;
|
||||
enum_le<SegmentType> type;
|
||||
|
||||
static constexpr HeaderField TABLE_OFFSET_FIELD = SegmentTableOffset;
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ constexpr u16 DefaultExtraCapabilities = 0x0431;
|
|||
|
||||
std::vector<u8> GenerateAuthenticationFrame(AuthenticationSeq seq) {
|
||||
AuthenticationFrame frame{};
|
||||
frame.auth_seq = static_cast<u16>(seq);
|
||||
frame.auth_seq = seq;
|
||||
|
||||
std::vector<u8> data(sizeof(frame));
|
||||
std::memcpy(data.data(), &frame, sizeof(frame));
|
||||
|
@ -26,7 +26,7 @@ AuthenticationSeq GetAuthenticationSeqNumber(const std::vector<u8>& body) {
|
|||
AuthenticationFrame frame;
|
||||
std::memcpy(&frame, body.data(), sizeof(frame));
|
||||
|
||||
return static_cast<AuthenticationSeq>(frame.auth_seq);
|
||||
return frame.auth_seq;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ static std::vector<u8> GenerateSSIDTag(u32 network_id) {
|
|||
std::vector<u8> GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id) {
|
||||
AssociationResponseFrame frame{};
|
||||
frame.capabilities = DefaultExtraCapabilities;
|
||||
frame.status_code = static_cast<u16>(status);
|
||||
frame.status_code = status;
|
||||
// The association id is ORed with this magic value (0xC000)
|
||||
constexpr u16 AssociationIdMagic = 0xC000;
|
||||
frame.assoc_id = association_id | AssociationIdMagic;
|
||||
|
@ -79,8 +79,7 @@ std::tuple<AssocStatus, u16> GetAssociationResult(const std::vector<u8>& body) {
|
|||
memcpy(&frame, body.data(), sizeof(frame));
|
||||
|
||||
constexpr u16 AssociationIdMask = 0x3FFF;
|
||||
return std::make_tuple(static_cast<AssocStatus>(frame.status_code),
|
||||
frame.assoc_id & AssociationIdMask);
|
||||
return std::make_tuple(frame.status_code, frame.assoc_id & AssociationIdMask);
|
||||
}
|
||||
|
||||
} // namespace Service::NWM
|
||||
|
|
|
@ -22,16 +22,16 @@ enum class AuthStatus : u16 { Successful = 0 };
|
|||
enum class AssocStatus : u16 { Successful = 0 };
|
||||
|
||||
struct AuthenticationFrame {
|
||||
u16_le auth_algorithm = static_cast<u16>(AuthAlgorithm::OpenSystem);
|
||||
u16_le auth_seq;
|
||||
u16_le status_code = static_cast<u16>(AuthStatus::Successful);
|
||||
enum_le<AuthAlgorithm> auth_algorithm = AuthAlgorithm::OpenSystem;
|
||||
enum_le<AuthenticationSeq> auth_seq;
|
||||
enum_le<AuthStatus> status_code = AuthStatus::Successful;
|
||||
};
|
||||
|
||||
static_assert(sizeof(AuthenticationFrame) == 6, "AuthenticationFrame has wrong size");
|
||||
|
||||
struct AssociationResponseFrame {
|
||||
u16_le capabilities;
|
||||
u16_le status_code;
|
||||
enum_le<AssocStatus> status_code;
|
||||
u16_le assoc_id;
|
||||
};
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ using MacAddress = std::array<u8, 6>;
|
|||
*/
|
||||
static std::vector<u8> GenerateLLCHeader(EtherType protocol) {
|
||||
LLCHeader header{};
|
||||
header.protocol = static_cast<u16>(protocol);
|
||||
header.protocol = protocol;
|
||||
|
||||
std::vector<u8> buffer(sizeof(header));
|
||||
memcpy(buffer.data(), &header, sizeof(header));
|
||||
|
@ -312,9 +312,7 @@ std::vector<u8> GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node
|
|||
EtherType GetFrameEtherType(const std::vector<u8>& frame) {
|
||||
LLCHeader header;
|
||||
std::memcpy(&header, frame.data(), sizeof(header));
|
||||
|
||||
u16 ethertype = header.protocol;
|
||||
return static_cast<EtherType>(ethertype);
|
||||
return header.protocol;
|
||||
}
|
||||
|
||||
u16 GetEAPoLFrameType(const std::vector<u8>& frame) {
|
||||
|
|
|
@ -25,11 +25,11 @@ enum class EtherType : u16 { SecureData = 0x876D, EAPoL = 0x888E };
|
|||
* and the OUI is always 0.
|
||||
*/
|
||||
struct LLCHeader {
|
||||
u8 dsap = static_cast<u8>(SAP::SNAPExtensionUsed);
|
||||
u8 ssap = static_cast<u8>(SAP::SNAPExtensionUsed);
|
||||
u8 control = static_cast<u8>(PDUControl::UnnumberedInformation);
|
||||
SAP dsap = SAP::SNAPExtensionUsed;
|
||||
SAP ssap = SAP::SNAPExtensionUsed;
|
||||
PDUControl control = PDUControl::UnnumberedInformation;
|
||||
std::array<u8, 3> OUI = {};
|
||||
u16_be protocol;
|
||||
enum_be<EtherType> protocol;
|
||||
};
|
||||
|
||||
static_assert(sizeof(LLCHeader) == 8, "LLCHeader has the wrong size");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue