From 6925f8a04aa0190638f311292cc69a41c81c905c Mon Sep 17 00:00:00 2001 From: Tushar Janefalkar Date: Mon, 28 Jul 2014 16:58:06 -0700 Subject: [PATCH 1/2] Revert "Revert "Remove masks for Glonass"" This reverts commit 08237e52b67a06bb1ed35b5fb4a40aed8cd4c83a. Change-Id: I4e507ef8777d45825234914841562e7f2901bae0 --- core/gps_extended_c.h | 10 ---------- core/loc_core_log.cpp | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/core/gps_extended_c.h b/core/gps_extended_c.h index 63fe32a9..d4a7dbea 100644 --- a/core/gps_extended_c.h +++ b/core/gps_extended_c.h @@ -102,16 +102,6 @@ typedef int16_t AGpsBearerType; #define AGPS_APN_BEARER_IPV6 1 #define AGPS_APN_BEARER_IPV4V6 2 -#define GPS_DELETE_ALMANAC_CORR 0x00001000 -#define GPS_DELETE_FREQ_BIAS_EST 0x00002000 -#define GPS_DELETE_EPHEMERIS_GLO 0x00004000 -#define GPS_DELETE_ALMANAC_GLO 0x00008000 -#define GPS_DELETE_SVDIR_GLO 0x00010000 -#define GPS_DELETE_SVSTEER_GLO 0x00020000 -#define GPS_DELETE_ALMANAC_CORR_GLO 0x00040000 -#define GPS_DELETE_TIME_GPS 0x00080000 -#define GPS_DELETE_TIME_GLO 0x00100000 - /** GPS extended callback structure. */ typedef struct { /** set to sizeof(GpsCallbacks) */ diff --git a/core/loc_core_log.cpp b/core/loc_core_log.cpp index 430f4b8e..d2eda661 100644 --- a/core/loc_core_log.cpp +++ b/core/loc_core_log.cpp @@ -118,13 +118,20 @@ static loc_name_val_s_type loc_eng_aiding_data_bits[] = NAME_VAL( GPS_DELETE_CELLDB_INFO ), NAME_VAL( GPS_DELETE_ALMANAC_CORR ), NAME_VAL( GPS_DELETE_FREQ_BIAS_EST ), - NAME_VAL( GPS_DELETE_EPHEMERIS_GLO ), - NAME_VAL( GPS_DELETE_ALMANAC_GLO ), - NAME_VAL( GPS_DELETE_SVDIR_GLO ), - NAME_VAL( GPS_DELETE_SVSTEER_GLO ), - NAME_VAL( GPS_DELETE_ALMANAC_CORR_GLO ), + NAME_VAL( GLO_DELETE_EPHEMERIS ), + NAME_VAL( GLO_DELETE_ALMANAC ), + NAME_VAL( GLO_DELETE_SVDIR ), + NAME_VAL( GLO_DELETE_SVSTEER ), + NAME_VAL( GLO_DELETE_ALMANAC_CORR ), NAME_VAL( GPS_DELETE_TIME_GPS ), - NAME_VAL( GPS_DELETE_TIME_GLO ) + NAME_VAL( GLO_DELETE_TIME ), + NAME_VAL( BDS_DELETE_SVDIR ), + NAME_VAL( BDS_DELETE_SVSTEER ), + NAME_VAL( BDS_DELETE_TIME ), + NAME_VAL( BDS_DELETE_ALMANAC_CORR ), + NAME_VAL( BDS_DELETE_EPHEMERIS ), + NAME_VAL( BDS_DELETE_ALMANAC ), + NAME_VAL( GPS_DELETE_ALL) }; static int loc_eng_aiding_data_bit_num = sizeof(loc_eng_aiding_data_bits) / sizeof(loc_name_val_s_type); From 5cdfc25284b0eae255c4024f40513e621f4b9487 Mon Sep 17 00:00:00 2001 From: Dante Russo Date: Fri, 1 Nov 2013 15:58:07 -0700 Subject: [PATCH 2/2] agps cert install api implementation Implementation of the install agps certificate API for installing certificates at runtime. Change-Id: I49239b612381e81bd8a4c0a5773783572d4b2d9a --- core/LocApiBase.cpp | 6 ++ core/LocApiBase.h | 4 +- core/gps_extended_c.h | 3 + etc/gps.conf | 8 ++ loc_api/libloc_api_50001/LocEngAdapter.h | 6 ++ loc_api/libloc_api_50001/loc.cpp | 34 ++++++++ loc_api/libloc_api_50001/loc_eng.cpp | 100 +++++++++++++++++++++++ loc_api/libloc_api_50001/loc_eng.h | 6 +- 8 files changed, 165 insertions(+), 2 deletions(-) diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp index 97c282df..4d5355fd 100644 --- a/core/LocApiBase.cpp +++ b/core/LocApiBase.cpp @@ -478,6 +478,12 @@ int LocApiBase:: setGpsLock(unsigned int lock) DEFAULT_IMPL(-1) +void LocApiBase:: + installAGpsCert(const DerEncodedCertificate* pData, + size_t length, + uint32_t slotBitMask) +DEFAULT_IMPL() + int LocApiBase:: getGpsLock() DEFAULT_IMPL(-1) diff --git a/core/LocApiBase.h b/core/LocApiBase.h index f489f63f..b312937e 100644 --- a/core/LocApiBase.h +++ b/core/LocApiBase.h @@ -208,7 +208,9 @@ public: virtual int openAndStartDataCall(); virtual void stopDataCall(); virtual void closeDataCall(); - + virtual void installAGpsCert(const DerEncodedCertificate* pData, + size_t length, + uint32_t slotBitMask); inline virtual void setInSession(bool inSession) {} /*Values for lock diff --git a/core/gps_extended_c.h b/core/gps_extended_c.h index d4a7dbea..20b7c406 100644 --- a/core/gps_extended_c.h +++ b/core/gps_extended_c.h @@ -68,6 +68,9 @@ extern "C" { /*Emergency SUPL*/ #define GPS_NI_TYPE_EMERGENCY_SUPL 4 +#define AGPS_CERTIFICATE_MAX_LENGTH 2000 +#define AGPS_CERTIFICATE_MAX_SLOTS 10 + typedef struct { /** set to sizeof(UlpLocation) */ size_t size; diff --git a/etc/gps.conf b/etc/gps.conf index 5a2a1761..678cbab1 100644 --- a/etc/gps.conf +++ b/etc/gps.conf @@ -64,6 +64,14 @@ CAPABILITIES=0x37 # C2K_HOST=c2k.pde.com or IP # C2K_PORT=1234 +# Bitmask of slots that are available +# for write/install to, where 1s indicate writable, +# and the default value is 0 where no slots +# are writable. For example, AGPS_CERT_WRITABLE_MASK +# of b1000001010 makes 3 slots available +# and the remaining 7 slots unwritable. +#AGPS_CERT_WRITABLE_MASK=0 + #################################### # LTE Positioning Profile Settings #################################### diff --git a/loc_api/libloc_api_50001/LocEngAdapter.h b/loc_api/libloc_api_50001/LocEngAdapter.h index a2170ad6..34d6d04e 100644 --- a/loc_api/libloc_api_50001/LocEngAdapter.h +++ b/loc_api/libloc_api_50001/LocEngAdapter.h @@ -257,6 +257,12 @@ public: return mLocApi->getBestAvailableZppFix(zppLoc, tech_mask); } enum loc_api_adapter_err setXtraVersionCheck(int check); + inline virtual void installAGpsCert(const DerEncodedCertificate* pData, + size_t length, + uint32_t slotBitMask) + { + mLocApi->installAGpsCert(pData, length, slotBitMask); + } virtual void handleEngineDownEvent(); virtual void handleEngineUpEvent(); virtual void reportPosition(UlpLocation &location, diff --git a/loc_api/libloc_api_50001/loc.cpp b/loc_api/libloc_api_50001/loc.cpp index f9a2133a..0b3c943d 100644 --- a/loc_api/libloc_api_50001/loc.cpp +++ b/loc_api/libloc_api_50001/loc.cpp @@ -148,6 +148,18 @@ static const AGpsRilInterface sLocEngAGpsRilInterface = loc_agps_ril_update_network_availability }; +static int loc_agps_install_certificates(const DerEncodedCertificate* certificates, + size_t length); +static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* fingerprints, + size_t length); + +static const SuplCertificateInterface sLocEngAGpsCertInterface = +{ + sizeof(SuplCertificateInterface), + loc_agps_install_certificates, + loc_agps_revoke_certificates +}; + static loc_eng_data_s_type loc_afw_data; static int gss_fd = -1; @@ -658,6 +670,10 @@ const void* loc_get_extension(const char* name) ret_val = get_geofence_interface(); } } + else if (strcmp(name, SUPL_CERTIFICATE_INTERFACE) == 0) + { + ret_val = &sLocEngAGpsCertInterface; + } else { LOC_LOGE ("get_extension: Invalid interface passed in\n"); @@ -938,6 +954,24 @@ static void loc_agps_ril_update_network_availability(int available, const char* EXIT_LOG(%s, VOID_RET); } +static int loc_agps_install_certificates(const DerEncodedCertificate* certificates, + size_t length) +{ + ENTRY_LOG(); + int ret_val = loc_eng_agps_install_certificates(loc_afw_data, certificates, length); + EXIT_LOG(%d, ret_val); + return ret_val; +} +static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* fingerprints, + size_t length) +{ + ENTRY_LOG(); + LOC_LOGE("%s:%d]: agps_revoke_certificates not supported"); + int ret_val = AGPS_CERTIFICATE_ERROR_GENERIC; + EXIT_LOG(%d, ret_val); + return ret_val; +} + static void local_loc_cb(UlpLocation* location, void* locExt) { ENTRY_LOG(); diff --git a/loc_api/libloc_api_50001/loc_eng.cpp b/loc_api/libloc_api_50001/loc_eng.cpp index 320a61d8..fc3121ab 100644 --- a/loc_api/libloc_api_50001/loc_eng.cpp +++ b/loc_api/libloc_api_50001/loc_eng.cpp @@ -119,6 +119,7 @@ static loc_param_s_type loc_parameter_table[] = {"A_GLONASS_POS_PROTOCOL_SELECT", &gps_conf.A_GLONASS_POS_PROTOCOL_SELECT, NULL, 'n'}, {"SENSOR_PROVIDER", &sap_conf.SENSOR_PROVIDER, NULL, 'n'}, {"XTRA_VERSION_CHECK", &gps_conf.XTRA_VERSION_CHECK, NULL, 'n'}, + {"AGPS_CERT_WRITABLE_MASK", &gps_conf.AGPS_CERT_WRITABLE_MASK, NULL, 'n'} }; static void loc_default_parameters(void) @@ -162,6 +163,9 @@ static void loc_default_parameters(void) sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0; /* default provider is SSC */ sap_conf.SENSOR_PROVIDER = 1; + + /* None of the 10 slots for agps certificates are writable by default */ + gps_conf.AGPS_CERT_WRITABLE_MASK = 0; } // 2nd half of init(), singled out for @@ -1476,6 +1480,51 @@ struct LocEngDataClientInit : public LocMsg { } }; +struct LocEngInstallAGpsCert : public LocMsg { + LocEngAdapter* mpAdapter; + const size_t mNumberOfCerts; + const uint32_t mSlotBitMask; + DerEncodedCertificate* mpData; + inline LocEngInstallAGpsCert(LocEngAdapter* adapter, + const DerEncodedCertificate* pData, + size_t numberOfCerts, + uint32_t slotBitMask) : + LocMsg(), mpAdapter(adapter), + mNumberOfCerts(numberOfCerts), mSlotBitMask(slotBitMask), + mpData(new DerEncodedCertificate[mNumberOfCerts]) + { + for (int i=0; i < mNumberOfCerts; i++) { + mpData[i].data = new u_char[pData[i].length]; + if (mpData[i].data) { + memcpy(mpData[i].data, (void*)pData[i].data, pData[i].length); + mpData[i].length = pData[i].length; + } else { + LOC_LOGE("malloc failed for cert#%d", i); + break; + } + } + locallog(); + } + inline ~LocEngInstallAGpsCert() + { + for (int i=0; i < mNumberOfCerts; i++) { + if (mpData[i].data) { + delete[] mpData[i].data; + } + } + delete[] mpData; + } + inline virtual void proc() const { + mpAdapter->installAGpsCert(mpData, mNumberOfCerts, mSlotBitMask); + } + inline void locallog() const { + LOC_LOGV("LocEngInstallAGpsCert - certs=%u mask=%u", + mNumberOfCerts, mSlotBitMask); + } + inline virtual void log() const { + locallog(); + } +}; /********************************************************************* * Initialization checking macros @@ -2446,6 +2495,57 @@ void loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type &loc_eng_d EXIT_LOG(%s, VOID_RET); } +int loc_eng_agps_install_certificates(loc_eng_data_s_type &loc_eng_data, + const DerEncodedCertificate* certificates, + size_t numberOfCerts) +{ + ENTRY_LOG_CALLFLOW(); + int ret_val = AGPS_CERTIFICATE_OPERATION_SUCCESS; + + uint32_t slotBitMask = gps_conf.AGPS_CERT_WRITABLE_MASK; + uint32_t slotCount = 0; + for (uint32_t slotBitMaskCounter=slotBitMask; slotBitMaskCounter; slotCount++) { + slotBitMaskCounter &= slotBitMaskCounter - 1; + } + LOC_LOGD("SlotBitMask=%u SlotCount=%u NumberOfCerts=%u", + slotBitMask, slotCount, numberOfCerts); + + LocEngAdapter* adapter = loc_eng_data.adapter; + + if (numberOfCerts == 0) { + LOC_LOGE("No certs to install, since numberOfCerts is zero"); + ret_val = AGPS_CERTIFICATE_OPERATION_SUCCESS; + } else if (!adapter) { + LOC_LOGE("adapter is null!"); + ret_val = AGPS_CERTIFICATE_ERROR_GENERIC; + } else if (slotCount < numberOfCerts) { + LOC_LOGE("Not enough cert slots (%u) to install %u certs!", + slotCount, numberOfCerts); + ret_val = AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES; + } else { + for (int i=0; i < numberOfCerts; ++i) + { + if (certificates[i].length > AGPS_CERTIFICATE_MAX_LENGTH) { + LOC_LOGE("cert#(%u) length of %u is too big! greater than %u", + certificates[i].length, AGPS_CERTIFICATE_MAX_LENGTH); + ret_val = AGPS_CERTIFICATE_ERROR_GENERIC; + break; + } + } + + if (ret_val == AGPS_CERTIFICATE_OPERATION_SUCCESS) { + adapter->sendMsg(new LocEngInstallAGpsCert(adapter, + certificates, + numberOfCerts, + slotBitMask)); + } + } + + EXIT_LOG(%d, ret_val); + return ret_val; +} + + /*=========================================================================== FUNCTION loc_eng_report_status diff --git a/loc_api/libloc_api_50001/loc_eng.h b/loc_api/libloc_api_50001/loc_eng.h index 109d02d3..99364cd3 100644 --- a/loc_api/libloc_api_50001/loc_eng.h +++ b/loc_api/libloc_api_50001/loc_eng.h @@ -147,6 +147,7 @@ typedef struct loc_gps_cfg_s uint8_t NMEA_PROVIDER; unsigned long A_GLONASS_POS_PROTOCOL_SELECT; unsigned long XTRA_VERSION_CHECK; + unsigned long AGPS_CERT_WRITABLE_MASK; } loc_gps_cfg_s_type; typedef struct @@ -210,9 +211,11 @@ int loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType, const char* apn, AGpsBearerType bearerType); int loc_eng_agps_closed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType); int loc_eng_agps_open_failed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType); - void loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type &loc_eng_data, int avaiable, const char* apn); +int loc_eng_agps_install_certificates(loc_eng_data_s_type &loc_eng_data, + const DerEncodedCertificate* certificates, + size_t length); //loc_eng_xtra functions int loc_eng_xtra_init (loc_eng_data_s_type &loc_eng_data, @@ -231,6 +234,7 @@ extern void loc_eng_ni_request_handler(loc_eng_data_s_type &loc_eng_data, const GpsNiNotification *notif, const void* passThrough); extern void loc_eng_ni_reset_on_engine_restart(loc_eng_data_s_type &loc_eng_data); + #ifdef __cplusplus } #endif /* __cplusplus */