6969#include "mac_api.h"
7070#include "6LoWPAN/MAC/mac_data_poll.h"
7171#include "libNET/src/net_load_balance_internal.h"
72+ #include "6LoWPAN/lowpan_adaptation_interface.h"
7273#include "6LoWPAN/NVM/nwk_nvm.h"
7374
7475
@@ -90,7 +91,7 @@ static void protocol_6lowpan_bootstrap_rpl_callback(rpl_event_t event, void *han
9091#endif
9192
9293static void protocol_6lowpan_mle_purge_neighbors (struct protocol_interface_info_entry * cur_interface , uint8_t entry_count , uint8_t force_priority );
93- static uint8_t protocol_6lowpan_mle_order_last_entries (mle_neigh_table_list_t * mle_neigh_table , uint8_t entry_count );
94+ static uint8_t protocol_6lowpan_mle_order_last_entries (int8_t interface_id , mle_neigh_table_list_t * mle_neigh_table , uint8_t entry_count );
9495static uint8_t protocol_6lowpan_mle_data_allocate (void );
9596static bool mle_accept_request_cb (int8_t interface_id , uint16_t msgId , bool usedAllRetries );
9697static void lowpan_comm_status_indication_cb (int8_t if_id , const mlme_comm_status_t * status );
@@ -469,7 +470,7 @@ static uint8_t *mle_table_set_neighbours(int8_t interface_id, uint8_t *ptr)
469470 * ptr ++ = MLE_NEIGHBOR_INCOMING_LINK | MLE_NEIGHBOR_OUTGOING_LINK ;
470471 }
471472
472- * ptr ++ = etx_local_incoming_idr_read (interface_id , cur ) >> 3 ;
473+ * ptr ++ = etx_local_incoming_idr_read (interface_id , cur -> attribute_index ) >> 3 ;
473474
474475 if ((* link_flags_ptr & 0x07 ) == 1 ) {
475476 ptr = common_write_16_bit (cur -> short_adr , ptr );
@@ -610,7 +611,7 @@ static void mle_neigh_entry_update_by_mle_tlv_list(int8_t interface_id, mle_neig
610611 uint8_t link_idr ;
611612 uint8_t iop_flags ;
612613 if (mle_link_quality_tlv_parse (mac64 , short_address , mle_tlv_info .dataPtr , mle_tlv_info .tlvLen , & iop_flags , & link_idr )) {
613- etx_remote_incoming_idr_update (interface_id , link_idr , entry_temp );
614+ etx_remote_incoming_idr_update (interface_id , link_idr , entry_temp -> attribute_index );
614615
615616 if ((iop_flags & MLE_NEIGHBOR_PRIORITY_LINK ) == MLE_NEIGHBOR_PRIORITY_LINK ) {
616617 entry_temp -> priority_child_flag = true;
@@ -986,8 +987,10 @@ int protocol_6lowpan_router_synch_to_new_router(protocol_interface_info_entry_t
986987
987988static uint8_t mle_calculate_idr (int8_t interface_id , mle_message_t * mle_msg , mle_neigh_table_entry_t * entry_temp )
988989{
989-
990- return etx_lqi_dbm_update (interface_id , mle_msg -> lqi , mle_msg -> dbm , entry_temp ) >> 3 ;
990+ if (!entry_temp ) {
991+ return etx_lqi_dbm_update (-2 , mle_msg -> lqi , mle_msg -> dbm , 0 ) >> 3 ;
992+ }
993+ return etx_lqi_dbm_update (interface_id , mle_msg -> lqi , mle_msg -> dbm , entry_temp -> attribute_index ) >> 3 ;
991994
992995}
993996
@@ -1315,7 +1318,7 @@ static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_
13151318 return ;
13161319 }
13171320
1318- entry_count = protocol_6lowpan_mle_order_last_entries (mle_neigh_table , entry_count );
1321+ entry_count = protocol_6lowpan_mle_order_last_entries (cur_interface -> id , mle_neigh_table , entry_count );
13191322
13201323 ns_list_foreach_reverse_safe (mle_neigh_table_entry_t , entry , mle_neigh_table ) {
13211324 if (++ count > entry_count ) {
@@ -1343,12 +1346,12 @@ static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_
13431346 }
13441347}
13451348
1346- static uint8_t protocol_6lowpan_mle_order_last_entries (mle_neigh_table_list_t * mle_neigh_table , uint8_t entry_count )
1349+ static uint8_t protocol_6lowpan_mle_order_last_entries (int8_t interface_id , mle_neigh_table_list_t * mle_neigh_table , uint8_t entry_count )
13471350{
13481351 mle_neigh_table_entry_t * last ;
13491352 mle_neigh_table_entry_t * first_ordered = NULL ;
1353+ etx_storage_t * etx_last , * etx_cur ;
13501354 uint8_t count = 0 ;
1351-
13521355 do {
13531356 last = NULL ;
13541357
@@ -1363,6 +1366,8 @@ static uint8_t protocol_6lowpan_mle_order_last_entries(mle_neigh_table_list_t *m
13631366 continue ;
13641367 }
13651368
1369+
1370+
13661371 // Primary parent (parent selected for bootstrap or RPL primary parent)
13671372 if (entry -> priorityFlag && !last -> priorityFlag ) {
13681373 continue ;
@@ -1379,7 +1384,10 @@ static uint8_t protocol_6lowpan_mle_order_last_entries(mle_neigh_table_list_t *m
13791384 }
13801385
13811386 // Better ETX
1382- if (entry -> etx <= last -> etx ) {
1387+ etx_cur = etx_storage_entry_get (interface_id , entry -> attribute_index );
1388+ etx_last = etx_storage_entry_get (interface_id , last -> attribute_index );
1389+
1390+ if (etx_cur && etx_last && etx_cur -> etx <= etx_last -> etx ) {
13831391 continue ;
13841392 }
13851393
@@ -1678,6 +1686,13 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
16781686 if (mle_class_init (interface_id , buffer .device_decription_table_size , & protocol_6lowpan_neighbor_information_remove , & protocol_6lowpan_host_challenge , & lowpan_interface_is_active ) != 0 ) {
16791687 return -1 ;
16801688 }
1689+
1690+ if (!etx_storage_list_allocate (cur -> id , buffer .device_decription_table_size )) {
1691+ return -1 ;
1692+ }
1693+
1694+ lowpan_adaptation_interface_etx_update_enable (cur -> id );
1695+
16811696 mle_class_router_challenge (interface_id , protocol_6lowpan_router_challenge );
16821697 }
16831698
0 commit comments