1 /*
2  * Copyright 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <bluetooth/log.h>
20 
21 #include <cstdint>
22 #include <string>
23 
24 #include "include/macros.h"
25 
26 enum tBT_PSM : uint16_t {
27   BT_PSM_SDP = 0x0001,
28   BT_PSM_RFCOMM = 0x0003,
29   BT_PSM_TCS = 0x0005,
30   BT_PSM_CTP = 0x0007,
31   BT_PSM_BNEP = 0x000F,
32   BT_PSM_HIDC = 0x0011,
33   HID_PSM_CONTROL = 0x0011,
34   BT_PSM_HIDI = 0x0013,
35   HID_PSM_INTERRUPT = 0x0013,
36   BT_PSM_UPNP = 0x0015,
37   BT_PSM_AVCTP = 0x0017,
38   BT_PSM_AVDTP = 0x0019,
39   BT_PSM_AVCTP_13 = 0x001B, /* Advanced Control - Browsing */
40   BT_PSM_UDI_CP = 0x001D, /* Unrestricted Digital Information Profile C-Plane */
41   BT_PSM_ATT = 0x001F,    /* Attribute Protocol  */
42   BT_PSM_EATT = 0x0027,
43   /* We will not allocate a PSM in the reserved range to 3rd party apps
44    */
45   BRCM_RESERVED_PSM_START = 0x5AE1,
46   BRCM_RESERVED_PSM_END = 0x5AFF,
47 };
48 
bt_psm_text(const tBT_PSM & psm)49 inline std::string bt_psm_text(const tBT_PSM& psm) {
50   switch (psm) {
51     CASE_RETURN_STRING_HEX04(BT_PSM_SDP);
52     CASE_RETURN_STRING_HEX04(BT_PSM_RFCOMM);
53     CASE_RETURN_STRING_HEX04(BT_PSM_TCS);
54     CASE_RETURN_STRING_HEX04(BT_PSM_CTP);
55     CASE_RETURN_STRING_HEX04(BT_PSM_BNEP);
56     CASE_RETURN_STRING_HEX04(BT_PSM_HIDC);
57     CASE_RETURN_STRING_HEX04(BT_PSM_HIDI);
58     CASE_RETURN_STRING_HEX04(BT_PSM_UPNP);
59     CASE_RETURN_STRING_HEX04(BT_PSM_AVCTP);
60     CASE_RETURN_STRING_HEX04(BT_PSM_AVDTP);
61     CASE_RETURN_STRING_HEX04(BT_PSM_AVCTP_13);
62     CASE_RETURN_STRING_HEX04(BT_PSM_UDI_CP);
63     CASE_RETURN_STRING_HEX04(BT_PSM_ATT);
64     CASE_RETURN_STRING_HEX04(BT_PSM_EATT);
65     CASE_RETURN_STRING_HEX04(BRCM_RESERVED_PSM_START);
66     CASE_RETURN_STRING_HEX04(BRCM_RESERVED_PSM_END);
67   };
68   RETURN_UNKNOWN_TYPE_STRING(type, psm);
69 }
70 
71 namespace fmt {
72 template <>
73 struct formatter<tBT_PSM> : enum_formatter<tBT_PSM> {};
74 }  // namespace fmt
75