/* 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); }
/* 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); }
/* 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