1 /* 2 * Copyright 2020 HIMSA II K/S - www.himsa.com. Represented by EHIMA - 3 * www.ehima.com 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #pragma once 19 20 #include <vector> 21 22 #include "btm_iso_api.h" 23 #include "btm_iso_api_types.h" 24 #include "device_groups.h" 25 #include "devices.h" 26 #include "hardware/bt_le_audio.h" 27 #include "le_audio_types.h" 28 29 namespace bluetooth::le_audio { 30 31 /* State machine interface */ 32 class LeAudioGroupStateMachine { 33 public: 34 class Callbacks { 35 public: 36 virtual ~Callbacks() = default; 37 38 virtual void StatusReportCb( 39 int group_id, bluetooth::le_audio::GroupStreamStatus status) = 0; 40 virtual void OnStateTransitionTimeout(int group_id) = 0; 41 virtual void OnUpdatedCisConfiguration(int group_id, uint8_t direction) = 0; 42 virtual void OnDeviceAutonomousStateTransitionTimeout( 43 LeAudioDevice* leAudioDevice) = 0; 44 }; 45 46 virtual ~LeAudioGroupStateMachine() = default; 47 48 static void Initialize(Callbacks* state_machine_callbacks); 49 static void Cleanup(void); 50 static LeAudioGroupStateMachine* Get(void); 51 52 virtual bool AttachToStream( 53 LeAudioDeviceGroup* group, LeAudioDevice* leAudioDevice, 54 types::BidirectionalPair<std::vector<uint8_t>> ccids) = 0; 55 virtual bool StartStream( 56 LeAudioDeviceGroup* group, types::LeAudioContextType context_type, 57 const types::BidirectionalPair<types::AudioContexts>& 58 metadata_context_types, 59 types::BidirectionalPair<std::vector<uint8_t>> ccid_lists = { 60 .sink = {}, .source = {}}) = 0; 61 virtual void SuspendStream(LeAudioDeviceGroup* group) = 0; 62 virtual bool ConfigureStream( 63 LeAudioDeviceGroup* group, types::LeAudioContextType context_type, 64 const types::BidirectionalPair<types::AudioContexts>& 65 metadata_context_types, 66 types::BidirectionalPair<std::vector<uint8_t>> ccid_lists = { 67 .sink = {}, .source = {}}) = 0; 68 virtual void StopStream(LeAudioDeviceGroup* group) = 0; 69 virtual void ProcessGattCtpNotification(LeAudioDeviceGroup* group, 70 uint8_t* value, uint16_t len) = 0; 71 virtual void ProcessGattNotifEvent(uint8_t* value, uint16_t len, 72 struct types::ase* ase, 73 LeAudioDevice* leAudioDevice, 74 LeAudioDeviceGroup* group) = 0; 75 76 virtual void ProcessHciNotifOnCigCreate( 77 LeAudioDeviceGroup* group, uint8_t status, uint8_t cig_id, 78 std::vector<uint16_t> conn_handles) = 0; 79 virtual void ProcessHciNotifOnCigRemove(uint8_t status, 80 LeAudioDeviceGroup* group) = 0; 81 virtual void ProcessHciNotifCisEstablished( 82 LeAudioDeviceGroup* group, LeAudioDevice* leAudioDevice, 83 const bluetooth::hci::iso_manager::cis_establish_cmpl_evt* event) = 0; 84 virtual void ProcessHciNotifCisDisconnected( 85 LeAudioDeviceGroup* group, LeAudioDevice* leAudioDevice, 86 const bluetooth::hci::iso_manager::cis_disconnected_evt* event) = 0; 87 virtual void ProcessHciNotifSetupIsoDataPath(LeAudioDeviceGroup* group, 88 LeAudioDevice* leAudioDevice, 89 uint8_t status, 90 uint16_t conn_hdl) = 0; 91 virtual void ProcessHciNotifRemoveIsoDataPath(LeAudioDeviceGroup* group, 92 LeAudioDevice* leAudioDevice, 93 uint8_t status, 94 uint16_t conn_hdl) = 0; 95 virtual void ProcessHciNotifIsoLinkQualityRead( 96 LeAudioDeviceGroup* group, LeAudioDevice* leAudioDevice, 97 uint8_t conn_handle, uint32_t txUnackedPackets, uint32_t txFlushedPackets, 98 uint32_t txLastSubeventPackets, uint32_t retransmittedPackets, 99 uint32_t crcErrorPackets, uint32_t rxUnreceivedPackets, 100 uint32_t duplicatePackets) = 0; 101 virtual void ProcessHciNotifAclDisconnected(LeAudioDeviceGroup* group, 102 LeAudioDevice* leAudioDevice) = 0; 103 }; 104 } // namespace bluetooth::le_audio 105