The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008-2014 Broadcom Corporation |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 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 file contains functions for BLE GAP. |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | |
| 25 | #include <string.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stddef.h> |
| 28 | |
| 29 | #include "bt_types.h" |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 30 | #include "bt_utils.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 31 | #include "btu.h" |
| 32 | #include "btm_int.h" |
| 33 | #include "hcimsgs.h" |
| 34 | #if (GAP_INCLUDED == TRUE) |
| 35 | #include "gap_api.h" |
| 36 | #endif |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 37 | |
| 38 | #if BLE_INCLUDED == TRUE |
| 39 | |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 40 | #include "vendor_ble.h" |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 41 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 42 | #include "gattdefs.h" |
Nitin Arora | 021e17a | 2014-01-29 19:18:39 -0800 | [diff] [blame] | 43 | #include "gatt_int.h" |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 44 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 45 | #include "btm_ble_int.h" |
| 46 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 47 | #define BTM_BLE_NAME_SHORT 0x01 |
| 48 | #define BTM_BLE_NAME_CMPL 0x02 |
| 49 | |
| 50 | #define BTM_BLE_FILTER_TARGET_UNKNOWN 0xff |
| 51 | #define BTM_BLE_POLICY_UNKNOWN 0xff |
| 52 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 53 | #define BTM_EXT_BLE_RMT_NAME_TIMEOUT 30 |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 54 | #define MIN_ADV_LENGTH 2 |
| 55 | |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 56 | static tBTM_BLE_VSC_CB cmn_ble_vsc_cb; |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 57 | static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL; |
| 58 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 59 | /******************************************************************************* |
| 60 | ** Local functions |
| 61 | *******************************************************************************/ |
| 62 | static void btm_ble_update_adv_flag(UINT8 flag); |
| 63 | static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt_type, UINT8 *p); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 64 | UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst, |
| 65 | tBTM_BLE_ADV_DATA *p_data); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 66 | static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, |
| 67 | BD_ADDR_PTR p_addr_ptr, |
| 68 | tBLE_ADDR_TYPE *p_init_addr_type, |
| 69 | tBLE_ADDR_TYPE *p_own_addr_type); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 70 | static void btm_ble_stop_observe(void); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 71 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 72 | #define BTM_BLE_INQ_RESULT 0x01 |
| 73 | #define BTM_BLE_OBS_RESULT 0x02 |
| 74 | #define BTM_BLE_SEL_CONN_RESULT 0x04 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 75 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 76 | /* LE states combo bit to check */ |
| 77 | const UINT8 btm_le_state_combo_tbl[BTM_BLE_STATE_MAX][BTM_BLE_STATE_MAX][2] = |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 78 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 79 | {/* single state support */ |
| 80 | {HCI_SUPP_LE_STATES_CONN_ADV_MASK, HCI_SUPP_LE_STATES_CONN_ADV_OFF}, /* conn_adv */ |
| 81 | {HCI_SUPP_LE_STATES_INIT_MASK, HCI_SUPP_LE_STATES_INIT_OFF}, /* init */ |
| 82 | {HCI_SUPP_LE_STATES_INIT_MASK, HCI_SUPP_LE_STATES_INIT_OFF}, /* master */ |
| 83 | {HCI_SUPP_LE_STATES_SLAVE_MASK, HCI_SUPP_LE_STATES_SLAVE_OFF}, /* slave */ |
| 84 | {0, 0}, /* todo: lo du dir adv, not covered ? */ |
| 85 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF}, /* hi duty dir adv */ |
| 86 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF}, /* non connectable adv */ |
| 87 | {HCI_SUPP_LE_STATES_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_OFF}, /* passive scan */ |
| 88 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF}, /* active scan */ |
| 89 | {HCI_SUPP_LE_STATES_SCAN_ADV_MASK, HCI_SUPP_LE_STATESSCAN_ADV_OFF} /* scanable adv */ |
| 90 | }, |
| 91 | { /* conn_adv =0 */ |
| 92 | {0, 0}, /* conn_adv */ |
| 93 | {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* init: 32 */ |
| 94 | {HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF}, /* master: 35 */ |
| 95 | {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* slave: 38,*/ |
| 96 | {0, 0}, /* lo du dir adv */ |
| 97 | {0, 0}, /* hi duty dir adv */ |
| 98 | {0, 0}, /* non connectable adv */ |
| 99 | {HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF}, /* passive scan */ |
| 100 | {HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ |
| 101 | {0, 0} /* scanable adv */ |
| 102 | }, |
| 103 | { /* init */ |
| 104 | {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* conn_adv: 32 */ |
| 105 | {0, 0}, /* init */ |
| 106 | {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* master 28 */ |
| 107 | {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* slave 41 */ |
| 108 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF} ,/* lo du dir adv 34 */ |
| 109 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF}, /* hi duty dir adv 33 */ |
| 110 | {HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK, HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF}, /* non connectable adv */ |
| 111 | {HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF}, /* passive scan */ |
| 112 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF}, /* active scan */ |
| 113 | {HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF} /* scanable adv */ |
| 114 | |
| 115 | }, |
| 116 | { /* master */ |
| 117 | {HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF}, /* conn_adv: 35 */ |
| 118 | {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* init 28 */ |
| 119 | {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* master 28 */ |
| 120 | {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* slave: 32 */ |
| 121 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF}, /* lo duty cycle adv 37 */ |
| 122 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF}, /* hi duty cycle adv 36 */ |
| 123 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF}, /* non connectable adv */ |
| 124 | {HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF}, /* passive scan */ |
| 125 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF}, /* active scan */ |
| 126 | {HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF} /* scanable adv */ |
| 127 | |
| 128 | }, |
| 129 | { /* slave */ |
| 130 | {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* conn_adv: 38,*/ |
| 131 | {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* init 41 */ |
| 132 | {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* master 41 */ |
| 133 | {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* slave: 38,*/ |
| 134 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF}, /* lo duty cycle adv 40 */ |
| 135 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF}, /* hi duty cycle adv 39 */ |
| 136 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF}, /* non connectable adv */ |
| 137 | {HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF}, /* passive scan */ |
| 138 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF}, /* active scan */ |
| 139 | {HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF} /* scanable adv */ |
| 140 | |
| 141 | }, |
| 142 | { /* lo duty cycle adv */ |
| 143 | {0, 0}, /* conn_adv: 38,*/ |
| 144 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF} ,/* init 34 */ |
| 145 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF}, /* master 37 */ |
| 146 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF}, /* slave: 40 */ |
| 147 | {0, 0}, /* lo duty cycle adv 40 */ |
| 148 | {0, 0}, /* hi duty cycle adv 39 */ |
| 149 | {0, 0}, /* non connectable adv */ |
| 150 | {0, 0}, /* TODO: passive scan, not covered? */ |
| 151 | {0, 0}, /* TODO: active scan, not covered? */ |
| 152 | {0, 0} /* scanable adv */ |
| 153 | }, |
| 154 | { /* hi duty cycle adv */ |
| 155 | {0, 0}, /* conn_adv: 38,*/ |
| 156 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF}, /* init 33 */ |
| 157 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF}, /* master 36 */ |
| 158 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF}, /* slave: 39*/ |
| 159 | {0, 0}, /* lo duty cycle adv 40 */ |
| 160 | {0, 0}, /* hi duty cycle adv 39 */ |
| 161 | {0, 0}, /* non connectable adv */ |
| 162 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF}, /* passive scan */ |
| 163 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF}, /* active scan */ |
| 164 | {0, 0} /* scanable adv */ |
| 165 | }, |
| 166 | { /* non connectable adv */ |
| 167 | {0, 0}, /* conn_adv: */ |
| 168 | {HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK, HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF}, /* init */ |
| 169 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF}, /* master */ |
| 170 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF}, /* slave: */ |
| 171 | {0, 0}, /* lo duty cycle adv */ |
| 172 | {0, 0}, /* hi duty cycle adv */ |
| 173 | {0, 0}, /* non connectable adv */ |
| 174 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF}, /* passive scan */ |
| 175 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ |
| 176 | {0, 0} /* scanable adv */ |
| 177 | }, |
| 178 | { /* passive scan */ |
| 179 | {HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF}, /* conn_adv: */ |
| 180 | {HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF}, /* init */ |
| 181 | {HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF}, /* master */ |
| 182 | {HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF}, /* slave: */ |
| 183 | {0, 0}, /* lo duty cycle adv */ |
| 184 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF}, /* hi duty cycle adv */ |
| 185 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF}, /* non connectable adv */ |
| 186 | {0, 0}, /* passive scan */ |
| 187 | {0, 0}, /* active scan */ |
| 188 | {HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF} /* scanable adv */ |
| 189 | }, |
| 190 | { /* active scan */ |
| 191 | {HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF}, /* conn_adv: */ |
| 192 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF}, /* init */ |
| 193 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF}, /* master */ |
| 194 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF}, /* slave: */ |
| 195 | {0, 0}, /* lo duty cycle adv */ |
| 196 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF}, /* hi duty cycle adv */ |
| 197 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF}, /* non connectable adv */ |
| 198 | {0, 0}, /* TODO: passive scan */ |
| 199 | {0, 0}, /* TODO: active scan */ |
| 200 | {HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF} /* scanable adv */ |
| 201 | }, |
| 202 | { /* scanable adv */ |
| 203 | {0, 0}, /* conn_adv: */ |
| 204 | {HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF}, /* init */ |
| 205 | {HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF}, /* master */ |
| 206 | {HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF}, /* slave: */ |
| 207 | {0, 0}, /* lo duty cycle adv */ |
| 208 | {0, 0}, /* hi duty cycle adv */ |
| 209 | {0, 0}, /* non connectable adv */ |
| 210 | {HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF}, /* passive scan */ |
| 211 | {HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ |
| 212 | {0, 0} /* scanable adv */ |
| 213 | } |
| 214 | |
| 215 | }; |
| 216 | /* check LE combo state supported */ |
| 217 | #define BTM_LE_STATES_SUPPORTED(x, y, z) ((x)[(z)] & (y)) |
| 218 | |
| 219 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 220 | /******************************************************************************* |
| 221 | ** |
| 222 | ** Function BTM_BleUpdateAdvWhitelist |
| 223 | ** |
| 224 | ** Description Add or remove device from advertising white list |
| 225 | ** |
| 226 | ** Returns void |
| 227 | ** |
| 228 | *******************************************************************************/ |
| 229 | BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda) |
| 230 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 231 | UNUSED(add_remove); |
| 232 | UNUSED(remote_bda); |
| 233 | |
| 234 | return FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 235 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 236 | |
| 237 | /******************************************************************************* |
| 238 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 239 | ** Function BTM_BleUpdateAdvFilterPolicy |
| 240 | ** |
| 241 | ** Description This function update the filter policy of advertiser. |
| 242 | ** |
| 243 | ** Parameter adv_policy: advertising filter policy |
| 244 | ** |
| 245 | ** Return void |
| 246 | *******************************************************************************/ |
| 247 | void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy) |
| 248 | { |
| 249 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 250 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; |
| 251 | BD_ADDR p_addr_ptr= {0}; |
| 252 | UINT8 adv_mode = p_cb->adv_mode; |
| 253 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 254 | BTM_TRACE_EVENT ("BTM_BleUpdateAdvFilterPolicy"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 255 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 256 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 257 | return; |
| 258 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 259 | if (p_cb->afp != adv_policy) |
| 260 | { |
| 261 | p_cb->afp = adv_policy; |
| 262 | |
| 263 | /* if adv active, stop and restart */ |
| 264 | btm_ble_stop_adv (); |
| 265 | |
| 266 | if (p_cb->connectable_mode & BTM_BLE_CONNECTABLE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 267 | p_cb->evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, |
| 268 | &p_cb->adv_addr_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 269 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 270 | btsnd_hcic_ble_write_adv_params ((UINT16)(p_cb->adv_interval_min ? p_cb->adv_interval_min : |
| 271 | BTM_BLE_GAP_ADV_SLOW_INT), |
| 272 | (UINT16)(p_cb->adv_interval_max ? p_cb->adv_interval_max : |
| 273 | BTM_BLE_GAP_ADV_SLOW_INT), |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 274 | p_cb->evt_type, |
| 275 | p_cb->adv_addr_type, |
| 276 | init_addr_type, |
| 277 | p_addr_ptr, |
| 278 | p_cb->adv_chnl_map, |
| 279 | p_cb->afp); |
| 280 | |
| 281 | if (adv_mode == BTM_BLE_ADV_ENABLE) |
| 282 | btm_ble_start_adv (); |
| 283 | |
| 284 | } |
| 285 | } |
| 286 | /******************************************************************************* |
| 287 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 288 | ** Function BTM_BleObserve |
| 289 | ** |
| 290 | ** Description This procedure keep the device listening for advertising |
| 291 | ** events from a broadcast device. |
| 292 | ** |
| 293 | ** Parameters start: start or stop observe. |
| 294 | ** white_list: use white list in observer mode or not. |
| 295 | ** |
| 296 | ** Returns void |
| 297 | ** |
| 298 | *******************************************************************************/ |
| 299 | tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration, |
| 300 | tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb) |
| 301 | { |
| 302 | tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 303 | tBTM_STATUS status = BTM_WRONG_MODE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 304 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 305 | BTM_TRACE_EVENT ("BTM_BleObserve : scan_type:%d",btm_cb.btm_inq_vars.scan_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 306 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 307 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 308 | return BTM_ILLEGAL_VALUE; |
| 309 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 310 | if (start) |
| 311 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 312 | /* shared inquiry database, do not allow observe if any inquiry is active */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 313 | if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 314 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 315 | BTM_TRACE_ERROR("Observe Already Active"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 316 | return status; |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 317 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 318 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 319 | btm_cb.ble_ctr_cb.p_obs_results_cb = p_results_cb; |
| 320 | btm_cb.ble_ctr_cb.p_obs_cmpl_cb = p_cmpl_cb; |
| 321 | status = BTM_CMD_STARTED; |
| 322 | |
| 323 | /* scan is not started */ |
| 324 | if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
| 325 | { |
| 326 | p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type; |
| 327 | /* allow config scanning type */ |
| 328 | btsnd_hcic_ble_set_scan_params (p_inq->scan_type, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 329 | (UINT16)(!p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval), |
| 330 | (UINT16)(!p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window), |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 331 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, |
| 332 | BTM_BLE_DEFAULT_SFP); /* assume observe always not using white list */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 333 | |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 334 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
| 335 | /* enable IRK list */ |
| 336 | btm_ble_vendor_irk_list_known_dev (TRUE); |
| 337 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 338 | status = btm_ble_start_scan(BTM_BLE_DUPLICATE_DISABLE); |
| 339 | } |
| 340 | if (status == BTM_CMD_STARTED) |
| 341 | { |
| 342 | btm_cb.ble_ctr_cb.scan_activity |= BTM_LE_OBSERVE_ACTIVE; |
| 343 | |
| 344 | if (duration != 0) |
| 345 | /* start observer timer */ |
| 346 | btu_start_timer (&btm_cb.ble_ctr_cb.obs_timer_ent, BTU_TTYPE_BLE_OBSERVE, duration); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 347 | } |
| 348 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 349 | else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 350 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 351 | status = BTM_CMD_STARTED; |
| 352 | btm_ble_stop_observe(); |
| 353 | } |
| 354 | else |
| 355 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 356 | BTM_TRACE_ERROR("Observe not active"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | return status; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 360 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /******************************************************************************* |
| 364 | ** |
| 365 | ** Function BTM_BleBroadcast |
| 366 | ** |
| 367 | ** Description This function is to start or stop broadcasting. |
| 368 | ** |
| 369 | ** Parameters start: start or stop broadcasting. |
| 370 | ** |
| 371 | ** Returns status. |
| 372 | ** |
| 373 | *******************************************************************************/ |
| 374 | tBTM_STATUS BTM_BleBroadcast(BOOLEAN start) |
| 375 | { |
| 376 | tBTM_STATUS status = BTM_NO_RESOURCES; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 377 | tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 378 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 379 | UINT8 evt_type = p_cb->scan_rsp ? BTM_BLE_DISCOVER_EVT: BTM_BLE_NON_CONNECT_EVT; |
| 380 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 381 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 382 | return BTM_ILLEGAL_VALUE; |
| 383 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 384 | #ifdef BTM_BLE_PC_ADV_TEST_MODE |
| 385 | if (BTM_BLE_PC_ADV_TEST_MODE) |
| 386 | { |
| 387 | evt_type = p_cb->scan_rsp ? BTM_BLE_CONNECT_EVT: BTM_BLE_NON_CONNECT_EVT; |
| 388 | } |
| 389 | #endif |
| 390 | |
| 391 | if (start && p_cb->adv_mode == BTM_BLE_ADV_DISABLE) |
| 392 | { |
| 393 | /* update adv params */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 394 | if (!btsnd_hcic_ble_write_adv_params ((UINT16)(p_cb->adv_interval_min ? p_cb->adv_interval_min : |
| 395 | BTM_BLE_GAP_ADV_INT), |
| 396 | (UINT16)(p_cb->adv_interval_max ? p_cb->adv_interval_max : |
| 397 | BTM_BLE_GAP_ADV_INT), |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 398 | evt_type, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 399 | p_addr_cb->own_addr_type, |
| 400 | p_cb->direct_bda.type, |
| 401 | p_cb->direct_bda.bda, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 402 | p_cb->adv_chnl_map, |
| 403 | p_cb->afp)) |
| 404 | |
| 405 | status = BTM_NO_RESOURCES; |
| 406 | else |
| 407 | p_cb->evt_type = evt_type; |
| 408 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 409 | status = btm_ble_start_adv (); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 410 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 411 | else if (!start) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 412 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 413 | status = btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 414 | } |
| 415 | else |
| 416 | { |
| 417 | status = BTM_WRONG_MODE; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 418 | BTM_TRACE_ERROR("Can not %s Broadcast, device %s in Broadcast mode", |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 419 | (start ? "Start" : "Stop"), (start ? "already" :"not")); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 420 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 421 | return status; |
| 422 | } |
| 423 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 424 | /******************************************************************************* |
| 425 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 426 | ** Function btm_vsc_brcm_features_complete |
| 427 | ** |
| 428 | ** Description Command Complete callback for HCI_BLE_VENDOR_CAP_OCF |
| 429 | ** |
| 430 | ** Returns void |
| 431 | ** |
| 432 | *******************************************************************************/ |
| 433 | static void btm_ble_vendor_capability_vsc_cmpl_cback (tBTM_VSC_CMPL *p_vcs_cplt_params) |
| 434 | { |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 435 | #if BLE_VND_INCLUDED == TRUE |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 436 | UINT8 status = 0xFF, *p; |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 437 | |
| 438 | BTM_TRACE_DEBUG("btm_ble_vendor_capability_vsc_cmpl_cback"); |
| 439 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 440 | /* Check status of command complete event */ |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 441 | if ((p_vcs_cplt_params->opcode == HCI_BLE_VENDOR_CAP_OCF) &&(p_vcs_cplt_params->param_len > 0)) |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 442 | { |
| 443 | p = p_vcs_cplt_params->p_param_buf; |
| 444 | STREAM_TO_UINT8 (status, p); |
| 445 | } |
| 446 | |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 447 | if (status == HCI_SUCCESS) |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 448 | { |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 449 | STREAM_TO_UINT8 (btm_cb.cmn_ble_vsc_cb.adv_inst_max, p); |
| 450 | STREAM_TO_UINT8 (btm_cb.cmn_ble_vsc_cb.rpa_offloading, p); |
| 451 | STREAM_TO_UINT16 (btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg, p); |
| 452 | STREAM_TO_UINT8 (btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, p); |
| 453 | STREAM_TO_UINT8 (btm_cb.cmn_ble_vsc_cb.filter_support, p); |
| 454 | STREAM_TO_UINT8 (btm_cb.cmn_ble_vsc_cb.max_filter, p); |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 455 | STREAM_TO_UINT8 (btm_cb.cmn_ble_vsc_cb.energy_support, p); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 456 | } |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 457 | |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 458 | BTM_TRACE_DEBUG("btm_ble_vnd_cap_vsc_cmpl_cback: stat=%d, irk=%d, ADV ins:%d, rpa=%d, ener=%d", |
| 459 | status, btm_ble_vendor_cb.irk_avail_size, btm_cb.cmn_ble_vsc_cb.adv_inst_max, |
| 460 | btm_cb.cmn_ble_vsc_cb.rpa_offloading, btm_cb.cmn_ble_vsc_cb.energy_support); |
| 461 | |
| 462 | if (BTM_BleMaxMultiAdvInstanceCount() > 0) |
| 463 | btm_ble_multi_adv_init(); |
| 464 | |
| 465 | if (btm_cb.cmn_ble_vsc_cb.max_filter > 0) |
| 466 | { |
| 467 | btm_ble_adv_filter_init(); |
| 468 | btm_ble_vendor_init(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz); |
| 469 | } |
| 470 | |
| 471 | if (btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg > 0) |
| 472 | btm_ble_batchscan_init(); |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 473 | |
| 474 | if (p_ctrl_le_feature_rd_cmpl_cback != NULL) |
| 475 | p_ctrl_le_feature_rd_cmpl_cback(status); |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 476 | |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 477 | #else |
| 478 | UNUSED(p_vcs_cplt_params); |
| 479 | #endif |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /******************************************************************************* |
| 483 | ** |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 484 | ** Function BTM_BleGetVendorCapabilities |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 485 | ** |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 486 | ** Description This function reads local LE features |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 487 | ** |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 488 | ** Parameters p_cmn_vsc_cb : Locala LE capability structure |
| 489 | ** |
| 490 | ** Returns void |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 491 | ** |
| 492 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 493 | BTM_API extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb) |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 494 | { |
Satya Calloji | 1a9247a | 2014-06-05 13:15:15 -0700 | [diff] [blame] | 495 | BTM_TRACE_DEBUG("BTM_BleGetVendorCapabilities"); |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 496 | |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 497 | if (NULL != p_cmn_vsc_cb) |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 498 | { |
| 499 | *p_cmn_vsc_cb = btm_cb.cmn_ble_vsc_cb; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | /****************************************************************************** |
| 504 | ** |
| 505 | ** Function BTM_BleReadControllerFeatures |
| 506 | ** |
| 507 | ** Description Reads BLE specific controller features |
| 508 | ** |
| 509 | ** Parameters: tBTM_BLE_CTRL_FEATURES_CBACK : Callback to notify when features are read |
| 510 | ** |
| 511 | ** Returns void |
| 512 | ** |
| 513 | *******************************************************************************/ |
| 514 | BTM_API extern void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK *p_vsc_cback) |
| 515 | { |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 516 | #if BLE_VND_INCLUDED == TRUE |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 517 | BTM_TRACE_DEBUG("BTM_BleReadControllerFeatures"); |
| 518 | |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 519 | p_ctrl_le_feature_rd_cmpl_cback = p_vsc_cback; |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 520 | if ( BTM_VendorSpecificCommand (HCI_BLE_VENDOR_CAP_OCF, |
| 521 | 0, |
| 522 | NULL, |
| 523 | btm_ble_vendor_capability_vsc_cmpl_cback) |
| 524 | != BTM_CMD_STARTED) |
| 525 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 526 | BTM_TRACE_ERROR("LE Get_Vendor Capabilities Command Failed."); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 527 | } |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 528 | #else |
| 529 | UNUSED(p_vsc_cback); |
| 530 | #endif |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 531 | return ; |
| 532 | } |
| 533 | |
| 534 | /******************************************************************************* |
| 535 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 536 | ** Function BTM_RegisterScanReqEvt |
| 537 | ** |
| 538 | ** Description This function is called to register a scan request callback |
| 539 | ** on the advertiser. |
| 540 | ** |
| 541 | ** Parameters p_scan_req_cback: scan request callback. If NULL, remove the |
| 542 | ** registration. |
| 543 | ** |
| 544 | ** Returns void |
| 545 | ** |
| 546 | *******************************************************************************/ |
| 547 | void BTM_RegisterScanReqEvt(tBTM_BLE_SCAN_REQ_CBACK *p_scan_req_cback) |
| 548 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 549 | #ifdef BTM_BLE_PC_ADV_TEST_MODE /* For general stack code (e.g. BTInsight testing), we simply do not define it to exclude or set it to TRUE to include */ |
| 550 | if (BTM_BLE_PC_ADV_TEST_MODE) /* For stack component, it is always defined and maps to a global variable g_bDraculaAdvertisingMode */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 551 | { |
| 552 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 553 | p_cb->p_scan_req_cback = p_scan_req_cback; |
| 554 | } |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 555 | #else |
| 556 | UNUSED(p_scan_req_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 557 | #endif |
| 558 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 559 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 560 | /******************************************************************************* |
| 561 | ** |
| 562 | ** Function BTM_BleConfigPrivacy |
| 563 | ** |
| 564 | ** Description This function is called to enable or disable the privacy in |
| 565 | ** LE channel of the local device. |
| 566 | ** |
| 567 | ** Parameters enable: TRUE to enable it; FALSE to disable it. |
| 568 | ** |
| 569 | ** Returns void |
| 570 | ** |
| 571 | *******************************************************************************/ |
| 572 | void BTM_BleConfigPrivacy(BOOLEAN enable) |
| 573 | { |
| 574 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 575 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 576 | BTM_TRACE_EVENT (" BTM_BleConfigPrivacy"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 577 | |
| 578 | if (p_cb->privacy != enable) |
| 579 | { |
| 580 | p_cb->privacy = enable; |
| 581 | |
| 582 | if (p_cb->privacy) |
| 583 | { |
| 584 | /* generate resolvable private address */ |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 585 | btm_gen_resolvable_private_addr(NULL); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 586 | } |
| 587 | else /* if privacy disabled, always use public address */ |
| 588 | { |
| 589 | p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_PUBLIC; |
| 590 | } |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 591 | |
| 592 | if (BTM_BleMaxMultiAdvInstanceCount() > 0) |
| 593 | btm_ble_multi_adv_enb_privacy(p_cb->privacy); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 597 | /******************************************************************************* |
| 598 | ** |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 599 | ** Function BTM_BleMaxMultiAdvInstanceCount |
| 600 | ** |
| 601 | ** Description Returns max number of multi adv instances supported by controller |
| 602 | ** |
| 603 | ** Returns Max multi adv instance count |
| 604 | ** |
| 605 | *******************************************************************************/ |
| 606 | BTM_API extern UINT8 BTM_BleMaxMultiAdvInstanceCount() |
| 607 | { |
| 608 | return btm_cb.cmn_ble_vsc_cb.adv_inst_max; |
| 609 | } |
| 610 | |
| 611 | #if BLE_PRIVACY_SPT == TRUE |
| 612 | /******************************************************************************* |
| 613 | ** |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 614 | ** Function btm_ble_resolve_random_addr_on_adv |
| 615 | ** |
| 616 | ** Description resolve random address complete callback. |
| 617 | ** |
| 618 | ** Returns void |
| 619 | ** |
| 620 | *******************************************************************************/ |
| 621 | static void btm_ble_resolve_random_addr_on_adv(void * p_rec, void *p) |
| 622 | { |
| 623 | tBTM_SEC_DEV_REC *match_rec = (tBTM_SEC_DEV_REC *) p_rec; |
| 624 | UINT8 addr_type = BLE_ADDR_RANDOM; |
| 625 | BD_ADDR bda; |
| 626 | UINT8 *pp = (UINT8 *)p + 1; |
| 627 | UINT8 evt_type; |
| 628 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 629 | BTM_TRACE_EVENT ("btm_ble_resolve_random_addr_on_adv "); |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 630 | |
| 631 | STREAM_TO_UINT8 (evt_type, pp); |
| 632 | STREAM_TO_UINT8 (addr_type, pp); |
| 633 | STREAM_TO_BDADDR (bda, pp); |
| 634 | |
| 635 | if (match_rec) |
| 636 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 637 | BTM_TRACE_ERROR("Random match"); |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 638 | match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA; |
| 639 | memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); |
| 640 | memcpy(bda, match_rec->bd_addr, BD_ADDR_LEN); |
| 641 | addr_type = match_rec->ble.ble_addr_type; |
| 642 | } |
| 643 | else |
| 644 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 645 | BTM_TRACE_ERROR("Random unmatch"); |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, pp); |
| 649 | |
| 650 | return; |
| 651 | } |
| 652 | #endif |
| 653 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 654 | /******************************************************************************* |
| 655 | ** |
Sharvil Nanavati | 2611263 | 2014-06-07 00:56:14 -0700 | [diff] [blame] | 656 | ** Function BTM_BleLocalPrivacyEnabled |
| 657 | ** |
| 658 | ** Description Checks if local device supports private address |
| 659 | ** |
| 660 | ** Returns Return TRUE if local privacy is enabled else FALSE |
| 661 | ** |
| 662 | *******************************************************************************/ |
| 663 | BOOLEAN BTM_BleLocalPrivacyEnabled() |
| 664 | { |
| 665 | #if BLE_PRIVACY_SPT == TRUE |
| 666 | return btm_cb.ble_ctr_cb.privacy; |
| 667 | #else |
| 668 | return false; |
| 669 | #endif |
| 670 | } |
| 671 | |
| 672 | /******************************************************************************* |
| 673 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 674 | ** Function BTM_BleSetBgConnType |
| 675 | ** |
| 676 | ** Description This function is called to set BLE connectable mode for a |
| 677 | ** peripheral device. |
| 678 | ** |
| 679 | ** Parameters bg_conn_type: it can be auto connection, or selective connection. |
| 680 | ** p_select_cback: callback function when selective connection procedure |
| 681 | ** is being used. |
| 682 | ** |
| 683 | ** Returns void |
| 684 | ** |
| 685 | *******************************************************************************/ |
| 686 | BOOLEAN BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE bg_conn_type, |
| 687 | tBTM_BLE_SEL_CBACK *p_select_cback) |
| 688 | { |
| 689 | BOOLEAN started = TRUE; |
| 690 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 691 | BTM_TRACE_EVENT ("BTM_BleSetBgConnType "); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 692 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 693 | return FALSE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 694 | |
| 695 | if (btm_cb.ble_ctr_cb.bg_conn_type != bg_conn_type) |
| 696 | { |
| 697 | switch (bg_conn_type) |
| 698 | { |
| 699 | case BTM_BLE_CONN_AUTO: |
| 700 | btm_ble_start_auto_conn(TRUE); |
| 701 | break; |
| 702 | |
| 703 | case BTM_BLE_CONN_SELECTIVE: |
| 704 | if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) |
| 705 | { |
| 706 | btm_ble_start_auto_conn(FALSE); |
| 707 | } |
| 708 | started = btm_ble_start_select_conn(TRUE, p_select_cback); |
| 709 | break; |
| 710 | |
| 711 | case BTM_BLE_CONN_NONE: |
| 712 | if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) |
| 713 | { |
| 714 | btm_ble_start_auto_conn(FALSE); |
| 715 | } |
| 716 | else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) |
| 717 | { |
| 718 | btm_ble_start_select_conn(FALSE, NULL); |
| 719 | } |
| 720 | started = TRUE; |
| 721 | break; |
| 722 | |
| 723 | default: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 724 | BTM_TRACE_ERROR("invalid bg connection type : %d ", bg_conn_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 725 | started = FALSE; |
| 726 | break; |
| 727 | } |
| 728 | |
| 729 | if (started) |
| 730 | btm_cb.ble_ctr_cb.bg_conn_type = bg_conn_type; |
| 731 | } |
| 732 | return started; |
| 733 | } |
| 734 | |
| 735 | /******************************************************************************* |
| 736 | ** |
Nitin Arora | 021e17a | 2014-01-29 19:18:39 -0800 | [diff] [blame] | 737 | ** Function BTM_BleClearBgConnDev |
| 738 | ** |
| 739 | ** Description This function is called to clear the whitelist, |
| 740 | ** end any pending whitelist connections, |
| 741 | * and reset the local bg device list. |
| 742 | ** |
| 743 | ** Parameters void |
| 744 | ** |
| 745 | ** Returns void |
| 746 | ** |
| 747 | *******************************************************************************/ |
| 748 | void BTM_BleClearBgConnDev(void) |
| 749 | { |
| 750 | btm_ble_start_auto_conn(FALSE); |
| 751 | btm_ble_clear_white_list(); |
| 752 | gatt_reset_bgdev_list(); |
| 753 | } |
| 754 | |
| 755 | /******************************************************************************* |
| 756 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 757 | ** Function BTM_BleUpdateBgConnDev |
| 758 | ** |
| 759 | ** Description This function is called to add or remove a device into/from |
| 760 | ** background connection procedure. The background connection |
| 761 | * procedure is decided by the background connection type, it can be |
| 762 | * auto connection, or selective connection. |
| 763 | ** |
| 764 | ** Parameters add_remove: TRUE to add; FALSE to remove. |
| 765 | ** remote_bda: device address to add/remove. |
| 766 | ** |
| 767 | ** Returns void |
| 768 | ** |
| 769 | *******************************************************************************/ |
| 770 | BOOLEAN BTM_BleUpdateBgConnDev(BOOLEAN add_remove, BD_ADDR remote_bda) |
| 771 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 772 | BOOLEAN ret = TRUE; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 773 | UINT8 dev_wl_type = 0; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 774 | BTM_TRACE_EVENT (" BTM_BleUpdateBgConnDev"); |
Andre Eisenbach | 946c681 | 2013-04-04 14:53:04 -0700 | [diff] [blame] | 775 | |
| 776 | /* update white list */ |
| 777 | ret = btm_update_bg_conn_list(add_remove, remote_bda, &dev_wl_type); |
| 778 | |
| 779 | btm_update_dev_to_white_list(add_remove, remote_bda, dev_wl_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 780 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 781 | return ret; |
| 782 | } |
| 783 | |
| 784 | /******************************************************************************* |
| 785 | ** |
| 786 | ** Function BTM_BleSetConnMode |
| 787 | ** |
| 788 | ** Description This function is called to set BLE connectable mode for a |
| 789 | ** peripheral device. |
| 790 | ** |
| 791 | ** Parameters directed: is directed connectable mode, or non-directed. |
| 792 | ** p_dir_bda: connectable direct initiator's LE device address |
| 793 | ** |
| 794 | ** Returns void |
| 795 | ** |
| 796 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 797 | tBTM_STATUS BTM_BleSetConnMode(BOOLEAN is_directed) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 798 | { |
| 799 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 800 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 801 | BTM_TRACE_EVENT ("BTM_BleSetConnMode is_directed = %d ", is_directed); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 802 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 803 | return BTM_ILLEGAL_VALUE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 804 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 805 | p_cb->directed_conn = is_directed; |
| 806 | return btm_ble_set_connectability( p_cb->connectable_mode); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 807 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /******************************************************************************* |
| 811 | ** |
| 812 | ** Function btm_set_conn_mode_adv_init_addr |
| 813 | ** |
| 814 | ** Description set initator address type and local address type based on adv |
| 815 | ** mode. |
| 816 | ** |
| 817 | ** |
| 818 | *******************************************************************************/ |
| 819 | static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, |
| 820 | BD_ADDR_PTR p_addr_ptr, |
| 821 | tBLE_ADDR_TYPE *p_init_addr_type, |
| 822 | tBLE_ADDR_TYPE *p_own_addr_type) |
| 823 | { |
| 824 | UINT8 evt_type; |
| 825 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 826 | UNUSED(p_own_addr_type); |
| 827 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 828 | if ( p_cb->directed_conn) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 829 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 830 | /* direct adv mode does not have privacy if privacy |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 831 | is not enabled or no reconn addr config */ |
| 832 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 833 | *p_init_addr_type = p_cb->direct_bda.type; |
| 834 | memcpy(p_addr_ptr, p_cb->direct_bda.bda, BD_ADDR_LEN); |
| 835 | evt_type = BTM_BLE_CONNECT_DIR_EVT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 836 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 837 | else /* undirect adv mode */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 838 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 839 | evt_type = BTM_BLE_CONNECT_EVT; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 840 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 841 | /* may need to reset random address if privacy is enabled */ |
| 842 | if (btm_cb.ble_ctr_cb.privacy && /* own addr_type is random */ |
| 843 | !BTM_BLE_IS_RESOLVE_BDA(btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr)) |
| 844 | { |
| 845 | /* need to generate RRA and update random addresss in controller */ |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 846 | btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 847 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 848 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 849 | |
| 850 | return evt_type; |
| 851 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | /******************************************************************************* |
| 855 | ** |
| 856 | ** Function BTM_BleSetAdvParams |
| 857 | ** |
| 858 | ** Description This function is called to set advertising parameters. |
| 859 | ** |
| 860 | ** Parameters adv_int_min: minimum advertising interval |
| 861 | ** adv_int_max: maximum advertising interval |
| 862 | ** p_dir_bda: connectable direct initiator's LE device address |
| 863 | ** chnl_map: advertising channel map. |
| 864 | ** |
| 865 | ** Returns void |
| 866 | ** |
| 867 | *******************************************************************************/ |
| 868 | tBTM_STATUS BTM_BleSetAdvParams(UINT16 adv_int_min, UINT16 adv_int_max, |
| 869 | tBLE_BD_ADDR *p_dir_bda, |
| 870 | tBTM_BLE_ADV_CHNL_MAP chnl_map) |
| 871 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 872 | tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 873 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 874 | tBTM_STATUS status = BTM_SUCCESS; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 875 | BD_ADDR p_addr_ptr = {0}; |
| 876 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; |
| 877 | tBLE_ADDR_TYPE own_addr_type = p_addr_cb->own_addr_type; |
| 878 | UINT8 adv_mode = p_cb->adv_mode; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 879 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 880 | BTM_TRACE_EVENT ("BTM_BleSetAdvParams"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 881 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 882 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 883 | return BTM_ILLEGAL_VALUE; |
| 884 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 885 | if (!BTM_BLE_VALID_PRAM(adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || |
| 886 | !BTM_BLE_VALID_PRAM(adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) |
| 887 | { |
| 888 | return BTM_ILLEGAL_VALUE; |
| 889 | } |
| 890 | |
| 891 | p_cb->adv_interval_min = adv_int_min; |
| 892 | p_cb->adv_interval_max = adv_int_max; |
| 893 | p_cb->adv_chnl_map = chnl_map; |
| 894 | |
| 895 | if (p_dir_bda) |
| 896 | { |
| 897 | memcpy(&p_cb->direct_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); |
| 898 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 899 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 900 | BTM_TRACE_EVENT ("update params for an active adv"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 901 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 902 | btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 903 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 904 | if (p_cb->connectable_mode & BTM_BLE_CONNECTABLE) |
| 905 | p_cb->evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, &own_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 906 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 907 | /* update adv params */ |
| 908 | btsnd_hcic_ble_write_adv_params (p_cb->adv_interval_min, |
| 909 | p_cb->adv_interval_max, |
| 910 | p_cb->evt_type, |
| 911 | own_addr_type, |
| 912 | init_addr_type, |
| 913 | p_addr_ptr, |
| 914 | p_cb->adv_chnl_map, |
| 915 | p_cb->afp); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 916 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 917 | if (adv_mode == BTM_BLE_ADV_ENABLE) |
| 918 | btm_ble_start_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 919 | |
| 920 | return status; |
| 921 | } |
| 922 | |
| 923 | /******************************************************************************* |
| 924 | ** |
| 925 | ** Function BTM_BleReadAdvParams |
| 926 | ** |
| 927 | ** Description This function is called to set advertising parameters. |
| 928 | ** |
| 929 | ** Parameters adv_int_min: minimum advertising interval |
| 930 | ** adv_int_max: maximum advertising interval |
| 931 | ** p_dir_bda: connectable direct initiator's LE device address |
| 932 | ** chnl_map: advertising channel map. |
| 933 | ** |
| 934 | ** Returns void |
| 935 | ** |
| 936 | *******************************************************************************/ |
| 937 | void BTM_BleReadAdvParams (UINT16 *adv_int_min, UINT16 *adv_int_max, |
| 938 | tBLE_BD_ADDR *p_dir_bda, tBTM_BLE_ADV_CHNL_MAP *p_chnl_map) |
| 939 | { |
| 940 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 941 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 942 | BTM_TRACE_EVENT ("BTM_BleReadAdvParams "); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 943 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 944 | return ; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 945 | |
| 946 | *adv_int_min = p_cb->adv_interval_min; |
| 947 | *adv_int_max = p_cb->adv_interval_max; |
| 948 | *p_chnl_map = p_cb->adv_chnl_map; |
| 949 | |
| 950 | if (p_dir_bda != NULL) |
| 951 | { |
| 952 | memcpy(p_dir_bda, &p_cb->direct_bda, sizeof(tBLE_BD_ADDR)); |
| 953 | } |
| 954 | } |
| 955 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 956 | /******************************************************************************* |
| 957 | ** |
| 958 | ** Function BTM_BleSetScanParams |
| 959 | ** |
| 960 | ** Description This function is called to set Scan parameters. |
| 961 | ** |
| 962 | ** Parameters adv_int_min: minimum advertising interval |
| 963 | ** adv_int_max: maximum advertising interval |
| 964 | ** p_dir_bda: connectable direct initiator's LE device address |
| 965 | ** chnl_map: advertising channel map. |
| 966 | ** scan_type: active scan or passive scan |
| 967 | ** |
| 968 | ** Returns void |
| 969 | ** |
| 970 | *******************************************************************************/ |
| 971 | void BTM_BleSetScanParams(UINT16 scan_interval, UINT16 scan_window, tBTM_BLE_SCAN_MODE scan_mode) |
| 972 | { |
| 973 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 974 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 975 | BTM_TRACE_EVENT (" BTM_BleSetScanParams"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 976 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 977 | return ; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 978 | |
| 979 | if (BTM_BLE_VALID_PRAM(scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && |
| 980 | BTM_BLE_VALID_PRAM(scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && |
| 981 | (scan_mode == BTM_BLE_SCAN_MODE_ACTI || scan_mode == BTM_BLE_SCAN_MODE_PASS)) |
| 982 | { |
| 983 | p_cb->scan_type = scan_mode; |
| 984 | |
| 985 | if (BTM_BLE_CONN_PARAM_UNDEF != scan_interval) |
| 986 | p_cb->scan_interval = scan_interval; |
| 987 | |
| 988 | if (BTM_BLE_CONN_PARAM_UNDEF != scan_window) |
| 989 | p_cb->scan_window = scan_window; |
| 990 | } |
| 991 | else |
| 992 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 993 | BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 994 | scan_interval, scan_window); |
| 995 | } |
| 996 | |
| 997 | } |
| 998 | |
| 999 | /******************************************************************************* |
| 1000 | ** |
| 1001 | ** Function BTM_BleWriteScanRsp |
| 1002 | ** |
| 1003 | ** Description This function is called to write LE scan response. |
| 1004 | ** |
| 1005 | ** Parameters: p_scan_rsp: scan response information. |
| 1006 | ** |
| 1007 | ** Returns void |
| 1008 | ** |
| 1009 | *******************************************************************************/ |
| 1010 | tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p_data) |
| 1011 | { |
| 1012 | tBTM_STATUS status = BTM_NO_RESOURCES; |
| 1013 | UINT8 rsp_data[BTM_BLE_AD_DATA_LEN], |
| 1014 | *p = rsp_data; |
| 1015 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1016 | BTM_TRACE_EVENT (" BTM_BleWriteScanRsp"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1017 | |
| 1018 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 1019 | return BTM_ILLEGAL_VALUE; |
| 1020 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1021 | memset(rsp_data, 0, BTM_BLE_AD_DATA_LEN); |
| 1022 | btm_ble_build_adv_data(&data_mask, &p, p_data); |
| 1023 | |
| 1024 | if (btsnd_hcic_ble_set_scan_rsp_data((UINT8)(p - rsp_data), rsp_data)) |
| 1025 | { |
| 1026 | status = BTM_SUCCESS; |
| 1027 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1028 | if (data_mask != 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1029 | btm_cb.ble_ctr_cb.inq_var.scan_rsp = TRUE; |
| 1030 | else |
| 1031 | btm_cb.ble_ctr_cb.inq_var.scan_rsp = FALSE; |
| 1032 | } |
| 1033 | else |
| 1034 | status = BTM_ILLEGAL_VALUE; |
| 1035 | |
| 1036 | return status; |
| 1037 | } |
| 1038 | |
| 1039 | /******************************************************************************* |
| 1040 | ** |
| 1041 | ** Function BTM_BleWriteAdvData |
| 1042 | ** |
| 1043 | ** Description This function is called to write advertising data. |
| 1044 | ** |
| 1045 | ** Parameters: None. |
| 1046 | ** |
| 1047 | ** Returns void |
| 1048 | ** |
| 1049 | *******************************************************************************/ |
| 1050 | tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p_data) |
| 1051 | { |
| 1052 | tBTM_BLE_LOCAL_ADV_DATA *p_cb_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; |
| 1053 | UINT8 *p; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1054 | tBTM_BLE_AD_MASK mask = data_mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1055 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1056 | BTM_TRACE_EVENT ("BTM_BleWriteAdvData "); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1057 | |
| 1058 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 1059 | return BTM_ILLEGAL_VALUE; |
| 1060 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1061 | memset(p_cb_data, 0, sizeof(tBTM_BLE_LOCAL_ADV_DATA)); |
| 1062 | p = p_cb_data->ad_data; |
| 1063 | p_cb_data->data_mask = data_mask; |
| 1064 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1065 | p_cb_data->p_flags = btm_ble_build_adv_data(&mask, &p, p_data); |
| 1066 | |
| 1067 | p_cb_data->p_pad = p; |
| 1068 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1069 | if (mask != 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1070 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1071 | BTM_TRACE_ERROR("Partial data write into ADV"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | p_cb_data->data_mask &= ~mask; |
| 1075 | |
| 1076 | if (btsnd_hcic_ble_set_adv_data((UINT8)(p_cb_data->p_pad - p_cb_data->ad_data), |
| 1077 | p_cb_data->ad_data)) |
| 1078 | return BTM_SUCCESS; |
| 1079 | else |
| 1080 | return BTM_NO_RESOURCES; |
| 1081 | |
| 1082 | } |
| 1083 | |
| 1084 | /******************************************************************************* |
| 1085 | ** |
| 1086 | ** Function BTM_CheckAdvData |
| 1087 | ** |
| 1088 | ** Description This function is called to get ADV data for a specific type. |
| 1089 | ** |
| 1090 | ** Parameters p_adv - pointer of ADV data |
| 1091 | ** type - finding ADV data type |
| 1092 | ** p_length - return the length of ADV data not including type |
| 1093 | ** |
| 1094 | ** Returns pointer of ADV data |
| 1095 | ** |
| 1096 | *******************************************************************************/ |
| 1097 | UINT8 *BTM_CheckAdvData( UINT8 *p_adv, UINT8 type, UINT8 *p_length) |
| 1098 | { |
| 1099 | UINT8 *p = p_adv; |
| 1100 | UINT8 length; |
| 1101 | UINT8 adv_type; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1102 | BTM_TRACE_API("BTM_CheckAdvData type=0x%02X", type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1103 | |
| 1104 | STREAM_TO_UINT8(length, p); |
| 1105 | |
| 1106 | while ( length && (p - p_adv <= BTM_BLE_CACHE_ADV_DATA_MAX)) |
| 1107 | { |
| 1108 | STREAM_TO_UINT8(adv_type, p); |
| 1109 | |
| 1110 | if ( adv_type == type ) |
| 1111 | { |
| 1112 | /* length doesn't include itself */ |
| 1113 | *p_length = length - 1; /* minus the length of type */ |
| 1114 | return p; |
| 1115 | } |
| 1116 | p += length - 1; /* skip the length of data */ |
| 1117 | STREAM_TO_UINT8(length, p); |
| 1118 | } |
| 1119 | |
| 1120 | *p_length = 0; |
| 1121 | return NULL; |
| 1122 | } |
| 1123 | |
| 1124 | /******************************************************************************* |
| 1125 | ** |
| 1126 | ** Function btm_ble_build_adv_data |
| 1127 | ** |
| 1128 | ** Description This function is called build the adv data and rsp data. |
| 1129 | *******************************************************************************/ |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1130 | UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst, |
| 1131 | tBTM_BLE_ADV_DATA *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1132 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1133 | UINT32 data_mask = *p_data_mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1134 | UINT8 *p = *p_dst, |
| 1135 | *p_flag = NULL; |
| 1136 | UINT16 len = BTM_BLE_AD_DATA_LEN, cp_len = 0; |
| 1137 | UINT8 i = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1138 | tBTM_BLE_PROP_ELEM *p_elem; |
| 1139 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1140 | BTM_TRACE_EVENT (" btm_ble_build_adv_data"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1141 | |
| 1142 | /* build the adv data structure and build the data string */ |
| 1143 | if (data_mask) |
| 1144 | { |
| 1145 | /* flags */ |
| 1146 | if (data_mask & BTM_BLE_AD_BIT_FLAGS) |
| 1147 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1148 | *p++ = MIN_ADV_LENGTH; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1149 | *p++ = BTM_BLE_AD_TYPE_FLAG; |
| 1150 | p_flag = p; |
| 1151 | if (p_data) |
| 1152 | *p++ = p_data->flag; |
| 1153 | else |
| 1154 | *p++ = 0; |
| 1155 | |
| 1156 | len -= 3; |
| 1157 | |
| 1158 | data_mask &= ~BTM_BLE_AD_BIT_FLAGS; |
| 1159 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1160 | /* appearance data */ |
| 1161 | if (len > 3 && data_mask & BTM_BLE_AD_BIT_APPEARANCE) |
| 1162 | { |
| 1163 | *p++ = 3; /* length */ |
| 1164 | *p++ = BTM_BLE_AD_TYPE_APPEARANCE; |
| 1165 | UINT16_TO_STREAM(p, p_data->appearance); |
| 1166 | len -= 4; |
| 1167 | |
| 1168 | data_mask &= ~BTM_BLE_AD_BIT_APPEARANCE; |
| 1169 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1170 | /* device name */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1171 | #if BTM_MAX_LOC_BD_NAME_LEN > 0 |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1172 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_DEV_NAME) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1173 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1174 | if (strlen(btm_cb.cfg.bd_name) > (UINT16)(len - MIN_ADV_LENGTH)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1175 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1176 | *p++ = len - MIN_ADV_LENGTH + 1; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1177 | *p++ = BTM_BLE_AD_TYPE_NAME_SHORT; |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1178 | ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, len - MIN_ADV_LENGTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1179 | } |
| 1180 | else |
| 1181 | { |
| 1182 | cp_len = (UINT16)strlen(btm_cb.cfg.bd_name); |
| 1183 | *p++ = cp_len + 1; |
| 1184 | *p++ = BTM_BLE_AD_TYPE_NAME_CMPL; |
| 1185 | ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, cp_len); |
| 1186 | } |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1187 | len -= (cp_len + MIN_ADV_LENGTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1188 | data_mask &= ~BTM_BLE_AD_BIT_DEV_NAME; |
| 1189 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1190 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1191 | /* manufacturer data */ |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1192 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_MANU && |
| 1193 | p_data && p_data->p_manu && |
| 1194 | p_data->p_manu->len != 0 && p_data->p_manu->p_val) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1195 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1196 | if (p_data->p_manu->len > (len - MIN_ADV_LENGTH)) |
| 1197 | cp_len = len - MIN_ADV_LENGTH; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1198 | else |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1199 | cp_len = p_data->p_manu->len; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1200 | |
| 1201 | *p++ = cp_len + 1; |
| 1202 | *p++ = BTM_BLE_AD_TYPE_MANU; |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1203 | ARRAY_TO_STREAM(p, p_data->p_manu->p_val, cp_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1204 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1205 | len -= (cp_len + MIN_ADV_LENGTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1206 | data_mask &= ~BTM_BLE_AD_BIT_MANU; |
| 1207 | } |
| 1208 | /* TX power */ |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1209 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_TX_PWR) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1210 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1211 | *p++ = MIN_ADV_LENGTH; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1212 | *p++ = BTM_BLE_AD_TYPE_TX_PWR; |
Satya Calloji | 4a7ad9b | 2014-07-29 15:32:51 -0700 | [diff] [blame] | 1213 | if (p_data->tx_power > BTM_BLE_ADV_TX_POWER_MAX) |
| 1214 | p_data->tx_power = BTM_BLE_ADV_TX_POWER_MAX; |
| 1215 | *p++ = btm_ble_map_adv_tx_power(p_data->tx_power); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1216 | len -= 3; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1217 | data_mask &= ~BTM_BLE_AD_BIT_TX_PWR; |
| 1218 | } |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1219 | /* 16 bits services */ |
| 1220 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_SERVICE && |
| 1221 | p_data && p_data->p_services && |
| 1222 | p_data->p_services->num_service != 0 && |
| 1223 | p_data->p_services->p_uuid) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1224 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1225 | if (p_data->p_services->num_service * LEN_UUID_16 > (len - MIN_ADV_LENGTH)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1226 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1227 | cp_len = (len - MIN_ADV_LENGTH)/LEN_UUID_16; |
| 1228 | *p ++ = 1 + cp_len * LEN_UUID_16; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1229 | *p++ = BTM_BLE_AD_TYPE_16SRV_PART; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1230 | } |
| 1231 | else |
| 1232 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1233 | cp_len = p_data->p_services->num_service; |
| 1234 | *p++ = 1 + cp_len * LEN_UUID_16; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1235 | *p++ = BTM_BLE_AD_TYPE_16SRV_CMPL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1236 | } |
| 1237 | for (i = 0; i < cp_len; i ++) |
| 1238 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1239 | UINT16_TO_STREAM(p, *(p_data->p_services->p_uuid + i)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1240 | } |
| 1241 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1242 | len -= (cp_len * MIN_ADV_LENGTH + MIN_ADV_LENGTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1243 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE; |
| 1244 | } |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1245 | /* 32 bits service uuid */ |
| 1246 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_SERVICE_32 && |
| 1247 | p_data && p_data->p_service_32b && |
| 1248 | p_data->p_service_32b->num_service != 0 && |
| 1249 | p_data->p_service_32b->p_uuid) |
| 1250 | { |
| 1251 | if ((p_data->p_service_32b->num_service * LEN_UUID_32) > (len - MIN_ADV_LENGTH)) |
| 1252 | { |
| 1253 | cp_len = (len - MIN_ADV_LENGTH)/LEN_UUID_32; |
| 1254 | *p ++ = 1 + cp_len * LEN_UUID_32; |
| 1255 | *p++ = BTM_BLE_AD_TYPE_32SRV_PART; |
| 1256 | } |
| 1257 | else |
| 1258 | { |
| 1259 | cp_len = p_data->p_service_32b->num_service; |
| 1260 | *p++ = 1 + cp_len * LEN_UUID_32; |
| 1261 | *p++ = BTM_BLE_AD_TYPE_32SRV_CMPL; |
| 1262 | } |
| 1263 | for (i = 0; i < cp_len; i ++) |
| 1264 | { |
| 1265 | UINT32_TO_STREAM(p, *(p_data->p_service_32b->p_uuid + i)); |
| 1266 | } |
| 1267 | |
| 1268 | len -= (cp_len * LEN_UUID_32 + MIN_ADV_LENGTH); |
| 1269 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_32; |
| 1270 | } |
| 1271 | /* 128 bits services */ |
| 1272 | if (len >= (MAX_UUID_SIZE + 2) && data_mask & BTM_BLE_AD_BIT_SERVICE_128 && |
| 1273 | p_data && p_data->p_services_128b) |
| 1274 | { |
| 1275 | *p ++ = 1 + MAX_UUID_SIZE; |
| 1276 | if (!p_data->p_services_128b->list_cmpl) |
| 1277 | *p++ = BTM_BLE_AD_TYPE_128SRV_PART; |
| 1278 | else |
| 1279 | *p++ = BTM_BLE_AD_TYPE_128SRV_CMPL; |
| 1280 | |
| 1281 | ARRAY_TO_STREAM(p, p_data->p_services_128b->uuid128, MAX_UUID_SIZE); |
| 1282 | |
| 1283 | len -= (MAX_UUID_SIZE + MIN_ADV_LENGTH); |
| 1284 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_128; |
| 1285 | } |
| 1286 | /* 32 bits Service Solicitation UUIDs */ |
| 1287 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_SERVICE_32SOL && |
| 1288 | p_data && p_data->p_sol_service_32b && |
| 1289 | p_data->p_sol_service_32b->num_service != 0 && |
| 1290 | p_data->p_sol_service_32b->p_uuid) |
| 1291 | { |
| 1292 | if ((p_data->p_sol_service_32b->num_service * LEN_UUID_32) > (len - MIN_ADV_LENGTH)) |
| 1293 | { |
| 1294 | cp_len = (len - MIN_ADV_LENGTH)/LEN_UUID_32; |
| 1295 | *p ++ = 1 + cp_len * LEN_UUID_32; |
| 1296 | } |
| 1297 | else |
| 1298 | { |
| 1299 | cp_len = p_data->p_sol_service_32b->num_service; |
| 1300 | *p++ = 1 + cp_len * LEN_UUID_32; |
| 1301 | } |
| 1302 | |
| 1303 | *p++ = BTM_BLE_AD_TYPE_32SOL_SRV_UUID; |
| 1304 | for (i = 0; i < cp_len; i ++) |
| 1305 | { |
| 1306 | UINT32_TO_STREAM(p, *(p_data->p_sol_service_32b->p_uuid + i)); |
| 1307 | } |
| 1308 | |
| 1309 | len -= (cp_len * LEN_UUID_32 + MIN_ADV_LENGTH); |
| 1310 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_32SOL; |
| 1311 | } |
| 1312 | /* 128 bits Solicitation services UUID */ |
| 1313 | if (len >= (MAX_UUID_SIZE + MIN_ADV_LENGTH) && data_mask & BTM_BLE_AD_BIT_SERVICE_128SOL && |
| 1314 | p_data && p_data->p_sol_service_128b) |
| 1315 | { |
| 1316 | *p ++ = 1 + MAX_UUID_SIZE; |
| 1317 | *p++ = BTM_BLE_AD_TYPE_128SOL_SRV_UUID; |
| 1318 | ARRAY_TO_STREAM(p, p_data->p_sol_service_128b->uuid128, MAX_UUID_SIZE); |
| 1319 | len -= (MAX_UUID_SIZE + MIN_ADV_LENGTH); |
| 1320 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_128SOL; |
| 1321 | } |
| 1322 | /* 16bits/32bits/128bits Service Data */ |
| 1323 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_SERVICE_DATA && |
| 1324 | p_data && p_data->p_service_data->len != 0 && p_data->p_service_data->p_val) |
| 1325 | { |
| 1326 | if (len > (p_data->p_service_data->service_uuid.len + MIN_ADV_LENGTH)) |
| 1327 | { |
| 1328 | if (p_data->p_service_data->len > (len - MIN_ADV_LENGTH)) |
| 1329 | cp_len = len - MIN_ADV_LENGTH- p_data->p_service_data->service_uuid.len; |
| 1330 | else |
| 1331 | cp_len = p_data->p_service_data->len; |
| 1332 | |
| 1333 | *p++ = cp_len + 1 + p_data->p_service_data->service_uuid.len; |
| 1334 | if (p_data->p_service_data->service_uuid.len == LEN_UUID_16) |
| 1335 | { |
| 1336 | *p++ = BTM_BLE_AD_TYPE_SERVICE_DATA; |
| 1337 | UINT16_TO_STREAM(p, p_data->p_service_data->service_uuid.uu.uuid16); |
| 1338 | } |
| 1339 | else if (p_data->p_service_data->service_uuid.len == LEN_UUID_32) |
| 1340 | { |
| 1341 | *p++ = BTM_BLE_AD_TYPE_32SERVICE_DATA; |
| 1342 | UINT32_TO_STREAM(p, p_data->p_service_data->service_uuid.uu.uuid32); |
| 1343 | } |
| 1344 | else |
| 1345 | { |
| 1346 | *p++ = BTM_BLE_AD_TYPE_128SERVICE_DATA; |
| 1347 | ARRAY_TO_STREAM(p, p_data->p_service_data->service_uuid.uu.uuid128, |
| 1348 | LEN_UUID_128); |
| 1349 | } |
| 1350 | |
| 1351 | ARRAY_TO_STREAM(p, p_data->p_service_data->p_val, cp_len); |
| 1352 | |
| 1353 | len -= (cp_len + MIN_ADV_LENGTH + p_data->p_service_data->service_uuid.len); |
| 1354 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_DATA; |
| 1355 | } |
| 1356 | else |
| 1357 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1358 | BTM_TRACE_WARNING("service data does not fit"); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1359 | } |
| 1360 | } |
| 1361 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1362 | if (len >= 6 && data_mask & BTM_BLE_AD_BIT_INT_RANGE && |
| 1363 | p_data) |
| 1364 | { |
| 1365 | *p++ = 5; |
| 1366 | *p++ = BTM_BLE_AD_TYPE_INT_RANGE; |
| 1367 | UINT16_TO_STREAM(p, p_data->int_range.low); |
| 1368 | UINT16_TO_STREAM(p, p_data->int_range.hi); |
| 1369 | len -= 6; |
| 1370 | data_mask &= ~BTM_BLE_AD_BIT_INT_RANGE; |
| 1371 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1372 | if (data_mask & BTM_BLE_AD_BIT_PROPRIETARY && p_data && p_data->p_proprietary) |
| 1373 | { |
| 1374 | for (i = 0; i < p_data->p_proprietary->num_elem ; i ++) |
| 1375 | { |
| 1376 | p_elem = p_data->p_proprietary->p_elem + i; |
| 1377 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1378 | if (len >= (MIN_ADV_LENGTH + p_elem->len))/* len byte(1) + ATTR type(1) + Uuid len(2) |
| 1379 | + value length */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1380 | { |
| 1381 | *p ++ = p_elem->len + 1; /* Uuid len + value length */ |
| 1382 | *p ++ = p_elem->adv_type; |
| 1383 | ARRAY_TO_STREAM(p, p_elem->p_val, p_elem->len); |
| 1384 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1385 | len -= (MIN_ADV_LENGTH + p_elem->len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1386 | } |
| 1387 | else |
| 1388 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1389 | BTM_TRACE_WARNING("data exceed max adv packet length"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1390 | break; |
| 1391 | } |
| 1392 | } |
| 1393 | data_mask &= ~BTM_BLE_AD_BIT_PROPRIETARY; |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | *p_data_mask = data_mask; |
| 1398 | *p_dst = p; |
| 1399 | |
| 1400 | return p_flag; |
| 1401 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1402 | /******************************************************************************* |
| 1403 | ** |
| 1404 | ** Function btm_ble_select_adv_interval |
| 1405 | ** |
| 1406 | ** Description select adv interval based on device mode |
| 1407 | ** |
| 1408 | ** Returns void |
| 1409 | ** |
| 1410 | *******************************************************************************/ |
| 1411 | void btm_ble_select_adv_interval(tBTM_BLE_INQ_CB *p_cb, UINT8 evt_type, UINT16 *p_adv_int_min, UINT16 *p_adv_int_max) |
| 1412 | { |
| 1413 | if (p_cb->adv_interval_min && p_cb->adv_interval_max) |
| 1414 | { |
| 1415 | *p_adv_int_min = p_cb->adv_interval_min; |
| 1416 | *p_adv_int_max = p_cb->adv_interval_max; |
| 1417 | } |
| 1418 | else |
| 1419 | { |
| 1420 | switch (evt_type) |
| 1421 | { |
| 1422 | case BTM_BLE_CONNECT_EVT: |
| 1423 | *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_1; |
| 1424 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1425 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1426 | case BTM_BLE_NON_CONNECT_EVT: |
| 1427 | case BTM_BLE_DISCOVER_EVT: |
| 1428 | *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_2; |
| 1429 | break; |
| 1430 | /* connectable directed event */ |
| 1431 | case BTM_BLE_CONNECT_DIR_EVT: |
| 1432 | *p_adv_int_min = BTM_BLE_GAP_ADV_DIR_MIN_INT; |
| 1433 | *p_adv_int_max = BTM_BLE_GAP_ADV_DIR_MAX_INT; |
| 1434 | break; |
| 1435 | |
| 1436 | default: |
| 1437 | *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_SLOW_INT; |
| 1438 | break; |
| 1439 | } |
| 1440 | } |
| 1441 | return; |
| 1442 | } |
| 1443 | /******************************************************************************* |
| 1444 | ** |
| 1445 | ** Function btm_ble_set_adv_flag |
| 1446 | ** |
| 1447 | ** Description Set adv flag in adv data. |
| 1448 | ** |
| 1449 | ** Returns void |
| 1450 | ** |
| 1451 | *******************************************************************************/ |
| 1452 | void btm_ble_set_adv_flag(UINT16 connect_mode, UINT16 disc_mode) |
| 1453 | { |
| 1454 | UINT8 flag = 0, old_flag = 0; |
| 1455 | tBTM_BLE_LOCAL_ADV_DATA *p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; |
| 1456 | |
| 1457 | if (p_adv_data->p_flags != NULL) |
| 1458 | flag = old_flag = *(p_adv_data->p_flags); |
| 1459 | |
| 1460 | /* BR/EDR non-discoverable , non-connectable */ |
| 1461 | if ((disc_mode & BTM_DISCOVERABLE_MASK) == 0 && |
| 1462 | (connect_mode & BTM_CONNECTABLE_MASK) == 0) |
| 1463 | flag |= BTM_BLE_BREDR_NOT_SPT; |
| 1464 | else |
| 1465 | flag &= ~BTM_BLE_BREDR_NOT_SPT; |
| 1466 | |
| 1467 | /* if local controller support, mark both controller and host support in flag */ |
| 1468 | if (HCI_SIMUL_LE_BREDR_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
| 1469 | flag |= (BTM_BLE_DMT_CONTROLLER_SPT|BTM_BLE_DMT_HOST_SPT); |
| 1470 | else |
| 1471 | flag &= ~(BTM_BLE_DMT_CONTROLLER_SPT|BTM_BLE_DMT_HOST_SPT); |
| 1472 | |
Matthew Xie | 7204059 | 2014-08-20 15:40:42 -0700 | [diff] [blame] | 1473 | BTM_TRACE_DEBUG("disc_mode %04x", disc_mode); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1474 | /* update discoverable flag */ |
| 1475 | if (disc_mode & BTM_BLE_LIMITED_DISCOVERABLE) |
| 1476 | { |
| 1477 | flag &= ~BTM_BLE_GEN_DISC_FLAG; |
| 1478 | flag |= BTM_BLE_LIMIT_DISC_FLAG ; |
| 1479 | } |
| 1480 | else if (disc_mode & BTM_BLE_GENERAL_DISCOVERABLE) |
| 1481 | { |
| 1482 | flag |= BTM_BLE_GEN_DISC_FLAG; |
| 1483 | flag &= ~BTM_BLE_LIMIT_DISC_FLAG; |
| 1484 | } |
| 1485 | else /* remove all discoverable flags */ |
| 1486 | { |
| 1487 | flag &= ~(BTM_BLE_LIMIT_DISC_FLAG|BTM_BLE_GEN_DISC_FLAG); |
| 1488 | } |
| 1489 | |
| 1490 | if (flag != old_flag) |
| 1491 | { |
| 1492 | btm_ble_update_adv_flag(flag); |
| 1493 | } |
| 1494 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1495 | /******************************************************************************* |
| 1496 | ** |
| 1497 | ** Function btm_ble_set_discoverability |
| 1498 | ** |
| 1499 | ** Description This function is called to set BLE discoverable mode. |
| 1500 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1501 | ** Parameters: combined_mode: discoverability mode. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1502 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1503 | ** Returns BTM_SUCCESS is status set successfully; otherwise failure. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1504 | ** |
| 1505 | *******************************************************************************/ |
| 1506 | tBTM_STATUS btm_ble_set_discoverability(UINT16 combined_mode) |
| 1507 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1508 | tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1509 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 1510 | UINT16 mode = (combined_mode & BTM_BLE_DISCOVERABLE_MASK); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1511 | UINT8 new_mode = BTM_BLE_ADV_ENABLE; |
| 1512 | UINT8 evt_type = (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE) ? \ |
| 1513 | ((p_cb->scan_rsp) ? BTM_BLE_DISCOVER_EVT : BTM_BLE_NON_CONNECT_EVT )\ |
| 1514 | : BTM_BLE_CONNECT_EVT; |
| 1515 | tBTM_STATUS status = BTM_SUCCESS; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1516 | BD_ADDR p_addr_ptr= {0}; |
| 1517 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC, |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1518 | own_addr_type = p_addr_cb->own_addr_type; |
| 1519 | UINT16 adv_int_min, adv_int_max; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1520 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1521 | BTM_TRACE_EVENT ("btm_ble_set_discoverability mode=0x%0x combined_mode=0x%x", mode, combined_mode); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1522 | |
| 1523 | /*** Check mode parameter ***/ |
| 1524 | if (mode > BTM_BLE_MAX_DISCOVERABLE) |
| 1525 | return(BTM_ILLEGAL_VALUE); |
| 1526 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1527 | btm_ble_set_adv_flag (btm_cb.btm_inq_vars.connectable_mode, combined_mode); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1528 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1529 | evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, &own_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1530 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1531 | if (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE && mode == BTM_BLE_NON_DISCOVERABLE) |
| 1532 | new_mode = BTM_BLE_ADV_DISABLE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1533 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1534 | btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1535 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1536 | btu_stop_timer(&p_cb->fast_adv_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1537 | |
| 1538 | /* update adv params if start advertising */ |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1539 | BTM_TRACE_EVENT ("evt_type=0x%x p-cb->evt_type=0x%x ", evt_type, p_cb->evt_type); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1540 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1541 | if (new_mode == BTM_BLE_ADV_ENABLE && |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1542 | (evt_type != p_cb->evt_type ||p_cb->adv_addr_type != own_addr_type || !p_cb->fast_adv_on)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1543 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1544 | btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1545 | |
| 1546 | /* update adv params */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1547 | if (!btsnd_hcic_ble_write_adv_params (adv_int_min, |
| 1548 | adv_int_max, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1549 | evt_type, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1550 | own_addr_type, |
| 1551 | init_addr_type, |
| 1552 | p_addr_ptr, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1553 | p_cb->adv_chnl_map, |
| 1554 | p_cb->afp)) |
| 1555 | |
| 1556 | status = BTM_NO_RESOURCES; |
| 1557 | else |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1558 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1559 | p_cb->evt_type = evt_type; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1560 | p_cb->adv_addr_type = own_addr_type; |
| 1561 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1562 | |
| 1563 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1564 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1565 | if (status == BTM_SUCCESS && p_cb->adv_mode != new_mode) |
| 1566 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1567 | if (new_mode == BTM_BLE_ADV_ENABLE) |
| 1568 | status = btm_ble_start_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1569 | else |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1570 | status = btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1571 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1572 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) |
| 1573 | { |
| 1574 | p_cb->fast_adv_on = TRUE; |
| 1575 | /* start initial GAP mode adv timer */ |
| 1576 | btu_start_timer (&p_cb->fast_adv_timer, BTU_TTYPE_BLE_GAP_FAST_ADV, |
| 1577 | BTM_BLE_GAP_FAST_ADV_TOUT); |
| 1578 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1579 | |
| 1580 | /* set up stop advertising timer */ |
| 1581 | if (status == BTM_SUCCESS && mode == BTM_BLE_LIMITED_DISCOVERABLE) |
| 1582 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1583 | BTM_TRACE_EVENT ("start timer for limited disc mode duration=%d (180 secs)", BTM_BLE_GAP_LIM_TOUT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1584 | /* start Tgap(lim_timeout) */ |
| 1585 | btu_start_timer (&p_cb->inq_timer_ent, BTU_TTYPE_BLE_GAP_LIM_DISC, |
| 1586 | BTM_BLE_GAP_LIM_TOUT); |
| 1587 | } |
| 1588 | return status; |
| 1589 | } |
| 1590 | |
| 1591 | /******************************************************************************* |
| 1592 | ** |
| 1593 | ** Function btm_ble_set_connectability |
| 1594 | ** |
| 1595 | ** Description This function is called to set BLE connectability mode. |
| 1596 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1597 | ** Parameters: combined_mode: connectability mode. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1598 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1599 | ** Returns BTM_SUCCESS is status set successfully; otherwise failure. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1600 | ** |
| 1601 | *******************************************************************************/ |
| 1602 | tBTM_STATUS btm_ble_set_connectability(UINT16 combined_mode) |
| 1603 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1604 | tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1605 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 1606 | UINT16 mode = (combined_mode & BTM_BLE_CONNECTABLE_MASK); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1607 | UINT8 new_mode = BTM_BLE_ADV_ENABLE; |
| 1608 | UINT8 evt_type = (p_cb->scan_rsp) ? BTM_BLE_DISCOVER_EVT: BTM_BLE_NON_CONNECT_EVT; |
| 1609 | tBTM_STATUS status = BTM_SUCCESS; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1610 | BD_ADDR p_addr_ptr = {0}; |
| 1611 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC, |
| 1612 | own_addr_type = p_addr_cb->own_addr_type; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1613 | UINT16 adv_int_min, adv_int_max; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1614 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1615 | BTM_TRACE_EVENT ("btm_ble_set_connectability mode=0x%0x combined_mode=0x%x", mode, combined_mode); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1616 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1617 | /*** Check mode parameter ***/ |
| 1618 | if (mode > BTM_BLE_MAX_CONNECTABLE) |
| 1619 | return(BTM_ILLEGAL_VALUE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1620 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1621 | p_cb->connectable_mode = mode; |
| 1622 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1623 | btm_ble_set_adv_flag (combined_mode, btm_cb.btm_inq_vars.discoverable_mode); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1624 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1625 | evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, &own_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1626 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1627 | if (mode == BTM_BLE_NON_CONNECTABLE && p_cb->discoverable_mode == BTM_BLE_NON_DISCOVERABLE) |
| 1628 | new_mode = BTM_BLE_ADV_DISABLE; |
| 1629 | |
| 1630 | btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); |
| 1631 | |
| 1632 | btu_stop_timer(&p_cb->fast_adv_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1633 | /* update adv params if needed */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1634 | if ((p_cb->evt_type != evt_type || p_cb->adv_addr_type != p_addr_cb->own_addr_type || !p_cb->fast_adv_on)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1635 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1636 | btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1637 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1638 | if (!btsnd_hcic_ble_write_adv_params (adv_int_min, |
| 1639 | adv_int_max, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1640 | evt_type, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1641 | own_addr_type, |
| 1642 | init_addr_type, |
| 1643 | p_addr_ptr, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1644 | p_cb->adv_chnl_map, |
| 1645 | p_cb->afp)) |
| 1646 | status = BTM_NO_RESOURCES; |
| 1647 | else |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1648 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1649 | p_cb->evt_type = evt_type; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1650 | p_cb->adv_addr_type = own_addr_type; |
| 1651 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1652 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1653 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1654 | /* update advertising mode */ |
| 1655 | if (status == BTM_SUCCESS && new_mode != p_cb->adv_mode) |
| 1656 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1657 | if (new_mode == BTM_BLE_ADV_ENABLE) |
| 1658 | status = btm_ble_start_adv(); |
| 1659 | else |
| 1660 | status = btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1661 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1662 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) |
| 1663 | { |
| 1664 | p_cb->fast_adv_on = TRUE; |
| 1665 | /* start initial GAP mode adv timer */ |
| 1666 | btu_start_timer (&p_cb->fast_adv_timer, BTU_TTYPE_BLE_GAP_FAST_ADV, |
| 1667 | BTM_BLE_GAP_FAST_ADV_TOUT); |
| 1668 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1669 | return status; |
| 1670 | } |
| 1671 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1672 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1673 | /******************************************************************************* |
| 1674 | ** |
| 1675 | ** Function btm_ble_start_inquiry |
| 1676 | ** |
| 1677 | ** Description This function is called to start BLE inquiry procedure. |
| 1678 | ** If the duration is zero, the periodic inquiry mode is cancelled. |
| 1679 | ** |
| 1680 | ** Parameters: mode - GENERAL or LIMITED inquiry |
| 1681 | ** p_inq_params - pointer to the BLE inquiry parameter. |
| 1682 | ** p_results_cb - callback returning pointer to results (tBTM_INQ_RESULTS) |
| 1683 | ** p_cmpl_cb - callback indicating the end of an inquiry |
| 1684 | ** |
| 1685 | ** |
| 1686 | ** |
| 1687 | ** Returns BTM_CMD_STARTED if successfully started |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1688 | ** BTM_NO_RESOURCES if could not allocate a message buffer |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1689 | ** BTM_BUSY - if an inquiry is already active |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1690 | ** |
| 1691 | *******************************************************************************/ |
| 1692 | tBTM_STATUS btm_ble_start_inquiry (UINT8 mode, UINT8 duration) |
| 1693 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1694 | tBTM_STATUS status = BTM_CMD_STARTED; |
| 1695 | tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; |
| 1696 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1697 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1698 | BTM_TRACE_DEBUG("btm_ble_start_inquiry: mode = %02x inq_active = 0x%02x", mode, btm_cb.btm_inq_vars.inq_active); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1699 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1700 | /* if selective connection is active, or inquiry is already active, reject it */ |
| 1701 | if (BTM_BLE_IS_INQ_ACTIVE(p_ble_cb->scan_activity) || |
| 1702 | BTM_BLE_IS_SEL_CONN_ACTIVE (p_ble_cb->scan_activity)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1703 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1704 | BTM_TRACE_ERROR("LE Inquiry is active, can not start inquiry"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1705 | return(BTM_BUSY); |
| 1706 | } |
| 1707 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1708 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1709 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1710 | btm_update_scanner_filter_policy(SP_ADV_ALL); |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 1711 | |
| 1712 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 1713 | /* enable IRK list */ |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 1714 | if (btm_cb.cmn_ble_vsc_cb.rpa_offloading == TRUE) |
| 1715 | btm_ble_vendor_irk_list_known_dev (TRUE); |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 1716 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1717 | status = btm_ble_start_scan(BTM_BLE_DUPLICATE_DISABLE); |
| 1718 | } |
| 1719 | |
| 1720 | if (status == BTM_CMD_STARTED) |
| 1721 | { |
| 1722 | p_inq->inq_active |= mode; |
| 1723 | p_ble_cb->scan_activity |= mode; |
| 1724 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1725 | BTM_TRACE_DEBUG("btm_ble_start_inquiry inq_active = 0x%02x", p_inq->inq_active); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1726 | |
| 1727 | if (duration != 0) |
| 1728 | { |
| 1729 | /* start inquiry timer */ |
| 1730 | btu_start_timer (&p_inq->inq_timer_ent, BTU_TTYPE_BLE_INQUIRY, duration); |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | return status; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1735 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | /******************************************************************************* |
| 1739 | ** |
| 1740 | ** Function btm_ble_read_remote_name_cmpl |
| 1741 | ** |
| 1742 | ** Description This function is called when BLE remote name is received. |
| 1743 | ** |
| 1744 | ** Returns void |
| 1745 | ** |
| 1746 | *******************************************************************************/ |
| 1747 | void btm_ble_read_remote_name_cmpl(BOOLEAN status, BD_ADDR bda, UINT16 length, char *p_name) |
| 1748 | { |
| 1749 | UINT8 hci_status = HCI_SUCCESS; |
| 1750 | BD_NAME bd_name; |
| 1751 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1752 | memset(bd_name, 0, (BD_NAME_LEN + 1)); |
Zhihai Xu | 7f9bcf8 | 2014-01-15 15:49:21 -0800 | [diff] [blame] | 1753 | if (length > BD_NAME_LEN) |
| 1754 | { |
| 1755 | length = BD_NAME_LEN; |
| 1756 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1757 | memcpy((UINT8*)bd_name, p_name, length); |
| 1758 | |
| 1759 | if ((!status) || (length==0)) |
| 1760 | { |
| 1761 | hci_status = HCI_ERR_HOST_TIMEOUT; |
| 1762 | } |
| 1763 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1764 | btm_process_remote_name(bda, bd_name, length +1, hci_status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1765 | btm_sec_rmt_name_request_complete (bda, (UINT8 *)p_name, hci_status); |
| 1766 | } |
| 1767 | |
| 1768 | /******************************************************************************* |
| 1769 | ** |
| 1770 | ** Function btm_ble_read_remote_name |
| 1771 | ** |
| 1772 | ** Description This function read remote LE device name using GATT read |
| 1773 | ** procedure. |
| 1774 | ** |
| 1775 | ** Parameters: None. |
| 1776 | ** |
| 1777 | ** Returns void |
| 1778 | ** |
| 1779 | *******************************************************************************/ |
| 1780 | tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, tBTM_CMPL_CB *p_cb) |
| 1781 | { |
| 1782 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 1783 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1784 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 1785 | return BTM_ERR_PROCESSING; |
| 1786 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1787 | if (p_cur && |
| 1788 | p_cur->results.ble_evt_type != BTM_BLE_EVT_CONN_ADV && |
| 1789 | p_cur->results.ble_evt_type != BTM_BLE_EVT_CONN_DIR_ADV) |
| 1790 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1791 | BTM_TRACE_DEBUG("name request to non-connectable device failed."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1792 | return BTM_ERR_PROCESSING; |
| 1793 | } |
| 1794 | |
| 1795 | /* read remote device name using GATT procedure */ |
| 1796 | if (p_inq->remname_active) |
| 1797 | return BTM_BUSY; |
| 1798 | |
| 1799 | if (!GAP_BleReadPeerDevName(remote_bda, btm_ble_read_remote_name_cmpl)) |
| 1800 | return BTM_BUSY; |
| 1801 | |
| 1802 | p_inq->p_remname_cmpl_cb = p_cb; |
| 1803 | p_inq->remname_active = TRUE; |
| 1804 | |
| 1805 | memcpy(p_inq->remname_bda, remote_bda, BD_ADDR_LEN); |
| 1806 | |
| 1807 | btu_start_timer (&p_inq->rmt_name_timer_ent, |
| 1808 | BTU_TTYPE_BTM_RMT_NAME, |
| 1809 | BTM_EXT_BLE_RMT_NAME_TIMEOUT); |
| 1810 | |
| 1811 | return BTM_CMD_STARTED; |
| 1812 | } |
| 1813 | |
| 1814 | /******************************************************************************* |
| 1815 | ** |
| 1816 | ** Function btm_ble_cancel_remote_name |
| 1817 | ** |
| 1818 | ** Description This function cancel read remote LE device name. |
| 1819 | ** |
| 1820 | ** Parameters: None. |
| 1821 | ** |
| 1822 | ** Returns void |
| 1823 | ** |
| 1824 | *******************************************************************************/ |
| 1825 | BOOLEAN btm_ble_cancel_remote_name(BD_ADDR remote_bda) |
| 1826 | { |
| 1827 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 1828 | BOOLEAN status; |
| 1829 | |
| 1830 | status = GAP_BleCancelReadPeerDevName(remote_bda); |
| 1831 | |
| 1832 | p_inq->remname_active = FALSE; |
| 1833 | memset(p_inq->remname_bda, 0, BD_ADDR_LEN); |
| 1834 | btu_stop_timer(&p_inq->rmt_name_timer_ent); |
| 1835 | |
| 1836 | return status; |
| 1837 | } |
| 1838 | |
| 1839 | /******************************************************************************* |
| 1840 | ** |
| 1841 | ** Function btm_ble_update_adv_flag |
| 1842 | ** |
| 1843 | ** Description This function update the limited discoverable flag in the adv |
| 1844 | ** data. |
| 1845 | ** |
| 1846 | ** Parameters: None. |
| 1847 | ** |
| 1848 | ** Returns void |
| 1849 | ** |
| 1850 | *******************************************************************************/ |
| 1851 | static void btm_ble_update_adv_flag(UINT8 flag) |
| 1852 | { |
| 1853 | tBTM_BLE_LOCAL_ADV_DATA *p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; |
| 1854 | UINT8 *p; |
| 1855 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1856 | BTM_TRACE_DEBUG ("btm_ble_update_adv_flag new=0x%x", flag); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1857 | |
| 1858 | if (p_adv_data->p_flags != NULL) |
| 1859 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1860 | BTM_TRACE_DEBUG ("btm_ble_update_adv_flag old=0x%x", *p_adv_data->p_flags); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1861 | *p_adv_data->p_flags = flag; |
| 1862 | } |
| 1863 | else /* no FLAGS in ADV data*/ |
| 1864 | { |
| 1865 | p = (p_adv_data->p_pad == NULL) ? p_adv_data->ad_data : p_adv_data->p_pad; |
| 1866 | /* need 3 bytes space to stuff in the flags, if not */ |
| 1867 | /* erase all written data, just for flags */ |
| 1868 | if ((BTM_BLE_AD_DATA_LEN - (p - p_adv_data->ad_data)) < 3) |
| 1869 | { |
| 1870 | p = p_adv_data->p_pad = p_adv_data->ad_data; |
| 1871 | memset(p_adv_data->ad_data, 0, BTM_BLE_AD_DATA_LEN); |
| 1872 | } |
| 1873 | |
| 1874 | *p++ = 2; |
| 1875 | *p++ = BTM_BLE_AD_TYPE_FLAG; |
| 1876 | p_adv_data->p_flags = p; |
| 1877 | *p++ = flag; |
| 1878 | p_adv_data->p_pad = p; |
| 1879 | } |
| 1880 | |
| 1881 | if (btsnd_hcic_ble_set_adv_data((UINT8)(p_adv_data->p_pad - p_adv_data->ad_data), |
| 1882 | p_adv_data->ad_data)) |
| 1883 | p_adv_data->data_mask |= BTM_BLE_AD_BIT_FLAGS; |
| 1884 | |
| 1885 | } |
| 1886 | |
| 1887 | #if 0 |
| 1888 | /******************************************************************************* |
| 1889 | ** |
| 1890 | ** Function btm_ble_parse_adv_data |
| 1891 | ** |
| 1892 | ** Description This function parse the adv data into a structure. |
| 1893 | ** |
| 1894 | ** Returns pointer to entry, or NULL if not found |
| 1895 | ** |
| 1896 | *******************************************************************************/ |
| 1897 | static void btm_ble_parse_adv_data(tBTM_INQ_INFO *p_info, UINT8 *p_data, |
| 1898 | UINT8 len, tBTM_BLE_INQ_DATA *p_adv_data, UINT8 *p_buf) |
| 1899 | { |
| 1900 | UINT8 *p_cur = p_data; |
| 1901 | UINT8 ad_len, ad_type, ad_flag; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1902 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1903 | BTM_TRACE_EVENT (" btm_ble_parse_adv_data"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1904 | |
| 1905 | while (len > 0) |
| 1906 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1907 | BTM_TRACE_DEBUG("btm_ble_parse_adv_data: len = %d", len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1908 | if ((ad_len = *p_cur ++) == 0) |
| 1909 | break; |
| 1910 | |
| 1911 | ad_type = *p_cur ++; |
| 1912 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1913 | BTM_TRACE_DEBUG(" ad_type = %02x ad_len = %d", ad_type, ad_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1914 | |
| 1915 | switch (ad_type) |
| 1916 | { |
| 1917 | case BTM_BLE_AD_TYPE_NAME_SHORT: |
| 1918 | |
| 1919 | case BTM_BLE_AD_TYPE_NAME_CMPL: |
| 1920 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_DEV_NAME; |
| 1921 | if (p_info) |
| 1922 | { |
| 1923 | p_info->remote_name_type =(ad_type == BTM_BLE_AD_TYPE_NAME_SHORT) ? |
| 1924 | BTM_BLE_NAME_SHORT: BTM_BLE_NAME_CMPL; |
| 1925 | memcpy(p_info->remote_name, p_cur, ad_len -1); |
| 1926 | p_info->remote_name[ad_len] = 0; |
| 1927 | p_adv_data->p_remote_name = p_info->remote_name; |
| 1928 | p_info->remote_name_len = p_adv_data->remote_name_len = ad_len - 1; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1929 | BTM_TRACE_DEBUG("BTM_BLE_AD_TYPE_NAME name = %s",p_adv_data->p_remote_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1930 | } |
| 1931 | p_cur += (ad_len -1); |
| 1932 | |
| 1933 | break; |
| 1934 | |
| 1935 | case BTM_BLE_AD_TYPE_FLAG: |
| 1936 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_FLAGS; |
| 1937 | ad_flag = *p_cur ++; |
| 1938 | p_adv_data->flag = (UINT8)(ad_flag & BTM_BLE_ADV_FLAG_MASK) ; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1939 | BTM_TRACE_DEBUG("BTM_BLE_AD_TYPE_FLAG flag = %s | %s | %s", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1940 | (p_adv_data->flag & BTM_BLE_LIMIT_DISC_FLAG)? "LE_LIMIT_DISC" : "", |
| 1941 | (p_adv_data->flag & BTM_BLE_GEN_DISC_FLAG)? "LE_GENERAL_DISC" : "", |
| 1942 | (p_adv_data->flag & BTM_BLE_BREDR_NOT_SPT)? "LE Only device" : ""); |
| 1943 | break; |
| 1944 | |
| 1945 | case BTM_BLE_AD_TYPE_TX_PWR: |
| 1946 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_TX_PWR; |
| 1947 | p_adv_data->tx_power_level = (INT8)*p_cur ++; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1948 | BTM_TRACE_DEBUG("BTM_BLE_AD_TYPE_TX_PWR tx_level = %d", p_adv_data->tx_power_level); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1949 | break; |
| 1950 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1951 | case BTM_BLE_AD_TYPE_MANU: |
| 1952 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1953 | case BTM_BLE_AD_TYPE_16SRV_PART: |
| 1954 | case BTM_BLE_AD_TYPE_16SRV_CMPL: |
| 1955 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_SERVICE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1956 | /* need allocate memory to store UUID list */ |
| 1957 | p_adv_data->service.num_service = (ad_len - 1)/2; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1958 | BTM_TRACE_DEBUG("service UUID list, num = %d", p_adv_data->service.num_service); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1959 | p_cur += (ad_len - 1); |
| 1960 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1961 | |
| 1962 | case BTM_BLE_AD_TYPE_SOL_SRV_UUID: |
| 1963 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_SERVICE_SOL; |
| 1964 | /* need allocate memory to store UUID list */ |
| 1965 | p_adv_data->service.num_service = (ad_len - 1)/2; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1966 | BTM_TRACE_DEBUG("service UUID list, num = %d", p_adv_data->service.num_service); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1967 | p_cur += (ad_len - 1); |
| 1968 | break; |
| 1969 | |
| 1970 | case BTM_BLE_AD_TYPE_128SOL_SRV_UUID: |
| 1971 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL; |
| 1972 | /* need allocate memory to store UUID list */ |
| 1973 | p_adv_data->service.num_service = (ad_len - 1)/16; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1974 | BTM_TRACE_DEBUG("service UUID list, num = %d", p_adv_data->service.num_service); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1975 | p_cur += (ad_len - 1); |
| 1976 | break; |
| 1977 | |
| 1978 | case BTM_BLE_AD_TYPE_APPEARANCE: |
| 1979 | case BTM_BLE_AD_TYPE_PUBLIC_TARGET: |
| 1980 | case BTM_BLE_AD_TYPE_RANDOM_TARGET: |
| 1981 | default: |
| 1982 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1983 | } |
| 1984 | len -= (ad_len + 1); |
| 1985 | } |
| 1986 | } |
| 1987 | #endif |
| 1988 | |
| 1989 | /******************************************************************************* |
| 1990 | ** |
| 1991 | ** Function btm_ble_cache_adv_data |
| 1992 | ** |
| 1993 | ** Description Update advertising cache data. |
| 1994 | ** |
| 1995 | ** Returns void |
| 1996 | ** |
| 1997 | *******************************************************************************/ |
| 1998 | void btm_ble_cache_adv_data(tBTM_INQ_RESULTS *p_cur, UINT8 data_len, UINT8 *p, UINT8 evt_type) |
| 1999 | { |
| 2000 | tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 2001 | UINT8 *p_cache; |
| 2002 | UINT8 length; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2003 | UNUSED(p_cur); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2004 | |
| 2005 | /* cache adv report/scan response data */ |
| 2006 | if (evt_type != BTM_BLE_SCAN_RSP_EVT) |
| 2007 | { |
| 2008 | p_le_inq_cb->adv_len = 0; |
| 2009 | memset(p_le_inq_cb->adv_data_cache, 0, BTM_BLE_CACHE_ADV_DATA_MAX); |
| 2010 | } |
| 2011 | |
| 2012 | if (data_len > 0) |
| 2013 | { |
| 2014 | p_cache = &p_le_inq_cb->adv_data_cache[p_le_inq_cb->adv_len]; |
| 2015 | STREAM_TO_UINT8(length, p); |
| 2016 | while ( length && ((p_le_inq_cb->adv_len + length + 1) <= BTM_BLE_CACHE_ADV_DATA_MAX)) |
| 2017 | { |
| 2018 | /* copy from the length byte & data into cache */ |
| 2019 | memcpy(p_cache, p-1, length+1); |
| 2020 | /* advance the cache pointer past data */ |
| 2021 | p_cache += length+1; |
| 2022 | /* increment cache length */ |
| 2023 | p_le_inq_cb->adv_len += length+1; |
| 2024 | /* skip the length of data */ |
| 2025 | p += length; |
| 2026 | STREAM_TO_UINT8(length, p); |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | /* parse service UUID from adv packet and save it in inq db eir_uuid */ |
| 2031 | /* TODO */ |
| 2032 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2033 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2034 | /******************************************************************************* |
| 2035 | ** |
| 2036 | ** Function btm_ble_is_discoverable |
| 2037 | ** |
| 2038 | ** Description check ADV flag to make sure device is discoverable and match |
| 2039 | ** the search condition |
| 2040 | ** |
| 2041 | ** Parameters |
| 2042 | ** |
| 2043 | ** Returns void |
| 2044 | ** |
| 2045 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2046 | UINT8 btm_ble_is_discoverable(BD_ADDR bda, UINT8 evt_type, UINT8 *p) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2047 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2048 | UINT8 *p_flag, flag = 0, rt = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2049 | UINT8 data_len; |
| 2050 | tBTM_INQ_PARMS *p_cond = &btm_cb.btm_inq_vars.inqparms; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2051 | tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2052 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2053 | UNUSED(p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2054 | |
| 2055 | /* for observer, always "discoverable */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2056 | if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
| 2057 | rt |= BTM_BLE_OBS_RESULT; |
| 2058 | |
| 2059 | if (BTM_BLE_IS_SEL_CONN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity) && |
| 2060 | (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_CONNECT_DIR_EVT)) |
| 2061 | rt |= BTM_BLE_SEL_CONN_RESULT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2062 | |
| 2063 | /* does not match filter condition */ |
| 2064 | if (p_cond->filter_cond_type == BTM_FILTER_COND_BD_ADDR && |
| 2065 | memcmp(bda, p_cond->filter_cond.bdaddr_cond, BD_ADDR_LEN) != 0) |
| 2066 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2067 | BTM_TRACE_DEBUG("BD ADDR does not meet filter condition"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2068 | return rt; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2069 | } |
| 2070 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2071 | if (p_le_inq_cb->adv_len != 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2072 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2073 | if ((p_flag = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, |
| 2074 | BTM_BLE_AD_TYPE_FLAG, &data_len)) != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2075 | { |
| 2076 | flag = * p_flag; |
| 2077 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2078 | if ((btm_cb.btm_inq_vars.inq_active & BTM_BLE_GENERAL_INQUIRY) && |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2079 | (flag & (BTM_BLE_LIMIT_DISC_FLAG|BTM_BLE_GEN_DISC_FLAG)) != 0) |
| 2080 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2081 | BTM_TRACE_DEBUG("Find Generable Discoverable device"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2082 | rt |= BTM_BLE_INQ_RESULT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2083 | } |
| 2084 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2085 | else if (btm_cb.btm_inq_vars.inq_active & BTM_BLE_LIMITED_INQUIRY && |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2086 | (flag & BTM_BLE_LIMIT_DISC_FLAG) != 0) |
| 2087 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2088 | BTM_TRACE_DEBUG("Find limited discoverable device"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2089 | rt |= BTM_BLE_INQ_RESULT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2090 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2091 | } |
| 2092 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2093 | return rt; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2094 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2095 | |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2096 | static void btm_ble_appearance_to_cod(UINT16 appearance, UINT8 *dev_class) |
| 2097 | { |
| 2098 | dev_class[0] = 0; |
| 2099 | |
| 2100 | switch (appearance) |
| 2101 | { |
| 2102 | case BTM_BLE_APPEARANCE_GENERIC_PHONE: |
| 2103 | dev_class[1] = BTM_COD_MAJOR_PHONE; |
| 2104 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2105 | break; |
| 2106 | case BTM_BLE_APPEARANCE_GENERIC_COMPUTER: |
| 2107 | dev_class[1] = BTM_COD_MAJOR_COMPUTER; |
| 2108 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2109 | break; |
| 2110 | case BTM_BLE_APPEARANCE_GENERIC_REMOTE: |
| 2111 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2112 | dev_class[2] = BTM_COD_MINOR_REMOTE_CONTROL; |
| 2113 | break; |
| 2114 | case BTM_BLE_APPEARANCE_GENERIC_THERMOMETER: |
| 2115 | case BTM_BLE_APPEARANCE_THERMOMETER_EAR: |
| 2116 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2117 | dev_class[2] = BTM_COD_MINOR_THERMOMETER; |
| 2118 | break; |
| 2119 | case BTM_BLE_APPEARANCE_GENERIC_HEART_RATE: |
| 2120 | case BTM_BLE_APPEARANCE_HEART_RATE_BELT: |
| 2121 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2122 | dev_class[2] = BTM_COD_MINOR_HEART_PULSE_MONITOR; |
| 2123 | break; |
| 2124 | case BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE: |
| 2125 | case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM: |
| 2126 | case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST: |
| 2127 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2128 | dev_class[2] = BTM_COD_MINOR_BLOOD_MONITOR; |
| 2129 | break; |
| 2130 | case BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER: |
| 2131 | case BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP: |
| 2132 | case BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST: |
| 2133 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2134 | dev_class[2] = BTM_COD_MINOR_PULSE_OXIMETER; |
| 2135 | break; |
| 2136 | case BTM_BLE_APPEARANCE_GENERIC_GLUCOSE: |
| 2137 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2138 | dev_class[2] = BTM_COD_MINOR_GLUCOSE_METER; |
| 2139 | break; |
| 2140 | case BTM_BLE_APPEARANCE_GENERIC_WEIGHT: |
| 2141 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2142 | dev_class[2] = BTM_COD_MINOR_WEIGHING_SCALE; |
| 2143 | break; |
| 2144 | case BTM_BLE_APPEARANCE_GENERIC_WALKING: |
| 2145 | case BTM_BLE_APPEARANCE_WALKING_IN_SHOE: |
| 2146 | case BTM_BLE_APPEARANCE_WALKING_ON_SHOE: |
| 2147 | case BTM_BLE_APPEARANCE_WALKING_ON_HIP: |
| 2148 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2149 | dev_class[2] = BTM_COD_MINOR_STEP_COUNTER; |
| 2150 | break; |
| 2151 | case BTM_BLE_APPEARANCE_GENERIC_WATCH: |
| 2152 | case BTM_BLE_APPEARANCE_SPORTS_WATCH: |
| 2153 | dev_class[1] = BTM_COD_MAJOR_WEARABLE; |
| 2154 | dev_class[2] = BTM_COD_MINOR_WRIST_WATCH; |
| 2155 | break; |
| 2156 | case BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES: |
| 2157 | dev_class[1] = BTM_COD_MAJOR_WEARABLE; |
| 2158 | dev_class[2] = BTM_COD_MINOR_GLASSES; |
| 2159 | break; |
| 2160 | case BTM_BLE_APPEARANCE_GENERIC_DISPLAY: |
| 2161 | dev_class[1] = BTM_COD_MAJOR_IMAGING; |
| 2162 | dev_class[2] = BTM_COD_MINOR_DISPLAY; |
| 2163 | break; |
| 2164 | case BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER: |
| 2165 | dev_class[1] = BTM_COD_MAJOR_AUDIO; |
| 2166 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2167 | break; |
| 2168 | case BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER: |
| 2169 | case BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER: |
| 2170 | case BTM_BLE_APPEARANCE_GENERIC_HID: |
| 2171 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2172 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2173 | break; |
| 2174 | case BTM_BLE_APPEARANCE_HID_KEYBOARD: |
| 2175 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2176 | dev_class[2] = BTM_COD_MINOR_KEYBOARD; |
| 2177 | break; |
| 2178 | case BTM_BLE_APPEARANCE_HID_MOUSE: |
| 2179 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2180 | dev_class[2] = BTM_COD_MINOR_POINTING; |
| 2181 | break; |
| 2182 | case BTM_BLE_APPEARANCE_HID_JOYSTICK: |
| 2183 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2184 | dev_class[2] = BTM_COD_MINOR_JOYSTICK; |
| 2185 | break; |
| 2186 | case BTM_BLE_APPEARANCE_HID_GAMEPAD: |
| 2187 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2188 | dev_class[2] = BTM_COD_MINOR_GAMEPAD; |
| 2189 | break; |
| 2190 | case BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET: |
| 2191 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2192 | dev_class[2] = BTM_COD_MINOR_DIGITIZING_TABLET; |
| 2193 | break; |
| 2194 | case BTM_BLE_APPEARANCE_HID_CARD_READER: |
| 2195 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2196 | dev_class[2] = BTM_COD_MINOR_CARD_READER; |
| 2197 | break; |
| 2198 | case BTM_BLE_APPEARANCE_HID_DIGITAL_PEN: |
| 2199 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2200 | dev_class[2] = BTM_COD_MINOR_DIGITAL_PAN; |
| 2201 | break; |
| 2202 | case BTM_BLE_APPEARANCE_UKNOWN: |
| 2203 | case BTM_BLE_APPEARANCE_GENERIC_CLOCK: |
| 2204 | case BTM_BLE_APPEARANCE_GENERIC_TAG: |
| 2205 | case BTM_BLE_APPEARANCE_GENERIC_KEYRING: |
| 2206 | case BTM_BLE_APPEARANCE_GENERIC_CYCLING: |
| 2207 | case BTM_BLE_APPEARANCE_CYCLING_COMPUTER: |
| 2208 | case BTM_BLE_APPEARANCE_CYCLING_SPEED: |
| 2209 | case BTM_BLE_APPEARANCE_CYCLING_CADENCE: |
| 2210 | case BTM_BLE_APPEARANCE_CYCLING_POWER: |
| 2211 | case BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE: |
| 2212 | case BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS: |
| 2213 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION: |
| 2214 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV: |
| 2215 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD: |
| 2216 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV: |
| 2217 | default: |
| 2218 | dev_class[1] = BTM_COD_MAJOR_UNCLASSIFIED; |
| 2219 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2220 | }; |
| 2221 | } |
| 2222 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2223 | /******************************************************************************* |
| 2224 | ** |
| 2225 | ** Function btm_ble_update_inq_result |
| 2226 | ** |
| 2227 | ** Description Update adv packet information into inquiry result. |
| 2228 | ** |
| 2229 | ** Parameters |
| 2230 | ** |
| 2231 | ** Returns void |
| 2232 | ** |
| 2233 | *******************************************************************************/ |
| 2234 | BOOLEAN btm_ble_update_inq_result(tINQ_DB_ENT *p_i, UINT8 addr_type, UINT8 evt_type, UINT8 *p) |
| 2235 | { |
| 2236 | BOOLEAN to_report = TRUE; |
| 2237 | tBTM_INQ_RESULTS *p_cur = &p_i->inq_info.results; |
| 2238 | UINT8 len; |
| 2239 | UINT8 *p_flag; |
| 2240 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 2241 | UINT8 data_len, rssi; |
| 2242 | tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 2243 | UINT8 *p1; |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2244 | UINT8 *p_uuid16; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2245 | |
| 2246 | STREAM_TO_UINT8 (data_len, p); |
| 2247 | |
| 2248 | if (data_len > BTM_BLE_ADV_DATA_LEN_MAX) |
| 2249 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2250 | BTM_TRACE_WARNING("EIR data too long %d. discard", data_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2251 | return FALSE; |
| 2252 | } |
| 2253 | btm_ble_cache_adv_data(p_cur, data_len, p, evt_type); |
| 2254 | |
| 2255 | p1 = (p + data_len); |
| 2256 | STREAM_TO_UINT8 (rssi, p1); |
| 2257 | |
| 2258 | /* Save the info */ |
| 2259 | p_cur->inq_result_type = BTM_INQ_RESULT_BLE; |
| 2260 | p_cur->ble_addr_type = addr_type; |
| 2261 | p_cur->rssi = rssi; |
| 2262 | |
| 2263 | /* active scan, always wait until get scan_rsp to report the result */ |
| 2264 | if ((btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI && |
| 2265 | (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_DISCOVER_EVT))) |
| 2266 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2267 | BTM_TRACE_DEBUG("btm_ble_update_inq_result scan_rsp=false, to_report=false,\ |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2268 | scan_type_active=%d", btm_cb.ble_ctr_cb.inq_var.scan_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2269 | p_i->scan_rsp = FALSE; |
| 2270 | to_report = FALSE; |
| 2271 | } |
| 2272 | else |
| 2273 | p_i->scan_rsp = TRUE; |
| 2274 | |
| 2275 | if (p_i->inq_count != p_inq->inq_counter) |
| 2276 | p_cur->device_type = BT_DEVICE_TYPE_BLE; |
| 2277 | else |
| 2278 | p_cur->device_type |= BT_DEVICE_TYPE_BLE; |
| 2279 | |
| 2280 | if (evt_type != BTM_BLE_SCAN_RSP_EVT) |
| 2281 | p_cur->ble_evt_type = evt_type; |
| 2282 | |
| 2283 | p_i->inq_count = p_inq->inq_counter; /* Mark entry for current inquiry */ |
| 2284 | |
| 2285 | if (p_le_inq_cb->adv_len != 0) |
| 2286 | { |
| 2287 | if ((p_flag = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_FLAG, &len)) != NULL) |
| 2288 | p_cur->flag = * p_flag; |
| 2289 | } |
| 2290 | |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2291 | if (p_le_inq_cb->adv_len != 0) |
| 2292 | { |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2293 | /* Check to see the BLE device has the Appearance UUID in the advertising data. If it does |
| 2294 | * then try to convert the appearance value to a class of device value Bluedroid can use. |
| 2295 | * Otherwise fall back to trying to infer if it is a HID device based on the service class. |
| 2296 | */ |
| 2297 | p_uuid16 = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_APPEARANCE, &len); |
| 2298 | if (p_uuid16 && len == 2) |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2299 | { |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2300 | btm_ble_appearance_to_cod((UINT16)p_uuid16[0] | (p_uuid16[1] << 8), p_cur->dev_class); |
| 2301 | } |
| 2302 | else |
| 2303 | { |
| 2304 | if ((p_uuid16 = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, |
| 2305 | BTM_BLE_AD_TYPE_16SRV_CMPL, &len)) != NULL) |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2306 | { |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2307 | UINT8 i; |
| 2308 | for (i = 0; i + 2 <= len; i = i + 2) |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2309 | { |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2310 | /* if this BLE device support HID over LE, set HID Major in class of device */ |
| 2311 | if ((p_uuid16[i] | (p_uuid16[i+1] << 8)) == UUID_SERVCLASS_LE_HID) |
| 2312 | { |
| 2313 | p_cur->dev_class[0] = 0; |
| 2314 | p_cur->dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2315 | p_cur->dev_class[2] = 0; |
| 2316 | break; |
| 2317 | } |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | } |
| 2322 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2323 | /* if BR/EDR not supported is not set, assume is a DUMO device */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2324 | if ((p_cur->flag & BTM_BLE_BREDR_NOT_SPT) == 0 && |
| 2325 | evt_type != BTM_BLE_CONNECT_DIR_EVT) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2326 | { |
Andre Eisenbach | bf68ac7 | 2013-10-25 16:17:45 -0700 | [diff] [blame] | 2327 | if (p_cur->ble_addr_type != BLE_ADDR_RANDOM) |
| 2328 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2329 | BTM_TRACE_DEBUG("BR/EDR NOT support bit not set, treat as DUMO"); |
Andre Eisenbach | bf68ac7 | 2013-10-25 16:17:45 -0700 | [diff] [blame] | 2330 | p_cur->device_type |= BT_DEVICE_TYPE_DUMO; |
| 2331 | } else { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2332 | BTM_TRACE_DEBUG("Random address, treating device as LE only"); |
Andre Eisenbach | bf68ac7 | 2013-10-25 16:17:45 -0700 | [diff] [blame] | 2333 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2334 | } |
| 2335 | else |
| 2336 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2337 | BTM_TRACE_DEBUG("BR/EDR NOT SUPPORT bit set, LE only device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | return to_report; |
| 2341 | |
| 2342 | } |
| 2343 | |
| 2344 | /******************************************************************************* |
| 2345 | ** |
| 2346 | ** Function btm_send_sel_conn_callback |
| 2347 | ** |
| 2348 | ** Description send selection connection request callback. |
| 2349 | ** |
| 2350 | ** Parameters |
| 2351 | ** |
| 2352 | ** Returns void |
| 2353 | ** |
| 2354 | *******************************************************************************/ |
| 2355 | void btm_send_sel_conn_callback(BD_ADDR remote_bda, UINT8 evt_type, UINT8 *p_data, UINT8 addr_type) |
| 2356 | { |
| 2357 | UINT8 data_len, len; |
| 2358 | UINT8 *p_dev_name, remname[31] = {0}; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2359 | UNUSED(addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2360 | |
| 2361 | if (btm_cb.ble_ctr_cb.p_select_cback == NULL || |
| 2362 | /* non-connectable device */ |
| 2363 | (evt_type != BTM_BLE_EVT_CONN_ADV && evt_type != BTM_BLE_EVT_CONN_DIR_ADV)) |
| 2364 | return; |
| 2365 | |
| 2366 | STREAM_TO_UINT8 (data_len, p_data); |
| 2367 | |
| 2368 | /* get the device name if exist in ADV data */ |
| 2369 | if (data_len != 0) |
| 2370 | { |
| 2371 | p_dev_name = BTM_CheckAdvData(p_data, BTM_BLE_AD_TYPE_NAME_CMPL, &len); |
| 2372 | |
| 2373 | if (p_dev_name == NULL) |
| 2374 | p_dev_name = BTM_CheckAdvData(p_data, BTM_BLE_AD_TYPE_NAME_SHORT, &len); |
| 2375 | |
| 2376 | if (p_dev_name) |
| 2377 | memcpy(remname, p_dev_name, len); |
| 2378 | } |
| 2379 | /* allow connection */ |
| 2380 | if ((* btm_cb.ble_ctr_cb.p_select_cback)(remote_bda, remname)) |
| 2381 | { |
| 2382 | /* terminate selective connection, initiate connection */ |
| 2383 | btm_ble_initiate_select_conn(remote_bda); |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | /******************************************************************************* |
| 2388 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2389 | ** Function btm_ble_process_adv_pkt |
| 2390 | ** |
| 2391 | ** Description This function is called when adv packet report events are |
| 2392 | ** received from the device. It updates the inquiry database. |
| 2393 | ** If the inquiry database is full, the oldest entry is discarded. |
| 2394 | ** |
| 2395 | ** Parameters |
| 2396 | ** |
| 2397 | ** Returns void |
| 2398 | ** |
| 2399 | *******************************************************************************/ |
| 2400 | void btm_ble_process_adv_pkt (UINT8 *p_data) |
| 2401 | { |
| 2402 | BD_ADDR bda; |
| 2403 | UINT8 evt_type = 0, *p = p_data; |
| 2404 | UINT8 addr_type = 0; |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2405 | UINT8 num_reports; |
| 2406 | UINT8 data_len; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2407 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 2408 | BOOLEAN match = FALSE; |
| 2409 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2410 | |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2411 | /* Extract the number of reports in this event. */ |
| 2412 | STREAM_TO_UINT8(num_reports, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2413 | |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2414 | while (num_reports--) |
| 2415 | { |
| 2416 | /* Extract inquiry results */ |
| 2417 | STREAM_TO_UINT8 (evt_type, p); |
| 2418 | STREAM_TO_UINT8 (addr_type, p); |
| 2419 | STREAM_TO_BDADDR (bda, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2420 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2421 | #ifdef BTM_BLE_PC_ADV_TEST_MODE /* For general stack code (e.g. BTInsight testing), we simply do not define it to exclude or set it to TRUE to include */ |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2422 | if (BTM_BLE_PC_ADV_TEST_MODE) /* For stack component, it is always defined and maps to a global variable g_bDraculaAdvertisingMode */ |
| 2423 | { |
| 2424 | if (btm_cb.ble_ctr_cb.p_scan_req_cback) |
| 2425 | (*btm_cb.ble_ctr_cb.p_scan_req_cback)(bda, addr_type, evt_type); |
| 2426 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2427 | #endif |
| 2428 | |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 2429 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2430 | /* map address to security record */ |
| 2431 | btm_public_addr_to_random_pseudo(bda, &addr_type); |
| 2432 | BTM_TRACE_ERROR("new address: %02x:%02x:%02x:%02x:%02x:%02x", |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 2433 | bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); |
| 2434 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2435 | |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2436 | /* Only process the results if the inquiry is still active */ |
| 2437 | if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
| 2438 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2439 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2440 | BTM_TRACE_DEBUG("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x", |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2441 | bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2442 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 2443 | #if SMP_INCLUDED == TRUE |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2444 | /* always do RRA resolution on host */ |
| 2445 | if (!match && BTM_BLE_IS_RESOLVE_BDA(bda)) |
| 2446 | { |
| 2447 | btm_ble_resolve_random_addr(bda, btm_ble_resolve_random_addr_on_adv, p_data); |
| 2448 | } |
| 2449 | else |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 2450 | #endif |
| 2451 | #endif |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2452 | { |
| 2453 | btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, p); |
| 2454 | } |
| 2455 | |
| 2456 | STREAM_TO_UINT8(data_len, p); |
| 2457 | |
| 2458 | /* Advance to the next event data_len + rssi byte */ |
| 2459 | p += data_len + 1; |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 2460 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | /******************************************************************************* |
| 2464 | ** |
| 2465 | ** Function btm_ble_process_adv_pkt_cont |
| 2466 | ** |
| 2467 | ** Description This function is called after random address resolution is |
| 2468 | ** done, and proceed to process adv packet. |
| 2469 | ** |
| 2470 | ** Parameters |
| 2471 | ** |
| 2472 | ** Returns void |
| 2473 | ** |
| 2474 | *******************************************************************************/ |
| 2475 | static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt_type, UINT8 *p) |
| 2476 | { |
| 2477 | tINQ_DB_ENT *p_i; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2478 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 2479 | tBTM_INQ_RESULTS_CB *p_inq_results_cb = p_inq->p_inq_results_cb; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2480 | tBTM_INQ_RESULTS_CB *p_obs_results_cb = btm_cb.ble_ctr_cb.p_obs_results_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2481 | tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2482 | BOOLEAN update = TRUE; |
| 2483 | UINT8 result = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2484 | |
| 2485 | p_i = btm_inq_db_find (bda); |
| 2486 | |
| 2487 | /* Check if this address has already been processed for this inquiry */ |
| 2488 | if (btm_inq_find_bdaddr(bda)) |
| 2489 | { |
| 2490 | /* never been report as an LE device */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2491 | if (p_i && |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2492 | (!(p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) || |
| 2493 | /* scan repsonse to be updated */ |
| 2494 | (!p_i->scan_rsp))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2495 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2496 | update = TRUE; |
| 2497 | } |
| 2498 | else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
| 2499 | { |
| 2500 | update = FALSE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2501 | } |
| 2502 | else |
| 2503 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2504 | /* if yes, skip it */ |
| 2505 | return; /* assumption: one result per event */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2506 | } |
| 2507 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2508 | /* If existing entry, use that, else get a new one (possibly reusing the oldest) */ |
| 2509 | if (p_i == NULL) |
| 2510 | { |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2511 | if ((p_i = btm_inq_db_new (bda)) != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2512 | { |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2513 | p_inq->inq_cmpl_info.num_resp++; |
| 2514 | } |
| 2515 | else |
| 2516 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2517 | } |
| 2518 | else if (p_i->inq_count != p_inq->inq_counter) /* first time seen in this inquiry */ |
| 2519 | { |
| 2520 | p_inq->inq_cmpl_info.num_resp++; |
| 2521 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2522 | /* update the LE device information in inquiry database */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2523 | if (!btm_ble_update_inq_result(p_i, addr_type, evt_type, p)) |
| 2524 | return; |
| 2525 | |
| 2526 | if ((result = btm_ble_is_discoverable(bda, evt_type, p)) == 0) |
| 2527 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2528 | BTM_TRACE_ERROR("discard adv pkt"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2529 | return; |
| 2530 | } |
| 2531 | if (!update) |
| 2532 | result &= ~BTM_BLE_INQ_RESULT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2533 | #if BTM_USE_INQ_RESULTS_FILTER == TRUE |
| 2534 | /* If the number of responses found and limited, issue a cancel inquiry */ |
| 2535 | if (p_inq->inqparms.max_resps && |
| 2536 | p_inq->inq_cmpl_info.num_resp == p_inq->inqparms.max_resps) |
| 2537 | { |
| 2538 | /* new device */ |
| 2539 | if (p_i == NULL || |
| 2540 | (/* assume a DUMO device, BR/EDR inquiry is always active */ |
| 2541 | p_i && p_i->inq_info.results.device_type == BT_DEVICE_TYPE_BLE && p_i->scan_rsp)) |
| 2542 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2543 | BTM_TRACE_WARNING("INQ RES: Extra Response Received...cancelling inquiry.."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2544 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2545 | /* if is non-periodic inquiry active, cancel now */ |
| 2546 | if ((p_inq->inq_active & BTM_BR_INQ_ACTIVE_MASK) != 0 && |
| 2547 | (p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) == 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2548 | btsnd_hcic_inq_cancel(); |
| 2549 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2550 | btm_ble_stop_inquiry(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2551 | |
| 2552 | #if BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE |
| 2553 | btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT); |
| 2554 | #endif |
| 2555 | } |
| 2556 | } |
| 2557 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2558 | /* background connection in selective connection mode */ |
| 2559 | if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) |
| 2560 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2561 | if (result & BTM_BLE_SEL_CONN_RESULT) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2562 | btm_send_sel_conn_callback(bda, evt_type, p, addr_type); |
| 2563 | else |
| 2564 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2565 | BTM_TRACE_DEBUG("None LE device, can not initiate selective connection"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2566 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2567 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2568 | else |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2569 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2570 | if (p_inq_results_cb && (result & BTM_BLE_INQ_RESULT)) |
| 2571 | { |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2572 | (p_inq_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, p_le_inq_cb->adv_data_cache); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2573 | } |
| 2574 | if (p_obs_results_cb && (result & BTM_BLE_OBS_RESULT)) |
| 2575 | { |
| 2576 | (p_obs_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, p_le_inq_cb->adv_data_cache); |
| 2577 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | /******************************************************************************* |
| 2582 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2583 | ** Function btm_ble_start_scan |
| 2584 | ** |
| 2585 | ** Description Start the BLE scan. |
| 2586 | ** |
| 2587 | ** Returns void |
| 2588 | ** |
| 2589 | *******************************************************************************/ |
| 2590 | tBTM_STATUS btm_ble_start_scan (UINT8 filter_enable) |
| 2591 | { |
| 2592 | tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; |
| 2593 | tBTM_STATUS status = BTM_CMD_STARTED; |
| 2594 | |
| 2595 | /* start scan, disable duplicate filtering */ |
Mike J. Chen | dab8714 | 2014-07-18 17:40:12 -0700 | [diff] [blame] | 2596 | if (!btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, filter_enable)) { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2597 | status = BTM_NO_RESOURCES; |
Mike J. Chen | dab8714 | 2014-07-18 17:40:12 -0700 | [diff] [blame] | 2598 | btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN; |
| 2599 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2600 | else |
| 2601 | { |
Mike J. Chen | dab8714 | 2014-07-18 17:40:12 -0700 | [diff] [blame] | 2602 | btm_cb.ble_ctr_cb.wl_state |= BTM_BLE_WL_SCAN; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2603 | if (p_inq->scan_type == BTM_BLE_SCAN_MODE_ACTI) |
| 2604 | btm_ble_set_topology_mask(BTM_BLE_STATE_ACTIVE_SCAN_BIT); |
| 2605 | else |
| 2606 | btm_ble_set_topology_mask(BTM_BLE_STATE_PASSIVE_SCAN_BIT); |
| 2607 | } |
| 2608 | return status; |
| 2609 | } |
| 2610 | |
| 2611 | /******************************************************************************* |
| 2612 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2613 | ** Function btm_ble_stop_scan |
| 2614 | ** |
| 2615 | ** Description Stop the BLE scan. |
| 2616 | ** |
| 2617 | ** Returns void |
| 2618 | ** |
| 2619 | *******************************************************************************/ |
| 2620 | void btm_ble_stop_scan(void) |
| 2621 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2622 | BTM_TRACE_EVENT ("btm_ble_stop_scan "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2623 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2624 | /* Clear the inquiry callback if set */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2625 | btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2626 | |
| 2627 | /* stop discovery now */ |
| 2628 | btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); |
| 2629 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2630 | btm_update_scanner_filter_policy(SP_ADV_ALL); |
Mike J. Chen | dab8714 | 2014-07-18 17:40:12 -0700 | [diff] [blame] | 2631 | |
| 2632 | btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2633 | } |
| 2634 | /******************************************************************************* |
| 2635 | ** |
| 2636 | ** Function btm_ble_stop_inquiry |
| 2637 | ** |
| 2638 | ** Description Stop the BLE Inquiry. |
| 2639 | ** |
| 2640 | ** Returns void |
| 2641 | ** |
| 2642 | *******************************************************************************/ |
| 2643 | void btm_ble_stop_inquiry(void) |
| 2644 | { |
| 2645 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 2646 | tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; |
| 2647 | |
| 2648 | btu_stop_timer (&p_ble_cb->inq_var.inq_timer_ent); |
| 2649 | |
| 2650 | p_ble_cb->scan_activity &= ~BTM_BLE_INQUIRY_MASK; |
| 2651 | |
| 2652 | /* If no more scan activity, stop LE scan now */ |
| 2653 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) |
| 2654 | btm_ble_stop_scan(); |
| 2655 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2656 | /* If we have a callback registered for inquiry complete, call it */ |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2657 | BTM_TRACE_DEBUG ("BTM Inq Compl Callback: status 0x%02x, num results %d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2658 | p_inq->inq_cmpl_info.status, p_inq->inq_cmpl_info.num_resp); |
| 2659 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2660 | btm_process_inq_complete(HCI_SUCCESS, (UINT8)(p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | /******************************************************************************* |
| 2664 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2665 | ** Function btm_ble_stop_observe |
| 2666 | ** |
| 2667 | ** Description Stop the BLE Observe. |
| 2668 | ** |
| 2669 | ** Returns void |
| 2670 | ** |
| 2671 | *******************************************************************************/ |
| 2672 | static void btm_ble_stop_observe(void) |
| 2673 | { |
| 2674 | tBTM_BLE_CB *p_ble_cb = & btm_cb.ble_ctr_cb; |
| 2675 | tBTM_CMPL_CB *p_obs_cb = p_ble_cb->p_obs_cmpl_cb; |
| 2676 | |
| 2677 | btu_stop_timer (&p_ble_cb->obs_timer_ent); |
| 2678 | |
| 2679 | p_ble_cb->scan_activity &= ~BTM_LE_OBSERVE_ACTIVE; |
| 2680 | |
| 2681 | p_ble_cb->p_obs_results_cb = NULL; |
| 2682 | p_ble_cb->p_obs_cmpl_cb = NULL; |
| 2683 | |
| 2684 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) |
| 2685 | btm_ble_stop_scan(); |
| 2686 | |
| 2687 | if (p_obs_cb) |
| 2688 | (p_obs_cb)((tBTM_INQUIRY_CMPL *) &btm_cb.btm_inq_vars.inq_cmpl_info); |
| 2689 | } |
| 2690 | /******************************************************************************* |
| 2691 | ** |
| 2692 | ** Function btm_ble_adv_states_operation |
| 2693 | ** |
| 2694 | ** Description Set or clear adv states in topology mask |
| 2695 | ** |
| 2696 | ** Returns operation status. TRUE if sucessful, FALSE otherwise. |
| 2697 | ** |
| 2698 | *******************************************************************************/ |
| 2699 | typedef BOOLEAN (BTM_TOPOLOGY_FUNC_PTR)(tBTM_BLE_STATE_MASK); |
| 2700 | static BOOLEAN btm_ble_adv_states_operation(BTM_TOPOLOGY_FUNC_PTR *p_handler, UINT8 adv_evt) |
| 2701 | { |
| 2702 | BOOLEAN rt = FALSE; |
| 2703 | |
| 2704 | switch (adv_evt) |
| 2705 | { |
| 2706 | case BTM_BLE_CONNECT_EVT: |
| 2707 | rt = (*p_handler)(BTM_BLE_STATE_CONN_ADV_BIT); |
| 2708 | break; |
| 2709 | |
| 2710 | case BTM_BLE_NON_CONNECT_EVT: |
| 2711 | rt = (*p_handler) (BTM_BLE_STATE_NON_CONN_ADV_BIT); |
| 2712 | break; |
| 2713 | case BTM_BLE_CONNECT_DIR_EVT: |
| 2714 | rt = (*p_handler) (BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT); |
| 2715 | break; |
| 2716 | |
| 2717 | case BTM_BLE_DISCOVER_EVT: |
| 2718 | rt = (*p_handler) (BTM_BLE_STATE_SCAN_ADV_BIT); |
| 2719 | break; |
| 2720 | |
| 2721 | default: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2722 | BTM_TRACE_ERROR("unknown adv event : %d", adv_evt); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2723 | break; |
| 2724 | } |
| 2725 | |
| 2726 | return rt; |
| 2727 | } |
| 2728 | |
| 2729 | |
| 2730 | /******************************************************************************* |
| 2731 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2732 | ** Function btm_ble_start_adv |
| 2733 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2734 | ** Description start the BLE advertising. |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2735 | ** |
| 2736 | ** Returns void |
| 2737 | ** |
| 2738 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2739 | tBTM_STATUS btm_ble_start_adv(void) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2740 | { |
| 2741 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 2742 | tBTM_STATUS rt = BTM_NO_RESOURCES; |
| 2743 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2744 | if (!btm_ble_adv_states_operation (btm_ble_topology_check, p_cb->evt_type)) |
| 2745 | return BTM_WRONG_MODE; |
| 2746 | |
| 2747 | if (p_cb->afp != AP_SCAN_CONN_ALL) |
| 2748 | { |
| 2749 | btm_execute_wl_dev_operation(); |
| 2750 | btm_cb.ble_ctr_cb.wl_state |= BTM_BLE_WL_ADV; |
| 2751 | } |
| 2752 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2753 | if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE)) |
| 2754 | { |
| 2755 | if (p_cb->afp != AP_SCAN_CONN_ALL) |
| 2756 | btm_cb.ble_ctr_cb.wl_state |= BTM_BLE_WL_ADV; |
| 2757 | |
| 2758 | p_cb->adv_mode = BTM_BLE_ADV_ENABLE; |
| 2759 | |
| 2760 | rt = BTM_SUCCESS; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2761 | } |
| 2762 | else |
| 2763 | { |
| 2764 | p_cb->adv_mode = BTM_BLE_ADV_DISABLE; |
| 2765 | btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV; |
| 2766 | } |
| 2767 | return rt; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2768 | } |
| 2769 | /******************************************************************************* |
| 2770 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2771 | ** Function btm_ble_stop_adv |
| 2772 | ** |
| 2773 | ** Description Stop the BLE advertising. |
| 2774 | ** |
| 2775 | ** Returns void |
| 2776 | ** |
| 2777 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2778 | tBTM_STATUS btm_ble_stop_adv(void) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2779 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2780 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 2781 | tBTM_STATUS rt = BTM_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2782 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2783 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2784 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2785 | if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE)) |
| 2786 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2787 | p_cb->fast_adv_on = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2788 | p_cb->adv_mode = BTM_BLE_ADV_DISABLE; |
| 2789 | btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2790 | |
| 2791 | /* clear all adv states */ |
| 2792 | btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_ADV_MASK); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2793 | } |
| 2794 | else |
| 2795 | rt = BTM_NO_RESOURCES; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2796 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2797 | return rt; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2798 | } |
| 2799 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2800 | |
| 2801 | /******************************************************************************* |
| 2802 | ** |
| 2803 | ** Function btm_ble_set_topology_mask |
| 2804 | ** |
| 2805 | ** Description set BLE topology mask |
| 2806 | ** |
| 2807 | ** Returns TRUE is request is allowed, FALSE otherwise. |
| 2808 | ** |
| 2809 | *******************************************************************************/ |
| 2810 | BOOLEAN btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state_mask) |
| 2811 | { |
| 2812 | BOOLEAN rt = TRUE; |
| 2813 | |
| 2814 | request_state_mask &= BTM_BLE_STATE_ALL_MASK; |
| 2815 | |
| 2816 | btm_cb.ble_ctr_cb.cur_states |= request_state_mask; |
| 2817 | |
| 2818 | return rt; |
| 2819 | } |
| 2820 | /******************************************************************************* |
| 2821 | ** |
| 2822 | ** Function btm_ble_clear_topology_mask |
| 2823 | ** |
| 2824 | ** Description Clear BLE topology bit mask |
| 2825 | ** |
| 2826 | ** Returns TRUE is request is allowed, FALSE otherwise. |
| 2827 | ** |
| 2828 | *******************************************************************************/ |
| 2829 | BOOLEAN btm_ble_clear_topology_mask (tBTM_BLE_STATE_MASK request_state_mask) |
| 2830 | { |
| 2831 | request_state_mask &= BTM_BLE_STATE_ALL_MASK; |
| 2832 | |
| 2833 | btm_cb.ble_ctr_cb.cur_states &= ~request_state_mask; |
| 2834 | |
| 2835 | return TRUE; |
| 2836 | } |
| 2837 | /******************************************************************************* |
| 2838 | ** |
| 2839 | ** Function btm_ble_update_mode_operation |
| 2840 | ** |
| 2841 | ** Description This function update the GAP role operation when a link status |
| 2842 | ** is updated. |
| 2843 | ** |
| 2844 | ** Returns void |
| 2845 | ** |
| 2846 | *******************************************************************************/ |
| 2847 | void btm_ble_update_mode_operation(UINT8 link_role, BD_ADDR bd_addr, BOOLEAN conn_cancel) |
| 2848 | { |
| 2849 | tACL_CONN *pa = &btm_cb.acl_db[0]; |
| 2850 | UINT16 xx; |
| 2851 | UINT16 mask = BTM_BLE_STATE_ALL_CONN_MASK; |
| 2852 | |
| 2853 | UNUSED(bd_addr); |
| 2854 | UNUSED (conn_cancel); |
| 2855 | |
| 2856 | if (link_role == HCI_ROLE_SLAVE) |
| 2857 | { |
| 2858 | btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 2859 | /* clear all adv states */ |
| 2860 | mask |= BTM_BLE_STATE_ALL_ADV_MASK; |
| 2861 | } |
| 2862 | |
| 2863 | btm_ble_clear_topology_mask (mask); |
| 2864 | |
| 2865 | /* check the device link role maps */ |
| 2866 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, pa++) |
| 2867 | { |
| 2868 | if (pa->in_use && pa->transport == BT_TRANSPORT_LE) |
| 2869 | { |
| 2870 | if (pa->link_role == HCI_ROLE_MASTER) |
| 2871 | btm_ble_set_topology_mask (BTM_BLE_STATE_MASTER_BIT); |
| 2872 | else |
| 2873 | btm_ble_set_topology_mask (BTM_BLE_STATE_SLAVE_BIT); |
| 2874 | } |
| 2875 | } |
| 2876 | |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 2877 | if (btm_cb.cmn_ble_vsc_cb.adv_inst_max == 0 && |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 2878 | btm_cb.ble_ctr_cb.inq_var.connectable_mode == BTM_BLE_CONNECTABLE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2879 | { |
| 2880 | btm_ble_set_connectability ( btm_cb.ble_ctr_cb.inq_var.connectable_mode ); |
| 2881 | } |
| 2882 | |
| 2883 | if (btm_ble_get_conn_st() == BLE_CONN_IDLE) |
| 2884 | { |
| 2885 | if (!btm_send_pending_direct_conn()) |
| 2886 | { |
| 2887 | btm_ble_resume_bg_conn(); |
| 2888 | } |
| 2889 | } |
| 2890 | } |
| 2891 | |
| 2892 | /******************************************************************************* |
| 2893 | ** |
| 2894 | ** Function btm_ble_start_slow_adv |
| 2895 | ** |
| 2896 | ** Description Restart adv with slow adv interval |
| 2897 | ** |
| 2898 | ** Returns void |
| 2899 | ** |
| 2900 | *******************************************************************************/ |
| 2901 | static void btm_ble_start_slow_adv (void) |
| 2902 | { |
| 2903 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 2904 | BD_ADDR p_addr_ptr= {0}; |
| 2905 | |
| 2906 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) |
| 2907 | { |
| 2908 | btm_ble_stop_adv(); |
| 2909 | |
| 2910 | btsnd_hcic_ble_write_adv_params (BTM_BLE_GAP_ADV_SLOW_INT, |
| 2911 | BTM_BLE_GAP_ADV_SLOW_INT, |
| 2912 | p_cb->evt_type, |
| 2913 | p_cb->adv_addr_type, |
| 2914 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type,/* slow adv |
| 2915 | mode never goes into directed adv */ |
| 2916 | p_addr_ptr, |
| 2917 | p_cb->adv_chnl_map, |
| 2918 | p_cb->afp); |
| 2919 | |
| 2920 | btm_ble_start_adv(); |
| 2921 | } |
| 2922 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2923 | /******************************************************************************* |
| 2924 | ** |
| 2925 | ** Function btm_ble_timeout |
| 2926 | ** |
| 2927 | ** Description Called when BTM BLE inquiry timer expires |
| 2928 | ** |
| 2929 | ** Returns void |
| 2930 | ** |
| 2931 | *******************************************************************************/ |
| 2932 | void btm_ble_timeout(TIMER_LIST_ENT *p_tle) |
| 2933 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2934 | BTM_TRACE_EVENT ("btm_ble_timeout"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2935 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2936 | switch (p_tle->event) |
| 2937 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2938 | case BTU_TTYPE_BLE_OBSERVE: |
| 2939 | btm_ble_stop_observe(); |
| 2940 | break; |
| 2941 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2942 | case BTU_TTYPE_BLE_INQUIRY: |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2943 | btm_ble_stop_inquiry(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2944 | break; |
| 2945 | |
| 2946 | case BTU_TTYPE_BLE_GAP_LIM_DISC: |
| 2947 | /* lim_timeout expiried, limited discovery should exit now */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2948 | btm_cb.btm_inq_vars.discoverable_mode &= ~BTM_BLE_LIMITED_DISCOVERABLE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2949 | btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode, btm_cb.btm_inq_vars.discoverable_mode); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2950 | break; |
| 2951 | |
| 2952 | case BTU_TTYPE_BLE_RANDOM_ADDR: |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2953 | if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2954 | { |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 2955 | if (NULL == (void *)(p_tle->param)) |
| 2956 | { |
| 2957 | /* refresh the random addr */ |
| 2958 | btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low); |
| 2959 | } |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 2960 | else |
| 2961 | { |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 2962 | if (BTM_BleMaxMultiAdvInstanceCount() > 0) |
| 2963 | btm_ble_multi_adv_configure_rpa((tBTM_BLE_MULTI_ADV_INST*)p_tle->param); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 2964 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2965 | } |
| 2966 | break; |
| 2967 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2968 | case BTU_TTYPE_BLE_GAP_FAST_ADV: |
| 2969 | /* fast adv is completed, fall back to slow adv interval */ |
| 2970 | btm_ble_start_slow_adv(); |
| 2971 | break; |
| 2972 | |
| 2973 | default: |
| 2974 | break; |
| 2975 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2976 | } |
| 2977 | } |
| 2978 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2979 | |
| 2980 | /******************************************************************************* |
| 2981 | ** |
| 2982 | ** Function btm_ble_read_remote_features_complete |
| 2983 | ** |
| 2984 | ** Description This function is called when the command complete message |
| 2985 | ** is received from the HCI for the read LE remote feature supported |
| 2986 | ** complete event. |
| 2987 | ** |
| 2988 | ** Returns void |
| 2989 | ** |
| 2990 | *******************************************************************************/ |
| 2991 | void btm_ble_read_remote_features_complete(UINT8 *p) |
| 2992 | { |
| 2993 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2994 | UINT16 handle; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2995 | int xx; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2996 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2997 | BTM_TRACE_EVENT ("btm_ble_read_remote_features_complete "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2998 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2999 | /* Skip status */ |
| 3000 | p++; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3001 | STREAM_TO_UINT16 (handle, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3002 | |
| 3003 | /* Look up the connection by handle and copy features */ |
| 3004 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++) |
| 3005 | { |
| 3006 | if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle)) |
| 3007 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3008 | STREAM_TO_ARRAY(p_acl_cb->peer_le_features, p, BD_FEATURES_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3009 | break; |
| 3010 | } |
| 3011 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3012 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | /******************************************************************************* |
| 3016 | ** |
| 3017 | ** Function btm_ble_write_adv_enable_complete |
| 3018 | ** |
| 3019 | ** Description This function process the write adv enable command complete. |
| 3020 | ** |
| 3021 | ** Returns void |
| 3022 | ** |
| 3023 | *******************************************************************************/ |
| 3024 | void btm_ble_write_adv_enable_complete(UINT8 * p) |
| 3025 | { |
| 3026 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 3027 | |
| 3028 | /* if write adv enable/disbale not succeed */ |
| 3029 | if (*p != HCI_SUCCESS) |
| 3030 | { |
| 3031 | /* toggle back the adv mode */ |
| 3032 | p_cb->adv_mode = !p_cb->adv_mode; |
| 3033 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3034 | |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 3035 | #if (BLE_PRIVACY_SPT == TRUE) |
| 3036 | if ((p_cb->adv_mode == BTM_BLE_ADV_DISABLE) && |
| 3037 | (btm_cb.cmn_ble_vsc_cb.rpa_offloading == TRUE)) |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 3038 | btm_ble_vendor_disable_irk_list(); |
| 3039 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3040 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3041 | |
| 3042 | /******************************************************************************* |
| 3043 | ** |
| 3044 | ** Function btm_ble_dir_adv_tout |
| 3045 | ** |
| 3046 | ** Description when directed adv time out |
| 3047 | ** |
| 3048 | ** Returns void |
| 3049 | ** |
| 3050 | *******************************************************************************/ |
| 3051 | void btm_ble_dir_adv_tout(void) |
| 3052 | { |
| 3053 | btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 3054 | |
| 3055 | /* make device fall back into undirected adv mode by default */ |
| 3056 | btm_cb.ble_ctr_cb.inq_var.directed_conn = FALSE; |
| 3057 | } |
| 3058 | |
| 3059 | /******************************************************************************* |
| 3060 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3061 | ** Function btm_ble_init |
| 3062 | ** |
| 3063 | ** Description Initialize the control block variable values. |
| 3064 | ** |
| 3065 | ** Returns void |
| 3066 | ** |
| 3067 | *******************************************************************************/ |
| 3068 | void btm_ble_init (void) |
| 3069 | { |
| 3070 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 3071 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3072 | BTM_TRACE_EVENT ("btm_ble_init "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3073 | |
| 3074 | memset(p_cb, 0, sizeof(tBTM_BLE_CB)); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 3075 | memset(&(btm_cb.cmn_ble_vsc_cb), 0 , sizeof(tBTM_BLE_VSC_CB)); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3076 | p_cb->cur_states = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3077 | |
| 3078 | p_cb->inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 3079 | p_cb->inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; |
| 3080 | p_cb->inq_var.adv_chnl_map = BTM_BLE_DEFAULT_ADV_CHNL_MAP; |
| 3081 | p_cb->inq_var.afp = BTM_BLE_DEFAULT_AFP; |
| 3082 | p_cb->inq_var.sfp = BTM_BLE_DEFAULT_SFP; |
| 3083 | p_cb->inq_var.connectable_mode = BTM_BLE_NON_CONNECTABLE; |
| 3084 | p_cb->inq_var.discoverable_mode = BTM_BLE_NON_DISCOVERABLE; |
| 3085 | |
| 3086 | /* for background connection, reset connection params to be undefined */ |
| 3087 | p_cb->scan_int = p_cb->scan_win = BTM_BLE_CONN_PARAM_UNDEF; |
| 3088 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 3089 | p_cb->inq_var.evt_type = BTM_BLE_NON_CONNECT_EVT; |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 3090 | |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 3091 | #if BLE_VND_INCLUDED == FALSE |
| 3092 | btm_ble_vendor_init(BTM_CS_IRK_LIST_MAX); |
Satya Calloji | 1a9247a | 2014-06-05 13:15:15 -0700 | [diff] [blame] | 3093 | btm_ble_adv_filter_init(); |
| 3094 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3095 | } |
| 3096 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3097 | /******************************************************************************* |
| 3098 | ** |
| 3099 | ** Function btm_ble_topology_check |
| 3100 | ** |
| 3101 | ** Description check to see requested state is supported. One state check at |
| 3102 | ** a time is supported |
| 3103 | ** |
| 3104 | ** Returns TRUE is request is allowed, FALSE otherwise. |
| 3105 | ** |
| 3106 | *******************************************************************************/ |
| 3107 | BOOLEAN btm_ble_topology_check(tBTM_BLE_STATE_MASK request_state_mask) |
| 3108 | { |
| 3109 | BOOLEAN rt = FALSE; |
| 3110 | UINT32 llt_mask = 0; |
| 3111 | UINT8 *p; |
| 3112 | |
| 3113 | UINT8 state_offset = 0; |
| 3114 | UINT16 cur_states = btm_cb.ble_ctr_cb.cur_states; |
| 3115 | UINT8 mask, offset; |
| 3116 | UINT8 request_state = 0; |
| 3117 | |
| 3118 | /* check only one bit is set and within valid range */ |
| 3119 | if (request_state_mask == BTM_BLE_STATE_INVALID || |
| 3120 | request_state_mask > BTM_BLE_STATE_SCAN_ADV_BIT || |
| 3121 | (request_state_mask & (request_state_mask -1 )) != 0) |
| 3122 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3123 | BTM_TRACE_ERROR("illegal state requested: %d", request_state_mask); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3124 | return rt; |
| 3125 | } |
| 3126 | |
| 3127 | while (request_state_mask) |
| 3128 | { |
| 3129 | request_state_mask >>= 1; |
| 3130 | request_state ++; |
| 3131 | } |
| 3132 | |
| 3133 | /* check if the requested state is supported or not */ |
| 3134 | mask = btm_le_state_combo_tbl[0][request_state - 1][0]; |
| 3135 | offset = btm_le_state_combo_tbl[0][request_state-1][1]; |
| 3136 | |
| 3137 | if (!BTM_LE_STATES_SUPPORTED(btm_cb.devcb.le_supported_states, mask, offset)) |
| 3138 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3139 | BTM_TRACE_ERROR("state requested not supported: %d", request_state); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3140 | return rt; |
| 3141 | } |
| 3142 | |
| 3143 | rt = TRUE; |
| 3144 | /* make sure currently active states are all supported in conjunction with the requested |
| 3145 | state. If the bit in table is not set, the combination is not supported */ |
| 3146 | while (cur_states != 0) |
| 3147 | { |
| 3148 | if (cur_states & 0x01) |
| 3149 | { |
| 3150 | mask = btm_le_state_combo_tbl[request_state][state_offset][0]; |
| 3151 | offset = btm_le_state_combo_tbl[request_state][state_offset][1]; |
| 3152 | |
| 3153 | if (mask != 0 && offset != 0) |
| 3154 | { |
| 3155 | if (!BTM_LE_STATES_SUPPORTED(btm_cb.devcb.le_supported_states, mask, offset)) |
| 3156 | { |
| 3157 | rt = FALSE; |
| 3158 | break; |
| 3159 | } |
| 3160 | } |
| 3161 | } |
| 3162 | cur_states >>= 1; |
| 3163 | state_offset ++; |
| 3164 | } |
| 3165 | return rt; |
| 3166 | } |
| 3167 | |
| 3168 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3169 | #endif /* BLE_INCLUDED */ |