Rename things more in line with official AX.25 spec
This commit is contained in:
parent
c3667b08a1
commit
7188a5f194
3 changed files with 29 additions and 30 deletions
|
@ -24,8 +24,7 @@ typedef struct _patty_ax25_frame {
|
||||||
patty_ax25_address src;
|
patty_ax25_address src;
|
||||||
patty_ax25_address repeaters[7];
|
patty_ax25_address repeaters[7];
|
||||||
|
|
||||||
int hops,
|
uint8_t hops;
|
||||||
repeated;
|
|
||||||
|
|
||||||
enum patty_ax25_version version;
|
enum patty_ax25_version version;
|
||||||
enum patty_ax25_frame_type type;
|
enum patty_ax25_frame_type type;
|
||||||
|
@ -34,14 +33,15 @@ typedef struct _patty_ax25_frame {
|
||||||
uint16_t control;
|
uint16_t control;
|
||||||
uint8_t proto;
|
uint8_t proto;
|
||||||
|
|
||||||
void * payload;
|
void *info;
|
||||||
size_t payloadsz;
|
size_t len;
|
||||||
|
|
||||||
size_t size;
|
|
||||||
} patty_ax25_frame;
|
} patty_ax25_frame;
|
||||||
|
|
||||||
int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t len);
|
ssize_t patty_ax25_frame_decode(patty_ax25_frame *frame,
|
||||||
|
void *data,
|
||||||
|
size_t len);
|
||||||
|
|
||||||
int patty_ax25_frame_payload(patty_ax25_frame *frame, void **data, size_t *len);
|
ssize_t patty_ax25_frame_info(patty_ax25_frame *frame,
|
||||||
|
void **info);
|
||||||
|
|
||||||
#endif /* _PATTY_AX25_FRAME_H */
|
#endif /* _PATTY_AX25_FRAME_H */
|
||||||
|
|
|
@ -112,16 +112,16 @@ static int frame_fprint(FILE *stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frame->type == PATTY_AX25_FRAME_INFO) {
|
if (frame->type == PATTY_AX25_FRAME_INFO) {
|
||||||
if (fprintf(stream, " type I poll %d ns %d nr %d payload %zu",
|
if (fprintf(stream, " type I poll %d ns %d nr %d info %zu",
|
||||||
PATTY_AX25_CONTROL_POLL(frame->control),
|
PATTY_AX25_CONTROL_POLL(frame->control),
|
||||||
PATTY_AX25_CONTROL_SEQ_SEND(frame->control),
|
PATTY_AX25_CONTROL_SEQ_SEND(frame->control),
|
||||||
PATTY_AX25_CONTROL_SEQ_RECV(frame->control),
|
PATTY_AX25_CONTROL_SEQ_RECV(frame->control),
|
||||||
frame->payloadsz) < 0) {
|
frame->len) < 0) {
|
||||||
goto error_io;
|
goto error_io;
|
||||||
}
|
}
|
||||||
} else if (frame->type == PATTY_AX25_FRAME_UNNUMBERED) {
|
} else if (frame->type == PATTY_AX25_FRAME_UNNUMBERED) {
|
||||||
if (fprintf(stream, " type U payload %zu",
|
if (fprintf(stream, " type U info %zu",
|
||||||
frame->payloadsz) < 0) {
|
frame->len) < 0) {
|
||||||
goto error_io;
|
goto error_io;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
33
src/frame.c
33
src/frame.c
|
@ -81,8 +81,6 @@ static ssize_t decode_hops(patty_ax25_frame *frame,
|
||||||
frame->hops++;
|
frame->hops++;
|
||||||
|
|
||||||
if (frame->repeaters[i].last) {
|
if (frame->repeaters[i].last) {
|
||||||
frame->repeated = frame->repeaters[i].repeated;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,9 +151,10 @@ error:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t decode_payload(patty_ax25_frame *frame,
|
static ssize_t decode_info(patty_ax25_frame *frame,
|
||||||
void *data,
|
void *data,
|
||||||
off_t offset) {
|
off_t offset,
|
||||||
|
size_t size) {
|
||||||
uint8_t control = ((uint8_t *)data + offset)[0];
|
uint8_t control = ((uint8_t *)data + offset)[0];
|
||||||
size_t decoded = 0;
|
size_t decoded = 0;
|
||||||
|
|
||||||
|
@ -194,10 +193,10 @@ static ssize_t decode_payload(patty_ax25_frame *frame,
|
||||||
decoded++;
|
decoded++;
|
||||||
|
|
||||||
frame->proto = ((uint8_t *)data + offset)[1];
|
frame->proto = ((uint8_t *)data + offset)[1];
|
||||||
frame->payload = (void *)((uint8_t *)data + offset + decoded);
|
frame->info = (void *)((uint8_t *)data + offset + decoded);
|
||||||
frame->payloadsz = frame->size - offset - decoded;
|
frame->len = size - offset - decoded;
|
||||||
|
|
||||||
decoded += frame->payloadsz;
|
decoded += frame->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
return decoded;
|
return decoded;
|
||||||
|
@ -206,14 +205,14 @@ error:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) {
|
ssize_t patty_ax25_frame_decode(patty_ax25_frame *frame,
|
||||||
|
void *data,
|
||||||
|
size_t size) {
|
||||||
ssize_t decoded;
|
ssize_t decoded;
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
|
|
||||||
memset(frame, '\0', sizeof(*frame));
|
memset(frame, '\0', sizeof(*frame));
|
||||||
|
|
||||||
frame->size = size;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First, decode the variable-length Address field.
|
* First, decode the variable-length Address field.
|
||||||
*/
|
*/
|
||||||
|
@ -227,9 +226,9 @@ int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Next, decode the remaining Control Field, optional Protocol Identifier
|
* Next, decode the remaining Control Field, optional Protocol Identifier
|
||||||
* field, and payload that may follow.
|
* field, and Info payload that may follow.
|
||||||
*/
|
*/
|
||||||
if ((decoded = decode_payload(frame, data, offset)) < 0) {
|
if ((decoded = decode_info(frame, data, offset, size)) < 0) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
|
|
||||||
goto error_decode;
|
goto error_decode;
|
||||||
|
@ -243,17 +242,17 @@ error_decode:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int patty_ax25_frame_payload(patty_ax25_frame *frame, void **data, size_t *len) {
|
ssize_t patty_ax25_frame_info(patty_ax25_frame *frame,
|
||||||
if (frame == NULL || frame->payload == NULL || data == NULL || len == NULL) {
|
void **info) {
|
||||||
|
if (frame == NULL || frame->info == NULL || info == NULL) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
|
|
||||||
goto error_invalid_args;
|
goto error_invalid_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
*data = frame->payload;
|
*info = frame->info;
|
||||||
*len = frame->payloadsz;
|
|
||||||
|
|
||||||
return 0;
|
return frame->len;
|
||||||
|
|
||||||
error_invalid_args:
|
error_invalid_args:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue