Bluetooth: Move security related code to bluetooth.h

Also rename bt_conn_security function to bt_security and
bt_conn_security_t to bt__security_t.

Change-Id: I543c7b97241c4389ef0eb491b6869f93105ae533
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
This commit is contained in:
Szymon Janc 2015-06-26 19:24:50 +02:00 committed by Anas Nashif
commit a14314e913
4 changed files with 36 additions and 34 deletions

View file

@ -131,6 +131,38 @@ int bt_connect_le(const bt_addr_le_t *peer);
*/
int bt_disconnect(struct bt_conn *conn, uint8_t reason);
/*! Security level. */
typedef enum {
BT_SECURITY_LOW, /*! No encryption and no authentication. */
BT_SECURITY_MEDIUM, /*! encryption and no authentication (no MITM). */
BT_SECURITY_HIGH, /*! encryption and authentication (MITM). */
BT_SECURITY_FIPS, /*! Authenticated LE Secure Connections and
* encryption.
*/
} bt_security_t;
/*! @brief Set security level for a connection.
*
* This function enable security (encryption) for a connection. If device is
* already paired with sufficiently strong key encryption will be enabled. If
* link is already encrypted with sufficiently strong key this function does
* nothing.
*
* If device is not paired pairing will be initiated. If device is paired and
* keys are too weak but input output capabilities allow for strong enough keys
* pairing will be initiated.
*
* This function may return error if required level of security is not possible
* to achieve due to local or remote device limitation (eg input output
* capabilities).
*
* @param conn Connection object.
* @param sec Requested security level.
*
* @return 0 on success or negative error
*/
int bt_security(struct bt_conn *conn, bt_security_t sec);
/*! @def BT_ADDR_STR_LEN
*
* @brief Recommended length of user string buffer for Bluetooth address

View file

@ -93,34 +93,4 @@ struct bt_conn_cb {
*/
void bt_conn_cb_register(struct bt_conn_cb *cb);
typedef enum {
BT_CONN_SEC_LOW,
BT_CONN_SEC_MEDIUM,
BT_CONN_SEC_HIGH,
BT_CONN_SEC_FIPS,
} bt_conn_security_t;
/*! @brief Set security level for a connection.
*
* This function enable security (encryption) for a connection. If device is
* already paired with sufficiently strong key encryption will be enabled. If
* link is already encrypted with sufficiently strong key this function does
* nothing.
*
* If device is not paired pairing will be initiated. If device is paired and
* keys are too weak but input output capabilities allow for strong enough keys
* pairing will be initiated.
*
* This function may return error if required level of security is not possible
* to achieve due to local or remote device limitation (eg input output
* capabilities).
*
* @param conn Connection object.
* @param sec Requested security level.
*
* @return 0 on success or negative error
*/
int bt_conn_security(struct bt_conn *conn, bt_conn_security_t sec);
#endif /* __BT_CONN_H */

View file

@ -390,19 +390,19 @@ const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn)
return &conn->dst;
}
int bt_conn_security(struct bt_conn *conn, bt_conn_security_t sec)
int bt_security(struct bt_conn *conn, bt_security_t sec)
{
if (conn->state != BT_CONN_CONNECTED) {
return -ENOTCONN;
}
/* nothing to do */
if (sec == BT_CONN_SEC_LOW) {
if (sec == BT_SECURITY_LOW) {
return 0;
}
/* for now we only support JustWorks */
if (sec > BT_CONN_SEC_MEDIUM) {
if (sec > BT_SECURITY_MEDIUM) {
return -EINVAL;
}

View file

@ -272,7 +272,7 @@ static void cmd_security(int argc, char *argv[])
sec = *argv[3] - '0';
err = bt_conn_security(conn, sec);
err = bt_security(conn, sec);
if (err) {
printk("Setting security failed (err %d)\n", err);
}