aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlin Jerpelea <alin.jerpelea@sonymobile.com>2017-09-30 14:10:39 +0200
committerAlin Jerpelea <alin.jerpelea@sonymobile.com>2017-09-30 14:10:45 +0200
commitdceef471f223dbea9d87fdbec98c5e05d961758d (patch)
tree22782d2eb8950163d1ab9767bedc204b1daaf7a2
parentc263ac661a5d024ff71186b35f4ba0c3cd9fe593 (diff)
Implement dynamic linking
The initial implementation was using build time linking and was depending of the proprietary libta.so libray. This change implements dynamic loading and the code can be built without having the proprietary libta.so library at build time Please note that the libta.so blob MUST be prezent on the device Test 1: build will not fail without proprietary libraries Test 2: MAC address is imported on device using the new macaddress Signed-off-by: Alin Jerpelea <alin.jerpelea@sonymobile.com>
-rw-r--r--Android.mk1
-rw-r--r--macaddrsetup.c23
2 files changed, 19 insertions, 5 deletions
diff --git a/Android.mk b/Android.mk
index c0b6274..2de44fa 100644
--- a/Android.mk
+++ b/Android.mk
@@ -8,7 +8,6 @@ LOCAL_SRC_FILES := \
macaddrsetup.c
LOCAL_SHARED_LIBRARIES := \
- libta \
liblog \
libcutils
diff --git a/macaddrsetup.c b/macaddrsetup.c
index 8bcea15..687890c 100644
--- a/macaddrsetup.c
+++ b/macaddrsetup.c
@@ -2,6 +2,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <dlfcn.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
@@ -11,13 +12,11 @@
#define LOG_TAG "macaddrsetup"
#include <cutils/log.h>
+#define LIB_TA "libta.so"
+
#define BT_MAC_FILE "/data/misc/bluetooth/bluetooth_bdaddr"
extern const char *__progname;
-extern int ta_open(uint8_t p, uint8_t m, uint8_t c);
-extern int ta_close(void);
-extern int ta_getsize(uint32_t id, uint32_t *size);
-extern int ta_read(uint32_t id, void *buf, uint32_t size);
int main(int argc, char **argv)
{
@@ -25,12 +24,27 @@ int main(int argc, char **argv)
char buf[6];
FILE *fpb, *fpw = NULL;
int ret, err, bt_addr, wl_addr;
+ void *ta_handle = NULL;
+ int (*ta_open)(uint8_t p, uint8_t m, uint8_t c) = NULL;
+ int (*ta_close)(void) = NULL;
+ int (*ta_getsize)(uint32_t id, uint32_t *size) = NULL;
+ int (*ta_read)(uint32_t id, void *buf, uint32_t size) = NULL;
// Sony had a check for ro.hardware here, but since all supported devices were added here anyways,
// and the values are the same, it has been removed.
wl_addr=2560;
bt_addr=2568;
+ ta_handle = dlopen(LIB_TA, RTLD_NOW);
+ if (!ta_handle) {
+ ALOGE("%s: DLOPEN failed for %s", __func__, LIB_TA);
+ } else {
+ ta_open = dlsym(ta_handle, "ta_open");
+ ta_close = dlsym(ta_handle, "ta_close");
+ ta_getsize = dlsym(ta_handle, "ta_getsize");
+ ta_read = dlsym(ta_handle, "ta_read");
+ }
+
for (;;) {
err = ta_open(2, 0x1, 1);
if (!err)
@@ -107,6 +121,7 @@ int main(int argc, char **argv)
fclose(fpb);
if (fpw)
fclose(fpw);
+ dlclose(ta_handle);
return 0;
}