bt_hci_cmd_send_sync() failure when changing txpower, error -5

This is similar to issues others have experienced in the past, yet the solutions from those threads aren't working for me. 

As per guidance from other threads, I have both of these enabled: 
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y
CONFIG_BT_HCI_VS_EXT=y

Here's the error message I'm getting from BT debug logs:
HCI set TX power err: -5 reason 0x00
W: opcode 0xfc0e status 0x42

I'm using SDK v2.5.2. Here's my full project configuration:

# not yet sure if this is helpful, harmful, or just unnecessary
CONFIG_NCS_SAMPLES_DEFAULTS=y

# to fix v2.5.x floating points in printk() debug prints
CONFIG_CBPRINTF_FP_SUPPORT=y

# for reading / writing to flash
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_LOG_LEVEL_WRN=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_NVS_LOG_LEVEL_WRN=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

# software resets
CONFIG_REBOOT=y

# for button, LED, accelerometer
CONFIG_GPIO=y
CONFIG_I2C=y

# for printing heap usage stats
CONFIG_SYS_HEAP_RUNTIME_STATS=y

# for bluetooth (general)
CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y

# for bluetooth (advertising)
CONFIG_BT_BROADCASTER=y
CONFIG_BT_DEVICE_APPEARANCE=512
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_EXT_ADV=y
CONFIG_BT_EXT_ADV_MAX_ADV_SET=2

# for bluetooth (tx power control)
CONFIG_BT_HCI_VS_EXT=y
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y

# for bluetooth (scanning)
CONFIG_BT_CENTRAL=y
CONFIG_BT_SCAN=y
CONFIG_BT_ID_MAX=1
CONFIG_BT_SCAN_FILTER_ENABLE=y
CONFIG_BT_SCAN_NAME_CNT=2

# for bluetooth (connecting)
CONFIG_BT_SMP=y
CONFIG_BT_SMP_SC_ONLY=n
CONFIG_BT_SMP_APP_PAIRING_ACCEPT=n
CONFIG_BT_SMP_ENFORCE_MITM=y
CONFIG_BT_BONDABLE=n

# for blueooth (GATT)
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DM=y
CONFIG_BT_GATT_DM_DATA_PRINT=y

#CONFIG_BT_L2CAP_TX_MTU=65
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

And here's the function I'm calling to change the txpower. Note that I've tried calling this at various stages (after advertising set is created, after advertising has started) with the same issue.

static void set_tx_power(uint8_t handle_type, uint16_t handle, int8_t tx_pwr_lvl)
{
	struct bt_hci_cp_vs_write_tx_power_level *cp;
	struct bt_hci_rp_vs_write_tx_power_level *rp;
	struct net_buf *buf, *rsp = NULL;
	int err;

	buf = bt_hci_cmd_create(BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL,
				sizeof(*cp));
	if (!buf) {
		printk("Unable to allocate command buffer\n");
		return;
	}

	cp = net_buf_add(buf, sizeof(*cp));
	cp->handle = sys_cpu_to_le16(handle);
	cp->handle_type = handle_type;
	cp->tx_power_level = tx_pwr_lvl;

	err = bt_hci_cmd_send_sync(BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL,
				   buf, &rsp);
	if (err) {
		uint8_t reason = rsp ?
			((struct bt_hci_rp_vs_write_tx_power_level *)
			  rsp->data)->status : 0;
		printk("Set Tx power err: %d reason 0x%02x\n", err, reason);
		return;
	}

	rp = (void *)rsp->data;
	printk("Actual Tx Power: %d\n", rp->selected_tx_power);

	net_buf_unref(rsp);
}

Thanks!

Parents Reply Children
No Data
Related