provide setConfigure API related BT including EDR, BLE by cautil.
authorjihwan seo <jihwan.seo@samsung.com>
Tue, 17 Jan 2017 07:19:34 +0000 (16:19 +0900)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Tue, 31 Jan 2017 02:42:46 +0000 (02:42 +0000)
It can be set Adv Flag that check whether start Adv
in initialize step or not.
and It will resolve battery consumption issue.

Change-Id: I09791c1d8ca71373c36309150dbc97c5031a8bc2
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16491
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
12 files changed:
java/iotivity-android/src/main/java/org/iotivity/ca/CaInterface.java
java/jni/JniCaInterface.c
resource/csdk/connectivity/api/cacommon.h
resource/csdk/connectivity/api/cautilinterface.h
resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.c
resource/csdk/connectivity/util/inc/camanagerleinterface.h
resource/csdk/connectivity/util/src/camanager/bt_le_manager/android/caleconnectionmanager.c
resource/csdk/connectivity/util/src/cautilinterface.c
resource/csdk/include/octypes.h
resource/csdk/stack/src/ocstack.c
resource/include/CAManager.h
resource/src/CAManager.cpp

index f8f0661..5a88476 100644 (file)
@@ -255,6 +255,14 @@ public class CaInterface {
     }
     private static native void stopLeAdvertisingImpl();
 
+    /**
+     *  set BT configure
+     */
+    public synchronized static void setBTConfigure(int flag){
+        CaInterface.setBTConfigureImpl(flag);
+    }
+    private static native void setBTConfigureImpl(int flag);
+
     public synchronized static int setCipherSuite(OicCipher cipher, OcConnectivityType connType){
         return CaInterface.setCipherSuiteImpl(cipher.getValue(), connType.getValue());
     }
index d7ed9b2..a2ce4a0 100644 (file)
@@ -429,6 +429,16 @@ Java_org_iotivity_ca_CaInterface_stopLeAdvertisingImpl(JNIEnv *env, jclass clazz
     CAUtilStopLEAdvertising();
 }
 
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaInterface_setBTConfigureImpl(JNIEnv *env, jclass clazz, jint flag)
+{
+    LOGI("setConfigureImpl");
+    (void)env;
+    (void)clazz;
+    CAUtilConfig_t configs = {(CATransportBTFlags_t)flag};
+    CAUtilSetBTConfigure(configs);
+}
+
 JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl
   (JNIEnv *env, jclass clazz, jint cipherSuite, jint adapter)
 {
index 949c9fd..f971ec7 100755 (executable)
@@ -214,6 +214,16 @@ typedef enum
     CA_SCOPE_GLOBAL    = 0xE, // IPv6 Global scope
 } CATransportFlags_t;
 
+typedef enum
+{
+    CA_DEFAULT_BT_FLAGS = 0,
+    // flags for BLE transport
+    CA_LE_ADV_DISABLE   = 0x1,   // disable BLE advertisement
+    CA_LE_ADV_ENABLE    = 0x2,   // enable BLE advertisement
+    // flags for EDR transport
+    CA_EDR_SERVER_DISABLE = (1 << 7)
+} CATransportBTFlags_t;
+
 #define CA_IPFAMILY_MASK (CA_IPV6|CA_IPV4)
 #define CA_SCOPE_MASK 0xf     // mask scope bits above
 
@@ -619,6 +629,7 @@ typedef struct
         bool ipv6tcpenabled;    /**< IPv6 TCP enabled by OCInit flags */
     } tcp;
 #endif
+    CATransportBTFlags_t bleFlags;   /**< flags related BLE transport */
 } CAGlobals_t;
 
 extern CAGlobals_t caglobals;
index 094fdd6..c29d486 100644 (file)
@@ -52,6 +52,15 @@ typedef struct
     CMSpeedLevel_t level;
 } CMConfigureInfo_t;
 
+/*
+ * CAUtilConfig_t structure.
+ */
+typedef struct
+{
+    CATransportBTFlags_t bleFlags;
+    CMConfigureInfo_t cmInfo;
+} CAUtilConfig_t;
+
 /**
  * Callback function type for connection status changes delivery.
  * @param[out]   info           Remote endpoint information.
@@ -209,6 +218,12 @@ CAResult_t CAUtilStartLEAdvertising();
  */
 CAResult_t CAUtilStopLEAdvertising();
 
+/**
+ * set CAUtil BT configure.
+ * @param[in]  config       ::CAUtilConfig_t value
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CAUtilSetBTConfigure(CAUtilConfig_t config);
 #ifdef __cplusplus
 } /* extern "C" */
 #endif //__cplusplus
index ed0ac42..8350f4a 100644 (file)
@@ -413,6 +413,13 @@ CAResult_t CALEServerSendResponse(JNIEnv *env, jobject device, jint requestId, j
 
 CAResult_t CALEServerStartAdvertise()
 {
+    if ((caglobals.bleFlags & CA_LE_ADV_DISABLE) || CA_DEFAULT_BT_FLAGS == caglobals.bleFlags)
+    {
+        OIC_LOG_V(INFO, TAG, "the advertisement of the bleFlags is disable[%d]",
+                  caglobals.bleFlags);
+        return CA_STATUS_OK;
+    }
+
     if (!g_jvm)
     {
         OIC_LOG(ERROR, TAG, "g_jvm is null");
@@ -1798,7 +1805,7 @@ CAResult_t CALEServerStartMulticastServer()
     }
 
     // start advertise
-    ret = CALEServerStartAdvertise(env, g_leAdvertiseCallback);
+    ret = CALEServerStartAdvertise();
     if (CA_STATUS_OK != ret)
     {
         OIC_LOG(ERROR, TAG, "CALEServerStartAdvertise has failed");
index 95f4916..bfe29b5 100644 (file)
@@ -92,6 +92,12 @@ CAResult_t CAManagerLEStartAdvertising();
  */
 CAResult_t CAManagerLEStopAdvertising();
 
+/**
+ * set CAUtilConfig_t configure.
+ * @param[in]  config       ::CAUtilConfig_t value
+ */
+void CAManagerSetConfigure(CAUtilConfig_t config);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
index edefd64..2c02fce 100644 (file)
@@ -292,6 +292,12 @@ void CAManagerLEStopScan()
     CALERestartScanWithInterval(0, 0, BLE_SCAN_DISABLE);
 }
 
+void CAManagerSetConfigure(CAUtilConfig_t config)
+{
+    OIC_LOG_V(INFO, TAG, "set configure for bleFlags : %d", config.bleFlags);
+    caglobals.bleFlags = config.bleFlags;
+}
+
 CAResult_t CAManagerLEStartAdvertising()
 {
     CAResult_t ret = CALEServerStartAdvertise();
index f570bcb..57e8261 100644 (file)
@@ -335,3 +335,17 @@ CAResult_t CAUtilStopLEAdvertising()
     return CA_NOT_SUPPORTED;
 #endif
 }
+
+CAResult_t CAUtilSetBTConfigure(CAUtilConfig_t config)
+{
+    OIC_LOG_V(DEBUG, TAG, "CAUtilSetConfigure");
+    OIC_LOG_V(DEBUG, TAG, "bleFlag [%d]", config.bleFlags);
+#if (defined(__ANDROID__) && defined(LE_ADAPTER))
+    CAManagerSetConfigure(config);
+    return CA_STATUS_OK;
+#else
+    (void) config;
+    OIC_LOG(DEBUG, TAG, "it is not supported");
+    return CA_NOT_SUPPORTED;
+#endif
+}
index 5155fa5..8adb2ac 100755 (executable)
@@ -671,6 +671,16 @@ typedef enum
     OC_ADAPTER_NFC           = (1 << 5)
 } OCTransportAdapter;
 
+typedef enum
+{
+    OC_DEFAULT_BT_FLAGS = 0,
+    // flags for BLE transport
+    OC_LE_ADV_DISABLE   = 0x1,   // disable BLE advertisement
+    OC_LE_ADV_ENABLE    = 0x2,   // enable BLE advertisement
+    // flags for EDR transport
+    OC_EDR_SERVER_DISABLE = (1 << 7)
+} OCTransportBTFlags_t;
+
 /**
  *  Enum layout assumes some targets have 16-bit integer (e.g., Arduino).
  */
@@ -1821,7 +1831,6 @@ typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
  */
 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
 //#endif // DIRECT_PAIRING
-
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
 /**
  * Callback function definition for Change in TrustCertChain
index 355584a..08ca676 100644 (file)
@@ -2394,6 +2394,10 @@ OCStackResult OCStop()
         return OC_STACK_ERROR;
     }
 
+    // unset cautil config
+    CAUtilConfig_t configs = {(CATransportBTFlags_t)CA_DEFAULT_BT_FLAGS};
+    CAUtilSetBTConfigure(configs);
+
     stackState = OC_STACK_UNINIT_IN_PROGRESS;
 
 #ifdef WITH_PRESENCE
index e227b16..ba758c0 100644 (file)
@@ -32,6 +32,23 @@ namespace OC
     */
     namespace CAManager
     {
+        /**
+         *  Data structure to provide the configuration for cautil.
+         */
+        struct CAUtilConfig
+        {
+            /** the flag for ble advertising. */
+            OCTransportBTFlags_t       bleFlag;
+
+            public:
+                CAUtilConfig()
+                    : bleFlag(OC_DEFAULT_BT_FLAGS)
+            {}
+                CAUtilConfig(OCTransportBTFlags_t bleFlag_)
+                    : bleFlag(bleFlag_)
+            {}
+        };
+
         // typedef to get adapter status changes from CA.
         typedef std::function<void(const std::string&, OCConnectivityType,
                                    bool)> ConnectionChangedCallback;
@@ -76,16 +93,23 @@ namespace OC
 
         /**
          * start BLE advertising.
-        * @return Returns ::OC_STACK_OK if success.
+         * @return Returns ::OC_STACK_OK if success.
          */
         OCStackResult startLEAdvertising();
 
         /**
          * stop BLE advertising.
-        * @return Returns ::OC_STACK_OK if success.
+         * @return Returns ::OC_STACK_OK if success.
          */
         OCStackResult stopLEAdvertising();
 
+        /**
+         * set BT configure.
+         * @param[in]  config       ::CAUtilConfig data
+         * @return Returns ::OC_STACK_OK if success.
+         */
+        OCStackResult setBTConfigure(const CAUtilConfig& config);
+
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
         /**
          * Select the cipher suite for TLS/DTLS handshake.
index 47cc11c..380b3d7 100644 (file)
@@ -29,6 +29,9 @@
 #include "CAManager.h"
 #include "cautilinterface.h"
 #include "casecurityinterface.h"
+#include "logger.h"
+
+#define TAG "OIC_CAMANAGER"
 
 using namespace OC;
 
@@ -127,6 +130,15 @@ uint16_t CAManager::getAssignedPortNumber(OCTransportAdapter adapter, OCTranspor
 {
     return CAGetAssignedPortNumber((CATransportAdapter_t) adapter, (CATransportFlags_t) flag);
 }
+
+OCStackResult CAManager::setBTConfigure(const CAUtilConfig& config)
+{
+    OIC_LOG(INFO, TAG, "setBTConfigure");
+    CAUtilConfig_t configs = {(CATransportBTFlags_t)config.bleFlag};
+    CAResult_t ret = CAUtilSetBTConfigure(configs);
+    return convertCAResultToOCResult(ret);
+}
+
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
 OCStackResult CAManager::setCipherSuite(const uint16_t cipher, OCTransportAdapter adapter)
 {