-
Notifications
You must be signed in to change notification settings - Fork 17
/
README
44 lines (34 loc) · 2 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
This is an example Bluetooth Serial Port Profile client and server
application which uses bluez 5.x to exercise the Bluetooth Serial
Port Profile (1.2).
To run as a server, just invoke from the command-line using 'sudo' and
no arguements.
To run as a client, adding any string after the command name will trigger
this mode.
First, the application registers itself to bluez using the ProfileManager1's
RegisterProfile method. It will indicate to bluez what role it's playing
(client or server). If run as server, this will cause the BT controller to
list the Serial Port profile when the bluetoothctl 'show' command is run.
Likewise, from a remote device, the bluetootctl 'info' command will also show
the Serial Port profile listed for the device. When run a client, the Serial
Port profile will not be listed on either side.
When a connection is triggered on the client, bluez will call the NewConnection
method and pass an active Bluetooth RFCOMM socket which then can be used to
write data to the server. On the server side, if the client device is paired,
but trusted, then the default agent needs to be configured (eg. agent on,
default-agent), and if so, a prompt will be displayed asking an admin to
confirm the incoming server request.
If trusted, or an admin confirms the service request, then the server's
NewConnection method will be called with a fd representing the other end of
the BT socket.
In the current implementation, the IO is done very simply with read/write calls.
Also, the server explicitly sets the socket to blocking mode to simplify the
code. When boths sides complete their IO, the application exits.
To trigger the connection from client to server, the following dbus-send
command can be used:
$ sudo dbus-send --system --print-reply --dest=org.bluez \
/org/bluez/hciX/dev_XX_YY_ZZ_AA_BB_CC \
org.bluez.Device1.ConnectProfile \
string:"00001101-0000-1000-8000-00805f9b34fb"
* hciX - replace X with controller index (eg. hci0)
* dev_XX_YY_ZZ_AA_BB_CC - replace with server's BT control MAC address