1c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//
25b790feeeb211c42bf78ca3ae9c26aa30e516765Jakub Pawlowski//  Copyright 2015 Google, Inc.
3c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//
4c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//  Licensed under the Apache License, Version 2.0 (the "License");
5c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//  you may not use this file except in compliance with the License.
6c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//  You may obtain a copy of the License at:
7c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//
8c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//  http://www.apache.org/licenses/LICENSE-2.0
9c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//
10c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//  Unless required by applicable law or agreed to in writing, software
11c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//  distributed under the License is distributed on an "AS IS" BASIS,
12c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//  See the License for the specific language governing permissions and
14c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//  limitations under the License.
15c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray//
16c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray
17c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray#pragma once
18c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray
1991613743c9db02dbe05d93d2afa163b78068d054Arman Uguray#include <stdint.h>
2091613743c9db02dbe05d93d2afa163b78068d054Arman Uguray
21c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguraynamespace bluetooth {
22c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray
23c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray// Defined here are various status codes that can be returned from the stack for
24c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray// BLE operations.
25c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Ugurayenum BLEStatus {
26c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray  BLE_STATUS_SUCCESS = 0,
27909b7e6681101eb5e2d56209993134932284b50eArman Uguray  BLE_STATUS_ADV_ERROR_DATA_TOO_LARGE = 1,
28909b7e6681101eb5e2d56209993134932284b50eArman Uguray  BLE_STATUS_ADV_ERROR_TOO_MANY_ADVERTISERS = 2,
29909b7e6681101eb5e2d56209993134932284b50eArman Uguray  BLE_STATUS_ADV_ERROR_ALREADY_STARTED = 3,
30909b7e6681101eb5e2d56209993134932284b50eArman Uguray  BLE_STATUS_ADV_ERROR_FEATURE_UNSUPPORTED = 5,
31c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray  BLE_STATUS_FAILURE = 0x101,
32514bf6087093375351784b287cb29c5f4603273cArman Uguray};
33c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray
34514bf6087093375351784b287cb29c5f4603273cArman Ugurayenum GATTError {
35514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_NONE = 0,
36514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_INVALID_HANDLE = 0x01,
37514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_READ_NOT_PERMITTED = 0x02,
38514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_WRITE_NOT_PERMITTED = 0x03,
39514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_INVALID_PDU = 0x04,
40514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_INSUFFICIENT_AUTHEN = 0x05,
41514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_REQUEST_NOT_SUPPORTED = 0x06,
42514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_INVALID_OFFSET = 0x07,
43514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_INSUFFICIENT_AUTHOR = 0x08,
44514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_PREP_QUEUE_FULL = 0x09,
45514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_ATTRIBUTE_NOT_FOUND = 0x0a,
46514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_ATTRIBUTE_NOT_LONG = 0x0b,
47514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_INSUFFICIENT_KEY_SIZE = 0x0c,
48514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_INVALID_ATTRIBUTE_LENGTH = 0x0d,
49514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_UNLIKELY = 0x0e,
50514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_INSUFFICIENT_ENCR = 0x0f,
51514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_UNSUPPORTED_GRP_TYPE = 0x10,
52514bf6087093375351784b287cb29c5f4603273cArman Uguray  GATT_ERROR_INSUFFICIENT_RESOURCES = 0x11,
531c162dc31bad03ee21a93e5afb9c7a572bf21ec7Arman Uguray  GATT_ERROR_CCCD_IMPROPERLY_CONFIGURED = 0xFD,
541c162dc31bad03ee21a93e5afb9c7a572bf21ec7Arman Uguray  GATT_ERROR_PROCEDURE_IN_PROGRESS = 0xFE,
551c162dc31bad03ee21a93e5afb9c7a572bf21ec7Arman Uguray  GATT_ERROR_OUT_OF_RANGE = 0xFF
56c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray};
57c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray
58911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonenum Transport { TRANSPORT_AUTO = 0, TRANSPORT_BREDR = 1, TRANSPORT_LE = 2 };
59df0b2714553cabc735222ce18a5f018c5a5fa138Arman Uguray
6091613743c9db02dbe05d93d2afa163b78068d054Arman Uguray// Android attribute permission values
6191613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint16_t kAttributePermissionNone = 0x0;
6291613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint16_t kAttributePermissionRead = 0x1;
6391613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint16_t kAttributePermissionReadEncrypted = 0x2;
6491613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint16_t kAttributePermissionReadEncryptedMITM = 0x4;
6591613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint16_t kAttributePermissionWrite = 0x10;
6691613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint16_t kAttributePermissionWriteEncrypted = 0x20;
6791613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint16_t kAttributePermissionWriteEncryptedMITM = 0x40;
6891613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint16_t kAttributePermissionWriteSigned = 0x80;
6991613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint16_t kAttributePermissionWriteSignedMITM = 0x100;
7091613743c9db02dbe05d93d2afa163b78068d054Arman Uguray
7191613743c9db02dbe05d93d2afa163b78068d054Arman Uguray// GATT characteristic properties bit-field values (not including the
7291613743c9db02dbe05d93d2afa163b78068d054Arman Uguray// characteristic extended properties).
7391613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint8_t kCharacteristicPropertyNone = 0x0;
7491613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint8_t kCharacteristicPropertyBroadcast = 0x1;
7591613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint8_t kCharacteristicPropertyRead = 0x2;
7691613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint8_t kCharacteristicPropertyWriteNoResponse = 0x4;
7791613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint8_t kCharacteristicPropertyWrite = 0x8;
7891613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint8_t kCharacteristicPropertyNotify = 0x10;
7991613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint8_t kCharacteristicPropertyIndicate = 0x20;
8091613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint8_t kCharacteristicPropertySignedWrite = 0x40;
8191613743c9db02dbe05d93d2afa163b78068d054Arman Ugurayconst uint8_t kCharacteristicPropertyExtendedProps = 0x80;
8291613743c9db02dbe05d93d2afa163b78068d054Arman Uguray
83909b7e6681101eb5e2d56209993134932284b50eArman Uguray// Advertising interval for different modes.
84909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst int kAdvertisingIntervalHighMs = 1000;
85909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst int kAdvertisingIntervalMediumMs = 250;
86909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst int kAdvertisingIntervalLowMs = 100;
87909b7e6681101eb5e2d56209993134932284b50eArman Uguray
88909b7e6681101eb5e2d56209993134932284b50eArman Uguray// Add some randomness to the advertising min/max interval so the controller can
89909b7e6681101eb5e2d56209993134932284b50eArman Uguray// do some optimization.
90909b7e6681101eb5e2d56209993134932284b50eArman Uguray// TODO(armansito): I took this directly from packages/apps/Bluetooth but based
91909b7e6681101eb5e2d56209993134932284b50eArman Uguray// on code review comments this constant and the accompanying logic doesn't make
92909b7e6681101eb5e2d56209993134932284b50eArman Uguray// sense. Let's remove this constant and figure out how to properly calculate
93909b7e6681101eb5e2d56209993134932284b50eArman Uguray// the Max. Adv. Interval. (See http://b/24344075).
94909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst int kAdvertisingIntervalDeltaUnit = 10;
95909b7e6681101eb5e2d56209993134932284b50eArman Uguray
96e0750ca056c8561d4a5b7ea14430049bf1d82fc1Jakub Pawlowski// Legacy Advertising types (ADV_IND, ADV_SCAN_IND, etc.) that are exposed to
97909b7e6681101eb5e2d56209993134932284b50eArman Uguray// applications.
9835675d0e738750ea348a0e593c72908bae1bacd7Jakub Pawlowskiconst uint16_t kAdvertisingEventTypeLegacyConnectable = 0x0013;
99e0750ca056c8561d4a5b7ea14430049bf1d82fc1Jakub Pawlowskiconst uint16_t kAdvertisingEventTypeLegacyScannable = 0x0012;
100e0750ca056c8561d4a5b7ea14430049bf1d82fc1Jakub Pawlowskiconst uint16_t kAdvertisingEventTypeLegacyNonConnectable = 0x0010;
101909b7e6681101eb5e2d56209993134932284b50eArman Uguray
102909b7e6681101eb5e2d56209993134932284b50eArman Uguray// Advertising channels. These should be kept the same as those defined in the
103909b7e6681101eb5e2d56209993134932284b50eArman Uguray// stack.
104909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst int kAdvertisingChannel37 = (1 << 0);
105909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst int kAdvertisingChannel38 = (1 << 1);
106909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst int kAdvertisingChannel39 = (1 << 2);
107909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst int kAdvertisingChannelAll =
108909b7e6681101eb5e2d56209993134932284b50eArman Uguray    (kAdvertisingChannel37 | kAdvertisingChannel38 | kAdvertisingChannel39);
109909b7e6681101eb5e2d56209993134932284b50eArman Uguray
110909b7e6681101eb5e2d56209993134932284b50eArman Uguray// Various Extended Inquiry Response fields types that are used for advertising
111909b7e6681101eb5e2d56209993134932284b50eArman Uguray// data fields as defined in the Core Specification Supplement.
112909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst uint8_t kEIRTypeFlags = 0x01;
113819e2ecb84a22d6e03ec9ed67b3260c0dd7e8abaJakub Pawlowskiconst uint8_t kEIRTypeIncomplete16BitUuids = 0x02;
114819e2ecb84a22d6e03ec9ed67b3260c0dd7e8abaJakub Pawlowskiconst uint8_t kEIRTypeComplete16BitUuids = 0x03;
115819e2ecb84a22d6e03ec9ed67b3260c0dd7e8abaJakub Pawlowskiconst uint8_t kEIRTypeIncomplete32BitUuids = 0x04;
116819e2ecb84a22d6e03ec9ed67b3260c0dd7e8abaJakub Pawlowskiconst uint8_t kEIRTypeComplete32BitUuids = 0x05;
117819e2ecb84a22d6e03ec9ed67b3260c0dd7e8abaJakub Pawlowskiconst uint8_t kEIRTypeIncomplete128BitUuids = 0x06;
118819e2ecb84a22d6e03ec9ed67b3260c0dd7e8abaJakub Pawlowskiconst uint8_t kEIRTypeComplete128BitUuids = 0x07;
1190ecddf398c92324e15a53c9d410646fd7a494b96Jakub Pawlowskiconst uint8_t kEIRTypeShortenedLocalName = 0x08;
1200ecddf398c92324e15a53c9d410646fd7a494b96Jakub Pawlowskiconst uint8_t kEIRTypeCompleteLocalName = 0x09;
1210ecddf398c92324e15a53c9d410646fd7a494b96Jakub Pawlowskiconst uint8_t kEIRTypeTxPower = 0x0A;
1222a2583bdd3069d7d0bd2a70fe9ab8b523b30f97aBailey Forrestconst uint8_t kEIRTypeServiceData = 0x16;
123909b7e6681101eb5e2d56209993134932284b50eArman Ugurayconst uint8_t kEIRTypeManufacturerSpecificData = 0xFF;
124909b7e6681101eb5e2d56209993134932284b50eArman Uguray
125c2fc0f287f4dfaf206a51856b8d5dfa923af3c05Arman Uguray}  // namespace bluetooth
126