📄 sdmain.cpp
字号:
switch (dwCode) {
case IOCTL_SD_BUS_DRIVER_GET_SLOT_COUNT:
if (dwLenOut != sizeof(DWORD)) {
dwErr = ERROR_INVALID_PARAMETER;
} else {
DWORD dwSlotCount = pBusDriver->GetSlotInfo(NULL, 0);
cbActualOut = sizeof(DWORD);
if (!CeSafeCopyMemory(pBufOut, &dwSlotCount, cbActualOut)) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
break;
case IOCTL_SD_BUS_DRIVER_GET_SLOT_INFO:
// GetSlotInfo will __try/__except buffer accesses
if (0 == pBusDriver->GetSlotInfo(pBufOut, dwLenOut)) {
dwErr = ERROR_INVALID_PARAMETER;
} else {
cbActualOut = dwLenOut;
}
break;
case IOCTL_SD_BUS_DRIVER_GET_SLOT_POWER_CONTROL:
if ((sizeof(DWORD) == dwLenIn) &&
(sizeof(SLOT_POWER_DATA) == dwLenOut))
{
DWORD dwSlotIndex;
if (!CeSafeCopyMemory(&dwSlotIndex, pBufIn, sizeof(dwSlotIndex))) {
dwErr = ERROR_INVALID_PARAMETER;
}
else {
SLOT_POWER_DATA slotPowerData;
cbActualOut = sizeof(slotPowerData);
SD_API_STATUS status = pBusDriver->GetSlotPowerControlInfo(dwSlotIndex,
&slotPowerData);
if ( !SD_API_SUCCESS(status) ||
!CeSafeCopyMemory(pBufOut, &slotPowerData, sizeof(slotPowerData)) ) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
}
else if ( (sizeof(BUS_DRIVER_IN_SLOT_FUNCTION_POWER) == dwLenIn) &&
(sizeof(FUNCTION_POWER_DATA) == dwLenOut) )
{
BUS_DRIVER_IN_SLOT_FUNCTION_POWER FuncPowerIn;
if (!CeSafeCopyMemory(&FuncPowerIn, pBufIn, sizeof(FuncPowerIn))) {
dwErr = ERROR_INVALID_PARAMETER;
}
else {
FUNCTION_POWER_DATA FuncPowerData;
cbActualOut = sizeof(FuncPowerData);
SD_API_STATUS status = pBusDriver->GetFunctionPowerControlInfo(
FuncPowerIn.SlotIndex, FuncPowerIn.FunctionNumber, &FuncPowerData);
if ( !SD_API_SUCCESS(status) ||
!CeSafeCopyMemory(pBufOut, &FuncPowerData, sizeof(FuncPowerData)) ) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
}
else {
dwErr = ERROR_INVALID_PARAMETER;
}
break;
case IOCTL_SD_BUS_DRIVER_DISABLE_SLOT_POWER_CONTROL:
if(sizeof(DWORD) == dwLenIn)
{
DWORD dwSlotIndex;
if (!CeSafeCopyMemory(&dwSlotIndex, pBufIn, sizeof(dwSlotIndex))) {
dwErr = ERROR_INVALID_PARAMETER;
}
else if (!SD_API_SUCCESS(pBusDriver->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)
{
DWORD dwSlotIndex;
if (!CeSafeCopyMemory(&dwSlotIndex, pBufIn, sizeof(dwSlotIndex))) {
dwErr = ERROR_INVALID_PARAMETER;
}
else if (!SD_API_SUCCESS(pBusDriver->SetSlotPowerControl(dwSlotIndex, TRUE))) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
else {
dwErr = ERROR_INVALID_PARAMETER;
}
break;
case IOCTL_SD_BUS_DRIVER_GET_VERSION:
if (dwLenOut != sizeof(DWORD)) {
dwErr = ERROR_INVALID_PARAMETER;
}
else {
DWORD dwVersion = MAKELONG(CE_MINOR_VER, CE_MAJOR_VER);
cbActualOut = sizeof(dwVersion);
if (!CeSafeCopyMemory(pBufOut, &dwVersion, sizeof(DWORD))) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
break;
#ifdef ENABLE_SDIO_V1_1_SUPPORT
case IOCTL_SD_BUS_DRIVER_SLOT_CARD_RESET:
if (sizeof(DWORD) == dwLenIn) {
DWORD dwSlotIndex;
if (!CeSafeCopyMemory(&dwSlotIndex, pBufIn, sizeof(dwSlotIndex))) {
dwErr = ERROR_INVALID_PARAMETER;
}
else if (!pBusDriver->SlotCardSelectDeselect(dwSlotIndex, SlotResetRequest)) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
else {
dwErr = ERROR_INVALID_PARAMETER;
}
break;
case IOCTL_SD_BUS_DRIVER_SLOT_CARD_SELECT:
if (sizeof(DWORD) == dwLenIn) {
DWORD dwSlotIndex;
if (!CeSafeCopyMemory(&dwSlotIndex, pBufIn, sizeof(dwSlotIndex))) {
dwErr = ERROR_INVALID_PARAMETER;
}
else if (!pBusDriver->SlotCardSelectDeselect(dwSlotIndex, SlotSelectRequest)) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
else {
dwErr = ERROR_INVALID_PARAMETER;
}
break;
case IOCTL_SD_BUS_DRIVER_SLOT_CARD_DESELECT:
if (sizeof(DWORD) == dwLenIn) {
DWORD dwSlotIndex;
if (!CeSafeCopyMemory(&dwSlotIndex, pBufIn, sizeof(dwSlotIndex))) {
dwErr = ERROR_INVALID_PARAMETER;
}
else if (!pBusDriver->SlotCardSelectDeselect(dwSlotIndex, SlotDeselectRequest)) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
else {
dwErr = ERROR_INVALID_PARAMETER;
}
break;
#endif //ENABLE_SDIO_V1_1_SUPPORT
default:
dwErr = ERROR_INVALID_PARAMETER;
}
if (cbActualOut != -1 && pdwActualOut && dwErr == ERROR_SUCCESS) {
if (!CeSafeCopyMemory(pdwActualOut, &cbActualOut, sizeof(DWORD))) {
dwErr = ERROR_INVALID_PARAMETER;
}
}
if (dwErr != ERROR_SUCCESS) {
SetLastError(dwErr);
fRet = FALSE;
}
}
DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDBusDriver: -SDC_IOControl 0x%X\n"), fRet));
return fRet;
}
///////////////////////////////////////////////////////////////////////////////
// SDC_Open - the open entry point for the bus driver
// Input: hDeviceContext - the device context from SDC_Init
// AccessCode - the desired access
// ShareMode - the desired share mode
// Output:
// Return: returns open context (in this case, just the context from SDC_Init)
// Notes:
///////////////////////////////////////////////////////////////////////////////
extern "C"
DWORD SDC_Open(DWORD hDeviceContext,
DWORD AccessCode,
DWORD ShareMode)
{
DWORD dwRet;
DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDBusDriver: +-SDC_Open\n")));
DEBUGCHK(hDeviceContext == (DWORD) s_pSDBusDriver);
if (AccessCode & DEVACCESS_BUSNAMESPACE) {
// This is a bus access
dwRet = (DWORD) &s_fBusAccessContext;
}
else {
// Standard access
dwRet = hDeviceContext;
}
return dwRet;
}
// Fill in the host controller's function table.
extern "C"
SD_API_STATUS
SDHCDGetHCFunctions(
PSDHOST_API_FUNCTIONS pFunctions
)
{
SD_API_STATUS status = SD_API_STATUS_INVALID_PARAMETER;
DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDHCDGetHCFunctions: +Init\n")));
if ( pFunctions && (pFunctions->dwSize == sizeof(*pFunctions)) ) {
pFunctions->pAllocateContext = &SDHCDAllocateContext__X;
pFunctions->pDeleteContext = &SDHCDDeleteContext__X;
pFunctions->pRegisterHostController = &SDHCDRegisterHostController__X;
pFunctions->pDeregisterHostController = &SDHCDDeregisterHostController__X;
pFunctions->pIndicateSlotStateChange = &SDHCDIndicateSlotStateChange__X;
pFunctions->pIndicateBusRequestComplete = &SDHCDIndicateBusRequestComplete__X;
pFunctions->pUnlockRequest = &SDHCDUnlockRequest__X;
pFunctions->pGetAndLockCurrentRequest = &SDHCDGetAndLockCurrentRequest__X;
pFunctions->pPowerUpDown = &SDHCDPowerUpDown__X;
status = SD_API_STATUS_SUCCESS;
}
else {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHCDGetHCFunctions: Invalid parameter\n")));
}
DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDHCDGetHCFunctions: -Init\n")));
return status;
}
// DO NOT REMOVE --- END EXTERNALLY DEVELOPED SOURCE CODE ID --- DO NOT REMOVE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -