Skip to content

Instantly share code, notes, and snippets.

@carlocaione
Created March 18, 2016 08:49
Show Gist options
  • Save carlocaione/c6759a8570d35af196d3 to your computer and use it in GitHub Desktop.
Save carlocaione/c6759a8570d35af196d3 to your computer and use it in GitHub Desktop.
diff --git a/tools/btattach.c b/tools/btattach.c
index bdbbe16..a184823 100644
--- a/tools/btattach.c
+++ b/tools/btattach.c
@@ -37,13 +37,13 @@
#include <sys/ioctl.h>
#include <poll.h>
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-#include <bluetooth/hci_lib.h>
+#include "lib/bluetooth.h"
+#include "lib/hci.h"
+#include "lib/hci_lib.h"
#include "hciattach.h"
-#include "monitor/mainloop.h"
#include "monitor/bt.h"
+#include "monitor/mainloop.h"
#include "src/shared/timeout.h"
#include "src/shared/util.h"
#include "src/shared/hci.h"
@@ -154,7 +154,8 @@ static int attach_proto(const char *path, unsigned int proto,
}
bt_hci_send(hci, BT_HCI_CMD_READ_LOCAL_VERSION, NULL, 0,
- local_version_callback, NULL, NULL);
+ local_version_callback, hci,
+ (bt_hci_destroy_func_t) bt_hci_unref);
}
return fd;
@@ -187,28 +188,46 @@ static void usage(void)
printf("options:\n"
"\t-B, --bredr <device> Attach BR/EDR controller\n"
"\t-A, --amp <device> Attach AMP controller\n"
+ "\t-P, --protocol <proto> Specify protocol type\n"
"\t-h, --help Show help options\n");
}
static const struct option main_options[] = {
- { "bredr", required_argument, NULL, 'B' },
- { "amp", required_argument, NULL, 'A' },
- { "version", no_argument, NULL, 'v' },
- { "help", no_argument, NULL, 'h' },
+ { "bredr", required_argument, NULL, 'B' },
+ { "amp", required_argument, NULL, 'A' },
+ { "protocol", required_argument, NULL, 'P' },
+ { "version", no_argument, NULL, 'v' },
+ { "help", no_argument, NULL, 'h' },
+ { }
+};
+
+static const struct {
+ const char *name;
+ unsigned int id;
+} proto_table[] = {
+ { "h4", HCI_UART_H4 },
+ { "bcsp", HCI_UART_BCSP },
+ { "3wire", HCI_UART_3WIRE },
+ { "h4ds", HCI_UART_H4DS },
+ { "ll", HCI_UART_LL },
+ { "ath3k", HCI_UART_ATH3K },
+ { "intel", HCI_UART_INTEL },
+ { "bcm", HCI_UART_BCM },
+ { "qca", HCI_UART_QCA },
{ }
};
int main(int argc, char *argv[])
{
- const char *bredr_path = NULL, *amp_path = NULL;
+ const char *bredr_path = NULL, *amp_path = NULL, *proto = NULL;
bool raw_device = false;
sigset_t mask;
- int exit_status, count = 0;
+ int exit_status, count = 0, proto_id = HCI_UART_H4;
for (;;) {
int opt;
- opt = getopt_long(argc, argv, "B:A:Rvh",
+ opt = getopt_long(argc, argv, "B:A:P:Rvh",
main_options, NULL);
if (opt < 0)
break;
@@ -220,6 +239,9 @@ int main(int argc, char *argv[])
case 'A':
amp_path = optarg;
break;
+ case 'P':
+ proto = optarg;
+ break;
case 'R':
raw_device = true;
break;
@@ -247,6 +269,22 @@ int main(int argc, char *argv[])
mainloop_set_signal(&mask, signal_callback, NULL, NULL);
+ if (proto) {
+ unsigned int i;
+
+ for (i = 0; proto_table[i].name; i++) {
+ if (!strcmp(proto_table[i].name, proto)) {
+ proto_id = proto_table[i].id;
+ break;
+ }
+ }
+
+ if (!proto_table[i].name) {
+ fprintf(stderr, "Invalid protocol\n");
+ return EXIT_FAILURE;
+ }
+ }
+
if (bredr_path) {
unsigned long flags;
int fd;
@@ -258,7 +296,7 @@ int main(int argc, char *argv[])
if (raw_device)
flags = (1 << HCI_UART_RAW_DEVICE);
- fd = attach_proto(bredr_path, HCI_UART_H4, flags);
+ fd = attach_proto(bredr_path, proto_id, flags);
if (fd >= 0) {
mainloop_add_fd(fd, 0, uart_callback, NULL, NULL);
count++;
@@ -277,7 +315,7 @@ int main(int argc, char *argv[])
if (raw_device)
flags = (1 << HCI_UART_RAW_DEVICE);
- fd = attach_proto(amp_path, HCI_UART_H4, flags);
+ fd = attach_proto(amp_path, proto_id, flags);
if (fd >= 0) {
mainloop_add_fd(fd, 0, uart_callback, NULL, NULL);
count++;
diff --git a/tools/hciattach.h b/tools/hciattach.h
index 2aaf075..7d9d9ba 100644
--- a/tools/hciattach.h
+++ b/tools/hciattach.h
@@ -39,10 +39,16 @@
#define HCI_UART_H4DS 3
#define HCI_UART_LL 4
#define HCI_UART_ATH3K 5
+#define HCI_UART_INTEL 6
+#define HCI_UART_BCM 7
+#define HCI_UART_QCA 8
#define HCI_UART_RAW_DEVICE 0
#define HCI_UART_RESET_ON_INIT 1
#define HCI_UART_CREATE_AMP 2
+#define HCI_UART_INIT_PENDING 3
+#define HCI_UART_EXT_CONFIG 4
+#define HCI_UART_VND_DETECT 5
int read_hci_event(int fd, unsigned char *buf, int size);
int set_speed(int fd, struct termios *ti, int speed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment