Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / src / pmutility.c
1 /* *****************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * *****************************************************************/
20 #ifndef _POSIX_C_SOURCE
21 #define _POSIX_C_SOURCE 200112L
22 #endif
23
24 #include <unistd.h>
25 #include <string.h>
26 #include <time.h>
27 #include <sys/time.h>
28
29 #include "ocstack.h"
30 #include "oic_malloc.h"
31 #include "oic_string.h"
32 #include "logger.h"
33 #include "cJSON.h"
34 #include "utlist.h"
35 #include "ocpayload.h"
36
37 #include "securevirtualresourcetypes.h"
38 #include "srmresourcestrings.h" //@note: SRM's internal header
39 #include "doxmresource.h"       //@note: SRM's internal header
40 #include "pstatresource.h"      //@note: SRM's internal header
41
42 #include "pmtypes.h"
43 #include "pmutility.h"
44
45 #include "srmutility.h"
46
47 #define TAG ("PM-UTILITY")
48
49 typedef struct _DiscoveryInfo{
50     OCProvisionDev_t    **ppDevicesList;
51     bool                isOwnedDiscovery;
52 } DiscoveryInfo;
53
54 /**
55  * Function to search node in linked list that matches given IP and port.
56  *
57  * @param[in] pList         List of OCProvisionDev_t.
58  * @param[in] addr          address of target device.
59  * @param[in] port          port of remote server.
60  *
61  * @return pointer of OCProvisionDev_t if exist, otherwise NULL
62  */
63 OCProvisionDev_t* GetDevice(OCProvisionDev_t **ppDevicesList, const char* addr, const uint16_t port)
64 {
65     if(NULL == addr || NULL == *ppDevicesList)
66     {
67         OC_LOG_V(ERROR, TAG, "Invalid Input parameters in [%s]\n", __FUNCTION__);
68         return NULL;
69     }
70
71     OCProvisionDev_t *ptr = NULL;
72     LL_FOREACH(*ppDevicesList, ptr)
73     {
74         if( strcmp(ptr->endpoint.addr, addr) == 0 && port == ptr->endpoint.port)
75         {
76             return ptr;
77         }
78     }
79
80     return NULL;
81 }
82
83
84 /**
85  * Add device information to list.
86  *
87  * @param[in] pList         List of OCProvisionDev_t.
88  * @param[in] addr          address of target device.
89  * @param[in] port          port of remote server.
90  * @param[in] adapter       adapter type of endpoint.
91  * @param[in] doxm          pointer to doxm instance.
92  * @param[in] connType  connectivity type of endpoint
93  *
94  * @return OC_STACK_OK for success and errorcode otherwise.
95  */
96 OCStackResult AddDevice(OCProvisionDev_t **ppDevicesList, const char* addr, const uint16_t port,
97                         OCTransportAdapter adapter, OCConnectivityType connType, OicSecDoxm_t *doxm)
98 {
99     if (NULL == addr)
100     {
101         return OC_STACK_INVALID_PARAM;
102     }
103
104     OCProvisionDev_t *ptr = GetDevice(ppDevicesList, addr, port);
105     if(!ptr)
106     {
107         ptr = (OCProvisionDev_t *)OICCalloc(1, sizeof (OCProvisionDev_t));
108         if (NULL == ptr)
109         {
110             OC_LOG(ERROR, TAG, "Error while allocating memory for linkedlist node !!");
111             return OC_STACK_NO_MEMORY;
112         }
113
114         OICStrcpy(ptr->endpoint.addr, MAX_ADDR_STR_SIZE, addr);
115         ptr->endpoint.port = port;
116         ptr->doxm = doxm;
117         ptr->securePort = DEFAULT_SECURE_PORT;
118         ptr->endpoint.adapter = adapter;
119         ptr->next = NULL;
120         ptr->connType = connType;
121         ptr->devStatus = DEV_STATUS_ON; //AddDevice is called when discovery(=alive)
122
123         LL_PREPEND(*ppDevicesList, ptr);
124     }
125
126     return OC_STACK_OK;
127 }
128
129 /**
130  * Function to set secure port information from the given list of devices.
131  *
132  * @param[in] pList         List of OCProvisionDev_t.
133  * @param[in] addr          address of target device.
134  * @param[in] port          port of remote server.
135  * @param[in] secureport    secure port information.
136  *
137  * @return OC_STACK_OK for success and errorcode otherwise.
138  */
139 OCStackResult UpdateSecurePortOfDevice(OCProvisionDev_t **ppDevicesList, const char *addr,
140                                        uint16_t port, uint16_t securePort)
141 {
142     OCProvisionDev_t *ptr = GetDevice(ppDevicesList, addr, port);
143
144     if(!ptr)
145     {
146         OC_LOG(ERROR, TAG, "Can not find device information in the discovery device list");
147         return OC_STACK_ERROR;
148     }
149
150     ptr->securePort = securePort;
151
152     return OC_STACK_OK;
153 }
154
155 /**
156  * This function deletes list of provision target devices
157  *
158  * @param[in] pDevicesList         List of OCProvisionDev_t.
159  */
160 void PMDeleteDeviceList(OCProvisionDev_t *pDevicesList)
161 {
162     if(pDevicesList)
163     {
164         OCProvisionDev_t *del = NULL, *tmp = NULL;
165         LL_FOREACH_SAFE(pDevicesList, del, tmp)
166         {
167             LL_DELETE(pDevicesList, del);
168
169             DeleteDoxmBinData(del->doxm);
170             DeletePstatBinData(del->pstat);
171             OICFree(del);
172         }
173     }
174 }
175
176 OCProvisionDev_t* PMCloneOCProvisionDev(const OCProvisionDev_t* src)
177 {
178     OC_LOG(DEBUG, TAG, "IN PMCloneOCProvisionDev");
179
180     if (!src)
181     {
182         OC_LOG(ERROR, TAG, "PMCloneOCProvisionDev : Invalid parameter");
183         return NULL;
184     }
185
186     // TODO: Consider use VERIFY_NON_NULL instead of if ( null check ) { goto exit; }
187     OCProvisionDev_t* newDev = (OCProvisionDev_t*)OICCalloc(1, sizeof(OCProvisionDev_t));
188     VERIFY_NON_NULL(TAG, newDev, ERROR);
189
190     memcpy(&newDev->endpoint, &src->endpoint, sizeof(OCDevAddr));
191
192     if (src->pstat)
193     {
194         newDev->pstat= (OicSecPstat_t*)OICCalloc(1, sizeof(OicSecPstat_t));
195         VERIFY_NON_NULL(TAG, newDev->pstat, ERROR);
196
197         memcpy(newDev->pstat, src->pstat, sizeof(OicSecPstat_t));
198         // We have to assign NULL for not necessary information to prevent memory corruption.
199         newDev->pstat->sm = NULL;
200     }
201
202     if (src->doxm)
203     {
204         newDev->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
205         VERIFY_NON_NULL(TAG, newDev->doxm, ERROR);
206
207         memcpy(newDev->doxm, src->doxm, sizeof(OicSecDoxm_t));
208         // We have to assign NULL for not necessary information to prevent memory corruption.
209         newDev->doxm->oxmType = NULL;
210         newDev->doxm->oxm = NULL;
211     }
212
213     newDev->securePort = src->securePort;
214     newDev->devStatus = src->devStatus;
215     newDev->connType = src->connType;
216     newDev->next = NULL;
217
218     OC_LOG(DEBUG, TAG, "OUT PMCloneOCProvisionDev");
219
220     return newDev;
221
222 exit:
223     OC_LOG(ERROR, TAG, "PMCloneOCProvisionDev : Failed to allocate memory");
224     if (newDev)
225     {
226         OICFree(newDev->pstat);
227         OICFree(newDev->doxm);
228         OICFree(newDev);
229     }
230     return NULL;
231 }
232
233 /**
234  * Timeout implementation for secure discovery. When performing secure discovery,
235  * we should wait a certain period of time for getting response of each devices.
236  *
237  * @param[in]  waittime  Timeout in seconds.
238  * @param[in]  waitForStackResponse if true timeout function will call OCProcess while waiting.
239  * @return OC_STACK_OK on success otherwise error.
240  */
241 OCStackResult PMTimeout(unsigned short waittime, bool waitForStackResponse)
242 {
243     struct timespec startTime = {.tv_sec=0, .tv_nsec=0};
244     struct timespec currTime  = {.tv_sec=0, .tv_nsec=0};
245
246     OCStackResult res = OC_STACK_OK;
247 #ifdef _POSIX_MONOTONIC_CLOCK
248     int clock_res = clock_gettime(CLOCK_MONOTONIC, &startTime);
249 #else
250     int clock_res = clock_gettime(CLOCK_REALTIME, &startTime);
251 #endif
252     if (0 != clock_res)
253     {
254         return OC_STACK_ERROR;
255     }
256     while (OC_STACK_OK == res)
257     {
258 #ifdef _POSIX_MONOTONIC_CLOCK
259         clock_res = clock_gettime(CLOCK_MONOTONIC, &currTime);
260 #else
261         clock_res = clock_gettime(CLOCK_REALTIME, &currTime);
262 #endif
263         if (0 != clock_res)
264         {
265             return OC_STACK_TIMEOUT;
266         }
267         long elapsed = (currTime.tv_sec - startTime.tv_sec);
268         if (elapsed > waittime)
269         {
270             return OC_STACK_OK;
271         }
272         if (waitForStackResponse)
273         {
274             res = OCProcess();
275         }
276     }
277     return res;
278 }
279
280 /**
281  * Extract secure port information from payload of discovery response.
282  *
283  * @param[in] jsonStr response payload of /oic/res discovery.
284  *
285  * @return Secure port
286  */
287 uint16_t GetSecurePortFromJSON(char* jsonStr)
288 {
289     // TODO: Modify error handling
290     if (NULL == jsonStr)
291     {
292         return 0;
293     }
294     cJSON *jsonProp = NULL;
295     cJSON *jsonP = NULL;
296     cJSON *jsonPort = NULL;
297
298     cJSON *jsonRoot = cJSON_Parse(jsonStr);
299     if(!jsonRoot)
300     {
301         // TODO: Add error log & return default secure port
302         return 0;
303     }
304
305     jsonProp = cJSON_GetObjectItem(jsonRoot, "prop");
306     if(!jsonProp)
307     {
308         // TODO: Add error log & return default secure port
309         return 0;
310     }
311
312     jsonP = cJSON_GetObjectItem(jsonProp, "p");
313     if(!jsonP)
314     {
315         // TODO: Add error log & return default secure port
316         return 0;
317     }
318
319     jsonPort = cJSON_GetObjectItem(jsonP, "port");
320     if(!jsonPort)
321     {
322         // TODO: Add error log & return default secure port
323         return 0;
324     }
325
326     return (uint16_t)jsonPort->valueint;
327 }
328
329 bool PMGenerateQuery(bool isSecure,
330                      const char* address, const uint16_t port,
331                      const OCConnectivityType connType,
332                      char* buffer, size_t bufferSize, const char* uri)
333 {
334     if(!address || !buffer || !uri)
335     {
336         OC_LOG(ERROR, TAG, "PMGenerateQuery : Invalid parameters.");
337         return false;
338     }
339
340     int snRet = 0;
341     char* prefix = (isSecure == true) ? COAPS_PREFIX : COAP_PREFIX;
342
343     switch(connType & CT_MASK_ADAPTER)
344     {
345         case CT_ADAPTER_IP:
346             switch(connType & CT_MASK_FLAGS)
347             {
348                 case CT_IP_USE_V4:
349                         snRet = snprintf(buffer, bufferSize, "%s%s:%d%s",
350                                          prefix, address, port, uri);
351                     break;
352                 case CT_IP_USE_V6:
353                         snRet = snprintf(buffer, bufferSize, "%s[%s]:%d%s",
354                                          prefix, address, port, uri);
355                     break;
356                 default:
357                     OC_LOG(ERROR, TAG, "Unknown address format.");
358                     return false;
359             }
360             // snprintf return value check
361             if (snRet < 0)
362             {
363                 OC_LOG_V(ERROR, TAG, "PMGenerateQuery : Error (snprintf) %d\n", snRet);
364                 return false;
365             }
366             else if ((size_t)snRet >= bufferSize)
367             {
368                 OC_LOG_V(ERROR, TAG, "PMGenerateQuery : Truncated (snprintf) %d\n", snRet);
369                 return false;
370             }
371
372             break;
373         // TODO: We need to verify tinyDTLS in below cases
374         case CT_ADAPTER_GATT_BTLE:
375         case CT_ADAPTER_RFCOMM_BTEDR:
376             OC_LOG(ERROR, TAG, "Not supported connectivity adapter.");
377             return false;
378             break;
379         default:
380             OC_LOG(ERROR, TAG, "Unknown connectivity adapter.");
381             return false;
382     }
383
384     return true;
385 }
386
387 /**
388  * Callback handler for getting secure port information using /oic/res discovery.
389  *
390  * @param[in] ctx             user context
391  * @param[in] handle          Handle for response
392  * @param[in] clientResponse  Response information(It will contain payload)
393  *
394  * @return OC_STACK_KEEP_TRANSACTION to keep transaction and
395  *         OC_STACK_DELETE_TRANSACTION to delete it.
396  */
397 static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
398                                  OCClientResponse *clientResponse)
399 {
400     if (ctx == NULL)
401     {
402         OC_LOG(ERROR, TAG, "Lost List of device information");
403         return OC_STACK_DELETE_TRANSACTION;
404     }
405     (void)UNUSED;
406     if (clientResponse)
407     {
408         if  (NULL == clientResponse->payload)
409         {
410             OC_LOG(INFO, TAG, "Skiping Null payload");
411         }
412         else
413         {
414             if (PAYLOAD_TYPE_DISCOVERY != clientResponse->payload->type)
415             {
416                 OC_LOG(INFO, TAG, "Wrong payload type");
417                 return OC_STACK_DELETE_TRANSACTION;
418             }
419
420             uint16_t securePort = 0;
421             OCResourcePayload* resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources;
422
423             if (resPayload && resPayload->secure)
424             {
425                 securePort = resPayload->port;
426             }
427             else
428             {
429                 OC_LOG(INFO, TAG, "Can not find secure port information.");
430                 return OC_STACK_DELETE_TRANSACTION;
431             }
432
433             DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
434             OCProvisionDev_t **ppDevicesList = pDInfo->ppDevicesList;
435
436             OCStackResult res = UpdateSecurePortOfDevice(ppDevicesList, clientResponse->devAddr.addr,
437                                                          clientResponse->devAddr.port, securePort);
438             if (OC_STACK_OK != res)
439             {
440                 OC_LOG(ERROR, TAG, "Error while getting secure port.");
441                 return OC_STACK_DELETE_TRANSACTION;
442             }
443             OC_LOG(INFO, TAG, "Exiting SecurePortDiscoveryHandler.");
444         }
445
446         return  OC_STACK_DELETE_TRANSACTION;
447     }
448     else
449     {
450         OC_LOG(INFO, TAG, "Skiping Null response");
451     }
452     return  OC_STACK_DELETE_TRANSACTION;
453 }
454
455 /**
456  * Callback handler for PMDeviceDiscovery API.
457  *
458  * @param[in] ctx             User context
459  * @param[in] handle          Handler for response
460  * @param[in] clientResponse  Response information (It will contain payload)
461  * @return OC_STACK_KEEP_TRANSACTION to keep transaction and
462  *         OC_STACK_DELETE_TRANSACTION to delete it.
463  */
464 static OCStackApplicationResult DeviceDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
465                                 OCClientResponse *clientResponse)
466 {
467     if (ctx == NULL)
468     {
469         OC_LOG(ERROR, TAG, "Lost List of device information");
470         return OC_STACK_KEEP_TRANSACTION;
471     }
472     (void)UNUSED;
473     if (clientResponse)
474     {
475         if  (NULL == clientResponse->payload)
476         {
477             OC_LOG(INFO, TAG, "Skiping Null payload");
478             return OC_STACK_KEEP_TRANSACTION;
479         }
480         if (OC_STACK_OK != clientResponse->result)
481         {
482             OC_LOG(INFO, TAG, "Error in response");
483             return OC_STACK_KEEP_TRANSACTION;
484         }
485         else
486         {
487             if (PAYLOAD_TYPE_SECURITY != clientResponse->payload->type)
488             {
489                 OC_LOG(INFO, TAG, "Unknown payload type");
490                 return OC_STACK_KEEP_TRANSACTION;
491             }
492             OicSecDoxm_t *ptrDoxm = JSONToDoxmBin(
493                             ((OCSecurityPayload*)clientResponse->payload)->securityData);
494             if (NULL == ptrDoxm)
495             {
496                 OC_LOG(INFO, TAG, "Ignoring malformed JSON");
497                 return OC_STACK_KEEP_TRANSACTION;
498             }
499             else
500             {
501                 OC_LOG(DEBUG, TAG, "Successfully converted doxm json to bin.");
502
503                 //If this is owend device discovery we have to filter out the responses.
504                 DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
505                 OCProvisionDev_t **ppDevicesList = pDInfo->ppDevicesList;
506
507                 // Get my device ID from doxm resource
508                 OicUuid_t myId;
509                 memset(&myId, 0, sizeof(myId));
510                 OCStackResult res = GetDoxmDevOwnerId(&myId);
511                 if(OC_STACK_OK != res)
512                 {
513                     OC_LOG(ERROR, TAG, "Error while getting my device ID.");
514                     DeleteDoxmBinData(ptrDoxm);
515                     return OC_STACK_KEEP_TRANSACTION;
516                 }
517
518                 // If this is owned discovery response but owner is not me then discard it.
519                 if( (pDInfo->isOwnedDiscovery) &&
520                     (0 != memcmp(&ptrDoxm->owner.id, &myId.id, sizeof(myId.id))) )
521                 {
522                     OC_LOG(DEBUG, TAG, "Discovered device is not owend by me");
523                     DeleteDoxmBinData(ptrDoxm);
524                     return OC_STACK_KEEP_TRANSACTION;
525                 }
526
527                 res = AddDevice(ppDevicesList, clientResponse->devAddr.addr,
528                         clientResponse->devAddr.port,
529                         clientResponse->devAddr.adapter,
530                         clientResponse->connType, ptrDoxm);
531                 if (OC_STACK_OK != res)
532                 {
533                     OC_LOG(ERROR, TAG, "Error while adding data to linkedlist.");
534                     DeleteDoxmBinData(ptrDoxm);
535                     return OC_STACK_KEEP_TRANSACTION;
536                 }
537
538                 //Try to the unicast discovery to getting secure port
539                 char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = { 0, };
540                 if(!PMGenerateQuery(false,
541                                     clientResponse->devAddr.addr, clientResponse->devAddr.port,
542                                     clientResponse->connType,
543                                     query, sizeof(query), OC_RSRVD_WELL_KNOWN_URI))
544                 {
545                     OC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
546                     return OC_STACK_KEEP_TRANSACTION;
547                 }
548                 OC_LOG_V(DEBUG, TAG, "Query=%s", query);
549
550                 OCCallbackData cbData;
551                 cbData.cb = &SecurePortDiscoveryHandler;
552                 cbData.context = ctx;
553                 cbData.cd = NULL;
554                 OCStackResult ret = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
555                         clientResponse->connType, OC_LOW_QOS, &cbData, NULL, 0);
556                 // TODO: Should we use the default secure port in case of error?
557                 if(OC_STACK_OK != ret)
558                 {
559                     OC_LOG(ERROR, TAG, "Failed to Secure Port Discovery");
560                     return OC_STACK_KEEP_TRANSACTION;
561                 }
562                 else
563                 {
564                     OC_LOG_V(INFO, TAG, "OCDoResource with [%s] Success", query);
565                 }
566                 OC_LOG(INFO, TAG, "Exiting ProvisionDiscoveryHandler.");
567             }
568
569             return  OC_STACK_KEEP_TRANSACTION;
570         }
571     }
572     else
573     {
574         OC_LOG(INFO, TAG, "Skiping Null response");
575         return OC_STACK_KEEP_TRANSACTION;
576     }
577
578     return  OC_STACK_DELETE_TRANSACTION;
579 }
580
581 /**
582  * Discover owned/unowned devices in the same IP subnet. .
583  *
584  * @param[in] waittime      Timeout in seconds.
585  * @param[in] isOwned       bool flag for owned / unowned discovery
586  * @param[in] ppDevicesList        List of OCProvisionDev_t.
587  *
588  * @return OC_STACK_OK on success otherwise error.
589  */
590 OCStackResult PMDeviceDiscovery(unsigned short waittime, bool isOwned, OCProvisionDev_t **ppDevicesList)
591 {
592     OC_LOG(DEBUG, TAG, "IN PMDeviceDiscovery");
593
594     if (NULL != *ppDevicesList)
595     {
596         OC_LOG(ERROR, TAG, "List is not null can cause memory leak");
597         return OC_STACK_INVALID_PARAM;
598     }
599
600     const char DOXM_OWNED_FALSE_MULTICAST_QUERY[] = "/oic/sec/doxm?Owned=FALSE";
601     const char DOXM_OWNED_TRUE_MULTICAST_QUERY[] = "/oic/sec/doxm?Owned=TRUE";
602
603     DiscoveryInfo *pDInfo = OICCalloc(1, sizeof(DiscoveryInfo));
604     if(NULL == pDInfo)
605     {
606         OC_LOG(ERROR, TAG, "PMDeviceDiscovery : Memory allocation failed.");
607         return OC_STACK_NO_MEMORY;
608     }
609
610     pDInfo->ppDevicesList = ppDevicesList;
611     pDInfo->isOwnedDiscovery = isOwned;
612
613     OCCallbackData cbData;
614     cbData.cb = &DeviceDiscoveryHandler;
615     cbData.context = (void *)pDInfo;
616     cbData.cd = NULL;
617     OCStackResult res = OC_STACK_ERROR;
618
619     const char* query = isOwned ? DOXM_OWNED_TRUE_MULTICAST_QUERY :
620                                   DOXM_OWNED_FALSE_MULTICAST_QUERY;
621
622     OCDoHandle handle = NULL;
623     res = OCDoResource(&handle, OC_REST_DISCOVER, query, 0, 0,
624                                      CT_DEFAULT, OC_LOW_QOS, &cbData, NULL, 0);
625     if (res != OC_STACK_OK)
626     {
627         OC_LOG(ERROR, TAG, "OCStack resource error");
628         OICFree(pDInfo);
629         return res;
630     }
631
632     //Waiting for each response.
633     res = PMTimeout(waittime, true);
634     if(OC_STACK_OK != res)
635     {
636         OC_LOG(ERROR, TAG, "Failed to wait response for secure discovery.");
637         OICFree(pDInfo);
638         OCStackResult resCancel = OCCancel(handle, OC_LOW_QOS, NULL, 0);
639         if(OC_STACK_OK !=  resCancel)
640         {
641             OC_LOG(ERROR, TAG, "Failed to remove registered callback");
642         }
643         return res;
644     }
645     res = OCCancel(handle,OC_LOW_QOS,NULL,0);
646     if (OC_STACK_OK != res)
647     {
648         OC_LOG(ERROR, TAG, "Failed to remove registered callback");
649         OICFree(pDInfo);
650         return res;
651     }
652     OC_LOG(DEBUG, TAG, "OUT PMDeviceDiscovery");
653     OICFree(pDInfo);
654     return res;
655 }
656
657 /**
658  * Function to print OCProvisionDev_t for debug purpose.
659  *
660  * @param[in] pDev Pointer to OCProvisionDev_t. It's information will be printed by OC_LOG_XX
661  *
662  */
663 void PMPrintOCProvisionDev(const OCProvisionDev_t* pDev)
664 {
665     if (pDev)
666     {
667         OC_LOG(DEBUG, TAG, "+++++ OCProvisionDev_t Information +++++");
668         OC_LOG_V(DEBUG, TAG, "IP %s", pDev->endpoint.addr);
669         OC_LOG_V(DEBUG, TAG, "PORT %d", pDev->endpoint.port);
670         OC_LOG_V(DEBUG, TAG, "S-PORT %d", pDev->securePort);
671         OC_LOG(DEBUG, TAG, "++++++++++++++++++++++++++++++++++++++++");
672     }
673     else
674     {
675         OC_LOG(DEBUG, TAG, "+++++ OCProvisionDev_t is NULL +++++");
676     }
677 }
678
679 bool PMDeleteFromUUIDList(OCUuidList_t *pUuidList, OicUuid_t *targetId)
680 {
681     if(pUuidList == NULL || targetId == NULL)
682     {
683         return false;
684     }
685     OCUuidList_t *tmp1 = NULL,*tmp2=NULL;
686     LL_FOREACH_SAFE(pUuidList, tmp1, tmp2)
687     {
688         if(0 == memcmp(tmp1->dev.id, targetId->id, sizeof(targetId->id)))
689         {
690             LL_DELETE(pUuidList, tmp1);
691             OICFree(tmp1);
692             return true;
693         }
694     }
695     return false;
696 }