Skip to content

Commit ae8ae32

Browse files
author
Juha Heiskanen
committed
EAPOL relay agent rx filter from joiner side
Relay agent will drop same mac identifier if it rx in 5 seconds period. MAC data sequency number is allocated to data request only 1 time now.
1 parent 0d4eb7a commit ae8ae32

File tree

8 files changed

+64
-6
lines changed

8 files changed

+64
-6
lines changed

source/6LoWPAN/ws/ws_eapol_pdu.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "6LoWPAN/MAC/mpx_api.h"
3232
#include "6LoWPAN/ws/ws_config.h"
3333
#include "6LoWPAN/ws/ws_eapol_pdu.h"
34+
#include "6LoWPAN/ws/ws_llc.h"
3435

3536
#ifdef HAVE_WS
3637

@@ -49,6 +50,7 @@ typedef NS_LIST_HEAD(eapol_pdu_msdu_t, link) eapol_pdu_msdu_list_t;
4950

5051
typedef struct {
5152
uint8_t priority;
53+
bool filter_requsted: 1;
5254
ws_eapol_pdu_address_check *addr_check;
5355
ws_eapol_pdu_receive *receive;
5456
ns_list_link_t link;
@@ -147,6 +149,7 @@ int8_t ws_eapol_pdu_cb_register(protocol_interface_info_entry_t *interface_ptr,
147149
new_cb->priority = cb_data->priority;
148150
new_cb->addr_check = cb_data->addr_check;
149151
new_cb->receive = cb_data->receive;
152+
new_cb->filter_requsted = cb_data->filter_requsted;
150153

151154
ns_list_foreach(eapol_pdu_recv_cb_t, entry, &eapol_pdu_data->recv_cb_list) {
152155
if (new_cb->priority <= entry->priority) {
@@ -307,6 +310,11 @@ static void ws_eapol_pdu_mpx_data_indication(const mpx_api_t *api, const struct
307310

308311
ns_list_foreach(eapol_pdu_recv_cb_t, entry, &eapol_pdu_data->recv_cb_list) {
309312
if (entry->addr_check(eapol_pdu_data->interface_ptr, data->SrcAddr) >= 0) {
313+
if (entry->filter_requsted && !ws_llc_eapol_relay_forward_filter(eapol_pdu_data->interface_ptr, data->SrcAddr, data->DSN)) {
314+
tr_info("EAPOL relay filter drop");
315+
return;
316+
}
317+
310318
entry->receive(eapol_pdu_data->interface_ptr, data->SrcAddr, data->msdu_ptr, data->msduLength);
311319
break;
312320
}

source/6LoWPAN/ws/ws_eapol_pdu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ typedef enum {
9999

100100
typedef struct {
101101
eapol_pdu_recv_prior_t priority; /**< Priority: high, medium or low */
102+
bool filter_requsted: 1; /**< True when EAPOL temporary filter requsted, false for normal functionality */
102103
ws_eapol_pdu_address_check *addr_check; /**< Address check callback */
103104
ws_eapol_pdu_receive *receive; /**< PDU receive callback */
104105
} eapol_pdu_recv_cb_data_t;

source/6LoWPAN/ws/ws_eapol_relay.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static void ws_eapol_relay_socket_cb(void *cb);
5353

5454
static const eapol_pdu_recv_cb_data_t eapol_pdu_recv_cb_data = {
5555
.priority = EAPOL_PDU_RECV_LOW_PRIORITY,
56+
.filter_requsted = true,
5657
.addr_check = ws_eapol_relay_eapol_pdu_address_check,
5758
.receive = ws_eapol_relay_eapol_pdu_receive
5859
};

source/6LoWPAN/ws/ws_llc.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,21 @@ typedef struct llc_neighbour_req {
7878
struct ws_neighbor_class_entry *ws_neighbor; /**< Wi-sun Neighbor information entry. */
7979
} llc_neighbour_req_t;
8080

81+
typedef struct eapol_temporary_info_s {
82+
uint8_t eapol_rx_relay_filter; /*!< seconds for dropping duplicate id */
83+
uint8_t last_rx_mac_sequency; /*!< Only compared when Timer is active */
84+
uint16_t eapol_timeout; /*!< EAPOL relay Temporary entry lifetime */
85+
} eapol_temporary_info_t;
86+
8187
/**
8288
* Neighbor temporary structure for storage FHSS data before create a real Neighbour info
8389
*/
8490
typedef struct ws_neighbor_temp_class_s {
8591
struct ws_neighbor_class_entry neigh_info_list; /*!< Allocated hopping info array*/
92+
eapol_temporary_info_t eapol_temp_info;
8693
uint8_t mac64[8];
8794
uint8_t mpduLinkQuality;
8895
int8_t signal_dbm;
89-
uint16_t eapol_timeout;
9096
ns_list_link_t link;
9197
} ws_neighbor_temp_class_t;
9298

@@ -220,6 +226,8 @@ void ws_llc_hopping_schedule_config(struct protocol_interface_info_entry *interf
220226

221227
void ws_llc_timer_seconds(struct protocol_interface_info_entry *interface, uint16_t seconds_update);
222228

229+
bool ws_llc_eapol_relay_forward_filter(struct protocol_interface_info_entry *interface, const uint8_t *joiner_eui64, uint8_t mac_sequency);
230+
223231
ws_neighbor_temp_class_t *ws_llc_get_multicast_temp_entry(struct protocol_interface_info_entry *interface, const uint8_t *mac64);
224232

225233
void ws_llc_free_multicast_temp_entry(struct protocol_interface_info_entry *interface, ws_neighbor_temp_class_t *neighbor);

source/6LoWPAN/ws/ws_llc_data_service.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static void ws_llc_mac_confirm_cb(const mac_api_t *api, const mcps_data_conf_t *
431431
ws_neighbor_temp_class_t *temp_entry = ws_llc_discover_eapol_temp_entry(base->temp_entries, message->dst_address);
432432
if (temp_entry) {
433433
//Update Temporary Lifetime
434-
temp_entry->eapol_timeout = interface->ws_info->cfg->timing.temp_eapol_min_timeout + 1;
434+
temp_entry->eapol_temp_info.eapol_timeout = interface->ws_info->cfg->timing.temp_eapol_min_timeout + 1;
435435
}
436436
}
437437
}
@@ -740,7 +740,7 @@ static void ws_llc_eapol_indication_cb(const mac_api_t *api, const mcps_data_ind
740740
return;
741741
}
742742
//Update Temporary Lifetime
743-
temp_entry->eapol_timeout = interface->ws_info->cfg->timing.temp_eapol_min_timeout + 1;
743+
temp_entry->eapol_temp_info.eapol_timeout = interface->ws_info->cfg->timing.temp_eapol_min_timeout + 1;
744744

745745
neighbor_info.ws_neighbor = &temp_entry->neigh_info_list;
746746
//Storage Signal info for future ETX update possibility
@@ -1329,6 +1329,7 @@ static void ws_init_temporary_neigh_data(ws_neighbor_temp_class_t *entry, const
13291329
entry->neigh_info_list.rsl_in = RSL_UNITITIALIZED;
13301330
entry->neigh_info_list.rsl_out = RSL_UNITITIALIZED;
13311331
memcpy(entry->mac64, mac64, 8);
1332+
entry->eapol_temp_info.eapol_rx_relay_filter = 0;
13321333
}
13331334

13341335

@@ -1653,13 +1654,46 @@ void ws_llc_timer_seconds(struct protocol_interface_info_entry *interface, uint1
16531654
}
16541655

16551656
ns_list_foreach_safe(ws_neighbor_temp_class_t, entry, &base->temp_entries->active_eapol_temp_neigh) {
1656-
if (entry->eapol_timeout <= seconds_update) {
1657+
if (entry->eapol_temp_info.eapol_timeout <= seconds_update) {
16571658
ns_list_remove(&base->temp_entries->active_eapol_temp_neigh, entry);
16581659
ns_list_add_to_end(&base->temp_entries->free_temp_neigh, entry);
16591660
} else {
1660-
entry->eapol_timeout -= seconds_update;
1661+
entry->eapol_temp_info.eapol_timeout -= seconds_update;
1662+
if (entry->eapol_temp_info.eapol_rx_relay_filter == 0) {
1663+
//No active filter period
1664+
continue;
1665+
}
1666+
1667+
//Update filter time
1668+
if (entry->eapol_temp_info.eapol_rx_relay_filter <= seconds_update) {
1669+
entry->eapol_temp_info.eapol_rx_relay_filter = 0;
1670+
} else {
1671+
entry->eapol_temp_info.eapol_rx_relay_filter -= seconds_update;
1672+
}
16611673
}
16621674
}
16631675
}
16641676

1677+
bool ws_llc_eapol_relay_forward_filter(struct protocol_interface_info_entry *interface, const uint8_t *joiner_eui64, uint8_t mac_sequency)
1678+
{
1679+
llc_data_base_t *base = ws_llc_discover_by_interface(interface);
1680+
if (!base) {
1681+
return false;
1682+
}
1683+
1684+
ws_neighbor_temp_class_t *neighbor = ws_llc_discover_eapol_temp_entry(base->temp_entries, joiner_eui64);
1685+
if (!neighbor) {
1686+
return false;
1687+
}
1688+
1689+
if (neighbor->eapol_temp_info.eapol_rx_relay_filter && neighbor->eapol_temp_info.last_rx_mac_sequency == mac_sequency) {
1690+
return false;
1691+
}
1692+
neighbor->eapol_temp_info.last_rx_mac_sequency = mac_sequency;
1693+
neighbor->eapol_temp_info.eapol_rx_relay_filter = 6; //Activate 5-5.99 seconds filter time
1694+
return true;
1695+
1696+
}
1697+
1698+
16651699
#endif

source/6LoWPAN/ws/ws_pae_supp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ static void ws_pae_supp_kmp_api_finished(kmp_api_t *kmp);
157157

158158
static const eapol_pdu_recv_cb_data_t eapol_pdu_recv_cb_data = {
159159
.priority = EAPOL_PDU_RECV_HIGH_PRIORITY,
160+
.filter_requsted = false,
160161
.addr_check = ws_pae_supp_eapol_pdu_address_check,
161162
.receive = kmp_eapol_pdu_if_receive
162163
};

source/MAC/IEEE802_15_4/mac_data_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef struct mac_pre_build_frame {
9797
bool mac_allocated_payload_ptr: 1;
9898
bool asynch_request: 1;
9999
bool message_builded: 1;
100+
bool DSN_allocated: 1;
100101
unsigned security_mic_len: 5; //Max possible lengths 0, 4, 8, 16 bytes
101102
unsigned priority: 2;
102103
struct mac_pre_build_frame *next; //Pointer for queue purpose

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ mac_pre_build_frame_t *mcps_sap_prebuild_frame_buffer_get(uint16_t payload_size)
12261226
memset(buffer, 0, sizeof(mac_pre_build_frame_t));
12271227
buffer->initial_tx_channel = 0xffff;
12281228
buffer->aux_header.frameCounter = 0xffffffff;
1229+
buffer->DSN_allocated = false;
12291230
if (payload_size) {
12301231
//Mac interlnal payload allocate
12311232
buffer->mac_payload = ns_dyn_mem_temporary_alloc(payload_size);
@@ -1502,7 +1503,10 @@ static void mcps_generic_sequence_number_allocate(protocol_interface_rf_mac_setu
15021503
switch (buffer->fcf_dsn.frametype) {
15031504
case MAC_FRAME_CMD:
15041505
case MAC_FRAME_DATA:
1505-
buffer->fcf_dsn.DSN = mac_mlme_set_new_sqn(rf_ptr);
1506+
if (!buffer->DSN_allocated) {
1507+
buffer->fcf_dsn.DSN = mac_mlme_set_new_sqn(rf_ptr);
1508+
buffer->DSN_allocated = true;
1509+
}
15061510
break;
15071511
case MAC_FRAME_BEACON:
15081512
buffer->fcf_dsn.DSN = mac_mlme_set_new_beacon_sqn(rf_ptr);

0 commit comments

Comments
 (0)