Link Control Commands (OGF = 0x01) |
No |
Command Name |
OpCode |
Description |
1 |
Inquiry |
0x0001 |
Command used to enter Inquiry mode where
it discovers other Bluetooth devices. |
2 |
Inquiry_Cancel |
0x0002 |
Command to cancel the Inquiry mode in
which the Bluetooth device is in. |
3 |
Periodic_Inquiry_Mode |
0x0003 |
Command to set the device to enter
Inquiry modes periodically according to the time interval set. |
4 |
Exit_Periodic_Inquiry_Mode |
0x0004 |
Command to exit the periodic Inquiry mode |
5 |
Create_Connection |
0x0005 |
Command to create an ACL connection to
the device specified by the BD_ADDR in the parameters. |
6 |
Disconnect |
0x0006 |
Command to terminate the existing
connection to a device |
7 |
Add_SCO_Connection |
0x0007 |
Create an SCO connection defined by the
connection handle parameters. |
8 |
Accept_Connection_Request |
0x0009 |
Command to accept a new connection
request |
9 |
Reject_Connection_Request |
0x000A |
Command to reject a new connection
request |
10 |
Link_Key_Request_Reply |
0x000B |
Reply command to a link key request event
sent from controller to the host |
11 |
Link_Key_Request_Negative_Reply |
0x000C |
Reply command to a link key request event
from the controller to the host if there is no link key associated
with the connection. |
12 |
PIN_Code_Request_Reply |
0x000D |
Reply command to a PIN code request event
sent from a controller to the host. |
13 |
PIN_Code_Request_Negative_Reply |
0x000E |
Reply command to a PIN code request event
sent from the controller to the host if there is no PIN associated
with the connection. |
14 |
Change_Connection_Packet_Type |
0x000F |
Command to change the type of packets to
be sent for an existing connection. |
15 |
Authentication_Requested |
0x0011 |
Command to establish authentication
between two devices specified by the connection handle. |
16 |
Set_Connection_Encryption |
0x0013 |
Command to enable or disable the link
level encryption. |
17 |
Change_Connection_Link_Key |
0x0015 |
Command to force the change of a link key
to a new one between two connected devices. |
18 |
Master_Link_Key |
0x0017 |
Command to force two devices to use the
master’s link key temporarily. |
19 |
Remote_Name_Request |
0x0019 |
Command to determine the user friendly
name of the connected device. |
20 |
Read_Remote_Supported_Features |
0x001B |
Command to determine the features
supported by the connected device. |
21 |
Read_Remote_Version_Information |
0x001D |
Command to determine the version
information of the connected device. |
22 |
Read_Clock_Offset |
0x001F |
Command to read the clock offset of the
remote device. |
HCI Policy Command (OGF=0x02) |
1 |
Hold_Mode |
0x0001 |
Command to place the current or remote
device into the Hold mode state. |
2 |
Sniff_Mode |
0x0003 |
Command to place the current or remote
device into the Sniff mode state. |
3 |
Exit_Sniff_Mode |
0x0004 |
Command to exit the current or remote
device from the Sniff mode state. |
4 |
Park_Mode |
0x0005 |
Command to place the current or remote
device into the Park mode state. |
5 |
Exit_Park_Mode |
0x0006 |
Command to exit the current or remote
device from the Park mode state. |
6 |
QoS_Setup |
0x0007 |
Command to setup the Quality of Service
parameters of the device. |
7 |
Role_Discovery |
0x0009 |
Command to determine the role of the
device for a particular connection. |
8 |
Switch_Role |
0x000B |
Command to allow the device to switch
roles for a particular connection. |
9 |
Read_Link_Policy_Settings |
0x000C |
Command to determine the link policy that
the LM can use to establish connections. |
10 |
Write_Link_Policy_Settings |
0x000D |
Command to set the link policy that the
LM can use for a particular connection. |
Host Controller and Baseband Commands (OGF=0x03) |
1 |
Set_Event_Mask |
0x0001 |
Command to set which events are generated
by the HCI for the host. |
2 |
Reset |
0x0003 |
Command to reset the host controller,
link manager and the radio module. |
3 |
Set_Event_Filter |
0x0005 |
Command used by host to set the different
types of event filters that the host needs to receive. |
4 |
Flush |
0x0008 |
Command used to flush all pending data
packets for transmission for a particular connection handle. |
5 |
Read_PIN_Type |
0x0009 |
Command used by host to determine if the
link manager assumes that the host requires a variable PIN type or
fixed PIN code. PIN is used during pairing. |
6 |
Write_PIN_Type |
0x000A |
Command used by host to write to the host
controller on the PIN type supported by the host. |
7 |
Create_New_Unit_Key |
0x000B |
Command used to create a new unit key. |
8 |
Read_Stored_Link_Key |
0x000D |
Command to read the link key stored in
the host controller. |
9 |
Write_Stored_Link_Key |
0x0011 |
Command to write the link key to the host
controller. |
10 |
Delete_Stored_Link_Key |
0x0012 |
Command to delete a stored link key in
the host controller. |
11 |
Change_Local_Name |
0x0013 |
Command to modify the user friendly name
of the device. |
12 |
Read_Local_Name |
0x0014 |
Command to read the user friendly name of
the device. |
13 |
Read_Connection_Accept_Timeout |
0x0015 |
Command to determine the timeout session
before the host denies and rejects a new connection request. |
14 |
Write_Connection_Accept_Timeout |
0x0016 |
Command to set the timeout session before
a device can deny or reject a connection request. |
15 |
Read_Page_Timeout |
0x0017 |
Command to read the timeout value where a
device will wait for a connection acceptance before sending a
connection failure is returned. |
16 |
Write_Page_Timeout |
0x0018 |
Command to write the timeout value where
a device will wait for a connection acceptance before sending a
connection failure is returned. |
17 |
Read_Scan_Enable |
0x0019 |
Command to read the status of the
Scan_Enable configuration. |
18 |
Write_Scan_Enable |
0x001A |
Command to set the status of the
Scan_Enable configuration. |
19 |
Read_Page_Scan_Activity |
0x001B |
Command to read the value of the
Page_Scan_Interval and Page_Scan_Window configurations. |
20 |
Write_Page_Scan_Activity |
0x001C |
Command to write the value of the
Page_Scan_Interval and Page_Scan_Window configurations. |
21 |
Read_Inquiry_Scan_Activity |
0x001D |
Command to read the value of the
Inquiry_Scan_Interval and Inquiry_Scan_Window configurations. |
22 |
Write_Inquiry_Scan_Activity |
0x001E |
Command to set the value of the
Inquiry_Scan_Interval and Inquiry_Scan_Window configurations. |
23 |
Read_Authentication_Enable |
0x001F |
Command to read the Authentication_Enable
parameter. |
24 |
Write_Authentication_Enable |
0x0020 |
Command to set the Authentication_Enable
parameter. |
25 |
Read_Encryption_Mode |
0x0021 |
Command to read the Encryption_Mode
parameter. |
26 |
Write_Encryption_Mode |
0x0022 |
Command to write the Encryption_Mode
parameter. |
27 |
Read_Class_Of_Device |
0x0023 |
Command to read the Class_Of_Device
parameter. |
28 |
Write_Class_Of_Device |
0x0024 |
Command to set the Class_Of_Device
parameter. |
29 |
Read_Voice_Setting |
0x0025 |
Command to read the Voice_Setting
parameter. Used for voice connections. |
30 |
Write_Voice_Setting |
0x0026 |
Command to set the Voice_Setting
parameter. Used for voice connections. |
31 |
Read_Automatic_Flush_Timeout |
0x0027 |
Command to read the Flush_Timeout
parameter. Used for ACL connections only. |
32 |
Write_Automatic_Flush_Timeout |
0x0028 |
Command to set the Flush_Timeout
parameter. Used for ACL connections only. |
33 |
Read_Num_Broadcast_Retransmissions |
0x0029 |
Command to read the number of time a
broadcast message is retransmitted. |
34 |
Write_Num_Broadcast_Retransmissions |
0x002A |
Command to set the number of time a
broadcast message is retransmitted. |
35 |
Read_Hold_Mode_Activity |
0x002B |
Command to set the Hold_Mode activity to
instruct the device to perform an activity during hold mode. |
36 |
Write_Hold_Mode_Activity |
0x002C |
Command to set the Hold_Mode_Activity
parameter. |
37 |
Read_Transmit_Power_Level |
0x002D |
Command to read the power level required
for transmission for a connection handle. |
38 |
Read_SCO_Flow_Control_Enable |
0x002E |
Command to check the current status of
the flow control for the SCO connection. |
39 |
Write_SCO_Flow_Control_Enable |
0x002F |
Command to set the status of the flow
control for a connection handle. |
40 |
Set_Host_Controller_To_Host_Flow_Control |
0x0031 |
Command to set the flow control from the
host controller to host in on or off state. |
41 |
Host_Buffer_Size |
0x0033 |
Command set by host to inform the host
controller of the buffer size of the host for ACL and SCO connections. |
42 |
Host_Number_Of_Completed_Packets |
0x0035 |
Command set from host to host controller
when it is ready to receive more data packets. |
43 |
Read_Link_Supervision_Timeout |
0x0036 |
Command to read the timeout for
monitoring link losses. |
44 |
Write_Link_Supervision_Timeout |
0x0037 |
Command to set the timeout for monitoring
link losses. |
45 |
Read_Number_Of_Supported_IAC |
0x0038 |
Command to read the number of IACs that
the device can listen on during Inquiry access. |
46 |
Read_Current_IAC_LAP |
0x0039 |
Command to read the LAP for the current
IAC. |
47 |
Write_Current_IAC_LAP |
0x003A |
Command to set the LAP for the current
IAC. |
48 |
Read_Page_Scan_Period_Mode |
0x003B |
Command to read the timeout session of a
page scan. |
49 |
Write_Page_Scan_Period_Mode |
0x003C |
Command to set the timeout session of a
page scan. |
50 |
Read_Page_Scan_Mode |
0x003D |
Command to read the default Page scan
mode. |
51 |
Write_Page_Scan_Mode |
0x003E |
Command to set the default page scan
mode. |
Hi!
Do you know any way to write an application on my SDK 1.6 phone which could measure the lq(link quality) level between my phone and a bluetooth transmitter?
By the way how could I implement these hci commands written here in my code? Is there a .jar or something I coul put into my build path?
Thanks in advice,
Peter
Hi Peter,
Yes, it is possible. You need to directly interface the bluetooth chip, via serial connection.
Then you need a parser , very much like the AT modem parser.
Hope this helps,
Radu
Thank you for the answer, but it’s not all clear.
So you are saying, that there is not an API or something I could use, I should implement a brand new method based on the concept of linq quality, but I don’t understand, why do I need a serial connection to the BT chip. Isn’t it enough to be connected to the device, like when I want to get the RSSI value of a connection?
And do I need the parser to be aware of the results I get from the chip? (for example I send it 00110 and I recieve back 01110 then the parser would analyze the result and add the “1 difference” to the lq calculator I also need to implement)?
I’ve read on a forum about a method named getLinkQuality() included in the Bluez API, have you heard about this possibility?
The problem was that I couldn’t use the API like it was a folder(not a .jar or something like that) full of program files written in C language.
And one last question: how could I implement these hci commands written in this article in my code?
I’m really sorry for asking so much, I’m new at Android programming, and I have to finish my code until 8th of december, and the only thing missing is this LQ level I need to get.
Any hints would really be appreciated.
Peter
And by the way this BT chip I want to communicate with is a mobile phone.
Hello Peter,
Actually I was referring to a lower programming level. I pointed to that direction because you’ve asked “how could I implement these hci commands written here in my code?”
To get an idea, first see this diagram:
http://www.ibm.com/developerworks/wireless/library/wi-boogie1/bt_protocol_stack_c.gif
As you can see, the HCI layer is at the bottom. It is used to directly interface the radio BT chip, inside the mobile phone. You no longer use high level APIs (like DiscoverBTDevices, L2CAPConnect, etc), instead you implement EVERYTHING by yourself, by sending these HCI commands over a serial link to the BT Radio Chip (which is nothing else but a micro-processor).
The advantage over this effort, is that you have complete control.
Should I have some time for this, I will write a sample code.
Really thanks for the idea, but do you know about a way that I could reach these functions via high level API-s?
Android NDK for example is a new thing for me, but it can use native codes to build a project, and I saw codes written in C I could use. I think I’ll try that first.
Regards,
Peter
Ok, than the way to go is to stick to BlueZ and try compiling a native code sample that gives you the RSSI. HAve a look here, for a start: http://www.pocketmagic.net/?p=1332
Well, I must say, you are a huge help for me…wonderful page you linked. I really, really thank you, now I can continue working on my project. I hope I will be able to finish it, but if not, I know where to find answers.
Thank you a lot again.
Peter
Glad this helped. For any questions, just drop a line here. Good luck!
Hi!
I’m really sorry to write again, but could you tell me how to modificate/use this code (http://android.git.kernel.org/?p=platform/external/bluez.git;a=commitdiff;h=611c26d196ef15425ae92dec9f3cdf92bbbe489a) to give a variable in my java code the hci_read_link_quality value?
On this site they describe the Android.mk file and there is the code itself, but I can’t find out how to gain the value itself.
Regards,
Peter
Hi Peter,
Well the modifications require some time, so instead of doing them myself, I will guide you to the right direction:
http://www.pocketmagic.net/?p=1398
See Bluetooth on Android using BlueZ and JNI for an example on how to use BlueZ with your code. There are step by step examples that should help you.
Once you get that working, it will be easier for you to integrate the RSSI code.
Do you have experience with C coding? You will need it.
Well I have only experience with C++ coding, but that will do. Thanks again, this will probably take some time. I’ll let you know when I’m done;)
Ok, good luck with that!