blob: d91eaba541876544caf3c632c9ca74d1917a0ca5 [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 */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080080 bta_dm_ble_observe,
Myles Watsoncd1fd072016-11-09 13:17:43 -080081 bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */
Marie Janssene9e58ce2016-06-17 14:12:17 -070082#if (BLE_PRIVACY_SPT == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -080083 bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -070084#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -080085 bta_dm_ble_set_data_length, /* BTA_DM_API_SET_DATA_LENGTH_EVT */
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -070086 bta_dm_ble_get_energy_info, /* BTA_DM_API_BLE_ENERGY_INFO_EVT */
The Android Open Source Project5738f832012-12-12 16:00:35 -080087
Myles Watsoncd1fd072016-11-09 13:17:43 -080088 bta_dm_enable_test_mode, /* BTA_DM_API_ENABLE_TEST_MODE_EVT */
89 bta_dm_disable_test_mode, /* BTA_DM_API_DISABLE_TEST_MODE_EVT */
90 bta_dm_execute_callback, /* BTA_DM_API_EXECUTE_CBACK_EVT */
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -070091
Myles Watsoncd1fd072016-11-09 13:17:43 -080092 bta_dm_remove_all_acl, /* BTA_DM_API_REMOVE_ALL_ACL_EVT */
93 bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */
The Android Open Source Project5738f832012-12-12 16:00:35 -080094};
95
The Android Open Source Project5738f832012-12-12 16:00:35 -080096/* state machine action enumeration list */
Myles Watsoncd1fd072016-11-09 13:17:43 -080097enum {
98 BTA_DM_API_SEARCH, /* 0 bta_dm_search_start */
99 BTA_DM_API_SEARCH_CANCEL, /* 1 bta_dm_search_cancel */
100 BTA_DM_API_DISCOVER, /* 2 bta_dm_discover */
101 BTA_DM_INQUIRY_CMPL, /* 3 bta_dm_inq_cmpl */
102 BTA_DM_REMT_NAME, /* 4 bta_dm_rmt_name */
103 BTA_DM_SDP_RESULT, /* 5 bta_dm_sdp_result */
104 BTA_DM_SEARCH_CMPL, /* 6 bta_dm_search_cmpl*/
105 BTA_DM_FREE_SDP_DB, /* 7 bta_dm_free_sdp_db */
106 BTA_DM_DISC_RESULT, /* 8 bta_dm_disc_result */
107 BTA_DM_SEARCH_RESULT, /* 9 bta_dm_search_result */
108 BTA_DM_QUEUE_SEARCH, /* 10 bta_dm_queue_search */
109 BTA_DM_QUEUE_DISC, /* 11 bta_dm_queue_disc */
110 BTA_DM_SEARCH_CLEAR_QUEUE, /* 12 bta_dm_search_clear_queue */
111 BTA_DM_SEARCH_CANCEL_CMPL, /* 13 bta_dm_search_cancel_cmpl */
112 BTA_DM_SEARCH_CANCEL_NOTIFY, /* 14 bta_dm_search_cancel_notify */
113 BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, /* 15 bta_dm_search_cancel_transac_cmpl */
114 BTA_DM_DISC_RMT_NAME, /* 16 bta_dm_disc_rmt_name */
115 BTA_DM_API_DI_DISCOVER, /* 17 bta_dm_di_disc */
Myles Watson90088882016-11-15 16:33:22 -0800116 BTA_DM_CLOSE_GATT_CONN, /* 18 bta_dm_close_gatt_conn */
117 BTA_DM_SEARCH_NUM_ACTIONS /* 19 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800118};
119
The Android Open Source Project5738f832012-12-12 16:00:35 -0800120/* action function list */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800121const tBTA_DM_ACTION bta_dm_search_action[] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800122
Myles Watsoncd1fd072016-11-09 13:17:43 -0800123 bta_dm_search_start, /* 0 BTA_DM_API_SEARCH */
124 bta_dm_search_cancel, /* 1 BTA_DM_API_SEARCH_CANCEL */
125 bta_dm_discover, /* 2 BTA_DM_API_DISCOVER */
126 bta_dm_inq_cmpl, /* 3 BTA_DM_INQUIRY_CMPL */
127 bta_dm_rmt_name, /* 4 BTA_DM_REMT_NAME */
128 bta_dm_sdp_result, /* 5 BTA_DM_SDP_RESULT */
129 bta_dm_search_cmpl, /* 6 BTA_DM_SEARCH_CMPL */
130 bta_dm_free_sdp_db, /* 7 BTA_DM_FREE_SDP_DB */
131 bta_dm_disc_result, /* 8 BTA_DM_DISC_RESULT */
132 bta_dm_search_result, /* 9 BTA_DM_SEARCH_RESULT */
133 bta_dm_queue_search, /* 10 BTA_DM_QUEUE_SEARCH */
134 bta_dm_queue_disc, /* 11 BTA_DM_QUEUE_DISC */
135 bta_dm_search_clear_queue, /* 12 BTA_DM_SEARCH_CLEAR_QUEUE */
136 bta_dm_search_cancel_cmpl, /* 13 BTA_DM_SEARCH_CANCEL_CMPL */
137 bta_dm_search_cancel_notify, /* 14 BTA_DM_SEARCH_CANCEL_NOTIFY */
138 bta_dm_search_cancel_transac_cmpl, /* 15 BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL
139 */
140 bta_dm_disc_rmt_name, /* 16 BTA_DM_DISC_RMT_NAME */
Myles Watson84baa7f2016-11-14 12:05:37 -0800141 bta_dm_di_disc, /* 17 BTA_DM_API_DI_DISCOVER */
Myles Watson90088882016-11-15 16:33:22 -0800142 bta_dm_close_gatt_conn};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800143
Myles Watsoncd1fd072016-11-09 13:17:43 -0800144#define BTA_DM_SEARCH_IGNORE BTA_DM_SEARCH_NUM_ACTIONS
The Android Open Source Project5738f832012-12-12 16:00:35 -0800145/* state table information */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800146#define BTA_DM_SEARCH_ACTIONS 2 /* number of actions */
147#define BTA_DM_SEARCH_NEXT_STATE 2 /* position of next state */
148#define BTA_DM_SEARCH_NUM_COLS 3 /* number of columns in state tables */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800149
150/* state table for listen state */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800151const uint8_t bta_dm_search_idle_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800152
Myles Watsoncd1fd072016-11-09 13:17:43 -0800153 /* Event Action 1
154 Action 2 Next State */
155 /* API_SEARCH */ {BTA_DM_API_SEARCH, BTA_DM_SEARCH_IGNORE,
156 BTA_DM_SEARCH_ACTIVE},
157 /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE,
158 BTA_DM_SEARCH_IDLE},
159 /* API_SEARCH_DISC */ {BTA_DM_API_DISCOVER, BTA_DM_SEARCH_IGNORE,
160 BTA_DM_DISCOVER_ACTIVE},
161 /* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
162 BTA_DM_SEARCH_IDLE},
163 /* REMT_NAME_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
164 BTA_DM_SEARCH_IDLE},
165 /* SDP_RESULT_EVT */ {BTA_DM_FREE_SDP_DB, BTA_DM_SEARCH_IGNORE,
166 BTA_DM_SEARCH_IDLE},
167 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
168 BTA_DM_SEARCH_IDLE},
169 /* DISCV_RES_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
170 BTA_DM_SEARCH_IDLE},
171 /* API_DI_DISCOVER_EVT */ {BTA_DM_API_DI_DISCOVER, BTA_DM_SEARCH_IGNORE,
Myles Watson84baa7f2016-11-14 12:05:37 -0800172 BTA_DM_SEARCH_ACTIVE},
173 /* DISC_CLOSE_TOUT_EVT */
Myles Watson90088882016-11-15 16:33:22 -0800174 {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE}};
Myles Watsoncd1fd072016-11-09 13:17:43 -0800175const uint8_t bta_dm_search_search_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800176
Myles Watsoncd1fd072016-11-09 13:17:43 -0800177 /* Event Action 1
178 Action 2 Next State */
179 /* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
180 BTA_DM_SEARCH_ACTIVE},
181 /* API_SEARCH_CANCEL */ {BTA_DM_API_SEARCH_CANCEL, BTA_DM_SEARCH_IGNORE,
182 BTA_DM_SEARCH_CANCELLING},
183 /* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
184 BTA_DM_SEARCH_ACTIVE},
185 /* INQUIRY_CMPL */ {BTA_DM_INQUIRY_CMPL, BTA_DM_SEARCH_IGNORE,
186 BTA_DM_SEARCH_ACTIVE},
187 /* REMT_NAME_EVT */ {BTA_DM_REMT_NAME, BTA_DM_SEARCH_IGNORE,
188 BTA_DM_SEARCH_ACTIVE},
189 /* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE,
190 BTA_DM_SEARCH_ACTIVE},
191 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE,
192 BTA_DM_SEARCH_IDLE},
193 /* DISCV_RES_EVT */ {BTA_DM_SEARCH_RESULT, BTA_DM_SEARCH_IGNORE,
194 BTA_DM_SEARCH_ACTIVE},
195 /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
Myles Watson84baa7f2016-11-14 12:05:37 -0800196 BTA_DM_SEARCH_ACTIVE},
197 /* DISC_CLOSE_TOUT_EVT */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800198 {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800199
200};
201
Myles Watsoncd1fd072016-11-09 13:17:43 -0800202const uint8_t
203 bta_dm_search_search_cancelling_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800204
Myles Watsoncd1fd072016-11-09 13:17:43 -0800205 /* Event Action 1
206 Action 2 Next State */
207 /* API_SEARCH */ {BTA_DM_QUEUE_SEARCH, BTA_DM_SEARCH_IGNORE,
208 BTA_DM_SEARCH_CANCELLING},
209 /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CLEAR_QUEUE,
210 BTA_DM_SEARCH_CANCEL_NOTIFY,
211 BTA_DM_SEARCH_CANCELLING},
212 /* API_SEARCH_DISC */ {BTA_DM_QUEUE_DISC, BTA_DM_SEARCH_IGNORE,
213 BTA_DM_SEARCH_CANCELLING},
214 /* INQUIRY_CMPL */ {BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IGNORE,
215 BTA_DM_SEARCH_IDLE},
216 /* REMT_NAME_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
217 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
218 /* SDP_RESULT_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
219 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
220 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
221 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
222 /* DISCV_RES_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,
223 BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
224 /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
Myles Watson84baa7f2016-11-14 12:05:37 -0800225 BTA_DM_SEARCH_CANCELLING},
226 /* DISC_CLOSE_TOUT_EVT */
Myles Watson90088882016-11-15 16:33:22 -0800227 {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800228
Myles Watsoncd1fd072016-11-09 13:17:43 -0800229const uint8_t bta_dm_search_disc_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800230
Myles Watsoncd1fd072016-11-09 13:17:43 -0800231 /* Event Action 1
232 Action 2 Next State */
233 /* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
234 BTA_DM_DISCOVER_ACTIVE},
235 /* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE,
236 BTA_DM_SEARCH_CANCELLING},
237 /* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
238 BTA_DM_DISCOVER_ACTIVE},
239 /* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
240 BTA_DM_DISCOVER_ACTIVE},
241 /* REMT_NAME_EVT */ {BTA_DM_DISC_RMT_NAME, BTA_DM_SEARCH_IGNORE,
242 BTA_DM_DISCOVER_ACTIVE},
243 /* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE,
244 BTA_DM_DISCOVER_ACTIVE},
245 /* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE,
246 BTA_DM_SEARCH_IDLE},
247 /* DISCV_RES_EVT */ {BTA_DM_DISC_RESULT, BTA_DM_SEARCH_IGNORE,
248 BTA_DM_DISCOVER_ACTIVE},
249 /* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE,
Myles Watson84baa7f2016-11-14 12:05:37 -0800250 BTA_DM_DISCOVER_ACTIVE},
251 /* DISC_CLOSE_TOUT_EVT */
Myles Watson90088882016-11-15 16:33:22 -0800252 {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800253
Marie Janssene9e58ce2016-06-17 14:12:17 -0700254typedef const uint8_t (*tBTA_DM_ST_TBL)[BTA_DM_SEARCH_NUM_COLS];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800255
256/* state table */
257const tBTA_DM_ST_TBL bta_dm_search_st_tbl[] = {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800258 bta_dm_search_idle_st_table, bta_dm_search_search_active_st_table,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800259 bta_dm_search_search_cancelling_st_table,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800260 bta_dm_search_disc_active_st_table};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800261
262/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800263 *
264 * Function bta_dm_sm_disable
265 *
266 * Description unregister BTA DM
267 *
268 *
269 * Returns void
270 *
271 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800272void bta_dm_sm_disable() { bta_sys_deregister(BTA_ID_DM); }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800273
274/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800275 *
276 * Function bta_dm_sm_execute
277 *
278 * Description State machine event handling function for DM
279 *
280 *
281 * Returns void
282 *
283 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800284bool bta_dm_sm_execute(BT_HDR* p_msg) {
285 uint16_t event = p_msg->event & 0x00ff;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800286
Myles Watsoncd1fd072016-11-09 13:17:43 -0800287 APPL_TRACE_EVENT("bta_dm_sm_execute event:0x%x", event);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800288
Myles Watsoncd1fd072016-11-09 13:17:43 -0800289 /* execute action functions */
290 if (event < BTA_DM_NUM_ACTIONS) {
291 (*bta_dm_action[event])((tBTA_DM_MSG*)p_msg);
292 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800293
Myles Watsoncd1fd072016-11-09 13:17:43 -0800294 return true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800295}
296
297/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800298 *
299 * Function bta_dm_sm_search_disable
300 *
301 * Description unregister BTA SEARCH DM
302 *
303 *
304 * Returns void
305 *
306 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800307void bta_dm_search_sm_disable() { bta_sys_deregister(BTA_ID_DM_SEARCH); }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800308
309/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800310 *
311 * Function bta_dm_search_sm_execute
312 *
313 * Description State machine event handling function for DM
314 *
315 *
316 * Returns void
317 *
318 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800319bool bta_dm_search_sm_execute(BT_HDR* p_msg) {
320 tBTA_DM_ST_TBL state_table;
321 uint8_t action;
322 int i;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800323
Myles Watsoncd1fd072016-11-09 13:17:43 -0800324 APPL_TRACE_EVENT("bta_dm_search_sm_execute state:%d, event:0x%x",
325 bta_dm_search_cb.state, p_msg->event);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800326
Myles Watsoncd1fd072016-11-09 13:17:43 -0800327 /* look up the state table for the current state */
328 state_table = bta_dm_search_st_tbl[bta_dm_search_cb.state];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800329
Myles Watsoncd1fd072016-11-09 13:17:43 -0800330 bta_dm_search_cb.state =
331 state_table[p_msg->event & 0x00ff][BTA_DM_SEARCH_NEXT_STATE];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800332
Myles Watsoncd1fd072016-11-09 13:17:43 -0800333 /* execute action functions */
334 for (i = 0; i < BTA_DM_SEARCH_ACTIONS; i++) {
Marie Janssenf33b6f42016-11-22 15:01:42 -0800335 action = state_table[p_msg->event & 0x00ff][i];
336 if (action != BTA_DM_SEARCH_IGNORE) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800337 (*bta_dm_search_action[action])((tBTA_DM_MSG*)p_msg);
338 } else {
339 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800340 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800341 }
342 return true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800343}