From a2da1c4a9a33471138919be3df4f16928a3a01ce Mon Sep 17 00:00:00 2001 From: unknown10777 <83267603+unknown10777@users.noreply.github.com> Date: Sun, 24 Dec 2023 22:18:31 +0800 Subject: [PATCH 1/4] fix usart btfactory not working for HC-04 --- client/src/cmdusart.c | 116 +++++++++++++++++++++++++++++++----------- 1 file changed, 87 insertions(+), 29 deletions(-) diff --git a/client/src/cmdusart.c b/client/src/cmdusart.c index 0d33ef374..84c9a35c2 100644 --- a/client/src/cmdusart.c +++ b/client/src/cmdusart.c @@ -148,6 +148,10 @@ static int CmdUsartConfig(const char *Cmd) { return set_usart_config(baudrate, parity); } +// module command not universal so specific commands needed if anyone DIY'd their own Blueshark. +bool isBluetoothExtensionHC04 = false; +bool isBluetoothExtensionHC05Blueshark = false; + static int usart_bt_testcomm(uint32_t baudrate, uint8_t parity) { int ret = set_usart_config(baudrate, parity); if (ret != PM3_SUCCESS) @@ -161,10 +165,26 @@ static int usart_bt_testcomm(uint32_t baudrate, uint8_t parity) { // 1000, such large timeout needed ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); - if (ret == PM3_SUCCESS) { + if (ret == PM3_SUCCESS) + { PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); - if (str_startswith((char *)data, "hc01.comV2.0") || str_startswith((char *)data, "BT SPP V3.0")) { + if (str_startswith((char *)data, "hc01.comV2.0") || + str_startswith((char *)data, "www.hc01.com") || + str_startswith((char *)data, "BT SPP V4.0")) + { PrintAndLogEx(SUCCESS, "Add-on " _GREEN_("found!")); + // if it fully match HC-04's attribute + if (str_startswith((char *)data, "www.hc01.com V2.5, 2022-04-26")) + { + isBluetoothExtensionHC04 = true; + PrintAndLogEx(INFO, "Bluetooth module identified as HC-04."); + } + + // if it fully match Blueshark HC-05's attribute + if (str_startswith((char *)data, "hc01.comV2.0")){ + isBluetoothExtensionHC05Blueshark = true; + PrintAndLogEx(INFO, "Bluetooth module identified as Blueshark HC-05."); + } return PM3_SUCCESS; } } @@ -236,7 +256,7 @@ static int CmdUsartBtFactory(const char *Cmd) { } if (!found) { - PrintAndLogEx(FAILED, "Sorry, add-on not found. Abort."); + PrintAndLogEx(FAILED, "Sorry, add-on not found. Abort. If you DIY'd your own, please report your model and manual to us."); return PM3_ESOFT; } @@ -246,13 +266,18 @@ static int CmdUsartBtFactory(const char *Cmd) { size_t len = 0; memset(data, 0, sizeof(data)); - string = "AT+NAMEPM3_RDV4.0"; + if (isBluetoothExtensionHC04 == true) { + string = "AT+NAME=PM3_RDV4.0"; + } else { + string = "AT+NAMEPM3_RDV4.0"; + } + PrintAndLogEx(SUCCESS, "TX (%3zu):%.*s", strlen(string), (int)strlen(string), string); int ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); if (ret == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); - if (strcmp((char *)data, "OKsetname") == 0) { + if (strstr((char *)data, "OK")) { PrintAndLogEx(SUCCESS, "Name set to " _GREEN_("PM3_RDV4.0")); } else { PrintAndLogEx(WARNING, "Unexpected response to AT+NAME: " _YELLOW_("%.*s"), (int)len, data); @@ -262,6 +287,8 @@ static int CmdUsartBtFactory(const char *Cmd) { return PM3_ESOFT; } + msleep(500); + memset(data, 0, sizeof(data)); len = 0; string = "AT+ROLE=S"; @@ -270,7 +297,7 @@ static int CmdUsartBtFactory(const char *Cmd) { ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); if (ret == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); - if (strcmp((char *)data, "OK+ROLE:S") == 0) { + if (strstr((char *)data, "OK")) { PrintAndLogEx(SUCCESS, "Role set to " _GREEN_("Slave")); } else { PrintAndLogEx(WARNING, "Unexpected response to AT+ROLE=S: " _YELLOW_("%.*s"), (int)len, data); @@ -280,15 +307,23 @@ static int CmdUsartBtFactory(const char *Cmd) { return PM3_ESOFT; } + msleep(500); + memset(data, 0, sizeof(data)); len = 0; - string = "AT+PIN1234"; + + if (isBluetoothExtensionHC04 == true) { + string = "AT+PIN=1234"; + } else { + string = "AT+PIN1234"; + } + PrintAndLogEx(SUCCESS, "TX (%3zu):%.*s", strlen(string), (int)strlen(string), string); ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); if (ret == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); - if (strcmp((char *)data, "OKsetPIN") == 0) { + if (strcmp((char *)data, "OK")) { PrintAndLogEx(SUCCESS, "PIN set to " _GREEN_("1234")); } else { PrintAndLogEx(WARNING, "Unexpected response to AT+PIN: " _YELLOW_("%.*s"), (int)len, data); @@ -298,38 +333,61 @@ static int CmdUsartBtFactory(const char *Cmd) { return PM3_ESOFT; } - // parity must be changed before baudrate - if (parity != USART_PARITY) { - memset(data, 0, sizeof(data)); - len = 0; - string = "AT+PN"; - PrintAndLogEx(SUCCESS, "TX (%3zu):%.*s", strlen(string), (int)strlen(string), string); + msleep(500); + + if (isBluetoothExtensionHC04 != true) { + // parity must be changed before baudrate + if (parity != USART_PARITY) { + memset(data, 0, sizeof(data)); + len = 0; + string = "AT+PN"; + PrintAndLogEx(SUCCESS, "TX (%3zu):%.*s", strlen(string), (int)strlen(string), string); - ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); - if (ret == PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); - if (strcmp((char *)data, "OK None") == 0) { - PrintAndLogEx(SUCCESS, "Parity set to " _GREEN_("None")); + ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); + if (ret == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); + if (strcmp((char *)data, "OK None") == 0) { + PrintAndLogEx(SUCCESS, "Parity set to " _GREEN_("None")); + } else { + PrintAndLogEx(WARNING, "Unexpected response to AT+P: " _YELLOW_("%.*s"), (int)len, data); + } } else { - PrintAndLogEx(WARNING, "Unexpected response to AT+P: " _YELLOW_("%.*s"), (int)len, data); + PrintAndLogEx(WARNING, "Lost contact with add-on, please try again"); + return PM3_ESOFT; } - } else { - PrintAndLogEx(WARNING, "Lost contact with add-on, please try again"); - return PM3_ESOFT; } - } - if (baudrate != USART_BAUD_RATE) { + if (baudrate != USART_BAUD_RATE) { + memset(data, 0, sizeof(data)); + len = 0; + string = BTADDON_BAUD_AT; + PrintAndLogEx(SUCCESS, "TX (%3zu):%.*s", strlen(string), (int)strlen(string), string); + + ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); + if (ret == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); + if (strcmp((char *)data, "OK" BTADDON_BAUD_NUM) == 0) { + PrintAndLogEx(SUCCESS, "Baudrate set to " _GREEN_(BTADDON_BAUD_NUM)); + } else { + PrintAndLogEx(WARNING, "Unexpected response to AT+BAUD: " _YELLOW_("%.*s"), (int)len, data); + } + } else { + PrintAndLogEx(WARNING, "Lost contact with add-on, please try again"); + return PM3_ESOFT; + } + } + } else { + memset(data, 0, sizeof(data)); - len = 0; - string = BTADDON_BAUD_AT; + len=0; + string = "AT+BAUD=115200,N"; PrintAndLogEx(SUCCESS, "TX (%3zu):%.*s", strlen(string), (int)strlen(string), string); ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); if (ret == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); - if (strcmp((char *)data, "OK" BTADDON_BAUD_NUM) == 0) { - PrintAndLogEx(SUCCESS, "Baudrate set to " _GREEN_(BTADDON_BAUD_NUM)); + if (strcmp((char *)data, "OK")) { + PrintAndLogEx(SUCCESS, "Parity set to " _GREEN_("None") "and Baudrate set to " _GREEN_("115200")); } else { PrintAndLogEx(WARNING, "Unexpected response to AT+BAUD: " _YELLOW_("%.*s"), (int)len, data); } From f13970ef7446b9a67514e8790cca5e866d065771 Mon Sep 17 00:00:00 2001 From: unknown10777 <83267603+unknown10777@users.noreply.github.com> Date: Sun, 24 Dec 2023 22:24:18 +0800 Subject: [PATCH 2/4] typo --- client/src/cmdusart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cmdusart.c b/client/src/cmdusart.c index 84c9a35c2..a356834cd 100644 --- a/client/src/cmdusart.c +++ b/client/src/cmdusart.c @@ -334,7 +334,7 @@ static int CmdUsartBtFactory(const char *Cmd) { } msleep(500); - + if (isBluetoothExtensionHC04 != true) { // parity must be changed before baudrate if (parity != USART_PARITY) { @@ -387,7 +387,7 @@ static int CmdUsartBtFactory(const char *Cmd) { if (ret == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); if (strcmp((char *)data, "OK")) { - PrintAndLogEx(SUCCESS, "Parity set to " _GREEN_("None") "and Baudrate set to " _GREEN_("115200")); + PrintAndLogEx(SUCCESS, "Parity set to " _GREEN_("None") " and Baudrate set to " _GREEN_("115200")); } else { PrintAndLogEx(WARNING, "Unexpected response to AT+BAUD: " _YELLOW_("%.*s"), (int)len, data); } From ecce0e65023daf085fcac6eeedc73a852cadf832 Mon Sep 17 00:00:00 2001 From: unknown10777 <83267603+unknown10777@users.noreply.github.com> Date: Mon, 25 Dec 2023 01:31:18 +0800 Subject: [PATCH 3/4] some not match original code spacing --- client/src/cmdusart.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/client/src/cmdusart.c b/client/src/cmdusart.c index a356834cd..755205966 100644 --- a/client/src/cmdusart.c +++ b/client/src/cmdusart.c @@ -165,23 +165,22 @@ static int usart_bt_testcomm(uint32_t baudrate, uint8_t parity) { // 1000, such large timeout needed ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); - if (ret == PM3_SUCCESS) - { + if (ret == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); if (str_startswith((char *)data, "hc01.comV2.0") || str_startswith((char *)data, "www.hc01.com") || - str_startswith((char *)data, "BT SPP V4.0")) - { + str_startswith((char *)data, "BT SPP V4.0")) { + PrintAndLogEx(SUCCESS, "Add-on " _GREEN_("found!")); + // if it fully match HC-04's attribute - if (str_startswith((char *)data, "www.hc01.com V2.5, 2022-04-26")) - { + if (str_startswith((char *)data, "www.hc01.com V2.5, 2022-04-26")) { isBluetoothExtensionHC04 = true; PrintAndLogEx(INFO, "Bluetooth module identified as HC-04."); } // if it fully match Blueshark HC-05's attribute - if (str_startswith((char *)data, "hc01.comV2.0")){ + if (str_startswith((char *)data, "hc01.comV2.0")) { isBluetoothExtensionHC05Blueshark = true; PrintAndLogEx(INFO, "Bluetooth module identified as Blueshark HC-05."); } From c22778d2199404b2634802d437a83522afd53901 Mon Sep 17 00:00:00 2001 From: unknown10777 <83267603+unknown10777@users.noreply.github.com> Date: Tue, 26 Dec 2023 21:37:46 +0800 Subject: [PATCH 4/4] detect if module said OK --- client/src/cmdusart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cmdusart.c b/client/src/cmdusart.c index 755205966..be52aa7ca 100644 --- a/client/src/cmdusart.c +++ b/client/src/cmdusart.c @@ -322,7 +322,7 @@ static int CmdUsartBtFactory(const char *Cmd) { ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); if (ret == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); - if (strcmp((char *)data, "OK")) { + if (strstr((char *)data, "OK") != NULL) { PrintAndLogEx(SUCCESS, "PIN set to " _GREEN_("1234")); } else { PrintAndLogEx(WARNING, "Unexpected response to AT+PIN: " _YELLOW_("%.*s"), (int)len, data); @@ -385,7 +385,7 @@ static int CmdUsartBtFactory(const char *Cmd) { ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); if (ret == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data); - if (strcmp((char *)data, "OK")) { + if (strstr((char *)data, "OK") != NULL) { PrintAndLogEx(SUCCESS, "Parity set to " _GREEN_("None") " and Baudrate set to " _GREEN_("115200")); } else { PrintAndLogEx(WARNING, "Unexpected response to AT+BAUD: " _YELLOW_("%.*s"), (int)len, data);