Skip to content

Commit 096aeef

Browse files
author
Mika Tervonen
authored
ws create interface and start rpl for poc (ARMmbed#1562)
1 parent 9bf1d1f commit 096aeef

File tree

6 files changed

+242
-55
lines changed

6 files changed

+242
-55
lines changed

source/6LoWPAN/adaptation_interface.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,11 @@ static bool mac_data_is_broadcast_addr(const sockaddr_t *addr)
990990
static bool mcps_data_indication_neighbor_validate(int8_t interface_id, const sockaddr_t *addr)
991991
{
992992
/* If MLE is enabled, we will talk if we have an MLE association */
993+
994+
if (!mle_class_exists_for_interface(interface_id)) {
995+
// No MLE for this interface all neighbours are valid
996+
return true;
997+
}
993998
mle_neigh_table_entry_t *mle_entry = mle_class_get_by_link_address(interface_id, addr->address + 2, addr->addr_type);
994999
if (mle_entry && (mle_entry->handshakeReady || mle_entry->thread_commission)) {
9951000
return true;

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 216 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,65 +15,37 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include <string.h>
1819
#include "nsconfig.h"
1920
#include "ns_types.h"
2021
#include "ns_trace.h"
2122
#include "net_interface.h"
2223
#include "eventOS_event.h"
2324
#include "NWK_INTERFACE/Include/protocol.h"
25+
#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
2426
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
27+
#include "6LoWPAN/MAC/mac_helper.h"
28+
#include "6LoWPAN/MAC/mac_data_poll.h"
2529
#include "6LoWPAN/ws/ws_common.h"
2630
#include "6LoWPAN/ws/ws_bootstrap.h"
31+
#include "RPL/rpl_control.h"
32+
#include "RPL/rpl_data.h"
33+
#include "Common_Protocols/icmpv6.h"
34+
#include "Common_Protocols/icmpv6_radv.h"
2735

36+
#include "net_rpl.h"
2837
#include "mac_api.h"
2938

3039
#define TRACE_GROUP "wsbs"
3140

3241
#ifdef HAVE_WS
33-
34-
static void ws_bootstrap_tasklet(arm_event_s *event)
35-
{
36-
ws_bootsrap_event_type_e event_type;
37-
event_type = (ws_bootsrap_event_type_e)event->event_type;
38-
protocol_interface_info_entry_t *cur;
39-
cur = protocol_stack_interface_info_get_by_bootstrap_id(event->receiver);
40-
if (!cur) {
41-
return;
42-
}
43-
44-
switch (event_type) {
45-
case WS_INIT_EVENT:
46-
tr_debug("tasklet init");
47-
break;
48-
case WS_DISCOVERY_START:
49-
tr_debug("Discovery start");
50-
ws_bootstrap_configuration_start(cur);
51-
52-
break;
53-
case WS_CONFIGURATION_START:
54-
tr_debug("Configuration start");
55-
ws_bootstrap_authentication_start(cur);
56-
break;
57-
case WS_AUTHENTICATION_START:
58-
tr_debug("authentication start");
59-
ws_bootstrap_operation_start(cur);
60-
break;
61-
case WS_OPERATION_START:
62-
tr_debug("operation start");
63-
// Activate RPL
64-
// Activate IPv6 stack
65-
break;
66-
default:
67-
tr_err("Invalid event received");
68-
break;
69-
}
70-
71-
}
42+
static void ws_bootstrap_event_handler(arm_event_s *event);
43+
static void ws_bootstrap_state_change(protocol_interface_info_entry_t *cur, icmp_state_t nwk_bootstrap_state);
7244

7345
static int ws_bootstrap_tasklet_init(protocol_interface_info_entry_t *cur)
7446
{
7547
if (cur->bootStrapId < 0) {
76-
cur->bootStrapId = eventOS_event_handler_create(&ws_bootstrap_tasklet, WS_INIT_EVENT);
48+
cur->bootStrapId = eventOS_event_handler_create(&ws_bootstrap_event_handler, WS_INIT_EVENT);
7749
tr_debug("WS tasklet init");
7850
}
7951

@@ -116,13 +88,13 @@ static int8_t ws_bootsrap_event_trig(ws_bootsrap_event_type_e event_type, int8_t
11688
protocol_6lowpan_register_handlers(cur);
11789
addr_interface_set_ll64(cur, NULL);
11890
cur->nwk_nd_re_scan_count = 0;
119-
//thread_interface_up(cur);
91+
//WS_interface_up(cur);
12092
// Trigger discovery for bootstrap
12193
ret_val = nwk_6lowpan_up(cur);
12294
if (ret_val) {
12395
goto cleanup;
12496
}
125-
ws_bootstrap_discovery_start(cur);
97+
ws_bootstrap_event_discovery_start(cur);
12698

12799
return 0;
128100
cleanup:
@@ -149,6 +121,7 @@ void ws_bootstrap_configuration_reset(protocol_interface_info_entry_t *cur)
149121

150122
// Do not process beacons
151123
cur->mac_parameters->beacon_ind = NULL;
124+
cur->mac_parameters->mac_security_level = 0;
152125

153126
// Set default parameters to interface
154127
cur->configure_flags = INTERFACE_BOOTSTRAP_DEFINED;
@@ -169,6 +142,7 @@ void ws_bootstrap_configuration_reset(protocol_interface_info_entry_t *cur)
169142
tr_err("Invalid bootstrap_mode");
170143
}
171144

145+
cur->nwk_bootstrap_state = ER_ACTIVE_SCAN;
172146
//cur->mac_security_key_usage_update_cb = ws_management_mac_security_key_update_cb;
173147
return;
174148
}
@@ -226,21 +200,213 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
226200
return 0;
227201
}
228202

229-
void ws_bootstrap_discovery_start(protocol_interface_info_entry_t *cur)
203+
static void ws_bootstrap_mac_activate(protocol_interface_info_entry_t *cur, uint16_t channel, uint16_t panid, bool coordinator)
204+
{
205+
mlme_start_t start_req;
206+
memset(&start_req, 0, sizeof(mlme_start_t));
207+
208+
cur->mac_parameters->pan_id = panid;
209+
cur->mac_parameters->mac_channel = channel;
210+
211+
start_req.PANId = panid;
212+
start_req.LogicalChannel = channel;
213+
start_req.BeaconOrder = 0x0f;
214+
start_req.SuperframeOrder = 0x0f;
215+
start_req.PANCoordinator = coordinator;
216+
217+
if (cur->mac_api) {
218+
cur->mac_api->mlme_req(cur->mac_api, MLME_START, (void*)&start_req);
219+
}
220+
}
221+
static void ws_bootstrap_mac_interface_activate(protocol_interface_info_entry_t *cur)
222+
{
223+
tr_debug("MAC init");
224+
mac_helper_pib_boolean_set(cur, macRxOnWhenIdle, true);
225+
cur->lowpan_info &= ~INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE;
226+
227+
//mac_data_poll_init(cur);
228+
//mac_helper_mac16_address_set(cur, 0xffff);
229+
//mac_helper_default_security_level_set(cur, cur->mac_parameters->mac_configured_sec_level);
230+
//mac_helper_default_security_key_id_mode_set(cur,MAC_KEY_ID_MODE_IDX);
231+
ws_bootstrap_mac_activate(cur, 11, 0xabab, true);
232+
return;
233+
}
234+
static void ws_bootstrap_ip_stack_activate(protocol_interface_info_entry_t *cur)
235+
{
236+
tr_debug("ip stack init");
237+
clear_power_state(ICMP_ACTIVE);
238+
cur->lowpan_info |= INTERFACE_NWK_BOOTSRAP_ACTIVE;
239+
}
240+
static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
241+
{
242+
243+
protocol_interface_info_entry_t *cur = handle;
244+
if (!cur->rpl_domain || cur->interface_mode != INTERFACE_UP) {
245+
return;
246+
}
247+
tr_warn("RPL callback event %d", event);
248+
}
249+
static uint8_t dodag_id[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
250+
static uint8_t dodag_prefix[16] = {0xfd,00,0xaa};
251+
252+
static void ws_bootstrap_rpl_root_activate(protocol_interface_info_entry_t *cur)
253+
{
254+
tr_debug("RPL root Activate");
255+
rpl_dodag_conf_t new_conf;
256+
new_conf.default_lifetime = 64;
257+
new_conf.lifetime_unit = 60;
258+
new_conf.dag_max_rank_increase = 3072;
259+
new_conf.min_hop_rank_increase = 128;// 24 HOP?
260+
new_conf.dio_interval_min = 9;
261+
new_conf.dio_interval_doublings = 12;
262+
new_conf.dio_redundancy_constant = 10;
263+
new_conf.objective_code_point = 1;
264+
new_conf.authentication = 0;
265+
new_conf.path_control_size = 0;
266+
rpl_data_init_root();
267+
protocol_6lowpan_rpl_root_dodag = rpl_control_create_dodag_root(protocol_6lowpan_rpl_domain, 1, dodag_id, &new_conf, new_conf.min_hop_rank_increase, RPL_GROUNDED | RPL_MODE_NON_STORING | RPL_DODAG_PREF(0));
268+
if (!protocol_6lowpan_rpl_root_dodag) {
269+
tr_err("RPL dodag init failed");
270+
}
271+
uint8_t t_flags = PIO_A;
272+
273+
icmpv6_slaac_address_add(cur, dodag_prefix, 64, 0xffffffff, 0xffffffff, true, SLAAC_IID_FIXED);
274+
275+
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, dodag_prefix, 64, t_flags, 0xffffffff, 0xffffffff, false);
276+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, dodag_prefix, 64, 0, 0xffffffff, false);
277+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 0xffffffff, false);
278+
}
279+
280+
static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
281+
{
282+
tr_debug("RPL Activate");
283+
bool downstream = true;
284+
bool leaf = false;
285+
286+
addr_add_router_groups(cur);
287+
rpl_control_set_domain_on_interface(cur, protocol_6lowpan_rpl_domain, downstream);
288+
rpl_control_set_callback(protocol_6lowpan_rpl_domain, ws_bootstrap_rpl_callback, cur);
289+
// If i am router I Do this
290+
rpl_control_force_leaf(protocol_6lowpan_rpl_domain, leaf);
291+
292+
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER) {
293+
rpl_control_transmit_dis(cur->rpl_domain, cur, 0, 0, NULL, 0, ADDR_LINK_LOCAL_ALL_ROUTERS);
294+
} else if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
295+
ws_bootstrap_rpl_root_activate(cur);
296+
}
297+
298+
}
299+
300+
301+
static void ws_bootstrap_icmp_rs_msg_tx(protocol_interface_info_entry_t *cur)
230302
{
231-
ws_bootsrap_event_trig(WS_DISCOVERY_START, cur->bootStrapId, ARM_LIB_HIGH_PRIORITY_EVENT);
303+
tr_debug("send RS");
304+
buffer_t *buf = icmpv6_build_rs(cur, NULL);
305+
306+
protocol_push(buf);
232307
}
233-
void ws_bootstrap_configuration_start(protocol_interface_info_entry_t *cur)
308+
309+
/*
310+
* Event transitions
311+
*
312+
* */
313+
314+
void ws_bootstrap_event_discovery_start(protocol_interface_info_entry_t *cur)
234315
{
235-
ws_bootsrap_event_trig(WS_CONFIGURATION_START, cur->bootStrapId, ARM_LIB_HIGH_PRIORITY_EVENT);
316+
ws_bootsrap_event_trig(WS_DISCOVERY_START, cur->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT);
236317
}
237-
void ws_bootstrap_authentication_start(protocol_interface_info_entry_t *cur)
318+
void ws_bootstrap_event_configuration_start(protocol_interface_info_entry_t *cur)
238319
{
239-
ws_bootsrap_event_trig(WS_AUTHENTICATION_START, cur->bootStrapId, ARM_LIB_HIGH_PRIORITY_EVENT);
320+
ws_bootsrap_event_trig(WS_CONFIGURATION_START, cur->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT);
321+
}
322+
void ws_bootstrap_event_authentication_start(protocol_interface_info_entry_t *cur)
323+
{
324+
ws_bootsrap_event_trig(WS_AUTHENTICATION_START, cur->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT);
325+
}
326+
void ws_bootstrap_event_operation_start(protocol_interface_info_entry_t *cur)
327+
{
328+
ws_bootsrap_event_trig(WS_OPERATION_START, cur->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT);
329+
}
330+
void ws_bootstrap_event_routing_ready(protocol_interface_info_entry_t *cur)
331+
{
332+
ws_bootsrap_event_trig(WS_ROUTING_READY, cur->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT);
333+
}
334+
335+
static void ws_bootstrap_event_handler(arm_event_s *event)
336+
{
337+
ws_bootsrap_event_type_e event_type;
338+
event_type = (ws_bootsrap_event_type_e)event->event_type;
339+
protocol_interface_info_entry_t *cur;
340+
cur = protocol_stack_interface_info_get_by_bootstrap_id(event->receiver);
341+
if (!cur) {
342+
return;
343+
}
344+
345+
switch (event_type) {
346+
case WS_INIT_EVENT:
347+
tr_debug("tasklet init");
348+
break;
349+
case WS_DISCOVERY_START:
350+
tr_info("Discovery start");
351+
ws_bootstrap_mac_interface_activate(cur);
352+
ws_bootstrap_state_change(cur, ER_ACTIVE_SCAN);
353+
break;
354+
case WS_CONFIGURATION_START:
355+
tr_info("Configuration start");
356+
ws_bootstrap_event_authentication_start(cur);
357+
break;
358+
case WS_AUTHENTICATION_START:
359+
tr_info("authentication start");
360+
ws_bootstrap_event_operation_start(cur);
361+
break;
362+
case WS_OPERATION_START:
363+
tr_info("operation start");
364+
// Activate RPL
365+
// Activate IPv6 stack
366+
ws_bootstrap_ip_stack_activate(cur);
367+
ws_bootstrap_rpl_activate(cur);
368+
ws_bootstrap_event_routing_ready(cur);
369+
break;
370+
case WS_ROUTING_READY:
371+
tr_info("Routing ready");
372+
ws_bootstrap_state_change(cur, ER_BOOTSRAP_DONE);
373+
break;
374+
default:
375+
tr_err("Invalid event received");
376+
break;
377+
}
378+
240379
}
241-
void ws_bootstrap_operation_start(protocol_interface_info_entry_t *cur)
380+
381+
382+
/*
383+
* State machine
384+
*
385+
* */
386+
387+
static void ws_bootstrap_state_change(protocol_interface_info_entry_t *cur, icmp_state_t nwk_bootstrap_state)
242388
{
243-
ws_bootsrap_event_trig(WS_OPERATION_START, cur->bootStrapId, ARM_LIB_HIGH_PRIORITY_EVENT);
389+
cur->bootsrap_state_machine_cnt = 1;
390+
cur->nwk_bootstrap_state = nwk_bootstrap_state;
244391
}
392+
void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur)
393+
{
394+
395+
switch (cur->nwk_bootstrap_state) {
396+
case ER_ACTIVE_SCAN:
397+
tr_debug("WS SM:Active Scan");
398+
ws_bootstrap_event_configuration_start(cur);
399+
break;
400+
401+
case ER_BOOTSRAP_DONE:
402+
tr_debug("WS SM:Bootstrap Done");
403+
// Bootstrap_done event to application
404+
nwk_bootsrap_state_update(ARM_NWK_BOOTSTRAP_READY, cur);
405+
break;
245406

407+
default:
408+
tr_warn("WS SM:Invalid state %d",cur->nwk_bootstrap_state);
409+
410+
}
411+
}
246412
#endif //HAVE_WS

source/6LoWPAN/ws/ws_bootstrap.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,31 @@ typedef enum {
2424
WS_DISCOVERY_START, /**< discovery start*/
2525
WS_CONFIGURATION_START, /**< configuration learn start*/
2626
WS_AUTHENTICATION_START, /**< authentication start*/
27-
WS_OPERATION_START /**< active operation start*/
27+
WS_OPERATION_START, /**< active operation start*/
28+
WS_ROUTING_READY /**< RPL routing connected to BR*/
2829
} ws_bootsrap_event_type_e;
2930

3031
#ifdef HAVE_WS
3132

3233
int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode);
3334

35+
void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur);
3436

3537
/*State machine transactions*/
36-
void ws_bootstrap_discovery_start(protocol_interface_info_entry_t *cur);
38+
void ws_bootstrap_event_discovery_start(protocol_interface_info_entry_t *cur);
3739

38-
void ws_bootstrap_configuration_start(protocol_interface_info_entry_t *cur);
40+
void ws_bootstrap_event_configuration_start(protocol_interface_info_entry_t *cur);
3941

40-
void ws_bootstrap_authentication_start(protocol_interface_info_entry_t *cur);
42+
void ws_bootstrap_event_authentication_start(protocol_interface_info_entry_t *cur);
4143

42-
void ws_bootstrap_operation_start(protocol_interface_info_entry_t *cur);
44+
void ws_bootstrap_event_operation_start(protocol_interface_info_entry_t *cur);
45+
46+
void ws_bootstrap_event_routing_ready(protocol_interface_info_entry_t *cur);
4347

4448
#else
4549

4650
#define ws_bootstrap_init(interface_id, bootstrap_mode) (-1)
51+
#define ws_bootstrap_state_machine(cur)
4752

4853
#endif //HAVE_WS
4954

source/NWK_INTERFACE/protocol_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
#include "6LoWPAN/Thread/thread_bootstrap.h"
6565
#include "6LoWPAN/Thread/thread_routing.h"
6666
#include "6LoWPAN/Thread/thread_management_internal.h"
67+
#include "6LoWPAN/ws/ws_bootstrap.h"
68+
#include "6LoWPAN/ws/ws_common.h"
6769
#include "ipv6_stack/protocol_ipv6.h"
6870
#include "Service_Libs/whiteboard/whiteboard.h"
6971

@@ -1059,6 +1061,8 @@ void net_bootsrap_cb_run(uint8_t event)
10591061
//eventOS_scheduler_set_active_tasklet(protocol_read_tasklet_id());
10601062
if (thread_info(cur)) {
10611063
thread_bootstrap_state_machine(cur);
1064+
} else if (ws_info(cur)) {
1065+
ws_bootstrap_state_machine(cur);
10621066
} else {
10631067
protocol_6lowpan_bootstrap(cur);
10641068
}

0 commit comments

Comments
 (0)