#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "ble/le_device_db.h"
#include "ble/core.h"
#include "ble/sm.h"
#include "bluetooth_company_id.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_linked_list.h"
#include "btstack_memory.h"
#include "gap.h"
#include "hci.h"
#include "hci_dump.h"
#include "l2cap.h"
Data Structures | |
struct | sm_setup_context |
Macros | |
#define | __BTSTACK_FILE__ "sm.c" |
#define | IS_RESPONDER(role) (1 || role) |
Typedefs | |
typedef struct sm_setup_context | sm_setup_context_t |
Functions | |
static void | dkg_next_state (void) |
gap_random_address_type_t | gap_random_address_get_mode (void) |
Get privacy mode. More... | |
void | gap_random_address_set (bd_addr_t addr) |
Sets a fixed random address for advertising. More... | |
void | gap_random_address_set_mode (gap_random_address_type_t random_address_type) |
Enable privacy by using random addresses. More... | |
void | gap_random_address_set_update_period (int period_ms) |
Sets update period for random address. More... | |
static void | gap_random_address_trigger (void) |
static int | gap_random_address_type_requires_updates (void) |
static void | gap_random_address_update_handler (btstack_timer_source_t *timer) |
static void | gap_random_address_update_start (void) |
static void | gap_random_address_update_stop (void) |
static void | log_info_hex16 (const char *name, uint16_t value) |
static uint8_t | own_address_type (void) |
static void | rau_next_state (void) |
void | sm_add_event_handler (btstack_packet_callback_registration_t *callback_handler) |
Add event packet handler. More... | |
static void | sm_address_resolution_handle_event (address_resolution_event_t event) |
static int | sm_address_resolution_idle (void) |
int | sm_address_resolution_lookup (uint8_t address_type, bd_addr_t address) |
static void | sm_address_resolution_start_lookup (uint8_t addr_type, hci_con_handle_t con_handle, bd_addr_t addr, address_resolution_mode_t mode, void *context) |
static void | sm_aes128_start (sm_key_t key, sm_key_t plaintext, void *context) |
static void | sm_ah_r_prime (uint8_t r[3], uint8_t *r_prime) |
void | sm_allow_ltk_reconstruction_without_le_device_db_entry (int allow) |
Allow connection re-encryption in Peripheral (Responder) role for LE Legacy Pairing without entry for Central device stored in LE Device DB. More... | |
int | sm_authenticated (hci_con_handle_t con_handle) |
Get authentication property. More... | |
void | sm_authorization_decline (hci_con_handle_t con_handle) |
Report user authorization decline. More... | |
void | sm_authorization_grant (hci_con_handle_t con_handle) |
Report user authorization grant. More... | |
authorization_state_t | sm_authorization_state (hci_con_handle_t con_handle) |
Queries authorization state. More... | |
void | sm_bonding_decline (hci_con_handle_t con_handle) |
Decline bonding triggered by event before. More... | |
static void | sm_c1_t1 (sm_key_t r, uint8_t preq[7], uint8_t pres[7], uint8_t iat, uint8_t rat, uint8_t *t1) |
static void | sm_c1_t3 (sm_key_t t2, bd_addr_t ia, bd_addr_t ra, uint8_t *t3) |
static int | sm_calc_actual_encryption_key_size (int other) |
static void | sm_d1_d_prime (uint16_t d, uint16_t r, uint8_t *d1_prime) |
static void | sm_dispatch_event (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) |
static void | sm_dm_r_prime (uint8_t r[8], uint8_t *r_prime) |
static void | sm_done_for_handle (hci_con_handle_t con_handle) |
int | sm_encryption_key_size (hci_con_handle_t con_handle) |
Get encryption key size. More... | |
static void | sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) |
static sm_connection_t * | sm_get_connection_for_handle (hci_con_handle_t con_handle) |
static void | sm_handle_encryption_result (uint8_t *data) |
static void | sm_handle_random_result (uint8_t *data) |
void | sm_init (void) |
Initializes the Security Manager, connects to L2CAP. More... | |
static void | sm_init_setup (sm_connection_t *sm_conn) |
static int | sm_is_null (uint8_t *data, int size) |
static int | sm_is_null_key (uint8_t *key) |
static int | sm_is_null_random (uint8_t random[8]) |
void | sm_just_works_confirm (hci_con_handle_t con_handle) |
Confirm Just Works bonding. More... | |
static int | sm_key_distribution_all_received (sm_connection_t *sm_conn) |
static int | sm_key_distribution_flags_for_auth_req (void) |
static int | sm_key_distribution_flags_for_set (uint8_t key_set) |
static void | sm_key_distribution_handle_all_received (sm_connection_t *sm_conn) |
void | sm_keypress_notification (hci_con_handle_t con_handle, uint8_t action) |
Send keypress notification for keyboard only devices. More... | |
int | sm_le_device_index (hci_con_handle_t con_handle) |
Identify device in LE Device DB. More... | |
static void | sm_next_responding_state (sm_connection_t *sm_conn) |
static void | sm_notify_client_authorization (uint8_t type, hci_con_handle_t con_handle, uint8_t addr_type, bd_addr_t address, uint8_t result) |
static void | sm_notify_client_base (uint8_t type, hci_con_handle_t con_handle, uint8_t addr_type, bd_addr_t address) |
static void | sm_notify_client_index (uint8_t type, hci_con_handle_t con_handle, uint8_t addr_type, bd_addr_t address, uint16_t index) |
static void | sm_notify_client_passkey (uint8_t type, hci_con_handle_t con_handle, uint8_t addr_type, bd_addr_t address, uint32_t passkey) |
void | sm_numeric_comparison_confirm (hci_con_handle_t con_handle) |
Confirm value from SM_EVENT_NUMERIC_COMPARISON_REQUEST for Numeric Comparison bonding. More... | |
static void | sm_pairing_error (sm_connection_t *sm_conn, uint8_t reason) |
void | sm_passkey_input (hci_con_handle_t con_handle, uint32_t passkey) |
Reports passkey input by user. More... | |
static void | sm_pdu_handler (uint8_t packet_type, hci_con_handle_t con_handle, uint8_t *packet, uint16_t size) |
static void | sm_pdu_received_in_wrong_state (sm_connection_t *sm_conn) |
static void | sm_random_start (void *context) |
void | sm_register_oob_data_callback (int(*get_oob_data_callback)(uint8_t addres_type, bd_addr_t addr, uint8_t *oob_data)) |
Registers OOB Data Callback. More... | |
void | sm_request_pairing (hci_con_handle_t con_handle) |
Used by att_server.c to request user authorization. More... | |
static void | sm_reset_setup (void) |
static void | sm_reset_tk (void) |
static void | sm_run (void) |
static void | sm_s1_r_prime (sm_key_t r1, sm_key_t r2, uint8_t *r_prime) |
void | sm_send_security_request (hci_con_handle_t con_handle) |
Trigger Security Request. More... | |
static void | sm_send_security_request_for_connection (sm_connection_t *sm_conn) |
void | sm_set_accepted_stk_generation_methods (uint8_t accepted_stk_generation_methods) |
Limit the STK generation methods. More... | |
void | sm_set_authentication_requirements (uint8_t auth_req) |
Sets the requested authentication requirements, bonding yes/no, MITM yes/no, SC yes/no, keypress yes/no. More... | |
void | sm_set_encryption_key_size_range (uint8_t min_size, uint8_t max_size) |
Set the accepted encryption key size range. More... | |
void | sm_set_er (sm_key_t er) |
Set secret ER key for key generation as described in Core V4.0, Vol 3, Part G, 5.2.2. More... | |
void | sm_set_io_capabilities (io_capability_t io_capability) |
Sets the available IO Capabilities. More... | |
void | sm_set_ir (sm_key_t ir) |
Set secret IR key for key generation as described in Core V4.0, Vol 3, Part G, 5.2.2. More... | |
static void | sm_setup_event_base (uint8_t *event, int event_size, uint8_t type, hci_con_handle_t con_handle, uint8_t addr_type, bd_addr_t address) |
static void | sm_setup_key_distribution (uint8_t key_set) |
static void | sm_setup_tk (void) |
static int | sm_stk_generation_init (sm_connection_t *sm_conn) |
void | sm_test_set_irk (sm_key_t irk) |
void | sm_test_use_fixed_ec_keypair (void) |
void | sm_test_use_fixed_local_csrk (void) |
static void | sm_timeout_handler (btstack_timer_source_t *timer) |
static void | sm_timeout_reset (sm_connection_t *sm_conn) |
static void | sm_timeout_start (sm_connection_t *sm_conn) |
static void | sm_timeout_stop (void) |
static void | sm_trigger_user_response (sm_connection_t *sm_conn) |
static void | sm_truncate_key (sm_key_t key, int max_encryption_size) |
void | sm_use_fixed_ec_keypair (uint8_t *qx, uint8_t *qy, uint8_t *d) |
Set Elliptic Key Public/Private Keypair. More... | |
void | sm_use_fixed_legacy_pairing_passkey_in_display_role (uint32_t passkey) |
Set passkey used with LE Legacy Pairing when we generate and show it instead of random number. More... | |
static int | sm_validate_stk_generation_method (void) |
#define __BTSTACK_FILE__ "sm.c" |
#define IS_RESPONDER | ( | role | ) | (1 || role) |
typedef struct sm_setup_context sm_setup_context_t |
enum cmac_state_t |
enum sm_aes128_state_t |
enum sm_state_var_t |
enum sm_user_response_t |
|
inlinestatic |
References dkg_state.
Referenced by sm_handle_encryption_result(), and sm_run().
gap_random_address_type_t gap_random_address_get_mode | ( | void | ) |
void gap_random_address_set | ( | bd_addr_t | addr | ) |
Sets a fixed random address for advertising.
addr |
References gap_random_address_set_mode(), GAP_RANDOM_ADDRESS_TYPE_STATIC, RAU_SET_ADDRESS, rau_state, RAU_W4_WORKING, sm_random_address, and sm_run().
void gap_random_address_set_mode | ( | gap_random_address_type_t | random_address_type | ) |
Enable privacy by using random addresses.
random_address_type | to use (incl. OFF) |
References gap_random_address_trigger(), gap_random_address_type_requires_updates(), gap_random_address_update_start(), gap_random_address_update_stop(), gap_random_adress_type, hci_le_set_own_address_type(), and own_address_type().
Referenced by gap_random_address_set().
void gap_random_address_set_update_period | ( | int | period_ms | ) |
Sets update period for random address.
period_ms | in ms |
References gap_random_address_type_requires_updates(), gap_random_address_update_start(), gap_random_address_update_stop(), and gap_random_adress_update_period.
|
static |
References log_info, RAU_GET_RANDOM, RAU_IDLE, rau_state, and sm_run().
Referenced by gap_random_address_set_mode(), and gap_random_address_update_handler().
|
static |
References GAP_RANDOM_ADDRESS_TYPE_OFF, and gap_random_adress_type.
Referenced by gap_random_address_set_mode(), and gap_random_address_set_update_period().
|
static |
References btstack_run_loop_add_timer(), btstack_run_loop_set_timer(), gap_random_address_trigger(), gap_random_adress_update_period, log_info, and UNUSED.
Referenced by gap_random_address_update_start().
|
static |
|
static |
References btstack_run_loop_remove_timer().
Referenced by gap_random_address_set_mode(), and gap_random_address_set_update_period().
|
static |
References log_info.
Referenced by sm_handle_encryption_result(), and sm_handle_random_result().
|
static |
References BD_ADDR_TYPE_LE_PUBLIC, BD_ADDR_TYPE_LE_RANDOM, GAP_RANDOM_ADDRESS_TYPE_OFF, and gap_random_adress_type.
Referenced by gap_random_address_set_mode().
|
inlinestatic |
References rau_state.
Referenced by sm_handle_encryption_result(), and sm_run().
void sm_add_event_handler | ( | btstack_packet_callback_registration_t * | callback_handler | ) |
Add event packet handler.
References btstack_linked_list_add_tail().
Referenced by att_server_init().
|
static |
References ADDRESS_RESOLUTION_FAILED, ADDRESS_RESOLUTION_FOR_CONNECTION, ADDRESS_RESOLUTION_GENERAL, ADDRESS_RESOLUTION_IDLE, ADDRESS_RESOLUTION_SUCEEDED, le_device_db_encryption_get(), log_info, NULL, sm_address_resolution_addr_type, sm_address_resolution_address, sm_address_resolution_context, sm_address_resolution_mode, sm_address_resolution_test, SM_EVENT_IDENTITY_RESOLVING_FAILED, SM_EVENT_IDENTITY_RESOLVING_SUCCEEDED, sm_is_null_key(), sm_notify_client_base(), and sm_notify_client_index().
Referenced by sm_handle_encryption_result(), and sm_run().
|
static |
References ADDRESS_RESOLUTION_IDLE, and sm_address_resolution_mode.
Referenced by sm_run().
int sm_address_resolution_lookup | ( | uint8_t | address_type, |
bd_addr_t | address | ||
) |
|
static |
|
static |
Referenced by sm_run().
void sm_allow_ltk_reconstruction_without_le_device_db_entry | ( | int | allow | ) |
Allow connection re-encryption in Peripheral (Responder) role for LE Legacy Pairing without entry for Central device stored in LE Device DB.
allow | encryption using reconstructed LTK without stored entry (Default: 1) |
References sm_reconstruct_ltk_without_le_device_db_entry.
int sm_authenticated | ( | hci_con_handle_t | con_handle | ) |
Get authentication property.
con_handle |
References sm_get_connection_for_handle().
Referenced by att_event_packet_handler().
void sm_authorization_decline | ( | hci_con_handle_t | con_handle | ) |
Report user authorization decline.
con_handle |
References SM_EVENT_AUTHORIZATION_RESULT, sm_get_connection_for_handle(), and sm_notify_client_authorization().
void sm_authorization_grant | ( | hci_con_handle_t | con_handle | ) |
Report user authorization grant.
con_handle |
References SM_EVENT_AUTHORIZATION_RESULT, sm_get_connection_for_handle(), and sm_notify_client_authorization().
authorization_state_t sm_authorization_state | ( | hci_con_handle_t | con_handle | ) |
Queries authorization state.
con_handle |
References sm_get_connection_for_handle().
Referenced by att_server_process_validated_request().
void sm_bonding_decline | ( | hci_con_handle_t | con_handle | ) |
Decline bonding triggered by event before.
con_handle |
References JUST_WORKS, NK_BOTH_INPUT, OK_BOTH_INPUT, OOB, PK_INIT_INPUT, PK_RESP_INPUT, sm_get_connection_for_handle(), sm_pairing_error(), SM_REASON_NUMERIC_COMPARISON_FAILED, SM_REASON_UNSPECIFIED_REASON, sm_run(), sm_setup_context::sm_stk_generation_method, sm_setup_context::sm_user_response, and SM_USER_RESPONSE_DECLINE.
|
static |
References log_info_key(), and reverse_56().
Referenced by sm_run().
References log_info_key().
Referenced by sm_handle_encryption_result().
|
inlinestatic |
References sm_max_encryption_key_size, and sm_min_encryption_key_size.
Referenced by sm_stk_generation_init().
|
static |
References big_endian_store_16().
Referenced by sm_run().
|
static |
References btstack_linked_list_iterator_has_next(), btstack_linked_list_iterator_init(), btstack_linked_list_iterator_next(), btstack_packet_callback_registration_t::callback, hci_dump_packet(), and UNUSED.
Referenced by sm_notify_client_authorization(), sm_notify_client_base(), sm_notify_client_index(), sm_notify_client_passkey(), and sm_pdu_handler().
|
static |
Referenced by sm_run().
|
static |
References HCI_CON_HANDLE_INVALID, log_info, sm_active_connection_handle, and sm_timeout_stop().
Referenced by sm_event_packet_handler(), sm_handle_encryption_result(), sm_pdu_handler(), sm_run(), and sm_timeout_handler().
int sm_encryption_key_size | ( | hci_con_handle_t | con_handle | ) |
Get encryption key size.
con_handle |
References sm_get_connection_for_handle().
Referenced by att_event_packet_handler().
|
static |
References BTSTACK_EVENT_STATE, btstack_event_state_get_state(), con_handle, DKG_CALC_DHK, DKG_CALC_IRK, dkg_state, EC_KEY_GENERATION_ACTIVE, EC_KEY_GENERATION_DONE, ERROR_CODE_AUTHENTICATION_FAILURE, GAP_RANDOM_ADDRESS_TYPE_OFF, GAP_RANDOM_ADDRESS_TYPE_STATIC, gap_random_adress_type, HCI_EVENT_COMMAND_COMPLETE, HCI_EVENT_DISCONNECTION_COMPLETE, HCI_EVENT_ENCRYPTION_CHANGE, HCI_EVENT_ENCRYPTION_KEY_REFRESH_COMPLETE, HCI_EVENT_IS_COMMAND_COMPLETE, HCI_EVENT_LE_META, HCI_EVENT_PACKET, hci_event_packet_get_type(), hci_le_encrypt, hci_le_rand, hci_read_bd_addr, hci_read_local_supported_commands, HCI_STATE_WORKING, HCI_SUBEVENT_LE_CONNECTION_COMPLETE, HCI_SUBEVENT_LE_GENERATE_DHKEY_COMPLETE, hci_subevent_le_generate_dhkey_complete_get_dhkey(), hci_subevent_le_generate_dhkey_complete_get_status(), HCI_SUBEVENT_LE_LONG_TERM_KEY_REQUEST, HCI_SUBEVENT_LE_READ_LOCAL_P256_PUBLIC_KEY_COMPLETE, hci_subevent_le_read_local_p256_public_key_complete_get_dhkey_x(), hci_subevent_le_read_local_p256_public_key_complete_get_dhkey_y(), hci_subevent_le_read_local_p256_public_key_complete_get_status(), IS_RESPONDER, le_device_db_remove(), le_device_db_set_local_bd_addr(), little_endian_read_16(), log_error, log_info, log_info_hexdump(), OFFSET_OF_DATA_IN_COMMAND_COMPLETE, RAU_GET_RANDOM, RAU_IDLE, RAU_SET_ADDRESS, rau_state, reverse_64(), reverse_bd_addr(), sm_active_connection_handle, sm_done_for_handle(), sm_get_connection_for_handle(), sm_handle_encryption_result(), sm_handle_random_result(), sm_is_null_random(), sm_key_distribution_all_received(), sm_key_distribution_handle_all_received(), sm_pdu_received_in_wrong_state(), sm_persistent_irk_ready, sm_reconstruct_ltk_without_le_device_db_entry, sm_run(), sm_slave_request_security, SM_STATE_VAR_DHKEY_CALCULATED, sm_setup_context::sm_state_vars, sm_setup_context::sm_use_secure_connections, and UNUSED.
Referenced by sm_init().
|
static |
References hci_connection_for_handle(), and NULL.
Referenced by sm_authenticated(), sm_authorization_decline(), sm_authorization_grant(), sm_authorization_state(), sm_bonding_decline(), sm_encryption_key_size(), sm_event_packet_handler(), sm_just_works_confirm(), sm_keypress_notification(), sm_le_device_index(), sm_passkey_input(), sm_pdu_handler(), sm_request_pairing(), sm_run(), and sm_send_security_request().
|
static |
References ADDRESS_RESOLUTION_SUCEEDED, big_endian_read_16(), CMAC_W4_MI, CMAC_W4_MLAST, CMAC_W4_SUBKEYS, dkg_next_state(), dkg_state, DKG_W4_DHK, DKG_W4_IRK, IS_RESPONDER, log_info, log_info_hex16(), log_info_key(), rau_next_state(), rau_state, RAU_W4_ENC, reverse_128(), reverse_24(), sm_address_resolution_address, sm_address_resolution_ah_calculation_active, sm_address_resolution_handle_event(), sm_address_resolution_test, sm_aes128_context, SM_AES128_IDLE, sm_aes128_state, sm_c1_t3(), sm_setup_context::sm_c1_t3_value, sm_done_for_handle(), sm_setup_context::sm_key_distribution_received_set, sm_setup_context::sm_key_distribution_send_set, SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION, sm_setup_context::sm_local_confirm, sm_setup_context::sm_local_csrk, sm_setup_context::sm_local_div, sm_setup_context::sm_local_ediv, sm_setup_context::sm_local_y, sm_setup_context::sm_ltk, sm_setup_context::sm_m_address, sm_next_responding_state(), sm_setup_context::sm_pairing_failed_reason, sm_setup_context::sm_peer_confirm, sm_persistent_dhk, sm_persistent_irk, sm_random_address, SM_REASON_CONFIRM_VALUE_FAILED, sm_setup_context::sm_s_address, sm_truncate_key(), and sm_setup_context::sm_use_secure_connections.
Referenced by sm_event_packet_handler().
|
static |
References big_endian_read_16(), big_endian_store_32(), EC_KEY_GENERATION_ACTIVE, EC_KEY_GENERATION_DONE, GAP_RANDOM_ADDRESS_NON_RESOLVABLE, GAP_RANDOM_ADDRESS_RESOLVABLE, gap_random_adress_type, IS_RESPONDER, little_endian_read_32(), log_info, log_info_hex16(), log_info_hexdump(), NULL, RAU_GET_ENC, RAU_SET_ADDRESS, rau_state, RAU_W4_RANDOM, reverse_64(), sm_fixed_legacy_pairing_passkey_in_display_role, sm_setup_context::sm_local_div, sm_setup_context::sm_local_rand, sm_setup_context::sm_local_random, sm_random_address, sm_random_context, sm_reset_tk(), sm_setup_context::sm_stk_generation_method, sm_setup_context::sm_tk, sm_trigger_user_response(), sm_setup_context::sm_use_secure_connections, sm_setup_context::sm_user_response, and SM_USER_RESPONSE_IDLE.
Referenced by sm_event_packet_handler().
void sm_init | ( | void | ) |
Initializes the Security Manager, connects to L2CAP.
References ADDRESS_RESOLUTION_IDLE, btstack_packet_callback_registration_t::callback, CMAC_IDLE, dkg_state, DKG_W4_WORKING, EC_KEY_GENERATION_IDLE, gap_random_adress_update_period, hci_add_event_handler(), HCI_CON_HANDLE_INVALID, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, l2cap_register_fixed_channel(), NULL, rau_state, RAU_W4_WORKING, sm_accepted_stk_generation_methods, sm_active_connection_handle, sm_address_resolution_ah_calculation_active, sm_address_resolution_mode, sm_address_resolution_test, SM_AES128_IDLE, sm_aes128_state, sm_event_packet_handler(), sm_fixed_legacy_pairing_passkey_in_display_role, sm_max_encryption_key_size, sm_min_encryption_key_size, sm_pdu_handler(), sm_reconstruct_ltk_without_le_device_db_entry, sm_set_er(), sm_set_ir(), SM_STK_GENERATION_METHOD_JUST_WORKS, SM_STK_GENERATION_METHOD_NUMERIC_COMPARISON, SM_STK_GENERATION_METHOD_OOB, SM_STK_GENERATION_METHOD_PASSKEY, and test_use_fixed_local_csrk.
Referenced by le_counter_setup(), le_prov_app_setup(), and tss_app_setup().
|
static |
References gap_le_get_own_address(), IS_RESPONDER, sm_auth_req, sm_get_oob_data, sm_io_capabilities, sm_key_distribution_flags_for_auth_req(), sm_setup_context::sm_m_addr_type, sm_setup_context::sm_m_address, sm_setup_context::sm_m_preq, sm_max_encryption_key_size, sm_pairing_packet_set_auth_req(), sm_pairing_packet_set_initiator_key_distribution(), sm_pairing_packet_set_io_capability(), sm_pairing_packet_set_max_encryption_key_size(), sm_pairing_packet_set_oob_data_flag(), sm_pairing_packet_set_responder_key_distribution(), sm_setup_context::sm_peer_addr_type, sm_setup_context::sm_peer_address, sm_setup_context::sm_s_addr_type, sm_setup_context::sm_s_address, sm_setup_context::sm_s_pres, and sm_setup_context::sm_tk.
Referenced by sm_run().
|
static |
Referenced by sm_is_null_key(), and sm_is_null_random().
|
static |
References sm_is_null().
Referenced by sm_address_resolution_handle_event(), sm_pdu_handler(), sm_request_pairing(), and sm_run().
|
static |
References sm_is_null().
Referenced by sm_event_packet_handler(), and sm_run().
void sm_just_works_confirm | ( | hci_con_handle_t | con_handle | ) |
Confirm Just Works bonding.
con_handle |
References sm_get_connection_for_handle(), sm_run(), sm_setup_context::sm_use_secure_connections, sm_setup_context::sm_user_response, and SM_USER_RESPONSE_CONFIRM.
Referenced by sm_numeric_comparison_confirm().
|
static |
References IS_RESPONDER, log_debug, sm_key_distribution_flags_for_set(), sm_setup_context::sm_key_distribution_received_set, sm_pairing_packet_get_initiator_key_distribution(), sm_pairing_packet_get_responder_key_distribution(), and sm_setup_context::sm_s_pres.
Referenced by sm_event_packet_handler(), sm_pdu_handler(), and sm_run().
|
static |
References sm_auth_req, SM_AUTHREQ_BONDING, SM_KEYDIST_ENC_KEY, SM_KEYDIST_ID_KEY, and SM_KEYDIST_SIGN.
Referenced by sm_init_setup(), and sm_run().
|
static |
References SM_KEYDIST_ENC_KEY, SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION, SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION, SM_KEYDIST_FLAG_IDENTITY_INFORMATION, SM_KEYDIST_FLAG_MASTER_IDENTIFICATION, SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION, SM_KEYDIST_ID_KEY, and SM_KEYDIST_SIGN.
Referenced by sm_key_distribution_all_received(), and sm_setup_key_distribution().
|
static |
References bd_addr_to_str(), BD_ADDR_TYPE_LE_PUBLIC, le_device_db_add(), le_device_db_count(), le_device_db_encryption_set(), le_device_db_info(), log_info, NULL, SM_EVENT_IDENTITY_CREATED, sm_setup_context::sm_key_distribution_received_set, sm_setup_context::sm_key_distribution_send_set, SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION, SM_KEYDIST_FLAG_IDENTITY_INFORMATION, SM_KEYDIST_FLAG_MASTER_IDENTIFICATION, SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION, sm_setup_context::sm_local_csrk, sm_setup_context::sm_ltk, sm_notify_client_index(), sm_setup_context::sm_peer_addr_type, sm_setup_context::sm_peer_address, sm_setup_context::sm_peer_csrk, sm_setup_context::sm_peer_ediv, sm_setup_context::sm_peer_irk, sm_setup_context::sm_peer_ltk, sm_setup_context::sm_peer_rand, and sm_setup_context::sm_use_secure_connections.
Referenced by sm_event_packet_handler(), sm_pdu_handler(), and sm_run().
void sm_keypress_notification | ( | hci_con_handle_t | con_handle, |
uint8_t | action | ||
) |
Send keypress notification for keyboard only devices.
con_handle | |
action | see SM_KEYPRESS_* in bluetooth.h |
References sm_get_connection_for_handle(), sm_setup_context::sm_keypress_notification, SM_KEYPRESS_PASSKEY_ENTRY_COMPLETED, and sm_run().
int sm_le_device_index | ( | hci_con_handle_t | con_handle | ) |
Identify device in LE Device DB.
handle |
References sm_get_connection_for_handle().
|
inlinestatic |
Referenced by sm_handle_encryption_result(), and sm_run().
|
static |
References HCI_EVENT_PACKET, sm_dispatch_event(), and sm_setup_event_base().
Referenced by sm_authorization_decline(), and sm_authorization_grant().
|
static |
References HCI_EVENT_PACKET, sm_dispatch_event(), and sm_setup_event_base().
Referenced by sm_address_resolution_handle_event(), sm_address_resolution_start_lookup(), sm_pdu_handler(), and sm_trigger_user_response().
|
static |
References HCI_EVENT_PACKET, le_device_db_info(), NULL, reverse_bd_addr(), sm_dispatch_event(), and sm_setup_event_base().
Referenced by sm_address_resolution_handle_event(), and sm_key_distribution_handle_all_received().
|
static |
References HCI_EVENT_PACKET, little_endian_store_32(), sm_dispatch_event(), and sm_setup_event_base().
Referenced by sm_trigger_user_response().
void sm_numeric_comparison_confirm | ( | hci_con_handle_t | con_handle | ) |
Confirm value from SM_EVENT_NUMERIC_COMPARISON_REQUEST for Numeric Comparison bonding.
con_handle |
References sm_just_works_confirm().
|
static |
References sm_setup_context::sm_pairing_failed_reason.
Referenced by sm_bonding_decline(), and sm_pdu_received_in_wrong_state().
void sm_passkey_input | ( | hci_con_handle_t | con_handle, |
uint32_t | passkey | ||
) |
Reports passkey input by user.
con_handle | |
passkey | in [0..999999] |
References big_endian_store_32(), sm_get_connection_for_handle(), sm_reset_tk(), sm_run(), sm_setup_context::sm_tk, sm_setup_context::sm_user_response, and SM_USER_RESPONSE_PASSKEY.
|
static |
References HCI_EVENT_PACKET, IS_RESPONDER, JUST_WORKS, L2CAP_EVENT_CAN_SEND_NOW, le_device_db_encryption_get(), little_endian_read_16(), little_endian_store_16(), log_debug, log_error, log_info, NK_BOTH_INPUT, NULL, OK_BOTH_INPUT, OOB, PK_INIT_INPUT, PK_RESP_INPUT, reverse_128(), reverse_256(), reverse_64(), reverse_bd_addr(), SM_CODE_ENCRYPTION_INFORMATION, SM_CODE_IDENTITY_ADDRESS_INFORMATION, SM_CODE_IDENTITY_INFORMATION, SM_CODE_KEYPRESS_NOTIFICATION, SM_CODE_MASTER_IDENTIFICATION, SM_CODE_PAIRING_CONFIRM, SM_CODE_PAIRING_DHKEY_CHECK, SM_CODE_PAIRING_FAILED, SM_CODE_PAIRING_PUBLIC_KEY, SM_CODE_PAIRING_RANDOM, SM_CODE_PAIRING_REQUEST, SM_CODE_PAIRING_RESPONSE, SM_CODE_SECURITY_REQUEST, SM_CODE_SIGNING_INFORMATION, SM_DATA_PACKET, sm_dispatch_event(), sm_done_for_handle(), SM_EVENT_KEYPRESS_NOTIFICATION, SM_EVENT_PASSKEY_DISPLAY_CANCEL, sm_get_connection_for_handle(), sm_is_null_key(), sm_key_distribution_all_received(), sm_key_distribution_handle_all_received(), sm_setup_context::sm_key_distribution_received_set, SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION, SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION, SM_KEYDIST_FLAG_IDENTITY_INFORMATION, SM_KEYDIST_FLAG_MASTER_IDENTIFICATION, SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION, sm_notify_client_base(), sm_setup_context::sm_pairing_failed_reason, sm_pdu_received_in_wrong_state(), sm_setup_context::sm_peer_addr_type, sm_setup_context::sm_peer_address, sm_setup_context::sm_peer_confirm, sm_setup_context::sm_peer_csrk, sm_setup_context::sm_peer_ediv, sm_setup_context::sm_peer_irk, sm_setup_context::sm_peer_ltk, sm_setup_context::sm_peer_rand, sm_setup_context::sm_peer_random, SM_REASON_PASSKEYT_ENTRY_FAILED, sm_run(), sm_setup_context::sm_s_pres, SM_STATE_VAR_DHKEY_COMMAND_RECEIVED, SM_STATE_VAR_DHKEY_NEEDED, sm_setup_context::sm_state_vars, sm_stk_generation_init(), sm_setup_context::sm_stk_generation_method, sm_trigger_user_response(), sm_setup_context::sm_use_secure_connections, sm_setup_context::sm_user_response, SM_USER_RESPONSE_DECLINE, SM_USER_RESPONSE_IDLE, SM_USER_RESPONSE_PASSKEY, SM_USER_RESPONSE_PENDING, and UNUSED.
Referenced by sm_init().
|
inlinestatic |
References sm_pairing_error(), and SM_REASON_UNSPECIFIED_REASON.
Referenced by sm_event_packet_handler(), and sm_pdu_handler().
|
static |
References hci_le_rand, hci_send_cmd(), and sm_random_context.
Referenced by sm_run().
void sm_register_oob_data_callback | ( | int(*)(uint8_t addres_type, bd_addr_t addr, uint8_t *oob_data) | get_oob_data_callback | ) |
Registers OOB Data Callback.
The callback should set the oob_data and return 1 if OOB data is availble
get_oob_data_callback |
References sm_get_oob_data.
void sm_request_pairing | ( | hci_con_handle_t | con_handle | ) |
Used by att_server.c to request user authorization.
con_handle |
References IS_RESPONDER, le_device_db_encryption_get(), log_info, NULL, sm_get_connection_for_handle(), sm_is_null_key(), sm_run(), and sm_send_security_request_for_connection().
Referenced by att_server_process_validated_request().
|
static |
References sm_setup_context::sm_keypress_notification, sm_reset_tk(), and sm_setup_context::sm_state_vars.
Referenced by sm_run().
|
static |
References sm_setup_context::sm_tk.
Referenced by sm_handle_random_result(), sm_passkey_input(), sm_reset_setup(), and sm_setup_tk().
|
static |
References sm_lookup_entry_t::address, ADDRESS_RESOLUTION_FAILED, ADDRESS_RESOLUTION_FOR_CONNECTION, ADDRESS_RESOLUTION_GENERAL, ADDRESS_RESOLUTION_SUCEEDED, sm_lookup_entry_t::address_type, bd_addr_to_str(), big_endian_read_32(), btstack_linked_list_empty(), btstack_linked_list_iterator_has_next(), btstack_linked_list_iterator_next(), btstack_linked_list_remove(), buffer, CMAC_CALC_MI, CMAC_CALC_MLAST, CMAC_CALC_SUBKEYS, DKG_CALC_DHK, DKG_CALC_IRK, dkg_next_state(), dkg_state, EC_KEY_GENERATION_ACTIVE, EC_KEY_GENERATION_W4_KEY, gap_le_get_own_address(), gap_local_bd_addr(), gap_random_address_get_mode(), GAP_RANDOM_ADDRESS_NON_RESOLVABLE, GAP_RANDOM_ADDRESS_RESOLVABLE, GAP_RANDOM_ADDRESS_TYPE_OFF, GAP_RANDOM_ADDRESS_TYPE_STATIC, hci_can_send_command_packet_now(), HCI_CON_HANDLE_INVALID, hci_connections_get_iterator(), hci_get_state(), hci_le_generate_dhkey, hci_le_long_term_key_negative_reply, hci_le_long_term_key_request_reply, hci_le_read_local_p256_public_key, hci_le_set_random_address, hci_le_start_encryption, hci_send_cmd(), HCI_STATE_WORKING, IS_RESPONDER, JUST_WORKS, l2cap_can_send_fixed_channel_packet_now(), L2CAP_CID_SECURITY_MANAGER_PROTOCOL, l2cap_request_can_send_fix_channel_now_event(), l2cap_send_connectionless(), le_device_db_count(), le_device_db_info(), little_endian_store_16(), log_info, log_info_key(), NK_BOTH_INPUT, NULL, OK_BOTH_INPUT, OOB, PK_INIT_INPUT, PK_RESP_INPUT, RAU_GET_ENC, RAU_GET_RANDOM, RAU_IDLE, rau_next_state(), RAU_SET_ADDRESS, rau_state, reverse_128(), reverse_256(), reverse_64(), reverse_bd_addr(), sm_active_connection_handle, sm_address_resolution_addr_type, sm_address_resolution_address, sm_address_resolution_ah_calculation_active, sm_address_resolution_context, sm_address_resolution_handle_event(), sm_address_resolution_idle(), sm_address_resolution_start_lookup(), sm_address_resolution_test, SM_AES128_ACTIVE, SM_AES128_IDLE, sm_aes128_start(), sm_aes128_state, sm_ah_r_prime(), SM_AUTHREQ_BONDING, sm_c1_t1(), sm_setup_context::sm_c1_t3_value, sm_cmac_ready(), SM_CODE_ENCRYPTION_INFORMATION, SM_CODE_IDENTITY_ADDRESS_INFORMATION, SM_CODE_IDENTITY_INFORMATION, SM_CODE_KEYPRESS_NOTIFICATION, SM_CODE_MASTER_IDENTIFICATION, SM_CODE_PAIRING_CONFIRM, SM_CODE_PAIRING_DHKEY_CHECK, SM_CODE_PAIRING_FAILED, SM_CODE_PAIRING_PUBLIC_KEY, SM_CODE_PAIRING_RANDOM, SM_CODE_PAIRING_REQUEST, SM_CODE_PAIRING_RESPONSE, SM_CODE_SECURITY_REQUEST, SM_CODE_SIGNING_INFORMATION, sm_d1_d_prime(), sm_dm_r_prime(), sm_done_for_handle(), sm_get_connection_for_handle(), sm_init_setup(), sm_is_null_key(), sm_is_null_random(), sm_key_distribution_all_received(), sm_key_distribution_flags_for_auth_req(), sm_key_distribution_handle_all_received(), sm_setup_context::sm_key_distribution_send_set, SM_KEYDIST_ENC_KEY, SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION, SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION, SM_KEYDIST_FLAG_IDENTITY_INFORMATION, SM_KEYDIST_FLAG_MASTER_IDENTIFICATION, SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION, sm_setup_context::sm_keypress_notification, sm_setup_context::sm_local_confirm, sm_setup_context::sm_local_csrk, sm_setup_context::sm_local_div, sm_setup_context::sm_local_ediv, sm_setup_context::sm_local_rand, sm_setup_context::sm_local_random, sm_setup_context::sm_ltk, sm_setup_context::sm_m_addr_type, sm_setup_context::sm_m_preq, sm_next_responding_state(), sm_setup_context::sm_pairing_failed_reason, sm_pairing_packet_get_initiator_key_distribution(), sm_pairing_packet_get_responder_key_distribution(), sm_pairing_packet_set_code(), sm_pairing_packet_set_initiator_key_distribution(), sm_pairing_packet_set_responder_key_distribution(), sm_setup_context::sm_peer_ediv, sm_setup_context::sm_peer_ltk, sm_setup_context::sm_peer_rand, sm_setup_context::sm_peer_random, sm_persistent_dhk, sm_persistent_er, sm_persistent_ir, sm_persistent_irk, sm_random_address, sm_random_start(), sm_reset_setup(), sm_s1_r_prime(), sm_setup_context::sm_s_addr_type, sm_setup_context::sm_s_pres, sm_setup_key_distribution(), SM_STATE_VAR_DHKEY_NEEDED, sm_setup_context::sm_state_vars, sm_stk_generation_init(), sm_setup_context::sm_stk_generation_method, sm_timeout_reset(), sm_timeout_start(), sm_setup_context::sm_tk, sm_trigger_user_response(), sm_setup_context::sm_use_secure_connections, test_use_fixed_local_csrk, and UNUSED.
Referenced by gap_random_address_set(), gap_random_address_trigger(), sm_address_resolution_lookup(), sm_bonding_decline(), sm_event_packet_handler(), sm_just_works_confirm(), sm_keypress_notification(), sm_passkey_input(), sm_pdu_handler(), sm_request_pairing(), sm_send_security_request_for_connection(), and sm_timeout_handler().
References log_info_key().
Referenced by sm_run().
void sm_send_security_request | ( | hci_con_handle_t | con_handle | ) |
Trigger Security Request.
References sm_get_connection_for_handle(), and sm_send_security_request_for_connection().
Referenced by handle_hci_event().
|
static |
References sm_run().
Referenced by sm_request_pairing(), and sm_send_security_request().
void sm_set_accepted_stk_generation_methods | ( | uint8_t | accepted_stk_generation_methods | ) |
Limit the STK generation methods.
Bonding is stopped if the resulting one isn't in the list
OR | combination of SM_STK_GENERATION_METHOD_ |
References sm_accepted_stk_generation_methods.
void sm_set_authentication_requirements | ( | uint8_t | auth_req | ) |
Sets the requested authentication requirements, bonding yes/no, MITM yes/no, SC yes/no, keypress yes/no.
OR | combination of SM_AUTHREQ_ flags |
References log_error, sm_auth_req, and SM_AUTHREQ_SECURE_CONNECTION.
void sm_set_encryption_key_size_range | ( | uint8_t | min_size, |
uint8_t | max_size | ||
) |
Set the accepted encryption key size range.
Bonding is stopped if the result isn't within the range
min_size | (default 7) |
max_size | (default 16) |
References sm_max_encryption_key_size, and sm_min_encryption_key_size.
void sm_set_er | ( | sm_key_t | er | ) |
Set secret ER key for key generation as described in Core V4.0, Vol 3, Part G, 5.2.2.
er |
References sm_persistent_er.
Referenced by sm_init().
void sm_set_io_capabilities | ( | io_capability_t | io_capability | ) |
void sm_set_ir | ( | sm_key_t | ir | ) |
Set secret IR key for key generation as described in Core V4.0, Vol 3, Part G, 5.2.2.
References sm_persistent_ir.
Referenced by sm_init().
|
static |
References little_endian_store_16(), and reverse_bd_addr().
Referenced by sm_notify_client_authorization(), sm_notify_client_base(), sm_notify_client_index(), and sm_notify_client_passkey().
|
static |
References sm_key_distribution_flags_for_set(), sm_setup_context::sm_key_distribution_received_set, and sm_setup_context::sm_key_distribution_send_set.
Referenced by sm_run(), and sm_stk_generation_init().
|
static |
References IO_CAPABILITY_KEYBOARD_DISPLAY, JUST_WORKS, log_info, log_info_key(), OOB, SM_AUTHREQ_MITM_PROTECTION, SM_AUTHREQ_SECURE_CONNECTION, sm_setup_context::sm_m_preq, sm_pairing_packet_get_auth_req(), sm_pairing_packet_get_io_capability(), sm_pairing_packet_get_oob_data_flag(), sm_reset_tk(), sm_setup_context::sm_s_pres, sm_setup_context::sm_stk_generation_method, sm_setup_context::sm_tk, sm_setup_context::sm_use_secure_connections, and stk_generation_method.
Referenced by sm_stk_generation_init().
|
static |
References IS_RESPONDER, JUST_WORKS, log_info, sm_calc_actual_encryption_key_size(), sm_setup_context::sm_m_preq, sm_pairing_packet_get_initiator_key_distribution(), sm_pairing_packet_get_max_encryption_key_size(), sm_pairing_packet_get_responder_key_distribution(), SM_REASON_AUTHENTHICATION_REQUIREMENTS, SM_REASON_ENCRYPTION_KEY_SIZE, sm_setup_context::sm_s_pres, sm_setup_key_distribution(), sm_setup_tk(), sm_setup_context::sm_stk_generation_method, and sm_validate_stk_generation_method().
Referenced by sm_pdu_handler(), and sm_run().
void sm_test_set_irk | ( | sm_key_t | irk | ) |
References sm_persistent_irk, and sm_persistent_irk_ready.
void sm_test_use_fixed_ec_keypair | ( | void | ) |
References EC_KEY_GENERATION_DONE.
void sm_test_use_fixed_local_csrk | ( | void | ) |
References test_use_fixed_local_csrk.
|
static |
References btstack_run_loop_get_timer_context(), log_info, sm_done_for_handle(), and sm_run().
Referenced by sm_timeout_start().
|
static |
References sm_timeout_start(), and sm_timeout_stop().
Referenced by sm_run().
|
static |
|
static |
References btstack_run_loop_remove_timer(), and sm_setup_context::sm_timeout.
Referenced by sm_done_for_handle(), and sm_timeout_reset().
|
static |
References big_endian_read_32(), IS_RESPONDER, JUST_WORKS, NK_BOTH_INPUT, OK_BOTH_INPUT, OOB, PK_INIT_INPUT, PK_RESP_INPUT, SM_EVENT_JUST_WORKS_REQUEST, SM_EVENT_NUMERIC_COMPARISON_REQUEST, SM_EVENT_PASSKEY_DISPLAY_NUMBER, SM_EVENT_PASSKEY_INPUT_NUMBER, sm_notify_client_base(), sm_notify_client_passkey(), sm_setup_context::sm_stk_generation_method, sm_setup_context::sm_tk, sm_setup_context::sm_user_response, SM_USER_RESPONSE_IDLE, and SM_USER_RESPONSE_PENDING.
Referenced by sm_handle_random_result(), sm_pdu_handler(), and sm_run().
|
static |
Referenced by sm_handle_encryption_result().
void sm_use_fixed_ec_keypair | ( | uint8_t * | qx, |
uint8_t * | qy, | ||
uint8_t * | d | ||
) |
Set Elliptic Key Public/Private Keypair.
qx | 32 bytes |
qy | 32 bytes |
d | 32 bytes |
References EC_KEY_GENERATION_DONE, and UNUSED.
void sm_use_fixed_legacy_pairing_passkey_in_display_role | ( | uint32_t | passkey | ) |
Set passkey used with LE Legacy Pairing when we generate and show it instead of random number.
passkey |
References sm_fixed_legacy_pairing_passkey_in_display_role.
|
static |
References JUST_WORKS, NK_BOTH_INPUT, OK_BOTH_INPUT, OOB, PK_INIT_INPUT, PK_RESP_INPUT, sm_accepted_stk_generation_methods, sm_setup_context::sm_stk_generation_method, SM_STK_GENERATION_METHOD_JUST_WORKS, SM_STK_GENERATION_METHOD_NUMERIC_COMPARISON, SM_STK_GENERATION_METHOD_OOB, and SM_STK_GENERATION_METHOD_PASSKEY.
Referenced by sm_stk_generation_init().
|
static |
Referenced by dkg_next_state(), sm_event_packet_handler(), sm_handle_encryption_result(), sm_init(), and sm_run().
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Referenced by uhd_ctrl_phase_setup().
|
static |
Referenced by sm_init(), sm_set_accepted_stk_generation_methods(), and sm_validate_stk_generation_method().
|
static |
Referenced by sm_done_for_handle(), sm_event_packet_handler(), sm_init(), and sm_run().
|
static |
Referenced by sm_address_resolution_handle_event(), sm_address_resolution_start_lookup(), and sm_run().
|
static |
|
static |
Referenced by sm_handle_encryption_result(), sm_init(), and sm_run().
|
static |
Referenced by sm_address_resolution_handle_event(), sm_address_resolution_start_lookup(), and sm_run().
|
static |
|
static |
|
static |
|
static |
Referenced by sm_aes128_start(), and sm_handle_encryption_result().
|
static |
Referenced by sm_aes128_start(), sm_handle_encryption_result(), sm_init(), and sm_run().
|
static |
Referenced by sm_init_setup(), sm_key_distribution_flags_for_auth_req(), and sm_set_authentication_requirements().
|
static |
|
static |
Referenced by sm_handle_random_result(), sm_init(), and sm_use_fixed_legacy_pairing_passkey_in_display_role().
Referenced by sm_init_setup(), and sm_register_oob_data_callback().
|
static |
Referenced by sm_init_setup(), and sm_set_io_capabilities().
|
static |
Referenced by sm_calc_actual_encryption_key_size(), sm_init(), sm_init_setup(), and sm_set_encryption_key_size_range().
|
static |
Referenced by sm_calc_actual_encryption_key_size(), sm_init(), and sm_set_encryption_key_size_range().
|
static |
|
static |
Referenced by sm_handle_encryption_result(), and sm_run().
|
static |
Referenced by sm_run(), and sm_set_er().
|
static |
Referenced by sm_run(), and sm_set_ir().
|
static |
Referenced by sm_handle_encryption_result(), sm_run(), and sm_test_set_irk().
|
static |
Referenced by sm_event_packet_handler(), and sm_test_set_irk().
|
static |
Referenced by gap_random_address_set(), sm_handle_encryption_result(), sm_handle_random_result(), and sm_run().
|
static |
Referenced by sm_handle_random_result(), and sm_random_start().
|
static |
Referenced by sm_allow_ltk_reconstruction_without_le_device_db_entry(), sm_event_packet_handler(), and sm_init().
|
static |
Referenced by sm_event_packet_handler().
|
static |
Referenced by sm_setup_tk().
|
static |
Referenced by sm_init(), sm_run(), and sm_test_use_fixed_local_csrk().
|
static |