sm.c (6bc3aba4a007d81969ae8107022ea3bb67d99778) sm.c (24c20dc492cd6244a77bb5eb27a1ad4b9bd8238e)
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

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

4358}
4359
4360static sm_connection_t * sm_get_connection_for_handle(hci_con_handle_t con_handle){
4361 hci_connection_t * hci_con = hci_connection_for_handle(con_handle);
4362 if (!hci_con) return NULL;
4363 return &hci_con->sm_connection;
4364}
4365
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

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

4358}
4359
4360static sm_connection_t * sm_get_connection_for_handle(hci_con_handle_t con_handle){
4361 hci_connection_t * hci_con = hci_connection_for_handle(con_handle);
4362 if (!hci_con) return NULL;
4363 return &hci_con->sm_connection;
4364}
4365
4366static void sm_send_security_request_for_connection(sm_connection_t * sm_conn){
4367 switch (sm_conn->sm_engine_state){
4368 case SM_GENERAL_IDLE:
4369 case SM_RESPONDER_IDLE:
4370 sm_conn->sm_engine_state = SM_RESPONDER_SEND_SECURITY_REQUEST;
4371 sm_trigger_run();
4372 break;
4373 default:
4374 break;
4375 }
4376}
4377
4378// @deprecated: map onto sm_request_pairing
4379void sm_send_security_request(hci_con_handle_t con_handle){
4380 sm_connection_t * sm_conn = sm_get_connection_for_handle(con_handle);
4381 if (!sm_conn) return;
4382 if (!IS_RESPONDER(sm_conn->sm_role)) return;
4383 sm_request_pairing(con_handle);
4384}
4385
4386// request pairing
4387void sm_request_pairing(hci_con_handle_t con_handle){
4388 sm_connection_t * sm_conn = sm_get_connection_for_handle(con_handle);
4389 if (!sm_conn) return; // wrong connection
4390
4391 log_info("sm_request_pairing in role %u, state %u", sm_conn->sm_role, sm_conn->sm_engine_state);
4392 if (IS_RESPONDER(sm_conn->sm_role)){
4366// @deprecated: map onto sm_request_pairing
4367void sm_send_security_request(hci_con_handle_t con_handle){
4368 sm_connection_t * sm_conn = sm_get_connection_for_handle(con_handle);
4369 if (!sm_conn) return;
4370 if (!IS_RESPONDER(sm_conn->sm_role)) return;
4371 sm_request_pairing(con_handle);
4372}
4373
4374// request pairing
4375void sm_request_pairing(hci_con_handle_t con_handle){
4376 sm_connection_t * sm_conn = sm_get_connection_for_handle(con_handle);
4377 if (!sm_conn) return; // wrong connection
4378
4379 log_info("sm_request_pairing in role %u, state %u", sm_conn->sm_role, sm_conn->sm_engine_state);
4380 if (IS_RESPONDER(sm_conn->sm_role)){
4393 sm_send_security_request_for_connection(sm_conn);
4381 switch (sm_conn->sm_engine_state){
4382 case SM_GENERAL_IDLE:
4383 case SM_RESPONDER_IDLE:
4384 sm_conn->sm_engine_state = SM_RESPONDER_SEND_SECURITY_REQUEST;
4385 sm_trigger_run();
4386 break;
4387 default:
4388 break;
4389 }
4394 } else {
4395 // used as a trigger to start central/master/initiator security procedures
4396 bool have_ltk;
4397 uint8_t ltk[16];
4398 switch (sm_conn->sm_engine_state){
4399 case SM_INITIATOR_CONNECTED:
4400 switch (sm_conn->sm_irk_lookup_state){
4401 case IRK_LOOKUP_SUCCEEDED:

--- 341 unchanged lines hidden ---
4390 } else {
4391 // used as a trigger to start central/master/initiator security procedures
4392 bool have_ltk;
4393 uint8_t ltk[16];
4394 switch (sm_conn->sm_engine_state){
4395 case SM_INITIATOR_CONNECTED:
4396 switch (sm_conn->sm_irk_lookup_state){
4397 case IRK_LOOKUP_SUCCEEDED:

--- 341 unchanged lines hidden ---