1 /** @file 2 * @brief Internal APIs for Bluetooth MCP. 3 */ 4 5 /* 6 * Copyright (c) 2019 - 2021 Nordic Semiconductor ASA 7 * 8 * SPDX-License-Identifier: Apache-2.0 9 */ 10 11 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MCP_INTERNAL_ 12 #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MCP_INTERNAL_ 13 14 #include <stdbool.h> 15 #include <stdint.h> 16 17 #include <zephyr/autoconf.h> 18 #include <zephyr/bluetooth/audio/mcs.h> 19 #include <zephyr/bluetooth/conn.h> 20 #include <zephyr/bluetooth/gatt.h> 21 #include <zephyr/bluetooth/services/ots.h> 22 #include <zephyr/sys/atomic.h> 23 #include <zephyr/types.h> 24 25 struct mcs_instance_t *lookup_inst_by_conn(struct bt_conn *conn); 26 27 enum mcc_flag { 28 MCC_FLAG_BUSY, 29 30 MCC_FLAG_NUM_FLAGS, /* keep as last */ 31 }; 32 33 struct mcs_instance_t { 34 struct bt_conn *conn; 35 uint16_t start_handle; 36 uint16_t end_handle; 37 uint16_t player_name_handle; 38 #ifdef CONFIG_BT_MCC_OTS 39 uint16_t icon_obj_id_handle; 40 #endif /* CONFIG_BT_MCC_OTS */ 41 #if defined(CONFIG_BT_MCC_READ_MEDIA_PLAYER_ICON_URL) 42 uint16_t icon_url_handle; 43 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_PLAYER_ICON_URL) */ 44 uint16_t track_changed_handle; 45 #if defined(CONFIG_BT_MCC_READ_TRACK_TITLE) 46 uint16_t track_title_handle; 47 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_TITLE) */ 48 #if defined(CONFIG_BT_MCC_READ_TRACK_DURATION) 49 uint16_t track_duration_handle; 50 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_DURATION) */ 51 #if defined(CONFIG_BT_MCC_READ_TRACK_POSITION) || defined(CONFIG_BT_MCC_SET_TRACK_POSITION) 52 uint16_t track_position_handle; 53 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_POSITION) || defined(CONFIG_BT_MCC_SET_TRACK_POSITION) */ 54 #if defined(CONFIG_BT_MCC_READ_PLAYBACK_SPEED) || defined(CONFIG_BT_MCC_SET_PLAYBACK_SPEED) 55 uint16_t playback_speed_handle; 56 #endif /* defined (CONFIG_BT_MCC_READ_PLAYBACK_SPEED) || */ 57 /* defined (CONFIG_BT_MCC_SET_PLAYBACK_SPEED) */ 58 #if defined(CONFIG_BT_MCC_READ_SEEKING_SPEED) 59 uint16_t seeking_speed_handle; 60 #endif /* defined (CONFIG_BT_MCC_READ_SEEKING_SPEED) */ 61 #ifdef CONFIG_BT_MCC_OTS 62 uint16_t segments_obj_id_handle; 63 uint16_t current_track_obj_id_handle; 64 uint16_t next_track_obj_id_handle; 65 uint16_t current_group_obj_id_handle; 66 uint16_t parent_group_obj_id_handle; 67 #endif /* CONFIG_BT_MCC_OTS */ 68 #if defined(CONFIG_BT_MCC_READ_PLAYING_ORDER) || defined(CONFIG_BT_MCC_SET_PLAYING_ORDER) 69 uint16_t playing_order_handle; 70 #endif /* defined(CONFIG_BT_MCC_READ_PLAYING_ORDER) || defined(CONFIG_BT_MCC_SET_PLAYING_ORDER) */ 71 #if defined(CONFIG_BT_MCC_READ_PLAYING_ORDER_SUPPORTED) 72 uint16_t playing_orders_supported_handle; 73 #endif /* defined(CONFIG_BT_MCC_READ_PLAYING_ORDER_SUPPORTED) */ 74 #if defined(CONFIG_BT_MCC_READ_MEDIA_STATE) 75 uint16_t media_state_handle; 76 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_STATE) */ 77 uint16_t cp_handle; 78 #if defined(CONFIG_BT_MCC_READ_MEDIA_CONTROL_POINT_OPCODES_SUPPORTED) 79 uint16_t opcodes_supported_handle; 80 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_CONTROL_POINT_OPCODES_SUPPORTED) */ 81 #ifdef CONFIG_BT_MCC_OTS 82 uint16_t scp_handle; 83 uint16_t search_results_obj_id_handle; 84 #endif /* CONFIG_BT_MCC_OTS */ 85 #if defined(CONFIG_BT_MCC_READ_CONTENT_CONTROL_ID) 86 uint16_t content_control_id_handle; 87 #endif /* defined(CONFIG_BT_MCC_READ_CONTENT_CONTROL_ID) */ 88 89 90 /* The write buffer is used for 91 * - track position (4 octets) 92 * - playback speed (1 octet) 93 * - playing order (1 octet) 94 * - the control point (5 octets) 95 * (1 octet opcode + optionally 4 octet param) 96 * (mpl_cmd.opcode + mpl_cmd.param) 97 * If the object transfer client is included, it is also used for 98 * - object IDs (6 octets - BT_OTS_OBJ_ID_SIZE) and 99 * - the search control point (64 octets - SEARCH_LEN_MAX) 100 * 101 * If there is no OTC, the largest is control point 102 * If OTC is included, the largest is the search control point 103 */ 104 #ifdef CONFIG_BT_MCC_OTS 105 char write_buf[SEARCH_LEN_MAX]; 106 #else 107 /* Trick to be able to use sizeof on members of a struct type */ 108 /* TODO: Rewrite the mpl_cmd to have the "use_param" parameter */ 109 /* separately, and the opcode and param alone as a struct */ 110 char write_buf[sizeof(((struct mpl_cmd *)0)->opcode) + 111 sizeof(((struct mpl_cmd *)0)->param)]; 112 #endif /* CONFIG_BT_MCC_OTS */ 113 114 struct bt_gatt_discover_params discover_params; 115 struct bt_gatt_read_params read_params; 116 struct bt_gatt_write_params write_params; 117 118 /** Any fields below here cannot be memset as part of a reset */ 119 120 struct bt_gatt_subscribe_params player_name_sub_params; 121 struct bt_gatt_subscribe_params track_changed_sub_params; 122 #if defined(CONFIG_BT_MCC_READ_TRACK_TITLE_ENABLE_SUBSCRIPTION) 123 struct bt_gatt_subscribe_params track_title_sub_params; 124 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_TITLE_ENABLE_SUBSCRIPTION) */ 125 #if defined(CONFIG_BT_MCC_READ_TRACK_DURATION) 126 struct bt_gatt_subscribe_params track_duration_sub_params; 127 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_DURATION) */ 128 #if defined(CONFIG_BT_MCC_READ_TRACK_POSITION) 129 struct bt_gatt_subscribe_params track_position_sub_params; 130 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_POSITION)*/ 131 #if defined(CONFIG_BT_MCC_READ_PLAYBACK_SPEED) 132 struct bt_gatt_subscribe_params playback_speed_sub_params; 133 #endif /* defined (CONFIG_BT_MCC_READ_PLAYBACK_SPEED) */ 134 #if defined(CONFIG_BT_MCC_READ_SEEKING_SPEED) 135 struct bt_gatt_subscribe_params seeking_speed_sub_params; 136 #endif /* defined (CONFIG_BT_MCC_READ_SEEKING_SPEED) */ 137 #ifdef CONFIG_BT_MCC_OTS 138 struct bt_gatt_subscribe_params current_track_obj_sub_params; 139 struct bt_gatt_subscribe_params next_track_obj_sub_params; 140 struct bt_gatt_subscribe_params parent_group_obj_sub_params; 141 struct bt_gatt_subscribe_params current_group_obj_sub_params; 142 #endif /* CONFIG_BT_MCC_OTS */ 143 #if defined(CONFIG_BT_MCC_READ_PLAYING_ORDER) 144 struct bt_gatt_subscribe_params playing_order_sub_params; 145 #endif /* defined(CONFIG_BT_MCC_READ_PLAYING_ORDER) */ 146 #if defined(CONFIG_BT_MCC_READ_MEDIA_STATE) 147 struct bt_gatt_subscribe_params media_state_sub_params; 148 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_STATE) */ 149 struct bt_gatt_subscribe_params cp_sub_params; 150 #if defined(CONFIG_BT_MCC_READ_MEDIA_CONTROL_POINT_OPCODES_SUPPORTED) 151 struct bt_gatt_subscribe_params opcodes_supported_sub_params; 152 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_CONTROL_POINT_OPCODES_SUPPORTED) */ 153 #ifdef CONFIG_BT_MCC_OTS 154 struct bt_gatt_subscribe_params scp_sub_params; 155 struct bt_gatt_subscribe_params search_results_obj_sub_params; 156 #endif /* CONFIG_BT_MCC_OTS */ 157 158 #ifdef CONFIG_BT_MCC_OTS 159 struct bt_ots_client otc; 160 #endif /* CONFIG_BT_MCC_OTS */ 161 162 ATOMIC_DEFINE(flags, MCC_FLAG_NUM_FLAGS); 163 }; 164 165 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MCP_INTERNAL_ */ 166