diff options
| author | 2017-07-17 09:25:58 -0500 | |
|---|---|---|
| committer | 2017-08-27 10:48:09 -0500 | |
| commit | 54411bef4eb16af0822820205a923690ea7e822a (patch) | |
| tree | e8a0a55d7be9cb4bd50c456ecb7d934685d95f9c /src/core | |
| parent | Merge pull request #2814 from Kloen/macro-remove (diff) | |
| download | yuzu-54411bef4eb16af0822820205a923690ea7e822a.tar.gz yuzu-54411bef4eb16af0822820205a923690ea7e822a.tar.xz yuzu-54411bef4eb16af0822820205a923690ea7e822a.zip | |
Services/UDS: Add functions to generate 802.11 auth and assoc response frames.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/hle/service/nwm/nwm_uds.h | 12 | ||||
| -rw-r--r-- | src/core/hle/service/nwm/uds_beacon.h | 11 | ||||
| -rw-r--r-- | src/core/hle/service/nwm/uds_connection.cpp | 79 | ||||
| -rw-r--r-- | src/core/hle/service/nwm/uds_connection.h | 51 |
5 files changed, 144 insertions, 11 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ea09819e5..0719138af 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -144,6 +144,7 @@ set(SRCS | |||
| 144 | hle/service/nwm/nwm_tst.cpp | 144 | hle/service/nwm/nwm_tst.cpp |
| 145 | hle/service/nwm/nwm_uds.cpp | 145 | hle/service/nwm/nwm_uds.cpp |
| 146 | hle/service/nwm/uds_beacon.cpp | 146 | hle/service/nwm/uds_beacon.cpp |
| 147 | hle/service/nwm/uds_connection.cpp | ||
| 147 | hle/service/nwm/uds_data.cpp | 148 | hle/service/nwm/uds_data.cpp |
| 148 | hle/service/pm_app.cpp | 149 | hle/service/pm_app.cpp |
| 149 | hle/service/ptm/ptm.cpp | 150 | hle/service/ptm/ptm.cpp |
| @@ -342,6 +343,7 @@ set(HEADERS | |||
| 342 | hle/service/nwm/nwm_tst.h | 343 | hle/service/nwm/nwm_tst.h |
| 343 | hle/service/nwm/nwm_uds.h | 344 | hle/service/nwm/nwm_uds.h |
| 344 | hle/service/nwm/uds_beacon.h | 345 | hle/service/nwm/uds_beacon.h |
| 346 | hle/service/nwm/uds_connection.h | ||
| 345 | hle/service/nwm/uds_data.h | 347 | hle/service/nwm/uds_data.h |
| 346 | hle/service/pm_app.h | 348 | hle/service/pm_app.h |
| 347 | hle/service/ptm/ptm.h | 349 | hle/service/ptm/ptm.h |
diff --git a/src/core/hle/service/nwm/nwm_uds.h b/src/core/hle/service/nwm/nwm_uds.h index 141f49f9c..f1caaf974 100644 --- a/src/core/hle/service/nwm/nwm_uds.h +++ b/src/core/hle/service/nwm/nwm_uds.h | |||
| @@ -42,6 +42,7 @@ using NodeList = std::vector<NodeInfo>; | |||
| 42 | enum class NetworkStatus { | 42 | enum class NetworkStatus { |
| 43 | NotConnected = 3, | 43 | NotConnected = 3, |
| 44 | ConnectedAsHost = 6, | 44 | ConnectedAsHost = 6, |
| 45 | Connecting = 7, | ||
| 45 | ConnectedAsClient = 9, | 46 | ConnectedAsClient = 9, |
| 46 | ConnectedAsSpectator = 10, | 47 | ConnectedAsSpectator = 10, |
| 47 | }; | 48 | }; |
| @@ -85,6 +86,17 @@ static_assert(offsetof(NetworkInfo, oui_value) == 0xC, "oui_value is at the wron | |||
| 85 | static_assert(offsetof(NetworkInfo, wlan_comm_id) == 0x10, "wlancommid is at the wrong offset."); | 86 | static_assert(offsetof(NetworkInfo, wlan_comm_id) == 0x10, "wlancommid is at the wrong offset."); |
| 86 | static_assert(sizeof(NetworkInfo) == 0x108, "NetworkInfo has incorrect size."); | 87 | static_assert(sizeof(NetworkInfo) == 0x108, "NetworkInfo has incorrect size."); |
| 87 | 88 | ||
| 89 | /// Additional block tag ids in the Beacon and Association Response frames | ||
| 90 | enum class TagId : u8 { | ||
| 91 | SSID = 0, | ||
| 92 | SupportedRates = 1, | ||
| 93 | DSParameterSet = 2, | ||
| 94 | TrafficIndicationMap = 5, | ||
| 95 | CountryInformation = 7, | ||
| 96 | ERPInformation = 42, | ||
| 97 | VendorSpecific = 221 | ||
| 98 | }; | ||
| 99 | |||
| 88 | class NWM_UDS final : public Interface { | 100 | class NWM_UDS final : public Interface { |
| 89 | public: | 101 | public: |
| 90 | NWM_UDS(); | 102 | NWM_UDS(); |
diff --git a/src/core/hle/service/nwm/uds_beacon.h b/src/core/hle/service/nwm/uds_beacon.h index caacf4c6f..c726b04d9 100644 --- a/src/core/hle/service/nwm/uds_beacon.h +++ b/src/core/hle/service/nwm/uds_beacon.h | |||
| @@ -17,17 +17,6 @@ namespace NWM { | |||
| 17 | using MacAddress = std::array<u8, 6>; | 17 | using MacAddress = std::array<u8, 6>; |
| 18 | constexpr std::array<u8, 3> NintendoOUI = {0x00, 0x1F, 0x32}; | 18 | constexpr std::array<u8, 3> NintendoOUI = {0x00, 0x1F, 0x32}; |
| 19 | 19 | ||
| 20 | /// Additional block tag ids in the Beacon frames | ||
| 21 | enum class TagId : u8 { | ||
| 22 | SSID = 0, | ||
| 23 | SupportedRates = 1, | ||
| 24 | DSParameterSet = 2, | ||
| 25 | TrafficIndicationMap = 5, | ||
| 26 | CountryInformation = 7, | ||
| 27 | ERPInformation = 42, | ||
| 28 | VendorSpecific = 221 | ||
| 29 | }; | ||
| 30 | |||
| 31 | /** | 20 | /** |
| 32 | * Internal vendor-specific tag ids as stored inside | 21 | * Internal vendor-specific tag ids as stored inside |
| 33 | * VendorSpecific blocks in the Beacon frames. | 22 | * VendorSpecific blocks in the Beacon frames. |
diff --git a/src/core/hle/service/nwm/uds_connection.cpp b/src/core/hle/service/nwm/uds_connection.cpp new file mode 100644 index 000000000..c8a76ec2a --- /dev/null +++ b/src/core/hle/service/nwm/uds_connection.cpp | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "core/hle/service/nwm/nwm_uds.h" | ||
| 6 | #include "core/hle/service/nwm/uds_connection.h" | ||
| 7 | #include "fmt/format.h" | ||
| 8 | |||
| 9 | namespace Service { | ||
| 10 | namespace NWM { | ||
| 11 | |||
| 12 | // Note: These values were taken from a packet capture of an o3DS XL | ||
| 13 | // broadcasting a Super Smash Bros. 4 lobby. | ||
| 14 | constexpr u16 DefaultExtraCapabilities = 0x0431; | ||
| 15 | |||
| 16 | std::vector<u8> GenerateAuthenticationFrame(AuthenticationSeq seq) { | ||
| 17 | AuthenticationFrame frame{}; | ||
| 18 | frame.auth_seq = static_cast<u16>(seq); | ||
| 19 | |||
| 20 | std::vector<u8> data(sizeof(frame)); | ||
| 21 | std::memcpy(data.data(), &frame, sizeof(frame)); | ||
| 22 | |||
| 23 | return data; | ||
| 24 | } | ||
| 25 | |||
| 26 | AuthenticationSeq GetAuthenticationSeqNumber(const std::vector<u8>& body) { | ||
| 27 | AuthenticationFrame frame; | ||
| 28 | std::memcpy(&frame, body.data(), sizeof(frame)); | ||
| 29 | |||
| 30 | return static_cast<AuthenticationSeq>(frame.auth_seq); | ||
| 31 | } | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Generates an SSID tag of an 802.11 Beacon frame with an 8-byte character representation of the | ||
| 35 | * specified network id as the SSID value. | ||
| 36 | * @param network_id The network id to use. | ||
| 37 | * @returns A buffer with the SSID tag. | ||
| 38 | */ | ||
| 39 | static std::vector<u8> GenerateSSIDTag(u32 network_id) { | ||
| 40 | constexpr u8 SSIDSize = 8; | ||
| 41 | |||
| 42 | struct { | ||
| 43 | u8 id = static_cast<u8>(TagId::SSID); | ||
| 44 | u8 size = SSIDSize; | ||
| 45 | } tag_header; | ||
| 46 | |||
| 47 | std::vector<u8> buffer(sizeof(tag_header) + SSIDSize); | ||
| 48 | |||
| 49 | std::memcpy(buffer.data(), &tag_header, sizeof(tag_header)); | ||
| 50 | |||
| 51 | std::string network_name = fmt::format("{0:08X}", network_id); | ||
| 52 | |||
| 53 | std::memcpy(buffer.data() + sizeof(tag_header), network_name.c_str(), SSIDSize); | ||
| 54 | |||
| 55 | return buffer; | ||
| 56 | } | ||
| 57 | |||
| 58 | std::vector<u8> GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id) { | ||
| 59 | AssociationResponseFrame frame{}; | ||
| 60 | frame.capabilities = DefaultExtraCapabilities; | ||
| 61 | frame.status_code = static_cast<u16>(status); | ||
| 62 | // The association id is ORed with this magic value (0xC000) | ||
| 63 | constexpr u16 AssociationIdMagic = 0xC000; | ||
| 64 | frame.assoc_id = association_id | AssociationIdMagic; | ||
| 65 | |||
| 66 | std::vector<u8> data(sizeof(frame)); | ||
| 67 | std::memcpy(data.data(), &frame, sizeof(frame)); | ||
| 68 | |||
| 69 | auto ssid_tag = GenerateSSIDTag(network_id); | ||
| 70 | data.insert(data.end(), ssid_tag.begin(), ssid_tag.end()); | ||
| 71 | |||
| 72 | // TODO(Subv): Add the SupportedRates tag. | ||
| 73 | // TODO(Subv): Add the DSParameterSet tag. | ||
| 74 | // TODO(Subv): Add the ERPInformation tag. | ||
| 75 | return data; | ||
| 76 | } | ||
| 77 | |||
| 78 | } // namespace NWM | ||
| 79 | } // namespace Service | ||
diff --git a/src/core/hle/service/nwm/uds_connection.h b/src/core/hle/service/nwm/uds_connection.h new file mode 100644 index 000000000..73f55a4fd --- /dev/null +++ b/src/core/hle/service/nwm/uds_connection.h | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <vector> | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "common/swap.h" | ||
| 10 | #include "core/hle/service/service.h" | ||
| 11 | |||
| 12 | namespace Service { | ||
| 13 | namespace NWM { | ||
| 14 | |||
| 15 | /// Sequence number of the 802.11 authentication frames. | ||
| 16 | enum class AuthenticationSeq : u16 { SEQ1 = 1, SEQ2 = 2 }; | ||
| 17 | |||
| 18 | enum class AuthAlgorithm : u16 { OpenSystem = 0 }; | ||
| 19 | |||
| 20 | enum class AuthStatus : u16 { Successful = 0 }; | ||
| 21 | |||
| 22 | enum class AssocStatus : u16 { Successful = 0 }; | ||
| 23 | |||
| 24 | struct AuthenticationFrame { | ||
| 25 | u16_le auth_algorithm = static_cast<u16>(AuthAlgorithm::OpenSystem); | ||
| 26 | u16_le auth_seq; | ||
| 27 | u16_le status_code = static_cast<u16>(AuthStatus::Successful); | ||
| 28 | }; | ||
| 29 | |||
| 30 | static_assert(sizeof(AuthenticationFrame) == 6, "AuthenticationFrame has wrong size"); | ||
| 31 | |||
| 32 | struct AssociationResponseFrame { | ||
| 33 | u16_le capabilities; | ||
| 34 | u16_le status_code; | ||
| 35 | u16_le assoc_id; | ||
| 36 | }; | ||
| 37 | |||
| 38 | static_assert(sizeof(AssociationResponseFrame) == 6, "AssociationResponseFrame has wrong size"); | ||
| 39 | |||
| 40 | /// Generates an 802.11 authentication frame, starting at the frame body. | ||
| 41 | std::vector<u8> GenerateAuthenticationFrame(AuthenticationSeq seq); | ||
| 42 | |||
| 43 | /// Returns the sequence number from the body of an Authentication frame. | ||
| 44 | AuthenticationSeq GetAuthenticationSeqNumber(const std::vector<u8>& body); | ||
| 45 | |||
| 46 | /// Generates an 802.11 association response frame with the specified status, association id and | ||
| 47 | /// network id, starting at the frame body. | ||
| 48 | std::vector<u8> GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id); | ||
| 49 | |||
| 50 | } // namespace NWM | ||
| 51 | } // namespace Service | ||