Skip to content

Instantly share code, notes, and snippets.

@auscompgeek
Last active February 21, 2024 11:46
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save auscompgeek/65b1c8fafaba19262420 to your computer and use it in GitHub Desktop.
Save auscompgeek/65b1c8fafaba19262420 to your computer and use it in GitHub Desktop.
Opal free read data format

Opal

Opal is the public transport smartcard ticketing system in Sydney, Australia.

Opal cards are MIFARE DESFire EV1 cards, with the application ID 0x314553. All files are restricted except for file 7, which is freely readable.

The official Android app can interpret this free read data. Much of the information here was derived by reverse engineering this app.

Format

The free read file is 16 octets long.

The data is essentially a 128-bit integer, stored in little-endian. As the fields are not byte-aligned, reading the data as a bitstream is difficult (read: impossible) without reversing the order of the octets.

Offsets and lengths listed are measured in bits, and assume you have reversed the octets. Ranges listed do not include the end bit.

Start End Length Field description
0 16 16 Checksum
16 20 4 Weekly paid journey count
20 21 1 Auto top-up enabled
21 25 4 Last tap usage type
25 28 3 Mode of transport
28 39 11 Last tap time: minutes since 00:00
39 54 15 Last tap date: days since epoch
54 75 21 Balance in cents (two's complement)
75 91 16 Transaction sequence number
91 92 1 Card status, 1 if blocked
92 96 4 Serial number check digit
96 128 32 Serial number

Card number

All card numbers start with the Opal issuer number "308522". This is then concatenated with the serial number zero-padded to 9 digits, followed by the check digit.

Tap date/time

The epoch is 1 January 1980 (1980-01-01).

It is believed that tap dates and times are stored in local time (Australia/NSW).

Modes of transport

ID Description
0 Rail
1 Ferry or Light Rail
2 Bus
3-7 (reserved)

Usage types

ID Description
0 Card has not been used
1 Tap on: new journey
2 Tap on: transfer from same mode
3 Tap on: transfer from different mode
4 Tap on: Manly-CQ ferry: new journey
5 Tap on: Manly-CQ ferry: transfer from another ferry 1
6 Tap on: Manly-CQ ferry: transfer from different mode
7 Tap off: distance based fare
8 Tap off: flat-rate fare
9 Tap off: automatically completed journey (failure to tap off)
10 Tap off: end of trip without start (failure to tap on)
11 Tap off: tap on reversal
12 Unsuccessful tap (low balance?)
13 (reserved)
14 (reserved)

1 Transfers between ferries can only occur at Circular Quay.

Checksum

The checksum is a CRC-16-CCITT checksum of the original data (without the checksum). It is stored in big-endian on the card, and is hence little-endian once read in reversed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment