example: register for events after setting up the stack, register for hci events after sm_init()

This commit is contained in:
Matthias Ringwald 2018-08-24 10:03:14 +02:00
parent 04115d8549
commit a4fe646795
37 changed files with 228 additions and 187 deletions

View File

@ -211,10 +211,6 @@ static void handle_l2cap_media_data_packet(uint8_t seid, uint8_t *packet, uint16
static int a2dp_and_avrcp_setup(void){
/* Register for HCI events */
hci_event_callback_registration.callback = &hci_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
// Initialize AVDTP Sink
a2dp_sink_init();
@ -246,6 +242,10 @@ static int a2dp_and_avrcp_setup(void){
gap_discoverable_control(1);
gap_set_class_of_device(0x200408);
/* Register for HCI events */
hci_event_callback_registration.callback = &hci_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
return 0;
}

View File

@ -235,9 +235,6 @@ static void stdin_process(char cmd);
#endif
static int a2dp_source_and_avrcp_services_init(void){
// Register for HCI events.
hci_event_callback_registration.callback = &a2dp_source_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
// Initialize A2DP Source.
@ -276,6 +273,10 @@ static int a2dp_source_and_avrcp_services_init(void){
gap_discoverable_control(1);
gap_set_class_of_device(0x200408);
// Register for HCI events.
hci_event_callback_registration.callback = &a2dp_source_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
hxcmod_initialized = hxcmod_init(&mod_context);
if (hxcmod_initialized){
hxcmod_setcfg(&mod_context, A2DP_SAMPLE_RATE, 16, 1, 1, 1);

View File

@ -136,9 +136,6 @@ int btstack_main(int argc, const char * argv[]){
printf("BTstack ANCS Client starting up...\n");
// register for HCI events
hci_event_callback_registration.callback = &app_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// set up l2cap_le
l2cap_init();
@ -151,19 +148,28 @@ int btstack_main(int argc, const char * argv[]){
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
sm_set_authentication_requirements( SM_AUTHREQ_BONDING );
// register for HCI events
hci_event_callback_registration.callback = &app_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// register for SM events
sm_event_callback_registration.callback = &app_packet_handler;
sm_add_event_handler(&sm_event_callback_registration);
// setup ATT server
att_server_init(profile_data, NULL, NULL);
// setup ANCS Client
ancs_client_init();
// register for ATT Serer events
att_server_register_packet_handler(app_packet_handler);
// setup GATT client
gatt_client_init();
// setup ANCS Client
ancs_client_init();
// register for ancs events
ancs_client_register_callback(&ancs_callback);
// setup advertisements

View File

@ -231,10 +231,6 @@ static void heartbeat_handler(struct btstack_timer_source *ts){
int btstack_main(int argc, const char * argv[]);
int btstack_main(int argc, const char * argv[]){
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// init L2CAP
l2cap_init();
@ -247,17 +243,20 @@ int btstack_main(int argc, const char * argv[]){
memset(spp_service_buffer, 0, sizeof(spp_service_buffer));
spp_create_sdp_record(spp_service_buffer, 0x10001, RFCOMM_SERVER_CHANNEL, "SPP Counter");
sdp_register_service(spp_service_buffer);
printf("SDP service record size: %u\n", de_get_len(spp_service_buffer));
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// set local name
gap_set_local_name("ANT Demo");
// make discoverable
gap_discoverable_control(1);
// set one-shot timer
heartbeat.process = &heartbeat_handler;
btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
btstack_run_loop_add_timer(&heartbeat);
// set local name
gap_set_local_name("BlueMSP-Demo");
// make discoverable
gap_discoverable_control(1);
printf("Run...\n\r");
// turn on!

View File

@ -168,19 +168,13 @@ int btstack_main(int argc, const char * argv[]){
(void)argc;
(void)argv;
// Register for HCI events.
hci_event_callback_registration.callback = &avrcp_browsing_controller_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// Initialize L2CAP.
l2cap_init();
// Initialize AVRCP Controller.
avrcp_controller_init();
// Register AVRCP for HCI events.
avrcp_controller_register_packet_handler(&avrcp_browsing_controller_packet_handler);
// Initialize AVRCP Browsing Controller, HCI events will be sent to the AVRCP Controller callback.
// Initialize AVRCP Browsing Controller, HCI events will be sent to the AVRCP Controller callback.
avrcp_browsing_controller_init();
// // Register AVRCP for HCI events.
// avrcp_browsing_controller_register_packet_handler(&avrcp_browsing_controller_packet_handler);
@ -200,6 +194,14 @@ int btstack_main(int argc, const char * argv[]){
gap_discoverable_control(1);
gap_set_class_of_device(0x200408);
// Register for HCI events.
hci_event_callback_registration.callback = &avrcp_browsing_controller_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// Register for AVRCP events.
avrcp_controller_register_packet_handler(&avrcp_browsing_controller_packet_handler);
#ifdef HAVE_BTSTACK_STDIN
// Parse human readable Bluetooth address.
sscanf_bd_addr(device_addr_string, device_addr);

View File

@ -110,9 +110,6 @@ int btstack_main(int argc, const char * argv[]) {
(void)argc;
(void)argv;
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// make device connectable
// @note: gap_connectable_control will be enabled when an L2CAP service
// (e.g. RFCOMM) is initialized). Therefore, it's not needed in regular applications
@ -121,6 +118,9 @@ int btstack_main(int argc, const char * argv[]) {
// make device discoverable
gap_discoverable_control(1);
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// turn on!
hci_power_control(HCI_POWER_ON);

View File

@ -249,12 +249,12 @@ int btstack_main(int argc, const char * argv[]) {
(void)argc;
(void)argv;
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// enabled EIR
hci_set_inquiry_mode(INQUIRY_MODE_RSSI_AND_EIR);
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// turn on!
hci_power_control(HCI_POWER_ON);

View File

@ -68,11 +68,12 @@ static btstack_packet_callback_registration_t hci_event_callback_registration;
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
static void gap_le_advertisements_setup(void){
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// Active scanning, 100% (scan interval = scan window)
gap_set_scan_parameters(1,48,48);
gap_start_scan();
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
}
/* LISTING_END */

View File

@ -334,10 +334,6 @@ int btstack_main(int argc, const char * argv[]){
(void)argc;
(void)argv;
#endif
hci_event_callback_registration.callback = &hci_event_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
// setup ATT server - only needed if LE Peripheral does ATT queries on its own, e.g. Android phones
@ -349,6 +345,10 @@ int btstack_main(int argc, const char * argv[]){
sm_init();
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
hci_event_callback_registration.callback = &hci_event_handler;
hci_add_event_handler(&hci_event_callback_registration);
// turn on!
hci_power_control(HCI_POWER_ON);

View File

@ -102,10 +102,6 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
static void gatt_client_setup(void){
// register for HCI events
hci_event_callback_registration.callback = &handle_hci_event;
hci_add_event_handler(&hci_event_callback_registration);
// Initialize L2CAP and register HCI event handler
l2cap_init();
@ -115,6 +111,10 @@ static void gatt_client_setup(void){
// Optinoally, Setup security manager
sm_init();
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
// register for HCI events
hci_event_callback_registration.callback = &handle_hci_event;
hci_add_event_handler(&hci_event_callback_registration);
}
/* LISTING_END */
@ -297,12 +297,12 @@ int btstack_main(int argc, const char * argv[]){
(void)argv;
#endif
// setup ATT server - only needed if LE Peripheral does ATT queries on its own, e.g. Android phones
att_server_init(profile_data, NULL, NULL);
// setup GATT client
gatt_client_setup();
// setup ATT server - only needed if LE Peripheral does ATT queries on its own, e.g. Android and iOS
att_server_init(profile_data, NULL, NULL);
// turn on!
hci_power_control(HCI_POWER_ON);

View File

@ -364,10 +364,6 @@ int btstack_main(int argc, const char * argv[]){
(void)argc;
(void)argv;
#endif
hci_event_callback_registration.callback = &hci_event_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
gatt_client_init();
@ -375,6 +371,9 @@ int btstack_main(int argc, const char * argv[]){
sm_init();
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
hci_event_callback_registration.callback = &hci_event_handler;
hci_add_event_handler(&hci_event_callback_registration);
// turn on!
hci_power_control(HCI_POWER_ON);

View File

@ -563,11 +563,6 @@ int btstack_main(int argc, const char * argv[]){
sco_demo_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
hci_register_sco_packet_handler(&packet_handler);
gap_set_local_name("HFP AG Demo 00:00:00:00:00:00");
gap_discoverable_control(1);
@ -596,8 +591,6 @@ int btstack_main(int argc, const char * argv[]){
hfp_ag_init_hf_indicators(hf_indicators_nr, hf_indicators);
hfp_ag_init_call_hold_services(call_hold_services_nr, call_hold_services);
hfp_ag_set_subcriber_number_information(&subscriber_number, 1);
hfp_ag_register_packet_handler(&packet_handler);
hci_register_sco_packet_handler(&packet_handler);
// SDP Server
sdp_init();
@ -606,6 +599,14 @@ int btstack_main(int argc, const char * argv[]){
printf("SDP service record size: %u\n", de_get_len( hfp_service_buffer));
sdp_register_service(hfp_service_buffer);
// register for HCI events and SCO packets
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
hci_register_sco_packet_handler(&packet_handler);
// register for HFP events
hfp_ag_register_packet_handler(&packet_handler);
// parse humand readable Bluetooth address
sscanf_bd_addr(device_addr_string, device_addr);

View File

@ -564,11 +564,6 @@ int btstack_main(int argc, const char * argv[]){
sco_demo_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
hci_register_sco_packet_handler(&packet_handler);
gap_discoverable_control(1);
gap_set_class_of_device(0x200408);
gap_set_local_name("HFP HF Demo 00:00:00:00:00:00");
@ -591,15 +586,21 @@ int btstack_main(int argc, const char * argv[]){
hfp_hf_init_hf_indicators(sizeof(indicators)/sizeof(uint16_t), indicators);
hfp_hf_init_codecs(sizeof(codecs), codecs);
hfp_hf_register_packet_handler(packet_handler);
hci_register_sco_packet_handler(&packet_handler);
sdp_init();
memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer));
hfp_hf_create_sdp_record(hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_hf_service_name, hf_supported_features, wide_band_speech);
printf("SDP service record size: %u\n", de_get_len(hfp_service_buffer));
sdp_register_service(hfp_service_buffer);
// register for HCI events and SCO packets
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
hci_register_sco_packet_handler(&packet_handler);
hci_register_sco_packet_handler(&packet_handler);
// register for HFP events
hfp_hf_register_packet_handler(packet_handler);
#ifdef HAVE_BTSTACK_STDIN
// parse human readable Bluetooth address
sscanf_bd_addr(device_addr_string, device_addr);

View File

@ -138,13 +138,13 @@ static void handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel
static void hid_host_setup(void){
// Initialize L2CAP
l2cap_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// Initialize L2CAP
l2cap_init();
// Disable stdout buffering
setbuf(stdout, NULL);
}

View File

@ -382,11 +382,6 @@ int btstack_main(int argc, const char * argv[]){
(void)argc;
(void)argv;
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
hci_register_sco_packet_handler(&packet_handler);
gap_discoverable_control(1);
gap_set_class_of_device(0x2540);
gap_set_local_name("HID Keyboard Demo 00:00:00:00:00:00");
@ -408,9 +403,14 @@ int btstack_main(int argc, const char * argv[]){
printf("Device ID SDP service record size: %u\n", de_get_len((uint8_t*)device_id_sdp_service_buffer));
sdp_register_service(device_id_sdp_service_buffer);
// HID Device
hid_device_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// register for HID events
hid_device_register_packet_handler(&packet_handler);
#ifdef HAVE_BTSTACK_STDIN

View File

@ -284,11 +284,6 @@ int btstack_main(int argc, const char * argv[]){
(void)argc;
(void)argv;
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
hci_register_sco_packet_handler(&packet_handler);
gap_discoverable_control(1);
gap_set_class_of_device(0x2540);
gap_set_local_name("HID Mouse Demo 00:00:00:00:00:00");
@ -306,6 +301,12 @@ int btstack_main(int argc, const char * argv[]){
// HID Device
hid_device_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// register for HID
hid_device_register_packet_handler(&packet_handler);
#ifdef HAVE_BTSTACK_STDIN

View File

@ -179,10 +179,6 @@ const uint8_t adv_data_len = sizeof(adv_data);
static void le_keyboard_setup(void){
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
// setup le device db
@ -190,8 +186,6 @@ static void le_keyboard_setup(void){
// setup SM: Display only
sm_init();
sm_event_callback_registration.callback = &packet_handler;
sm_add_event_handler(&sm_event_callback_registration);
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION | SM_AUTHREQ_BONDING);
@ -206,7 +200,6 @@ static void le_keyboard_setup(void){
// setup HID Device service
hids_device_init(0, hid_descriptor_keyboard_boot_mode, sizeof(hid_descriptor_keyboard_boot_mode));
hids_device_register_packet_handler(packet_handler);
// setup advertisements
uint16_t adv_int_min = 0x0030;
@ -217,6 +210,17 @@ static void le_keyboard_setup(void){
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);
// 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 = &packet_handler;
sm_add_event_handler(&sm_event_callback_registration);
// register for HIDS
hids_device_register_packet_handler(packet_handler);
}
// HID Keyboard lookup

View File

@ -116,9 +116,6 @@ const uint8_t adv_data_len = sizeof(adv_data);
static void hog_mouse_setup(void){
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// setup l2cap and register for connection parameter updates
l2cap_init();
@ -129,8 +126,6 @@ static void hog_mouse_setup(void){
// setup SM: Display only
sm_init();
sm_event_callback_registration.callback = &packet_handler;
sm_add_event_handler(&sm_event_callback_registration);
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
// sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION | SM_AUTHREQ_BONDING);
sm_set_authentication_requirements(SM_AUTHREQ_BONDING);
@ -146,7 +141,6 @@ static void hog_mouse_setup(void){
// setup HID Device service
hids_device_init(0, hid_descriptor_mouse_boot_mode, sizeof(hid_descriptor_mouse_boot_mode));
hids_device_register_packet_handler(packet_handler);
// setup advertisements
uint16_t adv_int_min = 0x0030;
@ -157,6 +151,15 @@ static void hog_mouse_setup(void){
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);
// register for events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
sm_event_callback_registration.callback = &packet_handler;
sm_add_event_handler(&sm_event_callback_registration);
hids_device_register_packet_handler(packet_handler);
}
// HID Report sending

View File

@ -296,6 +296,8 @@ int btstack_main(int argc, const char * argv[]){
hsp_ag_init(rfcomm_channel_nr);
hsp_ag_register_packet_handler(&packet_handler);
// register for SCO packets
hci_register_sco_packet_handler(&packet_handler);
// parse human readable Bluetooth address

View File

@ -280,11 +280,6 @@ int btstack_main(int argc, const char * argv[]){
sco_demo_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
hci_register_sco_packet_handler(&packet_handler);
l2cap_init();
sdp_init();
@ -295,6 +290,13 @@ int btstack_main(int argc, const char * argv[]){
rfcomm_init();
hsp_hs_init(rfcomm_channel_nr);
// register for HCI events and SCO packets
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
hci_register_sco_packet_handler(&packet_handler);
// register for HSP events
hsp_hs_register_packet_handler(packet_handler);
#ifdef HAVE_BTSTACK_STDIN

View File

@ -95,10 +95,6 @@ const uint8_t adv_data_len = sizeof(adv_data);
static void le_counter_setup(void){
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
// setup le device db
@ -109,7 +105,6 @@ static void le_counter_setup(void){
// setup ATT server
att_server_init(profile_data, att_read_callback, att_write_callback);
att_server_register_packet_handler(packet_handler);
// setup battery service
battery_service_server_init(battery);
@ -124,6 +119,13 @@ static void le_counter_setup(void){
gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data);
gap_advertisements_enable(1);
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// register for ATT event
att_server_register_packet_handler(packet_handler);
// set one-shot timer
heartbeat.process = &heartbeat_handler;
btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);

View File

@ -339,14 +339,14 @@ int btstack_main(int argc, const char * argv[]){
(void)argv;
#endif
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
sm_init();
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// turn on!
hci_power_control(HCI_POWER_ON);

View File

@ -103,12 +103,7 @@ static uint8_t data_channel_buffer[TEST_PACKET_SIZE];
static void le_data_channel_setup(void){
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
l2cap_register_packet_handler(&packet_handler);
// setup le device db
le_device_db_init();
@ -119,6 +114,12 @@ static void le_data_channel_setup(void){
// 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);
l2cap_register_packet_handler(&packet_handler);
// le data channel setup
l2cap_le_register_service(&packet_handler, TSPX_le_psm, LEVEL_0);

View File

@ -136,10 +136,6 @@ static void next_connection_index(void){
static void le_streamer_setup(void){
// register for HCI events
hci_event_callback_registration.callback = &hci_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
// setup le device db
@ -150,8 +146,14 @@ static void le_streamer_setup(void){
// setup ATT server
att_server_init(profile_data, NULL, att_write_callback);
att_server_register_packet_handler(att_packet_handler);
// register for HCI events
hci_event_callback_registration.callback = &hci_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// register for ATT events
att_server_register_packet_handler(att_packet_handler);
// setup advertisements
uint16_t adv_int_min = 0x0030;
uint16_t adv_int_max = 0x0030;

View File

@ -7,7 +7,7 @@ CHARACTERISTIC, GATT_SERVICE_CHANGED, READ,
// Test Service
PRIMARY_SERVICE, 0000FF10-0000-1000-8000-00805F9B34FB
// Test Characteristic A, write_without_response as well as notify
CHARACTERISTIC, 0000FF11-0000-1000-8000-00805F9B34FB, WRITE_WITHOUT_RESPONSE | NOTIFY | DYNAMIC,
CHARACTERISTIC, 0000FF11-0000-1000-8000-00805F9B34FB, ENCRYPTION_KEY_SIZE_16 | WRITE_WITHOUT_RESPONSE | NOTIFY | DYNAMIC,
// Test Characteristic B, write_without_response as well as notify
CHARACTERISTIC, 0000FF12-0000-1000-8000-00805F9B34FB, WRITE_WITHOUT_RESPONSE | NOTIFY | DYNAMIC,

View File

@ -437,10 +437,6 @@ int btstack_main(int argc, const char * argv[]){
(void)argc;
(void)argv;
#endif
hci_event_callback_registration.callback = &hci_event_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
sm_init();
@ -449,6 +445,9 @@ int btstack_main(int argc, const char * argv[]){
// sm_init needed before gatt_client_init
gatt_client_init();
hci_event_callback_registration.callback = &hci_event_handler;
hci_add_event_handler(&hci_event_callback_registration);
// use different connection parameters: conn interval min/max (* 1.25 ms), slave latency, supervision timeout, CE len min/max (* 0.6125 ms)
// gap_set_connection_parameters(0x06, 0x06, 4, 1000, 0x01, 0x06 * 2);

View File

@ -95,10 +95,6 @@ static void network_send_packet_callback(const uint8_t * packet, uint16_t size);
static void panu_setup(void){
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// Initialize L2CAP
l2cap_init();
@ -110,6 +106,10 @@ static void panu_setup(void){
// Initialize network interface
btstack_network_init(&network_send_packet_callback);
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
}
/* LISTING_END */

View File

@ -229,13 +229,7 @@ int btstack_main(int argc, const char * argv[]){
(void)argc;
(void)argv;
sscanf_bd_addr(remote_addr_string, remote_addr);
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// init L2CAP
l2cap_init();
@ -248,6 +242,12 @@ int btstack_main(int argc, const char * argv[]){
// init PBAP Client
pbap_client_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
sscanf_bd_addr(remote_addr_string, remote_addr);
#ifdef HAVE_BTSTACK_STDIN
btstack_stdin_setup(stdin_process);
#endif

View File

@ -84,13 +84,12 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
static void handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
static void sdp_client_init(void){
// init L2CAP
l2cap_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// init L2CAP
l2cap_init();
}
/* LISTING_END */

View File

@ -75,13 +75,12 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
static void handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
static void sdp_client_init(void){
// init L2CAP
l2cap_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// init L2CAP
l2cap_init();
}
/* LISTING_END */

View File

@ -132,19 +132,16 @@ static void handle_query_rfcomm_event(uint8_t packet_type, uint16_t channel, uin
int btstack_main(int argc, const char * argv[]);
int btstack_main(int argc, const char * argv[]){
(void)argc;
(void)argv;
printf("Client HCI init done\r\n");
// init L2CAP
l2cap_init();
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// init L2CAP
l2cap_init();
// turn on!
hci_power_control(HCI_POWER_ON);

View File

@ -79,9 +79,6 @@ static btstack_packet_callback_registration_t sm_event_callback_registration;
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
static void sm_pairing_central_setup(void){
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
// setup le device db
@ -89,17 +86,23 @@ static void sm_pairing_central_setup(void){
// setup SM: Display only
sm_init();
sm_event_callback_registration.callback = &packet_handler;
sm_add_event_handler(&sm_event_callback_registration);
// setup ATT server
att_server_init(profile_data, NULL, NULL);
att_server_register_packet_handler(packet_handler);
att_server_init(profile_data, NULL, NULL);
/**
* Choose ONE of the following configurations
*/
// register handler
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
sm_event_callback_registration.callback = &packet_handler;
sm_add_event_handler(&sm_event_callback_registration);
att_server_register_packet_handler(packet_handler);
// LE Legacy Pairing, Just Works
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_YES_NO);
sm_set_authentication_requirements(SM_AUTHREQ_NO_BONDING);

View File

@ -83,10 +83,6 @@ const uint8_t adv_data_len = sizeof(adv_data);
static void sm_peripheral_setup(void){
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
// setup le device db
@ -94,8 +90,6 @@ static void sm_peripheral_setup(void){
// setup SM: Display only
sm_init();
sm_event_callback_registration.callback = &packet_handler;
sm_add_event_handler(&sm_event_callback_registration);
/**
* Choose ONE of the following configurations
@ -103,7 +97,7 @@ static void sm_peripheral_setup(void){
// LE Legacy Pairing, Just Works
// sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
// sm_set_authentication_requirements(0);
// sm_set_authentication_requirements(SM_AUTHREQ_BONDING);
// LE Legacy Pairing, Passkey entry initiator enter, responder (us) displays
// sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
@ -116,8 +110,8 @@ static void sm_peripheral_setup(void){
// sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION);
// LE Secure Connections, Numeric Comparison
// sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_YES_NO);
// sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION|SM_AUTHREQ_MITM_PROTECTION);
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION|SM_AUTHREQ_MITM_PROTECTION);
// LE Legacy Pairing, Passkey entry initiator enter, responder (us) displays
// sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
@ -127,7 +121,6 @@ static void sm_peripheral_setup(void){
// setup ATT server
att_server_init(profile_data, NULL, NULL);
att_server_register_packet_handler(packet_handler);
// setup advertisements
uint16_t adv_int_min = 0x0030;
@ -138,6 +131,17 @@ static void sm_peripheral_setup(void){
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);
// 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 = &packet_handler;
sm_add_event_handler(&sm_event_callback_registration);
// register for ATT
att_server_register_packet_handler(packet_handler);
}
/* LISTING_END */
@ -154,11 +158,22 @@ static void sm_peripheral_setup(void){
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(channel);
UNUSED(size);
hci_con_handle_t con_handle;
bd_addr_t addr;
switch (packet_type) {
case HCI_EVENT_PACKET:
switch (hci_event_packet_get_type(packet)) {
case HCI_EVENT_LE_META:
switch (hci_event_le_meta_get_subevent_code(packet)) {
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
// setup new
con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
sm_send_security_request(con_handle);
break;
default:
break;
}
break;
case SM_EVENT_JUST_WORKS_REQUEST:
printf("Just Works requested\n");
sm_just_works_confirm(sm_event_just_works_request_get_handle(packet));

View File

@ -261,11 +261,6 @@ static void heartbeat_handler(struct btstack_timer_source *ts){
int btstack_main(void);
int btstack_main(void)
{
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
rfcomm_init();
@ -290,12 +285,13 @@ int btstack_main(void)
// setup ATT server
att_server_init(profile_data, att_read_callback, att_write_callback);
att_server_register_packet_handler(packet_handler);
// set one-shot timer
heartbeat.process = &heartbeat_handler;
btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
btstack_run_loop_add_timer(&heartbeat);
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// register for ATT events
att_server_register_packet_handler(packet_handler);
// setup advertisements
uint16_t adv_int_min = 0x0030;
@ -307,6 +303,11 @@ int btstack_main(void)
gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data);
gap_advertisements_enable(1);
// set one-shot timer
heartbeat.process = &heartbeat_handler;
btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
btstack_run_loop_add_timer(&heartbeat);
// beat once
beat();

View File

@ -370,11 +370,6 @@ int btstack_main(int argc, const char * argv[])
UNUSED(argc);
(void)argv;
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
rfcomm_init();
@ -403,6 +398,12 @@ int btstack_main(int argc, const char * argv[])
// setup ATT server
att_server_init(profile_data, att_read_callback, att_write_callback);
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// register for ATT events
att_server_register_packet_handler(packet_handler);
// setup advertisements

View File

@ -251,10 +251,6 @@ int btstack_main(int argc, const char * argv[])
(void)argc;
(void)argv;
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
rfcomm_init();
@ -267,6 +263,10 @@ int btstack_main(int argc, const char * argv[])
sdp_register_service(spp_service_buffer);
// printf("SDP service record size: %u\n", de_get_len(spp_service_buffer));
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// short-cut to find other SPP Streamer
gap_set_class_of_device(TEST_COD);

View File

@ -266,15 +266,15 @@ int btstack_main(int argc, const char * argv[]){
UNUSED(argc);
(void)argv;
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
rfcomm_init();
rfcomm_register_service(packet_handler, RFCOMM_SERVER_CHANNEL, 0xffff);
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// init SDP
gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO);