Skip to content

shipped · · 6 min

How the connector reads six kinds of terminal: one contract, two relays, and nothing that writes

ZKTeco over its binary protocol on 4370, ZKTeco pushing over ADMS, Hikvision over ISAPI, Dahua over CGI, Sintech's UDP push, and now the FK family on 5005. How each is found on an office network, how each proves which terminal it is, what is read, and the rule that the connector cannot send a command that changes a terminal's records.

Part 3 of the fifth-protocol series. The earlier readers post goes deep on four brands. This one is the map: every kind of terminal the connector handles after the site visit, on one page, and where the new one fits.

figure 1 · six ways in, one contract
ZKTecobinary protocol · TCP 4370ZKTeco pushADMS over HTTP · to the PCHikvisionISAPI · HTTP with digestDahuaCGI · HTTP with digestSintech32-byte UDP datagramsFK family (new)binary protocol · TCP 5005connectorreader contractInfo · PunchesUsersrelays · spoolplatformHTTPS outsolid: the PC asks · dashed: the terminal sends
Found by
TCP knock on 5005, then its hello must answer
Proves it is the right terminal by
no serial on the wire: the network ID and address stand in
What is read
count, log blocks, a name per staff number
Never sent
four commands exist in the package; anything else is refused before the wire
Four families are read by the PC through one small Go interface. Two send by themselves and are relayed. Pick one to see how it is found, how it proves which terminal it is, and what the connector will never send it.

One contract

Every terminal the PC asks is behind one small Go interface:

terminal
type Reader interface {
	Info(ctx context.Context) (Info, error)                              // alive; how many punches; no log walk
	Punches(ctx context.Context, since, until time.Time) ([]Punch, error) // (since, until]
	Users(ctx context.Context) ([]User, error)
	Close() error
}

A registry maps a family name to a constructor. The runner does not know which protocol it is talking to: it opens a reader for a terminal, reads from where it last stopped, and closes it. Optional abilities, such as reading or setting a clock, are separate interfaces found with a type check, so a family that cannot do them simply does not have them.

Adding the FK family was one new package that registers itself:

terminal
func init() {
	machine.Register("fk", func(t machine.Target) (machine.Reader, error) { return New(t), nil })
}

and one line on the platform's side allowing the family name, so a terminal of that kind goes on its PC's reading list.

The six

FamilyOn the wireWho talks firstHow it is foundHow it proves which terminal it is
ZKTecobinary protocol, TCP 4370the PCa TCP knock on 4370, then the MAC's vendor prefixsays its serial before any read
ZKTeco pushADMS over HTTP, to the PCthe terminalit calls in with its serialits serial in every request
HikvisionISAPI, HTTP with digestthe PCSADP multicast probeits serial from deviceInfo
DahuaCGI, HTTP with digestthe PCDHIP multicast probeits serial from magicBox
Sintech32-byte UDP datagramsthe terminalits keypad menu points it at the PCits serial in every datagram
FK familybinary protocol, TCP 5005the PCa TCP knock on 5005, then its hello must answernone on the wire: network ID and address

The two that talk first are not readers. The connector relays them: it receives what they send, keeps it on disk, and passes it on. It does not instruct them.

Finding a terminal that does not announce itself

Hikvision and Dahua answer a multicast question on the local network. The binary protocols answer nothing until spoken to, so the search knocks: it opens a TCP connection to each likely port on each address and closes it, sending nothing.

A port that accepts a connection is not proof of a terminal. Port 5005 in particular is a common developer port. So for the FK family the knock is followed by the protocol's hello, a read, and an address is listed as a terminal only if the hello answers in that protocol. A terminal with a communication password answers the hello with "no", which is still an answer in the protocol: it is listed, and marked as having a password.

When nothing answers a probe, the network ID can still help. The first half of a MAC address names the maker of the network chip. That is a hint, never an identity: several terminal brands use the same chip makers, and this terminal used a locally administered MAC that names no maker at all. Finding machines that do not announce themselves has the full search.

Proving it is the right terminal

Reading the wrong terminal is worse than reading none: punches land on the wrong office's attendance. So every reader starts by checking the terminal is the one on the platform's list. Four families say their serial; the connector compares it before reading anything.

The FK family has no serial request in its protocol. It is known instead by its network ID, read from the PC's address table, and by the address it was set up at. When the terminal moves, the search accepts it at a new address only if its network ID or its newest punch matches the one on record.

Read-only by construction

The FK package can send four requests: hello, record count, a block of the log, and a name for a staff number. There is no constant in the package for anything else, and the function that sends requests refuses any command not on that list before it reaches the network:

terminal
var sendable = map[byte]bool{cmdPing: true, cmdCount: true, cmdBlock: true, cmdName: true}

func (r *Reader) request(ctx context.Context, cmd byte, args [10]byte, more int) (...) {
	if !sendable[cmd] {
		return 0, nil, fmt.Errorf("command %#x is not one this connector sends", cmd)
	}
	...
}

The ZKTeco package is built the same way. In both families there are commands that clear the attendance log, and a reader that cannot express them cannot send them by mistake: not through a bug, not through a typo, not through a well-meaning "try this" on site. A test checks that only those requests ever reach the test terminal.

The HTTP families can set a clock, and only when someone asks. Nothing else is written to any terminal.

What each one costs to read

FamilyA read asks forFilter by time on the terminal?
ZKTecothe whole logno
Hikvisionevents in a time window, page by pageyes
Dahuarecords in a time windowyes
FK familythe whole log, in 1,024-byte blocksno

The two binary families send everything every time and the connector filters. For the FK terminal on the day, that was about 16,000 records of 20 bytes, roughly 330 KB, in about twenty seconds over the LAN. Fine once a minute for one terminal; the code notes the upgrade path, reading from the end backwards, for when a full terminal proves slow.

The rest of the connector

Everything after the reader is shared by all six:

  • A spool on disk. Punches are written before they are sent, and removed only when the platform has them. An outage on either side is a delay, not a loss.
  • A reading position per terminal. The first read of a terminal starts from now; older punches are an explicit request, uploaded day by day.
  • A machine list from the platform, every few minutes: which terminals to read, at which address, port and device number.
  • Outbound HTTPS only. Nothing on the office network is opened to the internet.

The architecture post has all of it. The point of this map is smaller: a sixth kind of terminal was one new package, one name on the platform's list, and the same rule as the others. It cannot write.

Working through something like this? I help teams ship AI and cloud systems that hold up, and cost what they should.