mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-28 19:20:54 +00:00
l2cap: don't forward HCI to l2cap packet handler. Replace l2cap_register_packet_handler with hci_add_event_handler. Fix tests
This commit is contained in:
parent
17a9b5545c
commit
c5b64319fd
@ -72,7 +72,7 @@
|
|||||||
// ancs client demo profile
|
// ancs client demo profile
|
||||||
#include "ancs_client_demo.h"
|
#include "ancs_client_demo.h"
|
||||||
|
|
||||||
const uint8_t adv_data[] = {
|
static const uint8_t adv_data[] = {
|
||||||
// Flags general discoverable
|
// Flags general discoverable
|
||||||
0x02, 0x01, 0x02,
|
0x02, 0x01, 0x02,
|
||||||
// Name
|
// Name
|
||||||
@ -80,7 +80,8 @@ const uint8_t adv_data[] = {
|
|||||||
// Service Solicitation, 128-bit UUIDs - ANCS (little endian)
|
// Service Solicitation, 128-bit UUIDs - ANCS (little endian)
|
||||||
0x11,0x15,0xD0,0x00,0x2D,0x12,0x1E,0x4B,0x0F,0xA4,0x99,0x4E,0xCE,0xB5,0x31,0xF4,0x05,0x79
|
0x11,0x15,0xD0,0x00,0x2D,0x12,0x1E,0x4B,0x0F,0xA4,0x99,0x4E,0xCE,0xB5,0x31,0xF4,0x05,0x79
|
||||||
};
|
};
|
||||||
uint8_t adv_data_len = sizeof(adv_data);
|
static uint8_t adv_data_len = sizeof(adv_data);
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||||
switch (packet_type) {
|
switch (packet_type) {
|
||||||
@ -122,11 +123,19 @@ static void ancs_callback(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
app_packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
int btstack_main(int argc, const char * argv[]){
|
int btstack_main(int argc, const char * argv[]){
|
||||||
|
|
||||||
printf("BTstack ANCS Client starting up...\n");
|
printf("BTstack ANCS Client starting up...\n");
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// set up l2cap_le
|
// set up l2cap_le
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ static void gap_le_advertisements_setup(void){
|
|||||||
hci_event_callback_registration.callback = &packet_handler;
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
hci_add_event_handler(&hci_event_callback_registration);
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LISTING_END */
|
/* LISTING_END */
|
||||||
|
|
||||||
/* @section GAP LE Advertising Data Dumper
|
/* @section GAP LE Advertising Data Dumper
|
||||||
|
@ -91,6 +91,7 @@ static le_service_t battery_service;
|
|||||||
static le_characteristic_t config_characteristic;
|
static le_characteristic_t config_characteristic;
|
||||||
|
|
||||||
static gc_state_t state = TC_IDLE;
|
static gc_state_t state = TC_IDLE;
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static void printUUID(uint8_t * uuid128, uint16_t uuid16){
|
static void printUUID(uint8_t * uuid128, uint16_t uuid16){
|
||||||
if (uuid16){
|
if (uuid16){
|
||||||
@ -234,7 +235,7 @@ static void fill_advertising_report_from_packet(advertising_report_t * report, u
|
|||||||
dump_advertising_report(report);
|
dump_advertising_report(report);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void hci_event_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
advertising_report_t report;
|
advertising_report_t report;
|
||||||
uint8_t event = packet[0];
|
uint8_t event = packet[0];
|
||||||
@ -304,8 +305,10 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(&handle_hci_event);
|
|
||||||
|
|
||||||
gatt_client_init();
|
gatt_client_init();
|
||||||
gc_id = gatt_client_register_packet_handler(&handle_gatt_client_event);
|
gc_id = gatt_client_register_packet_handler(&handle_gatt_client_event);
|
||||||
|
@ -85,11 +85,12 @@ typedef struct advertising_report {
|
|||||||
static bd_addr_t cmdline_addr = { };
|
static bd_addr_t cmdline_addr = { };
|
||||||
static int cmdline_addr_found = 0;
|
static int cmdline_addr_found = 0;
|
||||||
|
|
||||||
uint16_t gc_handle;
|
static uint16_t gc_handle;
|
||||||
static le_service_t services[40];
|
static le_service_t services[40];
|
||||||
static int service_count = 0;
|
static int service_count = 0;
|
||||||
static int service_index = 0;
|
static int service_index = 0;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
/* @section GATT client setup
|
/* @section GATT client setup
|
||||||
*
|
*
|
||||||
@ -105,16 +106,20 @@ static uint16_t gc_id;
|
|||||||
|
|
||||||
// Handles connect, disconnect, and advertising report events,
|
// Handles connect, disconnect, and advertising report events,
|
||||||
// starts the GATT client, and sends the first query.
|
// starts the GATT client, and sends the first query.
|
||||||
static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
|
|
||||||
// Handles GATT client query results, sends queries and the
|
// Handles GATT client query results, sends queries and the
|
||||||
// GAP disconnect command when the querying is done.
|
// GAP disconnect command when the querying is done.
|
||||||
void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
|
|
||||||
static void gatt_client_setup(void){
|
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
|
// Initialize L2CAP and register HCI event handler
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(&handle_hci_event);
|
|
||||||
|
|
||||||
// Initialize GATT client
|
// Initialize GATT client
|
||||||
gatt_client_init();
|
gatt_client_init();
|
||||||
@ -180,7 +185,7 @@ static void fill_advertising_report_from_packet(advertising_report_t * report, u
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* LISTING_START(GATTBrowserHCIPacketHandler): Connecting and disconnecting from the GATT client */
|
/* LISTING_START(GATTBrowserHCIPacketHandler): Connecting and disconnecting from the GATT client */
|
||||||
static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
advertising_report_t report;
|
advertising_report_t report;
|
||||||
|
|
||||||
|
@ -76,6 +76,8 @@
|
|||||||
#include "l2cap.h"
|
#include "l2cap.h"
|
||||||
#include "btstack_debug.h"
|
#include "btstack_debug.h"
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static uint8_t hsp_service_buffer[150];
|
static uint8_t hsp_service_buffer[150];
|
||||||
static const uint8_t rfcomm_channel_nr = 1;
|
static const uint8_t rfcomm_channel_nr = 1;
|
||||||
static const char hsp_hs_service_name[] = "Headset Test";
|
static const char hsp_hs_service_name[] = "Headset Test";
|
||||||
@ -215,6 +217,9 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
int btstack_main(int argc, const char * argv[]){
|
int btstack_main(int argc, const char * argv[]){
|
||||||
@ -223,16 +228,17 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
compute_signal();
|
compute_signal();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 8-bit, 2's complement (== int8_t)
|
|
||||||
// 16-bit samples probably required for USB:
|
|
||||||
// hci_set_sco_voice_setting(0x0060);
|
|
||||||
|
|
||||||
hci_register_sco_packet_handler(&sco_packet_handler);
|
|
||||||
|
|
||||||
hci_discoverable_control(1);
|
hci_discoverable_control(1);
|
||||||
hci_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO);
|
hci_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO);
|
||||||
gap_set_local_name("BTstack HSP HS");
|
gap_set_local_name("BTstack HSP HS");
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
|
// register for SCO packets
|
||||||
|
hci_register_sco_packet_handler(&sco_packet_handler);
|
||||||
|
|
||||||
hsp_hs_init(rfcomm_channel_nr);
|
hsp_hs_init(rfcomm_channel_nr);
|
||||||
hsp_hs_register_packet_handler(packet_handler);
|
hsp_hs_register_packet_handler(packet_handler);
|
||||||
|
|
||||||
|
@ -85,8 +85,9 @@
|
|||||||
/* LISTING_START(MainConfiguration): Init L2CAP SM ATT Server and start heartbeat timer */
|
/* LISTING_START(MainConfiguration): Init L2CAP SM ATT Server and start heartbeat timer */
|
||||||
static int le_notification_enabled;
|
static int le_notification_enabled;
|
||||||
static btstack_timer_source_t heartbeat;
|
static btstack_timer_source_t heartbeat;
|
||||||
|
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 packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
static uint16_t att_read_callback(uint16_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size);
|
static uint16_t att_read_callback(uint16_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size);
|
||||||
static int att_write_callback(uint16_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
|
static int att_write_callback(uint16_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
|
||||||
static void heartbeat_handler(struct btstack_timer_source *ts);
|
static void heartbeat_handler(struct btstack_timer_source *ts);
|
||||||
@ -101,8 +102,12 @@ const uint8_t adv_data[] = {
|
|||||||
const uint8_t adv_data_len = sizeof(adv_data);
|
const uint8_t adv_data_len = sizeof(adv_data);
|
||||||
|
|
||||||
static void le_counter_setup(void){
|
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();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
// setup le device db
|
// setup le device db
|
||||||
le_device_db_init();
|
le_device_db_init();
|
||||||
@ -137,7 +142,7 @@ static void le_counter_setup(void){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* LISTING_START(packetHandler): Packet Handler */
|
/* LISTING_START(packetHandler): Packet Handler */
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
switch (packet_type) {
|
switch (packet_type) {
|
||||||
case HCI_EVENT_PACKET:
|
case HCI_EVENT_PACKET:
|
||||||
switch (packet[0]) {
|
switch (packet[0]) {
|
||||||
|
@ -74,8 +74,10 @@
|
|||||||
|
|
||||||
static int le_notification_enabled;
|
static int le_notification_enabled;
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size);
|
||||||
static int att_write_callback(uint16_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
|
static int att_write_callback(uint16_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
|
||||||
static void streamer(void);
|
static void streamer(void);
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
const uint8_t adv_data[] = {
|
const uint8_t adv_data[] = {
|
||||||
// Flags general discoverable
|
// Flags general discoverable
|
||||||
@ -102,6 +104,11 @@ static uint16_t conn_handle;
|
|||||||
/* LISTING_START(MainConfiguration): Init L2CAP, SM, ATT Server, and enable advertisements */
|
/* LISTING_START(MainConfiguration): Init L2CAP, SM, ATT Server, and enable advertisements */
|
||||||
|
|
||||||
static void le_streamer_setup(void){
|
static void le_streamer_setup(void){
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
|
|
||||||
// setup le device db
|
// setup le device db
|
||||||
@ -198,6 +205,10 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
streamer();
|
streamer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
/* LISTING_END */
|
/* LISTING_END */
|
||||||
/*
|
/*
|
||||||
* @section Streamer
|
* @section Streamer
|
||||||
|
@ -125,6 +125,7 @@ static char tap_dev_name[16] = "bnep%d";
|
|||||||
|
|
||||||
|
|
||||||
static btstack_data_source_t tap_dev_ds;
|
static btstack_data_source_t tap_dev_ds;
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
/* @section Main application configuration
|
/* @section Main application configuration
|
||||||
*
|
*
|
||||||
@ -137,9 +138,13 @@ 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, uint8_t *packet, uint16_t size);
|
static void handle_sdp_client_query_result(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
|
|
||||||
static void panu_setup(void){
|
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
|
// Initialize L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
// Initialise BNEP
|
// Initialise BNEP
|
||||||
bnep_init();
|
bnep_init();
|
||||||
|
@ -71,6 +71,7 @@ static uint8_t attribute_value[1000];
|
|||||||
static const int attribute_value_buffer_size = sizeof(attribute_value);
|
static const int attribute_value_buffer_size = sizeof(attribute_value);
|
||||||
|
|
||||||
static bd_addr_t remote = {0x04,0x0C,0xCE,0xE4,0x85,0xD3};
|
static bd_addr_t remote = {0x04,0x0C,0xCE,0xE4,0x85,0xD3};
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static void assertBuffer(int size){
|
static void assertBuffer(int size){
|
||||||
if (size > attribute_value_buffer_size){
|
if (size > attribute_value_buffer_size){
|
||||||
@ -88,13 +89,17 @@ static void assertBuffer(int size){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* LISTING_START(SDPClientInit): SDP client setup */
|
/* LISTING_START(SDPClientInit): SDP client setup */
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
static void handle_sdp_client_query_result(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
static void handle_sdp_client_query_result(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
|
|
||||||
static void sdp_client_init(void){
|
static void sdp_client_init(void){
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
sdp_parser_init();
|
sdp_parser_init();
|
||||||
sdp_parser_register_callback(handle_sdp_client_query_result);
|
sdp_parser_register_callback(handle_sdp_client_query_result);
|
||||||
@ -111,7 +116,7 @@ static void sdp_client_init(void){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* LISTING_START(SDPQueryUUID): Querying the a list of service records on a remote device. */
|
/* LISTING_START(SDPQueryUUID): Querying the a list of service records on a remote device. */
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
uint8_t event = packet[0];
|
uint8_t event = packet[0];
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ int attribute_id = -1;
|
|||||||
|
|
||||||
static uint8_t attribute_value[1000];
|
static uint8_t attribute_value[1000];
|
||||||
static const int attribute_value_buffer_size = sizeof(attribute_value);
|
static const int attribute_value_buffer_size = sizeof(attribute_value);
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
/* @section SDP Client Setup
|
/* @section SDP Client Setup
|
||||||
*
|
*
|
||||||
@ -78,13 +79,17 @@ static const int attribute_value_buffer_size = sizeof(attribute_value);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* LISTING_START(SDPClientInit): SDP client setup */
|
/* LISTING_START(SDPClientInit): SDP client setup */
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
static void handle_sdp_client_query_result(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
static void handle_sdp_client_query_result(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
|
|
||||||
static void sdp_client_init(void){
|
static void sdp_client_init(void){
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
sdp_parser_init();
|
sdp_parser_init();
|
||||||
sdp_parser_register_callback(handle_sdp_client_query_result);
|
sdp_parser_register_callback(handle_sdp_client_query_result);
|
||||||
@ -106,7 +111,7 @@ static bd_addr_t remote = {0x04,0x0C,0xCE,0xE4,0x85,0xD3};
|
|||||||
/* LISTING_END */
|
/* LISTING_END */
|
||||||
|
|
||||||
/* LISTING_START(SDPQueryUUID): Querying a list of service records on a remote device. */
|
/* LISTING_START(SDPQueryUUID): Querying a list of service records on a remote device. */
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
// printf("packet_handler type %u, packet[0] %x\n", packet_type, packet[0]);
|
// printf("packet_handler type %u, packet[0] %x\n", packet_type, packet[0]);
|
||||||
|
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
|
@ -65,9 +65,10 @@ static bd_addr_t remote = {0x84, 0x38, 0x35, 0x65, 0xD1, 0x15};
|
|||||||
static uint8_t service_index = 0;
|
static uint8_t service_index = 0;
|
||||||
static uint8_t channel_nr[10];
|
static uint8_t channel_nr[10];
|
||||||
static char* service_name[10];
|
static char* service_name[10];
|
||||||
|
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 packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
// printf("packet_handler type %u, packet[0] %x\n", packet_type, packet[0]);
|
// printf("packet_handler type %u, packet[0] %x\n", packet_type, packet[0]);
|
||||||
|
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
@ -125,9 +126,12 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
|
|
||||||
printf("Client HCI init done\r\n");
|
printf("Client HCI init done\r\n");
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
sdp_query_rfcomm_register_callback(handle_query_rfcomm_event);
|
sdp_query_rfcomm_register_callback(handle_query_rfcomm_event);
|
||||||
|
|
||||||
|
@ -87,6 +87,8 @@ static int counter = 0;
|
|||||||
static char counter_string[30];
|
static char counter_string[30];
|
||||||
static int counter_string_len;
|
static int counter_string_len;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @section Advertisements
|
* @section Advertisements
|
||||||
*
|
*
|
||||||
@ -179,6 +181,10 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
// ATT Client Read Callback for Dynamic Data
|
// ATT Client Read Callback for Dynamic Data
|
||||||
// - if buffer == NULL, don't copy data, just return size of value
|
// - if buffer == NULL, don't copy data, just return size of value
|
||||||
// - if buffer != NULL, copy data and return number bytes copied
|
// - if buffer != NULL, copy data and return number bytes copied
|
||||||
@ -250,8 +256,11 @@ int btstack_main(void)
|
|||||||
{
|
{
|
||||||
hci_discoverable_control(1);
|
hci_discoverable_control(1);
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
rfcomm_register_packet_handler(packet_handler);
|
rfcomm_register_packet_handler(packet_handler);
|
||||||
|
@ -70,9 +70,11 @@
|
|||||||
#define HEARTBEAT_PERIOD_MS 1000
|
#define HEARTBEAT_PERIOD_MS 1000
|
||||||
|
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size);
|
||||||
|
|
||||||
static uint16_t rfcomm_channel_id;
|
static uint16_t rfcomm_channel_id;
|
||||||
static uint8_t spp_service_buffer[150];
|
static uint8_t spp_service_buffer[150];
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
|
|
||||||
/* @section SPP Service Setup
|
/* @section SPP Service Setup
|
||||||
@ -91,8 +93,12 @@ static uint8_t spp_service_buffer[150];
|
|||||||
|
|
||||||
/* LISTING_START(SPPSetup): SPP service setup */
|
/* LISTING_START(SPPSetup): SPP service setup */
|
||||||
static void spp_service_setup(void){
|
static void spp_service_setup(void){
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
rfcomm_register_packet_handler(packet_handler);
|
rfcomm_register_packet_handler(packet_handler);
|
||||||
@ -252,6 +258,9 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
}
|
}
|
||||||
/* LISTING_RESUME */
|
/* LISTING_RESUME */
|
||||||
}
|
}
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
/* LISTING_END */
|
/* LISTING_END */
|
||||||
|
|
||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
|
@ -68,6 +68,7 @@ static uint8_t rfcomm_channel_nr = 1;
|
|||||||
static uint16_t rfcomm_channel_id;
|
static uint16_t rfcomm_channel_id;
|
||||||
static uint8_t rfcomm_send_credit = 0;
|
static uint8_t rfcomm_send_credit = 0;
|
||||||
static uint8_t spp_service_buffer[150];
|
static uint8_t spp_service_buffer[150];
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
/* @section SPP Service Setup
|
/* @section SPP Service Setup
|
||||||
*
|
*
|
||||||
@ -80,9 +81,13 @@ static uint8_t spp_service_buffer[150];
|
|||||||
|
|
||||||
/* LISTING_START(explicitFlowControl): Providing one initial credit during RFCOMM service initialization */
|
/* LISTING_START(explicitFlowControl): Providing one initial credit during RFCOMM service initialization */
|
||||||
static void spp_service_setup(void){
|
static void spp_service_setup(void){
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
// init RFCOMM
|
// init RFCOMM
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
|
@ -84,6 +84,7 @@ static uint16_t mtu;
|
|||||||
static uint16_t rfcomm_cid = 0;
|
static uint16_t rfcomm_cid = 0;
|
||||||
static uint32_t data_to_send = DATA_VOLUME;
|
static uint32_t data_to_send = DATA_VOLUME;
|
||||||
static state_t state = W4_SDP_RESULT;
|
static state_t state = W4_SDP_RESULT;
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static void create_test_data(void){
|
static void create_test_data(void){
|
||||||
int x,y;
|
int x,y;
|
||||||
@ -150,6 +151,9 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_found_service(const char * name, uint8_t port){
|
static void handle_found_service(const char * name, uint8_t port){
|
||||||
printf("APP: Service name: '%s', RFCOMM port %u\n", name, port);
|
printf("APP: Service name: '%s', RFCOMM port %u\n", name, port);
|
||||||
@ -189,9 +193,12 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
|
|
||||||
printf("Client HCI init done\r\n");
|
printf("Client HCI init done\r\n");
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
rfcomm_register_packet_handler(packet_handler);
|
rfcomm_register_packet_handler(packet_handler);
|
||||||
|
|
||||||
|
@ -192,6 +192,8 @@ static uint16_t gatt_client_id = 0;
|
|||||||
|
|
||||||
static void (*bluetooth_status_handler)(BLUETOOTH_STATE state) = dummy_bluetooth_status_handler;
|
static void (*bluetooth_status_handler)(BLUETOOTH_STATE state) = dummy_bluetooth_status_handler;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static int global_enable = 0;
|
static int global_enable = 0;
|
||||||
|
|
||||||
static btstack_link_key_db_t const * btstack_link_key_db = NULL;
|
static btstack_link_key_db_t const * btstack_link_key_db = NULL;
|
||||||
@ -1637,6 +1639,9 @@ static void daemon_packet_handler(void * connection, uint8_t packet_type, uint16
|
|||||||
daemon_emit_packet(connection, packet_type, channel, packet, size);
|
daemon_emit_packet(connection, packet_type, channel, packet, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
daemon_packet_handler(NULL, packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
static void l2cap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){
|
static void l2cap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){
|
||||||
daemon_packet_handler(NULL, packet_type, channel, packet, size);
|
daemon_packet_handler(NULL, packet_type, channel, packet, size);
|
||||||
}
|
}
|
||||||
@ -2067,6 +2072,10 @@ int main (int argc, char * const * argv){
|
|||||||
hci_ssp_set_enable(0);
|
hci_ssp_set_enable(0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(&l2cap_packet_handler);
|
l2cap_register_packet_handler(&l2cap_packet_handler);
|
||||||
|
@ -76,6 +76,7 @@ static uint8_t rfcomm_channel_nr = 1;
|
|||||||
static uint16_t rfcomm_channel_id = 0;
|
static uint16_t rfcomm_channel_id = 0;
|
||||||
static uint8_t spp_service_buffer[100];
|
static uint8_t spp_service_buffer[100];
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
// Bluetooth logic
|
// Bluetooth logic
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||||
@ -193,6 +194,10 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
static void heartbeat_handler(struct btstack_timer_source *ts){
|
static void heartbeat_handler(struct btstack_timer_source *ts){
|
||||||
|
|
||||||
if (rfcomm_channel_id){
|
if (rfcomm_channel_id){
|
||||||
@ -215,9 +220,12 @@ 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[]);
|
||||||
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 = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
// init RFCOMM
|
// init RFCOMM
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
|
@ -76,6 +76,7 @@ char lineBuffer[80];
|
|||||||
static uint8_t rfcomm_channel_nr = 1;
|
static uint8_t rfcomm_channel_nr = 1;
|
||||||
static uint16_t rfcomm_channel_id;
|
static uint16_t rfcomm_channel_id;
|
||||||
static uint8_t spp_service_buffer[150];
|
static uint8_t spp_service_buffer[150];
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
// SPP description
|
// SPP description
|
||||||
static uint8_t accel_buffer[6];
|
static uint8_t accel_buffer[6];
|
||||||
@ -197,6 +198,10 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
int btstack_main(int argc, const char * argv[]){
|
int btstack_main(int argc, const char * argv[]){
|
||||||
@ -205,9 +210,12 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
halAccelerometerInit();
|
halAccelerometerInit();
|
||||||
prepare_accel_packet();
|
prepare_accel_packet();
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
// init RFCOMM
|
// init RFCOMM
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
|
@ -76,6 +76,7 @@ static uint8_t rfcomm_channel_nr = 1;
|
|||||||
static uint16_t rfcomm_channel_id = 0;
|
static uint16_t rfcomm_channel_id = 0;
|
||||||
static uint8_t spp_service_buffer[100];
|
static uint8_t spp_service_buffer[100];
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
// Bluetooth logic
|
// Bluetooth logic
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||||
@ -192,6 +193,9 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
static void heartbeat_handler(struct btstack_timer_source *ts){
|
static void heartbeat_handler(struct btstack_timer_source *ts){
|
||||||
|
|
||||||
@ -215,9 +219,12 @@ 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[]);
|
||||||
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 = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
// init RFCOMM
|
// init RFCOMM
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
|
@ -86,6 +86,8 @@ typedef enum {
|
|||||||
|
|
||||||
static state_t state = 0;
|
static state_t state = 0;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
#define KEYCODE_RETURN '\n'
|
#define KEYCODE_RETURN '\n'
|
||||||
#define KEYCODE_ESCAPE 27
|
#define KEYCODE_ESCAPE 27
|
||||||
#define KEYCODE_TAB '\t'
|
#define KEYCODE_TAB '\t'
|
||||||
@ -341,6 +343,9 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
static hci_transport_config_uart_t config = {
|
static hci_transport_config_uart_t config = {
|
||||||
HCI_TRANSPORT_CONFIG_UART,
|
HCI_TRANSPORT_CONFIG_UART,
|
||||||
@ -383,9 +388,12 @@ int main(void){
|
|||||||
// use eHCILL
|
// use eHCILL
|
||||||
btstack_chipset_cc256x_enable_ehcill(1);
|
btstack_chipset_cc256x_enable_ehcill(1);
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
// ready - enable irq used in h4 task
|
// ready - enable irq used in h4 task
|
||||||
__enable_interrupt();
|
__enable_interrupt();
|
||||||
|
@ -80,6 +80,8 @@ static uint8_t spp_service_buffer[150];
|
|||||||
// SPP description
|
// SPP description
|
||||||
static uint8_t accel_buffer[6];
|
static uint8_t accel_buffer[6];
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static void prepare_accel_packet(void){
|
static void prepare_accel_packet(void){
|
||||||
int16_t accl_x;
|
int16_t accl_x;
|
||||||
int16_t accl_y;
|
int16_t accl_y;
|
||||||
@ -197,6 +199,9 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
int btstack_main(int argc, const char * argv[]){
|
int btstack_main(int argc, const char * argv[]){
|
||||||
@ -205,9 +210,12 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
halAccelerometerInit();
|
halAccelerometerInit();
|
||||||
prepare_accel_packet();
|
prepare_accel_packet();
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
// init RFCOMM
|
// init RFCOMM
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
|
@ -314,7 +314,7 @@ static void sm_truncate_key(sm_key_t key, int max_encryption_size){
|
|||||||
|
|
||||||
static void sm_timeout_handler(btstack_timer_source_t * timer){
|
static void sm_timeout_handler(btstack_timer_source_t * timer){
|
||||||
log_info("SM timeout");
|
log_info("SM timeout");
|
||||||
sm_connection_t * sm_conn = btstack_run_loop_get_timer_context(timer);
|
sm_connection_t * sm_conn = (sm_connection_t*) btstack_run_loop_get_timer_context(timer);
|
||||||
sm_conn->sm_engine_state = SM_GENERAL_TIMEOUT;
|
sm_conn->sm_engine_state = SM_GENERAL_TIMEOUT;
|
||||||
sm_done_for_handle(sm_conn->sm_handle);
|
sm_done_for_handle(sm_conn->sm_handle);
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ void hfp_create_sdp_record(uint8_t * service, uint32_t service_record_handle, ui
|
|||||||
|
|
||||||
static hfp_connection_t * connection_doing_sdp_query = NULL;
|
static hfp_connection_t * connection_doing_sdp_query = NULL;
|
||||||
|
|
||||||
static void handle_query_rfcomm_event(uint8_t packet_type, uint8_t *packet, uint16_t size, void * context){
|
static void handle_query_rfcomm_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
hfp_connection_t * connection = connection_doing_sdp_query;
|
hfp_connection_t * connection = connection_doing_sdp_query;
|
||||||
|
|
||||||
if ( connection->state != HFP_W4_SDP_EVENT_QUERY_COMPLETE) return;
|
if ( connection->state != HFP_W4_SDP_EVENT_QUERY_COMPLETE) return;
|
||||||
@ -1274,7 +1274,7 @@ static void parse_sequence(hfp_connection_t * context){
|
|||||||
|
|
||||||
void hfp_init(uint16_t rfcomm_channel_nr){
|
void hfp_init(uint16_t rfcomm_channel_nr){
|
||||||
rfcomm_register_service(rfcomm_channel_nr, 0xffff);
|
rfcomm_register_service(rfcomm_channel_nr, 0xffff);
|
||||||
sdp_query_rfcomm_register_callback(handle_query_rfcomm_event, NULL);
|
sdp_query_rfcomm_register_callback(handle_query_rfcomm_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hfp_establish_service_level_connection(bd_addr_t bd_addr, uint16_t service_uuid){
|
void hfp_establish_service_level_connection(bd_addr_t bd_addr, uint16_t service_uuid){
|
||||||
|
@ -62,6 +62,21 @@
|
|||||||
#include "classic/hfp_gsm_model.h"
|
#include "classic/hfp_gsm_model.h"
|
||||||
#include "classic/hfp_ag.h"
|
#include "classic/hfp_ag.h"
|
||||||
|
|
||||||
|
// private prototypes
|
||||||
|
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||||
|
static void hfp_run_for_context(hfp_connection_t *context);
|
||||||
|
static void hfp_ag_setup_audio_connection(hfp_connection_t * connection);
|
||||||
|
static void hfp_ag_hf_start_ringing(hfp_connection_t * context);
|
||||||
|
|
||||||
|
// public prototypes
|
||||||
|
hfp_generic_status_indicator_t * get_hfp_generic_status_indicators();
|
||||||
|
int get_hfp_generic_status_indicators_nr();
|
||||||
|
void set_hfp_generic_status_indicators(hfp_generic_status_indicator_t * indicators, int indicator_nr);
|
||||||
|
void set_hfp_ag_indicators(hfp_ag_indicator_t * indicators, int indicator_nr);
|
||||||
|
int get_hfp_ag_indicators_nr(hfp_connection_t * context);
|
||||||
|
hfp_ag_indicator_t * get_hfp_ag_indicators(hfp_connection_t * context);
|
||||||
|
|
||||||
|
// gobals
|
||||||
static const char default_hfp_ag_service_name[] = "Voice gateway";
|
static const char default_hfp_ag_service_name[] = "Voice gateway";
|
||||||
|
|
||||||
static uint16_t hfp_supported_features = HFP_DEFAULT_AG_SUPPORTED_FEATURES;
|
static uint16_t hfp_supported_features = HFP_DEFAULT_AG_SUPPORTED_FEATURES;
|
||||||
@ -83,17 +98,8 @@ static int hfp_ag_response_and_hold_active = 0;
|
|||||||
static hfp_phone_number_t * subscriber_numbers = NULL;
|
static hfp_phone_number_t * subscriber_numbers = NULL;
|
||||||
static int subscriber_numbers_count = 0;
|
static int subscriber_numbers_count = 0;
|
||||||
|
|
||||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
static void hfp_run_for_context(hfp_connection_t *context);
|
|
||||||
static void hfp_ag_setup_audio_connection(hfp_connection_t * connection);
|
|
||||||
static void hfp_ag_hf_start_ringing(hfp_connection_t * context);
|
|
||||||
|
|
||||||
hfp_generic_status_indicator_t * get_hfp_generic_status_indicators();
|
|
||||||
int get_hfp_generic_status_indicators_nr();
|
|
||||||
void set_hfp_generic_status_indicators(hfp_generic_status_indicator_t * indicators, int indicator_nr);
|
|
||||||
void set_hfp_ag_indicators(hfp_ag_indicator_t * indicators, int indicator_nr);
|
|
||||||
int get_hfp_ag_indicators_nr(hfp_connection_t * context);
|
|
||||||
hfp_ag_indicator_t * get_hfp_ag_indicators(hfp_connection_t * context);
|
|
||||||
|
|
||||||
hfp_ag_indicator_t * get_hfp_ag_indicators(hfp_connection_t * context){
|
hfp_ag_indicator_t * get_hfp_ag_indicators(hfp_connection_t * context){
|
||||||
// TODO: save only value, and value changed in the context?
|
// TODO: save only value, and value changed in the context?
|
||||||
@ -1969,6 +1975,10 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
hfp_run();
|
hfp_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
static void hfp_ag_set_ag_indicators(hfp_ag_indicator_t * ag_indicators, int ag_indicators_nr){
|
static void hfp_ag_set_ag_indicators(hfp_ag_indicator_t * ag_indicators, int ag_indicators_nr){
|
||||||
hfp_ag_indicators_nr = ag_indicators_nr;
|
hfp_ag_indicators_nr = ag_indicators_nr;
|
||||||
memcpy(hfp_ag_indicators, ag_indicators, ag_indicators_nr * sizeof(hfp_ag_indicator_t));
|
memcpy(hfp_ag_indicators, ag_indicators, ag_indicators_nr * sizeof(hfp_ag_indicator_t));
|
||||||
@ -1983,8 +1993,12 @@ void hfp_ag_init(uint16_t rfcomm_channel_nr, uint32_t supported_features,
|
|||||||
log_error("hfp_init: codecs_nr (%d) > HFP_MAX_NUM_CODECS (%d)", codecs_nr, HFP_MAX_NUM_CODECS);
|
log_error("hfp_init: codecs_nr (%d) > HFP_MAX_NUM_CODECS (%d)", codecs_nr, HFP_MAX_NUM_CODECS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
rfcomm_register_packet_handler(packet_handler);
|
rfcomm_register_packet_handler(packet_handler);
|
||||||
|
|
||||||
|
@ -83,6 +83,8 @@ static hfp_callheld_status_t hfp_callheld_status;
|
|||||||
|
|
||||||
static char phone_number[25];
|
static char phone_number[25];
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
void hfp_hf_register_packet_handler(hfp_callback_t callback){
|
void hfp_hf_register_packet_handler(hfp_callback_t callback){
|
||||||
hfp_callback = callback;
|
hfp_callback = callback;
|
||||||
if (callback == NULL){
|
if (callback == NULL){
|
||||||
@ -1022,6 +1024,10 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
hfp_run();
|
hfp_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
void hfp_hf_set_codecs(uint8_t * codecs, int codecs_nr){
|
void hfp_hf_set_codecs(uint8_t * codecs, int codecs_nr){
|
||||||
if (codecs_nr > HFP_MAX_NUM_CODECS){
|
if (codecs_nr > HFP_MAX_NUM_CODECS){
|
||||||
log_error("hfp_hf_set_codecs: codecs_nr (%d) > HFP_MAX_NUM_CODECS (%d)", codecs_nr, HFP_MAX_NUM_CODECS);
|
log_error("hfp_hf_set_codecs: codecs_nr (%d) > HFP_MAX_NUM_CODECS (%d)", codecs_nr, HFP_MAX_NUM_CODECS);
|
||||||
@ -1048,8 +1054,12 @@ void hfp_hf_set_codecs(uint8_t * codecs, int codecs_nr){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void hfp_hf_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, uint16_t * indicators, int indicators_nr, uint32_t indicators_status){
|
void hfp_hf_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, uint16_t * indicators, int indicators_nr, uint32_t indicators_status){
|
||||||
|
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
rfcomm_register_packet_handler(packet_handler);
|
rfcomm_register_packet_handler(packet_handler);
|
||||||
hfp_init(rfcomm_channel_nr);
|
hfp_init(rfcomm_channel_nr);
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ static uint8_t ag_send_error = 0;
|
|||||||
static uint8_t ag_num_button_press_received = 0;
|
static uint8_t ag_num_button_press_received = 0;
|
||||||
static uint8_t ag_support_custom_commands = 0;
|
static uint8_t ag_support_custom_commands = 0;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HSP_IDLE,
|
HSP_IDLE,
|
||||||
HSP_SDP_QUERY_RFCOMM_CHANNEL,
|
HSP_SDP_QUERY_RFCOMM_CHANNEL,
|
||||||
@ -237,7 +239,6 @@ int hsp_ag_send_result(char * result){
|
|||||||
return hsp_ag_send_str_over_rfcomm(rfcomm_cid, result);
|
return hsp_ag_send_str_over_rfcomm(rfcomm_cid, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void hsp_ag_reset_state(void){
|
static void hsp_ag_reset_state(void){
|
||||||
hsp_state = HSP_IDLE;
|
hsp_state = HSP_IDLE;
|
||||||
|
|
||||||
@ -256,10 +257,17 @@ static void hsp_ag_reset_state(void){
|
|||||||
ag_speaker_gain = -1;
|
ag_speaker_gain = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
void hsp_ag_init(uint8_t rfcomm_channel_nr){
|
void hsp_ag_init(uint8_t rfcomm_channel_nr){
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
rfcomm_register_packet_handler(packet_handler);
|
rfcomm_register_packet_handler(packet_handler);
|
||||||
|
@ -89,6 +89,8 @@ static uint8_t hs_send_button_press = 0;
|
|||||||
static uint8_t hs_support_custom_indications = 0;
|
static uint8_t hs_support_custom_indications = 0;
|
||||||
static uint8_t hs_outgoing_connection = 0;
|
static uint8_t hs_outgoing_connection = 0;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HSP_IDLE,
|
HSP_IDLE,
|
||||||
HSP_SDP_QUERY_RFCOMM_CHANNEL,
|
HSP_SDP_QUERY_RFCOMM_CHANNEL,
|
||||||
@ -253,10 +255,17 @@ static void hsp_hs_reset_state(void){
|
|||||||
hs_support_custom_indications = 0;
|
hs_support_custom_indications = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
void hsp_hs_init(uint8_t rfcomm_channel_nr){
|
void hsp_hs_init(uint8_t rfcomm_channel_nr){
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
rfcomm_register_packet_handler(packet_handler);
|
rfcomm_register_packet_handler(packet_handler);
|
||||||
|
@ -715,7 +715,7 @@ static void rfcomm_multiplexer_finalize(rfcomm_multiplexer_t * multiplexer){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void rfcomm_multiplexer_timer_handler(btstack_timer_source_t *timer){
|
static void rfcomm_multiplexer_timer_handler(btstack_timer_source_t *timer){
|
||||||
rfcomm_multiplexer_t * multiplexer = btstack_run_loop_get_timer_context(timer);
|
rfcomm_multiplexer_t * multiplexer = (rfcomm_multiplexer_t*) btstack_run_loop_get_timer_context(timer);
|
||||||
if (rfcomm_multiplexer_has_channels(multiplexer)) return;
|
if (rfcomm_multiplexer_has_channels(multiplexer)) return;
|
||||||
|
|
||||||
log_info("rfcomm_multiplexer_timer_handler timeout: shutting down multiplexer! (no channels)");
|
log_info("rfcomm_multiplexer_timer_handler timeout: shutting down multiplexer! (no channels)");
|
||||||
|
@ -956,9 +956,6 @@ static void l2cap_event_handler(uint8_t *packet, uint16_t size){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass on: main packet handler
|
|
||||||
(*packet_handler)(HCI_EVENT_PACKET, 0, packet, size);
|
|
||||||
|
|
||||||
l2cap_run();
|
l2cap_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ static uint8_t adv_multi_packet[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int adv_index = 0;
|
static int adv_index = 0;
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
void CHECK_EQUAL_ARRAY(const uint8_t * expected, uint8_t * actual, int size){
|
void CHECK_EQUAL_ARRAY(const uint8_t * expected, uint8_t * actual, int size){
|
||||||
for (int i=0; i<size; i++){
|
for (int i=0; i<size; i++){
|
||||||
@ -149,7 +150,8 @@ bool nameHasPrefix(const char * name_prefix, uint16_t data_length, uint8_t * dat
|
|||||||
TEST_GROUP(ADParser){
|
TEST_GROUP(ADParser){
|
||||||
void setup(void){
|
void setup(void){
|
||||||
hci_init(&dummy_transport, NULL, NULL);
|
hci_init(&dummy_transport, NULL, NULL);
|
||||||
hci_register_packet_handler(packet_handler);
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
static uint8_t advertisement_received;
|
static uint8_t advertisement_received;
|
||||||
static uint8_t connected;
|
static uint8_t connected;
|
||||||
static uint8_t advertisement_packet[150];
|
static uint8_t advertisement_packet[150];
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
void mock_simulate_hci_state_working();
|
void mock_simulate_hci_state_working();
|
||||||
void mock_simulate_command_complete(const hci_cmd_t *cmd);
|
void mock_simulate_command_complete(const hci_cmd_t *cmd);
|
||||||
@ -39,7 +40,7 @@ void CHECK_EQUAL_ARRAY(const uint8_t * expected, uint8_t * actual, int size){
|
|||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
|
|
||||||
static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
|
|
||||||
bd_addr_t address;
|
bd_addr_t address;
|
||||||
@ -77,8 +78,11 @@ TEST_GROUP(LECentral){
|
|||||||
void setup(void){
|
void setup(void){
|
||||||
advertisement_received = 0;
|
advertisement_received = 0;
|
||||||
connected = 0;
|
connected = 0;
|
||||||
|
// register for HCI events
|
||||||
|
hci_event_callback_registration.callback = &handle_hci_event;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(&handle_hci_event);
|
|
||||||
|
|
||||||
mock().expectOneCall("hci_can_send_packet_now_using_packet_buffer").andReturnValue(1);
|
mock().expectOneCall("hci_can_send_packet_now_using_packet_buffer").andReturnValue(1);
|
||||||
mock_simulate_hci_state_working();
|
mock_simulate_hci_state_working();
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include "ble/sm.h"
|
#include "ble/sm.h"
|
||||||
|
|
||||||
static btstack_packet_handler_t att_packet_handler;
|
static btstack_packet_handler_t att_packet_handler;
|
||||||
static void (*registered_l2cap_packet_handler) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL;
|
static void (*registered_hci_event_handler) (uint8_t packet_type, uint8_t *packet, uint16_t size) = NULL;
|
||||||
|
|
||||||
static btstack_linked_list_t connections;
|
static btstack_linked_list_t connections;
|
||||||
static const uint16_t max_mtu = 23;
|
static const uint16_t max_mtu = 23;
|
||||||
@ -25,22 +25,22 @@ uint16_t get_gatt_client_handle(void){
|
|||||||
|
|
||||||
void mock_simulate_command_complete(const hci_cmd_t *cmd){
|
void mock_simulate_command_complete(const hci_cmd_t *cmd){
|
||||||
uint8_t packet[] = {HCI_EVENT_COMMAND_COMPLETE, 4, 1, cmd->opcode & 0xff, cmd->opcode >> 8, 0};
|
uint8_t packet[] = {HCI_EVENT_COMMAND_COMPLETE, 4, 1, cmd->opcode & 0xff, cmd->opcode >> 8, 0};
|
||||||
registered_l2cap_packet_handler(HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet));
|
registered_hci_event_handler(HCI_EVENT_PACKET, (uint8_t *)&packet, sizeof(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mock_simulate_hci_state_working(void){
|
void mock_simulate_hci_state_working(void){
|
||||||
uint8_t packet[3] = {BTSTACK_EVENT_STATE, 0, HCI_STATE_WORKING};
|
uint8_t packet[3] = {BTSTACK_EVENT_STATE, 0, HCI_STATE_WORKING};
|
||||||
registered_l2cap_packet_handler(HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, 3);
|
registered_hci_event_handler(HCI_EVENT_PACKET, (uint8_t *)&packet, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mock_simulate_connected(void){
|
void mock_simulate_connected(void){
|
||||||
uint8_t packet[] = {0x3E, 0x13, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x50, 0x00, 0x00, 0x00, 0xD0, 0x07, 0x05};
|
uint8_t packet[] = {0x3E, 0x13, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x50, 0x00, 0x00, 0x00, 0xD0, 0x07, 0x05};
|
||||||
registered_l2cap_packet_handler(HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet));
|
registered_hci_event_handler(HCI_EVENT_PACKET, (uint8_t *)&packet, sizeof(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mock_simulate_scan_response(void){
|
void mock_simulate_scan_response(void){
|
||||||
uint8_t packet[] = {0xE2, 0x13, 0xE2, 0x01, 0x34, 0xB1, 0xF7, 0xD1, 0x77, 0x9B, 0xCC, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
uint8_t packet[] = {0xE2, 0x13, 0xE2, 0x01, 0x34, 0xB1, 0xF7, 0xD1, 0x77, 0x9B, 0xCC, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
||||||
registered_l2cap_packet_handler(HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet));
|
registered_hci_event_handler(HCI_EVENT_PACKET, (uint8_t *)&packet, sizeof(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t le_central_start_scan(void){
|
uint8_t le_central_start_scan(void){
|
||||||
@ -89,11 +89,10 @@ void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint1
|
|||||||
att_packet_handler = packet_handler;
|
att_packet_handler = packet_handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void l2cap_register_packet_handler(void (*handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){
|
void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler){
|
||||||
registered_l2cap_packet_handler = handler;
|
registered_hci_event_handler = callback_handler->callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int l2cap_reserve_packet_buffer(void){
|
int l2cap_reserve_packet_buffer(void){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ include ${BTSTACK_ROOT}/example/embedded/Makefile.inc
|
|||||||
COMMON = \
|
COMMON = \
|
||||||
sdp.c \
|
sdp.c \
|
||||||
sdp_query_rfcomm.c \
|
sdp_query_rfcomm.c \
|
||||||
|
btstack_link_key_db_memory.c \
|
||||||
btstack_linked_list.c \
|
btstack_linked_list.c \
|
||||||
btstack_memory.c \
|
btstack_memory.c \
|
||||||
btstack_memory_pool.c \
|
btstack_memory_pool.c \
|
||||||
@ -21,7 +22,6 @@ COMMON = \
|
|||||||
hci_dump.c \
|
hci_dump.c \
|
||||||
l2cap.c \
|
l2cap.c \
|
||||||
l2cap_signaling.c \
|
l2cap_signaling.c \
|
||||||
remote_device_db_memory.c \
|
|
||||||
rfcomm.c \
|
rfcomm.c \
|
||||||
sdp_client.c \
|
sdp_client.c \
|
||||||
sdp_parser.c \
|
sdp_parser.c \
|
||||||
@ -32,14 +32,14 @@ COMMON = \
|
|||||||
MOCK = \
|
MOCK = \
|
||||||
mock.c \
|
mock.c \
|
||||||
test_sequences.c \
|
test_sequences.c \
|
||||||
|
btstack_link_key_db_memory.c \
|
||||||
btstack_linked_list.c \
|
btstack_linked_list.c \
|
||||||
btstack_memory.c \
|
btstack_memory.c \
|
||||||
|
btstack_memory_pool.c \
|
||||||
|
btstack_util.c \
|
||||||
hci_cmd.c \
|
hci_cmd.c \
|
||||||
hci_dump.c \
|
hci_dump.c \
|
||||||
btstack_memory_pool.c \
|
|
||||||
remote_device_db_memory.c \
|
|
||||||
sdp_util.c \
|
sdp_util.c \
|
||||||
btstack_util.c \
|
|
||||||
|
|
||||||
COMMON_OBJ = $(COMMON:.c=.o)
|
COMMON_OBJ = $(COMMON:.c=.o)
|
||||||
MOCK_OBJ = $(MOCK:.c=.o)
|
MOCK_OBJ = $(MOCK:.c=.o)
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
|
|
||||||
#include "mock.h"
|
#include "mock.h"
|
||||||
|
|
||||||
static void *registered_sdp_app_context;
|
|
||||||
static uint8_t sdp_rfcomm_channel_nr = 1;
|
static uint8_t sdp_rfcomm_channel_nr = 1;
|
||||||
const char sdp_rfcomm_service_name[] = "BTstackMock";
|
const char sdp_rfcomm_service_name[] = "BTstackMock";
|
||||||
static uint16_t rfcomm_cid = 1;
|
static uint16_t rfcomm_cid = 1;
|
||||||
@ -71,7 +70,7 @@ static uint8_t rfcomm_reserved_buffer[1000];
|
|||||||
hfp_connection_t * hfp_context;
|
hfp_connection_t * hfp_context;
|
||||||
|
|
||||||
void (*registered_rfcomm_packet_handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
void (*registered_rfcomm_packet_handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||||
void (*registered_sdp_app_callback)(uint8_t packet_type, uint8_t *packet, uint16_t size, void * context);
|
void (*registered_sdp_app_callback)(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
|
|
||||||
uint8_t * get_rfcomm_payload(){
|
uint8_t * get_rfcomm_payload(){
|
||||||
return &rfcomm_payload[0];
|
return &rfcomm_payload[0];
|
||||||
@ -129,8 +128,7 @@ void print_without_newlines(uint8_t *data, uint16_t len){
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void l2cap_init(void){}
|
extern "C" void l2cap_init(void){}
|
||||||
|
extern "C" void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler){
|
||||||
extern "C" void l2cap_register_packet_handler(void (*handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int rfcomm_send(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){
|
int rfcomm_send(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){
|
||||||
@ -201,9 +199,8 @@ int hci_send_cmd(const hci_cmd_t *cmd, ...){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sdp_query_rfcomm_register_callback(void(*sdp_app_callback)(uint8_t packet_type, uint8_t *packet, uint16_t size, void * context), void * context){
|
void sdp_query_rfcomm_register_callback(void(*sdp_app_callback)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
|
||||||
registered_sdp_app_callback = sdp_app_callback;
|
registered_sdp_app_callback = sdp_app_callback;
|
||||||
registered_sdp_app_context = context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sdp_query_complete_response(uint8_t status){
|
static void sdp_query_complete_response(uint8_t status){
|
||||||
@ -211,7 +208,7 @@ static void sdp_query_complete_response(uint8_t status){
|
|||||||
event[0] = SDP_EVENT_QUERY_COMPLETE;
|
event[0] = SDP_EVENT_QUERY_COMPLETE;
|
||||||
event[1] = 1;
|
event[1] = 1;
|
||||||
event[2] = status;
|
event[2] = status;
|
||||||
(*registered_sdp_app_callback)(HCI_EVENT_PACKET, event, sizeof(event), registered_sdp_app_context);
|
(*registered_sdp_app_callback)(HCI_EVENT_PACKET, event, sizeof(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sdp_query_rfcomm_service_response(uint8_t status){
|
static void sdp_query_rfcomm_service_response(uint8_t status){
|
||||||
@ -222,7 +219,7 @@ static void sdp_query_rfcomm_service_response(uint8_t status){
|
|||||||
event[2] = sdp_rfcomm_channel_nr;
|
event[2] = sdp_rfcomm_channel_nr;
|
||||||
memcpy(&event[3], sdp_rfcomm_service_name, sdp_service_name_len);
|
memcpy(&event[3], sdp_rfcomm_service_name, sdp_service_name_len);
|
||||||
event[3+sdp_service_name_len] = 0;
|
event[3+sdp_service_name_len] = 0;
|
||||||
(*registered_sdp_app_callback)(HCI_EVENT_PACKET, event, sizeof(event), registered_sdp_app_context);
|
(*registered_sdp_app_callback)(HCI_EVENT_PACKET, event, sizeof(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdp_query_rfcomm_channel_and_name_for_uuid(bd_addr_t remote, uint16_t uuid){
|
void sdp_query_rfcomm_channel_and_name_for_uuid(bd_addr_t remote, uint16_t uuid){
|
||||||
|
@ -135,6 +135,8 @@ static size_t network_buffer_len = 0;
|
|||||||
|
|
||||||
static uint8_t panu_sdp_record[200];
|
static uint8_t panu_sdp_record[200];
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static uint16_t setup_ethernet_header(int src_compressed, int dst_compressed, int broadcast, uint16_t network_protocol_type){
|
static uint16_t setup_ethernet_header(int src_compressed, int dst_compressed, int broadcast, uint16_t network_protocol_type){
|
||||||
// setup packet
|
// setup packet
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
@ -782,13 +784,19 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
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 = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
/* Initialize L2CAP */
|
/* Initialize L2CAP */
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
|
|
||||||
/* Initialise BNEP */
|
/* Initialise BNEP */
|
||||||
bnep_init();
|
bnep_init();
|
||||||
|
@ -777,7 +777,6 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
hci_add_event_handler(&hci_event_callback_registration);
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(&packet_handler);
|
|
||||||
l2cap_register_fixed_channel(&packet_handler, L2CAP_CID_CONNECTIONLESS_CHANNEL);
|
l2cap_register_fixed_channel(&packet_handler, L2CAP_CID_CONNECTIONLESS_CHANNEL);
|
||||||
|
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
|
@ -70,6 +70,8 @@ static int send_err = 0;
|
|||||||
|
|
||||||
static uint8_t hfp_service_level_connection_state = 0;
|
static uint8_t hfp_service_level_connection_state = 0;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static void send_str_over_rfcomm(uint16_t cid, char * command){
|
static void send_str_over_rfcomm(uint16_t cid, char * command){
|
||||||
printf("Send %s.\n", command);
|
printf("Send %s.\n", command);
|
||||||
int err = rfcomm_send(cid, (uint8_t*) command, strlen(command));
|
int err = rfcomm_send(cid, (uint8_t*) command, strlen(command));
|
||||||
@ -139,6 +141,12 @@ static void packet_handler(void * connection, uint8_t packet_type, uint16_t chan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void handle_query_rfcomm_event(uint8_t packet_type, uint8_t *packet, uint16_t size, void * context){
|
void handle_query_rfcomm_event(uint8_t packet_type, uint8_t *packet, uint16_t size, void * context){
|
||||||
switch (event->type){
|
switch (event->type){
|
||||||
case SDP_EVENT_QUERY_RFCOMM_SERVICE:
|
case SDP_EVENT_QUERY_RFCOMM_SERVICE:
|
||||||
@ -162,9 +170,12 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
|
|
||||||
printf("Client HCI init done\r\n");
|
printf("Client HCI init done\r\n");
|
||||||
|
|
||||||
|
/* Register for HCI events */
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// init L2CAP
|
// init L2CAP
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(packet_handler);
|
|
||||||
rfcomm_init();
|
rfcomm_init();
|
||||||
rfcomm_register_packet_handler(packet_handler);
|
rfcomm_register_packet_handler(packet_handler);
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ static bd_addr_t remote = {0x84, 0x38, 0x35, 0x65, 0xD1, 0x15};
|
|||||||
static uint16_t handle;
|
static uint16_t handle;
|
||||||
static uint16_t local_cid;
|
static uint16_t local_cid;
|
||||||
|
|
||||||
|
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 packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||||
|
|
||||||
bd_addr_t event_addr;
|
bd_addr_t event_addr;
|
||||||
@ -108,6 +110,11 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||||
|
packet_handler(packet_type, 0, packet, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void show_usage(void){
|
static void show_usage(void){
|
||||||
printf("\n--- CLI for L2CAP TEST ---\n");
|
printf("\n--- CLI for L2CAP TEST ---\n");
|
||||||
printf("c - create connection to SDP at addr %s\n", bd_addr_to_str(remote));
|
printf("c - create connection to SDP at addr %s\n", bd_addr_to_str(remote));
|
||||||
@ -156,8 +163,11 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
hci_set_class_of_device(0x220404);
|
hci_set_class_of_device(0x220404);
|
||||||
hci_discoverable_control(1);
|
hci_discoverable_control(1);
|
||||||
|
|
||||||
|
/* Register for HCI events */
|
||||||
|
hci_event_callback_registration.callback = &hci_event_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(&packet_handler);
|
|
||||||
l2cap_register_service(packet_handler, PSM_SDP, 100, LEVEL_0);
|
l2cap_register_service(packet_handler, PSM_SDP, 100, LEVEL_0);
|
||||||
|
|
||||||
// turn on!
|
// turn on!
|
||||||
|
@ -90,7 +90,7 @@ extern "C" void sdp_client_query(bd_addr_t remote, uint8_t * des_serviceSearchPa
|
|||||||
void sdp_query_rfcomm_init();
|
void sdp_query_rfcomm_init();
|
||||||
|
|
||||||
|
|
||||||
void handle_query_rfcomm_event(uint8_t packet_type, uint8_t *packet, uint16_t size, void * context){
|
void handle_query_rfcomm_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
switch (packet[0]){
|
switch (packet[0]){
|
||||||
case SDP_EVENT_QUERY_RFCOMM_SERVICE:
|
case SDP_EVENT_QUERY_RFCOMM_SERVICE:
|
||||||
channel_nr[service_index] = sdp_event_query_rfcomm_service_get_rfcomm_channel(packet);
|
channel_nr[service_index] = sdp_event_query_rfcomm_service_get_rfcomm_channel(packet);
|
||||||
@ -112,7 +112,7 @@ TEST_GROUP(SDPClient){
|
|||||||
|
|
||||||
void setup(void){
|
void setup(void){
|
||||||
service_index = 0;
|
service_index = 0;
|
||||||
sdp_query_rfcomm_register_callback(handle_query_rfcomm_event, NULL);
|
sdp_query_rfcomm_register_callback(handle_query_rfcomm_event);
|
||||||
sdp_parser_init();
|
sdp_parser_init();
|
||||||
sdp_query_rfcomm_init();
|
sdp_query_rfcomm_init();
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ static void handle_sdp_parser_event(uint8_t packet_type, uint8_t *packet, uint16
|
|||||||
static uint32_t record_handle = sdp_test_record_list[0];
|
static uint32_t record_handle = sdp_test_record_list[0];
|
||||||
switch (packet[0]){
|
switch (packet[0]){
|
||||||
case SDP_EVENT_QUERY_SERVICE_RECORD_HANDLE:
|
case SDP_EVENT_QUERY_SERVICE_RECORD_HANDLE:
|
||||||
CHECK_EQUAL(sdp_query_service_record_handle_event_get_record_handle(packet), record_handle);
|
CHECK_EQUAL(sdp_event_query_service_record_handle_get_record_handle(packet), record_handle);
|
||||||
record_handle++;
|
record_handle++;
|
||||||
break;
|
break;
|
||||||
case SDP_EVENT_QUERY_COMPLETE:
|
case SDP_EVENT_QUERY_COMPLETE:
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static btstack_packet_handler_t le_data_handler;
|
static btstack_packet_handler_t le_data_handler;
|
||||||
static void (*event_packet_handler) (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL;
|
static void (*event_packet_handler) (uint8_t packet_type, uint8_t *packet, uint16_t size) = NULL;
|
||||||
|
|
||||||
static uint8_t packet_buffer[256];
|
static uint8_t packet_buffer[256];
|
||||||
static uint16_t packet_buffer_len = 0;
|
static uint16_t packet_buffer_len = 0;
|
||||||
@ -59,7 +59,7 @@ void aes128_calc_cyphertext(uint8_t key[16], uint8_t plaintext[16], uint8_t cyph
|
|||||||
void mock_simulate_hci_event(uint8_t * packet, uint16_t size){
|
void mock_simulate_hci_event(uint8_t * packet, uint16_t size){
|
||||||
hci_dump_packet(HCI_EVENT_PACKET, 1, packet, size);
|
hci_dump_packet(HCI_EVENT_PACKET, 1, packet, size);
|
||||||
if (event_packet_handler){
|
if (event_packet_handler){
|
||||||
event_packet_handler(NULL, HCI_EVENT_PACKET, NULL, packet, size);
|
event_packet_handler(HCI_EVENT_PACKET, packet, size);
|
||||||
}
|
}
|
||||||
if (le_data_handler){
|
if (le_data_handler){
|
||||||
le_data_handler(HCI_EVENT_PACKET, NULL, packet, size);
|
le_data_handler(HCI_EVENT_PACKET, NULL, packet, size);
|
||||||
@ -187,9 +187,8 @@ void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint1
|
|||||||
le_data_handler = packet_handler;
|
le_data_handler = packet_handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){
|
void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler){
|
||||||
printf("l2cap_register_packet_handler\n");
|
event_packet_handler = callback_handler->callback;
|
||||||
event_packet_handler = handler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int l2cap_reserve_packet_buffer(void){
|
int l2cap_reserve_packet_buffer(void){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user