• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "das_task_main.h"
17 #include "alg_loader.h"
18 #include "base_sub_task.h"
19 #include "das_lite_token_manager.h"
20 #include "das_standard_token_manager.h"
21 #include "das_task_common.h"
22 #include "hc_log.h"
23 #include "iso_task_main.h"
24 #include "pake_v2_task_main.h"
25 #include "pake_protocol_dl_common.h"
26 #include "pake_protocol_ec_common.h"
27 #include "pake_v1_task_main.h"
28 #include "protocol_common.h"
29 
30 typedef struct DasProtocolEntityT {
31     ProtocolType type;
32     uint32_t algInProtocol;
33     const TokenManager *tokenManagerInstance;
34     SubTaskBase *(*createSubTask)(const CJson *);
35 } DasProtocolEntity;
36 
37 IMPLEMENT_HC_VECTOR(SubTaskVec, void *, 1)
38 DECLARE_HC_VECTOR(DasProtocolEntityVec, void *);
39 IMPLEMENT_HC_VECTOR(DasProtocolEntityVec, void *, 1)
40 
41 DasProtocolEntityVec g_protocolEntityVec;
42 ProtocolType g_taskTypeToProtocolType[] = {
43     ISO, // TASK_TYPE_ISO_PROTOCOL = 0,
44     PAKE_V1, // TASK_TYPE_PAKE_V1_PROTOCOL = 1,
45     PAKE_V2 // TASK_TYPE_PAKE_V2_PROTOCOL = 2,
46 };
47 
GetMinVersion(VersionStruct * version)48 static void GetMinVersion(VersionStruct *version)
49 {
50     version->first = 1;
51     version->second = 0;
52     version->third = 0;
53 }
54 
GetMaxVersion(VersionStruct * version)55 static void GetMaxVersion(VersionStruct *version)
56 {
57     version->first = MAJOR_VERSION_NO;
58     version->second = 0;
59     version->third = 0;
60 
61     uint32_t index;
62     void **ptr = NULL;
63     FOR_EACH_HC_VECTOR(g_protocolEntityVec, index, ptr) {
64         if (ptr != NULL && *ptr != NULL) {
65             DasProtocolEntity *temp = (DasProtocolEntity *)(*ptr);
66             version->third = (version->third) | temp->algInProtocol;
67         }
68     }
69 }
70 
InitVersionInfo(VersionInfo * versionInfo)71 static void InitVersionInfo(VersionInfo *versionInfo)
72 {
73     GetMinVersion(&(versionInfo->minVersion));
74     GetMaxVersion(&(versionInfo->curVersion));
75     versionInfo->versionStatus = INITIAL;
76 }
77 
AddVersionToOut(const VersionInfo * versionInfo,CJson * out)78 static int AddVersionToOut(const VersionInfo *versionInfo, CJson *out)
79 {
80     CJson *payload = GetObjFromJson(out, FIELD_PAYLOAD);
81     if (payload == NULL) {
82         LOGD("Not find payload.");
83         return HC_SUCCESS;
84     }
85     return AddVersionToJson(payload, &(versionInfo->minVersion), &(versionInfo->curVersion));
86 }
87 
CombineJson(CJson * desObj,const CJson * srcObj)88 static int CombineJson(CJson *desObj, const CJson *srcObj)
89 {
90     CHECK_PTR_RETURN_ERROR_CODE(desObj, "desObj");
91     CHECK_PTR_RETURN_ERROR_CODE(srcObj, "srcObj");
92     int res;
93     int len = GetItemNum(srcObj);
94     for (int i = 0; i < len; i++) {
95         CJson *item = GetItemFromArray(srcObj, i);
96         const char *key = GetItemKey(item);
97         CJson *payload = GetObjFromJson(desObj, FIELD_PAYLOAD);
98         if (strcmp(key, FIELD_PAYLOAD) == 0 && payload != NULL) {
99             res = CombineJson(payload, item);
100             if (res != HC_SUCCESS) {
101                 LOGE("Combine payload failed, res: %x.", res);
102                 return res;
103             }
104         } else {
105             if (AddObjToJson(desObj, key, item) != HC_SUCCESS) {
106                 LOGE("AddObjToJson failed.");
107                 return HC_ERR_JSON_ADD;
108             }
109         }
110     }
111     return HC_SUCCESS;
112 }
113 
DestroyTaskT(Task * task)114 static void DestroyTaskT(Task *task)
115 {
116     if (task == NULL) {
117         return;
118     }
119     uint32_t index;
120     void **ptr = NULL;
121     FOR_EACH_HC_VECTOR(task->vec, index, ptr) {
122         if (ptr != NULL && *ptr != NULL) {
123             ((SubTaskBase *)(*ptr))->destroyTask((SubTaskBase *)(*ptr));
124         }
125     }
126     DESTROY_HC_VECTOR(SubTaskVec, &(task->vec));
127     HcFree(task);
128 }
129 
ProcessMultiTask(Task * task,const CJson * in,CJson * out,int32_t * status)130 static int ProcessMultiTask(Task *task, const CJson *in, CJson *out, int32_t *status)
131 {
132     int res = HC_SUCCESS;
133     uint32_t index;
134     void **ptr = NULL;
135     CJson *tmpOut = NULL;
136     CJson *combinedSendToPeer = CreateJson();
137     if (combinedSendToPeer == NULL) {
138         LOGE("Create combinedSendToPeer failed.");
139         return HC_ERR_JSON_CREATE;
140     }
141     FOR_EACH_HC_VECTOR(task->vec, index, ptr) {
142         if ((ptr == NULL) || (*ptr == NULL)) {
143             LOGD("Null ptr in subTask vector.");
144             continue;
145         }
146         tmpOut = CreateJson();
147         if (tmpOut == NULL) {
148             LOGE("Create tmpOut failed.");
149             res = HC_ERR_JSON_CREATE;
150             goto ERR;
151         }
152         res = ((SubTaskBase *)(*ptr))->process((*ptr), in, tmpOut, status);
153         if (res != HC_SUCCESS) {
154             LOGE("Process subTask failed, index: %u, res: %x.", index, res);
155             goto ERR;
156         }
157 
158         CJson *tmpSendToPeer = GetObjFromJson(tmpOut, FIELD_SEND_TO_PEER);
159         res = CombineJson(combinedSendToPeer, tmpSendToPeer);
160         if (res != HC_SUCCESS) {
161             LOGE("CombineJson failed, res: %x.", res);
162             goto ERR;
163         }
164         FreeJson(tmpOut);
165         tmpOut = NULL;
166     }
167     if (AddObjToJson(out, FIELD_SEND_TO_PEER, combinedSendToPeer) != HC_SUCCESS) {
168         LOGE("Add combinedSendToPeer to json object failed.");
169         res = HC_ERR_JSON_ADD;
170         goto ERR;
171     }
172 ERR:
173     FreeJson(combinedSendToPeer);
174     FreeJson(tmpOut);
175     return res;
176 }
177 
NegotiateAndProcessTask(Task * task,const CJson * in,CJson * out,int32_t * status)178 static int NegotiateAndProcessTask(Task *task, const CJson *in, CJson *out, int32_t *status)
179 {
180     VersionStruct curVersionPeer = { 0, 0, 0 };
181     VersionStruct minVersionPeer = { 0, 0, 0 };
182     int res = GetVersionFromJson(in, &minVersionPeer, &curVersionPeer);
183     if (res != HC_SUCCESS) {
184         LOGE("Get peer version info failed, res: %x.", res);
185         return res;
186     }
187     res = NegotiateVersion(&minVersionPeer, &curVersionPeer, &(task->versionInfo.curVersion));
188     if (res != HC_SUCCESS) {
189         LOGE("NegotiateVersion failed, res: %x.", res);
190         return res;
191     }
192     if (!IsVersionEqual(&(task->versionInfo.curVersion), &curVersionPeer)) {
193         LOGE("Negotiated version is not matched with peer.");
194         return HC_ERR_UNSUPPORTED_VERSION;
195     }
196     ProtocolType protocolType = GetPrototolType(&(task->versionInfo.curVersion), task->versionInfo.opCode);
197     LOGI("Client select protocolType: %d", protocolType);
198 
199     SubTaskBase *subTask = NULL;
200     uint32_t index = 0;
201     void **ptr = task->vec.getp(&(task->vec), 0);
202     while (index < task->vec.size(&(task->vec)) && ptr != NULL) {
203         SubTaskBase *temp = (SubTaskBase *)(*ptr);
204         if (g_taskTypeToProtocolType[temp->getTaskType(temp)] == protocolType) {
205             subTask = temp;
206             index++;
207         } else {
208             temp->destroyTask(temp);
209             task->vec.eraseElement(&(task->vec), ptr, index);
210         }
211         ptr = task->vec.getp(&(task->vec), index);
212     }
213     if (subTask == NULL) {
214         LOGE("Can't find matched subTask.");
215         return HC_ERR_NOT_SUPPORT;
216     }
217     subTask->curVersion = task->versionInfo.curVersion;
218     res = subTask->process(subTask, in, out, status);
219     if (res != HC_SUCCESS) {
220         LOGE("Process subTask failed, res: %x.", res);
221     }
222     return res;
223 }
224 
IsPeerErrMessage(const CJson * in,int32_t * res)225 static bool IsPeerErrMessage(const CJson *in, int32_t *res)
226 {
227     int32_t message = 0;
228     if (GetIntFromJson(in, FIELD_MESSAGE, &message) != HC_SUCCESS) {
229         LOGD("There is no message code.");
230         return false;
231     }
232     if (message != ERR_MESSAGE) {
233         return false;
234     }
235 
236     if (GetIntFromJson(in, FIELD_ERROR_CODE, res) != HC_SUCCESS) {
237         LOGE("Get peer error code failed.");
238     }
239     return true;
240 }
241 
ProcessTaskT(Task * task,const CJson * in,CJson * out,int32_t * status)242 static int ProcessTaskT(Task *task, const CJson *in, CJson *out, int32_t *status)
243 {
244     int32_t res;
245     if (IsPeerErrMessage(in, &res)) {
246         LOGE("Receive error message from peer, errCode: %x.", res);
247         DasSendErrMsgToSelf(out, HC_ERR_PEER_ERROR);
248         return HC_ERR_PEER_ERROR;
249     }
250     if (task->vec.size(&(task->vec)) == 0) {
251         LOGE("Task hasn't subTask.");
252         res = HC_ERR_TASK_IS_NULL;
253         goto ERR;
254     }
255 
256     if (task->versionInfo.versionStatus == INITIAL) {
257         res = ProcessMultiTask(task, in, out, status);
258         if (res != HC_SUCCESS) {
259             LOGE("ProcessMultiTask failed, res: %x.", res);
260             goto ERR;
261         }
262         task->versionInfo.versionStatus = VERSION_CONFIRM;
263     } else if (task->versionInfo.versionStatus == VERSION_CONFIRM) {
264         res = NegotiateAndProcessTask(task, in, out, status);
265         if (res != HC_SUCCESS) {
266             LOGE("NegotiateAndProcessTask failed, res: %x.", res);
267             goto ERR;
268         }
269         task->versionInfo.versionStatus = VERSION_DECIDED;
270     } else {
271         SubTaskBase *subTask = HC_VECTOR_GET(&(task->vec), 0);
272         res = subTask->process(subTask, in, out, status);
273         if (res != HC_SUCCESS) {
274             LOGE("Process subTask failed, res: %x.", res);
275             goto ERR;
276         }
277     }
278 
279     res = AddVersionToOut(&(task->versionInfo), out);
280     if (res != HC_SUCCESS) {
281         LOGE("AddVersionToOut failed, res: %x.", res);
282         goto ERR;
283     }
284     return res;
285 ERR:
286     if (task->versionInfo.versionStatus == INITIAL) {
287         DasSendErrMsgToSelf(out, res);
288     } else {
289         DasSendErrorToOut(out, res);
290     }
291     return res;
292 }
293 
CreateMultiSubTask(Task * task,const CJson * in)294 static int CreateMultiSubTask(Task *task, const CJson *in)
295 {
296     InitVersionInfo(&(task->versionInfo));
297     uint32_t index;
298     void **ptr = NULL;
299     FOR_EACH_HC_VECTOR(g_protocolEntityVec, index, ptr) {
300         if (ptr != NULL && (*ptr) != NULL) {
301             DasProtocolEntity *temp = (DasProtocolEntity *)(*ptr);
302             SubTaskBase *subTask = temp->createSubTask(in);
303             if (subTask == NULL) {
304                 LOGE("Create subTask failed, protocolType: %d.", temp->type);
305                 return HC_ERR_ALLOC_MEMORY;
306             }
307             subTask->curVersion = task->versionInfo.curVersion;
308             task->vec.pushBackT(&(task->vec), (void *)subTask);
309         }
310     }
311     return HC_SUCCESS;
312 }
313 
CreateSingleSubTask(Task * task,const CJson * in)314 static int CreateSingleSubTask(Task *task, const CJson *in)
315 {
316     VersionStruct curVersionPeer = { 0, 0, 0 };
317     VersionStruct minVersionPeer = { 0, 0, 0 };
318     int res = GetVersionFromJson(in, &minVersionPeer, &curVersionPeer);
319     if (res != HC_SUCCESS) {
320         LOGE("Get peer version info failed, res: %x.", res);
321         return res;
322     }
323     InitVersionInfo(&(task->versionInfo));
324     res = NegotiateVersion(&minVersionPeer, &curVersionPeer, &(task->versionInfo.curVersion));
325     if (res != HC_SUCCESS) {
326         LOGE("NegotiateVersion failed, res: %x.", res);
327         return res;
328     }
329     task->versionInfo.versionStatus = VERSION_DECIDED;
330 
331     ProtocolType protocolType = GetPrototolType(&(task->versionInfo.curVersion), task->versionInfo.opCode);
332     LOGI("Server select protocolType: %d", protocolType);
333 
334     uint32_t index;
335     void **ptr = NULL;
336     FOR_EACH_HC_VECTOR(g_protocolEntityVec, index, ptr) {
337         if (ptr != NULL && (*ptr) != NULL && (((DasProtocolEntity *)(*ptr))->type == protocolType)) {
338             DasProtocolEntity *temp = (DasProtocolEntity *)(*ptr);
339             SubTaskBase *subTask = temp->createSubTask(in);
340             if (subTask == NULL) {
341                 LOGE("Create subTask failed.");
342                 return HC_ERR_ALLOC_MEMORY;
343             }
344             subTask->curVersion = task->versionInfo.curVersion;
345             task->vec.pushBackT(&(task->vec), (void *)subTask);
346             return HC_SUCCESS;
347         }
348     }
349 
350     LOGE("Can't find protocolType.");
351     return HC_ERR_NOT_SUPPORT;
352 }
353 
CreateTaskT(int32_t * taskId,const CJson * in,CJson * out)354 Task *CreateTaskT(int32_t *taskId, const CJson *in, CJson *out)
355 {
356     int res;
357     Task *task = NULL;
358     bool isClient = true;
359     if (GetBoolFromJson(in, FIELD_IS_CLIENT, &isClient) != HC_SUCCESS) {
360         LOGE("Get isClient failed.");
361         res = HC_ERR_JSON_GET;
362         goto ERR;
363     }
364     task = (Task *)HcMalloc(sizeof(Task), 0);
365     if (task == NULL) {
366         LOGE("Malloc for das task failed.");
367         res = HC_ERR_ALLOC_MEMORY;
368         goto ERR;
369     }
370     task->vec = CREATE_HC_VECTOR(SubTaskVec);
371     task->destroyTask = DestroyTaskT;
372     task->processTask = ProcessTaskT;
373 
374     Uint8Buff taskIdBuf = { (uint8_t *)taskId, sizeof(int) };
375     res = GetLoaderInstance()->generateRandom(&taskIdBuf);
376     if (res != 0) {
377         LOGE("Generate taskId failed.");
378         goto ERR;
379     }
380     task->taskId = *taskId;
381     if (GetIntFromJson(in, FIELD_OPERATION_CODE, &(task->versionInfo.opCode)) != HC_SUCCESS) {
382         LOGE("Get opcode failed.");
383         res = HC_ERR_JSON_GET;
384         goto ERR;
385     }
386     if (isClient) {
387         res = CreateMultiSubTask(task, in);
388     } else {
389         res = CreateSingleSubTask(task, in);
390     }
391     if (res != HC_SUCCESS) {
392         LOGE("Create sub task failed, res: %x.", res);
393         goto ERR;
394     }
395     return task;
396 ERR:
397     if (isClient) {
398         DasSendErrMsgToSelf(out, res);
399     } else {
400         DasSendErrorToOut(out, res);
401     }
402     DestroyTaskT(task);
403     return NULL;
404 }
405 
RegisterLocalIdentityInTask(const char * pkgName,const char * serviceType,Uint8Buff * authId,int userType)406 int32_t RegisterLocalIdentityInTask(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType)
407 {
408     int32_t res = HC_SUCCESS;
409     uint32_t index;
410     void **ptr = NULL;
411     FOR_EACH_HC_VECTOR(g_protocolEntityVec, index, ptr) {
412         if (ptr != NULL && (*ptr) != NULL) {
413             DasProtocolEntity *temp = (DasProtocolEntity *)(*ptr);
414             if ((temp->tokenManagerInstance == NULL) || (temp->tokenManagerInstance->registerLocalIdentity == NULL)) {
415                 LOGD("Protocol type: %d, unsupported method!", temp->type);
416                 continue;
417             }
418             res = temp->tokenManagerInstance->registerLocalIdentity(pkgName, serviceType, authId, userType);
419             if (res != HC_SUCCESS) {
420                 LOGE("Protocol type: %d, registerLocalIdentity failed, res: %d!", temp->type, res);
421                 return HC_ERR_GENERATE_KEY_FAILED;
422             }
423         }
424     }
425     return res;
426 }
427 
UnregisterLocalIdentityInTask(const char * pkgName,const char * serviceType,Uint8Buff * authId,int userType)428 int32_t UnregisterLocalIdentityInTask(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType)
429 {
430     int32_t res = HC_SUCCESS;
431     uint32_t index;
432     void **ptr = NULL;
433     FOR_EACH_HC_VECTOR(g_protocolEntityVec, index, ptr) {
434         if (ptr != NULL && (*ptr) != NULL) {
435             DasProtocolEntity *temp = (DasProtocolEntity *)(*ptr);
436             if ((temp->tokenManagerInstance == NULL) || (temp->tokenManagerInstance->unregisterLocalIdentity == NULL)) {
437                 LOGD("Protocol type: %d, unsupported method!", temp->type);
438                 continue;
439             }
440             res = temp->tokenManagerInstance->unregisterLocalIdentity(pkgName, serviceType, authId, userType);
441             if (res != HC_SUCCESS) {
442                 LOGE("Protocol type: %d, unregisterLocalIdentity failed, res: %d!", temp->type, res);
443                 return res;
444             }
445         }
446     }
447     return res;
448 }
449 
DeletePeerAuthInfoInTask(const char * pkgName,const char * serviceType,Uint8Buff * authIdPeer,int userTypePeer)450 int32_t DeletePeerAuthInfoInTask(const char *pkgName, const char *serviceType, Uint8Buff *authIdPeer, int userTypePeer)
451 {
452     int32_t res = HC_SUCCESS;
453     uint32_t index;
454     void **ptr = NULL;
455     FOR_EACH_HC_VECTOR(g_protocolEntityVec, index, ptr) {
456         if (ptr != NULL && (*ptr) != NULL) {
457             DasProtocolEntity *temp = (DasProtocolEntity *)(*ptr);
458             if ((temp->tokenManagerInstance == NULL) || (temp->tokenManagerInstance->deletePeerAuthInfo == NULL)) {
459                 LOGD("Protocol type: %d, unsupported method!", temp->type);
460                 continue;
461             }
462             res = temp->tokenManagerInstance->deletePeerAuthInfo(pkgName, serviceType, authIdPeer, userTypePeer);
463             if (res != HC_SUCCESS) {
464                 LOGE("Protocol type: %d, deletePeerAuthInfo failed, res: %d!", temp->type, res);
465                 return res;
466             }
467         }
468     }
469     return res;
470 }
471 
GetPublicKeyInTask(const char * pkgName,const char * serviceType,Uint8Buff * authIdPeer,int userTypePeer,Uint8Buff * returnPk)472 int32_t GetPublicKeyInTask(const char *pkgName, const char *serviceType, Uint8Buff *authIdPeer, int userTypePeer,
473                            Uint8Buff *returnPk)
474 {
475     uint32_t index;
476     void **ptr = NULL;
477     FOR_EACH_HC_VECTOR(g_protocolEntityVec, index, ptr) {
478         if (ptr != NULL && (*ptr) != NULL) {
479             DasProtocolEntity *temp = (DasProtocolEntity *)(*ptr);
480             if ((temp->tokenManagerInstance == NULL) || (temp->tokenManagerInstance->getPublicKey == NULL)) {
481                 LOGD("Protocol type: %d, unsupported method!", temp->type);
482                 continue;
483             }
484             return temp->tokenManagerInstance->getPublicKey(pkgName, serviceType, authIdPeer, userTypePeer, returnPk);
485         }
486     }
487     LOGE("Failed to find valid protocol!");
488     return HC_ERR_NOT_SUPPORT;
489 }
490 
GetPakeAlgInProtocol(int offset)491 static uint32_t GetPakeAlgInProtocol(int offset)
492 {
493     uint32_t algInProtocol = PSK_SPEKE;
494 #ifdef P2P_PAKE_DL_TYPE
495     algInProtocol |= (GetPakeDlAlg() << offset);
496 #endif
497 #ifdef P2P_PAKE_EC_TYPE
498     algInProtocol |= (GetPakeEcAlg() << offset);
499 #endif
500     (void)offset;
501     return algInProtocol;
502 }
503 
InitDasProtocolEntities(void)504 int32_t InitDasProtocolEntities(void)
505 {
506     g_protocolEntityVec = CREATE_HC_VECTOR(DasProtocolEntityVec);
507     DasProtocolEntity *protocol = NULL;
508     if (IsIsoSupported()) {
509         protocol = (DasProtocolEntity *)HcMalloc(sizeof(DasProtocolEntity), 0);
510         if (protocol == NULL) {
511             LOGE("Malloc for Iso dasProtocolEntity failed.");
512             return HC_ERR_ALLOC_MEMORY;
513         }
514         protocol->type = ISO;
515         protocol->algInProtocol = ISO_ALG;
516         protocol->createSubTask = CreateIsoSubTask;
517         protocol->tokenManagerInstance = GetLiteTokenManagerInstance();
518         g_protocolEntityVec.pushBackT(&g_protocolEntityVec, (void *)protocol);
519     }
520 
521     if (IsSupportPakeV1()) {
522         protocol = (DasProtocolEntity *)HcMalloc(sizeof(DasProtocolEntity), 0);
523         if (protocol == NULL) {
524             LOGE("Malloc for pake v1 dasProtocolEntity failed.");
525             return HC_ERR_ALLOC_MEMORY;
526         }
527         protocol->type = PAKE_V1;
528         protocol->algInProtocol = GetPakeAlgInProtocol(ALG_OFFSET_FOR_PAKE_V1);
529         protocol->createSubTask = CreatePakeV1SubTask;
530         protocol->tokenManagerInstance = GetStandardTokenManagerInstance();
531         g_protocolEntityVec.pushBackT(&g_protocolEntityVec, (void *)protocol);
532     }
533 
534     if (IsSupportPakeV2()) {
535         protocol = (DasProtocolEntity *)HcMalloc(sizeof(DasProtocolEntity), 0);
536         if (protocol == NULL) {
537             LOGE("Malloc for pake v2 dasProtocolEntity failed.");
538             return HC_ERR_ALLOC_MEMORY;
539         }
540         protocol->type = PAKE_V2;
541         protocol->algInProtocol = GetPakeAlgInProtocol(ALG_OFFSET_FOR_PAKE_V2);
542         protocol->createSubTask = CreatePakeV2SubTask;
543         protocol->tokenManagerInstance = GetStandardTokenManagerInstance();
544         g_protocolEntityVec.pushBackT(&g_protocolEntityVec, (void *)protocol);
545     }
546 
547     return HC_SUCCESS;
548 }
549 
DestroyDasProtocolEntities(void)550 void DestroyDasProtocolEntities(void)
551 {
552     uint32_t index;
553     void **ptr = NULL;
554     FOR_EACH_HC_VECTOR(g_protocolEntityVec, index, ptr) {
555         if (ptr != NULL && *ptr != NULL) {
556             HcFree((DasProtocolEntity *)(*ptr));
557             *ptr = NULL;
558         }
559     }
560     DESTROY_HC_VECTOR(DasProtocolEntityVec, &g_protocolEntityVec);
561 }
562