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