24
24
#include "eventOS_event.h"
25
25
#include "randLIB.h"
26
26
#include "common_functions.h"
27
+ #include "mac_common_defines.h"
27
28
#include "NWK_INTERFACE/Include/protocol.h"
28
29
#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
29
30
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
@@ -73,6 +74,23 @@ static void ws_bootstrap_state_change(protocol_interface_info_entry_t *cur, icmp
73
74
static bool ws_bootstrap_state_active (struct protocol_interface_info_entry * cur );
74
75
static bool ws_bootstrap_state_discovery (struct protocol_interface_info_entry * cur );
75
76
77
+ mac_neighbor_table_entry_t * ws_bootstrap_add_neighbor (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
78
+ {
79
+ mac_neighbor_table_entry_t * neighbor = mac_neighbor_table_address_discover (interface -> mac_parameters -> mac_neighbor_table , src64 , MAC_ADDR_MODE_64_BIT );
80
+ if (!neighbor ) {
81
+ neighbor = mac_neighbor_table_entry_allocate (interface -> mac_parameters -> mac_neighbor_table , src64 );
82
+ if (neighbor ) {
83
+ mlme_device_descriptor_t device_desc ;
84
+ tr_debug ("Added new neighbor %s : index:%u" , trace_array (src64 , 8 ), neighbor -> index );
85
+ mac_helper_device_description_write (interface , & device_desc , neighbor -> mac64 , neighbor -> mac16 ,0 , false);
86
+ mac_helper_devicetable_set (& device_desc , interface ,neighbor -> index , interface -> mac_parameters -> mac_default_key_index );
87
+ }
88
+ }
89
+
90
+ return neighbor ;
91
+ }
92
+
93
+
76
94
static void ws_bootstrap_address_registration_ns_send (struct protocol_interface_info_entry * interface , const struct if_address_entry * addr )
77
95
{
78
96
aro_t aro ;
@@ -331,23 +349,17 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
331
349
return ;
332
350
}
333
351
334
- // This parent is selected and used for authentication.
335
- if (memcmp (cur -> ws_info -> parent_info .addr , ADDR_UNSPECIFIED ,8 ) != 0 ) {
336
- //Decide which is better parent for authentication
337
- if (cur -> ws_info -> parent_info .link_quality > data -> mpduLinkQuality ) {
338
- return ;
339
- }
340
- }
341
-
342
- ws_pan_information_t pan_information ;
343
- ws_hoopping_schedule_t hopping_schedule = { 0 };
344
352
uint_fast24_t ufsi ;
345
353
346
354
if (!ws_bootstrap_ufsi_read (ie_ext -> headerIeList , ie_ext -> headerIeListLength , & ufsi )) {
347
355
// Corrupted
348
356
tr_error ("No ufsi" );
349
357
return ;
350
358
}
359
+
360
+ ws_pan_information_t pan_information ;
361
+ ws_hoopping_schedule_t hopping_schedule = { 0 };
362
+
351
363
if (!ws_bootstrap_pan_information_read (ie_ext -> payloadIeList , ie_ext -> payloadIeListLength , & pan_information )) {
352
364
// Corrupted
353
365
tr_error ("No pan information" );
@@ -367,6 +379,31 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
367
379
return ;
368
380
}
369
381
382
+ mac_neighbor_table_entry_t * neighbor = ws_bootstrap_add_neighbor (cur , data -> SrcAddr );
383
+ if (!neighbor ) {
384
+ return ;
385
+ }
386
+ ws_neighbour_class_entry_t * ws_neighbor = ws_neighbour_class_entry_get (& cur -> ws_info -> neighbor_storage , neighbor -> index );
387
+ if (!ws_neighbor ) {
388
+ return ;
389
+ }
390
+
391
+ ws_neighbor -> fhhs_data .utt_timestamp = data -> timestamp ;
392
+ ws_neighbor -> fhhs_data .ufsi = ufsi ;
393
+ ws_neighbor -> fhhs_data .channel_function = hopping_schedule .channel_function ;
394
+ ws_neighbor -> fhhs_data .unicast_dwell = hopping_schedule .fhss_uc_dwell_interval ;
395
+
396
+
397
+
398
+ // This parent is selected and used for authentication.
399
+ if (memcmp (cur -> ws_info -> parent_info .addr , ADDR_UNSPECIFIED ,8 ) != 0 ) {
400
+ //Decide which is better parent for authentication
401
+ if (cur -> ws_info -> parent_info .link_quality > data -> mpduLinkQuality ) {
402
+ return ;
403
+ }
404
+ }
405
+
406
+
370
407
// Parent valid store information
371
408
cur -> ws_info -> parent_info .ufsi = ufsi ;
372
409
// Saved from unicast IE
@@ -387,8 +424,10 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
387
424
388
425
static void ws_bootstrap_pan_advertisement_solicit_analyse (struct protocol_interface_info_entry * cur , const struct mcps_data_ind_s * data , const struct mcps_data_ie_list * ie_ext )
389
426
{
427
+ if (data -> SrcAddrMode != MAC_ADDR_MODE_64_BIT ) {
428
+ return ;
429
+ }
390
430
391
- (void )data ;
392
431
if (!ws_bootstrap_state_active (cur )) {
393
432
// We are not active yet
394
433
return ;
@@ -398,6 +437,37 @@ static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_inter
398
437
tr_debug ("Network name not matching" );
399
438
return ;
400
439
}
440
+
441
+ uint_fast24_t ufsi ;
442
+ ws_hoopping_schedule_t hopping_schedule = { 0 };
443
+
444
+ if (!ws_bootstrap_ufsi_read (ie_ext -> headerIeList , ie_ext -> headerIeListLength , & ufsi )) {
445
+ // Corrupted
446
+ tr_error ("No ufsi" );
447
+ return ;
448
+ }
449
+
450
+ // TODO create own function to read just dwell time
451
+ if (!ws_bootstrap_unicast_schedule_read (ie_ext -> payloadIeList , ie_ext -> payloadIeListLength , & hopping_schedule )) {
452
+ // Corrupted
453
+ tr_error ("No unicast schedule" );
454
+ return ;
455
+ }
456
+
457
+ mac_neighbor_table_entry_t * neighbor = ws_bootstrap_add_neighbor (cur , data -> SrcAddr );
458
+ if (!neighbor ) {
459
+ return ;
460
+ }
461
+ ws_neighbour_class_entry_t * ws_neighbor = ws_neighbour_class_entry_get (& cur -> ws_info -> neighbor_storage , neighbor -> index );
462
+ if (!ws_neighbor ) {
463
+ return ;
464
+ }
465
+
466
+ ws_neighbor -> fhhs_data .utt_timestamp = data -> timestamp ;
467
+ ws_neighbor -> fhhs_data .ufsi = ufsi ;
468
+ ws_neighbor -> fhhs_data .channel_function = hopping_schedule .channel_function ;
469
+ ws_neighbor -> fhhs_data .unicast_dwell = hopping_schedule .fhss_uc_dwell_interval ;
470
+
401
471
trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_advertisement ,& trickle_params_pan_advertisement );
402
472
}
403
473
@@ -477,9 +547,18 @@ static void ws_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_pt
477
547
478
548
static bool ws_neighbor_entry_nud_notify (mac_neighbor_table_entry_t * entry_ptr , void * user_data )
479
549
{
480
- //TODO generate NS NUD
481
- (void ) entry_ptr ;
482
- (void ) user_data ;
550
+ protocol_interface_info_entry_t * cur = user_data ;
551
+
552
+ uint8_t ll_target [16 ];
553
+ memcpy (ll_target , ADDR_LINK_LOCAL_PREFIX , 8 );
554
+ memcpy (ll_target + 8 , entry_ptr -> mac64 , 8 );
555
+ ll_target [8 ] ^= 2 ;
556
+ tr_debug ("NUD generate NS" );
557
+ buffer_t * buffer = icmpv6_build_ns (cur , ll_target , NULL , true, false, NULL );
558
+ if (!buffer ) {
559
+ return false;
560
+ }
561
+ protocol_push (buffer );
483
562
return true;
484
563
}
485
564
0 commit comments