blob: a63b2150ab3f00032aae9a9614d0c304746d2d73 [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;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700179
180 if (strcmp(attr[0], "name") != 0) {
181 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
182 goto done;
183 }
184
185 index = platform_get_snd_device_index((char *)attr[1]);
186 if (index < 0) {
187 ALOGE("%s: Device %s not found, no ACDB ID set!",
188 __func__, attr[1]);
189 goto done;
190 }
191
192 if (strcmp(attr[2], "backend") != 0) {
193 ALOGE("%s: Device %s has no backend set!",
194 __func__, attr[1]);
195 goto done;
196 }
197
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530198 if (attr[4] != NULL) {
199 if (strcmp(attr[4], "interface") != 0) {
200 hw_interface = NULL;
201 } else {
202 hw_interface = (char *)attr[5];
203 }
204 }
205
206 if (platform_set_snd_device_backend(index, attr[3], hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700207 ALOGE("%s: Device %s backend %s was not set!",
208 __func__, attr[1], attr[3]);
209 goto done;
210 }
211
212done:
213 return;
214}
215
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700216static void process_gain_db_to_level_map(const XML_Char **attr)
217{
218 struct amp_db_and_gain_table tbl_entry;
219
220 if ((strcmp(attr[0], "db") != 0) ||
221 (strcmp(attr[2], "level") != 0)) {
222 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
223 __func__, attr[0], attr[2]);
224 goto done;
225 }
226
227 tbl_entry.db = atof(attr[1]);
228 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
229 tbl_entry.level = atoi(attr[3]);
230
231 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
232 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
233 platform_add_gain_level_mapping(&tbl_entry);
234
235done:
236 return;
237}
238
239
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700240static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800241{
Ben Romberger61764e32014-01-10 13:49:02 -0800242 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800243
Ben Romberger61764e32014-01-10 13:49:02 -0800244 if (strcmp(attr[0], "name") != 0) {
245 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800246 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800247 }
Ben Romberger55886882014-01-10 13:49:02 -0800248
Ben Romberger61764e32014-01-10 13:49:02 -0800249 index = platform_get_snd_device_index((char *)attr[1]);
250 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800251 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
252 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800253 goto done;
254 }
255
256 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800257 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
258 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800259 goto done;
260 }
261
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700262 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
263 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800264 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800265 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800266 }
Ben Romberger55886882014-01-10 13:49:02 -0800267
Ben Romberger55886882014-01-10 13:49:02 -0800268done:
269 return;
270}
271
Amit Shekhar5a39c912014-10-14 15:39:30 -0700272static void process_bit_width(const XML_Char **attr)
273{
274 int index;
275
276 if (strcmp(attr[0], "name") != 0) {
277 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
278 goto done;
279 }
280
281 index = platform_get_snd_device_index((char *)attr[1]);
282 if (index < 0) {
283 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
284 __func__, attr[1]);
285 goto done;
286 }
287
288 if (strcmp(attr[2], "bit_width") != 0) {
289 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
290 __func__, attr[1]);
291 goto done;
292 }
293
294 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
295 ALOGE("%s: Device %s, ACDB ID %d was not set!",
296 __func__, attr[1], atoi((char *)attr[3]));
297 goto done;
298 }
299
300done:
301 return;
302}
303
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800304static void process_interface_name(const XML_Char **attr)
305{
306 int ret;
307
308 if (strcmp(attr[0], "name") != 0) {
309 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
310
311 goto done;
312 }
313
314 if (strcmp(attr[2], "interface") != 0) {
315 ALOGE("%s: Device %s has no Audio Interface set!",
316 __func__, attr[1]);
317
318 goto done;
319 }
320
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530321 if (strcmp(attr[4], "codec_type") != 0) {
322 ALOGE("%s: Device %s has no codec type set!",
323 __func__, attr[1]);
324
325 goto done;
326 }
327
328 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
329 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800330 if (ret < 0) {
331 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800332 goto done;
333 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800334
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800335done:
336 return;
337}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530338
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700339static void process_config_params(const XML_Char **attr)
340{
341 if (strcmp(attr[0], "key") != 0) {
342 ALOGE("%s: 'key' not found", __func__);
343 goto done;
344 }
345
346 if (strcmp(attr[2], "value") != 0) {
347 ALOGE("%s: 'value' not found", __func__);
348 goto done;
349 }
350
351 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
352done:
353 return;
354}
355
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530356/* process acdb meta info key value */
357static void process_acdb_metainfo_key(const XML_Char **attr)
358{
359 if (strcmp(attr[0], "name") != 0) {
360 ALOGE("%s: 'name' not found", __func__);
361 goto done;
362 }
363
364 if (strcmp(attr[2], "value") != 0) {
365 ALOGE("%s: 'value' not found", __func__);
366 goto done;
367 }
368
369 int key = atoi((char *)attr[3]);
370 if (platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
371 ALOGE("%s: key %d was not set!", __func__, key);
372 goto done;
373 }
374
375done:
376 return;
377}
378
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700379static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -0800380 const XML_Char **attr)
381{
Amit Shekhar5a39c912014-10-14 15:39:30 -0700382 if (strcmp(tag_name, "bit_width_configs") == 0) {
383 section = BITWIDTH;
384 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700385 section = ACDB;
386 } else if (strcmp(tag_name, "pcm_ids") == 0) {
387 section = PCM_ID;
388 } else if (strcmp(tag_name, "backend_names") == 0) {
389 section = BACKEND_NAME;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700390 } else if (strcmp(tag_name, "config_params") == 0) {
391 section = CONFIG_PARAMS;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800392 } else if (strcmp(tag_name, "interface_names") == 0) {
393 section = INTERFACE_NAME;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700394 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
395 section = GAIN_LEVEL_MAPPING;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530396 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
397 section = ACDB_METAINFO_KEY;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700398 } else if (strcmp(tag_name, "device") == 0) {
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800399 if ((section != ACDB) && (section != BACKEND_NAME) && (section != BITWIDTH) &&
Laxminath Kasam167ade52016-05-23 17:46:51 +0530400 (section != INTERFACE_NAME)) {
401 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700402 return;
403 }
404
405 /* call into process function for the current section */
406 section_process_fn fn = section_table[section];
407 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700408 } else if (strcmp(tag_name, "gain_level_map") == 0) {
409 if (section != GAIN_LEVEL_MAPPING) {
410 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
411 return;
412 }
413
414 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
415 fn(attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700416 } else if (strcmp(tag_name, "usecase") == 0) {
417 if (section != PCM_ID) {
418 ALOGE("usecase tag only supported with PCM_ID section");
419 return;
420 }
421
422 section_process_fn fn = section_table[PCM_ID];
423 fn(attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700424 } else if (strcmp(tag_name, "param") == 0) {
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530425 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700426 ALOGE("param tag only supported with CONFIG_PARAMS section");
427 return;
428 }
429
430 section_process_fn fn = section_table[section];
431 fn(attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700432 }
Ben Romberger55886882014-01-10 13:49:02 -0800433
434 return;
435}
436
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700437static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -0800438{
Amit Shekhar5a39c912014-10-14 15:39:30 -0700439 if (strcmp(tag_name, "bit_width_configs") == 0) {
440 section = ROOT;
441 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700442 section = ROOT;
443 } else if (strcmp(tag_name, "pcm_ids") == 0) {
444 section = ROOT;
445 } else if (strcmp(tag_name, "backend_names") == 0) {
446 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700447 } else if (strcmp(tag_name, "config_params") == 0) {
448 section = ROOT;
449 platform_set_parameters(my_data.platform, my_data.kvpairs);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800450 } else if (strcmp(tag_name, "interface_names") == 0) {
451 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700452 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
453 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530454 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
455 section = ROOT;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700456 }
Ben Romberger55886882014-01-10 13:49:02 -0800457}
458
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700459int platform_info_init(const char *filename, void *platform)
Ben Romberger55886882014-01-10 13:49:02 -0800460{
461 XML_Parser parser;
462 FILE *file;
463 int ret = 0;
464 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -0800465 void *buf;
466
Helen Zeng6a16ad72014-02-23 22:04:44 -0800467 file = fopen(filename, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700468 section = ROOT;
469
Ben Romberger55886882014-01-10 13:49:02 -0800470 if (!file) {
471 ALOGD("%s: Failed to open %s, using defaults.",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800472 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -0800473 ret = -ENODEV;
474 goto done;
475 }
476
477 parser = XML_ParserCreate(NULL);
478 if (!parser) {
479 ALOGE("%s: Failed to create XML parser!", __func__);
480 ret = -ENODEV;
481 goto err_close_file;
482 }
483
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700484 my_data.platform = platform;
485 my_data.kvpairs = str_parms_create();
486
Ben Romberger55886882014-01-10 13:49:02 -0800487 XML_SetElementHandler(parser, start_tag, end_tag);
488
489 while (1) {
490 buf = XML_GetBuffer(parser, BUF_SIZE);
491 if (buf == NULL) {
492 ALOGE("%s: XML_GetBuffer failed", __func__);
493 ret = -ENOMEM;
494 goto err_free_parser;
495 }
496
497 bytes_read = fread(buf, 1, BUF_SIZE, file);
498 if (bytes_read < 0) {
499 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
500 ret = bytes_read;
501 goto err_free_parser;
502 }
503
504 if (XML_ParseBuffer(parser, bytes_read,
505 bytes_read == 0) == XML_STATUS_ERROR) {
506 ALOGE("%s: XML_ParseBuffer failed, for %s",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800507 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -0800508 ret = -EINVAL;
509 goto err_free_parser;
510 }
511
512 if (bytes_read == 0)
513 break;
514 }
515
Ben Romberger55886882014-01-10 13:49:02 -0800516err_free_parser:
517 XML_ParserFree(parser);
518err_close_file:
519 fclose(file);
520done:
521 return ret;
522}