Skip to content

Commit 022d61f

Browse files
author
Juha Heiskanen
committed
Wi-sun Neighbour table update and DHCP new callback
Temporary entry with shorter lifetime and API for remove and set stable lifetime. Temporary entry life time is 5 seconds. Temporary entry is released after TX process automatically. NA build will remove neighbours which not have ARO. DHCP relay and server will call new registred callback for direct received messages.
1 parent 857b41f commit 022d61f

File tree

10 files changed

+195
-7
lines changed

10 files changed

+195
-7
lines changed

nanostack/dhcp_service_api.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ typedef int (dhcp_service_receive_req_cb)(uint16_t instance_id, uint32_t msg_tr_
109109

110110
typedef int (dhcp_service_receive_resp_cb)(uint16_t instance_id, void *ptr, uint8_t msg_name, uint8_t *msg_ptr, uint16_t msg_len);
111111

112+
/* \brief Neighbour table update callback this is called for DHCP relay and server link local responses
113+
*
114+
* \param interface interface where address is got
115+
* \param ll_addr Link local which neighbour must be guarantee.
116+
*
117+
*
118+
*/
119+
typedef void (dhcp_relay_neighbour_cb)(int8_t interface, uint8_t ll_addr[static 16]);
120+
112121

113122
/**
114123
* \brief Initialize a new DHCP service instance.
@@ -235,5 +244,16 @@ void dhcp_service_req_remove_all(void *msg_class_ptr);
235244
*/
236245
bool dhcp_service_timer_tick(uint16_t ticks);
237246

247+
/**
248+
* \brief Register callback which is called when Relay or server RX direct message.
249+
*
250+
* \param interface_id Interface id for registed callback.
251+
* \param notify_cb callback pointer
252+
*
253+
* \return 0, if everything went fine.
254+
* \return -1, if error occurred.
255+
*/
256+
int dhcp_service_link_local_rx_cb_set(int8_t interface_id, dhcp_relay_neighbour_cb *notify_cb);
257+
238258

239259
#endif //DHCP_SERVICE_API_H_

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
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+
147171
static 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+
154188
static 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+
841893
static 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;

source/6LoWPAN/ws/ws_bootstrap.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,28 @@ struct ws_neighbor_class_entry *ws_bootstrap_eapol_tx_temporary_set(struct proto
9292

9393
void ws_bootstrap_eapol_tx_temporary_clear(struct protocol_interface_info_entry *interface);
9494

95+
void ws_bootstrap_neighbor_set_stable(struct protocol_interface_info_entry *interface, const uint8_t *src64);
96+
9597
int ws_bootstrap_get_info(protocol_interface_info_entry_t *cur, struct ws_stack_info *info_ptr);
9698

99+
void ws_bootstrap_mac_neighbor_short_time_set(struct protocol_interface_info_entry *interface, const uint8_t *src64, uint32_t valid_time);
100+
101+
void ws_bootstrap_mac_neighbor_temporary_remove(struct protocol_interface_info_entry *interface, const uint8_t *src64);
102+
97103
#else
98104

99105
#define ws_bootstrap_init(interface_id, bootstrap_mode) (-1)
100106
#define ws_bootstrap_state_machine(cur)
101107
#define ws_bootstrap_restart(cur)
102108
#define ws_bootstrap_neighbor_remove(cur, ll_address)
103109
#define ws_bootstrap_aro_failure(cur, ll_address)
110+
#define ws_bootstrap_neighbor_set_stable(interface, src64)
111+
#define ws_bootstrap_mac_neighbor_temporary_remove(interface, src64)
104112
#define ws_bootstrap_primary_parent_update(interface, neighbor)
105113
#define ws_bootstrap_secondary_parent_update(interface)
106114
#define ws_bootstrap_get_info(cur, info_ptr)
107115

116+
108117
#endif //HAVE_WS
109118

110119
#endif /* WS_BOOTSTRAP_H_ */

source/6LoWPAN/ws/ws_common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ uint8_t ws_common_allow_child_registration(protocol_interface_info_entry_t *inte
422422
tr_warn("Child registration not allowed %d/%d, max:%d", child_count, max_child_count, mac_neighbor_info(interface)->list_total_size);
423423
return ARO_FULL;
424424
}
425+
ws_bootstrap_neighbor_set_stable(interface, eui64);
425426
tr_info("Child registration allowed %d/%d, max:%d", child_count, max_child_count, mac_neighbor_info(interface)->list_total_size);
426427
return ARO_SUCCESS;
427428
}
@@ -488,5 +489,12 @@ void ws_common_secondary_parent_update(protocol_interface_info_entry_t *interfac
488489
{
489490
ws_bootstrap_secondary_parent_update(interface);
490491
}
492+
void ws_common_link_temporary_remove(struct protocol_interface_info_entry *interface, const uint8_t *ll64)
493+
{
494+
uint8_t mac64[8];
495+
memcpy(mac64, ll64 + 8, 8);
496+
mac64[0] ^= 2;
497+
ws_bootstrap_mac_neighbor_temporary_remove(interface, mac64);
498+
}
491499

492500
#endif // HAVE_WS

source/6LoWPAN/ws/ws_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface,
155155

156156
void ws_common_secondary_parent_update(protocol_interface_info_entry_t *interface);
157157

158+
void ws_common_link_temporary_remove(struct protocol_interface_info_entry *interface, const uint8_t *ll64);
159+
158160
#define ws_info(cur) ((cur)->ws_info)
159161
#else
160162
#define ws_info(cur) ((ws_info_t *) NULL)
@@ -168,6 +170,7 @@ void ws_common_secondary_parent_update(protocol_interface_info_entry_t *interfac
168170
#define ws_common_latency_estimate_get(cur) 0
169171
#define ws_common_datarate_get(cur) 0
170172
#define ws_common_network_size_estimate_get(cur) 0
173+
#define ws_common_link_temporary_remove(interface, ll64) ((void)0)
171174
#define ws_common_primary_parent_update(interface, neighbor)
172175
#define ws_common_secondary_parent_update(interface)
173176

source/6LoWPAN/ws/ws_common_defines.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ typedef struct ws_bs_ie {
240240
#define WS_FAN_VERSION_1_0 1
241241

242242
#define WS_NEIGHBOR_LINK_TIMEOUT 2200
243+
244+
#define WS_NEIGHBOUR_TEMPORARY_ENTRY_LIFETIME 5
245+
#define WS_NEIGHBOUR_DHCP_ENTRY_LIFETIME 60
243246
#define WS_NEIGHBOR_TEMPORARY_LINK_MIN_TIMEOUT_LARGE 520
244247
#define WS_NEIGHBOR_TEMPORARY_LINK_MIN_TIMEOUT_SMALL 260
245248
#define WS_NEIGHBOR_NUD_TIMEOUT WS_NEIGHBOR_LINK_TIMEOUT / 2

source/6LoWPAN/ws/ws_llc_data_service.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,16 @@ static void ws_llc_mac_confirm_cb(const mac_api_t *api, const mcps_data_conf_t *
465465
}
466466
}
467467
//ETX update
468+
llc_neighbour_req_t neighbor_info;
469+
neighbor_info.ws_neighbor = NULL;
470+
neighbor_info.neighbor = NULL;
468471
if (message->ack_requested && messsage_type == WS_FT_DATA) {
469-
llc_neighbour_req_t neighbor_info;
472+
470473
bool success = false;
471474

475+
if (message->dst_address_type == MAC_ADDR_MODE_64_BIT) {
476+
base->ws_neighbor_info_request_cb(interface, message->dst_address, &neighbor_info, false);
477+
}
472478
switch (data->status) {
473479
case MLME_SUCCESS:
474480
case MLME_TX_NO_ACK:
@@ -477,7 +483,7 @@ static void ws_llc_mac_confirm_cb(const mac_api_t *api, const mcps_data_conf_t *
477483
success = true;
478484
}
479485

480-
if (message->dst_address_type == MAC_ADDR_MODE_64_BIT && base->ws_neighbor_info_request_cb(interface, message->dst_address, &neighbor_info, false)) {
486+
if (neighbor_info.ws_neighbor && neighbor_info.neighbor && neighbor_info.neighbor->link_lifetime == WS_NEIGHBOR_LINK_TIMEOUT) {
481487
etx_transm_attempts_update(interface->id, 1 + data->tx_retries, success, neighbor_info.neighbor->index, neighbor_info.neighbor->mac64);
482488
//TODO discover RSL from Enchanced ACK Header IE elements
483489
ws_utt_ie_t ws_utt;
@@ -500,6 +506,7 @@ static void ws_llc_mac_confirm_cb(const mac_api_t *api, const mcps_data_conf_t *
500506
default:
501507
break;
502508
}
509+
503510
}
504511
//Free message
505512
llc_message_free(message, base);
@@ -529,6 +536,12 @@ static void ws_llc_mac_confirm_cb(const mac_api_t *api, const mcps_data_conf_t *
529536
ns_list_remove(&base->temp_entries->llc_eap_pending_list, message);
530537
ws_llc_mpx_eapol_send(base, message);
531538
}
539+
} else {
540+
if (neighbor_info.ws_neighbor && neighbor_info.neighbor && neighbor_info.neighbor->link_lifetime != WS_NEIGHBOR_LINK_TIMEOUT) {
541+
//Remove temp neighbour
542+
tr_debug("Remove Temp Entry by TX confirm");
543+
mac_neighbor_table_neighbor_remove(mac_neighbor_info(interface), neighbor_info.neighbor);
544+
}
532545
}
533546

534547
return;

source/Common_Protocols/icmpv6.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,7 @@ buffer_t *icmpv6_build_na(protocol_interface_info_entry_t *cur, bool solicited,
16481648
}
16491649
/* All other than ARO NA messages are omitted and MAC ACK is considered as success */
16501650
if (!tllao_required && (!aro && cur->ipv6_neighbour_cache.omit_na)) {
1651+
ws_common_link_temporary_remove(cur, src_addr);
16511652
return NULL;
16521653
}
16531654

0 commit comments

Comments
 (0)