summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Geoffrey Kruse2021-03-06 16:56:54 -0800
committerGravatar Nikias Bassen2022-05-05 18:53:16 +0200
commita070a2e0b8774132a2c90822ba22580c4d1842da (patch)
treeae4dfcdacb2401c42029f56b1ea831afff2f71e9 /include
parentc6f89deac00347faa187f2f5296e32840c4f26b4 (diff)
downloadlibimobiledevice-a070a2e0b8774132a2c90822ba22580c4d1842da.tar.gz
libimobiledevice-a070a2e0b8774132a2c90822ba22580c4d1842da.tar.bz2
Initial commit of working packet logger (idevicebtlogger)
Diffstat (limited to 'include')
-rw-r--r--include/libimobiledevice/bt_packet_logger.h162
1 files changed, 162 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..697e879
--- /dev/null
+++ b/include/libimobiledevice/bt_packet_logger.h
@@ -0,0 +1,162 @@
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
35/** Error Codes */
36typedef enum {
37 BT_PACKET_LOGGER_E_SUCCESS = 0,
38 BT_PACKET_LOGGER_E_INVALID_ARG = -1,
39 BT_PACKET_LOGGER_E_MUX_ERROR = -2,
40 BT_PACKET_LOGGER_E_SSL_ERROR = -3,
41 BT_PACKET_LOGGER_E_NOT_ENOUGH_DATA = -4,
42 BT_PACKET_LOGGER_E_TIMEOUT = -5,
43 BT_PACKET_LOGGER_E_UNKNOWN_ERROR = -256
44} bt_packet_logger_error_t;
45
46typedef struct bt_packet_logger_client_private bt_packet_logger_client_private;
47typedef bt_packet_logger_client_private *bt_packet_logger_client_t; /**< The client handle. */
48
49/** Receives each character received from the device. */
50typedef void (*bt_packet_logger_receive_cb_t)(uint8_t * data, uint16_t len, void *user_data);
51
52/* Interface */
53
54/**
55 * Connects to the bt_packet_logger service on the specified device.
56 *
57 * @param device The device to connect to.
58 * @param service The service descriptor returned by lockdownd_start_service.
59 * @param client Pointer that will point to a newly allocated
60 * bt_packet_logger_client_t upon successful return. Must be freed using
61 * bt_packet_logger_client_free() after use.
62 *
63 * @return BT_PACKET_LOGGER_E_SUCCESS on success, BT_PACKET_LOGGER_E_INVALID_ARG when
64 * client is NULL, or an BT_PACKET_LOGGER_E_* error code otherwise.
65 */
66bt_packet_logger_error_t bt_packet_logger_client_new(idevice_t device, lockdownd_service_descriptor_t service, bt_packet_logger_client_t * client);
67
68/**
69 * Starts a new bt_packet_logger service on the specified device and connects to it.
70 *
71 * @param device The device to connect to.
72 * @param client Pointer that will point to a newly allocated
73 * bt_packet_logger_client_t upon successful return. Must be freed using
74 * bt_packet_logger_client_free() after use.
75 * @param label The label to use for communication. Usually the program name.
76 * Pass NULL to disable sending the label in requests to lockdownd.
77 *
78 * @return BT_PACKET_LOGGER_E_SUCCESS on success, or an BT_PACKET_LOGGER_E_* error
79 * code otherwise.
80 */
81bt_packet_logger_error_t bt_packet_logger_client_start_service(idevice_t device, bt_packet_logger_client_t * client, const char* label);
82
83/**
84 * Disconnects a bt_packet_logger client from the device and frees up the
85 * bt_packet_logger client data.
86 *
87 * @param client The bt_packet_logger client to disconnect and free.
88 *
89 * @return BT_PACKET_LOGGER_E_SUCCESS on success, BT_PACKET_LOGGER_E_INVALID_ARG when
90 * client is NULL, or an BT_PACKET_LOGGER_E_* error code otherwise.
91 */
92bt_packet_logger_error_t bt_packet_logger_client_free(bt_packet_logger_client_t client);
93
94
95/**
96 * Starts capturing the syslog of the device using a callback.
97 *
98 * Use bt_packet_logger_stop_capture() to stop receiving the syslog.
99 *
100 * @param client The bt_packet_logger client to use
101 * @param callback Callback to receive each character from the syslog.
102 * @param user_data Custom pointer passed to the callback function.
103 *
104 * @return BT_PACKET_LOGGER_E_SUCCESS on success,
105 * BT_PACKET_LOGGER_E_INVALID_ARG when one or more parameters are
106 * invalid or BT_PACKET_LOGGER_E_UNKNOWN_ERROR when an unspecified
107 * error occurs or a syslog capture has already been started.
108 */
109bt_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);
110
111/**
112 * Stops capturing the syslog of the device.
113 *
114 * Use bt_packet_logger_start_capture() to start receiving the syslog.
115 *
116 * @param client The bt_packet_logger client to use
117 *
118 * @return BT_PACKET_LOGGER_E_SUCCESS on success,
119 * BT_PACKET_LOGGER_E_INVALID_ARG when one or more parameters are
120 * invalid or BT_PACKET_LOGGER_E_UNKNOWN_ERROR when an unspecified
121 * error occurs or a syslog capture has already been started.
122 */
123bt_packet_logger_error_t bt_packet_logger_stop_capture(bt_packet_logger_client_t client);
124
125/* Receiving */
126
127/**
128 * Receives data using the given bt_packet_logger client with specified timeout.
129 *
130 * @param client The bt_packet_logger client to use for receiving
131 * @param data Buffer that will be filled with the data received
132 * @param size Number of bytes to receive
133 * @param received Number of bytes received (can be NULL to ignore)
134 * @param timeout Maximum time in milliseconds to wait for data.
135 *
136 * @return BT_PACKET_LOGGER_E_SUCCESS on success,
137 * BT_PACKET_LOGGER_E_INVALID_ARG when one or more parameters are
138 * invalid, BT_PACKET_LOGGER_E_MUX_ERROR when a communication error
139 * occurs, or BT_PACKET_LOGGER_E_UNKNOWN_ERROR when an unspecified
140 * error occurs.
141 */
142bt_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);
143
144/**
145 * Receives data from the service.
146 *
147 * @param client The bt_packet_logger client
148 * @param data Buffer that will be filled with the data received
149 * @param size Number of bytes to receive
150 * @param received Number of bytes received (can be NULL to ignore)
151 * @param timeout Maximum time in milliseconds to wait for data.
152 *
153 * @return BT_PACKET_LOGGER_E_SUCCESS on success,
154 * BT_PACKET_LOGGER_E_INVALID_ARG when client or plist is NULL
155 */
156bt_packet_logger_error_t bt_packet_logger_receive(bt_packet_logger_client_t client, char *data, uint32_t size, uint32_t *received);
157
158#ifdef __cplusplus
159}
160#endif
161
162#endif