xref: /btstack/port/libusb/README.md (revision 8e0bef02fedb425c450844ee3ba3a68eec5a5f07)
1808a498cSMatthias Ringwald# BTstack Port for POSIX Systems with libusb Library
2304b2f4dSMatthias Ringwald
3808a498cSMatthias Ringwald## Compilation
4304b2f4dSMatthias RingwaldThe quickest way to try BTstack is on a Linux or OS X system with an
5304b2f4dSMatthias Ringwaldadditional USB Bluetooth dongle. It requires
6304b2f4dSMatthias Ringwald[pkg-config](http://www.freedesktop.org/wiki/Software/pkg-config/)
7304b2f4dSMatthias Ringwaldand [libusb-1.0](http://libusb.info) or higher to be
8304b2f4dSMatthias Ringwaldinstalled.
9304b2f4dSMatthias Ringwald
10808a498cSMatthias RingwaldOn a recent Debian-based system, all you need is:
11808a498cSMatthias Ringwald
12ca1e85e2SMatthias Ringwald	sudo apt-get install gcc git cmake ninja-build pkg-config libusb-1.0 portaudio19-dev
13808a498cSMatthias Ringwald
14808a498cSMatthias Ringwald
15ca1e85e2SMatthias RingwaldWhen everything is ready, you compile all examples with make:
16808a498cSMatthias Ringwald
17808a498cSMatthias Ringwald	make
18808a498cSMatthias Ringwald
19ca1e85e2SMatthias Ringwaldor using CMake + Ninja:
20ca1e85e2SMatthias Ringwald
21ca1e85e2SMatthias Ringwald    mkdir build
22ca1e85e2SMatthias Ringwald    cd build
23*8e0bef02SMatthias Ringwald    cmake -G Ninja ..
24ca1e85e2SMatthias Ringwald    ninja
25ca1e85e2SMatthias Ringwald
2676143106SMatthias Ringwald## Environment Setup
2776143106SMatthias Ringwald
2876143106SMatthias Ringwald### Linux
29808a498cSMatthias Ringwald
30ca1e85e2SMatthias RingwaldOn Linux, the USB Bluetooth dongle is usually not accessible to a regular user.
31304b2f4dSMatthias Ringwald
32ca1e85e2SMatthias RingwaldYou can add a udev rule for your dongle to extend access rights to user processes.
33ca1e85e2SMatthias Ringwald
34ca1e85e2SMatthias RingwaldFor this, create `/etc/udev/rules.d/btstack.rules` and add this
35304b2f4dSMatthias Ringwald
36304b2f4dSMatthias Ringwald	# Match all devices from CSR
37304b2f4dSMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0a12", MODE="0666"
38304b2f4dSMatthias Ringwald
39df9a25acSMatthias Ringwald	# Match all devices from Realtek
40df9a25acSMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", MODE="0666"
41df9a25acSMatthias Ringwald
42cbfa934eSMatthias Ringwald	# Match Cypress Semiconductor / Broadcom BCM20702A, e.g. DeLOCK Bluetooth 4.0 dongle
43cbfa934eSMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0a5c", ATTRS{idProduct}=="21e8", MODE="0666"
44304b2f4dSMatthias Ringwald
45304b2f4dSMatthias Ringwald	# Match Asus BT400
46cbfa934eSMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", ATTRS{idProduct}=="17cb", MODE="0666"
47304b2f4dSMatthias Ringwald
48425c3bbdSMatthias Ringwald	# Match Laird BT860 / Cypress Semiconductor CYW20704A2
49cbfa934eSMatthias Ringwald	SUBSYSTEM=="usb", ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="f901", MODE="0666"
50425c3bbdSMatthias Ringwald
5176143106SMatthias Ringwald### macOS
52808a498cSMatthias Ringwald
53808a498cSMatthias RingwaldOn macOS, the OS will try to use a plugged-in Bluetooth Controller if one is available.
54808a498cSMatthias RingwaldIt's best to to tell the OS to always use the internal Bluetooth Contoller.
55808a498cSMatthias Ringwald
56808a498cSMatthias RingwaldFor this, execute:
57304b2f4dSMatthias Ringwald
58304b2f4dSMatthias Ringwald    sudo nvram bluetoothHostControllerSwitchBehavior=never
59304b2f4dSMatthias Ringwald
60c7558746SMatthias Ringwaldand then reboot to activate the change.
61c7558746SMatthias Ringwald
6276143106SMatthias RingwaldNote: if you get this error,
6376143106SMatthias Ringwald
6476143106SMatthias Ringwald	libusb: warning [darwin_open] USBDeviceOpen: another process has device opened for exclusive access
6576143106SMatthias Ringwald	libusb: error [darwin_reset_device] ResetDevice: device not opened for exclusive access
6676143106SMatthias Ringwald
6776143106SMatthias Ringwaldand you didn't start another instance and you didn't assign the USB Controller to a virtual machine,
6876143106SMatthias RingwaldmacOS uses the plugged-in Bluetooth Controller. Please configure NVRAM as explained and try again after a reboot.
6976143106SMatthias Ringwald
70df9a25acSMatthias Ringwald### Broadcom/Cypress/Infineon Controllers
71df9a25acSMatthias RingwaldDuring startup BTstack queries the Controlle for the Local Name, which is set to the Controller type (e.g. 'BCM20702A).
72df9a25acSMatthias RingwaldThe chipset support uses this information to look for a local PatchRAM file of that name and uploads it.
73df9a25acSMatthias Ringwald
74df9a25acSMatthias Ringwald### Realtek Controllers
75df9a25acSMatthias RingwaldDuring startup, the libusb HCI transport implementations reports the USB Vendor/Product ID, which is then forwarded to the Realtek chipset support.
76df9a25acSMatthias RingwaldThe chipset support contains a mapping between USB Product ID and ( Patch, Configuration ) files. If found, these are
77df9a25acSMatthias Ringwalduploaded.
78df9a25acSMatthias Ringwald
7976143106SMatthias Ringwald
80808a498cSMatthias Ringwald## Running the examples
81808a498cSMatthias Ringwald
82808a498cSMatthias RingwaldBTstack's HCI USB transport will try to find a suitable Bluetooth module and use it.
83808a498cSMatthias Ringwald
84808a498cSMatthias RingwaldOn 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.
85808a498cSMatthias Ringwald
86808a498cSMatthias Ringwald	$ ./le_counter
87808a498cSMatthias Ringwald	Packet Log: /tmp/hci_dump.pklg
88808a498cSMatthias Ringwald	BTstack counter 0001
89df9a25acSMatthias Ringwald	Packet Log: /tmp/hci_dump_6.pklg
90df9a25acSMatthias Ringwald	USB device 0x0a12/0x0001, path: 06
91df9a25acSMatthias Ringwald    Local version information:
92df9a25acSMatthias Ringwald    - HCI Version    0x0006
93df9a25acSMatthias Ringwald    - HCI Revision   0x22bb
94df9a25acSMatthias Ringwald    - LMP Version    0x0006
95df9a25acSMatthias Ringwald    - LMP Subversion 0x22bb
96df9a25acSMatthias Ringwald    - Manufacturer 0x000a
97df9a25acSMatthias Ringwald	BTstack up and running on 00:1A:7D:DA:71:01.
98808a498cSMatthias Ringwald
99808a498cSMatthias RingwaldIf 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.
100808a498cSMatthias Ringwald
101df9a25acSMatthias RingwaldExample running le_streamer and le_streamer_client in two processes, using CSR Bluetooth dongles at USB path 6 and 4:
102808a498cSMatthias Ringwald
103808a498cSMatthias Ringwald	./le_streamer -u 6
104808a498cSMatthias Ringwald	Specified USB Path: 06
105808a498cSMatthias Ringwald	Packet Log: /tmp/hci_dump_6.pklg
106df9a25acSMatthias Ringwald	USB device 0x0a12/0x0001, path: 06
107df9a25acSMatthias Ringwald    Local version information:
108df9a25acSMatthias Ringwald    - HCI Version    0x0006
109df9a25acSMatthias Ringwald    - HCI Revision   0x22bb
110df9a25acSMatthias Ringwald    - LMP Version    0x0006
111df9a25acSMatthias Ringwald    - LMP Subversion 0x22bb
112df9a25acSMatthias Ringwald    - Manufacturer 0x000a
113df9a25acSMatthias Ringwald	BTstack up and running on 00:1A:7D:DA:71:01.
114808a498cSMatthias Ringwald	To start the streaming, please run the le_streamer_client example on other device, or use some GATT Explorer, e.g. LightBlue, BLExplr.
115808a498cSMatthias Ringwald
116808a498cSMatthias Ringwald	$ ./le_streamer_client -u 4
117808a498cSMatthias Ringwald	Specified USB Path: 04
118808a498cSMatthias Ringwald	Packet Log: /tmp/hci_dump_4.pklg
119df9a25acSMatthias Ringwald	USB device 0x0a12/0x0001, path: 04
120df9a25acSMatthias Ringwald    Local version information:
121df9a25acSMatthias Ringwald    - HCI Version    0x0006
122df9a25acSMatthias Ringwald    - HCI Revision   0x22bb
123df9a25acSMatthias Ringwald    - LMP Version    0x0006
124df9a25acSMatthias Ringwald    - LMP Subversion 0x22bb
125df9a25acSMatthias Ringwald    - Manufacturer 0x000a
126df9a25acSMatthias Ringwald	BTstack up and running on 00:1A:7D:DA:71:02.
127808a498cSMatthias Ringwald	Start scanning!
128