Bluetooth: Add initial Kconfig split options

This allows to specify which roles are supported. Broadcaster and
Observer roles are always supported.

Image size reduction for samples apps:
beacon     43148 -> 15196
central    46892 -> 46356
peripheral 47532 -> 45940

Change-Id: If260c13d63651b9b54df5bafc2c412b01dcb1eb0
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
Szymon Janc 2015-09-07 18:25:59 +02:00 committed by Anas Nashif
commit 8ff443b1c9
12 changed files with 169 additions and 29 deletions

View file

@ -39,10 +39,25 @@ menuconfig BLUETOOTH
This option enables Bluetooth Low Energy support. This option enables Bluetooth Low Energy support.
if BLUETOOTH if BLUETOOTH
config BLUETOOTH_CONN
bool
default n
config BLUETOOTH_PERIPHERAL
bool "Peripheral Role support"
default n
select BLUETOOTH_CONN
config BLUETOOTH_CENTRAL
bool "Central Role support"
default n
select BLUETOOTH_CONN
if BLUETOOTH_PERIPHERAL || BLUETOOTH_CENTRAL
config BLUETOOTH_MAX_CONN config BLUETOOTH_MAX_CONN
int int
prompt "Maximum number of simultaneous connections" prompt "Maximum number of simultaneous connections"
depends on BLUETOOTH depends on BLUETOOTH_CONN
default 1 default 1
range 1 16 range 1 16
help help
@ -52,7 +67,7 @@ config BLUETOOTH_MAX_CONN
config BLUETOOTH_MAX_PAIRED config BLUETOOTH_MAX_PAIRED
int int
prompt "Maximum number of paired devices" prompt "Maximum number of paired devices"
depends on BLUETOOTH depends on BLUETOOTH_CONN
default 1 default 1
range 1 32 range 1 32
help help
@ -149,3 +164,4 @@ config BLUETOOTH_DEBUG_GATT
This option enables debug support for the Bluetooth This option enables debug support for the Bluetooth
Generic Attribute Profile (GATT). Generic Attribute Profile (GATT).
endif endif
endif

View file

@ -1,9 +1,10 @@
obj-y = att.o \ obj-y = buf.o \
buf.o \ hci_core.o
conn.o \
gatt.o \ obj-$(CONFIG_BLUETOOTH_CONN) += conn.o \
hci_core.o \ l2cap.o \
keys.o \ keys.o \
l2cap.o \ smp.o \
smp.o \ att.o \
uuid.o gatt.o \
uuid.o

View file

@ -568,6 +568,7 @@ int bt_conn_security(struct bt_conn *conn, bt_security_t sec)
conn->required_sec_level = sec; conn->required_sec_level = sec;
#if defined(CONFIG_BLUETOOTH_CENTRAL)
if (conn->role == BT_HCI_ROLE_MASTER) { if (conn->role == BT_HCI_ROLE_MASTER) {
struct bt_keys *keys; struct bt_keys *keys;
@ -585,8 +586,13 @@ int bt_conn_security(struct bt_conn *conn, bt_security_t sec)
return bt_smp_send_pairing_req(conn); return bt_smp_send_pairing_req(conn);
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
return bt_smp_send_security_req(conn); return bt_smp_send_security_req(conn);
#else
return -EIO;
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
} }
void bt_conn_set_auto_conn(struct bt_conn *conn, bool auto_conn) void bt_conn_set_auto_conn(struct bt_conn *conn, bool auto_conn)

View file

@ -209,6 +209,7 @@ int bt_hci_cmd_send_sync(uint16_t opcode, struct bt_buf *buf,
return err; return err;
} }
#if defined(CONFIG_BLUETOOTH_CONN)
static void hci_acl(struct bt_buf *buf) static void hci_acl(struct bt_buf *buf)
{ {
struct bt_hci_acl_hdr *hdr = (void *)buf->data; struct bt_hci_acl_hdr *hdr = (void *)buf->data;
@ -242,6 +243,7 @@ static void hci_acl(struct bt_buf *buf)
bt_conn_recv(conn, buf, flags); bt_conn_recv(conn, buf, flags);
bt_conn_put(conn); bt_conn_put(conn);
} }
#endif /* CONFIG_BLUETOOTH_CONN */
#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_PRINTK) #if defined(CONFIG_INIT_STACKS) && defined(CONFIG_PRINTK)
#include <offsets.h> #include <offsets.h>
@ -318,6 +320,7 @@ static void analyze_stacks(struct bt_conn *conn, struct bt_conn **ref)
/* HCI event processing */ /* HCI event processing */
#if defined(CONFIG_BLUETOOTH_CONN)
static void update_sec_level(struct bt_conn *conn) static void update_sec_level(struct bt_conn *conn)
{ {
struct bt_keys *keys; struct bt_keys *keys;
@ -367,6 +370,7 @@ static void hci_encrypt_change(struct bt_buf *buf)
bt_conn_put(conn); bt_conn_put(conn);
} }
#endif /* CONFIG_BLUETOOTH_CONN */
static void hci_reset_complete(struct bt_buf *buf) static void hci_reset_complete(struct bt_buf *buf)
{ {
@ -471,6 +475,7 @@ static void hci_cmd_status(struct bt_buf *buf)
} }
} }
#if defined(CONFIG_BLUETOOTH_CONN)
static void hci_num_completed_packets(struct bt_buf *buf) static void hci_num_completed_packets(struct bt_buf *buf)
{ {
struct bt_hci_evt_num_completed_packets *evt = (void *)buf->data; struct bt_hci_evt_num_completed_packets *evt = (void *)buf->data;
@ -550,6 +555,7 @@ static void copy_id_addr(struct bt_conn *conn, const bt_addr_le_t *addr)
bt_addr_le_copy(&conn->dst, addr); bt_addr_le_copy(&conn->dst, addr);
} }
} }
#endif /* CONFIG_BLUETOOTH_CONN */
static int bt_hci_start_scanning(uint8_t scan_type) static int bt_hci_start_scanning(uint8_t scan_type)
{ {
@ -642,6 +648,7 @@ static int bt_hci_stop_scanning(void)
return err; return err;
} }
#if defined(CONFIG_BLUETOOTH_CONN)
static int hci_le_create_conn(const bt_addr_le_t *addr) static int hci_le_create_conn(const bt_addr_le_t *addr)
{ {
struct bt_buf *buf; struct bt_buf *buf;
@ -663,6 +670,7 @@ static int hci_le_create_conn(const bt_addr_le_t *addr)
return bt_hci_cmd_send_sync(BT_HCI_OP_LE_CREATE_CONN, buf, NULL); return bt_hci_cmd_send_sync(BT_HCI_OP_LE_CREATE_CONN, buf, NULL);
} }
#endif /* CONFIG_BLUETOOTH_CONN */
/* Used to determine whether to start scan and which scan type should be used */ /* Used to determine whether to start scan and which scan type should be used */
int bt_le_scan_update(void) int bt_le_scan_update(void)
@ -680,6 +688,7 @@ int bt_le_scan_update(void)
} }
} }
#if defined(CONFIG_BLUETOOTH_CONN)
if (!scan_dev_found_cb) { if (!scan_dev_found_cb) {
struct bt_conn *conn; struct bt_conn *conn;
@ -693,10 +702,12 @@ int bt_le_scan_update(void)
return bt_hci_start_scanning(BT_LE_SCAN_PASSIVE); return bt_hci_start_scanning(BT_LE_SCAN_PASSIVE);
} }
#endif /* CONFIG_BLUETOOTH_CONN */
return bt_hci_start_scanning(BT_LE_SCAN_ACTIVE); return bt_hci_start_scanning(BT_LE_SCAN_ACTIVE);
} }
#if defined(CONFIG_BLUETOOTH_CONN)
static void hci_disconn_complete(struct bt_buf *buf) static void hci_disconn_complete(struct bt_buf *buf)
{ {
struct bt_hci_evt_disconn_complete *evt = (void *)buf->data; struct bt_hci_evt_disconn_complete *evt = (void *)buf->data;
@ -1019,6 +1030,7 @@ static void check_pending_conn(const bt_addr_le_t *addr, uint8_t evtype)
done: done:
bt_conn_put(conn); bt_conn_put(conn);
} }
#endif /* CONFIG_BLUETOOTH_CONN */
static void le_adv_report(struct bt_buf *buf) static void le_adv_report(struct bt_buf *buf)
{ {
@ -1031,13 +1043,15 @@ static void le_adv_report(struct bt_buf *buf)
while (num_reports--) { while (num_reports--) {
int8_t rssi = info->data[info->length]; int8_t rssi = info->data[info->length];
#if defined(CONFIG_BLUETOOTH_CONN)
const bt_addr_le_t *addr; const bt_addr_le_t *addr;
struct bt_keys *keys; struct bt_keys *keys;
#endif /* CONFIG_BLUETOOTH_CONN */
BT_DBG("%s event %u, len %u, rssi %d dBm\n", BT_DBG("%s event %u, len %u, rssi %d dBm\n",
bt_addr_le_str(&info->addr), bt_addr_le_str(&info->addr),
info->evt_type, info->length, rssi); info->evt_type, info->length, rssi);
#if defined(CONFIG_BLUETOOTH_CONN)
keys = bt_keys_find_irk(&info->addr); keys = bt_keys_find_irk(&info->addr);
if (keys) { if (keys) {
addr = &keys->addr; addr = &keys->addr;
@ -1054,7 +1068,12 @@ static void le_adv_report(struct bt_buf *buf)
} }
check_pending_conn(addr, info->evt_type); check_pending_conn(addr, info->evt_type);
#else
if (scan_dev_found_cb) {
scan_dev_found_cb(&info->addr, rssi, info->evt_type,
info->data, info->length);
}
#endif /* CONFIG_BLUETOOTH_CONN */
/* Get next report iteration by moving pointer to right offset /* Get next report iteration by moving pointer to right offset
* in buf according to spec 4.2, Vol 2, Part E, 7.7.65.2. * in buf according to spec 4.2, Vol 2, Part E, 7.7.65.2.
*/ */
@ -1063,6 +1082,7 @@ static void le_adv_report(struct bt_buf *buf)
} }
} }
#if defined(CONFIG_BLUETOOTH_CONN)
static void le_ltk_request(struct bt_buf *buf) static void le_ltk_request(struct bt_buf *buf)
{ {
struct bt_hci_evt_le_ltk_request *evt = (void *)buf->data; struct bt_hci_evt_le_ltk_request *evt = (void *)buf->data;
@ -1119,6 +1139,7 @@ static void le_ltk_request(struct bt_buf *buf)
done: done:
bt_conn_put(conn); bt_conn_put(conn);
} }
#endif /* CONFIG_BLUETOOTH_CONN */
static void hci_le_meta_event(struct bt_buf *buf) static void hci_le_meta_event(struct bt_buf *buf)
{ {
@ -1127,15 +1148,13 @@ static void hci_le_meta_event(struct bt_buf *buf)
bt_buf_pull(buf, sizeof(*evt)); bt_buf_pull(buf, sizeof(*evt));
switch (evt->subevent) { switch (evt->subevent) {
#if defined(CONFIG_BLUETOOTH_CONN)
case BT_HCI_EVT_LE_CONN_COMPLETE: case BT_HCI_EVT_LE_CONN_COMPLETE:
le_conn_complete(buf); le_conn_complete(buf);
break; break;
case BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE: case BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE:
le_conn_update_complete(buf); le_conn_update_complete(buf);
break; break;
case BT_HCI_EVT_LE_ADVERTISING_REPORT:
le_adv_report(buf);
break;
case BT_HCI_EVT_LE_LTK_REQUEST: case BT_HCI_EVT_LE_LTK_REQUEST:
le_ltk_request(buf); le_ltk_request(buf);
break; break;
@ -1145,6 +1164,10 @@ static void hci_le_meta_event(struct bt_buf *buf)
case BT_HCI_EVT_LE_CONN_PARAM_REQ: case BT_HCI_EVT_LE_CONN_PARAM_REQ:
le_conn_param_req(buf); le_conn_param_req(buf);
break; break;
#endif /* CONFIG_BLUETOOTH_CONN */
case BT_HCI_EVT_LE_ADVERTISING_REPORT:
le_adv_report(buf);
break;
default: default:
BT_DBG("Unhandled LE event %x\n", evt->subevent); BT_DBG("Unhandled LE event %x\n", evt->subevent);
break; break;
@ -1160,6 +1183,7 @@ static void hci_event(struct bt_buf *buf)
bt_buf_pull(buf, sizeof(*hdr)); bt_buf_pull(buf, sizeof(*hdr));
switch (hdr->evt) { switch (hdr->evt) {
#if defined(CONFIG_BLUETOOTH_CONN)
case BT_HCI_EVT_DISCONN_COMPLETE: case BT_HCI_EVT_DISCONN_COMPLETE:
hci_disconn_complete(buf); hci_disconn_complete(buf);
break; break;
@ -1169,6 +1193,7 @@ static void hci_event(struct bt_buf *buf)
case BT_HCI_EVT_ENCRYPT_KEY_REFRESH_COMPLETE: case BT_HCI_EVT_ENCRYPT_KEY_REFRESH_COMPLETE:
hci_encrypt_key_refresh_complete(buf); hci_encrypt_key_refresh_complete(buf);
break; break;
#endif /* CONFIG_BLUETOOTH_CONN */
case BT_HCI_EVT_LE_META_EVENT: case BT_HCI_EVT_LE_META_EVENT:
hci_le_meta_event(buf); hci_le_meta_event(buf);
break; break;
@ -1256,9 +1281,11 @@ static void rx_prio_fiber(void)
case BT_HCI_EVT_CMD_STATUS: case BT_HCI_EVT_CMD_STATUS:
hci_cmd_status(buf); hci_cmd_status(buf);
break; break;
#if defined(CONFIG_BLUETOOTH_CONN)
case BT_HCI_EVT_NUM_COMPLETED_PACKETS: case BT_HCI_EVT_NUM_COMPLETED_PACKETS:
hci_num_completed_packets(buf); hci_num_completed_packets(buf);
break; break;
#endif /* CONFIG_BLUETOOTH_CONN */
default: default:
BT_ERR("Unknown event 0x%02x\n", hdr->evt); BT_ERR("Unknown event 0x%02x\n", hdr->evt);
break; break;
@ -1331,6 +1358,7 @@ static void le_read_buffer_size_complete(struct bt_buf *buf)
bt_dev.le_pkts = rp->le_max_num; bt_dev.le_pkts = rp->le_max_num;
} }
#if defined(CONFIG_BLUETOOTH_CONN)
static int set_flow_control(void) static int set_flow_control(void)
{ {
struct bt_hci_cp_host_buffer_size *hbs; struct bt_hci_cp_host_buffer_size *hbs;
@ -1365,6 +1393,7 @@ static int set_flow_control(void)
*enable = 0x01; *enable = 0x01;
return bt_hci_cmd_send_sync(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, buf, NULL); return bt_hci_cmd_send_sync(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, buf, NULL);
} }
#endif /* CONFIG_BLUETOOTH_CONN */
static int hci_init(void) static int hci_init(void)
{ {
@ -1430,26 +1459,38 @@ static int hci_init(void)
ev = bt_buf_add(buf, sizeof(*ev)); ev = bt_buf_add(buf, sizeof(*ev));
memset(ev, 0, sizeof(*ev)); memset(ev, 0, sizeof(*ev));
#if defined(CONFIG_BLUETOOTH_CONN)
ev->events[0] |= 0x10; /* Disconnection Complete */ ev->events[0] |= 0x10; /* Disconnection Complete */
ev->events[1] |= 0x08; /* Read Remote Version Information Complete */ ev->events[1] |= 0x08; /* Read Remote Version Information Complete */
#endif /* CONFIG_BLUETOOTH_CONN */
ev->events[1] |= 0x20; /* Command Complete */ ev->events[1] |= 0x20; /* Command Complete */
ev->events[1] |= 0x40; /* Command Status */ ev->events[1] |= 0x40; /* Command Status */
ev->events[1] |= 0x80; /* Hardware Error */ ev->events[1] |= 0x80; /* Hardware Error */
#if defined(CONFIG_BLUETOOTH_CONN)
ev->events[2] |= 0x04; /* Number of Completed Packets */ ev->events[2] |= 0x04; /* Number of Completed Packets */
#endif /* CONFIG_BLUETOOTH_CONN */
ev->events[3] |= 0x02; /* Data Buffer Overflow */ ev->events[3] |= 0x02; /* Data Buffer Overflow */
ev->events[7] |= 0x20; /* LE Meta-Event */ ev->events[7] |= 0x20; /* LE Meta-Event */
#if defined(CONFIG_BLUETOOTH_CONN)
if (bt_dev.le_features[0] & BT_HCI_LE_ENCRYPTION) { if (bt_dev.le_features[0] & BT_HCI_LE_ENCRYPTION) {
ev->events[0] |= 0x80; /* Encryption Change */ ev->events[0] |= 0x80; /* Encryption Change */
ev->events[5] |= 0x80; /* Encryption Key Refresh Complete */ ev->events[5] |= 0x80; /* Encryption Key Refresh Complete */
} }
#endif /* CONFIG_BLUETOOTH_CONN */
bt_hci_cmd_send_sync(BT_HCI_OP_SET_EVENT_MASK, buf, NULL); bt_hci_cmd_send_sync(BT_HCI_OP_SET_EVENT_MASK, buf, NULL);
#if defined(CONFIG_BLUETOOTH_CONN)
err = set_flow_control(); err = set_flow_control();
if (err) { if (err) {
return err; return err;
} }
#endif /* CONFIG_BLUETOOTH_CONN */
if (lmp_bredr_capable(bt_dev)) { if (lmp_bredr_capable(bt_dev)) {
struct bt_hci_cp_write_le_host_supp *cp; struct bt_hci_cp_write_le_host_supp *cp;
@ -1560,11 +1601,14 @@ static int bt_init(void)
} }
err = hci_init(); err = hci_init();
if (err) {
return err;
}
return bt_l2cap_init(); #if defined(CONFIG_BLUETOOTH_CONN)
if (!err) {
err = bt_l2cap_init();
}
#endif /* CONFIG_BLUETOOTH_CONN */
return err;
} }
static void hci_rx_fiber(bt_ready_cb_t ready_cb) static void hci_rx_fiber(bt_ready_cb_t ready_cb)
@ -1584,9 +1628,11 @@ static void hci_rx_fiber(bt_ready_cb_t ready_cb)
BT_DBG("buf %p type %u len %u\n", buf, buf->type, buf->len); BT_DBG("buf %p type %u len %u\n", buf, buf->type, buf->len);
switch (buf->type) { switch (buf->type) {
#if defined(CONFIG_BLUETOOTH_CONN)
case BT_ACL_IN: case BT_ACL_IN:
hci_acl(buf); hci_acl(buf);
break; break;
#endif /* CONFIG_BLUETOOTH_CONN */
case BT_EVT: case BT_EVT:
hci_event(buf); hci_event(buf);
break; break;

View file

@ -165,6 +165,7 @@ static void le_conn_param_rsp(struct bt_conn *conn, struct bt_buf *buf)
bt_conn_connected(conn); bt_conn_connected(conn);
} }
#if defined(CONFIG_BLUETOOTH_CENTRAL)
static void le_conn_param_update_req(struct bt_conn *conn, uint8_t ident, static void le_conn_param_update_req(struct bt_conn *conn, uint8_t ident,
struct bt_buf *buf) struct bt_buf *buf)
{ {
@ -217,6 +218,7 @@ static void le_conn_param_update_req(struct bt_conn *conn, uint8_t ident,
bt_conn_le_conn_update(conn, min, max, latency, timeout); bt_conn_le_conn_update(conn, min, max, latency, timeout);
} }
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */
static void le_sig(struct bt_conn *conn, struct bt_buf *buf) static void le_sig(struct bt_conn *conn, struct bt_buf *buf)
{ {
@ -248,9 +250,11 @@ static void le_sig(struct bt_conn *conn, struct bt_buf *buf)
case BT_L2CAP_CONN_PARAM_RSP: case BT_L2CAP_CONN_PARAM_RSP:
le_conn_param_rsp(conn, buf); le_conn_param_rsp(conn, buf);
break; break;
#if defined(CONFIG_BLUETOOTH_CENTRAL)
case BT_L2CAP_CONN_PARAM_REQ: case BT_L2CAP_CONN_PARAM_REQ:
le_conn_param_update_req(conn, hdr->ident, buf); le_conn_param_update_req(conn, hdr->ident, buf);
break; break;
#endif /* CONFIG_BLUETOOTH_CENTRAL */
default: default:
BT_WARN("Unknown L2CAP PDU code 0x%02x\n", hdr->code); BT_WARN("Unknown L2CAP PDU code 0x%02x\n", hdr->code);
rej_not_understood(conn, hdr->ident); rej_not_understood(conn, hdr->ident);

View file

@ -508,6 +508,7 @@ static uint8_t smp_request_tk(struct bt_conn *conn, uint8_t remote_io)
return 0; return 0;
} }
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
static uint8_t smp_pairing_req(struct bt_conn *conn, struct bt_buf *buf) static uint8_t smp_pairing_req(struct bt_conn *conn, struct bt_buf *buf)
{ {
struct bt_smp_pairing *req = (void *)buf->data; struct bt_smp_pairing *req = (void *)buf->data;
@ -557,6 +558,12 @@ static uint8_t smp_pairing_req(struct bt_conn *conn, struct bt_buf *buf)
return smp_request_tk(conn, req->io_capability); return smp_request_tk(conn, req->io_capability);
} }
#else
static uint8_t smp_pairing_req(struct bt_conn *conn, struct bt_buf *buf)
{
return BT_SMP_ERR_CMD_NOTSUPP;
}
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
static bool sec_level_reachable(struct bt_conn *conn) static bool sec_level_reachable(struct bt_conn *conn)
{ {
@ -572,6 +579,7 @@ static bool sec_level_reachable(struct bt_conn *conn)
} }
} }
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
int bt_smp_send_security_req(struct bt_conn *conn) int bt_smp_send_security_req(struct bt_conn *conn)
{ {
struct bt_smp *smp = conn->smp; struct bt_smp *smp = conn->smp;
@ -605,7 +613,9 @@ int bt_smp_send_security_req(struct bt_conn *conn)
return 0; return 0;
} }
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
#if defined(CONFIG_BLUETOOTH_CENTRAL)
int bt_smp_send_pairing_req(struct bt_conn *conn) int bt_smp_send_pairing_req(struct bt_conn *conn)
{ {
struct bt_smp *smp = conn->smp; struct bt_smp *smp = conn->smp;
@ -650,6 +660,7 @@ int bt_smp_send_pairing_req(struct bt_conn *conn)
return 0; return 0;
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */
static uint8_t smp_send_pairing_confirm(struct bt_conn *conn) static uint8_t smp_send_pairing_confirm(struct bt_conn *conn)
{ {
@ -680,6 +691,7 @@ static uint8_t smp_send_pairing_confirm(struct bt_conn *conn)
return 0; return 0;
} }
#if defined(CONFIG_BLUETOOTH_CENTRAL)
static uint8_t smp_pairing_rsp(struct bt_conn *conn, struct bt_buf *buf) static uint8_t smp_pairing_rsp(struct bt_conn *conn, struct bt_buf *buf)
{ {
struct bt_smp_pairing *rsp = (void *)buf->data; struct bt_smp_pairing *rsp = (void *)buf->data;
@ -714,6 +726,12 @@ static uint8_t smp_pairing_rsp(struct bt_conn *conn, struct bt_buf *buf)
return 0; return 0;
} }
#else
static uint8_t smp_pairing_rsp(struct bt_conn *conn, struct bt_buf *buf)
{
return BT_SMP_ERR_CMD_NOTSUPP;
}
#endif /* CONFIG_BLUETOOTH_CENTRAL */
static uint8_t smp_send_pairing_random(struct bt_conn *conn) static uint8_t smp_send_pairing_random(struct bt_conn *conn)
{ {
@ -744,18 +762,21 @@ static uint8_t smp_pairing_confirm(struct bt_conn *conn, struct bt_buf *buf)
memcpy(smp->pcnf, req->val, sizeof(smp->pcnf)); memcpy(smp->pcnf, req->val, sizeof(smp->pcnf));
#if defined(CONFIG_BLUETOOTH_CENTRAL)
if (conn->role == BT_HCI_ROLE_MASTER) { if (conn->role == BT_HCI_ROLE_MASTER) {
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM);
return smp_send_pairing_random(conn); return smp_send_pairing_random(conn);
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
if (atomic_test_bit(&smp->flags, SMP_FLAG_TK_VALID)) { if (atomic_test_bit(&smp->flags, SMP_FLAG_TK_VALID)) {
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM);
return smp_send_pairing_confirm(conn); return smp_send_pairing_confirm(conn);
} }
atomic_set_bit(&smp->flags, SMP_FLAG_CFM_DELAYED); atomic_set_bit(&smp->flags, SMP_FLAG_CFM_DELAYED);
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
return 0; return 0;
} }
@ -795,6 +816,7 @@ static uint8_t smp_pairing_random(struct bt_conn *conn, struct bt_buf *buf)
return BT_SMP_ERR_CONFIRM_FAILED; return BT_SMP_ERR_CONFIRM_FAILED;
} }
#if defined(CONFIG_BLUETOOTH_CENTRAL)
if (conn->role == BT_HCI_ROLE_MASTER) { if (conn->role == BT_HCI_ROLE_MASTER) {
uint8_t stk[16]; uint8_t stk[16];
@ -825,7 +847,9 @@ static uint8_t smp_pairing_random(struct bt_conn *conn, struct bt_buf *buf)
return 0; return 0;
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
keys = bt_keys_get_type(BT_KEYS_SLAVE_LTK, &conn->dst); keys = bt_keys_get_type(BT_KEYS_SLAVE_LTK, &conn->dst);
if (!keys) { if (!keys) {
BT_ERR("Unable to create new keys\n"); BT_ERR("Unable to create new keys\n");
@ -853,6 +877,7 @@ static uint8_t smp_pairing_random(struct bt_conn *conn, struct bt_buf *buf)
atomic_set_bit(&smp->flags, SMP_FLAG_ENC_PENDING); atomic_set_bit(&smp->flags, SMP_FLAG_ENC_PENDING);
smp_send_pairing_random(conn); smp_send_pairing_random(conn);
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
return 0; return 0;
} }
@ -865,12 +890,20 @@ static void smp_reset(struct bt_conn *conn)
atomic_set(&smp->allowed_cmds, 0); atomic_set(&smp->allowed_cmds, 0);
atomic_set(&smp->flags, 0); atomic_set(&smp->flags, 0);
if (conn->role == BT_HCI_ROLE_MASTER) { switch(conn->role) {
atomic_set_bit(&smp->allowed_cmds, #if defined(CONFIG_BLUETOOTH_CENTRAL)
BT_SMP_CMD_SECURITY_REQUEST); case BT_HCI_ROLE_MASTER:
} else { atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_SECURITY_REQUEST);
atomic_set_bit(&smp->allowed_cmds, break;
BT_SMP_CMD_PAIRING_REQ); #endif /* CONFIG_BLUETOOTH_CENTRAL */
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
case BT_HCI_ROLE_SLAVE:
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_REQ);
break;
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
default:
break;
} }
} }
@ -1030,9 +1063,11 @@ static uint8_t smp_master_ident(struct bt_conn *conn, struct bt_buf *buf)
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO);
} }
#if defined(CONFIG_BLUETOOTH_CENTRAL)
if (conn->role == BT_HCI_ROLE_MASTER && !smp->remote_dist) { if (conn->role == BT_HCI_ROLE_MASTER && !smp->remote_dist) {
bt_smp_distribute_keys(conn); bt_smp_distribute_keys(conn);
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */
return 0; return 0;
} }
@ -1114,9 +1149,11 @@ static uint8_t smp_ident_addr_info(struct bt_conn *conn, struct bt_buf *buf)
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO);
} }
#if defined(CONFIG_BLUETOOTH_CENTRAL)
if (conn->role == BT_HCI_ROLE_MASTER && !smp->remote_dist) { if (conn->role == BT_HCI_ROLE_MASTER && !smp->remote_dist) {
bt_smp_distribute_keys(conn); bt_smp_distribute_keys(conn);
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */
return 0; return 0;
} }
@ -1140,13 +1177,16 @@ static uint8_t smp_signing_info(struct bt_conn *conn, struct bt_buf *buf)
smp->remote_dist &= ~BT_SMP_DIST_SIGN; smp->remote_dist &= ~BT_SMP_DIST_SIGN;
#if defined(CONFIG_BLUETOOTH_CENTRAL)
if (conn->role == BT_HCI_ROLE_MASTER && !smp->remote_dist) { if (conn->role == BT_HCI_ROLE_MASTER && !smp->remote_dist) {
bt_smp_distribute_keys(conn); bt_smp_distribute_keys(conn);
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */
return 0; return 0;
} }
#if defined(CONFIG_BLUETOOTH_CENTRAL)
static uint8_t smp_security_request(struct bt_conn *conn, struct bt_buf *buf) static uint8_t smp_security_request(struct bt_conn *conn, struct bt_buf *buf)
{ {
struct bt_smp_security_request *req = (void *)buf->data; struct bt_smp_security_request *req = (void *)buf->data;
@ -1189,6 +1229,12 @@ pair:
return 0; return 0;
} }
#else
static uint8_t smp_security_request(struct bt_conn *conn, struct bt_buf *buf)
{
return BT_SMP_ERR_CMD_NOTSUPP;
}
#endif /* CONFIG_BLUETOOTH_CENTRAL */
static const struct { static const struct {
uint8_t (*func)(struct bt_conn *conn, struct bt_buf *buf); uint8_t (*func)(struct bt_conn *conn, struct bt_buf *buf);
@ -1322,10 +1368,12 @@ static void bt_smp_encrypt_change(struct bt_conn *conn)
bt_keys_clear(keys, BT_KEYS_ALL); bt_keys_clear(keys, BT_KEYS_ALL);
} }
#if defined(CONFIG_BLUETOOTH_CENTRAL)
/* Slave distributes it's keys first */ /* Slave distributes it's keys first */
if (conn->role == BT_HCI_ROLE_MASTER && smp->remote_dist) { if (conn->role == BT_HCI_ROLE_MASTER && smp->remote_dist) {
return; return;
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */
bt_smp_distribute_keys(conn); bt_smp_distribute_keys(conn);
} }
@ -1878,10 +1926,20 @@ void bt_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
return; return;
} }
if (conn->role == BT_HCI_ROLE_MASTER) { switch(conn->role) {
#if defined(CONFIG_BLUETOOTH_CENTRAL)
case BT_HCI_ROLE_MASTER:
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM);
} else { break;
#endif /* CONFIG_BLUETOOTH_CENTRAL */
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
case BT_HCI_ROLE_SLAVE:
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM);
break;
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
default:
break;
} }
} }

View file

@ -2,3 +2,4 @@ CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_BLUETOOTH=y CONFIG_BLUETOOTH=y
CONFIG_BLUETOOTH_UART=y CONFIG_BLUETOOTH_UART=y
CONFIG_BLUETOOTH_DEBUG=y CONFIG_BLUETOOTH_DEBUG=y
CONFIG_BLUETOOTH_CENTRAL=y

View file

@ -2,3 +2,4 @@ CONFIG_BLUETOOTH=y
CONFIG_BLUETOOTH_UART=y CONFIG_BLUETOOTH_UART=y
CONFIG_BLUETOOTH_DEBUG=y CONFIG_BLUETOOTH_DEBUG=y
CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_BLUETOOTH_PERIPHERAL=y

View file

@ -2,3 +2,4 @@ CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_BLUETOOTH=y CONFIG_BLUETOOTH=y
CONFIG_BLUETOOTH_UART=y CONFIG_BLUETOOTH_UART=y
CONFIG_BLUETOOTH_DEBUG=y CONFIG_BLUETOOTH_DEBUG=y
CONFIG_BLUETOOTH_PERIPHERAL=y

View file

@ -4,3 +4,5 @@ CONFIG_BLUETOOTH=y
CONFIG_BLUETOOTH_UART=y CONFIG_BLUETOOTH_UART=y
CONFIG_BLUETOOTH_DEBUG=y CONFIG_BLUETOOTH_DEBUG=y
CONFIG_CONSOLE_HANDLER=y CONFIG_CONSOLE_HANDLER=y
CONFIG_BLUETOOTH_CENTRAL=y
CONFIG_BLUETOOTH_PERIPHERAL=y

View file

@ -4,5 +4,7 @@ CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_BLUETOOTH=y CONFIG_BLUETOOTH=y
CONFIG_BLUETOOTH_UART=y CONFIG_BLUETOOTH_UART=y
CONFIG_CONSOLE_HANDLER=y CONFIG_CONSOLE_HANDLER=y
CONFIG_BLUETOOTH_CENTRAL=y
CONFIG_BLUETOOTH_PERIPHERAL=y
CONFIG_TINYCRYPT=y CONFIG_TINYCRYPT=y
CONFIG_TINYCRYPT_AES=y CONFIG_TINYCRYPT_AES=y

View file

@ -3,6 +3,8 @@ CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_CONSOLE_HANDLER=y CONFIG_CONSOLE_HANDLER=y
CONFIG_BLUETOOTH=y CONFIG_BLUETOOTH=y
CONFIG_BLUETOOTH_UART=y CONFIG_BLUETOOTH_UART=y
CONFIG_BLUETOOTH_CENTRAL=y
CONFIG_BLUETOOTH_PERIPHERAL=y
CONFIG_BLUETOOTH_DEBUG=y CONFIG_BLUETOOTH_DEBUG=y
CONFIG_BLUETOOTH_DEBUG_HCI_CORE=y CONFIG_BLUETOOTH_DEBUG_HCI_CORE=y
CONFIG_BLUETOOTH_DEBUG_BUF=y CONFIG_BLUETOOTH_DEBUG_BUF=y