drivers/nble: Implement passkey entry
Implement bt_smp_auth_passkey_entry() and bt_conn_auth_passkey_entry() functions to be used by apps and tester. Change-Id: I600284334c67840dd0c17991596ad31986bf0afd Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
parent
ed044a7279
commit
0324f39313
|
@ -369,7 +369,7 @@ int bt_conn_auth_cb_register(const struct bt_conn_auth_cb *cb)
|
|||
|
||||
int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
|
||||
{
|
||||
return -ENOSYS;
|
||||
return bt_smp_auth_passkey_entry(conn, passkey);
|
||||
}
|
||||
|
||||
int bt_conn_auth_cancel(struct bt_conn *conn)
|
||||
|
|
|
@ -373,21 +373,41 @@ void on_nble_sm_passkey_req_evt(const struct nble_sm_passkey_req_evt *ev)
|
|||
bt_conn_unref(conn);
|
||||
}
|
||||
|
||||
static void nble_security_reply(struct bt_conn *conn,
|
||||
struct nble_sm_passkey *par)
|
||||
{
|
||||
struct nble_sm_passkey_reply_req rsp = {
|
||||
.conn = conn,
|
||||
.conn_handle = conn->handle,
|
||||
};
|
||||
|
||||
memcpy(&rsp.params, par, sizeof(*par));
|
||||
|
||||
nble_sm_passkey_reply_req(&rsp);
|
||||
}
|
||||
|
||||
static int sm_error(struct bt_conn *conn, uint8_t reason)
|
||||
{
|
||||
struct nble_sm_passkey_reply_req req;
|
||||
struct nble_sm_passkey params;
|
||||
|
||||
req.conn = conn;
|
||||
req.conn_handle = conn->handle;
|
||||
params.type = NBLE_GAP_SM_REJECT;
|
||||
params.reason = reason;
|
||||
|
||||
req.params.type = NBLE_GAP_SM_REJECT;
|
||||
req.params.reason = reason;
|
||||
|
||||
nble_sm_passkey_reply_req(&req);
|
||||
nble_security_reply(conn, ¶ms);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void legacy_passkey_entry(struct bt_smp *smp, unsigned int passkey)
|
||||
{
|
||||
struct nble_sm_passkey pkey = {
|
||||
.type = NBLE_SM_PK_PASSKEY,
|
||||
.passkey = passkey,
|
||||
};
|
||||
|
||||
nble_security_reply(smp->conn, &pkey);
|
||||
}
|
||||
|
||||
int bt_smp_auth_cancel(struct bt_conn *conn)
|
||||
{
|
||||
BT_DBG("");
|
||||
|
@ -395,6 +415,29 @@ int bt_smp_auth_cancel(struct bt_conn *conn)
|
|||
return sm_error(conn, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);
|
||||
}
|
||||
|
||||
int bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
|
||||
{
|
||||
struct bt_smp *smp;
|
||||
|
||||
BT_DBG("");
|
||||
|
||||
smp = smp_chan_get(conn);
|
||||
if (!smp) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!atomic_test_and_clear_bit(&smp->flags, SMP_FLAG_USER)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!atomic_test_bit(&smp->flags, SMP_FLAG_SC)) {
|
||||
legacy_passkey_entry(smp, passkey);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_smp_init(void)
|
||||
{
|
||||
BT_DBG("");
|
||||
|
|
|
@ -17,3 +17,5 @@
|
|||
void bt_smp_connected(struct bt_conn *conn);
|
||||
void bt_smp_disconnected(struct bt_conn *conn);
|
||||
int bt_smp_init(void);
|
||||
|
||||
int bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey);
|
||||
|
|
Loading…
Reference in a new issue