diff options
| author | 2017-04-12 11:57:24 -0500 | |
|---|---|---|
| committer | 2017-04-12 11:57:24 -0500 | |
| commit | 26745f28ea00f1f085ef030cc4be4a4eae44e5a6 (patch) | |
| tree | 2be08d13a7a14bf1dbc8976f3c287053e9ed1b7e | |
| parent | Merge pull request #2658 from JayFoxRox/blend-equation-fix (diff) | |
| parent | Services/UDS: Fixed a style mistake in GetChannel. (diff) | |
| download | yuzu-26745f28ea00f1f085ef030cc4be4a4eae44e5a6.tar.gz yuzu-26745f28ea00f1f085ef030cc4be4a4eae44e5a6.tar.xz yuzu-26745f28ea00f1f085ef030cc4be4a4eae44e5a6.zip | |
Merge pull request #2628 from Subv/uds
Services/UDS: Initial support for hosting local-wlan networks.
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/service/nwm/nwm_uds.cpp | 367 | ||||
| -rw-r--r-- | src/core/hle/service/nwm/nwm_uds.h | 66 |
2 files changed, 388 insertions, 45 deletions
diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 08fade320..ef6c5ebe3 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp | |||
| @@ -1,16 +1,49 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | 1 | // Copyright 2017 Citra Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | ||
| 6 | #include <unordered_map> | ||
| 7 | #include <vector> | ||
| 5 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 6 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "core/core_timing.h" | ||
| 7 | #include "core/hle/kernel/event.h" | 11 | #include "core/hle/kernel/event.h" |
| 12 | #include "core/hle/kernel/shared_memory.h" | ||
| 13 | #include "core/hle/result.h" | ||
| 8 | #include "core/hle/service/nwm/nwm_uds.h" | 14 | #include "core/hle/service/nwm/nwm_uds.h" |
| 15 | #include "core/memory.h" | ||
| 9 | 16 | ||
| 10 | namespace Service { | 17 | namespace Service { |
| 11 | namespace NWM { | 18 | namespace NWM { |
| 12 | 19 | ||
| 13 | static Kernel::SharedPtr<Kernel::Event> uds_handle_event; | 20 | // Event that is signaled every time the connection status changes. |
| 21 | static Kernel::SharedPtr<Kernel::Event> connection_status_event; | ||
| 22 | |||
| 23 | // Shared memory provided by the application to store the receive buffer. | ||
| 24 | // This is not currently used. | ||
| 25 | static Kernel::SharedPtr<Kernel::SharedMemory> recv_buffer_memory; | ||
| 26 | |||
| 27 | // Connection status of this 3DS. | ||
| 28 | static ConnectionStatus connection_status{}; | ||
| 29 | |||
| 30 | // Node information about the current 3DS. | ||
| 31 | // TODO(Subv): Keep an array of all nodes connected to the network, | ||
| 32 | // that data has to be retransmitted in every beacon frame. | ||
| 33 | static NodeInfo node_info; | ||
| 34 | |||
| 35 | // Mapping of bind node ids to their respective events. | ||
| 36 | static std::unordered_map<u32, Kernel::SharedPtr<Kernel::Event>> bind_node_events; | ||
| 37 | |||
| 38 | // The WiFi network channel that the network is currently on. | ||
| 39 | // Since we're not actually interacting with physical radio waves, this is just a dummy value. | ||
| 40 | static u8 network_channel = DefaultNetworkChannel; | ||
| 41 | |||
| 42 | // Information about the network that we're currently connected to. | ||
| 43 | static NetworkInfo network_info; | ||
| 44 | |||
| 45 | // Event that will generate and send the 802.11 beacon frames. | ||
| 46 | static int beacon_broadcast_event; | ||
| 14 | 47 | ||
| 15 | /** | 48 | /** |
| 16 | * NWM_UDS::Shutdown service function | 49 | * NWM_UDS::Shutdown service function |
| @@ -32,14 +65,14 @@ static void Shutdown(Interface* self) { | |||
| 32 | 65 | ||
| 33 | /** | 66 | /** |
| 34 | * NWM_UDS::RecvBeaconBroadcastData service function | 67 | * NWM_UDS::RecvBeaconBroadcastData service function |
| 68 | * Returns the raw beacon data for nearby networks that match the supplied WlanCommId. | ||
| 35 | * Inputs: | 69 | * Inputs: |
| 36 | * 1 : Output buffer max size | 70 | * 1 : Output buffer max size |
| 37 | * 2 : Unknown | 71 | * 2-3 : Unknown |
| 38 | * 3 : Unknown | 72 | * 4-5 : Host MAC address. |
| 39 | * 4 : MAC address? | 73 | * 6-14 : Unused |
| 40 | * 6-14 : Unknown, usually zero / uninitialized? | 74 | * 15 : WLan Comm Id |
| 41 | * 15 : WLan Comm ID | 75 | * 16 : Id |
| 42 | * 16 : This is the ID also located at offset 0xE in the CTR-generation structure. | ||
| 43 | * 17 : Value 0 | 76 | * 17 : Value 0 |
| 44 | * 18 : Input handle | 77 | * 18 : Input handle |
| 45 | * 19 : (Size<<4) | 12 | 78 | * 19 : (Size<<4) | 12 |
| @@ -77,42 +110,274 @@ static void RecvBeaconBroadcastData(Interface* self) { | |||
| 77 | /** | 110 | /** |
| 78 | * NWM_UDS::Initialize service function | 111 | * NWM_UDS::Initialize service function |
| 79 | * Inputs: | 112 | * Inputs: |
| 80 | * 1 : Unknown | 113 | * 1 : Shared memory size |
| 81 | * 2-11 : Input Structure | 114 | * 2-11 : Input NodeInfo Structure |
| 82 | * 12 : Unknown u16 | 115 | * 12 : 2-byte Version |
| 83 | * 13 : Value 0 | 116 | * 13 : Value 0 |
| 84 | * 14 : Handle | 117 | * 14 : Shared memory handle |
| 85 | * Outputs: | 118 | * Outputs: |
| 86 | * 0 : Return header | 119 | * 0 : Return header |
| 87 | * 1 : Result of function, 0 on success, otherwise error code | 120 | * 1 : Result of function, 0 on success, otherwise error code |
| 88 | * 2 : Value 0 | 121 | * 2 : Value 0 |
| 89 | * 3 : Output handle | 122 | * 3 : Output event handle |
| 90 | */ | 123 | */ |
| 91 | static void InitializeWithVersion(Interface* self) { | 124 | static void InitializeWithVersion(Interface* self) { |
| 92 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 125 | IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1B, 12, 2); |
| 93 | u32 unk1 = cmd_buff[1]; | 126 | |
| 94 | u32 unk2 = cmd_buff[12]; | 127 | u32 sharedmem_size = rp.Pop<u32>(); |
| 95 | u32 value = cmd_buff[13]; | 128 | |
| 96 | u32 handle = cmd_buff[14]; | 129 | // Update the node information with the data the game gave us. |
| 97 | 130 | rp.PopRaw(node_info); | |
| 98 | // Because NWM service is not implemented at all, we stub the Initialize function with an error | 131 | |
| 99 | // code instead of success to prevent games from using the service and from causing more issues. | 132 | u16 version; |
| 100 | // The error code is from a real 3DS with wifi off, thus believed to be "network disabled". | 133 | rp.PopRaw(version); |
| 101 | /* | 134 | Kernel::Handle sharedmem_handle = rp.PopHandle(); |
| 102 | cmd_buff[1] = RESULT_SUCCESS.raw; | 135 | |
| 103 | cmd_buff[2] = 0; | 136 | recv_buffer_memory = Kernel::g_handle_table.Get<Kernel::SharedMemory>(sharedmem_handle); |
| 104 | cmd_buff[3] = Kernel::g_handle_table.Create(uds_handle_event) | 137 | |
| 105 | .MoveFrom(); // TODO(purpasmart): Verify if this is a event handle | 138 | ASSERT_MSG(recv_buffer_memory->size == sharedmem_size, "Invalid shared memory size."); |
| 106 | */ | 139 | |
| 107 | cmd_buff[0] = IPC::MakeHeader(0x1B, 1, 2); | 140 | // Reset the connection status, it contains all zeros after initialization, |
| 108 | cmd_buff[1] = ResultCode(static_cast<ErrorDescription>(2), ErrorModule::UDS, | 141 | // except for the actual status value. |
| 109 | ErrorSummary::StatusChanged, ErrorLevel::Status) | 142 | connection_status = {}; |
| 110 | .raw; | 143 | connection_status.status = static_cast<u32>(NetworkStatus::NotConnected); |
| 111 | cmd_buff[2] = 0; | 144 | |
| 112 | cmd_buff[3] = 0; | 145 | IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); |
| 113 | 146 | rb.Push(RESULT_SUCCESS); | |
| 114 | LOG_WARNING(Service_NWM, "(STUBBED) called unk1=0x%08X, unk2=0x%08X, value=%u, handle=0x%08X", | 147 | rb.PushCopyHandles(Kernel::g_handle_table.Create(connection_status_event).MoveFrom()); |
| 115 | unk1, unk2, value, handle); | 148 | |
| 149 | LOG_DEBUG(Service_NWM, "called sharedmem_size=0x%08X, version=0x%08X, sharedmem_handle=0x%08X", | ||
| 150 | sharedmem_size, version, sharedmem_handle); | ||
| 151 | } | ||
| 152 | |||
| 153 | /** | ||
| 154 | * NWM_UDS::GetConnectionStatus service function. | ||
| 155 | * Returns the connection status structure for the currently open network connection. | ||
| 156 | * This structure contains information about the connection, | ||
| 157 | * like the number of connected nodes, etc. | ||
| 158 | * Inputs: | ||
| 159 | * 0 : Command header. | ||
| 160 | * Outputs: | ||
| 161 | * 0 : Return header | ||
| 162 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 163 | * 2-13 : Channel of the current WiFi network connection. | ||
| 164 | */ | ||
| 165 | static void GetConnectionStatus(Interface* self) { | ||
| 166 | IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0xB, 0, 0); | ||
| 167 | IPC::RequestBuilder rb = rp.MakeBuilder(13, 0); | ||
| 168 | |||
| 169 | rb.Push(RESULT_SUCCESS); | ||
| 170 | rb.PushRaw(connection_status); | ||
| 171 | |||
| 172 | LOG_DEBUG(Service_NWM, "called"); | ||
| 173 | } | ||
| 174 | |||
| 175 | /** | ||
| 176 | * NWM_UDS::Bind service function. | ||
| 177 | * Binds a BindNodeId to a data channel and retrieves a data event. | ||
| 178 | * Inputs: | ||
| 179 | * 1 : BindNodeId | ||
| 180 | * 2 : Receive buffer size. | ||
| 181 | * 3 : u8 Data channel to bind to. | ||
| 182 | * 4 : Network node id. | ||
| 183 | * Outputs: | ||
| 184 | * 0 : Return header | ||
| 185 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 186 | * 2 : Copy handle descriptor. | ||
| 187 | * 3 : Data available event handle. | ||
| 188 | */ | ||
| 189 | static void Bind(Interface* self) { | ||
| 190 | IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x12, 4, 0); | ||
| 191 | |||
| 192 | u32 bind_node_id = rp.Pop<u32>(); | ||
| 193 | u32 recv_buffer_size = rp.Pop<u32>(); | ||
| 194 | u8 data_channel; | ||
| 195 | rp.PopRaw(data_channel); | ||
| 196 | u16 network_node_id; | ||
| 197 | rp.PopRaw(network_node_id); | ||
| 198 | |||
| 199 | // TODO(Subv): Store the data channel and verify it when receiving data frames. | ||
| 200 | |||
| 201 | LOG_DEBUG(Service_NWM, "called"); | ||
| 202 | |||
| 203 | if (data_channel == 0) { | ||
| 204 | IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); | ||
| 205 | rb.Push(ResultCode(ErrorDescription::NotAuthorized, ErrorModule::UDS, | ||
| 206 | ErrorSummary::WrongArgument, ErrorLevel::Usage)); | ||
| 207 | return; | ||
| 208 | } | ||
| 209 | |||
| 210 | // Create a new event for this bind node. | ||
| 211 | // TODO(Subv): Signal this event when new data is received on this data channel. | ||
| 212 | auto event = Kernel::Event::Create(Kernel::ResetType::OneShot, | ||
| 213 | "NWM::BindNodeEvent" + std::to_string(bind_node_id)); | ||
| 214 | bind_node_events[bind_node_id] = event; | ||
| 215 | |||
| 216 | IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); | ||
| 217 | |||
| 218 | rb.Push(RESULT_SUCCESS); | ||
| 219 | rb.PushCopyHandles(Kernel::g_handle_table.Create(event).MoveFrom()); | ||
| 220 | } | ||
| 221 | |||
| 222 | /** | ||
| 223 | * NWM_UDS::BeginHostingNetwork service function. | ||
| 224 | * Creates a network and starts broadcasting its presence. | ||
| 225 | * Inputs: | ||
| 226 | * 1 : Passphrase buffer size. | ||
| 227 | * 3 : VAddr of the NetworkInfo structure. | ||
| 228 | * 5 : VAddr of the passphrase. | ||
| 229 | * Outputs: | ||
| 230 | * 0 : Return header | ||
| 231 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 232 | */ | ||
| 233 | static void BeginHostingNetwork(Interface* self) { | ||
| 234 | IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1D, 1, 4); | ||
| 235 | |||
| 236 | const u32 passphrase_size = rp.Pop<u32>(); | ||
| 237 | |||
| 238 | size_t desc_size; | ||
| 239 | const VAddr network_info_address = rp.PopStaticBuffer(&desc_size, false); | ||
| 240 | ASSERT(desc_size == sizeof(NetworkInfo)); | ||
| 241 | const VAddr passphrase_address = rp.PopStaticBuffer(&desc_size, false); | ||
| 242 | ASSERT(desc_size == passphrase_size); | ||
| 243 | |||
| 244 | // TODO(Subv): Store the passphrase and verify it when attempting a connection. | ||
| 245 | |||
| 246 | LOG_DEBUG(Service_NWM, "called"); | ||
| 247 | |||
| 248 | Memory::ReadBlock(network_info_address, &network_info, sizeof(NetworkInfo)); | ||
| 249 | |||
| 250 | // The real UDS module throws a fatal error if this assert fails. | ||
| 251 | ASSERT_MSG(network_info.max_nodes > 1, "Trying to host a network of only one member."); | ||
| 252 | |||
| 253 | connection_status.status = static_cast<u32>(NetworkStatus::ConnectedAsHost); | ||
| 254 | connection_status.max_nodes = network_info.max_nodes; | ||
| 255 | |||
| 256 | // There's currently only one node in the network (the host). | ||
| 257 | connection_status.total_nodes = 1; | ||
| 258 | // The host is always the first node | ||
| 259 | connection_status.network_node_id = 1; | ||
| 260 | node_info.network_node_id = 1; | ||
| 261 | // Set the bit 0 in the nodes bitmask to indicate that node 1 is already taken. | ||
| 262 | connection_status.node_bitmask |= 1; | ||
| 263 | |||
| 264 | // If the game has a preferred channel, use that instead. | ||
| 265 | if (network_info.channel != 0) | ||
| 266 | network_channel = network_info.channel; | ||
| 267 | |||
| 268 | connection_status_event->Signal(); | ||
| 269 | |||
| 270 | // Start broadcasting the network, send a beacon frame every 102.4ms. | ||
| 271 | CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU), | ||
| 272 | beacon_broadcast_event, 0); | ||
| 273 | |||
| 274 | LOG_WARNING(Service_NWM, | ||
| 275 | "An UDS network has been created, but broadcasting it is unimplemented."); | ||
| 276 | |||
| 277 | IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); | ||
| 278 | rb.Push(RESULT_SUCCESS); | ||
| 279 | } | ||
| 280 | |||
| 281 | /** | ||
| 282 | * NWM_UDS::DestroyNetwork service function. | ||
| 283 | * Closes the network that we're currently hosting. | ||
| 284 | * Inputs: | ||
| 285 | * 0 : Command header. | ||
| 286 | * Outputs: | ||
| 287 | * 0 : Return header | ||
| 288 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 289 | */ | ||
| 290 | static void DestroyNetwork(Interface* self) { | ||
| 291 | IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x08, 0, 0); | ||
| 292 | |||
| 293 | // TODO(Subv): Find out what happens if this is called while | ||
| 294 | // no network is being hosted. | ||
| 295 | |||
| 296 | // Unschedule the beacon broadcast event. | ||
| 297 | CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0); | ||
| 298 | |||
| 299 | connection_status.status = static_cast<u8>(NetworkStatus::NotConnected); | ||
| 300 | connection_status_event->Signal(); | ||
| 301 | |||
| 302 | IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); | ||
| 303 | |||
| 304 | rb.Push(RESULT_SUCCESS); | ||
| 305 | |||
| 306 | LOG_WARNING(Service_NWM, "called"); | ||
| 307 | } | ||
| 308 | |||
| 309 | /** | ||
| 310 | * NWM_UDS::GetChannel service function. | ||
| 311 | * Returns the WiFi channel in which the network we're connected to is transmitting. | ||
| 312 | * Inputs: | ||
| 313 | * 0 : Command header. | ||
| 314 | * Outputs: | ||
| 315 | * 0 : Return header | ||
| 316 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 317 | * 2 : Channel of the current WiFi network connection. | ||
| 318 | */ | ||
| 319 | static void GetChannel(Interface* self) { | ||
| 320 | IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1A, 0, 0); | ||
| 321 | IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); | ||
| 322 | |||
| 323 | bool is_connected = connection_status.status != static_cast<u32>(NetworkStatus::NotConnected); | ||
| 324 | |||
| 325 | u8 channel = is_connected ? network_channel : 0; | ||
| 326 | |||
| 327 | rb.Push(RESULT_SUCCESS); | ||
| 328 | rb.PushRaw(channel); | ||
| 329 | |||
| 330 | LOG_DEBUG(Service_NWM, "called"); | ||
| 331 | } | ||
| 332 | |||
| 333 | /** | ||
| 334 | * NWM_UDS::SetApplicationData service function. | ||
| 335 | * Updates the application data that is being broadcast in the beacon frames | ||
| 336 | * for the network that we're hosting. | ||
| 337 | * Inputs: | ||
| 338 | * 1 : Data size. | ||
| 339 | * 3 : VAddr of the data. | ||
| 340 | * Outputs: | ||
| 341 | * 0 : Return header | ||
| 342 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 343 | * 2 : Channel of the current WiFi network connection. | ||
| 344 | */ | ||
| 345 | static void SetApplicationData(Interface* self) { | ||
| 346 | IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1A, 1, 2); | ||
| 347 | |||
| 348 | u32 size = rp.Pop<u32>(); | ||
| 349 | |||
| 350 | size_t desc_size; | ||
| 351 | const VAddr address = rp.PopStaticBuffer(&desc_size, false); | ||
| 352 | ASSERT(desc_size == size); | ||
| 353 | |||
| 354 | LOG_DEBUG(Service_NWM, "called"); | ||
| 355 | |||
| 356 | IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); | ||
| 357 | |||
| 358 | if (size > ApplicationDataSize) { | ||
| 359 | rb.Push(ResultCode(ErrorDescription::TooLarge, ErrorModule::UDS, | ||
| 360 | ErrorSummary::WrongArgument, ErrorLevel::Usage)); | ||
| 361 | return; | ||
| 362 | } | ||
| 363 | |||
| 364 | network_info.application_data_size = size; | ||
| 365 | Memory::ReadBlock(address, network_info.application_data.data(), size); | ||
| 366 | |||
| 367 | rb.Push(RESULT_SUCCESS); | ||
| 368 | } | ||
| 369 | |||
| 370 | // Sends a 802.11 beacon frame with information about the current network. | ||
| 371 | static void BeaconBroadcastCallback(u64 userdata, int cycles_late) { | ||
| 372 | // Don't do anything if we're not actually hosting a network | ||
| 373 | if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) | ||
| 374 | return; | ||
| 375 | |||
| 376 | // TODO(Subv): Actually generate the beacon and send it. | ||
| 377 | |||
| 378 | // Start broadcasting the network, send a beacon frame every 102.4ms. | ||
| 379 | CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU) - cycles_late, | ||
| 380 | beacon_broadcast_event, 0); | ||
| 116 | } | 381 | } |
| 117 | 382 | ||
| 118 | const Interface::FunctionInfo FunctionTable[] = { | 383 | const Interface::FunctionInfo FunctionTable[] = { |
| @@ -123,23 +388,23 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 123 | {0x00050040, nullptr, "EjectClient"}, | 388 | {0x00050040, nullptr, "EjectClient"}, |
| 124 | {0x00060000, nullptr, "EjectSpectator"}, | 389 | {0x00060000, nullptr, "EjectSpectator"}, |
| 125 | {0x00070080, nullptr, "UpdateNetworkAttribute"}, | 390 | {0x00070080, nullptr, "UpdateNetworkAttribute"}, |
| 126 | {0x00080000, nullptr, "DestroyNetwork"}, | 391 | {0x00080000, DestroyNetwork, "DestroyNetwork"}, |
| 127 | {0x00090442, nullptr, "ConnectNetwork (deprecated)"}, | 392 | {0x00090442, nullptr, "ConnectNetwork (deprecated)"}, |
| 128 | {0x000A0000, nullptr, "DisconnectNetwork"}, | 393 | {0x000A0000, nullptr, "DisconnectNetwork"}, |
| 129 | {0x000B0000, nullptr, "GetConnectionStatus"}, | 394 | {0x000B0000, GetConnectionStatus, "GetConnectionStatus"}, |
| 130 | {0x000D0040, nullptr, "GetNodeInformation"}, | 395 | {0x000D0040, nullptr, "GetNodeInformation"}, |
| 131 | {0x000E0006, nullptr, "DecryptBeaconData (deprecated)"}, | 396 | {0x000E0006, nullptr, "DecryptBeaconData (deprecated)"}, |
| 132 | {0x000F0404, RecvBeaconBroadcastData, "RecvBeaconBroadcastData"}, | 397 | {0x000F0404, RecvBeaconBroadcastData, "RecvBeaconBroadcastData"}, |
| 133 | {0x00100042, nullptr, "SetApplicationData"}, | 398 | {0x00100042, SetApplicationData, "SetApplicationData"}, |
| 134 | {0x00110040, nullptr, "GetApplicationData"}, | 399 | {0x00110040, nullptr, "GetApplicationData"}, |
| 135 | {0x00120100, nullptr, "Bind"}, | 400 | {0x00120100, Bind, "Bind"}, |
| 136 | {0x00130040, nullptr, "Unbind"}, | 401 | {0x00130040, nullptr, "Unbind"}, |
| 137 | {0x001400C0, nullptr, "PullPacket"}, | 402 | {0x001400C0, nullptr, "PullPacket"}, |
| 138 | {0x00150080, nullptr, "SetMaxSendDelay"}, | 403 | {0x00150080, nullptr, "SetMaxSendDelay"}, |
| 139 | {0x00170182, nullptr, "SendTo"}, | 404 | {0x00170182, nullptr, "SendTo"}, |
| 140 | {0x001A0000, nullptr, "GetChannel"}, | 405 | {0x001A0000, GetChannel, "GetChannel"}, |
| 141 | {0x001B0302, InitializeWithVersion, "InitializeWithVersion"}, | 406 | {0x001B0302, InitializeWithVersion, "InitializeWithVersion"}, |
| 142 | {0x001D0044, nullptr, "BeginHostingNetwork"}, | 407 | {0x001D0044, BeginHostingNetwork, "BeginHostingNetwork"}, |
| 143 | {0x001E0084, nullptr, "ConnectToNetwork"}, | 408 | {0x001E0084, nullptr, "ConnectToNetwork"}, |
| 144 | {0x001F0006, nullptr, "DecryptBeaconData"}, | 409 | {0x001F0006, nullptr, "DecryptBeaconData"}, |
| 145 | {0x00200040, nullptr, "Flush"}, | 410 | {0x00200040, nullptr, "Flush"}, |
| @@ -148,13 +413,25 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 148 | }; | 413 | }; |
| 149 | 414 | ||
| 150 | NWM_UDS::NWM_UDS() { | 415 | NWM_UDS::NWM_UDS() { |
| 151 | uds_handle_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "NWM::uds_handle_event"); | 416 | connection_status_event = |
| 417 | Kernel::Event::Create(Kernel::ResetType::OneShot, "NWM::connection_status_event"); | ||
| 152 | 418 | ||
| 153 | Register(FunctionTable); | 419 | Register(FunctionTable); |
| 420 | |||
| 421 | beacon_broadcast_event = | ||
| 422 | CoreTiming::RegisterEvent("UDS::BeaconBroadcastCallback", BeaconBroadcastCallback); | ||
| 154 | } | 423 | } |
| 155 | 424 | ||
| 156 | NWM_UDS::~NWM_UDS() { | 425 | NWM_UDS::~NWM_UDS() { |
| 157 | uds_handle_event = nullptr; | 426 | network_info = {}; |
| 427 | bind_node_events.clear(); | ||
| 428 | connection_status_event = nullptr; | ||
| 429 | recv_buffer_memory = nullptr; | ||
| 430 | |||
| 431 | connection_status = {}; | ||
| 432 | connection_status.status = static_cast<u32>(NetworkStatus::NotConnected); | ||
| 433 | |||
| 434 | CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0); | ||
| 158 | } | 435 | } |
| 159 | 436 | ||
| 160 | } // namespace NWM | 437 | } // namespace NWM |
diff --git a/src/core/hle/service/nwm/nwm_uds.h b/src/core/hle/service/nwm/nwm_uds.h index 55db748f6..65349f9fd 100644 --- a/src/core/hle/service/nwm/nwm_uds.h +++ b/src/core/hle/service/nwm/nwm_uds.h | |||
| @@ -4,6 +4,10 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 8 | #include <cstddef> | ||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "common/swap.h" | ||
| 7 | #include "core/hle/service/service.h" | 11 | #include "core/hle/service/service.h" |
| 8 | 12 | ||
| 9 | // Local-WLAN service | 13 | // Local-WLAN service |
| @@ -11,6 +15,68 @@ | |||
| 11 | namespace Service { | 15 | namespace Service { |
| 12 | namespace NWM { | 16 | namespace NWM { |
| 13 | 17 | ||
| 18 | const size_t ApplicationDataSize = 0xC8; | ||
| 19 | const u8 DefaultNetworkChannel = 11; | ||
| 20 | |||
| 21 | // Number of milliseconds in a TU. | ||
| 22 | const double MillisecondsPerTU = 1.024; | ||
| 23 | // Interval measured in TU, the default value is 100TU = 102.4ms | ||
| 24 | const u16 DefaultBeaconInterval = 100; | ||
| 25 | |||
| 26 | struct NodeInfo { | ||
| 27 | u64_le friend_code_seed; | ||
| 28 | std::array<u16_le, 10> username; | ||
| 29 | INSERT_PADDING_BYTES(4); | ||
| 30 | u16_le network_node_id; | ||
| 31 | INSERT_PADDING_BYTES(6); | ||
| 32 | }; | ||
| 33 | |||
| 34 | static_assert(sizeof(NodeInfo) == 40, "NodeInfo has incorrect size."); | ||
| 35 | |||
| 36 | enum class NetworkStatus { | ||
| 37 | NotConnected = 3, | ||
| 38 | ConnectedAsHost = 6, | ||
| 39 | ConnectedAsClient = 9, | ||
| 40 | ConnectedAsSpectator = 10, | ||
| 41 | }; | ||
| 42 | |||
| 43 | struct ConnectionStatus { | ||
| 44 | u32_le status; | ||
| 45 | INSERT_PADDING_WORDS(1); | ||
| 46 | u16_le network_node_id; | ||
| 47 | INSERT_PADDING_BYTES(2); | ||
| 48 | INSERT_PADDING_BYTES(32); | ||
| 49 | u8 total_nodes; | ||
| 50 | u8 max_nodes; | ||
| 51 | u16_le node_bitmask; | ||
| 52 | }; | ||
| 53 | |||
| 54 | static_assert(sizeof(ConnectionStatus) == 0x30, "ConnectionStatus has incorrect size."); | ||
| 55 | |||
| 56 | struct NetworkInfo { | ||
| 57 | std::array<u8, 6> host_mac_address; | ||
| 58 | u8 channel; | ||
| 59 | INSERT_PADDING_BYTES(1); | ||
| 60 | u8 initialized; | ||
| 61 | INSERT_PADDING_BYTES(3); | ||
| 62 | std::array<u8, 3> oui_value; | ||
| 63 | u8 oui_type; | ||
| 64 | // This field is received as BigEndian from the game. | ||
| 65 | u32_be wlan_comm_id; | ||
| 66 | u8 id; | ||
| 67 | INSERT_PADDING_BYTES(1); | ||
| 68 | u16_be attributes; | ||
| 69 | u32_be network_id; | ||
| 70 | u8 total_nodes; | ||
| 71 | u8 max_nodes; | ||
| 72 | INSERT_PADDING_BYTES(2); | ||
| 73 | INSERT_PADDING_BYTES(0x1F); | ||
| 74 | u8 application_data_size; | ||
| 75 | std::array<u8, ApplicationDataSize> application_data; | ||
| 76 | }; | ||
| 77 | |||
| 78 | static_assert(sizeof(NetworkInfo) == 0x108, "NetworkInfo has incorrect size."); | ||
| 79 | |||
| 14 | class NWM_UDS final : public Interface { | 80 | class NWM_UDS final : public Interface { |
| 15 | public: | 81 | public: |
| 16 | NWM_UDS(); | 82 | NWM_UDS(); |