blob: 6b642612767346cbe5343351304f7c792639511d [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302 * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
Ben Romberger55886882014-01-10 13:49:02 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Ben Romberger61764e32014-01-10 13:49:02 -080030#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080031#define LOG_NDDEBUG 0
32
33#include <errno.h>
34#include <stdio.h>
35#include <expat.h>
36#include <cutils/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070037#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080038#include <audio_hw.h>
Ben Romberger61764e32014-01-10 13:49:02 -080039#include "platform_api.h"
40#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070041#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080042
Ben Romberger55886882014-01-10 13:49:02 -080043#define BUF_SIZE 1024
44
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070045typedef enum {
46 ROOT,
47 ACDB,
Amit Shekhar5a39c912014-10-14 15:39:30 -070048 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070049 PCM_ID,
50 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080051 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070052 CONFIG_PARAMS,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070053 GAIN_LEVEL_MAPPING,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053054 ACDB_METAINFO_KEY,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070055} section_t;
56
57typedef void (* section_process_fn)(const XML_Char **attr);
58
59static void process_acdb_id(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070060static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070061static void process_pcm_id(const XML_Char **attr);
62static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080063static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070064static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070065static void process_root(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070066static void process_gain_db_to_level_map(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053067static void process_acdb_metainfo_key(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070068
69static section_process_fn section_table[] = {
70 [ROOT] = process_root,
71 [ACDB] = process_acdb_id,
Amit Shekhar5a39c912014-10-14 15:39:30 -070072 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070073 [PCM_ID] = process_pcm_id,
74 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080075 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070076 [CONFIG_PARAMS] = process_config_params,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070077 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053078 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070079};
80
81static section_t section;
82
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070083struct platform_info {
84 void *platform;
85 struct str_parms *kvpairs;
86};
87
88static struct platform_info my_data;
89
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070090/*
91 * <audio_platform_info>
92 * <acdb_ids>
93 * <device name="???" acdb_id="???"/>
94 * ...
95 * ...
96 * </acdb_ids>
97 * <backend_names>
98 * <device name="???" backend="???"/>
99 * ...
100 * ...
101 * </backend_names>
102 * <pcm_ids>
103 * <usecase name="???" type="in/out" id="???"/>
104 * ...
105 * ...
106 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800107 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530108 * <device name="Use audio device name here, not sound device name" interface="PRIMARY_I2S" codec_type="external/internal"/>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800109 * ...
110 * ...
111 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700112 * <config_params>
113 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
114 * ...
115 * ...
116 * </config_params>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700117 * </audio_platform_info>
118 */
119
120static void process_root(const XML_Char **attr __unused)
121{
122}
123
124/* mapping from usecase to pcm dev id */
125static void process_pcm_id(const XML_Char **attr)
126{
127 int index;
128
129 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700130 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700131 goto done;
132 }
133
134 index = platform_get_usecase_index((char *)attr[1]);
135 if (index < 0) {
136 ALOGE("%s: usecase %s not found!",
137 __func__, attr[1]);
138 goto done;
139 }
140
141 if (strcmp(attr[2], "type") != 0) {
142 ALOGE("%s: usecase type not mentioned", __func__);
143 goto done;
144 }
145
146 int type = -1;
147
148 if (!strcasecmp((char *)attr[3], "in")) {
149 type = 1;
150 } else if (!strcasecmp((char *)attr[3], "out")) {
151 type = 0;
152 } else {
153 ALOGE("%s: type must be IN or OUT", __func__);
154 goto done;
155 }
156
157 if (strcmp(attr[4], "id") != 0) {
158 ALOGE("%s: usecase id not mentioned", __func__);
159 goto done;
160 }
161
162 int id = atoi((char *)attr[5]);
163
164 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
165 ALOGE("%s: usecase %s type %d id %d was not set!",
166 __func__, attr[1], type, id);
167 goto done;
168 }
169
170done:
171 return;
172}
173
174/* backend to be used for a device */
175static void process_backend_name(const XML_Char **attr)
176{
177 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530178 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530179 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700180
181 if (strcmp(attr[0], "name") != 0) {
182 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
183 goto done;
184 }
185
186 index = platform_get_snd_device_index((char *)attr[1]);
187 if (index < 0) {
188 ALOGE("%s: Device %s not found, no ACDB ID set!",
189 __func__, attr[1]);
190 goto done;
191 }
192
193 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530194 if (strcmp(attr[2], "interface") == 0)
195 hw_interface = (char *)attr[3];
196 } else {
197 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700198 }
199
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530200 if (attr[4] != NULL) {
201 if (strcmp(attr[4], "interface") != 0) {
202 hw_interface = NULL;
203 } else {
204 hw_interface = (char *)attr[5];
205 }
206 }
207
Ashish Jaind150d4c2017-02-03 18:44:34 +0530208 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700209 ALOGE("%s: Device %s backend %s was not set!",
210 __func__, attr[1], attr[3]);
211 goto done;
212 }
213
214done:
215 return;
216}
217
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700218static void process_gain_db_to_level_map(const XML_Char **attr)
219{
220 struct amp_db_and_gain_table tbl_entry;
221
222 if ((strcmp(attr[0], "db") != 0) ||
223 (strcmp(attr[2], "level") != 0)) {
224 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
225 __func__, attr[0], attr[2]);
226 goto done;
227 }
228
229 tbl_entry.db = atof(attr[1]);
230 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
231 tbl_entry.level = atoi(attr[3]);
232
233 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
234 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
235 platform_add_gain_level_mapping(&tbl_entry);
236
237done:
238 return;
239}
240
241
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700242static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800243{
Ben Romberger61764e32014-01-10 13:49:02 -0800244 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800245
Ben Romberger61764e32014-01-10 13:49:02 -0800246 if (strcmp(attr[0], "name") != 0) {
247 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800248 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800249 }
Ben Romberger55886882014-01-10 13:49:02 -0800250
Ben Romberger61764e32014-01-10 13:49:02 -0800251 index = platform_get_snd_device_index((char *)attr[1]);
252 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800253 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
254 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800255 goto done;
256 }
257
258 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800259 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
260 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800261 goto done;
262 }
263
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700264 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
265 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800266 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800267 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800268 }
Ben Romberger55886882014-01-10 13:49:02 -0800269
Ben Romberger55886882014-01-10 13:49:02 -0800270done:
271 return;
272}
273
Amit Shekhar5a39c912014-10-14 15:39:30 -0700274static void process_bit_width(const XML_Char **attr)
275{
276 int index;
277
278 if (strcmp(attr[0], "name") != 0) {
279 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
280 goto done;
281 }
282
283 index = platform_get_snd_device_index((char *)attr[1]);
284 if (index < 0) {
285 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
286 __func__, attr[1]);
287 goto done;
288 }
289
290 if (strcmp(attr[2], "bit_width") != 0) {
291 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
292 __func__, attr[1]);
293 goto done;
294 }
295
296 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
297 ALOGE("%s: Device %s, ACDB ID %d was not set!",
298 __func__, attr[1], atoi((char *)attr[3]));
299 goto done;
300 }
301
302done:
303 return;
304}
305
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800306static void process_interface_name(const XML_Char **attr)
307{
308 int ret;
309
310 if (strcmp(attr[0], "name") != 0) {
311 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
312
313 goto done;
314 }
315
316 if (strcmp(attr[2], "interface") != 0) {
317 ALOGE("%s: Device %s has no Audio Interface set!",
318 __func__, attr[1]);
319
320 goto done;
321 }
322
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530323 if (strcmp(attr[4], "codec_type") != 0) {
324 ALOGE("%s: Device %s has no codec type set!",
325 __func__, attr[1]);
326
327 goto done;
328 }
329
330 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
331 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800332 if (ret < 0) {
333 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800334 goto done;
335 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800336
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800337done:
338 return;
339}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530340
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700341static void process_config_params(const XML_Char **attr)
342{
343 if (strcmp(attr[0], "key") != 0) {
344 ALOGE("%s: 'key' not found", __func__);
345 goto done;
346 }
347
348 if (strcmp(attr[2], "value") != 0) {
349 ALOGE("%s: 'value' not found", __func__);
350 goto done;
351 }
352
353 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
354done:
355 return;
356}
357
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530358/* process acdb meta info key value */
359static void process_acdb_metainfo_key(const XML_Char **attr)
360{
361 if (strcmp(attr[0], "name") != 0) {
362 ALOGE("%s: 'name' not found", __func__);
363 goto done;
364 }
365
366 if (strcmp(attr[2], "value") != 0) {
367 ALOGE("%s: 'value' not found", __func__);
368 goto done;
369 }
370
371 int key = atoi((char *)attr[3]);
372 if (platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
373 ALOGE("%s: key %d was not set!", __func__, key);
374 goto done;
375 }
376
377done:
378 return;
379}
380
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700381static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -0800382 const XML_Char **attr)
383{
Amit Shekhar5a39c912014-10-14 15:39:30 -0700384 if (strcmp(tag_name, "bit_width_configs") == 0) {
385 section = BITWIDTH;
386 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700387 section = ACDB;
388 } else if (strcmp(tag_name, "pcm_ids") == 0) {
389 section = PCM_ID;
390 } else if (strcmp(tag_name, "backend_names") == 0) {
391 section = BACKEND_NAME;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700392 } else if (strcmp(tag_name, "config_params") == 0) {
393 section = CONFIG_PARAMS;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800394 } else if (strcmp(tag_name, "interface_names") == 0) {
395 section = INTERFACE_NAME;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700396 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
397 section = GAIN_LEVEL_MAPPING;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530398 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
399 section = ACDB_METAINFO_KEY;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700400 } else if (strcmp(tag_name, "device") == 0) {
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800401 if ((section != ACDB) && (section != BACKEND_NAME) && (section != BITWIDTH) &&
Laxminath Kasam167ade52016-05-23 17:46:51 +0530402 (section != INTERFACE_NAME)) {
403 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700404 return;
405 }
406
407 /* call into process function for the current section */
408 section_process_fn fn = section_table[section];
409 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700410 } else if (strcmp(tag_name, "gain_level_map") == 0) {
411 if (section != GAIN_LEVEL_MAPPING) {
412 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
413 return;
414 }
415
416 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
417 fn(attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700418 } else if (strcmp(tag_name, "usecase") == 0) {
419 if (section != PCM_ID) {
420 ALOGE("usecase tag only supported with PCM_ID section");
421 return;
422 }
423
424 section_process_fn fn = section_table[PCM_ID];
425 fn(attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700426 } else if (strcmp(tag_name, "param") == 0) {
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530427 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700428 ALOGE("param tag only supported with CONFIG_PARAMS section");
429 return;
430 }
431
432 section_process_fn fn = section_table[section];
433 fn(attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700434 }
Ben Romberger55886882014-01-10 13:49:02 -0800435
436 return;
437}
438
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700439static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -0800440{
Amit Shekhar5a39c912014-10-14 15:39:30 -0700441 if (strcmp(tag_name, "bit_width_configs") == 0) {
442 section = ROOT;
443 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700444 section = ROOT;
445 } else if (strcmp(tag_name, "pcm_ids") == 0) {
446 section = ROOT;
447 } else if (strcmp(tag_name, "backend_names") == 0) {
448 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700449 } else if (strcmp(tag_name, "config_params") == 0) {
450 section = ROOT;
451 platform_set_parameters(my_data.platform, my_data.kvpairs);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800452 } else if (strcmp(tag_name, "interface_names") == 0) {
453 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700454 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
455 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530456 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
457 section = ROOT;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700458 }
Ben Romberger55886882014-01-10 13:49:02 -0800459}
460
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700461int platform_info_init(const char *filename, void *platform)
Ben Romberger55886882014-01-10 13:49:02 -0800462{
463 XML_Parser parser;
464 FILE *file;
465 int ret = 0;
466 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -0800467 void *buf;
468
Helen Zeng6a16ad72014-02-23 22:04:44 -0800469 file = fopen(filename, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700470 section = ROOT;
471
Ben Romberger55886882014-01-10 13:49:02 -0800472 if (!file) {
473 ALOGD("%s: Failed to open %s, using defaults.",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800474 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -0800475 ret = -ENODEV;
476 goto done;
477 }
478
479 parser = XML_ParserCreate(NULL);
480 if (!parser) {
481 ALOGE("%s: Failed to create XML parser!", __func__);
482 ret = -ENODEV;
483 goto err_close_file;
484 }
485
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700486 my_data.platform = platform;
487 my_data.kvpairs = str_parms_create();
488
Ben Romberger55886882014-01-10 13:49:02 -0800489 XML_SetElementHandler(parser, start_tag, end_tag);
490
491 while (1) {
492 buf = XML_GetBuffer(parser, BUF_SIZE);
493 if (buf == NULL) {
494 ALOGE("%s: XML_GetBuffer failed", __func__);
495 ret = -ENOMEM;
496 goto err_free_parser;
497 }
498
499 bytes_read = fread(buf, 1, BUF_SIZE, file);
500 if (bytes_read < 0) {
501 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
502 ret = bytes_read;
503 goto err_free_parser;
504 }
505
506 if (XML_ParseBuffer(parser, bytes_read,
507 bytes_read == 0) == XML_STATUS_ERROR) {
508 ALOGE("%s: XML_ParseBuffer failed, for %s",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800509 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -0800510 ret = -EINVAL;
511 goto err_free_parser;
512 }
513
514 if (bytes_read == 0)
515 break;
516 }
517
Ben Romberger55886882014-01-10 13:49:02 -0800518err_free_parser:
519 XML_ParserFree(parser);
520err_close_file:
521 fclose(file);
522done:
523 return ret;
524}