From fcc1fada58db4e76c123740489a3e0324893dee4 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 17 Jan 2017 19:03:55 +0200 Subject: [PATCH] Bluetooth: conn: Take advantage of IS_ENABLED whenever possible Try to use IS_ENABLED instead of #ifdefs whenever possible. Change-Id: I78a3ccc6fcb84b431198f1a6c46aa6d50e9e9cd1 Signed-off-by: Johan Hedberg --- subsys/bluetooth/host/conn.c | 83 +++++++++++++-------------- subsys/bluetooth/host/conn_internal.h | 2 - 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 70fc216a5e6..59a9ddf90f7 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -638,8 +638,8 @@ uint8_t bt_conn_enc_key_size(struct bt_conn *conn) return 0; } -#if defined(CONFIG_BLUETOOTH_BREDR) - if (conn->type == BT_CONN_TYPE_BR) { + if (IS_ENABLED(CONFIG_BLUETOOTH_BREDR) && + conn->type == BT_CONN_TYPE_BR) { struct bt_hci_cp_read_encryption_key_size *cp; struct bt_hci_rp_read_encryption_key_size *rp; struct net_buf *buf; @@ -668,13 +668,12 @@ uint8_t bt_conn_enc_key_size(struct bt_conn *conn) return key_size; } -#endif /* CONFIG_BLUETOOTH_BREDR */ -#if defined(CONFIG_BLUETOOTH_SMP) - return conn->le.keys ? conn->le.keys->enc_size : 0; -#else + if (IS_ENABLED(CONFIG_BLUETOOTH_SMP)) { + return conn->le.keys ? conn->le.keys->enc_size : 0; + } + return 0; -#endif /* CONFIG_BLUETOOTH_SMP */ } void bt_conn_security_changed(struct bt_conn *conn) @@ -765,11 +764,10 @@ int bt_conn_security(struct bt_conn *conn, bt_security_t sec) return -ENOTCONN; } -#if defined(CONFIG_BLUETOOTH_SMP_SC_ONLY) - if (sec < BT_SECURITY_FIPS) { + if (IS_ENABLED(CONFIG_BLUETOOTH_SMP_SC_ONLY) && + sec < BT_SECURITY_FIPS) { return -EOPNOTSUPP; } -#endif/* CONFIG_BLUETOOTH_SMP_SC_ONLY */ /* nothing to do */ if (conn->sec_level >= sec || conn->required_sec_level >= sec) { @@ -1424,16 +1422,15 @@ int bt_conn_le_param_update(struct bt_conn *conn, int bt_conn_disconnect(struct bt_conn *conn, uint8_t reason) { -#if defined(CONFIG_BLUETOOTH_CENTRAL) /* Disconnection is initiated by us, so auto connection shall * be disabled. Otherwise the passive scan would be enabled * and we could send LE Create Connection as soon as the remote * starts advertising. */ - if (conn->type == BT_CONN_TYPE_LE) { + if (IS_ENABLED(CONFIG_BLUETOOTH_CENTRAL) && + conn->type == BT_CONN_TYPE_LE) { bt_le_set_auto_conn(&conn->le.dst, NULL); } -#endif switch (conn->state) { case BT_CONN_CONNECT_SCAN: @@ -1632,12 +1629,13 @@ int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey) if (!bt_auth) { return -EINVAL; } -#if defined(CONFIG_BLUETOOTH_SMP) - if (conn->type == BT_CONN_TYPE_LE) { + + if (IS_ENABLED(CONFIG_BLUETOOTH_SMP) && + conn->type == BT_CONN_TYPE_LE) { bt_smp_auth_passkey_entry(conn, passkey); return 0; } -#endif /* CONFIG_BLUETOOTH_SMP */ + #if defined(CONFIG_BLUETOOTH_BREDR) if (conn->type == BT_CONN_TYPE_BR) { /* User entered passkey, reset user state. */ @@ -1658,12 +1656,13 @@ int bt_conn_auth_passkey_confirm(struct bt_conn *conn) { if (!bt_auth) { return -EINVAL; - }; -#if defined(CONFIG_BLUETOOTH_SMP) - if (conn->type == BT_CONN_TYPE_LE) { + } + + if (IS_ENABLED(CONFIG_BLUETOOTH_SMP) && + conn->type == BT_CONN_TYPE_LE) { return bt_smp_auth_passkey_confirm(conn); } -#endif /* CONFIG_BLUETOOTH_SMP */ + #if defined(CONFIG_BLUETOOTH_BREDR) if (conn->type == BT_CONN_TYPE_BR) { /* Allow user confirm passkey value, then reset user state. */ @@ -1683,11 +1682,12 @@ int bt_conn_auth_cancel(struct bt_conn *conn) if (!bt_auth) { return -EINVAL; } -#if defined(CONFIG_BLUETOOTH_SMP) - if (conn->type == BT_CONN_TYPE_LE) { + + if (IS_ENABLED(CONFIG_BLUETOOTH_SMP) && + conn->type == BT_CONN_TYPE_LE) { return bt_smp_auth_cancel(conn); } -#endif /* CONFIG_BLUETOOTH_SMP */ + #if defined(CONFIG_BLUETOOTH_BREDR) if (conn->type == BT_CONN_TYPE_BR) { /* Allow user cancel authentication, then reset user state. */ @@ -1736,25 +1736,6 @@ int bt_conn_auth_pairing_confirm(struct bt_conn *conn) } #endif /* CONFIG_BLUETOOTH_SMP || CONFIG_BLUETOOTH_BREDR */ -static void background_scan_init(void) -{ -#if defined(CONFIG_BLUETOOTH_CENTRAL) - int i; - - for (i = 0; i < ARRAY_SIZE(conns); i++) { - struct bt_conn *conn = &conns[i]; - - if (!atomic_get(&conn->ref)) { - continue; - } - - if (atomic_test_bit(conn->flags, BT_CONN_AUTO_CONNECT)) { - bt_conn_set_state(conn, BT_CONN_CONNECT_SCAN); - } - } -#endif /* CONFIG_BLUETOOTH_CENTRAL */ -} - int bt_conn_init(void) { int err; @@ -1768,7 +1749,23 @@ int bt_conn_init(void) bt_l2cap_init(); - background_scan_init(); + /* Initialize background scan */ + if (IS_ENABLED(CONFIG_BLUETOOTH_CENTRAL)) { + int i; + + for (i = 0; i < ARRAY_SIZE(conns); i++) { + struct bt_conn *conn = &conns[i]; + + if (!atomic_get(&conn->ref)) { + continue; + } + + if (atomic_test_bit(conn->flags, + BT_CONN_AUTO_CONNECT)) { + bt_conn_set_state(conn, BT_CONN_CONNECT_SCAN); + } + } + } return 0; } diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index 129be5dd94c..ed3832bc578 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -132,7 +132,6 @@ int bt_conn_send(struct bt_conn *conn, struct net_buf *buf); /* Add a new LE connection */ struct bt_conn *bt_conn_add_le(const bt_addr_le_t *peer); -#if defined(CONFIG_BLUETOOTH_BREDR) /* Add a new BR/EDR connection */ struct bt_conn *bt_conn_add_br(const bt_addr_t *peer); @@ -143,7 +142,6 @@ void bt_conn_pin_code_req(struct bt_conn *conn); uint8_t bt_conn_get_io_capa(void); uint8_t bt_conn_ssp_get_auth(const struct bt_conn *conn); void bt_conn_ssp_auth(struct bt_conn *conn, uint32_t passkey); -#endif void bt_conn_disconnect_all(void);