{
if(NULL == addr || NULL == *ppDevicesList)
{
- OC_LOG_V(ERROR, TAG, "Invalid Input parameters in [%s]\n", __FUNCTION__);
+ OIC_LOG_V(ERROR, TAG, "Invalid Input parameters in [%s]\n", __FUNCTION__);
return NULL;
}
ptr = (OCProvisionDev_t *)OICCalloc(1, sizeof (OCProvisionDev_t));
if (NULL == ptr)
{
- OC_LOG(ERROR, TAG, "Error while allocating memory for linkedlist node !!");
+ OIC_LOG(ERROR, TAG, "Error while allocating memory for linkedlist node !!");
return OC_STACK_NO_MEMORY;
}
ptr->endpoint.adapter = adapter;
ptr->next = NULL;
ptr->connType = connType;
+ ptr->devStatus = DEV_STATUS_ON; //AddDevice is called when discovery(=alive)
LL_PREPEND(*ppDevicesList, ptr);
}
if(!ptr)
{
- OC_LOG(ERROR, TAG, "Can not find device information in the discovery device list");
+ OIC_LOG(ERROR, TAG, "Can not find device information in the discovery device list");
return OC_STACK_ERROR;
}
OCProvisionDev_t* PMCloneOCProvisionDev(const OCProvisionDev_t* src)
{
- OC_LOG(DEBUG, TAG, "IN PMCloneOCProvisionDev");
+ OIC_LOG(DEBUG, TAG, "IN PMCloneOCProvisionDev");
if (!src)
{
- OC_LOG(ERROR, TAG, "PMCloneOCProvisionDev : Invalid parameter");
+ OIC_LOG(ERROR, TAG, "PMCloneOCProvisionDev : Invalid parameter");
return NULL;
}
}
newDev->securePort = src->securePort;
- //TODO: Below comment line should be activated after 2333 change is merged
- //newDev->devStatus = src->devStatus;
+ newDev->devStatus = src->devStatus;
newDev->connType = src->connType;
newDev->next = NULL;
- OC_LOG(DEBUG, TAG, "OUT PMCloneOCProvisionDev");
+ OIC_LOG(DEBUG, TAG, "OUT PMCloneOCProvisionDev");
return newDev;
exit:
- OC_LOG(ERROR, TAG, "PMCloneOCProvisionDev : Failed to allocate memory");
+ OIC_LOG(ERROR, TAG, "PMCloneOCProvisionDev : Failed to allocate memory");
if (newDev)
{
OICFree(newDev->pstat);
{
if(!address || !buffer || !uri)
{
- OC_LOG(ERROR, TAG, "PMGenerateQuery : Invalid parameters.");
+ OIC_LOG(ERROR, TAG, "PMGenerateQuery : Invalid parameters.");
return false;
}
switch(connType & CT_MASK_ADAPTER)
{
case CT_ADAPTER_IP:
- switch(connType & CT_MASK_FLAGS)
+ switch(connType & CT_MASK_FLAGS & ~CT_FLAG_SECURE)
{
case CT_IP_USE_V4:
snRet = snprintf(buffer, bufferSize, "%s%s:%d%s",
prefix, address, port, uri);
break;
default:
- OC_LOG(ERROR, TAG, "Unknown address format.");
+ OIC_LOG(ERROR, TAG, "Unknown address format.");
return false;
}
- if(snRet >= bufferSize)
+ // snprintf return value check
+ if (snRet < 0)
{
- OC_LOG(ERROR, TAG, "PMGenerateQuery : URI is too long");
+ OIC_LOG_V(ERROR, TAG, "PMGenerateQuery : Error (snprintf) %d\n", snRet);
return false;
}
+ else if ((size_t)snRet >= bufferSize)
+ {
+ OIC_LOG_V(ERROR, TAG, "PMGenerateQuery : Truncated (snprintf) %d\n", snRet);
+ return false;
+ }
+
break;
// TODO: We need to verify tinyDTLS in below cases
case CT_ADAPTER_GATT_BTLE:
case CT_ADAPTER_RFCOMM_BTEDR:
- OC_LOG(ERROR, TAG, "Not supported connectivity adapter.");
+ OIC_LOG(ERROR, TAG, "Not supported connectivity adapter.");
return false;
break;
default:
- OC_LOG(ERROR, TAG, "Unknown connectivity adapter.");
+ OIC_LOG(ERROR, TAG, "Unknown connectivity adapter.");
return false;
}
{
if (ctx == NULL)
{
- OC_LOG(ERROR, TAG, "Lost List of device information");
- return OC_STACK_KEEP_TRANSACTION;
+ OIC_LOG(ERROR, TAG, "Lost List of device information");
+ return OC_STACK_DELETE_TRANSACTION;
}
(void)UNUSED;
if (clientResponse)
{
if (NULL == clientResponse->payload)
{
- OC_LOG(INFO, TAG, "Skiping Null payload");
+ OIC_LOG(INFO, TAG, "Skiping Null payload");
}
else
{
if (PAYLOAD_TYPE_DISCOVERY != clientResponse->payload->type)
{
- OC_LOG(INFO, TAG, "Wrong payload type");
- return OC_STACK_KEEP_TRANSACTION;
+ OIC_LOG(INFO, TAG, "Wrong payload type");
+ return OC_STACK_DELETE_TRANSACTION;
}
uint16_t securePort = 0;
}
else
{
- OC_LOG(INFO, TAG, "Can not find secure port information.");
- return OC_STACK_KEEP_TRANSACTION;
+ OIC_LOG(INFO, TAG, "Can not find secure port information.");
+ return OC_STACK_DELETE_TRANSACTION;
}
DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
clientResponse->devAddr.port, securePort);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "Error while getting secure port.");
- return OC_STACK_KEEP_TRANSACTION;
+ OIC_LOG(ERROR, TAG, "Error while getting secure port.");
+ return OC_STACK_DELETE_TRANSACTION;
}
- OC_LOG(INFO, TAG, "Exiting SecurePortDiscoveryHandler.");
+ OIC_LOG(INFO, TAG, "Exiting SecurePortDiscoveryHandler.");
}
- return OC_STACK_KEEP_TRANSACTION;
+ return OC_STACK_DELETE_TRANSACTION;
}
else
{
- OC_LOG(INFO, TAG, "Skiping Null response");
+ OIC_LOG(INFO, TAG, "Skiping Null response");
}
return OC_STACK_DELETE_TRANSACTION;
}
{
if (ctx == NULL)
{
- OC_LOG(ERROR, TAG, "Lost List of device information");
+ OIC_LOG(ERROR, TAG, "Lost List of device information");
return OC_STACK_KEEP_TRANSACTION;
}
(void)UNUSED;
{
if (NULL == clientResponse->payload)
{
- OC_LOG(INFO, TAG, "Skiping Null payload");
+ OIC_LOG(INFO, TAG, "Skiping Null payload");
return OC_STACK_KEEP_TRANSACTION;
}
if (OC_STACK_OK != clientResponse->result)
{
- OC_LOG(INFO, TAG, "Error in response");
+ OIC_LOG(INFO, TAG, "Error in response");
return OC_STACK_KEEP_TRANSACTION;
}
else
{
if (PAYLOAD_TYPE_SECURITY != clientResponse->payload->type)
{
- OC_LOG(INFO, TAG, "Unknown payload type");
+ OIC_LOG(INFO, TAG, "Unknown payload type");
return OC_STACK_KEEP_TRANSACTION;
}
OicSecDoxm_t *ptrDoxm = JSONToDoxmBin(
((OCSecurityPayload*)clientResponse->payload)->securityData);
if (NULL == ptrDoxm)
{
- OC_LOG(INFO, TAG, "Ignoring malformed JSON");
+ OIC_LOG(INFO, TAG, "Ignoring malformed JSON");
return OC_STACK_KEEP_TRANSACTION;
}
else
{
- OC_LOG(DEBUG, TAG, "Successfully converted doxm json to bin.");
+ OIC_LOG(DEBUG, TAG, "Successfully converted doxm json to bin.");
//If this is owend device discovery we have to filter out the responses.
DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
OCStackResult res = GetDoxmDevOwnerId(&myId);
if(OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "Error while getting my device ID.");
+ OIC_LOG(ERROR, TAG, "Error while getting my device ID.");
DeleteDoxmBinData(ptrDoxm);
return OC_STACK_KEEP_TRANSACTION;
}
if( (pDInfo->isOwnedDiscovery) &&
(0 != memcmp(&ptrDoxm->owner.id, &myId.id, sizeof(myId.id))) )
{
- OC_LOG(DEBUG, TAG, "Discovered device is not owend by me");
+ OIC_LOG(DEBUG, TAG, "Discovered device is not owend by me");
DeleteDoxmBinData(ptrDoxm);
return OC_STACK_KEEP_TRANSACTION;
}
clientResponse->connType, ptrDoxm);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "Error while adding data to linkedlist.");
+ OIC_LOG(ERROR, TAG, "Error while adding data to linkedlist.");
DeleteDoxmBinData(ptrDoxm);
return OC_STACK_KEEP_TRANSACTION;
}
-
+ char rsrc_uri[MAX_URI_LENGTH+1] = {0};
+ int wr_len = snprintf(rsrc_uri, sizeof(rsrc_uri), "%s?%s=%s",
+ OC_RSRVD_WELL_KNOWN_URI, OC_RSRVD_RESOURCE_TYPE, OIC_RSRC_TYPE_SEC_DOXM);
+ if(wr_len <= 0 || (size_t)wr_len >= sizeof(rsrc_uri))
+ {
+ OIC_LOG(ERROR, TAG, "rsrc_uri_string_print failed");
+ return OC_STACK_ERROR;
+ }
//Try to the unicast discovery to getting secure port
- char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = { 0, };
+ char query[MAX_URI_LENGTH+MAX_QUERY_LENGTH+1] = {0};
if(!PMGenerateQuery(false,
clientResponse->devAddr.addr, clientResponse->devAddr.port,
clientResponse->connType,
- query, sizeof(query), OC_RSRVD_WELL_KNOWN_URI))
+ query, sizeof(query), rsrc_uri))
{
- OC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
return OC_STACK_KEEP_TRANSACTION;
}
- OC_LOG_V(DEBUG, TAG, "Query=%s", query);
+ OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData;
cbData.cb = &SecurePortDiscoveryHandler;
cbData.context = ctx;
cbData.cd = NULL;
- OCStackResult ret = OCDoResource(NULL, OC_REST_GET, query, 0, 0,
+ OCStackResult ret = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
clientResponse->connType, OC_LOW_QOS, &cbData, NULL, 0);
// TODO: Should we use the default secure port in case of error?
if(OC_STACK_OK != ret)
{
- OC_LOG(ERROR, TAG, "Failed to Secure Port Discovery");
+ OIC_LOG(ERROR, TAG, "Failed to Secure Port Discovery");
return OC_STACK_KEEP_TRANSACTION;
}
else
{
- OC_LOG_V(INFO, TAG, "OCDoResource with [%s] Success", query);
+ OIC_LOG_V(INFO, TAG, "OCDoResource with [%s] Success", query);
}
- OC_LOG(INFO, TAG, "Exiting ProvisionDiscoveryHandler.");
+ OIC_LOG(INFO, TAG, "Exiting ProvisionDiscoveryHandler.");
}
return OC_STACK_KEEP_TRANSACTION;
}
else
{
- OC_LOG(INFO, TAG, "Skiping Null response");
+ OIC_LOG(INFO, TAG, "Skiping Null response");
return OC_STACK_KEEP_TRANSACTION;
}
*/
OCStackResult PMDeviceDiscovery(unsigned short waittime, bool isOwned, OCProvisionDev_t **ppDevicesList)
{
- OC_LOG(DEBUG, TAG, "IN PMDeviceDiscovery");
+ OIC_LOG(DEBUG, TAG, "IN PMDeviceDiscovery");
if (NULL != *ppDevicesList)
{
- OC_LOG(ERROR, TAG, "List is not null can cause memory leak");
+ OIC_LOG(ERROR, TAG, "List is not null can cause memory leak");
return OC_STACK_INVALID_PARAM;
}
DiscoveryInfo *pDInfo = OICCalloc(1, sizeof(DiscoveryInfo));
if(NULL == pDInfo)
{
- OC_LOG(ERROR, TAG, "PMDeviceDiscovery : Memory allocation failed.");
+ OIC_LOG(ERROR, TAG, "PMDeviceDiscovery : Memory allocation failed.");
return OC_STACK_NO_MEMORY;
}
const char* query = isOwned ? DOXM_OWNED_TRUE_MULTICAST_QUERY :
DOXM_OWNED_FALSE_MULTICAST_QUERY;
- res = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
+ OCDoHandle handle = NULL;
+ res = OCDoResource(&handle, OC_REST_DISCOVER, query, 0, 0,
CT_DEFAULT, OC_LOW_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack resource error");
- goto exit;
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
+ OICFree(pDInfo);
+ return res;
}
//Waiting for each response.
res = PMTimeout(waittime, true);
if(OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "Failed to wait response for secure discovery.");
- goto exit;
+ OIC_LOG(ERROR, TAG, "Failed to wait response for secure discovery.");
+ OICFree(pDInfo);
+ OCStackResult resCancel = OCCancel(handle, OC_LOW_QOS, NULL, 0);
+ if(OC_STACK_OK != resCancel)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to remove registered callback");
+ }
+ return res;
}
-
- OC_LOG(DEBUG, TAG, "OUT PMDeviceDiscovery");
-
-exit:
+ res = OCCancel(handle,OC_LOW_QOS,NULL,0);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to remove registered callback");
+ OICFree(pDInfo);
+ return res;
+ }
+ OIC_LOG(DEBUG, TAG, "OUT PMDeviceDiscovery");
OICFree(pDInfo);
return res;
}
/**
* Function to print OCProvisionDev_t for debug purpose.
*
- * @param[in] pDev Pointer to OCProvisionDev_t. It's information will be printed by OC_LOG_XX
+ * @param[in] pDev Pointer to OCProvisionDev_t. It's information will be printed by OIC_LOG_XX
*
*/
void PMPrintOCProvisionDev(const OCProvisionDev_t* pDev)
{
if (pDev)
{
- OC_LOG(DEBUG, TAG, "+++++ OCProvisionDev_t Information +++++");
- OC_LOG_V(DEBUG, TAG, "IP %s", pDev->endpoint.addr);
- OC_LOG_V(DEBUG, TAG, "PORT %d", pDev->endpoint.port);
- OC_LOG_V(DEBUG, TAG, "S-PORT %d", pDev->securePort);
- OC_LOG(DEBUG, TAG, "++++++++++++++++++++++++++++++++++++++++");
+ OIC_LOG(DEBUG, TAG, "+++++ OCProvisionDev_t Information +++++");
+ OIC_LOG_V(DEBUG, TAG, "IP %s", pDev->endpoint.addr);
+ OIC_LOG_V(DEBUG, TAG, "PORT %d", pDev->endpoint.port);
+ OIC_LOG_V(DEBUG, TAG, "S-PORT %d", pDev->securePort);
+ OIC_LOG(DEBUG, TAG, "++++++++++++++++++++++++++++++++++++++++");
}
else
{
- OC_LOG(DEBUG, TAG, "+++++ OCProvisionDev_t is NULL +++++");
+ OIC_LOG(DEBUG, TAG, "+++++ OCProvisionDev_t is NULL +++++");
}
}