blob: 8ab035b2f6d9fca39bb3660887f71f6e01205be6 [file] [log] [blame]
Michael Bestas3a0209e2023-05-04 01:15:47 +03001/* Copyright (c) 2011-2015, 2018-2020 The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation, nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#define LOG_NDEBUG 0
31#define LOG_TAG "LocSvc_utils_cfg"
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <pthread.h>
36#include <string.h>
37#include <ctype.h>
38#include <unistd.h>
39#include <time.h>
40#include <grp.h>
41#include <errno.h>
42#include <loc_cfg.h>
43#include <loc_pla.h>
44#include <loc_target.h>
45#include <loc_misc_utils.h>
46#ifdef USE_GLIB
47#include <glib.h>
48#endif
49#include "log_util.h"
50
51/*=============================================================================
52 *
53 * GLOBAL DATA DECLARATION
54 *
55 *============================================================================*/
56
57/* Parameter data */
58static uint32_t DEBUG_LEVEL = 0xff;
59static uint32_t TIMESTAMP = 0;
60static uint32_t DATUM_TYPE = 0;
61static bool sVendorEnhanced = true;
62static uint32_t sLogBufferEnabled = 0;
63
64/* Parameter spec table */
65static const loc_param_s_type loc_param_table[] =
66{
67 {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'},
68 {"TIMESTAMP", &TIMESTAMP, NULL, 'n'},
69 {"DATUM_TYPE", &DATUM_TYPE, NULL, 'n'},
70 {"LOG_BUFFER_ENABLED", &sLogBufferEnabled, NULL, 'n'},
71};
72static const int loc_param_num = sizeof(loc_param_table) / sizeof(loc_param_s_type);
73
74typedef struct loc_param_v_type
75{
76 char* param_name;
77 char* param_str_value;
78 int param_int_value;
79 double param_double_value;
80}loc_param_v_type;
81
82// Reference below arrays wherever needed to avoid duplicating
83// same conf path string over and again in location code.
84const char LOC_PATH_GPS_CONF[] = LOC_PATH_GPS_CONF_STR;
85const char LOC_PATH_IZAT_CONF[] = LOC_PATH_IZAT_CONF_STR;
86const char LOC_PATH_FLP_CONF[] = LOC_PATH_FLP_CONF_STR;
87const char LOC_PATH_LOWI_CONF[] = LOC_PATH_LOWI_CONF_STR;
88const char LOC_PATH_SAP_CONF[] = LOC_PATH_SAP_CONF_STR;
89const char LOC_PATH_APDR_CONF[] = LOC_PATH_APDR_CONF_STR;
90const char LOC_PATH_XTWIFI_CONF[] = LOC_PATH_XTWIFI_CONF_STR;
91const char LOC_PATH_QUIPC_CONF[] = LOC_PATH_QUIPC_CONF_STR;
92const char LOC_PATH_ANT_CORR[] = LOC_PATH_ANT_CORR_STR;
93const char LOC_PATH_SLIM_CONF[] = LOC_PATH_SLIM_CONF_STR;
94const char LOC_PATH_VPE_CONF[] = LOC_PATH_VPE_CONF_STR;
95
Michael Bestas05ca34d2023-05-05 20:09:13 +030096bool isXtraDaemonEnabled() {
97 bool enabled = property_get_bool("persist.sys.xtra-daemon.enabled", false);
98 LOC_LOGe("xtra-daemon enabled: %d\n", enabled);
99 return enabled;
100}
101
Michael Bestas3a0209e2023-05-04 01:15:47 +0300102bool isVendorEnhanced() {
103 return sVendorEnhanced;
104}
105void setVendorEnhanced(bool vendorEnhanced) {
106 sVendorEnhanced = vendorEnhanced;
107}
108
109/*===========================================================================
110FUNCTION loc_get_datum_type
111
112DESCRIPTION
113 get datum type
114
115PARAMETERS:
116 N/A
117
118DEPENDENCIES
119 N/A
120
121RETURN VALUE
122 DATUM TYPE
123
124SIDE EFFECTS
125 N/A
126===========================================================================*/
127int loc_get_datum_type()
128{
129 return DATUM_TYPE;
130}
131
132/*===========================================================================
133FUNCTION loc_set_config_entry
134
135DESCRIPTION
136 Potentially sets a given configuration table entry based on the passed in
137 configuration value. This is done by using a string comparison of the
138 parameter names and those found in the configuration file.
139
140PARAMETERS:
141 config_entry: configuration entry in the table to possibly set
142 config_value: value to store in the entry if the parameter names match
143
144DEPENDENCIES
145 N/A
146
147RETURN VALUE
148 None
149
150SIDE EFFECTS
151 N/A
152===========================================================================*/
153int loc_set_config_entry(const loc_param_s_type* config_entry,
154 loc_param_v_type* config_value,
155 uint16_t string_len = LOC_MAX_PARAM_STRING)
156{
157 int ret=-1;
158 if(NULL == config_entry || NULL == config_value)
159 {
160 LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__);
161 return ret;
162 }
163
164 if (strcmp(config_entry->param_name, config_value->param_name) == 0 &&
165 config_entry->param_ptr)
166 {
167 switch (config_entry->param_type)
168 {
169 case 's':
170 if (strcmp(config_value->param_str_value, "NULL") == 0)
171 {
172 *((char*)config_entry->param_ptr) = '\0';
173 }
174 else {
175 strlcpy((char*) config_entry->param_ptr,
176 config_value->param_str_value,
177 string_len);
178 }
179 /* Log INI values */
180 LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__,
181 config_entry->param_name, (char*)config_entry->param_ptr);
182
183 if(NULL != config_entry->param_set)
184 {
185 *(config_entry->param_set) = 1;
186 }
187 ret = 0;
188 break;
189 case 'n':
190 *((int *)config_entry->param_ptr) = config_value->param_int_value;
191 /* Log INI values */
192 LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__,
193 config_entry->param_name, config_value->param_int_value);
194
195 if(NULL != config_entry->param_set)
196 {
197 *(config_entry->param_set) = 1;
198 }
199 ret = 0;
200 break;
201 case 'f':
202 *((double *)config_entry->param_ptr) = config_value->param_double_value;
203 /* Log INI values */
204 LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__,
205 config_entry->param_name, config_value->param_double_value);
206
207 if(NULL != config_entry->param_set)
208 {
209 *(config_entry->param_set) = 1;
210 }
211 ret = 0;
212 break;
213 default:
214 LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s",
215 __FUNCTION__, config_entry->param_name);
216 }
217 }
218 return ret;
219}
220
221/*===========================================================================
222FUNCTION loc_fill_conf_item
223
224DESCRIPTION
225 Takes a line of configuration item and sets defined values based on
226 the passed in configuration table. This table maps strings to values to
227 set along with the type of each of these values.
228
229PARAMETERS:
230 input_buf : buffer contanis config item
231 config_table: table definition of strings to places to store information
232 table_length: length of the configuration table
233
234DEPENDENCIES
235 N/A
236
237RETURN VALUE
238 0: Number of records in the config_table filled with input_buf
239
240SIDE EFFECTS
241 N/A
242===========================================================================*/
243int loc_fill_conf_item(char* input_buf,
244 const loc_param_s_type* config_table,
245 uint32_t table_length, uint16_t string_len = LOC_MAX_PARAM_STRING)
246{
247 int ret = 0;
248
249 if (input_buf && config_table) {
250 char *lasts;
251 loc_param_v_type config_value;
252 memset(&config_value, 0, sizeof(config_value));
253
254 /* Separate variable and value */
255 config_value.param_name = strtok_r(input_buf, "=", &lasts);
256 /* skip lines that do not contain "=" */
257 if (config_value.param_name) {
258 config_value.param_str_value = strtok_r(NULL, "\0", &lasts);
259
260 /* skip lines that do not contain two operands */
261 if (config_value.param_str_value) {
262 /* Trim leading and trailing spaces */
263 loc_util_trim_space(config_value.param_name);
264 loc_util_trim_space(config_value.param_str_value);
265
266 /* Parse numerical value */
267 if ((strlen(config_value.param_str_value) >=3) &&
268 (config_value.param_str_value[0] == '0') &&
269 (tolower(config_value.param_str_value[1]) == 'x'))
270 {
271 /* hex */
272 config_value.param_int_value = (int) strtol(&config_value.param_str_value[2],
273 (char**) NULL, 16);
274 }
275 else {
276 config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */
277 config_value.param_int_value = atoi(config_value.param_str_value); /* dec */
278 }
279
280 for(uint32_t i = 0; NULL != config_table && i < table_length; i++)
281 {
282 if(!loc_set_config_entry(&config_table[i], &config_value, string_len)) {
283 ret += 1;
284 }
285 }
286 }
287 }
288 }
289
290 return ret;
291}
292
293/*===========================================================================
294FUNCTION loc_read_conf_r_long (repetitive)
295
296DESCRIPTION
297 Reads the specified configuration file and sets defined values based on
298 the passed in configuration table. This table maps strings to values to
299 set along with the type of each of these values.
300 The difference between this and loc_read_conf is that this function returns
301 the file pointer position at the end of filling a config table. Also, it
302 reads a fixed number of parameters at a time which is equal to the length
303 of the configuration table. This functionality enables the caller to
304 repeatedly call the function to read data from the same file.
305
306PARAMETERS:
307 conf_fp : file pointer
308 config_table: table definition of strings to places to store information
309 table_length: length of the configuration table
310
311DEPENDENCIES
312 N/A
313
314RETURN VALUE
315 0: Table filled successfully
316 1: No more parameters to read
317 -1: Error filling table
318
319SIDE EFFECTS
320 N/A
321===========================================================================*/
322int loc_read_conf_r_long(FILE *conf_fp, const loc_param_s_type* config_table,
323 uint32_t table_length, uint16_t string_len)
324{
325 int ret=0;
326 char input_buf[string_len]; /* declare a char array */
327 unsigned int num_params=table_length;
328
329 if(conf_fp == NULL) {
330 LOC_LOGE("%s:%d]: ERROR: File pointer is NULL\n", __func__, __LINE__);
331 ret = -1;
332 goto err;
333 }
334
335 /* Clear all validity bits */
336 for(uint32_t i = 0; NULL != config_table && i < table_length; i++)
337 {
338 if(NULL != config_table[i].param_set)
339 {
340 *(config_table[i].param_set) = 0;
341 }
342 }
343
344 LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params);
345 while(num_params)
346 {
347 if(!fgets(input_buf, string_len, conf_fp)) {
348 LOC_LOGD("%s:%d]: fgets returned NULL\n", __func__, __LINE__);
349 break;
350 }
351
352 num_params -= loc_fill_conf_item(input_buf, config_table, table_length, string_len);
353 }
354
355err:
356 return ret;
357}
358
359/*===========================================================================
360FUNCTION loc_udpate_conf_long
361
362DESCRIPTION
363 Parses the passed in buffer for configuration items, and update the table
364 that is also passed in.
365
366Reads the specified configuration file and sets defined values based on
367 the passed in configuration table. This table maps strings to values to
368 set along with the type of each of these values.
369
370PARAMETERS:
371 conf_data: configuration items in bufferas a string
372 length: strlen(conf_data)
373 config_table: table definition of strings to places to store information
374 table_length: length of the configuration table
375
376DEPENDENCIES
377 N/A
378
379RETURN VALUE
380 number of the records in the table that is updated at time of return.
381
382SIDE EFFECTS
383 N/A
384===========================================================================*/
385int loc_update_conf_long(const char* conf_data, int32_t length,
386 const loc_param_s_type* config_table,
387 uint32_t table_length, uint16_t string_len)
388{
389 int ret = -1;
390
391 if (conf_data && length && config_table && table_length) {
392 // make a copy, so we do not tokenize the original data
393 char* conf_copy = (char*)malloc(length+1);
394
395 if (conf_copy != NULL)
396 {
397 memcpy(conf_copy, conf_data, length);
398 // we hard NULL the end of string to be safe
399 conf_copy[length] = 0;
400
401 // start with one record off
402 uint32_t num_params = table_length - 1;
403 char* saveptr = NULL;
404 char* input_buf = strtok_r(conf_copy, "\n", &saveptr);
405 ret = 0;
406
407 LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params);
408 while(num_params && input_buf) {
409 ret++;
410 num_params -=
411 loc_fill_conf_item(input_buf, config_table, table_length, string_len);
412 input_buf = strtok_r(NULL, "\n", &saveptr);
413 }
414 free(conf_copy);
415 }
416 }
417
418 return ret;
419}
420
421/*===========================================================================
422FUNCTION loc_read_conf_long
423
424DESCRIPTION
425 Reads the specified configuration file and sets defined values based on
426 the passed in configuration table. This table maps strings to values to
427 set along with the type of each of these values.
428
429PARAMETERS:
430 conf_file_name: configuration file to read
431 config_table: table definition of strings to places to store information
432 table_length: length of the configuration table
433
434DEPENDENCIES
435 N/A
436
437RETURN VALUE
438 None
439
440SIDE EFFECTS
441 N/A
442===========================================================================*/
443void loc_read_conf_long(const char* conf_file_name, const loc_param_s_type* config_table,
444 uint32_t table_length, uint16_t string_len)
445{
446 FILE *conf_fp = NULL;
447
448 log_buffer_init(false);
449 if((conf_fp = fopen(conf_file_name, "r")) != NULL)
450 {
451 LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name);
452 if(table_length && config_table) {
453 loc_read_conf_r_long(conf_fp, config_table, table_length, string_len);
454 rewind(conf_fp);
455 }
456 loc_read_conf_r_long(conf_fp, loc_param_table, loc_param_num, string_len);
457 fclose(conf_fp);
458 }
459 /* Initialize logging mechanism with parsed data */
460 loc_logger_init(DEBUG_LEVEL, TIMESTAMP);
461 log_buffer_init(sLogBufferEnabled);
462 log_tag_level_map_init();
463}
464
465/*=============================================================================
466 *
467 * Define and Structures for Parsing Location Process Configuration File
468 *
469 *============================================================================*/
470#define MAX_NUM_STRINGS 20
471
472//We can have 8 masks for now
473#define CONFIG_MASK_TARGET_ALL 0X01
474#define CONFIG_MASK_TARGET_FOUND 0X02
475#define CONFIG_MASK_TARGET_CHECK 0X03
476#define CONFIG_MASK_BASEBAND_ALL 0X04
477#define CONFIG_MASK_BASEBAND_FOUND 0X08
478#define CONFIG_MASK_BASEBAND_CHECK 0x0c
479#define CONFIG_MASK_AUTOPLATFORM_ALL 0x10
480#define CONFIG_MASK_AUTOPLATFORM_FOUND 0x20
481#define CONFIG_MASK_AUTOPLATFORM_CHECK 0x30
482#define CONFIG_MASK_SOCID_ALL 0x40
483#define CONFIG_MASK_SOCID_FOUND 0x80
484#define CONFIG_MASK_SOCID_CHECK 0xc0
485
486#define LOC_FEATURE_MASK_GTP_WIFI_BASIC 0x01
487#define LOC_FEATURE_MASK_GTP_WIFI_PREMIUM 0X02
488#define LOC_FEATURE_MASK_GTP_CELL_BASIC 0X04
489#define LOC_FEATURE_MASK_GTP_CELL_PREMIUM 0X08
490#define LOC_FEATURE_MASK_SAP_BASIC 0x40
491#define LOC_FEATURE_MASK_SAP_PREMIUM 0X80
492#define LOC_FEATURE_MASK_GTP_WAA_BASIC 0X100
493#define LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC 0X400
494#define LOC_FEATURE_MASK_ODCPI 0x1000
495#define LOC_FEATURE_MASK_FREE_WIFI_SCAN_INJECT 0x2000
496#define LOC_FEATURE_MASK_SUPL_WIFI 0x4000
497#define LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO 0x8000
498
499typedef struct {
500 char proc_name[LOC_MAX_PARAM_STRING];
501 char proc_argument[LOC_MAX_PARAM_STRING];
502 char proc_status[LOC_MAX_PARAM_STRING];
503 char group_list[LOC_MAX_PARAM_STRING];
504 unsigned int premium_feature;
505 unsigned int loc_feature_mask;
506 char platform_list[LOC_MAX_PARAM_STRING];
507 char baseband[LOC_MAX_PARAM_STRING];
508 char low_ram_targets[LOC_MAX_PARAM_STRING];
509 char soc_id_list[LOC_MAX_PARAM_STRING];
510 unsigned int sglte_target;
511 char feature_gtp_mode[LOC_MAX_PARAM_STRING];
512 char feature_gtp_waa[LOC_MAX_PARAM_STRING];
513 char feature_sap[LOC_MAX_PARAM_STRING];
514 char feature_odcpi[LOC_MAX_PARAM_STRING];
515 char feature_free_wifi_scan_inject[LOC_MAX_PARAM_STRING];
516 char feature_supl_wifi[LOC_MAX_PARAM_STRING];
517 char feature_wifi_supplicant_info[LOC_MAX_PARAM_STRING];
518 char auto_platform[LOC_MAX_PARAM_STRING];
519 unsigned int vendor_enhanced_process;
520} loc_launcher_conf;
521
522/* process configuration parameters */
523static loc_launcher_conf conf;
524
525/* gps.conf Parameter spec table */
526static const loc_param_s_type gps_conf_parameter_table[] = {
527 {"SGLTE_TARGET", &conf.sglte_target, NULL, 'n'},
528};
529
530/* location feature conf, e.g.: izat.conf feature mode table*/
531static const loc_param_s_type loc_feature_conf_table[] = {
532 {"GTP_MODE", &conf.feature_gtp_mode, NULL, 's'},
533 {"GTP_WAA", &conf.feature_gtp_waa, NULL, 's'},
534 {"SAP", &conf.feature_sap, NULL, 's'},
535 {"ODCPI", &conf.feature_odcpi, NULL, 's'},
536 {"FREE_WIFI_SCAN_INJECT", &conf.feature_free_wifi_scan_inject, NULL, 's'},
537 {"SUPL_WIFI", &conf.feature_supl_wifi, NULL, 's'},
538 {"WIFI_SUPPLICANT_INFO", &conf.feature_wifi_supplicant_info, NULL, 's'},
539};
540
541/* location process conf, e.g.: izat.conf Parameter spec table */
542static const loc_param_s_type loc_process_conf_parameter_table[] = {
543 {"PROCESS_NAME", &conf.proc_name, NULL, 's'},
544 {"PROCESS_ARGUMENT", &conf.proc_argument, NULL, 's'},
545 {"PROCESS_STATE", &conf.proc_status, NULL, 's'},
546 {"PROCESS_GROUPS", &conf.group_list, NULL, 's'},
547 {"PREMIUM_FEATURE", &conf.premium_feature, NULL, 'n'},
548 {"IZAT_FEATURE_MASK", &conf.loc_feature_mask, NULL, 'n'},
549 {"PLATFORMS", &conf.platform_list, NULL, 's'},
550 {"SOC_IDS", &conf.soc_id_list, NULL, 's'},
551 {"BASEBAND", &conf.baseband, NULL, 's'},
552 {"LOW_RAM_TARGETS", &conf.low_ram_targets, NULL, 's'},
553 {"HARDWARE_TYPE", &conf.auto_platform, NULL, 's'},
554 {"VENDOR_ENHANCED_PROCESS", &conf.vendor_enhanced_process, NULL, 'n'},
555};
556
557/*===========================================================================
558FUNCTION loc_read_process_conf
559
560DESCRIPTION
561 Parse the specified conf file and return info for the processes defined.
562 The format of the file should conform with izat.conf.
563
564PARAMETERS:
565 conf_file_name: configuration file to read
566 process_count_ptr: pointer to store number of processes defined in the conf file.
567 process_info_table_ptr: pointer to store the process info table.
568
569DEPENDENCIES
570 The file must be in izat.conf format.
571
572RETURN VALUE
573 0: success
574 none-zero: failure
575
576SIDE EFFECTS
577 N/A
578
579NOTES:
580 On success, memory pointed by (*process_info_table_ptr) must be freed.
581===========================================================================*/
582int loc_read_process_conf(const char* conf_file_name, uint32_t * process_count_ptr,
583 loc_process_info_s_type** process_info_table_ptr) {
584 loc_process_info_s_type *child_proc = nullptr;
585 volatile int i=0;
586 unsigned int j=0;
587 gid_t gid_list[LOC_PROCESS_MAX_NUM_GROUPS];
588 char *split_strings[MAX_NUM_STRINGS];
589 int name_length=0, group_list_length=0, platform_length=0, baseband_length=0, ngroups=0, ret=0;
590 int auto_platform_length = 0, soc_id_list_length=0;
591 int group_index=0, nstrings=0, status_length=0;
592 FILE* conf_fp = nullptr;
593 char platform_name[PROPERTY_VALUE_MAX], baseband_name[PROPERTY_VALUE_MAX];
594 int low_ram_target=0;
595 char autoplatform_name[PROPERTY_VALUE_MAX], socid_value[PROPERTY_VALUE_MAX];
596 unsigned int loc_service_mask=0;
597 unsigned char config_mask = 0;
598 unsigned char proc_list_length=0;
599 int gtp_cell_ap_enabled = 0;
600 char arg_gtp_waa[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--";
601 char arg_gtp_modem_cell[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--";
602 char arg_gtp_wifi[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--";
603 char arg_sap[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--";
604 char arg_disabled[LOC_PROCESS_MAX_ARG_STR_LENGTH] = LOC_FEATURE_MODE_DISABLED;
605 char arg_basic[LOC_PROCESS_MAX_ARG_STR_LENGTH] = LOC_FEATURE_MODE_BASIC;
606 char arg_premium[LOC_PROCESS_MAX_ARG_STR_LENGTH] = LOC_FEATURE_MODE_PREMIUM;
607
608 if (process_count_ptr == NULL || process_info_table_ptr == NULL) {
609 return -1;
610 }
611
612 //Read gps.conf and fill parameter table
613 UTIL_READ_CONF(LOC_PATH_GPS_CONF, gps_conf_parameter_table);
614
615 //Form argument strings
616 strlcat(arg_gtp_waa, LOC_FEATURE_GTP_WAA, LOC_PROCESS_MAX_ARG_STR_LENGTH-3);
617 strlcat(arg_gtp_modem_cell, LOC_FEATURE_GTP_MODEM_CELL, LOC_PROCESS_MAX_ARG_STR_LENGTH-3);
618 strlcat(arg_gtp_wifi, LOC_FEATURE_GTP_WIFI, LOC_PROCESS_MAX_ARG_STR_LENGTH-3);
619 strlcat(arg_sap, LOC_FEATURE_SAP, LOC_PROCESS_MAX_ARG_STR_LENGTH-3);
620
621 //Get platform name from ro.board.platform property
622 loc_get_platform_name(platform_name, sizeof(platform_name));
623 //Get baseband name from ro.baseband property
624 loc_get_target_baseband(baseband_name, sizeof(baseband_name));
625 //Identify if this is an automotive platform
626 loc_get_auto_platform_name(autoplatform_name,sizeof(autoplatform_name));
627 //Identify if this is a low ram target from ro.config.low_ram property
628 low_ram_target = loc_identify_low_ram_target();
629 // Get the soc-id for this device.
630 loc_get_device_soc_id(socid_value, sizeof(socid_value));
631
632 UTIL_READ_CONF(conf_file_name, loc_feature_conf_table);
633
634 //Set service mask for GTP_MODE
635 if (strcmp(conf.feature_gtp_mode, "DISABLED") == 0) {
636 LOC_LOGD("%s:%d]: GTP MODE DISABLED", __func__, __LINE__);
637 }
638 else if (strcmp(conf.feature_gtp_mode, "LEGACY_WWAN") == 0) {
639 LOC_LOGD("%s:%d]: Setting GTP MODE to mode: LEGACY_WWAN", __func__, __LINE__);
640 loc_service_mask |= LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC;
641 }
642 else if (strcmp(conf.feature_gtp_mode, "SDK") == 0) {
643 LOC_LOGD("%s:%d]: Setting GTP MODE to mode: SDK", __func__, __LINE__);
644 loc_service_mask |= LOC_FEATURE_MASK_GTP_WIFI_BASIC;
645 }
646 else if (strcmp(conf.feature_gtp_mode, "SDK_WIFI") == 0) {
647 LOC_LOGD("%s:%d]: Setting GTP MODE to mode: SDK", __func__, __LINE__);
648 loc_service_mask |= LOC_FEATURE_MASK_GTP_WIFI_BASIC;
649 }
650 //conf file has a garbage value
651 else {
652 LOC_LOGE("%s:%d]: Unrecognized value for GTP MODE Mode."\
653 " Setting GTP WIFI to default mode: DISABLED", __func__, __LINE__);
654 }
655 //Set service mask for GTP_WAA
656 if (strcmp(conf.feature_gtp_waa, "BASIC") == 0) {
657 LOC_LOGD("%s:%d]: Setting GTP WAA to mode: BASIC", __func__, __LINE__);
658 loc_service_mask |= LOC_FEATURE_MASK_GTP_WAA_BASIC;
659 }
660 else if (strcmp(conf.feature_gtp_waa, "DISABLED") == 0) {
661 LOC_LOGD("%s:%d]: GTP WAA DISABLED", __func__, __LINE__);
662 }
663 //conf file has a garbage value
664 else {
665 LOC_LOGE("%s:%d]: Unrecognized value for GTP WAA Mode."\
666 " Setting GTP WAA to default mode: DISABLED", __func__, __LINE__);
667 }
668
669 //Set service mask for SAP
670 if(strcmp(conf.feature_sap, "PREMIUM") == 0 ||
671 strcmp(conf.feature_sap, "PREMIUM_ENV_AIDING") == 0) {
672 LOC_LOGD("%s:%d]: Setting SAP to mode: PREMIUM", __func__, __LINE__);
673 loc_service_mask |= LOC_FEATURE_MASK_SAP_PREMIUM;
674 }
675 else if (strcmp(conf.feature_sap, "BASIC") == 0) {
676 LOC_LOGD("%s:%d]: Setting SAP to mode: BASIC", __func__, __LINE__);
677 loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC;
678 }
679 else if (strcmp(conf.feature_sap, "MODEM_DEFAULT") == 0) {
680 LOC_LOGD("%s:%d]: Setting SAP to mode: MODEM_DEFAULT", __func__, __LINE__);
681 loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC;
682 }
683 else if (strcmp(conf.feature_sap, "DISABLED") == 0) {
684#ifdef USE_GLIB
685 /* Enable slim_daemon even when SAP is set to DISABLED*/
686 loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC;
687#else
688 LOC_LOGD("%s:%d]: Setting SAP to mode: DISABLED", __func__, __LINE__);
689#endif
690 }
691 else {
692 LOC_LOGE("%s:%d]: Unrecognized value for SAP Mode."\
693 " Setting SAP to default mode: BASIC", __func__, __LINE__);
694 loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC;
695 }
696
697 // Set service mask for ODCPI
698 if (strcmp(conf.feature_odcpi, "BASIC") == 0) {
699 LOC_LOGD("%s:%d]: Setting ODCPI to mode: BASIC", __func__, __LINE__);
700 loc_service_mask |= LOC_FEATURE_MASK_ODCPI;
701 }
702 else if (strcmp(conf.feature_odcpi, "DISABLED") == 0) {
703 LOC_LOGD("%s:%d]: Setting ODCPI to mode: DISABLED", __func__, __LINE__);
704 }
705 else if (strcmp(conf.feature_odcpi, "PREMIUM") == 0) {
706 LOC_LOGD("%s:%d]: Unrecognized value for ODCPI mode."\
707 "Setting ODCPI to default mode: BASIC", __func__, __LINE__);
708 loc_service_mask |= LOC_FEATURE_MASK_ODCPI;
709 }
710
711 // Set service mask for FREE_WIFI_SCAN_INJECT
712 if (strcmp(conf.feature_free_wifi_scan_inject, "BASIC") == 0) {
713 LOC_LOGD("%s:%d]: Setting FREE_WIFI_SCAN_INJECT to mode: BASIC", __func__, __LINE__);
714 loc_service_mask |= LOC_FEATURE_MASK_FREE_WIFI_SCAN_INJECT;
715 }
716 else if (strcmp(conf.feature_free_wifi_scan_inject, "DISABLED") == 0) {
717 LOC_LOGD("%s:%d]: Setting FREE_WIFI_SCAN_INJECT to mode: DISABLED", __func__, __LINE__);
718 }
719 else if (strcmp(conf.feature_free_wifi_scan_inject, "PREMIUM") == 0) {
720 LOC_LOGD("%s:%d]: Unrecognized value for FREE_WIFI_SCAN_INJECT mode."\
721 "Setting FREE_WIFI_SCAN_INJECT to default mode: BASIC", __func__, __LINE__);
722 loc_service_mask |= LOC_FEATURE_MASK_FREE_WIFI_SCAN_INJECT;
723 }
724
725 // Set service mask for SUPL_WIFI
726 if (strcmp(conf.feature_supl_wifi, "BASIC") == 0) {
727 LOC_LOGD("%s:%d]: Setting SUPL_WIFI to mode: BASIC", __func__, __LINE__);
728 loc_service_mask |= LOC_FEATURE_MASK_SUPL_WIFI;
729 }
730 else if (strcmp(conf.feature_supl_wifi, "DISABLED") == 0) {
731 LOC_LOGD("%s:%d]: Setting SUPL_WIFI to mode: DISABLED", __func__, __LINE__);
732 }
733 else if (strcmp(conf.feature_supl_wifi, "PREMIUM") == 0) {
734 LOC_LOGD("%s:%d]: Unrecognized value for SUPL_WIFI mode."\
735 "Setting SUPL_WIFI to default mode: BASIC", __func__, __LINE__);
736 loc_service_mask |= LOC_FEATURE_MASK_SUPL_WIFI;
737 }
738
739 // Set service mask for WIFI_SUPPLICANT_INFO
740 if (strcmp(conf.feature_wifi_supplicant_info, "BASIC") == 0) {
741 LOC_LOGD("%s:%d]: Setting WIFI_SUPPLICANT_INFO to mode: BASIC", __func__, __LINE__);
742 loc_service_mask |= LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO;
743 }
744 else if (strcmp(conf.feature_wifi_supplicant_info, "DISABLED") == 0) {
745 LOC_LOGD("%s:%d]: Setting WIFI_SUPPLICANT_INFO to mode: DISABLED", __func__, __LINE__);
746 }
747 else if (strcmp(conf.feature_wifi_supplicant_info, "PREMIUM") == 0) {
748 LOC_LOGD("%s:%d]: Unrecognized value for WIFI_SUPPLICANT_INFO mode."\
749 "Setting LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO to default mode: BASIC", __func__, __LINE__);
750 loc_service_mask |= LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO;
751 }
752
753 LOC_LOGD("%s:%d]: loc_service_mask: %x\n", __func__, __LINE__, loc_service_mask);
754
755 if((conf_fp = fopen(conf_file_name, "r")) == NULL) {
756 LOC_LOGE("%s:%d]: Error opening %s %s\n", __func__,
757 __LINE__, conf_file_name, strerror(errno));
758 ret = -1;
759 goto err;
760 }
761
762 //Parse through the file to find out how many processes are to be launched
763 proc_list_length = 0;
764 do {
765 conf.proc_name[0] = 0;
766 //Here note that the 3rd parameter is passed as 1.
767 //This is so that only the first parameter in the table which is "PROCESS_NAME"
768 //is read. We do not want to read the entire block of parameters at this time
769 //since we are only counting the number of processes to launch.
770 //Therefore, only counting the occurrences of PROCESS_NAME parameter
771 //should suffice
772 if(loc_read_conf_r(conf_fp, loc_process_conf_parameter_table, 1)) {
773 LOC_LOGE("%s:%d]: Unable to read conf file. Failing\n", __func__, __LINE__);
774 ret = -1;
775 goto err;
776 }
777 name_length=(int)strlen(conf.proc_name);
778 if(name_length) {
779 proc_list_length++;
780 LOC_LOGD("Process name:%s", conf.proc_name);
781 }
782 } while(name_length);
783 LOC_LOGD("Process cnt = %d", proc_list_length);
784
785 child_proc = (loc_process_info_s_type *)calloc(proc_list_length, sizeof(loc_process_info_s_type));
786 if(child_proc == NULL) {
787 LOC_LOGE("%s:%d]: ERROR: Malloc returned NULL\n", __func__, __LINE__);
788 ret = -1;
789 goto err;
790 }
791
792 //Move file descriptor to the beginning of the file
793 //so that the parameters can be read
794 rewind(conf_fp);
795
796 for(j=0; j<proc_list_length; j++) {
797 //Set defaults for all the child process structs
798 child_proc[j].proc_status = DISABLED;
799 memset(child_proc[j].group_list, 0, sizeof(child_proc[j].group_list));
800 config_mask=0;
801 if(loc_read_conf_r(conf_fp, loc_process_conf_parameter_table,
802 sizeof(loc_process_conf_parameter_table)/sizeof(loc_process_conf_parameter_table[0]))) {
803 LOC_LOGE("%s:%d]: Unable to read conf file. Failing\n", __func__, __LINE__);
804 ret = -1;
805 goto err;
806 }
807
808 name_length=(int)strlen(conf.proc_name);
809 group_list_length=(int)strlen(conf.group_list);
810 platform_length = (int)strlen(conf.platform_list);
811 baseband_length = (int)strlen(conf.baseband);
812 status_length = (int)strlen(conf.proc_status);
813 auto_platform_length = (int)strlen(conf.auto_platform);
814 soc_id_list_length = (int)strlen(conf.soc_id_list);
815
816 if(!name_length || !group_list_length || !platform_length ||
817 !baseband_length || !status_length || !auto_platform_length || !soc_id_list_length) {
818 LOC_LOGE("%s:%d]: Error: i: %d; One of the parameters not specified in conf file",
819 __func__, __LINE__, i);
820 continue;
821 }
822
Michael Bestas05ca34d2023-05-05 20:09:13 +0300823 if (strcmp(conf.proc_name, "xtra-daemon") == 0 && !isXtraDaemonEnabled()) {
824 LOC_LOGE("%s:%d]: Process xtra-daemon is disabled via property",
825 __func__, __LINE__);
826 child_proc[j].proc_status = DISABLED_FROM_CONF;
827 continue;
828 }
829
Michael Bestas3a0209e2023-05-04 01:15:47 +0300830 if (!isVendorEnhanced() && (conf.vendor_enhanced_process != 0)) {
831 LOC_LOGD("%s:%d]: Process %s is disabled via vendor enhanced process check",
832 __func__, __LINE__, conf.proc_name);
833 child_proc[j].proc_status = DISABLED_VIA_VENDOR_ENHANCED_CHECK;
834 continue;
835 }
836
837 if (strcmp(conf.proc_status, "DISABLED") == 0) {
838 LOC_LOGD("%s:%d]: Process %s is disabled in conf file",
839 __func__, __LINE__, conf.proc_name);
840 child_proc[j].proc_status = DISABLED_FROM_CONF;
841 continue;
842 }
843 else if (strcmp(conf.proc_status, "ENABLED") == 0) {
844 LOC_LOGD("%s:%d]: Process %s is enabled in conf file",
845 __func__, __LINE__, conf.proc_name);
846 }
847
848 //Since strlcpy copies length-1 characters, we add 1 to name_length
849 if((name_length+1) > LOC_MAX_PARAM_STRING) {
850 LOC_LOGE("%s:%d]: i: %d; Length of name parameter too long. Max length: %d",
851 __func__, __LINE__, i, LOC_MAX_PARAM_STRING);
852 continue;
853 }
854 strlcpy(child_proc[j].name[0], conf.proc_name, sizeof (child_proc[j].name[0]));
855
856 child_proc[j].num_groups = 0;
857 ngroups = loc_util_split_string(conf.group_list, split_strings, MAX_NUM_STRINGS, ' ');
858 for(i=0; i<ngroups; i++) {
859 struct group* grp = getgrnam(split_strings[i]);
860 if (grp) {
861 child_proc[j].group_list[child_proc[j].num_groups] = grp->gr_gid;
862 child_proc[j].num_groups++;
863 LOC_LOGd("Group %s = %d", split_strings[i], grp->gr_gid);
864 }
865 }
866
867 nstrings = loc_util_split_string(conf.platform_list, split_strings, MAX_NUM_STRINGS, ' ');
868 if (strcmp("all", split_strings[0]) == 0) {
869 if (nstrings == 1 || (nstrings == 2 && (strcmp("exclude", split_strings[1]) == 0))) {
870 LOC_LOGD("%s:%d]: Enabled for all targets\n", __func__, __LINE__);
871 config_mask |= CONFIG_MASK_TARGET_ALL;
872 }
873 else if (nstrings > 2 && (strcmp("exclude", split_strings[1]) == 0)) {
874 config_mask |= CONFIG_MASK_TARGET_FOUND;
875 for (i=2; i<nstrings; i++) {
876 if (strcmp(platform_name, split_strings[i]) == 0) {
877 LOC_LOGD("%s:%d]: Disabled platform %s\n", __func__, __LINE__, platform_name);
878 config_mask &= ~CONFIG_MASK_TARGET_FOUND;
879 break;
880 }
881 }
882 }
883 }
884 else {
885 for(i=0; i<nstrings; i++) {
886 if (strcmp(platform_name, split_strings[i]) == 0) {
887 LOC_LOGD("%s:%d]: Matched platform: %s\n",
888 __func__, __LINE__, split_strings[i]);
889 config_mask |= CONFIG_MASK_TARGET_FOUND;
890 break;
891 }
892 }
893 }
894
895 // SOC Id's check
896 nstrings = loc_util_split_string(conf.soc_id_list, split_strings, MAX_NUM_STRINGS, ' ');
897 if (strcmp("all", split_strings[0]) == 0) {
898 if (nstrings == 1 || (nstrings == 2 && (strcmp("exclude", split_strings[1]) == 0))) {
899 LOC_LOGd("Enabled for all SOC ids\n");
900 config_mask |= CONFIG_MASK_SOCID_ALL;
901 }
902 else if (nstrings > 2 && (strcmp("exclude", split_strings[1]) == 0)) {
903 config_mask |= CONFIG_MASK_SOCID_FOUND;
904 for (i = 2; i < nstrings; i++) {
905 if (strcmp(socid_value, split_strings[i]) == 0) {
906 LOC_LOGd("Disabled for SOC id %s\n", socid_value);
907 config_mask &= ~CONFIG_MASK_SOCID_FOUND;
908 break;
909 }
910 }
911 }
912 }
913 else {
914 for (i = 0; i < nstrings; i++) {
915 if (strcmp(socid_value, split_strings[i]) == 0) {
916 LOC_LOGd("Matched SOC id : %s\n", split_strings[i]);
917 config_mask |= CONFIG_MASK_SOCID_FOUND;
918 break;
919 }
920 }
921 }
922
923 nstrings = loc_util_split_string(conf.baseband, split_strings, MAX_NUM_STRINGS, ' ');
924 if (strcmp("all", split_strings[0]) == 0) {
925 if (nstrings == 1 || (nstrings == 2 && (strcmp("exclude", split_strings[1]) == 0))) {
926 LOC_LOGD("%s:%d]: Enabled for all basebands\n", __func__, __LINE__);
927 config_mask |= CONFIG_MASK_BASEBAND_ALL;
928 }
929 else if (nstrings > 2 && (strcmp("exclude", split_strings[1]) == 0)) {
930 config_mask |= CONFIG_MASK_BASEBAND_FOUND;
931 for (i=2; i<nstrings; i++) {
932 if (strcmp(baseband_name, split_strings[i]) == 0) {
933 LOC_LOGD("%s:%d]: Disabled band %s\n", __func__, __LINE__, baseband_name);
934 config_mask &= ~CONFIG_MASK_BASEBAND_FOUND;
935 break;
936 }
937 }
938 }
939 }
940 else {
941 for(i=0; i<nstrings; i++) {
942 if (strcmp(baseband_name, split_strings[i]) == 0) {
943 LOC_LOGD("%s:%d]: Matched baseband: %s\n",
944 __func__, __LINE__, split_strings[i]);
945 config_mask |= CONFIG_MASK_BASEBAND_FOUND;
946 break;
947 }
948 //Since ro.baseband is not a reliable source for detecting sglte
949 //the alternative is to read the SGLTE_TARGET parameter from gps.conf
950 //this parameter is read into conf_sglte_target
951 else if((strcmp("sglte", split_strings[i]) == 0 ) && conf.sglte_target) {
952 LOC_LOGD("%s:%d]: Matched baseband SGLTE\n", __func__, __LINE__);
953 config_mask |= CONFIG_MASK_BASEBAND_FOUND;
954 break;
955 }
956 }
957 }
958
959 nstrings = loc_util_split_string(conf.auto_platform, split_strings, MAX_NUM_STRINGS, ' ');
960 if (strcmp("all", split_strings[0]) == 0) {
961 LOC_LOGD("%s:%d]: Enabled for all auto platforms\n", __func__, __LINE__);
962 config_mask |= CONFIG_MASK_AUTOPLATFORM_ALL;
963 }
964 else {
965 for(i=0; i<nstrings; i++) {
966 if (strcmp(autoplatform_name, split_strings[i]) == 0) {
967 LOC_LOGD("%s:%d]: Matched auto platform: %s\n",
968 __func__, __LINE__, split_strings[i]);
969 config_mask |= CONFIG_MASK_AUTOPLATFORM_FOUND;
970 break;
971 }
972 }
973 }
974
975 nstrings = loc_util_split_string(conf.low_ram_targets, split_strings, MAX_NUM_STRINGS, ' ');
976 if (!strcmp("DISABLED", split_strings[0]) && low_ram_target) {
977 LOC_LOGd("Disabled for low ram targets\n");
978 child_proc[j].proc_status = DISABLED;
979 continue;
980 }
981
982 if((config_mask & CONFIG_MASK_TARGET_CHECK) &&
983 (config_mask & CONFIG_MASK_BASEBAND_CHECK) &&
984 (config_mask & CONFIG_MASK_AUTOPLATFORM_CHECK) &&
985 (config_mask & CONFIG_MASK_SOCID_CHECK) &&
986 (child_proc[j].proc_status != DISABLED_FROM_CONF) &&
987 (child_proc[j].proc_status != DISABLED_VIA_VENDOR_ENHANCED_CHECK)) {
988
989 //Set args
990 //The first argument passed through argv is usually the name of the
991 //binary when started from commandline.
992 //getopt() seems to ignore this first argument and hence we assign it
993 //to the process name for consistency with command line args
994 i = 0;
995 char* temp_arg = ('/' == child_proc[j].name[0][0]) ?
996 (strrchr(child_proc[j].name[0], '/') + 1) : child_proc[j].name[0];
997 strlcpy (child_proc[j].args[i++], temp_arg, sizeof (child_proc[j].args[0]));
998
999 if(conf.premium_feature) {
1000 if(conf.loc_feature_mask & loc_service_mask) {
1001 LOC_LOGD("%s:%d]: Enabled. %s has service mask: %x\n",
1002 __func__, __LINE__, child_proc[j].name[0], conf.loc_feature_mask);
1003 child_proc[j].proc_status = ENABLED;
1004
1005 if(conf.loc_feature_mask &
1006 (LOC_FEATURE_MASK_GTP_WIFI_BASIC | LOC_FEATURE_MASK_GTP_WIFI_PREMIUM)) {
1007 if(loc_service_mask & LOC_FEATURE_MASK_GTP_WIFI_BASIC) {
1008 strlcpy(child_proc[j].args[i++], arg_gtp_wifi,
1009 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1010 strlcpy(child_proc[j].args[i++], arg_basic,
1011 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1012 }
1013 else if(loc_service_mask & LOC_FEATURE_MASK_GTP_WIFI_PREMIUM) {
1014 strlcpy(child_proc[j].args[i++], arg_gtp_wifi,
1015 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1016 strlcpy(child_proc[j].args[i++], arg_premium,
1017 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1018 }
1019 else
1020 {
1021 strlcpy(child_proc[j].args[i++], arg_gtp_wifi,
1022 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1023 strlcpy(child_proc[j].args[i++], arg_disabled,
1024 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1025 }
1026 }
1027 if(conf.loc_feature_mask &
1028 (LOC_FEATURE_MASK_GTP_CELL_BASIC | LOC_FEATURE_MASK_GTP_CELL_PREMIUM )) {
1029 if(loc_service_mask & LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC) {
1030 strlcpy(child_proc[j].args[i++], arg_gtp_modem_cell,
1031 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1032 strlcpy(child_proc[j].args[i++], arg_basic,
1033 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1034 }
1035 else {
1036 strlcpy(child_proc[j].args[i++], arg_gtp_modem_cell,
1037 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1038 strlcpy(child_proc[j].args[i++], arg_disabled,
1039 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1040 }
1041 }
1042 if(conf.loc_feature_mask &
1043 (LOC_FEATURE_MASK_SAP_BASIC | LOC_FEATURE_MASK_SAP_PREMIUM)) {
1044 if(loc_service_mask & LOC_FEATURE_MASK_SAP_BASIC) {
1045 strlcpy(child_proc[j].args[i++], arg_sap,
1046 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1047 strlcpy(child_proc[j].args[i++], arg_basic,
1048 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1049 }
1050 else if(loc_service_mask & LOC_FEATURE_MASK_SAP_PREMIUM) {
1051 strlcpy(child_proc[j].args[i++], arg_sap,
1052 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1053 strlcpy(child_proc[j].args[i++], arg_premium,
1054 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1055 }
1056 else
1057 {
1058 strlcpy(child_proc[j].args[i++], arg_sap,
1059 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1060 strlcpy(child_proc[j].args[i++], arg_disabled,
1061 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1062 }
1063 }
1064
1065 if(conf.loc_feature_mask & LOC_FEATURE_MASK_GTP_WAA_BASIC) {
1066 if(loc_service_mask & LOC_FEATURE_MASK_GTP_WAA_BASIC) {
1067 strlcpy(child_proc[j].args[i++], arg_gtp_waa,
1068 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1069 strlcpy(child_proc[j].args[i++], arg_basic,
1070 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1071 }
1072 else
1073 {
1074 strlcpy(child_proc[j].args[i++], arg_gtp_waa,
1075 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1076 strlcpy(child_proc[j].args[i++], arg_disabled,
1077 LOC_PROCESS_MAX_ARG_STR_LENGTH);
1078 }
1079 }
1080 IF_LOC_LOGD {
1081 LOC_LOGD("%s:%d]: %s args\n", __func__, __LINE__, child_proc[j].name[0]);
1082 for(unsigned int k=0; k<LOC_PROCESS_MAX_NUM_ARGS; k++) {
1083 if(child_proc[j].args[k][0] != '\0') {
1084 LOC_LOGD("%s:%d]: k: %d, %s\n", __func__, __LINE__, k,
1085 child_proc[j].args[k]);
1086 }
1087 }
1088 LOC_LOGD("%s:%d]: \n", __func__, __LINE__);
1089 }
1090 }
1091 else {
1092 LOC_LOGD("%s:%d]: Disabled. %s has service mask: %x \n",
1093 __func__, __LINE__, child_proc[j].name[0], conf.loc_feature_mask);
1094 }
1095 }
1096 else {
1097 LOC_LOGD("%s:%d]: %s not a premium feature. Enabled\n",
1098 __func__, __LINE__, child_proc[j].name[0]);
1099 child_proc[j].proc_status = ENABLED;
1100 }
1101
1102 /*Fill up the remaining arguments from configuration file*/
1103 LOC_LOGD("%s] Parsing Process_Arguments from Configuration: %s \n",
1104 __func__, conf.proc_argument);
1105 if(0 != conf.proc_argument[0])
1106 {
1107 /**************************************
1108 ** conf_proc_argument is shared by all the programs getting launched,
1109 ** hence copy to process specific argument string and parse the same.
1110 ***************************************/
1111 strlcpy(child_proc[j].argumentString, conf.proc_argument,
1112 sizeof(child_proc[j].argumentString));
1113 char *temp_args[LOC_PROCESS_MAX_NUM_ARGS];
1114 memset (temp_args, 0, sizeof (temp_args));
1115 loc_util_split_string(child_proc[j].argumentString, &temp_args[i],
1116 (LOC_PROCESS_MAX_NUM_ARGS - i), ' ');
1117 // copy argument from the pointer to the memory
1118 for (unsigned int index = i; index < LOC_PROCESS_MAX_NUM_ARGS; index++) {
1119 if (temp_args[index] == NULL) {
1120 break;
1121 }
1122 strlcpy (child_proc[j].args[index], temp_args[index],
1123 sizeof (child_proc[j].args[index]));
1124 }
1125 }
1126 }
1127 else {
1128 LOC_LOGD("%s:%d]: Process %s is disabled\n",
1129 __func__, __LINE__, child_proc[j].name[0]);
1130 }
1131 }
1132
1133err:
1134 if (conf_fp) {
1135 fclose(conf_fp);
1136 }
1137 if (ret != 0) {
1138 LOC_LOGE("%s:%d]: ret: %d", __func__, __LINE__, ret);
1139 if (child_proc) {
1140 free (child_proc);
1141 child_proc = nullptr;
1142 }
1143 *process_count_ptr = 0;
1144 *process_info_table_ptr = nullptr;
1145
1146 }
1147 else {
1148 *process_count_ptr = proc_list_length;
1149 *process_info_table_ptr = child_proc;
1150 }
1151
1152 return ret;
1153}