1 /* 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 #ifndef LOC_CFG_H
31 #define LOC_CFG_H
32
33 #include <stdio.h>
34 #include <stdint.h>
35 #include <sys/types.h>
36 #include <unistd.h>
37 #include <grp.h>
38
39 #define LOC_MAX_PARAM_NAME 80
40 #define LOC_MAX_PARAM_STRING 172
41 #define LOC_MAX_PARAM_LINE (LOC_MAX_PARAM_NAME + LOC_MAX_PARAM_STRING)
42
43 #define LOC_FEATURE_MODE_DISABLED "DISABLED"
44 #define LOC_FEATURE_MODE_BASIC "BASIC"
45 #define LOC_FEATURE_MODE_PREMIUM "PREMIUM"
46
47 #define LOC_FEATURE_GTP_AP_CELL "gtp-ap-cell"
48 #define LOC_FEATURE_GTP_MODEM_CELL "gtp-modem-cell"
49 #define LOC_FEATURE_GTP_CELL_ENH "gtp-cell-enh"
50 #define LOC_FEATURE_GTP_WIFI "gtp-wifi"
51 #define LOC_FEATURE_GTP_WAA "gtp-waa"
52 #define LOC_FEATURE_SAP "sap"
53
54 #define LOC_PROCESS_MAX_NUM_GROUPS 20
55 #define LOC_PROCESS_MAX_NUM_ARGS 25
56 #define LOC_PROCESS_MAX_ARG_STR_LENGTH 32
57
58 #define UTIL_UPDATE_CONF(conf_data, len, config_table) \
59 loc_update_conf((conf_data), (len), (&config_table[0]), \
60 sizeof(config_table) / sizeof(config_table[0]))
61
62 #define UTIL_READ_CONF_DEFAULT(filename) \
63 loc_read_conf((filename), NULL, 0);
64
65 #define UTIL_READ_CONF(filename, config_table) \
66 loc_read_conf((filename), (&config_table[0]), sizeof(config_table) / sizeof(config_table[0]))
67
68 #define UTIL_READ_CONF_LONG(filename, config_table, rec_len) \
69 loc_read_conf_long((filename), (&config_table[0]), \
70 sizeof(config_table) / sizeof(config_table[0]), (rec_len))
71
72 /*=============================================================================
73 *
74 * MODULE TYPE DECLARATION
75 *
76 *============================================================================*/
77 typedef struct
78 {
79 const char *param_name;
80 void *param_ptr; /* for string type, buf size need to be LOC_MAX_PARAM_STRING */
81 uint8_t *param_set; /* indicate value set by config file */
82 char param_type; /* 'n' for number,
83 's' for string, NOTE: buf size need to be LOC_MAX_PARAM_STRING
84 'f' for double */
85 } loc_param_s_type;
86
87 typedef enum {
88 ENABLED,
89 RUNNING,
90 DISABLED,
91 DISABLED_FROM_CONF,
92 DISABLED_VIA_VENDOR_ENHANCED_CHECK
93 } loc_process_e_status;
94
95 typedef struct {
96 loc_process_e_status proc_status;
97 pid_t proc_id;
98 char name[2][LOC_MAX_PARAM_STRING];
99 gid_t group_list[LOC_PROCESS_MAX_NUM_GROUPS];
100 unsigned char num_groups;
101 char args[LOC_PROCESS_MAX_NUM_ARGS][LOC_PROCESS_MAX_ARG_STR_LENGTH];
102 char argumentString[LOC_MAX_PARAM_STRING];
103 } loc_process_info_s_type;
104
105 /*=============================================================================
106 *
107 * MODULE EXTERNAL DATA
108 *
109 *============================================================================*/
110
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114
115 /*=============================================================================
116 *
117 * MODULE EXPORTED FUNCTIONS
118 *
119 *============================================================================*/
120 bool isVendorEnhanced();
121 void setVendorEnhanced(bool vendorEnhanced);
122 void loc_read_conf_long(const char* conf_file_name,
123 const loc_param_s_type* config_table,
124 uint32_t table_length, uint16_t string_len);
125 int loc_read_conf_r_long(FILE *conf_fp, const loc_param_s_type* config_table,
126 uint32_t table_length, uint16_t string_len);
127 int loc_update_conf_long(const char* conf_data, int32_t length,
128 const loc_param_s_type* config_table, uint32_t table_length,
129 uint16_t string_len);
130
loc_read_conf(const char * conf_file_name,const loc_param_s_type * config_table,uint32_t table_length)131 inline void loc_read_conf(const char* conf_file_name,
132 const loc_param_s_type* config_table, uint32_t table_length) {
133 loc_read_conf_long(conf_file_name, config_table, table_length, LOC_MAX_PARAM_STRING);
134 }
135
loc_read_conf_r(FILE * conf_fp,const loc_param_s_type * config_table,uint32_t table_length)136 inline int loc_read_conf_r(FILE *conf_fp, const loc_param_s_type* config_table,
137 uint32_t table_length) {
138 return (loc_read_conf_r_long(conf_fp, config_table, table_length, LOC_MAX_PARAM_STRING));
139 }
140
loc_update_conf(const char * conf_data,int32_t length,const loc_param_s_type * config_table,uint32_t table_length)141 inline int loc_update_conf(const char* conf_data, int32_t length,
142 const loc_param_s_type* config_table, uint32_t table_length) {
143 return (loc_update_conf_long(
144 conf_data, length, config_table, table_length, LOC_MAX_PARAM_STRING));
145 }
146
147 // Below are the location conf file paths
148 extern const char LOC_PATH_GPS_CONF[];
149 extern const char LOC_PATH_IZAT_CONF[];
150 extern const char LOC_PATH_FLP_CONF[];
151 extern const char LOC_PATH_LOWI_CONF[];
152 extern const char LOC_PATH_SAP_CONF[];
153 extern const char LOC_PATH_APDR_CONF[];
154 extern const char LOC_PATH_XTWIFI_CONF[];
155 extern const char LOC_PATH_QUIPC_CONF[];
156 extern const char LOC_PATH_ANT_CORR[];
157 extern const char LOC_PATH_SLIM_CONF[];
158 extern const char LOC_PATH_VPE_CONF[];
159
160 int loc_read_process_conf(const char* conf_file_name, uint32_t * process_count_ptr,
161 loc_process_info_s_type** process_info_table_ptr);
162 int loc_get_datum_type();
163 #ifdef __cplusplus
164 }
165 #endif
166
167 #endif /* LOC_CFG_H */
168