static int e1000_txpoll(struct net_driver_s *dev) { struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private; int tail = e1000->tx_ring.tail; /* If the polling resulted in data that should be sent out on the network, * the field d_len is set to a value > 0. */ if (e1000->netdev.d_len > 0) { /* Look up the destination MAC address and add it to the Ethernet * header. */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(e1000->netdev.d_flags)) #endif { arp_out(&e1000->netdev); } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 else #endif { neighbor_out(&e1000->netdev); } #endif /* CONFIG_NET_IPv6 */ /* Send the packet */ e1000_transmit(e1000); /* Check if there is room in the device to hold another packet. If not, * return a non-zero value to terminate the poll. */ if (!e1000->tx_ring.desc[tail].desc_status) { return -1; } } /* If zero is returned, the polling will continue until all connections have * been examined. */ return 0; }
static int vnet_txpoll(struct net_driver_s *dev) { FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; /* If the polling resulted in data that should be sent out on the network, * the field d_len is set to a value > 0. */ if (vnet->sk_dev.d_len > 0) { /* Look up the destination MAC address and add it to the Ethernet * header. */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(vnet->sk_dev.d_flags)) #endif { arp_out(&vnet->sk_dev); } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 else #endif { neighbor_out(&vnet->sk_dev); } #endif /* CONFIG_NET_IPv6 */ /* Send the packet */ vnet_transmit(vnet); /* Check if there is room in the device to hold another packet. If not, * return a non-zero value to terminate the poll. */ if (vnet_is_txbuff_full(vnet->vnet)) { return 1; } } /* If zero is returned, the polling will continue until all connections have * been examined. */ return 0; }
static int bcmf_txpoll(FAR struct net_driver_s *dev) { FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private; wlinfo("Entry\n"); /* If the polling resulted in data that should be sent out on the network, * the field d_len is set to a value > 0. */ if (priv->bc_dev.d_len > 0) { /* Look up the destination MAC address and add it to the Ethernet * header. */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(priv->bc_dev.d_flags)) #endif { arp_out(&priv->bc_dev); } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 else #endif { neighbor_out(&priv->bc_dev); } #endif /* CONFIG_NET_IPv6 */ /* Send the packet */ bcmf_transmit(priv, priv->cur_tx_frame); /* Check if there is room in the device to hold another packet. If not, * return a non-zero value to terminate the poll. */ // TODO priv->cur_tx_frame = NULL; return 1; } /* If zero is returned, the polling will continue until all connections have * been examined. */ return 0; }
static int sim_txpoll(struct net_driver_s *dev) { /* If the polling resulted in data that should be sent out on the network, * the field d_len is set to a value > 0. */ if (g_sim_dev.d_len > 0) { /* Look up the destination MAC address and add it to the Ethernet * header. */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(&g_sim_dev)) #endif { arp_out(&g_sim_dev); } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 else #endif { neighbor_out(&g_sim_dev); } #endif /* CONFIG_NET_IPv6 */ /* Send the packet */ netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } /* If zero is returned, the polling will continue until all connections have * been examined. */ return 0; }
static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev, FAR void *pvconn, FAR void *pvpriv, uint16_t flags) { FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; FAR struct send_s *pstate = (FAR struct send_s *)pvpriv; #ifdef CONFIG_NETDEV_MULTINIC /* The TCP socket is connected and, hence, should be bound to a device. * Make sure that the polling device is the one that we are bound to. */ DEBUGASSERT(conn->dev != NULL); if (dev != conn->dev) { return flags; } #endif nllvdbg("flags: %04x acked: %d sent: %d\n", flags, pstate->snd_acked, pstate->snd_sent); /* If this packet contains an acknowledgement, then update the count of * acknowledged bytes. */ if ((flags & TCP_ACKDATA) != 0) { FAR struct tcp_hdr_s *tcp; /* Update the timeout */ #ifdef CONFIG_NET_SOCKOPTS pstate->snd_time = clock_systimer(); #endif /* Get the offset address of the TCP header */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET) #endif { DEBUGASSERT(IFF_IS_IPv4(dev->d_flags)); tcp = TCPIPv4BUF; } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 else #endif { DEBUGASSERT(IFF_IS_IPv6(dev->d_flags)); tcp = TCPIPv6BUF; } #endif /* CONFIG_NET_IPv6 */ /* The current acknowledgement number number is the (relative) offset * of the of the next byte needed by the receiver. The snd_isn is the * offset of the first byte to send to the receiver. The difference * is the number of bytes to be acknowledged. */ pstate->snd_acked = tcp_getsequence(tcp->ackno) - pstate->snd_isn; nllvdbg("ACK: acked=%d sent=%d buflen=%d\n", pstate->snd_acked, pstate->snd_sent, pstate->snd_buflen); /* Have all of the bytes in the buffer been sent and acknowledged? */ if (pstate->snd_acked >= pstate->snd_buflen) { /* Yes. Then pstate->snd_buflen should hold the number of bytes * actually sent. */ goto end_wait; } /* No.. fall through to send more data if necessary */ } /* Check if we are being asked to retransmit data */ else if ((flags & TCP_REXMIT) != 0) { /* Yes.. in this case, reset the number of bytes that have been sent * to the number of bytes that have been ACKed. */ pstate->snd_sent = pstate->snd_acked; #if defined(CONFIG_NET_TCP_SPLIT) /* Reset the even/odd indicator to even since we need to * retransmit. */ pstate->snd_odd = false; #endif /* Fall through to re-send data from the last that was ACKed */ } /* Check for a loss of connection */ else if ((flags & TCP_DISCONN_EVENTS) != 0) { /* Report not connected */ nllvdbg("Lost connection\n"); net_lostconnection(pstate->snd_sock, flags); pstate->snd_sent = -ENOTCONN; goto end_wait; } /* Check if the outgoing packet is available (it may have been claimed * by a sendto interrupt serving a different thread). */ #if 0 /* We can't really support multiple senders on the same TCP socket */ else if (dev->d_sndlen > 0) { /* Another thread has beat us sending data, wait for the next poll */ return flags; } #endif /* We get here if (1) not all of the data has been ACKed, (2) we have been * asked to retransmit data, (3) the connection is still healthy, and (4) * the outgoing packet is available for our use. In this case, we are * now free to send more data to receiver -- UNLESS the buffer contains * unprocessed incoming data. In that event, we will have to wait for the * next polling cycle. */ if ((flags & TCP_NEWDATA) == 0 && pstate->snd_sent < pstate->snd_buflen) { uint32_t seqno; /* Get the amount of data that we can send in the next packet */ uint32_t sndlen = pstate->snd_buflen - pstate->snd_sent; #if defined(CONFIG_NET_TCP_SPLIT) /* RFC 1122 states that a host may delay ACKing for up to 500ms but * must respond to every second segment). This logic here will trick * the RFC 1122 recipient into responding sooner. This logic will be * activated if: * * 1. An even number of packets has been send (where zero is an even * number), * 2. There is more data be sent (more than or equal to * CONFIG_NET_TCP_SPLIT_SIZE), but * 3. Not enough data for two packets. * * Then we will split the remaining, single packet into two partial * packets. This will stimulate the RFC 1122 peer to ACK sooner. * * Don't try to split very small packets (less than CONFIG_NET_TCP_SPLIT_SIZE). * Only the first even packet and the last odd packets could have * sndlen less than CONFIG_NET_TCP_SPLIT_SIZE. The value of sndlen on * the last even packet is guaranteed to be at least MSS/2 by the * logic below. */ if (sndlen >= CONFIG_NET_TCP_SPLIT_SIZE) { /* sndlen is the number of bytes remaining to be sent. * conn->mss will provide the number of bytes that can sent * in one packet. The difference, then, is the number of bytes * that would be sent in the next packet after this one. */ int32_t next_sndlen = sndlen - conn->mss; /* Is this the even packet in the packet pair transaction? */ if (!pstate->snd_odd) { /* next_sndlen <= 0 means that the entire remaining data * could fit into this single packet. This is condition * in which we must do the split. */ if (next_sndlen <= 0) { /* Split so that there will be an odd packet. Here * we know that 0 < sndlen <= MSS */ sndlen = (sndlen / 2) + 1; } } /* No... this is the odd packet in the packet pair transaction */ else { /* Will there be another (even) packet afer this one? * (next_sndlen > 0) Will the split condition occur on that * next, even packet? ((next_sndlen - conn->mss) < 0) If * so, then perform the split now to avoid the case where the * byte count is less than CONFIG_NET_TCP_SPLIT_SIZE on the * next pair. */ if (next_sndlen > 0 && (next_sndlen - conn->mss) < 0) { /* Here, we know that sndlen must be MSS < sndlen <= 2*MSS * and so (sndlen / 2) is <= MSS. */ sndlen /= 2; } } } /* Toggle the even/odd indicator */ pstate->snd_odd ^= true; #endif /* CONFIG_NET_TCP_SPLIT */ if (sndlen > conn->mss) { sndlen = conn->mss; } /* Check if we have "space" in the window */ if ((pstate->snd_sent - pstate->snd_acked + sndlen) < conn->winsize) { /* Set the sequence number for this packet. NOTE: The network updates * sndseq on receipt of ACK *before* this function is called. In that * case sndseq will point to the next unacknowledged byte (which might * have already been sent). We will overwrite the value of sndseq * here before the packet is sent. */ seqno = pstate->snd_sent + pstate->snd_isn; nllvdbg("SEND: sndseq %08x->%08x\n", conn->sndseq, seqno); tcp_setsequence(conn->sndseq, seqno); #ifdef NEED_IPDOMAIN_SUPPORT /* If both IPv4 and IPv6 support are enabled, then we will need to * select which one to use when generating the outgoing packet. * If only one domain is selected, then the setup is already in * place and we need do nothing. */ tcpsend_ipselect(dev, pstate); #endif /* Then set-up to send that amount of data. (this won't actually * happen until the polling cycle completes). */ devif_send(dev, &pstate->snd_buffer[pstate->snd_sent], sndlen); /* Check if the destination IP address is in the ARP or Neighbor * table. If not, then the send won't actually make it out... it * will be replaced with an ARP request or Neighbor Solicitation. */ if (pstate->snd_sent != 0 || psock_send_addrchck(conn)) { /* Update the amount of data sent (but not necessarily ACKed) */ pstate->snd_sent += sndlen; nllvdbg("SEND: acked=%d sent=%d buflen=%d\n", pstate->snd_acked, pstate->snd_sent, pstate->snd_buflen); } } } #ifdef CONFIG_NET_SOCKOPTS /* All data has been sent and we are just waiting for ACK or re-transmit * indications to complete the send. Check for a timeout. */ if (send_timeout(pstate)) { /* Yes.. report the timeout */ nlldbg("SEND timeout\n"); pstate->snd_sent = -ETIMEDOUT; goto end_wait; } #endif /* CONFIG_NET_SOCKOPTS */ /* Continue waiting */ return flags; end_wait: /* Do not allow any further callbacks */ pstate->snd_cb->flags = 0; pstate->snd_cb->priv = NULL; pstate->snd_cb->event = NULL; /* There are no outstanding, unacknowledged bytes */ conn->unacked = 0; /* Wake up the waiting thread */ sem_post(&pstate->snd_sem); return flags; }
static void emac_receive(FAR struct emac_driver_s *priv) { do { /* Check for errors and update statistics */ /* Check if the packet is a valid size for the network buffer configuration */ /* Copy the data data from the hardware to priv->d_dev.d_buf. Set * amount of data in priv->d_dev.d_len */ #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet tap */ pkt_input(&priv->d_dev); #endif /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 if (BUF->type == HTONS(ETHTYPE_IP)) { nllvdbg("IPv4 frame\n"); /* Handle ARP on input then give the IPv4 packet to the network * layer */ arp_ipin(&priv->d_dev); ipv4_input(&priv->d_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->d_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(priv->d_dev.d_flags)) #endif { arp_out(&priv->d_dev); } #ifdef CONFIG_NET_IPv6 else { neighbor_out(&priv->d_dev); } #endif /* And send the packet */ emac_transmit(priv); } } else #endif #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); /* Give the IPv6 packet to the network layer */ ipv6_input(&priv->d_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->d_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv4 if (IFF_IS_IPv4(priv->d_dev.d_flags)) { arp_out(&priv->d_dev); } else #endif #ifdef CONFIG_NET_IPv6 { neighbor_out(&priv->d_dev); } #endif /* And send the packet */ emac_transmit(priv); } } else #endif #ifdef CONFIG_NET_ARP if (BUF->type == htons(ETHTYPE_ARP)) { arp_arpin(&priv->d_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->d_dev.d_len > 0) { emac_transmit(priv); } } #endif } while (true); /* While there are more packets to be processed */ }
void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) { FAR struct udp_hdr_s *udp; nllvdbg("UDP payload: %d (%d) bytes\n", dev->d_sndlen, dev->d_len); if (dev->d_sndlen > 0) { /* Initialize the IP header. */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET || (conn->domain == PF_INET6 && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr))) #endif { /* Get pointers to the IPv4 header and the offset TCP header */ FAR struct ipv4_hdr_s *ipv4 = IPv4BUF; DEBUGASSERT(IFF_IS_IPv4(dev->d_flags)); udp = UDPIPv4BUF; /* Initialize the IPv4 header. */ ipv4->vhl = 0x45; ipv4->tos = 0; ++g_ipid; ipv4->ipid[0] = g_ipid >> 8; ipv4->ipid[1] = g_ipid & 0xff; ipv4->ipoffset[0] = 0; ipv4->ipoffset[1] = 0; ipv4->ttl = conn->ttl; ipv4->proto = IP_PROTO_UDP; net_ipv4addr_hdrcopy(ipv4->srcipaddr, &dev->d_ipaddr); #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET6 && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr)) { in_addr_t raddr = ip6_get_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr); net_ipv4addr_hdrcopy(ipv4->destipaddr, &raddr); } else #endif { net_ipv4addr_hdrcopy(ipv4->destipaddr, &conn->u.ipv4.raddr); } /* The total length to send is the size of the application data * plus the IPv4 and UDP headers (and, eventually, the link layer * header) */ dev->d_len = dev->d_sndlen + IPv4UDP_HDRLEN; /* The IPv4 length includes the size of the IPv4 header */ ipv4->len[0] = (dev->d_len >> 8); ipv4->len[1] = (dev->d_len & 0xff); /* Calculate IP checksum. */ ipv4->ipchksum = 0; ipv4->ipchksum = ~ipv4_chksum(dev); #ifdef CONFIG_NET_STATISTICS g_netstats.ipv4.sent++; #endif } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 else #endif {
static void e1000_receive(struct e1000_dev *e1000) { int head = e1000->rx_ring.head; unsigned char *cp = (unsigned char *) (e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE); int cnt; while (e1000->rx_ring.desc[head].desc_status) { /* Check for errors and update statistics */ /* Here we do not handle packets that exceed packet-buffer size */ if ((e1000->rx_ring.desc[head].desc_status & 3) == 1) { cprintf("NIC READ: Oversized packet\n"); goto next; } /* Check if the packet is a valid size for the uIP buffer configuration */ /* get the number of actual data-bytes in this packet */ cnt = e1000->rx_ring.desc[head].packet_length; if (cnt > CONFIG_NET_ETH_MTU || cnt < 14) { cprintf("NIC READ: invalid package size\n"); goto next; } /* Copy the data data from the hardware to e1000->netdev.d_buf. Set * amount of data in e1000->netdev.d_len */ /* now we try to copy these data-bytes to the UIP buffer */ memcpy(e1000->netdev.d_buf, cp, cnt); e1000->netdev.d_len = cnt; #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet tap */ pkt_input(&e1000->netdev); #endif /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 if (BUF->type == HTONS(ETHTYPE_IP)) { nllvdbg("IPv4 frame\n"); /* Handle ARP on input then give the IPv4 packet to the network * layer */ arp_ipin(&e1000->netdev); ipv4_input(&e1000->netdev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (e1000->netdev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(e1000->netdev.d_flags)) #endif { arp_out(&e1000->netdev); } #ifdef CONFIG_NET_IPv6 else { neighbor_out(&e1000->netdev); } #endif /* And send the packet */ e1000_transmit(e1000); } } else #endif #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); /* Give the IPv6 packet to the network layer */ ipv6_input(&e1000->netdev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (e1000->netdev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv4 if (IFF_IS_IPv4(e1000->netdev.d_flags)) { arp_out(&e1000->netdev); } else #endif #ifdef CONFIG_NET_IPv6 { neighbor_out(&e1000->netdev); } #endif /* And send the packet */ e1000_transmit(e1000); } } else #endif #ifdef CONFIG_NET_ARP if (BUF->type == htons(ETHTYPE_ARP)) { arp_arpin(&e1000->netdev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (e1000->netdev.d_len > 0) { e1000_transmit(e1000); } #endif } next: e1000->rx_ring.desc[head].desc_status = 0; e1000->rx_ring.head = (head + 1) % CONFIG_E1000_N_RX_DESC; e1000->rx_ring.free++; head = e1000->rx_ring.head; cp = (unsigned char *)(e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE); } }
static void bcmf_receive(FAR struct bcmf_dev_s *priv) { struct bcmf_frame_s *frame; // wlinfo("Entry\n"); do { /* Request frame buffer from bus interface */ frame = bcmf_bdc_rx_frame(priv); if (frame == NULL) { /* No more frame to process */ break; } if (!priv->bc_bifup) { /* Interface down, drop frame */ priv->bus->free_frame(priv, frame); continue; } priv->bc_dev.d_buf = frame->data; priv->bc_dev.d_len = frame->len - (uint32_t)(frame->data - frame->base); wlinfo("Got frame %p %d\n", frame, priv->bc_dev.d_len); #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet tap */ pkt_input(&priv->bc_dev); #endif /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 if (BUF->type == HTONS(ETHTYPE_IP)) { ninfo("IPv4 frame\n"); NETDEV_RXIPV4(&priv->bc_dev); /* Handle ARP on input then give the IPv4 packet to the network * layer */ arp_ipin(&priv->bc_dev); ipv4_input(&priv->bc_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->bc_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(priv->bc_dev.d_flags)) #endif { arp_out(&priv->bc_dev); } #ifdef CONFIG_NET_IPv6 else { neighbor_out(&kel->bc_dev); } #endif /* And send the packet */ bcmf_transmit(priv, frame); } else { /* Release RX frame buffer */ priv->bus->free_frame(priv, frame); } } else #endif #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(ETHTYPE_IP6)) { ninfo("Iv6 frame\n"); NETDEV_RXIPV6(&priv->bc_dev); /* Give the IPv6 packet to the network layer */ ipv6_input(&priv->bc_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->bc_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv4 if (IFF_IS_IPv4(priv->bc_dev.d_flags)) { arp_out(&priv->bc_dev); } else #endif #ifdef CONFIG_NET_IPv6 { neighbor_out(&priv->bc_dev); } #endif /* And send the packet */ bcmf_transmit(priv, frame); } else { /* Release RX frame buffer */ priv->bus->free_frame(priv, frame); } } else #endif #ifdef CONFIG_NET_ARP if (BUF->type == htons(ETHTYPE_ARP)) { arp_arpin(&priv->bc_dev); NETDEV_RXARP(&priv->bc_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->bc_dev.d_len > 0) { bcmf_transmit(priv, frame); } else { /* Release RX frame buffer */ priv->bus->free_frame(priv, frame); } } else #endif { wlerr("ERROR: RX dropped\n"); NETDEV_RXDROPPED(&priv->bc_dev); priv->bus->free_frame(priv, frame); } } while (1); /* While there are more packets to be processed */ }
void tcp_appsend(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, uint16_t result) { uint8_t hdrlen; /* Handle the result based on the application response */ nllvdbg("result: %04x d_sndlen: %d conn->unacked: %d\n", result, dev->d_sndlen, conn->unacked); /* Get the IP header length associated with the IP domain configured for * this TCP connection. */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET) #endif { DEBUGASSERT(IFF_IS_IPv4(dev->d_flags)); hdrlen = IPv4TCP_HDRLEN; } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 else #endif { DEBUGASSERT(IFF_IS_IPv6(dev->d_flags)); hdrlen = IPv6TCP_HDRLEN; } #endif /* CONFIG_NET_IPv6 */ /* Check for connection aborted */ if ((result & TCP_ABORT) != 0) { dev->d_sndlen = 0; conn->tcpstateflags = TCP_CLOSED; nllvdbg("TCP state: TCP_CLOSED\n"); tcp_send(dev, conn, TCP_RST | TCP_ACK, hdrlen); } /* Check for connection closed */ else if ((result & TCP_CLOSE) != 0) { conn->tcpstateflags = TCP_FIN_WAIT_1; conn->unacked = 1; conn->nrtx = 0; nllvdbg("TCP state: TCP_FIN_WAIT_1\n"); dev->d_sndlen = 0; tcp_send(dev, conn, TCP_FIN | TCP_ACK, hdrlen); } /* None of the above */ else { #ifdef CONFIG_NET_TCP_WRITE_BUFFERS DEBUGASSERT(dev->d_sndlen >= 0 && dev->d_sndlen <= conn->mss); #else /* If d_sndlen > 0, the application has data to be sent. */ if (dev->d_sndlen > 0) { /* Remember how much data we send out now so that we know * when everything has been acknowledged. Just increment the amount * of data sent. This will be needed in sequence number calculations * and we know that this is not a re-transmission. Retransmissions * do not go through this path. */ conn->unacked += dev->d_sndlen; /* The application cannot send more than what is allowed by the * MSS (the minumum of the MSS and the available window). */ DEBUGASSERT(dev->d_sndlen <= conn->mss); } conn->nrtx = 0; #endif /* Then handle the rest of the operation just as for the rexmit case */ tcp_rexmit(dev, conn, result); } }
void tcp_rexmit(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, uint16_t result) { uint8_t hdrlen; nllvdbg("result: %04x d_sndlen: %d conn->unacked: %d\n", result, dev->d_sndlen, conn->unacked); /* Get the IP header length associated with the IP domain configured for * this TCP connection. */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET) #endif { DEBUGASSERT(IFF_IS_IPv4(dev->d_flags)); hdrlen = IPv4TCP_HDRLEN; } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 else #endif { DEBUGASSERT(IFF_IS_IPv6(dev->d_flags)); hdrlen = IPv6TCP_HDRLEN; } #endif /* CONFIG_NET_IPv6 */ /* If the application has data to be sent, or if the incoming packet had * new data in it, we must send out a packet. */ #ifdef CONFIG_NET_TCP_WRITE_BUFFERS if (dev->d_sndlen > 0) #else if (dev->d_sndlen > 0 && conn->unacked > 0) #endif { /* We always set the ACK flag in response packets adding the length of * the IP and TCP headers. */ tcp_send(dev, conn, TCP_ACK | TCP_PSH, dev->d_sndlen + hdrlen); } /* If there is no data to send, just send out a pure ACK if one is requested`. */ else if ((result & TCP_SNDACK) != 0) { tcp_send(dev, conn, TCP_ACK, hdrlen); } /* There is nothing to do -- drop the packet */ else { dev->d_len = 0; } }
void netdriver_loop(void) { FAR struct eth_hdr_s *eth; /* Check for new frames. If so, then poll the network for new XMIT data */ net_lock(); (void)devif_poll(&g_sim_dev, sim_txpoll); net_unlock(); /* netdev_read will return 0 on a timeout event and >0 on a data received event */ g_sim_dev.d_len = netdev_read((FAR unsigned char *)g_sim_dev.d_buf, CONFIG_NET_ETH_MTU); /* Disable preemption through to the following so that it behaves a little more * like an interrupt (otherwise, the following logic gets pre-empted an behaves * oddly. */ sched_lock(); if (g_sim_dev.d_len > 0) { /* Data received event. Check for valid Ethernet header with destination == our * MAC address */ eth = BUF; if (g_sim_dev.d_len > ETH_HDRLEN) { int is_ours; /* Figure out if this ethernet frame is addressed to us. This affects * what we're willing to receive. Note that in promiscuous mode, the * up_comparemac will always return 0. */ is_ours = (up_comparemac(eth->dest, &g_sim_dev.d_mac.ether) == 0); #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet * tap. */ if (is_ours) { pkt_input(&g_sim_dev); } #endif /* CONFIG_NET_PKT */ /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 if (eth->type == HTONS(ETHTYPE_IP) && is_ours) { ninfo("IPv4 frame\n"); /* Handle ARP on input then give the IPv4 packet to the network * layer */ arp_ipin(&g_sim_dev); ipv4_input(&g_sim_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the global variable * d_len is set to a value > 0. */ if (g_sim_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(g_sim_dev.d_flags)) #endif { arp_out(&g_sim_dev); } #ifdef CONFIG_NET_IPv6 else { neighbor_out(&g_sim_dev); } #endif /* And send the packet */ netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } else #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 if (eth->type == HTONS(ETHTYPE_IP6) && is_ours) { ninfo("Iv6 frame\n"); /* Give the IPv6 packet to the network layer */ ipv6_input(&g_sim_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the global variable * d_len is set to a value > 0. */ if (g_sim_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv4 if (IFF_IS_IPv4(g_sim_dev.d_flags)) { arp_out(&g_sim_dev); } else #endif #ifdef CONFIG_NET_IPv6 { neighbor_out(&g_sim_dev); } #endif /* CONFIG_NET_IPv6 */ /* And send the packet */ netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } else #endif/* CONFIG_NET_IPv6 */ #ifdef CONFIG_NET_ARP if (eth->type == htons(ETHTYPE_ARP)) { arp_arpin(&g_sim_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the global variable * d_len is set to a value > 0. */ if (g_sim_dev.d_len > 0) { netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } else #endif { nwarn("WARNING: Unsupported Ethernet type %u\n", eth->type); } } } /* Otherwise, it must be a timeout event */ else if (timer_expired(&g_periodic_timer)) { timer_reset(&g_periodic_timer); devif_timer(&g_sim_dev, sim_txpoll); } sched_unlock(); }
static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, FAR void *pvconn, FAR void *pvpriv, uint16_t flags) { FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; FAR struct socket *psock = (FAR struct socket *)pvpriv; #ifdef CONFIG_NETDEV_MULTINIC /* The TCP socket is connected and, hence, should be bound to a device. * Make sure that the polling device is the one that we are bound to. */ DEBUGASSERT(conn->dev != NULL); if (dev != conn->dev) { return flags; } #endif ninfo("flags: %04x\n", flags); /* If this packet contains an acknowledgement, then update the count of * acknowledged bytes. */ if ((flags & TCP_ACKDATA) != 0) { FAR struct tcp_wrbuffer_s *wrb; FAR struct tcp_hdr_s *tcp; FAR sq_entry_t *entry; FAR sq_entry_t *next; uint32_t ackno; /* Get the offset address of the TCP header */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET) #endif { DEBUGASSERT(IFF_IS_IPv4(dev->d_flags)); tcp = TCPIPv4BUF; } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 else #endif { DEBUGASSERT(IFF_IS_IPv6(dev->d_flags)); tcp = TCPIPv6BUF; } #endif /* CONFIG_NET_IPv6 */ /* Get the ACK number from the TCP header */ ackno = tcp_getsequence(tcp->ackno); ninfo("ACK: ackno=%u flags=%04x\n", ackno, flags); /* Look at every write buffer in the unacked_q. The unacked_q * holds write buffers that have been entirely sent, but which * have not yet been ACKed. */ for (entry = sq_peek(&conn->unacked_q); entry; entry = next) { uint32_t lastseq; /* Check of some or all of this write buffer has been ACKed. */ next = sq_next(entry); wrb = (FAR struct tcp_wrbuffer_s *)entry; /* If the ACKed sequence number is greater than the start * sequence number of the write buffer, then some or all of * the write buffer has been ACKed. */ if (ackno > WRB_SEQNO(wrb)) { /* Get the sequence number at the end of the data */ lastseq = WRB_SEQNO(wrb) + WRB_PKTLEN(wrb); ninfo("ACK: wrb=%p seqno=%u lastseq=%u pktlen=%u ackno=%u\n", wrb, WRB_SEQNO(wrb), lastseq, WRB_PKTLEN(wrb), ackno); /* Has the entire buffer been ACKed? */ if (ackno >= lastseq) { ninfo("ACK: wrb=%p Freeing write buffer\n", wrb); /* Yes... Remove the write buffer from ACK waiting queue */ sq_rem(entry, &conn->unacked_q); /* And return the write buffer to the pool of free buffers */ tcp_wrbuffer_release(wrb); } else { unsigned int trimlen; /* No, then just trim the ACKed bytes from the beginning * of the write buffer. This will free up some I/O buffers * that can be reused while are still sending the last * buffers in the chain. */ trimlen = ackno - WRB_SEQNO(wrb); if (trimlen > WRB_SENT(wrb)) { /* More data has been ACKed then we have sent? */ trimlen = WRB_SENT(wrb); } ninfo("ACK: wrb=%p trim %u bytes\n", wrb, trimlen); WRB_TRIM(wrb, trimlen); WRB_SEQNO(wrb) = ackno; WRB_SENT(wrb) -= trimlen; /* Set the new sequence number for what remains */ ninfo("ACK: wrb=%p seqno=%u pktlen=%u\n", wrb, WRB_SEQNO(wrb), WRB_PKTLEN(wrb)); } } } /* A special case is the head of the write_q which may be partially * sent and so can still have un-ACKed bytes that could get ACKed * before the entire write buffer has even been sent. */ wrb = (FAR struct tcp_wrbuffer_s *)sq_peek(&conn->write_q); if (wrb && WRB_SENT(wrb) > 0 && ackno > WRB_SEQNO(wrb)) { uint32_t nacked; /* Number of bytes that were ACKed */ nacked = ackno - WRB_SEQNO(wrb); if (nacked > WRB_SENT(wrb)) { /* More data has been ACKed then we have sent? ASSERT? */ nacked = WRB_SENT(wrb); } ninfo("ACK: wrb=%p seqno=%u nacked=%u sent=%u ackno=%u\n", wrb, WRB_SEQNO(wrb), nacked, WRB_SENT(wrb), ackno); /* Trim the ACKed bytes from the beginning of the write buffer. */ WRB_TRIM(wrb, nacked); WRB_SEQNO(wrb) = ackno; WRB_SENT(wrb) -= nacked; ninfo("ACK: wrb=%p seqno=%u pktlen=%u sent=%u\n", wrb, WRB_SEQNO(wrb), WRB_PKTLEN(wrb), WRB_SENT(wrb)); } } /* Check for a loss of connection */ else if ((flags & TCP_DISCONN_EVENTS) != 0) { ninfo("Lost connection: %04x\n", flags); if (psock->s_conn != NULL) { /* Report not connected */ net_lostconnection(psock, flags); } /* Free write buffers and terminate polling */ psock_lost_connection(psock, conn); return flags; } /* Check if we are being asked to retransmit data */ else if ((flags & TCP_REXMIT) != 0) { FAR struct tcp_wrbuffer_s *wrb; FAR sq_entry_t *entry; ninfo("REXMIT: %04x\n", flags); /* If there is a partially sent write buffer at the head of the * write_q? Has anything been sent from that write buffer? */ wrb = (FAR struct tcp_wrbuffer_s *)sq_peek(&conn->write_q); ninfo("REXMIT: wrb=%p sent=%u\n", wrb, wrb ? WRB_SENT(wrb) : 0); if (wrb != NULL && WRB_SENT(wrb) > 0) { FAR struct tcp_wrbuffer_s *tmp; uint16_t sent; /* Yes.. Reset the number of bytes sent sent from the write buffer */ sent = WRB_SENT(wrb); if (conn->unacked > sent) { conn->unacked -= sent; } else { conn->unacked = 0; } if (conn->sent > sent) { conn->sent -= sent; } else { conn->sent = 0; } WRB_SENT(wrb) = 0; ninfo("REXMIT: wrb=%p sent=%u, conn unacked=%d sent=%d\n", wrb, WRB_SENT(wrb), conn->unacked, conn->sent); /* Increment the retransmit count on this write buffer. */ if (++WRB_NRTX(wrb) >= TCP_MAXRTX) { nwarn("WARNING: Expiring wrb=%p nrtx=%u\n", wrb, WRB_NRTX(wrb)); /* The maximum retry count as been exhausted. Remove the write * buffer at the head of the queue. */ tmp = (FAR struct tcp_wrbuffer_s *)sq_remfirst(&conn->write_q); DEBUGASSERT(tmp == wrb); UNUSED(tmp); /* And return the write buffer to the free list */ tcp_wrbuffer_release(wrb); /* NOTE expired is different from un-ACKed, it is designed to * represent the number of segments that have been sent, * retransmitted, and un-ACKed, if expired is not zero, the * connection will be closed. * * field expired can only be updated at TCP_ESTABLISHED state */ conn->expired++; } } /* Move all segments that have been sent but not ACKed to the write * queue again note, the un-ACKed segments are put at the head of the * write_q so they can be resent as soon as possible. */ while ((entry = sq_remlast(&conn->unacked_q)) != NULL) { wrb = (FAR struct tcp_wrbuffer_s *)entry; uint16_t sent; /* Reset the number of bytes sent sent from the write buffer */ sent = WRB_SENT(wrb); if (conn->unacked > sent) { conn->unacked -= sent; } else { conn->unacked = 0; } if (conn->sent > sent) { conn->sent -= sent; } else { conn->sent = 0; } WRB_SENT(wrb) = 0; ninfo("REXMIT: wrb=%p sent=%u, conn unacked=%d sent=%d\n", wrb, WRB_SENT(wrb), conn->unacked, conn->sent); /* Free any write buffers that have exceed the retry count */ if (++WRB_NRTX(wrb) >= TCP_MAXRTX) { nwarn("WARNING: Expiring wrb=%p nrtx=%u\n", wrb, WRB_NRTX(wrb)); /* Return the write buffer to the free list */ tcp_wrbuffer_release(wrb); /* NOTE expired is different from un-ACKed, it is designed to * represent the number of segments that have been sent, * retransmitted, and un-ACKed, if expired is not zero, the * connection will be closed. * * field expired can only be updated at TCP_ESTABLISHED state */ conn->expired++; continue; } else { /* Insert the write buffer into the write_q (in sequence * number order). The retransmission will occur below * when the write buffer with the lowest sequence number * is pulled from the write_q again. */ ninfo("REXMIT: Moving wrb=%p nrtx=%u\n", wrb, WRB_NRTX(wrb)); psock_insert_segment(wrb, &conn->write_q); } } } /* Check if the outgoing packet is available (it may have been claimed * by a sendto interrupt serving a different thread). */ if (dev->d_sndlen > 0) { /* Another thread has beat us sending data, wait for the next poll */ return flags; } /* We get here if (1) not all of the data has been ACKed, (2) we have been * asked to retransmit data, (3) the connection is still healthy, and (4) * the outgoing packet is available for our use. In this case, we are * now free to send more data to receiver -- UNLESS the buffer contains * unprocessed incoming data. In that event, we will have to wait for the * next polling cycle. */ if ((conn->tcpstateflags & TCP_ESTABLISHED) && (flags & (TCP_POLL | TCP_REXMIT)) && !(sq_empty(&conn->write_q))) { /* Check if the destination IP address is in the ARP or Neighbor * table. If not, then the send won't actually make it out... it * will be replaced with an ARP request or Neighbor Solicitation. */ if (psock_send_addrchck(conn)) { FAR struct tcp_wrbuffer_s *wrb; uint32_t predicted_seqno; size_t sndlen; /* Peek at the head of the write queue (but don't remove anything * from the write queue yet). We know from the above test that * the write_q is not empty. */ wrb = (FAR struct tcp_wrbuffer_s *)sq_peek(&conn->write_q); DEBUGASSERT(wrb); /* Get the amount of data that we can send in the next packet. * We will send either the remaining data in the buffer I/O * buffer chain, or as much as will fit given the MSS and current * window size. */ sndlen = WRB_PKTLEN(wrb) - WRB_SENT(wrb); if (sndlen > conn->mss) { sndlen = conn->mss; } if (sndlen > conn->winsize) { sndlen = conn->winsize; } ninfo("SEND: wrb=%p pktlen=%u sent=%u sndlen=%u\n", wrb, WRB_PKTLEN(wrb), WRB_SENT(wrb), sndlen); /* Set the sequence number for this segment. If we are * retransmitting, then the sequence number will already * be set for this write buffer. */ if (WRB_SEQNO(wrb) == (unsigned)-1) { WRB_SEQNO(wrb) = conn->isn + conn->sent; } /* The TCP stack updates sndseq on receipt of ACK *before* * this function is called. In that case sndseq will point * to the next unacknowledged byte (which might have already * been sent). We will overwrite the value of sndseq here * before the packet is sent. */ tcp_setsequence(conn->sndseq, WRB_SEQNO(wrb) + WRB_SENT(wrb)); #ifdef NEED_IPDOMAIN_SUPPORT /* If both IPv4 and IPv6 support are enabled, then we will need to * select which one to use when generating the outgoing packet. * If only one domain is selected, then the setup is already in * place and we need do nothing. */ send_ipselect(dev, psock); #endif /* Then set-up to send that amount of data with the offset * corresponding to the amount of data already sent. (this * won't actually happen until the polling cycle completes). */ devif_iob_send(dev, WRB_IOB(wrb), sndlen, WRB_SENT(wrb)); /* Remember how much data we send out now so that we know * when everything has been acknowledged. Just increment * the amount of data sent. This will be needed in sequence * number calculations. */ conn->unacked += sndlen; conn->sent += sndlen; /* Below prediction will become true, unless retransmission occurrence */ predicted_seqno = tcp_getsequence(conn->sndseq) + sndlen; if ((predicted_seqno > conn->sndseq_max) || (tcp_getsequence(conn->sndseq) > predicted_seqno)) /* overflow */ { conn->sndseq_max = predicted_seqno; } ninfo("SEND: wrb=%p nrtx=%u unacked=%u sent=%u\n", wrb, WRB_NRTX(wrb), conn->unacked, conn->sent); /* Increment the count of bytes sent from this write buffer */ WRB_SENT(wrb) += sndlen; ninfo("SEND: wrb=%p sent=%u pktlen=%u\n", wrb, WRB_SENT(wrb), WRB_PKTLEN(wrb)); /* Remove the write buffer from the write queue if the * last of the data has been sent from the buffer. */ DEBUGASSERT(WRB_SENT(wrb) <= WRB_PKTLEN(wrb)); if (WRB_SENT(wrb) >= WRB_PKTLEN(wrb)) { FAR struct tcp_wrbuffer_s *tmp; ninfo("SEND: wrb=%p Move to unacked_q\n", wrb); tmp = (FAR struct tcp_wrbuffer_s *)sq_remfirst(&conn->write_q); DEBUGASSERT(tmp == wrb); UNUSED(tmp); /* Put the I/O buffer chain in the un-acked queue; the * segment is waiting for ACK again */ psock_insert_segment(wrb, &conn->unacked_q); } /* Only one data can be sent by low level driver at once, * tell the caller stop polling the other connection. */ flags &= ~TCP_POLL; } } /* Continue waiting */ return flags; }
static void misoc_net_receive(FAR struct misoc_net_driver_s *priv) { uint8_t rxslot; uint32_t rxlen; do { /* Check for errors and update statistics */ /* Check if the packet is a valid size for the network buffer * configuration. */ /* Find rx slot */ rxslot = ethmac_sram_writer_slot_read(); /* Get rx len */ rxlen = ethmac_sram_writer_length_read(); /* Copy the data data from the hardware to priv->misoc_net_dev.d_buf. Set * amount of data in priv->misoc_net_dev.d_len * * NOTE: These memcpy's could be avoided by simply setting the d_buf * pointer to the rx*_buf containing the received data. Some additional * buffer management logic would also be required. */ misoc_flush_dcache(); if (rxslot) { memcpy(priv->misoc_net_dev.d_buf, priv->rx1_buf, rxlen); } else { memcpy(priv->misoc_net_dev.d_buf, priv->rx0_buf, rxlen); } /* Clear event pending */ ethmac_sram_writer_ev_pending_write(1); priv->misoc_net_dev.d_len = rxlen; #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet tap */ pkt_input(&priv->misoc_net_dev); #endif /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 if (BUF->type == HTONS(ETHTYPE_IP)) { ninfo("IPv4 frame\n"); NETDEV_RXIPV4(&priv->misoc_net_dev); /* Handle ARP on input then give the IPv4 packet to the network * layer */ arp_ipin(&priv->misoc_net_dev); ipv4_input(&priv->misoc_net_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->misoc_net_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(priv->misoc_net_dev.d_flags)) #endif { arp_out(&priv->misoc_net_dev); } #ifdef CONFIG_NET_IPv6 else { neighbor_out(&kel->misoc_net_dev); } #endif /* And send the packet */ misoc_net_transmit(priv); } } else #endif #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(ETHTYPE_IP6)) { ninfo("Iv6 frame\n"); NETDEV_RXIPV6(&priv->misoc_net_dev); /* Give the IPv6 packet to the network layer */ ipv6_input(&priv->misoc_net_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->misoc_net_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv4 if (IFF_IS_IPv4(priv->misoc_net_dev.d_flags)) { arp_out(&priv->misoc_net_dev); } else #endif #ifdef CONFIG_NET_IPv6 { neighbor_out(&priv->misoc_net_dev); } #endif /* And send the packet */ misoc_net_transmit(priv); } } else #endif #ifdef CONFIG_NET_ARP if (BUF->type == htons(ETHTYPE_ARP)) { arp_arpin(&priv->misoc_net_dev); NETDEV_RXARP(&priv->misoc_net_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->misoc_net_dev.d_len > 0) { misoc_net_transmit(priv); } } #endif else { NETDEV_RXDROPPED(&priv->misoc_net_dev); } } while (ethmac_sram_writer_ev_pending_read() & ETHMAC_EV_SRAM_WRITER); }
void rtos_vnet_recv(struct rgmp_vnet *rgmp_vnet, char *data, int len) { struct vnet_driver_s *vnet = rgmp_vnet->priv; do { /* Check if the packet is a valid size for the network buffer * configuration. */ if (len > CONFIG_NET_ETH_MTU || len < 14) { #ifdef CONFIG_DEBUG cprintf("VNET: receive invalid packet of size %d\n", len); #endif return; } /* Copy the data data from the hardware to vnet->sk_dev.d_buf. Set * amount of data in vnet->sk_dev.d_len */ memcpy(vnet->sk_dev.d_buf, data, len); vnet->sk_dev.d_len = len; #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet tap */ pkt_input(&vnet->sk_dev); #endif /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 if (BUF->type == HTONS(ETHTYPE_IP)) { nllvdbg("IPv4 frame\n"); /* Handle ARP on input then give the IPv4 packet to the network * layer */ arp_ipin(&vnet->sk_dev); ipv4_input(&vnet->sk_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (vnet->sk_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(vnet->sk_dev.d_flags)) #endif { arp_out(&vnet->sk_dev); } #ifdef CONFIG_NET_IPv6 else { neighbor_out(&vnet->sk_dev); } #endif /* And send the packet */ vnet_transmit(vnet); } } else #endif #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); /* Give the IPv6 packet to the network layer */ ipv6_input(&vnet->sk_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (vnet->sk_dev.d_len > 0) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv4 if (IFF_IS_IPv4(vnet->sk_dev.d_flags)) { arp_out(&vnet->sk_dev); } else #endif #ifdef CONFIG_NET_IPv6 { neighbor_out(&vnet->sk_dev); } #endif /* And send the packet */ vnet_transmit(vnet); } } else #endif #ifdef CONFIG_NET_ARP if (BUF->type == htons(ETHTYPE_ARP)) { arp_arpin(&vnet->sk_dev); /* If the above function invocation resulted in data that should * be sent out on the network, the field d_len will set to a * value > 0. */ if (vnet->sk_dev.d_len > 0) { vnet_transmit(vnet); } } #endif } while (0); /* While there are more packets to be processed */ }