1 /******************************************************************************
2  *
3  *  Copyright (C) 2022 The Android Open Source Project
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 
19 #pragma once
20 
21 #include <inttypes.h>
22 
23 namespace bluetooth {
24 namespace hal {
25 
26 #define HCI_OP_NOP 0x0000
27 
28 #define MGMT_EV_SIZE_MAX 1024
29 #define MGMT_PKT_HDR_SIZE 6
30 struct mgmt_pkt {
31   uint16_t opcode;
32   uint16_t index;
33   uint16_t len;
34   uint8_t data[MGMT_EV_SIZE_MAX];
35 } __attribute__((packed));
36 
37 #define MGMT_EV_COMMAND_COMPLETE 0x1
38 struct mgmt_ev_cmd_complete {
39   uint16_t opcode;
40   uint8_t status;
41   uint8_t data[];
42 } __attribute__((packed));
43 
44 #define MGMT_OP_GET_VS_OPCODE 0x0102
45 #define MGMT_VS_OPCODE_MSFT 0x0001
46 struct mgmt_cp_get_vs_opcode {
47   uint16_t hci_id;
48   uint16_t vendor_specification;
49 } __attribute__((packed));
50 
51 struct mgmt_rp_get_vs_opcode {
52   uint16_t hci_id;
53   uint16_t opcode;
54 } __attribute__((packed));
55 
56 #define MGMT_POLL_TIMEOUT_MS 2000
57 
58 // This class provides an interface to interact with the kernel.
59 class Mgmt {
60  public:
61   uint16_t get_vs_opcode(uint16_t vendor_specification);
62 };
63 
64 }  // namespace hal
65 }  // namespace bluetooth
66