You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/11/30 20:07:06 UTC
[5/8] incubator-mynewt-core git commit: nimble/gap: Add check for
connection parameters
nimble/gap: Add check for connection parameters
With this patch GAP will make sure that requested connection parameters
are valid. If not BLE_HS_EINVAL will be returned
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3e8cbec3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3e8cbec3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3e8cbec3
Branch: refs/heads/develop
Commit: 3e8cbec34ba02cfcce901a84069bcdf2d1fb2f12
Parents: 9cacc49
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Mon Nov 28 23:41:40 2016 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Tue Nov 29 23:03:49 2016 +0100
----------------------------------------------------------------------
net/nimble/host/src/ble_gap.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3e8cbec3/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 6d83a9b..863fc5d 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2857,6 +2857,31 @@ ble_gap_update_tx(uint16_t conn_handle,
return 0;
}
+static bool
+ble_gap_validate_conn_params(const struct ble_gap_upd_params *params)
+{
+
+ /* Requirements from Bluetooth spec. v4.2 [Vol 2, Part E], 7.8.18 */
+ if (params->itvl_min > params->itvl_max) {
+ return false;
+ }
+
+ if (params->itvl_min < 0x0006 || params->itvl_max > 0x0C80) {
+ return false;
+ }
+
+ if (params->latency > 0x01F3) {
+ return false;
+ }
+
+ if (params->supervision_timeout <=
+ (((1 + params->latency) * params->itvl_max) * 6 / 4)) {
+ return false;
+ }
+
+ return true;
+}
+
/**
* Initiates a connection parameter update procedure.
*
@@ -2871,6 +2896,7 @@ ble_gap_update_tx(uint16_t conn_handle,
* BLE_HS_EALREADY if a connection update
* procedure for this connection is already in
* progress;
+ * BLE_HS_EINVAL if requested parameters are invalid;
* Other nonzero on error.
*/
int
@@ -2886,6 +2912,11 @@ ble_gap_update_params(uint16_t conn_handle,
struct ble_hs_conn *conn;
int rc;
+ /* Validate parameters with a spec */
+ if (ble_gap_validate_conn_params(params)) {
+ return BLE_HS_EINVAL;
+ }
+
STATS_INC(ble_gap_stats, update);
memset(&l2cap_params, 0, sizeof l2cap_params);
entry = NULL;