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
21namespace bluetooth {
22
23// Defined here are various status codes that can be returned from the stack for
24// BLE operations.
25enum 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
34enum 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
58enum Transport { TRANSPORT_AUTO = 0, TRANSPORT_BREDR = 1, TRANSPORT_LE = 2 };
59
60// Android attribute permission values
61const uint16_t kAttributePermissionNone = 0x0;
62const uint16_t kAttributePermissionRead = 0x1;
63const uint16_t kAttributePermissionReadEncrypted = 0x2;
64const uint16_t kAttributePermissionReadEncryptedMITM = 0x4;
65const uint16_t kAttributePermissionWrite = 0x10;
66const uint16_t kAttributePermissionWriteEncrypted = 0x20;
67const uint16_t kAttributePermissionWriteEncryptedMITM = 0x40;
68const uint16_t kAttributePermissionWriteSigned = 0x80;
69const uint16_t kAttributePermissionWriteSignedMITM = 0x100;
70
71// GATT characteristic properties bit-field values (not including the
72// characteristic extended properties).
73const uint8_t kCharacteristicPropertyNone = 0x0;
74const uint8_t kCharacteristicPropertyBroadcast = 0x1;
75const uint8_t kCharacteristicPropertyRead = 0x2;
76const uint8_t kCharacteristicPropertyWriteNoResponse = 0x4;
77const uint8_t kCharacteristicPropertyWrite = 0x8;
78const uint8_t kCharacteristicPropertyNotify = 0x10;
79const uint8_t kCharacteristicPropertyIndicate = 0x20;
80const uint8_t kCharacteristicPropertySignedWrite = 0x40;
81const uint8_t kCharacteristicPropertyExtendedProps = 0x80;
82
83// Advertising interval for different modes.
84const int kAdvertisingIntervalHighMs = 1000;
85const int kAdvertisingIntervalMediumMs = 250;
86const 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).
94const int kAdvertisingIntervalDeltaUnit = 10;
95
96// Legacy Advertising types (ADV_IND, ADV_SCAN_IND, etc.) that are exposed to
97// applications.
98const uint16_t kAdvertisingEventTypeLegacyConnectable = 0x0013;
99const uint16_t kAdvertisingEventTypeLegacyScannable = 0x0012;
100const uint16_t kAdvertisingEventTypeLegacyNonConnectable = 0x0010;
101
102// Advertising channels. These should be kept the same as those defined in the
103// stack.
104const int kAdvertisingChannel37 = (1 << 0);
105const int kAdvertisingChannel38 = (1 << 1);
106const int kAdvertisingChannel39 = (1 << 2);
107const 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.
112const uint8_t kEIRTypeFlags = 0x01;
113const uint8_t kEIRTypeIncomplete16BitUUIDs = 0x02;
114const uint8_t kEIRTypeComplete16BitUUIDs = 0x03;
115const uint8_t kEIRTypeIncomplete32BitUUIDs = 0x04;
116const uint8_t kEIRTypeComplete32BitUUIDs = 0x05;
117const uint8_t kEIRTypeIncomplete128BitUUIDs = 0x06;
118const uint8_t kEIRTypeComplete128BitUUIDs = 0x07;
119const uint8_t kEIRTypeShortenedLocalName = 0x08;
120const uint8_t kEIRTypeCompleteLocalName = 0x09;
121const uint8_t kEIRTypeTxPower = 0x0A;
122const uint8_t kEIRTypeServiceData = 0x16;
123const uint8_t kEIRTypeManufacturerSpecificData = 0xFF;
124
125}  // namespace bluetooth
126