Beispiel #1
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      GattStartAdverts
 *
 *  DESCRIPTION
 *      This function is used to start undirected advertisements and moves to 
 *      ADVERTISING state.
 *
 *  RETURNS
 *      Nothing.
 *
 *---------------------------------------------------------------------------*/
extern void GattStartAdverts(bool fast_connection)
{
    /* Variable 'connect_flags' needs to be updated to have peer address type 
     * if Directed advertisements are supported as peer address type will 
     * only be used in that case. We don't support directed advertisements for 
     * this application.
     */

#ifdef USE_STATIC_RANDOM_ADDRESS
    uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | 
                      L2CAP_OWN_ADDR_TYPE_RANDOM;
#else
    uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | 
                          L2CAP_OWN_ADDR_TYPE_PUBLIC;
#endif /* USE_STATIC_RANDOM_ADDRESS */

    /* Set UCID to INVALID_UCID */
    g_lightapp_data.gatt_data.st_ucid = GATT_INVALID_UCID;

    /* Set advertisement parameters */
    gattSetAdvertParams(fast_connection);

    /* Start GATT connection in Slave role */
    GattConnectReq(NULL, connect_flags);
}
extern void GattStartAdverts(bool fast_connection)
{
    /* Variable 'connect_flags' needs to be updated to have peer address type
     * if Directed advertisements are supported as peer address type will
     * only be used in that case. We don't support directed advertisements for
     * this application.
     */

#ifdef USE_STATIC_RANDOM_ADDRESS
    uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED |
                      L2CAP_OWN_ADDR_TYPE_RANDOM;
#else
    uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED |
                          L2CAP_OWN_ADDR_TYPE_PUBLIC;
#endif /* USE_STATIC_RANDOM_ADDRESS */

    /* Set UCID to INVALID_UCID */
    g_hr_data.st_ucid = GATT_INVALID_UCID;

    /* Set advertisement parameters */
    gattSetAdvertParams(fast_connection);

    /* If white list is enabled, set the controller's advertising filter policy
     * to "process scan and connection requests only from devices in the White
     * List"
     */
    if((g_hr_data.enable_white_list == TRUE) &&
        (!GattIsAddressResolvableRandom(&(g_hr_data.bonded_bd_addr))))
    {
#ifdef USE_STATIC_RANDOM_ADDRESS
        connect_flags = L2CAP_CONNECTION_SLAVE_WHITELIST |
                   L2CAP_OWN_ADDR_TYPE_RANDOM;
#else
        connect_flags = L2CAP_CONNECTION_SLAVE_WHITELIST |
                       L2CAP_OWN_ADDR_TYPE_PUBLIC;
#endif /* USE_STATIC_RANDOM_ADDRESS */
    }

    /* Start GATT connection in Slave role */
    GattConnectReq(NULL, connect_flags);

    /* Start advertisement timer */
    if(g_hr_data.advert_timer_value)
    {
        TimerDelete(g_hr_data.app_tid);

        /* Start advertisement timer  */
        g_hr_data.app_tid = TimerCreate(g_hr_data.advert_timer_value, TRUE,
                                        gattAdvertTimerHandler);
    }

}
Beispiel #3
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      GattTriggerFastAdverts
 *
 *  DESCRIPTION
 *      This function is used to trigger fast advertisements 
 *
 *  RETURNS
 *      Nothing
 *
 *---------------------------------------------------------------------------*/
extern void GattTriggerFastAdverts(void)
{
    CSR_MESH_USER_ADV_PARAMS_T adv_params;

    /* Reset existing advertising data */
    CsrMeshStoreUserAdvData(0, NULL, ad_src_advertise);
    CsrMeshStoreUserAdvData(0, NULL, ad_src_scan_rsp);

#ifdef USE_STATIC_RANDOM_ADDRESS
    /* Restore the Random Address of the Bluetooth Device */
    MemCopy(&adv_params.bd_addr.addr, &g_lightapp_data.random_bd_addr, 
                                                            sizeof(BD_ADDR_T));
    adv_params.bd_addr.type = L2CA_RANDOM_ADDR_TYPE;
#else
    adv_params.bd_addr.type = L2CA_PUBLIC_ADDR_TYPE;
#endif /* USE_STATIC_RANDOM_ADDRESS */

    /* Set GAP peripheral params */
    adv_params.role = gap_role_peripheral;
    adv_params.bond = gap_mode_bond_no;
    adv_params.connect_mode = gap_mode_connect_undirected;
    adv_params.discover_mode = gap_mode_discover_general;
    adv_params.security_mode = gap_mode_security_unauthenticate;

    g_lightapp_data.gatt_data.advert_timer_value = 
                                             ADVERT_INTERVAL + appRandomDelay();

    /* If GATT bearer is enabled send connectable advert */
    if(g_lightapp_data.bearer_data.bearerEnabled & BLE_GATT_SERVER_BEARER_MASK)
    {
        /* Set advertisement parameters */
        gattSetAdvertParams(TRUE);
        /* Send a connectable advertisement */
        CsrMeshSendUserAdvert(&adv_params);

        /* Restart the advertising timer */
        TimerDelete(g_lightapp_data.gatt_data.app_tid);
        g_lightapp_data.gatt_data.app_tid = TimerCreate(
                                   g_lightapp_data.gatt_data.advert_timer_value,
                                                    TRUE, gattAdvertTimerHandler);
    }
}
Beispiel #4
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      GattStartAdverts
 *
 *  DESCRIPTION
 *      This function is used to start undirected advertisements and moves to 
 *      ADVERTISING state.
 *
 *  PARAMETERS
 *      p_addr [in]             Bonded host address
 *      fast_connection [in]    TRUE:  Fast advertisements
 *                              FALSE: Slow advertisements
 *
 *  RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
extern void GattStartAdverts(TYPED_BD_ADDR_T *p_addr, bool fast_connection)
{
    /* Variable 'connect_flags' needs to be updated to have peer address type 
     * if Directed advertisements are supported as peer address type will 
     * only be used in that case. We don't support directed advertisements for 
     * this application.
     */
#ifdef USE_STATIC_RANDOM_ADDRESS
    uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | 
                           L2CAP_OWN_ADDR_TYPE_RANDOM;
#else
    uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | 
                           L2CAP_OWN_ADDR_TYPE_PUBLIC;
#endif /* USE_STATIC_RANDOM_ADDRESS */

    /* Set advertisement parameters */
    gattSetAdvertParams(p_addr, fast_connection);

    /* If white list is enabled, set the controller's advertising filter policy 
     * to "process scan and connection requests only from devices in the White 
     * List"
     */
    if(IsWhiteListEnabled() && !GattIsAddressResolvableRandom(p_addr))
    {
#ifdef USE_STATIC_RANDOM_ADDRESS
        connect_flags = L2CAP_CONNECTION_SLAVE_WHITELIST |
                        L2CAP_OWN_ADDR_TYPE_RANDOM;
#else
        connect_flags = L2CAP_CONNECTION_SLAVE_WHITELIST |
                        L2CAP_OWN_ADDR_TYPE_PUBLIC;
#endif /* USE_STATIC_RANDOM_ADDRESS */
    }

    /* Start GATT connection in Slave role */
    GattConnectReq(NULL, connect_flags);

     /* Start advertisement timer */
    if(g_gatt_data.advert_timer_value)
    {
        StartAdvertTimer(g_gatt_data.advert_timer_value);
    }
}
Beispiel #5
0
extern void GattStartAdverts(bool fast_connection, gap_mode_connect connect_mode)
{
    uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | 
                          L2CAP_OWN_ADDR_TYPE_PUBLIC;

    /* Set UCID to INVALID_UCID */
    g_btcar_data.st_ucid = GATT_INVALID_UCID;

    /* Set advertisement parameters */
    gattSetAdvertParams(fast_connection, connect_mode);

    if(g_btcar_data.bonded && 
        !IsAddressResolvableRandom(&g_btcar_data.bonded_bd_addr) &&
        !IsAddressNonResolvableRandom(&g_btcar_data.bonded_bd_addr))
    {

        if(connect_mode == gap_mode_connect_directed)
        {
            connect_flags = L2CAP_CONNECTION_SLAVE_DIRECTED |
                            L2CAP_OWN_ADDR_TYPE_PUBLIC |
                            L2CAP_PEER_ADDR_TYPE_PUBLIC;
        }
        else
        {
            /* When the device is bonded, set the advertising filter policy to 
             * "process scan and connection requests only from devices in white 
             * list"
             */
            connect_flags = L2CAP_CONNECTION_SLAVE_WHITELIST | 
                               L2CAP_OWN_ADDR_TYPE_PUBLIC;
        }
    }

#ifdef __GAP_PRIVACY_SUPPORT__

    /*Check if privacy enabled */
    if(IsGapPeripheralPrivacyEnabled())
    {
        if(connect_mode == gap_mode_connect_directed)
        {
            /* Set advAddress to reconnection address. */
            GapSetRandomAddress(GapGetReconnectionAddress());

            connect_flags = L2CAP_CONNECTION_SLAVE_DIRECTED | 
                            L2CAP_OWN_ADDR_TYPE_RANDOM | 
                            L2CAP_PEER_ADDR_TYPE_RANDOM;
        }
        else
        {
            /* Generate Resolvable random address and use it as advAddress. */
            SMPrivacyRegenerateAddress(NULL);

            if(g_btcar_data.bonded_bd_addr.type == L2CA_RANDOM_ADDR_TYPE)
            {
                /* Change to random address */
                connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED |
                                 L2CAP_OWN_ADDR_TYPE_RANDOM | 
                                 L2CAP_PEER_ADDR_TYPE_RANDOM;
            }
            else
            {
                            /* Change to random address */
                connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED |
                                 L2CAP_OWN_ADDR_TYPE_RANDOM | 
                                 L2CAP_PEER_ADDR_TYPE_PUBLIC;
            }
        }

    }

#endif /* __GAP_PRIVACY_SUPPORT__ */

    /* Start GATT connection in Slave role */
    GattConnectReq(NULL, connect_flags);

     /* Start advertisement timer */
    if(g_btcar_data.advert_timer_value)
    {
        TimerDelete(g_btcar_data.app_tid);

        /* Start advertisement timer  */
        g_btcar_data.app_tid = TimerCreate(g_btcar_data.advert_timer_value, TRUE, 
                                        gattAdvertTimerHandler);
    }
}