[style][ble] format ble files
This commit is contained in:
parent
da07eee6ea
commit
67c8532ae0
@ -16,7 +16,7 @@ list(APPEND ADD_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/ble_stack/cli_cmds")
|
||||
list(APPEND ADD_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/ble_stack/services")
|
||||
list(APPEND ADD_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/blecontroller/ble_inc")
|
||||
|
||||
if(CONFIG_BT_OAD_SERVER AND CONFIG_BT_OAD_CLIENT)
|
||||
if(CONFIG_BT_OAD_SERVER OR CONFIG_BT_OAD_CLIENT)
|
||||
list(APPEND ADD_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/ble_stack/services/oad")
|
||||
endif()
|
||||
#######################################################
|
||||
|
Binary file not shown.
@ -110,6 +110,14 @@ if(NOT CFG_BLE_PDS)
|
||||
set(CFG_BLE_PDS 0)
|
||||
endif()
|
||||
|
||||
if(NOT CONFIG_BT_OAD_SERVER)
|
||||
set(CONFIG_BT_OAD_SERVER 1)
|
||||
endif()
|
||||
|
||||
if(CONFIG_BT_OAD_SERVER)
|
||||
set(CONFIG_BL_MCU_SDK 1)
|
||||
endif()
|
||||
|
||||
if(NOT CONFIG_BT_MESH)
|
||||
set(CONFIG_BT_MESH 0)
|
||||
endif()
|
||||
@ -276,6 +284,10 @@ if(CONFIG_BT_OAD_SERVER)
|
||||
list(APPEND CFLAGS -DCONFIG_BT_OAD_SERVER)
|
||||
endif()
|
||||
|
||||
if(CONFIG_BL_MCU_SDK)
|
||||
list(APPEND CFLAGS -DCONFIG_BL_MCU_SDK)
|
||||
endif()
|
||||
|
||||
if(CONFIG_BT_OAD_CLIENT)
|
||||
list(APPEND CFLAGS -DCONFIG_BT_OAD_CLIENT)
|
||||
endif()
|
||||
|
@ -19,90 +19,28 @@
|
||||
#include "byteorder.h"
|
||||
#include "hci_onchip.h"
|
||||
|
||||
extern int hci_host_recv_pkt_handler(uint8_t *data, uint16_t len);
|
||||
#define DATA_MSG_CNT 10
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
struct rx_msg_struct msg_array[9];
|
||||
struct rx_msg_struct data_msg[DATA_MSG_CNT];
|
||||
struct k_queue msg_queue;
|
||||
static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, uint8_t *param,
|
||||
uint8_t param_len, void *rx_buf);
|
||||
#else
|
||||
static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, uint8_t *param,
|
||||
uint8_t param_len);
|
||||
#if defined(BFLB_BLE_NOTIFY_ADV_DISCARDED)
|
||||
extern void ble_controller_notify_adv_discarded(uint8_t *adv_bd_addr, uint8_t adv_type);
|
||||
#endif
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
struct rx_msg_struct *bl_find_valid_queued_entry(void)
|
||||
struct rx_msg_struct *bl_find_valid_data_msg()
|
||||
{
|
||||
struct rx_msg_struct empty_msg;
|
||||
memset(&empty_msg, 0, sizeof(struct rx_msg_struct));
|
||||
|
||||
for (int i = 0; i < sizeof(msg_array) / (sizeof(struct rx_msg_struct)); i++) {
|
||||
if (!memcmp(&msg_array[i], &empty_msg, sizeof(struct rx_msg_struct))) {
|
||||
return (msg_array + i);
|
||||
for (int i = 0; i < DATA_MSG_CNT; i++) {
|
||||
if (!memcmp(&data_msg[i], &empty_msg, sizeof(struct rx_msg_struct))) {
|
||||
return (data_msg + i);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void bl_handle_queued_msg(void)
|
||||
{
|
||||
//give a default buf type BT_BUF_ACL_IN, will be set buf type in bl_onchiphci_rx_packet_handler again.
|
||||
struct net_buf *buf;
|
||||
struct rx_msg_struct *msg;
|
||||
|
||||
if (k_queue_is_empty(&msg_queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT);
|
||||
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg = k_fifo_get(&msg_queue, K_NO_WAIT);
|
||||
BT_ASSERT(buf);
|
||||
|
||||
bl_onchiphci_rx_packet_handler(msg->pkt_type, msg->src_id, msg->param, msg->param_len, buf);
|
||||
|
||||
if (msg->param) {
|
||||
k_free(msg->param);
|
||||
}
|
||||
|
||||
memset(msg, 0, sizeof(struct rx_msg_struct));
|
||||
}
|
||||
|
||||
void bl_onchiphci_interface_deinit(void)
|
||||
{
|
||||
struct rx_msg_struct *msg;
|
||||
|
||||
do {
|
||||
msg = k_fifo_get(&msg_queue, K_NO_WAIT);
|
||||
|
||||
if (msg) {
|
||||
if (msg->param) {
|
||||
k_free(msg->param);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
|
||||
k_queue_free(&msg_queue);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t bl_onchiphci_interface_init(void)
|
||||
{
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
memset(msg_array, 0, sizeof(msg_array));
|
||||
k_queue_init(&msg_queue, 9);
|
||||
#endif
|
||||
return bt_onchiphci_interface_init(bl_onchiphci_rx_packet_handler);
|
||||
}
|
||||
|
||||
int bl_onchiphci_send_2_controller(struct net_buf *buf)
|
||||
{
|
||||
uint16_t opcode;
|
||||
@ -112,7 +50,6 @@ int bl_onchiphci_send_2_controller(struct net_buf *buf)
|
||||
hci_pkt_struct pkt;
|
||||
|
||||
buf_type = bt_buf_get_type(buf);
|
||||
|
||||
switch (buf_type) {
|
||||
case BT_BUF_CMD: {
|
||||
struct bt_hci_cmd_hdr *chdr;
|
||||
@ -131,9 +68,8 @@ int bl_onchiphci_send_2_controller(struct net_buf *buf)
|
||||
opcode = sys_le16_to_cpu(chdr->opcode);
|
||||
//move buf to the payload
|
||||
net_buf_pull(buf, sizeof(struct bt_hci_cmd_hdr));
|
||||
|
||||
switch (opcode) {
|
||||
//Refer to hci_cmd_desc_tab_le, for the ones of which dest_ll is BLE_CTRL
|
||||
//ble refer to hci_cmd_desc_tab_le, for the ones of which dest_ll is BLE_CTRL
|
||||
case BT_HCI_OP_LE_CONN_UPDATE:
|
||||
case BT_HCI_OP_LE_READ_CHAN_MAP:
|
||||
case BT_HCI_OP_LE_READ_REMOTE_FEATURES:
|
||||
@ -144,21 +80,22 @@ int bl_onchiphci_send_2_controller(struct net_buf *buf)
|
||||
case BT_HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY:
|
||||
case BT_HCI_OP_LE_SET_DATA_LEN:
|
||||
case BT_HCI_OP_LE_READ_PHY:
|
||||
case BT_HCI_OP_LE_SET_PHY: {
|
||||
case BT_HCI_OP_LE_SET_PHY:
|
||||
//bredr identify link id, according to dest_id
|
||||
case BT_HCI_OP_READ_REMOTE_FEATURES:
|
||||
case BT_HCI_OP_READ_REMOTE_EXT_FEATURES:
|
||||
case BT_HCI_OP_READ_ENCRYPTION_KEY_SIZE: {
|
||||
//dest_id is connectin handle
|
||||
dest_id = buf->data[0];
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pkt.p.hci_cmd.opcode = opcode;
|
||||
pkt.p.hci_cmd.param_len = chdr->param_len;
|
||||
pkt.p.hci_cmd.params = buf->data;
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
case BT_BUF_ACL_OUT: {
|
||||
@ -198,94 +135,14 @@ int bl_onchiphci_send_2_controller(struct net_buf *buf)
|
||||
return bt_onchiphci_send(pkt_type, dest_id, &pkt);
|
||||
}
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, uint8_t *param,
|
||||
uint8_t param_len, void *rx_buf)
|
||||
#else
|
||||
static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, uint8_t *param,
|
||||
uint8_t param_len)
|
||||
#endif
|
||||
void bl_packet_to_host(uint8_t pkt_type, uint16_t src_id, uint8_t *param, uint8_t param_len, struct net_buf *buf)
|
||||
{
|
||||
uint8_t nb_h2c_cmd_pkts = 0x01, buf_type, *buf_data;
|
||||
uint16_t tlt_len;
|
||||
bool prio = true;
|
||||
uint8_t nb_h2c_cmd_pkts = 0x01;
|
||||
|
||||
struct net_buf *buf = NULL;
|
||||
static uint32_t monitor = 0;
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
struct rx_msg_struct *rx_msg;
|
||||
#endif
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
|
||||
if (!rx_buf) {
|
||||
#endif
|
||||
buf_type = (pkt_type == BT_HCI_ACL_DATA) ? BT_BUF_ACL_IN : BT_BUF_EVT;
|
||||
|
||||
if (pkt_type == BT_HCI_CMD_CMP_EVT || pkt_type == BT_HCI_CMD_STAT_EVT) {
|
||||
buf = bt_buf_get_cmd_complete(K_FOREVER);
|
||||
} else {
|
||||
do {
|
||||
// When deal with LE ADV report, Don't use reserve buf
|
||||
if (((pkt_type == BT_HCI_LE_EVT && param[0] == BT_HCI_EVT_LE_ADVERTISING_REPORT) || (pkt_type == BT_HCI_ACL_DATA)) &&
|
||||
(bt_buf_get_rx_avail_cnt() <= CONFIG_BT_RX_BUF_RSV_COUNT)) {
|
||||
break;
|
||||
}
|
||||
|
||||
//not use K_FOREVER, rw main loop thread cannot be blocked here. if there is no rx buffer,directly igore.
|
||||
//otherwise, if rw main loop blocked here, hci command cannot be handled.
|
||||
buf = bt_buf_get_rx(buf_type, K_NO_WAIT);
|
||||
} while (0);
|
||||
}
|
||||
|
||||
if (!buf) {
|
||||
if (((++monitor) & 0xff) == 0) {
|
||||
BT_WARN("hci_rx_pool is not available\n");
|
||||
}
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
|
||||
//if it is le adv pkt, discard it.
|
||||
if (pkt_type == BT_HCI_LE_EVT && param[0] == BT_HCI_EVT_LE_ADVERTISING_REPORT) {
|
||||
return;
|
||||
} else {
|
||||
rx_msg = bl_find_valid_queued_entry();
|
||||
|
||||
if (!rx_msg) {
|
||||
return;
|
||||
} else {
|
||||
rx_msg->pkt_type = pkt_type;
|
||||
rx_msg->src_id = src_id;
|
||||
|
||||
if (param_len) {
|
||||
rx_msg->param = k_malloc(param_len);
|
||||
memcpy(rx_msg->param, param, param_len);
|
||||
}
|
||||
|
||||
rx_msg->param_len = param_len;
|
||||
k_fifo_put(&msg_queue, rx_msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#else //OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
monitor = 0;
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
} else {
|
||||
buf = rx_buf;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
buf_data = net_buf_tail(buf);
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
uint8_t *buf_data = net_buf_tail(buf);
|
||||
bt_buf_set_rx_adv(buf, false);
|
||||
#endif
|
||||
|
||||
switch (pkt_type) {
|
||||
case BT_HCI_CMD_CMP_EVT: {
|
||||
@ -298,7 +155,6 @@ static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, ui
|
||||
memcpy(buf_data, param, param_len);
|
||||
break;
|
||||
}
|
||||
|
||||
case BT_HCI_CMD_STAT_EVT: {
|
||||
tlt_len = BT_HCI_CSEVT_LEN;
|
||||
*buf_data++ = BT_HCI_EVT_CMD_STATUS;
|
||||
@ -308,31 +164,22 @@ static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, ui
|
||||
sys_put_le16(src_id, buf_data);
|
||||
break;
|
||||
}
|
||||
|
||||
case BT_HCI_LE_EVT: {
|
||||
prio = false;
|
||||
bt_buf_set_type(buf, BT_BUF_EVT);
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
|
||||
if (param[0] == BT_HCI_EVT_LE_ADVERTISING_REPORT) {
|
||||
bt_buf_set_rx_adv(buf, true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
tlt_len = BT_HCI_EVT_LE_PARAM_OFFSET + param_len;
|
||||
*buf_data++ = BT_HCI_EVT_LE_META_EVENT;
|
||||
*buf_data++ = param_len;
|
||||
memcpy(buf_data, param, param_len);
|
||||
break;
|
||||
}
|
||||
|
||||
case BT_HCI_EVT: {
|
||||
if (src_id != BT_HCI_EVT_NUM_COMPLETED_PACKETS) {
|
||||
prio = false;
|
||||
}
|
||||
|
||||
bt_buf_set_type(buf, BT_BUF_EVT);
|
||||
tlt_len = BT_HCI_EVT_LE_PARAM_OFFSET + param_len;
|
||||
*buf_data++ = src_id;
|
||||
@ -340,19 +187,12 @@ static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, ui
|
||||
memcpy(buf_data, param, param_len);
|
||||
break;
|
||||
}
|
||||
|
||||
case BT_HCI_ACL_DATA: {
|
||||
prio = false;
|
||||
bt_buf_set_type(buf, BT_BUF_ACL_IN);
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
tlt_len = bt_onchiphci_hanlde_rx_acl(param, buf_data);
|
||||
#else
|
||||
tlt_len = param_len;
|
||||
memcpy(buf_data, param, param_len);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
net_buf_unref(buf);
|
||||
return;
|
||||
@ -367,3 +207,117 @@ static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, ui
|
||||
hci_driver_enque_recvq(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void bl_trigger_queued_msg()
|
||||
{
|
||||
struct net_buf *buf = NULL;
|
||||
struct rx_msg_struct *msg = NULL;
|
||||
|
||||
do {
|
||||
unsigned int lock = irq_lock();
|
||||
|
||||
if (k_queue_is_empty(&msg_queue)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (bt_buf_get_rx_avail_cnt() <= CONFIG_BT_RX_BUF_RSV_COUNT)
|
||||
break;
|
||||
|
||||
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
break;
|
||||
}
|
||||
|
||||
msg = k_fifo_get(&msg_queue, K_NO_WAIT);
|
||||
|
||||
BT_ASSERT(msg);
|
||||
|
||||
bl_packet_to_host(msg->pkt_type, msg->src_id, msg->param, msg->param_len, buf);
|
||||
|
||||
irq_unlock(lock);
|
||||
|
||||
if (msg->param) {
|
||||
k_free(msg->param);
|
||||
}
|
||||
memset(msg, 0, sizeof(struct rx_msg_struct));
|
||||
|
||||
} while (buf);
|
||||
}
|
||||
|
||||
static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, uint8_t *param, uint8_t param_len)
|
||||
{
|
||||
struct net_buf *buf = NULL;
|
||||
struct rx_msg_struct *rx_msg = NULL;
|
||||
|
||||
if (pkt_type == BT_HCI_CMD_CMP_EVT || pkt_type == BT_HCI_CMD_STAT_EVT) {
|
||||
buf = bt_buf_get_cmd_complete(K_FOREVER);
|
||||
bl_packet_to_host(pkt_type, src_id, param, param_len, buf);
|
||||
return;
|
||||
} else if (pkt_type == BT_HCI_LE_EVT && param[0] == BT_HCI_EVT_LE_ADVERTISING_REPORT) {
|
||||
if (bt_buf_get_rx_avail_cnt() <= CONFIG_BT_RX_BUF_RSV_COUNT) {
|
||||
BT_INFO("Discard adv report.");
|
||||
#if defined(BFLB_BLE_NOTIFY_ADV_DISCARDED)
|
||||
ble_controller_notify_adv_discarded(¶m[4], param[2]);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT);
|
||||
if (buf)
|
||||
bl_packet_to_host(pkt_type, src_id, param, param_len, buf);
|
||||
return;
|
||||
} else {
|
||||
if (pkt_type != BT_HCI_ACL_DATA) {
|
||||
/* Using the reserved buf (CONFIG_BT_RX_BUF_RSV_COUNT) firstly. */
|
||||
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT);
|
||||
if (buf) {
|
||||
bl_packet_to_host(pkt_type, src_id, param, param_len, buf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rx_msg = bl_find_valid_data_msg();
|
||||
}
|
||||
|
||||
BT_ASSERT(rx_msg);
|
||||
|
||||
rx_msg->pkt_type = pkt_type;
|
||||
rx_msg->src_id = src_id;
|
||||
rx_msg->param_len = param_len;
|
||||
if (param_len) {
|
||||
rx_msg->param = k_malloc(param_len);
|
||||
memcpy(rx_msg->param, param, param_len);
|
||||
}
|
||||
|
||||
k_fifo_put(&msg_queue, rx_msg);
|
||||
|
||||
bl_trigger_queued_msg();
|
||||
}
|
||||
|
||||
uint8_t bl_onchiphci_interface_init(void)
|
||||
{
|
||||
for (int i = 0; i < DATA_MSG_CNT; i++) {
|
||||
memset(data_msg + i, 0, sizeof(struct rx_msg_struct));
|
||||
}
|
||||
|
||||
k_queue_init(&msg_queue, DATA_MSG_CNT);
|
||||
|
||||
return bt_onchiphci_interface_init(bl_onchiphci_rx_packet_handler);
|
||||
}
|
||||
|
||||
void bl_onchiphci_interface_deinit(void)
|
||||
{
|
||||
struct rx_msg_struct *msg;
|
||||
|
||||
do {
|
||||
msg = k_fifo_get(&msg_queue, K_NO_WAIT);
|
||||
if (msg) {
|
||||
if (msg->param) {
|
||||
k_free(msg->param);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
|
||||
k_queue_free(&msg_queue);
|
||||
}
|
||||
|
@ -4,14 +4,12 @@
|
||||
#include "net/buf.h"
|
||||
#include "bluetooth.h"
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
struct rx_msg_struct {
|
||||
uint8_t pkt_type;
|
||||
uint16_t src_id;
|
||||
uint8_t *param;
|
||||
uint8_t param_len;
|
||||
} __packed;
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
DATA_TYPE_COMMAND = 1,
|
||||
@ -21,10 +19,8 @@ typedef enum {
|
||||
} serial_data_type_t;
|
||||
|
||||
uint8_t bl_onchiphci_interface_init(void);
|
||||
|
||||
void bl_onchiphci_interface_deinit(void);
|
||||
void bl_trigger_queued_msg(void);
|
||||
int bl_onchiphci_send_2_controller(struct net_buf *buf);
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
void bl_onchiphci_interface_deinit(void);
|
||||
#endif
|
||||
#endif //__BL_CONTROLLER_H__
|
@ -110,33 +110,27 @@ const struct cli_command btStackCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = {
|
||||
{"ble_set_device_name", "\r\nble_set_device_name:\r\n\[Lenth of name]\r\n\[name]\r\n", blecli_set_device_name},
|
||||
#if defined(CONFIG_BLE_TP_SERVER)
|
||||
|
||||
{
|
||||
"ble_tp_start", "\r\nble_tp_start:\r\n\
|
||||
[TP test,1:enable, 0:disable]\r\n", blecli_tp_start
|
||||
},
|
||||
{"ble_tp_start", "\r\nble_tp_start:\r\n\
|
||||
[TP test,1:enable, 0:disable]\r\n", blecli_tp_start},
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_OBSERVER)
|
||||
{
|
||||
"ble_start_scan", "\r\nble_start_scan:\r\n\
|
||||
{"ble_start_scan", "\r\nble_start_scan:\r\n\
|
||||
[Scan type, 0:passive scan, 1:active scan]\r\n\
|
||||
[Duplicate filtering, 0:Disable duplicate filtering, 1:Enable duplicate filtering]\r\n\
|
||||
[Scan interval, 0x0004-4000,e.g.0080]\r\n\
|
||||
[Scan window, 0x0004-4000,e.g.0050]\r\n", blecli_start_scan
|
||||
},
|
||||
[Scan window, 0x0004-4000,e.g.0050]\r\n", blecli_start_scan},
|
||||
|
||||
{"ble_stop_scan", "\r\nble_stop_scan:[Stop scan]\r\nParameter[Null]\r\n", blecli_stop_scan},
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_PERIPHERAL)
|
||||
{
|
||||
"ble_start_adv", "\r\nble_start_adv:\r\n\
|
||||
{"ble_start_adv", "\r\nble_start_adv:\r\n\
|
||||
[Adv type,0:adv_ind,1:adv_scan_ind,2:adv_nonconn_ind]\r\n\
|
||||
[Mode, 0:discov, 1:non-discov]\r\n\
|
||||
[Adv Interval Min,0x0020-4000,e.g.0030]\r\n\
|
||||
[Adv Interval Max,0x0020-4000,e.g.0060]\r\n", blecli_start_advertise
|
||||
},
|
||||
|
||||
[Adv Interval Max,0x0020-4000,e.g.0060]\r\n", blecli_start_advertise},
|
||||
|
||||
{"ble_stop_adv", "\r\nble_stop_adv:[Stop advertising]\r\nParameter[Null]\r\n", blecli_stop_advertise},
|
||||
|
||||
{"ble_read_local_address", "\r\nble_read_local_address:[Read local address]\r\n", blecli_read_local_address},
|
||||
@ -144,45 +138,33 @@ const struct cli_command btStackCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = {
|
||||
|
||||
#if defined(CONFIG_BT_CONN)
|
||||
#if defined(CONFIG_BT_CENTRAL)
|
||||
{
|
||||
"ble_connect", "\r\nble_connect:[Connect remote device]\r\n\
|
||||
{"ble_connect", "\r\nble_connect:[Connect remote device]\r\n\
|
||||
[Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\
|
||||
[Address value, e.g.112233AABBCC]\r\n", blecli_connect
|
||||
},
|
||||
[Address value, e.g.112233AABBCC]\r\n", blecli_connect},
|
||||
#endif //CONFIG_BT_CENTRAL
|
||||
|
||||
{
|
||||
"ble_disconnect", "\r\nble_disconnect:[Disconnect remote device]\r\n\
|
||||
|
||||
{"ble_disconnect", "\r\nble_disconnect:[Disconnect remote device]\r\n\
|
||||
[Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\
|
||||
[Address value,e.g.112233AABBCC]\r\n", blecli_disconnect
|
||||
},
|
||||
|
||||
{
|
||||
"ble_select_conn", "\r\nble_select_conn:[Select a specific connection]\r\n\
|
||||
[Address value,e.g.112233AABBCC]\r\n", blecli_disconnect},
|
||||
|
||||
{"ble_select_conn", "\r\nble_select_conn:[Select a specific connection]\r\n\
|
||||
[Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\
|
||||
[Address value, e.g.112233AABBCC]\r\n", blecli_select_conn
|
||||
},
|
||||
|
||||
{
|
||||
"ble_unpair", "\r\nble_unpair:[Unpair connection]\r\n\
|
||||
[Address value, e.g.112233AABBCC]\r\n", blecli_select_conn},
|
||||
|
||||
{"ble_unpair", "\r\nble_unpair:[Unpair connection]\r\n\
|
||||
[Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\
|
||||
[Address value, all 0: unpair all connection, otherwise:unpair specific connection]\r\n", blecli_unpair
|
||||
},
|
||||
[Address value, all 0: unpair all connection, otherwise:unpair specific connection]\r\n", blecli_unpair},
|
||||
|
||||
{
|
||||
"ble_conn_update", "\r\nble_conn_update:\r\n\
|
||||
{"ble_conn_update", "\r\nble_conn_update:\r\n\
|
||||
[Conn Interval Min,0x0006-0C80,e.g.0030]\r\n\
|
||||
[Conn Interval Max,0x0006-0C80,e.g.0030]\r\n\
|
||||
[Conn Latency,0x0000-01f3,e.g.0004]\r\n\
|
||||
[Supervision Timeout,0x000A-0C80,e.g.0010]\r\n", blecli_conn_update
|
||||
},
|
||||
[Supervision Timeout,0x000A-0C80,e.g.0010]\r\n", blecli_conn_update},
|
||||
#endif //CONFIG_BT_CONN
|
||||
|
||||
#if defined(CONFIG_BT_SMP)
|
||||
{
|
||||
"ble_security", "\r\nble_security:[Start security]\r\n\
|
||||
[Security level, Default value 4, 2:BT_SECURITY_MEDIUM, 3:BT_SECURITY_HIGH, 4:BT_SECURITY_FIPS]\r\n", blecli_security
|
||||
},
|
||||
{"ble_security", "\r\nble_security:[Start security]\r\n\
|
||||
[Security level, Default value 4, 2:BT_SECURITY_MEDIUM, 3:BT_SECURITY_HIGH, 4:BT_SECURITY_FIPS]\r\n", blecli_security},
|
||||
|
||||
{"ble_auth", "\r\nble_auth:[Register auth callback]\r\n", blecli_auth},
|
||||
|
||||
@ -199,63 +181,49 @@ const struct cli_command btStackCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = {
|
||||
#if defined(CONFIG_BT_GATT_CLIENT)
|
||||
{"ble_exchange_mtu", "\r\nble_exchange_mtu:[Exchange mtu]\r\n Parameter[Null]\r\n", blecli_exchange_mtu},
|
||||
|
||||
{
|
||||
"ble_discover", "\r\nble_discover:[Gatt discovery]\r\n\
|
||||
{"ble_discover", "\r\nble_discover:[Gatt discovery]\r\n\
|
||||
[Discovery type, 0:Primary, 1:Secondary, 2:Include, 3:Characteristic, 4:Descriptor]\r\n\
|
||||
[Uuid value, 2 Octets, e.g.1800]\r\n\
|
||||
[Start handle, 2 Octets, e.g.0001]\r\n\
|
||||
[End handle, 2 Octets, e.g.ffff]\r\n", blecli_discover
|
||||
},
|
||||
[End handle, 2 Octets, e.g.ffff]\r\n", blecli_discover},
|
||||
|
||||
{
|
||||
"ble_read", "\r\nble_read:[Gatt Read]\r\n\
|
||||
{"ble_read", "\r\nble_read:[Gatt Read]\r\n\
|
||||
[Attribute handle, 2 Octets]\r\n\
|
||||
[Value offset, 2 Octets]\r\n", blecli_read
|
||||
},
|
||||
[Value offset, 2 Octets]\r\n", blecli_read},
|
||||
|
||||
{
|
||||
"ble_write", "\r\nble_write:[Gatt write]\r\n\
|
||||
{"ble_write", "\r\nble_write:[Gatt write]\r\n\
|
||||
[Attribute handle, 2 Octets]\r\n\
|
||||
[Value offset, 2 Octets]\r\n\
|
||||
[Value length, 2 Octets]\r\n\
|
||||
[Value data]\r\n", blecli_write
|
||||
},
|
||||
[Value data]\r\n", blecli_write},
|
||||
|
||||
{
|
||||
"ble_write_without_rsp", "\r\nble_write_without_rsp:[Gatt write without response]\r\n\
|
||||
{"ble_write_without_rsp", "\r\nble_write_without_rsp:[Gatt write without response]\r\n\
|
||||
[Sign, 0: No need signed, 1:Signed write cmd if no smp]\r\n\
|
||||
[Attribute handle, 2 Octets]\r\n\
|
||||
[Value length, 2 Octets]\r\n\
|
||||
[Value data]\r\n", blecli_write_without_rsp
|
||||
},
|
||||
[Value data]\r\n", blecli_write_without_rsp},
|
||||
|
||||
{
|
||||
"ble_subscribe", "\r\nble_subscribe:[Gatt subscribe]\r\n\
|
||||
{"ble_subscribe", "\r\nble_subscribe:[Gatt subscribe]\r\n\
|
||||
[CCC handle, 2 Octets]\r\n\
|
||||
[Value handle, 2 Octets]\r\n\
|
||||
[Value, 1:notify, 2:indicate]\r\n", blecli_subscribe
|
||||
},
|
||||
[Value, 1:notify, 2:indicate]\r\n", blecli_subscribe},
|
||||
|
||||
{"ble_unsubscribe", "\r\nble_unsubscribe:[Gatt unsubscribe]\r\n Parameter[Null]\r\n", blecli_unsubscribe},
|
||||
#endif /*CONFIG_BT_GATT_CLIENT*/
|
||||
|
||||
{
|
||||
"ble_set_data_len",
|
||||
"\r\nble_set_data_len:[LE Set Data Length]\r\n\
|
||||
{"ble_set_data_len",
|
||||
"\r\nble_set_data_len:[LE Set Data Length]\r\n\
|
||||
[tx octets, 2 octets]\r\n\
|
||||
[tx time, 2 octets]\r\n",
|
||||
blecli_set_data_len
|
||||
},
|
||||
blecli_set_data_len},
|
||||
|
||||
{"ble_conn_info", "\r\nble_conn_info:[LE get all connection devices info]\r\n", blecli_get_all_conn_info},
|
||||
|
||||
#if defined(CONFIG_SET_TX_PWR)
|
||||
{
|
||||
"ble_set_tx_pwr",
|
||||
"\r\nble_set_tx_pwr:[Set tx power mode]\r\n\
|
||||
{"ble_set_tx_pwr",
|
||||
"\r\nble_set_tx_pwr:[Set tx power mode]\r\n\
|
||||
[mode, 1 octet, value:5,6,7]\r\n",
|
||||
blecli_set_tx_pwr
|
||||
},
|
||||
blecli_set_tx_pwr},
|
||||
#endif
|
||||
|
||||
#else
|
||||
@ -336,11 +304,9 @@ static void connected(struct bt_conn *conn, u8_t err)
|
||||
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
||||
|
||||
#if defined(CONFIG_BLE_MULTI_ADV)
|
||||
|
||||
if (ble_adv_id && !bt_le_multi_adv_stop(ble_adv_id)) {
|
||||
ble_adv_id = 0;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MULTI_ADV */
|
||||
|
||||
if (err) {
|
||||
@ -355,7 +321,6 @@ static void connected(struct bt_conn *conn, u8_t err)
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_RECONNECT_TEST)
|
||||
|
||||
if (conn->role == BT_CONN_ROLE_MASTER) {
|
||||
if (bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN)) {
|
||||
vOutputString("Disconnection fail. \r\n");
|
||||
@ -363,7 +328,6 @@ static void connected(struct bt_conn *conn, u8_t err)
|
||||
vOutputString("Disconnect success. \r\n");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -375,7 +339,6 @@ static void disconnected(struct bt_conn *conn, u8_t reason)
|
||||
vOutputString("Disconnected: %s (reason %u) \r\n", addr, reason);
|
||||
|
||||
#if defined(CONFIG_BLE_RECONNECT_TEST)
|
||||
|
||||
if (conn->role == BT_CONN_ROLE_SLAVE) {
|
||||
if (set_adv_enable(true)) {
|
||||
vOutputString("Restart adv fail. \r\n");
|
||||
@ -383,7 +346,6 @@ static void disconnected(struct bt_conn *conn, u8_t reason)
|
||||
vOutputString("Restart adv success. \r\n");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (default_conn == conn) {
|
||||
@ -451,7 +413,6 @@ static void blecli_set_2M_phy(char *pcWriteBuffer, int xWriteBufferLen, int argc
|
||||
vOutputString("Not connected \r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hci_le_set_phy(default_conn)) {
|
||||
vOutputString("Set ble 2M Phy successfully \r\n");
|
||||
} else {
|
||||
@ -468,7 +429,6 @@ static void blecli_set_default_phy(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
vOutputString("Not connected \r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
get_uint8_from_string(&argv[1], &phy);
|
||||
|
||||
if (phy == 0) {
|
||||
@ -494,9 +454,8 @@ static void blecli_get_device_name(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
|
||||
if (device_name) {
|
||||
vOutputString("device_name: %s\r\n", device_name);
|
||||
} else {
|
||||
} else
|
||||
vOutputString("Failed to read device name\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void blecli_set_device_name(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
|
||||
@ -505,12 +464,10 @@ static void blecli_set_device_name(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
|
||||
if (strlen(argv[1]) > 0 && strlen(argv[1]) <= CONFIG_BT_DEVICE_NAME_MAX) {
|
||||
err = bt_set_name((char *)argv[1]);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to set device name\r\n");
|
||||
} else {
|
||||
} else
|
||||
vOutputString("Set the device name successfully\r\n");
|
||||
}
|
||||
} else {
|
||||
vOutputString("Invaild lenth(%d)\r\n", strlen(argv[1]));
|
||||
}
|
||||
@ -521,7 +478,6 @@ static void blecli_tp_start(char *pcWriteBuffer, int xWriteBufferLen, int argc,
|
||||
extern u8_t tp_start;
|
||||
|
||||
get_uint8_from_string(&argv[1], &tp_start);
|
||||
|
||||
if (tp_start == 1) {
|
||||
vOutputString("Ble Throughput enable\r\n");
|
||||
} else if (tp_start == 0) {
|
||||
@ -545,7 +501,6 @@ static bool data_cb(struct bt_data *data, void *user_data)
|
||||
len = (data->data_len > NAME_LEN - 1) ? (NAME_LEN - 1) : (data->data_len);
|
||||
memcpy(name, data->data, len);
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@ -598,7 +553,6 @@ static void blecli_stop_scan(char *pcWriteBuffer, int xWriteBufferLen, int argc,
|
||||
int err;
|
||||
|
||||
err = bt_le_scan_stop();
|
||||
|
||||
if (err) {
|
||||
vOutputString("Stopping scanning failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -620,7 +574,6 @@ static void blecli_scan_filter_size(char *pcWriteBuffer, int xWriteBufferLen, in
|
||||
get_uint8_from_string(&argv[1], &size);
|
||||
|
||||
err = ble_controller_set_scan_filter_table_size(size);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Set failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -685,7 +638,6 @@ static void blecli_start_advertise(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
/*Get adv type, 0:adv_ind, 1:adv_scan_ind, 2:adv_nonconn_ind 3: adv_direct_ind*/
|
||||
get_uint8_from_string(&argv[1], &adv_type);
|
||||
vOutputString("adv_type 0x%x\r\n", adv_type);
|
||||
|
||||
if (adv_type == 0) {
|
||||
param.options = (BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_ONE_TIME);
|
||||
} else if (adv_type == 1) {
|
||||
@ -700,7 +652,6 @@ static void blecli_start_advertise(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
/*Get mode, 0:General discoverable, 1:non discoverable, 2:limit discoverable*/
|
||||
get_uint8_from_string(&argv[2], &mode);
|
||||
vOutputString("mode 0x%x\r\n", mode);
|
||||
|
||||
if (mode == 0 || mode == 1 || mode == 2) {
|
||||
if (mode == 0) {
|
||||
struct bt_data gen_disc_data = (struct bt_data)BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL));
|
||||
@ -737,21 +688,17 @@ static void blecli_start_advertise(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
|
||||
if (adv_type == 1 || adv_type == 0) {
|
||||
#if defined(CONFIG_BLE_MULTI_ADV)
|
||||
|
||||
if (ble_adv_id == 0) {
|
||||
err = bt_le_multi_adv_start(¶m, ad, ad_len, &ad_discov[0], 1, &ble_adv_id);
|
||||
}
|
||||
|
||||
#else
|
||||
err = bt_le_adv_start(¶m, ad, ad_len, &ad_discov[0], 1);
|
||||
#endif /*CONFIG_BLE_MULTI_ADV*/
|
||||
} else {
|
||||
#if defined(CONFIG_BLE_MULTI_ADV)
|
||||
|
||||
if (ble_adv_id == 0) {
|
||||
err = bt_le_multi_adv_start(¶m, ad, ad_len, NULL, 0, &ble_adv_id);
|
||||
}
|
||||
|
||||
#else
|
||||
err = bt_le_adv_start(¶m, ad, ad_len, NULL, 0);
|
||||
#endif
|
||||
@ -768,15 +715,12 @@ static void blecli_stop_advertise(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
{
|
||||
#if defined(CONFIG_BLE_MULTI_ADV)
|
||||
bool err = -1;
|
||||
|
||||
if (ble_adv_id && !bt_le_multi_adv_stop(ble_adv_id)) {
|
||||
ble_adv_id = 0;
|
||||
err = 0;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
#else
|
||||
|
||||
if (bt_le_adv_stop()) {
|
||||
#endif
|
||||
vOutputString("Failed to stop advertising\r\n");
|
||||
@ -808,7 +752,6 @@ static void blecli_start_multi_advertise(char *pcWriteBuffer, int xWriteBufferLe
|
||||
ad_len_1 = ARRAY_SIZE(ad_discov);
|
||||
|
||||
err_1 = bt_le_multi_adv_start(¶m_1, ad_1, ad_len_1, NULL, 0, &instant_id_1);
|
||||
|
||||
if (err_1) {
|
||||
vOutputString("Failed to start multi adv_1 (err_1%d)\r\n", err_1);
|
||||
} else {
|
||||
@ -829,7 +772,6 @@ static void blecli_start_multi_advertise(char *pcWriteBuffer, int xWriteBufferLe
|
||||
ad_len_2 = ARRAY_SIZE(ad_discov);
|
||||
|
||||
err_2 = bt_le_multi_adv_start(¶m_2, ad_2, ad_len_2, NULL, 0, &instant_id_2);
|
||||
|
||||
if (err_2) {
|
||||
vOutputString("Failed to start multi adv_2 (err_2: %d)\r\n", err_2);
|
||||
} else {
|
||||
@ -884,7 +826,6 @@ static void blecli_connect(char *pcWriteBuffer, int xWriteBufferLen, int argc, c
|
||||
addr.type = type;
|
||||
|
||||
get_bytearray_from_string(&argv[2], addr_val, 6);
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
vOutputString("addr[%d]:[0x%x]\r\n", i, addr_val[i]);
|
||||
}
|
||||
@ -913,7 +854,6 @@ static void blecli_disconnect(char *pcWriteBuffer, int xWriteBufferLen, int argc
|
||||
vOutputString("Number of Parameters is not correct\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
get_uint8_from_string(&argv[1], (u8_t *)&type);
|
||||
get_bytearray_from_string(&argv[2], addr_val, 6);
|
||||
reverse_bytearray(addr_val, addr.a.val, 6);
|
||||
@ -1007,7 +947,6 @@ static void blecli_conn_update(char *pcWriteBuffer, int xWriteBufferLen, int arg
|
||||
vOutputString("Number of Parameters is not correct\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
get_uint16_from_string(&argv[1], ¶m.interval_min);
|
||||
get_uint16_from_string(&argv[2], ¶m.interval_max);
|
||||
get_uint16_from_string(&argv[3], ¶m.latency);
|
||||
@ -1033,9 +972,8 @@ static void blecli_security(char *pcWriteBuffer, int xWriteBufferLen, int argc,
|
||||
return;
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
if (argc == 2)
|
||||
get_uint8_from_string(&argv[1], &sec_level);
|
||||
}
|
||||
|
||||
err = bt_conn_set_security(default_conn, sec_level);
|
||||
|
||||
@ -1184,7 +1122,6 @@ static void blecli_auth_passkey(char *pcWriteBuffer, int xWriteBufferLen, int ar
|
||||
}
|
||||
|
||||
passkey = atoi(argv[1]);
|
||||
|
||||
if (passkey > PASSKEY_MAX) {
|
||||
vOutputString("Passkey should be between 0-999999\r\n");
|
||||
return;
|
||||
@ -1216,7 +1153,6 @@ static void blecli_exchange_mtu(char *pcWriteBuffer, int xWriteBufferLen, int ar
|
||||
exchange_params.func = exchange_func;
|
||||
|
||||
err = bt_gatt_exchange_mtu(default_conn, &exchange_params);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Exchange failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -1284,21 +1220,18 @@ u8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *attr, struct
|
||||
bt_uuid_to_str(gatt_service->uuid, str, sizeof(str));
|
||||
vOutputString("Service %s found: start handle %x, end_handle %x\r\n", str, attr->handle, gatt_service->end_handle);
|
||||
break;
|
||||
|
||||
case BT_GATT_DISCOVER_CHARACTERISTIC:
|
||||
gatt_chrc = attr->user_data;
|
||||
bt_uuid_to_str(gatt_chrc->uuid, str, sizeof(str));
|
||||
vOutputString("Characteristic %s found: attr->handle %x chrc->handle %x \r\n", str, attr->handle, gatt_chrc->value_handle);
|
||||
print_chrc_props(gatt_chrc->properties);
|
||||
break;
|
||||
|
||||
case BT_GATT_DISCOVER_INCLUDE:
|
||||
gatt_include = attr->user_data;
|
||||
bt_uuid_to_str(gatt_include->uuid, str, sizeof(str));
|
||||
vOutputString("Include %s found: handle %x, start %x, end %x\r\n", str, attr->handle,
|
||||
gatt_include->start_handle, gatt_include->end_handle);
|
||||
break;
|
||||
|
||||
default:
|
||||
bt_uuid_to_str(attr->uuid, str, sizeof(str));
|
||||
vOutputString("Descriptor %s found: handle %x\r\n", str, attr->handle);
|
||||
@ -1328,7 +1261,6 @@ static void blecli_discover(char *pcWriteBuffer, int xWriteBufferLen, int argc,
|
||||
discover_params.end_handle = 0xffff;
|
||||
|
||||
get_uint8_from_string(&argv[1], &disc_type);
|
||||
|
||||
if (disc_type == 0) {
|
||||
discover_params.type = BT_GATT_DISCOVER_PRIMARY;
|
||||
} else if (disc_type == 1) {
|
||||
@ -1343,20 +1275,17 @@ static void blecli_discover(char *pcWriteBuffer, int xWriteBufferLen, int argc,
|
||||
vOutputString("Invalid discovery type\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
get_uint16_from_string(&argv[2], &uuid.val);
|
||||
|
||||
if (uuid.val) {
|
||||
if (uuid.val)
|
||||
discover_params.uuid = &uuid.uuid;
|
||||
} else {
|
||||
else
|
||||
discover_params.uuid = NULL;
|
||||
}
|
||||
|
||||
get_uint16_from_string(&argv[3], &discover_params.start_handle);
|
||||
get_uint16_from_string(&argv[4], &discover_params.end_handle);
|
||||
|
||||
err = bt_gatt_discover(default_conn, &discover_params);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Discover failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -1379,7 +1308,6 @@ static u8_t read_func(struct bt_conn *conn, u8_t err, struct bt_gatt_read_params
|
||||
if (length > 0 && length <= sizeof(str)) {
|
||||
memcpy(str, buf, length);
|
||||
vOutputString("device name : %s \r\n", str);
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
vOutputString("buf=[0x%x]\r\n", buf[i]);
|
||||
}
|
||||
@ -1414,7 +1342,6 @@ static void blecli_read(char *pcWriteBuffer, int xWriteBufferLen, int argc, char
|
||||
read_params.handle_count = 1;
|
||||
|
||||
err = bt_gatt_read(default_conn, &read_params);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Read failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -1458,16 +1385,13 @@ static void blecli_write(char *pcWriteBuffer, int xWriteBufferLen, int argc, cha
|
||||
get_uint16_from_string(&argv[3], &write_params.length);
|
||||
data_len = write_params.length;
|
||||
gatt_write_buf = k_malloc(data_len);
|
||||
|
||||
if (!gatt_write_buf) {
|
||||
vOutputString("Failed to alloc buffer for the data\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
get_bytearray_from_string(&argv[4], gatt_write_buf, data_len);
|
||||
|
||||
write_params.data = k_malloc(data_len);
|
||||
;
|
||||
write_params.data = gatt_write_buf;
|
||||
write_params.length = data_len;
|
||||
write_params.func = write_func;
|
||||
|
||||
@ -1504,12 +1428,10 @@ static void blecli_write_without_rsp(char *pcWriteBuffer, int xWriteBufferLen, i
|
||||
get_uint16_from_string(&argv[2], &handle);
|
||||
get_uint16_from_string(&argv[3], &len);
|
||||
gatt_write_buf = k_malloc(len);
|
||||
|
||||
if (!gatt_write_buf) {
|
||||
vOutputString("Failed to alloc buffer for the data\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
get_bytearray_from_string(&argv[4], gatt_write_buf, len);
|
||||
|
||||
err = bt_gatt_write_without_response(default_conn, handle, gatt_write_buf, len, sign);
|
||||
@ -1537,19 +1459,15 @@ static u8_t notify_func(struct bt_conn *conn,
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_TP_TEST)
|
||||
|
||||
if (!time) {
|
||||
time = k_now_ms();
|
||||
}
|
||||
|
||||
len += length;
|
||||
|
||||
if (k_now_ms() - time >= 1000) {
|
||||
vOutputString("data_len=[%d]\r\n", len);
|
||||
time = k_now_ms();
|
||||
len = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//vOutputString("Notification: data length %u\r\n", length);
|
||||
@ -1574,7 +1492,6 @@ static void blecli_subscribe(char *pcWriteBuffer, int xWriteBufferLen, int argc,
|
||||
subscribe_params.notify = notify_func;
|
||||
|
||||
int err = bt_gatt_subscribe(default_conn, &subscribe_params);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Subscribe failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -1595,7 +1512,6 @@ static void blecli_unsubscribe(char *pcWriteBuffer, int xWriteBufferLen, int arg
|
||||
}
|
||||
|
||||
int err = bt_gatt_unsubscribe(default_conn, &subscribe_params);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Unsubscribe failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -1624,7 +1540,6 @@ static void blecli_set_data_len(char *pcWriteBuffer, int xWriteBufferLen, int ar
|
||||
get_uint16_from_string(&argv[2], &tx_time);
|
||||
|
||||
err = bt_le_set_data_len(default_conn, tx_octets, tx_time);
|
||||
|
||||
if (err) {
|
||||
vOutputString("ble_set_data_len, LE Set Data Length (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -1646,7 +1561,6 @@ static void blecli_get_all_conn_info(char *pcWriteBuffer, int xWriteBufferLen, i
|
||||
}
|
||||
|
||||
vOutputString("ble connected devices count: %d\r\n", link_num);
|
||||
|
||||
for (int i = 0; i < link_num; i++) {
|
||||
bt_addr_le_to_str(info[i].le.remote, le_addr, sizeof(le_addr));
|
||||
vOutputString("[%d]: address %s\r\n", i, le_addr);
|
||||
@ -1666,19 +1580,15 @@ static void blecli_set_tx_pwr(char *pcWriteBuffer, int xWriteBufferLen, int argc
|
||||
|
||||
get_uint8_from_string(&argv[1], &power);
|
||||
#if defined(BL602)
|
||||
|
||||
if (power > 21) {
|
||||
vOutputString("ble_set_tx_pwr, invalid value, value shall be in [%d - %d]\r\n", 0, 21);
|
||||
return;
|
||||
}
|
||||
|
||||
#elif defined(BL702)
|
||||
|
||||
if (power > 14) {
|
||||
vOutputString("ble_set_tx_pwr, invalid value, value shall be in [%d - %d]\r\n", 0, 14);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
err = bt_set_tx_pwr((int8_t)power);
|
||||
|
||||
@ -1696,7 +1606,6 @@ static void blecli_disable(char *pcWriteBuffer, int xWriteBufferLen, int argc, c
|
||||
int err;
|
||||
|
||||
err = bt_disable();
|
||||
|
||||
if (err) {
|
||||
vOutputString("Fail to disable bt, there is existed scan/adv/conn event \r\n");
|
||||
} else {
|
||||
@ -1721,7 +1630,6 @@ static void blecli_hog_srv_notify(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
get_uint8_from_string(&argv[2], &press);
|
||||
|
||||
err = hog_notify(default_conn, hid_usage, press);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to send notification\r\n");
|
||||
} else {
|
||||
|
@ -139,11 +139,9 @@ static void bredr_write_eir(char *p_write_buffer, int write_buffer_len, int argc
|
||||
for (int i = 0; i < strlen(name); i++) {
|
||||
printf("0x%02x ", data[2 + i]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
err = bt_br_write_eir(rec, data);
|
||||
|
||||
if (err) {
|
||||
printf("BR/EDR write EIR failed, (err %d)\n", err);
|
||||
} else {
|
||||
|
@ -118,10 +118,9 @@ static void pts_ble_prepare_write(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
const struct cli_command PtsCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = {
|
||||
/*1.The cmd string to type, 2.Cmd description, 3.The function to run, 4.Number of parameters*/
|
||||
|
||||
{
|
||||
"pts_ble_address_register", "\r\npts_ble_address_register:\r\n\[Address type, 0:non-rpa, 1:rpa, 2:public adderss]\r\n\
|
||||
{ "pts_ble_address_register", "\r\npts_ble_address_register:\r\n\[Address type, 0:non-rpa, 1:rpa, 2:public adderss]\r\n\
|
||||
[Pts_address, e.g.peer_addr]\r\n",
|
||||
pts_ble_address_register },
|
||||
pts_ble_address_register },
|
||||
{ "pts_ble_set_flag", "\r\npts_ble_set_flag:[Set flag for different applications]\r\n\[Flag, e.g.0,1]\r\n", pts_ble_set_flag },
|
||||
{ "pts_ble_set_smp_flag", "\r\npts_ble_set_smp_flag:[Set flag for SM test]\r\n\[Flag, e.g.0,1]\r\n", pts_ble_set_smp_flag },
|
||||
{ "pts_ble_clear_smp_flag", "\r\npts_ble_clear_smp_flag:[Clear smp test flag]\r\n\[Flag, e.g.0,1]\r\n", pts_ble_clear_smp_flag },
|
||||
@ -315,9 +314,8 @@ static ssize_t pts_write_short_value(struct bt_conn *conn, const struct bt_gatt_
|
||||
u16_t tlen = len;
|
||||
u8_t *data = (u8_t *)buf;
|
||||
|
||||
for (i = 0; i < tlen; i++) {
|
||||
for (i = 0; i < tlen; i++)
|
||||
vOutputString("data[%d]->[0x%x]\r\n", i, data[i]);
|
||||
}
|
||||
|
||||
/*The rest of space is enough.*/
|
||||
if (TEST_SVAL_MAX >= tlen) {
|
||||
@ -327,9 +325,8 @@ static ssize_t pts_write_short_value(struct bt_conn *conn, const struct bt_gatt_
|
||||
}
|
||||
|
||||
/*If prepare write, it will return 0 */
|
||||
if (flags == BT_GATT_WRITE_FLAG_PREPARE) {
|
||||
if (flags == BT_GATT_WRITE_FLAG_PREPARE)
|
||||
tlen = 0;
|
||||
}
|
||||
|
||||
return tlen;
|
||||
}
|
||||
@ -390,9 +387,8 @@ static ssize_t pts_write_long_value(
|
||||
}
|
||||
|
||||
/*If prepare write, it will return 0 */
|
||||
if (flags == BT_GATT_WRITE_FLAG_PREPARE) {
|
||||
if (flags == BT_GATT_WRITE_FLAG_PREPARE)
|
||||
tlen = 0;
|
||||
}
|
||||
|
||||
return tlen;
|
||||
}
|
||||
@ -506,9 +502,9 @@ static struct bt_gatt_attr pts_attr[] = {
|
||||
#if defined(PTS_GAP_SLAVER_CONFIG_WRITE_CHARC)
|
||||
|
||||
/* Case : GATT/SR/GAR/BV-03-C
|
||||
* Verify that a Generic Attribute Profile server can support writing a Characteristic
|
||||
* Value selected by handle
|
||||
*/
|
||||
* Verify that a Generic Attribute Profile server can support writing a Characteristic
|
||||
* Value selected by handle
|
||||
*/
|
||||
BT_GATT_CHARACTERISTIC(
|
||||
BT_UUID_PTS_CHAR_WRITE_VALUE,
|
||||
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
|
||||
@ -518,9 +514,9 @@ static struct bt_gatt_attr pts_attr[] = {
|
||||
NULL),
|
||||
|
||||
/* Case : GATT/SR/GAR/BV-01-C
|
||||
* Verify that a Generic Attribute Profile server can support a write to a
|
||||
* characteristic without response
|
||||
*/
|
||||
* Verify that a Generic Attribute Profile server can support a write to a
|
||||
* characteristic without response
|
||||
*/
|
||||
BT_GATT_CHARACTERISTIC(
|
||||
BT_UUID_PTS_CHAR_WRITE_NORSP,
|
||||
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE_WITHOUT_RESP,
|
||||
@ -529,11 +525,11 @@ static struct bt_gatt_attr pts_attr[] = {
|
||||
pts_write_short_value,
|
||||
NULL),
|
||||
|
||||
/* Case : GATT/SR/GAR/BI-03-C, GATT/SR/GAR/BI-12-C
|
||||
* Verify that a Generic Attribute Profile server can detect and reject a
|
||||
* Write Characteristic Value Request to a non-writeable Characteristic Value
|
||||
* and issue a Write Not Permitted Response.
|
||||
*/
|
||||
/* Case : GATT/SR/GAR/BI-03-C, GATT/SR/GAR/BI-12-C
|
||||
* Verify that a Generic Attribute Profile server can detect and reject a
|
||||
* Write Characteristic Value Request to a non-writeable Characteristic Value
|
||||
* and issue a Write Not Permitted Response.
|
||||
*/
|
||||
BT_GATT_CHARACTERISTIC(
|
||||
BT_UUID_PTS_CHAR_WRITE_AUTHEN,
|
||||
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
|
||||
@ -580,8 +576,8 @@ static struct bt_gatt_attr pts_attr[] = {
|
||||
#if defined(PTS_GAP_SLAVER_CONFIG_READ_CHARC)
|
||||
|
||||
/* Case : GATT/SR/GAR/BI-04-C
|
||||
* Using authenticated link-key for read access. handle is 15
|
||||
*/
|
||||
* Using authenticated link-key for read access. handle is 15
|
||||
*/
|
||||
BT_GATT_CHARACTERISTIC(
|
||||
BT_UUID_PTS_CHAR_READ_AUTHEN,
|
||||
BT_GATT_CHRC_READ,
|
||||
@ -591,10 +587,10 @@ static struct bt_gatt_attr pts_attr[] = {
|
||||
NULL),
|
||||
|
||||
/* Case : GATT/SR/GAR/BI-06-C
|
||||
* Verify that a Generic Attribute Profile server can detect and reject a Read
|
||||
* Characteristic by UUID Request to a non-readable Characteristic Value and issue
|
||||
* a Read Not Permitted Response
|
||||
*/
|
||||
* Verify that a Generic Attribute Profile server can detect and reject a Read
|
||||
* Characteristic by UUID Request to a non-readable Characteristic Value and issue
|
||||
* a Read Not Permitted Response
|
||||
*/
|
||||
BT_GATT_CHARACTERISTIC(
|
||||
BT_UUID_PTS_CHAR_READ_NOPERM,
|
||||
BT_GATT_CHRC_READ,
|
||||
@ -604,9 +600,9 @@ static struct bt_gatt_attr pts_attr[] = {
|
||||
NULL),
|
||||
|
||||
/* Case : GATT/SR/GAR/BV-04-C;GATT/SR/GAR/BI-13-C
|
||||
* Verify that a Generic Attribute Profile server can support reading a
|
||||
* long Characteristic Value selected by handle.
|
||||
*/
|
||||
* Verify that a Generic Attribute Profile server can support reading a
|
||||
* long Characteristic Value selected by handle.
|
||||
*/
|
||||
BT_GATT_CHARACTERISTIC(
|
||||
BT_UUID_PTS_CHAR_READ_LONGVAL,
|
||||
BT_GATT_CHRC_READ,
|
||||
@ -616,9 +612,9 @@ static struct bt_gatt_attr pts_attr[] = {
|
||||
NULL),
|
||||
|
||||
/* Case : GATT/SR/GAR/BV-06-C;GATT/SR/GAR/BV-07-C;GATT/SR/GAR/BV-08-C
|
||||
* Verify that a Generic Attribute Profile server can support reading a Long
|
||||
* Characteristic Descriptor selected by handle.
|
||||
*/
|
||||
* Verify that a Generic Attribute Profile server can support reading a Long
|
||||
* Characteristic Descriptor selected by handle.
|
||||
*/
|
||||
BT_GATT_DESCRIPTOR(
|
||||
BT_UUID_PTS_CHAR_READ_LVAL_REF,
|
||||
BT_GATT_PERM_READ,
|
||||
@ -627,10 +623,10 @@ static struct bt_gatt_attr pts_attr[] = {
|
||||
report),
|
||||
|
||||
/* Case : GATT/SR/GAR/BI-12-C
|
||||
* Verify that a Generic Attribute Profile server can detect and reject a Read Long
|
||||
* Characteristic Value Request to a non-readable Characteristic Value and issue a
|
||||
* Read Not Permitted Response.
|
||||
*/
|
||||
* Verify that a Generic Attribute Profile server can detect and reject a Read Long
|
||||
* Characteristic Value Request to a non-readable Characteristic Value and issue a
|
||||
* Read Not Permitted Response.
|
||||
*/
|
||||
BT_GATT_CHARACTERISTIC(
|
||||
BT_UUID_PTS_CHAR_READ_L_NOPERM,
|
||||
BT_GATT_CHRC_READ,
|
||||
@ -714,7 +710,6 @@ static void pts_ble_notify(char *pcWriteBuffer, int xWriteBufferLen, int argc, c
|
||||
vOutputString("len = [0x%x]\r\n", params.len);
|
||||
|
||||
err = bt_gatt_notify_cb(default_conn, ¶ms);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to notifition [%d]\r\n", err);
|
||||
}
|
||||
@ -762,7 +757,6 @@ static void pts_ble_indicate(char *pcWriteBuffer, int xWriteBufferLen, int argc,
|
||||
vOutputString("len = [0x%x] handle(0x%x)\r\n", params.len, params.attr->handle);
|
||||
|
||||
err = bt_gatt_indicate(default_conn, ¶ms);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to indicate [%d]\r\n", err);
|
||||
}
|
||||
@ -782,7 +776,6 @@ static bool data_cb(struct bt_data *data, void *user_data)
|
||||
len = (data->data_len > NAME_LEN - 1) ? (NAME_LEN - 1) : (data->data_len);
|
||||
memcpy(name, data->data, len);
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@ -826,9 +819,8 @@ static void pts_device_found(const bt_addr_le_t *addr, s8_t rssi, u8_t evtype,
|
||||
if (!memcmp(&pts_addr, addr, sizeof(bt_addr_le_t)) ||
|
||||
!memcmp(name, pts_cmplt_name, sizeof(*pts_cmplt_name)) ||
|
||||
!memcmp(name, pts_short_name, sizeof(*pts_short_name))) {
|
||||
if (memcmp(&pts_addr, addr, sizeof(bt_addr_le_t))) {
|
||||
if (memcmp(&pts_addr, addr, sizeof(bt_addr_le_t)))
|
||||
memcpy(&pts_addr, addr, sizeof(pts_addr));
|
||||
}
|
||||
|
||||
vOutputString("[DEVICE]: %s, AD evt type %u, RSSI %i %s \r\n", le_addr, evtype, rssi, name);
|
||||
|
||||
@ -836,15 +828,13 @@ static void pts_device_found(const bt_addr_le_t *addr, s8_t rssi, u8_t evtype,
|
||||
|
||||
if (*ad_flag & 0x01) {
|
||||
vOutputString("Advertising data : 'Limited Discovered Mode' flag is set one\r\n");
|
||||
} else {
|
||||
} else
|
||||
vOutputString("Advertising data : 'Limited Discovered Mode' flag is not set\r\n");
|
||||
}
|
||||
|
||||
if (*ad_flag & 0x02) {
|
||||
vOutputString("Advertising data : 'General Discovered Mode' flag is set one\r\n");
|
||||
} else {
|
||||
} else
|
||||
vOutputString("Advertising data : 'General Discovered Mode' flag is not set\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -890,7 +880,6 @@ static void pts_ble_sc_indicate(char *pcWriteBuffer, int xWriteBufferLen, int ar
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.func = NULL;
|
||||
err = service_change_test(¶ms, default_conn);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to sc indicate\r\n");
|
||||
return;
|
||||
@ -916,7 +905,6 @@ static void pts_ble_start_scan_rpa(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
get_uint8_from_string(&argv[5], (uint8_t *)&is_rpa);
|
||||
|
||||
err = bt_le_pts_scan_start(&scan_param, pts_device_found, is_rpa);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to start scan (err %d) \r\n", err);
|
||||
} else {
|
||||
@ -947,12 +935,10 @@ static void pts_ble_add_dev_to_resolve_list(char *pcWriteBuffer, int xWriteBuffe
|
||||
get_uint8_from_string(&argv[1], &type);
|
||||
get_bytearray_from_string(&argv[2], val /*(uint8_t *)addr.a.val*/, 6);
|
||||
reverse_bytearray(val, addr.a.val, 6);
|
||||
|
||||
if (type == 0) {
|
||||
if (type == 0)
|
||||
addr.type = BT_ADDR_LE_PUBLIC;
|
||||
} else if (type == 1) {
|
||||
else if (type == 1)
|
||||
addr.type = BT_ADDR_LE_RANDOM;
|
||||
}
|
||||
|
||||
memcpy(&key.addr, &addr, sizeof(bt_addr_le_t));
|
||||
memcpy(key.irk.val, peer_irk, 16);
|
||||
@ -966,7 +952,6 @@ static void pts_ble_register_pts_svc(char *pcWriteBuffer, int xWriteBufferLen, i
|
||||
int err;
|
||||
|
||||
err = bt_gatt_service_register(&pts_svc);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to register PTS service\r\n");
|
||||
} else {
|
||||
@ -982,17 +967,17 @@ static int set_attr_enc_key_size(const struct bt_gatt_attr *attr,
|
||||
|
||||
/* Fail if requested attribute is a service */
|
||||
/*if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_PRIMARY) ||
|
||||
!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_SECONDARY) ||
|
||||
!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_INCLUDE)) {
|
||||
return -1;
|
||||
}*/
|
||||
!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_SECONDARY) ||
|
||||
!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_INCLUDE)) {
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
/* Fail if permissions are not set */
|
||||
/*if (!(attr->perm & ((BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_READ_AUTHEN) |
|
||||
(BT_GATT_PERM_WRITE_ENCRYPT | BT_GATT_PERM_WRITE_AUTHEN)))) {
|
||||
|
||||
return -1;
|
||||
}*/
|
||||
(BT_GATT_PERM_WRITE_ENCRYPT | BT_GATT_PERM_WRITE_AUTHEN)))) {
|
||||
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
vOutputString("perm:0x%x\r\n", attr->perm);
|
||||
vOutputString("handle:0x%04x\r\n", attr->handle);
|
||||
@ -1011,11 +996,10 @@ static void pts_set_enc_key_size(char *pcWriteBuffer, int xWriteBufferLen, int a
|
||||
get_uint8_from_string(&argv[1], &key_size);
|
||||
get_uint8_from_string(&argv[2], &index);
|
||||
|
||||
if (key_size < 0x07 || key_size > 0x0f) {
|
||||
if (key_size < 0x07 || key_size > 0x0f)
|
||||
vOutputString("Invalid key size(%d)\r\n", key_size);
|
||||
} else {
|
||||
else {
|
||||
err = set_attr_enc_key_size(&pts_attr[index], key_size);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to set attr enc key size(%d)\r\n", err);
|
||||
}
|
||||
@ -1041,7 +1025,6 @@ static void pts_ble_wl_connect(char *pcWriteBuffer, int xWriteBufferLen, int arg
|
||||
|
||||
if (enable == 0x01) {
|
||||
err = bt_conn_create_auto_le(¶m);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Auto connect failed (err = [%d])\r\n", err);
|
||||
return;
|
||||
@ -1050,7 +1033,6 @@ static void pts_ble_wl_connect(char *pcWriteBuffer, int xWriteBufferLen, int arg
|
||||
}
|
||||
} else if (enable == 0x02) {
|
||||
err = bt_conn_create_auto_stop();
|
||||
|
||||
if (err) {
|
||||
vOutputString("Auto connection stop (err = [%d])\r\n", err);
|
||||
return;
|
||||
@ -1070,7 +1052,6 @@ static void pts_ble_bt_le_whitelist_add(char *pcWriteBuffer, int xWriteBufferLen
|
||||
}
|
||||
|
||||
err = bt_le_whitelist_clear();
|
||||
|
||||
if (err) {
|
||||
vOutputString("Clear white list device failed (err = [%d])\r\n", err);
|
||||
}
|
||||
@ -1081,7 +1062,6 @@ static void pts_ble_bt_le_whitelist_add(char *pcWriteBuffer, int xWriteBufferLen
|
||||
reverse_bytearray(val, waddr.a.val, 6);
|
||||
|
||||
err = bt_le_whitelist_add(&waddr);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to add device to whitelist (err = [%d])\r\n", err);
|
||||
}
|
||||
@ -1103,7 +1083,6 @@ static void pts_ble_start_scan_timeout(char *pcWriteBuffer, int xWriteBufferLen,
|
||||
get_uint16_from_string(&argv[6], (uint16_t *)&time);
|
||||
|
||||
err = bt_le_pts_scan_start(&scan_param, pts_device_found, addre_type);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Failed to start scan (err %d) \r\n", err);
|
||||
} else {
|
||||
@ -1126,9 +1105,8 @@ static void pts_ble_address_register(char *pcWriteBuffer, int xWriteBufferLen, i
|
||||
|
||||
if (type == 0) {
|
||||
addr.type = BT_ADDR_LE_PUBLIC;
|
||||
} else if (type == 1) {
|
||||
} else if (type == 1)
|
||||
addr.type = BT_ADDR_LE_RANDOM;
|
||||
}
|
||||
|
||||
memcpy(&pts_addr, &addr, sizeof(bt_addr_le_t));
|
||||
|
||||
@ -1174,13 +1152,12 @@ static void pts_ble_bondable(char *pcWriteBuffer, int xWriteBufferLen, int argc,
|
||||
|
||||
get_uint8_from_string(&argv[1], &bondable);
|
||||
|
||||
if (bondable == 0x01) {
|
||||
if (bondable == 0x01)
|
||||
bt_set_bondable(true);
|
||||
} else if (bondable == 0x00) {
|
||||
else if (bondable == 0x00)
|
||||
bt_set_bondable(false);
|
||||
} else {
|
||||
else
|
||||
vOutputString("Bondable status is unknow \r\n");
|
||||
}
|
||||
}
|
||||
#endif //#if defined(CONFIG_BT_OBSERVER)
|
||||
|
||||
@ -1205,7 +1182,6 @@ static void pts_ble_start_advertise(char *pcWriteBuffer, int xWriteBufferLen, in
|
||||
vOutputString("Number of Parameters is not correct\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event_flag) {
|
||||
case ad_type_service_uuid:
|
||||
pts_ad.type = BT_DATA_UUID128_ALL;
|
||||
@ -1298,15 +1274,13 @@ static void pts_ble_start_advertise(char *pcWriteBuffer, int xWriteBufferLen, in
|
||||
ad = ad_discov;
|
||||
ad_len = ARRAY_SIZE(ad_discov);
|
||||
}
|
||||
|
||||
if (is_ad == 1) {
|
||||
ad = &pts_ad;
|
||||
ad_len = 1;
|
||||
} /*else{
|
||||
|
||||
ad = ad_discov;
|
||||
ad_len = ARRAY_SIZE(ad_discov);
|
||||
}*/
|
||||
ad = ad_discov;
|
||||
ad_len = ARRAY_SIZE(ad_discov);
|
||||
}*/
|
||||
|
||||
} else {
|
||||
vOutputString("Arg2 is invalid\r\n");
|
||||
@ -1317,15 +1291,14 @@ static void pts_ble_start_advertise(char *pcWriteBuffer, int xWriteBufferLen, in
|
||||
//get_bytearray_from_string(&argv[3], (u8_t *)¶m.addr_type, 1);
|
||||
get_uint8_from_string(&argv[3], (u8_t *)&adder_type);
|
||||
|
||||
if (adder_type == 0) {
|
||||
if (adder_type == 0)
|
||||
param.addr_type = BT_ADDR_TYPE_NON_RPA;
|
||||
} else if (adder_type == 1) {
|
||||
else if (adder_type == 1)
|
||||
param.addr_type = BT_ADDR_TYPE_RPA;
|
||||
} else if (adder_type == 2) {
|
||||
else if (adder_type == 2)
|
||||
param.addr_type = BT_ADDR_LE_PUBLIC;
|
||||
} else {
|
||||
else
|
||||
vOutputString("Invaild address type\r\n");
|
||||
}
|
||||
|
||||
if (argc == 6) {
|
||||
get_uint16_from_string(&argv[4], ¶m.interval_min);
|
||||
@ -1343,7 +1316,6 @@ static void pts_ble_start_advertise(char *pcWriteBuffer, int xWriteBufferLen, in
|
||||
pts.type = BT_ADDR_LE_PUBLIC;
|
||||
memcpy(pts.a.val, pts_address, 6);
|
||||
conn = bt_conn_create_slave_le(&pts, ¶m);
|
||||
|
||||
if (!conn) {
|
||||
err = 1;
|
||||
} else {
|
||||
@ -1391,7 +1363,6 @@ static void pts_ble_connect_le(char *pcWriteBuffer, int xWriteBufferLen, int arg
|
||||
vOutputString("Number of Parameters is not correct\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event_flag == own_addr_type_random) {
|
||||
param.own_address_type = BT_ADDR_LE_RANDOM_ID;
|
||||
}
|
||||
@ -1399,17 +1370,16 @@ static void pts_ble_connect_le(char *pcWriteBuffer, int xWriteBufferLen, int arg
|
||||
get_uint8_from_string(&argv[1], (u8_t *)&type);
|
||||
|
||||
/*Get addr type,0:ADDR_RAND, 1:ADDR_RPA_OR_PUBLIC,2:ADDR_PUBLIC, 3:ADDR_RPA_OR_RAND*/
|
||||
if (type == 0) {
|
||||
if (type == 0)
|
||||
addr.type = 1; /*ADDR_RAND*/
|
||||
} else if (type == 1) {
|
||||
else if (type == 1)
|
||||
addr.type = 2; /*ADDR_RPA_OR_PUBLIC*/
|
||||
} else if (type == 2) {
|
||||
else if (type == 2)
|
||||
addr.type = 0; /*ADDR_PUBLIC*/
|
||||
} else if (type == 3) {
|
||||
else if (type == 3)
|
||||
addr.type = 3; /*ADDR_RPA_OR_RAND*/
|
||||
} else {
|
||||
else
|
||||
vOutputString("adderss type is unknow [0x%x]\r\n", type);
|
||||
}
|
||||
|
||||
get_bytearray_from_string(&argv[2], addr_val, 6);
|
||||
|
||||
@ -1417,17 +1387,16 @@ static void pts_ble_connect_le(char *pcWriteBuffer, int xWriteBufferLen, int arg
|
||||
|
||||
get_uint8_from_string(&argv[3], (u8_t *)&type);
|
||||
|
||||
if (type == 0) {
|
||||
if (type == 0)
|
||||
param.own_address_type = 1; /*ADDR_RAND*/
|
||||
} else if (type == 1) {
|
||||
else if (type == 1)
|
||||
param.own_address_type = 2; /*ADDR_RPA_OR_PUBLIC*/
|
||||
} else if (type == 2) {
|
||||
else if (type == 2)
|
||||
param.own_address_type = 0; /*ADDR_PUBLIC*/
|
||||
} else if (type == 3) {
|
||||
else if (type == 3)
|
||||
param.own_address_type = 3; /*ADDR_RPA_OR_RAND*/
|
||||
} else {
|
||||
else
|
||||
vOutputString("adderss type is unknow [0x%x]\r\n", type);
|
||||
}
|
||||
|
||||
conn = bt_conn_create_le(&addr, /*BT_LE_CONN_PARAM_DEFAULT*/ ¶m);
|
||||
|
||||
@ -1451,23 +1420,21 @@ static void pts_ble_disconnect(char *pcWriteBuffer, int xWriteBufferLen, int arg
|
||||
vOutputString("Number of Parameters is not correct\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
get_uint8_from_string(&argv[1], (u8_t *)&type);
|
||||
get_bytearray_from_string(&argv[2], addr_val, 6);
|
||||
reverse_bytearray(addr_val, addr.a.val, 6);
|
||||
|
||||
/*Get addr type,0:ADDR_RAND, 1:ADDR_RPA_OR_PUBLIC,2:ADDR_PUBLIC, 3:ADDR_RPA_OR_RAND*/
|
||||
if (type == 0) {
|
||||
if (type == 0)
|
||||
addr.type = 1; /*ADDR_RAND*/
|
||||
} else if (type == 1) {
|
||||
else if (type == 1)
|
||||
addr.type = 2; /*ADDR_RPA_OR_PUBLIC*/
|
||||
} else if (type == 2) {
|
||||
else if (type == 2)
|
||||
addr.type = 0; /*ADDR_PUBLIC*/
|
||||
} else if (type == 3) {
|
||||
else if (type == 3)
|
||||
addr.type = 3; /*ADDR_RPA_OR_RAND*/
|
||||
} else {
|
||||
else
|
||||
vOutputString("adderss type is unknow\r\n");
|
||||
}
|
||||
|
||||
conn = bt_conn_lookup_addr_le(selected_id, &addr);
|
||||
|
||||
@ -1481,7 +1448,6 @@ static void pts_ble_disconnect(char *pcWriteBuffer, int xWriteBufferLen, int arg
|
||||
} else {
|
||||
vOutputString("Disconnect successfully\r\n");
|
||||
}
|
||||
|
||||
bt_conn_unref(conn);
|
||||
}
|
||||
|
||||
@ -1494,23 +1460,20 @@ static void pts_ble_conn_update(char *pcWriteBuffer, int xWriteBufferLen, int ar
|
||||
vOutputString("Number of Parameters is not correct\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (default_conn == NULL) {
|
||||
vOutputString("Connection is NULL\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(¶m, 0, sizeof(struct bt_le_conn_param));
|
||||
get_uint16_from_string(&argv[1], ¶m.interval_min);
|
||||
get_uint16_from_string(&argv[2], ¶m.interval_max);
|
||||
get_uint16_from_string(&argv[3], ¶m.latency);
|
||||
get_uint16_from_string(&argv[4], ¶m.timeout);
|
||||
|
||||
if (event_flag == dir_connect_req) {
|
||||
if (event_flag == dir_connect_req)
|
||||
err = bt_conn_le_param_update(default_conn, ¶m);
|
||||
} else {
|
||||
else
|
||||
err = pts_bt_conn_le_param_update(default_conn, ¶m);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
vOutputString("conn update failed (err %d)\r\n", err);
|
||||
@ -1527,13 +1490,12 @@ static void pts_ble_set_mitm(char *pcWriteBuffer, int xWriteBufferLen, int argc,
|
||||
|
||||
get_uint8_from_string(&argv[1], &enable);
|
||||
|
||||
if (enable == 0x01) {
|
||||
if (enable == 0x01)
|
||||
bt_set_mitm(true);
|
||||
} else if (enable == 0x00) {
|
||||
else if (enable == 0x00)
|
||||
bt_set_mitm(false);
|
||||
} else {
|
||||
else
|
||||
vOutputString("Inviad parameter\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
#endif //#if defined(CONFIG_BT_SMP)
|
||||
@ -1562,7 +1524,6 @@ static void pts_ble_discover_uuid_128(char *pcWriteBuffer, int xWriteBufferLen,
|
||||
discover_params.end_handle = 0xffff;
|
||||
|
||||
get_uint8_from_string(&argv[1], &disc_type);
|
||||
|
||||
if (disc_type == 0) {
|
||||
discover_params.type = BT_GATT_DISCOVER_PRIMARY;
|
||||
} else if (disc_type == 1) {
|
||||
@ -1577,7 +1538,6 @@ static void pts_ble_discover_uuid_128(char *pcWriteBuffer, int xWriteBufferLen,
|
||||
vOutputString("Invalid discovery type\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
get_bytearray_from_string(&argv[2], val, 16);
|
||||
|
||||
reverse_bytearray(val, uuid_128.val, 16);
|
||||
@ -1585,17 +1545,15 @@ static void pts_ble_discover_uuid_128(char *pcWriteBuffer, int xWriteBufferLen,
|
||||
/*Set array value to 0 */
|
||||
(void)memset(val, 0x0, 16);
|
||||
|
||||
if (!memcmp(uuid_128.val, val, 16)) {
|
||||
if (!memcmp(uuid_128.val, val, 16))
|
||||
discover_params.uuid = NULL;
|
||||
} else {
|
||||
else
|
||||
discover_params.uuid = &uuid_128.uuid;
|
||||
}
|
||||
|
||||
get_uint16_from_string(&argv[3], &discover_params.start_handle);
|
||||
get_uint16_from_string(&argv[4], &discover_params.end_handle);
|
||||
|
||||
err = bt_gatt_discover(default_conn, &discover_params);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Discover failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -1619,10 +1577,8 @@ static u8_t read_func(struct bt_conn *conn, u8_t err, struct bt_gatt_read_params
|
||||
vOutputString("device name : %s \r\n", str);
|
||||
|
||||
u8_t i = 0;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
for (i = 0; i < length; i++)
|
||||
vOutputString("data[%d] = [0x%x]\r\n", i, buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
@ -1662,17 +1618,15 @@ static void pts_ble_read_uuid_128(char *pcWriteBuffer, int xWriteBufferLen, int
|
||||
|
||||
(void)memset(val, 0, 16);
|
||||
|
||||
if (!memcmp(uuid.val, val, 16)) {
|
||||
if (!memcmp(uuid.val, val, 16))
|
||||
read_params.by_uuid.uuid = NULL;
|
||||
} else {
|
||||
else
|
||||
read_params.by_uuid.uuid = &uuid.uuid;
|
||||
}
|
||||
|
||||
get_uint16_from_string(&argv[2], &read_params.by_uuid.start_handle);
|
||||
get_uint16_from_string(&argv[3], &read_params.by_uuid.end_handle);
|
||||
|
||||
err = bt_gatt_read(default_conn, &read_params);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Read failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -1701,16 +1655,13 @@ static void pts_ble_read_uuid(char *pcWriteBuffer, int xWriteBufferLen, int argc
|
||||
read_params.by_uuid.end_handle = 0xffff;
|
||||
|
||||
get_uint16_from_string(&argv[1], &uuid.val);
|
||||
|
||||
if (uuid.val) {
|
||||
if (uuid.val)
|
||||
read_params.by_uuid.uuid = &uuid.uuid;
|
||||
}
|
||||
|
||||
get_uint16_from_string(&argv[2], &read_params.by_uuid.start_handle);
|
||||
get_uint16_from_string(&argv[3], &read_params.by_uuid.end_handle);
|
||||
|
||||
err = bt_gatt_read(default_conn, &read_params);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Read failed (err %d)\r\n", err);
|
||||
} else {
|
||||
@ -1744,7 +1695,6 @@ static void pts_ble_mread(char *pcWriteBuffer, int xWriteBufferLen, int argc, ch
|
||||
vOutputString("i = [%d]\r\n", i);
|
||||
|
||||
err = bt_gatt_read(default_conn, &read_params);
|
||||
|
||||
if (err) {
|
||||
vOutputString("Read failed (err %d)\r\n", err);
|
||||
} else {
|
||||
|
@ -21,9 +21,12 @@
|
||||
#include <string.h>
|
||||
#include <misc/byteorder.h>
|
||||
#include <net/buf.h>
|
||||
#if defined(BFLB_BLE)
|
||||
#if defined(BFLB_DYNAMIC_ALLOC_MEM)
|
||||
#include "bl_port.h"
|
||||
#endif
|
||||
#include "bl_hci_wrapper.h"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_BUF_LOG)
|
||||
#define NET_BUF_DBG(fmt, ...) LOG_DBG("(%p) " fmt, k_current_get(), \
|
||||
@ -130,9 +133,9 @@ struct net_buf_pool *_net_buf_pool_list[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
#else //defined(BFLB_DYNAMIC_ALLOC_MEM)
|
||||
#else
|
||||
extern struct net_buf_pool _net_buf_pool_list[];
|
||||
#endif //BFLB_BLE
|
||||
#endif //BFLB_DYNAMIC_ALLOC_MEM
|
||||
|
||||
#if defined(BFLB_DYNAMIC_ALLOC_MEM)
|
||||
void net_buf_init(struct net_buf_pool *buf_pool, u16_t buf_count, size_t data_size, destroy_cb_t destroy)
|
||||
@ -153,10 +156,15 @@ void net_buf_init(struct net_buf_pool *buf_pool, u16_t buf_count, size_t data_si
|
||||
buf_pool->avail_count = buf_count;
|
||||
#endif
|
||||
buf_pool->destroy = destroy;
|
||||
|
||||
k_lifo_init(&(buf_pool->free), buf_count);
|
||||
}
|
||||
|
||||
void net_buf_deinit(struct net_buf_pool *buf_pool)
|
||||
{
|
||||
extern void bt_delete_queue(struct k_fifo * queue_to_del);
|
||||
bt_delete_queue((struct k_fifo *)(&(buf_pool->free)));
|
||||
|
||||
struct net_buf_pool_fixed *buf_fixed = (struct net_buf_pool_fixed *)buf_pool->alloc->alloc_data;
|
||||
k_free(buf_fixed->data_pool);
|
||||
k_free(buf_pool->__bufs);
|
||||
@ -184,7 +192,6 @@ static int pool_id(struct net_buf_pool *pool)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NET_BUF_ASSERT(index < (sizeof(_net_buf_pool_list) / 4));
|
||||
return index;
|
||||
#else
|
||||
@ -261,7 +268,6 @@ static void mem_pool_data_unref(struct net_buf *buf, u8_t *data)
|
||||
u8_t *ref_count;
|
||||
|
||||
ref_count = data - 1;
|
||||
|
||||
if (--(*ref_count)) {
|
||||
return;
|
||||
}
|
||||
@ -305,7 +311,6 @@ static u8_t *heap_data_alloc(struct net_buf *buf, size_t *size, s32_t timeout)
|
||||
u8_t *ref_count;
|
||||
|
||||
ref_count = k_malloc(1 + *size);
|
||||
|
||||
if (!ref_count) {
|
||||
return NULL;
|
||||
}
|
||||
@ -320,7 +325,6 @@ static void heap_data_unref(struct net_buf *buf, u8_t *data)
|
||||
u8_t *ref_count;
|
||||
|
||||
ref_count = data - 1;
|
||||
|
||||
if (--(*ref_count)) {
|
||||
return;
|
||||
}
|
||||
@ -384,23 +388,22 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
|
||||
size, timeout);
|
||||
|
||||
/* We need to lock interrupts temporarily to prevent race conditions
|
||||
* when accessing pool->uninit_count.
|
||||
*/
|
||||
* when accessing pool->uninit_count.
|
||||
*/
|
||||
key = irq_lock();
|
||||
|
||||
/* If there are uninitialized buffers we're guaranteed to succeed
|
||||
* with the allocation one way or another.
|
||||
*/
|
||||
* with the allocation one way or another.
|
||||
*/
|
||||
if (pool->uninit_count) {
|
||||
u16_t uninit_count;
|
||||
|
||||
/* If this is not the first access to the pool, we can
|
||||
* be opportunistic and try to fetch a previously used
|
||||
* buffer from the LIFO with K_NO_WAIT.
|
||||
*/
|
||||
* be opportunistic and try to fetch a previously used
|
||||
* buffer from the LIFO with K_NO_WAIT.
|
||||
*/
|
||||
if (pool->uninit_count < pool->buf_count) {
|
||||
buf = k_lifo_get(&pool->free, K_NO_WAIT);
|
||||
|
||||
if (buf) {
|
||||
irq_unlock(key);
|
||||
goto success;
|
||||
@ -417,11 +420,9 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
|
||||
irq_unlock(key);
|
||||
|
||||
#if defined(CONFIG_NET_BUF_LOG) && (CONFIG_NET_BUF_LOG_LEVEL >= LOG_LEVEL_WRN)
|
||||
|
||||
if (timeout == K_FOREVER) {
|
||||
u32_t ref = k_uptime_get_32();
|
||||
buf = k_lifo_get(&pool->free, K_NO_WAIT);
|
||||
|
||||
while (!buf) {
|
||||
#if defined(CONFIG_NET_BUF_POOL_USAGE)
|
||||
NET_BUF_WARN("%s():%d: Pool %s low on buffers.",
|
||||
@ -444,11 +445,9 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
|
||||
} else {
|
||||
buf = k_lifo_get(&pool->free, timeout);
|
||||
}
|
||||
|
||||
#else
|
||||
buf = k_lifo_get(&pool->free, timeout);
|
||||
#endif
|
||||
|
||||
if (!buf) {
|
||||
NET_BUF_ERR("%s():%d: Failed to get free buffer", func, line);
|
||||
return NULL;
|
||||
@ -465,7 +464,6 @@ success:
|
||||
}
|
||||
|
||||
buf->__buf = data_alloc(buf, &size, timeout);
|
||||
|
||||
if (!buf->__buf) {
|
||||
NET_BUF_ERR("%s():%d: Failed to allocate data",
|
||||
func, line);
|
||||
@ -527,7 +525,6 @@ struct net_buf *net_buf_alloc_with_data(struct net_buf_pool *pool,
|
||||
#else
|
||||
buf = net_buf_alloc_len(pool, 0, timeout);
|
||||
#endif
|
||||
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
@ -553,7 +550,6 @@ struct net_buf *net_buf_get(struct k_fifo *fifo, s32_t timeout)
|
||||
NET_BUF_DBG("%s():%d: fifo %p timeout %d", func, line, fifo, timeout);
|
||||
|
||||
buf = k_fifo_get(fifo, timeout);
|
||||
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
@ -657,11 +653,6 @@ void net_buf_put(struct k_fifo *fifo, struct net_buf *buf)
|
||||
k_fifo_put_list(fifo, buf, tail);
|
||||
}
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
extern struct net_buf_pool hci_rx_pool;
|
||||
extern void bl_handle_queued_msg(void);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_BUF_LOG)
|
||||
void net_buf_unref_debug(struct net_buf *buf, const char *func, int line)
|
||||
#else
|
||||
@ -673,30 +664,22 @@ void net_buf_unref(struct net_buf *buf)
|
||||
while (buf) {
|
||||
struct net_buf *frags = buf->frags;
|
||||
struct net_buf_pool *pool;
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
u8_t buf_type = bt_buf_get_type(buf);
|
||||
bool adv_report = bt_buf_check_rx_adv(buf);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_BUF_LOG)
|
||||
|
||||
if (!buf->ref) {
|
||||
NET_BUF_ERR("%s():%d: buf %p double free", func, line,
|
||||
buf);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
NET_BUF_DBG("buf %p ref %u pool_id %u frags %p", buf, buf->ref,
|
||||
buf->pool_id, buf->frags);
|
||||
|
||||
unsigned int key = irq_lock(); /* Added by bouffalo lab, to protect ref decrease */
|
||||
|
||||
if (--buf->ref > 0) {
|
||||
irq_unlock(key); /* Added by bouffalo lab */
|
||||
return;
|
||||
}
|
||||
|
||||
irq_unlock(key); /* Added by bouffalo lab */
|
||||
|
||||
if (buf->__buf) {
|
||||
@ -722,13 +705,11 @@ void net_buf_unref(struct net_buf *buf)
|
||||
|
||||
buf = frags;
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
|
||||
if (pool == &hci_rx_pool && (buf_type == BT_BUF_ACL_IN || adv_report == true)) {
|
||||
bl_handle_queued_msg();
|
||||
#if defined(BFLB_BLE)
|
||||
if (pool == &hci_rx_pool) {
|
||||
bl_trigger_queued_msg();
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -757,14 +738,13 @@ struct net_buf *net_buf_clone(struct net_buf *buf, s32_t timeout)
|
||||
pool = net_buf_pool_get(buf->pool_id);
|
||||
|
||||
clone = net_buf_alloc_len(pool, 0, timeout);
|
||||
|
||||
if (!clone) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If the pool supports data referencing use that. Otherwise
|
||||
* we need to allocate new data and make a copy.
|
||||
*/
|
||||
* we need to allocate new data and make a copy.
|
||||
*/
|
||||
if (pool->alloc->cb->ref && !(buf->flags & NET_BUF_EXTERNAL_DATA)) {
|
||||
clone->__buf = data_ref(buf, buf->__buf);
|
||||
clone->data = buf->data;
|
||||
@ -780,7 +760,6 @@ struct net_buf *net_buf_clone(struct net_buf *buf, s32_t timeout)
|
||||
}
|
||||
|
||||
clone->__buf = data_alloc(clone, &size, timeout);
|
||||
|
||||
if (!clone->__buf || size < buf->size) {
|
||||
net_buf_destroy(clone);
|
||||
return NULL;
|
||||
@ -813,7 +792,6 @@ void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag)
|
||||
if (parent->frags) {
|
||||
net_buf_frag_last(frag)->frags = parent->frags;
|
||||
}
|
||||
|
||||
/* Take ownership of the fragment reference */
|
||||
parent->frags = frag;
|
||||
}
|
||||
@ -881,7 +859,6 @@ size_t net_buf_linearize(void *dst, size_t dst_len, struct net_buf *src,
|
||||
|
||||
/* traverse the fragment chain until len bytes are copied */
|
||||
copied = 0;
|
||||
|
||||
while (frag && len > 0) {
|
||||
to_copy = MIN(len, frag->len - offset);
|
||||
memcpy((u8_t *)dst + copied, frag->data + offset, to_copy);
|
||||
@ -924,7 +901,6 @@ size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
|
||||
}
|
||||
|
||||
frag = allocate_cb(timeout, user_data);
|
||||
|
||||
if (!frag) {
|
||||
return added_len;
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ u8_t u8_to_dec(char *buf, u8_t buflen, u8_t value)
|
||||
|
||||
while (buflen > 0 && divisor > 0) {
|
||||
digit = value / divisor;
|
||||
|
||||
if (digit != 0 || divisor == 1 || num_digits != 0) {
|
||||
*buf = (char)digit + '0';
|
||||
buf++;
|
||||
|
@ -13,19 +13,19 @@
|
||||
|
||||
#if defined(CONFIG_BT_HCI_HOST)
|
||||
/* The Bluetooth subsystem requires the Tx thread to execute at higher priority
|
||||
* than the Rx thread as the Tx thread needs to process the acknowledgements
|
||||
* before new Rx data is processed. This is a necessity to correctly detect
|
||||
* transaction violations in ATT and SMP protocols.
|
||||
*/
|
||||
* than the Rx thread as the Tx thread needs to process the acknowledgements
|
||||
* before new Rx data is processed. This is a necessity to correctly detect
|
||||
* transaction violations in ATT and SMP protocols.
|
||||
*/
|
||||
BUILD_ASSERT(CONFIG_BT_HCI_TX_PRIO < CONFIG_BT_RX_PRIO);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_CTLR)
|
||||
/* The Bluetooth Controller's priority receive thread priority shall be higher
|
||||
* than the Bluetooth Host's Tx and the Controller's receive thread priority.
|
||||
* This is required in order to dispatch Number of Completed Packets event
|
||||
* before any new data arrives on a connection to the Host threads.
|
||||
*/
|
||||
* than the Bluetooth Host's Tx and the Controller's receive thread priority.
|
||||
* This is required in order to dispatch Number of Completed Packets event
|
||||
* before any new data arrives on a connection to the Host threads.
|
||||
*/
|
||||
BUILD_ASSERT(CONFIG_BT_CTLR_RX_PRIO < CONFIG_BT_HCI_TX_PRIO);
|
||||
#endif /* CONFIG_BT_CTLR */
|
||||
|
||||
|
@ -47,7 +47,6 @@ size_t bin2hex(const u8_t *buf, size_t buflen, char *hex, size_t hexlen)
|
||||
if (hex2char(buf[i] >> 4, &hex[2 * i]) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (hex2char(buf[i] & 0xf, &hex[2 * i + 1]) < 0) {
|
||||
return 0;
|
||||
}
|
||||
@ -70,7 +69,6 @@ size_t hex2bin(const char *hex, size_t hexlen, u8_t *buf, size_t buflen)
|
||||
if (char2hex(hex[0], &dec) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buf[0] = dec;
|
||||
hex++;
|
||||
buf++;
|
||||
@ -81,13 +79,11 @@ size_t hex2bin(const char *hex, size_t hexlen, u8_t *buf, size_t buflen)
|
||||
if (char2hex(hex[2 * i], &dec) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buf[i] = dec << 4;
|
||||
|
||||
if (char2hex(hex[2 * i + 1], &dec) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buf[i] += dec;
|
||||
}
|
||||
|
||||
|
@ -163,9 +163,9 @@ extern atomic_val_t atomic_get(const atomic_t *target);
|
||||
static inline atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
|
||||
{
|
||||
/* This builtin, as described by Intel, is not a traditional
|
||||
* test-and-set operation, but rather an atomic exchange operation. It
|
||||
* writes value into *ptr, and returns the previous contents of *ptr.
|
||||
*/
|
||||
* test-and-set operation, but rather an atomic exchange operation. It
|
||||
* writes value into *ptr, and returns the previous contents of *ptr.
|
||||
*/
|
||||
return __atomic_exchange_n(target, value, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
#else
|
||||
|
@ -11,7 +11,7 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*
|
||||
* @(#)errno.h 7.1 (Berkeley) 6/4/86
|
||||
* @(#)errno.h 7.1 (Berkeley) 6/4/86
|
||||
*/
|
||||
|
||||
#ifndef __INCerrnoh
|
||||
@ -28,15 +28,15 @@ extern int *__errno(void);
|
||||
* POSIX Error codes
|
||||
*/
|
||||
|
||||
#define EPERM 1 /* Not owner */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such context */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define E2BIG 7 /* Arg list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define EPERM 1 /* Not owner */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such context */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define E2BIG 7 /* Arg list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define ECHILD 10 /* No children */
|
||||
#define EAGAIN 11 /* No more contexts */
|
||||
#define ENOMEM 12 /* Not enough core */
|
||||
@ -104,8 +104,8 @@ extern int *__errno(void);
|
||||
#define EHOSTDOWN 67 /* Host is down */
|
||||
|
||||
/* non-blocking and interrupt i/o */
|
||||
#define EINPROGRESS 68 /* Operation now in progress */
|
||||
#define EALREADY 69 /* Operation already in progress */
|
||||
#define EINPROGRESS 68 /* Operation now in progress */
|
||||
#define EALREADY 69 /* Operation already in progress */
|
||||
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
||||
|
||||
#define ENOSYS 71 /* Function not implemented */
|
||||
|
@ -43,7 +43,7 @@
|
||||
* This type of situation can be resolved using the __ASSERT_EVAL() macro.
|
||||
*
|
||||
* __ASSERT_EVAL ((void) foo(),
|
||||
* int x = foo(),
|
||||
* int x = foo(),
|
||||
* x != 0,
|
||||
* "foo() returned zero!");
|
||||
*
|
||||
|
@ -112,8 +112,8 @@
|
||||
#define sys_be64_to_cpu(val) __bswap_64(val)
|
||||
#define sys_cpu_to_be64(val) __bswap_64(val)
|
||||
/********************************************************************************
|
||||
** Macros to get and put bytes to a stream (Little Endian format).
|
||||
*/
|
||||
** Macros to get and put bytes to a stream (Little Endian format).
|
||||
*/
|
||||
#define UINT32_TO_STREAM(p, u32) \
|
||||
{ \
|
||||
*(p)++ = (u8_t)(u32); \
|
||||
@ -151,8 +151,8 @@
|
||||
#define sys_be64_to_cpu(val) (val)
|
||||
#define sys_cpu_to_be64(val) (val)
|
||||
/********************************************************************************
|
||||
** Macros to get and put bytes to a stream (Big Endian format)
|
||||
*/
|
||||
** Macros to get and put bytes to a stream (Big Endian format)
|
||||
*/
|
||||
#define UINT32_TO_STREAM(p, u32) \
|
||||
{ \
|
||||
*(p)++ = (u8_t)((u32) >> 24); \
|
||||
|
@ -450,7 +450,6 @@ static inline void sys_dlist_insert_at(sys_dlist_t *list, sys_dnode_t *node,
|
||||
while (pos && !cond(pos, data)) {
|
||||
pos = sys_dlist_peek_next(list, pos);
|
||||
}
|
||||
|
||||
sys_dlist_insert_before(list, pos, node);
|
||||
}
|
||||
}
|
||||
|
@ -381,7 +381,6 @@ static inline sys_snode_t *sys_slist_get_not_empty(sys_slist_t *list)
|
||||
sys_snode_t *node = list->head;
|
||||
|
||||
list->head = node->next;
|
||||
|
||||
if (list->tail == node) {
|
||||
list->tail = list->head;
|
||||
}
|
||||
|
@ -22,19 +22,18 @@ static inline size_t stack_unused_space_get(const char *stack, size_t size)
|
||||
|
||||
#ifdef CONFIG_STACK_SENTINEL
|
||||
/* First 4 bytes of the stack buffer reserved for the sentinel
|
||||
* value, it won't be 0xAAAAAAAA for thread stacks.
|
||||
*/
|
||||
* value, it won't be 0xAAAAAAAA for thread stacks.
|
||||
*/
|
||||
stack += 4;
|
||||
#endif
|
||||
|
||||
/* TODO Currently all supported platforms have stack growth down and
|
||||
* there is no Kconfig option to configure it so this always build
|
||||
* "else" branch. When support for platform with stack direction up
|
||||
* (or configurable direction) is added this check should be confirmed
|
||||
* that correct Kconfig option is used.
|
||||
*/
|
||||
* there is no Kconfig option to configure it so this always build
|
||||
* "else" branch. When support for platform with stack direction up
|
||||
* (or configurable direction) is added this check should be confirmed
|
||||
* that correct Kconfig option is used.
|
||||
*/
|
||||
#if defined(STACK_GROWS_UP)
|
||||
|
||||
for (i = size - 1; i >= 0; i--) {
|
||||
if ((unsigned char)stack[i] == 0xaa) {
|
||||
unused++;
|
||||
@ -42,9 +41,7 @@ static inline size_t stack_unused_space_get(const char *stack, size_t size)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
if ((unsigned char)stack[i] == 0xaa) {
|
||||
unused++;
|
||||
@ -52,7 +49,6 @@ static inline size_t stack_unused_space_get(const char *stack, size_t size)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return unused;
|
||||
}
|
||||
|
@ -268,9 +268,8 @@ static inline s64_t arithmetic_shift_right(s64_t value, u8_t shift)
|
||||
|
||||
#define UTIL_EAT(...)
|
||||
#define UTIL_EXPAND(...) __VA_ARGS__
|
||||
#define UTIL_WHEN(c) \
|
||||
UTIL_IF(c) \
|
||||
(UTIL_EXPAND, UTIL_EAT)
|
||||
#define UTIL_WHEN(c) UTIL_IF(c) \
|
||||
(UTIL_EXPAND, UTIL_EAT)
|
||||
|
||||
#define UTIL_REPEAT(count, macro, ...) \
|
||||
UTIL_WHEN(count) \
|
||||
|
@ -90,8 +90,8 @@ struct net_buf_simple {
|
||||
u16_t size;
|
||||
|
||||
/** Start of the data storage. Not to be accessed directly
|
||||
* (the data pointer should be used instead).
|
||||
*/
|
||||
* (the data pointer should be used instead).
|
||||
*/
|
||||
u8_t *__buf;
|
||||
};
|
||||
|
||||
@ -566,12 +566,11 @@ struct net_buf {
|
||||
u8_t pool_id;
|
||||
|
||||
/* Union for convenience access to the net_buf_simple members, also
|
||||
* preserving the old API.
|
||||
*/
|
||||
* preserving the old API.
|
||||
*/
|
||||
union {
|
||||
/* The ABI of this struct must match net_buf_simple */
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
/** Pointer to the start of data in the buffer. */
|
||||
u8_t *data;
|
||||
|
||||
@ -582,9 +581,9 @@ struct net_buf {
|
||||
u16_t size;
|
||||
|
||||
/** Start of the data storage. Not to be accessed
|
||||
* directly (the data pointer should be used
|
||||
* instead).
|
||||
*/
|
||||
* directly (the data pointer should be used
|
||||
* instead).
|
||||
*/
|
||||
u8_t *__buf;
|
||||
};
|
||||
|
||||
@ -614,7 +613,7 @@ struct net_buf_pool {
|
||||
/** LIFO to place the buffer into when free */
|
||||
struct k_lifo free;
|
||||
|
||||
/** Number of buffers in pool */
|
||||
/** Number of buffers in pool */
|
||||
#if defined(BFLB_DYNAMIC_ALLOC_MEM)
|
||||
u16_t buf_count;
|
||||
#else
|
||||
@ -1503,7 +1502,6 @@ static inline struct net_buf *net_buf_skip(struct net_buf *buf, u16_t len)
|
||||
{
|
||||
while (buf && len--) {
|
||||
net_buf_pull_u8(buf);
|
||||
|
||||
if (!buf->len) {
|
||||
buf = net_buf_frag_del(NULL, buf);
|
||||
}
|
||||
|
@ -92,19 +92,19 @@
|
||||
#if !defined(_ASMLANGUAGE)
|
||||
#ifdef CONFIG_COVERAGE
|
||||
/*
|
||||
* The always_inline attribute forces a function to be inlined,
|
||||
* even ignoring -fno-inline. So for code coverage, do not
|
||||
* force inlining of these functions to keep their bodies around
|
||||
* so their number of executions can be counted.
|
||||
*
|
||||
* Note that "inline" is kept here for kobject_hash.c and
|
||||
* priv_stacks_hash.c. These are built without compiler flags
|
||||
* used for coverage. ALWAYS_INLINE cannot be empty as compiler
|
||||
* would complain about unused functions. Attaching unused
|
||||
* attribute would result in their text sections ballon more than
|
||||
* 10 times in size, as those functions are kept in text section.
|
||||
* So just keep "inline" here.
|
||||
*/
|
||||
* The always_inline attribute forces a function to be inlined,
|
||||
* even ignoring -fno-inline. So for code coverage, do not
|
||||
* force inlining of these functions to keep their bodies around
|
||||
* so their number of executions can be counted.
|
||||
*
|
||||
* Note that "inline" is kept here for kobject_hash.c and
|
||||
* priv_stacks_hash.c. These are built without compiler flags
|
||||
* used for coverage. ALWAYS_INLINE cannot be empty as compiler
|
||||
* would complain about unused functions. Attaching unused
|
||||
* attribute would result in their text sections ballon more than
|
||||
* 10 times in size, as those functions are kept in text section.
|
||||
* So just keep "inline" here.
|
||||
*/
|
||||
#define ALWAYS_INLINE inline
|
||||
#else
|
||||
#define ALWAYS_INLINE inline __attribute__((always_inline))
|
||||
@ -186,8 +186,8 @@
|
||||
for (struct struct_type *iterator = \
|
||||
_CONCAT(_##struct_type, _list_start); \
|
||||
({ __ASSERT(iterator <= _CONCAT(_##struct_type, _list_end), \
|
||||
"unexpected list end location"); \
|
||||
iterator < _CONCAT(_##struct_type, _list_end); }); \
|
||||
"unexpected list end location"); \
|
||||
iterator < _CONCAT(_##struct_type, _list_end); }); \
|
||||
iterator++)
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_COMMON_H_ */
|
||||
|
@ -52,9 +52,9 @@
|
||||
#define BUILD_ASSERT(EXPR) static_assert(EXPR, "")
|
||||
#define BUILD_ASSERT_MSG(EXPR, MSG) static_assert(EXPR, MSG)
|
||||
/*
|
||||
* GCC 4.6 and higher have the C11 _Static_assert built in, and its
|
||||
* output is easier to understand than the common BUILD_ASSERT macros.
|
||||
*/
|
||||
* GCC 4.6 and higher have the C11 _Static_assert built in, and its
|
||||
* output is easier to understand than the common BUILD_ASSERT macros.
|
||||
*/
|
||||
#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \
|
||||
(__STDC_VERSION__) >= 201100
|
||||
#define BUILD_ASSERT(EXPR) _Static_assert(EXPR, "")
|
||||
@ -157,7 +157,7 @@
|
||||
#define __ramfunc
|
||||
#elif defined(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT)
|
||||
#define __ramfunc __attribute__((noinline)) \
|
||||
__attribute__((long_call, section(".ramfunc")))
|
||||
__attribute__((long_call, section(".ramfunc")))
|
||||
#endif /* !CONFIG_XIP */
|
||||
|
||||
#ifndef __packed
|
||||
@ -266,9 +266,9 @@
|
||||
.type sym, % object
|
||||
#elif defined(CONFIG_ARC)
|
||||
/*
|
||||
* Need to use assembly macros because ';' is interpreted as the start of
|
||||
* a single line comment in the ARC assembler.
|
||||
*/
|
||||
* Need to use assembly macros because ';' is interpreted as the start of
|
||||
* a single line comment in the ARC assembler.
|
||||
*/
|
||||
|
||||
.macro glbl_text symbol
|
||||
.globl \symbol
|
||||
@ -305,7 +305,7 @@
|
||||
* These macros specify the section in which a given function or variable
|
||||
* resides.
|
||||
*
|
||||
* - SECTION_FUNC allows only one function to reside in a sub-section
|
||||
* - SECTION_FUNC allows only one function to reside in a sub-section
|
||||
* - SECTION_SUBSEC_FUNC allows multiple functions to reside in a sub-section
|
||||
* This ensures that garbage collection only discards the section
|
||||
* if all functions in the sub-section are not referenced.
|
||||
@ -321,20 +321,20 @@
|
||||
*/
|
||||
|
||||
.macro section_var section, symbol.section.\section\().\symbol
|
||||
\symbol :.endm
|
||||
\symbol :.endm
|
||||
|
||||
.macro section_func section,
|
||||
.macro section_func section,
|
||||
symbol
|
||||
.section.\section\()
|
||||
.\symbol,
|
||||
"ax" FUNC_CODE()
|
||||
PERFOPT_ALIGN
|
||||
\symbol : FUNC_INSTR(\symbol)
|
||||
.endm
|
||||
\symbol : FUNC_INSTR(\symbol)
|
||||
.endm
|
||||
|
||||
.macro section_subsec_func section,
|
||||
.macro section_subsec_func section,
|
||||
subsection, symbol.section.\section\().\subsection, "ax" PERFOPT_ALIGN
|
||||
\symbol :.endm
|
||||
\symbol :.endm
|
||||
|
||||
#define SECTION_VAR(sect, sym) section_var sect, sym
|
||||
#define SECTION_FUNC(sect, sym) section_func sect, sym
|
||||
@ -446,9 +446,9 @@
|
||||
* Macro ensures that expressions are evaluated only once.
|
||||
*
|
||||
* @note Macro has limited usage compared to the standard macro as it cannot be
|
||||
* used:
|
||||
* - to generate constant integer, e.g. __aligned(Z_MAX(4,5))
|
||||
* - static variable, e.g. array like static u8_t array[Z_MAX(...)];
|
||||
* used:
|
||||
* - to generate constant integer, e.g. __aligned(Z_MAX(4,5))
|
||||
* - static variable, e.g. array like static u8_t array[Z_MAX(...)];
|
||||
*/
|
||||
#define Z_MAX(a, b) ({ \
|
||||
/* random suffix to avoid naming conflict */ \
|
||||
|
@ -29,10 +29,10 @@
|
||||
#include <xtensa/config/core.h>
|
||||
|
||||
/*
|
||||
* XCC does not define the following macros with the expected names, but the
|
||||
* HAL defines similar ones. Thus we include it and define the missing macros
|
||||
* ourselves.
|
||||
*/
|
||||
* XCC does not define the following macros with the expected names, but the
|
||||
* HAL defines similar ones. Thus we include it and define the missing macros
|
||||
* ourselves.
|
||||
*/
|
||||
#if XCHAL_MEMORY_ORDER == XTHAL_BIGENDIAN
|
||||
#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
|
||||
#elif XCHAL_MEMORY_ORDER == XTHAL_LITTLEENDIAN
|
||||
|
@ -8,8 +8,7 @@ struct k_work_q {
|
||||
struct k_fifo fifo;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
bl_timer_t timer;
|
||||
struct k_delayed_work *delay_work;
|
||||
} timer_rec_d;
|
||||
|
@ -50,28 +50,21 @@ static inline int is_condition_met(struct k_poll_event *event, u32_t *state)
|
||||
*state = K_POLL_STATE_SEM_AVAILABLE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case K_POLL_TYPE_DATA_AVAILABLE:
|
||||
if (!k_queue_is_empty(event->queue)) {
|
||||
*state = K_POLL_STATE_FIFO_DATA_AVAILABLE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case K_POLL_TYPE_SIGNAL:
|
||||
if (event->signal->signaled) {
|
||||
*state = K_POLL_STATE_SIGNALED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case K_POLL_TYPE_IGNORE:
|
||||
return 0;
|
||||
|
||||
default:
|
||||
__ASSERT(0, "invalid event type (0x%x)\n", event->type);
|
||||
break;
|
||||
@ -95,21 +88,17 @@ static inline int register_event(struct k_poll_event *event,
|
||||
__ASSERT(event->sem, "invalid semaphore\n");
|
||||
add_event(&event->sem->poll_events, event, poller);
|
||||
break;
|
||||
|
||||
case K_POLL_TYPE_DATA_AVAILABLE:
|
||||
__ASSERT(event->queue, "invalid queue\n");
|
||||
add_event(&event->queue->poll_events, event, poller);
|
||||
break;
|
||||
|
||||
case K_POLL_TYPE_SIGNAL:
|
||||
__ASSERT(event->signal, "invalid poll signal\n");
|
||||
add_event(&event->signal->poll_events, event, poller);
|
||||
break;
|
||||
|
||||
case K_POLL_TYPE_IGNORE:
|
||||
/* nothing to do */
|
||||
break;
|
||||
|
||||
default:
|
||||
__ASSERT(0, "invalid event type\n");
|
||||
break;
|
||||
@ -130,21 +119,17 @@ static inline void clear_event_registration(struct k_poll_event *event)
|
||||
__ASSERT(event->sem, "invalid semaphore\n");
|
||||
sys_dlist_remove(&event->_node);
|
||||
break;
|
||||
|
||||
case K_POLL_TYPE_DATA_AVAILABLE:
|
||||
__ASSERT(event->queue, "invalid queue\n");
|
||||
sys_dlist_remove(&event->_node);
|
||||
break;
|
||||
|
||||
case K_POLL_TYPE_SIGNAL:
|
||||
__ASSERT(event->signal, "invalid poll signal\n");
|
||||
sys_dlist_remove(&event->_node);
|
||||
break;
|
||||
|
||||
case K_POLL_TYPE_IGNORE:
|
||||
/* nothing to do */
|
||||
break;
|
||||
|
||||
default:
|
||||
__ASSERT(0, "invalid event type\n");
|
||||
break;
|
||||
@ -179,23 +164,19 @@ static bool polling_events(struct k_poll_event *events, int num_events,
|
||||
for (int ii = 0; ii < num_events; ii++) {
|
||||
u32_t state;
|
||||
key = irq_lock();
|
||||
|
||||
if (is_condition_met(&events[ii], &state)) {
|
||||
set_event_ready(&events[ii], state);
|
||||
polling = false;
|
||||
} else if (timeout != K_NO_WAIT && polling) {
|
||||
rc = register_event(&events[ii], NULL);
|
||||
|
||||
if (rc == 0) {
|
||||
++(*last_registered);
|
||||
} else {
|
||||
__ASSERT(0, "unexpected return code\n");
|
||||
}
|
||||
}
|
||||
|
||||
irq_unlock(key);
|
||||
}
|
||||
|
||||
return polling;
|
||||
}
|
||||
|
||||
@ -245,7 +226,6 @@ int k_poll_signal_raise(struct k_poll_signal *signal, int result)
|
||||
signal->signaled = 1;
|
||||
|
||||
poll_event = (struct k_poll_event *)sys_dlist_get(&signal->poll_events);
|
||||
|
||||
if (!poll_event) {
|
||||
irq_unlock(key);
|
||||
return 0;
|
||||
|
@ -43,17 +43,16 @@ static int ah(const u8_t irk[16], const u8_t r[3], u8_t out[3])
|
||||
(void)memset(res + 3, 0, 13);
|
||||
|
||||
err = bt_encrypt_le(irk, res, res);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* The output of the random address function ah is:
|
||||
* ah(h, r) = e(k, r') mod 2^24
|
||||
* The output of the security function e is then truncated to 24 bits
|
||||
* by taking the least significant 24 bits of the output of e as the
|
||||
* result of ah.
|
||||
*/
|
||||
* ah(h, r) = e(k, r') mod 2^24
|
||||
* The output of the security function e is then truncated to 24 bits
|
||||
* by taking the least significant 24 bits of the output of e as the
|
||||
* result of ah.
|
||||
*/
|
||||
memcpy(out, res, 3);
|
||||
|
||||
return 0;
|
||||
@ -69,7 +68,6 @@ bool bt_rpa_irk_matches(const u8_t irk[16], const bt_addr_t *addr)
|
||||
BT_DBG("IRK %s bdaddr %s", bt_hex(irk, 16), bt_addr_str(addr));
|
||||
|
||||
err = ah(irk, addr->val + 3, hash);
|
||||
|
||||
if (err) {
|
||||
return false;
|
||||
}
|
||||
@ -84,7 +82,6 @@ int bt_rpa_create(const u8_t irk[16], bt_addr_t *rpa)
|
||||
int err;
|
||||
|
||||
err = bt_rand(rpa->val + 3, 3);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -92,7 +89,6 @@ int bt_rpa_create(const u8_t irk[16], bt_addr_t *rpa)
|
||||
BT_ADDR_SET_RPA(rpa);
|
||||
|
||||
err = ah(irk, rpa->val + 3, rpa->val);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
@ -16,32 +16,32 @@ The following is the license information for this code:
|
||||
|
||||
================================================================================
|
||||
|
||||
Copyright (c) 2017, Intel Corporation. All rights reserved.
|
||||
Copyright (c) 2017, Intel Corporation. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice, this
|
||||
- Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of the Intel Corporation nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
- Neither the name of the Intel Corporation nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
================================================================================
|
||||
|
@ -55,8 +55,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define Nb (4) /* number of columns (32-bit words) comprising the state */
|
||||
#define Nk (4) /* number of 32-bit words comprising the key */
|
||||
#define Nb (4) /* number of columns (32-bit words) comprising the state */
|
||||
#define Nk (4) /* number of 32-bit words comprising the key */
|
||||
#define Nr (10) /* number of rounds */
|
||||
#define TC_AES_BLOCK_SIZE (Nb * Nk)
|
||||
#define TC_AES_KEY_SIZE (Nb * Nk)
|
||||
|
@ -67,8 +67,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
/* updated each time another BLOCKLEN_BYTES bytes are produced */
|
||||
uint8_t V[TC_AES_BLOCK_SIZE];
|
||||
|
||||
|
@ -513,11 +513,11 @@ int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve);
|
||||
int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve);
|
||||
|
||||
/*
|
||||
* @brief Converts an integer in uECC native format to big-endian bytes.
|
||||
* @param bytes OUT -- bytes representation
|
||||
* @param num_bytes IN -- number of bytes
|
||||
* @param native IN -- uECC native representation
|
||||
*/
|
||||
* @brief Converts an integer in uECC native format to big-endian bytes.
|
||||
* @param bytes OUT -- bytes representation
|
||||
* @param num_bytes IN -- number of bytes
|
||||
* @param native IN -- uECC native representation
|
||||
*/
|
||||
void uECC_vli_nativeToBytes(uint8_t *bytes, int num_bytes,
|
||||
const unsigned int *native);
|
||||
|
||||
|
@ -118,7 +118,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
/**
|
||||
* @brief Verify an ECDSA signature.
|
||||
* @return returns TC_SUCCESS (1) if the signature is valid
|
||||
* returns TC_FAIL (0) if the signature is invalid.
|
||||
* returns TC_FAIL (0) if the signature is invalid.
|
||||
*
|
||||
* @param p_public_key IN -- The signer's public key.
|
||||
* @param p_message_hash IN -- The hash of the signed data.
|
||||
|
@ -120,7 +120,7 @@ int tc_hmac_prng_init(TCHmacPrng_t prng,
|
||||
* @brief HMAC-PRNG reseed procedure
|
||||
* Mixes seed into prng, enables tc_hmac_prng_generate
|
||||
* @return returns TC_CRYPTO_SUCCESS (1)
|
||||
* returns TC_CRYPTO_FAIL (0) if:
|
||||
* returns TC_CRYPTO_FAIL (0) if:
|
||||
* prng == NULL,
|
||||
* seed == NULL,
|
||||
* seedlen < MIN_SLEN,
|
||||
|
@ -89,11 +89,9 @@ int tc_aes128_set_encrypt_key(TCAesKeySched_t s, const uint8_t *k)
|
||||
|
||||
for (; i < (Nb * (Nr + 1)); ++i) {
|
||||
t = s->words[i - 1];
|
||||
|
||||
if ((i % Nk) == 0) {
|
||||
t = subword(rotword(t)) ^ rconst[i / Nk];
|
||||
}
|
||||
|
||||
s->words[i] = s->words[i - Nk] ^ t;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,6 @@ int tc_cbc_mode_encrypt(uint8_t *out, unsigned int outlen, const uint8_t *in,
|
||||
|
||||
for (n = m = 0; n < inlen; ++n) {
|
||||
buffer[m++] ^= *in++;
|
||||
|
||||
if (m == TC_AES_BLOCK_SIZE) {
|
||||
(void)tc_aes_encrypt(buffer, buffer, sched);
|
||||
(void)_copy(out, TC_AES_BLOCK_SIZE,
|
||||
@ -95,19 +94,17 @@ int tc_cbc_mode_decrypt(uint8_t *out, unsigned int outlen, const uint8_t *in,
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that in == iv + ciphertext, i.e. the iv and the ciphertext are
|
||||
* contiguous. This allows for a very efficient decryption algorithm
|
||||
* that would not otherwise be possible.
|
||||
*/
|
||||
* Note that in == iv + ciphertext, i.e. the iv and the ciphertext are
|
||||
* contiguous. This allows for a very efficient decryption algorithm
|
||||
* that would not otherwise be possible.
|
||||
*/
|
||||
p = iv;
|
||||
|
||||
for (n = m = 0; n < outlen; ++n) {
|
||||
if ((n % TC_AES_BLOCK_SIZE) == 0) {
|
||||
(void)tc_aes_decrypt(buffer, in, sched);
|
||||
in += TC_AES_BLOCK_SIZE;
|
||||
m = 0;
|
||||
}
|
||||
|
||||
*out++ = buffer[m++] ^ *p++;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,6 @@ static void ccm_cbc_mac(uint8_t *T, const uint8_t *data, unsigned int dlen,
|
||||
|
||||
while (i < dlen) {
|
||||
T[i++ % (Nb * Nk)] ^= *data++;
|
||||
|
||||
if (((i % (Nb * Nk)) == 0) || dlen == i) {
|
||||
(void)tc_aes_encrypt(T, T, sched);
|
||||
}
|
||||
@ -114,18 +113,15 @@ static int ccm_ctr_mode(uint8_t *out, unsigned int outlen, const uint8_t *in,
|
||||
|
||||
/* select the last 2 bytes of the nonce to be incremented */
|
||||
block_num = (uint16_t)((nonce[14] << 8) | (nonce[15]));
|
||||
|
||||
for (i = 0; i < inlen; ++i) {
|
||||
if ((i % (TC_AES_BLOCK_SIZE)) == 0) {
|
||||
block_num++;
|
||||
nonce[14] = (uint8_t)(block_num >> 8);
|
||||
nonce[15] = (uint8_t)(block_num);
|
||||
|
||||
if (!tc_aes_encrypt(buffer, nonce, sched)) {
|
||||
return TC_CRYPTO_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/* update the output */
|
||||
*out++ = buffer[i % (TC_AES_BLOCK_SIZE)] ^ *in++;
|
||||
}
|
||||
@ -149,8 +145,7 @@ int tc_ccm_generation_encryption(uint8_t *out, unsigned int olen,
|
||||
((alen > 0) && (associated_data == (uint8_t *)0)) ||
|
||||
(alen >= TC_CCM_AAD_MAX_BYTES) || /* associated data size unsupported */
|
||||
(plen >= TC_CCM_PAYLOAD_MAX_BYTES) || /* payload size unsupported */
|
||||
(olen < (plen + c->mlen))) /* invalid output buffer size */
|
||||
{
|
||||
(olen < (plen + c->mlen))) { /* invalid output buffer size */
|
||||
return TC_CRYPTO_FAIL;
|
||||
}
|
||||
|
||||
@ -162,21 +157,17 @@ int tc_ccm_generation_encryption(uint8_t *out, unsigned int olen,
|
||||
|
||||
/* formatting the sequence b for authentication: */
|
||||
b[0] = ((alen > 0) ? 0x40 : 0) | (((c->mlen - 2) / 2 << 3)) | (1);
|
||||
|
||||
for (i = 1; i <= 13; ++i) {
|
||||
b[i] = c->nonce[i - 1];
|
||||
}
|
||||
|
||||
b[14] = (uint8_t)(plen >> 8);
|
||||
b[15] = (uint8_t)(plen);
|
||||
|
||||
/* computing the authentication tag using cbc-mac: */
|
||||
(void)tc_aes_encrypt(tag, b, c->sched);
|
||||
|
||||
if (alen > 0) {
|
||||
ccm_cbc_mac(tag, associated_data, alen, 1, c->sched);
|
||||
}
|
||||
|
||||
if (plen > 0) {
|
||||
ccm_cbc_mac(tag, payload, plen, 0, c->sched);
|
||||
}
|
||||
@ -195,7 +186,6 @@ int tc_ccm_generation_encryption(uint8_t *out, unsigned int olen,
|
||||
/* encrypting b and adding the tag to the output: */
|
||||
(void)tc_aes_encrypt(b, b, c->sched);
|
||||
out += plen;
|
||||
|
||||
for (i = 0; i < c->mlen; ++i) {
|
||||
*out++ = tag[i] ^ b[i];
|
||||
}
|
||||
@ -215,8 +205,7 @@ int tc_ccm_decryption_verification(uint8_t *out, unsigned int olen,
|
||||
((alen > 0) && (associated_data == (uint8_t *)0)) ||
|
||||
(alen >= TC_CCM_AAD_MAX_BYTES) || /* associated data size unsupported */
|
||||
(plen >= TC_CCM_PAYLOAD_MAX_BYTES) || /* payload size unsupported */
|
||||
(olen < plen - c->mlen)) /* invalid output buffer size */
|
||||
{
|
||||
(olen < plen - c->mlen)) { /* invalid output buffer size */
|
||||
return TC_CRYPTO_FAIL;
|
||||
}
|
||||
|
||||
@ -228,11 +217,9 @@ int tc_ccm_decryption_verification(uint8_t *out, unsigned int olen,
|
||||
|
||||
/* formatting the sequence b for decryption: */
|
||||
b[0] = 1; /* q - 1 = 2 - 1 = 1 */
|
||||
|
||||
for (i = 1; i < 14; ++i) {
|
||||
b[i] = c->nonce[i - 1];
|
||||
}
|
||||
|
||||
b[14] = b[15] = TC_ZERO_BYTE; /* initial counter value is 0 */
|
||||
|
||||
/* decrypting payload using ctr mode: */
|
||||
@ -242,7 +229,6 @@ int tc_ccm_decryption_verification(uint8_t *out, unsigned int olen,
|
||||
|
||||
/* encrypting b and restoring the tag from input: */
|
||||
(void)tc_aes_encrypt(b, b, c->sched);
|
||||
|
||||
for (i = 0; i < c->mlen; ++i) {
|
||||
tag[i] = *(payload + plen - c->mlen + i) ^ b[i];
|
||||
}
|
||||
@ -251,21 +237,17 @@ int tc_ccm_decryption_verification(uint8_t *out, unsigned int olen,
|
||||
|
||||
/* formatting the sequence b for authentication: */
|
||||
b[0] = ((alen > 0) ? 0x40 : 0) | (((c->mlen - 2) / 2 << 3)) | (1);
|
||||
|
||||
for (i = 1; i < 14; ++i) {
|
||||
b[i] = c->nonce[i - 1];
|
||||
}
|
||||
|
||||
b[14] = (uint8_t)((plen - c->mlen) >> 8);
|
||||
b[15] = (uint8_t)(plen - c->mlen);
|
||||
|
||||
/* computing the authentication tag using cbc-mac: */
|
||||
(void)tc_aes_encrypt(b, b, c->sched);
|
||||
|
||||
if (alen > 0) {
|
||||
ccm_cbc_mac(b, associated_data, alen, 1, c->sched);
|
||||
}
|
||||
|
||||
if (plen > 0) {
|
||||
ccm_cbc_mac(b, out, plen - c->mlen, 0, c->sched);
|
||||
}
|
||||
|
@ -84,14 +84,11 @@ void gf_double(uint8_t *out, uint8_t *in)
|
||||
uint8_t carry = (in[0] >> 7) ? gf_wrap : 0;
|
||||
|
||||
out += (TC_AES_BLOCK_SIZE - 1);
|
||||
|
||||
for (;;) {
|
||||
*out-- = (*x << 1) ^ carry;
|
||||
|
||||
if (x == in) {
|
||||
break;
|
||||
}
|
||||
|
||||
carry = *x-- >> 7;
|
||||
}
|
||||
}
|
||||
@ -163,11 +160,9 @@ int tc_cmac_update(TCCmacState_t s, const uint8_t *data, size_t data_length)
|
||||
if (s == (TCCmacState_t)0) {
|
||||
return TC_CRYPTO_FAIL;
|
||||
}
|
||||
|
||||
if (data_length == 0) {
|
||||
return TC_CRYPTO_SUCCESS;
|
||||
}
|
||||
|
||||
if (data == (const uint8_t *)0) {
|
||||
return TC_CRYPTO_FAIL;
|
||||
}
|
||||
@ -188,7 +183,6 @@ int tc_cmac_update(TCCmacState_t s, const uint8_t *data, size_t data_length)
|
||||
s->leftover_offset += data_length;
|
||||
return TC_CRYPTO_SUCCESS;
|
||||
}
|
||||
|
||||
/* leftover block is now full; encrypt it first */
|
||||
_copy(&s->leftover[s->leftover_offset],
|
||||
remaining_space,
|
||||
@ -201,7 +195,6 @@ int tc_cmac_update(TCCmacState_t s, const uint8_t *data, size_t data_length)
|
||||
for (i = 0; i < TC_AES_BLOCK_SIZE; ++i) {
|
||||
s->iv[i] ^= s->leftover[i];
|
||||
}
|
||||
|
||||
tc_aes_encrypt(s->iv, s->iv, s->sched);
|
||||
}
|
||||
|
||||
@ -210,7 +203,6 @@ int tc_cmac_update(TCCmacState_t s, const uint8_t *data, size_t data_length)
|
||||
for (i = 0; i < TC_AES_BLOCK_SIZE; ++i) {
|
||||
s->iv[i] ^= data[i];
|
||||
}
|
||||
|
||||
tc_aes_encrypt(s->iv, s->iv, s->sched);
|
||||
data += TC_AES_BLOCK_SIZE;
|
||||
data_length -= TC_AES_BLOCK_SIZE;
|
||||
@ -247,7 +239,6 @@ int tc_cmac_final(uint8_t *tag, TCCmacState_t s)
|
||||
s->leftover[s->leftover_offset] = TC_CMAC_PADDING;
|
||||
k = (uint8_t *)s->K2;
|
||||
}
|
||||
|
||||
for (i = 0; i < TC_AES_BLOCK_SIZE; ++i) {
|
||||
s->iv[i] ^= s->leftover[i] ^ k[i];
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ int tc_ctr_mode(uint8_t *out, unsigned int outlen, const uint8_t *in,
|
||||
/* select the last 4 bytes of the nonce to be incremented */
|
||||
block_num = (nonce[12] << 24) | (nonce[13] << 16) |
|
||||
(nonce[14] << 8) | (nonce[15]);
|
||||
|
||||
for (i = 0; i < inlen; ++i) {
|
||||
if ((i % (TC_AES_BLOCK_SIZE)) == 0) {
|
||||
/* encrypt data using the current nonce */
|
||||
@ -73,7 +72,6 @@ int tc_ctr_mode(uint8_t *out, unsigned int outlen, const uint8_t *in,
|
||||
return TC_CRYPTO_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/* update the output */
|
||||
*out++ = buffer[i % (TC_AES_BLOCK_SIZE)] ^ *in++;
|
||||
}
|
||||
|
@ -53,7 +53,6 @@
|
||||
static void arrInc(uint8_t arr[], unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (0 != arr) {
|
||||
for (i = len; i > 0U; i--) {
|
||||
if (++arr[i - 1] != 0U) {
|
||||
@ -91,7 +90,6 @@ static void tc_ctr_prng_update(TCCtrPrng_t *const ctx, uint8_t const *const prov
|
||||
if (blocklen > TC_AES_BLOCK_SIZE) {
|
||||
blocklen = TC_AES_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
(void)tc_aes_encrypt(output_block, ctx->V, &ctx->key);
|
||||
|
||||
/* 10.2.1.2 step 2.3/step 3 */
|
||||
@ -103,7 +101,6 @@ static void tc_ctr_prng_update(TCCtrPrng_t *const ctx, uint8_t const *const prov
|
||||
/* 10.2.1.2 step 4 */
|
||||
if (0 != providedData) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0U; i < sizeof temp; i++) {
|
||||
temp[i] ^= providedData[i];
|
||||
}
|
||||
@ -132,7 +129,6 @@ int tc_ctr_prng_init(TCCtrPrng_t *const ctx,
|
||||
if (0 != personalization) {
|
||||
/* 10.2.1.3.1 step 1 */
|
||||
unsigned int len = pLen;
|
||||
|
||||
if (len > sizeof personalization_buf) {
|
||||
len = sizeof personalization_buf;
|
||||
}
|
||||
@ -144,7 +140,6 @@ int tc_ctr_prng_init(TCCtrPrng_t *const ctx,
|
||||
if ((0 != ctx) && (0 != entropy) && (entropyLen >= sizeof seed_material)) {
|
||||
/* 10.2.1.3.1 step 3 */
|
||||
memcpy(seed_material, entropy, sizeof seed_material);
|
||||
|
||||
for (i = 0U; i < sizeof seed_material; i++) {
|
||||
seed_material[i] ^= personalization_buf[i];
|
||||
}
|
||||
@ -163,7 +158,6 @@ int tc_ctr_prng_init(TCCtrPrng_t *const ctx,
|
||||
|
||||
result = TC_CRYPTO_SUCCESS;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -181,7 +175,6 @@ int tc_ctr_prng_reseed(TCCtrPrng_t *const ctx,
|
||||
if (0 != additional_input) {
|
||||
/* 10.2.1.4.1 step 1 */
|
||||
unsigned int len = additionallen;
|
||||
|
||||
if (len > sizeof additional_input_buf) {
|
||||
len = sizeof additional_input_buf;
|
||||
}
|
||||
@ -191,11 +184,9 @@ int tc_ctr_prng_reseed(TCCtrPrng_t *const ctx,
|
||||
}
|
||||
|
||||
unsigned int seedlen = (unsigned int)TC_AES_KEY_SIZE + (unsigned int)TC_AES_BLOCK_SIZE;
|
||||
|
||||
if ((0 != ctx) && (entropyLen >= seedlen)) {
|
||||
/* 10.2.1.4.1 step 3 */
|
||||
memcpy(seed_material, entropy, sizeof seed_material);
|
||||
|
||||
for (i = 0U; i < sizeof seed_material; i++) {
|
||||
seed_material[i] ^= additional_input_buf[i];
|
||||
}
|
||||
@ -208,7 +199,6 @@ int tc_ctr_prng_reseed(TCCtrPrng_t *const ctx,
|
||||
|
||||
result = TC_CRYPTO_SUCCESS;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -232,15 +222,12 @@ int tc_ctr_prng_generate(TCCtrPrng_t *const ctx,
|
||||
result = TC_CTR_PRNG_RESEED_REQ;
|
||||
} else {
|
||||
uint8_t additional_input_buf[TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE] = { 0U };
|
||||
|
||||
if (0 != additional_input) {
|
||||
/* 10.2.1.5.1 step 2 */
|
||||
unsigned int len = additionallen;
|
||||
|
||||
if (len > sizeof additional_input_buf) {
|
||||
len = sizeof additional_input_buf;
|
||||
}
|
||||
|
||||
memcpy(additional_input_buf, additional_input, len);
|
||||
tc_ctr_prng_update(ctx, additional_input_buf);
|
||||
}
|
||||
@ -249,7 +236,6 @@ int tc_ctr_prng_generate(TCCtrPrng_t *const ctx,
|
||||
|
||||
/* 10.2.1.5.1 step 4 */
|
||||
unsigned int len = 0U;
|
||||
|
||||
while (len < outlen) {
|
||||
unsigned int blocklen = outlen - len;
|
||||
uint8_t output_block[TC_AES_BLOCK_SIZE];
|
||||
@ -264,7 +250,6 @@ int tc_ctr_prng_generate(TCCtrPrng_t *const ctx,
|
||||
if (blocklen > TC_AES_BLOCK_SIZE) {
|
||||
blocklen = TC_AES_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
memcpy(&(out[len]), output_block, blocklen);
|
||||
|
||||
len += blocklen;
|
||||
|
@ -87,7 +87,6 @@ int uECC_curve_public_key_size(uECC_Curve curve)
|
||||
void uECC_vli_clear(uECC_word_t *vli, wordcount_t num_words)
|
||||
{
|
||||
wordcount_t i;
|
||||
|
||||
for (i = 0; i < num_words; ++i) {
|
||||
vli[i] = 0;
|
||||
}
|
||||
@ -97,11 +96,9 @@ uECC_word_t uECC_vli_isZero(const uECC_word_t *vli, wordcount_t num_words)
|
||||
{
|
||||
uECC_word_t bits = 0;
|
||||
wordcount_t i;
|
||||
|
||||
for (i = 0; i < num_words; ++i) {
|
||||
bits |= vli[i];
|
||||
}
|
||||
|
||||
return (bits == 0);
|
||||
}
|
||||
|
||||
@ -116,9 +113,8 @@ static wordcount_t vli_numDigits(const uECC_word_t *vli,
|
||||
const wordcount_t max_words)
|
||||
{
|
||||
wordcount_t i;
|
||||
|
||||
/* Search from the end until we find a non-zero digit. We do it in reverse
|
||||
* because we expect that most digits will be nonzero. */
|
||||
* because we expect that most digits will be nonzero. */
|
||||
for (i = max_words - 1; i >= 0 && vli[i] == 0; --i) {
|
||||
}
|
||||
|
||||
@ -132,13 +128,11 @@ bitcount_t uECC_vli_numBits(const uECC_word_t *vli,
|
||||
uECC_word_t digit;
|
||||
|
||||
wordcount_t num_digits = vli_numDigits(vli, max_words);
|
||||
|
||||
if (num_digits == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
digit = vli[num_digits - 1];
|
||||
|
||||
for (i = 0; digit; ++i) {
|
||||
digit >>= 1;
|
||||
}
|
||||
@ -169,7 +163,6 @@ cmpresult_t uECC_vli_cmp_unsafe(const uECC_word_t *left,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -182,7 +175,6 @@ uECC_word_t uECC_vli_equal(const uECC_word_t *left, const uECC_word_t *right,
|
||||
for (i = num_words - 1; i >= 0; --i) {
|
||||
diff |= (left[i] ^ right[i]);
|
||||
}
|
||||
|
||||
return !(diff == 0);
|
||||
}
|
||||
|
||||
@ -198,7 +190,6 @@ uECC_word_t uECC_vli_sub(uECC_word_t *result, const uECC_word_t *left,
|
||||
{
|
||||
uECC_word_t borrow = 0;
|
||||
wordcount_t i;
|
||||
|
||||
for (i = 0; i < num_words; ++i) {
|
||||
uECC_word_t diff = left[i] - right[i] - borrow;
|
||||
uECC_word_t val = (diff > left[i]);
|
||||
@ -206,7 +197,6 @@ uECC_word_t uECC_vli_sub(uECC_word_t *result, const uECC_word_t *left,
|
||||
|
||||
result[i] = diff;
|
||||
}
|
||||
|
||||
return borrow;
|
||||
}
|
||||
|
||||
@ -217,14 +207,12 @@ static uECC_word_t uECC_vli_add(uECC_word_t *result, const uECC_word_t *left,
|
||||
{
|
||||
uECC_word_t carry = 0;
|
||||
wordcount_t i;
|
||||
|
||||
for (i = 0; i < num_words; ++i) {
|
||||
uECC_word_t sum = left[i] + right[i] + carry;
|
||||
uECC_word_t val = (sum < left[i]);
|
||||
carry = cond_set(val, carry, (sum != left[i]));
|
||||
result[i] = sum;
|
||||
}
|
||||
|
||||
return carry;
|
||||
}
|
||||
|
||||
@ -244,7 +232,6 @@ static void uECC_vli_rshift1(uECC_word_t *vli, wordcount_t num_words)
|
||||
uECC_word_t carry = 0;
|
||||
|
||||
vli += num_words;
|
||||
|
||||
while (vli-- > end) {
|
||||
uECC_word_t temp = *vli;
|
||||
*vli = (temp >> 1) | carry;
|
||||
@ -288,13 +275,11 @@ static void uECC_vli_mult(uECC_word_t *result, const uECC_word_t *left,
|
||||
for (i = (k + 1) - num_words; i < num_words; ++i) {
|
||||
muladd(left[i], right[k - i], &r0, &r1, &r2);
|
||||
}
|
||||
|
||||
result[k] = r0;
|
||||
r0 = r1;
|
||||
r1 = r2;
|
||||
r2 = 0;
|
||||
}
|
||||
|
||||
result[num_words * 2 - 1] = r0;
|
||||
}
|
||||
|
||||
@ -303,10 +288,9 @@ void uECC_vli_modAdd(uECC_word_t *result, const uECC_word_t *left,
|
||||
wordcount_t num_words)
|
||||
{
|
||||
uECC_word_t carry = uECC_vli_add(result, left, right, num_words);
|
||||
|
||||
if (carry || uECC_vli_cmp_unsafe(mod, result, num_words) != 1) {
|
||||
/* result > mod (result = mod + remainder), so subtract mod to get
|
||||
* remainder. */
|
||||
* remainder. */
|
||||
uECC_vli_sub(result, result, mod, num_words);
|
||||
}
|
||||
}
|
||||
@ -316,10 +300,9 @@ void uECC_vli_modSub(uECC_word_t *result, const uECC_word_t *left,
|
||||
wordcount_t num_words)
|
||||
{
|
||||
uECC_word_t l_borrow = uECC_vli_sub(result, left, right, num_words);
|
||||
|
||||
if (l_borrow) {
|
||||
/* In this case, result == -diff == (max int) - diff. Since -x % d == d - x,
|
||||
* we can get the correct result from result + mod (with overflow). */
|
||||
* we can get the correct result from result + mod (with overflow). */
|
||||
uECC_vli_add(result, result, mod, num_words);
|
||||
}
|
||||
}
|
||||
@ -341,7 +324,6 @@ void uECC_vli_mmod(uECC_word_t *result, uECC_word_t *product,
|
||||
wordcount_t bit_shift = shift % uECC_WORD_BITS;
|
||||
uECC_word_t carry = 0;
|
||||
uECC_vli_clear(mod_multiple, word_shift);
|
||||
|
||||
if (bit_shift > 0) {
|
||||
for (index = 0; index < (uECC_word_t)num_words; ++index) {
|
||||
mod_multiple[word_shift + index] = (mod[index] << bit_shift) | carry;
|
||||
@ -354,24 +336,19 @@ void uECC_vli_mmod(uECC_word_t *result, uECC_word_t *product,
|
||||
for (index = 1; shift >= 0; --shift) {
|
||||
uECC_word_t borrow = 0;
|
||||
wordcount_t i;
|
||||
|
||||
for (i = 0; i < num_words * 2; ++i) {
|
||||
uECC_word_t diff = v[index][i] - mod_multiple[i] - borrow;
|
||||
|
||||
if (diff != v[index][i]) {
|
||||
borrow = (diff > v[index][i]);
|
||||
}
|
||||
|
||||
v[1 - index][i] = diff;
|
||||
}
|
||||
|
||||
/* Swap the index if there was no borrow */
|
||||
index = !(index ^ borrow);
|
||||
uECC_vli_rshift1(mod_multiple, num_words);
|
||||
mod_multiple[num_words - 1] |= mod_multiple[num_words] << (uECC_WORD_BITS - 1);
|
||||
uECC_vli_rshift1(mod_multiple + num_words, num_words);
|
||||
}
|
||||
|
||||
uECC_vli_set(result, v[index], num_words);
|
||||
}
|
||||
|
||||
@ -411,9 +388,7 @@ static void vli_modInv_update(uECC_word_t *uv,
|
||||
if (!EVEN(uv)) {
|
||||
carry = uECC_vli_add(uv, uv, mod, num_words);
|
||||
}
|
||||
|
||||
uECC_vli_rshift1(uv, num_words);
|
||||
|
||||
if (carry) {
|
||||
uv[num_words - 1] |= HIGH_BIT_SET;
|
||||
}
|
||||
@ -436,7 +411,6 @@ void uECC_vli_modInv(uECC_word_t *result, const uECC_word_t *input,
|
||||
uECC_vli_clear(u, num_words);
|
||||
u[0] = 1;
|
||||
uECC_vli_clear(v, num_words);
|
||||
|
||||
while ((cmpResult = uECC_vli_cmp_unsafe(a, b, num_words)) != 0) {
|
||||
if (EVEN(a)) {
|
||||
uECC_vli_rshift1(a, num_words);
|
||||
@ -447,26 +421,21 @@ void uECC_vli_modInv(uECC_word_t *result, const uECC_word_t *input,
|
||||
} else if (cmpResult > 0) {
|
||||
uECC_vli_sub(a, a, b, num_words);
|
||||
uECC_vli_rshift1(a, num_words);
|
||||
|
||||
if (uECC_vli_cmp_unsafe(u, v, num_words) < 0) {
|
||||
uECC_vli_add(u, u, mod, num_words);
|
||||
}
|
||||
|
||||
uECC_vli_sub(u, u, v, num_words);
|
||||
vli_modInv_update(u, mod, num_words);
|
||||
} else {
|
||||
uECC_vli_sub(b, b, a, num_words);
|
||||
uECC_vli_rshift1(b, num_words);
|
||||
|
||||
if (uECC_vli_cmp_unsafe(v, u, num_words) < 0) {
|
||||
uECC_vli_add(v, v, mod, num_words);
|
||||
}
|
||||
|
||||
uECC_vli_sub(v, v, u, num_words);
|
||||
vli_modInv_update(v, mod, num_words);
|
||||
}
|
||||
}
|
||||
|
||||
uECC_vli_set(result, u, num_words);
|
||||
}
|
||||
|
||||
@ -497,7 +466,6 @@ void double_jacobian_default(uECC_word_t *X1, uECC_word_t *Y1,
|
||||
|
||||
uECC_vli_modAdd(Z1, X1, X1, curve->p, num_words); /* t3 = 2*(x1^2 - z1^4) */
|
||||
uECC_vli_modAdd(X1, X1, Z1, curve->p, num_words); /* t1 = 3*(x1^2 - z1^4) */
|
||||
|
||||
if (uECC_vli_testBit(X1, 0)) {
|
||||
uECC_word_t l_carry = uECC_vli_add(X1, X1, curve->p, num_words);
|
||||
uECC_vli_rshift1(X1, num_words);
|
||||
@ -663,7 +631,6 @@ static void XYcZ_initial_double(uECC_word_t *X1, uECC_word_t *Y1,
|
||||
{
|
||||
uECC_word_t z[NUM_ECC_WORDS];
|
||||
wordcount_t num_words = curve->num_words;
|
||||
|
||||
if (initial_Z) {
|
||||
uECC_vli_set(z, initial_Z, num_words);
|
||||
} else {
|
||||
@ -818,7 +785,7 @@ uECC_word_t EccPoint_compute_public_key(uECC_word_t *result,
|
||||
uECC_word_t carry;
|
||||
|
||||
/* Regularize the bitcount for the private key so that attackers cannot
|
||||
* use a side channel attack to learn the number of leading zeros. */
|
||||
* use a side channel attack to learn the number of leading zeros. */
|
||||
carry = regularize_k(private_key, tmp1, tmp2, curve);
|
||||
|
||||
EccPoint_mult(result, curve->G, p2[!carry], 0, curve->num_n_bits + 1, curve);
|
||||
@ -826,7 +793,6 @@ uECC_word_t EccPoint_compute_public_key(uECC_word_t *result,
|
||||
if (EccPoint_isZero(result, curve)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -835,7 +801,6 @@ void uECC_vli_nativeToBytes(uint8_t *bytes, int num_bytes,
|
||||
const unsigned int *native)
|
||||
{
|
||||
wordcount_t i;
|
||||
|
||||
for (i = 0; i < num_bytes; ++i) {
|
||||
unsigned b = num_bytes - 1 - i;
|
||||
bytes[i] = native[b / uECC_WORD_SIZE] >> (8 * (b % uECC_WORD_SIZE));
|
||||
@ -848,7 +813,6 @@ void uECC_vli_bytesToNative(unsigned int *native, const uint8_t *bytes,
|
||||
{
|
||||
wordcount_t i;
|
||||
uECC_vli_clear(native, (num_bytes + (uECC_WORD_SIZE - 1)) / uECC_WORD_SIZE);
|
||||
|
||||
for (i = 0; i < num_bytes; ++i) {
|
||||
unsigned b = num_bytes - 1 - i;
|
||||
native[b / uECC_WORD_SIZE] |=
|
||||
@ -871,16 +835,13 @@ int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top,
|
||||
if (!g_rng_function((uint8_t *)random, num_words * uECC_WORD_SIZE)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
random[num_words - 1] &=
|
||||
mask >> ((bitcount_t)(num_words * uECC_WORD_SIZE * 8 - num_bits));
|
||||
|
||||
if (!uECC_vli_isZero(random, num_words) &&
|
||||
uECC_vli_cmp(top, random, num_words) == 1) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -905,9 +866,8 @@ int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve)
|
||||
curve->x_side(tmp2, point, curve); /* tmp2 = x^3 + ax + b */
|
||||
|
||||
/* Make sure that y^2 == x^3 + ax + b */
|
||||
if (uECC_vli_equal(tmp1, tmp2, num_words) != 0) {
|
||||
if (uECC_vli_equal(tmp1, tmp2, num_words) != 0)
|
||||
return -3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ec_dh.c - TinyCrypt implementation of EC-DH */
|
||||
|
||||
/*
|
||||
/*
|
||||
* Copyright (c) 2014, Kenneth MacKay
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -78,8 +78,8 @@ int uECC_make_key_with_d(uint8_t *public_key, uint8_t *private_key,
|
||||
uECC_word_t _public[NUM_ECC_WORDS * 2];
|
||||
|
||||
/* This function is designed for test purposes-only (such as validating NIST
|
||||
* test vectors) as it uses a provided value for d instead of generating
|
||||
* it uniformly at random. */
|
||||
* test vectors) as it uses a provided value for d instead of generating
|
||||
* it uniformly at random. */
|
||||
memcpy(_private, d, NUM_ECC_BYTES);
|
||||
|
||||
/* Computing public-key from private: */
|
||||
@ -100,7 +100,6 @@ int uECC_make_key_with_d(uint8_t *public_key, uint8_t *private_key,
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -114,7 +113,6 @@ int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve)
|
||||
for (tries = 0; tries < uECC_RNG_MAX_TRIES; ++tries) {
|
||||
/* Generating _private uniformly at random: */
|
||||
uECC_RNG_Function rng_function = uECC_get_rng();
|
||||
|
||||
if (!rng_function ||
|
||||
!rng_function((uint8_t *)_random, 2 * NUM_ECC_WORDS * uECC_WORD_SIZE)) {
|
||||
return 0;
|
||||
@ -142,7 +140,6 @@ int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -172,17 +169,16 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
|
||||
num_bytes);
|
||||
|
||||
/* Regularize the bitcount for the private key so that attackers cannot use a
|
||||
* side channel attack to learn the number of leading zeros. */
|
||||
* side channel attack to learn the number of leading zeros. */
|
||||
carry = regularize_k(_private, _private, tmp, curve);
|
||||
|
||||
/* If an RNG function was specified, try to get a random initial Z value to
|
||||
* improve protection against side-channel attacks. */
|
||||
* improve protection against side-channel attacks. */
|
||||
if (g_rng_function) {
|
||||
if (!uECC_generate_random_int(p2[carry], curve->p, num_words)) {
|
||||
r = 0;
|
||||
goto clear_and_out;
|
||||
}
|
||||
|
||||
initial_Z = p2[carry];
|
||||
}
|
||||
|
||||
|
@ -81,15 +81,12 @@ static void bits2int(uECC_word_t *native, const uint8_t *bits,
|
||||
|
||||
uECC_vli_clear(native, num_n_words);
|
||||
uECC_vli_bytesToNative(native, bits, bits_size);
|
||||
|
||||
if (bits_size * 8 <= (unsigned)curve->num_n_bits) {
|
||||
return;
|
||||
}
|
||||
|
||||
shift = bits_size * 8 - curve->num_n_bits;
|
||||
carry = 0;
|
||||
ptr = native + num_n_words;
|
||||
|
||||
while (ptr-- > native) {
|
||||
uECC_word_t temp = *ptr;
|
||||
*ptr = (temp >> shift) | carry;
|
||||
@ -123,13 +120,12 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
|
||||
carry = regularize_k(k, tmp, s, curve);
|
||||
EccPoint_mult(p, curve->G, k2[!carry], 0, num_n_bits + 1, curve);
|
||||
|
||||
if (uECC_vli_isZero(p, num_words)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If an RNG function was specified, get a random number
|
||||
to prevent side channel analysis of k. */
|
||||
to prevent side channel analysis of k. */
|
||||
if (!g_rng_function) {
|
||||
uECC_vli_clear(tmp, num_n_words);
|
||||
tmp[0] = 1;
|
||||
@ -138,7 +134,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
}
|
||||
|
||||
/* Prevent side channel analysis of uECC_vli_modInv() to determine
|
||||
bits of k / the private key by premultiplying by a random number */
|
||||
bits of k / the private key by premultiplying by a random number */
|
||||
uECC_vli_modMult(k, k, tmp, curve->n, num_n_words); /* k' = rand * k */
|
||||
uECC_vli_modInv(k, k, curve->n, num_n_words); /* k = 1 / k' */
|
||||
uECC_vli_modMult(k, k, tmp, curve->n, num_n_words); /* k = 1 / k */
|
||||
@ -155,7 +151,6 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
bits2int(tmp, message_hash, hash_size, curve);
|
||||
uECC_vli_modAdd(s, tmp, s, curve->n, num_n_words); /* s = e + r*d */
|
||||
uECC_vli_modMult(s, s, k, curve->n, num_n_words); /* s = (e + r*d) / k */
|
||||
|
||||
if (uECC_vli_numBits(s, num_n_words) > (bitcount_t)curve->num_bytes * 8) {
|
||||
return 0;
|
||||
}
|
||||
@ -174,7 +169,6 @@ int uECC_sign(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
for (tries = 0; tries < uECC_RNG_MAX_TRIES; ++tries) {
|
||||
/* Generating _random uniformly at random: */
|
||||
uECC_RNG_Function rng_function = uECC_get_rng();
|
||||
|
||||
if (!rng_function ||
|
||||
!rng_function((uint8_t *)_random, 2 * NUM_ECC_WORDS * uECC_WORD_SIZE)) {
|
||||
return 0;
|
||||
@ -188,7 +182,6 @@ int uECC_sign(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -278,7 +271,6 @@ int uECC_verify(const uint8_t *public_key, const uint8_t *message_hash,
|
||||
|
||||
index = (!!uECC_vli_testBit(u1, i)) | ((!!uECC_vli_testBit(u2, i)) << 1);
|
||||
point = points[index];
|
||||
|
||||
if (point) {
|
||||
uECC_vli_set(tx, point, num_words);
|
||||
uECC_vli_set(ty, point + num_words, num_words);
|
||||
|
@ -73,15 +73,12 @@
|
||||
int default_CSPRNG(uint8_t *dest, unsigned int size)
|
||||
{
|
||||
/* input sanity check: */
|
||||
if (dest == (uint8_t *)0 || (size <= 0)) {
|
||||
if (dest == (uint8_t *)0 || (size <= 0))
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||
|
||||
if (fd == -1) {
|
||||
fd = open("/dev/random", O_RDONLY | O_CLOEXEC);
|
||||
|
||||
if (fd == -1) {
|
||||
return 0;
|
||||
}
|
||||
@ -89,16 +86,12 @@ int default_CSPRNG(uint8_t *dest, unsigned int size)
|
||||
|
||||
char *ptr = (char *)dest;
|
||||
size_t left = (size_t)size;
|
||||
|
||||
while (left > 0) {
|
||||
ssize_t bytes_read = read(fd, ptr, left);
|
||||
|
||||
if (bytes_read <= 0) // read failed
|
||||
{
|
||||
if (bytes_read <= 0) { // read failed
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
left -= bytes_read;
|
||||
ptr += bytes_read;
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ static void rekey(uint8_t *key, const uint8_t *new_key, unsigned int key_size)
|
||||
key[i] = inner_pad ^ new_key[i];
|
||||
key[i + TC_SHA256_BLOCK_SIZE] = outer_pad ^ new_key[i];
|
||||
}
|
||||
|
||||
for (; i < TC_SHA256_BLOCK_SIZE; ++i) {
|
||||
key[i] = inner_pad;
|
||||
key[i + TC_SHA256_BLOCK_SIZE] = outer_pad;
|
||||
@ -66,12 +65,12 @@ int tc_hmac_set_key(TCHmacState_t ctx, const uint8_t *key,
|
||||
|
||||
if (key_size <= TC_SHA256_BLOCK_SIZE) {
|
||||
/*
|
||||
* The next three calls are dummy calls just to avoid
|
||||
* certain timing attacks. Without these dummy calls,
|
||||
* adversaries would be able to learn whether the key_size is
|
||||
* greater than TC_SHA256_BLOCK_SIZE by measuring the time
|
||||
* consumed in this process.
|
||||
*/
|
||||
* The next three calls are dummy calls just to avoid
|
||||
* certain timing attacks. Without these dummy calls,
|
||||
* adversaries would be able to learn whether the key_size is
|
||||
* greater than TC_SHA256_BLOCK_SIZE by measuring the time
|
||||
* consumed in this process.
|
||||
*/
|
||||
(void)tc_sha256_init(&dummy_state.hash_state);
|
||||
(void)tc_sha256_update(&dummy_state.hash_state,
|
||||
dummy_key,
|
||||
|
@ -88,13 +88,10 @@ static void update(TCHmacPrng_t prng, const uint8_t *data, unsigned int datalen,
|
||||
(void)tc_hmac_update(&prng->h, prng->v, sizeof(prng->v));
|
||||
(void)tc_hmac_update(&prng->h, &separator0, sizeof(separator0));
|
||||
|
||||
if (data && datalen) {
|
||||
if (data && datalen)
|
||||
(void)tc_hmac_update(&prng->h, data, datalen);
|
||||
}
|
||||
|
||||
if (additional_data && additional_datalen) {
|
||||
if (additional_data && additional_datalen)
|
||||
(void)tc_hmac_update(&prng->h, additional_data, additional_datalen);
|
||||
}
|
||||
|
||||
(void)tc_hmac_final(prng->key, sizeof(prng->key), &prng->h);
|
||||
|
||||
@ -106,9 +103,8 @@ static void update(TCHmacPrng_t prng, const uint8_t *data, unsigned int datalen,
|
||||
(void)tc_hmac_update(&prng->h, prng->v, sizeof(prng->v));
|
||||
(void)tc_hmac_final(prng->v, sizeof(prng->v), &prng->h);
|
||||
|
||||
if (data == 0 || datalen == 0) {
|
||||
if (data == 0 || datalen == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/* configure the new prng key into the prng's instance of hmac */
|
||||
tc_hmac_set_key(&prng->h, prng->key, sizeof(prng->key));
|
||||
@ -118,11 +114,8 @@ static void update(TCHmacPrng_t prng, const uint8_t *data, unsigned int datalen,
|
||||
(void)tc_hmac_update(&prng->h, prng->v, sizeof(prng->v));
|
||||
(void)tc_hmac_update(&prng->h, &separator1, sizeof(separator1));
|
||||
(void)tc_hmac_update(&prng->h, data, datalen);
|
||||
|
||||
if (additional_data && additional_datalen) {
|
||||
if (additional_data && additional_datalen)
|
||||
(void)tc_hmac_update(&prng->h, additional_data, additional_datalen);
|
||||
}
|
||||
|
||||
(void)tc_hmac_final(prng->key, sizeof(prng->key), &prng->h);
|
||||
|
||||
/* configure the new prng key into the prng's instance of hmac */
|
||||
@ -173,9 +166,9 @@ int tc_hmac_prng_reseed(TCHmacPrng_t prng,
|
||||
|
||||
if (additional_input != (const uint8_t *)0) {
|
||||
/*
|
||||
* Abort if additional_input is provided but has inappropriate
|
||||
* length
|
||||
*/
|
||||
* Abort if additional_input is provided but has inappropriate
|
||||
* length
|
||||
*/
|
||||
if (additionallen == 0 ||
|
||||
additionallen > MAX_ALEN) {
|
||||
return TC_CRYPTO_FAIL;
|
||||
|
@ -44,11 +44,11 @@ int tc_sha256_init(TCSha256State_t s)
|
||||
}
|
||||
|
||||
/*
|
||||
* Setting the initial state values.
|
||||
* These values correspond to the first 32 bits of the fractional parts
|
||||
* of the square roots of the first 8 primes: 2, 3, 5, 7, 11, 13, 17
|
||||
* and 19.
|
||||
*/
|
||||
* Setting the initial state values.
|
||||
* These values correspond to the first 32 bits of the fractional parts
|
||||
* of the square roots of the first 8 primes: 2, 3, 5, 7, 11, 13, 17
|
||||
* and 19.
|
||||
*/
|
||||
_set((uint8_t *)s, 0x00, sizeof(*s));
|
||||
s->iv[0] = 0x6a09e667;
|
||||
s->iv[1] = 0xbb67ae85;
|
||||
@ -74,7 +74,6 @@ int tc_sha256_update(TCSha256State_t s, const uint8_t *data, size_t datalen)
|
||||
|
||||
while (datalen-- > 0) {
|
||||
s->leftover[s->leftover_offset++] = *(data++);
|
||||
|
||||
if (s->leftover_offset >= TC_SHA256_BLOCK_SIZE) {
|
||||
compress(s->iv, s->leftover);
|
||||
s->leftover_offset = 0;
|
||||
@ -98,7 +97,6 @@ int tc_sha256_final(uint8_t *digest, TCSha256State_t s)
|
||||
s->bits_hashed += (s->leftover_offset << 3);
|
||||
|
||||
s->leftover[s->leftover_offset++] = 0x80; /* always room for one byte */
|
||||
|
||||
if (s->leftover_offset > (sizeof(s->leftover) - 8)) {
|
||||
/* there is not room for all the padding in this block */
|
||||
_set(s->leftover + s->leftover_offset, 0x00,
|
||||
|
@ -70,6 +70,5 @@ int _compare(const uint8_t *a, const uint8_t *b, size_t size)
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
result |= tempa[i] ^ tempb[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -28,12 +28,10 @@ unsigned int find_msb_set(uint32_t data)
|
||||
if (!data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ((data & mask) == 0) {
|
||||
count += 1u;
|
||||
mask = mask >> 1u;
|
||||
}
|
||||
|
||||
return (32 - count);
|
||||
}
|
||||
|
||||
@ -45,12 +43,10 @@ unsigned int find_lsb_set(uint32_t data)
|
||||
if (!data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ((data & mask) == 0) {
|
||||
count += 1u;
|
||||
mask = mask << 1u;
|
||||
}
|
||||
|
||||
return (1 + count);
|
||||
}
|
||||
|
||||
@ -92,7 +88,6 @@ size_t bin2hex(const uint8_t *buf, size_t buflen, char *hex, size_t hexlen)
|
||||
if (hex2char(buf[i] >> 4, &hex[2 * i]) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (hex2char(buf[i] & 0xf, &hex[2 * i + 1]) < 0) {
|
||||
return 0;
|
||||
}
|
||||
@ -115,7 +110,6 @@ size_t hex2bin(const char *hex, size_t hexlen, uint8_t *buf, size_t buflen)
|
||||
if (char2hex(hex[0], &dec) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buf[0] = dec;
|
||||
hex++;
|
||||
buf++;
|
||||
@ -126,13 +120,11 @@ size_t hex2bin(const char *hex, size_t hexlen, uint8_t *buf, size_t buflen)
|
||||
if (char2hex(hex[2 * i], &dec) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buf[i] = dec << 4;
|
||||
|
||||
if (char2hex(hex[2 * i + 1], &dec) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buf[i] += dec;
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,6 @@ static void work_timeout(void *timer)
|
||||
{
|
||||
/* Parameter timer type is */
|
||||
struct k_delayed_work *w = (struct k_delayed_work *)k_timer_get_id(timer);
|
||||
|
||||
if (w->work_q == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -183,19 +182,16 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
|
||||
|
||||
timer = &work->timer;
|
||||
remain = timer->timeout - (k_now_ms() - timer->start_ms);
|
||||
|
||||
if (remain < 0) {
|
||||
remain = 0;
|
||||
}
|
||||
|
||||
return remain;
|
||||
}
|
||||
|
||||
void k_delayed_work_del_timer(struct k_delayed_work *work)
|
||||
{
|
||||
if (NULL == work || NULL == work->timer.timer.hdl) {
|
||||
if (NULL == work || NULL == work->timer.timer.hdl)
|
||||
return;
|
||||
}
|
||||
|
||||
k_timer_delete(&work->timer);
|
||||
work->timer.timer.hdl = NULL;
|
||||
@ -233,7 +229,6 @@ static void work_q_main(void *work_q_ptr, void *p2, void *p3)
|
||||
k_work_handler_t handler;
|
||||
|
||||
work = k_queue_get(&work_q->queue, K_FOREVER);
|
||||
|
||||
if (!work) {
|
||||
continue;
|
||||
}
|
||||
@ -247,8 +242,8 @@ static void work_q_main(void *work_q_ptr, void *p2, void *p3)
|
||||
}
|
||||
|
||||
/* Make sure we don't hog up the CPU if the FIFO never (or
|
||||
* very rarely) gets empty.
|
||||
*/
|
||||
* very rarely) gets empty.
|
||||
*/
|
||||
k_yield();
|
||||
}
|
||||
}
|
||||
@ -297,7 +292,6 @@ int k_delayed_work_submit_to_queue(struct k_work_q *work_q,
|
||||
/* Cancel if work has been submitted */
|
||||
if (work->work_q == work_q) {
|
||||
err = k_delayed_work_cancel(work);
|
||||
|
||||
if (err < 0) {
|
||||
goto done;
|
||||
}
|
||||
|
@ -113,13 +113,11 @@ static void prio_recv_thread(void *p1, void *p2, void *p3)
|
||||
BT_DBG("sem taken");
|
||||
|
||||
#if defined(CONFIG_INIT_STACKS)
|
||||
|
||||
if (k_uptime_get_32() - prio_ts > K_SECONDS(5)) {
|
||||
STACK_ANALYZE("prio recv thread stack",
|
||||
prio_recv_thread_stack);
|
||||
prio_ts = k_uptime_get_32();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -139,21 +137,17 @@ static inline struct net_buf *encode_node(struct radio_pdu_node_rx *node_rx,
|
||||
} else {
|
||||
buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER);
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
hci_evt_encode(node_rx, buf);
|
||||
}
|
||||
|
||||
break;
|
||||
#if defined(CONFIG_BT_CONN)
|
||||
|
||||
case HCI_CLASS_ACL_DATA:
|
||||
/* generate ACL data */
|
||||
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER);
|
||||
hci_acl_encode(node_rx, buf);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
LL_ASSERT(0);
|
||||
break;
|
||||
@ -172,7 +166,6 @@ static inline struct net_buf *process_node(struct radio_pdu_node_rx *node_rx)
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
|
||||
|
||||
if (hbuf_count != -1) {
|
||||
bool pend = !sys_slist_is_empty(&hbuf_pend);
|
||||
|
||||
@ -181,12 +174,10 @@ static inline struct net_buf *process_node(struct radio_pdu_node_rx *node_rx)
|
||||
case HCI_CLASS_EVT_DISCARDABLE:
|
||||
case HCI_CLASS_EVT_REQUIRED:
|
||||
break;
|
||||
|
||||
case HCI_CLASS_EVT_CONNECTION:
|
||||
/* for conn-related events, only pend is relevant */
|
||||
hbuf_count = 1;
|
||||
|
||||
/* fallthrough */
|
||||
/* fallthrough */
|
||||
case HCI_CLASS_ACL_DATA:
|
||||
if (pend || !hbuf_count) {
|
||||
sys_slist_append(&hbuf_pend,
|
||||
@ -194,15 +185,12 @@ static inline struct net_buf *process_node(struct radio_pdu_node_rx *node_rx)
|
||||
BT_DBG("FC: Queuing item: %d", class);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
LL_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* process regular node from radio */
|
||||
@ -223,7 +211,6 @@ static inline struct net_buf *process_hbuf(struct radio_pdu_node_rx *n)
|
||||
int reset;
|
||||
|
||||
reset = atomic_test_and_clear_bit(&hci_state_mask, HCI_STATE_BIT_RESET);
|
||||
|
||||
if (reset) {
|
||||
/* flush queue, no need to free, the LL has already done it */
|
||||
sys_slist_init(&hbuf_pend);
|
||||
@ -239,7 +226,6 @@ static inline struct net_buf *process_hbuf(struct radio_pdu_node_rx *n)
|
||||
|
||||
/* host acked ACL packets, try to dequeue from hbuf */
|
||||
node = sys_slist_peek_head(&hbuf_pend);
|
||||
|
||||
if (!node) {
|
||||
return NULL;
|
||||
}
|
||||
@ -247,7 +233,6 @@ static inline struct net_buf *process_hbuf(struct radio_pdu_node_rx *n)
|
||||
/* Return early if this iteration already has a node to process */
|
||||
node_rx = NODE_RX(node);
|
||||
class = hci_get_class(node_rx);
|
||||
|
||||
if (n) {
|
||||
if (class == HCI_CLASS_EVT_CONNECTION ||
|
||||
(class == HCI_CLASS_ACL_DATA && hbuf_count)) {
|
||||
@ -255,7 +240,6 @@ static inline struct net_buf *process_hbuf(struct radio_pdu_node_rx *n)
|
||||
BT_DBG("FC: signalling");
|
||||
k_poll_signal_raise(&hbuf_signal, 0x0);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -264,7 +248,6 @@ static inline struct net_buf *process_hbuf(struct radio_pdu_node_rx *n)
|
||||
BT_DBG("FC: dequeueing event");
|
||||
(void)sys_slist_get(&hbuf_pend);
|
||||
break;
|
||||
|
||||
case HCI_CLASS_ACL_DATA:
|
||||
if (hbuf_count) {
|
||||
BT_DBG("FC: dequeueing ACL data");
|
||||
@ -273,9 +256,7 @@ static inline struct net_buf *process_hbuf(struct radio_pdu_node_rx *n)
|
||||
/* no buffers, HCI will signal */
|
||||
node = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HCI_CLASS_EVT_DISCARDABLE:
|
||||
case HCI_CLASS_EVT_REQUIRED:
|
||||
default:
|
||||
@ -289,7 +270,6 @@ static inline struct net_buf *process_hbuf(struct radio_pdu_node_rx *n)
|
||||
hbuf_count = hbuf_total - (hci_hbuf_sent - hci_hbuf_acked);
|
||||
/* next node */
|
||||
node = sys_slist_peek_head(&hbuf_pend);
|
||||
|
||||
if (node) {
|
||||
node_rx = NODE_RX(node);
|
||||
class = hci_get_class(node_rx);
|
||||
@ -297,8 +277,8 @@ static inline struct net_buf *process_hbuf(struct radio_pdu_node_rx *n)
|
||||
if (class == HCI_CLASS_EVT_CONNECTION ||
|
||||
(class == HCI_CLASS_ACL_DATA && hbuf_count)) {
|
||||
/* more to process, schedule an
|
||||
* iteration
|
||||
*/
|
||||
* iteration
|
||||
*/
|
||||
BT_DBG("FC: signalling");
|
||||
k_poll_signal_raise(&hbuf_signal, 0x0);
|
||||
}
|
||||
@ -316,7 +296,6 @@ void co_rx_thread()
|
||||
{
|
||||
struct net_buf *buf = NULL;
|
||||
buf = net_buf_get(&recv_fifo, K_NO_WAIT);
|
||||
|
||||
if (buf) {
|
||||
BT_DBG("Calling bt_recv(%p)", buf);
|
||||
bt_recv(buf);
|
||||
@ -327,7 +306,6 @@ void co_tx_rx_thread(void *p1)
|
||||
{
|
||||
UNUSED(p1);
|
||||
BT_DBG("using %s\n", __func__);
|
||||
|
||||
while (1) {
|
||||
if (k_sem_count_get(&g_poll_sem) > 0) {
|
||||
co_tx_thread();
|
||||
@ -363,12 +341,10 @@ static void recv_thread(void *p1)
|
||||
#if defined(BFLB_BLE)
|
||||
struct net_buf *buf = NULL;
|
||||
buf = net_buf_get(&recv_fifo, K_FOREVER);
|
||||
|
||||
if (buf) {
|
||||
BT_DBG("Calling bt_recv(%p)", buf);
|
||||
bt_recv(buf);
|
||||
}
|
||||
|
||||
#else
|
||||
struct radio_pdu_node_rx *node_rx = NULL;
|
||||
struct net_buf *buf = NULL;
|
||||
@ -379,7 +355,6 @@ static void recv_thread(void *p1)
|
||||
|
||||
err = k_poll(events, 2, K_FOREVER);
|
||||
LL_ASSERT(err == 0);
|
||||
|
||||
if (events[0].state == K_POLL_STATE_SIGNALED) {
|
||||
events[0].signal->signaled = 0;
|
||||
} else if (events[1].state ==
|
||||
@ -412,17 +387,14 @@ static void recv_thread(void *p1)
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
k_yield();
|
||||
|
||||
#if defined(CONFIG_INIT_STACKS)
|
||||
|
||||
if (k_uptime_get_32() - rx_ts > K_SECONDS(5)) {
|
||||
STACK_ANALYZE("recv thread stack", recv_thread_stack);
|
||||
rx_ts = k_uptime_get_32();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -435,7 +407,6 @@ static int cmd_handle(struct net_buf *buf)
|
||||
struct net_buf *evt;
|
||||
|
||||
evt = hci_cmd_handle(buf);
|
||||
|
||||
if (evt) {
|
||||
BT_DBG("Replying with event of %u bytes", evt->len);
|
||||
bt_recv_prio(evt);
|
||||
@ -449,7 +420,6 @@ static int acl_handle(struct net_buf *buf)
|
||||
int err;
|
||||
|
||||
err = hci_acl_handle(buf, &evt);
|
||||
|
||||
if (evt) {
|
||||
BT_DBG("Replying with event of %u bytes", evt->len);
|
||||
bt_recv_prio(evt);
|
||||
@ -480,20 +450,16 @@ static int hci_driver_send(struct net_buf *buf)
|
||||
return err;
|
||||
#else
|
||||
type = bt_buf_get_type(buf);
|
||||
|
||||
switch (type) {
|
||||
#if defined(CONFIG_BT_CONN)
|
||||
|
||||
case BT_BUF_ACL_OUT:
|
||||
err = acl_handle(buf);
|
||||
break;
|
||||
#endif /* CONFIG_BT_CONN */
|
||||
|
||||
case BT_BUF_CMD:
|
||||
err = cmd_handle(buf);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("Unknown HCI type %u", type);
|
||||
return -EINVAL;
|
||||
@ -523,7 +489,6 @@ static int hci_driver_open(void)
|
||||
BT_ERR("LL initialization failed: %u", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(BFLB_BLE)
|
||||
|
@ -40,8 +40,7 @@ struct bt_a2dp {
|
||||
struct bt_avdtp session;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
OI_CODEC_SBC_DECODER_CONTEXT decoder_context;
|
||||
uint32_t context_data[CODEC_DATA_WORDS(SBC_MAX_CHANNELS, SBC_CODEC_FAST_FILTER_BUFFERS)];
|
||||
int16_t decode_buf[15 * SBC_MAX_SAMPLES_PER_FRAME * SBC_MAX_CHANNELS];
|
||||
@ -151,7 +150,6 @@ struct bt_a2dp *get_new_connection(struct bt_conn *conn)
|
||||
for (i = 0; i < CONFIG_BT_MAX_CONN; i++) {
|
||||
if (connection[i].session.br_chan.chan.conn == conn) {
|
||||
BT_DBG("Conn already exists");
|
||||
|
||||
if (!connection[i].session.streams->chan.chan.conn) {
|
||||
BT_DBG("Create AV stream");
|
||||
return &connection[i];
|
||||
@ -186,7 +184,6 @@ int a2dp_accept(struct bt_conn *conn, struct bt_avdtp **session)
|
||||
struct bt_a2dp *a2dp_conn;
|
||||
|
||||
a2dp_conn = get_new_connection(conn);
|
||||
|
||||
if (!a2dp_conn) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -206,7 +203,6 @@ int a2dp_sbc_decode_init()
|
||||
2,
|
||||
false,
|
||||
false);
|
||||
|
||||
if (!OI_SUCCESS(status)) {
|
||||
BT_ERR("decode init failed with error: %d\n", status);
|
||||
return status;
|
||||
@ -246,7 +242,6 @@ int a2dp_sbc_decode_process(uint8_t media_data[], uint16_t data_len)
|
||||
&data_size,
|
||||
pcm,
|
||||
&pcm_size);
|
||||
|
||||
if (!OI_SUCCESS(status)) {
|
||||
BT_ERR("decoding failure with error: %d \n", status);
|
||||
return -1;
|
||||
@ -278,7 +273,6 @@ int bt_a2dp_init(void)
|
||||
|
||||
/* Register event handlers with AVDTP */
|
||||
err = bt_avdtp_register(&avdtp_cb);
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("A2DP registration failed");
|
||||
return err;
|
||||
@ -286,7 +280,6 @@ int bt_a2dp_init(void)
|
||||
|
||||
/* Register SDP record */
|
||||
err = bt_sdp_register_service(&a2dp_rec);
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("A2DP regist sdp record failed");
|
||||
return err;
|
||||
@ -294,7 +287,6 @@ int bt_a2dp_init(void)
|
||||
|
||||
int reg_1 = bt_a2dp_register_endpoint(&endpoint_1, BT_A2DP_AUDIO, BT_A2DP_SINK);
|
||||
int reg_2 = bt_a2dp_register_endpoint(&endpoint_2, BT_A2DP_AUDIO, BT_A2DP_SINK);
|
||||
|
||||
if (reg_1 || reg_2) {
|
||||
BT_ERR("A2DP registration endpoint 1 failed");
|
||||
return err;
|
||||
@ -303,7 +295,6 @@ int bt_a2dp_init(void)
|
||||
bt_a2dp_set_sbc_codec_info();
|
||||
|
||||
err = a2dp_sbc_decode_init();
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("sbc codec init failed");
|
||||
return err;
|
||||
@ -319,14 +310,12 @@ struct bt_a2dp *bt_a2dp_connect(struct bt_conn *conn)
|
||||
int err;
|
||||
|
||||
a2dp_conn = get_new_connection(conn);
|
||||
|
||||
if (!a2dp_conn) {
|
||||
BT_ERR("Cannot allocate memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err = bt_avdtp_connect(conn, &(a2dp_conn->session));
|
||||
|
||||
if (err < 0) {
|
||||
/* If error occurs, undo the saving and return the error */
|
||||
a2d_reset(a2dp_conn);
|
||||
@ -346,7 +335,6 @@ int bt_a2dp_register_endpoint(struct bt_a2dp_endpoint *endpoint,
|
||||
BT_ASSERT(endpoint);
|
||||
|
||||
err = bt_avdtp_register_sep(media_type, role, &(endpoint->info));
|
||||
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ int at_check_byte(struct net_buf *buf, char check_byte)
|
||||
if (*str != check_byte) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
net_buf_pull(buf, 1);
|
||||
|
||||
return 0;
|
||||
@ -111,7 +110,6 @@ static int get_cmd_value(struct at_client *at, struct net_buf *buf,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
net_buf_pull(buf, cmd_len);
|
||||
|
||||
if (pos == at->buf_max_len) {
|
||||
@ -142,7 +140,6 @@ static int get_response_string(struct at_client *at, struct net_buf *buf,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
net_buf_pull(buf, cmd_len);
|
||||
|
||||
if (pos == at->buf_max_len) {
|
||||
@ -163,11 +160,9 @@ static int at_state_start(struct at_client *at, struct net_buf *buf)
|
||||
int err;
|
||||
|
||||
err = at_check_byte(buf, '\r');
|
||||
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
at->state = AT_STATE_START_CR;
|
||||
|
||||
return 0;
|
||||
@ -178,11 +173,9 @@ static int at_state_start_cr(struct at_client *at, struct net_buf *buf)
|
||||
int err;
|
||||
|
||||
err = at_check_byte(buf, '\n');
|
||||
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
at->state = AT_STATE_START_LF;
|
||||
|
||||
return 0;
|
||||
@ -191,7 +184,6 @@ static int at_state_start_cr(struct at_client *at, struct net_buf *buf)
|
||||
static int at_state_start_lf(struct at_client *at, struct net_buf *buf)
|
||||
{
|
||||
reset_buffer(at);
|
||||
|
||||
if (at_check_byte(buf, '+') == 0) {
|
||||
at->state = AT_STATE_GET_CMD_STRING;
|
||||
return 0;
|
||||
@ -229,7 +221,6 @@ static int at_state_process_cmd(struct at_client *at, struct net_buf *buf)
|
||||
at->resp = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
at->state = AT_STATE_UNSOLICITED_CMD;
|
||||
return 0;
|
||||
}
|
||||
@ -261,8 +252,8 @@ static int at_state_process_result(struct at_client *at, struct net_buf *buf)
|
||||
if (at_parse_result(at->buf, buf, &result) == 0) {
|
||||
if (at->finish) {
|
||||
/* cme_err is 0 - Is invalid until result is
|
||||
* AT_RESULT_CME_ERROR
|
||||
*/
|
||||
* AT_RESULT_CME_ERROR
|
||||
*/
|
||||
cme_err = 0;
|
||||
at->finish(at, result, cme_err);
|
||||
}
|
||||
@ -330,9 +321,7 @@ int at_parse_input(struct at_client *at, struct net_buf *buf)
|
||||
if (at->state < AT_STATE_START || at->state >= AT_STATE_END) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = parser_cb[at->state](at, buf);
|
||||
|
||||
if (ret < 0) {
|
||||
/* Reset the state in case of error */
|
||||
at->cmd_state = AT_CMD_START;
|
||||
@ -352,14 +341,13 @@ static int at_cmd_start(struct at_client *at, struct net_buf *buf,
|
||||
if (type == AT_CMD_TYPE_NORMAL) {
|
||||
at->state = AT_STATE_UNSOLICITED_CMD;
|
||||
}
|
||||
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
if (type == AT_CMD_TYPE_OTHER) {
|
||||
/* Skip for Other type such as ..RING.. which does not have
|
||||
* values to get processed.
|
||||
*/
|
||||
* values to get processed.
|
||||
*/
|
||||
at->cmd_state = AT_CMD_PROCESS_VALUE;
|
||||
} else {
|
||||
at->cmd_state = AT_CMD_GET_VALUE;
|
||||
@ -396,7 +384,6 @@ static int at_cmd_state_end_lf(struct at_client *at, struct net_buf *buf,
|
||||
int err;
|
||||
|
||||
err = at_check_byte(buf, '\n');
|
||||
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
@ -425,13 +412,10 @@ int at_parse_cmd_input(struct at_client *at, struct net_buf *buf,
|
||||
at->cmd_state >= AT_CMD_STATE_END) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = cmd_parser_cb[at->cmd_state](at, buf, prefix, func, type);
|
||||
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Check for main state, the end of cmd parsing and return. */
|
||||
if (at->state == AT_STATE_START) {
|
||||
return 0;
|
||||
@ -454,7 +438,6 @@ int at_open_list(struct at_client *at)
|
||||
if (at->buf[at->pos] != '(') {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
at->pos++;
|
||||
|
||||
return 0;
|
||||
@ -467,7 +450,6 @@ int at_close_list(struct at_client *at)
|
||||
if (at->buf[at->pos] != ')') {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
at->pos++;
|
||||
|
||||
next_list(at);
|
||||
@ -484,14 +466,12 @@ int at_list_get_string(struct at_client *at, char *name, uint8_t len)
|
||||
if (at->buf[at->pos] != '"') {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
at->pos++;
|
||||
|
||||
while (at->buf[at->pos] != '\0' && at->buf[at->pos] != '"') {
|
||||
if (i == len) {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
name[i++] = at->buf[at->pos++];
|
||||
}
|
||||
|
||||
@ -504,7 +484,6 @@ int at_list_get_string(struct at_client *at, char *name, uint8_t len)
|
||||
if (at->buf[at->pos] != '"') {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
at->pos++;
|
||||
|
||||
skip_space(at);
|
||||
@ -519,7 +498,6 @@ int at_list_get_range(struct at_client *at, uint32_t *min, uint32_t *max)
|
||||
int ret;
|
||||
|
||||
ret = at_get_number(at, &low);
|
||||
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@ -532,10 +510,8 @@ int at_list_get_range(struct at_client *at, uint32_t *min, uint32_t *max)
|
||||
if (!isdigit((unsigned char)at->buf[at->pos])) {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
out:
|
||||
ret = at_get_number(at, &high);
|
||||
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -140,19 +140,16 @@ static int att_send(struct bt_conn *conn, struct net_buf *buf,
|
||||
BT_DBG("code 0x%02x", hdr->code);
|
||||
|
||||
#if defined(CONFIG_BT_SMP) && defined(CONFIG_BT_SIGNING)
|
||||
|
||||
if (hdr->code == BT_ATT_OP_SIGNED_WRITE_CMD) {
|
||||
int err;
|
||||
|
||||
err = bt_smp_sign(conn, buf);
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Error signing data");
|
||||
net_buf_unref(buf);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return bt_l2cap_send_cb(conn, BT_L2CAP_CID_ATT, buf,
|
||||
cb ? cb : att_cb(buf),
|
||||
@ -227,14 +224,11 @@ static bt_conn_tx_cb_t att_cb(struct net_buf *buf)
|
||||
switch (att_op_get_type(buf->data[0])) {
|
||||
case ATT_RESPONSE:
|
||||
return att_rsp_sent;
|
||||
|
||||
case ATT_CONFIRMATION:
|
||||
return att_cfm_sent;
|
||||
|
||||
case ATT_REQUEST:
|
||||
case ATT_INDICATION:
|
||||
return att_req_sent;
|
||||
|
||||
default:
|
||||
return att_pdu_sent;
|
||||
}
|
||||
@ -252,7 +246,6 @@ static void send_err_rsp(struct bt_conn *conn, u8_t req, u16_t handle,
|
||||
}
|
||||
|
||||
buf = bt_att_create_pdu(conn, BT_ATT_OP_ERROR_RSP, sizeof(*rsp));
|
||||
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
@ -285,7 +278,6 @@ static u8_t att_mtu_req(struct bt_att *att, struct net_buf *buf)
|
||||
}
|
||||
|
||||
pdu = bt_att_create_pdu(conn, BT_ATT_OP_MTU_RSP, sizeof(*rsp));
|
||||
|
||||
if (!pdu) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -300,21 +292,18 @@ static u8_t att_mtu_req(struct bt_att *att, struct net_buf *buf)
|
||||
(void)bt_l2cap_send_cb(conn, BT_L2CAP_CID_ATT, pdu, att_rsp_sent, NULL);
|
||||
|
||||
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 484:
|
||||
*
|
||||
* A device's Exchange MTU Request shall contain the same MTU as the
|
||||
* device's Exchange MTU Response (i.e. the MTU shall be symmetric).
|
||||
*/
|
||||
*
|
||||
* A device's Exchange MTU Request shall contain the same MTU as the
|
||||
* device's Exchange MTU Response (i.e. the MTU shall be symmetric).
|
||||
*/
|
||||
att->chan.rx.mtu = MIN(mtu_client, mtu_server);
|
||||
att->chan.tx.mtu = att->chan.rx.mtu;
|
||||
|
||||
BT_DBG("Negotiated MTU %u", att->chan.rx.mtu);
|
||||
|
||||
#if defined(BFLB_BLE_MTU_CHANGE_CB)
|
||||
|
||||
if (att->chan.chan.ops->mtu_changed) {
|
||||
if (att->chan.chan.ops->mtu_changed)
|
||||
att->chan.chan.ops->mtu_changed(&(att->chan.chan), att->chan.rx.mtu);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
@ -349,7 +338,6 @@ static int att_send_req(struct bt_att *att, struct bt_att_req *req)
|
||||
/* Keep a reference for resending in case of an error */
|
||||
err = bt_l2cap_send_cb(att->chan.chan.conn, BT_L2CAP_CID_ATT,
|
||||
net_buf_ref(req->buf), att_cb(req->buf), NULL);
|
||||
|
||||
if (err) {
|
||||
net_buf_unref(req->buf);
|
||||
req->buf = NULL;
|
||||
@ -367,7 +355,6 @@ static void att_process(struct bt_att *att)
|
||||
|
||||
/* Pull next request from the list */
|
||||
node = sys_slist_get(&att->reqs);
|
||||
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
@ -445,10 +432,10 @@ static u8_t att_mtu_rsp(struct bt_att *att, struct net_buf *buf)
|
||||
att->chan.rx.mtu = MIN(mtu, BT_ATT_MTU);
|
||||
|
||||
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 484:
|
||||
*
|
||||
* A device's Exchange MTU Request shall contain the same MTU as the
|
||||
* device's Exchange MTU Response (i.e. the MTU shall be symmetric).
|
||||
*/
|
||||
*
|
||||
* A device's Exchange MTU Request shall contain the same MTU as the
|
||||
* device's Exchange MTU Response (i.e. the MTU shall be symmetric).
|
||||
*/
|
||||
att->chan.tx.mtu = att->chan.rx.mtu;
|
||||
|
||||
BT_DBG("Negotiated MTU %u", att->chan.rx.mtu);
|
||||
@ -464,7 +451,6 @@ static bool range_is_valid(u16_t start, u16_t end, u16_t *err)
|
||||
if (err) {
|
||||
*err = 0U;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -473,7 +459,6 @@ static bool range_is_valid(u16_t start, u16_t end, u16_t *err)
|
||||
if (err) {
|
||||
*err = start;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -522,7 +507,6 @@ static u8_t find_info_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_ATT_INFO_128:
|
||||
if (attr->uuid->type != BT_UUID_TYPE_128) {
|
||||
return BT_GATT_ITER_STOP;
|
||||
@ -552,7 +536,6 @@ static u8_t att_find_info_rsp(struct bt_att *att, u16_t start_handle,
|
||||
(void)memset(&data, 0, sizeof(data));
|
||||
|
||||
data.buf = bt_att_create_pdu(conn, BT_ATT_OP_FIND_INFO_RSP, 0);
|
||||
|
||||
if (!data.buf) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -625,7 +608,6 @@ static u8_t find_type_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
attr->handle > sys_le16_to_cpu(data->group->end_handle)) {
|
||||
data->group->end_handle = sys_cpu_to_le16(attr->handle);
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_CONTINUE;
|
||||
}
|
||||
|
||||
@ -638,12 +620,11 @@ static u8_t find_type_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
|
||||
/* Read attribute value and store in the buffer */
|
||||
read = attr->read(conn, attr, uuid, sizeof(uuid), 0);
|
||||
|
||||
if (read < 0) {
|
||||
/*
|
||||
* Since we don't know if it is the service with requested UUID,
|
||||
* we cannot respond with an error to this request.
|
||||
*/
|
||||
* Since we don't know if it is the service with requested UUID,
|
||||
* we cannot respond with an error to this request.
|
||||
*/
|
||||
goto skip;
|
||||
}
|
||||
|
||||
@ -657,12 +638,10 @@ static u8_t find_type_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
BT_WARN("Unable to create UUID: size %u", data->value_len);
|
||||
goto skip;
|
||||
}
|
||||
|
||||
if (!bt_uuid_create(&ref_uuid.uuid, uuid, read)) {
|
||||
BT_WARN("Unable to create UUID: size %d", read);
|
||||
goto skip;
|
||||
}
|
||||
|
||||
if (bt_uuid_cmp(&recvd_uuid.uuid, &ref_uuid.uuid)) {
|
||||
goto skip;
|
||||
}
|
||||
@ -696,7 +675,6 @@ static u8_t att_find_type_rsp(struct bt_att *att, u16_t start_handle,
|
||||
(void)memset(&data, 0, sizeof(data));
|
||||
|
||||
data.buf = bt_att_create_pdu(conn, BT_ATT_OP_FIND_TYPE_RSP, 0);
|
||||
|
||||
if (!data.buf) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -719,21 +697,18 @@ static u8_t att_find_type_rsp(struct bt_att *att, u16_t start_handle,
|
||||
data.err);
|
||||
|
||||
#if defined(CONFIG_BT_STACK_PTS)
|
||||
|
||||
/*PTS sends a request to the iut discover all primary services it contains */
|
||||
if (event_flag == att_find_by_type_value_ind) {
|
||||
BT_PTS("rsp err : [%d] start_handle = [0x%04x]\r\n", data.err, start_handle);
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_STACK_PTS)
|
||||
|
||||
/*when PTS sends a request to the iut discover all primary services it contains, set event flag
|
||||
* to @att_find_by_type_value_ind make it easy for the user to check whether the messages is correct in the console.
|
||||
*/
|
||||
/*when PTS sends a request to the iut discover all primary services it contains, set event flag
|
||||
* to @att_find_by_type_value_ind make it easy for the user to check whether the messages is correct in the console.
|
||||
*/
|
||||
if (event_flag == att_find_by_type_value_ind) {
|
||||
u8_t i = 0;
|
||||
u8_t *req_val = (u8_t *)data.value;
|
||||
@ -742,17 +717,14 @@ static u8_t att_find_type_rsp(struct bt_att *att, u16_t start_handle,
|
||||
(void)memcpy(src, req_val, data.value_len);
|
||||
|
||||
BT_PTS("uuid = [");
|
||||
|
||||
for (i = 0; i < value_len; i++) {
|
||||
BT_PTS("%02x", src[value_len - 1 - i]);
|
||||
}
|
||||
|
||||
BT_PTS("]\r\n");
|
||||
|
||||
BT_PTS("start_handle = [0x%04x] end_handle = [0x%04x]\r\n", data.buf->data[1] | data.buf->data[2] << 8,
|
||||
data.buf->data[3] | data.buf->data[4] << 8);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
(void)bt_l2cap_send_cb(conn, BT_L2CAP_CID_ATT, data.buf, att_rsp_sent,
|
||||
@ -785,10 +757,10 @@ static u8_t att_find_type_req(struct bt_att *att, struct net_buf *buf)
|
||||
}
|
||||
|
||||
/* The Attribute Protocol Find By Type Value Request shall be used with
|
||||
* the Attribute Type parameter set to the UUID for "Primary Service"
|
||||
* and the Attribute Value set to the 16-bit Bluetooth UUID or 128-bit
|
||||
* UUID for the specific primary service.
|
||||
*/
|
||||
* the Attribute Type parameter set to the UUID for "Primary Service"
|
||||
* and the Attribute Value set to the 16-bit Bluetooth UUID or 128-bit
|
||||
* UUID for the specific primary service.
|
||||
*/
|
||||
if (bt_uuid_cmp(BT_UUID_DECLARE_16(type), BT_UUID_GATT_PRIMARY)) {
|
||||
send_err_rsp(conn, BT_ATT_OP_FIND_TYPE_REQ, start_handle,
|
||||
BT_ATT_ERR_ATTRIBUTE_NOT_FOUND);
|
||||
@ -834,29 +806,27 @@ static u8_t read_type_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
BT_DBG("handle 0x%04x", attr->handle);
|
||||
|
||||
/*
|
||||
* If an attribute in the set of requested attributes would cause an
|
||||
* Error Response then this attribute cannot be included in a
|
||||
* Read By Type Response and the attributes before this attribute
|
||||
* shall be returned
|
||||
*
|
||||
* If the first attribute in the set of requested attributes would
|
||||
* cause an Error Response then no other attributes in the requested
|
||||
* attributes can be considered.
|
||||
*/
|
||||
* If an attribute in the set of requested attributes would cause an
|
||||
* Error Response then this attribute cannot be included in a
|
||||
* Read By Type Response and the attributes before this attribute
|
||||
* shall be returned
|
||||
*
|
||||
* If the first attribute in the set of requested attributes would
|
||||
* cause an Error Response then no other attributes in the requested
|
||||
* attributes can be considered.
|
||||
*/
|
||||
data->err = bt_gatt_check_perm(conn, attr, BT_GATT_PERM_READ_MASK);
|
||||
|
||||
if (data->err) {
|
||||
if (data->rsp->len) {
|
||||
data->err = 0x00;
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
|
||||
/*
|
||||
* If any attribute is founded in handle range it means that error
|
||||
* should be changed from pre-set: attr not found error to no error.
|
||||
*/
|
||||
* If any attribute is founded in handle range it means that error
|
||||
* should be changed from pre-set: attr not found error to no error.
|
||||
*/
|
||||
data->err = 0x00;
|
||||
|
||||
/* Fast forward to next item position */
|
||||
@ -866,7 +836,6 @@ static u8_t read_type_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
/* Read attribute value and store in the buffer */
|
||||
read = attr->read(conn, attr, data->buf->data + data->buf->len,
|
||||
att->chan.tx.mtu - data->buf->len, 0);
|
||||
|
||||
if (read < 0) {
|
||||
data->err = err_to_att(read);
|
||||
return BT_GATT_ITER_STOP;
|
||||
@ -899,7 +868,6 @@ static u8_t att_read_type_rsp(struct bt_att *att, struct bt_uuid *uuid,
|
||||
|
||||
data.buf = bt_att_create_pdu(conn, BT_ATT_OP_READ_TYPE_RSP,
|
||||
sizeof(*data.rsp));
|
||||
|
||||
if (!data.buf) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -923,11 +891,8 @@ static u8_t att_read_type_rsp(struct bt_att *att, struct bt_uuid *uuid,
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_STACK_PTS)
|
||||
|
||||
if (event_flag == att_read_by_type_ind) {
|
||||
if (event_flag == att_read_by_type_ind)
|
||||
BT_PTS("handle : [0x%04x]\r\n", data.rsp->data->handle);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
(void)bt_l2cap_send_cb(conn, BT_L2CAP_CID_ATT, data.buf, att_rsp_sent,
|
||||
@ -957,7 +922,6 @@ static u8_t att_read_type_req(struct bt_att *att, struct net_buf *buf)
|
||||
|
||||
start_handle = sys_le16_to_cpu(req->start_handle);
|
||||
end_handle = sys_le16_to_cpu(req->end_handle);
|
||||
|
||||
if (!bt_uuid_create(&u.uuid, req->uuid, uuid_len)) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -994,14 +958,13 @@ static u8_t read_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
data->rsp = net_buf_add(data->buf, sizeof(*data->rsp));
|
||||
|
||||
/*
|
||||
* If any attribute is founded in handle range it means that error
|
||||
* should be changed from pre-set: invalid handle error to no error.
|
||||
*/
|
||||
* If any attribute is founded in handle range it means that error
|
||||
* should be changed from pre-set: invalid handle error to no error.
|
||||
*/
|
||||
data->err = 0x00;
|
||||
|
||||
/* Check attribute permissions */
|
||||
data->err = bt_gatt_check_perm(conn, attr, BT_GATT_PERM_READ_MASK);
|
||||
|
||||
if (data->err) {
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
@ -1009,7 +972,6 @@ static u8_t read_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
/* Read attribute value and store in the buffer */
|
||||
read = attr->read(conn, attr, data->buf->data + data->buf->len,
|
||||
att->chan.tx.mtu - data->buf->len, data->offset);
|
||||
|
||||
if (read < 0) {
|
||||
data->err = err_to_att(read);
|
||||
return BT_GATT_ITER_STOP;
|
||||
@ -1037,7 +999,6 @@ static u8_t att_read_rsp(struct bt_att *att, u8_t op, u8_t rsp, u16_t handle,
|
||||
(void)memset(&data, 0, sizeof(data));
|
||||
|
||||
data.buf = bt_att_create_pdu(conn, rsp, 0);
|
||||
|
||||
if (!data.buf) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -1105,7 +1066,6 @@ static u8_t att_read_mult_req(struct bt_att *att, struct net_buf *buf)
|
||||
(void)memset(&data, 0, sizeof(data));
|
||||
|
||||
data.buf = bt_att_create_pdu(conn, BT_ATT_OP_READ_MULT_RSP, 0);
|
||||
|
||||
if (!data.buf) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -1118,12 +1078,12 @@ static u8_t att_read_mult_req(struct bt_att *att, struct net_buf *buf)
|
||||
BT_DBG("handle 0x%04x ", handle);
|
||||
|
||||
/* An Error Response shall be sent by the server in response to
|
||||
* the Read Multiple Request [....] if a read operation is not
|
||||
* permitted on any of the Characteristic Values.
|
||||
*
|
||||
* If handle is not valid then return invalid handle error.
|
||||
* If handle is found error will be cleared by read_cb.
|
||||
*/
|
||||
* the Read Multiple Request [....] if a read operation is not
|
||||
* permitted on any of the Characteristic Values.
|
||||
*
|
||||
* If handle is not valid then return invalid handle error.
|
||||
* If handle is found error will be cleared by read_cb.
|
||||
*/
|
||||
data.err = BT_ATT_ERR_INVALID_HANDLE;
|
||||
|
||||
bt_gatt_foreach_attr(handle, handle, read_cb, &data);
|
||||
@ -1167,7 +1127,6 @@ static u8_t read_group_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
attr->handle > sys_le16_to_cpu(data->group->end_handle)) {
|
||||
data->group->end_handle = sys_cpu_to_le16(attr->handle);
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_CONTINUE;
|
||||
}
|
||||
|
||||
@ -1195,7 +1154,6 @@ static u8_t read_group_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
/* Read attribute value and store in the buffer */
|
||||
read = attr->read(conn, attr, data->buf->data + data->buf->len,
|
||||
att->chan.tx.mtu - data->buf->len, 0);
|
||||
|
||||
if (read < 0) {
|
||||
/* TODO: Handle read errors */
|
||||
return BT_GATT_ITER_STOP;
|
||||
@ -1226,7 +1184,6 @@ static u8_t att_read_group_rsp(struct bt_att *att, struct bt_uuid *uuid,
|
||||
|
||||
data.buf = bt_att_create_pdu(conn, BT_ATT_OP_READ_GROUP_RSP,
|
||||
sizeof(*data.rsp));
|
||||
|
||||
if (!data.buf) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -1289,12 +1246,12 @@ static u8_t att_read_group_req(struct bt_att *att, struct net_buf *buf)
|
||||
}
|
||||
|
||||
/* Core v4.2, Vol 3, sec 2.5.3 Attribute Grouping:
|
||||
* Not all of the grouping attributes can be used in the ATT
|
||||
* Read By Group Type Request. The "Primary Service" and "Secondary
|
||||
* Service" grouping types may be used in the Read By Group Type
|
||||
* Request. The "Characteristic" grouping type shall not be used in
|
||||
* the ATT Read By Group Type Request.
|
||||
*/
|
||||
* Not all of the grouping attributes can be used in the ATT
|
||||
* Read By Group Type Request. The "Primary Service" and "Secondary
|
||||
* Service" grouping types may be used in the Read By Group Type
|
||||
* Request. The "Characteristic" grouping type shall not be used in
|
||||
* the ATT Read By Group Type Request.
|
||||
*/
|
||||
if (bt_uuid_cmp(&u.uuid, BT_UUID_GATT_PRIMARY) &&
|
||||
bt_uuid_cmp(&u.uuid, BT_UUID_GATT_SECONDARY)) {
|
||||
send_err_rsp(conn, BT_ATT_OP_READ_GROUP_REQ, start_handle,
|
||||
@ -1326,7 +1283,6 @@ static u8_t write_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
/* Check attribute permissions */
|
||||
data->err = bt_gatt_check_perm(data->conn, attr,
|
||||
BT_GATT_PERM_WRITE_MASK);
|
||||
|
||||
if (data->err) {
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
@ -1339,7 +1295,6 @@ static u8_t write_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
/* Write attribute value */
|
||||
write = attr->write(data->conn, attr, data->value, data->len,
|
||||
data->offset, flags);
|
||||
|
||||
if (write < 0 || write != data->len) {
|
||||
data->err = err_to_att(write);
|
||||
return BT_GATT_ITER_STOP;
|
||||
@ -1369,7 +1324,6 @@ static u8_t att_write_rsp(struct bt_conn *conn, u8_t req, u8_t rsp,
|
||||
/* Only allocate buf if required to respond */
|
||||
if (rsp) {
|
||||
data.buf = bt_att_create_pdu(conn, rsp, 0);
|
||||
|
||||
if (!data.buf) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -1391,7 +1345,6 @@ static u8_t att_write_rsp(struct bt_conn *conn, u8_t req, u8_t rsp,
|
||||
/* Respond here since handle is set */
|
||||
send_err_rsp(conn, req, handle, data.err);
|
||||
}
|
||||
|
||||
return req == BT_ATT_OP_EXEC_WRITE_REQ ? data.err : 0;
|
||||
}
|
||||
|
||||
@ -1437,7 +1390,6 @@ static u8_t prep_write_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
/* Check attribute permissions */
|
||||
data->err = bt_gatt_check_perm(data->conn, attr,
|
||||
BT_GATT_PERM_WRITE_MASK);
|
||||
|
||||
if (data->err) {
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
@ -1450,7 +1402,6 @@ static u8_t prep_write_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
/* Write attribute value to check if device is authorized */
|
||||
write = attr->write(data->conn, attr, data->value, data->len,
|
||||
data->offset, BT_GATT_WRITE_FLAG_PREPARE);
|
||||
|
||||
if (write != 0) {
|
||||
data->err = err_to_att(write);
|
||||
return BT_GATT_ITER_STOP;
|
||||
@ -1459,7 +1410,6 @@ static u8_t prep_write_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||
append:
|
||||
/* Copy data into the outstanding queue */
|
||||
data->buf = net_buf_alloc(&prep_pool, K_NO_WAIT);
|
||||
|
||||
if (!data->buf) {
|
||||
data->err = BT_ATT_ERR_PREPARE_QUEUE_FULL;
|
||||
return BT_GATT_ITER_STOP;
|
||||
@ -1515,7 +1465,6 @@ static u8_t att_prep_write_rsp(struct bt_att *att, u16_t handle, u16_t offset,
|
||||
|
||||
/* Generate response */
|
||||
data.buf = bt_att_create_pdu(conn, BT_ATT_OP_PREPARE_WRITE_RSP, 0);
|
||||
|
||||
if (!data.buf) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -1570,7 +1519,6 @@ static u8_t att_exec_write_rsp(struct bt_att *att, u8_t flags)
|
||||
err = att_write_rsp(conn, BT_ATT_OP_EXEC_WRITE_REQ, 0,
|
||||
data->handle, data->offset,
|
||||
buf->data, buf->len);
|
||||
|
||||
if (err) {
|
||||
/* Respond here since handle is set */
|
||||
send_err_rsp(conn, BT_ATT_OP_EXEC_WRITE_REQ,
|
||||
@ -1587,7 +1535,6 @@ static u8_t att_exec_write_rsp(struct bt_att *att, u8_t flags)
|
||||
|
||||
/* Generate response */
|
||||
buf = bt_att_create_pdu(conn, BT_ATT_OP_EXEC_WRITE_RSP, 0);
|
||||
|
||||
if (!buf) {
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
@ -1642,7 +1589,6 @@ static u8_t att_signed_write_cmd(struct bt_att *att, struct net_buf *buf)
|
||||
/* Verifying data requires full buffer including attribute header */
|
||||
net_buf_push(buf, sizeof(struct bt_att_hdr));
|
||||
err = bt_smp_sign_verify(conn, buf);
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Error verifying data");
|
||||
/* No response for this command */
|
||||
@ -1665,58 +1611,53 @@ static int att_change_security(struct bt_conn *conn, u8_t err)
|
||||
|
||||
switch (err) {
|
||||
case BT_ATT_ERR_INSUFFICIENT_ENCRYPTION:
|
||||
if (conn->sec_level >= BT_SECURITY_L2) {
|
||||
if (conn->sec_level >= BT_SECURITY_L2)
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
sec = BT_SECURITY_L2;
|
||||
break;
|
||||
|
||||
case BT_ATT_ERR_AUTHENTICATION:
|
||||
if (conn->sec_level < BT_SECURITY_L2) {
|
||||
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part C]
|
||||
* page 375:
|
||||
*
|
||||
* If an LTK is not available, the service request
|
||||
* shall be rejected with the error code 'Insufficient
|
||||
* Authentication'.
|
||||
* Note: When the link is not encrypted, the error code
|
||||
* "Insufficient Authentication" does not indicate that
|
||||
* MITM protection is required.
|
||||
*/
|
||||
* page 375:
|
||||
*
|
||||
* If an LTK is not available, the service request
|
||||
* shall be rejected with the error code 'Insufficient
|
||||
* Authentication'.
|
||||
* Note: When the link is not encrypted, the error code
|
||||
* "Insufficient Authentication" does not indicate that
|
||||
* MITM protection is required.
|
||||
*/
|
||||
sec = BT_SECURITY_L2;
|
||||
} else if (conn->sec_level < BT_SECURITY_L3) {
|
||||
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part C]
|
||||
* page 375:
|
||||
*
|
||||
* If an authenticated pairing is required but only an
|
||||
* unauthenticated pairing has occurred and the link is
|
||||
* currently encrypted, the service request shall be
|
||||
* rejected with the error code 'Insufficient
|
||||
* Authentication'.
|
||||
* Note: When unauthenticated pairing has occurred and
|
||||
* the link is currently encrypted, the error code
|
||||
* 'Insufficient Authentication' indicates that MITM
|
||||
* protection is required.
|
||||
*/
|
||||
* page 375:
|
||||
*
|
||||
* If an authenticated pairing is required but only an
|
||||
* unauthenticated pairing has occurred and the link is
|
||||
* currently encrypted, the service request shall be
|
||||
* rejected with the error code 'Insufficient
|
||||
* Authentication'.
|
||||
* Note: When unauthenticated pairing has occurred and
|
||||
* the link is currently encrypted, the error code
|
||||
* 'Insufficient Authentication' indicates that MITM
|
||||
* protection is required.
|
||||
*/
|
||||
sec = BT_SECURITY_L3;
|
||||
} else if (conn->sec_level < BT_SECURITY_L4) {
|
||||
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part C]
|
||||
* page 375:
|
||||
*
|
||||
* If LE Secure Connections authenticated pairing is
|
||||
* required but LE legacy pairing has occurred and the
|
||||
* link is currently encrypted, the service request
|
||||
* shall be rejected with the error code ''Insufficient
|
||||
* Authentication'.
|
||||
*/
|
||||
* page 375:
|
||||
*
|
||||
* If LE Secure Connections authenticated pairing is
|
||||
* required but LE legacy pairing has occurred and the
|
||||
* link is currently encrypted, the service request
|
||||
* shall be rejected with the error code ''Insufficient
|
||||
* Authentication'.
|
||||
*/
|
||||
sec = BT_SECURITY_L4;
|
||||
} else {
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -1748,7 +1689,6 @@ static u8_t att_error_rsp(struct bt_att *att, struct net_buf *buf)
|
||||
|
||||
err = rsp->error;
|
||||
#if defined(CONFIG_BT_SMP)
|
||||
|
||||
if (att->req->retrying) {
|
||||
goto done;
|
||||
}
|
||||
@ -1759,7 +1699,6 @@ static u8_t att_error_rsp(struct bt_att *att, struct net_buf *buf)
|
||||
/* Wait security_changed: TODO: Handle fail case */
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_SMP */
|
||||
|
||||
done:
|
||||
@ -1863,7 +1802,6 @@ static u8_t att_indicate(struct bt_att *att, struct net_buf *buf)
|
||||
bt_gatt_notification(conn, handle, buf->data, buf->len);
|
||||
|
||||
buf = bt_att_create_pdu(conn, BT_ATT_OP_CONFIRM, 0);
|
||||
|
||||
if (!buf) {
|
||||
return 0;
|
||||
}
|
||||
@ -2025,14 +1963,11 @@ static att_type_t att_op_get_type(u8_t op)
|
||||
case BT_ATT_OP_PREPARE_WRITE_REQ:
|
||||
case BT_ATT_OP_EXEC_WRITE_REQ:
|
||||
return ATT_REQUEST;
|
||||
|
||||
case BT_ATT_OP_CONFIRM:
|
||||
return ATT_CONFIRMATION;
|
||||
|
||||
case BT_ATT_OP_WRITE_CMD:
|
||||
case BT_ATT_OP_SIGNED_WRITE_CMD:
|
||||
return ATT_COMMAND;
|
||||
|
||||
case BT_ATT_OP_ERROR_RSP:
|
||||
case BT_ATT_OP_MTU_RSP:
|
||||
case BT_ATT_OP_FIND_INFO_RSP:
|
||||
@ -2046,10 +1981,8 @@ static att_type_t att_op_get_type(u8_t op)
|
||||
case BT_ATT_OP_PREPARE_WRITE_RSP:
|
||||
case BT_ATT_OP_EXEC_WRITE_RSP:
|
||||
return ATT_RESPONSE;
|
||||
|
||||
case BT_ATT_OP_NOTIFY:
|
||||
return ATT_NOTIFICATION;
|
||||
|
||||
case BT_ATT_OP_INDICATE:
|
||||
return ATT_INDICATION;
|
||||
}
|
||||
@ -2086,12 +2019,10 @@ static int bt_att_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
|
||||
if (!handler) {
|
||||
BT_WARN("Unhandled ATT code 0x%02x", hdr->code);
|
||||
|
||||
if (att_op_get_type(hdr->code) != ATT_COMMAND) {
|
||||
send_err_rsp(chan->conn, hdr->code, 0,
|
||||
BT_ATT_ERR_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2134,14 +2065,12 @@ static struct bt_att *att_chan_get(struct bt_conn *conn)
|
||||
}
|
||||
|
||||
chan = bt_l2cap_le_lookup_rx_cid(conn, BT_L2CAP_CID_ATT);
|
||||
|
||||
if (!chan) {
|
||||
BT_ERR("Unable to find ATT channel");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
att = ATT_CHAN(chan);
|
||||
|
||||
if (atomic_test_bit(att->flags, ATT_DISCONNECTED)) {
|
||||
BT_WARN("ATT context flagged as disconnected");
|
||||
return NULL;
|
||||
@ -2157,7 +2086,6 @@ struct net_buf *bt_att_create_pdu(struct bt_conn *conn, u8_t op, size_t len)
|
||||
struct bt_att *att;
|
||||
|
||||
att = att_chan_get(conn);
|
||||
|
||||
if (!att) {
|
||||
return NULL;
|
||||
}
|
||||
@ -2174,7 +2102,6 @@ struct net_buf *bt_att_create_pdu(struct bt_conn *conn, u8_t op, size_t len)
|
||||
/* Use a timeout only when responding/confirming */
|
||||
buf = bt_l2cap_create_pdu_timeout(NULL, 0, ATT_TIMEOUT);
|
||||
break;
|
||||
|
||||
default:
|
||||
buf = bt_l2cap_create_pdu(NULL, 0);
|
||||
}
|
||||
@ -2197,12 +2124,10 @@ static void att_reset(struct bt_att *att)
|
||||
struct net_buf *buf;
|
||||
|
||||
#if CONFIG_BT_ATT_PREPARE_COUNT > 0
|
||||
|
||||
/* Discard queued buffers */
|
||||
while ((buf = k_fifo_get(&att->prep_queue, K_NO_WAIT))) {
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_ATT_PREPARE_COUNT > 0 */
|
||||
|
||||
while ((buf = k_fifo_get(&att->tx_queue, K_NO_WAIT))) {
|
||||
@ -2245,13 +2170,13 @@ static void att_timeout(struct k_work *work)
|
||||
BT_ERR("ATT Timeout");
|
||||
|
||||
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 480:
|
||||
*
|
||||
* A transaction not completed within 30 seconds shall time out. Such a
|
||||
* transaction shall be considered to have failed and the local higher
|
||||
* layers shall be informed of this failure. No more attribute protocol
|
||||
* requests, commands, indications or notifications shall be sent to the
|
||||
* target device on this ATT Bearer.
|
||||
*/
|
||||
*
|
||||
* A transaction not completed within 30 seconds shall time out. Such a
|
||||
* transaction shall be considered to have failed and the local higher
|
||||
* layers shall be informed of this failure. No more attribute protocol
|
||||
* requests, commands, indications or notifications shall be sent to the
|
||||
* target device on this ATT Bearer.
|
||||
*/
|
||||
att_reset(att);
|
||||
|
||||
/* Consider the channel disconnected */
|
||||
@ -2290,20 +2215,23 @@ static void bt_att_disconnected(struct bt_l2cap_chan *chan)
|
||||
bt_gatt_disconnected(ch->chan.conn);
|
||||
|
||||
#ifdef BFLB_BLE_PATCH_FREE_ALLOCATED_BUFFER_IN_OS
|
||||
|
||||
if (att->timeout_work.timer.timer.hdl) {
|
||||
if (att->timeout_work.timer.timer.hdl)
|
||||
k_delayed_work_del_timer(&att->timeout_work);
|
||||
}
|
||||
|
||||
if (att->tx_queue._queue.hdl) {
|
||||
k_queue_free(&att->tx_queue._queue);
|
||||
att->tx_queue._queue.hdl = NULL;
|
||||
}
|
||||
|
||||
if (att->tx_sem.sem.hdl) {
|
||||
k_sem_delete(&att->tx_sem);
|
||||
#if CONFIG_BT_ATT_PREPARE_COUNT > 0
|
||||
if (att->prep_queue._queue.hdl) {
|
||||
k_queue_free(&att->prep_queue._queue);
|
||||
att->prep_queue._queue.hdl = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (att->tx_sem.sem.hdl)
|
||||
k_sem_delete(&att->tx_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -2319,9 +2247,9 @@ static void bt_att_encrypt_change(struct bt_l2cap_chan *chan,
|
||||
conn, conn->handle, conn->sec_level, hci_status);
|
||||
|
||||
/*
|
||||
* If status (HCI status of security procedure) is non-zero, notify
|
||||
* outstanding request about security failure.
|
||||
*/
|
||||
* If status (HCI status of security procedure) is non-zero, notify
|
||||
* outstanding request about security failure.
|
||||
*/
|
||||
if (hci_status) {
|
||||
att_handle_rsp(att, NULL, 0, BT_ATT_ERR_AUTHENTICATION);
|
||||
return;
|
||||
@ -2338,7 +2266,6 @@ static void bt_att_encrypt_change(struct bt_l2cap_chan *chan,
|
||||
}
|
||||
|
||||
k_sem_take(&att->tx_sem, K_FOREVER);
|
||||
|
||||
if (!att_is_connected(att)) {
|
||||
BT_WARN("Disconnected");
|
||||
k_sem_give(&att->tx_sem);
|
||||
@ -2415,7 +2342,6 @@ void bt_att_init(void)
|
||||
|
||||
#if CONFIG_BT_ATT_PREPARE_COUNT > 0
|
||||
#if defined(BFLB_DYNAMIC_ALLOC_MEM)
|
||||
k_lifo_init(&prep_pool.free, CONFIG_BT_ATT_PREPARE_COUNT);
|
||||
net_buf_init(&prep_pool, CONFIG_BT_ATT_PREPARE_COUNT, BT_ATT_MTU, NULL);
|
||||
#endif
|
||||
#endif
|
||||
@ -2428,7 +2354,6 @@ u16_t bt_att_get_mtu(struct bt_conn *conn)
|
||||
struct bt_att *att;
|
||||
|
||||
att = att_chan_get(conn);
|
||||
|
||||
if (!att) {
|
||||
return 0;
|
||||
}
|
||||
@ -2447,7 +2372,6 @@ int bt_att_send(struct bt_conn *conn, struct net_buf *buf, bt_conn_tx_cb_t cb,
|
||||
__ASSERT_NO_MSG(buf);
|
||||
|
||||
att = att_chan_get(conn);
|
||||
|
||||
if (!att) {
|
||||
net_buf_unref(buf);
|
||||
return -ENOTCONN;
|
||||
@ -2463,12 +2387,10 @@ int bt_att_send(struct bt_conn *conn, struct net_buf *buf, bt_conn_tx_cb_t cb,
|
||||
}
|
||||
|
||||
err = att_send(conn, buf, cb, user_data);
|
||||
|
||||
if (err) {
|
||||
if (!cb) {
|
||||
k_sem_give(&att->tx_sem);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -2485,7 +2407,6 @@ int bt_att_req_send(struct bt_conn *conn, struct bt_att_req *req)
|
||||
__ASSERT_NO_MSG(req);
|
||||
|
||||
att = att_chan_get(conn);
|
||||
|
||||
if (!att) {
|
||||
net_buf_unref(req->buf);
|
||||
req->buf = NULL;
|
||||
@ -2513,7 +2434,6 @@ void bt_att_req_cancel(struct bt_conn *conn, struct bt_att_req *req)
|
||||
}
|
||||
|
||||
att = att_chan_get(conn);
|
||||
|
||||
if (!att) {
|
||||
return;
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ static struct bt_avdtp_event_cb *event_cb;
|
||||
|
||||
static struct bt_avdtp_seid_lsep *lseps;
|
||||
|
||||
static uint8_t tid;
|
||||
|
||||
extern struct bt_a2dp_codec_sbc_params sbc_info;
|
||||
|
||||
#define AVDTP_CHAN(_ch) CONTAINER_OF(_ch, struct bt_avdtp, br_chan.chan)
|
||||
@ -66,8 +68,7 @@ static void handle_avdtp_sec_ctrl_cmd(struct bt_avdtp *session, struct net_buf *
|
||||
static void handle_avdtp_get_all_cap_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type);
|
||||
static void handle_avdtp_dly_rpt_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type);
|
||||
|
||||
static const struct
|
||||
{
|
||||
static const struct {
|
||||
uint8_t sig_id;
|
||||
void (*func)(struct bt_avdtp *session, struct net_buf *buf,
|
||||
uint8_t msg_type);
|
||||
@ -96,7 +97,6 @@ static int avdtp_send(struct bt_avdtp *session,
|
||||
hdr = (struct bt_avdtp_single_sig_hdr *)buf->data;
|
||||
|
||||
result = bt_l2cap_chan_send(&session->br_chan.chan, buf);
|
||||
|
||||
if (result < 0) {
|
||||
BT_ERR("Error:L2CAP send fail - result = %d", result);
|
||||
return result;
|
||||
@ -118,10 +118,9 @@ static struct net_buf *avdtp_create_pdu(uint8_t msg_type,
|
||||
uint8_t sig_id)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
static uint8_t tid;
|
||||
struct bt_avdtp_single_sig_hdr *hdr;
|
||||
|
||||
BT_DBG("");
|
||||
BT_DBG("tid = %d", tid);
|
||||
|
||||
buf = bt_l2cap_create_pdu(NULL, 0);
|
||||
|
||||
@ -150,12 +149,10 @@ static void avdtp_timeout(struct k_work *work)
|
||||
static int avdtp_parsing_capability(struct net_buf *buf)
|
||||
{
|
||||
BT_DBG(" ");
|
||||
|
||||
while (buf->len) {
|
||||
uint8_t svc_cat = net_buf_pull_u8(buf);
|
||||
uint8_t cat_len = net_buf_pull_u8(buf);
|
||||
;
|
||||
|
||||
switch (svc_cat) {
|
||||
case BT_AVDTP_SERVICE_CAT_MEDIA_TRANSPORT:
|
||||
|
||||
@ -200,25 +197,20 @@ static int avdtp_parsing_capability(struct net_buf *buf)
|
||||
static void handle_avdtp_discover_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type)
|
||||
{
|
||||
BT_DBG(" ");
|
||||
|
||||
if (!session) {
|
||||
BT_DBG("Error: Session not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
struct net_buf *rsp_buf;
|
||||
|
||||
rsp_buf = avdtp_create_pdu(BT_AVDTP_ACCEPT, BT_AVDTP_PACKET_TYPE_SINGLE, BT_AVDTP_DISCOVER);
|
||||
|
||||
if (!rsp_buf) {
|
||||
BT_ERR("Error: No Buff available");
|
||||
return;
|
||||
}
|
||||
|
||||
struct bt_avdtp_seid_lsep *disc_sep = lseps;
|
||||
|
||||
uint8_t acp_endpoint[2];
|
||||
|
||||
while (disc_sep) {
|
||||
acp_endpoint[0] = disc_sep->sep.id << 2 | disc_sep->sep.inuse << 1 | disc_sep->sep.rfa0;
|
||||
acp_endpoint[1] = disc_sep->sep.media_type << 4 | disc_sep->sep.tsep << 3 | disc_sep->sep.rfa1;
|
||||
@ -229,17 +221,14 @@ static void handle_avdtp_discover_cmd(struct bt_avdtp *session, struct net_buf *
|
||||
|
||||
#if 0
|
||||
BT_DBG("rsp_buf len: %d \n", rsp_buf->len);
|
||||
|
||||
for(int i = 0; i < rsp_buf->len; i++)
|
||||
{
|
||||
BT_WARN("0x%02x, ", rsp_buf->data[i]);
|
||||
BT_WARN("0x%02x, ", rsp_buf->data[i]);
|
||||
}
|
||||
|
||||
BT_WARN("\n");
|
||||
BT_WARN("\n");
|
||||
#endif
|
||||
|
||||
int result = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
|
||||
|
||||
if (result < 0) {
|
||||
BT_ERR("Error: BT L2CAP send fail - result = %d", result);
|
||||
return;
|
||||
@ -249,16 +238,13 @@ static void handle_avdtp_discover_cmd(struct bt_avdtp *session, struct net_buf *
|
||||
static void handle_avdtp_get_cap_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type)
|
||||
{
|
||||
BT_DBG(" ");
|
||||
|
||||
if (!session) {
|
||||
BT_DBG("Error: Session not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
struct net_buf *rsp_buf;
|
||||
|
||||
rsp_buf = avdtp_create_pdu(BT_AVDTP_ACCEPT, BT_AVDTP_PACKET_TYPE_SINGLE, BT_AVDTP_GET_CAPABILITIES);
|
||||
|
||||
if (!rsp_buf) {
|
||||
BT_ERR("Error: No Buff available");
|
||||
return;
|
||||
@ -292,17 +278,14 @@ static void handle_avdtp_get_cap_cmd(struct bt_avdtp *session, struct net_buf *b
|
||||
|
||||
#if 0
|
||||
BT_DBG("rsp_buf len: %d \n", rsp_buf->len);
|
||||
|
||||
for(int i = 0; i < rsp_buf->len; i++)
|
||||
{
|
||||
BT_WARN("0x%02x, ", rsp_buf->data[i]);
|
||||
BT_WARN("0x%02x, ", rsp_buf->data[i]);
|
||||
}
|
||||
|
||||
BT_WARN("\n");
|
||||
BT_WARN("\n");
|
||||
#endif
|
||||
|
||||
int result = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
|
||||
|
||||
if (result < 0) {
|
||||
BT_ERR("Error: BT L2CAP send fail - result = %d", result);
|
||||
return;
|
||||
@ -312,7 +295,6 @@ static void handle_avdtp_get_cap_cmd(struct bt_avdtp *session, struct net_buf *b
|
||||
static void handle_avdtp_set_conf_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type)
|
||||
{
|
||||
BT_DBG(" ");
|
||||
|
||||
if (!session) {
|
||||
BT_DBG("Error: Session not valid");
|
||||
return;
|
||||
@ -325,14 +307,12 @@ static void handle_avdtp_set_conf_cmd(struct bt_avdtp *session, struct net_buf *
|
||||
|
||||
struct net_buf *rsp_buf;
|
||||
rsp_buf = avdtp_create_pdu(BT_AVDTP_ACCEPT, BT_AVDTP_PACKET_TYPE_SINGLE, BT_AVDTP_SET_CONFIGURATION);
|
||||
|
||||
if (!rsp_buf) {
|
||||
BT_ERR("Error: No Buff available");
|
||||
return;
|
||||
}
|
||||
|
||||
int result = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
|
||||
|
||||
if (result < 0) {
|
||||
BT_ERR("Error: BT L2CAP send fail - result = %d", result);
|
||||
return;
|
||||
@ -352,23 +332,19 @@ static void handle_avdtp_reconf_cmd(struct bt_avdtp *session, struct net_buf *bu
|
||||
static void handle_avdtp_open_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type)
|
||||
{
|
||||
BT_DBG(" ");
|
||||
|
||||
if (!session) {
|
||||
BT_DBG("Error: Session not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
struct net_buf *rsp_buf;
|
||||
|
||||
rsp_buf = avdtp_create_pdu(BT_AVDTP_ACCEPT, BT_AVDTP_PACKET_TYPE_SINGLE, BT_AVDTP_OPEN);
|
||||
|
||||
if (!rsp_buf) {
|
||||
BT_ERR("Error: No Buff available");
|
||||
return;
|
||||
}
|
||||
|
||||
int result = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
|
||||
|
||||
if (result < 0) {
|
||||
BT_ERR("Error: BT L2CAP send fail - result = %d", result);
|
||||
return;
|
||||
@ -378,23 +354,19 @@ static void handle_avdtp_open_cmd(struct bt_avdtp *session, struct net_buf *buf,
|
||||
static void handle_avdtp_start_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type)
|
||||
{
|
||||
BT_DBG(" ");
|
||||
|
||||
if (!session) {
|
||||
BT_DBG("Error: Session not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
struct net_buf *rsp_buf;
|
||||
|
||||
rsp_buf = avdtp_create_pdu(BT_AVDTP_ACCEPT, BT_AVDTP_PACKET_TYPE_SINGLE, BT_AVDTP_START);
|
||||
|
||||
if (!rsp_buf) {
|
||||
BT_ERR("Error: No Buff available");
|
||||
return;
|
||||
}
|
||||
|
||||
int result = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
|
||||
|
||||
if (result < 0) {
|
||||
BT_ERR("Error: BT L2CAP send fail - result = %d", result);
|
||||
return;
|
||||
@ -404,23 +376,19 @@ static void handle_avdtp_start_cmd(struct bt_avdtp *session, struct net_buf *buf
|
||||
static void handle_avdtp_close_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type)
|
||||
{
|
||||
BT_DBG(" ");
|
||||
|
||||
if (!session) {
|
||||
BT_DBG("Error: Session not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
struct net_buf *rsp_buf;
|
||||
|
||||
rsp_buf = avdtp_create_pdu(BT_AVDTP_ACCEPT, BT_AVDTP_PACKET_TYPE_SINGLE, BT_AVDTP_CLOSE);
|
||||
|
||||
if (!rsp_buf) {
|
||||
BT_ERR("Error: No Buff available");
|
||||
return;
|
||||
}
|
||||
|
||||
int result = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
|
||||
|
||||
if (result < 0) {
|
||||
BT_ERR("Error: BT L2CAP send fail - result = %d", result);
|
||||
return;
|
||||
@ -430,23 +398,19 @@ static void handle_avdtp_close_cmd(struct bt_avdtp *session, struct net_buf *buf
|
||||
static void handle_avdtp_suspend_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type)
|
||||
{
|
||||
BT_DBG(" ");
|
||||
|
||||
if (!session) {
|
||||
BT_DBG("Error: Session not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
struct net_buf *rsp_buf;
|
||||
|
||||
rsp_buf = avdtp_create_pdu(BT_AVDTP_ACCEPT, BT_AVDTP_PACKET_TYPE_SINGLE, BT_AVDTP_SUSPEND);
|
||||
|
||||
if (!rsp_buf) {
|
||||
BT_ERR("Error: No Buff available");
|
||||
return;
|
||||
}
|
||||
|
||||
int result = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
|
||||
|
||||
if (result < 0) {
|
||||
BT_ERR("Error: BT L2CAP send fail - result = %d", result);
|
||||
return;
|
||||
@ -456,23 +420,19 @@ static void handle_avdtp_suspend_cmd(struct bt_avdtp *session, struct net_buf *b
|
||||
static void handle_avdtp_abort_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t msg_type)
|
||||
{
|
||||
BT_DBG(" ");
|
||||
|
||||
if (!session) {
|
||||
BT_DBG("Error: Session not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
struct net_buf *rsp_buf;
|
||||
|
||||
rsp_buf = avdtp_create_pdu(BT_AVDTP_ACCEPT, BT_AVDTP_PACKET_TYPE_SINGLE, BT_AVDTP_ABORT);
|
||||
|
||||
if (!rsp_buf) {
|
||||
BT_ERR("Error: No Buff available");
|
||||
return;
|
||||
}
|
||||
|
||||
int result = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
|
||||
|
||||
if (result < 0) {
|
||||
BT_ERR("Error: BT L2CAP send fail - result = %d", result);
|
||||
return;
|
||||
@ -544,14 +504,12 @@ int bt_avdtp_l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
msgtype, sigid, tid);
|
||||
|
||||
#if 0
|
||||
BT_DBG("avdtp payload len: %d \n", buf->len);
|
||||
|
||||
for(int i = 0; i < buf->len; i++)
|
||||
{
|
||||
BT_WARN("0x%02x, ", buf->data[i]);
|
||||
}
|
||||
|
||||
BT_WARN("\n");
|
||||
BT_DBG("avdtp payload len: %d \n", buf->len);
|
||||
for(int i = 0; i < buf->len; i++)
|
||||
{
|
||||
BT_WARN("0x%02x, ", buf->data[i]);
|
||||
}
|
||||
BT_WARN("\n");
|
||||
#endif
|
||||
|
||||
/* validate if there is an outstanding resp expected*/
|
||||
@ -584,18 +542,15 @@ int bt_avdtp_l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
int bt_avdtp_l2cap_media_stream_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
{
|
||||
#if 0
|
||||
BT_DBG("avdtp payload len: %d \n", buf->len);
|
||||
|
||||
for(int i = 0; i < buf->len; i++)
|
||||
{
|
||||
BT_WARN("0x%02x, ", buf->data[i]);
|
||||
}
|
||||
|
||||
BT_WARN("\n");
|
||||
BT_DBG("avdtp payload len: %d \n", buf->len);
|
||||
for(int i = 0; i < buf->len; i++)
|
||||
{
|
||||
BT_WARN("0x%02x, ", buf->data[i]);
|
||||
}
|
||||
BT_WARN("\n");
|
||||
#endif
|
||||
|
||||
int res = a2dp_sbc_decode_process(buf->data, buf->len);
|
||||
|
||||
if (res) {
|
||||
BT_DBG("decode fail, error: %d \n", res);
|
||||
}
|
||||
@ -654,7 +609,6 @@ int bt_avdtp_l2cap_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
||||
BT_DBG("conn %p", conn);
|
||||
/* Get the AVDTP session from upper layer */
|
||||
result = event_cb->accept(conn, &session);
|
||||
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
@ -664,6 +618,7 @@ int bt_avdtp_l2cap_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
||||
session->br_chan.chan.ops = &ops;
|
||||
session->br_chan.rx.mtu = BT_AVDTP_MAX_MTU;
|
||||
*chan = &session->br_chan.chan;
|
||||
tid = 0;
|
||||
} else {
|
||||
BT_DBG("create l2cap_br AV stream, session %p", session);
|
||||
session->streams->chan.chan.ops = &media_ops;
|
||||
@ -728,7 +683,6 @@ int bt_avdtp_init(void)
|
||||
|
||||
/* Register AVDTP PSM with L2CAP */
|
||||
err = bt_l2cap_br_server_register(&avdtp_l2cap);
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("AVDTP L2CAP Registration failed %d", err);
|
||||
}
|
||||
@ -743,7 +697,6 @@ int bt_avdtp_discover(struct bt_avdtp *session,
|
||||
struct net_buf *buf;
|
||||
|
||||
BT_DBG("");
|
||||
|
||||
if (!param || !session) {
|
||||
BT_DBG("Error: Callback/Session not valid");
|
||||
return -EINVAL;
|
||||
@ -752,7 +705,6 @@ int bt_avdtp_discover(struct bt_avdtp *session,
|
||||
buf = avdtp_create_pdu(BT_AVDTP_CMD,
|
||||
BT_AVDTP_PACKET_TYPE_SINGLE,
|
||||
BT_AVDTP_DISCOVER);
|
||||
|
||||
if (!buf) {
|
||||
BT_ERR("Error: No Buff available");
|
||||
return -ENOMEM;
|
||||
|
@ -114,14 +114,14 @@ struct bt_avdtp_single_sig_hdr {
|
||||
|
||||
struct bt_avdtp_ind_cb {
|
||||
/*
|
||||
* discovery_ind;
|
||||
* get_capabilities_ind;
|
||||
* set_configuration_ind;
|
||||
* open_ind;
|
||||
* start_ind;
|
||||
* suspend_ind;
|
||||
* close_ind;
|
||||
*/
|
||||
* discovery_ind;
|
||||
* get_capabilities_ind;
|
||||
* set_configuration_ind;
|
||||
* open_ind;
|
||||
* start_ind;
|
||||
* suspend_ind;
|
||||
* close_ind;
|
||||
*/
|
||||
};
|
||||
|
||||
struct bt_avdtp_cap {
|
||||
|
@ -93,22 +93,18 @@ static int blhast_common_reset(void)
|
||||
if (!(bt_dev.drv->quirks & BT_QUIRK_NO_RESET)) {
|
||||
/* Send HCI_RESET */
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_RESET, NULL, &rsp);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
bt_hci_reset_complete(rsp);
|
||||
net_buf_unref(rsp);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
|
||||
err = bt_set_flow_control();
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_HCI_ACL_FLOW_CONTROL */
|
||||
|
||||
return 0;
|
||||
@ -128,7 +124,6 @@ static int blhast_ble_reset(void)
|
||||
if (BT_FEAT_BREDR(bt_dev.features)) {
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_WRITE_LE_HOST_SUPP,
|
||||
sizeof(*cp_le));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -140,7 +135,6 @@ static int blhast_ble_reset(void)
|
||||
cp_le->simul = 0x00;
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_WRITE_LE_HOST_SUPP, buf,
|
||||
NULL);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -155,7 +149,6 @@ static int blhast_ble_reset(void)
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_MAX_DATA_LEN, NULL,
|
||||
&rsp);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -167,7 +160,6 @@ static int blhast_ble_reset(void)
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN,
|
||||
sizeof(*cp));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -178,7 +170,6 @@ static int blhast_ble_reset(void)
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN,
|
||||
buf, NULL);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -198,7 +189,6 @@ static int blhast_br_reset(void)
|
||||
|
||||
/* Set SSP mode */
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_SSP_MODE, sizeof(*ssp_cp));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -206,14 +196,12 @@ static int blhast_br_reset(void)
|
||||
ssp_cp = net_buf_add(buf, sizeof(*ssp_cp));
|
||||
ssp_cp->mode = 0x01;
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_WRITE_SSP_MODE, buf, NULL);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Enable Inquiry results with RSSI or extended Inquiry */
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_INQUIRY_MODE, sizeof(*inq_cp));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -221,14 +209,12 @@ static int blhast_br_reset(void)
|
||||
inq_cp = net_buf_add(buf, sizeof(*inq_cp));
|
||||
inq_cp->mode = 0x02;
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_WRITE_INQUIRY_MODE, buf, NULL);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Set local name */
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_LOCAL_NAME, sizeof(*name_cp));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -238,14 +224,12 @@ static int blhast_br_reset(void)
|
||||
sizeof(name_cp->local_name));
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_WRITE_LOCAL_NAME, buf, NULL);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Set page timeout*/
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_PAGE_TIMEOUT, sizeof(u16_t));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -253,7 +237,6 @@ static int blhast_br_reset(void)
|
||||
net_buf_add_le16(buf, CONFIG_BT_PAGE_TIMEOUT);
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_WRITE_PAGE_TIMEOUT, buf, NULL);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -264,7 +247,6 @@ static int blhast_br_reset(void)
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_SC_HOST_SUPP,
|
||||
sizeof(*sc_cp));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -274,7 +256,6 @@ static int blhast_br_reset(void)
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_WRITE_SC_HOST_SUPP, buf,
|
||||
NULL);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -297,25 +278,20 @@ static int blhast_host_hci_reset(void)
|
||||
}
|
||||
|
||||
err = blhast_ble_reset();
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_BREDR)
|
||||
|
||||
if (BT_FEAT_BREDR(bt_dev.features)) {
|
||||
err = blhast_br_reset();
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
err = bt_set_event_mask();
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -342,24 +318,20 @@ static void blhast_host_state_restore(void)
|
||||
atomic_set_bit(bt_dev.flags, BT_DEV_ASSIST_RUN);
|
||||
|
||||
#if defined(CONFIG_BT_OBSERVER)
|
||||
|
||||
if (atomic_test_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) {
|
||||
BT_WARN("Restore BLE scan\r\n");
|
||||
atomic_clear_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN);
|
||||
atomic_clear_bit(bt_dev.flags, BT_DEV_SCANNING);
|
||||
bt_le_scan_start((const struct bt_le_scan_param *)&blhast_le_scan_param, blhast_le_scan_cb);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (atomic_test_and_clear_bit(bt_dev.flags, BT_DEV_ADVERTISING)) {
|
||||
BT_WARN("Restore BLE advertising\r\n");
|
||||
|
||||
if (blhast_le_ad.ad_len > 0) {
|
||||
ad = k_malloc(sizeof(struct bt_data) * blhast_le_ad.ad_len);
|
||||
blhast_ble_construct_ad(&blhast_le_ad, ad);
|
||||
}
|
||||
|
||||
if (blhast_le_sd.ad_len > 0) {
|
||||
sd = k_malloc(sizeof(struct bt_data) * blhast_le_sd.ad_len);
|
||||
blhast_ble_construct_ad(&blhast_le_sd, sd);
|
||||
@ -368,13 +340,10 @@ static void blhast_host_state_restore(void)
|
||||
bt_le_adv_start((const struct bt_le_adv_param *)&blhast_le_adv_param, ad,
|
||||
blhast_le_ad.ad_len, sd, blhast_le_sd.ad_len);
|
||||
|
||||
if (ad) {
|
||||
if (ad)
|
||||
k_free(ad);
|
||||
}
|
||||
|
||||
if (sd) {
|
||||
if (sd)
|
||||
k_free(sd);
|
||||
}
|
||||
}
|
||||
|
||||
atomic_clear_bit(bt_dev.flags, BT_DEV_ASSIST_RUN);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -133,8 +133,8 @@ struct bt_conn {
|
||||
/* Sent but not acknowledged TX packets with a callback */
|
||||
sys_slist_t tx_pending;
|
||||
/* Sent but not acknowledged TX packets without a callback before
|
||||
* the next packet (if any) in tx_pending.
|
||||
*/
|
||||
* the next packet (if any) in tx_pending.
|
||||
*/
|
||||
u32_t pending_no_cb;
|
||||
|
||||
/* Completed TX for which we need to call the callback */
|
||||
@ -331,11 +331,11 @@ void bt_conn_process_tx(struct bt_conn *conn);
|
||||
|
||||
#if defined(BFLB_BLE)
|
||||
/** @brief Get connection handle for a connection.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param conn_handle Place to store the Connection handle.
|
||||
*
|
||||
* @return 0 on success or negative error value on failure.
|
||||
*/
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param conn_handle Place to store the Connection handle.
|
||||
*
|
||||
* @return 0 on success or negative error value on failure.
|
||||
*/
|
||||
int bt_hci_get_conn_handle(const struct bt_conn *conn, u16_t *conn_handle);
|
||||
#endif
|
||||
|
@ -39,7 +39,6 @@ static int prng_reseed(struct tc_hmac_prng_struct *h)
|
||||
struct net_buf *rsp;
|
||||
|
||||
ret = bt_hci_cmd_send_sync(BT_HCI_OP_LE_RAND, NULL, &rsp);
|
||||
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
@ -54,7 +53,6 @@ static int prng_reseed(struct tc_hmac_prng_struct *h)
|
||||
|
||||
ret = tc_hmac_prng_reseed(h, seed, sizeof(seed), (u8_t *)&extra,
|
||||
sizeof(extra));
|
||||
|
||||
if (ret == TC_CRYPTO_FAIL) {
|
||||
BT_ERR("Failed to re-seed PRNG");
|
||||
return -EIO;
|
||||
@ -75,7 +73,6 @@ int prng_init(void)
|
||||
}
|
||||
|
||||
ret = bt_hci_cmd_send_sync(BT_HCI_OP_LE_RAND, NULL, &rsp);
|
||||
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
@ -103,10 +100,8 @@ int bt_rand(void *buf, size_t len)
|
||||
#else
|
||||
int ret;
|
||||
ret = tc_hmac_prng_generate(buf, len, &prng);
|
||||
|
||||
if (ret == TC_HMAC_PRNG_RESEED_REQ) {
|
||||
ret = prng_reseed(&prng);
|
||||
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -9,13 +9,13 @@
|
||||
/* @brief Container for public key callback */
|
||||
struct bt_pub_key_cb {
|
||||
/** @brief Callback type for Public Key generation.
|
||||
*
|
||||
* Used to notify of the local public key or that the local key is not
|
||||
* available (either because of a failure to read it or because it is
|
||||
* being regenerated).
|
||||
*
|
||||
* @param key The local public key, or NULL in case of no key.
|
||||
*/
|
||||
*
|
||||
* Used to notify of the local public key or that the local key is not
|
||||
* available (either because of a failure to read it or because it is
|
||||
* being regenerated).
|
||||
*
|
||||
* @param key The local public key, or NULL in case of no key.
|
||||
*/
|
||||
void (*func)(const u8_t key[64]);
|
||||
|
||||
struct bt_pub_key_cb *_next;
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -89,8 +89,8 @@ struct bt_dev_le {
|
||||
/* Size of the the controller resolving list */
|
||||
u8_t rl_size;
|
||||
/* Number of entries in the resolving list. rl_entries > rl_size
|
||||
* means that host-side resolving is used.
|
||||
*/
|
||||
* means that host-side resolving is used.
|
||||
*/
|
||||
u8_t rl_entries;
|
||||
#endif /* CONFIG_BT_SMP */
|
||||
|
||||
|
@ -69,8 +69,7 @@ static ATOMIC_DEFINE(flags, NUM_FLAGS);
|
||||
|
||||
static K_SEM_DEFINE(cmd_sem, 0, 1);
|
||||
|
||||
static struct
|
||||
{
|
||||
static struct {
|
||||
u8_t private_key[32];
|
||||
|
||||
union {
|
||||
@ -105,12 +104,10 @@ static void send_cmd_status(u16_t opcode, u8_t status)
|
||||
static u8_t generate_keys(void)
|
||||
{
|
||||
#if !defined(CONFIG_BT_USE_DEBUG_KEYS)
|
||||
|
||||
do {
|
||||
int rc;
|
||||
|
||||
rc = uECC_make_key(ecc.pk, ecc.private_key, &curve_secp256r1);
|
||||
|
||||
if (rc == TC_CRYPTO_FAIL) {
|
||||
BT_ERR("Failed to create ECC public/private pair");
|
||||
return BT_HCI_ERR_UNSPECIFIED;
|
||||
@ -118,7 +115,6 @@ static u8_t generate_keys(void)
|
||||
|
||||
/* make sure generated key isn't debug key */
|
||||
} while (memcmp(ecc.private_key, debug_private_key, 32) == 0);
|
||||
|
||||
#else
|
||||
sys_memcpy_swap(&ecc.pk, debug_public_key, 32);
|
||||
sys_memcpy_swap(&ecc.pk[32], &debug_public_key[32], 32);
|
||||
@ -155,8 +151,8 @@ static void emulate_le_p256_public_key_cmd(void)
|
||||
(void)memset(evt->key, 0, sizeof(evt->key));
|
||||
} else {
|
||||
/* Convert X and Y coordinates from big-endian (provided
|
||||
* by crypto API) to little endian HCI.
|
||||
*/
|
||||
* by crypto API) to little endian HCI.
|
||||
*/
|
||||
sys_memcpy_swap(evt->key, ecc.pk, 32);
|
||||
sys_memcpy_swap(&evt->key[32], &ecc.pk[32], 32);
|
||||
}
|
||||
@ -175,7 +171,6 @@ static void emulate_le_generate_dhkey(void)
|
||||
int ret;
|
||||
|
||||
ret = uECC_valid_public_key(ecc.pk, &curve_secp256r1);
|
||||
|
||||
if (ret < 0) {
|
||||
BT_ERR("public key is not valid (ret %d)", ret);
|
||||
ret = TC_CRYPTO_FAIL;
|
||||
@ -201,8 +196,8 @@ static void emulate_le_generate_dhkey(void)
|
||||
} else {
|
||||
evt->status = 0U;
|
||||
/* Convert from big-endian (provided by crypto API) to
|
||||
* little-endian HCI.
|
||||
*/
|
||||
* little-endian HCI.
|
||||
*/
|
||||
sys_memcpy_swap(evt->dhkey, ecc.dhkey, sizeof(ecc.dhkey));
|
||||
}
|
||||
|
||||
@ -227,7 +222,6 @@ static void ecc_thread(void *p1, void *p2, void *p3)
|
||||
} else {
|
||||
__ASSERT(0, "Unhandled ECC command");
|
||||
}
|
||||
|
||||
#if !defined(BFLB_BLE)
|
||||
STACK_ANALYZE("ecc stack", ecc_thread_stack);
|
||||
#endif
|
||||
@ -241,9 +235,9 @@ static void clear_ecc_events(struct net_buf *buf)
|
||||
cmd = (void *)(buf->data + sizeof(struct bt_hci_cmd_hdr));
|
||||
|
||||
/*
|
||||
* don't enable controller ECC events as those will be generated from
|
||||
* emulation code
|
||||
*/
|
||||
* don't enable controller ECC events as those will be generated from
|
||||
* emulation code
|
||||
*/
|
||||
cmd->events[0] &= ~0x80; /* LE Read Local P-256 PKey Compl */
|
||||
cmd->events[1] &= ~0x01; /* LE Generate DHKey Compl Event */
|
||||
}
|
||||
@ -270,8 +264,8 @@ static void le_gen_dhkey(struct net_buf *buf)
|
||||
|
||||
cmd = (void *)buf->data;
|
||||
/* Convert X and Y coordinates from little-endian HCI to
|
||||
* big-endian (expected by the crypto API).
|
||||
*/
|
||||
* big-endian (expected by the crypto API).
|
||||
*/
|
||||
sys_memcpy_swap(ecc.pk, cmd->key, 32);
|
||||
sys_memcpy_swap(&ecc.pk[32], &cmd->key[32], 32);
|
||||
k_sem_give(&cmd_sem);
|
||||
@ -310,16 +304,13 @@ int bt_hci_ecc_send(struct net_buf *buf)
|
||||
net_buf_pull(buf, sizeof(*chdr));
|
||||
le_p256_pub_key(buf);
|
||||
return 0;
|
||||
|
||||
case BT_HCI_OP_LE_GENERATE_DHKEY:
|
||||
net_buf_pull(buf, sizeof(*chdr));
|
||||
le_gen_dhkey(buf);
|
||||
return 0;
|
||||
|
||||
case BT_HCI_OP_LE_SET_EVENT_MASK:
|
||||
clear_ecc_events(buf);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -83,24 +83,23 @@ static struct bt_sdp_attribute hfp_attrs[] = {
|
||||
BT_SDP_ARRAY_16(0x0107) }, ) }, )),
|
||||
BT_SDP_SERVICE_NAME("hands-free"),
|
||||
/*
|
||||
"SupportedFeatures" attribute bit mapping for the HF
|
||||
bit 0: EC and/or NR function
|
||||
bit 1: Call waiting or three-way calling
|
||||
bit 2: CLI presentation capability
|
||||
bit 3: Voice recognition activation
|
||||
bit 4: Remote volume control
|
||||
bit 5: Wide band speech
|
||||
bit 6: Enhanced Voice Recognition Status
|
||||
bit 7: Voice Recognition Text
|
||||
*/
|
||||
"SupportedFeatures" attribute bit mapping for the HF
|
||||
bit 0: EC and/or NR function
|
||||
bit 1: Call waiting or three-way calling
|
||||
bit 2: CLI presentation capability
|
||||
bit 3: Voice recognition activation
|
||||
bit 4: Remote volume control
|
||||
bit 5: Wide band speech
|
||||
bit 6: Enhanced Voice Recognition Status
|
||||
bit 7: Voice Recognition Text
|
||||
*/
|
||||
BT_SDP_SUPPORTED_FEATURES(0x0035),
|
||||
};
|
||||
|
||||
static struct bt_sdp_record hfp_rec = BT_SDP_RECORD(hfp_attrs);
|
||||
|
||||
/* The order should follow the enum hfp_hf_ag_indicators */
|
||||
static const struct
|
||||
{
|
||||
static const struct {
|
||||
char *name;
|
||||
uint32_t min;
|
||||
uint32_t max;
|
||||
@ -184,7 +183,6 @@ void hf_slc_error(struct at_client *hf_at)
|
||||
|
||||
BT_ERR("SLC error: disconnecting");
|
||||
err = bt_rfcomm_dlc_disconnect(&hf->rfcomm_dlc);
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Rfcomm: Unable to disconnect :%d", -err);
|
||||
}
|
||||
@ -201,7 +199,6 @@ int hfp_hf_send_cmd(struct bt_hfp_hf *hf, at_resp_cb_t resp,
|
||||
at_register(&hf->at, resp, finish);
|
||||
|
||||
buf = bt_rfcomm_create_pdu(&hf_pool);
|
||||
|
||||
if (!buf) {
|
||||
BT_ERR("No Buffers!");
|
||||
return -ENOMEM;
|
||||
@ -209,19 +206,16 @@ int hfp_hf_send_cmd(struct bt_hfp_hf *hf, at_resp_cb_t resp,
|
||||
|
||||
va_start(vargs, format);
|
||||
ret = vsnprintf((char *)buf->data, (net_buf_tailroom(buf) - 1), format, vargs);
|
||||
|
||||
if (ret < 0) {
|
||||
BT_ERR("Unable to format variable arguments");
|
||||
return ret;
|
||||
}
|
||||
|
||||
va_end(vargs);
|
||||
|
||||
net_buf_add(buf, ret);
|
||||
net_buf_add_u8(buf, '\r');
|
||||
|
||||
ret = bt_rfcomm_dlc_send(&hf->rfcomm_dlc, buf);
|
||||
|
||||
if (ret < 0) {
|
||||
BT_ERR("Rfcomm send error :(%d)", ret);
|
||||
return ret;
|
||||
@ -237,7 +231,6 @@ int brsf_handle(struct at_client *hf_at)
|
||||
int ret;
|
||||
|
||||
ret = at_get_number(hf_at, &val);
|
||||
|
||||
if (ret < 0) {
|
||||
BT_ERR("Error getting value");
|
||||
return ret;
|
||||
@ -256,11 +249,10 @@ int brsf_resp(struct at_client *hf_at, struct net_buf *buf)
|
||||
|
||||
err = at_parse_cmd_input(hf_at, buf, "BRSF", brsf_handle,
|
||||
AT_CMD_TYPE_NORMAL);
|
||||
|
||||
if (err < 0) {
|
||||
/* Returning negative value is avoided before SLC connection
|
||||
* established.
|
||||
*/
|
||||
* established.
|
||||
*/
|
||||
BT_ERR("Error parsing CMD input");
|
||||
hf_slc_error(hf_at);
|
||||
}
|
||||
@ -280,7 +272,6 @@ static void cind_handle_values(struct at_client *hf_at, uint32_t index,
|
||||
if (strcmp(name, ag_ind[i].name) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (min != ag_ind[i].min || max != ag_ind[i].max) {
|
||||
BT_ERR("%s indicator min/max value not matching", name);
|
||||
}
|
||||
@ -346,7 +337,6 @@ int cind_resp(struct at_client *hf_at, struct net_buf *buf)
|
||||
|
||||
err = at_parse_cmd_input(hf_at, buf, "CIND", cind_handle,
|
||||
AT_CMD_TYPE_NORMAL);
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("Error parsing CMD input");
|
||||
hf_slc_error(hf_at);
|
||||
@ -380,51 +370,37 @@ void ag_indicator_handle_values(struct at_client *hf_at, uint32_t index,
|
||||
if (bt_hf->service) {
|
||||
bt_hf->service(conn, value);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HF_CALL_IND:
|
||||
if (bt_hf->call) {
|
||||
bt_hf->call(conn, value);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HF_CALL_SETUP_IND:
|
||||
if (bt_hf->call_setup) {
|
||||
bt_hf->call_setup(conn, value);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HF_CALL_HELD_IND:
|
||||
if (bt_hf->call_held) {
|
||||
bt_hf->call_held(conn, value);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HF_SINGNAL_IND:
|
||||
if (bt_hf->signal) {
|
||||
bt_hf->signal(conn, value);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HF_ROAM_IND:
|
||||
if (bt_hf->roam) {
|
||||
bt_hf->roam(conn, value);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HF_BATTERY_IND:
|
||||
if (bt_hf->battery) {
|
||||
bt_hf->battery(conn, value);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("Unknown AG indicator");
|
||||
break;
|
||||
@ -440,7 +416,6 @@ int cind_status_handle(struct at_client *hf_at)
|
||||
int ret;
|
||||
|
||||
ret = at_get_number(hf_at, &value);
|
||||
|
||||
if (ret < 0) {
|
||||
BT_ERR("could not get the value");
|
||||
return ret;
|
||||
@ -460,7 +435,6 @@ int cind_status_resp(struct at_client *hf_at, struct net_buf *buf)
|
||||
|
||||
err = at_parse_cmd_input(hf_at, buf, "CIND", cind_status_handle,
|
||||
AT_CMD_TYPE_NORMAL);
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("Error parsing CMD input");
|
||||
hf_slc_error(hf_at);
|
||||
@ -475,12 +449,10 @@ int ciev_handle(struct at_client *hf_at)
|
||||
int ret;
|
||||
|
||||
ret = at_get_number(hf_at, &index);
|
||||
|
||||
if (ret < 0) {
|
||||
BT_ERR("could not get the Index");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* The first element of the list shall have 1 */
|
||||
if (!index) {
|
||||
BT_ERR("Invalid index value '0'");
|
||||
@ -488,7 +460,6 @@ int ciev_handle(struct at_client *hf_at)
|
||||
}
|
||||
|
||||
ret = at_get_number(hf_at, &value);
|
||||
|
||||
if (ret < 0) {
|
||||
BT_ERR("could not get the value");
|
||||
return ret;
|
||||
@ -519,12 +490,10 @@ int bcs_handle(struct at_client *hf_at)
|
||||
struct bt_hfp_hf *hf = CONTAINER_OF(hf_at, struct bt_hfp_hf, at);
|
||||
|
||||
ret = at_get_number(hf_at, &value);
|
||||
|
||||
if (ret < 0) {
|
||||
BT_ERR("could not get the value");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (value == 1) {
|
||||
if (hfp_hf_send_cmd(hf, NULL, NULL, "AT+BCS=1") < 0) {
|
||||
BT_ERR("Error Sending AT+BCS=1");
|
||||
@ -571,7 +540,6 @@ int unsolicited_cb(struct at_client *hf_at, struct net_buf *buf)
|
||||
const struct unsolicited *handler;
|
||||
|
||||
handler = hfp_hf_unsol_lookup(hf_at);
|
||||
|
||||
if (!handler) {
|
||||
BT_ERR("Unhandled unsolicited response");
|
||||
return -ENOMSG;
|
||||
@ -598,16 +566,13 @@ int cmd_complete(struct at_client *hf_at, enum at_result result,
|
||||
case AT_RESULT_OK:
|
||||
cmd.type = HFP_HF_CMD_OK;
|
||||
break;
|
||||
|
||||
case AT_RESULT_ERROR:
|
||||
cmd.type = HFP_HF_CMD_ERROR;
|
||||
break;
|
||||
|
||||
case AT_RESULT_CME_ERROR:
|
||||
cmd.type = HFP_HF_CMD_CME_ERROR;
|
||||
cmd.cme = cme_err;
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("Unknown error code");
|
||||
cmd.type = HFP_HF_CMD_UNKNOWN_ERROR;
|
||||
@ -680,7 +645,6 @@ int cind_status_finish(struct at_client *hf_at, enum at_result result,
|
||||
|
||||
at_register_unsolicited(hf_at, unsolicited_cb);
|
||||
err = hfp_hf_send_cmd(hf, NULL, cmer_finish, "AT+CMER=3,0,0,1");
|
||||
|
||||
if (err < 0) {
|
||||
hf_slc_error(hf_at);
|
||||
return err;
|
||||
@ -703,7 +667,6 @@ int cind_finish(struct at_client *hf_at, enum at_result result,
|
||||
|
||||
err = hfp_hf_send_cmd(hf, cind_status_resp, cind_status_finish,
|
||||
"AT+CIND?");
|
||||
|
||||
if (err < 0) {
|
||||
hf_slc_error(hf_at);
|
||||
return err;
|
||||
@ -725,7 +688,6 @@ int bac_finish(struct at_client *hf_at, enum at_result result,
|
||||
}
|
||||
|
||||
err = hfp_hf_send_cmd(hf, cind_resp, cind_finish, "AT+CIND=?");
|
||||
|
||||
if (err < 0) {
|
||||
hf_slc_error(hf_at);
|
||||
return err;
|
||||
@ -747,7 +709,6 @@ int brsf_finish(struct at_client *hf_at, enum at_result result,
|
||||
}
|
||||
|
||||
err = hfp_hf_send_cmd(hf, NULL, bac_finish, "AT+BAC=1,2");
|
||||
|
||||
if (err < 0) {
|
||||
hf_slc_error(hf_at);
|
||||
return err;
|
||||
@ -764,7 +725,6 @@ int hf_slc_establish(struct bt_hfp_hf *hf)
|
||||
|
||||
err = hfp_hf_send_cmd(hf, brsf_resp, brsf_finish, "AT+BRSF=%u",
|
||||
hf->hf_features);
|
||||
|
||||
if (err < 0) {
|
||||
hf_slc_error(&hf->at);
|
||||
return err;
|
||||
@ -801,7 +761,6 @@ int bt_hfp_hf_send_cmd(struct bt_conn *conn, enum bt_hfp_hf_at_cmd cmd)
|
||||
}
|
||||
|
||||
hf = bt_hfp_hf_lookup_bt_conn(conn);
|
||||
|
||||
if (!hf) {
|
||||
BT_ERR("No HF connection found");
|
||||
return -ENOTCONN;
|
||||
@ -810,24 +769,18 @@ int bt_hfp_hf_send_cmd(struct bt_conn *conn, enum bt_hfp_hf_at_cmd cmd)
|
||||
switch (cmd) {
|
||||
case BT_HFP_HF_ATA:
|
||||
err = hfp_hf_send_cmd(hf, NULL, cmd_complete, "ATA");
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("Failed ATA");
|
||||
return err;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_HFP_HF_AT_CHUP:
|
||||
err = hfp_hf_send_cmd(hf, NULL, cmd_complete, "AT+CHUP");
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("Failed AT+CHUP");
|
||||
return err;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("Invalid AT Command");
|
||||
return -EINVAL;
|
||||
@ -851,7 +804,6 @@ static void hfp_hf_disconnected(struct bt_rfcomm_dlc *dlc)
|
||||
struct bt_conn *conn = dlc->session->br_chan.chan.conn;
|
||||
|
||||
BT_DBG("hf disconnected!");
|
||||
|
||||
if (bt_hf->disconnected) {
|
||||
bt_hf->disconnected(conn);
|
||||
}
|
||||
@ -913,7 +865,6 @@ int bt_hfp_hf_init(void)
|
||||
int err;
|
||||
|
||||
#if defined(BFLB_DYNAMIC_ALLOC_MEM)
|
||||
k_lifo_init(&hf_pool.free, CONFIG_BT_MAX_CONN + 1);
|
||||
net_buf_init(&hf_pool, CONFIG_BT_MAX_CONN + 1, BT_RFCOMM_BUF_SIZE(BT_HF_CLIENT_MAX_PDU), NULL);
|
||||
#endif
|
||||
|
||||
@ -928,11 +879,9 @@ int bt_hfp_hf_init(void)
|
||||
|
||||
/* Register SDP record */
|
||||
err = bt_sdp_register_service(&hfp_rec);
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("HFP regist sdp record failed");
|
||||
}
|
||||
|
||||
BT_DBG("HFP initialized successfully.");
|
||||
return err;
|
||||
}
|
||||
|
@ -96,7 +96,6 @@ void hci_iso(struct net_buf *buf)
|
||||
}
|
||||
|
||||
conn = bt_conn_lookup_handle(iso(buf)->handle);
|
||||
|
||||
if (!conn) {
|
||||
BT_ERR("Unable to find conn for handle %u", iso(buf)->handle);
|
||||
net_buf_unref(buf);
|
||||
@ -119,7 +118,6 @@ void hci_le_cis_estabilished(struct net_buf *buf)
|
||||
|
||||
/* ISO connection handles are already assigned at this point */
|
||||
conn = bt_conn_lookup_handle(handle);
|
||||
|
||||
if (!conn) {
|
||||
BT_ERR("No connection found for handle %u", handle);
|
||||
return;
|
||||
@ -146,7 +144,6 @@ int hci_le_reject_cis(uint16_t handle, uint8_t reason)
|
||||
int err;
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_REJECT_CIS, sizeof(*cp));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -156,7 +153,6 @@ int hci_le_reject_cis(uint16_t handle, uint8_t reason)
|
||||
cp->reason = reason;
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_REJECT_CIS, buf, NULL);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -171,7 +167,6 @@ int hci_le_accept_cis(uint16_t handle)
|
||||
int err;
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_ACCEPT_CIS, sizeof(*cp));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -180,7 +175,6 @@ int hci_le_accept_cis(uint16_t handle)
|
||||
cp->handle = sys_cpu_to_le16(handle);
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_ACCEPT_CIS, buf, NULL);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -201,7 +195,6 @@ void hci_le_cis_req(struct net_buf *buf)
|
||||
|
||||
/* Lookup existing connection with same handle */
|
||||
iso = bt_conn_lookup_handle(cis_handle);
|
||||
|
||||
if (iso) {
|
||||
BT_ERR("Invalid ISO handle %u", cis_handle);
|
||||
hci_le_reject_cis(cis_handle, BT_HCI_ERR_CONN_LIMIT_EXCEEDED);
|
||||
@ -211,7 +204,6 @@ void hci_le_cis_req(struct net_buf *buf)
|
||||
|
||||
/* Lookup ACL connection to attach */
|
||||
conn = bt_conn_lookup_handle(acl_handle);
|
||||
|
||||
if (!conn) {
|
||||
BT_ERR("Invalid ACL handle %u", acl_handle);
|
||||
hci_le_reject_cis(cis_handle, BT_HCI_ERR_UNKNOWN_CONN_ID);
|
||||
@ -232,7 +224,6 @@ void hci_le_cis_req(struct net_buf *buf)
|
||||
|
||||
/* Request application to accept */
|
||||
err = bt_iso_accept(iso);
|
||||
|
||||
if (err) {
|
||||
BT_DBG("App rejected ISO %d", err);
|
||||
bt_iso_cleanup(iso);
|
||||
@ -254,7 +245,6 @@ int hci_le_remove_cig(uint8_t cig_id)
|
||||
struct net_buf *buf;
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_REMOVE_CIG, sizeof(*req));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -370,7 +360,6 @@ static struct net_buf *hci_le_set_cig_params(struct bt_iso_create_param *param)
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_CIG_PARAMS,
|
||||
sizeof(*req) + sizeof(*cis) * param->num_conns);
|
||||
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
@ -401,11 +390,9 @@ static struct net_buf *hci_le_set_cig_params(struct bt_iso_create_param *param)
|
||||
case BT_ISO_CHAN_QOS_IN:
|
||||
cis->m_sdu = param->chans[i]->qos->sdu;
|
||||
break;
|
||||
|
||||
case BT_ISO_CHAN_QOS_OUT:
|
||||
cis->s_sdu = param->chans[i]->qos->sdu;
|
||||
break;
|
||||
|
||||
case BT_ISO_CHAN_QOS_INOUT:
|
||||
cis->m_sdu = param->chans[i]->qos->sdu;
|
||||
cis->s_sdu = param->chans[i]->qos->sdu;
|
||||
@ -419,7 +406,6 @@ static struct net_buf *hci_le_set_cig_params(struct bt_iso_create_param *param)
|
||||
}
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_CIG_PARAMS, buf, &rsp);
|
||||
|
||||
if (err) {
|
||||
return NULL;
|
||||
}
|
||||
@ -453,7 +439,6 @@ int bt_conn_bind_iso(struct bt_iso_create_param *param)
|
||||
}
|
||||
|
||||
conn = bt_conn_add_iso(conn);
|
||||
|
||||
if (!conn) {
|
||||
err = -ENOMEM;
|
||||
goto failed;
|
||||
@ -466,7 +451,6 @@ int bt_conn_bind_iso(struct bt_iso_create_param *param)
|
||||
}
|
||||
|
||||
rsp = hci_le_set_cig_params(param);
|
||||
|
||||
if (!rsp) {
|
||||
err = -EIO;
|
||||
goto failed;
|
||||
@ -492,7 +476,6 @@ int bt_conn_bind_iso(struct bt_iso_create_param *param)
|
||||
return 0;
|
||||
|
||||
failed:
|
||||
|
||||
for (i = 0; i < param->num_conns; i++) {
|
||||
conn = param->conns[i];
|
||||
|
||||
@ -513,7 +496,6 @@ static int hci_le_create_cis(struct bt_conn **conn, uint8_t num_conns)
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_CREATE_CIS,
|
||||
sizeof(*req) + sizeof(*cis) * num_conns);
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -557,7 +539,6 @@ int bt_conn_connect_iso(struct bt_conn **conns, uint8_t num_conns)
|
||||
}
|
||||
|
||||
err = hci_le_create_cis(conns, num_conns);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -580,7 +561,6 @@ static int hci_le_setup_iso_data_path(struct bt_conn *conn,
|
||||
int err;
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SETUP_ISO_PATH, sizeof(*cp));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -598,13 +578,11 @@ static int hci_le_setup_iso_data_path(struct bt_conn *conn,
|
||||
memcpy(cc, path->path->cc, cp->codec_config_len);
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SETUP_ISO_PATH, buf, &rsp);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
rp = (void *)rsp->data;
|
||||
|
||||
if (rp->status || (rp->handle != conn->handle)) {
|
||||
err = -EIO;
|
||||
}
|
||||
@ -622,7 +600,6 @@ static int hci_le_remove_iso_data_path(struct bt_conn *conn, uint8_t dir)
|
||||
int err;
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_REMOVE_ISO_PATH, sizeof(*cp));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
@ -632,13 +609,11 @@ static int hci_le_remove_iso_data_path(struct bt_conn *conn, uint8_t dir)
|
||||
cp->path_dir = dir;
|
||||
|
||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_REMOVE_ISO_PATH, buf, &rsp);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
rp = (void *)rsp->data;
|
||||
|
||||
if (rp->status || (rp->handle != conn->handle)) {
|
||||
err = -EIO;
|
||||
}
|
||||
@ -671,7 +646,6 @@ int bt_iso_accept(struct bt_conn *conn)
|
||||
}
|
||||
|
||||
err = iso_server->accept(conn, &chan);
|
||||
|
||||
if (err < 0) {
|
||||
BT_ERR("err %d", err);
|
||||
return err;
|
||||
@ -696,7 +670,6 @@ static int bt_iso_setup_data_path(struct bt_conn *conn)
|
||||
};
|
||||
|
||||
chan = SYS_SLIST_PEEK_HEAD_CONTAINER(&conn->channels, chan, node);
|
||||
|
||||
if (!chan) {
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -709,23 +682,19 @@ static int bt_iso_setup_data_path(struct bt_conn *conn)
|
||||
in_path.pid = in_path.path->pid;
|
||||
out_path.pid = BT_ISO_DATA_PATH_DISABLED;
|
||||
break;
|
||||
|
||||
case BT_ISO_CHAN_QOS_OUT:
|
||||
in_path.pid = BT_ISO_DATA_PATH_DISABLED;
|
||||
out_path.pid = out_path.path->pid;
|
||||
break;
|
||||
|
||||
case BT_ISO_CHAN_QOS_INOUT:
|
||||
in_path.pid = in_path.path->pid;
|
||||
out_path.pid = out_path.path->pid;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = hci_le_setup_iso_data_path(conn, &in_path);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -832,19 +801,14 @@ const char *bt_iso_chan_state_str(uint8_t state)
|
||||
switch (state) {
|
||||
case BT_ISO_DISCONNECTED:
|
||||
return "disconnected";
|
||||
|
||||
case BT_ISO_BOUND:
|
||||
return "bound";
|
||||
|
||||
case BT_ISO_CONNECT:
|
||||
return "connect";
|
||||
|
||||
case BT_ISO_CONNECTED:
|
||||
return "connected";
|
||||
|
||||
case BT_ISO_DISCONNECT:
|
||||
return "disconnect";
|
||||
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
@ -862,36 +826,27 @@ void bt_iso_chan_set_state_debug(struct bt_iso_chan *chan, uint8_t state,
|
||||
case BT_ISO_DISCONNECTED:
|
||||
/* regardless of old state always allows this state */
|
||||
break;
|
||||
|
||||
case BT_ISO_BOUND:
|
||||
if (chan->state != BT_ISO_DISCONNECTED) {
|
||||
BT_WARN("%s()%d: invalid transition", func, line);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_ISO_CONNECT:
|
||||
if (chan->state != BT_ISO_BOUND) {
|
||||
BT_WARN("%s()%d: invalid transition", func, line);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_ISO_CONNECTED:
|
||||
if (chan->state != BT_ISO_BOUND &&
|
||||
chan->state != BT_ISO_CONNECT) {
|
||||
BT_WARN("%s()%d: invalid transition", func, line);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_ISO_DISCONNECT:
|
||||
if (chan->state != BT_ISO_CONNECTED) {
|
||||
BT_WARN("%s()%d: invalid transition", func, line);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("%s()%d: unknown (%u) state was set", func, line, state);
|
||||
return;
|
||||
@ -941,7 +896,6 @@ int bt_iso_chan_bind(struct bt_conn **conns, uint8_t num_conns,
|
||||
param.chans = chans;
|
||||
|
||||
err = bt_conn_bind_iso(¶m);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -972,7 +926,6 @@ int bt_iso_chan_connect(struct bt_iso_chan **chans, uint8_t num_chans)
|
||||
}
|
||||
|
||||
err = bt_conn_connect_iso(conns, num_chans);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@ -1017,16 +970,15 @@ void bt_iso_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
|
||||
conn->handle, buf->len, flags, pb, ts);
|
||||
|
||||
/* When the PB_Flag does not equal 0b00, the fields Time_Stamp,
|
||||
* Packet_Sequence_Number, Packet_Status_Flag and ISO_SDU_Length
|
||||
* are omitted from the HCI ISO Data packet.
|
||||
*/
|
||||
* Packet_Sequence_Number, Packet_Status_Flag and ISO_SDU_Length
|
||||
* are omitted from the HCI ISO Data packet.
|
||||
*/
|
||||
switch (pb) {
|
||||
case BT_ISO_START:
|
||||
case BT_ISO_SINGLE:
|
||||
|
||||
/* The ISO_Data_Load field contains either the first fragment
|
||||
* of an SDU or a complete SDU.
|
||||
*/
|
||||
* of an SDU or a complete SDU.
|
||||
*/
|
||||
if (ts) {
|
||||
struct bt_hci_iso_ts_data_hdr *ts_hdr;
|
||||
|
||||
@ -1058,26 +1010,22 @@ void bt_iso_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
|
||||
|
||||
conn->rx = buf;
|
||||
conn->rx_len = len - buf->len;
|
||||
|
||||
if (conn->rx_len) {
|
||||
/* if conn->rx_len then package is longer than the
|
||||
* buf->len and cannot fit in a SINGLE package
|
||||
*/
|
||||
* buf->len and cannot fit in a SINGLE package
|
||||
*/
|
||||
if (pb == BT_ISO_SINGLE) {
|
||||
BT_ERR("Unexpected ISO single fragment");
|
||||
bt_conn_reset_rx_state(conn);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_ISO_CONT:
|
||||
|
||||
/* The ISO_Data_Load field contains a continuation fragment of
|
||||
* an SDU.
|
||||
*/
|
||||
* an SDU.
|
||||
*/
|
||||
if (!conn->rx) {
|
||||
BT_ERR("Unexpected ISO continuation fragment");
|
||||
net_buf_unref(buf);
|
||||
@ -1100,8 +1048,8 @@ void bt_iso_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
|
||||
|
||||
case BT_ISO_END:
|
||||
/* The ISO_Data_Load field contains the last fragment of an
|
||||
* SDU.
|
||||
*/
|
||||
* SDU.
|
||||
*/
|
||||
BT_DBG("End, len %u rx_len %u", buf->len, conn->rx_len);
|
||||
|
||||
if (!conn->rx) {
|
||||
@ -1122,7 +1070,6 @@ void bt_iso_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
|
||||
net_buf_unref(buf);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("Unexpected ISO pb flags (0x%02x)", pb);
|
||||
bt_conn_reset_rx_state(conn);
|
||||
|
@ -63,7 +63,6 @@ struct bt_keys *bt_keys_get_addr(u8_t id, const bt_addr_le_t *addr)
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST)
|
||||
|
||||
if (first_free_slot == ARRAY_SIZE(key_pool)) {
|
||||
struct bt_keys *oldest = &key_pool[0];
|
||||
|
||||
@ -76,14 +75,12 @@ struct bt_keys *bt_keys_get_addr(u8_t id, const bt_addr_le_t *addr)
|
||||
}
|
||||
|
||||
bt_unpair(oldest->id, &oldest->addr);
|
||||
|
||||
if (!bt_addr_le_cmp(&oldest->addr, BT_ADDR_LE_ANY)) {
|
||||
first_free_slot = oldest - &key_pool[0];
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */
|
||||
|
||||
if (first_free_slot < ARRAY_SIZE(key_pool)) {
|
||||
keys = &key_pool[first_free_slot];
|
||||
keys->id = id;
|
||||
@ -153,13 +150,11 @@ struct bt_keys *bt_keys_get_type(int type, u8_t id, const bt_addr_le_t *addr)
|
||||
BT_DBG("type %d %s", type, bt_addr_le_str(addr));
|
||||
|
||||
keys = bt_keys_find(type, id, addr);
|
||||
|
||||
if (keys) {
|
||||
return keys;
|
||||
}
|
||||
|
||||
keys = bt_keys_get_addr(id, addr);
|
||||
|
||||
if (!keys) {
|
||||
return NULL;
|
||||
}
|
||||
@ -240,7 +235,6 @@ bt_addr_le_t *bt_get_keys_address(u8_t id)
|
||||
bt_addr_le_t addr;
|
||||
|
||||
memset(&addr, 0, sizeof(bt_addr_le_t));
|
||||
|
||||
if (id < ARRAY_SIZE(key_pool)) {
|
||||
if (bt_addr_le_cmp(&key_pool[id].addr, &addr)) {
|
||||
return &key_pool[id].addr;
|
||||
@ -259,7 +253,6 @@ void bt_keys_add_type(struct bt_keys *keys, int type)
|
||||
void bt_keys_clear(struct bt_keys *keys)
|
||||
{
|
||||
#if defined(BFLB_BLE)
|
||||
|
||||
if (keys->keys & BT_KEYS_IRK) {
|
||||
bt_id_del(keys);
|
||||
}
|
||||
@ -332,7 +325,6 @@ int bt_keys_store(struct bt_keys *keys)
|
||||
|
||||
str = settings_str_from_bytes(keys->storage_start, BT_KEYS_STORAGE_LEN,
|
||||
val, sizeof(val));
|
||||
|
||||
if (!str) {
|
||||
BT_ERR("Unable to encode bt_keys as value");
|
||||
return -EINVAL;
|
||||
@ -350,7 +342,6 @@ int bt_keys_store(struct bt_keys *keys)
|
||||
}
|
||||
|
||||
err = settings_save_one(key, keys->storage_start, BT_KEYS_STORAGE_LEN);
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Failed to save keys (err %d)", err);
|
||||
return err;
|
||||
@ -381,7 +372,6 @@ static int keys_set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
}
|
||||
|
||||
len = read_cb(cb_arg, val, sizeof(val));
|
||||
|
||||
if (len < 0) {
|
||||
BT_ERR("Failed to read value (err %zu)", len);
|
||||
return -EINVAL;
|
||||
@ -391,7 +381,6 @@ static int keys_set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
(len) ? bt_hex(val, sizeof(val)) : "(null)");
|
||||
|
||||
err = bt_settings_decode_key(name, &addr);
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Unable to decode address %s", name);
|
||||
return -EINVAL;
|
||||
@ -407,7 +396,6 @@ static int keys_set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
|
||||
if (!len) {
|
||||
keys = bt_keys_find(BT_KEYS_ALL, id, &addr);
|
||||
|
||||
if (keys) {
|
||||
(void)memset(keys, 0, sizeof(*keys));
|
||||
BT_DBG("Cleared keys for %s", bt_addr_le_str(&addr));
|
||||
@ -420,17 +408,15 @@ static int keys_set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
}
|
||||
|
||||
keys = bt_keys_get_addr(id, &addr);
|
||||
|
||||
if (!keys) {
|
||||
BT_ERR("Failed to allocate keys for %s", bt_addr_le_str(&addr));
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (len != BT_KEYS_STORAGE_LEN) {
|
||||
do {
|
||||
/* Load shorter structure for compatibility with old
|
||||
* records format with no counter.
|
||||
*/
|
||||
* records format with no counter.
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST) &&
|
||||
len == BT_KEYS_STORAGE_LEN_COMPAT) {
|
||||
BT_WARN("Keys for %s have no aging counter",
|
||||
@ -451,11 +437,9 @@ static int keys_set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
|
||||
BT_DBG("Successfully restored keys for %s", bt_addr_le_str(&addr));
|
||||
#if IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST)
|
||||
|
||||
if (aging_counter_val < keys->aging_counter) {
|
||||
aging_counter_val = keys->aging_counter;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */
|
||||
return 0;
|
||||
}
|
||||
@ -475,16 +459,16 @@ static int keys_commit(void)
|
||||
BT_DBG("");
|
||||
|
||||
/* We do this in commit() rather than add() since add() may get
|
||||
* called multiple times for the same address, especially if
|
||||
* the keys were already removed.
|
||||
*/
|
||||
* called multiple times for the same address, especially if
|
||||
* the keys were already removed.
|
||||
*/
|
||||
bt_keys_foreach(BT_KEYS_IRK, id_add, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//SETTINGS_STATIC_HANDLER_DEFINE(bt_keys, "bt/keys", NULL, keys_set, keys_commit,
|
||||
// NULL);
|
||||
// NULL);
|
||||
|
||||
#if defined(BFLB_BLE)
|
||||
int bt_keys_load(void)
|
||||
|
@ -54,43 +54,35 @@ struct bt_keys_link_key *bt_keys_get_link_key(const bt_addr_t *addr)
|
||||
struct bt_keys_link_key *key;
|
||||
|
||||
key = bt_keys_find_link_key(addr);
|
||||
|
||||
if (key) {
|
||||
return key;
|
||||
}
|
||||
|
||||
key = bt_keys_find_link_key(BT_ADDR_ANY);
|
||||
#if 0 //IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST) //MBHJ
|
||||
if (!key) {
|
||||
int i;
|
||||
|
||||
if(!key)
|
||||
{
|
||||
int i;
|
||||
key = &key_pool[0];
|
||||
for (i = 1; i < ARRAY_SIZE(key_pool); i++) {
|
||||
struct bt_keys_link_key *current = &key_pool[i];
|
||||
|
||||
key = &key_pool[0];
|
||||
|
||||
for(i = 1; i < ARRAY_SIZE(key_pool); i++)
|
||||
{
|
||||
struct bt_keys_link_key *current = &key_pool[i];
|
||||
|
||||
if(current->aging_counter < key->aging_counter)
|
||||
{
|
||||
key = current;
|
||||
}
|
||||
}
|
||||
|
||||
if(key)
|
||||
{
|
||||
bt_keys_link_key_clear(key);
|
||||
}
|
||||
}
|
||||
if (current->aging_counter < key->aging_counter) {
|
||||
key = current;
|
||||
}
|
||||
}
|
||||
|
||||
if (key) {
|
||||
bt_keys_link_key_clear(key);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (key) {
|
||||
bt_addr_copy(&key->addr, addr);
|
||||
#if 0 //IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST) //MBHJ
|
||||
key->aging_counter = ++aging_counter_val;
|
||||
last_keys_updated = key;
|
||||
key->aging_counter = ++aging_counter_val;
|
||||
last_keys_updated = key;
|
||||
#endif
|
||||
BT_DBG("created %p for %s", key, bt_addr_str(addr));
|
||||
return key;
|
||||
@ -128,12 +120,10 @@ void bt_keys_link_key_clear_addr(const bt_addr_t *addr)
|
||||
key = &key_pool[i];
|
||||
bt_keys_link_key_clear(key);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
key = bt_keys_find_link_key(addr);
|
||||
|
||||
if (key) {
|
||||
bt_keys_link_key_clear(key);
|
||||
}
|
||||
@ -142,27 +132,22 @@ void bt_keys_link_key_clear_addr(const bt_addr_t *addr)
|
||||
void bt_keys_link_key_store(struct bt_keys_link_key *link_key)
|
||||
{
|
||||
#if 0 //MBHJ
|
||||
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
|
||||
int err;
|
||||
char key[BT_SETTINGS_KEY_MAX];
|
||||
bt_addr_le_t le_addr;
|
||||
|
||||
if(IS_ENABLED(CONFIG_BT_SETTINGS))
|
||||
{
|
||||
int err;
|
||||
char key[BT_SETTINGS_KEY_MAX];
|
||||
bt_addr_le_t le_addr;
|
||||
|
||||
le_addr.type = BT_ADDR_LE_PUBLIC;
|
||||
bt_addr_copy(&le_addr.a, &link_key->addr);
|
||||
bt_settings_encode_key(key, sizeof(key), "link_key",
|
||||
&le_addr, NULL);
|
||||
|
||||
err = settings_save_one(key, link_key->storage_start,
|
||||
BT_KEYS_LINK_KEY_STORAGE_LEN);
|
||||
|
||||
if(err)
|
||||
{
|
||||
BT_ERR("Failed to svae link key (err %d)", err);
|
||||
}
|
||||
}
|
||||
le_addr.type = BT_ADDR_LE_PUBLIC;
|
||||
bt_addr_copy(&le_addr.a, &link_key->addr);
|
||||
bt_settings_encode_key(key, sizeof(key), "link_key",
|
||||
&le_addr, NULL);
|
||||
|
||||
err = settings_save_one(key, link_key->storage_start,
|
||||
BT_KEYS_LINK_KEY_STORAGE_LEN);
|
||||
if (err) {
|
||||
BT_ERR("Failed to svae link key (err %d)", err);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -183,7 +168,6 @@ static int link_key_set(const char *name, size_t len_rd,
|
||||
}
|
||||
|
||||
len = read_cb(cb_arg, val, sizeof(val));
|
||||
|
||||
if (len < 0) {
|
||||
BT_ERR("Failed to read value (err %zu)", len);
|
||||
return -EINVAL;
|
||||
@ -193,14 +177,12 @@ static int link_key_set(const char *name, size_t len_rd,
|
||||
len ? bt_hex(val, sizeof(val)) : "(null)");
|
||||
|
||||
err = bt_settings_decode_key(name, &le_addr);
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Unable to decode address %s", name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
link_key = bt_keys_get_link_key(&le_addr.a);
|
||||
|
||||
if (len != BT_KEYS_LINK_KEY_STORAGE_LEN) {
|
||||
if (link_key) {
|
||||
bt_keys_link_key_clear(link_key);
|
||||
@ -217,11 +199,9 @@ static int link_key_set(const char *name, size_t len_rd,
|
||||
BT_DBG("Successfully restored link key for %s",
|
||||
bt_addr_le_str(&le_addr));
|
||||
#if IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST)
|
||||
|
||||
if (aging_counter_val < link_key->aging_counter) {
|
||||
aging_counter_val = link_key->aging_counter;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */
|
||||
|
||||
return 0;
|
||||
|
@ -58,8 +58,8 @@ static sys_slist_t le_channels;
|
||||
|
||||
#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
|
||||
/* Size of MTU is based on the maximum amount of data the buffer can hold
|
||||
* excluding ACL and driver headers.
|
||||
*/
|
||||
* excluding ACL and driver headers.
|
||||
*/
|
||||
#define L2CAP_MAX_LE_MPS BT_L2CAP_RX_MTU
|
||||
/* For now use MPS - SDU length to disable segmentation */
|
||||
#define L2CAP_MAX_LE_MTU (L2CAP_MAX_LE_MPS - 2)
|
||||
@ -84,7 +84,6 @@ static u8_t get_ident(void)
|
||||
static u8_t ident;
|
||||
|
||||
ident++;
|
||||
|
||||
/* handle integer overflow (0 is not valid) */
|
||||
if (!ident) {
|
||||
ident++;
|
||||
@ -110,9 +109,9 @@ static struct bt_l2cap_le_chan *l2cap_chan_alloc_cid(struct bt_conn *conn,
|
||||
u16_t cid;
|
||||
|
||||
/*
|
||||
* No action needed if there's already a CID allocated, e.g. in
|
||||
* the case of a fixed channel.
|
||||
*/
|
||||
* No action needed if there's already a CID allocated, e.g. in
|
||||
* the case of a fixed channel.
|
||||
*/
|
||||
if (ch && ch->rx.cid > 0) {
|
||||
return ch;
|
||||
}
|
||||
@ -127,7 +126,8 @@ static struct bt_l2cap_le_chan *l2cap_chan_alloc_cid(struct bt_conn *conn,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct bt_l2cap_le_chan *__l2cap_lookup_ident(struct bt_conn *conn, u16_t ident, bool remove)
|
||||
static struct bt_l2cap_le_chan *
|
||||
__l2cap_lookup_ident(struct bt_conn *conn, u16_t ident, bool remove)
|
||||
{
|
||||
struct bt_l2cap_chan *chan;
|
||||
sys_snode_t *prev = NULL;
|
||||
@ -139,7 +139,6 @@ static struct bt_l2cap_le_chan *__l2cap_lookup_ident(struct bt_conn *conn, u16_t
|
||||
sys_slist_remove(&conn->channels, prev,
|
||||
&chan->node);
|
||||
}
|
||||
|
||||
return BT_L2CAP_LE_CHAN(chan);
|
||||
}
|
||||
|
||||
@ -171,19 +170,14 @@ const char *bt_l2cap_chan_state_str(bt_l2cap_chan_state_t state)
|
||||
switch (state) {
|
||||
case BT_L2CAP_DISCONNECTED:
|
||||
return "disconnected";
|
||||
|
||||
case BT_L2CAP_CONNECT:
|
||||
return "connect";
|
||||
|
||||
case BT_L2CAP_CONFIG:
|
||||
return "config";
|
||||
|
||||
case BT_L2CAP_CONNECTED:
|
||||
return "connected";
|
||||
|
||||
case BT_L2CAP_DISCONNECT:
|
||||
return "disconnect";
|
||||
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
@ -204,37 +198,28 @@ void bt_l2cap_chan_set_state_debug(struct bt_l2cap_chan *chan,
|
||||
case BT_L2CAP_DISCONNECTED:
|
||||
/* regardless of old state always allows this state */
|
||||
break;
|
||||
|
||||
case BT_L2CAP_CONNECT:
|
||||
if (chan->state != BT_L2CAP_DISCONNECTED) {
|
||||
BT_WARN("%s()%d: invalid transition", func, line);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_L2CAP_CONFIG:
|
||||
if (chan->state != BT_L2CAP_CONNECT) {
|
||||
BT_WARN("%s()%d: invalid transition", func, line);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_L2CAP_CONNECTED:
|
||||
if (chan->state != BT_L2CAP_CONFIG &&
|
||||
chan->state != BT_L2CAP_CONNECT) {
|
||||
BT_WARN("%s()%d: invalid transition", func, line);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_L2CAP_DISCONNECT:
|
||||
if (chan->state != BT_L2CAP_CONFIG &&
|
||||
chan->state != BT_L2CAP_CONNECTED) {
|
||||
BT_WARN("%s()%d: invalid transition", func, line);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("%s()%d: unknown (%u) state was set", func, line, state);
|
||||
return;
|
||||
@ -277,11 +262,8 @@ destroy:
|
||||
}
|
||||
|
||||
#ifdef BFLB_BLE_PATCH_FREE_ALLOCATED_BUFFER_IN_OS
|
||||
|
||||
if (chan->rtx_work.timer.timer.hdl) {
|
||||
if (chan->rtx_work.timer.timer.hdl)
|
||||
k_delayed_work_del_timer(&chan->rtx_work);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -344,13 +326,11 @@ static bool l2cap_chan_add(struct bt_conn *conn, struct bt_l2cap_chan *chan,
|
||||
bt_l2cap_chan_add(conn, chan, destroy);
|
||||
|
||||
#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
|
||||
|
||||
if (L2CAP_LE_CID_IS_DYN(ch->rx.cid)) {
|
||||
k_work_init(&ch->rx_work, l2cap_rx_process);
|
||||
k_fifo_init(&ch->rx_queue, 20);
|
||||
bt_l2cap_chan_set_state(chan, BT_L2CAP_CONNECT);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
|
||||
|
||||
return true;
|
||||
@ -385,8 +365,8 @@ void bt_l2cap_connected(struct bt_conn *conn)
|
||||
ch = BT_L2CAP_LE_CHAN(chan);
|
||||
|
||||
/* Fill up remaining fixed channel context attached in
|
||||
* fchan->accept()
|
||||
*/
|
||||
* fchan->accept()
|
||||
*/
|
||||
ch->rx.cid = fchan->cid;
|
||||
ch->tx.cid = fchan->cid;
|
||||
|
||||
@ -425,11 +405,10 @@ static struct net_buf *l2cap_create_le_sig_pdu(struct net_buf *buf,
|
||||
|
||||
/* Don't wait more than the minimum RTX timeout of 2 seconds */
|
||||
buf = bt_l2cap_create_pdu_timeout(NULL, 0, K_SECONDS(2));
|
||||
|
||||
if (!buf) {
|
||||
/* If it was not possible to allocate a buffer within the
|
||||
* timeout return NULL.
|
||||
*/
|
||||
* timeout return NULL.
|
||||
*/
|
||||
BT_ERR("Unable to allocate buffer for op 0x%02x", code);
|
||||
return NULL;
|
||||
}
|
||||
@ -447,14 +426,14 @@ static void l2cap_chan_send_req(struct bt_l2cap_le_chan *chan,
|
||||
struct net_buf *buf, s32_t timeout)
|
||||
{
|
||||
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part A] page 126:
|
||||
*
|
||||
* The value of this timer is implementation-dependent but the minimum
|
||||
* initial value is 1 second and the maximum initial value is 60
|
||||
* seconds. One RTX timer shall exist for each outstanding signaling
|
||||
* request, including each Echo Request. The timer disappears on the
|
||||
* final expiration, when the response is received, or the physical
|
||||
* link is lost.
|
||||
*/
|
||||
*
|
||||
* The value of this timer is implementation-dependent but the minimum
|
||||
* initial value is 1 second and the maximum initial value is 60
|
||||
* seconds. One RTX timer shall exist for each outstanding signaling
|
||||
* request, including each Echo Request. The timer disappears on the
|
||||
* final expiration, when the response is received, or the physical
|
||||
* link is lost.
|
||||
*/
|
||||
if (timeout) {
|
||||
k_delayed_work_submit(&chan->chan.rtx_work, timeout);
|
||||
} else {
|
||||
@ -473,7 +452,6 @@ static int l2cap_le_conn_req(struct bt_l2cap_le_chan *ch)
|
||||
|
||||
buf = l2cap_create_le_sig_pdu(NULL, BT_L2CAP_LE_CONN_REQ,
|
||||
ch->chan.ident, sizeof(*req));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -560,7 +538,6 @@ static void l2cap_send_reject(struct bt_conn *conn, u8_t ident,
|
||||
|
||||
buf = l2cap_create_le_sig_pdu(NULL, BT_L2CAP_CMD_REJECT, ident,
|
||||
sizeof(*rej) + data_len);
|
||||
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
@ -618,7 +595,6 @@ static void le_conn_param_update_req(struct bt_l2cap *l2cap, u8_t ident,
|
||||
|
||||
buf = l2cap_create_le_sig_pdu(buf, BT_L2CAP_CONN_PARAM_RSP, ident,
|
||||
sizeof(*rsp));
|
||||
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
@ -626,7 +602,6 @@ static void le_conn_param_update_req(struct bt_l2cap *l2cap, u8_t ident,
|
||||
accepted = le_param_req(conn, ¶m);
|
||||
|
||||
rsp = net_buf_add(buf, sizeof(*rsp));
|
||||
|
||||
if (accepted) {
|
||||
rsp->result = sys_cpu_to_le16(BT_L2CAP_CONN_PARAM_ACCEPTED);
|
||||
} else {
|
||||
@ -757,8 +732,8 @@ static void l2cap_chan_rx_init(struct bt_l2cap_le_chan *chan)
|
||||
}
|
||||
|
||||
/* MPS shall not be bigger than MTU + 2 as the remaining bytes cannot
|
||||
* be used.
|
||||
*/
|
||||
* be used.
|
||||
*/
|
||||
chan->rx.mps = MIN(chan->rx.mtu + 2, L2CAP_MAX_LE_MPS);
|
||||
k_sem_init(&chan->rx.credits, 0, BT_UINT_MAX);
|
||||
|
||||
@ -840,20 +815,16 @@ static u16_t le_err_to_result(int err)
|
||||
switch (err) {
|
||||
case -ENOMEM:
|
||||
return BT_L2CAP_LE_ERR_NO_RESOURCES;
|
||||
|
||||
case -EACCES:
|
||||
return BT_L2CAP_LE_ERR_AUTHORIZATION;
|
||||
|
||||
case -EPERM:
|
||||
return BT_L2CAP_LE_ERR_KEY_SIZE;
|
||||
|
||||
case -ENOTSUP:
|
||||
/* This handle the cases where a fixed channel is registered but
|
||||
* for some reason (e.g. controller not suporting a feature)
|
||||
* cannot be used.
|
||||
*/
|
||||
* for some reason (e.g. controller not suporting a feature)
|
||||
* cannot be used.
|
||||
*/
|
||||
return BT_L2CAP_LE_ERR_PSM_NOT_SUPP;
|
||||
|
||||
default:
|
||||
return BT_L2CAP_LE_ERR_UNACCEPT_PARAMS;
|
||||
}
|
||||
@ -891,7 +862,6 @@ static void le_conn_req(struct bt_l2cap *l2cap, u8_t ident,
|
||||
|
||||
buf = l2cap_create_le_sig_pdu(buf, BT_L2CAP_LE_CONN_RSP, ident,
|
||||
sizeof(*rsp));
|
||||
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
@ -901,20 +871,17 @@ static void le_conn_req(struct bt_l2cap *l2cap, u8_t ident,
|
||||
|
||||
/* Check if there is a server registered */
|
||||
server = l2cap_server_lookup_psm(psm);
|
||||
|
||||
if (!server) {
|
||||
rsp->result = sys_cpu_to_le16(BT_L2CAP_LE_ERR_PSM_NOT_SUPP);
|
||||
goto rsp;
|
||||
}
|
||||
|
||||
/* Check if connection has minimum required security level */
|
||||
/* Check if connection has minimum required security level */
|
||||
#if defined(CONFIG_BT_SMP)
|
||||
|
||||
if (conn->sec_level < server->sec_level) {
|
||||
rsp->result = sys_cpu_to_le16(BT_L2CAP_LE_ERR_AUTHENTICATION);
|
||||
goto rsp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (!L2CAP_LE_CID_IS_DYN(scid)) {
|
||||
@ -923,17 +890,15 @@ static void le_conn_req(struct bt_l2cap *l2cap, u8_t ident,
|
||||
}
|
||||
|
||||
chan = bt_l2cap_le_lookup_tx_cid(conn, scid);
|
||||
|
||||
if (chan) {
|
||||
rsp->result = sys_cpu_to_le16(BT_L2CAP_LE_ERR_SCID_IN_USE);
|
||||
goto rsp;
|
||||
}
|
||||
|
||||
/* Request server to accept the new connection and allocate the
|
||||
* channel.
|
||||
*/
|
||||
* channel.
|
||||
*/
|
||||
err = server->accept(conn, &chan);
|
||||
|
||||
if (err < 0) {
|
||||
rsp->result = sys_cpu_to_le16(le_err_to_result(err));
|
||||
goto rsp;
|
||||
@ -975,7 +940,6 @@ static void le_conn_req(struct bt_l2cap *l2cap, u8_t ident,
|
||||
} else {
|
||||
rsp->result = sys_cpu_to_le16(BT_L2CAP_LE_ERR_NO_RESOURCES);
|
||||
}
|
||||
|
||||
rsp:
|
||||
bt_l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf);
|
||||
}
|
||||
@ -1023,7 +987,6 @@ static void le_disconn_req(struct bt_l2cap *l2cap, u8_t ident,
|
||||
BT_DBG("dcid 0x%04x scid 0x%04x", dcid, sys_le16_to_cpu(req->scid));
|
||||
|
||||
chan = l2cap_remove_rx_cid(conn, dcid);
|
||||
|
||||
if (!chan) {
|
||||
struct bt_l2cap_cmd_reject_cid_data data;
|
||||
|
||||
@ -1037,7 +1000,6 @@ static void le_disconn_req(struct bt_l2cap *l2cap, u8_t ident,
|
||||
|
||||
buf = l2cap_create_le_sig_pdu(buf, BT_L2CAP_DISCONN_RSP, ident,
|
||||
sizeof(*rsp));
|
||||
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
@ -1059,10 +1021,8 @@ static int l2cap_change_security(struct bt_l2cap_le_chan *chan, u16_t err)
|
||||
if (chan->chan.required_sec_level >= BT_SECURITY_L2) {
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
chan->chan.required_sec_level = BT_SECURITY_L2;
|
||||
break;
|
||||
|
||||
case BT_L2CAP_LE_ERR_AUTHENTICATION:
|
||||
if (chan->chan.required_sec_level < BT_SECURITY_L2) {
|
||||
chan->chan.required_sec_level = BT_SECURITY_L2;
|
||||
@ -1073,9 +1033,7 @@ static int l2cap_change_security(struct bt_l2cap_le_chan *chan, u16_t err)
|
||||
} else {
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -1145,20 +1103,16 @@ static void le_conn_rsp(struct bt_l2cap *l2cap, u8_t ident,
|
||||
l2cap_chan_rx_give_credits(chan, chan->rx.init_credits);
|
||||
|
||||
break;
|
||||
|
||||
case BT_L2CAP_LE_ERR_AUTHENTICATION:
|
||||
case BT_L2CAP_LE_ERR_ENCRYPTION:
|
||||
#if defined(CONFIG_BT_SMP)
|
||||
|
||||
/* If security needs changing wait it to be completed */
|
||||
if (l2cap_change_security(chan, result) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
bt_l2cap_chan_remove(conn, &chan->chan);
|
||||
__attribute__((fallthrough));
|
||||
|
||||
default:
|
||||
bt_l2cap_chan_del(&chan->chan);
|
||||
}
|
||||
@ -1182,7 +1136,6 @@ static void le_disconn_rsp(struct bt_l2cap *l2cap, u8_t ident,
|
||||
BT_DBG("dcid 0x%04x scid 0x%04x", sys_le16_to_cpu(rsp->dcid), scid);
|
||||
|
||||
chan = l2cap_remove_rx_cid(conn, scid);
|
||||
|
||||
if (!chan) {
|
||||
return;
|
||||
}
|
||||
@ -1197,7 +1150,6 @@ static inline struct net_buf *l2cap_alloc_seg(struct net_buf *buf)
|
||||
|
||||
/* Try to use original pool if possible */
|
||||
seg = net_buf_alloc(pool, K_NO_WAIT);
|
||||
|
||||
if (seg) {
|
||||
net_buf_reserve(seg, BT_L2CAP_CHAN_SEND_RESERVE);
|
||||
return seg;
|
||||
@ -1223,20 +1175,18 @@ static struct net_buf *l2cap_chan_create_seg(struct bt_l2cap_le_chan *ch,
|
||||
headroom = BT_L2CAP_CHAN_SEND_RESERVE + sdu_hdr_len;
|
||||
|
||||
/* Check if original buffer has enough headroom and don't have any
|
||||
* fragments.
|
||||
*/
|
||||
* fragments.
|
||||
*/
|
||||
if (net_buf_headroom(buf) >= headroom && !buf->frags) {
|
||||
if (sdu_hdr_len) {
|
||||
/* Push SDU length if set */
|
||||
net_buf_push_le16(buf, net_buf_frags_len(buf));
|
||||
}
|
||||
|
||||
return net_buf_ref(buf);
|
||||
}
|
||||
|
||||
segment:
|
||||
seg = l2cap_alloc_seg(buf);
|
||||
|
||||
if (!seg) {
|
||||
return NULL;
|
||||
}
|
||||
@ -1281,7 +1231,6 @@ static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, struct net_buf *buf,
|
||||
}
|
||||
|
||||
seg = l2cap_chan_create_seg(ch, buf, sdu_hdr_len);
|
||||
|
||||
if (!seg) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -1298,8 +1247,8 @@ static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, struct net_buf *buf,
|
||||
len = seg->len - sdu_hdr_len;
|
||||
|
||||
/* Set a callback if there is no data left in the buffer and sent
|
||||
* callback has been set.
|
||||
*/
|
||||
* callback has been set.
|
||||
*/
|
||||
if ((buf == seg || !buf->len) && ch->chan.ops->sent) {
|
||||
bt_l2cap_send_cb(ch->chan.conn, ch->tx.cid, seg,
|
||||
l2cap_chan_sdu_sent, &ch->chan);
|
||||
@ -1308,11 +1257,10 @@ static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, struct net_buf *buf,
|
||||
}
|
||||
|
||||
/* Check if there is no credits left clear output status and notify its
|
||||
* change.
|
||||
*/
|
||||
* change.
|
||||
*/
|
||||
if (!k_sem_count_get(&ch->tx.credits)) {
|
||||
atomic_clear_bit(ch->chan.status, BT_L2CAP_STATUS_OUT);
|
||||
|
||||
if (ch->chan.ops->status) {
|
||||
ch->chan.ops->status(&ch->chan, ch->chan.status);
|
||||
}
|
||||
@ -1334,7 +1282,6 @@ static int l2cap_chan_le_send_sdu(struct bt_l2cap_le_chan *ch,
|
||||
}
|
||||
|
||||
frag = *buf;
|
||||
|
||||
if (!frag->len && frag->frags) {
|
||||
frag = frag->frags;
|
||||
}
|
||||
@ -1342,18 +1289,15 @@ static int l2cap_chan_le_send_sdu(struct bt_l2cap_le_chan *ch,
|
||||
if (!sent) {
|
||||
/* Add SDU length for the first segment */
|
||||
ret = l2cap_chan_le_send(ch, frag, BT_L2CAP_SDU_HDR_LEN);
|
||||
|
||||
if (ret < 0) {
|
||||
if (ret == -EAGAIN) {
|
||||
/* Store sent data into user_data */
|
||||
memcpy(net_buf_user_data(frag), &sent,
|
||||
sizeof(sent));
|
||||
}
|
||||
|
||||
*buf = frag;
|
||||
return ret;
|
||||
}
|
||||
|
||||
sent = ret;
|
||||
}
|
||||
|
||||
@ -1365,14 +1309,12 @@ static int l2cap_chan_le_send_sdu(struct bt_l2cap_le_chan *ch,
|
||||
}
|
||||
|
||||
ret = l2cap_chan_le_send(ch, frag, 0);
|
||||
|
||||
if (ret < 0) {
|
||||
if (ret == -EAGAIN) {
|
||||
/* Store sent data into user_data */
|
||||
memcpy(net_buf_user_data(frag), &sent,
|
||||
sizeof(sent));
|
||||
}
|
||||
|
||||
*buf = frag;
|
||||
return ret;
|
||||
}
|
||||
@ -1415,12 +1357,10 @@ static void l2cap_chan_le_send_resume(struct bt_l2cap_le_chan *ch)
|
||||
BT_DBG("buf %p sent %u", buf, sent);
|
||||
|
||||
sent = l2cap_chan_le_send_sdu(ch, &buf, sent);
|
||||
|
||||
if (sent < 0) {
|
||||
if (sent == -EAGAIN) {
|
||||
ch->tx_buf = buf;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1446,7 +1386,6 @@ static void le_credits(struct bt_l2cap *l2cap, u8_t ident,
|
||||
BT_DBG("cid 0x%04x credits %u", cid, credits);
|
||||
|
||||
chan = bt_l2cap_le_lookup_tx_cid(conn, cid);
|
||||
|
||||
if (!chan) {
|
||||
BT_ERR("Unable to find channel of LE Credits packet");
|
||||
return;
|
||||
@ -1476,7 +1415,6 @@ static void reject_cmd(struct bt_l2cap *l2cap, u8_t ident,
|
||||
|
||||
/* Check if there is a outstanding channel */
|
||||
chan = l2cap_remove_ident(conn, ident);
|
||||
|
||||
if (!chan) {
|
||||
return;
|
||||
}
|
||||
@ -1517,43 +1455,34 @@ static int l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
le_conn_param_rsp(l2cap, buf);
|
||||
break;
|
||||
#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
|
||||
|
||||
case BT_L2CAP_LE_CONN_REQ:
|
||||
le_conn_req(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_LE_CONN_RSP:
|
||||
le_conn_rsp(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_DISCONN_REQ:
|
||||
le_disconn_req(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_DISCONN_RSP:
|
||||
le_disconn_rsp(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_LE_CREDITS:
|
||||
le_credits(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_CMD_REJECT:
|
||||
reject_cmd(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
#else
|
||||
|
||||
case BT_L2CAP_CMD_REJECT:
|
||||
/* Ignored */
|
||||
break;
|
||||
#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
|
||||
|
||||
case BT_L2CAP_CONN_PARAM_REQ:
|
||||
if (IS_ENABLED(CONFIG_BT_CENTRAL)) {
|
||||
le_conn_param_update_req(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(BFLB_BLE)
|
||||
__attribute__((fallthrough));
|
||||
#endif
|
||||
@ -1584,7 +1513,6 @@ static void l2cap_chan_send_credits(struct bt_l2cap_le_chan *chan,
|
||||
|
||||
buf = l2cap_create_le_sig_pdu(buf, BT_L2CAP_LE_CREDITS, get_ident(),
|
||||
sizeof(*ev));
|
||||
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
@ -1608,7 +1536,6 @@ static void l2cap_chan_update_credits(struct bt_l2cap_le_chan *chan,
|
||||
(chan->rx.mps - 1)) /
|
||||
chan->rx.mps;
|
||||
credits -= k_sem_count_get(&chan->rx.credits);
|
||||
|
||||
if (credits <= 0) {
|
||||
return;
|
||||
}
|
||||
@ -1651,7 +1578,6 @@ static struct net_buf *l2cap_alloc_frag(s32_t timeout, void *user_data)
|
||||
struct net_buf *frag = NULL;
|
||||
|
||||
frag = chan->chan.ops->alloc_buf(&chan->chan);
|
||||
|
||||
if (!frag) {
|
||||
return NULL;
|
||||
}
|
||||
@ -1670,14 +1596,12 @@ static void l2cap_chan_le_recv_sdu(struct bt_l2cap_le_chan *chan,
|
||||
|
||||
/* Receiving complete SDU, notify channel and reset SDU buf */
|
||||
err = chan->chan.ops->recv(&chan->chan, buf);
|
||||
|
||||
if (err < 0) {
|
||||
if (err != -EINPROGRESS) {
|
||||
BT_ERR("err %d", err);
|
||||
bt_l2cap_chan_disconnect(&chan->chan);
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1692,7 +1616,6 @@ static void l2cap_chan_le_recv_seg(struct bt_l2cap_le_chan *chan,
|
||||
u16_t seg = 0U;
|
||||
|
||||
len = net_buf_frags_len(chan->_sdu);
|
||||
|
||||
if (len) {
|
||||
memcpy(&seg, net_buf_user_data(chan->_sdu), sizeof(seg));
|
||||
}
|
||||
@ -1712,7 +1635,6 @@ static void l2cap_chan_le_recv_seg(struct bt_l2cap_le_chan *chan,
|
||||
/* Append received segment to SDU */
|
||||
len = net_buf_append_bytes(chan->_sdu, buf->len, buf->data, K_NO_WAIT,
|
||||
l2cap_alloc_frag, chan);
|
||||
|
||||
if (len != buf->len) {
|
||||
BT_ERR("Unable to store SDU");
|
||||
bt_l2cap_chan_disconnect(&chan->chan);
|
||||
@ -1721,14 +1643,13 @@ static void l2cap_chan_le_recv_seg(struct bt_l2cap_le_chan *chan,
|
||||
|
||||
if (net_buf_frags_len(chan->_sdu) < chan->_sdu_len) {
|
||||
/* Give more credits if remote has run out of them, this
|
||||
* should only happen if the remote cannot fully utilize the
|
||||
* MPS for some reason.
|
||||
*/
|
||||
* should only happen if the remote cannot fully utilize the
|
||||
* MPS for some reason.
|
||||
*/
|
||||
if (!k_sem_count_get(&chan->rx.credits) &&
|
||||
seg == chan->rx.init_credits) {
|
||||
l2cap_chan_update_credits(chan, buf);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1770,26 +1691,22 @@ static void l2cap_chan_le_recv(struct bt_l2cap_le_chan *chan,
|
||||
/* Always allocate buffer from the channel if supported. */
|
||||
if (chan->chan.ops->alloc_buf) {
|
||||
chan->_sdu = chan->chan.ops->alloc_buf(&chan->chan);
|
||||
|
||||
if (!chan->_sdu) {
|
||||
BT_ERR("Unable to allocate buffer for SDU");
|
||||
bt_l2cap_chan_disconnect(&chan->chan);
|
||||
return;
|
||||
}
|
||||
|
||||
chan->_sdu_len = sdu_len;
|
||||
l2cap_chan_le_recv_seg(chan, buf);
|
||||
return;
|
||||
}
|
||||
|
||||
err = chan->chan.ops->recv(&chan->chan, buf);
|
||||
|
||||
if (err) {
|
||||
if (err != -EINPROGRESS) {
|
||||
BT_ERR("err %d", err);
|
||||
bt_l2cap_chan_disconnect(&chan->chan);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1807,7 +1724,6 @@ static void l2cap_chan_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
k_work_submit(&ch->rx_work);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
|
||||
|
||||
BT_DBG("chan %p len %u", chan, buf->len);
|
||||
@ -1840,7 +1756,6 @@ void bt_l2cap_recv(struct bt_conn *conn, struct net_buf *buf)
|
||||
BT_DBG("Packet for CID %u len %u", cid, buf->len);
|
||||
|
||||
chan = bt_l2cap_le_lookup_rx_cid(conn, cid);
|
||||
|
||||
if (!chan) {
|
||||
BT_WARN("Ignoring data for unknown CID 0x%04x", cid);
|
||||
net_buf_unref(buf);
|
||||
@ -1858,7 +1773,6 @@ int bt_l2cap_update_conn_param(struct bt_conn *conn,
|
||||
|
||||
buf = l2cap_create_le_sig_pdu(NULL, BT_L2CAP_CONN_PARAM_REQ,
|
||||
get_ident(), sizeof(*req));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -1927,7 +1841,6 @@ void bt_l2cap_init(void)
|
||||
|
||||
bt_l2cap_le_fixed_chan_register(&chan);
|
||||
#endif
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_BREDR)) {
|
||||
bt_l2cap_br_init();
|
||||
}
|
||||
@ -2005,7 +1918,6 @@ int bt_l2cap_chan_disconnect(struct bt_l2cap_chan *chan)
|
||||
|
||||
buf = l2cap_create_le_sig_pdu(NULL, BT_L2CAP_DISCONN_REQ,
|
||||
ch->chan.ident, sizeof(*req));
|
||||
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -2040,14 +1952,12 @@ int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
}
|
||||
|
||||
err = l2cap_chan_le_send_sdu(BT_L2CAP_LE_CHAN(chan), &buf, 0);
|
||||
|
||||
if (err < 0) {
|
||||
if (err == -EAGAIN) {
|
||||
/* Queue buffer to be sent later */
|
||||
net_buf_put(&(BT_L2CAP_LE_CHAN(chan))->tx_queue, buf);
|
||||
return *((u16_t *)net_buf_user_data(buf));
|
||||
}
|
||||
|
||||
BT_ERR("failed to send message %d", err);
|
||||
}
|
||||
|
||||
|
@ -124,23 +124,24 @@ struct bt_l2cap_chan *bt_l2cap_br_lookup_tx_cid(struct bt_conn *conn,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct bt_l2cap_br_chan *l2cap_br_chan_alloc_cid(struct bt_conn *conn, struct bt_l2cap_chan *chan)
|
||||
static struct bt_l2cap_br_chan *
|
||||
l2cap_br_chan_alloc_cid(struct bt_conn *conn, struct bt_l2cap_chan *chan)
|
||||
{
|
||||
struct bt_l2cap_br_chan *ch = BR_CHAN(chan);
|
||||
uint16_t cid;
|
||||
|
||||
/*
|
||||
* No action needed if there's already a CID allocated, e.g. in
|
||||
* the case of a fixed channel.
|
||||
*/
|
||||
* No action needed if there's already a CID allocated, e.g. in
|
||||
* the case of a fixed channel.
|
||||
*/
|
||||
if (ch->rx.cid > 0) {
|
||||
return ch;
|
||||
}
|
||||
|
||||
/*
|
||||
* L2CAP_BR_CID_DYN_END is 0xffff so we don't check against it since
|
||||
* cid is uint16_t, just check against uint16_t overflow
|
||||
*/
|
||||
* L2CAP_BR_CID_DYN_END is 0xffff so we don't check against it since
|
||||
* cid is uint16_t, just check against uint16_t overflow
|
||||
*/
|
||||
for (cid = L2CAP_BR_CID_DYN_START; cid; cid++) {
|
||||
if (!bt_l2cap_br_lookup_rx_cid(conn, cid)) {
|
||||
ch->rx.cid = cid;
|
||||
@ -187,12 +188,10 @@ static void l2cap_br_rtx_timeout(struct k_work *work)
|
||||
case BT_L2CAP_CONFIG:
|
||||
bt_l2cap_br_chan_disconnect(&chan->chan);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_DISCONNECT:
|
||||
case BT_L2CAP_CONNECT:
|
||||
l2cap_br_chan_cleanup(&chan->chan);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -219,7 +218,6 @@ static uint8_t l2cap_br_get_ident(void)
|
||||
static uint8_t ident;
|
||||
|
||||
ident++;
|
||||
|
||||
/* handle integer overflow (0 is not valid) */
|
||||
if (!ident) {
|
||||
ident++;
|
||||
@ -232,14 +230,14 @@ static void l2cap_br_chan_send_req(struct bt_l2cap_br_chan *chan,
|
||||
struct net_buf *buf, s32_t timeout)
|
||||
{
|
||||
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part A] page 126:
|
||||
*
|
||||
* The value of this timer is implementation-dependent but the minimum
|
||||
* initial value is 1 second and the maximum initial value is 60
|
||||
* seconds. One RTX timer shall exist for each outstanding signaling
|
||||
* request, including each Echo Request. The timer disappears on the
|
||||
* final expiration, when the response is received, or the physical
|
||||
* link is lost.
|
||||
*/
|
||||
*
|
||||
* The value of this timer is implementation-dependent but the minimum
|
||||
* initial value is 1 second and the maximum initial value is 60
|
||||
* seconds. One RTX timer shall exist for each outstanding signaling
|
||||
* request, including each Echo Request. The timer disappears on the
|
||||
* final expiration, when the response is received, or the physical
|
||||
* link is lost.
|
||||
*/
|
||||
k_delayed_work_submit(&chan->chan.rtx_work, timeout);
|
||||
|
||||
bt_l2cap_send(chan->chan.conn, BT_L2CAP_CID_BR_SIG, buf);
|
||||
@ -261,7 +259,6 @@ static void l2cap_br_get_info(struct bt_l2cap_br *l2cap, uint16_t info_type)
|
||||
case BT_L2CAP_INFO_FEAT_MASK:
|
||||
case BT_L2CAP_INFO_FIXED_CHAN:
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_WARN("Unsupported info type %u", info_type);
|
||||
return;
|
||||
@ -302,7 +299,6 @@ static void connect_optional_fixed_channels(struct bt_l2cap_br *l2cap)
|
||||
|
||||
chan = bt_l2cap_br_lookup_rx_cid(l2cap->chan.chan.conn,
|
||||
BT_L2CAP_CID_BR_SMP);
|
||||
|
||||
if (chan) {
|
||||
connect_fixed_channel(BR_CHAN(chan));
|
||||
}
|
||||
@ -323,9 +319,9 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
if (atomic_test_and_clear_bit(l2cap->chan.flags,
|
||||
L2CAP_FLAG_SIG_INFO_PENDING)) {
|
||||
/*
|
||||
* Release RTX timer since got the response & there's pending
|
||||
* command request.
|
||||
*/
|
||||
* Release RTX timer since got the response & there's pending
|
||||
* command request.
|
||||
*/
|
||||
k_delayed_work_cancel(&l2cap->chan.chan.rtx_work);
|
||||
}
|
||||
|
||||
@ -343,7 +339,6 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
|
||||
rsp = net_buf_pull_mem(buf, sizeof(*rsp));
|
||||
result = sys_le16_to_cpu(rsp->result);
|
||||
|
||||
if (result != BT_L2CAP_INFO_SUCCESS) {
|
||||
BT_WARN("Result unsuccessful");
|
||||
err = -EINVAL;
|
||||
@ -363,7 +358,6 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
|
||||
l2cap_br_get_info(l2cap, BT_L2CAP_INFO_FIXED_CHAN);
|
||||
return 0;
|
||||
|
||||
case BT_L2CAP_INFO_FIXED_CHAN:
|
||||
l2cap->info_fixed_chan = net_buf_pull_u8(buf);
|
||||
BT_DBG("remote fixed channel mask 0x%02x",
|
||||
@ -372,13 +366,11 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
connect_optional_fixed_channels(l2cap);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_WARN("type 0x%04x unsupported", type);
|
||||
err = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
done:
|
||||
atomic_set_bit(l2cap->chan.flags, L2CAP_FLAG_SIG_INFO_DONE);
|
||||
l2cap->info_ident = 0U;
|
||||
@ -431,7 +423,6 @@ static int l2cap_br_info_req(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
net_buf_add_le32(rsp_buf, L2CAP_FEAT_FIXED_CHAN_MASK);
|
||||
hdr_info->len = sys_cpu_to_le16(sizeof(*rsp) + sizeof(uint32_t));
|
||||
break;
|
||||
|
||||
case BT_L2CAP_INFO_FIXED_CHAN:
|
||||
rsp->type = sys_cpu_to_le16(BT_L2CAP_INFO_FIXED_CHAN);
|
||||
rsp->result = sys_cpu_to_le16(BT_L2CAP_INFO_SUCCESS);
|
||||
@ -441,7 +432,6 @@ static int l2cap_br_info_req(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
|
||||
hdr_info->len = sys_cpu_to_le16(sizeof(*rsp) + 8);
|
||||
break;
|
||||
|
||||
default:
|
||||
rsp->type = req->type;
|
||||
rsp->result = sys_cpu_to_le16(BT_L2CAP_INFO_NOTSUPP);
|
||||
@ -480,9 +470,9 @@ void bt_l2cap_br_connected(struct bt_conn *conn)
|
||||
}
|
||||
|
||||
/*
|
||||
* other fixed channels will be connected after Information
|
||||
* Response is received
|
||||
*/
|
||||
* other fixed channels will be connected after Information
|
||||
* Response is received
|
||||
*/
|
||||
if (fchan->cid == BT_L2CAP_CID_BR_SIG) {
|
||||
struct bt_l2cap_br *sig_ch;
|
||||
|
||||
@ -530,12 +520,11 @@ static void l2cap_br_conf(struct bt_l2cap_chan *chan)
|
||||
(void)memset(conf, 0, sizeof(*conf));
|
||||
|
||||
conf->dcid = sys_cpu_to_le16(BR_CHAN(chan)->tx.cid);
|
||||
|
||||
/*
|
||||
* Add MTU option if app set non default BR/EDR L2CAP MTU,
|
||||
* otherwise sent empty configuration data meaning default MTU
|
||||
* to be used.
|
||||
*/
|
||||
* Add MTU option if app set non default BR/EDR L2CAP MTU,
|
||||
* otherwise sent empty configuration data meaning default MTU
|
||||
* to be used.
|
||||
*/
|
||||
if (BR_CHAN(chan)->rx.mtu != L2CAP_BR_DEFAULT_MTU) {
|
||||
l2cap_br_conf_add_mtu(buf, BR_CHAN(chan)->rx.mtu);
|
||||
}
|
||||
@ -543,10 +532,10 @@ static void l2cap_br_conf(struct bt_l2cap_chan *chan)
|
||||
hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr));
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* might be needed to start tracking number of configuration iterations
|
||||
* on both directions
|
||||
*/
|
||||
* TODO:
|
||||
* might be needed to start tracking number of configuration iterations
|
||||
* on both directions
|
||||
*/
|
||||
l2cap_br_chan_send_req(BR_CHAN(chan), buf, L2CAP_BR_CFG_TIMEOUT);
|
||||
}
|
||||
|
||||
@ -568,7 +557,8 @@ enum l2cap_br_conn_security_result {
|
||||
* - bt_conn_set_security API returns < 0.
|
||||
*/
|
||||
|
||||
static enum l2cap_br_conn_security_result l2cap_br_conn_security(struct bt_l2cap_chan *chan, const uint16_t psm)
|
||||
static enum l2cap_br_conn_security_result
|
||||
l2cap_br_conn_security(struct bt_l2cap_chan *chan, const uint16_t psm)
|
||||
{
|
||||
int check;
|
||||
|
||||
@ -578,9 +568,9 @@ static enum l2cap_br_conn_security_result l2cap_br_conn_security(struct bt_l2cap
|
||||
}
|
||||
|
||||
/*
|
||||
* No link key needed for legacy devices (pre 2.1) and when low security
|
||||
* level is required.
|
||||
*/
|
||||
* No link key needed for legacy devices (pre 2.1) and when low security
|
||||
* level is required.
|
||||
*/
|
||||
if (chan->required_sec_level == BT_SECURITY_L1 &&
|
||||
!BT_FEAT_HOST_SSP(chan->conn->br.features)) {
|
||||
return L2CAP_CONN_SECURITY_PASSED;
|
||||
@ -591,49 +581,46 @@ static enum l2cap_br_conn_security_result l2cap_br_conn_security(struct bt_l2cap
|
||||
case BT_SECURITY_L3:
|
||||
case BT_SECURITY_L2:
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
/*
|
||||
* For non SDP PSM connections GAP's Security Mode 4 requires at
|
||||
* least unauthenticated link key and enabled encryption if
|
||||
* remote supports SSP before any L2CAP CoC traffic. So preset
|
||||
* local to MEDIUM security to trigger it if needed.
|
||||
*/
|
||||
* For non SDP PSM connections GAP's Security Mode 4 requires at
|
||||
* least unauthenticated link key and enabled encryption if
|
||||
* remote supports SSP before any L2CAP CoC traffic. So preset
|
||||
* local to MEDIUM security to trigger it if needed.
|
||||
*/
|
||||
if (BT_FEAT_HOST_SSP(chan->conn->br.features)) {
|
||||
chan->required_sec_level = BT_SECURITY_L2;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
check = bt_conn_set_security(chan->conn, chan->required_sec_level);
|
||||
|
||||
/*
|
||||
* Check case when on existing connection security level already covers
|
||||
* channel (service) security requirements against link security and
|
||||
* bt_conn_set_security API returns 0 what implies also there was no
|
||||
* need to trigger authentication.
|
||||
*/
|
||||
* Check case when on existing connection security level already covers
|
||||
* channel (service) security requirements against link security and
|
||||
* bt_conn_set_security API returns 0 what implies also there was no
|
||||
* need to trigger authentication.
|
||||
*/
|
||||
if (check == 0 &&
|
||||
chan->conn->sec_level >= chan->required_sec_level) {
|
||||
return L2CAP_CONN_SECURITY_PASSED;
|
||||
}
|
||||
|
||||
/*
|
||||
* If 'check' still holds 0, it means local host just sent HCI
|
||||
* authentication command to start procedure to increase link security
|
||||
* since service/profile requires that.
|
||||
*/
|
||||
* If 'check' still holds 0, it means local host just sent HCI
|
||||
* authentication command to start procedure to increase link security
|
||||
* since service/profile requires that.
|
||||
*/
|
||||
if (check == 0) {
|
||||
return L2CAP_CONN_SECURITY_PENDING;
|
||||
};
|
||||
|
||||
/*
|
||||
* For any other values in 'check' it means there was internal
|
||||
* validation condition forbidding to start authentication at this
|
||||
* moment.
|
||||
*/
|
||||
* For any other values in 'check' it means there was internal
|
||||
* validation condition forbidding to start authentication at this
|
||||
* moment.
|
||||
*/
|
||||
return L2CAP_CONN_SECURITY_REJECT;
|
||||
}
|
||||
|
||||
@ -700,16 +687,15 @@ static void l2cap_br_conn_req(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
|
||||
/* Check if there is a server registered */
|
||||
server = l2cap_br_server_lookup_psm(psm);
|
||||
|
||||
if (!server) {
|
||||
result = BT_L2CAP_BR_ERR_PSM_NOT_SUPP;
|
||||
goto no_chan;
|
||||
}
|
||||
|
||||
/*
|
||||
* Report security violation for non SDP channel without encryption when
|
||||
* remote supports SSP.
|
||||
*/
|
||||
* Report security violation for non SDP channel without encryption when
|
||||
* remote supports SSP.
|
||||
*/
|
||||
if (server->sec_level != BT_SECURITY_L0 &&
|
||||
BT_FEAT_HOST_SSP(conn->br.features) && !conn->encrypt) {
|
||||
result = BT_L2CAP_BR_ERR_SEC_BLOCK;
|
||||
@ -722,22 +708,21 @@ static void l2cap_br_conn_req(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
}
|
||||
|
||||
chan = bt_l2cap_br_lookup_tx_cid(conn, scid);
|
||||
|
||||
if (chan) {
|
||||
/*
|
||||
* we have a chan here but this is due to SCID being already in
|
||||
* use so it is not channel we are suppose to pass to
|
||||
* l2cap_br_conn_req_reply as wrong DCID would be used
|
||||
*/
|
||||
* we have a chan here but this is due to SCID being already in
|
||||
* use so it is not channel we are suppose to pass to
|
||||
* l2cap_br_conn_req_reply as wrong DCID would be used
|
||||
*/
|
||||
result = BT_L2CAP_BR_ERR_SCID_IN_USE;
|
||||
goto no_chan;
|
||||
}
|
||||
|
||||
/*
|
||||
* Request server to accept the new connection and allocate the
|
||||
* channel. If no free channels available for PSM server reply with
|
||||
* proper result and quit since chan pointer is uninitialized then.
|
||||
*/
|
||||
* Request server to accept the new connection and allocate the
|
||||
* channel. If no free channels available for PSM server reply with
|
||||
* proper result and quit since chan pointer is uninitialized then.
|
||||
*/
|
||||
if (server->accept(conn, &chan) < 0) {
|
||||
result = BT_L2CAP_BR_ERR_NO_RESOURCES;
|
||||
goto no_chan;
|
||||
@ -760,17 +745,14 @@ static void l2cap_br_conn_req(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
result = BT_L2CAP_BR_PENDING;
|
||||
/* TODO: auth timeout */
|
||||
break;
|
||||
|
||||
case L2CAP_CONN_SECURITY_PASSED:
|
||||
result = BT_L2CAP_BR_SUCCESS;
|
||||
break;
|
||||
|
||||
case L2CAP_CONN_SECURITY_REJECT:
|
||||
default:
|
||||
result = BT_L2CAP_BR_ERR_SEC_BLOCK;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Reply on connection request as acceptor */
|
||||
l2cap_br_conn_req_reply(chan, result);
|
||||
|
||||
@ -813,7 +795,6 @@ static void l2cap_br_conf_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
result, opt_len);
|
||||
|
||||
chan = bt_l2cap_br_lookup_rx_cid(conn, scid);
|
||||
|
||||
if (!chan) {
|
||||
BT_ERR("channel mismatch!");
|
||||
return;
|
||||
@ -823,9 +804,9 @@ static void l2cap_br_conf_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
k_delayed_work_cancel(&chan->rtx_work);
|
||||
|
||||
/*
|
||||
* TODO: handle other results than success and parse response data if
|
||||
* available
|
||||
*/
|
||||
* TODO: handle other results than success and parse response data if
|
||||
* available
|
||||
*/
|
||||
switch (result) {
|
||||
case BT_L2CAP_CONF_SUCCESS:
|
||||
atomic_set_bit(BR_CHAN(chan)->flags, L2CAP_FLAG_CONN_LCONF_DONE);
|
||||
@ -838,14 +819,11 @@ static void l2cap_br_conf_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
BR_CHAN(chan)->tx.cid, BR_CHAN(chan)->tx.mtu);
|
||||
|
||||
bt_l2cap_chan_set_state(chan, BT_L2CAP_CONNECTED);
|
||||
|
||||
if (chan->ops && chan->ops->connected) {
|
||||
chan->ops->connected(chan);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
/* currently disconnect channel on non success result */
|
||||
bt_l2cap_chan_disconnect(chan);
|
||||
@ -902,10 +880,10 @@ static void l2cap_br_send_reject(struct bt_conn *conn, uint8_t ident,
|
||||
rej->reason = sys_cpu_to_le16(reason);
|
||||
|
||||
/*
|
||||
* optional data if available must be already in little-endian format
|
||||
* made by caller.and be compliant with Core 4.2 [Vol 3, Part A, 4.1,
|
||||
* table 4.4]
|
||||
*/
|
||||
* optional data if available must be already in little-endian format
|
||||
* made by caller.and be compliant with Core 4.2 [Vol 3, Part A, 4.1,
|
||||
* table 4.4]
|
||||
*/
|
||||
if (data) {
|
||||
net_buf_add_mem(buf, data, data_len);
|
||||
}
|
||||
@ -927,7 +905,6 @@ static uint16_t l2cap_br_conf_opt_mtu(struct bt_l2cap_chan *chan,
|
||||
|
||||
/* pulling MTU value moves buf data to next option item */
|
||||
mtu = net_buf_pull_le16(buf);
|
||||
|
||||
if (mtu < L2CAP_BR_MIN_MTU) {
|
||||
result = BT_L2CAP_CONF_UNACCEPT;
|
||||
BR_CHAN(chan)->tx.mtu = L2CAP_BR_MIN_MTU;
|
||||
@ -965,7 +942,6 @@ static void l2cap_br_conf_req(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
BT_DBG("dcid 0x%04x flags 0x%02x len %u", dcid, flags, opt_len);
|
||||
|
||||
chan = bt_l2cap_br_lookup_rx_cid(conn, dcid);
|
||||
|
||||
if (!chan) {
|
||||
BT_ERR("rx channel mismatch!");
|
||||
struct bt_l2cap_cmd_reject_cid_data data = {
|
||||
@ -1001,13 +977,12 @@ static void l2cap_br_conf_req(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
/* getting MTU modifies buf internals */
|
||||
result = l2cap_br_conf_opt_mtu(chan, buf, opt->len);
|
||||
/*
|
||||
* MTU is done. For now bailout the loop but later on
|
||||
* there can be a need to continue checking next options
|
||||
* that are after MTU value and then goto is not proper
|
||||
* way out here.
|
||||
*/
|
||||
* MTU is done. For now bailout the loop but later on
|
||||
* there can be a need to continue checking next options
|
||||
* that are after MTU value and then goto is not proper
|
||||
* way out here.
|
||||
*/
|
||||
goto send_rsp;
|
||||
|
||||
default:
|
||||
if (!hint) {
|
||||
BT_DBG("option %u not handled", opt->type);
|
||||
@ -1033,10 +1008,10 @@ send_rsp:
|
||||
rsp->scid = sys_cpu_to_le16(BR_CHAN(chan)->tx.cid);
|
||||
|
||||
/*
|
||||
* TODO: If options other than MTU bacame meaningful then processing
|
||||
* the options chain need to be modified and taken into account when
|
||||
* sending back to peer.
|
||||
*/
|
||||
* TODO: If options other than MTU bacame meaningful then processing
|
||||
* the options chain need to be modified and taken into account when
|
||||
* sending back to peer.
|
||||
*/
|
||||
if (result == BT_L2CAP_CONF_UNACCEPT) {
|
||||
l2cap_br_conf_add_mtu(buf, BR_CHAN(chan)->tx.mtu);
|
||||
}
|
||||
@ -1058,7 +1033,6 @@ send_rsp:
|
||||
BR_CHAN(chan)->tx.cid, BR_CHAN(chan)->tx.mtu);
|
||||
|
||||
bt_l2cap_chan_set_state(chan, BT_L2CAP_CONNECTED);
|
||||
|
||||
if (chan->ops && chan->ops->connected) {
|
||||
chan->ops->connected(chan);
|
||||
}
|
||||
@ -1110,7 +1084,6 @@ static void l2cap_br_disconn_req(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
BT_DBG("scid 0x%04x dcid 0x%04x", dcid, scid);
|
||||
|
||||
chan = l2cap_br_remove_tx_cid(conn, scid);
|
||||
|
||||
if (!chan) {
|
||||
struct bt_l2cap_cmd_reject_cid_data data;
|
||||
|
||||
@ -1210,7 +1183,6 @@ static void l2cap_br_disconn_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
BT_DBG("dcid 0x%04x scid 0x%04x", dcid, scid);
|
||||
|
||||
chan = l2cap_br_remove_tx_cid(conn, dcid);
|
||||
|
||||
if (!chan) {
|
||||
BT_WARN("No dcid 0x%04x channel found", dcid);
|
||||
return;
|
||||
@ -1250,11 +1222,9 @@ int bt_l2cap_br_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan,
|
||||
case BT_L2CAP_CONNECTED:
|
||||
/* Already connected */
|
||||
return -EISCONN;
|
||||
|
||||
case BT_L2CAP_DISCONNECTED:
|
||||
/* Can connect */
|
||||
break;
|
||||
|
||||
case BT_L2CAP_CONFIG:
|
||||
case BT_L2CAP_DISCONNECT:
|
||||
default:
|
||||
@ -1273,14 +1243,12 @@ int bt_l2cap_br_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan,
|
||||
switch (l2cap_br_conn_security(chan, psm)) {
|
||||
case L2CAP_CONN_SECURITY_PENDING:
|
||||
/*
|
||||
* Authentication was triggered, wait with sending request on
|
||||
* connection security changed callback context.
|
||||
*/
|
||||
* Authentication was triggered, wait with sending request on
|
||||
* connection security changed callback context.
|
||||
*/
|
||||
return 0;
|
||||
|
||||
case L2CAP_CONN_SECURITY_PASSED:
|
||||
break;
|
||||
|
||||
case L2CAP_CONN_SECURITY_REJECT:
|
||||
default:
|
||||
l2cap_br_chan_cleanup(chan);
|
||||
@ -1325,7 +1293,6 @@ static void l2cap_br_conn_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
result, status);
|
||||
|
||||
chan = bt_l2cap_br_lookup_rx_cid(conn, scid);
|
||||
|
||||
if (!chan) {
|
||||
BT_ERR("No scid 0x%04x channel found", scid);
|
||||
return;
|
||||
@ -1348,11 +1315,9 @@ static void l2cap_br_conn_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
|
||||
bt_l2cap_chan_set_state(chan, BT_L2CAP_CONFIG);
|
||||
atomic_clear_bit(BR_CHAN(chan)->flags, L2CAP_FLAG_CONN_PENDING);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_BR_PENDING:
|
||||
k_delayed_work_submit(&chan->rtx_work, L2CAP_BR_CONN_TIMEOUT);
|
||||
break;
|
||||
|
||||
default:
|
||||
l2cap_br_chan_cleanup(chan);
|
||||
break;
|
||||
@ -1403,35 +1368,27 @@ static int l2cap_br_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
case BT_L2CAP_INFO_RSP:
|
||||
l2cap_br_info_rsp(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_INFO_REQ:
|
||||
l2cap_br_info_req(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_DISCONN_REQ:
|
||||
l2cap_br_disconn_req(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_CONN_REQ:
|
||||
l2cap_br_conn_req(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_CONF_RSP:
|
||||
l2cap_br_conf_rsp(l2cap, hdr->ident, len, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_CONF_REQ:
|
||||
l2cap_br_conf_req(l2cap, hdr->ident, len, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_DISCONN_RSP:
|
||||
l2cap_br_disconn_rsp(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
case BT_L2CAP_CONN_RSP:
|
||||
l2cap_br_conn_rsp(l2cap, hdr->ident, buf);
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_WARN("Unknown/Unsupported L2CAP PDU code 0x%02x", hdr->code);
|
||||
l2cap_br_send_reject(chan->conn, hdr->ident,
|
||||
@ -1457,9 +1414,9 @@ static void l2cap_br_conn_pend(struct bt_l2cap_chan *chan, uint8_t status)
|
||||
|
||||
if (status) {
|
||||
/*
|
||||
* Security procedure status is non-zero so respond with
|
||||
* security violation only as channel acceptor.
|
||||
*/
|
||||
* Security procedure status is non-zero so respond with
|
||||
* security violation only as channel acceptor.
|
||||
*/
|
||||
l2cap_br_conn_req_reply(chan, BT_L2CAP_BR_ERR_SEC_BLOCK);
|
||||
|
||||
/* Release channel allocated to outgoing connection request */
|
||||
@ -1476,15 +1433,15 @@ static void l2cap_br_conn_pend(struct bt_l2cap_chan *chan, uint8_t status)
|
||||
}
|
||||
|
||||
/*
|
||||
* For incoming connection state send confirming outstanding
|
||||
* response and initiate configuration request.
|
||||
*/
|
||||
* For incoming connection state send confirming outstanding
|
||||
* response and initiate configuration request.
|
||||
*/
|
||||
if (l2cap_br_conn_req_reply(chan, BT_L2CAP_BR_SUCCESS) == 0) {
|
||||
bt_l2cap_chan_set_state(chan, BT_L2CAP_CONFIG);
|
||||
/*
|
||||
* Initialize config request since remote needs to know
|
||||
* local MTU segmentation.
|
||||
*/
|
||||
* Initialize config request since remote needs to know
|
||||
* local MTU segmentation.
|
||||
*/
|
||||
l2cap_br_conf(chan);
|
||||
} else if (atomic_test_and_clear_bit(BR_CHAN(chan)->flags,
|
||||
L2CAP_FLAG_CONN_PENDING)) {
|
||||
@ -1543,7 +1500,6 @@ void bt_l2cap_br_recv(struct bt_conn *conn, struct net_buf *buf)
|
||||
cid = sys_le16_to_cpu(hdr->cid);
|
||||
|
||||
chan = bt_l2cap_br_lookup_rx_cid(conn, cid);
|
||||
|
||||
if (!chan) {
|
||||
BT_WARN("Ignoring data for unknown CID 0x%04x", cid);
|
||||
net_buf_unref(buf);
|
||||
@ -1551,9 +1507,9 @@ void bt_l2cap_br_recv(struct bt_conn *conn, struct net_buf *buf)
|
||||
}
|
||||
|
||||
/*
|
||||
* if data was received for fixed channel before Information
|
||||
* Response we connect channel here.
|
||||
*/
|
||||
* if data was received for fixed channel before Information
|
||||
* Response we connect channel here.
|
||||
*/
|
||||
check_fixed_channel(chan);
|
||||
|
||||
chan->ops->recv(chan, buf);
|
||||
@ -1594,7 +1550,6 @@ BT_L2CAP_BR_CHANNEL_DEFINE(br_fixed_chan, BT_L2CAP_CID_BR_SIG, l2cap_br_accept);
|
||||
void bt_l2cap_br_init(void)
|
||||
{
|
||||
#if defined(BFLB_DYNAMIC_ALLOC_MEM)
|
||||
k_lifo_init(&br_sig_pool.free, CONFIG_BT_MAX_CONN);
|
||||
net_buf_init(&br_sig_pool, CONFIG_BT_MAX_CONN, BT_L2CAP_BUF_SIZE(L2CAP_BR_MIN_MTU), NULL);
|
||||
#endif
|
||||
sys_slist_init(&br_servers);
|
||||
|
@ -78,16 +78,12 @@ static inline u8_t bt_monitor_opcode(struct net_buf *buf)
|
||||
switch (bt_buf_get_type(buf)) {
|
||||
case BT_BUF_CMD:
|
||||
return BT_MONITOR_COMMAND_PKT;
|
||||
|
||||
case BT_BUF_EVT:
|
||||
return BT_MONITOR_EVENT_PKT;
|
||||
|
||||
case BT_BUF_ACL_OUT:
|
||||
return BT_MONITOR_ACL_TX_PKT;
|
||||
|
||||
case BT_BUF_ACL_IN:
|
||||
return BT_MONITOR_ACL_RX_PKT;
|
||||
|
||||
default:
|
||||
return BT_MONITOR_NOP;
|
||||
}
|
||||
|
@ -25,11 +25,9 @@ int multi_adv_get_instant_num(void)
|
||||
struct multi_adv_instant *inst = &(g_multi_adv_list[0]);
|
||||
|
||||
for (i = 0; i < MAX_MULTI_ADV_INSTANT; i++) {
|
||||
if (inst[i].inuse_flag) {
|
||||
if (inst[i].inuse_flag)
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
@ -45,7 +43,6 @@ struct multi_adv_instant *multi_adv_alloc_unused_instant(void)
|
||||
return &(inst[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -60,7 +57,6 @@ int multi_adv_delete_instant_by_id(int instant_id)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -74,7 +70,6 @@ struct multi_adv_instant *multi_adv_find_instant_by_id(int instant_id)
|
||||
return &(inst[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -85,7 +80,6 @@ struct multi_adv_instant *multi_adv_find_instant_by_order(int order)
|
||||
if (inst[order].inuse_flag) {
|
||||
return &(inst[order]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -95,7 +89,6 @@ int multi_adv_set_ad_data(uint8_t *ad_data, const struct bt_data *ad, size_t ad_
|
||||
|
||||
memset(ad_data, 0, MAX_AD_DATA_LEN);
|
||||
len = 0;
|
||||
|
||||
for (i = 0; i < ad_len; i++) {
|
||||
/* Check if ad fit in the remaining buffer */
|
||||
if (len + ad[i].data_len + 2 > MAX_AD_DATA_LEN) {
|
||||
@ -118,17 +111,13 @@ int change_to_tick(int min_interval, int max_interval)
|
||||
|
||||
if (max_interval / SLOT_PER_PERIOD != min_interval / SLOT_PER_PERIOD) {
|
||||
tick = min_interval / SLOT_PER_PERIOD;
|
||||
|
||||
if (min_interval % SLOT_PER_PERIOD) {
|
||||
if (min_interval % SLOT_PER_PERIOD)
|
||||
tick++;
|
||||
}
|
||||
} else {
|
||||
tick = min_interval / SLOT_PER_PERIOD;
|
||||
}
|
||||
|
||||
if (tick <= 1) {
|
||||
if (tick <= 1)
|
||||
tick = 1;
|
||||
}
|
||||
|
||||
return tick;
|
||||
}
|
||||
@ -179,36 +168,27 @@ int calculate_offset(uint16_t interval[], uint16_t offset[], int num, int durati
|
||||
int offset_range;
|
||||
|
||||
offset_range = interval[num];
|
||||
|
||||
if (offset_range > duration) {
|
||||
if (offset_range > duration)
|
||||
offset_range = duration;
|
||||
}
|
||||
|
||||
if (num == 0) {
|
||||
if (num == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
min_max_instants = 0x7fffffff;
|
||||
|
||||
/* using 0-interval-1 as offset */
|
||||
for (i = 0; i < offset_range; i++) {
|
||||
curr_max_instants = 0;
|
||||
|
||||
/* search slot form 0 - duration to get the max instants number */
|
||||
for (j = 0; j < duration; j++) {
|
||||
/* get instant number in each slot */
|
||||
instants = 0;
|
||||
|
||||
for (k = 0; k < num; k++) {
|
||||
if (j % interval[k] == offset[k]) {
|
||||
instants++;
|
||||
}
|
||||
}
|
||||
|
||||
if (j % interval[num] == i) {
|
||||
if (j % interval[num] == i)
|
||||
instants++;
|
||||
}
|
||||
|
||||
if (curr_max_instants < instants) {
|
||||
curr_max_instants = instants;
|
||||
}
|
||||
@ -220,7 +200,6 @@ int calculate_offset(uint16_t interval[], uint16_t offset[], int num, int durati
|
||||
curr_offset = i;
|
||||
}
|
||||
}
|
||||
|
||||
return curr_offset;
|
||||
}
|
||||
|
||||
@ -229,15 +208,12 @@ void multi_adv_schedule_table(int inst_num, uint16_t inst_interval[], uint16_t i
|
||||
int i, min_multi, last_min_multi;
|
||||
/* calculate min multi */
|
||||
last_min_multi = min_multi = inst_interval[0];
|
||||
|
||||
for (i = 1; i < inst_num; i++) {
|
||||
min_multi = calculate_min_multi(min_multi, inst_interval[i]);
|
||||
|
||||
if (min_multi > MAX_MIN_MULTI) {
|
||||
min_multi = last_min_multi;
|
||||
break;
|
||||
}
|
||||
|
||||
last_min_multi = min_multi;
|
||||
}
|
||||
|
||||
@ -254,11 +230,9 @@ int multi_adv_start_adv_instant(struct multi_adv_instant *adv_instant)
|
||||
ret = bt_le_adv_start_instant(&adv_instant->param,
|
||||
adv_instant->ad, adv_instant->ad_len,
|
||||
adv_instant->sd, adv_instant->sd_len);
|
||||
|
||||
if (ret) {
|
||||
BT_WARN("adv start instant failed: inst_id %d, err %d\r\n", adv_instant->instant_id, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -267,10 +241,8 @@ void multi_adv_schedule_timer_handle(void)
|
||||
struct multi_adv_scheduler *adv_scheduler = &g_multi_adv_scheduler;
|
||||
|
||||
multi_adv_schedule_timer_stop();
|
||||
|
||||
if (adv_scheduler->schedule_state == SCHEDULE_STOP) {
|
||||
if (adv_scheduler->schedule_state == SCHEDULE_STOP)
|
||||
return;
|
||||
}
|
||||
|
||||
adv_scheduler->slot_clock = adv_scheduler->next_slot_clock;
|
||||
adv_scheduler->slot_offset = adv_scheduler->next_slot_offset;
|
||||
@ -304,7 +276,6 @@ int multi_adv_schedule_timer_stop(void)
|
||||
k_delayed_work_cancel(&g_multi_adv_timer);
|
||||
adv_scheduler->schedule_timer_active = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -319,10 +290,8 @@ void multi_adv_schedule_timeslot(struct multi_adv_scheduler *adv_scheduler)
|
||||
uint8_t match_order[MAX_MULTI_ADV_INSTANT];
|
||||
|
||||
inst_num = 0;
|
||||
|
||||
for (i = 0; i < MAX_MULTI_ADV_INSTANT; i++) {
|
||||
adv_instant = multi_adv_find_instant_by_order(i);
|
||||
|
||||
if (adv_instant) {
|
||||
inst_interval[inst_num] = adv_instant->instant_interval;
|
||||
inst_offset[inst_num] = adv_instant->instant_offset;
|
||||
@ -334,7 +303,6 @@ void multi_adv_schedule_timeslot(struct multi_adv_scheduler *adv_scheduler)
|
||||
inst_clk = adv_scheduler->slot_clock;
|
||||
inst_off = adv_scheduler->slot_offset;
|
||||
match = 0;
|
||||
|
||||
for (i = 0; i < inst_num; i++) {
|
||||
if ((inst_clk % inst_interval[i]) == inst_offset[i]) {
|
||||
match_order[match] = i;
|
||||
@ -354,10 +322,8 @@ void multi_adv_schedule_timeslot(struct multi_adv_scheduler *adv_scheduler)
|
||||
|
||||
/* start instant */
|
||||
adv_instant = multi_adv_find_instant_by_order(inst_order[match_order[insts]]);
|
||||
|
||||
if (adv_instant) {
|
||||
if (adv_instant)
|
||||
multi_adv_start_adv_instant(adv_instant);
|
||||
}
|
||||
}
|
||||
|
||||
/* next instant in the same slot */
|
||||
@ -369,7 +335,6 @@ void multi_adv_schedule_timeslot(struct multi_adv_scheduler *adv_scheduler)
|
||||
adv_scheduler->next_slot_clock++;
|
||||
adv_scheduler->next_slot_offset = 0;
|
||||
}
|
||||
|
||||
multi_adv_schedule_timer_start(offset_per_instant);
|
||||
return;
|
||||
}
|
||||
@ -377,21 +342,17 @@ void multi_adv_schedule_timeslot(struct multi_adv_scheduler *adv_scheduler)
|
||||
|
||||
/* next instant not in the same slot */
|
||||
min_next_slot = 0x7fffffff;
|
||||
|
||||
for (i = 0; i < inst_num; i++) {
|
||||
if (inst_clk - inst_offset[i] < 0) {
|
||||
match = 0;
|
||||
} else {
|
||||
match = (inst_clk - inst_offset[i]) / inst_interval[i] + 1;
|
||||
}
|
||||
|
||||
next_slot = match * inst_interval[i] + inst_offset[i];
|
||||
|
||||
if (next_slot < min_next_slot) {
|
||||
min_next_slot = next_slot;
|
||||
}
|
||||
}
|
||||
|
||||
adv_scheduler->next_slot_offset = 0;
|
||||
adv_scheduler->next_slot_clock = min_next_slot;
|
||||
|
||||
@ -437,13 +398,10 @@ void multi_adv_new_schedule(void)
|
||||
if (adv_scheduler->schedule_state == SCHEDULE_START) {
|
||||
multi_adv_schedule_stop();
|
||||
}
|
||||
|
||||
/* get all instant and calculate ticks and */
|
||||
high_duty_instant = 0;
|
||||
|
||||
for (i = 0; i < MAX_MULTI_ADV_INSTANT; i++) {
|
||||
adv_instant = multi_adv_find_instant_by_order(i);
|
||||
|
||||
if (adv_instant) {
|
||||
/* if high duty cycle adv found */
|
||||
if (adv_instant->param.interval_min < HIGH_DUTY_CYCLE_INTERVAL) {
|
||||
@ -468,14 +426,10 @@ void multi_adv_new_schedule(void)
|
||||
bt_le_adv_stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (inst_num == 1) {
|
||||
adv_instant = multi_adv_find_instant_by_order(inst_order[0]);
|
||||
|
||||
if (!adv_instant) {
|
||||
if (!adv_instant)
|
||||
return;
|
||||
}
|
||||
|
||||
multi_adv_start_adv_instant(adv_instant);
|
||||
return;
|
||||
}
|
||||
@ -489,11 +443,9 @@ void multi_adv_new_schedule(void)
|
||||
/* set interval and offset to instant */
|
||||
for (i = 0; i < inst_num; i++) {
|
||||
adv_instant = multi_adv_find_instant_by_order(inst_order[i]);
|
||||
|
||||
if (!adv_instant) {
|
||||
continue;
|
||||
}
|
||||
|
||||
adv_instant->instant_interval = inst_interval[i];
|
||||
adv_instant->instant_offset = inst_offset[i];
|
||||
|
||||
@ -518,16 +470,12 @@ int bt_le_multi_adv_start(const struct bt_le_adv_param *param,
|
||||
struct multi_adv_instant *adv_instant;
|
||||
|
||||
instant_num = multi_adv_get_instant_num();
|
||||
|
||||
if (instant_num >= MAX_MULTI_ADV_INSTANT) {
|
||||
if (instant_num >= MAX_MULTI_ADV_INSTANT)
|
||||
return -1;
|
||||
}
|
||||
|
||||
adv_instant = multi_adv_alloc_unused_instant();
|
||||
|
||||
if (adv_instant == 0) {
|
||||
if (adv_instant == 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(&(adv_instant->param), param, sizeof(struct bt_le_adv_param));
|
||||
|
||||
@ -542,9 +490,8 @@ int bt_le_multi_adv_start(const struct bt_le_adv_param *param,
|
||||
|
||||
int bt_le_multi_adv_stop(int instant_id)
|
||||
{
|
||||
if (multi_adv_find_instant_by_id(instant_id) == 0) {
|
||||
if (multi_adv_find_instant_by_id(instant_id) == 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
//BT_WARN("%s id[%d]\n", __func__, instant_id);
|
||||
multi_adv_delete_instant_by_id(instant_id);
|
||||
@ -563,6 +510,5 @@ bool bt_le_multi_adv_id_is_vaild(int instant_id)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -174,7 +174,6 @@ static struct bt_rfcomm_dlc *rfcomm_dlcs_remove_dlci(struct bt_rfcomm_dlc *dlcs,
|
||||
tmp->_next = dlcs->_next;
|
||||
return dlcs;
|
||||
}
|
||||
|
||||
tmp = dlcs;
|
||||
}
|
||||
|
||||
@ -194,7 +193,8 @@ static struct bt_rfcomm_server *rfcomm_server_lookup_channel(uint8_t channel)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct bt_rfcomm_session *rfcomm_sessions_lookup_bt_conn(struct bt_conn *conn)
|
||||
static struct bt_rfcomm_session *
|
||||
rfcomm_sessions_lookup_bt_conn(struct bt_conn *conn)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -271,18 +271,17 @@ static void rfcomm_dlc_disconnect(struct bt_rfcomm_dlc *dlc)
|
||||
switch (old_state) {
|
||||
case BT_RFCOMM_STATE_CONNECTED:
|
||||
/* Queue a dummy buffer to wake up and stop the
|
||||
* tx thread for states where it was running.
|
||||
*/
|
||||
* tx thread for states where it was running.
|
||||
*/
|
||||
net_buf_put(&dlc->tx_queue,
|
||||
net_buf_alloc(&dummy_pool, K_NO_WAIT));
|
||||
|
||||
/* There could be a writer waiting for credits so return a
|
||||
* dummy credit to wake it up.
|
||||
*/
|
||||
* dummy credit to wake it up.
|
||||
*/
|
||||
rfcomm_dlc_tx_give_credits(dlc, 1);
|
||||
k_sem_give(&dlc->session->fc);
|
||||
break;
|
||||
|
||||
default:
|
||||
rfcomm_dlc_destroy(dlc);
|
||||
break;
|
||||
@ -318,8 +317,8 @@ static void rfcomm_session_disconnected(struct bt_rfcomm_session *session)
|
||||
struct net_buf *bt_rfcomm_create_pdu(struct net_buf_pool *pool)
|
||||
{
|
||||
/* Length in RFCOMM header can be 2 bytes depending on length of user
|
||||
* data
|
||||
*/
|
||||
* data
|
||||
*/
|
||||
return bt_conn_create_pdu(pool,
|
||||
sizeof(struct bt_l2cap_hdr) +
|
||||
sizeof(struct bt_rfcomm_hdr) + 1);
|
||||
@ -470,7 +469,6 @@ static struct bt_rfcomm_dlc *rfcomm_dlc_accept(struct bt_rfcomm_session *session
|
||||
|
||||
channel = BT_RFCOMM_GET_CHANNEL(dlci);
|
||||
server = rfcomm_server_lookup_channel(channel);
|
||||
|
||||
if (!server) {
|
||||
BT_ERR("Server Channel not registered");
|
||||
return NULL;
|
||||
@ -529,10 +527,10 @@ static void rfcomm_check_fc(struct bt_rfcomm_dlc *dlc)
|
||||
k_sem_take(&dlc->session->fc, K_FOREVER);
|
||||
|
||||
/* Give the sems immediately so that sem will be available for all
|
||||
* the bufs in the queue. It will be blocked only once all the bufs
|
||||
* are sent (which will preempt this thread) and FCOFF / FC bit
|
||||
* with 1, is received.
|
||||
*/
|
||||
* the bufs in the queue. It will be blocked only once all the bufs
|
||||
* are sent (which will preempt this thread) and FCOFF / FC bit
|
||||
* with 1, is received.
|
||||
*/
|
||||
k_sem_give(&dlc->session->fc);
|
||||
k_sem_give(&dlc->tx_credits);
|
||||
}
|
||||
@ -550,7 +548,6 @@ static void rfcomm_dlc_tx_thread(void *p1)
|
||||
/* Get next packet for dlc */
|
||||
BT_DBG("Wait for buf %p", dlc);
|
||||
buf = net_buf_get(&dlc->tx_queue, timeout);
|
||||
|
||||
/* If its dummy buffer or non user disconnect then break */
|
||||
if ((dlc->state != BT_RFCOMM_STATE_CONNECTED &&
|
||||
dlc->state != BT_RFCOMM_STATE_USER_DISCONNECT) ||
|
||||
@ -558,12 +555,10 @@ static void rfcomm_dlc_tx_thread(void *p1)
|
||||
if (buf) {
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
rfcomm_check_fc(dlc);
|
||||
|
||||
if (dlc->state != BT_RFCOMM_STATE_CONNECTED &&
|
||||
dlc->state != BT_RFCOMM_STATE_USER_DISCONNECT) {
|
||||
net_buf_unref(buf);
|
||||
@ -748,8 +743,8 @@ static void rfcomm_dlc_connected(struct bt_rfcomm_dlc *dlc)
|
||||
|
||||
if (dlc->session->cfc == BT_RFCOMM_CFC_UNKNOWN) {
|
||||
/* This means PN negotiation is not done for this session and
|
||||
* can happen only for 1.0b device.
|
||||
*/
|
||||
* can happen only for 1.0b device.
|
||||
*/
|
||||
dlc->session->cfc = BT_RFCOMM_CFC_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
@ -789,10 +784,10 @@ static enum security_result rfcomm_dlc_security(struct bt_rfcomm_dlc *dlc)
|
||||
BT_DBG("dlc %p", dlc);
|
||||
|
||||
/* If current security level is greater than or equal to required
|
||||
* security level then return SUCCESS.
|
||||
* For SSP devices the current security will be atleast MEDIUM
|
||||
* since L2CAP is enforcing it
|
||||
*/
|
||||
* security level then return SUCCESS.
|
||||
* For SSP devices the current security will be atleast MEDIUM
|
||||
* since L2CAP is enforcing it
|
||||
*/
|
||||
if (conn->sec_level >= dlc->required_sec_level) {
|
||||
return RFCOMM_SECURITY_PASSED;
|
||||
}
|
||||
@ -823,38 +818,33 @@ static int rfcomm_dlc_close(struct bt_rfcomm_dlc *dlc)
|
||||
if (dlc->role == BT_RFCOMM_ROLE_ACCEPTOR) {
|
||||
rfcomm_send_dm(dlc->session, dlc->dlci);
|
||||
}
|
||||
|
||||
//__fallthrough;
|
||||
//__fallthrough;
|
||||
case BT_RFCOMM_STATE_INIT:
|
||||
rfcomm_dlc_drop(dlc);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_STATE_CONNECTING:
|
||||
case BT_RFCOMM_STATE_CONFIG:
|
||||
dlc->state = BT_RFCOMM_STATE_DISCONNECTING;
|
||||
rfcomm_send_disc(dlc->session, dlc->dlci);
|
||||
k_delayed_work_submit(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_STATE_CONNECTED:
|
||||
dlc->state = BT_RFCOMM_STATE_DISCONNECTING;
|
||||
|
||||
/* Queue a dummy buffer to wake up and stop the
|
||||
* tx thread.
|
||||
*/
|
||||
* tx thread.
|
||||
*/
|
||||
net_buf_put(&dlc->tx_queue,
|
||||
net_buf_alloc(&dummy_pool, K_NO_WAIT));
|
||||
|
||||
/* There could be a writer waiting for credits so return a
|
||||
* dummy credit to wake it up.
|
||||
*/
|
||||
* dummy credit to wake it up.
|
||||
*/
|
||||
rfcomm_dlc_tx_give_credits(dlc, 1);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_STATE_DISCONNECTING:
|
||||
case BT_RFCOMM_STATE_DISCONNECTED:
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_STATE_IDLE:
|
||||
default:
|
||||
return -EINVAL;
|
||||
@ -876,10 +866,8 @@ static void rfcomm_handle_sabm(struct bt_rfcomm_session *session, uint8_t dlci)
|
||||
enum security_result result;
|
||||
|
||||
dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci);
|
||||
|
||||
if (!dlc) {
|
||||
dlc = rfcomm_dlc_accept(session, dlci);
|
||||
|
||||
if (!dlc) {
|
||||
rfcomm_send_dm(session, dlci);
|
||||
return;
|
||||
@ -887,15 +875,12 @@ static void rfcomm_handle_sabm(struct bt_rfcomm_session *session, uint8_t dlci)
|
||||
}
|
||||
|
||||
result = rfcomm_dlc_security(dlc);
|
||||
|
||||
switch (result) {
|
||||
case RFCOMM_SECURITY_PENDING:
|
||||
dlc->state = BT_RFCOMM_STATE_SECURITY_PENDING;
|
||||
return;
|
||||
|
||||
case RFCOMM_SECURITY_PASSED:
|
||||
break;
|
||||
|
||||
case RFCOMM_SECURITY_REJECT:
|
||||
default:
|
||||
rfcomm_send_dm(session, dlci);
|
||||
@ -927,12 +912,10 @@ static int rfcomm_send_pn(struct bt_rfcomm_dlc *dlc, uint8_t cr)
|
||||
pn = net_buf_add(buf, sizeof(*pn));
|
||||
pn->dlci = dlc->dlci;
|
||||
pn->mtu = sys_cpu_to_le16(dlc->mtu);
|
||||
|
||||
if (dlc->state == BT_RFCOMM_STATE_CONFIG &&
|
||||
(dlc->session->cfc == BT_RFCOMM_CFC_UNKNOWN ||
|
||||
dlc->session->cfc == BT_RFCOMM_CFC_SUPPORTED)) {
|
||||
pn->credits = dlc->rx_credit;
|
||||
|
||||
if (cr) {
|
||||
pn->flow_ctrl = BT_RFCOMM_PN_CFC_CMD;
|
||||
} else {
|
||||
@ -940,12 +923,11 @@ static int rfcomm_send_pn(struct bt_rfcomm_dlc *dlc, uint8_t cr)
|
||||
}
|
||||
} else {
|
||||
/* If PN comes in already opened dlc or cfc not supported
|
||||
* these should be 0
|
||||
*/
|
||||
* these should be 0
|
||||
*/
|
||||
pn->credits = 0U;
|
||||
pn->flow_ctrl = 0U;
|
||||
}
|
||||
|
||||
pn->max_retrans = 0U;
|
||||
pn->ack_timer = 0U;
|
||||
pn->priority = 0U;
|
||||
@ -986,18 +968,15 @@ static int rfcomm_dlc_start(struct bt_rfcomm_dlc *dlc)
|
||||
BT_DBG("dlc %p", dlc);
|
||||
|
||||
result = rfcomm_dlc_security(dlc);
|
||||
|
||||
switch (result) {
|
||||
case RFCOMM_SECURITY_PASSED:
|
||||
dlc->mtu = MIN(dlc->mtu, dlc->session->mtu);
|
||||
dlc->state = BT_RFCOMM_STATE_CONFIG;
|
||||
rfcomm_send_pn(dlc, BT_RFCOMM_MSG_CMD_CR);
|
||||
break;
|
||||
|
||||
case RFCOMM_SECURITY_PENDING:
|
||||
dlc->state = BT_RFCOMM_STATE_SECURITY_PENDING;
|
||||
break;
|
||||
|
||||
case RFCOMM_SECURITY_REJECT:
|
||||
default:
|
||||
return -EIO;
|
||||
@ -1015,10 +994,8 @@ static void rfcomm_handle_ua(struct bt_rfcomm_session *session, uint8_t dlci)
|
||||
switch (session->state) {
|
||||
case BT_RFCOMM_STATE_CONNECTING:
|
||||
session->state = BT_RFCOMM_STATE_CONNECTED;
|
||||
|
||||
for (dlc = session->dlcs; dlc; dlc = next) {
|
||||
next = dlc->_next;
|
||||
|
||||
if (dlc->role == BT_RFCOMM_ROLE_INITIATOR &&
|
||||
dlc->state == BT_RFCOMM_STATE_INIT) {
|
||||
if (rfcomm_dlc_start(dlc) < 0) {
|
||||
@ -1026,29 +1003,23 @@ static void rfcomm_handle_ua(struct bt_rfcomm_session *session, uint8_t dlci)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Disconnect session if there is no dlcs left */
|
||||
rfcomm_session_disconnect(session);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_STATE_DISCONNECTING:
|
||||
session->state = BT_RFCOMM_STATE_DISCONNECTED;
|
||||
/* Cancel disc timer */
|
||||
k_delayed_work_cancel(&session->rtx_work);
|
||||
err = bt_l2cap_chan_disconnect(&session->br_chan.chan);
|
||||
|
||||
if (err < 0) {
|
||||
session->state = BT_RFCOMM_STATE_IDLE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci);
|
||||
|
||||
if (!dlc) {
|
||||
return;
|
||||
}
|
||||
@ -1057,12 +1028,10 @@ static void rfcomm_handle_ua(struct bt_rfcomm_session *session, uint8_t dlci)
|
||||
case BT_RFCOMM_STATE_CONNECTING:
|
||||
rfcomm_dlc_connected(dlc);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_STATE_DISCONNECTING:
|
||||
rfcomm_dlc_drop(dlc);
|
||||
rfcomm_session_disconnect(session);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1076,7 +1045,6 @@ static void rfcomm_handle_dm(struct bt_rfcomm_session *session, uint8_t dlci)
|
||||
BT_DBG("dlci %d", dlci);
|
||||
|
||||
dlc = rfcomm_dlcs_remove_dlci(session->dlcs, dlci);
|
||||
|
||||
if (!dlc) {
|
||||
return;
|
||||
}
|
||||
@ -1095,7 +1063,6 @@ static void rfcomm_handle_msc(struct bt_rfcomm_session *session,
|
||||
BT_DBG("dlci %d", dlci);
|
||||
|
||||
dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci);
|
||||
|
||||
if (!dlc) {
|
||||
return;
|
||||
}
|
||||
@ -1108,17 +1075,17 @@ static void rfcomm_handle_msc(struct bt_rfcomm_session *session,
|
||||
/* Only FC bit affects the flow on RFCOMM level */
|
||||
if (BT_RFCOMM_GET_FC(msc->v24_signal)) {
|
||||
/* If FC bit is 1 the device is unable to accept frames.
|
||||
* Take the semaphore with timeout K_NO_WAIT so that
|
||||
* dlc thread will be blocked when it tries sem_take
|
||||
* before sending the data. K_NO_WAIT timeout will make
|
||||
* sure that RX thread will not be blocked while taking
|
||||
* the semaphore.
|
||||
*/
|
||||
* Take the semaphore with timeout K_NO_WAIT so that
|
||||
* dlc thread will be blocked when it tries sem_take
|
||||
* before sending the data. K_NO_WAIT timeout will make
|
||||
* sure that RX thread will not be blocked while taking
|
||||
* the semaphore.
|
||||
*/
|
||||
k_sem_take(&dlc->tx_credits, K_NO_WAIT);
|
||||
} else {
|
||||
/* Give the sem so that it will unblock the waiting dlc
|
||||
* thread in sem_take().
|
||||
*/
|
||||
* thread in sem_take().
|
||||
*/
|
||||
k_sem_give(&dlc->tx_credits);
|
||||
}
|
||||
}
|
||||
@ -1141,7 +1108,6 @@ static void rfcomm_handle_rls(struct bt_rfcomm_session *session,
|
||||
}
|
||||
|
||||
dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci);
|
||||
|
||||
if (!dlc) {
|
||||
return;
|
||||
}
|
||||
@ -1178,8 +1144,8 @@ static void rfcomm_handle_rpn(struct bt_rfcomm_session *session,
|
||||
}
|
||||
|
||||
/* If only one value byte then current port settings has to be returned
|
||||
* We will send default values
|
||||
*/
|
||||
* We will send default values
|
||||
*/
|
||||
default_rpn.dlci = BT_RFCOMM_SET_ADDR(dlci, 1);
|
||||
default_rpn.baud_rate = BT_RFCOMM_RPN_BAUD_RATE_9600;
|
||||
default_rpn.flow_control = BT_RFCOMM_RPN_FLOW_NONE;
|
||||
@ -1203,7 +1169,6 @@ static void rfcomm_handle_pn(struct bt_rfcomm_session *session,
|
||||
struct bt_rfcomm_dlc *dlc;
|
||||
|
||||
dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, pn->dlci);
|
||||
|
||||
if (!dlc) {
|
||||
/* Ignore if it is a response */
|
||||
if (!cr) {
|
||||
@ -1217,7 +1182,6 @@ static void rfcomm_handle_pn(struct bt_rfcomm_session *session,
|
||||
}
|
||||
|
||||
dlc = rfcomm_dlc_accept(session, pn->dlci);
|
||||
|
||||
if (!dlc) {
|
||||
rfcomm_send_dm(session, pn->dlci);
|
||||
return;
|
||||
@ -1231,7 +1195,6 @@ static void rfcomm_handle_pn(struct bt_rfcomm_session *session,
|
||||
if (session->cfc == BT_RFCOMM_CFC_UNKNOWN) {
|
||||
session->cfc = BT_RFCOMM_CFC_SUPPORTED;
|
||||
}
|
||||
|
||||
k_sem_init(&dlc->tx_credits, 0, UINT32_MAX);
|
||||
rfcomm_dlc_tx_give_credits(dlc, pn->credits);
|
||||
} else {
|
||||
@ -1250,7 +1213,6 @@ static void rfcomm_handle_pn(struct bt_rfcomm_session *session,
|
||||
rfcomm_dlc_close(dlc);
|
||||
return;
|
||||
}
|
||||
|
||||
dlc->mtu = MIN(dlc->mtu, sys_le16_to_cpu(pn->mtu));
|
||||
rfcomm_send_pn(dlc, BT_RFCOMM_MSG_RESP_CR);
|
||||
} else {
|
||||
@ -1259,12 +1221,10 @@ static void rfcomm_handle_pn(struct bt_rfcomm_session *session,
|
||||
}
|
||||
|
||||
dlc->mtu = MIN(dlc->mtu, sys_le16_to_cpu(pn->mtu));
|
||||
|
||||
if (pn->flow_ctrl == BT_RFCOMM_PN_CFC_RESP) {
|
||||
if (session->cfc == BT_RFCOMM_CFC_UNKNOWN) {
|
||||
session->cfc = BT_RFCOMM_CFC_SUPPORTED;
|
||||
}
|
||||
|
||||
k_sem_init(&dlc->tx_credits, 0, UINT32_MAX);
|
||||
rfcomm_dlc_tx_give_credits(dlc, pn->credits);
|
||||
} else {
|
||||
@ -1285,7 +1245,6 @@ static void rfcomm_handle_disc(struct bt_rfcomm_session *session, uint8_t dlci)
|
||||
|
||||
if (dlci) {
|
||||
dlc = rfcomm_dlcs_remove_dlci(session->dlcs, dlci);
|
||||
|
||||
if (!dlc) {
|
||||
rfcomm_send_dm(session, dlci);
|
||||
return;
|
||||
@ -1329,28 +1288,22 @@ static void rfcomm_handle_msg(struct bt_rfcomm_session *session,
|
||||
case BT_RFCOMM_PN:
|
||||
rfcomm_handle_pn(session, buf, cr);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_MSC:
|
||||
rfcomm_handle_msc(session, buf, cr);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_RLS:
|
||||
rfcomm_handle_rls(session, buf, cr);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_RPN:
|
||||
rfcomm_handle_rpn(session, buf, cr);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_TEST:
|
||||
if (!cr) {
|
||||
break;
|
||||
}
|
||||
|
||||
rfcomm_send_test(session, BT_RFCOMM_MSG_RESP_CR, buf->data,
|
||||
buf->len - 1);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_FCON:
|
||||
if (session->cfc == BT_RFCOMM_CFC_SUPPORTED) {
|
||||
BT_ERR("FCON received when CFC is supported ");
|
||||
@ -1362,12 +1315,11 @@ static void rfcomm_handle_msg(struct bt_rfcomm_session *session,
|
||||
}
|
||||
|
||||
/* Give the sem so that it will unblock the waiting dlc threads
|
||||
* of this session in sem_take().
|
||||
*/
|
||||
* of this session in sem_take().
|
||||
*/
|
||||
k_sem_give(&session->fc);
|
||||
rfcomm_send_fcon(session, BT_RFCOMM_MSG_RESP_CR);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_FCOFF:
|
||||
if (session->cfc == BT_RFCOMM_CFC_SUPPORTED) {
|
||||
BT_ERR("FCOFF received when CFC is supported ");
|
||||
@ -1379,15 +1331,14 @@ static void rfcomm_handle_msg(struct bt_rfcomm_session *session,
|
||||
}
|
||||
|
||||
/* Take the semaphore with timeout K_NO_WAIT so that all the
|
||||
* dlc threads in this session will be blocked when it tries
|
||||
* sem_take before sending the data. K_NO_WAIT timeout will
|
||||
* make sure that RX thread will not be blocked while taking
|
||||
* the semaphore.
|
||||
*/
|
||||
* dlc threads in this session will be blocked when it tries
|
||||
* sem_take before sending the data. K_NO_WAIT timeout will
|
||||
* make sure that RX thread will not be blocked while taking
|
||||
* the semaphore.
|
||||
*/
|
||||
k_sem_take(&session->fc, K_NO_WAIT);
|
||||
rfcomm_send_fcoff(session, BT_RFCOMM_MSG_RESP_CR);
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_WARN("Unknown/Unsupported RFCOMM Msg type 0x%02x", msg_type);
|
||||
rfcomm_send_nsc(session, hdr->type);
|
||||
@ -1426,7 +1377,6 @@ static void rfcomm_handle_data(struct bt_rfcomm_session *session,
|
||||
BT_DBG("dlci %d, pf %d", dlci, pf);
|
||||
|
||||
dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci);
|
||||
|
||||
if (!dlc) {
|
||||
BT_ERR("Data recvd in non existing DLC");
|
||||
rfcomm_send_dm(session, dlci);
|
||||
@ -1453,7 +1403,6 @@ static void rfcomm_handle_data(struct bt_rfcomm_session *session,
|
||||
|
||||
/* Remove FCS */
|
||||
buf->len -= BT_RFCOMM_FCS_SIZE;
|
||||
|
||||
if (dlc->ops && dlc->ops->recv) {
|
||||
dlc->ops->recv(dlc, buf);
|
||||
}
|
||||
@ -1528,7 +1477,6 @@ static int rfcomm_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
fcs_len = (frame_type == BT_RFCOMM_UIH) ? BT_RFCOMM_FCS_LEN_UIH :
|
||||
BT_RFCOMM_FCS_LEN_NON_UIH;
|
||||
fcs = *(net_buf_tail(buf) - 1);
|
||||
|
||||
if (!rfcomm_check_fcs(fcs_len, buf->data, fcs)) {
|
||||
BT_ERR("FCS check failed");
|
||||
return 0;
|
||||
@ -1544,7 +1492,6 @@ static int rfcomm_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
case BT_RFCOMM_SABM:
|
||||
rfcomm_handle_sabm(session, dlci);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_UIH:
|
||||
if (!dlci) {
|
||||
rfcomm_handle_msg(session, buf);
|
||||
@ -1552,21 +1499,16 @@ static int rfcomm_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
rfcomm_handle_data(session, buf, dlci,
|
||||
BT_RFCOMM_GET_PF(hdr->control));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_DISC:
|
||||
rfcomm_handle_disc(session, dlci);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_UA:
|
||||
rfcomm_handle_ua(session, dlci);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_DM:
|
||||
rfcomm_handle_dm(session, dlci);
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_WARN("Unknown/Unsupported RFCOMM Frame type 0x%02x",
|
||||
frame_type);
|
||||
@ -1620,14 +1562,11 @@ static void rfcomm_session_rtx_timeout(struct k_work *work)
|
||||
case BT_RFCOMM_STATE_CONNECTED:
|
||||
rfcomm_session_disconnect(session);
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_STATE_DISCONNECTING:
|
||||
session->state = BT_RFCOMM_STATE_DISCONNECTED;
|
||||
|
||||
if (bt_l2cap_chan_disconnect(&session->br_chan.chan) < 0) {
|
||||
session->state = BT_RFCOMM_STATE_IDLE;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1693,10 +1632,8 @@ int bt_rfcomm_dlc_connect(struct bt_conn *conn, struct bt_rfcomm_dlc *dlc,
|
||||
}
|
||||
|
||||
session = rfcomm_sessions_lookup_bt_conn(conn);
|
||||
|
||||
if (!session) {
|
||||
session = rfcomm_session_new(BT_RFCOMM_ROLE_INITIATOR);
|
||||
|
||||
if (!session) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -1716,33 +1653,25 @@ int bt_rfcomm_dlc_connect(struct bt_conn *conn, struct bt_rfcomm_dlc *dlc,
|
||||
/* There is an ongoing incoming conn */
|
||||
break;
|
||||
}
|
||||
|
||||
chan = &session->br_chan.chan;
|
||||
chan->required_sec_level = dlc->required_sec_level;
|
||||
ret = bt_l2cap_chan_connect(conn, chan, BT_L2CAP_PSM_RFCOMM);
|
||||
|
||||
if (ret < 0) {
|
||||
session->state = BT_RFCOMM_STATE_IDLE;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
session->state = BT_RFCOMM_STATE_CONNECTING;
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_STATE_CONNECTING:
|
||||
break;
|
||||
|
||||
case BT_RFCOMM_STATE_CONNECTED:
|
||||
ret = rfcomm_dlc_start(dlc);
|
||||
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Cancel idle timer if any */
|
||||
k_delayed_work_cancel(&session->rtx_work);
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("Invalid session state %d", session->state);
|
||||
ret = -EINVAL;
|
||||
@ -1768,10 +1697,10 @@ int bt_rfcomm_dlc_disconnect(struct bt_rfcomm_dlc *dlc)
|
||||
|
||||
if (dlc->state == BT_RFCOMM_STATE_CONNECTED) {
|
||||
/* This is to handle user initiated disconnect to send pending
|
||||
* bufs in the queue before disconnecting
|
||||
* Queue a dummy buffer (in case if queue is empty) to wake up
|
||||
* and stop the tx thread.
|
||||
*/
|
||||
* bufs in the queue before disconnecting
|
||||
* Queue a dummy buffer (in case if queue is empty) to wake up
|
||||
* and stop the tx thread.
|
||||
*/
|
||||
dlc->state = BT_RFCOMM_STATE_USER_DISCONNECT;
|
||||
net_buf_put(&dlc->tx_queue,
|
||||
net_buf_alloc(&dummy_pool, K_NO_WAIT));
|
||||
@ -1791,7 +1720,6 @@ static int rfcomm_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
||||
BT_DBG("conn %p", conn);
|
||||
|
||||
session = rfcomm_session_new(BT_RFCOMM_ROLE_ACCEPTOR);
|
||||
|
||||
if (session) {
|
||||
*chan = &session->br_chan.chan;
|
||||
return 0;
|
||||
@ -1805,7 +1733,6 @@ static int rfcomm_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
||||
void bt_rfcomm_init(void)
|
||||
{
|
||||
#if defined(BFLB_DYNAMIC_ALLOC_MEM)
|
||||
k_lifo_init(&dummy_pool.free, CONFIG_BT_MAX_CONN);
|
||||
net_buf_init(&dummy_pool, CONFIG_BT_MAX_CONN, 1, NULL);
|
||||
#endif
|
||||
static struct bt_l2cap_server server = {
|
||||
|
@ -282,39 +282,31 @@ static uint16_t parse_data_elem(struct net_buf *buf,
|
||||
data_elem->data_size = BIT(data_elem->type &
|
||||
BT_SDP_SIZE_DESC_MASK);
|
||||
break;
|
||||
|
||||
case BT_SDP_TEXT_STR_UNSPEC:
|
||||
case BT_SDP_SEQ_UNSPEC:
|
||||
case BT_SDP_ALT_UNSPEC:
|
||||
case BT_SDP_URL_STR_UNSPEC:
|
||||
size_field_len = BIT((data_elem->type & BT_SDP_SIZE_DESC_MASK) -
|
||||
BT_SDP_SIZE_INDEX_OFFSET);
|
||||
|
||||
if (buf->len < size_field_len) {
|
||||
BT_WARN("Malformed packet");
|
||||
return BT_SDP_INVALID_SYNTAX;
|
||||
}
|
||||
|
||||
switch (size_field_len) {
|
||||
case 1:
|
||||
data_elem->data_size = net_buf_pull_u8(buf);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
data_elem->data_size = net_buf_pull_be16(buf);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
data_elem->data_size = net_buf_pull_be32(buf);
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_WARN("Invalid size in remote request");
|
||||
return BT_SDP_INVALID_SYNTAX;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_WARN("Invalid type in remote request");
|
||||
return BT_SDP_INVALID_SYNTAX;
|
||||
@ -374,21 +366,18 @@ static uint32_t search_uuid(struct bt_sdp_data_elem *elem, struct bt_uuid *uuid,
|
||||
if (seq_size == 2U) {
|
||||
u.uuid.type = BT_UUID_TYPE_16;
|
||||
u.u16.val = *((uint16_t *)cur_elem);
|
||||
|
||||
if (!bt_uuid_cmp(&u.uuid, uuid)) {
|
||||
*found = true;
|
||||
}
|
||||
} else if (seq_size == 4U) {
|
||||
u.uuid.type = BT_UUID_TYPE_32;
|
||||
u.u32.val = *((uint32_t *)cur_elem);
|
||||
|
||||
if (!bt_uuid_cmp(&u.uuid, uuid)) {
|
||||
*found = true;
|
||||
}
|
||||
} else if (seq_size == 16U) {
|
||||
u.uuid.type = BT_UUID_TYPE_128;
|
||||
memcpy(u.u128.val, cur_elem, seq_size);
|
||||
|
||||
if (!bt_uuid_cmp(&u.uuid, uuid)) {
|
||||
*found = true;
|
||||
}
|
||||
@ -404,11 +393,9 @@ static uint32_t search_uuid(struct bt_sdp_data_elem *elem, struct bt_uuid *uuid,
|
||||
/* Recursively parse data elements */
|
||||
size = search_uuid((struct bt_sdp_data_elem *)cur_elem,
|
||||
uuid, found, nest_level + 1);
|
||||
|
||||
if (*found) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cur_elem += sizeof(struct bt_sdp_data_elem);
|
||||
seq_size -= size;
|
||||
} while (seq_size);
|
||||
@ -439,7 +426,6 @@ static struct bt_sdp_record *bt_sdp_foreach_svc(bt_sdp_svc_func_t func,
|
||||
|
||||
rec = rec->next;
|
||||
}
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
@ -491,7 +477,6 @@ static uint16_t find_services(struct net_buf *buf,
|
||||
} u;
|
||||
|
||||
res = parse_data_elem(buf, &data_elem);
|
||||
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
@ -510,7 +495,6 @@ static uint16_t find_services(struct net_buf *buf,
|
||||
/* Go over the sequence of UUIDs, and match one UUID at a time */
|
||||
while (uuid_list_size) {
|
||||
res = parse_data_elem(buf, &data_elem);
|
||||
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
@ -547,8 +531,8 @@ static uint16_t find_services(struct net_buf *buf,
|
||||
uuid_list_size -= data_elem.total_size;
|
||||
|
||||
/* Go over the list of services, and look for a service which
|
||||
* doesn't have this UUID
|
||||
*/
|
||||
* doesn't have this UUID
|
||||
*/
|
||||
for (rec_idx = 0U; rec_idx < num_services; rec_idx++) {
|
||||
record = matching_recs[rec_idx];
|
||||
|
||||
@ -563,15 +547,14 @@ static uint16_t find_services(struct net_buf *buf,
|
||||
att_idx++) {
|
||||
search_uuid(&record->attrs[att_idx].val,
|
||||
&u.uuid, &found, 1);
|
||||
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove the record from the list if it doesn't have
|
||||
* the UUID
|
||||
*/
|
||||
* the UUID
|
||||
*/
|
||||
if (!found) {
|
||||
matching_recs[rec_idx] = NULL;
|
||||
}
|
||||
@ -603,7 +586,6 @@ static uint16_t sdp_svc_search_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
bool pkt_full = false;
|
||||
|
||||
res = find_services(buf, matching_recs);
|
||||
|
||||
if (res) {
|
||||
/* Error in parsing */
|
||||
return res;
|
||||
@ -630,8 +612,8 @@ static uint16_t sdp_svc_search_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
}
|
||||
|
||||
/* We send out only SDP_SS_CONT_STATE_SIZE bytes continuation state in
|
||||
* responses, so expect only SDP_SS_CONT_STATE_SIZE bytes in requests
|
||||
*/
|
||||
* responses, so expect only SDP_SS_CONT_STATE_SIZE bytes in requests
|
||||
*/
|
||||
if (cont_state_size) {
|
||||
if (cont_state_size != SDP_SS_CONT_STATE_SIZE) {
|
||||
BT_WARN("Invalid cont state size %u", cont_state_size);
|
||||
@ -645,8 +627,8 @@ static uint16_t sdp_svc_search_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
|
||||
cont_state = net_buf_pull_u8(buf);
|
||||
/* We include total_recs in the continuation state. We calculate
|
||||
* it once and preserve it across all the partial responses
|
||||
*/
|
||||
* it once and preserve it across all the partial responses
|
||||
*/
|
||||
total_recs = net_buf_pull_be16(buf);
|
||||
}
|
||||
|
||||
@ -686,9 +668,9 @@ static uint16_t sdp_svc_search_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
net_buf_add_u8(resp_buf, cont_state);
|
||||
|
||||
/* If it is the first packet of a partial response,
|
||||
* continue dry-running to calculate total_recs.
|
||||
* Else break
|
||||
*/
|
||||
* continue dry-running to calculate total_recs.
|
||||
* Else break
|
||||
*/
|
||||
if (cont_state_size) {
|
||||
break;
|
||||
}
|
||||
@ -750,19 +732,17 @@ static uint32_t copy_attribute(struct bt_sdp_data_elem *elem,
|
||||
case 1:
|
||||
net_buf_add_u8(buf, elem->data_size);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
net_buf_add_be16(buf, elem->data_size);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
net_buf_add_be32(buf, elem->data_size);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Recursively parse (till the last element is not another data element)
|
||||
* and then fill the elements
|
||||
*/
|
||||
* and then fill the elements
|
||||
*/
|
||||
if ((elem->type & BT_SDP_TYPE_DESC_MASK) == BT_SDP_SEQ_UNSPEC ||
|
||||
(elem->type & BT_SDP_TYPE_DESC_MASK) == BT_SDP_ALT_UNSPEC) {
|
||||
do {
|
||||
@ -859,9 +839,9 @@ static uint8_t select_attrs(struct bt_sdp_attribute *attr, uint8_t att_idx,
|
||||
attr_size = 3 + attr->val.total_size;
|
||||
|
||||
/* If this is the first attribute of the service, then we need
|
||||
* to account for the space required to add the per-service
|
||||
* data element sequence header as well.
|
||||
*/
|
||||
* to account for the space required to add the per-service
|
||||
* data element sequence header as well.
|
||||
*/
|
||||
if ((sad->state->current_svc != sad->rec->index) &&
|
||||
sad->new_service) {
|
||||
/* 3 bytes for Per-Service Data Elem Seq declaration */
|
||||
@ -885,8 +865,8 @@ static uint8_t select_attrs(struct bt_sdp_attribute *attr, uint8_t att_idx,
|
||||
/* Keep filling data only if packet is not exhausted */
|
||||
if (!sad->state->pkt_full && sad->rsp_buf) {
|
||||
/* Add Per-Service Data Element Seq declaration once
|
||||
* only when we are starting from the first attribute
|
||||
*/
|
||||
* only when we are starting from the first attribute
|
||||
*/
|
||||
if (!sad->seq &&
|
||||
(sad->state->current_svc != sad->rec->index)) {
|
||||
sad->seq = net_buf_add(sad->rsp_buf,
|
||||
@ -910,14 +890,14 @@ static uint8_t select_attrs(struct bt_sdp_attribute *attr, uint8_t att_idx,
|
||||
|
||||
if (sad->seq) {
|
||||
/* Keep adding the sequence size if this packet contains
|
||||
* the Per-Service Data Element Seq declaration header
|
||||
*/
|
||||
* the Per-Service Data Element Seq declaration header
|
||||
*/
|
||||
sad->seq->size += attr_size;
|
||||
sad->state->att_list_size += seq_size;
|
||||
} else {
|
||||
/* Keep adding the total attr lists size if:
|
||||
* It's a dry-run, calculating the total attr lists size
|
||||
*/
|
||||
* It's a dry-run, calculating the total attr lists size
|
||||
*/
|
||||
sad->state->att_list_size += seq_size;
|
||||
}
|
||||
|
||||
@ -926,12 +906,12 @@ static uint8_t select_attrs(struct bt_sdp_attribute *attr, uint8_t att_idx,
|
||||
}
|
||||
|
||||
/* End the search if:
|
||||
* 1. We have exhausted the packet
|
||||
* AND
|
||||
* 2. This packet doesn't contain the service element declaration header
|
||||
* AND
|
||||
* 3. This is not a dry-run (then we look for other attrs that match)
|
||||
*/
|
||||
* 1. We have exhausted the packet
|
||||
* AND
|
||||
* 2. This packet doesn't contain the service element declaration header
|
||||
* AND
|
||||
* 3. This is not a dry-run (then we look for other attrs that match)
|
||||
*/
|
||||
if (sad->state->pkt_full && !sad->seq && sad->rsp_buf) {
|
||||
return BT_SDP_ITER_STOP;
|
||||
}
|
||||
@ -1011,7 +991,6 @@ static uint16_t get_att_search_list(struct net_buf *buf, uint32_t *filter,
|
||||
|
||||
*num_filters = 0U;
|
||||
res = parse_data_elem(buf, &data_elem);
|
||||
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
@ -1020,7 +999,6 @@ static uint16_t get_att_search_list(struct net_buf *buf, uint32_t *filter,
|
||||
|
||||
while (size) {
|
||||
res = parse_data_elem(buf, &data_elem);
|
||||
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
@ -1110,7 +1088,6 @@ static uint16_t sdp_svc_att_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
|
||||
/* Set up the filters */
|
||||
res = get_att_search_list(buf, filter, &num_filters);
|
||||
|
||||
if (res) {
|
||||
/* Error in parsing */
|
||||
return res;
|
||||
@ -1124,8 +1101,8 @@ static uint16_t sdp_svc_att_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
cont_state_size = net_buf_pull_u8(buf);
|
||||
|
||||
/* We only send out 1 byte continuation state in responses,
|
||||
* so expect only 1 byte in requests
|
||||
*/
|
||||
* so expect only 1 byte in requests
|
||||
*/
|
||||
if (cont_state_size) {
|
||||
if (cont_state_size != SDP_SA_CONT_STATE_SIZE) {
|
||||
BT_WARN("Invalid cont state size %u", cont_state_size);
|
||||
@ -1219,7 +1196,6 @@ static uint16_t sdp_svc_search_att_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
bool dry_run = false;
|
||||
|
||||
res = find_services(buf, matching_recs);
|
||||
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
@ -1247,8 +1223,8 @@ static uint16_t sdp_svc_search_att_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
cont_state_size = net_buf_pull_u8(buf);
|
||||
|
||||
/* We only send out 2 bytes continuation state in responses,
|
||||
* so expect only 2 bytes in requests
|
||||
*/
|
||||
* so expect only 2 bytes in requests
|
||||
*/
|
||||
if (cont_state_size) {
|
||||
if (cont_state_size != SDP_SSA_CONT_STATE_SIZE) {
|
||||
BT_WARN("Invalid cont state size %u", cont_state_size);
|
||||
@ -1309,8 +1285,8 @@ static uint16_t sdp_svc_search_att_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
net_buf_add_u8(rsp_buf, state.last_att);
|
||||
|
||||
/* Break if it's not a partial response, else dry-run
|
||||
* Dry run: Look for other services that match
|
||||
*/
|
||||
* Dry run: Look for other services that match
|
||||
*/
|
||||
if (cont_state_size) {
|
||||
break;
|
||||
}
|
||||
@ -1328,13 +1304,11 @@ static uint16_t sdp_svc_search_att_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
net_buf_add_u8(rsp_buf, 0);
|
||||
att_list_len = 2U;
|
||||
}
|
||||
|
||||
/* Search exhausted */
|
||||
net_buf_add_u8(rsp_buf, 0);
|
||||
}
|
||||
|
||||
rsp->att_list_len = sys_cpu_to_be16(att_list_len);
|
||||
|
||||
if (seq) {
|
||||
seq->size = sys_cpu_to_be16(state.att_list_size);
|
||||
}
|
||||
@ -1346,8 +1320,7 @@ static uint16_t sdp_svc_search_att_req(struct bt_sdp *sdp, struct net_buf *buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct
|
||||
{
|
||||
static const struct {
|
||||
uint8_t op_code;
|
||||
uint16_t (*func)(struct bt_sdp *sdp, struct net_buf *buf, uint16_t tid);
|
||||
} handlers[] = {
|
||||
@ -1452,7 +1425,6 @@ static int bt_sdp_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
||||
void bt_sdp_init(void)
|
||||
{
|
||||
#if defined(BFLB_DYNAMIC_ALLOC_MEM)
|
||||
k_lifo_init(&sdp_pool.free, CONFIG_BT_MAX_CONN);
|
||||
net_buf_init(&sdp_pool, CONFIG_BT_MAX_CONN, BT_L2CAP_BUF_SIZE(SDP_MTU), NULL);
|
||||
#endif
|
||||
static struct bt_l2cap_server server = {
|
||||
@ -1463,7 +1435,6 @@ void bt_sdp_init(void)
|
||||
int res;
|
||||
|
||||
res = bt_l2cap_br_server_register(&server);
|
||||
|
||||
if (res) {
|
||||
BT_ERR("L2CAP server registration failed with error %d", res);
|
||||
}
|
||||
@ -1509,11 +1480,11 @@ static int sdp_client_ssa_search(struct bt_sdp_client *session)
|
||||
struct net_buf *buf;
|
||||
|
||||
/*
|
||||
* Select proper user params, if session->param is invalid it means
|
||||
* getting new UUID from top of to be resolved params list. Otherwise
|
||||
* the context is in a middle of partial SDP PDU responses and cached
|
||||
* value from context can be used.
|
||||
*/
|
||||
* Select proper user params, if session->param is invalid it means
|
||||
* getting new UUID from top of to be resolved params list. Otherwise
|
||||
* the context is in a middle of partial SDP PDU responses and cached
|
||||
* value from context can be used.
|
||||
*/
|
||||
if (!session->param) {
|
||||
param = GET_PARAM(sys_slist_peek_head(&session->reqs));
|
||||
} else {
|
||||
@ -1542,20 +1513,17 @@ static int sdp_client_ssa_search(struct bt_sdp_client *session)
|
||||
/* Seq value */
|
||||
net_buf_add_be16(buf, BT_UUID_16(param->uuid)->val);
|
||||
break;
|
||||
|
||||
case BT_UUID_TYPE_32:
|
||||
net_buf_add_u8(buf, 0x05);
|
||||
net_buf_add_u8(buf, BT_SDP_UUID32);
|
||||
net_buf_add_be32(buf, BT_UUID_32(param->uuid)->val);
|
||||
break;
|
||||
|
||||
case BT_UUID_TYPE_128:
|
||||
net_buf_add_u8(buf, 0x11);
|
||||
net_buf_add_u8(buf, BT_SDP_UUID128);
|
||||
net_buf_add_mem(buf, BT_UUID_128(param->uuid)->val,
|
||||
ARRAY_SIZE(BT_UUID_128(param->uuid)->val));
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("Unknown UUID type %u", param->uuid->type);
|
||||
return -EINVAL;
|
||||
@ -1564,9 +1532,9 @@ static int sdp_client_ssa_search(struct bt_sdp_client *session)
|
||||
/* Set attribute max bytes count to be returned from server */
|
||||
net_buf_add_be16(buf, BT_SDP_MAX_ATTR_LEN);
|
||||
/*
|
||||
* Sequence definition where data is sequence of elements and where
|
||||
* additional next byte points the size of elements within
|
||||
*/
|
||||
* Sequence definition where data is sequence of elements and where
|
||||
* additional next byte points the size of elements within
|
||||
*/
|
||||
net_buf_add_u8(buf, BT_SDP_SEQ8);
|
||||
net_buf_add_u8(buf, 0x05);
|
||||
/* Data element definition for two following 16bits range elements */
|
||||
@ -1576,11 +1544,11 @@ static int sdp_client_ssa_search(struct bt_sdp_client *session)
|
||||
net_buf_add_be16(buf, 0xffff);
|
||||
|
||||
/*
|
||||
* Update and validate PDU ContinuationState. Initial SSA Request has
|
||||
* zero length continuation state since no interaction has place with
|
||||
* server so far, otherwise use the original state taken from remote's
|
||||
* last response PDU that is cached by SDP client context.
|
||||
*/
|
||||
* Update and validate PDU ContinuationState. Initial SSA Request has
|
||||
* zero length continuation state since no interaction has place with
|
||||
* server so far, otherwise use the original state taken from remote's
|
||||
* last response PDU that is cached by SDP client context.
|
||||
*/
|
||||
if (session->cstate.length == 0U) {
|
||||
net_buf_add_u8(buf, 0x00);
|
||||
} else {
|
||||
@ -1639,27 +1607,24 @@ static uint16_t sdp_client_get_total(struct bt_sdp_client *session,
|
||||
uint8_t seq;
|
||||
|
||||
/*
|
||||
* Pull value of total octets of all attributes available to be
|
||||
* collected when response gets completed for given UUID. Such info can
|
||||
* be get from the very first response frame after initial SSA request
|
||||
* was sent. For subsequent calls related to the same SSA request input
|
||||
* buf and in/out function parameters stays neutral.
|
||||
*/
|
||||
* Pull value of total octets of all attributes available to be
|
||||
* collected when response gets completed for given UUID. Such info can
|
||||
* be get from the very first response frame after initial SSA request
|
||||
* was sent. For subsequent calls related to the same SSA request input
|
||||
* buf and in/out function parameters stays neutral.
|
||||
*/
|
||||
if (session->cstate.length == 0U) {
|
||||
seq = net_buf_pull_u8(buf);
|
||||
pulled = 1U;
|
||||
|
||||
switch (seq) {
|
||||
case BT_SDP_SEQ8:
|
||||
*total = net_buf_pull_u8(buf);
|
||||
pulled += 1U;
|
||||
break;
|
||||
|
||||
case BT_SDP_SEQ16:
|
||||
*total = net_buf_pull_be16(buf);
|
||||
pulled += 2U;
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_WARN("Sequence type 0x%02x not handled", seq);
|
||||
*total = 0U;
|
||||
@ -1686,11 +1651,9 @@ static uint16_t get_record_len(struct net_buf *buf)
|
||||
case BT_SDP_SEQ8:
|
||||
len = net_buf_pull_u8(buf);
|
||||
break;
|
||||
|
||||
case BT_SDP_SEQ16:
|
||||
len = net_buf_pull_be16(buf);
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_WARN("Sequence type 0x%02x not handled", seq);
|
||||
len = 0U;
|
||||
@ -1728,7 +1691,6 @@ static void sdp_client_notify_result(struct bt_sdp_client *session,
|
||||
struct net_buf_simple_state buf_state;
|
||||
|
||||
rec_len = get_record_len(session->rec_buf);
|
||||
|
||||
/* tell the user about multi record resolution */
|
||||
if (session->rec_buf->len > rec_len) {
|
||||
result.next_record_hint = true;
|
||||
@ -1741,10 +1703,10 @@ static void sdp_client_notify_result(struct bt_sdp_client *session,
|
||||
/* initialize internal result buffer instead of memcpy */
|
||||
result.resp_buf = session->rec_buf;
|
||||
/*
|
||||
* Set user internal result buffer length as same as record
|
||||
* length to fake user. User will see the individual record
|
||||
* length as rec_len insted of whole session rec_buf length.
|
||||
*/
|
||||
* Set user internal result buffer length as same as record
|
||||
* length to fake user. User will see the individual record
|
||||
* length as rec_len insted of whole session rec_buf length.
|
||||
*/
|
||||
result.resp_buf->len = rec_len;
|
||||
|
||||
user_ret = session->param->func(conn, &result);
|
||||
@ -1752,11 +1714,10 @@ static void sdp_client_notify_result(struct bt_sdp_client *session,
|
||||
/* restore original session buffer */
|
||||
net_buf_simple_restore(&session->rec_buf->b, &buf_state);
|
||||
/*
|
||||
* sync session buffer data length with next record chunk not
|
||||
* send to user so far
|
||||
*/
|
||||
* sync session buffer data length with next record chunk not
|
||||
* send to user so far
|
||||
*/
|
||||
net_buf_pull(session->rec_buf, rec_len);
|
||||
|
||||
if (user_ret == BT_SDP_DISCOVER_UUID_STOP) {
|
||||
break;
|
||||
}
|
||||
@ -1779,7 +1740,6 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
}
|
||||
|
||||
hdr = net_buf_pull_mem(buf, sizeof(*hdr));
|
||||
|
||||
if (hdr->op_code == BT_SDP_ERROR_RSP) {
|
||||
BT_INFO("Error SDP PDU response");
|
||||
return 0;
|
||||
@ -1804,13 +1764,11 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
case BT_SDP_SVC_SEARCH_ATTR_RSP:
|
||||
/* Get number of attributes in this frame. */
|
||||
frame_len = net_buf_pull_be16(buf);
|
||||
|
||||
/* Check valid buf len for attribute list and cont state */
|
||||
if (buf->len < frame_len + SDP_CONT_STATE_LEN_SIZE) {
|
||||
BT_ERR("Invalid frame payload length");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check valid range of attributes length */
|
||||
if (frame_len < 2) {
|
||||
BT_ERR("Invalid attributes data length");
|
||||
@ -1833,10 +1791,10 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
}
|
||||
|
||||
/*
|
||||
* No record found for given UUID. The check catches case when
|
||||
* current response frame has Continuation State shortest and
|
||||
* valid and this is the first response frame as well.
|
||||
*/
|
||||
* No record found for given UUID. The check catches case when
|
||||
* current response frame has Continuation State shortest and
|
||||
* valid and this is the first response frame as well.
|
||||
*/
|
||||
if (frame_len == 2U && cstate->length == 0U &&
|
||||
session->cstate.length == 0U) {
|
||||
BT_DBG("record for UUID 0x%s not found",
|
||||
@ -1859,9 +1817,9 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
net_buf_pull(buf, frame_len);
|
||||
|
||||
/*
|
||||
* check if current response says there's next portion to be
|
||||
* fetched
|
||||
*/
|
||||
* check if current response says there's next portion to be
|
||||
* fetched
|
||||
*/
|
||||
if (cstate->length) {
|
||||
/* Cache original Continuation State in context */
|
||||
memcpy(&session->cstate, cstate,
|
||||
@ -1883,7 +1841,6 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
/* Get next UUID and start resolving it */
|
||||
sdp_client_params_iterator(session);
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_DBG("PDU 0x%0x response not handled", hdr->op_code);
|
||||
break;
|
||||
@ -1933,9 +1890,9 @@ static void sdp_client_disconnected(struct bt_l2cap_chan *chan)
|
||||
net_buf_unref(session->rec_buf);
|
||||
|
||||
/*
|
||||
* Reset session excluding L2CAP channel member. Let's the channel
|
||||
* resets autonomous.
|
||||
*/
|
||||
* Reset session excluding L2CAP channel member. Let's the channel
|
||||
* resets autonomous.
|
||||
*/
|
||||
(void)memset(&session->reqs, 0,
|
||||
sizeof(*session) - sizeof(session->chan));
|
||||
}
|
||||
@ -1966,7 +1923,6 @@ static struct bt_sdp_client *sdp_client_new_session(struct bt_conn *conn)
|
||||
session->chan.rx.mtu = SDP_CLIENT_MTU;
|
||||
|
||||
err = sdp_client_chan_connect(session);
|
||||
|
||||
if (err) {
|
||||
(void)memset(session, 0, sizeof(*session));
|
||||
BT_ERR("Cannot connect %d", err);
|
||||
@ -1992,9 +1948,9 @@ static struct bt_sdp_client *sdp_client_get_session(struct bt_conn *conn)
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to allocate session context since not found in pool and attempt
|
||||
* connect to remote SDP endpoint.
|
||||
*/
|
||||
* Try to allocate session context since not found in pool and attempt
|
||||
* connect to remote SDP endpoint.
|
||||
*/
|
||||
return sdp_client_new_session(conn);
|
||||
}
|
||||
|
||||
@ -2009,7 +1965,6 @@ int bt_sdp_discover(struct bt_conn *conn,
|
||||
}
|
||||
|
||||
session = sdp_client_get_session(conn);
|
||||
|
||||
if (!session) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -2027,7 +1982,6 @@ static inline ssize_t sdp_get_int_len(const uint8_t *data, size_t len)
|
||||
switch (data[0]) {
|
||||
case BT_SDP_DATA_NIL:
|
||||
return 1;
|
||||
|
||||
case BT_SDP_BOOL:
|
||||
case BT_SDP_INT8:
|
||||
case BT_SDP_UINT8:
|
||||
@ -2036,7 +1990,6 @@ static inline ssize_t sdp_get_int_len(const uint8_t *data, size_t len)
|
||||
}
|
||||
|
||||
return 2;
|
||||
|
||||
case BT_SDP_INT16:
|
||||
case BT_SDP_UINT16:
|
||||
if (len < 3) {
|
||||
@ -2044,7 +1997,6 @@ static inline ssize_t sdp_get_int_len(const uint8_t *data, size_t len)
|
||||
}
|
||||
|
||||
return 3;
|
||||
|
||||
case BT_SDP_INT32:
|
||||
case BT_SDP_UINT32:
|
||||
if (len < 5) {
|
||||
@ -2052,7 +2004,6 @@ static inline ssize_t sdp_get_int_len(const uint8_t *data, size_t len)
|
||||
}
|
||||
|
||||
return 5;
|
||||
|
||||
case BT_SDP_INT64:
|
||||
case BT_SDP_UINT64:
|
||||
if (len < 9) {
|
||||
@ -2060,7 +2011,6 @@ static inline ssize_t sdp_get_int_len(const uint8_t *data, size_t len)
|
||||
}
|
||||
|
||||
return 9;
|
||||
|
||||
case BT_SDP_INT128:
|
||||
case BT_SDP_UINT128:
|
||||
default:
|
||||
@ -2084,14 +2034,12 @@ static inline ssize_t sdp_get_uuid_len(const uint8_t *data, size_t len)
|
||||
}
|
||||
|
||||
return 3;
|
||||
|
||||
case BT_SDP_UUID32:
|
||||
if (len < 5) {
|
||||
break;
|
||||
}
|
||||
|
||||
return 5;
|
||||
|
||||
case BT_SDP_UUID128:
|
||||
default:
|
||||
BT_ERR("Invalid/unhandled DTD 0x%02x", data[0]);
|
||||
@ -2124,10 +2072,8 @@ static inline ssize_t sdp_get_str_len(const uint8_t *data, size_t len)
|
||||
}
|
||||
|
||||
return 2 + pnext[0];
|
||||
|
||||
case BT_SDP_TEXT_STR16:
|
||||
case BT_SDP_URL_STR16:
|
||||
|
||||
/* validate len for pnext safe use to read 16bit value */
|
||||
if (len < 3) {
|
||||
break;
|
||||
@ -2138,14 +2084,12 @@ static inline ssize_t sdp_get_str_len(const uint8_t *data, size_t len)
|
||||
}
|
||||
|
||||
return 3 + sys_get_be16(pnext);
|
||||
|
||||
case BT_SDP_TEXT_STR32:
|
||||
case BT_SDP_URL_STR32:
|
||||
default:
|
||||
BT_ERR("Invalid/unhandled DTD 0x%02x", data[0]);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err:
|
||||
BT_ERR("Too short buffer length %zu", len);
|
||||
return -EMSGSIZE;
|
||||
@ -2173,10 +2117,8 @@ static inline ssize_t sdp_get_seq_len(const uint8_t *data, size_t len)
|
||||
}
|
||||
|
||||
return 2 + pnext[0];
|
||||
|
||||
case BT_SDP_SEQ16:
|
||||
case BT_SDP_ALT16:
|
||||
|
||||
/* validate len for pnext safe use to read 16bit value */
|
||||
if (len < 3) {
|
||||
break;
|
||||
@ -2187,14 +2129,12 @@ static inline ssize_t sdp_get_seq_len(const uint8_t *data, size_t len)
|
||||
}
|
||||
|
||||
return 3 + sys_get_be16(pnext);
|
||||
|
||||
case BT_SDP_SEQ32:
|
||||
case BT_SDP_ALT32:
|
||||
default:
|
||||
BT_ERR("Invalid/unhandled DTD 0x%02x", data[0]);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err:
|
||||
BT_ERR("Too short buffer length %zu", len);
|
||||
return -EMSGSIZE;
|
||||
@ -2221,12 +2161,10 @@ static ssize_t sdp_get_attr_value_len(const uint8_t *data, size_t len)
|
||||
case BT_SDP_INT64:
|
||||
case BT_SDP_INT128:
|
||||
return sdp_get_int_len(data, len);
|
||||
|
||||
case BT_SDP_UUID16:
|
||||
case BT_SDP_UUID32:
|
||||
case BT_SDP_UUID128:
|
||||
return sdp_get_uuid_len(data, len);
|
||||
|
||||
case BT_SDP_TEXT_STR8:
|
||||
case BT_SDP_TEXT_STR16:
|
||||
case BT_SDP_TEXT_STR32:
|
||||
@ -2234,7 +2172,6 @@ static ssize_t sdp_get_attr_value_len(const uint8_t *data, size_t len)
|
||||
case BT_SDP_URL_STR16:
|
||||
case BT_SDP_URL_STR32:
|
||||
return sdp_get_str_len(data, len);
|
||||
|
||||
case BT_SDP_SEQ8:
|
||||
case BT_SDP_SEQ16:
|
||||
case BT_SDP_SEQ32:
|
||||
@ -2242,7 +2179,6 @@ static ssize_t sdp_get_attr_value_len(const uint8_t *data, size_t len)
|
||||
case BT_SDP_ALT16:
|
||||
case BT_SDP_ALT32:
|
||||
return sdp_get_seq_len(data, len);
|
||||
|
||||
default:
|
||||
BT_ERR("Unknown DTD 0x%02x", data[0]);
|
||||
return -EINVAL;
|
||||
@ -2266,8 +2202,8 @@ struct bt_sdp_attr_item {
|
||||
/* Attribute identifier. */
|
||||
uint16_t attr_id;
|
||||
/* Address of beginning attribute value taken from original buffer
|
||||
* holding response from server.
|
||||
*/
|
||||
* holding response from server.
|
||||
*/
|
||||
uint8_t *val;
|
||||
/* Says about the length of attribute value. */
|
||||
uint16_t len;
|
||||
@ -2280,7 +2216,6 @@ static int bt_sdp_get_attr(const struct net_buf *buf,
|
||||
uint16_t id;
|
||||
|
||||
data = buf->data;
|
||||
|
||||
while (data - buf->data < buf->len) {
|
||||
ssize_t dlen;
|
||||
|
||||
@ -2297,7 +2232,6 @@ static int bt_sdp_get_attr(const struct net_buf *buf,
|
||||
|
||||
dlen = sdp_get_attr_value_len(data,
|
||||
buf->len - (data - buf->data));
|
||||
|
||||
if (dlen < 0) {
|
||||
BT_ERR("Invalid attribute value data");
|
||||
return -EINVAL;
|
||||
@ -2306,9 +2240,9 @@ static int bt_sdp_get_attr(const struct net_buf *buf,
|
||||
if (id == attr_id) {
|
||||
BT_DBG("Attribute ID 0x%04x Value found", id);
|
||||
/*
|
||||
* Initialize attribute value buffer data using selected
|
||||
* data slice from original buffer.
|
||||
*/
|
||||
* Initialize attribute value buffer data using selected
|
||||
* data slice from original buffer.
|
||||
*/
|
||||
attr->val = data;
|
||||
attr->len = dlen;
|
||||
attr->attr_id = id;
|
||||
@ -2344,9 +2278,7 @@ static ssize_t sdp_get_seq_len_item(uint8_t **data, size_t len)
|
||||
|
||||
*data += 2;
|
||||
return pnext[0];
|
||||
|
||||
case BT_SDP_SEQ16:
|
||||
|
||||
/* validate len for pnext safe use to read 16bit value */
|
||||
if (len < 3) {
|
||||
break;
|
||||
@ -2358,9 +2290,7 @@ static ssize_t sdp_get_seq_len_item(uint8_t **data, size_t len)
|
||||
|
||||
*data += 3;
|
||||
return sys_get_be16(pnext);
|
||||
|
||||
case BT_SDP_SEQ32:
|
||||
|
||||
/* validate len for pnext safe use to read 32bit value */
|
||||
if (len < 5) {
|
||||
break;
|
||||
@ -2372,12 +2302,10 @@ static ssize_t sdp_get_seq_len_item(uint8_t **data, size_t len)
|
||||
|
||||
*data += 5;
|
||||
return sys_get_be32(pnext);
|
||||
|
||||
default:
|
||||
BT_ERR("Invalid/unhandled DTD 0x%02x", *data[0]);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err:
|
||||
BT_ERR("Too short buffer length %zu", len);
|
||||
return -EMSGSIZE;
|
||||
@ -2395,7 +2323,6 @@ static int sdp_get_uuid_data(const struct bt_sdp_attr_item *attr,
|
||||
|
||||
/* Attribute value is a SEQ, get length of parent SEQ frame */
|
||||
slen = sdp_get_seq_len_item(&p, attr->len);
|
||||
|
||||
if (slen < 0) {
|
||||
return slen;
|
||||
}
|
||||
@ -2408,7 +2335,6 @@ static int sdp_get_uuid_data(const struct bt_sdp_attr_item *attr,
|
||||
to_end = attr->len - (p - attr->val);
|
||||
/* how long is current UUID's item data associated to */
|
||||
slen = sdp_get_seq_len_item(&p, to_end);
|
||||
|
||||
if (slen < 0) {
|
||||
return slen;
|
||||
}
|
||||
@ -2430,9 +2356,7 @@ static int sdp_get_uuid_data(const struct bt_sdp_attr_item *attr,
|
||||
p += sizeof(uint16_t);
|
||||
left -= sizeof(uint16_t);
|
||||
break;
|
||||
|
||||
case BT_SDP_UUID32:
|
||||
|
||||
/* check if valid UUID32 can be read safely */
|
||||
if (left < 5) {
|
||||
return -EMSGSIZE;
|
||||
@ -2444,7 +2368,6 @@ static int sdp_get_uuid_data(const struct bt_sdp_attr_item *attr,
|
||||
p += sizeof(uint32_t);
|
||||
left -= sizeof(uint32_t);
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("Invalid/unhandled DTD 0x%02x\n", p[0]);
|
||||
return -EINVAL;
|
||||
@ -2454,9 +2377,9 @@ static int sdp_get_uuid_data(const struct bt_sdp_attr_item *attr,
|
||||
left -= sizeof(p[0]);
|
||||
|
||||
/*
|
||||
* Check if current UUID value matches input one given by user.
|
||||
* If found save it's location and length and return.
|
||||
*/
|
||||
* Check if current UUID value matches input one given by user.
|
||||
* If found save it's location and length and return.
|
||||
*/
|
||||
if ((proto_profile == BT_UUID_16(&pd->uuid)->val) ||
|
||||
(proto_profile == BT_UUID_32(&pd->uuid)->val)) {
|
||||
pd->params = p;
|
||||
@ -2489,50 +2412,40 @@ static int sdp_get_param_item(struct bt_sdp_uuid_desc *pd_item, uint16_t *param)
|
||||
|
||||
switch (p[0]) {
|
||||
case BT_SDP_UINT8:
|
||||
|
||||
/* check if 8bits value can be read safely */
|
||||
if (pd_item->params_len < 2) {
|
||||
len_err = true;
|
||||
break;
|
||||
}
|
||||
|
||||
*param = (++p)[0];
|
||||
p += sizeof(uint8_t);
|
||||
break;
|
||||
|
||||
case BT_SDP_UINT16:
|
||||
|
||||
/* check if 16bits value can be read safely */
|
||||
if (pd_item->params_len < 3) {
|
||||
len_err = true;
|
||||
break;
|
||||
}
|
||||
|
||||
*param = sys_get_be16(++p);
|
||||
p += sizeof(uint16_t);
|
||||
break;
|
||||
|
||||
case BT_SDP_UINT32:
|
||||
|
||||
/* check if 32bits value can be read safely */
|
||||
if (pd_item->params_len < 5) {
|
||||
len_err = true;
|
||||
break;
|
||||
}
|
||||
|
||||
*param = sys_get_be32(++p);
|
||||
p += sizeof(uint32_t);
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_ERR("Invalid/unhandled DTD 0x%02x\n", p[0]);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if no more data than already read is associated with UUID. In
|
||||
* valid case after getting parameter we should reach data buf end.
|
||||
*/
|
||||
* Check if no more data than already read is associated with UUID. In
|
||||
* valid case after getting parameter we should reach data buf end.
|
||||
*/
|
||||
if (p - pd_item->params != pd_item->params_len || len_err) {
|
||||
BT_DBG("Invalid param buffer length");
|
||||
return -EMSGSIZE;
|
||||
@ -2554,7 +2467,6 @@ int bt_sdp_get_proto_param(const struct net_buf *buf, enum bt_sdp_proto proto,
|
||||
}
|
||||
|
||||
res = bt_sdp_get_attr(buf, &attr, BT_SDP_ATTR_PROTO_DESC_LIST);
|
||||
|
||||
if (res < 0) {
|
||||
BT_WARN("Attribute 0x%04x not found, err %d",
|
||||
BT_SDP_ATTR_PROTO_DESC_LIST, res);
|
||||
@ -2562,7 +2474,6 @@ int bt_sdp_get_proto_param(const struct net_buf *buf, enum bt_sdp_proto proto,
|
||||
}
|
||||
|
||||
res = sdp_get_uuid_data(&attr, &pd, proto);
|
||||
|
||||
if (res < 0) {
|
||||
BT_WARN("Protocol specifier 0x%04x not found, err %d", proto,
|
||||
res);
|
||||
@ -2580,7 +2491,6 @@ int bt_sdp_get_profile_version(const struct net_buf *buf, uint16_t profile,
|
||||
int res;
|
||||
|
||||
res = bt_sdp_get_attr(buf, &attr, BT_SDP_ATTR_PROFILE_DESC_LIST);
|
||||
|
||||
if (res < 0) {
|
||||
BT_WARN("Attribute 0x%04x not found, err %d",
|
||||
BT_SDP_ATTR_PROFILE_DESC_LIST, res);
|
||||
@ -2588,7 +2498,6 @@ int bt_sdp_get_profile_version(const struct net_buf *buf, uint16_t profile,
|
||||
}
|
||||
|
||||
res = sdp_get_uuid_data(&attr, &pd, profile);
|
||||
|
||||
if (res < 0) {
|
||||
BT_WARN("Profile 0x%04x not found, err %d", profile, res);
|
||||
return res;
|
||||
@ -2604,7 +2513,6 @@ int bt_sdp_get_features(const struct net_buf *buf, uint16_t *features)
|
||||
int res;
|
||||
|
||||
res = bt_sdp_get_attr(buf, &attr, BT_SDP_ATTR_SUPPORTED_FEATURES);
|
||||
|
||||
if (res < 0) {
|
||||
BT_WARN("Attribute 0x%04x not found, err %d",
|
||||
BT_SDP_ATTR_SUPPORTED_FEATURES, res);
|
||||
|
@ -55,12 +55,11 @@ void bt_settings_encode_key(char *path, size_t path_size, const char *subsys,
|
||||
/* Skip if path_size is less than 3; strlen("bt/") */
|
||||
if (len < path_size) {
|
||||
/* Key format:
|
||||
* "bt/<subsys>/<addr><type>/<key>", "/<key>" is optional
|
||||
*/
|
||||
* "bt/<subsys>/<addr><type>/<key>", "/<key>" is optional
|
||||
*/
|
||||
strcpy(path, "bt/");
|
||||
strncpy(&path[len], subsys, path_size - len);
|
||||
len = strlen(path);
|
||||
|
||||
if (len < path_size) {
|
||||
path[len] = '/';
|
||||
len++;
|
||||
@ -73,8 +72,8 @@ void bt_settings_encode_key(char *path, size_t path_size, const char *subsys,
|
||||
|
||||
if (len < path_size) {
|
||||
/* Type can be either BT_ADDR_LE_PUBLIC or
|
||||
* BT_ADDR_LE_RANDOM (value 0 or 1)
|
||||
*/
|
||||
* BT_ADDR_LE_RANDOM (value 0 or 1)
|
||||
*/
|
||||
path[len] = '0' + addr->type;
|
||||
len++;
|
||||
}
|
||||
@ -143,7 +142,6 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
}
|
||||
|
||||
len = read_cb(cb_arg, &bt_dev.id_addr, sizeof(bt_dev.id_addr));
|
||||
|
||||
if (len < sizeof(bt_dev.id_addr[0])) {
|
||||
if (len < 0) {
|
||||
BT_ERR("Failed to read ID address from storage"
|
||||
@ -154,7 +152,6 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
BT_HEXDUMP_DBG(&bt_dev.id_addr, len,
|
||||
"data read");
|
||||
}
|
||||
|
||||
(void)memset(bt_dev.id_addr, 0,
|
||||
sizeof(bt_dev.id_addr));
|
||||
bt_dev.id_count = 0U;
|
||||
@ -162,7 +159,6 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
int i;
|
||||
|
||||
bt_dev.id_count = len / sizeof(bt_dev.id_addr[0]);
|
||||
|
||||
for (i = 0; i < bt_dev.id_count; i++) {
|
||||
BT_DBG("ID[%d] %s", i,
|
||||
bt_addr_le_str(&bt_dev.id_addr[i]));
|
||||
@ -173,10 +169,8 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC)
|
||||
|
||||
if (!strncmp(name, "name", len)) {
|
||||
len = read_cb(cb_arg, &bt_dev.name, sizeof(bt_dev.name) - 1);
|
||||
|
||||
if (len < 0) {
|
||||
BT_ERR("Failed to read device name from storage"
|
||||
" (err %zu)",
|
||||
@ -186,17 +180,13 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
|
||||
BT_DBG("Name set to %s", log_strdup(bt_dev.name));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_PRIVACY)
|
||||
|
||||
if (!strncmp(name, "irk", len)) {
|
||||
len = read_cb(cb_arg, bt_dev.irk, sizeof(bt_dev.irk));
|
||||
|
||||
if (len < sizeof(bt_dev.irk[0])) {
|
||||
if (len < 0) {
|
||||
BT_ERR("Failed to read IRK from storage"
|
||||
@ -210,7 +200,6 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
int i, count;
|
||||
|
||||
count = len / sizeof(bt_dev.irk[0]);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
BT_DBG("IRK[%d] %s", i,
|
||||
bt_hex(bt_dev.irk[i], 16));
|
||||
@ -219,7 +208,6 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_PRIVACY */
|
||||
|
||||
return -ENOENT;
|
||||
@ -233,18 +221,15 @@ static void save_id(struct k_work *work)
|
||||
BT_INFO("Saving ID");
|
||||
err = settings_save_one("bt/id", &bt_dev.id_addr,
|
||||
ID_DATA_LEN(bt_dev.id_addr));
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Failed to save ID (err %d)", err);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_PRIVACY)
|
||||
err = settings_save_one("bt/irk", bt_dev.irk, ID_DATA_LEN(bt_dev.irk));
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Failed to save IRK (err %d)", err);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -259,10 +244,8 @@ int bt_check_if_ef_ready()
|
||||
|
||||
if (!ef_ready_flag) {
|
||||
err = easyflash_init();
|
||||
|
||||
if (!err) {
|
||||
if (!err)
|
||||
ef_ready_flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
@ -275,10 +258,8 @@ int bt_settings_set_bin(const char *key, const uint8_t *value, size_t length)
|
||||
int err;
|
||||
|
||||
err = bt_check_if_ef_ready();
|
||||
|
||||
if (err) {
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
str_value = pvPortMalloc(length * 2 + 1);
|
||||
|
||||
@ -288,7 +269,6 @@ int bt_settings_set_bin(const char *key, const uint8_t *value, size_t length)
|
||||
str_value[(i * 2) + 0] = lookup[(value[i] >> 4) & 0x0F];
|
||||
str_value[(i * 2) + 1] = lookup[value[i] & 0x0F];
|
||||
}
|
||||
|
||||
str_value[length * 2] = '\0';
|
||||
|
||||
err = ef_set_env(key, (const char *)str_value);
|
||||
@ -306,13 +286,10 @@ int bt_settings_get_bin(const char *key, u8_t *value, size_t exp_len, size_t *re
|
||||
int err;
|
||||
|
||||
err = bt_check_if_ef_ready();
|
||||
|
||||
if (err) {
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
str_value = ef_get_env(key);
|
||||
|
||||
if (str_value == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -323,9 +300,8 @@ int bt_settings_get_bin(const char *key, u8_t *value, size_t exp_len, size_t *re
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (real_len) {
|
||||
if (real_len)
|
||||
*real_len = str_value_len / 2;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < str_value_len / 2; i++) {
|
||||
strncpy(rand, str_value + 2 * i, 2);
|
||||
@ -352,11 +328,8 @@ void bt_settings_save_id(void)
|
||||
{
|
||||
#if defined(BFLB_BLE)
|
||||
#if defined(CONFIG_BT_SETTINGS)
|
||||
|
||||
if (bt_check_if_ef_ready()) {
|
||||
if (bt_check_if_ef_ready())
|
||||
return;
|
||||
}
|
||||
|
||||
bt_settings_set_bin(NV_LOCAL_ID_ADDR, (const u8_t *)&bt_dev.id_addr[0], sizeof(bt_addr_le_t) * CONFIG_BT_ID_MAX);
|
||||
#if defined(CONFIG_BT_PRIVACY)
|
||||
bt_settings_set_bin(NV_LOCAL_IRK, (const u8_t *)&bt_dev.irk[0], 16 * CONFIG_BT_ID_MAX);
|
||||
@ -371,29 +344,24 @@ void bt_settings_save_id(void)
|
||||
#if defined(CONFIG_BT_SETTINGS)
|
||||
void bt_settings_save_name(void)
|
||||
{
|
||||
if (bt_check_if_ef_ready()) {
|
||||
if (bt_check_if_ef_ready())
|
||||
return;
|
||||
}
|
||||
|
||||
ef_set_env(NV_LOCAL_NAME, bt_dev.name);
|
||||
}
|
||||
|
||||
void bt_local_info_load(void)
|
||||
{
|
||||
if (bt_check_if_ef_ready()) {
|
||||
if (bt_check_if_ef_ready())
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC)
|
||||
char *dev_name;
|
||||
uint8_t len;
|
||||
dev_name = ef_get_env(NV_LOCAL_NAME);
|
||||
|
||||
if (dev_name != NULL) {
|
||||
len = ((strlen(dev_name) + 1) < CONFIG_BT_DEVICE_NAME_MAX) ? (strlen(dev_name) + 1) : CONFIG_BT_DEVICE_NAME_MAX;
|
||||
memcpy(bt_dev.name, dev_name, len);
|
||||
}
|
||||
|
||||
#endif
|
||||
bt_settings_get_bin(NV_LOCAL_ID_ADDR, (u8_t *)&bt_dev.id_addr[0], sizeof(bt_addr_le_t) * CONFIG_BT_ID_MAX, NULL);
|
||||
#if defined(CONFIG_BT_PRIVACY)
|
||||
@ -409,18 +377,14 @@ static int commit(void)
|
||||
BT_DBG("");
|
||||
|
||||
#if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC)
|
||||
|
||||
if (bt_dev.name[0] == '\0') {
|
||||
bt_set_name(CONFIG_BT_DEVICE_NAME);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (!bt_dev.id_count) {
|
||||
int err;
|
||||
|
||||
err = bt_setup_id_addr();
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Unable to setup an identity address");
|
||||
return err;
|
||||
@ -428,7 +392,7 @@ static int commit(void)
|
||||
}
|
||||
|
||||
/* Make sure that the identities created by bt_id_create after
|
||||
* bt_enable is saved to persistent storage. */
|
||||
* bt_enable is saved to persistent storage. */
|
||||
if (!atomic_test_bit(bt_dev.flags, BT_DEV_PRESET_ID)) {
|
||||
bt_settings_save_id();
|
||||
}
|
||||
@ -454,7 +418,6 @@ int bt_settings_init(void)
|
||||
BT_DBG("");
|
||||
|
||||
err = settings_subsys_init();
|
||||
|
||||
if (err) {
|
||||
BT_ERR("settings_subsys_init failed (err %d)", err);
|
||||
return err;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -46,10 +46,10 @@ static int bt_smp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
struct bt_smp_hdr *hdr;
|
||||
|
||||
/* If a device does not support pairing then it shall respond with
|
||||
* a Pairing Failed command with the reason set to "Pairing Not
|
||||
* Supported" when any command is received.
|
||||
* Core Specification Vol. 3, Part H, 3.3
|
||||
*/
|
||||
* a Pairing Failed command with the reason set to "Pairing Not
|
||||
* Supported" when any command is received.
|
||||
* Core Specification Vol. 3, Part H, 3.3
|
||||
*/
|
||||
|
||||
buf = bt_l2cap_create_pdu(NULL, 0);
|
||||
/* NULL is not a possible return due to K_FOREVER */
|
||||
|
@ -24,9 +24,8 @@
|
||||
*/
|
||||
static const struct bt_uuid_128 uuid128_base = {
|
||||
.uuid = { BT_UUID_TYPE_128 },
|
||||
.val = {
|
||||
BT_UUID_128_ENCODE(
|
||||
0x00000000, 0x0000, 0x1000, 0x8000, 0x00805F9B34FB) }
|
||||
.val = { BT_UUID_128_ENCODE(
|
||||
0x00000000, 0x0000, 0x1000, 0x8000, 0x00805F9B34FB) }
|
||||
};
|
||||
|
||||
static void uuid_to_uuid128(const struct bt_uuid *src, struct bt_uuid_128 *dst)
|
||||
@ -37,13 +36,11 @@ static void uuid_to_uuid128(const struct bt_uuid *src, struct bt_uuid_128 *dst)
|
||||
sys_put_le16(BT_UUID_16(src)->val,
|
||||
&dst->val[UUID_16_BASE_OFFSET]);
|
||||
return;
|
||||
|
||||
case BT_UUID_TYPE_32:
|
||||
*dst = uuid128_base;
|
||||
sys_put_le32(BT_UUID_32(src)->val,
|
||||
&dst->val[UUID_16_BASE_OFFSET]);
|
||||
return;
|
||||
|
||||
case BT_UUID_TYPE_128:
|
||||
memcpy(dst, src, sizeof(*dst));
|
||||
return;
|
||||
@ -70,10 +67,8 @@ int bt_uuid_cmp(const struct bt_uuid *u1, const struct bt_uuid *u2)
|
||||
switch (u1->type) {
|
||||
case BT_UUID_TYPE_16:
|
||||
return (int)BT_UUID_16(u1)->val - (int)BT_UUID_16(u2)->val;
|
||||
|
||||
case BT_UUID_TYPE_32:
|
||||
return (int)BT_UUID_32(u1)->val - (int)BT_UUID_32(u2)->val;
|
||||
|
||||
case BT_UUID_TYPE_128:
|
||||
return memcmp(BT_UUID_128(u1)->val, BT_UUID_128(u2)->val, 16);
|
||||
}
|
||||
@ -89,21 +84,17 @@ bool bt_uuid_create(struct bt_uuid *uuid, const u8_t *data, u8_t data_len)
|
||||
uuid->type = BT_UUID_TYPE_16;
|
||||
BT_UUID_16(uuid)->val = sys_get_le16(data);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
uuid->type = BT_UUID_TYPE_32;
|
||||
BT_UUID_32(uuid)->val = sys_get_le32(data);
|
||||
break;
|
||||
|
||||
case 16:
|
||||
uuid->type = BT_UUID_TYPE_128;
|
||||
memcpy(&BT_UUID_128(uuid)->val, data, 16);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -117,11 +108,9 @@ void bt_uuid_to_str(const struct bt_uuid *uuid, char *str, size_t len)
|
||||
case BT_UUID_TYPE_16:
|
||||
snprintk(str, len, "%04x", BT_UUID_16(uuid)->val);
|
||||
break;
|
||||
|
||||
case BT_UUID_TYPE_32:
|
||||
snprintk(str, len, "%04x", BT_UUID_32(uuid)->val);
|
||||
break;
|
||||
|
||||
case BT_UUID_TYPE_128:
|
||||
memcpy(&tmp0, &BT_UUID_128(uuid)->val[0], sizeof(tmp0));
|
||||
memcpy(&tmp1, &BT_UUID_128(uuid)->val[2], sizeof(tmp1));
|
||||
@ -133,7 +122,6 @@ void bt_uuid_to_str(const struct bt_uuid *uuid, char *str, size_t len)
|
||||
snprintk(str, len, "%08x-%04x-%04x-%04x-%08x%04x",
|
||||
tmp5, tmp4, tmp3, tmp2, tmp1, tmp0);
|
||||
break;
|
||||
|
||||
default:
|
||||
(void)memset(str, 0, len);
|
||||
return;
|
||||
|
@ -28,14 +28,12 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/** Bluetooth Device Address */
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
u8_t val[6];
|
||||
} bt_addr_t;
|
||||
|
||||
/** Bluetooth LE Device Address */
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
u8_t type;
|
||||
bt_addr_t a;
|
||||
} bt_addr_le_t;
|
||||
|
@ -251,50 +251,50 @@ enum {
|
||||
BT_LE_ADV_OPT_NONE = 0,
|
||||
|
||||
/** Advertise as connectable. Type of advertising is determined by
|
||||
* providing SCAN_RSP data and/or enabling local privacy support.
|
||||
*/
|
||||
* providing SCAN_RSP data and/or enabling local privacy support.
|
||||
*/
|
||||
BT_LE_ADV_OPT_CONNECTABLE = BIT(0),
|
||||
|
||||
/** Don't try to resume connectable advertising after a connection.
|
||||
* This option is only meaningful when used together with
|
||||
* BT_LE_ADV_OPT_CONNECTABLE. If set the advertising will be stopped
|
||||
* when bt_le_adv_stop() is called or when an incoming (slave)
|
||||
* connection happens. If this option is not set the stack will
|
||||
* take care of keeping advertising enabled even as connections
|
||||
* occur.
|
||||
*/
|
||||
* This option is only meaningful when used together with
|
||||
* BT_LE_ADV_OPT_CONNECTABLE. If set the advertising will be stopped
|
||||
* when bt_le_adv_stop() is called or when an incoming (slave)
|
||||
* connection happens. If this option is not set the stack will
|
||||
* take care of keeping advertising enabled even as connections
|
||||
* occur.
|
||||
*/
|
||||
/* if defined CONFIG_BLE_MULTI_ADV , Only support adv one time.*/
|
||||
BT_LE_ADV_OPT_ONE_TIME = BIT(1),
|
||||
|
||||
/** Advertise using the identity address as the own address.
|
||||
* @warning This will compromise the privacy of the device, so care
|
||||
* must be taken when using this option.
|
||||
*/
|
||||
* @warning This will compromise the privacy of the device, so care
|
||||
* must be taken when using this option.
|
||||
*/
|
||||
BT_LE_ADV_OPT_USE_IDENTITY = BIT(2),
|
||||
|
||||
/** Advertise using GAP device name */
|
||||
BT_LE_ADV_OPT_USE_NAME = BIT(3),
|
||||
|
||||
/** Use low duty directed advertising mode, otherwise high duty mode
|
||||
* will be used. This option is only effective when used with
|
||||
* bt_conn_create_slave_le().
|
||||
*/
|
||||
* will be used. This option is only effective when used with
|
||||
* bt_conn_create_slave_le().
|
||||
*/
|
||||
BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY = BIT(4),
|
||||
|
||||
/** Enable use of Resolvable Private Address (RPA) as the target address
|
||||
* in directed advertisements when CONFIG_BT_PRIVACY is not enabled.
|
||||
* This is required if the remote device is privacy-enabled and
|
||||
* supports address resolution of the target address in directed
|
||||
* advertisement.
|
||||
* It is the responsibility of the application to check that the remote
|
||||
* device supports address resolution of directed advertisements by
|
||||
* reading its Central Address Resolution characteristic.
|
||||
*/
|
||||
* in directed advertisements when CONFIG_BT_PRIVACY is not enabled.
|
||||
* This is required if the remote device is privacy-enabled and
|
||||
* supports address resolution of the target address in directed
|
||||
* advertisement.
|
||||
* It is the responsibility of the application to check that the remote
|
||||
* device supports address resolution of directed advertisements by
|
||||
* reading its Central Address Resolution characteristic.
|
||||
*/
|
||||
BT_LE_ADV_OPT_DIR_ADDR_RPA = BIT(5),
|
||||
|
||||
/** Use whitelist to filter devices that can request scan response
|
||||
* data.
|
||||
*/
|
||||
* data.
|
||||
*/
|
||||
BT_LE_ADV_OPT_FILTER_SCAN_REQ = BIT(6),
|
||||
|
||||
/** Use whitelist to filter devices that can connect. */
|
||||
@ -371,10 +371,10 @@ struct bt_le_adv_param {
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
* @return -ECONNREFUSED When connectable advertising is requested and there
|
||||
* is already maximum number of connections established.
|
||||
* This error code is only guaranteed when using Zephyr
|
||||
* controller, for other controllers code returned in
|
||||
* this case may be -EIO.
|
||||
* is already maximum number of connections established.
|
||||
* This error code is only guaranteed when using Zephyr
|
||||
* controller, for other controllers code returned in
|
||||
* this case may be -EIO.
|
||||
*/
|
||||
int bt_le_adv_start(const struct bt_le_adv_param *param,
|
||||
const struct bt_data *ad, size_t ad_len,
|
||||
@ -588,8 +588,8 @@ struct bt_le_oob_sc_data {
|
||||
/** General OOB data. */
|
||||
struct bt_le_oob {
|
||||
/** LE address. If local privacy is enabled this is Resolvable Private
|
||||
* Address.
|
||||
*/
|
||||
* Address.
|
||||
*/
|
||||
bt_addr_le_t addr;
|
||||
|
||||
/** OOB data that are relevant for LESC pairing. */
|
||||
@ -649,8 +649,8 @@ typedef void bt_br_discovery_cb_t(struct bt_br_discovery_result *results,
|
||||
/** BR/EDR discovery parameters */
|
||||
struct bt_br_discovery_param {
|
||||
/** Maximum length of the discovery in units of 1.28 seconds.
|
||||
* Valid range is 0x01 - 0x30.
|
||||
*/
|
||||
* Valid range is 0x01 - 0x30.
|
||||
*/
|
||||
u8_t length;
|
||||
|
||||
/** True if limited discovery procedure is to be used. */
|
||||
@ -760,19 +760,15 @@ static inline int bt_addr_le_to_str(const bt_addr_le_t *addr, char *str,
|
||||
case BT_ADDR_LE_PUBLIC:
|
||||
strcpy(type, "public");
|
||||
break;
|
||||
|
||||
case BT_ADDR_LE_RANDOM:
|
||||
strcpy(type, "random");
|
||||
break;
|
||||
|
||||
case BT_ADDR_LE_PUBLIC_ID:
|
||||
strcpy(type, "public-id");
|
||||
break;
|
||||
|
||||
case BT_ADDR_LE_RANDOM_ID:
|
||||
strcpy(type, "random-id");
|
||||
break;
|
||||
|
||||
default:
|
||||
snprintk(type, sizeof(type), "0x%02x", addr->type);
|
||||
break;
|
||||
|
@ -99,7 +99,7 @@ static inline void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
|
||||
*(u8_t *)net_buf_user_data(buf) = type;
|
||||
}
|
||||
|
||||
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
|
||||
#if defined(BFLB_BLE)
|
||||
static inline void bt_buf_set_rx_adv(struct net_buf *buf, bool is_adv)
|
||||
{
|
||||
u8_t *usr_data = (u8_t *)net_buf_user_data(buf);
|
||||
@ -124,11 +124,11 @@ static inline u8_t bt_buf_check_rx_adv(struct net_buf *buf)
|
||||
static inline enum bt_buf_type bt_buf_get_type(struct net_buf *buf)
|
||||
{
|
||||
/* De-referencing the pointer from net_buf_user_data(buf) as a
|
||||
* pointer to an enum causes issues on qemu_x86 because the true
|
||||
* size is 8-bit, but the enum is 32-bit on qemu_x86. So we put in
|
||||
* a temporary cast to 8-bit to ensure only 8 bits are read from
|
||||
* the pointer.
|
||||
*/
|
||||
* pointer to an enum causes issues on qemu_x86 because the true
|
||||
* size is 8-bit, but the enum is 32-bit on qemu_x86. So we put in
|
||||
* a temporary cast to 8-bit to ensure only 8 bits are read from
|
||||
* the pointer.
|
||||
*/
|
||||
return (enum bt_buf_type)(*(u8_t *)net_buf_user_data(buf));
|
||||
}
|
||||
|
||||
|
@ -151,8 +151,8 @@ struct bt_conn_le_info {
|
||||
/** Source (Local) Identity Address */
|
||||
const bt_addr_le_t *src;
|
||||
/** Destination (Remote) Identity Address or remote Resolvable Private
|
||||
* Address (RPA) before identity has been resolved.
|
||||
*/
|
||||
* Address (RPA) before identity has been resolved.
|
||||
*/
|
||||
const bt_addr_le_t *dst;
|
||||
/** Local device address used during connection setup. */
|
||||
const bt_addr_le_t *local;
|
||||
@ -331,8 +331,8 @@ typedef enum __packed {
|
||||
BT_SECURITY_FIPS __deprecated = BT_SECURITY_L4,
|
||||
|
||||
/** Bit to force new pairing procedure, bit-wise OR with requested
|
||||
* security level.
|
||||
*/
|
||||
* security level.
|
||||
*/
|
||||
BT_SECURITY_FORCE_PAIR = BIT(7),
|
||||
} bt_security_t;
|
||||
|
||||
@ -425,95 +425,95 @@ enum bt_security_err {
|
||||
*/
|
||||
struct bt_conn_cb {
|
||||
/** @brief A new connection has been established.
|
||||
*
|
||||
* This callback notifies the application of a new connection.
|
||||
* In case the err parameter is non-zero it means that the
|
||||
* connection establishment failed.
|
||||
*
|
||||
* @param conn New connection object.
|
||||
* @param err HCI error. Zero for success, non-zero otherwise.
|
||||
*
|
||||
* @p err can mean either of the following:
|
||||
* - @ref BT_HCI_ERR_UNKNOWN_CONN_ID Creating the connection started by
|
||||
* @ref bt_conn_create_le was canceled either by the user through
|
||||
* @ref bt_conn_disconnect or by the timeout in the host through
|
||||
* :option:`CONFIG_BT_CREATE_CONN_TIMEOUT`.
|
||||
* - @p BT_HCI_ERR_ADV_TIMEOUT Directed advertiser started by @ref
|
||||
* bt_conn_create_slave_le with high duty cycle timed out after 1.28
|
||||
* seconds.
|
||||
*/
|
||||
*
|
||||
* This callback notifies the application of a new connection.
|
||||
* In case the err parameter is non-zero it means that the
|
||||
* connection establishment failed.
|
||||
*
|
||||
* @param conn New connection object.
|
||||
* @param err HCI error. Zero for success, non-zero otherwise.
|
||||
*
|
||||
* @p err can mean either of the following:
|
||||
* - @ref BT_HCI_ERR_UNKNOWN_CONN_ID Creating the connection started by
|
||||
* @ref bt_conn_create_le was canceled either by the user through
|
||||
* @ref bt_conn_disconnect or by the timeout in the host through
|
||||
* :option:`CONFIG_BT_CREATE_CONN_TIMEOUT`.
|
||||
* - @p BT_HCI_ERR_ADV_TIMEOUT Directed advertiser started by @ref
|
||||
* bt_conn_create_slave_le with high duty cycle timed out after 1.28
|
||||
* seconds.
|
||||
*/
|
||||
void (*connected)(struct bt_conn *conn, u8_t err);
|
||||
|
||||
/** @brief A connection has been disconnected.
|
||||
*
|
||||
* This callback notifies the application that a connection
|
||||
* has been disconnected.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param reason HCI reason for the disconnection.
|
||||
*/
|
||||
*
|
||||
* This callback notifies the application that a connection
|
||||
* has been disconnected.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param reason HCI reason for the disconnection.
|
||||
*/
|
||||
void (*disconnected)(struct bt_conn *conn, u8_t reason);
|
||||
|
||||
/** @brief LE connection parameter update request.
|
||||
*
|
||||
* This callback notifies the application that a remote device
|
||||
* is requesting to update the connection parameters. The
|
||||
* application accepts the parameters by returning true, or
|
||||
* rejects them by returning false. Before accepting, the
|
||||
* application may also adjust the parameters to better suit
|
||||
* its needs.
|
||||
*
|
||||
* It is recommended for an application to have just one of these
|
||||
* callbacks for simplicity. However, if an application registers
|
||||
* multiple it needs to manage the potentially different
|
||||
* requirements for each callback. Each callback gets the
|
||||
* parameters as returned by previous callbacks, i.e. they are not
|
||||
* necessarily the same ones as the remote originally sent.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param param Proposed connection parameters.
|
||||
*
|
||||
* @return true to accept the parameters, or false to reject them.
|
||||
*/
|
||||
*
|
||||
* This callback notifies the application that a remote device
|
||||
* is requesting to update the connection parameters. The
|
||||
* application accepts the parameters by returning true, or
|
||||
* rejects them by returning false. Before accepting, the
|
||||
* application may also adjust the parameters to better suit
|
||||
* its needs.
|
||||
*
|
||||
* It is recommended for an application to have just one of these
|
||||
* callbacks for simplicity. However, if an application registers
|
||||
* multiple it needs to manage the potentially different
|
||||
* requirements for each callback. Each callback gets the
|
||||
* parameters as returned by previous callbacks, i.e. they are not
|
||||
* necessarily the same ones as the remote originally sent.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param param Proposed connection parameters.
|
||||
*
|
||||
* @return true to accept the parameters, or false to reject them.
|
||||
*/
|
||||
bool (*le_param_req)(struct bt_conn *conn,
|
||||
struct bt_le_conn_param *param);
|
||||
|
||||
/** @brief The parameters for an LE connection have been updated.
|
||||
*
|
||||
* This callback notifies the application that the connection
|
||||
* parameters for an LE connection have been updated.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param interval Connection interval.
|
||||
* @param latency Connection latency.
|
||||
* @param timeout Connection supervision timeout.
|
||||
*/
|
||||
*
|
||||
* This callback notifies the application that the connection
|
||||
* parameters for an LE connection have been updated.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param interval Connection interval.
|
||||
* @param latency Connection latency.
|
||||
* @param timeout Connection supervision timeout.
|
||||
*/
|
||||
void (*le_param_updated)(struct bt_conn *conn, u16_t interval,
|
||||
u16_t latency, u16_t timeout);
|
||||
#if defined(CONFIG_BT_SMP)
|
||||
/** @brief Remote Identity Address has been resolved.
|
||||
*
|
||||
* This callback notifies the application that a remote
|
||||
* Identity Address has been resolved
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param rpa Resolvable Private Address.
|
||||
* @param identity Identity Address.
|
||||
*/
|
||||
*
|
||||
* This callback notifies the application that a remote
|
||||
* Identity Address has been resolved
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param rpa Resolvable Private Address.
|
||||
* @param identity Identity Address.
|
||||
*/
|
||||
void (*identity_resolved)(struct bt_conn *conn,
|
||||
const bt_addr_le_t *rpa,
|
||||
const bt_addr_le_t *identity);
|
||||
#endif /* CONFIG_BT_SMP */
|
||||
#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR)
|
||||
/** @brief The security level of a connection has changed.
|
||||
*
|
||||
* This callback notifies the application that the security level
|
||||
* of a connection has changed.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param level New security level of the connection.
|
||||
* @param err Security error. Zero for success, non-zero otherwise.
|
||||
*/
|
||||
*
|
||||
* This callback notifies the application that the security level
|
||||
* of a connection has changed.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param level New security level of the connection.
|
||||
* @param err Security error. Zero for success, non-zero otherwise.
|
||||
*/
|
||||
void (*security_changed)(struct bt_conn *conn, bt_security_t level,
|
||||
enum bt_security_err err);
|
||||
#endif /* defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) */
|
||||
@ -644,8 +644,7 @@ struct bt_conn_oob_info {
|
||||
|
||||
union {
|
||||
/** LESC OOB pairing parameters */
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
/** OOB data configuration */
|
||||
enum {
|
||||
/** Local OOB data requested */
|
||||
@ -667,157 +666,157 @@ struct bt_conn_oob_info {
|
||||
/** Authenticated pairing callback structure */
|
||||
struct bt_conn_auth_cb {
|
||||
/** @brief Display a passkey to the user.
|
||||
*
|
||||
* When called the application is expected to display the given
|
||||
* passkey to the user, with the expectation that the passkey will
|
||||
* then be entered on the peer device. The passkey will be in the
|
||||
* range of 0 - 999999, and is expected to be padded with zeroes so
|
||||
* that six digits are always shown. E.g. the value 37 should be
|
||||
* shown as 000037.
|
||||
*
|
||||
* This callback may be set to NULL, which means that the local
|
||||
* device lacks the ability do display a passkey. If set
|
||||
* to non-NULL the cancel callback must also be provided, since
|
||||
* this is the only way the application can find out that it should
|
||||
* stop displaying the passkey.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
* @param passkey Passkey to show to the user.
|
||||
*/
|
||||
*
|
||||
* When called the application is expected to display the given
|
||||
* passkey to the user, with the expectation that the passkey will
|
||||
* then be entered on the peer device. The passkey will be in the
|
||||
* range of 0 - 999999, and is expected to be padded with zeroes so
|
||||
* that six digits are always shown. E.g. the value 37 should be
|
||||
* shown as 000037.
|
||||
*
|
||||
* This callback may be set to NULL, which means that the local
|
||||
* device lacks the ability do display a passkey. If set
|
||||
* to non-NULL the cancel callback must also be provided, since
|
||||
* this is the only way the application can find out that it should
|
||||
* stop displaying the passkey.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
* @param passkey Passkey to show to the user.
|
||||
*/
|
||||
void (*passkey_display)(struct bt_conn *conn, unsigned int passkey);
|
||||
|
||||
/** @brief Request the user to enter a passkey.
|
||||
*
|
||||
* When called the user is expected to enter a passkey. The passkey
|
||||
* must be in the range of 0 - 999999, and should be expected to
|
||||
* be zero-padded, as that's how the peer device will typically be
|
||||
* showing it (e.g. 37 would be shown as 000037).
|
||||
*
|
||||
* Once the user has entered the passkey its value should be given
|
||||
* to the stack using the bt_conn_auth_passkey_entry() API.
|
||||
*
|
||||
* This callback may be set to NULL, which means that the local
|
||||
* device lacks the ability to enter a passkey. If set to non-NULL
|
||||
* the cancel callback must also be provided, since this is the
|
||||
* only way the application can find out that it should stop
|
||||
* requesting the user to enter a passkey.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
*/
|
||||
*
|
||||
* When called the user is expected to enter a passkey. The passkey
|
||||
* must be in the range of 0 - 999999, and should be expected to
|
||||
* be zero-padded, as that's how the peer device will typically be
|
||||
* showing it (e.g. 37 would be shown as 000037).
|
||||
*
|
||||
* Once the user has entered the passkey its value should be given
|
||||
* to the stack using the bt_conn_auth_passkey_entry() API.
|
||||
*
|
||||
* This callback may be set to NULL, which means that the local
|
||||
* device lacks the ability to enter a passkey. If set to non-NULL
|
||||
* the cancel callback must also be provided, since this is the
|
||||
* only way the application can find out that it should stop
|
||||
* requesting the user to enter a passkey.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
*/
|
||||
void (*passkey_entry)(struct bt_conn *conn);
|
||||
|
||||
/** @brief Request the user to confirm a passkey.
|
||||
*
|
||||
* When called the user is expected to confirm that the given
|
||||
* passkey is also shown on the peer device.. The passkey will
|
||||
* be in the range of 0 - 999999, and should be zero-padded to
|
||||
* always be six digits (e.g. 37 would be shown as 000037).
|
||||
*
|
||||
* Once the user has confirmed the passkey to match, the
|
||||
* bt_conn_auth_passkey_confirm() API should be called. If the
|
||||
* user concluded that the passkey doesn't match the
|
||||
* bt_conn_auth_cancel() API should be called.
|
||||
*
|
||||
* This callback may be set to NULL, which means that the local
|
||||
* device lacks the ability to confirm a passkey. If set to non-NULL
|
||||
* the cancel callback must also be provided, since this is the
|
||||
* only way the application can find out that it should stop
|
||||
* requesting the user to confirm a passkey.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
* @param passkey Passkey to be confirmed.
|
||||
*/
|
||||
*
|
||||
* When called the user is expected to confirm that the given
|
||||
* passkey is also shown on the peer device.. The passkey will
|
||||
* be in the range of 0 - 999999, and should be zero-padded to
|
||||
* always be six digits (e.g. 37 would be shown as 000037).
|
||||
*
|
||||
* Once the user has confirmed the passkey to match, the
|
||||
* bt_conn_auth_passkey_confirm() API should be called. If the
|
||||
* user concluded that the passkey doesn't match the
|
||||
* bt_conn_auth_cancel() API should be called.
|
||||
*
|
||||
* This callback may be set to NULL, which means that the local
|
||||
* device lacks the ability to confirm a passkey. If set to non-NULL
|
||||
* the cancel callback must also be provided, since this is the
|
||||
* only way the application can find out that it should stop
|
||||
* requesting the user to confirm a passkey.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
* @param passkey Passkey to be confirmed.
|
||||
*/
|
||||
void (*passkey_confirm)(struct bt_conn *conn, unsigned int passkey);
|
||||
|
||||
/** @brief Request the user to provide OOB data.
|
||||
*
|
||||
* When called the user is expected to provide OOB data. The required
|
||||
* data are indicated by the information structure.
|
||||
*
|
||||
* For LESC OOB pairing method, the user should provide local OOB data,
|
||||
* remote OOB data or both depending on their availability. Their value
|
||||
* should be given to the stack using the bt_le_oob_set_sc_data() API.
|
||||
*
|
||||
* This callback must be set to non-NULL in order to support OOB
|
||||
* pairing.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
* @param info OOB pairing information.
|
||||
*/
|
||||
*
|
||||
* When called the user is expected to provide OOB data. The required
|
||||
* data are indicated by the information structure.
|
||||
*
|
||||
* For LESC OOB pairing method, the user should provide local OOB data,
|
||||
* remote OOB data or both depending on their availability. Their value
|
||||
* should be given to the stack using the bt_le_oob_set_sc_data() API.
|
||||
*
|
||||
* This callback must be set to non-NULL in order to support OOB
|
||||
* pairing.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
* @param info OOB pairing information.
|
||||
*/
|
||||
void (*oob_data_request)(struct bt_conn *conn,
|
||||
struct bt_conn_oob_info *info);
|
||||
|
||||
/** @brief Cancel the ongoing user request.
|
||||
*
|
||||
* This callback will be called to notify the application that it
|
||||
* should cancel any previous user request (passkey display, entry
|
||||
* or confirmation).
|
||||
*
|
||||
* This may be set to NULL, but must always be provided whenever the
|
||||
* passkey_display, passkey_entry passkey_confirm or pairing_confirm
|
||||
* callback has been provided.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
*/
|
||||
*
|
||||
* This callback will be called to notify the application that it
|
||||
* should cancel any previous user request (passkey display, entry
|
||||
* or confirmation).
|
||||
*
|
||||
* This may be set to NULL, but must always be provided whenever the
|
||||
* passkey_display, passkey_entry passkey_confirm or pairing_confirm
|
||||
* callback has been provided.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
*/
|
||||
void (*cancel)(struct bt_conn *conn);
|
||||
|
||||
/** @brief Request confirmation for an incoming pairing.
|
||||
*
|
||||
* This callback will be called to confirm an incoming pairing
|
||||
* request where none of the other user callbacks is applicable.
|
||||
*
|
||||
* If the user decides to accept the pairing the
|
||||
* bt_conn_auth_pairing_confirm() API should be called. If the
|
||||
* user decides to reject the pairing the bt_conn_auth_cancel() API
|
||||
* should be called.
|
||||
*
|
||||
* This callback may be set to NULL, which means that the local
|
||||
* device lacks the ability to confirm a pairing request. If set
|
||||
* to non-NULL the cancel callback must also be provided, since
|
||||
* this is the only way the application can find out that it should
|
||||
* stop requesting the user to confirm a pairing request.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
*/
|
||||
*
|
||||
* This callback will be called to confirm an incoming pairing
|
||||
* request where none of the other user callbacks is applicable.
|
||||
*
|
||||
* If the user decides to accept the pairing the
|
||||
* bt_conn_auth_pairing_confirm() API should be called. If the
|
||||
* user decides to reject the pairing the bt_conn_auth_cancel() API
|
||||
* should be called.
|
||||
*
|
||||
* This callback may be set to NULL, which means that the local
|
||||
* device lacks the ability to confirm a pairing request. If set
|
||||
* to non-NULL the cancel callback must also be provided, since
|
||||
* this is the only way the application can find out that it should
|
||||
* stop requesting the user to confirm a pairing request.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
*/
|
||||
void (*pairing_confirm)(struct bt_conn *conn);
|
||||
|
||||
#if defined(CONFIG_BT_BREDR)
|
||||
/** @brief Request the user to enter a passkey.
|
||||
*
|
||||
* This callback will be called for a BR/EDR (Bluetooth Classic)
|
||||
* connection where pairing is being performed. Once called the
|
||||
* user is expected to enter a PIN code with a length between
|
||||
* 1 and 16 digits. If the @a highsec parameter is set to true
|
||||
* the PIN code must be 16 digits long.
|
||||
*
|
||||
* Once entered, the PIN code should be given to the stack using
|
||||
* the bt_conn_auth_pincode_entry() API.
|
||||
*
|
||||
* This callback may be set to NULL, however in that case pairing
|
||||
* over BR/EDR will not be possible. If provided, the cancel
|
||||
* callback must be provided as well.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
* @param highsec true if 16 digit PIN is required.
|
||||
*/
|
||||
*
|
||||
* This callback will be called for a BR/EDR (Bluetooth Classic)
|
||||
* connection where pairing is being performed. Once called the
|
||||
* user is expected to enter a PIN code with a length between
|
||||
* 1 and 16 digits. If the @a highsec parameter is set to true
|
||||
* the PIN code must be 16 digits long.
|
||||
*
|
||||
* Once entered, the PIN code should be given to the stack using
|
||||
* the bt_conn_auth_pincode_entry() API.
|
||||
*
|
||||
* This callback may be set to NULL, however in that case pairing
|
||||
* over BR/EDR will not be possible. If provided, the cancel
|
||||
* callback must be provided as well.
|
||||
*
|
||||
* @param conn Connection where pairing is currently active.
|
||||
* @param highsec true if 16 digit PIN is required.
|
||||
*/
|
||||
void (*pincode_entry)(struct bt_conn *conn, bool highsec);
|
||||
#endif
|
||||
|
||||
/** @brief notify that pairing process was complete.
|
||||
*
|
||||
* This callback notifies the application that the pairing process
|
||||
* has been completed.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param bonded pairing is bonded or not.
|
||||
*/
|
||||
*
|
||||
* This callback notifies the application that the pairing process
|
||||
* has been completed.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param bonded pairing is bonded or not.
|
||||
*/
|
||||
void (*pairing_complete)(struct bt_conn *conn, bool bonded);
|
||||
|
||||
/** @brief notify that pairing process has failed.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param reason Pairing failed reason
|
||||
*/
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param reason Pairing failed reason
|
||||
*/
|
||||
void (*pairing_failed)(struct bt_conn *conn,
|
||||
enum bt_security_err reason);
|
||||
};
|
||||
|
@ -39,36 +39,36 @@ enum {
|
||||
BT_GATT_PERM_WRITE = BIT(1),
|
||||
|
||||
/** Attribute read permission with encryption.
|
||||
*
|
||||
* If set, requires encryption for read access.
|
||||
*/
|
||||
*
|
||||
* If set, requires encryption for read access.
|
||||
*/
|
||||
BT_GATT_PERM_READ_ENCRYPT = BIT(2),
|
||||
|
||||
/** Attribute write permission with encryption.
|
||||
*
|
||||
* If set, requires encryption for write access.
|
||||
*/
|
||||
*
|
||||
* If set, requires encryption for write access.
|
||||
*/
|
||||
BT_GATT_PERM_WRITE_ENCRYPT = BIT(3),
|
||||
|
||||
/** Attribute read permission with authentication.
|
||||
*
|
||||
* If set, requires encryption using authenticated link-key for read
|
||||
* access.
|
||||
*/
|
||||
*
|
||||
* If set, requires encryption using authenticated link-key for read
|
||||
* access.
|
||||
*/
|
||||
BT_GATT_PERM_READ_AUTHEN = BIT(4),
|
||||
|
||||
/** Attribute write permission with authentication.
|
||||
*
|
||||
* If set, requires encryption using authenticated link-key for write
|
||||
* access.
|
||||
*/
|
||||
*
|
||||
* If set, requires encryption using authenticated link-key for write
|
||||
* access.
|
||||
*/
|
||||
BT_GATT_PERM_WRITE_AUTHEN = BIT(5),
|
||||
|
||||
/** Attribute prepare write permission.
|
||||
*
|
||||
* If set, allows prepare writes with use of BT_GATT_WRITE_FLAG_PREPARE
|
||||
* passed to write callback.
|
||||
*/
|
||||
*
|
||||
* If set, allows prepare writes with use of BT_GATT_WRITE_FLAG_PREPARE
|
||||
* passed to write callback.
|
||||
*/
|
||||
BT_GATT_PERM_PREPARE_WRITE = BIT(6),
|
||||
};
|
||||
|
||||
@ -85,17 +85,17 @@ enum {
|
||||
/* GATT attribute write flags */
|
||||
enum {
|
||||
/** Attribute prepare write flag
|
||||
*
|
||||
* If set, write callback should only check if the device is
|
||||
* authorized but no data shall be written.
|
||||
*/
|
||||
*
|
||||
* If set, write callback should only check if the device is
|
||||
* authorized but no data shall be written.
|
||||
*/
|
||||
BT_GATT_WRITE_FLAG_PREPARE = BIT(0),
|
||||
|
||||
/** Attribute write command flag
|
||||
*
|
||||
* If set, indicates that write operation is a command (Write without
|
||||
* response) which doesn't generate any response.
|
||||
*/
|
||||
*
|
||||
* If set, indicates that write operation is a command (Write without
|
||||
* response) which doesn't generate any response.
|
||||
*/
|
||||
BT_GATT_WRITE_FLAG_CMD = BIT(1),
|
||||
};
|
||||
|
||||
@ -105,39 +105,39 @@ struct bt_gatt_attr {
|
||||
const struct bt_uuid *uuid;
|
||||
|
||||
/** Attribute read callback
|
||||
*
|
||||
* The callback can also be used locally to read the contents of the
|
||||
* attribute in which case no connection will be set.
|
||||
*
|
||||
* @param conn The connection that is requesting to read
|
||||
* @param attr The attribute that's being read
|
||||
* @param buf Buffer to place the read result in
|
||||
* @param len Length of data to read
|
||||
* @param offset Offset to start reading from
|
||||
*
|
||||
* @return Number fo bytes read, or in case of an error
|
||||
* BT_GATT_ERR() with a specific ATT error code.
|
||||
*/
|
||||
*
|
||||
* The callback can also be used locally to read the contents of the
|
||||
* attribute in which case no connection will be set.
|
||||
*
|
||||
* @param conn The connection that is requesting to read
|
||||
* @param attr The attribute that's being read
|
||||
* @param buf Buffer to place the read result in
|
||||
* @param len Length of data to read
|
||||
* @param offset Offset to start reading from
|
||||
*
|
||||
* @return Number fo bytes read, or in case of an error
|
||||
* BT_GATT_ERR() with a specific ATT error code.
|
||||
*/
|
||||
ssize_t (*read)(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr,
|
||||
void *buf, u16_t len,
|
||||
u16_t offset);
|
||||
|
||||
/** Attribute write callback
|
||||
*
|
||||
* The callback can also be used locally to read the contents of the
|
||||
* attribute in which case no connection will be set.
|
||||
*
|
||||
* @param conn The connection that is requesting to write
|
||||
* @param attr The attribute that's being written
|
||||
* @param buf Buffer with the data to write
|
||||
* @param len Number of bytes in the buffer
|
||||
* @param offset Offset to start writing from
|
||||
* @param flags Flags (BT_GATT_WRITE_*)
|
||||
*
|
||||
* @return Number of bytes written, or in case of an error
|
||||
* BT_GATT_ERR() with a specific ATT error code.
|
||||
*/
|
||||
*
|
||||
* The callback can also be used locally to read the contents of the
|
||||
* attribute in which case no connection will be set.
|
||||
*
|
||||
* @param conn The connection that is requesting to write
|
||||
* @param attr The attribute that's being written
|
||||
* @param buf Buffer with the data to write
|
||||
* @param len Number of bytes in the buffer
|
||||
* @param offset Offset to start writing from
|
||||
* @param flags Flags (BT_GATT_WRITE_*)
|
||||
*
|
||||
* @return Number of bytes written, or in case of an error
|
||||
* BT_GATT_ERR() with a specific ATT error code.
|
||||
*/
|
||||
ssize_t (*write)(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr,
|
||||
const void *buf, u16_t len,
|
||||
@ -286,8 +286,8 @@ struct bt_gatt_cpf {
|
||||
/** Format of the value of the characteristic */
|
||||
u8_t format;
|
||||
/** Exponent field to determine how the value of this characteristic is
|
||||
* further formatted
|
||||
*/
|
||||
* further formatted
|
||||
*/
|
||||
s8_t exponent;
|
||||
/** Unit of the characteristic */
|
||||
u16_t unit;
|
||||
@ -1025,27 +1025,27 @@ enum {
|
||||
/** Discover Included Services. */
|
||||
BT_GATT_DISCOVER_INCLUDE,
|
||||
/** Discover Characteristic Values.
|
||||
*
|
||||
* Discover Characteristic Value and its properties.
|
||||
*/
|
||||
*
|
||||
* Discover Characteristic Value and its properties.
|
||||
*/
|
||||
BT_GATT_DISCOVER_CHARACTERISTIC,
|
||||
/** Discover Descriptors.
|
||||
*
|
||||
* Discover Attributes which are not services or characteristics.
|
||||
*
|
||||
* Note: The use of this type of discover is not recommended for
|
||||
* discovering in ranges across multiple services/characteristics
|
||||
* as it may incur in extra round trips.
|
||||
*/
|
||||
*
|
||||
* Discover Attributes which are not services or characteristics.
|
||||
*
|
||||
* Note: The use of this type of discover is not recommended for
|
||||
* discovering in ranges across multiple services/characteristics
|
||||
* as it may incur in extra round trips.
|
||||
*/
|
||||
BT_GATT_DISCOVER_DESCRIPTOR,
|
||||
/** Discover Attributes.
|
||||
*
|
||||
* Discover Attributes of any type.
|
||||
*
|
||||
* Note: The use of this type of discover is not recommended for
|
||||
* discovering in ranges across multiple services/characteristics as
|
||||
* it may incur in more round trips.
|
||||
*/
|
||||
*
|
||||
* Discover Attributes of any type.
|
||||
*
|
||||
* Note: The use of this type of discover is not recommended for
|
||||
* discovering in ranges across multiple services/characteristics as
|
||||
* it may incur in more round trips.
|
||||
*/
|
||||
BT_GATT_DISCOVER_ATTRIBUTE,
|
||||
};
|
||||
|
||||
@ -1057,8 +1057,7 @@ struct bt_gatt_discover_params {
|
||||
/** Discover attribute callback */
|
||||
bt_gatt_discover_func_t func;
|
||||
union {
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
/** Include service attribute declaration handle */
|
||||
u16_t attr_handle;
|
||||
/** Included service start handle */
|
||||
@ -1137,14 +1136,12 @@ struct bt_gatt_read_params {
|
||||
bt_gatt_read_func_t func;
|
||||
size_t handle_count;
|
||||
union {
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
u16_t handle;
|
||||
u16_t offset;
|
||||
} single;
|
||||
u16_t *handles;
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
u16_t start_handle;
|
||||
u16_t end_handle;
|
||||
struct bt_uuid *uuid;
|
||||
@ -1289,21 +1286,21 @@ typedef u8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
|
||||
/* Subscription flags */
|
||||
enum {
|
||||
/** Persistence flag
|
||||
*
|
||||
* If set, indicates that the subscription is not saved
|
||||
* on the GATT server side. Therefore, upon disconnection,
|
||||
* the subscription will be automatically removed
|
||||
* from the client's subscriptions list and
|
||||
* when the client reconnects, it will have to
|
||||
* issue a new subscription.
|
||||
*/
|
||||
*
|
||||
* If set, indicates that the subscription is not saved
|
||||
* on the GATT server side. Therefore, upon disconnection,
|
||||
* the subscription will be automatically removed
|
||||
* from the client's subscriptions list and
|
||||
* when the client reconnects, it will have to
|
||||
* issue a new subscription.
|
||||
*/
|
||||
BT_GATT_SUBSCRIBE_FLAG_VOLATILE,
|
||||
|
||||
/** Write pending flag
|
||||
*
|
||||
* If set, indicates write operation is pending waiting remote end to
|
||||
* respond.
|
||||
*/
|
||||
*
|
||||
* If set, indicates write operation is pending waiting remote end to
|
||||
* respond.
|
||||
*/
|
||||
BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING,
|
||||
|
||||
BT_GATT_SUBSCRIBE_NUM_FLAGS
|
||||
|
@ -48,93 +48,93 @@ struct bt_hfp_hf_cmd_complete {
|
||||
/** @brief HFP profile application callback */
|
||||
struct bt_hfp_hf_cb {
|
||||
/** HF connected callback to application
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection completes.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection completes.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*/
|
||||
void (*connected)(struct bt_conn *conn);
|
||||
/** HF disconnected callback to application
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection gets disconnected, including when a connection gets
|
||||
* rejected or cancelled or any error in SLC establisment.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection gets disconnected, including when a connection gets
|
||||
* rejected or cancelled or any error in SLC establisment.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*/
|
||||
void (*disconnected)(struct bt_conn *conn);
|
||||
/** HF indicator Callback
|
||||
*
|
||||
* This callback provides service indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value service indicator value received from the AG.
|
||||
*/
|
||||
*
|
||||
* This callback provides service indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value service indicator value received from the AG.
|
||||
*/
|
||||
void (*service)(struct bt_conn *conn, uint32_t value);
|
||||
/** HF indicator Callback
|
||||
*
|
||||
* This callback provides call indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value call indicator value received from the AG.
|
||||
*/
|
||||
*
|
||||
* This callback provides call indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value call indicator value received from the AG.
|
||||
*/
|
||||
void (*call)(struct bt_conn *conn, uint32_t value);
|
||||
/** HF indicator Callback
|
||||
*
|
||||
* This callback provides call setup indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value call setup indicator value received from the AG.
|
||||
*/
|
||||
*
|
||||
* This callback provides call setup indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value call setup indicator value received from the AG.
|
||||
*/
|
||||
void (*call_setup)(struct bt_conn *conn, uint32_t value);
|
||||
/** HF indicator Callback
|
||||
*
|
||||
* This callback provides call held indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value call held indicator value received from the AG.
|
||||
*/
|
||||
*
|
||||
* This callback provides call held indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value call held indicator value received from the AG.
|
||||
*/
|
||||
void (*call_held)(struct bt_conn *conn, uint32_t value);
|
||||
/** HF indicator Callback
|
||||
*
|
||||
* This callback provides signal indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value signal indicator value received from the AG.
|
||||
*/
|
||||
*
|
||||
* This callback provides signal indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value signal indicator value received from the AG.
|
||||
*/
|
||||
void (*signal)(struct bt_conn *conn, uint32_t value);
|
||||
/** HF indicator Callback
|
||||
*
|
||||
* This callback provides roaming indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value roaming indicator value received from the AG.
|
||||
*/
|
||||
*
|
||||
* This callback provides roaming indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value roaming indicator value received from the AG.
|
||||
*/
|
||||
void (*roam)(struct bt_conn *conn, uint32_t value);
|
||||
/** HF indicator Callback
|
||||
*
|
||||
* This callback battery service indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value battery indicator value received from the AG.
|
||||
*/
|
||||
*
|
||||
* This callback battery service indicator value to the application
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param value battery indicator value received from the AG.
|
||||
*/
|
||||
void (*battery)(struct bt_conn *conn, uint32_t value);
|
||||
/** HF incoming call Ring indication callback to application
|
||||
*
|
||||
* If this callback is provided it will be called whenever there
|
||||
* is an incoming call.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever there
|
||||
* is an incoming call.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*/
|
||||
void (*ring_indication)(struct bt_conn *conn);
|
||||
/** HF notify command completed callback to application
|
||||
*
|
||||
* The command sent from the application is notified about its status
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param cmd structure contains status of the command including cme.
|
||||
*/
|
||||
*
|
||||
* The command sent from the application is notified about its status
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param cmd structure contains status of the command including cme.
|
||||
*/
|
||||
void (*cmd_complete_cb)(struct bt_conn *conn,
|
||||
struct bt_hfp_hf_cmd_complete *cmd);
|
||||
};
|
||||
|
@ -77,10 +77,10 @@ enum {
|
||||
/** @brief ISO Channel QoS structure. */
|
||||
struct bt_iso_chan_qos {
|
||||
/** @brief Channel direction
|
||||
*
|
||||
* Possible values: BT_ISO_CHAN_QOS_IN, BT_ISO_CHAN_QOS_OUT or
|
||||
* BT_ISO_CHAN_QOS_INOUT.
|
||||
*/
|
||||
*
|
||||
* Possible values: BT_ISO_CHAN_QOS_IN, BT_ISO_CHAN_QOS_OUT or
|
||||
* BT_ISO_CHAN_QOS_INOUT.
|
||||
*/
|
||||
uint8_t dir;
|
||||
/** Channel interval */
|
||||
uint32_t interval;
|
||||
@ -121,40 +121,40 @@ struct bt_iso_chan_path {
|
||||
/** @brief ISO Channel operations structure. */
|
||||
struct bt_iso_chan_ops {
|
||||
/** @brief Channel connected callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection completes.
|
||||
*
|
||||
* @param chan The channel that has been connected
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection completes.
|
||||
*
|
||||
* @param chan The channel that has been connected
|
||||
*/
|
||||
void (*connected)(struct bt_iso_chan *chan);
|
||||
|
||||
/** @brief Channel disconnected callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* channel is disconnected, including when a connection gets
|
||||
* rejected.
|
||||
*
|
||||
* @param chan The channel that has been Disconnected
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* channel is disconnected, including when a connection gets
|
||||
* rejected.
|
||||
*
|
||||
* @param chan The channel that has been Disconnected
|
||||
*/
|
||||
void (*disconnected)(struct bt_iso_chan *chan);
|
||||
|
||||
/** @brief Channel alloc_buf callback
|
||||
*
|
||||
* If this callback is provided the channel will use it to allocate
|
||||
* buffers to store incoming data.
|
||||
*
|
||||
* @param chan The channel requesting a buffer.
|
||||
*
|
||||
* @return Allocated buffer.
|
||||
*/
|
||||
*
|
||||
* If this callback is provided the channel will use it to allocate
|
||||
* buffers to store incoming data.
|
||||
*
|
||||
* @param chan The channel requesting a buffer.
|
||||
*
|
||||
* @return Allocated buffer.
|
||||
*/
|
||||
struct net_buf *(*alloc_buf)(struct bt_iso_chan *chan);
|
||||
|
||||
/** @brief Channel recv callback
|
||||
*
|
||||
* @param chan The channel receiving data.
|
||||
* @param buf Buffer containing incoming data.
|
||||
*/
|
||||
*
|
||||
* @param chan The channel receiving data.
|
||||
* @param buf Buffer containing incoming data.
|
||||
*/
|
||||
void (*recv)(struct bt_iso_chan *chan, struct net_buf *buf);
|
||||
};
|
||||
|
||||
@ -164,15 +164,15 @@ struct bt_iso_server {
|
||||
bt_security_t sec_level;
|
||||
|
||||
/** @brief Server accept callback
|
||||
*
|
||||
* This callback is called whenever a new incoming connection requires
|
||||
* authorization.
|
||||
*
|
||||
* @param conn The connection that is requesting authorization
|
||||
* @param chan Pointer to receive the allocated channel
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
*
|
||||
* This callback is called whenever a new incoming connection requires
|
||||
* authorization.
|
||||
*
|
||||
* @param conn The connection that is requesting authorization
|
||||
* @param chan Pointer to receive the allocated channel
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
int (*accept)(struct bt_conn *conn, struct bt_iso_chan **chan);
|
||||
};
|
||||
|
||||
|
@ -167,82 +167,82 @@ struct bt_l2cap_br_chan {
|
||||
/** @brief L2CAP Channel operations structure. */
|
||||
struct bt_l2cap_chan_ops {
|
||||
/** Channel connected callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection completes.
|
||||
*
|
||||
* @param chan The channel that has been connected
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection completes.
|
||||
*
|
||||
* @param chan The channel that has been connected
|
||||
*/
|
||||
void (*connected)(struct bt_l2cap_chan *chan);
|
||||
|
||||
/** Channel disconnected callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* channel is disconnected, including when a connection gets
|
||||
* rejected.
|
||||
*
|
||||
* @param chan The channel that has been Disconnected
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* channel is disconnected, including when a connection gets
|
||||
* rejected.
|
||||
*
|
||||
* @param chan The channel that has been Disconnected
|
||||
*/
|
||||
void (*disconnected)(struct bt_l2cap_chan *chan);
|
||||
|
||||
/** Channel encrypt_change callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* security level changed (indirectly link encryption done) or
|
||||
* authentication procedure fails. In both cases security initiator
|
||||
* and responder got the final status (HCI status) passed by
|
||||
* related to encryption and authentication events from local host's
|
||||
* controller.
|
||||
*
|
||||
* @param chan The channel which has made encryption status changed.
|
||||
* @param status HCI status of performed security procedure caused
|
||||
* by channel security requirements. The value is populated
|
||||
* by HCI layer and set to 0 when success and to non-zero (reference to
|
||||
* HCI Error Codes) when security/authentication failed.
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* security level changed (indirectly link encryption done) or
|
||||
* authentication procedure fails. In both cases security initiator
|
||||
* and responder got the final status (HCI status) passed by
|
||||
* related to encryption and authentication events from local host's
|
||||
* controller.
|
||||
*
|
||||
* @param chan The channel which has made encryption status changed.
|
||||
* @param status HCI status of performed security procedure caused
|
||||
* by channel security requirements. The value is populated
|
||||
* by HCI layer and set to 0 when success and to non-zero (reference to
|
||||
* HCI Error Codes) when security/authentication failed.
|
||||
*/
|
||||
void (*encrypt_change)(struct bt_l2cap_chan *chan, u8_t hci_status);
|
||||
|
||||
/** Channel alloc_buf callback
|
||||
*
|
||||
* If this callback is provided the channel will use it to allocate
|
||||
* buffers to store incoming data.
|
||||
*
|
||||
* @param chan The channel requesting a buffer.
|
||||
*
|
||||
* @return Allocated buffer.
|
||||
*/
|
||||
*
|
||||
* If this callback is provided the channel will use it to allocate
|
||||
* buffers to store incoming data.
|
||||
*
|
||||
* @param chan The channel requesting a buffer.
|
||||
*
|
||||
* @return Allocated buffer.
|
||||
*/
|
||||
struct net_buf *(*alloc_buf)(struct bt_l2cap_chan *chan);
|
||||
|
||||
/** Channel recv callback
|
||||
*
|
||||
* @param chan The channel receiving data.
|
||||
* @param buf Buffer containing incoming data.
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
* If -EINPROGRESS is returned user has to confirm once the data has
|
||||
* been processed by calling bt_l2cap_chan_recv_complete passing back
|
||||
* the buffer received with its original user_data which contains the
|
||||
* number of segments/credits used by the packet.
|
||||
*/
|
||||
*
|
||||
* @param chan The channel receiving data.
|
||||
* @param buf Buffer containing incoming data.
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
* If -EINPROGRESS is returned user has to confirm once the data has
|
||||
* been processed by calling bt_l2cap_chan_recv_complete passing back
|
||||
* the buffer received with its original user_data which contains the
|
||||
* number of segments/credits used by the packet.
|
||||
*/
|
||||
int (*recv)(struct bt_l2cap_chan *chan, struct net_buf *buf);
|
||||
|
||||
/* Channel sent callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever a SDU has
|
||||
* been completely sent.
|
||||
*
|
||||
* @param chan The channel which has sent data.
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever a SDU has
|
||||
* been completely sent.
|
||||
*
|
||||
* @param chan The channel which has sent data.
|
||||
*/
|
||||
void (*sent)(struct bt_l2cap_chan *chan);
|
||||
|
||||
/* Channel status callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* channel status changes.
|
||||
*
|
||||
* @param chan The channel which status changed
|
||||
* @param status The channel status
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* channel status changes.
|
||||
*
|
||||
* @param chan The channel which status changed
|
||||
* @param status The channel status
|
||||
*/
|
||||
void (*status)(struct bt_l2cap_chan *chan, atomic_t *status);
|
||||
|
||||
#if defined(BFLB_BLE_MTU_CHANGE_CB)
|
||||
@ -258,36 +258,36 @@ struct bt_l2cap_chan_ops {
|
||||
/** @brief L2CAP Server structure. */
|
||||
struct bt_l2cap_server {
|
||||
/** Server PSM. Possible values:
|
||||
*
|
||||
* 0 A dynamic value will be auto-allocated when
|
||||
* bt_l2cap_server_register() is called.
|
||||
*
|
||||
* 0x0001-0x007f Standard, Bluetooth SIG-assigned fixed values.
|
||||
*
|
||||
* 0x0080-0x00ff Dynamically allocated. May be pre-set by the
|
||||
* application before server registration (not
|
||||
* recommended however), or auto-allocated by the
|
||||
* stack if the app gave 0 as the value.
|
||||
*/
|
||||
*
|
||||
* 0 A dynamic value will be auto-allocated when
|
||||
* bt_l2cap_server_register() is called.
|
||||
*
|
||||
* 0x0001-0x007f Standard, Bluetooth SIG-assigned fixed values.
|
||||
*
|
||||
* 0x0080-0x00ff Dynamically allocated. May be pre-set by the
|
||||
* application before server registration (not
|
||||
* recommended however), or auto-allocated by the
|
||||
* stack if the app gave 0 as the value.
|
||||
*/
|
||||
u16_t psm;
|
||||
|
||||
/** Required minimim security level */
|
||||
bt_security_t sec_level;
|
||||
|
||||
/** Server accept callback
|
||||
*
|
||||
* This callback is called whenever a new incoming connection requires
|
||||
* authorization.
|
||||
*
|
||||
* @param conn The connection that is requesting authorization
|
||||
* @param chan Pointer to received the allocated channel
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
* Possible return values:
|
||||
* -ENOMEM if no available space for new channel.
|
||||
* -EACCES if application did not authorize the connection.
|
||||
* -EPERM if encryption key size is too short.
|
||||
*/
|
||||
*
|
||||
* This callback is called whenever a new incoming connection requires
|
||||
* authorization.
|
||||
*
|
||||
* @param conn The connection that is requesting authorization
|
||||
* @param chan Pointer to received the allocated channel
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
* Possible return values:
|
||||
* -ENOMEM if no available space for new channel.
|
||||
* -EACCES if application did not authorize the connection.
|
||||
* -EPERM if encryption key size is too short.
|
||||
*/
|
||||
int (*accept)(struct bt_conn *conn, struct bt_l2cap_chan **chan);
|
||||
|
||||
sys_snode_t node;
|
||||
|
@ -38,29 +38,29 @@ struct bt_rfcomm_dlc;
|
||||
/** @brief RFCOMM DLC operations structure. */
|
||||
struct bt_rfcomm_dlc_ops {
|
||||
/** DLC connected callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection completes.
|
||||
*
|
||||
* @param dlc The dlc that has been connected
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection completes.
|
||||
*
|
||||
* @param dlc The dlc that has been connected
|
||||
*/
|
||||
void (*connected)(struct bt_rfcomm_dlc *dlc);
|
||||
|
||||
/** DLC disconnected callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* dlc is disconnected, including when a connection gets
|
||||
* rejected or cancelled (both incoming and outgoing)
|
||||
*
|
||||
* @param dlc The dlc that has been Disconnected
|
||||
*/
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* dlc is disconnected, including when a connection gets
|
||||
* rejected or cancelled (both incoming and outgoing)
|
||||
*
|
||||
* @param dlc The dlc that has been Disconnected
|
||||
*/
|
||||
void (*disconnected)(struct bt_rfcomm_dlc *dlc);
|
||||
|
||||
/** DLC recv callback
|
||||
*
|
||||
* @param dlc The dlc receiving data.
|
||||
* @param buf Buffer containing incoming data.
|
||||
*/
|
||||
*
|
||||
* @param dlc The dlc receiving data.
|
||||
* @param buf Buffer containing incoming data.
|
||||
*/
|
||||
void (*recv)(struct bt_rfcomm_dlc *dlc, struct net_buf *buf);
|
||||
};
|
||||
|
||||
@ -104,15 +104,15 @@ struct bt_rfcomm_server {
|
||||
uint8_t channel;
|
||||
|
||||
/** Server accept callback
|
||||
*
|
||||
* This callback is called whenever a new incoming connection requires
|
||||
* authorization.
|
||||
*
|
||||
* @param conn The connection that is requesting authorization
|
||||
* @param dlc Pointer to received the allocated dlc
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
*
|
||||
* This callback is called whenever a new incoming connection requires
|
||||
* authorization.
|
||||
*
|
||||
* @param conn The connection that is requesting authorization
|
||||
* @param dlc Pointer to received the allocated dlc
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
int (*accept)(struct bt_conn *conn, struct bt_rfcomm_dlc **dlc);
|
||||
|
||||
struct bt_rfcomm_server *_next;
|
||||
|
@ -55,7 +55,6 @@ static inline bool bt_hci_evt_is_prio(u8_t evt)
|
||||
case BT_HCI_EVT_DATA_BUF_OVERFLOW:
|
||||
#endif
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -123,39 +122,39 @@ struct bt_hci_driver {
|
||||
enum bt_hci_driver_bus bus;
|
||||
|
||||
/** Specific controller quirks. These are set by the HCI driver
|
||||
* and acted upon by the host. They can either be statically
|
||||
* set at buildtime, or set at runtime before the HCI driver's
|
||||
* open() callback returns.
|
||||
*/
|
||||
* and acted upon by the host. They can either be statically
|
||||
* set at buildtime, or set at runtime before the HCI driver's
|
||||
* open() callback returns.
|
||||
*/
|
||||
u32_t quirks;
|
||||
|
||||
/**
|
||||
* @brief Open the HCI transport.
|
||||
*
|
||||
* Opens the HCI transport for operation. This function must not
|
||||
* return until the transport is ready for operation, meaning it
|
||||
* is safe to start calling the send() handler.
|
||||
*
|
||||
* If the driver uses its own RX thread, i.e.
|
||||
* CONFIG_BT_RECV_IS_RX_THREAD is set, then this
|
||||
* function is expected to start that thread.
|
||||
*
|
||||
* @return 0 on success or negative error number on failure.
|
||||
*/
|
||||
* @brief Open the HCI transport.
|
||||
*
|
||||
* Opens the HCI transport for operation. This function must not
|
||||
* return until the transport is ready for operation, meaning it
|
||||
* is safe to start calling the send() handler.
|
||||
*
|
||||
* If the driver uses its own RX thread, i.e.
|
||||
* CONFIG_BT_RECV_IS_RX_THREAD is set, then this
|
||||
* function is expected to start that thread.
|
||||
*
|
||||
* @return 0 on success or negative error number on failure.
|
||||
*/
|
||||
int (*open)(void);
|
||||
|
||||
/**
|
||||
* @brief Send HCI buffer to controller.
|
||||
*
|
||||
* Send an HCI command or ACL data to the controller. The exact
|
||||
* type of the data can be checked with the help of bt_buf_get_type().
|
||||
*
|
||||
* @note This function must only be called from a cooperative thread.
|
||||
*
|
||||
* @param buf Buffer containing data to be sent to the controller.
|
||||
*
|
||||
* @return 0 on success or negative error number on failure.
|
||||
*/
|
||||
* @brief Send HCI buffer to controller.
|
||||
*
|
||||
* Send an HCI command or ACL data to the controller. The exact
|
||||
* type of the data can be checked with the help of bt_buf_get_type().
|
||||
*
|
||||
* @note This function must only be called from a cooperative thread.
|
||||
*
|
||||
* @param buf Buffer containing data to be sent to the controller.
|
||||
*
|
||||
* @return 0 on success or negative error number on failure.
|
||||
*/
|
||||
int (*send)(struct net_buf *buf);
|
||||
};
|
||||
|
||||
|
@ -32,19 +32,15 @@ int bl_rand()
|
||||
int counter = 0;
|
||||
int32_t ret = 0;
|
||||
Sec_Eng_Trng_Enable();
|
||||
|
||||
do {
|
||||
ret = Sec_Eng_Trng_Get_Random((uint8_t *)&val, 4);
|
||||
|
||||
if (ret < -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((counter++) > TRNG_LOOP_COUNTER) {
|
||||
break;
|
||||
}
|
||||
} while (0 == val);
|
||||
|
||||
val >>= 1; //leave signe bit alone
|
||||
return val;
|
||||
}
|
||||
@ -80,7 +76,6 @@ void k_queue_insert_from_isr(struct k_queue *queue, void *prev, void *data)
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
|
||||
xQueueSendFromISR(queue->hdl, &data, &xHigherPriorityTaskWoken);
|
||||
|
||||
if (xHigherPriorityTaskWoken == pdTRUE) {
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
@ -132,7 +127,6 @@ void *k_queue_get(struct k_queue *queue, s32_t timeout)
|
||||
}
|
||||
|
||||
ret = xQueueReceive(queue->hdl, &msg, t == BL_WAIT_FOREVER ? portMAX_DELAY : ms2tick(t));
|
||||
|
||||
if (ret == pdPASS) {
|
||||
return msg;
|
||||
} else {
|
||||
@ -168,7 +162,6 @@ int k_sem_take(struct k_sem *sem, uint32_t timeout)
|
||||
unsigned int t = timeout;
|
||||
|
||||
(void)ret;
|
||||
|
||||
if (timeout == K_FOREVER) {
|
||||
t = BL_WAIT_FOREVER;
|
||||
} else if (timeout == K_NO_WAIT) {
|
||||
|
@ -17,8 +17,7 @@
|
||||
#define BL_NO_WAIT 0x0
|
||||
#define ms2tick pdMS_TO_TICKS
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
void *hdl;
|
||||
} bl_hdl_t;
|
||||
|
||||
|
@ -175,17 +175,17 @@
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* CONFIG_BLUETOOTH_L2CAP_TX_BUF_COUNT: number of buffer for outgoing L2CAP packages
|
||||
* range 2 to 255
|
||||
*/
|
||||
* CONFIG_BLUETOOTH_L2CAP_TX_BUF_COUNT: number of buffer for outgoing L2CAP packages
|
||||
* range 2 to 255
|
||||
*/
|
||||
#ifndef CONFIG_BT_L2CAP_TX_BUF_COUNT
|
||||
#define CONFIG_BT_L2CAP_TX_BUF_COUNT CFG_BLE_TX_BUFF_DATA
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BT_L2CAP_TX_MTU: Max L2CAP MTU for L2CAP tx buffer
|
||||
* range 65 to 2000 if SMP enabled,otherwise range 23 to 2000
|
||||
*/
|
||||
* CONFIG_BT_L2CAP_TX_MTU: Max L2CAP MTU for L2CAP tx buffer
|
||||
* range 65 to 2000 if SMP enabled,otherwise range 23 to 2000
|
||||
*/
|
||||
#ifndef CONFIG_BT_L2CAP_TX_MTU
|
||||
#ifdef CONFIG_BT_SMP
|
||||
#define CONFIG_BT_L2CAP_TX_MTU 247 //96 //65
|
||||
@ -195,9 +195,9 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BT_L2CAP_TX_USER_DATA_SIZE: the max length for L2CAP tx buffer user data size
|
||||
* range 4 to 65535
|
||||
*/
|
||||
* CONFIG_BT_L2CAP_TX_USER_DATA_SIZE: the max length for L2CAP tx buffer user data size
|
||||
* range 4 to 65535
|
||||
*/
|
||||
#ifndef CONFIG_BT_L2CAP_TX_USER_DATA_SIZE
|
||||
#define CONFIG_BT_L2CAP_TX_USER_DATA_SIZE 4
|
||||
#endif
|
||||
@ -206,53 +206,53 @@
|
||||
#define CONFIG_BT_ATT_PREPARE_COUNT 64
|
||||
#else
|
||||
/**
|
||||
* CONFIG_BT_ATT_PREPARE_COUNT: Number of buffers available for ATT prepare write, setting
|
||||
* this to 0 disables GATT long/reliable writes.
|
||||
* range 0 to 64
|
||||
*/
|
||||
* CONFIG_BT_ATT_PREPARE_COUNT: Number of buffers available for ATT prepare write, setting
|
||||
* this to 0 disables GATT long/reliable writes.
|
||||
* range 0 to 64
|
||||
*/
|
||||
#ifndef CONFIG_BT_ATT_PREPARE_COUNT
|
||||
#define CONFIG_BT_ATT_PREPARE_COUNT 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BLUETOOTH_SMP:Eable the Security Manager Protocol
|
||||
* (SMP), making it possible to pair devices over LE
|
||||
*/
|
||||
* CONFIG_BLUETOOTH_SMP:Eable the Security Manager Protocol
|
||||
* (SMP), making it possible to pair devices over LE
|
||||
*/
|
||||
#ifdef CONFIG_BT_SMP
|
||||
#undef CONFIG_BT_SMP
|
||||
#define CONFIG_BT_SMP 1
|
||||
|
||||
/**
|
||||
* CONFIG_BT_SIGNING:enables data signing which is used for transferring
|
||||
* authenticated data in an unencrypted connection
|
||||
*/
|
||||
* CONFIG_BT_SIGNING:enables data signing which is used for transferring
|
||||
* authenticated data in an unencrypted connection
|
||||
*/
|
||||
#ifdef CONFIG_BT_SIGNING
|
||||
#undef CONFIG_BT_SIGNING
|
||||
#define CONFIG_BT_SIGNING 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BT_SMP_SC_ONLY:enables support for Secure Connection Only Mode. In this
|
||||
* mode device shall only use Security Mode 1 Level 4 with exception
|
||||
* for services that only require Security Mode 1 Level 1 (no security).
|
||||
* Security Mode 1 Level 4 stands for authenticated LE Secure Connections
|
||||
* pairing with encryption. Enabling this option disables legacy pairing
|
||||
*/
|
||||
* CONFIG_BT_SMP_SC_ONLY:enables support for Secure Connection Only Mode. In this
|
||||
* mode device shall only use Security Mode 1 Level 4 with exception
|
||||
* for services that only require Security Mode 1 Level 1 (no security).
|
||||
* Security Mode 1 Level 4 stands for authenticated LE Secure Connections
|
||||
* pairing with encryption. Enabling this option disables legacy pairing
|
||||
*/
|
||||
#ifdef CONFIG_BT_SMP_SC_ONLY
|
||||
#undef CONFIG_BT_SMP_SC_ONLY
|
||||
#define CONFIG_BT_SMP_SC_ONLY 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BT_USE_DEBUG_KEYS:This option places Security Manager in
|
||||
* a Debug Mode. In this mode predefined
|
||||
* Diffie-Hellman private/public key pair is used as described
|
||||
* in Core Specification Vol. 3, Part H, 2.3.5.6.1. This option should
|
||||
* only be enabled for debugging and should never be used in production.
|
||||
* If this option is enabled anyone is able to decipher encrypted air
|
||||
* traffic.
|
||||
*/
|
||||
* CONFIG_BT_USE_DEBUG_KEYS:This option places Security Manager in
|
||||
* a Debug Mode. In this mode predefined
|
||||
* Diffie-Hellman private/public key pair is used as described
|
||||
* in Core Specification Vol. 3, Part H, 2.3.5.6.1. This option should
|
||||
* only be enabled for debugging and should never be used in production.
|
||||
* If this option is enabled anyone is able to decipher encrypted air
|
||||
* traffic.
|
||||
*/
|
||||
#ifdef CONFIG_BT_USE_DEBUG_KEYS
|
||||
#ifndef CONFIG_BT_TINYCRYPT_ECC
|
||||
#error "CONFIG_BT_USE_DEBUG_KEYS depends on CONFIG_BT_TINYCRYPT_ECC"
|
||||
@ -262,9 +262,9 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL:enables support for LE Connection
|
||||
* oriented Channels,allowing the creation of dynamic L2CAP Channels
|
||||
*/
|
||||
* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL:enables support for LE Connection
|
||||
* oriented Channels,allowing the creation of dynamic L2CAP Channels
|
||||
*/
|
||||
#ifdef CONFIG_BT_L2CAP_DYNAMIC_CHANNEL
|
||||
#undef CONFIG_BT_L2CAP_DYNAMIC_CHANNEL
|
||||
#define CONFIG_BT_L2CAP_DYNAMIC_CHANNEL 1
|
||||
@ -273,9 +273,9 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BT_PRIVACY:Enable local Privacy Feature support. This makes it possible
|
||||
* to use Resolvable Private Addresses (RPAs).
|
||||
*/
|
||||
* CONFIG_BT_PRIVACY:Enable local Privacy Feature support. This makes it possible
|
||||
* to use Resolvable Private Addresses (RPAs).
|
||||
*/
|
||||
#ifdef CONFIG_BT_PRIVACY
|
||||
#ifndef CONFIG_BT_SMP
|
||||
#error "CONFIG_BT_PRIVACY depends on CONFIG_BT_SMP"
|
||||
@ -284,34 +284,34 @@
|
||||
#define CONFIG_BT_PRIVACY 1
|
||||
|
||||
/**
|
||||
* CONFIG_BT_RPA_TIMEOUT:Resolvable Private Address timeout
|
||||
* range 1 to 65535,seconds
|
||||
*/
|
||||
* CONFIG_BT_RPA_TIMEOUT:Resolvable Private Address timeout
|
||||
* range 1 to 65535,seconds
|
||||
*/
|
||||
#ifndef CONFIG_BT_RPA_TIMEOUT
|
||||
#define CONFIG_BT_RPA_TIMEOUT 900
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BT_GATT_DYNAMIC_DB:enables GATT services to be added dynamically to database
|
||||
*/
|
||||
* CONFIG_BT_GATT_DYNAMIC_DB:enables GATT services to be added dynamically to database
|
||||
*/
|
||||
#ifdef CONFIG_BT_GATT_DYNAMIC_DB
|
||||
#undef CONFIG_BT_GATT_DYNAMIC_DB
|
||||
#define CONFIG_BT_GATT_DYNAMIC_DB 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BT_GATT_CLIENT:GATT client role support
|
||||
*/
|
||||
* CONFIG_BT_GATT_CLIENT:GATT client role support
|
||||
*/
|
||||
#ifdef CONFIG_BT_GATT_CLIENT
|
||||
#undef CONFIG_BT_GATT_CLIENT
|
||||
#define CONFIG_BT_GATT_CLIENT 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CONFIG_BT_MAX_PAIRED:Maximum number of paired devices
|
||||
* range 1 to 128
|
||||
*/
|
||||
* CONFIG_BT_MAX_PAIRED:Maximum number of paired devices
|
||||
* range 1 to 128
|
||||
*/
|
||||
#ifndef CONFIG_BT_MAX_PAIRED
|
||||
#define CONFIG_BT_MAX_PAIRED CONFIG_BT_MAX_CONN
|
||||
#endif
|
||||
@ -487,16 +487,16 @@
|
||||
|
||||
#ifndef CONFIG_BT_ATT_TX_MAX
|
||||
/*
|
||||
* Take throuthput test into consideration, set att tx max the same with lowstack tx buffer count.
|
||||
* att semaphore determine the max numble packets can send to lowsatck at once.
|
||||
*/
|
||||
* Take throuthput test into consideration, set att tx max the same with lowstack tx buffer count.
|
||||
* att semaphore determine the max numble packets can send to lowsatck at once.
|
||||
*/
|
||||
#define CONFIG_BT_ATT_TX_MAX 10
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_BT_CONN_TX_MAX
|
||||
/*
|
||||
* Take throuthput test into consideration, set upperstack conn tx max the same with lowstack tx buffer count.
|
||||
*/
|
||||
* Take throuthput test into consideration, set upperstack conn tx max the same with lowstack tx buffer count.
|
||||
*/
|
||||
#define CONFIG_BT_CONN_TX_MAX 10
|
||||
#endif
|
||||
|
||||
@ -571,8 +571,8 @@
|
||||
#define CONFIG_BT_GATT_SERVICE_CHANGED 1
|
||||
#define CONFIG_BT_GATT_CACHING 1
|
||||
#define CONFIG_BT_SCAN_WITH_IDENTITY 1
|
||||
#define CONFIG_BT_ADV_WITH_PUBLIC_ADDR 1
|
||||
#define CONFIG_BT_ATT_PREPARE_COUNT 64
|
||||
//#define CONFIG_BT_ADV_WITH_PUBLIC_ADDR 1
|
||||
#define CONFIG_BT_ATT_PREPARE_COUNT 64
|
||||
#endif
|
||||
#endif //BFLB_BLE
|
||||
|
||||
@ -592,7 +592,7 @@ happens, which cause memory leak issue.*/
|
||||
#define BFLB_BLE_PATCH_SET_SCRANGE_CHAGD_ONLY_IN_CONNECTED_STATE
|
||||
#ifdef CONFIG_BT_SETTINGS
|
||||
/*Semaphore is used during flash operation. Make sure that freertos has already run up when it
|
||||
intends to write information to flash.*/
|
||||
intends to write information to flash.*/
|
||||
#define BFLB_BLE_PATCH_SETTINGS_LOAD
|
||||
#endif
|
||||
#define BFLB_BLE_SMP_LOCAL_AUTH
|
||||
@ -602,10 +602,13 @@ happens, which cause memory leak issue.*/
|
||||
#endif
|
||||
|
||||
#define BFLB_RELEASE_CMD_SEM_IF_CONN_DISC
|
||||
/*Fix the issue when local auth_req is 0(no boinding),
|
||||
/*Fix the issue when local auth_req is 0(no boinding),
|
||||
BT_SMP_DIST_ENC_KEY bit is not cleared while remote ENC_KEY is received.*/
|
||||
#define BFLB_BLE_PATCH_CLEAR_REMOTE_KEY_BIT
|
||||
|
||||
#if defined(CONFIG_BT_CENTRAL) || defined(CONFIG_BT_OBSERVER)
|
||||
#define BFLB_BLE_NOTIFY_ADV_DISCARDED
|
||||
#endif
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -51,17 +51,14 @@ PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
/* Compute sizes needed for the memory regions, and bail if we don't have
|
||||
* enough memory for them. */
|
||||
subdataSize = maxChannels * sizeof(common->subdata[0]) * SBC_MAX_BANDS * SBC_MAX_BLOCKS;
|
||||
|
||||
if (subdataSize > codecDataBytes) {
|
||||
return OI_STATUS_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
filterBufferCount = (codecDataBytes - subdataSize) / (sizeof(common->filterBuffer[0][0]) * SBC_MAX_BANDS * maxChannels);
|
||||
|
||||
if (filterBufferCount < SBC_CODEC_MIN_FILTER_BUFFERS) {
|
||||
return OI_STATUS_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
common->filterBufferLen = filterBufferCount * SBC_MAX_BANDS;
|
||||
|
||||
/* Allocate memory for the subband data */
|
||||
|
@ -69,25 +69,20 @@ static void stereoBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common)
|
||||
}
|
||||
sbL = 0;
|
||||
sbR = nrof_subbands;
|
||||
|
||||
while (sbL < nrof_subbands) {
|
||||
excess = allocAdjustedBits(&common->bits.uint8[sbL], bitneeds.uint8[sbL] + bitadjust, excess);
|
||||
++sbL;
|
||||
excess = allocAdjustedBits(&common->bits.uint8[sbR], bitneeds.uint8[sbR] + bitadjust, excess);
|
||||
++sbR;
|
||||
}
|
||||
|
||||
sbL = 0;
|
||||
sbR = nrof_subbands;
|
||||
|
||||
while (excess) {
|
||||
excess = allocExcessBits(&common->bits.uint8[sbL], excess);
|
||||
++sbL;
|
||||
|
||||
if (!excess) {
|
||||
break;
|
||||
}
|
||||
|
||||
excess = allocExcessBits(&common->bits.uint8[sbR], excess);
|
||||
++sbR;
|
||||
}
|
||||
@ -147,12 +142,10 @@ OI_UINT16 OI_CODEC_SBC_CalculateBitpool(OI_CODEC_SBC_FRAME_INFO *frame,
|
||||
} else {
|
||||
hdr = 8 * nrof_subbands;
|
||||
}
|
||||
|
||||
if (frame->mode == SBC_DUAL_CHANNEL) {
|
||||
nrof_blocks *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
bits = 8 * (frameLen - SBC_HEADER_LEN) - hdr;
|
||||
return DIVIDE(bits, nrof_blocks);
|
||||
}
|
||||
|
@ -47,7 +47,6 @@ OI_UINT32 OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO *frame)
|
||||
case SBC_MONO:
|
||||
case SBC_DUAL_CHANNEL:
|
||||
return 16 * frame->nrof_subbands;
|
||||
|
||||
case SBC_STEREO:
|
||||
case SBC_JOINT_STEREO:
|
||||
return 32 * frame->nrof_subbands;
|
||||
@ -70,14 +69,12 @@ PRIVATE OI_UINT16 internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame)
|
||||
if (frame->mode == SBC_DUAL_CHANNEL) {
|
||||
result += nbits;
|
||||
}
|
||||
|
||||
if (frame->mode == SBC_MONO) {
|
||||
result += 4 * nrof_subbands;
|
||||
} else {
|
||||
result += 8 * nrof_subbands;
|
||||
}
|
||||
}
|
||||
|
||||
return SBC_HEADER_LEN + (result + 7) / 8;
|
||||
}
|
||||
|
||||
@ -152,51 +149,39 @@ OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
if (common->frameInfo.alloc == SBC_SNR) {
|
||||
for (sb = 0; sb < nrof_subbands; sb++) {
|
||||
OI_INT bits = scale_factor[sb];
|
||||
|
||||
if (bits > maxBits) {
|
||||
maxBits = bits;
|
||||
}
|
||||
|
||||
if ((bitneeds[sb] = bits) > 1) {
|
||||
bitcount += bits;
|
||||
}
|
||||
|
||||
prefBits += 2 + bits;
|
||||
}
|
||||
} else {
|
||||
const OI_INT8 *offset;
|
||||
|
||||
if (nrof_subbands == 4) {
|
||||
offset = offset4[common->frameInfo.freqIndex];
|
||||
} else {
|
||||
offset = offset8[common->frameInfo.freqIndex];
|
||||
}
|
||||
|
||||
for (sb = 0; sb < nrof_subbands; sb++) {
|
||||
OI_INT bits = scale_factor[sb];
|
||||
|
||||
if (bits > maxBits) {
|
||||
maxBits = bits;
|
||||
}
|
||||
|
||||
prefBits += 2 + bits;
|
||||
|
||||
if (bits) {
|
||||
bits -= offset[sb];
|
||||
|
||||
if (bits > 0) {
|
||||
bits /= 2;
|
||||
}
|
||||
|
||||
bits += 5;
|
||||
}
|
||||
|
||||
if ((bitneeds[sb] = bits) > 1) {
|
||||
bitcount += bits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
common->maxBitneed = OI_MAX(maxBits, common->maxBitneed);
|
||||
*preferredBitpool += prefBits;
|
||||
return bitcount;
|
||||
@ -300,7 +285,6 @@ OI_INT adjustToFitBitpool(const OI_UINT bitpool,
|
||||
count = (count & 0xFF) + (count >> 8);
|
||||
|
||||
chop >>= 1;
|
||||
|
||||
if (count > bitpool) {
|
||||
bitadjust -= chop;
|
||||
} else {
|
||||
@ -338,7 +322,6 @@ INLINE OI_INT allocAdjustedBits(OI_UINT8 *dest,
|
||||
} else {
|
||||
bits = 16;
|
||||
}
|
||||
|
||||
*dest = (OI_UINT8)bits;
|
||||
return excess;
|
||||
}
|
||||
@ -381,14 +364,11 @@ void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
allocBits = &common->bits.uint8[ch ? nrof_subbands : 0];
|
||||
|
||||
sb = 0;
|
||||
|
||||
while (sb < nrof_subbands) {
|
||||
excess = allocAdjustedBits(&allocBits[sb], bitneeds->uint8[sb] + bitadjust, excess);
|
||||
++sb;
|
||||
}
|
||||
|
||||
sb = 0;
|
||||
|
||||
while (excess) {
|
||||
excess = allocExcessBits(&allocBits[sb], excess);
|
||||
++sb;
|
||||
|
@ -71,7 +71,6 @@ PRIVATE OI_UINT8 OI_BITSTREAM_ReadUINT4Aligned(OI_BITSTREAM *bs)
|
||||
bs->value = (bs->value << 8) | *bs->ptr.r++;
|
||||
bs->bitPtr = 8;
|
||||
}
|
||||
|
||||
result >>= 28;
|
||||
OI_ASSERT(result < (1u << 4));
|
||||
return (OI_UINT8)result;
|
||||
|
@ -52,11 +52,9 @@ OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context
|
||||
|
||||
if (enhanced) {
|
||||
#ifdef SBC_ENHANCED
|
||||
|
||||
if (subbands != SBC_SUBBANDS_8) {
|
||||
return OI_STATUS_INVALID_PARAMETERS;
|
||||
}
|
||||
|
||||
#else
|
||||
return OI_STATUS_INVALID_PARAMETERS;
|
||||
#endif
|
||||
@ -127,7 +125,6 @@ OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
} else {
|
||||
context->enhancedEnabled = FALSE;
|
||||
}
|
||||
|
||||
context->restrictSubbands = subbands;
|
||||
context->limitFrameFormat = TRUE;
|
||||
return OI_OK;
|
||||
|
@ -60,11 +60,9 @@ INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
context->enhancedEnabled = enhanced ? TRUE : FALSE;
|
||||
#else
|
||||
context->enhancedEnabled = FALSE;
|
||||
|
||||
if (enhanced) {
|
||||
return OI_STATUS_INVALID_PARAMETERS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (msbc_enable) {
|
||||
@ -131,7 +129,6 @@ INLINE void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE
|
||||
* already been populated
|
||||
*/
|
||||
d1 = data[1];
|
||||
|
||||
if (d1 != frame->cachedInfo) {
|
||||
frame->freqIndex = (d1 & (BIT7 | BIT6)) >> 6;
|
||||
frame->frequency = freq_values[frame->freqIndex];
|
||||
@ -149,7 +146,6 @@ INLINE void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE
|
||||
|
||||
frame->cachedInfo = d1;
|
||||
}
|
||||
|
||||
/*
|
||||
* For decode, the bit allocator needs to know the bitpool value
|
||||
*/
|
||||
@ -177,14 +173,11 @@ PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
} else {
|
||||
common->frameInfo.join = 0;
|
||||
}
|
||||
|
||||
i /= 2;
|
||||
|
||||
do {
|
||||
*scale_factor++ = HIGH(f = *b++);
|
||||
*scale_factor++ = LOW(f);
|
||||
} while (--i);
|
||||
|
||||
/*
|
||||
* In this case we know that the scale factors end on a byte boundary so all we need to do
|
||||
* is initialize the bitstream.
|
||||
@ -194,12 +187,10 @@ PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
OI_ASSERT(common->frameInfo.nrof_subbands == 4 && common->frameInfo.mode == SBC_JOINT_STEREO);
|
||||
common->frameInfo.join = HIGH(f = *b++);
|
||||
i = (i - 1) / 2;
|
||||
|
||||
do {
|
||||
*scale_factor++ = LOW(f);
|
||||
*scale_factor++ = HIGH(f = *b++);
|
||||
} while (--i);
|
||||
|
||||
*scale_factor++ = LOW(f);
|
||||
/*
|
||||
* In 4-subband joint stereo mode, the joint stereo information ends on a half-byte
|
||||
@ -222,15 +213,12 @@ PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTR
|
||||
OI_UINT bitPtr = global_bs->bitPtr;
|
||||
|
||||
const OI_UINT iter_count = common->frameInfo.nrof_channels * common->frameInfo.nrof_subbands / 4;
|
||||
|
||||
do {
|
||||
OI_UINT i;
|
||||
|
||||
for (i = 0; i < iter_count; ++i) {
|
||||
OI_UINT32 sf_by4 = ((OI_UINT32 *)common->scale_factor)[i];
|
||||
OI_UINT32 bits_by4 = common->bits.uint32[i];
|
||||
OI_UINT n;
|
||||
|
||||
for (n = 0; n < 4; ++n) {
|
||||
OI_INT32 dequant;
|
||||
OI_UINT bits;
|
||||
@ -247,7 +235,6 @@ PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTR
|
||||
sf = (sf_by4 >> 24) & 0xFF;
|
||||
sf_by4 <<= 8;
|
||||
}
|
||||
|
||||
if (bits) {
|
||||
OI_UINT32 raw;
|
||||
OI_BITSTREAM_READUINT(raw, bits, ptr, value, bitPtr);
|
||||
@ -255,7 +242,6 @@ PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTR
|
||||
} else {
|
||||
dequant = 0;
|
||||
}
|
||||
|
||||
*s++ = dequant;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ PRIVATE OI_STATUS FindSyncword(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
}
|
||||
|
||||
#ifdef SBC_ENHANCED
|
||||
|
||||
if (context->limitFrameFormat && context->enhancedEnabled) {
|
||||
/* If the context is restricted, only search for specified SYNCWORD */
|
||||
search1 = search2;
|
||||
@ -62,12 +61,10 @@ PRIVATE OI_STATUS FindSyncword(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
/* If enhanced is not enabled, only search for classic SBC SYNCWORD*/
|
||||
search2 = search1;
|
||||
}
|
||||
|
||||
while (*frameBytes && (**frameData != search1) && (**frameData != search2)) {
|
||||
(*frameBytes)--;
|
||||
(*frameData)++;
|
||||
}
|
||||
|
||||
if (*frameBytes) {
|
||||
/* Syncword found, *frameData points to it, and *frameBytes correctly
|
||||
* reflects the number of bytes available to read, including the
|
||||
@ -80,14 +77,11 @@ PRIVATE OI_STATUS FindSyncword(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
* *frameBytes is 0. */
|
||||
return OI_CODEC_SBC_NO_SYNCWORD;
|
||||
}
|
||||
|
||||
#else // SBC_ENHANCED
|
||||
|
||||
#else // SBC_ENHANCED
|
||||
while (*frameBytes && (!(context->sbc_mode == OI_SBC_MODE_STD && **frameData == OI_SBC_SYNCWORD)) && (!(context->sbc_mode == OI_SBC_MODE_MSBC && **frameData == OI_mSBC_SYNCWORD))) {
|
||||
(*frameBytes)--;
|
||||
(*frameData)++;
|
||||
}
|
||||
|
||||
if (*frameBytes) {
|
||||
/* Syncword found, *frameData points to it, and *frameBytes correctly
|
||||
* reflects the number of bytes available to read, including the
|
||||
@ -100,7 +94,6 @@ PRIVATE OI_STATUS FindSyncword(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
* *frameBytes is 0. */
|
||||
return OI_CODEC_SBC_NO_SYNCWORD;
|
||||
}
|
||||
|
||||
#endif // SBC_ENHANCED
|
||||
}
|
||||
|
||||
@ -136,7 +129,6 @@ static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
OI_SBC_ComputeBitAllocation(&context->common);
|
||||
|
||||
TRACE(("Reading samples"));
|
||||
|
||||
if (context->common.frameInfo.mode == SBC_JOINT_STEREO) {
|
||||
OI_SBC_ReadSamplesJoint(context, &bs);
|
||||
} else {
|
||||
@ -173,7 +165,6 @@ static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
*/
|
||||
if (context->common.frameInfo.nrof_channels == 1 && context->common.pcmStride == 2) {
|
||||
OI_UINT i;
|
||||
|
||||
for (i = 0; i < frameSamples; ++i) {
|
||||
pcmData[2 * i + 1] = pcmData[2 * i];
|
||||
}
|
||||
@ -183,7 +174,6 @@ static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
* Return number of pcm bytes generated by the decode operation.
|
||||
*/
|
||||
*pcmBytes = frameSamples * sizeof(OI_INT16) * context->common.pcmStride;
|
||||
|
||||
if (context->bufferedBlocks > 0) {
|
||||
return OI_CODEC_SBC_PARTIAL_DECODE;
|
||||
} else {
|
||||
@ -212,7 +202,6 @@ PRIVATE OI_STATUS internal_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
* Compute the frame length and check we have enough frame data to proceed
|
||||
*/
|
||||
bodyLen = OI_CODEC_SBC_CalculateFramelen(&context->common.frameInfo) - SBC_HEADER_LEN;
|
||||
|
||||
if (*frameBytes < bodyLen) {
|
||||
TRACE(("-OI_CODEC_SBC_Decode: OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA"));
|
||||
return OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA;
|
||||
@ -220,18 +209,15 @@ PRIVATE OI_STATUS internal_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
} else {
|
||||
bodyLen = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode the SBC data. Pass TRUE to DecodeBody to allow partial decoding of
|
||||
* tones.
|
||||
*/
|
||||
status = DecodeBody(context, *frameData, pcmData, pcmBytes, TRUE);
|
||||
|
||||
if (OI_SUCCESS(status) || status == OI_CODEC_SBC_PARTIAL_DECODE) {
|
||||
*frameData += bodyLen;
|
||||
*frameBytes -= bodyLen;
|
||||
}
|
||||
|
||||
TRACE(("-OI_CODEC_SBC_DecodeRaw: %d", status));
|
||||
return status;
|
||||
}
|
||||
@ -261,7 +247,6 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
|
||||
TRACE(("Finding syncword"));
|
||||
status = FindSyncword(context, frameData, frameBytes);
|
||||
|
||||
if (!OI_SUCCESS(status)) {
|
||||
return status;
|
||||
}
|
||||
@ -303,7 +288,6 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
* data that we don't actually need.
|
||||
*/
|
||||
framelen = OI_CODEC_SBC_CalculateFramelen(&context->common.frameInfo);
|
||||
|
||||
if (*frameBytes < framelen) {
|
||||
TRACE(("-OI_CODEC_SBC_DecodeFrame: OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA"));
|
||||
return OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA;
|
||||
@ -312,7 +296,6 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
TRACE(("Calculating checksum"));
|
||||
|
||||
crc = OI_SBC_CalculateChecksum(&context->common.frameInfo, *frameData);
|
||||
|
||||
if (crc != context->common.frameInfo.crc) {
|
||||
TRACE(("CRC Mismatch: calc=%02x read=%02x\n", crc, context->common.frameInfo.crc));
|
||||
TRACE(("-OI_CODEC_SBC_DecodeFrame: OI_CODEC_SBC_CHECKSUM_MISMATCH"));
|
||||
@ -320,7 +303,6 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
}
|
||||
|
||||
#ifdef OI_DEBUG
|
||||
|
||||
/*
|
||||
* Make sure the bitpool values are sane.
|
||||
*/
|
||||
@ -328,12 +310,10 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
ERROR(("Bitpool too small: %d (must be >= 2)", context->common.frameInfo.bitpool));
|
||||
return OI_STATUS_INVALID_PARAMETERS;
|
||||
}
|
||||
|
||||
if (context->common.frameInfo.bitpool > OI_SBC_MaxBitpool(&context->common.frameInfo)) {
|
||||
ERROR(("Bitpool too large: %d (must be <= %ld)", context->common.frameInfo.bitpool, OI_SBC_MaxBitpool(&context->common.frameInfo)));
|
||||
return OI_STATUS_INVALID_PARAMETERS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -342,12 +322,10 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
* you have to decode a whole packet at a time.
|
||||
*/
|
||||
status = DecodeBody(context, *frameData + SBC_HEADER_LEN, pcmData, pcmBytes, FALSE);
|
||||
|
||||
if (OI_SUCCESS(status)) {
|
||||
*frameData += framelen;
|
||||
*frameBytes -= framelen;
|
||||
}
|
||||
|
||||
TRACE(("-OI_CODEC_SBC_DecodeFrame: %d", status));
|
||||
|
||||
return status;
|
||||
@ -363,32 +341,24 @@ OI_STATUS OI_CODEC_SBC_SkipFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
OI_UINT8 crc;
|
||||
|
||||
status = FindSyncword(context, frameData, frameBytes);
|
||||
|
||||
if (!OI_SUCCESS(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (*frameBytes < SBC_HEADER_LEN) {
|
||||
return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA;
|
||||
}
|
||||
|
||||
OI_SBC_ReadHeader(&context->common, *frameData);
|
||||
framelen = OI_SBC_CalculateFrameAndHeaderlen(&context->common.frameInfo, &headerlen);
|
||||
|
||||
if (*frameBytes < headerlen) {
|
||||
return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA;
|
||||
}
|
||||
|
||||
crc = OI_SBC_CalculateChecksum(&context->common.frameInfo, *frameData);
|
||||
|
||||
if (crc != context->common.frameInfo.crc) {
|
||||
return OI_CODEC_SBC_CHECKSUM_MISMATCH;
|
||||
}
|
||||
|
||||
if (*frameBytes < framelen) {
|
||||
return OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA;
|
||||
}
|
||||
|
||||
context->bufferedBlocks = 0;
|
||||
*frameData += framelen;
|
||||
*frameBytes -= framelen;
|
||||
@ -423,7 +393,6 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
|
||||
|
||||
/* Inline logic to avoid corrupting context */
|
||||
frameLen = blocks * frameData[2];
|
||||
|
||||
switch (mode) {
|
||||
case SBC_JOINT_STEREO:
|
||||
frameLen += subbands + (8 * subbands);
|
||||
@ -431,7 +400,6 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
|
||||
|
||||
case SBC_DUAL_CHANNEL:
|
||||
frameLen *= 2;
|
||||
|
||||
/* fall through */
|
||||
|
||||
default:
|
||||
@ -444,7 +412,6 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
|
||||
|
||||
frameCount++;
|
||||
frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8;
|
||||
|
||||
if (frameBytes > frameLen) {
|
||||
frameBytes -= frameLen;
|
||||
frameData += frameLen;
|
||||
@ -452,7 +419,6 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
|
||||
frameBytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return frameCount;
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,6 @@ INLINE OI_INT32 OI_SBC_Dequant_Unscaled(OI_UINT32 raw, OI_UINT scale_factor, OI_
|
||||
if (bits <= 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (bits == 16) {
|
||||
result = (raw << 16) + raw - 0x7fff7fff;
|
||||
return SCALE(result, 24 - scale_factor);
|
||||
|
@ -241,7 +241,6 @@ static INLINE OI_CHAR crc_iterate(OI_UINT8 oldcrc, OI_UINT8 next)
|
||||
OI_UINT idx;
|
||||
idx = oldcrc ^ next;
|
||||
crc = crc8_wide[idx >> 1];
|
||||
|
||||
if (idx % 2) {
|
||||
crc &= 0xff;
|
||||
} else {
|
||||
@ -257,7 +256,6 @@ static INLINE OI_CHAR crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
|
||||
OI_UINT idx;
|
||||
idx = (oldcrc ^ next) >> 4;
|
||||
crc = crc8_wide[idx >> 1];
|
||||
|
||||
if (idx % 2) {
|
||||
crc &= 0xff;
|
||||
} else {
|
||||
@ -369,7 +367,6 @@ PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCou
|
||||
do {
|
||||
COPY4WORDS_BACK(d, s);
|
||||
} while (--n);
|
||||
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user