summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2014-09-01 13:58:40 +0200
committerPaul Kocialkowski <contact@paulk.fr>2014-09-01 13:58:40 +0200
commitec2052799f860ea6432482dbc26f54b5819130d3 (patch)
treea16599c4478e7a86c82f7996b3cb2c75b0ea9473 /src
parent15e9f165e86064ad637f782bed0b9bd66beb40b9 (diff)
downloadexternal_libnfc-nxp-replicant-4.2.zip
external_libnfc-nxp-replicant-4.2.tar.gz
external_libnfc-nxp-replicant-4.2.tar.bz2
Firmware data load from a static file instead of a libraryHEADreplicant-4.2-0004replicant-4.2-0003replicant-4.2
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/phHal4Nfc.c71
-rw-r--r--src/phLibNfc.c4
2 files changed, 52 insertions, 23 deletions
diff --git a/src/phHal4Nfc.c b/src/phHal4Nfc.c
index f40ed9b..168d4e6 100755
--- a/src/phHal4Nfc.c
+++ b/src/phHal4Nfc.c
@@ -304,41 +304,68 @@ phHal4Nfc_Configure_Layers(
#define LOG_TAG "NFC-HCI"
#include <utils/Log.h>
-#include <dlfcn.h>
+#include <sys/stat.h>
+#include <fcntl.h>
-#define FW_PATH "/system/vendor/firmware/libpn544_fw.so"
-#define FW_PATH_2 "/system/lib/libpn544_fw.so"
+#define FW_PATH "/system/vendor/firmware/pn544.bin"
const unsigned char *nxp_nfc_full_version = NULL;
const unsigned char *nxp_nfc_fw = NULL;
-int dlopen_firmware() {
- void *p;
+int open_firmware() {
+ struct stat firmware_stat;
+ void *buffer;
+ size_t length;
+ int fd;
+ int rc;
- void *handle = dlopen(FW_PATH, RTLD_NOW);
- if (handle == NULL) {
- handle = dlopen(FW_PATH_2, RTLD_NOW);
- if (handle == NULL) {
- ALOGE("Could not open %s or %s", FW_PATH, FW_PATH_2);
- return -1;
- }
+ if (nxp_nfc_full_version != NULL && nxp_nfc_fw != NULL)
+ return 0;
+
+ rc = stat(FW_PATH, &firmware_stat);
+ if (rc < 0) {
+ ALOGE("Could not open %s", FW_PATH);
+ return -1;
+ }
+
+ if (firmware_stat.st_size < NXP_FULL_VERSION_LEN) {
+ ALOGE("Invalid %s size: %lld", FW_PATH, firmware_stat.st_size);
+ return -1;
}
- p = dlsym(handle, "nxp_nfc_full_version");
- if (p == NULL) {
- ALOGE("Could not link nxp_nfc_full_version");
+ length = (size_t) firmware_stat.st_size;
+
+ fd = open(FW_PATH, O_RDONLY);
+ if (fd < 0) {
+ ALOGE("Could not open %s", FW_PATH);
return -1;
}
- nxp_nfc_full_version = (unsigned char *)p;
- p = dlsym(handle, "nxp_nfc_fw");
- if (p == NULL) {
- ALOGE("Could not link nxp_nfc_fw");
+ buffer = malloc(length);
+
+ rc = read(fd, buffer, length);
+ if (rc < (int) length) {
+ ALOGE("Could not read %s", FW_PATH);
return -1;
}
- nxp_nfc_fw = (unsigned char *)p;
+
+ close(fd);
+
+ nxp_nfc_full_version = (const unsigned char *) buffer;
+ nxp_nfc_fw = ((const unsigned char *) buffer + NXP_FULL_VERSION_LEN);
return 0;
+
+}
+
+void close_firmware() {
+ if (nxp_nfc_full_version == NULL || nxp_nfc_fw == NULL)
+ return;
+
+ free((void *) nxp_nfc_full_version);
+
+ nxp_nfc_full_version = NULL;
+ nxp_nfc_fw = NULL;
}
#endif
@@ -377,7 +404,7 @@ NFCSTATUS phHal4Nfc_Open(
else/*Do an initialization*/
{
#ifdef ANDROID
- dlopen_firmware();
+ open_firmware();
#endif
/*If hal4 ctxt in Hwreference is NULL create a new context*/
@@ -723,6 +750,8 @@ NFCSTATUS phHal4Nfc_Close(
{
}
+
+ close_firmware();
}
return closeRetVal;
}
diff --git a/src/phLibNfc.c b/src/phLibNfc.c
index 6477a3f..7b9310a 100644
--- a/src/phLibNfc.c
+++ b/src/phLibNfc.c
@@ -47,7 +47,7 @@
*************************** Macro's ******************************************
*/
-extern int dlopen_firmware();
+extern int open_firmware();
#ifndef STATIC_DISABLE
#define STATIC static
@@ -125,7 +125,7 @@ NFCSTATUS phLibNfc_Download_Mode ()
int phLibNfc_Load_Firmware_Image ()
{
int status;
- status = dlopen_firmware();
+ status = open_firmware();
return status;
}