hci.c (1c79b5e3cce0347141c6d999c2c0b5b090595be5) hci.c (88a03c8d0148d7fc90fe73b0a91b480a1329aab2)
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

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

196 bd_addr_copy(conn->address, addr);
197 conn->role = HCI_ROLE_INVALID;
198 conn->address_type = addr_type;
199 conn->con_handle = 0xffff;
200 conn->authentication_flags = AUTH_FLAGS_NONE;
201 conn->bonding_flags = 0;
202 conn->requested_security_level = LEVEL_0;
203#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

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

196 bd_addr_copy(conn->address, addr);
197 conn->role = HCI_ROLE_INVALID;
198 conn->address_type = addr_type;
199 conn->con_handle = 0xffff;
200 conn->authentication_flags = AUTH_FLAGS_NONE;
201 conn->bonding_flags = 0;
202 conn->requested_security_level = LEVEL_0;
203#ifdef ENABLE_CLASSIC
204 conn->request_role = HCI_ROLE_INVALID;
204 btstack_run_loop_set_timer_handler(&conn->timeout, hci_connection_timeout_handler);
205 btstack_run_loop_set_timer_context(&conn->timeout, conn);
206 hci_connection_timestamp(conn);
207#endif
208 conn->acl_recombination_length = 0;
209 conn->acl_recombination_pos = 0;
210 conn->num_packets_sent = 0;
211

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

3732 );
3733 return true;
3734 }
3735#endif
3736 return false;
3737}
3738#endif
3739
205 btstack_run_loop_set_timer_handler(&conn->timeout, hci_connection_timeout_handler);
206 btstack_run_loop_set_timer_context(&conn->timeout, conn);
207 hci_connection_timestamp(conn);
208#endif
209 conn->acl_recombination_length = 0;
210 conn->acl_recombination_pos = 0;
211 conn->num_packets_sent = 0;
212

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

3733 );
3734 return true;
3735 }
3736#endif
3737 return false;
3738}
3739#endif
3740
3740static bool hci_run_general_pending_commmands(void){
3741static bool hci_run_general_pending_commands(void){
3741 btstack_linked_item_t * it;
3742 for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next){
3743 hci_connection_t * connection = (hci_connection_t *) it;
3744
3745 switch(connection->state){
3746 case SEND_CREATE_CONNECTION:
3747 switch(connection->address_type){
3748#ifdef ENABLE_CLASSIC

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

3955 hci_send_cmd(&hci_exit_sniff_mode, connection->con_handle);
3956 return true;
3957 default:
3958 sniff_min_interval = connection->sniff_min_interval;
3959 connection->sniff_min_interval = 0;
3960 hci_send_cmd(&hci_sniff_mode, connection->con_handle, connection->sniff_max_interval, sniff_min_interval, connection->sniff_attempt, connection->sniff_timeout);
3961 return true;
3962 }
3742 btstack_linked_item_t * it;
3743 for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next){
3744 hci_connection_t * connection = (hci_connection_t *) it;
3745
3746 switch(connection->state){
3747 case SEND_CREATE_CONNECTION:
3748 switch(connection->address_type){
3749#ifdef ENABLE_CLASSIC

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

3956 hci_send_cmd(&hci_exit_sniff_mode, connection->con_handle);
3957 return true;
3958 default:
3959 sniff_min_interval = connection->sniff_min_interval;
3960 connection->sniff_min_interval = 0;
3961 hci_send_cmd(&hci_sniff_mode, connection->con_handle, connection->sniff_max_interval, sniff_min_interval, connection->sniff_attempt, connection->sniff_timeout);
3962 return true;
3963 }
3964
3965 if (connection->request_role != HCI_ROLE_INVALID){
3966 hci_role_t role = connection->request_role;
3967 connection->request_role = HCI_ROLE_INVALID;
3968 hci_send_cmd(&hci_switch_role_command, connection->address, role);
3969 return true;
3970 }
3963#endif
3964
3965#ifdef ENABLE_BLE
3966 switch (connection->le_con_parameter_update_state){
3967 // response to L2CAP CON PARAMETER UPDATE REQUEST
3968 case CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS:
3969 connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
3970 hci_send_cmd(&hci_le_connection_update, connection->con_handle, connection->le_conn_interval_min,

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

4025
4026#ifdef ENABLE_BLE
4027 // general gap le
4028 done = hci_run_general_gap_le();
4029 if (done) return;
4030#endif
4031
4032 // send pending HCI commands
3971#endif
3972
3973#ifdef ENABLE_BLE
3974 switch (connection->le_con_parameter_update_state){
3975 // response to L2CAP CON PARAMETER UPDATE REQUEST
3976 case CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS:
3977 connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
3978 hci_send_cmd(&hci_le_connection_update, connection->con_handle, connection->le_conn_interval_min,

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

4033
4034#ifdef ENABLE_BLE
4035 // general gap le
4036 done = hci_run_general_gap_le();
4037 if (done) return;
4038#endif
4039
4040 // send pending HCI commands
4033 done = hci_run_general_pending_commmands();
4041 done = hci_run_general_pending_commands();
4034 if (done) return;
4035
4036 // stack state sub statemachines
4037 hci_connection_t * connection;
4038 switch (hci_stack->state){
4039 case HCI_STATE_INITIALIZING:
4040 hci_initializing_run();
4041 break;

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

5173
5174hci_role_t gap_get_role(hci_con_handle_t connection_handle){
5175 hci_connection_t * conn = hci_connection_for_handle(connection_handle);
5176 if (!conn) return HCI_ROLE_INVALID;
5177 return (hci_role_t) conn->role;
5178}
5179
5180
4042 if (done) return;
4043
4044 // stack state sub statemachines
4045 hci_connection_t * connection;
4046 switch (hci_stack->state){
4047 case HCI_STATE_INITIALIZING:
4048 hci_initializing_run();
4049 break;

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

5181
5182hci_role_t gap_get_role(hci_con_handle_t connection_handle){
5183 hci_connection_t * conn = hci_connection_for_handle(connection_handle);
5184 if (!conn) return HCI_ROLE_INVALID;
5185 return (hci_role_t) conn->role;
5186}
5187
5188
5189uint8_t gap_request_role(bd_addr_t addr, hci_role_t role){
5190 hci_connection_t * conn = hci_connection_for_bd_addr_and_type(addr, BD_ADDR_TYPE_ACL);
5191 if (!conn) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
5192 conn->request_role = role;
5193 hci_run();
5194}
5195
5181#ifdef ENABLE_BLE
5182
5183uint8_t gap_le_set_phy(hci_con_handle_t connection_handle, uint8_t all_phys, uint8_t tx_phys, uint8_t rx_phys, uint8_t phy_options){
5184 hci_connection_t * conn = hci_connection_for_handle(connection_handle);
5185 if (!conn) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
5186
5187 conn->le_phy_update_all_phys = all_phys;
5188 conn->le_phy_update_tx_phys = tx_phys;

--- 519 unchanged lines hidden ---
5196#ifdef ENABLE_BLE
5197
5198uint8_t gap_le_set_phy(hci_con_handle_t connection_handle, uint8_t all_phys, uint8_t tx_phys, uint8_t rx_phys, uint8_t phy_options){
5199 hci_connection_t * conn = hci_connection_for_handle(connection_handle);
5200 if (!conn) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
5201
5202 conn->le_phy_update_all_phys = all_phys;
5203 conn->le_phy_update_tx_phys = tx_phys;

--- 519 unchanged lines hidden ---