⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 authhost.c

📁 wince host 和 target PCI驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [10]	= (0x03 | gbAGID);


	/* 0A00 0000 4020 B523 0011 0000 */
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer[0] = 0;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer[1] = 0x0A;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer[2] = 0;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer[3] = 0;
	pByte = (PByte)&((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer[4];
	memcpy(pByte,(Byte *)response, 5);

	if (!SendDeviceCommand(InqSRB))
	{
		VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
		VirtualFree(InqSRB, 0, MEM_RELEASE);
		return FALSE;
	}
	VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
	VirtualFree(InqSRB, 0, MEM_RELEASE);
	return TRUE;
}


BOOL Rdstrct1 (PBYTE pIsScramble)
{
	void	*InqSRB;			/* temporary inquiry ASPI SRB pointer */

	DBGS("Rdstrct1\n\r");
	InqSRB = VirtualAlloc(NULL, ASPI_SRB_LEN, MEM_COMMIT, PAGE_READWRITE);
	if (!InqSRB)
		DBGS("Rdstrct1 Allocation Failed ONE\n\r");
	memset(InqSRB, 0, ASPI_SRB_LEN);
	((PSRB_ExecSCSICmd) InqSRB)->SRB_Cmd			= SC_EXEC_SCSI_CMD;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_Flags			= SRB_DIR_IN | SRB_POSTING;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer	=
						VirtualAlloc(NULL, 8, MEM_COMMIT, PAGE_READWRITE);
	if (!((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer)
		DBGS("Rdstrct1 Allocation Failed ONE\n\r");
	memset(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, 8);
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufLen		= 8;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_SenseLen		= SENSE_LEN;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_CDBLen		= 12;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [0]		= 0xAD;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [7]		= 0x01;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [8]		= 0x00;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [9]		= 0x08;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [10]		= gbAGID;

	DBG2("Address InqSRB = %x pIsScramble = %x\n\r",(DWORD)&InqSRB,(DWORD)&pIsScramble);
	if (!SendDeviceCommand(InqSRB))
	{
		VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
		VirtualFree(InqSRB, 0, MEM_RELEASE);
		return FALSE;
	}
	if (!ReadDeviceBuffer(InqSRB))
	{
		VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
		VirtualFree(InqSRB, 0, MEM_RELEASE);
		return FALSE;
	}
	*pIsScramble = ((PSRB_ExecSCSICmd)InqSRB)->SRB_BufPointer[4];
	VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
	VirtualFree(InqSRB, 0, MEM_RELEASE);
	return TRUE;
}


BOOL Rdstrct2 (Byte bedk[2045])
{
	void	*InqSRB;			/* temporary inquiry ASPI SRB pointer */
	Byte 	*pByte;

	DBGS("Rdstrct2\n\r");
    InqSRB = VirtualAlloc(NULL, ASPI_SRB_LEN, MEM_COMMIT, PAGE_READWRITE);
	if (!InqSRB)
		DBGS("Rdstrct2 Allocation Failed ONE\n\r");
	memset(InqSRB, 0, ASPI_SRB_LEN);
	((PSRB_ExecSCSICmd) InqSRB)->SRB_Cmd		= SC_EXEC_SCSI_CMD;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_Flags		= SRB_DIR_IN | SRB_POSTING;
	//***I better be safe with this, rather allocate bigger than smaller
	//***chunk!!!
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer	= 
			VirtualAlloc(NULL, RDSTRCT2_BUFFER_LENGTH + 4, MEM_COMMIT, PAGE_READWRITE);
	if (!((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer)
		DBGS("Rdstrct2 Allocation Failed TWO\n\r");
	memset(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, RDSTRCT2_BUFFER_LENGTH);
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufLen		= RDSTRCT2_BUFFER_LENGTH;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_SenseLen	= SENSE_LEN;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_CDBLen		= 12;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [0]	= 0xAD;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [7]	= 0x02;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [8]	= 0x08;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [9]	= 0x04;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [10]	= gbAGID;

	if (!SendDeviceCommand(InqSRB))
	{
		VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
		VirtualFree(InqSRB, 0, MEM_RELEASE);
		return FALSE;
	}
	if (!ReadDeviceBuffer(InqSRB))
	{
		VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
		VirtualFree(InqSRB, 0, MEM_RELEASE);
		return FALSE;
	}

	//***Don't know why Pioneer drive you have to read twice for the diskkey,
	//***For Pioneer driver, it'll read the second time, while other drives,
	//***this second read buffer will fail, and it is OK
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer += 4; 
	ReadDeviceBuffer(InqSRB);
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer -= 4; 

	pByte = &((PSRB_ExecSCSICmd)InqSRB)->SRB_BufPointer[4];
	memcpy(bedk, pByte, 2045);
	VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
	VirtualFree(InqSRB, 0, MEM_RELEASE);
	return TRUE;
}

BOOL Report5 (void)
{
	void	*InqSRB;			/* temporary inquiry ASPI SRB pointer */

	DBGS("Report5\n\r");
    InqSRB = VirtualAlloc(NULL, ASPI_SRB_LEN, MEM_COMMIT, PAGE_READWRITE);
	if (!InqSRB)
		DBGS("Report5 Allocation Failed ONE\n\r");
	memset(InqSRB, 0, ASPI_SRB_LEN);
	((PSRB_ExecSCSICmd) InqSRB)->SRB_Cmd			= SC_EXEC_SCSI_CMD;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_Flags			= SRB_DIR_IN | SRB_POSTING;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer	= 
			VirtualAlloc(NULL, REPORT5_BUFFER_LENGTH, MEM_COMMIT, PAGE_READWRITE);
	if (!((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer)
		DBGS("Report5 Allocation Failed ONE\n\r");
	memset(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, REPORT5_BUFFER_LENGTH);
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufLen		= REPORT5_BUFFER_LENGTH;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_SenseLen		= SENSE_LEN;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_CDBLen		= 12;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [0]		= 0xA4;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [8]		= 0xFF;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [9]		= 0xFF;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [10]		= (0x05 | gbAGID);
	
	if (!SendDeviceCommand(InqSRB))
	{
		VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
		VirtualFree(InqSRB, 0, MEM_RELEASE);
		return FALSE;
	}
	if (!ReadDeviceBuffer(InqSRB))
	{
		VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
		VirtualFree(InqSRB, 0, MEM_RELEASE);
		return FALSE;
	}

	//***Now should I check the LSB of Byte 7 to see if Authentication 
	//***Success Flag set or not ???
	{
		if ( ((PSRB_ExecSCSICmd)InqSRB)->SRB_BufPointer[7] & 0x01)
			printf(">>>>>>Authentication Success<<<<<<\n\r");
		else		
			printf(">>>>>>Authentication Failure<<<<<<\n\r");
	}

	VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
	VirtualFree(InqSRB, 0, MEM_RELEASE);
	return TRUE;
}

BOOL Report4 (Byte titleKey[5])
{
	void	*InqSRB;			/* temporary inquiry ASPI SRB pointer */
	Byte	*pByte;

	DBGS("Report4\n\r");
    InqSRB = VirtualAlloc(NULL, ASPI_SRB_LEN, MEM_COMMIT, PAGE_READWRITE);
	if (!InqSRB)
		DBGS("Report4 Allocation Failed ONE\n\r");
	memset(InqSRB, 0, ASPI_SRB_LEN);
	((PSRB_ExecSCSICmd) InqSRB)->SRB_Cmd		= SC_EXEC_SCSI_CMD;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_Flags		= SRB_DIR_IN | SRB_POSTING;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer	= 
			VirtualAlloc(NULL, REPORT4_BUFFER_LENGTH, MEM_COMMIT, PAGE_READWRITE);
	memset(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, REPORT4_BUFFER_LENGTH);
	if (!((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer)
		DBGS("Report4 Allocation Failed TWO\n\r");
	((PSRB_ExecSCSICmd) InqSRB)->SRB_BufLen		= REPORT4_BUFFER_LENGTH;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_SenseLen	= SENSE_LEN;
	((PSRB_ExecSCSICmd) InqSRB)->SRB_CDBLen		= 12;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [0]	= 0xA4;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [4]	= 0x3A;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [5]	= 0xC4;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [9]	= 0x0C;
	((PSRB_ExecSCSICmd) InqSRB)->CDBByte [10]	= (0x04 | gbAGID);
	
	if (!SendDeviceCommand(InqSRB))
	{
		VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
		VirtualFree(InqSRB, 0, MEM_RELEASE);
		return FALSE;
	}
	if (!ReadDeviceBuffer(InqSRB))
	{
		VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
		VirtualFree(InqSRB, 0, MEM_RELEASE);
		return FALSE;
	}
	pByte = &((PSRB_ExecSCSICmd)InqSRB)->SRB_BufPointer[5];
	memcpy((PByte)titleKey, pByte, 5);
	VirtualFree(((PSRB_ExecSCSICmd) InqSRB)->SRB_BufPointer, 0, MEM_RELEASE);
	VirtualFree(InqSRB, 0, MEM_RELEASE);
	return TRUE;
}


/*
 * Function         : Open a drive, and return a handle
 * Parameters       : Drive Number (1..4), Error Code  
 * Function Result  : resulting Drive Handle or NULL
 */
extern DLLEXPORT int _stdcall dvdIntOpenDrive(dvdIntDrive *pidvdHandle)
{
	BYTE 	bCounter;
	BYTE 	bIsScramble;
	DWORD dwErrorCode;
	int	iNumTriesAGID=25;	//hnx:testing

	//***AutoDetect the drive
	//***Check to see if Drive is Open
	//***Check to see if there is Disk Drive
	DBGS("DLL:dvdIntOpenDrive\n\r");

	*pidvdHandle = 0;	//Well, let the handle to be NULL now!!!

	if (!LoadKernelDrv(&dwErrorCode))
		return dwErrorCode;

	bCounter = 50;
	while (!Rdstrct1(&bIsScramble))
		if (--bCounter == 0)
			return ERROR_UNKNOWN;

	if (!bIsScramble)
		return ERROR_NOAUTHREQUIRE;

	if (!StartUnit())
		DBGS("StartUnit FAILED\n\r");	//***But still keep go on

 	*pidvdHandle = 1;	//***Drive Handle, for now we just look at the first drive		 
	return ERROR_NONE;//***Successful Open
}


/*
 * Function         : Close a drive
 * Parameters       : drive     (I) drive to close
 * Function Result  : resulting error condition
 */

extern DLLEXPORT _stdcall dvdIntCloseDrive( dvdIntDrive drive )
{
	DBGS("DLL:dvdIntCloseDrive\n\r");

	gbAGID = 0;		//***Defensive programming
	
	CloseKernelDrv();
	return 0;
}

/*
 * Function         : Put a challenge to specified drive
 * Parameters       : drive     (I) drive to put challenge to
 *                    challenge (I) challenge to put
 * Function Result  : resulting error condition
 */

extern DLLEXPORT int _stdcall dvdIntPutDrvChallenge( dvdIntDrive drive, Byte challenge[10] )
{
	int	iNumTriesAGID=25;
	BYTE	bCounter;	//hnx:testing

	DBGS("DLL:dvdIntPutDrvChallenge\n\r");
	//***Invalidate all gbAGIDs possible
	for (bCounter = 0; bCounter < 4; bCounter++)
	{
		gbAGID = bCounter << 6;
		Report3f();
	}

	//***Why do I have to work so hard to get the AGID here ???
	while (!Report0())
	{
		if (--iNumTriesAGID == 0)
		{
			DBGS("DLL: dvdIntOpenDrive Can't get AGID\n\r");
			return -1;
		}
	}

	//***SndKey1, get 10 Bytes challenge key and send to drive
	if (!SndKey1(challenge))
	{
		DBGS("DLL:dvdIntPutDrvChallenge Challenge to drive ERROR\n\r");
		return -1;
	}		

	return 0;
}


/*
 * Function         : Get response on challenge from specified drive
 * Parameters       : drive     (I) drive to get response from
 *                    response  (O) response to get.
 * Function Result  : resulting error condition
 */

extern DLLEXPORT int _stdcall dvdIntGetDrvResponse( dvdIntDrive drive, Byte response[5] )

{
	DBGS("DLL:dvdIntGetDrvResponse\n\r");

	//***Report2 Save Byte 4 to Byte 8	
	if (!Report2(response))
	{
		DBGS("DLL:dvdIntGetDrvResponse Get Response from Drive ERROR\n\r");
		return -1;
	}
	return 0;
}

/*
 * Function         : Get challenge from specified drive
 * Parameters       : drive     (I) drive to get challenge from
 *                    challenge (O) challenge to get.
 * Function Result  : resulting error condition
 */

extern DLLEXPORT int _stdcall dvdIntGetDecChallenge( dvdIntDrive drive, Byte challenge[10] )
{
	DBGS("DLL:dvdIntGetDecChallenge\n\r");

	//***Report1 Save Byte 4 to Byte 13
	if (!Report1(challenge))
	{
		DBGS("DLL:dvdIntGetDecChallenge Get DecChallenge ERROR\n\r");
		return -1;
	}

	return 0;
}


/*
 * Function         : Put response on previously obtained challenge
 *                    to specified drive
 * Parameters       : drive     (I) drive to put response to
 *                    response  (O) response to get
 * Function Result  : resulting error condition
 */

extern DLLEXPORT int _stdcall dvdIntPutDecResponse( dvdIntDrive drive, Byte response[5] )
{
	DBGS("DLL:dvdIntPutDecResponse\n\r");

	printf("DLL DriveResponse received: ");

	//***SndKey3 Put Bytes respond to Byte 4 to Byte 8
	if (!SndKey3(response))
	{
		DBGS("DLL:dvdIntPutDecResponse Put Dec Response ERROR\n\r");
		return -1;
	}
	return 0;
}


/*
 * Function         : Get bus encoded disc key from specified drive
 * Parameters       : drive     (I) drive to get key from
 *                    bedk      (O) key to get
 * Function Result  : resulting error condition
 */

extern DLLEXPORT int _stdcall dvdIntGetEncDiscKey( dvdIntDrive drive, Byte bedk[2045] )
{
	DBGS("DLL:dvdIntGetEncDiscKey\n\r");

	//***Rdstrct2 Get either 2045 
	//***report5 Check for AUTHENTICATION Success flag, LSB of Byte 7, if
	//***successful, return success

	if (!Rdstrct2(bedk))
	{
		DBGS("DLL:dvdIntGetEncDiscKey Get Encode Disk Key ERROR\n\r");
		return -1;
	}

	if (!Report5())
	{
		DBGS("DLL:dvdIntGetEncDiscKey Check Authentication Success Flag ERROR\n\r");
		return -1; 
	}

	return 0;
}


/*
 * Function         : Get bus encoded title key from specified drive and title
 * Parameters       : drive     (I) drive to get key from
 *                    title     (I) title to get key from
 *                    betk      (O) key to get
 * Function Result  : resulting error condition
 */

extern DLLEXPORT int _stdcall dvdIntGetEncTitleKey( dvdIntDrive drive, Byte betk[5] )
{
	int	iNumTries;

	DBGS("DLL:dvdIntGetEncTitleKey\n\r");
	//***Report4 Get EncTitleKey	
	//***Ignore title number for now, I don't see anywhere in the doccumment 
	//***that it supports multiple titles

 	if (!Report4(betk))
	{
		DBGS("DLL:dvdIntGetEncTitleKey Get title key ERROR\n\r");
      return -1;
	}

	if (!Report5())
	{
		DBGS("DLL:dvdIntGetTitleKey Check Authentication Success Flag ERROR\n\r");
		return -1; 
	}
   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -