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