1 /*
2 * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "devmgr_service.h"
10 #include "devhost_service_clnt.h"
11 #include "device_token_clnt.h"
12 #include "devsvc_manager.h"
13 #include "hdf_attribute_manager.h"
14 #include "hdf_base.h"
15 #include "hdf_driver_installer.h"
16 #include "hdf_host_info.h"
17 #include "hdf_log.h"
18 #include "hdf_object_manager.h"
19 #include "osal_time.h"
20
21 #define HDF_LOG_TAG devmgr_service
22 #define INVALID_PID (-1)
23
DevmgrServiceDynamicDevInfoFound(const char * svcName,struct DevHostServiceClnt ** targetHostClnt,struct HdfDeviceInfo ** targetDeviceInfo)24 static bool DevmgrServiceDynamicDevInfoFound(
25 const char *svcName, struct DevHostServiceClnt **targetHostClnt, struct HdfDeviceInfo **targetDeviceInfo)
26 {
27 struct HdfSListIterator itDeviceInfo;
28 struct HdfDeviceInfo *deviceInfo = NULL;
29 struct DevHostServiceClnt *hostClnt = NULL;
30 struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
31 if (devMgrSvc == NULL) {
32 return false;
33 }
34
35 DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
36 HdfSListIteratorInit(&itDeviceInfo, &hostClnt->dynamicDevInfos);
37 while (HdfSListIteratorHasNext(&itDeviceInfo)) {
38 deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
39 if (strcmp(deviceInfo->svcName, svcName) == 0) {
40 *targetDeviceInfo = deviceInfo;
41 *targetHostClnt = hostClnt;
42 return true;
43 }
44 }
45 }
46
47 return false;
48 }
49
50 #define WAIT_HOST_SLEEP_TIME 1 // ms
51 #define WAIT_HOST_SLEEP_CNT 1000
DevmgrServiceStartHostProcess(struct DevHostServiceClnt * hostClnt,bool sync,bool dynamic)52 static int DevmgrServiceStartHostProcess(struct DevHostServiceClnt *hostClnt, bool sync, bool dynamic)
53 {
54 int waitCount = WAIT_HOST_SLEEP_CNT;
55 struct IDriverInstaller *installer = DriverInstallerGetInstance();
56 if (installer == NULL || installer->StartDeviceHost == NULL) {
57 HDF_LOGE("invalid installer");
58 return HDF_FAILURE;
59 }
60
61 hostClnt->hostPid = installer->StartDeviceHost(hostClnt->hostId, hostClnt->hostName, dynamic);
62 if (hostClnt->hostPid == HDF_FAILURE) {
63 HDF_LOGW("failed to start device host(%{public}s, %{public}u)", hostClnt->hostName, hostClnt->hostId);
64 return HDF_FAILURE;
65 }
66 hostClnt->stopFlag = false;
67 if (!sync) {
68 return HDF_SUCCESS;
69 }
70
71 while (hostClnt->hostService == NULL && waitCount > 0) {
72 OsalMSleep(WAIT_HOST_SLEEP_TIME);
73 waitCount--;
74 }
75
76 if (waitCount <= 0) {
77 HDF_LOGE("wait host(%{public}s, %{public}d) attach timeout", hostClnt->hostName, hostClnt->hostId);
78 hostClnt->hostPid = -1;
79 return HDF_ERR_TIMEOUT;
80 }
81
82 return HDF_SUCCESS;
83 }
84
DevmgrServiceLoadDevice(struct IDevmgrService * devMgrSvc,const char * serviceName)85 static int DevmgrServiceLoadDevice(struct IDevmgrService *devMgrSvc, const char *serviceName)
86 {
87 struct HdfDeviceInfo *deviceInfo = NULL;
88 struct DevHostServiceClnt *hostClnt = NULL;
89 bool dynamic = true;
90 int ret;
91 (void)devMgrSvc;
92
93 if (serviceName == NULL) {
94 return HDF_ERR_INVALID_PARAM;
95 }
96
97 if (!DevmgrServiceDynamicDevInfoFound(serviceName, &hostClnt, &deviceInfo)) {
98 HDF_LOGE("device %{public}s not in configed device list", serviceName);
99 return HDF_DEV_ERR_NO_DEVICE;
100 }
101
102 if (deviceInfo->preload != DEVICE_PRELOAD_DISABLE) {
103 HDF_LOGE("device %{public}s not an dynamic load device", serviceName);
104 return HDF_DEV_ERR_NORANGE;
105 }
106
107 dynamic = HdfSListIsEmpty(&hostClnt->unloadDevInfos) && !HdfSListIsEmpty(&hostClnt->dynamicDevInfos);
108 OsalMutexLock(&hostClnt->hostLock);
109 if (hostClnt->hostPid < 0) {
110 OsalMutexUnlock(&hostClnt->hostLock);
111 if (DevmgrServiceStartHostProcess(hostClnt, true, dynamic) != HDF_SUCCESS) {
112 HDF_LOGW("failed to start device host(%{public}s, %{public}u)", hostClnt->hostName, hostClnt->hostId);
113 return HDF_FAILURE;
114 }
115 OsalMutexLock(&hostClnt->hostLock);
116 }
117
118 if (hostClnt->hostService == NULL || hostClnt->hostService->AddDevice == NULL) {
119 OsalMutexUnlock(&hostClnt->hostLock);
120 HDF_LOGE("%{public}s load %{public}s failed, hostService is null", __func__, serviceName);
121 return HDF_FAILURE;
122 }
123 ret = hostClnt->hostService->AddDevice(hostClnt->hostService, deviceInfo);
124 OsalMutexUnlock(&hostClnt->hostLock);
125 if (ret == HDF_SUCCESS) {
126 deviceInfo->status = HDF_SERVICE_USABLE;
127 }
128 return ret;
129 }
130
DevmgrServiceStopHost(struct DevHostServiceClnt * hostClnt)131 static int DevmgrServiceStopHost(struct DevHostServiceClnt *hostClnt)
132 {
133 struct IDriverInstaller *installer = DriverInstallerGetInstance();
134 if (installer == NULL || installer->StopDeviceHost == NULL) {
135 HDF_LOGE("invalid installer");
136 return HDF_FAILURE;
137 }
138 installer->StopDeviceHost(hostClnt->hostId, hostClnt->hostName);
139 hostClnt->stopFlag = true;
140 return HDF_SUCCESS;
141 }
142
DevmgrServiceUnloadDevice(struct IDevmgrService * devMgrSvc,const char * serviceName)143 static int DevmgrServiceUnloadDevice(struct IDevmgrService *devMgrSvc, const char *serviceName)
144 {
145 struct HdfDeviceInfo *deviceInfo = NULL;
146 struct DevHostServiceClnt *hostClnt = NULL;
147 int ret;
148 (void)devMgrSvc;
149
150 if (serviceName == NULL) {
151 return HDF_ERR_INVALID_PARAM;
152 }
153
154 if (!DevmgrServiceDynamicDevInfoFound(serviceName, &hostClnt, &deviceInfo) ||
155 deviceInfo->preload != DEVICE_PRELOAD_DISABLE) {
156 HDF_LOGE("device %{public}s not in configed dynamic device list", serviceName);
157 return HDF_DEV_ERR_NO_DEVICE;
158 }
159 OsalMutexLock(&hostClnt->hostLock);
160 if (hostClnt->hostService == NULL || hostClnt->hostService->DelDevice == NULL) {
161 OsalMutexUnlock(&hostClnt->hostLock);
162 HDF_LOGE("%{public}s unload %{public}s failed, hostService is null", __func__, serviceName);
163 return HDF_FAILURE;
164 }
165 ret = hostClnt->hostService->DelDevice(hostClnt->hostService, deviceInfo->deviceId);
166 if (ret != HDF_SUCCESS) {
167 OsalMutexUnlock(&hostClnt->hostLock);
168 HDF_LOGI("%{public}s:unload service %{public}s delDevice failed", __func__, serviceName);
169 return ret;
170 }
171 deviceInfo->status = HDF_SERVICE_UNUSABLE;
172 if (!HdfSListIsEmpty(&hostClnt->devices)) {
173 OsalMutexUnlock(&hostClnt->hostLock);
174 HDF_LOGD("%{public}s host %{public}s devices is not empty", __func__, hostClnt->hostName);
175 return HDF_SUCCESS;
176 }
177 hostClnt->hostPid = INVALID_PID;
178 hostClnt->hostService = NULL; // old hostService will be recycled in CleanupDiedHostResources
179 HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete);
180 OsalMutexUnlock(&hostClnt->hostLock);
181 ret = DevmgrServiceStopHost(hostClnt);
182
183 return ret;
184 }
185
DevmgrServiceLoadLeftDriver(struct DevmgrService * devMgrSvc)186 int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
187 {
188 int32_t ret;
189 struct HdfSListIterator itDeviceInfo;
190 struct HdfDeviceInfo *deviceInfo = NULL;
191 struct DevHostServiceClnt *hostClnt = NULL;
192 if (devMgrSvc == NULL) {
193 return HDF_FAILURE;
194 }
195
196 DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
197 HdfSListIteratorInit(&itDeviceInfo, &hostClnt->unloadDevInfos);
198 while (HdfSListIteratorHasNext(&itDeviceInfo)) {
199 deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
200 if (deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2) {
201 ret = hostClnt->hostService->AddDevice(hostClnt->hostService, deviceInfo);
202 if (ret != HDF_SUCCESS) {
203 HDF_LOGE("%{public}s:failed to load driver %{public}s", __func__, deviceInfo->moduleName);
204 continue;
205 }
206 deviceInfo->status = HDF_SERVICE_USABLE;
207 HdfSListIteratorRemove(&itDeviceInfo);
208 }
209 }
210 }
211 return HDF_SUCCESS;
212 }
213
DevmgrServiceFindDeviceHost(struct IDevmgrService * inst,uint16_t hostId)214 static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrService *inst, uint16_t hostId)
215 {
216 struct DevHostServiceClnt *hostClnt = NULL;
217 struct DevmgrService *dmService = (struct DevmgrService *)inst;
218 if (dmService == NULL) {
219 HDF_LOGE("failed to find device host, dmService is null");
220 return NULL;
221 }
222
223 DLIST_FOR_EACH_ENTRY(hostClnt, &dmService->hosts, struct DevHostServiceClnt, node) {
224 if (hostClnt->hostId == hostId) {
225 return hostClnt;
226 }
227 }
228 HDF_LOGE("cannot find host %{public}u", hostId);
229 return NULL;
230 }
231
DevmgrServiceAttachDevice(struct IDevmgrService * inst,struct IHdfDeviceToken * token)232 static int DevmgrServiceAttachDevice(struct IDevmgrService *inst, struct IHdfDeviceToken *token)
233 {
234 struct DevHostServiceClnt *hostClnt = NULL;
235 struct DeviceTokenClnt *tokenClnt = NULL;
236
237 hostClnt = DevmgrServiceFindDeviceHost(inst, HOSTID(token->devid));
238 if (hostClnt == NULL) {
239 HDF_LOGE("failed to attach device, hostClnt is null");
240 return HDF_FAILURE;
241 }
242 tokenClnt = DeviceTokenClntNewInstance(token);
243 if (tokenClnt == NULL) {
244 HDF_LOGE("failed to attach device, tokenClnt is null");
245 return HDF_FAILURE;
246 }
247
248 HdfSListAdd(&hostClnt->devices, &tokenClnt->node);
249 return HDF_SUCCESS;
250 }
251
HdfSListHostSearchDeviceTokenComparer(struct HdfSListNode * tokenNode,uint32_t devid)252 static bool HdfSListHostSearchDeviceTokenComparer(struct HdfSListNode *tokenNode, uint32_t devid)
253 {
254 struct DeviceTokenClnt *tokenClnt = CONTAINER_OF(tokenNode, struct DeviceTokenClnt, node);
255 return tokenClnt->tokenIf->devid == devid;
256 }
257
DevmgrServiceDetachDevice(struct IDevmgrService * inst,devid_t devid)258 static int DevmgrServiceDetachDevice(struct IDevmgrService *inst, devid_t devid)
259 {
260 struct DevHostServiceClnt *hostClnt = NULL;
261 struct DeviceTokenClnt *tokenClnt = NULL;
262 struct HdfSListNode *tokenClntNode = NULL;
263
264 hostClnt = DevmgrServiceFindDeviceHost(inst, HOSTID(devid));
265 if (hostClnt == NULL) {
266 HDF_LOGE("failed to attach device, hostClnt is null");
267 return HDF_FAILURE;
268 }
269 tokenClntNode = HdfSListSearch(&hostClnt->devices, devid, HdfSListHostSearchDeviceTokenComparer);
270 if (tokenClntNode == NULL) {
271 HDF_LOGE("devmgr detach device %{public}x not found", devid);
272 return HDF_DEV_ERR_NO_DEVICE;
273 }
274 tokenClnt = CONTAINER_OF(tokenClntNode, struct DeviceTokenClnt, node);
275 HdfSListRemove(&hostClnt->devices, &tokenClnt->node);
276 return HDF_SUCCESS;
277 }
278
DevmgrServiceAttachDeviceHost(struct IDevmgrService * inst,uint16_t hostId,struct IDevHostService * hostService)279 static int DevmgrServiceAttachDeviceHost(
280 struct IDevmgrService *inst, uint16_t hostId, struct IDevHostService *hostService)
281 {
282 struct DevHostServiceClnt *hostClnt = DevmgrServiceFindDeviceHost(inst, hostId);
283 if (hostClnt == NULL) {
284 HDF_LOGE("failed to attach device host, hostClnt is null");
285 return HDF_FAILURE;
286 }
287 if (hostService == NULL) {
288 HDF_LOGE("failed to attach device host, hostService is null");
289 return HDF_FAILURE;
290 }
291
292 (void)OsalMutexLock(&hostClnt->hostLock);
293 hostClnt->hostService = hostService;
294 (void)OsalMutexUnlock(&hostClnt->hostLock);
295 return DevHostServiceClntInstallDriver(hostClnt);
296 }
297
DevmgrServiceStartDeviceHost(struct DevmgrService * devmgr,struct HdfHostInfo * hostAttr)298 static int DevmgrServiceStartDeviceHost(struct DevmgrService *devmgr, struct HdfHostInfo *hostAttr)
299 {
300 struct DevHostServiceClnt *hostClnt = DevHostServiceClntNewInstance(hostAttr->hostId, hostAttr->hostName);
301 if (hostClnt == NULL) {
302 HDF_LOGW("failed to create new device host client");
303 return HDF_FAILURE;
304 }
305
306 if (HdfAttributeManagerGetDeviceList(hostClnt) != HDF_SUCCESS) {
307 HDF_LOGW("failed to get device list for host %{public}s", hostClnt->hostName);
308 return HDF_FAILURE;
309 }
310
311 DListInsertTail(&hostClnt->node, &devmgr->hosts);
312
313 // not start the host which only have dynamic devices
314 if (HdfSListIsEmpty(&hostClnt->unloadDevInfos)) {
315 return HDF_SUCCESS;
316 }
317
318 if (DevmgrServiceStartHostProcess(hostClnt, false, false) != HDF_SUCCESS) {
319 HDF_LOGW("failed to start device host, host id is %{public}u", hostAttr->hostId);
320 DListRemove(&hostClnt->node);
321 DevHostServiceClntFreeInstance(hostClnt);
322 return HDF_FAILURE;
323 }
324 return HDF_SUCCESS;
325 }
326
DevmgrServiceStartDeviceHosts(struct DevmgrService * inst)327 static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
328 {
329 int ret;
330 struct HdfSList hostList;
331 struct HdfSListIterator it;
332 struct HdfHostInfo *hostAttr = NULL;
333
334 HdfSListInit(&hostList);
335 if (!HdfAttributeManagerGetHostList(&hostList)) {
336 HDF_LOGW("%s: host list is null", __func__);
337 return HDF_SUCCESS;
338 }
339 HdfSListIteratorInit(&it, &hostList);
340 while (HdfSListIteratorHasNext(&it)) {
341 hostAttr = (struct HdfHostInfo *)HdfSListIteratorNext(&it);
342 ret = DevmgrServiceStartDeviceHost(inst, hostAttr);
343 if (ret != HDF_SUCCESS) {
344 HDF_LOGW("%{public}s failed to start device host, host id is %{public}u, host name is '%{public}s'",
345 __func__, hostAttr->hostId, hostAttr->hostName);
346 }
347 }
348 HdfSListFlush(&hostList, HdfHostInfoDelete);
349 return HDF_SUCCESS;
350 }
351
DevmgrServiceListAllDevice(struct IDevmgrService * inst,struct HdfSBuf * reply)352 static int32_t DevmgrServiceListAllDevice(struct IDevmgrService *inst, struct HdfSBuf *reply)
353 {
354 struct DevmgrService *devMgrSvc = (struct DevmgrService *)inst;
355 struct DevHostServiceClnt *hostClnt = NULL;
356 struct HdfSListIterator iterator;
357 struct HdfSListNode *node = NULL;
358 const char *name = NULL;
359
360 if (devMgrSvc == NULL || reply == NULL) {
361 HDF_LOGE("%{public}s failed, parameter is null", __func__);
362 return HDF_FAILURE;
363 }
364
365 DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
366 HdfSbufWriteString(reply, hostClnt->hostName);
367 HdfSbufWriteUint32(reply, hostClnt->hostId);
368 HdfSbufWriteUint32(reply, HdfSListCount(&hostClnt->devices));
369
370 HdfSListIteratorInit(&iterator, &hostClnt->devices);
371 while (HdfSListIteratorHasNext(&iterator)) {
372 node = HdfSListIteratorNext(&iterator);
373 struct DeviceTokenClnt *tokenClnt = (struct DeviceTokenClnt *)node;
374 if (tokenClnt != NULL && tokenClnt->tokenIf != NULL) {
375 name = (tokenClnt->tokenIf->deviceName == NULL) ? "" : tokenClnt->tokenIf->deviceName;
376 HdfSbufWriteString(reply, name);
377 HdfSbufWriteUint32(reply, tokenClnt->tokenIf->devid);
378 name = (tokenClnt->tokenIf->servName == NULL) ? "" : tokenClnt->tokenIf->servName;
379 HdfSbufWriteString(reply, name);
380 } else {
381 HDF_LOGI("%{public}s host:%{public}s token null", __func__, hostClnt->hostName);
382 }
383 }
384 }
385 return HDF_SUCCESS;
386 }
387
DevmgrServiceStartService(struct IDevmgrService * inst)388 int DevmgrServiceStartService(struct IDevmgrService *inst)
389 {
390 int ret;
391 struct DevmgrService *dmService = (struct DevmgrService *)inst;
392 if (dmService == NULL) {
393 HDF_LOGE("failed to start device manager service, dmService is null");
394 return HDF_FAILURE;
395 }
396
397 ret = DevSvcManagerStartService();
398 HDF_LOGI("start svcmgr result %{public}d", ret);
399
400 return DevmgrServiceStartDeviceHosts(dmService);
401 }
402
DevmgrServicePowerStateChange(struct IDevmgrService * devmgrService,enum HdfPowerState powerState)403 int DevmgrServicePowerStateChange(struct IDevmgrService *devmgrService, enum HdfPowerState powerState)
404 {
405 struct DevHostServiceClnt *hostClient = NULL;
406 struct DevmgrService *devmgr = NULL;
407 int result = HDF_SUCCESS;
408
409 if (devmgrService == NULL) {
410 return HDF_ERR_INVALID_OBJECT;
411 }
412
413 if (!IsValidPowerState(powerState)) {
414 HDF_LOGE("%{public}s:invalid power event %{public}u", __func__, powerState);
415 return HDF_ERR_INVALID_PARAM;
416 }
417 devmgr = CONTAINER_OF(devmgrService, struct DevmgrService, super);
418
419 if (IsPowerWakeState(powerState)) {
420 HDF_LOGI("%{public}s:wake state %{public}u", __func__, powerState);
421 DLIST_FOR_EACH_ENTRY(hostClient, &devmgr->hosts, struct DevHostServiceClnt, node) {
422 if (hostClient->hostService != NULL) {
423 if (hostClient->hostService->PmNotify(hostClient->hostService, powerState) != HDF_SUCCESS) {
424 result = HDF_FAILURE;
425 }
426 }
427 }
428 } else {
429 HDF_LOGI("%{public}s:suspend state %{public}u", __func__, powerState);
430 DLIST_FOR_EACH_ENTRY_REVERSE(hostClient, &devmgr->hosts, struct DevHostServiceClnt, node) {
431 if (hostClient->hostService != NULL) {
432 if (hostClient->hostService->PmNotify(hostClient->hostService, powerState) != HDF_SUCCESS) {
433 result = HDF_FAILURE;
434 }
435 }
436 }
437 }
438
439 return result;
440 }
441
DevmgrServiceConstruct(struct DevmgrService * inst)442 bool DevmgrServiceConstruct(struct DevmgrService *inst)
443 {
444 struct IDevmgrService *devMgrSvcIf = NULL;
445 if (OsalMutexInit(&inst->devMgrMutex) != HDF_SUCCESS) {
446 HDF_LOGE("%s:failed to mutex init ", __func__);
447 return false;
448 }
449 devMgrSvcIf = (struct IDevmgrService *)inst;
450 if (devMgrSvcIf != NULL) {
451 devMgrSvcIf->AttachDevice = DevmgrServiceAttachDevice;
452 devMgrSvcIf->DetachDevice = DevmgrServiceDetachDevice;
453 devMgrSvcIf->LoadDevice = DevmgrServiceLoadDevice;
454 devMgrSvcIf->UnloadDevice = DevmgrServiceUnloadDevice;
455 devMgrSvcIf->AttachDeviceHost = DevmgrServiceAttachDeviceHost;
456 devMgrSvcIf->StartService = DevmgrServiceStartService;
457 devMgrSvcIf->PowerStateChange = DevmgrServicePowerStateChange;
458 devMgrSvcIf->ListAllDevice = DevmgrServiceListAllDevice;
459 DListHeadInit(&inst->hosts);
460 return true;
461 } else {
462 return false;
463 }
464 }
465
DevmgrServiceCreate(void)466 struct HdfObject *DevmgrServiceCreate(void)
467 {
468 static bool isDevMgrServiceInit = false;
469 static struct DevmgrService devmgrServiceInstance;
470 if (!isDevMgrServiceInit) {
471 if (!DevmgrServiceConstruct(&devmgrServiceInstance)) {
472 return NULL;
473 }
474 isDevMgrServiceInit = true;
475 }
476 return (struct HdfObject *)&devmgrServiceInstance;
477 }
478
DevmgrServiceGetInstance(void)479 struct IDevmgrService *DevmgrServiceGetInstance(void)
480 {
481 static struct IDevmgrService *instance = NULL;
482 if (instance == NULL) {
483 instance = (struct IDevmgrService *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVMGR_SERVICE);
484 }
485 return instance;
486 }
487
DevmgrServiceRelease(struct HdfObject * object)488 void DevmgrServiceRelease(struct HdfObject *object)
489 {
490 struct DevmgrService *devmgrService = (struct DevmgrService *)object;
491 struct DevHostServiceClnt *hostClnt = NULL;
492 struct DevHostServiceClnt *hostClntTmp = NULL;
493 if (devmgrService == NULL) {
494 return;
495 }
496 DLIST_FOR_EACH_ENTRY_SAFE(hostClnt, hostClntTmp, &devmgrService->hosts, struct DevHostServiceClnt, node) {
497 DListRemove(&hostClnt->node);
498 DevHostServiceClntDelete(hostClnt);
499 }
500
501 OsalMutexDestroy(&devmgrService->devMgrMutex);
502 }
503