Files
esp-idf/components/bt/esp_ble_iso/host/common/hci.c
T

99 lines
2.4 KiB
C

/*
* SPDX-FileCopyrightText: 2017-2025 Nordic Semiconductor ASA
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation
* SPDX-FileCopyrightText: 2025 NXP
* SPDX-FileContributor: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/bluetooth/buf.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/hci_types.h>
#include <zephyr/bluetooth/gap.h>
#include <../host/hci_core.h>
#include <../host/iso_internal.h>
#include "common/host.h"
LOG_MODULE_REGISTER(ISO_HCI, CONFIG_BT_ISO_LOG_LEVEL);
/* Device/HCI state, not an ISO packet, task-context -> eligible for PSRAM. */
BT_ISO_EXT_RAM_BSS_ATTR struct bt_dev bt_dev;
uint8_t bt_get_phy(uint8_t hci_phy)
{
switch (hci_phy) {
case BT_HCI_LE_PHY_1M:
return BT_GAP_LE_PHY_1M;
case BT_HCI_LE_PHY_2M:
return BT_GAP_LE_PHY_2M;
case BT_HCI_LE_PHY_CODED:
return BT_GAP_LE_PHY_CODED;
default:
LOG_WRN("UnknownHciPhy[%u]", hci_phy);
return 0;
}
}
struct cmd_data {
/** HCI status of the command completion */
uint8_t status;
/** The command OpCode that the buffer contains */
uint16_t opcode;
/** The state to update when command completes with success. */
struct bt_hci_cmd_state_set *state;
};
static BT_ISO_EXT_RAM_BSS_ATTR struct cmd_data cmd_data;
#define cmd(buf) (&cmd_data)
NET_BUF_POOL_FIXED_DEFINE(hci_cmd_pool, 1, 255, 0, NULL);
_IDF_ONLY
struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
{
struct bt_hci_cmd_hdr *hdr;
struct net_buf *buf;
LOG_DBG("HciCmdCreate[%04x][%u]", opcode, param_len);
buf = net_buf_alloc(&hci_cmd_pool, K_NO_WAIT);
BT_LE_ASSERT(buf);
net_buf_reserve(buf, BT_BUF_RESERVE);
cmd(buf)->opcode = opcode;
cmd(buf)->state = NULL;
hdr = net_buf_add(buf, sizeof(*hdr));
hdr->opcode = sys_cpu_to_le16(opcode);
hdr->param_len = param_len;
return buf;
}
_IDF_ONLY
int bt_hci_cmd_send_sync(uint16_t opcode,
struct net_buf *buf,
struct net_buf **rsp)
{
LOG_DBG("HciCmdSendSync[%04x]", opcode);
#if CONFIG_BT_BLUEDROID_ENABLED
return bt_le_bluedroid_iso_cmd_send_sync(opcode, buf, rsp);
#else
return bt_le_nimble_iso_cmd_send_sync(opcode, buf, rsp);
#endif
}