Skip to content

Commit c5f1af3

Browse files
author
Mika Leppänen
committed
Initial EAPOL changes
Added KMP API header, security protocol API header and modules for PAE controller, PAE supplicant, PAE autenticator, PAE library, KMP service, EAPOL relay, EAPOL PDU and initial EAPOL-Key exchange protocol. Modified bootstrap to call PAE.
1 parent 59a65ea commit c5f1af3

20 files changed

+1977
-4
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
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_relay.h"
6567

6668
#define TRACE_GROUP "wsbs"
6769

@@ -88,7 +90,11 @@ static uint16_t ws_bootstrap_routing_cost_calculate(protocol_interface_info_entr
8890
static uint16_t ws_bootstrap_rank_get(protocol_interface_info_entry_t *cur);
8991
static uint16_t ws_bootstrap_min_rank_inc_get(protocol_interface_info_entry_t *cur);
9092

93+
static void ws_bootstrap_set_test_key(protocol_interface_info_entry_t *cur);
94+
static void ws_bootstrap_authentication_completed(bool success, protocol_interface_info_entry_t *cur);
95+
9196
mac_neighbor_table_entry_t *ws_bootstrap_mac_neighbor_add(struct protocol_interface_info_entry *interface, const uint8_t *src64)
97+
9298
{
9399
mac_neighbor_table_entry_t *neighbor = mac_neighbor_table_address_discover(mac_neighbor_info(interface), src64, MAC_ADDR_MODE_64_BIT);
94100
if (neighbor) {
@@ -1360,6 +1366,17 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
13601366
goto init_fail;
13611367
}
13621368

1369+
//Init PAE controller and set callback
1370+
ws_pae_controller_init(cur);
1371+
ws_pae_controller_cb_register(&ws_bootstrap_authentication_completed);
1372+
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)) {
1376+
ret_val = -4;
1377+
// add deallocs
1378+
goto init_fail;
1379+
}
13631380

13641381
cur->if_up = ws_bootstrap_up;
13651382
cur->if_down = ws_bootstrap_down;
@@ -1706,6 +1723,27 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
17061723
// Discovery statemachine is checkked after two trickle interval
17071724
cur->bootsrap_state_machine_cnt = 2 * trickle_params_pan_discovery.Imin + randLIB_get_8bit() % 50;
17081725
}
1726+
1727+
// Start authentication
1728+
static void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *cur)
1729+
{
1730+
ws_pae_controller_supplicant_authenticate();
1731+
}
1732+
1733+
static void ws_bootstrap_authentication_completed(bool success, protocol_interface_info_entry_t *cur)
1734+
{
1735+
if (success) {
1736+
ws_bootstrap_set_test_key(cur);
1737+
1738+
ws_bootstrap_event_operation_start(cur);
1739+
1740+
//ws_bootstrap_event_configuration_start(cur);
1741+
} else {
1742+
// What else to do to start over again...
1743+
ws_bootstrap_event_discovery_start(cur);
1744+
}
1745+
}
1746+
17091747
// Start configuration learning
17101748
static void ws_bootstrap_start_configuration_learn(protocol_interface_info_entry_t *cur)
17111749
{
@@ -1714,6 +1752,8 @@ static void ws_bootstrap_start_configuration_learn(protocol_interface_info_entry
17141752

17151753
cur->ws_info->configuration_learned = false;
17161754
// Clear parent info
1755+
1756+
ws_pae_controller_set_target(cur->ws_info->parent_info.addr); // temporary!!! store since auth made later
17171757
memset(cur->ws_info->parent_info.addr, 0, 8);
17181758

17191759
// Clear all temporary information
@@ -1979,6 +2019,8 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
19792019
ws_bootstrap_fhss_activate(cur);
19802020
ws_bootstrap_set_test_key(cur);
19812021
ws_bootstrap_event_operation_start(cur);
2022+
2023+
ws_pae_controller_authenticator_start();
19822024
break;
19832025
}
19842026
// Configure LLC for network discovery
@@ -1992,9 +2034,19 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
19922034
// only advert sol stopped as we might be doing re authentication
19932035
cur->ws_info->trickle_pas_running = false;
19942036
//Add Test ecurity key and security level's
1995-
ws_bootstrap_set_test_key(cur);
1996-
ws_bootstrap_event_configuration_start(cur);
2037+
2038+
2039+
//////////////////
2040+
// Advertisements stopped during the EAPOL
2041+
cur->ws_info->trickle_pa_running = false;
2042+
cur->ws_info->trickle_pc_running = false;
2043+
cur->ws_info->trickle_pas_running = false;
2044+
cur->ws_info->trickle_pcs_running = false;
2045+
//////////////////
2046+
2047+
ws_bootstrap_start_authentication(cur);
19972048
break;
2049+
19982050
case WS_CONFIGURATION_START:
19992051
tr_info("Configuration start");
20002052
// Old configuration is considered invalid stopping all
@@ -2072,7 +2124,10 @@ void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur)
20722124

20732125
ws_bootstrap_network_information_learn(cur);
20742126
ws_bootstrap_fhss_activate(cur);
2075-
ws_bootstrap_event_authentication_start(cur);
2127+
2128+
ws_bootstrap_set_test_key(cur);
2129+
ws_bootstrap_event_configuration_start(cur);
2130+
//ws_bootstrap_event_authentication_start(cur);
20762131
return;
20772132
}
20782133

@@ -2081,7 +2136,12 @@ void ws_bootstrap_configure_process(protocol_interface_info_entry_t *cur)
20812136

20822137
if (cur->ws_info->configuration_learned) {
20832138
ws_bootstrap_network_configuration_learn(cur);
2084-
ws_bootstrap_event_operation_start(cur);
2139+
2140+
2141+
//ws_bootstrap_event_operation_start(cur);
2142+
2143+
ws_bootstrap_event_authentication_start(cur);
2144+
20852145
return;
20862146
}
20872147
return;

source/6LoWPAN/ws/ws_eapol_relay.c

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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 "6LoWPAN/ws/ws_config.h"
28+
#include "Security/kmp/kmp.h"
29+
30+
#include "mac_api.h"
31+
#include "mac_mcps.h"
32+
33+
#include "Common_Protocols/ipv6_constants.h"
34+
#include "socket_api.h"
35+
36+
#include "6LoWPAN/MAC/mac_helper.h"
37+
#include "6LoWPAN/MAC/mpx_api.h"
38+
39+
#ifdef HAVE_WS
40+
41+
#define TRACE_GROUP "wspsu"
42+
43+
static void ws_eapol_relay_socket_cb(void *ptr);
44+
static void ws_eapol_relay_mpx_data_confirm(const mpx_api_t* api, const struct mcps_data_conf_s *data);
45+
static void ws_eapol_relay_mpx_data_indication(const mpx_api_t* api, const struct mcps_data_ind_s *data);
46+
static void ws_eapol_relay_data_request_primitiv_set(mcps_data_req_t *dataReq, protocol_interface_info_entry_t *cur);
47+
48+
typedef struct {
49+
protocol_interface_info_entry_t *interface_ptr; /**< List link entry */
50+
int8_t relay_socket_id; /**< Socket ID for relay */
51+
mpx_api_t *mpx_api; /**< mpx api */
52+
uint16_t mpx_user_id; /**< mpx user identifier */
53+
} eapol_relay_data_t;
54+
55+
static eapol_relay_data_t *eapol_relay_data;
56+
57+
void ws_eapol_relay_init(protocol_interface_info_entry_t *cur)
58+
{
59+
if (!eapol_relay_data) {
60+
eapol_relay_data = ns_dyn_mem_alloc(sizeof(eapol_relay_data_t));
61+
}
62+
eapol_relay_data->interface_ptr = cur;
63+
eapol_relay_data->relay_socket_id = socket_open(IPV6_NH_UDP, 10253, &ws_eapol_relay_socket_cb);
64+
}
65+
66+
static void ws_eapol_relay_socket_cb(void *cb)
67+
{
68+
if (!eapol_relay_data || !eapol_relay_data->mpx_api) {
69+
return;
70+
}
71+
72+
socket_callback_t *cb_data = cb;
73+
74+
mcps_data_req_t data_request;
75+
76+
ws_eapol_relay_data_request_primitiv_set(&data_request, eapol_relay_data->interface_ptr);
77+
78+
kmp_udp_pdu_t *pdu = ns_dyn_mem_temporary_alloc(cb_data->d_len);
79+
80+
if (socket_recvfrom(cb_data->socket_id, pdu, cb_data->d_len, 0, 0) != cb_data->d_len) {
81+
ns_dyn_mem_free(pdu);
82+
return;
83+
}
84+
85+
memcpy(data_request.DstAddr, pdu->eui_64, 8);
86+
87+
data_request.msdu = &(pdu->kmp_id);
88+
data_request.msduLength = cb_data->d_len - 8;
89+
90+
eapol_relay_data->mpx_api->mpx_data_request(eapol_relay_data->mpx_api, &data_request, eapol_relay_data->mpx_user_id);
91+
92+
ns_dyn_mem_free(pdu);
93+
}
94+
95+
static void ws_eapol_relay_data_request_primitiv_set(mcps_data_req_t *dataReq, protocol_interface_info_entry_t *cur)
96+
{
97+
memset(dataReq, 0, sizeof(mcps_data_req_t));
98+
99+
dataReq->InDirectTx = false;
100+
dataReq->TxAckReq = true;
101+
dataReq->SrcAddrMode = ADDR_802_15_4_LONG;
102+
dataReq->DstAddrMode = ADDR_802_15_4_LONG;
103+
dataReq->DstPANId = mac_helper_panid_get(cur);
104+
}
105+
106+
int8_t ws_eapol_relay_mpx_register(struct mpx_api_s *mpx_api, uint16_t mpx_user_id)
107+
{
108+
eapol_relay_data->mpx_api = mpx_api;
109+
eapol_relay_data->mpx_user_id = mpx_user_id;
110+
111+
if (eapol_relay_data->mpx_api) {
112+
eapol_relay_data->mpx_api->mpx_user_registration(eapol_relay_data->mpx_api, ws_eapol_relay_mpx_data_confirm, ws_eapol_relay_mpx_data_indication, eapol_relay_data->mpx_user_id);
113+
}
114+
return 0;
115+
}
116+
117+
static void ws_eapol_relay_mpx_data_confirm(const mpx_api_t* api, const struct mcps_data_conf_s *data)
118+
{
119+
(void) api;
120+
(void) data;
121+
}
122+
123+
static void ws_eapol_relay_mpx_data_indication(const mpx_api_t* api, const struct mcps_data_ind_s *data)
124+
{
125+
(void) api;
126+
127+
if (!data || !data->msduLength || !data->msdu_ptr) {
128+
return;
129+
}
130+
131+
ns_address_t dest_addr;
132+
if (addr_interface_get_ll_address(eapol_relay_data->interface_ptr, &dest_addr.address[0], 1) < 0) {
133+
return;
134+
}
135+
dest_addr.type = ADDRESS_IPV6;
136+
dest_addr.identifier = 10254;
137+
138+
kmp_udp_pdu_t *pdu = ns_dyn_mem_temporary_alloc(8 + data->msduLength);
139+
memcpy(&pdu->eui_64[0], &data->SrcAddr[0], 8);
140+
memcpy(&pdu->kmp_id, data->msdu_ptr, data->msduLength);
141+
142+
socket_sendto(eapol_relay_data->relay_socket_id , &dest_addr, pdu, 8 + data->msduLength);
143+
144+
ns_dyn_mem_free(pdu);
145+
}
146+
147+
#endif /* HAVE_WS */
148+

source/6LoWPAN/ws/ws_eapol_relay.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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_RELAY_H_
19+
#define WS_EAPOL_RELAY_H_
20+
21+
void ws_eapol_relay_init(protocol_interface_info_entry_t *cur);
22+
23+
int8_t ws_eapol_relay_mpx_register(struct mpx_api_s *mpx_api, uint16_t mpx_user_id);
24+
25+
#endif /* WS_EAPOL_RELAY_H_ */

0 commit comments

Comments
 (0)