From e6c866b018ee90f694d72b181237b0038fc414ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiesner=20Andr=C3=A1s?= Date: Thu, 8 Dec 2022 17:03:12 +0100 Subject: [PATCH] ARP basics added --- eth_interface.h | 1 + prefab/packet_parsers/arp_packet.c | 20 +++++++++++++++++ prefab/packet_parsers/arp_packet.h | 36 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 prefab/packet_parsers/arp_packet.c create mode 100644 prefab/packet_parsers/arp_packet.h diff --git a/eth_interface.h b/eth_interface.h index a5f1f44..fcbe18f 100644 --- a/eth_interface.h +++ b/eth_interface.h @@ -11,6 +11,7 @@ typedef struct EthIODef_ { int (*llRxDone)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Receive done callback int (*llError)(struct EthIODef_ * io, int error); ///< Low-level error interrupt void * tag; ///< Some arbitrary tagging + } EthIODef; typedef struct EthInterface_ { diff --git a/prefab/packet_parsers/arp_packet.c b/prefab/packet_parsers/arp_packet.c new file mode 100644 index 0000000..895a943 --- /dev/null +++ b/prefab/packet_parsers/arp_packet.c @@ -0,0 +1,20 @@ +// +// Created by epagris on 2022.12.08.. +// + +#include "arp_packet.h" + +int parse_arp_packet(const uint8_t *hdr, uint32_t size, PcktProps * props) { + EthernetProps * frameProps = (EthernetProps *)props; + FETCH_ADVANCE(frameProps->destAddr, hdr, ETH_HW_ADDR_LEN); // copy destination address + FETCH_ADVANCE(frameProps->sourceAddr, hdr, ETH_HW_ADDR_LEN); // copy destination address + FETCH_WORD_H2N_ADVANCE(&frameProps->length_type, hdr); // copy length/type field + + // fill-in packet property header fields + frameProps->validityOK = true; + frameProps->containedPacketClass = + frameProps->length_type <= ETH_ETHERTYPE_LENGTH_THRESHOLD ? 0 : frameProps->length_type; + frameProps->headerSize = ETH_ETHERNET_HEADER_SIZE; + + return frameProps->containedPacketClass; +} \ No newline at end of file diff --git a/prefab/packet_parsers/arp_packet.h b/prefab/packet_parsers/arp_packet.h new file mode 100644 index 0000000..417dc55 --- /dev/null +++ b/prefab/packet_parsers/arp_packet.h @@ -0,0 +1,36 @@ +// +// Created by epagris on 2022.12.08.. +// + +#ifndef ETHERLIB_TEST_ARP_PACKET_H +#define ETHERLIB_TEST_ARP_PACKET_H + +#include + +#define ETH_ARP_PACKET_CLASS (0x0806) + +/** + * Arp operations + */ +typedef enum { + ARPOP_REQ = 1, ///< ARP Request + ARPOP_REP = 2 ///< ARP Reply +} ArpOp; + +typedef enum { + ARP_HWTYPE_ETHERNET = 1 +} ArpHwType; + +/** + * ARP properties. + */ +typedef struct { + uint16_t HTYPE; ///< Hardware type (Ethernet: 1) + uint16_t PTYPE; ///< Protocol type (IP: 0x0800) + uint8_t HLEN; ///< Hardware address length + uint8_t PLEN; ///< Protocol address length + uint16_t OPER; ///< Operation + uint16_t addr[]; ///< Array of addresses (SHA, SPA, THA, TPA) +} ArpProps; + +#endif //ETHERLIB_TEST_ARP_PACKET_H