From 57974c23ffb3f74497c3bfa99a20a5363fc0983b Mon Sep 17 00:00:00 2001 From: Emiliano Betti Date: Wed, 18 May 2016 12:53:15 +0200 Subject: [PATCH 1/7] Fix for INQUIRY command results --- C/iWRAP.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/C/iWRAP.c b/C/iWRAP.c index 2b421b9..2dad483 100644 --- a/C/iWRAP.c +++ b/C/iWRAP.c @@ -420,7 +420,7 @@ uint8_t iwrap_parse(uint8_t b, uint8_t mode) { #ifdef IWRAP_INCLUDE_RSP_INQUIRY_COUNT // INQUIRY {num_of_devices} if (iwrap_rsp_inquiry_count) { - char *test = (char *)iwrap_tptr + 5; + char *test = (char *)iwrap_tptr + 8; uint8_t num_of_devices = strtol(test, &test, 10); iwrap_rsp_inquiry_count(num_of_devices); } @@ -428,7 +428,7 @@ uint8_t iwrap_parse(uint8_t b, uint8_t mode) { } else { #ifdef IWRAP_INCLUDE_RSP_INQUIRY_RESULT // INQUIRY {addr} {class_of_device} [rssi] - if (iwrap_rsp_list_result) { + if (iwrap_rsp_inquiry_result) { char *test = (char *)iwrap_tptr + 8; iwrap_address_t mac; iwrap_hexstrtobin(test, &test, mac.address, 0); test++; From 441fa0bdbf13e80a3225dae0d814f18dd98f2e8f Mon Sep 17 00:00:00 2001 From: Emiliano Betti Date: Wed, 18 May 2016 12:58:02 +0200 Subject: [PATCH 2/7] AUTH event handled --- C/iWRAP.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/C/iWRAP.c b/C/iWRAP.c index 2dad483..f60b734 100644 --- a/C/iWRAP.c +++ b/C/iWRAP.c @@ -601,6 +601,17 @@ uint8_t iwrap_parse(uint8_t b, uint8_t mode) { #endif } #endif + #ifdef IWRAP_INCLUDE_EVT_AUTH + } else if (strncmp((char *)iwrap_tptr, "AUTH ", 5) == 0 && + iwrap_tptr[7] == ':' && iwrap_tptr[22] == '?') { + // AUTH {bd_addr}? + if (iwrap_evt_auth) { + char *test = (char *)iwrap_tptr + 5; + iwrap_address_t mac; + iwrap_hexstrtobin(test, &test, mac.address, 17); + iwrap_evt_auth(&mac); + } + #endif #ifdef IWRAP_INCLUDE_EVT_READY } else if (strncmp((char *)iwrap_tptr, "READY", 5) == 0) { // READY. From b3b7aaf039d9985ded0440d5d7dcfd7cf47b4580 Mon Sep 17 00:00:00 2001 From: Emiliano Betti Date: Wed, 18 May 2016 12:59:51 +0200 Subject: [PATCH 3/7] RSSI response handled --- C/iWRAP.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/C/iWRAP.c b/C/iWRAP.c index f60b734..500381b 100644 --- a/C/iWRAP.c +++ b/C/iWRAP.c @@ -612,6 +612,18 @@ uint8_t iwrap_parse(uint8_t b, uint8_t mode) { iwrap_evt_auth(&mac); } #endif + #ifdef IWRAP_INCLUDE_RSP_RSSI + } else if (strncmp((char *)iwrap_tptr, "RSSI", 4) == 0) { + // RSSI {bd_addr} {rssi} + if (iwrap_rsp_rssi) { + char *test = (char *)iwrap_tptr + 5; + int8_t rssi; + iwrap_address_t mac; + iwrap_hexstrtobin(test, &test, mac.address, 0); test++; // advance to first " character + rssi = strtol(test, &test, 10); + iwrap_rsp_rssi(&mac, rssi); + } + #endif #ifdef IWRAP_INCLUDE_EVT_READY } else if (strncmp((char *)iwrap_tptr, "READY", 5) == 0) { // READY. From 207a44bca1bb2ef960bb0559238878d50b1d02f2 Mon Sep 17 00:00:00 2001 From: Emiliano Betti Date: Wed, 18 May 2016 13:02:55 +0200 Subject: [PATCH 4/7] Fix for RING event --- C/iWRAP.c | 9 ++++----- C/iWRAP.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/C/iWRAP.c b/C/iWRAP.c index 500381b..f1bfb87 100644 --- a/C/iWRAP.c +++ b/C/iWRAP.c @@ -641,12 +641,11 @@ uint8_t iwrap_parse(uint8_t b, uint8_t mode) { uint8_t link_id = strtol(test, &test, 10); test++; iwrap_address_t address; iwrap_hexstrtobin(test, &test, address.address, 0); test++; - if (test[0] == 'S') { + if (strncmp(test, "SCO", 3) == 0) { // SCO (no "channel" parameter) char *profile = test; - test = strchr(test, ' '); - test[0] = 0; // null terminate for in-place string access to "mode" w/o reallocation - iwrap_evt_ring(link_id, &address, 0, profile); + test[3] = 0; + iwrap_evt_ring(link_id, &address, 0xFF, profile); } else { // not SCO uint16_t channel = strtol(test, &test, 16); test++; @@ -1110,7 +1109,7 @@ int (*iwrap_output)(int length, unsigned char *data); void (*iwrap_evt_ready)(); #endif #ifdef IWRAP_INCLUDE_EVT_RING - void (*iwrap_evt_ring)(uint8_t link_id, const iwrap_address_t *address, uint16_t channel, const char *profile); + void (*iwrap_evt_ring)(uint8_t link_id, const iwrap_address_t *address, uint8_t channel, const char *profile); #endif #ifdef IWRAP_INCLUDE_EVT_SSPAUTH void (*iwrap_evt_sspauth)(const iwrap_address_t *bd_addr); diff --git a/C/iWRAP.h b/C/iWRAP.h index 6a9a963..cc74f9c 100644 --- a/C/iWRAP.h +++ b/C/iWRAP.h @@ -367,7 +367,7 @@ extern int (*iwrap_output)(int length, unsigned char *data); extern void (*iwrap_evt_ready)(); #endif #ifdef IWRAP_INCLUDE_EVT_RING - extern void (*iwrap_evt_ring)(uint8_t link_id, const iwrap_address_t *address, uint16_t channel, const char *profile); + extern void (*iwrap_evt_ring)(uint8_t link_id, const iwrap_address_t *address, uint8_t channel, const char *profile); #endif #ifdef IWRAP_INCLUDE_EVT_SSPAUTH extern void (*iwrap_evt_sspauth)(const iwrap_address_t *bd_addr); From 0076172da81f3a2470f185fda09a5aa99b5f3b55 Mon Sep 17 00:00:00 2001 From: Emiliano Betti Date: Wed, 18 May 2016 13:06:44 +0200 Subject: [PATCH 5/7] MUX frame packing a little more robust --- C/iWRAP.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/C/iWRAP.c b/C/iWRAP.c index f1bfb87..93ccd63 100644 --- a/C/iWRAP.c +++ b/C/iWRAP.c @@ -768,6 +768,10 @@ uint8_t iwrap_parse(uint8_t b, uint8_t mode) { * @return Result code (non-zero indicates error) */ uint8_t iwrap_pack_mux_frame(uint8_t channel, uint16_t in_len, uint8_t *in, uint16_t *out_len, uint8_t **out) { + + if (in_len > 1024) /* Max mux frame size */ + return 2; + // allocate enough memory for the whole MUX frame *out = (uint8_t *)malloc(in_len + 5); @@ -779,7 +783,7 @@ uint8_t iwrap_parse(uint8_t b, uint8_t mode) { (*out)[0] = 0xBF; (*out)[1] = channel; (*out)[2] = 0x00 | ((in_len >> 8) & 0x03); // flags = 0 always in latest iWRAP (2014-05-05) - (*out)[3] = in_len; + (*out)[3] = in_len & 0xFF; memcpy((*out) + 4, in, in_len); (*out)[in_len + 4] = channel ^ 0xFF; return 0; From 52d422ba3c3ba76cf463f68a6613c04d7a5e27b8 Mon Sep 17 00:00:00 2001 From: Emiliano Betti Date: Wed, 18 May 2016 14:11:35 +0200 Subject: [PATCH 6/7] Allowing iWRAP.h to be included in C++ files --- C/iWRAP.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/C/iWRAP.h b/C/iWRAP.h index cc74f9c..a2aa522 100644 --- a/C/iWRAP.h +++ b/C/iWRAP.h @@ -37,6 +37,10 @@ THE SOFTWARE. #ifndef _IWRAP_H_ #define _IWRAP_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include #ifndef IWRAP_CONFIGURED @@ -385,4 +389,8 @@ extern int (*iwrap_output)(int length, unsigned char *data); extern void (*iwrap_evt_volume)(uint8_t volume); #endif -#endif /* _IWRAP_H_ */ \ No newline at end of file +#ifdef __cplusplus +} +#endif + +#endif /* _IWRAP_H_ */ From 7b215d2ce843071b268c0beca979b4de8f1e590e Mon Sep 17 00:00:00 2001 From: Emiliano Betti Date: Sun, 22 May 2016 12:06:07 +0200 Subject: [PATCH 7/7] Bug fix for CONNECT event --- C/iWRAP.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/C/iWRAP.c b/C/iWRAP.c index 93ccd63..417e7f0 100644 --- a/C/iWRAP.c +++ b/C/iWRAP.c @@ -307,9 +307,9 @@ uint8_t iwrap_parse(uint8_t b, uint8_t mode) { test++; uint16_t target = strtol(test, &test, 16); test++; iwrap_address_t mac; - if ((uint16_t)((iwrap_tptr - (uint8_t *)test) + 17) < iwrap_rx_payload_length) { + if ((uint16_t)(((uint8_t *)test) + 17 - iwrap_tptr) <= iwrap_rx_payload_length) { // optional [address] parameter present - iwrap_hexstrtobin(test, &test, mac.address, 0); test++; + iwrap_hexstrtobin(test, &test, mac.address, 0); iwrap_evt_connect(link_id, profile, target, &mac); } else { iwrap_evt_connect(link_id, profile, target, 0);