/****************************************************************************** 
##Function Name: CyBle_HrscGetCharacteristicDescriptor
*******************************************************************************

Summary:
 Gets a characteristic descriptor of a specified characteristic of the service.
 
 This function call can result in generation of the following events based on
 the response from the server device:
 * CYBLE_EVT_HRSC_READ_DESCR_RESPONSE
 * CYBLE_EVT_GATTC_ERROR_RSP

Parameters:
 connHandle: The connection handle.
 charIndex: The index of the service characteristic.
 descrIndex: The index of the service characteristic descriptor.

Return:
 Return value is of type CYBLE_API_RESULT_T.
 * CYBLE_ERROR_OK - The request was sent successfully
 * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed
 * CYBLE_ERROR_INVALID_STATE - The state is not valid
 * CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed
 * CYBLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have
                                              the particular descriptor
 * CYBLE_ERROR_INVALID_OPERATION - This operation is not permitted on 
                                    the specified attribute

******************************************************************************/
CYBLE_API_RESULT_T CyBle_HrscGetCharacteristicDescriptor(CYBLE_CONN_HANDLE_T connHandle,
                       CYBLE_HRS_CHAR_INDEX_T charIndex, CYBLE_HRS_DESCR_INDEX_T descrIndex)
{
    CYBLE_API_RESULT_T apiResult;

    if(CyBle_GetClientState() != CYBLE_CLIENT_STATE_DISCOVERED)
    {
        apiResult = CYBLE_ERROR_INVALID_STATE;
    }
    else if((charIndex >= CYBLE_HRS_CHAR_COUNT) || (descrIndex >= CYBLE_HRS_DESCR_COUNT))
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }
    else if(charIndex != CYBLE_HRS_HRM)
    {
        apiResult = CYBLE_ERROR_INVALID_OPERATION;
    }
	else if(CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE == cyBle_hrsc.hrmCccdHandle)
    {
		apiResult = CYBLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE;
	}
    else
    {
        apiResult = CyBle_GattcReadCharacteristicDescriptors(connHandle, cyBle_hrsc.hrmCccdHandle);
        if(apiResult == CYBLE_ERROR_OK)
        {
            cyBle_hrscReqHandle = cyBle_hrsc.hrmCccdHandle;
        }
    }
    
    return (apiResult);
}
Beispiel #2
0
/******************************************************************************
##Function Name: CyBle_GlscGetCharacteristicDescriptor
*******************************************************************************

Summary:
 Gets the characteristic descriptor of the specified characteristic.

Parameters:
 connHandle: The connection handle.
 charIndex: The index of a service characteristic.
 descrIndex: The index of the service characteristic descriptor.

Return:
 Return value is of type CYBLE_API_RESULT_T.
 * CYBLE_ERROR_OK - The request was sent successfully
 * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed
 * CYBLE_ERROR_INVALID_STATE - The state is not valid
 * CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed
 * CYBLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have
                                              the particular descriptor
 * CYBLE_ERROR_INVALID_OPERATION - This operation is not permitted on 
                                    the specified attribute

******************************************************************************/
CYBLE_API_RESULT_T CyBle_GlscGetCharacteristicDescriptor(CYBLE_CONN_HANDLE_T connHandle,
                       CYBLE_GLS_CHAR_INDEX_T charIndex, CYBLE_GLS_DESCR_INDEX_T descrIndex)
{
    CYBLE_API_RESULT_T apiResult;
    
    /* Check the parameters */
    if(CyBle_GetClientState() != CYBLE_CLIENT_STATE_DISCOVERED)
    {
        apiResult = CYBLE_ERROR_INVALID_STATE;
    }
    else if((charIndex >= CYBLE_GLS_CHAR_COUNT) || (descrIndex >= CYBLE_GLS_DESCR_COUNT))
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }
    else if(CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE == cyBle_glsc.charInfo[charIndex].cccdHandle)
    {
		apiResult = CYBLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE;
	}
    else
    {
        apiResult = CyBle_GattcReadCharacteristicDescriptors(connHandle, cyBle_glsc.charInfo[charIndex].cccdHandle);
        if(CYBLE_ERROR_OK == apiResult)
        {
            cyBle_glscReqHandle = cyBle_glsc.charInfo[charIndex].cccdHandle;
        }
    }
    
    return (apiResult);
}
Beispiel #3
0
/******************************************************************************
##Function Name: CyBle_WptscGetCharacteristicDescriptor
*******************************************************************************

Summary:
 Sends a request to get the characteristic descriptor of the specified
 characteristic of the service.

Parameters:
 connHandle:      The connection handle.
 charIndex:       The index of a service characteristic of type
                  CYBLE_WPTS_CHAR_INDEX_T.
 descrIndex:      The index of a service characteristic descriptor of type
                  CYBLE_WPTS_DESCR_INDEX_T.

Return:
 * CYBLE_ERROR_OK - The request was sent successfully.
 * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed.
 * CYBLE_ERROR_INVALID_STATE - The state is not valid.
 * CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed.
 * CYBLE_ERROR_INVALID_OPERATION - This operation is not permitted on
                                    the specified attribute.

******************************************************************************/
CYBLE_API_RESULT_T CyBle_WptscGetCharacteristicDescriptor(CYBLE_CONN_HANDLE_T connHandle,
    CYBLE_WPTS_CHAR_INDEX_T charIndex, CYBLE_WPTS_DESCR_INDEX_T descrIndex)
{
    CYBLE_API_RESULT_T apiResult;

    if(CyBle_GetClientState() != CYBLE_CLIENT_STATE_DISCOVERED)
    {
        apiResult = CYBLE_ERROR_INVALID_STATE;
    }
    else if((charIndex >= CYBLE_WPTS_CHAR_COUNT) || (descrIndex >= CYBLE_WPTS_DESCR_COUNT))
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }
    else
    {
        apiResult = CyBle_GattcReadCharacteristicDescriptors(connHandle,
                                                    cyBle_wptsc.charInfo[charIndex].descrHandle[descrIndex]);

        /* Save handle to support service specific read response from device */
        if(apiResult == CYBLE_ERROR_OK)
        {
            cyBle_wptscReqHandle = cyBle_wptsc.charInfo[charIndex].descrHandle[descrIndex];
        }
    }

    return (apiResult);
}
Beispiel #4
0
/******************************************************************************
##Function Name: CyBle_BcscGetCharacteristicDescriptor
*******************************************************************************

Summary:
 Sends a request to get the characteristic descriptor of the specified 
 characteristic of the service.

Parameters:
 connHandle: The connection handle.
 charIndex: The index of the service characteristic. Starts with zero.
 charInstance: The instance of the characteristic specified by "charIndex".
 descrIndex: The index of the service characteristic descriptor.

Return:
 * CYBLE_ERROR_OK - The request was sent successfully.
 * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed.
 * CYBLE_ERROR_INVALID_STATE - The state is not valid.
 * CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed.
 * CYBLE_ERROR_INVALID_OPERATION - This operation is not permitted on
                                    the specified attribute.

******************************************************************************/
CYBLE_API_RESULT_T CyBle_BcscGetCharacteristicDescriptor(CYBLE_CONN_HANDLE_T connHandle,
    CYBLE_BCS_CHAR_INDEX_T charIndex, CYBLE_BCS_DESCR_INDEX_T descrIndex)
{
    CYBLE_API_RESULT_T apiResult;

    if(CyBle_GetClientState() != CYBLE_CLIENT_STATE_DISCOVERED)
    {
        apiResult = CYBLE_ERROR_INVALID_STATE;
    }
    else if((charIndex >= CYBLE_BCS_CHAR_COUNT) || (descrIndex >= CYBLE_BCS_DESCR_COUNT))
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }
    else if(cyBle_bcsc.bodyCompositionMeasurementCccdHandle = CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
    {
        apiResult = CyBle_GattcReadCharacteristicDescriptors(connHandle, cyBle_bcsc.bodyCompositionMeasurementCccdHandle);

        /* Save handle to support service specific read response from device */
        if(apiResult == CYBLE_ERROR_OK)
        {
            cyBle_bcscReqHandle = cyBle_bcsc.bodyCompositionMeasurementCccdHandle;
        }
    }
    else
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }

    return (apiResult);
}
Beispiel #5
0
/******************************************************************************
##Function Name: CyBle_BascGetCharacteristicDescriptor
*******************************************************************************

Summary:
 Sends a request to get characteristic descriptor of specified Battery Service
 characteristic from the server device. This function call can result in 
 generation of the following events based on the response from the server 
 device.
 * CYBLE_EVT_BASC_READ_DESCR_RESPONSE
 * CYBLE_EVT_GATTC_ERROR_RSP

Parameters:
 connHandle: The BLE peer device connection handle.
 serviceIndex: Index of the service instance. e.g. If two Battery Services are 
                supported in your design, then first service will be identified
                by serviceIndex of 0 and the second by serviceIndex of 1.
 charIndex: The index of a Battery service characteristic of type 
             CYBLE_BAS_CHAR_INDEX_T.
 descrIndex: The index of a Battery service characteristic descriptor of type 
              CYBLE_BAS_DESCR_INDEX_T.

Return:
 * CYBLE_ERROR_OK - The request was sent successfully
 * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed
 * CYBLE_ERROR_INVALID_STATE - The state is not valid
 * CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed
 * CYBLE_ERROR_INVALID_OPERATION - This operation is not permitted on 
                                    the specified attribute

******************************************************************************/
CYBLE_API_RESULT_T CyBle_BascGetCharacteristicDescriptor(CYBLE_CONN_HANDLE_T connHandle, uint8 serviceIndex,
    CYBLE_BAS_CHAR_INDEX_T charIndex, CYBLE_BAS_DESCR_INDEX_T descrIndex)
{
    CYBLE_API_RESULT_T apiResult;
    CYBLE_GATT_DB_ATTR_HANDLE_T locDescrHandle;
    
    if(CyBle_GetClientState() != CYBLE_CLIENT_STATE_DISCOVERED)
    {
        apiResult = CYBLE_ERROR_INVALID_STATE;
    }
    else if((serviceIndex >= CYBLE_BASC_SERVICE_COUNT) 
         || (charIndex > CYBLE_BAS_BATTERY_LEVEL)
         || (descrIndex >= CYBLE_BAS_DESCR_COUNT))
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }
    else
    {
        if(descrIndex == CYBLE_BAS_BATTERY_LEVEL_CCCD)
        {
            locDescrHandle = cyBle_basc[serviceIndex].cccdHandle;
        }
        else /* CYBLE_BAS_BATTERY_LEVEL_CPFD */
        {
            locDescrHandle = cyBle_basc[serviceIndex].cpfdHandle;
        }
        
        apiResult = CyBle_GattcReadCharacteristicDescriptors(connHandle, locDescrHandle);
        
        /* Save handle to support service specific read response from device */
        if(apiResult == CYBLE_ERROR_OK)
        {
            cyBle_bascReqHandle = locDescrHandle;
        }
    }

    return (apiResult);
}
/******************************************************************************
* Function Name: CyBle_AnscGetCharacteristicDescriptor
***************************************************************************//**
* 
*  Sends a request to the peer device to get the characteristic descriptor of the
*  specified characteristic of Alert Notification Service.
* 
*  \param connHandle: BLE peer device connection handle.
*  \param charIndex: The index of the Service Characteristic.
*  \param descrIndex: The index of the Service Characteristic Descriptor.
* 
* \return
*  Return value is of type CYBLE_API_RESULT_T.
*   * CYBLE_ERROR_OK - A request was sent successfully.
*   * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed.
*   * CYBLE_ERROR_INVALID_STATE - The component is in invalid state for current 
*                                 operation.
*   * CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed.
*   * CYBLE_ERROR_INVALID_OPERATION - Cannot process a request to send PDU due
*                                     to invalid operation performed by the 
*                                     application.
*
* \events
*  In case of successful execution (return value = CYBLE_ERROR_OK)
*  the next events can appear: \n
*  If the ANS service-specific callback is registered 
*      (with CyBle_AnsRegisterAttrCallback):
*  * CYBLE_EVT_ANSC_READ_DESCR_RESPONSE - in case if the requested attribute is
*                                successfully wrote on the peer device,
*                                the details (char index, descr index, value, etc.) 
*                                are provided with event parameter structure
*                                of type CYBLE_ANS_DESCR_VALUE_T. 
*  .
*  Otherwise (if the ANS service-specific callback is not registered):
*  * CYBLE_EVT_GATTC_READ_RSP - in case if the requested attribute is 
*                                successfully read on the peer device,
*                                the details (handle, value, etc.) are 
*                                provided with event parameters 
*                                structure (CYBLE_GATTC_READ_RSP_PARAM_T).
*  * CYBLE_EVT_GATTC_ERROR_RSP - in case if there some trouble with the 
*                                requested attribute on the peer device,
*                                the details are provided with event parameters 
*                                structure (CYBLE_GATTC_ERR_RSP_PARAM_T).
*
******************************************************************************/
CYBLE_API_RESULT_T CyBle_AnscGetCharacteristicDescriptor(CYBLE_CONN_HANDLE_T connHandle,
                                                         CYBLE_ANS_CHAR_INDEX_T charIndex,
                                                         uint8 descrIndex)
{
    CYBLE_GATT_DB_ATTR_HANDLE_T tmpHandle;
    CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    
    if(CyBle_GetClientState() != CYBLE_CLIENT_STATE_DISCOVERED)
    {
        apiResult = CYBLE_ERROR_INVALID_STATE;
    }
    else if(((charIndex == CYBLE_ANS_NEW_ALERT) || (charIndex == CYBLE_ANS_UNREAD_ALERT_STATUS)) &&
        (descrIndex == (uint8) CYBLE_ANS_CCCD))
    {
        if(charIndex == CYBLE_ANS_NEW_ALERT)
        {
            tmpHandle = cyBle_ansc.characteristics[CYBLE_ANS_NEW_ALERT].descriptors[CYBLE_ANS_CCCD];
        }
        else
        {
            tmpHandle = cyBle_ansc.characteristics[CYBLE_ANS_UNREAD_ALERT_STATUS].descriptors[CYBLE_ANS_CCCD];
        }
        
        apiResult = CyBle_GattcReadCharacteristicDescriptors(connHandle, tmpHandle);
        
        if(apiResult == CYBLE_ERROR_OK)
        {
            cyBle_anscReqHandle = tmpHandle;
        }
    }
    else
    {
        /* Characteristic has not been discovered or had invalid fields */
    }

    return(apiResult);
}