1 /*
2 * Copyright 2020 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 <cstdint>
20
21 #include "macros.h"
22
23 /* BTM application return status codes */
24 enum class tBTM_STATUS : uint8_t {
25 BTM_SUCCESS = 0, /* 0 Command succeeded */
26 BTM_CMD_STARTED, /* 1 Command started OK. */
27 BTM_BUSY, /* 2 Device busy with another command */
28 BTM_NO_RESOURCES, /* 3 No resources to issue command */
29 BTM_MODE_UNSUPPORTED, /* 4 Request for 1 or more unsupported modes */
30 BTM_ILLEGAL_VALUE, /* 5 Illegal parameter value */
31 BTM_WRONG_MODE, /* 6 Device in wrong mode for request */
32 BTM_UNKNOWN_ADDR, /* 7 Unknown remote BD address */
33 BTM_DEVICE_TIMEOUT, /* 8 Device timeout */
34 BTM_BAD_VALUE_RET, /* 9 A bad value was received from HCI */
35 BTM_ERR_PROCESSING, /* 10 Generic error */
36 BTM_NOT_AUTHORIZED, /* 11 Authorization failed */
37 BTM_DEV_RESET, /* 12 Device has been reset */
38 BTM_CMD_STORED, /* 13 request is stored in control block */
39 BTM_ILLEGAL_ACTION, /* 14 state machine gets illegal command */
40 BTM_DELAY_CHECK, /* 15 delay the check on encryption */
41 BTM_SCO_BAD_LENGTH, /* 16 Bad SCO over HCI data length */
42 BTM_SUCCESS_NO_SECURITY, /* 17 security passed, no security set */
43 BTM_FAILED_ON_SECURITY, /* 18 security failed */
44 BTM_REPEATED_ATTEMPTS, /* 19 repeated attempts for LE security requests */
45 BTM_MODE4_LEVEL4_NOT_SUPPORTED, /* 20 Secure Connections Only Mode can't be
46 supported */
47 BTM_DEV_RESTRICT_LISTED, /* 21 The device is restrict listed */
48 BTM_ERR_KEY_MISSING, /* 22 Handle for Pin or Key Missing */
49 BTM_NOT_AUTHENTICATED, /* 23 the link is not authenticated */
50 BTM_NOT_ENCRYPTED, /* 24 the link is not encrypted */
51 BTM_INSUFFICIENT_ENCRYPT_KEY_SIZE, /* 25 the encrypt key size not sufficient
52 */
53 BTM_MAX_STATUS_VALUE,
54 BTM_UNDEFINED = 0xFF,
55 };
56
btm_status_value(const tBTM_STATUS & status)57 inline uint8_t btm_status_value(const tBTM_STATUS& status) { return static_cast<uint8_t>(status); }
58
to_btm_status(const uint8_t & value)59 inline tBTM_STATUS to_btm_status(const uint8_t& value) {
60 if (value >= static_cast<unsigned>(tBTM_STATUS::BTM_MAX_STATUS_VALUE)) {
61 return tBTM_STATUS::BTM_UNDEFINED;
62 }
63 return static_cast<tBTM_STATUS>(value);
64 }
65
btm_status_text(const tBTM_STATUS & status)66 inline std::string btm_status_text(const tBTM_STATUS& status) {
67 switch (status) {
68 CASE_RETURN_TEXT(tBTM_STATUS::BTM_SUCCESS);
69 CASE_RETURN_TEXT(tBTM_STATUS::BTM_CMD_STARTED);
70 CASE_RETURN_TEXT(tBTM_STATUS::BTM_BUSY);
71 CASE_RETURN_TEXT(tBTM_STATUS::BTM_NO_RESOURCES);
72 CASE_RETURN_TEXT(tBTM_STATUS::BTM_MODE_UNSUPPORTED);
73 CASE_RETURN_TEXT(tBTM_STATUS::BTM_ILLEGAL_VALUE);
74 CASE_RETURN_TEXT(tBTM_STATUS::BTM_WRONG_MODE);
75 CASE_RETURN_TEXT(tBTM_STATUS::BTM_UNKNOWN_ADDR);
76 CASE_RETURN_TEXT(tBTM_STATUS::BTM_DEVICE_TIMEOUT);
77 CASE_RETURN_TEXT(tBTM_STATUS::BTM_BAD_VALUE_RET);
78 CASE_RETURN_TEXT(tBTM_STATUS::BTM_ERR_PROCESSING);
79 CASE_RETURN_TEXT(tBTM_STATUS::BTM_NOT_AUTHORIZED);
80 CASE_RETURN_TEXT(tBTM_STATUS::BTM_DEV_RESET);
81 CASE_RETURN_TEXT(tBTM_STATUS::BTM_CMD_STORED);
82 CASE_RETURN_TEXT(tBTM_STATUS::BTM_ILLEGAL_ACTION);
83 CASE_RETURN_TEXT(tBTM_STATUS::BTM_DELAY_CHECK);
84 CASE_RETURN_TEXT(tBTM_STATUS::BTM_SCO_BAD_LENGTH);
85 CASE_RETURN_TEXT(tBTM_STATUS::BTM_SUCCESS_NO_SECURITY);
86 CASE_RETURN_TEXT(tBTM_STATUS::BTM_FAILED_ON_SECURITY);
87 CASE_RETURN_TEXT(tBTM_STATUS::BTM_REPEATED_ATTEMPTS);
88 CASE_RETURN_TEXT(tBTM_STATUS::BTM_MODE4_LEVEL4_NOT_SUPPORTED);
89 CASE_RETURN_TEXT(tBTM_STATUS::BTM_DEV_RESTRICT_LISTED);
90 CASE_RETURN_TEXT(tBTM_STATUS::BTM_ERR_KEY_MISSING);
91 CASE_RETURN_TEXT(tBTM_STATUS::BTM_NOT_AUTHENTICATED);
92 CASE_RETURN_TEXT(tBTM_STATUS::BTM_NOT_ENCRYPTED);
93 CASE_RETURN_TEXT(tBTM_STATUS::BTM_INSUFFICIENT_ENCRYPT_KEY_SIZE);
94 default:
95 return std::format("UNKNOWN[{}]", static_cast<uint8_t>(status));
96 }
97 }
98
99 namespace std {
100 template <>
101 struct formatter<tBTM_STATUS> : enum_formatter<tBTM_STATUS> {};
102 } // namespace std
103