-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflic2_packets.h
More file actions
441 lines (384 loc) · 10.6 KB
/
flic2_packets.h
File metadata and controls
441 lines (384 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/**
* Flic 2 C module
*
* Copyright (C) 2022 Shortcut Labs AB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef FLIC2_PACKETS_H
#define FLIC2_PACKETS_H
#include <stdint.h>
#ifdef _MSC_VER
#pragma pack(push, 1)
#ifndef PACKED
#define PACKED
#endif
#else
#ifndef PACKED
#define PACKED __attribute__ ((packed))
#endif
#endif
enum OpcodeToFlic {
OPCODE_TO_FLIC_FULL_VERIFY_REQUEST_1,
OPCODE_TO_FLIC_FULL_VERIFY_REQUEST_2_WITH_APP_TOKEN,
OPCODE_TO_FLIC_FULL_VERIFY_REQUEST_2_WITHOUT_APP_TOKEN,
OPCODE_TO_FLIC_FULL_VERIFY_ABORT_IND,
OPCODE_TO_FLIC_TEST_IF_REALLY_UNPAIRED_REQUEST,
OPCODE_TO_FLIC_QUICK_VERIFY_REQUEST,
OPCODE_TO_FLIC_FORCE_BT_DISCONNECT_IND,
OPCODE_TO_FLIC_BLE_SECURITY_REQUEST_IND,
OPCODE_TO_FLIC_GET_FIRMWARE_VERSION_REQUEST,
OPCODE_TO_FLIC_DISCONNECT_VERIFIED_LINK_IND,
OPCODE_TO_FLIC_SET_NAME_REQUEST,
OPCODE_TO_FLIC_GET_NAME_REQUEST,
OPCODE_TO_FLIC_SET_CONNECTION_PARAMETERS_IND,
OPCODE_TO_FLIC_START_API_TIMER_IND,
OPCODE_TO_FLIC_PING_RESPONSE,
OPCODE_TO_FLIC_INIT_BUTTON_EVENTS_REQUEST,
OPCODE_TO_FLIC_ACK_BUTTON_EVENTS_IND,
OPCODE_TO_FLIC_START_FIRMWARE_UPDATE_REQUEST,
OPCODE_TO_FLIC_FIRMWARE_UPDATE_DATA_IND,
OPCODE_TO_FLIC_SET_AUTO_DISCONNECT_TIME_IND,
OPCODE_TO_FLIC_GET_BATTERY_LEVEL_REQUEST,
OPCODE_TO_FLIC_SET_HID_STATUS_REQUEST,
OPCODE_TO_FLIC_HID_NOTIFICATION,
OPCODE_TO_FLIC_INIT_BUTTON_EVENTS_LIGHT_REQUEST,
OPCODE_TO_FLIC_FACTORY_RESET_REQUEST,
OPCODE_TO_FLIC_GET_CURRENT_TIME_REQUEST,
OPCODE_TO_FLIC_GET_DEVICE_ID_REQUEST,
OPCODE_TO_FLIC_SET_ADV_PARAMETERS_REQUEST,
};
enum OpcodeFromFlic {
OPCODE_FROM_FLIC_FULL_VERIFY_RESPONSE_1,
OPCODE_FROM_FLIC_FULL_VERIFY_RESPONSE_2,
OPCODE_FROM_FLIC_NO_LOGICAL_CONNECTION_SLOTS_IND,
OPCODE_FROM_FLIC_FULL_VERIFY_FAIL_RESPONSE,
OPCODE_FROM_FLIC_TEST_IF_REALLY_UNPAIRED_RESPONSE,
OPCODE_FROM_FLIC_GET_FIRMWARE_VERSION_RESPONSE,
OPCODE_FROM_FLIC_QUICK_VERIFY_NEGATIVE_RESPONSE,
OPCODE_FROM_FLIC_PAIRING_FINISHED_IND,
OPCODE_FROM_FLIC_QUICK_VERIFY_RESPONSE,
OPCODE_FROM_FLIC_DISCONNECTED_VERIFIED_LINK_IND,
OPCODE_FROM_FLIC_INIT_BUTTON_EVENTS_RESPONSE_WITH_BOOT_ID,
OPCODE_FROM_FLIC_INIT_BUTTON_EVENTS_RESPONSE_WITHOUT_BOOT_ID,
OPCODE_FROM_FLIC_BUTTON_EVENT_NOTIFICATION,
OPCODE_FROM_FLIC_API_TIMER_NOTIFICATION,
OPCODE_FROM_FLIC_NAME_UPDATED_NOTIFICATION,
OPCODE_FROM_FLIC_PING_REQUEST,
OPCODE_FROM_FLIC_GET_NAME_RESPONSE,
OPCODE_FROM_FLIC_SET_NAME_RESPONSE,
OPCODE_FROM_FLIC_START_FIRMWARE_UPDATE_RESPONSE,
OPCODE_FROM_FLIC_FIRMWARE_UPDATE_NOTIFICATION,
OPCODE_FROM_FLIC_GET_BATTERY_LEVEL_RESPONSE,
OPCODE_FROM_FLIC_SERVICES_CHANGED_CONFIRMED_IND,
OPCODE_FROM_FLIC_FACTORY_RESET_RESPONSE,
OPCODE_FROM_FLIC_GET_CURRENT_TIME_RESPONSE,
OPCODE_FROM_FLIC_GET_DEVICE_ID_RESPONSE,
OPCODE_FROM_FLIC_SET_ADV_PARAMETERS_RESPONSE,
};
enum DisconnectLogicalConnectionReason {
DISCONNECT_LOGICAL_CONNECTION_REASON_PING_TIMEOUT,
DISCONNECT_LOGICAL_CONNECTION_REASON_INVALID_SIGNATURE,
DISCONNECT_LOGICAL_CONNECTION_REASON_STARTED_NEW_WITH_SAME_PAIRING_IDENTIFIER,
DISCONNECT_LOGICAL_CONNECTION_REASON_BY_USER
};
enum FullVerifyFailReason {
FULL_VERIFY_FAIL_REASON_INVALID_VERIFIER,
FULL_VERIFY_FAIL_REASON_NOT_IN_PUBLIC_MODE,
};
struct FullVerifyRequest1 {
uint8_t opcode;
uint32_t tmp_id;
} PACKED;
struct FullVerifyResponse1 {
uint8_t opcode;
uint32_t tmp_id;
uint8_t signature[64];
uint8_t address[6];
uint8_t address_type;
uint8_t ecdh_public_key[32];
uint8_t random_bytes[8];
uint8_t link_is_encrypted: 1;
uint8_t is_in_public_mode: 1;
uint8_t has_bond_info: 1;
uint8_t padding: 5;
} PACKED;
struct FullVerifyRequest2WithoutAppToken {
uint8_t opcode;
uint8_t ecdh_public_key[32];
uint8_t random_bytes[8];
uint8_t signature_variant: 3;
uint8_t encryption_variant: 3;
uint8_t must_validate_app_token: 1;
uint8_t padding: 1;
uint8_t verifier[16];
} PACKED;
struct FullVerifyRequest2WithAppToken {
uint8_t opcode;
uint8_t ecdh_public_key[32];
uint8_t random_bytes[8];
uint8_t signature_variant: 3;
uint8_t encryption_variant: 3;
uint8_t must_validate_app_token: 1;
uint8_t padding: 1;
uint8_t encrypted_app_token[16];
uint8_t verifier[16];
} PACKED;
struct FullVerifyResponse2 {
uint8_t opcode;
uint8_t app_credentials_match: 1;
uint8_t cares_about_app_credentials: 1;
uint8_t padding: 6;
uint8_t button_uuid[16];
uint8_t name_len;
char name[23];
uint32_t firmware_version;
uint16_t battery_level;
char serial_number[11];
} PACKED;
struct FullVerifyFailResponse {
uint8_t opcode;
uint8_t reason;
} PACKED;
struct TestIfReallyUnpairedRequest {
uint8_t opcode;
uint8_t ecdh_public_key[32];
uint8_t random_bytes[8];
uint32_t pairing_identifier;
uint8_t pairing_token[16];
} PACKED;
struct TestIfReallyUnpairedResponse {
uint8_t opcode;
uint8_t result[16];
} PACKED;
struct NoLogicalConnectionSlotsInd {
uint8_t opcode;
uint32_t tmp_ids[];
} PACKED;
struct DisconnectedVerifiedLinkInd {
uint8_t opcode;
uint8_t reason;
} PACKED;
struct QuickVerifyRequest {
uint8_t opcode;
uint8_t random_client_bytes[7];
uint8_t signature_variant: 3;
uint8_t encryption_variant: 3;
uint8_t padding: 2;
uint32_t tmp_id;
uint32_t pairing_identifier;
} PACKED;
struct QuickVerifyResponse {
uint8_t opcode;
uint8_t random_button_bytes[8];
uint32_t tmp_id;
uint8_t link_is_encrypted: 1;
uint8_t has_bond_info: 1;
uint8_t padding: 6;
} PACKED;
struct QuickVerifyNegativeResponse {
uint8_t opcode;
uint32_t tmp_id;
} PACKED;
struct PairingFinishedInd {
uint8_t opcode;
uint8_t success: 1;
uint8_t master_sent_fail: 1;
uint8_t padding: 6;
uint8_t reason;
} PACKED;
struct InitButtonEventsRequest {
uint8_t opcode;
uint32_t event_count;
uint32_t boot_id;
uint32_t auto_disconnect_time: 9;
uint32_t max_queued_packets: 5;
#ifdef _MSC_VER
uint32_t max_queued_packets_age_low : 18;
uint8_t max_queued_packets_age_high : 2;
#else
uint32_t max_queued_packets_age: 20;
#endif
uint8_t enable_hid: 1;
uint8_t padding: 5;
} PACKED;
struct InitButtonEventsResponseWithoutBootId {
uint8_t opcode;
uint32_t has_queued_events: 1;
#ifdef _MSC_VER
uint32_t timestamp_low : 31;
uint16_t timestamp_high;
#else
uint64_t timestamp: 47;
#endif
uint32_t event_count;
} PACKED;
struct InitButtonEventsResponseWithBootId {
uint8_t opcode;
uint32_t has_queued_events: 1;
#ifdef _MSC_VER
uint32_t timestamp_low : 31;
uint16_t timestamp_high;
#else
uint64_t timestamp: 47;
#endif
uint32_t event_count;
uint32_t boot_id;
} PACKED;
struct AckButtonEventsInd {
uint8_t opcode;
uint32_t event_count;
} PACKED;
struct ApiTimerInd {
uint8_t opcode;
uint32_t timeout; // ticks 32768 per second, 0 clears the timer
uint32_t message;
} PACKED;
struct ApiTimerNotification {
uint8_t opcode;
uint32_t message;
} PACKED;
struct NameUpdatedNotification {
uint8_t opcode;
char name[];
} PACKED;
struct GetNameResponse {
uint8_t opcode;
#ifdef _MSC_VER
uint32_t timestamp_utc_ms_low;
uint16_t timestamp_utc_ms_high;
#else
uint64_t timestamp_utc_ms: 48;
#endif
char name[];
} PACKED;
struct SetNameRequest {
uint8_t opcode;
#ifdef _MSC_VER
uint32_t timestamp_utc_ms_low;
uint16_t timestamp_utc_ms_high : 15;
#else
uint64_t timestamp_utc_ms: 47;
#endif
uint16_t force_update: 1;
char name[];
} PACKED;
struct SetNameResponse {
uint8_t opcode;
#ifdef _MSC_VER
uint32_t timestamp_utc_ms_low;
uint16_t timestamp_utc_ms_high;
#else
uint64_t timestamp_utc_ms: 48;
#endif
char name[];
} PACKED;
struct SetConnectionParametersInd {
uint8_t opcode;
uint16_t intv_min, intv_max, latency, timeout;
} PACKED;
struct ButtonEventNotificationItem {
#ifdef _MSC_VER
uint32_t timestamp_low;
uint16_t timestamp_high;
#else
uint64_t timestamp: 48;
#endif
uint8_t event_encoded: 4;
uint8_t was_queued: 1;
uint8_t was_queued_last: 1;
uint8_t padding: 2;
} PACKED;
struct ButtonEventNotification {
uint8_t opcode;
uint32_t press_counter;
struct ButtonEventNotificationItem events[];
} PACKED;
struct GetFirmwareVersionResponse {
uint8_t opcode;
uint32_t version;
} PACKED;
struct StartFirmwareUpdateRequest {
uint8_t opcode;
uint16_t len;
uint64_t iv;
uint16_t status_interval;
} PACKED;
struct StartFirmwareUpdateResponse {
uint8_t opcode;
int start_pos;
} PACKED;
struct FirmwareUpdateDataInd {
uint8_t opcode;
uint8_t data[];
} PACKED;
struct FirmwareUpdateNotification {
uint8_t opcode;
int pos;
} PACKED;
struct SetAutoDisconnectTimeInd {
uint8_t opcode;
uint16_t auto_disconnect_time: 9;
uint16_t padding: 7;
} PACKED;
struct GetBatteryLevelResponse {
uint8_t opcode;
uint16_t battery_level;
} PACKED;
struct SetHidStatusRequest {
uint8_t opcode;
uint8_t enable_hid: 1;
uint8_t padding: 7;
} PACKED;
struct ServicesChangedConfirmationInd {
uint8_t opcode;
uint8_t reason;
} PACKED;
struct ForceBtDisconnectInd {
uint8_t opcode;
bool restart_adv;
} PACKED;
struct HidNotification {
uint8_t opcode;
uint16_t page;
uint16_t usage_id;
uint16_t duration;
} PACKED;
struct FactoryResetResponse {
uint8_t opcode;
} PACKED;
struct GetCurrentTimeResponse {
uint64_t opcode: 8;
uint64_t time: 56;
} PACKED;
struct GetDeviceIdResponse {
uint8_t opcode;
uint8_t device_id[8];
} PACKED;
struct SetAdvParametersRequest {
uint8_t opcode;
bool is_active;
bool remove_other_pairings_adv_settings;
bool with_short_range;
bool with_long_range;
uint16_t adv_intervals[2]; // 0.625 ms units
uint32_t timeout_seconds;
} PACKED;
struct SetAdvParametersResponse {
uint8_t opcode;
} PACKED;
#ifdef _MSC_VER
#pragma pack(pop)
#endif
#endif