Before BLE is connected, the peripheral device needs to broadcast continuously, and the central device scans, discovers the broadcast and then connects.
But how to configure the broadcast data? This is where the GAP ( Generic Access Profile ) of BLE comes in. Generic Access Service is a service that every BLE device has, which can be understood as a mandatory service. GAP specifies the broadcast structure and connection process.
GAP Structure
There are two types of security modes, and mode 1 has four situations:
The first type is unsecured, with no authentication or encryption, commonly known as naked. The second and third types are both encrypted, the third type is authenticated, and the second type is not authenticated.
The second security level will use the Just Works pairing method, while the third security level selects the appropriate pairing method based on IO Capability.
The fourth security level is a new option added in BLE v4.2. When BLE pairing, there is a risk of eavesdropping when transmitting the Passkey, and this level uses a special algorithm to prevent the transmission of the Passkey from being eavesdropped.
Mode 2 has two types
Signed certificates and unsigned certificates.
In the official SDK, GAP is configured by the gapm_set_dev_config_cmd structure.
struct gapm_set_dev_config_cmd
{
/// GAPM requested operation:
/// - GAPM_SET_DEV_CONFIG: Set device configuration
uint8_t operation;
/// Device Role: Central, Peripheral, Observer, Broadcaster or All roles.
uint8_t role;
/// -------------- Privacy Config -----------------------
/// Duration before regenerate device address when privacy is enabled. - in seconds
uint16_t renew_dur;
/// Provided own static private random address (addr_type = GAPM_CFG_ADDR_PRIVATE)
bd_addr_t addr;
/// Device IRK used for resolvable random BD address generation (LSB first)
struct gap_sec_key irk;
/// Device Address Type
/// - GAPM_CFG_ADDR_PUBLIC: Device Address is a Public Static address
/// - GAPM_CFG_ADDR_PRIVATE: Device Address is a Private Static address
/// - GAPM_CFG_ADDR_HOST_PRIVACY: Device Address generated using Host Privacy feature
/// - GAPM_CFG_ADDR_CTNL_PRIVACY: Device Address generated using Controller Privacy feature
uint8_t addr_type;
/// -------------- Security Config -----------------------
/// Pairing mode authorized (see enum gapm_pairing_mode)
uint8_t pairing_mode;
/// -------------- ATT Database Config -----------------------
/// GAP service start handle
uint16_t gap_start_hdl;
/// GATT service start handle
uint16_t gatt_start_hdl;
//CEVA-284
/// Attribute database and gap extended configuration ([url=home.php?mod=space&uid=418085]@see[/url] enum gapm_att_and_ext_cfg_flag)
//uint16_t att_cfg;
uint16_t att_and_ext_cfg;
/// -------------- LE Data Length Extension -----------------------
///Suggested value for the Controller's maximum transmitted number of payload octets to be used
uint16_t sugg_max_tx_octets;
///Suggested value for the Controller's maximum packet transmission time to be used
uint16_t sugg_max_tx_time;
/// --------------- L2CAP Configuration ---------------------------
/// Maximal MTU acceptable for device
uint16_t max_mtu;
/// Maximal MPS Packet size acceptable for device
uint16_t max_mps;
/// Maximum number of LE Credit based connection that can be established
uint8_t max_nb_lecb;
/// --------------- LE Audio Mode Supported -----------------------
///
/// LE Audio Mode Configuration (@see gapm_audio_cfg_flag)
uint16_t audio_cfg;
/// ------------------ LE PHY Management -------------------------
/// Preferred LE PHY rate for data transmission (@see enum gap_rate)
uint8_t tx_pref_rates;
/// Preferred LE PHY rate for data reception (@see enum gap_rate)
uint8_t rx_pref_rates;
};
From the above structure, we can see that before broadcasting the connection, we need to define the broadcast device address, device name, and even icon, etc.
There are two types of device addresses: Public Device Address and Random Device Address. Public Device Address is charged.
|