1 /******************************************************************************
3 * Copyright 2003-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This is the main implementation file for the BTA device manager.
23 ******************************************************************************/
26 #include "bta/dm/bta_dm_int.h"
27 #include "stack/include/bt_types.h"
29 /*****************************************************************************
31 ****************************************************************************/
34 tBTA_DM_SEARCH_CB bta_dm_search_cb;
35 tBTA_DM_DI_CB bta_dm_di_cb;
37 /*******************************************************************************
39 * Function bta_dm_sm_search_disable
41 * Description unregister BTA SEARCH DM
46 ******************************************************************************/
47 void bta_dm_search_sm_disable() { bta_sys_deregister(BTA_ID_DM_SEARCH); }
49 void bta_dm_search_set_state(uint8_t state) { bta_dm_search_cb.state = state; }
50 uint8_t bta_dm_search_get_state() { return bta_dm_search_cb.state; }
52 /*******************************************************************************
54 * Function bta_dm_search_sm_execute
56 * Description State machine event handling function for DM
61 ******************************************************************************/
62 bool bta_dm_search_sm_execute(BT_HDR_RIGID* p_msg) {
63 APPL_TRACE_EVENT("bta_dm_search_sm_execute state:%d, event:0x%x",
64 bta_dm_search_cb.state, p_msg->event);
66 tBTA_DM_MSG* message = (tBTA_DM_MSG*)p_msg;
67 switch (bta_dm_search_cb.state) {
68 case BTA_DM_SEARCH_IDLE:
69 switch (p_msg->event) {
70 case BTA_DM_API_SEARCH_EVT:
71 bta_dm_search_set_state(BTA_DM_SEARCH_ACTIVE);
72 bta_dm_search_start(message);
74 case BTA_DM_API_DISCOVER_EVT:
75 bta_dm_search_set_state(BTA_DM_DISCOVER_ACTIVE);
76 bta_dm_discover(message);
78 case BTA_DM_SDP_RESULT_EVT:
81 case BTA_DM_DISC_CLOSE_TOUT_EVT:
82 bta_dm_close_gatt_conn(message);
86 case BTA_DM_SEARCH_ACTIVE:
87 switch (p_msg->event) {
88 case BTA_DM_REMT_NAME_EVT:
89 bta_dm_rmt_name(message);
91 case BTA_DM_SDP_RESULT_EVT:
92 bta_dm_sdp_result(message);
94 case BTA_DM_SEARCH_CMPL_EVT:
97 case BTA_DM_DISCOVERY_RESULT_EVT:
98 bta_dm_search_result(message);
100 case BTA_DM_DISC_CLOSE_TOUT_EVT:
101 bta_dm_close_gatt_conn(message);
105 case BTA_DM_SEARCH_CANCELLING:
106 switch (p_msg->event) {
107 case BTA_DM_API_SEARCH_EVT:
108 bta_dm_queue_search(message);
110 case BTA_DM_API_DISCOVER_EVT:
111 bta_dm_queue_disc(message);
113 case BTA_DM_SDP_RESULT_EVT:
114 case BTA_DM_REMT_NAME_EVT:
115 case BTA_DM_SEARCH_CMPL_EVT:
116 case BTA_DM_DISCOVERY_RESULT_EVT:
117 bta_dm_search_set_state(BTA_DM_SEARCH_IDLE);
118 bta_dm_free_sdp_db();
119 bta_dm_search_cancel_notify();
120 bta_dm_search_cancel_cmpl();
124 case BTA_DM_DISCOVER_ACTIVE:
125 switch (p_msg->event) {
126 case BTA_DM_REMT_NAME_EVT:
127 bta_dm_disc_rmt_name(message);
129 case BTA_DM_SDP_RESULT_EVT:
130 bta_dm_sdp_result(message);
132 case BTA_DM_SEARCH_CMPL_EVT:
133 bta_dm_search_cmpl();
135 case BTA_DM_DISCOVERY_RESULT_EVT:
136 bta_dm_disc_result(message);