LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/oxm/\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/internal\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include\r
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include/internal\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/api\r
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/lib/libcoap-4.1.1\r
include $(BUILD_SHARED_LIBRARY)\r
#include "JniOcSecureResource.h"
#include "JniSecureUtils.h"
+#include "aclresource.h"
+#include "oic_malloc.h"
#include "oic_string.h"
namespace PH = std::placeholders;
JniOcSecureResource::JniOcSecureResource(std::shared_ptr<OCSecureResource> device)
: m_sharedSecureResource(device)
-{
-}
+{}
JniOcSecureResource::~JniOcSecureResource()
{
{
OCStackResult ret;
JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener);
- OicSecAcl_t *acl = new OicSecAcl_t;
+ OicSecAcl_t *acl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
if (!acl)
{
return OC_STACK_NO_MEMORY;
}
- acl->next = nullptr;
-
if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl, acl))
{
- delete acl;
+ DeleteACLList(acl);
return OC_STACK_ERROR;
}
ResultCallBack resultCallback = [acl, resultListener](PMResultList_t *result, int hasError)
{
- delete acl;
+ DeleteACLList(acl);
resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONACL);
};
ret = m_sharedSecureResource->provisionACL(acl, resultCallback);
if (ret != OC_STACK_OK)
{
- delete acl;
-
+ DeleteACLList(acl);
}
return ret;
}
if (_acl1)
{
- acl1 = new OicSecAcl_t;
+ acl1 = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
if (!acl1)
{
return OC_STACK_NO_MEMORY;
if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl1, acl1))
{
- delete acl1;
+ DeleteACLList(acl1);
return OC_STACK_ERROR;
}
- acl1->next = nullptr;
}
if (_acl2)
{
- acl2 = new OicSecAcl_t;
+ acl2 = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
if (!acl2)
{
- delete acl1;
+ DeleteACLList(acl1);
return OC_STACK_NO_MEMORY;
}
if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl2, acl2))
{
- delete acl2;
+ DeleteACLList(acl2);
return OC_STACK_ERROR;
}
- acl2->next = nullptr;
}
ResultCallBack resultCallback = [acl1, acl2, resultListener](PMResultList_t *result,
int hasError)
{
- delete acl1;
- delete acl2;
+ DeleteACLList(acl1);
+ DeleteACLList(acl2);
resultListener->ProvisionResultCallback(result, hasError,
ListenerFunc::PROVISIONPAIRWISEDEVICES);
};
*device2->getDevicePtr(), acl2, resultCallback);
if (ret != OC_STACK_OK)
{
- delete acl1;
- delete acl2;
+ DeleteACLList(acl1);
+ DeleteACLList(acl2);
}
return ret;
}
jclass g_cls_OcProvisionResult = nullptr;
jclass g_cls_OcSecureResource = nullptr;
jclass g_cls_OcOicSecAcl = nullptr;
+jclass g_cls_OcOicSecAcl_ace = nullptr;
+jclass g_cls_OcOicSecAcl_resr = nullptr;
+jclass g_cls_OcOicSecAcl_validity = nullptr;
jclass g_cls_OcOicSecPdAcl = nullptr;
jclass g_cls_OcDirectPairDevice = nullptr;
jmethodID g_mid_OcResourceResponse_N_ctor = nullptr;
jmethodID g_mid_OcResourceHandle_N_ctor = nullptr;
jmethodID g_mid_OcPresenceHandle_N_ctor = nullptr;
+
jmethodID g_mid_OcRequestHandle_N_ctor = nullptr;
jmethodID g_mid_OcHeaderOption_ctor = nullptr;
jmethodID g_mid_OcHeaderOption_get_id = nullptr;
jmethodID g_mid_OcDirectPairDevice_ctor = nullptr;
jmethodID g_mid_OcDirectPairDevice_dev_ctor = nullptr;
-jmethodID g_mid_OcOicSecAcl_get_subject = nullptr;
-jmethodID g_mid_OcOicSecAcl_get_resources_cnt = nullptr;
-jmethodID g_mid_OcOicSecAcl_get_resources = nullptr;
-jmethodID g_mid_OcOicSecAcl_get_permission = nullptr;
-jmethodID g_mid_OcOicSecAcl_get_periods_cnt = nullptr;
-jmethodID g_mid_OcOicSecAcl_get_periods = nullptr;
-jmethodID g_mid_OcOicSecAcl_get_recurrences = nullptr;
-jmethodID g_mid_OcOicSecAcl_get_rownerID = nullptr;
jmethodID g_mid_OcOicSecPdAcl_get_resources_cnt = nullptr;
jmethodID g_mid_OcOicSecPdAcl_get_resources = nullptr;
jmethodID g_mid_OcOicSecPdAcl_get_permission = nullptr;
jmethodID g_mid_OcOicSecPdAcl_get_periods = nullptr;
jmethodID g_mid_OcOicSecPdAcl_get_recurrences = nullptr;
+jmethodID g_mid_OcOicSecAcl_get_aces = nullptr;
+jmethodID g_mid_OcOicSecAcl_ace_get_subjectID = nullptr;
+jmethodID g_mid_OcOicSecAcl_ace_get_permissions = nullptr;
+jmethodID g_mid_OcOicSecAcl_ace_get_resources = nullptr;
+jmethodID g_mid_OcOicSecAcl_ace_get_validities = nullptr;
+jmethodID g_mid_OcOicSecAcl_resr_get_href = nullptr;
+jmethodID g_mid_OcOicSecAcl_resr_get_rel = nullptr;
+jmethodID g_mid_OcOicSecAcl_resr_get_types = nullptr;
+jmethodID g_mid_OcOicSecAcl_resr_get_typeLen = nullptr;
+jmethodID g_mid_OcOicSecAcl_resr_get_interfaces = nullptr;
+jmethodID g_mid_OcOicSecAcl_validity_get_getPeriod = nullptr;
+jmethodID g_mid_OcOicSecAcl_validity_get_recurrences = nullptr;
+jmethodID g_mid_OcOicSecAcl_validity_get_recurrenceLen = nullptr;
+jmethodID g_mid_OcOicSecAcl_resr_get_interfaceLen = nullptr;
+jmethodID g_mid_OcOicSecAcl_get_rownerID = nullptr;
+
jobject getOcException(JNIEnv* env, const char* file, const char* functionName,
const int line, const int code, const char* message)
{
g_cls_OcOicSecAcl = (jclass)env->NewGlobalRef(clazz);
env->DeleteLocalRef(clazz);
- g_mid_OcOicSecAcl_get_subject = env->GetMethodID(g_cls_OcOicSecAcl, "getSubject", "()Ljava/lang/String;");
- VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_subject);
+ g_mid_OcOicSecAcl_get_rownerID = env->GetMethodID(g_cls_OcOicSecAcl, "getRownerID", "()Ljava/lang/String;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_rownerID);
- g_mid_OcOicSecAcl_get_resources_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getResourcesCount", "()I");
- VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_resources_cnt);
+ g_mid_OcOicSecAcl_get_aces = env->GetMethodID(g_cls_OcOicSecAcl, "getOicSecAces", "()[Lorg/iotivity/base/OicSecAce;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_aces);
- g_mid_OcOicSecAcl_get_resources = env->GetMethodID(g_cls_OcOicSecAcl, "getResources", "(I)Ljava/lang/String;");
- VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_resources);
+ //OicSecAce
+ clazz = env->FindClass("org/iotivity/base/OicSecAce");
+ VERIFY_VARIABLE_NULL(clazz);
+ g_cls_OcOicSecAcl_ace = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
- g_mid_OcOicSecAcl_get_permission = env->GetMethodID(g_cls_OcOicSecAcl, "getPermission", "()I");
- VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_permission);
+ g_mid_OcOicSecAcl_ace_get_subjectID = env->GetMethodID(g_cls_OcOicSecAcl_ace, "getSubjectID","()Ljava/lang/String;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_ace_get_subjectID);
- g_mid_OcOicSecAcl_get_periods_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getPeriodsCount", "()I");
- VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_periods_cnt);
+ g_mid_OcOicSecAcl_ace_get_permissions = env->GetMethodID(g_cls_OcOicSecAcl_ace, "getPermission","()I");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_ace_get_permissions);
- g_mid_OcOicSecAcl_get_periods = env->GetMethodID(g_cls_OcOicSecAcl, "getPeriods", "(I)Ljava/lang/String;");
- VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_periods);
+ g_mid_OcOicSecAcl_ace_get_resources = env->GetMethodID(g_cls_OcOicSecAcl_ace, "getResources","()[Lorg/iotivity/base/OicSecResr;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_ace_get_resources);
- g_mid_OcOicSecAcl_get_recurrences = env->GetMethodID(g_cls_OcOicSecAcl, "getRecurrences", "(I)Ljava/lang/String;");
- VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_recurrences);
+ g_mid_OcOicSecAcl_ace_get_validities = env->GetMethodID(g_cls_OcOicSecAcl_ace, "getValidities","()[Lorg/iotivity/base/OicSecValidity;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_ace_get_validities);
- g_mid_OcOicSecAcl_get_rownerID = env->GetMethodID(g_cls_OcOicSecAcl, "getRownerID", "()Ljava/lang/String;");
- VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_rownerID);
+ //OicSecResr
+ clazz = env->FindClass("org/iotivity/base/OicSecResr");
+ VERIFY_VARIABLE_NULL(clazz);
+ g_cls_OcOicSecAcl_resr = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_OcOicSecAcl_resr_get_href = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getHref","()Ljava/lang/String;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_href);
+
+ g_mid_OcOicSecAcl_resr_get_rel = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getRel","()Ljava/lang/String;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_rel);
+
+ g_mid_OcOicSecAcl_resr_get_types = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getTypes","(I)Ljava/lang/String;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_types);
+
+ g_mid_OcOicSecAcl_resr_get_typeLen = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getTypeLen","()I");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_typeLen);
+
+ g_mid_OcOicSecAcl_resr_get_interfaces = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getInterfaces","(I)Ljava/lang/String;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_interfaces);
+
+ g_mid_OcOicSecAcl_resr_get_interfaceLen = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getInterfaceLen","()I");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_interfaceLen);
+
+ //OicSecAcl$OicSecValidity
+ clazz = env->FindClass("org/iotivity/base/OicSecValidity");
+ VERIFY_VARIABLE_NULL(clazz);
+ g_cls_OcOicSecAcl_validity = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_OcOicSecAcl_validity_get_getPeriod = env->GetMethodID(g_cls_OcOicSecAcl_validity, "getPeriod","()Ljava/lang/String;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_validity_get_getPeriod);
+
+ g_mid_OcOicSecAcl_validity_get_recurrences = env->GetMethodID(g_cls_OcOicSecAcl_validity, "getRecurrences","(I)Ljava/lang/String;");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_validity_get_recurrences);
+
+ g_mid_OcOicSecAcl_validity_get_recurrenceLen = env->GetMethodID(g_cls_OcOicSecAcl_validity, "getRecurrenceLen","()I");
+ VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_validity_get_recurrenceLen);
//OicSecPdAcl
clazz = env->FindClass("org/iotivity/base/OicSecPdAcl");
env->DeleteGlobalRef(g_cls_OcSecureResource);
env->DeleteGlobalRef(g_cls_OcProvisionResult);
env->DeleteGlobalRef(g_cls_OcOicSecAcl);
+ env->DeleteGlobalRef(g_cls_OcOicSecAcl_ace);
+ env->DeleteGlobalRef(g_cls_OcOicSecAcl_resr);
+ env->DeleteGlobalRef(g_cls_OcOicSecAcl_validity);
}
extern jclass g_cls_OcOicSecPdAcl;
extern jclass g_cls_OcDirectPairDevice;
+extern jclass g_cls_OcOicSecAcl_ace;
+extern jclass g_cls_OcOicSecAcl_resr;
+extern jclass g_cls_OcOicSecAcl_validity;
+
extern jmethodID g_mid_Integer_ctor;
extern jmethodID g_mid_Double_ctor;
extern jmethodID g_mid_Boolean_ctor;
extern jmethodID g_mid_OcSecureResource_ctor;
extern jmethodID g_mid_OcDirectPairDevice_ctor;
extern jmethodID g_mid_OcDirectPairDevice_dev_ctor;
-extern jmethodID g_mid_OcOicSecAcl_get_subject;
-extern jmethodID g_mid_OcOicSecAcl_get_resources_cnt;
-extern jmethodID g_mid_OcOicSecAcl_get_resources;
-extern jmethodID g_mid_OcOicSecAcl_get_permission;
-extern jmethodID g_mid_OcOicSecAcl_get_periods_cnt;
-extern jmethodID g_mid_OcOicSecAcl_get_periods;
-extern jmethodID g_mid_OcOicSecAcl_get_recurrences;
+
extern jmethodID g_mid_OcOicSecAcl_get_rownerID;
+extern jmethodID g_mid_OcOicSecAcl_get_aces;
+extern jmethodID g_mid_OcOicSecAcl_ace_get_subjectID;
+extern jmethodID g_mid_OcOicSecAcl_ace_get_permissions;
+extern jmethodID g_mid_OcOicSecAcl_ace_get_resources;
+extern jmethodID g_mid_OcOicSecAcl_ace_get_validities;
+extern jmethodID g_mid_OcOicSecAcl_resr_get_href;
+extern jmethodID g_mid_OcOicSecAcl_resr_get_rel;
+extern jmethodID g_mid_OcOicSecAcl_resr_get_types;
+extern jmethodID g_mid_OcOicSecAcl_resr_get_typeLen;
+extern jmethodID g_mid_OcOicSecAcl_resr_get_interfaces;
+extern jmethodID g_mid_OcOicSecAcl_resr_get_interfaceLen;
+extern jmethodID g_mid_OcOicSecAcl_validity_get_getPeriod;
+extern jmethodID g_mid_OcOicSecAcl_validity_get_recurrences;
+extern jmethodID g_mid_OcOicSecAcl_validity_get_recurrenceLen;
extern jmethodID g_mid_OcOicSecPdAcl_get_resources_cnt;
extern jmethodID g_mid_OcOicSecPdAcl_get_resources;
extern jmethodID g_mid_OcOicSecPdAcl_get_permission;
extern jmethodID g_mid_OcOicSecPdAcl_get_periods;
extern jmethodID g_mid_OcOicSecPdAcl_get_recurrences;
+
typedef void(*RemoveListenerCallback)(JNIEnv* env, jobject jListener);
static jfieldID GetHandleField(JNIEnv *env, jobject jobj)
*/
#include "JniSecureUtils.h"
+#include "JniOcStack.h"
#include "JniOcSecureResource.h"
+#include "oic_malloc.h"
#include "srmutility.h"
#include "base64.h"
for (size_t i = 0; i < result->size(); ++i)
{
- jstring jStr = env->NewStringUTF((convertUUIDtoStr(result->at(i).deviceId).c_str()));
+ char *Str = NULL;
+
+ if (OC_STACK_OK != ConvertUuidToStr(&(result->at(i).deviceId), &Str))
+ {
+ return nullptr;
+ }
+ jstring jStr = env->NewStringUTF(Str);
+ OICFree(Str);
+
if (!jStr)
{
return nullptr;
}
for (size_t i = 0; i < vector.size(); ++i)
{
- jstring jStr = env->NewStringUTF((convertUUIDtoStr(vector[i])).c_str());
+ char *Str = NULL;
+
+ if (OC_STACK_OK != ConvertUuidToStr(&(vector[i]), &Str))
+ {
+ return nullptr;
+ }
+ jstring jStr = env->NewStringUTF(Str);
+ OICFree(Str);
+
if (!jStr)
{
return nullptr;
return jList;
}
-OCStackResult JniSecureUtils::convertJavaACLToOCAcl(JNIEnv *env, jobject in, OicSecAcl_t *acl)
+static OicSecValidity_t* getValiditiesList(JNIEnv *env, jobject validityObject)
{
jstring jData;
- jvalue args[1];
-
- jData = (jstring) env->CallObjectMethod(in, g_mid_OcOicSecAcl_get_subject);
- if (!jData || env->ExceptionCheck())
+ jobjectArray valList = (jobjectArray)env->CallObjectMethod(validityObject, g_mid_OcOicSecAcl_ace_get_validities);
+ if (!valList || env->ExceptionCheck())
{
- return OC_STACK_ERROR;
+ return nullptr;
}
+ int nr_validities = env->GetArrayLength(valList);
- char *str = (char*) env->GetStringUTFChars(jData, 0);
- if (OC_STACK_OK == ConvertStrToUuid(str, &acl->subject))
- {
- env->ReleaseStringUTFChars(jData, str);
- }
- else
- {
- return OC_STACK_ERROR;
- }
+ OicSecValidity_t *valHead = NULL;
- jint jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_resources_cnt);
- if (!jCount || env->ExceptionCheck())
+ for (int i = 0 ; i < nr_validities; i++)
{
- return OC_STACK_ERROR;
- }
+ OicSecValidity_t *tmp = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t));
+ jobject element = env->GetObjectArrayElement(valList, i);
+ if (!element || env->ExceptionCheck())
+ {
+ return nullptr;
+ }
- acl->resourcesLen = jCount;
- acl->resources = new char*[jCount];
- for (jint i = 0; i < jCount; ++i)
- {
- args[0].i = i;
- jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_resources, args);
+ jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_validity_get_getPeriod);
if (!jData || env->ExceptionCheck())
{
- return OC_STACK_ERROR;
+ return nullptr;
}
+ tmp->period = (char*)env->GetStringUTFChars(jData, 0);
- acl->resources[i] = (char*) env->GetStringUTFChars(jData, 0);
- }
+ jint jrecurrenceLen = (jint) env->CallIntMethod(element,
+ g_mid_OcOicSecAcl_validity_get_recurrenceLen);
+ tmp->recurrenceLen = (int)jrecurrenceLen;
- jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_permission);
- if (env->ExceptionCheck())
- {
- return OC_STACK_ERROR;
+ if (jrecurrenceLen > 0)
+ {
+ jvalue argv[1];
+ tmp->recurrences = (char**)OICCalloc(jrecurrenceLen, sizeof(char*));
+
+ for (int i = 0 ; i < jrecurrenceLen; i++)
+ {
+ argv[0].i = i;
+ jData = (jstring)env->CallObjectMethodA(element, g_mid_OcOicSecAcl_validity_get_recurrences, argv);
+ if (!jData || env->ExceptionCheck())
+ {
+ return nullptr;
+ }
+ tmp->recurrences[i] = (char*)env->GetStringUTFChars(jData, 0);
+ }
+ }
+ if (NULL == valHead)
+ {
+ valHead = tmp;
+ }
+ else
+ {
+ OicSecValidity_t *ptr = valHead;
+ while(ptr->next != NULL) ptr = ptr->next;
+ ptr->next = tmp;
+ tmp->next = NULL;
+ }
+ env->DeleteLocalRef(element);
}
+ return valHead;
+}
- acl->permission = jCount;
- jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_periods_cnt);
- if (env->ExceptionCheck())
+static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject)
+{
+ jstring jData;
+
+ jobjectArray rescList = (jobjectArray)env->CallObjectMethod(resourceObject, g_mid_OcOicSecAcl_ace_get_resources);
+ if (!rescList || env->ExceptionCheck())
{
- return OC_STACK_ERROR;
+ return nullptr;
}
- acl->prdRecrLen = jCount;
- acl->periods = new char*[jCount];
- for (jint i = 0; i < jCount; ++i)
+ int nr_resc = env->GetArrayLength(rescList);
+ OicSecRsrc_t *rescHead = NULL;
+
+ for (int i = 0 ; i < nr_resc; i++)
{
- args[0].i = i;
- jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_periods, args);
+ OicSecRsrc_t *tmp = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
+ jobject element = env->GetObjectArrayElement(rescList, i);
+ if (!element || env->ExceptionCheck())
+ {
+ return nullptr;
+ }
+ jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_resr_get_href);
if (!jData || env->ExceptionCheck())
{
- return OC_STACK_ERROR;
+ return nullptr;
}
+ tmp->href = (char*)env->GetStringUTFChars(jData, 0);
- acl->periods[i] = (char*) env->GetStringUTFChars(jData, 0);
- }
+ jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_resr_get_rel);
+ if (!jData || env->ExceptionCheck())
+ {
+ return nullptr;
+ }
+ tmp->rel = (char*)env->GetStringUTFChars(jData, 0);
- acl->recurrences = new char*[jCount]; //TODO:Period Len and Reccurence len is same
- for (jint i = 0; i < jCount; ++i)
- {
- args[0].i = i;
- jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_recurrences, args);
- if (!jData || env->ExceptionCheck())
+ jint len = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_resr_get_typeLen);
+ tmp->typeLen = (int)len;
+ if (len > 0)
{
- return OC_STACK_ERROR;
+ jvalue argv[1];
+ tmp->types = (char**)OICCalloc(len, sizeof(char*));
+
+ for (int i = 0 ; i < len; i++)
+ {
+ argv[0].i = i;
+ jData = (jstring)env->CallObjectMethodA(element, g_mid_OcOicSecAcl_resr_get_types, argv);
+ if (!jData || env->ExceptionCheck())
+ {
+ return nullptr;
+ }
+ tmp->types[i] = (char*)env->GetStringUTFChars(jData, 0);
+ }
}
- acl->recurrences[i] = (char*) env->GetStringUTFChars(jData, 0);
+ len = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_resr_get_interfaceLen);
+ tmp->interfaceLen = len;
+ if (len > 0)
+ {
+ jvalue argv[1];
+ tmp->interfaces = (char**)OICCalloc(len, sizeof(char*));
+
+ for (int i = 0 ; i < len; i++)
+ {
+ argv[0].i = i;
+ jData = (jstring)env->CallObjectMethodA(element, g_mid_OcOicSecAcl_resr_get_interfaces, argv);
+ if (!jData || env->ExceptionCheck())
+ {
+ return nullptr;
+ }
+ tmp->interfaces[i] = (char*)env->GetStringUTFChars(jData, 0);
+ }
+ }
+
+ if (NULL == rescHead)
+ {
+ rescHead = tmp;
+ }
+ else
+ {
+ OicSecRsrc_t *ptr = rescHead;
+ while(ptr->next != NULL) ptr = ptr->next;
+ ptr->next = tmp;
+ tmp->next = NULL;
+ }
+ env->DeleteLocalRef(element);
}
+ return rescHead;
+}
+
+OCStackResult JniSecureUtils::convertJavaACLToOCAcl(JNIEnv *env, jobject in, OicSecAcl_t *acl)
+{
+ jstring jData;
jData = (jstring) env->CallObjectMethod(in, g_mid_OcOicSecAcl_get_rownerID);
if (!jData || env->ExceptionCheck())
return OC_STACK_ERROR;
}
- str = (char*) env->GetStringUTFChars(jData, 0);
-
+ char *str = (char*) env->GetStringUTFChars(jData, 0);
if (OC_STACK_OK == ConvertStrToUuid(str, &acl->rownerID))
{
env->ReleaseStringUTFChars(jData, str);
return OC_STACK_ERROR;
}
+ jobjectArray acesList = (jobjectArray)env->CallObjectMethod(in, g_mid_OcOicSecAcl_get_aces);
+
+ if (!acesList || env->ExceptionCheck())
+ {
+ return OC_STACK_ERROR;
+ }
+
+ int nr_aces = env->GetArrayLength(acesList);
+
+ OicSecAce_t *acesHead = NULL;
+
+ for (int i = 0 ; i < nr_aces; i++)
+ {
+ OicSecAce_t *tmp = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t));
+
+ jobject element = env->GetObjectArrayElement(acesList, i);
+ if (!element || env->ExceptionCheck())
+ {
+ return OC_STACK_ERROR;
+ }
+
+ jData = (jstring) env->CallObjectMethod(element, g_mid_OcOicSecAcl_ace_get_subjectID);
+ if (!jData || env->ExceptionCheck())
+ {
+ return OC_STACK_ERROR;
+ }
+
+ str = (char*) env->GetStringUTFChars(jData, 0);
+ if (OC_STACK_OK == ConvertStrToUuid(str, &tmp->subjectuuid))
+ {
+ env->ReleaseStringUTFChars(jData, str);
+ }
+ else
+ {
+ return OC_STACK_ERROR;
+ }
+
+ jint perm = (jint)env->CallIntMethod(element, g_mid_OcOicSecAcl_ace_get_permissions);
+ tmp->permission = (uint16_t)perm;
+ if (nullptr == (tmp->resources = getResourcesList(env, element)))
+ {
+ return OC_STACK_ERROR;
+ }
+
+ tmp->validities = NULL; //TODO Seems Validities CBOR conversion is broken in C stack
+#if 0
+ if (nullptr == (tmp->validities = getValiditiesList(env, element)))
+ {
+ return OC_STACK_ERROR;
+ }
+#endif
+ if (NULL == acesHead)
+ {
+ acesHead = tmp;
+ }
+ else
+ {
+ OicSecAce_t *ptr = acesHead;
+ while(ptr->next != NULL) ptr = ptr->next;
+ ptr->next = tmp;
+ tmp->next = NULL;
+ }
+ }
+ acl->aces = acesHead;
return OC_STACK_OK;
}
--- /dev/null
+/*
+ *******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+import java.util.List;
+public class OicSecAce {
+ private String subjectID;
+ private int permission;
+ private List<OicSecResr> resources;
+ private List<OicSecValidity> validities;
+
+ public OicSecAce(String subjectID, int permission,
+ List<OicSecResr> resources, List<OicSecValidity> validities) {
+ super();
+ this.subjectID = subjectID;
+ this.permission = permission;
+ this.resources = resources;
+ this.validities = validities;
+ }
+
+ public String getSubjectID() {
+ return subjectID;
+ }
+
+ public void setSubjectID(String subjectID) {
+ this.subjectID = subjectID;
+ }
+
+ public int getPermission() {
+ return permission;
+ }
+
+ public void setPermission(int permission) {
+ this.permission = permission;
+ }
+
+ public List<OicSecResr> getResourcesList() {
+ return resources;
+ }
+
+ public OicSecResr[] getResources() {
+ return resources.toArray(new OicSecResr[resources.size()]);
+ }
+ public void setResources(List<OicSecResr> resources) {
+ this.resources = resources;
+ }
+
+ public List<OicSecValidity> getValiditiesList() {
+ return validities;
+ }
+
+ public OicSecValidity[] getValidities() {
+ return validities.toArray(new OicSecValidity[validities.size()]);
+ }
+
+
+ public void setValidities(List<OicSecValidity> validities) {
+ this.validities = validities;
+ }
+}
-/*
- *******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-
-package org.iotivity.base;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.Arrays;
-
-public class OicSecAcl implements Serializable {
-
- private String subject;
- private int permission;
- private List<String> resources;
- private List<String> periods;
- private List<String> recurrences;
- private String rownerID;
-
- public OicSecAcl(String subject, List<String> recurrences, List<String> periods, int permission,
- List<String> resources, String rownerID) {
- this.subject = subject;
- this.recurrences = recurrences;
- this.periods = periods;
- this.permission = permission;
- this.resources = resources;
- this.rownerID = rownerID;
- }
-
- public String getSubject() {
- return this.subject;
- }
-
- public void setSubject(String subject) {
- this.subject = subject;
- }
-
-
- public void setRownerID(String rownerID) {
- this.rownerID = rownerID;
- }
-
- public List<String> getRecurrences() {
- return recurrences;
- }
-
- public void setRecurrences(List<String> recurrences) {
- this.recurrences = recurrences;
- }
-
- public List<String> getPeriods() {
- return periods;
- }
-
- public void setPeriods(List<String> periods) {
- this.periods = periods;
- }
-
- public int getPermission() {
- return this.permission;
- }
-
- public void setPermission(int permission) {
- this.permission = permission;
- }
-
- public List<String> getResources() {
- return resources;
- }
-
- public void setResources(List<String> resources) {
- this.resources = resources;
- }
-
- public int getResourcesCount() {
- return this.resources.size();
- }
-
- public String getResources(int i) {
- return this.resources.get(i);
- }
-
- public int getPeriodsCount() {
- return this.periods.size();
- }
-
- public String getPeriods(int i) {
- return this.periods.get(i);
- }
-
- public String getRecurrences(int i) {
- return this.recurrences.get(i);
- }
-
- public String getRownerID() {
- return this.rownerID;
- }
-}
+/*\r
+ *******************************************************************\r
+ *\r
+ * Copyright 2016 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ */\r
+\r
+package org.iotivity.base;\r
+\r
+import java.util.List;\r
+\r
+public class OicSecAcl {\r
+ private String rownerID;\r
+ private List<OicSecAce> oicSecAces;\r
+\r
+ public OicSecAcl (String rownerID, List<OicSecAce> oicSecAces) {\r
+ super();\r
+ this.rownerID = rownerID;\r
+ this.oicSecAces = oicSecAces;\r
+ }\r
+ public String getRownerID() {\r
+ return rownerID;\r
+ }\r
+\r
+ public void setRownerID(String rownerID) {\r
+ this.rownerID = rownerID;\r
+ }\r
+\r
+ public List<OicSecAce> getOicSecAcesList() {\r
+ return oicSecAces;\r
+ }\r
+\r
+ public OicSecAce[] getOicSecAces() {\r
+ return oicSecAces.toArray(new OicSecAce[oicSecAces.size()]);\r
+ }\r
+\r
+ public void setOicSecAces(List<OicSecAce> oicSecAces) {\r
+ this.oicSecAces = oicSecAces;\r
+ }\r
+}\r
--- /dev/null
+/*
+ *******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+import java.util.List;
+public class OicSecResr {
+
+ private String href;
+ private String rel;
+ private List<String> types;
+ private int typeLen;
+ private List<String> interfaces;
+ private int interfaceLen;
+
+ public OicSecResr(String href, String rel, List<String> types, int typeLen,
+ List<String> interfaces, int interfaceLen) {
+ super();
+ this.href = href;
+ this.rel = rel;
+ this.types = types;
+ this.typeLen = typeLen;
+ this.interfaces = interfaces;
+ this.interfaceLen = interfaceLen;
+ }
+
+ public String getHref() {
+ return href;
+ }
+
+ public void setHref(String href) {
+ this.href = href;
+ }
+
+ public String getRel() {
+ return rel;
+ }
+
+ public void setRel(String rel) {
+ this.rel = rel;
+ }
+
+ public List<String> getTypesList() {
+ return types;
+ }
+
+ public void setTypes(List<String> types) {
+ this.types = types;
+ }
+
+ public int getTypeLen() {
+ return typeLen;
+ }
+
+ public void setTypeLen(int typeLen) {
+ this.typeLen = typeLen;
+ }
+
+ public List<String> getInterfacesList() {
+ return interfaces;
+ }
+
+ public String getInterfaces(int i) {
+ return this.interfaces.get(i);
+ }
+
+ public String getTypes(int i) {
+ return this.types.get(i);
+ }
+
+ public void setInterfaces(List<String> interfaces) {
+ this.interfaces = interfaces;
+ }
+
+ public int getInterfaceLen() {
+ return interfaceLen;
+ }
+
+ public void setInterfaceLen(int interfaceLen) {
+ this.interfaceLen = interfaceLen;
+ }
+
+}
--- /dev/null
+/*
+ *******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+import java.util.List;
+public class OicSecValidity {
+ private String period;
+ private List<String> recurrences;
+ private int recurrenceLen;
+
+ public OicSecValidity(String period, List<String> recurrences,
+ int recurrenceLen) {
+ super();
+ this.period = period;
+ this.recurrences = recurrences;
+ this.recurrenceLen = recurrenceLen;
+ }
+
+ public String getPeriod() {
+ return period;
+ }
+
+ public void setPeriod(String period) {
+ this.period = period;
+ }
+
+ public List<String> getRecurrencesList() {
+ return recurrences;
+ }
+
+ public String getRecurrences(int i) {
+ return this.recurrences.get(i);
+ }
+
+ public void setRecurrences(List<String> recurrences) {
+ this.recurrences = recurrences;
+ }
+
+ public int getRecurrenceLen() {
+ return recurrenceLen;
+ }
+
+ public void setRecurrenceLen(int recurrenceLen) {
+ this.recurrenceLen = recurrenceLen;
+ }
+
+}
import org.iotivity.base.OcProvisioning;
import org.iotivity.base.OcSecureResource;
import org.iotivity.base.OicSecAcl;
+import org.iotivity.base.OicSecAce;
+import org.iotivity.base.OicSecResr;
+import org.iotivity.base.OicSecValidity;
import org.iotivity.base.OicSecPdAcl;
import org.iotivity.base.OcPrmType;
import org.iotivity.base.OxmType;
import java.util.List;
public class ProvisioningClient extends Activity implements
- OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwiseDevicesListener {
+OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwiseDevicesListener {
private static final String TAG = "Provisioning Client: ";
private static final int BUFFER_SIZE = 1024;
int unownedDevCount = StringConstants.NUMBER_ZERO;
OcProvisioning.PinCallbackListener pinCallbackListener =
- new OcProvisioning.PinCallbackListener() {
- @Override
+ new OcProvisioning.PinCallbackListener() {
+ @Override
public String pinCallbackListener() {
Log.d(TAG, "Inside Pin Callback ");
return "";
}
- };
+ };
private String filePath = "";
private OcSecureResource newSecureResource;
private List<OcSecureResource> deviceList;
private TextView mEventsTextView;
OcSecureResource.ProvisionDirectPairingListener provisionDPListener =
- new OcSecureResource.ProvisionDirectPairingListener() {
- @Override
+ new OcSecureResource.ProvisionDirectPairingListener() {
+ @Override
public void provisionDirectPairingListener(List<ProvisionResult> provisionResults,
- int hasError) {
+ int hasError) {
Log.d(TAG, "Inside provisionDPListener");
ProvisionResult pResult = provisionResults.get(0);
if (hasError == StringConstants.ERROR_CODE) {
logMessage(TAG + "Provision direct pairing Failed for " + pResult.getDevId());
} else {
logMessage(TAG + "Provision direct pairing Successful for " + pResult.getDevId());
+ if (ownedDeviceList.size() == 1) {
+ new ProvisionACLAsyncTask().execute();
+ }
+ if (ownedDeviceList.size() > 1) {
+ new GetLinkedDevicesAsyncTask().execute();
+ }
}
}
- };
+ };
OcSecureResource.ProvisionAclListener provisionAclListener =
- new OcSecureResource.ProvisionAclListener() {
- @Override
+ new OcSecureResource.ProvisionAclListener() {
+ @Override
public void provisionAclListener(List<ProvisionResult> provisionResults,
- int hasError) {
+ int hasError) {
Log.d(TAG, "Inside ProvisionAclListener ");
if (hasError == StringConstants.ERROR_CODE) {
logMessage("Error: ACL Provision failed !!");
new DeviceRevocationAsyncTask().execute();
}
}
- };
+ };
OcSecureResource.ProvisionCredentialsListener provisionCredentialsListener =
- new OcSecureResource.ProvisionCredentialsListener() {
- @Override
+ new OcSecureResource.ProvisionCredentialsListener() {
+ @Override
public void provisionCredentialsListener(List<ProvisionResult> provisionResults,
- int hasError) {
+ int hasError) {
Log.d(TAG, "Inside ProvisionCredentialsListener ");
if (hasError == StringConstants.ERROR_CODE) {
logMessage("Error: Provision Credentials failed !!");
new ProvisionACLAsyncTask().execute();
}
}
- };
+ };
OcSecureResource.UnlinkDevicesListener unlinkDevicesListener =
- new OcSecureResource.UnlinkDevicesListener() {
- @Override
+ new OcSecureResource.UnlinkDevicesListener() {
+ @Override
public void unlinkDevicesListener(List<ProvisionResult> provisionResults,
- int hasError) {
+ int hasError) {
Log.d(TAG, "Inside unlinkDevicesListener ");
if (hasError == StringConstants.ERROR_CODE) {
logMessage("Error: UnLinking device !!");
new ProvisionCredentialAsyncTask().execute();
}
}
- };
+ };
OcSecureResource.RemoveDeviceListener removeDeviceListener =
- new OcSecureResource.RemoveDeviceListener() {
- @Override
+ new OcSecureResource.RemoveDeviceListener() {
+ @Override
public void removeDeviceListener(List<ProvisionResult> provisionResults,
- int hasError) {
+ int hasError) {
if (hasError == StringConstants.ERROR_CODE) {
logMessage("Error: Remove Fail !!");
} else {
logMessage("Remove Device done !!");
}
}
- };
+ };
@Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_secure_provision_client);
- mEventsTextView = new TextView(this);
- mEventsTextView.setGravity(Gravity.BOTTOM);
- mEventsTextView.setMovementMethod(new ScrollingMovementMethod());
- LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
- layout.addView(mEventsTextView, new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)
- );
- filePath = getFilesDir().getPath() + "/"; // data/data/<package>/files/
- //copy CBOR file when application runs first time
- SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
- boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);
- if (isFirstRun) {
- copyCborFromAsset();
- SharedPreferences.Editor editor = wmbPreference.edit();
- editor.putBoolean("FIRSTRUN", false);
- editor.commit();
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_secure_provision_client);
+ mEventsTextView = new TextView(this);
+ mEventsTextView.setGravity(Gravity.BOTTOM);
+ mEventsTextView.setMovementMethod(new ScrollingMovementMethod());
+ LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
+ layout.addView(mEventsTextView, new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)
+ );
+ filePath = getFilesDir().getPath() + "/"; // data/data/<package>/files/
+ //copy CBOR file when application runs first time
+ SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
+ boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);
+ if (isFirstRun) {
+ copyCborFromAsset();
+ SharedPreferences.Editor editor = wmbPreference.edit();
+ editor.putBoolean("FIRSTRUN", false);
+ editor.commit();
+ }
+ initOICStack();
}
- initOICStack();
- }
/**
* configure OIC platform and call findResource
* Initialize DataBase
*/
String sqlDbPath = getFilesDir().getAbsolutePath().replace("files", "databases") +
- File.separator;
+ File.separator;
File file = new File(sqlDbPath);
//check files directory exists
if (!(file.isDirectory())) {
}
@Override
- synchronized public void doOwnershipTransferListener(List<ProvisionResult> ProvisionResultList,
- int hasError) {
- ProvisionResult pResult = ProvisionResultList.get(0);
- if (hasError == StringConstants.ERROR_CODE) {
- logMessage(TAG + "Ownership Transfer Failed for " + pResult.getDevId());
- } else {
- logMessage(TAG + "Ownership Transfer Successful for "
- + pResult.getDevId());
- unownedDevCount--;
- }
- if (unownedDevCount == 0) { //When done with Ownership Transfer
- new OwnedDiscoveryAsyncTask().execute();
+ synchronized public void doOwnershipTransferListener(List<ProvisionResult> ProvisionResultList,
+ int hasError) {
+ ProvisionResult pResult = ProvisionResultList.get(0);
+ if (hasError == StringConstants.ERROR_CODE) {
+ logMessage(TAG + "Ownership Transfer Failed for " + pResult.getDevId());
+ } else {
+ logMessage(TAG + "Ownership Transfer Successful for "
+ + pResult.getDevId());
+ unownedDevCount--;
+ }
+ if (unownedDevCount == 0) { //When done with Ownership Transfer
+ new OwnedDiscoveryAsyncTask().execute();
+ }
}
- }
private void doDPProvisioning() {
logMessage(TAG + "Provision direct pairing for " + ownedDeviceList.get(0).getDeviceID());
newSecureResource = ownedDeviceList.get(0);
String pin = "00000000";
- List<OcPrmType>prmTypes = new ArrayList<OcPrmType>();
+ List<OcPrmType> prmTypes = new ArrayList<OcPrmType>();
prmTypes.add(OcPrmType.DP_PRE_CONFIGURED);
boolean edp = true;
List<String> resources = new ArrayList<String>();
logMessage(TAG + "Pairwise Provisioning b/w " + ownedDeviceList.get(0).getDeviceID()
+ " and " + ownedDeviceList.get(1).getDeviceID());
newSecureResource = ownedDeviceList.get(0);
- OcSecureResource newSecureResource2 = ownedDeviceList.get(1);
- List<String> resources = new ArrayList<String>();
- List<String> periods = new ArrayList<String>();
+
+ List<OicSecResr> resources1 = new ArrayList<OicSecResr>();
+ List<OicSecResr> resources2 = new ArrayList<OicSecResr>();
+ List<OicSecValidity> validities = new ArrayList<OicSecValidity>();
+
+ List<String> types1 = new ArrayList<String>();
+ types1.add(StringConstants.RESOURCE_TYPE_1A);
+ types1.add(StringConstants.RESOURCE_TYPE_1B);
+ List<String> types2 = new ArrayList<String>();
+ types2.add(StringConstants.RESOURCE_TYPE_2A);
+ types2.add(StringConstants.RESOURCE_TYPE_2B);
+ List<String> interfaces = new ArrayList<String>();
+ interfaces.add(StringConstants.RESOURCE_INTERFACE_1);
+ interfaces.add(StringConstants.RESOURCE_INTERFACE_2);
+
+ OicSecResr oicSecResr1a = new OicSecResr(StringConstants.HREF_RESOURCES_1A, "", types1, 2, interfaces, 2);
+ OicSecResr oicSecResr1b = new OicSecResr(StringConstants.HREF_RESOURCES_1B, "", types1, 2, interfaces, 2);
+ resources1.add(oicSecResr1a);
+ resources1.add(oicSecResr1b);
+
+ OicSecResr oicSecResr2a = new OicSecResr(StringConstants.HREF_RESOURCES_2A, "", types2, 2, interfaces, 2);
+ OicSecResr oicSecResr2b = new OicSecResr(StringConstants.HREF_RESOURCES_2B, "", types2, 2, interfaces, 2);
+ resources2.add(oicSecResr2a);
+ resources2.add(oicSecResr2b);
+
List<String> recurrences = new ArrayList<String>();
- recurrences.add(StringConstants.DEFAULT_RECURRENCES);
- resources.add(StringConstants.DEFAULT_RESOURCES);
- periods.add(StringConstants.DEFAULT_PERIOD);
- OicSecAcl acl1 = new OicSecAcl(newSecureResource.getDeviceID(), recurrences, periods,
- StringConstants.DEFAULT_PERMISSION, resources, StringConstants.DEFAULT_ROWNER_ID);
- OicSecAcl acl2 = new OicSecAcl(newSecureResource2.getDeviceID(), recurrences, periods,
- StringConstants.DEFAULT_PERMISSION, resources, StringConstants.DEFAULT_ROWNER_ID);
+ recurrences.add(StringConstants.DEFAULT_RECURRENCES_1);
+ recurrences.add(StringConstants.DEFAULT_RECURRENCES_2);
+ OicSecValidity oicSecValidity = new OicSecValidity(StringConstants.DEFAULT_PERIOD,
+ recurrences, 2);
+ validities.add(oicSecValidity);
+
+ OicSecAce oicsecace1 = new OicSecAce(newSecureResource.getDeviceID(),
+ StringConstants.DEFAULT_PERMISSION, resources1, validities);
+ OcSecureResource newSecureResource2 = ownedDeviceList.get(1);
+ OicSecAce oicsecace2 = new OicSecAce(newSecureResource2.getDeviceID(),
+ StringConstants.DEFAULT_PERMISSION, resources2, validities);
+
+ List<OicSecAce> oicSecAces1=new ArrayList<OicSecAce>();
+ oicSecAces1.add(oicsecace1);
+ List<OicSecAce> oicSecAces2=new ArrayList<OicSecAce>();
+ oicSecAces2.add(oicsecace2);
+ OicSecAcl acl1 = new OicSecAcl(StringConstants.DEFAULT_ROWNER_ID,oicSecAces1);
+ OicSecAcl acl2 = new OicSecAcl(StringConstants.DEFAULT_ROWNER_ID,oicSecAces2);
+
newSecureResource.provisionPairwiseDevices(EnumSet.of(CredType.SYMMETRIC_PAIR_WISE_KEY),
KeySize.OWNER_PSK_LENGTH_128, acl1, newSecureResource2, acl2, this);
} catch (Exception e) {
}
@Override
- public void provisionPairwiseDevicesListener(List<ProvisionResult> ProvisionResultList,
- int hasError) {
- if (hasError == StringConstants.ERROR_CODE) {
- logMessage(TAG + "provisionPairwiseDevices Failed");
- } else {
- for (int i = 0; i < ProvisionResultList.size(); i++) {
- ProvisionResult pResult = ProvisionResultList.get(i);
- logMessage(TAG + "provisionPairwiseDevices Result for "
- + pResult.getDevId() + "is " + pResult.getResult());
- }
- new GetLinkedDevicesAsyncTask().execute();
+ public void provisionPairwiseDevicesListener(List<ProvisionResult> ProvisionResultList,
+ int hasError) {
+ if (hasError == StringConstants.ERROR_CODE) {
+ logMessage(TAG + "provisionPairwiseDevices Failed");
+ } else {
+ for (int i = 0; i < ProvisionResultList.size(); i++) {
+ ProvisionResult pResult = ProvisionResultList.get(i);
+ logMessage(TAG + "provisionPairwiseDevices Result for "
+ + pResult.getDevId() + "is " + pResult.getResult());
+ }
+ doDPProvisioning();
+ }
}
- }
/**
* Copy svr db CBOR dat file from assets folder to app data files dir
public void logMsg(final String text) {
runOnUiThread(new Runnable() {
- public void run() {
+ public void run() {
Message msg = new Message();
msg.obj = text;
mEventsTextView.append(text);
mEventsTextView.append("\n\n");
- }
- });
+ }
+ });
Log.i(TAG, text);
Intent intent = new Intent(getPackageName());
intent.putExtra(StringConstants.MESSAGE, text);
private class DiscoveryOTTransferAsyncTask extends AsyncTask<Void, String, String> {
@Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
+ protected void onPreExecute() {
+ super.onPreExecute();
+ }
@Override
- protected String doInBackground(Void... params) {
- try {
- /**
- * Discover Un-owned devices
- */
- publishProgress(TAG + "Discovering Unowned Devices");
- deviceList = new ArrayList<OcSecureResource>(OcProvisioning.discoverUnownedDevices
- (StringConstants.DISCOVERY_TIMEOUT_10));
- if (deviceList.size() > 0) {
- unownedDevCount = deviceList.size();
- for (int i = 0; i < deviceList.size(); i++) {
- publishProgress(TAG + "Un-owned Discovered Device " + (i + 1) + "= " +
- deviceList.get(i).getDeviceID());
- }
- try {
- OcProvisioning.SetownershipTransferCBdata(OxmType.OIC_JUST_WORKS,
- pinCallbackListener);
+ protected String doInBackground(Void... params) {
+ try {
+ /**
+ * Discover Un-owned devices
+ */
+ publishProgress(TAG + "Discovering Unowned Devices");
+ deviceList = new ArrayList<OcSecureResource>(OcProvisioning.discoverUnownedDevices
+ (StringConstants.DISCOVERY_TIMEOUT_10));
+ if (deviceList.size() > 0) {
+ unownedDevCount = deviceList.size();
for (int i = 0; i < deviceList.size(); i++) {
- publishProgress(TAG + "Doing Ownership Transfer for " +
+ publishProgress(TAG + "Un-owned Discovered Device " + (i + 1) + "= " +
deviceList.get(i).getDeviceID());
- deviceList.get(i).doOwnershipTransfer(ProvisioningClient.this);
}
- } catch (OcException e) {
- publishProgress(TAG + "Ownership Transfer error: " + e.getMessage());
- return "Ownership Transfer error: " + e.getMessage();
+ try {
+ OcProvisioning.SetownershipTransferCBdata(OxmType.OIC_JUST_WORKS,
+ pinCallbackListener);
+ for (int i = 0; i < deviceList.size(); i++) {
+ publishProgress(TAG + "Doing Ownership Transfer for " +
+ deviceList.get(i).getDeviceID());
+ deviceList.get(i).doOwnershipTransfer(ProvisioningClient.this);
+ }
+ } catch (OcException e) {
+ publishProgress(TAG + "Ownership Transfer error: " + e.getMessage());
+ return "Ownership Transfer error: " + e.getMessage();
+ }
+ } else {
+ publishProgress(TAG + "No un-owned devices present");
+ new OwnedDiscoveryAsyncTask().execute();
}
- } else {
- publishProgress(TAG + "No un-owned devices present");
- new OwnedDiscoveryAsyncTask().execute();
+ } catch (OcException e) {
+ publishProgress(TAG + "Un-owned discovery error: " + e.getMessage());
+ return "Un-owned discovery error: " + e.getMessage();
}
- } catch (OcException e) {
- publishProgress(TAG + "Un-owned discovery error: " + e.getMessage());
- return "Un-owned discovery error: " + e.getMessage();
+ return "success";
}
- return "success";
- }
@Override
- protected void onProgressUpdate(String... values) {
- logMessage(values[0]);
- }
+ protected void onProgressUpdate(String... values) {
+ logMessage(values[0]);
+ }
@Override
- protected void onPostExecute(String s) {
- super.onPostExecute(s);
- }
+ protected void onPostExecute(String s) {
+ super.onPostExecute(s);
+ }
}
private class ProvisionACLAsyncTask extends AsyncTask<Void, String, Void> {
@Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
+ protected void onPreExecute() {
+ super.onPreExecute();
+ }
@Override
- protected Void doInBackground(Void... params) {
- try {
- if (ownedDeviceList.size() > 1) {
- OcSecureResource ocSecureResource = ownedDeviceList.get(0);
- OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1);
- publishProgress(TAG + "ACL Provision for " + ocSecureResource.getDeviceID());
- List<String> resources = new ArrayList<String>();
- List<String> periods = new ArrayList<String>();
- List<String> recurrences = new ArrayList<String>();
- recurrences.add(StringConstants.DEFAULT_RECURRENCES);
- resources.add(StringConstants.DEFAULT_RESOURCES);
- periods.add(StringConstants.DEFAULT_PERIOD);
- OicSecAcl aclObject = new OicSecAcl(ocSecureResourceDest.getDeviceID(),
- recurrences, periods, StringConstants.DEFAULT_PERMISSION, resources,
- StringConstants.DEFAULT_ROWNER_ID);
- ocSecureResource.provisionACL(aclObject, provisionAclListener);
- } else {
- publishProgress(TAG + "No Owned devices present");
+ protected Void doInBackground(Void... params) {
+ try {
+ if (ownedDeviceList.size() > 0) {
+ OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+
+ publishProgress(TAG + "ACL Provision for " + ocSecureResource.getDeviceID());
+ List<OicSecResr> resources1 = new ArrayList<OicSecResr>();
+ List<OicSecResr> resources2 = new ArrayList<OicSecResr>();
+ List<OicSecValidity> validities = new ArrayList<OicSecValidity>();
+
+ List<String> types1 = new ArrayList<String>();
+ types1.add(StringConstants.RESOURCE_TYPE_1A);
+ types1.add(StringConstants.RESOURCE_TYPE_1B);
+ List<String> types2 = new ArrayList<String>();
+ types2.add(StringConstants.RESOURCE_TYPE_2A);
+ types2.add(StringConstants.RESOURCE_TYPE_2B);
+ List<String> interfaces = new ArrayList<String>();
+ interfaces.add(StringConstants.RESOURCE_INTERFACE_1);
+ interfaces.add(StringConstants.RESOURCE_INTERFACE_2);
+
+ OicSecResr oicSecResr1a = new OicSecResr(StringConstants.HREF_RESOURCES_1A, "", types1, 2, interfaces, 2);
+ OicSecResr oicSecResr1b = new OicSecResr(StringConstants.HREF_RESOURCES_1B, "", types1, 2, interfaces, 2);
+ resources1.add(oicSecResr1a);
+ resources1.add(oicSecResr1b);
+
+ OicSecResr oicSecResr2a = new OicSecResr(StringConstants.HREF_RESOURCES_2A, "", types2, 2, interfaces, 2);
+ OicSecResr oicSecResr2b = new OicSecResr(StringConstants.HREF_RESOURCES_2B, "", types2, 2, interfaces, 2);
+ resources2.add(oicSecResr2a);
+ resources2.add(oicSecResr2b);
+
+ List<String> recurrences = new ArrayList<String>();
+ recurrences.add(StringConstants.DEFAULT_RECURRENCES_1);
+ recurrences.add(StringConstants.DEFAULT_RECURRENCES_2);
+ OicSecValidity oicSecValidity = new OicSecValidity(StringConstants.DEFAULT_PERIOD,
+ recurrences, 2);
+ validities.add(oicSecValidity);
+
+ OicSecAce oicsecace1 = new OicSecAce(StringConstants.DEFAULT_SUBJECT_ID1,
+ StringConstants.DEFAULT_PERMISSION, resources1, validities);
+
+ OicSecAce oicsecace2 = new OicSecAce(StringConstants.DEFAULT_SUBJECT_ID2,
+ StringConstants.DEFAULT_PERMISSION, resources2, validities);
+
+ List<OicSecAce> oicSecAces=new ArrayList<OicSecAce>();
+ oicSecAces.add(oicsecace1);
+ oicSecAces.add(oicsecace2);
+
+ OicSecAcl aclObject = new OicSecAcl(StringConstants.DEFAULT_ROWNER_ID, oicSecAces);
+
+ ocSecureResource.provisionACL(aclObject, provisionAclListener);
+ } else {
+ publishProgress(TAG + "No Owned devices present");
+ }
+ } catch (Exception e) {
+ publishProgress(TAG + "ProvisionACL error: " + e.getMessage());
}
- } catch (Exception e) {
- publishProgress(TAG + "ProvisionACL error: " + e.getMessage());
+ return null;
}
- return null;
- }
@Override
- protected void onProgressUpdate(String... values) {
- logMessage(values[0]);
- }
+ protected void onProgressUpdate(String... values) {
+ logMessage(values[0]);
+ }
}
private class ProvisionCredentialAsyncTask extends AsyncTask<Void, String, Void> {
@Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
+ protected void onPreExecute() {
+ super.onPreExecute();
+ }
@Override
- protected Void doInBackground(Void... params) {
- try {
- if (ownedDeviceList.size() > 1) {
- OcSecureResource ocSecureResource = ownedDeviceList.get(0);
- OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1);
- publishProgress(TAG + "ProvisionCredential for " +
- ocSecureResource.getDeviceID() + " with " +
- ocSecureResourceDest.getDeviceID());
- ocSecureResource.provisionCredentials(EnumSet.of(CredType.SYMMETRIC_PAIR_WISE_KEY),
- KeySize.OWNER_PSK_LENGTH_128,
- ocSecureResourceDest, provisionCredentialsListener);
- } else {
- publishProgress(TAG + "Cannot perform credentials between devices");
+ protected Void doInBackground(Void... params) {
+ try {
+ if (ownedDeviceList.size() > 1) {
+ OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+ OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1);
+ publishProgress(TAG + "ProvisionCredential for " +
+ ocSecureResource.getDeviceID() + " with " +
+ ocSecureResourceDest.getDeviceID());
+ ocSecureResource.provisionCredentials(EnumSet.of(CredType.SYMMETRIC_PAIR_WISE_KEY),
+ KeySize.OWNER_PSK_LENGTH_128,
+ ocSecureResourceDest, provisionCredentialsListener);
+ } else {
+ publishProgress(TAG + "Cannot perform credentials between devices");
+ }
+ } catch (Exception e) {
+ publishProgress(TAG + "Provision credentials error: " + e.getMessage());
}
- } catch (Exception e) {
- publishProgress(TAG + "Provision credentials error: " + e.getMessage());
+ return null;
}
- return null;
- }
@Override
- protected void onProgressUpdate(String... values) {
- logMessage(values[0]);
- }
+ protected void onProgressUpdate(String... values) {
+ logMessage(values[0]);
+ }
}
private class GetLinkedDevicesAsyncTask extends AsyncTask<Void, String, String> {
@Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
+ protected void onPreExecute() {
+ super.onPreExecute();
+ }
@Override
- protected String doInBackground(Void... params) {
- try {
- if (ownedDeviceList.size() > 1) {
- OcSecureResource ocSecureResource = ownedDeviceList.get(0);
- publishProgress(TAG + "Get linked devices of " + ocSecureResource.getDeviceID());
- List<String> linkedDevices = ocSecureResource.getLinkedDevices();
- if (linkedDevices.size() > 0) {
- for (int i = 0; i < linkedDevices.size(); i++) {
- publishProgress(TAG + "Linked Devices " +
- (i + 1) + "= " + linkedDevices.get(i));
+ protected String doInBackground(Void... params) {
+ try {
+ if (ownedDeviceList.size() > 1) {
+ OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+ publishProgress(TAG + "Get linked devices of " + ocSecureResource.getDeviceID());
+ List<String> linkedDevices = ocSecureResource.getLinkedDevices();
+ if (linkedDevices.size() > 0) {
+ for (int i = 0; i < linkedDevices.size(); i++) {
+ publishProgress(TAG + "Linked Devices " +
+ (i + 1) + "= " + linkedDevices.get(i));
+ }
+ } else {
+ publishProgress(TAG + "No linked Devices found");
}
} else {
- publishProgress(TAG + "No linked Devices found");
+ publishProgress(TAG + "Cannot perform linked devices");
}
- } else {
- publishProgress(TAG + "Cannot perform linked devices");
+ } catch (Exception e) {
+ publishProgress(TAG + "getLinked device error: " + e.getMessage());
+ return "failed";
}
- } catch (Exception e) {
- publishProgress(TAG + "getLinked device error: " + e.getMessage());
- return "failed";
+ return "success";
}
- return "success";
- }
@Override
- protected void onProgressUpdate(String... values) {
- logMessage(values[0]);
- }
+ protected void onProgressUpdate(String... values) {
+ logMessage(values[0]);
+ }
@Override
- protected void onPostExecute(String s) {
- if ("success".equals(s)) {
- new ProvisionUnlinkAsyncTask().execute();
+ protected void onPostExecute(String s) {
+ if ("success".equals(s)) {
+ new ProvisionUnlinkAsyncTask().execute();
+ }
}
- }
}
private class ProvisionUnlinkAsyncTask extends AsyncTask<Void, String, Void> {
@Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
+ protected void onPreExecute() {
+ super.onPreExecute();
+ }
@Override
- protected Void doInBackground(Void... params) {
- try {
- if (ownedDeviceList.size() > 1) {
- OcSecureResource ocSecureResource = ownedDeviceList.get(0);
- OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1);
- publishProgress(TAG + "Un linking " + ocSecureResource.getDeviceID() +
- " with " + ocSecureResourceDest.getDeviceID());
- ocSecureResource.unlinkDevices(ocSecureResourceDest, unlinkDevicesListener);
- } else {
- publishProgress(TAG + "Cannot perform unlink devices");
+ protected Void doInBackground(Void... params) {
+ try {
+ if (ownedDeviceList.size() > 1) {
+ OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+ OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1);
+ publishProgress(TAG + "Un linking " + ocSecureResource.getDeviceID() +
+ " with " + ocSecureResourceDest.getDeviceID());
+ ocSecureResource.unlinkDevices(ocSecureResourceDest, unlinkDevicesListener);
+ } else {
+ publishProgress(TAG + "Cannot perform unlink devices");
+ }
+ } catch (Exception e) {
+ publishProgress(TAG + "Unlink error: " + e.getMessage());
}
- } catch (Exception e) {
- publishProgress(TAG + "Unlink error: " + e.getMessage());
+ return null;
}
- return null;
- }
@Override
- protected void onProgressUpdate(String... values) {
- logMessage(values[0]);
- }
+ protected void onProgressUpdate(String... values) {
+ logMessage(values[0]);
+ }
}
private class DeviceRevocationAsyncTask extends AsyncTask<Void, String, Void> {
@Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
+ protected void onPreExecute() {
+ super.onPreExecute();
+ }
@Override
- protected Void doInBackground(Void... params) {
- try {
- if (ownedDeviceList.size() > 0) {
- OcSecureResource ocSecureResource = ownedDeviceList.get(0);
- publishProgress(TAG + "Removing " + ocSecureResource.getDeviceID());
- ocSecureResource.removeDevice(StringConstants.DISCOVERY_TIMEOUT_20,
- removeDeviceListener);
- } else {
- publishProgress(TAG + "Cannot remove");
+ protected Void doInBackground(Void... params) {
+ try {
+ if (ownedDeviceList.size() > 0) {
+ OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+ publishProgress(TAG + "Removing " + ocSecureResource.getDeviceID());
+ ocSecureResource.removeDevice(StringConstants.DISCOVERY_TIMEOUT_20,
+ removeDeviceListener);
+ } else {
+ publishProgress(TAG + "Cannot remove");
+ }
+ } catch (Exception e) {
+ publishProgress(TAG + "Remove Device error: " + e.getMessage());
}
- } catch (Exception e) {
- publishProgress(TAG + "Remove Device error: " + e.getMessage());
+ return null;
}
- return null;
- }
@Override
- protected void onProgressUpdate(String... values) {
- logMessage(values[0]);
- }
+ protected void onProgressUpdate(String... values) {
+ logMessage(values[0]);
+ }
}
private class OwnedDiscoveryAsyncTask extends AsyncTask<Void, String, String> {
@Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
+ protected void onPreExecute() {
+ super.onPreExecute();
+ }
@Override
- protected String doInBackground(Void... params) {
- try {
- publishProgress(TAG + "Initiate Owned device Discovery");
- ownedDeviceList = OcProvisioning.discoverOwnedDevices
+ protected String doInBackground(Void... params) {
+ try {
+ publishProgress(TAG + "Initiate Owned device Discovery");
+ ownedDeviceList = OcProvisioning.discoverOwnedDevices
(StringConstants.DISCOVERY_TIMEOUT_10);
- if (ownedDeviceList.size() > 0) {
- for (int i = 0; i < ownedDeviceList.size(); i++) {
- publishProgress(TAG + "Owned Discovered Device " + (i + 1) + "= " +
- ownedDeviceList.get(i).getDeviceID()
- + "\nIP Address= " + ownedDeviceList.get(i).getIpAddr()
- + "\nOwned Status= " + ownedDeviceList.get(i).getOwnedStatus()
- + "\nDevice Status= " + ((ownedDeviceList.get(i).
- getDeviceStatus() == DeviceStatus.ON) ? "ON" : "OFF")
- );
+ if (ownedDeviceList.size() > 0) {
+ for (int i = 0; i < ownedDeviceList.size(); i++) {
+ publishProgress(TAG + "Owned Discovered Device " + (i + 1) + "= " +
+ ownedDeviceList.get(i).getDeviceID()
+ + "\nIP Address= " + ownedDeviceList.get(i).getIpAddr()
+ + "\nOwned Status= " + ownedDeviceList.get(i).getOwnedStatus()
+ + "\nDevice Status= " + ((ownedDeviceList.get(i).
+ getDeviceStatus() == DeviceStatus.ON) ? "ON" : "OFF")
+ );
+ }
+ } else {
+ publishProgress(TAG + "No Owned devices present");
}
- } else {
- publishProgress(TAG + "No Owned devices present");
+ } catch (OcException e) {
+ publishProgress(TAG + "Owned device Discovery error: " + e.getMessage());
+ return "Owned device Discovery error: " + e.getMessage();
}
- } catch (OcException e) {
- publishProgress(TAG + "Owned device Discovery error: " + e.getMessage());
- return "Owned device Discovery error: " + e.getMessage();
+ return "success";
}
- return "success";
- }
@Override
- protected void onProgressUpdate(String... values) {
- logMessage(values[0]);
- }
+ protected void onProgressUpdate(String... values) {
+ logMessage(values[0]);
+ }
@Override
- protected void onPostExecute(String s) {
+ protected void onPostExecute(String s) {
- if (ownedDeviceList.size() > 0 && "success".equals(s)) {
- doDPProvisioning();
- }
+ if (ownedDeviceList.size() == 1 && "success".equals(s)) {
+ doDPProvisioning();
+ }
+ if (ownedDeviceList.size() > 1 && "success".equals(s)) {
+ doPairwiseProvisioning();
+ }
- if (ownedDeviceList.size() > 1 && "success".equals(s)) {
- doPairwiseProvisioning();
}
- }
}
/**
*/
public class MessageReceiver extends BroadcastReceiver {
@Override
- public void onReceive(Context context, Intent intent) {
- final String message = intent.getStringExtra(StringConstants.MESSAGE);
- logMessage(message);
- }
+ public void onReceive(Context context, Intent intent) {
+ final String message = intent.getStringExtra(StringConstants.MESSAGE);
+ logMessage(message);
+ }
}
}
public static final int ERROR_CODE = 1;
public static final String DEFAULT_ROWNER_ID = "61646d69-6e44-6576-6963-655555494430";
public static final String DEFAULT_RESOURCES = "*";
- public static final String DEFAULT_RECURRENCES = "Daily";
+ public static final String HREF_RESOURCES_1A = "/a/device1a";
+ public static final String HREF_RESOURCES_1B = "/a/device1b";
+ public static final String HREF_RESOURCES_2A = "/a/device2a";
+ public static final String HREF_RESOURCES_2B = "/a/device2b";
+ public static final String RESOURCE_TYPE_1A = "oic.wk.dev1a";
+ public static final String RESOURCE_TYPE_1B = "oic.wk.dev1b";
+ public static final String RESOURCE_TYPE_2A = "oic.wk.dev2a";
+ public static final String RESOURCE_TYPE_2B = "oic.wk.dev2b";
+
+
+ public static final String DEFAULT_SUBJECT_ID1 = "44446d69-6e44-6576-6963-655555494430";
+ public static final String DEFAULT_SUBJECT_ID2 = "55556d69-6e44-6576-6963-655555494430";
+
+ public static final String RESOURCE_INTERFACE_1 = "oic.if.baseline";
+ public static final String RESOURCE_INTERFACE_2 = "oic.if.r";
+
+
+ public static final String DEFAULT_RECURRENCES_1 = "Daily";
+ public static final String DEFAULT_RECURRENCES_2 = "Weekly";
public static final String DEFAULT_PERIOD = "12-12-16";
public static final int DEFAULT_PERMISSION = 31;
public static final String OIC_CLIENT_CBOR_DB_FILE = "oic_svr_db_client.dat";