1# -*- coding: utf-8 -*-
2import struct;
3from enum import IntEnum;
4from components.address import *;
5
6class Events(IntEnum):
7    BT_HCI_EVT_DISCONN_COMPLETE             = 5
8    BT_HCI_EVT_ENCRYPT_CHANGE_V1            = 8
9    BT_HCI_EVT_REMOTE_VERSION_INFO          = 12
10    BT_HCI_EVT_CMD_COMPLETE                 = 14
11    BT_HCI_EVT_CMD_STATUS                   = 15
12    BT_HCI_EVT_HARDWARE_ERROR               = 16
13    BT_HCI_EVT_NUM_COMPLETED_PACKETS        = 19
14    BT_HCI_EVT_DATA_BUF_OVERFLOW            = 26
15    BT_HCI_EVT_ENCRYPT_KEY_REFRESH_COMPLETE = 48
16    BT_HCI_EVT_LE_META_EVENT                = 62
17    BT_HCI_EVT_AUTH_PAYLOAD_TIMEOUT_EXP     = 87
18    BT_HCI_EVT_ENCRYPT_CHANGE_V2            = 89
19
20
21class MetaEvents(IntEnum):
22    BT_HCI_EVT_LE_CONN_COMPLETE             = 1
23    BT_HCI_EVT_LE_ADVERTISING_REPORT        = 2
24    BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE      = 3
25    BT_HCI_EVT_LE_REMOTE_FEAT_COMPLETE      = 4
26    BT_HCI_EVT_LE_LTK_REQUEST               = 5
27    BT_HCI_EVT_LE_CONN_PARAM_REQ            = 6
28    BT_HCI_EVT_LE_DATA_LEN_CHANGE           = 7
29    BT_HCI_EVT_LE_P256_PUBLIC_KEY_COMPLETE  = 8
30    BT_HCI_EVT_LE_GENERATE_DHKEY_COMPLETE   = 9
31    BT_HCI_EVT_LE_ENH_CONN_COMPLETE         = 10
32    BT_HCI_EVT_LE_DIRECT_ADV_REPORT         = 11
33    BT_HCI_EVT_LE_PHY_UPDATE_COMPLETE       = 12
34    BT_HCI_EVT_LE_EXT_ADVERTISING_REPORT    = 13
35    BT_HCI_EVT_LE_PER_ADV_SYNC_ESTABLISHED  = 14
36    BT_HCI_EVT_LE_PER_ADVERTISING_REPORT    = 15
37    BT_HCI_EVT_LE_PER_ADV_SYNC_LOST         = 16
38    BT_HCI_EVT_LE_SCAN_TIMEOUT              = 17
39    BT_HCI_EVT_LE_ADV_SET_TERMINATED        = 18
40    BT_HCI_EVT_LE_SCAN_REQ_RECEIVED         = 19
41    BT_HCI_EVT_LE_CHAN_SEL_ALGO             = 20
42    BT_HCI_EVT_LE_CIS_ESTABLISHED           = 25
43    BT_HCI_EVT_LE_CIS_REQUEST               = 26
44    BT_HCI_EVT_LE_REQUEST_PEER_SCA_COMPLETE = 31
45
46class CmdOpcodes(IntEnum):
47    BT_HCI_OP_INQUIRY                       = 0x0401
48    BT_HCI_OP_DISCONNECT                    = 0x0406
49    BT_HCI_OP_READ_REMOTE_VERSION_INFO      = 0x041D
50    BT_HCI_OP_SET_EVENT_MASK                = 0x0C01
51    BT_HCI_OP_RESET                         = 0x0C03
52    BT_HCI_OP_READ_TX_POWER_LEVEL           = 0x0C2D
53    BT_HCI_OP_SET_CTL_TO_HOST_FLOW          = 0x0C31
54    BT_HCI_OP_HOST_BUFFER_SIZE              = 0x0C33
55    BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS    = 0x0C35
56    BT_HCI_OP_SET_EVENT_MASK_PAGE_2         = 0x0C63
57    BT_HCI_OP_LE_READ_LE_HOST_SUPP          = 0x0C6C
58    BT_HCI_OP_LE_WRITE_LE_HOST_SUPP         = 0x0C6D
59    BT_HCI_OP_READ_AUTH_PAYLOAD_TIMEOUT     = 0x0C7B
60    BT_HCI_OP_WRITE_AUTH_PAYLOAD_TIMEOUT    = 0x0C7C
61    BT_HCI_OP_READ_LOCAL_VERSION_INFO       = 0x1001
62    BT_HCI_OP_READ_SUPPORTED_COMMANDS       = 0x1002
63    BT_HCI_OP_READ_LOCAL_FEATURES           = 0x1003
64    BT_HCI_OP_READ_BUFFER_SIZE              = 0x1005
65    BT_HCI_OP_READ_BD_ADDR                  = 0x1009
66    BT_HCI_OP_READ_RSSI                     = 0x1405
67    BT_HCI_OP_LE_SET_EVENT_MASK             = 0x2001
68    BT_HCI_OP_LE_READ_BUFFER_SIZE           = 0x2002
69    BT_HCI_OP_LE_READ_LOCAL_FEATURES        = 0x2003
70    BT_HCI_OP_LE_SET_RANDOM_ADDRESS         = 0x2005
71    BT_HCI_OP_LE_SET_ADV_PARAM              = 0x2006
72    BT_HCI_OP_LE_READ_ADV_CHAN_TX_POWER     = 0x2007
73    BT_HCI_OP_LE_SET_ADV_DATA               = 0x2008
74    BT_HCI_OP_LE_SET_SCAN_RSP_DATA          = 0x2009
75    BT_HCI_OP_LE_SET_ADV_ENABLE             = 0x200A
76    BT_HCI_OP_LE_SET_SCAN_PARAM             = 0x200B
77    BT_HCI_OP_LE_SET_SCAN_ENABLE            = 0x200C
78    BT_HCI_OP_LE_CREATE_CONN                = 0x200D
79    BT_HCI_OP_LE_CREATE_CONN_CANCEL         = 0x200E
80    BT_HCI_OP_LE_READ_FAL_SIZE               = 0x200F
81    BT_HCI_OP_LE_CLEAR_FAL                   = 0x2010
82    BT_HCI_OP_LE_ADD_DEV_TO_FAL              = 0x2011
83    BT_HCI_OP_LE_REM_DEV_FROM_FAL            = 0x2012
84    BT_HCI_OP_LE_CONN_UPDATE                = 0x2013
85    BT_HCI_OP_LE_SET_HOST_CHAN_CLASSIF      = 0x2014
86    BT_HCI_OP_LE_READ_CHAN_MAP              = 0x2015
87    BT_HCI_OP_LE_READ_REMOTE_FEATURES       = 0x2016
88    BT_HCI_OP_LE_ENCRYPT                    = 0x2017
89    BT_HCI_OP_LE_RAND                       = 0x2018
90    BT_HCI_OP_LE_START_ENCRYPTION           = 0x2019
91    BT_HCI_OP_LE_LTK_REQ_REPLY              = 0x201A
92    BT_HCI_OP_LE_LTK_REQ_NEG_REPLY          = 0x201B
93    BT_HCI_OP_LE_READ_SUPP_STATES           = 0x201C
94    BT_HCI_OP_LE_RX_TEST                    = 0x201D
95    BT_HCI_OP_LE_TX_TEST                    = 0x201E
96    BT_HCI_OP_LE_TEST_END                   = 0x201F
97    BT_HCI_OP_LE_CONN_PARAM_REQ_REPLY       = 0x2020
98    BT_HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY   = 0x2021
99    BT_HCI_OP_LE_SET_DATA_LEN               = 0x2022
100    BT_HCI_OP_LE_READ_DEFAULT_DATA_LEN      = 0x2023
101    BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN     = 0x2024
102    BT_HCI_OP_LE_P256_PUBLIC_KEY            = 0x2025
103    BT_HCI_OP_LE_GENERATE_DHKEY             = 0x2026
104    BT_HCI_OP_LE_ADD_DEV_TO_RL              = 0x2027
105    BT_HCI_OP_LE_REM_DEV_FROM_RL            = 0x2028
106    BT_HCI_OP_LE_CLEAR_RL                   = 0x2029
107    BT_HCI_OP_LE_READ_RL_SIZE               = 0x202A
108    BT_HCI_OP_LE_READ_PEER_RPA              = 0x202B
109    BT_HCI_OP_LE_READ_LOCAL_RPA             = 0x202C
110    BT_HCI_OP_LE_SET_ADDR_RES_ENABLE        = 0x202D
111    BT_HCI_OP_LE_SET_RPA_TIMEOUT            = 0x202E
112    BT_HCI_OP_LE_READ_MAX_DATA_LEN          = 0x202F
113    BT_HCI_OP_LE_READ_PHY                   = 0x2030
114    BT_HCI_OP_LE_SET_DEFAULT_PHY            = 0x2031
115    BT_HCI_OP_LE_SET_PHY                    = 0x2032
116    BT_HCI_OP_LE_ENH_RX_TEST                = 0x2033
117    BT_HCI_OP_LE_ENH_TX_TEST                = 0x2034
118    BT_HCI_OP_LE_SET_EXT_ADV_PARAM          = 0x2036
119    BT_HCI_OP_LE_SET_EXT_ADV_DATA           = 0x2037
120    BT_HCI_OP_LE_SET_EXT_SCAN_RSP_DATA      = 0x2038
121    BT_HCI_OP_LE_SET_EXT_ADV_ENABLE         = 0x2039
122    BT_HCI_OP_LE_READ_MAX_ADV_DATA_LEN      = 0x203A
123    BT_HCI_OP_LE_READ_NUM_ADV_SETS          = 0x203B
124    BT_HCI_OP_LE_REMOVE_ADV_SET             = 0x203C
125    BT_HCI_OP_CLEAR_ADV_SETS                = 0x203D
126    BT_HCI_OP_LE_SET_PER_ADV_PARAM          = 0x203E
127    BT_HCI_OP_LE_SET_PER_ADV_DATA           = 0x203F
128    BT_HCI_OP_LE_SET_PER_ADV_ENABLE         = 0x2040
129    BT_HCI_OP_LE_SET_EXT_SCAN_PARAM         = 0x2041
130    BT_HCI_OP_LE_SET_EXT_SCAN_ENABLE        = 0x2042
131    BT_HCI_OP_LE_EXT_CREATE_CONN            = 0x2043
132    BT_HCI_OP_LE_PER_ADV_CREATE_SYNC        = 0x2044
133    BT_HCI_OP_LE_PER_ADV_CREATE_SYNC_CANCEL = 0x2045
134    BT_HCI_OP_LE_PER_ADV_TERMINATE_SYNC     = 0x2046
135    BT_HCI_OP_LE_ADD_DEV_TO_PER_ADV_LIST    = 0x2047
136    BT_HCI_OP_LE_REM_DEV_FROM_PER_ADV_LIST  = 0x2048
137    BT_HCI_OP_LE_CLEAR_PER_ADV_LIST         = 0x2049
138    BT_HCI_OP_LE_READ_PER_ADV_LIST_SIZE     = 0x204A
139    BT_HCI_OP_LE_READ_TX_POWER              = 0x204B
140    BT_HCI_OP_LE_READ_RF_PATH_COMP          = 0x204C
141    BT_HCI_OP_LE_WRITE_RF_PATH_COMP         = 0x204D
142    BT_HCI_OP_LE_SET_PRIVACY_MODE           = 0x204E
143    BT_HCI_OP_LE_READ_BUFFER_SIZE_V2        = 0x2060
144    BT_HCI_OP_LE_SET_CIG_PARAMETERS         = 0x2062
145    BT_HCI_OP_LE_SET_CIG_PARAMETERS_TEST    = 0x2063
146    BT_HCI_OP_LE_CREATE_CIS                 = 0x2064
147    BT_HCI_OP_LE_REMOVE_CIG                 = 0x2065
148    BT_HCI_OP_LE_ACCEPT_CIS_REQUEST         = 0x2066
149    BT_HCI_OP_LE_REJECT_CIS_REQUEST         = 0x2067
150    BT_HCI_OP_LE_REQUEST_PEER_SCA           = 0x206D
151    BT_HCI_OP_LE_SETUP_ISO_DATA_PATH        = 0x206E
152    BT_HCI_OP_LE_REMOVE_ISO_DATA_PATH       = 0x206F
153    BT_HCI_OP_LE_ISO_TRANSMIT_TEST          = 0x2070
154    BT_HCI_OP_LE_ISO_RECEIVE_TEST           = 0x2071
155    BT_HCI_OP_LE_ISO_READ_TEST_COUNTERS     = 0x2072
156    BT_HCI_OP_LE_ISO_TEST_END               = 0x2073
157    BT_HCI_OP_LE_SET_HOST_FEATURE           = 0x2074
158    BT_HCI_OP_VS_WRITE_BD_ADDR              = 0xFC06
159
160class ErrorCodes(IntEnum):
161    BT_HCI_ERR_BAD_EVENT                    = 0x01
162    BT_HCI_ERR_SIZE                         = 0x02
163    BT_HCI_ERR_BAD_CONN_HANDLE              = 0x03
164    BT_HCI_ERR_BAD_ENCRYPT_ENABLED          = 0x04
165    BT_HCI_ERR_BAD_TX_POWER_LEVEL           = 0x05
166    BT_HCI_ERR_BAD_LE_SUPPORTED_HOST        = 0x06
167    BT_HCI_ERR_BAD_LE_SIMULTANEOUS_HOST     = 0x07
168    BT_HCI_ERR_BAD_PAYLOAD_TIMEOUT          = 0x08
169    BT_HCI_ERR_BAD_RSSI_VALUE               = 0x09
170    BT_HCI_ERR_BAD_ADV_TX_POWER_LEVEL       = 0x0A
171    BT_HCI_ERR_BAD_LIST_SIZE                = 0x0B
172    BT_HCI_ERR_BAD_MAX_DATA_OCTETS          = 0x0C
173    BT_HCI_ERR_BAD_MAX_DATA_TRANSMIT_TIME   = 0x0D
174    BT_HCI_ERR_BAD_CHANNEL_MAP              = 0x0E
175    BT_HCI_ERR_BAD_PHY_CHANNEL              = 0x0F
176    BT_HCI_ERR_BAD_SELECTED_TX_POWER        = 0x10
177    BT_HCI_ERR_BAD_MAX_DATA_LENGTH          = 0x11
178    BT_HCI_ERR_BAD_SUPPORTED_ADV_SETS       = 0x12
179    BT_HCI_ERR_BAD_RF_COMPENSATION_VALUE    = 0x13
180    BT_HCI_ERR_BAD_COMMAND_STATUS_OPCODE    = 0x14
181    BT_HCI_ERR_BAD_LINK_TYPE                = 0x15
182    BT_HCI_ERR_BAD_CONNECTION_INTERVAL      = 0x16
183    BT_HCI_ERR_BAD_CONNECTION_LATENCY       = 0x17
184    BT_HCI_ERR_BAD_SUPERVISION_TIMEOUT      = 0x18
185    BT_HCI_ERR_BAD_CENTRAL_CLOCK_ACCURACY    = 0x19
186    BT_HCI_ERR_BAD_CONNECTION_ROLE          = 0x1A
187    BT_HCI_ERR_BAD_ADDRESS_TYPE             = 0x1B
188    BT_HCI_ERR_BAD_ADV_REPORT_EVENT         = 0x1C
189    BT_HCI_ERR_BAD_ADV_DATA_LENGTH          = 0x1D
190    BT_HCI_ERR_BAD_PARAMETER_INTERRELATION  = 0x1E
191    BT_HCI_ERR_BAD_NO_ADVERTISING_REPORTS   = 0x1F
192    BT_HCI_ERR_BAD_ADV_SID                  = 0x20
193    BT_HCI_ERR_BAD_PERIODIC_ADV_INTERVAL    = 0x21
194    BT_HCI_ERR_BAD_ADV_DATA_STATUS          = 0x22
195    BT_HCI_ERR_BAD_ADV_UNUSED_VALUE         = 0x23
196    BT_HCI_ERR_BAD_SYNC_HANDLE              = 0x24
197    BT_HCI_ERR_BAD_ADVERTISING_HANDLE       = 0x25
198    BT_HCI_ERR_BAD_CHANNEL_SEL_ALGORITHM    = 0x26
199    BT_HCI_ERR_BAD_PEER_CLOCK_ACCURACY      = 0x27
200    BT_HCI_ERR_BAD_ENC_KEY_SIZE             = 0x28
201
202
203class Event:
204
205    __metaFormats__ = { MetaEvents.BT_HCI_EVT_LE_CONN_COMPLETE:            'LE Connection Complete Event for handle {1:d} status 0x{0:02X} role {2:d} from {3:s} interval {4:d} latency {5:d} timeout {6:d} accuracy {7:d}',
206                       MetaEvents.BT_HCI_EVT_LE_ADVERTISING_REPORT:        'LE Advertising Report Event event {0:d} from {1!s} with rssi {3:d} dBm.',
207                       MetaEvents.BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE:      'LE Connection Update Complete Event for handle {1:d} status 0x{0:02X} interval {2:d} latency {3:d} timeout {4:d}',
208                       MetaEvents.BT_HCI_EVT_LE_REMOTE_FEAT_COMPLETE:      'LE Read Remote Features Complete Event for handle {1:d} status 0x{0:02X} features 0x{2:016X}',
209                       MetaEvents.BT_HCI_EVT_LE_LTK_REQUEST:               'LE Long Term Key Request Event for handle {0:d} number 0x{1:016X} diversifier 0x{2:04X}',
210                       MetaEvents.BT_HCI_EVT_LE_CONN_PARAM_REQ:            'LE Remote Connection Parameter Request Event for handle {0:d} interval [{1:d}, {2:d}] latency {3:d} timeout {4:d}',
211                       MetaEvents.BT_HCI_EVT_LE_DATA_LEN_CHANGE:           'LE Data Length Change Event for handle {0:d} Tx ({1:d}, {2:d}) Rx ({3:d}, {4:d})',
212                       MetaEvents.BT_HCI_EVT_LE_P256_PUBLIC_KEY_COMPLETE:  'LE Read Local P-256 Public Key Complete Event status 0x{0:02X} key 0x{1:0128X}',
213                       MetaEvents.BT_HCI_EVT_LE_GENERATE_DHKEY_COMPLETE:   'LE Generate DHKey Complete Event status 0x{0:02X} key 0x{1:064X}',
214                       MetaEvents.BT_HCI_EVT_LE_ENH_CONN_COMPLETE:         'LE Enhanced Connection Complete Event for handle {1:d} status 0x{0:02X} role {2:d} address {3!s} localRPA {4!s} peerRPA {5!s} interval {6:d} latency {7:d} timeout {8:d} accuracy {9:d}',
215                       MetaEvents.BT_HCI_EVT_LE_DIRECT_ADV_REPORT:         'LE Directed Advertising Report Event event {0:d} address {1!s}, direct adddress {2!s} rssi {3:d}',
216                       MetaEvents.BT_HCI_EVT_LE_PHY_UPDATE_COMPLETE:       'LE PHY Update Complete Event for handle {1:d} status 0x{0:02X} Tx PHY {2:d} Rx PHY {3:d}',
217                       MetaEvents.BT_HCI_EVT_LE_EXT_ADVERTISING_REPORT:    'LE Extended Advertising Report Event type {0:d} address {1!s} PHYs ({2:d}, {3:d}) SID {4:d} Tx power {5:+d} dBm. rssi {6:d} dBm. interval {7:d}',
218                       MetaEvents.BT_HCI_EVT_LE_PER_ADV_SYNC_ESTABLISHED:  'LE Periodic Advertising Sync Established Event for handle {1:d} status 0x{0:02X} address {3!s} SID {2:d} PHY {4:d} interval {5:d} accuracy {6:d}',
219                       MetaEvents.BT_HCI_EVT_LE_PER_ADVERTISING_REPORT:    'LE Periodic Advertising Report Event for handle {0:d} TX power {1:+d} dBm. rssi {2:+d} dBm. data status 0x{3:02X}',
220                       MetaEvents.BT_HCI_EVT_LE_PER_ADV_SYNC_LOST:         'LE Periodic Advertising Sync Lost Event for handle {0:d}',
221                       MetaEvents.BT_HCI_EVT_LE_SCAN_TIMEOUT:              'LE Scan Timeout Event',
222                       MetaEvents.BT_HCI_EVT_LE_ADV_SET_TERMINATED:        'LE Advertising Set Terminated Event for Advertise handle {1:d} Connection handle {2:d} status 0x{0:02X} events {3:d}',
223                       MetaEvents.BT_HCI_EVT_LE_SCAN_REQ_RECEIVED:         'LE Scan Request Received Event for handle {0:d} address {1!s}',
224                       MetaEvents.BT_HCI_EVT_LE_CHAN_SEL_ALGO:             'LE Channel Selection Algorithm Event for handle {0:d} algorithm {1:d}',
225                       MetaEvents.BT_HCI_EVT_LE_CIS_ESTABLISHED:           'LE CIS Established Event for handle {1:d} status 0x{0:02X} sync delay (CIG) {2!s} sync delay (CIS) {3!s} TL (MToS) {4!s} TL (SToM) {5!s} PHY (MToS) {6:d} PHY (SToM) {7:d} NSE {8:d}' \
226                                                                           'BN (MToS) {9:d} BN (SToM) {10:d} FT (MToS) {11:d} FT (SToM) {12:d} Max PDU (MToS) {13:d} Max PDU (SToM) {14:d} ISO interval {15:d}',
227                       MetaEvents.BT_HCI_EVT_LE_CIS_REQUEST:               'LE CIS Request Event for handle {1:d} acl handle {0:d} CIG id {2:d} CIS id {3:d}',
228                       MetaEvents.BT_HCI_EVT_LE_REQUEST_PEER_SCA_COMPLETE: 'LE Request Peer SCA Complete status 0x{0:02X} handle {1:d} peer clock accuracy {2:d}'
229                        }
230
231    __eventFormats__ = { Events.BT_HCI_EVT_DISCONN_COMPLETE:               'Disconnect Complete Event for handle {1:d} status 0x{0:02X} reason 0x{2:02X}',
232                       Events.BT_HCI_EVT_ENCRYPT_CHANGE_V1:                'Encryption Change v1 Event for handle {1:d} status 0x{0:02X} encryption enabled {2:d}',
233                       Events.BT_HCI_EVT_REMOTE_VERSION_INFO:              'Read Remote Version Information Event for handle {1:d} status 0x{0:02X} manufacturer 0x{3:04X} version 0x{2:02X} subversion 0x{4:04X}',
234                       Events.BT_HCI_EVT_CMD_COMPLETE:                     'Command Complete Event for opCode 0x{1:04X} status 0x{2:02X} packets 0x{0:02X}',
235                       Events.BT_HCI_EVT_CMD_STATUS:                       'Command Status Event for opCode 0x{1:04X} status 0x{2:02X} packets 0x{0:02X}',
236                       Events.BT_HCI_EVT_HARDWARE_ERROR:                   'Hardware Error Event error {0:d}',
237                       Events.BT_HCI_EVT_NUM_COMPLETED_PACKETS:            'Number of Completed Packets Event num_handles {0:d} handles {1}, packets {2}',
238                       Events.BT_HCI_EVT_DATA_BUF_OVERFLOW:                'Data Buffer Overflow Event link type {0:d}',
239                       Events.BT_HCI_EVT_ENCRYPT_KEY_REFRESH_COMPLETE:     'Encryption Key Refresh Complete Event for handle {1:d} status 0x{0:02X}',
240                       Events.BT_HCI_EVT_LE_META_EVENT:                    '',
241                       Events.BT_HCI_EVT_AUTH_PAYLOAD_TIMEOUT_EXP:         'Authenticated Payload Timeout Expired Event for handle {0:d}',
242                       Events.BT_HCI_EVT_ENCRYPT_CHANGE_V2:                'Encryption Change v2 Event for handle {1:d} status 0x{0:02X} encryption enabled {2:d} encryption key size {3:d}',
243                         }
244
245    __cceFormats__ = { CmdOpcodes.BT_HCI_OP_SET_EVENT_MASK:                'Command Complete Event for Set Event Mask status 0x{2:02X}',
246                       CmdOpcodes.BT_HCI_OP_RESET:                         'Command Complete Event for Reset status 0x{2:02X}',
247                       CmdOpcodes.BT_HCI_OP_READ_TX_POWER_LEVEL:           'Command Complete Event for Read Transmit Power Level status 0x{2:02X} handle {3:d} power level {4:+d} dBm.',
248                       CmdOpcodes.BT_HCI_OP_SET_CTL_TO_HOST_FLOW:          'Command Complete Event for Set Controller To Host Flow Control status 0x{2:02X}',
249                       CmdOpcodes.BT_HCI_OP_HOST_BUFFER_SIZE:              'Command Complete Event for Host Buffer Size status 0x{2:02X}',
250                       CmdOpcodes.BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS:    'Command Complete Event for Host Number Of Completed Packets',
251                       CmdOpcodes.BT_HCI_OP_SET_EVENT_MASK_PAGE_2:         'Command Complete Event for Set Event Mask Page 2 status 0x{2:02X}',
252                       CmdOpcodes.BT_HCI_OP_LE_READ_LE_HOST_SUPP:          'Command Complete Event for Read LE Host Support status 0x{2:02X} LE supported host {3:d} simultaneous LE host {4:d}',
253                       CmdOpcodes.BT_HCI_OP_LE_WRITE_LE_HOST_SUPP:         'Command Complete Event for Write LE Host Support status 0x{2:02X}',
254                       CmdOpcodes.BT_HCI_OP_LE_READ_RF_PATH_COMP: 		   'Command Complete Event for LE Read RF Path Compensation status 0x{2:02X}',
255                       CmdOpcodes.BT_HCI_OP_READ_AUTH_PAYLOAD_TIMEOUT:     'Command Complete Event for Read Authenticated Payload Timeout status 0x{2:02X} handle {3:d} timeout {4:d} x 10 ms.',
256                       CmdOpcodes.BT_HCI_OP_WRITE_AUTH_PAYLOAD_TIMEOUT:    'Command Complete Event for Write Authenticated Payload Timeout status 0x{2:02X} handle {3:d}',
257                       CmdOpcodes.BT_HCI_OP_READ_LOCAL_VERSION_INFO:       'Command Complete Event for Read Local Version Information status 0x{2:02X} HCI version {3:d} HCI revision 0x{4:04X} LMP version {5:d} LMP subversion 0x{6:04X} manufacturer 0x{7:04X} ',
258                       CmdOpcodes.BT_HCI_OP_READ_SUPPORTED_COMMANDS:       'Command Complete Event for Read Local Supported Commands status 0x{2:02X}',
259                       CmdOpcodes.BT_HCI_OP_READ_LOCAL_FEATURES:           'Command Complete Event for Read Local Supported Features status 0x{2:02X}',
260                       CmdOpcodes.BT_HCI_OP_READ_BUFFER_SIZE:              'Command Complete Event for Read Buffer Size status 0x{2:02X} ACL packet length {3:d} SYN packet length {4:d} ACL packets {5:d} SYN packets {6:d}',
261                       CmdOpcodes.BT_HCI_OP_READ_BD_ADDR:                  'Command Complete Event for Read BD_ADDR status 0x{2:02X} address {3!s}',
262                       CmdOpcodes.BT_HCI_OP_READ_RSSI:                     'Command Complete Event for Read RSSI status 0x{2:02X} handle {3:d} rssi {4:+d} dBm.',
263                       CmdOpcodes.BT_HCI_OP_LE_SET_EVENT_MASK:             'Command Complete Event for LE Set Event Mask status 0x{2:02X}',
264                       CmdOpcodes.BT_HCI_OP_LE_READ_BUFFER_SIZE:           'Command Complete Event for LE Read Buffer Size status 0x{2:02X} LE data packet length {3:d} LE data packets {4:d}',
265                       CmdOpcodes.BT_HCI_OP_LE_READ_LOCAL_FEATURES:        'Command Complete Event for LE Read Local Supported Features status 0x{2:02X}',
266                       CmdOpcodes.BT_HCI_OP_LE_SET_RANDOM_ADDRESS:         'Command Complete Event for LE Set Random Address status 0x{2:02X}',
267                       CmdOpcodes.BT_HCI_OP_LE_SET_ADV_PARAM:              'Command Complete Event for LE Set Advertising Parameters status 0x{2:02X}',
268                       CmdOpcodes.BT_HCI_OP_LE_READ_ADV_CHAN_TX_POWER:     'Command Complete Event for LE Read Advertising Channel TX Power status 0x{2:02X} power level {3:+d} dBm.',
269                       CmdOpcodes.BT_HCI_OP_LE_SET_ADV_DATA:               'Command Complete Event for LE Set Advertising Data status 0x{2:02X}',
270                       CmdOpcodes.BT_HCI_OP_LE_SET_SCAN_RSP_DATA:          'Command Complete Event for LE Set Scan Response Data status 0x{2:02X}',
271                       CmdOpcodes.BT_HCI_OP_LE_SET_ADV_ENABLE:             'Command Complete Event for LE Set Advertising Enable status 0x{2:02X}',
272                       CmdOpcodes.BT_HCI_OP_LE_SET_SCAN_PARAM:             'Command Complete Event for LE Set Scan Parameters status 0x{2:02X}',
273                       CmdOpcodes.BT_HCI_OP_LE_SET_SCAN_ENABLE:            'Command Complete Event for LE Set Scan Enable status 0x{2:02X}',
274                       CmdOpcodes.BT_HCI_OP_LE_CREATE_CONN_CANCEL:         'Command Complete Event for LE Create Connection Cancel status 0x{2:02X}',
275                       CmdOpcodes.BT_HCI_OP_LE_READ_FAL_SIZE:               'Command Complete Event for LE Read Filter Accept List Size status 0x{2:02X} list size {3:d}',
276                       CmdOpcodes.BT_HCI_OP_LE_CLEAR_FAL:                   'Command Complete Event for LE Clear Filter Accept List status 0x{2:02X}',
277                       CmdOpcodes.BT_HCI_OP_LE_ADD_DEV_TO_FAL:              'Command Complete Event for LE Add Device To Filter Accept List status 0x{2:02X}',
278                       CmdOpcodes.BT_HCI_OP_LE_REM_DEV_FROM_FAL:            'Command Complete Event for LE Remove Device From Filter Accept List status 0x{2:02X}',
279                       CmdOpcodes.BT_HCI_OP_LE_SET_HOST_CHAN_CLASSIF:      'Command Complete Event for LE Set Host Channel Classification status 0x{2:02X}',
280                       CmdOpcodes.BT_HCI_OP_LE_READ_CHAN_MAP:              'Command Complete Event for LE Read Channel Map status 0x{2:02X} handle {3:d} channel map 0x{4:010X}',
281                       CmdOpcodes.BT_HCI_OP_LE_ENCRYPT:                    'Command Complete Event for LE Encrypt status 0x{2:02X}',
282                       CmdOpcodes.BT_HCI_OP_LE_RAND:                       'Command Complete Event for LE Rand status 0x{2:02X} number 0x{3:016X}',
283                       CmdOpcodes.BT_HCI_OP_LE_LTK_REQ_REPLY:              'Command Complete Event for LE Long Term Key Request Reply status 0x{2:02X} handle {3:d}',
284                       CmdOpcodes.BT_HCI_OP_LE_LTK_REQ_NEG_REPLY:          'Command Complete Event for LE Long Term Key Request Negative Reply status 0x{2:02X} handle {3:d}',
285                       CmdOpcodes.BT_HCI_OP_LE_READ_SUPP_STATES:           'Command Complete Event for LE Read Supported States status 0x{2:02X}',
286                       CmdOpcodes.BT_HCI_OP_LE_RX_TEST:                    'Command Complete Event for LE Receiver Test status 0x{2:02X}',
287                       CmdOpcodes.BT_HCI_OP_LE_TX_TEST:                    'Command Complete Event for LE Transmitter Test status 0x{2:02X}',
288                       CmdOpcodes.BT_HCI_OP_LE_TEST_END:                   'Command Complete Event for LE Test End status 0x{2:02X} packets {3:d}',
289                       CmdOpcodes.BT_HCI_OP_LE_CONN_PARAM_REQ_REPLY:       'Command Complete Event for LE Remote Connection Parameter Request Reply status 0x{2:02X} handle {3:d}',
290                       CmdOpcodes.BT_HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY:   'Command Complete Event for LE Remote Connection Parameter Request Negative Reply status 0x{2:02X} handle {3:d}',
291                       CmdOpcodes.BT_HCI_OP_LE_SET_DATA_LEN:               'Command Complete Event for LE Set Data Length status 0x{2:02X} handle {3:d}',
292                       CmdOpcodes.BT_HCI_OP_LE_READ_DEFAULT_DATA_LEN:      'Command Complete Event for LE Read Suggested Default Data Length status 0x{2:02X} max TX octets {3:d} max TX time {4:d}',
293                       CmdOpcodes.BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN:     'Command Complete Event for LE Write Suggested Default Data Length status 0x{2:02X}',
294                       CmdOpcodes.BT_HCI_OP_LE_ADD_DEV_TO_RL:              'Command Complete Event for LE Add Device To Resolving List status 0x{2:02X}',
295                       CmdOpcodes.BT_HCI_OP_LE_REM_DEV_FROM_RL:            'Command Complete Event for LE Remove Device From Resolving List status 0x{2:02X}',
296                       CmdOpcodes.BT_HCI_OP_LE_CLEAR_RL:                   'Command Complete Event for LE Clear Resolving List status 0x{2:02X}',
297                       CmdOpcodes.BT_HCI_OP_LE_READ_RL_SIZE:               'Command Complete Event for LE Read Resolving List Size status 0x{2:02X} list size {3:d}',
298                       CmdOpcodes.BT_HCI_OP_LE_READ_PEER_RPA:              'Command Complete Event for LE Read Peer Resolvable Address status 0x{2:02X} address {3!s}',
299                       CmdOpcodes.BT_HCI_OP_LE_READ_LOCAL_RPA:             'Command Complete Event for LE Read Local Resolvable Address status 0x{2:02X} address {3!s}',
300                       CmdOpcodes.BT_HCI_OP_LE_SET_ADDR_RES_ENABLE:        'Command Complete Event for LE Set Address Resolution Enable status 0x{2:02X}',
301                       CmdOpcodes.BT_HCI_OP_LE_SET_RPA_TIMEOUT:            'Command Complete Event for LE Set Resolvable Private Address Timeout status 0x{2:02X}',
302                       CmdOpcodes.BT_HCI_OP_LE_READ_MAX_DATA_LEN:          'Command Complete Event for LE Read Maximum Data Length status 0x{2:02X} max TX octets {3:d} max TX time {4:d} max RX octets {5:d} max RX time {6:d}',
303                       CmdOpcodes.BT_HCI_OP_LE_READ_PHY:                   'Command Complete Event for LE Read PHY status 0x{2:02X} handle {3:d} TX phy {4:d} RX phy {5:d}',
304                       CmdOpcodes.BT_HCI_OP_LE_SET_DEFAULT_PHY:            'Command Complete Event for LE Set Default PHY status 0x{2:02X}',
305                       CmdOpcodes.BT_HCI_OP_LE_ENH_RX_TEST:                'Command Complete Event for LE Enhanced Receiver Test status 0x{2:02X}',
306                       CmdOpcodes.BT_HCI_OP_LE_ENH_TX_TEST:                'Command Complete Event for LE Enhanced Transmitter Test status 0x{2:02X}',
307                       CmdOpcodes.BT_HCI_OP_LE_SET_EXT_ADV_PARAM:          'Command Complete Event for LE Set Extended Advertising Parameters status 0x{2:02X} power level {3:+d} dBm.',
308                       CmdOpcodes.BT_HCI_OP_LE_SET_EXT_ADV_DATA:           'Command Complete Event for LE Set Extended Advertising Data status 0x{2:02X}',
309                       CmdOpcodes.BT_HCI_OP_LE_SET_EXT_SCAN_RSP_DATA:      'Command Complete Event for LE Set Extended Scan Response Data status 0x{2:02X}',
310                       CmdOpcodes.BT_HCI_OP_LE_SET_EXT_ADV_ENABLE:         'Command Complete Event for LE Set Extended Advertising Enable status 0x{2:02X}',
311                       CmdOpcodes.BT_HCI_OP_LE_READ_MAX_ADV_DATA_LEN:      'Command Complete Event for LE Read Maximum Advertising Data Length status 0x{2:02X} max. data length {3:d}',
312                       CmdOpcodes.BT_HCI_OP_LE_READ_NUM_ADV_SETS:          'Command Complete Event for LE Read Number of Supported Advertising Sets status 0x{2:02X} supported sets {3:d}',
313                       CmdOpcodes.BT_HCI_OP_LE_REMOVE_ADV_SET:             'Command Complete Event for LE Remove Advertising Set status 0x{2:02X}',
314                       CmdOpcodes.BT_HCI_OP_CLEAR_ADV_SETS:                'Command Complete Event for LE Clear Advertising Sets status 0x{2:02X}',
315                       CmdOpcodes.BT_HCI_OP_LE_SET_PER_ADV_PARAM:          'Command Complete Event for LE Set Periodic Advertising Parameters status 0x{2:02X}',
316                       CmdOpcodes.BT_HCI_OP_LE_SET_PER_ADV_DATA:           'Command Complete Event for LE Set Periodic Advertising Data status 0x{2:02X}',
317                       CmdOpcodes.BT_HCI_OP_LE_SET_PER_ADV_ENABLE:         'Command Complete Event for LE Set Periodic Advertising Enable status 0x{2:02X}',
318                       CmdOpcodes.BT_HCI_OP_LE_SET_EXT_SCAN_PARAM:         'Command Complete Event for LE Set Extended Scan Parameters status 0x{2:02X}',
319                       CmdOpcodes.BT_HCI_OP_LE_SET_EXT_SCAN_ENABLE:        'Command Complete Event for LE Set Extended Scan Enable status 0x{2:02X}',
320                       CmdOpcodes.BT_HCI_OP_LE_PER_ADV_CREATE_SYNC_CANCEL: 'Command Complete Event for LE Periodic Advertising Create Sync Cancel status 0x{2:02X}',
321                       CmdOpcodes.BT_HCI_OP_LE_PER_ADV_TERMINATE_SYNC:     'Command Complete Event for LE Periodic Advertising Terminate Sync status 0x{2:02X}',
322                       CmdOpcodes.BT_HCI_OP_LE_ADD_DEV_TO_PER_ADV_LIST:    'Command Complete Event for LE Add Device To Periodic Advertiser List status 0x{2:02X}',
323                       CmdOpcodes.BT_HCI_OP_LE_REM_DEV_FROM_PER_ADV_LIST:  'Command Complete Event for LE Remove Device From Periodic Advertiser List status 0x{2:02X}',
324                       CmdOpcodes.BT_HCI_OP_LE_CLEAR_PER_ADV_LIST:         'Command Complete Event for LE Clear Periodic Advertiser List status 0x{2:02X}',
325                       CmdOpcodes.BT_HCI_OP_LE_READ_PER_ADV_LIST_SIZE:     'Command Complete Event for LE Read Periodic Advertiser List Size status 0x{2:02X} list size {3:d}',
326                       CmdOpcodes.BT_HCI_OP_LE_READ_TX_POWER:              'Command Complete Event for LE Read Transmit Power status 0x{2:02X} TX power range [{3:+d}, {4:+d}] dBm.',
327                       CmdOpcodes.BT_HCI_OP_LE_READ_RF_PATH_COMP:          'Command Complete Event for LE Read RF Path Compensation status 0x{2:02X} TX path compensation {3:+d} x 0.1 dB. RX path compensation {4:+d} x 0.1 dB.',
328                       CmdOpcodes.BT_HCI_OP_LE_WRITE_RF_PATH_COMP:         'Command Complete Event for LE Write RF Path Compensation status 0x{2:02X}',
329                       CmdOpcodes.BT_HCI_OP_LE_SET_PRIVACY_MODE:           'Command Complete Event for LE Set Privacy Mode status 0x{2:02X}',
330                       CmdOpcodes.BT_HCI_OP_LE_SET_CIG_PARAMETERS:         'Command Complete Event for LE Set CIG Parameters status 0x{2:02X} CIG id {3:d} CIS count {4:d}',
331                       CmdOpcodes.BT_HCI_OP_LE_SET_CIG_PARAMETERS_TEST:    'Command Complete Event for LE Set CIG Parameters Test status 0x{2:02X} CIG id {3:d} CIS count {4:d}',
332                       CmdOpcodes.BT_HCI_OP_LE_REMOVE_CIG:                 'Command Complete Event for LE Remove CIG status 0x{2:02X} CIG id {3:d}',
333                       CmdOpcodes.BT_HCI_OP_LE_REJECT_CIS_REQUEST:         'Command Complete Event for LE reject CIS Request status 0x{2:02X} handle {3:d}',
334                       CmdOpcodes.BT_HCI_OP_LE_SETUP_ISO_DATA_PATH:        'Command Complete Event for LE Setup ISO Data Path status 0x{2:02X} handle {3:d}',
335                       CmdOpcodes.BT_HCI_OP_LE_REMOVE_ISO_DATA_PATH:       'Command Complete Event for LE Remove ISO Data Path status 0x{2:02X} handle {3:d}',
336                       CmdOpcodes.BT_HCI_OP_LE_ISO_TRANSMIT_TEST:          'Command Complete Event for LE LE ISO Transmit Test status 0x{2:02X} handle {3:d}',
337                       CmdOpcodes.BT_HCI_OP_LE_ISO_RECEIVE_TEST:           'Command Complete Event for LE LE ISO Receive Test status 0x{2:02X} handle {3:d}',
338                       CmdOpcodes.BT_HCI_OP_LE_ISO_READ_TEST_COUNTERS:     'Command Complete Event for LE LE ISO Read Test Counters status 0x{2:02X} handle {3:d} received SDU count {4:d} missed SDU count {5:d} failed SDU count {6:d}',
339                       CmdOpcodes.BT_HCI_OP_LE_ISO_TEST_END:               'Command Complete Event for LE LE ISO Test End status 0x{2:02X} handle {3:d} received SDU count {4:d} missed SDU count {5:d} failed SDU count {6:d}',
340                       CmdOpcodes.BT_HCI_OP_LE_SET_HOST_FEATURE:           'Command Complete Event for LE Set Host Feature status 0x{2:02X}',
341                       CmdOpcodes.BT_HCI_OP_VS_WRITE_BD_ADDR:              'Command Complete Event for Write BD_ADDR status 0x{2:02X}',
342                       CmdOpcodes.BT_HCI_OP_LE_READ_BUFFER_SIZE_V2:        'Command Complete Event for LE Read Buffer Size V2 status 0x{2:02X} LE data packet length {3:d} LE data packets {4:d} ISO data packet length {5:d} ISO data packets {6:d}',
343 };
344
345    __cseFormats__ = { CmdOpcodes.BT_HCI_OP_INQUIRY:                       'Command Status Event for Inquire status 0x{2:02X}',
346                       CmdOpcodes.BT_HCI_OP_DISCONNECT:                    'Command Status Event for Disconnect status 0x{2:02X}',
347                       CmdOpcodes.BT_HCI_OP_READ_REMOTE_VERSION_INFO:      'Command Status Event for Read Remote Version Information status 0x{2:02X}',
348                       CmdOpcodes.BT_HCI_OP_LE_CREATE_CONN:                'Command Status Event for LE Create Connection status 0x{2:02X}',
349                       CmdOpcodes.BT_HCI_OP_LE_CONN_UPDATE:                'Command Status Event for LE Connection Update status 0x{2:02X}',
350                       CmdOpcodes.BT_HCI_OP_LE_READ_REMOTE_FEATURES:       'Command Status Event for LE Read Remote Features status 0x{2:02X}',
351                       CmdOpcodes.BT_HCI_OP_LE_START_ENCRYPTION:           'Command Status Event for LE Start Encryption status 0x{2:02X}',
352                       CmdOpcodes.BT_HCI_OP_LE_P256_PUBLIC_KEY:            'Command Status Event for LE Read Local P-256 Public Key Command status 0x{2:02X}',
353                       CmdOpcodes.BT_HCI_OP_LE_GENERATE_DHKEY:             'Command Status Event for LE Generate DHKey Command status 0x{2:02X}',
354                       CmdOpcodes.BT_HCI_OP_LE_SET_PHY:                    'Command Status Event for LE Set PHY status 0x{2:02X}',
355                       CmdOpcodes.BT_HCI_OP_LE_EXT_CREATE_CONN:            'Command Status Event for LE Extended Create Connection status 0x{2:02X}',
356                       CmdOpcodes.BT_HCI_OP_LE_PER_ADV_CREATE_SYNC:        'Command Status Event for LE Periodic Advertising Create Sync status 0x{2:02X}',
357                       CmdOpcodes.BT_HCI_OP_LE_ACCEPT_CIS_REQUEST:         'Command Status Event for LE Accept CIS Request status 0x{2:02X}',
358                       CmdOpcodes.BT_HCI_OP_LE_CREATE_CIS:                 'Command Status Event for LE Create CIS status 0x{2:02X}',
359                       CmdOpcodes.BT_HCI_OP_LE_REQUEST_PEER_SCA:           'Command Status Event for LE Request Peer SCA status 0x{2:02X}',
360                       }
361
362
363    def __init__(self, event, data, time=None):
364        self.event = event;
365        self.data  = data[:];
366        self.values = None;
367        self.errors = set([]);
368        self.time = time;
369        self.size = len(self.data);
370        self.subEvent = struct.unpack('B', self.data[:1])[0] if self.size > 0 and self.event == Events.BT_HCI_EVT_LE_META_EVENT else 0;
371
372    def __asNumber(self, data):
373        value = 0;
374        for part in reversed(data):
375            value <<= 8;
376            value += part;
377        return value;
378
379    def __checkSize(self, size):
380        if self.size != size:
381            if self.size == 4:
382                  # Unknown command response
383                  return False
384            self.errors.add(ErrorCodes.BT_HCI_ERR_SIZE);
385        return self.size >= size;
386
387    def __checkMinSize(self, size):
388        if not self.size >= size:
389            self.errors.add(ErrorCodes.BT_HCI_ERR_SIZE);
390        return self.size >= size;
391
392    def __checkConnectionHandle(self, handle):
393        if not (0 <= handle <= 0xEFF):
394            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_CONN_HANDLE);
395
396    def __checkEncryptionEnabled(self, enabled):
397        if not (0 <= enabled <= 2):
398            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ENCRYPT_ENABLED);
399
400    def __checkEncryptionKeySize(self, key_size):
401        if not (0x01 <= key_size <= 0x10):
402            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ENC_KEY_SIZE)
403
404    def __checkTXPowerLevel(self, level):
405        if not (-30 <= level <= 20):
406            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_TX_POWER_LEVEL);
407
408    def __checkLESupportedHost(self, value):
409        if not (0 <= value <= 1):
410            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_LE_SUPPORTED_HOST);
411
412    def __checkLESimultaneousHost(self, value):
413        if not (0 == value):
414            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_LE_SIMULTANEOUS_HOST);
415
416    def __checkPayloadTimeout(self, timeout):
417        if not (0 < timeout):
418            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_PAYLOAD_TIMEOUT);
419
420    def __checkRSSI(self, rssi):
421        if not ((-127 <= rssi <= 20) or (rssi == 127)):
422            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_RSSI_VALUE);
423
424    def __checkAdvTXPowerLevel(self, level):
425        if not (-20 <= level <= 10):
426            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ADV_TX_POWER_LEVEL);
427
428    def __checkListSize(self, size):
429        if not (1 <= size):
430            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_LIST_SIZE);
431
432    def __checkMaxDataOctets(self, octets):
433        if not (0x001B <= octets <= 0x00FB):
434            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_MAX_DATA_OCTETS);
435
436    def __checkMaxDataTransmitTime(self, time):
437        if not (0x0148 <= time <= 0x4290):
438            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_MAX_DATA_TRANSMIT_TIME);
439
440    def __checkChannelMap(self, map):
441        if not (map <= 0x1FFFFFFFFF):
442            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_CHANNEL_MAP);
443
444    def __checkPhy(self, phy, legal=[1,2,3]):
445        if not (phy in legal):
446            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_PHY_CHANNEL);
447
448    def __checkSelectedTXPower(self, power, minPower=-127, maxPower=126):
449        if not (minPower <= power <= maxPower):
450            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_SELECTED_TX_POWER);
451
452    def __checkMaxAdvDataLength(self, length):
453        if not (0x001F <= length <= 0x0672):
454            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_MAX_DATA_LENGTH);
455
456    def __checkSupportedAdvSets(self, sets):
457        if not (1 <= sets <= 240):
458            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_SUPPORTED_ADV_SETS);
459
460    def __checkRFPathCompensation(self, value):
461        if not (-1280 <= value <= 1280):
462            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_RF_COMPENSATION_VALUE);
463
464    def __checkLinkType(self, linkType):
465        if not (0 <= linkType <= 1):
466            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_LINK_TYPE);
467
468    def __checkConnectionInterval(self, interval):
469        if not (0x0006 <= interval <= 0x0C80):
470            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_CONNECTION_INTERVAL);
471
472    def __checkConnectionLatency(self, latency):
473        if not (0x0000 <= latency <= 0x01F3):
474            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_CONNECTION_LATENCY);
475
476    def __checkSupervisionTimeout(self, timeout):
477        if not (0x000A <= timeout <= 0x0C80):
478            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_SUPERVISION_TIMEOUT);
479
480    def __checkCentralClockAccuracy(self, accuracy):
481        if not (0 <= accuracy <= 7):
482            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_CENTRAL_CLOCK_ACCURACY);
483
484    def __checkConnectionRole(self, role):
485        if not (0 <= role <= 1):
486            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_CONNECTION_ROLE);
487
488    def __checkAddressType(self, type, legalTypes=[0,1,2,3]):
489        if not (type in legalTypes):
490            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ADDRESS_TYPE);
491
492    def __checkAdvEvent(self, event, minEvent=0, maxEvent=4):
493        if not (minEvent <= event <= maxEvent):
494            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ADV_REPORT_EVENT);
495
496    def __checkAdvDataLength(self, length, maxLength=31):
497        if not (0 <= length <= maxLength):
498            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ADV_DATA_LENGTH);
499
500    def __checkSid(self, sid, legal):
501        if not (sid in legal):
502            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ADV_SID);
503
504    def __checkSyncHandle(self, handle):
505        if not (0 <= handle <= 0xEFF):
506            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_SYNC_HANDLE);
507
508    def __checkPeriodicAdvInterval(self, interval):
509        if not (6 <= interval):
510            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_PERIODIC_ADV_INTERVAL);
511
512    def __checkAdvDataStatus(self, status):
513        if not (0 <= status <= 2):
514            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ADV_DATA_STATUS);
515
516    def __checkAdvertisingHandle(self, handle):
517        if not (0 <= handle <= 0xEF):
518            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ADVERTISING_HANDLE);
519
520    def __checkChannelAlgorithm(self, algorithm):
521        if not (0 <= algorithm <= 1):
522            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_CHANNEL_SEL_ALGORITHM);
523
524    def __checkPeerClockAccuracy(self, accuracy):
525        if not (0x00 <= accuracy <= 0x07):
526            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_PEER_CLOCK_ACCURACY)
527
528    def __checkAdvertisingReports(self, reports, minReports=1, maxReports=25):
529        if not (minReports <= reports <= maxReports):
530            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_NO_ADVERTISING_REPORTS);
531
532
533    def __disconnectComplete(self):
534        if self.__checkSize(4):
535            status, handle, reason = struct.unpack('<BHB', self.data[:4]);
536            self.__checkConnectionHandle(handle);
537        else:
538            status = handle = reason = 0;
539        return status, handle, reason;
540
541    def __encryptionChangeV1(self):
542        if self.__checkSize(4):
543            status, handle, enabled = struct.unpack('<BHB', self.data[:4]);
544            self.__checkConnectionHandle(handle);
545            self.__checkEncryptionEnabled(enabled);
546        else:
547            status = handle = enabled = 0;
548        return status, handle, enabled;
549
550
551    def __encryptionChangeV2(self):
552        if self.__checkSize(5):
553            status, handle, enabled, key_size = struct.unpack('<BHBB', self.data[:5])
554            self.__checkConnectionHandle(handle)
555            self.__checkEncryptionEnabled(enabled)
556            self.__checkEncryptionKeySize(key_size)
557        else:
558            status = handle = enabled = key_size = 0
559        return status, handle, enabled, key_size
560
561
562    def __RemoteVersionComplete(self):
563        if self.__checkSize(8):
564            status, handle, version, manufacturer, subVersion = struct.unpack('<BHBHH', self.data[:8]);
565            self.__checkConnectionHandle(handle);
566        else:
567            status = handle = version = manufacturer = subVersion = 0;
568        return status, handle, version, manufacturer, subVersion;
569
570    """ ================================================================================
571
572          The following private methods are all sub-sets of the Command Complete Event
573
574        ================================================================================ """
575
576    def __readTXPowerLevel(self):
577        if self.__checkSize(7):
578            handle, level = struct.unpack('<Hb', self.data[4:7]);
579            self.__checkConnectionHandle(handle);
580            self.__checkTXPowerLevel(level);
581        else:
582            handle = level = 0;
583        return handle, level
584
585    def __readLEHostSupport(self):
586        if self.__checkSize(6):
587            supported, simultaneous = struct.unpack('<BB', self.data[4:6]);
588            self.__checkLESupportedHost(supported);
589            self.__checkLESimultaneousHost(simultaneous);
590        else:
591            supported = simultaneous = 0;
592        return supported, simultaneous;
593
594    def __readAuthPayloadTimeout(self):
595        if self.__checkSize(8):
596            handle, timeout = struct.unpack('<HH', self.data[4:8]);
597            self.__checkConnectionHandle(handle);
598            self.__checkPayloadTimeout(timeout);
599            self.__checkConnectionHandle(handle);
600            self.__checkPayloadTimeout(timeout);
601        else:
602            handle = timeout = 0;
603        return handle, timeout;
604
605    def __writeAuthPayloadTimeout(self):
606        if self.__checkSize(6):
607            handle = struct.unpack('<H', self.data[4:6])[0];
608            self.__checkConnectionHandle(handle);
609        else:
610            handle = 0;
611        return (handle,);
612
613    def __readLocalVersionInformation(self):
614        if self.__checkSize(12):
615            hciVersion, hciRevision, lmpVersion, manufacturer, lmpSubversion = struct.unpack('<BHBHH', self.data[4:12]);
616        else:
617            hciVersion = hciRevision = lmpVersion = lmpSubversion = manufacturer = 0;
618        return hciVersion, hciRevision, lmpVersion, lmpSubversion, manufacturer;
619
620    def __readLocalSupportedCommands(self):
621        if self.__checkSize(68):
622            commands = struct.unpack('<64B', self.data[4:68]);
623        else:
624            commands = [0 for _ in range(64)];
625        return (commands,);
626
627    def __readLocalSupportedFeatures(self):
628        if self.__checkSize(12):
629            features = struct.unpack('<8B', self.data[4:12]);
630        else:
631            features = [0 for _ in range(8)];
632        return (features,);
633
634    def __readBufferSize(self):
635        if self.__checkSize(11):
636            aclLength, synLength, aclPackets, synPackets = struct.unpack('<HBHH', self.data[4:11]);
637        else:
638            aclLength = synLength = aclPackets = synPackets = 0
639        return aclLength, synLength, aclPackets, synPackets;
640
641    def __readBDAddress(self):
642        if self.__checkSize(10):
643            address = struct.unpack('<6B', self.data[4:10]);
644        else:
645            address = None;
646        return (Address(None, address),);
647
648    def __readRssi(self):
649        if self.__checkSize(7):
650            handle, rssi = struct.unpack('<Hb', self.data[4:7]);
651            self.__checkConnectionHandle(handle);
652            self.__checkRSSI(rssi);
653        else:
654            handle = rssi = 0;
655        return handle, rssi;
656
657    def __leReadBufferSize(self):
658        if self.__checkSize(7):
659            dpLength, dpCount = struct.unpack('<HB', self.data[4:7]);
660        else:
661            dpLength = dpCount = 0;
662        return dpLength, dpCount;
663
664    def __leReadBufferSizeV2(self):
665        if self.__checkSize(10):
666            dpLength, dpCount, isoLength, isoCount = struct.unpack('<HBHB', self.data[4:10]);
667        else:
668            dpLength = dpCount = isoLength = isoCount = 0;
669        return dpLength, dpCount, isoLength, isoCount;
670
671    def __leReadLocalSupportedFeatures(self):
672        if self.__checkSize(12):
673            features = struct.unpack('<8B', self.data[4:12]);
674        else:
675            features = [0 for _ in range(8)];
676        return (features,);
677
678    def __leReadAdvChannelTXPower(self):
679        if self.__checkSize(5):
680            power = struct.unpack('<b', self.data[4:5])[0];
681            self.__checkAdvTXPowerLevel(power);
682        else:
683            power = 0;
684        return (power,);
685
686    def __leReadListSize(self):
687        if self.__checkSize(5):
688            size = struct.unpack('<B', self.data[4:5])[0];
689            self.__checkListSize(size);
690        else:
691            size = 0;
692        return (size,);
693
694    def __leReadChannelMap(self):
695        if self.__checkSize(11):
696            handle = struct.unpack('<H', self.data[4:6])[0];
697            chnMap = struct.unpack('<5B', self.data[6:11]);
698            chnMapNo = self.__asNumber(chnMap);
699            self.__checkConnectionHandle(handle);
700            self.__checkChannelMap(chnMapNo);
701        else:
702            handle = chnMapNo = 0;
703        return handle, chnMapNo;
704
705    def __leEncrypt(self):
706        if self.__checkSize(20):
707            encData = struct.unpack('<16B', self.data[4:20]);
708        else:
709            encData = [0 for _ in range(16)];
710        return (encData,);
711
712    def __leRand(self):
713        if self.__checkSize(12):
714            number = struct.unpack('<8B', self.data[4:12]);
715        else:
716            number = [0 for _ in range(8)];
717        return (self.__asNumber(number),);
718
719    def __leLTKRequestReply(self):
720        if self.__checkSize(6):
721            handle = struct.unpack('<H', self.data[4:6])[0];
722            self.__checkConnectionHandle(handle);
723        else:
724            handle = 0;
725        return (handle,);
726
727    def __leReadSupportedStates(self):
728        if self.__checkSize(12):
729            states = struct.unpack('<8B', self.data[4:12]);
730        else:
731            states = [0 for _ in range(8)];
732        return (self.__asNumber(states),);
733
734    def __leTestEnd(self):
735        if self.__checkSize(6):
736            packets = struct.unpack('<H', self.data[4:6])[0];
737        else:
738            packets = 0;
739        return (packets,);
740
741    def __leRemoteConnectionParameterRequest(self):
742        if self.__checkSize(6):
743            handle = struct.unpack('<H', self.data[4:6])[0];
744            self.__checkConnectionHandle(handle);
745        else:
746            handle = 0;
747        return (handle,);
748
749    def __leSetDataLength(self):
750        if self.__checkSize(6):
751            handle = struct.unpack('<H', self.data[4:6])[0];
752            self.__checkConnectionHandle(handle);
753        else:
754            handle = 0;
755        return (handle,);
756
757    def __leReadDefaultDataLength(self):
758        if self.__checkSize(8):
759            maxOctets, maxTime = struct.unpack('<HH', self.data[4:8]);
760            self.__checkMaxDataOctets(maxOctets);
761            self.__checkMaxDataTransmitTime(maxTime);
762        else:
763            maxOctets = maxTime = 0;
764        return maxOctets, maxTime;
765
766    def __leReadResolvingListSize(self):
767        if self.__checkSize(5):
768            size = struct.unpack('<B', self.data[4:5])[0];
769        else:
770            size = 0;
771        return (size,);
772
773    def __leReadResolvableAddress(self):
774        if self.__checkSize(10):
775            address = struct.unpack('<6B', self.data[4:10]);
776        else:
777            address = None;
778        return (Address(None, address),);
779
780    def __leReadMaximumDataLength(self):
781        if self.__checkSize(12):
782            maxTXOctets, maxTXTime, maxRXOctets, maxRXTime = struct.unpack('<HHHH', self.data[4:12]);
783            self.__checkMaxDataOctets(maxTXOctets);
784            self.__checkMaxDataTransmitTime(maxTXTime);
785            self.__checkMaxDataOctets(maxRXOctets);
786            self.__checkMaxDataTransmitTime(maxRXTime);
787        else:
788            maxTXOctets = maxTXTime = maxRXOctets = maxRXTime = 0;
789        return maxTXOctets, maxTXTime, maxRXOctets, maxRXTime;
790
791    def __leReadPHY(self):
792        if self.__checkSize(8):
793            handle, txPHY, rxPHY = struct.unpack('<HBB', self.data[4:8]);
794            self.__checkConnectionHandle(handle);
795            self.__checkPhy(txPHY);
796            self.__checkPhy(rxPHY);
797        else:
798            handle = txPHY = rxPHY = 0;
799        return handle, txPHY, rxPHY;
800
801    def __leSetExtAdvParameters(self):
802        if self.__checkSize(5):
803            power = struct.unpack('<b', self.data[4:5])[0];
804            self.__checkSelectedTXPower(power);
805        else:
806            power = 0;
807        return (power,);
808
809    def __leReadMaxAdvDataLength(self):
810        if self.__checkSize(6):
811            maxLength = struct.unpack('<H', self.data[4:6])[0];
812            self.__checkMaxAdvDataLength(maxLength);
813        else:
814            maxLength = 0;
815        return (maxLength,);
816
817    def __leReadNoOfSupportedAdvSets(self):
818        if self.__checkSize(5):
819            maxSets = struct.unpack('<B', self.data[4:5])[0];
820            self.__checkSupportedAdvSets(maxSets);
821        else:
822            maxSets = 0;
823        return (maxSets,);
824
825    def __leReadTransmitPower(self):
826        if self.__checkSize(6):
827            minPower, maxPower = struct.unpack('<bb', self.data[4:6]);
828            self.__checkSelectedTXPower(minPower);
829            self.__checkSelectedTXPower(maxPower);
830        else:
831            minPower = maxPower = 0;
832        return minPower, maxPower;
833
834    def __leReadRFPathCompensation(self):
835        if self.__checkSize(8):
836            txPCValue, rxPCValue = struct.unpack('<hh', self.data[4:8]);
837            self.__checkRFPathCompensation(txPCValue);
838            self.__checkRFPathCompensation(rxPCValue);
839        else:
840            txPCValue = rxPCValue = 0;
841        return txPCValue, rxPCValue;
842
843    def __leSetCigParameters(self):
844        if self.__checkMinSize(6):
845            cigId, cisCount = struct.unpack('<BB', self.data[4:6])
846        else:
847            cigId = cisCount = 0
848
849        if self.__checkSize(6+cisCount*2):
850            connectionHandle = struct.unpack('<' + str(cisCount) + 'H', self.data[6:6+cisCount*2])
851        else:
852            connectionHandle = None
853        return cigId, cisCount, connectionHandle
854
855    def __leSetCigParametersTest(self):
856        return self.__leSetCigParameters()
857
858    def __leRemoveCig(self):
859        if self.__checkSize(5):
860            cigId = struct.unpack('<B', self.data[4:5])[0]
861        else:
862            cigId = 0
863        return (cigId,)
864
865    def __leRejectCisRequest(self):
866        if self.__checkSize(6):
867            connectionHandle = struct.unpack('<H', self.data[4:6])[0]
868            self.__checkConnectionHandle(connectionHandle)
869        else:
870            connectionHandle = 0
871        return (connectionHandle,)
872
873    def __leSetupIsoPath(self):
874        if self.__checkSize(6):
875            connectionHandle = struct.unpack('<H', self.data[4:6])[0]
876            self.__checkConnectionHandle(connectionHandle)
877        else:
878            connectionHandle = 0
879        return (connectionHandle,)
880
881    def __leRemoveIsoPath(self):
882        if self.__checkSize(6):
883            connectionHandle = struct.unpack('<H', self.data[4:6])[0]
884            self.__checkConnectionHandle(connectionHandle)
885        else:
886            connectionHandle = 0
887        return (connectionHandle,)
888
889    def __leIsoTransmitTest(self):
890        if self.__checkSize(6):
891            connectionHandle = struct.unpack('<H', self.data[4:6])[0]
892            self.__checkConnectionHandle(connectionHandle)
893        else:
894            connectionHandle = 0
895        return (connectionHandle,)
896
897    def __leIsoReceiveTest(self):
898        if self.__checkSize(6):
899            connectionHandle = struct.unpack('<H', self.data[4:6])[0]
900            self.__checkConnectionHandle(connectionHandle)
901        else:
902            connectionHandle = 0
903        return (connectionHandle,)
904
905    def __leIsoReadTestCounters(self):
906        if self.__checkSize(18):
907            connectionHandle, receivedSduCount, missedSduCount, failedSduCount = struct.unpack('<HIII', self.data[4:18])
908            self.__checkConnectionHandle(connectionHandle)
909        else:
910            connectionHandle = 0
911        return connectionHandle, receivedSduCount, missedSduCount, failedSduCount
912
913    def __leIsoTestEnd(self):
914        return self.__leIsoReadTestCounters()
915
916
917    """ ================================================================================
918
919           The above private methods were all sub-sets of the Command Complete Event
920
921        ================================================================================ """
922
923    def __commandComplete(self):
924        if self.size >= 4:
925            numPackets, opCode, status = struct.unpack('<BHB', self.data[:4]);
926            if opCode in self.__cceFuncs__:
927                return (numPackets, opCode, status) + self.__cceFuncs__[opCode](self);
928        else:
929            numPackets = opCode = status = 0;
930        self.__checkSize(4);
931        return numPackets, opCode, status;
932
933    def __commandStatus(self):
934        if self.__checkSize(4):
935            status, numPackets, opCode = struct.unpack('<BBH', self.data[:4]);
936            if not (opCode in CmdOpcodes._value2member_map_):
937                self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_COMMAND_STATUS_OPCODE);
938        else:
939            numPackets = opCode = status = 0;
940        return numPackets, opCode, status;
941
942    def __hardwareError(self):
943        if self.__checkSize(1):
944            error = struct.unpack('<B', self.data[:1])[0];
945        else:
946            error = 0;
947        return (error,);
948
949    def __completedPackets(self):
950        numHandles = struct.unpack('<B', self.data[:1])[0] if self.size > 0 else 0;
951        handles = []
952        packets = []
953        if self.__checkSize(1 + 4*numHandles):
954            for i in range(numHandles):
955                handles.append(struct.unpack_from('<H', self.data, 1+i*4)[0])
956                packets.append(struct.unpack_from('<H', self.data, 3+i*4)[0])
957            for handle in handles:
958                self.__checkConnectionHandle(handle);
959        return numHandles, handles, packets;
960
961    def __dataBufferOverflow(self):
962        if self.__checkSize(1):
963            linkType = struct.unpack('<B', self.data[:1])[0];
964            self.__checkLinkType(linkType);
965        else:
966            linkType = 0;
967        return (linkType,);
968
969    def __encryptionKeyRefreshComplete(self):
970        if self.__checkSize(3):
971            status, handle = struct.unpack('<BH', self.data[:3]);
972            self.__checkConnectionHandle(handle);
973        else:
974            status = handle = 0;
975        return status, handle;
976
977    def __authenticatedPayloadTimeout(self):
978        if self.__checkSize(2):
979            handle = struct.unpack('<H', self.data[:2])[0];
980            self.__checkConnectionHandle(handle);
981        else:
982            handle = 0;
983        return (handle,);
984
985    def __connectionComplete(self):
986        if self.__checkSize(19):
987            status, handle, role, addressType = struct.unpack('<BHBB', self.data[1:6]);
988            address = struct.unpack('<6B', self.data[6:12]);
989            interval, latency, timeout, accuracy = struct.unpack('<HHHB', self.data[12:19]);
990            self.__checkConnectionHandle(handle);
991            self.__checkConnectionRole(role);
992            self.__checkAddressType(addressType, [0,1]);
993            self.__checkConnectionInterval(interval);
994            self.__checkConnectionLatency(latency);
995            self.__checkSupervisionTimeout(timeout);
996            self.__checkCentralClockAccuracy(accuracy);
997        else:
998            status = handle = role = addressType = interval = latency = timeout = accuracy = 0;
999            address = None;
1000        return status, handle, role, Address(addressType, address), interval, latency, timeout, accuracy;
1001
1002    def __advertisingReport(self):
1003        if self.__checkMinSize(12):
1004            reports, event, addressType = struct.unpack('<BBB', self.data[1:4]);
1005            address = struct.unpack('<6B', self.data[4:10]);
1006            dataSize = struct.unpack('<B', self.data[10:11])[0];
1007            if self.__checkSize(12 + dataSize):
1008                if dataSize > 0:
1009                    data = list(struct.unpack('<' + str(dataSize) + 'B', self.data[11:11+dataSize]));
1010                else:
1011                    data = [];
1012                rssi = struct.unpack('b', self.data[11+dataSize:12+dataSize])[0];
1013            else:
1014                rssi, data = 0, [];
1015            self.__checkAdvEvent(event);
1016            self.__checkAddressType(addressType);
1017            self.__checkAdvDataLength(dataSize);
1018            self.__checkRSSI(rssi);
1019        else:
1020            event, addressType, rssi, address, data = 0, 0, 0, None, [];
1021        return event, Address(addressType, address), data, rssi;
1022
1023    def __connectionUpdateComplete(self):
1024        if self.__checkSize(10):
1025            status, handle, interval, latency, timeout = struct.unpack('<BHHHH', self.data[1:10]);
1026            self.__checkConnectionHandle(handle);
1027            self.__checkConnectionInterval(interval);
1028            self.__checkConnectionLatency(latency);
1029            self.__checkSupervisionTimeout(timeout);
1030        else:
1031            status = handle = interval = latency = timeout = 0;
1032        return status, handle, interval, latency, timeout;
1033
1034    def __remoteFeaturesComplete(self):
1035        if self.__checkSize(12):
1036            status, handle = struct.unpack('<BH', self.data[1:4]);
1037            features = struct.unpack('<8B', self.data[4:12]);
1038            self.__checkConnectionHandle(handle);
1039        else:
1040            status, handle, features = 0, 0, [0 for _ in range(8)];
1041        return status, handle, self.__asNumber(features);
1042
1043    def __leLTKRequest(self):
1044        if self.__checkSize(13):
1045            handle = struct.unpack('<H', self.data[1:3])[0];
1046            number = struct.unpack('<8B', self.data[3:11]);
1047            diversifier = struct.unpack('<H', self.data[11:13])[0];
1048            self.__checkConnectionHandle(handle);
1049        else:
1050            handle, number, diversifier = 0, [0 for _ in range(8)], 0;
1051        return handle, self.__asNumber(number), diversifier;
1052
1053    def __connectionParameterRequest(self):
1054        if self.__checkSize(11):
1055            handle, minInterval, maxInterval, latency, timeout = struct.unpack('<HHHHH', self.data[1:11]);
1056            self.__checkConnectionHandle(handle);
1057            self.__checkConnectionInterval(minInterval);
1058            self.__checkConnectionInterval(maxInterval);
1059            self.__checkConnectionLatency(latency);
1060            self.__checkSupervisionTimeout(timeout);
1061            if not (minInterval <= maxInterval):
1062                self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_PARAMETER_INTERRELATION);
1063        else:
1064            handle = minInterval = maxInterval = latency = timeout = 0;
1065        return handle, minInterval, maxInterval, latency, timeout;
1066
1067    def __dataLengthChange(self):
1068        if self.__checkSize(11):
1069            handle, maxTxOctets, maxTxTime, maxRxOctets, maxRxTime = struct.unpack('<HHHHH', self.data[1:11]);
1070            self.__checkConnectionHandle(handle);
1071            self.__checkMaxDataOctets(maxTxOctets);
1072            self.__checkMaxDataTransmitTime(maxTxTime);
1073            self.__checkMaxDataOctets(maxRxOctets);
1074            self.__checkMaxDataTransmitTime(maxRxTime);
1075        else:
1076            handle = maxTxOctets = maxTxTime = maxRxOctets = maxRxTime = 0;
1077        return handle, maxTxOctets, maxTxTime, maxRxOctets, maxRxTime;
1078
1079    def __publicKeyComplete(self):
1080        if self.__checkSize(66):
1081            status = struct.unpack('<B', self.data[1:2])[0];
1082            key = struct.unpack('<64B', self.data[2:66]);
1083        else:
1084            status, key = 0, [0 for _ in range(64)];
1085        return status, self.__asNumber(key);
1086
1087    def __generateDHKeyComplete(self):
1088        if self.__checkSize(34):
1089            status = struct.unpack('<B', self.data[1:2])[0];
1090            key = struct.unpack('<32B', self.data[2:34]);
1091        else:
1092            status, key = 0, [0 for _ in range(32)];
1093        return status, self.__asNumber(key);
1094
1095    def __enhancedConnectionComplete(self):
1096        if self.__checkSize(31):
1097            status, handle, role, addressType = struct.unpack('<BHBB', self.data[1:6]);
1098            peerAddress = struct.unpack('<6B', self.data[6:12]);
1099            localResolvableAddress = struct.unpack('<6B', self.data[12:18]);
1100            peerResolvableAddress = struct.unpack('<6B', self.data[18:24]);
1101            interval, latency, timeout, accuracy = struct.unpack('<HHHB', self.data[24:31]);
1102            if status == 0:
1103                self.__checkConnectionHandle(handle);
1104                self.__checkConnectionRole(role);
1105                self.__checkAddressType(addressType);
1106                self.__checkConnectionInterval(interval);
1107                self.__checkConnectionLatency(latency);
1108                self.__checkSupervisionTimeout(timeout);
1109                self.__checkCentralClockAccuracy(accuracy);
1110        else:
1111            status = handle = role = addressType = interval = latency = timeout = accuracy = 0;
1112            peerAddress = localResolvableAddress = peerResolvableAddress = None;
1113        return status, handle, role, Address(addressType, peerAddress), Address(None, localResolvableAddress), Address(None, peerResolvableAddress), \
1114               interval, latency, timeout, accuracy;
1115
1116    def __directAdvertisingReport(self):
1117        if self.__checkSize(18):
1118            reports, event, addressType = struct.unpack('<BBB', self.data[1:4]);
1119            address = struct.unpack('<6B', self.data[4:10]);
1120            directAddressType = struct.unpack('<B', self.data[10:11])[0];
1121            directAddress = struct.unpack('<6B', self.data[11:17]);
1122            rssi = struct.unpack('<b', self.data[17:18])[0];
1123            self.__checkAdvertisingReports(reports);
1124            self.__checkAdvEvent(event, 1, 1);
1125            self.__checkAddressType(addressType);
1126            self.__checkAddressType(directAddressType, [1]);
1127            self.__checkRSSI(rssi);
1128        else:
1129            event = addressType = directAddressType = rssi = 0;
1130            address = directAddress = None;
1131        return event, Address(addressType, address), Address(directAddressType, directAddress), rssi;
1132
1133    def __phyUpdateComplete(self):
1134        if self.__checkSize(6):
1135            status, handle, txPhysical, rxPhysical = struct.unpack('<BHBB', self.data[1:6]);
1136            self.__checkConnectionHandle(handle);
1137            self.__checkPhy(txPhysical);
1138            self.__checkPhy(rxPhysical);
1139        else:
1140            status = handle = txPhysical = rxPhysical = 0;
1141        return status, handle, txPhysical, rxPhysical;
1142
1143    def __extendedAdvertisingReport(self):
1144        if self.__checkMinSize(26):
1145            reports, eventType, addressType = struct.unpack('<BHB', self.data[1:5]);
1146            address = struct.unpack('<6B', self.data[5:11]);
1147            priPHY, secPHY, sid, txPower, rssi, interval, dirAddressType = struct.unpack('<BBBbbHB', self.data[11:19]);
1148            dirAddress = struct.unpack('<6B', self.data[19:25]);
1149            dataSize = struct.unpack('<B', self.data[25:26])[0];
1150            if self.__checkSize(26 + dataSize):
1151                if dataSize > 0:
1152                    data = list(struct.unpack('<' + str(dataSize) + 'B', self.data[26:26+dataSize]));
1153                else:
1154                    data = [];
1155            else:
1156                data = [];
1157            self.__checkAdvertisingReports(reports, 1, 10);
1158            self.__checkAdvEvent(eventType, 0, 0x7F);
1159            self.__checkAddressType(addressType, [0,1,2,3,255]);
1160            self.__checkPhy(priPHY, [1,3]);
1161            self.__checkPhy(secPHY, [0,1,2,3]);
1162            self.__checkSid(sid, [_ for _ in range(16)] + [255]);
1163            self.__checkSelectedTXPower(txPower, -127, 127);
1164            self.__checkRSSI(rssi);
1165            self.__checkPeriodicAdvInterval(interval);
1166            self.__checkAddressType(dirAddressType, [0,1,2,3,254]);
1167            self.__checkAdvDataLength(dataSize, 229);
1168        else:
1169            eventType = addressType = priPHY = secPHY = sid = txPower = rssi = interval = dirAddressType = 0;
1170            address, dirAddress, data = None, None, [];
1171        return eventType, Address(addressType, address), priPHY, secPHY, sid, txPower, rssi, interval, Address(dirAddressType, dirAddress), data;
1172
1173    def __periodicAdvertisingSync(self):
1174        if self.__checkSize(16):
1175            status, handle, sid, addressType = struct.unpack('<BHBB', self.data[1:6]);
1176            address = struct.unpack('<6B', self.data[6:12]);
1177            phy, interval, accuracy = struct.unpack('<BHB', self.data[12:16]);
1178            self.__checkSyncHandle(handle);
1179            self.__checkSid(sid, [_ for _ in range(16)]);
1180            self.__checkAddressType(addressType);
1181            self.__checkPhy(phy);
1182            self.__checkPeriodicAdvInterval(interval);
1183            self.__checkCentralClockAccuracy(accuracy);
1184        else:
1185            status = handle = sid = addressType = phy = interval = accuracy = 0;
1186            address = None;
1187        return status, handle, sid, Address(addressType, address), phy, interval, accuracy;
1188
1189    def __periodicAdvertisingReport(self):
1190        if self.__checkMinSize(8):
1191            handle, txPower, rssi, unUsed, dataStatus, dataSize = struct.unpack('<HbbBBB', self.data[1:8]);
1192            if self.__checkSize(8 + dataSize):
1193                if dataSize > 0:
1194                    data = list(struct.unpack('<' + str(dataSize) + 'B', self.data[8:8+dataSize]));
1195                else:
1196                    data = [];
1197                self.__checkSyncHandle(handle);
1198                self.__checkSelectedTXPower(txPower, -127, 127);
1199                self.__checkRSSI(rssi);
1200                self.__checkAdvDataStatus(dataStatus);
1201                self.__checkAdvDataLength(dataSize, 248);
1202                if not (unUsed == 0xFF):
1203                    self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_ADV_UNUSED_VALUE);
1204            else:
1205                data = [];
1206        else:
1207            handle, txPower, rssi, dataStatus, data = 0, 0, 0, 0, [];
1208        return handle, txPower, rssi, dataStatus, data;
1209
1210    def __periodicAdvertisingSyncLost(self):
1211        if self.__checkSize(3):
1212            handle = struct.unpack('<H', self.data[1:3])[0];
1213            self.__checkSyncHandle(handle);
1214        else:
1215            handle = 0;
1216        return (handle,);
1217
1218    def __scanTimeout(self):
1219        self.__checkSize(1);
1220        return (None,);
1221
1222    def __advertiseSetTerminated(self):
1223        if self.__checkSize(6):
1224            status, advertiseHandle, connectionHandle, completedEvents = struct.unpack('<BBHB', self.data[1:6]);
1225            self.__checkAdvertisingHandle(advertiseHandle);
1226            if status == 0:
1227                self.__checkConnectionHandle(connectionHandle)
1228        else:
1229            status = advertiseHandle = connectionHandle = completedEvents = 0;
1230        return status, advertiseHandle, connectionHandle, completedEvents;
1231
1232    def __scanRequestReceived(self):
1233        if self.__checkSize(9):
1234            handle, addressType = struct.unpack('<BB', self.data[1:3]);
1235            address = struct.unpack('<6B', self.data[3:9]);
1236            self.__checkAdvertisingHandle(handle);
1237            self.__checkAddressType(addressType);
1238        else:
1239            handle, addressType, address = 0, 0, None;
1240        return handle, Address(addressType, address);
1241
1242    def __channnelSelectionAlgorithm(self):
1243        if self.__checkSize(4):
1244            handle, algorithm = struct.unpack('<HB', self.data[1:4]);
1245            self.__checkConnectionHandle(handle);
1246            self.__checkChannelAlgorithm(algorithm);
1247        else:
1248            handle = algorithm = 0;
1249        return handle, algorithm;
1250
1251    def __cisEstablished(self):
1252        if self.__checkSize(29):
1253            status, connectionHandle = struct.unpack('<BH', self.data[1:4])
1254            cigSyncDelay = struct.unpack('<3B', self.data[4:7])
1255            cisSyncDelay = struct.unpack('<3B', self.data[7:10])
1256            transportLatencyMToS = struct.unpack('<3B', self.data[10:13])
1257            transportLatencySToM = struct.unpack('<3B', self.data[13:16])
1258            phyMToS, phySToM, nse = struct.unpack('<BBB', self.data[16:19])
1259            bNMToS, bNSToM, fTMToS, fTSToM = struct.unpack('<BBBB', self.data[19:23])
1260            maxPduMToS, maxPduSToM, isoInterval = struct.unpack('<HHH', self.data[23:29])
1261
1262            if status == 0:
1263                self.__checkConnectionHandle(connectionHandle)
1264                self.__checkPhy(phyMToS)
1265                self.__checkPhy(phySToM)
1266        else:
1267            status = connectionHandle = phyMToS = phySToM = nse = bNMToS = bNSToM = fTMToS = fTSToM = maxPduMToS = maxPduSToM = isoInterval = 0
1268            cigSyncDelay = cisSyncDelay = transportLatencyMToS = transportLatencySToM = None
1269
1270        return status, connectionHandle, toNumber(cigSyncDelay), toNumber(cisSyncDelay), toNumber(transportLatencyMToS), toNumber(transportLatencySToM), \
1271               phyMToS, phySToM, nse, bNMToS, bNSToM, fTMToS, fTSToM, maxPduMToS, maxPduSToM, isoInterval
1272
1273    def __cisRequest(self):
1274        if self.__checkSize(7):
1275            aclConnectionHandle, cisConnectionHandle, cigId, cisId = struct.unpack('<HHBB', self.data[1:7])
1276
1277            self.__checkConnectionHandle(aclConnectionHandle)
1278            self.__checkConnectionHandle(cisConnectionHandle)
1279        else:
1280            aclConnectionHandle = cisConnectionHandle = cigId = cisId = 0
1281
1282        return aclConnectionHandle, cisConnectionHandle, cigId, cisId
1283
1284    def __request_peer_sca_complete(self):
1285        if self.__checkSize(5):
1286            status, connectionHandle, peerClockAccuracy = struct.unpack('<BHB', self.data[1:5])
1287
1288            if status == 0:
1289                self.__checkConnectionHandle(connectionHandle)
1290                self.__checkPeerClockAccuracy(peerClockAccuracy)
1291        else:
1292            status = connectionHandle = peerClockAccuracy = 0
1293
1294        return status, connectionHandle, peerClockAccuracy
1295
1296
1297    def __metaEvent(self):
1298        if self.subEvent in self.__metaFuncs__:
1299            return self.__metaFuncs__[self.subEvent](self);
1300        else:
1301            raise Exception('LE Meta Event with invalid sub-event 0x%02X' % self.subEvent)
1302
1303    def decode(self):
1304        if not self.values is None:
1305            return self.values;
1306        elif self.event in self.__eventFuncs__:
1307            self.values = self.__eventFuncs__[self.event](self);
1308            if not len(self.errors) == 0:
1309                raise Exception('Illegal values in event data! Event: 0x%02X,0x%02X Errors: %s' % (self.event, self.subEvent, self.errors));
1310            return self.values;
1311        else:
1312            self.errors.add(ErrorCodes.BT_HCI_ERR_BAD_EVENT);
1313            raise Exception('Illegal Event with event code 0x%02X' % self.event);
1314
1315    def isCommandComplete(self):
1316        return self.event == Events.BT_HCI_EVT_CMD_COMPLETE;
1317
1318    def isCommandStatus(self):
1319        return self.event == Events.BT_HCI_EVT_CMD_STATUS;
1320
1321    def __str__(self):
1322        if self.event in self.__eventFormats__:
1323            if self.values is None:
1324                self.decode();
1325            if Events.BT_HCI_EVT_LE_META_EVENT != self.event:
1326                if Events.BT_HCI_EVT_CMD_COMPLETE == self.event and self.values[1] in self.__cceFormats__:
1327                    return self.__cceFormats__[self.values[1]].format(*self.values);
1328                elif Events.BT_HCI_EVT_CMD_STATUS == self.event and self.values[1] in self.__cseFormats__:
1329                    return self.__cseFormats__[self.values[1]].format(*self.values);
1330                else:
1331                    return self.__eventFormats__[self.event].format(*self.values);
1332            else:
1333                if self.subEvent in self.__metaFormats__:
1334                    return self.__metaFormats__[self.subEvent].format(*self.values);
1335                else:
1336                    raise Exception('LE Meta Event with invalid sub-event 0x%02X' % self.subEvent);
1337        else:
1338            raise Exception('Illegal Event with event code 0x%02X' % event);
1339
1340
1341    __metaFuncs__  = { MetaEvents.BT_HCI_EVT_LE_CONN_COMPLETE:            __connectionComplete,
1342                       MetaEvents.BT_HCI_EVT_LE_ADVERTISING_REPORT:       __advertisingReport,
1343                       MetaEvents.BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE:     __connectionUpdateComplete,
1344                       MetaEvents.BT_HCI_EVT_LE_REMOTE_FEAT_COMPLETE:     __remoteFeaturesComplete,
1345                       MetaEvents.BT_HCI_EVT_LE_LTK_REQUEST:              __leLTKRequest,
1346                       MetaEvents.BT_HCI_EVT_LE_CONN_PARAM_REQ:           __connectionParameterRequest,
1347                       MetaEvents.BT_HCI_EVT_LE_DATA_LEN_CHANGE:          __dataLengthChange,
1348                       MetaEvents.BT_HCI_EVT_LE_P256_PUBLIC_KEY_COMPLETE: __publicKeyComplete,
1349                       MetaEvents.BT_HCI_EVT_LE_GENERATE_DHKEY_COMPLETE:  __generateDHKeyComplete,
1350                       MetaEvents.BT_HCI_EVT_LE_ENH_CONN_COMPLETE:        __enhancedConnectionComplete,
1351                       MetaEvents.BT_HCI_EVT_LE_DIRECT_ADV_REPORT:        __directAdvertisingReport,
1352                       MetaEvents.BT_HCI_EVT_LE_PHY_UPDATE_COMPLETE:      __phyUpdateComplete,
1353                       MetaEvents.BT_HCI_EVT_LE_EXT_ADVERTISING_REPORT:   __extendedAdvertisingReport,
1354                       MetaEvents.BT_HCI_EVT_LE_PER_ADV_SYNC_ESTABLISHED: __periodicAdvertisingSync,
1355                       MetaEvents.BT_HCI_EVT_LE_PER_ADVERTISING_REPORT:   __periodicAdvertisingReport,
1356                       MetaEvents.BT_HCI_EVT_LE_PER_ADV_SYNC_LOST:        __periodicAdvertisingSyncLost,
1357                       MetaEvents.BT_HCI_EVT_LE_SCAN_TIMEOUT:             __scanTimeout,
1358                       MetaEvents.BT_HCI_EVT_LE_ADV_SET_TERMINATED:       __advertiseSetTerminated,
1359                       MetaEvents.BT_HCI_EVT_LE_SCAN_REQ_RECEIVED:        __scanRequestReceived,
1360                       MetaEvents.BT_HCI_EVT_LE_CHAN_SEL_ALGO:            __channnelSelectionAlgorithm,
1361                       MetaEvents.BT_HCI_EVT_LE_CIS_ESTABLISHED:          __cisEstablished,
1362                       MetaEvents.BT_HCI_EVT_LE_CIS_REQUEST:              __cisRequest,
1363                       MetaEvents.BT_HCI_EVT_LE_REQUEST_PEER_SCA_COMPLETE:  __request_peer_sca_complete,
1364                       }
1365
1366    __eventFuncs__ = { Events.BT_HCI_EVT_DISCONN_COMPLETE:                __disconnectComplete,
1367                       Events.BT_HCI_EVT_ENCRYPT_CHANGE_V1:               __encryptionChangeV1,
1368                       Events.BT_HCI_EVT_REMOTE_VERSION_INFO:             __RemoteVersionComplete,
1369                       Events.BT_HCI_EVT_CMD_COMPLETE:                    __commandComplete,
1370                       Events.BT_HCI_EVT_CMD_STATUS:                      __commandStatus,
1371                       Events.BT_HCI_EVT_HARDWARE_ERROR:                  __hardwareError,
1372                       Events.BT_HCI_EVT_NUM_COMPLETED_PACKETS:           __completedPackets,
1373                       Events.BT_HCI_EVT_DATA_BUF_OVERFLOW:               __dataBufferOverflow,
1374                       Events.BT_HCI_EVT_ENCRYPT_KEY_REFRESH_COMPLETE:    __encryptionKeyRefreshComplete,
1375                       Events.BT_HCI_EVT_LE_META_EVENT:                   __metaEvent,
1376                       Events.BT_HCI_EVT_AUTH_PAYLOAD_TIMEOUT_EXP:        __authenticatedPayloadTimeout,
1377                       Events.BT_HCI_EVT_ENCRYPT_CHANGE_V2:               __encryptionChangeV2,
1378                       }
1379
1380    __cceFuncs__ =   { CmdOpcodes.BT_HCI_OP_READ_TX_POWER_LEVEL:          __readTXPowerLevel,
1381                       CmdOpcodes.BT_HCI_OP_LE_READ_LE_HOST_SUPP:         __readLEHostSupport,
1382                       CmdOpcodes.BT_HCI_OP_READ_AUTH_PAYLOAD_TIMEOUT:    __readAuthPayloadTimeout,
1383                       CmdOpcodes.BT_HCI_OP_WRITE_AUTH_PAYLOAD_TIMEOUT:   __writeAuthPayloadTimeout,
1384                       CmdOpcodes.BT_HCI_OP_READ_LOCAL_VERSION_INFO:      __readLocalVersionInformation,
1385                       CmdOpcodes.BT_HCI_OP_READ_SUPPORTED_COMMANDS:      __readLocalSupportedCommands,
1386                       CmdOpcodes.BT_HCI_OP_READ_LOCAL_FEATURES:          __readLocalSupportedFeatures,
1387                       CmdOpcodes.BT_HCI_OP_READ_BUFFER_SIZE:             __readBufferSize,
1388                       CmdOpcodes.BT_HCI_OP_READ_BD_ADDR:                 __readBDAddress,
1389                       CmdOpcodes.BT_HCI_OP_READ_RSSI:                    __readRssi,
1390                       CmdOpcodes.BT_HCI_OP_LE_READ_BUFFER_SIZE:          __leReadBufferSize,
1391                       CmdOpcodes.BT_HCI_OP_LE_READ_LOCAL_FEATURES: 	  __leReadLocalSupportedFeatures,
1392                       CmdOpcodes.BT_HCI_OP_LE_READ_ADV_CHAN_TX_POWER: 	  __leReadAdvChannelTXPower,
1393                       CmdOpcodes.BT_HCI_OP_LE_READ_FAL_SIZE:              __leReadListSize,
1394                       CmdOpcodes.BT_HCI_OP_LE_READ_CHAN_MAP:             __leReadChannelMap,
1395                       CmdOpcodes.BT_HCI_OP_LE_ENCRYPT:                   __leEncrypt,
1396                       CmdOpcodes.BT_HCI_OP_LE_RAND:                      __leRand,
1397                       CmdOpcodes.BT_HCI_OP_LE_LTK_REQ_REPLY:             __leLTKRequestReply,
1398                       CmdOpcodes.BT_HCI_OP_LE_LTK_REQ_NEG_REPLY:         __leLTKRequestReply,
1399                       CmdOpcodes.BT_HCI_OP_LE_READ_SUPP_STATES:          __leReadSupportedStates,
1400                       CmdOpcodes.BT_HCI_OP_LE_TEST_END:                  __leTestEnd,
1401                       CmdOpcodes.BT_HCI_OP_LE_CONN_PARAM_REQ_REPLY:      __leRemoteConnectionParameterRequest,
1402                       CmdOpcodes.BT_HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY:  __leRemoteConnectionParameterRequest,
1403                       CmdOpcodes.BT_HCI_OP_LE_SET_DATA_LEN:              __leSetDataLength,
1404                       CmdOpcodes.BT_HCI_OP_LE_READ_DEFAULT_DATA_LEN:     __leReadDefaultDataLength,
1405                       CmdOpcodes.BT_HCI_OP_LE_READ_RL_SIZE:              __leReadListSize,
1406                       CmdOpcodes.BT_HCI_OP_LE_READ_PEER_RPA:             __leReadResolvableAddress,
1407                       CmdOpcodes.BT_HCI_OP_LE_READ_LOCAL_RPA:            __leReadResolvableAddress,
1408                       CmdOpcodes.BT_HCI_OP_LE_READ_MAX_DATA_LEN:         __leReadMaximumDataLength,
1409                       CmdOpcodes.BT_HCI_OP_LE_READ_PHY:                  __leReadPHY,
1410                       CmdOpcodes.BT_HCI_OP_LE_SET_EXT_ADV_PARAM:         __leSetExtAdvParameters,
1411                       CmdOpcodes.BT_HCI_OP_LE_READ_MAX_ADV_DATA_LEN:     __leReadMaxAdvDataLength,
1412                       CmdOpcodes.BT_HCI_OP_LE_READ_NUM_ADV_SETS:         __leReadNoOfSupportedAdvSets,
1413                       CmdOpcodes.BT_HCI_OP_LE_READ_PER_ADV_LIST_SIZE:    __leReadListSize,
1414                       CmdOpcodes.BT_HCI_OP_LE_READ_TX_POWER:             __leReadTransmitPower,
1415                       CmdOpcodes.BT_HCI_OP_LE_READ_RF_PATH_COMP:         __leReadRFPathCompensation,
1416                       CmdOpcodes.BT_HCI_OP_LE_SET_CIG_PARAMETERS:        __leSetCigParameters,
1417                       CmdOpcodes.BT_HCI_OP_LE_SET_CIG_PARAMETERS_TEST:   __leSetCigParametersTest,
1418                       CmdOpcodes.BT_HCI_OP_LE_REMOVE_CIG:                __leRemoveCig,
1419                       CmdOpcodes.BT_HCI_OP_LE_REJECT_CIS_REQUEST:        __leRejectCisRequest,
1420                       CmdOpcodes.BT_HCI_OP_LE_SETUP_ISO_DATA_PATH:       __leSetupIsoPath,
1421                       CmdOpcodes.BT_HCI_OP_LE_REMOVE_ISO_DATA_PATH:      __leRemoveIsoPath,
1422                       CmdOpcodes.BT_HCI_OP_LE_ISO_TRANSMIT_TEST:         __leIsoTransmitTest,
1423                       CmdOpcodes.BT_HCI_OP_LE_ISO_RECEIVE_TEST:          __leIsoReceiveTest,
1424                       CmdOpcodes.BT_HCI_OP_LE_ISO_READ_TEST_COUNTERS:    __leIsoReadTestCounters,
1425                       CmdOpcodes.BT_HCI_OP_LE_ISO_TEST_END:              __leIsoTestEnd,
1426                       CmdOpcodes.BT_HCI_OP_LE_READ_BUFFER_SIZE_V2:       __leReadBufferSizeV2,
1427                       }
1428