Refactors with the lightest touch 💅
This commit is contained in:
parent
447a266432
commit
aa294b2710
1 changed files with 44 additions and 25 deletions
69
src/ax25.c
69
src/ax25.c
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <patty/ax25.h>
|
||||
|
||||
static ssize_t frame_decode_address(patty_ax25_address *address, void *data, off_t offset) {
|
||||
static ssize_t frame_decode_station(patty_ax25_address *address, void *data, off_t offset) {
|
||||
int i, space = 0;
|
||||
uint8_t ssid = ((uint8_t *)data + offset)[6];
|
||||
|
||||
|
@ -70,7 +70,7 @@ static ssize_t frame_decode_hops(patty_ax25_frame *frame, void *data, off_t star
|
|||
* frame.
|
||||
*/
|
||||
for (i=0; i<PATTY_AX25_MAX_HOPS; i++) {
|
||||
if ((decoded = frame_decode_address(&frame->repeaters[i], data, offset)) < 0) {
|
||||
if ((decoded = frame_decode_station(&frame->repeaters[i], data, offset)) < 0) {
|
||||
goto error;
|
||||
} else {
|
||||
offset += decoded;
|
||||
|
@ -101,6 +101,44 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static ssize_t frame_decode_address(patty_ax25_frame *frame, void *data, off_t start) {
|
||||
off_t offset = start;
|
||||
ssize_t decoded;
|
||||
|
||||
if ((decoded = frame_decode_station(&frame->dest, data, offset)) < 0) {
|
||||
goto error;
|
||||
} else {
|
||||
offset += decoded;
|
||||
}
|
||||
|
||||
/*
|
||||
* It would be considered erroneous if the destination address did have the
|
||||
* extension bit set to 1.
|
||||
*/
|
||||
if ((decoded = frame_decode_station(&frame->src, data, offset)) < 0) {
|
||||
goto error;
|
||||
} else {
|
||||
offset += decoded;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the source address is not the final address in the frame, begin
|
||||
* decoding repeater addresses.
|
||||
*/
|
||||
if (!frame->src.last) {
|
||||
if ((decoded = frame_decode_hops(frame, data, offset)) < 0) {
|
||||
goto error;
|
||||
} else {
|
||||
offset += decoded;
|
||||
}
|
||||
}
|
||||
|
||||
return offset - start;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static ssize_t frame_decode_payload(patty_ax25_frame *frame, void *data, off_t offset) {
|
||||
uint8_t control = ((uint8_t *)data + offset)[0];
|
||||
size_t decoded = 0;
|
||||
|
@ -160,34 +198,15 @@ int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) {
|
|||
|
||||
frame->size = size;
|
||||
|
||||
if ((decoded = frame_decode_address(&frame->dest, data, offset)) < 0) {
|
||||
/*
|
||||
* First, decode the variable-length Address field.
|
||||
*/
|
||||
if ((decoded = frame_decode_address(frame, data, offset)) < 0) {
|
||||
goto error_decode;
|
||||
} else {
|
||||
offset += decoded;
|
||||
}
|
||||
|
||||
/*
|
||||
* It would be considered erroneous if the destination address did have the
|
||||
* extension bit set to 1.
|
||||
*/
|
||||
if ((decoded = frame_decode_address(&frame->src, data, offset)) < 0) {
|
||||
goto error_decode;
|
||||
} else {
|
||||
offset += decoded;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the source address is not the final address in the frame, begin
|
||||
* decoding repeater addresses.
|
||||
*/
|
||||
if (!frame->src.last) {
|
||||
if ((decoded = frame_decode_hops(frame, data, offset)) < 0) {
|
||||
goto error_decode;
|
||||
} else {
|
||||
offset += decoded;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Now, decode the remaining Control Field, optional Protocol Identifier
|
||||
* field, and payload that may follow.
|
||||
|
|
Loading…
Add table
Reference in a new issue