diff options
author | Chris Kuethe <chris.kuethe@gmail.com> | 2009-07-16 22:22:05 +0000 |
---|---|---|
committer | Chris Kuethe <chris.kuethe@gmail.com> | 2009-07-16 22:22:05 +0000 |
commit | 5c69efcfba3dc218526cac5ce1d22a4832a8695b (patch) | |
tree | e4eccea86cc543f10c3e781f5af58f106f7d023c | |
parent | b7dd74582b7c7d6676e01653e2e1c6b7ae7ace6c (diff) | |
download | gpsd-5c69efcfba3dc218526cac5ce1d22a4832a8695b.tar.gz |
Make the oncore sniffer use the known lengths of packets.
This guards against finding 0x0d 0x0a somewhere in the payload. It can
happen, and does happen often enough to be annoying. From Hakan
Johansson on gpsd-dev
-rw-r--r-- | gpsd.h-tail | 2 | ||||
-rw-r--r-- | packet.c | 25 | ||||
-rw-r--r-- | packet_states.h | 12 |
3 files changed, 24 insertions, 15 deletions
diff --git a/gpsd.h-tail b/gpsd.h-tail index 75c868cc..20055009 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -111,6 +111,8 @@ extern void rtcm2_output_magnavox(isgps30bits_t *, FILE *); extern void rtcm3_unpack(/*@out@*/struct rtcm3_t *, char *); extern void rtcm3_dump(struct rtcm3_t *rtcm, FILE *); +extern ssize_t oncore_payload_length(unsigned char id1,unsigned char id2); + /* Next, declarations for the core library... */ /* factors for converting among confidence interval units */ @@ -554,23 +554,30 @@ static void nextstate(struct gps_packet_t *lexer, #endif /* SUPERSTAR2_ENABLE */ #ifdef ONCORE_ENABLE case ONCORE_AT2: - if (isupper(c)) + if (isupper(c)) { + lexer->length = c; lexer->state = ONCORE_ID1; - else + } else lexer->state = GROUND_STATE; break; case ONCORE_ID1: - if (isalpha(c)) - lexer->state = ONCORE_ID2; - else + if (isalpha(c)) { + lexer->length = + oncore_payload_length((unsigned char) lexer->length,c); + if ((ssize_t) lexer->length != -1) { + lexer->state = ONCORE_PAYLOAD; + break; + } + } lexer->state = GROUND_STATE; break; - case ONCORE_ID2: - lexer->state = ONCORE_PAYLOAD; - break; case ONCORE_PAYLOAD: + if (--lexer->length == 0) + lexer->state = ONCORE_CHECKSUM; + break; + case ONCORE_CHECKSUM: if (c != '\r') - lexer->state = ONCORE_PAYLOAD; + lexer->state = GROUND_STATE; else lexer->state = ONCORE_CR; break; diff --git a/packet_states.h b/packet_states.h index 72a57fa6..99845b51 100644 --- a/packet_states.h +++ b/packet_states.h @@ -126,12 +126,12 @@ #endif #ifdef ONCORE_ENABLE - ONCORE_AT2, /* second @ */ - ONCORE_ID1, /* first character of command type */ - ONCORE_ID2, /* second character of command type */ - ONCORE_PAYLOAD, - ONCORE_CR, /* closing CR */ - ONCORE_RECOGNIZED, /* closing LF */ + ONCORE_AT2, /* second @ */ + ONCORE_ID1, /* first character of command type */ + ONCORE_PAYLOAD, /* payload eating */ + ONCORE_CHECKSUM, /* checksum byte */ + ONCORE_CR, /* closing CR */ + ONCORE_RECOGNIZED, /* closing LF */ #endif |