/** * Should allocate a pbuf and transfer the bytes of the incoming * packet from the interface into the pbuf. * * @param netif the lwip network interface structure for this g2100if * @return a pbuf filled with the received packet (including MAC header) * NULL on memory error */ static struct pbuf * low_level_input(struct netif *netif) { struct g2100if *g2100if = netif->state; struct pbuf *p, *q; u16_t len; /* Obtain the size of the packet and put it into the "len" variable. */ // *** len = zg_get_rx_status(); #if ETH_PAD_SIZE len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ #endif /* We allocate a pbuf chain of pbufs from the pool. */ p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); if (p != NULL) { #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif /* We iterate over the pbuf chain until we have read the entire * packet into the pbuf. */ for(q = p; q != NULL; q = q->next) { /* Read enough bytes to fill this pbuf in the chain. The * available data in the pbuf is given by the q->len * variable. */ // *** //read data into(q->payload, q->len); memcpy(&zg_buf, q->payload, q->len); } // *** //acknowledge that packet has been read(); zg_clear_rx_status(); #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif LINK_STATS_INC(link.recv); } else { // *** //drop packet(); zg_clear_rx_status(); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); } return p; }
Packet *macGetPacket(void) { // Returns NULL on error uint16_t l = zg_get_rx_status(); Packet *p = (Packet *)mmalloc(sizeof(Packet)); if (p == NULL) { return NULL; } p->dLength = l; if (l > 0) { p->d = (uint8_t *)mmalloc(l * sizeof(uint8_t)); if (p->d != NULL) { for (uint16_t i = 0; i < l; i++) { p->d[i] = zg_buf[i]; } } } else { p->d = NULL; } return p; }
u8_t nic_poll(void) { u16_t packetLength; // Connection lost, retry if(zg_get_conn_state() != 1) { // Include debug functionalities, if required #if(VNET_DEBUG) // Print address VNET_LOG("(vNet)WiFi Connection lost, retry"); VNET_LOG("\r\n"); #endif while(zg_get_conn_state() != 1){ zg_drv_process(); } } // This method place the incoming data directly into the uIP buffer packetLength = zg_get_rx_status(); // Process the in/out data from the Wifi controller zg_drv_process(); // If there are no incoming data if(!packetLength) return packetLength = 0; // If the lenght exceed the buffer size if(packetLength > UIP_BUFSIZE) return packetLength = 0; // Return the lenght return packetLength; }
unsigned int network_read(void) { return zg_get_rx_status(); }