blob: 3d25691e0fa0b43dc59a1d37ca057b31a37c95ae [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
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 Project5738f832012-12-12 16:00:35 -080026#include "bta_dm_int.h"
Myles Watsoncd1fd072016-11-09 13:17:43 -080027#include "bta_sys.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080028
29/*****************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080030 * Constants and types
31 ****************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080032
Myles Watsoncd1fd072016-11-09 13:17:43 -080033tBTA_DM_CB bta_dm_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -080034tBTA_DM_SEARCH_CB bta_dm_search_cb;
Myles Watsoncd1fd072016-11-09 13:17:43 -080035tBTA_DM_DI_CB bta_dm_di_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -080036
Myles Watsoncd1fd072016-11-09 13:17:43 -080037#define BTA_DM_NUM_ACTIONS (BTA_DM_MAX_EVT & 0x00ff)
The Android Open Source Project5738f832012-12-12 16:00:35 -080038
39/* type for action functions */
Myles Watsoncd1fd072016-11-09 13:17:43 -080040typedef void (*tBTA_DM_ACTION)(tBTA_DM_MSG* p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -080041
42/* action function list */
Myles Watsoncd1fd072016-11-09 13:17:43 -080043const tBTA_DM_ACTION bta_dm_action[] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -080044
45 /* device manager local device API events */
Myles Watsoncd1fd072016-11-09 13:17:43 -080046 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 Project5738f832012-12-12 16:00:35 -080053
54 /* security API events */
Myles Watsoncd1fd072016-11-09 13:17:43 -080055 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 Project5738f832012-12-12 16:00:35 -080058
59 /* power manger events */
Myles Watsoncd1fd072016-11-09 13:17:43 -080060 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 Project5738f832012-12-12 16:00:35 -080062
63 /* simple pairing events */
Myles Watsoncd1fd072016-11-09 13:17:43 -080064 bta_dm_confirm, /* 18 BTA_DM_API_CONFIRM_EVT */
The Android Open Source Project5738f832012-12-12 16:00:35 -080065
Myles Watsoncd1fd072016-11-09 13:17:43 -080066 bta_dm_set_encryption, /* BTA_DM_API_SET_ENCRYPTION_EVT */
The Android Open Source Project5738f832012-12-12 16:00:35 -080067
Jakub Pawlowski175da702015-11-12 15:00:58 -080068 /* out of band pairing events */
Myles Watsoncd1fd072016-11-09 13:17:43 -080069 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 Project5738f832012-12-12 16:00:35 -080072
Myles Watsoncd1fd072016-11-09 13:17:43 -080073 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 Battaead3cde2013-02-05 15:22:31 -080081 bta_dm_ble_observe,
Myles Watsoncd1fd072016-11-09 13:17:43 -080082 bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */
Marie Janssene9e58ce2016-06-17 14:12:17 -070083#if (BLE_PRIVACY_SPT == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -080084 bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -070085#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -080086 bta_dm_ble_set_data_length, /* BTA_DM_API_SET_DATA_LENGTH_EVT */
Marie Janssene9e58ce2016-06-17 14:12:17 -070087#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
Andre Eisenbach2d754412013-11-20 17:23:06 -080088 bta_dm_cfg_filter_cond, /* BTA_DM_API_CFG_FILTER_COND_EVT */
Satya Calloji1a9247a2014-06-05 13:15:15 -070089 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 Eisenbach2d754412013-11-20 17:23:06 -080091#endif
Satya Callojic4e25962014-05-10 23:46:24 -070092 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 Calloji1acb61c2014-06-14 23:16:18 -070096 bta_dm_ble_track_advertiser, /* BTA_DM_API_BLE_TRACK_ADVERTISER_EVT */
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -070097 bta_dm_ble_get_energy_info, /* BTA_DM_API_BLE_ENERGY_INFO_EVT */
The Android Open Source Project5738f832012-12-12 16:00:35 -080098
Myles Watsoncd1fd072016-11-09 13:17:43 -080099 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 VijayaRaghavan76356ae2015-04-21 11:32:29 -0700102
Myles Watsoncd1fd072016-11-09 13:17:43 -0800103 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 Project5738f832012-12-12 16:00:35 -0800105};
106
The Android Open Source Project5738f832012-12-12 16:00:35 -0800107/* state machine action enumeration list */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800108enum {
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 Watson90088882016-11-15 16:33:22 -0800127 BTA_DM_CLOSE_GATT_CONN, /* 18 bta_dm_close_gatt_conn */
128 BTA_DM_SEARCH_NUM_ACTIONS /* 19 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800129};
130
The Android Open Source Project5738f832012-12-12 16:00:35 -0800131/* action function list */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800132const tBTA_DM_ACTION bta_dm_search_action[] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800133
Myles Watsoncd1fd072016-11-09 13:17:43 -0800134 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 Watson84baa7f2016-11-14 12:05:37 -0800152 bta_dm_di_disc, /* 17 BTA_DM_API_DI_DISCOVER */
Myles Watson90088882016-11-15 16:33:22 -0800153 bta_dm_close_gatt_conn};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800154
Myles Watsoncd1fd072016-11-09 13:17:43 -0800155#define BTA_DM_SEARCH_IGNORE BTA_DM_SEARCH_NUM_ACTIONS
The Android Open Source Project5738f832012-12-12 16:00:35 -0800156/* state table information */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800157#define BTA_DM_SEARCH_ACTIONS 2 /* number of actions */
158#define BTA_DM_SEARCH_NEXT_STATE 2 /* position of next state */
159#define BTA_DM_SEARCH_NUM_COLS 3 /* number of columns in state tables */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800160
161/* state table for listen state */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800162const uint8_t bta_dm_search_idle_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800163
Myles Watsoncd1fd072016-11-09 13:17:43 -0800164 /* Event Action 1
165 Action 2 Next State */
166 /* API_SEARCH */ {BTA_DM_API_SEARCH, BTA_DM_SEARCH_IGNORE,
167 BTA_DM_SEARCH_ACTIVE},
168 /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE,
169 BTA_DM_SEARCH_IDLE},
170 /* API_SEARCH_DISC */ {BTA_DM_API_DISCOVER, BTA_DM_SEARCH_IGNORE,
171 BTA_DM_DISCOVER_ACTIVE},
172 /* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
173 BTA_DM_SEARCH_IDLE},
174 /* REMT_NAME_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
175 BTA_DM_SEARCH_IDLE},
176 /* SDP_RESULT_EVT */ {BTA_DM_FREE_SDP_DB, BTA_DM_SEARCH_IGNORE,
177 BTA_DM_SEARCH_IDLE},
178 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
179 BTA_DM_SEARCH_IDLE},
180 /* DISCV_RES_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
181 BTA_DM_SEARCH_IDLE},
182 /* API_DI_DISCOVER_EVT */ {BTA_DM_API_DI_DISCOVER, BTA_DM_SEARCH_IGNORE,
Myles Watson84baa7f2016-11-14 12:05:37 -0800183 BTA_DM_SEARCH_ACTIVE},
184 /* DISC_CLOSE_TOUT_EVT */
Myles Watson90088882016-11-15 16:33:22 -0800185 {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE}};
Myles Watsoncd1fd072016-11-09 13:17:43 -0800186const uint8_t bta_dm_search_search_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800187
Myles Watsoncd1fd072016-11-09 13:17:43 -0800188 /* Event Action 1
189 Action 2 Next State */
190 /* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
191 BTA_DM_SEARCH_ACTIVE},
192 /* API_SEARCH_CANCEL */ {BTA_DM_API_SEARCH_CANCEL, BTA_DM_SEARCH_IGNORE,
193 BTA_DM_SEARCH_CANCELLING},
194 /* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
195 BTA_DM_SEARCH_ACTIVE},
196 /* INQUIRY_CMPL */ {BTA_DM_INQUIRY_CMPL, BTA_DM_SEARCH_IGNORE,
197 BTA_DM_SEARCH_ACTIVE},
198 /* REMT_NAME_EVT */ {BTA_DM_REMT_NAME, BTA_DM_SEARCH_IGNORE,
199 BTA_DM_SEARCH_ACTIVE},
200 /* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE,
201 BTA_DM_SEARCH_ACTIVE},
202 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE,
203 BTA_DM_SEARCH_IDLE},
204 /* DISCV_RES_EVT */ {BTA_DM_SEARCH_RESULT, BTA_DM_SEARCH_IGNORE,
205 BTA_DM_SEARCH_ACTIVE},
206 /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
Myles Watson84baa7f2016-11-14 12:05:37 -0800207 BTA_DM_SEARCH_ACTIVE},
208 /* DISC_CLOSE_TOUT_EVT */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800209 {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800210
211};
212
Myles Watsoncd1fd072016-11-09 13:17:43 -0800213const uint8_t
214 bta_dm_search_search_cancelling_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800215
Myles Watsoncd1fd072016-11-09 13:17:43 -0800216 /* Event Action 1
217 Action 2 Next State */
218 /* API_SEARCH */ {BTA_DM_QUEUE_SEARCH, BTA_DM_SEARCH_IGNORE,
219 BTA_DM_SEARCH_CANCELLING},
220 /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CLEAR_QUEUE,
221 BTA_DM_SEARCH_CANCEL_NOTIFY,
222 BTA_DM_SEARCH_CANCELLING},
223 /* API_SEARCH_DISC */ {BTA_DM_QUEUE_DISC, BTA_DM_SEARCH_IGNORE,
224 BTA_DM_SEARCH_CANCELLING},
225 /* INQUIRY_CMPL */ {BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IGNORE,
226 BTA_DM_SEARCH_IDLE},
227 /* REMT_NAME_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
228 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
229 /* SDP_RESULT_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
230 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
231 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
232 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
233 /* DISCV_RES_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
234 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
235 /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
Myles Watson84baa7f2016-11-14 12:05:37 -0800236 BTA_DM_SEARCH_CANCELLING},
237 /* DISC_CLOSE_TOUT_EVT */
Myles Watson90088882016-11-15 16:33:22 -0800238 {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800239
Myles Watsoncd1fd072016-11-09 13:17:43 -0800240const uint8_t bta_dm_search_disc_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800241
Myles Watsoncd1fd072016-11-09 13:17:43 -0800242 /* Event Action 1
243 Action 2 Next State */
244 /* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
245 BTA_DM_DISCOVER_ACTIVE},
246 /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE,
247 BTA_DM_SEARCH_CANCELLING},
248 /* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
249 BTA_DM_DISCOVER_ACTIVE},
250 /* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
251 BTA_DM_DISCOVER_ACTIVE},
252 /* REMT_NAME_EVT */ {BTA_DM_DISC_RMT_NAME, BTA_DM_SEARCH_IGNORE,
253 BTA_DM_DISCOVER_ACTIVE},
254 /* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE,
255 BTA_DM_DISCOVER_ACTIVE},
256 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE,
257 BTA_DM_SEARCH_IDLE},
258 /* DISCV_RES_EVT */ {BTA_DM_DISC_RESULT, BTA_DM_SEARCH_IGNORE,
259 BTA_DM_DISCOVER_ACTIVE},
260 /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
Myles Watson84baa7f2016-11-14 12:05:37 -0800261 BTA_DM_DISCOVER_ACTIVE},
262 /* DISC_CLOSE_TOUT_EVT */
Myles Watson90088882016-11-15 16:33:22 -0800263 {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800264
Marie Janssene9e58ce2016-06-17 14:12:17 -0700265typedef const uint8_t (*tBTA_DM_ST_TBL)[BTA_DM_SEARCH_NUM_COLS];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800266
267/* state table */
268const tBTA_DM_ST_TBL bta_dm_search_st_tbl[] = {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800269 bta_dm_search_idle_st_table, bta_dm_search_search_active_st_table,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800270 bta_dm_search_search_cancelling_st_table,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800271 bta_dm_search_disc_active_st_table};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800272
273/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800274 *
275 * Function bta_dm_sm_disable
276 *
277 * Description unregister BTA DM
278 *
279 *
280 * Returns void
281 *
282 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800283void bta_dm_sm_disable() { bta_sys_deregister(BTA_ID_DM); }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800284
285/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800286 *
287 * Function bta_dm_sm_execute
288 *
289 * Description State machine event handling function for DM
290 *
291 *
292 * Returns void
293 *
294 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800295bool bta_dm_sm_execute(BT_HDR* p_msg) {
296 uint16_t event = p_msg->event & 0x00ff;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800297
Myles Watsoncd1fd072016-11-09 13:17:43 -0800298 APPL_TRACE_EVENT("bta_dm_sm_execute event:0x%x", event);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800299
Myles Watsoncd1fd072016-11-09 13:17:43 -0800300 /* execute action functions */
301 if (event < BTA_DM_NUM_ACTIONS) {
302 (*bta_dm_action[event])((tBTA_DM_MSG*)p_msg);
303 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800304
Myles Watsoncd1fd072016-11-09 13:17:43 -0800305 return true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800306}
307
308/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800309 *
310 * Function bta_dm_sm_search_disable
311 *
312 * Description unregister BTA SEARCH DM
313 *
314 *
315 * Returns void
316 *
317 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800318void bta_dm_search_sm_disable() { bta_sys_deregister(BTA_ID_DM_SEARCH); }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800319
320/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800321 *
322 * Function bta_dm_search_sm_execute
323 *
324 * Description State machine event handling function for DM
325 *
326 *
327 * Returns void
328 *
329 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800330bool bta_dm_search_sm_execute(BT_HDR* p_msg) {
331 tBTA_DM_ST_TBL state_table;
332 uint8_t action;
333 int i;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800334
Myles Watsoncd1fd072016-11-09 13:17:43 -0800335 APPL_TRACE_EVENT("bta_dm_search_sm_execute state:%d, event:0x%x",
336 bta_dm_search_cb.state, p_msg->event);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800337
Myles Watsoncd1fd072016-11-09 13:17:43 -0800338 /* look up the state table for the current state */
339 state_table = bta_dm_search_st_tbl[bta_dm_search_cb.state];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800340
Myles Watsoncd1fd072016-11-09 13:17:43 -0800341 bta_dm_search_cb.state =
342 state_table[p_msg->event & 0x00ff][BTA_DM_SEARCH_NEXT_STATE];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800343
Myles Watsoncd1fd072016-11-09 13:17:43 -0800344 /* execute action functions */
345 for (i = 0; i < BTA_DM_SEARCH_ACTIONS; i++) {
Marie Janssenf33b6f42016-11-22 15:01:42 -0800346 action = state_table[p_msg->event & 0x00ff][i];
347 if (action != BTA_DM_SEARCH_IGNORE) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800348 (*bta_dm_search_action[action])((tBTA_DM_MSG*)p_msg);
349 } else {
350 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800351 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800352 }
353 return true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800354}