Lines 172-356
Link Here
|
172 |
<chapter id="bluez"> |
172 |
<chapter id="bluez"> |
173 |
<title>BlueZ - The Bluetooth Stack</title> |
173 |
<title>BlueZ - The Bluetooth Stack</title> |
174 |
<section> |
174 |
<section> |
175 |
<title>Installing BlueZ</title> |
175 |
<title>What is BlueZ?</title> |
176 |
<body> |
176 |
<body> |
177 |
|
177 |
|
178 |
<p> |
178 |
<p> |
179 |
Now that the device is detected by the kernel, we need a layer that lets |
179 |
Now that the device is detected by the kernel, we need a layer that lets |
180 |
applications communicate with the Bluetooth device. BlueZ provides the official |
180 |
applications communicate with the Bluetooth device. BlueZ provides the official |
181 |
Linux Bluetooth stack. The ebuilds that provide what we need are |
181 |
Linux Bluetooth stack. The ebuild that provides what we need is |
182 |
<c>bluez-libs</c> and <c>bluez-utils</c>. Devices that need Broadcom firmware |
182 |
<c>bluez</c>. Devices that need Broadcom firmware |
183 |
files or the like may need <c>bluez-firmware</c>. |
183 |
files or the like may need <c>bluez-firmware</c>. |
184 |
</p> |
184 |
</p> |
|
|
185 |
</body> |
186 |
</section> |
187 |
|
188 |
<section> |
189 |
<title>BlueZ permission control</title> |
190 |
|
191 |
<body> |
192 |
|
193 |
<p> |
194 |
Before installing, it is a good idea to choose how to control users' ability to |
195 |
use bluetooth. |
196 |
</p> |
197 |
|
198 |
<p> |
199 |
There are two methods: |
200 |
</p> |
201 |
|
202 |
<ul> |
203 |
<!-- This needs to be clarified. This is what I think |
204 |
consolekit is, but I don't use it. --> |
205 |
<li>"consolekit": identifies users who are sat in front of the computer, |
206 |
and grants them access;</li> |
207 |
<li>"plugdev": allows members of the plugdev group to use bluetooth</li> |
208 |
</ul> |
209 |
|
210 |
<p> |
211 |
Although the permission policy can be tuned by editing the dbus permission rules |
212 |
for <c>bluez</c>, the <c>consolekit</c> USE flag must be set accordingly |
213 |
</p> |
214 |
|
215 |
<ul> |
216 |
<li><c>consolekit</c> — means the consolekit method is used and requires |
217 |
it to be enabled in some dependencies</li> |
218 |
<li><c>-consolekit</c> — selects the plugdev method, and does not |
219 |
require any consolekit support in dependencies.</li> |
220 |
</ul> |
221 |
|
222 |
</body> |
223 |
</section> |
224 |
|
225 |
<section> |
226 |
<title>Installing bluez</title> |
227 |
|
228 |
<body> |
229 |
|
230 |
<p> |
231 |
Now we can install the package, using the following command. |
232 |
</p> |
185 |
|
233 |
|
186 |
<pre caption="Installing bluez-libs and bluez-utils"> |
234 |
<pre caption="Installing bluez"> |
187 |
# <i>emerge net-wireless/bluez-libs net-wireless/bluez-utils</i> |
235 |
# <i>emerge net-wireless/bluez</i> |
188 |
</pre> |
236 |
</pre> |
189 |
|
237 |
|
|
|
238 |
<p> |
239 |
This ebuild might require certain USE flags to be enabled for other ebuilds: |
240 |
</p> |
241 |
|
242 |
<ul> |
243 |
<li><c>sys-fs/udev</c> must have the <c>extras</c> flag enabled</li> |
244 |
<li>When <c>bluez</c> is built with <c>consolekit</c> enabled (see above), |
245 |
<c>sys-auth/pambase</c> must have it enabled too.</li> |
246 |
</ul> |
247 |
|
248 |
<p> |
249 |
Now the bluetooth stack is completely installed, but you need other tools to do |
250 |
anything useful with it. |
251 |
</p> |
252 |
|
253 |
<p> |
254 |
You can get some tools (including a CLI tool to pair devices) enabling |
255 |
the <c>test-programs</c> USE flag |
256 |
for <c>bluez</c>, which will install some testing utilities. But this is a |
257 |
limited set of tools, mainly intended for testing — you probably want to |
258 |
install an external bluetooth utilities package. |
259 |
</p> |
190 |
</body> |
260 |
</body> |
191 |
</section> |
261 |
</section> |
|
|
262 |
|
192 |
<section> |
263 |
<section> |
193 |
<title>BlueZ configuration and PIN pairing</title> |
264 |
<title>Start BlueZ</title> |
194 |
<body> |
265 |
<body> |
195 |
|
266 |
|
196 |
<p> |
267 |
<p> |
197 |
Now it's time to see if the Bluetooth device is being picked up correctly by the |
268 |
Now it's time to see if the Bluetooth device is being picked up correctly by the |
198 |
system. We start up the required Bluetooth services first. |
269 |
system. We start up the required Bluetooth services first. (It may have been |
|
|
270 |
started when you plugged the device, if it uses some hotpluggable interface |
271 |
(like USB).) |
199 |
</p> |
272 |
</p> |
200 |
|
273 |
|
201 |
<pre caption="Running hciconfig"> |
274 |
<pre caption="Running hciconfig"> |
202 |
<comment>(Start up Bluetooth)</comment> |
275 |
<comment>(Start up Bluetooth)</comment> |
203 |
# <i>/etc/init.d/bluetooth start</i> |
276 |
# <i>/etc/init.d/bluetooth start</i> |
204 |
* Starting Bluetooth ... |
277 |
* Starting Bluetooth ... |
205 |
* Starting hcid ... [ ok ] |
|
|
206 |
* Starting sdpd ... [ ok ] |
207 |
* Starting rfcomm ... [ ok ] |
278 |
* Starting rfcomm ... [ ok ] |
208 |
|
279 |
|
209 |
# <i>hciconfig</i> |
280 |
# <i>hciconfig</i> |
210 |
hci0: Type: USB |
281 |
hci0: Type: USB |
211 |
BD Address: 00:01:02:03:04:05 ACL MTU: 192:8 SCO MTU: 64:8 |
282 |
BD Address: 00:01:02:03:04:05 ACL MTU: 192:8 SCO MTU: 64:8 |
212 |
DOWN |
283 |
UP RUNNING PSCAN |
213 |
RX bytes:131 acl:0 sco:0 events:18 errors:0 |
284 |
RX bytes:131 acl:0 sco:0 events:18 errors:0 |
214 |
TX bytes:565 acl:0 sco:0 commands:17 errors:0 |
285 |
TX bytes:565 acl:0 sco:0 commands:17 errors:0 |
215 |
</pre> |
286 |
</pre> |
216 |
|
287 |
|
217 |
<p> |
288 |
<p>If BlueZ is not started when the device is detected and you use |
218 |
This shows that the Bluetooth device has been recognised. As you might have |
289 |
bluetooth frequenty, you may want to add it to the default runlevel, |
219 |
noticed the device is <e>DOWN</e>. Let's configure it so that we can bring it |
290 |
so that it starts automatically on boot. To do that, use |
220 |
up. The configuration file is at <path>/etc/bluetooth/hcid.conf</path>. The |
291 |
<c>rc-update</c>.</p> |
221 |
required changes to the config file are shown below. For additional details |
|
|
222 |
please refer to <c>man hcid.conf</c>. |
223 |
</p> |
224 |
|
225 |
<pre caption="Editing /etc/bluetooth/hcid.conf"> |
226 |
<comment>(Recommended changes to be made to the file are shown)</comment> |
227 |
|
228 |
# HCId options |
229 |
options { |
230 |
# Automatically initialize new devices |
231 |
autoinit yes; |
232 |
|
233 |
<comment>(Change security to "auto")</comment> |
234 |
# Security Manager mode |
235 |
# none - Security manager disabled |
236 |
# auto - Use local PIN for incoming connections |
237 |
# user - Always ask user for a PIN |
238 |
# |
239 |
security auto; |
240 |
|
241 |
# Pairing mode |
242 |
pairing multi; |
243 |
|
244 |
<comment>(You only need a pin helper if you are using <=bluez-libs-2.x and <=bluez-utils-2.x) |
245 |
(Change pin_helper to use /etc/bluetooth/pin-helper)</comment> |
246 |
# PIN helper |
247 |
pin_helper /etc/bluetooth/pin-helper; |
248 |
} |
249 |
|
250 |
# Default settings for HCI devices |
251 |
device { |
252 |
<comment>(Set your device name here, you can call it anything you want)</comment> |
253 |
# Local device name |
254 |
# %d - device id |
255 |
# %h - host name |
256 |
name "BlueZ at %h (%d)"; |
257 |
|
258 |
# Local device class |
259 |
class 0x3e0100; |
260 |
|
261 |
# Inquiry and Page scan |
262 |
iscan enable; pscan enable; |
263 |
|
264 |
# Default link mode |
265 |
lm accept; |
266 |
|
267 |
# Default link policy |
268 |
lp rswitch,hold,sniff,park; |
269 |
|
270 |
<comment>(Leave as is, if you don't know what exactly these do)</comment> |
271 |
# Authentication and Encryption (Security Mode 3) |
272 |
#auth enable; |
273 |
#encrypt enable; |
274 |
} |
275 |
</pre> |
276 |
|
277 |
<p> |
278 |
After that, we have to configure the Bluetooth device PIN. That will help in |
279 |
pairing this device with another one. |
280 |
</p> |
281 |
|
292 |
|
282 |
<pre caption="Editing /etc/bluetooth/pin"> |
293 |
<pre caption="Automatically start bluetooth on boot"> |
283 |
<comment>(Replace 123456 with your desired pin number.)</comment> |
294 |
<comment>(We can also add it to the default runlevel.)</comment> |
284 |
123456 |
295 |
# <i>rc-update add bluetooth default</i> |
|
|
296 |
* bluetooth added to runlevel default |
285 |
</pre> |
297 |
</pre> |
286 |
|
298 |
|
287 |
<impo> |
|
|
288 |
This number (of your choice) must be the same in all your hosts with Bluetooth |
289 |
devices so they can be paired. This number must also be kept secret since anyone |
290 |
with knowledge of this number can essentially establish connections with your |
291 |
devices. |
292 |
</impo> |
293 |
|
294 |
<note> |
295 |
Beginning with <c>>=bluez-libs-3.x</c> and <c>>=bluez-utils-3.x</c>, pin helpers |
296 |
have been replaced by passkey agents. There are a few different graphical |
297 |
passkey agents available to help manage your PIN, such as <c>bluez-gnome</c> and |
298 |
<c>kdebluetooth</c>. You can also use <c>passkey-agent</c> (found in |
299 |
<c>bluez-utils</c>) from the command line. |
300 |
</note> |
301 |
|
302 |
</body> |
299 |
</body> |
303 |
</section> |
300 |
</section> |
|
|
301 |
|
304 |
<section> |
302 |
<section> |
305 |
<title>Services configuration</title> |
303 |
<title>PIN Pairing</title> |
306 |
<body> |
304 |
<body> |
307 |
|
305 |
|
308 |
<p> |
306 |
<p> |
309 |
Now that we have concluded with the configuration of BlueZ, it's time to restart |
307 |
In <c>=bluez-4</c>, there is no global PIN — when a device is paired you |
310 |
the necessary services. |
308 |
need some bluetooth utility to input a PIN. One such utility |
|
|
309 |
is <c>simple-agent</c>, part of bluez testing utilities (when built |
310 |
with <c>USE="test-programs"</c>). |
311 |
</p> |
311 |
</p> |
312 |
|
312 |
|
313 |
<pre caption="Starting the Bluetooth daemons"> |
313 |
<p> |
314 |
# <i>/etc/init.d/bluetooth restart</i> |
314 |
Before pairing, you must know the bluetooth adapter id |
315 |
<comment>(We can also add it to the default runlevel.)</comment> |
315 |
(run <c>/usr/sbin/hciconfig</c>, if you have several adapters, you need to |
316 |
# <i>rc-update add bluetooth default</i> |
316 |
choose which one you want to pair. |
317 |
* bluetooth added to runlevel default |
317 |
</p> |
318 |
* rc-update complete. |
|
|
319 |
</pre> |
320 |
|
318 |
|
321 |
<p> |
319 |
<p> |
322 |
Let's be sure that the Bluetooth daemons started correctly. If we can see that |
320 |
<!-- Does it work with friendly names too? --> |
323 |
both <c>hcid</c> and <c>sdpd</c> are running, then we configured Bluetooth the |
321 |
You also need the MAC address of the device you want to pair with the |
324 |
right way. After that, we can see if the devices are now up and running with |
322 |
adapter. Some devices have this written in some label, others don't. To find it |
325 |
the configured options. |
323 |
out, make the device visible and run <c>hcitool scan</c> — the result is a |
|
|
324 |
list of devices, with their friendly names and MAC addresses. |
326 |
</p> |
325 |
</p> |
327 |
|
326 |
|
328 |
<pre caption="Checking whether Bluetooth daemons started correctly"> |
327 |
<pre caption="pairing with simple-agent"> |
329 |
<comment>(Check to see if the services are running)</comment> |
328 |
<comment>Find the MAC address:</comment> |
330 |
# <i>ps -ae | grep hcid</i> |
329 |
$ hcitool scan |
331 |
26050 ? 00:00:00 hcid |
330 |
Scanning ... |
332 |
# <i>ps -ae | grep sdpd</i> |
331 |
05:04:03:02:01:00 friendly-name |
333 |
26054 ? 00:00:00 sdpd |
|
|
334 |
|
332 |
|
335 |
# <i>hciconfig -a</i> |
333 |
<comment>Find the adapter ID:</comment> |
|
|
334 |
$ /usr/sbin/hciconfig |
336 |
hci0: Type: USB |
335 |
hci0: Type: USB |
337 |
BD Address: 00:0A:0B:0C:0D:0E ACL MTU: 192:8 SCO MTU: 64:8 |
336 |
BD Address: 00:01:02:03:04:05 ACL MTU: 192:8 SCO MTU: 64:8 |
338 |
UP RUNNING PSCAN ISCAN |
337 |
UP RUNNING PSCAN |
339 |
RX bytes:125 acl:0 sco:0 events:17 errors:0 |
338 |
RX bytes:131 acl:0 sco:0 events:18 errors:0 |
340 |
TX bytes:565 acl:0 sco:0 commands:17 errors:0 |
339 |
TX bytes:565 acl:0 sco:0 commands:17 errors:0 |
341 |
Features: 0xff 0xff 0x0f 0x00 0x00 0x00 0x00 0x00 |
340 |
|
342 |
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 |
341 |
<comment>And then pair the device</comment> |
343 |
Link policy: RSWITCH HOLD SNIFF PARK |
342 |
$ simple-agent hci0 05:04:03:02:01:00 |
344 |
Link mode: SLAVE ACCEPT |
343 |
RequestPinCode (/org/bluez/..../hci0/dev_05_04_03_02_01_00) |
345 |
Name: 'BlueZ at bluehat (0)' |
344 |
Enter PIN Code: 1234 |
346 |
Class: 0x3e0100 |
345 |
<comment>(Now the remote device will ask you for this same PIN.)</comment> |
347 |
Service Classes: Networking, Rendering, Capturing, Object Transfer, |
346 |
Release |
348 |
Audio |
347 |
New device (/org/bluez/..../hci0/dev_05_04_03_02_01_00) |
349 |
Device Class: Computer, Uncategorized |
|
|
350 |
HCI Ver: 1.1 (0x1) HCI Rev: 0x1e7 LMP Ver: 1.1 (0x1) LMP Subver: 0x1e7 |
351 |
Manufacturer: Cambridge Silicon Radio (10) |
352 |
</pre> |
348 |
</pre> |
353 |
|
349 |
|
|
|
350 |
<p> |
351 |
Other bluetooth packages might be able to handle pairing. This involves a tool |
352 |
which initiates pairing or a tool which listens for pairing requests, or both. |
353 |
<!-- Should this be developed to include instructions on how to do it |
354 |
with other tools? --> |
355 |
</p> |
354 |
</body> |
356 |
</body> |
355 |
</section> |
357 |
</section> |
356 |
</chapter> |
358 |
</chapter> |
Lines 367-372
Link Here
|
367 |
the <c>hcitool</c> command for the same. |
369 |
the <c>hcitool</c> command for the same. |
368 |
</p> |
370 |
</p> |
369 |
|
371 |
|
|
|
372 |
<!-- some or ALL? --> |
373 |
<note> |
374 |
Some devices have a visibility setting, which if disabled will prevent |
375 |
your device from detecting them. |
376 |
</note> |
377 |
|
378 |
|
370 |
<pre caption="Checking for local devices"> |
379 |
<pre caption="Checking for local devices"> |
371 |
# <i>hcitool dev</i> |
380 |
# <i>hcitool dev</i> |
372 |
Devices: |
381 |
Devices: |
Lines 391-397
Link Here
|
391 |
</p> |
400 |
</p> |
392 |
|
401 |
|
393 |
<pre caption="Running l2ping"> |
402 |
<pre caption="Running l2ping"> |
394 |
# <i>l2ping 00:0A:0B:0C:0D:0E</i> |
403 |
# <i>l2ping 00:0A:0B:0C:0D:0E -c 4</i> |
395 |
Ping: 00:0A:0B:0C:0D:0E from 00:01:02:03:04:05 (data size 20) ... |
404 |
Ping: 00:0A:0B:0C:0D:0E from 00:01:02:03:04:05 (data size 20) ... |
396 |
20 bytes from 00:0A:0B:0C:0D:0E id 200 time 69.85ms |
405 |
20 bytes from 00:0A:0B:0C:0D:0E id 200 time 69.85ms |
397 |
20 bytes from 00:0A:0B:0C:0D:0E id 201 time 9.97ms |
406 |
20 bytes from 00:0A:0B:0C:0D:0E id 201 time 9.97ms |
Lines 435-440
Link Here
|
435 |
<comment>(Enter the address of the device you want to connect to)</comment> |
444 |
<comment>(Enter the address of the device you want to connect to)</comment> |
436 |
device 00:0A:0B:0C:0D:0E; |
445 |
device 00:0A:0B:0C:0D:0E; |
437 |
|
446 |
|
|
|
447 |
# RFCOMM channel for the connection |
448 |
<comment>(Optional. If not specified, it will use channel 1)</comment> |
449 |
channel 1; |
450 |
|
438 |
} |
451 |
} |
439 |
</pre> |
452 |
</pre> |
440 |
|
453 |
|
Lines 480-485
Link Here
|
480 |
</p> |
493 |
</p> |
481 |
|
494 |
|
482 |
<p> |
495 |
<p> |
|
|
496 |
A bluetooth device may provide several services, on different |
497 |
channels. To connect to those services using rfcomm, you need to find |
498 |
out the right channel first. You can do that using <c>sdptool</c>, |
499 |
part of bluez.<!-- always or depends on some USE? --> |
500 |
</p> |
501 |
|
502 |
<pre caption="Finding the right channel (Bluetooth Service Discovery)"> |
503 |
<comment>(The second parameter is the MAC address of the device you want to connect to)</comment> |
504 |
$ sdptool browse 00:01:02:03:04:05 |
505 |
Browsing 00:01:02:03:04:05 ... |
506 |
Service Name: OBEX Object Push |
507 |
Service RecHandle: 0x10001 |
508 |
Service Class ID List: |
509 |
"OBEX Object Push" (0x1105) |
510 |
Protocol Descriptor List: |
511 |
"L2CAP" (0x0100) |
512 |
"RFCOMM" (0x0003) |
513 |
<comment>(So if you want to connect to OBEX Object Push, use channel 4)</comment> |
514 |
Channel: 4 |
515 |
"OBEX" (0x0008) |
516 |
Language Base Attr List: |
517 |
code_ISO639: 0x656e |
518 |
encoding: 0x6a |
519 |
base_offset: 0x100 |
520 |
Profile Descriptor List: |
521 |
"OBEX Object Push" (0x1105) |
522 |
Version: 0x0100 |
523 |
|
524 |
<comment>(Each service is described in lines like the ones above.)</comment> |
525 |
Service Name: Serial Port |
526 |
Service RecHandle: 0x10002 |
527 |
Service Class ID List: |
528 |
<comment>...</comment> |
529 |
</pre> |
530 |
|
531 |
<p> |
483 |
Each time you call the <c>rfcomm</c> command, you can also specify the physical |
532 |
Each time you call the <c>rfcomm</c> command, you can also specify the physical |
484 |
device you want to use. Below you can see a small example specifiying the |
533 |
device you want to use. Below you can see a small example specifiying the |
485 |
physical device on the above two commands. |
534 |
physical device on the above two commands. |
Lines 574-580
Link Here
|
574 |
<body> |
623 |
<body> |
575 |
|
624 |
|
576 |
<p> |
625 |
<p> |
577 |
KDE makes use of <c>kdebluetooth</c> and provides more utilities than its Gnome |
626 |
KDE makes use of <c>kbluetooth</c> and provides more utilities than its Gnome |
578 |
counterpart as seen below. |
627 |
counterpart as seen below. |
579 |
</p> |
628 |
</p> |
580 |
|
629 |
|
Lines 596-603
Link Here
|
596 |
</li> |
645 |
</li> |
597 |
</ul> |
646 |
</ul> |
598 |
|
647 |
|
599 |
<pre caption="Installing kdebluetooth"> |
648 |
<pre caption="Installing kbluetooth"> |
600 |
# <i>emerge kdebluetooth</i> |
649 |
# <i>emerge kbluetooth</i> |
601 |
</pre> |
650 |
</pre> |
602 |
|
651 |
|
603 |
</body> |
652 |
</body> |
Lines 608-626
Link Here
|
608 |
|
657 |
|
609 |
<ul> |
658 |
<ul> |
610 |
<li> |
659 |
<li> |
611 |
<c>app-mobilephone/obexftp</c>: File transfer over OBEX for mobile phones |
660 |
<c>app-mobilephone/gnokii</c>: Program to access some features |
|
|
661 |
like SMS, calendar and address book. It is also able to set some |
662 |
phone settings, like its clock. Has graphical and commandline |
663 |
interfaces. You will need the <c>bluetooth</c> USE flag set to |
664 |
ensure that <c>gnokii</c> has Bluetooth support. |
612 |
</li> |
665 |
</li> |
613 |
<li> |
666 |
<li> |
614 |
<c>app-mobilephone/bemused</c>: Bemused is a system which allows you to |
667 |
<c>app-mobilephone/obexftp</c>: File transfer over OBEX for mobile phones. |
615 |
control your music collection from your phone, using Bluetooth. |
668 |
You will need the <c>bluetooth</c> USE flag set to ensure |
|
|
669 |
that <c>obexftp</c> has Bluetooth support. |
616 |
</li> |
670 |
</li> |
617 |
<li> |
671 |
<li> |
618 |
<c>app-pda/multisync</c>: Multisync allows you to sync contacts, calendar |
672 |
<c>app-pda/multisync-gui</c>: Multisync allows you to sync contacts, calendar |
619 |
entries and notes from your mobile phone with your computer, over a |
673 |
entries and notes from your mobile phone with your computer, over a |
620 |
Bluetooth connection (amongst other things). It includes such features as |
674 |
Bluetooth connection (amongst other things). It includes such features as |
621 |
backing up this information and restoring it later, and syncing with the |
675 |
backing up this information and restoring it later, and syncing with the |
622 |
Evolution e-mail client. You will need the <c>irmc</c> USE flag set to |
676 |
Evolution e-mail client. |
623 |
ensure that <c>multisync</c> has Bluetooth support. |
|
|
624 |
</li> |
677 |
</li> |
625 |
<li> |
678 |
<li> |
626 |
<c>net-wireless/opd</c> and <c>net-wireless/ussp-push</c> are command line |
679 |
<c>net-wireless/opd</c> and <c>net-wireless/ussp-push</c> are command line |