mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-26 11:37:10 +00:00
sm: replace sm_register_packet_handler with sm_add_event_handler
This commit is contained in:
parent
127fa568c1
commit
406722e45a
@ -92,6 +92,7 @@ static int att_ir_lookup_active = 0;
|
||||
static int att_handle_value_indication_handle = 0;
|
||||
static btstack_timer_source_t att_handle_value_indication_timer;
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
static btstack_packet_callback_registration_t sm_event_callback_registration;
|
||||
static btstack_packet_handler_t att_client_packet_handler = NULL;
|
||||
|
||||
static void att_handle_value_indication_notify_client(uint8_t status, uint16_t client_handle, uint16_t attribute_handle){
|
||||
@ -365,8 +366,9 @@ void att_server_init(uint8_t const * db, att_read_callback_t read_callback, att_
|
||||
hci_event_callback_registration.callback = &att_event_packet_handler2;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
||||
// SM events
|
||||
sm_register_packet_handler(att_event_packet_handler);
|
||||
// register for SM events
|
||||
sm_event_callback_registration.callback = &att_event_packet_handler2;
|
||||
sm_add_event_handler(&sm_event_callback_registration);
|
||||
|
||||
// and L2CAP ATT Server PDUs
|
||||
att_dispatch_register_server(att_packet_handler);
|
||||
|
@ -2265,10 +2265,6 @@ void sm_register_oob_data_callback( int (*get_oob_data_callback)(uint8_t addres_
|
||||
sm_get_oob_data = get_oob_data_callback;
|
||||
}
|
||||
|
||||
void sm_register_packet_handler(btstack_packet_handler_t handler){
|
||||
sm_client_packet_handler = handler;
|
||||
}
|
||||
|
||||
void sm_add_event_handler(btstack_packet_callback_registration_t * callback_handler){
|
||||
btstack_linked_list_add_tail(&sm_event_handlers, (btstack_linked_item_t*) callback_handler);
|
||||
}
|
||||
|
@ -80,12 +80,6 @@ void sm_set_ir(sm_key_t ir);
|
||||
*/
|
||||
void sm_register_oob_data_callback( int (*get_oob_data_callback)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_data));
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Registers packet handler. Called by att_server.c
|
||||
*/
|
||||
void sm_register_packet_handler(btstack_packet_handler_t handler);
|
||||
|
||||
/**
|
||||
* @brief Add event packet handler.
|
||||
*/
|
||||
|
@ -198,6 +198,9 @@ static le_characteristic_t gap_peripheral_privacy_flag_characteristic;
|
||||
static le_characteristic_t signed_write_characteristic;
|
||||
static le_service_t service;
|
||||
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
static btstack_packet_callback_registration_t sm_event_callback_registration;
|
||||
|
||||
static void show_usage();
|
||||
///
|
||||
|
||||
@ -330,7 +333,7 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
||||
case BTSTACK_EVENT_STATE:
|
||||
// bt stack activated, get started
|
||||
if (packet[2] == HCI_STATE_WORKING) {
|
||||
printf("SM Init completed\n");
|
||||
printf("Central test ready\n");
|
||||
show_usage();
|
||||
gap_run();
|
||||
}
|
||||
@ -1664,6 +1667,10 @@ static uint16_t att_read_callback(uint16_t con_handle, uint16_t attribute_handle
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void att_event_packet_handler2(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[]){
|
||||
|
||||
@ -1674,12 +1681,19 @@ int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
strcpy(gap_device_name, "BTstack");
|
||||
|
||||
// register for HCI Events
|
||||
hci_event_callback_registration.callback = &att_event_packet_handler2;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
||||
// register for SM events
|
||||
sm_event_callback_registration.callback = &att_event_packet_handler2;
|
||||
sm_add_event_handler(&sm_event_callback_registration);
|
||||
|
||||
// set up l2cap_le
|
||||
l2cap_init();
|
||||
|
||||
// Setup SM: Display only
|
||||
sm_init();
|
||||
sm_register_packet_handler(app_packet_handler);
|
||||
sm_register_oob_data_callback(get_oob_data_callback);
|
||||
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
|
||||
sm_io_capabilities = "IO_CAPABILITY_NO_INPUT_NO_OUTPUT";
|
||||
|
@ -50,7 +50,9 @@
|
||||
#include "hci.h"
|
||||
#include "btstack_debug.h"
|
||||
|
||||
uint16_t sco_handle = 0;
|
||||
static uint16_t sco_handle = 0;
|
||||
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
|
||||
static void try_send_sco(void){
|
||||
if (!sco_handle) return;
|
||||
@ -94,7 +96,8 @@ static void packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t event
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
hci_register_packet_handler(&packet_handler);
|
||||
hci_event_callback_registration.callback = &packet_handler;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
@ -108,6 +108,8 @@ uint8_t test_acl_packet_22[] = {
|
||||
|
||||
bd_addr_t test_device_addr = {0x34, 0xb1, 0xf7, 0xd1, 0x77, 0x9b};
|
||||
|
||||
static btstack_packet_callback_registration_t sm_event_callback_registration;
|
||||
|
||||
void mock_init(void);
|
||||
void mock_simulate_hci_state_working(void);
|
||||
void mock_simulate_hci_event(uint8_t * packet, uint16_t size);
|
||||
@ -157,6 +159,9 @@ void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet,
|
||||
}
|
||||
}
|
||||
|
||||
static void att_event_packet_handler2(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||
app_packet_handler(packet_type, 0, packet, size);
|
||||
}
|
||||
|
||||
void CHECK_EQUAL_ARRAY(uint8_t * expected, uint8_t * actual, int size){
|
||||
int i;
|
||||
@ -181,8 +186,8 @@ TEST_GROUP(SecurityManager){
|
||||
sm_init();
|
||||
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
|
||||
sm_set_authentication_requirements( SM_AUTHREQ_BONDING );
|
||||
sm_register_packet_handler(app_packet_handler);
|
||||
}
|
||||
sm_event_callback_registration.callback = &att_event_packet_handler2;
|
||||
sm_add_event_handler(&sm_event_callback_registration); }
|
||||
};
|
||||
|
||||
TEST(SecurityManager, MainTest){
|
||||
|
Loading…
x
Reference in New Issue
Block a user