Getting there
This commit is contained in:
parent
9217b0366f
commit
663965db71
2 changed files with 28 additions and 11 deletions
13
src/decode.c
13
src/decode.c
|
@ -136,7 +136,6 @@ error_io:
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
patty_kiss_tnc *tnc;
|
patty_kiss_tnc *tnc;
|
||||||
ssize_t len;
|
|
||||||
void *data;
|
void *data;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
|
@ -150,9 +149,18 @@ int main(int argc, char **argv) {
|
||||||
goto error_kiss_tnc_open;
|
goto error_kiss_tnc_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((len = patty_kiss_tnc_recv(tnc, &data, &port)) > 0) {
|
while (1) {
|
||||||
|
ssize_t len;
|
||||||
patty_ax25_frame frame;
|
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) {
|
if (patty_ax25_frame_decode(&frame, data, len) < 0) {
|
||||||
perror("Unable to decode frame");
|
perror("Unable to decode frame");
|
||||||
|
|
||||||
|
@ -172,6 +180,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
error_frame_fprint:
|
error_frame_fprint:
|
||||||
error_ax25_frame_decode:
|
error_ax25_frame_decode:
|
||||||
|
error_ax25_frame_read:
|
||||||
patty_kiss_tnc_close(tnc);
|
patty_kiss_tnc_close(tnc);
|
||||||
|
|
||||||
error_kiss_tnc_open:
|
error_kiss_tnc_open:
|
||||||
|
|
26
src/kiss.c
26
src/kiss.c
|
@ -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++) {
|
for (i=0, b=0; i<tnc->buflen; i++) {
|
||||||
uint8_t c = ((uint8_t *)tnc->buf)[i];
|
uint8_t c = ((uint8_t *)tnc->buf)[i];
|
||||||
|
|
||||||
/*
|
if (i == 0) {
|
||||||
* If the first byte is not a frame end, then that's a bad thing.
|
if (c != PATTY_KISS_FEND) {
|
||||||
*/
|
/*
|
||||||
if (i == 0 && c != PATTY_KISS_FEND) {
|
* If the first byte is not a frame end, then that's a bad thing.
|
||||||
errno = EIO;
|
*/
|
||||||
|
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) {
|
goto error_io;
|
||||||
*port = (c & 0xf0) >> 4;
|
}
|
||||||
|
|
||||||
|
*port = PATTY_KISS_COMMAND_PORT(c);
|
||||||
|
|
||||||
continue;
|
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.
|
* Try to decode the TNC buffer into the frame.
|
||||||
*/
|
*/
|
||||||
if ((decoded = patty_kiss_tnc_decode(tnc, tnc->frame, &framelen, port)) < 0) {
|
if ((decoded = patty_kiss_tnc_decode(tnc, tnc->frame, &framelen, port)) < 0) {
|
||||||
|
patty_kiss_tnc_drop(tnc);
|
||||||
|
|
||||||
goto error_io;
|
goto error_io;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue