blob: ecbff69c7dd0b05eda0be747ffec72dc2da0bc07 [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
Marie Janssene9e58ce2016-06-17 14:12:17 -070073#if (BLE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -080074 bta_dm_add_blekey, /* BTA_DM_API_ADD_BLEKEY_EVT */
75 bta_dm_add_ble_device, /* BTA_DM_API_ADD_BLEDEVICE_EVT */
76 bta_dm_ble_passkey_reply, /* BTA_DM_API_BLE_PASSKEY_REPLY_EVT */
77 bta_dm_ble_confirm_reply, /* BTA_DM_API_BLE_CONFIRM_REPLY_EVT */
78 bta_dm_security_grant, bta_dm_ble_set_bg_conn_type,
79 bta_dm_ble_set_conn_params, /* BTA_DM_API_BLE_CONN_PARAM_EVT */
80 bta_dm_ble_set_conn_scan_params, /* BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT */
81 bta_dm_ble_set_scan_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080082 bta_dm_ble_observe,
Myles Watsoncd1fd072016-11-09 13:17:43 -080083 bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */
Marie Janssene9e58ce2016-06-17 14:12:17 -070084#if (BLE_PRIVACY_SPT == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -080085 bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -070086#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -080087 bta_dm_ble_set_data_length, /* BTA_DM_API_SET_DATA_LENGTH_EVT */
Marie Janssene9e58ce2016-06-17 14:12:17 -070088#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
Andre Eisenbach2d754412013-11-20 17:23:06 -080089 bta_dm_cfg_filter_cond, /* BTA_DM_API_CFG_FILTER_COND_EVT */
Satya Calloji1a9247a2014-06-05 13:15:15 -070090 bta_dm_scan_filter_param_setup, /* BTA_DM_API_SCAN_FILTER_SETUP_EVT */
91 bta_dm_enable_scan_filter, /* BTA_DM_API_SCAN_FILTER_ENABLE_EVT */
Andre Eisenbach2d754412013-11-20 17:23:06 -080092#endif
Satya Callojic4e25962014-05-10 23:46:24 -070093 bta_dm_ble_setup_storage, /* BTA_DM_API_BLE_SETUP_STORAGE_EVT */
94 bta_dm_ble_enable_batch_scan, /* BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT */
95 bta_dm_ble_disable_batch_scan, /* BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT */
96 bta_dm_ble_read_scan_reports, /* BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT */
Satya Calloji1acb61c2014-06-14 23:16:18 -070097 bta_dm_ble_track_advertiser, /* BTA_DM_API_BLE_TRACK_ADVERTISER_EVT */
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -070098 bta_dm_ble_get_energy_info, /* BTA_DM_API_BLE_ENERGY_INFO_EVT */
Prerepa Viswanadhamb9447032014-08-07 18:30:59 -070099#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800100
Myles Watsoncd1fd072016-11-09 13:17:43 -0800101 bta_dm_enable_test_mode, /* BTA_DM_API_ENABLE_TEST_MODE_EVT */
102 bta_dm_disable_test_mode, /* BTA_DM_API_DISABLE_TEST_MODE_EVT */
103 bta_dm_execute_callback, /* BTA_DM_API_EXECUTE_CBACK_EVT */
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -0700104
Myles Watsoncd1fd072016-11-09 13:17:43 -0800105 bta_dm_remove_all_acl, /* BTA_DM_API_REMOVE_ALL_ACL_EVT */
106 bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800107};
108
The Android Open Source Project5738f832012-12-12 16:00:35 -0800109/* state machine action enumeration list */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800110enum {
111 BTA_DM_API_SEARCH, /* 0 bta_dm_search_start */
112 BTA_DM_API_SEARCH_CANCEL, /* 1 bta_dm_search_cancel */
113 BTA_DM_API_DISCOVER, /* 2 bta_dm_discover */
114 BTA_DM_INQUIRY_CMPL, /* 3 bta_dm_inq_cmpl */
115 BTA_DM_REMT_NAME, /* 4 bta_dm_rmt_name */
116 BTA_DM_SDP_RESULT, /* 5 bta_dm_sdp_result */
117 BTA_DM_SEARCH_CMPL, /* 6 bta_dm_search_cmpl*/
118 BTA_DM_FREE_SDP_DB, /* 7 bta_dm_free_sdp_db */
119 BTA_DM_DISC_RESULT, /* 8 bta_dm_disc_result */
120 BTA_DM_SEARCH_RESULT, /* 9 bta_dm_search_result */
121 BTA_DM_QUEUE_SEARCH, /* 10 bta_dm_queue_search */
122 BTA_DM_QUEUE_DISC, /* 11 bta_dm_queue_disc */
123 BTA_DM_SEARCH_CLEAR_QUEUE, /* 12 bta_dm_search_clear_queue */
124 BTA_DM_SEARCH_CANCEL_CMPL, /* 13 bta_dm_search_cancel_cmpl */
125 BTA_DM_SEARCH_CANCEL_NOTIFY, /* 14 bta_dm_search_cancel_notify */
126 BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, /* 15 bta_dm_search_cancel_transac_cmpl */
127 BTA_DM_DISC_RMT_NAME, /* 16 bta_dm_disc_rmt_name */
128 BTA_DM_API_DI_DISCOVER, /* 17 bta_dm_di_disc */
Marie Janssene9e58ce2016-06-17 14:12:17 -0700129#if (BLE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800130 BTA_DM_CLOSE_GATT_CONN, /* 18 bta_dm_close_gatt_conn */
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700131#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -0800132 BTA_DM_SEARCH_NUM_ACTIONS /* 19 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800133};
134
The Android Open Source Project5738f832012-12-12 16:00:35 -0800135/* action function list */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800136const tBTA_DM_ACTION bta_dm_search_action[] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800137
Myles Watsoncd1fd072016-11-09 13:17:43 -0800138 bta_dm_search_start, /* 0 BTA_DM_API_SEARCH */
139 bta_dm_search_cancel, /* 1 BTA_DM_API_SEARCH_CANCEL */
140 bta_dm_discover, /* 2 BTA_DM_API_DISCOVER */
141 bta_dm_inq_cmpl, /* 3 BTA_DM_INQUIRY_CMPL */
142 bta_dm_rmt_name, /* 4 BTA_DM_REMT_NAME */
143 bta_dm_sdp_result, /* 5 BTA_DM_SDP_RESULT */
144 bta_dm_search_cmpl, /* 6 BTA_DM_SEARCH_CMPL */
145 bta_dm_free_sdp_db, /* 7 BTA_DM_FREE_SDP_DB */
146 bta_dm_disc_result, /* 8 BTA_DM_DISC_RESULT */
147 bta_dm_search_result, /* 9 BTA_DM_SEARCH_RESULT */
148 bta_dm_queue_search, /* 10 BTA_DM_QUEUE_SEARCH */
149 bta_dm_queue_disc, /* 11 BTA_DM_QUEUE_DISC */
150 bta_dm_search_clear_queue, /* 12 BTA_DM_SEARCH_CLEAR_QUEUE */
151 bta_dm_search_cancel_cmpl, /* 13 BTA_DM_SEARCH_CANCEL_CMPL */
152 bta_dm_search_cancel_notify, /* 14 BTA_DM_SEARCH_CANCEL_NOTIFY */
153 bta_dm_search_cancel_transac_cmpl, /* 15 BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL
154 */
155 bta_dm_disc_rmt_name, /* 16 BTA_DM_DISC_RMT_NAME */
156 bta_dm_di_disc /* 17 BTA_DM_API_DI_DISCOVER */
Marie Janssene9e58ce2016-06-17 14:12:17 -0700157#if (BLE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800158 ,
159 bta_dm_close_gatt_conn
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700160#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800161};
162
Myles Watsoncd1fd072016-11-09 13:17:43 -0800163#define BTA_DM_SEARCH_IGNORE BTA_DM_SEARCH_NUM_ACTIONS
The Android Open Source Project5738f832012-12-12 16:00:35 -0800164/* state table information */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800165#define BTA_DM_SEARCH_ACTIONS 2 /* number of actions */
166#define BTA_DM_SEARCH_NEXT_STATE 2 /* position of next state */
167#define BTA_DM_SEARCH_NUM_COLS 3 /* number of columns in state tables */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800168
169/* state table for listen state */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800170const uint8_t bta_dm_search_idle_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800171
Myles Watsoncd1fd072016-11-09 13:17:43 -0800172 /* Event Action 1
173 Action 2 Next State */
174 /* API_SEARCH */ {BTA_DM_API_SEARCH, BTA_DM_SEARCH_IGNORE,
175 BTA_DM_SEARCH_ACTIVE},
176 /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE,
177 BTA_DM_SEARCH_IDLE},
178 /* API_SEARCH_DISC */ {BTA_DM_API_DISCOVER, BTA_DM_SEARCH_IGNORE,
179 BTA_DM_DISCOVER_ACTIVE},
180 /* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
181 BTA_DM_SEARCH_IDLE},
182 /* REMT_NAME_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
183 BTA_DM_SEARCH_IDLE},
184 /* SDP_RESULT_EVT */ {BTA_DM_FREE_SDP_DB, BTA_DM_SEARCH_IGNORE,
185 BTA_DM_SEARCH_IDLE},
186 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
187 BTA_DM_SEARCH_IDLE},
188 /* DISCV_RES_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
189 BTA_DM_SEARCH_IDLE},
190 /* API_DI_DISCOVER_EVT */ {BTA_DM_API_DI_DISCOVER, BTA_DM_SEARCH_IGNORE,
191 BTA_DM_SEARCH_ACTIVE}
Marie Janssene9e58ce2016-06-17 14:12:17 -0700192#if (BLE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800193 /* DISC_CLOSE_TOUT_EVT */,
194 {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE}
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700195#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800196};
Myles Watsoncd1fd072016-11-09 13:17:43 -0800197const uint8_t bta_dm_search_search_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800198
Myles Watsoncd1fd072016-11-09 13:17:43 -0800199 /* Event Action 1
200 Action 2 Next State */
201 /* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
202 BTA_DM_SEARCH_ACTIVE},
203 /* API_SEARCH_CANCEL */ {BTA_DM_API_SEARCH_CANCEL, BTA_DM_SEARCH_IGNORE,
204 BTA_DM_SEARCH_CANCELLING},
205 /* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
206 BTA_DM_SEARCH_ACTIVE},
207 /* INQUIRY_CMPL */ {BTA_DM_INQUIRY_CMPL, BTA_DM_SEARCH_IGNORE,
208 BTA_DM_SEARCH_ACTIVE},
209 /* REMT_NAME_EVT */ {BTA_DM_REMT_NAME, BTA_DM_SEARCH_IGNORE,
210 BTA_DM_SEARCH_ACTIVE},
211 /* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE,
212 BTA_DM_SEARCH_ACTIVE},
213 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE,
214 BTA_DM_SEARCH_IDLE},
215 /* DISCV_RES_EVT */ {BTA_DM_SEARCH_RESULT, BTA_DM_SEARCH_IGNORE,
216 BTA_DM_SEARCH_ACTIVE},
217 /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
218 BTA_DM_SEARCH_ACTIVE}
Marie Janssene9e58ce2016-06-17 14:12:17 -0700219#if (BLE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800220 /* DISC_CLOSE_TOUT_EVT */,
221 {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE}
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700222#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800223
224};
225
Myles Watsoncd1fd072016-11-09 13:17:43 -0800226const uint8_t
227 bta_dm_search_search_cancelling_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800228
Myles Watsoncd1fd072016-11-09 13:17:43 -0800229 /* Event Action 1
230 Action 2 Next State */
231 /* API_SEARCH */ {BTA_DM_QUEUE_SEARCH, BTA_DM_SEARCH_IGNORE,
232 BTA_DM_SEARCH_CANCELLING},
233 /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CLEAR_QUEUE,
234 BTA_DM_SEARCH_CANCEL_NOTIFY,
235 BTA_DM_SEARCH_CANCELLING},
236 /* API_SEARCH_DISC */ {BTA_DM_QUEUE_DISC, BTA_DM_SEARCH_IGNORE,
237 BTA_DM_SEARCH_CANCELLING},
238 /* INQUIRY_CMPL */ {BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IGNORE,
239 BTA_DM_SEARCH_IDLE},
240 /* REMT_NAME_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
241 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
242 /* SDP_RESULT_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
243 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
244 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
245 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
246 /* DISCV_RES_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
247 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
248 /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
249 BTA_DM_SEARCH_CANCELLING}
Marie Janssene9e58ce2016-06-17 14:12:17 -0700250#if (BLE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800251 /* DISC_CLOSE_TOUT_EVT */,
252 {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING}
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700253#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800254
255};
256
Myles Watsoncd1fd072016-11-09 13:17:43 -0800257const uint8_t bta_dm_search_disc_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800258
Myles Watsoncd1fd072016-11-09 13:17:43 -0800259 /* Event Action 1
260 Action 2 Next State */
261 /* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
262 BTA_DM_DISCOVER_ACTIVE},
263 /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE,
264 BTA_DM_SEARCH_CANCELLING},
265 /* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
266 BTA_DM_DISCOVER_ACTIVE},
267 /* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
268 BTA_DM_DISCOVER_ACTIVE},
269 /* REMT_NAME_EVT */ {BTA_DM_DISC_RMT_NAME, BTA_DM_SEARCH_IGNORE,
270 BTA_DM_DISCOVER_ACTIVE},
271 /* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE,
272 BTA_DM_DISCOVER_ACTIVE},
273 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE,
274 BTA_DM_SEARCH_IDLE},
275 /* DISCV_RES_EVT */ {BTA_DM_DISC_RESULT, BTA_DM_SEARCH_IGNORE,
276 BTA_DM_DISCOVER_ACTIVE},
277 /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
278 BTA_DM_DISCOVER_ACTIVE}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800279
Marie Janssene9e58ce2016-06-17 14:12:17 -0700280#if (BLE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800281 /* DISC_CLOSE_TOUT_EVT */,
282 {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE}
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700283#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800284};
285
Marie Janssene9e58ce2016-06-17 14:12:17 -0700286typedef const uint8_t (*tBTA_DM_ST_TBL)[BTA_DM_SEARCH_NUM_COLS];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800287
288/* state table */
289const tBTA_DM_ST_TBL bta_dm_search_st_tbl[] = {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800290 bta_dm_search_idle_st_table, bta_dm_search_search_active_st_table,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800291 bta_dm_search_search_cancelling_st_table,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800292 bta_dm_search_disc_active_st_table};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800293
294/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800295 *
296 * Function bta_dm_sm_disable
297 *
298 * Description unregister BTA DM
299 *
300 *
301 * Returns void
302 *
303 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800304void bta_dm_sm_disable() { bta_sys_deregister(BTA_ID_DM); }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800305
306/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800307 *
308 * Function bta_dm_sm_execute
309 *
310 * Description State machine event handling function for DM
311 *
312 *
313 * Returns void
314 *
315 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800316bool bta_dm_sm_execute(BT_HDR* p_msg) {
317 uint16_t event = p_msg->event & 0x00ff;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800318
Myles Watsoncd1fd072016-11-09 13:17:43 -0800319 APPL_TRACE_EVENT("bta_dm_sm_execute event:0x%x", event);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800320
Myles Watsoncd1fd072016-11-09 13:17:43 -0800321 /* execute action functions */
322 if (event < BTA_DM_NUM_ACTIONS) {
323 (*bta_dm_action[event])((tBTA_DM_MSG*)p_msg);
324 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800325
Myles Watsoncd1fd072016-11-09 13:17:43 -0800326 return true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800327}
328
329/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800330 *
331 * Function bta_dm_sm_search_disable
332 *
333 * Description unregister BTA SEARCH DM
334 *
335 *
336 * Returns void
337 *
338 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800339void bta_dm_search_sm_disable() { bta_sys_deregister(BTA_ID_DM_SEARCH); }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800340
341/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800342 *
343 * Function bta_dm_search_sm_execute
344 *
345 * Description State machine event handling function for DM
346 *
347 *
348 * Returns void
349 *
350 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800351bool bta_dm_search_sm_execute(BT_HDR* p_msg) {
352 tBTA_DM_ST_TBL state_table;
353 uint8_t action;
354 int i;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800355
Myles Watsoncd1fd072016-11-09 13:17:43 -0800356 APPL_TRACE_EVENT("bta_dm_search_sm_execute state:%d, event:0x%x",
357 bta_dm_search_cb.state, p_msg->event);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800358
Myles Watsoncd1fd072016-11-09 13:17:43 -0800359 /* look up the state table for the current state */
360 state_table = bta_dm_search_st_tbl[bta_dm_search_cb.state];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800361
Myles Watsoncd1fd072016-11-09 13:17:43 -0800362 bta_dm_search_cb.state =
363 state_table[p_msg->event & 0x00ff][BTA_DM_SEARCH_NEXT_STATE];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800364
Myles Watsoncd1fd072016-11-09 13:17:43 -0800365 /* execute action functions */
366 for (i = 0; i < BTA_DM_SEARCH_ACTIONS; i++) {
367 if ((action = state_table[p_msg->event & 0x00ff][i]) !=
368 BTA_DM_SEARCH_IGNORE) {
369 (*bta_dm_search_action[action])((tBTA_DM_MSG*)p_msg);
370 } else {
371 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800372 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800373 }
374 return true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800375}