Reworked 802.15.4 header creation and parsing so that it works regardless of the size of the rimeaddr_t typedef

This commit is contained in:
adamdunkels 2010-02-18 21:00:28 +00:00
parent 2fbf21b2b3
commit f5c48751b5
3 changed files with 29 additions and 28 deletions

View File

@ -44,7 +44,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: frame802154.c,v 1.3 2009/09/09 21:08:46 adamdunkels Exp $ * $Id: frame802154.c,v 1.4 2010/02/18 21:00:28 adamdunkels Exp $
*/ */
/* /*
* \brief This file is where the main functions that relate to frame * \brief This file is where the main functions that relate to frame
@ -217,7 +217,7 @@ frame802154_create(frame802154_t *p, uint8_t *buf, uint8_t buf_len)
/* Destination address */ /* Destination address */
for(c = flen.dest_addr_len; c > 0; c--) { for(c = flen.dest_addr_len; c > 0; c--) {
tx_frame_buffer[pos++] = p->dest_addr.u8[c - 1]; tx_frame_buffer[pos++] = p->dest_addr[c - 1];
} }
/* Source PAN ID */ /* Source PAN ID */
@ -228,7 +228,7 @@ frame802154_create(frame802154_t *p, uint8_t *buf, uint8_t buf_len)
/* Source address */ /* Source address */
for(c = flen.src_addr_len; c > 0; c--) { for(c = flen.src_addr_len; c > 0; c--) {
tx_frame_buffer[pos++] = p->src_addr.u8[c - 1]; tx_frame_buffer[pos++] = p->src_addr[c - 1];
} }
/* Aux header */ /* Aux header */
@ -291,18 +291,18 @@ frame802154_parse(uint8_t *data, uint8_t len, frame802154_t *pf)
/* } */ /* } */
/* p += l; */ /* p += l; */
if(fcf.dest_addr_mode == FRAME802154_SHORTADDRMODE) { if(fcf.dest_addr_mode == FRAME802154_SHORTADDRMODE) {
rimeaddr_copy(&(pf->dest_addr), &rimeaddr_null); rimeaddr_copy((rimeaddr_t *)&(pf->dest_addr), &rimeaddr_null);
pf->dest_addr.u8[0] = p[1]; pf->dest_addr[0] = p[1];
pf->dest_addr.u8[1] = p[0]; pf->dest_addr[1] = p[0];
p += 2; p += 2;
} else if(fcf.dest_addr_mode == FRAME802154_LONGADDRMODE) { } else if(fcf.dest_addr_mode == FRAME802154_LONGADDRMODE) {
for(c = 0; c < 8; c++) { for(c = 0; c < 8; c++) {
pf->dest_addr.u8[c] = p[7 - c]; pf->dest_addr[c] = p[7 - c];
} }
p += 8; p += 8;
} }
} else { } else {
rimeaddr_copy(&(pf->dest_addr), &rimeaddr_null); rimeaddr_copy((rimeaddr_t *)&(pf->dest_addr), &rimeaddr_null);
pf->dest_pid = 0; pf->dest_pid = 0;
} }
@ -323,18 +323,18 @@ frame802154_parse(uint8_t *data, uint8_t len, frame802154_t *pf)
/* } */ /* } */
/* p += l; */ /* p += l; */
if(fcf.src_addr_mode == FRAME802154_SHORTADDRMODE) { if(fcf.src_addr_mode == FRAME802154_SHORTADDRMODE) {
rimeaddr_copy(&(pf->src_addr), &rimeaddr_null); rimeaddr_copy((rimeaddr_t *)&(pf->src_addr), &rimeaddr_null);
pf->src_addr.u8[0] = p[1]; pf->src_addr[0] = p[1];
pf->src_addr.u8[1] = p[0]; pf->src_addr[1] = p[0];
p += 2; p += 2;
} else if(fcf.src_addr_mode == FRAME802154_LONGADDRMODE) { } else if(fcf.src_addr_mode == FRAME802154_LONGADDRMODE) {
for(c = 0; c < 8; c++) { for(c = 0; c < 8; c++) {
pf->src_addr.u8[c] = p[7 - c]; pf->src_addr[c] = p[7 - c];
} }
p += 8; p += 8;
} }
} else { } else {
rimeaddr_copy(&(pf->src_addr), &rimeaddr_null); rimeaddr_copy((rimeaddr_t *)&(pf->src_addr), &rimeaddr_null);
pf->src_pid = 0; pf->src_pid = 0;
} }

View File

@ -54,7 +54,7 @@
* This file converts to and from a structure to a packed 802.15.4 * This file converts to and from a structure to a packed 802.15.4
* frame. * frame.
* *
* $Id: frame802154.h,v 1.2 2009/04/09 21:54:09 nifi Exp $ * $Id: frame802154.h,v 1.3 2010/02/18 21:00:28 adamdunkels Exp $
*/ */
@ -151,9 +151,9 @@ typedef struct {
frame802154_fcf_t fcf; /**< Frame control field */ frame802154_fcf_t fcf; /**< Frame control field */
uint8_t seq; /**< Sequence number */ uint8_t seq; /**< Sequence number */
uint16_t dest_pid; /**< Destination PAN ID */ uint16_t dest_pid; /**< Destination PAN ID */
rimeaddr_t dest_addr; /**< Destination address */ uint8_t dest_addr[8]; /**< Destination address */
uint16_t src_pid; /**< Source PAN ID */ uint16_t src_pid; /**< Source PAN ID */
rimeaddr_t src_addr; /**< Source address */ uint8_t src_addr[8]; /**< Source address */
frame802154_aux_hdr_t aux_hdr; /**< Aux security header */ frame802154_aux_hdr_t aux_hdr; /**< Aux security header */
uint8_t *payload; /**< Pointer to 802.15.4 frame payload */ uint8_t *payload; /**< Pointer to 802.15.4 frame payload */
uint8_t payload_len; /**< Length of payload field */ uint8_t payload_len; /**< Length of payload field */

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: framer-802154.c,v 1.2 2009/10/20 07:42:03 nifi Exp $ * $Id: framer-802154.c,v 1.3 2010/02/18 21:00:28 adamdunkels Exp $
*/ */
/** /**
@ -54,8 +54,8 @@
#endif #endif
static uint8_t mac_dsn; static uint8_t mac_dsn;
static uint16_t mac_dst_pan_id = IEEE802154_PANID; const static uint16_t mac_dst_pan_id = IEEE802154_PANID;
static uint16_t mac_src_pan_id = IEEE802154_PANID; const static uint16_t mac_src_pan_id = IEEE802154_PANID;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
@ -83,7 +83,7 @@ create(void)
params.fcf.frame_type = FRAME802154_DATAFRAME; params.fcf.frame_type = FRAME802154_DATAFRAME;
params.fcf.security_enabled = 0; params.fcf.security_enabled = 0;
params.fcf.frame_pending = 0; params.fcf.frame_pending = 0;
params.fcf.ack_required = packetbuf_attr(PACKETBUF_ATTR_RELIABLE); params.fcf.ack_required = 1; //packetbuf_attr(PACKETBUF_ATTR_RELIABLE);
params.fcf.panid_compression = 0; params.fcf.panid_compression = 0;
/* Insert IEEE 802.15.4 (2003) version bit. */ /* Insert IEEE 802.15.4 (2003) version bit. */
@ -108,11 +108,12 @@ create(void)
if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) { if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) {
/* Broadcast requires short address mode. */ /* Broadcast requires short address mode. */
params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE;
params.dest_addr.u8[0] = 0xFF; params.dest_addr[0] = 0xFF;
params.dest_addr.u8[1] = 0xFF; params.dest_addr[1] = 0xFF;
} else { } else {
rimeaddr_copy(&params.dest_addr, packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); rimeaddr_copy((rimeaddr_t *)&params.dest_addr,
packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
params.fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; params.fcf.dest_addr_mode = FRAME802154_LONGADDRMODE;
} }
@ -123,7 +124,7 @@ create(void)
* Set up the source address using only the long address mode for * Set up the source address using only the long address mode for
* phase 1. * phase 1.
*/ */
rimeaddr_copy(&params.src_addr, &rimeaddr_node_addr); rimeaddr_copy((rimeaddr_t *)&params.src_addr, &rimeaddr_node_addr);
params.payload = packetbuf_dataptr(); params.payload = packetbuf_dataptr();
params.payload_len = packetbuf_datalen(); params.payload_len = packetbuf_datalen();
@ -157,11 +158,11 @@ parse(void)
PRINTF("P6MAC: for another pan %u\n", frame.dest_pid); PRINTF("P6MAC: for another pan %u\n", frame.dest_pid);
return 0; return 0;
} }
if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr.u8)) { if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &frame.dest_addr); packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (rimeaddr_t *)&frame.dest_addr);
} }
} }
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &frame.src_addr); packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (rimeaddr_t *)&frame.src_addr);
packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, frame.fcf.ack_required); packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, frame.fcf.ack_required);
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq); packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq);