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