hci.c (4dbe0476f2747f7334f34bae9fdeb5c33940f1cd) hci.c (f24eac89332f9d272f1528a9b6ca0fcd8fdd822c)
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

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

3341#ifdef ENABLE_LE_CENTRAL
3342 // handle error: error is reported only to the initiator -> outgoing connection
3343 if (status){
3344
3345 // handle cancelled outgoing connection
3346 // "If the cancellation was successful then, after the Command Complete event for the LE_Create_Connection_Cancel command,
3347 // either an LE Connection Complete or an LE Enhanced Connection Complete event shall be generated.
3348 // In either case, the event shall be sent with the error code Unknown Connection Identifier (0x02)."
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

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

3341#ifdef ENABLE_LE_CENTRAL
3342 // handle error: error is reported only to the initiator -> outgoing connection
3343 if (status){
3344
3345 // handle cancelled outgoing connection
3346 // "If the cancellation was successful then, after the Command Complete event for the LE_Create_Connection_Cancel command,
3347 // either an LE Connection Complete or an LE Enhanced Connection Complete event shall be generated.
3348 // In either case, the event shall be sent with the error code Unknown Connection Identifier (0x02)."
3349 bool connection_was_cancelled = false;
3349 if (status == ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER){
3350 if (status == ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER){
3351 connection_was_cancelled = true;
3350 // reset state
3351 hci_stack->le_connecting_state = LE_CONNECTING_IDLE;
3352 // get outgoing connection conn struct for direct connect
3353 if (hci_stack->le_connecting_request == LE_CONNECTING_DIRECT){
3354 conn = gap_get_outgoing_le_connection();
3355 conn->state = SEND_CREATE_CONNECTION;
3356 }
3357 }
3358
3359 // free connection if cancelled by user (request == IDLE)
3352 // reset state
3353 hci_stack->le_connecting_state = LE_CONNECTING_IDLE;
3354 // get outgoing connection conn struct for direct connect
3355 if (hci_stack->le_connecting_request == LE_CONNECTING_DIRECT){
3356 conn = gap_get_outgoing_le_connection();
3357 conn->state = SEND_CREATE_CONNECTION;
3358 }
3359 }
3360
3361 // free connection if cancelled by user (request == IDLE)
3360 if ((conn != NULL) && (hci_stack->le_connecting_request == LE_CONNECTING_IDLE)){
3362 bool cancelled_by_user = hci_stack->le_connecting_request == LE_CONNECTING_IDLE;
3363 if ((conn != NULL) && cancelled_by_user){
3361 // remove entry
3362 btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn);
3363 btstack_memory_hci_connection_free( conn );
3364 }
3365
3364 // remove entry
3365 btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn);
3366 btstack_memory_hci_connection_free( conn );
3367 }
3368
3366 // emit GAP_SUBEVENT_LE_CONNECTION_COMPLETE for error case
3367 hci_emit_event(gap_event, sizeof(gap_event), 1);
3369 // emit GAP_SUBEVENT_LE_CONNECTION_COMPLETE for:
3370 // - outgoing error not caused by connection cancel
3371 // - connection cancelled by user
3372 // by this, no event is emitted for intermediate connection cancel required filterlist modification
3373 if ((connection_was_cancelled == false) || cancelled_by_user){
3374 hci_emit_event(gap_event, sizeof(gap_event), 1);
3375 }
3368 return;
3369 }
3370#endif
3371
3372 // on success, both hosts receive connection complete event
3373 if (role == HCI_ROLE_MASTER){
3374#ifdef ENABLE_LE_CENTRAL
3375 // if we're master, it was an outgoing connection

--- 7433 unchanged lines hidden ---
3376 return;
3377 }
3378#endif
3379
3380 // on success, both hosts receive connection complete event
3381 if (role == HCI_ROLE_MASTER){
3382#ifdef ENABLE_LE_CENTRAL
3383 // if we're master, it was an outgoing connection

--- 7433 unchanged lines hidden ---