Added Device dashboard OC APIs
[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
122         LL_PREPEND(*ppDevicesList, ptr);
123     }
124
125     return OC_STACK_OK;
126 }
127
128 /**
129  * Function to set secure port information from the given list of devices.
130  *
131  * @param[in] pList         List of OCProvisionDev_t.
132  * @param[in] addr          address of target device.
133  * @param[in] port          port of remote server.
134  * @param[in] secureport    secure port information.
135  *
136  * @return OC_STACK_OK for success and errorcode otherwise.
137  */
138 OCStackResult UpdateSecurePortOfDevice(OCProvisionDev_t **ppDevicesList, const char *addr,
139                                        uint16_t port, uint16_t securePort)
140 {
141     OCProvisionDev_t *ptr = GetDevice(ppDevicesList, addr, port);
142
143     if(!ptr)
144     {
145         OC_LOG(ERROR, TAG, "Can not find device information in the discovery device list");
146         return OC_STACK_ERROR;
147     }
148
149     ptr->securePort = securePort;
150
151     return OC_STACK_OK;
152 }
153
154 /**
155  * This function deletes list of provision target devices
156  *
157  * @param[in] pDevicesList         List of OCProvisionDev_t.
158  */
159 void PMDeleteDeviceList(OCProvisionDev_t *pDevicesList)
160 {
161     if(pDevicesList)
162     {
163         OCProvisionDev_t *del = NULL, *tmp = NULL;
164         LL_FOREACH_SAFE(pDevicesList, del, tmp)
165         {
166             LL_DELETE(pDevicesList, del);
167
168             DeleteDoxmBinData(del->doxm);
169             DeletePstatBinData(del->pstat);
170             OICFree(del);
171         }
172     }
173 }
174
175 OCProvisionDev_t* PMCloneOCProvisionDev(const OCProvisionDev_t* src)
176 {
177     OC_LOG(DEBUG, TAG, "IN PMCloneOCProvisionDev");
178
179     if (!src)
180     {
181         OC_LOG(ERROR, TAG, "PMCloneOCProvisionDev : Invalid parameter");
182         return NULL;
183     }
184
185     // TODO: Consider use VERIFY_NON_NULL instead of if ( null check ) { goto exit; }
186     OCProvisionDev_t* newDev = (OCProvisionDev_t*)OICCalloc(1, sizeof(OCProvisionDev_t));
187     VERIFY_NON_NULL(TAG, newDev, ERROR);
188
189     memcpy(&newDev->endpoint, &src->endpoint, sizeof(OCDevAddr));
190
191     if (src->pstat)
192     {
193         newDev->pstat= (OicSecPstat_t*)OICCalloc(1, sizeof(OicSecPstat_t));
194         VERIFY_NON_NULL(TAG, newDev->pstat, ERROR);
195
196         memcpy(newDev->pstat, src->pstat, sizeof(OicSecPstat_t));
197         // We have to assign NULL for not necessary information to prevent memory corruption.
198         newDev->pstat->sm = NULL;
199     }
200
201     if (src->doxm)
202     {
203         newDev->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
204         VERIFY_NON_NULL(TAG, newDev->doxm, ERROR);
205
206         memcpy(newDev->doxm, src->doxm, sizeof(OicSecDoxm_t));
207         // We have to assign NULL for not necessary information to prevent memory corruption.
208         newDev->doxm->oxmType = NULL;
209         newDev->doxm->oxm = NULL;
210     }
211
212     newDev->securePort = src->securePort;
213     //TODO: Below comment line should be activated after 2333 change is merged
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             if(snRet >= bufferSize)
361             {
362                 OC_LOG(ERROR, TAG, "PMGenerateQuery : URI is too long");
363                 return false;
364             }
365             break;
366         // TODO: We need to verify tinyDTLS in below cases
367         case CT_ADAPTER_GATT_BTLE:
368         case CT_ADAPTER_RFCOMM_BTEDR:
369             OC_LOG(ERROR, TAG, "Not supported connectivity adapter.");
370             return false;
371             break;
372         default:
373             OC_LOG(ERROR, TAG, "Unknown connectivity adapter.");
374             return false;
375     }
376
377     return true;
378 }
379
380 /**
381  * Callback handler for getting secure port information using /oic/res discovery.
382  *
383  * @param[in] ctx             user context
384  * @param[in] handle          Handle for response
385  * @param[in] clientResponse  Response information(It will contain payload)
386  *
387  * @return OC_STACK_KEEP_TRANSACTION to keep transaction and
388  *         OC_STACK_DELETE_TRANSACTION to delete it.
389  */
390 static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
391                                  OCClientResponse *clientResponse)
392 {
393     if (ctx == NULL)
394     {
395         OC_LOG(ERROR, TAG, "Lost List of device information");
396         return OC_STACK_KEEP_TRANSACTION;
397     }
398     (void)UNUSED;
399     if (clientResponse)
400     {
401         if  (NULL == clientResponse->payload)
402         {
403             OC_LOG(INFO, TAG, "Skiping Null payload");
404         }
405         else
406         {
407             if (PAYLOAD_TYPE_DISCOVERY != clientResponse->payload->type)
408             {
409                 OC_LOG(INFO, TAG, "Wrong payload type");
410                 return OC_STACK_KEEP_TRANSACTION;
411             }
412
413             uint16_t securePort = 0;
414             OCResourcePayload* resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources;
415
416             if (resPayload && resPayload->secure)
417             {
418                 securePort = resPayload->port;
419             }
420             else
421             {
422                 OC_LOG(INFO, TAG, "Can not find secure port information.");
423                 return OC_STACK_KEEP_TRANSACTION;
424             }
425
426             DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
427             OCProvisionDev_t **ppDevicesList = pDInfo->ppDevicesList;
428
429             OCStackResult res = UpdateSecurePortOfDevice(ppDevicesList, clientResponse->devAddr.addr,
430                                                          clientResponse->devAddr.port, securePort);
431             if (OC_STACK_OK != res)
432             {
433                 OC_LOG(ERROR, TAG, "Error while getting secure port.");
434                 return OC_STACK_KEEP_TRANSACTION;
435             }
436             OC_LOG(INFO, TAG, "Exiting SecurePortDiscoveryHandler.");
437         }
438
439         return  OC_STACK_KEEP_TRANSACTION;
440     }
441     else
442     {
443         OC_LOG(INFO, TAG, "Skiping Null response");
444     }
445     return  OC_STACK_DELETE_TRANSACTION;
446 }
447
448 /**
449  * Callback handler for PMDeviceDiscovery API.
450  *
451  * @param[in] ctx             User context
452  * @param[in] handle          Handler for response
453  * @param[in] clientResponse  Response information (It will contain payload)
454  * @return OC_STACK_KEEP_TRANSACTION to keep transaction and
455  *         OC_STACK_DELETE_TRANSACTION to delete it.
456  */
457 static OCStackApplicationResult DeviceDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
458                                 OCClientResponse *clientResponse)
459 {
460     if (ctx == NULL)
461     {
462         OC_LOG(ERROR, TAG, "Lost List of device information");
463         return OC_STACK_KEEP_TRANSACTION;
464     }
465     (void)UNUSED;
466     if (clientResponse)
467     {
468         if  (NULL == clientResponse->payload)
469         {
470             OC_LOG(INFO, TAG, "Skiping Null payload");
471             return OC_STACK_KEEP_TRANSACTION;
472         }
473         if (OC_STACK_OK != clientResponse->result)
474         {
475             OC_LOG(INFO, TAG, "Error in response");
476             return OC_STACK_KEEP_TRANSACTION;
477         }
478         else
479         {
480             if (PAYLOAD_TYPE_SECURITY != clientResponse->payload->type)
481             {
482                 OC_LOG(INFO, TAG, "Unknown payload type");
483                 return OC_STACK_KEEP_TRANSACTION;
484             }
485             OicSecDoxm_t *ptrDoxm = JSONToDoxmBin(
486                             ((OCSecurityPayload*)clientResponse->payload)->securityData);
487             if (NULL == ptrDoxm)
488             {
489                 OC_LOG(INFO, TAG, "Ignoring malformed JSON");
490                 return OC_STACK_KEEP_TRANSACTION;
491             }
492             else
493             {
494                 OC_LOG(DEBUG, TAG, "Successfully converted doxm json to bin.");
495
496                 //If this is owend device discovery we have to filter out the responses.
497                 DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
498                 OCProvisionDev_t **ppDevicesList = pDInfo->ppDevicesList;
499
500                 // Get my device ID from doxm resource
501                 OicUuid_t myId;
502                 memset(&myId, 0, sizeof(myId));
503                 OCStackResult res = GetDoxmDevOwnerId(&myId);
504                 if(OC_STACK_OK != res)
505                 {
506                     OC_LOG(ERROR, TAG, "Error while getting my device ID.");
507                     DeleteDoxmBinData(ptrDoxm);
508                     return OC_STACK_KEEP_TRANSACTION;
509                 }
510
511                 // If this is owned discovery response but owner is not me then discard it.
512                 if( (pDInfo->isOwnedDiscovery) &&
513                     (0 != memcmp(&ptrDoxm->owner.id, &myId.id, sizeof(myId.id))) )
514                 {
515                     OC_LOG(DEBUG, TAG, "Discovered device is not owend by me");
516                     DeleteDoxmBinData(ptrDoxm);
517                     return OC_STACK_KEEP_TRANSACTION;
518                 }
519
520                 res = AddDevice(ppDevicesList, clientResponse->devAddr.addr,
521                         clientResponse->devAddr.port,
522                         clientResponse->devAddr.adapter,
523                         clientResponse->connType, ptrDoxm);
524                 if (OC_STACK_OK != res)
525                 {
526                     OC_LOG(ERROR, TAG, "Error while adding data to linkedlist.");
527                     DeleteDoxmBinData(ptrDoxm);
528                     return OC_STACK_KEEP_TRANSACTION;
529                 }
530
531                 //Try to the unicast discovery to getting secure port
532                 char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = { 0, };
533                 if(!PMGenerateQuery(false,
534                                     clientResponse->devAddr.addr, clientResponse->devAddr.port,
535                                     clientResponse->connType,
536                                     query, sizeof(query), OC_RSRVD_WELL_KNOWN_URI))
537                 {
538                     OC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
539                     return OC_STACK_KEEP_TRANSACTION;
540                 }
541                 OC_LOG_V(DEBUG, TAG, "Query=%s", query);
542
543                 OCCallbackData cbData;
544                 cbData.cb = &SecurePortDiscoveryHandler;
545                 cbData.context = ctx;
546                 cbData.cd = NULL;
547                 OCStackResult ret = OCDoResource(NULL, OC_REST_GET, query, 0, 0,
548                         clientResponse->connType, OC_LOW_QOS, &cbData, NULL, 0);
549                 // TODO: Should we use the default secure port in case of error?
550                 if(OC_STACK_OK != ret)
551                 {
552                     OC_LOG(ERROR, TAG, "Failed to Secure Port Discovery");
553                     return OC_STACK_KEEP_TRANSACTION;
554                 }
555                 else
556                 {
557                     OC_LOG_V(INFO, TAG, "OCDoResource with [%s] Success", query);
558                 }
559                 OC_LOG(INFO, TAG, "Exiting ProvisionDiscoveryHandler.");
560             }
561
562             return  OC_STACK_KEEP_TRANSACTION;
563         }
564     }
565     else
566     {
567         OC_LOG(INFO, TAG, "Skiping Null response");
568         return OC_STACK_KEEP_TRANSACTION;
569     }
570
571     return  OC_STACK_DELETE_TRANSACTION;
572 }
573
574 /**
575  * Discover owned/unowned devices in the same IP subnet. .
576  *
577  * @param[in] waittime      Timeout in seconds.
578  * @param[in] isOwned       bool flag for owned / unowned discovery
579  * @param[in] ppDevicesList        List of OCProvisionDev_t.
580  *
581  * @return OC_STACK_OK on success otherwise error.
582  */
583 OCStackResult PMDeviceDiscovery(unsigned short waittime, bool isOwned, OCProvisionDev_t **ppDevicesList)
584 {
585     OC_LOG(DEBUG, TAG, "IN PMDeviceDiscovery");
586
587     if (NULL != *ppDevicesList)
588     {
589         OC_LOG(ERROR, TAG, "List is not null can cause memory leak");
590         return OC_STACK_INVALID_PARAM;
591     }
592
593     const char DOXM_OWNED_FALSE_MULTICAST_QUERY[] = "/oic/sec/doxm?Owned=FALSE";
594     const char DOXM_OWNED_TRUE_MULTICAST_QUERY[] = "/oic/sec/doxm?Owned=TRUE";
595
596     DiscoveryInfo *pDInfo = OICCalloc(1, sizeof(DiscoveryInfo));
597     if(NULL == pDInfo)
598     {
599         OC_LOG(ERROR, TAG, "PMDeviceDiscovery : Memory allocation failed.");
600         return OC_STACK_NO_MEMORY;
601     }
602
603     pDInfo->ppDevicesList = ppDevicesList;
604     pDInfo->isOwnedDiscovery = isOwned;
605
606     OCCallbackData cbData;
607     cbData.cb = &DeviceDiscoveryHandler;
608     cbData.context = (void *)pDInfo;
609     cbData.cd = NULL;
610     OCStackResult res = OC_STACK_ERROR;
611
612     const char* query = isOwned ? DOXM_OWNED_TRUE_MULTICAST_QUERY :
613                                   DOXM_OWNED_FALSE_MULTICAST_QUERY;
614
615     res = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
616                                      CT_DEFAULT, OC_LOW_QOS, &cbData, NULL, 0);
617     if (res != OC_STACK_OK)
618     {
619         OC_LOG(ERROR, TAG, "OCStack resource error");
620         goto exit;
621     }
622
623     //Waiting for each response.
624     res = PMTimeout(waittime, true);
625     if(OC_STACK_OK != res)
626     {
627         OC_LOG(ERROR, TAG, "Failed to wait response for secure discovery.");
628         goto exit;
629     }
630
631     OC_LOG(DEBUG, TAG, "OUT PMDeviceDiscovery");
632
633 exit:
634     OICFree(pDInfo);
635     return res;
636 }
637
638 /**
639  * Function to print OCProvisionDev_t for debug purpose.
640  *
641  * @param[in] pDev Pointer to OCProvisionDev_t. It's information will be printed by OC_LOG_XX
642  *
643  */
644 void PMPrintOCProvisionDev(const OCProvisionDev_t* pDev)
645 {
646     if (pDev)
647     {
648         OC_LOG(DEBUG, TAG, "+++++ OCProvisionDev_t Information +++++");
649         OC_LOG_V(DEBUG, TAG, "IP %s", pDev->endpoint.addr);
650         OC_LOG_V(DEBUG, TAG, "PORT %d", pDev->endpoint.port);
651         OC_LOG_V(DEBUG, TAG, "S-PORT %d", pDev->securePort);
652         OC_LOG(DEBUG, TAG, "++++++++++++++++++++++++++++++++++++++++");
653     }
654     else
655     {
656         OC_LOG(DEBUG, TAG, "+++++ OCProvisionDev_t is NULL +++++");
657     }
658 }
659
660 bool PMDeleteFromUUIDList(OCUuidList_t *pUuidList, OicUuid_t *targetId)
661 {
662     if(pUuidList == NULL || targetId == NULL)
663     {
664         return false;
665     }
666     OCUuidList_t *tmp1 = NULL,*tmp2=NULL;
667     LL_FOREACH_SAFE(pUuidList, tmp1, tmp2)
668     {
669         if(0 == memcmp(tmp1->dev.id, targetId->id, sizeof(targetId->id)))
670         {
671             LL_DELETE(pUuidList, tmp1);
672             OICFree(tmp1);
673             return true;
674         }
675     }
676     return false;
677 }