drivers/kw2xrf/kw2xrf.c: fix bug and cleanup _assemble_tx_buf
BUG: the pktbuf was released at the wrong place and return value of _assemble_tx_buf was not verified.
This commit is contained in:
parent
24f7182ebe
commit
63fd7dc53a
@ -1104,30 +1104,25 @@ void kw2xrf_isr_event(gnrc_netdev_t *netdev, uint32_t event_type)
|
|||||||
int _assemble_tx_buf(kw2xrf_t *dev, gnrc_pktsnip_t *pkt)
|
int _assemble_tx_buf(kw2xrf_t *dev, gnrc_pktsnip_t *pkt)
|
||||||
{
|
{
|
||||||
gnrc_netif_hdr_t *hdr;
|
gnrc_netif_hdr_t *hdr;
|
||||||
int index = 0;
|
int index = 4;
|
||||||
|
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
gnrc_pktbuf_release(pkt);
|
return 0;
|
||||||
return -ENODEV;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get netif header check address length */
|
/* get netif header check address length */
|
||||||
hdr = (gnrc_netif_hdr_t *)pkt->data;
|
hdr = (gnrc_netif_hdr_t *)pkt->data;
|
||||||
|
|
||||||
/* FCF, set up data frame, request for ack, panid_compression */
|
/* we are building a data frame here */
|
||||||
/* TODO: Currently we don´t request for Ack in this device.
|
dev->buf[1] = IEEE802154_FCF_TYPE_DATA;
|
||||||
* since this is a soft_mac device this has to be
|
dev->buf[2] = IEEE802154_FCF_VERS_V0;
|
||||||
* handled in a upcoming CSMA-MAC layer.
|
|
||||||
*/
|
|
||||||
/*if (dev->option & KW2XRF_OPT_AUTOACK) {
|
|
||||||
dev->buf[1] = 0x61;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dev->buf[1] = 0x51;
|
|
||||||
}*/
|
|
||||||
dev->buf[1] = 0x51;
|
|
||||||
|
|
||||||
index = 4;
|
/* if AUTOACK is enabled, then we also expect ACKs for this packet */
|
||||||
|
if (!(hdr->flags & GNRC_NETIF_HDR_FLAGS_BROADCAST) &&
|
||||||
|
!(hdr->flags & GNRC_NETIF_HDR_FLAGS_MULTICAST) &&
|
||||||
|
(dev->option & KW2XRF_OPT_AUTOACK)) {
|
||||||
|
dev->buf[1] |= IEEE802154_FCF_ACK_REQ;
|
||||||
|
}
|
||||||
|
|
||||||
/* set destination pan_id */
|
/* set destination pan_id */
|
||||||
dev->buf[index++] = (uint8_t)((dev->radio_pan) & 0xff);
|
dev->buf[index++] = (uint8_t)((dev->radio_pan) & 0xff);
|
||||||
@ -1136,13 +1131,13 @@ int _assemble_tx_buf(kw2xrf_t *dev, gnrc_pktsnip_t *pkt)
|
|||||||
/* fill in destination address */
|
/* fill in destination address */
|
||||||
if (hdr->flags &
|
if (hdr->flags &
|
||||||
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
|
||||||
dev->buf[2] = IEEE802154_FCF_DST_ADDR_SHORT;
|
dev->buf[2] |= IEEE802154_FCF_DST_ADDR_SHORT;
|
||||||
dev->buf[index++] = 0xff;
|
dev->buf[index++] = 0xff;
|
||||||
dev->buf[index++] = 0xff;
|
dev->buf[index++] = 0xff;
|
||||||
}
|
}
|
||||||
else if (hdr->dst_l2addr_len == 2) {
|
else if (hdr->dst_l2addr_len == 2) {
|
||||||
/* set to short addressing mode */
|
/* set to short addressing mode */
|
||||||
dev->buf[2] = IEEE802154_FCF_DST_ADDR_SHORT;
|
dev->buf[2] |= IEEE802154_FCF_DST_ADDR_SHORT;
|
||||||
/* set destination address, byte order is inverted */
|
/* set destination address, byte order is inverted */
|
||||||
uint8_t *dst_addr = gnrc_netif_hdr_get_dst_addr(hdr);
|
uint8_t *dst_addr = gnrc_netif_hdr_get_dst_addr(hdr);
|
||||||
dev->buf[index++] = dst_addr[1];
|
dev->buf[index++] = dst_addr[1];
|
||||||
@ -1158,19 +1153,17 @@ int _assemble_tx_buf(kw2xrf_t *dev, gnrc_pktsnip_t *pkt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gnrc_pktbuf_release(pkt);
|
return 0;
|
||||||
return -ENOMSG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fill in source PAN ID (if applicable */
|
/* fill in source PAN ID (if applicable */
|
||||||
/* FIXME: compare with at86rf2xx, currently not working
|
|
||||||
if (dev->option & KW2XRF_OPT_USE_SRC_PAN) {
|
if (dev->option & KW2XRF_OPT_USE_SRC_PAN) {
|
||||||
dev->buf[index++] = (uint8_t)((dev->radio_pan) & 0xff);
|
dev->buf[index++] = (uint8_t)((dev->radio_pan) & 0xff);
|
||||||
dev->buf[index++] = (uint8_t)((dev->radio_pan) >> 8);
|
dev->buf[index++] = (uint8_t)((dev->radio_pan) >> 8);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
dev->buf[1] |= IEEE802154_FCF_PAN_COMP;
|
dev->buf[1] |= IEEE802154_FCF_PAN_COMP;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/* insert source address according to length */
|
/* insert source address according to length */
|
||||||
if (hdr->src_l2addr_len == 2) {
|
if (hdr->src_l2addr_len == 2) {
|
||||||
@ -1209,6 +1202,11 @@ int kw2xrf_send(gnrc_netdev_t *netdev, gnrc_pktsnip_t *pkt)
|
|||||||
if (pkt->type == GNRC_NETTYPE_NETIF) {
|
if (pkt->type == GNRC_NETTYPE_NETIF) {
|
||||||
/* Build header and fills this already into the tx-buf */
|
/* Build header and fills this already into the tx-buf */
|
||||||
index = _assemble_tx_buf(dev, pkt);
|
index = _assemble_tx_buf(dev, pkt);
|
||||||
|
if (index == 0) {
|
||||||
|
DEBUG("Unable to create 802.15.4 header\n");
|
||||||
|
gnrc_pktbuf_release(pkt);
|
||||||
|
return -ENOMSG;
|
||||||
|
}
|
||||||
DEBUG("Assembled header for GNRC_NETTYPE_UNDEF to tx-buf, index: %i\n", index);
|
DEBUG("Assembled header for GNRC_NETTYPE_UNDEF to tx-buf, index: %i\n", index);
|
||||||
}
|
}
|
||||||
else if (pkt->type == GNRC_NETTYPE_UNDEF) {
|
else if (pkt->type == GNRC_NETTYPE_UNDEF) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user