Bluetooth: SMP: Add support for passkey entry

This allows to request passkey being entered by user.

Change-Id: I6a56c65ca689473659a13c19f8578058476d2685
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
Szymon Janc 2015-08-17 09:16:51 +02:00 committed by Anas Nashif
commit 01c76d9fa4
2 changed files with 46 additions and 2 deletions

View file

@ -139,6 +139,7 @@ int bt_stop_scanning(void);
/** Authenticated pairing callback structure */
struct bt_auth_cb {
void (*passkey_display)(struct bt_conn *conn, unsigned int passkey);
void (*passkey_entry)(struct bt_conn *conn);
void (*cancel)(struct bt_conn *conn);
};
@ -153,6 +154,16 @@ struct bt_auth_cb {
*/
int bt_auth_cb_register(const struct bt_auth_cb *cb);
/** @brief Reply with entered passkey.
*
* This function should be called only after passkey_entry callback from
* bt_auth_cb structure was called.
*
* @param conn Connection object.
* @param passkey Entered passkey.
*/
void bt_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey);
/** @brief Cancel ongoing authenticated pairing.
*
* This function allows to cancel ongoing authenticated pairing.

View file

@ -419,8 +419,8 @@ static uint8_t smp_request_tk(struct bt_conn *conn, uint8_t remote_io)
break;
case PASSKEY_INPUT:
/* TODO add support for input passkey entry*/
return BT_SMP_ERR_UNSPECIFIED;
auth_cb->passkey_entry(conn);
break;
case JUST_WORKS:
break;
default:
@ -609,6 +609,11 @@ static uint8_t smp_pairing_rsp(struct bt_conn *conn, struct bt_buf *buf)
return ret;
}
/* waiting for passkey entry input for TK */
if (smp->method == PASSKEY_INPUT) {
return 0;
}
return smp_send_pairing_confirm(conn);
}
@ -1675,6 +1680,14 @@ static inline int smp_self_test(void)
static uint8_t get_io_capa(const struct bt_auth_cb *cb)
{
if (auth_cb->passkey_display && auth_cb->passkey_entry) {
return BT_SMP_IO_KEYBOARD_DISPLAY;
}
if (auth_cb->passkey_entry) {
return BT_SMP_IO_KEYBOARD_ONLY;
}
if (auth_cb->passkey_display) {
return BT_SMP_IO_DISPLAY_ONLY;
}
@ -1705,6 +1718,26 @@ int bt_auth_cb_register(const struct bt_auth_cb *cb)
return 0;
}
void bt_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
{
struct bt_smp *smp = conn->smp;
passkey = sys_cpu_to_le32(passkey);
memcpy(smp->tk, &passkey, sizeof(passkey));
/* if confirm failed ie. due to invalid passkey, cancel pairing */
if (smp_send_pairing_confirm(conn)) {
bt_auth_cancel(conn);
return;
}
if (conn->role == BT_HCI_ROLE_MASTER) {
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM);
} else {
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM);
}
}
void bt_auth_cancel(struct bt_conn *conn)
{
send_err_rsp(conn, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);