49#include "NFCEEPROMDriver.h"
50#include "EventQueue.h"
52#if defined TARGET_DISCO_L475VG_IOT01A
54#define M24SR_I2C_SDA_PIN PB_11
55#define M24SR_I2C_SCL_PIN PB_10
56#define M24SR_GPO_PIN PE_4
57#define M24SR_RF_DISABLE_PIN PE_2
59#elif MBED_CONF_X_NUCLEO_NFC01A1
61#define M24SR_I2C_SDA_PIN D14
62#define M24SR_I2C_SCL_PIN D15
63#define M24SR_GPO_PIN D12
64#define M24SR_RF_DISABLE_PIN D11
68#define M24SR_I2C_SDA_PIN NC
69#define M24SR_I2C_SCL_PIN NC
70#define M24SR_GPO_PIN NC
71#define M24SR_RF_DISABLE_PIN NC
80#define OPEN_SESSION_RETRIES 5
81#define CC_FILE_LENGTH 15
82#define NDEF_FILE_HEADER_SIZE 2
83#define MAX_NDEF_SIZE 0x1FFF
113 C_APDU(uint8_t cla, uint8_t ins, uint16_t p1p2, uint8_t length,
const uint8_t *data, uint8_t expected)
117 header.
P1 = (uint8_t)((p1p2 & 0xFF00) >> 8);
118 header.
P2 = (uint8_t)(p1p2 & 0x00FF);
124 C_APDUHeader_t header;
137enum M24srError_t : uint16_t {
139 M24SR_ERROR = 0x6F00,
140 M24SR_FILE_OVERFLOW_LE = 0x6280,
142 M24SR_PASSWORD_REQUIRED = 0x6300,
143 M24SR_PASSWORD_INCORRECT = 0x63C0,
144 M24SR_PASSWORD_INCORRECT1RETRY = 0x63C1,
145 M24SR_PASSWORD_INCORRECT2RETRY = 0x63C2,
146 M24SR_WRONG_LENGHT = 0x6700,
147 M24SR_UNSUCESSFUL_UPDATING = 0x6581,
148 M24SR_INCOPATIBLE_COMMAND = 0x6981,
149 M24SR_SECURITY_UNSATISFIED = 0x6982,
150 M24SR_REFERENCE_DATA_NOT_USABLE = 0x6984,
152 M24SR_INCORRECT_PARAMETER = 0x6a80,
153 M24SR_FILE_NOT_FOUND = 0x6a82,
154 M24SR_FILE_OVERFLOW_LC = 0x6A84,
156 M24SR_INCORRECT_P1_OR_P2 = 0x6A86,
157 M24SR_RF_SESSION_KILLED = 0x6500,
158 M24SR_INS_NOT_SUPPORTED = 0x6D00,
159 M24SR_CLASS_NOT_SUPPORTED = 0x6E00,
161 M24SR_IO_ERROR_I2CTIMEOUT = 0x0011,
162 M24SR_IO_ERROR_CRC = 0x0012,
163 M24SR_IO_ERROR_NACK = 0x0013,
164 M24SR_IO_ERROR_PARAMETER = 0x0014,
165 M24SR_IO_ERROR_NBATEMPT = 0x0015,
166 M24SR_IO_NOACKNOWLEDGE = 0x0016,
167 M24SR_IO_PIN_NOT_CONNECTED = 0x0017
177 I2C_ANSWER_READY = 3,
186 READ_PASSWORD = 0x01,
187 WRITE_PASSWORD = 0x02,
206 CHANGE_REFERENCE_DATA,
207 ENABLE_VERIFICATION_REQUIREMENT,
208 DISABLE_VERIFICATION_REQUIREMENT,
209 ENABLE_PERMANET_STATE,
210 DISABLE_PERMANET_STATE,
216enum Communication_t {
292 uint16_t write_count)
296 (void) bytes_written;
306 (void) password_type;
451 M24srDriver(PinName i2c_data_pin = M24SR_I2C_SDA_PIN, PinName i2c_clock_pin = M24SR_I2C_SCL_PIN,
452 PinName gpo_pin = M24SR_GPO_PIN, PinName rf_disable_pin = M24SR_RF_DISABLE_PIN);
460 set_callback(&_default_cb);
462 manage_i2c_gpo(I2C_ANSWER_READY);
469 return MAX_NDEF_SIZE;
476 if (_is_session_open) {
481 set_callback(&_open_session_cb);
490 set_callback(&_close_session_cb);
496 virtual void read_bytes(uint32_t address, uint8_t *bytes,
size_t count)
498 if (!_is_session_open) {
503 if (address > _ndef_size) {
508 set_callback(&_read_byte_cb);
510 if (count > _max_read_bytes) {
511 count = _max_read_bytes;
514 if (address + count > _ndef_size) {
515 count = _ndef_size - address;
524 address += NDEF_FILE_HEADER_SIZE;
526 read_binary((uint16_t) address, (uint8_t) count, bytes);
531 virtual void write_bytes(uint32_t address,
const uint8_t *bytes,
size_t count)
533 if (!_is_session_open) {
538 if (address > _ndef_size) {
544 set_callback(&_write_byte_cb);
546 set_callback(&_erase_bytes_cb);
549 if (count > _max_write_bytes) {
550 count = _max_write_bytes;
553 if (address + count > _ndef_size) {
554 count = _ndef_size - address;
563 address += NDEF_FILE_HEADER_SIZE;
565 update_binary((uint16_t) address, (uint8_t) count, bytes);
572 if (!_is_session_open) {
577 if (count > MAX_NDEF_SIZE - NDEF_FILE_HEADER_SIZE) {
582 set_callback(&_set_size_cb);
584 _ndef_size = (uint16_t)count;
587 uint8_t *bytes = (uint8_t *)&_ndef_size;
588 _ndef_size_buffer[0] = bytes[1];
589 _ndef_size_buffer[1] = bytes[0];
591 update_binary(0, NDEF_FILE_HEADER_SIZE, (
const uint8_t *)&_ndef_size_buffer);
598 if (!_is_session_open) {
603 set_callback(&_get_size_cb);
605 read_binary(0, NDEF_FILE_HEADER_SIZE, (uint8_t *)&_ndef_size_buffer);
620 void set_callback(Callbacks *
callback)
625 _command_cb = &_default_cb;
633 Callbacks *get_callback()
637 if (_subcommand_cb) {
638 return _subcommand_cb;
643 void nfc_interrupt_callback()
645 if (_communication_type == ASYNC) {
646 event_queue()->
call(
this, &M24srDriver::manage_event);
657 M24srError_t enable_read_password(
const uint8_t *current_write_password,
const uint8_t *new_password)
659 _subcommand_cb = &_change_password_request_status_cb;
660 _change_password_request_status_cb.set_task(READ_PASSWORD, new_password);
662 return verify(WRITE_PASSWORD, current_write_password);
671 M24srError_t disable_read_password(
const uint8_t *current_write_password)
673 _subcommand_cb = &_change_password_request_status_cb;
674 _change_password_request_status_cb.set_task(READ_PASSWORD, NULL);
676 return verify(WRITE_PASSWORD, current_write_password);
686 M24srError_t enable_write_password(
const uint8_t *current_write_password, uint8_t *new_password)
688 _subcommand_cb = &_change_password_request_status_cb;
689 _change_password_request_status_cb.set_task(WRITE_PASSWORD, new_password);
691 return verify(WRITE_PASSWORD, current_write_password);
700 M24srError_t disable_write_password(
const uint8_t *current_write_password)
702 _subcommand_cb = &_change_password_request_status_cb;
703 _change_password_request_status_cb.set_task(WRITE_PASSWORD, NULL);
705 return verify(WRITE_PASSWORD, current_write_password);
714 M24srError_t disable_all_password(
const uint8_t *super_user_password)
716 _subcommand_cb = &_remove_password_cb;
717 return verify(I2C_PASSWORD, super_user_password);
726 M24srError_t enable_read_only(
const uint8_t *current_write_password)
728 _subcommand_cb = &_change_access_state_cb;
729 _change_access_state_cb.change_access_state(ChangeAccessStateCallback::WRITE,
false);
731 return verify(WRITE_PASSWORD, current_write_password);
740 M24srError_t disable_read_only(
const uint8_t *current_write_password)
742 _subcommand_cb = &_change_access_state_cb;
743 _change_access_state_cb.change_access_state(ChangeAccessStateCallback::WRITE,
true);
745 return verify(I2C_PASSWORD, current_write_password);
754 M24srError_t enable_write_only(
const uint8_t *current_write_password)
756 _subcommand_cb = &_change_access_state_cb;
757 _change_access_state_cb.change_access_state(ChangeAccessStateCallback::READ,
false);
759 return verify(WRITE_PASSWORD, current_write_password);
768 M24srError_t disable_write_only(
const uint8_t *current_write_password)
770 _subcommand_cb = &_change_access_state_cb;
771 _change_access_state_cb.change_access_state(ChangeAccessStateCallback::READ,
true);
773 return verify(I2C_PASSWORD, current_write_password);
778 M24srError_t read_id(uint8_t *nfc_id);
779 M24srError_t get_session(
bool force =
false);
781 M24srError_t deselect();
782 M24srError_t receive_deselect();
784 M24srError_t select_application();
785 M24srError_t receive_select_application();
787 M24srError_t select_cc_file();
788 M24srError_t receive_select_cc_file();
790 M24srError_t select_ndef_file(uint16_t ndef_file_id);
791 M24srError_t receive_select_ndef_file();
793 M24srError_t select_system_file();
794 M24srError_t receive_select_system_file();
796 M24srError_t read_binary(uint16_t offset, uint8_t length, uint8_t *buffer);
797 M24srError_t st_read_binary(uint16_t offset, uint8_t length, uint8_t *buffer);
798 M24srError_t receive_read_binary();
800 M24srError_t update_binary(uint16_t offset, uint8_t length,
const uint8_t *data);
801 M24srError_t receive_update_binary();
803 M24srError_t verify(PasswordType_t password_type,
const uint8_t *password);
804 M24srError_t receive_verify();
806 M24srError_t change_reference_data(PasswordType_t password_type,
const uint8_t *password);
807 M24srError_t receive_change_reference_data();
809 M24srError_t enable_verification_requirement(PasswordType_t password_type);
810 M24srError_t receive_enable_verification_requirement();
812 M24srError_t disable_verification_requirement(PasswordType_t password_type);
813 M24srError_t receive_disable_verification_requirement();
815 M24srError_t enable_permanent_state(PasswordType_t password_type);
816 M24srError_t receive_enable_permanent_state();
818 M24srError_t disable_permanent_state(PasswordType_t password_type);
819 M24srError_t receive_disable_permanent_state();
821 M24srError_t send_interrupt();
822 M24srError_t state_control(
bool gpo_reset);
824 M24srError_t manage_i2c_gpo(NfcGpoState_t gpo_i2c_config);
825 M24srError_t manage_rf_gpo(NfcGpoState_t gpo_rf_config);
827 M24srError_t rf_config(
bool enable);
828 M24srError_t send_fwt_extension(uint8_t fwt_byte);
830 M24srError_t send_receive_i2c(uint16_t length, uint8_t *command);
836 M24srError_t manage_event();
844 M24srError_t io_send_i2c_command(uint8_t length,
const uint8_t *command);
852 M24srError_t io_receive_i2c_response(uint8_t length, uint8_t *command);
858 M24srError_t io_poll_i2c();
860 bool manage_sync_communication(M24srError_t *status);
866 class ChangePasswordRequestStatusCallback :
public Callbacks {
871 ChangePasswordRequestStatusCallback()
872 : _new_password(NULL),
893 void set_task(PasswordType_t type,
const uint8_t *new_password)
895 _new_password = new_password;
897 _enable = (new_password != NULL);
900 virtual void on_verified(M24srDriver *nfc, M24srError_t status, PasswordType_t,
const uint8_t *)
902 if (status != M24SR_SUCCESS) {
903 return on_finish_command(nfc, status);
906 nfc->change_reference_data(_type, _new_password);
908 nfc->disable_verification_requirement(_type);
912 virtual void on_disable_verification_requirement(M24srDriver *nfc, M24srError_t status, PasswordType_t)
914 on_finish_command(nfc, status);
917 virtual void on_change_reference_data(M24srDriver *nfc, M24srError_t status, PasswordType_t type,
const uint8_t *)
919 if (status == M24SR_SUCCESS) {
920 nfc->enable_permanent_state(type);
922 on_finish_command(nfc, status);
926 virtual void on_enable_permanent_state(M24srDriver *nfc, M24srError_t status, PasswordType_t)
928 on_finish_command(nfc, status);
937 void on_finish_command(M24srDriver *nfc, M24srError_t status)
939 nfc->_subcommand_cb = NULL;
942 if (_type == READ_PASSWORD) {
943 nfc->get_callback()->on_enable_read_password(nfc, status, _new_password);
945 nfc->get_callback()->on_enable_write_password(nfc, status, _new_password);
948 if (_type == READ_PASSWORD) {
949 nfc->get_callback()->on_disable_read_password(nfc, status);
951 nfc->get_callback()->on_disable_write_password(nfc, status);
957 const uint8_t *_new_password;
958 PasswordType_t _type;
965 class RemoveAllPasswordCallback :
public Callbacks {
970 RemoveAllPasswordCallback()
971 : _password(NULL) { }
983 virtual void on_verified(M24srDriver *nfc, M24srError_t status, PasswordType_t,
const uint8_t *data)
985 if (status != M24SR_SUCCESS) {
986 return on_finish_command(nfc, status);
989 nfc->disable_permanent_state(READ_PASSWORD);
992 virtual void on_disable_permanent_state(M24srDriver *nfc, M24srError_t status, PasswordType_t type)
994 if (status != M24SR_SUCCESS) {
995 return on_finish_command(nfc, status);
997 if (type == READ_PASSWORD) {
998 nfc->disable_permanent_state(WRITE_PASSWORD);
1000 nfc->disable_verification_requirement(READ_PASSWORD);
1004 virtual void on_disable_verification_requirement(M24srDriver *nfc, M24srError_t status, PasswordType_t type)
1006 if (status != M24SR_SUCCESS) {
1007 return on_finish_command(nfc, status);
1009 if (type == READ_PASSWORD) {
1010 nfc->disable_verification_requirement(WRITE_PASSWORD);
1012 nfc->change_reference_data(READ_PASSWORD, _password);
1016 virtual void on_change_reference_data(M24srDriver *nfc, M24srError_t status, PasswordType_t type,
1017 const uint8_t *data)
1019 if (status != M24SR_SUCCESS) {
1020 return on_finish_command(nfc, status);
1022 if (type == READ_PASSWORD) {
1023 nfc->change_reference_data(WRITE_PASSWORD, data);
1025 on_finish_command(nfc, status);
1035 void on_finish_command(M24srDriver *nfc, M24srError_t status)
1037 nfc->_subcommand_cb = NULL;
1039 nfc->get_callback()->on_disable_all_password(nfc, status);
1047 const uint8_t *_password;
1053 class ChangeAccessStateCallback :
public Callbacks {
1063 ChangeAccessStateCallback()
1081 void change_access_state(AccessType_t type,
bool enable)
1087 virtual void on_verified(M24srDriver *nfc, M24srError_t status, PasswordType_t,
const uint8_t *)
1089 if (status != M24SR_SUCCESS) {
1090 return on_finish_command(nfc, status);
1094 nfc->disable_permanent_state(_type == WRITE ? WRITE_PASSWORD : READ_PASSWORD);
1096 nfc->enable_permanent_state(_type == WRITE ? WRITE_PASSWORD : READ_PASSWORD);
1101 virtual void on_disable_permanent_state(M24srDriver *nfc, M24srError_t status, PasswordType_t type)
1103 if (status != M24SR_SUCCESS) {
1104 return on_finish_command(nfc, status);
1107 nfc->disable_verification_requirement(type);
1110 virtual void on_disable_verification_requirement(M24srDriver *nfc, M24srError_t status, PasswordType_t)
1112 on_finish_command(nfc, status);
1115 virtual void on_enable_permanent_state(M24srDriver *nfc, M24srError_t status, PasswordType_t)
1117 on_finish_command(nfc, status);
1126 void on_finish_command(M24srDriver *nfc, M24srError_t status)
1128 nfc->_subcommand_cb = NULL;
1130 if (_type == READ) {
1132 nfc->get_callback()->on_disable_write_only(nfc, status);
1135 nfc->get_callback()->on_disable_read_only(nfc, status);
1138 if (_type == WRITE) {
1140 nfc->get_callback()->on_enable_read_only(nfc, status);
1142 nfc->get_callback()->on_enable_write_only(nfc, status);
1155 class ManageGPOCallback :
public Callbacks {
1163 : _new_gpo_config(HIGH_IMPEDANCE),
1164 _read_gpo_config(0),
1165 _change_i2c_gpo(true) { }
1180 void set_new_gpo_config(
bool i2cGpo, NfcGpoState_t new_config)
1182 _new_gpo_config = new_config;
1183 _change_i2c_gpo = i2cGpo;
1186 virtual void on_selected_application(M24srDriver *nfc, M24srError_t status)
1188 if (status == M24SR_SUCCESS) {
1189 nfc->select_system_file();
1191 on_finish_command(nfc, status);
1195 virtual void on_selected_system_file(M24srDriver *nfc, M24srError_t status)
1197 if (status == M24SR_SUCCESS) {
1198 nfc->read_binary(0x0004, 0x01, &_read_gpo_config);
1200 on_finish_command(nfc, status);
1204 virtual void on_read_byte(M24srDriver *nfc, M24srError_t status, uint16_t, uint8_t *, uint16_t)
1206 if (status == M24SR_SUCCESS) {
1207 nfc->verify(I2C_PASSWORD, default_password);
1209 on_finish_command(nfc, status);
1213 virtual void on_verified(M24srDriver *nfc, M24srError_t status, PasswordType_t,
const uint8_t *)
1215 if (status != M24SR_SUCCESS) {
1216 return on_finish_command(nfc, status);
1219 if (_change_i2c_gpo) {
1220 _read_gpo_config = (_read_gpo_config & 0xF0) | (uint8_t) _new_gpo_config;
1222 _read_gpo_config = (_read_gpo_config & 0x0F) | (((uint8_t) _new_gpo_config) << 4);
1225 nfc->update_binary(0x0004, 0x01, &_read_gpo_config);
1228 virtual void on_updated_binary(M24srDriver *nfc, M24srError_t status, uint16_t, uint8_t *, uint16_t)
1231 if (status == M24SR_SUCCESS) {
1232 if (_new_gpo_config == I2C_ANSWER_READY) {
1233 nfc->_communication_type = ASYNC;
1235 nfc->_communication_type = SYNC;
1238 on_finish_command(nfc, status);
1247 void on_finish_command(M24srDriver *nfc, M24srError_t status)
1249 nfc->_subcommand_cb = NULL;
1250 if (_change_i2c_gpo) {
1251 nfc->_command_cb->on_manage_i2c_gpo(nfc, status, _new_gpo_config);
1253 nfc->_command_cb->on_manage_rf_gpo(nfc, status, _new_gpo_config);
1259 NfcGpoState_t _new_gpo_config;
1262 uint8_t _read_gpo_config;
1265 bool _change_i2c_gpo;
1271 class ReadIDCallback :
public Callbacks {
1277 ReadIDCallback() : _id(NULL) { }
1289 void set_task(uint8_t *
id)
1294 virtual void on_selected_application(M24srDriver *nfc, M24srError_t status)
1296 if (status == M24SR_SUCCESS) {
1297 nfc->select_system_file();
1299 on_finish_command(nfc, status);
1304 virtual void on_selected_system_file(M24srDriver *nfc, M24srError_t status)
1306 if (status == M24SR_SUCCESS) {
1307 nfc->read_binary(0x0011, 0x01, _id);
1309 on_finish_command(nfc, status);
1313 virtual void on_read_byte(M24srDriver *nfc, M24srError_t status, uint16_t, uint8_t *, uint16_t)
1315 on_finish_command(nfc, status);
1324 void on_finish_command(M24srDriver *nfc, M24srError_t status)
1326 nfc->_subcommand_cb = NULL;
1327 nfc->get_callback()->on_read_id(nfc, status, _id);
1339 class OpenSessionCallBack :
public Callbacks {
1341 OpenSessionCallBack()
1342 : _retries(OPEN_SESSION_RETRIES) { }
1344 void on_session_open(M24srDriver *nfc, M24srError_t status)
1346 if (status == M24SR_SUCCESS) {
1347 nfc->select_application();
1349 nfc->delegate()->on_session_started(
false);
1353 void on_selected_application(M24srDriver *nfc, M24srError_t status)
1355 if (status == M24SR_SUCCESS) {
1356 nfc->select_cc_file();
1358 if (_retries == 0) {
1359 nfc->delegate()->on_session_started(
false);
1362 nfc->select_application();
1367 void on_selected_cc_file(M24srDriver *nfc, M24srError_t status)
1369 if (status == M24SR_SUCCESS) {
1370 nfc->read_binary(0x0000, CC_FILE_LENGTH, CCFile);
1372 nfc->delegate()->on_session_started(
false);
1376 void on_read_byte(M24srDriver *nfc, M24srError_t status, uint16_t, uint8_t *bytes_read,
1377 uint16_t read_count)
1379 if (status != M24SR_SUCCESS || read_count != CC_FILE_LENGTH) {
1380 nfc->delegate()->on_session_started(
false);
1382 uint16_t ndef_file_id = (uint16_t)((bytes_read[0x09] << 8) | bytes_read[0x0A]);
1383 nfc->_max_read_bytes = (uint16_t)((bytes_read[0x03] << 8) | bytes_read[0x04]);
1384 nfc->_max_write_bytes = (uint16_t)((bytes_read[0x05] << 8) | bytes_read[0x06]);
1385 nfc->select_ndef_file(ndef_file_id);
1388 void on_selected_ndef_file(M24srDriver *nfc, M24srError_t status)
1390 nfc->_is_session_open = (status == M24SR_SUCCESS);
1391 nfc->delegate()->on_session_started(nfc->_is_session_open);
1405 class CloseSessionCallBack :
public Callbacks {
1407 CloseSessionCallBack() { }
1409 virtual void on_deselect(M24srDriver *nfc, M24srError_t status)
1411 if (status == M24SR_SUCCESS) {
1412 nfc->_is_session_open =
false;
1413 nfc->delegate()->on_session_ended(
true);
1415 nfc->delegate()->on_session_ended(
false);
1423 class WriteByteCallback :
public Callbacks {
1425 WriteByteCallback() { }
1427 virtual void on_updated_binary(M24srDriver *nfc, M24srError_t status, uint16_t offset, uint8_t *bytes_written,
1428 uint16_t write_count)
1430 if (status != M24SR_SUCCESS) {
1431 nfc->delegate()->on_bytes_written(0);
1435 nfc->delegate()->on_bytes_written(write_count);
1442 class ReadByteCallback :
public Callbacks {
1444 ReadByteCallback() { }
1446 virtual void on_read_byte(M24srDriver *nfc, M24srError_t status, uint16_t offset, uint8_t *bytes_read,
1447 uint16_t read_count)
1449 if (status != M24SR_SUCCESS) {
1450 nfc->delegate()->on_bytes_read(0);
1454 nfc->delegate()->on_bytes_read(read_count);
1458 class SetSizeCallback :
public Callbacks {
1460 SetSizeCallback() { }
1462 virtual void on_updated_binary(M24srDriver *nfc, M24srError_t status, uint16_t offset, uint8_t *bytes_written,
1463 uint16_t write_count)
1465 if (status != M24SR_SUCCESS) {
1466 nfc->delegate()->on_size_written(
false);
1470 nfc->delegate()->on_size_written(
true);
1474 class GetSizeCallback :
public Callbacks {
1476 GetSizeCallback() { }
1478 virtual void on_read_byte(M24srDriver *nfc, M24srError_t status, uint16_t offset, uint8_t *bytes_read,
1479 uint16_t read_count)
1481 if (status != M24SR_SUCCESS) {
1482 nfc->delegate()->on_size_read(
false, 0);
1487 nfc->_ndef_size = (((uint16_t) nfc->_ndef_size_buffer[0]) << 8 | nfc->_ndef_size_buffer[1]);
1489 nfc->delegate()->on_size_read(
true, nfc->_ndef_size);
1493 class EraseBytesCallback :
public Callbacks {
1495 EraseBytesCallback() { }
1497 virtual void on_updated_binary(M24srDriver *nfc, M24srError_t status, uint16_t offset, uint8_t *bytes_written,
1498 uint16_t write_count)
1500 if (status != M24SR_SUCCESS) {
1501 nfc->delegate()->on_bytes_erased(0);
1505 nfc->delegate()->on_bytes_erased(write_count);
1511 static const uint8_t default_password[16];
1521 Callbacks *_command_cb;
1528 Callbacks *_subcommand_cb;
1530 Callbacks _default_cb;
1531 ManageGPOCallback _manage_gpo_cb;
1532 ReadIDCallback _read_id_cb;
1533 ChangePasswordRequestStatusCallback _change_password_request_status_cb;
1534 RemoveAllPasswordCallback _remove_password_cb;
1535 ChangeAccessStateCallback _change_access_state_cb;
1536 OpenSessionCallBack _open_session_cb;
1537 CloseSessionCallBack _close_session_cb;
1538 WriteByteCallback _write_byte_cb;
1539 ReadByteCallback _read_byte_cb;
1540 SetSizeCallback _set_size_cb;
1541 GetSizeCallback _get_size_cb;
1542 EraseBytesCallback _erase_bytes_cb;
1545 uint8_t _buffer[0xFF];
1548 Communication_t _communication_type;
1550 Command_t _last_command;
1551 CommandData_t _last_command_data;
1554 uint16_t _ndef_size;
1555 uint8_t _ndef_size_buffer[NDEF_FILE_HEADER_SIZE];
1556 uint8_t _max_read_bytes;
1557 uint8_t _max_write_bytes;
1560 bool _is_session_open;
int call(F f, Args ...args)
Calls an event on the queue.
A digital input, used for reading the state of a pin.
A digital output, used for setting the state of a pin.
An I2C Master, used for communicating with I2C slave devices.
A digital interrupt input, used to call a function on a rising or falling edge.
The abstraction for a NFC EEPROM driver.
Object that contains all the callbacks fired by this class, each command has its own callback.
virtual void on_change_reference_data(M24srDriver *nfc, M24srError_t status, PasswordType_t type, const uint8_t *data)
called when change_reference_data completes
virtual void on_selected_application(M24srDriver *nfc, M24srError_t status)
called when select_application completes
virtual void on_enable_permanent_state(M24srDriver *nfc, M24srError_t status, PasswordType_t type)
called when enable_permanent_state completes
virtual void on_disable_verification_requirement(M24srDriver *nfc, M24srError_t status, PasswordType_t type)
called when disable_verification_requirement completes
virtual void on_deselect(M24srDriver *nfc, M24srError_t status)
called when deselect completes
virtual void on_updated_binary(M24srDriver *nfc, M24srError_t status, uint16_t offset, uint8_t *bytes_written, uint16_t write_count)
called when update_binary completes
virtual void on_selected_cc_file(M24srDriver *nfc, M24srError_t status)
called when select_cc_file completes
virtual void on_selected_ndef_file(M24srDriver *nfc, M24srError_t status)
called when select_ndef_file completes
virtual void on_read_id(M24srDriver *nfc, M24srError_t status, uint8_t *id)
called when read_id completes
virtual void on_disable_read_only(M24srDriver *nfc, M24srError_t status)
called when disable_read_only completes
virtual void on_manage_i2c_gpo(M24srDriver *nfc, M24srError_t status, NfcGpoState_t new_status)
called when manage_i2c_gpo completes
virtual void on_enable_write_password(M24srDriver *nfc, M24srError_t status, const uint8_t *new_password)
called when oenable_write_password completes
virtual void on_session_open(M24srDriver *nfc, M24srError_t status)
called when get_session completes
virtual void on_disable_all_password(M24srDriver *nfc, M24srError_t status)
called when disable_all_password completes
virtual void on_manage_rf_gpo(M24srDriver *nfc, M24srError_t status, NfcGpoState_t new_status)
called when manage_rf_gpo completes
virtual void on_disable_write_password(M24srDriver *nfc, M24srError_t status)
called when disable_write_password completes
virtual void on_enable_read_password(M24srDriver *nfc, M24srError_t status, const uint8_t *new_password)
called when enable_read_password completes
virtual void on_disable_permanent_state(M24srDriver *nfc, M24srError_t status, PasswordType_t type)
called when disable_permanent_state completes
virtual void on_enable_read_only(M24srDriver *nfc, M24srError_t status)
called when enable_read_only completes
virtual void on_disable_read_password(M24srDriver *nfc, M24srError_t status)
called when disable_read_password completes
virtual void on_read_byte(M24srDriver *nfc, M24srError_t status, uint16_t offset, uint8_t *bytes_read, uint16_t read_count)
called when read_binary completes
virtual void on_enable_write_only(M24srDriver *nfc, M24srError_t status)
called when enable_write_only completes
virtual void on_selected_system_file(M24srDriver *nfc, M24srError_t status)
called when select_system_file completes
virtual void on_verified(M24srDriver *nfc, M24srError_t status, PasswordType_t password_type, const uint8_t *pwd)
called when verify completes
virtual void on_disable_write_only(M24srDriver *nfc, M24srError_t status)
called when disable_write_only completes
virtual void on_enable_verification_requirement(M24srDriver *nfc, M24srError_t status, PasswordType_t type)
called when enable_verification_requirement completes
Class representing a M24SR component.
virtual size_t read_max_size()
virtual void start_session(bool force=true)
virtual void end_session()
virtual void write_bytes(uint32_t address, const uint8_t *bytes, size_t count)
virtual void write_size(size_t count)
virtual void read_bytes(uint32_t address, uint8_t *bytes, size_t count)
M24srDriver(PinName i2c_data_pin=NC, PinName i2c_clock_pin=NC, PinName gpo_pin=NC, PinName rf_disable_pin=NC)
Create the driver, default pin names will be used appropriate for the board.
virtual void erase_bytes(uint32_t address, size_t size)
virtual void on_size_read(bool success, size_t size)=0
Completion of size retrieval operation.
virtual void on_bytes_written(size_t count)=0
Completion of write operation.
virtual void on_session_started(bool success)=0
Completion of session start operation.
virtual void on_bytes_read(size_t count)=0
Completion of read operation.
const uint8_t * data
Command parameters.
uint8_t LE
Expected length of data to be returned.
uint8_t LC
Data field length.
User parameter used to invoke a command, it is used to provide the data back with the response.
uint16_t length
number of bytes in the data array
uint16_t offset
offset parameter used in the read/write command
uint8_t SW1
Command Processing status.
uint8_t * data
Data returned from the card.
uint8_t SW2
Command Processing qualification.