cvend
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cvend [2026-11-22 23:42 UTC (5 days ago)] – cvend deep dive, codes gathered from unstripped binaries on device, and some example c code and math qkb | cvend [2026-11-23 00:56 UTC (5 days ago)] (current) – fix Ultralight reply header to remove emdash qkb | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== cVEND NFC Reader ====== | ====== cVEND NFC Reader ====== | ||
| - | The cVEND is the NFC reader on the bottom half of the PM3. It is a FEIG cVEND | + | cVEND is the NFC reader on the bottom half of the PM3 |
| - | module with its own ARM CPU and embedded Linux, not just a UART peripheral. | + | |
| {{ : | {{ : | ||
| - | The host serial | + | The associated |
| - | The reader application reports version 02.35 and model string | + | ===== cVEND protocol notes ===== |
| - | '' | + | |
| - | The boot sequence was captured on the serial line with a Saleae | + | Boot-up / initialization |
| - | {{ : | + | |
| - | ===== Hardware and provisioning limits ===== | + | {{ : |
| - | The SAM, ISAM, HSM key, Girogo, ITSO, VDV-KA, and EMV configuration paths are | + | ==== IPP packet structure ==== |
| - | present in the firmware, but a surplus unit does not have the matching hardware, | + | |
| - | keys, or EMV config. The protocol table describes the firmware; it does not mean | + | |
| - | those paths work on every unit. | + | |
| + | ^ offset ^ length ^ name ^ description ^ | ||
| + | | 0 | 1 | | always 0xBC | | ||
| + | | 1 | 1 | '' | ||
| + | | 2 | 1 | '' | ||
| + | | 3 | 1 | '' | ||
| + | | 4 | 2 | '' | ||
| + | | 6 | 1 | '' | ||
| + | | 7 | '' | ||
| + | | 7+'' | ||
| - | ===== Reading raw UIDs ===== | + | ==== IPP message types ==== |
| - | The reader | + | ^ msgType ^ dir ^ name ^ description ^ |
| - | frame for every card it sees. No keys, no nx, and no enable sequence are needed | + | | 0x02 | -> | Version | | |
| - | to read a UID. | + | | 0x03 | <- | VersionReply | (device ID from rockchip otp, firmware version, cwd) as length-prefixed strings\\ e.g. " |
| + | | 0x04 | -> | Status | | | ||
| + | | 0x05 | <- | StatusReply | e.g. " | ||
| + | | 0x07 | <- | Heartbeat| sent every ~3s by reader | | ||
| + | | 0x0f | <- | Startup | sent by reader after startup, approx 1 minute after power on, e.g. " | ||
| + | | 0x10 | -> | Reset | first byte selects subcommand (2 = restart application, | ||
| + | | 0x11 | <- | ResetReply | e.g. " | ||
| + | | 0x20 | -> | LEDs | sets LED status, u32 bitmap; all eight LEDs are in the low byte | | ||
| + | | 0x22 | -> | Buzzer | makes the cvend beep; u16 frequency, u16 duration. | ||
| + | | 0x32 | -> | CardRelease | // registered in ProxCardCtrl:: | ||
| + | | 0x46 | -> | AbortCardHandling | // | ||
| + | | 0x96 | -> | PutFile | | | ||
| + | | 0x97 | <- | PutFileReply | | | ||
| + | | 0x98 | -> | GetFile | '' | ||
| + | | 0x99 | <- | GetFileReply | '' | ||
| + | | 0x9a | -> | DeleteFile | | | ||
| + | | 0x9b | <- | DeleteFileReply | | | ||
| + | | 0x9c | -> | FileInfo | '' | ||
| + | | 0x9d | <- | FileInfoReply | '' | ||
| + | | 0xa4 | -> | FileList | '' | ||
| + | | 0xa5 | <- | FileListReply | '' | ||
| + | | 0xaa | -> | SetTime | payload is a timestamp | | ||
| + | | 0xab | <- | SetTimeReply | | | ||
| + | | 0xac | -> | ITSOData | // | ||
| + | | 0xad | <- | ITSODataReply | | | ||
| + | | 0xae | -> | ITSOCtrl | // | ||
| + | | 0xaf | <- | ITSOCtrlReply | | | ||
| + | | 0xb1 | <- | ISORead | sent by reader when ISO14443A | ||
| + | | 0xb3 | <- | ISOCardReleased | sent by reader after ISO1443A card released with 0x32 or 0x46 | | ||
| + | | 0xb4 | -> | APDUProx | DeviceSelect(0x00), | ||
| + | | 0xb5 | <- | APDUProxReply | DeviceSelect(0x00), | ||
| + | | 0xb6 | -> | SAMCtrl | // | ||
| + | | 0xb7 | <- | SAMCtrlReply | | | ||
| + | | 0xb9 | <- | DESFireRead | sent by reader when DESFire card presented, after enabling DESFire with 0xe4 | | ||
| + | | 0xba | -> | | //unknown, registered in ProxCardDesfire:: | ||
| + | | 0xbb | <- | DESFireCardRemoved | sent by reader when DESFire card removed from field | | ||
| + | | 0xbc | -> | DESFireCommand | sends desfire command, documented in {{ 0: | ||
| + | | 0xbd | <- | DESFireCommandReply | response | ||
| + | | 0xbe | <- | UnhandledCard | sent by reader when a card is presented that is not supported by any enabled ProxCardFunction, | ||
| + | | 0xce | -> | | //unknown, registered in IppHandling:: | ||
| + | | 0xd0 | -> | EMV | first byte selects subcommand (0 = load config, 1 = preprocess, 2 = toggle polling)\\ * load config followed by null terminated filename, which is read and passed to fetfpd '' | ||
| + | | 0xd1 | <- | EMVStatus | sent by reader after startup and certain nfc state changes, EMV-style BER-TLV | | ||
| + | | 0xd4 | -> | UltralightCommand | Sends a subcommand to the UltralightC/ | ||
| + | | 0xd5 | <- | UltralightReply | Unsolicited card event ('' | ||
| + | | 0xe4 | -> | ProxCardFunction | first 2 bytes specify function (4=VdvKa, 5=MifareClassic, | ||
| + | | 0xe5 | <- | ProxCardFunctionReply | Returns 4 byte payload: 0x00, the function number (as above), 0x00, 0x00 | | ||
| + | | 0xe6 | -> | | //unknown, registered in GirogoIppHandler:: | ||
| + | | 0xe8 | -> | SecurityServices | first byte selects subcommand (0=GetVersionOfKey, | ||
| + | | 0xe9 | <- | SecurityServicesReply | | | ||
| + | | 0xea | -> | | //unknown, registered in ProxCardMifareClassic:: | ||
| + | | 0xed | <- | Log | first byte specifies log level (1=INFO, 2=WARNING, 3=ERROR) followed by null-terminated human-readable log message | | ||
| - | | + | -> - Host to Reader\\ |
| - | - Do not send the nx init sequence. The '' | + | <- - Reader to Host |
| - | | + | |
| - | - Watch for '' | + | |
| - | Gate on the frame type. '' | + | ==== 0x20 LEDs ==== |
| - | '' | + | |
| - | the frame type produces phantom reads. | + | |
| - | Direct frames, with sequence 1 and no payload | + | The '' |
| - | < | + | ^ bit ^ LED ^ |
| - | stty -F / | + | | 0x01 | status row 1, green | |
| + | | 0x02 | status row 2, green | | ||
| + | | 0x04 | status row 3, green | | ||
| + | | 0x08 | status row 4, green | | ||
| + | | 0x10 | status row 3, amber (same LED as 0x04) | | ||
| + | | 0x20 | status row 4, red (same LED as 0x08) | | ||
| + | | 0x40 | NFC logo, right | | ||
| + | | 0x80 | NFC logo, left | | ||
| - | # Status keepalive | + | ==== 0xD5 UltralightReply for unsolicited card events ==== |
| - | printf ' | + | |
| - | # Version request | + | '' |
| - | printf | + | |
| - | # Restart the reader application | + | ^ byte 0 ^ meaning ^ payload ^ |
| - | printf | + | | 0x00 | Card entered field | byte 1 = 0x00 (purpose unknown); bytes 2–8 = 7-byte UID (cascade / double UID format, e.g. '' |
| + | | 0x01 | Card left field | byte 1 = 0x00 | | ||
| - | # Listen for frames | + | ==== 0xD4 UltralightCommand |
| - | timeout -t 3 dd if=/ | + | |
| - | </ | + | |
| - | The examples use sequence 1. Increment the sequence byte and recompute the CRC-8 | + | Host sends 0xD4 with '' |
| - | if you send more than one frame. The CRC only appears on frames | + | |
| - | '' | + | |
| - | ===== What the firmware handles ===== | + | Reply format: '' |
| - | The cVEND runs a complete card stack on its own ARM core. None of this happens | + | Status codes: '' |
| - | on the PM3's i.MX6: | + | |
| - | * RF field and ISO14443A/B anticollision. | + | ^ subcmd ^ name ^ request payload (after subcmd byte) ^ reply payload (after subcmd + status) ^ |
| - | * Polling for every card type the reader is configured to look for. | + | | 0x02 | Read | '' |
| - | * ISO14443-4 activation, ATS, and protocol selection. | + | | 0x03 | Write | '' |
| - | * DESFire native protocol and the EMV Level 2 kernel. | + | | 0x04 | Authenticate (raw key) | '' |
| - | * Card presence tracking and the LED/buzzer feedback. | + | | 0x05 | Authenticate (key index) | '' |
| + | | 0x06 | Authenticate (index + key) | '' | ||
| + | | 0x07 | Abort | //none// — exactly 1 byte total | //empty// | | ||
| + | | 0x00–0x01, | ||
| - | A host application never talks to a card. It opens the serial port and reads the | + | Notes: |
| - | frames the reader pushes. That is why a UID reader fits in one short file, | + | * Subcmds 0x02–0x07 are registered in '' |
| - | and it is also the ceiling: if the firmware does not poll a card type, no amount | + | * If no card is in the field, the device echoes '' |
| - | of host code makes it appear. | + | * To read all pages of an NTAG 215: send subcmd 0x02 with '' |
| - | The base scan is UID-only for the same reason. The reader activates the card, | + | ==== 0xD1 EMVStatus ==== |
| - | emits '' | + | |
| - | '' | + | |
| - | '' | + | |
| - | card type enabled and the reader' | + | |
| - | drives. See [[nx]] for that side. | + | |
| - | ===== Writing a host application ===== | + | '' |
| - | + | ||
| - | Every frame is the same seven-byte header, then the payload: | + | |
| - | + | ||
| - | < | + | |
| - | BC seq replyTo | + | |
| - | </ | + | |
| - | + | ||
| - | * '' | + | |
| - | * '' | + | |
| - | * '' | + | |
| - | * '' | + | |
| - | * A trailing CRC-32 appears only when '' | + | |
| - | + | ||
| - | Parse in the same order the reader does: find '' | + | |
| - | then wait until the declared length plus the optional trailer is buffered. | + | |
| - | A '' | + | |
| - | header CRC will not validate. | + | |
| - | + | ||
| - | A complete reader, no dependencies: | + | |
| - | + | ||
| - | < | + | |
| - | #include < | + | |
| - | #include < | + | |
| - | #include < | + | |
| - | #include < | + | |
| - | #include < | + | |
| - | #include < | + | |
| - | #include < | + | |
| - | #include < | + | |
| - | + | ||
| - | static uint8_t crc8(const uint8_t *p, size_t n) | + | |
| - | { | + | |
| - | uint8_t c = 0; | + | |
| - | while (n--) { | + | |
| - | c ^= *p++; | + | |
| - | for (int i = 0; i < 8; i++) | + | |
| - | c = (c & 1) ? (c >> 1) ^ 0x8C : c >> 1; | + | |
| - | } | + | |
| - | return c; | + | |
| - | } | + | |
| - | + | ||
| - | static int send_frame(int fd, uint8_t seq, uint8_t type, | + | |
| - | const uint8_t *d, uint16_t n) | + | |
| - | { | + | |
| - | uint8_t b[7 + 64]; | + | |
| - | b[0] = 0xBC; b[1] = seq; b[2] = 0; b[3] = type; | + | |
| - | b[4] = n >> 8; b[5] = n & 0xFF; | + | |
| - | b[6] = crc8(b, 6); | + | |
| - | if (n) | + | |
| - | memcpy(b + 7, d, n); | + | |
| - | return write(fd, b, 7 + n) == 7 + n ? 0 : -1; | + | |
| - | } | + | |
| - | + | ||
| - | int main(void) | + | |
| - | { | + | |
| - | int fd = open("/ | + | |
| - | struct termios t; | + | |
| - | tcgetattr(fd, | + | |
| - | cfmakeraw(& | + | |
| - | cfsetispeed(& | + | |
| - | cfsetospeed(& | + | |
| - | tcsetattr(fd, | + | |
| - | + | ||
| - | uint8_t buf[512], seq = 1, last_uid[8] = {0}; | + | |
| - | size_t used = 0; | + | |
| - | time_t last_ka = 0, last_seen = 0; | + | |
| - | + | ||
| - | for (;;) { | + | |
| - | time_t now = time(NULL); | + | |
| - | if (now != last_ka) { | + | |
| - | send_frame(fd, | + | |
| - | if (++seq == 0) | + | |
| - | seq = 1; | + | |
| - | last_ka = now; | + | |
| - | } | + | |
| - | + | ||
| - | struct pollfd p = { fd, POLLIN, 0 }; | + | |
| - | if (poll(& | + | |
| - | continue; | + | |
| - | + | ||
| - | ssize_t r = read(fd, buf + used, sizeof buf - used); | + | |
| - | if (r <= 0) | + | |
| - | continue; | + | |
| - | used += r; | + | |
| - | + | ||
| - | size_t i = 0; | + | |
| - | while (used - i >= 7) { | + | |
| - | if (buf[i] != 0xBC || crc8(buf + i, 6) != buf[i + 6]) { | + | |
| - | i++; | + | |
| - | continue; | + | |
| - | } | + | |
| - | uint16_t n = (buf[i + 4] << 8) | buf[i + 5]; | + | |
| - | size_t total = 7 + n + (buf[i + 3] >= 0x80 ? 4 : 0); | + | |
| - | if (used - i < total) | + | |
| - | break; | + | |
| - | + | ||
| - | if (buf[i + 3] == 0xBE && n >= 18) { | + | |
| - | uint8_t *uid = buf + i + 7 + 11; /* see payload layout below */ | + | |
| - | int fresh = memcmp(uid, last_uid, 7) != 0 || | + | |
| - | now - last_seen > 3; | + | |
| - | last_seen = now; | + | |
| - | if (fresh) { | + | |
| - | memcpy(last_uid, | + | |
| - | for (int j = 0; j < 7; j++) | + | |
| - | printf(" | + | |
| - | } | + | |
| - | } | + | |
| - | i += total; | + | |
| - | } | + | |
| - | memmove(buf, | + | |
| - | used -= i; | + | |
| - | } | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | The UID sits at payload offset 11 in every '' | + | |
| - | byte, one length byte, nine reserved bytes, then the UID. Check the frame length | + | |
| - | before trusting the offset. The example assumes a 7-byte UID; a 4-byte UID | + | |
| - | carries a different length. | + | |
| - | + | ||
| - | ===== Card presence ===== | + | |
| - | + | ||
| - | The reader re-sends '' | + | |
| - | the field. It arrives unsolicited with '' | + | |
| - | not help match it. It does not send a leave frame on the base path, so presence | + | |
| - | has to be inferred: treat the card as gone when no '' | + | |
| - | arrived for a couple of seconds. Without that timeout a card parked on the reader | + | |
| - | keeps producing events and a queue fills up. | + | |
| - | + | ||
| - | Handled mode does have a leave event. '' | + | |
| - | '' | + | |
| - | '' | + | |
| - | + | ||
| - | < | + | |
| - | 00 00 04 85 92 8a a0 61 81 card entered | + | |
| - | 01 00 04 85 92 8a a0 61 81 card left | + | |
| - | </ | + | |
| - | + | ||
| - | That path only runs with card types enabled and the matching keys present. | + | |
| - | + | ||
| - | ===== What a card frame gives you ===== | + | |
| - | + | ||
| - | '' | + | |
| - | ATQA, the SAK, and the length-prefixed ATS, so cards can be classified without | + | |
| - | selecting them. The full layout is in the card events section below. | + | |
| - | + | ||
| - | SAK '' | + | |
| - | '' | + | |
| - | That is enough to decide whether to look for an EMV application or treat the | + | |
| - | card as a memory tag. | + | |
| - | + | ||
| - | The same reader has the LED and buzzer frames ('' | + | |
| - | host application can chirp and light the reader on a read without any extra | + | |
| - | hardware. | + | |
| - | + | ||
| - | ===== Running a reader next to nx ===== | + | |
| - | + | ||
| - | Only one process can own '' | + | |
| - | '' | + | |
| - | work reliably. | + | |
| - | + | ||
| - | Do not send the '' | + | |
| - | read. That switches the reader into nx's handled-card mode and stops the | + | |
| - | autonomous base scan. It is a different mode, not an initialization step for | + | |
| - | UIDs. Handled reads also need the card keys and, for some schemes, a SAM or | + | |
| - | ISAM. | + | |
| - | + | ||
| - | Do not re-initialize the reader on every tap. That stops the scan you are trying | + | |
| - | to read from. If scanning does stop, '' | + | |
| - | and normally returns scanning in about 6 seconds. If no Startup arrives, | + | |
| - | power-cycle the reader. A bare '' | + | |
| - | + | ||
| - | A loop like the one above has read 74 taps from five different cards over four | + | |
| - | minutes without a gap. | + | |
| - | + | ||
| - | ===== Card events ===== | + | |
| - | + | ||
| - | ^ Type ^ Direction ^ Meaning ^ | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | + | ||
| - | A '' | + | |
| - | + | ||
| - | < | + | |
| - | 00 status (card present) | + | |
| - | 0c length | + | |
| - | 00 x9 | + | |
| - | 04 50 67 0a 81 22 90 | + | |
| - | 44 03 ATQA, little-endian, | + | |
| - | 20 SAK | + | |
| - | 06 75 77 81 02 80 ATS, length-prefixed | + | |
| - | </ | + | |
| - | + | ||
| - | The bytes before the UID are status/ | + | |
| - | card-type field. | + | |
| - | + | ||
| - | ===== The 0xD1 status record ===== | + | |
| - | + | ||
| - | '' | + | |
| - | stream on this firmware, so do not use it as a keepalive indicator. It is | + | |
| - | EMV-style BER-TLV: | + | |
| < | < | ||
| Line 301: | Line 143: | ||
| </ | </ | ||
| - | The '' | + | The '' |
| - | card's token or UID lands once nx has the application keys. Without keys it | + | |
| - | stays zero and the UID arrives through '' | + | |
| - | ===== DESFire commands ===== | + | ==== Sample reader flow ==== |
| - | DESFire cards are read with '' | + | - Host enables desired card type with '' |
| - | DESFireCommandReply. The '' | + | - Reader acknowledges with '' |
| - | {{ 0: | + | - Reader waits for card, seems like it eventually goes to sleep without any stimuli. Might have to keep it awake by sending packets occasionally (e.g. '' |
| + | - When card is scanned, reader sends the corresponding read packet if the card type is enabled (e.g. '' | ||
| + | - Card data can then be queried by sending the equivalent command packets. DESFire commands are documented in {{ 0: | ||
| + | - Host sets DESFire application (e.g. packet type '' | ||
| + | - Reader responds with a status code in accordance with the documentation. This comes in the form of a '' | ||
| + | - Host sends read command. To read the full contents of file 0x00, the body is '' | ||
| + | - Reader responds with the status code and file data. | ||
| - | Enable the handler first with '' | + | ==== Card read flow ==== |
| - | it stops the autonomous base scan; pick one mode or the other. The reader then | + | R: BCB600B9000BBB0C000000048A6EF29B149079CB8CF0 |
| - | sends '' | + | H: BC2200BC000158602A714F60 |
| - | + | | |
| - | The commands nx sends after the card event: | + | |
| - | + | | |
| - | < | + | |
| - | GetVersion | + | |
| - | SelectApplication 0xBC -> 5A <3-byte application id> | + | |
| - | ReadData | + | |
| - | </ | + | |
| - | + | ||
| - | The application ID is issuer-specific. The stock software uses '' | + | |
| - | Portland TriMet cards use '' | + | |
| - | the card first. | + | |
| - | + | ||
| - | A GetVersion exchange captured from nx, split into header, payload, and CRC: | + | |
| - | + | ||
| - | < | + | |
| - | host BC 22 00 BC | 00 01 | 58 | 60 | 2A 71 4F 60 | + | |
| - | reader | + | |
| - | 01 01 03 00 16 05 04 8A 6E F2 | + | |
| - | 9B 14 90 20 48 73 30 30 50 22 | C9 8C 7E 9B | + | |
| - | </ | + | |
| - | + | ||
| - | '' | + | |
| - | and the DESFire data starts at '' | + | |
| - | the same capture was '' | + | |
| - | instead of assuming a fixed offset. | + | |
| - | + | ||
| - | A host DESFire frame starts '' | + | |
| - | message type, not an ack of some kind. | + | |
| - | + | ||
| - | ===== IPP packet structure ===== | + | |
| - | + | ||
| - | ^ offset ^ length ^ name ^ description ^ | + | |
| - | | 0 | 1 | | always '' | + | |
| - | | 1 | 1 | '' | + | |
| - | | 2 | 1 | '' | + | |
| - | | 3 | 1 | '' | + | |
| - | | 4 | 2 | '' | + | |
| - | | 6 | 1 | '' | + | |
| - | | 7 | '' | + | |
| - | | 7+'' | + | |
| - | + | ||
| - | ===== IPP Message types ===== | + | |
| - | + | ||
| - | ^ msgType ^ dir ^ name ^ notes ^ | + | |
| - | | 0x02 | -> | Version | reply 0x03 | | + | |
| - | | 0x03 | <- | VersionReply | device id from the Rockchip OTP, model string, firmware, and cwd as length-prefixed strings | | + | |
| - | | 0x04 | -> | Status | reply 0x05, '' | + | |
| - | | 0x05 | <- | StatusReply | | | + | |
| - | | 0x07 | <- | Heartbeat | about every 3.0 s | | + | |
| - | | 0x0F | <- | Startup | sent about 1 minute after reader power-on | | + | |
| - | | 0x10 | -> | Reset | first byte selects the action: 2 exits the app so it is respawned, 3 calls '' | + | |
| - | | 0x11 | <- | ResetReply | '' | + | |
| - | | 0x20 | -> | LEDs | u32 bitmap, big-endian. All eight LEDs are in the low byte. Upper bytes are inert. | | + | |
| - | | 0x22 | -> | Buzzer | '' | + | |
| - | | 0x32 | -> | CardRelease | | | + | |
| - | | 0x46 | -> | AbortCardHandling | | | + | |
| - | | 0x96 | -> | PutFile | write operation; use with care | | + | |
| - | | 0x97 | <- | PutFileReply | | | + | |
| - | | 0x98 | -> | GetFile | '' | + | |
| - | | 0x99 | <- | GetFileReply | | | + | |
| - | | 0x9A | -> | DeleteFile | left alone | | + | |
| - | | 0x9B | <- | DeleteFileReply | | | + | |
| - | | 0x9C | -> | FileInfo | '' | + | |
| - | | 0x9D | <- | FileInfoReply | | | + | |
| - | | 0xA4 | -> | FileList | '' | + | |
| - | | 0xA5 | <- | FileListReply | | | + | |
| - | | 0xAA | -> | SetTime | payload is a timestamp. Reply '' | + | |
| - | | 0xAB | <- | SetTimeReply | | | + | |
| - | | 0xAC | -> | ITSOData | needs an ISAM | | + | |
| - | | 0xAD | <- | ITSODataReply | | | + | |
| - | | 0xAE | -> | ITSOCtrl | needs an ISAM | | + | |
| - | | 0xAF | <- | ITSOCtrlReply | | | + | |
| - | | 0xB1 | <- | ISORead | UID at offset 2 | | + | |
| - | | 0xB3 | <- | ISOCardReleased | | | + | |
| - | | 0xB4 | -> | APDUProx | '' | + | |
| - | | 0xB5 | <- | APDUProxReply | '' | + | |
| - | | 0xB6 | -> | SAMCtrl | needs a fitted SAM | | + | |
| - | | 0xB7 | <- | SAMCtrlReply | status 0x72 on error | | + | |
| - | | 0xB9 | <- | DESFireRead | | | + | |
| - | | 0xBA | -> | DESFire | + | |
| - | | 0xBB | <- | DESFireCardRemoved | | | + | |
| - | | 0xBC | -> | DESFireCommand | native DESFire command | | + | |
| - | | 0xBD | <- | DESFireCommandReply | two reader bytes, then the card data. GetVersion | + | |
| - | | 0xBE | <- | UnhandledCard | UID carrier for disabled types | | + | |
| - | | 0xCE | -> | control | IppHandling | | + | |
| - | | 0xD0 | -> | EMV | 0 load config, followed by a null-terminated filename that is read on the reader and passed to '' | + | |
| - | | 0xD1 | <- | EMVStatus | BER-TLV status record | | + | |
| - | | 0xD4 | -> | UltralightCommand | subcommands below. Host path is limited; see the warning. | | + | |
| - | | 0xD5 | <- | UltralightReply / card event | | | + | |
| - | | 0xE4 | -> | ProxCardFunction | '' | + | |
| - | | 0xE5 | <- | ProxCardFunctionReply | '' | + | |
| - | | 0xE6 | -> | Girogo | not exercised; needs girogo keys and hardware | | + | |
| - | | 0xE8 | -> | SecurityServices | sub 0 GetVersionOfKey, | + | |
| - | | 0xE9 | <- | SecurityServicesReply | | | + | |
| - | | 0xEA | -> | Mifare Classic / wake | handler exists but often errors | | + | |
| - | | 0xED | <- | Log | level byte plus null-terminated text | | + | |
| - | + | ||
| - | Directions are host to reader ('' | + | |
| - | + | ||
| - | ===== LEDs ===== | + | |
| - | + | ||
| - | The '' | + | |
| - | + | ||
| - | ^ bit ^ LED ^ | + | |
| - | | 0x01 | status row 1, green | | + | |
| - | | 0x02 | status row 2, green | | + | |
| - | | 0x04 | status row 3, green | | + | |
| - | | 0x08 | status row 4, green | | + | |
| - | | 0x10 | status row 3, amber (same LED as 0x04) | | + | |
| - | | 0x20 | status row 4, red (same LED as 0x08) | | + | |
| - | | 0x40 | NFC logo, right | | + | |
| - | | 0x80 | NFC logo, left | | + | |
| - | + | ||
| - | '' | + | |
| - | The firmware also drives the LEDs during RF activity, so a host write holds only | + | |
| - | until the next firmware update. Drive them from a loop if you need them steady. | + | |
| - | + | ||
| - | ===== Reader filesystem ===== | + | |
| - | + | ||
| - | The reader exposes file operations over IPP. The two read operations are useful: | + | |
| - | + | ||
| - | < | + | |
| - | 0xA4 FileList | + | |
| - | -> 0xA5 [u32 len][name\0mtime\0...] | + | |
| - | + | ||
| - | 0x98 GetFile | + | |
| - | -> 0x99 [u32 len][data] | + | |
| - | </ | + | |
| - | + | ||
| - | '' | + | |
| - | about 60 KB. '' | + | |
| - | described below. | + | |
| - | + | ||
| - | Worth reading: | + | |
| - | + | ||
| - | * '' | + | |
| - | * '' | + | |
| - | * '' | + | |
| - | * '' | + | |
| - | * '' | + | |
| - | + | ||
| - | Direct example for a directory listing: | + | |
| - | + | ||
| - | < | + | |
| - | stty -F / | + | |
| - | printf ' | + | |
| - | timeout -t 2 dd if=/ | + | |
| - | </ | + | |
| - | + | ||
| - | Direct example for reading '' | + | |
| - | + | ||
| - | < | + | |
| - | printf ' | + | |
| - | timeout -t 2 dd if=/ | + | |
| - | </ | + | |
| - | + | ||
| - | The reply length depends on the file. Increase '' | + | |
| - | These examples also use sequence 1. Increment the sequence byte for each request. | + | |
| - | + | ||
| - | ===== The 0x9C CRC ===== | + | |
| - | + | ||
| - | '' | + | |
| - | + | ||
| - | < | + | |
| - | crc = 0x00000000 | + | |
| - | for each byte b: | + | |
| - | crc ^= b | + | |
| - | 8 times: crc = (crc >> 1) ^ 0xEDB88320 if crc & 1 else crc >> 1 | + | |
| - | return crc ^ 0xFFFFFFFF | + | |
| - | </ | + | |
| - | + | ||
| - | That is polynomial '' | + | |
| - | '' | + | |
| - | JAMCRC (which skips the final XOR). | + | |
| - | + | ||
| - | In C, one loop over the file: | + | |
| - | + | ||
| - | < | + | |
| - | static uint32_t file_crc(const uint8_t *p, size_t n) | + | |
| - | { | + | |
| - | uint32_t crc = 0; | + | |
| - | while (n--) { | + | |
| - | crc ^= *p++; | + | |
| - | for (int i = 0; i < 8; i++) | + | |
| - | crc = (crc & 1) ? (crc >> 1) ^ 0xEDB88320 : crc >> 1; | + | |
| - | } | + | |
| - | return crc ^ 0xFFFFFFFF; | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | The firmware' | + | |
| - | so a 4 KB chunk loop composes correctly. The reply is big-endian: | + | |
| - | + | ||
| - | < | + | |
| - | 00 00 status | + | |
| - | 00 00 00 06 size, 6 | + | |
| - | 04 40 bb d8 crc32 of " | + | |
| - | </ | + | |
| - | + | ||
| - | Verified against seven files and three ranged reads. | + | |
| - | + | ||
| - | '' | + | |
| - | with size 160 and CRC '' | + | |
| - | so '' | + | |
| - | + | ||
| - | ===== Sleep and recovery ===== | + | |
| - | + | ||
| - | The reader powers its RF field down after an idle timeout and can drop into a | + | |
| - | sub-1 mA hardware standby. There is no host wake opcode in the documented FEIG | + | |
| - | command set. A '' | + | |
| - | + | ||
| - | Leaving the tty open without a keepalive still scanned after 90 seconds. Either | + | |
| - | the idle timeout is longer than that or an open host tty counts as stimulus. The | + | |
| - | idle timeout is not established; | + | |
| - | + | ||
| - | Symptoms: scanning stops, only the '' | + | |
| - | stop. | + | |
| - | + | ||
| - | Recovery: | + | |
| - | + | ||
| - | < | + | |
| - | 0x10 02 | + | |
| - | </ | + | |
| - | + | ||
| - | That restarts the application. On a healthy reader it emits '' | + | |
| - | aborts, re-initializes, | + | |
| - | The serial link is preserved. If no Startup arrives, power-cycle the reader. | + | |
| - | + | ||
| - | The first payload byte selects what Reset does: | + | |
| - | + | ||
| - | | + | |
| - | | + | |
| - | | + | |
| - | * '' | + | |
| - | * anything else: no action, and the error above is logged. | + | |
| - | + | ||
| - | The handler reads the first payload byte, so do not send '' | + | |
| - | payload. That has left the reader unresponsive in testing. | + | |
| - | + | ||
| - | Subcode 3 replies '' | + | |
| - | '' | + | |
| - | that test ended with a physical power cycle. Treat 3 as " | + | |
| - | as a faster restart. | + | |
| - | + | ||
| - | ===== nx handshake reference ===== | + | |
| - | + | ||
| - | Captured by an LD_PRELOAD shim on nx's serial traffic: | + | |
| - | + | ||
| - | < | + | |
| - | 0xEA 0100 wake/ | + | |
| - | 0x02 | + | |
| - | 0xE4 00 05 01 01 | + | |
| - | 0xE4 00 07 01 01 | + | |
| - | 0xE4 00 0a 01 01 | + | |
| - | 0xAA < | + | |
| - | 0xE8 04fe0a0000 | + | |
| - | </ | + | |
| - | + | ||
| - | The '' | + | |
| - | nx's handled-card mode. The certificate read is informational. nx does not send a | + | |
| - | periodic poll after this. Continuous scanning is the reader' | + | |
| - | + | ||
| - | The '' | + | |
| - | It does not gate raw UID reading. | + | |
| - | + | ||
| - | ===== Reader internals ===== | + | |
| - | + | ||
| - | The '' | + | |
| - | to a named handler, and the binary carries INIT's source paths under | + | |
| - | '' | + | |
| - | + | ||
| - | The reader has: | + | |
| - | + | ||
| - | * a multi-application card controller ('' | + | |
| - | * DESFire, Mifare Classic, Ultralight-C, | + | |
| - | * a MIFARE SAM AV1/AV2 interface on '' | + | |
| - | * a PKCS#11 HSM on '' | + | |
| - | * an ITSO ISAM path on '' | + | |
| - | * EMVCo Entry Point and L2 kernels on '' | + | |
| - | + | ||
| - | Handlers register in their constructors: | + | |
| - | '' | + | |
| - | '' | + | |
| - | modules own their own opcodes ('' | + | |
| - | '' | + | |
| - | '' | + | |
| - | '' | + | |
| - | '' | + | |
| - | + | ||
| - | The card handlers and crypto are present, but the SAM, ISAM, HSM keys, and EMV | + | |
| - | configuration are not on a surplus unit. That is a key and provisioning | + | |
| - | limit, not missing firmware. | + | |
| - | + | ||
| - | ===== Telling transit cards apart ===== | + | |
| - | + | ||
| - | At the RF type layer the big agencies look the same. ORCA (Seattle), Compass | + | |
| - | (Vancouver), | + | |
| - | are NXP DESFire, so a base-scan frame gives you: | + | |
| - | + | ||
| - | * '' | + | |
| - | * '' | + | |
| - | * an ATS such as '' | + | |
| - | + | ||
| - | Nothing in that frame names the agency, the fare product, or the card | + | |
| - | generation. The UID is the only per-card value, and it is NXP stock, not an | + | |
| - | agency range. An app that wants to behave differently per agency either keeps a | + | |
| - | UID list or gets past the type layer. | + | |
| - | + | ||
| - | Getting past it does not need the keys. Selecting a DESFire application, | + | |
| - | ISO AID, answers success or "not found" without authentication. A probe for a | + | |
| - | known transit application therefore tells agencies apart. That needs APDU | + | |
| - | access, which the base scan does not give you. See '' | + | |
| - | + | ||
| - | Some cards are easier. A MIFARE Ultralight answers '' | + | |
| - | '' | + | |
| - | there and is distinguishable without a list. MIFARE Classic is '' | + | |
| - | for 1K and '' | + | |
| - | transit cards are the ones that look identical. | + | |
| - | + | ||
| - | ===== 0xD4 UltralightCommand ===== | + | |
| - | + | ||
| - | The command is documented, but the host-driven read path does not work well. | + | |
| - | + | ||
| - | < | + | |
| - | 0x02 Read [start_page u8][num_pages u8] | + | |
| - | 0x03 Write [page u8][4 bytes] | + | |
| - | 0x04 Auth raw key [16-byte key] | + | |
| - | 0x05 Auth key index [key index, big-endian u16] | + | |
| - | 0x06 Auth index+key | + | |
| - | 0x07 Abort no payload | + | |
| - | </ | + | |
| - | Read returns four bytes per page. An NTAG215 is 135 pages, so a full dump is | ||
| - | '' | ||
| - | The reply is '' | + | Another one (same payloads as previous but with different |
| - | 0x02 bad parameters. With no card in the field the reader answers | + | R: BCBF00B9000B480C000000048A6EF29B149079CB8CF0 |
| - | '' | + | H: BC2400BC0001C4602A714F60 |
| + | R: BCC024BD001E0800000401013300160504010103001605048A6EF29B149020487330305022C98C7E9B | ||
| + | H: BC2500BC0004365A2BC3F911A8A56A | ||
| + | R: BCC125BD00027401FDE0523164 | ||
| + | |||
| + | |||
| + | Sample log message: | ||
| + | BCB000ED0068450330363A34383A3038204572726F723A206665636C725F7472616E7363656976652829206661696C65643A206572726F723A20302C207374617475733A2030783030303030303038200A205B524649445265616465724D756C74694170702E6370703A3135395D0002CD1533BCB100ED0046B40130363A34383A3038207472616E7363656976652065 | ||
| - | In practice, '' | ||
| - | handler selects the card, runs its own transceive, and releases it in | ||
| - | milliseconds. Polling '' | ||
| - | services host commands or scans autonomously, | ||
| - | instead: enable the type, let the reader transceive, and read '' | ||
| - | ===== Open questions ===== | + | 00000000 |
| + | 00000010 | ||
| + | 00000020 | ||
| + | 00000030 | ||
| + | 00000040 | ||
| + | 00000050 | ||
| + | 00000060 | ||
| + | 00000070 | ||
| + | 00000080 | ||
| - | * What writes '' | ||
| - | * What '' | ||
| - | * The three-byte '' | ||
| - | * How long the idle timeout actually is, since 90 seconds with an open tty was not enough. | ||
| - | * The SAM, ISAM, HSM key provisioning, | ||
cvend.1795390955.txt.gz · Last modified: by qkb
