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 all devices from Realtek 33 SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", MODE="0666" 34 35 # Match Cypress Semiconductor / Broadcom BCM20702A, e.g. DeLOCK Bluetooth 4.0 dongle 36 SUBSYSTEM=="usb", ATTRS{idVendor}=="0a5c", ATTRS{idProduct}=="21e8", MODE="0666" 37 38 # Match Asus BT400 39 SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", ATTRS{idProduct}=="17cb", MODE="0666" 40 41 # Match Laird BT860 / Cypress Semiconductor CYW20704A2 42 SUBSYSTEM=="usb", ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="f901", MODE="0666" 43 44### macOS 45 46On macOS, the OS will try to use a plugged-in Bluetooth Controller if one is available. 47It's best to to tell the OS to always use the internal Bluetooth Contoller. 48 49For this, execute: 50 51 sudo nvram bluetoothHostControllerSwitchBehavior=never 52 53and then reboot to activate the change. 54 55Note: if you get this error, 56 57 libusb: warning [darwin_open] USBDeviceOpen: another process has device opened for exclusive access 58 libusb: error [darwin_reset_device] ResetDevice: device not opened for exclusive access 59 60and you didn't start another instance and you didn't assign the USB Controller to a virtual machine, 61macOS uses the plugged-in Bluetooth Controller. Please configure NVRAM as explained and try again after a reboot. 62 63### Broadcom/Cypress/Infineon Controllers 64During startup BTstack queries the Controlle for the Local Name, which is set to the Controller type (e.g. 'BCM20702A). 65The chipset support uses this information to look for a local PatchRAM file of that name and uploads it. 66 67### Realtek Controllers 68During startup, the libusb HCI transport implementations reports the USB Vendor/Product ID, which is then forwarded to the Realtek chipset support. 69The chipset support contains a mapping between USB Product ID and ( Patch, Configuration ) files. If found, these are 70uploaded. 71 72 73## Running the examples 74 75BTstack's HCI USB transport will try to find a suitable Bluetooth module and use it. 76 77On 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. 78 79 $ ./le_counter 80 Packet Log: /tmp/hci_dump.pklg 81 BTstack counter 0001 82 Packet Log: /tmp/hci_dump_6.pklg 83 USB device 0x0a12/0x0001, path: 06 84 Local version information: 85 - HCI Version 0x0006 86 - HCI Revision 0x22bb 87 - LMP Version 0x0006 88 - LMP Subversion 0x22bb 89 - Manufacturer 0x000a 90 BTstack up and running on 00:1A:7D:DA:71:01. 91 92If 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. 93 94Example running le_streamer and le_streamer_client in two processes, using CSR Bluetooth dongles at USB path 6 and 4: 95 96 ./le_streamer -u 6 97 Specified USB Path: 06 98 Packet Log: /tmp/hci_dump_6.pklg 99 USB device 0x0a12/0x0001, path: 06 100 Local version information: 101 - HCI Version 0x0006 102 - HCI Revision 0x22bb 103 - LMP Version 0x0006 104 - LMP Subversion 0x22bb 105 - Manufacturer 0x000a 106 BTstack up and running on 00:1A:7D:DA:71:01. 107 To start the streaming, please run the le_streamer_client example on other device, or use some GATT Explorer, e.g. LightBlue, BLExplr. 108 109 $ ./le_streamer_client -u 4 110 Specified USB Path: 04 111 Packet Log: /tmp/hci_dump_4.pklg 112 USB device 0x0a12/0x0001, path: 04 113 Local version information: 114 - HCI Version 0x0006 115 - HCI Revision 0x22bb 116 - LMP Version 0x0006 117 - LMP Subversion 0x22bb 118 - Manufacturer 0x000a 119 BTstack up and running on 00:1A:7D:DA:71:02. 120 Start scanning! 121