diff options
author | Arman Uguray <armansito@chromium.org> | 2014-11-14 12:20:23 -0800 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2014-11-17 11:29:27 +0200 |
commit | 46da8d07a7a2fdd91e3b15eceef831fc1aacb791 (patch) | |
tree | 9c3e94ac3fd390a7f702f4e1ce44e46901d85017 /tools/btgatt-server.c | |
parent | 01244de3a939a5d466cce3a8586c947034e36f37 (diff) | |
download | bluez-46da8d07a7a2fdd91e3b15eceef831fc1aacb791.tar.gz |
tools/btgatt-server: Introduce btgatt-server.
This patch introduces tools/btgatt-server, which is a command-line tool
for testing and debugging shared/gatt-server.
Diffstat (limited to 'tools/btgatt-server.c')
-rw-r--r-- | tools/btgatt-server.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c new file mode 100644 index 000000000..c0d8dd610 --- /dev/null +++ b/tools/btgatt-server.c @@ -0,0 +1,114 @@ +/* + * 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; +} |