Bluetooth: host: Add error code to directed advertiser
Add error code to API for starting directed advertiser. Also rename the API in order to follow the established naming pattern. Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
parent
fe597c07bf
commit
ed11ca1744
3 changed files with 31 additions and 15 deletions
|
@ -461,13 +461,28 @@ int bt_le_set_auto_conn(const bt_addr_le_t *addr,
|
|||
* The caller gets a new reference to the connection object which must be
|
||||
* released with bt_conn_unref() once done using the object.
|
||||
*
|
||||
* @param peer Remote address.
|
||||
* @param param Directed advertising parameters.
|
||||
* @param[in] peer Remote address.
|
||||
* @param[in] param Directed advertising parameters.
|
||||
* @param[out] conn Valid connection object on success.
|
||||
*
|
||||
* @return Valid connection object on success or NULL otherwise.
|
||||
* @return Zero on success or (negative) error code on failure.
|
||||
*/
|
||||
int bt_conn_le_create_slave(const bt_addr_le_t *peer,
|
||||
const struct bt_le_adv_param *param,
|
||||
struct bt_conn **conn);
|
||||
|
||||
__deprecated static inline
|
||||
struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,
|
||||
const struct bt_le_adv_param *param);
|
||||
const struct bt_le_adv_param *param)
|
||||
{
|
||||
struct bt_conn *conn;
|
||||
|
||||
if (bt_conn_le_create_slave(peer, param, &conn)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
/** Security level. */
|
||||
typedef enum __packed {
|
||||
|
|
|
@ -2373,8 +2373,9 @@ int bt_le_set_auto_conn(const bt_addr_le_t *addr,
|
|||
#endif /* CONFIG_BT_CENTRAL */
|
||||
|
||||
#if defined(CONFIG_BT_PERIPHERAL)
|
||||
struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,
|
||||
const struct bt_le_adv_param *param)
|
||||
int bt_conn_le_create_slave(const bt_addr_le_t *peer,
|
||||
const struct bt_le_adv_param *param,
|
||||
struct bt_conn **ret_conn)
|
||||
{
|
||||
int err;
|
||||
struct bt_conn *conn;
|
||||
|
@ -2397,25 +2398,24 @@ struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,
|
|||
BT_WARN("Found valid connection in %s state",
|
||||
state2str(conn->state));
|
||||
bt_conn_unref(conn);
|
||||
return NULL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
conn = bt_conn_add_le(param->id, peer);
|
||||
if (!conn) {
|
||||
return NULL;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
bt_conn_set_state(conn, BT_CONN_CONNECT_DIR_ADV);
|
||||
|
||||
err = bt_le_adv_start_internal(¶m_int, NULL, 0, NULL, 0, peer);
|
||||
if (err) {
|
||||
BT_WARN("Directed advertising could not be started: %d", err);
|
||||
|
||||
bt_conn_unref(conn);
|
||||
return NULL;
|
||||
return err;
|
||||
}
|
||||
|
||||
return conn;
|
||||
*ret_conn = conn;
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BT_PERIPHERAL */
|
||||
|
||||
|
|
|
@ -790,9 +790,10 @@ static int cmd_directed_adv(const struct shell *shell,
|
|||
}
|
||||
}
|
||||
|
||||
conn = bt_conn_create_slave_le(&addr, param);
|
||||
if (!conn) {
|
||||
shell_error(shell, "Failed to start directed advertising");
|
||||
err = bt_conn_le_create_slave(&addr, param, &conn);
|
||||
if (err) {
|
||||
shell_error(shell, "Failed to start directed advertising (%d)",
|
||||
err);
|
||||
return -ENOEXEC;
|
||||
} else {
|
||||
shell_print(shell, "Started directed advertising");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue