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