1 /*
2  * Copyright (c) 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 <securec.h>
10 #include <hdf_log.h>
11 #include "camera_config_parser.h"
12 #include "camera_device_manager.h"
13 #include "camera_utils.h"
14 
15 #define HDF_LOG_TAG HDF_CAMERA_UTILS
16 
17 #define CAMERA_DEVICE_BIT_MAX 2
18 #define DEC_CALC_COEFF 10
19 #define FPS_CALC_COEFF 1000
20 #define UINT_MAX_VAL 0xFFFFFFFF
21 #define UVC_DEVICE_ID 0
22 
23 static int32_t g_cameraIdMap[ID_MAX_NUM];
24 
FindAvailableId(uint32_t * id)25 bool FindAvailableId(uint32_t *id)
26 {
27     uint32_t i;
28     if (id == NULL) {
29         HDF_LOGE("%s: param is null ptr", __func__);
30         return false;
31     }
32     for (i = 0; i < ID_MAX_NUM; i++) {
33         if (g_cameraIdMap[i] == 0) {
34             *id = i;
35             return true;
36         }
37     }
38     return false;
39 }
40 
AddPermissionId(int32_t id,int32_t permissionId)41 int32_t AddPermissionId(int32_t id, int32_t permissionId)
42 {
43     if (id >= ID_MAX_NUM) {
44         HDF_LOGE("%s: error: id out of range!", __func__);
45         return HDF_FAILURE;
46     }
47     if (g_cameraIdMap[id] != 0) {
48         HDF_LOGE("%s: error: g_cameraIdMap[%{public}d] is already exist!", __func__, id);
49         return HDF_FAILURE;
50     }
51     g_cameraIdMap[id] = permissionId;
52     return HDF_SUCCESS;
53 }
54 
RemovePermissionId(int32_t id)55 int32_t RemovePermissionId(int32_t id)
56 {
57     int32_t i;
58     for (i = 0; i < ID_MAX_NUM; i++) {
59         if (g_cameraIdMap[i] != 0) {
60             if (g_cameraIdMap[i] == id) {
61                 g_cameraIdMap[i] = 0;
62                 return HDF_SUCCESS;
63             }
64         }
65     }
66     return HDF_FAILURE;
67 }
68 
GetCameraId(const char * str,int length,int * id)69 int32_t GetCameraId(const char *str, int length, int *id)
70 {
71     int32_t ret[CAMERA_DEVICE_BIT_MAX];
72     int32_t i = 0;
73     int32_t j = 0;
74 
75     if (str == NULL || id == NULL) {
76         HDF_LOGE("%s: param is null ptr", __func__);
77         return HDF_ERR_INVALID_PARAM;
78     }
79 
80     for (i = 0; i < length; i++) {
81         if ((*(str + i) < '0') || (*(str + i) > '9')) {
82             continue;
83         }
84         if (j >= CAMERA_DEVICE_BIT_MAX) {
85             HDF_LOGE("%s: wrong num: %{public}d", __func__, j);
86             return HDF_ERR_INVALID_PARAM;
87         }
88         ret[j] = (*(str + i) - '0');
89         j++;
90     }
91     *id = 0;
92     for (i = 0; i < j; i++) {
93         *id = ret[i] + (*id) * DEC_CALC_COEFF;
94     }
95     if (*id > CAMERA_MAX_NUM) {
96         HDF_LOGE("%s: wrong id: %{public}d", __func__, id);
97         return HDF_ERR_INVALID_PARAM;
98     }
99     return HDF_SUCCESS;
100 }
101 
GetDeviceDriver(const struct CameraDevice * cameraDev)102 struct CameraDeviceDriver *GetDeviceDriver(const struct CameraDevice *cameraDev)
103 {
104     if (cameraDev == NULL) {
105         HDF_LOGE("%s: cameraDev is null!", __func__);
106         return NULL;
107     }
108     return cameraDev->deviceDriver;
109 }
110 
CheckPermission(int permissionId)111 int32_t CheckPermission(int permissionId)
112 {
113     if (permissionId != CAMERA_MASTER) {
114         HDF_LOGE("%s: No permissions set ctrl!", __func__);
115         return HDF_ERR_NOPERM;
116     }
117     return HDF_SUCCESS;
118 }
119 
CheckSwitchType(int type,struct CameraConfigRoot * rootConfig,int32_t camId)120 static int32_t CheckSwitchType(int type, struct CameraConfigRoot *rootConfig, int32_t camId)
121 {
122     switch (type) {
123         case SENSOR_TYPE:
124             if (rootConfig->deviceConfig[camId].sensor.mode == DEVICE_NOT_SUPPORT) {
125                 HDF_LOGE("%s: sendor device %{public}d not supported!", __func__, camId);
126                 return HDF_ERR_NOT_SUPPORT;
127             }
128             break;
129         case ISP_TYPE:
130             if (rootConfig->deviceConfig[camId].isp.mode == DEVICE_NOT_SUPPORT) {
131                 HDF_LOGE("%s: isp device %{public}d not supported!", __func__, camId);
132                 return HDF_ERR_NOT_SUPPORT;
133             }
134             break;
135         case VCM_TYPE:
136             if (rootConfig->deviceConfig[camId].vcm.mode == DEVICE_NOT_SUPPORT) {
137                 HDF_LOGE("%s: vcm device %{public}d not supported!", __func__, camId);
138                 return HDF_ERR_NOT_SUPPORT;
139             }
140             break;
141         case LENS_TYPE:
142             if (rootConfig->deviceConfig[camId].lens.mode == DEVICE_NOT_SUPPORT) {
143                 HDF_LOGE("%s: lens device %{public}d not supported!", __func__, camId);
144                 return HDF_ERR_NOT_SUPPORT;
145             }
146             break;
147         case FLASH_TYPE:
148             if (rootConfig->deviceConfig[camId].flash.mode == DEVICE_NOT_SUPPORT) {
149                 HDF_LOGE("%s: flash device %{public}d not supported!", __func__, camId);
150                 return HDF_ERR_NOT_SUPPORT;
151             }
152             break;
153         case UVC_TYPE:
154             if (rootConfig->uvcMode == DEVICE_NOT_SUPPORT) {
155                 HDF_LOGE("%s: uvc device %{public}d not supported!", __func__, camId);
156                 return HDF_ERR_NOT_SUPPORT;
157             }
158             break;
159         case STREAM_TYPE:
160             break;
161         default:
162             HDF_LOGE("%s: wrong type: %{public}d", __func__, type);
163             return HDF_ERR_NOT_SUPPORT;
164     }
165     return HDF_SUCCESS;
166 }
167 
CheckCameraDevice(const char * deviceName,int type)168 int32_t CheckCameraDevice(const char *deviceName, int type)
169 {
170     int32_t ret;
171     int32_t camId = 0;
172     struct CameraConfigRoot *rootConfig = NULL;
173 
174     if (deviceName == NULL) {
175         HDF_LOGE("%s: get deviceName failed!", __func__);
176         return HDF_FAILURE;
177     }
178     rootConfig = HdfCameraGetConfigRoot();
179     if (rootConfig == NULL) {
180         HDF_LOGE("%s: get rootConfig failed!", __func__);
181         return HDF_FAILURE;
182     }
183     ret = GetCameraId(deviceName, strlen(deviceName), &camId);
184     CHECK_RETURN_RET(ret);
185 
186     ret = CheckSwitchType(type, rootConfig, camId);
187     return ret;
188 }
189 
GetSensorDevice(const char * kernelDrvName,struct CameraDeviceDriver * regDev)190 struct SensorDevice *GetSensorDevice(const char *kernelDrvName, struct CameraDeviceDriver *regDev)
191 {
192     int32_t i;
193     for (i = 0; i < DEVICE_NUM; i++) {
194         if (regDev->sensor[i] == NULL) {
195             continue;
196         }
197         if (strcmp(regDev->sensor[i]->kernelDrvName, kernelDrvName) == 0) {
198             return regDev->sensor[i];
199         }
200     }
201     return NULL;
202 }
203 
GetIspDevice(const char * kernelDrvName,struct CameraDeviceDriver * regDev)204 struct IspDevice *GetIspDevice(const char *kernelDrvName, struct CameraDeviceDriver *regDev)
205 {
206     int32_t i;
207     for (i = 0; i < DEVICE_NUM; i++) {
208         if (regDev->isp[i] == NULL) {
209             continue;
210         }
211         if (strcmp(regDev->isp[i]->kernelDrvName, kernelDrvName) == 0) {
212             return regDev->isp[i];
213         }
214     }
215     return NULL;
216 }
217 
GetLensDevice(const char * kernelDrvName,struct CameraDeviceDriver * regDev)218 struct LensDevice *GetLensDevice(const char *kernelDrvName, struct CameraDeviceDriver *regDev)
219 {
220     int32_t i;
221     for (i = 0; i < DEVICE_NUM; i++) {
222         if (regDev->lens[i] == NULL) {
223             continue;
224         }
225         if (strcmp(regDev->lens[i]->kernelDrvName, kernelDrvName) == 0) {
226             return regDev->lens[i];
227         }
228     }
229     return NULL;
230 }
231 
GetFlashDevice(const char * kernelDrvName,struct CameraDeviceDriver * regDev)232 struct FlashDevice *GetFlashDevice(const char *kernelDrvName, struct CameraDeviceDriver *regDev)
233 {
234     int32_t i;
235     for (i = 0; i < DEVICE_NUM; i++) {
236         if (regDev->flash[i] == NULL) {
237             continue;
238         }
239         if (strcmp(regDev->flash[i]->kernelDrvName, kernelDrvName) == 0) {
240             return regDev->flash[i];
241         }
242     }
243     return NULL;
244 }
245 
GetVcmDevice(const char * kernelDrvName,struct CameraDeviceDriver * regDev)246 struct VcmDevice *GetVcmDevice(const char *kernelDrvName, struct CameraDeviceDriver *regDev)
247 {
248     int32_t i;
249     for (i = 0; i < DEVICE_NUM; i++) {
250         if (regDev->vcm[i] == NULL) {
251             continue;
252         }
253         if (strcmp(regDev->vcm[i]->kernelDrvName, kernelDrvName) == 0) {
254             return regDev->vcm[i];
255         }
256     }
257     return NULL;
258 }
259 
GetUvcDevice(const char * kernelDrvName,struct CameraDeviceDriver * regDev)260 struct UvcDevice *GetUvcDevice(const char *kernelDrvName, struct CameraDeviceDriver *regDev)
261 {
262     int32_t i;
263     for (i = 0; i < DEVICE_NUM; i++) {
264         if (regDev->uvc[i] == NULL) {
265             continue;
266         }
267         if (strcmp(regDev->uvc[i]->kernelDrvName, kernelDrvName) == 0) {
268             return regDev->uvc[i];
269         }
270     }
271     return NULL;
272 }
273 
GetStreamDevice(const char * kernelDrvName,struct CameraDeviceDriver * regDev)274 struct StreamDevice *GetStreamDevice(const char *kernelDrvName, struct CameraDeviceDriver *regDev)
275 {
276     int32_t i;
277     for (i = 0; i < DEVICE_NUM; i++) {
278         if (regDev->stream[i] == NULL) {
279             continue;
280         }
281         if (strcmp(regDev->stream[i]->kernelDrvName, kernelDrvName) == 0) {
282             return regDev->stream[i];
283         }
284     }
285     return NULL;
286 }
287 
GetSensorNum(const char * driverName,int camId,struct CameraConfigRoot * rootConfig)288 static int32_t GetSensorNum(const char *driverName, int camId, struct CameraConfigRoot *rootConfig)
289 {
290     int32_t i, j;
291     for (i = 0; i < rootConfig->deviceNum; i++) {
292         for (j = 0; j < rootConfig->deviceConfig[camId].sensor.sensorNum; j++) {
293             if (strcmp(rootConfig->deviceConfig[camId].sensor.sensor[j].name, driverName) == 0) {
294                 return j;
295             }
296         }
297     }
298     return HDF_FAILURE;
299 }
300 
GetIspNum(const char * driverName,int camId,struct CameraConfigRoot * rootConfig)301 static int32_t GetIspNum(const char *driverName, int camId, struct CameraConfigRoot *rootConfig)
302 {
303     int32_t i, j;
304     for (i = 0; i < rootConfig->deviceNum; i++) {
305         for (j = 0; j < rootConfig->deviceConfig[camId].isp.ispNum; j++) {
306             if (strcmp(rootConfig->deviceConfig[camId].isp.isp[j].name, driverName) == 0) {
307                 return j;
308             }
309         }
310     }
311     return HDF_FAILURE;
312 }
313 
GetVcmNum(const char * driverName,int camId,struct CameraConfigRoot * rootConfig)314 static int32_t GetVcmNum(const char *driverName, int camId, struct CameraConfigRoot *rootConfig)
315 {
316     int32_t i, j;
317     for (i = 0; i < rootConfig->deviceNum; i++) {
318         for (j = 0; j < rootConfig->deviceConfig[camId].vcm.vcmNum; j++) {
319             if (strcmp(rootConfig->deviceConfig[camId].vcm.vcm[j].name, driverName) == 0) {
320                 return j;
321             }
322         }
323     }
324     return HDF_FAILURE;
325 }
326 
GetLensNum(const char * driverName,int camId,struct CameraConfigRoot * rootConfig)327 static int32_t GetLensNum(const char *driverName, int camId, struct CameraConfigRoot *rootConfig)
328 {
329     int32_t i, j;
330     for (i = 0; i < rootConfig->deviceNum; i++) {
331         for (j = 0; j < rootConfig->deviceConfig[camId].lens.lensNum; j++) {
332             if (strcmp(rootConfig->deviceConfig[camId].lens.lens[j].name, driverName) == 0) {
333                 return j;
334             }
335         }
336     }
337     return HDF_FAILURE;
338 }
339 
GetFlashNum(const char * driverName,int camId,struct CameraConfigRoot * rootConfig)340 static int32_t GetFlashNum(const char *driverName, int camId, struct CameraConfigRoot *rootConfig)
341 {
342     int32_t i, j;
343     for (i = 0; i < rootConfig->deviceNum; i++) {
344         for (j = 0; j < rootConfig->deviceConfig[camId].flash.flashNum; j++) {
345             if (strcmp(rootConfig->deviceConfig[camId].flash.flash[j].name, driverName) == 0) {
346                 return j;
347             }
348         }
349     }
350     return HDF_FAILURE;
351 }
352 
GetStreamNum(const char * driverName,struct CameraDeviceDriver * deviceDriver)353 int32_t GetStreamNum(const char *driverName, struct CameraDeviceDriver *deviceDriver)
354 {
355     int32_t i;
356     for (i = 0; i < DEVICE_NUM; i++) {
357         if (deviceDriver->stream[i] == NULL) {
358             continue;
359         }
360         if (strcmp(deviceDriver->stream[i]->kernelDrvName, driverName) == 0) {
361             return i;
362         }
363     }
364     return HDF_FAILURE;
365 }
366 
GetUvcNum(const char * driverName,struct CameraDeviceDriver * deviceDriver)367 int32_t GetUvcNum(const char *driverName, struct CameraDeviceDriver *deviceDriver)
368 {
369     int32_t i;
370     for (i = 0; i < DEVICE_NUM; i++) {
371         if (deviceDriver->uvc[i] == NULL) {
372             continue;
373         }
374         if (strcmp(deviceDriver->uvc[i]->kernelDrvName, driverName) == 0) {
375             return i;
376         }
377     }
378     return HDF_FAILURE;
379 }
380 
GetDeviceNum(const char * driverName,int camId,int type)381 int32_t GetDeviceNum(const char *driverName, int camId, int type)
382 {
383     int32_t ret;
384     struct CameraConfigRoot *rootConfig = NULL;
385 
386     rootConfig = HdfCameraGetConfigRoot();
387     if (rootConfig == NULL) {
388         HDF_LOGE("%s: get rootConfig failed!", __func__);
389         return HDF_FAILURE;
390     }
391     switch (type) {
392         case SENSOR_TYPE:
393             ret = GetSensorNum(driverName, camId, rootConfig);
394             break;
395         case ISP_TYPE:
396             ret = GetIspNum(driverName, camId, rootConfig);
397             break;
398         case VCM_TYPE:
399             ret = GetVcmNum(driverName, camId, rootConfig);
400             break;
401         case LENS_TYPE:
402             ret = GetLensNum(driverName, camId, rootConfig);
403             break;
404         case FLASH_TYPE:
405             ret = GetFlashNum(driverName, camId, rootConfig);
406             break;
407         case UVC_TYPE:
408             ret = UVC_DEVICE_ID;
409             break;
410         default:
411             HDF_LOGE("%s: wrong type: %{public}d", __func__, type);
412             return HDF_ERR_NOT_SUPPORT;
413     }
414     return ret;
415 }
416 
CheckFrameRate(int camId,const char * driverName,int type,struct CameraCtrlConfig * ctrlConfig)417 int32_t CheckFrameRate(int camId, const char *driverName, int type, struct CameraCtrlConfig *ctrlConfig)
418 {
419     int32_t fps;
420     int32_t deviceNum;
421     struct CameraConfigRoot *rootConfig = NULL;
422 
423     rootConfig = HdfCameraGetConfigRoot();
424     if (rootConfig == NULL) {
425         HDF_LOGE("%s: get rootConfig failed!", __func__);
426         return HDF_FAILURE;
427     }
428     deviceNum = GetDeviceNum(driverName, camId, type);
429     if (deviceNum < 0 || deviceNum >= DEVICE_NUM) {
430         return HDF_ERR_INVALID_PARAM;
431     }
432     if (ctrlConfig->pixelFormat.fps.numerator == 0 || ctrlConfig->pixelFormat.fps.denominator == 0) {
433         HDF_LOGE("%s: wrong numerator %{public}d or wrong denominator %{public}d!", __func__,
434             ctrlConfig->pixelFormat.fps.numerator, ctrlConfig->pixelFormat.fps.denominator);
435         return HDF_ERR_INVALID_PARAM;
436     }
437     if (FPS_CALC_COEFF > UINT_MAX_VAL / ctrlConfig->pixelFormat.fps.denominator) {
438         HDF_LOGE("%s: wrong num!", __func__);
439         return HDF_ERR_INVALID_PARAM;
440     }
441     fps = FPS_CALC_COEFF * (ctrlConfig->pixelFormat.fps.denominator) / ctrlConfig->pixelFormat.fps.numerator;
442 
443     switch (type) {
444         case STREAM_TYPE:
445             if (fps > FPS_CALC_COEFF * (rootConfig->deviceConfig[camId].stream.stream[deviceNum].frameRateMaxNum)) {
446                 HDF_LOGE("%s: stream%{public}d wrong fps = %{public}d", __func__, deviceNum, fps);
447                 return HDF_ERR_INVALID_PARAM;
448             }
449             break;
450         default:
451             HDF_LOGE("%s: wrong type: %{public}d", __func__, type);
452             return HDF_ERR_NOT_SUPPORT;
453     }
454     return HDF_SUCCESS;
455 }
456 
CameraGetDeviceInfo(int type,struct HdfSBuf * reqData,const char ** driverName,int32_t * camId,struct CameraDevice ** camDev)457 int32_t CameraGetDeviceInfo(int type, struct HdfSBuf *reqData,
458     const char **driverName, int32_t *camId, struct CameraDevice **camDev)
459 {
460     int32_t ret;
461     const char *deviceName = NULL;
462 
463     deviceName = HdfSbufReadString(reqData);
464     if (deviceName == NULL) {
465         HDF_LOGE("%s: Read deviceName failed!", __func__);
466         return HDF_FAILURE;
467     }
468 
469     ret = GetCameraId(deviceName, strlen(deviceName), camId);
470     CHECK_RETURN_RET(ret);
471     if ((*camId) > CAMERA_DEVICE_MAX_NUM) {
472         HDF_LOGE("%s: wrong camId! camId=%{public}d", __func__, (*camId));
473         return HDF_FAILURE;
474     }
475 
476     ret = CheckCameraDevice(deviceName, type);
477     CHECK_RETURN_RET(ret);
478 
479     *driverName = HdfSbufReadString(reqData);
480     if (*driverName == NULL) {
481         HDF_LOGE("%s: Read driverName failed!", __func__);
482         return HDF_FAILURE;
483     }
484 
485     *camDev = CameraDeviceGetByName(deviceName);
486     if (*camDev == NULL) {
487         HDF_LOGE("%s: camDev not found! deviceName=%{public}s", __func__, deviceName);
488         return HDF_FAILURE;
489     }
490     return HDF_SUCCESS;
491 }
492 
CameraGetNames(int type,struct HdfSBuf * reqData,const char ** deviceName,const char ** driverName)493 int32_t CameraGetNames(int type, struct HdfSBuf *reqData, const char **deviceName, const char **driverName)
494 {
495     int32_t ret;
496 
497     *deviceName = HdfSbufReadString(reqData);
498     if (*deviceName == NULL) {
499         HDF_LOGE("%s: Read deviceName failed!", __func__);
500         return HDF_FAILURE;
501     }
502     ret = CheckCameraDevice(*deviceName, type);
503     CHECK_RETURN_RET(ret);
504     *driverName = HdfSbufReadString(reqData);
505     if (*driverName == NULL) {
506         HDF_LOGE("%s: Read driverName failed!", __func__);
507         return HDF_FAILURE;
508     }
509     return HDF_SUCCESS;
510 }
511 
GetDeviceOps(struct CameraDeviceDriver * deviceDriver,int type,int32_t camId,const char * driverName,struct DeviceOps ** devOps)512 int32_t GetDeviceOps(struct CameraDeviceDriver *deviceDriver,
513     int type, int32_t camId, const char *driverName, struct DeviceOps **devOps)
514 {
515     int32_t num;
516 
517     num = GetDeviceNum(driverName, camId, type);
518     if (num < 0 || num >= DEVICE_NUM) {
519         HDF_LOGE("%s: wrong num: %{public}d", __func__, num);
520         return HDF_ERR_INVALID_PARAM;
521     }
522     switch (type) {
523         case SENSOR_TYPE:
524             *devOps = deviceDriver->sensor[num]->devOps;
525             break;
526         case ISP_TYPE:
527             *devOps = deviceDriver->isp[num]->devOps;
528             break;
529         case VCM_TYPE:
530             *devOps = deviceDriver->vcm[num]->devOps;
531             break;
532         case LENS_TYPE:
533             *devOps = deviceDriver->lens[num]->devOps;
534             break;
535         case FLASH_TYPE:
536             *devOps = deviceDriver->flash[num]->devOps;
537             break;
538         case UVC_TYPE:
539             *devOps = deviceDriver->uvc[num]->devOps;
540             break;
541         default:
542             HDF_LOGE("%s: wrong type: %{public}d", __func__, type);
543             return HDF_ERR_NOT_SUPPORT;
544     }
545     return HDF_SUCCESS;
546 }
547 
CameraDeviceGetCtrlConfig(struct CommonDevice * comDev,struct CameraDeviceConfig ** deviceConfig,int32_t * deviceId)548 int32_t CameraDeviceGetCtrlConfig(struct CommonDevice *comDev,
549     struct CameraDeviceConfig **deviceConfig, int32_t *deviceId)
550 {
551     int32_t num;
552     struct CameraConfigRoot *rootConfig = NULL;
553 
554     rootConfig = HdfCameraGetConfigRoot();
555     if (rootConfig == NULL) {
556         HDF_LOGE("%s: get rootConfig failed!", __func__);
557         return HDF_FAILURE;
558     }
559     if (comDev->camId > CAMERA_DEVICE_MAX_NUM) {
560         HDF_LOGE("%s: wrong camId! camId=%{public}d", __func__, comDev->camId);
561         return HDF_FAILURE;
562     }
563     *deviceConfig  = &rootConfig->deviceConfig[comDev->camId];
564     num = GetDeviceNum(comDev->driverName, comDev->camId, comDev->type);
565     if (num < 0 || num >= DEVICE_NUM) {
566         return HDF_ERR_INVALID_PARAM;
567     }
568     *deviceId = num;
569     return HDF_SUCCESS;
570 }
571 
CameraGetDevice(struct HdfSBuf * reqData,struct CommonDevice * comDev)572 int32_t CameraGetDevice(struct HdfSBuf *reqData, struct CommonDevice *comDev)
573 {
574     int32_t ret;
575 
576     if (!HdfSbufReadInt32(reqData, &comDev->type)) {
577         HDF_LOGE("%s: Read request data failed! type = %{public}d", __func__, comDev->type);
578         return HDF_FAILURE;
579     }
580     if (!HdfSbufReadInt32(reqData, &comDev->permissionId)) {
581         HDF_LOGE("%s: Read request data failed! permissionId = %{public}d", __func__, comDev->permissionId);
582         return HDF_FAILURE;
583     }
584     ret = CheckPermission(comDev->permissionId);
585     CHECK_RETURN_RET(ret);
586     ret = CameraGetDeviceInfo(comDev->type, reqData, &comDev->driverName, &comDev->camId, &comDev->camDev);
587     CHECK_RETURN_RET(ret);
588     return HDF_SUCCESS;
589 }
590 
CameraDispatchCommonInfo(const struct HdfDeviceIoClient * client,struct HdfSBuf * reqData,struct HdfSBuf * rspData,struct CommonDevice * comDev)591 int32_t CameraDispatchCommonInfo(const struct HdfDeviceIoClient *client,
592     struct HdfSBuf *reqData, struct HdfSBuf *rspData, struct CommonDevice *comDev)
593 {
594     int32_t ret;
595 
596     if (client == NULL || reqData == NULL || rspData == NULL) {
597         return HDF_ERR_INVALID_PARAM;
598     }
599     ret = CameraGetDevice(reqData, comDev);
600     CHECK_RETURN_RET(ret);
601     comDev->reqData = reqData;
602     comDev->rspData = rspData;
603     return HDF_SUCCESS;
604 }