1 /** @file 2 * @brief Internal APIs for Bluetooth AICS. 3 */ 4 5 /* 6 * Copyright (c) 2020 Bose Corporation 7 * Copyright (c) 2020 Nordic Semiconductor ASA 8 * 9 * SPDX-License-Identifier: Apache-2.0 10 */ 11 12 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_AICS_INTERNAL_ 13 #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_AICS_INTERNAL_ 14 #include <zephyr/types.h> 15 #include <bluetooth/gatt.h> 16 17 #if defined(CONFIG_BT_AICS) 18 #define BT_AICS_MAX_DESC_SIZE CONFIG_BT_AICS_MAX_INPUT_DESCRIPTION_SIZE 19 #else 20 #define BT_AICS_MAX_DESC_SIZE 1 21 #endif /* CONFIG_BT_AICS */ 22 23 /* AICS opcodes */ 24 #define BT_AICS_OPCODE_SET_GAIN 0x01 25 #define BT_AICS_OPCODE_UNMUTE 0x02 26 #define BT_AICS_OPCODE_MUTE 0x03 27 #define BT_AICS_OPCODE_SET_MANUAL 0x04 28 #define BT_AICS_OPCODE_SET_AUTO 0x05 29 30 /* AICS status */ 31 #define BT_AICS_STATUS_INACTIVE 0x00 32 #define BT_AICS_STATUS_ACTIVE 0x01 33 34 #define BT_AICS_INPUT_MODE_IMMUTABLE(gain_mode) \ 35 ((gain_mode) == BT_AICS_MODE_MANUAL_ONLY || (gain_mode) == BT_AICS_MODE_AUTO_ONLY) 36 37 #define BT_AICS_INPUT_MODE_SETTABLE(gain_mode) \ 38 ((gain_mode) == BT_AICS_MODE_AUTO || (gain_mode) == BT_AICS_MODE_MANUAL) 39 40 struct bt_aics_control { 41 uint8_t opcode; 42 uint8_t counter; 43 } __packed; 44 45 struct bt_aics_gain_control { 46 struct bt_aics_control cp; 47 int8_t gain_setting; 48 } __packed; 49 50 struct bt_aics_client { 51 uint8_t change_counter; 52 uint8_t gain_mode; 53 bool desc_writable; 54 bool active; 55 56 uint16_t start_handle; 57 uint16_t end_handle; 58 uint16_t state_handle; 59 uint16_t gain_handle; 60 uint16_t type_handle; 61 uint16_t status_handle; 62 uint16_t control_handle; 63 uint16_t desc_handle; 64 struct bt_gatt_subscribe_params state_sub_params; 65 struct bt_gatt_subscribe_params status_sub_params; 66 struct bt_gatt_subscribe_params desc_sub_params; 67 uint8_t subscribe_cnt; 68 bool cp_retried; 69 70 bool busy; 71 struct bt_aics_gain_control cp_val; 72 struct bt_gatt_write_params write_params; 73 struct bt_gatt_read_params read_params; 74 struct bt_gatt_discover_params discover_params; 75 struct bt_aics_cb *cb; 76 struct bt_conn *conn; 77 }; 78 79 struct bt_aics_state { 80 int8_t gain; 81 uint8_t mute; 82 uint8_t gain_mode; 83 uint8_t change_counter; 84 } __packed; 85 86 struct bt_aics_gain_settings { 87 uint8_t units; 88 int8_t minimum; 89 int8_t maximum; 90 } __packed; 91 92 struct bt_aics_server { 93 struct bt_aics_state state; 94 struct bt_aics_gain_settings gain_settings; 95 bool initialized; 96 uint8_t type; 97 uint8_t status; 98 struct bt_aics *inst; 99 char description[BT_AICS_MAX_DESC_SIZE]; 100 struct bt_aics_cb *cb; 101 102 struct bt_gatt_service *service_p; 103 }; 104 105 /* Struct used as a common type for the api */ 106 struct bt_aics { 107 bool client_instance; 108 union { 109 struct bt_aics_server srv; 110 struct bt_aics_client cli; 111 }; 112 113 }; 114 115 uint8_t aics_client_notify_handler(struct bt_conn *conn, 116 struct bt_gatt_subscribe_params *params, 117 const void *data, uint16_t length); 118 int bt_aics_client_register(struct bt_aics *inst); 119 int bt_aics_client_unregister(struct bt_aics *inst); 120 int bt_aics_client_state_get(struct bt_aics *inst); 121 int bt_aics_client_gain_setting_get(struct bt_aics *inst); 122 int bt_aics_client_type_get(struct bt_aics *inst); 123 int bt_aics_client_status_get(struct bt_aics *inst); 124 int bt_aics_client_unmute(struct bt_aics *inst); 125 int bt_aics_client_mute(struct bt_aics *inst); 126 int bt_aics_client_manual_gain_set(struct bt_aics *inst); 127 int bt_aics_client_automatic_gain_set(struct bt_aics *inst); 128 int bt_aics_client_gain_set(struct bt_aics *inst, int8_t gain); 129 int bt_aics_client_description_get(struct bt_aics *inst); 130 int bt_aics_client_description_set(struct bt_aics *inst, 131 const char *description); 132 133 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_AICS_INTERNAL_ */ 134