diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/nwm/nwm_uds.cpp | 98 |
1 files changed, 97 insertions, 1 deletions
diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 084113188..6c4600f25 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp | |||
| @@ -423,6 +423,102 @@ static void SetApplicationData(Interface* self) { | |||
| 423 | rb.Push(RESULT_SUCCESS); | 423 | rb.Push(RESULT_SUCCESS); |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | /** | ||
| 427 | * NWM_UDS::DecryptBeaconData service function. | ||
| 428 | * Decrypts the encrypted data tags contained in the 802.11 beacons. | ||
| 429 | * Inputs: | ||
| 430 | * 1 : Input network struct buffer descriptor. | ||
| 431 | * 2 : Input network struct buffer ptr. | ||
| 432 | * 3 : Input tag0 encrypted buffer descriptor. | ||
| 433 | * 4 : Input tag0 encrypted buffer ptr. | ||
| 434 | * 5 : Input tag1 encrypted buffer descriptor. | ||
| 435 | * 6 : Input tag1 encrypted buffer ptr. | ||
| 436 | * 64 : Output buffer descriptor. | ||
| 437 | * 65 : Output buffer ptr. | ||
| 438 | * Outputs: | ||
| 439 | * 0 : Return header | ||
| 440 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 441 | */ | ||
| 442 | static void DecryptBeaconData(Interface* self) { | ||
| 443 | IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1F, 0, 6); | ||
| 444 | |||
| 445 | size_t desc_size; | ||
| 446 | const VAddr network_struct_addr = rp.PopStaticBuffer(&desc_size); | ||
| 447 | ASSERT(desc_size == sizeof(NetworkInfo)); | ||
| 448 | |||
| 449 | size_t data0_size; | ||
| 450 | const VAddr encrypted_data0_addr = rp.PopStaticBuffer(&data0_size); | ||
| 451 | |||
| 452 | size_t data1_size; | ||
| 453 | const VAddr encrypted_data1_addr = rp.PopStaticBuffer(&data1_size); | ||
| 454 | |||
| 455 | size_t output_buffer_size; | ||
| 456 | const VAddr output_buffer_addr = rp.PeekStaticBuffer(0, &output_buffer_size); | ||
| 457 | |||
| 458 | // This size is hardcoded in the 3DS UDS code. | ||
| 459 | ASSERT(output_buffer_size == sizeof(NodeInfo) * UDSMaxNodes); | ||
| 460 | |||
| 461 | LOG_WARNING(Service_NWM, "called in0=%08X in1=%08X out=%08X", encrypted_data0_addr, | ||
| 462 | encrypted_data1_addr, output_buffer_addr); | ||
| 463 | |||
| 464 | NetworkInfo net_info; | ||
| 465 | Memory::ReadBlock(network_struct_addr, &net_info, sizeof(net_info)); | ||
| 466 | |||
| 467 | // Read the encrypted data. | ||
| 468 | // The first 4 bytes should be the OUI and the OUI Type of the tags. | ||
| 469 | std::array<u8, 3> oui; | ||
| 470 | Memory::ReadBlock(encrypted_data0_addr, oui.data(), oui.size()); | ||
| 471 | ASSERT_MSG(oui == NintendoOUI, "Unexpected OUI"); | ||
| 472 | Memory::ReadBlock(encrypted_data1_addr, oui.data(), oui.size()); | ||
| 473 | ASSERT_MSG(oui == NintendoOUI, "Unexpected OUI"); | ||
| 474 | |||
| 475 | ASSERT_MSG(Memory::Read8(encrypted_data0_addr + 3) == | ||
| 476 | static_cast<u8>(NintendoTagId::EncryptedData0), | ||
| 477 | "Unexpected tag id"); | ||
| 478 | ASSERT_MSG(Memory::Read8(encrypted_data1_addr + 3) == | ||
| 479 | static_cast<u8>(NintendoTagId::EncryptedData1), | ||
| 480 | "Unexpected tag id"); | ||
| 481 | |||
| 482 | std::vector<u8> beacon_data(data0_size + data1_size); | ||
| 483 | Memory::ReadBlock(encrypted_data0_addr + 4, beacon_data.data(), data0_size); | ||
| 484 | Memory::ReadBlock(encrypted_data1_addr + 4, beacon_data.data() + data0_size, data1_size); | ||
| 485 | |||
| 486 | // Decrypt the data | ||
| 487 | DecryptBeaconData(net_info, beacon_data); | ||
| 488 | |||
| 489 | // The beacon data header contains the MD5 hash of the data. | ||
| 490 | BeaconData beacon_header; | ||
| 491 | std::memcpy(&beacon_header, beacon_data.data(), sizeof(beacon_header)); | ||
| 492 | |||
| 493 | // TODO(Subv): Verify the MD5 hash of the data and return 0xE1211005 if invalid. | ||
| 494 | |||
| 495 | u8 num_nodes = net_info.max_nodes; | ||
| 496 | |||
| 497 | std::vector<NodeInfo> nodes; | ||
| 498 | |||
| 499 | for (int i = 0; i < num_nodes; ++i) { | ||
| 500 | BeaconNodeInfo info; | ||
| 501 | std::memcpy(&info, beacon_data.data() + sizeof(beacon_header) + i * sizeof(info), | ||
| 502 | sizeof(info)); | ||
| 503 | |||
| 504 | // Deserialize the node information. | ||
| 505 | NodeInfo node{}; | ||
| 506 | node.friend_code_seed = info.friend_code_seed; | ||
| 507 | node.network_node_id = info.network_node_id; | ||
| 508 | for (int i = 0; i < info.username.size(); ++i) | ||
| 509 | node.username[i] = info.username[i]; | ||
| 510 | |||
| 511 | nodes.push_back(node); | ||
| 512 | } | ||
| 513 | |||
| 514 | Memory::ZeroBlock(output_buffer_addr, sizeof(NodeInfo) * UDSMaxNodes); | ||
| 515 | Memory::WriteBlock(output_buffer_addr, nodes.data(), sizeof(NodeInfo) * nodes.size()); | ||
| 516 | |||
| 517 | IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); | ||
| 518 | rb.PushStaticBuffer(output_buffer_addr, output_buffer_size, 0); | ||
| 519 | rb.Push(RESULT_SUCCESS); | ||
| 520 | } | ||
| 521 | |||
| 426 | // Sends a 802.11 beacon frame with information about the current network. | 522 | // Sends a 802.11 beacon frame with information about the current network. |
| 427 | static void BeaconBroadcastCallback(u64 userdata, int cycles_late) { | 523 | static void BeaconBroadcastCallback(u64 userdata, int cycles_late) { |
| 428 | // Don't do anything if we're not actually hosting a network | 524 | // Don't do anything if we're not actually hosting a network |
| @@ -463,7 +559,7 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 463 | {0x001B0302, InitializeWithVersion, "InitializeWithVersion"}, | 559 | {0x001B0302, InitializeWithVersion, "InitializeWithVersion"}, |
| 464 | {0x001D0044, BeginHostingNetwork, "BeginHostingNetwork"}, | 560 | {0x001D0044, BeginHostingNetwork, "BeginHostingNetwork"}, |
| 465 | {0x001E0084, nullptr, "ConnectToNetwork"}, | 561 | {0x001E0084, nullptr, "ConnectToNetwork"}, |
| 466 | {0x001F0006, nullptr, "DecryptBeaconData"}, | 562 | {0x001F0006, DecryptBeaconData, "DecryptBeaconData"}, |
| 467 | {0x00200040, nullptr, "Flush"}, | 563 | {0x00200040, nullptr, "Flush"}, |
| 468 | {0x00210080, nullptr, "SetProbeResponseParam"}, | 564 | {0x00210080, nullptr, "SetProbeResponseParam"}, |
| 469 | {0x00220402, nullptr, "ScanOnConnection"}, | 565 | {0x00220402, nullptr, "ScanOnConnection"}, |