ble.h (3420B)
1 /* 2 * libdivecomputer 3 * 4 * Copyright (C) 2019 Jef Driesen 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301 USA 20 */ 21 22 #ifndef DC_BLE_H 23 #define DC_BLE_H 24 25 #include "ioctl.h" 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif /* __cplusplus */ 30 31 /** 32 * Get the remote device name. 33 */ 34 #define DC_IOCTL_BLE_GET_NAME DC_IOCTL_IOR('b', 0, DC_IOCTL_SIZE_VARIABLE) 35 36 /** 37 * Get the bluetooth authentication PIN code. 38 * 39 * The data format is a NULL terminated string. 40 */ 41 #define DC_IOCTL_BLE_GET_PINCODE DC_IOCTL_IOR('b', 1, DC_IOCTL_SIZE_VARIABLE) 42 43 /** 44 * Get/set the bluetooth authentication access code. 45 * 46 * The data format is a variable sized byte array. 47 */ 48 #define DC_IOCTL_BLE_GET_ACCESSCODE DC_IOCTL_IOR('b', 2, DC_IOCTL_SIZE_VARIABLE) 49 #define DC_IOCTL_BLE_SET_ACCESSCODE DC_IOCTL_IOW('b', 2, DC_IOCTL_SIZE_VARIABLE) 50 51 /** 52 * Perform a BLE characteristic read/write operation. 53 * 54 * The UUID of the characteristic must be specified as a #dc_ble_uuid_t 55 * data structure. If the operation requires additional data as in- or 56 * output, the buffer must be located immediately after the 57 * #dc_ble_uuid_t data structure. The size of the ioctl request is the 58 * total size, including the size of the #dc_ble_uuid_t structure. 59 */ 60 #define DC_IOCTL_BLE_CHARACTERISTIC_READ DC_IOCTL_IOR('b', 3, DC_IOCTL_SIZE_VARIABLE) 61 #define DC_IOCTL_BLE_CHARACTERISTIC_WRITE DC_IOCTL_IOW('b', 3, DC_IOCTL_SIZE_VARIABLE) 62 63 /** 64 * The minimum number of bytes (including the terminating null byte) for 65 * formatting a bluetooth UUID as a string. 66 */ 67 #define DC_BLE_UUID_SIZE 37 68 69 /** 70 * Bluetooth UUID (128 bits). 71 */ 72 typedef unsigned char dc_ble_uuid_t[16]; 73 74 /** 75 * Convert a bluetooth UUID to a string. 76 * 77 * The bluetooth UUID is formatted as 78 * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, where each XX pair is a 79 * hexadecimal number specifying an octet of the UUID. 80 * The minimum size for the buffer is #DC_BLE_UUID_SIZE bytes. 81 * 82 * @param[in] uuid A bluetooth UUID. 83 * @param[in] str The memory buffer to store the result. 84 * @param[in] size The size of the memory buffer. 85 * @returns The null-terminated string on success, or NULL on failure. 86 */ 87 char * 88 dc_ble_uuid2str (const dc_ble_uuid_t uuid, char *str, size_t size); 89 90 /** 91 * Convert a string to a bluetooth UUID. 92 * 93 * The string is expected to be in the format 94 * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, where each XX pair is a 95 * hexadecimal number specifying an octet of the UUID. 96 * 97 * @param[in] str A null-terminated string. 98 * @param[in] uuid The memory buffer to store the result. 99 * @returns Non-zero on success, or zero on failure. 100 */ 101 int 102 dc_ble_str2uuid (const char *str, dc_ble_uuid_t uuid); 103 104 #ifdef __cplusplus 105 } 106 #endif /* __cplusplus */ 107 #endif /* DC_BLE_H */