1 /** @file 2 * @brief Internal APIs for Bluetooth VOCS. 3 * 4 * Copyright (c) 2020 Bose Corporation 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_VOCS_INTERNAL_ 10 #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_VOCS_INTERNAL_ 11 12 #include <stdbool.h> 13 #include <stdint.h> 14 15 #include <zephyr/autoconf.h> 16 #include <zephyr/bluetooth/conn.h> 17 #include <zephyr/bluetooth/gatt.h> 18 #include <zephyr/kernel.h> 19 #include <zephyr/sys/atomic.h> 20 21 #if defined(CONFIG_BT_VOCS) 22 #define BT_VOCS_MAX_DESC_SIZE CONFIG_BT_VOCS_MAX_OUTPUT_DESCRIPTION_SIZE 23 #else 24 #define BT_VOCS_MAX_DESC_SIZE 1 25 #endif /* CONFIG_BT_VOCS */ 26 27 /* VOCS opcodes */ 28 #define BT_VOCS_OPCODE_SET_OFFSET 0x01 29 30 struct bt_vocs_control { 31 uint8_t opcode; 32 uint8_t counter; 33 int16_t offset; 34 } __packed; 35 36 struct bt_vocs_state { 37 int16_t offset; 38 uint8_t change_counter; 39 } __packed; 40 41 struct bt_vocs { 42 bool client_instance; 43 }; 44 45 enum bt_vocs_client_flag { 46 BT_VOCS_CLIENT_FLAG_BUSY, 47 BT_VOCS_CLIENT_FLAG_CP_RETRIED, 48 BT_VOCS_CLIENT_FLAG_DESC_WRITABLE, 49 BT_VOCS_CLIENT_FLAG_LOC_WRITABLE, 50 BT_VOCS_CLIENT_FLAG_ACTIVE, 51 52 BT_VOCS_CLIENT_FLAG_NUM_FLAGS, /* keep as last */ 53 }; 54 55 struct bt_vocs_client { 56 struct bt_vocs vocs; 57 struct bt_vocs_state state; 58 uint32_t location; 59 60 uint16_t start_handle; 61 uint16_t end_handle; 62 uint16_t state_handle; 63 uint16_t location_handle; 64 uint16_t control_handle; 65 uint16_t desc_handle; 66 struct bt_gatt_subscribe_params state_sub_params; 67 struct bt_gatt_subscribe_params location_sub_params; 68 struct bt_gatt_subscribe_params desc_sub_params; 69 70 struct bt_vocs_control cp; 71 struct bt_gatt_write_params write_params; 72 struct bt_gatt_read_params read_params; 73 struct bt_vocs_cb *cb; 74 struct bt_gatt_discover_params discover_params; 75 struct bt_conn *conn; 76 77 ATOMIC_DEFINE(flags, BT_VOCS_CLIENT_FLAG_NUM_FLAGS); 78 }; 79 80 enum bt_vocs_notify { 81 NOTIFY_STATE, 82 NOTIFY_LOCATION, 83 NOTIFY_OUTPUT_DESC, 84 NOTIFY_NUM, 85 }; 86 87 struct bt_vocs_server { 88 struct bt_vocs vocs; 89 struct bt_vocs_state state; 90 uint32_t location; 91 bool initialized; 92 char output_desc[BT_VOCS_MAX_DESC_SIZE]; 93 struct bt_vocs_cb *cb; 94 95 struct bt_gatt_service *service_p; 96 97 ATOMIC_DEFINE(notify, NOTIFY_NUM); 98 struct k_work_delayable notify_work; 99 }; 100 101 int bt_vocs_client_state_get(struct bt_vocs_client *inst); 102 int bt_vocs_client_state_set(struct bt_vocs_client *inst, int16_t offset); 103 int bt_vocs_client_location_get(struct bt_vocs_client *inst); 104 int bt_vocs_client_location_set(struct bt_vocs_client *inst, uint32_t location); 105 int bt_vocs_client_description_get(struct bt_vocs_client *inst); 106 int bt_vocs_client_description_set(struct bt_vocs_client *inst, const char *description); 107 108 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_VOCS_INTERNAL_ */ 109