Initializing GAP


What is connection parameters? Nordic Semiconductor.


GAP (Advertising and Connections)

The Generic Access Profile (GAP) dictates how devices interact with each other at a lower level, outside of the actual protocol stack. GAP establishes different sets of rules and concepts to regulate and standardize the lowlevel operation of devices:

  • Roles and interaction between them:
          Each device can operate in one or more roles at the same time. Each role imposes
          restrictions and enforces certain behavioral requirements. Certain combinations of
          roles allow devices to communicate with each other, and GAP establishes the interactions
          between those roles precisely. Although not always, roles tend to be as sociated with
          specific device types, and for many (though not all) implementations, they are also tightly
          bound with their use case and do not change at all.
  • Operational modes and transitions across those:
         Further refining the concept of a role, a mode is a state in which the device can
         switch to for a certain amount of time to achieve a particular goal or, more specifically,
         to allow a peer to perform a particular procedure. Switching modes can be
         triggered by user interface actions or automatically when required, and devices tend
         to switch modes more frequently than roles.
  • Operational procedures to achieve consistent and interoperable communication:
         A procedure is a sequence of actions (usually Link Layer control sequences or packet exchanges)
         that allows a device to attain a certain goal. A procedure is typically associated
         with a mode on the other peer, so they are often tightly coupled together.
  • Security aspects, including security modes and procedures:
         GAP builds on top of the Security Manager and the Security Manager Protocol by
         defining security modes and procedures that specify how peers set the level of security
         required by a particular data exchange and later how that security level is enforced.
         GAP further defines additional security features not associated with particular modes
         or procedures, and implementations are free to use those to increase the level of data
         protection required by each application.
  • Additional data formats for nonprotocol data:
         In addition to all of the above, GAP is also used as a placeholder for certain additional
         data format definitions that are related to the modes and procedures defined by the GAP sepcification.

GAP defines how devices can discover and connect with one another, how they bond, how devices can be broadcasters and observers, it also defines how the different types of addresses can be used to allow private and resolvable addresses.
NRF51822

	    		      							 		     					
/**@brief Function for the GAP initialization.
 *
 * @details This function will set up all the necessary GAP (Generic Access Profile) parameters of
 *          the device. It also sets the permissions and appearance.
 */
static void gap_params_init(void)
{
    uint32_t                err_code;
    ble_gap_conn_params_t   gap_conn_params;
    ble_gap_conn_sec_mode_t sec_mode;
	
    //Set security mode pointed to by ptr do {(ptr)->sm = 1; (ptr)->lv = 1;} while(0), open link.
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); 

    err_code = sd_ble_gap_device_name_set(&sec_mode,
                                          (const uint8_t *) DEVICE_NAME,
                                          strlen(DEVICE_NAME));
    APP_ERROR_CHECK(err_code);

    memset(&gap_conn_params, 0, sizeof(gap_conn_params));

    gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
    gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
    gap_conn_params.slave_latency     = SLAVE_LATENCY;
    gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT;

    err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
    APP_ERROR_CHECK(err_code);
}