mfrc522

package
v3.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mfrc522 controls a Mifare RFID card reader.

Datasheet

https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf

Index

Constants

View Source
const (
	AnyKeyRWID    BlockAccess = iota
	RAB_WN_IN_DN              = 0x02 // Read (A|B), Write (None), Increment (None), Decrement(None)
	RAB_WB_IN_DN              = 0x04
	RAB_WB_IB_DAB             = 0x06
	RAB_WN_IN_DAB             = 0x01
	RB_WB_IN_DN               = 0x03
	RB_WN_IN_DN               = 0x05
	RN_WN_IN_DN               = 0x07

	KeyA_RN_WA_BITS_RA_WN_KeyB_RA_WA        SectorTrailerAccess = iota
	KeyA_RN_WN_BITS_RA_WN_KeyB_RA_WN                            = 0x02
	KeyA_RN_WB_BITS_RAB_WN_KeyB_RN_WB                           = 0x04
	KeyA_RN_WN_BITS_RAB_WN_KeyB_RN_WN                           = 0x06
	KeyA_RN_WA_BITS_RA_WA_KeyB_RA_WA                            = 0x01
	KeyA_RN_WB_BITS_RAB_WB_KeyB_RN_WB                           = 0x03
	KeyA_RN_WN_BITS_RAB_WB_KeyB_RN_WN                           = 0x05
	KeyA_RN_WN_BITS_RAB_WN_KeyB_RN_WN_EXTRA                     = 0x07
)

Access bits.

Variables

View Source
var DefaultKey = [...]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}

DefaultKey provides the default bytes for card authentication for method B.

Functions

func CalculateBlockAccess

func CalculateBlockAccess(ba *BlocksAccess) []byte

CalculateBlockAccess calculates the block access.

Types

type AuthStatus

type AuthStatus byte

AuthStatus indicates the authentication response, could be one of AuthOk, AuthReadFailure or AuthFailure

const (
	AuthOk AuthStatus = iota
	AuthReadFailure
	AuthFailure
)

Card authentication status enum.

type BlockAccess

type BlockAccess byte

BlockAccess defines the block access bits.

type BlocksAccess

type BlocksAccess struct {
	B0, B1, B2 BlockAccess
	B3         SectorTrailerAccess
}

BlocksAccess defines the access structure for first 3 blocks of the sector and the access bits for the sector trail.

func ParseBlockAccess

func ParseBlockAccess(ad []byte) *BlocksAccess

ParseBlockAccess parses the given byte array into the block access structure.

func (*BlocksAccess) String

func (ba *BlocksAccess) String() string

type Dev

type Dev struct {
	// contains filtered or unexported fields
}

Dev is an handle to an MFRC522 RFID reader.

func NewSPI

func NewSPI(spiPort spi.Port, resetPin gpio.PinOut, irqPin gpio.PinIn) (*Dev, error)

NewSPI creates and initializes the RFID card reader attached to SPI.

spiPort - the SPI device to use.
resetPin - reset GPIO pin.
irqPin - irq GPIO pin.

func (*Dev) AntiColl

func (r *Dev) AntiColl() ([]byte, error)

AntiColl performs the collision check for different cards.

func (*Dev) Auth

func (r *Dev) Auth(mode byte, sector, block int, sectorKey [6]byte, serial []byte) (AuthStatus, error)

Auth authenticate the card fof the sector/block using the provided data.

mode - the authentication mode.
sector - the sector to authenticate on.
block - the block within sector to authenticate.
sectorKey - the key to be used for accessing the sector data.
serial - the serial of the card.

func (*Dev) CRC

func (r *Dev) CRC(inData []byte) ([]byte, error)

CRC calculates the CRC of the data using the card chip.

func (*Dev) CardWrite

func (r *Dev) CardWrite(command byte, data []byte) ([]byte, int, error)

CardWrite the low-level interface to write some raw commands to the card.

command - the command register
data - the data to write out to the card using the authenticated sector.

func (*Dev) Halt

func (r *Dev) Halt() error

Halt soft-stops the chip - PowerDown bit set, command IDLE

func (*Dev) Init

func (r *Dev) Init() error

Init initializes the RFID chip.

func (*Dev) ReadAuth

func (r *Dev) ReadAuth(auth byte, sector int, key [6]byte) (data []byte, err error)

ReadAuth - read the card authentication data.

sector - the sector to authenticate on.
key - the key to be used for accessing the sector data.

func (*Dev) ReadBlock

func (r *Dev) ReadBlock(sector int, block int) ([]byte, error)

ReadBlock reads the block from the card.

sector - card sector to read from
block - the block within the sector (0-3 tor Mifare 4K)

func (*Dev) ReadCard

func (r *Dev) ReadCard(auth byte, sector int, block int, key [6]byte) (data []byte, err error)

ReadCard reads the card sector/block.

auth - the authentication mode.
sector - the sector to authenticate on.
block - the block within sector to authenticate.
key - the key to be used for accessing the sector data.

func (*Dev) ReadSectorTrail

func (r *Dev) ReadSectorTrail(sector int) ([]byte, error)

ReadSectorTrail reads the sector trail (the last sector that contains the sector access bits)

sector - the sector number to read the data from.

func (*Dev) Request

func (r *Dev) Request() (int, error)

Request the card information. Returns number of blocks available on the card.

func (*Dev) Reset

func (r *Dev) Reset() error

Reset resets the RFID chip to initial state.

func (*Dev) SelectTag

func (r *Dev) SelectTag(serial []byte) (byte, error)

SelectTag selects the FOB device by device UUID.

func (*Dev) SetAntenna

func (r *Dev) SetAntenna(state bool) error

SetAntenna configures the antenna state, on/off.

func (*Dev) SetOperationtimeout

func (r *Dev) SetOperationtimeout(timeout time.Duration)

SetOperationtimeout updates the device timeout for card operations.

Effectively that sets the maximum time the RFID device will wait for IRQ from the proximity card detection.

timeout the duration to wait for IRQ strobe.

func (*Dev) StopCrypto

func (r *Dev) StopCrypto() error

StopCrypto stops the crypto chip.

func (*Dev) String

func (r *Dev) String() string

func (*Dev) Wait

func (r *Dev) Wait() error

Wait wait for IRQ to strobe on the IRQ pin when the card is detected.

func (*Dev) WriteBlock

func (r *Dev) WriteBlock(auth byte, sector int, block int, data [16]byte, key [6]byte) (err error)

WriteBlock writes the data into the card block.

auth - the authentiction mode.
sector - the sector on the card to write to.
block - the block within the sector to write into.
data - 16 bytes if data to write
key - the key used to authenticate the card - depends on the used auth method.

func (*Dev) WriteSectorTrail

func (r *Dev) WriteSectorTrail(auth byte, sector int, keyA [6]byte, keyB [6]byte, access *BlocksAccess, key [6]byte) (err error)

WriteSectorTrail writes the sector trait with sector access bits.

auth - authentication mode.
sector - sector to set authentication.
keyA - the key used for AuthA authentication scheme.
keyB - the key used for AuthB authentication schemd.
access - the block access structure.
key - the current key used to authenticate the provided sector.

type SectorTrailerAccess

type SectorTrailerAccess byte

SectorTrailerAccess defines the sector trailing block access bits.

Directories

Path Synopsis
Package commands contains the command that a MFRC522 supports.
Package commands contains the command that a MFRC522 supports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL