HCI 初始化流程
1、HCI_Reset 初始化的第一步
2、确定bt chip支持的command、feature、地址等
HCI_Read_Local_Version_Information
HCI_Read_Local_Supported_Commands
HCI_Read_Local_Supported_Features
HCI_Read_Local_Extended_Features
HCI_Read_BD_ADDR
3、设置接收哪些event
HCI_Set_Event_Mask
4、如果支持controller to host的流控(一般不用)
HCI_Set_Controller_To_Host_Flow_Control
HCI_Host_Buffer_Size
5、如果支持host to controller的流控(一般不用)
HCI_Read_Buffer_Size
6、设置Link key相关(一般用HCI_Delete_Stored_Link_Key,不用bt chip存储link key)
HCI_Read_Stored_Link_Key
HCI_Write_Stored_Link_Key
HCI_Delete_Stored_Link_Key
7、设置本地设备名
HCI_Write_Local_Name
设置SCO的配置
HCI_Write_Voice_Setting
8、设置cod
HCI_Write_Class_of_Device
9、设置IAC(一般不用)
HCI_Write_Current_IAC_LAP
10、设置是否可被搜索是否可被连接
HCI_Write_Scan_Enable
11、设置搜索相关
HCI_Write_Inquiry_Scan_Type 设置隔行/逐行扫描
HCI_Write_Inquiry_Mode 设置标准搜索/RSSI搜索/RSSI和eir搜索
HCI_Write_Extended_Inquiry_Response 设置eir
12、设置page相关
HCI_Write_Page_Timeout 设置page timeout
HCI_Write_Page_Scan_Type 设置逐行/隔行 page scan
13、设置是否需要认证
HCI_Write_Authentication_Enable 设置authentication enable
HCI_Write_Simple_Pairing_Mode 设置是否支持bt2.1
HCI_Write_Secure_Connections_Host_Support 设置是否支持secure connection
android bluedroid hci 指令定义:
https://cs.android.com/android/platform/superproject/+/master:packages/modules/Bluetooth/system/stack/include/
hcidefs.h;l=267?q=int%20hci_read_bd_addr&ss=android
#define HCI_READ_BD_ADDR (0x0009 | HCI_GRP_INFORMATIONAL_PARAMS)
https://cs.android.com/android/kernel/superproject/+/common-android-mainline:common/net/bluetooth/hci_sync.c;l=3296?q=int%20hci_read_bd_addr&ss=android
/* Read BD Address */
static int hci_read_bd_addr_sync(struct hci_dev *hdev)
{
return __hci_cmd_sync_status(hdev, HCI_OP_READ_BD_ADDR,
0, NULL, HCI_CMD_TIMEOUT);
}
bluez hci 指令定义
https://android.googlesource.com/platform/external/bluetooth/bluez/+/master/lib/bluetooth/hci_lib.h
int hci_read_bd_addr(int dd, bdaddr_t *bdaddr, int to);
常见的Android支持的HCI 指令集:
HCI UART: HCI Packet Type: Event Packet HCI: HCI Event Event: HCI_Command_Complete Total Length: 68 Num_HCI_Command_Packets: 1 Command_Opcode Opcode: 0x1002 Opcode Group (OGF): Informational Parameters command Command: HCI_Read_Local_Supported_Commands Return_Parameter(s) Status: Success HCI_Create_Connection_Cancel : Supported HCI_Disconnect: Supported HCI_Create_Connection: Supported HCI_Exit_Periodic_Inquiry_Mode: Supported HCI_Periodic_Inquiry_Mode: Supported HCI_Inquiry_Cancel: Supported HCI_Inquiry: Supported HCI_Authentication_Requested : Supported HCI_Change_Connection_Packet_Type: Supported HCI_PIN_Code_Request_Negative_Reply: Supported HCI_PIN_Code_Request_Reply: Supported HCI_Link_Key_Request_Negative_Reply: Supported HCI_Link_Key_Request_Reply: Supported HCI_Reject_Connection_Request: Supported HCI_Accept_Connection_Request: Supported HCI_Read_Remote_Version_Information: Supported HCI_Read_Remote_Extended_Features: Supported HCI_Read_Remote_Supported_Features: Supported HCI_Remote_Name_Request_Cancel : Supported HCI_Remote_Name_Request: Supported HCI_Master_Link_Key: Supported HCI_Change_Connection_Link_Key: Supported HCI_Set_Connection_Encryption: Supported HCI_Read_LMP_Handle: Supported HCI_Read_Clock_Offset: Supported HCI_Role_Discovery: Supported HCI_QoS_Setup: Supported HCI_Exit_Sniff_Mode: Supported HCI_Sniff_Mode: Supported HCI_Reset: Supported HCI_Set_Event_Mask: Supported HCI_Flow_Specification: Supported HCI_Write_Default_Link_Policy_Settings: Supported HCI_Read_Default_Link_Policy_Settings: Supported HCI_Write_Link_Policy_Settings: Supported HCI_Read_Link_Policy_Settings: Supported HCI_Switch_Role: Supported HCI_Delete_Stored_Link_Key: Supported HCI_Write_Stored_Link_Key: Supported HCI_Read_Stored_Link_Key: Supported Previously used: Supported HCI_Write_PIN_Type: Supported HCI_Read_PIN_Type: Supported HCI_Flush: Supported HCI_Set_Event_Filter: Supported HCI_Write_Scan_Enable: Supported HCI_Read_Scan_Enable: Supported HCI_Write_Page_Timeout: Supported HCI_Read_Page_Timeout: Supported HCI_Write_Connection_Accept_Timeout: Supported HCI_Read_Connection_Accept_Timeout: Supported HCI_Read_Local_Name: Supported HCI_Write_Local_Name: Supported HCI_Write_Authentication_Enable: Supported HCI_Read_Authentication_Enable: Supported HCI_Write_Inquiry_Scan_Activity: Supported HCI_Read_Inquiry_Scan_Activity: Supported HCI_Write_Page_Scan_Activity: Supported HCI_Read_Page_Scan_Activity: Supported HCI_Write_Num_Broadcast_Retransmissions: Supported HCI_Read_Num_Broadcast_Retransmissions: Supported HCI_Write_Automatic_Flush_Timeout: Supported HCI_Read_Automatic_Flush_Timeout: Supported HCI_Write_Voice_Setting: Supported HCI_Read_Voice_Setting: Supported HCI_Write_Class_Of_Device: Supported HCI_Read_Class_Of_Device: Supported HCI_Host_Number_Of_Completed_Packets: Supported HCI_Host_Buffer_Size: Supported HCI_Set_Controller_To_Host_Flow_Control: Supported HCI_Write_Synchronous_Flow_Control_Enable: Supported HCI_Read_Synchronous_Flow_Control_Enable: Supported HCI_Read_Transmit_Power_Level: Supported HCI_Write_Current_IAC_LAP: Supported HCI_Read_Current_IAC_LAP: Supported HCI_Read_Number_Of_Supported_IAC: Supported HCI_Write_Link_Supervision_Timeout: Supported HCI_Read_Link_Supervision_Timeout: Supported HCI_Write_Inquiry_Mode: Supported HCI_Read_Inquiry_Mode: Supported HCI_Write_Inquiry_Scan_Type: Supported HCI_Read_Inquiry_Scan_Type: Supported HCI_Set_AFH_Host_Channel_Classification : Supported HCI_Write_AFH_Channel_Assessment_Mode: Supported HCI_Read_AFH_Channel_Assessment_Mode: Supported HCI_Write_Page_Scan_Type: Supported HCI_Read_Page_Scan_Type: Supported HCI_Read_Buffer_Size: Supported HCI_Read_Local_Extended_Features: Supported HCI_Read_Local_Supported_Features: Supported HCI_Read_Local_Version_Information: Supported HCI_Read_Clock: Supported HCI_Read_AFH_Channel_Map: Supported HCI_Read_RSSI: Supported HCI_Read_Link_Quality: Supported HCI_Reset_Failed_Contact_Counter: Supported HCI_Read_Failed_Contact_Counter: Supported HCI_Read_BD_ADDR: Supported HCI_Reject_Synchronous_Connection_Request: Supported HCI_Accept_Synchronous_Connection_Request: Supported HCI_Setup_Synchronous_Connection_Request: Supported HCI_Enable_Device-Under_Test_Mode: Supported HCI_Write_Loopback_Mode: Supported HCI_Read_Loopback_Mode: Supported HCI_Read_Local_OOB_Data: Supported HCI_Write_Simple_Pairing_Mode: Supported HCI_Read_Simple_Pairing_Mode: Supported HCI_Sniff_Subrating: Supported HCI_Refresh_Encryption_Key: Supported HCI_Write_Extended_Inquiry_Response: Supported HCI_Read_Extended_Inquiry_Response: Supported HCI_IO_Capability_Request_Reply: Supported HCI_Write_Inquiry_Transmit_Power_Level: Supported HCI_Read_Inquiry_Response_Transmit_Power_Level: Supported HCI_Remote_OOB_Data_Request_Negative_Reply: Supported HCI_Enhanced_Flush: Supported HCI_Write_Simple_Pairing_Debug_Mode: Supported HCI_Remote_OOB_Data_Request_Reply: Supported HCI_User_Passkey_Request_Negative_Reply: Supported HCI_User_Passkey_Request_Reply: Supported HCI_User_Confirmation_Request_Negative_Reply: Supported HCI_User_Confirmation_Request_Reply : Supported HCI_Read_Encryption_Key_Size: Supported HCI_IO_Capability_Request_Negative_Reply: Supported HCI_Send_Keypress_Notification: Supported HCI_Set_Event_Mask_Page_2: Supported HCI_Read_Data_Block_Size: Supported HCI_Write_Flow_Control_Mode: Supported HCI_Read_Flow_Control_Mode: Supported HCI_Write_LE_Host_Support: Supported HCI_Read_LE_Host_Support: Supported HCI_Read_Enhanced_Transmit_Power_Level: Supported HCI_LE_Set_Advertising_Data: Supported HCI_LE_Read_Advertising_Physical_Channel_Tx_Power: Supported HCI_LE_Set_Advertising_Parameters: Supported HCI_LE_Set_Random_Address: Supported HCI_LE_Read_Local_Supported_Features: Supported HCI_LE_Read_Buffer_Size [v1]: Supported HCI_LE_Set_Event_Mask: Supported HCI_LE_Clear_White_List: Supported HCI_LE_Read_White_List_Size: Supported HCI_LE_Create_Connection_Cancel: Supported HCI_LE_Create_Connection: Supported HCI_LE_Set_Scan_Enable: Supported HCI_LE_Set_Scan_Parameters: Supported HCI_LE_Set_Advertising_Enable: Supported HCI_LE_Set_Scan_Response_Data: Supported HCI_LE_Rand: Supported HCI_LE_Encrypt: Supported HCI_LE_Read_Remote_Features: Supported HCI_LE_Read_Channel_Map: Supported HCI_LE_Set_Host_Channel_Classification: Supported HCI_LE_Connection_Update: Supported HCI_LE_Remove_Device_From_White_List: Supported HCI_LE_Add_Device_To_White_List: Supported HCI_LE_Test_End: Supported HCI_LE_Transmitter_Test: Supported HCI_LE_Receiver_Test: Supported HCI_LE_Read_Supported_States: Supported HCI_LE_Long_Term_Key_Request_Negative_Reply: Supported HCI_LE_Long_Term_Key_Request_Reply: Supported HCI_LE_Enable_Encryption: Supported HCI_Read_Local_Supported_Codecs [v1]: Supported HCI_Enhanced_Accept_Synchronous_Connection: Supported HCI_Enhanced_Setup_Synchronous_Connection: Supported HCI_Write_Secure_Connections_Test_Mode: Supported HCI_Read_Local_OOB_Extended_Data: Supported HCI_Write_Authenticated_Payload_Timeout: Supported HCI_Read_Authenticated_Payload_Timeout: Supported HCI_Write_Secure_Connections_Host_Support: Supported HCI_Read_Secure_Connections_Host_Support: Supported HCI_Remote_OOB_Extended_Data_Request_Reply: Supported HCI_LE_Read_Suggested_Default_Data_Length: Supported HCI_LE_Set_Data_Length: Supported HCI_LE_Read_Peer_Resolvable_Address: Supported HCI_LE_Read_Resolving_List_Size: Supported HCI_LE_Clear_Resolving_List: Supported HCI_LE_Remove_Device_From_Resolving_List: Supported HCI_LE_Add_Device_To_Resolving_List: Supported HCI_LE_Generate_DHKey [v1]: Supported HCI_LE_Read_Local_P-256_Public_Key: Supported HCI_LE_Write_Suggested_Default_Data_Length: Supported HCI_LE_Receiver_Test: Supported HCI_LE_Set_PHY: Supported HCI_LE_Set_Default_PHY: Supported HCI_LE_Read_PHY: Supported HCI_LE_Read_Maximum_Data_Length: Supported HCI_LE_Set_Resolvable_Private_Address_Timeout: Supported HCI_LE_Set_Address_Resolution_Enable: Supported HCI_LE_Read_Local_Resolvable_Address: Supported HCI_LE_Read_Number_of_Supported_Advertising_Sets: Supported HCI_LE_Read_Maximum_Advertising_Data_Length: Supported HCI_LE_Set_Extended_Advertising_Enable: Supported HCI_LE_Set_Extended_Scan_Response_Data: Supported HCI_LE_Set_Extended_Advertising_Data: Supported HCI_LE_Set_Extended_Advertising_Parameters: Supported HCI_LE_Set_Advertising_Set_Random_Address: Supported HCI_LE_Transmitter_Test: Supported HCI_LE_Extended_Create_Connection: Supported HCI_LE_Set_Extended_Scan_Enable: Supported HCI_LE_Set_Extended_Scan_Parameters: Supported HCI_LE_Set_Periodic_Advertising_Enable: Supported HCI_LE_Set_Periodic_Advertising_Data: Supported HCI_LE_Set_Periodic_Advertising_Parameters: Supported HCI_LE_Clear_Advertising_Sets: Supported HCI_LE_Remove_Advertising_Set: Supported HCI_LE_Read_Transmit_Power: Supported HCI_LE_Read_Periodic_Advertiser_List_Size: Supported HCI_LE_Clear_Periodic_Advertiser_List: Supported HCI_LE_Remove_Device_From_Periodic_Advertiser_List: Supported HCI_LE_Add_Device_To_Periodic_Advertiser_List: Supported HCI_LE_Periodic_Advertising_Terminate_Sync: Supported HCI_LE_Periodic_Advertising_Create_Sync_Cancel: Supported HCI_LE_Periodic_Advertising_Create_Sync: Supported HCI_LE_Set_Privacy_Mode: Supported HCI_LE_Write_RF_Path_Compensation: Supported HCI_LE_Read_RF_Path_Compensation: Supported HCI_LE_Periodic_Advertising_Set_Info_Transfer: Supported HCI_LE_Periodic_Advertising_Sync_Transfer: Supported HCI_LE_Set_Periodic_Advertising_Receive_Enable: Supported HCI_LE_Set_CIG_Parameters: Supported HCI_LE_Read_ISO_TX_Sync: Supported HCI_LE_Read_Buffer_Size [v2]: Supported HCI_LE_Modify_Sleep_Clock_Accuracy: Supported HCI_Read_Local_Simple_Pairing_Options: Supported HCI_LE_Generate_DHKey[v2]: Supported HCI_LE_Set_Default_Periodic_Advertising_Sync_Transfer_Parameters: Supported HCI_LE_Set_Periodic_Advertising_Sync_Transfer_Parameters: Supported HCI_LE_Terminate_BIG: Supported HCI_LE_Create_BIG_Test: Supported HCI_LE_Create_BIG: Supported HCI_LE_Reject_CIS_Request: Supported HCI_LE_Accept_CIS_Request: Supported HCI_LE_Remove_CIG: Supported HCI_LE_Create_CIS: Supported HCI_LE_Set_CIG_Parameters_Test: Supported HCI_LE_ISO_Read_Test_Counters: Supported HCI_LE_ISO_Receive_Test: Supported HCI_LE_ISO_Transmit_Test: Supported HCI_LE_Remove_ISO_Data_Path: Supported HCI_LE_Setup_ISO_Data_Path: Supported HCI_LE_Request_Peer_SCA: Supported HCI_LE_BIG_Terminate_Sync: Supported HCI_LE_BIG_Create_Sync: Supported HCI_LE_Read_ISO_Link_Quality: Supported HCI_LE_Set_Host_Feature: Supported HCI_LE_ISO_Test_End: Supported HCI_Configure_Data_Path: Supported HCI_Read_Local_Supported_Controller_Delay: Supported HCI_Read_Local_Supported_Codec_Capabilities: Supported HCI_Read_Local_Supported_Codecs [v2]: Supported Unassigned Bits: 0x 00 00 00 00 00 00 00 00 00 00 ...标签:初始化,LE,Read,流程,Supported,Write,Set,HCI From: https://www.cnblogs.com/bluestorm/p/17700422.html