I am developping an Android application that simply connect a phone with a computer.
I had connected two computer with this commands (from comand line/console): Server Listening with this:
sdptool add --channel=15 SP
rfcomm listen rfcomm4 15
Client connect to the server with this:
rfcomm connect rfcomm4 11:11:11:11:11:11 15
This is working ok. (I am using Linux with bluez) it generate a rfcomm4 device in /dev in each machine and i can send and recive thata like a serial port.
The problem comes when i want to do that from an android phone. First of all, in one computer i start the server like this:
sdptool add --channel=15 SP
rfcomm listen rfcomm4 15
Then, in the android app (made with eclipse and android sdk) in a new thread i do:
...
UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
...
BluetoothSocket tmp = remoteDevice.createInsecureRfcommSocketToServiceRecord(MY_UUID);
...
mBluetoothAdapter.cancelDiscovery();
...
mmSocket.connect();
...
But the conection never come up to the server... There are somes variables that i can not understand perfectly. That UUID... what is exaclty? I had read and read and it says that the channel goes in that long String... but... How? How can i put the channel 15 (the one i am listening in the server) in the uuid. other articles says that the uuid is something pre-stablished. and for the rfcomm it go that uuid...
I am not sure if i am doing the rigth aproach to have a simple comunication (like a chat) between a android phone and a linux PC with the bluez 2.25. (this version in the server CAN NOT BE CHANGED). If my aproach is wrong, i will apreciated that someone tell me how to do that.
Thank you very much!
@ashish thanks for reply!!
I do hcidump like you said in the computer, and when i UP the device with hciconfig hci0 up if give me this:
[root@FriendlyARM /]# hcidump -i hci0 -t
HCI sniffer - Bluetooth packet analyzer ver 2.5
device: hci0 snap_len: 1500 filter: 0xffffffff
2000-01-02 05:25:26.472669 < HCI Command: Read Local Supported Features (0x04|0x0003) plen 0
2000-01-02 05:25:26.474602 > HCI Event: Command Complete (0x0e) plen 12
Read Local Supported Features (0x04|0x0003) ncmd 1
status 0x00
Features: 0xff 0xff 0x8d 0xfe 0x9b 0xf9 0x00 0x80
2000-01-02 05:25:26.474711 < HCI Command: Read Local Version Information (0x04|0x0001) plen 0
2000-01-02 05:25:26.476613 > HCI Event: Command Complete (0x0e) plen 12
Read Local Version Information (0x04|0x0001) ncmd 1
status 0x00
HCI Version: 2.0 (0x3) HCI Revision: 0x3000
LMP Version: 2.0 (0x3) LMP Subversion: 0x420b
Manufacturer: Broadcom Corporation (15)
2000-01-02 05:25:26.479366 < HCI Command: Read Buffer Size (0x04|0x0005) plen 0
2000-01-02 05:25:26.481614 > HCI Event: Command Complete (0x0e) plen 11
Read Buffer Size (0x04|0x0005) ncmd 1
status 0x00
ACL MTU 1017:8 SCO MTU 64:0
2000-01-02 05:25:26.481753 < HCI Command: Read BD ADDR (0x04|0x0009) plen 0
2000-01-02 05:25:26.483597 > HCI Event: Command Complete (0x0e) plen 10
Read BD ADDR (0x04|0x0009) ncmd 1
status 0x00 bdaddr 00:1B:10:00:2A:EC
2000-01-02 05:25:26.483719 < HCI Command: Read Class of Device (0x03|0x0023) plen 0
2000-01-02 05:25:26.485593 > HCI Event: Command Complete (0x0e) plen 7
Read Class of Device (0x03|0x0023) ncmd 1
status 0x00 class 0x000000
2000-01-02 05:25:26.485714 < HCI Command: Read Local Name (0x03|0x0014) plen 0
2000-01-02 05:25:26.503570 > HCI Event: Command Complete (0x0e) plen 252
Read Local Name (0x03|0x0014) ncmd 1
status 0x00 name 'BCM2045B'
2000-01-02 05:25:26.503671 < HCI Command: Read Voice Setting (0x03|0x0025) plen 0
2000-01-02 05:25:26.505593 > HCI Event: Command Complete (0x0e) plen 6
Read Voice Setting (0x03|0x0025) ncmd 1
status 0x00 voice setting 0x0060
2000-01-02 05:25:26.505715 < HCI Command: Set Event Filter (0x03|0x0005) plen 1
type 0 condition 0
Clear all filters
2000-01-02 05:25:26.507599 > HCI Event: Command Complete (0x0e) plen 4
Set Event Filter (0x03|0x0005) ncmd 1
status 0x00
2000-01-02 05:25:26.507711 < HCI Command: Write Page Timeout (0x03|0x0018) plen 2
timeout 32768
2000-01-02 05:25:26.509594 > HCI Event: Command Complete (0x0e) plen 4
Write Page Timeout (0x03|0x0018) ncmd 1
status 0x00
2000-01-02 05:25:26.509700 < HCI Command: Write Connection Accept Timeout (0x03|0x0016) plen 2
timeout 32000
2000-01-02 05:25:26.511604 > HCI Event: Command Complete (0x0e) plen 4
Write Connection Accept Timeout (0x03|0x0016) ncmd 1
status 0x00
2000-01-02 05:25:26.512423 < HCI Command: Write Scan Enable (0x03|0x001a) plen 1
enable 3
2000-01-02 05:25:26.514583 > HCI Event: Command Complete (0x0e) plen 4
Write Scan Enable (0x03|0x001a) ncmd 1
status 0x00
Then... When i try the connection (from the android-phone TO the computer with the code that i put up, in the first post, with the generic RFCOMM UUID) the hcidump give me this:
2000-01-02 05:33:50.147694 > HCI Event: Connect Request (0x04) plen 10
bdaddr CC:FE:3C:D3:83:7A class 0x5a020c type ACL
2000-01-02 05:33:50.147884 < HCI Command: Accept Connection Request (0x01|0x0009) plen 7
bdaddr CC:FE:3C:D3:83:7A role 0x01
Role: Slave
2000-01-02 05:33:50.150700 > HCI Event: Command Status (0x0f) plen 4
Accept Connection Request (0x01|0x0009) status 0x00 ncmd 1
2000-01-02 05:33:50.305680 > HCI Event: Connect Complete (0x03) plen 11
status 0x00 handle 11 bdaddr CC:FE:3C:D3:83:7A type ACL encrypt 0x00
2000-01-02 05:33:50.305816 < HCI Command: Read Remote Supported Features (0x01|0x001b) plen 2
handle 11
2000-01-02 05:33:50.307692 > HCI Event: Command Status (0x0f) plen 4
Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
2000-01-02 05:33:50.308689 > HCI Event: Read Remote Supported Features (0x0b) plen 11
status 0x00 handle 11
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
2000-01-02 05:33:50.308865 < HCI Command: Remote Name Request (0x01|0x0019) plen 10
bdaddr CC:FE:3C:D3:83:7A mode 2 clkoffset 0x0000
2000-01-02 05:33:50.311689 > HCI Event: Command Status (0x0f) plen 4
Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
2000-01-02 05:33:50.331693 > HCI Event: Max Slots Change (0x1b) plen 3
handle 11 slots 5
2000-01-02 05:33:50.346676 > ACL data: handle 11 flags 0x02 dlen 10
L2CAP(s): Info req: type 2
2000-01-02 05:33:50.346801 < ACL data: handle 11 flags 0x02 dlen 16
L2CAP(s): Info rsp: type 2 result 0
Extended feature mask 0x00b8
Enhanced Retransmission mode
Streaming mode
FCS Option
Fixed Channels
2000-01-02 05:33:50.352689 > ACL data: handle 11 flags 0x02 dlen 10
L2CAP(s): Info req: type 3
2000-01-02 05:33:50.352797 < ACL data: handle 11 flags 0x02 dlen 20
L2CAP(s): Info rsp: type 3 result 0
Fixed channel list 0x00000002
L2CAP Signalling Channel
2000-01-02 05:33:50.356688 > ACL data: handle 11 flags 0x02 dlen 12
L2CAP(s): Connect req: psm 1 scid 0x0045
2000-01-02 05:33:50.356797 < ACL data: handle 11 flags 0x02 dlen 16
L2CAP(s): Connect rsp: dcid 0x0000 scid 0x0045 result 2 status 0
Connection refused - PSM not supported
2000-01-02 05:33:50.366652 > HCI Event: Remote Name Req Complete (0x07) plen 255
status 0x00 bdaddr CC:FE:3C:D3:83:7A name 'BigDaddy'
2000-01-02 05:33:50.596654 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 11 packets 3
2000-01-02 05:33:54.310068 < HCI Command: Disconnect (0x01|0x0006) plen 3
handle 11 reason 0x13
Reason: Remote User Terminated Connection
2000-01-02 05:33:54.312334 > HCI Event: Command Status (0x0f) plen 4
Disconnect (0x01|0x0006) status 0x00 ncmd 1
2000-01-02 05:33:54.460326 > HCI Event: Disconn Complete (0x05) plen 4
status 0x00 handle 11 reason 0x16
Reason: Connection Terminated by Local Host
But the computer server keep with this:
[root@FriendlyARM /]# sdptool add --channel=15 SP
[root@FriendlyARM /]# rfcomm listen rfcomm4 15
Waiting for connection on channel 15
So the phone-device dows not connect with the computer... (obviosly) but... why? Do you have any idea what i am doing wrong?
My Goal is to get a rfcommX port in each device to change mensage... (Like a chat)