Bluetooth: Mesh: Provisioning: Introduce link open/close callbacks

It may be useful for the app to know when the provisioning link is
active and when it has been closed. This can be used e.g. to signal
the user the state of the device. Some PTS tests also require
verifying the link state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-11-12 08:41:45 +02:00 committed by Johan Hedberg
commit 092a28541a
2 changed files with 18 additions and 0 deletions

View file

@ -468,6 +468,8 @@ struct bt_mesh_prov {
int (*input)(bt_mesh_input_action act, u8_t size); int (*input)(bt_mesh_input_action act, u8_t size);
void (*link_open)(void);
void (*link_close)(void);
void (*complete)(void); void (*complete)(void);
}; };

View file

@ -229,6 +229,10 @@ static void reset_link(void)
{ {
prov_clear_tx(); prov_clear_tx();
if (prov->link_close) {
prov->link_close();
}
/* Clear everything except the retransmit delayed work config */ /* Clear everything except the retransmit delayed work config */
memset(&link, 0, offsetof(struct prov_link, tx.retransmit)); memset(&link, 0, offsetof(struct prov_link, tx.retransmit));
@ -1162,6 +1166,10 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf)
return; return;
} }
if (prov->link_open) {
prov->link_open();
}
link.id = rx->link_id; link.id = rx->link_id;
atomic_set_bit(link.flags, LINK_ACTIVE); atomic_set_bit(link.flags, LINK_ACTIVE);
net_buf_simple_init(link.rx.buf, 0); net_buf_simple_init(link.rx.buf, 0);
@ -1463,6 +1471,10 @@ int bt_mesh_pb_gatt_open(struct bt_conn *conn)
link.conn = bt_conn_ref(conn); link.conn = bt_conn_ref(conn);
link.expect = PROV_INVITE; link.expect = PROV_INVITE;
if (prov->link_open) {
prov->link_open();
}
return 0; return 0;
} }
@ -1482,6 +1494,10 @@ int bt_mesh_pb_gatt_close(struct bt_conn *conn)
bt_mesh_attention(NULL, 0); bt_mesh_attention(NULL, 0);
} }
if (prov->link_close) {
prov->link_close();
}
bt_conn_unref(link.conn); bt_conn_unref(link.conn);
pub_key = atomic_test_bit(link.flags, LOCAL_PUB_KEY); pub_key = atomic_test_bit(link.flags, LOCAL_PUB_KEY);