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 12808a498cSMatthias Ringwald apt-get install gcc git libusb-1.0 pkg-config 13808a498cSMatthias Ringwald 14808a498cSMatthias Ringwald 15808a498cSMatthias RingwaldWhen everything is ready, you compile all examples with: 16808a498cSMatthias Ringwald 17808a498cSMatthias Ringwald make 18808a498cSMatthias Ringwald 1976143106SMatthias Ringwald## Environment Setup 2076143106SMatthias Ringwald 2176143106SMatthias Ringwald### Linux 22808a498cSMatthias Ringwald 23808a498cSMatthias RingwaldOn Linux, the USB Bluetooth dongle is usually not accessible to a regular user. You can either: 24304b2f4dSMatthias Ringwald- run the examples as root 25304b2f4dSMatthias Ringwald- add a udev rule for your dongle to extend access rights to user processes 26304b2f4dSMatthias Ringwald 27304b2f4dSMatthias RingwaldTo add an udev rule, please create `/etc/udev/rules.d/btstack.rules` and add this 28304b2f4dSMatthias Ringwald 29304b2f4dSMatthias Ringwald # Match all devices from CSR 30304b2f4dSMatthias Ringwald SUBSYSTEM=="usb", ATTRS{idVendor}=="0a12", MODE="0666" 31304b2f4dSMatthias Ringwald 32*cbfa934eSMatthias Ringwald # Match Cypress Semiconductor / Broadcom BCM20702A, e.g. DeLOCK Bluetooth 4.0 dongle 33*cbfa934eSMatthias Ringwald SUBSYSTEM=="usb", ATTRS{idVendor}=="0a5c", ATTRS{idProduct}=="21e8", MODE="0666" 34304b2f4dSMatthias Ringwald 35304b2f4dSMatthias Ringwald # Match Asus BT400 36*cbfa934eSMatthias Ringwald SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", ATTRS{idProduct}=="17cb", MODE="0666" 37304b2f4dSMatthias Ringwald 38425c3bbdSMatthias Ringwald # Match Laird BT860 / Cypress Semiconductor CYW20704A2 39*cbfa934eSMatthias Ringwald SUBSYSTEM=="usb", ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="f901", MODE="0666" 40425c3bbdSMatthias Ringwald 4176143106SMatthias Ringwald### macOS 42808a498cSMatthias Ringwald 43808a498cSMatthias RingwaldOn macOS, the OS will try to use a plugged-in Bluetooth Controller if one is available. 44808a498cSMatthias RingwaldIt's best to to tell the OS to always use the internal Bluetooth Contoller. 45808a498cSMatthias Ringwald 46808a498cSMatthias RingwaldFor this, execute: 47304b2f4dSMatthias Ringwald 48304b2f4dSMatthias Ringwald sudo nvram bluetoothHostControllerSwitchBehavior=never 49304b2f4dSMatthias Ringwald 50c7558746SMatthias Ringwaldand then reboot to activate the change. 51c7558746SMatthias Ringwald 5276143106SMatthias RingwaldNote: if you get this error, 5376143106SMatthias Ringwald 5476143106SMatthias Ringwald libusb: warning [darwin_open] USBDeviceOpen: another process has device opened for exclusive access 5576143106SMatthias Ringwald libusb: error [darwin_reset_device] ResetDevice: device not opened for exclusive access 5676143106SMatthias Ringwald 5776143106SMatthias Ringwaldand you didn't start another instance and you didn't assign the USB Controller to a virtual machine, 5876143106SMatthias RingwaldmacOS uses the plugged-in Bluetooth Controller. Please configure NVRAM as explained and try again after a reboot. 5976143106SMatthias Ringwald 6076143106SMatthias Ringwald 61808a498cSMatthias Ringwald## Running the examples 62808a498cSMatthias Ringwald 63808a498cSMatthias RingwaldBTstack's HCI USB transport will try to find a suitable Bluetooth module and use it. 64808a498cSMatthias Ringwald 65808a498cSMatthias 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. 66808a498cSMatthias Ringwald 67808a498cSMatthias Ringwald $ ./le_counter 68808a498cSMatthias Ringwald Packet Log: /tmp/hci_dump.pklg 69808a498cSMatthias Ringwald BTstack counter 0001 70808a498cSMatthias Ringwald USB Path: 06 71808a498cSMatthias Ringwald BTstack up and running on 00:1A:7D:DA:71:13. 72808a498cSMatthias Ringwald 73808a498cSMatthias 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. 74808a498cSMatthias Ringwald 75808a498cSMatthias RingwaldExample running le_streamer and le_streamer_client in two processes, using Bluetooth dongles at USB path 6 and 4: 76808a498cSMatthias Ringwald 77808a498cSMatthias Ringwald ./le_streamer -u 6 78808a498cSMatthias Ringwald Specified USB Path: 06 79808a498cSMatthias Ringwald Packet Log: /tmp/hci_dump_6.pklg 80808a498cSMatthias Ringwald USB Path: 06 81808a498cSMatthias Ringwald BTstack up and running on 00:1A:7D:DA:71:13. 82808a498cSMatthias Ringwald To start the streaming, please run the le_streamer_client example on other device, or use some GATT Explorer, e.g. LightBlue, BLExplr. 83808a498cSMatthias Ringwald 84808a498cSMatthias Ringwald $ ./le_streamer_client -u 4 85808a498cSMatthias Ringwald Specified USB Path: 04 86808a498cSMatthias Ringwald Packet Log: /tmp/hci_dump_4.pklg 87808a498cSMatthias Ringwald USB Path: 04 88808a498cSMatthias Ringwald BTstack up and running on 00:1A:7D:DA:71:13. 89808a498cSMatthias Ringwald Start scanning! 90