diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/nwm/nwm_uds.cpp | 55 | ||||
| -rw-r--r-- | src/core/hle/service/nwm/nwm_uds.h | 5 |
2 files changed, 58 insertions, 2 deletions
diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index b69c90ef1..da7c2bb0d 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <vector> | 7 | #include <vector> |
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "core/core_timing.h" | ||
| 10 | #include "core/hle/kernel/event.h" | 11 | #include "core/hle/kernel/event.h" |
| 11 | #include "core/hle/kernel/shared_memory.h" | 12 | #include "core/hle/kernel/shared_memory.h" |
| 12 | #include "core/hle/result.h" | 13 | #include "core/hle/result.h" |
| @@ -41,6 +42,9 @@ static u8 network_channel = DefaultNetworkChannel; | |||
| 41 | // Information about the network that we're currently connected to. | 42 | // Information about the network that we're currently connected to. |
| 42 | static NetworkInfo network_info; | 43 | static NetworkInfo network_info; |
| 43 | 44 | ||
| 45 | // Event that will generate and send the 802.11 beacon frames. | ||
| 46 | static int beacon_broadcast_event; | ||
| 47 | |||
| 44 | /** | 48 | /** |
| 45 | * NWM_UDS::Shutdown service function | 49 | * NWM_UDS::Shutdown service function |
| 46 | * Inputs: | 50 | * Inputs: |
| @@ -260,7 +264,9 @@ static void BeginHostingNetwork(Interface* self) { | |||
| 260 | 264 | ||
| 261 | connection_status_event->Signal(); | 265 | connection_status_event->Signal(); |
| 262 | 266 | ||
| 263 | // TODO(Subv): Start broadcasting the network, send a beacon frame every 102.4ms. | 267 | // Start broadcasting the network, send a beacon frame every 102.4ms. |
| 268 | CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU), | ||
| 269 | beacon_broadcast_event, 0); | ||
| 264 | 270 | ||
| 265 | LOG_WARNING(Service_NWM, | 271 | LOG_WARNING(Service_NWM, |
| 266 | "An UDS network has been created, but broadcasting it is unimplemented."); | 272 | "An UDS network has been created, but broadcasting it is unimplemented."); |
| @@ -270,6 +276,33 @@ static void BeginHostingNetwork(Interface* self) { | |||
| 270 | } | 276 | } |
| 271 | 277 | ||
| 272 | /** | 278 | /** |
| 279 | * NWM_UDS::DestroyNetwork service function. | ||
| 280 | * Closes the network that we're currently hosting. | ||
| 281 | * Inputs: | ||
| 282 | * 0 : Command header. | ||
| 283 | * Outputs: | ||
| 284 | * 0 : Return header | ||
| 285 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 286 | */ | ||
| 287 | static void DestroyNetwork(Interface* self) { | ||
| 288 | IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x08, 0, 0); | ||
| 289 | |||
| 290 | // TODO(Subv): Find out what happens if this is called while | ||
| 291 | // no network is being hosted. | ||
| 292 | |||
| 293 | // Unschedule the beacon broadcast event. | ||
| 294 | CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0); | ||
| 295 | |||
| 296 | connection_status.status = static_cast<u8>(NetworkStatus::NotConnected); | ||
| 297 | |||
| 298 | IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); | ||
| 299 | |||
| 300 | rb.Push(RESULT_SUCCESS); | ||
| 301 | |||
| 302 | LOG_WARNING(Service_NWM, "called"); | ||
| 303 | } | ||
| 304 | |||
| 305 | /** | ||
| 273 | * NWM_UDS::GetChannel service function. | 306 | * NWM_UDS::GetChannel service function. |
| 274 | * Returns the WiFi channel in which the network we're connected to is transmitting. | 307 | * Returns the WiFi channel in which the network we're connected to is transmitting. |
| 275 | * Inputs: | 308 | * Inputs: |
| @@ -331,6 +364,19 @@ static void SetApplicationData(Interface* self) { | |||
| 331 | rb.Push(RESULT_SUCCESS); | 364 | rb.Push(RESULT_SUCCESS); |
| 332 | } | 365 | } |
| 333 | 366 | ||
| 367 | // Sends a 802.11 beacon frame with information about the current network. | ||
| 368 | static void BeaconBroadcastCallback(u64 userdata, int cycles_late) { | ||
| 369 | // Don't do anything if we're not actually hosting a network | ||
| 370 | if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) | ||
| 371 | return; | ||
| 372 | |||
| 373 | // TODO(Subv): Actually generate the beacon and send it. | ||
| 374 | |||
| 375 | // Start broadcasting the network, send a beacon frame every 102.4ms. | ||
| 376 | CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU) - cycles_late, | ||
| 377 | beacon_broadcast_event, 0); | ||
| 378 | } | ||
| 379 | |||
| 334 | const Interface::FunctionInfo FunctionTable[] = { | 380 | const Interface::FunctionInfo FunctionTable[] = { |
| 335 | {0x00010442, nullptr, "Initialize (deprecated)"}, | 381 | {0x00010442, nullptr, "Initialize (deprecated)"}, |
| 336 | {0x00020000, nullptr, "Scrap"}, | 382 | {0x00020000, nullptr, "Scrap"}, |
| @@ -339,7 +385,7 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 339 | {0x00050040, nullptr, "EjectClient"}, | 385 | {0x00050040, nullptr, "EjectClient"}, |
| 340 | {0x00060000, nullptr, "EjectSpectator"}, | 386 | {0x00060000, nullptr, "EjectSpectator"}, |
| 341 | {0x00070080, nullptr, "UpdateNetworkAttribute"}, | 387 | {0x00070080, nullptr, "UpdateNetworkAttribute"}, |
| 342 | {0x00080000, nullptr, "DestroyNetwork"}, | 388 | {0x00080000, DestroyNetwork, "DestroyNetwork"}, |
| 343 | {0x00090442, nullptr, "ConnectNetwork (deprecated)"}, | 389 | {0x00090442, nullptr, "ConnectNetwork (deprecated)"}, |
| 344 | {0x000A0000, nullptr, "DisconnectNetwork"}, | 390 | {0x000A0000, nullptr, "DisconnectNetwork"}, |
| 345 | {0x000B0000, GetConnectionStatus, "GetConnectionStatus"}, | 391 | {0x000B0000, GetConnectionStatus, "GetConnectionStatus"}, |
| @@ -368,6 +414,9 @@ NWM_UDS::NWM_UDS() { | |||
| 368 | Kernel::Event::Create(Kernel::ResetType::OneShot, "NWM::connection_status_event"); | 414 | Kernel::Event::Create(Kernel::ResetType::OneShot, "NWM::connection_status_event"); |
| 369 | 415 | ||
| 370 | Register(FunctionTable); | 416 | Register(FunctionTable); |
| 417 | |||
| 418 | beacon_broadcast_event = | ||
| 419 | CoreTiming::RegisterEvent("UDS::BeaconBroadcastCallback", BeaconBroadcastCallback); | ||
| 371 | } | 420 | } |
| 372 | 421 | ||
| 373 | NWM_UDS::~NWM_UDS() { | 422 | NWM_UDS::~NWM_UDS() { |
| @@ -378,6 +427,8 @@ NWM_UDS::~NWM_UDS() { | |||
| 378 | 427 | ||
| 379 | connection_status = {}; | 428 | connection_status = {}; |
| 380 | connection_status.status = static_cast<u32>(NetworkStatus::NotConnected); | 429 | connection_status.status = static_cast<u32>(NetworkStatus::NotConnected); |
| 430 | |||
| 431 | CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0); | ||
| 381 | } | 432 | } |
| 382 | 433 | ||
| 383 | } // namespace NWM | 434 | } // namespace NWM |
diff --git a/src/core/hle/service/nwm/nwm_uds.h b/src/core/hle/service/nwm/nwm_uds.h index 3dfc32de8..65349f9fd 100644 --- a/src/core/hle/service/nwm/nwm_uds.h +++ b/src/core/hle/service/nwm/nwm_uds.h | |||
| @@ -18,6 +18,11 @@ namespace NWM { | |||
| 18 | const size_t ApplicationDataSize = 0xC8; | 18 | const size_t ApplicationDataSize = 0xC8; |
| 19 | const u8 DefaultNetworkChannel = 11; | 19 | const u8 DefaultNetworkChannel = 11; |
| 20 | 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 | |||
| 21 | struct NodeInfo { | 26 | struct NodeInfo { |
| 22 | u64_le friend_code_seed; | 27 | u64_le friend_code_seed; |
| 23 | std::array<u16_le, 10> username; | 28 | std::array<u16_le, 10> username; |