/** * This internal method handles RD discovery request. * Responds with the RD discovery payload message. */ static OCEntityHandlerResult handleGetRequest(const OCEntityHandlerRequest *ehRequest) { if (!ehRequest) { OIC_LOG(DEBUG, TAG, "Invalid request pointer."); return OC_EH_ERROR; } OCEntityHandlerResult ehResult = OC_EH_OK; OIC_LOG_V(DEBUG, TAG, "Received OC_REST_GET from client with query: %s.", ehRequest->query); OCRDPayload *rdPayload = OCRDPayloadCreate(); if (!rdPayload) { return OC_STACK_NO_MEMORY; } rdPayload->rdDiscovery = OCRDDiscoveryPayloadCreate(NULL, OCGetServerInstanceIDString(), OC_RD_DISC_SEL); if (!rdPayload->rdDiscovery) { OCRDPayloadDestroy(rdPayload); return OC_STACK_NO_MEMORY; } OIC_LOG_PAYLOAD(DEBUG, (OCPayload *) rdPayload); if (sendResponse(ehRequest, rdPayload) != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "Sending response failed."); ehResult = OC_EH_ERROR; } return ehResult; }
/** * This functions will replace the get_ap_scan_result(~~) */ static OCEntityHandlerResult get_provisioning_info(things_resource_s *target_resource) { OCEntityHandlerResult eh_result = OC_EH_ERROR; const char *device_id = OCGetServerInstanceIDString(); const char *device_rt = dm_get_things_device_type(0); bool is_owned = false; bool is_reset = things_get_reset_mask(RST_ALL_FLAG); if (OC_STACK_OK != OCGetDeviceOwnedState(&is_owned)) { THINGS_LOG_E(TAG, "Failed to get device owned state, Informing as UNOWNED~!!!!"); is_owned = false; } if (target_resource->rep == NULL) { things_representation_s *pstRep = NULL; pstRep = things_create_representation_inst(NULL); target_resource->things_set_representation(target_resource, pstRep); } things_representation_s *child_rep[1] = { NULL }; child_rep[0] = things_create_representation_inst(NULL); child_rep[0]->things_set_value(child_rep[0], SEC_ATTRIBUTE_PROV_TARGET_ID, device_id); child_rep[0]->things_set_value(child_rep[0], SEC_ATTRIBUTE_PROV_TARGET_RT, device_rt); child_rep[0]->things_set_bool_value(child_rep[0], SEC_ATTRIBUTE_PROV_TARGET_PUBED, dm_is_rsc_published()); target_resource->rep->things_set_arrayvalue(target_resource->rep, SEC_ATTRIBUTE_PROV_TARGETS, 1, child_rep); target_resource->rep->things_set_bool_value(target_resource->rep, SEC_ATTRIBUTE_PROV_TARGET_OWNED, is_owned); target_resource->rep->things_set_value(target_resource->rep, SEC_ATTRIBUTE_PROV_EZSETDI, device_id); target_resource->rep->things_set_bool_value(target_resource->rep, SEC_ATTRIBUTE_PROV_RESET, is_reset); target_resource->rep->things_set_int_value(target_resource->rep, SEC_ATTRIBUTE_PROV_ABORT, 0); if (NULL != child_rep[0]) { things_release_representation_inst(child_rep[0]); } eh_result = OC_EH_OK; return eh_result; }
void set_platform_info(things_server_builder_s *builder, char *model_num, char *pver, char *osver, char *hwver, char *fwver, char *venderid, char *mnmn, char *mn_url) { THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY); if (model_num == NULL || strlen(model_num) < 1) { THINGS_LOG_E(TAG, "Invalid input for registering platform Info"); return; } THINGS_LOG_D(TAG, "[/oic/p] Manufacturer :%s", mnmn); THINGS_LOG_D(TAG, "[/oic/p] Model Name :%s", model_num); THINGS_LOG_D(TAG, "[/oic/p] Ver. Plaform :%s", pver); THINGS_LOG_D(TAG, "[/oic/p] Ver. OS :%s", osver); THINGS_LOG_D(TAG, "[/oic/p] Ver. HW :%s", hwver); THINGS_LOG_D(TAG, "[/oic/p] Ver. FW :%s", fwver); THINGS_LOG_D(TAG, "[/oic/p] Ver. vid :%s", venderid); OCPlatformInfo platform_info; platform_info.platformID = (char *)OCGetServerInstanceIDString(); platform_info.manufacturerName = mnmn; platform_info.modelNumber = model_num; platform_info.platformVersion = pver; platform_info.operatingSystemVersion = osver; platform_info.hardwareVersion = hwver; platform_info.firmwareVersion = fwver; platform_info.manufacturerUrl = mn_url; platform_info.dateOfManufacture = NULL; platform_info.supportUrl = NULL; platform_info.systemTime = NULL; iotivity_api_lock(); OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, KEY_ATTR_PLATFORM_VENDERID, venderid); OCSetPlatformInfo(platform_info); iotivity_api_unlock(); THINGS_LOG_D(TAG, THINGS_FUNC_EXIT); }
OCRDPayload *OCRDPublishPayloadCreate(OCResourceHandle resourceHandles[], uint8_t nHandles, uint64_t ttl) { OCTagsPayload *tagsPayload = NULL; OCLinksPayload *linksPayload = NULL; OCStringLL *rt = NULL; OCStringLL *itf = NULL; OCStringLL *mt = NULL; OCResourceProperty p = OC_RES_PROP_NONE; uint8_t ins = 0; OCRDPayload *rdPayload = OCRDPayloadCreate(); if (!rdPayload) { return NULL; } const unsigned char *id = (const unsigned char *) OCGetServerInstanceIDString(); tagsPayload = OCCopyTagsResources(NULL, id, ttl); if (!tagsPayload) { goto exit; } for (uint8_t j = 0; j < nHandles; j++) { OCResourceHandle handle = resourceHandles[j]; if (handle) { rt = NULL; itf = NULL; mt = NULL; ins = 0; const char *uri = OCGetResourceUri(handle); uint8_t numElement = 0; if (OC_STACK_OK == OCGetNumberOfResourceTypes(handle, &numElement)) { OCStackResult res = CreateStringLL(numElement, handle, OCGetResourceTypeName, &rt); if (OC_STACK_OK != res || !rt) { goto exit; } } if (OC_STACK_OK == OCGetNumberOfResourceInterfaces(handle, &numElement)) { OCStackResult res = CreateStringLL(numElement, handle, OCGetResourceInterfaceName, &itf); if (OC_STACK_OK != res || !itf) { goto exit; } } p = OCGetResourceProperties(handle); p = (OCResourceProperty) ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)); OCStackResult res = OCGetResourceIns(handle, &ins); if (OC_STACK_OK != res) { goto exit; } mt = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); if (!mt) { goto exit; } mt->value = OICStrdup(DEFAULT_MESSAGE_TYPE); if (!mt->value) { goto exit; } if (!linksPayload) { linksPayload = OCCopyLinksResources(uri, NULL, rt, itf, p, NULL, NULL, ins, ttl, mt);; if (!linksPayload) { goto exit; } } else { OCLinksPayload *temp = linksPayload; while (temp->next) { temp = temp->next; } temp->next = OCCopyLinksResources(uri, NULL, rt, itf, p, NULL, NULL, ins, ttl, mt); if (!temp->next) { goto exit; } } OCFreeOCStringLL(rt); OCFreeOCStringLL(itf); OCFreeOCStringLL(mt); } } rdPayload->rdPublish = OCCopyCollectionResource(tagsPayload, linksPayload); if (!rdPayload->rdPublish) { goto exit; } return rdPayload; exit: if (rt) { OCFreeOCStringLL(rt); } if (itf) { OCFreeOCStringLL(itf); } if (mt) { OCFreeOCStringLL(mt); } if (tagsPayload) { OCFreeTagsResource(tagsPayload); } if (linksPayload) { OCFreeLinksResource(linksPayload); } OCRDPayloadDestroy(rdPayload); return NULL; }