diff --git a/.gitignore b/.gitignore
index 164cc97..82304b0 100644
--- a/.gitignore
+++ b/.gitignore
tools/obexctl
tools/gatt-service
tools/btgatt-client
+tools/btgatt-server
tools/mcaptest
test/sap_client.pyc
test/bluezutils.pyc
diff --git a/Makefile.tools b/Makefile.tools
index 75a6faa..ef4162b 100644
--- a/Makefile.tools
+++ b/Makefile.tools
tools/btmgmt tools/btinfo tools/btattach \
tools/btsnoop tools/btproxy tools/btiotest \
tools/cltest tools/seq2bseq tools/hex2hcd \
- tools/ibeacon tools/btgatt-client
+ tools/ibeacon tools/btgatt-client \
+ tools/btgatt-server
tools_bdaddr_SOURCES = tools/bdaddr.c src/oui.h src/oui.c
tools_bdaddr_LDADD = lib/libbluetooth-internal.la @UDEV_LIBS@
tools_ibeacon_LDADD = src/libshared-mainloop.la
tools_btgatt_client_SOURCES = tools/btgatt-client.c src/uuid-helper.c
-tools_btgatt_client_LDADD = lib/libbluetooth-internal.la \
- src/libshared-mainloop.la
+tools_btgatt_client_LDADD = src/libshared-mainloop.la \
+ lib/libbluetooth-internal.la
+
+tools_btgatt_server_SOURCES = tools/btgatt-server.c src/uuid-helper.c
+tools_btgatt_server_LDADD = src/libshared-mainloop.la \
+ lib/libbluetooth-internal.la
EXTRA_DIST += tools/bdaddr.1
endif
diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c
new file mode 100644
index 0000000..c0d8dd6
--- /dev/null
+++ b/tools/btgatt-server.c
+/*
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Google Inc.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
+#include <bluetooth/l2cap.h>
+#include "lib/uuid.h"
+
+static bool verbose = false;
+
+static void usage(void)
+{
+ printf("btgatt-server\n");
+ printf("Usage:\n\tbtgatt-server [options]\n");
+
+ printf("Options:\n"
+ "\t-i, --index <id>\t\tSpecify adapter index, e.g. hci0\n"
+ "\t-m, --mtu <mtu>\t\t\tThe ATT MTU to use\n"
+ "\t-s, --security-level <sec>\tSet security level (low|"
+ "medium|high)\n"
+ "\t-v, --verbose\t\t\tEnable extra logging\n"
+ "\t-h, --help\t\t\tDisplay help\n");
+}
+
+static struct option main_options[] = {
+ { "index", 1, 0, 'i' },
+ { "mtu", 1, 0, 'm' },
+ { "security-level", 1, 0, 's' },
+ { "verbose", 0, 0, 'v' },
+ { "help", 0, 0, 'h' },
+ { }
+};
+
+int main(int argc, char *argv[])
+{
+ int opt;
+ bdaddr_t src_addr;
+ int dev_id = -1;
+
+ while ((opt = getopt_long(argc, argv, "+hvs:m:i:",
+ main_options, NULL)) != -1) {
+ switch (opt) {
+ case 'h':
+ usage();
+ return EXIT_SUCCESS;
+ case 'v':
+ verbose = true;
+ break;
+ case 's':
+ /* TODO */
+ break;
+ case 'm':
+ /* TODO */
+ break;
+ case 'i':
+ dev_id = hci_devid(optarg);
+ if (dev_id < 0) {
+ perror("Invalid adapter");
+ return EXIT_FAILURE;
+ }
+
+ break;
+ default:
+ fprintf(stderr, "Invalid option: %c\n", opt);
+ return EXIT_FAILURE;
+ }
+ }
+
+ argc -= optind;
+ argv -= optind;
+ optind = 0;
+
+ if (argc) {
+ usage();
+ return EXIT_SUCCESS;
+ }
+
+ if (dev_id == -1)
+ bacpy(&src_addr, BDADDR_ANY);
+ else if (hci_devba(dev_id, &src_addr) < 0) {
+ perror("Adapter not available");
+ return EXIT_FAILURE;
+ }
+
+ /* TODO: Set up mainloop and listening LE socket */
+
+ return 0;
+}