1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <base/strings/stringprintf.h>
#include <cstdint>
#include <string>
/*
* Definitions for HCI Error Codes that are passed in the events
*/
typedef enum : uint8_t {
HCI_SUCCESS = 0x00,
HCI_ERR_ILLEGAL_COMMAND = 0x01,
HCI_ERR_NO_CONNECTION = 0x02,
HCI_ERR_HW_FAILURE = 0x03,
HCI_ERR_PAGE_TIMEOUT = 0x04,
HCI_ERR_AUTH_FAILURE = 0x05,
HCI_ERR_KEY_MISSING = 0x06,
HCI_ERR_MEMORY_FULL = 0x07,
HCI_ERR_CONNECTION_TOUT = 0x08,
HCI_ERR_MAX_NUM_OF_CONNECTIONS = 0x09,
HCI_ERR_MAX_NUM_OF_SCOS = 0x0A,
HCI_ERR_CONNECTION_EXISTS = 0x0B,
HCI_ERR_COMMAND_DISALLOWED = 0x0C,
HCI_ERR_HOST_REJECT_RESOURCES = 0x0D,
HCI_ERR_HOST_REJECT_SECURITY = 0x0E,
HCI_ERR_HOST_REJECT_DEVICE = 0x0F,
HCI_ERR_HOST_TIMEOUT = 0x10, // stack/btm/btm_ble_gap,
HCI_ERR_ILLEGAL_PARAMETER_FMT = 0x12,
HCI_ERR_PEER_USER = 0x13,
HCI_ERR_CONN_CAUSE_LOCAL_HOST = 0x16,
HCI_ERR_REPEATED_ATTEMPTS = 0x17,
HCI_ERR_PAIRING_NOT_ALLOWED = 0x18,
HCI_ERR_UNSUPPORTED_REM_FEATURE = 0x1A, // stack/btm/btm_ble_gap
HCI_ERR_UNSPECIFIED = 0x1F,
HCI_ERR_LMP_RESPONSE_TIMEOUT = 0x22, // GATT_CONN_LMP_TIMEOUT
HCI_ERR_LMP_ERR_TRANS_COLLISION = 0x23, // TODO remove
HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE = 0x25,
HCI_ERR_UNIT_KEY_USED = 0x26,
HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED = 0x29,
HCI_ERR_DIFF_TRANSACTION_COLLISION = 0x2A, // stack/btm/btm_sec
HCI_ERR_INSUFFCIENT_SECURITY = 0x2F, // btif/btu
HCI_ERR_ROLE_SWITCH_PENDING = 0x32, // stack/btm/btm_sco
HCI_ERR_ROLE_SWITCH_FAILED = 0x35,
HCI_ERR_HOST_BUSY_PAIRING = 0x38, // stack/btm/btm_sec
HCI_ERR_UNACCEPT_CONN_INTERVAL = 0x3B, // stack/l2cap/l2c_ble
HCI_ERR_ADVERTISING_TIMEOUT = 0x3C, // stack/btm/btm_ble
HCI_ERR_CONN_FAILED_ESTABLISHMENT = 0x3E, // GATT_CONN_FAIL_ESTABLISH
HCI_ERR_LIMIT_REACHED = 0x43, // stack/btm/btm_ble_multi_adv.cc
_HCI_ERR_MAX_ERR = 0x43,
HCI_ERR_UNDEFINED = 0xff,
} tHCI_ERROR_CODE;
#define HCI_ERR_MAX_ERR _HCI_ERR_MAX_ERR // HACK for now for SMP
inline std::string hci_error_code_text(const tHCI_ERROR_CODE& error_code) {
switch (error_code) {
case HCI_SUCCESS:
return std::string("Success");
case HCI_ERR_ILLEGAL_COMMAND:
return std::string("Illegal Command");
case HCI_ERR_NO_CONNECTION:
return std::string("Unknown Connection");
case HCI_ERR_HW_FAILURE:
return std::string("Hardware Failure");
case HCI_ERR_PAGE_TIMEOUT:
return std::string("Page Timeout");
case HCI_ERR_AUTH_FAILURE:
return std::string("Authentication Failure");
case HCI_ERR_KEY_MISSING:
return std::string("Pin or Key Missing");
case HCI_ERR_MEMORY_FULL:
return std::string("Memory Capacity Exceeded");
case HCI_ERR_CONNECTION_TOUT:
return std::string("Connection Timeout");
case HCI_ERR_MAX_NUM_OF_CONNECTIONS:
return std::string("Connection Limit Exceeded");
case HCI_ERR_MAX_NUM_OF_SCOS:
return std::string("Synchronous Connection Limit Exceeded");
case HCI_ERR_CONNECTION_EXISTS:
return std::string("Connection Already Exists");
case HCI_ERR_COMMAND_DISALLOWED:
return std::string("Command Disallowed");
case HCI_ERR_HOST_REJECT_RESOURCES:
return std::string("Connection Rejected Limited Resources");
case HCI_ERR_HOST_REJECT_SECURITY:
return std::string("Connection Rejected Security Reasons");
case HCI_ERR_HOST_REJECT_DEVICE:
return std::string("Connection Rejected Unacceptable BdAddr");
case HCI_ERR_HOST_TIMEOUT:
return std::string("Connection Accept Timeout");
case HCI_ERR_ILLEGAL_PARAMETER_FMT:
return std::string("Unsupported Feature or Parameter Value");
case HCI_ERR_PEER_USER:
return std::string("Remote Terminated Connection");
case HCI_ERR_CONN_CAUSE_LOCAL_HOST:
return std::string("Local Terminated Connection");
case HCI_ERR_REPEATED_ATTEMPTS:
return std::string("Repeated Attempts");
case HCI_ERR_PAIRING_NOT_ALLOWED:
return std::string("Pairing not Allowed");
case HCI_ERR_UNSUPPORTED_REM_FEATURE:
return std::string("Unsupported Remote or Lmp Feature");
case HCI_ERR_UNSPECIFIED:
return std::string("Unspecified Error");
case HCI_ERR_LMP_RESPONSE_TIMEOUT:
return std::string("Gatt Connection Lmp Timeout");
case HCI_ERR_LMP_ERR_TRANS_COLLISION:
return std::string("Link Layer Collision");
case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
return std::string("Encryption Mode not Acceptable");
case HCI_ERR_UNIT_KEY_USED:
return std::string("Unit Key Used");
case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
return std::string("Pairing with Unit Key Unsupported");
case HCI_ERR_DIFF_TRANSACTION_COLLISION:
return std::string("Diff Transaction Collision");
case HCI_ERR_INSUFFCIENT_SECURITY:
return std::string("Insufficient Security");
case HCI_ERR_ROLE_SWITCH_PENDING:
return std::string("Role Switch Pending");
case HCI_ERR_HOST_BUSY_PAIRING:
return std::string("Host Busy Pairing");
case HCI_ERR_UNACCEPT_CONN_INTERVAL:
return std::string("Unacceptable Connection Interval");
case HCI_ERR_ADVERTISING_TIMEOUT:
return std::string("Advertising Timeout");
case HCI_ERR_CONN_FAILED_ESTABLISHMENT:
return std::string("Connection Failed Establishment");
case HCI_ERR_LIMIT_REACHED:
return std::string("Limit Reached");
default:
return base::StringPrintf("Unknown Error[%02hx]", error_code);
}
}
// Context equivalence
using tHCI_STATUS = tHCI_ERROR_CODE;
inline std::string hci_status_code_text(const tHCI_STATUS& status_code) {
return hci_error_code_text(status_code);
}
using tHCI_REASON = tHCI_ERROR_CODE;
inline std::string hci_reason_code_text(const tHCI_REASON& reason_code) {
return hci_error_code_text(reason_code);
}
// Conversion from raw packet value
inline tHCI_ERROR_CODE to_hci_error_code(const uint8_t& error_code) {
if (error_code > _HCI_ERR_MAX_ERR) return HCI_ERR_UNDEFINED;
return static_cast<tHCI_ERROR_CODE>(error_code);
}
inline tHCI_STATUS to_hci_status_code(const uint8_t& status_code) {
if (status_code > _HCI_ERR_MAX_ERR) return HCI_ERR_UNDEFINED;
return static_cast<tHCI_STATUS>(status_code);
}
inline tHCI_REASON to_hci_reason_code(const uint8_t& reason_code) {
if (reason_code > _HCI_ERR_MAX_ERR) return HCI_ERR_UNDEFINED;
return static_cast<tHCI_REASON>(reason_code);
}
|