mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-28 08:37:22 +00:00
example: add sm_pairing_central
This commit is contained in:
parent
fd30bf16b2
commit
7c485f8b45
@ -82,6 +82,7 @@ EXAMPLES = \
|
|||||||
hsp_ag_demo \
|
hsp_ag_demo \
|
||||||
hsp_hs_demo \
|
hsp_hs_demo \
|
||||||
sm_pairing_peripheral \
|
sm_pairing_peripheral \
|
||||||
|
sm_pairing_central \
|
||||||
|
|
||||||
EXAMPLES_USING_LE = \
|
EXAMPLES_USING_LE = \
|
||||||
ancs_client_demo \
|
ancs_client_demo \
|
||||||
@ -92,6 +93,7 @@ EXAMPLES_USING_LE = \
|
|||||||
spp_and_le_counter \
|
spp_and_le_counter \
|
||||||
gap_le_advertisements \
|
gap_le_advertisements \
|
||||||
sm_pairing_peripheral \
|
sm_pairing_peripheral \
|
||||||
|
sm_pairing_central \
|
||||||
|
|
||||||
# .o for .c
|
# .o for .c
|
||||||
CORE_OBJ = $(CORE:.c=.o)
|
CORE_OBJ = $(CORE:.c=.o)
|
||||||
@ -137,6 +139,9 @@ le_counter: le_counter.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ}
|
|||||||
sm_pairing_peripheral: sm_pairing_peripheral.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_REAL_OBJ} sm_pairing_peripheral.c
|
sm_pairing_peripheral: sm_pairing_peripheral.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_REAL_OBJ} sm_pairing_peripheral.c
|
||||||
${CC} $(filter-out sm_pairing_peripheral.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
${CC} $(filter-out sm_pairing_peripheral.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
||||||
|
|
||||||
|
sm_pairing_central: ${CORE_OBJ} ${COMMON_OBJ} ${SM_REAL_OBJ} ad_parser.o sm_pairing_central.o
|
||||||
|
${CC} ${CFLAGS} ${LDFLAGS} $^ -o $@
|
||||||
|
|
||||||
le_streamer: le_streamer.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_REAL_OBJ} le_streamer.c
|
le_streamer: le_streamer.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_REAL_OBJ} le_streamer.c
|
||||||
${CC} $(filter-out le_streamer.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
${CC} $(filter-out le_streamer.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
||||||
|
|
||||||
|
@ -37,10 +37,13 @@
|
|||||||
|
|
||||||
|
|
||||||
// *****************************************************************************
|
// *****************************************************************************
|
||||||
/* EXAMPLE_START(gap_le_connect_to_1111): GAP LE Advertisements Dumper
|
/* EXAMPLE_START(sm_pairing_central): LE Peripheral - Test pairing combinations
|
||||||
*
|
|
||||||
* @text This example shows how to scan and parse advertisements.
|
|
||||||
*
|
*
|
||||||
|
* @text Depending on the Authentication requiremens and IO Capabilities,
|
||||||
|
* the pairing process uses different short and long term key generation method.
|
||||||
|
* This example helps explore the different options incl. LE Secure Connections.
|
||||||
|
* It scans for advertisements and connects to the first device that lists a
|
||||||
|
* random service.
|
||||||
*/
|
*/
|
||||||
// *****************************************************************************
|
// *****************************************************************************
|
||||||
|
|
||||||
@ -53,6 +56,12 @@
|
|||||||
|
|
||||||
#include "btstack.h"
|
#include "btstack.h"
|
||||||
|
|
||||||
|
|
||||||
|
// We're looking for a remote device that lists this service in the advertisement
|
||||||
|
// LightBlue assigns 0x1111 as the UUID for a Blank service.
|
||||||
|
#define REMOTE_SERVICE 0x1111
|
||||||
|
|
||||||
|
|
||||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
static btstack_packet_callback_registration_t sm_event_callback_registration;
|
static btstack_packet_callback_registration_t sm_event_callback_registration;
|
||||||
|
|
||||||
@ -66,7 +75,7 @@ static btstack_packet_callback_registration_t sm_event_callback_registration;
|
|||||||
/* LISTING_START(GAPLEAdvSetup): Setting up GAP LE client for receiving advertisements */
|
/* LISTING_START(GAPLEAdvSetup): Setting up GAP LE client for receiving advertisements */
|
||||||
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 gap_le_connect_to_1111_setup(void){
|
static void sm_pairing_central_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);
|
||||||
|
|
||||||
@ -79,21 +88,34 @@ static void gap_le_connect_to_1111_setup(void){
|
|||||||
sm_init();
|
sm_init();
|
||||||
sm_event_callback_registration.callback = &packet_handler;
|
sm_event_callback_registration.callback = &packet_handler;
|
||||||
sm_add_event_handler(&sm_event_callback_registration);
|
sm_add_event_handler(&sm_event_callback_registration);
|
||||||
// Numeric Comparison
|
|
||||||
// sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_YES_NO);
|
/**
|
||||||
// Passkey entry initiator enter, responder displays
|
* Choose ONE of the following configurations
|
||||||
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
|
*/
|
||||||
sm_set_authentication_requirements(SM_AUTHREQ_MITM_PROTECTION);
|
|
||||||
|
// LE Legacy Pairing, Just Works
|
||||||
|
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_YES_NO);
|
||||||
|
sm_set_authentication_requirements(0);
|
||||||
|
|
||||||
|
// LE Legacy Pairing, Passkey entry initiator enter, responder (us) displays
|
||||||
|
// sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
|
||||||
|
// sm_set_authentication_requirements(SM_AUTHREQ_MITM_PROTECTION);
|
||||||
|
|
||||||
#ifdef ENABLE_LE_SECURE_CONNECTIONS
|
#ifdef ENABLE_LE_SECURE_CONNECTIONS
|
||||||
sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION|SM_AUTHREQ_MITM_PROTECTION);
|
// LE Secure Connetions, Just Works
|
||||||
// Just Works (no MITM requested)
|
// sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_YES_NO);
|
||||||
// sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION);
|
// 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);
|
||||||
|
|
||||||
|
// LE Legacy Pairing, Passkey entry initiator enter, responder (us) displays
|
||||||
|
// sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
|
||||||
|
// sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION|SM_AUTHREQ_MITM_PROTECTION);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LISTING_END */
|
|
||||||
|
|
||||||
|
|
||||||
/* LISTING_END */
|
/* LISTING_END */
|
||||||
|
|
||||||
/* @section HCI packet handler
|
/* @section HCI packet handler
|
||||||
@ -128,8 +150,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
printf("Advertisement event: addr-type %u, addr %s, data[%u] ",
|
printf("Advertisement event: addr-type %u, addr %s, data[%u] ",
|
||||||
address_type, bd_addr_to_str(address), length);
|
address_type, bd_addr_to_str(address), length);
|
||||||
printf_hexdump(data, length);
|
printf_hexdump(data, length);
|
||||||
if (!ad_data_contains_uuid16(length, (uint8_t *) data, 0x1111)) break;
|
if (!ad_data_contains_uuid16(length, (uint8_t *) data, REMOTE_SERVICE)) break;
|
||||||
printf("Found remtoe with UUID 1111, connecting...\n");
|
printf("Found remote with UUID %04x, connecting...\n", REMOTE_SERVICE);
|
||||||
gap_stop_scan();
|
gap_stop_scan();
|
||||||
gap_connect(address,address_type);
|
gap_connect(address,address_type);
|
||||||
break;
|
break;
|
||||||
@ -162,7 +184,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
int btstack_main(void);
|
int btstack_main(void);
|
||||||
int btstack_main(void)
|
int btstack_main(void)
|
||||||
{
|
{
|
||||||
gap_le_connect_to_1111_setup();
|
sm_pairing_central_setup();
|
||||||
|
|
||||||
// turn on!
|
// turn on!
|
||||||
hci_power_control(HCI_POWER_ON);
|
hci_power_control(HCI_POWER_ON);
|
@ -7,12 +7,6 @@ COMMON += hci_transport_h2_libusb.c btstack_run_loop_posix.c btstack_link_key_db
|
|||||||
|
|
||||||
include ${BTSTACK_ROOT}/example/Makefile.inc
|
include ${BTSTACK_ROOT}/example/Makefile.inc
|
||||||
|
|
||||||
# custom
|
|
||||||
EXAMPLES += gap_le_connect_to_1111
|
|
||||||
gap_le_connect_to_1111: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${SM_REAL_OBJ} ad_parser.o gap_le_connect_to_1111.c
|
|
||||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
|
||||||
|
|
||||||
|
|
||||||
# CC = gcc-fsf-4.9
|
# CC = gcc-fsf-4.9
|
||||||
CFLAGS += -g -Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Werror
|
CFLAGS += -g -Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Werror
|
||||||
# CFLAGS += -Werror
|
# CFLAGS += -Werror
|
||||||
|
Loading…
x
Reference in New Issue
Block a user