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_ERR_KEY_MISSING, /* 22 Handle for Pin or Key Missing */
48 BTM_MAX_STATUS_VALUE = BTM_DEV_RESTRICT_LISTED,
49 BTM_UNDEFINED = 0xFF,
50 };
51 typedef uint8_t tBTM_STATUS;
52
btm_status_value(const tBTM_STATUS & status)53 inline uint8_t btm_status_value(const tBTM_STATUS& status) {
54 return static_cast<uint8_t>(status);
55 }
56
to_btm_status(const uint8_t & value)57 inline tBTM_STATUS to_btm_status(const uint8_t& value) {
58 if (value > BTM_MAX_STATUS_VALUE) return BTM_UNDEFINED;
59 return static_cast<tBTM_STATUS>(value);
60 }
61
62 #define CASE_RETURN_TEXT(code) \
63 case code: \
64 return #code
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(BTM_SUCCESS);
69 CASE_RETURN_TEXT(BTM_CMD_STARTED);
70 CASE_RETURN_TEXT(BTM_BUSY);
71 CASE_RETURN_TEXT(BTM_NO_RESOURCES);
72 CASE_RETURN_TEXT(BTM_MODE_UNSUPPORTED);
73 CASE_RETURN_TEXT(BTM_ILLEGAL_VALUE);
74 CASE_RETURN_TEXT(BTM_WRONG_MODE);
75 CASE_RETURN_TEXT(BTM_UNKNOWN_ADDR);
76 CASE_RETURN_TEXT(BTM_DEVICE_TIMEOUT);
77 CASE_RETURN_TEXT(BTM_BAD_VALUE_RET);
78 CASE_RETURN_TEXT(BTM_ERR_PROCESSING);
79 CASE_RETURN_TEXT(BTM_NOT_AUTHORIZED);
80 CASE_RETURN_TEXT(BTM_DEV_RESET);
81 CASE_RETURN_TEXT(BTM_CMD_STORED);
82 CASE_RETURN_TEXT(BTM_ILLEGAL_ACTION);
83 CASE_RETURN_TEXT(BTM_DELAY_CHECK);
84 CASE_RETURN_TEXT(BTM_SCO_BAD_LENGTH);
85 CASE_RETURN_TEXT(BTM_SUCCESS_NO_SECURITY);
86 CASE_RETURN_TEXT(BTM_FAILED_ON_SECURITY);
87 CASE_RETURN_TEXT(BTM_REPEATED_ATTEMPTS);
88 CASE_RETURN_TEXT(BTM_MODE4_LEVEL4_NOT_SUPPORTED);
89 CASE_RETURN_TEXT(BTM_DEV_RESTRICT_LISTED);
90 CASE_RETURN_TEXT(BTM_ERR_KEY_MISSING);
91 default:
92 return base::StringPrintf("UNKNOWN[%hhu]", status);
93 }
94 }
95
96 #undef CASE_RETURN_TEXT
97