vendor/ holds the camera's 16 MB NOR dump (backup-ssc377d-nor16m.bin), the vendor update V3.6.1.3, and their unpacked trees, which the RE tools and notes read. verify.py now defaults to vendor/flash_dump_ssc377d, and the docs point at vendor/ instead of folders beside the checkout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EfVNki7giKruPunvux6dDA
14 KiB
MC-L18D lens board (AF / zoom) serial protocol
Decoded from the vendor comm_server and media_server in
backup-ssc377d-nor16m.bin (app V3.4.5.2, built 2025-11-06). The method was
static disassembly plus running the vendor's own code in an ARM emulator.
af-board-re/verify.py re-derives every frame below from the binaries: 40 checks,
all passing. Nothing here was observed on a real board. The board's side is
inferred from what the camera sends and what it accepts back.
This replaces the earlier note in MCL18D-PORT.md ("115200 baud, FC 01
protocol"). That note was wrong for this camera. The FC frames belong to
af_protocol_5_flag builds and to other products. The 115200-baud 0x51
channel is the _MY customer's upgrade port on /dev/ttyS4. Both are listed
under "Other variants" below.
Link
| Port | /dev/ttyS2 (FUART, connector D7 TX/RX), the same port as a Pelco pan/tilt head |
| Line | 57600 8N1, used whenever /opt/ch/af.flag exists. This overrides PTZConfig BaudRate (2400). _WTD customer builds use 115200. A number in /opt/ch/diy_baudrate overrides both. |
| Direction | Both ways. The camera streams AF data and Pelco-D to the board; the board sends its own 51 01 04 78 status frames back, and the vendor's media_server reads them (thread_af_console_data). An earlier version of this table said the camera never reads the port; that was wrong. |
One wire carries four kinds of traffic:
- Pelco-D commands for zoom, focus, iris, presets and pan/tilt.
- AF data frames, one per ISP frame, carrying focus values computed from the ISP's AF statistics.
- Detection-box frames, forwarded unchanged.
- A version query at boot, and the firmware upgrade.
What this camera is set to
| Setting | Value on the device | Effect |
|---|---|---|
/opt/ch/af.flag |
present | lens board on ttyS2 at 57600, version query at boot |
/opt/ch/af_protocol_5_flag |
absent | AF data in the 0x51 format, not FC |
customer (/etc/filesys.ver, /etc/flag.customize) |
_ASKP |
no _MY / _WTD / _TV variant |
| product type | 0x681 | no product-specific gain scaling |
AfConfig type (/mnt/nand/config.xml) |
1 | AF frames from CAfV2 (18 bytes) |
AfConfig type (factory config.default.mcl18d.xml) |
2 | AF frames from CAfV3 (16 bytes) |
AfConfig bSendOnStart |
1 | AF frames are always forwarded |
AfConfig bSendCoordinate, /opt/ch/send_hd_coordinate.flag |
1, present | detection boxes are forwarded |
AfConfig type selects the sender: 0 → V1, 1 → V2, 2 → V3, 3 → V4, 4 → V5,
anything else → V1. Three things override it:
/opt/ch/diy_afconfigN(N = 1–6) selects VN directly.- The
_MYcustomer forces V6. flag.tv.af5.version,flag.af.ptz.wtd, or the_TVcustomer on product 1538 force V5.
1. Commands: Pelco-D
FF addr b2 b3 d1 d2 sum: address 1, and sum is the sum of bytes 1–5. The
board takes standard Pelco-D, and the vendor sends it unwrapped.
| Verb (web / ONVIF / CGI) | Frame |
|---|---|
| zoom tele / wide | FF 01 00 20 ss ss cs / FF 01 00 40 ss ss cs |
focus near / far (FocusNearAutoOff / FocusFarAutoOff) |
FF 01 01 00 30 30 62 / FF 01 00 80 30 30 E1 |
iris open / close (IrisOpenAutoOff / IrisCloseAutoOff) |
FF 01 02 00 30 30 63 / FF 01 04 00 30 30 65 |
| stop | FF 01 00 00 00 00 01 |
| up / down / left / right | FF 01 00 08 00 ss / 00 10 00 ss / 00 04 ss 00 / 00 02 ss 00 (+ sum) |
| diagonals | 0C / 14 / 0A / 12 with both speeds |
| goto / set / clear preset n | FF 01 00 07 00 nn / 00 03 00 nn / 00 05 00 nn (+ sum) |
- Speed
ss: the request's speed level 0–10 maps to 0x05–0x37 in steps of 5. Any other value gives 0x1E. - Zoom: zoom frames carry the pan/tilt speed in both data bytes.
- Focus and iris: these always use 0x30.
- Bare
focusnear/focusfar: these verbs send the stop frame. The web page and CGI only ever send the…AutoOffforms.
2. AF data: camera to board
media_server waits for each ISP frame, with a 500 ms timeout, and reads the
AF statistics. It builds one frame from them and sends it to comm_server,
which writes it to the port unchanged. At 30 fps that is about 30 frames a second.
comm_server writes a frame only if it is longer than 3 bytes and one of these holds:
bSendOnStartis set, or- the last PTZ command was under 300 s ago and the customer is not
_Y_.
/opt/ch/flag.af.init.disable holds frames back until the first PTZ move.
Focus values
The ISP AF statistics are five arrays of 16 windows. Each value is 40 bits, little-endian, so each array is 80 bytes. The senders add arrays 0, 1, 3 and 4 and skip array 2. That fits the SigmaStar layout high-IIR, low-IIR, luma, vertical FIR, horizontal FIR, but the names are inferred from the layout.
- FV(w) = Σ over arrays {0,1,3,4} of (stat[a][w] >> 6)
- Sent as two bytes:
(FV >> 11) & FF, then(FV >> 3) & FF. That is FV/8 as a 16-bit big-endian value, truncated. - Window 0 covers (19,19)–(1003,1003) of the 0–1023 normalised frame, almost the whole picture.
- Window 1 covers (170,170)–(850,850), the central two-thirds. For
type 3it is (334,334)–(668,668). - So FV0 is whole-frame sharpness and FV1 is centre sharpness.
CAfV2: this camera's live setting, 18 bytes
| Byte | Content |
|---|---|
| 0–5 | 51 01 04 78 01 11 |
| 6–7 | FV window 0 |
| 8–9 | FV window 1 |
| 10 | total gain, (sensor gain / 1024) × (ISP gain / 1024), truncated to an integer |
| 11 | bits 7–4: main-stream width class, where ≥4000 → 7, ≥3840 → 6, ≥3072 → 5, ≥2592 → 4, ≥2560 → 3, ≥2304 → 2, ≥1920 → 1, ≥1080 → 0, smaller → 4. Bit 0 is 1 at night. |
| 12–13 | bits 23–16, then 15–8, of stat[0][window 1] (raw) |
| 14 | IR-cut mode setting (the STREAM_FEATURE_IRCUT mode) |
| 15 | IR lamp brightness, % |
| 16 | white lamp brightness, % |
| 17 | sum of bytes 0–16 |
CAfV3: factory default, 16 bytes
51 01 04 78 01 0D, FV0 (2 bytes), FV1 (2 bytes), then:
- gain (divided by 30 on product types 1566, 1569, 1698–1700 and 1921; not this camera)
- night (1 or 0)
- IR-cut mode
- IR lamp %
- white lamp %
- sum
Other senders
| Sender | Length | Layout |
|---|---|---|
| V1 | 14 | 51 01 04 78 01 0D, FV0, FV1, gain, night, IR-cut mode, sum |
| V4 | 16 | as V3, but the IR-cut byte is mode | (second IR-cut field << 4) |
V6 (_MY) |
16 | 51 01 04 79 19 09, then FV0' and FV1' (arrays 0 and 1 only, sent as FV >> 10, FV >> 2), gain, night-or-lamp-on, IR-cut byte as in V4, IR %, white %, sum |
V5 (FC) |
16 | FC 14 1A 0A, then bits 23–8 of stat[1][1], bits 23–8 of stat[0][1], four status bytes from globals I did not identify, 2 or 5, the sum of bytes 0–13, and 00 |
Bytes 4 and 5 of the 0x51 frames are not a length. V1 and V3 both say 0D
but are 14 and 16 bytes long. Treat bytes 0–5 as a fixed header per sender.
3. Detection boxes: camera to board
When bSendCoordinate is set, comm_server writes media_server's
"Coordinatetrans" payloads unchanged. I saw two record formats:
- 9-byte records:
FF 01 91 00 x y w h .. - 7-byte records:
FF 01 C5 …, withC2on_WTDandtv.af5builds. The coordinates are scaled to 800 × 480.
These look like human-detection boxes for auto-tracking heads. I have not decoded them fully.
4. Version query at boot
thread_ptz runs this every time it starts with af.flag set, retrying up to three times until it gets an answer.
The result goes into /tmp/AF_version.txt and is shown in the app. The ASCII
commands end in the sum of their characters.
Camera sends: END + D7 eight times, 60 ms apart, then VER + ED.
Board replies with up to 11 bytes. The camera waits 100 ms, then reads with a 1 s select(), tried twice:
| Byte | Content |
|---|---|
| 0–2 | not checked (probably VER) |
| 3 | lens model, see below. Any other value fails, and the camera tries EXVER. |
| 4 | variant: for model 6, 0 is MX3901 and 1 is MS1134 |
| 5–6 | year, BCD (20 24) |
| 7 | month, BCD |
| 8 | day, BCD |
| 9–10 | not checked |
| Code | Lens |
|---|---|
| 01 / 02 | YUT-MX3901 2.7-13.5mm 200W / 2.8-12mm 200W |
| 03 / 04 | FTK-MX3901 2.8-12mm 300W / 500W |
| 05 | YUT-MX3901 2.7-13.5mm 500W |
| 06 | YUT-MX3901 (or MS1134) 2.7-13.5mm 800W |
| 07 / 08 | YUT-MX3901 2.8-8mm 400W / 500W |
| 09 | YUT-MX3901 6-22mm 300W |
| 10 / 11 | YUT-MX3901 5-50mm 200W / FTK-MX3901 6-22mm 500W |
| 12 / 13 | YUT-MX3901 3.6-11mm 4K / FH-MX3901 3.3-10mm |
| 14 / 15 | YUT-MX3901 2.7-12mm 500W / 2.8-8mm 800W |
| 20 / 21 | pan/tilt boards "PTZ- MODEL-020" / "PTZ - MODEL-021" |
Fallback, EXVER: the camera sends END + D7 eight times, then
EXVER + 8A. The board replies EXVER, a count n, n bytes of text, and the
sum of all the bytes before it. The text is the version string.
5. Firmware upgrade: same port, same speed
This is ttl_upgrade_proc_public, used when the app pushes a lens-board
image (/tmp/upguard_af.bin; the image names refer to an HK32 MCU). The board
pulls the image in 128-byte blocks by address:
| Step | Direction | Bytes |
|---|---|---|
| wake | camera to board | END + D7 fifteen times, 60 ms apart |
| start | camera to board | START + size as a 32-bit big-endian value + sum (10 bytes) |
| request | board to camera | DATA + address as a 32-bit big-endian value + 80 + sum (10 bytes). The first one is 44 41 54 41 00 00 00 00 80 9A. |
| block | camera to board | DATA + the same address + 80 + 128 bytes of image (the last block zero-padded) + the sum of bytes 0–136 (138 bytes) |
| done | board to camera | OK + 9A |
If the next request does not advance the address by 128, the camera resends the previous block. Do not try this without the vendor image and a way to recover the board.
Other variants in this comm_server (not this camera)
_MYcustomers: Pelco-D is wrapped as51 01 04 79 18 07+ the 7 Pelco bytes + the sum of all prior bytes, 14 bytes in total. Upgrades go through a separate envelope at 115200 on/dev/ttyS4:- frame:
51 01 04 79 <target> <len> <payload> <sum> - target, from the image name:
AF0x78,PTZ0x77,PWR0x76,BTL0x01 - data packet payload:
84 11, packet number as big-endian 16-bit, then data - board replies use the same envelope, and the camera checks header, length and sum
- frame:
FC 01 A3 01 00 A1: sent withechoto ttyS2 on product types 1813, 1817 and 1825 only.FC 01 B4 02 00 00 B3andFC 01 B4 02 00 01 B4: toggled by an alarm-light handler.FF 01 00 A0 00 F1 92: a status query for_WTDheads.
What this means for OpenIPC
Observed on the camera, 2026-10-28/29, OpenIPC with the keep-alive below. Every item here is measured, not inferred from the binaries, unless it says otherwise.
- The board sleeps without AF data. Plain Pelco-D on its own does nothing:
no pan, tilt, zoom or focus, no reply to the version query, and not a single
byte back (
/proc/tty/driverrx stayed 0 through a sweep of every baud from 2400 to 115200, Pelco-D at addresses 0 and 1, and Pelco-P). Five CAfV2 frames 33 ms apart wake it; one does not. Once awake it obeyed a plain Pelco-D frame 3 s after the last AF frame, and had gone back to sleep 40 s after. A frame every 100 ms kept it awake through every test. The vendor never sees this because it streams a frame per video frame from boot. - Waking takes about 20 s. The first stream after sleep starts a run of large focus moves (a homing pass, INFERRED from the picture) before it settles.
- The pan/tilt is behind the board. Pan and tilt answer only while the board is awake, at the same 57600 and address 1, so they share its gate.
pelco-ptz keepalivesendspelco_af_frame()everykeepalive_ms(default 100) andS94mcl18dstarts it at boot. Its values are constant, so the board's own autofocus has nothing real to climb; focus after a zoom is not managed. Commands frompelco-ptzgo out between its frames.- No absolute positions, no feedback. The head ignores Pelco-D set-position
(0x4B/0x4D/0x4F, also after 0x49 "set zero") and never answers the position
queries (0x51/0x53/0x55). Its presets work: set, move away, go to returns to
the stored view. So presets are this head's only absolute positions, and
onvif.confno longer offers AbsoluteMove/RelativeMove. - Board status frames. While something moves the board sends
51 01 04 78 01 0a 0a 10 3b 3b NN 21 3b 14 0f 3b <sum>.NNrose 02 to 03 on zoom-in and fell to 01 on zoom-out, so it looks like a coarse zoom step (INFERRED). Nothing in them changed with pan or tilt, and the board is silent while idle. mcl18d-afstill ships but is not part of the fix. It needs the keep-alive like everything else, majestic on this platform refuses its?crop=(HTTP 501, so it judges the whole frame), and the board's own focus moves under it. It has not given a good result on the camera.- Termios. The vendor's version query clears CREAD and still gets its reply
because the vendor kernel ignores CREAD. OpenIPC's
ms_uart.chonours it, so a reader here must set CREAD (pelco-ptzdoes). - Shared port. The whole port runs at 57600 when
af.flagis set, so a separate Pelco head on the same wires would have to run at 57600 too.
Reproducing
cd af-board-re
python3 -m pip install unicorn # in a venv
python3 verify.py # defaults to ../vendor/flash_dump_ssc377d
python3 od.py ../vendor/flash_dump_ssc377d/rootfs/opt/ch/comm_server 1bd64 1c1e0 # annotated disassembly
Addresses for the flash-dump build:
comm_server:
| Function | Address |
|---|---|
HandleYuntai (after its upgrade guard) |
0x43408 |
Get_AF_Version |
0x1bd64 |
Get_AF_Version_EX |
0x1b8a8 |
ttl_upgrade_proc_public |
0x1c270 |
PtzInitComm |
0x3b4f8 |
thread_ptz |
0x3bed8 |
media_server:
| Function | Address |
|---|---|
InitAf |
0x429a4 |
CAfV1 |
0x4d640 |
CAfV2 |
0x4e1c4 / 0x4dfcc |
CAfV3 |
0x4cfec / 0x4cde0 |
CAfV4 |
0x4dea8 |
CAfV5 |
0x4cb64 |
CAfV6 |
0x4d2a8 |