summaryrefslogtreecommitdiff
path: root/loc_api
diff options
context:
space:
mode:
authorDante Russo <drusso@codeaurora.org>2014-07-25 15:15:52 -0700
committerVineeta Srivastava <vsrivastava@google.com>2014-08-01 07:58:54 +0000
commit1d4940024c54e7d1e63f73edd5054a18a7a01b63 (patch)
tree191ff9ce67d383620a4b2587a2846f3b980696c2 /loc_api
parent33627a403843dfa40837e800663475cba345a044 (diff)
downloadgps-1d4940024c54e7d1e63f73edd5054a18a7a01b63.tar.gz
Agps Cert Install Api Implementation
Implementation of the install agps certificate API for installing certificates at runtime. Also add a field in gps.conf for cert writable properties. bug: 16633052 Change-Id: I49239b612381e81bd8a4c0a5773783572d4b2d9a
Diffstat (limited to 'loc_api')
-rw-r--r--loc_api/libloc_api_50001/LocEngAdapter.h7
-rw-r--r--loc_api/libloc_api_50001/loc.cpp34
-rw-r--r--loc_api/libloc_api_50001/loc_eng.cpp100
-rw-r--r--loc_api/libloc_api_50001/loc_eng.h5
4 files changed, 146 insertions, 0 deletions
diff --git a/loc_api/libloc_api_50001/LocEngAdapter.h b/loc_api/libloc_api_50001/LocEngAdapter.h
index 93f3dc2..484193c 100644
--- a/loc_api/libloc_api_50001/LocEngAdapter.h
+++ b/loc_api/libloc_api_50001/LocEngAdapter.h
@@ -257,6 +257,13 @@ public:
return mLocApi->getBestAvailableZppFix(zppLoc, tech_mask);
}
+ 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 36171f3..c753626 100644
--- a/loc_api/libloc_api_50001/loc.cpp
+++ b/loc_api/libloc_api_50001/loc.cpp
@@ -151,6 +151,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;
@@ -691,6 +703,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");
@@ -971,6 +987,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("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 1e53672..6f4ee70 100644
--- a/loc_api/libloc_api_50001/loc_eng.cpp
+++ b/loc_api/libloc_api_50001/loc_eng.cpp
@@ -118,6 +118,7 @@ static loc_param_s_type loc_parameter_table[] =
{"LPP_PROFILE", &gps_conf.LPP_PROFILE, NULL, 'n'},
{"A_GLONASS_POS_PROTOCOL_SELECT", &gps_conf.A_GLONASS_POS_PROTOCOL_SELECT, NULL, 'n'},
{"SENSOR_PROVIDER", &sap_conf.SENSOR_PROVIDER, NULL, 'n'},
+ {"AGPS_CERT_WRITABLE_MASK", &gps_conf.AGPS_CERT_WRITABLE_MASK, NULL, 'n'},
};
static void loc_default_parameters(void)
@@ -163,6 +164,9 @@ static void loc_default_parameters(void)
/* 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
@@ -1477,6 +1481,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
@@ -2449,6 +2498,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 ff787da..fcca9ba 100644
--- a/loc_api/libloc_api_50001/loc_eng.h
+++ b/loc_api/libloc_api_50001/loc_eng.h
@@ -146,6 +146,7 @@ typedef struct loc_gps_cfg_s
unsigned long LPP_PROFILE;
uint8_t NMEA_PROVIDER;
unsigned long A_GLONASS_POS_PROTOCOL_SELECT;
+ unsigned long AGPS_CERT_WRITABLE_MASK;
} loc_gps_cfg_s_type;
typedef struct
@@ -235,6 +236,10 @@ extern void loc_eng_ni_request_handler(loc_eng_data_s_type &loc_eng_data,
extern void loc_eng_ni_reset_on_engine_restart(loc_eng_data_s_type &loc_eng_data);
int loc_eng_read_config(void);
+int loc_eng_agps_install_certificates(loc_eng_data_s_type &loc_eng_data,
+ const DerEncodedCertificate* certificates,
+ size_t length);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */