coding conventions for most of system libraries

dev/timer
Oliver Hahm 10 years ago
parent f359453083
commit 5c52e1ce2e

@ -1,5 +1,5 @@
/**
* Auto initialization for used modules
* Auto initialization for used modules
*
* Copyright (C) 2013 INRIA.
*
@ -27,7 +27,8 @@
extern int main(void);
void auto_init(void) {
void auto_init(void)
{
#ifdef MODULE_BOARD_DISPLAY
extern void lcd_init();
lcd_init();

@ -1,5 +1,5 @@
/**
* Character device messaging loop.
* Character device messaging loop.
*
* Copyright (C) 2013, INRIA.
*
@ -28,12 +28,18 @@
//#define ENABLE_DEBUG
#include <debug.h>
static int min(int a, int b) {
if (b>a) return a;
else return b;
static int min(int a, int b)
{
if(b > a) {
return a;
}
else {
return b;
}
}
void chardev_loop(ringbuffer_t *rb) {
void chardev_loop(ringbuffer_t *rb)
{
msg_t m;
int pid = thread_getpid();
@ -43,14 +49,15 @@ void chardev_loop(ringbuffer_t *rb) {
puts("UART0 thread started.");
while (1) {
while(1) {
msg_receive(&m);
if (m.sender_pid != pid) {
if(m.sender_pid != pid) {
DEBUG("Receiving message from another thread\n");
switch (m.type) {
switch(m.type) {
case OPEN:
if (reader_pid == -1) {
if(reader_pid == -1) {
reader_pid = m.sender_pid;
/* no error */
m.content.value = 0;
@ -58,10 +65,12 @@ void chardev_loop(ringbuffer_t *rb) {
else {
m.content.value = -EBUSY;
}
msg_reply(&m,&m);
msg_reply(&m, &m);
break;
case READ:
if (m.sender_pid != reader_pid) {
if(m.sender_pid != reader_pid) {
m.content.value = -EINVAL;
r = NULL;
msg_reply(&m, &m);
@ -69,9 +78,11 @@ void chardev_loop(ringbuffer_t *rb) {
else {
r = (struct posix_iop_t *)m.content.ptr;
}
break;
case CLOSE:
if (m.sender_pid == reader_pid) {
if(m.sender_pid == reader_pid) {
DEBUG("uart0_thread: closing file from %i\n", reader_pid);
reader_pid = -1;
r = NULL;
@ -80,15 +91,17 @@ void chardev_loop(ringbuffer_t *rb) {
else {
m.content.value = -EINVAL;
}
msg_reply(&m,&m);
msg_reply(&m, &m);
break;
default:
m.content.value = -EINVAL;
msg_reply(&m, &m);
}
}
if (rb->avail && (r != NULL)) {
if(rb->avail && (r != NULL)) {
int state = disableIRQ();
int nbytes = min(r->nbytes, rb->avail);
DEBUG("uart0_thread [%i]: sending %i bytes received from %i to pid %i\n", pid, nbytes, m.sender_pid, reader_pid);
@ -97,7 +110,7 @@ void chardev_loop(ringbuffer_t *rb) {
m.sender_pid = reader_pid;
m.type = OPEN;
m.content.ptr = (char*)r;
m.content.ptr = (char *)r;
msg_reply(&m, &m);

@ -1,5 +1,5 @@
/**
* System wide configuration struct.
* System wide configuration struct.
*
* Copyright (C) 2013 INRIA.
*
@ -10,7 +10,7 @@
* @ingroup config
* @{
* @file config_c
* @brief Provides system configuration struct with default values.
* @brief Provides system configuration struct with default values.
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @}
*/

@ -1,5 +1,5 @@
#ifndef __BOARD_UART0_H
#define __BOARD_UART0_H
#define __BOARD_UART0_H
extern int uart0_handler_pid;

@ -1,5 +1,5 @@
#ifndef __CHARDEV_THREAD_H
#define __CHARDEV_THREAD_H
#define __CHARDEV_THREAD_H
#include <ringbuffer.h>

@ -8,18 +8,18 @@ void print_success(void);
void print_failed(void);
void gpio_n_timer_init(void);
void adjust_timer(void);
static void ping_handler(void *payload, int payload_size,
packet_info_t *packet_info);
static void pong_handler(void *payload, int payload_size,
packet_info_t *packet_info);
static void ping_handler(void *payload, int payload_size,
packet_info_t *packet_info);
static void pong_handler(void *payload, int payload_size,
packet_info_t *packet_info);
void pong(uint16_t src);
typedef struct pong{
int hopcount;
int ttl;
radio_address_t radio_address;
typedef struct pong {
int hopcount;
int ttl;
radio_address_t radio_address;
} ping_r;
typedef struct ping_payload{
char* payload;
typedef struct ping_payload {
char *payload;
} ping_payload;

@ -1,5 +1,5 @@
#ifndef __READ_H
#define __READ_H
#define __READ_H
#define OPEN 0
#define CLOSE 1
@ -12,8 +12,8 @@ struct posix_iop_t {
};
int posix_open(int pid, int flags);
int posix_close(int pid);
int posix_read(int pid, char* buffer, int bufsize);
int posix_write(int pid, char* buffer, int bufsize);
int posix_close(int pid);
int posix_read(int pid, char *buffer, int bufsize);
int posix_write(int pid, char *buffer, int bufsize);
#endif /* __READ_H */

@ -1,7 +1,7 @@
#ifndef __PS_H
#define __PS_H
#define __PS_H
void thread_print_all(void);
void _ps_handler(char*);
void _ps_handler(char *);
#endif /* __PS_H */

@ -1,28 +1,14 @@
/******************************************************************************
Copyright 2008-2009 , Freie Universitaet Berlin (FUB). All rights reserved.
These sources were developed at the Freie Universitaet Berlin, Computer Systems
and Telematics group (http://cst.mi.fu-berlin.de).
-------------------------------------------------------------------------------
This file is part of RIOT.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
RIOT is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/ .
--------------------------------------------------------------------------------
For further information and questions please use the web site
http://scatterweb.mi.fu-berlin.de
and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/
/**
* Generic radio driver interface
*
* Copyright (C) 2008-2009 Freie Universitaet Berlin (FUB).
* Copyright (C) 2013 INRIA.
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*
*/
#ifndef RADIO_H_
#define RADIO_H_
@ -58,41 +44,40 @@ and the mailinglist (subscription via web site)
#define L1_PROTOCOL_CATCH_ALL (0xff) ///< Catch all protocol ID
enum layer_1_protocols
{
LAYER_1_PROTOCOL_LL_ACK = 1, ///< Link-Level Acknowledgement (LL-ACK)
LAYER_1_PROTOCOL_MM = 2, ///< Micro Mesh network packet (MM)
enum layer_1_protocols {
LAYER_1_PROTOCOL_LL_ACK = 1, ///< Link-Level Acknowledgement (LL-ACK)
LAYER_1_PROTOCOL_MM = 2, ///< Micro Mesh network packet (MM)
};
/**
* Radio/MAC API.
*/
typedef struct radio {
const char* name;
const radio_address_t broadcast_address;
const uint8_t output_power_max;
/**
* @return the average transmission duration of one packet
* in milliseconds, e.g. till ACK received.
*/
int (*get_avg_transmission_duration)(void);
radio_address_t (*get_address)(void);
bool (*set_address)(radio_address_t address);
bool (*set_output_power)(uint8_t pa_idx);
bool (*set_packet_monitor)(packet_monitor_t monitor);
/**
* @return -1 if an error occurs (e.g. handler table full) else >= 0.
*/
int (*set_packet_handler)(protocol_t protocol, packet_handler_t handler);
/**
* @return A negative value if operation failed; else the number of transmitted bytes.
*/
int (*send)(radio_address_t address, protocol_t protocol, int priority, char *payload, int payload_len);
void (*print_stats)(void);
void (*print_config)(void);
typedef struct {
const char *name;
const radio_address_t broadcast_address;
const uint8_t output_power_max;
/**
* @return the average transmission duration of one packet
* in milliseconds, e.g. till ACK received.
*/
int (*get_avg_transmission_duration)(void);
radio_address_t (*get_address)(void);
bool (*set_address)(radio_address_t address);
bool (*set_output_power)(uint8_t pa_idx);
bool (*set_packet_monitor)(packet_monitor_t monitor);
/**
* @return -1 if an error occurs (e.g. handler table full) else >= 0.
*/
int (*set_packet_handler)(protocol_t protocol, packet_handler_t handler);
/**
* @return A negative value if operation failed; else the number of transmitted bytes.
*/
int (*send)(radio_address_t address, protocol_t protocol, int priority, char *payload, int payload_len);
void (*print_stats)(void);
void (*print_config)(void);
} radio_t;
extern const struct radio* feuerware_radios[FEUERWARE_CONF_NUM_RADIOS];
extern const struct radio *feuerware_radios[FEUERWARE_CONF_NUM_RADIOS];
/** @} */

@ -1,28 +1,14 @@
/******************************************************************************
Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved.
These sources were developed at the Freie Universitaet Berlin, Computer Systems
and Telematics group (http://cst.mi.fu-berlin.de).
-------------------------------------------------------------------------------
This file is part of RIOT.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
RIOT is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/ .
--------------------------------------------------------------------------------
For further information and questions please use the web site
http://scatterweb.mi.fu-berlin.de
and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/
/**
* Generic radio driver interface data structures and prototypes
*
* Copyright (C) 2009 Freie Universitaet Berlin (FUB).
* Copyright (C) 2013 INRIA.
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*
*/
#ifndef COMMONTYPES_H_
#define COMMONTYPES_H_
@ -33,6 +19,7 @@ and the mailinglist (subscription via web site)
*
* @author Freie Universität Berlin, Computer Systems & Telematics
* @author Thomas Hillebrandt <hillebra@inf.fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @version $Revision: 2061 $
*
* @note $Id: common-types.h 2061 2010-04-01 12:13:22Z hillebra $
@ -50,11 +37,10 @@ typedef uint16_t radio_address_t; ///< Radio layer address type
/**
* @brief Packet transmission priorities of various layers.
*/
enum transmission_priorities
{
PRIORITY_ALARM = 0,
PRIORITY_WARNING = 1,
PRIORITY_DATA = 2
enum transmission_priorities {
PRIORITY_ALARM = 0,
PRIORITY_WARNING = 1,
PRIORITY_DATA = 2
};
/**
@ -62,23 +48,23 @@ enum transmission_priorities
* This struct is passed along all receive functions of
* all layers. Each layers fills in additional information.
*/
typedef struct __attribute__ ((packed)) packet_info_t
{
uint16_t source; ///< Net layer: source
uint16_t destination; ///< Net layer: destination
radio_address_t phy_src; ///< Radio layer: source
uint8_t rssi; ///< Radio layer: RSSI
uint8_t lqi; ///< Radio layer: LQI
uint8_t ttl; ///< Net layer: TTL
uint8_t tos; ///< Net layer: TOS
bool promiscuous; ///< Radio layer: whether network interface is in promiscuous mode
typedef struct __attribute__((packed)) packet_info_t {
uint16_t source; ///< Net layer: source
uint16_t destination; ///< Net layer: destination
radio_address_t phy_src; ///< Radio layer: source
uint8_t rssi; ///< Radio layer: RSSI
uint8_t lqi; ///< Radio layer: LQI
uint8_t ttl; ///< Net layer: TTL
uint8_t tos; ///< Net layer: TOS
bool promiscuous; ///< Radio layer: whether network interface is in promiscuous mode
} packet_info_t;
/**
* @brief General link layer packet format
*/
typedef struct __attribute__ ((packed)) {
typedef struct __attribute__((packed))
{
uint8_t processing; ///< internal processing state
uint16_t src; ///< Radio source address
uint16_t dst; ///< Radio destination address
@ -87,7 +73,8 @@ typedef struct __attribute__ ((packed)) {
timex_t toa; ///< Time of Arrival
uint8_t length; ///< Length of payload
uint8_t *data; ///< Payload
} radio_packet_t;
}
radio_packet_t;
/**
@ -96,7 +83,7 @@ typedef struct __attribute__ ((packed)) {
* @param [in] payload_size Size of the packet payload data in bytes
* @param [in/out] packet_info Cross-layer meta data
*/
typedef void (*packet_handler_t)(void* payload, int payload_size, packet_info_t* packet_info);
typedef void (*packet_handler_t)(void *payload, int payload_size, packet_info_t *packet_info);
/**
* Packet monitor of all layers. Normally there can be one packet
@ -107,6 +94,6 @@ typedef void (*packet_handler_t)(void* payload, int payload_size, packet_info_t*
* @param protocol Protocol type of the packet payload data
* @param packet_info Cross-layer meta data
*/
typedef void (*packet_monitor_t)(void* payload, int payload_size, protocol_t protocol, packet_info_t* packet_info);
typedef void (*packet_monitor_t)(void *payload, int payload_size, protocol_t protocol, packet_info_t *packet_info);
#endif /* COMMONTYPES_H_ */

@ -25,7 +25,7 @@ and the mailinglist (subscription via web site)
*******************************************************************************/
#ifndef __SHELL_H
#define __SHELL_H
#define __SHELL_H
/**
* @defgroup shell Simple Shell Interpreter
@ -35,15 +35,15 @@ and the mailinglist (subscription via web site)
//#include "hashtable.h"
typedef struct shell_command_t {
char* name;
char* desc;
void (*handler)(char*);
char *name;
char *desc;
void (*handler)(char *);
} shell_command_t;
typedef struct shell_t {
const shell_command_t *command_list;
int (*readchar)(void);
void (*put_char)(int);
int (*readchar)(void);
void (*put_char)(int);
} shell_t;
/**

@ -1,5 +1,5 @@
#ifndef __SHELL_COMMANDS_H
#define __SHELL_COMMANDS_H
#define __SHELL_COMMANDS_H
#include <shell.h>

@ -1,5 +1,5 @@
#ifndef __TIMEX_H
#define __TIMEX_H
#define __TIMEX_H
#include <stdint.h>
@ -9,7 +9,7 @@ typedef struct timex_t {
} timex_t;
/* a+b */
timex_t timex_add(const timex_t a, const timex_t b);
timex_t timex_add(const timex_t a, const timex_t b);
/* a-b*/
timex_t timex_sub(const timex_t a, const timex_t b);

@ -1,5 +1,5 @@
#ifndef TRANSCEIVER_H
#define TRANSCEIVER_H
#define TRANSCEIVER_H
#include <radio/types.h>
@ -84,7 +84,7 @@ typedef struct {
extern int transceiver_pid;
/**
* @brief Initializes the transceiver module for certain transceiver types
* @brief Initializes the transceiver module for certain transceiver types
*
* @param transceivers Specifies all transceivers to init
**/

@ -17,7 +17,7 @@
* Timer library header file.
*/
#ifndef __VTIMER_H
#define __VTIMER_H
#define __VTIMER_H
#include "queue.h"
#include "timex.h"
@ -34,8 +34,8 @@
typedef struct vtimer_t {
queue_node_t queue_entry;
timex_t absolute;
void(*action)(void*);
void* arg;
void(*action)(void *);
void *arg;
unsigned int pid;
} vtimer_t;
@ -43,7 +43,7 @@ typedef struct vtimer_t {
* @brief Current system time
* @return Time as timex_t since system boot
*/
void vtimer_now(timex_t* out);
void vtimer_now(timex_t *out);
/**
* @brief Initializes the vtimer subsystem. To be called once at system initialization. Will be initialized by auto_init.
@ -54,7 +54,7 @@ int vtimer_init(void);
/**
* @brief will cause the calling thread to be suspended from excecution until the number of microseconds has elapsed
* @param[in] us number of microseconds
* @param[in] us number of microseconds
* @return 0 on success, < 0 on error
*/
int vtimer_usleep(uint32_t us);
@ -94,6 +94,6 @@ int vtimer_remove(vtimer_t *t);
/**
* @brief Prints a vtimer_t
*/
void vtimer_print(vtimer_t* t);
void vtimer_print(vtimer_t *t);
#endif /* __VTIMER_H */

File diff suppressed because it is too large Load Diff

@ -60,13 +60,12 @@ and the mailinglist (subscription via web site)
* | Source | Address[1..n] |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
typedef struct __attribute__ ((packed)) mmr_rreq_message_t
{
uint8_t type; ///< Must be first byte in struct for type detection
uint8_t length;
uint16_t destination;
uint16_t source;
uint16_t address[ADDRESS_LIST_SIZE];
typedef struct __attribute__((packed)) {
uint8_t type; ///< Must be first byte in struct for type detection
uint8_t length;
uint16_t destination;
uint16_t source;
uint16_t address[ADDRESS_LIST_SIZE];
} mmr_rreq_message_t;
/**
@ -80,13 +79,12 @@ typedef struct __attribute__ ((packed)) mmr_rreq_message_t
* | Source | Address[1..n] |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
typedef struct __attribute__ ((packed)) mmr_rrep_message_t
{
uint8_t type; ///< Must be first byte in struct for type detection
uint8_t length;
uint16_t destination;
uint16_t source;
uint16_t address[ADDRESS_LIST_SIZE];
typedef struct __attribute__((packed)) {
uint8_t type; ///< Must be first byte in struct for type detection
uint8_t length;
uint16_t destination;
uint16_t source;
uint16_t address[ADDRESS_LIST_SIZE];
} mmr_rrep_message_t;
/**
@ -111,11 +109,10 @@ typedef struct __attribute__ ((packed)) mmr_rrep_message_t
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
typedef struct __attribute__ ((packed)) mmr_rerr_message_t
{
uint8_t type; ///< Must be first byte in struct for type detection
uint8_t error_type;
uint16_t type_specific_info;
typedef struct __attribute__((packed)) {
uint8_t type; ///< Must be first byte in struct for type detection
uint8_t error_type;
uint16_t type_specific_info;
} mmr_rerr_message_t;
/**
@ -131,7 +128,7 @@ void mmr_init(void);
* @param message incoming packet
* @param packet_info Additional packet information
*/
void mmr_peek(net_message_t* message, packet_info_t* packet_info);
void mmr_peek(net_message_t *message, packet_info_t *packet_info);
/**
* Called by the network layer to request transmission of a packet that
@ -145,7 +142,7 @@ void mmr_peek(net_message_t* message, packet_info_t* packet_info);
* @return true if packet was successfully stored for transmission; false otherwise
* (e.g. message queue full).
*/
bool mmr_send(net_message_t* message);
bool mmr_send(net_message_t *message);
/**
* Called by the network layer which forwards notifications of dropped packets
@ -155,7 +152,7 @@ bool mmr_send(net_message_t* message);
* @param next_hop next hop network address of dropped packet (can be undefined)
* @param error Error type which informs about reason
*/
void mmr_packet_dropped(net_message_t* message, uint16_t next_hop, int error);
void mmr_packet_dropped(net_message_t *message, uint16_t next_hop, int error);
/**
* @brief Receive a message from network layer.
@ -164,7 +161,7 @@ void mmr_packet_dropped(net_message_t* message, uint16_t next_hop, int error);
* @param msg_size Size of received message
* @param packet_info Additional packet information
*/
void mmr_receive(void* msg, int msg_size, packet_info_t* packet_info);
void mmr_receive(void *msg, int msg_size, packet_info_t *packet_info);
/**
* @brief Print routing layer statistics.

File diff suppressed because it is too large Load Diff

@ -59,7 +59,7 @@ void mms_init(void);
* @param rp Routing protocol type identifier.
* @param ri Pointer to route interface.
*/
void mms_initp(protocol_t rp, route_interface_t* ri);
void mms_initp(protocol_t rp, route_interface_t *ri);
/**
* @brief Add network interface.
@ -70,7 +70,7 @@ void mms_initp(protocol_t rp, route_interface_t* ri);
*
* @return Interface identifier or -1 if an error occurs.
*/
int mms_add_interface(const char* name, uint16_t addr, const radio_t* radio);
int mms_add_interface(const char *name, uint16_t addr, const radio_t *radio);
/**
* @brief Get the address of the network interface with given id.
@ -129,12 +129,14 @@ int mms_connect(int socket, uint16_t dest_addr);
/**
* @see ::trans_send(int,void*,int,protocol_t,uint8_t)
*/
int mms_sock_send(int socket, void* buffer, int length, protocol_t protocol, uint8_t priority);
int mms_sock_send(int socket, void *buffer, int length, protocol_t protocol,
uint8_t priority);
/**
* @see ::trans_sendto(int,void*,int,protocol_t,uint8_t,uint16_t)
*/
int mms_sock_sendto(int socket, void* buffer, int length, protocol_t protocol, uint8_t priority, uint16_t dest_addr);
int mms_sock_sendto(int socket, void *buffer, int length, protocol_t protocol,
uint8_t priority, uint16_t dest_addr);
/**
* @brief Convenience function to send a message via UDPL socket.
@ -148,7 +150,8 @@ int mms_sock_sendto(int socket, void* buffer, int length, protocol_t protocol, u
* @return Upon successful completion, mms_send() returns a value greater zero.
* Otherwise, a negative value is returned to indicate the error.
*/
int mms_send(void* msg, int msg_len, uint16_t dst, protocol_t protocol, uint8_t priority);
int mms_send(void *msg, int msg_len, uint16_t dst, protocol_t protocol,
uint8_t priority);
/**
* @see ::trans_poll(int)
@ -170,7 +173,7 @@ int mms_close(int socket, int how);
* @param msg_size Size of incoming packet.
* @param packet_info Additional packet information.
*/
void mms_receive(void* msg, int msg_size, packet_info_t* packet_info);
void mms_receive(void *msg, int msg_size, packet_info_t *packet_info);
/**
* @brief Flush kernel route table.
@ -188,7 +191,7 @@ void mms_flush_routes(bool flush_static);
*
* @param format String that contains the text to be written to stdout.
*/
void mms_net_printf(const char * format);
void mms_net_printf(const char *format);
/**
* @brief Print kernel route table.

@ -1,3 +1,21 @@
/**
* 6lowpan border router multiplexer
*
* Copyright (C) 2013 INRIA.
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*
* @ingroup sixlowpan
* @{
* @file bordermultiplex.c
* @brief multiplexiing border router information
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @}
*/
#include <stdio.h>
#include <string.h>
@ -16,158 +34,179 @@
#define END_ESC 0xDC
#define ESC_ESC 0xDD
void demultiplex(border_packet_t *packet, int len) {
switch (packet->type) {
case (BORDER_PACKET_RAW_TYPE):{
fputs(((char *)packet) + sizeof (border_packet_t), stdin);
void demultiplex(border_packet_t *packet, int len)
{
switch(packet->type) {
case(BORDER_PACKET_RAW_TYPE): {
fputs(((char *)packet) + sizeof(border_packet_t), stdin);
break;
}
case (BORDER_PACKET_L3_TYPE):{
case(BORDER_PACKET_L3_TYPE): {
border_l3_header_t *l3_header_buf = (border_l3_header_t *)packet;
switch (l3_header_buf->ethertype) {
case (BORDER_ETHERTYPE_IPV6):{
struct ipv6_hdr_t *ipv6_buf = (struct ipv6_hdr_t *)(((unsigned char *)packet) + sizeof (border_l3_header_t));
switch(l3_header_buf->ethertype) {
case(BORDER_ETHERTYPE_IPV6): {
struct ipv6_hdr_t *ipv6_buf = (struct ipv6_hdr_t *)(((unsigned char *)packet) + sizeof(border_l3_header_t));
border_send_ipv6_over_lowpan(ipv6_buf, 1, 1);
break;
}
default:
printf("ERROR: Unknown ethertype 0x%04x\n", l3_header_buf->ethertype);
break;
}
break;
}
case (BORDER_PACKET_CONF_TYPE):{
case(BORDER_PACKET_CONF_TYPE): {
border_conf_header_t *conf_header_buf = (border_conf_header_t *)packet;
switch (conf_header_buf->conftype) {
case (BORDER_CONF_CONTEXT):{
switch(conf_header_buf->conftype) {
case(BORDER_CONF_CONTEXT): {
border_context_packet_t *context = (border_context_packet_t *)packet;
ipv6_addr_t target_addr;
ipv6_set_all_nds_mcast_addr(&target_addr);
mutex_lock(&lowpan_context_mutex);
lowpan_context_update(
context->context.cid,
&context->context.prefix,
context->context.length,
context->context.comp,
context->context.lifetime
);
mutex_unlock(&lowpan_context_mutex,0);
context->context.cid,
&context->context.prefix,
context->context.length,
context->context.comp,
context->context.lifetime
);
mutex_unlock(&lowpan_context_mutex, 0);
abr_add_context(context->context.version, &abr_addr, context->context.cid);
// Send router advertisement
/* Send router advertisement */
break;
}
case (BORDER_CONF_IPADDR):{
case(BORDER_CONF_IPADDR): {
//border_addr_packet_t *addr_packet = (border_addr_packet_t *)packet;
// add address
/* add address */
break;
}
default:
printf("ERROR: Unknown conftype %02x\n", conf_header_buf->conftype);
break;
}
break;
}
default:
printf("ERROR: Unknown border packet type %02x\n", packet->type);
break;
}
}
void multiplex_send_ipv6_over_uart(struct ipv6_hdr_t *packet) {
void multiplex_send_ipv6_over_uart(struct ipv6_hdr_t *packet)
{
border_l3_header_t *serial_buf;
serial_buf = (border_l3_header_t *)get_serial_out_buffer(0);
serial_buf->empty = 0;
serial_buf->type = BORDER_PACKET_L3_TYPE;
serial_buf->ethertype = BORDER_ETHERTYPE_IPV6;
memcpy(get_serial_in_buffer(0)+sizeof (border_l3_header_t), packet, IPV6_HDR_LEN + packet->length);
flowcontrol_send_over_uart((border_packet_t *) serial_buf, sizeof (border_l3_header_t));
memcpy(get_serial_in_buffer(0) + sizeof(border_l3_header_t), packet, IPV6_HDR_LEN + packet->length);
flowcontrol_send_over_uart((border_packet_t *) serial_buf, sizeof(border_l3_header_t));
}
void multiplex_send_addr_over_uart(ipv6_addr_t *addr) {
void multiplex_send_addr_over_uart(ipv6_addr_t *addr)
{
border_addr_packet_t *serial_buf;
serial_buf = (border_addr_packet_t *)get_serial_in_buffer(0);
serial_buf->empty = 0;
serial_buf->type = BORDER_PACKET_CONF_TYPE;
serial_buf->conftype = BORDER_CONF_IPADDR;
memcpy(&serial_buf->addr, addr, sizeof(ipv6_addr_t));
flowcontrol_send_over_uart((border_packet_t *) serial_buf, sizeof (border_addr_packet_t));
flowcontrol_send_over_uart((border_packet_t *) serial_buf, sizeof(border_addr_packet_t));
}
int readpacket(uint8_t *packet_buf, size_t size) {
int readpacket(uint8_t *packet_buf, size_t size)
{
uint8_t *line_buf_ptr = packet_buf;
uint8_t byte = END+1;
uint8_t byte = END + 1;
uint8_t esc = 0;
while (1) {
while(1) {
byte = uart0_readc();
if (byte == END) {
if(byte == END) {
break;
}
if ( (line_buf_ptr - packet_buf) >= size-1) {
if((line_buf_ptr - packet_buf) >= size - 1) {
return -SIXLOWERROR_ARRAYFULL;
}
if (esc) {
if(esc) {
esc = 0;
switch (byte) {
case(END_ESC):{
switch(byte) {
case(END_ESC): {
*line_buf_ptr++ = END;
continue;
}
case(ESC_ESC):{
case(ESC_ESC): {
*line_buf_ptr++ = ESC;
continue;
}
default:
continue;
}
}
if (byte == ESC) {
if(byte == ESC) {
esc = 1;
continue;
}
*line_buf_ptr++ = byte;
}
return (line_buf_ptr - packet_buf - 1);
}
int writepacket(uint8_t *packet_buf, size_t size) {
int writepacket(uint8_t *packet_buf, size_t size)
{
uint8_t *byte_ptr = packet_buf;
while ((byte_ptr - packet_buf) < size) {
if ((byte_ptr - packet_buf) > BORDER_BUFFER_SIZE) {
while((byte_ptr - packet_buf) < size) {
if((byte_ptr - packet_buf) > BORDER_BUFFER_SIZE) {
return -1;
}
switch (*byte_ptr) {
case(END):{
switch(*byte_ptr) {
case(END): {
*byte_ptr = END_ESC;
uart0_putc(ESC);
break;
}
case(ESC):{
case(ESC): {
*byte_ptr = ESC_ESC;
uart0_putc(ESC);
break;
}
default:{
default: {
break;
}
}
uart0_putc(*byte_ptr);
byte_ptr++;
}
uart0_putc(END);
return (byte_ptr - packet_buf);
}

@ -1,3 +1,21 @@
/**
* 6lowpan border router multiplexer
*
* Copyright (C) 2013 INRIA.
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*
* @ingroup sixlowpan
* @{
* @file bordermultiplex.h
* @brief data structs for border router multiplexing
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @}
*/
#ifndef BORDERMULTIPLEX_H
#define BORDERMULTIPLEX_H
@ -18,27 +36,27 @@
/* ethertypes for L3 packets */
#define BORDER_ETHERTYPE_IPV6 0x86DD
typedef struct __attribute__ ((packed)) border_packet_t {
typedef struct __attribute__((packed)) {
uint8_t empty;
uint8_t type;
uint8_t seq_num;
} border_packet_t;
typedef struct __attribute__ ((packed)) border_l3_header_t {
typedef struct __attribute__((packed)) {
uint8_t empty;
uint8_t type;
uint8_t seq_num;
uint16_t ethertype;
} border_l3_header_t;
typedef struct __attribute__ ((packed)) border_conf_header_t {
typedef struct __attribute__((packed)) {
uint8_t empty;
uint8_t type;
uint8_t seq_num;
uint8_t conftype;
} border_conf_header_t;
typedef struct __attribute__ ((packed)) border_addr_packet_t {
typedef struct __attribute__((packed)) {
uint8_t empty;
uint8_t type;
uint8_t seq_num;
@ -47,7 +65,7 @@ typedef struct __attribute__ ((packed)) border_addr_packet_t {
ipv6_addr_t addr;
} border_addr_packet_t;
typedef struct __attribute__ ((packed)) border_context_packet_t {
typedef struct __attribute__((packed)) {
uint8_t empty;
uint8_t type;
uint8_t seq_num;

@ -1,3 +1,21 @@
/**
* 6lowpan border router flow control
*
* Copyright (C) 2013 INRIA.
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*
* @ingroup sixlowpan
* @{
* @file flowcontrol.c
* @brief flowcontrol for constraint node border router implementation
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @}
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -20,53 +38,59 @@ flowcontrol_stat_t slwin_stat;
sem_t connection_established;
int16_t synack_seqnum = -1;
ipv6_addr_t init_threeway_handshake(void) {
ipv6_addr_t init_threeway_handshake(void)
{
border_syn_packet_t *syn;
msg_t m;
m.content.ptr = NULL;
msg_send(&m,border_get_serial_reader(),1);
msg_send(&m, border_get_serial_reader(), 1);
msg_receive(&m);
syn = (border_syn_packet_t *)m.content.ptr;
border_conf_header_t *synack = (border_conf_header_t *)get_serial_out_buffer(0);
ipv6_addr_t addr;
memcpy(&addr, &(syn->addr), sizeof (ipv6_addr_t));
memcpy(&addr, &(syn->addr), sizeof(ipv6_addr_t));
slwin_stat.next_exp = syn->next_seq_num;
slwin_stat.last_frame = syn->next_exp - 1;
slwin_stat.last_ack = slwin_stat.last_frame;
synack->empty = 0;
synack->type = BORDER_PACKET_CONF_TYPE;
synack->conftype = BORDER_CONF_SYNACK;
sending_slot_pid = thread_create(sending_slot_stack, SENDING_SLOT_STACK_SIZE, PRIORITY_MAIN-1, CREATE_SLEEPING, sending_slot, "sending slot");
flowcontrol_send_over_uart((border_packet_t *)synack, sizeof (border_conf_header_t));
sending_slot_pid = thread_create(sending_slot_stack, SENDING_SLOT_STACK_SIZE, PRIORITY_MAIN - 1, CREATE_SLEEPING, sending_slot, "sending slot");
flowcontrol_send_over_uart((border_packet_t *)synack, sizeof(border_conf_header_t));
synack_seqnum = synack->seq_num;
return addr;
}
ipv6_addr_t flowcontrol_init(void) {
ipv6_addr_t flowcontrol_init(void)
{
int i;
sem_init(&slwin_stat.send_win_not_full,BORDER_SWS);
sem_init(&slwin_stat.send_win_not_full, BORDER_SWS);
for(i = 0; i < BORDER_SWS; i++) {
slwin_stat.send_win[i].frame_len = 0;
}
memset(&slwin_stat.send_win,0, sizeof(struct send_slot) * BORDER_SWS);
memset(&slwin_stat.send_win, 0, sizeof(struct send_slot) * BORDER_SWS);
for(i = 0; i < BORDER_RWS; i++) {
slwin_stat.recv_win[i].received = 0;
slwin_stat.recv_win[i].frame_len = 0;
}
memset(&slwin_stat.recv_win,0, sizeof(struct recv_slot) * BORDER_RWS);
memset(&slwin_stat.recv_win, 0, sizeof(struct recv_slot) * BORDER_RWS);
return init_threeway_handshake();
}
static void sending_slot(void) {
static void sending_slot(void)
{
msg_t m;
uint8_t seq_num;
struct send_slot *slot;
@ -76,93 +100,104 @@ static void sending_slot(void) {
msg_receive(&m);
seq_num = *((uint8_t *)m.content.ptr);
slot = &(slwin_stat.send_win[seq_num % BORDER_SWS]);
tmp = (border_packet_t*) slot->frame;
tmp = (border_packet_t *)slot->frame;
if (seq_num == tmp->seq_num) {
writepacket(slot->frame,slot->frame_len);
if (set_timeout(&slot->timeout, BORDER_SL_TIMEOUT, (void*) m.content.ptr) != 0) {
if(seq_num == tmp->seq_num) {
writepacket(slot->frame, slot->frame_len);
if(set_timeout(&slot->timeout, BORDER_SL_TIMEOUT, (void *)m.content.ptr) != 0) {
printf("ERROR: Error invoking timeout timer\n");
}
}
}
}
static int set_timeout(vtimer_t *timeout, long useconds, void *args) {
static int set_timeout(vtimer_t *timeout, long useconds, void *args)
{
timex_t interval;
interval.seconds = useconds / 1000000;
interval.microseconds = (useconds % 1000000) * 1000;
return vtimer_set_msg(timeout, interval, sending_slot_pid, args);
}
static int in_window(uint8_t seq_num, uint8_t min, uint8_t max) {
static int in_window(uint8_t seq_num, uint8_t min, uint8_t max)
{
uint8_t pos = seq_num - min;
uint8_t maxpos = max - min + 1;
return pos < maxpos;
}
void flowcontrol_send_over_uart(border_packet_t *packet, int len) {
void flowcontrol_send_over_uart(border_packet_t *packet, int len)
{
struct send_slot *slot;
uint8_t args[] = {packet->seq_num};
sem_wait(&(slwin_stat.send_win_not_full));
packet->seq_num = ++slwin_stat.last_frame;
slot = &(slwin_stat.send_win[packet->seq_num % BORDER_SWS]);
memcpy(slot->frame, (uint8_t *)packet, len);
slot->frame_len = len;
if (set_timeout(&slot->timeout, BORDER_SL_TIMEOUT, (void *)args) != 0) {
if(set_timeout(&slot->timeout, BORDER_SL_TIMEOUT, (void *)args) != 0) {
printf("ERROR: Error invoking timeout timer\n");
return;
}
writepacket((uint8_t *)packet, len);
}
void send_ack(uint8_t seq_num) {
void send_ack(uint8_t seq_num)
{
border_packet_t *packet = (border_packet_t *)get_serial_out_buffer(0);
packet->empty = 0;
packet->type = BORDER_PACKET_ACK_TYPE;
packet->seq_num = seq_num;
writepacket((uint8_t *)packet, sizeof (border_packet_t));
writepacket((uint8_t *)packet, sizeof(border_packet_t));
}
void flowcontrol_deliver_from_uart(border_packet_t *packet, int len) {
if (packet->type == BORDER_PACKET_ACK_TYPE) {
if (in_window(packet->seq_num, slwin_stat.last_ack+1, slwin_stat.last_frame)) {
if (synack_seqnum == packet->seq_num) {
void flowcontrol_deliver_from_uart(border_packet_t *packet, int len)
{
if(packet->type == BORDER_PACKET_ACK_TYPE) {
if(in_window(packet->seq_num, slwin_stat.last_ack + 1, slwin_stat.last_frame)) {
if(synack_seqnum == packet->seq_num) {
synack_seqnum = -1;
sem_signal(&connection_established);
}
do {
struct send_slot *slot;
slot = &(slwin_stat.send_win[++slwin_stat.last_ack % BORDER_SWS]);
vtimer_remove(&slot->timeout);
memset(&slot->frame,0,BORDER_BUFFER_SIZE);
memset(&slot->frame, 0, BORDER_BUFFER_SIZE);
sem_signal(&slwin_stat.send_win_not_full);
} while (slwin_stat.last_ack != packet->seq_num);
}
while(slwin_stat.last_ack != packet->seq_num);
}
} else {
}
else {
struct recv_slot *slot;
slot = &(slwin_stat.recv_win[packet->seq_num % BORDER_RWS]);
if ( !in_window(packet->seq_num,
slwin_stat.next_exp,
slwin_stat.next_exp + BORDER_RWS - 1)) {
if(!in_window(packet->seq_num,
slwin_stat.next_exp,
slwin_stat.next_exp + BORDER_RWS - 1)) {
return;
}
memcpy(slot->frame, (uint8_t *)packet, len);
slot->received = 1;
if (packet->seq_num == slwin_stat.next_exp) {
while (slot->received) {
if(packet->seq_num == slwin_stat.next_exp) {
while(slot->received) {
demultiplex((border_packet_t *)slot->frame