mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-30 16:20:24 +00:00
example: rename le_data_channel examples into le_credit_based_flow_control_mode
This commit is contained in:
parent
40b92a9edc
commit
284d66bc61
@ -42,12 +42,12 @@ list_of_examples = {
|
||||
["gatt_battery_query"], ["gatt_device_information_query"], ["gatt_heart_rate_client"],
|
||||
["nordic_spp_le_counter"], ["nordic_spp_le_streamer"], ["ublox_spp_le_counter"],
|
||||
["sm_pairing_central"], ["sm_pairing_peripheral"],
|
||||
["le_data_channel_client"], ["le_data_channel_server"],
|
||||
["le_credit_based_flow_control_mode_client"], ["le_credit_based_flow_control_mode_server"],
|
||||
["att_delayed_response"], ["ancs_client_demo"], ["le_mitm"]],
|
||||
|
||||
"Networking" : [["pan_lwip_http_server"], ["panu_demo"]],
|
||||
|
||||
"Performance" : [["le_streamer_client"], ["gatt_streamer_server"], ["le_data_channel_client"], ["le_data_channel_server"], ["spp_streamer_client"], ["spp_streamer"]],
|
||||
"Performance" : [["le_streamer_client"], ["gatt_streamer_server"], ["le_credit_based_flow_control_mode_client"], ["le_credit_based_flow_control_mode_server"], ["spp_streamer_client"], ["spp_streamer"]],
|
||||
"Phone Book Access" : [["pbap_client_demo"]],
|
||||
|
||||
"SDP Queries" : [["sdp_general_query"], ["sdp_rfcomm_query"], ["sdp_bnep_query"]],
|
||||
|
@ -231,8 +231,8 @@ EXAMPLES_LE_ONLY= \
|
||||
hog_host_demo \
|
||||
hog_keyboard_demo \
|
||||
hog_mouse_demo \
|
||||
le_data_channel_client \
|
||||
le_data_channel_server \
|
||||
le_credit_based_flow_control_mode_client \
|
||||
le_credit_based_flow_control_mode_server \
|
||||
le_mitm \
|
||||
le_streamer_client \
|
||||
mesh_node_demo \
|
||||
@ -262,7 +262,7 @@ EXAMPLES_GATT_FILES = \
|
||||
gatt_streamer_server.gatt \
|
||||
hog_keyboard_demo.gatt \
|
||||
hog_mouse_demo.gatt \
|
||||
le_data_channel_server.gatt \
|
||||
le_credit_based_flow_control_mode_server.gatt \
|
||||
nordic_spp_le_counter.gatt \
|
||||
nordic_spp_le_streamer.gatt \
|
||||
sm_pairing_central.gatt \
|
||||
@ -492,14 +492,14 @@ avrcp_browsing_client: ${CORE_OBJ} ${COMMON_OBJ} ${CLASSIC_OBJ} ${SDP_CLIENT} ${
|
||||
dut_mode_classic: ${CORE_OBJ} ${COMMON_OBJ} ${CLASSIC_OBJ} dut_mode_classic.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
le_data_channel_client: ${CORE_OBJ} ${COMMON_OBJ} le_data_channel_client.c
|
||||
le_credit_based_flow_control_mode_client: ${CORE_OBJ} ${COMMON_OBJ} le_credit_based_flow_control_mode_client.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
|
||||
le_data_channel_server.o: le_data_channel_server.h le_data_channel_server.c
|
||||
${CC} ${CFLAGS} -c $(filter-out le_data_channel_server.h,$^) -o $@
|
||||
le_credit_based_flow_control_mode_server.o: le_credit_based_flow_control_mode_server.h le_credit_based_flow_control_mode_server.c
|
||||
${CC} ${CFLAGS} -c $(filter-out le_credit_based_flow_control_mode_server.h,$^) -o $@
|
||||
|
||||
le_data_channel_server: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} le_data_channel_server.o
|
||||
le_credit_based_flow_control_mode_server: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} le_credit_based_flow_control_mode_server.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
|
||||
|
@ -35,13 +35,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define BTSTACK_FILE__ "le_data_channel_client.c"
|
||||
#define BTSTACK_FILE__ "le_credit_based_flow_control_mode_client.c"
|
||||
|
||||
// *****************************************************************************
|
||||
/* EXAMPLE_START(le_data_channel_client): LE Data Channel Client - Send Data over L2CAP
|
||||
/* EXAMPLE_START(le_credit_based_flow_control_mode_client): LE Credit-Based Flow-Control Mode Client - Send Data over L2CAP
|
||||
*
|
||||
* @text Connects to 'LE Data Channel' and streams data
|
||||
* via LE Data Channel == LE Connection-Oriented Channel == LE Credit-based Connection
|
||||
* @text Connects to 'LE CBM Server' and streams data
|
||||
* via L2CAP Channel in LE Credit-Based Flow-Control Mode (CBM)
|
||||
*/
|
||||
// *****************************************************************************
|
||||
|
||||
@ -71,14 +71,14 @@ static bd_addr_t cmdline_addr;
|
||||
static int cmdline_addr_found = 0;
|
||||
|
||||
// addr and type of device with correct name
|
||||
static bd_addr_t le_data_channel_addr;
|
||||
static bd_addr_type_t le_data_channel_addr_type;
|
||||
static bd_addr_t le_cbm_server_addr;
|
||||
static bd_addr_type_t le_cbm_server_addr_type;
|
||||
|
||||
static hci_con_handle_t connection_handle;
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
static btstack_packet_callback_registration_t sm_event_callback_registration;
|
||||
|
||||
static uint8_t data_channel_buffer[TEST_PACKET_SIZE];
|
||||
static uint8_t cbm_receive_buffer[TEST_PACKET_SIZE];
|
||||
|
||||
/*
|
||||
* @section Track throughput
|
||||
@ -101,16 +101,16 @@ typedef struct {
|
||||
int test_data_len;
|
||||
uint32_t test_data_sent;
|
||||
uint32_t test_data_start;
|
||||
} le_data_channel_connection_t;
|
||||
} le_cbm_connection_t;
|
||||
|
||||
static le_data_channel_connection_t le_data_channel_connection;
|
||||
static le_cbm_connection_t le_cbm_connection;
|
||||
|
||||
static void test_reset(le_data_channel_connection_t * context){
|
||||
static void test_reset(le_cbm_connection_t * context){
|
||||
context->test_data_start = btstack_run_loop_get_time_ms();
|
||||
context->test_data_sent = 0;
|
||||
}
|
||||
|
||||
static void test_track_data(le_data_channel_connection_t * context, int bytes_transferred){
|
||||
static void test_track_data(le_cbm_connection_t * context, int bytes_transferred){
|
||||
context->test_data_sent += bytes_transferred;
|
||||
// evaluate
|
||||
uint32_t now = btstack_run_loop_get_time_ms();
|
||||
@ -167,24 +167,24 @@ static int advertisement_report_contains_name(const char * name, uint8_t * adver
|
||||
static void streamer(void){
|
||||
|
||||
// create test data
|
||||
le_data_channel_connection.counter++;
|
||||
if (le_data_channel_connection.counter > 'Z') le_data_channel_connection.counter = 'A';
|
||||
memset(le_data_channel_connection.test_data, le_data_channel_connection.counter, le_data_channel_connection.test_data_len);
|
||||
le_cbm_connection.counter++;
|
||||
if (le_cbm_connection.counter > 'Z') le_cbm_connection.counter = 'A';
|
||||
memset(le_cbm_connection.test_data, le_cbm_connection.counter, le_cbm_connection.test_data_len);
|
||||
|
||||
// send
|
||||
l2cap_cbm_send_data(le_data_channel_connection.cid, (uint8_t *) le_data_channel_connection.test_data, le_data_channel_connection.test_data_len);
|
||||
l2cap_cbm_send_data(le_cbm_connection.cid, (uint8_t *) le_cbm_connection.test_data, le_cbm_connection.test_data_len);
|
||||
|
||||
// track
|
||||
test_track_data(&le_data_channel_connection, le_data_channel_connection.test_data_len);
|
||||
test_track_data(&le_cbm_connection, le_cbm_connection.test_data_len);
|
||||
|
||||
// request another packet
|
||||
l2cap_cbm_request_can_send_now_event(le_data_channel_connection.cid);
|
||||
l2cap_cbm_request_can_send_now_event(le_cbm_connection.cid);
|
||||
}
|
||||
/* LISTING_END */
|
||||
#endif
|
||||
|
||||
// Either connect to remote specified on command line or start scan for device with "LE Data Channel" in advertisement
|
||||
static void le_data_channel_client_start(void){
|
||||
// Either connect to remote specified on command line or start scan for device with "LE CBM Server" in advertisement
|
||||
static void le_cbm_client_start(void){
|
||||
if (cmdline_addr_found){
|
||||
printf("Connect to %s\n", bd_addr_to_str(cmdline_addr));
|
||||
state = TC_W4_CONNECT;
|
||||
@ -214,7 +214,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
case BTSTACK_EVENT_STATE:
|
||||
// BTstack activated, get started
|
||||
if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING) {
|
||||
le_data_channel_client_start();
|
||||
le_cbm_client_start();
|
||||
} else {
|
||||
state = TC_OFF;
|
||||
}
|
||||
@ -222,15 +222,15 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
case GAP_EVENT_ADVERTISING_REPORT:
|
||||
if (state != TC_W4_SCAN_RESULT) return;
|
||||
// check name in advertisement
|
||||
if (!advertisement_report_contains_name("LE Data Channel", packet)) return;
|
||||
if (!advertisement_report_contains_name("LE CBM Server", packet)) return;
|
||||
// store address and type
|
||||
gap_event_advertising_report_get_address(packet, le_data_channel_addr);
|
||||
le_data_channel_addr_type = gap_event_advertising_report_get_address_type(packet);
|
||||
gap_event_advertising_report_get_address(packet, le_cbm_server_addr);
|
||||
le_cbm_server_addr_type = gap_event_advertising_report_get_address_type(packet);
|
||||
// stop scanning, and connect to the device
|
||||
state = TC_W4_CONNECT;
|
||||
gap_stop_scan();
|
||||
printf("Stop scan. Connect to device with addr %s.\n", bd_addr_to_str(le_data_channel_addr));
|
||||
gap_connect(le_data_channel_addr,le_data_channel_addr_type);
|
||||
printf("Stop scan. Connect to device with addr %s.\n", bd_addr_to_str(le_cbm_server_addr));
|
||||
gap_connect(le_cbm_server_addr, le_cbm_server_addr_type);
|
||||
break;
|
||||
case HCI_EVENT_LE_META:
|
||||
// wait for connection complete
|
||||
@ -243,19 +243,19 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
printf("Connection Latency: %u\n", hci_subevent_le_connection_complete_get_conn_latency(packet));
|
||||
// initialize gatt client context with handle, and add it to the list of active clients
|
||||
// query primary services
|
||||
printf("Connect to performance test channel.\n");
|
||||
printf("Connect to performance test service.\n");
|
||||
state = TC_W4_CHANNEL;
|
||||
l2cap_cbm_create_channel(&packet_handler, connection_handle, TSPX_le_psm, data_channel_buffer,
|
||||
sizeof(data_channel_buffer), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_0, &le_data_channel_connection.cid);
|
||||
l2cap_cbm_create_channel(&packet_handler, connection_handle, TSPX_le_psm, cbm_receive_buffer,
|
||||
sizeof(cbm_receive_buffer), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_0, &le_cbm_connection.cid);
|
||||
break;
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
if (cmdline_addr_found){
|
||||
printf("Disconnected %s\n", bd_addr_to_str(cmdline_addr));
|
||||
return;
|
||||
}
|
||||
printf("Disconnected %s\n", bd_addr_to_str(le_data_channel_addr));
|
||||
printf("Disconnected %s\n", bd_addr_to_str(le_cbm_server_addr));
|
||||
if (state == TC_OFF) break;
|
||||
le_data_channel_client_start();
|
||||
le_cbm_client_start();
|
||||
break;
|
||||
case L2CAP_EVENT_CBM_CHANNEL_OPENED:
|
||||
// inform about new l2cap connection
|
||||
@ -265,19 +265,19 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
handle = l2cap_event_le_channel_opened_get_handle(packet);
|
||||
status = l2cap_event_le_channel_opened_get_status(packet);
|
||||
if (status == ERROR_CODE_SUCCESS) {
|
||||
printf("L2CAP: LE Data Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
printf("L2CAP: CBM Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
bd_addr_to_str(event_address), handle, psm, cid, little_endian_read_16(packet, 15));
|
||||
le_data_channel_connection.cid = cid;
|
||||
le_data_channel_connection.connection_handle = handle;
|
||||
le_data_channel_connection.test_data_len = btstack_min(l2cap_event_le_channel_opened_get_remote_mtu(packet), sizeof(le_data_channel_connection.test_data));
|
||||
le_cbm_connection.cid = cid;
|
||||
le_cbm_connection.connection_handle = handle;
|
||||
le_cbm_connection.test_data_len = btstack_min(l2cap_event_le_channel_opened_get_remote_mtu(packet), sizeof(le_cbm_connection.test_data));
|
||||
state = TC_TEST_DATA;
|
||||
printf("Test packet size: %u\n", le_data_channel_connection.test_data_len);
|
||||
test_reset(&le_data_channel_connection);
|
||||
printf("Test packet size: %u\n", le_cbm_connection.test_data_len);
|
||||
test_reset(&le_cbm_connection);
|
||||
#ifdef TEST_STREAM_DATA
|
||||
l2cap_cbm_request_can_send_now_event(le_data_channel_connection.cid);
|
||||
l2cap_cbm_request_can_send_now_event(le_cbm_connection.cid);
|
||||
#endif
|
||||
} else {
|
||||
printf("L2CAP: LE Data Channel connection to device %s failed. status code 0x%02x\n", bd_addr_to_str(event_address), status);
|
||||
printf("L2CAP: Connection to device %s failed. status code 0x%02x\n", bd_addr_to_str(event_address), status);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -289,7 +289,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
|
||||
case L2CAP_EVENT_CBM_CHANNEL_CLOSED:
|
||||
cid = l2cap_event_le_channel_closed_get_local_cid(packet);
|
||||
printf("L2CAP: LE Data Channel closed 0x%02x\n", cid);
|
||||
printf("L2CAP: Channel closed 0x%02x\n", cid);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -298,7 +298,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
break;
|
||||
|
||||
case L2CAP_DATA_PACKET:
|
||||
test_track_data(&le_data_channel_connection, size);
|
||||
test_track_data(&le_cbm_connection, size);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -337,7 +337,7 @@ static void sm_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
#ifdef HAVE_BTSTACK_STDIN
|
||||
static void usage(const char *name){
|
||||
fprintf(stderr, "Usage: %s [-a|--address aa:bb:cc:dd:ee:ff]\n", name);
|
||||
fprintf(stderr, "If no argument is provided, LE Data Channel Client will start scanning and connect to the first device named 'LE Data Channel'.\n");
|
||||
fprintf(stderr, "If no argument is provided, LE CBM Client will start scanning and connect to the first device named 'LE CBM Server'.\n");
|
||||
fprintf(stderr, "To connect to a specific device use argument [-a].\n\n");
|
||||
}
|
||||
#endif
|
@ -35,12 +35,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define BTSTACK_FILE__ "le_data_channel_server.c"
|
||||
#define BTSTACK_FILE__ "le_credit_based_flow_control_mode_server.c"
|
||||
|
||||
// *****************************************************************************
|
||||
/* EXAMPLE_START(le_data_channel): LE Data Channel Server - Receive data over L2CAP
|
||||
/* EXAMPLE_START(le_credit_based_flow_control_mode_server): LE Credit-Based Flow-Control Mode Server - Receive data over L2CAP
|
||||
*
|
||||
* @text iOS 11 and newer supports LE Data Channels for fast transfer over LE
|
||||
* @text iOS 11 and newer supports L2CAP channels in LE Credit-Based Flow-Control Mode for fast transfer over LE
|
||||
* [https://github.com/bluekitchen/CBL2CAPChannel-Demo](Basic iOS example on GitHub)
|
||||
*/
|
||||
// *****************************************************************************
|
||||
@ -52,7 +52,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "btstack.h"
|
||||
#include "le_data_channel_server.h"
|
||||
#include "le_credit_based_flow_control_mode_server.h"
|
||||
|
||||
// #define TEST_STREAM_DATA
|
||||
#define TEST_PACKET_SIZE 1000
|
||||
@ -69,7 +69,7 @@ const uint8_t adv_data[] = {
|
||||
// Flags general discoverable, BR/EDR not supported
|
||||
0x02, 0x01, 0x06,
|
||||
// Name
|
||||
0x10, 0x09, 'L', 'E', ' ', 'D', 'a', 't', 'a', ' ', 'C', 'h', 'a', 'n', 'n', 'e', 'l',
|
||||
0x0E, 0x09, 'L', 'E', ' ', 'C', 'B', 'M', ' ', 'S', 'e', 'r', 'v', 'e', 'r',
|
||||
};
|
||||
const uint8_t adv_data_len = sizeof(adv_data);
|
||||
|
||||
@ -87,63 +87,13 @@ typedef struct {
|
||||
int test_data_len;
|
||||
uint32_t test_data_sent;
|
||||
uint32_t test_data_start;
|
||||
} le_data_channel_connection_t;
|
||||
} le_cbm_connection_t;
|
||||
|
||||
static le_data_channel_connection_t le_data_channel_connection;
|
||||
static le_cbm_connection_t le_cbm_connection;
|
||||
|
||||
static uint16_t initial_credits = L2CAP_LE_AUTOMATIC_CREDITS;
|
||||
static uint8_t data_channel_buffer[TEST_PACKET_SIZE];
|
||||
|
||||
/* @section Main Application Setup
|
||||
*
|
||||
* @text Listing MainConfiguration shows main application code.
|
||||
* It initializes L2CAP, the Security Manager, and configures the ATT Server with the pre-compiled
|
||||
* ATT Database generated from $le_data_channel.gatt$. Finally, it configures the advertisements
|
||||
* and boots the Bluetooth stack.
|
||||
*/
|
||||
|
||||
/* LISTING_START(MainConfiguration): Init L2CAP, SM, ATT Server, and enable advertisements */
|
||||
|
||||
static void le_data_channel_setup(void){
|
||||
|
||||
l2cap_init();
|
||||
|
||||
// setup le device db
|
||||
le_device_db_init();
|
||||
|
||||
// setup SM: Display only
|
||||
sm_init();
|
||||
|
||||
// setup ATT server: iOS disconnects if ATT MTU Exchange fails
|
||||
att_server_init(profile_data, NULL, NULL);
|
||||
|
||||
// register for HCI events
|
||||
hci_event_callback_registration.callback = &packet_handler;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
||||
// register for SM events
|
||||
sm_event_callback_registration.callback = &sm_packet_handler;
|
||||
sm_add_event_handler(&sm_event_callback_registration);
|
||||
|
||||
// register for L2CAP events
|
||||
l2cap_event_callback_registration.callback = &packet_handler;
|
||||
l2cap_add_event_handler(&l2cap_event_callback_registration);
|
||||
|
||||
// le data channel setup
|
||||
l2cap_cbm_register_service(&packet_handler, TSPX_le_psm, LEVEL_0);
|
||||
|
||||
// setup advertisements
|
||||
uint16_t adv_int_min = 0x0030;
|
||||
uint16_t adv_int_max = 0x0030;
|
||||
uint8_t adv_type = 0;
|
||||
bd_addr_t null_addr;
|
||||
memset(null_addr, 0, 6);
|
||||
gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00);
|
||||
gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data);
|
||||
gap_advertisements_enable(1);
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
/*
|
||||
* @section Track throughput
|
||||
* @text We calculate the throughput by setting a start time and measuring the amount of
|
||||
@ -153,12 +103,12 @@ static void le_data_channel_setup(void){
|
||||
|
||||
/* LISTING_START(tracking): Tracking throughput */
|
||||
|
||||
static void test_reset(le_data_channel_connection_t * context){
|
||||
static void test_reset(le_cbm_connection_t * context){
|
||||
context->test_data_start = btstack_run_loop_get_time_ms();
|
||||
context->test_data_sent = 0;
|
||||
}
|
||||
|
||||
static void test_track_data(le_data_channel_connection_t * context, int bytes_transferred){
|
||||
static void test_track_data(le_cbm_connection_t * context, int bytes_transferred){
|
||||
context->test_data_sent += bytes_transferred;
|
||||
// evaluate
|
||||
uint32_t now = btstack_run_loop_get_time_ms();
|
||||
@ -231,34 +181,34 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
case BTSTACK_EVENT_STATE:
|
||||
// BTstack activated, get started
|
||||
if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING) {
|
||||
printf("To start the streaming, please run the le_data_channel_client example on other device.\n");
|
||||
printf("To start streaming, please run the le_credit_based_flow_control_mode_client example on other device.\n");
|
||||
}
|
||||
break;
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
// free connection
|
||||
printf("%c: Disconnect, reason %02x\n", le_data_channel_connection.name, hci_event_disconnection_complete_get_reason(packet));
|
||||
le_data_channel_connection.connection_handle = HCI_CON_HANDLE_INVALID;
|
||||
printf("%c: Disconnect, reason %02x\n", le_cbm_connection.name, hci_event_disconnection_complete_get_reason(packet));
|
||||
le_cbm_connection.connection_handle = HCI_CON_HANDLE_INVALID;
|
||||
break;
|
||||
case HCI_EVENT_LE_META:
|
||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||
// print connection parameters (without using float operations)
|
||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
||||
printf("%c: Connection Interval: %u.%02u ms\n", le_data_channel_connection.name, conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||
printf("%c: Connection Latency: %u\n", le_data_channel_connection.name, hci_subevent_le_connection_complete_get_conn_latency(packet));
|
||||
printf("%c: Connection Interval: %u.%02u ms\n", le_cbm_connection.name, conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||
printf("%c: Connection Latency: %u\n", le_cbm_connection.name, hci_subevent_le_connection_complete_get_conn_latency(packet));
|
||||
|
||||
// min con interval 15 ms - supported from iOS 11
|
||||
gap_request_connection_parameter_update(le_data_channel_connection.connection_handle, 12, 12, 0, 0x0048);
|
||||
printf("Connected, requesting conn param update for handle 0x%04x\n", le_data_channel_connection.connection_handle);
|
||||
gap_request_connection_parameter_update(le_cbm_connection.connection_handle, 12, 12, 0, 0x0048);
|
||||
printf("Connected, requesting conn param update for handle 0x%04x\n", le_cbm_connection.connection_handle);
|
||||
//
|
||||
test_reset(&le_data_channel_connection);
|
||||
test_reset(&le_cbm_connection);
|
||||
break;
|
||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
||||
// print connection parameters (without using float operations)
|
||||
conn_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet);
|
||||
printf("LE Connection Update:\n");
|
||||
printf("%c: Connection Interval: %u.%02u ms\n", le_data_channel_connection.name, conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||
printf("%c: Connection Latency: %u\n", le_data_channel_connection.name, hci_subevent_le_connection_update_complete_get_conn_latency(packet));
|
||||
printf("%c: Connection Interval: %u.%02u ms\n", le_cbm_connection.name, conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||
printf("%c: Connection Latency: %u\n", le_cbm_connection.name, hci_subevent_le_connection_update_complete_get_conn_latency(packet));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -269,13 +219,13 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
printf("L2CAP Connection Parameter Update Complete, response: %x\n", l2cap_event_connection_parameter_update_response_get_result(packet));
|
||||
break;
|
||||
|
||||
// LE Data Channels
|
||||
// LE Credit-based Flow-Control Mode
|
||||
|
||||
case L2CAP_EVENT_CBM_INCOMING_CONNECTION:
|
||||
psm = l2cap_event_le_incoming_connection_get_psm(packet);
|
||||
cid = l2cap_event_le_incoming_connection_get_local_cid(packet);
|
||||
if (psm != TSPX_le_psm) break;
|
||||
printf("L2CAP: Accepting incoming LE connection request for 0x%02x, PSM %02x\n", cid, psm);
|
||||
printf("L2CAP: Accepting incoming connection request for 0x%02x, PSM %02x\n", cid, psm);
|
||||
l2cap_cbm_accept_connection(cid, data_channel_buffer, sizeof(data_channel_buffer), initial_credits);
|
||||
break;
|
||||
|
||||
@ -287,26 +237,26 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
handle = l2cap_event_le_channel_opened_get_handle(packet);
|
||||
status = l2cap_event_le_channel_opened_get_status(packet);
|
||||
if (status == ERROR_CODE_SUCCESS) {
|
||||
printf("L2CAP: LE Data Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
printf("L2CAP: Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
bd_addr_to_str(event_address), handle, psm, cid, little_endian_read_16(packet, 15));
|
||||
// setup new
|
||||
le_data_channel_connection.counter = 'A';
|
||||
le_data_channel_connection.cid = cid;
|
||||
le_data_channel_connection.connection_handle = handle;
|
||||
le_data_channel_connection.test_data_len = btstack_min(l2cap_event_le_channel_opened_get_remote_mtu(packet), sizeof(le_data_channel_connection.test_data));
|
||||
printf("Test packet size: %u\n", le_data_channel_connection.test_data_len);
|
||||
test_reset(&le_data_channel_connection);
|
||||
le_cbm_connection.counter = 'A';
|
||||
le_cbm_connection.cid = cid;
|
||||
le_cbm_connection.connection_handle = handle;
|
||||
le_cbm_connection.test_data_len = btstack_min(l2cap_event_le_channel_opened_get_remote_mtu(packet), sizeof(le_cbm_connection.test_data));
|
||||
printf("Test packet size: %u\n", le_cbm_connection.test_data_len);
|
||||
test_reset(&le_cbm_connection);
|
||||
#ifdef TEST_STREAM_DATA
|
||||
l2cap_cbm_request_can_send_now_event(le_data_channel_connection.cid);
|
||||
#endif
|
||||
} else {
|
||||
printf("L2CAP: LE Data Channel connection to device %s failed. status code %u\n", bd_addr_to_str(event_address), status);
|
||||
printf("L2CAP: Connection to device %s failed. status code %u\n", bd_addr_to_str(event_address), status);
|
||||
}
|
||||
break;
|
||||
|
||||
case L2CAP_EVENT_CBM_CHANNEL_CLOSED:
|
||||
printf("L2CAP: LE Data Channel closed\n");
|
||||
le_data_channel_connection.cid = 0;
|
||||
printf("L2CAP: Channel closed\n");
|
||||
le_cbm_connection.cid = 0;
|
||||
break;
|
||||
|
||||
#ifdef TEST_STREAM_DATA
|
||||
@ -321,7 +271,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
break;
|
||||
|
||||
case L2CAP_DATA_PACKET:
|
||||
test_track_data(&le_data_channel_connection, size);
|
||||
test_track_data(&le_cbm_connection, size);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -357,10 +307,52 @@ static void sm_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
}
|
||||
}
|
||||
|
||||
/* @section Main Application Setup
|
||||
*
|
||||
* @text Listing MainConfiguration shows main application code.
|
||||
* It initializes L2CAP, the Security Manager, and configures the ATT Server with the pre-compiled
|
||||
* ATT Database generated from $le_credit_based_flow_control_mode_server.gatt$. Finally, it configures the advertisements
|
||||
* and boots the Bluetooth stack.
|
||||
*/
|
||||
|
||||
int btstack_main(void);
|
||||
int btstack_main(void)
|
||||
{
|
||||
le_data_channel_setup();
|
||||
l2cap_init();
|
||||
|
||||
// setup le device db
|
||||
le_device_db_init();
|
||||
|
||||
// setup SM: Display only
|
||||
sm_init();
|
||||
|
||||
// setup ATT server: iOS disconnects if ATT MTU Exchange fails
|
||||
att_server_init(profile_data, NULL, NULL);
|
||||
|
||||
// register for HCI events
|
||||
hci_event_callback_registration.callback = &packet_handler;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
||||
// register for SM events
|
||||
sm_event_callback_registration.callback = &sm_packet_handler;
|
||||
sm_add_event_handler(&sm_event_callback_registration);
|
||||
|
||||
// register for L2CAP events
|
||||
l2cap_event_callback_registration.callback = &packet_handler;
|
||||
l2cap_add_event_handler(&l2cap_event_callback_registration);
|
||||
|
||||
// le data channel setup
|
||||
l2cap_cbm_register_service(&packet_handler, TSPX_le_psm, LEVEL_0);
|
||||
|
||||
// setup advertisements
|
||||
uint16_t adv_int_min = 0x0030;
|
||||
uint16_t adv_int_max = 0x0030;
|
||||
uint8_t adv_type = 0;
|
||||
bd_addr_t null_addr;
|
||||
memset(null_addr, 0, 6);
|
||||
gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00);
|
||||
gap_advertisements_set_data(adv_data_len, (uint8_t *) adv_data);
|
||||
gap_advertisements_enable(1);
|
||||
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
6
port/archive/posix-h5-bcm/.gitignore
vendored
6
port/archive/posix-h5-bcm/.gitignore
vendored
@ -44,9 +44,9 @@ hsp_hs_test
|
||||
l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
le_streamer_client
|
||||
|
6
port/libusb-intel/.gitignore
vendored
6
port/libusb-intel/.gitignore
vendored
@ -48,9 +48,9 @@ l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_counter_work
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
le_streamer_client
|
||||
|
6
port/libusb/.gitignore
vendored
6
port/libusb/.gitignore
vendored
@ -55,9 +55,9 @@ l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_counter_work
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_mitm
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
|
6
port/posix-h4-atwilc3000/.gitignore
vendored
6
port/posix-h4-atwilc3000/.gitignore
vendored
@ -39,9 +39,9 @@ hsp_hs_test
|
||||
l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
le_streamer_client
|
||||
|
6
port/posix-h4-da14581/.gitignore
vendored
6
port/posix-h4-da14581/.gitignore
vendored
@ -54,9 +54,9 @@ hsp_hs_test
|
||||
l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
le_streamer_and_counter_client
|
||||
|
6
port/posix-h4-da14585/.gitignore
vendored
6
port/posix-h4-da14585/.gitignore
vendored
@ -54,9 +54,9 @@ hsp_hs_test
|
||||
l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
le_streamer_and_counter_client
|
||||
|
6
port/posix-h4-zephyr/.gitignore
vendored
6
port/posix-h4-zephyr/.gitignore
vendored
@ -54,9 +54,9 @@ hsp_hs_test
|
||||
l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
le_streamer_and_counter_client
|
||||
|
6
port/posix-h4/.gitignore
vendored
6
port/posix-h4/.gitignore
vendored
@ -54,9 +54,9 @@ hsp_hs_test
|
||||
l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
le_streamer_and_counter_client
|
||||
|
6
port/posix-h5/.gitignore
vendored
6
port/posix-h5/.gitignore
vendored
@ -54,9 +54,9 @@ hsp_hs_test
|
||||
l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
le_streamer_and_counter_client
|
||||
|
6
port/raspi/.gitignore
vendored
6
port/raspi/.gitignore
vendored
@ -44,9 +44,9 @@ hsp_hs_test
|
||||
l2cap_test
|
||||
le_counter
|
||||
le_counter.h
|
||||
le_data_channel_client
|
||||
le_data_channel_server
|
||||
le_data_channel_server.h
|
||||
le_credit_based_flow_control_mode_client
|
||||
le_credit_based_flow_control_mode_server
|
||||
le_credit_based_flow_control_mode_server.h
|
||||
le_streamer
|
||||
le_streamer.h
|
||||
le_streamer_client
|
||||
|
Loading…
x
Reference in New Issue
Block a user