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