The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2003-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This is the main implementation file for the BTA device manager. |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | |
| 25 | #include "bta_api.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 26 | #include "bta_dm_int.h" |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 27 | #include "bta_sys.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 28 | |
| 29 | /***************************************************************************** |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 30 | * Constants and types |
| 31 | ****************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 32 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 33 | tBTA_DM_CB bta_dm_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 34 | tBTA_DM_SEARCH_CB bta_dm_search_cb; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 35 | tBTA_DM_DI_CB bta_dm_di_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 36 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 37 | #define BTA_DM_NUM_ACTIONS (BTA_DM_MAX_EVT & 0x00ff) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 38 | |
| 39 | /* type for action functions */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 40 | typedef void (*tBTA_DM_ACTION)(tBTA_DM_MSG* p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 41 | |
| 42 | /* action function list */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 43 | const tBTA_DM_ACTION bta_dm_action[] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 44 | |
| 45 | /* device manager local device API events */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 46 | bta_dm_enable, /* 0 BTA_DM_API_ENABLE_EVT */ |
| 47 | bta_dm_disable, /* 1 BTA_DM_API_DISABLE_EVT */ |
| 48 | bta_dm_set_dev_name, /* 2 BTA_DM_API_SET_NAME_EVT */ |
| 49 | bta_dm_set_visibility, /* 3 BTA_DM_API_SET_VISIBILITY_EVT */ |
| 50 | bta_dm_acl_change, /* 8 BTA_DM_ACL_CHANGE_EVT */ |
| 51 | bta_dm_add_device, /* 9 BTA_DM_API_ADD_DEVICE_EVT */ |
| 52 | bta_dm_close_acl, /* 10 BTA_DM_API_ADD_DEVICE_EVT */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 53 | |
| 54 | /* security API events */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 55 | bta_dm_bond, /* 11 BTA_DM_API_BOND_EVT */ |
| 56 | bta_dm_bond_cancel, /* 12 BTA_DM_API_BOND_CANCEL_EVT */ |
| 57 | bta_dm_pin_reply, /* 13 BTA_DM_API_PIN_REPLY_EVT */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 58 | |
| 59 | /* power manger events */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 60 | bta_dm_pm_btm_status, /* 16 BTA_DM_PM_BTM_STATUS_EVT */ |
| 61 | bta_dm_pm_timer, /* 17 BTA_DM_PM_TIMER_EVT*/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 62 | |
| 63 | /* simple pairing events */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 64 | bta_dm_confirm, /* 18 BTA_DM_API_CONFIRM_EVT */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 65 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 66 | bta_dm_set_encryption, /* BTA_DM_API_SET_ENCRYPTION_EVT */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 67 | |
Jakub Pawlowski | 175da70 | 2015-11-12 15:00:58 -0800 | [diff] [blame] | 68 | /* out of band pairing events */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 69 | bta_dm_loc_oob, /* 20 BTA_DM_API_LOC_OOB_EVT */ |
| 70 | bta_dm_ci_io_req_act, /* 21 BTA_DM_CI_IO_REQ_EVT */ |
| 71 | bta_dm_ci_rmt_oob_act, /* 22 BTA_DM_CI_RMT_OOB_EVT */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 72 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 73 | bta_dm_add_blekey, /* BTA_DM_API_ADD_BLEKEY_EVT */ |
| 74 | bta_dm_add_ble_device, /* BTA_DM_API_ADD_BLEDEVICE_EVT */ |
| 75 | bta_dm_ble_passkey_reply, /* BTA_DM_API_BLE_PASSKEY_REPLY_EVT */ |
| 76 | bta_dm_ble_confirm_reply, /* BTA_DM_API_BLE_CONFIRM_REPLY_EVT */ |
| 77 | bta_dm_security_grant, bta_dm_ble_set_bg_conn_type, |
| 78 | bta_dm_ble_set_conn_params, /* BTA_DM_API_BLE_CONN_PARAM_EVT */ |
| 79 | bta_dm_ble_set_conn_scan_params, /* BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT */ |
| 80 | bta_dm_ble_set_scan_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 81 | bta_dm_ble_observe, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 82 | bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 83 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 84 | bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 85 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 86 | bta_dm_ble_set_data_length, /* BTA_DM_API_SET_DATA_LENGTH_EVT */ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 87 | #if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE) |
Andre Eisenbach | 2d75441 | 2013-11-20 17:23:06 -0800 | [diff] [blame] | 88 | bta_dm_cfg_filter_cond, /* BTA_DM_API_CFG_FILTER_COND_EVT */ |
Satya Calloji | 1a9247a | 2014-06-05 13:15:15 -0700 | [diff] [blame] | 89 | bta_dm_scan_filter_param_setup, /* BTA_DM_API_SCAN_FILTER_SETUP_EVT */ |
| 90 | bta_dm_enable_scan_filter, /* BTA_DM_API_SCAN_FILTER_ENABLE_EVT */ |
Andre Eisenbach | 2d75441 | 2013-11-20 17:23:06 -0800 | [diff] [blame] | 91 | #endif |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 92 | bta_dm_ble_setup_storage, /* BTA_DM_API_BLE_SETUP_STORAGE_EVT */ |
| 93 | bta_dm_ble_enable_batch_scan, /* BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT */ |
| 94 | bta_dm_ble_disable_batch_scan, /* BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT */ |
| 95 | bta_dm_ble_read_scan_reports, /* BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT */ |
Satya Calloji | 1acb61c | 2014-06-14 23:16:18 -0700 | [diff] [blame] | 96 | bta_dm_ble_track_advertiser, /* BTA_DM_API_BLE_TRACK_ADVERTISER_EVT */ |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 97 | bta_dm_ble_get_energy_info, /* BTA_DM_API_BLE_ENERGY_INFO_EVT */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 98 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 99 | bta_dm_enable_test_mode, /* BTA_DM_API_ENABLE_TEST_MODE_EVT */ |
| 100 | bta_dm_disable_test_mode, /* BTA_DM_API_DISABLE_TEST_MODE_EVT */ |
| 101 | bta_dm_execute_callback, /* BTA_DM_API_EXECUTE_CBACK_EVT */ |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 102 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 103 | bta_dm_remove_all_acl, /* BTA_DM_API_REMOVE_ALL_ACL_EVT */ |
| 104 | bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 107 | /* state machine action enumeration list */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 108 | enum { |
| 109 | BTA_DM_API_SEARCH, /* 0 bta_dm_search_start */ |
| 110 | BTA_DM_API_SEARCH_CANCEL, /* 1 bta_dm_search_cancel */ |
| 111 | BTA_DM_API_DISCOVER, /* 2 bta_dm_discover */ |
| 112 | BTA_DM_INQUIRY_CMPL, /* 3 bta_dm_inq_cmpl */ |
| 113 | BTA_DM_REMT_NAME, /* 4 bta_dm_rmt_name */ |
| 114 | BTA_DM_SDP_RESULT, /* 5 bta_dm_sdp_result */ |
| 115 | BTA_DM_SEARCH_CMPL, /* 6 bta_dm_search_cmpl*/ |
| 116 | BTA_DM_FREE_SDP_DB, /* 7 bta_dm_free_sdp_db */ |
| 117 | BTA_DM_DISC_RESULT, /* 8 bta_dm_disc_result */ |
| 118 | BTA_DM_SEARCH_RESULT, /* 9 bta_dm_search_result */ |
| 119 | BTA_DM_QUEUE_SEARCH, /* 10 bta_dm_queue_search */ |
| 120 | BTA_DM_QUEUE_DISC, /* 11 bta_dm_queue_disc */ |
| 121 | BTA_DM_SEARCH_CLEAR_QUEUE, /* 12 bta_dm_search_clear_queue */ |
| 122 | BTA_DM_SEARCH_CANCEL_CMPL, /* 13 bta_dm_search_cancel_cmpl */ |
| 123 | BTA_DM_SEARCH_CANCEL_NOTIFY, /* 14 bta_dm_search_cancel_notify */ |
| 124 | BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, /* 15 bta_dm_search_cancel_transac_cmpl */ |
| 125 | BTA_DM_DISC_RMT_NAME, /* 16 bta_dm_disc_rmt_name */ |
| 126 | BTA_DM_API_DI_DISCOVER, /* 17 bta_dm_di_disc */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 127 | BTA_DM_CLOSE_GATT_CONN, /* 18 bta_dm_close_gatt_conn */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 128 | BTA_DM_SEARCH_NUM_ACTIONS /* 19 */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 129 | }; |
| 130 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 131 | /* action function list */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 132 | const tBTA_DM_ACTION bta_dm_search_action[] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 133 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 134 | bta_dm_search_start, /* 0 BTA_DM_API_SEARCH */ |
| 135 | bta_dm_search_cancel, /* 1 BTA_DM_API_SEARCH_CANCEL */ |
| 136 | bta_dm_discover, /* 2 BTA_DM_API_DISCOVER */ |
| 137 | bta_dm_inq_cmpl, /* 3 BTA_DM_INQUIRY_CMPL */ |
| 138 | bta_dm_rmt_name, /* 4 BTA_DM_REMT_NAME */ |
| 139 | bta_dm_sdp_result, /* 5 BTA_DM_SDP_RESULT */ |
| 140 | bta_dm_search_cmpl, /* 6 BTA_DM_SEARCH_CMPL */ |
| 141 | bta_dm_free_sdp_db, /* 7 BTA_DM_FREE_SDP_DB */ |
| 142 | bta_dm_disc_result, /* 8 BTA_DM_DISC_RESULT */ |
| 143 | bta_dm_search_result, /* 9 BTA_DM_SEARCH_RESULT */ |
| 144 | bta_dm_queue_search, /* 10 BTA_DM_QUEUE_SEARCH */ |
| 145 | bta_dm_queue_disc, /* 11 BTA_DM_QUEUE_DISC */ |
| 146 | bta_dm_search_clear_queue, /* 12 BTA_DM_SEARCH_CLEAR_QUEUE */ |
| 147 | bta_dm_search_cancel_cmpl, /* 13 BTA_DM_SEARCH_CANCEL_CMPL */ |
| 148 | bta_dm_search_cancel_notify, /* 14 BTA_DM_SEARCH_CANCEL_NOTIFY */ |
| 149 | bta_dm_search_cancel_transac_cmpl, /* 15 BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL |
| 150 | */ |
| 151 | bta_dm_disc_rmt_name, /* 16 BTA_DM_DISC_RMT_NAME */ |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 152 | bta_dm_di_disc, /* 17 BTA_DM_API_DI_DISCOVER */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 153 | bta_dm_close_gatt_conn |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 156 | #define BTA_DM_SEARCH_IGNORE BTA_DM_SEARCH_NUM_ACTIONS |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 157 | /* state table information */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 158 | #define BTA_DM_SEARCH_ACTIONS 2 /* number of actions */ |
| 159 | #define BTA_DM_SEARCH_NEXT_STATE 2 /* position of next state */ |
| 160 | #define BTA_DM_SEARCH_NUM_COLS 3 /* number of columns in state tables */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 161 | |
| 162 | /* state table for listen state */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 163 | const uint8_t bta_dm_search_idle_st_table[][BTA_DM_SEARCH_NUM_COLS] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 164 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 165 | /* Event Action 1 |
| 166 | Action 2 Next State */ |
| 167 | /* API_SEARCH */ {BTA_DM_API_SEARCH, BTA_DM_SEARCH_IGNORE, |
| 168 | BTA_DM_SEARCH_ACTIVE}, |
| 169 | /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE, |
| 170 | BTA_DM_SEARCH_IDLE}, |
| 171 | /* API_SEARCH_DISC */ {BTA_DM_API_DISCOVER, BTA_DM_SEARCH_IGNORE, |
| 172 | BTA_DM_DISCOVER_ACTIVE}, |
| 173 | /* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
| 174 | BTA_DM_SEARCH_IDLE}, |
| 175 | /* REMT_NAME_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
| 176 | BTA_DM_SEARCH_IDLE}, |
| 177 | /* SDP_RESULT_EVT */ {BTA_DM_FREE_SDP_DB, BTA_DM_SEARCH_IGNORE, |
| 178 | BTA_DM_SEARCH_IDLE}, |
| 179 | /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
| 180 | BTA_DM_SEARCH_IDLE}, |
| 181 | /* DISCV_RES_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
| 182 | BTA_DM_SEARCH_IDLE}, |
| 183 | /* API_DI_DISCOVER_EVT */ {BTA_DM_API_DI_DISCOVER, BTA_DM_SEARCH_IGNORE, |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 184 | BTA_DM_SEARCH_ACTIVE}, |
| 185 | /* DISC_CLOSE_TOUT_EVT */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 186 | {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE} |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 187 | }; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 188 | const uint8_t bta_dm_search_search_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 189 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 190 | /* Event Action 1 |
| 191 | Action 2 Next State */ |
| 192 | /* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
| 193 | BTA_DM_SEARCH_ACTIVE}, |
| 194 | /* API_SEARCH_CANCEL */ {BTA_DM_API_SEARCH_CANCEL, BTA_DM_SEARCH_IGNORE, |
| 195 | BTA_DM_SEARCH_CANCELLING}, |
| 196 | /* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
| 197 | BTA_DM_SEARCH_ACTIVE}, |
| 198 | /* INQUIRY_CMPL */ {BTA_DM_INQUIRY_CMPL, BTA_DM_SEARCH_IGNORE, |
| 199 | BTA_DM_SEARCH_ACTIVE}, |
| 200 | /* REMT_NAME_EVT */ {BTA_DM_REMT_NAME, BTA_DM_SEARCH_IGNORE, |
| 201 | BTA_DM_SEARCH_ACTIVE}, |
| 202 | /* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE, |
| 203 | BTA_DM_SEARCH_ACTIVE}, |
| 204 | /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE, |
| 205 | BTA_DM_SEARCH_IDLE}, |
| 206 | /* DISCV_RES_EVT */ {BTA_DM_SEARCH_RESULT, BTA_DM_SEARCH_IGNORE, |
| 207 | BTA_DM_SEARCH_ACTIVE}, |
| 208 | /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 209 | BTA_DM_SEARCH_ACTIVE}, |
| 210 | /* DISC_CLOSE_TOUT_EVT */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 211 | {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE} |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 212 | |
| 213 | }; |
| 214 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 215 | const uint8_t |
| 216 | bta_dm_search_search_cancelling_st_table[][BTA_DM_SEARCH_NUM_COLS] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 217 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 218 | /* Event Action 1 |
| 219 | Action 2 Next State */ |
| 220 | /* API_SEARCH */ {BTA_DM_QUEUE_SEARCH, BTA_DM_SEARCH_IGNORE, |
| 221 | BTA_DM_SEARCH_CANCELLING}, |
| 222 | /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CLEAR_QUEUE, |
| 223 | BTA_DM_SEARCH_CANCEL_NOTIFY, |
| 224 | BTA_DM_SEARCH_CANCELLING}, |
| 225 | /* API_SEARCH_DISC */ {BTA_DM_QUEUE_DISC, BTA_DM_SEARCH_IGNORE, |
| 226 | BTA_DM_SEARCH_CANCELLING}, |
| 227 | /* INQUIRY_CMPL */ {BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IGNORE, |
| 228 | BTA_DM_SEARCH_IDLE}, |
| 229 | /* REMT_NAME_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, |
| 230 | BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE}, |
| 231 | /* SDP_RESULT_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, |
| 232 | BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE}, |
| 233 | /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, |
| 234 | BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE}, |
| 235 | /* DISCV_RES_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, |
| 236 | BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE}, |
| 237 | /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 238 | BTA_DM_SEARCH_CANCELLING}, |
| 239 | /* DISC_CLOSE_TOUT_EVT */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 240 | {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING} |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 241 | }; |
| 242 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 243 | const uint8_t bta_dm_search_disc_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 244 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 245 | /* Event Action 1 |
| 246 | Action 2 Next State */ |
| 247 | /* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
| 248 | BTA_DM_DISCOVER_ACTIVE}, |
| 249 | /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE, |
| 250 | BTA_DM_SEARCH_CANCELLING}, |
| 251 | /* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
| 252 | BTA_DM_DISCOVER_ACTIVE}, |
| 253 | /* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
| 254 | BTA_DM_DISCOVER_ACTIVE}, |
| 255 | /* REMT_NAME_EVT */ {BTA_DM_DISC_RMT_NAME, BTA_DM_SEARCH_IGNORE, |
| 256 | BTA_DM_DISCOVER_ACTIVE}, |
| 257 | /* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE, |
| 258 | BTA_DM_DISCOVER_ACTIVE}, |
| 259 | /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE, |
| 260 | BTA_DM_SEARCH_IDLE}, |
| 261 | /* DISCV_RES_EVT */ {BTA_DM_DISC_RESULT, BTA_DM_SEARCH_IGNORE, |
| 262 | BTA_DM_DISCOVER_ACTIVE}, |
| 263 | /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 264 | BTA_DM_DISCOVER_ACTIVE}, |
| 265 | /* DISC_CLOSE_TOUT_EVT */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 266 | {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE} |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 267 | }; |
| 268 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 269 | typedef const uint8_t (*tBTA_DM_ST_TBL)[BTA_DM_SEARCH_NUM_COLS]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 270 | |
| 271 | /* state table */ |
| 272 | const tBTA_DM_ST_TBL bta_dm_search_st_tbl[] = { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 273 | bta_dm_search_idle_st_table, bta_dm_search_search_active_st_table, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 274 | bta_dm_search_search_cancelling_st_table, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 275 | bta_dm_search_disc_active_st_table}; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 276 | |
| 277 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 278 | * |
| 279 | * Function bta_dm_sm_disable |
| 280 | * |
| 281 | * Description unregister BTA DM |
| 282 | * |
| 283 | * |
| 284 | * Returns void |
| 285 | * |
| 286 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 287 | void bta_dm_sm_disable() { bta_sys_deregister(BTA_ID_DM); } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 288 | |
| 289 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 290 | * |
| 291 | * Function bta_dm_sm_execute |
| 292 | * |
| 293 | * Description State machine event handling function for DM |
| 294 | * |
| 295 | * |
| 296 | * Returns void |
| 297 | * |
| 298 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 299 | bool bta_dm_sm_execute(BT_HDR* p_msg) { |
| 300 | uint16_t event = p_msg->event & 0x00ff; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 301 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 302 | APPL_TRACE_EVENT("bta_dm_sm_execute event:0x%x", event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 303 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 304 | /* execute action functions */ |
| 305 | if (event < BTA_DM_NUM_ACTIONS) { |
| 306 | (*bta_dm_action[event])((tBTA_DM_MSG*)p_msg); |
| 307 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 308 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 309 | return true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 313 | * |
| 314 | * Function bta_dm_sm_search_disable |
| 315 | * |
| 316 | * Description unregister BTA SEARCH DM |
| 317 | * |
| 318 | * |
| 319 | * Returns void |
| 320 | * |
| 321 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 322 | void bta_dm_search_sm_disable() { bta_sys_deregister(BTA_ID_DM_SEARCH); } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 323 | |
| 324 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 325 | * |
| 326 | * Function bta_dm_search_sm_execute |
| 327 | * |
| 328 | * Description State machine event handling function for DM |
| 329 | * |
| 330 | * |
| 331 | * Returns void |
| 332 | * |
| 333 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 334 | bool bta_dm_search_sm_execute(BT_HDR* p_msg) { |
| 335 | tBTA_DM_ST_TBL state_table; |
| 336 | uint8_t action; |
| 337 | int i; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 338 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 339 | APPL_TRACE_EVENT("bta_dm_search_sm_execute state:%d, event:0x%x", |
| 340 | bta_dm_search_cb.state, p_msg->event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 341 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 342 | /* look up the state table for the current state */ |
| 343 | state_table = bta_dm_search_st_tbl[bta_dm_search_cb.state]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 344 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 345 | bta_dm_search_cb.state = |
| 346 | state_table[p_msg->event & 0x00ff][BTA_DM_SEARCH_NEXT_STATE]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 347 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 348 | /* execute action functions */ |
| 349 | for (i = 0; i < BTA_DM_SEARCH_ACTIONS; i++) { |
| 350 | if ((action = state_table[p_msg->event & 0x00ff][i]) != |
| 351 | BTA_DM_SEARCH_IGNORE) { |
| 352 | (*bta_dm_search_action[action])((tBTA_DM_MSG*)p_msg); |
| 353 | } else { |
| 354 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 355 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 356 | } |
| 357 | return true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 358 | } |