Linux下Bluetooth編程

來源:互聯網
上載者:User

1.
HCI
層協議概述:

HCI提供一套統一的方法來訪問Bluetooth底層。:

 

 

 

從圖上可以看出,Host Controller Interface(HCI)  就是用來溝通Host和Module。Host通常就是PC, Module則是以各種物理串連形式(USB,serial,pc-card等)串連到PC上的bluetooth
Dongle。

在Host這一端:application,SDP,L2cap等協議都是軟體形式提出的(Bluez中是以kernel層程式)。在Module這一端:Link Manager, BB, 等協議都是硬體中firmware提供的。

HCI則比較特殊,它一部分在軟體中實現,用來給上層協議和程式提供提供者(Bluez中,hci.c
hci_usb.c,hci_sock.c等).另一部分也是在Firmware中實現,用來將軟體部分的指令等用底層協議明白的方式傳遞給底層。

 

居於PC的上層程式與協議和居於Modules的下層協議之間通過HCI溝通,有4種不同形式的傳輸:Commands,
Event, ACL Data, SCO/eSCO Data。

 

1.1.
HCI
Command

HCI Command是Host向Modules發送命令的一種方式。HCI Command Packet結構如下:

OpCode用來唯一標識HCI Command.它由2部分組成,10bit的Opcode
Command. 6bit的Opcode Group。

1.1.1: OpCode Group:

Linux Kernel(BlueZ)中,~/include/net/bluetooth/hci.h中定義了OpCode Group。

#define OGF_LINK_CTL 0x01

#define OGF_LINK_POLICY 0x02  

#define OGF_HOST_CTL 0x03

#define OGF_INFO_PARAM 0x04

#define OGF_STATUS_PARAM 0x05

它們代表了不同的Command Group:

 

OGF_LINK_CTL: Link control,這個Command Group中的Command允許Host控制與其它bluetooth
device 的串連。

OGF_LINK_POLICY :Link Policy。這個Command Group中的Command允許調整Link
Manager control.

OGF_HOST_CTL: Control and Baseband.

 

1.1.2: Opcode
Command:
 

用來在同一個Group內唯一識別Command。~/include/net/bluetooth/hci.h中定義。

 

 

1.2:
HCI Event

Modules向Host發送一些資訊,使用HCI EventEvent Packet結構如下:

HCI Event分3種:Command complete
Event,
Command
States
Event
Command Subsequently Completend.

Command complete
Event
:
如果Host發送的Command可以立刻有結果,則會發送此類Event。也就是說,如果發送的Command只與本地Modules有關,不與remote裝置打交道,則使用Command
complete Event。例如:HCI_Read_Buffer_Size.

Command States
Event
如果Host發送的Command不能立刻得知結果,則發送此類Event。Host發送的Command執行要與Remote裝置打交道,則必然無法立刻得知結果,所以會發送Command
States Event.例如:

HCI Connect。

Command Subsequently Completend:Command延後完成Event。例如:串連已建立。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.