Skip to content

Commit a524936

Browse files
author
Mika Leppänen
committed
Moved EAPOL relay port and IP address configuration to bootstrap
Modified EAPOL relay components (EAPOL relay, authenticator EAPOL relay KMP socket if, PAE authenticator) so that ports for different entities are configured by bootstrap. Also IP addresses for authenticator EAPOL relay and PAE KMP socket interface are now configurable (ready to be in different IP addresses) Removed security key setting from boostrap also in case PAE flags are not defined. In that case PEA controller inserts the security keys without security negotiations. Added and corrected comments on modules.
1 parent 68fa4f6 commit a524936

18 files changed

+539
-203
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
#include "6LoWPAN/ws/ws_pae_controller.h"
6666
#include "6LoWPAN/ws/ws_eapol_pdu.h"
6767
#include "6LoWPAN/ws/ws_eapol_auth_relay.h"
68-
#include "ws_eapol_relay.h"
68+
#include "6LoWPAN/ws/ws_eapol_relay.h"
6969

7070
#define TRACE_GROUP "wsbs"
7171

@@ -92,13 +92,8 @@ static uint16_t ws_bootstrap_routing_cost_calculate(protocol_interface_info_entr
9292
static uint16_t ws_bootstrap_rank_get(protocol_interface_info_entry_t *cur);
9393
static uint16_t ws_bootstrap_min_rank_inc_get(protocol_interface_info_entry_t *cur);
9494

95-
#if !defined(HAVE_PAE_SUPP) && !defined(HAVE_PAE_AUTH)
96-
static void ws_bootstrap_set_test_key(protocol_interface_info_entry_t *cur);
97-
#else
98-
#define ws_bootstrap_set_test_key(cur)
99-
#endif
100-
static void ws_bootstrap_key_insert(uint8_t gtk_index, uint8_t *gtk, protocol_interface_info_entry_t *cur);
101-
static void ws_bootstrap_authentication_completed(bool success, protocol_interface_info_entry_t *cur);
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);
10297

10398
mac_neighbor_table_entry_t *ws_bootstrap_mac_neighbor_add(struct protocol_interface_info_entry *interface, const uint8_t *src64)
10499

@@ -1588,7 +1583,8 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
15881583
dhcp_relay_agent_enable(cur->id, dodag_info.dodag_id);
15891584

15901585
tr_debug("Start EAPOL relay");
1591-
ws_eapol_relay_start(cur, dodag_info.dodag_id, 10253);
1586+
// Set both own port and border router port to 10253
1587+
ws_eapol_relay_start(cur, EAPOL_RELAY_SOCKET_PORT, dodag_info.dodag_id, EAPOL_RELAY_SOCKET_PORT);
15921588
}
15931589

15941590
ws_set_fhss_hop(cur);
@@ -1756,7 +1752,7 @@ static void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *c
17561752
}
17571753

17581754

1759-
static void ws_bootstrap_key_insert(uint8_t gtk_index, uint8_t *gtk, protocol_interface_info_entry_t *cur)
1755+
static void ws_bootstrap_key_insert(protocol_interface_info_entry_t *cur, uint8_t gtk_index, uint8_t *gtk)
17601756
{
17611757
// Convert GTK to Group AES Key (GAK)
17621758

@@ -1769,12 +1765,10 @@ static void ws_bootstrap_key_insert(uint8_t gtk_index, uint8_t *gtk, protocol_in
17691765
mac_helper_security_default_key_set(cur, gtk, gtk_index + 1, MAC_KEY_ID_MODE_IDX);
17701766
}
17711767

1772-
static void ws_bootstrap_authentication_completed(bool success, protocol_interface_info_entry_t *cur)
1768+
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, bool success)
17731769
{
17741770
if (success) {
17751771
tr_debug("authentication success");
1776-
ws_bootstrap_set_test_key(cur);
1777-
17781772
ws_bootstrap_event_configuration_start(cur);
17791773
} else {
17801774
tr_debug("authentication failed");
@@ -2002,21 +1996,6 @@ static bool ws_bootstrap_address_registration_ongoing(protocol_interface_info_en
20021996
return false;
20031997
}
20041998

2005-
#if !defined(HAVE_PAE_SUPP) && !defined(HAVE_PAE_AUTH)
2006-
static void ws_bootstrap_set_test_key(protocol_interface_info_entry_t *cur)
2007-
{
2008-
uint8_t key_material[16];
2009-
for (int i = 0; i < 16; i++) {
2010-
key_material[i] = 0xcf - i;
2011-
}
2012-
mac_helper_security_key_clean(cur);
2013-
mac_helper_default_security_level_set(cur, AES_SECURITY_LEVEL_ENC_MIC64);
2014-
mac_helper_default_security_key_id_mode_set(cur, MAC_KEY_ID_MODE_IDX);
2015-
//Set Keys
2016-
mac_helper_security_default_key_set(cur, key_material, 1, MAC_KEY_ID_MODE_IDX);
2017-
}
2018-
#endif
2019-
20201999
static void ws_bootstrap_event_handler(arm_event_s *event)
20212000
{
20222001
ws_bootsrap_event_type_e event_type;
@@ -2057,13 +2036,19 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
20572036
// Set default parameters for FHSS when starting a discovery
20582037
ws_fhss_border_router_configure(cur);
20592038
ws_bootstrap_fhss_activate(cur);
2060-
ws_bootstrap_set_test_key(cur);
20612039
ws_bootstrap_event_operation_start(cur);
20622040

2063-
ws_eapol_relay_start(cur, 0, 10255);
2064-
ws_eapol_auth_relay_start(cur);
2041+
uint8_t ll_addr[16];
2042+
addr_interface_get_ll_address(cur, ll_addr, 1);
2043+
2044+
// Set EAPOL relay to port 10255 and authenticator relay to 10253 (and to own ll address)
2045+
ws_eapol_relay_start(cur, BR_EAPOL_RELAY_SOCKET_PORT, ll_addr, EAPOL_RELAY_SOCKET_PORT);
2046+
2047+
// Set authenticator relay to port 10253 and PAE to 10254 (and to own ll address)
2048+
ws_eapol_auth_relay_start(cur, EAPOL_RELAY_SOCKET_PORT, ll_addr, PAE_AUTH_SOCKET_PORT);
20652049

2066-
ws_pae_controller_authenticator_start(cur);
2050+
// Set PAE port to 10254 and authenticator relay to 10253 (and to own ll address)
2051+
ws_pae_controller_authenticator_start(cur, PAE_AUTH_SOCKET_PORT, ll_addr, EAPOL_RELAY_SOCKET_PORT);
20672052
break;
20682053
}
20692054
// Configure LLC for network discovery

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_ */

source/6LoWPAN/ws/ws_eapol_auth_relay.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,30 @@
3838
#ifdef HAVE_WS
3939
#ifdef HAVE_PAE_AUTH
4040

41-
#define TRACE_GROUP "earl"
41+
#define TRACE_GROUP "wsar"
4242

4343
typedef struct {
4444
protocol_interface_info_entry_t *interface_ptr; /**< Interface pointer */
45+
ns_address_t remote_addr; /**< Remote address and port */
46+
ns_address_t relay_addr; /**< Relay address */
4547
int8_t socket_id; /**< Socket ID for relay */
4648
ns_list_link_t link; /**< Link */
4749
} eapol_auth_relay_t;
4850

4951
static eapol_auth_relay_t *ws_eapol_auth_relay_get(protocol_interface_info_entry_t *interface_ptr);
5052
static void ws_eapol_auth_relay_socket_cb(void *cb);
51-
static int8_t ws_eapol_auth_relay_send_to_kmp(const eapol_auth_relay_t *eapol_auth_relay, const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len);
53+
static int8_t ws_eapol_auth_relay_send_to_kmp(eapol_auth_relay_t *eapol_auth_relay, const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len);
5254

5355
static NS_LIST_DEFINE(eapol_auth_relay_list, eapol_auth_relay_t, link);
5456

55-
int8_t ws_eapol_auth_relay_start(protocol_interface_info_entry_t *interface_ptr)
57+
int8_t ws_eapol_auth_relay_start(protocol_interface_info_entry_t *interface_ptr, uint16_t local_port, const uint8_t *remote_addr, uint16_t remote_port)
5658
{
57-
if (!interface_ptr) {
59+
if (!interface_ptr || !remote_addr) {
5860
return -1;
5961
}
6062

6163
if (ws_eapol_auth_relay_get(interface_ptr)) {
62-
return -1;
64+
return 0;
6365
}
6466

6567
eapol_auth_relay_t *eapol_auth_relay = ns_dyn_mem_alloc(sizeof(eapol_auth_relay_t));
@@ -68,7 +70,12 @@ int8_t ws_eapol_auth_relay_start(protocol_interface_info_entry_t *interface_ptr)
6870
}
6971

7072
eapol_auth_relay->interface_ptr = interface_ptr;
71-
eapol_auth_relay->socket_id = socket_open(IPV6_NH_UDP, 10253, &ws_eapol_auth_relay_socket_cb);
73+
74+
eapol_auth_relay->remote_addr.type = ADDRESS_IPV6;
75+
memcpy(&eapol_auth_relay->relay_addr.address, remote_addr, 16);
76+
eapol_auth_relay->relay_addr.identifier = remote_port;
77+
78+
eapol_auth_relay->socket_id = socket_open(IPV6_NH_UDP, local_port, &ws_eapol_auth_relay_socket_cb);
7279
if (eapol_auth_relay->socket_id < 0) {
7380
ns_dyn_mem_free(eapol_auth_relay);
7481
return -1;
@@ -143,18 +150,19 @@ static void ws_eapol_auth_relay_socket_cb(void *cb)
143150
}
144151

145152
// Message from source port 10254 (KMP service) -> to IP relay on node or on authenticator
146-
if (src_addr.identifier == 10254) {
153+
if (src_addr.identifier == eapol_auth_relay->relay_addr.identifier) {
147154
uint8_t *ptr = socket_pdu;
148-
uint8_t *relay_ip_addr, *eui_64;
149-
uint16_t relay_port;
150-
relay_ip_addr = ptr;
155+
uint8_t *eui_64;
156+
ns_address_t relay_ip_addr;
157+
relay_ip_addr.type = ADDRESS_IPV6;
158+
memcpy(relay_ip_addr.address, ptr, 16);
151159
ptr += 16;
152-
relay_port = common_read_16_bit(ptr);
160+
relay_ip_addr.identifier = common_read_16_bit(ptr);
153161
ptr += 2;
154162
eui_64 = ptr;
155163
ptr += 8;
156164
uint16_t data_len = cb_data->d_len - 26;
157-
ws_eapol_relay_lib_send_to_relay(eapol_auth_relay->socket_id, eui_64, relay_ip_addr, relay_port,
165+
ws_eapol_relay_lib_send_to_relay(eapol_auth_relay->socket_id, eui_64, &relay_ip_addr,
158166
ptr, data_len);
159167
ns_dyn_mem_free(socket_pdu);
160168
// Other source port (either 10253 or node relay source port) -> to KMP service
@@ -166,13 +174,9 @@ static void ws_eapol_auth_relay_socket_cb(void *cb)
166174
}
167175
}
168176

169-
static int8_t ws_eapol_auth_relay_send_to_kmp(const eapol_auth_relay_t *eapol_auth_relay, const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len)
177+
static int8_t ws_eapol_auth_relay_send_to_kmp(eapol_auth_relay_t *eapol_auth_relay, const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len)
170178
{
171-
ns_address_t dest_addr;
172-
173-
if (ws_eapol_relay_lib_ll_address_get(eapol_auth_relay->interface_ptr, &dest_addr) < 0) {
174-
return -1;
175-
}
179+
ns_address_t dest_addr = eapol_auth_relay->relay_addr;
176180

177181
uint8_t temp_array[26];
178182
ns_iovec_t msg_iov[2];

source/6LoWPAN/ws/ws_eapol_auth_relay.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,43 @@
2020

2121
#ifdef HAVE_PAE_AUTH
2222

23-
int8_t ws_eapol_auth_relay_start(protocol_interface_info_entry_t *interface_ptr);
23+
/*
24+
* EAPOL authenticator relay acts as a proxy between EAPOL UDP relay and
25+
* authenticator PAE (KMP service). Relay is bound by default to EAPOL UDP
26+
* relay port 10253 (set by local port parameter) and transfers messages
27+
* to/from authenticator PAE. As default PAE is bound to UDP port 10254
28+
* (set by remote address and port parameters).
29+
*
30+
*/
31+
32+
/**
33+
* ws_eapol_auth_relay_start start authenticator relay
34+
*
35+
* \param interface_ptr interface
36+
* \param local_port local port
37+
* \param remote_addr remote address
38+
* \param remote_port remote port
39+
*
40+
* \return < 0 failure
41+
* \return >= 0 success
42+
*
43+
*/
44+
int8_t ws_eapol_auth_relay_start(protocol_interface_info_entry_t *interface_ptr, uint16_t local_port, const uint8_t *remote_addr, uint16_t remote_port);
45+
46+
/**
47+
* ws_eapol_auth_relay_delete delete authenticator relay
48+
*
49+
* \param interface_ptr interface
50+
*
51+
* \return < 0 failure
52+
* \return >= 0 success
53+
*
54+
*/
2455
int8_t ws_eapol_auth_relay_delete(protocol_interface_info_entry_t *interface_ptr);
2556

2657
#else
2758

28-
#define ws_eapol_auth_relay_start(interface_ptr)
59+
#define ws_eapol_auth_relay_start(interface_ptr, local_port, remote_addr, remote_port)
2960
#define ws_eapol_auth_relay_delete(interface_ptr)
3061

3162
#endif

source/6LoWPAN/ws/ws_eapol_pdu.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
#ifdef HAVE_WS
3636

37-
#define TRACE_GROUP "wsepdu"
37+
#define TRACE_GROUP "wsep"
3838

3939
typedef struct {
4040
uint8_t handle;
@@ -79,7 +79,7 @@ int8_t ws_eapol_pdu_init(protocol_interface_info_entry_t *interface_ptr)
7979
}
8080

8181
if (ws_eapol_pdu_data_get(interface_ptr) != NULL) {
82-
return -1;
82+
return 0;
8383
}
8484

8585
eapol_pdu_data_t *eapol_pdu_data = ns_dyn_mem_alloc(sizeof(eapol_pdu_data_t));
@@ -180,7 +180,7 @@ int8_t ws_eapol_pdu_cb_unregister(protocol_interface_info_entry_t *interface_ptr
180180
return -1;
181181
}
182182

183-
int8_t ws_eapol_pdu_send_to_mpx(protocol_interface_info_entry_t *interface_ptr, const uint8_t *eui_64, void *data, uint16_t data_len, void *buffer)
183+
int8_t ws_eapol_pdu_send_to_mpx(protocol_interface_info_entry_t *interface_ptr, const uint8_t *eui_64, void *data, uint16_t size, void *buffer)
184184
{
185185
eapol_pdu_data_t *eapol_pdu_data = ws_eapol_pdu_data_get(interface_ptr);
186186

@@ -193,7 +193,6 @@ int8_t ws_eapol_pdu_send_to_mpx(protocol_interface_info_entry_t *interface_ptr,
193193

194194
eapol_pdu_msdu_t *msdu_entry = ns_dyn_mem_temporary_alloc(sizeof(eapol_pdu_msdu_t));
195195
if (!msdu_entry) {
196-
ns_dyn_mem_free(buffer);
197196
return -1;
198197
}
199198
msdu_entry->data_ptr = data;
@@ -203,7 +202,7 @@ int8_t ws_eapol_pdu_send_to_mpx(protocol_interface_info_entry_t *interface_ptr,
203202

204203
memcpy(data_request.DstAddr, eui_64, 8);
205204
data_request.msdu = data;
206-
data_request.msduLength = data_len;
205+
data_request.msduLength = size;
207206

208207
eapol_pdu_data->mpx_api->mpx_data_request(eapol_pdu_data->mpx_api, &data_request, eapol_pdu_data->mpx_user_id);
209208
return 0;

0 commit comments

Comments
 (0)