From 001e7af3e34a4449ab27fdd26ff440b0830b989f Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 24 Nov 2021 07:17:01 +0000 Subject: [PATCH] - fixed Eth_pkt_recv - DHCP sending of client id is disabled git-svn-id: http://moon:8086/svn/mips@209 a8ebac50-d88d-4704-bea3-6648445a41b3 --- src/common/network/dhcp.c | 10 +++++-- src/common/network/ethernet.c | 7 +++-- src/test_emac.c | 54 ++++++++++++++++------------------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/common/network/dhcp.c b/src/common/network/dhcp.c index ce5a42d..73834da 100644 --- a/src/common/network/dhcp.c +++ b/src/common/network/dhcp.c @@ -4,12 +4,12 @@ // 21.12.2003, J. Ahrensfeld // // ------------------------------------------------------------------------- +#include #include #include "ethernet.h" #include "ipv4.h" #include "udp.h" #include "dhcp.h" -#include "string.h" const char hostname[] = "ML-402"; @@ -46,6 +46,7 @@ void DHCP_request_send(packet_t *pPacket, uint32_t dhcp_msg_type, uint8_t *mac_a pos = 0; size = sizeof(magic); + memset(&pDHCP->options[pos], 0xAA, sizeof(pDHCP->options)); memcpy(&pDHCP->options[pos], &magic, size); pos += size; @@ -60,6 +61,7 @@ void DHCP_request_send(packet_t *pPacket, uint32_t dhcp_msg_type, uint8_t *mac_a pDHCP->options[pos] = dhcp_msg_type; pos += size; +#ifdef WITH_CLIENT_ID // Set client ID size = sizeof(dhcp_opt_hdr_t); pOpt_hdr = (dhcp_opt_hdr_t*)&pDHCP->options[pos]; @@ -70,7 +72,8 @@ void DHCP_request_send(packet_t *pPacket, uint32_t dhcp_msg_type, uint8_t *mac_a size = pOpt_hdr->len; memcpy(&pDHCP->options[pos], mac_addr_src, size); pos += size; - +#endif + // Set client name size = sizeof(dhcp_opt_hdr_t); pOpt_hdr = (dhcp_opt_hdr_t*)&pDHCP->options[pos]; @@ -107,6 +110,7 @@ void DHCP_request_send(packet_t *pPacket, uint32_t dhcp_msg_type, uint8_t *mac_a pDHCP->options[pos] = dhcp_msg_type; pos += size; +#ifdef WITH_CLIENT_ID // Set client ID size = sizeof(dhcp_opt_hdr_t); pOpt_hdr = (dhcp_opt_hdr_t*)&pDHCP->options[pos]; @@ -117,7 +121,7 @@ void DHCP_request_send(packet_t *pPacket, uint32_t dhcp_msg_type, uint8_t *mac_a size = pOpt_hdr->len; memcpy(&pDHCP->options[pos], mac_addr_src, size); pos += size; - +#endif // Set client name size = sizeof(dhcp_opt_hdr_t); pOpt_hdr = (dhcp_opt_hdr_t*)&pDHCP->options[pos]; diff --git a/src/common/network/ethernet.c b/src/common/network/ethernet.c index 473f950..f242420 100644 --- a/src/common/network/ethernet.c +++ b/src/common/network/ethernet.c @@ -124,8 +124,8 @@ uint32_t Eth_pkt_recv(uint8_t *pData) volatile uint32_t *pEmac_size = (uint32_t*)SYS_EMAC_RX_SIZE; volatile uint32_t *pEmac_data = (uint32_t*)SYS_EMAC_DATA; - uint32_t crc32, i, num_words, num_bytes, pkt_size; - + uint32_t i, num_words, num_bytes; + if(EMAC_RX_is_avail()) { @@ -143,11 +143,14 @@ uint32_t Eth_pkt_recv(uint8_t *pData) EMAC_RX_request(); for (i=0; i < num_words; i++) + { ((uint32_t*)pData)[i] = *pEmac_data; + } EMAC_RX_free(); } } + return num_bytes; } uint16_t htons(uint16_t a) diff --git a/src/test_emac.c b/src/test_emac.c index 3fa4c18..bad82cb 100644 --- a/src/test_emac.c +++ b/src/test_emac.c @@ -29,11 +29,10 @@ gpio_if_t gpio_led_dir; gpio_if_t gpio_btn_data; gpio_if_t gpio_btn_dir; -gpio_if_t gpio_mdio_data; - Mii_t mii; #define BUFFER_SIZE (32*1024*1024) +#define WITH_DHCP_CLIENT fifo_t rx_descr_fifo; uint32_t *g_pBuf; @@ -212,10 +211,6 @@ int main() volatile uint8_t *pEmac_maddr8 = (uint8_t*)SYS_EMAC_MADDR; uint8_t buffer[2048], data[1460]; packet_t packet; - ARP *pARP; - IPV4 *pIPV4; - UDP *pUDP; - DHCP *pDHCP; uint32_t start, stop; rx_descr_t rx_descr; @@ -246,23 +241,6 @@ int main() // Reset PHY MiiGpio_Reset(&mii); - res = gpio_read(&gpio_led_dir); - printf("Dir = %08X\n", res); - -// while(1) - { - res = gpio_read(&gpio_led_data); - printf("LED-Data = %08X\n", res); - gpio_write(&gpio_led_data, res + 1); - - res = gpio_read(&gpio_btn_data); - printf("Btn-Data = %08X\n", res); - - res = gpio_read(&gpio_mdio_data); - printf("MDIO-Data = %08X\n", res); - sleep(100); - } - // Phy_loopback_enable(&mii, PHY_ADDR, MPHY_CONTROL_SPD_SEL_100); // printf("Set loopback mode.\n\r"); @@ -353,10 +331,15 @@ int main() if (!res) continue; -// printf("SYS_EMAC_RX_STAT = %08X\n", *pEmac_rx_ctrl); -// printf("SYS_EMAC_RX_SIZE = %08X\n", *pEmac_rx_size); - -/* +#ifdef WITH_DHCP_CLIENT + ARP *pARP; + IPV4 *pIPV4; + UDP *pUDP; + DHCP *pDHCP; + + printf("---------------------------------------------------------------\n"); + printf("- Send DHCP Discover ------------------------------------------\n"); + printf("---------------------------------------------------------------\n"); Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst); DHCP_request_send(&packet, DHCP_MSG_DHCPDISCOVER, eth_myself, ip_zero, ip_bcast, NULL); Eth_pkt_send(&packet); @@ -364,13 +347,17 @@ int main() sleep(500); do { - Eth_pkt_recv(buffer); + int32_t size = Eth_pkt_recv(buffer); + PrintBuffer8((uint8_t*)buffer, 16, size); pIPV4 = (IPV4*)&buffer[sizeof(eth_hdr_t)]; pUDP = (UDP*)&buffer[sizeof(eth_hdr_t) + sizeof(IPV4)]; pDHCP = (DHCP*)&buffer[sizeof(eth_hdr_t) + sizeof(IPV4) + sizeof(UDP)]; } while (pUDP->dst_port != 68); + printf("---------------------------------------------------------------\n"); + printf("- Send DHCP Request -------------------------------------------\n"); + printf("---------------------------------------------------------------\n"); Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst); DHCP_request_send(&packet, DHCP_MSG_DHCPREQUEST, eth_myself, ip_zero, ip_bcast, pDHCP); Eth_pkt_send(&packet); @@ -378,6 +365,9 @@ int main() sleep(500); continue; + printf("---------------------------------------------------------------\n"); + printf("- Send ARP Request --------------------------------------------\n"); + printf("---------------------------------------------------------------\n"); Eth_pkt_create(&packet, TYPE_PROTO_ARP, eth_myself, eth_bcst); ArpRequest(&packet, eth_myself, myIP, eth_zero, arpIpDst); Eth_pkt_send(&packet); @@ -386,16 +376,22 @@ int main() Eth_pkt_recv(buffer); pARP = (ARP*)&buffer[sizeof(eth_hdr_t)]; + printf("---------------------------------------------------------------\n"); + printf("- Send ICMP ---------------------------------------------------\n"); + printf("---------------------------------------------------------------\n"); Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, pARP->eth_addr_src); ICMPSendRequest(&packet, myIP, arpIpDst, data, sizeof(data)); Eth_pkt_send(&packet); + printf("---------------------------------------------------------------\n"); + printf("- Send ARP UDP ------------------------------------------------\n"); + printf("---------------------------------------------------------------\n"); Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, pARP->eth_addr_src); UDP_create(&packet, myIP, 10001, arpIpDst, 10002, data, sizeof(data)); Eth_pkt_send(&packet); continue; -*/ +#endif start = clock(); Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst);