Bluetooth: Cleanup dependency build for LE/BREDR

Reorganizes mostly by using preprocessor (indirectly Kconfig options)
strictly LE-SMP related interfaces and security interfaces shared
between LE and BREDR connections.

Change-Id: I90daa36d72403cd5b73e6791714fcaf7f1fbe8e5
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
Arkadiusz Lichwa 2016-02-19 12:05:19 +01:00 committed by Gerrit Code Review
commit aaa2650f0f
6 changed files with 38 additions and 28 deletions

View file

@ -246,7 +246,7 @@ typedef enum __packed {
*/ */
} bt_security_t; } bt_security_t;
#if defined(CONFIG_BLUETOOTH_SMP) #if defined(CONFIG_BLUETOOTH_SMP) || defined(CONFIG_BLUETOOTH_BREDR)
/** @brief Set security level for a connection. /** @brief Set security level for a connection.
* *
* This function enable security (encryption) for a connection. If device is * This function enable security (encryption) for a connection. If device is
@ -279,7 +279,7 @@ int bt_conn_security(struct bt_conn *conn, bt_security_t sec);
* @return Encryption key size. * @return Encryption key size.
*/ */
uint8_t bt_conn_enc_key_size(struct bt_conn *conn); uint8_t bt_conn_enc_key_size(struct bt_conn *conn);
#endif /* CONFIG_BLUETOOTH_SMP */ #endif /* CONFIG_BLUETOOTH_SMP || CONFIG_BLUETOOTH_BREDR */
/** Connection callback structure */ /** Connection callback structure */
struct bt_conn_cb { struct bt_conn_cb {
@ -291,8 +291,10 @@ struct bt_conn_cb {
void (*identity_resolved)(struct bt_conn *conn, void (*identity_resolved)(struct bt_conn *conn,
const bt_addr_le_t *rpa, const bt_addr_le_t *rpa,
const bt_addr_le_t *identity); const bt_addr_le_t *identity);
#endif /* CONFIG_BLUETOOTH_SMP */
#if defined(CONFIG_BLUETOOTH_SMP) || defined(CONFIG_BLUETOOTH_BREDR)
void (*security_changed)(struct bt_conn *conn, bt_security_t level); void (*security_changed)(struct bt_conn *conn, bt_security_t level);
#endif #endif /* defined(CONFIG_BLUETOOTH_SMP) || defined(CONFIG_BLUETOOTH_BREDR) */
struct bt_conn_cb *_next; struct bt_conn_cb *_next;
}; };

View file

@ -118,11 +118,6 @@ void notify_le_param_updated(struct bt_conn *conn)
} }
#if defined(CONFIG_BLUETOOTH_SMP) #if defined(CONFIG_BLUETOOTH_SMP)
uint8_t bt_conn_enc_key_size(struct bt_conn *conn)
{
return conn->keys ? conn->keys->enc_size : 0;
}
void bt_conn_identity_resolved(struct bt_conn *conn) void bt_conn_identity_resolved(struct bt_conn *conn)
{ {
const bt_addr_le_t *rpa; const bt_addr_le_t *rpa;
@ -141,17 +136,6 @@ void bt_conn_identity_resolved(struct bt_conn *conn)
} }
} }
void bt_conn_security_changed(struct bt_conn *conn)
{
struct bt_conn_cb *cb;
for (cb = callback_list; cb; cb = cb->_next) {
if (cb->security_changed) {
cb->security_changed(conn, conn->sec_level);
}
}
}
int bt_conn_le_start_encryption(struct bt_conn *conn, uint64_t rand, int bt_conn_le_start_encryption(struct bt_conn *conn, uint64_t rand,
uint16_t ediv, const uint8_t *ltk, size_t len) uint16_t ediv, const uint8_t *ltk, size_t len)
{ {
@ -175,11 +159,29 @@ int bt_conn_le_start_encryption(struct bt_conn *conn, uint64_t rand,
return bt_hci_cmd_send_sync(BT_HCI_OP_LE_START_ENCRYPTION, buf, NULL); return bt_hci_cmd_send_sync(BT_HCI_OP_LE_START_ENCRYPTION, buf, NULL);
} }
#endif /* CONFIG_BLUETOOTH_SMP */
#if defined(CONFIG_BLUETOOTH_SMP) || defined(CONFIG_BLUETOOTH_BREDR)
uint8_t bt_conn_enc_key_size(struct bt_conn *conn)
{
return conn->keys ? conn->keys->enc_size : 0;
}
void bt_conn_security_changed(struct bt_conn *conn)
{
struct bt_conn_cb *cb;
for (cb = callback_list; cb; cb = cb->_next) {
if (cb->security_changed) {
cb->security_changed(conn, conn->sec_level);
}
}
}
static int start_security(struct bt_conn *conn) static int start_security(struct bt_conn *conn)
{ {
switch (conn->role) { switch (conn->role) {
#if defined(CONFIG_BLUETOOTH_CENTRAL) #if defined(CONFIG_BLUETOOTH_CENTRAL) && defined(CONFIG_BLUETOOTH_SMP)
case BT_HCI_ROLE_MASTER: case BT_HCI_ROLE_MASTER:
{ {
if (!conn->keys) { if (!conn->keys) {
@ -215,11 +217,11 @@ static int start_security(struct bt_conn *conn)
conn->keys->ltk.val, conn->keys->ltk.val,
conn->keys->enc_size); conn->keys->enc_size);
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */ #endif /* CONFIG_BLUETOOTH_CENTRAL && CONFIG_BLUETOOTH_SMP */
#if defined(CONFIG_BLUETOOTH_PERIPHERAL) #if defined(CONFIG_BLUETOOTH_PERIPHERAL) && defined(CONFIG_BLUETOOTH_SMP)
case BT_HCI_ROLE_SLAVE: case BT_HCI_ROLE_SLAVE:
return bt_smp_send_security_req(conn); return bt_smp_send_security_req(conn);
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */ #endif /* CONFIG_BLUETOOTH_PERIPHERAL && CONFIG_BLUETOOTH_SMP */
default: default:
return -EINVAL; return -EINVAL;
} }

View file

@ -155,10 +155,12 @@ int bt_conn_le_start_encryption(struct bt_conn *conn, uint64_t rand,
/* Notify higher layers that RPA was resolved */ /* Notify higher layers that RPA was resolved */
void bt_conn_identity_resolved(struct bt_conn *conn); void bt_conn_identity_resolved(struct bt_conn *conn);
#endif /* CONFIG_BLUETOOTH_SMP */
#if defined(CONFIG_BLUETOOTH_SMP) || defined(CONFIG_BLUETOOTH_BREDR)
/* Notify higher layers that connection security changed */ /* Notify higher layers that connection security changed */
void bt_conn_security_changed(struct bt_conn *conn); void bt_conn_security_changed(struct bt_conn *conn);
#endif /* CONFIG_BLUETOOTH_SMP */ #endif /* CONFIG_BLUETOOTH_SMP || CONFIG_BLUETOOTH_BREDR */
/* Prepare a PDU to be sent over a connection */ /* Prepare a PDU to be sent over a connection */
struct net_buf *bt_conn_create_pdu(struct nano_fifo *fifo, size_t reserve); struct net_buf *bt_conn_create_pdu(struct nano_fifo *fifo, size_t reserve);

View file

@ -46,9 +46,9 @@
#include "l2cap_internal.h" #include "l2cap_internal.h"
#endif /* CONFIG_BLUETOOTH_CONN */ #endif /* CONFIG_BLUETOOTH_CONN */
#if defined(CONFIG_BLUETOOTH_SMP) #if defined(CONFIG_BLUETOOTH_CONN)
#include "smp.h" #include "smp.h"
#endif /* CONFIG_BLUETOOTH_SMP */ #endif /* CONFIG_BLUETOOTH_CONN */
#if !defined(CONFIG_BLUETOOTH_DEBUG_HCI_CORE) #if !defined(CONFIG_BLUETOOTH_DEBUG_HCI_CORE)
#undef BT_DBG #undef BT_DBG

View file

@ -62,9 +62,9 @@ struct bt_link_key {
struct bt_keys { struct bt_keys {
bt_addr_le_t addr; bt_addr_le_t addr;
#if defined(CONFIG_BLUETOOTH_SMP) #if defined(CONFIG_BLUETOOTH_SMP) || defined(CONFIG_BLUETOOTH_BREDR)
uint8_t enc_size; uint8_t enc_size;
#endif #endif /* CONFIG_BLUETOOTH_SMP || CONFIG_BLUETOOTH_BREDR */
atomic_t flags; atomic_t flags;
uint16_t keys; uint16_t keys;

View file

@ -104,6 +104,10 @@ static int bt_smp_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
return -ENOMEM; return -ENOMEM;
} }
void bt_smp_update_keys(struct bt_conn *conn)
{
}
int bt_smp_init(void) int bt_smp_init(void)
{ {
static struct bt_l2cap_fixed_chan chan = { static struct bt_l2cap_fixed_chan chan = {