sm.c (7040ba26e3181cf7b9df54821f87f9b3cfa6882e) | sm.c (b96d60a6103b1a6f7c049e6b27899ce7e6965cfd) |
---|---|
1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 372 unchanged lines hidden (view full) --- 381 382// active connection - the one for which the_setup is used for 383static uint16_t sm_active_connection_handle = HCI_CON_HANDLE_INVALID; 384 385// @return 1 if oob data is available 386// stores oob data in provided 16 byte buffer if not null 387static int (*sm_get_oob_data)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_data) = NULL; 388static int (*sm_get_sc_oob_data)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_sc_peer_confirm, uint8_t * oob_sc_peer_random); | 1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 372 unchanged lines hidden (view full) --- 381 382// active connection - the one for which the_setup is used for 383static uint16_t sm_active_connection_handle = HCI_CON_HANDLE_INVALID; 384 385// @return 1 if oob data is available 386// stores oob data in provided 16 byte buffer if not null 387static int (*sm_get_oob_data)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_data) = NULL; 388static int (*sm_get_sc_oob_data)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_sc_peer_confirm, uint8_t * oob_sc_peer_random); |
389static bool (*sm_get_ltk_callback)(hci_con_handle_t con_handle, uint8_t addres_type, bd_addr_t addr, uint8_t * ltk); |
|
389 390static void sm_run(void); 391static void sm_done_for_handle(hci_con_handle_t con_handle); 392static sm_connection_t * sm_get_connection_for_handle(hci_con_handle_t con_handle); 393#ifdef ENABLE_CROSS_TRANSPORT_KEY_DERIVATION 394static sm_connection_t * sm_get_connection_for_bd_addr_and_type(bd_addr_t address, bd_addr_type_t addr_type); 395#endif 396static inline int sm_calc_actual_encryption_key_size(int other); --- 2609 unchanged lines hidden (view full) --- 3006 case SM_RESPONDER_PH2_SEND_LTK_REPLY: { 3007 sm_key_t stk_flipped; 3008 reverse_128(setup->sm_ltk, stk_flipped); 3009 connection->sm_engine_state = SM_PH2_W4_CONNECTION_ENCRYPTED; 3010 hci_send_cmd(&hci_le_long_term_key_request_reply, connection->sm_handle, stk_flipped); 3011 return; 3012 } 3013 case SM_RESPONDER_PH4_SEND_LTK_REPLY: { | 390 391static void sm_run(void); 392static void sm_done_for_handle(hci_con_handle_t con_handle); 393static sm_connection_t * sm_get_connection_for_handle(hci_con_handle_t con_handle); 394#ifdef ENABLE_CROSS_TRANSPORT_KEY_DERIVATION 395static sm_connection_t * sm_get_connection_for_bd_addr_and_type(bd_addr_t address, bd_addr_type_t addr_type); 396#endif 397static inline int sm_calc_actual_encryption_key_size(int other); --- 2609 unchanged lines hidden (view full) --- 3007 case SM_RESPONDER_PH2_SEND_LTK_REPLY: { 3008 sm_key_t stk_flipped; 3009 reverse_128(setup->sm_ltk, stk_flipped); 3010 connection->sm_engine_state = SM_PH2_W4_CONNECTION_ENCRYPTED; 3011 hci_send_cmd(&hci_le_long_term_key_request_reply, connection->sm_handle, stk_flipped); 3012 return; 3013 } 3014 case SM_RESPONDER_PH4_SEND_LTK_REPLY: { |
3015 // allow to override LTK 3016 if (sm_get_ltk_callback != NULL){ 3017 (void)(*sm_get_ltk_callback)(connection->sm_handle, connection->sm_peer_addr_type, connection->sm_peer_address, setup->sm_ltk); 3018 } |
|
3014 sm_key_t ltk_flipped; 3015 reverse_128(setup->sm_ltk, ltk_flipped); 3016 connection->sm_engine_state = SM_PH4_W4_CONNECTION_ENCRYPTED; 3017 hci_send_cmd(&hci_le_long_term_key_request_reply, connection->sm_handle, ltk_flipped); 3018 return; 3019 } 3020 3021 case SM_RESPONDER_PH0_RECEIVED_LTK_REQUEST: --- 1613 unchanged lines hidden (view full) --- 4635void sm_register_oob_data_callback( int (*get_oob_data_callback)(uint8_t address_type, bd_addr_t addr, uint8_t * oob_data)){ 4636 sm_get_oob_data = get_oob_data_callback; 4637} 4638 4639void sm_register_sc_oob_data_callback( int (*get_sc_oob_data_callback)(uint8_t address_type, bd_addr_t addr, uint8_t * oob_sc_peer_confirm, uint8_t * oob_sc_peer_random)){ 4640 sm_get_sc_oob_data = get_sc_oob_data_callback; 4641} 4642 | 3019 sm_key_t ltk_flipped; 3020 reverse_128(setup->sm_ltk, ltk_flipped); 3021 connection->sm_engine_state = SM_PH4_W4_CONNECTION_ENCRYPTED; 3022 hci_send_cmd(&hci_le_long_term_key_request_reply, connection->sm_handle, ltk_flipped); 3023 return; 3024 } 3025 3026 case SM_RESPONDER_PH0_RECEIVED_LTK_REQUEST: --- 1613 unchanged lines hidden (view full) --- 4640void sm_register_oob_data_callback( int (*get_oob_data_callback)(uint8_t address_type, bd_addr_t addr, uint8_t * oob_data)){ 4641 sm_get_oob_data = get_oob_data_callback; 4642} 4643 4644void sm_register_sc_oob_data_callback( int (*get_sc_oob_data_callback)(uint8_t address_type, bd_addr_t addr, uint8_t * oob_sc_peer_confirm, uint8_t * oob_sc_peer_random)){ 4645 sm_get_sc_oob_data = get_sc_oob_data_callback; 4646} 4647 |
4648void sm_register_ltk_callback( bool (*get_ltk_callback)(hci_con_handle_t con_handle, uint8_t address_type, bd_addr_t addr, uint8_t * ltk)){ 4649 sm_get_ltk_callback = get_ltk_callback; 4650} 4651 |
|
4643void sm_add_event_handler(btstack_packet_callback_registration_t * callback_handler){ 4644 btstack_linked_list_add_tail(&sm_event_handlers, (btstack_linked_item_t*) callback_handler); 4645} 4646 4647void sm_remove_event_handler(btstack_packet_callback_registration_t * callback_handler){ 4648 btstack_linked_list_remove(&sm_event_handlers, (btstack_linked_item_t*) callback_handler); 4649} 4650 --- 545 unchanged lines hidden --- | 4652void sm_add_event_handler(btstack_packet_callback_registration_t * callback_handler){ 4653 btstack_linked_list_add_tail(&sm_event_handlers, (btstack_linked_item_t*) callback_handler); 4654} 4655 4656void sm_remove_event_handler(btstack_packet_callback_registration_t * callback_handler){ 4657 btstack_linked_list_remove(&sm_event_handlers, (btstack_linked_item_t*) callback_handler); 4658} 4659 --- 545 unchanged lines hidden --- |