gps_extended_c.h revision 47ad5e4cf2f6810db3c0e7ec79696496a94b6f0d
1/* Copyright (c) 2013-2014, 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#ifndef GPS_EXTENDED_C_H 30#define GPS_EXTENDED_C_H 31 32#ifdef __cplusplus 33extern "C" { 34#endif /* __cplusplus */ 35 36#include <ctype.h> 37#include <stdbool.h> 38#include <hardware/gps.h> 39 40/** Location has valid source information. */ 41#define LOCATION_HAS_SOURCE_INFO 0x0020 42/** GpsLocation has valid "is indoor?" flag */ 43#define GPS_LOCATION_HAS_IS_INDOOR 0x0040 44/** GpsLocation has valid floor number */ 45#define GPS_LOCATION_HAS_FLOOR_NUMBER 0x0080 46/** GpsLocation has valid map URL*/ 47#define GPS_LOCATION_HAS_MAP_URL 0x0100 48/** GpsLocation has valid map index */ 49#define GPS_LOCATION_HAS_MAP_INDEX 0x0200 50 51/** Sizes for indoor fields */ 52#define GPS_LOCATION_MAP_URL_SIZE 400 53#define GPS_LOCATION_MAP_INDEX_SIZE 16 54 55/** Position source is ULP */ 56#define ULP_LOCATION_IS_FROM_HYBRID 0x0001 57/** Position source is GNSS only */ 58#define ULP_LOCATION_IS_FROM_GNSS 0x0002 59/** Position source is ZPP only */ 60#define ULP_LOCATION_IS_FROM_ZPP 0x0004 61/** Position is from a Geofence Breach Event */ 62#define ULP_LOCATION_IS_FROM_GEOFENCE 0X0008 63/** Positioin is from Hardware FLP */ 64#define ULP_LOCATION_IS_FROM_HW_FLP 0x0010 65 66#define ULP_MIN_INTERVAL_INVALID 0xffffffff 67 68/*Emergency SUPL*/ 69#define GPS_NI_TYPE_EMERGENCY_SUPL 4 70 71typedef struct { 72 /** set to sizeof(UlpLocation) */ 73 size_t size; 74 GpsLocation gpsLocation; 75 /* Provider indicator for HYBRID or GPS */ 76 uint16_t position_source; 77 /*allows HAL to pass additional information related to the location */ 78 int rawDataSize; /* in # of bytes */ 79 void * rawData; 80 bool is_indoor; 81 float floor_number; 82 char map_url[GPS_LOCATION_MAP_URL_SIZE]; 83 unsigned char map_index[GPS_LOCATION_MAP_INDEX_SIZE]; 84} UlpLocation; 85 86/** AGPS type */ 87typedef int16_t AGpsExtType; 88#define AGPS_TYPE_INVALID -1 89#define AGPS_TYPE_ANY 0 90#define AGPS_TYPE_SUPL 1 91#define AGPS_TYPE_C2K 2 92#define AGPS_TYPE_WWAN_ANY 3 93#define AGPS_TYPE_WIFI 4 94#define AGPS_TYPE_SUPL_ES 5 95 96/** SSID length */ 97#define SSID_BUF_SIZE (32+1) 98 99typedef int16_t AGpsBearerType; 100#define AGPS_APN_BEARER_INVALID -1 101#define AGPS_APN_BEARER_IPV4 0 102#define AGPS_APN_BEARER_IPV6 1 103#define AGPS_APN_BEARER_IPV4V6 2 104 105/** GPS extended callback structure. */ 106typedef struct { 107 /** set to sizeof(GpsCallbacks) */ 108 size_t size; 109 gps_set_capabilities set_capabilities_cb; 110 gps_acquire_wakelock acquire_wakelock_cb; 111 gps_release_wakelock release_wakelock_cb; 112 gps_create_thread create_thread_cb; 113 gps_request_utc_time request_utc_time_cb; 114} GpsExtCallbacks; 115 116/** GPS extended batch options */ 117typedef struct { 118 double max_power_allocation_mW; 119 uint32_t sources_to_use; 120 uint32_t flags; 121 int64_t period_ns; 122} GpsExtBatchOptions; 123 124/** Callback to report the xtra server url to the client. 125 * The client should use this url when downloading xtra unless overwritten 126 * in the gps.conf file 127 */ 128typedef void (* report_xtra_server)(const char*, const char*, const char*); 129 130/** Callback structure for the XTRA interface. */ 131typedef struct { 132 gps_xtra_download_request download_request_cb; 133 gps_create_thread create_thread_cb; 134 report_xtra_server report_xtra_server_cb; 135} GpsXtraExtCallbacks; 136 137/** Represents the status of AGPS. */ 138typedef struct { 139 /** set to sizeof(AGpsExtStatus) */ 140 size_t size; 141 142 AGpsExtType type; 143 AGpsStatusValue status; 144 uint32_t ipv4_addr; 145 char ipv6_addr[16]; 146 char ssid[SSID_BUF_SIZE]; 147 char password[SSID_BUF_SIZE]; 148} AGpsExtStatus; 149 150/** Callback with AGPS status information. 151 * Can only be called from a thread created by create_thread_cb. 152 */ 153typedef void (* agps_status_extended)(AGpsExtStatus* status); 154 155/** Callback structure for the AGPS interface. */ 156typedef struct { 157 agps_status_extended status_cb; 158 gps_create_thread create_thread_cb; 159} AGpsExtCallbacks; 160 161 162/** GPS NI callback structure. */ 163typedef struct 164{ 165 /** 166 * Sends the notification request from HAL to GPSLocationProvider. 167 */ 168 gps_ni_notify_callback notify_cb; 169 gps_create_thread create_thread_cb; 170} GpsNiExtCallbacks; 171 172typedef enum loc_server_type { 173 LOC_AGPS_CDMA_PDE_SERVER, 174 LOC_AGPS_CUSTOM_PDE_SERVER, 175 LOC_AGPS_MPC_SERVER, 176 LOC_AGPS_SUPL_SERVER 177} LocServerType; 178 179typedef enum loc_position_mode_type { 180 LOC_POSITION_MODE_INVALID = -1, 181 LOC_POSITION_MODE_STANDALONE = 0, 182 LOC_POSITION_MODE_MS_BASED, 183 LOC_POSITION_MODE_MS_ASSISTED, 184 LOC_POSITION_MODE_RESERVED_1, 185 LOC_POSITION_MODE_RESERVED_2, 186 LOC_POSITION_MODE_RESERVED_3, 187 LOC_POSITION_MODE_RESERVED_4, 188 LOC_POSITION_MODE_RESERVED_5 189 190} LocPositionMode; 191 192#define MIN_POSSIBLE_FIX_INTERVAL 1000 /* msec */ 193 194/** GpsLocationExtended has valid latitude and longitude. */ 195#define GPS_LOCATION_EXTENDED_HAS_LAT_LONG (1U<<0) 196/** GpsLocationExtended has valid altitude. */ 197#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE (1U<<1) 198/** GpsLocationExtended has valid speed. */ 199#define GPS_LOCATION_EXTENDED_HAS_SPEED (1U<<2) 200/** GpsLocationExtended has valid bearing. */ 201#define GPS_LOCATION_EXTENDED_HAS_BEARING (1U<<4) 202/** GpsLocationExtended has valid accuracy. */ 203#define GPS_LOCATION_EXTENDED_HAS_ACCURACY (1U<<8) 204 205/** GPS extended supports geofencing */ 206#define GPS_EXTENDED_CAPABILITY_GEOFENCE 0x0000001 207/** GPS extended supports batching */ 208#define GPS_EXTENDED_CAPABILITY_BATCHING 0x0000002 209 210/** Flags to indicate which values are valid in a GpsLocationExtended. */ 211typedef uint16_t GpsLocationExtendedFlags; 212/** GpsLocationExtended has valid pdop, hdop, vdop. */ 213#define GPS_LOCATION_EXTENDED_HAS_DOP 0x0001 214/** GpsLocationExtended has valid altitude mean sea level. */ 215#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL 0x0002 216/** UlpLocation has valid magnetic deviation. */ 217#define GPS_LOCATION_EXTENDED_HAS_MAG_DEV 0x0004 218/** UlpLocation has valid mode indicator. */ 219#define GPS_LOCATION_EXTENDED_HAS_MODE_IND 0x0008 220/** GpsLocationExtended has valid vertical uncertainty */ 221#define GPS_LOCATION_EXTENDED_HAS_VERT_UNC 0x0010 222/** GpsLocationExtended has valid speed uncertainty */ 223#define GPS_LOCATION_EXTENDED_HAS_SPEED_UNC 0x0020 224 225/** Represents gps location extended. */ 226typedef struct { 227 /** set to sizeof(GpsLocationExtended) */ 228 size_t size; 229 /** Contains GpsLocationExtendedFlags bits. */ 230 uint16_t flags; 231 /** Contains the Altitude wrt mean sea level */ 232 float altitudeMeanSeaLevel; 233 /** Contains Position Dilusion of Precision. */ 234 float pdop; 235 /** Contains Horizontal Dilusion of Precision. */ 236 float hdop; 237 /** Contains Vertical Dilusion of Precision. */ 238 float vdop; 239 /** Contains Magnetic Deviation. */ 240 float magneticDeviation; 241 /** vertical uncertainty in meters */ 242 float vert_unc; 243 /** speed uncertainty in m/s */ 244 float speed_unc; 245} GpsLocationExtended; 246 247typedef struct GpsExtLocation_s { 248 size_t size; 249 uint16_t flags; 250 double latitude; 251 double longitude; 252 double altitude; 253 float speed; 254 float bearing; 255 float accuracy; 256 int64_t timestamp; 257 uint32_t sources_used; 258} GpsExtLocation; 259 260enum loc_sess_status { 261 LOC_SESS_SUCCESS, 262 LOC_SESS_INTERMEDIATE, 263 LOC_SESS_FAILURE 264}; 265 266typedef uint32_t LocPosTechMask; 267#define LOC_POS_TECH_MASK_DEFAULT ((LocPosTechMask)0x00000000) 268#define LOC_POS_TECH_MASK_SATELLITE ((LocPosTechMask)0x00000001) 269#define LOC_POS_TECH_MASK_CELLID ((LocPosTechMask)0x00000002) 270#define LOC_POS_TECH_MASK_WIFI ((LocPosTechMask)0x00000004) 271#define LOC_POS_TECH_MASK_SENSORS ((LocPosTechMask)0x00000008) 272#define LOC_POS_TECH_MASK_REFERENCE_LOCATION ((LocPosTechMask)0x00000010) 273#define LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION ((LocPosTechMask)0x00000020) 274#define LOC_POS_TECH_MASK_AFLT ((LocPosTechMask)0x00000040) 275#define LOC_POS_TECH_MASK_HYBRID ((LocPosTechMask)0x00000080) 276 277typedef enum { 278 LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC = 0, 279 LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, 280 LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, 281 LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, 282 LOC_ENG_IF_REQUEST_SENDER_ID_MODEM, 283 LOC_ENG_IF_REQUEST_SENDER_ID_UNKNOWN 284} loc_if_req_sender_id_e_type; 285 286 287#define smaller_of(a, b) (((a) > (b)) ? (b) : (a)) 288#define MAX_APN_LEN 100 289 290// This will be overridden by the individual adapters 291// if necessary. 292#define DEFAULT_IMPL(rtv) \ 293{ \ 294 LOC_LOGD("%s: default implementation invoked", __func__); \ 295 return rtv; \ 296} 297 298enum loc_api_adapter_err { 299 LOC_API_ADAPTER_ERR_SUCCESS = 0, 300 LOC_API_ADAPTER_ERR_GENERAL_FAILURE = 1, 301 LOC_API_ADAPTER_ERR_UNSUPPORTED = 2, 302 LOC_API_ADAPTER_ERR_INVALID_HANDLE = 4, 303 LOC_API_ADAPTER_ERR_INVALID_PARAMETER = 5, 304 LOC_API_ADAPTER_ERR_ENGINE_BUSY = 6, 305 LOC_API_ADAPTER_ERR_PHONE_OFFLINE = 7, 306 LOC_API_ADAPTER_ERR_TIMEOUT = 8, 307 LOC_API_ADAPTER_ERR_SERVICE_NOT_PRESENT = 9, 308 309 LOC_API_ADAPTER_ERR_ENGINE_DOWN = 100, 310 LOC_API_ADAPTER_ERR_FAILURE, 311 LOC_API_ADAPTER_ERR_UNKNOWN 312}; 313 314enum loc_api_adapter_event_index { 315 LOC_API_ADAPTER_REPORT_POSITION = 0, // Position report comes in loc_parsed_position_s_type 316 LOC_API_ADAPTER_REPORT_SATELLITE, // Satellite in view report 317 LOC_API_ADAPTER_REPORT_NMEA_1HZ, // NMEA report at 1HZ rate 318 LOC_API_ADAPTER_REPORT_NMEA_POSITION, // NMEA report at position report rate 319 LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY, // NI notification/verification request 320 LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA, // Assistance data, eg: time, predicted orbits request 321 LOC_API_ADAPTER_REQUEST_LOCATION_SERVER, // Request for location server 322 LOC_API_ADAPTER_REPORT_IOCTL, // Callback report for loc_ioctl 323 LOC_API_ADAPTER_REPORT_STATUS, // Misc status report: eg, engine state 324 LOC_API_ADAPTER_REQUEST_WIFI, // 325 LOC_API_ADAPTER_SENSOR_STATUS, // 326 LOC_API_ADAPTER_REQUEST_TIME_SYNC, // 327 LOC_API_ADAPTER_REPORT_SPI, // 328 LOC_API_ADAPTER_REPORT_NI_GEOFENCE, // 329 LOC_API_ADAPTER_GEOFENCE_GEN_ALERT, // 330 LOC_API_ADAPTER_REPORT_GENFENCE_BREACH, // 331 LOC_API_ADAPTER_PEDOMETER_CTRL, // 332 LOC_API_ADAPTER_MOTION_CTRL, // 333 LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA, // Wifi ap data 334 LOC_API_ADAPTER_BATCH_FULL, // Batching on full 335 LOC_API_ADAPTER_BATCHED_POSITION_REPORT, // Batching on fix 336 LOC_API_ADAPTER_BATCHED_GENFENCE_BREACH_REPORT, // 337 338 LOC_API_ADAPTER_EVENT_MAX 339}; 340 341#define LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT (1<<LOC_API_ADAPTER_REPORT_POSITION) 342#define LOC_API_ADAPTER_BIT_SATELLITE_REPORT (1<<LOC_API_ADAPTER_REPORT_SATELLITE) 343#define LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT (1<<LOC_API_ADAPTER_REPORT_NMEA_1HZ) 344#define LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT (1<<LOC_API_ADAPTER_REPORT_NMEA_POSITION) 345#define LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST (1<<LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY) 346#define LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST (1<<LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA) 347#define LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST (1<<LOC_API_ADAPTER_REQUEST_LOCATION_SERVER) 348#define LOC_API_ADAPTER_BIT_IOCTL_REPORT (1<<LOC_API_ADAPTER_REPORT_IOCTL) 349#define LOC_API_ADAPTER_BIT_STATUS_REPORT (1<<LOC_API_ADAPTER_REPORT_STATUS) 350#define LOC_API_ADAPTER_BIT_REQUEST_WIFI (1<<LOC_API_ADAPTER_REQUEST_WIFI) 351#define LOC_API_ADAPTER_BIT_SENSOR_STATUS (1<<LOC_API_ADAPTER_SENSOR_STATUS) 352#define LOC_API_ADAPTER_BIT_REQUEST_TIME_SYNC (1<<LOC_API_ADAPTER_REQUEST_TIME_SYNC) 353#define LOC_API_ADAPTER_BIT_REPORT_SPI (1<<LOC_API_ADAPTER_REPORT_SPI) 354#define LOC_API_ADAPTER_BIT_REPORT_NI_GEOFENCE (1<<LOC_API_ADAPTER_REPORT_NI_GEOFENCE) 355#define LOC_API_ADAPTER_BIT_GEOFENCE_GEN_ALERT (1<<LOC_API_ADAPTER_GEOFENCE_GEN_ALERT) 356#define LOC_API_ADAPTER_BIT_REPORT_GENFENCE_BREACH (1<<LOC_API_ADAPTER_REPORT_GENFENCE_BREACH) 357#define LOC_API_ADAPTER_BIT_BATCHED_GENFENCE_BREACH_REPORT (1<<LOC_API_ADAPTER_BATCHED_GENFENCE_BREACH_REPORT) 358#define LOC_API_ADAPTER_BIT_PEDOMETER_CTRL (1<<LOC_API_ADAPTER_PEDOMETER_CTRL) 359#define LOC_API_ADAPTER_BIT_MOTION_CTRL (1<<LOC_API_ADAPTER_MOTION_CTRL) 360#define LOC_API_ADAPTER_BIT_REQUEST_WIFI_AP_DATA (1<<LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA) 361#define LOC_API_ADAPTER_BIT_BATCH_FULL (1<<LOC_API_ADAPTER_BATCH_FULL) 362#define LOC_API_ADAPTER_BIT_BATCHED_POSITION_REPORT (1<<LOC_API_ADAPTER_BATCHED_POSITION_REPORT) 363 364typedef unsigned int LOC_API_ADAPTER_EVENT_MASK_T; 365 366 367#ifdef __cplusplus 368} 369#endif /* __cplusplus */ 370 371#endif /* GPS_EXTENDED_C_H */ 372 373