1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bluetooth_hci_callbacks.h"
17 #include "cstdint"
18 
OnInited(BtStatus status)19 NO_SANITIZE("cfi") int32_t BluetoothHciCallbacks::OnInited(BtStatus status)
20 {
21     if ((callbacks_ != nullptr) && (callbacks_->OnInited)) {
22         BtInitStatus initStatus = BtInitStatus::SUCCESS;
23         if (status != BtStatus::SUCCESS) {
24             initStatus = BtInitStatus::INITIALIZATION_ERROR;
25         }
26         callbacks_->OnInited(initStatus);
27     }
28     return 0;
29 }
30 
OnReceivedHciPacket(BtType type,const std::vector<uint8_t> & data)31 NO_SANITIZE("cfi") int32_t BluetoothHciCallbacks::OnReceivedHciPacket(BtType type, const std::vector<uint8_t> &data)
32 {
33     if ((callbacks_ != nullptr) && (callbacks_->OnReceivedHciPacket)) {
34         BtPacketType packetType = BtPacketType::PACKET_TYPE_UNKNOWN;
35         switch (type) {
36             case BtType::HCI_EVENT:
37                 packetType = BtPacketType::PACKET_TYPE_EVENT;
38                 break;
39             case BtType::ACL_DATA:
40                 packetType = BtPacketType::PACKET_TYPE_ACL;
41                 break;
42             case BtType::SCO_DATA:
43                 packetType = BtPacketType::PACKET_TYPE_SCO;
44                 break;
45             default:
46                 break;
47         }
48         BtPacket packet = {
49             .data = (data.size() ? (uint8_t *)&data[0] : nullptr),
50             .size = data.size(),
51         };
52         callbacks_->OnReceivedHciPacket(packetType, &packet);
53     }
54     return 0;
55 }
56