Пример #1
0
/********************************************************************
 * @fn          gapRole_startConnUpdate
 *
 * @brief       Start the connection update procedure
 *
 * @param       handleFailure - what to do if the update does not occur.
 *              Method may choose to terminate connection, try again, or take no action
 *
 * @return      none
 */
static void gapRole_startConnUpdate( uint8 handleFailure )
{
  // First check the current connection parameters versus the configured parameters
  if ( (gapRole_ConnInterval < gapRole_MinConnInterval)   ||
       (gapRole_ConnInterval > gapRole_MaxConnInterval)   ||
       (gapRole_ConnSlaveLatency != gapRole_SlaveLatency) ||
       (gapRole_ConnTimeout  != gapRole_TimeoutMultiplier) )
  {
    gapUpdateLinkParamReq_t linkParams;
    uint16 timeout = GAP_GetParamValue( TGAP_CONN_PARAM_TIMEOUT );

    linkParams.connectionHandle = gapRole_ConnectionHandle;
    linkParams.intervalMin = gapRole_MinConnInterval;
    linkParams.intervalMax = gapRole_MaxConnInterval;
    linkParams.connLatency = gapRole_SlaveLatency;
    linkParams.connTimeout = gapRole_TimeoutMultiplier;
            
    VOID GAP_UpdateLinkParamReq( &linkParams );
        
    paramUpdateNoSuccessOption = handleFailure;
        
    // Let's wait either for L2CAP Connection Parameters Update Response or
    // for Controller to update connection parameters
    VOID osal_start_timerEx( gapRole_TaskID, CONN_PARAM_TIMEOUT_EVT, timeout );
  }
}
Пример #2
0
/********************************************************************
 * @fn          gapRole_connUpdate
 *
 * @brief       Start the connection update procedure
 *
 * @param       handleFailure - what to do if the update does not occur.
 *              Method may choose to terminate connection, try again,
 *              or take no action
 * @param       pConnParams   - connection parameters to use
 *
 * @return      SUCCESS: operation was successful.
 *              INVALIDPARAMETER: Data can not fit into one packet.
 *              MSG_BUFFER_NOT_AVAIL: No HCI buffer is available.
 *              bleInvalidRange: 
 *              bleIncorrectMode: invalid profile role.
 *              bleAlreadyInRequestedMode: already updating link parameters.
 *              bleNotConnected: Connection is down
 *              bleMemAllocError: Memory allocation error occurred.
 *              bleNoResources: No available resource
 */
bStatus_t gapRole_connUpdate(uint8_t handleFailure, gapRole_updateConnParams_t *pConnParams)
{
  bStatus_t status;
  linkDBInfo_t pInfo;
  
  //ensure connection exists
  linkDB_GetInfo(pConnParams->connHandle, &pInfo);
  if (!(pInfo.stateFlags & LINK_CONNECTED))
  {
    return (bleNotConnected);
  }
  // Make sure we don't send an L2CAP Connection Parameter Update Request
  // command within TGAP(conn_param_timeout) of an L2CAP Connection Parameter
  // Update Response being received.
  if (Util_isActive(&updateTimeoutClock) == FALSE)
  {     
    uint16_t timeout = GAP_GetParamValue(TGAP_CONN_PARAM_TIMEOUT);
#if defined(L2CAP_CONN_UPDATE)
    l2capParamUpdateReq_t updateReq;
    
    updateReq.intervalMin = pConnParams->minConnInterval;
    updateReq.intervalMax = pConnParams->maxConnInterval;
    updateReq.slaveLatency = pConnParams->slaveLatency;
    updateReq.timeoutMultiplier = pConnParams->timeoutMultiplier;
    
    status =  L2CAP_ConnParamUpdateReq(pConnParams->connHandle, &updateReq, selfEntity);
#else
    gapUpdateLinkParamReq_t linkParams;
    
    linkParams.connectionHandle = pConnParams->connHandle;
    linkParams.intervalMin = pConnParams->minConnInterval;
    linkParams.intervalMax = pConnParams->maxConnInterval;
    linkParams.connLatency = pConnParams->slaveLatency;
    linkParams.connTimeout = pConnParams->timeoutMultiplier;
    
    status = GAP_UpdateLinkParamReq( &linkParams );
#endif // L2CAP_CONN_UPDATE
    
    if(status == SUCCESS)
    {
      //store update params for possible resending
      paramUpdateNoSuccessOption = handleFailure;
      VOID memcpy(&gapRole_updateConnParams, pConnParams, sizeof(gapRole_updateConnParams_t));
      
      // start timeout clock
      Util_restartClock(&updateTimeoutClock, timeout);
    }
  }
  else
  {
    return(blePending);
  }
  
  return status;
}
/********************************************************************
 * @fn          gapRole_startConnUpdate
 *
 * @brief       Start the connection update procedure
 *
 * @param       handleFailure - what to do if the update does not occur.
 *              Method may choose to terminate connection, try again,
 *              or take no action
 *
 * @return      none
 */
static bStatus_t gapRole_startConnUpdate(uint8_t handleFailure, uint8 connHandle) {
	bStatus_t status;
	uint8 connHandleIndex = gapRoleInfo_Find(connHandle);

	//update only connection to master, not those to slave
	if (multiConnInfo[connHandleIndex].gapRole_ConnRole != GAP_PROFILE_PERIPHERAL) {
		return (bleNotConnected);
	}
	// If there is no existing connection no update need be sent
	if (multiConnInfo[connHandleIndex].gapRole_ConnectionHandle == GAPROLE_CONN_JUST_TERMINATED || multiConnInfo[connHandleIndex].gapRole_ConnectionHandle == INVALID_CONNHANDLE) {
		return (bleNotConnected);
	}

	// First check the current connection parameters versus the configured parameters
//	if ((multiConnInfo[connHandleIndex].gapRole_ConnInterval < gapRole_MinConnInterval) || (multiConnInfo[connHandleIndex].gapRole_ConnInterval > gapRole_MaxConnInterval)
//			|| (multiConnInfo[connHandleIndex].gapRole_ConnSlaveLatency != gapRole_SlaveLatency)
//			|| (multiConnInfo[connHandleIndex].gapRole_ConnTimeout != gapRole_TimeoutMultiplier)) {
	if (gapRole_MinConnInterval > 6 && gapRole_MinConnInterval < 3200){

		//TODO: do some test to check if parameters are within specification of ble

		uint16_t timeout = GAP_GetParamValue(TGAP_CONN_PARAM_TIMEOUT);
#if defined(L2CAP_CONN_UPDATE)
		l2capParamUpdateReq_t updateReq;

		updateReq.intervalMin = gapRole_MinConnInterval;
		updateReq.intervalMax = gapRole_MaxConnInterval;
		updateReq.slaveLatency = gapRole_SlaveLatency;
		updateReq.timeoutMultiplier = gapRole_TimeoutMultiplier;

		status = L2CAP_ConnParamUpdateReq(connHandle, &updateReq, selfEntity);
#else
		gapUpdateLinkParamReq_t linkParams;

		linkParams.connectionHandle = connHandle;
		linkParams.intervalMin = gapRole_MinConnInterval;
		linkParams.intervalMax = gapRole_MaxConnInterval;
		linkParams.connLatency = gapRole_SlaveLatency;
		linkParams.connTimeout = gapRole_TimeoutMultiplier;

		status = GAP_UpdateLinkParamReq(&linkParams);
#endif // L2CAP_CONN_UPDATE

		if (status == SUCCESS) {
			paramUpdateNoSuccessOption = handleFailure;
			// Let's wait either for L2CAP Connection Parameters Update Response or
			// for Controller to update connection parameters
			Util_restartClock(&updateTimeoutClock, timeout);
		}
	} else {
		status = bleInvalidRange;
	}

	return status;
}
/**
 * @brief   Update the link connection parameters.
 *
 * Public function defined in central.h.
 */
bStatus_t GAPCentralRole_UpdateLink(uint16_t connHandle, uint16_t connIntervalMin,
                                    uint16_t connIntervalMax, uint16_t connLatency,
                                    uint16_t connTimeout)
{
  gapUpdateLinkParamReq_t params;

  params.connectionHandle = connHandle;
  params.intervalMin = connIntervalMin;
  params.intervalMax = connIntervalMax;
  params.connLatency = connLatency;
  params.connTimeout = connTimeout;
  
  return GAP_UpdateLinkParamReq(&params);
}
Пример #5
0
/********************************************************************
 * @fn          gapRole_startConnUpdate
 *
 * @brief       Start the connection update procedure
 *
 * @param       handleFailure - what to do if the update does not occur.
 *              Method may choose to terminate connection, try again,
 *              or take no action
 *
 * @return      none
 */
static bStatus_t gapRole_startConnUpdate(uint8_t handleFailure)
{
    bStatus_t status;

    // First check the current connection parameters versus the configured parameters
    if ((gapRole_ConnInterval < gapRole_MinConnInterval)   ||
            (gapRole_ConnInterval > gapRole_MaxConnInterval)   ||
            (gapRole_ConnSlaveLatency != gapRole_SlaveLatency) ||
            (gapRole_ConnTimeout  != gapRole_TimeoutMultiplier))
    {
        uint16_t timeout = GAP_GetParamValue(TGAP_CONN_PARAM_TIMEOUT);
#if defined(L2CAP_CONN_UPDATE)
        l2capParamUpdateReq_t updateReq;

        updateReq.intervalMin = gapRole_MinConnInterval;
        updateReq.intervalMax = gapRole_MaxConnInterval;
        updateReq.slaveLatency = gapRole_SlaveLatency;
        updateReq.timeoutMultiplier = gapRole_TimeoutMultiplier;

        status =  L2CAP_ConnParamUpdateReq(gapRole_ConnectionHandle, &updateReq, selfEntity);
#else
        gapUpdateLinkParamReq_t linkParams;

        linkParams.connectionHandle = gapRole_ConnectionHandle;
        linkParams.intervalMin = gapRole_MinConnInterval;
        linkParams.intervalMax = gapRole_MaxConnInterval;
        linkParams.connLatency = gapRole_SlaveLatency;
        linkParams.connTimeout = gapRole_TimeoutMultiplier;

        status = GAP_UpdateLinkParamReq( &linkParams );
#endif // L2CAP_CONN_UPDATE

        if(status == SUCCESS)
        {
            paramUpdateNoSuccessOption = handleFailure;
            // Let's wait either for L2CAP Connection Parameters Update Response or
            // for Controller to update connection parameters
            Util_restartClock(&updateTimeoutClock, timeout);
        }
    }
    else
    {
        status = bleInvalidRange;
    }

    return status;
}