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