Documentation ¶
Overview ¶
Package mfrc522 controls a Mifare RFID card reader.
Datasheet ¶
Index ¶
- Constants
- Variables
- func CalculateBlockAccess(ba *BlocksAccess) []byte
- type AuthStatus
- type BlockAccess
- type BlocksAccess
- type Dev
- func (r *Dev) AntiColl() ([]byte, error)
- func (r *Dev) Auth(mode byte, sector, block int, sectorKey [6]byte, serial []byte) (AuthStatus, error)
- func (r *Dev) CRC(inData []byte) ([]byte, error)
- func (r *Dev) CardWrite(command byte, data []byte) ([]byte, int, error)
- func (r *Dev) Halt() error
- func (r *Dev) Init() error
- func (r *Dev) ReadAuth(auth byte, sector int, key [6]byte) (data []byte, err error)
- func (r *Dev) ReadBlock(sector int, block int) ([]byte, error)
- func (r *Dev) ReadCard(auth byte, sector int, block int, key [6]byte) (data []byte, err error)
- func (r *Dev) ReadSectorTrail(sector int) ([]byte, error)
- func (r *Dev) Request() (int, error)
- func (r *Dev) Reset() error
- func (r *Dev) SelectTag(serial []byte) (byte, error)
- func (r *Dev) SetAntenna(state bool) error
- func (r *Dev) SetOperationtimeout(timeout time.Duration)
- func (r *Dev) StopCrypto() error
- func (r *Dev) String() string
- func (r *Dev) Wait() error
- func (r *Dev) WriteBlock(auth byte, sector int, block int, data [16]byte, key [6]byte) (err error)
- func (r *Dev) WriteSectorTrail(auth byte, sector int, keyA [6]byte, keyB [6]byte, access *BlocksAccess, ...) (err error)
- type SectorTrailerAccess
Constants ¶
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 ¶
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 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 ¶
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) 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) CardWrite ¶
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) ReadAuth ¶
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 ¶
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 ¶
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 ¶
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) SetAntenna ¶
SetAntenna configures the antenna state, on/off.
func (*Dev) SetOperationtimeout ¶
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) WriteBlock ¶
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.