AX25:add new print function compatible with TNC-2 format.
[bertos.git] / bertos / net / ax25.h
index 0aa8513dc4cfb1137970b3001fecf5a8c30f2e1a..0e609136f18e5d56f20b066f39b6ea23eacaa731 100644 (file)
@@ -39,7 +39,7 @@
  *
  * $WIZ$ module_name = "ax25"
  * $WIZ$ module_configuration = "bertos/cfg/cfg_ax25.h"
- * $WIZ$ module_depends = "kfile"
+ * $WIZ$ module_depends = "kfile", "crc-ccitt"
  */
 
 
@@ -95,6 +95,13 @@ typedef struct AX25Call
        uint8_t ssid; ///< SSID (secondary station ID) for the call
 } AX25Call;
 
+/**
+ * Create an AX25Call structure on the fly.
+ * \param str callsign, can be 6 characters or shorter.
+ * \param id  ssid associated with the callsign.
+ */
+#define AX25_CALL(str, id) {.call = (str), .ssid = (id) }
+
 /**
  * Maximum number of Repeaters in a AX25 message.
  */
@@ -115,7 +122,7 @@ typedef struct AX25Msg
        #endif
        uint16_t ctrl; ///< AX25 control field
        uint8_t pid;   ///< AX25 PID field
-       uint8_t *info; ///< Pointer to the info field (payload) of the message
+       const uint8_t *info; ///< Pointer to the info field (payload) of the message
        size_t len;    ///< Payload length
 } AX25Msg;
 
@@ -123,7 +130,7 @@ typedef struct AX25Msg
 #define AX25_PID_NOLAYER3 0xF0
 
 /**
- * HDLC flags
+ * \name HDLC flags.
  * These should be moved in
  * a separated HDLC related file one day...
  * \{
@@ -135,24 +142,47 @@ typedef struct AX25Msg
 
 
 /**
- * Check if there are any AX25 messages to be processed.
- * This function read available characters from the medium and search for
- * any AX25 messages.
- * If a message is found it is decoded and the linked callback executed.
- * This function may be blocking if there are no available chars and the KFile
- * used in \a ctx to access the medium is configured in blocking mode.
+ * Declare an AX25 path.
+ * \param dst the destination callsign for the path, \see AX25_CALL
+ *        for a handy way to create a callsign on the fly.
+ * \param src the source callsign for the path, \see AX25_CALL
+ *        for a handy way to create a callsign on the fly.
  *
- * \param ctx AX25 context to operate on.
+ * Additional optional callsigns can be specified at the end of this macro
+ * in order to add repeater callsigns or specific unproto paths.
+ *
+ * This macro can be used to simply path array declaration.
+ * Should be used in this way:
+ * \code
+ * AX25Call path[] = AX25_PATH(AX25_CALL("abcdef", 0), AX25_CALL("ghjklm", 0), AX25_CALL("wide1", 1), AX25_CALL("wide2", 2));
+ * \endcode
+ *
+ * The declared path can then be passed to ax25_sendVia().
  */
+#define AX25_PATH(dst, src, ...) { dst, src, ## __VA_ARGS__ }
+
 void ax25_poll(AX25Ctx *ctx);
+void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len);
 
 /**
- * Init the AX25 protocol decoder.
+ * Send an AX25 frame on the channel.
+ * \param ctx AX25 context to operate on.
+ * \param dst the destination callsign for the frame, \see AX25_CALL
+ *        for a handy way to create a callsign on the fly.
+ * \param src the source callsign for the frame, \see AX25_CALL
+ *        for a handy way to create a callsign on the fly.
+ * \param buf payload buffer.
+ * \param len length of the payload.
  *
- * \param ctx AX25 context to init.
- * \param channel Used to gain access to the physical medium
- * \param hook Callback function called when a message is received
+ * \see ax25_sendVia() if you want to send a frame with a specific path.
  */
+#define ax25_send(ctx, dst, src, buf, len) ax25_sendVia(ctx, ({static AX25Call __path[]={dst, src}; __path;}), 2, buf, len)
 void ax25_init(AX25Ctx *ctx, KFile *channel, ax25_callback_t hook);
 
+void ax25_print(KFile *ch, const AX25Msg *msg);
+
+int ax25_testSetup(void);
+int ax25_testTearDown(void);
+int ax25_testRun(void);
+
 #endif /* NET_AX25_H */