Bluetooth: Mesh: Fix provisioner provisioning

Correct format errors, such as oob action 2-octers
should use 0x%04x, and action in prov capalilities pdu
big-ending. When every call `bt_mesh_auth_method_set<*>`
should also clear auth value, otherwise will case confirm
failed.

Provisioner role expect peer public key should be sent
immediately, instead of requiring ACK. After all, ACK may
be lost, and the other device’s public key will be sent
over, and provisioning procedure will be failed..

This is a resubmission of PR (#30086)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
This commit is contained in:
Lingao Meng 2021-02-22 22:48:21 -08:00 committed by Johan Hedberg
commit 0841ee69f2
2 changed files with 12 additions and 10 deletions

View file

@ -50,7 +50,7 @@ int bt_mesh_prov_reset_state(void (*func)(const uint8_t key[64]))
{ {
int err; int err;
static struct bt_pub_key_cb pub_key_cb; static struct bt_pub_key_cb pub_key_cb;
const size_t offset = offsetof(struct bt_mesh_prov_link, dhkey); const size_t offset = offsetof(struct bt_mesh_prov_link, auth);
pub_key_cb.func = func ? func : pub_key_ready; pub_key_cb.func = func ? func : pub_key_ready;
@ -268,7 +268,7 @@ static void prov_recv(const struct prov_bearer *bearer, void *cb_data,
if (type >= ARRAY_SIZE(bt_mesh_prov_link.role->op)) { if (type >= ARRAY_SIZE(bt_mesh_prov_link.role->op)) {
BT_ERR("Unknown provisioning PDU type 0x%02x", type); BT_ERR("Unknown provisioning PDU type 0x%02x", type);
bt_mesh_prov_link.role->error(PROV_ERR_NVAL_FMT); bt_mesh_prov_link.role->error(PROV_ERR_NVAL_PDU);
return; return;
} }

View file

@ -183,9 +183,9 @@ static bool prov_check_method(struct bt_mesh_dev_capabilities *caps)
} }
if (!(BIT(bt_mesh_prov_link.oob_action) & caps->input_actions)) { if (!(BIT(bt_mesh_prov_link.oob_action) & caps->input_actions)) {
BT_WARN("The required input action (0x%02x) " BT_WARN("The required input action (0x%04x) "
"not supported by the device (0x%02x)", "not supported by the device (0x%02x)",
bt_mesh_prov_link.oob_action, caps->input_actions); (uint16_t)BIT(bt_mesh_prov_link.oob_action), caps->input_actions);
return false; return false;
} }
@ -209,9 +209,9 @@ static bool prov_check_method(struct bt_mesh_dev_capabilities *caps)
} }
if (!(BIT(bt_mesh_prov_link.oob_action) & caps->output_actions)) { if (!(BIT(bt_mesh_prov_link.oob_action) & caps->output_actions)) {
BT_WARN("The required output action (0x%02x) " BT_WARN("The required output action (0x%04x) "
"not supported by the device (0x%02x)", "not supported by the device (0x%02x)",
bt_mesh_prov_link.oob_action, caps->output_actions); (uint16_t)BIT(bt_mesh_prov_link.oob_action), caps->output_actions);
return false; return false;
} }
@ -241,9 +241,11 @@ static void prov_capabilities(const uint8_t *data)
BT_DBG("Static OOB Type: 0x%02x", caps.static_oob); BT_DBG("Static OOB Type: 0x%02x", caps.static_oob);
BT_DBG("Output OOB Size: %u", caps.output_size); BT_DBG("Output OOB Size: %u", caps.output_size);
caps.output_actions = (bt_mesh_output_action_t)data[6]; caps.output_actions = (bt_mesh_output_action_t)
(sys_get_be16(&data[6]));
caps.input_size = data[8]; caps.input_size = data[8];
caps.input_actions = (bt_mesh_input_action_t)data[9]; caps.input_actions = (bt_mesh_input_action_t)
(sys_get_be16(&data[9]));
BT_DBG("Output OOB Action: 0x%04x", caps.output_actions); BT_DBG("Output OOB Action: 0x%04x", caps.output_actions);
BT_DBG("Input OOB Size: %u", caps.input_size); BT_DBG("Input OOB Size: %u", caps.input_size);
BT_DBG("Input OOB Action: 0x%04x", caps.input_actions); BT_DBG("Input OOB Action: 0x%04x", caps.input_actions);
@ -339,8 +341,6 @@ static void public_key_sent(int err, void *cb_data)
prov_dh_key_gen(); prov_dh_key_gen();
return; return;
} }
bt_mesh_prov_link.expect = PROV_PUB_KEY;
} }
static void send_pub_key(void) static void send_pub_key(void)
@ -370,6 +370,8 @@ static void send_pub_key(void)
BT_ERR("Failed to send Public Key"); BT_ERR("Failed to send Public Key");
return; return;
} }
bt_mesh_prov_link.expect = PROV_PUB_KEY;
} }
static void prov_dh_key_cb(const uint8_t dhkey[32]) static void prov_dh_key_cb(const uint8_t dhkey[32])