Skip to content

Commit 94e516f

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
Integrated new WS IE header and payload API's
Remove local static function and replace by new denided read function's
1 parent c553e8c commit 94e516f

File tree

2 files changed

+30
-102
lines changed

2 files changed

+30
-102
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 18 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "6LoWPAN/ws/ws_common_defines.h"
4646
#include "6LoWPAN/ws/ws_llc.h"
4747
#include "6LoWPAN/ws/ws_neighbor_class.h"
48+
#include "6LoWPAN/ws/ws_ie_lib.h"
4849
#include "6LoWPAN/lowpan_adaptation_interface.h"
4950
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
5051
#include "platform/topo_trace.h"
@@ -262,75 +263,6 @@ static bool ws_bootstrap_network_name_matches(const struct mcps_data_ie_list *ie
262263
return true;
263264
}
264265

265-
static bool ws_bootstrap_unicast_schedule_read(uint8_t *ptr, uint16_t length, ws_hopping_schedule_t *uc_hopping)
266-
{
267-
mac_nested_payload_IE_t nested_payload_ie;
268-
nested_payload_ie.id = WP_PAYLOAD_IE_US_TYPE;
269-
nested_payload_ie.type_long = true;
270-
271-
if (0 == mac_ie_nested_discover(ptr , length, &nested_payload_ie)) {
272-
tr_warn("No unicast schedule");
273-
return false;
274-
}
275-
if (nested_payload_ie.length < 4) {
276-
tr_warn("corrupetd schedule");
277-
return false;
278-
}
279-
if (!uc_hopping) {
280-
// all OK no data read
281-
return true;
282-
}
283-
uc_hopping->fhss_uc_dwell_interval = nested_payload_ie.content_ptr[0];
284-
uc_hopping->clock_drift = nested_payload_ie.content_ptr[1];
285-
uc_hopping->timing_accurancy = nested_payload_ie.content_ptr[2];
286-
uc_hopping->channel_plan = (nested_payload_ie.content_ptr[3] & 0x03);
287-
uc_hopping->channel_function = (nested_payload_ie.content_ptr[3] & 0x38) >> 3;
288-
289-
// TODO missing rest of the fields
290-
291-
return true;
292-
}
293-
294-
static bool ws_bootstrap_pan_information_read(uint8_t *ptr, uint16_t length, ws_pan_information_t *pan_information)
295-
{
296-
mac_nested_payload_IE_t nested_payload_ie;
297-
nested_payload_ie.id = WP_PAYLOAD_IE_PAN_TYPE;
298-
nested_payload_ie.type_long = true;
299-
300-
if (0 == mac_ie_nested_discover(ptr , length, &nested_payload_ie)) {
301-
tr_warn("No PAN information");
302-
return false;
303-
}
304-
if (nested_payload_ie.length < 5) {
305-
tr_warn("corrupetd PAN information");
306-
return false;
307-
}
308-
if (pan_information) {
309-
pan_information->pan_size = common_read_16_bit_inverse(nested_payload_ie.content_ptr);
310-
pan_information->routing_cost = common_read_16_bit_inverse(nested_payload_ie.content_ptr + 2);
311-
pan_information->use_parent_bs = (nested_payload_ie.content_ptr[4] & 0x10) == 0x10;
312-
pan_information->rpl_routing_method = (nested_payload_ie.content_ptr[4] & 0x20) == 0x20;
313-
pan_information->version = (nested_payload_ie.content_ptr[4]& 0xe0) >> 5;
314-
}
315-
316-
return true;
317-
}
318-
319-
static bool ws_bootstrap_ufsi_read(uint8_t *ptr, uint16_t length, uint_fast24_t *ufsi)
320-
{
321-
mac_header_IE_t utt_ie;
322-
utt_ie.id = MAC_HEADER_ASSIGNED_EXTERNAL_ORG_IE_ID;
323-
324-
if (4 != mac_ie_header_sub_id_discover(ptr, length, &utt_ie, WH_IE_UTT_TYPE)) {
325-
// NO UTT header
326-
return false;
327-
}
328-
if (ufsi) {
329-
*ufsi = common_read_24_bit_inverse(&utt_ie.content_ptr[1]);
330-
}
331-
return true;
332-
}
333-
334266
static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext)
335267
{
336268

@@ -350,25 +282,25 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
350282
return;
351283
}
352284

353-
uint_fast24_t ufsi;
285+
ws_utt_ie_t ws_utt;
354286

355-
if (!ws_bootstrap_ufsi_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ufsi)) {
287+
if (!ws_wh_utt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_utt)) {
356288
// Corrupted
357289
tr_error("No ufsi");
358290
return;
359291
}
360292

361293
ws_pan_information_t pan_information;
362-
ws_hopping_schedule_t hopping_schedule = { 0 };
294+
ws_us_ie_t ws_us;
363295

364-
if (!ws_bootstrap_pan_information_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &pan_information)) {
296+
if (!ws_wp_nested_pan_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &pan_information)) {
365297
// Corrupted
366298
tr_error("No pan information");
367299
return;
368300
}
369301

370302
// TODO create own function to read just dwell time
371-
if (!ws_bootstrap_unicast_schedule_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &hopping_schedule)) {
303+
if (!ws_wp_nested_us_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &ws_us)) {
372304
// Corrupted
373305
tr_error("No unicast schedule");
374306
return;
@@ -390,9 +322,9 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
390322
}
391323

392324
ws_neighbor->fhss_data.utt_timestamp = data->timestamp;
393-
ws_neighbor->fhss_data.ufsi = ufsi;
394-
ws_neighbor->fhss_data.channel_function = hopping_schedule.channel_function;
395-
ws_neighbor->fhss_data.unicast_dwell = hopping_schedule.fhss_uc_dwell_interval;
325+
ws_neighbor->fhss_data.ufsi = ws_utt.ut;
326+
ws_neighbor->fhss_data.channel_function = ws_us.channle_function;
327+
ws_neighbor->fhss_data.unicast_dwell = ws_us.dwell_interval;
396328

397329

398330

@@ -406,9 +338,9 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
406338

407339

408340
// Parent valid store information
409-
cur->ws_info->parent_info.ufsi = ufsi;
341+
cur->ws_info->parent_info.ufsi = ws_utt.ut;
410342
// Saved from unicast IE
411-
cur->ws_info->parent_info.dwell_interval = hopping_schedule.fhss_uc_dwell_interval;
343+
cur->ws_info->parent_info.dwell_interval = ws_us.dwell_interval;
412344

413345
// Saved from Pan information
414346
cur->ws_info->parent_info.pan_configuration = pan_information;
@@ -439,17 +371,17 @@ static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_inter
439371
return;
440372
}
441373

442-
uint_fast24_t ufsi;
443-
ws_hopping_schedule_t hopping_schedule = { 0 };
374+
ws_utt_ie_t ws_utt;
375+
ws_us_ie_t ws_us;
444376

445-
if (!ws_bootstrap_ufsi_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ufsi)) {
377+
if (!ws_wh_utt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_utt)) {
446378
// Corrupted
447379
tr_error("No ufsi");
448380
return;
449381
}
450382

451383
// TODO create own function to read just dwell time
452-
if (!ws_bootstrap_unicast_schedule_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &hopping_schedule)) {
384+
if (!ws_wp_nested_us_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &ws_us)) {
453385
// Corrupted
454386
tr_error("No unicast schedule");
455387
return;
@@ -465,9 +397,9 @@ static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_inter
465397
}
466398

467399
ws_neighbor->fhss_data.utt_timestamp = data->timestamp;
468-
ws_neighbor->fhss_data.ufsi = ufsi;
469-
ws_neighbor->fhss_data.channel_function = hopping_schedule.channel_function;
470-
ws_neighbor->fhss_data.unicast_dwell = hopping_schedule.fhss_uc_dwell_interval;
400+
ws_neighbor->fhss_data.ufsi = ws_utt.ut;
401+
ws_neighbor->fhss_data.channel_function = ws_us.channle_function;
402+
ws_neighbor->fhss_data.unicast_dwell = ws_us.dwell_interval;
471403

472404
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_advertisement);
473405
}

source/6LoWPAN/ws/ws_llc_data_service.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,12 @@ static void ws_llc_mac_indication_cb(const mac_api_t* api, const mcps_data_ind_t
401401
}
402402

403403
//Discover Header WH_IE_UTT_TYPE
404-
mac_header_IE_t utt_ie;
405-
uint8_t message_type;
406-
utt_ie.id = MAC_HEADER_ASSIGNED_EXTERNAL_ORG_IE_ID;
407-
if (4 != mac_ie_header_sub_id_discover(ie_ext->headerIeList, ie_ext->headerIeListLength, &utt_ie, WH_IE_UTT_TYPE)) {
404+
ws_utt_ie_t ws_utt;
405+
if (!ws_wh_utt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_utt)) {
408406
// NO UTT header
409407
return;
410408
}
409+
411410
protocol_interface_info_entry_t *interface = base->interface_ptr;
412411

413412
ws_neighbor_class_entry_t * ws_neighbor = NULL;
@@ -416,30 +415,27 @@ static void ws_llc_mac_indication_cb(const mac_api_t* api, const mcps_data_ind_t
416415
ws_neighbor = ws_neighbor_class_entry_get(&interface->ws_info->neighbor_storage, neighbor->index);
417416
}
418417

419-
420-
const uint8_t *ptr = utt_ie.content_ptr;
421-
message_type = *ptr++ & 0x0f;
422418
if (ws_neighbor) {
423419
ws_neighbor->fhss_data.utt_timestamp = data->timestamp;
424-
ws_neighbor->fhss_data.ufsi = common_read_24_bit_inverse(ptr);
420+
ws_neighbor->fhss_data.ufsi = ws_utt.ut;
425421
//Update BT if it is part of message
426-
if (5 == mac_ie_header_sub_id_discover(ie_ext->headerIeList, ie_ext->headerIeListLength, &utt_ie, WH_IE_BT_TYPE)) {
427-
ptr = utt_ie.content_ptr;
422+
ws_bt_ie_t ws_bt;
423+
if (ws_wh_bt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_bt)) {
428424
ws_neighbor->fhss_data.bt_timestamp = data->timestamp;
429-
ws_neighbor->fhss_data.broadcast_slot_number = common_read_16_bit_inverse(ptr);
430-
ws_neighbor->fhss_data.broadcast_interval = common_read_24_bit_inverse(ptr + 2);
425+
ws_neighbor->fhss_data.broadcast_slot_number = ws_bt.broadcast_slot_number;
426+
ws_neighbor->fhss_data.broadcast_interval = ws_bt.bsi;
431427
}
432428

433429
//Refresh Neighbor if unicast
434-
if (message_type == WS_FT_DATA && data->DstAddrMode && addr_check_broadcast(data->DstAddr, data->DstAddrMode)) {
430+
if (ws_utt.message_type == WS_FT_DATA && data->DstAddrMode && addr_check_broadcast(data->DstAddr, data->DstAddrMode)) {
435431
tr_debug("Refresh neigh index %u", neighbor->index);
436432
mac_neighbor_table_neighbor_refresh(interface->mac_parameters->mac_neighbor_table, neighbor, neighbor->link_lifetime);
437433
}
438434
}
439435

440436

441437
//Discover 2 Payload Heder
442-
if (message_type == WS_FT_DATA || message_type == WS_FT_EAPOL) {
438+
if (ws_utt.message_type == WS_FT_DATA || ws_utt.message_type == WS_FT_EAPOL) {
443439

444440
mac_payload_IE_t mpx_ie;
445441
mpx_ie.id = MAC_PAYLOAD_MPX_IE_GROUP_ID;
@@ -468,7 +464,7 @@ static void ws_llc_mac_indication_cb(const mac_api_t* api, const mcps_data_ind_t
468464
}
469465

470466
//Asynch Message
471-
if (message_type < WS_FT_DATA && base->acynch_ind) {
467+
if (ws_utt.message_type < WS_FT_DATA && base->acynch_ind) {
472468
mac_payload_IE_t ws_wp_nested;
473469

474470
ws_wp_nested.id = WS_WP_NESTED_IE;
@@ -482,7 +478,7 @@ static void ws_llc_mac_indication_cb(const mac_api_t* api, const mcps_data_ind_t
482478
asynch_ie_list.headerIeListLength = ie_ext->headerIeListLength;
483479
asynch_ie_list.payloadIeList = ws_wp_nested.content_ptr;
484480
asynch_ie_list.payloadIeListLength = ws_wp_nested.length;
485-
base->acynch_ind(base->interface_ptr,data, &asynch_ie_list, message_type);
481+
base->acynch_ind(base->interface_ptr,data, &asynch_ie_list, ws_utt.message_type);
486482
}
487483

488484
}

0 commit comments

Comments
 (0)