1 /* Copyright (c) 2009-2014,2016, 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_ENG_H 31 #define LOC_ENG_H 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif /* __cplusplus */ 36 37 // Uncomment to keep all LOG messages (LOGD, LOGI, LOGV, etc.) 38 #define MAX_NUM_ATL_CONNECTIONS 2 39 40 // Define boolean type to be used by libgps on loc api module 41 typedef unsigned char boolean; 42 43 #ifndef TRUE 44 #define TRUE 1 45 #endif 46 47 #ifndef FALSE 48 #define FALSE 0 49 #endif 50 51 #include <loc.h> 52 #include <loc_eng_xtra.h> 53 #include <loc_eng_ni.h> 54 #include <loc_eng_agps.h> 55 #include <loc_cfg.h> 56 #include <loc_log.h> 57 #include <log_util.h> 58 #include <loc_eng_agps.h> 59 #include <LocEngAdapter.h> 60 61 // The data connection minimal open time 62 #define DATA_OPEN_MIN_TIME 1 /* sec */ 63 64 // The system sees GPS engine turns off after inactive for this period of time 65 #define GPS_AUTO_OFF_TIME 2 /* secs */ 66 #define SUCCESS TRUE 67 #define FAILURE FALSE 68 #define INVALID_ATL_CONNECTION_HANDLE -1 69 70 #define MAX_XTRA_SERVER_URL_LENGTH 256 71 72 enum loc_nmea_provider_e_type { 73 NMEA_PROVIDER_AP = 0, // Application Processor Provider of NMEA 74 NMEA_PROVIDER_MP // Modem Processor Provider of NMEA 75 }; 76 77 enum loc_mute_session_e_type { 78 LOC_MUTE_SESS_NONE = 0, 79 LOC_MUTE_SESS_WAIT, 80 LOC_MUTE_SESS_IN_SESSION 81 }; 82 83 // Module data 84 typedef struct loc_eng_data_s 85 { 86 LocEngAdapter *adapter; 87 loc_location_cb_ext location_cb; 88 gps_status_callback status_cb; 89 loc_sv_status_cb_ext sv_status_cb; 90 agps_status_extended agps_status_cb; 91 gps_nmea_callback nmea_cb; 92 gps_ni_notify_callback ni_notify_cb; 93 gps_set_capabilities set_capabilities_cb; 94 gps_acquire_wakelock acquire_wakelock_cb; 95 gps_release_wakelock release_wakelock_cb; 96 gps_request_utc_time request_utc_time_cb; 97 gnss_set_system_info set_system_info_cb; 98 gnss_sv_status_callback gnss_sv_status_cb; 99 gnss_measurement_callback gnss_measurement_cb; 100 boolean intermediateFix; 101 AGpsStatusValue agps_status; 102 loc_eng_xtra_data_s_type xtra_module_data; 103 loc_eng_ni_data_s_type loc_eng_ni_data; 104 105 // AGPS state machines 106 AgpsStateMachine* agnss_nif; 107 AgpsStateMachine* internet_nif; 108 AgpsStateMachine* wifi_nif; 109 //State machine for Data Services 110 AgpsStateMachine* ds_nif; 111 112 // GPS engine status 113 GpsStatusValue engine_status; 114 GpsStatusValue fix_session_status; 115 116 // Aiding data information to be deleted, aiding data can only be deleted when GPS engine is off 117 GpsAidingData aiding_data_for_deletion; 118 119 // For muting session broadcast 120 loc_mute_session_e_type mute_session_state; 121 122 // For nmea generation 123 boolean generateNmea; 124 uint32_t sv_used_mask; 125 float hdop; 126 float pdop; 127 float vdop; 128 129 // Address buffers, for addressing setting before init 130 int supl_host_set; 131 char supl_host_buf[101]; 132 int supl_port_buf; 133 int c2k_host_set; 134 char c2k_host_buf[101]; 135 int c2k_port_buf; 136 int mpc_host_set; 137 char mpc_host_buf[101]; 138 int mpc_port_buf; 139 140 loc_ext_parser location_ext_parser; 141 loc_ext_parser sv_ext_parser; 142 } loc_eng_data_s_type; 143 144 /* GPS.conf support */ 145 /* NOTE: the implementaiton of the parser casts number 146 fields to 32 bit. To ensure all 'n' fields working, 147 they must all be 32 bit fields. */ 148 typedef struct loc_gps_cfg_s 149 { 150 uint32_t INTERMEDIATE_POS; 151 uint32_t ACCURACY_THRES; 152 uint32_t SUPL_VER; 153 uint32_t SUPL_MODE; 154 uint32_t CAPABILITIES; 155 uint32_t LPP_PROFILE; 156 uint32_t XTRA_VERSION_CHECK; 157 char XTRA_SERVER_1[MAX_XTRA_SERVER_URL_LENGTH]; 158 char XTRA_SERVER_2[MAX_XTRA_SERVER_URL_LENGTH]; 159 char XTRA_SERVER_3[MAX_XTRA_SERVER_URL_LENGTH]; 160 uint32_t USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL; 161 uint32_t NMEA_PROVIDER; 162 uint32_t GPS_LOCK; 163 uint32_t A_GLONASS_POS_PROTOCOL_SELECT; 164 uint32_t AGPS_CERT_WRITABLE_MASK; 165 } loc_gps_cfg_s_type; 166 167 /* NOTE: the implementaiton of the parser casts number 168 fields to 32 bit. To ensure all 'n' fields working, 169 they must all be 32 bit fields. */ 170 /* Meanwhile, *_valid fields are 8 bit fields, and 'f' 171 fields are double. Rigid as they are, it is the 172 the status quo, until the parsing mechanism is 173 change, that is. */ 174 typedef struct 175 { 176 uint8_t GYRO_BIAS_RANDOM_WALK_VALID; 177 double GYRO_BIAS_RANDOM_WALK; 178 uint32_t SENSOR_ACCEL_BATCHES_PER_SEC; 179 uint32_t SENSOR_ACCEL_SAMPLES_PER_BATCH; 180 uint32_t SENSOR_GYRO_BATCHES_PER_SEC; 181 uint32_t SENSOR_GYRO_SAMPLES_PER_BATCH; 182 uint32_t SENSOR_ACCEL_BATCHES_PER_SEC_HIGH; 183 uint32_t SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH; 184 uint32_t SENSOR_GYRO_BATCHES_PER_SEC_HIGH; 185 uint32_t SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH; 186 uint32_t SENSOR_CONTROL_MODE; 187 uint32_t SENSOR_USAGE; 188 uint32_t SENSOR_ALGORITHM_CONFIG_MASK; 189 uint8_t ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID; 190 double ACCEL_RANDOM_WALK_SPECTRAL_DENSITY; 191 uint8_t ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID; 192 double ANGLE_RANDOM_WALK_SPECTRAL_DENSITY; 193 uint8_t RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID; 194 double RATE_RANDOM_WALK_SPECTRAL_DENSITY; 195 uint8_t VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID; 196 double VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY; 197 uint32_t SENSOR_PROVIDER; 198 } loc_sap_cfg_s_type; 199 200 extern loc_gps_cfg_s_type gps_conf; 201 extern loc_sap_cfg_s_type sap_conf; 202 203 204 uint32_t getCarrierCapabilities(); 205 206 //loc_eng functions 207 int loc_eng_init(loc_eng_data_s_type &loc_eng_data, 208 LocCallbacks* callbacks, 209 LOC_API_ADAPTER_EVENT_MASK_T event, 210 ContextBase* context); 211 int loc_eng_start(loc_eng_data_s_type &loc_eng_data); 212 int loc_eng_stop(loc_eng_data_s_type &loc_eng_data); 213 void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data); 214 int loc_eng_inject_time(loc_eng_data_s_type &loc_eng_data, 215 GpsUtcTime time, int64_t timeReference, 216 int uncertainty); 217 int loc_eng_inject_location(loc_eng_data_s_type &loc_eng_data, 218 double latitude, double longitude, 219 float accuracy); 220 void loc_eng_delete_aiding_data(loc_eng_data_s_type &loc_eng_data, 221 GpsAidingData f); 222 int loc_eng_set_position_mode(loc_eng_data_s_type &loc_eng_data, 223 LocPosMode ¶ms); 224 const void* loc_eng_get_extension(loc_eng_data_s_type &loc_eng_data, 225 const char* name); 226 int loc_eng_set_server_proxy(loc_eng_data_s_type &loc_eng_data, 227 LocServerType type, const char *hostname, int port); 228 void loc_eng_mute_one_session(loc_eng_data_s_type &loc_eng_data); 229 int loc_eng_read_config(void); 230 231 //loc_eng_agps functions 232 void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data, 233 AGpsExtCallbacks* callbacks); 234 int loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType, 235 const char* apn, AGpsBearerType bearerType); 236 int loc_eng_agps_closed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType); 237 int loc_eng_agps_open_failed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType); 238 void loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type &loc_eng_data, 239 int avaiable, const char* apn); 240 int loc_eng_agps_install_certificates(loc_eng_data_s_type &loc_eng_data, 241 const DerEncodedCertificate* certificates, 242 size_t length); 243 244 //loc_eng_xtra functions 245 int loc_eng_xtra_init (loc_eng_data_s_type &loc_eng_data, 246 GpsXtraExtCallbacks* callbacks); 247 int loc_eng_xtra_inject_data(loc_eng_data_s_type &loc_eng_data, 248 char* data, int length); 249 int loc_eng_xtra_request_server(loc_eng_data_s_type &loc_eng_data); 250 void loc_eng_xtra_version_check(loc_eng_data_s_type &loc_eng_data, int check); 251 252 //loc_eng_ni functions 253 extern void loc_eng_ni_init(loc_eng_data_s_type &loc_eng_data, 254 GpsNiExtCallbacks *callbacks); 255 extern void loc_eng_ni_respond(loc_eng_data_s_type &loc_eng_data, 256 int notif_id, GpsUserResponseType user_response); 257 extern void loc_eng_ni_request_handler(loc_eng_data_s_type &loc_eng_data, 258 const GpsNiNotification *notif, 259 const void* passThrough); 260 extern void loc_eng_ni_reset_on_engine_restart(loc_eng_data_s_type &loc_eng_data); 261 262 void loc_eng_configuration_update (loc_eng_data_s_type &loc_eng_data, 263 const char* config_data, int32_t length); 264 int loc_eng_gps_measurement_init(loc_eng_data_s_type &loc_eng_data, 265 GpsMeasurementCallbacks* callbacks); 266 void loc_eng_gps_measurement_close(loc_eng_data_s_type &loc_eng_data); 267 268 #ifdef __cplusplus 269 } 270 #endif /* __cplusplus */ 271 272 #endif // LOC_ENG_H 273