Skip to content
Snippets Groups Projects
Commit 2f179f26 authored by Kaspar Schleiser's avatar Kaspar Schleiser
Browse files

sys/net/gnrc/netif: adapt to netdev with iolist

parent c935a075
No related branches found
No related tags found
No related merge requests found
......@@ -135,26 +135,22 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
hdr.dst[0], hdr.dst[1], hdr.dst[2],
hdr.dst[3], hdr.dst[4], hdr.dst[5]);
size_t n;
payload = gnrc_pktbuf_get_iovec(pkt, &n); /* use payload as temporary
* variable */
res = -ENOBUFS;
if (payload != NULL) {
pkt = payload; /* reassign for later release; vec_snip is prepended to pkt */
struct iovec *vector = (struct iovec *)pkt->data;
vector[0].iov_base = (char *)&hdr;
vector[0].iov_len = sizeof(ethernet_hdr_t);
iolist_t iolist = {
.iol_next = (iolist_t *)payload,
.iol_base = &hdr,
.iol_len = sizeof(ethernet_hdr_t)
};
#ifdef MODULE_NETSTATS_L2
if ((netif_hdr->flags & GNRC_NETIF_HDR_FLAGS_BROADCAST) ||
(netif_hdr->flags & GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
dev->stats.tx_mcast_count++;
}
else {
dev->stats.tx_unicast_count++;
}
#endif
res = dev->driver->send(dev, vector, n);
if ((netif_hdr->flags & GNRC_NETIF_HDR_FLAGS_BROADCAST) ||
(netif_hdr->flags & GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
dev->stats.tx_mcast_count++;
}
else {
dev->stats.tx_unicast_count++;
}
#endif
res = dev->driver->send(dev, &iolist);
gnrc_pktbuf_release(pkt);
......
......@@ -168,10 +168,9 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
netdev_t *dev = netif->dev;
netdev_ieee802154_t *state = (netdev_ieee802154_t *)netif->dev;
gnrc_netif_hdr_t *netif_hdr;
gnrc_pktsnip_t *vec_snip;
const uint8_t *src, *dst = NULL;
int res = 0;
size_t n, src_len, dst_len;
size_t src_len, dst_len;
uint8_t mhr[IEEE802154_MAX_HDR_LEN];
uint8_t flags = (uint8_t)(state->flags & NETDEV_IEEE802154_SEND_MASK);
le_uint16_t dev_pan = byteorder_btols(byteorder_htons(state->pan));
......@@ -211,38 +210,34 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
DEBUG("_send_ieee802154: Error preperaring frame\n");
return -EINVAL;
}
/* prepare packet for sending */
vec_snip = gnrc_pktbuf_get_iovec(pkt, &n);
if (vec_snip != NULL) {
struct iovec *vector;
pkt = vec_snip; /* reassign for later release; vec_snip is prepended to pkt */
vector = (struct iovec *)pkt->data;
vector[0].iov_base = mhr;
vector[0].iov_len = (size_t)res;
/* prepare iolist for netdev / mac layer */
iolist_t iolist = {
.iol_next = (iolist_t *)pkt->next,
.iol_base = mhr,
.iol_len = (size_t)res
};
#ifdef MODULE_NETSTATS_L2
if (netif_hdr->flags &
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
netif->dev->stats.tx_mcast_count++;
}
else {
netif->dev->stats.tx_unicast_count++;
}
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
netif->dev->stats.tx_mcast_count++;
}
else {
netif->dev->stats.tx_unicast_count++;
}
#endif
#ifdef MODULE_GNRC_MAC
if (netif->mac.mac_info & GNRC_NETIF_MAC_INFO_CSMA_ENABLED) {
res = csma_sender_csma_ca_send(dev, vector, n, &netif->mac.csma_conf);
}
else {
res = dev->driver->send(dev, vector, n);
}
#else
res = dev->driver->send(dev, vector, n);
#endif
if (netif->mac.mac_info & GNRC_NETIF_MAC_INFO_CSMA_ENABLED) {
res = csma_sender_csma_ca_send(dev, &iolist, &netif->mac.csma_conf);
}
else {
return -ENOBUFS;
res = dev->driver->send(dev, &iolist);
}
#else
res = dev->driver->send(dev, &iolist);
#endif
/* release old data */
gnrc_pktbuf_release(pkt);
return res;
......
......@@ -92,27 +92,20 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
{
gnrc_pktsnip_t *vector;
int res = -ENOBUFS;
size_t n;
if (pkt->type == GNRC_NETTYPE_NETIF) {
/* we don't need the netif snip: remove it */
pkt = gnrc_pktbuf_remove_snip(pkt, pkt);
}
/* prepare packet for sending */
vector = gnrc_pktbuf_get_iovec(pkt, &n);
if (vector != NULL) {
/* reassign for later release; vector is prepended to pkt */
pkt = vector;
struct iovec *v = (struct iovec *)vector->data;
netdev_t *dev = netif->dev;
netdev_t *dev = netif->dev;
#ifdef MODULE_NETSTATS_L2
dev->stats.tx_unicast_count++;
dev->stats.tx_unicast_count++;
#endif
res = dev->driver->send(dev, v, n);
}
res = dev->driver->send(dev, (iolist_t *)pkt);
/* release old data */
gnrc_pktbuf_release(pkt);
return res;
......
......@@ -37,8 +37,7 @@ static msg_t _main_msg_queue[MSG_QUEUE_SIZE];
static uint8_t tmp_buffer[ETHERNET_DATA_LEN];
static size_t tmp_buffer_bytes = 0;
static int _dump_send_packet(netdev_t *netdev, const struct iovec *vector,
int count)
static int _dump_send_packet(netdev_t *netdev, const iolist_t *iolist)
{
int res;
......@@ -55,13 +54,13 @@ static int _dump_send_packet(netdev_t *netdev, const struct iovec *vector,
printf("unknown ");
}
puts("device:");
for (int i = 0; i < count; i++) {
if ((tmp_buffer_bytes + vector[i].iov_len) > ETHERNET_DATA_LEN) {
for (const iolist_t *iol = iolist; iol; iol = iol->iol_next) {
size_t len = iol->iol_len;
if ((tmp_buffer_bytes + len) > ETHERNET_DATA_LEN) {
return -ENOBUFS;
}
memcpy(&tmp_buffer[tmp_buffer_bytes], vector[i].iov_base,
vector[i].iov_len);
tmp_buffer_bytes += vector[i].iov_len;
memcpy(&tmp_buffer[tmp_buffer_bytes], iol->iol_base, len);
tmp_buffer_bytes += len;
}
od_hex_dump(tmp_buffer, tmp_buffer_bytes, OD_WIDTH_DEFAULT);
res = (int)tmp_buffer_bytes;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment