merge in ics-mr1-release history after reset to ics-mr1
diff --git a/Android.mk b/Android.mk
index af260ce..b45f78b 100644
--- a/Android.mk
+++ b/Android.mk
@@ -129,7 +129,7 @@
LOCAL_MODULE:= libnfc
LOCAL_MODULE_TAGS := optional
-LOCAL_SHARED_LIBRARIES := libcutils libnfc_ndef libdl
+LOCAL_SHARED_LIBRARIES := libcutils libnfc_ndef libdl libhardware
include $(BUILD_SHARED_LIBRARY)
diff --git a/Linux_x86/phDal4Nfc.c b/Linux_x86/phDal4Nfc.c
index 8b4f687..3e031f1 100644
--- a/Linux_x86/phDal4Nfc.c
+++ b/Linux_x86/phDal4Nfc.c
@@ -48,11 +48,9 @@
#include <phDal4Nfc_i2c.h>
#include <phDal4Nfc_link.h>
#include <phDal4Nfc_messageQueueLib.h>
+#include <hardware/hardware.h>
+#include <hardware/nfc.h>
-/*-----------------------------------------------------------------------------------
- MISC DEFINITIONS
-------------------------------------------------------------------------------------*/
-#define DEFAULT_LINK_TYPE ENUM_DAL_LINK_TYPE_COM1
/*-----------------------------------------------------------------------------------
TYPES
@@ -269,7 +267,7 @@
else
{
static phDal4Nfc_sConfig_t hw_config;
- hw_config.nLinkType = DEFAULT_LINK_TYPE;
+ hw_config.deviceNode = NULL;
result = phDal4Nfc_Config(&hw_config, pHwRef );
}
}
@@ -351,6 +349,9 @@
/* Close the link */
gLinkFunc.close();
+ if (gDalContext.pDev != NULL) {
+ nfc_pn544_close(gDalContext.pDev);
+ }
/* Reset the Read Writer context to NULL */
memset((void *)&gReadWriteContext,0,sizeof(gReadWriteContext));
/* Reset the DAL context values to NULL */
@@ -533,22 +534,40 @@
NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
{
NFCSTATUS retstatus = NFCSTATUS_SUCCESS;
+ const hw_module_t* hw_module;
+ nfc_pn544_device_t* pn544_dev;
+ uint8_t num_eeprom_settings;
+ uint8_t* eeprom_settings;
+ int ret;
+
+ /* Retrieve the hw module from the Android NFC HAL */
+ ret = hw_get_module(NFC_HARDWARE_MODULE_ID, &hw_module);
+ if (ret) {
+ LOGE("hw_get_module() failed");
+ return NFCSTATUS_FAILED;
+ }
+ ret = nfc_pn544_open(hw_module, &pn544_dev);
+ if (ret) {
+ LOGE("Could not open pn544 hw_module");
+ return NFCSTATUS_FAILED;
+ }
+ config->deviceNode = pn544_dev->device_node;
+ if (config->deviceNode == NULL) {
+ LOGE("deviceNode NULL");
+ return NFCSTATUS_FAILED;
+ }
DAL_PRINT("phDal4Nfc_Config");
- if ((config == NULL) || (phwref == NULL) || (config->nClientId == -1))
+ if ((config == NULL) || (phwref == NULL))
return NFCSTATUS_INVALID_PARAMETER;
/* Register the link callbacks */
memset(&gLinkFunc, 0, sizeof(phDal4Nfc_link_cbk_interface_t));
- switch(config->nLinkType)
+ switch(pn544_dev->linktype)
{
- case ENUM_DAL_LINK_TYPE_COM1:
- case ENUM_DAL_LINK_TYPE_COM2:
- case ENUM_DAL_LINK_TYPE_COM3:
- case ENUM_DAL_LINK_TYPE_COM4:
- case ENUM_DAL_LINK_TYPE_COM5:
- case ENUM_DAL_LINK_TYPE_USB:
+ case PN544_LINK_TYPE_UART:
+ case PN544_LINK_TYPE_USB:
{
DAL_PRINT("UART link Config");
/* Uart link interface */
@@ -564,7 +583,7 @@
}
break;
- case ENUM_DAL_LINK_TYPE_I2C:
+ case PN544_LINK_TYPE_I2C:
{
DAL_PRINT("I2C link Config");
/* i2c link interface */
@@ -608,6 +627,9 @@
#else
nDeferedCallMessageQueueId = config->nClientId;
#endif
+
+ gDalContext.pDev = pn544_dev;
+
/* Start Read and Write Threads */
if(NFCSTATUS_SUCCESS != phDal4Nfc_StartThreads())
{
@@ -615,7 +637,6 @@
}
gDalContext.hw_valid = TRUE;
-
phDal4Nfc_Reset(1);
phDal4Nfc_Reset(0);
phDal4Nfc_Reset(1);
@@ -696,6 +717,13 @@
phOsalNfc_Message_t OsalMsg ;
int i;
int i2c_error_count;
+ int i2c_workaround;
+ if (gDalContext.pDev != NULL) {
+ i2c_workaround = gDalContext.pDev->enable_i2c_workaround;
+ } else {
+ LOGE("gDalContext.pDev is not set");
+ return NFCSTATUS_FAILED;
+ }
pthread_setname_np(pthread_self(), "reader");
@@ -730,12 +758,12 @@
/* Wait for IRQ !!! */
gReadWriteContext.nNbOfBytesRead = gLinkFunc.read(gReadWriteContext.pReadBuffer, gReadWriteContext.nNbOfBytesToRead);
- /* TODO: Remove this hack
- * Reading the value 0x57 indicates a HW I2C error at I2C address 0x57
+ /* Reading the value 0x57 indicates a HW I2C error at I2C address 0x57
* (pn544). There should not be false positives because a read of length 1
* must be a HCI length read, and a length of 0x57 is impossible (max is 33).
*/
- if(gReadWriteContext.nNbOfBytesToRead == 1 && gReadWriteContext.pReadBuffer[0] == 0x57)
+ if(i2c_workaround && gReadWriteContext.nNbOfBytesToRead == 1 &&
+ gReadWriteContext.pReadBuffer[0] == 0x57)
{
i2c_error_count++;
DAL_DEBUG("RX Thread Read 0x57 %d times\n", i2c_error_count);
diff --git a/Linux_x86/phDal4Nfc_i2c.c b/Linux_x86/phDal4Nfc_i2c.c
index 72da8e7..8b742d9 100644
--- a/Linux_x86/phDal4Nfc_i2c.c
+++ b/Linux_x86/phDal4Nfc_i2c.c
@@ -24,7 +24,7 @@
#define LOG_TAG "NFC_i2c"
#include <cutils/log.h>
-
+#include <hardware/nfc.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
@@ -144,24 +144,12 @@
NFCSTATUS phDal4Nfc_i2c_open_and_configure(pphDal4Nfc_sConfig_t pConfig, void ** pLinkHandle)
{
- char * pComPort;
-
DAL_ASSERT_STR(gI2cPortContext.nOpened==0, "Trying to open but already done!");
- switch(pConfig->nLinkType)
- {
- case ENUM_DAL_LINK_TYPE_I2C:
- pComPort = "/dev/pn544";
- break;
- default:
- DAL_DEBUG("Open failed: unknown type %d\n", pConfig->nLinkType);
- return NFCSTATUS_INVALID_PARAMETER;
- }
-
- DAL_DEBUG("Opening port=%s\n", pComPort);
+ DAL_DEBUG("Opening port=%s\n", pConfig->deviceNode);
/* open port */
- gI2cPortContext.nHandle = open(pComPort, O_RDWR | O_NOCTTY);
+ gI2cPortContext.nHandle = open(pConfig->deviceNode, O_RDWR | O_NOCTTY);
if (gI2cPortContext.nHandle < 0)
{
DAL_DEBUG("Open failed: open() returned %d\n", gI2cPortContext.nHandle);
diff --git a/Linux_x86/phDal4Nfc_uart.c b/Linux_x86/phDal4Nfc_uart.c
index a2f6db3..b19c5c5 100644
--- a/Linux_x86/phDal4Nfc_uart.c
+++ b/Linux_x86/phDal4Nfc_uart.c
@@ -28,7 +28,7 @@
#define LOG_TAG "NFC_uart"
#include <cutils/log.h>
-
+#include <hardware/nfc.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
@@ -159,7 +159,6 @@
NFCSTATUS phDal4Nfc_uart_open_and_configure(pphDal4Nfc_sConfig_t pConfig, void ** pLinkHandle)
{
- char * pComPort;
int nComStatus;
NFCSTATUS nfcret = NFCSTATUS_SUCCESS;
int ret;
@@ -168,41 +167,8 @@
srand(time(NULL));
- switch(pConfig->nLinkType)
- {
- case ENUM_DAL_LINK_TYPE_COM1:
- pComPort = "/dev/ttyO0";
- break;
- case ENUM_DAL_LINK_TYPE_COM2:
- pComPort = "/dev/ttyO1";
- break;
- case ENUM_DAL_LINK_TYPE_COM3:
- pComPort = "/dev/ttyO2";
- break;
- case ENUM_DAL_LINK_TYPE_COM4:
- pComPort = "/dev/ttyO3";
- break;
- case ENUM_DAL_LINK_TYPE_COM5:
- pComPort = "/dev/ttyO4";
- break;
- case ENUM_DAL_LINK_TYPE_COM6:
- pComPort = "/dev/ttyO5";
- break;
- case ENUM_DAL_LINK_TYPE_COM7:
- pComPort = "/dev/ttyO6";
- break;
- case ENUM_DAL_LINK_TYPE_COM8:
- pComPort = "/dev/ttyO7";
- break;
- case ENUM_DAL_LINK_TYPE_USB:
- pComPort = "/dev/ttyUSB0";
- break;
- default:
- return NFCSTATUS_INVALID_PARAMETER;
- }
-
/* open communication port handle */
- gComPortContext.nHandle = open(pComPort, O_RDWR | O_NOCTTY);
+ gComPortContext.nHandle = open(pConfig->deviceNode, O_RDWR | O_NOCTTY);
if (gComPortContext.nHandle < 0)
{
*pLinkHandle = NULL;
diff --git a/inc/phNfcTypes.h b/inc/phNfcTypes.h
index 989cfe8..1f0fe1c 100644
--- a/inc/phNfcTypes.h
+++ b/inc/phNfcTypes.h
@@ -222,28 +222,6 @@
uint32_t length;
} phNfc_sData_t;
-
-/**
- *\brief Possible Hardware Configuration exposed to upper layer.
- * Typically this should be port name (Ex:"COM1","COM2") to which PN544 is connected.
- */
-typedef enum
-{
- ENUM_LINK_TYPE_COM1,
- ENUM_LINK_TYPE_COM2,
- ENUM_LINK_TYPE_COM3,
- ENUM_LINK_TYPE_COM4,
- ENUM_LINK_TYPE_COM5,
- ENUM_LINK_TYPE_COM6,
- ENUM_LINK_TYPE_COM7,
- ENUM_LINK_TYPE_COM8,
- ENUM_LINK_TYPE_I2C,
- ENUM_LINK_TYPE_USB,
- ENUM_LINK_TYPE_TCP,
-
- ENUM_LINK_TYPE_NB,
-} phLibNfc_eConfigLinkType;
-
/**
* \brief Possible Hardware Configuration exposed to upper layer.
* Typically this should be at least the communication link (Ex:"COM1","COM2")
@@ -251,8 +229,8 @@
*/
typedef struct phLibNfc_sConfig_t
{
- /** Hardware communication link to the controller */
- phLibNfc_eConfigLinkType nLinkType;
+ /** Device node of the controller */
+ const char* deviceNode;
/** The client ID (thread ID or message queue ID) */
unsigned int nClientId;
} phLibNfc_sConfig_t, *pphLibNfc_sConfig_t;
diff --git a/src/phDal4Nfc.h b/src/phDal4Nfc.h
index 0913c5e..3cbb585 100644
--- a/src/phDal4Nfc.h
+++ b/src/phDal4Nfc.h
@@ -49,6 +49,7 @@
*
*
*/
+#include <hardware/nfc.h>
/**< Basic type definitions */
#include <phNfcTypes.h>
/**< Generic Interface Layer Function Definitions */
@@ -75,6 +76,7 @@
phNfcIF_sCallBack_t cb_if; /**<Callback info registered by upper layer*/
volatile uint8_t hw_valid; /**<Flag - shows Hardware present or not */
void *pHwRef; /**<Hardware Reference*/
+ nfc_pn544_device_t *pDev; /**<Android HAL reference*/
}phDal4Nfc_SContext_t,*pphDal4Nfc_SContext_t;
/**
@@ -123,26 +125,6 @@
pphNfcIF_Transact_Completion_CB_t writeCbPtr;
} phDal4Nfc_Message_t,*pphDal4Nfc_Message_t;
-/**
- * \ingroup grp_nfc_dal
- *\brief Possible DAL Configuration exposed to upper layer.
- * Typically this should be port name (Ex:"COM1","COM2") to which PN544 is connected.
- */
-#define ENUM_DAL_LINK_TYPE_COM1 ENUM_LINK_TYPE_COM1
-#define ENUM_DAL_LINK_TYPE_COM2 ENUM_LINK_TYPE_COM2
-#define ENUM_DAL_LINK_TYPE_COM3 ENUM_LINK_TYPE_COM3
-#define ENUM_DAL_LINK_TYPE_COM4 ENUM_LINK_TYPE_COM4
-#define ENUM_DAL_LINK_TYPE_COM5 ENUM_LINK_TYPE_COM5
-#define ENUM_DAL_LINK_TYPE_COM6 ENUM_LINK_TYPE_COM6
-#define ENUM_DAL_LINK_TYPE_COM7 ENUM_LINK_TYPE_COM7
-#define ENUM_DAL_LINK_TYPE_COM8 ENUM_LINK_TYPE_COM8
-#define ENUM_DAL_LINK_TYPE_I2C ENUM_LINK_TYPE_I2C
-#define ENUM_DAL_LINK_TYPE_USB ENUM_LINK_TYPE_USB
-#define ENUM_DAL_LINK_TYPE_TCP ENUM_LINK_TYPE_TCP
-
-#define ENUM_DAL_LINK_TYPE_NB ENUM_LINK_TYPE_NB
-typedef phLibNfc_eConfigLinkType phDal4Nfc_eConfigLinkType;
-
typedef phLibNfc_sConfig_t phDal4Nfc_sConfig_t;
typedef phLibNfc_sConfig_t *pphDal4Nfc_sConfig_t;