Bluetooth: Fix checking parameters in bt_le_conn_params_valid

Parameters should be checked according to specification. Previous
implementation don't check properly given timeout. Additional check of
lower timeout limit was required.

Change-Id: Id6d302de9c8c9952c0f61107a1ef8d9fa727bffb
Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tieto.com>
This commit is contained in:
Grzegorz Kolodziejczyk 2016-02-02 17:06:12 +01:00 committed by Anas Nashif
commit b3617ba937

View file

@ -161,21 +161,18 @@ static inline bool bt_addr_le_is_identity(const bt_addr_le_t *addr)
static inline bool bt_le_conn_params_valid(uint16_t min, uint16_t max, static inline bool bt_le_conn_params_valid(uint16_t min, uint16_t max,
uint16_t latency, uint16_t timeout) uint16_t latency, uint16_t timeout)
{ {
uint16_t max_latency;
if (min > max || min < 6 || max > 3200) { if (min > max || min < 6 || max > 3200) {
return false; return false;
} }
if (timeout < 10 || timeout > 3200) { /* Limits according to BT Core spec 4.2 [Vol 2, Part E, 7.8.12] */
if (timeout < 10 || timeout > 3200 ||
(2 * timeout) < ((1 + latency) * max * 5)) {
return false; return false;
} }
/* calculation based on BT spec 4.2 [Vol3, PartA, 4.20] /* Limits according to BT Core spec 4.2 [Vol 6, Part B, 4.5.1] */
* max_latency = ((timeout * 10)/(max * 1.25 * 2)) - 1; if (latency > 499 || ((latency + 1) * max) > (timeout * 4)) {
*/
max_latency = (timeout * 4 / max) - 1;
if (latency > 499 || latency > max_latency) {
return false; return false;
} }