#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);
}
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);
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.");
}
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.");
(*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;
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
}
}
-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;
}
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
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
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
// 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;
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;
}
// 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
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
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");
// 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);
}
}
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;
startPos = strchr(temp + 3, '/');
if (!startPos)
{
- LOGI("Resource URI is missing\n");
+ LOGE("Resource URI is missing");
return;
}
}
--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))
{
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;
}
package org.iotivity.service;
-import java.util.ArrayList;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
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;
private RelativeLayout mSendRequestLayout = null;
+ private RelativeLayout mSendRequestToAllLayout = null;
+
private RelativeLayout mSendRequestSettingLayout = null;
+ private RelativeLayout mSendRequestToAllSettingLayout = null;
+
private RelativeLayout mSendResponseNotiSettingLayout = null;
private RelativeLayout mReceiveLayout = null;
private RelativeLayout mRequestTitleLayout = null;
+ private RelativeLayout mRequestToAllTitleLayout = null;
+
private RelativeLayout mResponseNotificationTitleLayout = null;
private RelativeLayout mAdvertiseTitleLayout = null;
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;
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;
/**
* 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) {
// 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);
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);
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);
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();
}
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);
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);
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);
RM.RMStartListeningServer();
- if (mSelectedItems.size() == 0) {
+ if (interestedNetwork == 0) {
mCurrentMode = Mode.SERVER;
mMode_tv.setText("MODE: " + mCurrentMode.toString());
showNetworkView();
RM.RMStartDiscoveryServer();
- if (mSelectedItems.size() == 0) {
+ if (interestedNetwork == 0) {
mCurrentMode = Mode.CLIENT;
mMode_tv.setText("MODE: " + mCurrentMode.toString());
showNetworkView();
case 3:
- showAlertDialog("Select Network");
+ checkInterestedNetwork("Select Network");
break;
}
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");
+ }
}
};
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");
+ }
}
};
public void onClick(View v) {
DLog.v(TAG, "AdvertiseResource click");
- RM.RMAdvertiseResource(mNotification_ed.getText().toString(),
- selectedNetwork);
+ RM.RMAdvertiseResource(mAdvertise_ed.getText().toString());
}
};
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");
+ }
}
};
@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");
}
};
@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();
}
};
}
};
- 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
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;
}
}
})
@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) {
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() {
@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");
mPayLoadServerEditLayout
.setVisibility(View.INVISIBLE);
- } else if (selectedItem == DTLS.UNSECURED.ordinal()) {
+ } else if (selectedMsgSecured == DTLS.UNSECURED.ordinal()) {
isSecured = 0;
DLog.v(TAG, "Send unsecured message");
.setVisibility(View.VISIBLE);
}
}
+ checkMsgType("Select Msg Type");
}
}).show();
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() {
@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();
}