From 10401afd17861fa9e4892dff3a916875b5ddb4cc Mon Sep 17 00:00:00 2001 From: nekomona Date: Wed, 12 Jul 2023 20:08:05 +0800 Subject: [PATCH] Fix IP check and provision check --- src/debug.h | 2 +- src/logging/RemoteLogHelper.cpp | 2 +- src/network/connection.cpp | 3 +++ src/network/connection.h | 1 + src/network/remotecmd.cpp | 7 +++++-- src/network/wifihandler.cpp | 1 - 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/debug.h b/src/debug.h index 91ea7b4a2..334d843ad 100644 --- a/src/debug.h +++ b/src/debug.h @@ -48,7 +48,7 @@ #define serialDebug false // Set to true to get Serial output for debugging #define serialBaudRate 115200 #define USE_REMOTE_COMMAND true -#define ALLOW_REMOTE_WIFI_PROV false +#define ALLOW_REMOTE_WIFI_PROV true #define LED_INTERVAL_STANDBY 10000 #define PRINT_STATE_EVERY_MS 60000 diff --git a/src/logging/RemoteLogHelper.cpp b/src/logging/RemoteLogHelper.cpp index e2eecea12..3ed48ace8 100644 --- a/src/logging/RemoteLogHelper.cpp +++ b/src/logging/RemoteLogHelper.cpp @@ -4,7 +4,7 @@ namespace SlimeVR { namespace Logging { -bool getRemoteCmdConncted() { return networkRemoteCmd.isConnected(); } +bool getRemoteCmdConncted() { return networkRemoteCmd.isConnected() && networkConnection.isConnected(); } Stream& getRemoteCmdStream() { return networkRemoteCmd.getStream(); } } // namespace Logging diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 9bd2b694a..9d3005aef 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -478,6 +478,9 @@ void Connection::searchForServer() { statusManager.setStatus(SlimeVR::Status::SERVER_CONNECTING, false); ledManager.off(); +#if USE_REMOTE_COMMAND + networkRemoteCmd.reset(); +#endif m_Logger.debug( "Handshake successful, server is %s:%d", diff --git a/src/network/connection.h b/src/network/connection.h index 2f12cfb3e..9ff7f61ad 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -30,6 +30,7 @@ #include "quat.h" #include "sensors/sensor.h" #include "wifihandler.h" +#include "remotecmd.h" namespace SlimeVR { namespace Network { diff --git a/src/network/remotecmd.cpp b/src/network/remotecmd.cpp index eb38c9108..de8118f5f 100644 --- a/src/network/remotecmd.cpp +++ b/src/network/remotecmd.cpp @@ -18,15 +18,18 @@ void RemoteCmd::update() { rcmdServer.accept().stop(); r_Logger.info("Remote command multi-connection dropped"); } else { + IPAddress rejectedIP; rcmdClient = rcmdServer.accept(); if (networkConnection.isConnected()) { // Only accept if rcmdClient have the same remote IP as udpmanager - if (rcmdClient.remoteIP() = networkConnection.m_ServerHost) { + if (rcmdClient.remoteIP() != networkConnection.m_ServerHost) { + rejectedIP = rcmdClient.remoteIP(); rcmdClient.stop(); } } #if !ALLOW_REMOTE_WIFI_PROV else { + rejectedIP = rcmdClient.remoteIP(); rcmdClient.stop(); } #endif @@ -38,7 +41,7 @@ void RemoteCmd::update() { } else { r_Logger.info( "Remote command from %s dropped", - rcmdClient.remoteIP().toString().c_str() + rejectedIP.toString().c_str() ); } } diff --git a/src/network/wifihandler.cpp b/src/network/wifihandler.cpp index 62422d1c8..e701a6afc 100644 --- a/src/network/wifihandler.cpp +++ b/src/network/wifihandler.cpp @@ -121,7 +121,6 @@ void WiFiNetwork::setUp() { void onConnected() { WiFiNetwork::stopProvisioning(); statusManager.setStatus(SlimeVR::Status::WIFI_CONNECTING, false); - networkRemoteCmd.reset(); isWifiConnected = true; hadWifi = true; wifiHandlerLogger.info("Connected successfully to SSID '%s', ip address %s", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());