From 7b09665f831eaf3c227cd698f0550f0a86390d70 Mon Sep 17 00:00:00 2001 From: lankamadan Date: Thu, 28 Jan 2016 16:51:30 +0900 Subject: [PATCH] Android JNI compilation issue fix & added build option for specifying type of Enrollee - JNI compilation issue is happening due to a change in file location and a structure name change. - Seperated Arduino specific implementation using #ifdef - Changed file persmission for some of the files from 777 to 644 Change-Id: Id73eac55bb678c9e6bddb288db55e5d8cd4680d1 Signed-off-by: lankamadan Reviewed-on: https://gerrit.iotivity.org/gerrit/4865 Tested-by: jenkins-iotivity --- build_common/SConscript | 1 + .../Build_Instructions_Android_Arduino.txt | 0 service/easy-setup/SConscript | 15 +++++++++-- .../mediator/EnrolleeDeviceWiFiOnboarding.java | 7 +++-- .../easy-setup/sdk/mediator/android/jni/Android.mk | 3 ++- .../sdk/mediator/android/jni/jni_easy_setup.cpp | 2 +- .../sdk/mediator/src/EnrolleeSecurity.cpp | 0 .../easy-setup/sdk/mediator/src/EnrolleeSecurity.h | 0 .../easy-setup/sdk/mediator/src/RemoteEnrollee.cpp | 0 .../sdk/mediator/src/RemoteEnrolleeResource.cpp | 0 .../sdk/mediator/src/RemoteEnrolleeResource.h | 0 .../easy-setup/sdk/mediator/src/prov_adapter.cpp | 17 +++++++++++- .../easy-setup/sdk/mediator/src/provisioning.cpp | 2 +- .../sdk/mediator/src/wifi_provisioning.cpp | 31 +++++++++++++++++++--- 14 files changed, 66 insertions(+), 12 deletions(-) mode change 100755 => 100644 service/easy-setup/Build_Instructions_Android_Arduino.txt mode change 100755 => 100644 service/easy-setup/sdk/mediator/src/EnrolleeSecurity.cpp mode change 100755 => 100644 service/easy-setup/sdk/mediator/src/EnrolleeSecurity.h mode change 100755 => 100644 service/easy-setup/sdk/mediator/src/RemoteEnrollee.cpp mode change 100755 => 100644 service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.cpp mode change 100755 => 100644 service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.h diff --git a/build_common/SConscript b/build_common/SConscript index 6bbdbde..f7c2854 100644 --- a/build_common/SConscript +++ b/build_common/SConscript @@ -104,6 +104,7 @@ help_vars.AddVariables(('DEVICE_NAME', 'Network display name for device (For Ard help_vars.Add(PathVariable('ANDROID_NDK', 'Android NDK path', None, PathVariable.PathAccept)) help_vars.Add(PathVariable('ANDROID_HOME', 'Android SDK path', None, PathVariable.PathAccept)) help_vars.Add(PathVariable('ANDROID_GRADLE', 'Gradle binary file', None, PathVariable.PathIsFile)) +help_vars.Add(EnumVariable('TARGET_ENROLLEE', 'Target Enrollee', 'arduino', allowed_values=('arduino', 'tizen', 'linux'))) AddOption('--prefix', dest='prefix', diff --git a/service/easy-setup/Build_Instructions_Android_Arduino.txt b/service/easy-setup/Build_Instructions_Android_Arduino.txt old mode 100755 new mode 100644 diff --git a/service/easy-setup/SConscript b/service/easy-setup/SConscript index 73522af..5be6fda 100755 --- a/service/easy-setup/SConscript +++ b/service/easy-setup/SConscript @@ -29,7 +29,6 @@ easysetup_path = os.curdir ###################################################################### #building Resource client, resourceBroker and resourceCache ###################################################################### - if env.get('RELEASE'): env.AppendUnique(CCFLAGS = ['-Os']) env.AppendUnique(CPPDEFINES = ['NDEBUG']) @@ -38,7 +37,19 @@ else: if env.get('LOGGING'): env.AppendUnique(CPPDEFINES = ['TB_LOG']) - + +# Easysetup provides reference implemenation of Arduino Enrollee. +# Mediator applications developed on different platforms will be default defining the +# flag 'REMOTE_ARDUINO_ENROLEE'. If the target Enrollee is not Arduino, the below commented +# modifications must be enabled instead (and the existing define must be commented). +# +##### The following lines must be uncommented, if target Enrollee is not Arduino +target_enrollee = env.get('TARGET_ENROLLEE') +if target_enrollee == 'arduino': + print "REMOTE_ARDUINO_ENROLEE flag is defined." + print "The Mediator application will be working only with Arduino Enrollee." + env.AppendUnique(CPPDEFINES = ['REMOTE_ARDUINO_ENROLEE']) + # Add third party libraries lib_env = env.Clone() SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env') diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceWiFiOnboarding.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceWiFiOnboarding.java index 09459a3..37e1b1d 100755 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceWiFiOnboarding.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceWiFiOnboarding.java @@ -48,7 +48,7 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice { EnrolleeInfo connectedDevice; private EasySetupManager easySetupManagerNativeInstance; ProvisionEnrollee provisionEnrolleInstance; - Timer myTimer; + Timer myTimer = null; IOnBoardingStatus deviceScanListener = new IOnBoardingStatus() { @@ -122,7 +122,10 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice { protected void stopOnBoardingProcess() { Log.i(TAG, "Stopping on boarding process"); - myTimer.cancel(); + if(myTimer != null) + { + myTimer.cancel(); + } boolean status = mWifiSoftAPManager.setWifiApEnabled(null, false); Log.i(TAG, "Soft AP is disabled with status " + status); } diff --git a/service/easy-setup/sdk/mediator/android/jni/Android.mk b/service/easy-setup/sdk/mediator/android/jni/Android.mk index 0e87f2a..bff0f74 100644 --- a/service/easy-setup/sdk/mediator/android/jni/Android.mk +++ b/service/easy-setup/sdk/mediator/android/jni/Android.mk @@ -55,6 +55,7 @@ NDK_ROOT := /home/madan/android-ndk-r10d LOCAL_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/jniutil/inc \ $(LOCAL_PATH)/../../../../../../service/easy-setup/sdk/mediator/inc \ + $(LOCAL_PATH)/../../../../../../service/easy-setup/sdk/mediator/src \ $(LOCAL_PATH)/../../../../../../service/easy-setup/sdk/common \ $(LOCAL_PATH)/../../../../../../resource/csdk/logger/include \ $(LOCAL_PATH)/../../../../../../resource/csdk/connectivity/common/inc \ @@ -82,4 +83,4 @@ LOCAL_SHARED_LIBRARIES := android-easysetup LOCAL_SHARED_LIBRARIES += android-connectivity_abstraction LOCAL_SHARED_LIBRARIES += android-octbstack -include $(BUILD_SHARED_LIBRARY) \ No newline at end of file +include $(BUILD_SHARED_LIBRARY) diff --git a/service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.cpp b/service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.cpp index b704de5..16386c0 100644 --- a/service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.cpp +++ b/service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.cpp @@ -155,7 +155,7 @@ JNIProvisionEnrollee(JNIEnv LOGI("JNI JNIProvisionEnrollee : netPWD is : %s",netPWD); OCConnectivityType connecitivityType; - EnrolleeNWProvInfo_t netInfo = + EnrolleeNWProvInfo netInfo = { 0}; strncpy(netInfo .netAddressInfo.WIFI.ipAddress, ipAddress, IPV4_ADDR_SIZE-1); diff --git a/service/easy-setup/sdk/mediator/src/EnrolleeSecurity.cpp b/service/easy-setup/sdk/mediator/src/EnrolleeSecurity.cpp old mode 100755 new mode 100644 diff --git a/service/easy-setup/sdk/mediator/src/EnrolleeSecurity.h b/service/easy-setup/sdk/mediator/src/EnrolleeSecurity.h old mode 100755 new mode 100644 diff --git a/service/easy-setup/sdk/mediator/src/RemoteEnrollee.cpp b/service/easy-setup/sdk/mediator/src/RemoteEnrollee.cpp old mode 100755 new mode 100644 diff --git a/service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.cpp b/service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.cpp old mode 100755 new mode 100644 diff --git a/service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.h b/service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.h old mode 100755 new mode 100644 diff --git a/service/easy-setup/sdk/mediator/src/prov_adapter.cpp b/service/easy-setup/sdk/mediator/src/prov_adapter.cpp index e600fac..8ceb278 100644 --- a/service/easy-setup/sdk/mediator/src/prov_adapter.cpp +++ b/service/easy-setup/sdk/mediator/src/prov_adapter.cpp @@ -26,13 +26,21 @@ #include #include "prov_adapter.h" +#include "oic_string.h" + #define ES_PROV_ADAP_TAG "ES_PROVISIONING_ADAPTER" //Use ipv4addr for both InitDiscovery and InitDeviceDiscovery char ipv4addr[IPV4_ADDR_SIZE] = {0}; -static const char * UNICAST_PROVISIONING_QUERY = "coap://%s:%d/oic/res?rt=oic.r.prov"; +#ifdef REMOTE_ARDUINO_ENROLEE + //Arduino Enrollee needs mediator application provide IP and port55555 which is specific + // to Arduino WiFi enrollee + static const char * UNICAST_PROVISIONING_QUERY = "coap://%s:%d/oic/res?rt=oic.r.prov"; +#else + static const char * UNICAST_PROVISIONING_QUERY = "/oic/res?rt=oic.r.prov"; +#endif volatile static OCProvisioningStatusCB cbData = NULL; @@ -80,8 +88,15 @@ void UnRegisterCallback() { OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo) { char findQuery[64] = {0}; + +#ifdef REMOTE_ARDUINO_ENROLEE + //Arduino Enrollee needs mediator application provide IP and port55555 which is specific + // to Arduino WiFi enrollee snprintf(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY, netInfo->netAddressInfo.WIFI.ipAddress, IP_PORT); +#else + OICStrcpy(findQuery, sizeof(UNICAST_PROVISIONING_QUERY), UNICAST_PROVISIONING_QUERY); +#endif return StartProvisioningProcess(netInfo, cbData, findQuery); } diff --git a/service/easy-setup/sdk/mediator/src/provisioning.cpp b/service/easy-setup/sdk/mediator/src/provisioning.cpp index b4d4b11..724d215 100644 --- a/service/easy-setup/sdk/mediator/src/provisioning.cpp +++ b/service/easy-setup/sdk/mediator/src/provisioning.cpp @@ -134,7 +134,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*h int64_t ps; if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_PS, &ps)) { - if (ps == 1) { + if (ps == 2) { input = input->next; continue; } diff --git a/service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp b/service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp index 92105e1..6f8bdc7 100644 --- a/service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp +++ b/service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp @@ -70,8 +70,19 @@ OCStackApplicationResult GetProvisioningStatusResponse(void* /*ctx*/, strncpy(resURI, input->uri, sizeof(resURI) - 1); + +#ifdef REMOTE_ARDUINO_ENROLEE + //Arduino Enrollee needs mediator application provide IP and port55555 which is specific + // to Arduino WiFi enrollee + // REMOTE_ARDUINO_ENROLEE has to be defined if Mediator is being tested with Arduino snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, IP_PORT, - resURI); + resURI); +#else + snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, + clientResponse->addr->port, + resURI); +#endif + if (ProvisionEnrollee(OC_HIGH_QOS, query, OC_RSRVD_ES_URI_PROV, clientResponse->addr, 0) != OC_STACK_OK) { @@ -118,7 +129,8 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/, OCDoHandle /*handle*/, OCClientResponse *clientResponse) { - OC_LOG(INFO, ES_WIFI_PROV_TAG, PCF("Entering FindProvisioningResourceResponse")); + OC_LOG_V(INFO, ES_WIFI_PROV_TAG, "Entering FindProvisioningResourceResponse %s", + clientResponse->devAddr.addr); // If user stopped the process then return from this function; if (IsSetupStopped()) { @@ -127,7 +139,6 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/, return OC_STACK_DELETE_TRANSACTION; } - if (!ValidateFinddResourceResponse(clientResponse)) { ErrorCallback(DEVICE_NOT_PROVISIONED); return OC_STACK_DELETE_TRANSACTION; @@ -139,8 +150,20 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/, OC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", discoveryPayload->resources->uri); +#ifdef REMOTE_ARDUINO_ENROLEE + //Arduino Enrollee needs mediator application provide IP and port55555 which is specific + // to Arduino WiFi enrollee + // REMOTE_ARDUINO_ENROLEE has to be defined if Mediator is being tested with Arduino + snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY, + clientResponse->addr->addr, + IP_PORT, + discoveryPayload->resources->uri); +#else snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY, - clientResponse->devAddr.addr, IP_PORT, discoveryPayload->resources->uri); + clientResponse->devAddr.addr, + clientResponse->devAddr.port, + discoveryPayload->resources->uri); +#endif OC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "query before GetProvisioningStatus call = %s", szQueryUri); -- 2.7.4