/* 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); }
/* occurred. */ int Bluetooth::openServer(unsigned int port){ int ret_val; char *ServiceName; /* First check to see if a valid Bluetooth Stack ID exists. */ if(bluetoothStackID) { /* Make sure that there is not already a Serial Port Server open. */ if(!ServerPortID) { /* Simply attempt to open an Serial Server, on RFCOMM Server*/ /* Port 1. */ ret_val = SPP_Open_Server_Port(bluetoothStackID, port, SPP_Event_Callback, (unsigned long)this); /* If the Open was successful, then note the Serial Port */ /* Server ID. */ if(ret_val > 0) { /* Note the Serial Port Server ID of the opened Serial */ /* Port Server. */ ServerPortID = ret_val; /* Create a Buffer to hold the Service Name. */ if((ServiceName = (char*)BTPS_AllocateMemory(64)) != NULL) { /* The Server was opened successfully, now register a */ /* SDP Record indicating that an Serial Port Server */ /* exists. Do this by first creating a Service Name. */ BTPS_SprintF(ServiceName, "Serial Port Server Port %d", port); /* Now that a Service Name has been created try to */ /* Register the SDP Record. */ ret_val = SPP_Register_Generic_SDP_Record(bluetoothStackID, ServerPortID, ServiceName, const_cast<DWord_t*>(&SPPServerSDPHandle)); /* If there was an error creating the Serial Port */ /* Server's SDP Service Record then go ahead an close */ /* down the server an flag an error. */ if(ret_val < 0) { SPP_Close_Server_Port(bluetoothStackID, ServerPortID); /* Flag that there is no longer an Serial Port */ /* Server Open. */ ServerPortID = 0; /* Flag that we are no longer connected. */ Connected = FALSE; ret_val = -1; } else { /* Simply flag to the user that everything */ /* initialized correctly. */ /* Flag success to the caller. */ ret_val = 0; } /* Free the Service Name buffer. */ BTPS_FreeMemory(ServiceName); } } else { ret_val = -1; } } else { /* A Server is already open, this program only supports one */ /* Server or Client at a time. */ ret_val = -1; } } else { /* No valid Bluetooth Stack ID exists. */ ret_val = -1; } return(ret_val); }