commit
8ab89c473a
@ -0,0 +1,11 @@
|
||||
PKG_NAME=emb6
|
||||
PKG_URL=https://github.com/hso-esk/emb6.git
|
||||
PKG_VERSION=14e4a3cfff01644e078870e14e16a1fe60dcc895
|
||||
PKG_BUILDDIR ?= $(BINDIRBASE)/pkg/$(BOARD)/$(PKG_NAME)
|
||||
|
||||
.PHONY: all
|
||||
|
||||
all: git-download
|
||||
"$(MAKE)" -C $(PKG_BUILDDIR)
|
||||
|
||||
include $(RIOTBASE)/pkg/pkg.mk
|
@ -0,0 +1,71 @@
|
||||
PKG_BUILDDIR ?= $(BINDIRBASE)/pkg/$(BOARD)/emb6
|
||||
EMB6_DIR := $(PKG_BUILDDIR)
|
||||
EMB6_CONTRIB := $(RIOTBASE)/pkg/emb6/contrib
|
||||
|
||||
INCLUDES += -I$(PKG_BUILDDIR)/target
|
||||
INCLUDES += -I$(RIOTBASE)/pkg/emb6/include
|
||||
|
||||
ifeq (,$(filter emb6_router,$(USEMODULE)))
|
||||
CFLAGS += -DEMB6_CONF_ROUTER=FALSE
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_bsp,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/target/bsp
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_common,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/emb6
|
||||
INCLUDES += -I$(EMB6_DIR)/emb6
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_contrib,$(USEMODULE)))
|
||||
DIRS += $(EMB6_CONTRIB)
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_conn_udp,$(USEMODULE)))
|
||||
DIRS += $(EMB6_CONTRIB)/conn/udp
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_ipv6,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/emb6/src/net/ipv6
|
||||
INCLUDES += -I$(EMB6_DIR)/emb6/inc/net/ipv6
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_ipv6_multicast,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/emb6/src/net/ipv6/multicast
|
||||
INCLUDES += -I$(EMB6_DIR)/emb6/inc/net/ipv6/multicast
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_llsec,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/emb6/src/mac/llsec
|
||||
INCLUDES += -I$(EMB6_DIR)/emb6/inc/mac/llsec
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_mac,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/emb6/src/mac
|
||||
INCLUDES += -I$(EMB6_DIR)/emb6/inc/mac
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_netdev2,$(USEMODULE)))
|
||||
DIRS += $(EMB6_CONTRIB)/netdev2
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_rpl,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/emb6/src/net/rpl
|
||||
INCLUDES += -I$(EMB6_DIR)/emb6/inc/net/rpl
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_sicslowpan,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/emb6/src/net/sicslowpan
|
||||
INCLUDES += -I$(EMB6_DIR)/emb6/inc/net/sicslowpan
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_sock,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/emb6/src/tport
|
||||
INCLUDES += -I$(EMB6_DIR)/emb6/inc/tport
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_utils,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/utils/src
|
||||
INCLUDES += -I$(EMB6_DIR)/utils/inc
|
||||
endif
|
@ -0,0 +1,3 @@
|
||||
MODULE = emb6_contrib
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include "emb6/netdev2.h"
|
||||
|
||||
#include "etimer.h"
|
||||
#include "board_conf.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
uint8_t board_conf(s_ns_t *ps_nStack)
|
||||
{
|
||||
if (ps_nStack != NULL) {
|
||||
ps_nStack->inif = &emb6_netdev2_driver;
|
||||
etimer_init();
|
||||
return ps_nStack->inif->init(ps_nStack);
|
||||
}
|
||||
else {
|
||||
DEBUG("Network stack pointer is NULL");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** @} */
|
@ -0,0 +1,3 @@
|
||||
MODULE = emb6_conn_udp
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "evproc.h"
|
||||
#include "msg.h"
|
||||
#include "mutex.h"
|
||||
#include "net/af.h"
|
||||
#include "net/conn/udp.h"
|
||||
#include "net/ipv6/hdr.h"
|
||||
#include "sched.h"
|
||||
#include "uip.h"
|
||||
|
||||
#define _MSG_TYPE_CLOSE (0x4123)
|
||||
#define _MSG_TYPE_RCV (0x4124)
|
||||
|
||||
/* struct to describe a sendto command for emb6 thread */
|
||||
typedef struct {
|
||||
struct udp_socket sock;
|
||||
mutex_t mutex;
|
||||
const void *data;
|
||||
int res;
|
||||
uint16_t data_len;
|
||||
} _send_cmd_t;
|
||||
|
||||
extern uint16_t uip_slen;
|
||||
|
||||
static bool send_registered = false;
|
||||
|
||||
static void _input_callback(struct udp_socket *c, void *ptr,
|
||||
const uip_ipaddr_t *src_addr, uint16_t src_port,
|
||||
const uip_ipaddr_t *dst_addr, uint16_t dst_port,
|
||||
const uint8_t *data, uint16_t datalen);
|
||||
static void _output_callback(c_event_t c_event, p_data_t p_data);
|
||||
|
||||
static int _reg_and_bind(struct udp_socket *c, void *ptr,
|
||||
udp_socket_input_callback_t cb, uint16_t port)
|
||||
{
|
||||
if (udp_socket_register(c, ptr, cb) < 0) {
|
||||
return -EMFILE;
|
||||
}
|
||||
if (udp_socket_bind(c, port) < 0) {
|
||||
udp_socket_close(c);
|
||||
return -EALREADY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int conn_udp_create(conn_udp_t *conn, const void *addr, size_t addr_len,
|
||||
int family, uint16_t port)
|
||||
{
|
||||
int res;
|
||||
|
||||
(void)addr;
|
||||
(void)addr_len;
|
||||
if (family != AF_INET6) {
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
if (conn->sock.input_callback != NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
mutex_init(&conn->mutex);
|
||||
mutex_lock(&conn->mutex);
|
||||
if ((res = _reg_and_bind(&conn->sock, conn, _input_callback, port)) < 0) {
|
||||
conn->sock.input_callback = NULL;
|
||||
mutex_unlock(&conn->mutex);
|
||||
return res;
|
||||
}
|
||||
conn->waiting_thread = KERNEL_PID_UNDEF;
|
||||
mutex_unlock(&conn->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void conn_udp_close(conn_udp_t *conn)
|
||||
{
|
||||
if (conn->sock.input_callback != NULL) {
|
||||
mutex_lock(&conn->mutex);
|
||||
if (conn->waiting_thread != KERNEL_PID_UNDEF) {
|
||||
msg_t msg;
|
||||
msg.type = _MSG_TYPE_CLOSE;
|
||||
msg.content.ptr = (char *)conn;
|
||||
mutex_unlock(&conn->mutex);
|
||||
msg_send(&msg, conn->waiting_thread);
|
||||
mutex_lock(&conn->mutex);
|
||||
}
|
||||
udp_socket_close(&conn->sock);
|
||||
conn->sock.input_callback = NULL;
|
||||
mutex_unlock(&conn->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
int conn_udp_getlocaladdr(conn_udp_t *conn, void *addr, uint16_t *port)
|
||||
{
|
||||
if (conn->sock.input_callback != NULL) {
|
||||
mutex_lock(&conn->mutex);
|
||||
memset(addr, 0, sizeof(ipv6_addr_t));
|
||||
*port = NTOHS(conn->sock.udp_conn->lport);
|
||||
mutex_unlock(&conn->mutex);
|
||||
return sizeof(ipv6_addr_t);
|
||||
}
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
int conn_udp_recvfrom(conn_udp_t *conn, void *data, size_t max_len, void *addr,
|
||||
size_t *addr_len, uint16_t *port)
|
||||
{
|
||||
int res = -EIO;
|
||||
msg_t msg;
|
||||
|
||||
if (conn->sock.input_callback == NULL) {
|
||||
return -ENOTSOCK;
|
||||
}
|
||||
mutex_lock(&conn->mutex);
|
||||
if (conn->waiting_thread != KERNEL_PID_UNDEF) {
|
||||
mutex_unlock(&conn->mutex);
|
||||
return -EALREADY;
|
||||
}
|
||||
conn->waiting_thread = sched_active_pid;
|
||||
mutex_unlock(&conn->mutex);
|
||||
msg_receive(&msg);
|
||||
if (msg.type == _MSG_TYPE_CLOSE) {
|
||||
conn->waiting_thread = KERNEL_PID_UNDEF;
|
||||
return -EINTR;
|
||||
}
|
||||
else if (msg.type == _MSG_TYPE_RCV) {
|
||||
mutex_lock(&conn->mutex);
|
||||
if (msg.content.ptr == (char *)conn) {
|
||||
if (max_len < conn->recv_info.datalen) {
|
||||
conn->waiting_thread = KERNEL_PID_UNDEF;
|
||||
mutex_unlock(&conn->mutex);
|
||||
return -ENOBUFS;
|
||||
}
|
||||
memcpy(data, conn->recv_info.data, conn->recv_info.datalen);
|
||||
memcpy(addr, conn->recv_info.src, sizeof(ipv6_addr_t));
|
||||
*addr_len = sizeof(ipv6_addr_t);
|
||||
*port = conn->recv_info.src_port;
|
||||
res = (int)conn->recv_info.datalen;
|
||||
}
|
||||
conn->waiting_thread = KERNEL_PID_UNDEF;
|
||||
mutex_unlock(&conn->mutex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int conn_udp_sendto(const void *data, size_t len, const void *src, size_t src_len,
|
||||
const void *dst, size_t dst_len, int family, uint16_t sport,
|
||||
uint16_t dport)
|
||||
{
|
||||
int res;
|
||||
_send_cmd_t send_cmd;
|
||||
|
||||
if (!send_registered) {
|
||||
if (evproc_regCallback(EVENT_TYPE_CONN_SEND, _output_callback) != E_SUCCESS) {
|
||||
return -EIO;
|
||||
}
|
||||
else {
|
||||
send_registered = true;
|
||||
}
|
||||
}
|
||||
mutex_init(&send_cmd.mutex);
|
||||
if ((len > (UIP_BUFSIZE - (UIP_LLH_LEN + UIP_IPUDPH_LEN))) ||
|
||||
(len > UINT16_MAX)) {
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
if ((dst_len > sizeof(ipv6_addr_t)) || (family != AF_INET6)) {
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
mutex_lock(&send_cmd.mutex);
|
||||
send_cmd.data = data;
|
||||
send_cmd.data_len = (uint16_t)len;
|
||||
if ((res = _reg_and_bind(&send_cmd.sock, NULL, NULL, sport)) < 0) {
|
||||
mutex_unlock(&send_cmd.mutex);
|
||||
return res;
|
||||
}
|
||||
udp_socket_connect(&send_cmd.sock, (uip_ipaddr_t *)dst, dport); /* can't fail at this point */
|
||||
/* change to emb6 thread context */
|
||||
if (evproc_putEvent(E_EVPROC_TAIL, EVENT_TYPE_CONN_SEND, &send_cmd) != E_SUCCESS) {
|
||||
udp_socket_close(&send_cmd.sock);
|
||||
mutex_unlock(&send_cmd.mutex);
|
||||
return -EIO;
|
||||
}
|
||||
/* block thread until data was send */
|
||||
mutex_lock(&send_cmd.mutex);
|
||||
udp_socket_close(&send_cmd.sock);
|
||||
mutex_unlock(&send_cmd.mutex);
|
||||
|
||||
return send_cmd.res;
|
||||
}
|
||||
|
||||
static void _input_callback(struct udp_socket *c, void *ptr,
|
||||
const uip_ipaddr_t *src_addr, uint16_t src_port,
|
||||
const uip_ipaddr_t *dst_addr, uint16_t dst_port,
|
||||
const uint8_t *data, uint16_t datalen)
|
||||
{
|
||||
conn_udp_t *conn = ptr;
|
||||
|
||||
(void)dst_addr;
|
||||
(void)dst_port;
|
||||
mutex_lock(&conn->mutex);
|
||||
if (conn->waiting_thread != KERNEL_PID_UNDEF) {
|
||||
msg_t msg;
|
||||
conn->recv_info.src_port = src_port;
|
||||
conn->recv_info.src = (const ipv6_addr_t *)src_addr;
|
||||
conn->recv_info.data = data;
|
||||
conn->recv_info.datalen = datalen - sizeof(ipv6_hdr_t);
|
||||
msg.type = _MSG_TYPE_RCV;
|
||||
msg.content.ptr = (char *)conn;
|
||||
mutex_unlock(&conn->mutex);
|
||||
msg_send(&msg, conn->waiting_thread);
|
||||
}
|
||||
else {
|
||||
mutex_unlock(&conn->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
static void _output_callback(c_event_t c_event, p_data_t p_data)
|
||||
{
|
||||
_send_cmd_t *send_cmd = (_send_cmd_t *)p_data;
|
||||
|
||||
if ((c_event != EVENT_TYPE_CONN_SEND) || (p_data == NULL)) {
|
||||
return;
|
||||
}
|
||||
if ((send_cmd->res = udp_socket_send(&send_cmd->sock, send_cmd->data, send_cmd->data_len)) < 0) {
|
||||
send_cmd->res = -EHOSTUNREACH;
|
||||
}
|
||||
mutex_unlock(&send_cmd->mutex);
|
||||
}
|
||||
|
||||
/** @} */
|
@ -0,0 +1,3 @@
|
||||
MODULE = emb6_netdev2
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include "msg.h"
|
||||
#include "net/netdev2.h"
|
||||
|
||||
#include "evproc.h"
|
||||
#include "emb6.h"
|
||||
#include "linkaddr.h"
|
||||
#include "packetbuf.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
extern uip_lladdr_t uip_lladdr;
|
||||
|
||||
static netdev2_t *_dev = NULL;
|
||||
static s_nsLowMac_t *_lowmac = NULL;
|
||||
static int8_t _rssi_base_value = -100;
|
||||
static uint8_t _last_rssi;
|
||||
|
||||
static int8_t _netdev2_init(s_ns_t *p_ns);
|
||||
static int8_t _netdev2_send(const void *pr_payload, uint8_t c_len);
|
||||
static int8_t _netdev2_on(void);
|
||||
static int8_t _netdev2_off(void);
|
||||
static void _netdev2_set_txpower(int8_t power);
|
||||
static int8_t _netdev2_get_txpower(void);
|
||||
static void _netdev2_set_sensitivity(int8_t sens);
|
||||
static int8_t _netdev2_get_sensitivity(void);
|
||||
static int8_t _netdev2_get_rssi(void);
|
||||
static void _netdev2_set_promisc(uint8_t c_on_off);
|
||||
|
||||
const s_nsIf_t emb6_netdev2_driver = {
|
||||
.name = "netdev2",
|
||||
.init = &_netdev2_init,
|
||||
.send = &_netdev2_send,
|
||||
.on = &_netdev2_on,
|
||||
.off = &_netdev2_off,
|
||||
.set_txpower = &_netdev2_set_txpower,
|
||||
.get_txpower = &_netdev2_get_txpower,
|
||||
.set_sensitivity = &_netdev2_set_sensitivity,
|
||||
.get_sensitivity = &_netdev2_get_sensitivity,
|
||||
.get_rssi = &_netdev2_get_rssi,
|
||||
.ant_div = NULL,
|
||||
.ant_rf_switch = NULL,
|
||||
.set_promisc = &_netdev2_set_promisc,
|
||||
};
|
||||
|
||||
static void _get_recv_pkt(void)
|
||||
{
|
||||
char *dataptr;
|
||||
struct netdev2_radio_rx_info rx_info;
|
||||
int8_t len;
|
||||
|
||||
packetbuf_clear();
|
||||
|
||||
dataptr = packetbuf_dataptr();
|
||||
len = _dev->driver->recv(_dev, dataptr, PACKETBUF_SIZE, &rx_info);
|
||||
_last_rssi = rx_info.rssi;
|
||||
|
||||
if ((len > 0) && (_lowmac != NULL)) {
|
||||
packetbuf_set_datalen(len);
|
||||
_lowmac->input();
|
||||
}
|
||||
}
|
||||
|
||||
static void _event_cb(netdev2_t *dev, netdev2_event_t event, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
if (event == NETDEV2_EVENT_ISR) {
|
||||
/* EVENT_TYPE_PCK_LL is supposed to be used by drivers, so use it
|
||||
* (though NETDEV2_EVENT_ISR technically doesn't only signify
|
||||
* incoming packets) */
|
||||
evproc_putEvent(E_EVPROC_HEAD, EVENT_TYPE_PCK_LL, NULL);
|
||||
}
|
||||
else {
|
||||
switch (event) {
|
||||
case NETDEV2_EVENT_RX_COMPLETE: {
|
||||
_get_recv_pkt();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void _emb6_netdev2_callback(c_event_t c_event, p_data_t p_data)
|
||||
{
|
||||
(void)p_data;
|
||||
if (c_event == EVENT_TYPE_PCK_LL) {
|
||||
_dev->driver->isr(_dev);
|
||||
}
|
||||
}
|
||||
|
||||
int emb6_netdev2_setup(netdev2_t *dev)
|
||||
{
|
||||
if (_dev == NULL) {
|
||||
_dev = dev;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int8_t _netdev2_init(s_ns_t *p_ns)
|
||||
{
|
||||
if ((_dev != NULL) && (p_ns != NULL) && (p_ns->lmac != NULL)) {
|
||||
_dev->event_callback = _event_cb;
|
||||
_dev->driver->get(_dev, NETOPT_ADDRESS_LONG, &mac_phy_config.mac_address,
|
||||
sizeof(mac_phy_config.mac_address));
|
||||
memcpy(&uip_lladdr, mac_phy_config.mac_address,
|
||||
sizeof(mac_phy_config.mac_address));
|
||||
_dev->driver->get(_dev, NETOPT_NID, &mac_phy_config.pan_id,
|
||||
sizeof(mac_phy_config.pan_id));
|
||||
linkaddr_set_node_addr((linkaddr_t *)&uip_lladdr);
|
||||
_lowmac = p_ns->lmac;
|
||||
evproc_regCallback(EVENT_TYPE_PCK_LL, _emb6_netdev2_callback);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int8_t _netdev2_send(const void *pr_payload, uint8_t c_len)
|
||||
{
|
||||
if (_dev != NULL) {
|
||||
const struct iovec vector = {
|
||||
.iov_base = (void *)pr_payload,
|
||||
.iov_len = c_len
|
||||
};
|
||||
if (_dev->driver->send(_dev, &vector, 1) < 0) {
|
||||
DEBUG("Error on send\n");
|
||||
return RADIO_TX_ERR;
|
||||
}
|
||||
DEBUG("Packet of length %u was transmitted\n", (unsigned)c_len);
|
||||
return RADIO_TX_OK;
|
||||
}
|
||||
DEBUG("Device was not initialized\n");
|
||||
return RADIO_TX_ERR;
|
||||
}
|
||||
|
||||
static int8_t _netdev2_on(void)
|
||||
{
|
||||
/* TODO: turn netdev2 on */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int8_t _netdev2_off(void)
|
||||
{
|
||||
/* TODO: turn netdev2 off */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _netdev2_set_txpower(int8_t power)
|
||||
{
|
||||
int16_t pwr = power;
|
||||
|
||||
_dev->driver->set(_dev, NETOPT_TX_POWER, &pwr, sizeof(pwr));
|
||||
}
|
||||
|
||||
static int8_t _netdev2_get_txpower(void)
|
||||
{
|
||||
int16_t power = 0;
|
||||
|
||||
_dev->driver->get(_dev, NETOPT_TX_POWER, &power, sizeof(power));
|
||||
return (int8_t)power;
|
||||
}
|
||||
|
||||
static void _netdev2_set_sensitivity(int8_t sens)
|
||||
{
|
||||
/* TODO: set sensitivity */
|
||||
}
|
||||
|
||||
static int8_t _netdev2_get_sensitivity(void)
|
||||
{
|
||||
/* TODO: get sensitivity */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int8_t _netdev2_get_rssi(void)
|
||||
{
|
||||
return (int8_t)(_rssi_base_value + 1.03 * _last_rssi);
|
||||
}
|
||||
|
||||
static void _netdev2_set_promisc(uint8_t c_on_off)
|
||||
{
|
||||
netopt_enable_t en = (c_on_off) ? NETOPT_ENABLE : NETOPT_DISABLE;
|
||||
|
||||
_dev->driver->set(_dev, NETOPT_PROMISCUOUSMODE, &en, sizeof(en));
|
||||
}
|
||||
|
||||
/** @} */
|
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (C) Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "led.h"
|
||||
#include "mutex.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "periph/hwrng.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#include "target.h"
|
||||
#include "bsp.h"
|
||||
|
||||
static mutex_t critical_mutex = MUTEX_INIT;
|
||||
|
||||
void hal_enterCritical(void)
|
||||
{
|
||||
mutex_lock(&critical_mutex);
|
||||
}
|
||||
|
||||
void hal_exitCritical(void)
|
||||
{
|
||||
mutex_unlock(&critical_mutex);
|
||||
}
|
||||
|
||||
int8_t hal_init(void)
|
||||
{
|
||||
/* Should have happened long before emb6 started, so nothing to do */
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t hal_getrand(void)
|
||||
{
|
||||
#if RANDOM_NUMOF
|
||||
uint8_t res;
|
||||
hwnrg_read((char *)&res, sizeof(res));
|
||||
return res;
|
||||
#elif defined(MODULE_RANDOM)
|
||||
return (uint8_t)(genrand_uint32() % UINT8_MAX);
|
||||
#else
|
||||
return 4; /* keeping the meme alive ;-) */
|
||||
#endif
|
||||
}
|
||||
|
||||
void hal_ledOn(uint16_t ui_led)
|
||||
{
|
||||
switch (ui_led) {
|
||||
case E_BSP_LED_RED:
|
||||
LED0_ON;
|
||||
break;
|
||||
case E_BSP_LED_YELLOW:
|
||||
LED1_ON;
|
||||
break;
|
||||
case E_BSP_LED_GREEN:
|
||||
LED2_ON;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void hal_ledOff(uint16_t ui_led)
|
||||
{
|
||||
switch (ui_led) {
|
||||
case E_BSP_LED_RED:
|
||||
LED0_OFF;
|
||||
break;
|
||||
case E_BSP_LED_YELLOW:
|
||||
LED1_OFF;
|
||||
break;
|
||||
case E_BSP_LED_GREEN:
|
||||
LED2_OFF;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t hal_extIntInit(en_targetExtInt_t e_extInt, pfn_intCallb_t pfn_intCallback)
|
||||
{
|
||||
/* RIOT does this in netdev2 initialization so nothing to do here. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hal_delay_us(uint32_t i_delay)
|
||||
{
|
||||
xtimer_usleep(i_delay);
|
||||
}
|
||||
|
||||
uint8_t hal_gpioPinInit(uint8_t c_pin, uint8_t c_dir, uint8_t c_initState)
|
||||
{
|
||||
/* Only used in board init code => not needed */
|
||||
(void)c_pin;
|
||||
(void)c_dir;
|
||||
(void)c_initState;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *hal_ctrlPinInit(en_targetExtPin_t e_pinType)
|
||||
{
|
||||
(void)e_pinType;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void hal_pinSet(void *p_pin)
|
||||
{
|
||||
/* Only used in board/driver-related code code => not needed */
|
||||
}
|
||||
|
||||
void hal_pinClr(void *p_pin)
|
||||
{
|
||||
/* Only used in board/driver-related code code => not needed */
|
||||
}
|
||||
|
||||
uint8_t hal_pinGet(void *p_pin)
|
||||
{
|
||||
/* Only used in board/driver-related code code => not needed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *hal_spiInit(void)
|
||||
{
|
||||
/* Only used in board/driver-related code code => not needed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/** \brief This function selects slave with which we will work
|
||||
* \param p_spi Pointer to spi description entity
|
||||
* \param action true or false
|
||||
*
|
||||
* \return 0 if failed, 1 id ok
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint8_t hal_spiSlaveSel(void *p_spi, bool action)
|
||||
{
|
||||
/* Only used in board/driver-related code code => not needed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t hal_spiTransceive( uint8_t *txData, uint8_t *p_reg)
|
||||
{
|
||||
/* Only used in board/driver-related code code => not needed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t hal_spiRead(uint8_t *p_reg, uint16_t i_length)
|
||||
{
|
||||
/* Only used in board/driver-related code code => not needed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/** \brief This function writes a new value via given SPI interface
|
||||
* registers.
|
||||
*
|
||||
*
|
||||
* \param value Pointer to a value.
|
||||
* \param i_length Length of a data to be received
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void hal_spiWrite(uint8_t *value, uint16_t i_length)
|
||||
{
|
||||
/* Only used in board/driver-related code code => not needed */
|
||||
}
|
||||
|
||||
void hal_watchdogReset(void)
|
||||
{
|
||||
/* WDT and tick-less scheduling don't make much sense */
|
||||
}
|
||||
|
||||
void hal_watchdogStart(void)
|
||||
{
|
||||
/* WDT and tick-less scheduling don't make much sense */
|
||||
}
|
||||
|
||||
void hal_watchdogStop(void)
|
||||
{
|
||||
/* WDT and tick-less scheduling don't make much sense */
|
||||
}
|
||||
|
||||
clock_time_t hal_getTick(void)
|
||||
{
|
||||
return (clock_time_t)xtimer_now();
|
||||
}
|
||||
|
||||
clock_time_t hal_getSec(void)
|
||||
{
|
||||
return (clock_time_t)xtimer_now() / SEC_IN_USEC;
|
||||
}
|
||||
|
||||
|
||||
clock_time_t hal_getTRes(void)
|
||||
{
|
||||
return SEC_IN_USEC;
|
||||
}
|
||||
|
||||
/** @} */
|
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @defgroup pkg_emb6 emb6 network stack
|
||||
* @ingroup pkg
|
||||
* @brief emb6 network stack
|
||||
* @see https://github.com/hso-esk/emb6/raw/develop/doc/pdf/emb6.pdf
|
||||
*
|
||||
* emb6 is a fork of Contiki's uIP network stack without its usage of
|
||||
* proto-threads. It uses periodic event polling instead.
|
||||
*/
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup emb6 emb6 network stack
|
||||
* @ingroup pkg
|
||||
* @brief
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief "Board" configuration for emb6
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef EMB6_BOARD_CONF_H_
|
||||
#define EMB6_BOARD_CONF_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "emb6.h"
|
||||
|
||||
/**
|
||||
* @brief emb6 board configuration function
|
||||
*
|
||||
* @param[in] ps_nStack pointer to global netstack struct
|
||||
*
|
||||
* @return success 1
|
||||
* @return failure 0
|
||||
*/
|
||||
uint8_t board_conf(s_ns_t *ps_nStack);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EMB6_BOARD_CONF_H_ */
|
||||
/** @} */
|
||||
/** @} */
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup emb6_conn_udp udp_conn wrapper for emb6
|
||||
* @ingroup emb6
|
||||
* @brief UDP conn for emb6
|
||||
*
|
||||
* For this implementation to receive with an open connection only with one
|
||||
* thread at once. If you use @ref conn_udp_recvfrom() with more than one thread
|
||||
* simultaneously, it will return `-EALREADY`.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief UDP conn definitions
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef EMB6_CONN_UDP_H_
|
||||
#define EMB6_CONN_UDP_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "kernel_types.h"
|
||||
#include "mutex.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
|
||||
#include "uip.h"
|
||||
#include "udp-socket.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief @ref net_conn_udp definition for emb6
|
||||
*/
|
||||
struct conn_udp {
|
||||
struct udp_socket sock; /**< emb6 internal socket */
|
||||
mutex_t mutex; /**< mutex for the connection */
|
||||
kernel_pid_t waiting_thread; /**< thread waiting for an incoming packet
|
||||
* on this connection */
|
||||
struct {
|
||||
uint16_t src_port; /**< source port */
|
||||
const ipv6_addr_t *src; /**< source address */
|
||||
const void *data; /**< data of received packet */
|
||||
size_t datalen; /**< length of received packet data */
|
||||
} recv_info; /**< info on received packet */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EMB6_CONN_UDP_H_ */
|
||||
/** @} */
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup pkgemb6_netdev2 netdev2 wrapper for emb6
|
||||
* @ingroup pkg_emb6
|
||||
* @brief
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef EMB6_NETDEV2_H_
|
||||
#define EMB6_NETDEV2_H_
|
||||
|
||||
#include "net/netdev2.h"
|
||||
|
||||
#include "emb6.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The emb6 network interface.
|
||||
*
|
||||
* @note emb6 only supports one network interface.
|
||||
*
|
||||
* This variable is used by @ref board_conf() to set the interface for the
|
||||
* stack.
|
||||
*/
|
||||
extern const s_nsIf_t emb6_netdev2_driver;
|
||||
|
||||
/**
|
||||
* @brief Setup a network device as the emb6 interface.
|
||||
*
|
||||
* @param[in] dev The network device for the interface
|
||||
*
|
||||
* @return 0 on success.
|
||||
* @return <= 0 on error.
|
||||
*/
|
||||
int emb6_netdev2_setup(netdev2_t *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EMB6_NETDEV2_H_ */
|
||||
/** @} */
|
@ -0,0 +1,130 @@
|
||||
From 4b417436908a6823e631519f794a20644a467f19 Mon Sep 17 00:00:00 2001
|
||||
From: Martine Lenders <mail@martine-lenders.eu>
|
||||
Date: Mon, 11 Jan 2016 15:09:34 +0100
|
||||
Subject: [PATCH 1/4] Add RIOT Makefiles
|
||||
|
||||
---
|
||||
Makefile | 1 +
|
||||
emb6/Makefile | 3 +++
|
||||
emb6/src/mac/Makefile | 3 +++
|
||||
emb6/src/mac/llsec/Makefile | 3 +++
|
||||
emb6/src/net/ipv6/Makefile | 3 +++
|
||||
emb6/src/net/ipv6/multicast/Makefile | 3 +++
|
||||
emb6/src/net/rpl/Makefile | 3 +++
|
||||
emb6/src/net/sicslowpan/Makefile | 3 +++
|
||||
emb6/src/tport/Makefile | 3 +++
|
||||
target/bsp/Makefile | 3 +++
|
||||
utils/src/Makefile | 3 +++
|
||||
11 files changed, 31 insertions(+)
|
||||
create mode 100644 Makefile
|
||||
create mode 100644 emb6/Makefile
|
||||
create mode 100644 emb6/src/mac/Makefile
|
||||
create mode 100644 emb6/src/mac/llsec/Makefile
|
||||
create mode 100644 emb6/src/net/ipv6/Makefile
|
||||
create mode 100644 emb6/src/net/ipv6/multicast/Makefile
|
||||
create mode 100644 emb6/src/net/rpl/Makefile
|
||||
create mode 100644 emb6/src/net/sicslowpan/Makefile
|
||||
create mode 100644 emb6/src/tport/Makefile
|
||||
create mode 100644 target/bsp/Makefile
|
||||
create mode 100644 utils/src/Makefile
|
||||
|
||||
diff --git a/Makefile b/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..48422e9
|
||||
--- /dev/null
|
||||
+++ b/Makefile
|
||||
@@ -0,0 +1 @@
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/emb6/Makefile b/emb6/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..c2ec39f
|
||||
--- /dev/null
|
||||
+++ b/emb6/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_common
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/emb6/src/mac/Makefile b/emb6/src/mac/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..d0472d8
|
||||
--- /dev/null
|
||||
+++ b/emb6/src/mac/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_mac
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/emb6/src/mac/llsec/Makefile b/emb6/src/mac/llsec/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..e13ee7f
|
||||
--- /dev/null
|
||||
+++ b/emb6/src/mac/llsec/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_llsec
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/emb6/src/net/ipv6/Makefile b/emb6/src/net/ipv6/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..844e39c
|
||||
--- /dev/null
|
||||
+++ b/emb6/src/net/ipv6/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_ipv6
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/emb6/src/net/ipv6/multicast/Makefile b/emb6/src/net/ipv6/multicast/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..f1c3f1e
|
||||
--- /dev/null
|
||||
+++ b/emb6/src/net/ipv6/multicast/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_ipv6_multicast
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/emb6/src/net/rpl/Makefile b/emb6/src/net/rpl/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..2fd941c
|
||||
--- /dev/null
|
||||
+++ b/emb6/src/net/rpl/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_rpl
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/emb6/src/net/sicslowpan/Makefile b/emb6/src/net/sicslowpan/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..9e14df3
|
||||
--- /dev/null
|
||||
+++ b/emb6/src/net/sicslowpan/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_sicslowpan
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/emb6/src/tport/Makefile b/emb6/src/tport/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..1b0ca7c
|
||||
--- /dev/null
|
||||
+++ b/emb6/src/tport/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_sock
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/target/bsp/Makefile b/target/bsp/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..ce548bd
|
||||
--- /dev/null
|
||||
+++ b/target/bsp/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_bsp
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
diff --git a/utils/src/Makefile b/utils/src/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..c9aa897
|
||||
--- /dev/null
|
||||
+++ b/utils/src/Makefile
|
||||
@@ -0,0 +1,3 @@
|
||||
+MODULE := emb6_utils
|
||||
+
|
||||
+include $(RIOTBASE)/Makefile.base
|
||||
--
|
||||
1.9.1
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,757 @@
|
||||
From cb47e0b69b747833322a83b7396878a631add116 Mon Sep 17 00:00:00 2001
|
||||
From: Martine Lenders <mail@martine-lenders.eu>
|
||||
Date: Fri, 5 Feb 2016 00:46:31 +0100
|
||||
Subject: [PATCH 3/4] Fix warnings
|
||||
|
||||
---
|
||||
emb6/src/net/ipv6/multicast/roll-tm.c | 82 ++++++++++++++++++------
|
||||
emb6/src/net/ipv6/multicast/smrf.c | 12 +++-
|
||||
emb6/src/net/ipv6/multicast/uip-mcast6-route.c | 2 +-
|
||||
emb6/src/net/ipv6/tcpip.c | 25 ++++++--
|
||||
emb6/src/net/ipv6/uip-icmp6.c | 35 +++++++++--
|
||||
emb6/src/net/ipv6/uip-nd6.c | 74 ++++++++++++++++++----
|
||||
emb6/src/net/ipv6/uip6.c | 86 +++++++++++++++++++++-----
|
||||
emb6/src/net/rpl/rpl-ext-header.c | 50 ++++++++++++---
|
||||
emb6/src/net/rpl/rpl-icmp6.c | 24 +++++--
|
||||
emb6/src/net/sicslowpan/sicslowpan.c | 45 +++++++++++---
|
||||
emb6/src/tport/udp-socket.c | 7 ++-
|
||||
11 files changed, 365 insertions(+), 77 deletions(-)
|
||||
|
||||
diff --git a/emb6/src/net/ipv6/multicast/roll-tm.c b/emb6/src/net/ipv6/multicast/roll-tm.c
|
||||
index 8b36300..96f4f47 100644
|
||||
--- a/emb6/src/net/ipv6/multicast/roll-tm.c
|
||||
+++ b/emb6/src/net/ipv6/multicast/roll-tm.c
|
||||
@@ -290,12 +290,17 @@ struct mcast_packet {
|
||||
#define MCAST_PACKET_S_BIT 0x20 /* Must Send Next Pass */
|
||||
#define MCAST_PACKET_L_BIT 0x10 /* Is listed in ICMP message */
|
||||
|
||||
+static inline struct uip_ip_hdr *_to_ip_hdr(void *ptr)
|
||||
+{
|
||||
+ return (struct uip_ip_hdr *)ptr;
|
||||
+}
|
||||
+
|
||||
/* Fetch a pointer to the Seed ID of a buffered message p */
|
||||
#if ROLL_TM_SHORT_SEEDS
|
||||
#define MCAST_PACKET_GET_SEED(p) ((seed_id_t *)&((p)->seed_id))
|
||||
#else
|
||||
#define MCAST_PACKET_GET_SEED(p) \
|
||||
- ((seed_id_t *)&((struct uip_ip_hdr *)&(p)->buff[UIP_LLH_LEN])->srcipaddr)
|
||||
+ ((seed_id_t *)&(((struct uip_ip_hdr *)&(p))->buff[UIP_LLH_LEN])->srcipaddr)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -303,7 +308,7 @@ struct mcast_packet {
|
||||
* p: pointer to a packet buffer
|
||||
*/
|
||||
#define MCAST_PACKET_TTL(p) \
|
||||
- (((struct uip_ip_hdr *)(p)->buff)->ttl)
|
||||
+ (_to_ip_hdr((p)->buff)->ttl)
|
||||
|
||||
/**
|
||||
* \brief Set 'Is Used' bit for packet p
|
||||
@@ -462,14 +467,55 @@ static uint16_t last_seq;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* uIPv6 Pointers */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
-#define UIP_DATA_BUF ((uint8_t *)&uip_buf[uip_l2_l3_hdr_len + UIP_UDPH_LEN])
|
||||
-#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
-#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
|
||||
-#define UIP_EXT_BUF_NEXT ((uint8_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + HBHO_TOTAL_LEN])
|
||||
-#define UIP_EXT_OPT_FIRST ((struct hbho_mcast *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + 2])
|
||||
-#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
-#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
-#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
||||
+/* least intrusive way to prevent -Wstrict-aliasing from firing */
|
||||
+static inline uint8_t *uip_data_buf(void)
|
||||
+{
|
||||
+ return ((uint8_t *)&uip_buf[uip_l2_l3_hdr_len + UIP_UDPH_LEN]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_udp_hdr *uip_udp_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_ext_hdr *uip_ext_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_ext_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]);
|
||||
+}
|
||||
+
|
||||
+uint8_t *uip_ext_buf_next(void)
|
||||
+{
|
||||
+ return ((uint8_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + HBHO_TOTAL_LEN]);
|
||||
+}
|
||||
+
|
||||
+static inline struct hbho_mcast *uip_ext_opt_first(void)
|
||||
+{
|
||||
+ return ((struct hbho_mcast *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + 2]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_ip_hdr *uip_ip_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_icmp_hdr *uip_icmp_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]);
|
||||
+}
|
||||
+
|
||||
+static inline unsigned char *uip_icmp_payload(void)
|
||||
+{
|
||||
+ return ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]);
|
||||
+}
|
||||
+
|
||||
+#define UIP_DATA_BUF (uip_data_buf())
|
||||
+#define UIP_UDP_BUF (uip_udp_buf())
|
||||
+#define UIP_EXT_BUF (uip_ext_buf())
|
||||
+#define UIP_EXT_BUF_NEXT (uip_ext_buf_next())
|
||||
+#define UIP_EXT_OPT_FIRST (uip_ext_opt_first())
|
||||
+#define UIP_IP_BUF (uip_ip_buf())
|
||||
+#define UIP_ICMP_BUF (uip_icmp_buf())
|
||||
+#define UIP_ICMP_PAYLOAD (uip_icmp_payload())
|
||||
extern uint16_t uip_slen;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Local function prototypes */
|
||||
@@ -689,7 +735,7 @@ reset_trickle_timer(uint8_t index)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct sliding_window *
|
||||
-window_allocate()
|
||||
+window_allocate(void)
|
||||
{
|
||||
for(iterswptr = &windows[ROLL_TM_WINS - 1]; iterswptr >= windows;
|
||||
iterswptr--) {
|
||||
@@ -721,7 +767,7 @@ window_lookup(seed_id_t *s, uint8_t m)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
-window_update_bounds()
|
||||
+window_update_bounds(void)
|
||||
{
|
||||
for(iterswptr = &windows[ROLL_TM_WINS - 1]; iterswptr >= windows;
|
||||
iterswptr--) {
|
||||
@@ -748,7 +794,7 @@ window_update_bounds()
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct mcast_packet *
|
||||
-buffer_reclaim()
|
||||
+buffer_reclaim(void)
|
||||
{
|
||||
struct sliding_window *largest = windows;
|
||||
struct mcast_packet *rv;
|
||||
@@ -790,7 +836,7 @@ buffer_reclaim()
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct mcast_packet *
|
||||
-buffer_allocate()
|
||||
+buffer_allocate(void)
|
||||
{
|
||||
for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
|
||||
locmpptr >= buffered_msgs; locmpptr--) {
|
||||
@@ -802,7 +848,7 @@ buffer_allocate()
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
-icmp_output()
|
||||
+icmp_output(void)
|
||||
{
|
||||
struct sequence_list_header *sl;
|
||||
uint8_t *buffer;
|
||||
@@ -1098,7 +1144,7 @@ accept(uint8_t in)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* ROLL TM ICMPv6 Input Handler */
|
||||
static void
|
||||
-icmp_input()
|
||||
+icmp_input(void)
|
||||
{
|
||||
uint8_t inconsistency;
|
||||
uint16_t *seq_ptr;
|
||||
@@ -1321,7 +1367,7 @@ drop:
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
-out()
|
||||
+out(void)
|
||||
{
|
||||
|
||||
if(uip_len + HBHO_TOTAL_LEN > UIP_BUFSIZE) {
|
||||
@@ -1391,7 +1437,7 @@ drop:
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
-in()
|
||||
+in(void)
|
||||
{
|
||||
/*
|
||||
* We call accept() which will sort out caching and forwarding. Depending
|
||||
diff --git a/emb6/src/net/ipv6/multicast/smrf.c b/emb6/src/net/ipv6/multicast/smrf.c
|
||||
index 9b4a3a5..38d31cd 100644
|
||||
--- a/emb6/src/net/ipv6/multicast/smrf.c
|
||||
+++ b/emb6/src/net/ipv6/multicast/smrf.c
|
||||
@@ -77,7 +77,13 @@ static uint8_t fwd_spread;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* uIPv6 Pointers */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
-#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
+/* least intrusive way to prevent -Wstrict-aliasing from firing */
|
||||
+static inline struct uip_ip_hdr *uip_ip_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]);
|
||||
+}
|
||||
+
|
||||
+#define UIP_IP_BUF (uip_ip_buf())
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
mcast_fwd(void *p)
|
||||
@@ -90,7 +96,7 @@ mcast_fwd(void *p)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
-in()
|
||||
+in(void)
|
||||
{
|
||||
rpl_dag_t *d; /* Our DODAG */
|
||||
uip_ipaddr_t *parent_ipaddr; /* Our pref. parent's IPv6 address */
|
||||
@@ -201,7 +207,7 @@ init(void)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
-out()
|
||||
+out(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
diff --git a/emb6/src/net/ipv6/multicast/uip-mcast6-route.c b/emb6/src/net/ipv6/multicast/uip-mcast6-route.c
|
||||
index 55d245d..75443a5 100644
|
||||
--- a/emb6/src/net/ipv6/multicast/uip-mcast6-route.c
|
||||
+++ b/emb6/src/net/ipv6/multicast/uip-mcast6-route.c
|
||||
@@ -126,7 +126,7 @@ uip_mcast6_route_count(void)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
-uip_mcast6_route_init()
|
||||
+uip_mcast6_route_init(void)
|
||||
{
|
||||
memb_init(&mcast_route_memb);
|
||||
list_init(mcast_route_list);
|
||||
diff --git a/emb6/src/net/ipv6/tcpip.c b/emb6/src/net/ipv6/tcpip.c
|
||||
index 9c76bed..1901d9e 100644
|
||||
--- a/emb6/src/net/ipv6/tcpip.c
|
||||
+++ b/emb6/src/net/ipv6/tcpip.c
|
||||
@@ -72,9 +72,24 @@ void uip_log(char *msg);
|
||||
#define UIP_LOG(m)
|
||||
#endif
|
||||
|
||||
-#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN + uip_ext_len])
|
||||
-#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
-#define UIP_TCP_BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
+static inline struct uip_icmp_hdr *uip_icmp_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN + uip_ext_len]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_ip_hdr *uip_ip_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_tcpip_hdr *uip_tcp_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]);
|
||||
+}
|
||||
+
|
||||
+#define UIP_ICMP_BUF (uip_icmp_buf())
|
||||
+#define UIP_IP_BUF (uip_ip_buf())
|
||||
+#define UIP_TCP_BUF (uip_tcp_buf())
|
||||
|
||||
#ifdef UIP_FALLBACK_INTERFACE
|
||||
extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE;
|
||||
@@ -165,15 +180,15 @@ unsigned char tcpip_is_forwarding; /* Forwarding right now? */
|
||||
//PROCESS(tcpip_process, "TCP/IP stack");
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
+#if UIP_TCP
|
||||
static void
|
||||
start_periodic_tcp_timer(void)
|
||||
{
|
||||
-#if UIP_TCP
|
||||
if(etimer_expired(&periodic)) {
|
||||
etimer_restart(&periodic);
|
||||
}
|
||||
-#endif /* UIP_TCP */
|
||||
}
|
||||
+#endif /* UIP_TCP */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
check_for_tcp_syn(void)
|
||||
diff --git a/emb6/src/net/ipv6/uip-icmp6.c b/emb6/src/net/ipv6/uip-icmp6.c
|
||||
index 484d0bf..6f53d12 100644
|
||||
--- a/emb6/src/net/ipv6/uip-icmp6.c
|
||||
+++ b/emb6/src/net/ipv6/uip-icmp6.c
|
||||
@@ -59,11 +59,34 @@
|
||||
#define PRINT6ADDR(addr)
|
||||
#endif
|
||||
|
||||
-#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
-#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
-#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
||||
-#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
-#define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN])
|
||||
+/* least intrusive way to prevent -Wstrict-aliasing from firing */
|
||||
+static inline struct uip_ip_hdr *uip_ip_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_icmp_hdr *uip_icmp_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_icmp6_error *uip_icmp6_error_buf(void) {
|
||||
+ return ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_ext_hdr *uip_ext_buf(void) {
|
||||
+ return ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len]);
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_ext_hdr *uip_first_ext_buf(void) {
|
||||
+ return ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN]);
|
||||
+}
|
||||
+
|
||||
+#define UIP_IP_BUF (uip_ip_buf())
|
||||
+#define UIP_ICMP_BUF (uip_icmp_buf())
|
||||
+#define UIP_ICMP6_ERROR_BUF (uip_icmp6_error_buf())
|
||||
+#define UIP_EXT_BUF (uip_ext_buf())
|
||||
+#define UIP_FIRST_EXT_BUF (uip_first_ext_buf())
|
||||
|
||||
/** \brief temporary IP address */
|
||||
static uip_ipaddr_t tmp_ipaddr;
|
||||
@@ -409,7 +432,7 @@ UIP_ICMP6_HANDLER(echo_reply_handler, ICMP6_ECHO_REPLY,
|
||||
UIP_ICMP6_HANDLER_CODE_ANY, echo_reply_input);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
-uip_icmp6_init()
|
||||
+uip_icmp6_init(void)
|
||||
{
|
||||
/* Register Echo Request and Reply handlers */
|
||||
uip_icmp6_register_input_handler(&echo_request_handler);
|
||||
diff --git a/emb6/src/net/ipv6/uip-nd6.c b/emb6/src/net/ipv6/uip-nd6.c
|
||||
index f04b6b3..26ed214 100644
|
||||
--- a/emb6/src/net/ipv6/uip-nd6.c
|
||||
+++ b/emb6/src/net/ipv6/uip-nd6.c
|
||||
@@ -93,6 +93,37 @@ void uip_log(char *msg);
|
||||
#define UIP_LOG(m)
|
||||
#endif /* UIP_LOGGING == 1 */
|
||||
|
||||
+/* least intrusive way to prevent -Wstrict-aliasing from firing */
|
||||
+static inline struct uip_ip_hdr *uip_ip_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) /**< Pointer to IP header */;
|
||||
+}
|
||||
+
|
||||
+static inline struct uip_icmp_hdr *uip_icmp_buf(void)
|
||||
+{
|
||||
+ return ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) /**< Pointer to ICMP header*/;
|
||||
+}
|
||||
+
|
||||
+static inline uip_nd6_rs *uip_nd6_rs_buf(void)
|
||||
+{
|
||||
+ return ((uip_nd6_rs *)&uip_buf[uip_l2_l3_icmp_hdr_len]);
|
||||
+}
|
||||
+
|
||||
+static inline uip_nd6_ra *uip_nd6_ra_buf(void)
|
||||
+{
|
||||
+ return ((uip_nd6_ra *)&uip_buf[uip_l2_l3_icmp_hdr_len]);
|
||||
+}
|
||||
+
|
||||
+static inline uip_nd6_ns *uip_nd6_ns_buf(void)
|
||||
+{
|
||||
+ return ((uip_nd6_ns *)&uip_buf[uip_l2_l3_icmp_hdr_len]);
|
||||
+}
|
||||
+
|
||||
+static inline uip_nd6_na *uip_nd6_na_buf(void)
|
||||
+{
|
||||
+ return ((uip_nd6_na *)&uip_buf[uip_l2_l3_icmp_hdr_len]);
|
||||
+}
|
||||
+
|
||||
/*------------------------------------------------------------------*/
|
||||
/** @{ */
|
||||
/** \name Pointers to the header structures.
|
||||
@@ -106,19 +137,19 @@ void uip_log(char *msg);
|
||||
* value of these length variables
|
||||
*/
|
||||
|
||||
-#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) /**< Pointer to IP header */
|
||||
-#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) /**< Pointer to ICMP header*/
|
||||
+#define UIP_IP_BUF (uip_ip_buf()) /**< Pointer to IP header */
|
||||
+#define UIP_ICMP_BUF (uip_icmp_buf()) /**< Pointer to ICMP header*/
|
||||
/**@{ Pointers to messages just after icmp header */
|
||||
-#define UIP_ND6_RS_BUF ((uip_nd6_rs *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
||||
-#define UIP_ND6_RA_BUF ((uip_nd6_ra *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
||||
-#define UIP_ND6_NS_BUF ((uip_nd6_ns *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
||||
-#define UIP_ND6_NA_BUF ((uip_nd6_na *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
||||
+#define UIP_ND6_RS_BUF (uip_nd6_rs_buf())
|
||||