Contiki-NG
border-router-embedded.c
Go to the documentation of this file.
1/*
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions
4 * are met:
5 * 1. Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * 2. Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * 3. Neither the name of the Institute nor the names of its contributors
11 * may be used to endorse or promote products derived from this software
12 * without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * This file is part of the Contiki operating system.
27 *
28 */
29/**
30 * \file
31 * border-router
32 * \author
33 * Niclas Finne <nfi@sics.se>
34 * Joakim Eriksson <joakime@sics.se>
35 * Nicolas Tsiftes <nvt@sics.se>
36 */
37
38#include "contiki.h"
39#include "net/routing/routing.h"
40#if PLATFORM_SUPPORTS_BUTTON_HAL
41#include "dev/button-hal.h"
42#else
43#include "dev/button-sensor.h"
44#endif
45#include "dev/slip.h"
46#include "rpl-border-router.h"
47
48/*---------------------------------------------------------------------------*/
49/* Log configuration */
50#include "sys/log.h"
51#define LOG_MODULE "BR"
52#define LOG_LEVEL LOG_LEVEL_INFO
53
54void request_prefix(void);
55
56/*---------------------------------------------------------------------------*/
57PROCESS(border_router_process, "Border router process");
58/*---------------------------------------------------------------------------*/
59PROCESS_THREAD(border_router_process, ev, data)
60{
61 static struct etimer et;
62
64
65/* While waiting for the prefix to be sent through the SLIP connection, the future
66 * border router can join an existing DAG as a parent or child, or acquire a default
67 * router that will later take precedence over the SLIP fallback interface.
68 * Prevent that by turning the radio off until we are initialized as a DAG root.
69 */
70 prefix_set = 0;
71 NETSTACK_MAC.off();
72
74
75#if !PLATFORM_SUPPORTS_BUTTON_HAL
76 SENSORS_ACTIVATE(button_sensor);
77#endif
78
79 LOG_INFO("RPL-Border router started\n");
80
81 /* Request prefix until it has been received */
82 while(!prefix_set) {
84 request_prefix();
86 LOG_INFO("Waiting for prefix\n");
87 }
88
89 NETSTACK_MAC.on();
90
91 print_local_addresses();
92
93 while(1) {
95#if PLATFORM_SUPPORTS_BUTTON_HAL
96 if(ev == button_hal_release_event) {
97#else
98 if(ev == sensors_event && data == &button_sensor) {
99#endif
100 LOG_INFO("Initiating global repair\n");
101 NETSTACK_ROUTING.global_repair("Button press");
102 }
103 }
104
105 PROCESS_END();
106}
107/*---------------------------------------------------------------------------*/
Header file for the button HAL.
process_event_t button_hal_release_event
A broadcast event generated when a button gets released.
Definition: button-hal.c:54
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
Definition: cc2538-rf.c:1154
#define CLOCK_SECOND
A second, measured in system clock time.
Definition: clock.h:82
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
Definition: etimer.c:213
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Definition: etimer.c:177
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define PROCESS_PAUSE()
Yield the process for a short while.
Definition: process.h:221
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
Definition: process.h:157
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
#define PROCESS_YIELD()
Yield the currently running process.
Definition: process.h:164
Header file for the logging system.
Routing driver header file.
A timer.
Definition: etimer.h:76
int(* on)(void)
Turn the MAC layer on.
Definition: mac.h:75
int(* off)(void)
Turn the MAC layer off.
Definition: mac.h:78
void(* global_repair)(const char *str)
Triggers a global topology repair.
Definition: routing.h:120
SENSORS & button_sensor
Exports global symbols for the sensor API.
Definition: z1-sensors.c:46