From 7efb64132db95ef787481026a22d5b8244627a04 Mon Sep 17 00:00:00 2001 From: Subv Date: Tue, 13 Jun 2017 16:30:17 -0500 Subject: UDS: Stub SendTo to generate the unencrypted data frame with the right headers. --- src/core/hle/service/nwm/nwm_uds.cpp | 68 +++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'src/core/hle/service/nwm/nwm_uds.cpp') diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index e92900d48..f6125825f 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -15,6 +15,7 @@ #include "core/hle/result.h" #include "core/hle/service/nwm/nwm_uds.h" #include "core/hle/service/nwm/uds_beacon.h" +#include "core/hle/service/nwm/uds_data.h" #include "core/memory.h" namespace Service { @@ -372,6 +373,71 @@ static void DestroyNetwork(Interface* self) { LOG_WARNING(Service_NWM, "called"); } +/** + * NWM_UDS::SendTo service function. + * Sends a data frame to the UDS network we're connected to. + * Inputs: + * 0 : Command header. + * 1 : Unknown. + * 2 : u16 Destination network node id. + * 3 : u8 Data channel. + * 4 : Buffer size >> 2 + * 5 : Data size + * 6 : Flags + * 7 : Input buffer descriptor + * 8 : Input buffer address + * Outputs: + * 0 : Return header + * 1 : Result of function, 0 on success, otherwise error code + */ +static void SendTo(Interface* self) { + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x17, 6, 2); + + rp.Skip(1, false); + u16 dest_node_id = rp.Pop(); + u8 data_channel = rp.Pop(); + rp.Skip(1, false); + u32 data_size = rp.Pop(); + u32 flags = rp.Pop(); + + size_t desc_size; + const VAddr input_address = rp.PopStaticBuffer(&desc_size, false); + ASSERT(desc_size == data_size); + + // TODO(Subv): Figure out the error if this is called while not connected to a network. + if (connection_status.status == static_cast(NetworkStatus::ConnectedAsClient) || + connection_status.status == static_cast(NetworkStatus::ConnectedAsHost)) { + ASSERT_MSG(false, "Not connected to a network (unimplemented)"); + } + + // TODO(Subv): Do something with the flags. + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + + constexpr size_t MaxSize = 0x5C6; + if (data_size > MaxSize) { + rb.Push(ResultCode(ErrorDescription::TooLarge, ErrorModule::UDS, + ErrorSummary::WrongArgument, ErrorLevel::Usage)); + return; + } + + std::vector data(data_size); + Memory::ReadBlock(input_address, data.data(), data.size()); + + // TODO(Subv): Increment the sequence number after each sent packet. + u16 sequence_number = 0; + std::vector data_frame = GenerateDataFrame(data, data_channel, dest_node_id, + connection_status.network_node_id, + sequence_number); + + // TODO(Subv): Send the frame. + + rb.Push(RESULT_SUCCESS); + + LOG_WARNING(Service_NWM, "(STUB) called dest_node_id=%u size=%u flags=%u channel=%u", + static_cast(dest_node_id), data_size, flags, static_cast(data_channel)); +} + /** * NWM_UDS::GetChannel service function. * Returns the WiFi channel in which the network we're connected to is transmitting. @@ -564,7 +630,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x00130040, nullptr, "Unbind"}, {0x001400C0, nullptr, "PullPacket"}, {0x00150080, nullptr, "SetMaxSendDelay"}, - {0x00170182, nullptr, "SendTo"}, + {0x00170182, SendTo, "SendTo"}, {0x001A0000, GetChannel, "GetChannel"}, {0x001B0302, InitializeWithVersion, "InitializeWithVersion"}, {0x001D0044, BeginHostingNetwork, "BeginHostingNetwork"}, -- cgit v1.2.3 From 61ce89a55ac6ff12f881e3bba0220ac3f04fbf50 Mon Sep 17 00:00:00 2001 From: Subv Date: Tue, 13 Jun 2017 21:50:22 -0500 Subject: UDS: Return the correct error messages in SendTo when not connected to a network or trying to send to itself. --- src/core/hle/service/nwm/nwm_uds.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/core/hle/service/nwm/nwm_uds.cpp') diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index f6125825f..c43c5ca44 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -404,15 +404,22 @@ static void SendTo(Interface* self) { const VAddr input_address = rp.PopStaticBuffer(&desc_size, false); ASSERT(desc_size == data_size); - // TODO(Subv): Figure out the error if this is called while not connected to a network. - if (connection_status.status == static_cast(NetworkStatus::ConnectedAsClient) || - connection_status.status == static_cast(NetworkStatus::ConnectedAsHost)) { - ASSERT_MSG(false, "Not connected to a network (unimplemented)"); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + + if (connection_status.status != static_cast(NetworkStatus::ConnectedAsClient) && + connection_status.status != static_cast(NetworkStatus::ConnectedAsHost)) { + rb.Push(ResultCode(ErrorDescription::NotAuthorized, ErrorModule::UDS, + ErrorSummary::InvalidState, ErrorLevel::Status)); + return; } - // TODO(Subv): Do something with the flags. + if (dest_node_id == connection_status.network_node_id) { + rb.Push(ResultCode(ErrorDescription::NotFound, ErrorModule::UDS, + ErrorSummary::WrongArgument, ErrorLevel::Status)); + return; + } - IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + // TODO(Subv): Do something with the flags. constexpr size_t MaxSize = 0x5C6; if (data_size > MaxSize) { -- cgit v1.2.3 From 9befb8c887b78128a2e8ef8febc82a4933196602 Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 14 Jun 2017 12:47:52 -0500 Subject: UDS: Added functions to encrypt and decrypt the data frames. The responsibility of encryption and encapsulation into an 802.11 MAC frame will fall into the callers of GenerateDataPayload. --- src/core/hle/service/nwm/nwm_uds.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/core/hle/service/nwm/nwm_uds.cpp') diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index c43c5ca44..d9bd9c4a4 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -433,9 +433,12 @@ static void SendTo(Interface* self) { // TODO(Subv): Increment the sequence number after each sent packet. u16 sequence_number = 0; - std::vector data_frame = GenerateDataFrame(data, data_channel, dest_node_id, - connection_status.network_node_id, - sequence_number); + std::vector data_payload = GenerateDataPayload(data, data_channel, dest_node_id, + connection_status.network_node_id, + sequence_number); + + // TODO(Subv): Retrieve the MAC address of the dest_node_id and our own to encrypt + // and encapsulate the payload. // TODO(Subv): Send the frame. -- cgit v1.2.3 From 87168bfe8b5b0b96f7e39f33db1df52da046c39a Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 14 Jun 2017 13:18:58 -0500 Subject: UDS: Run clang-format. --- src/core/hle/service/nwm/nwm_uds.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/core/hle/service/nwm/nwm_uds.cpp') diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index d9bd9c4a4..35fa1cd77 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -433,9 +433,8 @@ static void SendTo(Interface* self) { // TODO(Subv): Increment the sequence number after each sent packet. u16 sequence_number = 0; - std::vector data_payload = GenerateDataPayload(data, data_channel, dest_node_id, - connection_status.network_node_id, - sequence_number); + std::vector data_payload = GenerateDataPayload( + data, data_channel, dest_node_id, connection_status.network_node_id, sequence_number); // TODO(Subv): Retrieve the MAC address of the dest_node_id and our own to encrypt // and encapsulate the payload. @@ -640,7 +639,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x00130040, nullptr, "Unbind"}, {0x001400C0, nullptr, "PullPacket"}, {0x00150080, nullptr, "SetMaxSendDelay"}, - {0x00170182, SendTo, "SendTo"}, + {0x00170182, SendTo, "SendTo"}, {0x001A0000, GetChannel, "GetChannel"}, {0x001B0302, InitializeWithVersion, "InitializeWithVersion"}, {0x001D0044, BeginHostingNetwork, "BeginHostingNetwork"}, -- cgit v1.2.3