[style][ble] format ble files

This commit is contained in:
jzlv 2021-08-25 17:13:47 +08:00
parent da07eee6ea
commit 67c8532ae0
123 changed files with 2689 additions and 4973 deletions

View File

@ -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()
#######################################################

View File

@ -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()

View File

@ -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(&param[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);
}

View File

@ -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__

View File

@ -110,32 +110,26 @@ 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},
@ -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
},
[Address value,e.g.112233AABBCC]\r\n", blecli_disconnect},
{
"ble_select_conn", "\r\nble_select_conn:[Select a specific connection]\r\n\
{"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
},
[Address value, e.g.112233AABBCC]\r\n", blecli_select_conn},
{
"ble_unpair", "\r\nble_unpair:[Unpair connection]\r\n\
{"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",
{"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",
{"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(&param, ad, ad_len, &ad_discov[0], 1, &ble_adv_id);
}
#else
err = bt_le_adv_start(&param, 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(&param, ad, ad_len, NULL, 0, &ble_adv_id);
}
#else
err = bt_le_adv_start(&param, 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(&param_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(&param_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], &param.interval_min);
get_uint16_from_string(&argv[2], &param.interval_max);
get_uint16_from_string(&argv[3], &param.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 {

View File

@ -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 {

View File

@ -118,8 +118,7 @@ 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_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 },
@ -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;
}
@ -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, &params);
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, &params);
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,16 +828,14 @@ 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");
}
}
}
static void pts_ble_start_scan(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
@ -890,7 +880,6 @@ static void pts_ble_sc_indicate(char *pcWriteBuffer, int xWriteBufferLen, int ar
memset(&params, 0, sizeof(params));
params.func = NULL;
err = service_change_test(&params, 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 {
@ -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(&param);
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,12 +1274,10 @@ 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);
}*/
@ -1317,15 +1291,14 @@ static void pts_ble_start_advertise(char *pcWriteBuffer, int xWriteBufferLen, in
//get_bytearray_from_string(&argv[3], (u8_t *)&param.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], &param.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, &param);
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*/ &param);
@ -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(&param, 0, sizeof(struct bt_le_conn_param));
get_uint16_from_string(&argv[1], &param.interval_min);
get_uint16_from_string(&argv[2], &param.interval_max);
get_uint16_from_string(&argv[3], &param.latency);
get_uint16_from_string(&argv[4], &param.timeout);
if (event_flag == dir_connect_req) {
if (event_flag == dir_connect_req)
err = bt_conn_le_param_update(default_conn, &param);
} else {
else
err = pts_bt_conn_le_param_update(default_conn, &param);
}
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,11 +1577,9 @@ 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) {
(void)memset(params, 0, sizeof(*params));
@ -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 {

View File

@ -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;
}
@ -400,7 +404,6 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
*/
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,7 +738,6 @@ 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;
}
@ -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;
}

View File

@ -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++;

View File

@ -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;
}

View File

@ -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); \

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -34,7 +34,6 @@ static inline size_t stack_unused_space_get(const char *stack, size_t size)
* 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;
}

View File

@ -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) \

View File

@ -570,8 +570,7 @@ struct net_buf {
*/
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;
@ -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);
}

View File

@ -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
@ -321,7 +321,7 @@
*/
.macro section_var section, symbol.section.\section\().\symbol
\symbol :.endm
\symbol :.endm
.macro section_func section,
symbol
@ -329,12 +329,12 @@
.\symbol,
"ax" FUNC_CODE()
PERFOPT_ALIGN
\symbol : FUNC_INSTR(\symbol)
\symbol : FUNC_INSTR(\symbol)
.endm
.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

View File

@ -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;

View File

@ -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;

View File

@ -43,7 +43,6 @@ 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;
}
@ -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;
}

View File

@ -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];

View File

@ -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;
}

View File

@ -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,
@ -100,14 +99,12 @@ int tc_cbc_mode_decrypt(uint8_t *out, unsigned int outlen, const uint8_t *in,
* 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++;
}

View File

@ -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);
}

View File

@ -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];
}

View File

@ -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++;
}

View File

@ -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;

View File

@ -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,7 +113,6 @@ 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. */
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,7 +288,6 @@ 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. */
@ -316,7 +300,6 @@ 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). */
@ -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 {
@ -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;
}

View File

@ -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;
}
@ -182,7 +179,6 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
r = 0;
goto clear_and_out;
}
initial_Z = p2[carry];
}

View File

@ -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,7 +120,6 @@ 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;
}
@ -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);

View File

@ -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;
}

View File

@ -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;

View File

@ -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 */

View File

@ -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,

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
@ -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;
}

View File

@ -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,11 +174,9 @@ 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 */
case HCI_CLASS_ACL_DATA:
if (pend || !hbuf_count) {
@ -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);
@ -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)

View File

@ -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;
}

View File

@ -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;
}
@ -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,7 +341,6 @@ 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;
}
@ -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;
}

View File

@ -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;
}
@ -310,11 +302,8 @@ static u8_t att_mtu_req(struct bt_att *att, struct net_buf *buf)
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;
}
@ -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,7 +620,6 @@ 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,
@ -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,18 +697,15 @@ 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.
*/
@ -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,
@ -844,12 +816,10 @@ static u8_t read_type_cb(const struct bt_gatt_attr *attr, void *user_data)
* 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;
}
@ -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;
}
@ -1001,7 +965,6 @@ static u8_t read_cb(const struct bt_gatt_attr *attr, void *user_data)
/* 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;
}
@ -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;
}
@ -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,13 +1611,10 @@ 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]
@ -1714,9 +1657,7 @@ static int att_change_security(struct bt_conn *conn, u8_t err)
} 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))) {
@ -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
}
@ -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;
}

View File

@ -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("\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("\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;
@ -545,12 +505,10 @@ int bt_avdtp_l2cap_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");
#endif
@ -585,17 +543,14 @@ int bt_avdtp_l2cap_media_stream_recv(struct bt_l2cap_chan *chan, struct net_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");
#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;

View File

@ -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,14 +340,11 @@ 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);
}

View File

@ -111,11 +111,9 @@ static const u8_t ssp_method[4 /* remote */][4 /* local */] = {
struct k_sem *bt_conn_get_pkts(struct bt_conn *conn)
{
#if defined(CONFIG_BT_BREDR)
if (conn->type == BT_CONN_TYPE_BR || !bt_dev.le.mtu) {
return &bt_dev.br.pkts;
}
#endif /* CONFIG_BT_BREDR */
return &bt_dev.le.pkts;
@ -126,22 +124,16 @@ static inline const char *state2str(bt_conn_state_t state)
switch (state) {
case BT_CONN_DISCONNECTED:
return "disconnected";
case BT_CONN_CONNECT_SCAN:
return "connect-scan";
case BT_CONN_CONNECT_DIR_ADV:
return "connect-dir-adv";
case BT_CONN_CONNECT:
return "connect";
case BT_CONN_CONNECTED:
return "connected";
case BT_CONN_DISCONNECT:
return "disconnect";
default:
return "(unknown)";
}
@ -151,6 +143,17 @@ static void notify_connected(struct bt_conn *conn)
{
struct bt_conn_cb *cb;
#if defined(CONFIG_BT_BREDR)
if (conn->type == BT_CONN_TYPE_BR && conn->err) {
if (atomic_test_bit(bt_dev.flags, BT_DEV_ISCAN)) {
atomic_clear_bit(bt_dev.flags, BT_DEV_ISCAN);
}
if (atomic_test_bit(bt_dev.flags, BT_DEV_PSCAN)) {
atomic_clear_bit(bt_dev.flags, BT_DEV_PSCAN);
}
}
#endif
for (cb = callback_list; cb; cb = cb->_next) {
if (cb->connected) {
cb->connected(conn, conn->err);
@ -166,6 +169,17 @@ static void notify_disconnected(struct bt_conn *conn)
{
struct bt_conn_cb *cb;
#if defined(CONFIG_BT_BREDR)
if (conn->type == BT_CONN_TYPE_BR) {
if (atomic_test_bit(bt_dev.flags, BT_DEV_ISCAN)) {
atomic_clear_bit(bt_dev.flags, BT_DEV_ISCAN);
}
if (atomic_test_bit(bt_dev.flags, BT_DEV_PSCAN)) {
atomic_clear_bit(bt_dev.flags, BT_DEV_PSCAN);
}
}
#endif
for (cb = callback_list; cb; cb = cb->_next) {
if (cb->disconnected) {
cb->disconnected(conn, conn->err);
@ -278,7 +292,6 @@ static void tx_notify(struct bt_conn *conn)
void *user_data;
key = irq_lock();
if (sys_slist_is_empty(&conn->tx_complete)) {
irq_unlock(key);
break;
@ -347,7 +360,6 @@ static void conn_update_timeout(struct k_work *work)
}
#if defined(CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS)
/* if application set own params use those, otherwise use defaults */
if (atomic_test_and_clear_bit(conn->flags, BT_CONN_SLAVE_PARAM_SET)) {
param = BT_LE_CONN_PARAM(conn->le.interval_min,
@ -364,9 +376,7 @@ static void conn_update_timeout(struct k_work *work)
send_conn_le_param_update(conn, param);
}
#else
/* update only if application set own params */
if (atomic_test_and_clear_bit(conn->flags, BT_CONN_SLAVE_PARAM_SET)) {
param = BT_LE_CONN_PARAM(conn->le.interval_min,
@ -376,7 +386,6 @@ static void conn_update_timeout(struct k_work *work)
send_conn_le_param_update(conn, param);
}
#endif
atomic_set_bit(conn->flags, BT_CONN_SLAVE_PARAM_UPDATE);
@ -499,13 +508,11 @@ struct bt_conn *bt_conn_create_br(const bt_addr_t *peer,
struct net_buf *buf;
conn = bt_conn_lookup_addr_br(peer);
if (conn) {
switch (conn->state) {
case BT_CONN_CONNECT:
case BT_CONN_CONNECTED:
return conn;
default:
bt_conn_unref(conn);
return NULL;
@ -513,13 +520,11 @@ struct bt_conn *bt_conn_create_br(const bt_addr_t *peer,
}
conn = bt_conn_add_br(peer);
if (!conn) {
return NULL;
}
buf = bt_hci_cmd_create(BT_HCI_OP_CONNECT, sizeof(*cp));
if (!buf) {
bt_conn_unref(conn);
return NULL;
@ -554,13 +559,11 @@ struct bt_conn *bt_conn_create_sco(const bt_addr_t *peer)
int link_type;
sco_conn = bt_conn_lookup_addr_sco(peer);
if (sco_conn) {
switch (sco_conn->state) {
case BT_CONN_CONNECT:
case BT_CONN_CONNECTED:
return sco_conn;
default:
bt_conn_unref(sco_conn);
return NULL;
@ -574,13 +577,11 @@ struct bt_conn *bt_conn_create_sco(const bt_addr_t *peer)
}
sco_conn = bt_conn_add_sco(peer, link_type);
if (!sco_conn) {
return NULL;
}
buf = bt_hci_cmd_create(BT_HCI_OP_SETUP_SYNC_CONN, sizeof(*cp));
if (!buf) {
bt_sco_cleanup(sco_conn);
return NULL;
@ -702,7 +703,6 @@ static int pin_code_neg_reply(const bt_addr_t *bdaddr)
BT_DBG("");
buf = bt_hci_cmd_create(BT_HCI_OP_PIN_CODE_NEG_REPLY, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
}
@ -721,7 +721,6 @@ static int pin_code_reply(struct bt_conn *conn, const char *pin, u8_t len)
BT_DBG("");
buf = bt_hci_cmd_create(BT_HCI_OP_PIN_CODE_REPLY, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
}
@ -748,7 +747,6 @@ int bt_conn_auth_pincode_entry(struct bt_conn *conn, const char *pin)
}
len = strlen(pin);
if (len > 16) {
return -EINVAL;
}
@ -840,7 +838,6 @@ static int ssp_confirm_reply(struct bt_conn *conn)
BT_DBG("");
buf = bt_hci_cmd_create(BT_HCI_OP_USER_CONFIRM_REPLY, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
}
@ -859,7 +856,6 @@ static int ssp_confirm_neg_reply(struct bt_conn *conn)
BT_DBG("");
buf = bt_hci_cmd_create(BT_HCI_OP_USER_CONFIRM_NEG_REPLY, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
}
@ -906,19 +902,15 @@ void bt_conn_ssp_auth(struct bt_conn *conn, u32_t passkey)
atomic_set_bit(conn->flags, BT_CONN_USER);
bt_auth->passkey_confirm(conn, passkey);
break;
case PASSKEY_DISPLAY:
atomic_set_bit(conn->flags, BT_CONN_USER);
bt_auth->passkey_display(conn, passkey);
break;
case PASSKEY_INPUT:
atomic_set_bit(conn->flags, BT_CONN_USER);
bt_auth->passkey_entry(conn);
break;
case JUST_WORKS:
/*
* When local host works as pairing acceptor and 'justworks'
* model is applied then notify user about such pairing request.
@ -931,10 +923,8 @@ void bt_conn_ssp_auth(struct bt_conn *conn, u32_t passkey)
bt_auth->pairing_confirm(conn);
break;
}
ssp_confirm_reply(conn);
break;
default:
break;
}
@ -948,7 +938,6 @@ static int ssp_passkey_reply(struct bt_conn *conn, unsigned int passkey)
BT_DBG("");
buf = bt_hci_cmd_create(BT_HCI_OP_USER_PASSKEY_REPLY, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
}
@ -968,7 +957,6 @@ static int ssp_passkey_neg_reply(struct bt_conn *conn)
BT_DBG("");
buf = bt_hci_cmd_create(BT_HCI_OP_USER_PASSKEY_NEG_REPLY, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
}
@ -988,7 +976,6 @@ static int bt_hci_connect_br_cancel(struct bt_conn *conn)
int err;
buf = bt_hci_cmd_create(BT_HCI_OP_CONNECT_CANCEL, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
}
@ -997,7 +984,6 @@ static int bt_hci_connect_br_cancel(struct bt_conn *conn)
memcpy(&cp->bdaddr, &conn->br.dst, sizeof(cp->bdaddr));
err = bt_hci_cmd_send_sync(BT_HCI_OP_CONNECT_CANCEL, buf, &rsp);
if (err) {
return err;
}
@ -1019,7 +1005,6 @@ static int conn_auth(struct bt_conn *conn)
BT_DBG("");
buf = bt_hci_cmd_create(BT_HCI_OP_AUTH_REQUESTED, sizeof(*auth));
if (!buf) {
return -ENOBUFS;
}
@ -1059,7 +1044,6 @@ int bt_conn_le_start_encryption(struct bt_conn *conn, u8_t rand[8],
struct net_buf *buf;
buf = bt_hci_cmd_create(BT_HCI_OP_LE_START_ENCRYPTION, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
}
@ -1070,7 +1054,6 @@ int bt_conn_le_start_encryption(struct bt_conn *conn, u8_t rand[8],
memcpy(&cp->ediv, ediv, sizeof(cp->ediv));
memcpy(cp->ltk, ltk, len);
if (len < sizeof(cp->ltk)) {
(void)memset(cp->ltk + len, 0, sizeof(cp->ltk) - len);
}
@ -1102,7 +1085,6 @@ u8_t bt_conn_enc_key_size(struct bt_conn *conn)
buf = bt_hci_cmd_create(BT_HCI_OP_READ_ENCRYPTION_KEY_SIZE,
sizeof(*cp));
if (!buf) {
return 0;
}
@ -1140,20 +1122,16 @@ void bt_conn_security_changed(struct bt_conn *conn, enum bt_security_err err)
cb->security_changed(conn, conn->sec_level, err);
}
}
#if IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST)
if (!err && conn->sec_level >= BT_SECURITY_L2) {
bt_keys_update_usage(conn->id, bt_conn_get_dst(conn));
}
#endif
}
static int start_security(struct bt_conn *conn)
{
#if defined(CONFIG_BT_BREDR)
if (conn->type == BT_CONN_TYPE_BR) {
if (atomic_test_bit(conn->flags, BT_CONN_BR_PAIRING)) {
return -EBUSY;
@ -1170,7 +1148,6 @@ static int start_security(struct bt_conn *conn)
return conn_auth(conn);
}
#endif /* CONFIG_BT_BREDR */
if (IS_ENABLED(CONFIG_BT_SMP)) {
@ -1267,14 +1244,12 @@ void bt_conn_recv(struct bt_conn *conn, struct net_buf *buf, u8_t flags)
conn->rx_len = (sizeof(*hdr) + len) - buf->len;
BT_DBG("rx_len %u", conn->rx_len);
if (conn->rx_len) {
conn->rx = buf;
return;
}
break;
case BT_ACL_CONT:
if (!conn->rx_len) {
BT_ERR("Unexpected L2CAP continuation");
@ -1312,7 +1287,6 @@ void bt_conn_recv(struct bt_conn *conn, struct net_buf *buf, u8_t flags)
conn->rx_len = 0U;
break;
default:
BT_ERR("Unexpected ACL flags (0x%02x)", flags);
bt_conn_reset_rx_state(conn);
@ -1344,9 +1318,7 @@ static struct bt_conn_tx *conn_tx_alloc(void)
if (k_current_get() == &k_sys_work_q.thread) {
return k_fifo_get(&free_tx, K_NO_WAIT);
}
#endif
if (IS_ENABLED(CONFIG_BT_DEBUG_CONN)) {
struct bt_conn_tx *tx = k_fifo_get(&free_tx, K_NO_WAIT);
@ -1376,7 +1348,6 @@ int bt_conn_send_cb(struct bt_conn *conn, struct net_buf *buf,
if (cb) {
tx = conn_tx_alloc();
if (!tx) {
BT_ERR("Unable to allocate TX context");
net_buf_unref(buf);
@ -1433,14 +1404,12 @@ static bool send_frag(struct bt_conn *conn, struct net_buf *buf, u8_t flags,
/* Add to pending, it must be done before bt_buf_set_type */
key = irq_lock();
if (tx) {
sys_slist_append(&conn->tx_pending, &tx->node);
} else {
struct bt_conn_tx *tail_tx;
tail_tx = (void *)sys_slist_peek_tail(&conn->tx_pending);
if (tail_tx) {
pending_no_cb = &tail_tx->pending_no_cb;
} else {
@ -1449,17 +1418,14 @@ static bool send_frag(struct bt_conn *conn, struct net_buf *buf, u8_t flags,
(*pending_no_cb)++;
}
irq_unlock(key);
bt_buf_set_type(buf, BT_BUF_ACL_OUT);
err = bt_send(buf);
if (err) {
BT_ERR("Unable to send to driver (err %d)", err);
key = irq_lock();
/* Roll back the pending TX info */
if (tx) {
sys_slist_find_and_remove(&conn->tx_pending, &tx->node);
@ -1467,7 +1433,6 @@ static bool send_frag(struct bt_conn *conn, struct net_buf *buf, u8_t flags,
__ASSERT_NO_MSG(*pending_no_cb > 0);
(*pending_no_cb)--;
}
irq_unlock(key);
goto fail;
}
@ -1476,7 +1441,6 @@ static bool send_frag(struct bt_conn *conn, struct net_buf *buf, u8_t flags,
fail:
k_sem_give(bt_conn_get_pkts(conn));
if (tx) {
tx_free(tx);
}
@ -1484,18 +1448,15 @@ fail:
if (always_consume) {
net_buf_unref(buf);
}
return false;
}
static inline u16_t conn_mtu(struct bt_conn *conn)
{
#if defined(CONFIG_BT_BREDR)
if (conn->type == BT_CONN_TYPE_BR || !bt_dev.le.mtu) {
return bt_dev.br.mtu;
}
#endif /* CONFIG_BT_BREDR */
return bt_dev.le.mtu;
@ -1541,7 +1502,6 @@ static bool send_buf(struct bt_conn *conn, struct net_buf *buf)
/* Create & enqueue first fragment */
frag = create_frag(conn, buf);
if (!frag) {
return false;
}
@ -1556,7 +1516,6 @@ static bool send_buf(struct bt_conn *conn, struct net_buf *buf)
*/
while (buf->len > conn_mtu(conn)) {
frag = create_frag(conn, buf);
if (!frag) {
return false;
}
@ -1596,12 +1555,9 @@ static void conn_cleanup(struct bt_conn *conn)
k_queue_free(&conn->tx_queue._queue);
// k_queue_free(&conn->tx_notify._queue);
conn->tx_queue._queue.hdl = NULL;
//conn->tx_notify._queue.hdl = NULL;
if (conn->update_work.timer.timer.hdl) {
if (conn->update_work.timer.timer.hdl)
k_delayed_work_del_timer(&conn->update_work);
}
#endif
}
@ -1660,7 +1616,6 @@ void bt_conn_process_tx(struct bt_conn *conn)
/* Get next ACL packet for connection */
buf = net_buf_get(&conn->tx_queue, K_NO_WAIT);
BT_ASSERT(buf);
if (!send_buf(conn, buf)) {
net_buf_unref(buf);
}
@ -1747,15 +1702,12 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
*/
bt_conn_ref(conn);
break;
case BT_CONN_CONNECT:
if (IS_ENABLED(CONFIG_BT_CENTRAL) &&
conn->type == BT_CONN_TYPE_LE) {
k_delayed_work_cancel(&conn->update_work);
}
break;
default:
break;
}
@ -1767,7 +1719,6 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
/* TODO: Notify sco connected */
break;
}
k_fifo_init(&conn->tx_queue, 20);
k_poll_signal_raise(&conn_change, 0);
@ -1776,14 +1727,12 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
bt_l2cap_connected(conn);
notify_connected(conn);
break;
case BT_CONN_DISCONNECTED:
if (conn->type == BT_CONN_TYPE_SCO) {
/* TODO: Notify sco disconnected */
bt_conn_unref(conn);
break;
}
/* Notify disconnection and queue a dummy buffer to wake
* up and stop the tx thread for states where it was
* running.
@ -1822,18 +1771,14 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
}
break;
case BT_CONN_CONNECT_SCAN:
break;
case BT_CONN_CONNECT_DIR_ADV:
break;
case BT_CONN_CONNECT:
if (conn->type == BT_CONN_TYPE_SCO) {
break;
}
/*
* Timer is needed only for LE. For other link types controller
* will handle connection timeout.
@ -1844,10 +1789,8 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
}
break;
case BT_CONN_DISCONNECT:
break;
default:
BT_WARN("no valid (%u) state was set", state);
@ -1876,7 +1819,6 @@ struct bt_conn *bt_conn_lookup_handle(u16_t handle)
}
#if defined(CONFIG_BT_BREDR)
for (i = 0; i < ARRAY_SIZE(sco_conns); i++) {
if (!atomic_get(&sco_conns[i].ref)) {
continue;
@ -1892,7 +1834,6 @@ struct bt_conn *bt_conn_lookup_handle(u16_t handle)
return bt_conn_ref(&sco_conns[i]);
}
}
#endif
return NULL;
@ -1977,9 +1918,7 @@ void bt_conn_foreach(int type, void (*func)(struct bt_conn *conn, void *data),
func(&conns[i], data);
}
#if defined(CONFIG_BT_BREDR)
if (type & BT_CONN_TYPE_SCO) {
for (i = 0; i < ARRAY_SIZE(sco_conns); i++) {
if (!atomic_get(&sco_conns[i].ref)) {
@ -1989,7 +1928,6 @@ void bt_conn_foreach(int type, void (*func)(struct bt_conn *conn, void *data),
func(&sco_conns[i], data);
}
}
#endif /* defined(CONFIG_BT_BREDR) */
}
@ -2038,7 +1976,6 @@ int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info)
case BT_CONN_TYPE_LE:
info->le.dst = &conn->le.dst;
info->le.src = &bt_dev.id_addr[conn->id];
if (conn->role == BT_HCI_ROLE_MASTER) {
info->le.local = &conn->le.init_addr;
info->le.remote = &conn->le.resp_addr;
@ -2046,13 +1983,11 @@ int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info)
info->le.local = &conn->le.resp_addr;
info->le.remote = &conn->le.init_addr;
}
info->le.interval = conn->le.interval;
info->le.latency = conn->le.latency;
info->le.timeout = conn->le.timeout;
return 0;
#if defined(CONFIG_BT_BREDR)
case BT_CONN_TYPE_BR:
info->br.dst = &conn->br.dst;
return 0;
@ -2070,7 +2005,6 @@ int bt_conn_get_remote_dev_info(struct bt_conn_info *info)
if (!atomic_get(&conns[i].ref)) {
continue;
}
bt_conn_get_info(&conns[i], &info[link_num]);
link_num++;
}
@ -2085,7 +2019,6 @@ static int bt_hci_disconnect(struct bt_conn *conn, u8_t reason)
int err;
buf = bt_hci_cmd_create(BT_HCI_OP_DISCONNECT, sizeof(*disconn));
if (!buf) {
return -ENOBUFS;
}
@ -2095,7 +2028,6 @@ static int bt_hci_disconnect(struct bt_conn *conn, u8_t reason)
disconn->reason = reason;
err = bt_hci_cmd_send_sync(BT_HCI_OP_DISCONNECT, buf, NULL);
if (err) {
return err;
}
@ -2177,39 +2109,31 @@ int bt_conn_disconnect(struct bt_conn *conn, u8_t reason)
conn->type == BT_CONN_TYPE_LE) {
bt_le_set_auto_conn(&conn->le.dst, NULL);
}
#endif /* !defined(CONFIG_BT_WHITELIST) */
switch (conn->state) {
case BT_CONN_CONNECT_SCAN:
conn->err = reason;
bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
if (IS_ENABLED(CONFIG_BT_CENTRAL)) {
bt_le_scan_update(false);
}
return 0;
case BT_CONN_CONNECT_DIR_ADV:
conn->err = reason;
bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
if (IS_ENABLED(CONFIG_BT_PERIPHERAL)) {
/* User should unref connection object when receiving
* error in connection callback.
*/
return bt_le_adv_stop();
}
return 0;
case BT_CONN_CONNECT:
#if defined(CONFIG_BT_BREDR)
if (conn->type == BT_CONN_TYPE_BR) {
return bt_hci_connect_br_cancel(conn);
}
#endif /* CONFIG_BT_BREDR */
if (IS_ENABLED(CONFIG_BT_CENTRAL)) {
@ -2219,13 +2143,10 @@ int bt_conn_disconnect(struct bt_conn *conn, u8_t reason)
}
return 0;
case BT_CONN_CONNECTED:
return bt_hci_disconnect(conn, reason);
case BT_CONN_DISCONNECT:
return 0;
case BT_CONN_DISCONNECTED:
default:
return -ENOTCONN;
@ -2274,7 +2195,6 @@ int bt_conn_create_auto_le(const struct bt_le_conn_param *param)
/* Don't start initiator if we have general discovery procedure. */
conn = bt_conn_lookup_state_le(NULL, BT_CONN_CONNECT_SCAN);
if (conn) {
bt_conn_unref(conn);
return -EINVAL;
@ -2282,14 +2202,12 @@ int bt_conn_create_auto_le(const struct bt_le_conn_param *param)
/* Don't start initiator if we have direct discovery procedure. */
conn = bt_conn_lookup_state_le(NULL, BT_CONN_CONNECT);
if (conn) {
bt_conn_unref(conn);
return -EINVAL;
}
err = bt_le_auto_conn(param);
if (err) {
BT_ERR("Failed to start whitelist scan");
return err;
@ -2311,7 +2229,6 @@ int bt_conn_create_auto_stop(void)
}
err = bt_le_auto_conn_cancel();
if (err) {
BT_ERR("Failed to stop initiator");
return err;
@ -2345,21 +2262,17 @@ struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer,
}
conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, peer);
if (conn) {
switch (conn->state) {
case BT_CONN_CONNECT_SCAN:
bt_conn_set_param_le(conn, param);
return conn;
case BT_CONN_CONNECT:
case BT_CONN_CONNECTED:
return conn;
case BT_CONN_DISCONNECTED:
BT_WARN("Found valid but disconnected conn object");
goto start_scan;
default:
bt_conn_unref(conn);
return NULL;
@ -2376,7 +2289,6 @@ struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer,
/* Only default identity supported for now */
conn = bt_conn_add_le(BT_ID_DEFAULT, &dst);
if (!conn) {
return NULL;
}
@ -2403,10 +2315,8 @@ int bt_le_set_auto_conn(const bt_addr_le_t *addr,
/* Only default identity is supported */
conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr);
if (!conn) {
conn = bt_conn_add_le(BT_ID_DEFAULT, addr);
if (!conn) {
return -ENOMEM;
}
@ -2423,7 +2333,6 @@ int bt_le_set_auto_conn(const bt_addr_le_t *addr,
if (atomic_test_and_clear_bit(conn->flags,
BT_CONN_AUTO_CONNECT)) {
bt_conn_unref(conn);
if (conn->state == BT_CONN_CONNECT_SCAN) {
bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
}
@ -2435,7 +2344,6 @@ int bt_le_set_auto_conn(const bt_addr_le_t *addr,
if (param) {
bt_conn_set_state(conn, BT_CONN_CONNECT_SCAN);
}
bt_le_scan_update(false);
}
@ -2459,7 +2367,6 @@ struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,
BT_LE_ADV_OPT_ONE_TIME);
conn = bt_conn_lookup_addr_le(param->id, peer);
if (conn) {
switch (conn->state) {
case BT_CONN_CONNECT_DIR_ADV:
@ -2468,7 +2375,6 @@ struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,
*/
err = bt_le_adv_start_internal(&param_int, NULL, 0,
NULL, 0, peer);
if (err && (err != -EALREADY)) {
BT_WARN("Directed advertising could not be"
" started: %d",
@ -2476,17 +2382,13 @@ struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,
bt_conn_unref(conn);
return NULL;
}
__attribute__((fallthrough));
case BT_CONN_CONNECT:
case BT_CONN_CONNECTED:
return conn;
case BT_CONN_DISCONNECTED:
BT_WARN("Found valid but disconnected conn object");
goto start_adv;
default:
bt_conn_unref(conn);
return NULL;
@ -2494,7 +2396,6 @@ struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,
}
conn = bt_conn_add_le(param->id, peer);
if (!conn) {
return NULL;
}
@ -2503,7 +2404,6 @@ start_adv:
bt_conn_set_state(conn, BT_CONN_CONNECT_DIR_ADV);
err = bt_le_adv_start_internal(&param_int, NULL, 0, NULL, 0, peer);
if (err) {
BT_WARN("Directed advertising could not be started: %d", err);
@ -2523,7 +2423,6 @@ int bt_conn_le_conn_update(struct bt_conn *conn,
buf = bt_hci_cmd_create(BT_HCI_OP_LE_CONN_UPDATE,
sizeof(*conn_update));
if (!buf) {
return -ENOBUFS;
}
@ -2556,7 +2455,6 @@ struct net_buf *bt_conn_create_pdu_timeout(struct net_buf_pool *pool,
if (IS_ENABLED(CONFIG_BT_DEBUG_CONN)) {
buf = net_buf_alloc(pool, K_NO_WAIT);
if (!buf) {
BT_WARN("Unable to allocate buffer with K_NO_WAIT");
buf = net_buf_alloc(pool, timeout);
@ -2616,7 +2514,6 @@ int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
}
#if defined(CONFIG_BT_BREDR)
if (conn->type == BT_CONN_TYPE_BR) {
/* User entered passkey, reset user state. */
if (!atomic_test_and_clear_bit(conn->flags, BT_CONN_USER)) {
@ -2627,7 +2524,6 @@ int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
return ssp_passkey_reply(conn, passkey);
}
}
#endif /* CONFIG_BT_BREDR */
return -EINVAL;
@ -2645,7 +2541,6 @@ int bt_conn_auth_passkey_confirm(struct bt_conn *conn)
}
#if defined(CONFIG_BT_BREDR)
if (conn->type == BT_CONN_TYPE_BR) {
/* Allow user confirm passkey value, then reset user state. */
if (!atomic_test_and_clear_bit(conn->flags, BT_CONN_USER)) {
@ -2654,7 +2549,6 @@ int bt_conn_auth_passkey_confirm(struct bt_conn *conn)
return ssp_confirm_reply(conn);
}
#endif /* CONFIG_BT_BREDR */
return -EINVAL;
@ -2671,7 +2565,6 @@ int bt_conn_auth_cancel(struct bt_conn *conn)
}
#if defined(CONFIG_BT_BREDR)
if (conn->type == BT_CONN_TYPE_BR) {
/* Allow user cancel authentication, then reset user state. */
if (!atomic_test_and_clear_bit(conn->flags, BT_CONN_USER)) {
@ -2682,22 +2575,17 @@ int bt_conn_auth_cancel(struct bt_conn *conn)
case JUST_WORKS:
case PASSKEY_CONFIRM:
return ssp_confirm_neg_reply(conn);
case PASSKEY_INPUT:
return ssp_passkey_neg_reply(conn);
case PASSKEY_DISPLAY:
return bt_conn_disconnect(conn,
BT_HCI_ERR_AUTH_FAIL);
case LEGACY:
return pin_code_neg_reply(&conn->br.dst);
default:
break;
}
}
#endif /* CONFIG_BT_BREDR */
return -EINVAL;
@ -2711,16 +2599,13 @@ int bt_conn_auth_pairing_confirm(struct bt_conn *conn)
switch (conn->type) {
#if defined(CONFIG_BT_SMP)
case BT_CONN_TYPE_LE:
return bt_smp_auth_pairing_confirm(conn);
#endif /* CONFIG_BT_SMP */
#if defined(CONFIG_BT_BREDR)
case BT_CONN_TYPE_BR:
return ssp_confirm_reply(conn);
#endif /* CONFIG_BT_BREDR */
default:
return -EINVAL;
}
@ -2752,7 +2637,6 @@ struct bt_conn *bt_conn_lookup_id(u8_t id)
return bt_conn_ref(conn);
}
extern bool queue_inited;
int bt_conn_init(void)
{
#if defined(CONFIG_BT_SMP)
@ -2773,14 +2657,8 @@ int bt_conn_init(void)
struct net_buf_pool frag_pool;
#endif
#endif //BFLB_DYNAMIC_ALLOC_MEM
if (queue_inited == false) {
k_lifo_init(&acl_tx_pool.free, CONFIG_BT_L2CAP_TX_BUF_COUNT);
}
k_fifo_init(&free_tx, 20);
#endif
for (i = 0; i < ARRAY_SIZE(conn_tx); i++) {
k_fifo_put(&free_tx, &conn_tx[i]);
}
@ -2789,11 +2667,9 @@ int bt_conn_init(void)
#if defined(CONFIG_BT_SMP)
err = bt_smp_init();
if (err) {
return err;
}
#endif
bt_l2cap_init();

View File

@ -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;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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);
@ -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;
@ -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
@ -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;
}

View File

@ -99,8 +99,7 @@ static struct bt_sdp_attribute hfp_attrs[] = {
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,7 +249,6 @@ 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.
@ -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;
}

View File

@ -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(&param);
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;
}
@ -1023,7 +976,6 @@ void bt_iso_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
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.
*/
@ -1058,7 +1010,6 @@ 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
@ -1067,14 +1018,11 @@ void bt_iso_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
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.
*/
@ -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);

View File

@ -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,12 +408,10 @@ 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
@ -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;
}

View File

@ -54,36 +54,28 @@ 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)
{
if (!key) {
int i;
key = &key_pool[0];
for(i = 1; i < ARRAY_SIZE(key_pool); i++)
{
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)
{
if (current->aging_counter < key->aging_counter) {
key = current;
}
}
if(key)
{
if (key) {
bt_keys_link_key_clear(key);
}
}
#endif
if (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,9 +132,7 @@ 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))
{
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
int err;
char key[BT_SETTINGS_KEY_MAX];
bt_addr_le_t le_addr;
@ -156,13 +144,10 @@ void bt_keys_link_key_store(struct bt_keys_link_key *link_key)
err = settings_save_one(key, link_key->storage_start,
BT_KEYS_LINK_KEY_STORAGE_LEN);
if(err)
{
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;

View File

@ -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++;
@ -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;
@ -425,7 +405,6 @@ 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.
@ -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, &param);
rsp = net_buf_add(buf, sizeof(*rsp));
if (accepted) {
rsp->result = sys_cpu_to_le16(BT_L2CAP_CONN_PARAM_ACCEPTED);
} else {
@ -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.
*/
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,7 +890,6 @@ 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;
@ -933,7 +899,6 @@ static void le_conn_req(struct bt_l2cap *l2cap, u8_t ident,
* 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;
@ -1230,13 +1182,11 @@ static struct net_buf *l2cap_chan_create_seg(struct bt_l2cap_le_chan *ch,
/* 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;
}
@ -1312,7 +1261,6 @@ static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, struct net_buf *buf,
*/
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);
@ -1728,7 +1650,6 @@ static void l2cap_chan_le_recv_seg(struct bt_l2cap_le_chan *chan,
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);
}

View File

@ -124,7 +124,8 @@ 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;
@ -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++;
@ -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));
}
@ -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);
@ -530,7 +520,6 @@ 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
@ -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;
@ -591,9 +581,7 @@ 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
@ -603,7 +591,6 @@ static enum l2cap_br_conn_security_result l2cap_br_conn_security(struct bt_l2cap
if (BT_FEAT_HOST_SSP(chan->conn->br.features)) {
chan->required_sec_level = BT_SECURITY_L2;
}
break;
}
@ -700,7 +687,6 @@ 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;
@ -722,7 +708,6 @@ 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
@ -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;
@ -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);
@ -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 = {
@ -1007,7 +983,6 @@ static void l2cap_br_conf_req(struct bt_l2cap_br *l2cap, uint8_t ident,
* way out here.
*/
goto send_rsp;
default:
if (!hint) {
BT_DBG("option %u not handled", opt->type);
@ -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:
@ -1277,10 +1247,8 @@ int bt_l2cap_br_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan,
* 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,
@ -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);
@ -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);

View File

@ -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;
}

View File

@ -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,11 +322,9 @@ 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 */
if (match - insts > 1) {
@ -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;
}

View File

@ -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;
@ -282,7 +282,6 @@ static void rfcomm_dlc_disconnect(struct bt_rfcomm_dlc *dlc)
rfcomm_dlc_tx_give_credits(dlc, 1);
k_sem_give(&dlc->session->fc);
break;
default:
rfcomm_dlc_destroy(dlc);
break;
@ -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;
@ -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);
@ -823,19 +818,16 @@ 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;
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;
@ -850,11 +842,9 @@ static int rfcomm_dlc_close(struct bt_rfcomm_dlc *dlc)
*/
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 {
@ -945,7 +928,6 @@ static int rfcomm_send_pn(struct bt_rfcomm_dlc *dlc, uint8_t cr)
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;
}
@ -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;
}
@ -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 ");
@ -1367,7 +1320,6 @@ static void rfcomm_handle_msg(struct bt_rfcomm_session *session,
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 ");
@ -1387,7 +1339,6 @@ static void rfcomm_handle_msg(struct bt_rfcomm_session *session,
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;
@ -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 = {

View File

@ -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;
}
@ -563,7 +547,6 @@ 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;
}
@ -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;
@ -750,11 +732,9 @@ 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;
@ -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;
@ -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;
}
@ -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);
}
@ -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;
@ -1648,18 +1616,15 @@ static uint16_t sdp_client_get_total(struct bt_sdp_client *session,
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;
@ -1756,7 +1718,6 @@ static void sdp_client_notify_result(struct bt_sdp_client *session,
* 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");
@ -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;
@ -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);
@ -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;
@ -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;
@ -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;
@ -2489,46 +2412,36 @@ 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.
@ -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);

View File

@ -60,7 +60,6 @@ void bt_settings_encode_key(char *path, size_t path_size, const char *subsys,
strcpy(path, "bt/");
strncpy(&path[len], subsys, path_size - len);
len = strlen(path);
if (len < path_size) {
path[len] = '/';
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,11 +244,9 @@ 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;
@ -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

View File

@ -24,8 +24,7 @@
*/
static const struct bt_uuid_128 uuid128_base = {
.uuid = { BT_UUID_TYPE_128 },
.val = {
BT_UUID_128_ENCODE(
.val = { BT_UUID_128_ENCODE(
0x00000000, 0x0000, 0x1000, 0x8000, 0x00805F9B34FB) }
};
@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -644,8 +644,7 @@ struct bt_conn_oob_info {
union {
/** LESC OOB pairing parameters */
struct
{
struct {
/** OOB data configuration */
enum {
/** Local OOB data requested */

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {

View File

@ -17,8 +17,7 @@
#define BL_NO_WAIT 0x0
#define ms2tick pdMS_TO_TICKS
typedef struct
{
typedef struct {
void *hdl;
} bl_hdl_t;

View File

@ -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,7 +571,7 @@
#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_ADV_WITH_PUBLIC_ADDR 1
#define CONFIG_BT_ATT_PREPARE_COUNT 64
#endif
#endif //BFLB_BLE
@ -606,6 +606,9 @@ happens, which cause memory leak issue.*/
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

View File

@ -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 */

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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
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;
}

View File

@ -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);

View File

@ -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
}
/**

View File

@ -57,8 +57,7 @@ extern "C" {
* - array[4] contains bits 15-8, and
* - array[5] contains bits 7-0.
*/
typedef struct
{
typedef struct {
OI_UINT8 addr[OI_BD_ADDR_BYTE_SIZE]; /**< Bluetooth device address represented as an array of 8-bit values */
} OI_BD_ADDR;
@ -101,8 +100,7 @@ typedef OI_UINT32 OI_UUID32;
* native on the target (local) device. The remainder of the 128-bit UUID is
* stored as bytes in big-endian order.
*/
typedef struct
{
typedef struct {
OI_UINT32 ms32bits; /**< most significant 32 bits of 128-bit UUID */
OI_UINT8 base[OI_BT_UUID128_SIZE - sizeof(OI_UINT32)]; /**< remainder of 128-bit UUID, array of 8-bit values */
} OI_UUID128;
@ -135,16 +133,14 @@ typedef struct
* - array[14] contains bits 112- 119, and
* - array[15] contains bits 120- 127.
*/
typedef struct
{
typedef struct {
OI_UINT8 key[OI_BT_LINK_KEY_SIZE]; /**< link key represented as an array of 8-bit values */
} OI_LINK_KEY;
/** Out-of-band data size - C and R values are 16-bytes each */
#define OI_BT_OOB_NUM_BYTES 16
typedef struct
{
typedef struct {
OI_UINT8 value[OI_BT_OOB_NUM_BYTES]; /**< same struct used for C and R values */
} OI_OOB_DATA;
@ -166,8 +162,7 @@ typedef enum {
#define OI_BT_PIN_CODE_SIZE 16
/** data type for a PIN (PINs are treated as strings, so endianness does not apply.) */
typedef struct
{
typedef struct {
OI_UINT8 pin[OI_BT_PIN_CODE_SIZE]; /**< PIN represented as an array of 8-bit values */
} OI_PIN_CODE;

View File

@ -125,8 +125,7 @@ Declarations of codec functions, data types, and macros.
typedef OI_INT16 SBC_BUFFER_T;
/** Used internally. */
typedef struct
{
typedef struct {
OI_UINT16 frequency; /**< The sampling frequency. Input parameter. */
OI_UINT8 freqIndex;
@ -152,8 +151,7 @@ typedef struct
} OI_CODEC_SBC_FRAME_INFO;
/** Used internally. */
typedef struct
{
typedef struct {
const OI_CHAR *codecInfo;
OI_CODEC_SBC_FRAME_INFO frameInfo;
OI_INT8 scale_factor[SBC_MAX_CHANNELS * SBC_MAX_BANDS];
@ -192,8 +190,7 @@ typedef struct
sizeof(OI_UINT32))
/** Opaque parameter to decoding functions; maintains decoder context. */
typedef struct
{
typedef struct {
OI_CODEC_SBC_COMMON_CONTEXT common;
OI_UINT8 limitFrameFormat; /* Boolean, set by OI_CODEC_SBC_DecoderLimit() */
OI_UINT8 restrictSubbands;
@ -202,13 +199,11 @@ typedef struct
OI_UINT8 sbc_mode; /* OI_SBC_MODE_STD or OI_SBC_MODE_MSBC */
} OI_CODEC_SBC_DECODER_CONTEXT;
typedef struct
{
typedef struct {
OI_UINT32 data[CODEC_DATA_WORDS(1, SBC_CODEC_FAST_FILTER_BUFFERS)];
} OI_CODEC_SBC_CODEC_DATA_MONO;
typedef struct
{
typedef struct {
OI_UINT32 data[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)];
} OI_CODEC_SBC_CODEC_DATA_STEREO;

View File

@ -100,8 +100,7 @@ static const OI_UINT8 band_values[] = { 4, 8 };
#define TEST_MODE_SENTINEL_LENGTH 4
/** Used internally. */
typedef struct
{
typedef struct {
union {
const OI_UINT8 *r;
OI_UINT8 *w;

View File

@ -83,8 +83,7 @@ extern "C" {
*/
/** unsigned 64-bit integer as a structure of two unsigned 32-bit integers */
typedef struct
{
typedef struct {
OI_UINT32 I1; /**< most significant 32 bits */
OI_UINT32 I2; /**< least significant 32 bits */
} OI_UINT64;
@ -99,8 +98,7 @@ typedef struct
}
/** signed 64-bit integer as a structure of one unsigned 32-bit integer and one signed 32-bit integer */
typedef struct
{
typedef struct {
OI_INT32 I1; /**< most significant 32 bits as a signed integer */
OI_UINT32 I2; /**< least significant 32 bits as an unsigned integer */
} OI_INT64;
@ -115,8 +113,7 @@ typedef struct
}
/** unsigned 128-bit integer as a structure of four unsigned 32-bit integers */
typedef struct
{
typedef struct {
OI_UINT32 I1; /**< most significant 32 bits */
OI_UINT32 I2; /**< second-most significant 32 bits */
OI_UINT32 I3; /**< third-most significant 32 bits */
@ -133,8 +130,7 @@ typedef struct
}
/** signed 128-bit integer as a structure of three unsigned 32-bit integers and one signed 32-bit integer */
typedef struct
{
typedef struct {
OI_INT32 I1; /**< most significant 32 bits as a signed integer */
OI_UINT32 I2; /**< second-most significant 32 bits as an unsigned integer */
OI_UINT32 I3; /**< third-most significant 32 bits as an unsigned integer */

View File

@ -84,8 +84,7 @@ typedef OI_UINT16 OI_INTERVAL;
* stack's real-time clock and absolute time and date is implementation-dependent.
*/
typedef struct
{
typedef struct {
OI_INT32 seconds;
OI_INT16 mseconds;
} OI_TIME;

View File

@ -279,11 +279,9 @@ PRIVATE void OI_SBC_SynthFrame_80(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT1
for (blk = blkstart; blk < blkstop; blk++) {
if (offset == 0) {
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 72, context->common.filterBuffer[0]);
if (nrof_channels == 2) {
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 72, context->common.filterBuffer[1]);
}
offset = context->common.filterBufferLen - 80;
} else {
offset -= 1 * 8;
@ -294,10 +292,8 @@ PRIVATE void OI_SBC_SynthFrame_80(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT1
SYNTH80(pcm + ch, context->common.filterBuffer[ch] + offset, pcmStrideShift);
s += 8;
}
pcm += (8 << pcmStrideShift);
}
context->common.filterBufferOffset = offset;
}
@ -314,16 +310,13 @@ PRIVATE void OI_SBC_SynthFrame_4SB(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT
for (blk = blkstart; blk < blkstop; blk++) {
if (offset == 0) {
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 72, context->common.filterBuffer[0]);
if (nrof_channels == 2) {
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 72, context->common.filterBuffer[1]);
}
offset = context->common.filterBufferLen - 80;
} else {
offset -= 8;
}
for (ch = 0; ch < nrof_channels; ch++) {
cosineModulateSynth4(context->common.filterBuffer[ch] + offset, s);
SynthWindow40_int32_int32_symmetry_with_sum(pcm + ch,
@ -331,10 +324,8 @@ PRIVATE void OI_SBC_SynthFrame_4SB(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT
pcmStrideShift);
s += 4;
}
pcm += (4 << pcmStrideShift);
}
context->common.filterBufferOffset = offset;
}
@ -353,25 +344,20 @@ PRIVATE void OI_SBC_SynthFrame_Enhanced(OI_CODEC_SBC_DECODER_CONTEXT *context, O
for (blk = blkstart; blk < blkstop; blk++) {
if (offset == 0) {
COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 104, context->common.filterBuffer[0]);
if (nrof_channels == 2) {
COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 104, context->common.filterBuffer[1]);
}
offset = context->common.filterBufferLen - 112;
} else {
offset -= 8;
}
for (ch = 0; ch < nrof_channels; ++ch) {
DCT2_8(context->common.filterBuffer[ch] + offset, s);
SYNTH112(pcm + ch, context->common.filterBuffer[ch] + offset, pcmStrideShift);
s += 8;
}
pcm += (8 << pcmStrideShift);
}
context->common.filterBufferOffset = offset;
}
@ -401,7 +387,6 @@ PRIVATE void OI_SBC_SynthFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT16 *
OI_UINT nrof_channels = context->common.frameInfo.nrof_channels;
OI_ASSERT(nrof_subbands == 4 || nrof_subbands == 8);
if (nrof_subbands == 4) {
SynthFrame4SB[nrof_channels](context, pcm, start_block, nrof_blocks);
#ifdef SBC_ENHANCED

View File

@ -967,10 +967,8 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
ps32SbBuf = pstrEncParams->s32SbBuffer;
Offset2 = (SINT32)(EncMaxShiftCounter + 40);
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
/* Store new samples */
if (s32NumOfChannels == 1) {
s16X[3 + Offset] = *ps16PcmBuf;
@ -999,7 +997,6 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
s16X[Offset2 + 0 + Offset] = *ps16PcmBuf;
ps16PcmBuf++;
}
for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
ChOffset = s32Ch * Offset2 + Offset;
@ -1009,7 +1006,6 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
ps32SbBuf += SUB_BANDS_4;
}
if (s32NumOfChannels == 1) {
if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X4;
@ -1061,10 +1057,8 @@ void SbcAnalysisFilter8(SBC_ENC_PARAMS *pstrEncParams)
ps32SbBuf = pstrEncParams->s32SbBuffer;
Offset2 = (SINT32)(EncMaxShiftCounter + 80);
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
/* Store new samples */
if (s32NumOfChannels == 1) {
s16X[7 + Offset] = *ps16PcmBuf;
@ -1117,7 +1111,6 @@ void SbcAnalysisFilter8(SBC_ENC_PARAMS *pstrEncParams)
s16X[Offset2 + 0 + Offset] = *ps16PcmBuf;
ps16PcmBuf++;
}
for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
ChOffset = s32Ch * Offset2 + Offset;
@ -1127,7 +1120,6 @@ void SbcAnalysisFilter8(SBC_ENC_PARAMS *pstrEncParams)
ps32SbBuf += SUB_BANDS_8;
}
if (s32NumOfChannels == 1) {
if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X8;
@ -1149,7 +1141,6 @@ void SbcAnalysisFilter8(SBC_ENC_PARAMS *pstrEncParams)
void SbcAnalysisInit(void)
{
static bool loaded = false;
if (!loaded) {
loaded = true;
#if BT_BLE_DYNAMIC_ENV_MEMORY == TRUE
@ -1162,7 +1153,6 @@ void SbcAnalysisInit(void)
s16X = (SINT16 *)s32X;
#endif
}
memset(s16X, 0, ENC_VX_BUFFER_SIZE * sizeof(SINT16));
ShiftCounter = 0;
}

View File

@ -158,20 +158,16 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
#else
UINT8 Index, k;
SINT32 temp;
/*Calculate 4 subband samples by matrixing*/
for (Index = 0; Index < 8; Index++) {
temp = 0;
for (k = 0; k < 16; k++) {
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 );*/
temp += (gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] >> 16));
temp += ((gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);
}
pOutVect[Index] = temp;
}
#endif
/* BT_WARN("pOutVect: 0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x\n",\
pOutVect[0],pOutVect[1],pOutVect[2],pOutVect[3],pOutVect[4],pOutVect[5],pOutVect[6],pOutVect[7]);*/
@ -229,20 +225,16 @@ void SBC_FastIDCT4(SINT32 *pInVect, SINT32 *pOutVect)
#else
UINT8 Index, k;
SINT32 temp;
/*Calculate 4 subband samples by matrixing*/
for (Index = 0; Index < 4; Index++) {
temp = 0;
for (k = 0; k < 8; k++) {
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 ); */
temp += (gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] >> 16));
temp += ((gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);
}
pOutVect[Index] = temp;
}
#endif
}

View File

@ -70,7 +70,6 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
} else {
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
if (s32NumOfSubBands == 4) {
ps16GenTabPtr = (SINT16 *)
sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
@ -78,21 +77,18 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenTabPtr = (SINT16 *)
sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
}
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if (pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb] == 0) {
*(ps16GenBufPtr) = -5;
} else {
s32Loudness =
(SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb] - *ps16GenTabPtr);
if (s32Loudness > 0) {
*(ps16GenBufPtr) = (SINT16)(s32Loudness >> 1);
} else {
*(ps16GenBufPtr) = (SINT16)s32Loudness;
}
}
ps16GenBufPtr++;
ps16GenTabPtr++;
}
@ -101,7 +97,6 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
/* max bitneed index is searched*/
s32MaxBitNeed = 0;
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if (*(ps16GenBufPtr) > s32MaxBitNeed) {
s32MaxBitNeed = *(ps16GenBufPtr);
@ -109,13 +104,11 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenBufPtr++;
}
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
/*iterative process to find hwo many bitslices fit into the bitpool*/
s32BitSlice = s32MaxBitNeed + 1;
s32BitCount = pstrCodecParams->s16BitPool;
s32SliceCount = 0;
do {
s32BitSlice--;
s32BitCount -= s32SliceCount;
@ -129,11 +122,9 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
s32SliceCount++;
}
}
ps16GenBufPtr++;
} /*end of for*/
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
} while (s32BitCount - s32SliceCount > 0);
@ -145,7 +136,6 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
/*Bits are distributed until the last bitslice is reached*/
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if (*(ps16GenBufPtr) < s32BitSlice + 2) {
*(ps16GenArrPtr) = 0;
@ -158,12 +148,10 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenBufPtr++;
ps16GenArrPtr++;
}
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
/*the remaining bits are allocated starting at subband 0*/
s32Sb = 0;
while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) {
if ((*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16)) {
(*(ps16GenArrPtr))++;
@ -173,22 +161,18 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
*(ps16GenArrPtr) = 2;
s32BitCount -= 2;
}
s32Sb++;
ps16GenArrPtr++;
ps16GenBufPtr++;
}
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
s32Sb = 0;
while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) {
if (*(ps16GenArrPtr) < 16) {
(*(ps16GenArrPtr))++;
s32BitCount--;
}
s32Sb++;
ps16GenArrPtr++;
}

View File

@ -67,7 +67,6 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
pas16ScaleFactor = pstrCodecParams->as16ScaleFactor;
s32MaxBitNeed = 0;
ps16GenBufPtr = ps16BitNeed;
for (s32Ch = 0; s32Ch < 2; s32Ch++) {
if (s32NumOfSubBands == 4) {
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
@ -91,7 +90,6 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
if (*ps16GenBufPtr > s32MaxBitNeed) {
s32MaxBitNeed = *ps16GenBufPtr;
}
pas16ScaleFactor++;
ps16GenBufPtr++;
ps16GenTabPtr++;
@ -103,7 +101,6 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
s32BitSlice = s32MaxBitNeed + 1;
s32BitCount = s32BitPool;
s32SliceCount = 0;
do {
s32BitSlice--;
s32BitCount -= s32SliceCount;
@ -118,7 +115,6 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
s32SliceCount++;
}
}
ps16GenBufPtr++;
}
} while (s32BitCount - s32SliceCount > 0);
@ -131,7 +127,6 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
/* Bits are distributed until the last bitslice is reached */
ps16GenBufPtr = ps16BitNeed;
ps16GenArrPtr = pstrCodecParams->as16Bits;
for (s32Ch = 0; s32Ch < 2; s32Ch++) {
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if (*ps16GenBufPtr < s32BitSlice + 2) {
@ -141,7 +136,6 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
(SINT16)(*(ps16GenBufPtr)-s32BitSlice) :
16;
}
ps16GenBufPtr++;
ps16GenArrPtr++;
}
@ -161,7 +155,6 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
*(ps16GenArrPtr) = 2;
s32BitCount -= 2;
}
if (s32Ch == 1) {
s32Ch = 0;
s32Sb++;
@ -184,7 +177,6 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
(*(ps16GenArrPtr))++;
s32BitCount--;
}
if (s32Ch == 1) {
s32Ch = 0;
s32Sb++;

View File

@ -61,7 +61,6 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
#else
pstrEncParams->ps16NextPcmBuffer = pstrEncParams->as16PcmBuffer;
#endif
do {
/* SBC ananlysis filter*/
if (s32NumOfSubBands == 4) {
@ -79,12 +78,10 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
for (s32Sb = 0; s32Sb < s32Ch; s32Sb++) {
SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
s32MaxValue = 0;
for (s32Blk = s32NumOfBlocks; s32Blk > 0; s32Blk--) {
if (s32MaxValue < abs32(*SbBuffer)) {
s32MaxValue = abs32(*SbBuffer);
}
SbBuffer += s32Ch;
}
@ -95,21 +92,17 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
break;
}
}
*ps16ScfL++ = (SINT16)u32Count;
if (u32Count > maxBit) {
maxBit = u32Count;
}
}
/* In case of JS processing,check whether to use JS */
#if (SBC_JOINT_STE_INCLUDED == TRUE)
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
/* Calculate sum and differance scale factors for making JS decision */
ps16ScfL = pstrEncParams->as16ScaleFactor;
/* calculate the scale factor of Joint stereo max sum and diff */
for (s32Sb = 0; s32Sb < s32NumOfSubBands - 1; s32Sb++) {
SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
@ -117,44 +110,33 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
s32MaxValue = 0;
pSum = s32LRSum;
pDiff = s32LRDiff;
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
*pSum = (*SbBuffer + *(SbBuffer + s32NumOfSubBands)) >> 1;
if (abs32(*pSum) > s32MaxValue) {
s32MaxValue = abs32(*pSum);
}
pSum++;
*pDiff = (*SbBuffer - *(SbBuffer + s32NumOfSubBands)) >> 1;
if (abs32(*pDiff) > s32MaxValue2) {
s32MaxValue2 = abs32(*pDiff);
}
pDiff++;
SbBuffer += s32Ch;
}
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
for (; u32Count < 15; u32Count++) {
if (s32MaxValue <= (SINT32)(0x8000 << u32Count)) {
break;
}
}
u32CountSum = u32Count;
u32Count = (s32MaxValue2 > 0x800000) ? 9 : 0;
for (; u32Count < 15; u32Count++) {
if (s32MaxValue2 <= (SINT32)(0x8000 << u32Count)) {
break;
}
}
u32CountDiff = u32Count;
if ((*ps16ScfL + *(ps16ScfL + s32NumOfSubBands)) > (SINT16)(u32CountSum + u32CountDiff)) {
if (u32CountSum > maxBit) {
maxBit = u32CountSum;
@ -184,13 +166,10 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
} else {
pstrEncParams->as16Join[s32Sb] = 0;
}
ps16ScfL++;
}
pstrEncParams->as16Join[s32Sb] = 0;
}
#endif
pstrEncParams->s16MaxBitNeed = (SINT16)maxBit;
@ -279,7 +258,6 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
if (pstrEncParams->s16BitPool < 0) {
pstrEncParams->s16BitPool = 0;
}
/* sampling freq */
HeaderParams = ((pstrEncParams->s16SamplingFreq & 3) << 6);

View File

@ -83,7 +83,6 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
#endif
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
if (pstrEncParams->sbc_mode != SBC_MODE_MSBC) {
*pu8PacketPtr++ = (UINT8)SBC_SYNC_WORD_STD; /*Sync word*/
*pu8PacketPtr++ = (UINT8)(pstrEncParams->FrameHeader);
@ -95,14 +94,12 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
*pu8PacketPtr++ = 0;
*pu8PacketPtr = 0;
}
pu8PacketPtr += 2; /*skip for CRC*/
/*here it indicate if it is byte boundary or nibble boundary*/
s32PresentBit = 8;
Temp = 0;
#if (SBC_JOINT_STE_INCLUDED == TRUE)
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
/* pack join stero parameters */
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
@ -118,13 +115,11 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
Temp = 0;
}
}
#endif
/* Pack Scale factor */
ps16GenPtr = pstrEncParams->as16ScaleFactor;
s32Sb = s32NumOfChannels * s32NumOfSubBands;
/*Temp=*pu8PacketPtr;*/
for (s32Ch = s32Sb; s32Ch > 0; s32Ch--) {
Temp <<= 4;
@ -143,14 +138,11 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
ps32SbPtr = pstrEncParams->s32SbBuffer;
/*Temp=*pu8PacketPtr;*/
s32NumOfBlocks = pstrEncParams->s16NumOfBlocks;
for (s32Blk = s32NumOfBlocks - 1; s32Blk >= 0; s32Blk--) {
ps16GenPtr = pstrEncParams->as16Bits;
ps16ScfPtr = pstrEncParams->as16ScaleFactor;
for (s32Ch = s32Sb - 1; s32Ch >= 0; s32Ch--) {
s32LoopCount = *ps16GenPtr++;
if (s32LoopCount != 0) {
#if (SBC_IS_64_MULT_IN_QUANTIZER == TRUE)
/* finding level from reconstruction part of decoder */
@ -206,7 +198,6 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
Temp = 0;
s32PresentBit = 8;
}
Temp <<= s32LoopCount;
/* remove the unwanted msbs */
@ -218,7 +209,6 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
s32PresentBit -= s32LoopCount;
}
}
ps16ScfPtr++;
ps32SbPtr++;
}
@ -238,7 +228,6 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
so that many more bytes are included in CRC calculation.
*/
Temp = *pu8PacketPtr;
for (s32Ch = 1; s32Ch < (s32LoopCount + 4); s32Ch++) {
/* skip sync word and CRC bytes */
if (s32Ch != 3) {
@ -249,7 +238,6 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
u8CRC &= 0xFF;
}
}
Temp = *(++pu8PacketPtr);
}

View File

@ -66,16 +66,14 @@ static void ble_tp_connected(struct bt_conn *conn, u8_t err)
int tx_time = 0x0848;
int ret = -1;
if (err) {
if (err)
return;
}
printf("%s\n", __func__);
ble_tp_conn = conn;
//set data length after connected.
ret = bt_le_set_data_len(ble_tp_conn, tx_octets, tx_time);
if (!ret) {
BT_WARN("ble tp set data length success.\n");
} else {
@ -85,7 +83,6 @@ static void ble_tp_connected(struct bt_conn *conn, u8_t err)
//exchange mtu size after connected.
exchg_mtu.func = ble_tp_tx_mtu_size;
ret = bt_gatt_exchange_mtu(ble_tp_conn, &exchg_mtu);
if (!ret) {
BT_WARN("ble tp exchange mtu size pending.\n");
} else {

View File

@ -183,10 +183,8 @@ static int dis_set(const char *name, size_t len_rd,
const char *next;
nlen = settings_name_next(name, &next);
if (!strncmp(name, "manuf", nlen)) {
len = read_cb(store, &dis_manuf, sizeof(dis_manuf) - 1);
if (len < 0) {
BT_ERR("Failed to read manufacturer from storage"
" (err %d)",
@ -196,13 +194,10 @@ static int dis_set(const char *name, size_t len_rd,
BT_DBG("Manufacturer set to %s", dis_manuf);
}
return 0;
}
if (!strncmp(name, "model", nlen)) {
len = read_cb(store, &dis_model, sizeof(dis_model) - 1);
if (len < 0) {
BT_ERR("Failed to read model from storage"
" (err %d)",
@ -212,16 +207,12 @@ static int dis_set(const char *name, size_t len_rd,
BT_DBG("Model set to %s", dis_model);
}
return 0;
}
#if defined(CONFIG_BT_GATT_DIS_SERIAL_NUMBER)
if (!strncmp(name, "serial", nlen)) {
len = read_cb(store, &dis_serial_number,
sizeof(dis_serial_number) - 1);
if (len < 0) {
BT_ERR("Failed to read serial number from storage"
" (err %d)",
@ -231,16 +222,12 @@ static int dis_set(const char *name, size_t len_rd,
BT_DBG("Serial number set to %s", dis_serial_number);
}
return 0;
}
#endif
#if defined(CONFIG_BT_GATT_DIS_FW_REV)
if (!strncmp(name, "fw", nlen)) {
len = read_cb(store, &dis_fw_rev, sizeof(dis_fw_rev) - 1);
if (len < 0) {
BT_ERR("Failed to read firmware revision from storage"
" (err %d)",
@ -250,16 +237,12 @@ static int dis_set(const char *name, size_t len_rd,
BT_DBG("Firmware revision set to %s", dis_fw_rev);
}
return 0;
}
#endif
#if defined(CONFIG_BT_GATT_DIS_HW_REV)
if (!strncmp(name, "hw", nlen)) {
len = read_cb(store, &dis_hw_rev, sizeof(dis_hw_rev) - 1);
if (len < 0) {
BT_ERR("Failed to read hardware revision from storage"
" (err %d)",
@ -269,16 +252,12 @@ static int dis_set(const char *name, size_t len_rd,
BT_DBG("Hardware revision set to %s", dis_hw_rev);
}
return 0;
}
#endif
#if defined(CONFIG_BT_GATT_DIS_SW_REV)
if (!strncmp(name, "sw", nlen)) {
len = read_cb(store, &dis_sw_rev, sizeof(dis_sw_rev) - 1);
if (len < 0) {
BT_ERR("Failed to read software revision from storage"
" (err %d)",
@ -288,10 +267,8 @@ static int dis_set(const char *name, size_t len_rd,
BT_DBG("Software revision set to %s", dis_sw_rev);
}
return 0;
}
#endif
return 0;
}

View File

@ -20,6 +20,7 @@
#include <uuid.h>
#include <gatt.h>
#include "hog.h"
#include "log.h"
enum {
HIDS_REMOTE_WAKE = BIT(0),
@ -183,16 +184,14 @@ int hog_notify(struct bt_conn *conn, uint16_t hid_usage, uint8_t press)
}
}
if (!remote_key) {
if (!remote_key)
return EINVAL;
}
if (remote_key->hid_page == HID_PAGE_KBD) {
attr = &attrs[BT_CHAR_BLE_HID_REPORT_ATTR_VAL_INDEX];
len = 3;
} else {
} else
return EINVAL;
}
sys_put_le16(hid_usage, data);
data[2] = 0;

View File

@ -45,7 +45,6 @@ void oad_send_data_to_uart(uint8_t cmd_type, uint8_t *data, uint8_t len)
if (len + 2 > 128) {
return;
}
memset(final_data, 0, 128);
final_data[0] = cmd_type;
@ -98,14 +97,12 @@ static void oad_start_identity(char *pcWriteBuffer, int xWriteBufferLen, int arg
uint8_t buf[50];
int len = 0;
if (!default_conn) {
if (!default_conn)
return;
}
memset(buf, 0, 50);
get_bytearray_from_string(&argv[1], buf, 50);
len = buf[1];
if (len + 2 >= 50) {
BT_WARN("Failed to receved data\r\n");
return;
@ -118,9 +115,8 @@ static void oad_start_update(char *pcWriteBuffer, int xWriteBufferLen, int argc,
{
uint8_t buf[MAX_ATT_SIZE];
if (!default_conn) {
if (!default_conn)
return;
}
memset(buf, 0, MAX_ATT_SIZE);
get_bytearray_from_string(&argv[1], buf, MAX_ATT_SIZE);
@ -154,21 +150,18 @@ static u8_t oad_discover_func(struct bt_conn *conn, const struct bt_gatt_attr *a
BT_WARN("Service %s found: attr 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));
BT_WARN("Characteristic %s found: attr->handle %x chrcval->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));
BT_WARN("Include %s found: attr 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));
@ -202,7 +195,6 @@ static void oad_discovery(char *pcWriteBuffer, int xWriteBufferLen, int argc, ch
get_uint8_from_string(&argv[1], &disc_type);
BT_WARN("disc_type = [%d]\r\n", disc_type);
if (disc_type == 0) {
discover_params.type = BT_GATT_DISCOVER_PRIMARY;
} else if (disc_type == 1) {
@ -217,10 +209,8 @@ static void oad_discovery(char *pcWriteBuffer, int xWriteBufferLen, int argc, ch
BT_WARN("Invalid discovery type\r\n");
return;
}
//discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR;
err = bt_gatt_discover(default_conn, &discover_params);
if (err) {
BT_WARN("Discover failed (err %d)\r\n", err);
} else {
@ -241,7 +231,6 @@ static u8_t oad_client_recv_data(struct bt_conn *conn,
params->value_handle = 0U;
return BT_GATT_ITER_STOP;
}
BT_WARN("oad_client_recv_data:%s\r\n", bt_hex(pdata, length));
oad_client_notify_handler(data, length);
@ -251,7 +240,6 @@ static u8_t oad_client_recv_data(struct bt_conn *conn,
static void oad_subscribe(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
{
int err;
if (!default_conn) {
BT_WARN("Not connected\r\n");
return;
@ -264,7 +252,6 @@ static void oad_subscribe(char *pcWriteBuffer, int xWriteBufferLen, int argc, ch
subscribe_params.notify = oad_client_recv_data;
err = bt_gatt_subscribe(default_conn, &subscribe_params);
if (err) {
BT_WARN("Subscribe failed (err %d)\r\n", err);
} else {
@ -286,7 +273,6 @@ void oad_client_notify_handler(void *buf, u16_t len)
}
cmd_id = pdata[0];
switch (cmd_id) {
case OAD_CMD_IMAG_IDENTITY:
if (len == sizeof(struct oad_image_identity_t) + 1) {
@ -297,7 +283,6 @@ void oad_client_notify_handler(void *buf, u16_t len)
} else {
BT_WARN("Length (%d) sizeof (%d) errors\r\n", len, sizeof(struct oad_image_identity_t));
}
break;
case OAD_CMD_IMAG_BLOCK_REQ:
@ -309,7 +294,6 @@ void oad_client_notify_handler(void *buf, u16_t len)
} else {
BT_WARN("Length (%d) sizeof (%d) errors\r\n", len, sizeof(struct oad_block_req_t));
}
break;
case OAD_CMD_IMAG_UPGRD_END:
@ -320,7 +304,6 @@ void oad_client_notify_handler(void *buf, u16_t len)
} else {
BT_WARN("Length (%d) sizeof (%d) errors\r\n", len, sizeof(struct oad_upgrd_end_t));
}
break;
default:
@ -332,9 +315,8 @@ void oad_send_image_identity_to_servicer(struct bt_conn *conn, u8_t *data, u16_t
{
u16_t handle = in_handle;
if (!conn) {
if (!conn)
return;
}
data[0] = OAD_CMD_IMAG_IDENTITY;
bt_gatt_write_without_response(conn, handle, data, len, false);
@ -345,15 +327,13 @@ void oad_send_block_resp_to_servicer(struct bt_conn *conn, u8_t *data, u8_t len)
u16_t handle = in_handle;
u8_t slen = 0;
if (!conn) {
if (!conn)
return;
}
data[0] = OAD_CMD_IMAG_BLOCK_RESP;
if (len <= bt_gatt_get_mtu(conn)) {
if (len <= bt_gatt_get_mtu(conn))
slen = len;
} else {
else {
slen = bt_gatt_get_mtu(conn);
}

View File

@ -9,14 +9,29 @@
#include "ef_def.h"
#endif
#include "conn_internal.h"
#if !defined(CONFIG_BL_MCU_SDK)
#include "hal_boot2.h"
#include "bl_flash.h"
#include "bl_sys.h"
#else
#include "partition.h"
#include "hal_flash.h"
#include "errno.h"
#include "bl702_glb.h"
#endif
#include "log.h"
#include "bl702.h"
#include "softcrc.h"
#if defined(CONFIG_BL_MCU_SDK)
#define BL_SDK_VER "1.00"
#define BOOT2_PARTITION_ADDR (0x4202DC00)
#endif //CONFIG_BL_MCU_SDK
#define OTA_WRITE_FLASH_SIZE (256 * 16)
#define WBUF_SIZE(CON) (OTA_WRITE_FLASH_SIZE + bt_gatt_get_mtu(CON))
#define UPGRD_TIMEOUT K_SECONDS(2)
uint32_t calc_crc32_val = 0;
static app_check_oad_cb app_check_cb = NULL;
struct oad_env_tag oad_env;
@ -28,11 +43,15 @@ struct wflash_data_t {
static struct wflash_data_t wData;
#if defined(CONFIG_BL_MCU_SDK)
static int hal_boot2_partition_addr_inactive(const char *name, uint32_t *addr, uint32_t *size);
static int hal_boot2_get_active_entries_byname(u8_t *name, pt_table_entry_config *ptEntry_hal);
static int hal_boot2_update_ptable(pt_table_entry_config *ptEntry_hal);
#endif
static bool check_data_valid(struct oad_file_info *file_info)
{
if (file_info->manu_code != oad_env.file_info.manu_code || file_info->file_ver != oad_env.upgrd_file_ver) {
if (file_info->manu_code != oad_env.file_info.manu_code || file_info->file_ver != oad_env.upgrd_file_ver)
return false;
}
return true;
}
@ -51,9 +70,7 @@ static void oad_notify_image_info(struct bt_conn *conn)
BT_WARN("Buffer allocation failed\r\n");
return;
}
buf[index++] = OAD_CMD_IMAG_INFO;
if (strlen(build_date) + index <= 256) {
buf[index] = strlen(build_date);
memcpy(&buf[++index], build_date, strlen(build_date));
@ -61,7 +78,6 @@ static void oad_notify_image_info(struct bt_conn *conn)
} else {
BT_WARN("No enough space\r\n");
}
if (strlen(build_time) + index <= 256) {
buf[index] = strlen(build_time);
memcpy(&buf[++index], build_time, strlen(build_time));
@ -77,7 +93,6 @@ static void oad_notify_image_info(struct bt_conn *conn)
} else {
BT_WARN("No enough space\r\n");
}
BT_WARN("Info:%s,%s,%s\r\n", build_date, build_time, build_ver);
BT_WARN("Send:%s\r\n", bt_hex(buf, index));
bt_oad_notify(conn, buf, index);
@ -101,14 +116,24 @@ static void oad_notify_block_req(struct bt_conn *conn)
bt_oad_notify(conn, buf->data, buf->len);
}
static uint32_t oad_bswap32(uint32_t val32)
{
return (val32 << 24) | ((val32 << 8) & 0xFF0000) | ((val32 >> 8) & 0xFF00) | ((val32 >> 24) & 0xFF);
}
static void oad_notify_upgrd_end(struct bt_conn *conn, u8_t status)
{
struct net_buf_simple *buf = NET_BUF_SIMPLE(sizeof(struct oad_upgrd_end_t) + OAD_OPCODE_SIZE);
struct oad_upgrd_end_t *upgrd_end;
uint32_t recv_crc_bigend = 0;
if (status == OAD_SUCC) {
recv_crc_bigend = oad_bswap32(oad_env.upgrd_crc32);
if (calc_crc32_val == recv_crc_bigend) {
BT_WARN("Submit upgrade work\r\n");
k_delayed_work_submit(&oad_env.upgrd_work, UPGRD_TIMEOUT);
} else {
BT_WARN("crc check failed, received crc=0x%x, calculted crc=0x%x, recv_crc_bigend=0x%x\r\n", oad_env.upgrd_crc32, calc_crc32_val, recv_crc_bigend);
}
}
net_buf_simple_init(buf, 0);
@ -143,7 +168,11 @@ static void oad_notity_image_identity(struct bt_conn *conn)
void oad_upgrade(struct k_work *work)
{
int ret = 0;
#if !defined(CONFIG_BL_MCU_SDK)
HALPartition_Entry_Config ptEntry;
#else
pt_table_entry_config ptEntry;
#endif
BT_WARN("oad_upgrade\r\n");
oad_env.file_info.file_ver = oad_env.upgrd_file_ver;
@ -156,7 +185,6 @@ void oad_upgrade(struct k_work *work)
#endif
ret = hal_boot2_get_active_entries_byname((uint8_t *)"FW", &ptEntry);
if (ret) {
BT_WARN("Failed to get active entries by name\r\n");
return;
@ -164,7 +192,12 @@ void oad_upgrade(struct k_work *work)
ptEntry.len = oad_env.upgrd_file_size;
hal_boot2_update_ptable(&ptEntry);
#if !defined(CONFIG_BL_MCU_SDK)
bl_sys_reset_system();
#else
GLB_SW_System_Reset();
#endif
}
static u8_t oad_write_flash(u8_t *data, u16_t len)
@ -179,9 +212,13 @@ static u8_t oad_write_flash(u8_t *data, u16_t len)
}
BT_WARN("Upgrade file size is %d\r\n", oad_env.upgrd_file_size);
if (oad_env.upgrd_file_size <= size) {
#if !defined(CONFIG_BL_MCU_SDK)
bl_flash_erase(oad_env.new_img_addr, oad_env.upgrd_file_size);
#else
BT_WARN("flash erase\r\n");
flash_erase(oad_env.new_img_addr, oad_env.upgrd_file_size);
#endif
} else {
return -1;
}
@ -198,45 +235,57 @@ static u8_t oad_write_flash(u8_t *data, u16_t len)
}
BT_WARN("Start address : 0x%x\r\n", wflash_address);
#if !defined(CONFIG_BL_MCU_SDK)
bl_flash_write(wflash_address, data, len);
#else
flash_write(wflash_address, data, len);
#endif
oad_env.w_img_end_addr = wflash_address + len;
BT_WARN("End address : 0x%x\r\n", wflash_address + len);
calc_crc32_val = BFLB_Soft_CRC32_Ex(calc_crc32_val, data, len);
return 0;
}
static u8_t oad_image_data_handler(struct bt_conn *conn, const u8_t *data, u16_t len)
{
u16_t left_size = 0;
u16_t wlen = 0;
u16_t oDataLen = 0;
#if defined(CONFIG_BT_SETTINGS)
static u32_t write_count = 0;
#endif
if (!wData.wdata_buf) {
wData.wdata_buf = (u8_t *)k_malloc(WBUF_SIZE(conn));
if (!wData.wdata_buf) {
BT_WARN("Buf is NULL\r\n");
return OAD_ABORT;
};
memset(wData.wdata_buf, 0, WBUF_SIZE(conn));
wData.index = 0;
}
if (wData.wdata_buf) {
left_size = WBUF_SIZE(conn) - wData.index;
left_size = /*WBUF_SIZE(conn)*/ OTA_WRITE_FLASH_SIZE - wData.index;
BT_WARN("left_size (0x%x) wData.index (0x%x) len (%d)\r\n", left_size, wData.index, len);
if (left_size >= len) {
memcpy((wData.wdata_buf + wData.index), data, len);
wData.index += len;
if (wData.index >= OTA_WRITE_FLASH_SIZE && wData.index <= WBUF_SIZE(conn)) {
wlen = wData.index - OTA_WRITE_FLASH_SIZE;
oad_write_flash(wData.wdata_buf, OTA_WRITE_FLASH_SIZE);
} else {
oDataLen = len - left_size;
memcpy((wData.wdata_buf + wData.index), data, left_size);
wData.index += left_size;
if (wData.index == OTA_WRITE_FLASH_SIZE) {
if (oad_write_flash(wData.wdata_buf, OTA_WRITE_FLASH_SIZE)) {
BT_ERR("Failed to write flash\r\n");
return OAD_ABORT;
}
} else {
BT_ERR("Unexpect result\r\n");
return OAD_ABORT;
}
#if defined(CONFIG_BT_SETTINGS)
write_count += 1;
struct oad_ef_info ef_info;
@ -250,23 +299,17 @@ static u8_t oad_image_data_handler(struct bt_conn *conn, const u8_t *data, u16_t
ef_info.file_offset, ef_info.last_wflash_addr);
#endif
wData.index = 0;
memcpy((wData.wdata_buf + wData.index), (wData.wdata_buf + OTA_WRITE_FLASH_SIZE), wlen);
wData.index += wlen;
}
} else {
BT_WARN("No space for store data\r\n");
memcpy((wData.wdata_buf + wData.index), (data + left_size), oDataLen);
wData.index += oDataLen;
}
}
oad_env.upgrd_offset += len;
if (oad_env.upgrd_offset > oad_env.upgrd_file_size) {
return OAD_INVALID_IMAG;
} else if (oad_env.upgrd_offset == oad_env.upgrd_file_size) {
if (wData.index) {
if (wData.index)
oad_write_flash(wData.wdata_buf, wData.index);
}
if (wData.wdata_buf) {
k_free(wData.wdata_buf);
@ -293,7 +336,6 @@ static u8_t oad_image_block_resp_handler(struct bt_conn *conn, const u8_t *data,
switch (*data) {
case OAD_SUCC: {
block_rsp = (struct oad_block_rsp_t *)data;
if (!check_data_valid(&block_rsp->file_info)) {
status = OAD_INVALID_IMAG;
break;
@ -306,7 +348,6 @@ static u8_t oad_image_block_resp_handler(struct bt_conn *conn, const u8_t *data,
rsp_data = data + OAD_BLK_RSP_DATA_OFFSET;
status = oad_image_data_handler(conn, rsp_data, block_rsp->data_size);
if (status == OAD_UPGRD_CMPLT) {
oad_notify_upgrd_end(conn, OAD_SUCC);
} else if (status == OAD_REQ_MORE_DATA) {
@ -315,21 +356,25 @@ static u8_t oad_image_block_resp_handler(struct bt_conn *conn, const u8_t *data,
oad_notify_upgrd_end(conn, status);
}
} break;
case OAD_ABORT: {
#if !defined(CONFIG_BL_MCU_SDK)
bl_flash_erase(oad_env.new_img_addr, oad_env.upgrd_file_size);
#else
flash_erase(oad_env.new_img_addr, oad_env.upgrd_file_size);
#endif
} break;
default:
status = OAD_MALORMED_CMD;
}
return status;
}
static void oad_image_identity_handler(struct bt_conn *conn, const u8_t *data, u16_t len)
{
struct bt_le_conn_param conn_param;
struct oad_image_identity_t *identity = (struct oad_image_identity_t *)(data);
int err = 0;
BT_WARN("File size=[0x%x] [0x%x] [0x%x] [0x%x]\r\n", identity->file_size, identity->file_info.file_ver,
identity->file_info.manu_code, identity->crc32);
@ -341,12 +386,14 @@ static void oad_image_identity_handler(struct bt_conn *conn, const u8_t *data, u
bt_settings_get_bin(NV_IMG_info, (uint8_t *)&ef_info, sizeof(struct oad_ef_info), &llen);
BT_WARN("ef_info: file ver(%d) manu code(0x%x) file offset(0x%x) last_adder (0x%x)\r\n", ef_info.file_info.file_ver, ef_info.file_info.manu_code,
ef_info.file_offset, ef_info.last_wflash_addr);
#else
oad_env.new_img_addr = 0;
oad_env.w_img_end_addr = 0;
#endif
if (identity->file_info.manu_code == oad_env.file_info.manu_code &&
(app_check_cb)(oad_env.file_info.file_ver, identity->file_info.file_ver)) {
#if defined(CONFIG_BT_SETTINGS)
if (identity->crc32 && ef_info.upgrd_crc32 == identity->crc32) {
if (ef_info.file_offset && ef_info.file_offset <= identity->file_size) {
oad_env.upgrd_offset = ef_info.file_offset;
@ -360,6 +407,16 @@ static void oad_image_identity_handler(struct bt_conn *conn, const u8_t *data, u
oad_env.upgrd_offset = 0x00;
}
conn_param.interval_max = 6;
conn_param.interval_min = 6;
conn_param.latency = 0;
conn_param.timeout = 500; //5s
err = bt_conn_le_param_update(conn, &conn_param);
if (err)
BT_WARN("fail to start conn update\r\n");
else
BT_WARN("start conn update\r\n");
oad_env.upgrd_file_ver = identity->file_info.file_ver;
oad_env.upgrd_file_size = identity->file_size;
oad_env.upgrd_crc32 = identity->crc32;
@ -376,11 +433,9 @@ static void oad_recv_callback(struct bt_conn *conn, const u8_t *data, u16_t len)
if (*data == OAD_CMD_IMAG_IDENTITY && ((len - 1) == sizeof(struct oad_image_identity_t))) {
oad_image_identity_handler(conn, data + 1, len - 1);
}
if (*data == OAD_CMD_IMAG_BLOCK_RESP) {
oad_image_block_resp_handler(conn, data + 1, len - 1);
}
if (*data == OAD_CMD_IMAG_INFO) {
oad_image_info_handler(conn, data + 1, len - 1);
}
@ -395,7 +450,108 @@ static void oad_disc_callback(struct bt_conn *conn, u8_t reason)
wData.index = 0;
}
}
#if defined(CONFIG_BL_MCU_SDK)
static struct {
u8_t partition_active_idx;
u8_t pad[3];
pt_table_stuff_config table;
} boot2_partition_table;
//#define PARTITION_MAGIC (0x54504642)
pt_table_id_type active_id = PT_TABLE_ID_INVALID;
pt_table_stuff_config pt_table_stuff[2];
static int oad_hal_boot2_partition_addr(const char *name, uint32_t *addr0, uint32_t *addr1, uint32_t *size0, uint32_t *size1, int *active)
{
int i;
if (BFLB_PT_MAGIC_CODE != boot2_partition_table.table.pt_table.magicCode) {
return -EIO;
}
/*Get Target partition*/
for (i = 0; i < boot2_partition_table.table.pt_table.entryCnt; i++) {
if (0 == strcmp((char *)&(boot2_partition_table.table.pt_entries[i].name[0]), name)) {
break;
}
}
if (boot2_partition_table.table.pt_table.entryCnt == i) {
return -ENOENT;
}
*addr0 = boot2_partition_table.table.pt_entries[i].start_address[0];
*addr1 = boot2_partition_table.table.pt_entries[i].start_address[1];
*size0 = boot2_partition_table.table.pt_entries[i].max_len[0];
*size1 = boot2_partition_table.table.pt_entries[i].max_len[1];
*active = boot2_partition_table.table.pt_entries[i].active_index;
return 0;
}
static int hal_boot2_partition_addr_inactive(const char *name, uint32_t *addr, uint32_t *size)
{
uint32_t addr0, addr1;
uint32_t size0, size1;
int active, ret;
if ((ret = oad_hal_boot2_partition_addr(name, &addr0, &addr1, &size0, &size1, &active))) {
return ret;
}
*addr = active ? addr0 : addr1;
*size = active ? size0 : size1;
return 0;
}
static pt_table_error_type oad_PtTable_Get_Active_Entries_By_Name(pt_table_stuff_config *ptStuff,
u8_t *name,
pt_table_entry_config *ptEntry)
{
uint32_t i = 0;
uint32_t len = strlen((char *)name);
if (ptStuff == NULL || ptEntry == NULL) {
return PT_ERROR_PARAMETER;
}
for (i = 0; i < ptStuff->pt_table.entryCnt; i++) {
if (strlen((char *)ptStuff->pt_entries[i].name) == len &&
memcmp((char *)ptStuff->pt_entries[i].name, (char *)name, len) == 0) {
ARCH_MemCpy_Fast(ptEntry, &ptStuff->pt_entries[i], sizeof(pt_table_entry_config));
return PT_ERROR_SUCCESS;
}
}
return PT_ERROR_ENTRY_NOT_FOUND;
}
static int hal_boot2_update_ptable(pt_table_entry_config *ptEntry_hal)
{
int ret;
//FIXME force covert
pt_table_entry_config *ptEntry = (pt_table_entry_config *)ptEntry_hal;
ptEntry->active_index = !ptEntry->active_index;
(ptEntry->age)++;
ret = pt_table_update_entry((pt_table_id_type)(!active_id), &pt_table_stuff[!active_id], ptEntry);
return ret;
}
static int hal_boot2_get_active_entries_byname(uint8_t *name, pt_table_entry_config *ptEntry_hal)
{
pt_table_entry_config *ptEntry = (pt_table_entry_config *)ptEntry_hal;
if (oad_PtTable_Get_Active_Entries_By_Name(&boot2_partition_table.table, name, ptEntry)) {
return -1;
}
return 0;
}
static int oad_get_boot2_partition_table(void)
{
memcpy(&boot2_partition_table.table, &pt_table_stuff[active_id], sizeof(pt_table_stuff_config));
boot2_partition_table.partition_active_idx = active_id;
BT_WARN("magicCode: 0x%x\r\n", boot2_partition_table.table.pt_table.magicCode);
return 0;
}
#endif
void oad_service_enable(app_check_oad_cb cb)
{
//todo: get current file info for oad_env.fileinfo
@ -408,5 +564,11 @@ void oad_service_enable(app_check_oad_cb cb)
bt_oad_register_recv_cb(oad_recv_callback);
bt_oad_register_disc_cb(oad_disc_callback);
#if defined(CONFIG_BL_MCU_SDK)
flash_init();
pt_table_set_flash_operation(flash_erase, flash_write, flash_read);
active_id = pt_table_get_active_partition_need_lock(pt_table_stuff);
oad_get_boot2_partition_table();
#endif
k_delayed_work_init(&oad_env.upgrd_work, oad_upgrade);
}

View File

@ -1,6 +1,8 @@
#include "byteorder.h"
#include "oad_service.h"
#include "oad.h"
#include "log.h"
#include "hci_core.h"
oad_upper_recv_cb upper_recv_cb;
oad_disc_cb disc_cb;
@ -13,11 +15,44 @@ static struct bt_conn_cb ble_oad_conn_callbacks = {
.connected = ble_oad_connected,
.disconnected = ble_oad_disconnected,
};
static void ble_oad_tx_mtu_size(struct bt_conn *conn, u8_t err,
struct bt_gatt_exchange_params *params)
{
if (!err) {
BT_WARN("ble oad echange mtu size success, mtu size: %d\n", bt_gatt_get_mtu(ble_oad_conn));
} else {
BT_WARN("ble oad echange mtu size failure, err: %d\n", err);
}
}
static void ble_oad_connected(struct bt_conn *conn, u8_t err)
{
int ret = -1;
int tx_octets = 0x00fb;
int tx_time = 0x0848;
if (!ble_oad_conn) {
ble_oad_conn = conn;
}
//set data length after connected.
ret = bt_le_set_data_len(ble_oad_conn, tx_octets, tx_time);
if (!ret) {
BT_WARN("ble oad set data length success.\n");
} else {
BT_WARN("ble oad set data length failure, err: %d\n", ret);
}
//exchange mtu size after connected.
struct bt_gatt_exchange_params *exchg_mtu = k_malloc(sizeof(struct bt_gatt_exchange_params));
exchg_mtu->func = ble_oad_tx_mtu_size;
ret = bt_gatt_exchange_mtu(ble_oad_conn, exchg_mtu);
if (!ret) {
BT_WARN("ble oad exchange mtu size pending.\n");
} else {
BT_WARN("ble oad exchange mtu size failure, err: %d\n", ret);
}
}
static void ble_oad_disconnected(struct bt_conn *conn, u8_t reason)

View File

@ -11,10 +11,15 @@ void ble_controller_reset(void);
#endif
char *ble_controller_get_lib_ver(void);
// if 0, success.
// if -1, fail,
int8_t ble_controller_set_scan_filter_table_size(uint8_t size);
// return sleep duration, in unit of 1/32768s
// if 0, means not allow sleep
// if -1, means allow sleep, but there is no end of sleep interrupt (ble core deep sleep is not enabled)
int32_t ble_controller_sleep(void);
void ble_controller_sleep_restore(void);
bool ble_controller_sleep_is_ongoing(void);
void ble_controller_set_tx_pwr(int ble_tx_power);

View File

@ -10,15 +10,13 @@ enum {
BT_HCI_EVT
};
typedef struct
{
typedef struct {
uint16_t opcode;
uint8_t *params;
uint8_t param_len;
} bl_hci_cmd_struct;
typedef struct
{
typedef struct {
/// connection handle
uint16_t conhdl;
/// broadcast and packet boundary flag
@ -28,21 +26,17 @@ typedef struct
uint8_t *buffer;
} bl_hci_acl_data_tx;
typedef struct
{
typedef struct {
union {
bl_hci_cmd_struct hci_cmd;
bl_hci_acl_data_tx acl_data;
} p;
} hci_pkt_struct;
#if defined(OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER)
typedef void (*bt_hci_recv_cb)(uint8_t pkt_type, uint16_t src_id, uint8_t *param, uint8_t param_len, void *rx_buf);
uint8_t bt_onchiphci_hanlde_rx_acl(void *param, uint8_t *host_buf_data);
#else
typedef void (*bt_hci_recv_cb)(uint8_t pkt_type, uint16_t src_id, uint8_t *param, uint8_t param_len);
#endif
uint8_t bt_onchiphci_interface_init(bt_hci_recv_cb cb);
int bt_onchiphci_send(uint8_t pkt_type, uint16_t dest_id, hci_pkt_struct *pkt);
int8_t bt_onchiphci_send(uint8_t pkt_type, uint16_t dest_id, hci_pkt_struct *pkt);
uint8_t bt_onchiphci_hanlde_rx_acl(void *param, uint8_t *host_buf_data);
#endif

Some files were not shown because too many files have changed in this diff Show More