コード例 #1
0
   /* an error occurs.                                                  */
int BTPSAPI TPS_Set_Tx_Power_Level(unsigned int BluetoothStackID, unsigned int InstanceID, SByte_t Tx_Power_Level)
{
   int                  ret_val;
   TPSServerInstance_t *ServiceInstance;

   /* Make sure the parameters passed to us are semi-valid.             */
   if((BluetoothStackID) && (InstanceID))
   {
      /* Acquire the specified TPS Instance.                            */
      if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL)
      {
         /* Assign the Tx Power Level for the specified instance.       */
         ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(InstanceData[InstanceID-1].Tx_Power_Level), Tx_Power_Level);

         /* Return success to the caller.                               */
         ret_val = 0;

         /* UnLock the previously locked Bluetooth Stack.               */
         BSC_UnLockBluetoothStack(ServiceInstance->BluetoothStackID);
      }
      else
         ret_val = TPS_ERROR_INVALID_INSTANCE_ID;
   }
   else
      ret_val = TPS_ERROR_INVALID_PARAMETER;

   /* Finally return the result to the caller.                          */
   return(ret_val);
}
コード例 #2
0
   /* function returns the zero if successful or a negative error code. */
static int DecodeAlertLevel(unsigned int InstanceID, unsigned int BufferLength, Byte_t *Buffer, Byte_t *AlertLevel)
{
   int ret_val = LLS_ERROR_MALFORMATTED_DATA;

   /* Verify that the input parameters are valid.                       */
   if((BufferLength == LLS_ALERT_LEVEL_LENGTH) && (Buffer) && (AlertLevel))
   {
      /* Read the requested Alert Level.                                */
      *AlertLevel = READ_UNALIGNED_BYTE_LITTLE_ENDIAN(Buffer);

      /* Assign the Alert Level into the Instance Data.                 */
      ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(InstanceData[InstanceID-1].Alert_Level), *AlertLevel);
      ret_val = 0;
   }
   else
   {
      if(BufferLength == LLS_ALERT_LEVEL_LENGTH)
         ret_val = LLS_ERROR_INVALID_PARAMETER;
   }

   /* Finally return the result to the caller.                          */
   return(ret_val);
}
コード例 #3
0
ファイル: EHCILL.c プロジェクト: ee230/trunks
   /* controller. It returns 0 on success or a negative error code.     */
int HCILL_Configure(unsigned int BluetoothStackID, Word_t InactivityTimeout, Word_t RetransmitTimeout, Boolean_t DeepSleepEnable)
{   
   int     ret_val = 0;
   int     ParameterSize;
   Byte_t  Status,Length; 
   Byte_t *ReturnBuffer;
   Byte_t *HCILL_Parameters;
   
   /* Check to make sure we have a valid Bluetooth Stack ID.            */
   if(BluetoothStackID)
   {
      /* Allocate a buffer for the return from HCI_Send_Raw.            */
      if((ReturnBuffer = BTPS_AllocateMemory(RETURN_BUFFER_SIZE)) != NULL)
      {
         ParameterSize = ((HCI_VS_SLEEP_MODE_CONFIGURATIONS_SIZE > HCI_VS_HCILL_PARAMETERS_SIZE)?HCI_VS_SLEEP_MODE_CONFIGURATIONS_SIZE:HCI_VS_HCILL_PARAMETERS_SIZE);
         
         /* Allocate a buffer for HCILL Parameters.                     */
         HCILL_Parameters = BTPS_AllocateMemory(ParameterSize);
         if(HCILL_Parameters != NULL)
         {
            if((InactivityTimeout) && (RetransmitTimeout))
            {
               /* If either Inactivity Timeout  is less than 1 frame we */
               /* will round up.                                        */
               InactivityTimeout = (InactivityTimeout < HCILL_MIN_INACTIVITY_TIMEOUT)?HCILL_MIN_INACTIVITY_TIMEOUT:InactivityTimeout;
               
               /* We will not allow the Retransmit Timeout to be less   */
               /* than the minimum we support.                          */
               RetransmitTimeout = (RetransmitTimeout < HCILL_MIN_RETRANSMIT_TIMEOUT)?HCILL_MIN_RETRANSMIT_TIMEOUT:RetransmitTimeout;
               
               Length = RETURN_BUFFER_SIZE;
               ASSIGN_HOST_WORD_TO_LITTLE_ENDIAN_UNALIGNED_WORD(&(HCILL_Parameters[0]),MILLISECONDS_TO_FRAMES(InactivityTimeout));
               ASSIGN_HOST_WORD_TO_LITTLE_ENDIAN_UNALIGNED_WORD(&(HCILL_Parameters[2]),MILLISECONDS_TO_FRAMES(RetransmitTimeout));
               ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(HCILL_Parameters[4]),EHCILL_CTS_PULSE_WITDH_US);    
               
               /* Send out command to set HCILL Mode Parameters.        */
               ret_val = HCI_Send_Raw_Command(BluetoothStackID,HCI_VS_HCILL_PARAMETERS_OGF,HCI_VS_HCILL_PARAMETERS_OCF,HCI_VS_HCILL_PARAMETERS_SIZE,HCILL_Parameters,&Status,&Length,ReturnBuffer,TRUE);
               
               /* Determine if the command was executed successfully.   */
               if(!ret_val)
               {
                  if(Length == 1)
                  {
                     if(ReturnBuffer[0])
                        ret_val = -ReturnBuffer[0];
                  }
                  else
                     ret_val = -1;
               }
            }
            
            /* If we successfully set the HCILL Procol Parameters then  */
            /* we will enable/disable the protocol.                     */
            if(ret_val >= 0)
            {
               Length = RETURN_BUFFER_SIZE;
               
               /* Assign the command to enable HCILL mode.              */
               ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(HCILL_Parameters[0]),1);
               ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(HCILL_Parameters[1]),((DeepSleepEnable == TRUE)?1:0));
               ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(HCILL_Parameters[2]),0);
               ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(HCILL_Parameters[3]),0xFF);
               ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(HCILL_Parameters[4]),0xFF);
               ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(HCILL_Parameters[5]),0xFF);
               ASSIGN_HOST_BYTE_TO_LITTLE_ENDIAN_UNALIGNED_BYTE(&(HCILL_Parameters[6]),0xFF);
               ASSIGN_HOST_WORD_TO_LITTLE_ENDIAN_UNALIGNED_WORD(&(HCILL_Parameters[7]),0x0000);

               /* Send the command.                                     */
               ret_val = HCI_Send_Raw_Command(BluetoothStackID,HCI_VS_SLEEP_MODE_CONFIGURATIONS_OGF,HCI_VS_SLEEP_MODE_CONFIGURATIONS_OCF,HCI_VS_SLEEP_MODE_CONFIGURATIONS_SIZE,HCILL_Parameters,&Status,&Length,ReturnBuffer,TRUE);
               if(!ret_val)
               {
                  if(Length == 1)
                  {
                     if(ReturnBuffer[0])
                        ret_val = -ReturnBuffer[0];
                  }
                  else
                     ret_val = -1;
               }
            }
            
            /* Free Parameter Buffer.                                   */
            BTPS_FreeMemory(HCILL_Parameters);
         }
         /* Free the Return Buffer.                                     */
         BTPS_FreeMemory(ReturnBuffer);
      }
   }
   else
     ret_val = BTPS_ERROR_INVALID_BLUETOOTH_STACK_ID;
   
   return(ret_val);
}