http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/host_hci_cmd.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c deleted file mode 100644 index cce2e26..0000000 --- a/net/nimble/host/src/host_hci_cmd.c +++ /dev/null @@ -1,1364 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -#include <stdint.h> -#include <assert.h> -#include <string.h> -#include <errno.h> -#include <stdio.h> -#include "os/os.h" -#include "console/console.h" -#include "nimble/hci_common.h" -#include "nimble/ble_hci_trans.h" -#include "host/host_hci.h" -#include "host_dbg_priv.h" -#include "ble_hs_priv.h" - -static int -host_hci_cmd_transport(uint8_t *cmdbuf) -{ - int rc; - - rc = ble_hci_trans_hs_cmd_tx(cmdbuf); - switch (rc) { - case 0: - return 0; - - case BLE_ERR_MEM_CAPACITY: - return BLE_HS_ENOMEM_EVT; - - default: - return BLE_HS_EUNKNOWN; - } -} - -void -host_hci_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf) -{ - uint16_t opcode; - uint8_t *u8ptr; - - u8ptr = buf; - - opcode = (ogf << 10) | ocf; - htole16(u8ptr, opcode); - u8ptr[2] = len; -} - -int -host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, const void *cmddata) -{ - uint8_t *buf; - int rc; - - buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD); - BLE_HS_DBG_ASSERT(buf != NULL); - - htole16(buf, ogf << 10 | ocf); - buf[2] = len; - if (len != 0) { - memcpy(buf + BLE_HCI_CMD_HDR_LEN, cmddata, len); - } - - BLE_HS_LOG(DEBUG, "host_hci_cmd_send: ogf=0x%02x ocf=0x%02x len=%d\n", - ogf, ocf, len); - ble_hs_log_flat_buf(buf, len + BLE_HCI_CMD_HDR_LEN); - BLE_HS_LOG(DEBUG, "\n"); - rc = host_hci_cmd_transport(buf); - - if (rc == 0) { - STATS_INC(ble_hs_stats, hci_cmd); - } else { - BLE_HS_LOG(DEBUG, "host_hci_cmd_send failure; rc=%d\n", rc); - } - - return rc; -} - -int -host_hci_cmd_send_buf(void *buf) -{ - uint16_t opcode; - uint8_t *u8ptr; - uint8_t len; - int rc; - - switch (ble_hs_sync_state) { - case BLE_HS_SYNC_STATE_BAD: - return BLE_HS_ENOTSYNCED; - - case BLE_HS_SYNC_STATE_BRINGUP: - if (!ble_hs_is_parent_task()) { - return BLE_HS_ENOTSYNCED; - } - break; - - case BLE_HS_SYNC_STATE_GOOD: - break; - - default: - BLE_HS_DBG_ASSERT(0); - return BLE_HS_EUNKNOWN; - } - - u8ptr = buf; - - opcode = le16toh(u8ptr + 0); - len = u8ptr[2]; - - rc = host_hci_cmd_send(BLE_HCI_OGF(opcode), BLE_HCI_OCF(opcode), len, - u8ptr + BLE_HCI_CMD_HDR_LEN); - return rc; -} - - -/** - * Send a LE command from the host to the controller. - * - * @param ocf - * @param len - * @param cmddata - * - * @return int - */ -static int -host_hci_le_cmd_send(uint16_t ocf, uint8_t len, void *cmddata) -{ - int rc; - rc = host_hci_cmd_send(BLE_HCI_OGF_LE, ocf, len, cmddata); - return rc; -} - -/** - * Read BD_ADDR - * - * OGF = 0x04 (Informational parameters) - * OCF = 0x0009 - */ -void -host_hci_cmd_build_read_bd_addr(uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_BD_ADDR, - 0, dst); -} - -static int -host_hci_cmd_body_le_whitelist_chg(const uint8_t *addr, uint8_t addr_type, - uint8_t *dst) -{ - if (addr_type > BLE_ADDR_TYPE_RANDOM) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - dst[0] = addr_type; - memcpy(dst + 1, addr, BLE_DEV_ADDR_LEN); - - return 0; -} - -static int -host_hci_cmd_body_le_set_adv_params(const struct hci_adv_params *adv, - uint8_t *dst) -{ - uint16_t itvl; - - BLE_HS_DBG_ASSERT(adv != NULL); - - /* Make sure parameters are valid */ - if ((adv->adv_itvl_min > adv->adv_itvl_max) || - (adv->own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) || - (adv->peer_addr_type > BLE_HCI_ADV_PEER_ADDR_MAX) || - (adv->adv_filter_policy > BLE_HCI_ADV_FILT_MAX) || - (adv->adv_type > BLE_HCI_ADV_TYPE_MAX) || - (adv->adv_channel_map == 0) || - ((adv->adv_channel_map & 0xF8) != 0)) { - /* These parameters are not valid */ - return -1; - } - - /* Make sure interval is valid for advertising type. */ - if ((adv->adv_type == BLE_HCI_ADV_TYPE_ADV_NONCONN_IND) || - (adv->adv_type == BLE_HCI_ADV_TYPE_ADV_SCAN_IND)) { - itvl = BLE_HCI_ADV_ITVL_NONCONN_MIN; - } else { - itvl = BLE_HCI_ADV_ITVL_MIN; - } - - /* Do not check if high duty-cycle directed */ - if (adv->adv_type != BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD) { - if ((adv->adv_itvl_min < itvl) || - (adv->adv_itvl_min > BLE_HCI_ADV_ITVL_MAX)) { - return -1; - } - } - - htole16(dst, adv->adv_itvl_min); - htole16(dst + 2, adv->adv_itvl_max); - dst[4] = adv->adv_type; - dst[5] = adv->own_addr_type; - dst[6] = adv->peer_addr_type; - memcpy(dst + 7, adv->peer_addr, BLE_DEV_ADDR_LEN); - dst[13] = adv->adv_channel_map; - dst[14] = adv->adv_filter_policy; - - return 0; -} - -int -host_hci_cmd_build_le_set_adv_params(const struct hci_adv_params *adv, - uint8_t *dst, int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_PARAM_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_PARAMS, - BLE_HCI_SET_ADV_PARAM_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - rc = host_hci_cmd_body_le_set_adv_params(adv, dst); - if (rc != 0) { - return rc; - } - - return 0; -} - -/** - * Set advertising data - * - * OGF = 0x08 (LE) - * OCF = 0x0008 - * - * @param data - * @param len - * @param dst - * - * @return int - */ -static int -host_hci_cmd_body_le_set_adv_data(const uint8_t *data, uint8_t len, - uint8_t *dst) -{ - /* Check for valid parameters */ - if (((data == NULL) && (len != 0)) || (len > BLE_HCI_MAX_ADV_DATA_LEN)) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - memset(dst, 0, BLE_HCI_SET_ADV_DATA_LEN); - dst[0] = len; - memcpy(dst + 1, data, len); - - return 0; -} - -/** - * Set advertising data - * - * OGF = 0x08 (LE) - * OCF = 0x0008 - * - * @param data - * @param len - * @param dst - * - * @return int - */ -int -host_hci_cmd_build_le_set_adv_data(const uint8_t *data, uint8_t len, - uint8_t *dst, int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_DATA_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_DATA, - BLE_HCI_SET_ADV_DATA_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - rc = host_hci_cmd_body_le_set_adv_data(data, len, dst); - if (rc != 0) { - return rc; - } - - return 0; -} - -static int -host_hci_cmd_body_le_set_scan_rsp_data(const uint8_t *data, uint8_t len, - uint8_t *dst) -{ - /* Check for valid parameters */ - if (((data == NULL) && (len != 0)) || - (len > BLE_HCI_MAX_SCAN_RSP_DATA_LEN)) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - memset(dst, 0, BLE_HCI_SET_SCAN_RSP_DATA_LEN); - dst[0] = len; - memcpy(dst + 1, data, len); - - return 0; -} - -int -host_hci_cmd_build_le_set_scan_rsp_data(const uint8_t *data, uint8_t len, - uint8_t *dst, int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_RSP_DATA_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA, - BLE_HCI_SET_SCAN_RSP_DATA_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - rc = host_hci_cmd_body_le_set_scan_rsp_data(data, len, dst); - if (rc != 0) { - return rc; - } - - return 0; -} - -static void -host_hci_cmd_body_set_event_mask(uint64_t event_mask, uint8_t *dst) -{ - htole64(dst, event_mask); -} - -void -host_hci_cmd_build_set_event_mask(uint64_t event_mask, - uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND, - BLE_HCI_OCF_CB_SET_EVENT_MASK, - BLE_HCI_SET_EVENT_MASK_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_set_event_mask(event_mask, dst); -} - -void -host_hci_cmd_build_set_event_mask2(uint64_t event_mask, - uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND, - BLE_HCI_OCF_CB_SET_EVENT_MASK2, - BLE_HCI_SET_EVENT_MASK_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_set_event_mask(event_mask, dst); -} - -static void -host_hci_cmd_body_disconnect(uint16_t handle, uint8_t reason, uint8_t *dst) -{ - htole16(dst + 0, handle); - dst[2] = reason; -} - -void -host_hci_cmd_build_disconnect(uint16_t handle, uint8_t reason, - uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_DISCONNECT_CMD_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_DISCONNECT_CMD, - BLE_HCI_DISCONNECT_CMD_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_disconnect(handle, reason, dst); -} - -int -host_hci_cmd_disconnect(uint16_t handle, uint8_t reason) -{ - uint8_t cmd[BLE_HCI_DISCONNECT_CMD_LEN]; - int rc; - - host_hci_cmd_body_disconnect(handle, reason, cmd); - rc = host_hci_cmd_send(BLE_HCI_OGF_LINK_CTRL, - BLE_HCI_OCF_DISCONNECT_CMD, - BLE_HCI_DISCONNECT_CMD_LEN, - cmd); - return rc; -} - -static void -host_hci_cmd_body_le_set_event_mask(uint64_t event_mask, uint8_t *dst) -{ - htole64(dst, event_mask); -} - -void -host_hci_cmd_build_le_set_event_mask(uint64_t event_mask, - uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_LE_EVENT_MASK_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_SET_EVENT_MASK, - BLE_HCI_SET_LE_EVENT_MASK_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_le_set_event_mask(event_mask, dst); -} - -/** - * LE Read buffer size - * - * OGF = 0x08 (LE) - * OCF = 0x0002 - * - * @return int - */ -void -host_hci_cmd_build_le_read_buffer_size(uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_BUF_SIZE, 0, dst); -} - -/** - * LE Read buffer size - * - * OGF = 0x08 (LE) - * OCF = 0x0002 - * - * @return int - */ -int -host_hci_cmd_le_read_buffer_size(void) -{ - int rc; - - rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_BUF_SIZE, 0, NULL); - return rc; -} - -/** - * OGF=LE, OCF=0x0003 - */ -void -host_hci_cmd_build_le_read_loc_supp_feat(uint8_t *dst, uint8_t dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT, - 0, dst); -} - -static void -host_hci_cmd_body_le_set_adv_enable(uint8_t enable, uint8_t *dst) -{ - dst[0] = enable; -} - -void -host_hci_cmd_build_le_set_adv_enable(uint8_t enable, uint8_t *dst, - int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_ENABLE_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_ENABLE, - BLE_HCI_SET_ADV_ENABLE_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_le_set_adv_enable(enable, dst); -} - -static int -host_hci_cmd_body_le_set_scan_params( - uint8_t scan_type, uint16_t scan_itvl, uint16_t scan_window, - uint8_t own_addr_type, uint8_t filter_policy, uint8_t *dst) { - - /* Make sure parameters are valid */ - if ((scan_type != BLE_HCI_SCAN_TYPE_PASSIVE) && - (scan_type != BLE_HCI_SCAN_TYPE_ACTIVE)) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check interval and window */ - if ((scan_itvl < BLE_HCI_SCAN_ITVL_MIN) || - (scan_itvl > BLE_HCI_SCAN_ITVL_MAX) || - (scan_window < BLE_HCI_SCAN_WINDOW_MIN) || - (scan_window > BLE_HCI_SCAN_WINDOW_MAX) || - (scan_itvl < scan_window)) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check own addr type */ - if (own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check scanner filter policy */ - if (filter_policy > BLE_HCI_SCAN_FILT_MAX) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - dst[0] = scan_type; - htole16(dst + 1, scan_itvl); - htole16(dst + 3, scan_window); - dst[5] = own_addr_type; - dst[6] = filter_policy; - - return 0; -} - -int -host_hci_cmd_build_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl, - uint16_t scan_window, - uint8_t own_addr_type, - uint8_t filter_policy, - uint8_t *dst, int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_PARAMS, - BLE_HCI_SET_SCAN_PARAM_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - rc = host_hci_cmd_body_le_set_scan_params(scan_type, scan_itvl, - scan_window, own_addr_type, - filter_policy, dst); - if (rc != 0) { - return rc; - } - - return 0; -} - -static void -host_hci_cmd_body_le_set_scan_enable(uint8_t enable, uint8_t filter_dups, - uint8_t *dst) -{ - dst[0] = enable; - dst[1] = filter_dups; -} - -void -host_hci_cmd_build_le_set_scan_enable(uint8_t enable, uint8_t filter_dups, - uint8_t *dst, uint8_t dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_ENABLE_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_ENABLE, - BLE_HCI_SET_SCAN_ENABLE_LEN, dst); - - host_hci_cmd_body_le_set_scan_enable(enable, filter_dups, - dst + BLE_HCI_CMD_HDR_LEN); -} - -static int -host_hci_cmd_body_le_create_connection(const struct hci_create_conn *hcc, - uint8_t *cmd) -{ - /* Check scan interval and scan window */ - if ((hcc->scan_itvl < BLE_HCI_SCAN_ITVL_MIN) || - (hcc->scan_itvl > BLE_HCI_SCAN_ITVL_MAX) || - (hcc->scan_window < BLE_HCI_SCAN_WINDOW_MIN) || - (hcc->scan_window > BLE_HCI_SCAN_WINDOW_MAX) || - (hcc->scan_itvl < hcc->scan_window)) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check initiator filter policy */ - if (hcc->filter_policy > BLE_HCI_CONN_FILT_MAX) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check peer addr type */ - if (hcc->peer_addr_type > BLE_HCI_CONN_PEER_ADDR_MAX) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check own addr type */ - if (hcc->own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check connection interval min */ - if ((hcc->conn_itvl_min < BLE_HCI_CONN_ITVL_MIN) || - (hcc->conn_itvl_min > BLE_HCI_CONN_ITVL_MAX)) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check connection interval max */ - if ((hcc->conn_itvl_max < BLE_HCI_CONN_ITVL_MIN) || - (hcc->conn_itvl_max > BLE_HCI_CONN_ITVL_MAX) || - (hcc->conn_itvl_max < hcc->conn_itvl_min)) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check connection latency */ - if ((hcc->conn_latency < BLE_HCI_CONN_LATENCY_MIN) || - (hcc->conn_latency > BLE_HCI_CONN_LATENCY_MAX)) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check supervision timeout */ - if ((hcc->supervision_timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN) || - (hcc->supervision_timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX)) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - /* Check connection event length */ - if (hcc->min_ce_len > hcc->max_ce_len) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - htole16(cmd + 0, hcc->scan_itvl); - htole16(cmd + 2, hcc->scan_window); - cmd[4] = hcc->filter_policy; - cmd[5] = hcc->peer_addr_type; - memcpy(cmd + 6, hcc->peer_addr, BLE_DEV_ADDR_LEN); - cmd[12] = hcc->own_addr_type; - htole16(cmd + 13, hcc->conn_itvl_min); - htole16(cmd + 15, hcc->conn_itvl_max); - htole16(cmd + 17, hcc->conn_latency); - htole16(cmd + 19, hcc->supervision_timeout); - htole16(cmd + 21, hcc->min_ce_len); - htole16(cmd + 23, hcc->max_ce_len); - - return 0; -} - -int -host_hci_cmd_build_le_create_connection(const struct hci_create_conn *hcc, - uint8_t *cmd, int cmd_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - cmd_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CREATE_CONN_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN, - BLE_HCI_CREATE_CONN_LEN, cmd); - - rc = host_hci_cmd_body_le_create_connection(hcc, - cmd + BLE_HCI_CMD_HDR_LEN); - if (rc != 0) { - return rc; - } - - return 0; -} - -void -host_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CLEAR_WHITE_LIST, - 0, dst); -} - -int -host_hci_cmd_build_le_add_to_whitelist(const uint8_t *addr, uint8_t addr_type, - uint8_t *dst, int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CHG_WHITE_LIST_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ADD_WHITE_LIST, - BLE_HCI_CHG_WHITE_LIST_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - rc = host_hci_cmd_body_le_whitelist_chg(addr, addr_type, dst); - if (rc != 0) { - return rc; - } - - return 0; -} - -void -host_hci_cmd_build_reset(uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - host_hci_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET, - 0, dst); -} - -/** - * Reset the controller and link manager. - * - * @return int - */ -int -host_hci_cmd_reset(void) -{ - int rc; - - rc = host_hci_cmd_send(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET, 0, - NULL); - return rc; -} - -void -host_hci_cmd_build_read_adv_pwr(uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR, - 0, dst); -} - -/** - * Read the transmit power level used for LE advertising channel packets. - * - * @return int - */ -int -host_hci_cmd_read_adv_pwr(void) -{ - int rc; - - rc = host_hci_cmd_send(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR, 0, - NULL); - return rc; -} - -void -host_hci_cmd_build_le_create_conn_cancel(uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN_CANCEL, - 0, dst); -} - -int -host_hci_cmd_le_create_conn_cancel(void) -{ - int rc; - - rc = host_hci_cmd_send(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN_CANCEL, - 0, NULL); - return rc; -} - -static int -host_hci_cmd_body_le_conn_update(const struct hci_conn_update *hcu, - uint8_t *dst) -{ - /* XXX: add parameter checking later */ - htole16(dst + 0, hcu->handle); - htole16(dst + 2, hcu->conn_itvl_min); - htole16(dst + 4, hcu->conn_itvl_max); - htole16(dst + 6, hcu->conn_latency); - htole16(dst + 8, hcu->supervision_timeout); - htole16(dst + 10, hcu->min_ce_len); - htole16(dst + 12, hcu->max_ce_len); - - return 0; -} - -int -host_hci_cmd_build_le_conn_update(const struct hci_conn_update *hcu, - uint8_t *dst, int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_UPDATE_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CONN_UPDATE, - BLE_HCI_CONN_UPDATE_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - rc = host_hci_cmd_body_le_conn_update(hcu, dst); - if (rc != 0) { - return rc; - } - - return 0; -} - -int -host_hci_cmd_le_conn_update(const struct hci_conn_update *hcu) -{ - uint8_t cmd[BLE_HCI_CONN_UPDATE_LEN]; - int rc; - - rc = host_hci_cmd_body_le_conn_update(hcu, cmd); - if (rc != 0) { - return rc; - } - - rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_CONN_UPDATE, - BLE_HCI_CONN_UPDATE_LEN, cmd); - if (rc != 0) { - return rc; - } - - return 0; -} - -static void -host_hci_cmd_body_le_lt_key_req_reply(const struct hci_lt_key_req_reply *hkr, - uint8_t *dst) -{ - htole16(dst + 0, hkr->conn_handle); - memcpy(dst + 2, hkr->long_term_key, sizeof hkr->long_term_key); -} - -/** - * Sends the long-term key (LTK) to the controller. - * - * Note: This function expects the 128-bit key to be in little-endian byte - * order. - * - * OGF = 0x08 (LE) - * OCF = 0x001a - * - * @param key - * @param pt - * - * @return int - */ -void -host_hci_cmd_build_le_lt_key_req_reply(const struct hci_lt_key_req_reply *hkr, - uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LT_KEY_REQ_REPLY_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY, - BLE_HCI_LT_KEY_REQ_REPLY_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_le_lt_key_req_reply(hkr, dst); -} - -void -host_hci_cmd_build_le_lt_key_req_neg_reply(uint16_t conn_handle, - uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LT_KEY_REQ_NEG_REPLY_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY, - BLE_HCI_LT_KEY_REQ_NEG_REPLY_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - htole16(dst + 0, conn_handle); -} - -static void -host_hci_cmd_body_le_conn_param_reply(const struct hci_conn_param_reply *hcr, - uint8_t *dst) -{ - htole16(dst + 0, hcr->handle); - htole16(dst + 2, hcr->conn_itvl_min); - htole16(dst + 4, hcr->conn_itvl_max); - htole16(dst + 6, hcr->conn_latency); - htole16(dst + 8, hcr->supervision_timeout); - htole16(dst + 10, hcr->min_ce_len); - htole16(dst + 12, hcr->max_ce_len); -} - -void -host_hci_cmd_build_le_conn_param_reply(const struct hci_conn_param_reply *hcr, - uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_PARAM_REPLY_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_RR, - BLE_HCI_CONN_PARAM_REPLY_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_le_conn_param_reply(hcr, dst); -} - -int -host_hci_cmd_le_conn_param_reply(const struct hci_conn_param_reply *hcr) -{ - uint8_t cmd[BLE_HCI_CONN_PARAM_REPLY_LEN]; - int rc; - - htole16(cmd + 0, hcr->handle); - htole16(cmd + 2, hcr->conn_itvl_min); - htole16(cmd + 4, hcr->conn_itvl_max); - htole16(cmd + 6, hcr->conn_latency); - htole16(cmd + 8, hcr->supervision_timeout); - htole16(cmd + 10, hcr->min_ce_len); - htole16(cmd + 12, hcr->max_ce_len); - - rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_REM_CONN_PARAM_RR, - BLE_HCI_CONN_PARAM_REPLY_LEN, cmd); - return rc; -} - -static void -host_hci_cmd_body_le_conn_param_neg_reply( - const struct hci_conn_param_neg_reply *hcn, uint8_t *dst) -{ - htole16(dst + 0, hcn->handle); - dst[2] = hcn->reason; -} - - -void -host_hci_cmd_build_le_conn_param_neg_reply( - const struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_PARAM_NEG_REPLY_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR, - BLE_HCI_CONN_PARAM_NEG_REPLY_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_le_conn_param_neg_reply(hcn, dst); -} - -int -host_hci_cmd_le_conn_param_neg_reply( - const struct hci_conn_param_neg_reply *hcn) -{ - uint8_t cmd[BLE_HCI_CONN_PARAM_NEG_REPLY_LEN]; - int rc; - - host_hci_cmd_body_le_conn_param_neg_reply(hcn, cmd); - - rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR, - BLE_HCI_CONN_PARAM_NEG_REPLY_LEN, cmd); - return rc; -} - -/** - * Get random data - * - * OGF = 0x08 (LE) - * OCF = 0x0018 - * - * @return int - */ -void -host_hci_cmd_build_le_rand(uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RAND, 0, dst); -} - -static void -host_hci_cmd_body_le_start_encrypt(const struct hci_start_encrypt *cmd, - uint8_t *dst) -{ - htole16(dst + 0, cmd->connection_handle); - htole64(dst + 2, cmd->random_number); - htole16(dst + 10, cmd->encrypted_diversifier); - memcpy(dst + 12, cmd->long_term_key, sizeof cmd->long_term_key); -} - -/* - * OGF=0x08 OCF=0x0019 - */ -void -host_hci_cmd_build_le_start_encrypt(const struct hci_start_encrypt *cmd, - uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LE_START_ENCRYPT_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT, - BLE_HCI_LE_START_ENCRYPT_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_le_start_encrypt(cmd, dst); -} - -/** - * Read the RSSI for a given connection handle - * - * NOTE: OGF=0x05 OCF=0x0005 - * - * @param handle - * - * @return int - */ -static void -host_hci_cmd_body_read_rssi(uint16_t handle, uint8_t *dst) -{ - htole16(dst, handle); -} - -void -host_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_READ_RSSI_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_STATUS_PARAMS, BLE_HCI_OCF_RD_RSSI, - BLE_HCI_READ_RSSI_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - host_hci_cmd_body_read_rssi(handle, dst); -} - -static int -host_hci_cmd_body_set_data_len(uint16_t connection_handle, uint16_t tx_octets, - uint16_t tx_time, uint8_t *dst) -{ - - if (tx_octets < BLE_HCI_SET_DATALEN_TX_OCTETS_MIN || - tx_octets > BLE_HCI_SET_DATALEN_TX_OCTETS_MAX) { - - return BLE_HS_EINVAL; - } - - if (tx_time < BLE_HCI_SET_DATALEN_TX_TIME_MIN || - tx_time > BLE_HCI_SET_DATALEN_TX_TIME_MAX) { - - return BLE_HS_EINVAL; - } - - htole16(dst + 0, connection_handle); - htole16(dst + 2, tx_octets); - htole16(dst + 4, tx_time); - - return 0; -} - -/* - * OGF=0x08 OCF=0x0022 - */ -int -host_hci_cmd_build_set_data_len(uint16_t connection_handle, - uint16_t tx_octets, uint16_t tx_time, - uint8_t *dst, int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_DATA_LEN, - BLE_HCI_SET_DATALEN_LEN, dst); - dst += BLE_HCI_CMD_HDR_LEN; - - rc = host_hci_cmd_body_set_data_len(connection_handle, tx_octets, tx_time, - dst); - if (rc != 0) { - return rc; - } - - return 0; -} - -/** - * IRKs are in little endian. - */ -static int -host_hci_cmd_body_add_to_resolv_list(uint8_t addr_type, const uint8_t *addr, - const uint8_t *peer_irk, - const uint8_t *local_irk, - uint8_t *dst) -{ - if (addr_type > BLE_ADDR_TYPE_RANDOM) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - dst[0] = addr_type; - memcpy(dst + 1, addr, BLE_DEV_ADDR_LEN); - memcpy(dst + 1 + 6, peer_irk , 16); - memcpy(dst + 1 + 6 + 16, local_irk , 16); - /* 16 + 16 + 6 + 1 == 39 */ - return 0; -} - -/** - * OGF=0x08 OCF=0x0027 - * - * IRKs are in little endian. - */ -int -host_hci_cmd_build_add_to_resolv_list( - const struct hci_add_dev_to_resolving_list *padd, - uint8_t *dst, - int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_ADD_TO_RESOLV_LIST_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ADD_RESOLV_LIST, - BLE_HCI_ADD_TO_RESOLV_LIST_LEN, dst); - - rc = host_hci_cmd_body_add_to_resolv_list( - padd->addr_type, padd->addr, padd->peer_irk, padd->local_irk, - dst + BLE_HCI_CMD_HDR_LEN); - if (rc != 0) { - return rc; - } - - return 0; -} - -static int -host_hci_cmd_body_remove_from_resolv_list(uint8_t addr_type, - const uint8_t *addr, - uint8_t *dst) -{ - if (addr_type > BLE_ADDR_TYPE_RANDOM) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - dst[0] = addr_type; - memcpy(dst + 1, addr, BLE_DEV_ADDR_LEN); - return 0; -} - - -int -host_hci_cmd_build_remove_from_resolv_list(uint8_t addr_type, - const uint8_t *addr, - uint8_t *dst, int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_RMV_FROM_RESOLV_LIST_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RMV_RESOLV_LIST, - BLE_HCI_RMV_FROM_RESOLV_LIST_LEN, dst); - - rc = host_hci_cmd_body_remove_from_resolv_list(addr_type, addr, - dst + BLE_HCI_CMD_HDR_LEN); - if (rc != 0) { - return rc; - } - return 0; -} - -int -host_hci_cmd_build_clear_resolv_list(uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CLR_RESOLV_LIST, - 0, dst); - - return 0; -} - -int -host_hci_cmd_build_read_resolv_list_size(uint8_t *dst, int dst_len) -{ - BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_RESOLV_LIST_SIZE, - 0, dst); - - return 0; -} - -static int -host_hci_cmd_body_read_peer_resolv_addr(uint8_t peer_identity_addr_type, - const uint8_t *peer_identity_addr, - uint8_t *dst) -{ - if (peer_identity_addr_type > BLE_ADDR_TYPE_RANDOM) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - dst[0] = peer_identity_addr_type; - memcpy(dst + 1, peer_identity_addr, BLE_DEV_ADDR_LEN); - return 0; -} - -int -host_hci_cmd_build_read_peer_resolv_addr(uint8_t peer_identity_addr_type, - const uint8_t *peer_identity_addr, - uint8_t *dst, - int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_RD_PEER_RESOLV_ADDR_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_PEER_RESOLV_ADDR, - BLE_HCI_RD_PEER_RESOLV_ADDR_LEN, dst); - - rc = host_hci_cmd_body_read_peer_resolv_addr(peer_identity_addr_type, - peer_identity_addr, - dst + BLE_HCI_CMD_HDR_LEN); - if (rc != 0) { - return rc; - } - return 0; -} - -static int -host_hci_cmd_body_read_lcl_resolv_addr( - uint8_t local_identity_addr_type, - const uint8_t *local_identity_addr, - uint8_t *dst) -{ - if (local_identity_addr_type > BLE_ADDR_TYPE_RANDOM) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - dst[0] = local_identity_addr_type; - memcpy(dst + 1, local_identity_addr, BLE_DEV_ADDR_LEN); - return 0; -} - -/* - * OGF=0x08 OCF=0x002c - */ -int -host_hci_cmd_build_read_lcl_resolv_addr(uint8_t local_identity_addr_type, - const uint8_t *local_identity_addr, - uint8_t *dst, - int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_RD_LOC_RESOLV_ADDR_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_LOCAL_RESOLV_ADDR, - BLE_HCI_RD_LOC_RESOLV_ADDR_LEN, dst); - - rc = host_hci_cmd_body_read_lcl_resolv_addr(local_identity_addr_type, - local_identity_addr, - dst + BLE_HCI_CMD_HDR_LEN); - if (rc != 0) { - return rc; - } - return 0; -} - -static int -host_hci_cmd_body_set_addr_res_en(uint8_t enable, uint8_t *dst) -{ - if (enable > 1) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - dst[0] = enable; - return 0; -} - -/* - * OGF=0x08 OCF=0x002d - */ -int -host_hci_cmd_build_set_addr_res_en(uint8_t enable, uint8_t *dst, int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADDR_RESOL_ENA_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADDR_RES_EN, - BLE_HCI_SET_ADDR_RESOL_ENA_LEN, dst); - - rc = host_hci_cmd_body_set_addr_res_en(enable, dst + BLE_HCI_CMD_HDR_LEN); - if (rc != 0) { - return rc; - } - return 0; -} - -static int -host_hci_cmd_body_set_resolv_priv_addr_timeout(uint16_t timeout, uint8_t *dst) -{ - if (timeout == 0 || timeout > 0xA1B8) { - return BLE_ERR_INV_HCI_CMD_PARMS; - } - - htole16(dst, timeout); - return 0; -} - -/* - * OGF=0x08 OCF=0x002e - */ -int -host_hci_cmd_build_set_resolv_priv_addr_timeout(uint16_t timeout, uint8_t *dst, - int dst_len) -{ - int rc; - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RESOLV_PRIV_ADDR_TO_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_RPA_TMO, - BLE_HCI_SET_RESOLV_PRIV_ADDR_TO_LEN, dst); - - rc = host_hci_cmd_body_set_resolv_priv_addr_timeout( - timeout, dst + BLE_HCI_CMD_HDR_LEN); - if (rc != 0) { - return rc; - } - return 0; -} - -static int -host_hci_cmd_body_set_random_addr(const struct hci_rand_addr *paddr, - uint8_t *dst) -{ - memcpy(dst, paddr->addr, BLE_DEV_ADDR_LEN); - return 0; -} - -int -host_hci_cmd_build_set_random_addr(const uint8_t *addr, - uint8_t *dst, int dst_len) -{ - struct hci_rand_addr r_addr; - int rc; - - memcpy(r_addr.addr, addr, sizeof(r_addr.addr)); - - BLE_HS_DBG_ASSERT( - dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RAND_ADDR_LEN); - - host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_RAND_ADDR, - BLE_HCI_SET_RAND_ADDR_LEN, dst); - - rc = host_hci_cmd_body_set_random_addr(&r_addr, dst + BLE_HCI_CMD_HDR_LEN); - if (rc != 0) { - return rc; - } - - return 0; -}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_att_clt_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_att_clt_test.c b/net/nimble/host/src/test/ble_att_clt_test.c index 9461337..ab89e9d 100644 --- a/net/nimble/host/src/test/ble_att_clt_test.c +++ b/net/nimble/host/src/test/ble_att_clt_test.c @@ -412,7 +412,8 @@ TEST_CASE(ble_att_clt_test_rx_read_mult) htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 0, 12); rc = ble_hs_test_util_l2cap_rx_payload_flat( - conn_handle, BLE_L2CAP_CID_ATT, buf, BLE_ATT_READ_MULT_RSP_BASE_SZ + 2); + conn_handle, BLE_L2CAP_CID_ATT, buf, + BLE_ATT_READ_MULT_RSP_BASE_SZ + 2); TEST_ASSERT(rc == 0); /*** Larger response. */ @@ -420,12 +421,14 @@ TEST_CASE(ble_att_clt_test_rx_read_mult) htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 2, 43); htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 4, 91); rc = ble_hs_test_util_l2cap_rx_payload_flat( - conn_handle, BLE_L2CAP_CID_ATT, buf, BLE_ATT_READ_MULT_RSP_BASE_SZ + 6); + conn_handle, BLE_L2CAP_CID_ATT, buf, + BLE_ATT_READ_MULT_RSP_BASE_SZ + 6); TEST_ASSERT(rc == 0); /*** Zero-length response. */ rc = ble_hs_test_util_l2cap_rx_payload_flat( - conn_handle, BLE_L2CAP_CID_ATT, buf, BLE_ATT_READ_MULT_RSP_BASE_SZ + 0); + conn_handle, BLE_L2CAP_CID_ATT, buf, + BLE_ATT_READ_MULT_RSP_BASE_SZ + 0); TEST_ASSERT(rc == 0); } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_gap_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c index 2ae3354..170b8d9 100644 --- a/net/nimble/host/src/test/ble_gap_test.c +++ b/net/nimble/host/src/test/ble_gap_test.c @@ -372,11 +372,11 @@ ble_gap_test_util_rx_param_req(struct ble_gap_upd_params *params, int pos, evt.timeout = params->supervision_timeout; if (pos) { - opcode = host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_REM_CONN_PARAM_RR); + opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_RR); } else { - opcode = host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR); + opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR); } if (*cmd_idx == cmd_fail_idx) { hci_status = fail_status; @@ -825,7 +825,8 @@ TEST_CASE(ble_gap_test_case_conn_dir_good) TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT); TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0); } @@ -1059,7 +1060,8 @@ TEST_CASE(ble_gap_test_case_conn_terminate_good) TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); TEST_ASSERT(ble_gap_test_conn_desc.peer_id_addr_type == BLE_ADDR_TYPE_PUBLIC); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_gap_test_conn_arg == NULL); TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == BLE_HS_ENOTCONN); @@ -1099,7 +1101,8 @@ TEST_CASE(ble_gap_test_case_conn_terminate_ctlr_fail) TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); TEST_ASSERT(ble_gap_test_conn_desc.peer_id_addr_type == BLE_ADDR_TYPE_PUBLIC); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_gap_test_conn_arg == NULL); TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0); @@ -1494,7 +1497,8 @@ TEST_CASE(ble_gap_test_case_adv_good) if (c != BLE_GAP_CONN_MODE_NON) { TEST_ASSERT(!ble_gap_adv_active()); - TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT); + TEST_ASSERT(ble_gap_test_conn_event_type == + BLE_GAP_EVENT_CONNECT); TEST_ASSERT(ble_gap_test_conn_status == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, @@ -1689,7 +1693,8 @@ ble_gap_test_util_update(struct ble_gap_upd_params *params, TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE); TEST_ASSERT(ble_gap_test_conn_status == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == params->itvl_max); TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == params->latency); TEST_ASSERT(ble_gap_test_conn_desc.supervision_timeout == @@ -1703,7 +1708,8 @@ fail: TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE); TEST_ASSERT(ble_gap_test_conn_status == status); TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == BLE_GAP_INITIAL_CONN_ITVL_MAX); TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == @@ -1789,7 +1795,8 @@ ble_gap_test_util_update_req_pos(struct ble_gap_upd_params *peer_params, TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE); TEST_ASSERT(ble_gap_test_conn_status == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == self_params->itvl_max); TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == self_params->latency); TEST_ASSERT(ble_gap_test_conn_desc.supervision_timeout == @@ -1801,7 +1808,8 @@ hci_fail: TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE); TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status)); TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == BLE_GAP_INITIAL_CONN_ITVL_MAX); TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == @@ -1850,7 +1858,8 @@ hci_fail: TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE); TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status)); TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == BLE_GAP_INITIAL_CONN_ITVL_MAX); TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == @@ -1925,7 +1934,8 @@ ble_gap_test_util_update_req_concurrent( TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE); TEST_ASSERT(ble_gap_test_conn_status == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == self_params->itvl_max); TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == self_params->latency); TEST_ASSERT(ble_gap_test_conn_desc.supervision_timeout == @@ -1937,7 +1947,8 @@ hci_fail: TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE); TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(fail_status)); TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2); - TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0); + TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, + peer_addr, 6) == 0); TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == BLE_GAP_INITIAL_CONN_ITVL_MAX); TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == @@ -2269,8 +2280,8 @@ ble_gap_test_util_conn_timeout(int32_t duration_ms) os_time_advance(duration_ms); ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_CREATE_CONN_CANCEL), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_CREATE_CONN_CANCEL), 0); TEST_ASSERT(ble_gap_test_conn_event_type == -1); @@ -2350,8 +2361,8 @@ ble_gap_test_util_disc_timeout(int32_t duration_ms) os_time_advance(duration_ms); ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_SET_SCAN_ENABLE), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_SET_SCAN_ENABLE), 0); ticks_from_now = ble_gap_heartbeat(); TEST_ASSERT(ticks_from_now == BLE_HS_FOREVER); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_gatt_read_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_gatt_read_test.c b/net/nimble/host/src/test/ble_gatt_read_test.c index 0c9f1cb..822de5c 100644 --- a/net/nimble/host/src/test/ble_gatt_read_test.c +++ b/net/nimble/host/src/test/ble_gatt_read_test.c @@ -495,21 +495,24 @@ ble_gatt_read_test_misc_mult_verify_bad( TEST_CASE(ble_gatt_read_test_by_handle) { /* Read a seven-byte attribute. */ - ble_gatt_read_test_misc_verify_good((struct ble_hs_test_util_flat_attr[]) { { + ble_gatt_read_test_misc_verify_good( + (struct ble_hs_test_util_flat_attr[]) { { .handle = 43, .value = { 1,2,3,4,5,6,7 }, .value_len = 7 } }); /* Read a one-byte attribute. */ - ble_gatt_read_test_misc_verify_good((struct ble_hs_test_util_flat_attr[]) { { + ble_gatt_read_test_misc_verify_good( + (struct ble_hs_test_util_flat_attr[]) { { .handle = 0x5432, .value = { 0xff }, .value_len = 1 } }); /* Read a 200-byte attribute. */ - ble_gatt_read_test_misc_verify_good((struct ble_hs_test_util_flat_attr[]) { { + ble_gatt_read_test_misc_verify_good( + (struct ble_hs_test_util_flat_attr[]) { { .handle = 815, .value = { 0 }, .value_len = 200, @@ -669,7 +672,8 @@ TEST_CASE(ble_gatt_read_test_mult) } /* Read one attribute. */ - ble_gatt_read_test_misc_mult_verify_good((struct ble_hs_test_util_flat_attr[]) { { + ble_gatt_read_test_misc_mult_verify_good( + (struct ble_hs_test_util_flat_attr[]) { { .handle = 43, .value = { 0, 1, 2, 3, 4, 5, 6, 7 }, .value_len = 7 @@ -678,7 +682,8 @@ TEST_CASE(ble_gatt_read_test_mult) } }); /* Read two attributes. */ - ble_gatt_read_test_misc_mult_verify_good((struct ble_hs_test_util_flat_attr[]) { { + ble_gatt_read_test_misc_mult_verify_good( + (struct ble_hs_test_util_flat_attr[]) { { .handle = 43, .value = { 0, 1, 2, 3, 4, 5, 6, 7 }, .value_len = 7, @@ -691,7 +696,8 @@ TEST_CASE(ble_gatt_read_test_mult) } }); /* Read two attributes (swap order). */ - ble_gatt_read_test_misc_mult_verify_good((struct ble_hs_test_util_flat_attr[]) { { + ble_gatt_read_test_misc_mult_verify_good( + (struct ble_hs_test_util_flat_attr[]) { { .handle = 44, .value = { 8, 9, 10, 11 }, .value_len = 4, @@ -704,7 +710,8 @@ TEST_CASE(ble_gatt_read_test_mult) } }); /* Read five attributes. */ - ble_gatt_read_test_misc_mult_verify_good((struct ble_hs_test_util_flat_attr[]) { { + ble_gatt_read_test_misc_mult_verify_good( + (struct ble_hs_test_util_flat_attr[]) { { .handle = 43, .value = { 0, 1, 2, 3, 4, 5, 6, 7 }, .value_len = 7, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_host_hci_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_host_hci_test.c b/net/nimble/host/src/test/ble_host_hci_test.c deleted file mode 100644 index 32c5cf4..0000000 --- a/net/nimble/host/src/test/ble_host_hci_test.c +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include <stddef.h> -#include <errno.h> -#include <string.h> -#include "nimble/hci_common.h" -#include "nimble/ble_hci_trans.h" -#include "host/host_hci.h" -#include "host/ble_hs_test.h" -#include "testutil/testutil.h" -#include "ble_hs_test_util.h" - -TEST_CASE(ble_host_hci_test_event_bad) -{ - uint8_t *buf; - int rc; - - /*** Invalid event code. */ - buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI); - TEST_ASSERT_FATAL(buf != NULL); - - buf[0] = 0xff; - buf[1] = 0; - rc = host_hci_evt_process(buf); - TEST_ASSERT(rc == BLE_HS_ENOTSUP); -} - -TEST_CASE(ble_host_hci_test_rssi) -{ - uint8_t params[BLE_HCI_READ_RSSI_ACK_PARAM_LEN]; - uint16_t opcode; - int8_t rssi; - int rc; - - opcode = host_hci_opcode_join(BLE_HCI_OGF_STATUS_PARAMS, - BLE_HCI_OCF_RD_RSSI); - - /*** Success. */ - /* Connection handle. */ - htole16(params + 0, 1); - - /* RSSI. */ - params[2] = -8; - - ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params); - - rc = ble_hci_util_read_rssi(1, &rssi); - TEST_ASSERT_FATAL(rc == 0); - TEST_ASSERT(rssi == -8); - - /*** Failure: incorrect connection handle. */ - htole16(params + 0, 99); - - ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params); - - rc = ble_hci_util_read_rssi(1, &rssi); - TEST_ASSERT(rc == BLE_HS_ECONTROLLER); - - /*** Failure: params too short. */ - ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params - 1); - rc = ble_hci_util_read_rssi(1, &rssi); - TEST_ASSERT(rc == BLE_HS_ECONTROLLER); - - /*** Failure: params too long. */ - ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params + 1); - rc = ble_hci_util_read_rssi(1, &rssi); - TEST_ASSERT(rc == BLE_HS_ECONTROLLER); -} - -TEST_SUITE(ble_host_hci_suite) -{ - tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL); - - ble_host_hci_test_event_bad(); - ble_host_hci_test_rssi(); -} - -int -ble_host_hci_test_all(void) -{ - ble_host_hci_suite(); - return tu_any_failed; -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_hs_adv_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_hs_adv_test.c b/net/nimble/host/src/test/ble_hs_adv_test.c index 89c61a2..e99fd5b 100644 --- a/net/nimble/host/src/test/ble_hs_adv_test.c +++ b/net/nimble/host/src/test/ble_hs_adv_test.c @@ -24,7 +24,6 @@ #include "nimble/hci_common.h" #include "host/ble_hs_adv.h" #include "host/ble_hs_test.h" -#include "host/host_hci.h" #include "ble_hs_test_util.h" #define BLE_ADV_TEST_DATA_OFF 4 http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_hs_conn_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c index 0e896f4..c957446 100644 --- a/net/nimble/host/src/test/ble_hs_conn_test.c +++ b/net/nimble/host/src/test/ble_hs_conn_test.c @@ -24,7 +24,6 @@ #include "nimble/hci_common.h" #include "host/ble_hs_adv.h" #include "host/ble_hs_test.h" -#include "host/host_hci.h" #include "ble_hs_test_util.h" static int http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_hs_hci_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_hs_hci_test.c b/net/nimble/host/src/test/ble_hs_hci_test.c new file mode 100644 index 0000000..21184b8 --- /dev/null +++ b/net/nimble/host/src/test/ble_hs_hci_test.c @@ -0,0 +1,99 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stddef.h> +#include <errno.h> +#include <string.h> +#include "nimble/hci_common.h" +#include "nimble/ble_hci_trans.h" +#include "host/ble_hs_test.h" +#include "testutil/testutil.h" +#include "ble_hs_test_util.h" + +TEST_CASE(ble_hs_hci_test_event_bad) +{ + uint8_t *buf; + int rc; + + /*** Invalid event code. */ + buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI); + TEST_ASSERT_FATAL(buf != NULL); + + buf[0] = 0xff; + buf[1] = 0; + rc = ble_hs_hci_evt_process(buf); + TEST_ASSERT(rc == BLE_HS_ENOTSUP); +} + +TEST_CASE(ble_hs_hci_test_rssi) +{ + uint8_t params[BLE_HCI_READ_RSSI_ACK_PARAM_LEN]; + uint16_t opcode; + int8_t rssi; + int rc; + + opcode = ble_hs_hci_util_opcode_join(BLE_HCI_OGF_STATUS_PARAMS, + BLE_HCI_OCF_RD_RSSI); + + /*** Success. */ + /* Connection handle. */ + htole16(params + 0, 1); + + /* RSSI. */ + params[2] = -8; + + ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params); + + rc = ble_hs_hci_util_read_rssi(1, &rssi); + TEST_ASSERT_FATAL(rc == 0); + TEST_ASSERT(rssi == -8); + + /*** Failure: incorrect connection handle. */ + htole16(params + 0, 99); + + ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params); + + rc = ble_hs_hci_util_read_rssi(1, &rssi); + TEST_ASSERT(rc == BLE_HS_ECONTROLLER); + + /*** Failure: params too short. */ + ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params - 1); + rc = ble_hs_hci_util_read_rssi(1, &rssi); + TEST_ASSERT(rc == BLE_HS_ECONTROLLER); + + /*** Failure: params too long. */ + ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params + 1); + rc = ble_hs_hci_util_read_rssi(1, &rssi); + TEST_ASSERT(rc == BLE_HS_ECONTROLLER); +} + +TEST_SUITE(ble_hs_hci_suite) +{ + tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL); + + ble_hs_hci_test_event_bad(); + ble_hs_hci_test_rssi(); +} + +int +ble_hs_hci_test_all(void) +{ + ble_hs_hci_suite(); + return tu_any_failed; +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_hs_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c index 0b89bc9..3bc468e 100644 --- a/net/nimble/host/src/test/ble_hs_test.c +++ b/net/nimble/host/src/test/ble_hs_test.c @@ -46,7 +46,7 @@ main(int argc, char **argv) ble_gatts_notify_test_all(); ble_gatts_read_test_suite(); ble_gatts_reg_test_all(); - ble_host_hci_test_all(); + ble_hs_hci_test_all(); ble_hs_adv_test_all(); ble_hs_conn_test_all(); ble_l2cap_test_all(); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_hs_test_util.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c index 831a077..cfb86fa 100644 --- a/net/nimble/host/src/test/ble_hs_test_util.c +++ b/net/nimble/host/src/test/ble_hs_test_util.c @@ -26,7 +26,6 @@ #include "nimble/ble_hci_trans.h" #include "host/ble_hs_adv.h" #include "host/ble_hs_id.h" -#include "host/host_hci.h" #include "transport/ram/ble_hci_ram.h" #include "ble_hs_test_util.h" @@ -47,7 +46,7 @@ static const uint8_t ble_hs_test_util_pub_addr[BLE_DEV_ADDR_LEN] = OS_MEMPOOL_SIZE(BLE_HS_TEST_UTIL_NUM_MBUFS, BLE_HS_TEST_UTIL_MEMBLOCK_SIZE) #define BLE_HS_TEST_UTIL_LE_OPCODE(ocf) \ - host_hci_opcode_join(BLE_HCI_OGF_LE, (ocf)) + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, (ocf)) struct os_eventq ble_hs_test_util_evq; @@ -106,7 +105,7 @@ ble_hs_test_util_prev_tx_dequeue_once(struct hci_data_hdr *out_hci_hdr) om = OS_MBUF_PKTHDR_TO_MBUF(omp); - rc = ble_hci_util_data_hdr_strip(om, out_hci_hdr); + rc = ble_hs_hci_util_data_hdr_strip(om, out_hci_hdr); TEST_ASSERT_FATAL(rc == 0); TEST_ASSERT_FATAL(out_hci_hdr->hdh_len == OS_MBUF_PKTLEN(om)); @@ -262,7 +261,7 @@ ble_hs_test_util_rx_hci_evt(uint8_t *evt) memcpy(evbuf, evt, totlen); rc = ble_hci_trans_ll_evt_tx(evbuf); } else { - rc = host_hci_evt_process(evt); + rc = ble_hs_hci_evt_process(evt); } TEST_ASSERT_FATAL(rc == 0); @@ -352,7 +351,7 @@ ble_hs_test_util_set_ack_params(uint16_t opcode, uint8_t status, void *params, } ble_hs_test_util_num_phony_acks = 1; - ble_hci_set_phony_ack_cb(ble_hs_test_util_phony_ack_cb); + ble_hs_hci_set_phony_ack_cb(ble_hs_test_util_phony_ack_cb); } void @@ -371,7 +370,7 @@ ble_hs_test_util_set_ack_seq(struct ble_hs_test_util_phony_ack *acks) } ble_hs_test_util_num_phony_acks = i; - ble_hci_set_phony_ack_cb(ble_hs_test_util_phony_ack_cb); + ble_hs_hci_set_phony_ack_cb(ble_hs_test_util_phony_ack_cb); } void @@ -500,7 +499,8 @@ ble_hs_test_util_connect(uint8_t own_addr_type, uint8_t peer_addr_type, ble_hs_test_util_prev_hci_tx_clear(); ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_CREATE_CONN), ack_status); rc = ble_gap_connect(own_addr_type, peer_addr_type, peer_addr, duration_ms, @@ -526,8 +526,8 @@ ble_hs_test_util_conn_cancel(uint8_t ack_status) int rc; ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_CREATE_CONN_CANCEL), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_CREATE_CONN_CANCEL), ack_status); rc = ble_gap_conn_cancel(); @@ -557,8 +557,8 @@ ble_hs_test_util_conn_terminate(uint16_t conn_handle, uint8_t hci_status) int rc; ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LINK_CTRL, - BLE_HCI_OCF_DISCONNECT_CMD), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LINK_CTRL, + BLE_HCI_OCF_DISCONNECT_CMD), hci_status); rc = ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM); @@ -623,8 +623,8 @@ ble_hs_test_util_disc_cancel(uint8_t ack_status) int rc; ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_SET_SCAN_ENABLE), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_SET_SCAN_ENABLE), ack_status); rc = ble_gap_disc_cancel(); @@ -654,8 +654,9 @@ ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields, if (auto_pwr) { ble_hs_test_util_set_ack_params( - host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR), hci_status, + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR), + hci_status, ((uint8_t[1]){0}), 1); } @@ -884,8 +885,8 @@ ble_hs_test_util_l2cap_rx_payload_flat(uint16_t conn_handle, uint16_t cid, TEST_ASSERT_FATAL(rc == 0); hci_hdr.hdh_handle_pb_bc = - host_hci_handle_pb_bc_join(conn_handle, - BLE_HCI_PB_FIRST_FLUSH, 0); + ble_hs_hci_util_handle_pb_bc_join(conn_handle, + BLE_HCI_PB_FIRST_FLUSH, 0); hci_hdr.hdh_len = OS_MBUF_PKTHDR(om)->omp_len; rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, cid, &hci_hdr, om); @@ -919,55 +920,55 @@ ble_hs_test_util_set_startup_acks(void) */ ble_hs_test_util_set_ack_seq(((struct ble_hs_test_util_phony_ack[]) { { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_CTLR_BASEBAND, - BLE_HCI_OCF_CB_RESET), + .opcode = ble_hs_hci_util_opcode_join(BLE_HCI_OGF_CTLR_BASEBAND, + BLE_HCI_OCF_CB_RESET), }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_CTLR_BASEBAND, - BLE_HCI_OCF_CB_SET_EVENT_MASK), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_SET_EVENT_MASK), }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_CTLR_BASEBAND, - BLE_HCI_OCF_CB_SET_EVENT_MASK2), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_SET_EVENT_MASK2), }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_SET_EVENT_MASK), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_EVENT_MASK), }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_RD_BUF_SIZE), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_BUF_SIZE), /* Use a very low buffer size (16) to test fragmentation. */ .evt_params = { 0x10, 0x00, 0x20 }, .evt_params_len = 3, }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT), .evt_params = { 0 }, .evt_params_len = 8, }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_INFO_PARAMS, - BLE_HCI_OCF_IP_RD_BD_ADDR), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_BD_ADDR), .evt_params = BLE_HS_TEST_UTIL_PUB_ADDR_VAL, .evt_params_len = 6, }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_SET_ADDR_RES_EN), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADDR_RES_EN), }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_CLR_RESOLV_LIST), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CLR_RESOLV_LIST), }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_SET_ADDR_RES_EN), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADDR_RES_EN), }, { - .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_ADD_RESOLV_LIST), + .opcode = ble_hs_hci_util_opcode_join( + BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ADD_RESOLV_LIST), }, { 0 } })); @@ -1375,10 +1376,10 @@ ble_hs_test_util_init(void) rc = os_msys_register(&ble_hs_test_util_mbuf_pool); TEST_ASSERT_FATAL(rc == 0); - ble_hci_set_phony_ack_cb(NULL); + ble_hs_hci_set_phony_ack_cb(NULL); ble_hci_trans_cfg_ll(ble_hs_test_util_hci_txed, NULL, - ble_hs_test_util_pkt_txed, NULL); + ble_hs_test_util_pkt_txed, NULL); hci_cfg = ble_hci_ram_cfg_dflt; hci_cfg.num_evt_bufs = cfg.max_hci_bufs; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_l2cap_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c index 118d04f..69db2f8 100644 --- a/net/nimble/host/src/test/ble_l2cap_test.c +++ b/net/nimble/host/src/test/ble_l2cap_test.c @@ -21,7 +21,6 @@ #include <errno.h> #include "testutil/testutil.h" #include "nimble/hci_common.h" -#include "host/host_hci.h" #include "host/ble_hs_test.h" #include "ble_hs_test_util.h" @@ -74,7 +73,8 @@ ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id, ble_l2cap_sig_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req); ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CONN_UPDATE), 0); + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_CONN_UPDATE), 0); rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SIG, &hci_hdr, om); TEST_ASSERT_FATAL(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_os_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c index e12e489..a9c28ea 100644 --- a/net/nimble/host/src/test/ble_os_test.c +++ b/net/nimble/host/src/test/ble_os_test.c @@ -225,7 +225,8 @@ ble_os_disc_test_task_handler(void *arg) TEST_ASSERT(!cb_called); ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_ENABLE), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_SET_SCAN_ENABLE), 0); /* Wait 250 more ms; verify scan completed. */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_sm_lgcy_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_sm_lgcy_test.c b/net/nimble/host/src/test/ble_sm_lgcy_test.c index 9a61087..6e451ca 100644 --- a/net/nimble/host/src/test/ble_sm_lgcy_test.c +++ b/net/nimble/host/src/test/ble_sm_lgcy_test.c @@ -23,7 +23,6 @@ #include "testutil/testutil.h" #include "nimble/hci_common.h" #include "nimble/nimble_opt.h" -#include "host/host_hci.h" #include "host/ble_sm.h" #include "host/ble_hs_test.h" #include "ble_hs_test_util.h" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_sm_sc_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_sm_sc_test.c b/net/nimble/host/src/test/ble_sm_sc_test.c index f69c60e..518720c 100644 --- a/net/nimble/host/src/test/ble_sm_sc_test.c +++ b/net/nimble/host/src/test/ble_sm_sc_test.c @@ -23,7 +23,6 @@ #include "testutil/testutil.h" #include "nimble/hci_common.h" #include "nimble/nimble_opt.h" -#include "host/host_hci.h" #include "host/ble_sm.h" #include "host/ble_hs_test.h" #include "ble_hs_test_util.h" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_sm_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_sm_test.c b/net/nimble/host/src/test/ble_sm_test.c index 26efea9..f139ddb 100644 --- a/net/nimble/host/src/test/ble_sm_test.c +++ b/net/nimble/host/src/test/ble_sm_test.c @@ -23,7 +23,6 @@ #include "testutil/testutil.h" #include "nimble/hci_common.h" #include "nimble/nimble_opt.h" -#include "host/host_hci.h" #include "host/ble_sm.h" #include "host/ble_hs_test.h" #include "ble_hs_test_util.h" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/src/test/ble_sm_test_util.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c index bdecde6..5cb1d40 100644 --- a/net/nimble/host/src/test/ble_sm_test_util.c +++ b/net/nimble/host/src/test/ble_sm_test_util.c @@ -23,7 +23,6 @@ #include "testutil/testutil.h" #include "nimble/hci_common.h" #include "nimble/nimble_opt.h" -#include "host/host_hci.h" #include "host/ble_sm.h" #include "host/ble_hs_test.h" #include "host/ble_hs_id.h" @@ -916,8 +915,8 @@ ble_sm_test_util_set_lt_key_req_neg_reply_ack(uint8_t status, htole16(params, conn_handle); ble_hs_test_util_set_ack_params( - host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY), status, params, sizeof params); } @@ -928,7 +927,8 @@ ble_sm_test_util_set_lt_key_req_reply_ack(uint8_t status, uint16_t conn_handle) htole16(params, conn_handle); ble_hs_test_util_set_ack_params( - host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY), status, params, sizeof params); } @@ -1371,7 +1371,8 @@ ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t our_addr_type, TEST_ASSERT(ble_sm_dbg_num_procs() == 0); ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_START_ENCRYPT), 0); if (send_enc_req) { @@ -1656,8 +1657,8 @@ ble_sm_test_util_rx_keys(struct ble_sm_test_params *params, } if (peer_key_dist & BLE_SM_PAIR_KEY_DIST_ID) { ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_ADD_RESOLV_LIST), 0); + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_ADD_RESOLV_LIST), 0); ble_sm_test_util_rx_id_info(2, peer_id_info, 0); ble_sm_test_util_rx_id_addr_info(2, peer_id_addr_info, 0); } @@ -1724,7 +1725,8 @@ ble_sm_test_util_us_lgcy_good_once(struct ble_sm_test_params *params) TEST_ASSERT(ble_sm_dbg_num_procs() == 0); ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0); + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_START_ENCRYPT), 0); if (params->sec_req.authreq != 0) { ble_sm_test_util_rx_sec_req(2, ¶ms->sec_req, 0); } else { @@ -1984,7 +1986,8 @@ ble_sm_test_util_us_sc_good_once(struct ble_sm_test_params *params) TEST_ASSERT(ble_sm_dbg_num_procs() == 0); ble_hs_test_util_set_ack( - host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0); + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_START_ENCRYPT), 0); if (params->sec_req.authreq != 0) { ble_sm_test_util_rx_sec_req(2, ¶ms->sec_req, 0); } else { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d842a43c/net/nimble/host/store/ram/src/ble_store_ram.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/store/ram/src/ble_store_ram.c b/net/nimble/host/store/ram/src/ble_store_ram.c index d1e41b4..7528f03 100644 --- a/net/nimble/host/store/ram/src/ble_store_ram.c +++ b/net/nimble/host/store/ram/src/ble_store_ram.c @@ -136,7 +136,8 @@ ble_store_ram_read_our_sec(struct ble_store_key_sec *key_sec, { int idx; - idx = ble_store_ram_find_sec(key_sec, ble_store_ram_our_secs, ble_store_ram_num_our_secs); + idx = ble_store_ram_find_sec(key_sec, ble_store_ram_our_secs, + ble_store_ram_num_our_secs); if (idx == -1) { return BLE_HS_ENOENT; }
