xref: /btstack/port/libusb/README.md (revision 80e33422a96c028b3a9c308fc4b9b874712dafb4)
1# BTstack Port for POSIX Systems with libusb Library
2
3## Compilation
4The quickest way to try BTstack is on a Linux or OS X system with an
5additional USB Bluetooth dongle. It requires
6[pkg-config](http://www.freedesktop.org/wiki/Software/pkg-config/)
7and [libusb-1.0](http://libusb.info) or higher to be
8installed.
9
10On a recent Debian-based system, all you need is:
11
12	apt-get install gcc git libusb-1.0 pkg-config
13
14
15When everything is ready, you compile all examples with:
16
17	make
18
19## Environment
20
21On Linux, the USB Bluetooth dongle is usually not accessible to a regular user. You can either:
22- run the examples as root
23- add a udev rule for your dongle to extend access rights to user processes
24
25To add an udev rule, please create `/etc/udev/rules.d/btstack.rules` and add this
26
27	# Match all devices from CSR
28	SUBSYSTEM=="usb", ATTRS{idVendor}=="0a12", MODE="0666"
29
30	# Match DeLOCK Bluetooth 4.0 dongle
31	SUBSYSTEM=="usb", ATTRS{idVendor}=="0a5c", ATTRS{device}=="21e8", MODE="0666"
32
33	# Match Asus BT400
34	SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", ATTRS{device}=="17cb", MODE="0666"
35
36	# Match Laird BT860 / Cypress Semiconductor CYW20704A2
37	SUBSYSTEM=="usb", ATTRS{idVendor}=="04b4", ATTRS{device}=="f901", MODE="0666"
38
39
40On macOS, the OS will try to use a plugged-in Bluetooth Controller if one is available.
41It's best to to tell the OS to always use the internal Bluetooth Contoller.
42
43For this, execute:
44
45    sudo nvram bluetoothHostControllerSwitchBehavior=never
46
47and then reboot to activate the change.
48
49## Running the examples
50
51BTstack's HCI USB transport will try to find a suitable Bluetooth module and use it.
52
53On start, BTstack will try to find a suitable Bluetooth module. It will also print the path to the packet log as well as the USB path.
54
55	$ ./le_counter
56	Packet Log: /tmp/hci_dump.pklg
57	BTstack counter 0001
58	USB Path: 06
59	BTstack up and running on 00:1A:7D:DA:71:13.
60
61If you want to run multiple examples at the same time, it helps to fix the path to the used Bluetooth module by passing -u usb-path to the executable.
62
63Example running le_streamer and le_streamer_client in two processes, using Bluetooth dongles at USB path 6 and 4:
64
65	./le_streamer -u 6
66	Specified USB Path: 06
67	Packet Log: /tmp/hci_dump_6.pklg
68	USB Path: 06
69	BTstack up and running on 00:1A:7D:DA:71:13.
70	To start the streaming, please run the le_streamer_client example on other device, or use some GATT Explorer, e.g. LightBlue, BLExplr.
71
72	$ ./le_streamer_client -u 4
73	Specified USB Path: 04
74	Packet Log: /tmp/hci_dump_4.pklg
75	USB Path: 04
76	BTstack up and running on 00:1A:7D:DA:71:13.
77	Start scanning!
78