summaryrefslogtreecommitdiff
path: root/utils/loc_cfg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/loc_cfg.cpp')
-rw-r--r--utils/loc_cfg.cpp745
1 files changed, 742 insertions, 3 deletions
diff --git a/utils/loc_cfg.cpp b/utils/loc_cfg.cpp
index 8b495b9..8037979 100644
--- a/utils/loc_cfg.cpp
+++ b/utils/loc_cfg.cpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2015, 2018 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -37,13 +37,16 @@
#include <ctype.h>
#include <unistd.h>
#include <time.h>
+#include <pwd.h>
+#include <errno.h>
#include <loc_cfg.h>
-#include <platform_lib_includes.h>
+#include <loc_pla.h>
+#include <loc_target.h>
#include <loc_misc_utils.h>
#ifdef USE_GLIB
#include <glib.h>
#endif
-#include "platform_lib_includes.h"
+#include "log_util.h"
/*=============================================================================
*
@@ -71,6 +74,17 @@ typedef struct loc_param_v_type
double param_double_value;
}loc_param_v_type;
+// Reference below arrays wherever needed to avoid duplicating
+// same conf path string over and again in location code.
+const char LOC_PATH_GPS_CONF[] = LOC_PATH_GPS_CONF_STR;
+const char LOC_PATH_IZAT_CONF[] = LOC_PATH_IZAT_CONF_STR;
+const char LOC_PATH_FLP_CONF[] = LOC_PATH_FLP_CONF_STR;
+const char LOC_PATH_LOWI_CONF[] = LOC_PATH_LOWI_CONF_STR;
+const char LOC_PATH_SAP_CONF[] = LOC_PATH_SAP_CONF_STR;
+const char LOC_PATH_APDR_CONF[] = LOC_PATH_APDR_CONF_STR;
+const char LOC_PATH_XTWIFI_CONF[] = LOC_PATH_XTWIFI_CONF_STR;
+const char LOC_PATH_QUIPC_CONF[] = LOC_PATH_QUIPC_CONF_STR;
+
/*===========================================================================
FUNCTION loc_set_config_entry
@@ -395,3 +409,728 @@ void loc_read_conf(const char* conf_file_name, const loc_param_s_type* config_ta
/* Initialize logging mechanism with parsed data */
loc_logger_init(DEBUG_LEVEL, TIMESTAMP);
}
+
+/*=============================================================================
+ *
+ * Define and Structures for Parsing Location Process Configuration File
+ *
+ *============================================================================*/
+#define MAX_NUM_STRINGS 20
+
+//We can have 8 masks for now
+#define CONFIG_MASK_TARGET_ALL 0X01
+#define CONFIG_MASK_TARGET_FOUND 0X02
+#define CONFIG_MASK_TARGET_CHECK 0X03
+#define CONFIG_MASK_BASEBAND_ALL 0X04
+#define CONFIG_MASK_BASEBAND_FOUND 0X08
+#define CONFIG_MASK_BASEBAND_CHECK 0x0c
+#define CONFIG_MASK_AUTOPLATFORM_ALL 0x10
+#define CONFIG_MASK_AUTOPLATFORM_FOUND 0x20
+#define CONFIG_MASK_AUTOPLATFORM_CHECK 0x30
+
+#define LOC_FEATURE_MASK_GTP_WIFI_BASIC 0x01
+#define LOC_FEATURE_MASK_GTP_WIFI_PREMIUM 0X02
+#define LOC_FEATURE_MASK_GTP_CELL_BASIC 0X04
+#define LOC_FEATURE_MASK_GTP_CELL_PREMIUM 0X08
+#define LOC_FEATURE_MASK_GTP_AP_CELL_BASIC LOC_FEATURE_MASK_GTP_CELL_BASIC
+#define LOC_FEATURE_MASK_GTP_AP_CELL_PREMIUM LOC_FEATURE_MASK_GTP_CELL_PREMIUM
+#define LOC_FEATURE_MASK_SAP_BASIC 0x40
+#define LOC_FEATURE_MASK_SAP_PREMIUM 0X80
+#define LOC_FEATURE_MASK_GTP_WAA_BASIC 0X100
+#define LOC_FEATURE_MASK_GTP_WAA_PREMIUM 0x200
+#define LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC 0X400
+#define LOC_FEATURE_MASK_GTP_MODEM_CELL_PREMIUM 0X800
+#define LOC_FEATURE_MASK_ODCPI 0x1000
+#define LOC_FEATURE_MASK_FREE_WIFI_SCAN_INJECT 0x2000
+#define LOC_FEATURE_MASK_SUPL_WIFI 0x4000
+#define LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO 0x8000
+
+typedef struct {
+ char proc_name[LOC_MAX_PARAM_STRING];
+ char proc_argument[LOC_MAX_PARAM_STRING];
+ char proc_status[LOC_MAX_PARAM_STRING];
+ char group_list[LOC_MAX_PARAM_STRING];
+ unsigned int premium_feature;
+ unsigned int loc_feature_mask;
+ char platform_list[LOC_MAX_PARAM_STRING];
+ char baseband[LOC_MAX_PARAM_STRING];
+ char lean_targets[LOC_MAX_PARAM_STRING];
+ unsigned int sglte_target;
+ char feature_gtp_cell_proc[LOC_MAX_PARAM_STRING];
+ char feature_gtp_waa[LOC_MAX_PARAM_STRING];
+ char feature_gtp_cell[LOC_MAX_PARAM_STRING];
+ char feature_gtp_wifi[LOC_MAX_PARAM_STRING];
+ char feature_sap[LOC_MAX_PARAM_STRING];
+ char feature_odcpi[LOC_MAX_PARAM_STRING];
+ char feature_free_wifi_scan_inject[LOC_MAX_PARAM_STRING];
+ char feature_supl_wifi[LOC_MAX_PARAM_STRING];
+ char feature_wifi_supplicant_info[LOC_MAX_PARAM_STRING];
+ char auto_platform[LOC_MAX_PARAM_STRING];
+} loc_launcher_conf;
+
+/* process configuration parameters */
+static loc_launcher_conf conf;
+
+/* gps.conf Parameter spec table */
+static const loc_param_s_type gps_conf_parameter_table[] = {
+ {"SGLTE_TARGET", &conf.sglte_target, NULL, 'n'},
+};
+
+/* location feature conf, e.g.: izat.conf feature mode table*/
+static const loc_param_s_type loc_feature_conf_table[] = {
+ {"GTP_CELL_PROC", &conf.feature_gtp_cell_proc, NULL, 's'},
+ {"GTP_CELL", &conf.feature_gtp_cell, NULL, 's'},
+ {"GTP_WIFI", &conf.feature_gtp_wifi, NULL, 's'},
+ {"GTP_WAA", &conf.feature_gtp_waa, NULL, 's'},
+ {"SAP", &conf.feature_sap, NULL, 's'},
+ {"ODCPI", &conf.feature_odcpi, NULL, 's'},
+ {"FREE_WIFI_SCAN_INJECT", &conf.feature_free_wifi_scan_inject, NULL, 's'},
+ {"SUPL_WIFI", &conf.feature_supl_wifi, NULL, 's'},
+ {"WIFI_SUPPLICANT_INFO", &conf.feature_wifi_supplicant_info, NULL, 's'},
+};
+
+/* location process conf, e.g.: izat.conf Parameter spec table */
+static const loc_param_s_type loc_process_conf_parameter_table[] = {
+ {"PROCESS_NAME", &conf.proc_name, NULL, 's'},
+ {"PROCESS_ARGUMENT", &conf.proc_argument, NULL, 's'},
+ {"PROCESS_STATE", &conf.proc_status, NULL, 's'},
+ {"PROCESS_GROUPS", &conf.group_list, NULL, 's'},
+ {"PREMIUM_FEATURE", &conf.premium_feature, NULL, 'n'},
+ {"IZAT_FEATURE_MASK", &conf.loc_feature_mask, NULL, 'n'},
+ {"PLATFORMS", &conf.platform_list, NULL, 's'},
+ {"BASEBAND", &conf.baseband, NULL, 's'},
+ {"LEAN_TARGETS", &conf.lean_targets, NULL, 's'},
+ {"HARDWARE_TYPE", &conf.auto_platform, NULL, 's'},
+};
+
+/*===========================================================================
+FUNCTION loc_read_process_conf
+
+DESCRIPTION
+ Parse the specified conf file and return info for the processes defined.
+ The format of the file should conform with izat.conf.
+
+PARAMETERS:
+ conf_file_name: configuration file to read
+ process_count_ptr: pointer to store number of processes defined in the conf file.
+ process_info_table_ptr: pointer to store the process info table.
+
+DEPENDENCIES
+ The file must be in izat.conf format.
+
+RETURN VALUE
+ 0: success
+ none-zero: failure
+
+SIDE EFFECTS
+ N/A
+
+NOTES:
+ On success, memory pointed by (*process_info_table_ptr) must be freed.
+===========================================================================*/
+int loc_read_process_conf(const char* conf_file_name, uint32_t * process_count_ptr,
+ loc_process_info_s_type** process_info_table_ptr) {
+ loc_process_info_s_type *child_proc = nullptr;
+ volatile int i=0;
+ unsigned int j=0;
+ gid_t gid_list[LOC_PROCESS_MAX_NUM_GROUPS];
+ char *split_strings[MAX_NUM_STRINGS];
+ int name_length=0, group_list_length=0, platform_length=0, baseband_length=0, ngroups=0, ret=0;
+ int auto_platform_length = 0;
+ int group_index=0, nstrings=0, status_length=0;
+ FILE* conf_fp = nullptr;
+ char platform_name[PROPERTY_VALUE_MAX], baseband_name[PROPERTY_VALUE_MAX];
+ char autoplatform_name[PROPERTY_VALUE_MAX];
+ int lean_target=0;
+ unsigned int loc_service_mask=0;
+ char config_mask = 0;
+ unsigned char proc_list_length=0;
+ int gtp_cell_ap_enabled = 0;
+ char arg_gtp_waa[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--";
+ char arg_gtp_ap_cell[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--";
+ char arg_gtp_modem_cell[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--";
+ char arg_gtp_wifi[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--";
+ char arg_sap[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--";
+ char arg_disabled[LOC_PROCESS_MAX_ARG_STR_LENGTH] = LOC_FEATURE_MODE_DISABLED;
+ char arg_basic[LOC_PROCESS_MAX_ARG_STR_LENGTH] = LOC_FEATURE_MODE_BASIC;
+ char arg_premium[LOC_PROCESS_MAX_ARG_STR_LENGTH] = LOC_FEATURE_MODE_PREMIUM;
+
+ if (process_count_ptr == NULL || process_info_table_ptr == NULL) {
+ return -1;
+ }
+
+ //Read gps.conf and fill parameter table
+ UTIL_READ_CONF(LOC_PATH_GPS_CONF, gps_conf_parameter_table);
+
+ //Form argument strings
+ strlcat(arg_gtp_waa, LOC_FEATURE_GTP_WAA, LOC_PROCESS_MAX_ARG_STR_LENGTH-3);
+ strlcat(arg_gtp_ap_cell, LOC_FEATURE_GTP_AP_CELL, LOC_PROCESS_MAX_ARG_STR_LENGTH-3);
+ strlcat(arg_gtp_modem_cell, LOC_FEATURE_GTP_MODEM_CELL, LOC_PROCESS_MAX_ARG_STR_LENGTH-3);
+ strlcat(arg_gtp_wifi, LOC_FEATURE_GTP_WIFI, LOC_PROCESS_MAX_ARG_STR_LENGTH-3);
+ strlcat(arg_sap, LOC_FEATURE_SAP, LOC_PROCESS_MAX_ARG_STR_LENGTH-3);
+
+ //Get platform name from ro.board.platform property
+ loc_get_platform_name(platform_name, sizeof(platform_name));
+ //Get baseband name from ro.baseband property
+ loc_get_target_baseband(baseband_name, sizeof(baseband_name));
+ lean_target = loc_identify_lean_target();
+ LOC_LOGD("%s:%d]: lean target:%d", __func__, __LINE__, lean_target);
+ //Identify if this is an automotive platform
+ loc_get_auto_platform_name(autoplatform_name,sizeof(autoplatform_name));
+
+ UTIL_READ_CONF(conf_file_name, loc_feature_conf_table);
+
+ //Set service mask for GTP_WIFI
+ if(strcmp(conf.feature_gtp_wifi, "DISABLED") == 0) {
+ LOC_LOGD("%s:%d]: GTP WIFI DISABLED", __func__, __LINE__);
+ }
+ else if(strcmp(conf.feature_gtp_wifi, "BASIC") == 0) {
+ LOC_LOGD("%s:%d]: Setting GTP WIFI to mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_WIFI_BASIC;
+ }
+ //conf file has a garbage value
+ else {
+ LOC_LOGE("%s:%d]: Unrecognized value for GTP WIFI Mode."\
+ " Setting GTP WIFI to default mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_WIFI_BASIC;
+ }
+
+ //Set service mask for GTP_CELL
+ //Using a temp variable here to indicate wheter GTP cell is
+ //enabled on the AP or modem. This variable will be used in
+ //further checks below. An alternative was to compare the
+ //string again in each place which would've been more expensive
+ if(strcmp(conf.feature_gtp_cell_proc, "AP") == 0) {
+ gtp_cell_ap_enabled = 1;
+ }
+
+ if(strcmp(conf.feature_gtp_cell, "PREMIUM") == 0) {
+ LOC_LOGE("%s:%d]: Error: location feature GTP CELL does not support PREMIUM mode" \
+ " available modes are BASIC and DISABLED. Starting feature in BASIC mode",
+ __func__, __LINE__);
+ if(gtp_cell_ap_enabled) {
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_AP_CELL_BASIC;
+ }
+ else {
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC;
+ }
+ }
+ else if(strcmp(conf.feature_gtp_cell, "BASIC") == 0) {
+ LOC_LOGD("%s:%d]: Setting GTP CELL to mode: BASIC", __func__, __LINE__);
+ if(gtp_cell_ap_enabled) {
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_AP_CELL_BASIC;
+ }
+ else {
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC;
+ }
+ }
+ else if(strcmp(conf.feature_gtp_cell, "DISABLED") == 0) {
+ LOC_LOGD("%s:%d]: GTP CELL DISABLED", __func__, __LINE__);
+ }
+ //conf file has a garbage value
+ else {
+ LOC_LOGE("%s:%d]: Unrecognized value for GTP CELL Mode." \
+ " Setting GTP CELL to default mode: BASIC", __func__, __LINE__);
+ if(gtp_cell_ap_enabled) {
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_AP_CELL_BASIC;
+ }
+ else {
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC;
+ }
+ }
+
+ //Set service mask for GTP_WAA
+ if(strcmp(conf.feature_gtp_waa, "PREMIUM") == 0) {
+ LOC_LOGE("%s:%d]: Error: location feature GTP WAA does not support PREMIUM mode" \
+ " available modes are BASIC and DISABLED. Starting feature in BASIC mode",
+ __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_WAA_BASIC;
+ }
+ else if(strcmp(conf.feature_gtp_waa, "BASIC") == 0) {
+ LOC_LOGD("%s:%d]: Setting GTP WAA to mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_GTP_WAA_BASIC;
+ }
+ else if(strcmp(conf.feature_gtp_waa, "DISABLED") == 0) {
+ LOC_LOGD("%s:%d]: GTP WAA DISABLED", __func__, __LINE__);
+ }
+ //conf file has a garbage value
+ else {
+ LOC_LOGE("%s:%d]: Unrecognized value for GTP WAA Mode."\
+ " Setting GTP WAA to default mode: DISABLED", __func__, __LINE__);
+ }
+
+ //Set service mask for SAP
+ if(strcmp(conf.feature_sap, "PREMIUM") == 0) {
+ LOC_LOGD("%s:%d]: Setting SAP to mode: PREMIUM", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_SAP_PREMIUM;
+ }
+ else if(strcmp(conf.feature_sap, "BASIC") == 0) {
+ LOC_LOGD("%s:%d]: Setting SAP to mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC;
+ }
+ else if(strcmp(conf.feature_sap, "DISABLED") == 0) {
+ LOC_LOGD("%s:%d]: Setting SAP to mode: DISABLED", __func__, __LINE__);
+ }
+ else {
+ LOC_LOGE("%s:%d]: Unrecognized value for SAP Mode."\
+ " Setting SAP to default mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC;
+ }
+
+ // Set service mask for ODCPI
+ if(strcmp(conf.feature_odcpi, "BASIC") == 0) {
+ LOC_LOGD("%s:%d]: Setting ODCPI to mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_ODCPI;
+ }
+ else if(strcmp(conf.feature_odcpi, "DISABLED") == 0) {
+ LOC_LOGD("%s:%d]: Setting ODCPI to mode: DISABLED", __func__, __LINE__);
+ }
+ else if(strcmp(conf.feature_odcpi, "PREMIUM") == 0) {
+ LOC_LOGD("%s:%d]: Unrecognized value for ODCPI mode."\
+ "Setting ODCPI to default mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_ODCPI;
+ }
+
+ // Set service mask for FREE_WIFI_SCAN_INJECT
+ if(strcmp(conf.feature_free_wifi_scan_inject, "BASIC") == 0) {
+ LOC_LOGD("%s:%d]: Setting FREE_WIFI_SCAN_INJECT to mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_FREE_WIFI_SCAN_INJECT;
+ }
+ else if(strcmp(conf.feature_free_wifi_scan_inject, "DISABLED") == 0) {
+ LOC_LOGD("%s:%d]: Setting FREE_WIFI_SCAN_INJECT to mode: DISABLED", __func__, __LINE__);
+ }
+ else if(strcmp(conf.feature_free_wifi_scan_inject, "PREMIUM") == 0) {
+ LOC_LOGD("%s:%d]: Unrecognized value for FREE_WIFI_SCAN_INJECT mode."\
+ "Setting FREE_WIFI_SCAN_INJECT to default mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_FREE_WIFI_SCAN_INJECT;
+ }
+
+ // Set service mask for SUPL_WIFI
+ if(strcmp(conf.feature_supl_wifi, "BASIC") == 0) {
+ LOC_LOGD("%s:%d]: Setting SUPL_WIFI to mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_SUPL_WIFI;
+ }
+ else if(strcmp(conf.feature_supl_wifi, "DISABLED") == 0) {
+ LOC_LOGD("%s:%d]: Setting SUPL_WIFI to mode: DISABLED", __func__, __LINE__);
+ }
+ else if(strcmp(conf.feature_supl_wifi, "PREMIUM") == 0) {
+ LOC_LOGD("%s:%d]: Unrecognized value for SUPL_WIFI mode."\
+ "Setting SUPL_WIFI to default mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_SUPL_WIFI;
+ }
+
+ // Set service mask for WIFI_SUPPLICANT_INFO
+ if(strcmp(conf.feature_wifi_supplicant_info, "BASIC") == 0) {
+ LOC_LOGD("%s:%d]: Setting WIFI_SUPPLICANT_INFO to mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO;
+ }
+ else if(strcmp(conf.feature_wifi_supplicant_info, "DISABLED") == 0) {
+ LOC_LOGD("%s:%d]: Setting WIFI_SUPPLICANT_INFO to mode: DISABLED", __func__, __LINE__);
+ }
+ else if(strcmp(conf.feature_wifi_supplicant_info, "PREMIUM") == 0) {
+ LOC_LOGD("%s:%d]: Unrecognized value for WIFI_SUPPLICANT_INFO mode."\
+ "Setting LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO to default mode: BASIC", __func__, __LINE__);
+ loc_service_mask |= LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO;
+ }
+
+ LOC_LOGD("%s:%d]: loc_service_mask: %x\n", __func__, __LINE__, loc_service_mask);
+
+ if((conf_fp = fopen(conf_file_name, "r")) == NULL) {
+ LOC_LOGE("%s:%d]: Error opening %s %s\n", __func__,
+ __LINE__, conf_file_name, strerror(errno));
+ ret = -1;
+ goto err;
+ }
+
+ //Parse through the file to find out how many processes are to be launched
+ proc_list_length = 0;
+ do {
+ conf.proc_name[0] = 0;
+ //Here note that the 3rd parameter is passed as 1.
+ //This is so that only the first parameter in the table which is "PROCESS_NAME"
+ //is read. We do not want to read the entire block of parameters at this time
+ //since we are only counting the number of processes to launch.
+ //Therefore, only counting the occurrences of PROCESS_NAME parameter
+ //should suffice
+ if(loc_read_conf_r(conf_fp, loc_process_conf_parameter_table, 1)) {
+ LOC_LOGE("%s:%d]: Unable to read conf file. Failing\n", __func__, __LINE__);
+ ret = -1;
+ goto err;
+ }
+ name_length=(int)strlen(conf.proc_name);
+ if(name_length) {
+ proc_list_length++;
+ LOC_LOGD("Process name:%s", conf.proc_name);
+ }
+ } while(name_length);
+ LOC_LOGD("Process cnt = %d", proc_list_length);
+
+ child_proc = (loc_process_info_s_type *)calloc(proc_list_length, sizeof(loc_process_info_s_type));
+ if(child_proc == NULL) {
+ LOC_LOGE("%s:%d]: ERROR: Malloc returned NULL\n", __func__, __LINE__);
+ ret = -1;
+ goto err;
+ }
+
+ //Move file descriptor to the beginning of the file
+ //so that the parameters can be read
+ rewind(conf_fp);
+
+ for(j=0; j<proc_list_length; j++) {
+ //Set defaults for all the child process structs
+ child_proc[j].proc_status = DISABLED;
+ memset(child_proc[j].group_list, 0, sizeof(child_proc[j].group_list));
+ config_mask=0;
+ if(loc_read_conf_r(conf_fp, loc_process_conf_parameter_table,
+ sizeof(loc_process_conf_parameter_table)/sizeof(loc_process_conf_parameter_table[0]))) {
+ LOC_LOGE("%s:%d]: Unable to read conf file. Failing\n", __func__, __LINE__);
+ ret = -1;
+ goto err;
+ }
+
+ name_length=(int)strlen(conf.proc_name);
+ group_list_length=(int)strlen(conf.group_list);
+ platform_length = (int)strlen(conf.platform_list);
+ baseband_length = (int)strlen(conf.baseband);
+ status_length = (int)strlen(conf.proc_status);
+ auto_platform_length = (int)strlen(conf.auto_platform);
+
+ if(!name_length || !group_list_length || !platform_length ||
+ !baseband_length || !status_length || !auto_platform_length) {
+ LOC_LOGE("%s:%d]: Error: i: %d; One of the parameters not specified in conf file",
+ __func__, __LINE__, i);
+ continue;
+ }
+
+ if(strcmp(conf.proc_status, "DISABLED") == 0) {
+ LOC_LOGD("%s:%d]: Process %s is disabled in conf file",
+ __func__, __LINE__, conf.proc_name);
+ child_proc[j].proc_status = DISABLED_FROM_CONF;
+ continue;
+ }
+ else if(strcmp(conf.proc_status, "ENABLED") == 0) {
+ LOC_LOGD("%s:%d]: Process %s is enabled in conf file",
+ __func__, __LINE__, conf.proc_name);
+ }
+
+ //Since strlcpy copies length-1 characters, we add 1 to name_length
+ if((name_length+1) > LOC_MAX_PARAM_STRING) {
+ LOC_LOGE("%s:%d]: i: %d; Length of name parameter too long. Max length: %d",
+ __func__, __LINE__, i, LOC_MAX_PARAM_STRING);
+ continue;
+ }
+ strlcpy(child_proc[j].name[0], conf.proc_name, sizeof (child_proc[j].name[0]));
+
+ child_proc[j].num_groups = 0;
+ ngroups = loc_util_split_string(conf.group_list, split_strings, MAX_NUM_STRINGS, ' ');
+#ifdef __ANDROID__
+ for(i=0; i<ngroups; i++) {
+ struct passwd* pwd = getpwnam(split_strings[i]);
+ if (pwd) {
+ child_proc[j].group_list[i] = pwd->pw_gid;
+ child_proc[j].num_groups++;
+ LOC_LOGD("%s:%d]:Group %s = %d matches child_group: %d\n",
+ __func__, __LINE__, split_strings[i],
+ pwd->pw_gid,child_proc[j].group_list[i]);
+ }
+ }
+#endif
+ nstrings = loc_util_split_string(conf.platform_list, split_strings, MAX_NUM_STRINGS, ' ');
+ if(strcmp("all", split_strings[0]) == 0) {
+ if (nstrings == 1 || (nstrings == 2 && (strcmp("exclude", split_strings[1]) == 0))) {
+ LOC_LOGD("%s:%d]: Enabled for all targets\n", __func__, __LINE__);
+ config_mask |= CONFIG_MASK_TARGET_ALL;
+ }
+ else if (nstrings > 2 && (strcmp("exclude", split_strings[1]) == 0)) {
+ config_mask |= CONFIG_MASK_TARGET_FOUND;
+ for (i=2; i<nstrings; i++) {
+ if(strcmp(platform_name, split_strings[i]) == 0) {
+ LOC_LOGD("%s:%d]: Disabled platform %s\n", __func__, __LINE__, platform_name);
+ config_mask &= ~CONFIG_MASK_TARGET_FOUND;
+ break;
+ }
+ }
+ }
+ }
+ else {
+ for(i=0; i<nstrings; i++) {
+ if(strcmp(platform_name, split_strings[i]) == 0) {
+ LOC_LOGD("%s:%d]: Matched platform: %s\n",
+ __func__, __LINE__, split_strings[i]);
+ config_mask |= CONFIG_MASK_TARGET_FOUND;
+ break;
+ }
+ }
+ }
+
+ nstrings = loc_util_split_string(conf.baseband, split_strings, MAX_NUM_STRINGS, ' ');
+ if(strcmp("all", split_strings[0]) == 0) {
+ if (nstrings == 1 || (nstrings == 2 && (strcmp("exclude", split_strings[1]) == 0))) {
+ LOC_LOGD("%s:%d]: Enabled for all basebands\n", __func__, __LINE__);
+ config_mask |= CONFIG_MASK_BASEBAND_ALL;
+ }
+ else if (nstrings > 2 && (strcmp("exclude", split_strings[1]) == 0)) {
+ config_mask |= CONFIG_MASK_BASEBAND_FOUND;
+ for (i=2; i<nstrings; i++) {
+ if(strcmp(baseband_name, split_strings[i]) == 0) {
+ LOC_LOGD("%s:%d]: Disabled band %s\n", __func__, __LINE__, baseband_name);
+ config_mask &= ~CONFIG_MASK_BASEBAND_FOUND;
+ break;
+ }
+ }
+ }
+ }
+ else {
+ for(i=0; i<nstrings; i++) {
+ if(strcmp(baseband_name, split_strings[i]) == 0) {
+ LOC_LOGD("%s:%d]: Matched baseband: %s\n",
+ __func__, __LINE__, split_strings[i]);
+ config_mask |= CONFIG_MASK_BASEBAND_FOUND;
+ break;
+ }
+ //Since ro.baseband is not a reliable source for detecting sglte
+ //the alternative is to read the SGLTE_TARGET parameter from gps.conf
+ //this parameter is read into conf_sglte_target
+ else if((strcmp("sglte", split_strings[i]) == 0 ) && conf.sglte_target) {
+ LOC_LOGD("%s:%d]: Matched baseband SGLTE\n", __func__, __LINE__);
+ config_mask |= CONFIG_MASK_BASEBAND_FOUND;
+ break;
+ }
+ }
+ }
+
+ nstrings = loc_util_split_string(conf.auto_platform, split_strings, MAX_NUM_STRINGS, ' ');
+ if(strcmp("all", split_strings[0]) == 0) {
+ LOC_LOGD("%s:%d]: Enabled for all auto platforms\n", __func__, __LINE__);
+ config_mask |= CONFIG_MASK_AUTOPLATFORM_ALL;
+ }
+ else {
+ for(i=0; i<nstrings; i++) {
+ if(strcmp(autoplatform_name, split_strings[i]) == 0) {
+ LOC_LOGD("%s:%d]: Matched auto platform: %s\n",
+ __func__, __LINE__, split_strings[i]);
+ config_mask |= CONFIG_MASK_AUTOPLATFORM_FOUND;
+ break;
+ }
+ }
+ }
+
+ nstrings = loc_util_split_string(conf.lean_targets, split_strings, MAX_NUM_STRINGS, ' ');
+ if(!strcmp("DISABLED", split_strings[0]) && lean_target) {
+ LOC_LOGD("%s:%d]: Disabled for lean targets\n", __func__, __LINE__);
+ child_proc[j].proc_status = DISABLED;
+ continue;
+ }
+
+ if((config_mask & CONFIG_MASK_TARGET_CHECK) &&
+ (config_mask & CONFIG_MASK_BASEBAND_CHECK) &&
+ (config_mask & CONFIG_MASK_AUTOPLATFORM_CHECK) &&
+ (child_proc[j].proc_status != DISABLED_FROM_CONF)) {
+
+ //Set args
+ //The first argument passed through argv is usually the name of the
+ //binary when started from commandline.
+ //getopt() seems to ignore this first argument and hence we assign it
+ //to the process name for consistency with command line args
+ i = 0;
+ char* temp_arg = ('/' == child_proc[j].name[0][0]) ?
+ (strrchr(child_proc[j].name[0], '/') + 1) : child_proc[j].name[0];
+ strlcpy (child_proc[j].args[i++], temp_arg, sizeof (child_proc[j].args[i++]));
+
+ if(conf.premium_feature) {
+ if(conf.loc_feature_mask & loc_service_mask) {
+ LOC_LOGD("%s:%d]: Enabled. %s has service mask: %x\n",
+ __func__, __LINE__, child_proc[j].name[0], conf.loc_feature_mask);
+ child_proc[j].proc_status = ENABLED;
+
+ if(conf.loc_feature_mask &
+ (LOC_FEATURE_MASK_GTP_WIFI_BASIC | LOC_FEATURE_MASK_GTP_WIFI_PREMIUM)) {
+ if(loc_service_mask & LOC_FEATURE_MASK_GTP_WIFI_BASIC) {
+ strlcpy(child_proc[j].args[i++], arg_gtp_wifi,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_basic,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else if(loc_service_mask & LOC_FEATURE_MASK_GTP_WIFI_PREMIUM) {
+ strlcpy(child_proc[j].args[i++], arg_gtp_wifi,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_premium,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else
+ {
+ strlcpy(child_proc[j].args[i++], arg_gtp_wifi,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_disabled,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ }
+ if(conf.loc_feature_mask &
+ (LOC_FEATURE_MASK_GTP_CELL_BASIC | LOC_FEATURE_MASK_GTP_CELL_PREMIUM )) {
+ if(loc_service_mask & LOC_FEATURE_MASK_GTP_AP_CELL_BASIC){
+ strlcpy(child_proc[j].args[i++], arg_gtp_ap_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_basic,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_gtp_modem_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_disabled,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else if(loc_service_mask & LOC_FEATURE_MASK_GTP_AP_CELL_PREMIUM){
+ strlcpy(child_proc[j].args[i++], arg_gtp_ap_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_premium,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_gtp_modem_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_disabled,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else if(loc_service_mask & LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC) {
+ strlcpy(child_proc[j].args[i++], arg_gtp_modem_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_basic,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_gtp_ap_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_disabled,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else if(loc_service_mask & LOC_FEATURE_MASK_GTP_MODEM_CELL_PREMIUM) {
+ strlcpy(child_proc[j].args[i++], arg_gtp_modem_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_premium,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_gtp_ap_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_disabled,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else {
+ strlcpy(child_proc[j].args[i++], arg_gtp_ap_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_disabled,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_gtp_modem_cell,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_disabled,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ }
+ if(conf.loc_feature_mask &
+ (LOC_FEATURE_MASK_GTP_WAA_BASIC | LOC_FEATURE_MASK_GTP_WAA_PREMIUM)) {
+ if(loc_service_mask & LOC_FEATURE_MASK_GTP_WAA_BASIC) {
+ strlcpy(child_proc[j].args[i++], arg_gtp_waa,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_basic,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else if(loc_service_mask & LOC_FEATURE_MASK_GTP_WAA_PREMIUM) {
+ strlcpy(child_proc[j].args[i++], arg_gtp_waa,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_premium,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else
+ {
+ strlcpy(child_proc[j].args[i++], arg_gtp_waa,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_disabled,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ }
+ if(conf.loc_feature_mask &
+ (LOC_FEATURE_MASK_SAP_BASIC | LOC_FEATURE_MASK_SAP_PREMIUM)) {
+ if(loc_service_mask & LOC_FEATURE_MASK_SAP_BASIC) {
+ strlcpy(child_proc[j].args[i++], arg_sap,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_basic,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else if(loc_service_mask & LOC_FEATURE_MASK_SAP_PREMIUM) {
+ strlcpy(child_proc[j].args[i++], arg_sap,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_premium,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ else
+ {
+ strlcpy(child_proc[j].args[i++], arg_sap,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ strlcpy(child_proc[j].args[i++], arg_disabled,
+ LOC_PROCESS_MAX_ARG_STR_LENGTH);
+ }
+ }
+ IF_LOC_LOGD {
+ LOC_LOGD("%s:%d]: %s args\n", __func__, __LINE__, child_proc[j].name[0]);
+ for(unsigned int k=0; k<LOC_PROCESS_MAX_NUM_ARGS; k++) {
+ if(child_proc[j].args[k][0] != '\0') {
+ LOC_LOGD("%s:%d]: k: %d, %s\n", __func__, __LINE__, k,
+ child_proc[j].args[k]);
+ }
+ }
+ LOC_LOGD("%s:%d]: \n", __func__, __LINE__);
+ }
+ }
+ else {
+ LOC_LOGD("%s:%d]: Disabled. %s has service mask: %x \n",
+ __func__, __LINE__, child_proc[j].name[0], conf.loc_feature_mask);
+ }
+ }
+ else {
+ LOC_LOGD("%s:%d]: %s not a premium feature. Enabled\n",
+ __func__, __LINE__, child_proc[j].name[0]);
+ child_proc[j].proc_status = ENABLED;
+ }
+
+ /*Fill up the remaining arguments from configuration file*/
+ LOC_LOGD("%s] Parsing Process_Arguments from Configuration: %s \n",
+ __func__, conf.proc_argument);
+ if(0 != conf.proc_argument[0])
+ {
+ /**************************************
+ ** conf_proc_argument is shared by all the programs getting launched,
+ ** hence copy to process specific argument string and parse the same.
+ ***************************************/
+ strlcpy(child_proc[j].argumentString, conf.proc_argument,
+ sizeof(child_proc[j].argumentString));
+ char *temp_args[LOC_PROCESS_MAX_NUM_ARGS];
+ memset (temp_args, 0, sizeof (temp_args));
+ loc_util_split_string(child_proc[j].argumentString, &temp_args[i],
+ (LOC_PROCESS_MAX_NUM_ARGS - i), ' ');
+ // copy argument from the pointer to the memory
+ for (unsigned int index = i; index < LOC_PROCESS_MAX_NUM_ARGS; index++) {
+ if (temp_args[index] == NULL) {
+ break;
+ }
+ strlcpy (child_proc[j].args[index], temp_args[index],
+ sizeof (child_proc[j].args[index]));
+ }
+ }
+ }
+ else {
+ LOC_LOGD("%s:%d]: Process %s is disabled\n",
+ __func__, __LINE__, child_proc[j].name[0]);
+ }
+ }
+
+err:
+ fclose(conf_fp);
+ if (ret != 0) {
+ LOC_LOGE("%s:%d]: ret: %d", __func__, __LINE__, ret);
+ if (child_proc) {
+ free (child_proc);
+ child_proc = nullptr;
+ }
+ *process_count_ptr = 0;
+ *process_info_table_ptr = nullptr;
+
+ }
+ else {
+ *process_count_ptr = proc_list_length;
+ *process_info_table_ptr = child_proc;
+ }
+
+ return ret;
+}