/****************************************************************************** ##Function Name: CyBle_GattcStartDiscovery ******************************************************************************* Summary: Starts the automatic server discovery process. Two events may be generated after calling this function - CYBLE_EVT_GATTC_DISCOVERY_COMPLETE or CYBLE_EVT_GATTC_ERROR_RSP. The CYBLE_EVT_GATTC_DISCOVERY_COMPLETE event is generated when the remote device was successfully discovered. The CYBLE_EVT_GATTC_ERROR_RSP is generated if the device discovery is failed. Parameters: connHandle: The handle which consists of the device ID and ATT connection ID. Return: CYBLE_API_RESULT_T : Return value indicates if the function succeeded or failed. Following are the possible error codes. CYBLE_ERROR_OK - On successful operation CYBLE_ERROR_INVALID_PARAMETER - 'connHandle' value does not represent any existing entry. in the Stack CYBLE_ERROR_INVALID_OPERATION - The operation is not permitted. CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. ******************************************************************************/ CYBLE_API_RESULT_T CyBle_GattcStartDiscovery(CYBLE_CONN_HANDLE_T connHandle) { uint8 j; CYBLE_API_RESULT_T apiResult; if(CYBLE_STATE_CONNECTED != CyBle_GetState()) { apiResult = CYBLE_ERROR_INVALID_STATE; } else { CyBle_ServiceInit(); cyBle_connHandle = connHandle; /* Clean old discovery information */ for(j = 0u; j < (uint8) CYBLE_SRVI_COUNT; j++) { (void)memset(&cyBle_serverInfo[j].range, 0, sizeof(cyBle_serverInfo[0].range)); } apiResult = CyBle_GattcDiscoverAllPrimaryServices(connHandle); if(CYBLE_ERROR_OK == apiResult) { CyBle_SetClientState(CYBLE_CLIENT_STATE_SRVC_DISCOVERING); cyBle_eventHandlerFlag |= CYBLE_AUTO_DISCOVERY; } } return (apiResult); }
/****************************************************************************** ##Function Name: CyBle_WptscDiscovery ******************************************************************************* Summary: This function discovers the PRU's WPT service and characteristics using the GATT Primary Service Handle, received through the WPT Service Data within the PRU advertisement payload, together with the handle offsets defined A4WP specification. The PTU may perform service discovery using the CyBle_GattcStartDiscovery() API. This function may be used in response to Service Changed indication or to discover services other than the WPT service supported by the PRU. Parameters: servHandle: GATT Primary Service Handle of the WPT service. Return: None ******************************************************************************/ void CyBle_WptscDiscovery(CYBLE_GATT_DB_ATTR_HANDLE_T servHandle) { /* Clear old data */ CyBle_WptsInit(); cyBle_wptsc.serviceHandle = servHandle; cyBle_wptsc.charInfo[CYBLE_WPTS_PRU_CONTROL].valueHandle = servHandle + CYBLE_WPTS_PRU_CONTROL_CHAR_VALUE_OFFSET; cyBle_wptsc.charInfo[CYBLE_WPTS_PTU_STATIC_PAR].valueHandle = servHandle + CYBLE_WPTS_PTU_STATIC_PAR_CHAR_VALUE_OFFSET; cyBle_wptsc.charInfo[CYBLE_WPTS_PRU_ALERT].valueHandle = servHandle + CYBLE_WPTS_PRU_ALERT_PAR_CHAR_VALUE_OFFSET; cyBle_wptsc.charInfo[CYBLE_WPTS_PRU_ALERT].descrHandle[CYBLE_WPTS_CCCD] = servHandle + CYBLE_WPTS_PRU_ALERT_PAR_CHAR_CCCD_OFFSET; cyBle_wptsc.charInfo[CYBLE_WPTS_PRU_STATIC_PAR].valueHandle = servHandle + CYBLE_WPTS_PRU_STATIC_PAR_CHAR_VALUE_OFFSET; cyBle_wptsc.charInfo[CYBLE_WPTS_PRU_DYNAMIC_PAR].valueHandle = servHandle + CYBLE_WPTS_PRU_DYNAMIC_PAR_CHAR_VALUE_OFFSET; CyBle_SetClientState(CYBLE_CLIENT_STATE_DISCOVERED); }
/****************************************************************************** * Function Name: CyBle_GattcStartPartialDiscovery ***************************************************************************//** * * Starts the automatic server discovery process as per the range provided * on a GATT Server to which it is connected. This API could be used for * partial server discovery after indication received to the Service Changed * Characteristic Value. Two events may be generated * after calling this function - CYBLE_EVT_GATTC_DISCOVERY_COMPLETE or * CYBLE_EVT_GATTC_ERROR_RSP. The CYBLE_EVT_GATTC_DISCOVERY_COMPLETE event is * generated when the remote device was successfully discovered. The * CYBLE_EVT_GATTC_ERROR_RSP is generated if the device discovery is failed. * * \param connHandle: The handle which consists of the device ID and ATT connection ID. * \param startHandle: Start of affected attribute handle range. * \param endHandle: End of affected attribute handle range. * * \return * CYBLE_API_RESULT_T : Return value indicates if the function succeeded or * failed. Following are the possible error codes. * * <table> * <tr> * <th>Errors codes</th> * <th>Description</th> * </tr> * <tr> * <td>CYBLE_ERROR_OK</td> * <td>On successful operation</td> * </tr> * <tr> * <td>CYBLE_ERROR_INVALID_PARAMETER</td> * <td>'connHandle' value does not represent any existing entry.</td> * </tr> * <tr> * <td>CYBLE_ERROR_INVALID_OPERATION</td> * <td>The operation is not permitted</td> * </tr> * <tr> * <td>CYBLE_ERROR_MEMORY_ALLOCATION_FAILED</td> * <td>Memory allocation failed</td> * </tr> * <tr> * <td>CYBLE_ERROR_INVALID_STATE</td> * <td>If the function is called in any state except connected or discovered</td> * </tr> * </table> * ******************************************************************************/ CYBLE_API_RESULT_T CyBle_GattcStartPartialDiscovery(CYBLE_CONN_HANDLE_T connHandle, CYBLE_GATT_DB_ATTR_HANDLE_T startHandle, CYBLE_GATT_DB_ATTR_HANDLE_T endHandle) { uint8 j; CYBLE_API_RESULT_T apiResult; if((CyBle_GetState() != CYBLE_STATE_CONNECTED) || ((CyBle_GetClientState() != CYBLE_CLIENT_STATE_CONNECTED) && (CyBle_GetClientState() != CYBLE_CLIENT_STATE_DISCOVERED))) { apiResult = CYBLE_ERROR_INVALID_STATE; } else { /* Clean old discovery information of affected attribute range */ for(j = 0u; j < (uint8) CYBLE_SRVI_COUNT; j++) { if((cyBle_serverInfo[j].range.startHandle >= startHandle) && (cyBle_serverInfo[j].range.startHandle <= endHandle)) { (void)memset(&cyBle_serverInfo[j].range, 0, sizeof(cyBle_serverInfo[0].range)); } } cyBle_connHandle = connHandle; cyBle_gattcDiscoveryRange.startHandle = startHandle; cyBle_gattcDiscoveryRange.endHandle = endHandle; CyBle_ServiceInit(); apiResult = CyBle_GattcDiscoverPrimaryServices(connHandle, &cyBle_gattcDiscoveryRange); if(CYBLE_ERROR_OK == apiResult) { CyBle_SetClientState(CYBLE_CLIENT_STATE_SRVC_DISCOVERING); cyBle_eventHandlerFlag |= CYBLE_AUTO_DISCOVERY; } } return (apiResult); }