/*********************************************************************
 * @brief   Terminates the existing connection.
 *
 * Public function defined in peripheral.h.
 */
bStatus_t GAPRole_TerminateConnection(uint16_t connHandle) {

	uint8 connHandleIndex = gapRoleInfo_Find(connHandle);

	if (multiConnInfo[connHandleIndex].gapRole_ConnRole == GAP_PROFILE_PERIPHERAL)

		if ((gapRole_peripheralState == GAPROLE_CONNECTED) || (gapRole_peripheralState == GAPROLE_CONNECTED_ADV)) {
			return (GAP_TerminateLinkReq(selfEntity, connHandle,
			HCI_DISCONNECT_REMOTE_USER_TERM));
		} else {
			return (bleIncorrectMode);
		}

	else {
		return (GAP_TerminateLinkReq(selfEntity, connHandle,
		HCI_DISCONNECT_REMOTE_USER_TERM));
	}
}
Exemplo n.º 2
0
/*********************************************************************
 * @brief   Terminates the existing connection.
 *
 * Public function defined in peripheral.h.
 */
bStatus_t GAPRole_TerminateConnection( void )
{
  if ( gapRole_state == GAPROLE_CONNECTED )
  {
    return ( GAP_TerminateLinkReq( gapRole_TaskID, gapRole_ConnectionHandle ) );
  }
  else
  {
    return ( bleIncorrectMode );
  }
}
/*********************************************************************
 * @brief   Terminates the existing connection.
 *
 * Public function defined in peripheral.h.
 */
bStatus_t GAPRole_TerminateConnection( void )
{
  if ( (gapRole_state == GAPROLE_CONNECTED)
      || (gapRole_state == GAPROLE_CONNECTED_ADV) )
  {
    return ( GAP_TerminateLinkReq( gapRole_TaskID, gapRole_ConnectionHandle, 
                                   HCI_DISCONNECT_REMOTE_USER_TERM ) );
  }
  else
  {
    return ( bleIncorrectMode );
  }
}
/*********************************************************************
 * @brief   Task Event Processor function.
 *
 * Internal function defined in peripheral.h.
 */
uint16 GAPRole_ProcessEvent( uint8 task_id, uint16 events )
{
  VOID task_id; // OSAL required parameter that isn't used in this function
  
  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( gapRole_TaskID )) != NULL )
    {
      gapRole_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & GAP_EVENT_SIGN_COUNTER_CHANGED )
  {
    // Sign counter changed, save it to NV
    VOID osal_snv_write( BLE_NVID_SIGNCOUNTER, sizeof( uint32 ), &gapRole_signCounter );

    return ( events ^ GAP_EVENT_SIGN_COUNTER_CHANGED );
  }
  
  if ( events & START_ADVERTISING_EVT )
  {
    if ( gapRole_AdvEnabled )
    {
      gapAdvertisingParams_t params;

      // Setup advertisement parameters
      if ( gapRole_state == GAPROLE_CONNECTED )
      {
        // While in a connection, we can only advertise non-connectable undirected.
        params.eventType = GAP_ADTYPE_ADV_NONCONN_IND;
      }
      else
      {
        params.eventType = gapRole_AdvEventType;
        params.initiatorAddrType = gapRole_AdvDirectType;
        VOID osal_memcpy( params.initiatorAddr, gapRole_AdvDirectAddr, B_ADDR_LEN );
      }
      params.channelMap = gapRole_AdvChanMap;
      params.filterPolicy = gapRole_AdvFilterPolicy;

      if ( GAP_MakeDiscoverable( gapRole_TaskID, &params ) != SUCCESS )
      {
        gapRole_state = GAPROLE_ERROR;
        if ( pGapRoles_AppCGs && pGapRoles_AppCGs->pfnStateChange )
        {
          pGapRoles_AppCGs->pfnStateChange( gapRole_state );
        }
      }
    }
    return ( events ^ START_ADVERTISING_EVT );
  }

  if ( events & RSSI_READ_EVT )
  {
    // Only get RSSI when in a connection
    if ( (gapRole_state == GAPROLE_CONNECTED)
        || (gapRole_state == GAPROLE_CONNECTED_ADV) )
    {
      // Ask for RSSI
      VOID HCI_ReadRssiCmd( gapRole_ConnectionHandle );

      // Setup next event
      if ( gapRole_RSSIReadRate )
      {
        VOID osal_start_timerEx( gapRole_TaskID, RSSI_READ_EVT, gapRole_RSSIReadRate );
      }
    }
    return ( events ^ RSSI_READ_EVT );
  }

  if ( events & UPDATE_PARAMS_TIMEOUT_EVT )
  {
    // Clear an existing timeout
    if ( osal_get_timeoutEx( gapRole_TaskID, UPDATE_PARAMS_TIMEOUT_EVT ) )
    {
      VOID osal_stop_timerEx( gapRole_TaskID, UPDATE_PARAMS_TIMEOUT_EVT );
    }

    // The Update Parameters Timeout occurred - Terminate connection
    VOID GAP_TerminateLinkReq( gapRole_TaskID, gapRole_ConnectionHandle, 
                               HCI_DISCONNECT_REMOTE_USER_TERM );

    return ( events ^ UPDATE_PARAMS_TIMEOUT_EVT );
  }

  // Discard unknown events
  return 0;
}
Exemplo n.º 5
0
/**
 * @brief   Terminate a link.
 *
 * Public function defined in central.h.
 */
bStatus_t GAPCentralRole_TerminateLink( uint16 connHandle )
{
 return GAP_TerminateLinkReq( gapCentralRoleTaskId, connHandle ) ;
}
/**
 * @brief   Terminate a link.
 *
 * Public function defined in central.h.
 */
bStatus_t GAPCentralRole_TerminateLink(uint16_t connHandle)
{
  return GAP_TerminateLinkReq(selfEntity, connHandle, HCI_DISCONNECT_REMOTE_USER_TERM) ;
}
Exemplo n.º 7
0
/*********************************************************************
 * @brief   Terminates the existing connection.
 *
 * Public function defined in peripheral.h.
 */
bStatus_t GAPRole_TerminateConnection(uint16_t connHandle)
{
    return (GAP_TerminateLinkReq(selfEntity, connHandle, 
                                 HCI_DISCONNECT_REMOTE_USER_TERM));
}
Exemplo n.º 8
0
/**
 * @brief   Terminate a link.
 *
 * Public function defined in central.h.
 */
bStatus_t GAPCentralRole_TerminateLink( uint16 connHandle )
{
 return GAP_TerminateLinkReq( gapCentralRoleTaskId, connHandle, HCI_DISCONNECT_REMOTE_USER_TERM ) ;
}