~timchen119/+junk/bluez5-trusty

« back to all changes in this revision

Viewing changes to src/shared/att-types.h

  • Committer: tim
  • Date: 2015-09-04 08:03:03 UTC
  • Revision ID: tim@tim-inspiron-5442-20150904080303-75u7z8bdsl17xz8q
* init

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  BlueZ - Bluetooth protocol stack for Linux
 
4
 *
 
5
 *  Copyright (C) 2014  Google Inc.
 
6
 *
 
7
 *
 
8
 *  This library is free software; you can redistribute it and/or
 
9
 *  modify it under the terms of the GNU Lesser General Public
 
10
 *  License as published by the Free Software Foundation; either
 
11
 *  version 2.1 of the License, or (at your option) any later version.
 
12
 *
 
13
 *  This library is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 *  Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public
 
19
 *  License along with this library; if not, write to the Free Software
 
20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 *
 
22
 */
 
23
 
 
24
#include <stdint.h>
 
25
 
 
26
#ifndef __packed
 
27
#define __packed __attribute__((packed))
 
28
#endif
 
29
 
 
30
#define BT_ATT_SECURITY_AUTO    0
 
31
#define BT_ATT_SECURITY_LOW     1
 
32
#define BT_ATT_SECURITY_MEDIUM  2
 
33
#define BT_ATT_SECURITY_HIGH    3
 
34
 
 
35
#define BT_ATT_DEFAULT_LE_MTU   23
 
36
#define BT_ATT_MAX_LE_MTU       517
 
37
#define BT_ATT_MAX_VALUE_LEN    512
 
38
 
 
39
/* ATT protocol opcodes */
 
40
#define BT_ATT_OP_ERROR_RSP                     0x01
 
41
#define BT_ATT_OP_MTU_REQ                       0x02
 
42
#define BT_ATT_OP_MTU_RSP                       0x03
 
43
#define BT_ATT_OP_FIND_INFO_REQ                 0x04
 
44
#define BT_ATT_OP_FIND_INFO_RSP                 0x05
 
45
#define BT_ATT_OP_FIND_BY_TYPE_VAL_REQ          0x06
 
46
#define BT_ATT_OP_FIND_BY_TYPE_VAL_RSP          0x07
 
47
#define BT_ATT_OP_READ_BY_TYPE_REQ              0x08
 
48
#define BT_ATT_OP_READ_BY_TYPE_RSP              0x09
 
49
#define BT_ATT_OP_READ_REQ                      0x0a
 
50
#define BT_ATT_OP_READ_RSP                      0x0b
 
51
#define BT_ATT_OP_READ_BLOB_REQ                 0x0c
 
52
#define BT_ATT_OP_READ_BLOB_RSP                 0x0d
 
53
#define BT_ATT_OP_READ_MULT_REQ                 0x0e
 
54
#define BT_ATT_OP_READ_MULT_RSP                 0x0f
 
55
#define BT_ATT_OP_READ_BY_GRP_TYPE_REQ          0x10
 
56
#define BT_ATT_OP_READ_BY_GRP_TYPE_RSP          0x11
 
57
#define BT_ATT_OP_WRITE_REQ                     0x12
 
58
#define BT_ATT_OP_WRITE_RSP                     0x13
 
59
#define BT_ATT_OP_WRITE_CMD                     0x52
 
60
#define BT_ATT_OP_SIGNED_WRITE_CMD              0xD2
 
61
#define BT_ATT_OP_PREP_WRITE_REQ                0x16
 
62
#define BT_ATT_OP_PREP_WRITE_RSP                0x17
 
63
#define BT_ATT_OP_EXEC_WRITE_REQ                0x18
 
64
#define BT_ATT_OP_EXEC_WRITE_RSP                0x19
 
65
#define BT_ATT_OP_HANDLE_VAL_NOT                0x1B
 
66
#define BT_ATT_OP_HANDLE_VAL_IND                0x1D
 
67
#define BT_ATT_OP_HANDLE_VAL_CONF               0x1E
 
68
 
 
69
/* Packed struct definitions for ATT protocol PDUs */
 
70
/* TODO: Complete these definitions for all opcodes */
 
71
struct bt_att_pdu_error_rsp {
 
72
        uint8_t opcode;
 
73
        uint16_t handle;
 
74
        uint8_t ecode;
 
75
} __packed;
 
76
 
 
77
/* Special opcode to receive all requests (legacy servers) */
 
78
#define BT_ATT_ALL_REQUESTS 0x00
 
79
 
 
80
/* Error codes for Error response PDU */
 
81
#define BT_ATT_ERROR_INVALID_HANDLE                     0x01
 
82
#define BT_ATT_ERROR_READ_NOT_PERMITTED                 0x02
 
83
#define BT_ATT_ERROR_WRITE_NOT_PERMITTED                0x03
 
84
#define BT_ATT_ERROR_INVALID_PDU                        0x04
 
85
#define BT_ATT_ERROR_AUTHENTICATION                     0x05
 
86
#define BT_ATT_ERROR_REQUEST_NOT_SUPPORTED              0x06
 
87
#define BT_ATT_ERROR_INVALID_OFFSET                     0x07
 
88
#define BT_ATT_ERROR_AUTHORIZATION                      0x08
 
89
#define BT_ATT_ERROR_PREPARE_QUEUE_FULL                 0x09
 
90
#define BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND                0x0A
 
91
#define BT_ATT_ERROR_ATTRIBUTE_NOT_LONG                 0x0B
 
92
#define BT_ATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE   0x0C
 
93
#define BT_ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LEN        0x0D
 
94
#define BT_ATT_ERROR_UNLIKELY                           0x0E
 
95
#define BT_ATT_ERROR_INSUFFICIENT_ENCRYPTION            0x0F
 
96
#define BT_ATT_ERROR_UNSUPPORTED_GROUP_TYPE             0x10
 
97
#define BT_ATT_ERROR_INSUFFICIENT_RESOURCES             0x11
 
98
 
 
99
/*
 
100
 * Common Profile and Service Error Code descriptions (see Supplement to the
 
101
 * Bluetooth Core Specification, sections 1.2 and 2). The error codes within
 
102
 * 0xE0-0xFC are reserved for future use. The remaining 3 are defined as the
 
103
 * following:
 
104
 */
 
105
#define BT_ERROR_CCC_IMPROPERLY_CONFIGURED      0xfd
 
106
#define BT_ERROR_ALREADY_IN_PROGRESS            0xfe
 
107
#define BT_ERROR_OUT_OF_RANGE                   0xff
 
108
 
 
109
/*
 
110
 * ATT attribute permission bitfield values. Permissions are grouped as
 
111
 * "Access", "Encryption", "Authentication", and "Authorization". A bitmask of
 
112
 * permissions is a byte that encodes a combination of these.
 
113
 */
 
114
#define BT_ATT_PERM_READ                0x01
 
115
#define BT_ATT_PERM_WRITE               0x02
 
116
#define BT_ATT_PERM_READ_ENCRYPT        0x04
 
117
#define BT_ATT_PERM_WRITE_ENCRYPT       0x08
 
118
#define BT_ATT_PERM_ENCRYPT             (BT_ATT_PERM_READ_ENCRYPT | \
 
119
                                        BT_ATT_PERM_WRITE_ENCRYPT)
 
120
#define BT_ATT_PERM_READ_AUTHEN         0x10
 
121
#define BT_ATT_PERM_WRITE_AUTHEN        0x20
 
122
#define BT_ATT_PERM_AUTHEN              (BT_ATT_PERM_READ_AUTHEN | \
 
123
                                        BT_ATT_PERM_WRITE_AUTHEN)
 
124
#define BT_ATT_PERM_AUTHOR              0x40
 
125
#define BT_ATT_PERM_NONE                0x80
 
126
 
 
127
/* GATT Characteristic Properties Bitfield values */
 
128
#define BT_GATT_CHRC_PROP_BROADCAST                     0x01
 
129
#define BT_GATT_CHRC_PROP_READ                          0x02
 
130
#define BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP            0x04
 
131
#define BT_GATT_CHRC_PROP_WRITE                         0x08
 
132
#define BT_GATT_CHRC_PROP_NOTIFY                        0x10
 
133
#define BT_GATT_CHRC_PROP_INDICATE                      0x20
 
134
#define BT_GATT_CHRC_PROP_AUTH                          0x40
 
135
#define BT_GATT_CHRC_PROP_EXT_PROP                      0x80
 
136
 
 
137
/* GATT Characteristic Extended Properties Bitfield values */
 
138
#define BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE            0x01
 
139
#define BT_GATT_CHRC_EXT_PROP_WRITABLE_AUX              0x02
 
140
#define BT_GATT_CHRC_EXT_PROP_ENC_READ                  0x04
 
141
#define BT_GATT_CHRC_EXT_PROP_ENC_WRITE                 0x08
 
142
#define BT_GATT_CHRC_EXT_PROP_ENC       (BT_GATT_CHRC_EXT_PROP_ENC_READ | \
 
143
                                        BT_GATT_CHRC_EXT_PROP_ENC_WRITE)
 
144
#define BT_GATT_CHRC_EXT_PROP_AUTH_READ                 0x10
 
145
#define BT_GATT_CHRC_EXT_PROP_AUTH_WRITE                0x20
 
146
#define BT_GATT_CHRC_EXT_PROP_AUTH      (BT_GATT_CHRC_EXT_PROP_AUTH_READ | \
 
147
                                        BT_GATT_CHRC_EXT_PROP_AUTH_WRITE)