From 8fc9330a1d198834afa406a0c5ad41afecbd6d70 Mon Sep 17 00:00:00 2001 From: Aaron Angert Date: Sun, 26 Jan 2020 19:25:48 -0600 Subject: [PATCH 1/4] don't check for ZCM2 pin on raspberry pi --- src/platform/psmove_port_linux.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/platform/psmove_port_linux.cpp b/src/platform/psmove_port_linux.cpp index a6e29990..247fdc69 100644 --- a/src/platform/psmove_port_linux.cpp +++ b/src/platform/psmove_port_linux.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include @@ -772,9 +773,13 @@ psmove_port_register_psmove(const char *addr, const char *host, enum PSMove_Mode return PSMove_False; } + struct utsname uts; + uname(&uts); + // start agent for automatically entering the PIN code if the ZCM2 requests // it (only required once, during initial setup) - if (model == Model_ZCM2) { + // note the ZCM2 controller does not request for a pin on the pi + if (model == Model_ZCM2 && strcmp(uts.nodename , "raspberrypi") != 0) { bluetoothd.force_restart(); run_pin_agent(); } From b6012cf8224b0612980efb043032d8961dd33847 Mon Sep 17 00:00:00 2001 From: Aaron Angert Date: Tue, 24 Mar 2020 01:39:41 -0500 Subject: [PATCH 2/4] changed checking hostname to checking secure simple pairing --- src/platform/psmove_port_linux.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/platform/psmove_port_linux.cpp b/src/platform/psmove_port_linux.cpp index 247fdc69..549c84e9 100644 --- a/src/platform/psmove_port_linux.cpp +++ b/src/platform/psmove_port_linux.cpp @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include @@ -772,16 +772,32 @@ psmove_port_register_psmove(const char *addr, const char *host, enum PSMove_Mode if (!linux_bluez5_update_file_content(bluetoothd, cache_dir + "/" + controller_addr, BLUEZ5_CACHE_ENTRY)) { return PSMove_False; } - - struct utsname uts; - uname(&uts); + // start agent for automatically entering the PIN code if the ZCM2 requests // it (only required once, during initial setup) - // note the ZCM2 controller does not request for a pin on the pi - if (model == Model_ZCM2 && strcmp(uts.nodename , "raspberrypi") != 0) { + if (model == Model_ZCM2){ bluetoothd.force_restart(); - run_pin_agent(); + + //Run hciconfig to see if secure simple pairing is enabled + std::string command("hciconfig hci0 sspmode 2>&1"); + std::array buffer; + std::string result; + + FILE* pipe = popen(command.c_str(), "r"); + if (!pipe) + { + printf("Couldn't start command."); + } + while (fgets(buffer.data(), 128, pipe) != NULL) { + result += buffer.data(); + } + auto returnCode = pclose(pipe); + + //If it is not enabled, then run the pin agent to send 0000 + if(result.find("Enabled") == std::string::npos){ + run_pin_agent(); + } } return PSMove_True; From c389e130e91a52eb5ae9ecb3580442e36e81dc03 Mon Sep 17 00:00:00 2001 From: Aaron Angert Date: Tue, 24 Mar 2020 03:25:22 -0500 Subject: [PATCH 3/4] changed from running the command with popen to using hci_lib calls --- src/platform/psmove_port_linux.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/platform/psmove_port_linux.cpp b/src/platform/psmove_port_linux.cpp index 549c84e9..b39af034 100644 --- a/src/platform/psmove_port_linux.cpp +++ b/src/platform/psmove_port_linux.cpp @@ -779,23 +779,13 @@ psmove_port_register_psmove(const char *addr, const char *host, enum PSMove_Mode if (model == Model_ZCM2){ bluetoothd.force_restart(); - //Run hciconfig to see if secure simple pairing is enabled - std::string command("hciconfig hci0 sspmode 2>&1"); - std::array buffer; - std::string result; - - FILE* pipe = popen(command.c_str(), "r"); - if (!pipe) - { - printf("Couldn't start command."); - } - while (fgets(buffer.data(), 128, pipe) != NULL) { - result += buffer.data(); - } - auto returnCode = pclose(pipe); + uint8_t ssp = 0; + int dd = hci_open_dev(hci_devid(host)); + hci_read_simple_pairing_mode(dd, &ssp, -1); + hci_close_dev(dd); //If it is not enabled, then run the pin agent to send 0000 - if(result.find("Enabled") == std::string::npos){ + if(ssp == 0){ run_pin_agent(); } } From fdf6868224d6f297757c2e77f876d9194242b61d Mon Sep 17 00:00:00 2001 From: Aaron Angert Date: Tue, 24 Mar 2020 03:28:56 -0500 Subject: [PATCH 4/4] removed array include, added comments --- src/platform/psmove_port_linux.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/platform/psmove_port_linux.cpp b/src/platform/psmove_port_linux.cpp index b39af034..6a4d643a 100644 --- a/src/platform/psmove_port_linux.cpp +++ b/src/platform/psmove_port_linux.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include @@ -772,13 +771,13 @@ psmove_port_register_psmove(const char *addr, const char *host, enum PSMove_Mode if (!linux_bluez5_update_file_content(bluetoothd, cache_dir + "/" + controller_addr, BLUEZ5_CACHE_ENTRY)) { return PSMove_False; } - // start agent for automatically entering the PIN code if the ZCM2 requests // it (only required once, during initial setup) if (model == Model_ZCM2){ bluetoothd.force_restart(); + //check if secure simple pairing is enabled in the host adapter uint8_t ssp = 0; int dd = hci_open_dev(hci_devid(host)); hci_read_simple_pairing_mode(dd, &ssp, -1);