- refactored packet into own module

git-svn-id: http://moon:8086/svn/mips@227 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2021-12-22 12:47:46 +00:00
parent edd0df9b26
commit b7909dcca1
9 changed files with 74 additions and 38 deletions
+1 -1
View File
@@ -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):
+4 -4
View File
@@ -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));
}
-13
View File
@@ -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;
+1 -11
View File
@@ -16,6 +16,7 @@
#include <sys/types.h>
#include <libsys/gpio.h>
#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);
+4 -4
View File
@@ -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);
}
+2 -2
View File
@@ -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));
}
+21
View File
@@ -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;
}
+38
View File
@@ -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 <stdint.h>
#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 */
+3 -3
View File
@@ -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);
}
}