High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
Revision 60:de30b62ab8c1, committed 2014-05-30
- Comitter:
- Rohit Grover
- Date:
- Fri May 30 09:58:35 2014 +0100
- Parent:
- 59:2c30cb482915
- Child:
- 61:119faa0dfeee
- Commit message:
- UUID constructors should zero out relative part of baseUUID
Changed in this revision
UUID.cpp | Show annotated file Show diff for this revision Revisions of this file |
UUID.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/UUID.cpp Thu May 29 16:21:46 2014 +0100 +++ b/UUID.cpp Fri May 30 09:58:35 2014 +0100 @@ -22,21 +22,6 @@ /**************************************************************************/ /*! - @brief Creates an empty 128-bit UUID - - @note This UUID must be assigned a valid value via the 'update' - function before it can be safely used! -*/ -/**************************************************************************/ -UUID::UUID(void) : type(UUID_TYPE_SHORT), - base(), - value(0) -{ - /* empty */ -} - -/**************************************************************************/ -/*! @brief Creates a new 128-bit UUID @note The UUID is a unique 128-bit (16 byte) ID used to identify @@ -79,22 +64,33 @@ @endcode */ /**************************************************************************/ -UUID::UUID(const uint8_t uuid_base[LENGTH_OF_LONG_UUID]) : +UUID::UUID(const uint8_t longUUID[LENGTH_OF_LONG_UUID]) : type(UUID_TYPE_SHORT), - base(), + baseUUID(), value(0) { - memcpy(base, uuid_base, LENGTH_OF_LONG_UUID); - value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2])); + memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID); + value = (uint16_t)((longUUID[3] << 8) | (longUUID[2]));/* NEEDS REVIEW */ /* Check if this is a short of a long UUID */ - if (uuid_base[0] + uuid_base[1] + - uuid_base[4] + uuid_base[5] + uuid_base[6] + uuid_base[7] + - uuid_base[8] + uuid_base[9] + uuid_base[10] + uuid_base[11] + - uuid_base[12] + uuid_base[13] + uuid_base[14] + uuid_base[15] == 0) { - type = UUID_TYPE_SHORT; - } else { - type = UUID_TYPE_LONG; + unsigned index; + for (index = 0; index < LENGTH_OF_LONG_UUID; index++) { + if ((index == 2) || (index == 3)) { + continue; /* we should not consider bytes 2 and 3 because that's + * where the 16-bit relative UUID is placed. */ + } + + if (baseUUID[index] != 0) { + type = UUID_TYPE_LONG; + + /* NEEDS REVIEW */ + /* zero out the 16-bit part in the base; this will help equate long + * UUIDs when they differ only in this 16-bit relative part.*/ + baseUUID[2] = 0; + baseUUID[3] = 0; + + return; + } } } @@ -106,11 +102,13 @@ The 16-bit BLE UUID value. */ /**************************************************************************/ -UUID::UUID(const uint16_t ble_uuid) : type(UUID_TYPE_SHORT), - base(), - value(ble_uuid) +UUID::UUID(const uint16_t shortUUID) : type(UUID_TYPE_SHORT), + baseUUID(), + value(shortUUID) { - memcpy(base + 2, (uint8_t *)&ble_uuid, 2); + /* NEEDS REVIEW */ + baseUUID[2] = (shortUUID >> 8); + baseUUID[3] = (shortUUID & 0xff); } /**************************************************************************/
--- a/UUID.h Thu May 29 16:21:46 2014 +0100 +++ b/UUID.h Fri May 30 09:58:35 2014 +0100 @@ -31,9 +31,8 @@ static const unsigned LENGTH_OF_LONG_UUID = 16; public: - UUID(void); - UUID(uint8_t const[LENGTH_OF_LONG_UUID]); - UUID(uint16_t const); + UUID(const uint8_t longUUID[LENGTH_OF_LONG_UUID]); + UUID(uint16_t shortUUID); virtual ~UUID(void); public: @@ -41,7 +40,7 @@ return type; } const uint8_t* getBaseUUID(void) const { - return base; + return baseUUID; } uint16_t get16BitUUID(void) const { return value; @@ -49,7 +48,11 @@ private: uint8_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG - uint8_t base[LENGTH_OF_LONG_UUID]; // in case of custom + uint8_t baseUUID[LENGTH_OF_LONG_UUID]; /* the base of the long UUID (if + * used). Note: bytes 12 and 13 (counting from LSB) + * are zeroed out to allow comparison with other long + * UUIDs which differ only in the 16-bit relative + * part.*/ uint16_t value; // 16 bit uuid (byte 2-3 using with base) };