Example #1
0
   /* negative return error code if an error occurs.                    */
int BTPSAPI TPS_Query_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) && (Tx_Power_Level))
   {
      /* Acquire the specified TPS Instance.                            */
      if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL)
      {
         /* Query the current Tx Power Level.                           */
         *Tx_Power_Level = READ_UNALIGNED_BYTE_LITTLE_ENDIAN(&(InstanceData[InstanceID-1].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);
}
Example #2
0
   /* instances.                                                        */
static void BTPSAPI GATT_ServerEventCallback(unsigned int BluetoothStackID, GATT_Server_Event_Data_t *GATT_ServerEventData, unsigned long CallbackParameter)
{
   Word_t               AttributeOffset;
   Word_t               ValueLength;
   Byte_t               Event_Buffer[IAS_EVENT_DATA_SIZE + IAS_EVENT_DATA_BUFFER_SIZE];
   unsigned int         TransactionID;
   unsigned int         InstanceID;
   IAS_Event_Data_t    *EventData;
   IASServerInstance_t *ServiceInstance;

    /* Verify that all parameters to this callback are Semi-Valid.      */
   if((BluetoothStackID) && (GATT_ServerEventData) && (CallbackParameter))
   {
      /* The Instance ID is always registered as the callback parameter.*/
      InstanceID = (unsigned int)CallbackParameter;

      /* Acquire the Service Instance for the specified service.        */
      if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL)
      {
         switch(GATT_ServerEventData->Event_Data_Type)
         {
              case etGATT_Server_Write_Request:
               /* Verify that the Event Data is valid.                  */
               if(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data)
               {
                  /* Store the needed members for use later.            */
                  AttributeOffset = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeOffset;
                  TransactionID   = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->TransactionID;
                  ValueLength     = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeValueLength;

                  /* Verify that the parameters look correct.           */
                  if((ValueLength == IAS_ALERT_LEVEL_CONTROL_POINT_VALUE_LENGTH) && (!(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeValueOffset)) && (!(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->DelayWrite)))
                  {
                     /* IAS defines that the Write Without Response     */
                     /* procedure is used to write to this attribute,   */
                     /* therefore we will just accept the write request */
                     /* here to allow GATT to clean up the resources.   */
                     GATT_Write_Response(BluetoothStackID, TransactionID);

                     /* Format and Dispatch the event.                  */
                     EventData = FormatEventHeader(sizeof(Event_Buffer), Event_Buffer, etIAS_Server_Alert_Level_Control_Point_Command, InstanceID, GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->ConnectionID, GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->ConnectionType, &(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->RemoteDevice));
                     if(EventData)
                     {
                        /* Format the rest of the event.                */
                        EventData->Event_Data_Size                                                = IAS_ALERT_LEVEL_CONTROL_POINT_COMMAND_DATA_SIZE;
                        EventData->Event_Data.IAS_Alert_Level_Control_Point_Command_Data->Command = (IAS_Control_Point_Command_t)READ_UNALIGNED_BYTE_LITTLE_ENDIAN(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeValue);

                        __BTPSTRY
                        {
                           (*ServiceInstance->EventCallback)(ServiceInstance->BluetoothStackID, EventData, ServiceInstance->CallbackParameter);
                        }
                        __BTPSEXCEPT(1)
                        {
                           /* Do Nothing.                               */
                        }
                     }
                  }
                  else
                     GATT_Error_Response(BluetoothStackID, TransactionID, AttributeOffset, ATT_PROTOCOL_ERROR_CODE_REQUEST_NOT_SUPPORTED);
               }
Example #3
0
   /* non-zero, Instance ID on success or a negative error code.        */
static int LLSRegisterService(unsigned int BluetoothStackID, LLS_Event_Callback_t EventCallback, unsigned long CallbackParameter, unsigned int *ServiceID, GATT_Attribute_Handle_Group_t *ServiceHandleRange)
{
   int                  ret_val;
   unsigned int         InstanceID;
   LLSServerInstance_t *ServiceInstance;

   /* Make sure the parameters passed to us are semi-valid.             */
   if((BluetoothStackID) && (ServiceID))
   {
      /* Verify that no instance is registered to this Bluetooth Stack. */
      if(!InstanceRegisteredByStackID(BluetoothStackID))
      {
         /* Acquire a free LLS Instance.                                */
         InstanceID = 0;
         if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL)
         {
            /* Call GATT to register the LLS service.                   */
            ret_val = GATT_Register_Service(BluetoothStackID, LLS_SERVICE_FLAGS, LINK_LOSS_SERVICE_ATTRIBUTE_COUNT, (GATT_Service_Attribute_Entry_t *)Link_Loss_Service, ServiceHandleRange, GATT_ServerEventCallback, InstanceID);
            if(ret_val > 0)
            {
                /* Save the Instance information.                       */
               ServiceInstance->BluetoothStackID  = BluetoothStackID;
               ServiceInstance->ServiceID         = (unsigned int)ret_val;
               ServiceInstance->EventCallback     = EventCallback;
               ServiceInstance->CallbackParameter = CallbackParameter;
               *ServiceID                         = (unsigned int)ret_val;

               /* Intilize the Instance Data for this instance.         */
               BTPS_MemInitialize(&InstanceData[InstanceID-1], 0,LLS_INSTANCE_DATA_SIZE);

               ASSIGN_HOST_WORD_TO_LITTLE_ENDIAN_UNALIGNED_WORD(&(InstanceData[InstanceID-1].Alert_Level_Length), LLS_ALERT_LEVEL_LENGTH);

               /* Return the LLS Instance ID.                           */
               ret_val = (int)InstanceID;
            }

            /* UnLock the previously locked Bluetooth Stack.            */
            BSC_UnLockBluetoothStack(BluetoothStackID);
         }
         else
            ret_val = LLS_ERROR_INSUFFICIENT_RESOURCES;
      }
      else
         ret_val = LLS_ERROR_SERVICE_ALREADY_REGISTERED;
   }
   else
      ret_val = LLS_ERROR_INVALID_PARAMETER;

   /* Finally return the result to the caller.                          */
   return(ret_val);
}
Example #4
0
   /* non-zero, Instance ID on success or a negative error code.        */
static int IASRegisterService(unsigned int BluetoothStackID, IAS_Event_Callback_t EventCallback, unsigned long CallbackParameter, unsigned int *ServiceID, GATT_Attribute_Handle_Group_t *ServiceHandleRange)
{
   int                  ret_val;
   unsigned int         InstanceID;
   IASServerInstance_t *ServiceInstance;

   /* Make sure the parameters passed to us are semi-valid.             */
   if((BluetoothStackID) && (EventCallback) && (ServiceID))
   {
      /* Verify that no instance is registered to this Bluetooth Stack. */
      if(!InstanceRegisteredByStackID(BluetoothStackID))
      {
         /* Acquire a free IAS Instance.                                */
         InstanceID = 0;
         if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL)
         {
            /* Call GATT to register the IAS service.                   */
            ret_val = GATT_Register_Service(BluetoothStackID, IAS_SERVICE_FLAGS, IMMEDIATE_ALERT_SERVICE_ATTRIBUTE_COUNT, (GATT_Service_Attribute_Entry_t *)Immediate_Alert_Service, ServiceHandleRange, GATT_ServerEventCallback, InstanceID);
            if(ret_val > 0)
            {
               /* Save the Instance information.                        */
               ServiceInstance->BluetoothStackID  = BluetoothStackID;
               ServiceInstance->ServiceID         = (unsigned int)ret_val;
               ServiceInstance->EventCallback     = EventCallback;
               ServiceInstance->CallbackParameter = CallbackParameter;
               *ServiceID                         = (unsigned int)ret_val;

               /* Return the IAS Instance ID.                           */
               ret_val                            = (int)InstanceID;
            }
            /* UnLock the previously locked Bluetooth Stack.            */
            BSC_UnLockBluetoothStack(BluetoothStackID);
         }
         else
            ret_val = IAS_ERROR_INSUFFICIENT_RESOURCES;
      }
      else
         ret_val = IAS_ERROR_SERVICE_ALREADY_REGISTERED;
   }
   else
      ret_val = IAS_ERROR_INVALID_PARAMETER;

   /* Finally return the result to the caller.                          */
   return(ret_val);
}
Example #5
0
   /* successful or a negative return error code if an error occurs.    */
int BTPSAPI TPS_Cleanup_Service(unsigned int BluetoothStackID, unsigned int InstanceID)
{
   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)
      {
         /* Verify that the service is actually registered.             */
         if(ServiceInstance->ServiceID)
         {
            /* Call GATT to un-register the service.                    */
            GATT_Un_Register_Service(BluetoothStackID, ServiceInstance->ServiceID);

            /* Mark the instance entry as being free.                   */
            BTPS_MemInitialize(ServiceInstance, 0, TPS_SERVER_INSTANCE_DATA_SIZE);

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

         /* UnLock the previously locked Bluetooth Stack.               */
         BSC_UnLockBluetoothStack(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);
}
Example #6
0
   /* instances.                                                        */
static void BTPSAPI GATT_ServerEventCallback(unsigned int BluetoothStackID, GATT_Server_Event_Data_t *GATT_ServerEventData, unsigned long CallbackParameter)
{
   Word_t                     AttributeOffset;
   Word_t                     InstanceTag;
   Word_t                     ValueLength;
   Byte_t                    *Value;
   unsigned int               TransactionID;
   unsigned int               InstanceID;
   TPSServerInstance_t       *ServiceInstance;

   /* Verify that all parameters to this callback are Semi-Valid.       */
   if((BluetoothStackID) && (GATT_ServerEventData) && (CallbackParameter))
   {
      /* The Instance ID is always registered as the callback parameter.*/
      InstanceID = (unsigned int)CallbackParameter;

      /* Acquire the Service Instance for the specified service.        */
      if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL)
      {
         switch(GATT_ServerEventData->Event_Data_Type)
         {
            case etGATT_Server_Read_Request:
               /* Verify that the Event Data is valid.                  */
               if(GATT_ServerEventData->Event_Data.GATT_Read_Request_Data)
               {
                  AttributeOffset = GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->AttributeOffset;
                  TransactionID   = GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->TransactionID;

                  /* Verify that they are not trying to write with an   */
                  /* offset or using prepared writes.                   */
                  if(!(GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->AttributeValueOffset))
                  {
                     /* Verify that the read request is on the Tx Power */
                     /* Level characteristic.                           */
                     if((Tx_Power_Service[AttributeOffset].Attribute_Entry_Type == aetCharacteristicValue16) && (AttributeOffset == TPS_TX_POWER_LEVEL_ATTRIBUTE_OFFSET))
                     {
                        /* Get the instance tag for the characteristic. */
                        InstanceTag = (Word_t)(((GATT_Characteristic_Value_16_Entry_t *)Tx_Power_Service[AttributeOffset].Attribute_Value)->Characteristic_Value_Length);
                        ValueLength = READ_UNALIGNED_WORD_LITTLE_ENDIAN(&(((Byte_t *)(&InstanceData[InstanceID-1]))[InstanceTag]));
                        Value       = (Byte_t *)(&(((Byte_t *)(&InstanceData[InstanceID-1]))[InstanceTag + WORD_SIZE]));

                        /* Respond with the data.                       */
                        GATT_Read_Response(BluetoothStackID, TransactionID, (unsigned int)ValueLength, Value);
                     }
                  }
                  else
                     GATT_Error_Response(BluetoothStackID, TransactionID, AttributeOffset, ATT_PROTOCOL_ERROR_CODE_ATTRIBUTE_NOT_LONG);
               }
               break;
            default:
               /* Do nothing, as this is just here to get rid of        */
               /* warnings that some compilers flag when not all cases  */
               /* are handled in a switch off of a enumerated value.    */
               break;
         }

         /* UnLock the previously locked Bluetooth Stack.               */
         BSC_UnLockBluetoothStack(ServiceInstance->BluetoothStackID);
      }
   }
}
Example #7
0
   /* instances.                                                        */
static void BTPSAPI GATT_ServerEventCallback(unsigned int BluetoothStackID, GATT_Server_Event_Data_t *GATT_ServerEventData, unsigned long CallbackParameter)
{
   Word_t               AttributeOffset;
   Word_t               InstanceTag;
   Word_t               ValueLength;
   Byte_t              *Value;
   unsigned int         TransactionID;
   unsigned int         InstanceID;
   LLSServerInstance_t *ServiceInstance;
   LLS_Event_Data_t    *EventData;
   Byte_t               Event_Buffer[LLS_EVENT_DATA_SIZE + LLS_EVENT_DATA_BUFFER_SIZE];

   /* Verify that all parameters to this callback are Semi-Valid.       */
   if((BluetoothStackID) && (GATT_ServerEventData) && (CallbackParameter))
   {
      /* The Instance ID is always registered as the callback parameter.*/
      InstanceID = (unsigned int)CallbackParameter;
      /* Acquire the Service Instance for the specified service.        */
      if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL)
      {
         switch(GATT_ServerEventData->Event_Data_Type)
         {
         case etGATT_Server_Read_Request:
            /* Verify that the Event Data is valid.                     */
            AttributeOffset = GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->AttributeOffset;
            TransactionID   = GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->TransactionID;

            if(GATT_ServerEventData->Event_Data.GATT_Read_Request_Data)
            {
               /* Verify that they are not trying to write with an      */
               /* offset or using preprared writes.                     */
               if(!(GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->AttributeValueOffset))
               {
                  /* Get the instance tag for the characteristic.       */
                  InstanceTag = (Word_t)(((GATT_Characteristic_Value_16_Entry_t *)Link_Loss_Service[AttributeOffset].Attribute_Value)->Characteristic_Value_Length);
                  ValueLength = READ_UNALIGNED_WORD_LITTLE_ENDIAN(&(((Byte_t *)(&InstanceData[InstanceID-1]))[InstanceTag]));
                  Value       = (Byte_t *)(&(((Byte_t *)(&InstanceData[InstanceID-1]))[InstanceTag + WORD_SIZE]));

                  /* Respond with the data.                             */
                  GATT_Read_Response(BluetoothStackID, TransactionID, (unsigned int)ValueLength, Value);
               }
            }
            else
               GATT_Error_Response(BluetoothStackID, TransactionID, AttributeOffset, ATT_PROTOCOL_ERROR_CODE_ATTRIBUTE_NOT_LONG);
            break;
         case etGATT_Server_Write_Request:
            AttributeOffset = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeOffset;
            TransactionID   = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->TransactionID;
            ValueLength     = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeValueLength;
            Value           = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeValue;
            /* Verify the Event data is valid                           */
            if(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data)
            {
               /* Verify that the attribute value is valid.             */
               if((Value) && (ValueLength == LLS_ALERT_LEVEL_LENGTH))
               {
                  /* Format and Dispatch the event.                     */
                  EventData = FormatEventHeader(sizeof(Event_Buffer), Event_Buffer, etLLS_Alert_Level_Update, InstanceID, GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->ConnectionID, NULL, GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->ConnectionType, &(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->RemoteDevice));
                  if(EventData)
                  {
                     /* Format the rest of the event.                   */
                     EventData->Event_Data_Size = LLS_ALERT_LEVEL_UPDATE_DATA_SIZE;

                     /* Parse out the command.                          */
                     if(!DecodeAlertLevel(InstanceID, ValueLength, Value, &(EventData->Event_Data.LLS_Alert_Level_Update_Data->AlertLevel)))
                     {
                        /* Since the requested Alert Level was formatted*/
                        /* correctly and with the accepted range we will*/
                        /* accept the new Alert Level.                  */
                        GATT_Write_Response(BluetoothStackID, TransactionID);

                        /* Dispatch the event.                          */
                        __BTPSTRY
                        {
                           (*ServiceInstance->EventCallback)(ServiceInstance->BluetoothStackID, EventData, ServiceInstance->CallbackParameter);
                        }
                        __BTPSEXCEPT(1)
                        {
                           /* Do Nothing.                               */
                        }
                     }
                     else
                        GATT_Error_Response(BluetoothStackID, TransactionID, AttributeOffset, ATT_PROTOCOL_ERROR_CODE_UNLIKELY_ERROR);
                  }
                  else
                     GATT_Error_Response(BluetoothStackID, TransactionID, AttributeOffset, ATT_PROTOCOL_ERROR_CODE_UNLIKELY_ERROR);
               }
Example #8
0
   /* instances.                                                        */
static void BTPSAPI GATT_ServerEventCallback(unsigned int BluetoothStackID, GATT_Server_Event_Data_t *GATT_ServerEventData, unsigned long CallbackParameter)
{
   Word_t                                     AttributeOffset;
   Word_t                                     ValueLength;
   Byte_t                                    *Value;
   unsigned int                               TransactionID;
   unsigned int                               InstanceID;
   KFS_Event_Data_t                           EventData;
   KFSServerInstance_t                       *ServiceInstance;
   
   union
   {
      KFS_Read_Client_Configuration_Data_t    ReadClientData;
      KFS_Client_Configuration_Update_Data_t  ClientUpdateData;
   } EventBuffer;

   /* Verify that all parameters to this callback are Semi-Valid.       */
   if((GATT_ServerEventData) && (CallbackParameter))
   {
      /* The Instance ID is always registered as the callback parameter.*/
      InstanceID = (unsigned int)CallbackParameter;

      /* Acquire the Service Instance for the specified service.        */
      if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL)
      {
         switch(GATT_ServerEventData->Event_Data_Type)
         {
            case etGATT_Server_Read_Request:
               /* Verify that the Event Data is valid.                  */
               if(GATT_ServerEventData->Event_Data.GATT_Read_Request_Data)
               {                  
                  AttributeOffset = GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->AttributeOffset;
                  TransactionID   = GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->TransactionID;

                  /* Check to see if this is a read of the User         */
                  /* Description Descriptor or of the Client            */
                  /* Characteristic Configuration Descriptor.           */
                  if(AttributeOffset == KFS_USER_DESCRIPTION_OFFSET)
                  {
                     /* Verify that the offset is in range.             */
                     if(GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->AttributeValueOffset <= InstanceData[InstanceID-1].CharacteristicUserDescription.Characteristic_Length)
                     {
                        /* Calculate the length of the data that we are    */
                        /* going to return.                                */
                        ValueLength = (Word_t)(InstanceData[InstanceID-1].CharacteristicUserDescription.Characteristic_Length - GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->AttributeValueOffset);
   
                        if(InstanceData[InstanceID-1].CharacteristicUserDescription.Data)
                           Value = &(InstanceData[InstanceID-1].CharacteristicUserDescription.Data[GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->AttributeValueOffset]);
                        else
                        {
                           Value       = NULL;
                           ValueLength = 0;
                        }
   
                        /* Respond with the data.                          */
                        GATT_Read_Response(BluetoothStackID, TransactionID, (unsigned int)ValueLength, Value);
                     }
                     else
                        GATT_Error_Response(BluetoothStackID, TransactionID, AttributeOffset, ATT_PROTOCOL_ERROR_CODE_INVALID_OFFSET);
                  }
                  else
                  {
                     /* This is a read of the Client Characteristic     */
                     /* Configuration Descriptor so we must dispatch    */
                     /* this to the application to handle.              */
                     EventBuffer.ReadClientData.ConnectionID                 = GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->ConnectionID;
                     EventBuffer.ReadClientData.ConnectionType               = GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->ConnectionType;
                     EventBuffer.ReadClientData.RemoteDevice                 = GATT_ServerEventData->Event_Data.GATT_Read_Request_Data->RemoteDevice;
                     EventBuffer.ReadClientData.TransactionID                = TransactionID;
                     EventBuffer.ReadClientData.InstanceID                   = InstanceID;
                                                                             
                     EventData.Event_Data_Type                               = etKFS_Server_Read_Client_Configuration_Request;
                     EventData.Event_Data_Size                               = KFS_READ_CLIENT_CONFIGURATION_DATA_SIZE;
                     EventData.Event_Data.KFS_Read_Client_Configuration_Data = &(EventBuffer.ReadClientData);

                     /* Dispatch the event.                             */
                     __BTPSTRY
                     {
                        (*ServiceInstance->EventCallback)(ServiceInstance->BluetoothStackID, &EventData, ServiceInstance->CallbackParameter);
                     }
                     __BTPSEXCEPT(1)
                     {
                        /* Do Nothing.                                  */
                     }
                  }
               }
               break;
            case etGATT_Server_Write_Request:
               if(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data)
               {
                  AttributeOffset = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeOffset;
                  TransactionID   = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->TransactionID;
                  ValueLength     = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeValueLength;
                  Value           = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeValue;

                  if((!(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->AttributeValueOffset)) && (!(GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->DelayWrite)))
                  {
                     /* Format the Client Configuration Update Event.   */
                     EventBuffer.ClientUpdateData.ConnectionID                 = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->ConnectionID;
                     EventBuffer.ClientUpdateData.ConnectionType               = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->ConnectionType;
                     EventBuffer.ClientUpdateData.RemoteDevice                 = GATT_ServerEventData->Event_Data.GATT_Write_Request_Data->RemoteDevice;
                     EventBuffer.ClientUpdateData.InstanceID                   = InstanceID;
                                                                               
                     EventData.Event_Data_Type                                 = etKFS_Server_Client_Configuration_Update;
                     EventData.Event_Data_Size                                 = KFS_CLIENT_CONFIGURATION_UPDATE_DATA_SIZE;
                     EventData.Event_Data.KFS_Client_Configuration_Update_Data = &(EventBuffer.ClientUpdateData);

                     /* Attempt to decode the request Client            */
                     /* Configuration.                                  */
                     if(!DecodeClientConfigurationValue(ValueLength, Value, &(EventBuffer.ClientUpdateData.NotificationsEnabled)))
                     {
                        /* Go ahead and accept the write request since  */
                        /* we have decode the Client Configuration Value*/
                        /* successfully.                                */
                        GATT_Write_Response(BluetoothStackID, TransactionID);

                        /* Dispatch the event.                          */
                        __BTPSTRY
                        {
                           (*ServiceInstance->EventCallback)(ServiceInstance->BluetoothStackID, &EventData, ServiceInstance->CallbackParameter);
                        }
                        __BTPSEXCEPT(1)
                        {
                           /* Do Nothing.                               */
                        }
                     }
                     else