ondryaso / pi-rc522

Raspberry Pi Python library for SPI RFID RC522 module
MIT License
411 stars 150 forks source link

Added get_access_bits function #33

Closed Galarzaa90 closed 7 years ago

Galarzaa90 commented 7 years ago

Added a function to calculate the access bits that go in bytes 6 to 8 on the sector trailer, the result can be used for write_trailer function.

Example: A card's default access conditions are:

Block 0 Block 1 Block 2 Block 3
C1 0 0 0 0
C2 0 0 0 0
C3 0 0 0 1
access_bits = get_access_bits(c1=(0,0,0,0), c2=(0,0,0,0), c3=(0,0,0,1)) # Named parameters not necessary, just used for demonstration
> (255, 7, 128) #0xFF, 0x07, 0x80

The formula used can be seen on page 12 on MIFARE card's reference sheet