BeRTOS
ax25.h
Go to the documentation of this file.
00001 
00045 #ifndef NET_AX25_H
00046 #define NET_AX25_H
00047 
00048 #include "cfg/cfg_ax25.h"
00049 
00050 #include <cfg/compiler.h>
00051 #include <io/kfile.h>
00052 
00056 #define AX25_MIN_FRAME_LEN 18
00057 
00062 #define AX25_CRC_CORRECT 0xF0B8
00063 
00064 struct AX25Msg; // fwd declaration
00065 
00069 typedef void (*ax25_callback_t)(struct AX25Msg *msg);
00070 
00071 
00075 typedef struct AX25Ctx
00076 {
00077     uint8_t buf[CONFIG_AX25_FRAME_BUF_LEN]; 
00078     KFile *ch;        
00079     size_t frm_len;   
00080     uint16_t crc_in;  
00081     uint16_t crc_out; 
00082     ax25_callback_t hook; 
00083     bool sync;   
00084     bool escape; 
00085 } AX25Ctx;
00086 
00087 
00091 typedef struct AX25Call
00092 {
00093     char call[6]; 
00094     uint8_t ssid; 
00095 } AX25Call;
00096 
00102 #define AX25_CALL(str, id) {.call = (str), .ssid = (id) }
00103 
00107 #define AX25_MAX_RPT 8
00108 
00109 /*
00110  * Has to be lesser than 8 in order to fit in one byte
00111  * change AX25Msg.rpt_flags if you need more repeaters.
00112  */
00113 STATIC_ASSERT(AX25_MAX_RPT <= 8);
00114 
00119 typedef struct AX25Msg
00120 {
00121     AX25Call src;  
00122     AX25Call dst;  
00123     #if CONFIG_AX25_RPT_LST
00124     AX25Call rpt_lst[AX25_MAX_RPT]; 
00125     uint8_t rpt_cnt; 
00126     uint8_t rpt_flags; 
00127     #define AX25_REPEATED(msg, idx) ((msg)->rpt_flags & BV(idx))
00128     #endif
00129     uint16_t ctrl; 
00130     uint8_t pid;   
00131     const uint8_t *info; 
00132     size_t len;    
00133 } AX25Msg;
00134 
00135 
00136 #define AX25_CTRL_UI      0x03
00137 #define AX25_PID_NOLAYER3 0xF0
00138 
00145 #define HDLC_FLAG  0x7E
00146 #define HDLC_RESET 0x7F
00147 #define AX25_ESC   0x1B
00148 /* \} */
00149 
00150 
00169 #define AX25_PATH(dst, src, ...) { dst, src, ## __VA_ARGS__ }
00170 
00171 void ax25_poll(AX25Ctx *ctx);
00172 void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len);
00173 
00186 #define ax25_send(ctx, dst, src, buf, len) ax25_sendVia(ctx, ({static AX25Call __path[]={dst, src}; __path;}), 2, buf, len)
00187 void ax25_init(AX25Ctx *ctx, KFile *channel, ax25_callback_t hook);
00188 
00189 void ax25_print(KFile *ch, const AX25Msg *msg);
00190 
00191 int ax25_testSetup(void);
00192 int ax25_testTearDown(void);
00193 int ax25_testRun(void);
00194 
00195 #endif /* NET_AX25_H */