Skip to content

Commit

Permalink
Bluetooth: extending API for OOB pairing
Browse files Browse the repository at this point in the history
This change extends the Bluetooth API to support pairing with the OOB
data that are used in the Authentication Stage of the pairing procedure.
The LE Secure Connections specific API for OOB pairing is also added.
The general OOB API should be able to accomodate the LE legacy pairing
later on.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
  • Loading branch information
kapi-no authored and carlescufi committed May 27, 2019
1 parent 34758e8 commit edea2f0
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/bluetooth/bluetooth.h
Expand Up @@ -497,11 +497,24 @@ void bt_data_parse(struct net_buf_simple *ad,
bool (*func)(struct bt_data *data, void *user_data),
void *user_data);

/** OOB data that is specific for LE SC pairing method. */
struct bt_le_oob_sc_data {
/** Random Number. */
u8_t r[16];

/** Confirm Value. */
u8_t c[16];
};

/** General OOB data. */
struct bt_le_oob {
/** LE address. If local privacy is enabled this is Resolvable Private
* Address.
*/
bt_addr_le_t addr;

/** OOB data that are relevant for LESC pairing. */
struct bt_le_oob_sc_data le_sc_data;
};

/**
Expand All @@ -516,6 +529,9 @@ struct bt_le_oob {
*
* @param id Local identity, in most cases BT_ID_DEFAULT.
* @param oob LE related information
*
* @return Zero on success or error code otherwise, positive in case
* of protocol error or negative (POSIX) in case of stack internal error
*/
int bt_le_oob_get_local(u8_t id, struct bt_le_oob *oob);

Expand Down
103 changes: 103 additions & 0 deletions include/bluetooth/conn.h
Expand Up @@ -413,6 +413,59 @@ void bt_conn_cb_register(struct bt_conn_cb *cb);
*/
void bt_set_bondable(bool enable);

/** Allow/disallow remote OOB data to be used for pairing.
*
* Set/clear the OOB data flag for SMP Pairing Request/Response data.
* The initial value of this flag depends on BT_OOB_DATA_PRESENT Kconfig
* setting.
*
* @param enable Value allowing/disallowing remote OOB data.
*/
void bt_set_oob_data_flag(bool enable);

/**
* @brief Set OOB data during LE SC pairing procedure
*
* This function allows to set OOB data during the LE SC pairing procedure. The
* function should only be called in response to the oob_data_request() callback
* provided that LE SC method is used for pairing.
*
* The user should submit OOB data according to the information received in the
* callback. This may yield three different configurations: with only local OOB
* data present, with only remote OOB data present or with both local and
* remote OOB data present.
*
* @param conn Connection object
* @param oobd_local Local OOB data or NULL if not present
* @param oobd_remote Remote OOB data or NULL if not present
*
* @return Zero on success or error code otherwise, positive in case
* of protocol error or negative (POSIX) in case of stack internal error
*/
int bt_le_oob_set_sc_data(struct bt_conn *conn,
const struct bt_le_oob_sc_data *oobd_local,
const struct bt_le_oob_sc_data *oobd_remote);

/**
* @brief Get OOB data used for LE SC pairing procedure
*
* This function allows to get OOB data during the LE SC pairing procedure that
* were set by the bt_le_oob_set_sc_data() API.
*
* Note: The OOB data will only be available as long as the connection object
* associated with it is valid.
*
* @param conn Connection object
* @param oobd_local Local OOB data or NULL if not set
* @param oobd_remote Remote OOB data or NULL if not set
*
* @return Zero on success or error code otherwise, positive in case
* of protocol error or negative (POSIX) in case of stack internal error
*/
int bt_le_oob_get_sc_data(struct bt_conn *conn,
const struct bt_le_oob_sc_data **oobd_local,
const struct bt_le_oob_sc_data **oobd_remote);

/** @def BT_PASSKEY_INVALID
*
* Special passkey value that can be used to disable a previously
Expand All @@ -435,6 +488,38 @@ void bt_set_bondable(bool enable);
*/
int bt_passkey_set(unsigned int passkey);

/** Info Structure for OOB pairing */
struct bt_conn_oob_info {
/** Type of OOB pairing method */
enum {
/** LE legacy pairing */
BT_CONN_OOB_LE_LEGACY,

/** LE SC pairing */
BT_CONN_OOB_LE_SC,
} type;

union {
/** LESC OOB pairing parameters */
struct {
/** OOB data configuration */
enum {
/** Local OOB data requested */
BT_CONN_OOB_LOCAL_ONLY,

/** Remote OOB data requested */
BT_CONN_OOB_REMOTE_ONLY,

/** Both local and remote OOB data requested */
BT_CONN_OOB_BOTH_PEERS,

/** No OOB data requested */
BT_CONN_OOB_NO_DATA,
} oob_config;
} lesc;
};
};

/** Authenticated pairing callback structure */
struct bt_conn_auth_cb {
/** @brief Display a passkey to the user.
Expand Down Expand Up @@ -500,6 +585,24 @@ struct bt_conn_auth_cb {
*/
void (*passkey_confirm)(struct bt_conn *conn, unsigned int passkey);

/** @brief Request the user to provide OOB data.
*
* When called the user is expected to provide OOB data. The required
* data are indicated by the information structure.
*
* For LESC OOB pairing method, the user should provide local OOB data,
* remote OOB data or both depending on their availability. Their value
* should be given to the stack using the bt_le_oob_set_sc_data() API.
*
* This callback must be set to non-NULL in order to support OOB
* pairing.
*
* @param conn Connection where pairing is currently active.
* @param info OOB pairing information.
*/
void (*oob_data_request)(struct bt_conn *conn,
struct bt_conn_oob_info *info);

/** @brief Cancel the ongoing user request.
*
* This callback will be called to notify the application that it
Expand Down

0 comments on commit edea2f0

Please sign in to comment.