35
35
#include "6LoWPAN/MAC/mpx_api.h"
36
36
#include "6LoWPAN/MAC/mac_ie_lib.h"
37
37
#include "6LoWPAN/ws/ws_common_defines.h"
38
+ #include "6LoWPAN/ws/ws_config.h"
38
39
#include "6LoWPAN/ws/ws_common.h"
39
40
#include "6LoWPAN/ws/ws_bootstrap.h"
40
41
#include "RPL/rpl_protocol.h"
@@ -80,22 +81,50 @@ static bool ws_bootstrap_state_active(struct protocol_interface_info_entry *cur)
80
81
static bool ws_bootstrap_state_discovery (struct protocol_interface_info_entry * cur );
81
82
static bool ws_bootstrap_state_wait_rpl (struct protocol_interface_info_entry * cur );
82
83
static int8_t ws_bootsrap_event_trig (ws_bootsrap_event_type_e event_type , int8_t interface_id , arm_library_event_priority_e priority , void * event_data );
83
- static mac_neighbor_table_entry_t * ws_bootstrap_add_neighbor (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
84
+
85
+ static mac_neighbor_table_entry_t * ws_bootstrap_mac_neighbor_add (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
84
86
{
85
87
mac_neighbor_table_entry_t * neighbor = mac_neighbor_table_address_discover (interface -> mac_parameters -> mac_neighbor_table , src64 , MAC_ADDR_MODE_64_BIT );
86
88
if (!neighbor ) {
87
89
neighbor = mac_neighbor_table_entry_allocate (interface -> mac_parameters -> mac_neighbor_table , src64 );
88
- if (neighbor ) {
89
- mlme_device_descriptor_t device_desc ;
90
- tr_debug ("Added new neighbor %s : index:%u" , trace_array (src64 , 8 ), neighbor -> index );
91
- mac_helper_device_description_write (interface , & device_desc , neighbor -> mac64 , neighbor -> mac16 ,0 , false);
92
- mac_helper_devicetable_set (& device_desc , interface ,neighbor -> index , interface -> mac_parameters -> mac_default_key_index , true);
93
- }
94
90
}
91
+ if (!neighbor ) {
92
+ return NULL ;
93
+ }
94
+ mlme_device_descriptor_t device_desc ;
95
+ tr_debug ("Added new neighbor %s : index:%u" , trace_array (src64 , 8 ), neighbor -> index );
96
+ mac_helper_device_description_write (interface , & device_desc , neighbor -> mac64 , neighbor -> mac16 ,0 , false);
97
+ mac_helper_devicetable_set (& device_desc , interface ,neighbor -> index , interface -> mac_parameters -> mac_default_key_index , true);
95
98
return neighbor ;
96
99
}
97
100
101
+ static ws_neighbor_class_entry_t * ws_bootstrap_neighbor_add (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
102
+ {
103
+ mac_neighbor_table_entry_t * neighbor = ws_bootstrap_mac_neighbor_add (interface , src64 );
104
+ if (!neighbor ) {
105
+ return NULL ;
106
+ }
98
107
108
+ ws_neighbor_class_entry_t * ws_neighbor = ws_neighbor_class_entry_get (& interface -> ws_info -> neighbor_storage , neighbor -> index );
109
+ if (!ws_neighbor ) {
110
+ mac_neighbor_table_neighbor_remove (interface -> mac_parameters -> mac_neighbor_table , neighbor );
111
+ return NULL ;
112
+ }
113
+ return ws_neighbor ;
114
+ }
115
+
116
+ static void ws_bootstrap_neighbor_delete (struct protocol_interface_info_entry * interface , uint8_t attribute_index )
117
+ {
118
+ mac_helper_devicetable_remove (interface -> mac_api , attribute_index );
119
+ etx_neighbor_remove (interface -> id , attribute_index );
120
+ ws_neighbor_class_entry_remove (& interface -> ws_info -> neighbor_storage , attribute_index );
121
+ }
122
+
123
+ static void ws_bootstrap_neighbor_list_clean (struct protocol_interface_info_entry * interface )
124
+ {
125
+
126
+ mac_neighbor_table_neighbor_list_clean (interface -> mac_parameters -> mac_neighbor_table );
127
+ }
99
128
100
129
static void ws_bootstrap_address_notification_cb (struct protocol_interface_info_entry * interface , const struct if_address_entry * addr , if_address_callback_t reason )
101
130
{
@@ -334,19 +363,14 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
334
363
}
335
364
//TODO smarter Neighbor allocate system
336
365
337
- mac_neighbor_table_entry_t * neighbor = ws_bootstrap_add_neighbor (cur , data -> SrcAddr );
366
+ ws_neighbor_class_entry_t * neighbor = ws_bootstrap_neighbor_add (cur , data -> SrcAddr );
338
367
if (!neighbor ) {
339
368
return ;
340
369
}
341
370
342
- ws_neighbor_class_entry_t * ws_neighbor = ws_neighbor_class_entry_get (& cur -> ws_info -> neighbor_storage , neighbor -> index );
343
- if (!ws_neighbor ) {
344
- return ;
345
- }
346
-
347
- etx_lqi_dbm_update (cur -> id , data -> mpduLinkQuality , data -> signal_dbm , neighbor -> index );
348
- ws_neighbor_class_neighbor_unicast_time_info_update (ws_neighbor , ws_utt , data -> timestamp );
349
- ws_neighbor_class_neighbor_unicast_schedule_set (ws_neighbor , ws_us );
371
+ etx_lqi_dbm_update (cur -> id , data -> mpduLinkQuality , data -> signal_dbm , ws_neighbor_class_entry_index_get (& cur -> ws_info -> neighbor_storage ,neighbor ));
372
+ ws_neighbor_class_neighbor_unicast_time_info_update (neighbor , ws_utt , data -> timestamp );
373
+ ws_neighbor_class_neighbor_unicast_schedule_set (neighbor , ws_us );
350
374
351
375
// Save the best network parent
352
376
@@ -388,16 +412,13 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
388
412
static void ws_bootstrap_pan_advertisement_solicit_analyse (struct protocol_interface_info_entry * cur , const struct mcps_data_ind_s * data , ws_utt_ie_t * ws_utt , ws_us_ie_t * ws_us )
389
413
{
390
414
391
- mac_neighbor_table_entry_t * neighbor = ws_bootstrap_add_neighbor (cur , data -> SrcAddr );
415
+ ws_neighbor_class_entry_t * neighbor = ws_bootstrap_neighbor_add (cur , data -> SrcAddr );
392
416
if (!neighbor ) {
393
417
return ;
394
418
}
395
- ws_neighbor_class_entry_t * ws_neighbor = ws_neighbor_class_entry_get (& cur -> ws_info -> neighbor_storage , neighbor -> index );
396
- if (!ws_neighbor ) {
397
- return ;
398
- }
399
- ws_neighbor_class_neighbor_unicast_time_info_update (ws_neighbor , ws_utt , data -> timestamp );
400
- ws_neighbor_class_neighbor_unicast_schedule_set (ws_neighbor , ws_us );
419
+
420
+ ws_neighbor_class_neighbor_unicast_time_info_update (neighbor , ws_utt , data -> timestamp );
421
+ ws_neighbor_class_neighbor_unicast_schedule_set (neighbor , ws_us );
401
422
402
423
/*
403
424
* An inconsistent transmission is defined as:
@@ -463,20 +484,17 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
463
484
return ;
464
485
}
465
486
466
- mac_neighbor_table_entry_t * neighbor = ws_bootstrap_add_neighbor (cur , data -> SrcAddr );
487
+ ws_neighbor_class_entry_t * neighbor = ws_bootstrap_neighbor_add (cur , data -> SrcAddr );
467
488
if (!neighbor ) {
468
489
return ;
469
490
}
470
- ws_neighbor_class_entry_t * ws_neighbor = ws_neighbor_class_entry_get (& cur -> ws_info -> neighbor_storage , neighbor -> index );
471
- if (!ws_neighbor ) {
472
- return ;
473
- }
474
- etx_lqi_dbm_update (cur -> id , data -> mpduLinkQuality , data -> signal_dbm , neighbor -> index );
491
+
492
+ etx_lqi_dbm_update (cur -> id , data -> mpduLinkQuality , data -> signal_dbm , ws_neighbor_class_entry_index_get (& cur -> ws_info -> neighbor_storage ,neighbor ));
475
493
//Update Neighbor Broadcast and Unicast Parameters
476
- ws_neighbor_class_neighbor_unicast_time_info_update (ws_neighbor , ws_utt , data -> timestamp );
477
- ws_neighbor_class_neighbor_unicast_schedule_set (ws_neighbor , ws_us );
478
- ws_neighbor_class_neighbor_broadcast_time_info_update (ws_neighbor , & ws_bt_ie , data -> timestamp );
479
- ws_neighbor_class_neighbor_broadcast_schedule_set (ws_neighbor , & ws_bs_ie );
494
+ ws_neighbor_class_neighbor_unicast_time_info_update (neighbor , ws_utt , data -> timestamp );
495
+ ws_neighbor_class_neighbor_unicast_schedule_set (neighbor , ws_us );
496
+ ws_neighbor_class_neighbor_broadcast_time_info_update (neighbor , & ws_bt_ie , data -> timestamp );
497
+ ws_neighbor_class_neighbor_broadcast_schedule_set (neighbor , & ws_bs_ie );
480
498
481
499
482
500
if (cur -> ws_info -> configuration_learned &&
@@ -504,6 +522,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
504
522
*/
505
523
tr_info ("Updated PAN configuration heard" );
506
524
525
+ cur -> ws_info -> pan_version_timeout_timer = PAN_VERSION_TIMEOUT ;
507
526
cur -> ws_info -> pan_configuration .pan_version = pan_version ;
508
527
memcpy (cur -> ws_info -> gtkhash ,gtkhash_ptr ,32 );
509
528
@@ -531,17 +550,13 @@ static void ws_bootstrap_pan_config_solicit_analyse(struct protocol_interface_in
531
550
return ;
532
551
}
533
552
534
- mac_neighbor_table_entry_t * neighbor = ws_bootstrap_add_neighbor (cur , data -> SrcAddr );
553
+ ws_neighbor_class_entry_t * neighbor = ws_bootstrap_neighbor_add (cur , data -> SrcAddr );
535
554
if (!neighbor ) {
536
555
return ;
537
556
}
538
- ws_neighbor_class_entry_t * ws_neighbor = ws_neighbor_class_entry_get (& cur -> ws_info -> neighbor_storage , neighbor -> index );
539
- if (!ws_neighbor ) {
540
- return ;
541
- }
542
557
543
- ws_neighbor_class_neighbor_unicast_time_info_update (ws_neighbor , ws_utt , data -> timestamp );
544
- ws_neighbor_class_neighbor_unicast_schedule_set (ws_neighbor , ws_us );
558
+ ws_neighbor_class_neighbor_unicast_time_info_update (neighbor , ws_utt , data -> timestamp );
559
+ ws_neighbor_class_neighbor_unicast_schedule_set (neighbor , ws_us );
545
560
546
561
/*
547
562
* A consistent transmission is defined as a PAN Configuration Solicit with
@@ -643,6 +658,7 @@ static void ws_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_pt
643
658
644
659
protocol_interface_info_entry_t * cur = user_data ;
645
660
661
+ topo_trace (TOPOLOGY_MLE , entry_ptr -> ext64 , TOPO_REMOVE );
646
662
// Sleepy host
647
663
if (cur -> lowpan_info & INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE ) {
648
664
mac_data_poll_protocol_poll_mode_decrement (cur );
@@ -654,14 +670,7 @@ static void ws_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_pt
654
670
protocol_6lowpan_release_short_link_address_from_neighcache (cur , entry_ptr -> mac16 );
655
671
protocol_6lowpan_release_long_link_address_from_neighcache (cur , entry_ptr -> mac64 );
656
672
}
657
- mac_helper_devicetable_remove (cur -> mac_api , entry_ptr -> index );
658
-
659
- //Remove WS neighbor data
660
- ws_neighbor_class_entry_remove (& cur -> ws_info -> neighbor_storage , entry_ptr -> index );
661
- topo_trace (TOPOLOGY_MLE , entry_ptr -> ext64 , TOPO_REMOVE );
662
-
663
- //SET ETX to infinity
664
- etx_neighbor_remove (cur -> id , entry_ptr -> index );
673
+ ws_bootstrap_neighbor_delete (cur ,entry_ptr -> index );
665
674
}
666
675
667
676
@@ -850,6 +859,8 @@ static void ws_bootstrap_ip_stack_activate(protocol_interface_info_entry_t *cur)
850
859
tr_debug ("ip stack init" );
851
860
clear_power_state (ICMP_ACTIVE );
852
861
cur -> lowpan_info |= INTERFACE_NWK_BOOTSRAP_ACTIVE ;
862
+ ipv6_neighbour_cache_flush (& cur -> ipv6_neighbour_cache );
863
+
853
864
}
854
865
static void ws_bootstrap_rpl_callback (rpl_event_t event , void * handle )
855
866
{
@@ -865,7 +876,11 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
865
876
} else if (event == RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS ) {
866
877
// RPL gave up so we need to re-trigger network scan.
867
878
// TODO is this correct?
879
+ // TODO no! ws_bootstrap_event_configuration_start(cur); causes failure to
880
+ // We could send solicit for configuration and then select new parent when those arrive
881
+ /* This is done after address deletion, so RPL can act on them */
868
882
ws_bootstrap_event_configuration_start (cur );
883
+
869
884
}
870
885
cur -> ws_info -> rpl_state = event ;
871
886
tr_info ("RPL event %d" , event );
@@ -917,12 +932,40 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
917
932
tr_debug ("router discovery start" );
918
933
ws_bootstrap_state_change (cur , ER_ACTIVE_SCAN );
919
934
cur -> nwk_nd_re_scan_count = 0 ;
935
+ cur -> ws_info -> configuration_learned = false;
936
+ cur -> ws_info -> pan_version_timeout_timer = 0 ;
937
+ // Clear parent info
938
+ memset (cur -> ws_info -> parent_info .addr ,0 ,8 );
939
+
940
+ // Clear learned neighbours
941
+ ws_bootstrap_neighbor_list_clean (cur );
942
+
920
943
// Reset advertisement solicit trickle to start discovering network
921
944
trickle_start (& cur -> ws_info -> trickle_pan_advertisement_solicit , & trickle_params_pan_configuration );
922
945
trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_advertisement_solicit , & trickle_params_pan_configuration );
946
+
947
+ }
948
+ // Start configuration learning
949
+ static void ws_bootstrap_start_configuration_learn (protocol_interface_info_entry_t * cur )
950
+ {
951
+ tr_debug ("router configuration learn start" );
952
+ ws_bootstrap_state_change (cur , ER_SCAN );
953
+
954
+ cur -> ws_info -> configuration_learned = false;
955
+ cur -> ws_info -> pan_version_timeout_timer = 0 ;
956
+ rpl_control_remove_domain_from_interface (cur );
957
+ ipv6_neighbour_cache_flush (& cur -> ipv6_neighbour_cache );
923
958
// Clear parent info
924
959
memset (cur -> ws_info -> parent_info .addr ,0 ,8 );
925
960
961
+ // Clear learned neighbours
962
+ ws_bootstrap_neighbor_list_clean (cur );
963
+
964
+ // Reset advertisement solicit trickle to start discovering network
965
+ trickle_start (& cur -> ws_info -> trickle_pan_config_solicit , & trickle_params_pan_configuration );
966
+ trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_config_solicit , & trickle_params_pan_configuration );
967
+
968
+
926
969
}
927
970
928
971
/*
@@ -1070,6 +1113,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
1070
1113
cur -> ws_info -> pan_configuration .version = WS_FAN_VERSION_1_0 ;
1071
1114
cur -> ws_info -> hopping_schdule .channel_function = WS_FIXED_CHANNEL ;
1072
1115
ws_llc_set_gtkhash (cur , cur -> ws_info -> gtkhash );
1116
+ cur -> ws_info -> pan_version_timer = PAN_VERSION_LIFETIME ;
1073
1117
ws_bootstrap_fhss_activate (cur );
1074
1118
ws_bootstrap_event_operation_start (cur );
1075
1119
break ;
@@ -1087,13 +1131,12 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
1087
1131
break ;
1088
1132
case WS_CONFIGURATION_START :
1089
1133
tr_info ("Configuration start" );
1090
- // TODO temporary learn from parent
1091
- // Start solicit tricklle
1092
- // TODO process state after first Config go to operation
1093
- trickle_start (& cur -> ws_info -> trickle_pan_config_solicit , & trickle_params_pan_configuration );
1094
- trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_config_solicit , & trickle_params_pan_configuration );
1095
- ws_bootstrap_state_change (cur , ER_SCAN );
1096
- cur -> ws_info -> configuration_learned = false;
1134
+ trickle_stop (& cur -> ws_info -> trickle_pan_advertisement );
1135
+ trickle_stop (& cur -> ws_info -> trickle_pan_config );
1136
+
1137
+ // Build list of possible neighbours and learn first broadcast schedule
1138
+
1139
+ ws_bootstrap_start_configuration_learn (cur );
1097
1140
break ;
1098
1141
case WS_OPERATION_START :
1099
1142
tr_info ("operation start" );
@@ -1253,7 +1296,29 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
1253
1296
tr_info ("Send PAN configuration" );
1254
1297
ws_bootstrap_pan_config (cur );
1255
1298
}
1299
+ if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
1300
+ // update version number
1301
+ if (cur -> ws_info -> pan_version_timer > seconds ) {
1302
+ cur -> ws_info -> pan_version_timer -= seconds ;
1303
+ } else {
1304
+ // Border router has timed out
1305
+ tr_debug ("Border router version number update" );
1306
+ cur -> ws_info -> pan_version_timer = PAN_VERSION_LIFETIME ;
1307
+ cur -> ws_info -> pan_configuration .pan_version ++ ;
1308
+ // Inconsistent for border router to make information distribute faster
1309
+ trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_config ,& trickle_params_pan_configuration );
1310
+ }
1311
+ }
1312
+ if (cur -> ws_info -> pan_version_timeout_timer ){
1313
+ // PAN version timer running
1314
+ if (cur -> ws_info -> pan_version_timeout_timer > seconds ) {
1315
+ cur -> ws_info -> pan_version_timeout_timer -= seconds ;
1316
+ } else {
1317
+ // Border router has timed out
1318
+ tr_warn ("Border router has timed out" );
1319
+ ws_bootstrap_event_discovery_start (cur );
1320
+ }
1321
+ }
1256
1322
}
1257
1323
1258
-
1259
1324
#endif //HAVE_WS
0 commit comments