diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bt_packet_logger.c | 33 | ||||
| -rw-r--r-- | src/bt_packet_logger.h | 4 |
2 files changed, 16 insertions, 21 deletions
diff --git a/src/bt_packet_logger.c b/src/bt_packet_logger.c index 5391825..196039e 100644 --- a/src/bt_packet_logger.c +++ b/src/bt_packet_logger.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * bt_packet_logger.c | 2 | * bt_packet_logger.c |
| 3 | * com.apple.bt_packet_logger service implementation. | 3 | * com.apple.bluetooth.BTPacketLogger service implementation. |
| 4 | * | 4 | * |
| 5 | * Copyright (c) 2021 Geoffrey Kruse, All Rights Reserved. | 5 | * Copyright (c) 2021 Geoffrey Kruse, All Rights Reserved. |
| 6 | * | 6 | * |
| @@ -28,13 +28,16 @@ | |||
| 28 | #include "bt_packet_logger.h" | 28 | #include "bt_packet_logger.h" |
| 29 | #include "lockdown.h" | 29 | #include "lockdown.h" |
| 30 | #include "common/debug.h" | 30 | #include "common/debug.h" |
| 31 | |||
| 32 | struct bt_packet_logger_worker_thread { | 31 | struct bt_packet_logger_worker_thread { |
| 33 | bt_packet_logger_client_t client; | 32 | bt_packet_logger_client_t client; |
| 34 | bt_packet_logger_receive_cb_t cbfunc; | 33 | bt_packet_logger_receive_cb_t cbfunc; |
| 35 | void *user_data; | 34 | void *user_data; |
| 35 | uint8_t rxbuff[BT_MAX_PACKET_SIZE]; | ||
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | #define SZ_READ_TIMEOUT 100 | ||
| 39 | #define PAYLOAD_READ_TIMEOUT 500 | ||
| 40 | |||
| 38 | /** | 41 | /** |
| 39 | * Convert a service_error_t value to a bt_packet_logger_error_t value. | 42 | * Convert a service_error_t value to a bt_packet_logger_error_t value. |
| 40 | * Used internally to get correct error codes. | 43 | * Used internally to get correct error codes. |
| @@ -67,8 +70,6 @@ static bt_packet_logger_error_t bt_packet_logger_error(service_error_t err) | |||
| 67 | 70 | ||
| 68 | LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_new(idevice_t device, lockdownd_service_descriptor_t service, bt_packet_logger_client_t * client) | 71 | LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_new(idevice_t device, lockdownd_service_descriptor_t service, bt_packet_logger_client_t * client) |
| 69 | { | 72 | { |
| 70 | *client = NULL; | ||
| 71 | |||
| 72 | if (!device || !service || service->port == 0 || !client || *client) { | 73 | if (!device || !service || service->port == 0 || !client || *client) { |
| 73 | debug_info("Incorrect parameter passed to bt_packet_logger_client_new."); | 74 | debug_info("Incorrect parameter passed to bt_packet_logger_client_new."); |
| 74 | return BT_PACKET_LOGGER_E_INVALID_ARG; | 75 | return BT_PACKET_LOGGER_E_INVALID_ARG; |
| @@ -111,11 +112,6 @@ LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_free(bt_pa | |||
| 111 | return err; | 112 | return err; |
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_receive(bt_packet_logger_client_t client, char* data, uint32_t size, uint32_t *received) | ||
| 115 | { | ||
| 116 | return bt_packet_logger_receive_with_timeout(client, data, size, received, 1000); | ||
| 117 | } | ||
| 118 | |||
| 119 | LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_receive_with_timeout(bt_packet_logger_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout) | 115 | LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_receive_with_timeout(bt_packet_logger_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout) |
| 120 | { | 116 | { |
| 121 | bt_packet_logger_error_t res = BT_PACKET_LOGGER_E_UNKNOWN_ERROR; | 117 | bt_packet_logger_error_t res = BT_PACKET_LOGGER_E_UNKNOWN_ERROR; |
| @@ -141,8 +137,9 @@ void *bt_packet_logger_worker(void *arg) | |||
| 141 | bt_packet_logger_error_t ret = BT_PACKET_LOGGER_E_UNKNOWN_ERROR; | 137 | bt_packet_logger_error_t ret = BT_PACKET_LOGGER_E_UNKNOWN_ERROR; |
| 142 | struct bt_packet_logger_worker_thread *btwt = (struct bt_packet_logger_worker_thread*)arg; | 138 | struct bt_packet_logger_worker_thread *btwt = (struct bt_packet_logger_worker_thread*)arg; |
| 143 | 139 | ||
| 144 | if (!btwt) | 140 | if (!btwt) { |
| 145 | return NULL; | 141 | return NULL; |
| 142 | } | ||
| 146 | 143 | ||
| 147 | debug_info("Running"); | 144 | debug_info("Running"); |
| 148 | 145 | ||
| @@ -150,7 +147,7 @@ void *bt_packet_logger_worker(void *arg) | |||
| 150 | uint32_t bytes = 0; | 147 | uint32_t bytes = 0; |
| 151 | uint16_t len; | 148 | uint16_t len; |
| 152 | 149 | ||
| 153 | ret = bt_packet_logger_receive_with_timeout(btwt->client, &len, 2, &bytes, 100); | 150 | ret = bt_packet_logger_receive_with_timeout(btwt->client, (char*)&len, 2, &bytes, SZ_READ_TIMEOUT); |
| 154 | 151 | ||
| 155 | if (ret == BT_PACKET_LOGGER_E_TIMEOUT || ret == BT_PACKET_LOGGER_E_NOT_ENOUGH_DATA || ((bytes == 0) && (ret == BT_PACKET_LOGGER_E_SUCCESS))) { | 152 | if (ret == BT_PACKET_LOGGER_E_TIMEOUT || ret == BT_PACKET_LOGGER_E_NOT_ENOUGH_DATA || ((bytes == 0) && (ret == BT_PACKET_LOGGER_E_SUCCESS))) { |
| 156 | continue; | 153 | continue; |
| @@ -159,11 +156,10 @@ void *bt_packet_logger_worker(void *arg) | |||
| 159 | break; | 156 | break; |
| 160 | } | 157 | } |
| 161 | 158 | ||
| 162 | // todo remove magic and move "c" off stack | 159 | // sanity check received length |
| 163 | if(bytes > 0 && len > 12) { | 160 | if(bytes > 0 && len > sizeof(bt_packet_logger_header_t)) { |
| 164 | char c[65535]; | ||
| 165 | debug_info("Reading %u bytes\n", len); | 161 | debug_info("Reading %u bytes\n", len); |
| 166 | ret = bt_packet_logger_receive_with_timeout(btwt->client, c, len, &bytes, 500); | 162 | ret = bt_packet_logger_receive_with_timeout(btwt->client, (char *)btwt->rxbuff, len, &bytes, PAYLOAD_READ_TIMEOUT); |
| 167 | 163 | ||
| 168 | if(len != bytes) { | 164 | if(len != bytes) { |
| 169 | debug_info("Failed Read Expected %u, Received %u\n", len, bytes); | 165 | debug_info("Failed Read Expected %u, Received %u\n", len, bytes); |
| @@ -177,13 +173,12 @@ void *bt_packet_logger_worker(void *arg) | |||
| 177 | break; | 173 | break; |
| 178 | } | 174 | } |
| 179 | 175 | ||
| 180 | btwt->cbfunc(c, len, btwt->user_data); | 176 | btwt->cbfunc(btwt->rxbuff, len, btwt->user_data); |
| 181 | } | 177 | } |
| 182 | } | 178 | } |
| 183 | 179 | ||
| 184 | if (btwt) { | 180 | // null check performed above |
| 185 | free(btwt); | 181 | free(btwt); |
| 186 | } | ||
| 187 | 182 | ||
| 188 | debug_info("Exiting"); | 183 | debug_info("Exiting"); |
| 189 | 184 | ||
diff --git a/src/bt_packet_logger.h b/src/bt_packet_logger.h index 1ad906d..f9e0c3e 100644 --- a/src/bt_packet_logger.h +++ b/src/bt_packet_logger.h | |||
| @@ -19,8 +19,8 @@ | |||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #ifndef _SYSLOG_RELAY_H | 22 | #ifndef _BR_PACKET_LOGGER_H |
| 23 | #define _SYSLOG_RELAY_H | 23 | #define _BR_PACKET_LOGGER_H |
| 24 | 24 | ||
| 25 | #include "libimobiledevice/bt_packet_logger.h" | 25 | #include "libimobiledevice/bt_packet_logger.h" |
| 26 | #include "service.h" | 26 | #include "service.h" |
