From ac168eeb5dea3d24e537dce096563466dbc012fe Mon Sep 17 00:00:00 2001 From: Sebastian Valle Date: Tue, 13 Jun 2017 19:00:58 +0000 Subject: [PATCH] Services/UDS: Set the proper bit in the ConnectionStatus structure when creating a network. (#2738) * Services/UDS: Set the proper bit in the ConnectionStatus structure when creating a network. This lets the application know that the host was successfully added to the session. * Services/UDS: Reset the connection status when destroying the network * Services/UDS: Reset the connection status's bitmask of changed nodes after reporting it to the game. --- src/core/hle/service/nwm/nwm_uds.cpp | 10 ++++++++++ src/core/hle/service/nwm/nwm_uds.h | 7 +++++-- src/core/hle/service/nwm/uds_beacon.h | 3 --- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 6c4600f255..e92900d484 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -215,6 +215,11 @@ static void GetConnectionStatus(Interface* self) { rb.Push(RESULT_SUCCESS); rb.PushRaw(connection_status); + // Reset the bitmask of changed nodes after each call to this + // function to prevent falsely informing games of outstanding + // changes in subsequent calls. + connection_status.changed_nodes = 0; + LOG_DEBUG(Service_NWM, "called"); } @@ -314,8 +319,11 @@ static void BeginHostingNetwork(Interface* self) { // The host is always the first node connection_status.network_node_id = 1; node_info[0].network_node_id = 1; + connection_status.nodes[0] = connection_status.network_node_id; // Set the bit 0 in the nodes bitmask to indicate that node 1 is already taken. connection_status.node_bitmask |= 1; + // Notify the application that the first node was set. + connection_status.changed_nodes |= 1; // If the game has a preferred channel, use that instead. if (network_info.channel != 0) @@ -352,6 +360,8 @@ static void DestroyNetwork(Interface* self) { // Unschedule the beacon broadcast event. CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0); + // TODO(Subv): Check if connection_status is indeed reset after this call. + connection_status = {}; connection_status.status = static_cast(NetworkStatus::NotConnected); connection_status_event->Signal(); diff --git a/src/core/hle/service/nwm/nwm_uds.h b/src/core/hle/service/nwm/nwm_uds.h index 29b1465695..141f49f9c0 100644 --- a/src/core/hle/service/nwm/nwm_uds.h +++ b/src/core/hle/service/nwm/nwm_uds.h @@ -24,6 +24,9 @@ const double MillisecondsPerTU = 1.024; // Interval measured in TU, the default value is 100TU = 102.4ms const u16 DefaultBeaconInterval = 100; +/// The maximum number of nodes that can exist in an UDS session. +constexpr u32 UDSMaxNodes = 16; + struct NodeInfo { u64_le friend_code_seed; std::array username; @@ -47,8 +50,8 @@ struct ConnectionStatus { u32_le status; INSERT_PADDING_WORDS(1); u16_le network_node_id; - INSERT_PADDING_BYTES(2); - INSERT_PADDING_BYTES(32); + u16_le changed_nodes; + u16_le nodes[UDSMaxNodes]; u8 total_nodes; u8 max_nodes; u16_le node_bitmask; diff --git a/src/core/hle/service/nwm/uds_beacon.h b/src/core/hle/service/nwm/uds_beacon.h index 6df4c4f478..caacf4c6fa 100644 --- a/src/core/hle/service/nwm/uds_beacon.h +++ b/src/core/hle/service/nwm/uds_beacon.h @@ -15,9 +15,6 @@ namespace Service { namespace NWM { using MacAddress = std::array; - -/// The maximum number of nodes that can exist in an UDS session. -constexpr u32 UDSMaxNodes = 16; constexpr std::array NintendoOUI = {0x00, 0x1F, 0x32}; /// Additional block tag ids in the Beacon frames