diff --git a/src/Makefile b/src/Makefile index 0608549..e701a23 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ PROG-denano = $(addprefix $(BUILD_DIR)/, hello.elf dhry.elf queens.elf stanford. PROG-sim = $(addprefix $(BUILD_DIR)/, hello.elf test_exception_sim.elf test_emac_sim.elf) PROG-ml402 = $(addprefix $(BUILD_DIR)/, test_emac.elf) -SRCS-network = $(addprefix common/network/, arp.c dhcp.c emac.c ethernet.c icmp.c ipv4.c marvell_88e1111.c mii-bitbang.c udp.c fifo.c) +SRCS-network = $(addprefix common/network/, packet.c arp.c dhcp.c emac.c ethernet.c icmp.c ipv4.c marvell_88e1111.c mii-bitbang.c udp.c fifo.c) all: $(PROG-$(BOARD)) $(BUILD_DIR): diff --git a/src/common/network/arp.c b/src/common/network/arp.c index 3b0013b..37a935e 100644 --- a/src/common/network/arp.c +++ b/src/common/network/arp.c @@ -23,7 +23,7 @@ void ArpRequest(packet_t *pPacket, uint8_t *eth_addr_src, uint8_t *inet_addr_src { ARP *pARP; - pARP = (ARP*)Eth_pkt_buffer_get(pPacket); + pARP = (ARP*)packet_buffer_get(pPacket); memset(pARP, 0, sizeof(ARP)); @@ -40,7 +40,7 @@ void ArpRequest(packet_t *pPacket, uint8_t *eth_addr_src, uint8_t *inet_addr_src pARP->proto_size = 4; // Send it - Eth_pkt_append(pPacket, sizeof(ARP)); + packet_append(pPacket, sizeof(ARP)); } @@ -48,7 +48,7 @@ void ArpReply(packet_t *pPacket, uint8_t *eth_addr_src, uint8_t *inet_addr_src, { ARP *pARP; - pARP = (ARP*)Eth_pkt_buffer_get(pPacket); + pARP = (ARP*)packet_buffer_get(pPacket); memset(pARP, 0, sizeof(ARP)); @@ -65,7 +65,7 @@ void ArpReply(packet_t *pPacket, uint8_t *eth_addr_src, uint8_t *inet_addr_src, pARP->proto_size = 4; // Send it - Eth_pkt_append(pPacket, sizeof(ARP)); + packet_append(pPacket, sizeof(ARP)); } diff --git a/src/common/network/ethernet.c b/src/common/network/ethernet.c index 1226315..cc32001 100644 --- a/src/common/network/ethernet.c +++ b/src/common/network/ethernet.c @@ -59,19 +59,6 @@ uint8_t *Eth_pkt_create(packet_t *pPacket, uint16_t proto, uint8_t *pHwAddr_src, return pPacket->pData; } -uint8_t *Eth_pkt_append(packet_t *pPacket, uint32_t size) -{ - pPacket->size += size; - pPacket->pData += size; - - return pPacket->pData; -} - -uint8_t *Eth_pkt_buffer_get(packet_t *pPacket) -{ - return pPacket->pData; -} - uint32_t Eth_pkt_send(packet_t *pPacket) { volatile uint32_t *pEmac_ctrl = (uint32_t*)SYS_EMAC_TX_CTRL; diff --git a/src/common/network/ethernet.h b/src/common/network/ethernet.h index 7f1a550..8808ec6 100644 --- a/src/common/network/ethernet.h +++ b/src/common/network/ethernet.h @@ -16,6 +16,7 @@ #include #include +#include "packet.h" #define ETH_PACKET_MIN_SIZE 64 #define ETH_PACKET_MAX_SIZE 1500 @@ -52,20 +53,9 @@ typedef struct _seth_hdr_t } __attribute__ ((__packed__)) eth_hdr_t; -typedef struct _spacket_t -{ - uint8_t pkt_buf[1516]; - uint16_t size; - uint8_t *pData; - -} packet_t; - // ------------------------------------------------------------------------- void EthInit(void); uint8_t *Eth_pkt_create(packet_t *pPacket, uint16_t proto, uint8_t *pHwAddr_src, uint8_t *pHwAddr_dst); -uint8_t *Eth_pkt_append(packet_t *pPacket, uint32_t size); -uint8_t *Eth_pkt_buffer_get(packet_t *pPacket); - uint32_t Eth_pkt_send(packet_t *pPacket); uint32_t Eth_pkt_recv(uint8_t *pData); diff --git a/src/common/network/icmp.c b/src/common/network/icmp.c index 51922cd..fb39bcb 100644 --- a/src/common/network/icmp.c +++ b/src/common/network/icmp.c @@ -33,10 +33,10 @@ void ICMPSendRequest(packet_t *pPacket, uint8_t *inet_addr_src, uint8_t *inet_ad sum = IPv4ChkSum(icmp_payload, sum, len); pICMP->hdr_chksum = ~sum; - pData = (uint8_t*)Eth_pkt_append(pPacket, sizeof(ICMP)); + pData = (uint8_t*)packet_append(pPacket, sizeof(ICMP)); memcpy(pData, icmp_payload, len); - Eth_pkt_append(pPacket, len); + packet_append(pPacket, len); } @@ -57,10 +57,10 @@ void ICMPSendReply(packet_t *pPacket, uint8_t *inet_addr_src, uint8_t *inet_addr pICMP->hdr_chksum = ~sum; - pData = (uint8_t*)Eth_pkt_append(pPacket, sizeof(ICMP)); + pData = (uint8_t*)packet_append(pPacket, sizeof(ICMP)); memcpy(pData, icmp_payload, len); - Eth_pkt_append(pPacket, len); + packet_append(pPacket, len); } diff --git a/src/common/network/ipv4.c b/src/common/network/ipv4.c index 5c9a014..efb198c 100644 --- a/src/common/network/ipv4.c +++ b/src/common/network/ipv4.c @@ -17,7 +17,7 @@ uint8_t *IPV4_create(packet_t *pPacket, uint16_t proto, uint16_t len, uint8_t *i { IPV4 *pIPv4_hdr; - pIPv4_hdr = (IPV4*)Eth_pkt_buffer_get(pPacket); + pIPv4_hdr = (IPV4*)packet_buffer_get(pPacket); memset(pIPv4_hdr, 0, sizeof(IPV4)); @@ -36,7 +36,7 @@ uint8_t *IPV4_create(packet_t *pPacket, uint16_t proto, uint16_t len, uint8_t *i pIPv4_hdr->hdr_chksum = ~IPv4ChkSum((uint16_t*)pIPv4_hdr, 0, sizeof(IPV4)); // Send it - return Eth_pkt_append(pPacket, sizeof(IPV4)); + return packet_append(pPacket, sizeof(IPV4)); } diff --git a/src/common/network/packet.c b/src/common/network/packet.c new file mode 100644 index 0000000..be14219 --- /dev/null +++ b/src/common/network/packet.c @@ -0,0 +1,21 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/cFiles/file.c to edit this template + */ + +#include "packet.h" + +uint8_t *packet_append(packet_t *pPacket, uint32_t size) +{ + pPacket->size += size; + pPacket->pData += size; + + return pPacket->pData; +} + +uint8_t *packet_buffer_get(packet_t *pPacket) +{ + return pPacket->pData; +} + + diff --git a/src/common/network/packet.h b/src/common/network/packet.h new file mode 100644 index 0000000..f3db949 --- /dev/null +++ b/src/common/network/packet.h @@ -0,0 +1,38 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/cFiles/file.h to edit this template + */ + +/* + * File: packet.h + * Author: jens + * + * Created on 22. Dezember 2021, 11:17 + */ + +#ifndef PACKET_H +#define PACKET_H + +#include +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _spacket_t +{ + uint8_t pkt_buf[1516]; + uint16_t size; + uint8_t *pData; + +} packet_t; + +uint8_t *packet_append(packet_t *pPacket, uint32_t size); +uint8_t *packet_buffer_get(packet_t *pPacket); + + +#ifdef __cplusplus +} +#endif + +#endif /* PACKET_H */ + diff --git a/src/common/network/udp.c b/src/common/network/udp.c index 2c955af..5c401d1 100644 --- a/src/common/network/udp.c +++ b/src/common/network/udp.c @@ -40,13 +40,13 @@ uint8_t *UDP_create(packet_t *pPacket, uint8_t *inet_addr_src, uint16_t port_src pUDP->chksum = ~IPv4ChkSum((uint16_t*)pUDP_payload, chksum, len); // Commit header - pData = (uint8_t*)Eth_pkt_append(pPacket, sizeof(UDP)); + pData = (uint8_t*)packet_append(pPacket, sizeof(UDP)); // Commit data if (pUDP_payload) { memcpy(pData, pUDP_payload, len); - return Eth_pkt_append(pPacket, len); + return packet_append(pPacket, len); } return pData; @@ -59,6 +59,6 @@ void UDP_append(packet_t *pPacket, void const *pData, uint16_t len) if (pData) { memcpy(pPacket->pData, pData, len); - Eth_pkt_append(pPacket, len); + packet_append(pPacket, len); } }