Merge r470-477 from trunk.
This commit is contained in:
commit
30e715cff0
3 changed files with 42 additions and 11 deletions
|
@ -30,15 +30,24 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
// Needed by sleep() under Unix
|
// Needed by sleep() under Unix
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
// FIXME What about sleep() in Windows ?
|
#define sleep sleep
|
||||||
|
#define SUSP_TIME 1 // secs.
|
||||||
|
#else
|
||||||
|
// Needed by Sleep() under Windows
|
||||||
|
#include <winbase.h>
|
||||||
|
#define sleep Sleep
|
||||||
|
#define SUSP_TIME 1000 // msecs.
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
#include <nfc/nfc-messages.h>
|
#include <nfc/nfc-messages.h>
|
||||||
#include "nfc-utils.h"
|
#include "nfc-utils.h"
|
||||||
|
|
||||||
#define MAX_FRAME_LEN 264
|
#define MAX_FRAME_LEN 264
|
||||||
|
#define TIMEOUT 60 // secs.
|
||||||
|
|
||||||
#define NORMAL_MODE 1
|
#define NORMAL_MODE 1
|
||||||
#define VIRTUAL_CARD_MODE 2
|
#define VIRTUAL_CARD_MODE 2
|
||||||
|
@ -48,15 +57,30 @@
|
||||||
bool sam_connection(nfc_device_t* pnd, int mode)
|
bool sam_connection(nfc_device_t* pnd, int mode)
|
||||||
{
|
{
|
||||||
byte_t pncmd_sam_config[] = { 0xD4,0x14,0x00,0x00 };
|
byte_t pncmd_sam_config[] = { 0xD4,0x14,0x00,0x00 };
|
||||||
|
size_t szCmd = 0;
|
||||||
|
|
||||||
byte_t abtRx[MAX_FRAME_LEN];
|
byte_t abtRx[MAX_FRAME_LEN];
|
||||||
size_t szRxLen;
|
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;
|
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);
|
ERR("%s %d", "Unable to execute SAMConfiguration command with mode byte:", mode);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -71,10 +95,10 @@ void wait_one_minute()
|
||||||
printf("|");
|
printf("|");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
while (secs < 60)
|
while (secs < TIMEOUT)
|
||||||
{
|
{
|
||||||
sleep(1);
|
sleep(SUSP_TIME);
|
||||||
secs += 1;
|
secs++;
|
||||||
printf(".");
|
printf(".");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,14 +286,21 @@ bool pn532_uart_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, con
|
||||||
void
|
void
|
||||||
pn532_uart_wakeup(const nfc_device_spec_t nds)
|
pn532_uart_wakeup(const nfc_device_spec_t nds)
|
||||||
{
|
{
|
||||||
|
byte_t abtRx[BUFFER_LENGTH];
|
||||||
|
size_t szRxLen;
|
||||||
/** PN532C106 wakeup. */
|
/** PN532C106 wakeup. */
|
||||||
/** High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being 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
|
#ifdef DEBUG
|
||||||
PRINT_HEX("TX", pncmd_pn532c106_wakeup_preamble,sizeof(pncmd_pn532c106_wakeup_preamble));
|
PRINT_HEX("TX", pncmd_pn532c106_wakeup_preamble,sizeof(pncmd_pn532c106_wakeup_preamble));
|
||||||
#endif
|
#endif
|
||||||
uart_send((serial_port)nds, pncmd_pn532c106_wakeup_preamble, sizeof(pncmd_pn532c106_wakeup_preamble));
|
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
|
bool
|
||||||
|
|
|
@ -232,9 +232,9 @@ void pn53x_usb_disconnect(nfc_device_t* pnd)
|
||||||
if((ret = usb_release_interface(pus->pudh,0)) < 0)
|
if((ret = usb_release_interface(pus->pudh,0)) < 0)
|
||||||
DBG("usb_release failed %i",ret);
|
DBG("usb_release failed %i",ret);
|
||||||
DBG("%s","resetting USB");
|
DBG("%s","resetting USB");
|
||||||
usb_reset(pus->pudh);
|
|
||||||
if((ret = usb_close(pus->pudh)) < 0)
|
if((ret = usb_close(pus->pudh)) < 0)
|
||||||
DBG("usb_close failed %i",ret);
|
DBG("usb_close failed %i",ret);
|
||||||
|
usb_reset(pus->pudh);
|
||||||
free(pnd->nds);
|
free(pnd->nds);
|
||||||
free(pnd);
|
free(pnd);
|
||||||
DBG("%s","done!");
|
DBG("%s","done!");
|
||||||
|
|
Loading…
Add table
Reference in a new issue