mirror of
https://github.com/markqvist/OpenModem.git
synced 2025-07-30 18:38:33 -04:00
Initial KISS support
This commit is contained in:
parent
9addf50a33
commit
6e3d8d9987
18 changed files with 1521 additions and 164 deletions
|
@ -70,51 +70,56 @@
|
|||
|
||||
static void ax25_decode(AX25Ctx *ctx)
|
||||
{
|
||||
AX25Msg msg;
|
||||
uint8_t *buf = ctx->buf;
|
||||
|
||||
DECODE_CALL(buf, msg.dst.call);
|
||||
msg.dst.ssid = (*buf++ >> 1) & 0x0F;
|
||||
|
||||
DECODE_CALL(buf, msg.src.call);
|
||||
msg.src.ssid = (*buf >> 1) & 0x0F;
|
||||
|
||||
|
||||
/* Repeater addresses */
|
||||
#if CONFIG_AX25_RPT_LST
|
||||
for (msg.rpt_cnt = 0; !(*buf++ & 0x01) && (msg.rpt_cnt < countof(msg.rpt_lst)); msg.rpt_cnt++)
|
||||
{
|
||||
DECODE_CALL(buf, msg.rpt_lst[msg.rpt_cnt].call);
|
||||
msg.rpt_lst[msg.rpt_cnt].ssid = (*buf >> 1) & 0x0F;
|
||||
AX25_SET_REPEATED(&msg, msg.rpt_cnt, (*buf & 0x80));
|
||||
}
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_KISS
|
||||
if (ctx->hook)
|
||||
ctx->hook(ctx);
|
||||
#else
|
||||
while (!(*buf++ & 0x01))
|
||||
AX25Msg msg;
|
||||
uint8_t *buf = ctx->buf;
|
||||
DECODE_CALL(buf, msg.dst.call);
|
||||
msg.dst.ssid = (*buf++ >> 1) & 0x0F;
|
||||
|
||||
DECODE_CALL(buf, msg.src.call);
|
||||
msg.src.ssid = (*buf >> 1) & 0x0F;
|
||||
|
||||
|
||||
/* Repeater addresses */
|
||||
#if CONFIG_AX25_RPT_LST
|
||||
for (msg.rpt_cnt = 0; !(*buf++ & 0x01) && (msg.rpt_cnt < countof(msg.rpt_lst)); msg.rpt_cnt++)
|
||||
{
|
||||
DECODE_CALL(buf, msg.rpt_lst[msg.rpt_cnt].call);
|
||||
msg.rpt_lst[msg.rpt_cnt].ssid = (*buf >> 1) & 0x0F;
|
||||
AX25_SET_REPEATED(&msg, msg.rpt_cnt, (*buf & 0x80));
|
||||
}
|
||||
#else
|
||||
while (!(*buf++ & 0x01))
|
||||
{
|
||||
char rpt[6];
|
||||
uint8_t ssid;
|
||||
DECODE_CALL(buf, rpt);
|
||||
ssid = (*buf >> 1) & 0x0F;
|
||||
}
|
||||
#endif
|
||||
|
||||
msg.ctrl = *buf++;
|
||||
if (msg.ctrl != AX25_CTRL_UI)
|
||||
{
|
||||
char rpt[6];
|
||||
uint8_t ssid;
|
||||
DECODE_CALL(buf, rpt);
|
||||
ssid = (*buf >> 1) & 0x0F;
|
||||
return;
|
||||
}
|
||||
|
||||
msg.pid = *buf++;
|
||||
if (msg.pid != AX25_PID_NOLAYER3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
msg.len = ctx->frm_len - 2 - (buf - ctx->buf);
|
||||
msg.info = buf;
|
||||
|
||||
if (ctx->hook)
|
||||
ctx->hook(&msg);
|
||||
#endif
|
||||
|
||||
msg.ctrl = *buf++;
|
||||
if (msg.ctrl != AX25_CTRL_UI)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
msg.pid = *buf++;
|
||||
if (msg.pid != AX25_PID_NOLAYER3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
msg.len = ctx->frm_len - 2 - (buf - ctx->buf);
|
||||
msg.info = buf;
|
||||
|
||||
if (ctx->hook)
|
||||
ctx->hook(&msg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -258,6 +263,20 @@ void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const voi
|
|||
kfile_putc(HDLC_FLAG, ctx->ch);
|
||||
}
|
||||
|
||||
void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len) {
|
||||
ctx->crc_out = CRC_CCITT_INIT_VAL;
|
||||
kfile_putc(HDLC_FLAG, ctx->ch);
|
||||
const uint8_t *buf = (const uint8_t *)_buf;
|
||||
while (len--) ax25_putchar(ctx, *buf++);
|
||||
|
||||
uint8_t crcl = (ctx->crc_out & 0xff) ^ 0xff;
|
||||
uint8_t crch = (ctx->crc_out >> 8) ^ 0xff;
|
||||
ax25_putchar(ctx, crcl);
|
||||
ax25_putchar(ctx, crch);
|
||||
|
||||
kfile_putc(HDLC_FLAG, ctx->ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the AX25 protocol decoder.
|
||||
*
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#ifndef NET_AX25_H
|
||||
#define NET_AX25_H
|
||||
|
||||
#include "config.h" // Various configuration values
|
||||
#include "cfg/cfg_ax25.h"
|
||||
|
||||
#include <cfg/compiler.h>
|
||||
|
@ -62,11 +63,18 @@
|
|||
#define AX25_CRC_CORRECT 0xF0B8
|
||||
|
||||
struct AX25Msg; // fwd declaration
|
||||
struct AX25Ctx; // fwd declaration
|
||||
|
||||
/**
|
||||
* Type for AX25 messages callback.
|
||||
*/
|
||||
typedef void (*ax25_callback_t)(struct AX25Msg *msg);
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
|
||||
typedef void (*ax25_callback_t)(struct AX25Msg *msg);
|
||||
#endif
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_KISS
|
||||
typedef void (*ax25_callback_t)(struct AX25Ctx *ctx);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
|
@ -170,6 +178,7 @@ typedef struct AX25Msg
|
|||
|
||||
void ax25_poll(AX25Ctx *ctx);
|
||||
void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len);
|
||||
void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len);
|
||||
|
||||
/**
|
||||
* Send an AX25 frame on the channel.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue