1 /******************************************************************************
2 *
3 * Copyright 1999-2012 Broadcom Corporation
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 <base/strings/stringprintf.h>
22
23 #include <cstdint>
24
25 /* pairing failure reason code */
26 typedef enum : uint8_t {
27 SMP_SUCCESS = 0,
28 SMP_PASSKEY_ENTRY_FAIL = 0x01,
29 SMP_OOB_FAIL = 0x02,
30 SMP_PAIR_AUTH_FAIL = 0x03,
31 SMP_CONFIRM_VALUE_ERR = 0x04,
32 SMP_PAIR_NOT_SUPPORT = 0x05,
33 SMP_ENC_KEY_SIZE = 0x06,
34 SMP_INVALID_CMD = 0x07,
35 SMP_PAIR_FAIL_UNKNOWN = 0x08,
36 SMP_REPEATED_ATTEMPTS = 0x09,
37 SMP_INVALID_PARAMETERS = 0x0A,
38 SMP_DHKEY_CHK_FAIL = 0x0B,
39 SMP_NUMERIC_COMPAR_FAIL = 0x0C,
40 SMP_BR_PARING_IN_PROGR = 0x0D,
41 SMP_XTRANS_DERIVE_NOT_ALLOW = 0x0E,
42 SMP_MAX_FAIL_RSN_PER_SPEC = SMP_XTRANS_DERIVE_NOT_ALLOW,
43
44 /* self defined error code */
45 SMP_PAIR_INTERNAL_ERR = (SMP_MAX_FAIL_RSN_PER_SPEC + 0x01), /* 0x0F */
46
47 /* Unknown IO capability, unable to decide association model */
48 SMP_UNKNOWN_IO_CAP = (SMP_MAX_FAIL_RSN_PER_SPEC + 0x02), /* 0x10 */
49
50 SMP_BUSY = (SMP_MAX_FAIL_RSN_PER_SPEC + 0x05), /* 0x13 */
51 SMP_ENC_FAIL = (SMP_MAX_FAIL_RSN_PER_SPEC + 0x06), /* 0x14 */
52 SMP_STARTED = (SMP_MAX_FAIL_RSN_PER_SPEC + 0x07), /* 0x15 */
53 SMP_RSP_TIMEOUT = (SMP_MAX_FAIL_RSN_PER_SPEC + 0x08), /* 0x16 */
54
55 /* Unspecified failure reason */
56 SMP_FAIL = (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0A), /* 0x18 */
57
58 SMP_CONN_TOUT = (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0B), /* 0x19 */
59 } tSMP_STATUS;
60
61 #ifndef CASE_RETURN_TEXT
62 #define CASE_RETURN_TEXT(code) \
63 case code: \
64 return #code
65 #endif
66
smp_status_text(const tSMP_STATUS & status)67 inline std::string smp_status_text(const tSMP_STATUS& status) {
68 switch (status) {
69 CASE_RETURN_TEXT(SMP_SUCCESS);
70 CASE_RETURN_TEXT(SMP_PASSKEY_ENTRY_FAIL);
71 CASE_RETURN_TEXT(SMP_OOB_FAIL);
72 CASE_RETURN_TEXT(SMP_PAIR_AUTH_FAIL);
73 CASE_RETURN_TEXT(SMP_CONFIRM_VALUE_ERR);
74 CASE_RETURN_TEXT(SMP_PAIR_NOT_SUPPORT);
75 CASE_RETURN_TEXT(SMP_ENC_KEY_SIZE);
76 CASE_RETURN_TEXT(SMP_INVALID_CMD);
77 CASE_RETURN_TEXT(SMP_PAIR_FAIL_UNKNOWN);
78 CASE_RETURN_TEXT(SMP_REPEATED_ATTEMPTS);
79 CASE_RETURN_TEXT(SMP_INVALID_PARAMETERS);
80 CASE_RETURN_TEXT(SMP_DHKEY_CHK_FAIL);
81 CASE_RETURN_TEXT(SMP_NUMERIC_COMPAR_FAIL);
82 CASE_RETURN_TEXT(SMP_BR_PARING_IN_PROGR);
83 CASE_RETURN_TEXT(SMP_XTRANS_DERIVE_NOT_ALLOW);
84 CASE_RETURN_TEXT(SMP_PAIR_INTERNAL_ERR);
85 CASE_RETURN_TEXT(SMP_UNKNOWN_IO_CAP);
86 CASE_RETURN_TEXT(SMP_BUSY);
87 CASE_RETURN_TEXT(SMP_ENC_FAIL);
88 CASE_RETURN_TEXT(SMP_STARTED);
89 CASE_RETURN_TEXT(SMP_RSP_TIMEOUT);
90 CASE_RETURN_TEXT(SMP_FAIL);
91 CASE_RETURN_TEXT(SMP_CONN_TOUT);
92 default:
93 return base::StringPrintf("UNKNOWN[%hhu]", status);
94 }
95 }
96 #undef CASE_RETURN_TEXT
97