@@ -83,8 +83,9 @@ static bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *c
83
83
static int8_t ws_bootsrap_event_trig (ws_bootsrap_event_type_e event_type , int8_t interface_id , arm_library_event_priority_e priority , void * event_data );
84
84
85
85
static bool ws_bootstrap_neighbor_info_request (struct protocol_interface_info_entry * interface , const uint8_t * mac_64 , llc_neighbour_req_t * neighbor_buffer , bool request_new );
86
- static uint16_t ws_bootstrap_route_cost_calculate (protocol_interface_info_entry_t * cur );
87
- static uint16_t ws_bootstrap_get_min_rank_inc (protocol_interface_info_entry_t * cur );
86
+ static uint16_t ws_bootstrap_routing_cost_calculate (protocol_interface_info_entry_t * cur );
87
+ static uint16_t ws_bootstrap_rank_get (protocol_interface_info_entry_t * cur );
88
+ static uint16_t ws_bootstrap_min_rank_inc_get (protocol_interface_info_entry_t * cur );
88
89
89
90
mac_neighbor_table_entry_t * ws_bootstrap_mac_neighbor_add (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
90
91
{
@@ -783,6 +784,12 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
783
784
*
784
785
*/
785
786
787
+ // Save route cost for all neighbours
788
+ llc_neighbour_req_t neighbor_info ;
789
+ if (ws_bootstrap_neighbor_info_request (cur , data -> SrcAddr , & neighbor_info , false) ) {
790
+ neighbor_info .ws_neighbor -> routing_cost = pan_information .routing_cost ;
791
+ }
792
+
786
793
// Save the best network parent
787
794
788
795
if (ws_bootstrap_state_discovery (cur )) {
@@ -1499,8 +1506,8 @@ static void ws_bootstrap_ip_stack_activate(protocol_interface_info_entry_t *cur)
1499
1506
1500
1507
static void ws_set_fhss_hop (protocol_interface_info_entry_t * cur )
1501
1508
{
1502
- uint16_t own_rank = ws_bootstrap_route_cost_calculate (cur );
1503
- uint16_t rank_inc = ws_bootstrap_get_min_rank_inc (cur );
1509
+ uint16_t own_rank = ws_bootstrap_rank_get (cur );
1510
+ uint16_t rank_inc = ws_bootstrap_min_rank_inc_get (cur );
1504
1511
if (own_rank == 0xffff || rank_inc == 0xffff ) {
1505
1512
return ;
1506
1513
}
@@ -1802,16 +1809,41 @@ static struct rpl_instance *ws_get_rpl_instance(protocol_interface_info_entry_t
1802
1809
return best_instance ;
1803
1810
}
1804
1811
1805
- static uint16_t ws_bootstrap_route_cost_calculate (protocol_interface_info_entry_t * cur )
1812
+ static uint16_t ws_bootstrap_routing_cost_calculate (protocol_interface_info_entry_t * cur )
1806
1813
{
1807
- struct rpl_instance * rpl_instance = ws_get_rpl_instance ( cur );
1808
- if (!rpl_instance ) {
1814
+ mac_neighbor_table_entry_t * mac_neighbor = mac_neighbor_entry_get_priority ( mac_neighbor_info ( cur ) );
1815
+ if (!mac_neighbor ) {
1809
1816
return 0xffff ;
1810
1817
}
1811
- return rpl_control_current_rank (rpl_instance );
1818
+ ws_neighbor_class_entry_t * ws_neighbor = ws_neighbor_class_entry_get (& cur -> ws_info -> neighbor_storage , mac_neighbor -> index );
1819
+ if (!ws_neighbor ) {
1820
+ return 0xffff ;
1821
+ }
1822
+
1823
+ uint16_t etx = etx_local_etx_read (cur -> id ,mac_neighbor -> index );
1824
+ if (etx == 0 ) {
1825
+ etx = 0xffff ;
1826
+ }
1827
+ if (etx > 0x800 ) {
1828
+ // Wi-SUN section 6.2.3.1.6.1 says ETX can only be maximum of 1024 (8*128) in RPL units, ie 8.0.
1829
+ etx = 0x800 ;
1830
+ }
1831
+ etx = etx >> 1 ;
1832
+
1833
+ return ws_neighbor -> routing_cost + etx ;
1812
1834
}
1813
1835
1814
- static uint16_t ws_bootstrap_get_min_rank_inc (protocol_interface_info_entry_t * cur )
1836
+ static uint16_t ws_bootstrap_rank_get (protocol_interface_info_entry_t * cur )
1837
+ {
1838
+ struct rpl_instance * rpl_instance = ws_get_rpl_instance (cur );
1839
+ if (!rpl_instance ) {
1840
+ return 0xffff ;
1841
+ }
1842
+ return rpl_control_current_rank (rpl_instance );
1843
+ }
1844
+
1845
+
1846
+ static uint16_t ws_bootstrap_min_rank_inc_get (protocol_interface_info_entry_t * cur )
1815
1847
{
1816
1848
struct rpl_instance * rpl_instance = ws_get_rpl_instance (cur );
1817
1849
if (!rpl_instance ) {
@@ -1847,7 +1879,7 @@ static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
1847
1879
} else {
1848
1880
// Nodes need to calculate routing cost
1849
1881
// PAN size is saved from latest PAN advertisement
1850
- cur -> ws_info -> pan_information .routing_cost = ws_bootstrap_route_cost_calculate (cur );
1882
+ cur -> ws_info -> pan_information .routing_cost = ws_bootstrap_routing_cost_calculate (cur );
1851
1883
}
1852
1884
1853
1885
0 commit comments