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
27 #include <bluetooth/bluetooth.h>
28 #include <bluetooth/hci.h>
29 #include <bluetooth/hci_lib.h>
30 #include <bluetooth/uuid.h>
31 #include <bluetooth/sdp.h>
39 GIOChannel *gatt_connect(const gchar *src, const gchar *dst,
40 const gchar *dst_type, const gchar *sec_level,
41 int psm, int mtu, BtIOConnect connect_cb)
51 g_printerr("Remote Bluetooth address required\n");
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(BT_IO_L2CAP, connect_cb, NULL, NULL, &err,
80 BT_IO_OPT_SOURCE_BDADDR, &sba,
81 BT_IO_OPT_DEST_BDADDR, &dba,
82 BT_IO_OPT_DEST_TYPE, dest_type,
83 BT_IO_OPT_CID, ATT_CID,
84 BT_IO_OPT_SEC_LEVEL, sec,
87 chan = bt_io_connect(BT_IO_L2CAP, connect_cb, NULL, NULL, &err,
88 BT_IO_OPT_SOURCE_BDADDR, &sba,
89 BT_IO_OPT_DEST_BDADDR, &dba,
92 BT_IO_OPT_SEC_LEVEL, sec,
96 g_printerr("%s\n", err->message);
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);