From 20ed5e1a52621074e58ace20864562954f17b8bd Mon Sep 17 00:00:00 2001 From: Roel Verdult Date: Wed, 28 Jul 2010 12:52:39 +0000 Subject: [PATCH 1/4] fixed wakeup preamble, change PN532 chip to normal mode after wakeup --- libnfc/drivers/pn532_uart.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index c9a3f8e..99bfa28 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -286,14 +286,20 @@ bool pn532_uart_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, con void pn532_uart_wakeup(const nfc_device_spec_t nds) { + byte_t abtRx[BUFFER_LENGTH]; + size_t szRxLen; /** PN532C106 wakeup. */ /** High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */ - const byte_t pncmd_pn532c106_wakeup_preamble[] = { 0x55,0x55,0x00,0x00,0x00 }; - + /** After the preamble we request the PN532C106 chip to switch to "normal" mode (SAM is not used) */ + const byte_t pncmd_pn532c106_wakeup_preamble[] = { 0x55,0x55,0x00,0x00,0x00,0x00,0x00,0xff,0x03,0xfd,0xd4,0x14,0x01,0x17,0x00,0x00,0xff,0x03,0xfd,0xd4,0x14,0x01,0x17,0x00 }; #ifdef DEBUG PRINT_HEX("TX", pncmd_pn532c106_wakeup_preamble,sizeof(pncmd_pn532c106_wakeup_preamble)); #endif uart_send((serial_port)nds, pncmd_pn532c106_wakeup_preamble, sizeof(pncmd_pn532c106_wakeup_preamble)); + if(uart_receive((serial_port)nds,abtRx,&szRxLen)) { +#ifdef DEBUG + PRINT_HEX("RX", abtRx,szRxLen); +#endif } bool From 5129a37ec8100675da1ee9867177b99b59fbf74f Mon Sep 17 00:00:00 2001 From: Roel Verdult Date: Wed, 28 Jul 2010 12:56:40 +0000 Subject: [PATCH 2/4] fixed typo, missed closing bracket ;) --- libnfc/drivers/pn532_uart.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 99bfa28..a7480ac 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -300,6 +300,7 @@ pn532_uart_wakeup(const nfc_device_spec_t nds) #ifdef DEBUG PRINT_HEX("RX", abtRx,szRxLen); #endif + } } bool From f7e8ec0a95aee9f7e8e29f9fdec351b818a28765 Mon Sep 17 00:00:00 2001 From: Emanuele Bertoldi Date: Thu, 29 Jul 2010 10:18:19 +0000 Subject: [PATCH 3/4] nfc-sam: cleanup and Windows support improvements. --- examples/nfc-sam.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/examples/nfc-sam.c b/examples/nfc-sam.c index 7290596..d2581ec 100644 --- a/examples/nfc-sam.c +++ b/examples/nfc-sam.c @@ -30,15 +30,24 @@ #include #include +#ifndef _WIN32 // Needed by sleep() under Unix #include -// FIXME What about sleep() in Windows ? +#define sleep sleep +#define SUSP_TIME 1 // secs. +#else +// Needed by Sleep() under Windows +#include +#define sleep Sleep +#define SUSP_TIME 1000 // msecs. +#endif #include #include #include "nfc-utils.h" #define MAX_FRAME_LEN 264 +#define TIMEOUT 60 // secs. #define NORMAL_MODE 1 #define VIRTUAL_CARD_MODE 2 @@ -48,15 +57,30 @@ bool sam_connection(nfc_device_t* pnd, int mode) { byte_t pncmd_sam_config[] = { 0xD4,0x14,0x00,0x00 }; + size_t szCmd = 0; byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; - - // Only the VIRTUAL_CARD_MODE requires 4 bytes. - int size = sizeof(pncmd_sam_config)-((mode == VIRTUAL_CARD_MODE) ? 0 : 1); + pncmd_sam_config[2] = mode; - if (!pnd->pdc->transceive(pnd->nds,pncmd_sam_config,size,abtRx,&szRxLen)) { + switch (mode) + { + case VIRTUAL_CARD_MODE: + { + // Only the VIRTUAL_CARD_MODE requires 4 bytes. + szCmd = sizeof(pncmd_sam_config); + } + break; + + default: + { + szCmd = sizeof(pncmd_sam_config)-1; + } + break; + } + + if (!pnd->pdc->transceive(pnd->nds,pncmd_sam_config,szCmd,abtRx,&szRxLen)) { ERR("%s %d", "Unable to execute SAMConfiguration command with mode byte:", mode); return false; } @@ -71,10 +95,10 @@ void wait_one_minute() printf("|"); fflush(stdout); - while (secs < 60) + while (secs < TIMEOUT) { - sleep(1); - secs += 1; + sleep(SUSP_TIME); + secs++; printf("."); fflush(stdout); } From f01b73ab32c1cfb57bb81d217056cd5d3e6f44fa Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Thu, 29 Jul 2010 10:47:53 +0000 Subject: [PATCH 4/4] Move usb_reset(3) call. As the documentation states, and as reported in isssue 81 (fixed in r421), usb_reset()'s argument is invalid after the call and so usb_close(3) must be called before usb_reset(3). --- libnfc/drivers/pn53x_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 6b08daa..101525b 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -232,9 +232,9 @@ void pn53x_usb_disconnect(nfc_device_t* pnd) if((ret = usb_release_interface(pus->pudh,0)) < 0) DBG("usb_release failed %i",ret); DBG("%s","resetting USB"); - usb_reset(pus->pudh); if((ret = usb_close(pus->pudh)) < 0) DBG("usb_close failed %i",ret); + usb_reset(pus->pudh); free(pnd->nds); free(pnd); DBG("%s","done!");