Skip to content

Commit c94b306

Browse files
author
Juha Heiskanen
committed
LFN version and LGTK Hash IE advertisment and learn
1 parent 8e07511 commit c94b306

File tree

6 files changed

+163
-13
lines changed

6 files changed

+163
-13
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,65 @@ static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_inter
17081708
}
17091709
}
17101710
}
1711+
#ifdef HAVE_WS_VERSION_1_1
1712+
static void ws_bootstrap_pan_config_lfn_analyze(struct protocol_interface_info_entry *cur, const struct mcps_data_ie_list *ie_ext)
1713+
{
1714+
if (!ws_version_1_1(cur) || cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
1715+
return;
1716+
}
1717+
1718+
ws_lfnver_ie_t lfn_version;
1719+
if (!ws_wp_nested_lfn_version_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &lfn_version)) {
1720+
return; // LFN version
1721+
}
1722+
1723+
//Read LFNGTKHASH
1724+
ws_lgtkhash_ie_t ws_lgtkhash;
1725+
if (!ws_wp_nested_lgtk_hash_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &ws_lgtkhash)) {
1726+
return;
1727+
}
1728+
1729+
if (!cur->ws_info->lfngtk.lfn_version_learned) {
1730+
if (!cur->ws_info->configuration_learned) {
1731+
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config, &cur->ws_info->trickle_params_pan_discovery);
1732+
}
1733+
} else {
1734+
if (cur->ws_info->lfngtk.lfn_version == lfn_version.lfn_version) {
1735+
return;
1736+
}
1737+
1738+
if (common_serial_number_greater_16(cur->ws_info->lfngtk.lfn_version, lfn_version.lfn_version)) {
1739+
// older version heard ignoring the message
1740+
return;
1741+
}
1742+
}
1743+
1744+
cur->ws_info->lfngtk.lfn_version = lfn_version.lfn_version;
1745+
1746+
//Clear HASH allways at new first or for first leaned one's
1747+
memset(cur->ws_info->lfngtk.lgtkhash, 0, 24);
1748+
cur->ws_info->lfngtk.lfn_version_learned = true;
1749+
1750+
//Set Active key index and hash inline bits
1751+
cur->ws_info->lfngtk.active_key_index = ws_lgtkhash.active_lgtk_index;
1752+
cur->ws_info->lfngtk.active_hash_1 = ws_lgtkhash.lgtk0;
1753+
cur->ws_info->lfngtk.active_hash_2 = ws_lgtkhash.lgtk1;
1754+
cur->ws_info->lfngtk.active_hash_3 = ws_lgtkhash.lgtk2;
1755+
1756+
if (cur->ws_info->lfngtk.active_hash_1) {
1757+
memcpy(cur->ws_info->lfngtk.lgtkhash, ws_lgtkhash.lgtk0_hash, 8);
1758+
}
1759+
1760+
if (cur->ws_info->lfngtk.active_hash_2) {
1761+
memcpy(cur->ws_info->lfngtk.lgtkhash + 8, ws_lgtkhash.lgtk1_hash, 8);
1762+
}
1763+
1764+
if (cur->ws_info->lfngtk.active_hash_3) {
1765+
memcpy(cur->ws_info->lfngtk.lgtkhash + 16, ws_lgtkhash.lgtk2_hash, 8);
1766+
}
1767+
//TODO Analyze HASH's and set LFN group key index
1768+
}
1769+
#endif
17111770

17121771

17131772
static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext, ws_utt_ie_t *ws_utt, ws_us_ie_t *ws_us)
@@ -1821,6 +1880,9 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
18211880
ws_bootstrap_primary_parent_set(cur, &neighbor_info, WS_PARENT_SOFT_SYNCH);
18221881
}
18231882
// no need to process more
1883+
#ifdef HAVE_WS_VERSION_1_1
1884+
ws_bootstrap_pan_config_lfn_analyze(cur, ie_ext);
1885+
#endif
18241886
return;
18251887
} else {
18261888
// received version is different so we need to reset the trickle
@@ -1858,6 +1920,10 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
18581920

18591921
ws_pae_controller_nw_key_index_update(cur, data->Key.KeyIndex - 1);
18601922

1923+
#ifdef HAVE_WS_VERSION_1_1
1924+
ws_bootstrap_pan_config_lfn_analyze(cur, ie_ext);
1925+
#endif
1926+
18611927
if (!cur->ws_info->configuration_learned) {
18621928
// Generate own hopping schedules Follow first parent broadcast and plans and also use same unicast dwell
18631929
tr_info("learn network configuration");
@@ -3679,6 +3745,11 @@ static void ws_bootstrap_pan_config(protocol_interface_info_entry_t *cur)
36793745
async_req.wp_requested_nested_ie_list.pan_version_ie = true;
36803746
async_req.wp_requested_nested_ie_list.gtkhash_ie = true;
36813747
async_req.wp_requested_nested_ie_list.vp_ie = true;
3748+
#ifdef HAVE_WS_VERSION_1_1
3749+
if (ws_version_1_1(cur)) {
3750+
async_req.wp_requested_nested_ie_list.lfn_gtk_version_ie = cur->ws_info->lfngtk.lfn_version_learned;
3751+
}
3752+
#endif
36823753

36833754
ws_set_asynch_channel_list(cur, &async_req);
36843755

@@ -3775,6 +3846,13 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
37753846
// initialize for FAN 1.1 defaults
37763847
if (ws_version_1_1(cur)) {
37773848
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_1;
3849+
#ifdef HAVE_WS_VERSION_1_1
3850+
if (!cur->ws_info->lfngtk.lfn_version_learned) {
3851+
//Randomize LFN version
3852+
cur->ws_info->lfngtk.lfn_version = randLIB_get_random_in_range(0, 0xffff);
3853+
cur->ws_info->lfngtk.lfn_version_learned = true;
3854+
}
3855+
#endif
37783856
}
37793857

37803858
uint8_t *gtkhash = ws_pae_controller_gtk_hash_ptr_get(cur);

source/6LoWPAN/ws/ws_common.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ typedef struct {
9292
bool auto_trg_enabled;
9393
} ws_test_proc_trg_t;
9494

95+
typedef struct {
96+
uint16_t lfn_version;
97+
bool lfn_version_learned: 1;
98+
bool active_hash_1: 1;
99+
bool active_hash_2: 1;
100+
bool active_hash_3: 1;
101+
unsigned active_key_index: 2;
102+
uint8_t lgtkhash[24];
103+
} ws_lfn_lgtk_t;
104+
105+
typedef struct {
106+
unsigned length_of_list: 3;
107+
ws_pcab_ie_t pcab[7];
108+
} ws_phy_cap_info_t;
109+
95110
typedef NS_LIST_HEAD(ws_nud_table_entry_t, link) ws_nud_table_list_t;
96111

97112
typedef struct ws_info_s {
@@ -129,6 +144,10 @@ typedef struct ws_info_s {
129144
ws_nud_table_list_t active_nud_process;
130145
ws_nud_table_list_t free_nud_entries;
131146
ws_test_proc_trg_t test_proc_trg;
147+
#ifdef HAVE_WS_VERSION_1_1
148+
ws_lfn_lgtk_t lfngtk;
149+
ws_phy_cap_info_t phy_cap_info;
150+
#endif
132151
struct ws_cfg_s *cfg; /**< Wi-SUN configuration */
133152
struct ws_pan_information_s pan_information;
134153
ws_hopping_schedule_t hopping_schdule;

source/6LoWPAN/ws/ws_common_defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#define WP_PAYLOAD_IE_NETNAME_TYPE 5 /**< Network Name information */
5858
#define WP_PAYLOAD_IE_PAN_VER_TYPE 6 /**< Pan configuration version */
5959
#define WP_PAYLOAD_IE_GTKHASH_TYPE 7 /**< GTK Hash information */
60-
/* Wi-SUN FAN dfinition 1.1 */
60+
/* Wi-SUN FAN definition 1.1 */
6161
#define WP_PAYLOAD_IE_PCAP_TYPE 8 /**< PHY Capability information */
6262
#define WP_PAYLOAD_IE_LFNVER_TYPE 9 /**< LFN Version information */
6363
#define WP_PAYLOAD_IE_LGTKHASH_TYPE 10 /**< LFN GTK Hash Information */

source/6LoWPAN/ws/ws_llc.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ typedef struct wh_ie_sub_list_s {
4949
* @brief wp_nested_ie_sub_list_t ws asynch Nested Payload sub IE element request list
5050
*/
5151
typedef struct wp_nested_ie_sub_list_s {
52-
bool us_ie: 1; /**< Unicast Schedule information */
53-
bool bs_ie: 1; /**< Broadcast Schedule information */
54-
bool vp_ie: 1; /**< Vendor Payload information */
55-
bool pan_ie: 1; /**< PAN Information */
56-
bool net_name_ie: 1; /**< Network Name information */
57-
bool pan_version_ie: 1; /**< Pan configuration version */
58-
bool gtkhash_ie: 1; /**< GTK Hash information */
52+
bool us_ie: 1; /**< Unicast Schedule information */
53+
bool bs_ie: 1; /**< Broadcast Schedule information */
54+
bool vp_ie: 1; /**< Vendor Payload information */
55+
bool pan_ie: 1; /**< PAN Information */
56+
bool net_name_ie: 1; /**< Network Name information */
57+
bool pan_version_ie: 1; /**< Pan configuration version */
58+
bool gtkhash_ie: 1; /**< GTK Hash information */
59+
bool lfn_gtk_version_ie: 1; /**< LFN Version & GTK Hash */
5960
} wp_nested_ie_sub_list_t;
6061

6162
/**

source/6LoWPAN/ws/ws_llc_data_service.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ typedef struct {
158158

159159
static NS_LIST_DEFINE(llc_data_base_list, llc_data_base_t, link);
160160

161-
static uint16_t ws_wp_nested_message_length(wp_nested_ie_sub_list_t requested_list, llc_ie_params_t *params);
161+
static uint16_t ws_wp_nested_message_length(wp_nested_ie_sub_list_t requested_list, llc_data_base_t *llc_base);
162162
static uint16_t ws_wh_headers_length(wh_ie_sub_list_t requested_list, llc_ie_params_t *params);
163163

164164
/** LLC message local functions */
@@ -378,9 +378,10 @@ static uint16_t ws_wh_headers_length(wh_ie_sub_list_t requested_list, llc_ie_par
378378
return length;
379379
}
380380

381-
static uint16_t ws_wp_nested_message_length(wp_nested_ie_sub_list_t requested_list, llc_ie_params_t *params)
381+
static uint16_t ws_wp_nested_message_length(wp_nested_ie_sub_list_t requested_list, llc_data_base_t *llc_base)
382382
{
383383
uint16_t length = 0;
384+
llc_ie_params_t *params = &llc_base->ie_params;
384385
if (requested_list.gtkhash_ie) {
385386
//Static 32 bytes allways
386387
length += WS_WP_SUB_IE_ELEMENT_HEADER_LENGTH + params->gtkhash_length;
@@ -411,6 +412,17 @@ static uint16_t ws_wp_nested_message_length(wp_nested_ie_sub_list_t requested_li
411412
length += 2;
412413
}
413414
}
415+
#ifdef HAVE_WS_VERSION_1_1
416+
if (requested_list.lfn_gtk_version_ie) {
417+
418+
length += WS_WP_SUB_IE_ELEMENT_HEADER_LENGTH + ws_wp_nested_lfn_version_length();
419+
ws_lgtkhash_ie_t ws_lgtkhash;
420+
ws_lgtkhash.lgtk0 = llc_base->interface_ptr->ws_info->lfngtk.active_hash_1;
421+
ws_lgtkhash.lgtk1 = llc_base->interface_ptr->ws_info->lfngtk.active_hash_2;
422+
ws_lgtkhash.lgtk2 = llc_base->interface_ptr->ws_info->lfngtk.active_hash_3;
423+
length += WS_WP_SUB_IE_ELEMENT_HEADER_LENGTH + ws_wp_lgtk_hash_length(&ws_lgtkhash);
424+
}
425+
#endif
414426

415427
if (requested_list.bs_ie) {
416428
///Dynamic length
@@ -1038,7 +1050,7 @@ static void ws_llc_lowpan_mpx_data_request(llc_data_base_t *base, mpx_user_t *us
10381050
nested_wp_id.us_ie = true;
10391051

10401052
uint16_t ie_header_length = ws_wh_headers_length(ie_header_mask, &base->ie_params);
1041-
uint16_t nested_ie_length = ws_wp_nested_message_length(nested_wp_id, &base->ie_params);
1053+
uint16_t nested_ie_length = ws_wp_nested_message_length(nested_wp_id, base);
10421054

10431055
uint16_t over_head_size = ie_header_length;
10441056
if (nested_ie_length) {
@@ -1207,7 +1219,7 @@ static void ws_llc_mpx_eapol_request(llc_data_base_t *base, mpx_user_t *user_cb,
12071219
nested_wp_id.us_ie = true;
12081220

12091221
uint16_t ie_header_length = ws_wh_headers_length(ie_header_mask, &base->ie_params);
1210-
uint16_t nested_ie_length = ws_wp_nested_message_length(nested_wp_id, &base->ie_params);
1222+
uint16_t nested_ie_length = ws_wp_nested_message_length(nested_wp_id, base);
12111223

12121224
uint16_t over_head_size = ie_header_length;
12131225
if (nested_ie_length) {
@@ -1783,7 +1795,7 @@ int8_t ws_llc_asynch_request(struct protocol_interface_info_entry *interface, as
17831795
request->wh_requested_ie_list.rsl_ie = false; //Never should not be a part Asynch message
17841796
request->wh_requested_ie_list.vh_ie = false;
17851797
uint16_t header_buffer_length = ws_wh_headers_length(request->wh_requested_ie_list, &base->ie_params);
1786-
uint16_t wp_nested_payload_length = ws_wp_nested_message_length(request->wp_requested_nested_ie_list, &base->ie_params);
1798+
uint16_t wp_nested_payload_length = ws_wp_nested_message_length(request->wp_requested_nested_ie_list, base);
17871799

17881800
//Allocated
17891801
uint16_t total_length = header_buffer_length;
@@ -1880,6 +1892,28 @@ int8_t ws_llc_asynch_request(struct protocol_interface_info_entry *interface, as
18801892
//Write Vendor spesific payload
18811893
ptr = ws_wp_nested_vp_write(ptr, base->ie_params.vendor_payload, base->ie_params.vendor_payload_length);
18821894
}
1895+
1896+
#ifdef HAVE_WS_VERSION_1_1
1897+
if (ws_version_1_1(interface)) {
1898+
if (request->wp_requested_nested_ie_list.lfn_gtk_version_ie) {
1899+
ws_lfnver_ie_t lfn_ver;
1900+
ws_lgtkhash_ie_t ws_lgtkhash;
1901+
//Write LFN Version
1902+
lfn_ver.lfn_version = interface->ws_info->lfngtk.lfn_version;
1903+
ptr = ws_wp_nested_lfn_version_write(ptr, &lfn_ver);
1904+
//Write LFN GTK Hash info
1905+
ws_lgtkhash.lgtk0 = base->interface_ptr->ws_info->lfngtk.active_hash_1;
1906+
ws_lgtkhash.lgtk1 = base->interface_ptr->ws_info->lfngtk.active_hash_2;
1907+
ws_lgtkhash.lgtk2 = base->interface_ptr->ws_info->lfngtk.active_hash_3;
1908+
ws_lgtkhash.active_lgtk_index = base->interface_ptr->ws_info->lfngtk.active_key_index;
1909+
ws_lgtkhash.lgtk0_hash = base->interface_ptr->ws_info->lfngtk.lgtkhash;
1910+
ws_lgtkhash.lgtk1_hash = base->interface_ptr->ws_info->lfngtk.lgtkhash + 8;
1911+
ws_lgtkhash.lgtk2_hash = base->interface_ptr->ws_info->lfngtk.lgtkhash + 16;
1912+
ptr = ws_wp_nested_lgtk_hash_write(ptr, &ws_lgtkhash);
1913+
}
1914+
}
1915+
#endif
1916+
18831917
}
18841918

18851919
base->interface_ptr->mac_api->mcps_data_req_ext(base->interface_ptr->mac_api, &data_req, &message->ie_ext, &request->channel_list, message->priority);

test/nanostack/unittest/stub/ws_ie_lib_stub.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,21 @@ bool ws_wp_nested_network_name_read(uint8_t *data, uint16_t length, ws_wp_networ
198198
{
199199
return false;
200200
}
201+
202+
203+
uint16_t ws_wp_lgtk_hash_length(struct ws_lgtkhash_ie *ws_lgtkhash)
204+
{
205+
return 1;
206+
}
207+
208+
uint8_t *ws_wp_nested_lgtk_hash_write(uint8_t *ptr, struct ws_lgtkhash_ie *ws_lgtkhash)
209+
{
210+
ptr += 2 + 1;
211+
return ptr;
212+
}
213+
214+
uint8_t *ws_wp_nested_lfn_version_write(uint8_t *ptr, struct ws_lfnver_ie *ws_lfnver)
215+
{
216+
ptr += 2 + 2;
217+
return ptr;
218+
}

0 commit comments

Comments
 (0)