Skip to content

Commit 28d10d6

Browse files
author
Mika Leppänen
authored
Merge pull request #1901 from ARMmbed/kmp_pae_init
Initial EAPOL changes
2 parents 6e063b6 + 3f56121 commit 28d10d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+10566
-19
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 105 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
#include "DHCPv6_client/dhcpv6_client_api.h"
6363
#include "net_rpl.h"
6464
#include "mac_api.h"
65+
#include "6LoWPAN/ws/ws_pae_controller.h"
66+
#include "6LoWPAN/ws/ws_eapol_pdu.h"
67+
#include "6LoWPAN/ws/ws_eapol_auth_relay.h"
68+
#include "6LoWPAN/ws/ws_eapol_relay.h"
6569

6670
#define TRACE_GROUP "wsbs"
6771

@@ -88,7 +92,11 @@ static uint16_t ws_bootstrap_routing_cost_calculate(protocol_interface_info_entr
8892
static uint16_t ws_bootstrap_rank_get(protocol_interface_info_entry_t *cur);
8993
static uint16_t ws_bootstrap_min_rank_inc_get(protocol_interface_info_entry_t *cur);
9094

95+
static void ws_bootstrap_key_insert(protocol_interface_info_entry_t *cur, uint8_t gtk_index, uint8_t *gtk);
96+
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, bool success);
97+
9198
mac_neighbor_table_entry_t *ws_bootstrap_mac_neighbor_add(struct protocol_interface_info_entry *interface, const uint8_t *src64)
99+
92100
{
93101
mac_neighbor_table_entry_t *neighbor = mac_neighbor_table_address_discover(mac_neighbor_info(interface), src64, MAC_ADDR_MODE_64_BIT);
94102
if (neighbor) {
@@ -667,6 +675,9 @@ static int8_t ws_bootstrap_down(protocol_interface_info_entry_t *cur)
667675
nd_proxy_downstream_interface_unregister(cur->id);
668676
ws_nud_table_reset(cur);
669677
dhcp_client_delete(cur->id);
678+
ws_eapol_relay_delete(cur);
679+
ws_eapol_auth_relay_delete(cur);
680+
ws_pae_controller_stop(cur);
670681

671682
return nwk_6lowpan_down(cur);
672683
}
@@ -1404,6 +1415,26 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
14041415
goto init_fail;
14051416
}
14061417

1418+
//Init PAE controller and set callback
1419+
if (ws_pae_controller_init(cur) < 0) {
1420+
ret_val = -4;
1421+
goto init_fail;
1422+
}
1423+
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_key_insert) < 0) {
1424+
ret_val = -4;
1425+
goto init_fail;
1426+
}
1427+
1428+
//Init EAPOL PDU handler and register it to MPX
1429+
if (ws_eapol_pdu_init(cur) < 0) {
1430+
ret_val = -4;
1431+
goto init_fail;
1432+
}
1433+
if (ws_eapol_pdu_mpx_register(cur, mpx_api, MPX_KEY_MANAGEMENT_ENC_USER_ID != 0)) {
1434+
ret_val = -4;
1435+
// add deallocs
1436+
goto init_fail;
1437+
}
14071438

14081439
cur->if_up = ws_bootstrap_up;
14091440
cur->if_down = ws_bootstrap_down;
@@ -1445,10 +1476,13 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
14451476
//Error handling and free memory
14461477
init_fail:
14471478
lowpan_adaptation_interface_mpx_register(interface_id, NULL, 0);
1479+
ws_eapol_pdu_mpx_register(cur, NULL, 0);
14481480
mac_neighbor_table_delete(mac_neighbor_info(cur));
14491481
etx_storage_list_allocate(cur->id, 0);
14501482
ws_neighbor_class_dealloc(&neigh_info);
14511483
ws_llc_delete(cur);
1484+
ws_eapol_pdu_delete(cur);
1485+
ws_pae_controller_delete(cur);
14521486
return ret_val;
14531487
}
14541488

@@ -1591,6 +1625,10 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
15911625
if (instance && rpl_control_read_dodag_info(instance, &dodag_info)) {
15921626
tr_debug("Enable DHCPv6 relay");
15931627
dhcp_relay_agent_enable(cur->id, dodag_info.dodag_id);
1628+
1629+
tr_debug("Start EAPOL relay");
1630+
// Set both own port and border router port to 10253
1631+
ws_eapol_relay_start(cur, EAPOL_RELAY_SOCKET_PORT, dodag_info.dodag_id, EAPOL_RELAY_SOCKET_PORT);
15941632
}
15951633

15961634
ws_set_fhss_hop(cur);
@@ -1750,6 +1788,40 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
17501788
// Discovery statemachine is checkked after two trickle interval
17511789
cur->bootsrap_state_machine_cnt = 2 * trickle_params_pan_discovery.Imin + randLIB_get_8bit() % 50;
17521790
}
1791+
1792+
// Start authentication
1793+
static void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *cur)
1794+
{
1795+
tr_debug("authentication start");
1796+
ws_pae_controller_authenticate(cur);
1797+
}
1798+
1799+
1800+
static void ws_bootstrap_key_insert(protocol_interface_info_entry_t *cur, uint8_t gtk_index, uint8_t *gtk)
1801+
{
1802+
// Convert GTK to Group AES Key (GAK)
1803+
1804+
// Verify HASH etc.
1805+
1806+
mac_helper_security_key_clean(cur);
1807+
mac_helper_default_security_level_set(cur, AES_SECURITY_LEVEL_ENC_MIC64);
1808+
mac_helper_default_security_key_id_mode_set(cur, MAC_KEY_ID_MODE_IDX);
1809+
//Set Keys
1810+
mac_helper_security_default_key_set(cur, gtk, gtk_index + 1, MAC_KEY_ID_MODE_IDX);
1811+
}
1812+
1813+
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, bool success)
1814+
{
1815+
if (success) {
1816+
tr_debug("authentication success");
1817+
ws_bootstrap_event_configuration_start(cur);
1818+
} else {
1819+
tr_debug("authentication failed");
1820+
// What else to do to start over again...
1821+
ws_bootstrap_event_discovery_start(cur);
1822+
}
1823+
}
1824+
17531825
// Start configuration learning
17541826
static void ws_bootstrap_start_configuration_learn(protocol_interface_info_entry_t *cur)
17551827
{
@@ -1758,6 +1830,7 @@ static void ws_bootstrap_start_configuration_learn(protocol_interface_info_entry
17581830

17591831
cur->ws_info->configuration_learned = false;
17601832
// Clear parent info
1833+
17611834
memset(cur->ws_info->parent_info.addr, 0, 8);
17621835

17631836
// Clear all temporary information
@@ -1968,19 +2041,6 @@ static bool ws_bootstrap_address_registration_ongoing(protocol_interface_info_en
19682041
return false;
19692042
}
19702043

1971-
static void ws_bootstrap_set_test_key(protocol_interface_info_entry_t *cur)
1972-
{
1973-
uint8_t key_material[16];
1974-
for (int i = 0; i < 16; i++) {
1975-
key_material[i] = 0xcf - i;
1976-
}
1977-
mac_helper_security_key_clean(cur);
1978-
mac_helper_default_security_level_set(cur, AES_SECURITY_LEVEL_ENC_MIC64);
1979-
mac_helper_default_security_key_id_mode_set(cur, MAC_KEY_ID_MODE_IDX);
1980-
//Set Keys
1981-
mac_helper_security_default_key_set(cur, key_material, 1, MAC_KEY_ID_MODE_IDX);
1982-
}
1983-
19842044
static void ws_bootstrap_event_handler(arm_event_s *event)
19852045
{
19862046
ws_bootsrap_event_type_e event_type;
@@ -2021,8 +2081,19 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
20212081
// Set default parameters for FHSS when starting a discovery
20222082
ws_fhss_border_router_configure(cur);
20232083
ws_bootstrap_fhss_activate(cur);
2024-
ws_bootstrap_set_test_key(cur);
20252084
ws_bootstrap_event_operation_start(cur);
2085+
2086+
uint8_t ll_addr[16];
2087+
addr_interface_get_ll_address(cur, ll_addr, 1);
2088+
2089+
// Set EAPOL relay to port 10255 and authenticator relay to 10253 (and to own ll address)
2090+
ws_eapol_relay_start(cur, BR_EAPOL_RELAY_SOCKET_PORT, ll_addr, EAPOL_RELAY_SOCKET_PORT);
2091+
2092+
// Set authenticator relay to port 10253 and PAE to 10254 (and to own ll address)
2093+
ws_eapol_auth_relay_start(cur, EAPOL_RELAY_SOCKET_PORT, ll_addr, PAE_AUTH_SOCKET_PORT);
2094+
2095+
// Set PAE port to 10254 and authenticator relay to 10253 (and to own ll address)
2096+
ws_pae_controller_authenticator_start(cur, PAE_AUTH_SOCKET_PORT, ll_addr, EAPOL_RELAY_SOCKET_PORT);
20262097
break;
20272098
}
20282099
// Configure LLC for network discovery
@@ -2036,9 +2107,17 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
20362107
// only advert sol stopped as we might be doing re authentication
20372108
cur->ws_info->trickle_pas_running = false;
20382109
//Add Test ecurity key and security level's
2039-
ws_bootstrap_set_test_key(cur);
2040-
ws_bootstrap_event_configuration_start(cur);
2110+
2111+
2112+
// Advertisements stopped during the EAPOL
2113+
cur->ws_info->trickle_pa_running = false;
2114+
cur->ws_info->trickle_pc_running = false;
2115+
cur->ws_info->trickle_pas_running = false;
2116+
cur->ws_info->trickle_pcs_running = false;
2117+
2118+
ws_bootstrap_start_authentication(cur);
20412119
break;
2120+
20422121
case WS_CONFIGURATION_START:
20432122
tr_info("Configuration start");
20442123
// Old configuration is considered invalid stopping all
@@ -2114,8 +2193,14 @@ void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur)
21142193
return;
21152194
}
21162195

2196+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &cur->ws_info->parent_info.ws_utt, cur->ws_info->parent_info.timestamp);
2197+
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, &cur->ws_info->parent_info.ws_us);
2198+
2199+
21172200
ws_bootstrap_network_information_learn(cur);
21182201
ws_bootstrap_fhss_activate(cur);
2202+
2203+
ws_pae_controller_set_target(cur, cur->ws_info->parent_info.addr); // temporary!!! store since auth
21192204
ws_bootstrap_event_authentication_start(cur);
21202205
return;
21212206
}
@@ -2125,7 +2210,11 @@ void ws_bootstrap_configure_process(protocol_interface_info_entry_t *cur)
21252210

21262211
if (cur->ws_info->configuration_learned) {
21272212
ws_bootstrap_network_configuration_learn(cur);
2213+
2214+
21282215
ws_bootstrap_event_operation_start(cur);
2216+
2217+
21292218
return;
21302219
}
21312220
return;

source/6LoWPAN/ws/ws_common_defines.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,11 @@ typedef struct ws_bs_ie {
227227
#define WS_FHSS_BC_INTERVAL 1020;
228228
#define WS_FHSS_BC_DWELL_INTERVAL 255;
229229

230+
/*
231+
* EAPOL relay and PAE authenticator socket settings
232+
*/
233+
#define EAPOL_RELAY_SOCKET_PORT 10253
234+
#define BR_EAPOL_RELAY_SOCKET_PORT 10255
235+
#define PAE_AUTH_SOCKET_PORT 10254
230236

231237
#endif /* WS_COMMON_DEFINES_H_ */

0 commit comments

Comments
 (0)