Skip to main content

2-Wire Protocol Commands

Overview

  • Bus: 2 wire bus with bidirectional data (SDA) line and a clock (SCL) line
  • Connections: two pins (SDA/SCL) and ground. An additional pin is reserved for RESET, and is controlled by the {/} commands.
  • Output type: open drain/open collector
  • Pull-up resistors: always required (2K - 10K ohms)
  • Maximum voltage: 5volts

2-wire is a generic 8bit protocol mode with a bidirectional data line (SDA) and a clock line (SCL). 2-wire can be used to interface with SLE4442 smart cards, half-duple SPI devices and other 2 wire busses that don't use a full I2C implementation.

Connections

Bus PirateDirectionCircuitDescription
SDASDASerial Data
SCLSCLSerial Clock
RSTRSTReset signal for some devices
GNDGNDSignal Ground

Configuration options

Bus Pirate [/dev/ttyS0]
2WIRE speed
1kHz to 1000kHz
x. Exit
kHz (400kHz*) > 20
Mode: 2WIRE
2WIRE>

Pull-up resistors

2-Wire is an open-collector bus, it requires pull-up resistors to hold the clock and data lines high and create the data '1'. In 2-Wire mode, the Bus Pirate doesn't output high, it only pulls low. Without pull-up resistors there can never be a '1'.

Enable the Bus Pirate onboard pull-up resistors with the P command.

tip
  • 2-Wire requires pull-up resistors to hold the clock and data lines high.
  • Without pull-up resistors there can never be a '1'.
  • Enable the Bus Pirate onboard pull-up resistors with the P command.

Syntax

CommandDescription
[Issue I2C-style start condition. Some devices don't follow the I2C standard, but still use a similar START condition.
]Issue I2C-style stop condition. Some devices don't follow the I2C standard, but still use a similar STOP condition.
{RST/reset pin high
}RST/reset pin low
rRead one byte, send ACK. (r:1…255 for bulk reads)
0bWrite this binary value, check ACK. Format is 0b00000000 for a byte, but partial bytes are also fine: 0b1001.
0xWrite this HEX value, check ACK. Format is 0x01. Partial bytes are fine: 0xA. A-F can be lower-case or capital letters.
0-255Write this decimal value, check ACK. Any number not preceded by 0x or 0b is interpreted as a decimal value.
spaceValue delimiter. Use a space to separate numbers. No delimiter is required between non-number values: {0xa6 0 0 16 5 0b111 0xaF rrrr}.

Commands

Bus Pirate 5 has global commands available everywhere, and mode commands specific to the currently selected mode. Type help to see all commands in every mode, or help mode for the currently available mode commands.

sle4442

The sle4442 command in the Bus Pirate's 2-WIRE mode automates the process of reading, writing and unlocking a SLE4442 smart card.

Help

Bus Pirate [/dev/ttyS0]
2WIRE> sle4442 -h
usage:
sle4442 [init|dump|unlock|write|erase|psc]
[-a <address>] [-v <value>] [-p <current psc>] [-n <new psc>] [-h(elp)]

Initialize and probe: sle4442 init
Dump contents: sle4442 dump
Unlock card: sle4442 unlock -p 0xffffff
Write a value: sle4442 write -a 0xff -v 0x55
Erase memory: sle4442 erase
Update PSC: sle4442 psc -p 0xffffff -n 0x000000

SLE4442 smart card interface
init Initialize card with ISO7816-3 ATR. Default action
dump Display main, security and protect memory
unlock Unlock card with Programmable Security Code (PSC)
write Write data to card (requires unlock)
erase Erase data from range 0x32-0x255 (requires unlock)
psc Change Programmable Security Code (PSC)
-a Write address flag
-v Write value flag
-p Current Programmable Security Code (PSC) flag
-n New Programmable Security Code (PSC) flag

2WIRE>
tip

Use sle4442 -h to see the latest options and features.

Most Bus Pirate commands have help and usage examples. Add the -h flag to any command to see the available options and examples.

Options and flags

OptionDescription
sle4442 initInitialize and probe the card Answer To Reset
sle4442 dumpDisplay main, security and protect memory
sle4442 unlockUnlock card with Programmable Security Code (PSC)
sle4442 writeWrite data to card (requires unlock)
sle4442 eraseErase data from range 0x32-0x255 (requires unlock)
sle4442 pscChange Programmable Security Code (PSC)
FlagDescription
-aWrite address flag
-vWrite value flag
-pCurrent Programmable Security Code (PSC) flag
-nNew Programmable Security Code (PSC) flag

Reset SLE4442 card, decode ATR response

Bus Pirate [/dev/ttyS0]
2WIRE> sle4442 init
--SLE44xx decoder--
ATR: 0xa2 0x13 0x10 0x91
Protocol Type: S 10
Structure Identifier: General Purpose (Structure 1)
Read: Read to end
Data Units: 256
Data Units Bits: 8
Security memory: 0x07 0x00 0x00 0x00
Remaining attempts: 3 (0x7)

sle4442 and sle4442 init reset the card and decodes the Answer To Reset (ATR) response.

Dump SLE4442 card memory

Bus Pirate [/dev/ttyS0]
2WIRE> sle4442 dump
--SLE44xx decoder--
ATR: 0xa2 0x13 0x10 0x91
Protocol Type: S 10
Structure Identifier: General Purpose (Structure 1)
Read: Read to end
Data Units: 256
Data Units Bits: 8
Security memory: 0x07 0x00 0x00 0x00
Remaining attempts: 3 (0x7)
Protection memory: 0xff 0xff 0xff 0xff
Memory:
0xa2 0x13 0x10 0x91 0xff 0xff 0x81 0x15 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xd2 0x76 0x00 0x00 0x04 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff

sle4442 dump reads and displays the main, security and protection memory areas.

Unlock SLE4442 card with passcode

Bus Pirate [/dev/ttyS0]
2WIRE> sle4442 unlock -p 0x123456
--SLE44xx decoder--
ATR: 0xa2 0x13 0x10 0x91
Protocol Type: S 10
Structure Identifier: General Purpose (Structure 1)
Read: Read to end
Data Units: 256
Data Units Bits: 8
Security memory: 0x07 0x12 0x34 0x56
Remaining attempts: 3 (0x7)
Unlocking with PSC: 0x123456
Using free security bit: 0x03
Card unlocked, security bits reset
Security memory: 0x07 0x12 0x34 0x56
Remaining attempts: 3 (0x7)

sle4442 unlock unlocks the card using the Programmable Security Code (PSC). Use the -p flag to specify the PSC.

tip

New cards usually have a default PSC of 0xffffff.

Write data to SLE4442 card

Bus Pirate [/dev/ttyS0]
2WIRE> sle4442 write -a 0xff -v 0x88
--SLE44xx decoder--
ATR: 0xa2 0x13 0x10 0x91
Protocol Type: S 10
Structure Identifier: General Purpose (Structure 1)
Read: Read to end
Data Units: 256
Data Units Bits: 8
Security memory: 0x07 0x12 0x34 0x56
Remaining attempts: 3 (0x7)
Writing 0x88 to 0xff

sle4442 write writes a single byte of data to the card. Specify the address with the -a flag and the data value with the -v flag.

caution

The card must be unlocked before writing data.

Change SLE4442 passcode/PSC

Bus Pirate [/dev/ttyS0]
2WIRE> sle4442 psc -p 0x123456 -n 0xffffff
--SLE44xx decoder--
ATR: 0xa2 0x13 0x10 0x91
Protocol Type: S 10
Structure Identifier: General Purpose (Structure 1)
Read: Read to end
Data Units: 256
Data Units Bits: 8
Security memory: 0x07 0x12 0x34 0x56
Remaining attempts: 3 (0x7)
Unlocking with PSC: 0x123456
Using free security bit: 0x03
Card unlocked, security bits reset
Security memory: 0x07 0x12 0x34 0x56
Remaining attempts: 3 (0x7)
Updating with PSC: 0xFFFFFF
PSC updated to: 0xFFFFFF
Security memory: 0x07 0xff 0xff 0xff
Remaining attempts: 3 (0x7)

sle4442 psc changes the Programmable Security Code (PSC). Use the -p flag to specify the current PSC and the -n flag to specify the new PSC.