/*********************************************************************
 * @fn          simpleProfile_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 
                            uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
{
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }
 
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch ( uuid )
    {
      // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
      // gattserverapp handles those reads

      // characteristics 1 and 2 have read permissions
      // characteritisc 3 does not have read permissions; therefore it is not
      //   included here
      // characteristic 4 does not have read permissions, but because it
      //   can be sent as a notification, it is included here
      case SIMPLEPROFILE_CHAR1_UUID:
      case SIMPLEPROFILE_CHAR2_UUID:
      case SIMPLEPROFILE_CHAR4_UUID:
        *pLen = 1;
        pValue[0] = *pAttr->pValue;
        break;

      case SIMPLEPROFILE_CHAR5_UUID:
        *pLen = SIMPLEPROFILE_CHAR5_LEN;
        VOID osal_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
        break;
        
      default:
        // Should never get here! (characteristics 3 and 4 do not have read permissions)
        *pLen = 0;
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    *pLen = 0;
    status = ATT_ERR_INVALID_HANDLE;
  }

  return ( status );
}
Ejemplo n.º 2
0
/*********************************************************************
 * @fn          lights_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 * @param       method - type of read message 
 *
 * @return      Success or Failure
 */
static bStatus_t lights_ReadAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, 
                                   uint8_t *pValue, uint16_t *pLen,
                                   uint16_t offset, uint16_t maxLen,
                                   uint8_t method)
{
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }
 
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch ( uuid )
    {
      // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
      // gattserverapp handles those reads

      case LIGHTSPROFILE_RED_UUID:
      case LIGHTSPROFILE_GREEN_UUID:
      case LIGHTSPROFILE_BLUE_UUID:
      case LIGHTSPROFILE_WHITE_UUID:
        *pLen = 1;
        pValue[0] = *pAttr->pValue;
        break;

      case LIGHTSPROFILE_RGBW_UUID:
        *pLen = LIGHTSPROFILE_RGBW_LEN;
        VOID memcpy( pValue, pAttr->pValue, LIGHTSPROFILE_RGBW_LEN );
        break;
        
      default:
        // Should never get here! (characteristics 3 and 4 do not have read permissions)
        *pLen = 0;
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    *pLen = 0;
    status = ATT_ERR_INVALID_HANDLE;
  }

  return ( status );
}
/*********************************************************************
 * @fn          sensor_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 * @param       method - type of read message 
 *
 * @return      SUCCESS, blePending or Failure
 */
static bStatus_t sensor_ReadAttrCB(uint16_t connHandle, gattAttribute_t *pAttr,
                                    uint8_t *pValue, uint16_t *pLen, 
                                    uint16_t offset, uint16_t maxLen,
                                    uint8_t method)
{
  uint16_t uuid;
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if (gattPermitAuthorRead(pAttr->permissions))
  {
    // Insufficient authorization
    return (ATT_ERR_INSUFFICIENT_AUTHOR);
  }

  // Make sure it's not a blob operation (no attributes in the profile are long)
  if (offset > 0)
  {
    return (ATT_ERR_ATTR_NOT_LONG);
  }

  if (utilExtractUuid16(pAttr,&uuid) == FAILURE) {
    // Invalid handle
    *pLen = 0;
    return ATT_ERR_INVALID_HANDLE;
  }

  switch (uuid)
  {
    // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
    // gattserverapp handles those reads
    case REGISTER_DATA_UUID:
      sensor_readRegister();
      *pLen = registerAddress[0];
      memcpy(pValue, pAttr->pValue, *pLen);
      break;

    case REGISTER_ADDR_UUID:
      *pLen = REGISTER_ADDRESS_LEN;
      memcpy(pValue, pAttr->pValue, REGISTER_ADDRESS_LEN);
      break;
      
    case REGISTER_DEV_UUID:
      *pLen = REGISTER_DEVICE_LEN;
      memcpy(pValue, pAttr->pValue, REGISTER_DEVICE_LEN);
      break;

    default:
      *pLen = 0;
      status = ATT_ERR_ATTR_NOT_FOUND;
      break;
    }

  return (status);
}
Ejemplo n.º 4
0
/*********************************************************************
 * @fn          sensor_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 sensor_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                            uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen, uint8 method)
{
  uint16 uuid;
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }

  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }

  if (utilExtractUuid16(pAttr,&uuid) == FAILURE) {
    // Invalid handle
    *pLen = 0;
    return ATT_ERR_INVALID_HANDLE;
  }

  switch ( uuid )
  {
    // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
    // gattserverapp handles those reads
    case SENSOR_DATA_UUID:
      *pLen = SENSOR_DATA_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, SENSOR_DATA_LEN );
      break;

    case SENSOR_CALIBR_UUID:
      *pLen = SENSOR_CALI_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, SENSOR_CALI_LEN );
      break;

    case SENSOR_CONFIG_UUID:
    case SENSOR_PERIOD_UUID:
      *pLen = 1;
      pValue[0] = *pAttr->pValue;
      break;

    default:
      *pLen = 0;
      status = ATT_ERR_ATTR_NOT_FOUND;
      break;
    }

  return ( status );
}
static uint8 simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
{
  
//  LCDPrintText("Profile_ReadAttr",0,PRINT_STRING);
  
  
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
      LCDPrintText("no permission",1,PRINT_STRING);
  
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)

 
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
            switch ( uuid )
            {

                    case SIMPLEPROFILE_CHAR1_UUID:{

			  if ( offset >=SIMPLEPROFILE_CHAR1_ATCLEN )
    				    return ( ATT_ERR_ATTR_NOT_LONG );

			   // determine read length
        		   *pLen = MIN(maxLen, SIMPLEPROFILE_CHAR1_ATCLEN - offset);			                          
                            osal_memcpy( pValue, &simpleProfileChar1[offset], *pLen );


//						 LCDPrintText("offset",offset,PRINT_VALUE);
//						 LCDPrintText("maxLen",maxLen,PRINT_VALUE);
                        break;
                    }
                        
                    case SIMPLEPROFILE_CHAR2_UUID:{
                           *pLen = 1;
                            pValue[0] = *pAttr->pValue;
                    break;
                    }                    
               
            }
  }

  return ( status );
}
Ejemplo n.º 6
0
/*********************************************************************
 * @fn          roboRoachProfile_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 roboRoachProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 
                            uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
{
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }
 
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch ( uuid )
    {
      // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
      // gattserverapp handles those reads

      // Freq, Pulse, NumPulses, and Random Mode characteristics are all Readable.
      case ROBOROACH_CHAR_FREQUENCY_UUID:
      case ROBOROACH_CHAR_PULSE_WIDTH_UUID:
      case ROBOROACH_CHAR_NUM_PULSES_UUID:
      case ROBOROACH_CHAR_RANDOM_MODE_UUID:
        *pLen = 1;
        pValue[0] = *pAttr->pValue;
        break;
  
      default:
        // Should never get here! (Stimulation characteristics do not have read permissions)
        *pLen = 0;
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    *pLen = 0;
    status = ATT_ERR_INVALID_HANDLE;
  }

  return ( status );
}
Ejemplo n.º 7
0
/*********************************************************************
 * @fn          thermometer_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 thermometer_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 
                            uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
{
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }
 
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch ( uuid )
    {
      case THERMOMETER_TYPE_UUID:
        *pLen = THERMOMETER_TYPE_LEN;
        VOID osal_memcpy( pValue, &thermometerType, THERMOMETER_TYPE_LEN ) ;
        break;
        
      case THERMOMETER_INTERVAL_UUID:
        *pLen = THERMOMETER_INTERVAL_LEN;
        VOID osal_memcpy( pValue, &thermometerInterval, THERMOMETER_INTERVAL_LEN ) ;
        break;

      case THERMOMETER_IRANGE_UUID:
        *pLen = THERMOMETER_IRANGE_LEN;
         VOID osal_memcpy( pValue, &thermometerIRange, THERMOMETER_IRANGE_LEN ) ;
        break;        
        
      default:
        *pLen = 0;
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  
  return ( status );
}
Ejemplo n.º 8
0
/*********************************************************************
 * @fn          counter_ReadAttrCB
 *
 * @brief       Read an attribute. Every time a GATT client device wants to read 
 *              from an attribute in the profile, this function gets called.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 counter_ReadAttrCB( uint16_t connHandle, gattAttribute_t *pAttr,
        uint8_t *pValue, uint16_t *pLen,
        uint16_t offset, uint16_t maxLen,
        uint8_t method )
{
  uint16 uuid;
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }

  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }

  if (utilExtractUuid16(pAttr,&uuid) == FAILURE) {
    // Invalid handle
    *pLen = 0;
    return ATT_ERR_INVALID_HANDLE;
  }

  switch ( uuid )
  {
    // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
    // gattserverapp handles those reads
    case COUNTER_DATA_UUID:
      *pLen = COUNTER_DATA_LEN;
      // copy current counter value in counterData[0] to the buffer pointed to by pValue
      memcpy( pValue, &counterData[0], COUNTER_DATA_LEN );
      counterData[0]++;
      break;

    default:
      *pLen = 0;
      status = ATT_ERR_ATTR_NOT_FOUND;
      break;
    }

  return ( status );
}
Ejemplo n.º 9
0
/*********************************************************************
 * @fn          BloodPressure_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 BloodPressure_ReadAttrCB(uint16_t connHandle, 
                                      gattAttribute_t *pAttr, uint8_t *pValue,
                                      uint16_t *pLen, uint16_t offset, 
                                      uint16_t maxLen, uint8_t method)
{
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error.
  if (gattPermitAuthorRead(pAttr->permissions))
  {
    // Insufficient authorization.
    return (ATT_ERR_INSUFFICIENT_AUTHOR);
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)
  if (offset > 0)
  {
    return (ATT_ERR_ATTR_NOT_LONG);
  }
 
  if (pAttr->type.len == ATT_BT_UUID_SIZE)
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch (uuid)
    {
      case BLOODPRESSURE_FEATURE_UUID:
        {
          *pLen = 2;
          pValue[0] = LO_UINT16(bpFeature);
          pValue[1] = HI_UINT16(bpFeature);
        }
        break;
        
      default:
        // Should never get here! 
        // (characteristics 3 and 4 do not have read permissions)
        *pLen = 0;
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  
  return (status);
}
Ejemplo n.º 10
0
/*********************************************************************
 * @fn          ccService_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 * @param       method - type of read message 
 *
 * @return      SUCCESS, blePending or Failure
 */
static bStatus_t ccService_ReadAttrCB(uint16_t connHandle, 
                                      gattAttribute_t *pAttr,
                                      uint8_t *pValue, uint16_t *pLen, 
                                      uint16_t offset, uint16_t maxLen,
                                      uint8_t method)
{
  bStatus_t status = SUCCESS;
  uint16_t uuid;

  // If attribute permissions require authorization to read, return error
  if (gattPermitAuthorRead(pAttr->permissions))
  {
    // Insufficient authorization
    return (ATT_ERR_INSUFFICIENT_AUTHOR);
  }

  // Make sure it's not a blob operation (no attributes in the profile are long)
  if (offset > 0)
  {
    return (ATT_ERR_ATTR_NOT_LONG);
  }

  if (utilExtractUuid16(pAttr,&uuid) == FAILURE)
  {
    // Invalid handle
    *pLen = 0;
    return ATT_ERR_INVALID_HANDLE;
  }

  switch (uuid)
  {
  case CCSERVICE_CHAR1_UUID:
    *pLen = CCSERVICE_CHAR1_LEN;
    memcpy(pValue, pAttr->pValue, CCSERVICE_CHAR1_LEN);
    break;
    
  default:
    *pLen = 0;
    status = ATT_ERR_ATTR_NOT_FOUND;
    break;
  }

  return (status);
}
Ejemplo n.º 11
0
/*********************************************************************
 * @fn          simpleProfile_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 biscuit_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 
                            uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
{
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }
 
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch ( uuid )
    {
      // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
      // gattserverapp handles those reads

      // characteristics 1 and 2 have read permissions
      // characteritisc 3 does not have read permissions; therefore it is not
      //   included here
      // characteristic 4 does not have read permissions, but because it
      //   can be sent as a notification, it is included here
      case VENDOR_NAME_CHAR_UUID:
        *pLen = VENDOR_NAME_SIZE;
        VOID osal_memcpy( pValue, pAttr->pValue, VENDOR_NAME_SIZE);
        break;
        
      case TX_DATA_CHAR_UUID:
      case RESET_WRITE_CHAR_UUID:
        *pLen = 1;
        pValue[0] = *pAttr->pValue;
        break;

      case LIB_VER_CHAR_UUID:
        *pLen = 2;
        VOID osal_memcpy( pValue, pAttr->pValue, 2 );
        break;
        
      default:
        // Should never get here! (characteristics 3 and 4 do not have read permissions)
        *pLen = 0;
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    const uint8 uuid[ATT_UUID_SIZE] = 
    { 
      UUID_BASE_TAIL, LO_UINT16(pAttr->type.uuid[0]), pAttr->type.uuid[1], UUID_BASE_HEAD
    };
    
    // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
    // gattserverapp handles those reads

    // characteristics 1 and 2 have read permissions
    // characteritisc 3 does not have read permissions; therefore it is not
    //   included here
    // characteristic 4 does not have read permissions, but because it
    //   can be sent as a notification, it is included here
    if ( osal_memcmp(pAttr->type.uuid, txDataCharUUID, ATT_UUID_SIZE) )
    {
      *pLen = bLen;
      VOID osal_memcpy( pValue, pAttr->pValue, bLen );     
    }
    
    else if (osal_memcmp(pAttr->type.uuid, vendorNameCharUUID, ATT_UUID_SIZE))
    {
      *pLen = 13;
      VOID osal_memcpy( pValue, pAttr->pValue, 13 );
    }
    
    else if (osal_memcmp(pAttr->type.uuid, libVerCharUUID, ATT_UUID_SIZE))
    {
      *pLen = 2;
      VOID osal_memcpy( pValue, pAttr->pValue, 2 );
    }
    
    else
    {
      // Should never get here! (characteristics 3 and 4 do not have read permissions)
      *pLen = 0;
      status = ATT_ERR_ATTR_NOT_FOUND;
    }
  }

  return ( status );
}
/*********************************************************************
 * @fn          simpleProfile_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 
                            uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
{
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }
 
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch ( uuid )
    {
      // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
      // gattserverapp handles those reads

      // characteristics 1 and 2 have read permissions
      // characteritisc 3 does not have read permissions; therefore it is not
      //   included here
      // characteristic 4 does not have read permissions, but because it
      //   can be sent as a notification, it is included here
      case SIMPLEPROFILE_CHAR1_UUID:
      case SIMPLEPROFILE_CHAR2_UUID:
      case SIMPLEPROFILE_CHAR4_UUID:
        *pLen = 1;
        pValue[0] = *pAttr->pValue;
        break;

      case SIMPLEPROFILE_CHAR6_UUID:
        /*
        //*Len = SIMPLEPROFILE_CHAR6_LEN;
        //VOID osal_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR6_LEN );
        //LCD_WRITE_STRING_VALUE( "ReadAttrCB 6 len=", simpleProfileChar6Len, 10, HAL_LCD_LINE_1 );
        *pLen = simpleProfileChar6Len;
        VOID osal_memcpy( pValue, pAttr->pValue, simpleProfileChar6Len );
        {
          // 这个变量用于表明上一次写数据到从机已经成功, 可用于判断写数据时的判断, 以确保数据的完整性
          //extern bool simpleBLEChar6DoWrite2;
          //simpleBLEChar6DoWrite2 = TRUE;
        }
        break;
        */
      case SIMPLEPROFILE_CHAR5_UUID:
      case SIMPLEPROFILE_CHAR7_UUID:
      case SIMPLEPROFILE_CHAR8_UUID:
      case SIMPLEPROFILE_CHAR9_UUID:
      case SIMPLEPROFILE_CHARA_UUID:
        {
            uint8 newValue[20];
            extern uint8 simpleProfileReadConfig(uint16 uuid, uint8 *newValue);            
            *pLen = simpleProfileReadConfig(uuid, newValue);
            VOID osal_memcpy( pValue, newValue, *pLen );
        }
        break;
        
      default:
        // Should never get here! (characteristics 3 and 4 do not have read permissions)
        *pLen = 0;
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    *pLen = 0;
    status = ATT_ERR_INVALID_HANDLE;
  }

  return ( status );
}
Ejemplo n.º 13
0
/*********************************************************************
 * @fn          txrx_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 txrx_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 
                            uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
{
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }
 
  if ( pAttr->type.len == ATT_UUID_SIZE )
  {
    if ( osal_memcmp(pAttr->type.uuid, txDataCharUUID, ATT_UUID_SIZE) )
    {
      *pLen = txDataLen;
      VOID osal_memcpy( pValue, pAttr->pValue, txDataLen );     
    }
    else if ( osal_memcmp(pAttr->type.uuid, BaudrateCharUUID, ATT_UUID_SIZE) )
    {
      //*pLen = 1;
      //VOID osal_memcpy( pValue, pAttr->pValue, 1 );
      switch(Baudrate)
      {
        case 0:   //9600
        {
          *pLen = 9;
          uint8 *str = "BAUD_9600";
          VOID osal_memcpy( pValue, str, 9 );
          break;
        }
        
        case 1:   //19200
        {
          *pLen = 10;
          uint8 *str = "BAUD_19200";
          VOID osal_memcpy( pValue, str, 10 );
          break;
        }
         
        case 2:   //38400
        {
          *pLen = 10;
          uint8 *str = "BAUD_38400";
          VOID osal_memcpy( pValue, str, 10 );
          break;
        }
        
        case 3:   //57600
        {
          *pLen = 10;
          uint8 *str = "BAUD_57600";
          VOID osal_memcpy( pValue, str, 10 );
          break;
        }
        
        case 4:   //115200
        {
          *pLen = 11;
          uint8 *str = "BAUD_115200";
          VOID osal_memcpy( pValue, str, 11 );
          break;
        }
        
        default:
          break;
      }
    }
    else if ( osal_memcmp(pAttr->type.uuid, DevNameCharUUID, ATT_UUID_SIZE) )
    {
      *pLen = DevNameLen;
      VOID osal_memcpy( pValue, pAttr->pValue, DevNameLen );     
    }
    else if ( osal_memcmp(pAttr->type.uuid, VersionCharUUID, ATT_UUID_SIZE) )
    {
      *pLen = VersionLen;
      VOID osal_memcpy( pValue, pAttr->pValue, VersionLen );     
    }
    else if ( osal_memcmp(pAttr->type.uuid, TxPowerCharUUID, ATT_UUID_SIZE) )
    {
      switch(TxPower)
      {
        case 0:   //-23dbm
        {
          *pLen = 7;
          uint8 *str = "-23 dBm";
          VOID osal_memcpy( pValue, str, 7 );
          break;
        }
        
        case 1:   //-6dbm
        {
          *pLen = 6;
          uint8 *str = "-6 dBm";
          VOID osal_memcpy( pValue, str, 6 );
          break;
        }
         
        case 2:   //0dbm
        {
          *pLen = 5;
          uint8 *str = "0 dBm";
          VOID osal_memcpy( pValue, str, 5 );
          break;
        }
        
        case 3:   //+4dbm
        {
          *pLen = 6;
          uint8 *str = "+4 dBm";
          VOID osal_memcpy( pValue, str, 6 );
          break;
        }
        
        default:
          break;
      }     
    }
    else
    {
      // Should never get here!
      *pLen = 0;
      status = ATT_ERR_ATTR_NOT_FOUND;
    }
  }

  return ( status );
}
Ejemplo n.º 14
0
/*********************************************************************
 * @fn          iBeacon_ReadAttrCB
 *
 * @brief       Read an attribute.
 *
 * @param       connHandle - connection message was received on
 * @param       pAttr - pointer to attribute
 * @param       pValue - pointer to data to be read
 * @param       pLen - length of data to be read
 * @param       offset - offset of the first octet to be read
 * @param       maxLen - maximum length of data to be read
 *
 * @return      Success or Failure
 */
static uint8 iBeacon_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 
                            uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
{
  bStatus_t status = SUCCESS;

  // If attribute permissions require authorization to read, return error
  if ( gattPermitAuthorRead( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  // Make sure it's not a blob operation (no attributes in the profile are long)
  if ( offset > 0 )
  {
    return ( ATT_ERR_ATTR_NOT_LONG );
  }
 
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch ( uuid )
    {
      // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
      // gattserverapp handles those reads

      case IBEACON_CHAR1_UUID:
        *pLen = IBEACON_CHAR1_LEN;
        VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR1_LEN );
        break;
        
      case IBEACON_CHAR2_UUID:
        *pLen = IBEACON_CHAR2_LEN;
        VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR2_LEN );
        break;
        
      case IBEACON_CHAR3_UUID:
        *pLen = IBEACON_CHAR3_LEN;
        VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR3_LEN );
        break;
        
      case IBEACON_CHAR4_UUID:
        *pLen = IBEACON_CHAR4_LEN;
        VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR4_LEN );
        break;
        
      case IBEACON_CHAR5_UUID:
        *pLen = IBEACON_CHAR5_LEN;
        VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR5_LEN );
        break;
        
      case IBEACON_CHAR6_UUID:
        *pLen = IBEACON_CHAR6_LEN;
        VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR6_LEN );
        break;
        
      case IBEACON_CHAR7_UUID:
        *pLen = IBEACON_CHAR7_LEN;
        VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR7_LEN );
        break;
       
      case IBEACON_CHAR8_UUID:
        *pLen = IBEACON_CHAR8_LEN;
        VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR8_LEN );
        break;
        
      default:
        // Should never get here! (characteristics 3 and 4 do not have read permissions)
        *pLen = 0;
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else // 128-bit UUID
  {
    if ( osal_memcmp(pAttr->type.uuid, iBeaconChar1UUID, ATT_UUID_SIZE) )
    {
      *pLen = IBEACON_CHAR1_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR1_LEN);
    }
    else if ( osal_memcmp(pAttr->type.uuid, iBeaconChar2UUID, ATT_UUID_SIZE) )
    {
      *pLen = IBEACON_CHAR2_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR2_LEN);
    }
    else if ( osal_memcmp(pAttr->type.uuid, iBeaconChar3UUID, ATT_UUID_SIZE) )
    {
      *pLen = IBEACON_CHAR3_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR3_LEN);
    }
    else if ( osal_memcmp(pAttr->type.uuid, iBeaconChar4UUID, ATT_UUID_SIZE) )
    {
      *pLen = IBEACON_CHAR4_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR4_LEN);
    }
    else if ( osal_memcmp(pAttr->type.uuid, iBeaconChar5UUID, ATT_UUID_SIZE) )
    {
      *pLen = IBEACON_CHAR5_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR5_LEN);
    }
    else if ( osal_memcmp(pAttr->type.uuid, iBeaconChar6UUID, ATT_UUID_SIZE) )
    {
      *pLen = IBEACON_CHAR6_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR6_LEN);
    }
    else if ( osal_memcmp(pAttr->type.uuid, iBeaconChar7UUID, ATT_UUID_SIZE) )
    {
      *pLen = IBEACON_CHAR7_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR7_LEN);
    }   
    else if ( osal_memcmp(pAttr->type.uuid, iBeaconChar8UUID, ATT_UUID_SIZE) )
    {
      *pLen = IBEACON_CHAR8_LEN;
      VOID osal_memcpy( pValue, pAttr->pValue, IBEACON_CHAR8_LEN);
    }
    else
    {
      *pLen = 0;
      status = ATT_ERR_INVALID_HANDLE;
    }
  }

  return ( status );
}