From 2d0b533b5eb0f25b84271e4fefc8fdd46b7b7280 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Thu, 3 Sep 2015 13:25:06 +0100 Subject: [PATCH 1/3] adding LICENSE at the top level --- BSD-3clause-Nordic.txt | 31 +++++++++++++++++++++++++++++++ LICENSE | 6 ++++++ apache-2.0.txt | 13 +++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 BSD-3clause-Nordic.txt create mode 100644 LICENSE create mode 100644 apache-2.0.txt diff --git a/BSD-3clause-Nordic.txt b/BSD-3clause-Nordic.txt new file mode 100644 index 0000000..af65ba8 --- /dev/null +++ b/BSD-3clause-Nordic.txt @@ -0,0 +1,31 @@ +/* + * Copyright (c) Nordic Semiconductor ASA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of other + * contributors to this software may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a4089bc --- /dev/null +++ b/LICENSE @@ -0,0 +1,6 @@ +Many of the files in this module have been inherited from the Nordic SDK for +nRF51822; they come with a BSD-like license offered by Nordic for use in mbed. +Some other files come from the mbed SDK, and are licensed under Apache-2.0. +Unless specifically indicated otherwise in a file, files are licensed +under the Apache 2.0 license, as can be found in: apache-2.0.txt. +The BSD-like Nordic license can be found in BSD-3clause-Nordic.txt diff --git a/apache-2.0.txt b/apache-2.0.txt new file mode 100644 index 0000000..9327527 --- /dev/null +++ b/apache-2.0.txt @@ -0,0 +1,13 @@ +Copyright (c) 2015 ARM Limited + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. From 4af5d03cd596cc0594f9bdaafb6420905f1be287 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 29 Sep 2015 15:04:59 +0100 Subject: [PATCH 2/3] Error check number of characteristics Currently it just blindly writes beyond the end of the array, leading to impossible-to-find bugs. It doesn't help that the limit on the number of characteristics doesn't seem to be documented anywhere. --- source/nRF5xGattServer.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/nRF5xGattServer.cpp b/source/nRF5xGattServer.cpp index 8e4f7fa..3280639 100644 --- a/source/nRF5xGattServer.cpp +++ b/source/nRF5xGattServer.cpp @@ -45,7 +45,6 @@ nRF5xGattServer &nRF5xGattServer::getInstance(void) { /**************************************************************************/ ble_error_t nRF5xGattServer::addService(GattService &service) { - /* ToDo: Make sure we don't overflow the array, etc. */ /* ToDo: Make sure this service UUID doesn't already exist (?) */ /* ToDo: Basic validation */ @@ -63,7 +62,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service) /* Add characteristics to the service */ for (uint8_t i = 0; i < service.getCharacteristicCount(); i++) { - GattCharacteristic *p_char = service.getCharacteristic(i); + if (characteristicCount >= BLE_TOTAL_CHARACTERISTICS) { + return BLE_ERROR_NO_MEM; + } + GattCharacteristic *p_char = service.getCharacteristic(i); /* Skip any incompletely defined, read-only characteristics. */ if ((p_char->getValueAttribute().getValuePtr() == NULL) && @@ -108,9 +110,12 @@ ble_error_t nRF5xGattServer::addService(GattService &service) characteristicCount++; /* Add optional descriptors if any */ - /* ToDo: Make sure we don't overflow the array */ for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) { - GattAttribute *p_desc = p_char->getDescriptor(j); + if (descriptorCount >= BLE_TOTAL_DESCRIPTORS) { + return BLE_ERROR_NO_MEM; + } + + GattAttribute *p_desc = p_char->getDescriptor(j); /* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */ if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) { continue; From 816f4559f1ecddfd07cf928c65b2ee04edb05fc5 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Tue, 13 Oct 2015 12:54:46 +0100 Subject: [PATCH 3/3] white space diffs; convert tabs to spaces --- source/nRF5xGattServer.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/nRF5xGattServer.cpp b/source/nRF5xGattServer.cpp index 3280639..03eddf4 100644 --- a/source/nRF5xGattServer.cpp +++ b/source/nRF5xGattServer.cpp @@ -62,10 +62,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service) /* Add characteristics to the service */ for (uint8_t i = 0; i < service.getCharacteristicCount(); i++) { - if (characteristicCount >= BLE_TOTAL_CHARACTERISTICS) { - return BLE_ERROR_NO_MEM; - } - GattCharacteristic *p_char = service.getCharacteristic(i); + if (characteristicCount >= BLE_TOTAL_CHARACTERISTICS) { + return BLE_ERROR_NO_MEM; + } + GattCharacteristic *p_char = service.getCharacteristic(i); /* Skip any incompletely defined, read-only characteristics. */ if ((p_char->getValueAttribute().getValuePtr() == NULL) && @@ -111,11 +111,11 @@ ble_error_t nRF5xGattServer::addService(GattService &service) /* Add optional descriptors if any */ for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) { - if (descriptorCount >= BLE_TOTAL_DESCRIPTORS) { - return BLE_ERROR_NO_MEM; - } + if (descriptorCount >= BLE_TOTAL_DESCRIPTORS) { + return BLE_ERROR_NO_MEM; + } - GattAttribute *p_desc = p_char->getDescriptor(j); + GattAttribute *p_desc = p_char->getDescriptor(j); /* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */ if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) { continue;