From 60d8cb4c6fe583fe3660630f69944975901a2697 Mon Sep 17 00:00:00 2001 From: Kevin Schoedel Date: Fri, 31 Jul 2020 16:34:06 -0400 Subject: [PATCH] Allow chip-tool echo-ble to work along with credential passing Prior to #1898, received bluetooth messages were echoed back to the sender, and this facility is used by the command-line `chip-tool echo-ble`. To restore that, this change adopts a stricter format for WiFi credentials and treats anything else as an echo request. (This too is temporary code, pending an actual rendezvous implementation.) --- .../server/esp32/main/RendezvousSession.cpp | 25 ++++++++++++++++--- .../CHIPTool/QRCode/QRCodeViewController.m | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/examples/wifi-echo/server/esp32/main/RendezvousSession.cpp b/examples/wifi-echo/server/esp32/main/RendezvousSession.cpp index 4c26fd09383ba9..e06364c6268824 100644 --- a/examples/wifi-echo/server/esp32/main/RendezvousSession.cpp +++ b/examples/wifi-echo/server/esp32/main/RendezvousSession.cpp @@ -81,8 +81,25 @@ void RendezvousSession::HandleMessageReceived(Ble::BLEEndPoint * endPoint, Packe ChipLogProgress(Ble, "RendezvousSession: Receive message: %s", msg); - char * ssid = strtok(msg, ":"); - char * key = strtok(NULL, ":"); - ChipLogProgress(Ble, "RendezvousSession: SSID: %s, key: %s", ssid, key); - SetWiFiStationProvisioning(ssid, key); + if ((bufferLen > 3) && (msg[0] == msg[1]) && (msg[0] == msg[bufferLen - 1])) + { + // WiFi credentials, of the form ‘::SSID:password:’, where ‘:’ can be any single ASCII character. + msg[1] = 0; + char * ssid = strtok(&msg[2], msg); + char * key = strtok(NULL, msg); + if (ssid && key) + { + ChipLogProgress(Ble, "RendezvousSession: SSID: %s, key: %s", ssid, key); + SetWiFiStationProvisioning(ssid, key); + } + else + { + ChipLogError(Ble, "RendezvousSession: SSID: %p, key: %p", ssid, key); + } + } + else + { + // Echo. + mEndPoint->Send(buffer); + } } diff --git a/src/darwin/CHIPTool/CHIPTool/QRCode/QRCodeViewController.m b/src/darwin/CHIPTool/CHIPTool/QRCode/QRCodeViewController.m index 63d752301d5b71..53b6b11df88645 100644 --- a/src/darwin/CHIPTool/CHIPTool/QRCode/QRCodeViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/QRCode/QRCodeViewController.m @@ -260,7 +260,7 @@ - (void)retrieveAndSendWifiCredentials - (void)sendWifiCredentialsWithSSID:(NSString *)ssid password:(NSString *)password { - NSString * msg = [NSString stringWithFormat:@"%@:%@", ssid, password]; + NSString * msg = [NSString stringWithFormat:@"::%@:%@:", ssid, password]; NSError * error; BOOL didSend = [self.chipController sendMessage:[msg dataUsingEncoding:NSUTF8StringEncoding] error:&error]; if (!didSend) {