mirror of https://github.com/ARMmbed/mbed-os.git
NFC: Add a few missing method implementations and run astyle
parent
3f31a95a76
commit
6eb99d65b4
|
@ -117,7 +117,6 @@ private:
|
||||||
nfc_err_t ndef_encode(ac_buffer_builder_t *pBufferBldr);
|
nfc_err_t ndef_encode(ac_buffer_builder_t *pBufferBldr);
|
||||||
nfc_err_t ndef_decode(ac_buffer_t *pBuffer);
|
nfc_err_t ndef_decode(ac_buffer_t *pBuffer);
|
||||||
|
|
||||||
|
|
||||||
Delegate *_delegate;
|
Delegate *_delegate;
|
||||||
ndef_msg_t _ndef_message;
|
ndef_msg_t _ndef_message;
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,6 +43,9 @@ public:
|
||||||
*/
|
*/
|
||||||
NFCRemoteEndpoint(NFCController *controller);
|
NFCRemoteEndpoint(NFCController *controller);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor
|
||||||
|
*/
|
||||||
virtual ~NFCRemoteEndpoint();
|
virtual ~NFCRemoteEndpoint();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -160,16 +160,16 @@ void NFCController::polling_callback(nfc_err_t ret)
|
||||||
|
|
||||||
// Map reason
|
// Map reason
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case NFC_OK:
|
case NFC_OK:
|
||||||
reason = Delegate::nfc_discovery_terminated_completed;
|
reason = Delegate::nfc_discovery_terminated_completed;
|
||||||
break;
|
break;
|
||||||
case NFC_ERR_ABORTED:
|
case NFC_ERR_ABORTED:
|
||||||
reason = Delegate::nfc_discovery_terminated_canceled;
|
reason = Delegate::nfc_discovery_terminated_canceled;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Any other error code means there was an error during the discovery process
|
// Any other error code means there was an error during the discovery process
|
||||||
reason = Delegate::nfc_discovery_terminated_rf_error;
|
reason = Delegate::nfc_discovery_terminated_rf_error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_delegate->on_discovery_terminated(reason);
|
_delegate->on_discovery_terminated(reason);
|
||||||
|
|
|
@ -133,224 +133,224 @@ void NFCEEPROM::erase_ndef_message()
|
||||||
void NFCEEPROM::on_session_started(bool success)
|
void NFCEEPROM::on_session_started(bool success)
|
||||||
{
|
{
|
||||||
switch (_current_op) {
|
switch (_current_op) {
|
||||||
case nfc_eeprom_write_start_session:
|
case nfc_eeprom_write_start_session:
|
||||||
if (!success) {
|
if (!success) {
|
||||||
handle_error(NFC_ERR_CONTROLLER); // An EEPROM is not really a controller but close enough
|
handle_error(NFC_ERR_CONTROLLER); // An EEPROM is not really a controller but close enough
|
||||||
return;
|
|
||||||
}
|
|
||||||
_current_op = nfc_eeprom_write_write_bytes;
|
|
||||||
continue_write();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case nfc_eeprom_read_start_session:
|
|
||||||
if (!success) {
|
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_current_op = nfc_eeprom_read_read_size;
|
|
||||||
_driver->read_size();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case nfc_eeprom_erase_start_session:
|
|
||||||
if (!success) {
|
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_current_op = nfc_eeprom_erase_erase_bytes;
|
|
||||||
continue_erase();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// Should not happen, state machine is broken or driver is doing something wrong
|
|
||||||
handle_error(NFC_ERR_UNKNOWN);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
_current_op = nfc_eeprom_write_write_bytes;
|
||||||
|
continue_write();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case nfc_eeprom_read_start_session:
|
||||||
|
if (!success) {
|
||||||
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_current_op = nfc_eeprom_read_read_size;
|
||||||
|
_driver->read_size();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case nfc_eeprom_erase_start_session:
|
||||||
|
if (!success) {
|
||||||
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_current_op = nfc_eeprom_erase_erase_bytes;
|
||||||
|
continue_erase();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Should not happen, state machine is broken or driver is doing something wrong
|
||||||
|
handle_error(NFC_ERR_UNKNOWN);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NFCEEPROM::on_session_ended(bool success)
|
void NFCEEPROM::on_session_ended(bool success)
|
||||||
{
|
{
|
||||||
switch (_current_op) {
|
switch (_current_op) {
|
||||||
case nfc_eeprom_write_end_session:
|
case nfc_eeprom_write_end_session:
|
||||||
if (!success) {
|
if (!success) {
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
return;
|
|
||||||
}
|
|
||||||
_current_op = nfc_eeprom_idle;
|
|
||||||
if (_delegate != NULL) {
|
|
||||||
_delegate->on_ndef_message_written(_operation_result);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case nfc_eeprom_read_end_session:
|
|
||||||
if (!success) {
|
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_current_op = nfc_eeprom_idle;
|
|
||||||
|
|
||||||
// Try to parse the NDEF message
|
|
||||||
ndef_msg_decode(ndef_message());
|
|
||||||
|
|
||||||
if (_delegate != NULL) {
|
|
||||||
_delegate->on_ndef_message_read(_operation_result);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case nfc_eeprom_erase_end_session:
|
|
||||||
if (!success) {
|
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_current_op = nfc_eeprom_idle;
|
|
||||||
if (_delegate != NULL) {
|
|
||||||
_delegate->on_ndef_message_erased(_operation_result);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// Should not happen, state machine is broken or driver is doing something wrong
|
|
||||||
handle_error(NFC_ERR_UNKNOWN);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
_current_op = nfc_eeprom_idle;
|
||||||
|
if (_delegate != NULL) {
|
||||||
|
_delegate->on_ndef_message_written(_operation_result);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case nfc_eeprom_read_end_session:
|
||||||
|
if (!success) {
|
||||||
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_current_op = nfc_eeprom_idle;
|
||||||
|
|
||||||
|
// Try to parse the NDEF message
|
||||||
|
ndef_msg_decode(ndef_message());
|
||||||
|
|
||||||
|
if (_delegate != NULL) {
|
||||||
|
_delegate->on_ndef_message_read(_operation_result);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case nfc_eeprom_erase_end_session:
|
||||||
|
if (!success) {
|
||||||
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_current_op = nfc_eeprom_idle;
|
||||||
|
if (_delegate != NULL) {
|
||||||
|
_delegate->on_ndef_message_erased(_operation_result);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Should not happen, state machine is broken or driver is doing something wrong
|
||||||
|
handle_error(NFC_ERR_UNKNOWN);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NFCEEPROM::on_bytes_read(size_t count)
|
void NFCEEPROM::on_bytes_read(size_t count)
|
||||||
{
|
{
|
||||||
switch (_current_op) {
|
switch (_current_op) {
|
||||||
case nfc_eeprom_read_read_bytes: {
|
case nfc_eeprom_read_read_bytes: {
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Discard bytes that were actually read and update address
|
|
||||||
_eeprom_address += count;
|
|
||||||
ac_buffer_builder_t *buffer_builder = ndef_msg_buffer_builder(ndef_message());
|
|
||||||
ac_buffer_builder_write_n_skip(buffer_builder, count);
|
|
||||||
|
|
||||||
// Continue reading
|
|
||||||
continue_read();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// Should not happen, state machine is broken or driver is doing something wrong
|
|
||||||
handle_error(NFC_ERR_UNKNOWN);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Discard bytes that were actually read and update address
|
||||||
|
_eeprom_address += count;
|
||||||
|
ac_buffer_builder_t *buffer_builder = ndef_msg_buffer_builder(ndef_message());
|
||||||
|
ac_buffer_builder_write_n_skip(buffer_builder, count);
|
||||||
|
|
||||||
|
// Continue reading
|
||||||
|
continue_read();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// Should not happen, state machine is broken or driver is doing something wrong
|
||||||
|
handle_error(NFC_ERR_UNKNOWN);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NFCEEPROM::on_bytes_written(size_t count)
|
void NFCEEPROM::on_bytes_written(size_t count)
|
||||||
{
|
{
|
||||||
switch (_current_op) {
|
switch (_current_op) {
|
||||||
case nfc_eeprom_write_write_bytes:
|
case nfc_eeprom_write_write_bytes:
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip bytes that were actually written and update address
|
|
||||||
_eeprom_address += count;
|
|
||||||
ac_buffer_read_n_skip(&_ndef_buffer_reader, count);
|
|
||||||
|
|
||||||
// Continue writing
|
|
||||||
continue_write();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Should not happen, state machine is broken or driver is doing something wrong
|
|
||||||
handle_error(NFC_ERR_UNKNOWN);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip bytes that were actually written and update address
|
||||||
|
_eeprom_address += count;
|
||||||
|
ac_buffer_read_n_skip(&_ndef_buffer_reader, count);
|
||||||
|
|
||||||
|
// Continue writing
|
||||||
|
continue_write();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Should not happen, state machine is broken or driver is doing something wrong
|
||||||
|
handle_error(NFC_ERR_UNKNOWN);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NFCEEPROM::on_size_written(bool success)
|
void NFCEEPROM::on_size_written(bool success)
|
||||||
{
|
{
|
||||||
switch (_current_op) {
|
switch (_current_op) {
|
||||||
case nfc_eeprom_write_write_size:
|
case nfc_eeprom_write_write_size:
|
||||||
if (!success) {
|
if (!success) {
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// End session
|
|
||||||
_current_op = nfc_eeprom_write_end_session;
|
|
||||||
_operation_result = NFC_OK;
|
|
||||||
_driver->end_session();
|
|
||||||
break;
|
|
||||||
case nfc_eeprom_erase_write_size:
|
|
||||||
if (!success) {
|
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// End session
|
|
||||||
_current_op = nfc_eeprom_erase_end_session;
|
|
||||||
_operation_result = NFC_OK;
|
|
||||||
_driver->end_session();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Should not happen, state machine is broken or driver is doing something wrong
|
|
||||||
handle_error(NFC_ERR_UNKNOWN);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// End session
|
||||||
|
_current_op = nfc_eeprom_write_end_session;
|
||||||
|
_operation_result = NFC_OK;
|
||||||
|
_driver->end_session();
|
||||||
|
break;
|
||||||
|
case nfc_eeprom_erase_write_size:
|
||||||
|
if (!success) {
|
||||||
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// End session
|
||||||
|
_current_op = nfc_eeprom_erase_end_session;
|
||||||
|
_operation_result = NFC_OK;
|
||||||
|
_driver->end_session();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Should not happen, state machine is broken or driver is doing something wrong
|
||||||
|
handle_error(NFC_ERR_UNKNOWN);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NFCEEPROM::on_size_read(bool success, size_t size)
|
void NFCEEPROM::on_size_read(bool success, size_t size)
|
||||||
{
|
{
|
||||||
switch (_current_op) {
|
switch (_current_op) {
|
||||||
case nfc_eeprom_read_read_size: {
|
case nfc_eeprom_read_read_size: {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset NDEF message buffer builder
|
|
||||||
ac_buffer_builder_t *buffer_builder = ndef_msg_buffer_builder(ndef_message());
|
|
||||||
ac_buffer_builder_reset(buffer_builder);
|
|
||||||
|
|
||||||
// Check that we have a big enough buffer to read the message
|
|
||||||
if (size > ac_buffer_builder_writable(buffer_builder)) {
|
|
||||||
// Not enough space, close session
|
|
||||||
_current_op = nfc_eeprom_read_end_session;
|
|
||||||
_operation_result = NFC_ERR_BUFFER_TOO_SMALL;
|
|
||||||
_driver->end_session();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save size and reset address
|
|
||||||
_eeprom_address = 0;
|
|
||||||
_ndef_buffer_read_sz = size;
|
|
||||||
|
|
||||||
// Start reading bytes
|
|
||||||
_current_op = nfc_eeprom_read_read_bytes;
|
|
||||||
continue_read();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// Should not happen, state machine is broken or driver is doing something wrong
|
|
||||||
handle_error(NFC_ERR_UNKNOWN);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset NDEF message buffer builder
|
||||||
|
ac_buffer_builder_t *buffer_builder = ndef_msg_buffer_builder(ndef_message());
|
||||||
|
ac_buffer_builder_reset(buffer_builder);
|
||||||
|
|
||||||
|
// Check that we have a big enough buffer to read the message
|
||||||
|
if (size > ac_buffer_builder_writable(buffer_builder)) {
|
||||||
|
// Not enough space, close session
|
||||||
|
_current_op = nfc_eeprom_read_end_session;
|
||||||
|
_operation_result = NFC_ERR_BUFFER_TOO_SMALL;
|
||||||
|
_driver->end_session();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save size and reset address
|
||||||
|
_eeprom_address = 0;
|
||||||
|
_ndef_buffer_read_sz = size;
|
||||||
|
|
||||||
|
// Start reading bytes
|
||||||
|
_current_op = nfc_eeprom_read_read_bytes;
|
||||||
|
continue_read();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// Should not happen, state machine is broken or driver is doing something wrong
|
||||||
|
handle_error(NFC_ERR_UNKNOWN);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NFCEEPROM::on_bytes_erased(size_t count)
|
void NFCEEPROM::on_bytes_erased(size_t count)
|
||||||
{
|
{
|
||||||
switch (_current_op) {
|
switch (_current_op) {
|
||||||
case nfc_eeprom_erase_erase_bytes:
|
case nfc_eeprom_erase_erase_bytes:
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
handle_error(NFC_ERR_CONTROLLER);
|
handle_error(NFC_ERR_CONTROLLER);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update address
|
|
||||||
_eeprom_address += count;
|
|
||||||
|
|
||||||
// Continue erasing
|
|
||||||
continue_erase();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Should not happen, state machine is broken or driver is doing something wrong
|
|
||||||
handle_error(NFC_ERR_UNKNOWN);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update address
|
||||||
|
_eeprom_address += count;
|
||||||
|
|
||||||
|
// Continue erasing
|
||||||
|
continue_erase();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Should not happen, state machine is broken or driver is doing something wrong
|
||||||
|
handle_error(NFC_ERR_UNKNOWN);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,3 +75,8 @@ nfc_err_t NFCNDEFCapable::ndef_decode(ac_buffer_t *pBuffer)
|
||||||
parse_ndef_message(*pBuffer);
|
parse_ndef_message(*pBuffer);
|
||||||
return NFC_OK;
|
return NFC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ndef_msg_t *NFCNDEFCapable::ndef_message()
|
||||||
|
{
|
||||||
|
return &_ndef_message;
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,11 @@ NFCRemoteEndpoint::NFCRemoteEndpoint(NFCController *controller) : _controller(co
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NFCRemoteEndpoint::~NFCRemoteEndpoint()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
nfc_rf_protocols_bitmask_t NFCRemoteEndpoint::rf_protocols()
|
nfc_rf_protocols_bitmask_t NFCRemoteEndpoint::rf_protocols()
|
||||||
{
|
{
|
||||||
nfc_rf_protocols_bitmask_t rf_protocols = {0};
|
nfc_rf_protocols_bitmask_t rf_protocols = {0};
|
||||||
|
|
|
@ -40,6 +40,11 @@ Type4RemoteInitiator::Type4RemoteInitiator(NFCController *controller, uint8_t *b
|
||||||
nfc_tech_type4_target_init(&_type4, &_iso7816, ndef_message());
|
nfc_tech_type4_target_init(&_type4, &_iso7816, ndef_message());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Type4RemoteInitiator::~Type4RemoteInitiator()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
nfc_err_t Type4RemoteInitiator::connect()
|
nfc_err_t Type4RemoteInitiator::connect()
|
||||||
{
|
{
|
||||||
if (_is_connected) {
|
if (_is_connected) {
|
||||||
|
@ -121,3 +126,15 @@ bool Type4RemoteInitiator::is_ndef_supported() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Type4RemoteInitiator::disconnected_callback(bool deselected)
|
||||||
|
{
|
||||||
|
// Call disconnected callback
|
||||||
|
disconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Type4RemoteInitiator::s_disconnected_callback(nfc_tech_iso7816_t *pIso7816, bool deselected, void *pUserData)
|
||||||
|
{
|
||||||
|
Type4RemoteInitiator* self = (Type4RemoteInitiator*) pUserData;
|
||||||
|
self->disconnected_callback(deselected);
|
||||||
|
}
|
Loading…
Reference in New Issue