int ble_hs_test_util_l2cap_rx_payload_flat(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, const void *data, int len) { struct hci_data_hdr hci_hdr; struct os_mbuf *om; int rc; om = ble_hs_misc_pkthdr(); TEST_ASSERT_FATAL(om != NULL); om->om_data += BLE_L2CAP_HDR_SZ; rc = os_mbuf_append(om, data, len); TEST_ASSERT_FATAL(rc == 0); om = ble_l2cap_prepend_hdr(om, chan->blc_cid, OS_MBUF_PKTLEN(om)); TEST_ASSERT_FATAL(om != NULL); hci_hdr.hdh_handle_pb_bc = host_hci_handle_pb_bc_join(conn->bhc_handle, BLE_HCI_PB_FIRST_FLUSH, 0); hci_hdr.hdh_len = OS_MBUF_PKTHDR(om)->omp_len; rc = ble_hs_test_util_l2cap_rx(conn, &hci_hdr, om); return rc; }
static struct os_mbuf * host_hci_data_hdr_prepend(struct os_mbuf *om, uint16_t handle, uint8_t pb_flag) { struct hci_data_hdr hci_hdr; hci_hdr.hdh_handle_pb_bc = host_hci_handle_pb_bc_join(handle, pb_flag, 0); htole16(&hci_hdr.hdh_len, OS_MBUF_PKTHDR(om)->omp_len); om = os_mbuf_prepend(om, sizeof hci_hdr); if (om == NULL) { return NULL; } memcpy(om->om_data, &hci_hdr, sizeof hci_hdr); BLE_HS_LOG(DEBUG, "host tx hci data; handle=%d length=%d\n", handle, le16toh(&hci_hdr.hdh_len)); return om; }