loc_cfg.cpp 47 KB

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