3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2011 Nokia Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <bluetooth/bluetooth.h>
32 #include <bluetooth/hci.h>
33 #include <bluetooth/hci_lib.h>
34 #include <bluetooth/sdp.h>
37 #include <btio/btio.h>
43 GIOChannel *gatt_connect(const char *src, const char *dst,
44 const char *dst_type, const char *sec_level,
45 int psm, int mtu, BtIOConnect connect_cb,
51 GError *tmp_err = NULL;
58 if (!strncmp(src, "hci", 3))
59 hci_devba(atoi(src + 3), &sba);
63 bacpy(&sba, BDADDR_ANY);
65 /* Not used for BR/EDR */
66 if (strcmp(dst_type, "random") == 0)
67 dest_type = BDADDR_LE_RANDOM;
69 dest_type = BDADDR_LE_PUBLIC;
71 if (strcmp(sec_level, "medium") == 0)
72 sec = BT_IO_SEC_MEDIUM;
73 else if (strcmp(sec_level, "high") == 0)
79 chan = bt_io_connect(connect_cb, NULL, NULL, &tmp_err,
80 BT_IO_OPT_SOURCE_BDADDR, &sba,
81 BT_IO_OPT_SOURCE_TYPE, BDADDR_LE_PUBLIC,
82 BT_IO_OPT_DEST_BDADDR, &dba,
83 BT_IO_OPT_DEST_TYPE, dest_type,
84 BT_IO_OPT_CID, ATT_CID,
85 BT_IO_OPT_SEC_LEVEL, sec,
88 chan = bt_io_connect(connect_cb, NULL, NULL, &tmp_err,
89 BT_IO_OPT_SOURCE_BDADDR, &sba,
90 BT_IO_OPT_DEST_BDADDR, &dba,
93 BT_IO_OPT_SEC_LEVEL, sec,
97 g_propagate_error(gerr, tmp_err);
104 size_t gatt_attr_data_from_string(const char *str, uint8_t **data)
109 size = strlen(str) / 2;
110 *data = g_try_malloc0(size);
115 for (i = 0; i < size; i++) {
116 memcpy(tmp, str + (i * 2), 2);
117 (*data)[i] = (uint8_t) strtol(tmp, NULL, 16);