XilinxProcessorIPLib/drivers/hdcp22_rx_dp/src/xhdcp22_rx.c
static void *XHdcp22Rx_StateB1(XHdcp22_Rx *InstancePtr)
{
	/* Verify arguments */
	Xil_AssertNonvoid(InstancePtr != NULL);

	int Status;
	XHdcp22_Rx_Message *MsgPtr = (XHdcp22_Rx_Message*)InstancePtr->MessageBuffer;

	/* Update state */
	InstancePtr->Info.AuthenticationStatus = XHDCP22_RX_AUTHENTICATION_BUSY;
	InstancePtr->Info.CurrentState = InstancePtr->Info.NextState;

	/* Check error condition */
	if(InstancePtr->Info.ErrorFlag & XHDCP22_RX_ERROR_FLAG_DDC_BURST)
	{
		XHdcp22Rx_ResetDdc(InstancePtr, FALSE, TRUE, TRUE, TRUE);
		XHdcp22Rx_ResetAfterError(InstancePtr);
		return (void *)XHdcp22Rx_StateB0;
	}

	/* Check if message is available */
	InstancePtr->MessageSize = XHdcp22Rx_PollMessage(InstancePtr);

	/* Message handling */
	if(InstancePtr->MessageSize > 0)
	{
		switch(MsgPtr->MsgId)
		{
		case XHDCP22_RX_MSG_ID_AKEINIT:
			Status = XHdcp22Rx_ProcessMessageAKEInit(InstancePtr);
			if(Status == XST_SUCCESS)
			{
			    InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDCERT;
			    break;
			}
			XHdcp22Rx_LogWr(InstancePtr, XHDCP22_RX_LOG_EVT_ERROR, XHDCP22_RX_ERROR_FLAG_PROCESSING_AKEINIT);
			XHdcp22Rx_ResetAfterError(InstancePtr);
			return (void *)XHdcp22Rx_StateB0;
		case XHDCP22_RX_MSG_ID_AKENOSTOREDKM:
			if(InstancePtr->Info.CurrentState == XHDCP22_RX_STATE_B1_WAIT_AKEKM)
			{
				Status = XHdcp22Rx_ProcessMessageAKENoStoredKm(InstancePtr);
				if(Status == XST_SUCCESS)
				{
					InstancePtr->Info.IsNoStoredKm = TRUE;
					InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDHPRIME;
					break;
				}
			}
			XHdcp22Rx_LogWr(InstancePtr, XHDCP22_RX_LOG_EVT_ERROR, XHDCP22_RX_ERROR_FLAG_PROCESSING_AKENOSTOREDKM);
			XHdcp22Rx_ResetAfterError(InstancePtr);
			return (void *)XHdcp22Rx_StateB0;
		case XHDCP22_RX_MSG_ID_AKESTOREDKM:
			if(InstancePtr->Info.CurrentState == XHDCP22_RX_STATE_B1_WAIT_AKEKM)
			{
				Status = XHdcp22Rx_ProcessMessageAKEStoredKm(InstancePtr);
				if(Status == XST_SUCCESS)
				{
					InstancePtr->Info.IsNoStoredKm = FALSE;
					InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDHPRIME;
					break;
				}
			}
			XHdcp22Rx_LogWr(InstancePtr, XHDCP22_RX_LOG_EVT_ERROR, XHDCP22_RX_ERROR_FLAG_PROCESSING_AKESTOREDKM);
			XHdcp22Rx_ResetAfterError(InstancePtr);
			return (void *)XHdcp22Rx_StateB0;
		default:
			XHdcp22Rx_ResetAfterError(InstancePtr);
			return (void *)XHdcp22Rx_StateB0;
		}
	}

	/* Message send */
	switch(InstancePtr->Info.NextState)
	{
	case XHDCP22_RX_STATE_B1_SEND_AKESENDCERT:
		if(XHdcp22Rx_IsReadMessageComplete(InstancePtr) == TRUE)
		{
			Status = XHdcp22Rx_SendMessageAKESendCert(InstancePtr);
			InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_WAIT_AKEKM;
		}
		break;
	case XHDCP22_RX_STATE_B1_SEND_AKESENDHPRIME:
		if(XHdcp22Rx_IsReadMessageComplete(InstancePtr) == TRUE)
		{
			Status = XHdcp22Rx_SendMessageAKESendHPrime(InstancePtr);
			if(InstancePtr->Info.IsNoStoredKm)
			{
				InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDPAIRINGINFO;
			}
			else
			{
				InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_WAIT_LCINIT;
				return (void *)XHdcp22Rx_StateB2; /* Transition B1->B2 */
			}
		}
		break;
	case XHDCP22_RX_STATE_B1_SEND_AKESENDPAIRINGINFO:
		if(XHdcp22Rx_IsReadMessageComplete(InstancePtr) == TRUE)
		{
			Status = XHdcp22Rx_SendMessageAKESendPairingInfo(InstancePtr);
			InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_WAIT_LCINIT;
			return (void *)XHdcp22Rx_StateB2;
		}
		break;
	default:
		break;
	}

	return (void *)XHdcp22Rx_StateB1;
}
/*****************************************************************************/
/**
* This function implements the Receiver State B1 (ComputeKm). In this
* state the receiver makes the AKESendCert message available for reading
* by the transmitter in response to AKEInit. If AKENoStoredKm is received,
* the receiver decrypts Km with KprivRx and calculates HPrime. If AKEStoredKm
* is received it decrypts Ekh(Km) to derive Km and calculate HPrime. It makes
* AKESendHPrime message available for reading immediately after computation
* of HPrime to ensure that the message is received by the transmitter within
* the specified 1s timeout at the transmitter for NoStoredKm and 200ms timeout
* for StoredKm. When AKENoStoredKm is received the AKESendPairingInfo message
* is made available to the transmitter for reading after within 200ms after
* AKESendHPrime message is received by the transmitter.
*
* @param    InstancePtr is a pointer to the XHdcp22_Rx core instance.
*
* @return   Pointer to the function that implements the next state.
*
* @note     When an unexpected or malformed message is received the
*           system is reset to the default state B0 to allow graceful
*           recovery from error.
******************************************************************************/
This function implements the Receiver State B1 (ComputeKm). In this
state the receiver makes the AKESendCert message available for reading
by the transmitter in response to AKEInit. If AKENoStoredKm is received,
the receiver decrypts Km with KprivRx and calculates HPrime. If AKEStoredKm
is received it decrypts Ekh(Km) to derive Km and calculate HPrime. It makes
AKESendHPrime message available for reading immediately after computation
of HPrime to ensure that the message is received by the transmitter within
the specified 1s timeout at the transmitter for NoStoredKm and 200ms timeout
for StoredKm. When AKENoStoredKm is received the AKESendPairingInfo message
is made available to the transmitter for reading after within 200ms after
AKESendHPrime message is received by the transmitter.
This function implements the Receiver State B1 ( ComputeKm ) . In this state the receiver makes the AKESendCert message available for reading by the transmitter in response to AKEInit . If AKENoStoredKm is received the receiver decrypts Km with KprivRx and calculates HPrime . If AKEStoredKm is received it decrypts Ekh ( Km ) to derive Km and calculate HPrime . It makes AKESendHPrime message available for reading immediately after computation of HPrime to ensure that the message is received by the transmitter within the specified 1s timeout at the transmitter for NoStoredKm and 200ms timeout for StoredKm . When AKENoStoredKm is received the AKESendPairingInfo message is made available to the transmitter for reading after within 200ms after AKESendHPrime message is received by the transmitter .
static void *XHdcp22Rx_StateB1(XHdcp22_Rx *InstancePtr)
{
	Xil_AssertNonvoid(InstancePtr != NULL);
	int Status;
	XHdcp22_Rx_Message *MsgPtr = (XHdcp22_Rx_Message*)InstancePtr->MessageBuffer;
	InstancePtr->Info.AuthenticationStatus = XHDCP22_RX_AUTHENTICATION_BUSY;
	InstancePtr->Info.CurrentState = InstancePtr->Info.NextState;
	if(InstancePtr->Info.ErrorFlag & XHDCP22_RX_ERROR_FLAG_DDC_BURST)
	{
		XHdcp22Rx_ResetDdc(InstancePtr, FALSE, TRUE, TRUE, TRUE);
		XHdcp22Rx_ResetAfterError(InstancePtr);
		return (void *)XHdcp22Rx_StateB0;
	}
	InstancePtr->MessageSize = XHdcp22Rx_PollMessage(InstancePtr);
	if(InstancePtr->MessageSize > 0)
	{
		switch(MsgPtr->MsgId)
		{
		case XHDCP22_RX_MSG_ID_AKEINIT:
			Status = XHdcp22Rx_ProcessMessageAKEInit(InstancePtr);
			if(Status == XST_SUCCESS)
			{
			    InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDCERT;
			    break;
			}
			XHdcp22Rx_LogWr(InstancePtr, XHDCP22_RX_LOG_EVT_ERROR, XHDCP22_RX_ERROR_FLAG_PROCESSING_AKEINIT);
			XHdcp22Rx_ResetAfterError(InstancePtr);
			return (void *)XHdcp22Rx_StateB0;
		case XHDCP22_RX_MSG_ID_AKENOSTOREDKM:
			if(InstancePtr->Info.CurrentState == XHDCP22_RX_STATE_B1_WAIT_AKEKM)
			{
				Status = XHdcp22Rx_ProcessMessageAKENoStoredKm(InstancePtr);
				if(Status == XST_SUCCESS)
				{
					InstancePtr->Info.IsNoStoredKm = TRUE;
					InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDHPRIME;
					break;
				}
			}
			XHdcp22Rx_LogWr(InstancePtr, XHDCP22_RX_LOG_EVT_ERROR, XHDCP22_RX_ERROR_FLAG_PROCESSING_AKENOSTOREDKM);
			XHdcp22Rx_ResetAfterError(InstancePtr);
			return (void *)XHdcp22Rx_StateB0;
		case XHDCP22_RX_MSG_ID_AKESTOREDKM:
			if(InstancePtr->Info.CurrentState == XHDCP22_RX_STATE_B1_WAIT_AKEKM)
			{
				Status = XHdcp22Rx_ProcessMessageAKEStoredKm(InstancePtr);
				if(Status == XST_SUCCESS)
				{
					InstancePtr->Info.IsNoStoredKm = FALSE;
					InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDHPRIME;
					break;
				}
			}
			XHdcp22Rx_LogWr(InstancePtr, XHDCP22_RX_LOG_EVT_ERROR, XHDCP22_RX_ERROR_FLAG_PROCESSING_AKESTOREDKM);
			XHdcp22Rx_ResetAfterError(InstancePtr);
			return (void *)XHdcp22Rx_StateB0;
		default:
			XHdcp22Rx_ResetAfterError(InstancePtr);
			return (void *)XHdcp22Rx_StateB0;
		}
	}
	switch(InstancePtr->Info.NextState)
	{
	case XHDCP22_RX_STATE_B1_SEND_AKESENDCERT:
		if(XHdcp22Rx_IsReadMessageComplete(InstancePtr) == TRUE)
		{
			Status = XHdcp22Rx_SendMessageAKESendCert(InstancePtr);
			InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_WAIT_AKEKM;
		}
		break;
	case XHDCP22_RX_STATE_B1_SEND_AKESENDHPRIME:
		if(XHdcp22Rx_IsReadMessageComplete(InstancePtr) == TRUE)
		{
			Status = XHdcp22Rx_SendMessageAKESendHPrime(InstancePtr);
			if(InstancePtr->Info.IsNoStoredKm)
			{
				InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDPAIRINGINFO;
			}
			else
			{
				InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_WAIT_LCINIT;
				return (void *)XHdcp22Rx_StateB2; 
			}
		}
		break;
	case XHDCP22_RX_STATE_B1_SEND_AKESENDPAIRINGINFO:
		if(XHdcp22Rx_IsReadMessageComplete(InstancePtr) == TRUE)
		{
			Status = XHdcp22Rx_SendMessageAKESendPairingInfo(InstancePtr);
			InstancePtr->Info.NextState = XHDCP22_RX_STATE_B1_WAIT_LCINIT;
			return (void *)XHdcp22Rx_StateB2;
		}
		break;
	default:
		break;
	}
	return (void *)XHdcp22Rx_StateB1;
}
static void * XHdcp22Rx_StateB1 ( XHdcp22_Rx * InstancePtr ) { Xil_AssertNonvoid ( InstancePtr != NULL ) ; int Status ; XHdcp22_Rx_Message * MsgPtr = ( XHdcp22_Rx_Message * ) InstancePtr -> MessageBuffer ; InstancePtr -> Info . AuthenticationStatus = XHDCP22_RX_AUTHENTICATION_BUSY ; InstancePtr -> Info . CurrentState = InstancePtr -> Info . NextState ; if ( InstancePtr -> Info . ErrorFlag & XHDCP22_RX_ERROR_FLAG_DDC_BURST ) { XHdcp22Rx_ResetDdc ( InstancePtr , FALSE , TRUE , TRUE , TRUE ) ; XHdcp22Rx_ResetAfterError ( InstancePtr ) ; return ( void * ) XHdcp22Rx_StateB0 ; } InstancePtr -> MessageSize = XHdcp22Rx_PollMessage ( InstancePtr ) ; if ( InstancePtr -> MessageSize > 0 ) { switch ( MsgPtr -> MsgId ) { case XHDCP22_RX_MSG_ID_AKEINIT : Status = XHdcp22Rx_ProcessMessageAKEInit ( InstancePtr ) ; if ( Status == XST_SUCCESS ) { InstancePtr -> Info . NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDCERT ; break ; } XHdcp22Rx_LogWr ( InstancePtr , XHDCP22_RX_LOG_EVT_ERROR , XHDCP22_RX_ERROR_FLAG_PROCESSING_AKEINIT ) ; XHdcp22Rx_ResetAfterError ( InstancePtr ) ; return ( void * ) XHdcp22Rx_StateB0 ; case XHDCP22_RX_MSG_ID_AKENOSTOREDKM : if ( InstancePtr -> Info . CurrentState == XHDCP22_RX_STATE_B1_WAIT_AKEKM ) { Status = XHdcp22Rx_ProcessMessageAKENoStoredKm ( InstancePtr ) ; if ( Status == XST_SUCCESS ) { InstancePtr -> Info . IsNoStoredKm = TRUE ; InstancePtr -> Info . NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDHPRIME ; break ; } } XHdcp22Rx_LogWr ( InstancePtr , XHDCP22_RX_LOG_EVT_ERROR , XHDCP22_RX_ERROR_FLAG_PROCESSING_AKENOSTOREDKM ) ; XHdcp22Rx_ResetAfterError ( InstancePtr ) ; return ( void * ) XHdcp22Rx_StateB0 ; case XHDCP22_RX_MSG_ID_AKESTOREDKM : if ( InstancePtr -> Info . CurrentState == XHDCP22_RX_STATE_B1_WAIT_AKEKM ) { Status = XHdcp22Rx_ProcessMessageAKEStoredKm ( InstancePtr ) ; if ( Status == XST_SUCCESS ) { InstancePtr -> Info . IsNoStoredKm = FALSE ; InstancePtr -> Info . NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDHPRIME ; break ; } } XHdcp22Rx_LogWr ( InstancePtr , XHDCP22_RX_LOG_EVT_ERROR , XHDCP22_RX_ERROR_FLAG_PROCESSING_AKESTOREDKM ) ; XHdcp22Rx_ResetAfterError ( InstancePtr ) ; return ( void * ) XHdcp22Rx_StateB0 ; default : XHdcp22Rx_ResetAfterError ( InstancePtr ) ; return ( void * ) XHdcp22Rx_StateB0 ; } } switch ( InstancePtr -> Info . NextState ) { case XHDCP22_RX_STATE_B1_SEND_AKESENDCERT : if ( XHdcp22Rx_IsReadMessageComplete ( InstancePtr ) == TRUE ) { Status = XHdcp22Rx_SendMessageAKESendCert ( InstancePtr ) ; InstancePtr -> Info . NextState = XHDCP22_RX_STATE_B1_WAIT_AKEKM ; } break ; case XHDCP22_RX_STATE_B1_SEND_AKESENDHPRIME : if ( XHdcp22Rx_IsReadMessageComplete ( InstancePtr ) == TRUE ) { Status = XHdcp22Rx_SendMessageAKESendHPrime ( InstancePtr ) ; if ( InstancePtr -> Info . IsNoStoredKm ) { InstancePtr -> Info . NextState = XHDCP22_RX_STATE_B1_SEND_AKESENDPAIRINGINFO ; } else { InstancePtr -> Info . NextState = XHDCP22_RX_STATE_B1_WAIT_LCINIT ; return ( void * ) XHdcp22Rx_StateB2 ; } } break ; case XHDCP22_RX_STATE_B1_SEND_AKESENDPAIRINGINFO : if ( XHdcp22Rx_IsReadMessageComplete ( InstancePtr ) == TRUE ) { Status = XHdcp22Rx_SendMessageAKESendPairingInfo ( InstancePtr ) ; InstancePtr -> Info . NextState = XHDCP22_RX_STATE_B1_WAIT_LCINIT ; return ( void * ) XHdcp22Rx_StateB2 ; } break ; default : break ; } return ( void * ) XHdcp22Rx_StateB1 ; }
This function implements the Receiver State B1 (ComputeKm).
This function implements the Receiver State B1 ( ComputeKm ) .
/* Verify arguments */ /* Update state */ /* Check error condition */ /* Check if message is available */ /* Message handling */ /* Message send */ /* Transition B1->B2 */