external/bluetooth/bluedroid
Révision | 69218b169bd0ff9fdf1c5de148b3807e70de85de (tree) |
---|---|
l'heure | 2014-03-10 10:08:14 |
Auteur | Zhihai Xu <zhihaixu@goog...> |
Commiter | Android (Google) Code Review |
Merge changes I6673d478,I953b9ca6 into klp-dev
* changes:
@@ -2266,7 +2266,16 @@ static void btu_ble_ll_conn_complete_evt ( UINT8 *p, UINT16 evt_len) | ||
2266 | 2266 | |
2267 | 2267 | static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len) |
2268 | 2268 | { |
2269 | -/* This is empty until an upper layer cares about returning event */ | |
2269 | + /* LE connection update has completed successfully as a master. */ | |
2270 | + /* We can enable the update request if the result is a success. */ | |
2271 | + /* extract the HCI handle first */ | |
2272 | + UINT8 status; | |
2273 | + UINT16 handle; | |
2274 | + BT_TRACE_0(TRACE_LAYER_HCI, TRACE_TYPE_EVENT, "btu_ble_ll_conn_param_upd_evt"); | |
2275 | + | |
2276 | + STREAM_TO_UINT8 (status, p); | |
2277 | + STREAM_TO_UINT16 (handle, p); | |
2278 | + L2CA_HandleConnUpdateEvent(handle, status); | |
2270 | 2279 | } |
2271 | 2280 | |
2272 | 2281 | static void btu_ble_read_remote_feat_evt (UINT8 *p, UINT16 evt_len) |
@@ -1146,6 +1146,18 @@ L2C_API extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN | ||
1146 | 1146 | |
1147 | 1147 | /******************************************************************************* |
1148 | 1148 | ** |
1149 | +** Function L2CA_HandleConnUpdateEvent | |
1150 | +** | |
1151 | +** Description This function enables the connection update request from remote | |
1152 | +** after a successful connection update response is received. | |
1153 | +** | |
1154 | +** Returns void | |
1155 | +** | |
1156 | +*******************************************************************************/ | |
1157 | +L2C_API void L2CA_HandleConnUpdateEvent (UINT16 handle, UINT8 status); | |
1158 | + | |
1159 | +/******************************************************************************* | |
1160 | +** | |
1149 | 1161 | ** Function L2CA_GetBleConnRole |
1150 | 1162 | ** |
1151 | 1163 | ** Description This function returns the connection role. |
@@ -81,6 +81,56 @@ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda) | ||
81 | 81 | return(FALSE); |
82 | 82 | } |
83 | 83 | |
84 | +/******************************************************************************* | |
85 | +** | |
86 | +** Function L2CA_InternalBleConnUpdate | |
87 | +** | |
88 | +** Description update BLE connection based on status | |
89 | +** | |
90 | +** Parameters: lcb | |
91 | +** | |
92 | +** Return value: none | |
93 | +** | |
94 | +*******************************************************************************/ | |
95 | +static void L2CA_InternalBleConnUpdate (tL2C_LCB *p_lcb) | |
96 | +{ | |
97 | + if (p_lcb->upd_status & L2C_BLE_UPDATE_PENDING) return; | |
98 | + | |
99 | + if (p_lcb->upd_status & L2C_BLE_CONN_UPDATE_DISABLE) | |
100 | + { | |
101 | + /* application requests to disable parameters update. | |
102 | + If parameters are already updated, lets set them | |
103 | + up to what has been requested during connection establishement */ | |
104 | + if (p_lcb->upd_status & L2C_BLE_NOT_DEFAULT_PARAM) | |
105 | + { | |
106 | + tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev(p_lcb->remote_bd_addr); | |
107 | + | |
108 | + btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, | |
109 | + (UINT16)((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? | |
110 | + p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), | |
111 | + (UINT16)((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? | |
112 | + p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), | |
113 | + (UINT16)((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? | |
114 | + p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), | |
115 | + (UINT16)((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? | |
116 | + p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), | |
117 | + 0, 0); | |
118 | + p_lcb->upd_status &= ~L2C_BLE_NOT_DEFAULT_PARAM; | |
119 | + p_lcb->upd_status |= (L2C_BLE_UPDATE_PENDING | L2C_BLE_NEW_CONN_PARAM); | |
120 | + } | |
121 | + } | |
122 | + else | |
123 | + { | |
124 | + /* application allows to do update, if we were delaying one do it now */ | |
125 | + if (p_lcb->upd_status & L2C_BLE_NEW_CONN_PARAM) | |
126 | + { | |
127 | + btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, p_lcb->min_interval, | |
128 | + p_lcb->max_interval, p_lcb->latency, p_lcb->timeout, 0, 0); | |
129 | + p_lcb->upd_status &= ~L2C_BLE_NEW_CONN_PARAM; | |
130 | + p_lcb->upd_status |= (L2C_BLE_UPDATE_PENDING | L2C_BLE_NOT_DEFAULT_PARAM); | |
131 | + } | |
132 | + } | |
133 | +} | |
84 | 134 | |
85 | 135 | /******************************************************************************* |
86 | 136 | ** |
@@ -116,7 +166,14 @@ BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_in | ||
116 | 166 | } |
117 | 167 | |
118 | 168 | if (p_lcb->link_role == HCI_ROLE_MASTER) |
119 | - btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, min_int, max_int, latency, timeout, 0, 0); | |
169 | + { | |
170 | + p_lcb->min_interval = min_int; | |
171 | + p_lcb->max_interval = max_int; | |
172 | + p_lcb->latency = latency; | |
173 | + p_lcb->timeout = timeout; | |
174 | + p_lcb->upd_status |= L2C_BLE_NEW_CONN_PARAM; | |
175 | + L2CA_InternalBleConnUpdate(p_lcb); | |
176 | + } | |
120 | 177 | else |
121 | 178 | l2cu_send_peer_ble_par_req (p_lcb, min_int, max_int, latency, timeout); |
122 | 179 |
@@ -150,8 +207,9 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable) | ||
150 | 207 | return (FALSE); |
151 | 208 | } |
152 | 209 | |
153 | - L2CAP_TRACE_API4 ("L2CA_EnableUpdateBleConnParams - BD_ADDR %08x%04x enable %d current upd state %d", | |
154 | - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5], enable, p_lcb->upd_disabled); | |
210 | + L2CAP_TRACE_API4 ("L2CA_EnableUpdateBleConnParams - BD_ADDR %08x%04x enable %d upd state %d", | |
211 | + (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5], | |
212 | + enable, p_lcb->upd_status); | |
155 | 213 | |
156 | 214 | if (!p_lcb->is_ble_link || (p_lcb->link_role != HCI_ROLE_MASTER)) |
157 | 215 | { |
@@ -162,42 +220,56 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable) | ||
162 | 220 | |
163 | 221 | if (enable) |
164 | 222 | { |
165 | - /* application allows to do update, if we were delaying one do it now, otherwise | |
166 | - just mark lcb that updates are enabled */ | |
167 | - if (p_lcb->upd_disabled == UPD_PENDING) | |
168 | - { | |
169 | - btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, p_lcb->min_interval, p_lcb->max_interval, | |
170 | - p_lcb->latency, p_lcb->timeout, 0, 0); | |
171 | - p_lcb->upd_disabled = UPD_UPDATED; | |
172 | - } | |
173 | - else | |
174 | - { | |
175 | - p_lcb->upd_disabled = UPD_ENABLED; | |
176 | - } | |
223 | + p_lcb->upd_status &= ~L2C_BLE_CONN_UPDATE_DISABLE; | |
177 | 224 | } |
178 | 225 | else |
179 | 226 | { |
180 | - /* application requests to disable parameters update. If parameters are already updated, lets set them | |
181 | - up to what has been requested during connection establishement */ | |
182 | - if (p_lcb->upd_disabled == UPD_UPDATED) | |
183 | - { | |
184 | - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (rem_bda); | |
185 | - | |
186 | - btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, | |
187 | - (UINT16)((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), | |
188 | - (UINT16)((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), | |
189 | - (UINT16)((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), | |
190 | - (UINT16) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), | |
191 | - 0, 0); | |
192 | - } | |
193 | - p_lcb->upd_disabled = UPD_DISABLED; | |
227 | + p_lcb->upd_status |= L2C_BLE_CONN_UPDATE_DISABLE; | |
194 | 228 | } |
195 | 229 | |
230 | + L2CA_InternalBleConnUpdate(p_lcb); | |
231 | + | |
196 | 232 | return (TRUE); |
197 | 233 | } |
198 | 234 | |
199 | 235 | /******************************************************************************* |
200 | 236 | ** |
237 | +** Function L2CA_HandleConnUpdateEvent | |
238 | +** | |
239 | +** Description This function enables the connection update request from remote | |
240 | +** after a successful connection update response is received. | |
241 | +** | |
242 | +** Returns void | |
243 | +** | |
244 | +*******************************************************************************/ | |
245 | +void L2CA_HandleConnUpdateEvent (UINT16 handle, UINT8 status) | |
246 | +{ | |
247 | + tL2C_LCB *p_lcb; | |
248 | + | |
249 | + L2CAP_TRACE_DEBUG0("L2CA_HandleConnUpdateEvent"); | |
250 | + | |
251 | + /* See if we have a link control block for the remote device */ | |
252 | + p_lcb = l2cu_find_lcb_by_handle(handle); | |
253 | + if (!p_lcb) | |
254 | + { | |
255 | + L2CAP_TRACE_WARNING1("L2CA_EnableUpdateBleConnParams: Invalid handle: %d", handle); | |
256 | + return; | |
257 | + } | |
258 | + | |
259 | + p_lcb->upd_status &= ~L2C_BLE_UPDATE_PENDING; | |
260 | + | |
261 | + if (status != HCI_SUCCESS) | |
262 | + { | |
263 | + L2CAP_TRACE_WARNING1("L2CA_EnableUpdateBleConnParams: Error status: %d", status); | |
264 | + } | |
265 | + | |
266 | + L2CA_InternalBleConnUpdate(p_lcb); | |
267 | + | |
268 | + L2CAP_TRACE_DEBUG1("L2CA_HandleConnUpdateEvent: upd_status=%d", p_lcb->upd_status); | |
269 | +} | |
270 | + | |
271 | +/******************************************************************************* | |
272 | +** | |
201 | 273 | ** Function L2CA_GetBleConnRole |
202 | 274 | ** |
203 | 275 | ** Description This function returns the connection role. |
@@ -321,6 +393,7 @@ void l2cble_scanner_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type, | ||
321 | 393 | p_dev_rec->conn_params.slave_latency, |
322 | 394 | p_dev_rec->conn_params.supervision_tout, |
323 | 395 | 0, 0); |
396 | + p_lcb->upd_status |= L2C_BLE_UPDATE_PENDING; | |
324 | 397 | } |
325 | 398 | |
326 | 399 | /* Tell BTM Acl management about the link */ |
@@ -487,18 +560,8 @@ void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len) | ||
487 | 560 | p_lcb->max_interval = max_interval; |
488 | 561 | p_lcb->latency = latency; |
489 | 562 | p_lcb->timeout = timeout; |
490 | - | |
491 | - if (p_lcb->upd_disabled == UPD_ENABLED) | |
492 | - { | |
493 | - btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, min_interval, max_interval, | |
494 | - latency, timeout, 0, 0); | |
495 | - p_lcb->upd_disabled = UPD_UPDATED; | |
496 | - } | |
497 | - else | |
498 | - { | |
499 | - L2CAP_TRACE_EVENT0 ("L2CAP - LE - update currently disabled"); | |
500 | - p_lcb->upd_disabled = UPD_PENDING; | |
501 | - } | |
563 | + p_lcb->upd_status |= L2C_BLE_NEW_CONN_PARAM; | |
564 | + L2CA_InternalBleConnUpdate(p_lcb); | |
502 | 565 | } |
503 | 566 | } |
504 | 567 | else |
@@ -435,11 +435,11 @@ typedef struct t_l2c_linkcb | ||
435 | 435 | BOOLEAN is_ble_link; |
436 | 436 | tBLE_ADDR_TYPE ble_addr_type; |
437 | 437 | |
438 | -#define UPD_ENABLED 0 /* If peer requests update, we will change params */ | |
439 | -#define UPD_DISABLED 1 /* application requested not to update */ | |
440 | -#define UPD_PENDING 2 /* while updates are disabled, peer requested new parameters */ | |
441 | -#define UPD_UPDATED 3 /* peer updated connection parameters */ | |
442 | - UINT8 upd_disabled; | |
438 | +#define L2C_BLE_CONN_UPDATE_DISABLE 0x1 /* disable update connection parameters */ | |
439 | +#define L2C_BLE_NEW_CONN_PARAM 0x2 /* new connection parameter to be set */ | |
440 | +#define L2C_BLE_UPDATE_PENDING 0x4 /* waiting for connection update finished */ | |
441 | +#define L2C_BLE_NOT_DEFAULT_PARAM 0x8 /* not using default connection parameters */ | |
442 | + UINT8 upd_status; | |
443 | 443 | |
444 | 444 | UINT16 min_interval; /* parameters as requested by peripheral */ |
445 | 445 | UINT16 max_interval; |