CA Android Sample application Changes
authorjnashok <jn.ashok@samsung.com>
Thu, 7 May 2015 04:50:29 +0000 (13:50 +0900)
committerErich Keane <erich.keane@intel.com>
Fri, 8 May 2015 16:01:16 +0000 (16:01 +0000)
This has the latest CA Android Sample application changes
Currently only WiFi is suppported
Signed-off-by: jnashok <jn.ashok@samsung.com>
Change-Id: I14872da31e501de310721bfdcdd315f681e1ff88
Reviewed-on: https://gerrit.iotivity.org/gerrit/755
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
12 files changed:
build_common/android/SConscript
resource/csdk/connectivity/SConstruct
resource/csdk/connectivity/build/android/SConscript
resource/csdk/connectivity/build/android/jni/Android.mk
resource/csdk/connectivity/inc/caadapterutils.h
resource/csdk/connectivity/samples/android/SConscript [new file with mode: 0644]
resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c
resource/csdk/connectivity/samples/android/sample_service/res/layout/activity_main.xml
resource/csdk/connectivity/samples/android/sample_service/res/values/strings.xml
resource/csdk/connectivity/samples/android/sample_service/src/org/iotivity/service/MainActivity.java
resource/csdk/connectivity/samples/android/sample_service/src/org/iotivity/service/RMInterface.java
resource/csdk/connectivity/src/adapter_util/caadapterutils.c

index f74f660..7dfac8c 100644 (file)
@@ -181,6 +181,7 @@ env.AppendUnique(CCFLAGS = ['-Wall', '-fPIC'])
 #env.AppendUnique(LINKFLAGS = ['-ldl', '-lpthread'])
 
 env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+src_dir = env.get('SRC_DIR')
 env.AppendUnique(LIBPATH = [src_dir + '/resource/csdk/connectivity/lib/android'])
 env.AppendUnique(LIBS = ['log', 'coap'])
 
index 6529011..58d0fd9 100644 (file)
@@ -57,3 +57,6 @@ elif target_os == 'android':
 
        # Build 'src' sub-project
        SConscript(build_dir + 'SConscript')
+
+       # Build 'samples' sub-project
+       env.SConscript(build_dir + 'samples/android/SConscript')
index 3c7cd74..32880e7 100644 (file)
@@ -171,6 +171,7 @@ env.AppendUnique(CCFLAGS = ['-Wall', '-fPIC'])
 #env.AppendUnique(LINKFLAGS = ['-ldl', '-lpthread'])
 
 env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+src_dir = env.get('SRC_DIR')
 env.AppendUnique(LIBPATH = [src_dir + '/lib/android'])
 env.AppendUnique(LIBS = ['log', 'coap'])
 if env.get('SECURED') == '1':
index 282900a..e9605b2 100644 (file)
@@ -1,7 +1,3 @@
-include $(CLEAR_VARS)
-LOCAL_MODULE := flags_probe
-include $(BUILD_SHARED_LIBRARY)
-
 $(info TC_PREFIX=$(TOOLCHAIN_PREFIX))
 $(info CFLAGS=$(TARGET_CFLAGS))
 $(info CXXFLAGS=$(TARGET_CXXFLAGS) $(TARGET_NO_EXECUTE_CFLAGS))
@@ -9,4 +5,157 @@ $(info CPPPATH=$(TARGET_C_INCLUDES) $(__ndk_modules.$(APP_STL).EXPORT_C_INCLUDES
 $(info SYSROOT=$(SYSROOT_LINK))
 $(info LDFLAGS=$(TARGET_LDFLAGS) $(TARGET_NO_EXECUTE_LDFLAGS) $(TARGET_NO_UNDEFINED_LDFLAGS) $(TARGET_RELRO_LDFLAGS))
 $(info TC_VER=$(TOOLCHAIN_VERSION))
-$(info PLATFORM=$(APP_PLATFORM))
\ No newline at end of file
+$(info PLATFORM=$(APP_PLATFORM))
+
+
+#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+#define build type
+BUILD = debug
+
+PROJECT_ROOT_PATH                       ?= ../..
+PROJECT_API_PATH                        = $(PROJECT_ROOT_PATH)/api
+PROJECT_INC_PATH                        = $(PROJECT_ROOT_PATH)/inc
+PROJECT_SRC_PATH                        = $(PROJECT_ROOT_PATH)/src
+PROJECT_COMMON_PATH                     = $(PROJECT_ROOT_PATH)/common
+PROJECT_COMMON_INC_PATH                 = $(PROJECT_COMMON_PATH)/inc
+PROJECT_COMMON_SRC_PATH                 = $(PROJECT_COMMON_PATH)/src
+PROJECT_LIB_PATH                        = $(PROJECT_ROOT_PATH)/lib
+PROJECT_EXTERNAL_PATH                   = $(PROJECT_ROOT_PATH)/external/inc
+DTLS_LIB                                = $(PROJECT_LIB_PATH)/tinydtls
+GLIB_PATH                               = ../../../../../../extlibs/glib/glib-2.40.2
+
+#Modify below values to enable/disable the Adapter
+#Suffix "NO_" to disable given adapter
+EDR             = NO_EDR_ADAPTER
+WIFI            = WIFI_ADAPTER
+LE              = NO_LE_ADAPTER
+ETHERNET        = NO_ETHERNET_ADAPTER
+
+#Add Pre processor definitions
+DEFINE_FLAG =  -DWITH_POSIX -D__ANDROID__
+DEFINE_FLAG += -D$(EDR) -D$(LE) -D$(WIFI) -D$(ETHERNET)
+
+#Add Debug flags here
+DEBUG_FLAG      = -DTB_LOG
+#DEBUG_FLAG     += -DADB_SHELL
+
+BUILD_FLAG.debug        = $(DEFINE_FLAG) $(DEBUG_FLAG)
+BUILD_FLAG.release      =       $(DEFINE_FLAG)
+BUILD_FLAG = $(BUILD_FLAG.$(BUILD))
+
+#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+#include glib
+
+include $(CLEAR_VARS)
+LOCAL_PATH = $(PROJECT_LIB_PATH)/android
+LOCAL_MODULE = Glib
+LOCAL_SRC_FILES := libglib-2.40.2.so
+LOCAL_EXPORT_C_INCLUDES = $(GLIB_PATH) \
+                          $(GLIB_PATH)/glib
+
+include $(PREBUILT_SHARED_LIBRARY)
+
+#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+#include glibthread
+
+include $(CLEAR_VARS)
+LOCAL_PATH = $(PROJECT_LIB_PATH)/android
+LOCAL_MODULE = GLibThread
+LOCAL_SRC_FILES := libgthread-2.40.2.so
+LOCAL_EXPORT_C_INCLUDES = $(GLIB_PATH) \
+                          $(GLIB_PATH)/glib
+
+include $(PREBUILT_SHARED_LIBRARY)
+
+#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+#Build TinyDtls
+
+include $(CLEAR_VARS)
+include $(DTLS_LIB)/Android.mk
+
+#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+#Build CACommon
+
+include $(CLEAR_VARS)
+
+#Build Common Libraries
+LOCAL_PATH = $(PROJECT_COMMON_SRC_PATH)
+LOCAL_MODULE = CACommon
+LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
+
+LOCAL_SHARED_LIBRARIES = Glib GLibThread
+
+LOCAL_CFLAGS = -D__ANDROID__ $(DEBUG_FLAG)
+
+LOCAL_C_INCLUDES = $(PROJECT_COMMON_INC_PATH)
+LOCAL_C_INCLUDES += $(PROJECT_API_PATH)
+
+LOCAL_SRC_FILES =       oic_logger.c \
+                                        oic_console_logger.c logger.c oic_malloc.c \
+                                        uarraylist.c uqueue.c oic_string.c \
+                                        uthreadpool.c umutex.c
+
+include $(BUILD_STATIC_LIBRARY)
+
+#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+#Build CACoap
+
+include $(CLEAR_VARS)
+
+LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
+LOCAL_PATH = $(PROJECT_LIB_PATH)/libcoap-4.1.1
+LOCAL_MODULE = CACoap
+LOCAL_EXPORT_C_INCLUDES = $(PROJECT_LIB_PATH)/libcoap-4.1.1
+LOCAL_CFLAGS = -DWITH_POSIX
+LOCAL_SRC_FILES = pdu.c net.c debug.c encode.c uri.c coap_list.c resource.c hashkey.c \
+                                        str.c option.c async.c subscribe.c block.c
+
+include $(BUILD_STATIC_LIBRARY)
+
+#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+#Build CA
+
+#Relative path to LOCAL_PATH (PROJECT_SRC_PATH)
+LOCAL_PLATFORM                          = android
+
+ENET_ADAPTER_PATH                       = ethernet_adapter/$(LOCAL_PLATFORM)
+EDR_ADAPTER_PATH                        = bt_edr_adapter/$(LOCAL_PLATFORM)
+LE_ADAPTER_PATH                         = bt_le_adapter/$(LOCAL_PLATFORM)
+WIFI_ADAPTER_PATH                       = wifi_adapter/$(LOCAL_PLATFORM)
+ADAPTER_UTILS                           = adapter_util
+
+include $(CLEAR_VARS)
+
+LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
+LOCAL_PATH = $(PROJECT_SRC_PATH)
+LOCAL_MODULE = CA
+
+LOCAL_STATIC_LIBRARIES = CACommon CACoap TinyDtls
+
+LOCAL_C_INCLUDES = $(PROJECT_API_PATH)
+LOCAL_C_INCLUDES += $(PROJECT_COMMON_INC_PATH)
+LOCAL_C_INCLUDES += $(PROJECT_INC_PATH)
+LOCAL_C_INCLUDES += $(PROJECT_LIB_PATH)/libcoap-4.1.1
+LOCAL_C_INCLUDES += $(PROJECT_EXTERNAL_PATH)
+LOCAL_C_INCLUDES += $(DTLS_LIB)
+
+LOCAL_CFLAGS += $(BUILD_FLAG)
+LOCAL_CFLAGS += -std=c99
+
+LOCAL_SRC_FILES = \
+                caconnectivitymanager.c caremotehandler.c cainterfacecontroller.c \
+                camessagehandler.c canetworkconfigurator.c caprotocolmessage.c \
+                caretransmission.c caqueueingthread.c \
+                $(ADAPTER_UTILS)/caadapterutils.c \
+                $(ADAPTER_UTILS)/camsgparser.c \
+                bt_le_adapter/caleadapter.c $(LE_ADAPTER_PATH)/caleclient.c \
+                $(LE_ADAPTER_PATH)/caleserver.c $(LE_ADAPTER_PATH)/caleutils.c \
+                $(LE_ADAPTER_PATH)/calenwmonitor.c \
+                bt_edr_adapter/caedradapter.c $(EDR_ADAPTER_PATH)/caedrutils.c \
+                $(EDR_ADAPTER_PATH)/caedrclient.c $(EDR_ADAPTER_PATH)/caedrserver.c \
+                $(EDR_ADAPTER_PATH)/caedrnwmonitor.c \
+                wifi_adapter/cawifiadapter.c $(WIFI_ADAPTER_PATH)/cawifiserver.c \
+                $(WIFI_ADAPTER_PATH)/cawificlient.c $(WIFI_ADAPTER_PATH)/cawifinwmonitor.c \
+
+include $(BUILD_STATIC_LIBRARY)
+
index a9552ee..4287319 100644 (file)
 #ifndef CA_ADAPTER_UTILS_H_
 #define CA_ADAPTER_UTILS_H_
 
+#include <stdbool.h>
+#ifdef __ANDROID__
+#include <jni.h>
+#endif
+
 #include "cacommon.h"
 #include "logger.h"
 #include "pdu.h"
@@ -161,7 +166,11 @@ CAResult_t CAParseIPv4AddressInternal(const char *ipAddrStr, uint8_t *ipAddr,
 
 /**
  * @fn CAAdapterIsSameSubnet
- * @brief Check if two ip address belong to same subnet
+ * @brief Check if two ip address belong to same subnet.
+ * @param   ipAddress1   [IN]   IP address to be checked
+ * @param   ipAddress2   [IN]   IP address to be checked
+ * @param   netMask      [IN]   Subnet mask
+ * @return  true if same subnet and false if not same subnet
  */
 bool CAAdapterIsSameSubnet(const char *ipAddress1, const char *ipAddress2,
                            const char *netMask);
@@ -259,6 +268,43 @@ void CAClearNetInterfaceInfoList(u_arraylist_t *infoList);
  */
 void CAClearServerInfoList(u_arraylist_t *serverInfoList);
 
+#ifdef __ANDROID__
+/**
+ * @fn CANativeJNISetContext
+ * @brief   To set context of JNI Application
+ *          This must be called by the Android API before CA Initialization
+ * @param   env         [IN] JNI interface pointer
+ * @param   context     [IN] context object
+ * @return  None
+ */
+void CANativeJNISetContext(JNIEnv *env, jobject context);
+
+/**
+ * @fn CANativeJNISetJavaVM
+ * @brief   To set jvm object
+ *          This must be called by the Android API before CA Initialization
+ * @param   jvm         [IN] jvm object
+ * @return  None
+ */
+void CANativeJNISetJavaVM(JavaVM *jvm);
+
+/**
+ * @fn CANativeJNISetContext
+ * @brief   To get context
+ *          Called by adapters to get Application context
+ * @return  context object
+ */
+jobject CANativeJNIGetContext();
+
+/**
+ * @fn CANativeJNIGetJavaVM
+ * @brief   To get JVM object
+ *          Called from adapters to get JavaVM object
+ * @return  JVM object
+ */
+JavaVM *CANativeJNIGetJavaVM();
+#endif
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/resource/csdk/connectivity/samples/android/SConscript b/resource/csdk/connectivity/samples/android/SConscript
new file mode 100644 (file)
index 0000000..e3a4f18
--- /dev/null
@@ -0,0 +1,51 @@
+##\r
+# Building sample application\r
+##\r
+\r
+Import('env')\r
+\r
+app_env = env.Clone()\r
+\r
+ca_os = app_env.get('TARGET_OS')\r
+ca_transport = app_env.get('TARGET_TRANSPORT')\r
+secured = app_env.get('SECURED')\r
+\r
+root_dir = './../../'\r
+main_dir  = Dir('.').srcnode().abspath\r
+jni_dir = main_dir + '/sample_serivce/android/jni'\r
+env.PrependUnique(CPPPATH = ['jni_dir'])\r
+app_env.PrependUnique(CPPDEFINES = ['__ANDROID__'])\r
+\r
+#####################################################################\r
+# Source files and Target(s)\r
+######################################################################\r
+\r
+print"Reading ca script %s"%ca_transport\r
+\r
+app_env.AppendUnique(CPPPATH = [root_dir + '/api/'])\r
+\r
+print "Reading sample application build script"\r
+\r
+build_dir = app_env.get('BUILD_DIR')\r
+secured = app_env.get('SECURED')\r
+\r
+print "Sample secured flag is %s" % secured\r
+\r
+sample_dir = 'sample_service/jni/'\r
+sample_src = [sample_dir + 'ResourceModel.c',]\r
+\r
+print " sample src %s" % sample_src\r
+\r
+app_env.AppendUnique(LIBPATH = [app_env.get('BUILD_DIR'), '.',])\r
+app_env.AppendUnique(CPPPATH = ['lib/android'])\r
+app_env.PrependUnique(LIBS = ['connectivity_abstraction'])\r
+\r
+\r
+if secured == '1':\r
+       app_env.AppendUnique(CPPPATH = [root_dir + 'external/inc/'])\r
+       app_env.PrependUnique(CPPDEFINES = ['__WITH_DTLS__'])\r
+\r
+libRMInterface = app_env.SharedLibrary('RMInterface', sample_src, OBJPREFIX='libRMInterface_')\r
+app_env.InstallTarget(libRMInterface, 'RMInterface')\r
+\r
+\r
index aba8cff..5fb2f2e 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "cainterface.h"
 #include "cacommon.h"
+
 #include "org_iotivity_service_RMInterface.h"
 
 #define  LOG_TAG   "JNI_INTERFACE_SAMPLE"
 
 #define PORT_LENGTH 5
 #define SECURE_DEFAULT_PORT 5684
+#define RESOURCE_URI_LENGTH 14
+#define OPTION_INFO_LENGTH 1024
+#define NETWORK_INFO_LENGTH 1024
 
-int g_received = 0;
 uint16_t g_localSecurePort = SECURE_DEFAULT_PORT;
 
 void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* requestInfo);
 void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* responseInfo);
-void get_resource_uri(const char *URI, char *resourceURI, int length);
-int get_secure_information(CAPayload_t payLoad);
-CAResult_t get_network_type(int selectedNetwork);
+void get_resource_uri(const char *URI, char *resourceURI, uint32_t length);
+uint32_t get_secure_information(CAPayload_t payLoad);
+CAResult_t get_network_type(uint32_t selectedNetwork);
 void callback(char *subject, char *receivedData);
+CAResult_t get_remote_address(CATransportType_t transportType, CAAddress_t addressInfo);
 
 CATransportType_t g_selectedNwType = CA_IPV4;
 static CAToken_t g_lastRequestToken = NULL;
 static uint8_t g_lastRequestTokenLength;
+
 static const char SECURE_COAPS_PREFIX[] = "coaps://";
-static const char SECURE_INFO_DATA[]
-                                   = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
-                                     "\"if\":[\"oc.mi.def\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
-static const char NORMAL_INFO_DATA[]
-                                   = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
-                                     "\"if\":[\"oc.mi.def\"],\"obs\":1}}]}";
+static const char SECURE_INFO_DATA[] = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
+                                       "\"if\":[\"oc.mi.def\"],\"obs\":1,\"sec\":1,"
+                                       "\"port\":%d}}]}";
+static const char NORMAL_INFO_DATA[] = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
+                                       "\"if\":[\"oc.mi.def\"],\"obs\":1}}]}";
 
 static jobject g_responseListenerObject = NULL;
-extern JavaVM *g_jvm;
+static JavaVM *g_jvm;
 
+static CARemoteEndpoint_t *g_clientEndpoint = NULL;
 static CAToken_t g_clientToken;
 static uint8_t g_clientTokenLength = NULL;
+
+static uint16_t g_clientMsgId;
+static char *g_remoteAddress = NULL;
+
 // init
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_setNativeResponseListener
-    (JNIEnv *env, jobject obj, jobject listener){
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_setNativeResponseListener(JNIEnv *env, jobject obj,
+                                                                jobject listener)
+{
     LOGI("setNativeResponseListener");
     g_responseListenerObject = (*env)->NewGlobalRef(env, obj);
 }
@@ -64,11 +75,11 @@ static CADtlsPskCredsBlob_t *pskCredsBlob = NULL;
 
 void clearDtlsCredentialInfo()
 {
-    LOGI("clearDtlsCredentialInfo IN\n");
+    LOGI("clearDtlsCredentialInfo IN");
     if (pskCredsBlob)
     {
         // Initialize sensitive data to zeroes before freeing.
-        if (pskCredsBlob->creds)
+        if (NULL != pskCredsBlob->creds)
         {
             memset(pskCredsBlob->creds, 0, sizeof(OCDtlsPskCreds)*(pskCredsBlob->num));
             free(pskCredsBlob->creds);
@@ -78,20 +89,14 @@ void clearDtlsCredentialInfo()
         free(pskCredsBlob);
         pskCredsBlob = NULL;
     }
-    LOGI("clearDtlsCredentialInfo OUT\n");
+    LOGI("clearDtlsCredentialInfo OUT");
 }
 
-// Internal API. Invoked by CA stack to retrieve credentials from this module
+// Internal API. Invoked by OC stack to retrieve credentials from this module
 void CAGetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo)
 {
-    LOGI("CAGetDtlsPskCredentials IN\n");
-    if(!credInfo)
-    {
-        LOGE("Invalid credential container");
-        return;
-    }
-
-    *credInfo = (CADtlsPskCredsBlob_t *)malloc(sizeof(CADtlsPskCredsBlob_t));
+    LOGI("CAGetDtlsPskCredentials IN");
+    *credInfo = (CADtlsPskCredsBlob_t *) malloc(sizeof(CADtlsPskCredsBlob_t));
     if (NULL == *credInfo)
     {
         LOGE("Failed to allocate credential blob.");
@@ -99,7 +104,7 @@ void CAGetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo)
     }
 
     int16_t credLen = sizeof(OCDtlsPskCreds) * (pskCredsBlob->num);
-    (*credInfo)->creds = (OCDtlsPskCreds *)malloc(credLen);
+    (*credInfo)->creds = (OCDtlsPskCreds *) malloc(credLen);
     if (NULL == (*credInfo)->creds)
     {
         LOGE("Failed to allocate crentials.");
@@ -112,113 +117,137 @@ void CAGetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo)
     (*credInfo)->num = pskCredsBlob->num;
     memcpy((*credInfo)->creds, pskCredsBlob->creds, credLen);
 
-    LOGI("CAGetDtlsPskCredentials OUT\n");
+    LOGI("CAGetDtlsPskCredentials OUT");
 }
 
-bool SetCredentials()
+CAResult_t SetCredentials()
 {
-    LOGI("SetCredentials IN\n");
-    pskCredsBlob = (CADtlsPskCredsBlob_t *)calloc(1, sizeof(CADtlsPskCredsBlob_t));
+    LOGI("SetCredentials IN");
+    pskCredsBlob = (CADtlsPskCredsBlob_t *)malloc(sizeof(CADtlsPskCredsBlob_t));
     if (NULL == pskCredsBlob)
-     {
-        LOGE("Memory allocation failed!\n");
-        return false;
-     }
+    {
+        LOGE("Memory allocation failed!");
+        return CA_MEMORY_ALLOC_FAILED;
+    }
     memcpy(pskCredsBlob->identity, IDENTITY, DTLS_PSK_ID_LEN);
+
     pskCredsBlob->num = 1;
 
-    pskCredsBlob->creds = (OCDtlsPskCreds *)malloc(sizeof(OCDtlsPskCreds) * (pskCredsBlob->num));
+    pskCredsBlob->creds = (OCDtlsPskCreds *)malloc(sizeof(OCDtlsPskCreds) *(pskCredsBlob->num));
     if (NULL == pskCredsBlob->creds)
     {
-        LOGE("Memory allocation failed!\n");
-        free(pskCredsBlob);
-        return false;
+        LOGE("Memory allocation failed!");
+        return CA_MEMORY_ALLOC_FAILED;
     }
-
     memcpy(pskCredsBlob->creds[0].id, IDENTITY, DTLS_PSK_ID_LEN);
     memcpy(pskCredsBlob->creds[0].psk, RS_CLIENT_PSK, DTLS_PSK_PSK_LEN);
 
-    LOGI("SetCredentials OUT\n");
-    return true;
+    LOGI("SetCredentials OUT");
+    return CA_STATUS_OK;
 }
 #endif
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMInitialize
-  (JNIEnv *env, jobject obj, jobject context)
+JNIEXPORT jint JNI_OnLoad(JavaVM *jvm, void *reserved)
+{
+    LOGI("JNI_OnLoad");
+
+    JNIEnv* env;
+    if (JNI_OK != (*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION_1_6))
+    {
+        return -1;
+    }
+    g_jvm = jvm; /* cache the JavaVM pointer */
+
+    CANativeJNISetJavaVM(g_jvm);
+
+    return JNI_VERSION_1_6;
+}
+
+void JNI_OnUnload(JavaVM *jvm, void *reserved)
+{
+    LOGI("JNI_OnUnload");
+
+    JNIEnv* env;
+    if (JNI_OK != (*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION_1_6))
+    {
+        return;
+    }
+    g_jvm = 0;
+    return;
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMInitialize(JNIEnv *env, jobject obj, jobject context)
 {
     LOGI("RMInitialize");
-    //Currently set context for WiFiCore
-    CAJniSetContext(context);
-    CALEServerJNISetContext(env, context);
-    CALEClientJNISetContext(env, context);
-    CALENetworkMonitorJNISetContext(env, context);
 
-    CAResult_t res;
+    //Currently set context for Android Platform
+    CANativeJNISetContext(env, context);
+
+    CAResult_t res = CAInitialize();
+
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Could not Initialize");
+    }
 
 #ifdef __WITH_DTLS__
-    if (true != SetCredentials())
+    if (CA_STATUS_OK != SetCredentials())
     {
-        LOGI("SetCredentials failed\n");
+        LOGE("SetCredentials failed");
         return;
     }
 
     res = CARegisterDTLSCredentialsHandler(CAGetDtlsPskCredentials);
-    if(res != CA_STATUS_OK)
+    if(CA_STATUS_OK != res)
     {
-        LOGI("Set credential handler fail\n");
+        LOGE("Set credential handler fail");
         return;
     }
 #endif
-
-    if(CA_STATUS_OK != CAInitialize())
-    {
-        LOGI("Could not Initialize");
-    }
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMTerminate(JNIEnv *env, jobject obj)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMTerminate(JNIEnv *env, jobject obj)
 {
     LOGI("RMTerminate");
-
+    CADestroyToken(g_lastRequestToken);
     CATerminate();
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMStartListeningServer(JNIEnv *env,
-    jobject obj)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMStartListeningServer(JNIEnv *env, jobject obj)
 {
     LOGI("RMStartListeningServer");
 
-    if(CA_STATUS_OK != CAStartListeningServer())
+    if (CA_STATUS_OK != CAStartListeningServer())
     {
-        LOGI("Could not start Listening server");
+        LOGE("Could not start Listening server");
     }
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMStartDiscoveryServer(JNIEnv *env,
-    jobject obj)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMStartDiscoveryServer(JNIEnv *env, jobject obj)
 {
     LOGI("RMStartDiscoveryServer");
 
-    if(CA_STATUS_OK != CAStartDiscoveryServer())
+    if (CA_STATUS_OK != CAStartDiscoveryServer())
     {
-        LOGI("Could not start discovery server");
+        LOGE("Could not start discovery server");
     }
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMRegisterHandler(JNIEnv *env,
-    jobject obj)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMRegisterHandler(JNIEnv *env, jobject obj)
 {
     LOGI("RMRegisterHandler");
 
     CARegisterHandler(request_handler, response_handler);
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMFindResource(JNIEnv *env,
-        jobject obj, jstring uri)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMFindResource(JNIEnv *env, jobject obj, jstring uri)
 {
-    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
-    LOGI("RMFindResource - %s", strUri);
-
     // create token
     CAToken_t token = NULL;
     uint8_t tokenLength = CA_MAX_TOKEN_LEN;
@@ -232,9 +261,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMFindResource(JNIE
 
     printf("Generated token %s\n", token);
 
+    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
+    LOGI("RMFindResource - %s", strUri);
+
     res = CAFindResource((const CAURI_t) strUri, token, tokenLength);
 
-    if (res != CA_STATUS_OK)
+    //ReleseStringUTFCharss for strUri
+    (*env)->ReleaseStringUTFChars(env, uri, strUri);
+
+    if (CA_STATUS_OK != res)
     {
         LOGE("Could not find resource");
         //destroy token
@@ -249,29 +284,31 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMFindResource(JNIE
     }
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendRequest(JNIEnv *env,
-        jobject obj, jstring uri, jstring payload, jint selectedNetwork, jint isSecured,
-        jint msgType)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj, jstring uri,
+                                                    jstring payload, jint selectedNetwork,
+                                                    jint isSecured, jint msgType)
 {
-    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
-    LOGI("RMSendRequest - %s", strUri);
-
-    CAResult_t res;
-
     LOGI("selectedNetwork - %d", selectedNetwork);
-    res = get_network_type(selectedNetwork);
-    if (res != CA_STATUS_OK)
+    CAResult_t res = get_network_type(selectedNetwork);
+    if (CA_STATUS_OK != res)
     {
         return;
     }
 
+    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
+    LOGI("RMSendRequest - %s", strUri);
+
     //create remote endpoint
     CARemoteEndpoint_t* endpoint = NULL;
+    res = CACreateRemoteEndpoint((const CAURI_t) strUri, g_selectedNwType, &endpoint);
+
+    //ReleaseStringUTFChars for strUri
+    (*env)->ReleaseStringUTFChars(env, uri, strUri);
 
-    if(CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t)strUri, g_selectedNwType, &endpoint))
+    if (CA_STATUS_OK != res)
     {
-        LOGI("Could not create remote end point");
-        CADestroyRemoteEndpoint(endpoint);
+        LOGE("Could not create remote end point");
         return;
     }
 
@@ -290,22 +327,21 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendRequest(JNIEn
         return;
     }
 
-    char resourceURI[15] = {0};
+    char resourceURI[RESOURCE_URI_LENGTH + 1] = { 0 };
 
-    get_resource_uri((const CAURI_t)strUri, resourceURI, 14);
+    get_resource_uri((const CAURI_t) strUri, resourceURI, RESOURCE_URI_LENGTH);
 
-    CAInfo_t requestData = {0};
+    CAInfo_t requestData = { 0 };
     requestData.token = token;
     requestData.tokenLength = tokenLength;
 
-    const char* strPayload = (*env)->GetStringUTFChars(env, payload, NULL);
-    if (isSecured == 1)
+    if (1 == isSecured)
     {
         uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI);
         requestData.payload = (CAPayload_t) malloc(length);
         if (NULL == requestData.payload)
         {
-            LOGI("Memory allocation failed!\n");
+            LOGE("Memory allocation failed!");
             // destroy token
             CADestroyToken(token);
             // destroy remote endpoint
@@ -320,7 +356,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendRequest(JNIEn
         requestData.payload = (CAPayload_t) malloc(length);
         if (NULL == requestData.payload)
         {
-            LOGI("Memory allocation failed!\n");
+            LOGE("Memory allocation failed!");
             // destroy token
             CADestroyToken(token);
             // destroy remote endpoint
@@ -332,14 +368,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendRequest(JNIEn
 
     requestData.type = messageType;
 
-    CARequestInfo_t requestInfo = {0};
+    CARequestInfo_t requestInfo = { 0 };
     requestInfo.method = CA_GET;
     requestInfo.info = requestData;
 
     // send request
-    if(CA_STATUS_OK != CASendRequest(endpoint, &requestInfo))
+    if (CA_STATUS_OK != CASendRequest(endpoint, &requestInfo))
     {
-        LOGI("Could not send request");
+        LOGE("Could not send request");
     }
 
     // destroy token
@@ -347,37 +383,46 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendRequest(JNIEn
 
     // destroy remote endpoint
     CADestroyRemoteEndpoint(endpoint);
+
+    free(requestData.payload);
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendResponse(JNIEnv *env,
-    jobject obj, jstring uri, jstring payload, jint selectedNetwork, jint isSecured)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject obj, jstring uri,
+                                                        jint selectedNetwork)
 {
-    LOGI("RMSendResponse");
+    LOGI("selectedNetwork - %d", selectedNetwork);
+    CAResult_t res = get_network_type(selectedNetwork);
+    if (CA_STATUS_OK != res)
+    {
+        return;
+    }
 
     const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
-    LOGI("RMSendResponse - %s", strUri);
+    LOGI("RMSendReqestToAll - %s", strUri);
 
-    CAResult_t res;
+    // create remote endpoint
+    CARemoteEndpoint_t *endpoint = NULL;
+    res = CACreateRemoteEndpoint((const CAURI_t) strUri, g_selectedNwType, &endpoint);
 
-    LOGI("selectedNetwork - %d", selectedNetwork);
+    //ReleaseStringUTFChars for strUri
+    (*env)->ReleaseStringUTFChars(env, uri, strUri);
 
-    res = get_network_type(selectedNetwork);
-    if (res != CA_STATUS_OK)
+    if (CA_STATUS_OK != res)
     {
+        LOGE("create remote endpoint error, error code: %d", res);
         return;
     }
 
-    //create remote endpoint
-    CARemoteEndpoint_t* endpoint = NULL;
-
-    if(CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t)strUri, g_selectedNwType, &endpoint))
+    CAGroupEndpoint_t *group = (CAGroupEndpoint_t *) malloc(sizeof(CAGroupEndpoint_t));
+    if (NULL == group)
     {
-        LOGI("Could not create remote end point");
+        LOGE("Memory allocation failed!");
         CADestroyRemoteEndpoint(endpoint);
         return;
     }
-
-    CAMessageType_t messageType = CA_MSG_ACKNOWLEDGE;
+    group->transportType = endpoint->transportType;
+    group->resourceUri = endpoint->resourceUri;
 
     // create token
     CAToken_t token = NULL;
@@ -386,84 +431,134 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendResponse(JNIE
     res = CAGenerateToken(&token, tokenLength);
     if ((CA_STATUS_OK != res) || (!token))
     {
-        LOGE("token generate error!");
+        LOGE("token generate error!!");
+        // destroy remote endpoint
         CADestroyRemoteEndpoint(endpoint);
+        free(group);
+        return;
     }
 
-    char resourceURI[15] = {0};
+    LOGI("generated token %s", token);
 
-    get_resource_uri((const CAURI_t)strUri, resourceURI, 14);
+    CAInfo_t requestData = { 0 };
+    requestData.token = token;
+    requestData.tokenLength = tokenLength;
+    requestData.payload = "Temp Json Payload";
+    requestData.type = CA_MSG_NONCONFIRM;
 
-    CAInfo_t responseData = {0};
-    responseData.token = token;
+    CARequestInfo_t requestInfo = { 0 };
+    requestInfo.method = CA_GET;
+    requestInfo.info = requestData;
 
-    const char* strPayload = (*env)->GetStringUTFChars(env, payload, NULL);
-    if (isSecured == 1)
+    // send request to all
+    res = CASendRequestToAll(group, &requestInfo);
+    if (CA_STATUS_OK != res)
     {
-        uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI);
-        responseData.payload = (CAPayload_t) malloc(length);
-        if (NULL == responseData.payload)
-        {
-            LOGI("Memory allocation failed!\n");
-            // destroy token
-            CADestroyToken(token);
-            // destroy remote endpoint
-            CADestroyRemoteEndpoint(endpoint);
-            return;
-        }
-        snprintf(responseData.payload, length, SECURE_INFO_DATA, resourceURI, g_localSecurePort);
+        LOGE("Could not send request to all");
+        //destroy token
+        CADestroyToken(token);
     }
     else
     {
-        uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI);
-        responseData.payload = (CAPayload_t) malloc(length);
-        if (NULL == responseData.payload)
-        {
-            LOGI("Memory allocation failed!\n");
-            // destroy token
-            CADestroyToken(token);
-            // destroy remote endpoint
-            CADestroyRemoteEndpoint(endpoint);
-            return;
-        }
-        snprintf(responseData.payload, length, NORMAL_INFO_DATA, resourceURI);
+        CADestroyToken(g_lastRequestToken);
+        g_lastRequestToken = token;
+        g_lastRequestTokenLength = tokenLength;
     }
 
+    // destroy remote endpoint
+    CADestroyRemoteEndpoint(endpoint);
+    free(group);
+
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMSendResponse(JNIEnv *env, jobject obj,
+                                                     jint selectedNetwork,
+                                                     jint isSecured, jint msgType,
+                                                     jint responseValue)
+{
+    LOGI("RMSendResponse");
+
+    LOGI("selectedNetwork - %d", selectedNetwork);
+
+    CAResult_t res = get_network_type(selectedNetwork);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Not supported network type");
+        return;
+    }
+
+    if (NULL == g_clientEndpoint)
+    {
+        LOGE("No Request received");
+        return;
+    }
+
+    CAMessageType_t messageType = msgType;
+
+    CAInfo_t responseData = { 0 };
     responseData.type = messageType;
+    responseData.messageId = g_clientMsgId;
 
-    CAResponseInfo_t responseInfo = {0};
-    responseInfo.result = CA_SUCCESS;
-    responseInfo.info = responseData;
+    CAResponseInfo_t responseInfo = { 0 };
 
-    // send request
-    if(CA_STATUS_OK != CASendResponse(endpoint, &responseInfo))
+    if (msgType != CA_MSG_RESET)
+    {
+        responseData.token = g_clientToken;
+        responseData.tokenLength = g_clientTokenLength;
+        responseInfo.result = responseValue;
+
+        if (1 == isSecured)
+        {
+            uint32_t length = strlen(SECURE_INFO_DATA) + strlen(g_clientEndpoint->resourceUri) + 1;
+            responseData.payload = (CAPayload_t) malloc(length);
+            sprintf(responseData.payload, SECURE_INFO_DATA, g_clientEndpoint->resourceUri,
+                    g_localSecurePort);
+        }
+        else
+        {
+            uint32_t length = strlen(NORMAL_INFO_DATA) + strlen(g_clientEndpoint->resourceUri) + 1;
+            responseData.payload = (CAPayload_t) malloc(length);
+            sprintf(responseData.payload, NORMAL_INFO_DATA, g_clientEndpoint->resourceUri);
+        }
+    }
+    //msgType is RESET
+    else
     {
-        LOGI("Could not send response");
+        responseInfo.result = CA_EMPTY;
     }
 
-    LOGI("Send response");
+    responseInfo.info = responseData;
+
+    // send response
+    res = CASendResponse(g_clientEndpoint, &responseInfo);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Could not send response");
+    }
 
     // destroy token
-    CADestroyToken(token);
+    CADestroyToken(g_clientToken);
+    g_clientToken = NULL;
+    g_clientTokenLength = 0;
 
     // destroy remote endpoint
-    CADestroyRemoteEndpoint(endpoint);
+    CADestroyRemoteEndpoint(g_clientEndpoint);
+    g_clientEndpoint = NULL;
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMAdvertiseResource(JNIEnv *env,
-    jobject obj, jstring uri, jint selectedNetwork)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMAdvertiseResource(JNIEnv *env, jobject obj, jstring uri)
 {
     LOGI("RMAdvertiseResource");
 
-    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
-
-    int optionNum = 2;
+    uint32_t optionNum = 2;
 
-    CAHeaderOption_t *headerOpt;
-    headerOpt = (CAHeaderOption_t*) calloc(1, sizeof(CAHeaderOption_t) * optionNum);
+    CAHeaderOption_t *headerOpt = (CAHeaderOption_t*) calloc(1,
+                                                             sizeof(CAHeaderOption_t) * optionNum);
     if (NULL == headerOpt)
     {
-        LOGI("Memory allocation failed!\n");
+        LOGE("Memory allocation failed!");
         return;
     }
 
@@ -479,72 +574,99 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMAdvertiseResource
 
     // create token
     CAToken_t token = NULL;
-    CAResult_t res = CAGenerateToken(&token);
-    if (res != CA_STATUS_OK)
+    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
+
+    CAResult_t res = CAGenerateToken(&token, tokenLength);
+    if ((CA_STATUS_OK != res) || (!token))
     {
-        LOGI("token generate error!");
+        LOGE("token generate error!");
         free(headerOpt);
         return;
     }
 
-    CAAdvertiseResource((const CAURI_t)strUri, token, headerOpt, (uint8_t) optionNum);
+    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
+
+    res = CAAdvertiseResource((const CAURI_t) strUri, token, tokenLength,
+                              headerOpt, (uint8_t) optionNum);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Could not start advertise resource");
+        CADestroyToken(token);
+    }
+    else
+    {
+        CADestroyToken(g_lastRequestToken);
+        g_lastRequestToken = token;
+        g_lastRequestTokenLength = tokenLength;
+    }
 
     free(headerOpt);
+
+    //ReleaseStringUTFChars for strUri
+    (*env)->ReleaseStringUTFChars(env, uri, strUri);
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendNotification(JNIEnv *env,
-    jobject obj, jstring uri, jstring payload, jint selectedNetwork, jint isSecured)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMSendNotification(JNIEnv *env, jobject obj, jstring uri,
+                                                         jstring payload, jint selectedNetwork,
+                                                         jint isSecured, jint msgType,
+                                                         jint responseValue)
 {
-    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
-    LOGI("RMSendNotification - %s", strUri);
-
-    CAResult_t res;
-
     LOGI("selectedNetwork - %d", selectedNetwork);
 
-    res = get_network_type(selectedNetwork);
-    if (res != CA_STATUS_OK)
+    CAResult_t res = get_network_type(selectedNetwork);
+    if (CA_STATUS_OK != res)
     {
-       LOGI("Not supported network type");
+        LOGE("Not supported network type");
         return;
     }
 
+    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
+    LOGI("RMSendNotification - %s", strUri);
+
     //create remote endpoint
     CARemoteEndpoint_t* endpoint = NULL;
-
-    if(CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t)strUri, g_selectedNwType, &endpoint))
+    if (CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t) strUri,
+                                               g_selectedNwType, &endpoint))
     {
-        LOGI("Could not create remote end point");
-        CADestroyRemoteEndpoint(endpoint);
+        LOGE("Could not create remote end point");
         return;
+
+        //ReleaseStringUTFChars for strUri
+        (*env)->ReleaseStringUTFChars(env, uri, strUri);
     }
 
-    CAMessageType_t messageType = CA_MSG_NONCONFIRM;
+    char resourceURI[RESOURCE_URI_LENGTH + 1] = { 0 };
+    get_resource_uri((const CAURI_t) strUri, resourceURI, RESOURCE_URI_LENGTH);
+
+    //ReleaseStringUTFChars for strUri
+    (*env)->ReleaseStringUTFChars(env, uri, strUri);
+
+    CAMessageType_t messageType = msgType;
 
     // create token
     CAToken_t token = NULL;
-    res = CAGenerateToken(&token);
-    if (res != CA_STATUS_OK)
+    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
+
+    res = CAGenerateToken(&token, tokenLength);
+    if ((CA_STATUS_OK != res) || (!token))
     {
-        LOGI("token generate error!");
-        token = NULL;
+        LOGE("token generate error!");
+        CADestroyRemoteEndpoint(endpoint);
+        return;
     }
 
-    char resourceURI[15] = {0};
-
-    get_resource_uri((const CAURI_t)strUri, resourceURI, 14);
-
-    CAInfo_t responseData = {0};
+    CAInfo_t responseData = { 0 };
     responseData.token = token;
+    responseData.tokenLength = tokenLength;
 
-    const char* strPayload = (*env)->GetStringUTFChars(env, payload, NULL);
-    if (isSecured == 1)
+    if (1 == isSecured)
     {
         uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI);
         responseData.payload = (CAPayload_t) malloc(length);
         if (NULL == responseData.payload)
         {
-            LOGI("Memory allocation failed!\n");
+            LOGE("Memory allocation failed!");
             // destroy token
             CADestroyToken(token);
             // destroy remote endpoint
@@ -559,7 +681,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendNotification(
         responseData.payload = (CAPayload_t) malloc(length);
         if (NULL == responseData.payload)
         {
-            LOGI("Memory allocation failed!\n");
+            LOGE("Memory allocation failed!");
             // destroy token
             CADestroyToken(token);
             // destroy remote endpoint
@@ -571,14 +693,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendNotification(
 
     responseData.type = messageType;
 
-    CAResponseInfo_t responseInfo = {0};
-    responseInfo.result = CA_SUCCESS;
+    CAResponseInfo_t responseInfo = { 0 };
+    responseInfo.result = responseValue;
     responseInfo.info = responseData;
 
-    // send request
-    if(CA_STATUS_OK != CASendNotification(endpoint, &responseInfo))
+    // send notification
+    if (CA_STATUS_OK != CASendNotification(endpoint, &responseInfo))
     {
-        LOGI("Could not send notification");
+        LOGE("Could not send notification");
     }
 
     LOGI("Send Notification");
@@ -588,175 +710,403 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSendNotification(
 
     // destroy remote endpoint
     CADestroyRemoteEndpoint(endpoint);
+
+    free(responseData.payload);
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMSelectNetwork(JNIEnv *env, jobject obj,
-    jint networkType)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMSelectNetwork(JNIEnv *env, jobject obj, jint networkType)
 {
     LOGI("RMSelectNetwork Type : %d", networkType);
 
-    if(CA_STATUS_OK != CASelectNetwork(networkType))
+    if (CA_STATUS_OK != CASelectNetwork(networkType))
     {
-        LOGI("Could not select network");
+        LOGE("Could not select network");
     }
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_service_RMInterface_RMHandleRequestResponse(JNIEnv *env,
-    jobject obj)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMUnSelectNetwork(JNIEnv *env, jobject obj, jint networkType)
+{
+    LOGI("RMUnSelectNetwork Type : %d", networkType);
+
+    if (CA_STATUS_OK != CAUnSelectNetwork(networkType))
+    {
+        LOGE("Could not unselect network");
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMGetNetworkInfomation(JNIEnv *env, jobject obj)
+{
+    LOGI("RMGetNetworkInfomation");
+
+    CALocalConnectivity_t *tempInfo = NULL;
+    uint32_t tempSize = 0;
+
+    CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Could not start get network information");
+        OICFree(tempInfo);
+        return;
+    }
+
+    LOGI("################## Network Information #######################");
+    callback("######## Network Information", "#######");
+    LOGI("Network info total size is %d", tempSize);
+
+    uint32_t index;
+    for (index = 0; index < tempSize; index++)
+    {
+        res = get_remote_address(tempInfo[index].type, tempInfo[index].addressInfo);
+        if (CA_STATUS_OK != res)
+        {
+            OICFree(tempInfo);
+            return;
+        }
+        if (NULL != g_responseListenerObject)
+        {
+            char networkInfo[NETWORK_INFO_LENGTH];
+            LOGI("Type: %d", tempInfo[index].type);
+            sprintf(networkInfo, "%d",tempInfo[index].type);
+            callback("Type :", networkInfo);
+            if (CA_IPV4 == tempInfo[index].type)
+            {
+                LOGI("Port: %d", tempInfo[index].addressInfo.IP.port);
+                sprintf(networkInfo, "%d",tempInfo[index].addressInfo.IP.port);
+                callback("Port: ", networkInfo);
+            }
+            LOGI("Secured: %d", tempInfo[index].isSecured);
+            LOGI("Address: %s", g_remoteAddress);
+            callback("Address: ", g_remoteAddress);
+            free(g_remoteAddress);
+        }
+        if (true == tempInfo[index].isSecured)
+        {
+            g_localSecurePort = tempInfo[index].addressInfo.IP.port;
+        }
+    }
+
+    // free
+    OICFree(tempInfo);
+
+    LOGI("##############################################################");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_RMInterface_RMHandleRequestResponse(JNIEnv *env, jobject obj)
 {
     LOGI("RMHandleRequestResponse");
 
-    if(CA_STATUS_OK != CAHandleRequestResponse())
+    if (CA_STATUS_OK != CAHandleRequestResponse())
     {
-        LOGI("Could not handle request and response");
+        LOGE("Could not handle request and response");
     }
 }
 
 void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* requestInfo)
 {
+
     if (!object)
     {
-        LOGI("Remote endpoint is NULL!");
+        LOGE("Remote endpoint is NULL!");
         return;
     }
 
     if (!requestInfo)
     {
-        LOGI("Request info is NULL!");
+        LOGE("Request info is NULL!");
+        return;
+    }
+
+    if ((NULL != g_lastRequestToken) && (NULL != requestInfo->info.token) &&
+            (strncmp(g_lastRequestToken, requestInfo->info.token,
+                     requestInfo->info.tokenLength) == 0))
+    {
+        LOGI("token is same. received request of it's own. skip.. ");
         return;
     }
 
-    LOGI("##########received request from remote device #############\n");
-    LOGI("Uri: %s\n", object->resourceUri);
-    LOGI("Remote Address: %s\n", object->addressInfo.IP.ipAddress);
+    CAResult_t res = get_remote_address(object->transportType, object->addressInfo);
+    if (CA_STATUS_OK != res)
+    {
+        return;
+    }
 
-    LOGI("Data: %s\n", requestInfo->info.payload);
+    LOGI("##########received request from remote device #############");
+    if (object->resourceUri)
+    {
+        LOGI("Uri: %s", object->resourceUri);
+    }
+    LOGI("Remote Address: %s", g_remoteAddress);
+    LOGI("Data: %s", requestInfo->info.payload);
+    LOGI("Token: %s", requestInfo->info.token);
+    LOGI("Code: %d", requestInfo->method);
+    LOGI("MessageType: %d", requestInfo->info.type);
 
     if (NULL != g_responseListenerObject)
     {
         callback("received request from remote device", "#######");
-        callback("Uri: ", object->resourceUri);
+        char *cloneUri = NULL;
+        uint32_t len = 0;
+
+        if (NULL != object->resourceUri)
+        {
+            len = strlen(object->resourceUri);
+            cloneUri = (char *) malloc(sizeof(char) * (len + 1));
 
-        callback("Remote Address: ", (char *) object->addressInfo.IP.ipAddress);
+            if (NULL == cloneUri)
+            {
+                LOGE("cloneUri Out of memory");
+                free(g_remoteAddress);
+                return;
+            }
+
+            memcpy(cloneUri, object->resourceUri, len + 1);
+            callback("Uri: ", cloneUri);
+        }
 
-        if(requestInfo->info.payload)
+        len = strlen(g_remoteAddress);
+        char *cloneRemoteAddress = (char *) malloc(sizeof(char) * (len + 1));
+
+        if (NULL == cloneRemoteAddress)
         {
-            callback("Data: ", requestInfo->info.payload);
+            LOGE("cloneRemoteAddress Out of memory");
+            free(g_remoteAddress);
+            free(cloneUri);
+            return;
         }
-    }
 
-    if ((!g_lastRequestToken) && (!requestInfo->info.token) &&
-            (strncmp(g_lastRequestToken, requestInfo->info.token,
-                     requestInfo->info.tokenLength) == 0))
-    {
-        LOGI("token is same. received request of it's own. skip.. \n");
-        return;
+        memcpy(cloneRemoteAddress, g_remoteAddress, len + 1);
+
+        callback("Remote Address: ", cloneRemoteAddress);
+        free(cloneRemoteAddress);
+        free(g_remoteAddress);
+
+        //clone g_clientEndpoint
+        g_clientEndpoint = (CARemoteEndpoint_t *) malloc(sizeof(CARemoteEndpoint_t));
+        if (NULL == g_clientEndpoint)
+        {
+            LOGE("g_clientEndpoint Out of memory");
+            free(cloneUri);
+            return;
+        }
+        memcpy(g_clientEndpoint, object, sizeof(CARemoteEndpoint_t));
+
+        if (NULL != cloneUri)
+        {
+            len = strlen(cloneUri);
+            g_clientEndpoint->resourceUri = (char *) malloc(sizeof(char) * (len + 1));
+            if (NULL == g_clientEndpoint)
+            {
+                LOGE("g_clientEndpoint->resourceUri Out of memory");
+                free(g_clientEndpoint);
+                free(cloneUri);
+                return;
+            }
+            memcpy(g_clientEndpoint->resourceUri, cloneUri, len + 1);
+            free(cloneUri);
+        }
+        //clone g_clientToken
+        len = requestInfo->info.tokenLength;
+
+        g_clientToken = (char *) malloc(sizeof(char) * len);
+        if (NULL == g_clientToken)
+        {
+            LOGE("g_clientToken Out of memory");
+            free(g_clientEndpoint->resourceUri);
+            free(g_clientEndpoint);
+            return;
+        }
+
+        if (NULL != requestInfo->info.token)
+        {
+            memcpy(g_clientToken, requestInfo->info.token, len);
+            g_clientTokenLength = len;
+
+        }
+
+        //clone g_clientMsgId
+        g_clientMsgId = requestInfo->info.messageId;
+
+        if (NULL != requestInfo->info.payload)
+        {
+            len = strlen(requestInfo->info.payload);
+            char *clonePayload = (char *) malloc(sizeof(char) * (len + 1));
+
+            if (NULL == clonePayload)
+            {
+                LOGE("clonePayload Out of memory");
+                free(g_clientEndpoint->resourceUri);
+                free(g_clientEndpoint);
+                return;
+            }
+
+            memcpy(clonePayload, requestInfo->info.payload, len + 1);
+
+            callback("Data: ", clonePayload);
+            free(clonePayload);
+        }
     }
 
     if (requestInfo->info.options)
     {
         uint32_t len = requestInfo->info.numOptions;
         uint32_t i;
+
+        LOGI("Option count: %d", requestInfo->info.numOptions);
+
         for (i = 0; i < len; i++)
         {
-            LOGI("Option %d\n", i + 1);
-            LOGI("ID : %d\n", requestInfo->info.options[i].optionID);
-            LOGI("Data[%d]: %s\n", requestInfo->info.options[i].optionLength,
-                   requestInfo->info.options[i].optionData);
+            LOGI("Option %d", i + 1);
+            LOGI("ID : %d", requestInfo->info.options[i].optionID);
+            LOGI("Data[%d]: %s", requestInfo->info.options[i].optionLength,
+                 requestInfo->info.options[i].optionData);
 
             if (NULL != g_responseListenerObject)
             {
-                char tmpbuf[30];
-                sprintf(tmpbuf, "%d", i + 1);
-                callback("Option: ", tmpbuf);
-
-                sprintf(tmpbuf, "%d", requestInfo->info.options[i].optionID);
-                callback("ID: ", tmpbuf);
-
-                sprintf(tmpbuf, "Data:[%d]",  requestInfo->info.options[i].optionLength);
-                callback("tmpbuf: ", requestInfo->info.options[i].optionData);
+                char optionInfo[OPTION_INFO_LENGTH] = { 0, };
+                sprintf(optionInfo, "Num[%d] - ID : %d, Option Length : %d", i + 1,
+                        requestInfo->info.options[i].optionID,
+                        requestInfo->info.options[i].optionLength);
+
+                callback("Option info: ", optionInfo);
+
+                if (0 != requestInfo->info.options[i].optionData)
+                {
+                    uint32_t optionDataLen = strlen(requestInfo->info.options[i].optionData);
+                    char *cloneOptionData = (char *) malloc(sizeof(char) * (optionDataLen + 1));
+
+                    if (NULL == cloneOptionData)
+                    {
+                        LOGE("cloneOptionData Out of memory");
+                        free(g_clientEndpoint->resourceUri);
+                        free(g_clientEndpoint);
+                        return;
+                    }
+
+                    memcpy(cloneOptionData, requestInfo->info.options[i].optionData,
+                           optionDataLen + 1);
+
+                    callback("Option Data: ", cloneOptionData);
+                    free(cloneOptionData);
+                }
             }
         }
     }
-    LOGI("############################################################\n");
+    LOGI("############################################################");
 
     //Check if this has secure communication information
-    if (requestInfo->info.payload)
+    if (requestInfo->info.payload && CA_IPV4 == object->transportType)
     {
-        int securePort = get_secure_information(requestInfo->info.payload);
+        uint32_t securePort = get_secure_information(requestInfo->info.payload);
         if (0 < securePort) //Set the remote endpoint secure details and send response
         {
-            LOGI("This is secure resource...\n");
+            LOGI("This is secure resource...");
             char *uri = NULL;
             uint32_t length = 0;
 
             length = sizeof(SECURE_COAPS_PREFIX) - 1; //length of "coaps://"
-            length += strlen(object->addressInfo.IP.ipAddress) + PORT_LENGTH; // length of "ipaddress:port"
+            // length of "ipaddress:port"
+            length += strlen(object->addressInfo.IP.ipAddress) + PORT_LENGTH;
             length += strlen(object->resourceUri) + 1;
 
-            uri = calloc(1,sizeof(char)*length);
+            uri = calloc(1, sizeof(char) * length);
             if (!uri)
             {
-                LOGI("Failed to create new uri\n");
+                LOGE("Failed to create new uri");
+                free(uri);
                 return;
             }
-            sprintf(uri,"%s%s:%d/%s", SECURE_COAPS_PREFIX, object->addressInfo.IP.ipAddress,
-                      securePort, object->resourceUri);
+            sprintf(uri, "%s%s:%d/%s", SECURE_COAPS_PREFIX, object->addressInfo.IP.ipAddress,
+                    securePort, object->resourceUri);
 
             CARemoteEndpoint_t *endpoint = NULL;
             if (CA_STATUS_OK != CACreateRemoteEndpoint(uri, object->transportType, &endpoint))
             {
-                LOGI("Failed to create duplicate of remote endpoint!\n");
+                LOGE("Failed to create duplicate of remote endpoint!");
+                free(uri);
                 return;
             }
             endpoint->isSecured = true;
             object = endpoint;
+
+            free(uri);
         }
     }
-
-    g_received = 1;
-
 }
 
 void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* responseInfo)
 {
 
-    LOGI("##########Received response from remote device #############\n");
-    LOGI("Uri: %s\n", object->resourceUri);
-
-    if(object->transportType == CA_EDR)
-    {
-        LOGI("Remote Address: %s\n", object->addressInfo.BT.btMacAddress);
-    } else if(object->transportType == CA_LE)
-    {
-        LOGI("Remote Address: %s\n", object->addressInfo.LE.leMacAddress);
-    } else if(object->transportType == CA_IPV4)
+    CAResult_t res = get_remote_address(object->transportType, object->addressInfo);
+    if (CA_STATUS_OK != res)
     {
-        LOGI("Remote Address: %s\n", object->addressInfo.IP.ipAddress);
+        return;
     }
 
-    LOGI("response result: %d\n", responseInfo->result);
-    LOGI("Data: %s\n", responseInfo->info.payload);
+    LOGI("##########Received response from remote device #############");
+    LOGI("Uri: %s", object->resourceUri);
+    LOGI("Remote Address: %s", g_remoteAddress);
+    LOGI("response result: %d", responseInfo->result);
+    LOGI("Data: %s", responseInfo->info.payload);
+    LOGI("Token: %s", responseInfo->info.token);
+    LOGI("MessageType: %d", responseInfo->info.type);
 
     if (NULL != g_responseListenerObject)
     {
-        callback("received response from remote device", "#######");
-        callback("Uri: ", object->resourceUri);
+        uint32_t len = 0;
 
-        if(object->transportType == CA_EDR)
-        {
-            callback("Remote Address: ", (char*) object->addressInfo.BT.btMacAddress);
-        } else if(object->transportType == CA_LE)
+        if (NULL != object->resourceUri)
         {
-            callback("Remote Address: ", (char*) object->addressInfo.LE.leMacAddress);
-        } else if(object->transportType == CA_IPV4)
+            len = strlen(object->resourceUri);
+            char *cloneUri = (char *) malloc(sizeof(char) * (len + 1));
+
+            if (NULL == cloneUri)
+            {
+                LOGE("cloneUri Out of memory");
+                free(g_remoteAddress);
+                return;
+            }
+
+            memcpy(cloneUri, object->resourceUri, len + 1);
+
+            callback("Uri: ", cloneUri);
+            free(cloneUri);
+        }
+
+        len = strlen(g_remoteAddress);
+        char *cloneRemoteAddress = (char *) malloc(sizeof(char) * (len + 1));
+
+        if (NULL == cloneRemoteAddress)
         {
-            callback("Remote Address: ", (char*) object->addressInfo.IP.ipAddress);
+            LOGE("cloneRemoteAddress Out of memory");
+            free(g_remoteAddress);
+            return;
         }
 
-        if(responseInfo->info.payload)
+        memcpy(cloneRemoteAddress, g_remoteAddress, len + 1);
+
+        callback("Remote Address: ", cloneRemoteAddress);
+        free(cloneRemoteAddress);
+        free(g_remoteAddress);
+
+        if (NULL != responseInfo->info.payload)
         {
-            callback("Data: ", responseInfo->info.payload);
+            len = strlen(responseInfo->info.payload);
+            char *clonePayload = (char *) malloc(sizeof(char) * (len + 1));
+
+            if (NULL == clonePayload)
+            {
+                LOGE("clonePayload Out of memory");
+                return;
+            }
+
+            memcpy(clonePayload, responseInfo->info.payload, len + 1);
+
+            callback("Data: ", clonePayload);
+            free(clonePayload);
         }
     }
 
@@ -766,40 +1116,52 @@ void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t*
         uint32_t i;
         for (i = 0; i < len; i++)
         {
-            LOGI("Option %d\n", i + 1);
-            LOGI("ID : %d\n", responseInfo->info.options[i].optionID);
-            LOGI("Data[%d]: %s\n", responseInfo->info.options[i].optionLength,
-                      responseInfo->info.options[i].optionData);
+            LOGI("Option %d", i + 1);
+            LOGI("ID : %d", responseInfo->info.options[i].optionID);
+            LOGI("Data[%d]: %s", responseInfo->info.options[i].optionLength,
+                 responseInfo->info.options[i].optionData);
 
             if (NULL != g_responseListenerObject)
             {
-                char tmpbuf[30];
-                sprintf(tmpbuf, "%d", i + 1);
-                callback("Option: ", tmpbuf);
-
-                sprintf(tmpbuf, "%d", responseInfo->info.options[i].optionID);
-                callback("ID: ", tmpbuf);
-
-                sprintf(tmpbuf, "Data:[%d]",  responseInfo->info.options[i].optionLength);
-                callback("tmpbuf: ", responseInfo->info.options[i].optionData);
+                char optionInfo[OPTION_INFO_LENGTH] = { 0, };
+                sprintf(optionInfo, "Num[%d] - ID : %d, Option Length : %d", i + 1,
+                        responseInfo->info.options[i].optionID,
+                        responseInfo->info.options[i].optionLength);
+
+                callback("Option info: ", optionInfo);
+
+                if (0 != responseInfo->info.options[i].optionData)
+                {
+                    uint32_t optionDataLen = strlen(responseInfo->info.options[i].optionData);
+                    char *cloneOptionData = (char *) malloc(sizeof(char) * (optionDataLen + 1));
+
+                    if (NULL == cloneOptionData)
+                    {
+                        LOGE("cloneOptionData Out of memory");
+                        return;
+                    }
+                    memcpy(cloneOptionData, responseInfo->info.options[i].optionData,
+                           optionDataLen + 1);
+                    callback("Option Data: ", cloneOptionData);
+                    free(cloneOptionData);
+                }
             }
         }
     }
-    LOGI("############################################################\n");
-    g_received = 1;
+    LOGI("############################################################");
 
     //Check if this has secure communication information
-    if (responseInfo->info.payload)
+    if (responseInfo->info.payload && CA_IPV4 == object->transportType)
     {
-        int securePort = get_secure_information(responseInfo->info.payload);
+        uint32_t securePort = get_secure_information(responseInfo->info.payload);
         if (0 < securePort) //Set the remote endpoint secure details and send response
         {
-            LOGI("This is secure resource...\n");
+            LOGI("This is secure resource...");
         }
     }
 }
 
-void get_resource_uri(const char *URI, char *resourceURI, int length)
+void get_resource_uri(const char *URI, char *resourceURI, uint32_t length)
 {
     const char *startPos = URI;
     const char *temp = NULL;
@@ -808,7 +1170,7 @@ void get_resource_uri(const char *URI, char *resourceURI, int length)
         startPos = strchr(temp + 3, '/');
         if (!startPos)
         {
-            LOGI("Resource URI is missing\n");
+            LOGE("Resource URI is missing");
             return;
         }
     }
@@ -821,59 +1183,61 @@ void get_resource_uri(const char *URI, char *resourceURI, int length)
     --endPos;
 
     if (endPos - startPos <= length)
+    {
         memcpy(resourceURI, startPos + 1, endPos - startPos);
+    }
 
-    LOGI("URI: %s, ResourceURI:%s\n", URI, resourceURI);
+    LOGI("URI: %s, ResourceURI: %s", URI, resourceURI);
 }
 
-int get_secure_information(CAPayload_t payLoad)
+uint32_t get_secure_information(CAPayload_t payLoad)
 {
-    LOGI("entering get_secure_information\n");
+    LOGI("entering get_secure_information");
 
     if (!payLoad)
     {
-        LOGI("Payload is NULL\n");
+        LOGE("Payload is NULL");
         return -1;
     }
 
     const char *subString = NULL;
     if (NULL == (subString = strstr(payLoad, "\"sec\":1")))
     {
-        LOGI("This is not secure resource\n");
+        LOGE("This is not secure resource");
         return -1;
     }
 
     if (NULL == (subString = strstr(payLoad, "\"port\":")))
     {
-        LOGI("This secure resource does not have port information\n");
+        LOGE("This secure resource does not have port information");
         return -1;
     }
 
     const char *startPos = strstr(subString, ":");
     if (!startPos)
     {
-        LOGI("Parsing failed !\n");
+        LOGE("Parsing failed !");
         return -1;
     }
 
     const char *endPos = strstr(startPos, "}");
     if (!endPos)
     {
-        LOGI("Parsing failed !\n");
+        LOGE("Parsing failed !");
         return -1;
     }
 
-    char portStr[6] = {0};
-    memcpy(portStr, startPos + 1, (endPos-1) - startPos);
+    char portStr[6] = { 0 };
+    memcpy(portStr, startPos + 1, (endPos - 1) - startPos);
 
-    LOGI("secured port is: %s\n", portStr);
+    LOGI("secured port is: %s", portStr);
     return atoi(portStr);
 }
 
-CAResult_t get_network_type(int selectedNetwork)
+CAResult_t get_network_type(uint32_t selectedNetwork)
 {
 
-    int number = selectedNetwork;
+    uint32_t number = selectedNetwork;
 
     if (!(number & 0xf))
     {
@@ -898,17 +1262,67 @@ CAResult_t get_network_type(int selectedNetwork)
     return CA_NOT_SUPPORTED;
 }
 
-void callback(char *subject, char *receicedData)
+void callback(char *subject, char *receivedData)
 {
     JNIEnv* env = NULL;
-    int status = (*g_jvm)->GetEnv(g_jvm, (void **) &env, JNI_VERSION_1_6);
-    int res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
+    uint32_t status = (*g_jvm)->GetEnv(g_jvm, (void **) &env, JNI_VERSION_1_6);
+    uint32_t res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
 
     jclass cls = (*env)->GetObjectClass(env, g_responseListenerObject);
     jmethodID mid = (*env)->GetMethodID(env, cls, "OnResponseReceived",
-        "(Ljava/lang/String;Ljava/lang/String;)V");
+                                        "(Ljava/lang/String;Ljava/lang/String;)V");
 
-    jstring jsubject = (*env)->NewStringUTF(env, (char*)subject);
-    jstring jreceivedData = (*env)->NewStringUTF(env, (char*)receicedData);
+    jstring jsubject = (*env)->NewStringUTF(env, (char*) subject);
+    jstring jreceivedData = (*env)->NewStringUTF(env, (char*) receivedData);
     (*env)->CallVoidMethod(env, g_responseListenerObject, mid, jsubject, jreceivedData);
+
+}
+
+CAResult_t get_remote_address(CATransportType_t transportType, CAAddress_t addressInfo)
+{
+
+    uint32_t len = 0;
+    if (CA_IPV4 == transportType)
+    {
+        len = strlen(addressInfo.IP.ipAddress);
+        g_remoteAddress = (char *) malloc(sizeof(char) * (len + 1));
+
+        if (NULL == g_remoteAddress)
+        {
+            LOGE("g_remoteAddress Out of memory");
+            return CA_MEMORY_ALLOC_FAILED;
+        }
+
+        memcpy(g_remoteAddress, addressInfo.IP.ipAddress, len + 1);
+    }
+
+    else if (CA_EDR == transportType)
+    {
+        len = strlen(addressInfo.BT.btMacAddress);
+        g_remoteAddress = (char *) malloc(sizeof(char) * (len + 1));
+
+        if (NULL == g_remoteAddress)
+        {
+            LOGE("g_remoteAddress Out of memory");
+            return CA_MEMORY_ALLOC_FAILED;
+        }
+
+        memcpy(g_remoteAddress, addressInfo.BT.btMacAddress, len + 1);
+    }
+
+    else if (CA_LE == transportType)
+    {
+        len = strlen(addressInfo.LE.leMacAddress);
+        g_remoteAddress = (char *) malloc(sizeof(char) * (len + 1));
+
+        if (NULL == g_remoteAddress)
+        {
+            LOGE("g_remoteAddress Out of memory");
+            return CA_MEMORY_ALLOC_FAILED;
+        }
+
+        memcpy(g_remoteAddress, addressInfo.LE.leMacAddress, len + 1);
+    }
+
+    return CA_STATUS_OK;
 }
index 2bbabd1..25ce793 100644 (file)
@@ -54,7 +54,7 @@
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_below="@id/layout_mode" >
-
+                        
             <TextView
                 android:id="@+id/tv_find"
                 android:layout_width="fill_parent"
                 android:id="@+id/tv_request"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:text="[Send Request]"
-                />
+                android:text="[Send Request]" />
 
          </RelativeLayout>
 
-         <RelativeLayout
-            android:id="@+id/layout_request_setting_for_client"
+        <RelativeLayout
+            android:id="@+id/layout_request"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_below="@id/layout_request_title" >
 
-            <Button
-                android:id="@+id/btn_Request_setting_for_client"
+            <EditText
+                android:id="@+id/et_req_data"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:text="@string/request_setting" />
+                android:layout_centerVertical="true"
+                android:text="@string/req_data" />
         </RelativeLayout>
 
         <RelativeLayout
-            android:id="@+id/layout_request"
+            android:id="@+id/layout_payload_client_ed"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@id/layout_request_setting_for_client" >
+            android:layout_below="@id/layout_request" >
+
+            <EditText
+                android:id="@+id/et_payload_data"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_centerVertical="true"
+                android:text="@string/payload_data_client" />
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_request_setting_for_client"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_payload_client_ed" >
 
             <Button
                 android:id="@+id/btn_Request"
                 android:layout_alignParentRight="true"
                 android:text="@string/request" />
 
-            <EditText
-                android:id="@+id/et_req_data"
+            <Button
+                android:id="@+id/btn_Request_setting_for_client"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:layout_centerVertical="true"
                 android:layout_toLeftOf="@id/btn_Request"
-                android:text="@string/req_data" />
+                android:text="@string/request_setting" />
         </RelativeLayout>
 
         <RelativeLayout
-            android:id="@+id/layout_payload_client_ed"
+            android:id="@+id/layout_request_to_all_title"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@id/layout_request" >
+            android:layout_below="@id/layout_request_setting_for_client" >
+
+            <TextView
+                android:id="@+id/tv_request_to_all"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content" 
+                android:text="[Send Request to All]"
+                />
+
+         </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_request_to_all"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_request_to_all_title" >
 
             <EditText
-                android:id="@+id/et_payload_data"
+                android:id="@+id/et_req_to_all_data"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_centerVertical="true"
-                android:text="@string/payload_data_client" />
-
+                android:text="@string/uri" />
         </RelativeLayout>
 
         <RelativeLayout
-            android:id="@+id/layout_handle_title"
+            android:id="@+id/layout_request_to_all_setting_for_client"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@id/layout_advertise_resource" >
+            android:layout_below="@id/layout_request_to_all" >
 
-        <TextView
-                android:id="@+id/tv_handle"
-                android:layout_width="fill_parent"
+            <Button
+                android:id="@+id/btn_request_to_all"
+                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="[Handle Reqeust/Response data]"
-                />
+                android:layout_alignParentRight="true"
+                android:text="@string/request_to_all" />
 
+            <Button
+                android:id="@+id/btn_request_to_all_setting_for_client"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_toLeftOf="@id/btn_request_to_all"
+                android:text="@string/request_setting" />
         </RelativeLayout>
 
         <RelativeLayout
-            android:id="@+id/layout_receive"
+            android:id="@+id/layout_handle_title"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@id/layout_handle_title" >
+            android:layout_below="@id/layout_request_to_all_setting_for_client" >
 
-            <Button
-                android:id="@+id/btn_receive"
+            <TextView
+                android:id="@+id/tv_handle"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:text="@string/receive" />
+                android:text="[Handle Reqeust,Response data / Get NetworkInfo]"/>
         </RelativeLayout>
 
         <RelativeLayout
-            android:id="@+id/layout_received"
+            android:id="@+id/layout_receive"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@id/layout_receive" >
+            android:layout_below="@id/layout_handle_title" >
 
-            <TextView
-                android:id="@+id/tv_rev_text"
+            <Button
+                android:id="@+id/btn_get_network_info"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:visibility="invisible"
-                android:text="@string/received" />
-
-            <TextView
-                android:id="@+id/tv_ble_received"
+                android:layout_alignParentRight="true"
+                android:text="@string/get_network_info" />
+            <Button
+                android:id="@+id/btn_receive"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:layout_toRightOf="@id/tv_rev_text"
-                android:visibility="invisible"
-                android:text="@string/received" />
+                android:layout_toLeftOf="@id/btn_get_network_info"
+                android:text="@string/receive" />
         </RelativeLayout>
     </RelativeLayout>
 
index 087c756..f75b6be 100644 (file)
@@ -1,17 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-    <string name="app_name">sample_service</string>
+    <string name="app_name">CA Android Sample</string>
     <string name="find">Find</string>
     <string name="sendresponse">Send Response</string>
     <string name="notify">Send Notification</string>
     <string name="advertise">Advertise</string>
     <string name="request_setting">Request Setting</string>
     <string name="request">Request</string>
+    <string name="request_to_all">Request to All</string>
     <string name="response">Response</string>
     <string name="uri">/a/light</string>
     <string name="notification"></string>
     <string name="req_data"></string>
     <string name="resp_data">resourceUri/response</string>
+    <string name="get_network_info">Network Info</string>
     <string name="receive">Receive</string>
     <string name="received">Received Message</string>
     <string name="action_settings">Settings</string>
index 370a0da..fc321cb 100644 (file)
@@ -1,7 +1,5 @@
 package org.iotivity.service;
 
-import java.util.ArrayList;
-
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
@@ -24,34 +22,53 @@ public class MainActivity extends Activity {
 
     private final static String TAG = "MainActivity";
 
-    private final CharSequence[] mCheckBoxItems = { Network.WIFI.name(),
-            Network.EDR.name(), Network.LE.name() };
+    private final CharSequence[] mNetworkCheckBoxItems = { Network.IPV4.name(),
+            Network.IPV6.name(), Network.EDR.name(), Network.LE.name()};
 
-    private final CharSequence[] mDTLSCheckBoxItems = { DTLS.SECURED.name(),
-            DTLS.UNSECURED.name() };
+    private final CharSequence[] mDTLSCheckBoxItems = { DTLS.UNSECURED.name(),
+            DTLS.SECURED.name() };
 
     private final CharSequence[] mMsgTyleCheckBoxItems = { MsgType.CON.name(),
-            MsgType.NON.name() };
+            MsgType.NON.name(), MsgType.ACK.name(), MsgType.RESET.name() };
+
+    private final CharSequence[] mResponseResultCheckBoxItems = {
+            ResponseResult.CA_SUCCESS.name(), ResponseResult.CA_CREATED.name(),
+            ResponseResult.CA_DELETED.name(), ResponseResult.CA_EMPTY.name(),
+            ResponseResult.CA_BAD_REQ.name(), ResponseResult.CA_BAD_OPT.name(),
+            ResponseResult.CA_NOT_FOUND.name(),
+            ResponseResult.CA_INTERNAL_SERVER_ERROR.name(),
+            ResponseResult.CA_RETRANSMIT_TIMEOUT.name() };
 
     private enum Mode {
         SERVER, CLIENT, BOTH, UNKNOWN
     };
 
     private enum Network {
-        WIFI, EDR, LE
+        IPV4, IPV6, EDR, LE
     };
 
     private enum DTLS {
-        SECURED, UNSECURED
+        UNSECURED, SECURED
     };
 
     private enum MsgType {
-        CON, NON
+        CON, NON, ACK, RESET
     };
 
-    private Mode mCurrentMode = Mode.UNKNOWN;
+    private enum ResponseResult {
+        CA_SUCCESS, CA_CREATED, CA_DELETED, CA_EMPTY, CA_BAD_REQ, CA_BAD_OPT,
+        CA_NOT_FOUND, CA_INTERNAL_SERVER_ERROR, CA_RETRANSMIT_TIMEOUT
+    }
+
+    private boolean mCheckedItems[] = {
+            false, false, false, false
+    };
+
+    private int mSelectedItems[] = { 0, 0, 0, 0 };
 
-    private ArrayList<Integer> mSelectedItems = new ArrayList<Integer>();
+    private int mUnSelectedItems[] = { 0, 0, 0, 0 };
+
+    private Mode mCurrentMode = Mode.UNKNOWN;
 
     private RelativeLayout mFindResourceLayout = null;
 
@@ -59,8 +76,12 @@ public class MainActivity extends Activity {
 
     private RelativeLayout mSendRequestLayout = null;
 
+    private RelativeLayout mSendRequestToAllLayout = null;
+
     private RelativeLayout mSendRequestSettingLayout = null;
 
+    private RelativeLayout mSendRequestToAllSettingLayout = null;
+
     private RelativeLayout mSendResponseNotiSettingLayout = null;
 
     private RelativeLayout mReceiveLayout = null;
@@ -69,6 +90,8 @@ public class MainActivity extends Activity {
 
     private RelativeLayout mRequestTitleLayout = null;
 
+    private RelativeLayout mRequestToAllTitleLayout = null;
+
     private RelativeLayout mResponseNotificationTitleLayout = null;
 
     private RelativeLayout mAdvertiseTitleLayout = null;
@@ -93,8 +116,12 @@ public class MainActivity extends Activity {
 
     private EditText mReqData_ed = null;
 
+    private EditText mReqToAllData_ed = null;
+
     private EditText mPayload_ed = null;
 
+    private EditText mAdvertise_ed = null;
+
     private Button mFind_btn = null;
 
     private Button mNotify_btn = null;
@@ -105,10 +132,16 @@ public class MainActivity extends Activity {
 
     private Button mReqeust_setting_btn = null;
 
+    private Button mReqeustToAll_btn = null;
+
+    private Button mReqeustToAll_setting_btn = null;
+
     private Button mResponse_Notify_setting_btn = null;
 
     private Button mResponse_btn = null;
 
+    private Button mGetNetworkInfo_btn = null;
+
     private Button mRecv_btn = null;
 
     private Handler mLogHandler = null;
@@ -116,16 +149,24 @@ public class MainActivity extends Activity {
     /**
      * Defined ConnectivityType in cacommon.c
      *
-     * CA_ETHERNET = (1 << 0) CA_WIFI = (1 << 1) CA_EDR = (1 << 2) CA_LE = (1 <<
-     * 3)
+     * CA_IPV4 = (1 << 0) CA_IPV6 = (1 << 1) CA_EDR = (1 << 2) CA_LE = (1 << 3)
      */
-    private int CA_WIFI = (1 << 1);
+    private int CA_IPV4 = (1 << 0);
+    private int CA_IPV6 = (1 << 1);
     private int CA_EDR = (1 << 2);
     private int CA_LE = (1 << 3);
     private int isSecured = 0;
-    private int msgType = 0;
-    private int selectedItem = 0;
-    int selectedNetwork = 0;
+    private int msgType = 1;
+    private int responseValue = 0;
+    private int selectedNetworkType = -1;
+    private int selectedMsgType = 1;
+    private int selectedMsgSecured = 0;
+    private int selectedResponseValue = 0;
+    int selectedNetwork = -1;
+    int interestedNetwork = 0;
+    int uninterestedNetwork = 0;
+    private boolean isSendResponseSetting = false;
+    private boolean isSendRequestToAllSetting = false;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -144,17 +185,22 @@ public class MainActivity extends Activity {
 
         // client
         mSendRequestLayout = (RelativeLayout) findViewById(R.id.layout_request);
+        mSendRequestToAllLayout = (RelativeLayout) findViewById(R.id.layout_request_to_all);
         mSendRequestSettingLayout = (RelativeLayout)
                 findViewById(R.id.layout_request_setting_for_client);
+        mSendRequestToAllSettingLayout = (RelativeLayout)
+                findViewById(R.id.layout_request_to_all_setting_for_client);
         mFindResourceLayout = (RelativeLayout) findViewById(R.id.layout_find);
         mFindTitleLayout = (RelativeLayout) findViewById(R.id.layout_find_title);
         mRequestTitleLayout = (RelativeLayout) findViewById(R.id.layout_request_title);
+        mRequestToAllTitleLayout = (RelativeLayout) findViewById(R.id.layout_request_to_all_title);
         mHandleTitleLayout = (RelativeLayout) findViewById(R.id.layout_handle_title);
         mPayLoadClientEditLayout = (RelativeLayout) findViewById(R.id.layout_payload_client_ed);
 
         // server
         mSendNotificationLayout = (RelativeLayout) findViewById(R.id.layout_notify);
-        mPayLoadServerEditLayout = (RelativeLayout) findViewById(R.id.layout_payload_server_ed);
+        mPayLoadServerEditLayout = (RelativeLayout)
+                findViewById(R.id.layout_payload_server_ed);
         mSendResponseNotiSettingLayout = (RelativeLayout)
                 findViewById(R.id.layout_request_setting_for_server);
         mServerButtonLayout = (RelativeLayout) findViewById(R.id.layout_server_bt);
@@ -169,7 +215,9 @@ public class MainActivity extends Activity {
         mUri_ed = (EditText) findViewById(R.id.et_uri);
         mNotification_ed = (EditText) findViewById(R.id.et_notification);
         mReqData_ed = (EditText) findViewById(R.id.et_req_data);
+        mReqToAllData_ed = (EditText) findViewById(R.id.et_req_to_all_data);
         mPayload_ed = (EditText) findViewById(R.id.et_payload_data_for_server);
+        mAdvertise_ed = (EditText) findViewById(R.id.et_uri_advertise);
 
         mFind_btn = (Button) findViewById(R.id.btn_find_resource);
         mResponse_btn = (Button) findViewById(R.id.btn_sendresponse);
@@ -177,8 +225,11 @@ public class MainActivity extends Activity {
         mAdvertiseResource_btn = (Button) findViewById(R.id.btn_advertise);
         mReqeust_btn = (Button) findViewById(R.id.btn_Request);
         mReqeust_setting_btn = (Button) findViewById(R.id.btn_Request_setting_for_client);
-        mResponse_Notify_setting_btn = (Button)
-                findViewById(R.id.btn_Request_setting_for_server);
+        mReqeustToAll_btn = (Button) findViewById(R.id.btn_request_to_all);
+        mReqeustToAll_setting_btn = (Button)
+                findViewById(R.id.btn_request_to_all_setting_for_client);
+        mResponse_Notify_setting_btn = (Button) findViewById(R.id.btn_Request_setting_for_server);
+        mGetNetworkInfo_btn = (Button) findViewById(R.id.btn_get_network_info);
         mRecv_btn = (Button) findViewById(R.id.btn_receive);
 
         mFind_btn.setOnClickListener(mFindResourceHandler);
@@ -187,16 +238,18 @@ public class MainActivity extends Activity {
         mAdvertiseResource_btn.setOnClickListener(mAdvertiseResourceHandler);
         mReqeust_btn.setOnClickListener(mSendRequestHandler);
         mReqeust_setting_btn.setOnClickListener(mSendRequestSettingHandler);
+        mReqeustToAll_btn.setOnClickListener(mSendRequestToAllHandler);
+        mReqeustToAll_setting_btn.setOnClickListener(mSendRequestToAllSettingHandler);
         mResponse_Notify_setting_btn
                 .setOnClickListener(mSendResponseNotiSettingHandler);
         mRecv_btn.setOnClickListener(mResponseHandler);
+        mGetNetworkInfo_btn.setOnClickListener(mGetNetworkInfoHandler);
 
         showSelectModeView();
 
         // Initialize Connectivity Abstraction
         RM.RMInitialize(getApplicationContext());
-        // Select default network(WIFI)
-        RM.RMSelectNetwork(CA_WIFI);
+
         // set handler
         RM.RMRegisterHandler();
     }
@@ -206,10 +259,13 @@ public class MainActivity extends Activity {
         mFindResourceLayout.setVisibility(View.INVISIBLE);
         mSendNotificationLayout.setVisibility(View.INVISIBLE);
         mSendRequestLayout.setVisibility(View.INVISIBLE);
+        mSendRequestToAllLayout.setVisibility(View.INVISIBLE);
         mSendRequestSettingLayout.setVisibility(View.INVISIBLE);
+        mSendRequestToAllSettingLayout.setVisibility(View.INVISIBLE);
         mReceiveLayout.setVisibility(View.INVISIBLE);
         mFindTitleLayout.setVisibility(View.INVISIBLE);
         mRequestTitleLayout.setVisibility(View.INVISIBLE);
+        mRequestToAllTitleLayout.setVisibility(View.INVISIBLE);
         mHandleTitleLayout.setVisibility(View.INVISIBLE);
         mPayLoadClientEditLayout.setVisibility(View.INVISIBLE);
         mPayLoadServerEditLayout.setVisibility(View.INVISIBLE);
@@ -234,11 +290,14 @@ public class MainActivity extends Activity {
             mFindResourceLayout.setVisibility(View.INVISIBLE);
             mSendNotificationLayout.setVisibility(View.VISIBLE);
             mSendRequestLayout.setVisibility(View.INVISIBLE);
+            mSendRequestToAllLayout.setVisibility(View.INVISIBLE);
             mSendRequestSettingLayout.setVisibility(View.INVISIBLE);
+            mSendRequestToAllSettingLayout.setVisibility(View.INVISIBLE);
             mReceiveLayout.setVisibility(View.VISIBLE);
 
             mFindTitleLayout.setVisibility(View.INVISIBLE);
             mRequestTitleLayout.setVisibility(View.INVISIBLE);
+            mRequestToAllTitleLayout.setVisibility(View.INVISIBLE);
             mHandleTitleLayout.setVisibility(View.VISIBLE);
             mPayLoadClientEditLayout.setVisibility(View.INVISIBLE);
 
@@ -258,11 +317,14 @@ public class MainActivity extends Activity {
             mFindResourceLayout.setVisibility(View.VISIBLE);
             mSendNotificationLayout.setVisibility(View.INVISIBLE);
             mSendRequestLayout.setVisibility(View.VISIBLE);
+            mSendRequestToAllLayout.setVisibility(View.VISIBLE);
             mSendRequestSettingLayout.setVisibility(View.VISIBLE);
+            mSendRequestToAllSettingLayout.setVisibility(View.VISIBLE);
             mReceiveLayout.setVisibility(View.VISIBLE);
 
             mFindTitleLayout.setVisibility(View.VISIBLE);
             mRequestTitleLayout.setVisibility(View.VISIBLE);
+            mRequestToAllTitleLayout.setVisibility(View.VISIBLE);
             mHandleTitleLayout.setVisibility(View.VISIBLE);
             mPayLoadClientEditLayout.setVisibility(View.VISIBLE);
 
@@ -307,7 +369,7 @@ public class MainActivity extends Activity {
 
             RM.RMStartListeningServer();
 
-            if (mSelectedItems.size() == 0) {
+            if (interestedNetwork == 0) {
                 mCurrentMode = Mode.SERVER;
                 mMode_tv.setText("MODE: " + mCurrentMode.toString());
                 showNetworkView();
@@ -324,7 +386,7 @@ public class MainActivity extends Activity {
 
             RM.RMStartDiscoveryServer();
 
-            if (mSelectedItems.size() == 0) {
+            if (interestedNetwork == 0) {
                 mCurrentMode = Mode.CLIENT;
                 mMode_tv.setText("MODE: " + mCurrentMode.toString());
                 showNetworkView();
@@ -339,7 +401,7 @@ public class MainActivity extends Activity {
 
         case 3:
 
-            showAlertDialog("Select Network");
+            checkInterestedNetwork("Select Network");
 
             break;
         }
@@ -364,9 +426,12 @@ public class MainActivity extends Activity {
         public void onClick(View v) {
 
             DLog.v(TAG, "SendResponse click");
-            RM.RMSendResponse(mNotification_ed.getText().toString(),
-                    mPayload_ed.getText().toString(), selectedNetwork,
-                    isSecured);
+            if ( selectedNetwork != -1) {
+                RM.RMSendResponse(selectedNetwork, isSecured, msgType, responseValue);
+            }
+            else {
+                DLog.v(TAG, "Please Select Network Type");
+            }
         }
     };
 
@@ -376,9 +441,14 @@ public class MainActivity extends Activity {
         public void onClick(View v) {
 
             DLog.v(TAG, "SendNotification click");
-            RM.RMSendNotification(mNotification_ed.getText().toString(),
+            if ( selectedNetwork != -1) {
+                RM.RMSendNotification(mNotification_ed.getText().toString(),
                     mPayload_ed.getText().toString(), selectedNetwork,
-                    isSecured);
+                    isSecured, msgType, responseValue);
+            }
+            else {
+                DLog.v(TAG, "Please Select Network Type");
+            }
         }
     };
 
@@ -388,8 +458,7 @@ public class MainActivity extends Activity {
         public void onClick(View v) {
 
             DLog.v(TAG, "AdvertiseResource click");
-            RM.RMAdvertiseResource(mNotification_ed.getText().toString(),
-                    selectedNetwork);
+            RM.RMAdvertiseResource(mAdvertise_ed.getText().toString());
         }
     };
 
@@ -399,8 +468,13 @@ public class MainActivity extends Activity {
         public void onClick(View v) {
 
             DLog.v(TAG, "SendRequest click");
-            RM.RMSendRequest(mReqData_ed.getText().toString(), mPayload_ed
+            if ( selectedNetwork != -1) {
+                RM.RMSendRequest(mReqData_ed.getText().toString(), mPayload_ed
                     .getText().toString(), selectedNetwork, isSecured, msgType);
+            }
+            else {
+                DLog.v(TAG, "Please Select Network Type");
+            }
         }
     };
 
@@ -408,9 +482,31 @@ public class MainActivity extends Activity {
 
         @Override
         public void onClick(View v) {
+            checkSendNetworkType("Select Send Network Type");
+        }
+    };
+
+    private OnClickListener mSendRequestToAllHandler = new OnClickListener() {
+
+        @Override
+        public void onClick(View v) {
+
+            DLog.v(TAG, "SendRequestToAll click");
+            if ( selectedNetwork != -1) {
+                RM.RMSendReqestToAll(mReqToAllData_ed.getText().toString(), selectedNetwork);
+            }
+            else {
+                DLog.v(TAG, "Please Select Network Type");
+            }
+        }
+    };
+
+    private OnClickListener mSendRequestToAllSettingHandler = new OnClickListener() {
 
-            checkMsgSecured("Select DTLS Type");
-            checkMsgType("Select Msg Type");
+        @Override
+        public void onClick(View v) {
+            isSendRequestToAllSetting = true;
+            checkSendNetworkType("Select Send Network Type");
         }
     };
 
@@ -418,8 +514,16 @@ public class MainActivity extends Activity {
 
         @Override
         public void onClick(View v) {
+            isSendResponseSetting = true;
+            checkSendNetworkType("Select Send Network Type");
+        }
+    };
+
+    private OnClickListener mGetNetworkInfoHandler = new OnClickListener() {
+        @Override
+        public void onClick(View v) {
 
-            checkMsgSecured("Select DTLS Type");
+            RM.RMGetNetworkInfomation();
         }
     };
 
@@ -432,11 +536,11 @@ public class MainActivity extends Activity {
         }
     };
 
-    private void showAlertDialog(String title) {
+    private void checkInterestedNetwork(String title) {
 
         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
         builder.setTitle(title)
-                .setMultiChoiceItems(mCheckBoxItems, null,
+                .setMultiChoiceItems(mNetworkCheckBoxItems, mCheckedItems,
                         new DialogInterface.OnMultiChoiceClickListener() {
 
                             @Override
@@ -445,12 +549,13 @@ public class MainActivity extends Activity {
 
                                 if (isChecked) {
 
-                                    mSelectedItems.add(which);
+                                    mSelectedItems[which] = 1;
+                                    mUnSelectedItems[which] = 0;
 
-                                } else if (mSelectedItems.contains(which)) {
+                                } else if (mSelectedItems[which] == 1) {
 
-                                    mSelectedItems.remove(Integer
-                                            .valueOf(which));
+                                    mSelectedItems[which] = 0;
+                                    mUnSelectedItems[which] = 1;
                                 }
                             }
                         })
@@ -459,27 +564,49 @@ public class MainActivity extends Activity {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
 
-                        int interestedNetwork = 0;
-
-                        for (int i = 0; i < mSelectedItems.size(); i++) {
+                        interestedNetwork = 0;
 
-                            if (mSelectedItems.get(i) == Network.WIFI.ordinal()) {
-                                interestedNetwork |= CA_WIFI;
-                            } else if (mSelectedItems.get(i) == Network.EDR
-                                    .ordinal()) {
-                                interestedNetwork |= CA_EDR;
-                            } else if (mSelectedItems.get(i) == Network.LE
-                                    .ordinal()) {
-                                interestedNetwork |= CA_LE;
+                        for (int i = 0; i < mSelectedItems.length; i++) {
+                            if (mSelectedItems[i] == 1) {
+                                if(i != 1)
+                                    interestedNetwork |= (1 << i);
+                                else
+                                    checkNotSupportedTransport("Not Supported Transport");
+                            }
+                        }
+                        if(0 != interestedNetwork)
+                            RM.RMSelectNetwork(interestedNetwork);
+
+                        uninterestedNetwork = 0;
+
+                        for (int i = 0; i < mUnSelectedItems.length; i++) {
+                            if (mUnSelectedItems[i] == 1) {
+                                if (i != 1)
+                                    uninterestedNetwork |= (1 << i);
+                                else
+                                    checkNotSupportedTransport("Not Supported Transport");
+                                mUnSelectedItems[i] = 0;
                             }
                         }
+                        if(0 != uninterestedNetwork)
+                            RM.RMUnSelectNetwork(uninterestedNetwork);
 
-                        RM.RMSelectNetwork(interestedNetwork);
-                        selectedNetwork = interestedNetwork;
                     }
                 }).show();
+    }
+
+    private void checkNotSupportedTransport(String title) {
 
-        mSelectedItems.clear();
+        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+        builder.setTitle(title).
+        setMessage("Selected Transport Not Supported")
+        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+
+            }
+        }).show();
     }
 
     private void checkMsgSecured(String title) {
@@ -487,13 +614,13 @@ public class MainActivity extends Activity {
         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
 
         builder.setTitle(title)
-                .setSingleChoiceItems(mDTLSCheckBoxItems, -1,
+                .setSingleChoiceItems(mDTLSCheckBoxItems, selectedMsgSecured,
                         new DialogInterface.OnClickListener() {
 
                             @Override
                             public void onClick(DialogInterface dialog,
                                     int which) {
-                                selectedItem = which;
+                                selectedMsgSecured = which;
                             }
                         })
                 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
@@ -501,7 +628,7 @@ public class MainActivity extends Activity {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
 
-                        if (selectedItem == DTLS.SECURED.ordinal()) {
+                        if (selectedMsgSecured == DTLS.SECURED.ordinal()) {
                             isSecured = 1;
                             DLog.v(TAG, "Send secured message");
 
@@ -511,7 +638,7 @@ public class MainActivity extends Activity {
                             mPayLoadServerEditLayout
                                     .setVisibility(View.INVISIBLE);
 
-                        } else if (selectedItem == DTLS.UNSECURED.ordinal()) {
+                        } else if (selectedMsgSecured == DTLS.UNSECURED.ordinal()) {
                             isSecured = 0;
                             DLog.v(TAG, "Send unsecured message");
 
@@ -523,6 +650,7 @@ public class MainActivity extends Activity {
                                         .setVisibility(View.VISIBLE);
                             }
                         }
+                        checkMsgType("Select Msg Type");
                     }
 
                 }).show();
@@ -532,13 +660,13 @@ public class MainActivity extends Activity {
 
         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
         builder.setTitle(title)
-                .setSingleChoiceItems(mMsgTyleCheckBoxItems, -1,
+                .setSingleChoiceItems(mMsgTyleCheckBoxItems, selectedMsgType,
                         new DialogInterface.OnClickListener() {
 
                             @Override
                             public void onClick(DialogInterface dialog,
                                     int which) {
-                                selectedItem = which;
+                                selectedMsgType = which;
                             }
                         })
                 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
@@ -546,15 +674,126 @@ public class MainActivity extends Activity {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
 
-                        if (selectedItem == MsgType.CON.ordinal()) {
+                        if (selectedMsgType == MsgType.CON.ordinal()) {
                             msgType = 0;
                             DLog.v(TAG, "Message Type is CON");
 
-                        } else if (selectedItem == MsgType.NON.ordinal()) {
+                        } else if (selectedMsgType == MsgType.NON.ordinal()) {
                             msgType = 1;
                             DLog.v(TAG, "Message Type is NON");
+                        } else if (selectedMsgType == MsgType.ACK.ordinal()) {
+                            msgType = 2;
+                            DLog.v(TAG, "Message Type is ACK");
+                        } else if (selectedMsgType == MsgType.RESET.ordinal()) {
+                            msgType = 3;
+                            DLog.v(TAG, "Message Type is RESET");
+                            }
+
+                        if (isSendResponseSetting == true && msgType != 3) {
+                            checkResponseResult("Select Value of Response Result");
+                            isSendResponseSetting = false;
+                        }
+                    }
+                }).show();
+    }
+
+    private void checkResponseResult(String title) {
+
+        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+        builder.setTitle(title)
+                .setSingleChoiceItems(mResponseResultCheckBoxItems, selectedResponseValue,
+                        new DialogInterface.OnClickListener() {
+
+                            @Override
+                            public void onClick(DialogInterface dialog,
+                                    int which) {
+                                selectedResponseValue = which;
+                            }
+                        })
+                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+
+                        if (selectedResponseValue == ResponseResult.CA_SUCCESS.ordinal()) {
+                            responseValue = 200;
+                            DLog.v(TAG, "Response Value is CA_SUCCESS");
+                        } else if (selectedResponseValue == ResponseResult.CA_CREATED
+                                .ordinal()) {
+                            responseValue = 201;
+                            DLog.v(TAG, "Response Value is CA_CREATED");
+                        } else if (selectedResponseValue == ResponseResult.CA_DELETED
+                                .ordinal()) {
+                            responseValue = 202;
+                            DLog.v(TAG, "Response Value is CA_DELETED");
+                        } else if (selectedResponseValue == ResponseResult.CA_EMPTY
+                                .ordinal()) {
+                            responseValue = 0;
+                            DLog.v(TAG, "Response Value is CA_EMPTY");
+                        } else if (selectedResponseValue == ResponseResult.CA_BAD_REQ
+                                .ordinal()) {
+                            responseValue = 400;
+                            DLog.v(TAG, "Response Value is CA_BAD_REQ");
+                        } else if (selectedResponseValue == ResponseResult.CA_BAD_OPT
+                                .ordinal()) {
+                            responseValue = 402;
+                            DLog.v(TAG, "Response Value is CA_BAD_OPT");
+                        } else if (selectedResponseValue == ResponseResult.CA_NOT_FOUND
+                                .ordinal()) {
+                            responseValue = 404;
+                            DLog.v(TAG, "Response Value is CA_NOT_FOUND");
+                        } else if (selectedResponseValue ==
+                                ResponseResult.CA_INTERNAL_SERVER_ERROR
+                                .ordinal()) {
+                            responseValue = 500;
+                            DLog.v(TAG, "Response Value is CA_INTERNAL_SERVER_ERROR");
+                        } else if (selectedResponseValue == ResponseResult.CA_RETRANSMIT_TIMEOUT
+                                .ordinal()) {
+                            responseValue = 504;
+                            DLog.v(TAG, "Response Value is CA_RETRANSMIT_TIMEOUT");
+                        }
+                    }
+                }).show();
+    }
+
+    private void checkSendNetworkType(String title) {
+        selectedNetworkType = -1;
+        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+
+        builder.setTitle(title)
+                .setSingleChoiceItems(mNetworkCheckBoxItems, -1,
+                        new DialogInterface.OnClickListener() {
+
+                            @Override
+                            public void onClick(DialogInterface dialog,
+                                    int which) {
+                                selectedNetworkType = which;
+                            }
+                        })
+                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+
+                        if (selectedNetworkType == Network.IPV4.ordinal()) {
+                            selectedNetwork = CA_IPV4;
+                            DLog.v(TAG, "Selected Network is CA_IPV4");
+                        } else if (selectedNetworkType == Network.EDR.ordinal()) {
+                            selectedNetwork = CA_EDR;
+                            DLog.v(TAG, "Selected Network is EDR");
+                        } else if (selectedNetworkType == Network.LE.ordinal()) {
+                            selectedNetwork = CA_LE;
+                            DLog.v(TAG, "Selected Network is LE");
+                        }
+                        else {
+                            DLog.v(TAG, "Selected Network is NULL");
+                            selectedNetwork = -1;
                         }
 
+                        if (isSendRequestToAllSetting != true) {
+                            checkMsgSecured("Select DTLS Type");
+                        }
+                        isSendRequestToAllSetting = false;
                     }
                 }).show();
     }
index d847554..b70c066 100644 (file)
@@ -7,9 +7,6 @@ public class RMInterface {
     static {
         // Load RI JNI interface
         System.loadLibrary("RMInterface");
-
-        // Load CA JNI interface
-        System.loadLibrary("CAInterface");
     }
 
     private org.iotivity.service.MainActivity mResponseListener = null;
@@ -31,17 +28,22 @@ public class RMInterface {
     public native void RMSendRequest(String uri, String payload,
             int selectedNetwork, int isSecured, int msgType);
 
-    public native void RMSendResponse(String uri, String payload,
-            int selectedNetwork, int isSecured);
+    public native void RMSendReqestToAll(String uri, int selectedNetwork);
+
+    public native void RMSendResponse(int selectedNetwork, int isSecured,
+            int msgType, int responseValue);
 
-    public native void RMAdvertiseResource(String advertiseResource,
-            int selectedNetwork);
+    public native void RMAdvertiseResource(String advertiseResource);
 
     public native void RMSendNotification(String uri, String payload,
-            int selectedNetwork, int isSecured);
+            int selectedNetwork, int isSecured, int msgType, int responseValue);
 
     public native void RMSelectNetwork(int interestedNetwork);
 
+    public native void RMUnSelectNetwork(int uninterestedNetwork);
+
+    public native void RMGetNetworkInfomation();
+
     public native void RMHandleRequestResponse();
 
     public void setResponseListener(org.iotivity.service.MainActivity listener) {
index 6f85445..c073b62 100644 (file)
 #include <string.h>
 #include <ctype.h>
 
+#ifdef __ANDROID__
+#include <jni.h>
+#endif
+
 #include "oic_malloc.h"
 #include "oic_string.h"
 
 #define CA_ADAPTER_UTILS_TAG "CA_ADAPTER_UTILS"
 
+#ifdef __ANDROID__
+/**
+ * @var g_jvm
+ * @brief pointer to store JavaVM
+ */
+static JavaVM *g_jvm = NULL;
+
+/**
+ * @var gContext
+ * @brief pointer to store context for android callback interface
+ */
+static jobject g_Context = NULL;
+#endif
+
 void CALogPDUData(coap_pdu_t *pdu)
 {
     VERIFY_NON_NULL_VOID(pdu, CA_ADAPTER_UTILS_TAG, "pdu");
@@ -553,3 +571,35 @@ void CAClearServerInfoList(u_arraylist_t *serverInfoList)
     }
     u_arraylist_free(&serverInfoList);
 }
+
+#ifdef __ANDROID__
+void CANativeJNISetContext(JNIEnv *env, jobject context)
+{
+    OIC_LOG_V(DEBUG, CA_ADAPTER_UTILS_TAG, "CANativeJNISetContext");
+
+    if (!context)
+    {
+        OIC_LOG(DEBUG, CA_ADAPTER_UTILS_TAG, "context is null");
+
+    }
+
+    g_Context = (*env)->NewGlobalRef(env, context);
+}
+
+void CANativeJNISetJavaVM(JavaVM *jvm)
+{
+    OIC_LOG_V(DEBUG, CA_ADAPTER_UTILS_TAG, "CANativeJNISetJavaVM");
+    g_jvm = jvm;
+}
+
+jobject CANativeJNIGetContext()
+{
+    return g_Context;
+}
+
+JavaVM *CANativeJNIGetJavaVM()
+{
+    return g_jvm;
+}
+#endif
+