diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index f777834..69014b4 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -84,6 +84,8 @@ #define SERIAL_DEFAULT_PORT_SPEED 9600 +bool arygon_check_communication(const nfc_device_spec_t nds); + /** * @note ARYGON-ADRA (PN531): ???,n,8,1 * @note ARYGON-ADRB (PN532): 9600,n,8,1 @@ -129,31 +131,33 @@ arygon_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p *pszDeviceFound = 0; serial_port sp; - char acConnect[BUFFER_LENGTH]; + char acPort[BUFFER_LENGTH]; int iDevice; // I have no idea how MAC OS X deals with multiple devices, so a quick workaround for (iDevice=0; iDevice= szDevices) break; } #ifdef DEBUG - if (sp == INVALID_SERIAL_PORT) DBG("Invalid serial port: %s",acConnect); - if (sp == CLAIMED_SERIAL_PORT) DBG("Serial port already claimed: %s",acConnect); + if (sp == INVALID_SERIAL_PORT) DBG("Invalid serial port: %s",acPort); + if (sp == CLAIMED_SERIAL_PORT) DBG("Serial port already claimed: %s",acPort); #endif /* DEBUG */ } #endif /* SERIAL_AUTOPROBE_ENABLED */ @@ -301,5 +305,37 @@ bool arygon_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const s return true; } +//TODO Use tranceive function instead of raw uart send/receive for communication check. +bool +arygon_check_communication(const nfc_device_spec_t nds) +{ + byte_t abtRx[BUFFER_LENGTH]; + size_t szRxLen; + + /** To be sure that PN532 is alive, we have put a "Diagnose" command to execute a "Communication Line Test" */ + const byte_t pncmd_communication_test[] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00,0x00,0xff,0x09,0xf7,0xd4,0x00,0x00,'l','i','b','n','f','c',0xbe,0x00 }; + +#ifdef DEBUG + printf(" TX: "); + print_hex(pncmd_communication_test,sizeof(pncmd_communication_test)); +#endif + uart_send((serial_port)nds, pncmd_communication_test, sizeof(pncmd_communication_test)); + + if(!uart_receive((serial_port)nds,abtRx,&szRxLen)) { + return false; + } +#ifdef DEBUG + printf(" RX: "); + print_hex(abtRx,szRxLen); +#endif + + const byte_t attempted_result[] = { 0x00,0x00,0xff,0x00,0xff,0x00,0x00,0x00,0xff,0x09,0xf7,0xD5,0x01,0x00,'l','i','b','n','f','c',0xbc,0x00}; + if(0 != memcmp(abtRx,attempted_result,sizeof(attempted_result))) { + DBG("%s", "Communication test failed, result doesn't match to attempted one."); + return false; + } + return true; +} + #endif // DRIVER_ARYGON_ENABLED