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