ARP basics added

This commit is contained in:
Wiesner András 2022-12-08 17:03:12 +01:00
parent c14d3b192a
commit e6c866b018
3 changed files with 57 additions and 0 deletions

View File

@ -11,6 +11,7 @@ typedef struct EthIODef_ {
int (*llRxDone)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Receive done callback int (*llRxDone)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Receive done callback
int (*llError)(struct EthIODef_ * io, int error); ///< Low-level error interrupt int (*llError)(struct EthIODef_ * io, int error); ///< Low-level error interrupt
void * tag; ///< Some arbitrary tagging void * tag; ///< Some arbitrary tagging
} EthIODef; } EthIODef;
typedef struct EthInterface_ { typedef struct EthInterface_ {

View File

@ -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;
}

View File

@ -0,0 +1,36 @@
//
// Created by epagris on 2022.12.08..
//
#ifndef ETHERLIB_TEST_ARP_PACKET_H
#define ETHERLIB_TEST_ARP_PACKET_H
#include <stdint.h>
#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