Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 1af46d8

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
WS bootstrap update
Added neighbor add to PAN advert & PAN advert solicit message. Added validation IE elements before add neighbor. Update MAC neighbor table. Change-Id: I1ca100e4c249e0b0f8b67cf6de1541a4c204eedf
1 parent c771df0 commit 1af46d8

File tree

1 file changed

+93
-14
lines changed

1 file changed

+93
-14
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 93 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "eventOS_event.h"
2525
#include "randLIB.h"
2626
#include "common_functions.h"
27+
#include "mac_common_defines.h"
2728
#include "NWK_INTERFACE/Include/protocol.h"
2829
#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
2930
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
@@ -73,6 +74,23 @@ static void ws_bootstrap_state_change(protocol_interface_info_entry_t *cur, icmp
7374
static bool ws_bootstrap_state_active(struct protocol_interface_info_entry *cur);
7475
static bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *cur);
7576

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+
7694
static void ws_bootstrap_address_registration_ns_send(struct protocol_interface_info_entry *interface, const struct if_address_entry *addr)
7795
{
7896
aro_t aro;
@@ -331,23 +349,17 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
331349
return;
332350
}
333351

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 };
344352
uint_fast24_t ufsi;
345353

346354
if (!ws_bootstrap_ufsi_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ufsi)) {
347355
// Corrupted
348356
tr_error("No ufsi");
349357
return;
350358
}
359+
360+
ws_pan_information_t pan_information;
361+
ws_hoopping_schedule_t hopping_schedule = { 0 };
362+
351363
if (!ws_bootstrap_pan_information_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &pan_information)) {
352364
// Corrupted
353365
tr_error("No pan information");
@@ -367,6 +379,31 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
367379
return;
368380
}
369381

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+
370407
// Parent valid store information
371408
cur->ws_info->parent_info.ufsi = ufsi;
372409
// Saved from unicast IE
@@ -387,8 +424,10 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
387424

388425
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)
389426
{
427+
if (data->SrcAddrMode != MAC_ADDR_MODE_64_BIT) {
428+
return;
429+
}
390430

391-
(void)data;
392431
if(!ws_bootstrap_state_active(cur)) {
393432
// We are not active yet
394433
return;
@@ -398,6 +437,37 @@ static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_inter
398437
tr_debug("Network name not matching");
399438
return;
400439
}
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+
401471
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_advertisement);
402472
}
403473

@@ -477,9 +547,18 @@ static void ws_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_pt
477547

478548
static bool ws_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data)
479549
{
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);
483562
return true;
484563
}
485564

0 commit comments

Comments
 (0)