diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index fca8f4b91..37fb9fbb7 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -43,8 +43,8 @@ jobs: - args: "" # debug on, json encoder on - args: "DEBUG=1 JSON_ENCODER=1" - # secure off - - args: "SECURE=0" + # secure off, pki off + - args: "SECURE=0 PKI=0" # TODO: reenable when dynamic allocation is fixed # dynamic allocation off # - args: "DYNAMIC=0" diff --git a/port/android/Makefile b/port/android/Makefile index 0c494300a..4c90a35ee 100644 --- a/port/android/Makefile +++ b/port/android/Makefile @@ -196,7 +196,7 @@ WARNING_FLAGS=-Wall -Wextra -Werror -Wno-error=deprecated-declarations -pedantic CFLAGS_CLOUD=-I../../api/cloud -DOC_CLIENT -DOC_SERVER CFLAGS?=-fPIC -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -ffreestanding -Os -fno-stack-protector -ffunction-sections -fdata-sections -fno-strict-overflow -I./ -I../../include/ -I../../deps/tinycbor/src -I../../ -std=gnu99 $(WARNING_FLAGS) -DLONG_BIT=64 -D__ANDROID_MIN_SDK_VERSION__=${ANDROID_API} OBJ_COMMON=$(addprefix ${OBJDIR}/,$(notdir $(SRC_COMMON:.c=.o))) -OBJ_PORT_COMMON=$(addprefix obj/port/,$(notdir $(SRC_PORT_COMMON:.c=.o))) +OBJ_PORT_COMMON=$(addprefix ${OBJDIR}/port/,$(notdir $(SRC_PORT_COMMON:.c=.o))) OBJ_CLIENT=$(addprefix ${OBJDIR}/client/,$(notdir $(SRC:.c=.o) $(SRC_CLIENT:.c=.o))) OBJ_SERVER=$(addprefix ${OBJDIR}/server/,$(filter-out oc_obt.o oc_obt_otm_justworks.o oc_obt_otm_randompin.o oc_obt_otm_cert.o oc_obt_certs.o,$(notdir $(SRC:.c=.o)))) ifeq ($(CLOUD),1) @@ -326,11 +326,11 @@ ${OBJDIR}/%.o: %.c @mkdir -p ${@D} ${CC} -c -o $@ $< ${CFLAGS} -obj/port/%.o: ../../port/common/%.c +${OBJDIR}/port/%.o: ../../port/common/%.c @mkdir -p ${@D} ${CC} -c -o $@ $< ${CFLAGS} -obj/port/%.o: ../../port/common/posix/%.c +${OBJDIR}/port/%.o: ../../port/common/posix/%.c @mkdir -p ${@D} ${CC} -c -o $@ $< ${CFLAGS} diff --git a/port/android/ipadapter.c b/port/android/ipadapter.c index 7c82089fc..57ec775dd 100644 --- a/port/android/ipadapter.c +++ b/port/android/ipadapter.c @@ -52,15 +52,6 @@ #include #include #include -#if __ANDROID_API__ >= 24 -#include -#define OC_GETIFADDRS getifaddrs -#define OC_FREEIFADDRS freeifaddrs -#else -#include "ifaddrs-android.h" -#define OC_GETIFADDRS android_getifaddrs -#define OC_FREEIFADDRS android_freeifaddrs -#endif /* __ANDROID_API__ >= 24 */ #include #include #include @@ -73,6 +64,20 @@ #include #include +#include +#if !defined(__ANDROID_API__) || __ANDROID_API__ == 10000 +#error __ANDROID_API__ not defined +#endif +#if __ANDROID_API__ >= 24 +#include +#define OC_GETIFADDRS getifaddrs +#define OC_FREEIFADDRS freeifaddrs +#else +#include "ifaddrs-android.h" +#define OC_GETIFADDRS android_getifaddrs +#define OC_FREEIFADDRS android_freeifaddrs +#endif /* __ANDROID_API__ >= 24 */ + #if __ANDROID_API__ < 30 #define OC_NETLINK_IF_CHANGE_NOTIFICATIONS_AVAILABLE #endif /* __ANDROID_API__ < 30 */ diff --git a/swig/Makefile b/swig/Makefile index 615766675..47b097e50 100644 --- a/swig/Makefile +++ b/swig/Makefile @@ -66,6 +66,9 @@ LDFLAG += -lm INSTALL_ANDROID_LIBS = +SECURE ?= 1 +PKI ?= 1 + ifeq ($(DEBUG),1) EXTRA_FLAG += -DOC_LOG_MAXIMUM_LEVEL=8 -g -O0 endif @@ -88,6 +91,9 @@ ifeq ($(IDD), 1) endif ifneq ($(PKI),0) +ifeq ($(SECURE),0) +$(error PKI is enabled, but security is disabled) +endif EXTRA_FLAG += -DOC_PKI SWIG_CFLAG += -DOC_PKI endif @@ -131,14 +137,14 @@ ifeq ($(OS),linux) SWIG_CFLAG += -D__linux__ EXTRA_FLAG += -fno-strict-aliasing HEADER_FILE += -I../port/linux - LDFLAG += -lpthread -lrt + LDFLAG += -lpthread -lrt -Wl,--no-undefined endif ifeq ($(OS),android) EXTRA_HEADER_FILE = -I"$(ANDROID_BASE)/sysroot/usr/include/" PORT_OBJ_DIR = ../port/android/${ANDROID_HOST}obj/ SWIG_CFLAG += -D__linux__ HEADER_FILE += -I../port/android - LDFLAG += -llog + LDFLAG += -llog -Wl,--no-undefined INSTALL_ANDROID_LIBS = install_android_libs ifeq ($(ANDROID_API),) EXTRA_FLAG += -D__ANDROID_MIN_SDK_VERSION__=23 @@ -147,6 +153,7 @@ else endif endif +PORT_COMMON_OBJ_DIR = $(PORT_OBJ_DIR)port/ JAVA_LANG_OBJ_DIR += $(PORT_OBJ_DIR)swig/ all: clean build_swig build_jar build_jni_so $(INSTALL_ANDROID_LIBS) @@ -177,7 +184,7 @@ build_jar: copy_java $(JAR) -cfv $(IOTIVITY_LITE_JAVA_LIBS_DIR)$(JAR_NAME) -C $(IOTIVITY_LITE_JAVA_BIN_DIR) . build_jni_so: $(JNI_SRC) - $(CC) -shared $(JAVA_LANG_OBJ_DIR)*.o $(PORT_OBJ_DIR)*.o $(CLIENT_SERVER_OBJ_DIR)*.o $(CLOUD_OBJ_DIR) $(LDFLAG) -o $(IOTIVITY_LITE_JAVA_LIBS_DIR)$(JNI_SO_NAME) + $(CC) -shared $(JAVA_LANG_OBJ_DIR)*.o $(PORT_COMMON_OBJ_DIR)*.o $(PORT_OBJ_DIR)*.o $(CLIENT_SERVER_OBJ_DIR)*.o $(CLOUD_OBJ_DIR) $(LDFLAG) -o $(IOTIVITY_LITE_JAVA_LIBS_DIR)$(JNI_SO_NAME) install_android_libs: build_swig build_jar build_jni_so # copy so and jar files to samples diff --git a/swig/swig_interfaces/iotivity.swg b/swig/swig_interfaces/iotivity.swg index c68cb0a2c..f8fc25ac1 100644 --- a/swig/swig_interfaces/iotivity.swg +++ b/swig/swig_interfaces/iotivity.swg @@ -66,7 +66,7 @@ %typemap(javain) oc_sp_types_t "$javainput" %typemap(javaout) oc_sp_types_t { return $jnicall; } -%typemap(in) oc_cloud_status_t "$1 = (oc_sp_types_t)$input;" +%typemap(in) oc_cloud_status_t "$1 = (oc_cloud_status_t)$input;" %typemap(out) oc_cloud_status_t "$result = (jint)$1;" %typemap(jni) oc_cloud_status_t "jint"; %typemap(jtype) oc_cloud_status_t "int"; diff --git a/swig/swig_interfaces/oc_api.i b/swig/swig_interfaces/oc_api.i index a0de7a994..0dc0a731c 100644 --- a/swig/swig_interfaces/oc_api.i +++ b/swig/swig_interfaces/oc_api.i @@ -528,6 +528,7 @@ void jni_set_random_pin_callback(oc_random_pin_cb_t cb, jni_callback_data *jcb) */ public"; %rename(setConResAnnounced) oc_set_con_res_announced; + %ignore oc_reset; %rename(reset) jni_reset; %inline %{ @@ -539,6 +540,19 @@ void jni_reset(void) { } %} +%ignore oc_reset_v1; +%rename(resetV1) jni_reset_v1; +%inline %{ +void jni_reset_v1(bool force) { + OC_DBG("JNI: %s\n", __func__); +#ifdef OC_SECURITY + oc_reset_v1(force); +#else /* !OC_SECURITY */ + (void)force; +#endif /* OC_SECURITY */ +} +%} + %ignore oc_reset_device; %rename(resetDevice) jni_reset_device; %inline %{ @@ -996,6 +1010,8 @@ SWIGEXPORT jobject JNICALL Java_org_iotivity_OCMainJNI_getQueryValues(JNIEnv *je %ignore oc_get_response_payload_raw; %ignore oc_send_diagnostic_message; %ignore oc_get_diagnostic_message; +%ignore oc_reset_device_v1; +%ignore oc_is_owned_device; // client side %{ diff --git a/swig/swig_interfaces/oc_core_res.i b/swig/swig_interfaces/oc_core_res.i index 7e7b5b280..8bec5c8ca 100644 --- a/swig/swig_interfaces/oc_core_res.i +++ b/swig/swig_interfaces/oc_core_res.i @@ -51,5 +51,21 @@ %rename (filterResourceByRt) oc_filter_resource_by_rt; %rename (isDCR) oc_core_is_DCR; +%ignore oc_core_is_SVR; +%rename(isSVR) jni_core_is_SVR; +%inline %{ +bool jni_core_is_SVR(const oc_resource_t *resource, size_t device) +{ + OC_DBG("JNI: %s\n", __func__); +#if defined(OC_SECURITY) + return oc_core_is_SVR(resource, device); +#else + (void)resource; + (void)device; + return false; +#endif /* OC_SECURITY */ +} +%} + #define OC_NONNULL(...) %include "oc_core_res.h" diff --git a/swig/swig_interfaces/oc_cred.i b/swig/swig_interfaces/oc_cred.i index 3f4464ff7..b0dab8fd5 100644 --- a/swig/swig_interfaces/oc_cred.i +++ b/swig/swig_interfaces/oc_cred.i @@ -60,6 +60,7 @@ typedef struct role role; #ifdef OC_PKI return &(self->publicdata); #else + (void)self; return NULL; #endif /* OC_PKI */ } @@ -68,6 +69,7 @@ typedef struct role role; #ifdef OC_PKI return self->credusage; #else + (void)self; return OC_CREDUSAGE_NULL; #endif /* OC_PKI */ } @@ -76,15 +78,17 @@ typedef struct role role; #ifdef OC_PKI return self->chain; #else + (void)self; return NULL; #endif /* OC_PKI */ } struct oc_sec_cred_t *getChild() { #ifdef OC_PKI - return self->child; + return self->child; #else - return NULL; + (void)self; + return NULL; #endif /* OC_PKI */ } } @@ -184,6 +188,11 @@ const char *jni_cred_credtype_string(oc_sec_credtype_t credType) } %} +%ignore oc_sec_get_creds; +%ignore oc_sec_remove_cred; +%ignore oc_sec_get_cred_by_credid; +%ignore oc_sec_remove_cred_by_credid; + // TODO: implement oc_cred_verify_certificate_chain %ignore oc_sec_certs_data_t; %ignore oc_verify_sec_certs_data_fn_t; diff --git a/swig/swig_interfaces/oc_obt.i b/swig/swig_interfaces/oc_obt.i index 77fb8f157..247c5dfc7 100644 --- a/swig/swig_interfaces/oc_obt.i +++ b/swig/swig_interfaces/oc_obt.i @@ -80,7 +80,8 @@ %nodefaultctor oc_sec_ace_t; %nodefaultdtor oc_sec_ace_t; -// TODO: implement oc_sec_acl_clear, oc_sec_remove_ace, oc_sec_get_ace_by_aceid, oc_sec_remove_ace_by_aceid, oc_sec_acl_add_bootstrap_acl +// TODO: implement oc_sec_get_acl, oc_sec_acl_clear, oc_sec_remove_ace, oc_sec_get_ace_by_aceid, oc_sec_remove_ace_by_aceid, oc_sec_acl_add_bootstrap_acl +%ignore oc_sec_get_acl; %ignore oc_sec_ace_filter_t; %ignore oc_sec_acl_clear; %ignore oc_sec_remove_ace; @@ -113,6 +114,8 @@ void jni_resource_set_access_in_RFOTM(oc_resource_t *resource, bool state, /*******************End oc_acl.h*****************/ +%ignore oc_obt_set_sd_info; + %ignore oc_obt_init; %rename(init) jni_obt_init; %inline %{ diff --git a/swig/swig_interfaces/oc_pki.i b/swig/swig_interfaces/oc_pki.i index 7646dc6d5..bcfdf9467 100644 --- a/swig/swig_interfaces/oc_pki.i +++ b/swig/swig_interfaces/oc_pki.i @@ -20,6 +20,7 @@ %{ #include "oc_pki.h" +#include "oc_sp.h" #include "port/oc_log_internal.h" %}