1 /*
2 * Copyright (c) 2022 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 "hdf_audio_events.h"
17 #include <stdlib.h>
18 #include <string.h>
19 #include "securec.h"
20 #include "hdf_base.h"
21 #include "audio_uhdf_log.h"
22
23 #define HDF_LOG_TAG HDF_AUDIO_HAL_HOST
24
25 #define STRTOL_FORMART_HEX 16
26
AudioPnpMsgReadValue(const char * pnpInfo,const char * typeName,uint32_t * value)27 int32_t AudioPnpMsgReadValue(const char *pnpInfo, const char *typeName, uint32_t *value)
28 {
29 char pnpInfoTemp[AUDIO_PNP_MSG_LEN_MAX] = {0};
30 char *typeNameTepm = NULL;
31 char *outTemp = NULL;
32
33 if (pnpInfo == NULL || typeName == NULL || value == NULL) {
34 AUDIO_FUNC_LOGE("pnpInfo || typeName || value is null!");
35 return HDF_FAILURE;
36 }
37 if (strlen(pnpInfo) > AUDIO_PNP_MSG_LEN_MAX || strlen(typeName) > AUDIO_PNP_MSG_LEN_MAX) {
38 AUDIO_FUNC_LOGE("pnpInfo or typeName length error!");
39 return HDF_FAILURE;
40 }
41 if (memcpy_s(pnpInfoTemp, AUDIO_PNP_MSG_LEN_MAX, pnpInfo, strlen(pnpInfo)) != 0) {
42 AUDIO_FUNC_LOGE("memcpy_s info fail!");
43 return HDF_FAILURE;
44 }
45 typeNameTepm = strtok_s(pnpInfoTemp, ";", &outTemp);
46 while (typeNameTepm) {
47 if (!strncmp(typeNameTepm, typeName, strlen(typeName))) {
48 typeNameTepm += strlen(typeName) + 1; // 1 is "="
49 *value = strtol(typeNameTepm, NULL, STRTOL_FORMART_HEX);
50 break;
51 }
52 typeNameTepm = strtok_s(NULL, ";", &outTemp);
53 };
54
55 return HDF_SUCCESS;
56 }
57