📄 wmdrm_receiver.c
字号:
/* * Loop processing messages */ while ( ProximityContext.State != STATE_PROXIMITY_DETECTED ) { /* * Free any buffer from the previous iteration */ cbMessageReceived = 0xFFFFFFFF; // Init expecting read data size cbMessageToSend = 0; pbMessageToSend = NULL; pbMessageReceived = NULL; INIT_FAST_MALLOC(); /* Clear */ /* Reset all operation parameter to send */ ZEROMEM( &OperationParameter[0], (sizeof(DRM_DWORD)*5) ); /* * Build a message to send based on the current state */ switch ( ProximityContext.State ) { /* * Initially, RegistrationRequest Operation. */ case STATE_SEND_REGISTRATION_REQUEST: OperationCode = OPCODE_SENDREGISTRATIONREQUST; // 0x9180 NumParamater = 0; cbMessageReceived = 0; /* Not expect to receive data. */ dr = WmdrmNetGetRegistrationRequestMessage( &pbMessageToSend, &cbMessageToSend ); if ( dr != DRM_SUCCESS ) { goto ErrorExit; } break; /* * Handle RegistrationResponse Operation. */ case STATE_GET_REGISTRATION_RESPONSE: OperationCode = OPCODE_GETREGISTRATIONRESPONSE; //0x9181 OperationParameter[0] = RegistrationTransactionID; NumParamater = 1; /* cbMessageToSend = 0; // No sending data. */ /* cbMessageReceived = 0xFFFFFFFF; // Expect to receive data. */ /* Need Response : Setup pointer to point the area for response message */ pbMessageReceived = (DRM_BYTE **) MALLOC( sizeof(DRM_BYTE) ); ChkMem( pbMessageReceived ); break; /* * Handle ProximityChallenge Operation. */ case STATE_GET_PROXIMITY_CHALLENGE: while (timer_in_progress(FILESYS_TIMER)) { // wait 50msec } OperationCode = OPCODE_GETPROXIMITYCHALLENGE; //0x9182 OperationParameter[0] = RegistrationTransactionID; NumParamater = 1; /* cbMessageToSend = 0; // No sending data. */ cbMessageReceived = 0; /* Not expect to receive data. */ break; /* * Handle ProximityResponse Operation. */ case STATE_SEND_PROXIMITY_RESPONSE: OperationCode = OPCODE_SENDPROXIMITYRESPONSE; //0x9183 OperationParameter[0] = RegistrationTransactionID; NumParamater = 5; /* cbMessageToSend = 0; // No sending data. */ cbMessageReceived = 0; /* Not expect to receive data. */ /* Set Encrypted NonceDWORD to OperationParameter[1] ~ [4] */ MEMCPY( &OperationParameter[1], &EncryptedChallenge, sizeof(DRM_ID) ); for(index = 1; index < 5; index++) { SWAP_DWORD(OperationParameter[index]); // necessary to swap } break; /* * Handle SendWMDRMNDLicenseRequest Operation. */ case STATE_SEND_LICENSE_REQUEST: OperationCode = OPCODE_SENDWMDRMNDLICENSEREQUEST; OperationParameter[0] = ProximityContext.MediaSessionId; NumParamater = 1; cbMessageReceived = 0; /* Not expect to receive data. */ dr = WmdrmNetGetLicenseRequestMessage( &RightsId, &pbMessageToSend, &cbMessageToSend ); if ( dr != DRM_SUCCESS ) { goto ErrorExit; } break; /* * Handle GetWMDRMNDLicenseResponse Operation. */ case STATE_GET_LICENSE_RESPONSE: OperationCode = OPCODE_GETWMDRMNDLICENSERESPONSE; // opcode = 0x9185 OperationParameter[0] = ProximityContext.MediaSessionId; NumParamater = 1; /* cbMessageToSend = 0; // No sending data. */ /* cbMessageReceived = 0xFFFFFFFF; // Expect to receive data. */ /* Need Response : Setup pointer to point the area for response message */ pbMessageReceived = (DRM_BYTE **) MALLOC( sizeof(DRM_BYTE) ); ChkMem( pbMessageReceived ); break; /* * Handle OpenMediaSession Operation. */ case STATE_OPEN_MEDIA_SESSION: OperationCode = OPCODE_OPENMEDIASESSION; // opcode = 0x9170 OperationParameter[0] = ProximityContext.ObjectHandle; OperationParameter[1] = 0; /* "ForceNewSession" parameter */ NumParamater = 2; /* cbMessageToSend = 0; // No sending data. */ cbMessageReceived = 0; /* Not expect to receive data. */ ProximityContext.USBDeviceConfig &= MASK_USBDeviceSessionConfig; break; /* * Handle CloseMediaSession Operation. */ case STATE_CLOSE_MEDIA_SESSION: OperationCode = OPCODE_CLOSEMEDIASESSION; OperationParameter[0] = ProximityContext.MediaSessionId; NumParamater = 1; /* cbMessageToSend = 0; // No sending data. */ cbMessageReceived = 0; /* Not expect to receive data. */ break; #if 0 // No used for the moment. /* * Handle SetCurrentTimeOffset Operation. */ case STATE_SET_CURRENT_TIME_POSITION: OperationCode = OPCODE_SETCURRENTTIMEPOSITION; OperationParameter[0] = ProximityContext.MediaSessionId; OperationParameter[1] = ProximityContext.TimeOffset; NumParamater = 2; /* cbMessageToSend = 0; // No sending data. */ cbMessageReceived = 0; /* Not expect to receive data. */ break;#endif default: dr = DRM_E_FAIL; goto ErrorExit; } /********************************************************************************************************/ /* * Send the message to the transmitter and get a response. */ /********************************************************************************************************/ PREPARE_IOREAD_MTP(FS_XFER_command_event, DEV_USB_ID, OperationCode, OperationParameter[0], NumParamater,\ pbMessageToSend, cbMessageToSend, pbMessageReceived, cbMessageReceived, ResponseCode); dr = IO_Read(IO_READ_IMMEDIATE); if ( ResponseCode != RESPONSECODE_OK ) { /* If error with Proximity Response, not exit by error and Retry !! */ if ( ProximityContext.State != STATE_SEND_PROXIMITY_RESPONSE ) { dr = ResponseCode | 0x80000000; /* Store Error Code. */ } } if ( dr != DRM_SUCCESS ) { goto ErrorExit; } /* * Process the response we got back */ switch ( ProximityContext.State ) { case STATE_SEND_REGISTRATION_REQUEST: /* Store Registration Transaction ID */ RegistrationTransactionID = OperationParameter[0]; ProximityContext.State = STATE_GET_REGISTRATION_RESPONSE; break; case STATE_GET_REGISTRATION_RESPONSE: /* * Process a registration response message */ bMessageType = WmdrmNetGetMessageType( (DRM_BYTE *)*pbMessageReceived, cbMessageReceived ); /* Check Message Type */ if ( bMessageType != WMDRMNET_REGISTRATION_RESPONSE_MESSAGE_TYPE ) { dr = DRM_E_INVALID_MESSAGE; goto ErrorExit; } dr = WmdrmNetProcessRegistrationResponseMessage( (DRM_BYTE *)*pbMessageReceived, cbMessageReceived ); if ( dr != DRM_SUCCESS ) { goto ErrorExit; } ProximityContext.State = STATE_GET_PROXIMITY_CHALLENGE; break; case STATE_GET_PROXIMITY_CHALLENGE: /* * Process a proximity challenge message : Encrypt NonceDWORD. */ for(index = 0; index < 4; index++) { SWAP_DWORD(OperationParameter[index]); // necessary to swap } MEMCPY( &Challenge, &OperationParameter[0], sizeof(DRM_ID) ); OEM_DrmAesOne( ProximityContext.ProximityContentEncryptionKey, (DRM_BYTE *)&EncryptedChallenge, (DRM_BYTE *)&Challenge, DRM_AES_ENCRYPT ); ProximityContext.State = STATE_SEND_PROXIMITY_RESPONSE; break; case STATE_SEND_PROXIMITY_RESPONSE: if(ResponseCode != RESPONSECODE_OK) /* Error to do retry from STATE_GET_PROXIMITY_CHALLENGE */ { start_timer(FILESYS_TIMER, T50ms); ProximityContext.State = STATE_GET_PROXIMITY_CHALLENGE; break; } /* Succeeded proximity challenge */ case STATE_CLOSE_MEDIA_SESSION: ProximityContext.USBDeviceConfig &= MASK_USBDeviceSessionConfig; /* Fall down */#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -