1# Copyright 2023 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Class to hold the Floss enums."""
15
16import enum
17
18
19class BtTransport(enum.IntEnum):
20    """Bluetooth transport type."""
21    AUTO = 0
22    BREDR = 1
23    LE = 2
24    DUAL = 3
25
26
27class GattWriteRequestStatus(enum.IntEnum):
28    """Gatt write request status."""
29    SUCCESS = 0
30    FAIL = 1
31    BUSY = 2
32
33
34class GattWriteType(enum.IntEnum):
35    """GATT write type."""
36    INVALID = 0
37    WRITE_NO_RSP = 1
38    WRITE = 2
39    WRITE_PREPARE = 3
40
41
42class LePhy(enum.IntEnum):
43    """Bluetooth LE physical type."""
44    INVALID = 0
45    PHY1M = 1
46    PHY2M = 2
47    PHY_CODED = 3
48
49
50class GattPermission(enum.IntEnum):
51    """Bluetooth GATT permissions."""
52    PERM_READ = (1 << 0)
53    PERM_READ_ENCRYPTED = (1 << 1)
54    PERM_READ_ENC_MITM = (1 << 2)
55    PERM_WRITE = (1 << 4)
56    PERM_WRITE_ENCRYPTED = (1 << 5)
57    PERM_WRITE_ENC_MITM = (1 << 6)
58    PERM_WRITE_SIGNED = (1 << 7)
59    PERM_WRITE_SIGNED_MITM = (1 << 8)
60    PERM_READ_IF_ENCRYPTED_OR_DISCOVERABLE = (1 << 9)
61
62
63class GattCharacteristicProprieties(enum.IntEnum):
64    """Bluetooth GATT characteristic proprieties."""
65    CHAR_PROP_BIT_BROADCAST = (1 << 0)
66    CHAR_PROP_BIT_READ = (1 << 1)
67    CHAR_PROP_BIT_WRITE_NR = (1 << 2)
68    CHAR_PROP_BIT_WRITE = (1 << 3)
69    CHAR_PROP_BIT_NOTIFY = (1 << 4)
70    CHAR_PROP_BIT_INDICATE = (1 << 5)
71    CHAR_PROP_BIT_AUTH = (1 << 6)
72    CHAR_PROP_BIT_EXT_PROP = (1 << 7)
73
74
75class GattStatus(enum.IntEnum):
76    """Bluetooth GATT return status."""
77    SUCCESS = 0x00
78    INVALID_HANDLE = 0x01
79    READ_NOT_PERMIT = 0x02
80    WRITE_NOT_PERMIT = 0x03
81    INVALID_PDU = 0x04
82    INSUF_AUTHENTICATION = 0x05
83    REQ_NOT_SUPPORTED = 0x06
84    INVALID_OFFSET = 0x07
85    INSUF_AUTHORIZATION = 0x08
86    PREPARE_Q_FULL = 0x09
87    NOT_FOUND = 0x0A
88    NOT_LONG = 0x0B
89    INSUF_KEY_SIZE = 0x0C
90    INVALID_ATTRLEN = 0x0D
91    ERR_UNLIKELY = 0x0E
92    INSUF_ENCRYPTION = 0x0F
93    UNSUPPORT_GRP_TYPE = 0x10
94    INSUF_RESOURCE = 0x11
95    DATABASE_OUT_OF_SYNC = 0x12
96    VALUE_NOT_ALLOWED = 0x13
97    ILLEGAL_PARAMETER = 0x87
98    TOO_SHORT = 0x7F
99    NO_RESOURCES = 0x80
100    INTERNAL_ERROR = 0x81
101    WRONG_STATE = 0x82
102    DB_FULL = 0x83
103    BUSY = 0x84
104    ERROR = 0x85
105    CMD_STARTED = 0x86
106    PENDING = 0x88
107    AUTH_FAIL = 0x89
108    MORE = 0x8A
109    INVALID_CFG = 0x8B
110    SERVICE_STARTED = 0x8C
111    ENCRYPTED_NO_MITM = 0x8D
112    NOT_ENCRYPTED = 0x8E
113    CONGESTED = 0x8F
114    DUP_REG = 0x90
115    ALREADY_OPEN = 0x91
116    CANCEL = 0x92
117
118
119class BtStatus(enum.IntEnum):
120    """Bluetooth return status."""
121    SUCCESS = 0
122    FAIL = 1
123    NOT_READY = 2
124    NO_MEMORY = 3
125    BUSY = 4
126    DONE = 5
127    UNSUPPORTED = 6
128    INVALID_PARAM = 7
129    UNHANDLED = 8
130    AUTH_FAILURE = 9
131    REMOTE_DEVICE_DOWN = 10
132    AUTH_REJECTED = 11
133    JNI_ENVIRONMENT_ERROR = 12
134    JNI_THREAD_ATTACH_ERROR = 13
135    WAKE_LOCK_ERROR = 14
136    BT_STATUS_TIMEOUT = 15
137    DEVICE_NOT_FOUND = 16
138    UNEXPECTED_STATE = 17
139    SOCKET_ERROR = 18
140
141
142class SocketType(enum.IntEnum):
143    """Socket types."""
144    GT_SOCK_ANY = 0
145    GT_SOCK_STREAM = 1
146    GT_SOCK_DGRAM = 2
147    GT_SOCK_RAW = 3
148    GT_SOCK_RDM = 4
149    GT_SOCK_SEQPACKET = 5
150    GT_SOCK_DCCP = 6
151    GT_SOCK_PACKET = 10
152
153
154class SuspendMode(enum.IntEnum):
155    """Bluetooth suspend mode."""
156    NORMAL = 0
157    SUSPENDING = 1
158    SUSPENDED = 2
159    RESUMING = 3
160
161
162class ScanType(enum.IntEnum):
163    """Bluetooth scan type."""
164    ACTIVE = 0
165    PASSIVE = 1
166
167
168class BondState(enum.IntEnum):
169    """Bluetooth bonding state."""
170    NOT_BONDED = 0
171    BONDING = 1
172    BONDED = 2
173
174
175class BtPropertyType(enum.IntEnum):
176    """Bluetooth's property type."""
177    BdName = 0x1
178    BdAddr = 0x2
179    Uuids = 0x3
180    ClassOfDevice = 0x4
181    TypeOfDevice = 0x5
182    ServiceRecord = 0x6
183    AdapterScanMode = 0x7
184    AdapterBondedDevices = 0x8
185    AdapterDiscoverableTimeout = 0x9
186    RemoteFriendlyName = 0xA
187    RemoteRssi = 0xB
188    RemoteVersionInfo = 0xC
189    LocalLeFeatures = 0xD
190    LocalIoCaps = 0xE
191    LocalIoCapsBle = 0xF
192    DynamicAudioBuffer = 0x10
193    RemoteIsCoordinatedSetMember = 0x11
194    Appearance = 0x12
195    VendorProductInfo = 0x13
196    # Unimplemented:
197    #  BT_PROPERTY_REMOTE_ASHA_CAPABILITY,
198    #  BT_PROPERTY_REMOTE_ASHA_TRUNCATED_HISYNCID,
199    #  BT_PROPERTY_REMOTE_MODEL_NUM,
200    RemoteAddrType = 0x18
201    Unknown = 0xFE
202    RemoteDeviceTimestamp = 0xFF
203
204
205class PairingVariant(enum.IntEnum):
206    """Bluetooth pairing variant type."""
207    # SSP variants.
208    PASSKEY_CONFIRMATION = 0
209    PASSKEY_ENTRY = 1
210    CONSENT = 2
211    PASSKEY_NOTIFICATION = 3
212
213    # Legacy pairing variants.
214    PIN_ENTRY = 4
215    PIN_16_DIGITS_ENTRY = 5
216    PIN_NOTIFICATION = 6
217
218
219class BleAddressType(enum.IntEnum):
220    BLE_ADDR_PUBLIC = 0x00
221    BLE_ADDR_RANDOM = 0x01
222    BLE_ADDR_PUBLIC_ID = 0x02
223    BLE_ADDR_RANDOM_ID = 0x03
224    BLE_ADDR_ANONYMOUS = 0xFF
225
226
227class OwnAddressType(enum.IntEnum):
228    DEFAULT = -1
229    PUBLIC = 0
230    RANDOM = 1
231
232
233class BtConnectionState(enum.IntEnum):
234    NOT_CONNECTED = 0
235    CONNECTED_ONLY = 1
236    ENCRYPTED_BR_EDR = 3
237    ENCRYPTED_LE = 5
238    ENCRYPTED_BOTH = 7
239
240
241class CompanyIdentifiers(enum.IntEnum):
242    """Bluetooth SIG Company ID values.
243
244    Bluetooth SIG official document: https://www.bluetooth.com/specifications/assigned-numbers/
245    """
246    GOOGLE = 0x00E0
247
248
249class AdvertisingDataType(enum.IntEnum):
250    FLAGS = 0x01
251    INCOMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS = 0x02
252    COMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS = 0x03
253    INCOMPLETE_LIST_OF_32_BIT_SERVICE_CLASS_UUIDS = 0x04
254    COMPLETE_LIST_OF_32_BIT_SERVICE_CLASS_UUIDS = 0x05
255    INCOMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS = 0x06
256    COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS = 0x07
257    SHORTENED_LOCAL_NAME = 0x08
258    COMPLETE_LOCAL_NAME = 0x09
259    TX_POWER_LEVEL = 0x0A
260    CLASS_OF_DEVICE = 0x0D
261    SLAVE_CONNECTION_INTERVAL_RANGE = 0x12
262    LIST_OF_16_BIT_SERVICE_SOLICITATION_UUIDS = 0x14
263    LIST_OF_128_BIT_SERVICE_SOLICITATION_UUIDS = 0x15
264    SERVICE_DATA_16_BIT_UUID = 0x16
265    PUBLIC_TARGET_ADDRESS = 0x17
266    RANDOM_TARGET_ADDRESS = 0x18
267    APPEARANCE = 0x19
268    ADVERTISING_INTERVAL = 0x1A
269    LIST_OF_32_BIT_SERVICE_SOLICITATION_UUIDS = 0x1F
270    SERVICE_DATA_32_BIT_UUID = 0x20
271    SERVICE_DATA_128_BIT_UUID = 0x21
272    URI = 0x24
273    LE_SUPPORTED_FEATURES = 0x27
274    MANUFACTURER_SPECIFIC_DATA = 0xFF
275
276
277class BtDiscMode(enum.IntEnum):
278    """Bluetooth discoverable mode."""
279    NON_DISCOVERABLE = 0
280    LIMITED_DISCOVERABLE = 1
281    GENERAL_DISCOVERABLE = 2
282
283
284class BthhReportType(enum.IntEnum):
285    """Bluetooth HID report type."""
286    INPUT_REPORT = 1
287    OUTPUT_REPORT = 2
288    FEATURE_REPORT = 3
289