3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2010 Nokia Corporation
6
* Copyright (C) 2010 Marcel Holtmann <marcel@holtmann.org>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
/* GATT Profile Attribute types */
26
#define GATT_PRIM_SVC_UUID 0x2800
27
#define GATT_SND_SVC_UUID 0x2801
28
#define GATT_INCLUDE_UUID 0x2802
29
#define GATT_CHARAC_UUID 0x2803
31
/* GATT Characteristic Types */
32
#define GATT_CHARAC_DEVICE_NAME 0x2A00
33
#define GATT_CHARAC_APPEARANCE 0x2A01
34
#define GATT_CHARAC_PERIPHERAL_PRIV_FLAG 0x2A02
35
#define GATT_CHARAC_RECONNECTION_ADDRESS 0x2A03
36
#define GATT_CHARAC_PERIPHERAL_PREF_CONN 0x2A04
37
#define GATT_CHARAC_SERVICE_CHANGED 0x2A05
39
/* GATT Characteristic Descriptors */
40
#define GATT_CHARAC_EXT_PROPER_UUID 0x2900
41
#define GATT_CHARAC_USER_DESC_UUID 0x2901
42
#define GATT_CLIENT_CHARAC_CFG_UUID 0x2902
43
#define GATT_SERVER_CHARAC_CFG_UUID 0x2903
44
#define GATT_CHARAC_FMT_UUID 0x2904
45
#define GATT_CHARAC_AGREG_FMT_UUID 0x2905
47
/* Attribute Protocol Opcodes */
48
#define ATT_OP_ERROR 0x01
49
#define ATT_OP_MTU_REQ 0x02
50
#define ATT_OP_MTU_RESP 0x03
51
#define ATT_OP_FIND_INFO_REQ 0x04
52
#define ATT_OP_FIND_INFO_RESP 0x05
53
#define ATT_OP_FIND_BY_TYPE_REQ 0x06
54
#define ATT_OP_FIND_BY_TYPE_RESP 0x07
55
#define ATT_OP_READ_BY_TYPE_REQ 0x08
56
#define ATT_OP_READ_BY_TYPE_RESP 0x09
57
#define ATT_OP_READ_REQ 0x0A
58
#define ATT_OP_READ_RESP 0x0B
59
#define ATT_OP_READ_BLOB_REQ 0x0C
60
#define ATT_OP_READ_BLOB_RESP 0x0D
61
#define ATT_OP_READ_MULTI_REQ 0x0E
62
#define ATT_OP_READ_MULTI_RESP 0x0F
63
#define ATT_OP_READ_BY_GROUP_REQ 0x10
64
#define ATT_OP_READ_BY_GROUP_RESP 0x11
65
#define ATT_OP_WRITE_REQ 0x12
66
#define ATT_OP_WRITE_RESP 0x13
67
#define ATT_OP_WRITE_CMD 0x52
68
#define ATT_OP_PREP_WRITE_REQ 0x16
69
#define ATT_OP_PREP_WRITE_RESP 0x17
70
#define ATT_OP_EXEC_WRITE_REQ 0x18
71
#define ATT_OP_EXEC_WRITE_RESP 0x19
72
#define ATT_OP_HANDLE_NOTIFY 0x1B
73
#define ATT_OP_HANDLE_IND 0x1D
74
#define ATT_OP_HANDLE_CNF 0x1E
75
#define ATT_OP_SIGNED_WRITE_CMD 0xD2
77
/* Error codes for Error response PDU */
78
#define ATT_ECODE_INVALID_HANDLE 0x01
79
#define ATT_ECODE_READ_NOT_PERM 0x02
80
#define ATT_ECODE_WRITE_NOT_PERM 0x03
81
#define ATT_ECODE_INVALID_PDU 0x04
82
#define ATT_ECODE_INSUFF_AUTHEN 0x05
83
#define ATT_ECODE_REQ_NOT_SUPP 0x06
84
#define ATT_ECODE_INVALID_OFFSET 0x07
85
#define ATT_ECODE_INSUFF_AUTHO 0x08
86
#define ATT_ECODE_PREP_QUEUE_FULL 0x09
87
#define ATT_ECODE_ATTR_NOT_FOUND 0x0A
88
#define ATT_ECODE_ATTR_NOT_LONG 0x0B
89
#define ATT_ECODE_INSUFF_ENCR_KEY_SIZE 0x0C
90
#define ATT_ECODE_INVAL_ATTR_VALUE_LEN 0x0D
91
#define ATT_ECODE_UNLIKELY 0x0E
92
#define ATT_ECODE_INSUFF_ENC 0x0F
93
#define ATT_ECODE_UNSUPP_GRP_TYPE 0x10
94
#define ATT_ECODE_INSUFF_RESOURCES 0x11
95
/* Application error */
96
#define ATT_ECODE_IO 0xFF
98
/* Characteristic Property bit field */
99
#define ATT_CHAR_PROPER_BROADCAST 0x01
100
#define ATT_CHAR_PROPER_READ 0x02
101
#define ATT_CHAR_PROPER_WRITE_WITHOUT_RESP 0x04
102
#define ATT_CHAR_PROPER_WRITE 0x08
103
#define ATT_CHAR_PROPER_NOTIFY 0x10
104
#define ATT_CHAR_PROPER_INDICATE 0x20
105
#define ATT_CHAR_PROPER_AUTH 0x40
106
#define ATT_CHAR_PROPER_EXT_PROPER 0x80
109
#define ATT_MAX_MTU 256
110
#define ATT_DEFAULT_MTU 23
119
struct att_data_list {
130
/* These functions do byte conversion */
131
static inline uint8_t att_get_u8(const void *ptr)
133
const uint8_t *u8_ptr = ptr;
134
return bt_get_unaligned(u8_ptr);
137
static inline uint16_t att_get_u16(const void *ptr)
139
const uint16_t *u16_ptr = ptr;
140
return btohs(bt_get_unaligned(u16_ptr));
143
static inline uint32_t att_get_u32(const void *ptr)
145
const uint32_t *u32_ptr = ptr;
146
return btohl(bt_get_unaligned(u32_ptr));
149
static inline void att_put_u8(uint8_t src, void *dst)
151
bt_put_unaligned(src, (uint8_t *) dst);
154
static inline void att_put_u16(uint16_t src, void *dst)
156
bt_put_unaligned(htobs(src), (uint16_t *) dst);
159
static inline void att_put_u32(uint16_t src, void *dst)
161
bt_put_unaligned(htobl(src), (uint32_t *) dst);
164
void att_data_list_free(struct att_data_list *list);
166
const char *att_ecode2str(uint8_t status);
167
uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, uuid_t *uuid,
168
uint8_t *pdu, int len);
169
uint16_t dec_read_by_grp_req(const uint8_t *pdu, int len, uint16_t *start,
170
uint16_t *end, uuid_t *uuid);
171
uint16_t enc_read_by_grp_resp(struct att_data_list *list, uint8_t *pdu, int len);
172
uint16_t enc_find_by_type_req(uint16_t start, uint16_t end, uuid_t *uuid,
173
const uint8_t *value, int vlen, uint8_t *pdu, int len);
174
uint16_t dec_find_by_type_req(const uint8_t *pdu, int len, uint16_t *start,
175
uint16_t *end, uuid_t *uuid, uint8_t *value, int *vlen);
176
uint16_t enc_find_by_type_resp(GSList *ranges, uint8_t *pdu, int len);
177
GSList *dec_find_by_type_resp(const uint8_t *pdu, int len);
178
struct att_data_list *dec_read_by_grp_resp(const uint8_t *pdu, int len);
179
uint16_t enc_read_by_type_req(uint16_t start, uint16_t end, uuid_t *uuid,
180
uint8_t *pdu, int len);
181
uint16_t dec_read_by_type_req(const uint8_t *pdu, int len, uint16_t *start,
182
uint16_t *end, uuid_t *uuid);
183
uint16_t enc_read_by_type_resp(struct att_data_list *list, uint8_t *pdu,
185
uint16_t enc_write_cmd(uint16_t handle, const uint8_t *value, int vlen,
186
uint8_t *pdu, int len);
187
uint16_t dec_write_cmd(const uint8_t *pdu, int len, uint16_t *handle,
188
uint8_t *value, int *vlen);
189
struct att_data_list *dec_read_by_type_resp(const uint8_t *pdu, int len);
190
uint16_t enc_write_req(uint16_t handle, const uint8_t *value, int vlen,
191
uint8_t *pdu, int len);
192
uint16_t dec_write_req(const uint8_t *pdu, int len, uint16_t *handle,
193
uint8_t *value, int *vlen);
194
uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, int len);
195
uint16_t dec_read_req(const uint8_t *pdu, int len, uint16_t *handle);
196
uint16_t enc_read_resp(uint8_t *value, int vlen, uint8_t *pdu, int len);
197
uint16_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int *vlen);
198
uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status,
199
uint8_t *pdu, int len);
200
uint16_t enc_find_info_req(uint16_t start, uint16_t end, uint8_t *pdu, int len);
201
uint16_t dec_find_info_req(const uint8_t *pdu, int len, uint16_t *start,
203
uint16_t enc_find_info_resp(uint8_t format, struct att_data_list *list,
204
uint8_t *pdu, int len);
205
struct att_data_list *dec_find_info_resp(const uint8_t *pdu, int len,
207
uint16_t enc_notification(struct attribute *a, uint8_t *pdu, int len);
208
uint16_t enc_indication(struct attribute *a, uint8_t *pdu, int len);
209
struct attribute *dec_indication(const uint8_t *pdu, int len);
210
uint16_t enc_confirmation(uint8_t *pdu, int len);
212
uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, int len);
213
uint16_t dec_mtu_req(const uint8_t *pdu, int len, uint16_t *mtu);
214
uint16_t enc_mtu_resp(uint16_t mtu, uint8_t *pdu, int len);
215
uint16_t dec_mtu_resp(const uint8_t *pdu, int len, uint16_t *mtu);