summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice/bt_packet_logger.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libimobiledevice/bt_packet_logger.h')
-rw-r--r--include/libimobiledevice/bt_packet_logger.h156
1 files changed, 156 insertions, 0 deletions
diff --git a/include/libimobiledevice/bt_packet_logger.h b/include/libimobiledevice/bt_packet_logger.h
new file mode 100644
index 0000000..590e5c1
--- /dev/null
+++ b/include/libimobiledevice/bt_packet_logger.h
@@ -0,0 +1,156 @@
1/**
2 * @file libimobiledevice/bt_packet_logger.h
3 * @brief Capture the Bluetooth HCI trace from a device
4 * \internal
5 *
6 * Copyright (c) 2021 Geoffrey Kruse, All Rights Reserved.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef IBT_PACKET_LOGGER_H
24#define IBT_PACKET_LOGGER_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
32
33#define BT_PACKETLOGGER_SERVICE_NAME "com.apple.bluetooth.BTPacketLogger"
34#define BT_MAX_PACKET_SIZE 65535
35
36/** Error Codes */
37typedef enum {
38 BT_PACKET_LOGGER_E_SUCCESS = 0,
39 BT_PACKET_LOGGER_E_INVALID_ARG = -1,
40 BT_PACKET_LOGGER_E_MUX_ERROR = -2,
41 BT_PACKET_LOGGER_E_SSL_ERROR = -3,
42 BT_PACKET_LOGGER_E_NOT_ENOUGH_DATA = -4,
43 BT_PACKET_LOGGER_E_TIMEOUT = -5,
44 BT_PACKET_LOGGER_E_UNKNOWN_ERROR = -256
45} bt_packet_logger_error_t;
46
47typedef struct {
48 uint32_t length;
49 uint32_t ts_secs;
50 uint32_t ts_usecs;
51} bt_packet_logger_header_t;
52
53typedef struct bt_packet_logger_client_private bt_packet_logger_client_private;
54typedef bt_packet_logger_client_private *bt_packet_logger_client_t; /**< The client handle. */
55
56/** Receives each hci packet received from the device. */
57typedef void (*bt_packet_logger_receive_cb_t)(uint8_t * data, uint16_t len, void *user_data);
58
59/* Interface */
60
61/**
62 * Connects to the bt_packet_logger service on the specified device.
63 *
64 * @param device The device to connect to.
65 * @param service The service descriptor returned by lockdownd_start_service.
66 * @param client Pointer that will point to a newly allocated
67 * bt_packet_logger_client_t upon successful return. Must be freed using
68 * bt_packet_logger_client_free() after use.
69 *
70 * @return BT_PACKET_LOGGER_E_SUCCESS on success, BT_PACKET_LOGGER_E_INVALID_ARG when
71 * client is NULL, or an BT_PACKET_LOGGER_E_* error code otherwise.
72 */
73LIBIMOBILEDEVICE_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);
74
75/**
76 * Starts a new bt_packet_logger service on the specified device and connects to it.
77 *
78 * @param device The device to connect to.
79 * @param client Pointer that will point to a newly allocated
80 * bt_packet_logger_client_t upon successful return. Must be freed using
81 * bt_packet_logger_client_free() after use.
82 * @param label The label to use for communication. Usually the program name.
83 * Pass NULL to disable sending the label in requests to lockdownd.
84 *
85 * @return BT_PACKET_LOGGER_E_SUCCESS on success, or an BT_PACKET_LOGGER_E_* error
86 * code otherwise.
87 */
88LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_start_service(idevice_t device, bt_packet_logger_client_t * client, const char* label);
89
90/**
91 * Disconnects a bt_packet_logger client from the device and frees up the
92 * bt_packet_logger client data.
93 *
94 * @param client The bt_packet_logger client to disconnect and free.
95 *
96 * @return BT_PACKET_LOGGER_E_SUCCESS on success, BT_PACKET_LOGGER_E_INVALID_ARG when
97 * client is NULL, or an BT_PACKET_LOGGER_E_* error code otherwise.
98 */
99LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_free(bt_packet_logger_client_t client);
100
101
102/**
103 * Starts capturing the hci interface from the device using a callback.
104 *
105 * Use bt_packet_logger_stop_capture() to stop receiving hci data.
106 *
107 * @param client The bt_packet_logger client to use
108 * @param callback Callback to receive each packet from the hci interface.
109 * @param user_data Custom pointer passed to the callback function.
110 *
111 * @return BT_PACKET_LOGGER_E_SUCCESS on success,
112 * BT_PACKET_LOGGER_E_INVALID_ARG when one or more parameters are
113 * invalid or BT_PACKET_LOGGER_E_UNKNOWN_ERROR when an unspecified
114 * error occurs or an hci capture has already been started.
115 */
116LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_start_capture(bt_packet_logger_client_t client, bt_packet_logger_receive_cb_t callback, void* user_data);
117
118/**
119 * Stops capturing the hci interface from the device.
120 *
121 * Use bt_packet_logger_start_capture() to start receiving the hci data.
122 *
123 * @param client The bt_packet_logger client to use
124 *
125 * @return BT_PACKET_LOGGER_E_SUCCESS on success,
126 * BT_PACKET_LOGGER_E_INVALID_ARG when one or more parameters are
127 * invalid or BT_PACKET_LOGGER_E_UNKNOWN_ERROR when an unspecified
128 * error occurs or an hci capture has already been started.
129 */
130LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_stop_capture(bt_packet_logger_client_t client);
131
132/* Receiving */
133
134/**
135 * Receives data using the given bt_packet_logger client with specified timeout.
136 *
137 * @param client The bt_packet_logger client to use for receiving
138 * @param data Buffer that will be filled with the data received
139 * @param size Number of bytes to receive
140 * @param received Number of bytes received (can be NULL to ignore)
141 * @param timeout Maximum time in milliseconds to wait for data.
142 *
143 * @return BT_PACKET_LOGGER_E_SUCCESS on success,
144 * BT_PACKET_LOGGER_E_INVALID_ARG when one or more parameters are
145 * invalid, BT_PACKET_LOGGER_E_MUX_ERROR when a communication error
146 * occurs, or BT_PACKET_LOGGER_E_UNKNOWN_ERROR when an unspecified
147 * error occurs.
148 */
149LIBIMOBILEDEVICE_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);
150
151
152#ifdef __cplusplus
153}
154#endif
155
156#endif