Bluetooth HCI drive learning notes

Source: Internet
Author: User
Data Structure 1, hci_event

Indicates the hardware status of the Bluetooth controller.

Enum hci_event {

Device_up, device Enabled

Device_down: Disable the device.

The device_error device has an error.

};

Header file: bt_hcip.h

2. hci_type

Indicates the data packet type.

enum HCI_TYPE {
Command_packet = 1, command package
Data_packet_acl = 2, access control list data
Data_packet_sco = 3, connection-oriented data synchronization
Event_packet = 4, event
Etype_finish = End mark of 5 packets
};

Header file: bt_hcip.h

3. hci_parameters

Indicates the interface for HCI transmission.

typedef struct __hci_parameters {
  unsigned int uiSize;
Unsigned int finterfaceversion; transport layer driver version
Int imaxsizeread; buffer size, excluding header and tail
  int iMaxSizeWrite;
Int ireadbufferheader; default value
  int iReadBufferTrailer;               
Int iwritebufferheader; number of bytes between 0 and start
Int iwritebuffertrailer; number of bytes between end and size
Int uiflags; invalid; otherwise, invalid
  int fHardwareVersion;                 0/1/2
Unsigned int uiresetdelay; interval before the reset command is issued to the next command
Unsigned int uiwritetimeout; write timeout
Unsigned int uidriftfactor; Time
  int iScoWriteLowNumPackets;           0
  int iScoWriteNumPackets;              0
  int iScoWritePacketSize;              0/-1
  int iScoSampleSize;                   8/16
} HCI_PARAMETERS;               

Header file: bt_hcip.h

 
API function 1, hci_closeconnection
void HCI_CloseConnection(void);

Function: Disable the connection between stack and HCI transmission.

Note: calling this function will unlock read and write, hardware is not initialized, and all resource spaces including the buffer zone will be released. If the driver is in the DLL, it will be uninstalled when the function returns.

2. hci_openconnection (void );
int HCI_OpenConnection(void);

Function: establish a connection between the HCI Layer in the stack and the Bluetooth hardware. If a success is returned, the transmission starts. In this case, the stack calls the hci_readhciparamerters function.

Note: This function is used to enable hardware, initialize hardware, and establish a connection with hardware. If true is returned, the connection is established successfully. This is a blocking function.

3. hci_readhciparameters
int HCI_ReadHciParameters(
  HCI_PARAMETERS* pParms
);
Function: gets the hardware features of the Bluetooth controller. If true is returned, the result is successful. If false, the result is an error. If false is returned, the stack interface immediately calls hci_closeconnection.
Note: this function can be called before a connection is opened.
4. hci_readpacket
int HCI_ReadPacket(
  HCI_TYPE* peType, 
  BD_BUFFER* pInBuffer
);
Function: Read packets from connected devices. If the return value is true, the operation is successful. If the return value is false, the operation is successful. If the return value is false, the operation is incorrect. If false is returned, the stack interface immediately calls hci_closeconnection.
Note: The function is blocked only when the packet is read or an error occurs. If an error occurs, the Bluetooth protocol stack is disabled. This function must be unlocked and an error is returned after hci_closeconnection is called.
5. hci_writepacket
int HCI_WritePacket(
  HCI_TYPE eType, 
  BD_BUFFER* pOutBuffer
);
Function: send a package to the connected device. If the return value is true, the package is successfully completed. If the return value is false, an error occurs. If false is returned, the stack interface immediately calls hci_closeconnection.
Note: This function requires an empty buffer to reserve enough space for the header and the end of the package. This space is required by hci_readhciparameters. The function is blocked when it is sent. If an error occurs, the Bluetooth protocol stack will be disabled. This function must be unlocked and an error is returned after hci_closeconnection is called.

6. hci_starthardware

int HCI_StartHardware(void);

Function: initializes the Bluetooth hardware.

Note: To ensure hardware is enabled, the Bluetooth stack can call this function. The driver may attempt to initialize the hardware again. This function must call the callback function hci_transportcallback to confirm that the device is enabled and remove the temporary flag to identify the hardware availability.

7. hci_stophardware
int HCI_StopHardware(void);

Function: releases the Bluetooth hardware.

Note: This function is called to remove existing hardware connections and does not prompt for the arrival of hardware devices. This function must call the callback function hci_transportcallback to confirm the device is off and until hci_starthardware is called to erect a temporary flag to Identify hardware availability.

8. hci_setcallback
typedef int (*HCI_TransportCallback)(HCI_EVENT eEvent, void* pEvent);
  int HCI_SetCallback(
  HCI_TransportCallback pfCallback
);
Function: gets HCI parameters.
NOTE: If pfcallback is empty, the driver must be uninstalled. This function is called only when the current connection of the stack is closed and the pfcallback is set to null. If this parameter is not null, hardware is inserted or pulled out. If hardware insertion or disconnection is detected, the transport layer calls this function to provide services for the upper layer.
 

Header file: bt_hcip.h

Package: btd. Lib

 

The Bluetooth transport manager first searches for PNP devices, such as PCMCIA and USB. If no PNP device is found, it searches for an existing device in the registry.

Default register settings

The registration key HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Bluetooth \ transports builtin \ 1 indicates the built-in transport driver settings, and 1 indicates the priority.

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Bluetooth \ transports \ PNP \ <Guid> This indicates the configuration of the PNP transmission driver.

The GUID key represents the registration key value of the Transport Driver iclass. This value is bthuniv's settings for the transferred register. Before a device connection is enabled, these settings will be copied to the HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Bluetooth \ HCI directory.

If you specify the transmission driver by setting appropriate compilation variables, such as sysgen_bth_usb_only, bthuniv will not be used in the OS design. In this case, the appropriate transport-driven Registrar settings will be automatically copied to HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Bluetooth \ HCI.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.