Bluetooth: Add error return to authentication APIs

The authentication APIs may fail, so it's fair to give the application
a chance to catch these errors.

Change-Id: I323df86b94a823b201fe22d412e6bbcaa9029550
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2016-01-14 09:49:41 +02:00 committed by Anas Nashif
parent 8bf880a388
commit 0df7a2fac6
3 changed files with 39 additions and 23 deletions

View File

@ -56,14 +56,17 @@ int bt_auth_cb_register(const struct bt_auth_cb *cb)
return -ENOSYS;
}
void bt_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
int bt_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
{
return -ENOSYS;
}
void bt_auth_cancel(struct bt_conn *conn)
int bt_auth_cancel(struct bt_conn *conn)
{
return -ENOSYS;
}
void bt_auth_passkey_confirm(struct bt_conn *conn, bool match)
int bt_auth_passkey_confirm(struct bt_conn *conn, bool match)
{
return -ENOSYS;
}

View File

@ -272,16 +272,20 @@ int bt_auth_cb_register(const struct bt_auth_cb *cb);
*
* @param conn Connection object.
* @param passkey Entered passkey.
*
* @return Zero on success or negative error code otherwise
*/
void bt_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey);
int bt_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey);
/** @brief Cancel ongoing authenticated pairing.
*
* This function allows to cancel ongoing authenticated pairing.
*
* @param conn Connection object.
*
* @return Zero on success or negative error code otherwise
*/
void bt_auth_cancel(struct bt_conn *conn);
int bt_auth_cancel(struct bt_conn *conn);
/** @brief Reply if passkey was confirmed by user.
*
@ -291,8 +295,10 @@ void bt_auth_cancel(struct bt_conn *conn);
*
* @param conn Connection object.
* @param match True if passkey was confirmed to match, false otherwise.
*
* @return Zero on success or negative error code otherwise
*/
void bt_auth_passkey_confirm(struct bt_conn *conn, bool match);
int bt_auth_passkey_confirm(struct bt_conn *conn, bool match);
#if defined(CONFIG_BLUETOOTH_BREDR)
/** @brief Reply with entered PIN code.
@ -302,8 +308,10 @@ void bt_auth_passkey_confirm(struct bt_conn *conn, bool match);
*
* @param conn Connection object.
* @param pin Entered PIN code.
*
* @return Zero on success or negative error code otherwise
*/
void bt_auth_pincode_entry(struct bt_conn *conn, const char *pin);
int bt_auth_pincode_entry(struct bt_conn *conn, const char *pin);
#endif /* CONFIG_BLUETOOTH_BREDR */
#endif /* CONFIG_BLUETOOTH_SMP || CONFIG_BLUETOOTH_BREDR */

View File

@ -2670,75 +2670,80 @@ 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)
int bt_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
{
if (!bt_auth) {
return;
return -EINVAL;
}
#if defined(CONFIG_BLUETOOTH_SMP)
if (conn->type == BT_CONN_TYPE_LE) {
bt_smp_auth_passkey_entry(conn, passkey);
return 0;
}
#endif /* CONFIG_BLUETOOTH_SMP */
return -EINVAL;
}
void bt_auth_passkey_confirm(struct bt_conn *conn, bool match)
int bt_auth_passkey_confirm(struct bt_conn *conn, bool match)
{
if (!bt_auth) {
return;
return -EINVAL;
};
#if defined(CONFIG_BLUETOOTH_SMP)
if (conn->type == BT_CONN_TYPE_LE) {
bt_smp_auth_passkey_confirm(conn, match);
}
#endif /* CONFIG_BLUETOOTH_SMP */
return -EINVAL;
}
void bt_auth_cancel(struct bt_conn *conn)
int bt_auth_cancel(struct bt_conn *conn)
{
if (!bt_auth) {
return;
return -EINVAL;
}
#if defined(CONFIG_BLUETOOTH_SMP)
if (conn->type == BT_CONN_TYPE_LE) {
bt_smp_auth_cancel(conn);
return;
return 0;
}
#endif /* CONFIG_BLUETOOTH_SMP */
#if defined(CONFIG_BLUETOOTH_BREDR)
if (conn->type == BT_CONN_TYPE_BR) {
pin_code_neg_reply(&conn->br.dst);
return pin_code_neg_reply(&conn->br.dst);
}
#endif /* CONFIG_BLUETOOTH_BREDR */
return -EINVAL;
}
#if defined(CONFIG_BLUETOOTH_BREDR)
void bt_auth_pincode_entry(struct bt_conn *conn, const char *pin)
int bt_auth_pincode_entry(struct bt_conn *conn, const char *pin)
{
size_t len;
if (!bt_auth) {
return;
return -EINVAL;
}
if (conn->type != BT_CONN_TYPE_BR) {
return;
return -EINVAL;
}
len = strlen(pin);
if (len > 16) {
pin_code_neg_reply(&conn->br.dst);
return;
return -EINVAL;
}
if (conn->required_sec_level == BT_SECURITY_HIGH && len < 16) {
BT_WARN("PIN code for %s is not 16 bytes wide",
bt_addr_str(&conn->br.dst));
pin_code_neg_reply(&conn->br.dst);
return;
return -EPERM;
}
pin_code_reply(conn, pin, len);
return pin_code_reply(conn, pin, len);
}
#endif
#endif /* CONFIG_BLUETOOTH_SMP || CONFIG_BLUETOOTH_BREDR */