📄 sdbus.cpp
字号:
else {
ULONG curSlotCount = slotCount;
PBUS_DRIVER_SLOT_INFO pCurSlotInfo = pslotInfoArray;
for (DWORD dwHostIndex = 0; dwHostIndex < m_dwArraySize && curSlotCount ; dwHostIndex++) {
if (m_rgObjectArray[dwHostIndex]!=NULL) {
for (DWORD dwSlotIndex= 0; dwSlotIndex< m_rgObjectArray[dwHostIndex]->GetSlotCount() && curSlotCount; dwSlotIndex++) {
CSDSlot * psdSlot = m_rgObjectArray[dwHostIndex]->GetSlot(dwSlotIndex);
WCHAR description[MAX_SD_DESCRIPTION_STRING];
StringCchCopy(description,_countof(description), TEXT("Empty Slot"));
if (psdSlot) {
BOOL fContinue = TRUE;
for (DWORD dwFuncIndex = 0; dwFuncIndex< SD_MAXIMUM_DEVICE_PER_SLOT && fContinue; dwFuncIndex++) {
CSDDevice * pDevice = psdSlot->GetFunctionDevice(dwFuncIndex);
if (pDevice) {
if (pDevice->IsDriverLoaded()) {
StringCchCopy(description,_countof(description), pDevice->GetClientName());
__try {
pCurSlotInfo->CardInterface = ConvertFromEx(pDevice->GetCardInterface());
pCurSlotInfo->CardPresent = TRUE;
pCurSlotInfo->DeviceType = pDevice->GetDeviceType();
}
__except (SDProcessException(GetExceptionInformation())) {
slotCount = 0;
curSlotCount = 0;
}
fContinue = FALSE;
}
pDevice->DeRef();
}
}
if (fContinue) {
CSDDevice * pDevice = psdSlot->GetFunctionDevice(0);// Master Device.
if (pDevice) {
__try {
pCurSlotInfo->CardInterface = ConvertFromEx(pDevice->GetCardInterface());
pCurSlotInfo->CardPresent = TRUE;
pCurSlotInfo->DeviceType = pDevice->GetDeviceType();
}
__except (SDProcessException(GetExceptionInformation())) {
slotCount = 0;
curSlotCount = 0;
}
pDevice->DeRef();
}
}
}
__try {
StringCchCopy(pCurSlotInfo->Description,_countof(pCurSlotInfo->Description),description);
pCurSlotInfo->HostIndex = dwHostIndex;
pCurSlotInfo->SlotIndex = dwSlotIndex;
}
__except (SDProcessException(GetExceptionInformation())) {
slotCount = 0;
curSlotCount = 0;
}
curSlotCount--;
pCurSlotInfo++;
}
}
};
}
}
((CStaticContainer *)this)->Unlock();
return slotCount;
}
BOOL CSDHostContainer::GetHCandSlotbySlotIndex(CSDHost ** ppHost,CSDSlot**ppSlot,DWORD dwSlotIndex )
{
BOOL fRet = FALSE;
if (ppHost && ppSlot) {
((CStaticContainer *)this)->Lock();
for (DWORD dwIndex = 0 ; dwIndex < m_dwArraySize; dwIndex++) {
if (m_rgObjectArray[dwIndex]!=NULL) {
if (dwSlotIndex< m_rgObjectArray[dwIndex]->GetSlotCount()) {
*ppHost = m_rgObjectArray[dwIndex];
*ppSlot = (*ppHost)->GetSlot(dwSlotIndex);
(*ppHost)->AddRef();
fRet = TRUE;
break;
}
else {
dwSlotIndex -= m_rgObjectArray[dwIndex]->GetSlotCount();
}
}
};
((CStaticContainer *)this)->Unlock();
}
return fRet;
}
///////////////////////////////////////////////////////////////////////////////
// GetSlotPowerControlInfo - get slot power control information
// Input: slotIndexWanted - index of slot
//
// Output: pPCdata - data about power control at the slot
// Notes:
// returns SD Api Error
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDHostContainer::GetSlotPowerControlInfo(DWORD slotIndexWanted,
PSLOT_POWER_DATA pPCdata)
{
CSDHost *pHost = NULL;
CSDSlot *pSlot = NULL;
SD_API_STATUS status = SD_API_STATUS_NO_SUCH_DEVICE;
if (GetHCandSlotbySlotIndex(&pHost,&pSlot,slotIndexWanted) && pSlot!=NULL) {
memset(pPCdata, 0, sizeof(SLOT_POWER_DATA));
status = pSlot->CheckSlotReady();
if (SD_API_SUCCESS(status)) {
status = SD_API_STATUS_UNSUCCESSFUL;
CSDDevice * pDevice = pSlot->GetFunctionDevice(0);// Master Device.
if (pDevice) {
if (pDevice->GetCardInfo().SDIOInformation.pCommonInformation!=NULL) {
pPCdata->fCardSupportsPowerControl = pDevice->GetCardInfo().SDIOInformation.pCommonInformation->fCardSupportsPowerControl;
pPCdata->fPowerControlEnabled = pDevice->GetCardInfo().SDIOInformation.pCommonInformation->fPowerControlEnabled;
pPCdata->CurrentDrawOfSlot = pSlot->GetSlotPower();
pPCdata->OperatingVoltage = pDevice->GetOperationVoltage();
pPCdata->CurrentTupleVoltageRange = SD_MASK_FOR_33V_POWER_CONTROL_TUPLE;
pPCdata->NumberOfHighPowerTuples = 1; // For SDIO 1.1 this is 1
pPCdata->SizeOfFunctionRecord = sizeof(FUNCTION_POWER_DATA);
pPCdata->Functions =(UCHAR) pSlot->GetNumOfFunctionDevice();
status = SD_API_STATUS_SUCCESS ;
}
pDevice->DeRef();
}
}
}
if (pHost)
pHost->DeRef();
return status;
}
///////////////////////////////////////////////////////////////////////////////
// GetFunctionPowerControlInfo - get function power control information
// Input: slotIndexWanted - index of slot
// - index of slot
//
// Output: pFPCdata - data about power control at the function
// Notes:
// returns SD Api Error
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDHostContainer::GetFunctionPowerControlInfo(DWORD slotIndexWanted,
DWORD FunctionIndexWanted,
PFUNCTION_POWER_DATA pFPCdata)
{
CSDHost *pHost = NULL;
CSDSlot *pSlot = NULL;
SD_API_STATUS status = SD_API_STATUS_NO_SUCH_DEVICE;
if (GetHCandSlotbySlotIndex(&pHost,&pSlot,slotIndexWanted) && pSlot!=NULL) {
memset(pFPCdata, 0, sizeof(FUNCTION_POWER_DATA));
status = pSlot->CheckSlotReady();
if (SD_API_SUCCESS(status)) {
status = SD_API_STATUS_UNSUCCESSFUL;
CSDDevice * pDevice = pSlot->GetFunctionDevice(FunctionIndexWanted);// Master Device.
if (pDevice) {
StringCchCopy(pFPCdata->ClientName,_countof(pFPCdata->ClientName), pDevice->GetClientName() );
status = pDevice->GetFunctionPowerState(&pFPCdata->PowerState);
pFPCdata->PowerTuples = pDevice->GetCardInfo().SDIOInformation.PowerDrawData;
pDevice->DeRef();
}
}
}
if (pHost)
pHost->DeRef();
return status;
}
///////////////////////////////////////////////////////////////////////////////
// SetSlotPowerControl - set if a slot will enable power control on card insertion
// Input: slotIndexWanted - index of slot
// fEnablePowerControl - flag set if power control is to be enabled or not
//
// Output:
// Notes:
// returns SD Api Error
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDHostContainer::SetSlotPowerControl(DWORD slotIndexWanted, BOOL fEnablePowerControl)
{
CSDHost *pHost = NULL;
CSDSlot *pSlot = NULL;
SD_API_STATUS status = SD_API_STATUS_NO_SUCH_DEVICE;
if (GetHCandSlotbySlotIndex(&pHost,&pSlot,slotIndexWanted) && pSlot!=NULL) {
pSlot->SetSlotPowerControl(fEnablePowerControl);
status = SD_API_STATUS_SUCCESS ;
}
if (pHost)
pHost->DeRef();
return status;
}
///////////////////////////////////////////////////////////////////////////////
// SlotCardSelectDeselect - Select/Deselect the card in teh slot
// Input: SlotIndexWanted - index of slot
// Event - SlotDeselectRequest/SlotSelectRequest/SlotResetRequest
// Output:
// Notes:
///////////////////////////////////////////////////////////////////////////////
BOOL CSDHostContainer::SlotCardSelectDeselect(DWORD SlotIndexWanted, SD_SLOT_EVENT Event)
{
BOOL retStatus = FALSE; // return status
CSDHost *pHost = NULL;
CSDSlot *pSlot = NULL;
if (GetHCandSlotbySlotIndex(&pHost,&pSlot,SlotIndexWanted) && pSlot!=NULL) {
retStatus= pSlot->SlotCardSelectDeselect(Event);
}
if (pHost)
pHost->DeRef();
return retStatus;
}
BOOL
CSDHostContainer::SDC_IOControl(DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
DWORD dwErr = ERROR_SUCCESS;
DWORD cbActualOut = -1;
switch (dwCode) {
case IOCTL_SD_BUS_DRIVER_GET_SLOT_COUNT:
if (dwLenOut != sizeof(DWORD)) {
dwErr = ERROR_INVALID_PARAMETER;
} else {
*(PDWORD)pBufOut = GetSlotInfo(NULL, 0);
cbActualOut = sizeof(DWORD);
}
break;
case IOCTL_SD_BUS_DRIVER_GET_SLOT_INFO:
if (0 == GetSlotInfo((PBUS_DRIVER_SLOT_INFO)pBufOut, dwLenOut)) {
dwErr = ERROR_INVALID_PARAMETER;
} else {
cbActualOut = dwLenOut;
}
break;
case IOCTL_SD_BUS_DRIVER_GET_SLOT_POWER_CONTROL:
if ((sizeof(DWORD) == dwLenIn) && pBufIn!=NULL &&
(sizeof(SLOT_POWER_DATA) == dwLenOut) && pBufOut!=NULL) {
DWORD dwSlotIndex = *(PDWORD)pBufIn;
SLOT_POWER_DATA slotPowerData;
cbActualOut = sizeof(slotPowerData);
SD_API_STATUS status = GetSlotPowerControlInfo(dwSlotIndex,&slotPowerData);
if (SD_API_SUCCESS(status)) {
*(PSLOT_POWER_DATA)pBufOut = slotPowerData;
}
else {
dwErr = ERROR_GEN_FAILURE;
}
}
else if ( (sizeof(BUS_DRIVER_IN_SLOT_FUNCTION_POWER) == dwLenIn) && pBufIn!=NULL &&
(sizeof(FUNCTION_POWER_DATA) == dwLenOut)&& pBufOut!=NULL ){
BUS_DRIVER_IN_SLOT_FUNCTION_POWER FuncPowerIn = *(BUS_DRIVER_IN_SLOT_FUNCTION_POWER *)pBufIn ;
FUNCTION_POWER_DATA FuncPowerData;
cbActualOut = sizeof(FuncPowerData);
SD_API_STATUS status = GetFunctionPowerControlInfo(
FuncPowerIn.SlotIndex, FuncPowerIn.FunctionNumber, &FuncPowerData);
if ( SD_API_SUCCESS(status)) {
*(PFUNCTION_POWER_DATA)pBufOut = FuncPowerData;
}
else {
dwErr = ERROR_GEN_FAILURE;
}
}
else {
dwErr = ERROR_INVALID_PARAMETER;
}
break;
case IOCTL_SD_BUS_DRIVER_DISABLE_SLOT_POWER_CONTROL:
if(sizeof(DWORD) == dwLenIn && pBufIn!=NULL){
DWORD dwSlotIndex = *(PDWORD)pBufIn;
if (!SD_API_SUCCESS(SetSlotPowerControl(dwSlotIndex, FALSE))) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
else {
dwErr = ERROR_INVALID_PARAMETER;
}
break;
case IOCTL_SD_BUS_DRIVER_ENABLE_SLOT_POWER_CONTROL:
if (sizeof(DWORD) == dwLenIn && pBufIn!=NULL ) {
DWORD dwSlotIndex = *(PDWORD)pBufIn;
if (!SD_API_SUCCESS(SetSlotPowerControl(dwSlotIndex, TRUE))) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
else {
dwErr = ERROR_INVALID_PARAMETER;
}
break;
case IOCTL_SD_BUS_DRIVER_GET_VERSION:
if (dwLenOut != sizeof(DWORD) && pBufOut) {
dwErr = ERROR_INVALID_PARAMETER;
}
else {
*(PDWORD)pBufOut = MAKELONG(CE_MINOR_VER, CE_MAJOR_VER);
cbActualOut = sizeof(DWORD);
}
break;
case IOCTL_SD_BUS_DRIVER_SLOT_CARD_RESET:
if (sizeof(DWORD) == dwLenIn && pBufIn) {
DWORD dwSlotIndex = *(PDWORD)pBufIn;
if (!SlotCardSelectDeselect(dwSlotIndex, SlotResetRequest)) {
dwErr = ERROR_INVALID_PARAMETER;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -