diff --git a/include/patty/ax25.h b/include/patty/ax25.h index fc82de8..87f5623 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -29,8 +29,15 @@ enum patty_ax25_sock_status { PATTY_AX25_SOCK_ESTABLISHED }; +enum patty_ax25_sock_mode { + PATTY_AX25_SOCK_DM, + PATTY_AX25_SOCK_SABM, + PATTY_AX25_SOCK_SABME +}; + typedef struct _patty_ax25_sock { enum patty_ax25_sock_status status; + enum patty_ax25_sock_mode mode; time_t timer_ack; time_t timer_response; diff --git a/include/patty/ax25/frame.h b/include/patty/ax25/frame.h index 7e93bf5..bd62e4a 100644 --- a/include/patty/ax25/frame.h +++ b/include/patty/ax25/frame.h @@ -19,11 +19,16 @@ enum patty_ax25_frame_cr { PATTY_AX25_FRAME_RESPONSE }; +enum patty_ax25_frame_format { + PATTY_AX25_FRAME_NORMAL = 0, + PATTY_AX25_FRAME_EXTENDED = 1 +}; + typedef struct _patty_ax25_frame { patty_ax25_address dest; patty_ax25_address src; patty_ax25_address repeaters[8]; - + int hops; int repeated; @@ -31,8 +36,8 @@ typedef struct _patty_ax25_frame { enum patty_ax25_frame_type type; enum patty_ax25_frame_cr cr; - uint8_t control; - uint8_t proto; + uint16_t control; + uint8_t proto; void * payload; size_t payloadsz; @@ -40,6 +45,7 @@ typedef struct _patty_ax25_frame { size_t size; } patty_ax25_frame; -int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t len); +int patty_ax25_frame_decode(patty_ax25_frame *frame, + void *data, size_t len, enum patty_ax25_frame_format format); #endif /* _PATTY_AX25_FRAME_H */ diff --git a/src/ax25.c b/src/ax25.c index a7ccc71..ff0ab4a 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -77,6 +77,7 @@ static void sock_init(patty_ax25_sock *sock) { memset(sock, '\0', sizeof(*sock)); sock->status = PATTY_AX25_SOCK_OPEN; + sock->mode = PATTY_AX25_SOCK_DM; sock->n_maxlen = PATTY_AX25_FRAME_DEFAULT_MAXLEN; sock->n_window = PATTY_AX25_FRAME_DEFAULT_WINDOW; } diff --git a/src/frame.c b/src/frame.c index ad149a1..9d5b61e 100644 --- a/src/frame.c +++ b/src/frame.c @@ -3,7 +3,7 @@ #include -static ssize_t frame_decode_station(patty_ax25_address *address, void *data, off_t offset) { +static ssize_t frame_decode_station(patty_ax25_address *address, void *data, off_t offset, enum patty_ax25_frame_format format) { int i, space = 0; uint8_t ssid = ((uint8_t *)data + offset)[6]; @@ -59,7 +59,7 @@ error: return -1; } -static ssize_t frame_decode_hops(patty_ax25_frame *frame, void *data, off_t start) { +static ssize_t frame_decode_hops(patty_ax25_frame *frame, void *data, off_t start, enum patty_ax25_frame_format format) { ssize_t decoded; off_t offset = start; @@ -70,7 +70,7 @@ static ssize_t frame_decode_hops(patty_ax25_frame *frame, void *data, off_t star * frame. */ for (i=0; irepeaters[i], data, offset)) < 0) { + if ((decoded = frame_decode_station(&frame->repeaters[i], data, offset, format)) < 0) { goto error; } else { offset += decoded; @@ -101,11 +101,11 @@ error: return -1; } -static ssize_t frame_decode_address(patty_ax25_frame *frame, void *data, off_t start) { +static ssize_t frame_decode_address(patty_ax25_frame *frame, void *data, off_t start, enum patty_ax25_frame_format format) { off_t offset = start; ssize_t decoded; - if ((decoded = frame_decode_station(&frame->dest, data, offset)) < 0) { + if ((decoded = frame_decode_station(&frame->dest, data, offset, format)) < 0) { goto error; } else { offset += decoded; @@ -115,7 +115,7 @@ static ssize_t frame_decode_address(patty_ax25_frame *frame, void *data, off_t s * 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) { + if ((decoded = frame_decode_station(&frame->src, data, offset, format)) < 0) { goto error; } else { offset += decoded; @@ -140,7 +140,7 @@ static ssize_t frame_decode_address(patty_ax25_frame *frame, void *data, off_t s * decoding repeater addresses. */ if (!frame->src.last) { - if ((decoded = frame_decode_hops(frame, data, offset)) < 0) { + if ((decoded = frame_decode_hops(frame, data, offset, format)) < 0) { goto error; } else { offset += decoded; @@ -153,7 +153,7 @@ error: return -1; } -static ssize_t frame_decode_payload(patty_ax25_frame *frame, void *data, off_t offset) { +static ssize_t frame_decode_payload(patty_ax25_frame *frame, void *data, off_t offset, enum patty_ax25_frame_format format) { uint8_t control = ((uint8_t *)data + offset)[0]; size_t decoded = 0; @@ -204,7 +204,7 @@ error: return -1; } -int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) { +int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size, enum patty_ax25_frame_format format) { ssize_t decoded; off_t offset = 0; @@ -215,7 +215,7 @@ int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) { /* * First, decode the variable-length Address field. */ - if ((decoded = frame_decode_address(frame, data, offset)) < 0) { + if ((decoded = frame_decode_address(frame, data, offset, format)) < 0) { goto error_decode; } else { offset += decoded; @@ -225,7 +225,7 @@ int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) { * Now, decode the remaining Control Field, optional Protocol Identifier * field, and payload that may follow. */ - if ((decoded = frame_decode_payload(frame, data, offset)) < 0) { + if ((decoded = frame_decode_payload(frame, data, offset, format)) < 0) { goto error_decode; } else { offset += decoded;