2017-02-03 11:50:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016-2017 Nordic Semiconductor ASA
|
|
|
|
* Copyright (c) 2016 Vinayak Kariappa Chettimada
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zephyr.h>
|
2017-06-13 19:57:04 +08:00
|
|
|
#include <bluetooth/hci.h>
|
2017-02-03 11:50:04 +08:00
|
|
|
|
|
|
|
#include "util/util.h"
|
|
|
|
|
|
|
|
#include "pdu.h"
|
|
|
|
#include "ctrl.h"
|
|
|
|
#include "ll.h"
|
2017-06-21 18:30:01 +08:00
|
|
|
#include "ll_filter.h"
|
2017-02-03 11:50:04 +08:00
|
|
|
|
|
|
|
u32_t ll_create_connection(u16_t scan_interval, u16_t scan_window,
|
|
|
|
u8_t filter_policy, u8_t peer_addr_type,
|
|
|
|
u8_t *peer_addr, u8_t own_addr_type,
|
|
|
|
u16_t interval, u16_t latency,
|
|
|
|
u16_t timeout)
|
|
|
|
{
|
|
|
|
u32_t status;
|
2017-07-03 16:31:55 +08:00
|
|
|
u8_t rpa_gen = 0;
|
|
|
|
u8_t rl_idx = FILTER_IDX_NONE;
|
2017-02-03 11:50:04 +08:00
|
|
|
|
2018-02-06 15:55:13 +08:00
|
|
|
if (ll_scan_is_enabled()) {
|
2017-06-22 21:11:00 +08:00
|
|
|
return BT_HCI_ERR_CMD_DISALLOWED;
|
|
|
|
}
|
|
|
|
|
2017-02-03 11:50:04 +08:00
|
|
|
status = radio_connect_enable(peer_addr_type, peer_addr, interval,
|
|
|
|
latency, timeout);
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-08-14 19:45:13 +08:00
|
|
|
#if defined(CONFIG_BT_CTLR_PRIVACY)
|
2017-06-21 18:30:01 +08:00
|
|
|
ll_filters_scan_update(filter_policy);
|
2017-07-03 16:31:55 +08:00
|
|
|
|
|
|
|
if (!filter_policy && ctrl_rl_enabled()) {
|
|
|
|
/* Look up the resolving list */
|
|
|
|
rl_idx = ll_rl_find(peer_addr_type, peer_addr, NULL);
|
|
|
|
}
|
|
|
|
|
2017-06-26 18:27:25 +08:00
|
|
|
if (own_addr_type == BT_ADDR_LE_PUBLIC_ID ||
|
|
|
|
own_addr_type == BT_ADDR_LE_RANDOM_ID) {
|
2017-07-03 16:31:55 +08:00
|
|
|
|
2017-06-26 18:27:25 +08:00
|
|
|
/* Generate RPAs if required */
|
|
|
|
ll_rl_rpa_update(false);
|
2017-07-03 16:31:55 +08:00
|
|
|
own_addr_type &= 0x1;
|
|
|
|
rpa_gen = 1;
|
2017-06-26 18:27:25 +08:00
|
|
|
}
|
2017-06-21 18:30:01 +08:00
|
|
|
#endif
|
2017-02-03 11:50:04 +08:00
|
|
|
return radio_scan_enable(0, own_addr_type,
|
|
|
|
ll_addr_get(own_addr_type, NULL),
|
2017-07-03 16:31:55 +08:00
|
|
|
scan_interval, scan_window,
|
|
|
|
filter_policy, rpa_gen, rl_idx);
|
2017-02-03 11:50:04 +08:00
|
|
|
}
|