mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-21 12:40:42 +00:00
example: handle SM_EVENT_REENCRYPTION_COMPLETE
This commit is contained in:
parent
689e7fb3f6
commit
3f6e1c8176
@ -538,6 +538,8 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
|
||||
if (packet_type != HCI_EVENT_PACKET) return;
|
||||
|
||||
bool connect_to_service = false;
|
||||
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
case SM_EVENT_JUST_WORKS_REQUEST:
|
||||
printf("Just works requested\n");
|
||||
@ -554,10 +556,7 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
switch (sm_event_pairing_complete_get_status(packet)){
|
||||
case ERROR_CODE_SUCCESS:
|
||||
printf("Pairing complete, success\n");
|
||||
// continue - query primary services
|
||||
printf("Search for HID service.\n");
|
||||
app_state = W4_HID_SERVICE_FOUND;
|
||||
gatt_client_discover_primary_services_by_uuid16(handle_gatt_client_event, connection_handle, ORG_BLUETOOTH_SERVICE_HUMAN_INTERFACE_DEVICE);
|
||||
connect_to_service = true;
|
||||
break;
|
||||
case ERROR_CODE_CONNECTION_TIMEOUT:
|
||||
printf("Pairing failed, timeout\n");
|
||||
@ -572,9 +571,20 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SM_EVENT_REENCRYPTION_COMPLETE:
|
||||
printf("Re-encryption complete, success\n");
|
||||
connect_to_service = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (connect_to_service){
|
||||
// continue - query primary services
|
||||
printf("Search for HID service.\n");
|
||||
app_state = W4_HID_SERVICE_FOUND;
|
||||
gatt_client_discover_primary_services_by_uuid16(handle_gatt_client_event, connection_handle, ORG_BLUETOOTH_SERVICE_HUMAN_INTERFACE_DEVICE);
|
||||
}
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
@ -586,6 +596,16 @@ int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
/* LISTING_START(HogBootHostSetup): HID-over-GATT Boot Host Setup */
|
||||
|
||||
l2cap_init();
|
||||
|
||||
// setup SM: Display only
|
||||
sm_init();
|
||||
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
|
||||
sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION | SM_AUTHREQ_BONDING);
|
||||
|
||||
//
|
||||
gatt_client_init();
|
||||
|
||||
// register for events from HCI
|
||||
hci_event_callback_registration.callback = &packet_handler;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
@ -594,11 +614,6 @@ int btstack_main(int argc, const char * argv[]){
|
||||
sm_event_callback_registration.callback = &sm_packet_handler;
|
||||
sm_add_event_handler(&sm_event_callback_registration);
|
||||
|
||||
//
|
||||
l2cap_init();
|
||||
sm_init();
|
||||
gatt_client_init();
|
||||
|
||||
/* LISTING_END */
|
||||
|
||||
// Disable stdout buffering
|
||||
|
@ -456,6 +456,8 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
|
||||
if (packet_type != HCI_EVENT_PACKET) return;
|
||||
|
||||
bool connect_to_service = false;
|
||||
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
case SM_EVENT_JUST_WORKS_REQUEST:
|
||||
printf("Just works requested\n");
|
||||
@ -472,11 +474,7 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
switch (sm_event_pairing_complete_get_status(packet)){
|
||||
case ERROR_CODE_SUCCESS:
|
||||
printf("Pairing complete, success\n");
|
||||
|
||||
// continue - query primary services
|
||||
printf("Search for HID service.\n");
|
||||
app_state = W4_HID_CLIENT_CONNECTED;
|
||||
hids_client_connect(connection_handle, handle_gatt_client_event, protocol_mode, &hids_cid);
|
||||
connect_to_service = true;
|
||||
break;
|
||||
case ERROR_CODE_CONNECTION_TIMEOUT:
|
||||
printf("Pairing failed, timeout\n");
|
||||
@ -491,9 +489,20 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SM_EVENT_REENCRYPTION_COMPLETE:
|
||||
printf("Re-encryption complete, success\n");
|
||||
connect_to_service = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (connect_to_service){
|
||||
// continue - query primary services
|
||||
printf("Search for HID service.\n");
|
||||
app_state = W4_HID_CLIENT_CONNECTED;
|
||||
hids_client_connect(connection_handle, handle_gatt_client_event, protocol_mode, &hids_cid);
|
||||
}
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
@ -505,6 +514,21 @@ int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
/* LISTING_START(HogBootHostSetup): HID-over-GATT Host Setup */
|
||||
|
||||
l2cap_init();
|
||||
|
||||
// setup SM: Display only
|
||||
sm_init();
|
||||
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
|
||||
sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION | SM_AUTHREQ_BONDING);
|
||||
|
||||
//
|
||||
gatt_client_init();
|
||||
|
||||
// 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);
|
||||
|
||||
hids_client_init(hid_descriptor_storage, sizeof(hid_descriptor_storage));
|
||||
|
||||
// register for events from HCI
|
||||
hci_event_callback_registration.callback = &packet_handler;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
@ -512,16 +536,7 @@ int btstack_main(int argc, const char * argv[]){
|
||||
// register for events from Security Manager
|
||||
sm_event_callback_registration.callback = &sm_packet_handler;
|
||||
sm_add_event_handler(&sm_event_callback_registration);
|
||||
|
||||
//
|
||||
l2cap_init();
|
||||
sm_init();
|
||||
gatt_client_init();
|
||||
|
||||
// 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);
|
||||
|
||||
hids_client_init(hid_descriptor_storage, sizeof(hid_descriptor_storage));
|
||||
sm_set_authentication_requirements( SM_AUTHREQ_BONDING);
|
||||
|
||||
/* LISTING_END */
|
||||
|
||||
|
@ -463,6 +463,10 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SM_EVENT_REENCRYPTION_COMPLETE:
|
||||
connection_handle = sm_event_reencryption_complete_get_handle(packet);
|
||||
printf("[-] %s Re-encryption complete, success\n", mitm_name_for_handle(connection_handle));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user