|
| 1 | +--- |
| 2 | +Title: "NFC and RFID reader" |
| 3 | +--- |
| 4 | + |
| 5 | +The MFRC630 is a NFC and RFID card reader. |
| 6 | + |
| 7 | +## Constructors |
| 8 | + |
| 9 | +### class MFRC630(pycoproc=None, sda='P22', scl='P21', timeout=None, debug=False) |
| 10 | + |
| 11 | +Creates a `MFRC630` object. Constructor must be passed a Pycoproc or I2C object to successfully construct. |
| 12 | + |
| 13 | +## Methods |
| 14 | + |
| 15 | +### MFRC630.mfrc630_cmd_init() |
| 16 | + |
| 17 | +Initialises the MFRC630. |
| 18 | + |
| 19 | +### MFRC630.mfrc630_cmd_reset() |
| 20 | + |
| 21 | +Reset the device. Stops the currently active command and resets device. |
| 22 | + |
| 23 | +### MFRC630.mfrc630_cmd_idle() |
| 24 | + |
| 25 | +Set the device into idle mode. Stops the currently active command and return to idle mode. |
| 26 | + |
| 27 | +### MFRC630.mfrc630_cmd_load_key(key) |
| 28 | + |
| 29 | +Loads the provided key into the key buffer. |
| 30 | + |
| 31 | +* `key` Array which holds the MIFARE key, **it is always 6 bytes long** |
| 32 | + |
| 33 | +#### MFRC630.mfrc630_MF_read_block(block_address, dest) |
| 34 | + |
| 35 | +Reads a block of memory from an authenticated card. Try to read a block of memory from the card with the appropriate timeouts and error checking. |
| 36 | + |
| 37 | +* `block_address` The block to read |
| 38 | +* `dest` The array in which to write the 16 bytes read from the card |
| 39 | + |
| 40 | +Returns `0` for failure, otherwise the number of bytes received. |
| 41 | + |
| 42 | +#### MFRC630.mfrc630_MF_auth(uid, key_type, block) |
| 43 | + |
| 44 | +Perform a MIFARE authentication procedure. This function is a higher-level wrapper around the MF authenticate command. The result of the authentication is checked to identify whether it appears to have succeeded. The key must be loaded into the key buffer with `MFRC630.mfrc630_cmd_load_key(key)`. |
| 45 | + |
| 46 | +Once authenticated, the authentication MUST be stopped manually by calling the `mfrc630_MF_deauth()` function or otherwise disabling the `Crypto1 ON` bit in the status register. |
| 47 | + |
| 48 | +* `key_type`: The MIFARE key A or B (`MFRC630_MF_AUTH_KEY_A` or `MFRC630_MF_AUTH_KEY_B`) to use |
| 49 | +* `block`: The block to authenticate |
| 50 | +* `uid`: The authentication procedure required the first four bytes of the card's UID to authenticate |
| 51 | + |
| 52 | +Returns `0` in case of failure, nonzero in case of success. |
| 53 | + |
| 54 | +#### MFRC630.mfrc630_MF_deauth() |
| 55 | + |
| 56 | +Disables MIFARE authentication. Disable the `Crypto1` bit from the status register to disable encryption. |
| 57 | + |
| 58 | +#### MFRC630.mfrc630_iso14443a_WUPA_REQA(instruction) |
| 59 | + |
| 60 | +Send `WUPA` and `REQA`. Returns the response byte, the answer to request `A` byte (`ATQA`), or `0` in case of no answer. |
| 61 | + |
| 62 | +* instruction: `MFRC630_ISO14443_CMD_WUPA`, `MFRC630_ISO14443_CMD_REQA` |
| 63 | + |
| 64 | +#### MFRC630.mfrc630_iso14443a_select(uid) |
| 65 | + |
| 66 | +Performs the `SELECT` procedure to discover a card's UID. This performs the `SELECT` procedure as explained in _ISO14443A_, this determines the UID of the card, if multiple cards are present, a collision will occur, which is handled according to the norm. |
| 67 | + |
| 68 | +* `uid`: The UID of the card will be stored into this array. |
| 69 | + |
| 70 | +Returns the length of the UID in bytes (`4, 7, 10`), or `0` in case of failure. |
| 71 | + |
| 72 | +#### MFRC630.print_debug(msg) |
| 73 | + |
| 74 | +Prints debug statements if `DEBUG` is enabled. |
| 75 | + |
| 76 | +#### MFRC630.format_block(block, length) |
| 77 | + |
| 78 | +Prints `block` with `length`. |
| 79 | + |
| 80 | +#### MFRC630.mfrc630_format_block(data, len) |
| 81 | + |
| 82 | +Converts `data` to hexadecimal format. |
| 83 | + |
| 84 | +* `data` The array to be formatted |
| 85 | +* `len` The number of bytes to format |
| 86 | + |
| 87 | +#### MFRC630.mfrc630_print_block(data, len) |
| 88 | + |
| 89 | +Prints the bytes in `data` array in hexadecimal format, separated by spaces using the `mfrc630_format_block` method. |
| 90 | + |
| 91 | +* `data` The array to be printed |
| 92 | +* `len` The number of bytes to print |
| 93 | + |
| 94 | +## Constants |
0 commit comments