hci.c (7f839e2c2f0efc78d2cad72e87c06c3a8a705f8a) hci.c (9afaa4d426555cd46725e0caea74f010a121ef1c)
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

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

2882 // For SCO, we do the can_send_now_check here
2883 hci_notify_if_sco_can_send_now();
2884#endif
2885 }
2886 break;
2887 }
2888
2889#ifdef ENABLE_CLASSIC
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

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

2882 // For SCO, we do the can_send_now_check here
2883 hci_notify_if_sco_can_send_now();
2884#endif
2885 }
2886 break;
2887 }
2888
2889#ifdef ENABLE_CLASSIC
2890 case HCI_EVENT_FLUSH_OCCURRED:
2891 // flush occurs only if automatic flush has been enabled by gap_enable_link_watchdog()
2892 handle = hci_event_flush_occurred_get_handle(packet);
2893 conn = hci_connection_for_handle(handle);
2894 if (conn) {
2895 log_info("Flush occurred, disconnect 0x%04x", handle);
2896 conn->state = SEND_DISCONNECT;
2897 }
2898 break;
2899
2890 case HCI_EVENT_INQUIRY_COMPLETE:
2891 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_ACTIVE){
2892 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE;
2893 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0};
2894 hci_emit_event(event, sizeof(event), 1);
2895 }
2896 break;
2897 case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:

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

2953 conn->state = OPEN;
2954 conn->con_handle = little_endian_read_16(packet, 3);
2955
2956 // queue set supervision timeout if we're master
2957 if ((hci_stack->link_supervision_timeout != HCI_LINK_SUPERVISION_TIMEOUT_DEFAULT) && (conn->role == HCI_ROLE_MASTER)){
2958 connectionSetAuthenticationFlags(conn, AUTH_FLAG_WRITE_SUPERVISION_TIMEOUT);
2959 }
2960
2900 case HCI_EVENT_INQUIRY_COMPLETE:
2901 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_ACTIVE){
2902 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE;
2903 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0};
2904 hci_emit_event(event, sizeof(event), 1);
2905 }
2906 break;
2907 case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:

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

2963 conn->state = OPEN;
2964 conn->con_handle = little_endian_read_16(packet, 3);
2965
2966 // queue set supervision timeout if we're master
2967 if ((hci_stack->link_supervision_timeout != HCI_LINK_SUPERVISION_TIMEOUT_DEFAULT) && (conn->role == HCI_ROLE_MASTER)){
2968 connectionSetAuthenticationFlags(conn, AUTH_FLAG_WRITE_SUPERVISION_TIMEOUT);
2969 }
2970
2971 // queue write automatic flush timeout
2972 if (hci_stack->automatic_flush_timeout != 0){
2973 conn->gap_connection_tasks |= GAP_CONNECTION_TASK_WRITE_AUTOMATIC_FLUSH_TIMEOUT;
2974 }
2975
2961 // restart timer
2962 btstack_run_loop_set_timer(&conn->timeout, HCI_CONNECTION_TIMEOUT_MS);
2963 btstack_run_loop_add_timer(&conn->timeout);
2964
2965 // trigger remote features for dedicated bonding
2966 if ((conn->bonding_flags & BONDING_DEDICATED) != 0){
2967 hci_trigger_remote_features_for_connection(conn);
2968 }

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

3982uint8_t hci_get_allow_role_switch(void){
3983 return hci_stack->allow_role_switch;
3984}
3985
3986void gap_set_link_supervision_timeout(uint16_t link_supervision_timeout){
3987 hci_stack->link_supervision_timeout = link_supervision_timeout;
3988}
3989
2976 // restart timer
2977 btstack_run_loop_set_timer(&conn->timeout, HCI_CONNECTION_TIMEOUT_MS);
2978 btstack_run_loop_add_timer(&conn->timeout);
2979
2980 // trigger remote features for dedicated bonding
2981 if ((conn->bonding_flags & BONDING_DEDICATED) != 0){
2982 hci_trigger_remote_features_for_connection(conn);
2983 }

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

3997uint8_t hci_get_allow_role_switch(void){
3998 return hci_stack->allow_role_switch;
3999}
4000
4001void gap_set_link_supervision_timeout(uint16_t link_supervision_timeout){
4002 hci_stack->link_supervision_timeout = link_supervision_timeout;
4003}
4004
4005void gap_enable_link_watchdog(uint16_t timeout_ms){
4006 hci_stack->automatic_flush_timeout = btstack_min(timeout_ms, 1280) * 8 / 5; // divide by 0.625
4007}
4008
4009uint16_t hci_automatic_flush_timeout(void){
4010 return hci_stack->automatic_flush_timeout;
4011}
4012
3990void hci_disable_l2cap_timeout_check(void){
3991 disable_l2cap_timeouts = 1;
3992}
3993#endif
3994
3995#ifndef HAVE_HOST_CONTROLLER_API
3996// Set Public BD ADDR - passed on to Bluetooth chipset if supported in bt_control_h
3997void hci_set_bd_addr(bd_addr_t addr){

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

5644 }
5645
5646 if (connection->request_role != HCI_ROLE_INVALID){
5647 hci_role_t role = connection->request_role;
5648 connection->request_role = HCI_ROLE_INVALID;
5649 hci_send_cmd(&hci_switch_role_command, connection->address, role);
5650 return true;
5651 }
4013void hci_disable_l2cap_timeout_check(void){
4014 disable_l2cap_timeouts = 1;
4015}
4016#endif
4017
4018#ifndef HAVE_HOST_CONTROLLER_API
4019// Set Public BD ADDR - passed on to Bluetooth chipset if supported in bt_control_h
4020void hci_set_bd_addr(bd_addr_t addr){

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

5667 }
5668
5669 if (connection->request_role != HCI_ROLE_INVALID){
5670 hci_role_t role = connection->request_role;
5671 connection->request_role = HCI_ROLE_INVALID;
5672 hci_send_cmd(&hci_switch_role_command, connection->address, role);
5673 return true;
5674 }
5675
5676 if (connection->gap_connection_tasks != 0){
5677 if ((connection->gap_connection_tasks & GAP_CONNECTION_TASK_WRITE_AUTOMATIC_FLUSH_TIMEOUT) != 0){
5678 connection->gap_connection_tasks &= ~GAP_CONNECTION_TASK_WRITE_AUTOMATIC_FLUSH_TIMEOUT;
5679 hci_send_cmd(&hci_write_automatic_flush_timeout, connection->con_handle, hci_stack->automatic_flush_timeout);
5680 return true;
5681 }
5682 }
5652#endif
5653
5654#ifdef ENABLE_BLE
5655 switch (connection->le_con_parameter_update_state){
5656 // response to L2CAP CON PARAMETER UPDATE REQUEST
5657 case CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS:
5658 connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
5659 hci_send_cmd(&hci_le_connection_update, connection->con_handle, connection->le_conn_interval_min,

--- 2131 unchanged lines hidden ---
5683#endif
5684
5685#ifdef ENABLE_BLE
5686 switch (connection->le_con_parameter_update_state){
5687 // response to L2CAP CON PARAMETER UPDATE REQUEST
5688 case CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS:
5689 connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
5690 hci_send_cmd(&hci_le_connection_update, connection->con_handle, connection->le_conn_interval_min,

--- 2131 unchanged lines hidden ---