Пример #1
0
/*********************************************************************
* @fn      counter_WriteAttrCB
*
* @brief   Validate attribute data prior to a write operation. Every time a GATT 
*          client device wants to write to 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 written
* @param   len - length of data
* @param   offset - offset of the first octet to be written
*
* @return  Success or Failure
*/
static bStatus_t counter_WriteAttrCB( uint16_t connHandle, gattAttribute_t *pAttr,
        uint8_t *pValue, uint16_t len,
        uint16_t offset, uint8_t method )
{
  bStatus_t status = SUCCESS;
  uint16 uuid;

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

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

  switch ( uuid )
  {
    case COUNTER_DATA_UUID:
      // validate
      if ( offset != 0 ) 
      {
         status = ATT_ERR_INVALID_OFFSET;
      }
      if ( offset == 0 )
      {
        if ( len != 1 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      // Write the value
      if ( status == SUCCESS )
      {
        // Attribute consists of type|permissions|value|handle
        
        // pointer to the attribute's value part
        uint8 *pCurValue = (uint8 *)pAttr->pValue;
        
        // set attribute value to new value supplied in write operation
        *pCurValue = pValue[0];

        // save new value in variable        
        counterData[0] = pValue[0];
       // HalLedSet(HAL_LED_1, HAL_LED_MODE_ON );
      }
      break;

    default:
      // Should never get here!
      status = ATT_ERR_ATTR_NOT_FOUND;
      break;
  }

  return ( status );
}
Пример #2
0
/*********************************************************************
* @fn      sensor_WriteAttrCB
*
* @brief   Validate attribute data prior to a write operation
*
* @param   connHandle - connection message was received on
* @param   pAttr - pointer to attribute
* @param   pValue - pointer to data to be written
* @param   len - length of data
* @param   offset - offset of the first octet to be written
*
* @return  Success or Failure
*/
static bStatus_t sensor_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                           uint8 *pValue, uint8 len, uint16 offset )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  uint16 uuid;

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

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

  switch ( uuid )
  {
    case SENSOR_DATA_UUID:
      // Should not get here
      break;

    case GATT_CLIENT_CHAR_CFG_UUID:
      status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                              offset, GATT_CLIENT_CFG_NOTIFY );
      break;

    default:
      // Should never get here!
      status = ATT_ERR_ATTR_NOT_FOUND;
      break;
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && sensor_AppCBs && sensor_AppCBs->pfnSensorChange )
  {
    sensor_AppCBs->pfnSensorChange( notifyApp );
  }

  return ( status );
}
Пример #3
0
/*
 * @fn      uartServ1_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 *
 * @return  Success or Failure
 */
static bStatus_t uartServ1_WriteAttrCB(uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 len, uint16 offset)
{
	bStatus_t	status = SUCCESS;

	dmsg(("\033[40;31m0xFFE9 (Write)\033[0m\n"));

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

	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 UARTSERV1_CHAR_UUID:
			osal_memcpy(pAttr->pValue, pValue, len);

			if (uartServ1_AppCBs) {
				uartServ1_AppCBs(UARTSERV1_CHAR);
			}
			break;

		default:
			// should never get here! (characteristic 2 do not have write permissions)
			dmsg(("err\n"));
			status = ATT_ERR_ATTR_NOT_FOUND;
			break;
		}
	} else {
		// 128-bit UUID
		status = ATT_ERR_INVALID_HANDLE;
	}

	return (status);
}
Пример #4
0
/*********************************************************************
* @fn      ccService_WriteAttrCB
*
* @brief   Validate attribute data prior to a write operation
*
* @param   connHandle - connection message was received on
* @param   pAttr - pointer to attribute
* @param   pValue - pointer to data to be written
* @param   len - length of data
* @param   offset - offset of the first octet to be written
*
* @return  Success or Failure
*/
static bStatus_t ccService_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                       uint8 *pValue, uint8 len, uint16 offset, uint8 method )
{
  uint16 uuid;
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;

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

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

  switch ( uuid )
  {
  case CCSERVICE_CHAR2_UUID:

    // Validate the value
    // Make sure it's not a blob oper
    if ( offset == 0 )
    {
      if ( len != CCSERVICE_CHAR2_LEN )
      {
        status = ATT_ERR_INVALID_VALUE_SIZE;
      }
    }
    else
    {
      status = ATT_ERR_ATTR_NOT_LONG;
    }

    // Write the value
    if ( status == SUCCESS )
    {
      VOID osal_memcpy( ccServiceChar2, pValue, CCSERVICE_CHAR2_LEN );
      notifyApp = CCSERVICE_CHAR2;
    }

    break;
  case CCSERVICE_CHAR3_UUID:

    if ( offset == 0 )
    {
      if ( len != 1 )
      {
        status = ATT_ERR_INVALID_VALUE_SIZE;
      }
    }
    else
    {
      status = ATT_ERR_ATTR_NOT_LONG;
    }

    // Write the value
    if ( status == SUCCESS )
    {
      uint8 *pCurValue = (uint8 *)pAttr->pValue;
      *pCurValue = pValue[0];
      notifyApp = CCSERVICE_CHAR3;
    }

    break;

  case GATT_CLIENT_CHAR_CFG_UUID:
      status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                              offset, GATT_CLIENT_CFG_NOTIFY );
      break;

  default:
    status = ATT_ERR_ATTR_NOT_FOUND;
    break;
  }


  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && ccService_AppCBs && ccService_AppCBs->pfnCcChange )
  {
    ccService_AppCBs->pfnCcChange( notifyApp );
  }

  return ( status );
}
Пример #5
0
/*********************************************************************
 * @fn      lights_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr      - pointer to attribute
 * @param   pValue     - pointer to data to be written
 * @param   len        - length of data
 * @param   offset     - offset of the first octet to be written
 * @param   method     - type of write message 
 *
 * @return  Success or Failure
 */
static bStatus_t lights_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr,
                                    uint8_t *pValue, uint16_t len,
                                    uint16_t offset, uint8_t method)
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  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 LIGHTSPROFILE_RED_UUID:
      case LIGHTSPROFILE_GREEN_UUID:
      case LIGHTSPROFILE_BLUE_UUID:
      case LIGHTSPROFILE_WHITE_UUID:

        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        // Write the value
        if ( status == SUCCESS )
        {
          uint8 *pCurValue = (uint8 *)pAttr->pValue;        
          *pCurValue = pValue[0];

          if( pAttr->pValue == &lightsProfileRGBW[0] )
          {
            notifyApp = LIGHTSPROFILE_RED;        
          }

          if( pAttr->pValue == &lightsProfileRGBW[1] )
          {
            notifyApp = LIGHTSPROFILE_GREEN;        
          }

          if( pAttr->pValue == &lightsProfileRGBW[2] )
          {
            notifyApp = LIGHTSPROFILE_BLUE;        
          }

          if( pAttr->pValue == &lightsProfileRGBW[3] )
          {
            notifyApp = LIGHTSPROFILE_WHITE;        
          }          
        }
             
        break;

    case LIGHTSPROFILE_RGBW_UUID:
      if ( offset == 0 )
      {
        if ( len != LIGHTSPROFILE_RGBW_LEN )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;        
        memcpy( pCurValue, pValue, LIGHTSPROFILE_RGBW_LEN );

        if( (int)pAttr->pValue == (int)&lightsProfileRGBW )
        {
          notifyApp = LIGHTSPROFILE_RGBW;
        }
      }
      break;
        
      case GATT_CLIENT_CHAR_CFG_UUID:
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        break;
        
      default:
        // Should never get here!
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    status = ATT_ERR_INVALID_HANDLE;
  }

  // If a characteristic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && lights_AppCBs && lights_AppCBs->pfnLightsProfileChange )
  {
    lights_AppCBs->pfnLightsProfileChange( notifyApp );  
  }
  
  return ( status );
}
/*********************************************************************
 * @fn      sensor_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   method - type of write message 
 *
 * @return  SUCCESS, blePending or Failure
 */
static bStatus_t sensor_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr,
                                    uint8_t *pValue, uint16_t len, 
                                    uint16_t offset, uint8_t method)
{
  bStatus_t status = SUCCESS;
  uint8_t notifyApp = 0xFF;
  uint16_t uuid;
  
  // If attribute permissions require authorization to write, return error
  if (gattPermitAuthorWrite(pAttr->permissions))
  {
    // Insufficient authorization
    return (ATT_ERR_INSUFFICIENT_AUTHOR);
  }
  
  if (utilExtractUuid16(pAttr,&uuid) == FAILURE)
  {
    // Invalid handle
    return ATT_ERR_INVALID_HANDLE;
  }
  
  switch (uuid)
  {
  case REGISTER_DATA_UUID:
    // Validate the value
    // Make sure it's not a blob oper
    if (offset == 0)
    {
      if (len > REGISTER_DATA_LEN )
      {
        status = ATT_ERR_INVALID_VALUE_SIZE;
      }
    }
    else
    {
      status = ATT_ERR_ATTR_NOT_LONG;
    }
    
    // Write the value
    if (status == SUCCESS)
    {
      memcpy(pAttr->pValue, pValue, len);
      sensor_writeRegister();
    }
    break;
    
  case REGISTER_ADDR_UUID:
    // Validate the value
    // Make sure it's not a blob oper
    if (offset == 0)
    {
      if (len > REGISTER_ADDRESS_LEN )
      {
        status = ATT_ERR_INVALID_VALUE_SIZE;
      }
    }
    else
    {
      status = ATT_ERR_ATTR_NOT_LONG;
    }
    
    // Write the value
    if (status == SUCCESS)
    {
      if (pValue[0] <= REGISTER_DATA_LEN )
      {
        memcpy(pAttr->pValue, pValue, len);
        // Address changed; read data
        sensor_readRegister();
        
        if (pAttr->pValue == (uint8_t*)&registerAddress )
        {
          notifyApp = REGISTER_ADDR;
        }
      }
      else
      {
        status = ATT_ERR_INVALID_VALUE;
      }
    }
    break;
    
  case REGISTER_DEV_UUID:
    // Validate the value
    // Make sure it's not a blob oper
    if (offset == 0)
    {
      if (len != REGISTER_DEVICE_LEN )
      {
        status = ATT_ERR_INVALID_VALUE_SIZE;
      }
    }
    else
    {
      status = ATT_ERR_ATTR_NOT_LONG;
    }
    // Write the value
    if (status == SUCCESS)
    {
      if (pValue[0] < REGISTER_INTERFACE_NUM )
      {
        memcpy(pAttr->pValue, pValue, REGISTER_DEVICE_LEN);
        
        if (pAttr->pValue == (uint8_t*)&registerDeviceID )
        {
          notifyApp = REGISTER_DEV;
          // bspI2cReset();
          
          sensor_initRegister(registerDeviceID[0], registerDeviceID[1]);
        }
      }
        else
        {
          status = ATT_ERR_INVALID_VALUE;
        }
      }
      break;
      
    case GATT_CLIENT_CHAR_CFG_UUID:
      status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len,
                                              offset, GATT_CLIENT_CFG_NOTIFY);
      break;
      
    default:
      // Should never get here!
      status = ATT_ERR_ATTR_NOT_FOUND;
      break;
    }
    
    // If a characteristic value changed then callback function 
    // to notify application of change
    if ((notifyApp != 0xFF ) && sensor_AppCBs && sensor_AppCBs->pfnSensorChange)
    {
      sensor_AppCBs->pfnSensorChange(notifyApp);
    }
    
    return (status);
  }
static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 len, uint16 offset )
{
  
  
//LCDPrintText("Profile_WriteAttr",0,PRINT_STRING);
  
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if(gattPermitAuthorWrite( pAttr->permissions))     // Insufficient authorization                            
                             return ( ATT_ERR_INSUFFICIENT_AUTHOR );

  
  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
                                    uint8 actrual_len = MIN(len, SIMPLEPROFILE_CHAR1_ATCLEN - offset);        		   		                                            
                                    osal_memcpy( &simpleProfileChar1[offset], pValue, actrual_len);	
                                    notifyApp = SIMPLEPROFILE_CHAR1;                                 
                                    break;
                          }
                          
                          /*case SIMPLEPROFILE_CHAR2_UUID:{
                                     if ( offset >= SIMPLEPROFILE_CHAR2_LEN )
                                                      return ( ATT_ERR_ATTR_NOT_LONG );
                                    
                                    // determine read length
                                    uint8 actrual_len = MIN(len, SIMPLEPROFILE_CHAR2_LEN - offset);        		   		                                            
                                    osal_memcpy( &simpleProfileChar2[offset], pValue, actrual_len);	
                                    notifyApp = SIMPLEPROFILE_CHAR2;                                 
                                    break;
                          }*/
                          

                        case GATT_CLIENT_CHAR_CFG_UUID:{			
                        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY );                                                                      
                        notifyApp = SIMPLEPROFILE_CFG_CHAR2;
                        break;
                        }
                          
                        default:
                          // Should never get here! (characteristics 2 and 4 do not have write permissions)
                        status = ATT_ERR_ATTR_NOT_FOUND;
                        break;
                      }
  }
  else
    // 128-bit UUID
    status = ATT_ERR_INVALID_HANDLE;

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
            simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );  //调用回调函数 simpleProfileChangeCB()
  
  return ( status );
}
/*********************************************************************
 * @fn      climbProfile_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   method - type of write message
 *
 * @return  SUCCESS, blePending or Failure
 */
static bStatus_t climbProfile_WriteAttrCB(uint16_t connHandle,
                                           gattAttribute_t *pAttr,
                                           uint8_t *pValue, uint16_t len,
                                           uint16_t offset, uint8_t method)
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  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 CLIMBPROFILE_CHAR1_UUID:
    	  //should not get here
        break;

      case CLIMBPROFILE_CHAR2_UUID:

        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          /*if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }*/
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {

           VOID memcpy( pAttr->pValue, pValue, len ); //VERIFICARE!!!!
           uint8 i;
           for(i = len; i < CLIMBPROFILE_CHAR2_LEN;i++){ //azzera il resto della caratteristica
        	   pAttr->pValue[i] = 0;
           }

           notifyApp = CLIMBPROFILE_CHAR2;	//TODO: in some way the len parameter needs to be passed to app!

        }
        break;

      case GATT_CLIENT_CHAR_CFG_UUID:
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        break;
        
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    status = ATT_ERR_INVALID_HANDLE;
  }

  // If a characteristic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && climbProfile_AppCBs && climbProfile_AppCBs->pfnClimbProfileChange )
  {
    climbProfile_AppCBs->pfnClimbProfileChange( notifyApp );
  }
  
  return ( status );
}
Пример #9
0
/*********************************************************************
 * @fn      iBeacon_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   complete - whether this is the last packet
 * @param   oper - whether to validate and/or write attribute value  
 *
 * @return  Success or Failure
 */
static bStatus_t iBeacon_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                 uint8 *pValue, uint8 len, uint16 offset )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
 
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  if ( pAttr->type.len == ATT_BT_UUID_SIZE ) // 16-bit UUID
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    switch ( uuid )
    {
      case IBEACON_CHAR1_UUID:
      case IBEACON_CHAR2_UUID:
      case IBEACON_CHAR3_UUID:
      case IBEACON_CHAR4_UUID:
      case IBEACON_CHAR5_UUID:
      case IBEACON_CHAR6_UUID:
      case IBEACON_CHAR7_UUID:  
        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {
          uint8 *pCurValue = (uint8 *)pAttr->pValue;        
          *pCurValue = pValue[0];

          if ( pAttr->pValue == iBeaconChar1 )
          {
            notifyApp = IBEACON_CHAR1;        
          }
          else if ( pAttr->pValue == iBeaconChar2 )
          {
            notifyApp = IBEACON_CHAR2;                    
          }
          else if ( pAttr->pValue == iBeaconChar3 )
          {
            notifyApp = IBEACON_CHAR3;                    
          }
          else if ( pAttr->pValue == iBeaconChar4 )
          {
            notifyApp = IBEACON_CHAR4;                    
          }
          else if ( pAttr->pValue == iBeaconChar5 )
          {
            notifyApp = IBEACON_CHAR5;                    
          }
          else if ( pAttr->pValue == iBeaconChar6 )
          {
            notifyApp = IBEACON_CHAR6;                    
          }
          else if ( pAttr->pValue == iBeaconChar7 )
          {
            notifyApp = IBEACON_CHAR7;                    
          }
        }
             
        break;

      case GATT_CLIENT_CHAR_CFG_UUID:
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        break;
        
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else // 128-bit UUID
  {
    if (osal_memcmp(pAttr->type.uuid, iBeaconChar1UUID, ATT_UUID_SIZE) )
    {
      if (offset == 0)
      {
        if (len != IBEACON_CHAR1_LEN)
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
      
      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;        
        osal_memcpy(pCurValue, pValue, IBEACON_CHAR1_LEN); 

        if ( pAttr->pValue == iBeaconChar1 )
          notifyApp = IBEACON_CHAR1;
      }
    }
    else if (osal_memcmp(pAttr->type.uuid, iBeaconChar2UUID, ATT_UUID_SIZE) )
    {
      if (offset == 0)
      {
        if (len != IBEACON_CHAR2_LEN)
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }

      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;        
        pCurValue[0] = pValue[0];
        pCurValue[1] = pValue[1];

        if ( pAttr->pValue == iBeaconChar2 )
          notifyApp = IBEACON_CHAR2;
      }
    }
    else if (osal_memcmp(pAttr->type.uuid, iBeaconChar3UUID, ATT_UUID_SIZE) )
    {
      if (offset == 0)
      {
        if (len != IBEACON_CHAR3_LEN)
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }

      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;        
        pCurValue[0] = pValue[0];
        pCurValue[1] = pValue[1];

        if ( pAttr->pValue == iBeaconChar3 )
          notifyApp = IBEACON_CHAR3;
      }
    }
    else if (osal_memcmp(pAttr->type.uuid, iBeaconChar4UUID, ATT_UUID_SIZE) )
    {
      if (offset == 0)
      {
        if (len != IBEACON_CHAR4_LEN)
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
      
      int8 newValue = (int8)pValue[0];
      if(newValue > 0.0 || newValue < -100.0)
      {
        status = ATT_ERR_UNSUPPORTED_GRP_TYPE;
      }

      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;        
        *pCurValue = pValue[0];

        if ( pAttr->pValue == iBeaconChar4 )
          notifyApp = IBEACON_CHAR4;
      }
    }
    else if (osal_memcmp(pAttr->type.uuid, iBeaconChar5UUID, ATT_UUID_SIZE) )
    {
      if (offset == 0)
      {
        if (len != IBEACON_CHAR5_LEN)
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
      
      if(pValue[0] != 0x00 && pValue[0] != 0x01)
      {
        status = ATT_ERR_UNSUPPORTED_GRP_TYPE;
      }

      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;        
        pCurValue[0] = pValue[0];

        if ( pAttr->pValue == iBeaconChar5 )
          notifyApp = IBEACON_CHAR5;
      }
    }
    else if (osal_memcmp(pAttr->type.uuid, iBeaconChar6UUID, ATT_UUID_SIZE) )
    {
      if (offset == 0)
      {
        if (len != IBEACON_CHAR6_LEN)
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
      
      uint16 adv = pValue[0] * 256 + pValue[1];
      if(adv > 10000 || adv < 100)
      {
        status = ATT_ERR_UNSUPPORTED_GRP_TYPE;
      }

      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;        
        pCurValue[0] = pValue[0];
        pCurValue[1] = pValue[1];

        if ( pAttr->pValue == iBeaconChar6 )  
          notifyApp = IBEACON_CHAR6;
      }
    }
    else if (osal_memcmp(pAttr->type.uuid, iBeaconChar7UUID, ATT_UUID_SIZE) )
    {
      if (offset == 0)
      {
        if (len != IBEACON_CHAR7_LEN)
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
      
      if(pValue[0] != 0x00 && pValue[0] != 0x01 && pValue[0] != 0x02 && pValue[0] != 0x03)
      {
        status = ATT_ERR_UNSUPPORTED_GRP_TYPE;
      }

      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;        
        pCurValue[0] = pValue[0];

        if ( pAttr->pValue == iBeaconChar7 )
          notifyApp = IBEACON_CHAR7;
      }
    }
    else
    {
      status = ATT_ERR_INVALID_HANDLE;
    }
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && iBeacon_AppCBs && iBeacon_AppCBs->pfn_iBeaconChange )
  {
    iBeacon_AppCBs->pfn_iBeaconChange( notifyApp );  
  }
  
  return ( status );
}
Пример #10
0
/*********************************************************************
 * @fn      simpleProfile_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   complete - whether this is the last packet
 * @param   oper - whether to validate and/or write attribute value  
 *
 * @return  Success or Failure
 */
static bStatus_t biscuit_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                 uint8 *pValue, uint8 len, uint16 offset )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  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 VENDOR_NAME_CHAR_UUID:
      case RX_DATA_CHAR_UUID:

        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {
          uint8 *pCurValue = (uint8 *)pAttr->pValue;        
          *pCurValue = pValue[0];

  //        if( pAttr->pValue == &vendorNameCharValue )
          {
            notifyApp = VENDOR_NAME_CHAR;        
          }
  //        else
          {
            notifyApp = RX_DATA_CHAR;           
          }
        }
             
        break;

      case GATT_CLIENT_CHAR_CFG_UUID:
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        break;
        
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        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
    };

    if ( osal_memcmp(pAttr->type.uuid, rxDataCharUUID, ATT_UUID_SIZE) )
    {
      //Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len > 20 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
        
      //Write the value
      if ( status == SUCCESS )
      {
   //     uint8 *pCurValue = (uint8 *)pAttr->pValue;        
   //     *pCurValue = pValue[0];

        HalUARTWrite(HAL_UART_PORT_0, pValue, len);
                     
        notifyApp = RX_DATA_CHAR;           
      }

      else
      {      
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
      }
    }
    
    else if ( osal_memcmp(pAttr->type.uuid, resetWriteCharUUID, ATT_UUID_SIZE) ) // UUID 0004
    {
      resetWriteChar = 1;
    }
    
    else if ( osal_memcmp(uuid, vendorNameCharUUID, ATT_UUID_SIZE) )
    {
      //Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len != 1 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
        
      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;        
        *pCurValue = pValue[0];

    //    if( pAttr->pValue == &vendorNameCharValue ) //char 1 or 3?
        {
          notifyApp = VENDOR_NAME_CHAR;        
        }
    //    else
        {
          notifyApp = RX_DATA_CHAR;           
        }
      }

      else
      {      
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
      }
    }
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && biscuitProfile_AppCBs && biscuitProfile_AppCBs->pfnBiscuitProfileChange )
  {
    biscuitProfile_AppCBs->pfnBiscuitProfileChange( notifyApp );  
  }
  
  return ( status );
}
/*********************************************************************
 * @fn      sensor_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   method - type of write message 
 *
 * @return  SUCCESS, blePending or Failure
 */
static bStatus_t sensor_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr,
                                    uint8_t *pValue, uint16_t len,
                                    uint16_t offset, uint8_t method)
{
  bStatus_t status = SUCCESS;
  uint8_t notifyApp = 0xFF;
  uint16_t uuid;
  
  // If attribute permissions require authorization to write, return error
  if (gattPermitAuthorWrite(pAttr->permissions))
  {
    // Insufficient authorization
    return (ATT_ERR_INSUFFICIENT_AUTHOR);
  }
  
  if (utilExtractUuid16(pAttr,&uuid) == FAILURE)
  {
    // Invalid handle
    return ATT_ERR_INVALID_HANDLE;
  }
  
  switch (uuid)
  {
  case DISPLAY_DATA_UUID:
    // Validate the value
    // Make sure it's not a blob oper
    if (offset == 0)
    {
      if (len > DISPLAY_DATA_LEN )
      {
        status = ATT_ERR_INVALID_VALUE_SIZE;
      }
    }
    else
    {
      status = ATT_ERR_ATTR_NOT_LONG;
    }
    
    // Write the value
    if (status == SUCCESS)
    {
      memcpy(pAttr->pValue, pValue, len);
      
      // Execute the control sequence
      if (pAttr->pValue == (uint8_t*)&displayData )
      {
        notifyApp = DISPLAY_DATA;
      }
    }
    break;
    
  case DISPLAY_CONF_UUID:
    // Validate the value
    // Make sure it's not a blob oper
    if (offset == 0)
    {
      if (len > DISPLAY_CONF_LEN )
      {
        status = ATT_ERR_INVALID_VALUE_SIZE;
      }
    }
    else
    {
      status = ATT_ERR_ATTR_NOT_LONG;
    }
    
    // Write the value
    if (status == SUCCESS)
    {
      memcpy(pAttr->pValue, pValue, len);
      
      // Execute the control sequence
      if (pAttr->pValue == (uint8_t*)&displayControl )
      {
        notifyApp = DISPLAY_CONF;
      }
    }
    break;
    
    
  default:
    // Should never get here!
    status = ATT_ERR_ATTR_NOT_FOUND;
    break;
  }
  
  // If a characteristic value changed then callback function 
  // to notify application of change
  if ((notifyApp != 0xFF ) && sensor_AppCBs && sensor_AppCBs->pfnSensorChange)
  {
    sensor_AppCBs->pfnSensorChange(notifyApp);
  }
  
  return (status);
}
Пример #12
0
/*********************************************************************
 * @fn      simpleProfile_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   complete - whether this is the last packet
 * @param   oper - whether to validate and/or write attribute value  
 *
 * @return  Success or Failure
 */
static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                 uint8 *pValue, uint8 len, uint16 offset )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  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:
        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != 16 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {

          uint8 beaconID[] = {
            pValue[0],pValue[1],pValue[2],pValue[3],pValue[4],pValue[5],pValue[6],pValue[7],
            pValue[8],pValue[9],pValue[10],pValue[11],pValue[12],pValue[13],pValue[14],pValue[15]
          };
          VOID osal_snv_write(BEACON_ID, BEACON_LEN, &beaconID);
          SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR1, SIMPLEPROFILE_CHAR1_LEN, &beaconID );
          /*VOID osal_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN );
          if( pAttr->pValue == simpleProfileChar1 )
          {
            notifyApp = SIMPLEPROFILE_CHAR1;        
          }*/
        }
             
        break;
      case SIMPLEPROFILE_CHAR2_UUID:
        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != 4 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {

          uint8 major[] = {
            pValue[0],pValue[1],pValue[2],pValue[3],pValue[4],pValue[5],pValue[6],pValue[7],
            pValue[8],pValue[9],pValue[10],pValue[11],pValue[12],pValue[13],pValue[14],pValue[15]
          };
          VOID osal_snv_write(MAJOR_ID, MAJOR_LEN, &major);
          SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR2, SIMPLEPROFILE_CHAR2_LEN, &major );
          /*VOID osal_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN );
          if( pAttr->pValue == simpleProfileChar2 )
          {
            notifyApp = SIMPLEPROFILE_CHAR2;        
          }*/
        }
             
        break;
      case SIMPLEPROFILE_CHAR3_UUID:
        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {

          uint8 power[] = {
            pValue[0]
          };
          VOID osal_snv_write(POWER_ID, POWER_LEN, &power);
        }
             
        break;
        
        case SIMPLEPROFILE_CHAR4_UUID:
        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {

          if (pValue[0] == 0xFA)
          {
            HAL_SYSTEM_RESET();
          }
        }
             
        break;

      case GATT_CLIENT_CHAR_CFG_UUID:
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        break;
        
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    status = ATT_ERR_INVALID_HANDLE;
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
  {
    simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );  
  }
  
  return ( status );
}
Пример #13
0
/*********************************************************************
 * @fn      simpleProfile_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   complete - whether this is the last packet
 * @param   oper - whether to validate and/or write attribute value  
 *
 * @return  Success or Failure
 */
static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                 uint8 *pValue, uint8 len, uint16 offset )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  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:
      case SIMPLEPROFILE_CHAR3_UUID:

        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {
          uint8 *pCurValue = (uint8 *)pAttr->pValue;        
          *pCurValue = pValue[0];

          if( pAttr->pValue == &simpleProfileChar1 )
          {
            notifyApp = SIMPLEPROFILE_CHAR1;        
          }
          else
          {
            notifyApp = SIMPLEPROFILE_CHAR3;           
          }
        }
             
        break;

      case GATT_CLIENT_CHAR_CFG_UUID:
        // Validate the value
        // Make sure it's not a blob operation
        if ( offset == 0 )
        {
          if ( len == 2 )
          {
            uint16 charCfg = BUILD_UINT16( pValue[0], pValue[1] );
            
            // Validate characteristic configuration bit field
            if ( !( charCfg == GATT_CLIENT_CFG_NOTIFY   ||
                    charCfg == GATT_CFG_NO_OPERATION ) )
            {
              status = ATT_ERR_INVALID_VALUE;
            }
          }
          else
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
  
        // Write the value
        if ( status == SUCCESS )
        {
          uint16 value = BUILD_UINT16( pValue[0], pValue[1] );
          
          status = simpleProfile_WriteCharCfg( connHandle,
                                          (gattCharCfg_t *)(pAttr->pValue),
                                          value );

          if ( status == SUCCESS )
          {
            // Update Bond Manager
            VOID GAPBondMgr_UpdateCharCfg( connHandle, pAttr->handle, value );
          }

        }
        break;
        
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    status = ATT_ERR_INVALID_HANDLE;
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
  {
    simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );  
  }
  
  return ( status );
}
Пример #14
0
/*********************************************************************
 * @fn      simpleProfile_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   complete - whether this is the last packet
 * @param   oper - whether to validate and/or write attribute value  
 *
 * @return  Success or Failure
 */
static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                 uint8 *pValue, uint8 len, uint16 offset )

{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  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:
      case SIMPLEPROFILE_CHAR2_UUID:
      case SIMPLEPROFILE_CHAR3_UUID:

        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
                        #if 0
			if ( len != SIMPLEPROFILE_CHAR1_LEN )   //len µÈÓÚ¶àÉÙÊÇÓÉË­¾ö¶¨µÄ £¬ÊÇsimpleProfileAttrTblÖ®characteristic 1Ö®Characteristic Value³¤¶È¾ö¶¨µÄ  (´í)
			{				  						//Ϊʲô²»ÊÇÆäËû characteristic  (´í)
				status = ATT_ERR_INVALID_VALUE_SIZE;
			}
			#else	//¶Ô·½(Central)Óô®¿Ú·¢ËÍÊý¾Ý¸öÊýµÄËæÒâµÄ(ÔÝʱÈËΪԼ¶¨Ð¡ÓÚµÈÓÚ20 SIMPLEPROFILE_CHAR1_LEN)
					//Èô£¾20¾ÍÈÎÎñ´íÁË£¬ÒòΪÎÒµÄattribute tableÖеÄbufferÖ»ÓÐ SIMPLEPROFILE_CHAR1_LEN ´ó
					//(Ò²¿ÉÒÔ²»ÓÃÅжϣ¬ÎÒÖ»½ÓÊÕ20¸öÒ»´Î)
					//»¹¿ÉÒÔÔÚCentral¶Ë·¢Ë͵ÄʱºòÅжÏÏ£¬¶àÓÚ20¸ö¾Í²»·¢²¢ÇÒÌáʾ´íÎó ÕâÑù±È·¢¹ýÀ´½ÓÊÕÁ˲»´¦Àí¸üºÃ
					//»¹¿ÉÒÔÔÚCentral¶Ë°Ñ¶àÓÚ20×Ö½ÚµÄÇé¿ö·Ö¶à´Î·¢ËÍ ÔÝʱ²»¿¼ÂÇÕâÖÖÇé¿ö
			if ( len > SIMPLEPROFILE_CHAR1_LEN )   //len µÈÓÚ¶àÉÙÊÇÓÉË­¾ö¶¨µÄ £¬ÊÇsimpleProfileAttrTblÖ®characteristic 1Ö®Characteristic Value³¤¶È¾ö¶¨µÄ  (´í)
			{				  						//Ϊʲô²»ÊÇÆäËû characteristic  (´í)
				status = ATT_ERR_INVALID_VALUE_SIZE;
			}

			#endif
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {
          uint8 *pCurValue = (uint8 *)pAttr->pValue;
		  osal_memset(pCurValue,0,SIMPLEPROFILE_CHAR1_LEN);
		  //osal_memcpy(void * dst,const void GENERIC * src,unsigned int len)
		  //VOID osal_memcpy( pCurValue, pValue, SIMPLEPROFILE_CHAR1_LEN );
		  VOID osal_memcpy( pCurValue, pValue, len );		//ÔÙ¿´ÏÂ
		  //Õâ¸ölenÔÚ±¾ÎļþµÄÆäËûº¯ÊýÒ²ÄÜÓõ½±ÈÈçGetParameter
		  //ÔÚ±¾º¯ÊýµÄ×îºó»Øµ÷º¯ÊýÒ²ÄÜÓõ½£¬Ëä²»ÄÜ´«²ÎÊý£¬µ«ÊÇ¿ÉÓÃÈ«¾Ö±äÁ¿
		  //µ«ÊÇÓÉÓÚlen³¤¶È²»»áÌ«³¤£¬ËùÒÔ¾ÍÓÃ×î´óÖµ SIMPLEPROFILE_CHAR1_LEN Ò²¿ÉÒÔ

          if( pAttr->pValue == simpleProfileChar1 )		//µÈÓÚsimpleProfileChar1ÊÇÓÉË­¾ö¶¨µÄ
          													//simpleProfileAttrTblÖ®characteristic 1Ö®Characteristic Value¾ö¶¨µÄ
          													//(Ϊʲô²»ÊÇÆäËûcharacteristic 2¡¢3¡¢4¡¢5£¬ÔõÑù²ÅÄÜÓÃÉÏÕâЩcharacteristic)
          													//ÔÚÕâÀïÊÇÊý×éÃû simpleProfileChar1
          {
            notifyApp = SIMPLEPROFILE_CHAR1;    //³ýÁËchar1ºÍchar3»¹ÓÐÆäËûµÄ°É£¬ÌرðÊÇchar5     
          }
          else if(pAttr->pValue == simpleProfileChar2)
          {
            notifyApp = SIMPLEPROFILE_CHAR2;
          }
          else{
            notifyApp = SIMPLEPROFILE_CHAR3;
          }
        }
        break;

      case GATT_CLIENT_CHAR_CFG_UUID:			//¸ÉʲôÓõÄ? ÄÜ·ñ±»Ö´Ðе½ ?
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        break;
        
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    status = ATT_ERR_INVALID_HANDLE;
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
  {
    simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );  //µ÷Óûص÷º¯Êý simpleProfileChangeCB()
  }
  
  return ( status );
}
Пример #15
0
/*********************************************************************
 * @fn      txrx_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   complete - whether this is the last packet
 * @param   oper - whether to validate and/or write attribute value  
 *
 * @return  Success or Failure
 */
static bStatus_t txrx_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                 uint8 *pValue, uint8 len, uint16 offset )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }

  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 GATT_CLIENT_CHAR_CFG_UUID:
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        if (status == SUCCESS)
        {
          uint16 charCfg = BUILD_UINT16( pValue[0], pValue[1] );
          txrxService_AppCBs->pfnTXRXServiceChange( (charCfg == GATT_CFG_NO_OPERATION) ?
                                                      TXRX_RX_NOTI_DISABLED :
                                                      TXRX_RX_NOTI_ENABLED );
        }
        break;
        
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else // 128-bit  
  {
    if ( osal_memcmp(pAttr->type.uuid, rxDataCharUUID, ATT_UUID_SIZE) )
    {
      //Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len > 20 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
        
      //Write the value
      if ( status == SUCCESS )
      {                
        uint8 *pCurValue = (uint8 *)pAttr->pValue;
        osal_memcpy(pCurValue, pValue, len);
        rxDataLen = len;
        
        notifyApp = TXRX_RX_DATA_READY;           
      }
    }
    else if ( osal_memcmp(pAttr->type.uuid, BaudrateCharUUID, ATT_UUID_SIZE) )
    {
      //Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len != 1 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
      if(*pValue > 4)
      {
        status = ATT_ERR_INVALID_VALUE;
      }
        
      //Write the value
      if ( status == SUCCESS )
      {                
        uint8 *pCurValue = (uint8 *)pAttr->pValue;
        osal_memcpy(pCurValue, pValue, len);
        
        notifyApp = BAUDRATE_SET;           
      }
    }
    else if ( osal_memcmp(pAttr->type.uuid, DevNameCharUUID, ATT_UUID_SIZE) )
    {
      //Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len > 20 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
        
      //Write the value
      if ( status == SUCCESS )
      {                
        uint8 *pCurValue = (uint8 *)pAttr->pValue;
        osal_memcpy(pCurValue, pValue, len);
        DevNameLen = len;
        
        notifyApp = DEV_NAME_CHANGED;           
      }
    }
    else if ( osal_memcmp(pAttr->type.uuid, TxPowerCharUUID, ATT_UUID_SIZE) )
    {
      //Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len != 1 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
      if(*pValue > 3)
      {
        status = ATT_ERR_INVALID_VALUE;
      }
        
      //Write the value
      if ( status == SUCCESS )
      {                
        uint8 *pCurValue = (uint8 *)pAttr->pValue;
        osal_memcpy(pCurValue, pValue, len);
        
        notifyApp = TX_POWER_CHANGED;           
      }
    }
    else
    {      
      // Should never get here! (characteristics 2 and 4 do not have write permissions)
      status = ATT_ERR_ATTR_NOT_FOUND;
    }
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && txrxService_AppCBs && txrxService_AppCBs->pfnTXRXServiceChange )
  {
    txrxService_AppCBs->pfnTXRXServiceChange( notifyApp );  
  }
  
  return ( status );
}
Пример #16
0
/*********************************************************************
 * @fn      simpleProfile_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 *
 * @return  Success or Failure
 */
static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                 uint8 *pValue, uint8 len, uint16 offset )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  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:
      case SIMPLEPROFILE_CHAR3_UUID:

        //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {
          uint8 *pCurValue = (uint8 *)pAttr->pValue;        
          *pCurValue = pValue[0];

          if( pAttr->pValue == &simpleProfileChar1 )
          {
            notifyApp = SIMPLEPROFILE_CHAR1;        
          }
          else
          {
            notifyApp = SIMPLEPROFILE_CHAR3;           
          }
        }
             
        break;

      case GATT_CLIENT_CHAR_CFG_UUID:
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        break;
        
        
      case SIMPLEPROFILE_CHAR6_UUID:
          //Validate the value
        // Make sure it's not a blob oper
        if ( offset == 0 )
        {
          if ( len != SIMPLEPROFILE_CHAR6_LEN )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {
          VOID osal_memcpy(pAttr->pValue, pValue, len);
          notifyApp = SIMPLEPROFILE_CHAR6; 
        }
        
        break;
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    status = ATT_ERR_INVALID_HANDLE;
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
  {
    simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );  
  }
  
  return ( status );
}
Пример #17
0
/*********************************************************************
* @fn      sensor_WriteAttrCB
*
* @brief   Validate attribute data prior to a write operation
*
* @param   connHandle - connection message was received on
* @param   pAttr - pointer to attribute
* @param   pValue - pointer to data to be written
* @param   len - length of data
* @param   offset - offset of the first octet to be written
*
* @return  Success or Failure
*/
static bStatus_t sensor_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                           uint8 *pValue, uint8 len, uint16 offset, uint8 method )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  uint16 uuid;

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

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

  switch ( uuid )
  {
    case SENSOR_DATA_UUID:
    case SENSOR_CALIBR_UUID:
      // Should not get here
      break;

    case SENSOR_CONFIG_UUID:
      // Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len != 1 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }

      // Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;

        *pCurValue = pValue[0];

        if( pAttr->pValue == &sensorCfg )
        {
          notifyApp = SENSOR_CONF;
        }
      }
      break;

    case SENSOR_PERIOD_UUID:
      // Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len != 1 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }
      // Write the value
      if ( status == SUCCESS )
      {
        if (pValue[0]>=(SENSOR_MIN_UPDATE_PERIOD/SENSOR_PERIOD_RESOLUTION))
        {

          uint8 *pCurValue = (uint8 *)pAttr->pValue;
          *pCurValue = pValue[0];

          if( pAttr->pValue == &sensorPeriod )
          {
            notifyApp = SENSOR_PERI;
          }
        }
        else
        {
           status = ATT_ERR_INVALID_VALUE;
        }
      }
      break;

    case GATT_CLIENT_CHAR_CFG_UUID:
      status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                              offset, GATT_CLIENT_CFG_NOTIFY );
      break;

    default:
      // Should never get here!
      status = ATT_ERR_ATTR_NOT_FOUND;
      break;
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && sensor_AppCBs && sensor_AppCBs->pfnSensorChange )
  {
    sensor_AppCBs->pfnSensorChange( notifyApp );
  }

  return ( status );
}
Пример #18
0
/**
 * Validate attribute data prior to a write operation.
 *
 * @param connHandle - connection message was received on.
 * @param pAttr - pointer to attribute.
 * @param pValue - pointer to data to be written.
 * @param len - length of data.
 * @param offset - offset of the first octet to be written.
 * @param complete - whether this is the last packet.
 * @param oper - whether to validate and/or write attribute value  .
 * @return  Success or Failure.
 */
static bStatus_t buttonsProfile_WriteAttrCB(uint16 connHandle, gattAttribute_t* pAttr, uint8* pValue, uint8 len, uint16 offset)
{
	bStatus_t status = SUCCESS;
	uint8 notifyApp = 0xFF;

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

	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 BLE_BUTTONS_A_CHAR_UUID:
				P1_7 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_B_CHAR_UUID:
				P1_1 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_X_CHAR_UUID:
				P0_6 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_Y_CHAR_UUID:
				P0_5 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_UP_CHAR_UUID:
				P2_0 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_DN_CHAR_UUID:
				if (getValue(pAttr, pValue, len, offset, &status) > 0)
				{
					I2CIO |= 0x02; // SCL
				}
				else
				{
					I2CIO &= ~0x02; // SCL
				}
				break;
			case BLE_BUTTONS_L_CHAR_UUID:
				P0_7 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_R_CHAR_UUID:
				P1_6 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_LB_CHAR_UUID:
				P0_2 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_RB_CHAR_UUID:
				if (getValue(pAttr, pValue, len, offset, &status) > 0)
				{
					I2CIO |= 0x01; // SDA
				}
				else
				{
					I2CIO &= ~0x01; // SDA
				}			
				break;
			case BLE_BUTTONS_START_CHAR_UUID:
				P0_1 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_BACK_CHAR_UUID:
				P0_0 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_GUIDE_CHAR_UUID:
				P1_0 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_LS_CHAR_UUID:
				P0_3 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_RS_CHAR_UUID:
				P0_4 = getValue(pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_LX_CHAR_UUID:
				setChannelValue(6 - 1, pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_LY_CHAR_UUID:
				setChannelValue(5 - 1, pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_RX_CHAR_UUID:
				setChannelValue(4 - 1, pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_RY_CHAR_UUID:
				setChannelValue(2 - 1, pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_LT_CHAR_UUID:
				setChannelValue(3 - 1, pAttr, pValue, len, offset, &status);
				break;
			case BLE_BUTTONS_RT_CHAR_UUID:
				setChannelValue(1 - 1, pAttr, pValue, len, offset, &status);
				break;
			case GATT_CLIENT_CHAR_CFG_UUID:
				status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY);
				break;
			default:
				// Should never get here! (characteristics 2 and 4 do not have write permissions)
				status = ATT_ERR_ATTR_NOT_FOUND;
				break;
		}
	}
	else
	{
		// 128-bit UUID
		status = ATT_ERR_INVALID_HANDLE;
	}

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && buttonsProfile_AppCBs && buttonsProfile_AppCBs->pfnButtonsProfileChange )
  {
    buttonsProfile_AppCBs->pfnButtonsProfileChange( notifyApp );
  }

	return (status);
};
Пример #19
0
/*********************************************************************
 * @fn      test_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   complete - whether this is the last packet
 * @param   oper - whether to validate and/or write attribute value
 *
 * @return  Success or Failure
 */
static bStatus_t test_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                 uint8 *pValue, uint8 len, uint16 offset )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  uint16 uuid;

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

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

  switch ( uuid )
  {
    case TEST_CONF_UUID:
      // Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len != 1 )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }

      // Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;
        *pCurValue = pValue[0];

        if( pAttr->pValue == &testConf )
        {
          notifyApp = TEST_CONF_ATTR;
        }
      }
      break;

    case GATT_CLIENT_CHAR_CFG_UUID:
      status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                              offset, GATT_CLIENT_CFG_NOTIFY );
      break;

    default:
      // Should never get here! (characteristics 2 and 4 do not have write permissions)
      status = ATT_ERR_ATTR_NOT_FOUND;
      break;
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && test_AppCBs && test_AppCBs->pfnTestChange )
  {
    test_AppCBs->pfnTestChange( notifyApp );
  }

  return ( status );
}
Пример #20
0
/*********************************************************************
 * @fn      roboRoachProfile_WriteAttrCB
 *
 * @brief   Validate attribute data prior to a write operation
 *
 * @param   connHandle - connection message was received on
 * @param   pAttr - pointer to attribute
 * @param   pValue - pointer to data to be written
 * @param   len - length of data
 * @param   offset - offset of the first octet to be written
 * @param   complete - whether this is the last packet
 * @param   oper - whether to validate and/or write attribute value  
 *
 * @return  Success or Failure
 */
static bStatus_t roboRoachProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
                                 uint8 *pValue, uint8 len, uint16 offset )
{
  bStatus_t status = SUCCESS;
  uint8 notifyApp = 0xFF;
  
  // If attribute permissions require authorization to write, return error
  if ( gattPermitAuthorWrite( pAttr->permissions ) )
  {
    // Insufficient authorization
    return ( ATT_ERR_INSUFFICIENT_AUTHOR );
  }
  
  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
  {
    // 16-bit UUID
    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
    //AT_DBG( "roboRoach_WriteAttrCB: connHandle=[%i], uuid=[%x]", connHandle, uuid );
 
    switch ( uuid )
    {
      case ROBOROACH_CHAR_FREQUENCY_UUID:
      case ROBOROACH_CHAR_PULSE_WIDTH_UUID:
      case ROBOROACH_CHAR_NUM_PULSES_UUID:
      case ROBOROACH_CHAR_RANDOM_MODE_UUID:
      
        //Validate the value (Make sure it's not a blob oper)
        if ( offset == 0 )
        {
          if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //Write the value
        if ( status == SUCCESS )
        {
          uint8 *pCurValue = (uint8 *)pAttr->pValue;        
          *pCurValue = pValue[0];
          
          //Update the Stim Values
          roboRoachProfile_updateStimulationSettings();
      
        }
                     
        break;
        
      case ROBOROACH_CHAR_STIMULATE_LEFT_UUID :
      case ROBOROACH_CHAR_STIMULATE_RIGHT_UUID :
     
        //Double Check this is Legit.
        if ( offset == 0 )
        {
          if ( len != 1 )
          {
            status = ATT_ERR_INVALID_VALUE_SIZE;
          }
        }
        else
        {
          status = ATT_ERR_ATTR_NOT_LONG;
        }
        
        //No need to write the value.  Just fire the event!
        if ( status == SUCCESS )
        {         
          roboRoachProfile_Stimulate( uuid );
        }
                     
        break;
        
      case GATT_CLIENT_CHAR_CFG_UUID:
        status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
                                                 offset, GATT_CLIENT_CFG_NOTIFY );
        break;
        
      default:
        // Should never get here! (characteristics 2 and 4 do not have write permissions)
        status = ATT_ERR_ATTR_NOT_FOUND;
        break;
    }
  }
  else
  {
    // 128-bit UUID
    status = ATT_ERR_INVALID_HANDLE;
  }

  // If a charactersitic value changed then callback function to notify application of change
  if ( (notifyApp != 0xFF ) && roboRoach_AppCBs && roboRoach_AppCBs->pfnRoboRoachProfileChange )
  {
    roboRoach_AppCBs->pfnRoboRoachProfileChange( notifyApp );  
  }
  
  return ( status );
}