sm.c (7e2526228d649792ec8c08c6043488cf45d6dec2) sm.c (5611a760af48d1ce1beea59c7908be73bd2393f1)
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

--- 568 unchanged lines hidden (view full) ---

577}
578
579static void sm_address_resolution_start_lookup(uint8_t addr_type, uint16_t handle, bd_addr_t addr, address_resolution_mode_t mode, void * context){
580 memcpy(sm_address_resolution_address, addr, 6);
581 sm_address_resolution_addr_type = addr_type;
582 sm_address_resolution_test = 0;
583 sm_address_resolution_mode = mode;
584 sm_address_resolution_context = context;
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

--- 568 unchanged lines hidden (view full) ---

577}
578
579static void sm_address_resolution_start_lookup(uint8_t addr_type, uint16_t handle, bd_addr_t addr, address_resolution_mode_t mode, void * context){
580 memcpy(sm_address_resolution_address, addr, 6);
581 sm_address_resolution_addr_type = addr_type;
582 sm_address_resolution_test = 0;
583 sm_address_resolution_mode = mode;
584 sm_address_resolution_context = context;
585 sm_notify_client_base(SM_IDENTITY_RESOLVING_STARTED, handle, addr_type, addr);
585 sm_notify_client_base(SM_EVENT_IDENTITY_RESOLVING_STARTED, handle, addr_type, addr);
586}
587
588int sm_address_resolution_lookup(uint8_t address_type, bd_addr_t address){
589 // check if already in list
590 btstack_linked_list_iterator_t it;
591 sm_lookup_entry_t * entry;
592 btstack_linked_list_iterator_init(&it, &sm_address_resolution_general_queue);
593 while(btstack_linked_list_iterator_has_next(&it)){

--- 192 unchanged lines hidden (view full) ---

786
787static void sm_trigger_user_response(sm_connection_t * sm_conn){
788 // notify client for: JUST WORKS confirm, PASSKEY display or input
789 setup->sm_user_response = SM_USER_RESPONSE_IDLE;
790 switch (setup->sm_stk_generation_method){
791 case PK_RESP_INPUT:
792 if (sm_conn->sm_role){
793 setup->sm_user_response = SM_USER_RESPONSE_PENDING;
586}
587
588int sm_address_resolution_lookup(uint8_t address_type, bd_addr_t address){
589 // check if already in list
590 btstack_linked_list_iterator_t it;
591 sm_lookup_entry_t * entry;
592 btstack_linked_list_iterator_init(&it, &sm_address_resolution_general_queue);
593 while(btstack_linked_list_iterator_has_next(&it)){

--- 192 unchanged lines hidden (view full) ---

786
787static void sm_trigger_user_response(sm_connection_t * sm_conn){
788 // notify client for: JUST WORKS confirm, PASSKEY display or input
789 setup->sm_user_response = SM_USER_RESPONSE_IDLE;
790 switch (setup->sm_stk_generation_method){
791 case PK_RESP_INPUT:
792 if (sm_conn->sm_role){
793 setup->sm_user_response = SM_USER_RESPONSE_PENDING;
794 sm_notify_client_base(SM_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
794 sm_notify_client_base(SM_EVENT_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
795 } else {
795 } else {
796 sm_notify_client_passkey(SM_PASSKEY_DISPLAY_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, READ_NET_32(setup->sm_tk, 12));
796 sm_notify_client_passkey(SM_EVENT_PASSKEY_DISPLAY_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, READ_NET_32(setup->sm_tk, 12));
797 }
798 break;
799 case PK_INIT_INPUT:
800 if (sm_conn->sm_role){
797 }
798 break;
799 case PK_INIT_INPUT:
800 if (sm_conn->sm_role){
801 sm_notify_client_passkey(SM_PASSKEY_DISPLAY_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, READ_NET_32(setup->sm_tk, 12));
801 sm_notify_client_passkey(SM_EVENT_PASSKEY_DISPLAY_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, READ_NET_32(setup->sm_tk, 12));
802 } else {
803 setup->sm_user_response = SM_USER_RESPONSE_PENDING;
802 } else {
803 setup->sm_user_response = SM_USER_RESPONSE_PENDING;
804 sm_notify_client_base(SM_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
804 sm_notify_client_base(SM_EVENT_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
805 }
806 break;
807 case OK_BOTH_INPUT:
808 setup->sm_user_response = SM_USER_RESPONSE_PENDING;
805 }
806 break;
807 case OK_BOTH_INPUT:
808 setup->sm_user_response = SM_USER_RESPONSE_PENDING;
809 sm_notify_client_base(SM_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
809 sm_notify_client_base(SM_EVENT_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
810 break;
811 case JUST_WORKS:
812 setup->sm_user_response = SM_USER_RESPONSE_PENDING;
810 break;
811 case JUST_WORKS:
812 setup->sm_user_response = SM_USER_RESPONSE_PENDING;
813 sm_notify_client_base(SM_JUST_WORKS_REQUEST, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
813 sm_notify_client_base(SM_EVENT_JUST_WORKS_REQUEST, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
814 break;
815 case OOB:
816 // client already provided OOB data, let's skip notification.
817 break;
818 }
819}
820
821static int sm_key_distribution_all_received(sm_connection_t * sm_conn){

--- 148 unchanged lines hidden (view full) ---

970 }
971 break;
972 default:
973 break;
974 }
975
976 switch (event){
977 case ADDRESS_RESOLUTION_SUCEEDED:
814 break;
815 case OOB:
816 // client already provided OOB data, let's skip notification.
817 break;
818 }
819}
820
821static int sm_key_distribution_all_received(sm_connection_t * sm_conn){

--- 148 unchanged lines hidden (view full) ---

970 }
971 break;
972 default:
973 break;
974 }
975
976 switch (event){
977 case ADDRESS_RESOLUTION_SUCEEDED:
978 sm_notify_client_index(SM_IDENTITY_RESOLVING_SUCCEEDED, handle, sm_address_resolution_addr_type, sm_address_resolution_address, matched_device_id);
978 sm_notify_client_index(SM_EVENT_IDENTITY_RESOLVING_SUCCEEDED, handle, sm_address_resolution_addr_type, sm_address_resolution_address, matched_device_id);
979 break;
980 case ADDRESS_RESOLUTION_FAILED:
979 break;
980 case ADDRESS_RESOLUTION_FAILED:
981 sm_notify_client_base(SM_IDENTITY_RESOLVING_FAILED, handle, sm_address_resolution_addr_type, sm_address_resolution_address);
981 sm_notify_client_base(SM_EVENT_IDENTITY_RESOLVING_FAILED, handle, sm_address_resolution_addr_type, sm_address_resolution_address);
982 break;
983 }
984}
985
986static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){
987
988 int le_db_index = -1;
989

--- 1182 unchanged lines hidden (view full) ---

2172 break;;
2173 }
2174
2175 // received confirm value
2176 swap128(&packet[1], setup->sm_peer_confirm);
2177
2178 // notify client to hide shown passkey
2179 if (setup->sm_stk_generation_method == PK_INIT_INPUT){
982 break;
983 }
984}
985
986static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){
987
988 int le_db_index = -1;
989

--- 1182 unchanged lines hidden (view full) ---

2172 break;;
2173 }
2174
2175 // received confirm value
2176 swap128(&packet[1], setup->sm_peer_confirm);
2177
2178 // notify client to hide shown passkey
2179 if (setup->sm_stk_generation_method == PK_INIT_INPUT){
2180 sm_notify_client_base(SM_PASSKEY_DISPLAY_CANCEL, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
2180 sm_notify_client_base(SM_EVENT_PASSKEY_DISPLAY_CANCEL, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
2181 }
2182
2183 // handle user cancel pairing?
2184 if (setup->sm_user_response == SM_USER_RESPONSE_DECLINE){
2185 setup->sm_pairing_failed_reason = SM_REASON_PASSKEYT_ENTRY_FAILED;
2186 sm_conn->sm_engine_state = SM_GENERAL_SEND_PAIRING_FAILED;
2187 break;
2188 }

--- 244 unchanged lines hidden (view full) ---

2433 sm_run();
2434}
2435
2436// called by client app on authorization request
2437void sm_authorization_decline(uint16_t handle){
2438 sm_connection_t * sm_conn = sm_get_connection_for_handle(handle);
2439 if (!sm_conn) return; // wrong connection
2440 sm_conn->sm_connection_authorization_state = AUTHORIZATION_DECLINED;
2181 }
2182
2183 // handle user cancel pairing?
2184 if (setup->sm_user_response == SM_USER_RESPONSE_DECLINE){
2185 setup->sm_pairing_failed_reason = SM_REASON_PASSKEYT_ENTRY_FAILED;
2186 sm_conn->sm_engine_state = SM_GENERAL_SEND_PAIRING_FAILED;
2187 break;
2188 }

--- 244 unchanged lines hidden (view full) ---

2433 sm_run();
2434}
2435
2436// called by client app on authorization request
2437void sm_authorization_decline(uint16_t handle){
2438 sm_connection_t * sm_conn = sm_get_connection_for_handle(handle);
2439 if (!sm_conn) return; // wrong connection
2440 sm_conn->sm_connection_authorization_state = AUTHORIZATION_DECLINED;
2441 sm_notify_client_authorization(SM_AUTHORIZATION_RESULT, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, 0);
2441 sm_notify_client_authorization(SM_EVENT_AUTHORIZATION_RESULT, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, 0);
2442}
2443
2444void sm_authorization_grant(uint16_t handle){
2445 sm_connection_t * sm_conn = sm_get_connection_for_handle(handle);
2446 if (!sm_conn) return; // wrong connection
2447 sm_conn->sm_connection_authorization_state = AUTHORIZATION_GRANTED;
2442}
2443
2444void sm_authorization_grant(uint16_t handle){
2445 sm_connection_t * sm_conn = sm_get_connection_for_handle(handle);
2446 if (!sm_conn) return; // wrong connection
2447 sm_conn->sm_connection_authorization_state = AUTHORIZATION_GRANTED;
2448 sm_notify_client_authorization(SM_AUTHORIZATION_RESULT, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, 1);
2448 sm_notify_client_authorization(SM_EVENT_AUTHORIZATION_RESULT, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, 1);
2449}
2450
2451// GAP Bonding API
2452
2453void sm_bonding_decline(uint16_t handle){
2454 sm_connection_t * sm_conn = sm_get_connection_for_handle(handle);
2455 if (!sm_conn) return; // wrong connection
2456 setup->sm_user_response = SM_USER_RESPONSE_DECLINE;

--- 87 unchanged lines hidden ---
2449}
2450
2451// GAP Bonding API
2452
2453void sm_bonding_decline(uint16_t handle){
2454 sm_connection_t * sm_conn = sm_get_connection_for_handle(handle);
2455 if (!sm_conn) return; // wrong connection
2456 setup->sm_user_response = SM_USER_RESPONSE_DECLINE;

--- 87 unchanged lines hidden ---