Move no-framer from slip-radio to os, now named nullframer

This commit is contained in:
Simon Duquennoy 2017-09-10 15:18:44 +02:00
parent 9cde0886d6
commit 7d262d6d89
3 changed files with 42 additions and 72 deletions

View File

@ -9,7 +9,7 @@ endif
CONTIKI=../../.. CONTIKI=../../..
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
PROJECT_SOURCEFILES += slip-net.c no-framer.c PROJECT_SOURCEFILES += slip-net.c
ifeq ($(TARGET),sky) ifeq ($(TARGET),sky)
PROJECT_SOURCEFILES += slip-radio-cc2420.c slip-radio-sky-sensors.c PROJECT_SOURCEFILES += slip-radio-cc2420.c slip-radio-sky-sensors.c
endif endif

View File

@ -53,8 +53,7 @@ extern const struct slip_radio_sensors SLIP_RADIO_CONF_SENSORS;
#endif #endif
void slip_send_packet(const uint8_t *ptr, int len); void slip_send_packet(const uint8_t *ptr, int len);
void no_framer_parse_802154_frame(void);
/* max 16 packets at the same time??? */ /* max 16 packets at the same time??? */
uint8_t packet_ids[16]; uint8_t packet_ids[16];
int packet_pos; int packet_pos;
@ -73,6 +72,45 @@ CMD_HANDLERS(CMD_CONF_HANDLERS);
#else #else
CMD_HANDLERS(slip_radio_cmd_handler); CMD_HANDLERS(slip_radio_cmd_handler);
#endif #endif
static const uint16_t mac_src_pan_id = IEEE802154_PANID;
/*---------------------------------------------------------------------------*/
static int
is_broadcast_addr(uint8_t mode, uint8_t *addr)
{
int i = mode == FRAME802154_SHORTADDRMODE ? 2 : 8;
while(i-- > 0) {
if(addr[i] != 0xff) {
return 0;
}
}
return 1;
}
/*---------------------------------------------------------------------------*/
static int
parse_frame(void)
{
frame802154_t frame;
int len;
len = packetbuf_datalen();
if(frame802154_parse(packetbuf_dataptr(), len, &frame)) {
if(frame.fcf.dest_addr_mode) {
if(frame.dest_pid != mac_src_pan_id &&
frame.dest_pid != FRAME802154_BROADCASTPANDID) {
/* Packet to another PAN */
return 0;
}
if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
}
}
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
return 0;
}
return 0;
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
packet_sent(void *ptr, int status, int transmissions) packet_sent(void *ptr, int status, int transmissions)
@ -123,7 +161,7 @@ slip_radio_cmd_handler(const uint8_t *data, int len)
data[2], packetbuf_datalen()); data[2], packetbuf_datalen());
/* parse frame before sending to get addresses, etc. */ /* parse frame before sending to get addresses, etc. */
no_framer_parse_802154_frame(); parse_frame();
NETSTACK_MAC.send(packet_sent, &packet_ids[packet_pos]); NETSTACK_MAC.send(packet_sent, &packet_ids[packet_pos]);
packet_pos++; packet_pos++;

View File

@ -36,44 +36,7 @@
* Joakim Eriksson <joakime@sics.se> * Joakim Eriksson <joakime@sics.se>
*/ */
#include "net/mac/framer/framer.h" #include "net/mac/framer/framer.h"
#include "net/mac/framer/frame802154.h"
#include "net/packetbuf.h"
#include <string.h>
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINTADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7])
#else
#define PRINTF(...)
#define PRINTADDR(addr)
#endif
/** \brief The 16-bit identifier of the PAN on which the device is
* sending to. If this value is 0xffff, the device is not
* associated.
*/
static const uint16_t mac_dst_pan_id = IEEE802154_PANID;
/** \brief The 16-bit identifier of the PAN on which the device is
* operating. If this value is 0xffff, the device is not
* associated.
*/
static const uint16_t mac_src_pan_id = IEEE802154_PANID;
/*---------------------------------------------------------------------------*/
static int
is_broadcast_addr(uint8_t mode, uint8_t *addr)
{
int i = mode == FRAME802154_SHORTADDRMODE ? 2 : 8;
while(i-- > 0) {
if(addr[i] != 0xff) {
return 0;
}
}
return 1;
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
hdr_length(void) hdr_length(void)
@ -95,37 +58,6 @@ parse(void)
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int
no_framer_parse_802154_frame(void)
{
frame802154_t frame;
int len;
len = packetbuf_datalen();
if(frame802154_parse(packetbuf_dataptr(), len, &frame)) {
if(frame.fcf.dest_addr_mode) {
if(frame.dest_pid != mac_src_pan_id &&
frame.dest_pid != FRAME802154_BROADCASTPANDID) {
/* Packet to another PAN */
PRINTF("15.4: for another pan %u\n", frame.dest_pid);
return 0;
}
if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
}
}
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
PRINTF("15.4-IN: %2X", frame.fcf.frame_type);
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
PRINTF("%u (%u)\n", packetbuf_datalen(), len);
return 0;
}
return 0;
}
/*---------------------------------------------------------------------------*/
const struct framer no_framer = { const struct framer no_framer = {
hdr_length, hdr_length,
create, create,