1 /* 2 * Copyright (C) 2019 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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #define __BTSTACK_FILE__ "mesh.c" 39 40 #include <string.h> 41 #include <stdio.h> 42 43 #include "mesh/mesh.h" 44 45 #include "btstack_util.h" 46 #include "btstack_config.h" 47 #include "btstack_event.h" 48 #include "btstack_tlv.h" 49 #include "btstack_memory.h" 50 51 #include "mesh/adv_bearer.h" 52 #include "mesh/beacon.h" 53 #include "mesh/gatt_bearer.h" 54 #include "mesh/mesh_access.h" 55 #include "mesh/mesh_configuration_server.h" 56 #include "mesh/mesh_foundation.h" 57 #include "mesh/mesh_generic_model.h" 58 #include "mesh/mesh_generic_server.h" 59 #include "mesh/mesh_iv_index_seq_number.h" 60 #include "mesh/mesh_lower_transport.h" 61 #include "mesh/mesh_peer.h" 62 #include "mesh/mesh_proxy.h" 63 #include "mesh/mesh_upper_transport.h" 64 #include "mesh/mesh_virtual_addresses.h" 65 #include "mesh/pb_adv.h" 66 #include "mesh/pb_gatt.h" 67 #include "mesh/provisioning.h" 68 #include "mesh/provisioning_device.h" 69 70 // Persistent storage structures 71 72 typedef struct { 73 uint16_t netkey_index; 74 75 uint8_t version; 76 77 // net_key from provisioner or Config Model Client 78 uint8_t net_key[16]; 79 80 // derived data 81 82 // k1 83 uint8_t identity_key[16]; 84 uint8_t beacon_key[16]; 85 86 // k3 87 uint8_t network_id[8]; 88 89 // k2 90 uint8_t nid; 91 uint8_t encryption_key[16]; 92 uint8_t privacy_key[16]; 93 } mesh_persistent_net_key_t; 94 95 typedef struct { 96 uint16_t netkey_index; 97 uint16_t appkey_index; 98 uint8_t aid; 99 uint8_t version; 100 uint8_t key[16]; 101 } mesh_persistent_app_key_t; 102 103 typedef struct { 104 uint8_t gatt_proxy; 105 uint8_t beacon; 106 uint8_t default_ttl; 107 uint8_t network_transmit; 108 uint8_t relay; 109 uint8_t relay_retransmit; 110 uint8_t friend; 111 } mesh_persistent_foundation_t; 112 113 static btstack_packet_handler_t provisioning_device_packet_handler; 114 static btstack_packet_callback_registration_t hci_event_callback_registration; 115 static int provisioned; 116 117 // Mandatory Confiuration Server 118 static mesh_model_t mesh_configuration_server_model; 119 120 // Mandatory Health Server 121 static mesh_model_t mesh_health_server_model; 122 static mesh_configuration_server_model_context_t mesh_configuration_server_model_context; 123 124 // Random UUID on start 125 static btstack_crypto_random_t mesh_access_crypto_random; 126 static uint8_t random_device_uuid[16]; 127 128 // TLV 129 static const btstack_tlv_t * btstack_tlv_singleton_impl; 130 static void * btstack_tlv_singleton_context; 131 132 void mesh_access_setup_from_provisioning_data(const mesh_provisioning_data_t * provisioning_data){ 133 134 // set iv_index and iv index update active 135 int iv_index_update_active = (provisioning_data->flags & 2) >> 1; 136 mesh_iv_index_recovered(iv_index_update_active, provisioning_data->iv_index); 137 138 // set unicast address 139 mesh_node_primary_element_address_set(provisioning_data->unicast_address); 140 141 // set device_key 142 mesh_transport_set_device_key(provisioning_data->device_key); 143 144 if (provisioning_data->network_key){ 145 146 // setup primary network with provisioned netkey 147 mesh_network_key_add(provisioning_data->network_key); 148 149 // setup primary network 150 mesh_subnet_setup_for_netkey_index(provisioning_data->network_key->netkey_index); 151 152 // start sending Secure Network Beacons 153 mesh_subnet_t * provisioned_subnet = mesh_subnet_get_by_netkey_index(provisioning_data->network_key->netkey_index); 154 beacon_secure_network_start(provisioned_subnet); 155 } 156 157 // Mesh Proxy 158 #ifdef ENABLE_MESH_PROXY_SERVER 159 // Setup Proxy 160 mesh_proxy_init(provisioning_data->unicast_address); 161 mesh_proxy_start_advertising_with_network_id(); 162 #endif 163 } 164 165 static void mesh_access_setup_unprovisioned_device(void * arg){ 166 // set random value 167 if (arg == NULL){ 168 mesh_node_set_device_uuid(random_device_uuid); 169 } 170 171 #ifdef ENABLE_MESH_PB_ADV 172 // PB-ADV 173 beacon_unprovisioned_device_start(mesh_node_get_device_uuid(), 0); 174 #endif 175 #ifdef ENABLE_MESH_PB_GATT 176 mesh_proxy_start_advertising_unprovisioned_device(); 177 #endif 178 } 179 180 void mesh_access_setup_without_provisiong_data(void){ 181 const uint8_t * device_uuid = mesh_node_get_device_uuid(); 182 if (device_uuid){ 183 mesh_access_setup_unprovisioned_device((void *)device_uuid); 184 } else{ 185 btstack_crypto_random_generate(&mesh_access_crypto_random, random_device_uuid, 16, &mesh_access_setup_unprovisioned_device, NULL); 186 } 187 } 188 189 static void mesh_provisioning_message_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 190 mesh_provisioning_data_t provisioning_data; 191 192 switch(packet[0]){ 193 case HCI_EVENT_MESH_META: 194 switch(packet[2]){ 195 case MESH_SUBEVENT_PB_PROV_COMPLETE: 196 // get provisioning data 197 provisioning_device_data_get(&provisioning_data); 198 199 // and store in TLV 200 mesh_node_store_provisioning_data(&provisioning_data); 201 202 // setup node after provisioned 203 mesh_access_setup_from_provisioning_data(&provisioning_data); 204 205 // start advertising with node id after provisioning 206 mesh_proxy_set_advertising_with_node_id(provisioning_data.network_key->netkey_index, MESH_NODE_IDENTITY_STATE_ADVERTISING_RUNNING); 207 208 provisioned = 1; 209 break; 210 default: 211 break; 212 } 213 break; 214 default: 215 break; 216 } 217 if (provisioning_device_packet_handler == NULL) return; 218 219 // forward 220 (*provisioning_device_packet_handler)(packet_type, channel, packet, size); 221 } 222 223 static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 224 UNUSED(channel); 225 UNUSED(size); 226 227 switch (packet_type) { 228 case HCI_EVENT_PACKET: 229 switch (hci_event_packet_get_type(packet)) { 230 case BTSTACK_EVENT_STATE: 231 if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break; 232 // get TLV instance 233 btstack_tlv_get_instance(&btstack_tlv_singleton_impl, &btstack_tlv_singleton_context); 234 235 // startup from provisioning data stored in TLV 236 provisioned = mesh_node_startup_from_tlv(); 237 break; 238 239 case HCI_EVENT_DISCONNECTION_COMPLETE: 240 // enable PB_GATT 241 if (provisioned == 0){ 242 mesh_proxy_start_advertising_unprovisioned_device(); 243 } else { 244 #ifdef ENABLE_MESH_PROXY_SERVER 245 mesh_proxy_start_advertising_with_network_id(); 246 #endif 247 } 248 break; 249 250 case HCI_EVENT_LE_META: 251 if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break; 252 // disable PB_GATT 253 mesh_proxy_stop_advertising_unprovisioned_device(); 254 break; 255 default: 256 break; 257 } 258 break; 259 } 260 } 261 262 // Foundation state 263 static const uint32_t mesh_foundation_state_tag = ((uint32_t) 'M' << 24) | ((uint32_t) 'F' << 16) | ((uint32_t) 'N' << 8) | ((uint32_t) 'D' << 8); 264 265 void mesh_foundation_state_load(void){ 266 mesh_persistent_foundation_t data; 267 268 int foundation_state_len = btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, mesh_foundation_state_tag, (uint8_t *) &data, sizeof(data)); 269 if (foundation_state_len != sizeof(data)) return; 270 271 mesh_foundation_gatt_proxy_set(data.gatt_proxy); 272 mesh_foundation_beacon_set(data.gatt_proxy); 273 mesh_foundation_default_ttl_set(data.default_ttl); 274 mesh_foundation_friend_set(data.friend); 275 mesh_foundation_network_transmit_set(data.network_transmit); 276 mesh_foundation_relay_set(data.relay); 277 mesh_foundation_relay_retransmit_set(data.relay_retransmit); 278 } 279 280 void mesh_foundation_state_store(void){ 281 mesh_persistent_foundation_t data; 282 data.gatt_proxy = mesh_foundation_gatt_proxy_get(); 283 data.gatt_proxy = mesh_foundation_beacon_get(); 284 data.default_ttl = mesh_foundation_default_ttl_get(); 285 data.friend = mesh_foundation_friend_get(); 286 data.network_transmit = mesh_foundation_network_transmit_get(); 287 data.relay = mesh_foundation_relay_get(); 288 data.relay_retransmit = mesh_foundation_relay_retransmit_get(); 289 btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_foundation_state_tag, (uint8_t *) &data, sizeof(data)); 290 } 291 292 // Mesh Network Keys 293 static uint32_t mesh_network_key_tag_for_internal_index(uint16_t internal_index){ 294 return ((uint32_t) 'M' << 24) | ((uint32_t) 'N' << 16) | ((uint32_t) internal_index); 295 } 296 297 void mesh_store_network_key(mesh_network_key_t * network_key){ 298 mesh_persistent_net_key_t data; 299 printf("Store NetKey: internal index 0x%x, NetKey Index 0x%06x, NID %02x: ", network_key->internal_index, network_key->netkey_index, network_key->nid); 300 printf_hexdump(network_key->net_key, 16); 301 uint32_t tag = mesh_network_key_tag_for_internal_index(network_key->internal_index); 302 data.netkey_index = network_key->netkey_index; 303 memcpy(data.net_key, network_key->net_key, 16); 304 memcpy(data.identity_key, network_key->identity_key, 16); 305 memcpy(data.beacon_key, network_key->beacon_key, 16); 306 memcpy(data.network_id, network_key->network_id, 8); 307 data.nid = network_key->nid; 308 data.version = network_key->version; 309 memcpy(data.encryption_key, network_key->encryption_key, 16); 310 memcpy(data.privacy_key, network_key->privacy_key, 16); 311 btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(mesh_persistent_net_key_t)); 312 } 313 314 void mesh_delete_network_key(uint16_t internal_index){ 315 uint32_t tag = mesh_network_key_tag_for_internal_index(internal_index); 316 btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag); 317 } 318 319 320 void mesh_load_network_keys(void){ 321 printf("Load Network Keys\n"); 322 uint16_t internal_index; 323 for (internal_index = 0; internal_index < MAX_NR_MESH_NETWORK_KEYS; internal_index++){ 324 mesh_persistent_net_key_t data; 325 uint32_t tag = mesh_network_key_tag_for_internal_index(internal_index); 326 int netkey_len = btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data)); 327 if (netkey_len != sizeof(mesh_persistent_net_key_t)) continue; 328 329 mesh_network_key_t * network_key = btstack_memory_mesh_network_key_get(); 330 if (network_key == NULL) return; 331 332 network_key->netkey_index = data.netkey_index; 333 memcpy(network_key->net_key, data.net_key, 16); 334 memcpy(network_key->identity_key, data.identity_key, 16); 335 memcpy(network_key->beacon_key, data.beacon_key, 16); 336 memcpy(network_key->network_id, data.network_id, 8); 337 network_key->nid = data.nid; 338 network_key->version = data.version; 339 memcpy(network_key->encryption_key, data.encryption_key, 16); 340 memcpy(network_key->privacy_key, data.privacy_key, 16); 341 342 #ifdef ENABLE_GATT_BEARER 343 // setup advertisement with network id 344 network_key->advertisement_with_network_id.adv_length = mesh_proxy_setup_advertising_with_network_id(network_key->advertisement_with_network_id.adv_data, network_key->network_id); 345 #endif 346 347 mesh_network_key_add(network_key); 348 349 mesh_subnet_setup_for_netkey_index(network_key->netkey_index); 350 351 printf("- internal index 0x%x, NetKey Index 0x%06x, NID %02x: ", network_key->internal_index, network_key->netkey_index, network_key->nid); 352 printf_hexdump(network_key->net_key, 16); 353 } 354 } 355 356 void mesh_delete_network_keys(void){ 357 printf("Delete Network Keys\n"); 358 359 uint16_t internal_index; 360 for (internal_index = 0; internal_index < MAX_NR_MESH_NETWORK_KEYS; internal_index++){ 361 mesh_delete_network_key(internal_index); 362 } 363 } 364 365 // Mesh App Keys 366 367 static uint32_t mesh_transport_key_tag_for_internal_index(uint16_t internal_index){ 368 return ((uint32_t) 'M' << 24) | ((uint32_t) 'A' << 16) | ((uint32_t) internal_index); 369 } 370 371 void mesh_store_app_key(mesh_transport_key_t * app_key){ 372 mesh_persistent_app_key_t data; 373 printf("Store AppKey: internal index 0x%x, AppKey Index 0x%06x, AID %02x: ", app_key->internal_index, app_key->appkey_index, app_key->aid); 374 printf_hexdump(app_key->key, 16); 375 uint32_t tag = mesh_transport_key_tag_for_internal_index(app_key->internal_index); 376 data.netkey_index = app_key->netkey_index; 377 data.appkey_index = app_key->appkey_index; 378 data.aid = app_key->aid; 379 data.version = app_key->version; 380 memcpy(data.key, app_key->key, 16); 381 btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data)); 382 } 383 384 void mesh_delete_app_key(uint16_t internal_index){ 385 uint32_t tag = mesh_transport_key_tag_for_internal_index(internal_index); 386 btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag); 387 } 388 389 void mesh_load_app_keys(void){ 390 printf("Load App Keys\n"); 391 uint16_t internal_index; 392 for (internal_index = 0; internal_index < MAX_NR_MESH_TRANSPORT_KEYS; internal_index++){ 393 mesh_persistent_app_key_t data; 394 uint32_t tag = mesh_transport_key_tag_for_internal_index(internal_index); 395 int app_key_len = btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data)); 396 if (app_key_len == 0) continue; 397 398 mesh_transport_key_t * key = btstack_memory_mesh_transport_key_get(); 399 if (key == NULL) return; 400 401 key->internal_index = internal_index; 402 key->appkey_index = data.appkey_index; 403 key->netkey_index = data.netkey_index; 404 key->aid = data.aid; 405 key->akf = 1; 406 key->version = data.version; 407 memcpy(key->key, data.key, 16); 408 mesh_transport_key_add(key); 409 printf("- internal index 0x%x, AppKey Index 0x%06x, AID %02x: ", key->internal_index, key->appkey_index, key->aid); 410 printf_hexdump(key->key, 16); 411 } 412 } 413 414 void mesh_delete_app_keys(void){ 415 printf("Delete App Keys\n"); 416 417 uint16_t internal_index; 418 for (internal_index = 0; internal_index < MAX_NR_MESH_TRANSPORT_KEYS; internal_index++){ 419 mesh_delete_app_key(internal_index); 420 } 421 } 422 423 424 // Model to Appkey List 425 426 static uint32_t mesh_model_tag_for_index(uint16_t internal_model_id){ 427 return ((uint32_t) 'M' << 24) | ((uint32_t) 'B' << 16) | ((uint32_t) internal_model_id); 428 } 429 430 static void mesh_load_appkey_list(mesh_model_t * model){ 431 uint32_t tag = mesh_model_tag_for_index(model->mid); 432 btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &model->appkey_indices, sizeof(model->appkey_indices)); 433 } 434 435 static void mesh_store_appkey_list(mesh_model_t * model){ 436 uint32_t tag = mesh_model_tag_for_index(model->mid); 437 btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &model->appkey_indices, sizeof(model->appkey_indices)); 438 } 439 440 static void mesh_delete_appkey_list(mesh_model_t * model){ 441 uint32_t tag = mesh_model_tag_for_index(model->mid); 442 btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag); 443 } 444 445 void mesh_load_appkey_lists(void){ 446 printf("Load Appkey Lists\n"); 447 // iterate over elements and models 448 mesh_element_iterator_t element_it; 449 mesh_element_iterator_init(&element_it); 450 while (mesh_element_iterator_has_next(&element_it)){ 451 mesh_element_t * element = mesh_element_iterator_next(&element_it); 452 mesh_model_iterator_t model_it; 453 mesh_model_iterator_init(&model_it, element); 454 while (mesh_model_iterator_has_next(&model_it)){ 455 mesh_model_t * model = mesh_model_iterator_next(&model_it); 456 mesh_load_appkey_list(model); 457 } 458 } 459 } 460 461 void mesh_delete_appkey_lists(void){ 462 printf("Delete Appkey Lists\n"); 463 // iterate over elements and models 464 mesh_element_iterator_t element_it; 465 mesh_element_iterator_init(&element_it); 466 while (mesh_element_iterator_has_next(&element_it)){ 467 mesh_element_t * element = mesh_element_iterator_next(&element_it); 468 mesh_model_iterator_t model_it; 469 mesh_model_iterator_init(&model_it, element); 470 while (mesh_model_iterator_has_next(&model_it)){ 471 mesh_model_t * model = mesh_model_iterator_next(&model_it); 472 mesh_delete_appkey_list(model); 473 } 474 } 475 } 476 477 void mesh_model_reset_appkeys(mesh_model_t * mesh_model){ 478 uint16_t i; 479 for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){ 480 mesh_model->appkey_indices[i] = MESH_APPKEY_INVALID; 481 } 482 } 483 484 uint8_t mesh_model_bind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){ 485 uint16_t i; 486 for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){ 487 if (mesh_model->appkey_indices[i] == appkey_index) return MESH_FOUNDATION_STATUS_SUCCESS; 488 } 489 for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){ 490 if (mesh_model->appkey_indices[i] == MESH_APPKEY_INVALID) { 491 mesh_model->appkey_indices[i] = appkey_index; 492 mesh_store_appkey_list(mesh_model); 493 return MESH_FOUNDATION_STATUS_SUCCESS; 494 } 495 } 496 return MESH_FOUNDATION_STATUS_INSUFFICIENT_RESOURCES; 497 } 498 499 void mesh_model_unbind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){ 500 uint16_t i; 501 for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){ 502 if (mesh_model->appkey_indices[i] == appkey_index) { 503 mesh_model->appkey_indices[i] = MESH_APPKEY_INVALID; 504 mesh_store_appkey_list(mesh_model); 505 } 506 } 507 } 508 509 int mesh_model_contains_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){ 510 uint16_t i; 511 for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){ 512 if (mesh_model->appkey_indices[i] == appkey_index) return 1; 513 } 514 return 0; 515 } 516 517 static void mesh_node_setup_default_models(void){ 518 // configure Config Server 519 mesh_configuration_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_CONFIGURATION_SERVER); 520 mesh_configuration_server_model.model_data = &mesh_configuration_server_model_context; 521 mesh_configuration_server_model.operations = mesh_configuration_server_get_operations(); 522 mesh_element_add_model(mesh_node_get_primary_element(), &mesh_configuration_server_model); 523 524 // Config Health Server 525 mesh_health_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_HEALTH_SERVER); 526 mesh_element_add_model(mesh_node_get_primary_element(), &mesh_health_server_model); 527 } 528 529 void mesh_init(void){ 530 531 // register for HCI events 532 hci_event_callback_registration.callback = &hci_packet_handler; 533 hci_add_event_handler(&hci_event_callback_registration); 534 535 // ADV Bearer also used for GATT Proxy Advertisements and PB-GATT 536 adv_bearer_init(); 537 538 #ifdef ENABLE_MESH_GATT_BEARER 539 // Setup GATT bearer 540 gatt_bearer_init(); 541 #endif 542 543 #ifdef ENABLE_MESH_ADV_BEARER 544 // Setup Unprovisioned Device Beacon 545 beacon_init(); 546 #endif 547 548 provisioning_device_init(); 549 550 // Node Configuration 551 mesh_node_init(); 552 553 // Network layer 554 mesh_network_init(); 555 556 // Transport layers (lower + upper)) 557 mesh_lower_transport_init(); 558 mesh_upper_transport_init(); 559 560 // Access layer 561 mesh_access_init(); 562 563 mesh_node_setup_default_models(); 564 } 565 566 /** 567 * Register for Mesh Provisioning Device events 568 * @param packet_handler 569 */ 570 void mesh_register_provisioning_device_packet_handler(btstack_packet_handler_t packet_handler){ 571 provisioning_device_packet_handler = packet_handler; 572 provisioning_device_register_packet_handler(&mesh_provisioning_message_handler); 573 } 574