citra-emu
/
citra-canary
Archived
1
0
Fork 0

nwm/uds_connection: specify endiannes for enum

This commit is contained in:
Weiyi Wang 2018-09-21 20:25:53 -04:00
parent 16b36b6025
commit e0336403ee
2 changed files with 8 additions and 9 deletions

View File

@ -15,7 +15,7 @@ constexpr u16 DefaultExtraCapabilities = 0x0431;
std::vector<u8> GenerateAuthenticationFrame(AuthenticationSeq seq) { std::vector<u8> GenerateAuthenticationFrame(AuthenticationSeq seq) {
AuthenticationFrame frame{}; AuthenticationFrame frame{};
frame.auth_seq = static_cast<u16>(seq); frame.auth_seq = seq;
std::vector<u8> data(sizeof(frame)); std::vector<u8> data(sizeof(frame));
std::memcpy(data.data(), &frame, sizeof(frame)); std::memcpy(data.data(), &frame, sizeof(frame));
@ -27,7 +27,7 @@ AuthenticationSeq GetAuthenticationSeqNumber(const std::vector<u8>& body) {
AuthenticationFrame frame; AuthenticationFrame frame;
std::memcpy(&frame, body.data(), sizeof(frame)); std::memcpy(&frame, body.data(), sizeof(frame));
return static_cast<AuthenticationSeq>(frame.auth_seq); return frame.auth_seq;
} }
/** /**
@ -58,7 +58,7 @@ static std::vector<u8> GenerateSSIDTag(u32 network_id) {
std::vector<u8> GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id) { std::vector<u8> GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id) {
AssociationResponseFrame frame{}; AssociationResponseFrame frame{};
frame.capabilities = DefaultExtraCapabilities; frame.capabilities = DefaultExtraCapabilities;
frame.status_code = static_cast<u16>(status); frame.status_code = status;
// The association id is ORed with this magic value (0xC000) // The association id is ORed with this magic value (0xC000)
constexpr u16 AssociationIdMagic = 0xC000; constexpr u16 AssociationIdMagic = 0xC000;
frame.assoc_id = association_id | AssociationIdMagic; frame.assoc_id = association_id | AssociationIdMagic;
@ -80,8 +80,7 @@ std::tuple<AssocStatus, u16> GetAssociationResult(const std::vector<u8>& body) {
memcpy(&frame, body.data(), sizeof(frame)); memcpy(&frame, body.data(), sizeof(frame));
constexpr u16 AssociationIdMask = 0x3FFF; constexpr u16 AssociationIdMask = 0x3FFF;
return std::make_tuple(static_cast<AssocStatus>(frame.status_code), return std::make_tuple(frame.status_code, frame.assoc_id & AssociationIdMask);
frame.assoc_id & AssociationIdMask);
} }
} // namespace NWM } // namespace NWM

View File

@ -23,16 +23,16 @@ enum class AuthStatus : u16 { Successful = 0 };
enum class AssocStatus : u16 { Successful = 0 }; enum class AssocStatus : u16 { Successful = 0 };
struct AuthenticationFrame { struct AuthenticationFrame {
u16_le auth_algorithm = static_cast<u16>(AuthAlgorithm::OpenSystem); enum_le<AuthAlgorithm> auth_algorithm = AuthAlgorithm::OpenSystem;
u16_le auth_seq; enum_le<AuthenticationSeq> auth_seq;
u16_le status_code = static_cast<u16>(AuthStatus::Successful); enum_le<AuthStatus> status_code = AuthStatus::Successful;
}; };
static_assert(sizeof(AuthenticationFrame) == 6, "AuthenticationFrame has wrong size"); static_assert(sizeof(AuthenticationFrame) == 6, "AuthenticationFrame has wrong size");
struct AssociationResponseFrame { struct AssociationResponseFrame {
u16_le capabilities; u16_le capabilities;
u16_le status_code; enum_le<AssocStatus> status_code;
u16_le assoc_id; u16_le assoc_id;
}; };