diff options
| author | Peter Lawrence <[email protected]> | 2020-10-24 20:27:57 -0500 |
|---|---|---|
| committer | Peter Lawrence <[email protected]> | 2020-10-24 20:27:57 -0500 |
| commit | a097b7e51aac7fc92708e1bc536e84a9ec2af3ec (patch) | |
| tree | ce49f6b51b2c2f169e9e5def66eb2eab10075d3b /examples | |
| parent | f5b72f5796554910e14040cf747d6eea9505ee1a (diff) | |
net_device: re-factor code so as to not be specific to lwIP
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/device/net_lwip_webserver/src/main.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/examples/device/net_lwip_webserver/src/main.c b/examples/device/net_lwip_webserver/src/main.c index 020f4e4d6..27adce86f 100644 --- a/examples/device/net_lwip_webserver/src/main.c +++ b/examples/device/net_lwip_webserver/src/main.c @@ -99,7 +99,7 @@ static err_t linkoutput_fn(struct netif *netif, struct pbuf *p) /* if the network driver can accept another packet, we make it happen */ if (tud_network_can_xmit()) { - tud_network_xmit(p); + tud_network_xmit(p, 0 /* unused for this example */); return ERR_OK; } @@ -152,17 +152,49 @@ bool dns_query_proc(const char *name, ip_addr_t *addr) return false; } -bool tud_network_recv_cb(struct pbuf *p) +bool tud_network_recv_cb(const uint8_t *src, uint16_t size) { /* this shouldn't happen, but if we get another packet before parsing the previous, we must signal our inability to accept it */ if (received_frame) return false; - /* store away the pointer for service_traffic() to later handle */ - received_frame = p; + if (size) + { + struct pbuf *p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL); + + if (p) + { + /* pbuf_alloc() has already initialized struct; all we need to do is copy the data */ + memcpy(p->payload, src, size); + + /* store away the pointer for service_traffic() to later handle */ + received_frame = p; + } + } + return true; } +uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg) +{ + struct pbuf *p = (struct pbuf *)ref; + struct pbuf *q; + uint16_t len = 0; + + (void)arg; /* unused for this example */ + + /* traverse the "pbuf chain"; see ./lwip/src/core/pbuf.c for more info */ + for(q = p; q != NULL; q = q->next) + { + memcpy(dst, (char *)q->payload, q->len); + dst += q->len; + len += q->len; + if (q->len == q->tot_len) break; + } + + return len; +} + static void service_traffic(void) { /* handle any packet received by tud_network_recv_cb() */ |
