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:
parent
2fbf21b2b3
commit
f5c48751b5
|
@ -44,7 +44,7 @@
|
|||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* 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
|
||||
|
@ -217,7 +217,7 @@ frame802154_create(frame802154_t *p, uint8_t *buf, uint8_t buf_len)
|
|||
|
||||
/* Destination address */
|
||||
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 */
|
||||
|
@ -228,7 +228,7 @@ frame802154_create(frame802154_t *p, uint8_t *buf, uint8_t buf_len)
|
|||
|
||||
/* Source address */
|
||||
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 */
|
||||
|
@ -291,18 +291,18 @@ frame802154_parse(uint8_t *data, uint8_t len, frame802154_t *pf)
|
|||
/* } */
|
||||
/* p += l; */
|
||||
if(fcf.dest_addr_mode == FRAME802154_SHORTADDRMODE) {
|
||||
rimeaddr_copy(&(pf->dest_addr), &rimeaddr_null);
|
||||
pf->dest_addr.u8[0] = p[1];
|
||||
pf->dest_addr.u8[1] = p[0];
|
||||
rimeaddr_copy((rimeaddr_t *)&(pf->dest_addr), &rimeaddr_null);
|
||||
pf->dest_addr[0] = p[1];
|
||||
pf->dest_addr[1] = p[0];
|
||||
p += 2;
|
||||
} else if(fcf.dest_addr_mode == FRAME802154_LONGADDRMODE) {
|
||||
for(c = 0; c < 8; c++) {
|
||||
pf->dest_addr.u8[c] = p[7 - c];
|
||||
pf->dest_addr[c] = p[7 - c];
|
||||
}
|
||||
p += 8;
|
||||
}
|
||||
} else {
|
||||
rimeaddr_copy(&(pf->dest_addr), &rimeaddr_null);
|
||||
rimeaddr_copy((rimeaddr_t *)&(pf->dest_addr), &rimeaddr_null);
|
||||
pf->dest_pid = 0;
|
||||
}
|
||||
|
||||
|
@ -323,18 +323,18 @@ frame802154_parse(uint8_t *data, uint8_t len, frame802154_t *pf)
|
|||
/* } */
|
||||
/* p += l; */
|
||||
if(fcf.src_addr_mode == FRAME802154_SHORTADDRMODE) {
|
||||
rimeaddr_copy(&(pf->src_addr), &rimeaddr_null);
|
||||
pf->src_addr.u8[0] = p[1];
|
||||
pf->src_addr.u8[1] = p[0];
|
||||
rimeaddr_copy((rimeaddr_t *)&(pf->src_addr), &rimeaddr_null);
|
||||
pf->src_addr[0] = p[1];
|
||||
pf->src_addr[1] = p[0];
|
||||
p += 2;
|
||||
} else if(fcf.src_addr_mode == FRAME802154_LONGADDRMODE) {
|
||||
for(c = 0; c < 8; c++) {
|
||||
pf->src_addr.u8[c] = p[7 - c];
|
||||
pf->src_addr[c] = p[7 - c];
|
||||
}
|
||||
p += 8;
|
||||
}
|
||||
} else {
|
||||
rimeaddr_copy(&(pf->src_addr), &rimeaddr_null);
|
||||
rimeaddr_copy((rimeaddr_t *)&(pf->src_addr), &rimeaddr_null);
|
||||
pf->src_pid = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
* This file converts to and from a structure to a packed 802.15.4
|
||||
* 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 */
|
||||
uint8_t seq; /**< Sequence number */
|
||||
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 */
|
||||
rimeaddr_t src_addr; /**< Source address */
|
||||
uint8_t src_addr[8]; /**< Source address */
|
||||
frame802154_aux_hdr_t aux_hdr; /**< Aux security header */
|
||||
uint8_t *payload; /**< Pointer to 802.15.4 frame payload */
|
||||
uint8_t payload_len; /**< Length of payload field */
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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
|
||||
|
||||
static uint8_t mac_dsn;
|
||||
static uint16_t mac_dst_pan_id = IEEE802154_PANID;
|
||||
static uint16_t mac_src_pan_id = IEEE802154_PANID;
|
||||
const static uint16_t mac_dst_pan_id = IEEE802154_PANID;
|
||||
const static uint16_t mac_src_pan_id = IEEE802154_PANID;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
|
@ -83,7 +83,7 @@ create(void)
|
|||
params.fcf.frame_type = FRAME802154_DATAFRAME;
|
||||
params.fcf.security_enabled = 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;
|
||||
|
||||
/* Insert IEEE 802.15.4 (2003) version bit. */
|
||||
|
@ -108,22 +108,23 @@ create(void)
|
|||
if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) {
|
||||
/* Broadcast requires short address mode. */
|
||||
params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE;
|
||||
params.dest_addr.u8[0] = 0xFF;
|
||||
params.dest_addr.u8[1] = 0xFF;
|
||||
params.dest_addr[0] = 0xFF;
|
||||
params.dest_addr[1] = 0xFF;
|
||||
|
||||
} else {
|
||||
rimeaddr_copy(¶ms.dest_addr, packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
|
||||
rimeaddr_copy((rimeaddr_t *)¶ms.dest_addr,
|
||||
packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
|
||||
params.fcf.dest_addr_mode = FRAME802154_LONGADDRMODE;
|
||||
}
|
||||
|
||||
/* Set the source PAN ID to the global variable. */
|
||||
params.src_pid = mac_src_pan_id;
|
||||
|
||||
|
||||
/*
|
||||
* Set up the source address using only the long address mode for
|
||||
* phase 1.
|
||||
*/
|
||||
rimeaddr_copy(¶ms.src_addr, &rimeaddr_node_addr);
|
||||
rimeaddr_copy((rimeaddr_t *)¶ms.src_addr, &rimeaddr_node_addr);
|
||||
|
||||
params.payload = packetbuf_dataptr();
|
||||
params.payload_len = packetbuf_datalen();
|
||||
|
@ -157,11 +158,11 @@ parse(void)
|
|||
PRINTF("P6MAC: for another pan %u\n", frame.dest_pid);
|
||||
return 0;
|
||||
}
|
||||
if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr.u8)) {
|
||||
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &frame.dest_addr);
|
||||
if(!is_broadcast_addr(frame.fcf.dest_addr_mode, 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_PACKET_ID, frame.seq);
|
||||
|
||||
|
|
Loading…
Reference in a new issue