fb11e647
vrobic
reseau statique a...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/*
* 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 <string.h>
#include <stdbool.h>
#include "net/eui64.h"
#include "net/ieee802154.h"
#include "net/netdev2.h"
#include "net/netdev2/ieee802154.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
static int _get_iid(netdev2_ieee802154_t *dev, eui64_t *value, size_t max_len)
{
uint8_t *addr;
uint16_t addr_len;
assert(max_len >= sizeof(eui64_t));
if (dev->flags & NETDEV2_IEEE802154_SRC_MODE_LONG) {
addr_len = IEEE802154_LONG_ADDRESS_LEN;
addr = dev->long_addr;
}
else {
addr_len = IEEE802154_SHORT_ADDRESS_LEN;
addr = dev->short_addr;
}
ieee802154_get_iid(value, addr, addr_len);
return sizeof(eui64_t);
}
int netdev2_ieee802154_get(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
size_t max_len)
{
int res = -ENOTSUP;
switch (opt) {
case NETOPT_ADDRESS:
assert(max_len >= sizeof(dev->short_addr));
memcpy(value, dev->short_addr, sizeof(dev->short_addr));
res = sizeof(dev->short_addr);
break;
case NETOPT_ADDRESS_LONG:
assert(max_len >= sizeof(dev->long_addr));
memcpy(value, dev->long_addr, sizeof(dev->long_addr));
res = sizeof(dev->long_addr);
break;
case NETOPT_ADDR_LEN:
case NETOPT_SRC_LEN:
assert(max_len == sizeof(uint16_t));
if (dev->flags & NETDEV2_IEEE802154_SRC_MODE_LONG) {
*((uint16_t *)value) = IEEE802154_LONG_ADDRESS_LEN;
}
else {
*((uint16_t *)value) = IEEE802154_SHORT_ADDRESS_LEN;
}
res = sizeof(uint16_t);
break;
case NETOPT_NID:
assert(max_len == sizeof(dev->pan));
*((uint16_t *)value) = dev->pan;
res = sizeof(dev->pan);
break;
case NETOPT_CHANNEL:
assert(max_len == sizeof(uint16_t));
*((uint16_t *)value) = (uint16_t)dev->chan;
res = sizeof(dev->chan);
break;
case NETOPT_ACK_REQ:
assert(max_len == sizeof(netopt_enable_t));
if (dev->flags & NETDEV2_IEEE802154_ACK_REQ) {
*((netopt_enable_t *)value) = NETOPT_ENABLE;
}
else {
*((netopt_enable_t *)value) = NETOPT_DISABLE;
}
res = sizeof(netopt_enable_t);
break;
case NETOPT_RAWMODE:
assert(max_len == sizeof(netopt_enable_t));
if (dev->flags & NETDEV2_IEEE802154_RAW) {
*((netopt_enable_t *)value) = NETOPT_ENABLE;
}
else {
*((netopt_enable_t *)value) = NETOPT_DISABLE;
}
res = sizeof(netopt_enable_t);
break;
#ifdef MODULE_GNRC
case NETOPT_PROTO:
assert(max_len == sizeof(gnrc_nettype_t));
*((gnrc_nettype_t *)value) = dev->proto;
res = sizeof(gnrc_nettype_t);
break;
#endif
case NETOPT_DEVICE_TYPE:
assert(max_len == sizeof(uint16_t));
*((uint16_t *)value) = NETDEV2_TYPE_IEEE802154;
res = sizeof(uint16_t);
break;
case NETOPT_IPV6_IID:
res = _get_iid(dev, value, max_len);
break;
#ifdef MODULE_NETSTATS_L2
case NETOPT_STATS:
assert(max_len == sizeof(uintptr_t));
*((netstats_t **)value) = &dev->netdev.stats;
res = sizeof(uintptr_t);
break;
#endif
default:
break;
}
return res;
}
int netdev2_ieee802154_set(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
size_t len)
{
int res = -ENOTSUP;
switch (opt) {
case NETOPT_CHANNEL:
{
assert(len == sizeof(uint16_t));
uint16_t chan = *((uint16_t *)value);
/* real validity needs to be checked by device, since sub-GHz and
* 2.4 GHz band radios have different legal values. Here we only
* check that it fits in an 8-bit variabl*/
assert(chan <= UINT8_MAX);
dev->chan = chan;
res = sizeof(uint16_t);
break;
}
case NETOPT_ADDRESS:
assert(len <= sizeof(dev->short_addr));
memset(dev->short_addr, 0, sizeof(dev->short_addr));
memcpy(dev->short_addr, value, len);
res = sizeof(dev->short_addr);
break;
case NETOPT_ADDRESS_LONG:
assert(len <= sizeof(dev->long_addr));
memset(dev->long_addr, 0, sizeof(dev->long_addr));
memcpy(dev->long_addr, value, len);
res = sizeof(dev->long_addr);
break;
case NETOPT_ADDR_LEN:
case NETOPT_SRC_LEN:
assert(len == sizeof(uint16_t));
switch ((*(uint16_t *)value)) {
case IEEE802154_SHORT_ADDRESS_LEN:
dev->flags &= ~NETDEV2_IEEE802154_SRC_MODE_LONG;
break;
case IEEE802154_LONG_ADDRESS_LEN:
dev->flags |= NETDEV2_IEEE802154_SRC_MODE_LONG;
break;
default:
res = -EAFNOSUPPORT;
break;
}
res = sizeof(uint16_t);
break;
case NETOPT_NID:
assert(len == sizeof(dev->pan));
dev->pan = *((uint16_t *)value);
res = sizeof(dev->pan);
break;
case NETOPT_ACK_REQ:
if ((*(bool *)value)) {
dev->flags |= NETDEV2_IEEE802154_ACK_REQ;
}
else {
dev->flags &= ~NETDEV2_IEEE802154_ACK_REQ;
}
res = sizeof(uint16_t);
break;
case NETOPT_RAWMODE:
if ((*(bool *)value)) {
dev->flags |= NETDEV2_IEEE802154_RAW;
}
else {
dev->flags &= ~NETDEV2_IEEE802154_RAW;
}
res = sizeof(uint16_t);
break;
#ifdef MODULE_GNRC
case NETOPT_PROTO:
assert(len == sizeof(gnrc_nettype_t));
dev->proto = *((gnrc_nettype_t *)value);
res = sizeof(gnrc_nettype_t);
break;
#endif
default:
break;
}
return res;
}
/** @} */
|