Skip to content

Commit da15653

Browse files
author
Mika Leppänen
committed
EAPOL relay and KMP changes
- changed supplicant relay to send/receive pdu's directly to KMP without socket - added address parameter to KMP interface - split relay to supplicant and autenticator parts - added EAPOL PDU module where the supplicant and autenticator relay register to
1 parent fad633f commit da15653

28 files changed

+1475
-405
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
#include "net_rpl.h"
6464
#include "mac_api.h"
6565
#include "6LoWPAN/ws/ws_pae_controller.h"
66-
#include "6LoWPAN/ws/ws_eapol_relay.h"
66+
#include "6LoWPAN/ws/ws_eapol_pdu.h"
67+
#include "6LoWPAN/ws/ws_eapol_auth_relay.h"
68+
#include "6LoWPAN/ws/ws_eapol_supp_relay.h"
6769

6870
#define TRACE_GROUP "wsbs"
6971

@@ -1370,9 +1372,9 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
13701372
ws_pae_controller_init(cur);
13711373
ws_pae_controller_cb_register(&ws_bootstrap_authentication_completed);
13721374

1373-
//Init EAPOL relay and register it to MPX
1374-
ws_eapol_relay_init(cur);
1375-
if (ws_eapol_relay_mpx_register(mpx_api, MPX_KEY_MANAGEMENT_ENC_USER_ID != 0)) {
1375+
//Init EAPOL PDU handler and register it to MPX
1376+
ws_eapol_pdu_init(cur);
1377+
if (ws_eapol_pdu_mpx_register(mpx_api, MPX_KEY_MANAGEMENT_ENC_USER_ID != 0)) {
13761378
ret_val = -4;
13771379
// add deallocs
13781380
goto init_fail;
@@ -2018,6 +2020,8 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
20182020
ws_bootstrap_set_test_key(cur);
20192021
ws_bootstrap_event_operation_start(cur);
20202022

2023+
ws_eapol_auth_relay_init(cur);
2024+
ws_eapol_auth_relay_start();
20212025
ws_pae_controller_authenticator_start();
20222026
break;
20232027
}
@@ -2083,6 +2087,12 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
20832087
cur->ws_info->trickle_pcs_running = false;
20842088

20852089
ws_bootstrap_advertise_start(cur);
2090+
2091+
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
2092+
ws_eapol_supp_relay_init(cur);
2093+
ws_eapol_supp_relay_start();
2094+
}
2095+
20862096
ws_bootstrap_state_change(cur, ER_BOOTSRAP_DONE);
20872097
break;
20882098
case WS_ADDRESS_ADDED:
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Copyright (c) 2016-2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
#include "nsconfig.h"
20+
#include <string.h>
21+
#include "ns_types.h"
22+
#include "ns_list.h"
23+
#include "ns_trace.h"
24+
#include "nsdynmemLIB.h"
25+
#include "fhss_config.h"
26+
#include "NWK_INTERFACE/Include/protocol.h"
27+
#include "mac_api.h"
28+
#include "mac_mcps.h"
29+
#include "Common_Protocols/ipv6_constants.h"
30+
#include "socket_api.h"
31+
#include "6LoWPAN/MAC/mac_helper.h"
32+
#include "6LoWPAN/MAC/mpx_api.h"
33+
#include "6LoWPAN/ws/ws_config.h"
34+
#include "6LoWPAN/ws/ws_eapol_pdu.h"
35+
#include "6LoWPAN/ws/ws_eapol_relay.h"
36+
#include "6LoWPAN/ws/ws_eapol_auth_relay.h"
37+
#include "Security/kmp/kmp_socket_api.h"
38+
39+
#ifdef HAVE_WS
40+
41+
#define TRACE_GROUP "wspsu"
42+
43+
static int8_t ws_eapol_auth_relay_eapol_pdu_address_check(const uint8_t *eui_64);
44+
static int8_t ws_eapol_auth_relay_eapol_pdu_receive(const uint8_t *eui_64, const void *pdu, uint16_t size);
45+
static int8_t ws_eapol_auth_relay_socket_pdu_receive(const ns_address_t *src_addr, void *data, uint16_t len);
46+
static int8_t ws_eapol_auth_relay_send_to_kmp(const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len);
47+
48+
// Wi-Sun EAPOL relay UDP data format
49+
typedef struct {
50+
uint8_t eui_64[8]; /**< Supplicant EUI-64 */
51+
uint8_t kmp_id; /**< KMP id */
52+
} eapol_relay_udp_pdu_t;
53+
54+
int8_t ws_eapol_auth_relay_init(protocol_interface_info_entry_t *interface_ptr)
55+
{
56+
ws_eapol_relay_init(interface_ptr);
57+
ws_eapol_relay_cb_register(ws_eapol_auth_relay_socket_pdu_receive);
58+
59+
eapol_pdu_recv_cb_data_t cb_data;
60+
cb_data.priority = EAPOL_PDU_RECV_LOW_PRIORITY;
61+
cb_data.addr_check = ws_eapol_auth_relay_eapol_pdu_address_check;
62+
cb_data.receive = ws_eapol_auth_relay_eapol_pdu_receive;
63+
64+
if (ws_eapol_pdu_cb_register(&cb_data) < 0) {
65+
return -1;
66+
}
67+
68+
return 0;
69+
}
70+
71+
int8_t ws_eapol_auth_relay_start(void)
72+
{
73+
return 0;
74+
}
75+
76+
static int8_t ws_eapol_auth_relay_eapol_pdu_address_check(const uint8_t *eui_64)
77+
{
78+
(void) eui_64;
79+
80+
// Low priority, always route all here if asked
81+
return 0;
82+
}
83+
84+
static int8_t ws_eapol_auth_relay_eapol_pdu_receive(const uint8_t *eui_64, const void *pdu, uint16_t size)
85+
{
86+
ws_eapol_auth_relay_send_to_kmp(eui_64, ADDR_UNSPECIFIED, 0, pdu, size);
87+
return 0;
88+
}
89+
90+
static int8_t ws_eapol_auth_relay_socket_pdu_receive(const ns_address_t *src_addr, void *data, uint16_t len)
91+
{
92+
int8_t res = 0;
93+
94+
// KMP message from source port 10254
95+
if (src_addr->identifier == 10254) {
96+
kmp_udp_pdu_t *pdu = data;
97+
uint16_t data_len = len - sizeof(kmp_udp_pdu_t) + 2 * sizeof(uint8_t);
98+
99+
// KMP protocol to relay -> packet with IP relay address -> to IP relay of node
100+
if (memcmp(pdu->relay_ip_addr, ADDR_UNSPECIFIED, 16) != 0) {
101+
res = ws_eapol_relay_send_to_relay(pdu->eui_64, pdu->relay_ip_addr, pdu->relay_port,
102+
&pdu->kmp_id, data_len);
103+
ns_dyn_mem_free(pdu);
104+
105+
// KMP protocol to relay -> no IP relay address -> to MPX
106+
} else {
107+
void *eapol_pdu = ns_dyn_mem_temporary_alloc(data_len);
108+
if (!eapol_pdu) {
109+
ns_dyn_mem_free(pdu);
110+
return -1;
111+
}
112+
memcpy(eapol_pdu, &pdu->kmp_id, data_len);
113+
114+
res = ws_eapol_pdu_send_to_mpx(pdu->eui_64, eapol_pdu, data_len);
115+
ns_dyn_mem_free(pdu);
116+
}
117+
118+
// Other source port (either 10253 or node relay source port)
119+
} else {
120+
eapol_relay_udp_pdu_t *pdu = data;
121+
uint16_t data_len = len - sizeof(eapol_relay_udp_pdu_t) + sizeof(uint8_t);
122+
res = ws_eapol_auth_relay_send_to_kmp(pdu->eui_64, src_addr->address, src_addr->identifier,
123+
&pdu->kmp_id, data_len);
124+
ns_dyn_mem_free(pdu);
125+
}
126+
127+
return res;
128+
}
129+
130+
static int8_t ws_eapol_auth_relay_send_to_kmp(const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len)
131+
{
132+
uint16_t pdu_len = data_len + sizeof(kmp_udp_pdu_t) - 2 * sizeof(uint8_t);
133+
kmp_udp_pdu_t *pdu = ns_dyn_mem_temporary_alloc(pdu_len);
134+
if (!pdu) {
135+
return -1;
136+
}
137+
138+
memcpy(pdu->relay_ip_addr, ip_addr, 16);
139+
pdu->relay_port = port;
140+
141+
memcpy(&pdu->eui_64[0], eui_64, 8);
142+
memcpy(&pdu->kmp_id, data, data_len);
143+
144+
ns_address_t dest_addr;
145+
if (ws_eapol_relay_kmp_ll_address_get(&dest_addr) < 0) {
146+
ns_dyn_mem_free(pdu);
147+
return -1;
148+
}
149+
150+
ws_eapol_relay_socket_pdu_send(&dest_addr, pdu, pdu_len);
151+
ns_dyn_mem_free(pdu);
152+
153+
return 0;
154+
}
155+
156+
#endif /* HAVE_WS */
157+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2016-2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef WS_EAPOL_AUTH_RELAY_H_
19+
#define WS_EAPOL_AUTH_RELAY_H_
20+
21+
int8_t ws_eapol_auth_relay_init(protocol_interface_info_entry_t *interface_ptr);
22+
int8_t ws_eapol_auth_relay_start(void);
23+
24+
#endif /* WS_EAPOL_AUTH_RELAY_H_ */

0 commit comments

Comments
 (0)