In the following, we explain how the various Bluetooth profiles are used in BTstack. ## GAP - Generic Access Profile: Classic The GAP profile defines how devices find each other and establish a secure connection for other profiles. As mentioned before, the GAP functionality is split between and . Please check both. ### Become discoverable A remote unconnected Bluetooth device must be set as “discoverable” in order to be seen by a device performing the inquiry scan. To become discoverable, an application can call *gap_discoverable_control* with input parameter 1. If you want to provide a helpful name for your device, the application can set its local name by calling $gap_set_local_name$. To save energy, you may set the device as undiscoverable again, once a connection is established. See Listing [below](#lst:Discoverable) for an example. ~~~~ {#lst:Discoverable .c caption="{Setting discoverable mode.}"} int main(void){ ... // make discoverable gap_discoverable_control(1); btstack_run_loop_execute(); return 0; } void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){ ... switch(state){ case W4_CHANNEL_COMPLETE: // if connection is successful, make device undiscoverable gap_discoverable_control(0); ... } } ~~~~ ### Discover remote devices {#sec:GAPdiscoverRemoteDevices} To scan for remote devices, the *hci_inquiry* command is used. Found remote devices are reported as a part of: - HCI_EVENT_INQUIRY_RESULT, - HCI_EVENT-_INQUIRY_RESULT_WITH_RSSI, or - HCI_EVENT_EXTENDED_INQUIRY_RESPONSE events. Each response contains at least the Bluetooth address, the class of device, the page scan repetition mode, and the clock offset of found device. The latter events add information about the received signal strength or provide the Extended Inquiry Result (EIR). A code snippet is shown in Listing [below](#lst:DiscoverDevices). ~~~~ {#lst:DiscoverDevices .c caption="{Discover remote devices.}"} void print_inquiry_results(uint8_t *packet){ int event = packet[0]; int numResponses = hci_event_inquiry_result_get_num_responses(packet); uint16_t classOfDevice, clockOffset; uint8_t rssi, pageScanRepetitionMode; for (i=0; i