PBL mbed final
Fork of nRF51822 by
Revision 528:7144407893f0, committed 2015-12-02
- Comitter:
- rgrover1
- Date:
- Wed Dec 02 13:14:18 2015 +0000
- Parent:
- 527:180b820e70b6
- Child:
- 529:7b8ca6778535
- Commit message:
- Synchronized with git rev 27252473
Author: Marcus Chang
Fixed endianness bug in nRF5xServiceDiscovery::processDiscoverUUIDResponse to be consistent with BLE API.
Changed in this revision
--- a/module.json Wed Dec 02 13:14:17 2015 +0000 +++ b/module.json Wed Dec 02 13:14:18 2015 +0000 @@ -1,6 +1,6 @@ { "name": "ble-nrf51822", - "version": "2.1.0", + "version": "2.1.1", "description": "Nordic stack and drivers for the mbed BLE API.", "keywords": [ "Bluetooth",
--- a/source/btle/custom/custom_helper.cpp Wed Dec 02 13:14:17 2015 +0000 +++ b/source/btle/custom/custom_helper.cpp Wed Dec 02 13:14:18 2015 +0000 @@ -202,7 +202,7 @@ uint8_t properties, SecurityManager::SecurityMode_t requiredSecurity, uint8_t *p_data, - uint16_t min_length, + uint16_t length, uint16_t max_length, const uint8_t *userDescriptionDescriptorValuePtr, uint16_t userDescriptionDescriptorValueLen, @@ -242,7 +242,8 @@ attr_md.wr_auth = writeAuthorization; attr_md.vloc = BLE_GATTS_VLOC_STACK; - attr_md.vlen = (min_length == max_length) ? 0 : 1; + /* Always set variable size */ + attr_md.vlen = 1; if (char_props.read || char_props.notify || char_props.indicate) { switch (requiredSecurity) { @@ -292,7 +293,7 @@ attr_char_value.p_uuid = p_uuid; attr_char_value.p_attr_md = &attr_md; - attr_char_value.init_len = min_length; + attr_char_value.init_len = length; attr_char_value.max_len = max_length; attr_char_value.p_value = p_data; @@ -325,7 +326,7 @@ error_t custom_add_in_descriptor(uint16_t char_handle, ble_uuid_t *p_uuid, uint8_t *p_data, - uint16_t min_length, + uint16_t length, uint16_t max_length, uint16_t *p_desc_handle) { @@ -333,7 +334,8 @@ ble_gatts_attr_md_t desc_md = {0}; desc_md.vloc = BLE_GATTS_VLOC_STACK; - desc_md.vlen = (min_length == max_length) ? 0 : 1; + /* Always set variable size */ + desc_md.vlen = 1; /* Make it readable and writable */ BLE_GAP_CONN_SEC_MODE_SET_OPEN(&desc_md.read_perm); @@ -343,7 +345,7 @@ attr_desc.p_uuid = p_uuid; attr_desc.p_attr_md = &desc_md; - attr_desc.init_len = min_length; + attr_desc.init_len = length; attr_desc.max_len = max_length; attr_desc.p_value = p_data;
--- a/source/btle/custom/custom_helper.h Wed Dec 02 13:14:17 2015 +0000 +++ b/source/btle/custom/custom_helper.h Wed Dec 02 13:14:18 2015 +0000 @@ -36,7 +36,7 @@ uint8_t properties, SecurityManager::SecurityMode_t requiredSecurity, uint8_t *p_data, - uint16_t min_length, + uint16_t length, uint16_t max_length, const uint8_t *userDescriptionDescriptorValuePtr, uint16_t userDescriptionDescriptorValueLen, @@ -47,7 +47,7 @@ error_t custom_add_in_descriptor(uint16_t char_handle, ble_uuid_t *p_uuid, uint8_t *p_data, - uint16_t min_length, + uint16_t length, uint16_t max_length, uint16_t *p_desc_handle);
--- a/source/nRF5xGap.cpp Wed Dec 02 13:14:17 2015 +0000 +++ b/source/nRF5xGap.cpp Wed Dec 02 13:14:18 2015 +0000 @@ -374,15 +374,30 @@ /**************************************************************************/ ble_error_t nRF5xGap::setAddress(AddressType_t type, const Address_t address) { - if (type > ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) { + uint8_t cycle_mode; + ble_gap_addr_t dev_addr; + + /* When using Public or Static addresses, the cycle mode must be None. + When using Random Private addresses, the cycle mode must be Auto. + In auto mode, the given address is ignored. + */ + if ((type == ADDR_TYPE_PUBLIC) || (type == ADDR_TYPE_RANDOM_STATIC)) + { + cycle_mode = BLE_GAP_ADDR_CYCLE_MODE_NONE; + memcpy(dev_addr.addr, address, ADDR_LEN); + } + else if ((type == ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE) || (type == ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE)) + { + cycle_mode = BLE_GAP_ADDR_CYCLE_MODE_AUTO; + // address is ignored when in auto mode + } + else + { return BLE_ERROR_PARAM_OUT_OF_RANGE; } - ble_gap_addr_t dev_addr; dev_addr.addr_type = type; - memcpy(dev_addr.addr, address, ADDR_LEN); - - ASSERT_INT(ERROR_NONE, sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &dev_addr), BLE_ERROR_PARAM_OUT_OF_RANGE); + ASSERT_INT(ERROR_NONE, sd_ble_gap_address_set(cycle_mode, &dev_addr), BLE_ERROR_PARAM_OUT_OF_RANGE); return BLE_ERROR_NONE; }
--- a/source/nRF5xGattServer.cpp Wed Dec 02 13:14:17 2015 +0000 +++ b/source/nRF5xGattServer.cpp Wed Dec 02 13:14:18 2015 +0000 @@ -69,7 +69,7 @@ /* Skip any incompletely defined, read-only characteristics. */ if ((p_char->getValueAttribute().getValuePtr() == NULL) && - (p_char->getValueAttribute().getInitialLength() == 0) && + (p_char->getValueAttribute().getLength() == 0) && (p_char->getProperties() == GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)) { continue; } @@ -95,7 +95,7 @@ p_char->getProperties(), p_char->getRequiredSecurity(), p_char->getValueAttribute().getValuePtr(), - p_char->getValueAttribute().getInitialLength(), + p_char->getValueAttribute().getLength(), p_char->getValueAttribute().getMaxLength(), userDescriptionDescriptorValuePtr, userDescriptionDescriptorValueLen, @@ -127,7 +127,7 @@ custom_add_in_descriptor(BLE_GATT_HANDLE_INVALID, &nordicUUID, p_desc->getValuePtr(), - p_desc->getInitialLength(), + p_desc->getLength(), p_desc->getMaxLength(), &nrfDescriptorHandles[descriptorCount]), BLE_ERROR_PARAM_OUT_OF_RANGE);
--- a/source/nRF5xServiceDiscovery.cpp Wed Dec 02 13:14:17 2015 +0000 +++ b/source/nRF5xServiceDiscovery.cpp Wed Dec 02 13:14:18 2015 +0000 @@ -251,9 +251,9 @@ if (state == DISCOVER_SERVICE_UUIDS) { if ((response->count == 1) && (response->value_len == UUID::LENGTH_OF_LONG_UUID)) { UUID::LongUUIDBytes_t uuid; - /* Switch longUUID bytes to MSB */ + for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) { - uuid[i] = response->handle_value[0].p_value[UUID::LENGTH_OF_LONG_UUID - 1 - i]; + uuid[i] = response->handle_value[0].p_value[i]; } unsigned serviceIndex = serviceUUIDDiscoveryQueue.dequeue(); @@ -266,9 +266,9 @@ } else if (state == DISCOVER_CHARACTERISTIC_UUIDS) { if ((response->count == 1) && (response->value_len == UUID::LENGTH_OF_LONG_UUID + 1 /* props */ + 2 /* value handle */)) { UUID::LongUUIDBytes_t uuid; - /* Switch longUUID bytes to MSB */ + for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) { - uuid[i] = response->handle_value[0].p_value[3 + UUID::LENGTH_OF_LONG_UUID - 1 - i]; + uuid[i] = response->handle_value[0].p_value[3 + i]; } unsigned charIndex = charUUIDDiscoveryQueue.dequeue();