Merge branch 'master' into windows-port
authorDavid Antler <david.a.antler@intel.com>
Mon, 13 Jun 2016 21:33:25 +0000 (14:33 -0700)
committerDavid Antler <david.a.antler@intel.com>
Mon, 13 Jun 2016 21:33:31 +0000 (14:33 -0700)
Change-Id: Ia2e02ce01d3cb8b73b22f7c2ff4169c340d6f72f
Signed-off-by: David Antler <david.a.antler@intel.com>
37 files changed:
android/android_api/base/jni/JniCaInterface.c
android/android_api/base/jni/JniCaInterface.h
android/android_api/base/jni/JniOcPlatform.cpp
android/android_api/base/jni/JniOcPlatform.h
android/android_api/base/jni/JniOcRepresentation.cpp
android/android_api/base/jni/JniOcRepresentation.h
android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java
android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java
android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java
android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java
android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java
android/examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java
android/examples/devicediscoveryserver/src/main/java/org/iotivity/base/examples/DeviceDiscoveryServer.java
gbsbuild.sh
resource/csdk/connectivity/api/cautilinterface.h
resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.h
resource/csdk/connectivity/src/bt_le_adapter/android/calenwmonitor.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleutils.c
resource/csdk/connectivity/util/inc/camanagerleinterface.h
resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c
resource/csdk/connectivity/util/src/cautilinterface.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/src/aclresource.c
resource/csdk/security/src/doxmresource.c
resource/csdk/security/src/pstatresource.c
resource/csdk/security/unittest/aclresourcetest.cpp
resource/csdk/stack/include/octypes.h
resource/csdk/stack/include/payload_logging.h
resource/csdk/stack/src/ocpayload.c
resource/csdk/stack/src/ocpayloadconvert.c
resource/csdk/stack/src/ocpayloadparse.c
resource/csdk/stack/test/stacktests.cpp
resource/include/OCRepresentation.h
resource/src/OCRepresentation.cpp
resource/unittests/OCRepresentationEncodingTest.cpp

index d641f3d..81fcd81 100644 (file)
@@ -329,3 +329,14 @@ Java_org_iotivity_ca_CaInterface_caBtPairingCreateBond(JNIEnv *env, jclass clazz
     (void)clazz;
     CAUtilCreateBond(env, device);
 }
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl(JNIEnv *env, jclass clazz,
+                                                           jint intervalTime, jint workignCount)
+{
+    LOGI("setLeScanIntervalTimeImpl");
+    (void)env;
+    (void)clazz;
+    CAUtilSetLEScanInterval(intervalTime, workignCount);
+}
+
index 20dc995..9861eb8 100644 (file)
@@ -121,6 +121,14 @@ extern "C" {
     JNIEXPORT void JNICALL Java_org_iotivity_ca_CaInterface_initialize
         (JNIEnv *, jclass, jobject, jobject);
 
+    /*
+     * Class:     Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl
+     * Method:    setLeScanIntervalTimeImpl
+     * Signature: (II)V
+     */
+    JNIEXPORT void JNICALL Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl
+        (JNIEnv *, jclass, jint, jint);
+
 #ifdef __cplusplus
 }
 #endif
index 93029c9..8987a69 100644 (file)
@@ -26,6 +26,7 @@
 #include "JniOcResourceResponse.h"
 #include "JniOcSecurity.h"
 #include "JniUtils.h"
+#include "ocpayload.h"
 
 using namespace OC;
 
@@ -1070,20 +1071,44 @@ jobject jListener, jint jResourceProperty)
 JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0(
     JNIEnv *env,
     jclass clazz,
-    jstring jDeviceName)
+    jstring jDeviceName,
+    jobjectArray jDeviceTypes)
 {
     LOGI("OcPlatform_registerDeviceInfo");
 
-    std::string deviceName;
-    if (jDeviceName)
+    if (!jDeviceName)
     {
-        deviceName = env->GetStringUTFChars(jDeviceName, nullptr);
+        ThrowOcException(OC_STACK_INVALID_PARAM, "deviceName cannot be null");
+        return;
+    }
+
+    if (!jDeviceTypes)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "deviceTypes cannot be null");
+        return;
     }
 
     OCDeviceInfo deviceInfo;
     try
     {
-        DuplicateString(&deviceInfo.deviceName, deviceName);
+        DuplicateString(&deviceInfo.deviceName, env->GetStringUTFChars(jDeviceName, nullptr));
+        deviceInfo.types = NULL;
+
+        jsize len = env->GetArrayLength(jDeviceTypes);
+        for (jsize i = 0; i < len; ++i)
+        {
+            jstring jStr = (jstring)env->GetObjectArrayElement(jDeviceTypes, i);
+            if (!jStr)
+            {
+                ThrowOcException(OC_STACK_INVALID_PARAM, "device type cannot be null");
+                return;
+            }
+
+            OCResourcePayloadAddStringLL(&deviceInfo.types, env->GetStringUTFChars(jStr, nullptr));
+            if (env->ExceptionCheck()) return;
+
+            env->DeleteLocalRef(jStr);
+        }
     }
     catch (std::exception &e)
     {
index cfd6853..c66ad43 100644 (file)
@@ -163,10 +163,10 @@ extern "C" {
     /*
     * Class:     org_iotivity_base_OcPlatform
     * Method:    registerDeviceInfo0
-    * Signature: (Ljava/lang/String;)V
+    * Signature: (Ljava/lang/String;[Ljava/lang/String;)V
     */
     JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0
-        (JNIEnv *, jclass, jstring);
+        (JNIEnv *, jclass, jstring, jobjectArray);
 
     /*
     * Class:     org_iotivity_base_OcPlatform
index c9cf0d3..1403349 100644 (file)
@@ -19,6 +19,9 @@
 * //
 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 */
+
+#include <map>
+
 #include "JniOcRepresentation.h"
 #include "JniUtils.h"
 
@@ -40,6 +43,30 @@ OCRepresentation* JniOcRepresentation::getOCRepresentationPtr(JNIEnv *env, jobje
 
 /*
 * Class:     org_iotivity_base_OcRepresentation
+* Method:    getValues
+* Signature: ()Ljava/util/Map;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues
+(JNIEnv *env, jobject thiz)
+{
+    LOGD("OcRepresentation_getValues");
+    OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
+    if (!rep) return nullptr;
+
+    std::map<std::string, AttributeValue> values = rep->getValues();
+    jobject jHashMap = env->NewObject(g_cls_HashMap, g_mid_HashMap_ctor);
+    if (!jHashMap) return nullptr;
+
+    for (std::map<std::string, AttributeValue>::const_iterator it = values.begin(); it != values.end(); it++) {
+        jobject key = static_cast<jobject>(env->NewStringUTF(it->first.c_str()));
+        jobject val = boost::apply_visitor(JObjectConverter(env), it->second);
+        env->CallObjectMethod(jHashMap, g_mid_HashMap_put, key, val);
+    }
+    return jHashMap;
+}
+
+/*
+* Class:     org_iotivity_base_OcRepresentation
 * Method:    getValueN
 * Signature: (Ljava/lang/String;)Ljava/lang/Object;
 */
index e0a87b6..a153dd7 100644 (file)
@@ -462,6 +462,14 @@ extern "C" {
 
     /*
     * Class:     org_iotivity_base_OcRepresentation
+    * Method:    getValues
+    * Signature: ()Ljava/util/Map;
+    */
+    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues
+        (JNIEnv *, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcRepresentation
     * Method:    getValueN
     * Signature: (Ljava/lang/String;)Ljava/lang/Object;
     */
index 3ab7dd2..d6a67c7 100644 (file)
@@ -25,6 +25,7 @@ package org.iotivity.base;
 import android.test.InstrumentationTestCase;
 import android.util.Log;
 
+import java.util.Arrays;
 import java.util.Date;
 import java.util.EnumSet;
 import java.util.HashMap;
@@ -1048,7 +1049,10 @@ public class SmokeTest extends InstrumentationTestCase {
             }
         };
 
-        OcDeviceInfo devInfo = new OcDeviceInfo("myDeviceName");
+        OcDeviceInfo devInfo = new OcDeviceInfo(
+                "myDeviceName",
+                Arrays.asList(new String[]{"oic.d.test"})
+        );
 
         try {
             //server
index acb4cfa..4320ad1 100644 (file)
 
 package org.iotivity.base;
 
+import java.util.List;
+
 /**
- * This class is expected as input for device properties. Device name is mandatory and expected
- * from the application. Device id of type UUID will be generated by the stack.
+ * This class is expected as input for device properties. Device name and types are mandatory
+ * and expected from the application. Device id of type UUID will be generated by the stack.
  */
 public class OcDeviceInfo {
 
     private String mDeviceName;
+    private List<String> mDeviceTypes;
 
-    public OcDeviceInfo(String deviceName) {
-
+    public OcDeviceInfo(String deviceName, List<String> deviceTypes) {
         this.mDeviceName = deviceName;
+        this.mDeviceTypes = deviceTypes;
     }
 
     public String getDeviceName() {
         return mDeviceName;
     }
+
+    public List<String> getDeviceTypes() {
+        return mDeviceTypes;
+    }
 }
index d08b1c6..e37838d 100644 (file)
@@ -541,12 +541,16 @@ public final class OcPlatform {
             OcDeviceInfo ocDeviceInfo) throws OcException {
         OcPlatform.initCheck();
         OcPlatform.registerDeviceInfo0(
-                ocDeviceInfo.getDeviceName()
+                ocDeviceInfo.getDeviceName(),
+                ocDeviceInfo.getDeviceTypes().toArray(
+                        new String[ocDeviceInfo.getDeviceTypes().size()]
+                )
         );
     }
 
     private static native void registerDeviceInfo0(
-            String deviceName
+            String deviceName,
+            String[] deviceTypes
     ) throws OcException;
 
     /**
index 0be617a..24d8b88 100644 (file)
@@ -25,6 +25,7 @@ package org.iotivity.base;
 import java.security.InvalidParameterException;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 /**
  *
@@ -52,6 +53,8 @@ public class OcRepresentation {
         this.mNativeNeedsDelete = nativeNeedsDelete;
     }
 
+    public native Map<String, Object> getValues();
+
     public <T> T getValue(String key) throws OcException {
         Object obj = this.getValueN(key);
         @SuppressWarnings("unchecked")
index 7771ba1..3d62800 100644 (file)
@@ -177,4 +177,19 @@ public class CaInterface {
     private static native void caBtPairingStartScan();
     private static native void caBtPairingStopScan();
     private static native void caBtPairingCreateBond(BluetoothDevice device);
+
+    /**
+     *  set BLE scan interval time and working count.
+     *  scanning logic (start scan -> stop scan) will be worked repeatly for workingCount.
+     *  and if you choose '0' value for workingCount parameter,
+     *  scanning will be worked continually as interval time.
+     *  @param intervalTime                  interval time(Seconds).
+     *  @param workingCount                  working count with interval time.
+     */
+
+    public synchronized static void setLeScanIntervalTime(int intervalTime, int workingCount){
+        CaInterface.setLeScanIntervalTimeImpl(intervalTime, workingCount);
+    }
+
+    private static native void setLeScanIntervalTimeImpl(int intervalTime, int workingCount);
 }
index 6c2d317..28f9a93 100644 (file)
@@ -127,7 +127,7 @@ public class DeviceDiscoveryClient extends Activity implements
     private final static Map<String, String> DEVICE_INFO_KEYS = new HashMap<String, String>() {{
         put("di", "Device ID: ");
         put("n", "Device name: ");
-        put("lcv", "Spec version url: ");
+        put("icv", "Spec version url: ");
         put("dmv", "Data Model: ");
     }};
 
@@ -138,6 +138,12 @@ public class DeviceDiscoveryClient extends Activity implements
             for (String key : DEVICE_INFO_KEYS.keySet()) {
                 msg("\t" + DEVICE_INFO_KEYS.get(key) + ocRepresentation.getValue(key));
             }
+
+            msg("\tDevice types:");
+
+            for (String type : ocRepresentation.getResourceTypes()) {
+                msg("\t\t" + type);
+            }
         } catch (OcException e) {
             Log.e(TAG, e.toString());
             msg("Failed to read device info values.");
index a2920f4..c0d96b7 100644 (file)
@@ -40,6 +40,8 @@ import org.iotivity.base.PlatformConfig;
 import org.iotivity.base.QualityOfService;
 import org.iotivity.base.ServiceType;
 
+import java.util.Arrays;
+
 /**
  * This sample demonstrates platform and device discovery feature.
  * The server sets the platform and device related info. which can be later retrieved by a client.
@@ -61,7 +63,11 @@ public class DeviceDiscoveryServer extends Activity {
         msg("Configuring platform.");
         OcPlatform.Configure(platformConfig);
 
-        OcDeviceInfo deviceInfo = new OcDeviceInfo("myDeviceName");
+        OcDeviceInfo deviceInfo = new OcDeviceInfo(
+                "myDeviceName",
+                Arrays.asList(new String[]{"oic.d.phone"})
+        );
+
         try {
             msg("Registering device info");
             OcPlatform.registerDeviceInfo(deviceInfo);
index 9ba4a72..0a3cd39 100755 (executable)
@@ -30,6 +30,7 @@ cp -LR ./extlibs/tinycbor $sourcedir/tmp/extlibs
 rm -rf $sourcedir/tmp/extlibs/tinycbor/tinycbor/.git
 
 cp -R ./extlibs/cjson $sourcedir/tmp/extlibs
+cp -R ./extlibs/gtest $sourcedir/tmp/extlibs
 cp -R ./extlibs/tinydtls $sourcedir/tmp/extlibs
 cp -R ./extlibs/sqlite3 $sourcedir/tmp/extlibs
 cp -R ./extlibs/timer $sourcedir/tmp/extlibs
index d77bc30..93f927f 100644 (file)
@@ -135,6 +135,16 @@ CAResult_t CAUtilCreateBond(JNIEnv *env, jobject device);
  * @param[in]  listener         callback listener
  */
 void CAUtilSetFoundDeviceListener(jobject listener);
+
+/**
+ * set interval time and working count for LE scan.
+ * @param[in]  intervalTime         interval time(Seconds).
+ * @param[in]  workingCount         working cycle for selected interval time.
+ *
+ * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
+ */
+CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount);
+
 #endif
 
 #ifdef __cplusplus
index 696ef01..40c6533 100644 (file)
@@ -77,10 +77,10 @@ static ca_mutex g_dtlsContextMutex = NULL;
 static CAGetDTLSPskCredentialsHandler g_getCredentialsCallback = NULL;
 
 /**
- * @var MAX_RETRANSMISSION_TIME
+ * @var RETRANSMISSION_TIME
  * @brief Maximum timeout value (in seconds) to start DTLS retransmission.
  */
-#define MAX_RETRANSMISSION_TIME 1
+#define RETRANSMISSION_TIME 1
 
 /**
  * @var g_dtlsHandshakeCallback
@@ -1019,10 +1019,6 @@ exit:
 static void CAStartRetransmit()
 {
     static int timerId = -1;
-    clock_time_t nextSchedule = MAX_RETRANSMISSION_TIME;
-
-    OIC_LOG(DEBUG, NET_DTLS_TAG, "CAStartRetransmit IN");
-
     if (timerId != -1)
     {
         //clear previous timer
@@ -1037,25 +1033,11 @@ static void CAStartRetransmit()
             ca_mutex_unlock(g_dtlsContextMutex);
             return;
         }
-
-        OIC_LOG(DEBUG, NET_DTLS_TAG, "Check retransmission");
-        dtls_check_retransmit(g_caDtlsContext->dtlsContext, &nextSchedule);
+        dtls_check_retransmit(g_caDtlsContext->dtlsContext, NULL);
         ca_mutex_unlock(g_dtlsContextMutex);
-
-        //re-transmission timeout should not be greater then max one
-        //this will cover case when several clients start dtls sessions
-        nextSchedule /= CLOCKS_PER_SEC;
-        if (nextSchedule > MAX_RETRANSMISSION_TIME)
-        {
-            nextSchedule = MAX_RETRANSMISSION_TIME;
-        }
     }
-
     //start new timer
-    OIC_LOG(DEBUG, NET_DTLS_TAG, "Start new timer");
-    registerTimer(nextSchedule, &timerId, CAStartRetransmit);
-
-    OIC_LOG(DEBUG, NET_DTLS_TAG, "CAStartRetransmit OUT");
+    registerTimer(RETRANSMISSION_TIME, &timerId, CAStartRetransmit);
 }
 
 CAResult_t CAAdapterNetDtlsInit()
index 6241998..199f884 100644 (file)
@@ -41,6 +41,8 @@
 
 #define MICROSECS_PER_SEC 1000000
 #define WAIT_TIME_WRITE_CHARACTERISTIC 10 * MICROSECS_PER_SEC
+#define WAIT_TIME_SCAN_INTERVAL_DEFAULT 10
+#define WAIT_TIME_SCANNED_CHECKING 30
 
 #define GATT_CONNECTION_PRIORITY_BALANCED   0
 #define GATT_FAILURE                        257
@@ -68,7 +70,6 @@ static jobjectArray g_uuidList = NULL;
 
 // it will be prevent to start send logic when adapter has stopped.
 static bool g_isStartedLEClient = false;
-static bool g_isStartedScan = false;
 
 static jbyteArray g_sendBuffer = NULL;
 static uint32_t g_targetCnt = 0;
@@ -94,9 +95,17 @@ static ca_mutex g_deviceStateListMutex = NULL;
 static ca_mutex g_deviceScanRetryDelayMutex = NULL;
 static ca_cond g_deviceScanRetryDelayCond = NULL;
 
-static ca_mutex g_scanMutex = NULL;
+static ca_mutex g_threadScanIntervalMutex = NULL;
+static ca_cond g_threadScanIntervalCond = NULL;
+
 static ca_mutex g_threadSendStateMutex = NULL;
 
+static int32_t g_scanIntervalTime = WAIT_TIME_SCAN_INTERVAL_DEFAULT;
+static int32_t g_scanIntervalTimePrev = WAIT_TIME_SCAN_INTERVAL_DEFAULT;
+static int32_t g_intervalCount = 0;
+static bool g_isWorkingScanThread = false;
+static CALEScanState_t g_scanningStep = BLE_SCAN_DISABLE;
+
 static CABLEDataReceivedCallback g_CABLEClientDataReceivedCallback = NULL;
 
 /**
@@ -125,6 +134,143 @@ static bool CALECheckConnectionStateValue(jint state)
     return false;
 }
 
+void CALEClientSetScanInterval(int32_t intervalTime, int32_t workingCount)
+{
+    OIC_LOG_V(DEBUG, TAG, "CALEClientSetScanInterval : %d -> %d",
+              g_scanIntervalTime, intervalTime);
+
+    // previous time should be stored.
+    if (0 < workingCount)
+    {
+        g_scanIntervalTimePrev = g_scanIntervalTime;
+    }
+    g_scanIntervalTime = intervalTime;
+    g_intervalCount = workingCount;
+}
+
+void CALERestartScanWithInterval(int32_t intervalTime, int32_t workingCount)
+{
+    // restart scan with interval
+    CALEClientSetScanInterval(intervalTime, workingCount);
+    ca_cond_signal(g_threadScanIntervalCond);
+}
+
+static void CALEScanThread(void* object)
+{
+    (void)object;
+
+    bool isAttached = false;
+    JNIEnv* env;
+    jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
+    if (JNI_OK != res)
+    {
+        OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
+        res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
+
+        if (JNI_OK != res)
+        {
+            OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
+            return;
+        }
+        isAttached = true;
+    }
+
+    ca_mutex_lock(g_threadScanIntervalMutex);
+    while(g_isWorkingScanThread)
+    {
+        OIC_LOG(DEBUG, TAG, "scan waiting time out");
+        if (BLE_SCAN_ENABLE == g_scanningStep)
+        {
+            //stop scan
+            CAResult_t ret = CALEClientStopScan();
+            if (CA_STATUS_OK != ret)
+            {
+                OIC_LOG(INFO, TAG, "CALEClientStopScan has failed");
+            }
+        }
+        else
+        {
+            //start scan
+            CAResult_t ret = CALEClientStartScan();
+            if (CA_STATUS_OK != ret)
+            {
+                OIC_LOG(INFO, TAG, "CALEClientStartScan has failed");
+            }
+        }
+
+        OIC_LOG_V(DEBUG, TAG, "wait for Scan Interval Time during %d sec", g_scanIntervalTime);
+        if (CA_WAIT_SUCCESS == ca_cond_wait_for(g_threadScanIntervalCond,
+                                                g_threadScanIntervalMutex,
+                                                g_scanIntervalTime * MICROSECS_PER_SEC))
+        {
+            // called signal scan thread will be terminated
+            OIC_LOG(DEBUG, TAG, "signal scanInterval waiting");
+            g_scanningStep = BLE_SCAN_DISABLE;
+        }
+        else
+        {
+           if (BLE_SCAN_ENABLE == g_scanningStep)
+           {
+               if (g_intervalCount > 0)
+               {
+                   if (g_intervalCount == 1)
+                   {
+                       OIC_LOG(DEBUG, TAG, "reset default time");
+                       CALEClientSetScanInterval(g_scanIntervalTimePrev, 0);
+                   }
+                   g_intervalCount--;
+                   OIC_LOG_V(DEBUG, TAG, "interval count : %d", g_intervalCount);
+               }
+               g_scanningStep = BLE_SCAN_DISABLE;
+           }
+           else
+           {
+               g_scanningStep = BLE_SCAN_ENABLE;
+           }
+        }
+    }
+    ca_mutex_unlock(g_threadScanIntervalMutex);
+
+    if (isAttached)
+    {
+        (*g_jvm)->DetachCurrentThread(g_jvm);
+    }
+}
+
+CAResult_t CALEClientStartScanWithInterval()
+{
+    OIC_LOG(DEBUG, TAG, "IN - CALEClientStartScanWithInterval");
+
+    if (g_isWorkingScanThread)
+    {
+        OIC_LOG(DEBUG, TAG, "scan interval logic already running");
+        return CA_STATUS_OK;
+    }
+
+    // initialize scan flags
+    g_scanningStep = BLE_SCAN_DISABLE;
+    g_isWorkingScanThread = true;
+    g_intervalCount = 0;
+    g_scanIntervalTime = g_scanIntervalTimePrev;
+
+    if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle,
+                                                CALEScanThread, NULL))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to create read thread!");
+        g_isWorkingScanThread = false;
+        return CA_STATUS_FAILED;
+    }
+
+    OIC_LOG(DEBUG, TAG, "OUT - CALEClientStartScanWithInterval");
+    return CA_STATUS_OK;
+}
+
+void CALEClientStopScanWithInterval()
+{
+    g_isWorkingScanThread = false;
+    ca_cond_signal(g_threadScanIntervalCond);
+}
+
 //getting jvm
 void CALEClientJniInit()
 {
@@ -284,6 +430,7 @@ CAResult_t CALEClientInitialize()
     g_threadCond = ca_cond_new();
     g_threadWriteCharacteristicCond = ca_cond_new();
     g_deviceScanRetryDelayCond = ca_cond_new();
+    g_threadScanIntervalCond =  ca_cond_new();
 
     CALEClientCreateDeviceList();
     CALEClientJNISetContext();
@@ -391,7 +538,6 @@ void CALEClientTerminate()
         OIC_LOG(ERROR, TAG, "CALEClientRemoveAllGattObjs has failed");
     }
 
-    CALEClientSetScanFlag(false);
     CALEClientSetSendFinishFlag(true);
 
     CALEClientTerminateGattMutexVariables();
@@ -401,14 +547,19 @@ void CALEClientTerminate()
     ca_cond_free(g_threadCond);
     ca_cond_free(g_threadWriteCharacteristicCond);
     ca_cond_free(g_deviceScanRetryDelayCond);
+    ca_cond_free(g_threadScanIntervalCond);
 
     g_deviceDescCond = NULL;
     g_threadCond = NULL;
     g_threadWriteCharacteristicCond = NULL;
     g_deviceScanRetryDelayCond = NULL;
+    g_threadScanIntervalCond = NULL;
 
     g_isSignalSetFlag = false;
 
+    // stop scanning
+    CALEClientStopScanWithInterval();
+
     if (isAttached)
     {
         (*g_jvm)->DetachCurrentThread(g_jvm);
@@ -609,6 +760,9 @@ CAResult_t CALEClientIsThereScannedDevices(JNIEnv *env, const char* address)
         static uint64_t const TIMEOUT =
             2 * MICROSECS_PER_SEC;  // Microseconds
 
+        // set scan interval and start scan
+        CALERestartScanWithInterval(WAIT_TIME_SCANNED_CHECKING, 1);
+
         bool devicesDiscovered = false;
         for (size_t i = 0; i < RETRIES; ++i)
         {
@@ -659,6 +813,9 @@ CAResult_t CALEClientIsThereScannedDevices(JNIEnv *env, const char* address)
             }
         }
 
+        // reset scan interval time after checking scanned devices
+        CALERestartScanWithInterval(g_scanIntervalTimePrev, 0);
+
         // time out for scanning devices
         if (!devicesDiscovered)
         {
@@ -671,7 +828,7 @@ CAResult_t CALEClientIsThereScannedDevices(JNIEnv *env, const char* address)
 
 
 CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t* data,
-                                      const uint32_t dataLen)
+                                            const uint32_t dataLen)
 {
     OIC_LOG_V(DEBUG, TAG, "CALEClientSendUnicastMessageImpl, address: %s, data: %p", address,
               data);
@@ -743,13 +900,8 @@ CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t*
                 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
                 (*env)->DeleteLocalRef(env, jni_setAddress);
 
-                // connect to gatt server
-                ret = CALEClientStopScan();
-                if (CA_STATUS_OK != ret)
-                {
-                    OIC_LOG(ERROR, TAG, "CALEClientStopScan has failed");
-                    goto error_exit;
-                }
+                // stop scan while sending
+                CALEClientStopScanWithInterval();
 
                 if (g_sendBuffer)
                 {
@@ -797,10 +949,10 @@ CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t*
     }
 
     // start LE Scan again
-    ret = CALEClientStartScan();
+    ret = CALEClientStartScanWithInterval();
     if (CA_STATUS_OK != ret)
     {
-        OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+        OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
         ca_mutex_unlock(g_threadSendMutex);
         return ret;
     }
@@ -831,10 +983,10 @@ CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t*
 error_exit:
 
     // start LE Scan again
-    ret = CALEClientStartScan();
+    ret = CALEClientStartScanWithInterval();
     if (CA_STATUS_OK != ret)
     {
-        OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+        OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
         ca_mutex_unlock(g_threadSendMutex);
         if (isAttached)
         {
@@ -883,14 +1035,9 @@ CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t* data,
         goto error_exit;
     }
 
-    // connect to gatt server
-    res = CALEClientStopScan();
-    if (CA_STATUS_OK != res)
-    {
-        OIC_LOG(ERROR, TAG, "CALEClientStopScan has failed");
-        ca_mutex_unlock(g_threadSendMutex);
-        return res;
-    }
+    // stop scan while sending
+    CALEClientStopScanWithInterval();
+
     uint32_t length = u_arraylist_length(g_deviceList);
     g_targetCnt = length;
 
@@ -927,10 +1074,10 @@ CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t* data,
     ca_mutex_unlock(g_threadMutex);
 
     // start LE Scan again
-    res = CALEClientStartScan();
+    res = CALEClientStartScanWithInterval();
     if (CA_STATUS_OK != res)
     {
-        OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+        OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
         ca_mutex_unlock(g_threadSendMutex);
         return res;
     }
@@ -940,10 +1087,10 @@ CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t* data,
     return CA_STATUS_OK;
 
 error_exit:
-    res = CALEClientStartScan();
+    res = CALEClientStartScanWithInterval();
     if (CA_STATUS_OK != res)
     {
-        OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+        OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
         ca_mutex_unlock(g_threadSendMutex);
         return res;
     }
@@ -1150,12 +1297,6 @@ CAResult_t CALEClientStartScan()
         return CA_STATUS_FAILED;
     }
 
-    if (g_isStartedScan)
-    {
-        OIC_LOG(INFO, TAG, "scanning is already started");
-        return CA_STATUS_OK;
-    }
-
     bool isAttached = false;
     JNIEnv* env;
     jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
@@ -1230,6 +1371,7 @@ CAResult_t CALEClientStartScanImpl(JNIEnv *env, jobject callback)
     if (!jni_mid_getDefaultAdapter)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return CA_STATUS_FAILED;
     }
 
@@ -1240,6 +1382,7 @@ CAResult_t CALEClientStartScanImpl(JNIEnv *env, jobject callback)
     if (!jni_mid_startLeScan)
     {
         OIC_LOG(ERROR, TAG, "startLeScan: jni_mid_startLeScan is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return CA_STATUS_FAILED;
     }
 
@@ -1249,6 +1392,7 @@ CAResult_t CALEClientStartScanImpl(JNIEnv *env, jobject callback)
     if (!jni_obj_BTAdapter)
     {
         OIC_LOG(ERROR, TAG, "getState From BTAdapter: jni_obj_BTAdapter is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return CA_STATUS_FAILED;
     }
 
@@ -1263,9 +1407,10 @@ CAResult_t CALEClientStartScanImpl(JNIEnv *env, jobject callback)
     else
     {
         OIC_LOG(DEBUG, TAG, "LeScan has started");
-        CALEClientSetScanFlag(true);
     }
 
+    (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+    (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
     return CA_STATUS_OK;
 }
 
@@ -1295,6 +1440,7 @@ CAResult_t CALEClientStartScanWithUUIDImpl(JNIEnv *env, jobjectArray uuids, jobj
     if (!jni_mid_getDefaultAdapter)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return CA_STATUS_FAILED;
     }
 
@@ -1305,6 +1451,7 @@ CAResult_t CALEClientStartScanWithUUIDImpl(JNIEnv *env, jobjectArray uuids, jobj
     if (!jni_mid_startLeScan)
     {
         OIC_LOG(ERROR, TAG, "startLeScan: jni_mid_startLeScan is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return CA_STATUS_FAILED;
     }
 
@@ -1314,6 +1461,7 @@ CAResult_t CALEClientStartScanWithUUIDImpl(JNIEnv *env, jobjectArray uuids, jobj
     if (!jni_obj_BTAdapter)
     {
         OIC_LOG(ERROR, TAG, "getState From BTAdapter: jni_obj_BTAdapter is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return CA_STATUS_FAILED;
     }
 
@@ -1328,9 +1476,10 @@ CAResult_t CALEClientStartScanWithUUIDImpl(JNIEnv *env, jobjectArray uuids, jobj
     else
     {
         OIC_LOG(DEBUG, TAG, "LeScan has started");
-        CALEClientSetScanFlag(true);
     }
 
+    (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+    (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
     return CA_STATUS_OK;
 }
 
@@ -1376,12 +1525,6 @@ CAResult_t CALEClientStopScan()
         return CA_STATUS_FAILED;
     }
 
-    if (!g_isStartedScan)
-    {
-        OIC_LOG(INFO, TAG, "scanning is already stopped");
-        return CA_STATUS_OK;
-    }
-
     bool isAttached = false;
     JNIEnv* env;
     jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
@@ -1409,10 +1552,6 @@ CAResult_t CALEClientStopScan()
             OIC_LOG(ERROR, TAG, "CALEClientStopScanImpl has failed");
         }
     }
-    else
-    {
-        CALEClientSetScanFlag(false);
-    }
 
     if (isAttached)
     {
@@ -1422,13 +1561,6 @@ CAResult_t CALEClientStopScan()
     return ret;
 }
 
-void CALEClientSetScanFlag(bool flag)
-{
-    ca_mutex_lock(g_scanMutex);
-    g_isStartedScan = flag;
-    ca_mutex_unlock(g_scanMutex);
-}
-
 CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback)
 {
     OIC_LOG(DEBUG, TAG, "CALEClientStopScanImpl");
@@ -1456,6 +1588,7 @@ CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback)
     if (!jni_mid_getDefaultAdapter)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return CA_STATUS_FAILED;
     }
 
@@ -1466,6 +1599,7 @@ CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback)
     if (!jni_mid_stopLeScan)
     {
         OIC_LOG(ERROR, TAG, "stopLeScan: jni_mid_stopLeScan is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return CA_STATUS_FAILED;
     }
 
@@ -1475,6 +1609,7 @@ CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback)
     if (!jni_obj_BTAdapter)
     {
         OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return CA_STATUS_FAILED;
     }
 
@@ -1484,11 +1619,15 @@ CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback)
     if ((*env)->ExceptionCheck(env))
     {
         OIC_LOG(ERROR, TAG, "stopLeScan has failed");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+        (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
         (*env)->ExceptionDescribe(env);
         (*env)->ExceptionClear(env);
         return CA_STATUS_FAILED;
     }
 
+    (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+    (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
     return CA_STATUS_OK;
 }
 
@@ -2637,12 +2776,7 @@ CAResult_t CALEClientAddScanDeviceToList(JNIEnv *env, jobject device)
     if (!g_deviceList)
     {
         OIC_LOG(ERROR, TAG, "gdevice_list is null");
-
-        CALEClientSetScanFlag(false);
-        if (CA_STATUS_OK != CALEClientStopScan())
-        {
-            OIC_LOG(ERROR, TAG, "CALEClientStopScan has failed");
-        }
+        CALEClientStopScanWithInterval();
 
         ca_mutex_unlock(g_deviceListMutex);
         return CA_STATUS_FAILED;
@@ -3742,16 +3876,6 @@ CAResult_t CALEClientInitGattMutexVaraibles()
         }
     }
 
-    if (NULL == g_scanMutex)
-    {
-        g_scanMutex = ca_mutex_new();
-        if (NULL == g_scanMutex)
-        {
-            OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
-            return CA_STATUS_FAILED;
-        }
-    }
-
     if (NULL == g_threadWriteCharacteristicMutex)
     {
         g_threadWriteCharacteristicMutex = ca_mutex_new();
@@ -3782,6 +3906,16 @@ CAResult_t CALEClientInitGattMutexVaraibles()
         }
     }
 
+    if (NULL == g_threadScanIntervalMutex)
+    {
+        g_threadScanIntervalMutex = ca_mutex_new();
+        if (NULL == g_threadScanIntervalMutex)
+        {
+            OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
     return CA_STATUS_OK;
 }
 
@@ -3805,9 +3939,6 @@ void CALEClientTerminateGattMutexVariables()
     ca_mutex_free(g_SendFinishMutex);
     g_SendFinishMutex = NULL;
 
-    ca_mutex_free(g_scanMutex);
-    g_scanMutex = NULL;
-
     ca_mutex_free(g_threadWriteCharacteristicMutex);
     g_threadWriteCharacteristicMutex = NULL;
 
@@ -3816,6 +3947,9 @@ void CALEClientTerminateGattMutexVariables()
 
     ca_mutex_free(g_threadSendStateMutex);
     g_threadSendStateMutex = NULL;
+
+    ca_mutex_free(g_threadScanIntervalMutex);
+    g_threadScanIntervalMutex = NULL;
 }
 
 void CALEClientSetSendFinishFlag(bool flag)
@@ -3849,10 +3983,10 @@ CAResult_t CAStartLEGattClient()
         g_threadWriteCharacteristicCond = ca_cond_new();
     }
 
-    CAResult_t ret = CALEClientStartScan();
+    CAResult_t ret = CALEClientStartScanWithInterval();
     if (CA_STATUS_OK != ret)
     {
-        OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+        OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
         return ret;
     }
 
@@ -3892,11 +4026,7 @@ void CAStopLEGattClient()
         OIC_LOG(ERROR, TAG, "CALEClientDisconnectAll has failed");
     }
 
-    ret = CALEClientStopScan();
-    if(CA_STATUS_OK != ret)
-    {
-        OIC_LOG(ERROR, TAG, "CALEClientStopScan has failed");
-    }
+    CALEClientStopScanWithInterval();
 
     ca_mutex_lock(g_threadMutex);
     OIC_LOG(DEBUG, TAG, "signal - connection cond");
@@ -3914,15 +4044,22 @@ void CAStopLEGattClient()
     ca_cond_signal(g_deviceScanRetryDelayCond);
     ca_mutex_unlock(g_deviceScanRetryDelayMutex);
 
+    ca_mutex_lock(g_threadScanIntervalMutex);
+    OIC_LOG(DEBUG, TAG, "signal - delay cond");
+    ca_cond_signal(g_threadScanIntervalCond);
+    ca_mutex_unlock(g_threadScanIntervalMutex);
+
     ca_cond_free(g_deviceDescCond);
     ca_cond_free(g_threadCond);
     ca_cond_free(g_threadWriteCharacteristicCond);
     ca_cond_free(g_deviceScanRetryDelayCond);
+    ca_cond_free(g_threadScanIntervalCond);
 
     g_deviceDescCond = NULL;
     g_threadCond = NULL;
     g_threadWriteCharacteristicCond = NULL;
     g_deviceScanRetryDelayCond = NULL;
+    g_threadScanIntervalCond = NULL;
 
     if (isAttached)
     {
index ee5ffc8..eb61cf4 100644 (file)
@@ -52,6 +52,15 @@ typedef struct le_state_info
 } CALEState_t;
 
 /**
+ * BLE Scanning State.
+ */
+typedef enum
+{
+    BLE_SCAN_ENABLE = 0, /**< BLE scan is working */
+    BLE_SCAN_DISABLE     /**< BLE scan is not working */
+} CALEScanState_t;
+
+/**
  * Callback to be notified on reception of any data from remote devices.
  * @param[in]  address                MAC address of remote device.
  * @param[in]  data                   Data received from remote device.
@@ -248,12 +257,6 @@ jobject CALEClientGetUUIDObject(JNIEnv *env, const char *uuid);
 CAResult_t CALEClientStopScan();
 
 /**
- * set ble scanning flag.
- * @param[in]   flag        scan flag.
- */
-void CALEClientSetScanFlag(bool flag);
-
-/**
  * stop scan (implement).
  * @param[in]   env                   JNI interface pointer.
  * @param[in]   callback              callback to receive device object by scanning.
@@ -603,6 +606,31 @@ jobject CALEClientGattConnect(JNIEnv *env, jobject bluetoothDevice, jboolean aut
  */
 CAResult_t CALEClientDirectConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect);
 
+/**
+ * set new interval time and working count.
+ * @param[in]  intervalTime             interval time(Seconds).
+ * @param[in]  workingCount             working count for selected interval time.
+ */
+void CALEClientSetScanInterval(int32_t intervalTime, int32_t workingCount);
+
+/**
+ * restart scanning with new interval time and working count.
+ * @param[in]  intervalTime             interval time(Seconds).
+ * @param[in]  workingCount             working count for selected interval time.
+ */
+void CALERestartScanWithInterval(int32_t intervalTime, int32_t workingCount);
+
+/**
+ * start LE scanning logic with interval time and working count.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientStartScanWithInterval();
+
+/**
+ * stop LE scanning logic with interval time and cycle.
+ */
+void CALEClientStopScanWithInterval();
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
index 04f21e8..2578f88 100644 (file)
@@ -343,8 +343,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caLeStateChangedCallback(JNIEnv *env, j
             OIC_LOG(ERROR, TAG, "CALEServerRemoveAllDevices has failed");
         }
 
-        CALEClientSetScanFlag(false);
-
         CANetworkStatus_t newStatus = CA_INTERFACE_DOWN;
         g_bleDeviceStateChangedCallback(newStatus);
     }
index b6ad36f..d863f9e 100644 (file)
@@ -295,6 +295,7 @@ jboolean CALEIsEnableBTAdapter(JNIEnv *env)
     if (!jni_mid_getDefaultAdapter)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return JNI_FALSE;
     }
 
@@ -303,6 +304,7 @@ jboolean CALEIsEnableBTAdapter(JNIEnv *env)
     if (!jni_obj_BTAdapter)
     {
         OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
         return JNI_FALSE;
     }
 
@@ -311,12 +313,16 @@ jboolean CALEIsEnableBTAdapter(JNIEnv *env)
     if (!jni_mid_isEnable)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_isEnable is null");
+        (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+        (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
         return JNI_FALSE;
     }
 
     jboolean jni_isEnable = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_isEnable);
     OIC_LOG_V(DEBUG, TAG, "adapter state is %d", jni_isEnable);
 
+    (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+    (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
     return jni_isEnable;
 }
 
index fa3cb81..c15b05c 100644 (file)
@@ -66,6 +66,14 @@ CAResult_t CAManagerLEClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context
  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
  */
 CAResult_t CAManagerLEClientTerminate(JNIEnv *env);
+
+/**
+ * set BLE scan interval time and working count.
+ * @param[in]  intervalTime         interval time(Seconds).
+ * @param[in]  workingCount         working count for selected interval time.
+ */
+void CAManagerLESetScanInterval(jint intervalTime, jint workingCount);
+
 #endif
 
 #ifdef __cplusplus
index fb5742b..12d4e0f 100644 (file)
@@ -280,6 +280,12 @@ CAResult_t CAManagerLEClientTerminate(JNIEnv *env)
     return res;
 }
 
+void CAManagerLESetScanInterval(jint interval, jint count)
+{
+    OIC_LOG(DEBUG, TAG, "CAManagerLESetScanInterval");
+    CALERestartScanWithInterval(interval, count);
+}
+
 JNIEXPORT void JNICALL
 Java_org_iotivity_ca_CaLeClientInterface_caManagerAdapterStateChangedCallback(
         JNIEnv *env, jobject obj, jint state)
index 35c21b7..cdf46d7 100644 (file)
@@ -53,7 +53,7 @@ static void CAManagerAdapterMonitorHandler(CATransportAdapter_t adapter,
 
 static void CAManagerConnectionMonitorHandler(const CAEndpoint_t *info, bool isConnected)
 {
-    if (!info || !info->addr)
+    if (!info || !info->addr[0])
     {
         OIC_LOG(ERROR, TAG, "remoteAddress is NULL");
         return;
@@ -301,4 +301,16 @@ void CAUtilSetFoundDeviceListener(jobject listener)
     (void)listener;
 #endif
 }
+
+CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount)
+{
+    OIC_LOG(DEBUG, TAG, "CAUtilSetLEScanInterval");
+#ifdef LE_ADAPTER
+    CAManagerLESetScanInterval(intervalTime, workingCount);
+    return CA_STATUS_OK;
+#else
+    OIC_LOG(DEBUG, TAG, "it is not supported");
+    return CA_NOT_SUPPORTED;
+#endif
+}
 #endif
index 61a51d3..92b054f 100644 (file)
@@ -142,7 +142,7 @@ static OCStackResult StartOwnershipTransfer(void* ctx, OCProvisionDev_t* selecte
  * @param[in]  otmCtx  Context value of ownership transfer.
  * @return  OC_STACK_OK on success
  */
-static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx);
+static OCStackResult PostOwnerTransferModeToResource(OTMContext_t* otmCtx);
 
 /**
  * Function to send request to resource to get its pstat resource information.
@@ -160,7 +160,7 @@ static OCStackResult GetProvisioningStatusResource(OTMContext_t* otmCtx);
  * @param[in]  otmCtx  Context value of ownership transfer.
  * @return  OC_STACK_OK on success
  */
-static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx);
+static OCStackResult PostOwnerUuid(OTMContext_t* otmCtx);
 
 /**
  * Function to update the operation mode. As per the spec. Operation mode in client driven
@@ -169,7 +169,7 @@ static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx);
  * @param[in]  otmCtx  Context value of ownership transfer.
  * @return  OC_STACK_OK on success
  */
-static OCStackResult PutUpdateOperationMode(OTMContext_t* otmCtx);
+static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx);
 
 /**
  * Function to update the owner credential to new device
@@ -187,7 +187,7 @@ static OCStackResult PutOwnerCredential(OTMContext_t* otmCtx);
  * @param[in]  otmCtx  Context value of ownership transfer.
  * @return  OC_STACK_OK on success
  */
-static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx);
+static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx);
 
 /**
  * Function to update pstat as Ready for provisioning.
@@ -197,7 +197,7 @@ static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx);
  * @param[in] selectedDevice   selected device information to performing provisioning.
  * @return  OC_STACK_OK on success
  */
-static OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx);
+static OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx);
 
 /**
  * Function to update pstat as Ready for Normal Operation.
@@ -207,7 +207,7 @@ static OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx);
  * @param[in] selectedDevice   selected device information to performing provisioning.
  * @return  OC_STACK_OK on success
  */
-static OCStackResult PutNormalOperationStatus(OTMContext_t* otmCtx);
+static OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx);
 
 static bool IsComplete(OTMContext_t* otmCtx)
 {
@@ -321,8 +321,8 @@ void DTLSHandshakeCB(const CAEndpoint_t *endpoint, const CAErrorInfo_t *info)
                    false == newDevDoxm->owned &&
                    memcmp(&(newDevDoxm->owner), &emptyUuid, sizeof(OicUuid_t)) == 0)
                 {
-                    //Send request : PUT /oic/sec/doxm [{... , "devowner":"PT's UUID"}]
-                    res = PutOwnerUuid(g_otmCtx);
+                    //Send request : POST /oic/sec/doxm [{... , "devowner":"PT's UUID"}]
+                    res = PostOwnerUuid(g_otmCtx);
                     if(OC_STACK_OK != res)
                     {
                         OIC_LOG(ERROR, TAG, "OperationModeUpdate : Failed to send owner information");
@@ -541,8 +541,8 @@ static OCStackApplicationResult ListMethodsHandler(void *ctx, OCDoHandle UNUSED,
         //Select operation mode (Currently supported SINGLE_SERVICE_CLIENT_DRIVEN only)
         SelectOperationMode(otmCtx->selectedDeviceInfo, &(otmCtx->selectedDeviceInfo->pstat->om));
 
-        //Send request : PUT /oic/sec/pstat [{"om":"bx11", .. }]
-        OCStackResult res = PutUpdateOperationMode(otmCtx);
+        //Send request : POST /oic/sec/pstat [{"om":"bx11", .. }]
+        OCStackResult res = PostUpdateOperationMode(otmCtx);
         if (OC_STACK_OK != res)
         {
             OIC_LOG(ERROR, TAG, "Error while updating operation mode.");
@@ -744,11 +744,11 @@ static OCStackApplicationResult OwnerCredentialHandler(void *ctx, OCDoHandle UNU
                 }
             }
 
-            //PUT /oic/sec/doxm [{ ..., "owned":"TRUE" }]
-            res = PutOwnershipInformation(otmCtx);
+            //POST /oic/sec/doxm [{ ..., "owned":"TRUE" }]
+            res = PostOwnershipInformation(otmCtx);
             if(OC_STACK_OK != res)
             {
-                OIC_LOG(ERROR, TAG, "Failed to put ownership information to new device");
+                OIC_LOG(ERROR, TAG, "Failed to post ownership information to new device");
                 SetResult(otmCtx, res);
                 return OC_STACK_DELETE_TRANSACTION;
             }
@@ -795,7 +795,7 @@ static OCStackApplicationResult OwnershipInformationHandler(void *ctx, OCDoHandl
             OIC_LOG(INFO, TAG, "Ownership transfer was successfully completed.");
             OIC_LOG(INFO, TAG, "Set Ready for provisioning state .");
 
-            res = PutProvisioningStatus(otmCtx);
+            res = PostProvisioningStatus(otmCtx);
             if(OC_STACK_OK != res)
             {
                 OIC_LOG(ERROR, TAG, "Failed to update pstat");
@@ -843,7 +843,7 @@ static OCStackApplicationResult ProvisioningStatusHandler(void *ctx, OCDoHandle
         {
             OIC_LOG(INFO, TAG, "Device state is in Ready for Provisionig.");
 
-            res = PutNormalOperationStatus(otmCtx);
+            res = PostNormalOperationStatus(otmCtx);
             if(OC_STACK_OK != res)
             {
                 OIC_LOG(ERROR, TAG, "Failed to update pstat");
@@ -999,9 +999,9 @@ static OCStackResult PutOwnerCredential(OTMContext_t* otmCtx)
     return OC_STACK_OK;
 }
 
-static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx)
+static OCStackResult PostOwnerTransferModeToResource(OTMContext_t* otmCtx)
 {
-    OIC_LOG(DEBUG, TAG, "IN PutOwnerTransferModeToResource");
+    OIC_LOG(DEBUG, TAG, "IN PostOwnerTransferModeToResource");
 
     if(!otmCtx || !otmCtx->selectedDeviceInfo)
     {
@@ -1018,7 +1018,7 @@ static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx)
                         deviceInfo->connType,
                         query, sizeof(query), OIC_RSRC_DOXM_URI))
     {
-        OIC_LOG(ERROR, TAG, "PutOwnerTransferModeToResource : Failed to generate query");
+        OIC_LOG(ERROR, TAG, "PostOwnerTransferModeToResource : Failed to generate query");
         return OC_STACK_ERROR;
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
@@ -1042,7 +1042,7 @@ static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx)
     cbData.cb = &OwnerTransferModeHandler;
     cbData.context = (void *)otmCtx;
     cbData.cd = NULL;
-    res = OCDoResource(NULL, OC_REST_PUT, query,
+    res = OCDoResource(NULL, OC_REST_POST, query,
                        &deviceInfo->endpoint, (OCPayload *)secPayload,
                        deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
     if (res != OC_STACK_OK)
@@ -1050,7 +1050,7 @@ static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx)
         OIC_LOG(ERROR, TAG, "OCStack resource error");
     }
 
-    OIC_LOG(DEBUG, TAG, "OUT PutOwnerTransferModeToResource");
+    OIC_LOG(DEBUG, TAG, "OUT PostOwnerTransferModeToResource");
 
     return res;
 }
@@ -1093,9 +1093,9 @@ static OCStackResult GetProvisioningStatusResource(OTMContext_t* otmCtx)
     return res;
 }
 
-static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx)
+static OCStackResult PostOwnerUuid(OTMContext_t* otmCtx)
 {
-    OIC_LOG(DEBUG, TAG, "IN PutOwnerUuid");
+    OIC_LOG(DEBUG, TAG, "IN PostOwnerUuid");
 
     if(!otmCtx || !otmCtx->selectedDeviceInfo)
     {
@@ -1110,12 +1110,12 @@ static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx)
                         deviceInfo->connType,
                         query, sizeof(query), OIC_RSRC_DOXM_URI))
     {
-        OIC_LOG(ERROR, TAG, "PutOwnershipInformation : Failed to generate query");
+        OIC_LOG(ERROR, TAG, "PostOwnerUuid : Failed to generate query");
         return OC_STACK_ERROR;
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-    //PUT PT's uuid to new device
+    //Post PT's uuid to new device
     OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
     if(!secPayload)
     {
@@ -1138,21 +1138,21 @@ static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx)
     cbData.context = (void *)otmCtx;
     cbData.cd = NULL;
 
-    res = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload *)secPayload,
+    res = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload *)secPayload,
             deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
     if (res != OC_STACK_OK)
     {
         OIC_LOG(ERROR, TAG, "OCStack resource error");
     }
 
-    OIC_LOG(DEBUG, TAG, "OUT PutOwnerUuid");
+    OIC_LOG(DEBUG, TAG, "OUT PostOwnerUuid");
 
     return res;
 }
 
-static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx)
+static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx)
 {
-    OIC_LOG(DEBUG, TAG, "IN PutOwnershipInformation");
+    OIC_LOG(DEBUG, TAG, "IN PostOwnershipInformation");
 
     if(!otmCtx || !otmCtx->selectedDeviceInfo)
     {
@@ -1167,7 +1167,7 @@ static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx)
                         deviceInfo->connType,
                         query, sizeof(query), OIC_RSRC_DOXM_URI))
     {
-        OIC_LOG(ERROR, TAG, "PutOwnershipInformation : Failed to generate query");
+        OIC_LOG(ERROR, TAG, "PostOwnershipInformation : Failed to generate query");
         return OC_STACK_ERROR;
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
@@ -1197,21 +1197,21 @@ static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx)
     cbData.context = (void *)otmCtx;
     cbData.cd = NULL;
 
-    res = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
+    res = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload*)secPayload,
                        deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
     if (res != OC_STACK_OK)
     {
         OIC_LOG(ERROR, TAG, "OCStack resource error");
     }
 
-    OIC_LOG(DEBUG, TAG, "OUT PutOwnershipInformation");
+    OIC_LOG(DEBUG, TAG, "OUT PostOwnershipInformation");
 
     return res;
 }
 
-static OCStackResult PutUpdateOperationMode(OTMContext_t* otmCtx)
+static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx)
 {
-    OIC_LOG(DEBUG, TAG, "IN PutUpdateOperationMode");
+    OIC_LOG(DEBUG, TAG, "IN PostUpdateOperationMode");
 
     if(!otmCtx || !otmCtx->selectedDeviceInfo)
     {
@@ -1225,7 +1225,7 @@ static OCStackResult PutUpdateOperationMode(OTMContext_t* otmCtx)
                         deviceInfo->connType,
                         query, sizeof(query), OIC_RSRC_PSTAT_URI))
     {
-        OIC_LOG(ERROR, TAG, "PutUpdateOperationMode : Failed to generate query");
+        OIC_LOG(ERROR, TAG, "PostUpdateOperationMode : Failed to generate query");
         return OC_STACK_ERROR;
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
@@ -1250,14 +1250,14 @@ static OCStackResult PutUpdateOperationMode(OTMContext_t* otmCtx)
     cbData.cb = &OperationModeUpdateHandler;
     cbData.context = (void *)otmCtx;
     cbData.cd = NULL;
-    res = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload *)secPayload,
+    res = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload *)secPayload,
                        deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
     if (res != OC_STACK_OK)
     {
         OIC_LOG(ERROR, TAG, "OCStack resource error");
     }
 
-    OIC_LOG(DEBUG, TAG, "OUT PutUpdateOperationMode");
+    OIC_LOG(DEBUG, TAG, "OUT PostUpdateOperationMode");
 
     return res;
 }
@@ -1280,8 +1280,8 @@ static OCStackResult StartOwnershipTransfer(void* ctx, OCProvisionDev_t* selecte
     }
     OIC_LOG_V(DEBUG, TAG, "Selected provisoning method = %d", selectedDevice->doxm->oxmSel);
 
-    //Send Req: PUT /oic/sec/doxm [{..."OxmSel" :g_OTMDatas[Index of Selected OxM].OXMString,...}]
-    res = PutOwnerTransferModeToResource(otmCtx);
+    //Send Req: POST /oic/sec/doxm [{..."OxmSel" :g_OTMDatas[Index of Selected OxM].OXMString,...}]
+    res = PostOwnerTransferModeToResource(otmCtx);
     if(OC_STACK_OK != res)
     {
         OIC_LOG(WARNING, TAG, "Failed to select the provisioning method");
@@ -1408,9 +1408,9 @@ error:
     return res;
 }
 
-OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx)
+OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
 {
-    OIC_LOG(INFO, TAG, "IN PutProvisioningStatus");
+    OIC_LOG(INFO, TAG, "IN PostProvisioningStatus");
 
     if(!otmCtx || !otmCtx->selectedDeviceInfo)
     {
@@ -1444,7 +1444,7 @@ OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx)
                         otmCtx->selectedDeviceInfo->connType,
                         query, sizeof(query), OIC_RSRC_PSTAT_URI))
     {
-        OIC_LOG(ERROR, TAG, "PutProvisioningStatus : Failed to generate query");
+        OIC_LOG(ERROR, TAG, "PostProvisioningStatus : Failed to generate query");
         return OC_STACK_ERROR;
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
@@ -1453,7 +1453,7 @@ OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx)
     cbData.cb = &ProvisioningStatusHandler;
     cbData.context = (void*)otmCtx;
     cbData.cd = NULL;
-    OCStackResult ret = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
+    OCStackResult ret = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload*)secPayload,
             otmCtx->selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
     OIC_LOG_V(INFO, TAG, "OCDoResource returned: %d",ret);
     if (ret != OC_STACK_OK)
@@ -1461,14 +1461,14 @@ OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx)
         OIC_LOG(ERROR, TAG, "OCStack resource error");
     }
 
-    OIC_LOG(INFO, TAG, "OUT PutProvisioningStatus");
+    OIC_LOG(INFO, TAG, "OUT PostProvisioningStatus");
 
     return ret;
 }
 
-OCStackResult PutNormalOperationStatus(OTMContext_t* otmCtx)
+OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx)
 {
-    OIC_LOG(INFO, TAG, "IN PutNormalOperationStatus");
+    OIC_LOG(INFO, TAG, "IN PostNormalOperationStatus");
 
     if(!otmCtx || !otmCtx->selectedDeviceInfo)
     {
@@ -1502,7 +1502,7 @@ OCStackResult PutNormalOperationStatus(OTMContext_t* otmCtx)
                         otmCtx->selectedDeviceInfo->connType,
                         query, sizeof(query), OIC_RSRC_PSTAT_URI))
     {
-        OIC_LOG(ERROR, TAG, "PutNormalOperationStatus : Failed to generate query");
+        OIC_LOG(ERROR, TAG, "PostNormalOperationStatus : Failed to generate query");
         return OC_STACK_ERROR;
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
@@ -1511,7 +1511,7 @@ OCStackResult PutNormalOperationStatus(OTMContext_t* otmCtx)
     cbData.cb = &ReadyForNomalStatusHandler;
     cbData.context = (void*)otmCtx;
     cbData.cd = NULL;
-    OCStackResult ret = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
+    OCStackResult ret = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload*)secPayload,
             otmCtx->selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
     OIC_LOG_V(INFO, TAG, "OCDoResource returned: %d",ret);
     if (ret != OC_STACK_OK)
@@ -1519,7 +1519,7 @@ OCStackResult PutNormalOperationStatus(OTMContext_t* otmCtx)
         OIC_LOG(ERROR, TAG, "OCStack resource error");
     }
 
-    OIC_LOG(INFO, TAG, "OUT PutNormalOperationStatus");
+    OIC_LOG(INFO, TAG, "OUT PostNormalOperationStatus");
 
     return ret;
 }
index edd212a..8d57082 100644 (file)
@@ -45,6 +45,7 @@
 #define TAG  "SRM-ACL"
 #define NUMBER_OF_SEC_PROV_RSCS 4
 #define NUMBER_OF_DEFAULT_SEC_RSCS 2
+#define STRING_UUID_SIZE (UUID_LENGTH * 2 + 5)
 
 static const uint8_t ACL_MAP_SIZE = 2;
 static const uint8_t ACL_ACLIST_MAP_SIZE = 1;
@@ -833,8 +834,11 @@ static bool GetSubjectFromQueryString(const char *query, OicUuid_t *subject)
     {
         if (strncasecmp((char *) parseIter.attrPos, OIC_JSON_SUBJECTID_NAME, parseIter.attrLen) == 0)
         {
+            char strUuid[STRING_UUID_SIZE] = {0};
             VERIFY_SUCCESS(TAG, 0 != parseIter.valLen, ERROR);
-            memcpy(subject->id, parseIter.valPos, parseIter.valLen);
+            memcpy(strUuid, parseIter.valPos, parseIter.valLen);
+            OCStackResult res = ConvertStrToUuid(strUuid, subject);
+            VERIFY_SUCCESS(TAG, OC_STACK_OK == res, ERROR);
             return true;
         }
     }
index 19c1244..6cfbc4b 100644 (file)
@@ -579,9 +579,9 @@ static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest
     return ehRet;
 }
 
-static OCEntityHandlerResult HandleDoxmPutRequest(const OCEntityHandlerRequest * ehRequest)
+static OCEntityHandlerResult HandleDoxmPostRequest(const OCEntityHandlerRequest * ehRequest)
 {
-    OIC_LOG (DEBUG, TAG, "Doxm EntityHandle  processing PUT request");
+    OIC_LOG (DEBUG, TAG, "Doxm EntityHandle  processing POST request");
     OCEntityHandlerResult ehRet = OC_EH_ERROR;
     OicUuid_t emptyOwner = {.id = {0} };
 
@@ -845,8 +845,8 @@ OCEntityHandlerResult DoxmEntityHandler(OCEntityHandlerFlag flag,
                 ehRet = HandleDoxmGetRequest(ehRequest);
                 break;
 
-            case OC_REST_PUT:
-                ehRet = HandleDoxmPutRequest(ehRequest);
+            case OC_REST_POST:
+                ehRet = HandleDoxmPostRequest(ehRequest);
                 break;
 
             default:
index b3e63ac..75793c2 100644 (file)
@@ -350,10 +350,10 @@ static OCEntityHandlerResult HandlePstatGetRequest (const OCEntityHandlerRequest
  * resource or create a new resource.
  * For pstat, it updates only tm and om.
  */
-static OCEntityHandlerResult HandlePstatPutRequest(const OCEntityHandlerRequest *ehRequest)
+static OCEntityHandlerResult HandlePstatPostRequest(const OCEntityHandlerRequest *ehRequest)
 {
     OCEntityHandlerResult ehRet = OC_EH_ERROR;
-    OIC_LOG(INFO, TAG, "HandlePstatPutRequest  processing PUT request");
+    OIC_LOG(INFO, TAG, "HandlePstatPostRequest  processing POST request");
     OicSecPstat_t *pstat = NULL;
 
     if (ehRequest->payload)
@@ -441,8 +441,8 @@ static OCEntityHandlerResult HandlePstatPutRequest(const OCEntityHandlerRequest
             case OC_REST_GET:
                 ehRet = HandlePstatGetRequest(ehRequest);
                 break;
-            case OC_REST_PUT:
-                ehRet = HandlePstatPutRequest(ehRequest);
+            case OC_REST_POST:
+                ehRet = HandlePstatPostRequest(ehRequest);
                 break;
             default:
                 ehRet = OC_EH_ERROR;
index a2e10af..eefeaf8 100644 (file)
@@ -81,7 +81,7 @@ TEST(ACLResourceTest, CBORDefaultACLConversion)
     ASSERT_TRUE(convertedAcl != NULL);
 
     EXPECT_EQ(defaultAcl->resourcesLen, convertedAcl->resourcesLen);
-    for(int i = 0; i < convertedAcl->resourcesLen; i++)
+    for(size_t i = 0; i < convertedAcl->resourcesLen; i++)
     {
         EXPECT_EQ(0, strcmp(defaultAcl->resources[i], convertedAcl->resources[i]));
     }
@@ -366,7 +366,7 @@ TEST(ACLResourceTest, ACLDeleteWithSingleResourceTest)
 
     // Create Entity Handler DELETE request
     ehReq.method = OC_REST_DELETE;
-    char query[] = "subjectuuid=2222222222222222;resources=/a/led";
+    char query[] = "subjectuuid=32323232-3232-3232-3232-323232323232;resources=/a/led";
     ehReq.query = (char *)OICMalloc(strlen(query)+1);
     ASSERT_TRUE(NULL !=  ehReq.query);
     OICStrcpy(ehReq.query, strlen(query)+1, query);
@@ -417,7 +417,7 @@ TEST(ACLResourceTest, ACLDeleteWithMultiResourceTest)
 
     // Create Entity Handler DELETE request
     ehReq.method = OC_REST_DELETE;
-    char query[] = "subjectuuid=2222222222222222;resources=/a/led";
+    char query[] = "subjectuuid=32323232-3232-3232-3232-323232323232;resources=/a/led";
     ehReq.query = (char *)OICMalloc(strlen(query)+1);
     ASSERT_TRUE(NULL != ehReq.query);
     OICStrcpy(ehReq.query, strlen(query)+1, query);
@@ -465,7 +465,7 @@ TEST(ACLResourceTest, ACLGetWithQueryTest)
 
     //Create Entity Handler GET request wit query
     ehReq.method = OC_REST_GET;
-    char query[] = "subjectuuid=2222222222222222;resources=/a/led";
+    char query[] = "subjectuuid=32323232-3232-3232-3232-323232323232;resources=/a/led";
     ehReq.query = (char*)OICMalloc(strlen(query)+1);
     ASSERT_TRUE(NULL != ehReq.query);
     OICStrcpy(ehReq.query, strlen(query)+1, query);
index 073a965..3509298 100644 (file)
@@ -1252,7 +1252,7 @@ typedef struct
     OCPayload base;
     char* uri;
     OCPlatformInfo info;
-    char* rt;
+    OCStringLL* rt;
     OCStringLL* interfaces;
 } OCPlatformPayload;
 
index 12e6e3a..931e5f3 100644 (file)
@@ -271,7 +271,10 @@ INLINE_API void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
     if (payload->rt)
     {
         OIC_LOG(level, PL_TAG, "\tResource Types:");
-        OIC_LOG_V(level, PL_TAG, "\t\t%s", payload->rt);
+        for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
+        {
+            OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+        }
     }
     if (payload->interfaces)
     {
index 54182c9..8bb13b0 100644 (file)
@@ -188,6 +188,12 @@ static void OCCopyPropertyValue (OCRepPayloadValue *dest, OCRepPayloadValue *sou
         case OCREP_PROP_STRING:
             dest->str = OICStrdup(source->str);
             break;
+        case OCREP_PROP_BYTE_STRING:
+            dest->ocByteStr.bytes = (uint8_t*)OICMalloc(source->ocByteStr.len * sizeof(uint8_t));
+            VERIFY_PARAM_NON_NULL(TAG, dest->ocByteStr.bytes, "Failed allocating memory");
+            dest->ocByteStr.len = source->ocByteStr.len;
+            memcpy(dest->ocByteStr.bytes, source->ocByteStr.bytes, dest->ocByteStr.len);
+            break;
         case OCREP_PROP_OBJECT:
             dest->obj = OCRepPayloadClone(source->obj);
             break;
@@ -198,6 +204,8 @@ static void OCCopyPropertyValue (OCRepPayloadValue *dest, OCRepPayloadValue *sou
             // Nothing to do for the trivially copyable types.
             break;
     }
+exit:
+    return;
 }
 
 static void OCFreeRepPayloadValueContents(OCRepPayloadValue* val)
@@ -1386,8 +1394,7 @@ OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, si
     return NULL;
 }
 
-static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort,
-                                         uint16_t tcpPort)
+static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort)
 {
     OCResourcePayload* pl = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
     if (!pl)
@@ -1492,7 +1499,8 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
                                    uint16_t securePort, uint16_t tcpPort)
 {
-    OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, securePort, tcpPort));
+    OC_UNUSED(tcpPort);
+    OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, securePort));
 }
 
 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, const char *value)
@@ -1681,7 +1689,12 @@ OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo)
         return NULL;
     }
     payload->interfaces->value = OICStrdup(OC_RSRVD_INTERFACE_READ);
-    payload->rt = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
+    payload->rt = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
+    if (!payload->rt)
+    {
+        return NULL;
+    }
+    payload->rt->value = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
     payload->info = *platformInfo;
 
     return payload;
@@ -1697,7 +1710,7 @@ OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo)
     }
 
     payload->base.type = PAYLOAD_TYPE_PLATFORM;
-    payload->rt = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
+    OCResourcePayloadAddStringLL(&payload->rt, OC_RSRVD_RESOURCE_TYPE_PLATFORM);
 
     OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_DEFAULT);
     OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_READ);
@@ -1730,7 +1743,7 @@ void OCPlatformPayloadDestroy(OCPlatformPayload* payload)
     }
     OICFree(payload->uri);
     OCPlatformInfoDestroy(&payload->info);
-    OICFree(payload->rt);
+    OCFreeOCStringLL(payload->rt);
     OCFreeOCStringLL(payload->interfaces);
     OICFree(payload);
 }
index 477b9d7..d980cec 100644 (file)
@@ -514,8 +514,7 @@ static int64_t OCConvertPlatformPayload(OCPlatformPayload *payload, uint8_t *out
     // Resource type
     if (payload->rt)
     {
-        err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_RESOURCE_TYPE,
-                sizeof(OC_RSRVD_RESOURCE_TYPE) - 1, payload->rt);
+        err |= OCStringLLJoin(&repMap, OC_RSRVD_RESOURCE_TYPE, payload->rt);
         VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding resource type.");
     }
 
index 96f590c..dfd1ec7 100755 (executable)
@@ -470,7 +470,7 @@ static OCStackResult OCParsePlatformPayload(OCPayload **outPayload, CborValue *r
     OCStackResult ret = OC_STACK_INVALID_PARAM;
     CborError err = CborNoError;
     OCPlatformInfo info = {0};
-    char* rt = NULL;
+    OCStringLL* rt = NULL;
     OCStringLL* interfaces = NULL;
     OCPlatformPayload* out = NULL;
 
@@ -577,7 +577,7 @@ static OCStackResult OCParsePlatformPayload(OCPayload **outPayload, CborValue *r
 
         if(cbor_value_is_valid(&repVal))
         {
-            err = cbor_value_dup_text_string(&repVal, &rt, &len, NULL);
+            err = OCParseStringLL(rootValue, OC_RSRVD_RESOURCE_TYPE, &rt);
             VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find resource type in the platform payload");
         }
 
index 5bb4c16..9854e0a 100644 (file)
@@ -21,6 +21,7 @@
 
 extern "C"
 {
+    #include "ocpayload.h"
     #include "ocstack.h"
     #include "ocstackinternal.h"
     #include "logger.h"
@@ -1758,3 +1759,29 @@ TEST(StackResource, MultipleResourcesDiscovery)
 
     EXPECT_EQ(OC_STACK_OK, OCStop());
 }
+
+TEST(StackPayload, CloneByteString)
+{
+    uint8_t bytes[] = { 0, 1, 2, 3 };
+    OCByteString byteString;
+    byteString.bytes = bytes;
+    byteString.len = sizeof(bytes);
+
+    OCRepPayload *original = OCRepPayloadCreate();
+    ASSERT_TRUE(original != NULL);
+    EXPECT_TRUE(OCRepPayloadSetPropByteString(original, "name", byteString));
+
+    OCRepPayload *clone = OCRepPayloadClone(original);
+    ASSERT_TRUE(clone != NULL);
+
+    OCRepPayloadDestroy(original);
+
+    OCByteString cloneByteString;
+    EXPECT_TRUE(OCRepPayloadGetPropByteString(clone, "name", &cloneByteString));
+    ASSERT_TRUE(cloneByteString.bytes != NULL);
+    EXPECT_EQ(sizeof(bytes), cloneByteString.len);
+    EXPECT_TRUE(0 == memcmp(bytes, cloneByteString.bytes, sizeof(bytes)));
+    OICFree(cloneByteString.bytes);
+
+    OCRepPayloadDestroy(clone);
+}
index a7df3a0..65760e7 100644 (file)
@@ -178,6 +178,10 @@ namespace OC
                 m_values[str] = std::forward<T>(val);
             }
 
+            const std::map<std::string, AttributeValue>& getValues() const {
+                return m_values;
+            }
+
             /**
              *  Retrieve the attribute value associated with the supplied name
              *
index 09d1e16..7cefa7c 100644 (file)
@@ -134,9 +134,9 @@ namespace OC
             std::string(payload->info.systemTime) :
             std::string();
 
-        if (payload->rt)
+        for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
         {
-            rep.addResourceType(payload->rt);
+            rep.addResourceType(strll->value);
         }
         for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
         {
index 8c827c1..6e41e8f 100644 (file)
@@ -137,7 +137,7 @@ namespace OCRepresentationEncodingTest
         EXPECT_STREQ(time1, platform->info.systemTime);
         EXPECT_STREQ(OC_RSRVD_INTERFACE_DEFAULT, platform->interfaces->value);
         EXPECT_STREQ(OC_RSRVD_INTERFACE_READ, platform->interfaces->next->value);
-        EXPECT_STREQ(OC_RSRVD_RESOURCE_TYPE_PLATFORM, platform->rt);
+        EXPECT_STREQ(OC_RSRVD_RESOURCE_TYPE_PLATFORM, platform->rt->value);
 
         uint8_t* cborData;
         size_t cborSize;
@@ -161,7 +161,7 @@ namespace OCRepresentationEncodingTest
         EXPECT_STREQ(platform->info.supportUrl, platform->info.supportUrl);
         EXPECT_STREQ(platform->info.systemTime, platform2->info.systemTime);
         EXPECT_STREQ(platform->interfaces->value, platform2->interfaces->value);
-        EXPECT_STREQ(platform->rt, platform2->rt);
+        EXPECT_STREQ(platform->rt->value, platform2->rt->value);
 
         OCPayloadDestroy((OCPayload*)platform);