beacon.c (2fa98d7e52bbc58f1e999168903aa80914b17888) | beacon.c (bdf219b2290515559e5dd7fd6ae2114cb15ebd69) |
---|---|
1/* 2 * Copyright (C) 2017 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 130 unchanged lines hidden (view full) --- 139 140static void mesh_secure_network_beacon_setup(mesh_subnet_t * mesh_subnet){ 141 mesh_beacon_data[0] = BEACON_TYPE_SECURE_NETWORK; 142 mesh_beacon_data[1] = mesh_secure_network_beacon_get_flags(mesh_subnet); 143 // TODO: pick correct key based on key refresh phase 144 145 memcpy(&mesh_beacon_data[2], mesh_subnet->old_key->network_id, 8); 146 big_endian_store_32(mesh_beacon_data, 10, mesh_get_iv_index()); | 1/* 2 * Copyright (C) 2017 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 130 unchanged lines hidden (view full) --- 139 140static void mesh_secure_network_beacon_setup(mesh_subnet_t * mesh_subnet){ 141 mesh_beacon_data[0] = BEACON_TYPE_SECURE_NETWORK; 142 mesh_beacon_data[1] = mesh_secure_network_beacon_get_flags(mesh_subnet); 143 // TODO: pick correct key based on key refresh phase 144 145 memcpy(&mesh_beacon_data[2], mesh_subnet->old_key->network_id, 8); 146 big_endian_store_32(mesh_beacon_data, 10, mesh_get_iv_index()); |
147 btstack_crypto_aes128_cmac_message(&mesh_secure_network_beacon_cmac_request, mesh_subnet->old_key->beacon_key, 13, | 147 mesh_network_key_t * network_key = mesh_subnet_get_outgoing_network_key(mesh_subnet); 148 btstack_crypto_aes128_cmac_message(&mesh_secure_network_beacon_cmac_request, network_key->beacon_key, 13, |
148 &mesh_beacon_data[1], mesh_secure_network_beacon_auth_value, &mesh_secure_network_beacon_auth_value_calculated, mesh_subnet); 149} 150 151static void mesh_secure_network_beacon_update_interval(mesh_subnet_t * subnet){ 152 uint32_t min_observation_period_ms = 2 * subnet->beacon_interval_ms; 153 uint32_t actual_observation_period = btstack_time_delta(btstack_run_loop_get_time_ms(), subnet->beacon_observation_start_ms); 154 155 // The Observation Period in seconds should typically be double the typical Beacon Interval. --- 134 unchanged lines hidden (view full) --- 290 if (new_flags == 0) return; 291 292 // validate beacon - if crytpo ready 293 if (mesh_secure_network_beacon_active) return; 294 295 mesh_secure_network_beacon_active = 1; 296 memcpy(mesh_secure_network_beacon_validate_buffer, &packet[0], SECURE_NETWORK_BEACON_LEN); 297 | 149 &mesh_beacon_data[1], mesh_secure_network_beacon_auth_value, &mesh_secure_network_beacon_auth_value_calculated, mesh_subnet); 150} 151 152static void mesh_secure_network_beacon_update_interval(mesh_subnet_t * subnet){ 153 uint32_t min_observation_period_ms = 2 * subnet->beacon_interval_ms; 154 uint32_t actual_observation_period = btstack_time_delta(btstack_run_loop_get_time_ms(), subnet->beacon_observation_start_ms); 155 156 // The Observation Period in seconds should typically be double the typical Beacon Interval. --- 134 unchanged lines hidden (view full) --- 291 if (new_flags == 0) return; 292 293 // validate beacon - if crytpo ready 294 if (mesh_secure_network_beacon_active) return; 295 296 mesh_secure_network_beacon_active = 1; 297 memcpy(mesh_secure_network_beacon_validate_buffer, &packet[0], SECURE_NETWORK_BEACON_LEN); 298 |
298 // TODO: handle odl/new keys 299 btstack_crypto_aes128_cmac_message(&mesh_secure_network_beacon_cmac_request, subnet->old_key->beacon_key, 13, | 299 mesh_network_key_t * network_key = mesh_subnet_get_outgoing_network_key(mesh_subnet); 300 btstack_crypto_aes128_cmac_message(&mesh_secure_network_beacon_cmac_request, network_key->beacon_key, 13, |
300 &mesh_secure_network_beacon_validate_buffer[1], mesh_secure_network_beacon_auth_value, &beacon_handle_secure_beacon_auth_value_calculated, subnet); 301} 302 303static void beacon_handle_beacon_packet(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 304 log_info("beacon type %u", packet[0]); 305 switch (packet[0]){ 306 case BEACON_TYPE_UNPROVISIONED_DEVICE: 307 if (unprovisioned_device_beacon_handler){ --- 169 unchanged lines hidden --- | 301 &mesh_secure_network_beacon_validate_buffer[1], mesh_secure_network_beacon_auth_value, &beacon_handle_secure_beacon_auth_value_calculated, subnet); 302} 303 304static void beacon_handle_beacon_packet(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 305 log_info("beacon type %u", packet[0]); 306 switch (packet[0]){ 307 case BEACON_TYPE_UNPROVISIONED_DEVICE: 308 if (unprovisioned_device_beacon_handler){ --- 169 unchanged lines hidden --- |