| 1 | // Package gatt provides a Bluetooth Low Energy gatt implementation. |
| 2 | // |
| 3 | // Gatt (Generic Attribute Profile) is the protocol used to write |
| 4 | // BLE peripherals (servers) and centrals (clients). |
| 5 | // |
| 6 | // STATUS |
| 7 | // |
| 8 | // This package is a work in progress. The API will change. |
| 9 | // |
| 10 | // As a peripheral, you can create services, characteristics, and descriptors, |
| 11 | // advertise, accept connections, and handle requests. |
| 12 | // As a central, you can scan, connect, discover services, and make requests. |
| 13 | // |
| 14 | // SETUP |
| 15 | // |
| 16 | // gatt supports both Linux and OS X. |
| 17 | // |
| 18 | // On Linux: |
| 19 | // To gain complete and exclusive control of the HCI device, gatt uses |
| 20 | // HCI_CHANNEL_USER (introduced in Linux v3.14) instead of HCI_CHANNEL_RAW. |
| 21 | // Those who must use an older kernel may patch in these relevant commits |
| 22 | // from Marcel Holtmann: |
| 23 | // |
| 24 | // Bluetooth: Introduce new HCI socket channel for user operation |
| 25 | // Bluetooth: Introduce user channel flag for HCI devices |
| 26 | // Bluetooth: Refactor raw socket filter into more readable code |
| 27 | // |
| 28 | // Note that because gatt uses HCI_CHANNEL_USER, once gatt has opened the |
| 29 | // device no other program may access it. |
| 30 | // |
| 31 | // Before starting a gatt program, make sure that your BLE device is down: |
| 32 | // |
| 33 | // sudo hciconfig |
| 34 | // sudo hciconfig hci0 down # or whatever hci device you want to use |
| 35 | // |
| 36 | // If you have BlueZ 5.14+ (or aren't sure), stop the built-in |
| 37 | // bluetooth server, which interferes with gatt, e.g.: |
| 38 | // |
| 39 | // sudo service bluetooth stop |
| 40 | // |
| 41 | // Because gatt programs administer network devices, they must |
| 42 | // either be run as root, or be granted appropriate capabilities: |
| 43 | // |
| 44 | // sudo <executable> |
| 45 | // # OR |
| 46 | // sudo setcap 'cap_net_raw,cap_net_admin=eip' <executable> |
| 47 | // <executable> |
| 48 | // |
| 49 | // USAGE |
| 50 | // |
| 51 | // # Start a simple server. |
| 52 | // sudo go run example/server.go |
| 53 | // |
| 54 | // # Discover surrounding peripherals. |
| 55 | // sudo go run example/discoverer.go |
| 56 | // |
| 57 | // # Connect to and explorer a peripheral device. |
| 58 | // sudo go run example/explorer.go <peripheral ID> |
| 59 | // |
| 60 | // See the server.go, discoverer.go, and explorer.go in the examples/ |
| 61 | // directory for writing server or client programs that run on Linux |
| 62 | // and OS X. |
| 63 | // |
| 64 | // Users, especially on Linux platforms, seeking finer-grained control |
| 65 | // over the devices can see the examples/server_lnx.go for the usage |
| 66 | // of Option, which are platform specific. |
| 67 | // |
| 68 | // See the rest of the docs for other options and finer-grained control. |
| 69 | // |
| 70 | // Note that some BLE central devices, particularly iOS, may aggressively |
| 71 | // cache results from previous connections. If you change your services or |
| 72 | // characteristics, you may need to reboot the other device to pick up the |
| 73 | // changes. This is a common source of confusion and apparent bugs. For an |
| 74 | // OS X central, see http://stackoverflow.com/questions/20553957. |
| 75 | // |
| 76 | // |
| 77 | // REFERENCES |
| 78 | // |
| 79 | // gatt started life as a port of bleno, to which it is indebted: |
| 80 | // https://github.com/sandeepmistry/bleno. If you are having |
| 81 | // problems with gatt, particularly around installation, issues |
| 82 | // filed with bleno might also be helpful references. |
| 83 | // |
| 84 | // To try out your GATT server, it is useful to experiment with a |
| 85 | // generic BLE client. LightBlue is a good choice. It is available |
| 86 | // free for both iOS and OS X. |
| 87 | // |
| 88 | package gatt |