Lightly modified version of the BLE stack, that doesn't bring up a DFUService by default... as we have our own.

Fork of BLE_API by Bluetooth Low Energy

Committer:
finneyj
Date:
Thu May 21 09:34:46 2015 +0000
Revision:
403:f24e0ea73138
Parent:
339:1a56af0b1d71
Disabled autogenerated DFU Service

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 302:8f4348c2b6b5 1 /* mbed Microcontroller Library
rgrover1 302:8f4348c2b6b5 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 302:8f4348c2b6b5 3 *
rgrover1 302:8f4348c2b6b5 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 302:8f4348c2b6b5 5 * you may not use this file except in compliance with the License.
rgrover1 302:8f4348c2b6b5 6 * You may obtain a copy of the License at
rgrover1 302:8f4348c2b6b5 7 *
rgrover1 302:8f4348c2b6b5 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 302:8f4348c2b6b5 9 *
rgrover1 302:8f4348c2b6b5 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 302:8f4348c2b6b5 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 302:8f4348c2b6b5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 302:8f4348c2b6b5 13 * See the License for the specific language governing permissions and
rgrover1 302:8f4348c2b6b5 14 * limitations under the License.
rgrover1 302:8f4348c2b6b5 15 */
rgrover1 302:8f4348c2b6b5 16
rgrover1 302:8f4348c2b6b5 17 #ifndef __UUID_H__
rgrover1 302:8f4348c2b6b5 18 #define __UUID_H__
rgrover1 302:8f4348c2b6b5 19
rgrover1 339:1a56af0b1d71 20 #include <string.h>
rgrover1 339:1a56af0b1d71 21
rgrover1 302:8f4348c2b6b5 22 #include "blecommon.h"
rgrover1 302:8f4348c2b6b5 23
rgrover1 302:8f4348c2b6b5 24 const unsigned LENGTH_OF_LONG_UUID = 16;
rgrover1 302:8f4348c2b6b5 25 typedef uint16_t ShortUUIDBytes_t;
rgrover1 302:8f4348c2b6b5 26 typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID];
rgrover1 302:8f4348c2b6b5 27
rgrover1 302:8f4348c2b6b5 28 class UUID {
rgrover1 302:8f4348c2b6b5 29 public:
rgrover1 303:a0d78cb2e9ef 30 enum UUID_Type_t {
rgrover1 302:8f4348c2b6b5 31 UUID_TYPE_SHORT = 0, // Short BLE UUID
rgrover1 302:8f4348c2b6b5 32 UUID_TYPE_LONG = 1 // Full 128-bit UUID
rgrover1 302:8f4348c2b6b5 33 };
rgrover1 302:8f4348c2b6b5 34
rgrover1 302:8f4348c2b6b5 35 public:
rgrover1 332:1dc2f80b4710 36 /**
rgrover1 332:1dc2f80b4710 37 * Creates a new 128-bit UUID
rgrover1 332:1dc2f80b4710 38 *
rgrover1 332:1dc2f80b4710 39 * @note The UUID is a unique 128-bit (16 byte) ID used to identify
rgrover1 332:1dc2f80b4710 40 * different service or characteristics on the BLE device.
rgrover1 332:1dc2f80b4710 41 *
rgrover1 332:1dc2f80b4710 42 * @param longUUID
rgrover1 332:1dc2f80b4710 43 * The 128-bit (16-byte) UUID value.
rgrover1 332:1dc2f80b4710 44 */
rgrover1 332:1dc2f80b4710 45 UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) {
rgrover1 332:1dc2f80b4710 46 memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
rgrover1 332:1dc2f80b4710 47 shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3]));
rgrover1 332:1dc2f80b4710 48 }
rgrover1 332:1dc2f80b4710 49
rgrover1 332:1dc2f80b4710 50 /**
rgrover1 332:1dc2f80b4710 51 * Creates a new 16-bit UUID
rgrover1 332:1dc2f80b4710 52 *
rgrover1 332:1dc2f80b4710 53 * @note The UUID is a unique 16-bit (2 byte) ID used to identify
rgrover1 332:1dc2f80b4710 54 * different service or characteristics on the BLE device.
rgrover1 332:1dc2f80b4710 55 *
rgrover1 332:1dc2f80b4710 56 * For efficiency, and because 16 bytes would take a large chunk of the
rgrover1 332:1dc2f80b4710 57 * 27-byte data payload length of the Link Layer, the BLE specification adds
rgrover1 332:1dc2f80b4710 58 * two additional UUID formats: 16-bit and 32-bit UUIDs. These shortened
rgrover1 332:1dc2f80b4710 59 * formats can be used only with UUIDs that are defined in the Bluetooth
rgrover1 332:1dc2f80b4710 60 * specification (i.e., that are listed by the Bluetooth SIG as standard
rgrover1 332:1dc2f80b4710 61 * Bluetooth UUIDs).
rgrover1 332:1dc2f80b4710 62 *
rgrover1 332:1dc2f80b4710 63 * To reconstruct the full 128-bit UUID from the shortened version, insert
rgrover1 332:1dc2f80b4710 64 * the 16-bit short value (indicated by xxxx, including leading zeros) into
rgrover1 332:1dc2f80b4710 65 * the Bluetooth Base UUID:
rgrover1 332:1dc2f80b4710 66 *
rgrover1 332:1dc2f80b4710 67 * 0000xxxx-0000-1000-8000-00805F9B34FB
rgrover1 332:1dc2f80b4710 68 *
rgrover1 332:1dc2f80b4710 69 * @note Shortening is not available for UUIDs that are not derived from the
rgrover1 332:1dc2f80b4710 70 * Bluetooth Base UUID. Such non-standard UUIDs are commonly called
rgrover1 332:1dc2f80b4710 71 * vendor-specific UUIDs. In these cases, you’ll need to use the full
rgrover1 332:1dc2f80b4710 72 * 128-bit UUID value at all times.
rgrover1 332:1dc2f80b4710 73 *
rgrover1 332:1dc2f80b4710 74 * @note we don't yet support 32-bit shortened UUIDs.
rgrover1 332:1dc2f80b4710 75 */
rgrover1 332:1dc2f80b4710 76 UUID(ShortUUIDBytes_t shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(shortUUID) {
rgrover1 332:1dc2f80b4710 77 /* empty */
rgrover1 332:1dc2f80b4710 78 }
rgrover1 302:8f4348c2b6b5 79
rgrover1 302:8f4348c2b6b5 80 public:
rgrover1 303:a0d78cb2e9ef 81 UUID_Type_t shortOrLong(void) const {return type; }
rgrover1 302:8f4348c2b6b5 82 const uint8_t *getBaseUUID(void) const {
rgrover1 303:a0d78cb2e9ef 83 if (type == UUID_TYPE_SHORT) {
rgrover1 303:a0d78cb2e9ef 84 return (const uint8_t*)&shortUUID;
rgrover1 303:a0d78cb2e9ef 85 } else {
rgrover1 303:a0d78cb2e9ef 86 return baseUUID;
rgrover1 303:a0d78cb2e9ef 87 }
rgrover1 302:8f4348c2b6b5 88 }
rgrover1 332:1dc2f80b4710 89
rgrover1 302:8f4348c2b6b5 90 ShortUUIDBytes_t getShortUUID(void) const {return shortUUID;}
rgrover1 302:8f4348c2b6b5 91 uint8_t getLen(void) const {
rgrover1 302:8f4348c2b6b5 92 return ((type == UUID_TYPE_SHORT) ? sizeof(ShortUUIDBytes_t) : LENGTH_OF_LONG_UUID);
rgrover1 302:8f4348c2b6b5 93 }
rgrover1 302:8f4348c2b6b5 94
rgrover1 332:1dc2f80b4710 95 bool operator== (const UUID &other) const {
rgrover1 332:1dc2f80b4710 96 if ((this->type == UUID_TYPE_SHORT) && (other.type == UUID_TYPE_SHORT) &&
rgrover1 332:1dc2f80b4710 97 (this->shortUUID == other.shortUUID)) {
rgrover1 332:1dc2f80b4710 98 return true;
rgrover1 332:1dc2f80b4710 99 }
rgrover1 332:1dc2f80b4710 100
rgrover1 332:1dc2f80b4710 101 if ((this->type == UUID_TYPE_LONG) && (other.type == UUID_TYPE_LONG) &&
rgrover1 332:1dc2f80b4710 102 (memcmp(this->baseUUID, other.baseUUID, LENGTH_OF_LONG_UUID) == 0)) {
rgrover1 332:1dc2f80b4710 103 return true;
rgrover1 332:1dc2f80b4710 104 }
rgrover1 332:1dc2f80b4710 105
rgrover1 332:1dc2f80b4710 106 return false;
rgrover1 332:1dc2f80b4710 107 }
rgrover1 302:8f4348c2b6b5 108
rgrover1 302:8f4348c2b6b5 109 private:
rgrover1 303:a0d78cb2e9ef 110 UUID_Type_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG
rgrover1 302:8f4348c2b6b5 111 LongUUIDBytes_t baseUUID; /* the base of the long UUID (if
rgrover1 302:8f4348c2b6b5 112 * used). Note: bytes 12 and 13 (counting from LSB)
rgrover1 302:8f4348c2b6b5 113 * are zeroed out to allow comparison with other long
rgrover1 302:8f4348c2b6b5 114 * UUIDs which differ only in the 16-bit relative
rgrover1 302:8f4348c2b6b5 115 * part.*/
rgrover1 302:8f4348c2b6b5 116 ShortUUIDBytes_t shortUUID; // 16 bit uuid (byte 2-3 using with base)
rgrover1 302:8f4348c2b6b5 117 };
rgrover1 302:8f4348c2b6b5 118
rgrover1 302:8f4348c2b6b5 119 #endif // ifndef __UUID_H__