From 77e97b7f402e431cda47d11dd0002c45504c7dc3 Mon Sep 17 00:00:00 2001 From: nzasch <> Date: Mon, 24 Oct 2022 19:21:04 +0200 Subject: [PATCH] Initial import --- arnet.c | 247 ++++++++++++++++++++++++++++++++++++++++++ arnet.h | 27 +++++ arnet_cli.c | 63 +++++++++++ arnet_cli.h | 42 +++++++ arnet_header_fields.h | 55 ++++++++++ arnet_state.h | 46 ++++++++ arnet_types.h | 83 ++++++++++++++ 7 files changed, 563 insertions(+) create mode 100644 arnet.c create mode 100644 arnet.h create mode 100644 arnet_cli.c create mode 100644 arnet_cli.h create mode 100644 arnet_header_fields.h create mode 100644 arnet_state.h create mode 100644 arnet_types.h diff --git a/arnet.c b/arnet.c new file mode 100644 index 0000000..dd57a49 --- /dev/null +++ b/arnet.c @@ -0,0 +1,247 @@ +/* + * The ArNet protocol + * https://ciapini.wiki.esiliati.org/view/ArNet + */ + +#include + +#include "../../ringbuf.h" + +#include "../net.h" +#include "arnet.h" + +uint8_t arnet_tx_headers_pending, arnet_tx_headers_done[16], arnet_rx_headers_parsed; + +arnet_packet arnet_tx_packet_queue[NET_PACKET_RINGBUF_SIZE], arnet_rx_packet_queue[NET_PACKET_RINGBUF_SIZE]; + +arnet_node_state node; +arnet_segment_state segment; +arnet_connection_state connection[ARNET_ADDRESS_SIZE]; + +/* CRC24 table - FCS */ +static const uint32_t tbl_crc24[256] = { + 0x00000000, 0x00d6a776, 0x00f64557, 0x0020e221, 0x00b78115, 0x00612663, 0x0041c442, 0x00976334, + 0x00340991, 0x00e2aee7, 0x00c24cc6, 0x0014ebb0, 0x00838884, 0x00552ff2, 0x0075cdd3, 0x00a36aa5, + 0x00681322, 0x00beb454, 0x009e5675, 0x0048f103, 0x00df9237, 0x00093541, 0x0029d760, 0x00ff7016, + 0x005c1ab3, 0x008abdc5, 0x00aa5fe4, 0x007cf892, 0x00eb9ba6, 0x003d3cd0, 0x001ddef1, 0x00cb7987, + 0x00d02644, 0x00068132, 0x00266313, 0x00f0c465, 0x0067a751, 0x00b10027, 0x0091e206, 0x00474570, + 0x00e42fd5, 0x003288a3, 0x00126a82, 0x00c4cdf4, 0x0053aec0, 0x008509b6, 0x00a5eb97, 0x00734ce1, + 0x00b83566, 0x006e9210, 0x004e7031, 0x0098d747, 0x000fb473, 0x00d91305, 0x00f9f124, 0x002f5652, + 0x008c3cf7, 0x005a9b81, 0x007a79a0, 0x00acded6, 0x003bbde2, 0x00ed1a94, 0x00cdf8b5, 0x001b5fc3, + 0x00fb4733, 0x002de045, 0x000d0264, 0x00dba512, 0x004cc626, 0x009a6150, 0x00ba8371, 0x006c2407, + 0x00cf4ea2, 0x0019e9d4, 0x00390bf5, 0x00efac83, 0x0078cfb7, 0x00ae68c1, 0x008e8ae0, 0x00582d96, + 0x00935411, 0x0045f367, 0x00651146, 0x00b3b630, 0x0024d504, 0x00f27272, 0x00d29053, 0x00043725, + 0x00a75d80, 0x0071faf6, 0x005118d7, 0x0087bfa1, 0x0010dc95, 0x00c67be3, 0x00e699c2, 0x00303eb4, + 0x002b6177, 0x00fdc601, 0x00dd2420, 0x000b8356, 0x009ce062, 0x004a4714, 0x006aa535, 0x00bc0243, + 0x001f68e6, 0x00c9cf90, 0x00e92db1, 0x003f8ac7, 0x00a8e9f3, 0x007e4e85, 0x005eaca4, 0x00880bd2, + 0x00437255, 0x0095d523, 0x00b53702, 0x00639074, 0x00f4f340, 0x00225436, 0x0002b617, 0x00d41161, + 0x00777bc4, 0x00a1dcb2, 0x00813e93, 0x005799e5, 0x00c0fad1, 0x00165da7, 0x0036bf86, 0x00e018f0, + 0x00ad85dd, 0x007b22ab, 0x005bc08a, 0x008d67fc, 0x001a04c8, 0x00cca3be, 0x00ec419f, 0x003ae6e9, + 0x00998c4c, 0x004f2b3a, 0x006fc91b, 0x00b96e6d, 0x002e0d59, 0x00f8aa2f, 0x00d8480e, 0x000eef78, + 0x00c596ff, 0x00133189, 0x0033d3a8, 0x00e574de, 0x007217ea, 0x00a4b09c, 0x008452bd, 0x0052f5cb, + 0x00f19f6e, 0x00273818, 0x0007da39, 0x00d17d4f, 0x00461e7b, 0x0090b90d, 0x00b05b2c, 0x0066fc5a, + 0x007da399, 0x00ab04ef, 0x008be6ce, 0x005d41b8, 0x00ca228c, 0x001c85fa, 0x003c67db, 0x00eac0ad, + 0x0049aa08, 0x009f0d7e, 0x00bfef5f, 0x00694829, 0x00fe2b1d, 0x00288c6b, 0x00086e4a, 0x00dec93c, + 0x0015b0bb, 0x00c317cd, 0x00e3f5ec, 0x0035529a, 0x00a231ae, 0x007496d8, 0x005474f9, 0x0082d38f, + 0x0021b92a, 0x00f71e5c, 0x00d7fc7d, 0x00015b0b, 0x0096383f, 0x00409f49, 0x00607d68, 0x00b6da1e, + 0x0056c2ee, 0x00806598, 0x00a087b9, 0x007620cf, 0x00e143fb, 0x0037e48d, 0x001706ac, 0x00c1a1da, + 0x0062cb7f, 0x00b46c09, 0x00948e28, 0x0042295e, 0x00d54a6a, 0x0003ed1c, 0x00230f3d, 0x00f5a84b, + 0x003ed1cc, 0x00e876ba, 0x00c8949b, 0x001e33ed, 0x008950d9, 0x005ff7af, 0x007f158e, 0x00a9b2f8, + 0x000ad85d, 0x00dc7f2b, 0x00fc9d0a, 0x002a3a7c, 0x00bd5948, 0x006bfe3e, 0x004b1c1f, 0x009dbb69, + 0x0086e4aa, 0x005043dc, 0x0070a1fd, 0x00a6068b, 0x003165bf, 0x00e7c2c9, 0x00c720e8, 0x0011879e, + 0x00b2ed3b, 0x00644a4d, 0x0044a86c, 0x00920f1a, 0x00056c2e, 0x00d3cb58, 0x00f32979, 0x00258e0f, + 0x00eef788, 0x003850fe, 0x0018b2df, 0x00ce15a9, 0x0059769d, 0x008fd1eb, 0x00af33ca, 0x007994bc, + 0x00dafe19, 0x000c596f, 0x002cbb4e, 0x00fa1c38, 0x006d7f0c, 0x00bbd87a, 0x009b3a5b, 0x004d9d2d +}; + +// da integrare altrove + +void arnet_prepare_packet(void) { + arnet_tx_headers_pending = 1; // DH + if (arnet_tx_packet_queue[net_tx_packet_index_out].vc.enabled == 1) arnet_tx_headers_pending++; + if (arnet_tx_packet_queue[net_tx_packet_index_out].ec.enabled == 1) arnet_tx_headers_pending++; +} + +void arnet_packet_setup(void) { + arnet_tx_packet_queue[net_tx_packet_index_in].dh.header_size = 0; + arnet_tx_packet_queue[net_tx_packet_index_in].dh.protocol = ARNET_PACKET_PROTOCOL; + arnet_tx_packet_queue[net_tx_packet_index_in].dh.src_addr = node.address; + arnet_tx_packet_queue[net_tx_packet_index_in].dh.dst_addr = node.current_peer; + + if (node.enabled.vc == 1) { + // viene popolato in chiusura + arnet_tx_packet_queue[net_tx_packet_index_in].vc.enabled = node.enabled.vc; + arnet_tx_packet_queue[net_tx_packet_index_in].vc.sequence = connection[node.current_peer].sequence; + arnet_tx_packet_queue[net_tx_packet_index_in].dh.header_size++; + } + if (node.enabled.ec == 1) { + // viene popolato in chiusura + arnet_tx_packet_queue[net_tx_packet_index_in].ec.enabled = node.enabled.vc; + arnet_tx_packet_queue[net_tx_packet_index_in].ec.algo = EC_ALGO_CRC24; + arnet_tx_packet_queue[net_tx_packet_index_in].dh.header_size++; + } +} + +void arnet_packet_finalize(void) { + if (arnet_tx_packet_queue[net_tx_packet_index_in].vc.enabled == 1) { + // incrementa indice dei pacchetti mandati a questo nodo + connection[arnet_tx_packet_queue[net_tx_packet_index_in].dh.dst_addr].sequence++; + connection[arnet_tx_packet_queue[net_tx_packet_index_in].dh.dst_addr].sequence &= 0xFF; // dovrebbe essere superfluo + } + if (arnet_tx_packet_queue[net_tx_packet_index_in].ec.enabled == 1) { + arnet_tx_packet_queue[net_tx_packet_index_in].ec.value = arnet_generate_ec(net_tx_packet_queue[net_tx_packet_index_in], net_tx_data_ringbuf, arnet_tx_packet_queue[net_tx_packet_index_in].ec.algo); + } +} + +// genera header arnet + +uint32_t arnet_generate_header(void) { + uint32_t header = 0; + if (arnet_tx_headers_done[HTYPE_DH_VALUE] == 0) { + header |= (uint32_t) ((uint32_t) arnet_tx_packet_queue[net_tx_packet_index_out].dh.protocol << clz(DH_PROTOCOL_MASK)); + header |= (uint32_t) ((uint32_t) net_tx_packet_queue[net_tx_packet_index_out].data_size << clz(DH_PAYLOADSIZE_MASK)); + header |= (uint32_t) ((uint32_t) arnet_tx_packet_queue[net_tx_packet_index_out].dh.header_size << clz(DH_HEADERSIZE_MASK)); + header |= (uint32_t) ((uint32_t) arnet_tx_packet_queue[net_tx_packet_index_out].dh.src_addr << clz(DH_SRC_MASK)); + header |= (uint32_t) ((uint32_t) arnet_tx_packet_queue[net_tx_packet_index_out].dh.dst_addr << clz(DH_DST_MASK)); + arnet_tx_headers_done[HTYPE_DH_VALUE] = 1; + } else if (arnet_tx_packet_queue[net_tx_packet_index_out].vc.enabled == 1 && arnet_tx_headers_done[HTYPE_VC_VALUE] == 0) { + header |= (uint32_t) ((uint32_t) HTYPE_VC_VALUE << clz(ALLH_HTYPE_MASK)); + header |= (uint32_t) ((uint32_t) arnet_tx_packet_queue[net_tx_packet_index_out].vc.sequence << clz(VC_SEQ_MASK)); + // questo va stabilito al momento + header |= (uint32_t) ((uint32_t) connection[arnet_tx_packet_queue[net_tx_packet_index_out].dh.dst_addr].acknowledge << clz(VC_ACKSEQ_MASK)); + arnet_tx_headers_done[HTYPE_VC_VALUE] = 1; + } else if (arnet_tx_packet_queue[net_tx_packet_index_out].ec.enabled == 1 && arnet_tx_headers_done[HTYPE_EC_VALUE] == 0) { + header |= (uint32_t) ((uint32_t) HTYPE_EC_VALUE << clz(ALLH_HTYPE_MASK)); + header |= (uint32_t) ((uint32_t) arnet_tx_packet_queue[net_tx_packet_index_out].ec.value << clz(EC_VALUE_MASK)); + arnet_tx_headers_done[HTYPE_EC_VALUE] = 1; + } else { + // boh ? + } + // setta i bytes da mandare, dove va? a cosa serve ? + // arnet_bytes_pending = arnet_tx_packet_queue[net_tx_packet_index_out].dh.payload_size; + + return header; +} + + +// processa blocco header + +void arnet_parse_header_block(uint8_t *block, uint8_t block_size, net_packet *net_pck, arnet_packet *arnet_pck) { + uint32_t InputDataBlock = 0; + uint8_t i, InputPacketForMe; + + // serializza + for (i = 0; i < block_size; i++) { + InputDataBlock |= (uint32_t) block[i] << (i * 8); + } + + if (arnet_rx_headers_parsed == 0) { + // primo header block, e' default + arnet_pck->dh.protocol = get_header_field(InputDataBlock, DH_PROTOCOL_MASK); + if (arnet_pck->dh.protocol != ARNET_PACKET_PROTOCOL) { + // e mo??!?! + // net_rx_state = NET_STATE_IDLE; + } + arnet_pck->dh.src_addr = get_header_field(InputDataBlock, DH_SRC_MASK); + arnet_pck->dh.dst_addr = get_header_field(InputDataBlock, DH_DST_MASK); + if ((arnet_pck->dh.dst_addr == node.address) || (arnet_pck->dh.dst_addr == node.multicast_address) || (arnet_pck->dh.dst_addr == 0)) { + // e' per noi! tenere cmq tutto in coda o fare qualcosa? + InputPacketForMe = 1; + } + arnet_pck->dh.header_size = get_header_field(InputDataBlock, DH_HEADERSIZE_MASK); + net_pck->data_size = get_header_field(InputDataBlock, DH_PAYLOADSIZE_MASK); + + } else if (arnet_rx_headers_parsed < (arnet_pck->dh.header_size + 1)) { + // header seguenti + + switch (get_header_field(InputDataBlock, ALLH_HTYPE_MASK)) { + case HTYPE_VC_VALUE: + arnet_pck->vc.enabled = 1; + arnet_pck->vc.sequence = get_header_field(InputDataBlock, VC_SEQ_MASK); + arnet_pck->vc.acknowledge = get_header_field(InputDataBlock, VC_ACKSEQ_MASK); + if (arnet_pck->vc.acknowledge == connection[arnet_pck->dh.src_addr].sequence) { + // sequenza corretta, puoi debufferare + } else { + // skip!!! + } + break; + case HTYPE_EC_VALUE: + arnet_pck->ec.enabled = 1; + arnet_pck->ec.algo = get_header_field(InputDataBlock, EC_ALGO_MASK); + arnet_pck->ec.value = get_header_field(InputDataBlock, EC_VALUE_MASK); + break; + } + } else { + + } + + arnet_rx_headers_parsed++; + + // if (arnet_rx_headers_parsed > arnet_pck->dh.header_size) { + // // header completamente parsato + // net_rx_state = NET_STATE_HEADER_DONE; + // arnet_rx_headers_parsed = 0; + // + // // tagga inizio dati - andrebbe fuori + // net_rx_packet_queue[net_rx_packet_index_in].data_start = net_rx_data_ringbuf_input_index; //inizio dati + // + // if (arnet_pck->dh.payload_size > 0) { + // net_rx_data_content = DATA_IS_PAYLOAD; + // net_rx_state = NET_STATE_PAYLOAD_WAIT; + // } else { + // // pacchetto vuoto. qui non sta bene + // net_rx_data_content = DATA_IS_HEADER; + // net_rx_state = NET_STATE_PAYLOAD_DONE; + // StopReceive(); + // } + // + // } +} + + +// estrae campo header + +uint32_t get_header_field(uint32_t InputHeaderBlock, uint32_t Mask) { + uint32_t field_value = 0; + field_value = InputHeaderBlock & Mask; + // ndo sta ? + field_value = field_value >> clz(Mask); + + return field_value; +} + +uint8_t clz(uint32_t in) { + uint8_t i = 0; + while (i < 32) { + if (((in >> i) & 1) == 1) return i; + i++; + } + return i; +} + +uint8_t arnet_check_ec(net_packet *net_pck, uint8_t algo) { + uint8_t out; + if (algo == EC_ALGO_CRC24) { + // TODO + } else { + out = ARNET_EC_INVALID_ALGO; + } + return out; +} + +uint32_t arnet_generate_ec(net_packet net_pck, uint8_t *data_queue, uint8_t algo) { + uint16_t data_index; + uint32_t crc = 0; + if (algo == EC_ALGO_CRC24) { + data_index = net_pck.data_start; + + crc = ARNET_CRC24_INIT; + while (ringbuf_get_distance(net_pck.data_start, data_index, DATA_BUFFER_SIZE, DATA_BUFFER_SIZE_MASK) == net_pck.data_size) { + crc = (crc >> 8) ^ tbl_crc24[(crc ^ data_queue[data_index]) & 0xff]; + ringbuf_increment(&data_index, DATA_BUFFER_SIZE_MASK); + } + crc = ~crc; + crc &= 0xffffff; + } + return crc; +} \ No newline at end of file diff --git a/arnet.h b/arnet.h new file mode 100644 index 0000000..a7dc9d4 --- /dev/null +++ b/arnet.h @@ -0,0 +1,27 @@ +/** + * https://ciapini.wiki.esiliati.org/view/ArNet + */ + +#ifndef ARNET_H +#define ARNET_H + +#include + +#include "arnet_types.h" +#include "arnet_state.h" +#include "arnet_header_fields.h" + + +uint32_t arnet_generate_header(void); +void arnet_parse_header_block(uint8_t *block, uint8_t block_size, net_packet *net_pck, arnet_packet *arnet_pck); +uint32_t get_header_field(uint32_t InputHeaderBlock, uint32_t Mask); +uint8_t clz(uint32_t in); + +uint32_t arnet_generate_ec(net_packet net_pck, uint8_t *data_queue, uint8_t algo); + +void arnet_prepare_packet(void); +void arnet_packet_setup(void); +void arnet_packet_finalize(void); + + +#endif /* ARNET_H */ \ No newline at end of file diff --git a/arnet_cli.c b/arnet_cli.c new file mode 100644 index 0000000..1517010 --- /dev/null +++ b/arnet_cli.c @@ -0,0 +1,63 @@ +/* armando modem - iz4kll + * https://ciapini.wiki.esiliati.org/index.php/Armando47/ArNetCLI + */ + +#include + +#include "../../mini-printf.h" + +#include "../net.h" +#include "arnet.h" +#include "arnet_cli.h" +#include "arnet_types.h" + +uint8_t arnet_cli_print_packet(net_packet net_pck, arnet_packet arnet_pck, uint8_t *Buffer) { + uint8_t q = 0; + q += mini_snprintf((char*) (&Buffer[q]), 24, "%c%u%c%c%u", ARNET_CLI_SRC_ADDR, arnet_pck.dh.src_addr, ARNET_CLI_ELEMENT_SEPARATOR, ARNET_CLI_DST_ADDR, arnet_pck.dh.dst_addr); + + if (arnet_pck.vc.enabled == 1) { + q += mini_snprintf((char*) (&Buffer[q]), 24, "N%u", arnet_pck.vc.sequence); + } + + if (arnet_pck.ec.enabled == 1) { + q += mini_snprintf((char*) (&Buffer[q]), 24, "%c%c%u", ARNET_CLI_ELEMENT_SEPARATOR, ARNET_CLI_EC_ENABLED, arnet_pck.ec.ARQ); + } + + return q; +} + +uint8_t arnet_cli_print_state(uint8_t *Buffer) { + uint8_t q = 0; + // indirizzi + q += mini_snprintf((char*) (&Buffer[q]), 24, "%c%c%u%c%c%c%u", ARNET_CLI_SRC_ADDR, ARNET_CLI_KV_SEPARATOR, node.address, ARNET_CLI_ELEMENT_SEPARATOR, ARNET_CLI_DST_ADDR, ARNET_CLI_KV_SEPARATOR, node.current_peer); + // ec + q += mini_snprintf((char*) (&Buffer[q]), 24, "%c%c%c%u", ARNET_CLI_ELEMENT_SEPARATOR, ARNET_CLI_EC_ENABLED, ARNET_CLI_KV_SEPARATOR, node.enabled.ec); + return q; +} + +// esegui + +uint8_t arnet_cli_exec(uint8_t name, uint32_t value) { + uint8_t err = ARNET_CLI_ERR_OK; + if (name == ARNET_CLI_SRC_ADDR) { + if (value >= ARNET_ADDRESS_SIZE) { + err = ARNET_CLI_ERR_INVALID_VALUE; + } else { + node.address = value; + } + } else if (name == ARNET_CLI_DST_ADDR) { + if (value >= ARNET_ADDRESS_SIZE) { + err = ARNET_CLI_ERR_INVALID_VALUE; + } else { + node.current_peer = value; + } + } else if (name == ARNET_CLI_EC_ENABLED) { + if (value == 0) node.enabled.ec = 0; + else { + node.enabled.ec = 1; + } + } else { + err = ARNET_CLI_ERR_INVALID_NAME; + } + return err; +} diff --git a/arnet_cli.h b/arnet_cli.h new file mode 100644 index 0000000..890cc9d --- /dev/null +++ b/arnet_cli.h @@ -0,0 +1,42 @@ +/* + * https://ciapini.wiki.esiliati.org/view/ArNet + */ + +#ifndef ARNET_CLI_H +#define ARNET_CLI_H + +#include + +#include "../net.h" + +#define ARNET_CLI_ELEMENT_SEPARATOR ',' +#define ARNET_CLI_KV_SEPARATOR '=' + +// queue +#define ARNET_CLI_TX_QUEUE 'T' + +// packet +#define ARNET_CLI_SRC_ADDR 'S' +#define ARNET_CLI_DST_ADDR 'D' +#define ARNET_CLI_HDR_SIZE 'H' +#define ARNET_CLI_PLD_SIZE 'P' + +// EC + +#define ARNET_CLI_EC_ENABLED 'C' +#define ARNET_CLI_EC_OK 'K' + +// errors +#define ARNET_CLI_ERR 'E' +#define ARNET_CLI_ERR_OK 0 +#define ARNET_CLI_ERR_INVALID_NAME 1 +#define ARNET_CLI_ERR_INVALID_VALUE 2 + +// protoz +uint8_t arnet_cli_exec(uint8_t name, uint32_t value); +// uint8_t arnet_cli_parse(uint8_t *Buffer, uint8_t bufferlen); +uint8_t arnet_cli_print_state(uint8_t *Buffer); +uint8_t arnet_cli_print_packet(net_packet net_pck, arnet_packet arnet_pck, uint8_t *Buffer); + +#endif /* ARNET_CLI_H */ + diff --git a/arnet_header_fields.h b/arnet_header_fields.h new file mode 100644 index 0000000..044a1e0 --- /dev/null +++ b/arnet_header_fields.h @@ -0,0 +1,55 @@ +/** + * https://ciapini.wiki.esiliati.org/view/ArNet + */ + +#ifndef ARNET_HEADER_FIELDS_H +#define ARNET_HEADER_FIELDS_H + +// tutti gli header +#define ALLH_HTYPE_MASK 0xF0000000 + +// id del tipo di header +#define HTYPE_DH_VALUE 0x0 +#define HTYPE_VC_VALUE 0x1 +#define HTYPE_EC_VALUE 0x2 +#define HTYPE_TIMEH_VALUE 0x3 + +// default header + +#define DH_SRC_MASK 0x0000FF00 +#define DH_DST_MASK 0x000000FF +#define DH_HEADERSIZE_MASK 0x3C000000 +#define DH_PAYLOADSIZE_MASK 0x03FF0000 +#define DH_PROTOCOL_MASK 0xC0000000 + +// VC Header +#define VC_VCI_MASK 0x03FF0000 +#define VC_SEQ_MASK 0x0000FF00 +#define VC_ACKSEQ_MASK 0x000000FF + +// CRC header +#define EC_ALGO_MASK 0x0C000000 +#define EC_ARQ_MASK 0x02000000 +#define EC_ACK_MASK 0x01000000 +#define EC_VALUE_MASK 0x00FFFFFF + +#define EC_ALGO_CRC24 00 + + +// SAAH + +#define SAAH_TFRAME_MASK 0x0FF00000 +#define SAAH_SEGADDR_MASK 0x000FF000 +#define SAAH_CHANLOAD_MASK 0x00000FF0 +#define SAAH_CONGCLIENT_MASK 0x0000000F + +// GRTH + +#define GRTH_TTL_MASK 0x0F000000 +#define GRTH_FECN_MASK 0x0F000000 +#define GRTH_BECN_MASK 0x0F000000 +#define GRTH_SEGSRC_MASK 0x0000FF00 +#define GRTH_SEGDST_MASK 0x0F0000FF + +#endif /* ARNET_HEADER_FIELDS_H */ + diff --git a/arnet_state.h b/arnet_state.h new file mode 100644 index 0000000..6a3357e --- /dev/null +++ b/arnet_state.h @@ -0,0 +1,46 @@ +/** @file doxygen_c.h + * @author My Self + * @date 9 Sep 2012 + * https://ciapini.wiki.esiliati.org/view/ArNet + */ + +#ifndef ARNET_STATE_H +#define ARNET_STATE_H + +#include "arnet_cli.h" +#include "arnet_types.h" + +/** An enum type. + * The documentation block cannot be put after the enum! + */ +typedef struct { + uint8_t vc; + uint8_t ec; +} arnet_enabled_headers; + +typedef struct { + uint8_t address; ///< indirizzo del nodo + uint8_t current_peer; ///< nodo remoto + uint8_t multicast_address; ///< indirizzo multicast del nodo + uint8_t congestion; ///< congestione + uint16_t time; ///< tempo del nodo + uint16_t date; ///< data del nodo + arnet_enabled_headers enabled; ///< header abilitati +} arnet_node_state; + +typedef struct { + uint8_t address; +} arnet_segment_state; + +typedef struct { + // uint8_t vci; + uint8_t sequence; + uint8_t acknowledge; +} arnet_connection_state; + +extern arnet_node_state node; ///< stato del nodo +extern arnet_segment_state segment; +extern arnet_connection_state connection[ARNET_ADDRESS_SIZE]; ///< stato della connessione + +#endif /* ARNET_STATE_H */ + diff --git a/arnet_types.h b/arnet_types.h new file mode 100644 index 0000000..2adcdf5 --- /dev/null +++ b/arnet_types.h @@ -0,0 +1,83 @@ +/* + * https://ciapini.wiki.esiliati.org/view/ArNet + */ + +#ifndef ARNET_TYPES_H +#define ARNET_TYPES_H + +#include + +#include "../net.h" + +#define ARNET_PACKET_PROTOCOL 1 ///< 4bit net protocol id - arnet = 0 + +#define ARNET_PADDING 0 + +#define ARNET_ADDRESS_SIZE 256 ///< max arnet address space +#define ARNET_MAX_HEADER_NUMBER 16 ///< max arnet optional headers +#define ARNET_MAX_PACKET_SIZE 1024+((ARNET_MAX_HEADER_NUMBER+1)*4) ///< max arnet packet size + +// ERRORS & STATUS +// #define ARNET_ERR_INVALID_SRC 1 // invalid source address +// #define ARNET_ERR_INVALID_DST 2 // invalid destination address + +#define ARNET_EC_OK 0 +#define ARNET_EC_WRONG 1 +#define ARNET_EC_DISABLED 2 +#define ARNET_EC_INVALID_ALGO 3 + +#define ARNET_CRC24_INIT 0xffffff + +/* TODO +typedef struct { + uint8_t headers_pending; + uint8_t headers_parsed; + uint8_t headers_done[ARNET_MAX_HEADER_NUMBER]; +} arnet_status; +*/ + +// il payload size va nella coda net + +typedef struct { + uint8_t protocol; ///< codice protocollo + uint8_t header_size; ///< numero di header aggiuntivi + uint16_t payload_size; ///< dimensione del payload in byte + uint8_t src_addr; ///< indirizzo mittente + uint8_t dst_addr; ///< indirizzo destinatario +} DH; + +typedef struct { + uint8_t enabled; + // uint16_t vci; + uint8_t sequence; + uint8_t acknowledge; +} VC; + +typedef struct { + uint8_t enabled; + uint8_t algo; + uint8_t ARQ; + uint8_t ACK; + uint32_t value; +} EC; + +typedef struct { + uint8_t enabled; + uint8_t segaddr; + uint8_t timeframe; + uint8_t beacon_period; + uint8_t reserved_window; +} SAAH; + +typedef struct { + DH dh; ///< default header + VC vc; + EC ec; + SAAH saah; +} arnet_packet; + +extern uint8_t arnet_tx_headers_pending, arnet_tx_headers_done[16], arnet_rx_headers_parsed; +extern arnet_packet arnet_tx_packet_queue[NET_PACKET_RINGBUF_SIZE], arnet_rx_packet_queue[NET_PACKET_RINGBUF_SIZE]; + +#endif /* ARNET_TYPES_H */ +