From 29d6e050445df9d5c78faaf02e0ea5024a8097b8 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Thu, 8 Mar 2018 15:59:44 +0100 Subject: [PATCH 1/3] Let connected clients handle the eapol packet --- src/core/hle/service/nwm/nwm_uds.cpp | 33 ++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index ecc2ed966..b5cf6e192 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -239,19 +239,18 @@ static void HandleEAPoLPacket(const Network::WifiPacket& packet) { GenerateEAPoLLogoffFrame(packet.transmitter_address, node.network_node_id, node_info, network_info.max_nodes, network_info.total_nodes); // TODO(Subv): Encrypt the packet. - eapol_logoff.destination_address = packet.transmitter_address; + + // On a 3ds the eapol packet is only sent to packet.transmitter_address + // while a packet containing the node information is broadcasted + // For now we will bradcast the eapol packet instead + eapol_logoff.destination_address = Network::BroadcastMac; eapol_logoff.type = WifiPacket::PacketType::Data; SendPacket(eapol_logoff); // TODO(B3N30): Broadcast updated node list // The 3ds does this presumably to support spectators. connection_status_event->Signal(); - } else { - if (connection_status.status != static_cast(NetworkStatus::Connecting)) { - LOG_DEBUG(Service_NWM, "Connection sequence aborted, because connection status is %u", - connection_status.status); - return; - } + } else if (connection_status.status == static_cast(NetworkStatus::Connecting)) { auto logoff = ParseEAPoLLogoffFrame(packet.data); network_info.host_mac_address = packet.transmitter_address; @@ -279,6 +278,26 @@ static void HandleEAPoLPacket(const Network::WifiPacket& packet) { // otherwise it might cause deadlocks connection_status_event->Signal(); connection_event->Signal(); + } else if (connection_status.status == static_cast(NetworkStatus::ConnectedAsClient)) { + // On a 3ds this packet wouldn't be addressed to already connected clients + // We use this information because in the current implementation the host + // isn't broadcsting the node information + auto logoff = ParseEAPoLLogoffFrame(packet.data); + + network_info.total_nodes = logoff.connected_nodes; + connection_status.total_nodes = logoff.connected_nodes; + + node_info.clear(); + node_info.reserve(network_info.max_nodes); + for (size_t index = 0; index < logoff.connected_nodes; ++index) { + if (!(connection_status.node_bitmask & 1 << index)) { + connection_status.changed_nodes |= 1 << index; + } + connection_status.nodes[index] = logoff.nodes[index].network_node_id; + connection_status.node_bitmask |= 1 << index; + node_info.emplace_back(DeserializeNodeInfo(logoff.nodes[index])); + } + connection_status_event->Signal(); } } From 2d72b2be8b9a05a707101a8b33a4cc72bfc9c12e Mon Sep 17 00:00:00 2001 From: B3n30 Date: Thu, 5 Apr 2018 14:43:21 +0200 Subject: [PATCH 2/3] fix Subvs suggestions --- src/core/hle/service/nwm/nwm_uds.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index b5cf6e192..8c5c039b5 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -240,9 +240,11 @@ static void HandleEAPoLPacket(const Network::WifiPacket& packet) { network_info.max_nodes, network_info.total_nodes); // TODO(Subv): Encrypt the packet. + //TODO(B3N30): send the eapol packet just to the new client and implement a proper + // broadcast packet for all other clients // On a 3ds the eapol packet is only sent to packet.transmitter_address // while a packet containing the node information is broadcasted - // For now we will bradcast the eapol packet instead + // For now we will broadcast the eapol packet instead eapol_logoff.destination_address = Network::BroadcastMac; eapol_logoff.type = WifiPacket::PacketType::Data; @@ -281,7 +283,7 @@ static void HandleEAPoLPacket(const Network::WifiPacket& packet) { } else if (connection_status.status == static_cast(NetworkStatus::ConnectedAsClient)) { // On a 3ds this packet wouldn't be addressed to already connected clients // We use this information because in the current implementation the host - // isn't broadcsting the node information + // isn't broadcasting the node information auto logoff = ParseEAPoLLogoffFrame(packet.data); network_info.total_nodes = logoff.connected_nodes; @@ -290,7 +292,7 @@ static void HandleEAPoLPacket(const Network::WifiPacket& packet) { node_info.clear(); node_info.reserve(network_info.max_nodes); for (size_t index = 0; index < logoff.connected_nodes; ++index) { - if (!(connection_status.node_bitmask & 1 << index)) { + if ((connection_status.node_bitmask & (1 << index)) == 0) { connection_status.changed_nodes |= 1 << index; } connection_status.nodes[index] = logoff.nodes[index].network_node_id; From f64f118e3b0372e0f0c159e88aecda2df7e916e0 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Thu, 5 Apr 2018 14:57:35 +0200 Subject: [PATCH 3/3] fix Subvs suggestions --- src/core/hle/service/nwm/nwm_uds.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 8c5c039b5..be49ee8b4 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -240,7 +240,7 @@ static void HandleEAPoLPacket(const Network::WifiPacket& packet) { network_info.max_nodes, network_info.total_nodes); // TODO(Subv): Encrypt the packet. - //TODO(B3N30): send the eapol packet just to the new client and implement a proper + // TODO(B3N30): send the eapol packet just to the new client and implement a proper // broadcast packet for all other clients // On a 3ds the eapol packet is only sent to packet.transmitter_address // while a packet containing the node information is broadcasted