X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fnet%2Fsandbox.c;h=d538d379bbec77cb54c7072b63480218f3d456dd;hb=a51897b6c1e517ea2ce95da59784e84c5992dd00;hp=cb69a95d97f83b070e4277ec26188329e52559e8;hpb=d87a457be8f156ca6e775ffa785a96b0766d4e50;p=u-boot diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c index cb69a95d97..d538d379bb 100644 --- a/drivers/net/sandbox.c +++ b/drivers/net/sandbox.c @@ -11,6 +11,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -24,11 +25,35 @@ DECLARE_GLOBAL_DATA_PTR; */ struct eth_sandbox_priv { uchar fake_host_hwaddr[ARP_HLEN]; - IPaddr_t fake_host_ipaddr; + struct in_addr fake_host_ipaddr; uchar *recv_packet_buffer; int recv_packet_length; }; +static bool disabled[8] = {false}; +static bool skip_timeout; + +/* + * sandbox_eth_disable_response() + * + * index - The alias index (also DM seq number) + * disable - If non-zero, ignore sent packets and don't send mock response + */ +void sandbox_eth_disable_response(int index, bool disable) +{ + disabled[index] = disable; +} + +/* + * sandbox_eth_skip_timeout() + * + * When the first packet read is attempted, fast-forward time + */ +void sandbox_eth_skip_timeout(void) +{ + skip_timeout = true; +} + static int sb_eth_start(struct udevice *dev) { struct eth_sandbox_priv *priv = dev_get_priv(dev); @@ -48,6 +73,10 @@ static int sb_eth_send(struct udevice *dev, void *packet, int length) debug("eth_sandbox: Send packet %d\n", length); + if (dev->seq >= 0 && dev->seq < ARRAY_SIZE(disabled) && + disabled[dev->seq]) + return 0; + if (ntohs(eth->et_protlen) == PROT_ARP) { struct arp_hdr *arp = packet + ETHER_HDR_SIZE; @@ -56,7 +85,7 @@ static int sb_eth_send(struct udevice *dev, void *packet, int length) struct arp_hdr *arp_recv; /* store this as the assumed IP of the fake host */ - priv->fake_host_ipaddr = NetReadIP(&arp->ar_tpa); + priv->fake_host_ipaddr = net_read_ip(&arp->ar_tpa); /* Formulate a fake response */ eth_recv = (void *)priv->recv_packet_buffer; memcpy(eth_recv->et_dest, eth->et_src, ARP_HLEN); @@ -73,9 +102,9 @@ static int sb_eth_send(struct udevice *dev, void *packet, int length) arp_recv->ar_op = htons(ARPOP_REPLY); memcpy(&arp_recv->ar_sha, priv->fake_host_hwaddr, ARP_HLEN); - NetWriteIP(&arp_recv->ar_spa, priv->fake_host_ipaddr); + net_write_ip(&arp_recv->ar_spa, priv->fake_host_ipaddr); memcpy(&arp_recv->ar_tha, &arp->ar_sha, ARP_HLEN); - NetCopyIP(&arp_recv->ar_tpa, &arp->ar_spa); + net_copy_ip(&arp_recv->ar_tpa, &arp->ar_spa); priv->recv_packet_length = ETHER_HDR_SIZE + ARP_HDR_SIZE; @@ -104,9 +133,9 @@ static int sb_eth_send(struct udevice *dev, void *packet, int length) ARP_HLEN); ipr->ip_sum = 0; ipr->ip_off = 0; - NetCopyIP((void *)&ipr->ip_dst, &ip->ip_src); - NetWriteIP((void *)&ipr->ip_src, - priv->fake_host_ipaddr); + net_copy_ip((void *)&ipr->ip_dst, &ip->ip_src); + net_write_ip((void *)&ipr->ip_src, + priv->fake_host_ipaddr); ipr->ip_sum = compute_ip_checksum(ipr, IP_HDR_SIZE); @@ -123,10 +152,15 @@ static int sb_eth_send(struct udevice *dev, void *packet, int length) return 0; } -static int sb_eth_recv(struct udevice *dev, uchar **packetp) +static int sb_eth_recv(struct udevice *dev, int flags, uchar **packetp) { struct eth_sandbox_priv *priv = dev_get_priv(dev); + if (skip_timeout) { + sandbox_timer_add_offset(11000UL); + skip_timeout = false; + } + if (priv->recv_packet_length) { int lcl_recv_packet_length = priv->recv_packet_length;