summaryrefslogtreecommitdiff
path: root/libgpsd_core.c
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2018-07-14 13:53:30 -0700
committerGary E. Miller <gem@rellim.com>2018-07-14 14:02:23 -0700
commitf8aa971c9b806f19619b4d934a51c360e55101d7 (patch)
tree2fbed569a621204886f9a2650b3dad97d7dccb3d /libgpsd_core.c
parentf31b7c700aad5861fed7af796d1bed90168a6396 (diff)
downloadgpsd-f8aa971c9b806f19619b4d934a51c360e55101d7.tar.gz
libgpsd_core.c: Better initial sanitization of skyview[]
Thanks to Virgin Orbit for their support on this patch.
Diffstat (limited to 'libgpsd_core.c')
-rw-r--r--libgpsd_core.c60
1 files changed, 44 insertions, 16 deletions
diff --git a/libgpsd_core.c b/libgpsd_core.c
index 38a7d714..3678a850 100644
--- a/libgpsd_core.c
+++ b/libgpsd_core.c
@@ -724,22 +724,37 @@ static gps_mask_t fill_dop(const struct gpsd_errout_t *errout,
memset(satpos, 0, sizeof(satpos));
for (n = k = 0; k < gpsdata->satellites_visible; k++) {
- if (gpsdata->skyview[k].used && !SBAS_PRN(gpsdata->skyview[k].PRN))
- {
- const struct satellite_t *sp = &gpsdata->skyview[k];
- satpos[n][0] = sin(sp->azimuth * DEG_2_RAD)
- * cos(sp->elevation * DEG_2_RAD);
- satpos[n][1] = cos(sp->azimuth * DEG_2_RAD)
- * cos(sp->elevation * DEG_2_RAD);
- satpos[n][2] = sin(sp->elevation * DEG_2_RAD);
- satpos[n][3] = 1;
- gpsd_log(errout, LOG_INF, "PRN=%3d az=%3d el=%2d (%f, %f, %f)\n",
- gpsdata->skyview[k].PRN,
- gpsdata->skyview[k].azimuth,
- gpsdata->skyview[k].elevation,
- satpos[n][0], satpos[n][1], satpos[n][2]);
- n++;
- }
+ if (!gpsdata->skyview[k].used) {
+ /* skip unused sats */
+ continue;
+ }
+ if (1 > gpsdata->skyview[k].PRN || SBAS_PRN(gpsdata->skyview[k].PRN)) {
+ /* skip bad PRN, skip SBAS sats */
+ continue;
+ }
+ if (0 > gpsdata->skyview[k].azimuth ||
+ 359 < gpsdata->skyview[k].azimuth) {
+ /* skip bad azimuth */
+ continue;
+ }
+ if (-90 > gpsdata->skyview[k].elevation ||
+ 90 < gpsdata->skyview[k].elevation) {
+ /* skip bad elevation */
+ continue;
+ }
+ const struct satellite_t *sp = &gpsdata->skyview[k];
+ satpos[n][0] = sin(sp->azimuth * DEG_2_RAD)
+ * cos(sp->elevation * DEG_2_RAD);
+ satpos[n][1] = cos(sp->azimuth * DEG_2_RAD)
+ * cos(sp->elevation * DEG_2_RAD);
+ satpos[n][2] = sin(sp->elevation * DEG_2_RAD);
+ satpos[n][3] = 1;
+ gpsd_log(errout, LOG_INF, "PRN=%3d az=%3d el=%2d (%f, %f, %f)\n",
+ gpsdata->skyview[k].PRN,
+ gpsdata->skyview[k].azimuth,
+ gpsdata->skyview[k].elevation,
+ satpos[n][0], satpos[n][1], satpos[n][2]);
+ n++;
}
/* can't use gpsdata->satellites_used as that is a counter for xxGSA,
* and gets cleared at odd times */
@@ -1479,6 +1494,10 @@ gps_mask_t gpsd_poll(struct gps_device_t *session)
return session->gpsdata.set;
}
+ /* Should never get here */
+ gpsd_log(&session->context->errout, LOG_EMERG,
+ "fell out of gps_poll()!\n");
+ return 0;
}
int gpsd_multipoll(const bool data_ready,
@@ -1640,8 +1659,17 @@ void gpsd_wrap(struct gps_device_t *session)
void gpsd_zero_satellites( struct gps_data_t *out)
{
+ int sat;
+
(void)memset(out->skyview, '\0', sizeof(out->skyview));
out->satellites_visible = 0;
+ /* zero is good inbound data for ss, elevation, and azimuth. */
+ /* we need to set them to invalid values */
+ for ( sat = 0; sat < MAXCHANNELS; sat++ ) {
+ out->skyview[sat].azimuth = -1;
+ out->skyview[sat].elevation = -91;
+ out->skyview[sat].ss = -1.0;
+ }
#if 0
/*
* We used to clear DOPs here, but this causes misbehavior on some