1 //
2 //  Copyright (C) 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 {
59   TRANSPORT_AUTO = 0,
60   TRANSPORT_BREDR = 1,
61   TRANSPORT_LE = 2
62 };
63 
64 // Android attribute permission values
65 const uint16_t kAttributePermissionNone = 0x0;
66 const uint16_t kAttributePermissionRead = 0x1;
67 const uint16_t kAttributePermissionReadEncrypted = 0x2;
68 const uint16_t kAttributePermissionReadEncryptedMITM = 0x4;
69 const uint16_t kAttributePermissionWrite = 0x10;
70 const uint16_t kAttributePermissionWriteEncrypted = 0x20;
71 const uint16_t kAttributePermissionWriteEncryptedMITM = 0x40;
72 const uint16_t kAttributePermissionWriteSigned = 0x80;
73 const uint16_t kAttributePermissionWriteSignedMITM = 0x100;
74 
75 // GATT characteristic properties bit-field values (not including the
76 // characteristic extended properties).
77 const uint8_t kCharacteristicPropertyNone = 0x0;
78 const uint8_t kCharacteristicPropertyBroadcast = 0x1;
79 const uint8_t kCharacteristicPropertyRead = 0x2;
80 const uint8_t kCharacteristicPropertyWriteNoResponse = 0x4;
81 const uint8_t kCharacteristicPropertyWrite = 0x8;
82 const uint8_t kCharacteristicPropertyNotify = 0x10;
83 const uint8_t kCharacteristicPropertyIndicate = 0x20;
84 const uint8_t kCharacteristicPropertySignedWrite = 0x40;
85 const uint8_t kCharacteristicPropertyExtendedProps = 0x80;
86 
87 // Advertising interval for different modes.
88 const int kAdvertisingIntervalHighMs = 1000;
89 const int kAdvertisingIntervalMediumMs = 250;
90 const int kAdvertisingIntervalLowMs = 100;
91 
92 // Add some randomness to the advertising min/max interval so the controller can
93 // do some optimization.
94 // TODO(armansito): I took this directly from packages/apps/Bluetooth but based
95 // on code review comments this constant and the accompanying logic doesn't make
96 // sense. Let's remove this constant and figure out how to properly calculate
97 // the Max. Adv. Interval. (See http://b/24344075).
98 const int kAdvertisingIntervalDeltaUnit = 10;
99 
100 // Advertising types (ADV_IND, ADV_SCAN_IND, etc.) that are exposed to
101 // applications.
102 const int kAdvertisingEventTypeConnectable = 0;
103 const int kAdvertisingEventTypeScannable = 2;
104 const int kAdvertisingEventTypeNonConnectable = 3;
105 
106 // Advertising channels. These should be kept the same as those defined in the
107 // stack.
108 const int kAdvertisingChannel37 = (1 << 0);
109 const int kAdvertisingChannel38 = (1 << 1);
110 const int kAdvertisingChannel39 = (1 << 2);
111 const int kAdvertisingChannelAll =
112     (kAdvertisingChannel37 | kAdvertisingChannel38 | kAdvertisingChannel39);
113 
114 // Various Extended Inquiry Response fields types that are used for advertising
115 // data fields as defined in the Core Specification Supplement.
116 const uint8_t kEIRTypeFlags = 0x01;
117 const uint8_t kEIRTypeIncomplete16BitUUIDs = 0x02;
118 const uint8_t kEIRTypeComplete16BitUUIDs = 0x03;
119 const uint8_t kEIRTypeIncomplete32BitUUIDs = 0x04;
120 const uint8_t kEIRTypeComplete32BitUUIDs = 0x05;
121 const uint8_t kEIRTypeIncomplete128BitUUIDs = 0x06;
122 const uint8_t kEIRTypeComplete128BitUUIDs = 0x07;
123 const uint8_t kEIRTypeManufacturerSpecificData = 0xFF;
124 
125 }  // namespace bluetooth
126