From cbf514190ec32794c16e2f9bd6aabfd8c7a2518f Mon Sep 17 00:00:00 2001 From: B3n30 Date: Thu, 15 Feb 2018 22:13:53 +0100 Subject: [PATCH] NWM_UDS: Addressed wwyleles comments --- src/core/hle/service/nwm/nwm_uds.cpp | 30 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 426ce6ad8..8b0ea6180 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -510,7 +510,11 @@ void NWM_UDS::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) { u32 wlan_comm_id = rp.Pop(); u32 id = rp.Pop(); - Kernel::Handle input_handle = rp.PopHandle(); + // From 3dbrew: + // 'Official user processes create a new event handle which is then passed to this command. + // However, those user processes don't save that handle anywhere afterwards.' + // So we don't save/use that event too. + Kernel::SharedPtr input_event = rp.PopObject(); Kernel::MappedBuffer out_buffer = rp.PopMappedBuffer(); ASSERT(out_buffer.GetSize() == out_buffer_size); @@ -540,7 +544,7 @@ void NWM_UDS::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) { out_buffer.Write(&entry, offset, sizeof(BeaconEntryHeader)); offset += sizeof(BeaconEntryHeader); const unsigned char* beacon_data = beacon.data.data(); - out_buffer.Write(const_cast(static_cast(beacon_data)), offset, + out_buffer.Write(beacon_data, offset, beacon.data.size()); offset += beacon.data.size(); @@ -551,12 +555,13 @@ void NWM_UDS::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) { data_reply_header.total_size = total_size; out_buffer.Write(&data_reply_header, 0, sizeof(BeaconDataReplyHeader)); - IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 1); rb.Push(RESULT_SUCCESS); + rb.PushMappedBuffer(out_buffer); LOG_DEBUG(Service_NWM, "called out_buffer_size=0x%08X, wlan_comm_id=0x%08X, id=0x%08X," - "input_handle=0x%08X, unk1=0x%08X, unk2=0x%08X, offset=%d", - out_buffer_size, wlan_comm_id, id, input_handle, unk1, unk2, offset); + "unk1=0x%08X, unk2=0x%08X, offset=%zu", + out_buffer_size, wlan_comm_id, id, unk1, unk2, offset); } void NWM_UDS::InitializeWithVersion(Kernel::HLERequestContext& ctx) { @@ -663,7 +668,7 @@ void NWM_UDS::Bind(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(ResultCode(ErrorDescription::NotAuthorized, ErrorModule::UDS, ErrorSummary::WrongArgument, ErrorLevel::Usage)); - LOG_DEBUG(Service_NWM, "data_channel = %d, bind_node_id = %d", data_channel, bind_node_id); + LOG_WARNING(Service_NWM, "data_channel = %d, bind_node_id = %d", data_channel, bind_node_id); return; } @@ -672,7 +677,7 @@ void NWM_UDS::Bind(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(ResultCode(ErrorDescription::OutOfMemory, ErrorModule::UDS, ErrorSummary::OutOfResource, ErrorLevel::Status)); - LOG_DEBUG(Service_NWM, "max bind nodes"); + LOG_WARNING(Service_NWM, "max bind nodes"); return; } @@ -681,7 +686,7 @@ void NWM_UDS::Bind(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(ResultCode(ErrorDescription::TooLarge, ErrorModule::UDS, ErrorSummary::WrongArgument, ErrorLevel::Usage)); - LOG_DEBUG(Service_NWM, "MinRecvBufferSize"); + LOG_WARNING(Service_NWM, "MinRecvBufferSize"); return; } @@ -967,6 +972,7 @@ void NWM_UDS::PullPacket(Kernel::HLERequestContext& ctx) { u32 max_out_buff_size_aligned = rp.Pop(); u32 max_out_buff_size = rp.Pop(); + // This size is hard coded into the uds module. We don't know the meaning yet. u32 buff_size = std::min(max_out_buff_size_aligned, 0x172) << 2; std::lock_guard lock(connection_status_mutex); @@ -1123,11 +1129,11 @@ void NWM_UDS::DecryptBeaconData(Kernel::HLERequestContext& ctx) { ASSERT_MSG(encrypted_data0_buffer[3] == static_cast(NintendoTagId::EncryptedData0), "Unexpected tag id"); - std::vector beacon_data(encrypted_data0_buffer.size() + encrypted_data1_buffer.size()); + std::vector beacon_data(encrypted_data0_buffer.size() - 4 + encrypted_data1_buffer.size() - 4); std::memcpy(beacon_data.data(), encrypted_data0_buffer.data() + 4, - encrypted_data0_buffer.size()); - std::memcpy(beacon_data.data() + encrypted_data0_buffer.size(), - encrypted_data1_buffer.data() + 4, encrypted_data1_buffer.size()); + encrypted_data0_buffer.size() - 4); + std::memcpy(beacon_data.data() + encrypted_data0_buffer.size() - 4, + encrypted_data1_buffer.data() + 4, encrypted_data1_buffer.size() - 4); // Decrypt the data DecryptBeacon(net_info, beacon_data);