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
//! Protocol command codes and flags used by ZKTeco terminals.
//!
//! These mirror the constants in `pyzk`'s `zk/const.py`, which in turn come from
//! the ZKTeco `zkemsdk` SDK headers. They are protocol facts (numbers sent on the
//! wire), documented here so the rest of the crate never uses bare magic numbers.
/// Maximum value of an unsigned 16-bit integer. The protocol uses 16-bit reply
/// IDs and a 16-bit checksum, both of which wrap around this value.
pub const USHRT_MAX: u16 = 65535;
// --- Commands the host sends to the device -------------------------------------
/// Read some kind of bulk data from the machine.
pub const CMD_DB_RRQ: u16 = 7;
/// Upload (create/update) a user record.
pub const CMD_USER_WRQ: u16 = 8;
/// Read fingerprint templates / bulk user data.
pub const CMD_USERTEMP_RRQ: u16 = 9;
/// Upload a fingerprint template.
pub const CMD_USERTEMP_WRQ: u16 = 10;
/// Read a configuration parameter (string key/value).
pub const CMD_OPTIONS_RRQ: u16 = 11;
/// Write a configuration parameter.
pub const CMD_OPTIONS_WRQ: u16 = 12;
/// Read all attendance records.
pub const CMD_ATTLOG_RRQ: u16 = 13;
/// Clear all data (users, attendance, templates).
pub const CMD_CLEAR_DATA: u16 = 14;
/// Clear attendance records only.
pub const CMD_CLEAR_ATTLOG: u16 = 15;
/// Delete a user.
pub const CMD_DELETE_USER: u16 = 18;
/// Delete a fingerprint template.
pub const CMD_DELETE_USERTEMP: u16 = 19;
/// Cancel/clear the administrator flag.
pub const CMD_CLEAR_ADMIN: u16 = 20;
/// Unlock combination read.
pub const CMD_ULG_RRQ: u16 = 29;
/// Read free sizes / device capacity counters.
pub const CMD_GET_FREE_SIZES: u16 = 50;
/// Put the device into the normal working state.
pub const CMD_ENABLE_CLOCK: u16 = 57;
/// Enter verify state (used around enroll/live capture).
pub const CMD_STARTVERIFY: u16 = 60;
/// Begin enrolling a user/finger.
pub const CMD_STARTENROLL: u16 = 61;
/// Cancel an in-progress capture and return to idle.
pub const CMD_CANCELCAPTURE: u16 = 62;
/// Query device state.
pub const CMD_STATE_RRQ: u16 = 64;
/// Write a line of text to the LCD.
pub const CMD_WRITE_LCD: u16 = 66;
/// Clear the LCD.
pub const CMD_CLEAR_LCD: u16 = 67;
/// Get the configured user-id (PIN) width.
pub const CMD_GET_PINWIDTH: u16 = 69;
/// Query door state.
pub const CMD_DOORSTATE_RRQ: u16 = 75;
/// (Undocumented) get one user's template by `(uid, finger id)`.
pub const CMD_GET_USERTEMP: u16 = 88;
/// (Undocumented) save a user plus multiple templates in one shot.
pub const CMD_SAVE_USERTEMPS: u16 = 110;
/// (Undocumented) delete one user template by `(user_id, finger id)`.
pub const CMD_DEL_USER_TEMP: u16 = 134;
/// Get the device's clock.
pub const CMD_GET_TIME: u16 = 201;
/// Set the device's clock.
pub const CMD_SET_TIME: u16 = 202;
/// Register for real-time events (e.g. live attendance).
pub const CMD_REG_EVENT: u16 = 500;
/// Open a session (connect).
pub const CMD_CONNECT: u16 = 1000;
/// Close the session (disconnect).
pub const CMD_EXIT: u16 = 1001;
/// Re-enable the device (allow user interaction).
pub const CMD_ENABLEDEVICE: u16 = 1002;
/// Disable the device (lock out user interaction during bulk operations).
pub const CMD_DISABLEDEVICE: u16 = 1003;
/// Restart the device.
pub const CMD_RESTART: u16 = 1004;
/// Power the device off.
pub const CMD_POWEROFF: u16 = 1005;
/// Refresh the device's internal data after writes.
pub const CMD_REFRESHDATA: u16 = 1013;
/// Play a test voice/beep by index.
pub const CMD_TESTVOICE: u16 = 1017;
/// Get the firmware version string.
pub const CMD_GET_VERSION: u16 = 1100;
/// Authenticate with a scrambled comm-key (when the device requires a password).
pub const CMD_AUTH: u16 = 1102;
/// Device announces it is about to send `size` bytes of data.
pub const CMD_PREPARE_DATA: u16 = 1500;
/// A data packet (chunk).
pub const CMD_DATA: u16 = 1501;
/// Clear the device's open data buffer.
pub const CMD_FREE_DATA: u16 = 1502;
/// (Undocumented) initialize a buffer for partial/chunked reads.
pub const CMD_PREPARE_BUFFER: u16 = 1503;
/// (Undocumented) read a partial chunk from the prepared buffer.
pub const CMD_READ_BUFFER: u16 = 1504;
/// Unlock the door for a number of seconds.
pub const CMD_UNLOCK: u16 = 31;
// --- Replies the device sends back ---------------------------------------------
/// Command succeeded.
pub const CMD_ACK_OK: u16 = 2000;
/// Command failed.
pub const CMD_ACK_ERROR: u16 = 2001;
/// Returned data.
pub const CMD_ACK_DATA: u16 = 2002;
/// A registered event occurred.
pub const CMD_ACK_RETRY: u16 = 2003;
/// Connection not authorized — the device wants a comm-key (`CMD_AUTH`).
pub const CMD_ACK_UNAUTH: u16 = 2005;
/// Unknown command (also used by `clear_error`).
pub const CMD_ACK_UNKNOWN: u16 = 0xffff;
// --- Real-time event flags (bitmask for `reg_event`) ---------------------------
/// Real-time attendance verification succeeded (a punch).
pub const EF_ATTLOG: u32 = 1;
/// Real-time fingerprint press.
pub const EF_FINGER: u32 = 1 << 1;
/// Real-time user enrollment.
pub const EF_ENROLLUSER: u32 = 1 << 2;
/// Real-time finger enrollment.
pub const EF_ENROLLFINGER: u32 = 1 << 3;
/// Real-time button press.
pub const EF_BUTTON: u32 = 1 << 4;
/// Real-time unlock.
pub const EF_UNLOCK: u32 = 1 << 5;
/// Real-time fingerprint verification.
pub const EF_VERIFY: u32 = 1 << 7;
/// Real-time fingerprint minutia capture.
pub const EF_FPFTR: u32 = 1 << 8;
/// Alarm signal.
pub const EF_ALARM: u32 = 1 << 9;
// --- "Function code" selectors for buffered reads (`read_with_buffer`) ----------
/// Attendance log dataset.
pub const FCT_ATTLOG: i16 = 1;
/// Fingerprint template dataset.
pub const FCT_FINGERTMP: i16 = 2;
/// Operation log dataset.
pub const FCT_OPLOG: i16 = 4;
/// User dataset.
pub const FCT_USER: i16 = 5;
/// SMS dataset.
pub const FCT_SMS: i16 = 6;
/// User-data dataset.
pub const FCT_UDATA: i16 = 7;
/// Work-code dataset.
pub const FCT_WORKCODE: i16 = 8;
// --- TCP framing magic ----------------------------------------------------------
/// First half of the 4-byte magic that prefixes every TCP packet (`0x5050`).
pub const MACHINE_PREPARE_DATA_1: u16 = 20560;
/// Second half of the TCP magic (`0x7282`).
pub const MACHINE_PREPARE_DATA_2: u16 = 32130;