aboutsummaryrefslogtreecommitdiff
path: root/embdrv/sbc/decoder/include/oi_bt_spec.h
blob: 67d5217cdbd18a0dd5e2c79513d1b3ec6fcaa6f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/******************************************************************************
 *
 *  Copyright 2014 The Android Open Source Project
 *  Copyright 2002 - 2004 Open Interface North America, Inc. All rights
 *                        reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/
#ifndef _OI_BT_SPEC_H
#define _OI_BT_SPEC_H
/**
 * @file
 *
 * This file contains common definitions from the Bluetooth specification.
 *
 */

/*******************************************************************************
  $Revision: #1 $
 ******************************************************************************/

#include "oi_stddefs.h"

/** \addtogroup Misc Miscellaneous APIs */
/**@{*/

#ifdef __cplusplus
extern "C" {
#endif

/** The maximum number of active slaves in a piconet. */
#define OI_BT_MAX_ACTIVE_SLAVES 7

/**
 * @name Data types for working with UUIDs
 * UUIDs are 16 bytes (128 bits).
 *
 * To avoid having to pass around 128-bit values all the time, 32-bit and 16-bit
 * UUIDs are defined, along with a mapping from the shorter versions to the full
 * version.
 *
 * @{
 */

/**
 * 16-bit representation of a 128-bit UUID
 */
typedef uint16_t OI_UUID16;

/**
 * 32-bit representation of a 128-bit UUID
 */
typedef uint32_t OI_UUID32;

/**
 * number of bytes in a 128 bit UUID
 */
#define OI_BT_UUID128_SIZE 16

/**
 * number of bytes in IPv6 style addresses
 */
#define OI_BT_IPV6ADDR_SIZE 16

/**
 * type definition for a 128-bit UUID
 *
 * To simplify conversion between 128-bit UUIDs and 16-bit and 32-bit UUIDs,
 * the most significant 32 bits are stored with the same endian-ness as is
 * native on the target (local) device. The remainder of the 128-bit UUID is
 * stored as bytes in big-endian order.
 */
typedef struct {
  /* most significant 32 bits of 128-bit UUID */
  uint32_t ms32bits;
  /* remainder of 128-bit UUID, array of 8-bit values */
  uint8_t base[OI_BT_UUID128_SIZE - sizeof(uint32_t)];
} OI_UUID128;

/** @} */

/** number of bytes in a link key */
#define OI_BT_LINK_KEY_SIZE 16

/**
 * type definition for a baseband link key
 *
 * Because 128-bit integers may not be supported on all platforms, we define
 * link keys as an array of bytes. Unlike the Bluetooth device address,
 * the link key is stored in little-endian order, meaning that
 *  - array[0]  contains bits 0  - 7,
 *  - array[1]  contains bits 8  - 15,
 *  - array[2]  contains bits 16 - 23,
 *  - array[3]  contains bits 24 - 31,
 *  - array[4]  contains bits 32 - 39,
 *  - array[5]  contains bits 40 - 47,
 *  - array[6]  contains bits 48 - 55,
 *  - array[7]  contains bits 56 - 63,
 *  - array[8]  contains bits 64 - 71,
 *  - array[9]  contains bits 72 - 79,
 *  - array[10] contains bits 80 - 87,
 *  - array[11] contains bits 88 - 95,
 *  - array[12] contains bits 96 - 103,
 *  - array[13] contains bits 104- 111,
 *  - array[14] contains bits 112- 119, and
 *  - array[15] contains bits 120- 127.
 */
typedef struct {
  /* link key represented as an array of 8-bit values */
  uint8_t key[OI_BT_LINK_KEY_SIZE];
} OI_LINK_KEY;

/** Out-of-band data size - C and R values are 16-bytes each */
#define OI_BT_OOB_NUM_BYTES 16

typedef struct {
  /* same struct used for C and R values */
  uint8_t value[OI_BT_OOB_NUM_BYTES];
} OI_OOB_DATA;

/**
 * link key types
 */
typedef enum {
  OI_LINK_KEY_TYPE_COMBO = 0,           /* combination key */
  OI_LINK_KEY_TYPE_LOCAL_UNIT = 1,      /* local unit key */
  OI_LINK_KEY_TYPE_REMOTE_UNIT = 2,     /* remote unit key */
  OI_LINK_KEY_TYPE_DEBUG_COMBO = 3,     /* debug combination key */
  OI_LINK_KEY_TYPE_UNAUTHENTICATED = 4, /* Unauthenticated */
  OI_LINK_KEY_TYPE_AUTHENTICATED = 5,   /* Authenticated */
  OI_LINK_KEY_TYPE_CHANGED_COMBO = 6    /* Changed */

} OI_BT_LINK_KEY_TYPE;

/* Number of bytes allocated for a PIN (personal indentification number) */
#define OI_BT_PIN_CODE_SIZE 16

/* data type for a PIN (PINs are treated as strings.) */
typedef struct {
  /* PIN represented as an array of 8-bit values */
  uint8_t pin[OI_BT_PIN_CODE_SIZE];
} OI_PIN_CODE;

/* maximum number of SCO connections per device: 3 as of version 2.0+EDR
    of the Bluetooth specification (see sec 4.3 of vol 2 part B) */
#define OI_BT_MAX_SCO_CONNECTIONS 3

/** data type for clock offset */
typedef uint16_t OI_BT_CLOCK_OFFSET;

/** data type for a LM handle */
typedef uint16_t OI_HCI_LM_HANDLE;

/** opaque data type for a SCO or ACL connection handle */
typedef struct _OI_HCI_CONNECTION* OI_HCI_CONNECTION_HANDLE;

/** data type for HCI Error Code, as defined in oi_hcispec.h */
typedef uint8_t OI_HCI_ERROR_CODE;

/**
 * The Bluetooth device type is indicated by a 24-bit bitfield, represented as a
 * 32-bit number in the stack. The bit layout and values for device class are
 * specified in the file oi_bt_assigned_nos.h and in the Bluetooth "Assigned
 * Numbers" specification at http://www.bluetooth.org/assigned-numbers/.
 */
typedef uint32_t OI_BT_DEVICE_CLASS;
/* Bits 0-1 contain format type. */
#define OI_BT_DEV_CLASS_FORMAT_MASK 0x000003
/* Bits 2-7 contain minor device class value. */
#define OI_BT_DEV_CLASS_MINOR_DEVICE_MASK 0x0000FC
/* Bits 8-12 contain major device class value. */
#define OI_BT_DEV_CLASS_MAJOR_DEVICE_MASK 0x001F00
/* Bits 13-23 contain major service class value. */
#define OI_BT_DEV_CLASS_MAJOR_SERVICE_MASK 0xFFE000

/** There is currently only one device class format defined, type 00. */
#define OI_BT_DEV_CLASS_FORMAT_TYPE 00

/* Bit 13 in device class indicates limited discoverability mode (GAP v2.0+EDR,
 * section 4.1.2.2)
 */
#define OI_BT_DEV_CLASS_LIMITED_DISCO_BIT BIT13

/** macro to test validity of the Device Class Format */
#define OI_BT_VALID_DEVICE_CLASS_FORMAT(class) \
  (OI_BT_DEV_CLASS_FORMAT_TYPE == ((class) & OI_BT_DEV_CLASS_FORMAT_MASK))

/* the time between baseband clock ticks, currently 625 microseconds (one slot)
 */
#define OI_BT_TICK 625
/* some macros to convert to/from baseband clock ticks - no floating point! */
#define OI_SECONDS_TO_BT_TICKS(secs) ((secs)*1600)
#define OI_BT_TICKS_TO_SECONDS(ticks) ((ticks) / 1600)
#define OI_MSECS_TO_BT_TICKS(msecs) (((msecs)*8) / 5)
#define OI_BT_TICKS_TO_MSECS(ticks) (((ticks)*5) / 8)

/** EIR byte order */
#define OI_EIR_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER

#ifdef __cplusplus
}
#endif

/**@}*/

/*****************************************************************************/
#endif /* _OI_BT_SPEC_H */