Contiki-NG
Loading...
Searching...
No Matches
tun-bridge.c
1/*
2 * Copyright (c) 2011, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/**
31 * \author
32 * Niclas Finne <nfi@sics.se>
33 * Joakim Eriksson <joakime@sics.se>
34 */
35
36#include <stdio.h>
37#include <stdlib.h>
38#include <sys/time.h>
39#include <err.h>
40#include "border-router.h"
41#include "tun6-net.h"
42
43/*---------------------------------------------------------------------------*/
44/* Log configuration */
45#include "sys/log.h"
46#define LOG_MODULE "BR"
47#define LOG_LEVEL LOG_LEVEL_NONE
48
49extern uint16_t slip_config_basedelay;
50/*---------------------------------------------------------------------------*/
51#if CLOCK_SECOND != 1000
52#error The system clock must be ticking in milliseconds
53#endif
54static struct timer delay_timer;
55/*---------------------------------------------------------------------------*/
56static void
57tun_input_callback(void)
58{
59 /* Optional delay between outgoing packets */
60 /* Base delay times number of 6lowpan fragments to be sent */
61 if(!slip_config_basedelay || timer_expired(&delay_timer)) {
62 uip_len = tun6_net_input(uip_buf, sizeof(uip_buf));
64
65 if(slip_config_basedelay) {
66 timer_set(&delay_timer, slip_config_basedelay);
67 }
68 }
69}
70/*---------------------------------------------------------------------------*/
71void
72tun_init(void)
73{
74 timer_set(&delay_timer, 0);
75
76 slip_init();
77
78 if(!tun6_net_init(tun_input_callback)) {
79 err(EXIT_FAILURE, "failed to open tun device %s", tun6_net_get_tun_name());
80 }
81}
82/*---------------------------------------------------------------------------*/
83static void
84init(void)
85{
86}
87/*---------------------------------------------------------------------------*/
88static int
89output(void)
90{
91 LOG_DBG("SUT: %u\n", uip_len);
92 if(uip_len > 0) {
93 return tun6_net_output(uip_buf, uip_len);
94 }
95 return 0;
96}
97/*---------------------------------------------------------------------------*/
98const struct uip_fallback_interface rpl_interface = {
99 init, output
100};
101/*---------------------------------------------------------------------------*/
Border router header file.
void tcpip_input(void)
Deliver an incoming packet to the TCP/IP stack.
Definition tcpip.c:433
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
Definition timer.c:64
bool timer_expired(struct timer *t)
Check if a timer has expired.
Definition timer.c:123
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
Definition uip.h:465
uint16_t uip_len
The length of the packet in the uip_buf buffer.
Definition uip6.c:159
Header file for the logging system.
A timer.
Definition timer.h:84