62
62
#include "DHCPv6_client/dhcpv6_client_api.h"
63
63
#include "net_rpl.h"
64
64
#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"
65
69
66
70
#define TRACE_GROUP "wsbs"
67
71
@@ -88,7 +92,11 @@ static uint16_t ws_bootstrap_routing_cost_calculate(protocol_interface_info_entr
88
92
static uint16_t ws_bootstrap_rank_get (protocol_interface_info_entry_t * cur );
89
93
static uint16_t ws_bootstrap_min_rank_inc_get (protocol_interface_info_entry_t * cur );
90
94
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
+
91
98
mac_neighbor_table_entry_t * ws_bootstrap_mac_neighbor_add (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
99
+
92
100
{
93
101
mac_neighbor_table_entry_t * neighbor = mac_neighbor_table_address_discover (mac_neighbor_info (interface ), src64 , MAC_ADDR_MODE_64_BIT );
94
102
if (neighbor ) {
@@ -667,6 +675,9 @@ static int8_t ws_bootstrap_down(protocol_interface_info_entry_t *cur)
667
675
nd_proxy_downstream_interface_unregister (cur -> id );
668
676
ws_nud_table_reset (cur );
669
677
dhcp_client_delete (cur -> id );
678
+ ws_eapol_relay_delete (cur );
679
+ ws_eapol_auth_relay_delete (cur );
680
+ ws_pae_controller_stop (cur );
670
681
671
682
return nwk_6lowpan_down (cur );
672
683
}
@@ -1404,6 +1415,26 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
1404
1415
goto init_fail ;
1405
1416
}
1406
1417
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
+ }
1407
1438
1408
1439
cur -> if_up = ws_bootstrap_up ;
1409
1440
cur -> if_down = ws_bootstrap_down ;
@@ -1445,10 +1476,13 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
1445
1476
//Error handling and free memory
1446
1477
init_fail :
1447
1478
lowpan_adaptation_interface_mpx_register (interface_id , NULL , 0 );
1479
+ ws_eapol_pdu_mpx_register (cur , NULL , 0 );
1448
1480
mac_neighbor_table_delete (mac_neighbor_info (cur ));
1449
1481
etx_storage_list_allocate (cur -> id , 0 );
1450
1482
ws_neighbor_class_dealloc (& neigh_info );
1451
1483
ws_llc_delete (cur );
1484
+ ws_eapol_pdu_delete (cur );
1485
+ ws_pae_controller_delete (cur );
1452
1486
return ret_val ;
1453
1487
}
1454
1488
@@ -1591,6 +1625,10 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
1591
1625
if (instance && rpl_control_read_dodag_info (instance , & dodag_info )) {
1592
1626
tr_debug ("Enable DHCPv6 relay" );
1593
1627
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 );
1594
1632
}
1595
1633
1596
1634
ws_set_fhss_hop (cur );
@@ -1750,6 +1788,40 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
1750
1788
// Discovery statemachine is checkked after two trickle interval
1751
1789
cur -> bootsrap_state_machine_cnt = 2 * trickle_params_pan_discovery .Imin + randLIB_get_8bit () % 50 ;
1752
1790
}
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
+
1753
1825
// Start configuration learning
1754
1826
static void ws_bootstrap_start_configuration_learn (protocol_interface_info_entry_t * cur )
1755
1827
{
@@ -1758,6 +1830,7 @@ static void ws_bootstrap_start_configuration_learn(protocol_interface_info_entry
1758
1830
1759
1831
cur -> ws_info -> configuration_learned = false;
1760
1832
// Clear parent info
1833
+
1761
1834
memset (cur -> ws_info -> parent_info .addr , 0 , 8 );
1762
1835
1763
1836
// Clear all temporary information
@@ -1968,19 +2041,6 @@ static bool ws_bootstrap_address_registration_ongoing(protocol_interface_info_en
1968
2041
return false;
1969
2042
}
1970
2043
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
-
1984
2044
static void ws_bootstrap_event_handler (arm_event_s * event )
1985
2045
{
1986
2046
ws_bootsrap_event_type_e event_type ;
@@ -2021,8 +2081,19 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
2021
2081
// Set default parameters for FHSS when starting a discovery
2022
2082
ws_fhss_border_router_configure (cur );
2023
2083
ws_bootstrap_fhss_activate (cur );
2024
- ws_bootstrap_set_test_key (cur );
2025
2084
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 );
2026
2097
break ;
2027
2098
}
2028
2099
// Configure LLC for network discovery
@@ -2036,9 +2107,17 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
2036
2107
// only advert sol stopped as we might be doing re authentication
2037
2108
cur -> ws_info -> trickle_pas_running = false;
2038
2109
//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 );
2041
2119
break ;
2120
+
2042
2121
case WS_CONFIGURATION_START :
2043
2122
tr_info ("Configuration start" );
2044
2123
// Old configuration is considered invalid stopping all
@@ -2114,8 +2193,14 @@ void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur)
2114
2193
return ;
2115
2194
}
2116
2195
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
+
2117
2200
ws_bootstrap_network_information_learn (cur );
2118
2201
ws_bootstrap_fhss_activate (cur );
2202
+
2203
+ ws_pae_controller_set_target (cur , cur -> ws_info -> parent_info .addr ); // temporary!!! store since auth
2119
2204
ws_bootstrap_event_authentication_start (cur );
2120
2205
return ;
2121
2206
}
@@ -2125,7 +2210,11 @@ void ws_bootstrap_configure_process(protocol_interface_info_entry_t *cur)
2125
2210
2126
2211
if (cur -> ws_info -> configuration_learned ) {
2127
2212
ws_bootstrap_network_configuration_learn (cur );
2213
+
2214
+
2128
2215
ws_bootstrap_event_operation_start (cur );
2216
+
2217
+
2129
2218
return ;
2130
2219
}
2131
2220
return ;
0 commit comments