3
0
Fork 0
forked from suyu/suyu

Service/UDS: Schedule an event to broadcast the beacon frames every 102.4ms.

This commit is contained in:
Subv 2017-03-18 13:15:07 -05:00
parent 4243c1198f
commit 97f1e62b66
2 changed files with 58 additions and 2 deletions

View file

@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/core_timing.h"
#include "core/hle/kernel/event.h" #include "core/hle/kernel/event.h"
#include "core/hle/kernel/shared_memory.h" #include "core/hle/kernel/shared_memory.h"
#include "core/hle/result.h" #include "core/hle/result.h"
@ -41,6 +42,9 @@ static u8 network_channel = DefaultNetworkChannel;
// Information about the network that we're currently connected to. // Information about the network that we're currently connected to.
static NetworkInfo network_info; static NetworkInfo network_info;
// Event that will generate and send the 802.11 beacon frames.
static int beacon_broadcast_event;
/** /**
* NWM_UDS::Shutdown service function * NWM_UDS::Shutdown service function
* Inputs: * Inputs:
@ -260,7 +264,9 @@ static void BeginHostingNetwork(Interface* self) {
connection_status_event->Signal(); connection_status_event->Signal();
// TODO(Subv): Start broadcasting the network, send a beacon frame every 102.4ms. // Start broadcasting the network, send a beacon frame every 102.4ms.
CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU),
beacon_broadcast_event, 0);
LOG_WARNING(Service_NWM, LOG_WARNING(Service_NWM,
"An UDS network has been created, but broadcasting it is unimplemented."); "An UDS network has been created, but broadcasting it is unimplemented.");
@ -269,6 +275,33 @@ static void BeginHostingNetwork(Interface* self) {
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
} }
/**
* NWM_UDS::DestroyNetwork service function.
* Closes the network that we're currently hosting.
* Inputs:
* 0 : Command header.
* Outputs:
* 0 : Return header
* 1 : Result of function, 0 on success, otherwise error code
*/
static void DestroyNetwork(Interface* self) {
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x08, 0, 0);
// TODO(Subv): Find out what happens if this is called while
// no network is being hosted.
// Unschedule the beacon broadcast event.
CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0);
connection_status.status = static_cast<u8>(NetworkStatus::NotConnected);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_NWM, "called");
}
/** /**
* NWM_UDS::GetChannel service function. * NWM_UDS::GetChannel service function.
* Returns the WiFi channel in which the network we're connected to is transmitting. * Returns the WiFi channel in which the network we're connected to is transmitting.
@ -331,6 +364,19 @@ static void SetApplicationData(Interface* self) {
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
} }
// Sends a 802.11 beacon frame with information about the current network.
static void BeaconBroadcastCallback(u64 userdata, int cycles_late) {
// Don't do anything if we're not actually hosting a network
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost))
return;
// TODO(Subv): Actually generate the beacon and send it.
// Start broadcasting the network, send a beacon frame every 102.4ms.
CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU) - cycles_late,
beacon_broadcast_event, 0);
}
const Interface::FunctionInfo FunctionTable[] = { const Interface::FunctionInfo FunctionTable[] = {
{0x00010442, nullptr, "Initialize (deprecated)"}, {0x00010442, nullptr, "Initialize (deprecated)"},
{0x00020000, nullptr, "Scrap"}, {0x00020000, nullptr, "Scrap"},
@ -339,7 +385,7 @@ const Interface::FunctionInfo FunctionTable[] = {
{0x00050040, nullptr, "EjectClient"}, {0x00050040, nullptr, "EjectClient"},
{0x00060000, nullptr, "EjectSpectator"}, {0x00060000, nullptr, "EjectSpectator"},
{0x00070080, nullptr, "UpdateNetworkAttribute"}, {0x00070080, nullptr, "UpdateNetworkAttribute"},
{0x00080000, nullptr, "DestroyNetwork"}, {0x00080000, DestroyNetwork, "DestroyNetwork"},
{0x00090442, nullptr, "ConnectNetwork (deprecated)"}, {0x00090442, nullptr, "ConnectNetwork (deprecated)"},
{0x000A0000, nullptr, "DisconnectNetwork"}, {0x000A0000, nullptr, "DisconnectNetwork"},
{0x000B0000, GetConnectionStatus, "GetConnectionStatus"}, {0x000B0000, GetConnectionStatus, "GetConnectionStatus"},
@ -368,6 +414,9 @@ NWM_UDS::NWM_UDS() {
Kernel::Event::Create(Kernel::ResetType::OneShot, "NWM::connection_status_event"); Kernel::Event::Create(Kernel::ResetType::OneShot, "NWM::connection_status_event");
Register(FunctionTable); Register(FunctionTable);
beacon_broadcast_event =
CoreTiming::RegisterEvent("UDS::BeaconBroadcastCallback", BeaconBroadcastCallback);
} }
NWM_UDS::~NWM_UDS() { NWM_UDS::~NWM_UDS() {
@ -378,6 +427,8 @@ NWM_UDS::~NWM_UDS() {
connection_status = {}; connection_status = {};
connection_status.status = static_cast<u32>(NetworkStatus::NotConnected); connection_status.status = static_cast<u32>(NetworkStatus::NotConnected);
CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0);
} }
} // namespace NWM } // namespace NWM

View file

@ -18,6 +18,11 @@ namespace NWM {
const size_t ApplicationDataSize = 0xC8; const size_t ApplicationDataSize = 0xC8;
const u8 DefaultNetworkChannel = 11; const u8 DefaultNetworkChannel = 11;
// Number of milliseconds in a TU.
const double MillisecondsPerTU = 1.024;
// Interval measured in TU, the default value is 100TU = 102.4ms
const u16 DefaultBeaconInterval = 100;
struct NodeInfo { struct NodeInfo {
u64_le friend_code_seed; u64_le friend_code_seed;
std::array<u16_le, 10> username; std::array<u16_le, 10> username;