Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
slip-bridge.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010, 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
/**
32
* \file
33
* Slip fallback interface
34
* \author
35
* Niclas Finne <nfi@sics.se>
36
* Joakim Eriksson <joakime@sics.se>
37
* Joel Hoglund <joel@sics.se>
38
* Nicolas Tsiftes <nvt@sics.se>
39
*/
40
/*---------------------------------------------------------------------------*/
41
#include "
net/ipv6/uip.h
"
42
#include "
net/ipv6/uip-ds6.h
"
43
#include "dev/slip.h"
44
#include <string.h>
45
/*---------------------------------------------------------------------------*/
46
/* Log configuration */
47
#include "
sys/log.h
"
48
#define LOG_MODULE "SLIP"
49
#define LOG_LEVEL LOG_LEVEL_NONE
50
/*---------------------------------------------------------------------------*/
51
void
set_prefix_64(uip_ipaddr_t *);
52
53
static
uip_ipaddr_t last_sender;
54
55
/*---------------------------------------------------------------------------*/
56
void
57
request_prefix(
void
)
58
{
59
/* mess up uip_buf with a dirty request... */
60
uip_buf
[0] =
'?'
;
61
uip_buf
[1] =
'P'
;
62
uip_len
= 2;
63
slip_write(
uip_buf
,
uip_len
);
64
uipbuf_clear();
65
}
66
/*---------------------------------------------------------------------------*/
67
static
void
68
slip_input_callback(
void
)
69
{
70
LOG_DBG(
"SIN: %u\n"
,
uip_len
);
71
if
(
uip_buf
[0] ==
'!'
) {
72
LOG_INFO(
"Got configuration message of type %c\n"
,
73
uip_buf
[1]);
74
if
(
uip_buf
[1] ==
'P'
) {
75
uip_ipaddr_t prefix;
76
/* Here we set a prefix !!! */
77
memset(&prefix, 0, 16);
78
memcpy(&prefix, &
uip_buf
[2], 8);
79
80
uipbuf_clear();
81
82
LOG_INFO(
"Setting prefix "
);
83
LOG_INFO_6ADDR(&prefix);
84
LOG_INFO_(
"\n"
);
85
set_prefix_64(&prefix);
86
}
87
uipbuf_clear();
88
89
}
else
if
(
uip_buf
[0] ==
'?'
) {
90
LOG_INFO(
"Got request message of type %c\n"
,
uip_buf
[1]);
91
if
(
uip_buf
[1] ==
'M'
) {
92
char
*hexchar =
"0123456789abcdef"
;
93
int
j;
94
/* this is just a test so far... just to see if it works */
95
uip_buf
[0] =
'!'
;
96
for
(j = 0; j <
UIP_LLADDR_LEN
; j++) {
97
uip_buf
[2 + j * 2] = hexchar[
uip_lladdr
.addr[j] >> 4];
98
uip_buf
[3 + j * 2] = hexchar[
uip_lladdr
.addr[j] & 15];
99
}
100
uip_len
= 18;
101
slip_write(
uip_buf
,
uip_len
);
102
}
103
uipbuf_clear();
104
}
else
{
105
/* Save the last sender received over SLIP to avoid bouncing the
106
packet back if no route is found */
107
uip_ipaddr_copy
(&last_sender, &
UIP_IP_BUF
->srcipaddr);
108
}
109
}
110
/*---------------------------------------------------------------------------*/
111
static
void
112
init
(
void
)
113
{
114
slip_arch_init
();
115
process_start
(&slip_process, NULL);
116
slip_set_input_callback(slip_input_callback);
117
}
118
/*---------------------------------------------------------------------------*/
119
static
int
120
output(
void
)
121
{
122
if
(uip_ipaddr_cmp(&last_sender, &
UIP_IP_BUF
->srcipaddr)) {
123
/* Do not bounce packets back over SLIP if the packet was received
124
over SLIP */
125
LOG_ERR(
"slip-bridge: Destination off-link but no route src="
);
126
LOG_ERR_6ADDR(&
UIP_IP_BUF
->srcipaddr);
127
LOG_ERR_(
" dst="
);
128
LOG_ERR_6ADDR(&
UIP_IP_BUF
->destipaddr);
129
LOG_ERR_(
"\n"
);
130
}
else
{
131
LOG_DBG(
"SUT: %u\n"
,
uip_len
);
132
slip_send();
133
}
134
return
0;
135
}
136
/*---------------------------------------------------------------------------*/
137
const
struct
uip_fallback_interface rpl_interface = {
138
init, output
139
};
140
/*---------------------------------------------------------------------------*/
slip_arch_init
void slip_arch_init(void)
Initialize the SLIP driver.
Definition
slip-arch.c:62
init
static int init(void)
Definition
cc2538-rf.c:556
process_start
void process_start(struct process *p, process_data_t data)
Start a process.
Definition
process.c:121
uip_lladdr
uip_lladdr_t uip_lladdr
Host L2 address.
Definition
uip6.c:107
UIP_LLADDR_LEN
#define UIP_LLADDR_LEN
802.15.4 address
Definition
uip.h:145
UIP_IP_BUF
#define UIP_IP_BUF
Direct access to IPv6 header.
Definition
uip.h:71
uip_ipaddr_copy
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
Definition
uip.h:969
uip_buf
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
Definition
uip.h:465
uip_len
uint16_t uip_len
The length of the packet in the uip_buf buffer.
Definition
uip6.c:159
log.h
Header file for the logging system.
uip-ds6.h
Header file for IPv6-related data structures.
uip.h
Header file for the uIP TCP/IP stack.
os
services
rpl-border-router
embedded
slip-bridge.c
Generated on
for Contiki-NG by
1.17.0