1 // 2 // Copyright 2015 Google, Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at: 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #pragma once 18 19 #include <stdint.h> 20 21 namespace bluetooth { 22 23 // Defined here are various status codes that can be returned from the stack for 24 // BLE operations. 25 enum BLEStatus { 26 BLE_STATUS_SUCCESS = 0, 27 BLE_STATUS_ADV_ERROR_DATA_TOO_LARGE = 1, 28 BLE_STATUS_ADV_ERROR_TOO_MANY_ADVERTISERS = 2, 29 BLE_STATUS_ADV_ERROR_ALREADY_STARTED = 3, 30 BLE_STATUS_ADV_ERROR_FEATURE_UNSUPPORTED = 5, 31 BLE_STATUS_FAILURE = 0x101, 32 }; 33 34 enum GATTError { 35 GATT_ERROR_NONE = 0, 36 GATT_ERROR_INVALID_HANDLE = 0x01, 37 GATT_ERROR_READ_NOT_PERMITTED = 0x02, 38 GATT_ERROR_WRITE_NOT_PERMITTED = 0x03, 39 GATT_ERROR_INVALID_PDU = 0x04, 40 GATT_ERROR_INSUFFICIENT_AUTHEN = 0x05, 41 GATT_ERROR_REQUEST_NOT_SUPPORTED = 0x06, 42 GATT_ERROR_INVALID_OFFSET = 0x07, 43 GATT_ERROR_INSUFFICIENT_AUTHOR = 0x08, 44 GATT_ERROR_PREP_QUEUE_FULL = 0x09, 45 GATT_ERROR_ATTRIBUTE_NOT_FOUND = 0x0a, 46 GATT_ERROR_ATTRIBUTE_NOT_LONG = 0x0b, 47 GATT_ERROR_INSUFFICIENT_KEY_SIZE = 0x0c, 48 GATT_ERROR_INVALID_ATTRIBUTE_LENGTH = 0x0d, 49 GATT_ERROR_UNLIKELY = 0x0e, 50 GATT_ERROR_INSUFFICIENT_ENCR = 0x0f, 51 GATT_ERROR_UNSUPPORTED_GRP_TYPE = 0x10, 52 GATT_ERROR_INSUFFICIENT_RESOURCES = 0x11, 53 GATT_ERROR_CCCD_IMPROPERLY_CONFIGURED = 0xFD, 54 GATT_ERROR_PROCEDURE_IN_PROGRESS = 0xFE, 55 GATT_ERROR_OUT_OF_RANGE = 0xFF 56 }; 57 58 enum Transport { TRANSPORT_AUTO = 0, TRANSPORT_BREDR = 1, TRANSPORT_LE = 2 }; 59 60 // Android attribute permission values 61 const uint16_t kAttributePermissionNone = 0x0; 62 const uint16_t kAttributePermissionRead = 0x1; 63 const uint16_t kAttributePermissionReadEncrypted = 0x2; 64 const uint16_t kAttributePermissionReadEncryptedMITM = 0x4; 65 const uint16_t kAttributePermissionWrite = 0x10; 66 const uint16_t kAttributePermissionWriteEncrypted = 0x20; 67 const uint16_t kAttributePermissionWriteEncryptedMITM = 0x40; 68 const uint16_t kAttributePermissionWriteSigned = 0x80; 69 const uint16_t kAttributePermissionWriteSignedMITM = 0x100; 70 71 // GATT characteristic properties bit-field values (not including the 72 // characteristic extended properties). 73 const uint8_t kCharacteristicPropertyNone = 0x0; 74 const uint8_t kCharacteristicPropertyBroadcast = 0x1; 75 const uint8_t kCharacteristicPropertyRead = 0x2; 76 const uint8_t kCharacteristicPropertyWriteNoResponse = 0x4; 77 const uint8_t kCharacteristicPropertyWrite = 0x8; 78 const uint8_t kCharacteristicPropertyNotify = 0x10; 79 const uint8_t kCharacteristicPropertyIndicate = 0x20; 80 const uint8_t kCharacteristicPropertySignedWrite = 0x40; 81 const uint8_t kCharacteristicPropertyExtendedProps = 0x80; 82 83 // Advertising interval for different modes. 84 const int kAdvertisingIntervalHighMs = 1000; 85 const int kAdvertisingIntervalMediumMs = 250; 86 const int kAdvertisingIntervalLowMs = 100; 87 88 // Add some randomness to the advertising min/max interval so the controller can 89 // do some optimization. 90 // TODO(armansito): I took this directly from packages/apps/Bluetooth but based 91 // on code review comments this constant and the accompanying logic doesn't make 92 // sense. Let's remove this constant and figure out how to properly calculate 93 // the Max. Adv. Interval. (See http://b/24344075). 94 const int kAdvertisingIntervalDeltaUnit = 10; 95 96 // Legacy Advertising types (ADV_IND, ADV_SCAN_IND, etc.) that are exposed to 97 // applications. 98 const uint16_t kAdvertisingEventTypeLegacyConnectable = 0x0013; 99 const uint16_t kAdvertisingEventTypeLegacyScannable = 0x0012; 100 const uint16_t kAdvertisingEventTypeLegacyNonConnectable = 0x0010; 101 102 // Advertising channels. These should be kept the same as those defined in the 103 // stack. 104 const int kAdvertisingChannel37 = (1 << 0); 105 const int kAdvertisingChannel38 = (1 << 1); 106 const int kAdvertisingChannel39 = (1 << 2); 107 const int kAdvertisingChannelAll = 108 (kAdvertisingChannel37 | kAdvertisingChannel38 | kAdvertisingChannel39); 109 110 // Various Extended Inquiry Response fields types that are used for advertising 111 // data fields as defined in the Core Specification Supplement. 112 const uint8_t kEIRTypeFlags = 0x01; 113 const uint8_t kEIRTypeIncomplete16BitUuids = 0x02; 114 const uint8_t kEIRTypeComplete16BitUuids = 0x03; 115 const uint8_t kEIRTypeIncomplete32BitUuids = 0x04; 116 const uint8_t kEIRTypeComplete32BitUuids = 0x05; 117 const uint8_t kEIRTypeIncomplete128BitUuids = 0x06; 118 const uint8_t kEIRTypeComplete128BitUuids = 0x07; 119 const uint8_t kEIRTypeShortenedLocalName = 0x08; 120 const uint8_t kEIRTypeCompleteLocalName = 0x09; 121 const uint8_t kEIRTypeTxPower = 0x0A; 122 const uint8_t kEIRTypeServiceData = 0x16; 123 const uint8_t kEIRTypeManufacturerSpecificData = 0xFF; 124 125 } // namespace bluetooth 126