Getting there

This commit is contained in:
XANTRONIX Development 2020-05-27 00:22:50 -04:00 committed by XANTRONIX Industrial
parent 9217b0366f
commit 663965db71
2 changed files with 28 additions and 11 deletions

View file

@ -136,7 +136,6 @@ error_io:
int main(int argc, char **argv) {
patty_kiss_tnc *tnc;
ssize_t len;
void *data;
int port;
@ -150,9 +149,18 @@ int main(int argc, char **argv) {
goto error_kiss_tnc_open;
}
while ((len = patty_kiss_tnc_recv(tnc, &data, &port)) > 0) {
while (1) {
ssize_t len;
patty_ax25_frame frame;
if ((len = patty_kiss_tnc_recv(tnc, &data, &port)) < 0) {
perror("Unable to read frame");
goto error_ax25_frame_read;
} else if (len == 0) {
break;
}
if (patty_ax25_frame_decode(&frame, data, len) < 0) {
perror("Unable to decode frame");
@ -172,6 +180,7 @@ int main(int argc, char **argv) {
error_frame_fprint:
error_ax25_frame_decode:
error_ax25_frame_read:
patty_kiss_tnc_close(tnc);
error_kiss_tnc_open:

View file

@ -121,17 +121,23 @@ ssize_t patty_kiss_tnc_decode(patty_kiss_tnc *tnc, void *frame, size_t *len, int
for (i=0, b=0; i<tnc->buflen; i++) {
uint8_t c = ((uint8_t *)tnc->buf)[i];
/*
* If the first byte is not a frame end, then that's a bad thing.
*/
if (i == 0 && c != PATTY_KISS_FEND) {
errno = EIO;
if (i == 0) {
if (c != PATTY_KISS_FEND) {
/*
* If the first byte is not a frame end, then that's a bad thing.
*/
errno = EIO;
goto error_io;
}
goto error_io;
}
} else if (i == 1) {
if (PATTY_KISS_COMMAND(c) != PATTY_KISS_DATA) {
errno = EIO;
if (i == 1 && (c & 0x0f) == 0) {
*port = (c & 0xf0) >> 4;
goto error_io;
}
*port = PATTY_KISS_COMMAND_PORT(c);
continue;
}
@ -242,6 +248,8 @@ ssize_t patty_kiss_tnc_recv(patty_kiss_tnc *tnc, void **frame, int *port) {
* Try to decode the TNC buffer into the frame.
*/
if ((decoded = patty_kiss_tnc_decode(tnc, tnc->frame, &framelen, port)) < 0) {
patty_kiss_tnc_drop(tnc);
goto error_io;
}