Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2014 The Android Open Source Project |
| 4 | * Copyright 2003-2012 Broadcom Corporation |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | ******************************************************************************/ |
| 19 | |
| 20 | /****************************************************************************** |
| 21 | * |
| 22 | * This file contains action functions for MCE. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 26 | #include <arpa/inet.h> |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 27 | #include <hardware/bluetooth.h> |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 28 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 29 | #include <string.h> |
Pavlin Radoslavov | 258c253 | 2015-09-27 20:59:05 -0700 | [diff] [blame] | 30 | #include "bt_common.h" |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 31 | #include "bt_types.h" |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 32 | #include "bta_api.h" |
| 33 | #include "bta_mce_api.h" |
| 34 | #include "bta_mce_int.h" |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 35 | #include "bta_sys.h" |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 36 | #include "btm_api.h" |
| 37 | #include "btm_int.h" |
| 38 | #include "sdp_api.h" |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 39 | #include "utl.h" |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 40 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 41 | using bluetooth::Uuid; |
| 42 | |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 43 | /***************************************************************************** |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 44 | * Constants |
| 45 | ****************************************************************************/ |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 46 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 47 | static const Uuid bta_mce_mas_uuid = |
| 48 | Uuid::From16Bit(UUID_SERVCLASS_MESSAGE_ACCESS); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 49 | |
| 50 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 51 | * |
| 52 | * Function bta_mce_search_cback |
| 53 | * |
| 54 | * Description Callback from btm after search is completed |
| 55 | * |
| 56 | * Returns void |
| 57 | * |
| 58 | ******************************************************************************/ |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 59 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 60 | static void bta_mce_search_cback(uint16_t result, void* user_data) { |
| 61 | tSDP_DISC_REC* p_rec = NULL; |
| 62 | tBTA_MCE_MAS_DISCOVERY_COMP evt_data; |
| 63 | int found = 0; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 64 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 65 | APPL_TRACE_DEBUG("bta_mce_start_discovery_cback res: 0x%x", result); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 66 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 67 | bta_mce_cb.sdp_active = BTA_MCE_SDP_ACT_NONE; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 68 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 69 | if (bta_mce_cb.p_dm_cback == NULL) return; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 70 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 71 | evt_data.status = BTA_MCE_FAILURE; |
Jakub Pawlowski | 98b1b94 | 2017-06-16 10:54:34 -0700 | [diff] [blame] | 72 | evt_data.remote_addr = bta_mce_cb.remote_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 73 | evt_data.num_mas = 0; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 74 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 75 | if (result == SDP_SUCCESS || result == SDP_DB_FULL) { |
| 76 | do { |
| 77 | tSDP_DISC_ATTR* p_attr; |
| 78 | tSDP_PROTOCOL_ELEM pe; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 79 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 80 | p_rec = SDP_FindServiceUUIDInDb(p_bta_mce_cfg->p_sdp_db, bta_mce_mas_uuid, |
| 81 | p_rec); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 82 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 83 | APPL_TRACE_DEBUG("p_rec:%p", p_rec); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 84 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 85 | if (p_rec == NULL) break; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 86 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 87 | if (!SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) |
| 88 | continue; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 89 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 90 | evt_data.mas[found].scn = pe.params[0]; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 91 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 92 | p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME); |
| 93 | if (p_attr == NULL) continue; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 94 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 95 | evt_data.mas[found].p_srv_name = (char*)p_attr->attr_value.v.array; |
| 96 | evt_data.mas[found].srv_name_len = |
| 97 | SDP_DISC_ATTR_LEN(p_attr->attr_len_type); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 98 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 99 | p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAS_INSTANCE_ID); |
| 100 | if (p_attr == NULL) break; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 101 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 102 | evt_data.mas[found].instance_id = p_attr->attr_value.v.u8; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 103 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 104 | p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_MSG_TYPE); |
| 105 | if (p_attr == NULL) break; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 106 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 107 | evt_data.mas[found].msg_type = p_attr->attr_value.v.u8; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 108 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 109 | found++; |
| 110 | } while (p_rec != NULL && found < BTA_MCE_MAX_MAS_INSTANCES); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 111 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 112 | evt_data.num_mas = found; |
| 113 | evt_data.status = BTA_MCE_SUCCESS; |
| 114 | } |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 115 | |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 116 | tBTA_MCE bta_mce; |
| 117 | bta_mce.mas_disc_comp = evt_data; |
| 118 | bta_mce_cb.p_dm_cback(BTA_MCE_MAS_DISCOVERY_COMP_EVT, &bta_mce, user_data); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 122 | * |
| 123 | * Function bta_mce_enable |
| 124 | * |
| 125 | * Description Initializes the MCE I/F |
| 126 | * |
| 127 | * Returns void |
| 128 | * |
| 129 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 130 | void bta_mce_enable(tBTA_MCE_MSG* p_data) { |
| 131 | tBTA_MCE_STATUS status = BTA_MCE_SUCCESS; |
| 132 | bta_mce_cb.p_dm_cback = p_data->enable.p_cback; |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 133 | tBTA_MCE bta_mce; |
| 134 | bta_mce.status = status; |
| 135 | bta_mce_cb.p_dm_cback(BTA_MCE_ENABLE_EVT, &bta_mce, NULL); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 139 | * |
| 140 | * Function bta_mce_get_remote_mas_instances |
| 141 | * |
| 142 | * Description Discovers MAS instances on remote device |
| 143 | * |
| 144 | * Returns void |
| 145 | * |
| 146 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 147 | void bta_mce_get_remote_mas_instances(tBTA_MCE_MSG* p_data) { |
| 148 | if (p_data == NULL) { |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 149 | APPL_TRACE_DEBUG("MCE control block handle is null"); |
| 150 | return; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 151 | } |
| 152 | tBTA_MCE_STATUS status = BTA_MCE_FAILURE; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 153 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 154 | APPL_TRACE_DEBUG("%s in, sdp_active:%d", __func__, bta_mce_cb.sdp_active); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 155 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 156 | if (bta_mce_cb.sdp_active != BTA_MCE_SDP_ACT_NONE) { |
| 157 | /* SDP is still in progress */ |
| 158 | status = BTA_MCE_BUSY; |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 159 | if (bta_mce_cb.p_dm_cback) { |
| 160 | tBTA_MCE bta_mce; |
| 161 | bta_mce.status = status; |
| 162 | bta_mce_cb.p_dm_cback(BTA_MCE_MAS_DISCOVERY_COMP_EVT, &bta_mce, NULL); |
| 163 | } |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 164 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 165 | return; |
| 166 | } |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 167 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 168 | bta_mce_cb.sdp_active = BTA_MCE_SDP_ACT_YES; |
Jakub Pawlowski | 98b1b94 | 2017-06-16 10:54:34 -0700 | [diff] [blame] | 169 | bta_mce_cb.remote_addr = p_data->get_rmt_mas.bd_addr; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 170 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 171 | SDP_InitDiscoveryDb(p_bta_mce_cfg->p_sdp_db, p_bta_mce_cfg->sdp_db_size, 1, |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 172 | &bta_mce_mas_uuid, 0, NULL); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 173 | |
Jakub Pawlowski | 98b1b94 | 2017-06-16 10:54:34 -0700 | [diff] [blame] | 174 | if (!SDP_ServiceSearchAttributeRequest2(p_data->get_rmt_mas.bd_addr, |
| 175 | p_bta_mce_cfg->p_sdp_db, |
| 176 | bta_mce_search_cback, NULL)) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 177 | bta_mce_cb.sdp_active = BTA_MCE_SDP_ACT_NONE; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 178 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 179 | /* failed to start SDP. report the failure right away */ |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 180 | if (bta_mce_cb.p_dm_cback) { |
| 181 | tBTA_MCE bta_mce; |
| 182 | bta_mce.status = status; |
| 183 | bta_mce_cb.p_dm_cback(BTA_MCE_MAS_DISCOVERY_COMP_EVT, &bta_mce, NULL); |
| 184 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 185 | } |
| 186 | /* |
| 187 | else report the result when the cback is called |
| 188 | */ |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 189 | } |