📄 device.cpp
字号:
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pdwType)
{
return(E_INVALIDARG);
}
//
// The device is simply a storage device, which accepts non-SDMI compliant
// content.
//
*pdwType = WMDM_DEVICE_TYPE_STORAGE | WMDM_DEVICE_TYPE_NONSDMI;
//
// Get the device serial number.
//
g_MaverickInfo.GetSerialNumber(m_ulDrive, &sSerialNum);
//
// If we have a serial number, then indicate that we accept SDMI compliant
// content.
//
if(sSerialNum.cbSize != 0)
{
*pdwType |= WMDM_DEVICE_TYPE_SDMI;
}
//
// Success.
//
return(S_OK);
}
//****************************************************************************
//
// IMDSPDevice::GetVersion returns the version number of the device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::GetVersion(DWORD *pdwVersion)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pdwVersion)
{
return(E_INVALIDARG);
}
//
// Return the version number of the device.
//
*pdwVersion = g_MaverickInfo.GetVersion();
//
// Success.
//
return(S_OK);
}
//
// Opaque Command to get extended certification information
//
// GUID = {C39BF696-B776-459c-A13A-4B7116AB9F09}
//
#if 0
static const GUID guidCertInfoEx =
{ 0xc39bf696, 0xb776, 0x459c, { 0xa1, 0x3a, 0x4b, 0x71, 0x16, 0xab, 0x9f, 0x9 } };
typedef struct
{
HRESULT hr;
DWORD cbCert;
BYTE pbCert[1];
} CERTINFOEX;
static const BYTE bCertInfoEx_App[] =
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
static const BYTE bCertInfoEx_SP[] =
{ 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };
#endif
//****************************************************************************
//
// IMDSPDevice::SendOpaqueCommand sends an opaque command to the device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::SendOpaqueCommand(OPAQUECOMMAND *pCommand)
{
//HRESULT hr;
//HMAC hMAC;
//BYTE abMACVerify[WMDM_MAC_LENGTH];
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pCommand)
{
return(E_INVALIDARG);
}
//
// We do not support any opaque device commands.
//
return(WMDM_E_NOTSUPPORTED);
// XYZZY Do we need this?
#if 0
//
// Compute and verify MAC
//
CORg(g_pAppSCServer->MACInit(&hMAC));
CORg(g_pAppSCServer->MACUpdate(hMAC, (BYTE *)(&(pCommand->guidCommand)),
sizeof(GUID)));
CORg(g_pAppSCServer->MACUpdate(hMAC, (BYTE *)(&(pCommand->dwDataLen)),
sizeof(pCommand->dwDataLen)));
if(pCommand->pData)
{
CORg(g_pAppSCServer->MACUpdate(hMAC, (BYTE *)(pCommand->pData),
pCommand->dwDataLen));
}
CORg(g_pAppSCServer->MACFinal(hMAC, abMACVerify));
if(memcmp(abMACVerify, pCommand->abMAC, WMDM_MAC_LENGTH) != 0)
{
CORg(WMDM_E_MAC_CHECK_FAILED);
}
//
// Take action based on the command GUID
//
if(memcmp(&(pCommand->guidCommand), &guidCertInfoEx, sizeof(GUID)) == 0)
{
//
// Command to exchange extended authentication information
//
CERTINFOEX *pCertInfoEx;
DWORD cbData_App = sizeof(bCertInfoEx_App) / sizeof(BYTE);
DWORD cbData_SP = sizeof(bCertInfoEx_SP) / sizeof(BYTE);
DWORD cbData_Return = sizeof(CERTINFOEX) + cbData_SP;
//
// The caller must include their extended cert info
//
if(!pCommand->pData)
{
CORg(E_INVALIDARG);
}
//
// Map the data in the opaque command to a CERTINFOEX structure
//
pCertInfoEx = (CERTINFOEX *)pCommand->pData;
//
// In this simple extended authentication scheme, the caller must
// provide the exact cert info
//
if((pCertInfoEx->cbCert != cbData_App) ||
(memcmp(pCertInfoEx->pbCert, bCertInfoEx_App, cbData_App) != 0))
{
CORg(WMDM_E_NOTCERTIFIED);
}
//
// Free the caller data and allocate enough data for our return data
//
CoTaskMemFree(pCommand->pData);
CFRg((pCommand->pData = (BYTE *)CoTaskMemAlloc(cbData_Return)));
pCommand->dwDataLen = cbData_Return;
//
// Copy the extended cert info into return data structure
//
pCertInfoEx = (CERTINFOEX *)pCommand->pData;
pCertInfoEx->hr = S_OK;
pCertInfoEx->cbCert = cbData_SP;
memcpy(pCertInfoEx->pbCert, bCertInfoEx_SP, cbData_SP);
//
// Compute MAC on return data
//
CORg(g_pAppSCServer->MACInit(&hMAC));
CORg(g_pAppSCServer->MACUpdate(hMAC,
(BYTE *)(&(pCommand->guidCommand)),
sizeof(GUID)));
CORg(g_pAppSCServer->MACUpdate(hMAC, (BYTE *)(&(pCommand->dwDataLen)),
sizeof(pCommand->dwDataLen)));
if(pCommand->pData)
{
CORg(g_pAppSCServer->MACUpdate(hMAC, (BYTE *)(pCommand->pData),
pCommand->dwDataLen));
}
CORg(g_pAppSCServer->MACFinal(hMAC, pCommand->abMAC));
hr = S_OK;
}
else
{
CORg(WMDM_E_NOTSUPPORTED);
}
Error:
return(hr);
#endif
}
//****************************************************************************
//
// IMDSPDeviceControl::GetCapabilities returns the control capabilities of the
// device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::GetCapabilities(DWORD *pdwCapabilitiesMask)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pdwCapabilitiesMask)
{
return(E_INVALIDARG);
}
//
// We do not support any device control.
//
*pdwCapabilitiesMask = 0;
//
// Success.
//
return(S_OK);
}
//****************************************************************************
//
// IMDSPDeviceControl::GetDCStatus returns the control status of the device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::GetDCStatus(DWORD *pdwStatus)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pdwStatus)
{
return(E_INVALIDARG);
}
//
// Our status is always ready.
//
*pdwStatus = WMDM_STATUS_READY;
//
// Success.
//
return(S_OK);
}
//****************************************************************************
//
// IMDSPDeviceControl::Pause pauses the playback or record on the device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::Pause(void)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// We do not support the ::Pause method.
//
return(WMDM_E_NOTSUPPORTED);
}
//****************************************************************************
//
// IMDSPDeviceControl::Play starts playback on the device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::Play(void)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// We do not support the ::Play method.
//
return(WMDM_E_NOTSUPPORTED);
}
//****************************************************************************
//
// IMDSPDeviceControl::Record starts recording on the device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::Record(_WAVEFORMATEX *pFormat)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pFormat)
{
return(E_INVALIDARG);
}
//
// We do not support the ::Record method.
//
return(WMDM_E_NOTSUPPORTED);
}
//****************************************************************************
//
// IMDSPDeviceControl::Resume resumes the paused playback or record on the
// device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::Resume(void)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// We do not support the ::Resume method.
//
return(WMDM_E_NOTSUPPORTED);
}
//****************************************************************************
//
// IMDSPDeviceControl::Seek seeks to the specified position on the device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::Seek(UINT fuMode, int nOffset)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// We do not support the ::Seek method.
//
return(WMDM_E_NOTSUPPORTED);
}
//****************************************************************************
//
// IMDSPDeviceControl::Stop stops the playback or record on the device.
//
//****************************************************************************
STDMETHODIMP
CMDSPDevice::Stop(void)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(E_FAIL);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// We do not support the ::Stop method.
//
return(WMDM_E_NOTSUPPORTED);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -