diff options
Diffstat (limited to 'src/core/hle/service/nwm/uds_data.cpp')
-rw-r--r-- | src/core/hle/service/nwm/uds_data.cpp | 80 |
1 files changed, 77 insertions, 3 deletions
diff --git a/src/core/hle/service/nwm/uds_data.cpp b/src/core/hle/service/nwm/uds_data.cpp index 3ef2a84b6..4b389710f 100644 --- a/src/core/hle/service/nwm/uds_data.cpp +++ b/src/core/hle/service/nwm/uds_data.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <algorithm> #include <cstring> #include <cryptopp/aes.h> #include <cryptopp/ccm.h> @@ -277,10 +278,10 @@ std::vector<u8> GenerateDataPayload(const std::vector<u8>& data, u8 channel, u16 std::vector<u8> GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node_info) { EAPoLStartPacket eapol_start{}; eapol_start.association_id = association_id; - eapol_start.friend_code_seed = node_info.friend_code_seed; + eapol_start.node.friend_code_seed = node_info.friend_code_seed; - for (int i = 0; i < node_info.username.size(); ++i) - eapol_start.username[i] = node_info.username[i]; + std::copy(node_info.username.begin(), node_info.username.end(), + eapol_start.node.username.begin()); // Note: The network_node_id and unknown bytes seem to be uninitialized in the NWM module. // TODO(B3N30): The last 8 bytes seem to have a fixed value of 07 88 15 00 04 e9 13 00 in @@ -295,5 +296,78 @@ std::vector<u8> GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node return buffer; } +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); +} + +u16 GetEAPoLFrameType(const std::vector<u8>& frame) { + // Ignore the LLC header + u16_be eapol_type; + std::memcpy(&eapol_type, frame.data() + sizeof(LLCHeader), sizeof(eapol_type)); + return eapol_type; +} + +NodeInfo DeserializeNodeInfoFromFrame(const std::vector<u8>& frame) { + EAPoLStartPacket eapol_start; + + // Skip the LLC header + std::memcpy(&eapol_start, frame.data() + sizeof(LLCHeader), sizeof(eapol_start)); + + NodeInfo node{}; + node.friend_code_seed = eapol_start.node.friend_code_seed; + + std::copy(eapol_start.node.username.begin(), eapol_start.node.username.end(), + node.username.begin()); + + return node; +} + +NodeInfo DeserializeNodeInfo(const EAPoLNodeInfo& node) { + NodeInfo node_info{}; + node_info.friend_code_seed = node.friend_code_seed; + node_info.network_node_id = node.network_node_id; + + std::copy(node.username.begin(), node.username.end(), node_info.username.begin()); + + return node_info; +} + +std::vector<u8> GenerateEAPoLLogoffFrame(const MacAddress& mac_address, u16 network_node_id, + const NodeList& nodes, u8 max_nodes, u8 total_nodes) { + EAPoLLogoffPacket eapol_logoff{}; + eapol_logoff.assigned_node_id = network_node_id; + eapol_logoff.connected_nodes = total_nodes; + eapol_logoff.max_nodes = max_nodes; + + for (size_t index = 0; index < total_nodes; ++index) { + const auto& node_info = nodes[index]; + auto& node = eapol_logoff.nodes[index]; + + node.friend_code_seed = node_info.friend_code_seed; + node.network_node_id = node_info.network_node_id; + + std::copy(node_info.username.begin(), node_info.username.end(), node.username.begin()); + } + + std::vector<u8> eapol_buffer(sizeof(EAPoLLogoffPacket)); + std::memcpy(eapol_buffer.data(), &eapol_logoff, sizeof(eapol_logoff)); + + std::vector<u8> buffer = GenerateLLCHeader(EtherType::EAPoL); + buffer.insert(buffer.end(), eapol_buffer.begin(), eapol_buffer.end()); + return buffer; +} + +EAPoLLogoffPacket ParseEAPoLLogoffFrame(const std::vector<u8>& frame) { + EAPoLLogoffPacket eapol_logoff; + + // Skip the LLC header + std::memcpy(&eapol_logoff, frame.data() + sizeof(LLCHeader), sizeof(eapol_logoff)); + return eapol_logoff; +} + } // namespace NWM } // namespace Service |