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 Setup 20 21### Linux 22 23On Linux, the USB Bluetooth dongle is usually not accessible to a regular user. You can either: 24- run the examples as root 25- add a udev rule for your dongle to extend access rights to user processes 26 27To add an udev rule, please create `/etc/udev/rules.d/btstack.rules` and add this 28 29 # Match all devices from CSR 30 SUBSYSTEM=="usb", ATTRS{idVendor}=="0a12", MODE="0666" 31 32 # Match DeLOCK Bluetooth 4.0 dongle 33 SUBSYSTEM=="usb", ATTRS{idVendor}=="0a5c", ATTRS{device}=="21e8", MODE="0666" 34 35 # Match Asus BT400 36 SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", ATTRS{device}=="17cb", MODE="0666" 37 38 # Match Laird BT860 / Cypress Semiconductor CYW20704A2 39 SUBSYSTEM=="usb", ATTRS{idVendor}=="04b4", ATTRS{device}=="f901", MODE="0666" 40 41### macOS 42 43On macOS, the OS will try to use a plugged-in Bluetooth Controller if one is available. 44It's best to to tell the OS to always use the internal Bluetooth Contoller. 45 46For this, execute: 47 48 sudo nvram bluetoothHostControllerSwitchBehavior=never 49 50and then reboot to activate the change. 51 52Note: if you get this error, 53 54 libusb: warning [darwin_open] USBDeviceOpen: another process has device opened for exclusive access 55 libusb: error [darwin_reset_device] ResetDevice: device not opened for exclusive access 56 57and you didn't start another instance and you didn't assign the USB Controller to a virtual machine, 58macOS uses the plugged-in Bluetooth Controller. Please configure NVRAM as explained and try again after a reboot. 59 60 61## Running the examples 62 63BTstack's HCI USB transport will try to find a suitable Bluetooth module and use it. 64 65On 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. 66 67 $ ./le_counter 68 Packet Log: /tmp/hci_dump.pklg 69 BTstack counter 0001 70 USB Path: 06 71 BTstack up and running on 00:1A:7D:DA:71:13. 72 73If 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. 74 75Example running le_streamer and le_streamer_client in two processes, using Bluetooth dongles at USB path 6 and 4: 76 77 ./le_streamer -u 6 78 Specified USB Path: 06 79 Packet Log: /tmp/hci_dump_6.pklg 80 USB Path: 06 81 BTstack up and running on 00:1A:7D:DA:71:13. 82 To start the streaming, please run the le_streamer_client example on other device, or use some GATT Explorer, e.g. LightBlue, BLExplr. 83 84 $ ./le_streamer_client -u 4 85 Specified USB Path: 04 86 Packet Log: /tmp/hci_dump_4.pklg 87 USB Path: 04 88 BTstack up and running on 00:1A:7D:DA:71:13. 89 Start scanning! 90