SysIo  1.9.0
Embedded Library and tools
ax25.h
1 
9 #ifndef _SYSIO_AX25_H_
10 #define _SYSIO_AX25_H_
11 
12 #include <sysio/defs.h>
13 
14 #ifdef __cplusplus
15  extern "C" {
16 #endif
17 /* ========================================================================== */
18 #include <stdio.h>
19 
20 
31 /* constants ================================================================ */
35 #define AX25_MAX_RPT 8
36 
40 #define AX25_CALL_LEN 6
41 
45 #define AX25_INFO_LEN 256
46 
50 #define AX25_FRAME_BUF_LEN ((AX25_CALL_LEN+1)*(2+AX25_MAX_RPT)+AX25_INFO_LEN+4)
51 
57 #define AX25_CTRL_UI 0x03
58 
64 #define AX25_PID_NOLAYER3 0xF0
65 
71 #define HDLC_FLAG 0x7E
72 #define HDLC_RESET 0x7F
73 #define AX25_ESC 0x1B
74 
78 typedef enum {
79 
80  AX25_SUCCESS = 0,
81  AX25_FILE_ACCESS_ERROR = -1,
82  AX25_ILLEGAL_CALLSIGN = -2,
83  AX25_INVALID_FRAME = -3,
84  AX25_CRC_ERROR = -4,
85  AX25_NOT_ENOUGH_MEMORY = -5,
86  AX25_NOT_ENOUGH_REPEATER = -6,
87  AX25_OBJECT_NOT_FOUND = -7,
88  AX25_FILE_NOT_FOUND = -8,
89  AX25_ILLEGAL_REPEATER = -9,
90  AX25_NO_FRAME_RECEIVED = -10
91 
92 } eAx25Error;
93 
94 //##############################################################################
95 //# #
96 //# xAx25Node Class #
97 //# #
98 //##############################################################################
102 typedef struct xAx25Node {
103 
105  uint8_t ssid;
106  bool flag;
107 } xAx25Node;
108 
115 xAx25Node * xAx25NodeNew (void);
116 
122 void vAx25NodeDelete (xAx25Node *n);
123 
130 int iAx25NodeClear (xAx25Node *n);
131 
139 int iAx25NodeSetCallsign (xAx25Node *n, const char * callsign);
140 
150 char * xAx25NodeToStr (const xAx25Node *p);
151 
158 int iAx25NodePrint (const xAx25Node *n);
159 
166 int iAx25NodeFilePrint (const xAx25Node *n, FILE * f);
167 
168 //##############################################################################
169 //# #
170 //# xAx25Frame Class #
171 //# #
172 //##############################################################################
177 typedef struct xAx25Frame {
178 
181  xAx25Node *repeaters[AX25_MAX_RPT];
182  uint8_t repeaters_len;
183  uint8_t ctrl;
184  uint8_t pid;
185  uint8_t info[AX25_FRAME_BUF_LEN+1];
186  size_t info_len;
187 } xAx25Frame;
188 
195 xAx25Frame * xAx25FrameNew (void);
196 
202 void vAx25FrameDelete (xAx25Frame *frame);
203 
213 int iAx25FrameClear (xAx25Frame *frame);
214 
223 int iAx25FrameSetSrc (xAx25Frame *frame, const char *callsign, uint8_t ssid);
224 
233 int iAx25FrameSetDst (xAx25Frame *frame, const char *callsign, uint8_t ssid);
234 
243 int iAx25FrameAddRepeater (xAx25Frame *frame, const char *callsign, uint8_t ssid);
244 
253 int iAx25FrameSetRepeaterFlag (xAx25Frame *frame, uint8_t index, bool flag);
254 
263 int iAx25FrameSetInfo (xAx25Frame *frame, const void *info, size_t info_len);
264 
271 char * xAx25FrameToStr (const xAx25Frame *frame);
272 
278 int iAx25FrameFilePrint (const xAx25Frame *frame, FILE *f);
279 
284 int iAx25FramePrint (const xAx25Frame *frame);
285 
286 //##############################################################################
287 //# #
288 //# xAx25 Class #
289 //# #
290 //##############################################################################
291 
295 typedef struct xAx25 {
296 
297  int fin;
298  int fout;
299  uint8_t buf[AX25_FRAME_BUF_LEN];
300  size_t len;
301  uint16_t crc_in;
302  uint16_t crc_out;
303  bool sync;
304  bool escape;
305  bool frm_recv;
306  int error;
307 } xAx25;
308 
315 xAx25 * xAx25New (void);
316 
322 void vAx25Delete (xAx25 *p);
323 
329 int iAx25Clear (xAx25 *p);
330 
337 int iAx25SetFdin (xAx25 *p, int fdin);
338 
345 int iAx25SetFdout (xAx25 *p, int fdout);
346 
359 bool bAx25Poll(xAx25 *ax25);
360 
368 int iAx25Send (xAx25 *ax25, const xAx25Frame *frame);
369 
377 int iAx25Read (xAx25 *ax25, xAx25Frame *frame);
378 
382 int iAx25Error (xAx25 *ax25);
383 
390 /* ========================================================================== */
391 #ifdef __cplusplus
392  }
393 #endif
394 
395 #endif /* _SYSIO_AX25_H_ */
uint16_t crc_out
CRC of current sent frame.
Definition: ax25.h:302
uint8_t repeaters_len
Number of repeaters.
Definition: ax25.h:182
char callsign[AX25_CALL_LEN+1]
Callsign, max 6 character.
Definition: ax25.h:104
xAx25Node * xAx25NodeNew(void)
int iAx25NodeFilePrint(const xAx25Node *n, FILE *f)
int iAx25Clear(xAx25 *p)
xAx25Frame * xAx25FrameNew(void)
int iAx25Send(xAx25 *ax25, const xAx25Frame *frame)
uint8_t ctrl
AX25 control field.
Definition: ax25.h:183
int fin
stream used to access the physical input
Definition: ax25.h:297
size_t info_len
payload length
Definition: ax25.h:186
bool sync
True if we have received a HDLC flag.
Definition: ax25.h:303
bool frm_recv
True if we have received a valid frame.
Definition: ax25.h:305
int iAx25Read(xAx25 *ax25, xAx25Frame *frame)
int iAx25FrameSetRepeaterFlag(xAx25Frame *frame, uint8_t index, bool flag)
void vAx25FrameDelete(xAx25Frame *frame)
int iAx25SetFdout(xAx25 *p, int fdout)
Definition: ax25.h:295
struct xAx25 xAx25
xAx25 * xAx25New(void)
xAx25Node * dst
Destination node.
Definition: ax25.h:179
bool escape
True when we have to escape the following char.
Definition: ax25.h:304
eAx25Error
Definition: ax25.h:78
#define AX25_MAX_RPT
Definition: ax25.h:35
int iAx25FrameClear(xAx25Frame *frame)
uint8_t pid
AX25 PID field.
Definition: ax25.h:184
uint8_t ssid
SSID (secondary station ID) for the call.
Definition: ax25.h:105
int iAx25FrameAddRepeater(xAx25Frame *frame, const char *callsign, uint8_t ssid)
int iAx25NodePrint(const xAx25Node *n)
size_t len
buffer length
Definition: ax25.h:300
int iAx25Error(xAx25 *ax25)
struct xAx25Frame xAx25Frame
int iAx25NodeClear(xAx25Node *n)
char * xAx25NodeToStr(const xAx25Node *p)
int fout
stream used to access the physical output
Definition: ax25.h:298
int iAx25NodeSetCallsign(xAx25Node *n, const char *callsign)
int iAx25SetFdin(xAx25 *p, int fdin)
int iAx25FramePrint(const xAx25Frame *frame)
#define AX25_FRAME_BUF_LEN
Definition: ax25.h:50
char * xAx25FrameToStr(const xAx25Frame *frame)
uint16_t crc_in
CRC for current received frame.
Definition: ax25.h:301
void vAx25NodeDelete(xAx25Node *n)
#define AX25_CALL_LEN
Definition: ax25.h:40
void vAx25Delete(xAx25 *p)
bool bAx25Poll(xAx25 *ax25)
struct xAx25Node xAx25Node
int iAx25FrameSetInfo(xAx25Frame *frame, const void *info, size_t info_len)
int iAx25FrameSetDst(xAx25Frame *frame, const char *callsign, uint8_t ssid)
int iAx25FrameSetSrc(xAx25Frame *frame, const char *callsign, uint8_t ssid)
bool flag
boolean flag: has-been-repeated, general purpose ...
Definition: ax25.h:106
int iAx25FrameFilePrint(const xAx25Frame *frame, FILE *f)
xAx25Node * src
Source node.
Definition: ax25.h:180