38 #include "provisioner.h" 45 #include "nrf_mesh_assert.h" 47 #include "nrf_mesh_prov.h" 48 #include "nrf_mesh_prov_bearer_adv.h" 49 #include "nrf_mesh_events.h" 50 #include "device_state_manager.h" 52 #include "config_client.h" 53 #include "access_config.h" 54 #include "simple_on_off_server.h" 55 #include "health_common.h" 57 #include "nrf_mesh_sdk.h" 64 PROV_STATE_CONFIG_FIRST,
65 PROV_STATE_CONFIG_COMPOSITION_GET,
66 PROV_STATE_CONFIG_APPKEY_ADD,
67 PROV_STATE_CONFIG_APPKEY_BIND_HEALTH,
68 PROV_STATE_CONFIG_APPKEY_BIND_ONOFF,
69 PROV_STATE_CONFIG_PUBLICATION_HEALTH,
70 PROV_STATE_CONFIG_PUBLICATION_ONOFF,
71 PROV_STATE_CONFIG_SUBSCRIPTION
79 static nrf_mesh_prov_ctx_t m_prov_ctx;
81 static prov_state_t m_prov_state;
82 static uint16_t m_target_address;
85 static void start_provisioning(
const uint8_t * p_uuid)
90 .netkey_index = NETKEY_INDEX,
92 .address = m_target_address,
93 .flags.iv_update =
false,
94 .flags.key_refresh =
false 97 m_prov_state = PROV_STATE_PROV;
100 static void do_config_step(
void)
102 switch (m_prov_state)
104 case PROV_STATE_CONFIG_FIRST:
105 m_prov_state = PROV_STATE_CONFIG_COMPOSITION_GET;
109 case PROV_STATE_CONFIG_COMPOSITION_GET:
111 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Getting composition data\n");
117 case PROV_STATE_CONFIG_APPKEY_ADD:
119 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Adding appkey\n");
126 case PROV_STATE_CONFIG_APPKEY_BIND_HEALTH:
128 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Binding appkey to the Health model\n");
132 uint16_t element_address = m_target_address;
138 case PROV_STATE_CONFIG_APPKEY_BIND_ONOFF:
140 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Binding appkey to the Simple On/Off model\n");
144 uint16_t element_address = m_target_address;
150 case PROV_STATE_CONFIG_PUBLICATION_HEALTH:
165 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Setting publication address for the health server to 0x%04x\n", pubstate.
publish_address.
value);
172 case PROV_STATE_CONFIG_PUBLICATION_ONOFF:
187 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Setting publication address for the On/Off server to 0x%04x\n", pubstate.
publish_address.
value);
194 case PROV_STATE_CONFIG_SUBSCRIPTION:
196 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Adding subscription\n");
197 uint16_t element_address = m_target_address;
200 address.
value = GROUP_ADDRESS;
219 if (m_prov_state == PROV_STATE_WAIT)
222 m_prov_state = PROV_STATE_PROV;
227 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Local provisioning link closed\n");
228 if (m_prov_state == PROV_STATE_PROV)
230 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Provisioning failed. Retrying...\n");
231 m_prov_state = PROV_STATE_WAIT;
233 else if (m_prov_state == PROV_STATE_CONFIG_FIRST)
240 m_prov_state = PROV_STATE_IDLE;
241 provisioner_prov_complete_cb(&p_evt->params.
complete);
250 if (status != NRF_SUCCESS)
252 __LOG(LOG_SRC_APP, LOG_LEVEL_ERROR,
253 "Provisioning OOB selection rejected, error code %d. Retrying...\n", status);
254 m_prov_state = PROV_STATE_WAIT;
258 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Using static authentication\n");
265 uint8_t static_data[16] = STATIC_AUTH_DATA;
267 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Static authentication data provided\n");
272 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,
"Local provisioning link established\n");
280 void provisioner_configure(uint16_t address)
282 m_target_address = address;
283 if (m_prov_state == PROV_STATE_PROV)
286 m_prov_state = PROV_STATE_CONFIG_FIRST;
290 m_prov_state = PROV_STATE_CONFIG_FIRST;
295 void provisioner_wait_for_unprov(uint16_t address)
297 m_target_address = address;
298 m_prov_state = PROV_STATE_WAIT;
303 if (event_type == CONFIG_CLIENT_EVENT_TYPE_TIMEOUT)
305 provisioner_config_failed_cb();
312 m_prov_state == PROV_STATE_CONFIG_COMPOSITION_GET)
314 __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO,
"Composition data", ((
const uint8_t *) &p_event->
p_msg->composition_data_status), length);
315 m_prov_state = PROV_STATE_CONFIG_APPKEY_ADD;
319 m_prov_state == PROV_STATE_CONFIG_APPKEY_ADD)
323 m_prov_state = PROV_STATE_CONFIG_APPKEY_BIND_HEALTH;
327 m_prov_state == PROV_STATE_CONFIG_APPKEY_BIND_HEALTH)
330 m_prov_state = PROV_STATE_CONFIG_APPKEY_BIND_ONOFF;
334 m_prov_state == PROV_STATE_CONFIG_APPKEY_BIND_ONOFF)
337 m_prov_state = PROV_STATE_CONFIG_PUBLICATION_HEALTH;
341 m_prov_state == PROV_STATE_CONFIG_PUBLICATION_HEALTH)
344 m_prov_state = PROV_STATE_CONFIG_PUBLICATION_ONOFF;
348 m_prov_state == PROV_STATE_CONFIG_PUBLICATION_ONOFF)
351 m_prov_state = PROV_STATE_CONFIG_SUBSCRIPTION;
355 m_prov_state == PROV_STATE_CONFIG_SUBSCRIPTION)
358 m_prov_state = PROV_STATE_IDLE;
359 provisioner_config_successful_cb();
367 void provisioner_init(
void)
369 m_prov_state = PROV_STATE_IDLE;
373 ERROR_CHECK(
nrf_mesh_prov_init(&m_prov_ctx, m_public_key, m_private_key, &capabilities, prov_evt_handler));
Step resolution: 100ms / step.
uint32_t config_client_appkey_add(uint16_t netkey_index, uint16_t appkey_index, const uint8_t *p_appkey)
Sends an application key add request.
uint8_t status
Status code.
Command successfully processed.
uint16_t company_id
Company ID.
#define SIMPLE_ON_OFF_SERVER_MODEL_ID
Simple OnOff Server model ID.
#define NRF_MESH_PROV_PUBKEY_SIZE
Size of the elliptic curve public key.
Provisioning event structure.
uint8_t retransmit_interval
Retransmit interval (in multiples of 50 ms).
#define NRF_MESH_KEY_SIZE
Size (in octets) of an encryption key.
uint16_t value
Address value.
#define NRF_MESH_ASSERT(cond)
Run-time assertion.
nrf_mesh_address_t publish_address
Publish address.
uint8_t step_res
Step resolution.
uint32_t nrf_mesh_prov_auth_data_provide(nrf_mesh_prov_ctx_t *p_ctx, const uint8_t *p_data, uint8_t size)
Provides out-of-band authentication data input to the provisioning stack.
#define ACCESS_COMPANY_ID_NORDIC
Company ID value for Nordic Semiconductor.
#define NRF_MESH_PROV_OOB_CAPS_DEFAULT(NUM_ELEMENTS)
Sets the default authentication capabilities.
Provisioning link established.
uint32_t config_client_model_app_bind(uint16_t element_address, uint16_t appkey_index, access_model_id_t model_id)
Sends a application bind request.
Static OOB authentication method.
nrf_mesh_prov_evt_unprov_t unprov
Unprovisioned beacon received event.
uint32_t config_client_model_subscription_add(uint16_t element_address, nrf_mesh_address_t address, access_model_id_t model_id)
Sends a subscription add request.
Opcode for the "Config Model Subscription Status" message.
#define NRF_MESH_PROV_PRIVKEY_SIZE
Size of the elliptic curve private key.
uint16_t element_address
Element address of the model to set the publication state.
uint8_t step_num
Number of steps.
Advertising-based provisioning bearer, PB-ADV.
nrf_mesh_prov_ctx_t * p_context
Provisioning context where the capabilities were received.
uint32_t nrf_mesh_prov_provision(nrf_mesh_prov_ctx_t *p_ctx, const uint8_t *p_target_uuid, const nrf_mesh_prov_provisioning_data_t *p_data, nrf_mesh_prov_bearer_type_t bearer)
Provisions a device.
nrf_mesh_prov_ctx_t * p_context
Provisioning context pointer.
PB-ADV context structure.
Opcode for the "Config Model Publication Status" message.
Received an unprovisioned node beacon.
uint8_t device_uuid[NRF_MESH_UUID_SIZE]
Device UUID of the unprovisioned node.
Configuration client event structure.
Opcode for the "AppKey Status" message.
prov_bearer_t * nrf_mesh_prov_bearer_adv_interface_get(nrf_mesh_prov_bearer_adv_t *p_bearer_adv)
Gets the provisioning bearer interface for the PB-ADV bearer.
Publication state parameter structure.
access_model_id_t model_id
Model identifier.
nrf_mesh_prov_evt_caps_received_t oob_caps_received
Provisioning capabilities received.
nrf_mesh_address_type_t type
Address type.
uint32_t config_client_composition_data_get(void)
Sends a composition data GET request.
uint32_t nrf_mesh_prov_generate_keys(uint8_t *p_public, uint8_t *p_private)
Generates a valid keypair for use with the provisioning cryptography.
const config_msg_t * p_msg
Pointer to message structure.
uint16_t model_id
Model ID.
#define ACCESS_COMPANY_ID_NONE
Company ID value for Bluetooth SIG opcodes or models.
uint16_t appkey_index
Application key index.
Provisioning authentication capabilities.
#define HEALTH_SERVER_MODEL_ID
Model ID for the Health Server model.
Step resolution: 10s / step.
uint32_t nrf_mesh_prov_bearer_add(nrf_mesh_prov_ctx_t *p_ctx, prov_bearer_t *p_prov_bearer)
Adds a new bearer to the provisioning context structure.
uint8_t status
Status code.
uint32_t config_client_model_publication_set(const config_publication_state_t *p_publication_state)
Sends a model publication set request.
config_client_event_type_t
Configuration client event types.
uint32_t nrf_mesh_prov_scan_start(nrf_mesh_prov_evt_handler_cb_t event_handler)
Starts the scanning for unprovisioned devices.
nrf_mesh_prov_evt_complete_t complete
Provisioning complete.
Provisioning data to transmit to a device.
uint32_t nrf_mesh_prov_oob_use(nrf_mesh_prov_ctx_t *p_ctx, nrf_mesh_prov_oob_method_t method, uint8_t action, uint8_t size)
Selects which out-of-band authentication method to use.
uint8_t publish_ttl
Publish TTL value.
uint8_t status
Status code.
Provisioning static data request.
uint32_t nrf_mesh_prov_init(nrf_mesh_prov_ctx_t *p_ctx, const uint8_t *p_public_key, const uint8_t *p_private_key, const nrf_mesh_prov_oob_caps_t *p_caps, nrf_mesh_prov_evt_handler_cb_t event_handler)
Initializes the provisioning context structure.
Opcode for the "Composition Data Status" message.
config_opcode_t opcode
Opcode of the status reply.
bool frendship_credential_flag
Set true to use friendship credentials for publishing.
uint8_t retransmit_count
Retransmit count.
Provisionee capabilities received.
uint8_t status
Status code.
Opcode for the "Model App Status" message.
The key with given index is already stored in the node with a different value.
access_publish_period_t publish_period
Publish period.
#define ACCESS_ELEMENT_COUNT
The number of elements in the application.
nrf_mesh_prov_evt_static_request_t static_request
Static provisioning data requested.
uint8_t netkey[NRF_MESH_KEY_SIZE]
Network key for the device.