Skip to content

Commit 1d19918

Browse files
Qbiczjhedberg
authored andcommitted
Bluetooth: host: Meaningful error codes on advertising start
Translate HCI error codes to POSIX error codes in order to be able to distinguish reason of connectable advertising start failure. Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
1 parent 5e4f6e9 commit 1d19918

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

include/bluetooth/bluetooth.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ struct bt_le_adv_param {
343343
* @param sd_len Number of elements in sd
344344
*
345345
* @return Zero on success or (negative) error code otherwise.
346+
* @return -ECONNREFUSED When connectable advertising is requested and there
347+
* is already maximum number of connections established.
348+
* This error code is only guaranteed when using Zephyr
349+
* controller, for other controllers code returned in
350+
* this case may be -EIO.
346351
*/
347352
int bt_le_adv_start(const struct bt_le_adv_param *param,
348353
const struct bt_data *ad, size_t ad_len,

subsys/bluetooth/host/hci_core.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,15 @@ int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf,
314314
BT_DBG("opcode 0x%04x status 0x%02x", opcode, cmd(buf)->status);
315315

316316
if (cmd(buf)->status) {
317-
err = -EIO;
317+
switch (cmd(buf)->status) {
318+
case BT_HCI_ERR_CONN_LIMIT_EXCEEDED:
319+
err = -ECONNREFUSED;
320+
break;
321+
default:
322+
err = -EIO;
323+
break;
324+
}
325+
318326
net_buf_unref(buf);
319327
} else {
320328
err = 0;

0 commit comments

Comments
 (0)