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