6363#include "Service_Libs/nd_proxy/nd_proxy.h"
6464#include "Service_Libs/blacklist/blacklist.h"
6565#include "platform/topo_trace.h"
66+ #include "dhcp_service_api.h"
6667#include "libDHCPv6/libDHCPv6.h"
6768#include "DHCPv6_client/dhcpv6_client_api.h"
6869#include "ws_management_api.h"
@@ -136,21 +137,54 @@ mac_neighbor_table_entry_t *ws_bootstrap_mac_neighbor_add(struct protocol_interf
136137 }
137138 // TODO only call these for new neighbour
138139 mlme_device_descriptor_t device_desc ;
139- neighbor -> lifetime = WS_NEIGHBOR_LINK_TIMEOUT ;
140- neighbor -> link_lifetime = WS_NEIGHBOR_LINK_TIMEOUT ;
141- tr_debug ("Added new neighbor %s : index:%u" , trace_array (src64 , 8 ), neighbor -> index );
140+ neighbor -> lifetime = WS_NEIGHBOUR_TEMPORARY_ENTRY_LIFETIME ;
141+ neighbor -> link_lifetime = WS_NEIGHBOUR_TEMPORARY_ENTRY_LIFETIME ;
142142 mac_helper_device_description_write (interface , & device_desc , neighbor -> mac64 , neighbor -> mac16 , 0 , false);
143143 mac_helper_devicetable_set (& device_desc , interface , neighbor -> index , interface -> mac_parameters -> mac_default_key_index , true);
144+
144145 return neighbor ;
145146}
146147
148+ void ws_bootstrap_neighbor_set_stable (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
149+ {
150+ mac_neighbor_table_entry_t * neighbor = mac_neighbor_table_address_discover (mac_neighbor_info (interface ), src64 , MAC_ADDR_MODE_64_BIT );
151+
152+ if (neighbor && neighbor -> link_lifetime != WS_NEIGHBOR_LINK_TIMEOUT ) {
153+ neighbor -> lifetime = WS_NEIGHBOR_LINK_TIMEOUT ;
154+ neighbor -> link_lifetime = WS_NEIGHBOR_LINK_TIMEOUT ;
155+ tr_info ("Added new neighbor %s : index:%u" , trace_array (src64 , 8 ), neighbor -> index );
156+ }
157+ }
158+
159+ void ws_bootstrap_mac_neighbor_short_time_set (struct protocol_interface_info_entry * interface , const uint8_t * src64 , uint32_t valid_time )
160+ {
161+ mac_neighbor_table_entry_t * neighbor = mac_neighbor_table_address_discover (mac_neighbor_info (interface ), src64 , MAC_ADDR_MODE_64_BIT );
162+
163+ if (neighbor && neighbor -> link_lifetime != WS_NEIGHBOR_LINK_TIMEOUT ) {
164+ //mlme_device_descriptor_t device_desc;
165+ neighbor -> lifetime = valid_time ;
166+ neighbor -> link_lifetime = valid_time ;
167+ tr_debug ("Set short response neighbor %s : index:%u" , trace_array (src64 , 8 ), neighbor -> index );
168+ }
169+ }
170+
147171static void ws_bootstrap_neighbor_delete (struct protocol_interface_info_entry * interface , mac_neighbor_table_entry_t * entry_ptr )
148172{
149173 mac_helper_devicetable_remove (interface -> mac_api , entry_ptr -> index , entry_ptr -> mac64 );
150174 etx_neighbor_remove (interface -> id , entry_ptr -> index , entry_ptr -> mac64 );
151175 ws_neighbor_class_entry_remove (& interface -> ws_info -> neighbor_storage , entry_ptr -> index );
152176}
153177
178+ void ws_bootstrap_mac_neighbor_temporary_remove (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
179+ {
180+ mac_neighbor_table_entry_t * neighbor = mac_neighbor_table_address_discover (mac_neighbor_info (interface ), src64 , MAC_ADDR_MODE_64_BIT );
181+
182+ if (neighbor && neighbor -> link_lifetime != WS_NEIGHBOR_LINK_TIMEOUT ) {
183+ tr_debug ("Remove temporary neighbour %s" , trace_array (src64 , 8 ));
184+ mac_neighbor_table_neighbor_remove (mac_neighbor_info (interface ), neighbor );
185+ }
186+ }
187+
154188static void ws_bootstap_eapol_neigh_entry_allocate (struct protocol_interface_info_entry * interface )
155189{
156190 uint8_t mac_64 [8 ];
@@ -161,6 +195,7 @@ static void ws_bootstap_eapol_neigh_entry_allocate(struct protocol_interface_inf
161195 if (!mac_entry ) {
162196 return ;
163197 }
198+ ws_bootstrap_neighbor_set_stable (interface , mac_64 );
164199 mac_entry -> lifetime = 0xffffffff ;
165200 mac_entry -> link_lifetime = 0xffffffff ;
166201 ws_neighbor_class_entry_t * ws_neigh = ws_neighbor_class_entry_get (& interface -> ws_info -> neighbor_storage , mac_entry -> index );
@@ -838,6 +873,23 @@ bool ws_bootstrap_nd_ns_transmit(protocol_interface_info_entry_t *cur, ipv6_neig
838873 return true;
839874}
840875
876+ static void ws_bootstrap_dhcp_neighbour_update_cb (int8_t interface_id , uint8_t ll_addr [static 16 ])
877+ {
878+ if (memcmp (ll_addr , ADDR_LINK_LOCAL_PREFIX , 8 )) {
879+ return ;
880+ }
881+
882+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (interface_id );
883+ if (!cur ) {
884+ return ;
885+ }
886+
887+ uint8_t mac64 [8 ];
888+ memcpy (mac64 , ll_addr + 8 , 8 );
889+ mac64 [0 ] ^= 2 ;
890+ ws_bootstrap_mac_neighbor_short_time_set (cur , mac64 , WS_NEIGHBOUR_DHCP_ENTRY_LIFETIME );
891+ }
892+
841893static int8_t ws_bootstrap_up (protocol_interface_info_entry_t * cur )
842894{
843895 int8_t ret_val = -1 ;
@@ -886,6 +938,7 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
886938 cur -> if_ns_transmit = ws_bootstrap_nd_ns_transmit ;
887939
888940 dhcp_client_init (cur -> id , DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE );
941+ dhcp_service_link_local_rx_cb_set (cur -> id , ws_bootstrap_dhcp_neighbour_update_cb );
889942 dhcp_client_configure (cur -> id , true, true, true); //RENEW uses SOLICIT, Interface will use 1 instance for address get, IAID address hint is not used.
890943 dhcp_client_solicit_timeout_set (cur -> id , WS_DHCP_SOLICIT_TIMEOUT , WS_DHCP_SOLICIT_MAX_RT , WS_DHCP_SOLICIT_MAX_RC );
891944
@@ -1434,6 +1487,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
14341487 if (!neighbour_pointer_valid ) {
14351488 return ;
14361489 }
1490+ ws_bootstrap_neighbor_set_stable (cur , data -> SrcAddr );
14371491 }
14381492
14391493 if (neighbour_pointer_valid ) {
@@ -1707,6 +1761,10 @@ static void ws_bootstrap_neighbor_table_clean(struct protocol_interface_info_ent
17071761 continue ;
17081762 }
17091763
1764+ if (cur -> link_lifetime != WS_NEIGHBOR_LINK_TIMEOUT ) {
1765+ continue ;
1766+ }
1767+
17101768 if (cur -> link_role == PRIORITY_PARENT_NEIGHBOUR ) {
17111769 //This is our primary parent we cannot delete
17121770 continue ;
@@ -1834,7 +1892,7 @@ static bool ws_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr,
18341892 ws_neighbor_class_entry_t * ws_neighbor = ws_neighbor_class_entry_get (& cur -> ws_info -> neighbor_storage , entry_ptr -> index );
18351893 etx_storage_t * etx_entry = etx_storage_entry_get (cur -> id , entry_ptr -> index );
18361894
1837- if (!entry_ptr -> trusted_device || !ws_neighbor || !etx_entry || ws_neighbor -> negative_aro_send ) {
1895+ if (!entry_ptr -> trusted_device || !ws_neighbor || !etx_entry || ws_neighbor -> negative_aro_send || entry_ptr -> link_lifetime != WS_NEIGHBOR_LINK_TIMEOUT ) {
18381896 return false;
18391897 }
18401898
@@ -2515,6 +2573,7 @@ static bool ws_rpl_new_parent_callback(uint8_t *ll_parent_address, void *handle,
25152573 bool create_ok = ws_bootstrap_neighbor_info_request (cur , entry -> mac64 , & neigh_buffer , true);
25162574 if (create_ok ) {
25172575 ws_neighbor_class_entry_t * ws_neigh = neigh_buffer .ws_neighbor ;
2576+ ws_bootstrap_neighbor_set_stable (cur , entry -> mac64 );
25182577 //Copy fhss temporary data
25192578 * ws_neigh = entry -> neigh_info_list ;
25202579 //ETX Create here
@@ -3226,7 +3285,7 @@ static int8_t ws_bootstrap_neighbor_set(protocol_interface_info_entry_t *cur, pa
32263285 ns_list_add_to_end (& cur -> ws_info -> parent_list_free , parent_ptr );
32273286 return -1 ;
32283287 }
3229-
3288+ ws_bootstrap_neighbor_set_stable ( cur , parent_ptr -> addr );
32303289 ws_neighbor_class_neighbor_unicast_time_info_update (neighbor_info .ws_neighbor , & parent_ptr -> ws_utt , parent_ptr -> timestamp );
32313290 ws_neighbor_class_neighbor_unicast_schedule_set (neighbor_info .ws_neighbor , & parent_ptr -> ws_us , & cur -> ws_info -> hopping_schdule );
32323291 return 0 ;
0 commit comments