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
27
#include <bluetooth/sdp.h>
28
#include <bluetooth/sdp_lib.h>
34
guint gatt_discover_primary(GAttrib *attrib, uint16_t start, uint16_t end,
35
uuid_t *uuid, GAttribResultFunc func, gpointer user_data)
37
uint8_t pdu[ATT_DEFAULT_MTU];
42
sdp_uuid16_create(&prim, GATT_PRIM_SVC_UUID);
46
/* Discover all primary services */
47
op = ATT_OP_READ_BY_GROUP_REQ;
48
plen = enc_read_by_grp_req(start, end, &prim, pdu, sizeof(pdu));
53
/* Discover primary service by service UUID */
54
op = ATT_OP_FIND_BY_TYPE_REQ;
56
if (uuid->type == SDP_UUID16) {
57
value = &uuid->value.uuid16;
58
vlen = sizeof(uuid->value.uuid16);
60
value = &uuid->value.uuid128;
61
vlen = sizeof(uuid->value.uuid128);
64
plen = enc_find_by_type_req(start, end, &prim, value, vlen,
71
return g_attrib_send(attrib, op, pdu, plen, func, user_data, NULL);
74
guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
75
GAttribResultFunc func, gpointer user_data)
79
sdp_uuid16_create(&uuid, GATT_CHARAC_UUID);
81
return gatt_read_char_by_uuid(attrib, start, end, &uuid, func,
85
guint gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start, uint16_t end,
86
uuid_t *uuid, GAttribResultFunc func,
89
uint8_t pdu[ATT_DEFAULT_MTU];
92
plen = enc_read_by_type_req(start, end, uuid, pdu, sizeof(pdu));
96
return g_attrib_send(attrib, ATT_OP_READ_BY_TYPE_REQ,
97
pdu, plen, func, user_data, NULL);
100
guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
103
uint8_t pdu[ATT_DEFAULT_MTU];
106
plen = enc_read_req(handle, pdu, sizeof(pdu));
107
return g_attrib_send(attrib, ATT_OP_READ_REQ, pdu, plen, func,
111
guint gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value,
112
int vlen, GAttribResultFunc func, gpointer user_data)
114
uint8_t pdu[ATT_DEFAULT_MTU];
117
plen = enc_write_req(handle, value, vlen, pdu, sizeof(pdu));
118
return g_attrib_send(attrib, ATT_OP_WRITE_REQ, pdu, plen, func,
122
guint gatt_find_info(GAttrib *attrib, uint16_t start, uint16_t end,
123
GAttribResultFunc func, gpointer user_data)
125
uint8_t pdu[ATT_DEFAULT_MTU];
128
plen = enc_find_info_req(start, end, pdu, sizeof(pdu));
132
return g_attrib_send(attrib, ATT_OP_FIND_INFO_REQ, pdu, plen, func,
136
guint gatt_write_cmd(GAttrib *attrib, uint16_t handle, uint8_t *value, int vlen,
137
GDestroyNotify notify, gpointer user_data)
139
uint8_t pdu[ATT_DEFAULT_MTU];
142
plen = enc_write_cmd(handle, value, vlen, pdu, sizeof(pdu));
143
return g_attrib_send(attrib, ATT_OP_WRITE_CMD, pdu, plen, NULL,