Exemple #1
0
/*********************************************************************
 * @fn      ProxPeriph_AddService
 *
 * @brief   Initializes the Proximity Peripheral service by
 *          registering GATT attributes with the GATT server.
 *          Only call this function once.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return   Success or Failure
 */
bStatus_t ProxPeriph_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  if ( services & PP_LINK_LOSS_SERVICE )
  {
    // Register Link Loss attribute list and CBs with GATT Server App  
    status = GATTServApp_RegisterService( linkLossAttrTbl, GATT_NUM_ATTRS( linkLossAttrTbl ),
                                          GATT_MAX_ENCRYPT_KEY_SIZE, &proxPeriphCBs );
  }

  if ( ( status == SUCCESS ) && ( services & PP_IM_ALETR_SERVICE ) )
  {
    // Register Link Loss attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( imAlertAttrTbl, GATT_NUM_ATTRS( imAlertAttrTbl ),
                                          GATT_MAX_ENCRYPT_KEY_SIZE, &proxPeriphCBs );
  }
  
  if ( ( status == SUCCESS )  && ( services & PP_TX_PWR_LEVEL_SERVICE ) )
  {
    // Register Tx Power Level attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( txPwrLevelAttrTbl, GATT_NUM_ATTRS( txPwrLevelAttrTbl ),
                                          GATT_MAX_ENCRYPT_KEY_SIZE, &proxPeriphCBs );
  }

  return ( status );
}
Exemple #2
0
/**
 * @fn      UartProfile_AddService
 *
 * @brief   Initializes the Simple Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t UartProfile_AddService(void)
{
	uint8	status = SUCCESS;

	// Initialize Client Characteristic Configuration attributes
	GATTServApp_InitCharCfg(INVALID_CONNHANDLE, uartServ2CharCfg);

	// Register with Link DB to receive link status change callback
	linkDB_Register(UartProfile_HandleConnStatusCB);

	// Register GATT attribute list and CBs with GATT Server App
	GATTServApp_RegisterService(uartServ1AttrTbl, GATT_NUM_ATTRS(uartServ1AttrTbl), &uartServ1CBs);
	GATTServApp_RegisterService(uartServ2AttrTbl, GATT_NUM_ATTRS(uartServ2AttrTbl), &uartServ2CBs);
	return (status);
}
/*********************************************************************
 * @fn      Audio_SetParameter
 *
 * @brief   Set an Audio Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to write
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16 will be cast to
 *          uint16 pointer).
 *
 * @return  SUCCESS, bleInvalidRange, INVALIDPARAMETER, or return
 *          value of GATTServApp_ProcessCharCfg
 */
bStatus_t Audio_SetParameter(uint8 param, uint8 len, void *value)
{
  bStatus_t ret = SUCCESS;

  switch (param)
  {
    case AUDIOPROFILE_START:
      if (len == sizeof (audioProfileStart))
      {
        audioProfileStart = *((uint8*)value);

        // See if Notifications have been enabled and send
        ret = GATTServApp_ProcessCharCfg(audioProfileStartConfig,
                                         &audioProfileStart,
                                         FALSE,
                                         audioProfileAttrTbl,
                                         GATT_NUM_ATTRS(audioProfileAttrTbl),
                                         INVALID_TASK_ID,
                                         audioProfile_ReadAttrCB);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case AUDIOPROFILE_AUDIO:
      {
        VOID memcpy(audioProfileAudio, value, BLEAUDIO_NOTSIZE);

        // See if Notifications have been enabled and send
        ret = GATTServApp_ProcessCharCfg(audioProfileAudioConfig,
                                         (uint8_t *)audioProfileAudio,
                                         FALSE,
                                         audioProfileAttrTbl,
                                         GATT_NUM_ATTRS(audioProfileAttrTbl),
                                         INVALID_TASK_ID,
                                         audioProfile_ReadAttrCB);
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }

  return ret;
}
/*********************************************************************
 * @fn      OADTarget_getNextBlockReq
 *
 * @brief   Process the Request for next image block.
 *
 * @param   connHandle - connection message was received on
 * @param   blkNum - block number to request from OAD Manager.
 *
 * @return  None
 */
static void OADTarget_getNextBlockReq(uint16_t connHandle, uint16_t blkNum)
{
  uint16_t value = GATTServApp_ReadCharCfg(connHandle, oadImgBlockConfig);

  // If notifications enabled
  if (value & GATT_CLIENT_CFG_NOTIFY)
  {
    attHandleValueNoti_t noti;
    
    noti.pValue = GATT_bm_alloc(connHandle, ATT_HANDLE_VALUE_NOTI, 2, NULL);
    
    if (noti.pValue != NULL)
    {
      gattAttribute_t *pAttr = GATTServApp_FindAttr(oadAttrTbl, 
                                                    GATT_NUM_ATTRS(oadAttrTbl),
                                                    oadCharVals+OAD_CHAR_IMG_BLOCK);
      noti.handle = pAttr->handle;
      noti.len = 2;
      
      noti.pValue[0] = LO_UINT16(blkNum);
      noti.pValue[1] = HI_UINT16(blkNum);
      
      if (GATT_Notification(connHandle, &noti, FALSE) != SUCCESS)
      {
        GATT_bm_free((gattMsg_t *)&noti, ATT_HANDLE_VALUE_NOTI);
      }
    }
  }
}
/*********************************************************************
 * @fn      OADTarget_addService
 *
 * @brief   Initializes the OAD Service by registering GATT attributes
 *          with the GATT server. Only call this function once.
 *
 * @return  The return value of GATTServApp_RegisterForMsg().
 */
bStatus_t OADTarget_addService(void)
{
  // Allocate Client Characteristic Configuration table
  oadImgIdentifyConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                                       linkDBNumConns);
  if (oadImgIdentifyConfig == NULL)
  {
    return (bleMemAllocError);
  }
  
  // Allocate Client Characteristic Configuration table
  oadImgBlockConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                                    linkDBNumConns);
  
  if (oadImgBlockConfig == NULL)
  {
    // Free already allocated data
    ICall_free(oadImgIdentifyConfig);
    
    return (bleMemAllocError);
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, oadImgIdentifyConfig);
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, oadImgBlockConfig);

  return GATTServApp_RegisterService(oadAttrTbl, GATT_NUM_ATTRS(oadAttrTbl), 
                                     GATT_MAX_ENCRYPT_KEY_SIZE, &oadCBs);
}
Exemple #6
0
/*********************************************************************
 * @fn      HeartRate_AddService
 *
 * @brief   Initializes the Heart Rate service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t HeartRate_AddService(uint32 services)
{
  uint8 status;

  // Allocate Client Characteristic Configuration table
  heartRateMeasClientCharCfg = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                              linkDBNumConns );
  if ( heartRateMeasClientCharCfg == NULL )
  {
    return ( bleMemAllocError );
  }
  
  // Initialize Client Characteristic Configuration attributes.
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, heartRateMeasClientCharCfg);

  if (services & HEARTRATE_SERVICE)
  {
    // Register GATT attribute list and CBs with GATT Server App.
    status = GATTServApp_RegisterService(heartRateAttrTbl, 
                                         GATT_NUM_ATTRS(heartRateAttrTbl),
                                         GATT_MAX_ENCRYPT_KEY_SIZE,
                                         &heartRateCBs);
  }
  else
  {
    status = SUCCESS;
  }

  return (status);
}
/*********************************************************************
 * @fn      SimpleProfile_AddService
 *
 * @brief   Initializes the Simple Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t ExampleService_AddService( void )
{
 static uint8 excute_time =0;
 uint8 status = SUCCESS;
 
 if(excute_time > 0)          //make sure it is only excuted once, because everytime it excuted, it add the attr to the list ,no matter wheather it exists in it.
   return(status);
 else
   excute_time++;
 
 HalLcdWriteStringValue("excute_time",excute_time,10,HAL_LCD_LINE_6);
  


  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar2Config );

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( simpleProfile_HandleConnStatusCB );  
  

    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( simpleProfileAttrTbl, 
                                          GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                          &simpleProfileCBs );


  return ( status );
}
/*********************************************************************
 * @fn      ClimbProfile_AddService
 *
 * @brief   Initializes the Simple Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t ClimbProfile_AddService( uint32 services )
{
  uint8 status;

  // Allocate Client Characteristic Configuration table
  climbProfileChar1Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                            linkDBNumConns );
  if ( climbProfileChar1Config == NULL )
  {     
    return ( bleMemAllocError );
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, climbProfileChar1Config );

  if ( services & CLIMBPROFILE_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( climbProfileAttrTbl,
                                          GATT_NUM_ATTRS( climbProfileAttrTbl ),
                                          GATT_MAX_ENCRYPT_KEY_SIZE,
                                          &climbProfileCBs );
  }
  else
  {
    status = SUCCESS;
  }

  return ( status );
}
Exemple #9
0
/*********************************************************************
 * @fn      Pir_SetParameter
 *
 * @brief   Set a parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16 will be cast to
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t Pir_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
    case SENSOR_DATA:
    if ( len == SENSOR_DATA_LEN )
    {
      VOID osal_memcpy( sensorData, value, SENSOR_DATA_LEN );
      // See if Notification has been enabled
      GATTServApp_ProcessCharCfg( sensorDataConfig, sensorData, FALSE,
                                 sensorAttrTable, GATT_NUM_ATTRS( sensorAttrTable ),
                                 INVALID_TASK_ID );
    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }

  return ( ret );
}
/*********************************************************************
 * @fn      SimpleProfile_AddService
 *
 * @brief   Initializes the Simple Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t SimpleProfile_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Allocate Client Characteristic Configuration table
  simpleProfileChar4Config = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                              linkDBNumConns );
  if ( simpleProfileChar4Config == NULL )
  {
    return ( bleMemAllocError );
  }

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar4Config );

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( simpleProfile_HandleConnStatusCB );

  if ( services & SIMPLEPROFILE_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( simpleProfileAttrTbl,
                                          GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                          GATT_MIN_ENCRYPT_KEY_SIZE,
                                          &simpleProfileCBs );
  }

  return ( status );
}
Exemple #11
0
/*********************************************************************
 * @fn      SK_AddService
 *
 * @brief   Initializes the Simple Key service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t SK_AddService(uint32 services)
{
  uint8 status = SUCCESS;

  // Allocate Client Characteristic Configuration table
  skConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                            linkDBNumConns);
  if (skConfig == NULL)
  {
    return (bleMemAllocError);
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, skConfig); 
  
  if (services & SK_SERVICE)
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService(simplekeysAttrTbl, 
                                         GATT_NUM_ATTRS(simplekeysAttrTbl),
                                         GATT_MAX_ENCRYPT_KEY_SIZE,
                                         &skCBs);
  }

  return (status);
}
/*********************************************************************
 * @fn      ClimbProfile_SetParameter
 *
 * @brief   Set a Simple Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to write
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16 will be cast to
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t ClimbProfile_SetParameter( uint8 param, uint8 len, void *value )
{
    bStatus_t ret = SUCCESS;
    switch ( param )
    {
    case CLIMBPROFILE_CHAR1:

        if( len <=  CLIMBPROFILE_CHAR1_LEN) {
            VOID memcpy( climbProfileChar1, value, CLIMBPROFILE_CHAR1_LEN );
//    	  climbProfileChar1 = (uint8*)value;
            /*
                	  attHandleValueNoti_t noti;
                	  noti.len = len;
                	  noti.handle = climbProfileAttrTbl[2].handle;
                	  ret = GATT_Notification(0,&noti, FALSE);
             */

            GATTServApp_ProcessCharCfg( climbProfileChar1Config, climbProfileChar1, FALSE,
                                        climbProfileAttrTbl, GATT_NUM_ATTRS( climbProfileAttrTbl ),
                                        INVALID_TASK_ID, climbProfile_ReadAttrCB );

        }
        else
        {
            ret = bleInvalidRange;
        }
        break;

    default:
        ret = INVALIDPARAMETER;
        break;
    }

    return ( ret );
}
/*********************************************************************
 * @fn      Audio_AddService
 *
 * @brief   Initializes the Audio Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  SUCCESS, bleMemAllocError, or return value of
 *          GATTServApp_RegisterService
 */
bStatus_t Audio_AddService(void)
{
  uint8 status = SUCCESS;

  // Allocate Audio Cmd Client Characteristic Configuration table
  audioProfileStartConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t)*
                                                          linkDBNumConns );
  if (audioProfileStartConfig == NULL)
  {
    return bleMemAllocError;
  }

  // Initialize Audio Cmd Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, audioProfileStartConfig);

  // Allocate Audio Stream Client Characteristic Configuration table
  audioProfileAudioConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t)*
                                                          linkDBNumConns);
  if (audioProfileAudioConfig == NULL)
  {
    return bleMemAllocError;
  }

  // Initialize Audio Stream Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, audioProfileAudioConfig);

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService(audioProfileAttrTbl,
                                       GATT_NUM_ATTRS(audioProfileAttrTbl),
                                       GATT_MAX_ENCRYPT_KEY_SIZE,
                                       &audioProfileCBs);

  return status;
}
/*********************************************************************
 * @fn          simpleProfile_ProcessCharCfg
 *
 * @brief       Process Client Charateristic Configuration change.
 *
 * @param       charCfgTbl - characteristic configuration table
 * @param       pValue - pointer to attribute value
 * @param       authenticated - whether an authenticated link is required
 *
 * @return      none
 */
static void simpleProfile_ProcessCharCfg( gattCharCfg_t *charCfgTbl, 
                                     uint8 *pValue, uint8 authenticated )
{
  for ( uint8 i = 0; i < GATT_MAX_NUM_CONN; i++ )
  {
    gattCharCfg_t *pItem = &(charCfgTbl[i]);

    if ( ( pItem->connHandle != INVALID_CONNHANDLE ) &&
         ( pItem->value != GATT_CFG_NO_OPERATION ) )
    {
      gattAttribute_t *pAttr;
  
      // Find the characteristic value attribute 
      pAttr = GATTServApp_FindAttr( simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ), pValue );
      if ( pAttr != NULL )
      {
        attHandleValueNoti_t noti;
    
        // If the attribute value is longer than (ATT_MTU - 3) octets, then
        // only the first (ATT_MTU - 3) octets of this attributes value can
        // be sent in a notification.
        if ( simpleProfile_ReadAttrCB( pItem->connHandle, pAttr, noti.value,
                                  &noti.len, 0, (ATT_MTU_SIZE-3) ) == SUCCESS )
        {
          noti.handle = pAttr->handle;
  
          if ( pItem->value & GATT_CLIENT_CFG_NOTIFY )
          {
            VOID GATT_Notification( pItem->connHandle, &noti, authenticated );
          }
        }
      }
    }
  } // for
}
Exemple #15
0
/*********************************************************************
 * @fn      DevInfo_AddService
 *
 * @brief   Initializes the Device Information service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t DevInfo_AddService( void )
{
  // Register GATT attribute list and CBs with GATT Server App
  return GATTServApp_RegisterService( devInfoAttrTbl,
                                      GATT_NUM_ATTRS( devInfoAttrTbl ),
                                      &devInfoCBs );
}
Exemple #16
0
/*********************************************************************
 * @fn      SK_AddService
 *
 * @brief   Initializes the Simple Key service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t SK_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  for ( uint8 i = 0; i < GATT_MAX_NUM_CONN; i++ )
  {
    skConfig[i].connHandle = INVALID_CONNHANDLE;
    skConfig[i].value = GATT_CFG_NO_OPERATION;

  }

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( sk_HandleConnStatusCB );  
  
  
  if ( services & SK_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( simplekeysAttrTbl, GATT_NUM_ATTRS( simplekeysAttrTbl ),
                                          sk_ReadAttrCB, sk_WriteAttrCB, NULL );
  }

  return ( status );
}
Exemple #17
0
/*********************************************************************
 * @fn      SK_SetParameter
 *
 * @brief   Set a Simple Key Profile parameter.
 *
 * @param   param  - Profile parameter ID
 * @param   len    - length of data to write
 * @param   pValue - pointer to data to write.  This is dependent on
 *                   the parameter ID and WILL be cast to the appropriate 
 *                   data type (example: data type of uint16 will be cast to 
 *                   uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t SK_SetParameter(uint8 param, uint8 len, void *pValue)
{
  bStatus_t ret = SUCCESS;
  switch (param)
  {
    case SK_KEY_ATTR:
      if (len == sizeof(uint8)) 
      {
        skKeyPressed = *((uint8*)pValue);
        
        // See if Notification/Indication has been enabled
        GATTServApp_ProcessCharCfg(skConfig, &skKeyPressed, FALSE, 
                                   simplekeysAttrTbl, 
                                   GATT_NUM_ATTRS(simplekeysAttrTbl),
                                   INVALID_TASK_ID, SK_readAttrCB);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    default:
      ret = INVALIDPARAMETER;
      break;
  }
  
  return (ret);
}
Exemple #18
0
/*
 * BatteryService_SetParameter - Set a BatteryService parameter.
 *
 *    param - Profile parameter ID
 *    len   - length of data to write
 *    value - pointer to data to write.  This is dependent on
 *            the parameter ID and may be cast to the appropriate 
 *            data type (example: data type of uint16_t will be cast to 
 *            uint16_t pointer).
 */
bStatus_t BatteryService_SetParameter( uint8_t param, uint16_t len, void *value )
{
  bStatus_t ret = SUCCESS;
  switch ( param )
  {
    case BS_BATTERY_LEVEL_ID:
      if ( len <= BS_BATTERY_LEVEL_LEN &&
           len >= BS_BATTERY_LEVEL_LEN_MIN ) 
      {
        memcpy(bs_Battery_LevelVal, value, len);
        bs_Battery_LevelValLen = len; // Update length for read and get.

        // Try to send notification.
        GATTServApp_ProcessCharCfg( bs_Battery_LevelConfig, (uint8_t *)&bs_Battery_LevelVal, FALSE,
                                    Battery_ServiceAttrTbl, GATT_NUM_ATTRS( Battery_ServiceAttrTbl ),
                                    INVALID_TASK_ID,  Battery_Service_ReadAttrCB);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }
  return ret;
}
/*********************************************************************
 * @fn      OADTarget_rejectImage
 *
 * @brief   Reject the Image identified by the OAD manager, send back
 *          active image version, length and UID to manager.
 *
 * @param   connHandle - connection message was received on.
 * @param   pImgHdr    - pointer to the img_hdr_t data to send.
 *
 * @return  None.
 */
static void OADTarget_rejectImage(uint16_t connHandle, img_hdr_t *pImgHdr)
{
  uint16_t value = GATTServApp_ReadCharCfg(connHandle, oadImgIdentifyConfig);

  // If notifications enabled
  if (value & GATT_CLIENT_CFG_NOTIFY)
  {
    attHandleValueNoti_t noti;
    
    noti.pValue = GATT_bm_alloc(connHandle, ATT_HANDLE_VALUE_NOTI, 8, NULL);
    
    if (noti.pValue != NULL)
    {
      gattAttribute_t *pAttr = GATTServApp_FindAttr(oadAttrTbl,
                                                    GATT_NUM_ATTRS(oadAttrTbl),
                                                    oadCharVals+OAD_CHAR_IMG_IDENTIFY);
      noti.handle = pAttr->handle;
      noti.len = OAD_IMG_HDR_SIZE;
      
      noti.pValue[0] = LO_UINT16(pImgHdr->ver);
      noti.pValue[1] = HI_UINT16(pImgHdr->ver);

      noti.pValue[2] = LO_UINT16(pImgHdr->len);
      noti.pValue[3] = HI_UINT16(pImgHdr->len);

      (void)memcpy(noti.pValue+4, pImgHdr->uid, sizeof(pImgHdr->uid));

      if (GATT_Notification(connHandle, &noti, FALSE) != SUCCESS)
      {
        GATT_bm_free((gattMsg_t *)&noti, ATT_HANDLE_VALUE_NOTI);
      }
    }
  }
}
/*********************************************************************
 * @fn      Test_AddService
 *
 * @brief   Initializes the Test Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Test_AddService(void)
{
  // Register GATT attribute list and CBs with GATT Server App
  return GATTServApp_RegisterService( testAttrTable,
                                      GATT_NUM_ATTRS (testAttrTable),
                                      GATT_MAX_ENCRYPT_KEY_SIZE,
                                      &testCBs );
}
Exemple #21
0
/*********************************************************************
 * @fn      Reset_addService
 *
 * @brief   Initializes the OAD Reset service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   none
 *
 * @return  Success or Failure
 */
uint8_t Reset_addService(void)
{
    // Register GATT attribute list and CBs with GATT Server App
    return GATTServApp_RegisterService(resetServiceAttrTbl,
                                       GATT_NUM_ATTRS(resetServiceAttrTbl),
                                       GATT_MAX_ENCRYPT_KEY_SIZE,
                                       &resetServiceCBs);
}
/*********************************************************************
 * @fn      Display_addService
 *
 * @brief   Initializes the Sensor Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t Display_addService(void)
{  
  // Register GATT attribute list and CBs with GATT Server App
  return GATTServApp_RegisterService( sensorAttrTable,
                                      GATT_NUM_ATTRS (sensorAttrTable),
                                      GATT_MAX_ENCRYPT_KEY_SIZE,
                                      &sensorCBs );
}
Exemple #23
0
/*********************************************************************
 * @fn      proxReporter_AddService
 *
 * @brief   Initializes the Proximity Reporter service by
 *          registering GATT attributes with the GATT server.
 *          Only call this function once.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return   Success or Failure
 */
bStatus_t ProxReporter_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  if ( services & PP_LINK_LOSS_SERVICE )
  {
    // Register Link Loss attribute list and CBs with GATT Server App  
    status = GATTServApp_RegisterService( linkLossAttrTbl, 
                                          GATT_NUM_ATTRS( linkLossAttrTbl ),
                                          GATT_MAX_ENCRYPT_KEY_SIZE,
                                          &proxReporterCBs );
  }

  if ( ( status == SUCCESS ) && ( services & PP_IM_ALETR_SERVICE ) )
  {
    // Register Link Loss attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( imAlertAttrTbl, 
                                          GATT_NUM_ATTRS( imAlertAttrTbl ),
                                          GATT_MAX_ENCRYPT_KEY_SIZE,
                                          &proxReporterCBs );
  }
  
  if ( ( status == SUCCESS )  && ( services & PP_TX_PWR_LEVEL_SERVICE ) )
  {
    // Allocate Client Characteristic Configuration table
    txPwrLevelConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                        linkDBNumConns );
    if ( txPwrLevelConfig != NULL )
    {
      // Initialize Client Characteristic Configuration attributes
      GATTServApp_InitCharCfg( INVALID_CONNHANDLE, txPwrLevelConfig ); 
      
      // Register Tx Power Level attribute list and CBs with GATT Server App
      status = GATTServApp_RegisterService( txPwrLevelAttrTbl, 
                                            GATT_NUM_ATTRS( txPwrLevelAttrTbl ),
                                            GATT_MAX_ENCRYPT_KEY_SIZE,
                                            &proxReporterCBs );
    }
    else
    {
      status = bleMemAllocError;
    }
  }

  return ( status );
}
/*********************************************************************
 * @fn      Lights_addService
 *
 * @brief   Initializes the Lights Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t Lights_addService(void)
{

  // Register GATT attribute list and CBs with GATT Server App
  return GATTServApp_RegisterService(lightsProfileAttrTbl, 
                                     GATT_NUM_ATTRS(lightsProfileAttrTbl),
                                     GATT_MAX_ENCRYPT_KEY_SIZE,
                                     &lightsProfileCBs);
}
/*********************************************************************
 * @fn      Glucose_AddService
 *
 * @brief   Initializes the Glucose   service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Glucose_AddService(uint32 services)
{
    uint8 status;

    // Allocate Client Characteristic Configuration table
    glucoseMeasConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                        linkDBNumConns );
    if ( glucoseMeasConfig == NULL )
    {
        return ( bleMemAllocError );
    }

    // Allocate Client Characteristic Configuration table
    glucoseContextConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                           linkDBNumConns );
    if ( glucoseContextConfig == NULL )
    {
        // Free already allocated data
        osal_mem_free( glucoseMeasConfig );

        return ( bleMemAllocError );
    }

    // Allocate Client Characteristic Configuration table
    glucoseControlConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                           linkDBNumConns );
    if ( glucoseControlConfig == NULL )
    {
        // Free already allocated data
        osal_mem_free( glucoseMeasConfig );
        osal_mem_free( glucoseContextConfig );

        return ( bleMemAllocError );
    }

    // Initialize Client Characteristic Configuration attributes.
    GATTServApp_InitCharCfg(INVALID_CONNHANDLE, glucoseMeasConfig);
    GATTServApp_InitCharCfg(INVALID_CONNHANDLE, glucoseContextConfig);
    GATTServApp_InitCharCfg(INVALID_CONNHANDLE, glucoseControlConfig);

    if (services & GLUCOSE_SERVICE)
    {
        // Register GATT attribute list and CBs with GATT Server App.
        status = GATTServApp_RegisterService(glucoseAttrTbl,
                                             GATT_NUM_ATTRS(glucoseAttrTbl),
                                             GATT_MAX_ENCRYPT_KEY_SIZE,
                                             &glucoseCBs);
    }
    else
    {
        status = SUCCESS;
    }

    return (status);
}
Exemple #26
0
/*********************************************************************
 * @fn      OADTarget_AddService
 *
 * @brief   Initializes the OAD Service by registering GATT attributes
 *          with the GATT server. Only call this function once.
 *
 * @return  The return value of GATTServApp_RegisterForMsg().
 */
bStatus_t OADTarget_AddService(void)
{
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, oadImgIdentifyConfig );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, oadImgBlockConfig );

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( oadHandleConnStatusCB );

  return GATTServApp_RegisterService(oadAttrTbl, GATT_NUM_ATTRS(oadAttrTbl), &oadCBs);
}
Exemple #27
0
/*********************************************************************
* @fn      CcService_SetParameter
*
* @brief   Set a Simple Profile parameter.
*
* @param   param - Profile parameter ID
* @param   len - length of data to right
* @param   value - pointer to data to write.  This is dependent on
*          the parameter ID and WILL be cast to the appropriate
*          data type (example: data type of uint16 will be cast to
*          uint16 pointer).
*
* @return  bStatus_t
*/
bStatus_t CcService_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
  case CCSERVICE_CHAR1:
    if ( len == CCSERVICE_CHAR1_LEN )
    {
      VOID osal_memcpy(ccServiceChar1, value, CCSERVICE_CHAR1_LEN );

      // See if Notification has been enabled
      GATTServApp_ProcessCharCfg( ccDataConfig, ccServiceChar1, FALSE,
                                 ccServiceAttrTbl, GATT_NUM_ATTRS( ccServiceAttrTbl ),
                                 INVALID_TASK_ID, ccService_ReadAttrCB );

    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

  case CCSERVICE_CHAR2:
    if ( len == CCSERVICE_CHAR2_LEN )
    {
      // Should not write to this value other than startup
      VOID osal_memcpy( ccServiceChar2, value, CCSERVICE_CHAR2_LEN );
    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

  case CCSERVICE_CHAR3:
    if ( len == sizeof ( uint8 ) )
    {
      // Should not write to this value other than startup
      ccServiceChar3 = *((uint8*)value);
    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

  default:
    ret = INVALIDPARAMETER;
    break;
  }

  return ( ret );
}
Exemple #28
0
/**
 * @fn      Batt_AddService
 *
 * @brief   Initializes the Battery Service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t Batt_AddService(void)
{
	uint8 status = SUCCESS;

	// Initialize Client Characteristic Configuration attributes
	GATTServApp_InitCharCfg(INVALID_CONNHANDLE, battLevelClientCharCfg);

	// Register GATT attribute list and CBs with GATT Server App
	status = GATTServApp_RegisterService(battAttrTbl, GATT_NUM_ATTRS(battAttrTbl), &battCBs);

	return (status);
}
Exemple #29
0
/*********************************************************************
 * @fn      ProxReporter_SetParameter
 *
 * @brief   Set a Proximity Reporter parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t ProxReporter_SetParameter(uint8 param, uint8 len, void *value)
{
  bStatus_t ret = SUCCESS;
  
  switch (param)
  {
    case PP_LINK_LOSS_ALERT_LEVEL:
      if ((len == sizeof (uint8)) && 
          ((*((uint8*)value) <= PP_ALERT_LEVEL_HIGH))) 
      {
        llAlertLevel = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    case PP_IM_ALERT_LEVEL:
      if (len == sizeof (uint8)) 
      {
        imAlertLevel = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case PP_TX_POWER_LEVEL:
      if (len == sizeof (int8)) 
      {
        txPwrLevel = *((int8*)value);

        // See if notifications have been enabled.
        GATTServApp_ProcessCharCfg(txPwrLevelConfig, (uint8 *)&txPwrLevel, 
                                   FALSE, txPwrLevelAttrTbl, 
                                   GATT_NUM_ATTRS(txPwrLevelAttrTbl),
                                   INVALID_TASK_ID, ProxReporter_ReadAttrCB);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }
  
  return (ret);
}
Exemple #30
0
/*
 * TxPower_AddService- Initializes the TxPower service by registering
 *          GATT attributes with the GATT server.
 *
 */
bStatus_t TxPower_AddService( void )
{
  uint8_t status;

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( Tx_PowerAttrTbl, 
                                        GATT_NUM_ATTRS( Tx_PowerAttrTbl ),
                                        GATT_MAX_ENCRYPT_KEY_SIZE,
                                        &Tx_PowerCBs );

  return ( status );
}