+
+OCStackResult OCSetHeaderOption(OCHeaderOption* ocHdrOpt, size_t* numOptions, uint16_t optionID,
+ const void* optionData, size_t optionDataLength)
+{
+ if (!ocHdrOpt)
+ {
+ OIC_LOG (INFO, TAG, "Header options are NULL");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ if (!optionData)
+ {
+ OIC_LOG (INFO, TAG, "optionData are NULL");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ if (!numOptions)
+ {
+ OIC_LOG (INFO, TAG, "numOptions is NULL");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ if (*numOptions >= MAX_HEADER_OPTIONS)
+ {
+ OIC_LOG (INFO, TAG, "Exceeding MAX_HEADER_OPTIONS");
+ return OC_STACK_NO_MEMORY;
+ }
+
+ ocHdrOpt += *numOptions;
+ ocHdrOpt->protocolID = OC_COAP_ID;
+ ocHdrOpt->optionID = optionID;
+ ocHdrOpt->optionLength =
+ optionDataLength < MAX_HEADER_OPTION_DATA_LENGTH ?
+ optionDataLength : MAX_HEADER_OPTION_DATA_LENGTH;
+ memcpy(ocHdrOpt->optionData, (const void*) optionData, ocHdrOpt->optionLength);
+ *numOptions += 1;
+
+ return OC_STACK_OK;
+}
+
+OCStackResult OCGetHeaderOption(OCHeaderOption* ocHdrOpt, size_t numOptions, uint16_t optionID,
+ void* optionData, size_t optionDataLength, uint16_t* receivedDataLength)
+{
+ if (!ocHdrOpt || !numOptions)
+ {
+ OIC_LOG (INFO, TAG, "No options present");
+ return OC_STACK_OK;
+ }
+
+ if (!optionData)
+ {
+ OIC_LOG (INFO, TAG, "optionData are NULL");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ if (!receivedDataLength)
+ {
+ OIC_LOG (INFO, TAG, "receivedDataLength is NULL");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ for (uint8_t i = 0; i < numOptions; i++)
+ {
+ if (ocHdrOpt[i].optionID == optionID)
+ {
+ if (optionDataLength >= ocHdrOpt->optionLength)
+ {
+ memcpy(optionData, ocHdrOpt->optionData, ocHdrOpt->optionLength);
+ *receivedDataLength = ocHdrOpt->optionLength;
+ return OC_STACK_OK;
+ }
+ else
+ {
+ OIC_LOG (ERROR, TAG, "optionDataLength is less than the length of received data");
+ return OC_STACK_ERROR;
+ }
+ }
+ }
+ return OC_STACK_OK;
+}
+
+void OCDefaultAdapterStateChangedHandler(CATransportAdapter_t adapter, bool enabled)
+{
+ OIC_LOG(DEBUG, TAG, "OCDefaultAdapterStateChangedHandler");
+
+ OC_UNUSED(adapter);
+ OC_UNUSED(enabled);
+}
+
+void OCDefaultConnectionStateChangedHandler(const CAEndpoint_t *info, bool isConnected)
+{
+ OIC_LOG(DEBUG, TAG, "OCDefaultConnectionStateChangedHandler");
+
+ /*
+ * If the client observes one or more resources over a reliable connection,
+ * then the CoAP server (or intermediary in the role of the CoAP server)
+ * MUST remove all entries associated with the client endpoint from the lists
+ * of observers when the connection is either closed or times out.
+ */
+ if (!isConnected)
+ {
+ OCDevAddr devAddr = { OC_DEFAULT_ADAPTER };
+ CopyEndpointToDevAddr(info, &devAddr);
+
+ // remove observer list with remote device address.
+ DeleteObserverUsingDevAddr(&devAddr);
+ }
+}
+
+OCStackResult OCGetDeviceId(OCUUIdentity *deviceId)
+{
+ OicUuid_t oicUuid;
+ OCStackResult ret = OC_STACK_ERROR;
+
+ ret = GetDoxmDeviceID(&oicUuid);
+ if (OC_STACK_OK == ret)
+ {
+ memcpy(deviceId, &oicUuid, UUID_IDENTITY_SIZE);
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "Device ID Get error");
+ }
+ return ret;
+}
+
+OCStackResult OCSetDeviceId(const OCUUIdentity *deviceId)
+{
+ OicUuid_t oicUuid;
+ OCStackResult ret = OC_STACK_ERROR;
+
+ memcpy(&oicUuid, deviceId, UUID_LENGTH);
+ for (int i = 0; i < UUID_LENGTH; i++)
+ {
+ OIC_LOG_V(INFO, TAG, "Set Device Id %x", oicUuid.id[i]);
+ }
+ ret = SetDoxmDeviceID(&oicUuid);
+ return ret;
+}
+
+OCStackResult OCGetDeviceOwnedState(bool *isOwned)
+{
+ bool isDeviceOwned = true;
+ OCStackResult ret = OC_STACK_ERROR;
+
+ ret = GetDoxmIsOwned(&isDeviceOwned);
+ if (OC_STACK_OK == ret)
+ {
+ *isOwned = isDeviceOwned;
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "Device Owned State Get error");
+ }
+ return ret;
+}
+
+OCStackResult OCGetDeviceOperationalState(bool* isOp)
+{
+ if(NULL != isOp)
+ {
+ *isOp = GetPstatIsop();
+ return OC_STACK_OK;
+ }
+
+ return OC_STACK_ERROR;
+}
+
+void OCClearCallBackList()
+{
+ DeleteClientCBList();
+}
+
+void OCClearObserverlist()
+{
+ DeleteObserverList();
+}
+
+int OCEncrypt(const unsigned char *pt, size_t pt_len,
+ unsigned char **ct, size_t *ct_len)
+{
+#ifndef __SECURE_PSI__
+ OIC_LOG_V(DEBUG, TAG, "Not Supported : %s", __func__);
+ return 0;
+#else
+ OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+
+ return psiEncrypt(pt, pt_len, ct, ct_len);
+#endif // __SECURE_PSI__
+}
+
+int OCDecrypt(const unsigned char *ct, size_t ct_len,
+ unsigned char **pt, size_t *pt_len)
+{
+#ifndef __SECURE_PSI__
+ OIC_LOG_V(DEBUG, TAG, "Not Supported : %s", __func__);
+ return 0;
+#else
+ OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+
+ return psiDecrypt(ct, ct_len, pt, pt_len);
+#endif // __SECURE_PSI__
+}
+
+OCStackResult OCSetKey(const unsigned char* key)
+{
+#ifndef __SECURE_PSI__
+ OIC_LOG_V(DEBUG, TAG, "Not Supported : %s", __func__);
+ return OC_STACK_OK;
+#else
+ OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+
+ return psiSetKey(key);
+#endif // __SECURE_PSI__
+}
+
+OCStackResult OCGetKey(unsigned char* key)
+{
+#ifndef __SECURE_PSI__
+ OIC_LOG_V(DEBUG, TAG, "Not Supported : %s", __func__);
+ return OC_STACK_OK;
+#else
+ OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+
+ return psiGetKey(key);
+#endif // __SECURE_PSI__
+}
+
+OCStackResult OCSetSecurePSI(const unsigned char *key, const OCPersistentStorage *psPlain,
+ const OCPersistentStorage *psEnc, const OCPersistentStorage *psRescue)
+{
+#ifndef __SECURE_PSI__
+ OIC_LOG_V(DEBUG, TAG, "Not Supported : %s", __func__);
+ return OC_STACK_OK;
+#else
+ OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+
+ return setSecurePSI(key, psPlain, psEnc, psRescue);
+#endif // __SECURE_PSI__
+}
+
+#if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
+static void OtmEventHandler(const char *addr, uint16_t port, const char *uuid, int event)
+{
+ if (g_otmEventHandler.cb)
+ {
+ g_otmEventHandler.cb(g_otmEventHandler.ctx, addr, port, uuid, event);
+ }
+}
+
+/* TODO Work-around
+ * It is already declared in srmutility.h.
+ * We can't include the header file, because of "redefined VERIFY_NON_NULL"
+ */
+typedef void (*OicSecOtmEventHandler_t)(const char* addr, uint16_t port,
+ const char* uuid, int event);
+void SetOtmEventHandler(OicSecOtmEventHandler_t otmEventHandler);
+#endif
+
+OCStackResult OCSetOtmEventHandler(void *ctx, OCOtmEventHandler cb)
+{
+#if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
+ OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+
+ g_otmEventHandler.cb = cb;
+ g_otmEventHandler.ctx = ctx;
+
+ if (g_otmEventHandler.cb)
+ {
+ OIC_LOG(DEBUG, TAG, "SET OCOtmEventHandler");
+ SetOtmEventHandler(OtmEventHandler);
+ }
+ else
+ {
+ OIC_LOG(DEBUG, TAG, "UNSET OCOtmEventHandler");
+ SetOtmEventHandler(NULL);
+ }
+#else
+ OIC_LOG_V(DEBUG, TAG, "Not Supported : %s", __func__);
+ OC_UNUSED(ctx);
+ OC_UNUSED(cb);
+#endif
+ return OC_STACK_OK;
+}