Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
9.7 KiB

  1. /******************************************************************************\
  2. * *
  3. * COPYPROT.C - Copy protection related code. *
  4. * *
  5. * Copyright (c) C-Cube Microsystems 1996 *
  6. * All Rights Reserved. *
  7. * *
  8. * Use of C-Cube Microsystems code is governed by terms and conditions *
  9. * stated in the accompanying licensing statement. *
  10. * *
  11. \******************************************************************************/
  12. #include "Headers.h"
  13. #pragma hdrstop
  14. #include "copyprot.h"
  15. #include "cl6100.h"
  16. /*
  17. ** CopyProtSetPropIfAdapterReady ()
  18. **
  19. ** Set property handling routine for the Copy Protection on any pin
  20. **
  21. ** Arguments:
  22. **
  23. ** pSrb -> property command block
  24. ** pSrb->CommandData.PropertyInfo describes the requested property
  25. **
  26. ** Returns:
  27. **
  28. ** Side Effects:
  29. */
  30. void CopyProtSetPropIfAdapterReady( PHW_STREAM_REQUEST_BLOCK pSrb )
  31. {
  32. PHW_DEVICE_EXTENSION pHwDevExt = pSrb->HwDeviceExtension;
  33. // First check if there any Srb or interrupt pending
  34. if( !AdapterCanAuthenticateNow( pHwDevExt ) )
  35. {
  36. if( pHwDevExt->nTimeoutCount == AUTHENTICATION_TIMEOUT_COUNT )
  37. MonoOutStr( " !!! Schedule CPP CB !!! " );
  38. else
  39. MonoOutStr( "*" );
  40. if( --pHwDevExt->nTimeoutCount > 0 )
  41. {
  42. pSrb->Status = STATUS_PENDING;
  43. StreamClassScheduleTimer( NULL, pHwDevExt,
  44. 10000,
  45. (PHW_TIMER_ROUTINE)CopyProtSetPropIfAdapterReady,
  46. pSrb );
  47. return;
  48. }
  49. }
  50. CopyProtSetProp( pSrb );
  51. }
  52. /*
  53. ** CopyProtSetProp ()
  54. **
  55. ** Set property handling routine for the Copy Protection on any pin
  56. **
  57. ** Arguments:
  58. **
  59. ** pSrb -> property command block
  60. ** pSrb->CommandData.PropertyInfo describes the requested property
  61. **
  62. ** Returns:
  63. **
  64. ** Side Effects:
  65. */
  66. void CopyProtSetProp( PHW_STREAM_REQUEST_BLOCK pSrb )
  67. {
  68. PHW_DEVICE_EXTENSION pHwDevExt = pSrb->HwDeviceExtension;
  69. // static BOOL bSwitchDecryptionOn = FALSE;
  70. // static ZIVA_STATE zInitialState;
  71. WORD wFunction;
  72. BYTE *pData = NULL;
  73. BYTE byDecryptionFlag = 0;
  74. BOOL bWasPending;
  75. bWasPending = (BOOL)(pSrb->Status == STATUS_PENDING);
  76. pSrb->Status = STATUS_SUCCESS;
  77. switch( pSrb->CommandData.PropertyInfo->Property->Id )
  78. {
  79. case KSPROPERTY_DVDCOPY_CHLG_KEY:
  80. // set property for challenge key. This provides the dvd drive
  81. // challenge key for the decoder
  82. pData = (BYTE*)(PKS_DVDCOPY_CHLGKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo);
  83. wFunction = DVD_SEND_CHALLENGE;
  84. break;
  85. case KSPROPERTY_DVDCOPY_DVD_KEY1:
  86. // Set DVD Key1 provides the dvd drive bus key 1 for the decoer
  87. pData = (BYTE*)((PKS_DVDCOPY_BUSKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo))->BusKey;
  88. wFunction = DVD_SEND_RESPONSE;
  89. break;
  90. case KSPROPERTY_DVDCOPY_TITLE_KEY:
  91. // Set DVD title key, provides the dvd drive title key to the decoder
  92. // To make Toshiba CPP chip work copy LSB in the KeyFlags to the MSB...
  93. ((PKS_DVDCOPY_TITLEKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo))->KeyFlags =
  94. ((PKS_DVDCOPY_TITLEKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo))->KeyFlags |
  95. ((PKS_DVDCOPY_TITLEKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo))->KeyFlags << 24;
  96. // And provide it to DVD_Authenticate() function
  97. pData = (BYTE*)(((PKS_DVDCOPY_TITLEKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo))->TitleKey)-1;
  98. wFunction = DVD_SEND_TITLE_KEY;
  99. // The DVD_SECTOR_PROTECTED flag during Title Key exchange is not
  100. // reliable. So just assume that if we are doing Title Key exchange
  101. // we also have to switch decryption on.
  102. // if( ((PKS_DVDCOPY_TITLEKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo))->KeyFlags &
  103. // DVD_SECTOR_PROTECTED )
  104. pHwDevExt->bSwitchDecryptionOn = TRUE;
  105. break;
  106. case KSPROPERTY_DVDCOPY_DISC_KEY:
  107. // Set the DVD disc key. provides the dvd disc key to the decoder
  108. pData = (BYTE*)((PKS_DVDCOPY_DISCKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo))->DiscKey;
  109. wFunction = DVD_SEND_DISK_KEY;
  110. #ifdef EZDVD
  111. // Do nothing
  112. #else
  113. RtlCopyMemory( pHwDevExt->pDiscKeyBufferLinear, pData, DISC_KEY_SIZE );
  114. pData = (BYTE *)pHwDevExt->pDiscKeyBufferPhysical.LowPart;
  115. #endif
  116. break;
  117. case KSPROPERTY_DVDCOPY_SET_COPY_STATE:
  118. switch( ((PKS_DVDCOPY_SET_COPY_STATE)(pSrb->CommandData.PropertyInfo->PropertyInfo))->DVDCopyState )
  119. {
  120. case KS_DVDCOPYSTATE_INITIALIZE:
  121. MonoOutStr( "\n0. Copy Protection Init " );
  122. // Make sure that Decryption will be switched off if
  123. // Title Key exchange does not occur.
  124. pHwDevExt->bSwitchDecryptionOn = FALSE;
  125. // If decoder is not in the Stopped state - stop it but
  126. // remember the initial state.
  127. pHwDevExt->zInitialState = ZivaHw_GetState();
  128. if( pHwDevExt->zInitialState != ZIVA_STATE_STOP)
  129. ZivaHw_Abort() ;
  130. // pSrb->Status = STATUS_IO_DEVICE_ERROR;
  131. break;
  132. case KS_DVDCOPYSTATE_DONE:
  133. MonoOutStr( "\n8. Copy Protection Done " );
  134. if( pHwDevExt->nTimeoutCount < AUTHENTICATION_TIMEOUT_COUNT )
  135. {
  136. MonoOutStr( " (" );
  137. MonoOutInt( pHwDevExt->nTimeoutCount );
  138. MonoOutStr( " timeouts left) " );
  139. pHwDevExt->nTimeoutCount = AUTHENTICATION_TIMEOUT_COUNT;
  140. }
  141. // Make sure next Authentication request will be postponed
  142. // until last packet flag has come on each stream.
  143. AdapterClearAuthenticationStatus( pHwDevExt );
  144. // Switch Decryption on if required.
  145. if( pHwDevExt->bSwitchDecryptionOn )
  146. {
  147. wFunction = DVD_SET_DECRYPTION_MODE;
  148. byDecryptionFlag = 1;
  149. pData = &byDecryptionFlag;
  150. }
  151. // Make sure we will resume play state of the decoder
  152. // when the first chunk of data comes in.
  153. /*sri if( pHwDevExt->zInitialState == ZIVA_STATE_PLAY )
  154. pHwDevExt->bPlayCommandPending = TRUE;
  155. else if(pHwDevExt-> zInitialState == ZIVA_STATE_SCAN )
  156. pHwDevExt->bScanCommandPending = TRUE;
  157. else if( pHwDevExt->zInitialState == ZIVA_STATE_SLOWMOTION )
  158. pHwDevExt->bSlowCommandPending = TRUE;*/
  159. pHwDevExt->bPlayCommandPending = TRUE;
  160. break;
  161. // Indicates we are starting a title key copy protection sequence
  162. case KS_DVDCOPYSTATE_INITIALIZE_TITLE:
  163. MonoOutStr( "\nX. KS_DVDCOPYSTATE_INITIALIZE_TITLE" );
  164. break;
  165. case KS_DVDCOPYSTATE_AUTHENTICATION_NOT_REQUIRED:
  166. MonoOutStr( "\nX. KS_DVDCOPYSTATE_AUTHENTICATION_NOT_REQUIRED" );
  167. break;
  168. case KS_DVDCOPYSTATE_AUTHENTICATION_REQUIRED:
  169. MonoOutStr( "\nX. KS_DVDCOPYSTATE_AUTHENTICATION_REQUIRED" );
  170. break;
  171. default:
  172. MonoOutStr( "\n!!!!!!!!!!!!! Unexpected DVDCopyState !!!!!!!!!!!!!!!! " );
  173. DebugPrint(( DebugLevelVerbose, "ZiVA: !!!!!!!!!!!!! Unexpected DVDCopyState !!!!!!!!!!!!!!!!->0x%x", ((PKS_DVDCOPY_SET_COPY_STATE)(pSrb->CommandData.PropertyInfo->PropertyInfo))->DVDCopyState ));
  174. break;
  175. }
  176. break;
  177. #if 0//DECODER_DVDPC
  178. case KSPROPERTY_COPY_MACROVISION:
  179. {
  180. int nNewApsMode;
  181. nNewApsMode = ((PKS_COPY_MACROVISION)(pSrb->CommandData.PropertyInfo->PropertyInfo))->MACROVISIONLevel;
  182. if(pHwDevExt->nApsMode != nNewApsMode)
  183. {
  184. pHwDevExt->nApsMode = nNewApsMode;
  185. SetAPSMode(pHwDevExt->nApsMode,1);//pHwDevExt->VidSystem);
  186. }
  187. }
  188. return;
  189. #endif
  190. default:
  191. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  192. }
  193. if( pData )
  194. {
  195. if( !DVD_Authenticate( wFunction, pData ) )
  196. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  197. }
  198. if( bWasPending )
  199. { // Release the current control request block to the Stream Class Driver
  200. MonoOutStr( " !!! Releasing Scheduled CPP Srb !!! " );
  201. AdapterReleaseRequest( pSrb );
  202. }
  203. }
  204. /*
  205. ** CopyProtGetProp ()
  206. **
  207. ** get property handling routine for the CopyProt encoder pin
  208. **
  209. ** Arguments:
  210. **
  211. ** pSrb -> property command block
  212. ** pSrb->CommandData.PropertyInfo describes the requested property
  213. **
  214. ** Returns:
  215. **
  216. ** Side Effects:
  217. */
  218. void CopyProtGetProp( PHW_STREAM_REQUEST_BLOCK pSrb )
  219. {
  220. PHW_DEVICE_EXTENSION pHwDevExt = pSrb->HwDeviceExtension;
  221. WORD wFunction;
  222. BYTE *pData = NULL;
  223. pSrb->Status = STATUS_SUCCESS;
  224. switch( pSrb->CommandData.PropertyInfo->Property->Id )
  225. {
  226. case KSPROPERTY_DVDCOPY_CHLG_KEY:
  227. // get property for challenge key. This provides the dvd drive
  228. // with the challenge key FROM the decoder
  229. pData = (BYTE*)(PKS_DVDCOPY_CHLGKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo);
  230. wFunction = DVD_GET_CHALLENGE;
  231. pSrb->ActualBytesTransferred = sizeof( KS_DVDCOPY_CHLGKEY );
  232. break;
  233. case KSPROPERTY_DVDCOPY_DEC_KEY2:
  234. //
  235. // get DVD Key2 provides the dvd drive with bus key 2 from the decoder
  236. //
  237. pData = (BYTE*)(PKS_DVDCOPY_BUSKEY)(pSrb->CommandData.PropertyInfo->PropertyInfo);
  238. wFunction = DVD_GET_RESPONSE;
  239. pSrb->ActualBytesTransferred = sizeof( KS_DVDCOPY_BUSKEY );
  240. break;
  241. /* case KSPROPERTY_DVDCOPY_REGION:
  242. // indicate region 1 for US content
  243. ((PKS_DVDCOPY_REGION)(pSrb->CommandData.PropertyInfo->PropertyInfo))->RegionData = 0x1;
  244. pSrb->ActualBytesTransferred = sizeof( KS_DVDCOPY_REGION );
  245. break; sri*/
  246. case KSPROPERTY_DVDCOPY_SET_COPY_STATE:
  247. if( pHwDevExt->iStreamToAuthenticateOn == -1 ||
  248. pHwDevExt->iStreamToAuthenticateOn == (int)pSrb->StreamObject->StreamNumber )
  249. {
  250. pHwDevExt->iStreamToAuthenticateOn = pSrb->StreamObject->StreamNumber;
  251. ((PKS_DVDCOPY_SET_COPY_STATE)(pSrb->CommandData.PropertyInfo->PropertyInfo))->DVDCopyState
  252. = KS_DVDCOPYSTATE_AUTHENTICATION_REQUIRED;
  253. }
  254. else
  255. ((PKS_DVDCOPY_SET_COPY_STATE)(pSrb->CommandData.PropertyInfo->PropertyInfo))->DVDCopyState
  256. = KS_DVDCOPYSTATE_AUTHENTICATION_NOT_REQUIRED;
  257. pSrb->ActualBytesTransferred = sizeof( KS_DVDCOPY_SET_COPY_STATE );
  258. break;
  259. default:
  260. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  261. }
  262. if( pData )
  263. {
  264. if( !DVD_Authenticate( wFunction, pData ) )
  265. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  266. }
  267. }