int RealTimeNonceTimer(void *aParameter)
{
    int returnValue = SUCCESS;
    DtcpAkeCoreData *coreData;

    if (!aParameter)
    {
        returnValue = INVALID_ARGUMENT;
    }

    if (IS_SUCCESS(returnValue))
    {
        coreData = (DtcpAkeCoreData *)aParameter;

        // Create initial nonce value
        OsWrap_SemaphoreWait(coreData->DataSemaphore);

        Rng_GetRandomNumber(coreData->RealTimeNonce, DTCP_CONTENT_KEY_NONCE_SIZE);

        OsWrap_SemaphorePost(coreData->DataSemaphore);

        while (1)
        {
            // Sleep for timer period
            OsWrap_Sleep(DTCP_RTP_NONCE_TIMER_PERIOD * 1000);

            if (0 < coreData->UpdateRealTimeNonceStreamCount)
            {
                // Increment nonce
                OsWrap_SemaphoreWait(coreData->DataSemaphore);
                IncrementNonce(coreData->RealTimeNonce);
                OsWrap_SemaphorePost(coreData->DataSemaphore);

            }
        }
    }


    return returnValue;
}
Ejemplo n.º 2
0
int DtcpAkeCore_OpenAkeSession(EnAkeTypeId               aAkeTypeId,
                               EnDeviceMode              aDeviceMode,
                               DtcpAkeCoreSessionHandle *aAkeCoreSessionHandle)
{
    int returnValue = SUCCESS;
    DtcpAkeCoreSessionData *sessionData;

    if (aAkeCoreSessionHandle)
    {
        OsWrap_SemaphoreWait(gAkeCoreData.DataSemaphore);

        returnValue = OsWrap_AddToList(&gAkeCoreData.AkeSessions, 
                                       &sessionData,
                                       sizeof(DtcpAkeCoreSessionData));

        OsWrap_SemaphorePost(gAkeCoreData.DataSemaphore);

        if (IS_SUCCESS(returnValue) && NULL != sessionData)
        {
            memset(sessionData, 0, sizeof(DtcpAkeCoreSessionData));
            sessionData->AkeCoreData = &gAkeCoreData;
            sessionData->AkeTypeId = aAkeTypeId;
            sessionData->DeviceMode = aDeviceMode;
            sessionData->TheirSrmV = 0;
            sessionData->TheirSrmG = 0;
            sessionData->TheirSrmC = 0;
            *aAkeCoreSessionHandle = sessionData;
        }
    }
    else
    {
        returnValue = INVALID_ARGUMENT;
    }

    return returnValue;
} // DtcpAkeCore_OpenAkeSession
Ejemplo n.º 3
0
static int do_spi_io(struct spi_device* lp_dev, u8* lp_send_buffer, u8* lp_recv_buffer, 
                     int buffer_size)
{
    int ret_value;
	struct spi_message msg;
    struct spi_transfer xfer = 
        {
            .len = buffer_size, 
            .tx_buf = (void*)lp_send_buffer,
            .rx_buf = (void*)lp_recv_buffer,
            .speed_hz = 1000000,
        };

    spi_message_init(&msg);
    spi_message_add_tail(&xfer, &msg);

    dev_info(&lp_dev->dev, "spi io: transfer size = %d\n", buffer_size);
    
    ret_value = spi_sync(lp_dev, &msg);

    if (IS_SUCCESS(ret_value))
    {
        dev_info(&lp_dev->dev, "spi io done.\n");
    }
    
    dev_info(&lp_dev->dev, "do_spi_io ret_value = %d\n", ret_value);

    return ret_value;
}


int do_io_transaction(struct spi_device* lp_dev, 
                      _IN_ struct spi_io_context* lp_io_context,
                      _IN_ u8* const lp_send_buffer, int send_buffer_size,
                      _OUT_ u8* lp_recv_buffer, int recv_buffer_size, 
                      _OUT_ int* lp_recved_size )
{
    int ret_value = ER_FAILED;

    int total_trafster = 0;
    int one_time_transfer = 0;
    int total_receive_size = 0;

    int remain_send_count = send_buffer_size;
    int remain_recv_count = 0;

    int is_recved_vaild_fh = 0;

    struct buffer* lp_send_operator = NULL;
    struct buffer* lp_recv_operator = NULL;

    struct buffer dummy_send_buffer;
    struct buffer dummy_recv_buffer;

    struct buffer send_buffer;
    struct buffer recv_buffer;

    INIT_BUFFER(&dummy_send_buffer,
                lp_io_context->send_dummy_buffer,
                lp_io_context->send_dummy_buffer_size);
    
    INIT_BUFFER(&dummy_recv_buffer,
                lp_io_context->recv_dummy_buffer,
                lp_io_context->recv_dummy_buffer_size);
    
    INIT_BUFFER(&send_buffer, lp_send_buffer, send_buffer_size);

    INIT_BUFFER(&recv_buffer, lp_recv_buffer, recv_buffer_size);

    /*need some check here, but still in think.*/

    total_trafster = send_buffer_size;
    while(total_trafster > 0)
    {
        int send_buffer_is_dummy;
        int recv_buffer_is_dummy;

        /*
          Step1. try calc out transfer bye count
        */
        if (0 != BUFFER_REMAIN_LENGTH(send_buffer))
        {
            lp_send_operator = &send_buffer;
            send_buffer_is_dummy = FALSE;
        }
        else
        {
            lp_send_operator = &dummy_send_buffer;
            send_buffer_is_dummy = TRUE;
        }

        if (0 != remain_recv_count 
            && is_recved_vaild_fh)
        {
            lp_recv_operator = &recv_buffer;
            recv_buffer_is_dummy = FALSE;
        }
        else
        {
            lp_recv_operator = &dummy_recv_buffer;
            recv_buffer_is_dummy = TRUE;
        }

        if (is_recved_vaild_fh)
        {
            RESET_BUFFER(&dummy_send_buffer);
            RESET_BUFFER(&dummy_recv_buffer);

            if (send_buffer_is_dummy && recv_buffer_is_dummy)
            {
                one_time_transfer = 0;
            }
            else
            {
                one_time_transfer = MIN(BUFFER_REMAIN_LENGTH(*lp_send_operator),
                                        BUFFER_REMAIN_LENGTH(*lp_recv_operator));
            }
        }
        else
        {
            /*
              can't reset dummy recv buffer because it contain last time received
              splited data
             */
            one_time_transfer = MIN(BUFFER_REMAIN_LENGTH(*lp_send_operator), 
                                    BUFFER_REMAIN_LENGTH(dummy_recv_buffer));                      
        }

        if (0 == one_time_transfer)
        {
            /*caller's receive buffer is not enough case.*/
            if ( 0 != remain_recv_count)
            {
                ret_value = ER_NO_ENOUGH_RECV_BUFFER;
            }

            break;
        }

        /*
          Step 2. Prepare and do transfer
         */
        dev_info(&lp_dev->dev, "before do_spi_io\n");
        ret_value = do_spi_io(lp_dev,
                              BUFFER_PTR(*lp_send_operator), 
                              BUFFER_PTR(*lp_recv_operator),
                              one_time_transfer);
        if (IS_FAILED(ret_value))
        {
            dev_err(&lp_dev->dev, "do_spi_io() failed! \n");
            break;
        }
        dev_info(&lp_dev->dev, "after do_spi_io\n");

        lp_send_operator->index += one_time_transfer;
        lp_recv_operator->index += one_time_transfer;

        remain_send_count = MAX(0, remain_send_count - one_time_transfer);
        remain_recv_count = MAX(0, remain_recv_count - one_time_transfer);
        total_trafster -= one_time_transfer;

        /*
          Step 3. check if we received valid frame header
         */
        if (!is_recved_vaild_fh)
        {
            int total_payload_size;
            int contained_payload_size;
            int fh_start_index;
            int is_valid_fh;
            
            is_valid_fh = verify_frame_head_and_get_payload_size(lp_recv_operator->lp_ptr, 
                                                                 BUFFER_USED_LENGTH(*lp_recv_operator),
                                                                 &total_payload_size,
                                                                 &contained_payload_size,
                                                                 &fh_start_index);
            if (IS_SUCCESS(is_valid_fh))
            {
                int copy_size = contained_payload_size + SIZE_OF_FRAME_HEAD;
                int need_recv_buffer_size = total_payload_size + SIZE_OF_FRAME_HEAD;

                /*received new frame head!*/
                remain_recv_count = total_payload_size - contained_payload_size;
                
                /*received frame head, so we update total transfer count here*/
                total_trafster = MAX(remain_recv_count, remain_send_count);

                /*
                printf("[packege check]: total payload = %d, contained = %d, fh_start = %d\n",
                       total_payload_size,
                       contained_payload_size,
                       fh_start_index);
                */

                /*copy all valid data to actual receive buffer head*/

                if (need_recv_buffer_size > BUFFER_REMAIN_LENGTH(recv_buffer))
                {
                    ret_value = ER_NO_ENOUGH_RECV_BUFFER;
                    break;
                }
                
                /*do not reset buffer, because we now support
                  received mulit-frame in one io cycle.
                 */
                //RESET_BUFFER(&recv_buffer);                

                memcpy(BUFFER_PTR(recv_buffer), 
                       lp_recv_operator->lp_ptr + fh_start_index,
                       copy_size);

                /*
                  save total received size here to support receive mulit-frame
                 */
                total_receive_size += need_recv_buffer_size;
                
                recv_buffer.index += copy_size;
                recv_buffer.length = total_receive_size;

                //                pr_err("dump: index = %d, length = %d\n",
                //       recv_buffer.index, recv_buffer.length);

                is_recved_vaild_fh = TRUE;
            }
            else
            {
                int is_recved_hf_prefix = ER_FAILED;

                remain_recv_count = 0;

                //copy SIZEOF_FRAME_HEAD bytes from tail to head
                memcpy(dummy_recv_buffer.lp_ptr,
                       BUFFER_PTR_FROM_USED_TAIL(*lp_recv_operator, SIZE_OF_FRAME_HEAD),
                       SIZE_OF_FRAME_HEAD);

                dummy_recv_buffer.index = SIZE_OF_FRAME_HEAD;

                /*check if the last SIZE_OF_FRAME_HEAD bytes contained frame head prefix,
                  we will read more data if it contained, to resovle slice case
                 */
                is_recved_hf_prefix = verify_frame_head_prefix(BUFFER_PTR_FROM_USED_TAIL(*lp_recv_operator, SIZE_OF_FRAME_HEAD),
                                                               SIZE_OF_FRAME_HEAD);
                /*
                  check if the received data included frame head prefix 0x53
                 */
                if (IS_SUCCESS(is_recved_hf_prefix))
                {
                    total_trafster += BUFFER_REMAIN_LENGTH(dummy_recv_buffer);
                    /*
                    printf("set total_transfer = %d\n", total_trafster);
                    */
                }
                
                is_recved_vaild_fh = FALSE;
            }
        }
        else
        {
            /*
              if we already received one frame, but still has some data need
              send, we need change is_recved_vaild_fh = FALSE to prepare receive
              the next frame
             */
#if 1
            if (remain_send_count > 0
                && 0 == remain_recv_count)
            {
                is_recved_vaild_fh = FALSE;
                RESET_BUFFER(&dummy_recv_buffer);
                //pr_err("psh: note: try receive mulit-frame.\n");
            }
#endif

        }
    }

#if 1   
    if (IS_FAILED(ret_value))
    {
        /*
          dump recvied buffer
         */
        
        dump_buffer(lp_recv_operator->lp_ptr, BUFFER_USED_LENGTH(*lp_recv_operator));
    }
    else
    {
        //dump_buffer(recv_buffer.lp_ptr, BUFFER_USED_LENGTH(recv_buffer));
    }
#endif


    lp_recved_size ? *lp_recved_size = BUFFER_USED_LENGTH(recv_buffer) : 0;

    return ret_value;

}
Ejemplo n.º 4
0
/* FIXME: it will be a platform device */
static int psh_probe(struct spi_device *client)
{
	int ret = -EPERM;
	struct psh_ia_priv *ia_data;
	struct psh_ext_if *psh_if_info;
	int rc;
	
	dev_err(&client->dev, "%s\n", __func__);

	psh_if_info = kzalloc(sizeof(*psh_if_info), GFP_KERNEL);
	if (!psh_if_info) {
		dev_err(&client->dev, "can not allocate psh_if_info\n");
		goto psh_if_err;
	}

	ret = psh_ia_common_init(&client->dev, &psh_if_info->ia_data);
	if (ret) {
		dev_err(&client->dev, "fail to init psh_ia_common\n");
		goto psh_ia_err;
	}

    ia_data = psh_if_info->ia_data;

    /*
      initialize send list
     */
    mutex_init(&psh_if_info->send_data_list.lock);
    mutex_init(&psh_if_info->workitem_mutex);
    INIT_LIST_HEAD(&psh_if_info->send_data_list.head);
    
    psh_if_info->task_flag = TASK_FLAG_CLEAR;
    dev_err(&client->dev, "send list inited\n");

	psh_if_info->hwmon_dev = hwmon_device_register(&client->dev);
	if (!psh_if_info->hwmon_dev) {
		dev_err(&client->dev, "fail to register hwmon device\n");
		goto hwmon_err;
	}

	psh_if_info->pshc = client;

	ia_data->platform_priv = psh_if_info;

#if 0
	psh_if_info->gpio_psh_ctl =
				acpi_get_gpio_by_index(&client->dev, 1, NULL);
#endif

	psh_if_info->gpio_psh_ctl = -1;

	if (psh_if_info->gpio_psh_ctl < 0) {
		dev_warn(&client->dev, "fail to get psh_ctl pin by ACPI\n");
	} else {
		rc = gpio_request(psh_if_info->gpio_psh_ctl, "psh_ctl");
		if (rc) {
			dev_warn(&client->dev, "fail to request psh_ctl pin\n");
			psh_if_info->gpio_psh_ctl = -1;
		} else {
			gpio_export(psh_if_info->gpio_psh_ctl, 1);
			gpio_direction_output(psh_if_info->gpio_psh_ctl, 1);
			gpio_set_value(psh_if_info->gpio_psh_ctl, 1);
		}
	}
#if 0
	psh_if_info->gpio_psh_rst =
				acpi_get_gpio_by_index(&client->dev, 0, NULL);
#endif 

	psh_if_info->gpio_psh_rst = GPIO_PSH_MCU_RESET;

	if (psh_if_info->gpio_psh_rst < 0) {
		dev_warn(&client->dev, "failed to get psh_rst pin by ACPI\n");
	} else {
		rc = gpio_request(psh_if_info->gpio_psh_rst, "psh_rst");
		if (rc) {
			dev_warn(&client->dev, "fail to request psh_rst pin\n");
			psh_if_info->gpio_psh_rst = -1;
		} else {
			gpio_export(psh_if_info->gpio_psh_rst, 1);
			gpio_direction_output(psh_if_info->gpio_psh_rst, 1);
			gpio_set_value(psh_if_info->gpio_psh_rst, 1);
		}
	}
	// TODO update gpio_psh_int from platform_data 
	//psh_if_info->gpio_psh_int = (int)id->driver_data;
	
	client->irq = gpio_to_irq(GPIO_PSH_INT);  // force polling mode
#ifdef DRV_POLLING_MODE
	client->irq = -1;
#endif
 
	if(client->irq > 0){

	    psh_if_info->gpio_psh_int = GPIO_PSH_INT; 
	
	    rc = gpio_request(psh_if_info->gpio_psh_int, "psh_int");
	    if (rc) {
		    dev_warn(&client->dev, "fail to request psh_int pin\n");
		    psh_if_info->gpio_psh_int = -1;
	    } else {
		    gpio_export(psh_if_info->gpio_psh_int, 1);
	    }

	    /* set the flag to to enable irq when need */
	    irq_set_status_flags(client->irq, IRQ_NOAUTOEN);

	    ret = request_threaded_irq(client->irq, NULL, psh_byt_irq_thread,
			IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "psh_byt", client);
	    if (ret) {
		    dev_err(&client->dev, "fail to request irq\n");
		    goto irq_err;
	    }

	    psh_if_info->irq_disabled = 1;
    }

#ifdef DRV_POLLING_MODE 
	psh_if_info->gpio_psh_int = GPIO_PSH_INT;
	rc = gpio_request(psh_if_info->gpio_psh_int, "psh_int");
	if (rc) {
		    dev_warn(&client->dev, "fail to request psh_int pin\n");
		    psh_if_info->gpio_psh_int = -1;
	}
	else {
		    gpio_export(psh_if_info->gpio_psh_int, 1);
			gpio_direction_input(psh_if_info->gpio_psh_int);
	}
#endif 	

    //    psh_if_info->wq = create_singlethread_workqueue("psh_work");
    /*    psh_if_info->wq = alloc_ordered_workqueue("%S", WQ_MEM_RECLAIM|WQ_HIGHPRI, "psh_work");*/


    psh_if_info->wq = alloc_workqueue("%s", WQ_HIGHPRI, 0, "psh_work");

#if 1

    //just a profiler here
    timestamp_init_with_name(&client->dev, 
                             &psh_if_info->io_profiler, "profile_pull");

    poller_init(&psh_if_info->poller_worker,
                poll_sensor_data_by_thread, psh_if_info);

    poller_set_frequency(&psh_if_info->poller_worker, 1000);

    if (!IS_SUCCESS(poller_start(&client->dev,
                                 &psh_if_info->poller_worker)))
    {
        dev_err(&client->dev, "fail to create poller\n");
        goto wq_err;
    }

    /*
      try sync timestamp with sensorhub fw once 
     */
    ia_sync_timestamp_with_sensorhub_fw(psh_if_info->ia_data);

#endif

	if (!psh_if_info->wq) {
	    dev_err(&client->dev, "fail to create workqueue\n");
		goto wq_err;
	}
    
	INIT_WORK(&psh_if_info->work, psh_work_func);
    
    
    //dev_err(&client->dev, "sensor polling speed: %dHZ\n", POLL_HZ_PER_SECOND);
    
#ifdef DRV_POLLING_MODE 	
	INIT_DELAYED_WORK(&psh_if_info->dwork, poll_sensor_data);
#endif 

#ifdef ENABLE_RPM	
	pm_runtime_set_active(&client->dev);
	pm_runtime_use_autosuspend(&client->dev);
	pm_runtime_set_autosuspend_delay(&client->dev, 0);
	pm_runtime_enable(&client->dev);
#endif 

#ifndef DRV_POLLING_MODE 
	psh_if_info->irq_disabled = 0;
    enable_irq(psh_if_info->pshc->irq);
#endif 

	return 0;

wq_err:
	free_irq(client->irq, psh_if_info->pshc);
irq_err:
	hwmon_device_unregister(psh_if_info->hwmon_dev);
hwmon_err:
	psh_ia_common_deinit(&client->dev);
psh_ia_err:
	kfree(psh_if_info);
psh_if_err:
	return ret;
}
Ejemplo n.º 5
0
int DtcpAkeCore_CreateSrmData(DtcpAkeCoreSessionHandle  aAkeCoreSessionHandle,
                              unsigned char           **aSrmCmdBufferPtr,
                              unsigned int             *aSrmCmdBufferSize)
{
    int returnValue = SUCCESS;
    DtcpAkeCoreSessionData *sessionData;
    unsigned char *ourCert;
    unsigned int   ourCertSize;
    unsigned char *ourSrm;
    unsigned int   ourSrmSize;
    unsigned int   srmUpdateSize;

    sessionData = (DtcpAkeCoreSessionData *)aAkeCoreSessionHandle;

    if ((NULL != sessionData) && 
        (NULL != aSrmCmdBufferPtr) && 
        (NULL != aSrmCmdBufferSize) && 
        (OsWrap_EntryIsInList(&sessionData->AkeCoreData->AkeSessions, sessionData)))
    {
        *aSrmCmdBufferPtr = NULL;
        *aSrmCmdBufferSize = 0;

        // Determine if their SRM needs to be updated.
        returnValue = DtcpCore_GetCert(&ourCert, &ourCertSize);
    }
    else
    {
        returnValue = INVALID_ARGUMENT;
    }

    if (IS_SUCCESS(returnValue))
    {
        returnValue = DtcpCore_GetSrm(&ourSrm, &ourSrmSize);
    }

    if (IS_SUCCESS(returnValue))
    {
        returnValue = DtcpSrm_IsTheirSrmCurrent(ourSrm,
                                                ourSrmSize,
                                                sessionData->TheirSrmG,
                                                sessionData->TheirSrmV,
                                                sessionData->TheirSrmC,
                                                &srmUpdateSize);
    }

    if (IS_SUCCESS(returnValue) && (0 < srmUpdateSize))
    {
        sessionData->SrmCmdBuffer = NULL;
        sessionData->SrmCmdBuffer = (unsigned char *)malloc(srmUpdateSize);
        if (sessionData->SrmCmdBuffer)
        {
            sessionData->SrmCmdBufferSize = srmUpdateSize;
            memcpy(sessionData->SrmCmdBuffer, ourSrm, srmUpdateSize);
            *aSrmCmdBufferPtr  = sessionData->SrmCmdBuffer;
            *aSrmCmdBufferSize = srmUpdateSize;
        }
        else
        {
            returnValue = FAILURE;
        }
    }
    return returnValue;
} // DtcpAkeCore_CreateSrmData
Ejemplo n.º 6
0
int DtcpAkeCore_CreateExchangeKeyData(DtcpAkeCoreSessionHandle aAkeCoreSessionHandle,
                                      EnExchKeyId aExchKeyId,
                                      unsigned char **aExchangeKeyCmdBufferPtr,
                                      unsigned int *aExchangeKeyCmdBufferSize)
{
    int returnValue = SUCCESS;
    DtcpAkeCoreSessionData *sessionData;
    unsigned char *exchKeyCmdBuffer;
    unsigned int exchKeyCmdBufferSize;

    sessionData = (DtcpAkeCoreSessionData *)aAkeCoreSessionHandle;

    if ((NULL != sessionData) && 
        (NULL != aExchangeKeyCmdBufferPtr) && 
        (NULL != aExchangeKeyCmdBufferSize) &&
        (OsWrap_EntryIsInList(&sessionData->AkeCoreData->AkeSessions, sessionData)))
    {
        exchKeyCmdBuffer = (unsigned char *)malloc(DTCP_EXCHANGE_KEY_CMD_DATA_SIZE);
        exchKeyCmdBufferSize = DTCP_EXCHANGE_KEY_CMD_DATA_SIZE;

        if (0 != exchKeyCmdBuffer)
        {
            returnValue = DtcpAkeExchKeys_CreateExchKeyData(aAkeCoreSessionHandle,
                                                            aExchKeyId,
                                                            exchKeyCmdBuffer);

            if (IS_SUCCESS(returnValue))
            {
                if (exchKeyIdCopyNever == aExchKeyId)
                {
                    sessionData->ExchKeyCopyNeverCmdBuffer = exchKeyCmdBuffer;
                    sessionData->ExchKeyCopyNeverCmdBufferSize = exchKeyCmdBufferSize;
                }

                if (exchKeyIdCopyOneGeneration == aExchKeyId)
                {
                    sessionData->ExchKeyCopyOneGenCmdBuffer = exchKeyCmdBuffer;
                    sessionData->ExchKeyCopyOneGenCmdBufferSize = exchKeyCmdBufferSize;
                }

                if (exchKeyIdCopyNoMore == aExchKeyId)
                {
                    sessionData->ExchKeyCopyNoMoreCmdBuffer = exchKeyCmdBuffer;
                    sessionData->ExchKeyCopyNoMoreCmdBufferSize = exchKeyCmdBufferSize;
                }

                if (exchKeyIdAes128 == aExchKeyId)
                {
                    sessionData->ExchKeyAes128CmdBuffer = exchKeyCmdBuffer;
                    sessionData->ExchKeyAes128CmdBufferSize = exchKeyCmdBufferSize;
                }

                *aExchangeKeyCmdBufferPtr = exchKeyCmdBuffer;
                *aExchangeKeyCmdBufferSize = exchKeyCmdBufferSize;
            }
        }
        else
        {
            returnValue = FAILURE;
        }
    }
    else
    {
        returnValue = INVALID_ARGUMENT;
    }

    return returnValue;
} // DtcpAkeCore_CreateExchangeKeyData
Ejemplo n.º 7
0
int Rng_GetRandomNumber(unsigned char *aRngBuffer, unsigned int aRngSize)
{
    int returnValue = SUCCESS;
    IppsRijndael128 *cipherContext = 0;
    int cipherContextSize = 0;
    unsigned int i;
    unsigned char plainText[DTCP_AES_BLOCK_SIZE];
    unsigned char cipherText[DTCP_AES_BLOCK_SIZE];

    if (gRngData.UpdateRngSeedFunc != 0)
    {
        if (aRngBuffer)
        {
            // Initialize cipher using seed value as the key
            if (ippStsNoErr == ippsRijndael128BufferSize(&cipherContextSize))
            {
                cipherContext = (IppsRijndael128 *)malloc(cipherContextSize);
                if (cipherContext)
                {
                    if (ippStsNoErr != ippsRijndael128Init(gRngData.RngSeed, IppsRijndaelKey128, cipherContext))
                    {
                        returnValue = FAILURE;
                    }
                }
                else
                {
                    returnValue = FAILURE;
                }
            }
            else
            {
                returnValue = FAILURE;
            }

            if (IS_SUCCESS(returnValue))
            {
                // encrypt buffer to create random data
                for (i = 0; i < aRngSize; ++i)
                {
                    ippsRijndael128EncryptECB(plainText,
                                              cipherText,
                                              1,
                                              cipherContext,
                                              IppsCPPaddingZEROS);

                    plainText[0] ^= cipherText[0];
                    plainText[1] ^= cipherText[1];

                    cipherText[0] = cipherText[0] ^ cipherText[1] ^ cipherText[2] ^ cipherText[3] ^
                                    cipherText[4] ^ cipherText[5] ^ cipherText[6] ^ cipherText[7];
                    aRngBuffer[i] = cipherText[0];
                }

                // Create next seed value
                ippsRijndael128EncryptECB(plainText,
                                            cipherText,
                                            1,
                                            cipherContext,
                                            IppsCPPaddingZEROS);
                cipherText[0] = cipherText[0] ^ cipherText[1] ^ cipherText[2] ^ cipherText[3] ^
                                cipherText[4] ^ cipherText[5] ^ cipherText[6] ^ cipherText[7];
                memcpy(gRngData.RngSeed, cipherText, DTCP_AES_BLOCK_SIZE);

                // Update seed
                gRngData.UpdateRngSeedFunc((unsigned char *)gRngData.RngSeed, DTCP_AES_BLOCK_SIZE);
            }
        }
        else
        {
            returnValue = INVALID_ARGUMENT;
        }
    }
    else
    {
        returnValue = NOT_INITIALIZED;
    }

    if (cipherContext)
    {
        free(cipherContext);
    }
    return returnValue;
} // Rng_GetRandomNumber
Ejemplo n.º 8
0
void
MsgAction :: process(Client* aClient)
{
    ASSERT(aClient != nullptr);
    ASSERT(aClient->getPlayer() != nullptr);

    Client& client = *aClient;
    Player& player = *aClient->getPlayer();

    switch (mInfo->Action)
    {
        case ACTION_CHG_DIR:
            {
                if (player.getUID() != mInfo->UniqId)
                {
                    client.disconnect();
                    return;
                }

                player.setDirection((uint8_t)mInfo->Direction);
                player.broadcastRoomMsg(this, false);
                break;
            }
        case ACTION_EMOTION:
            {
                if (player.getUID() != mInfo->UniqId)
                {
                    client.disconnect();
                    return;
                }

                // TODO: mining = false, intone = false, in battle = false

                player.setPose((uint16_t)mInfo->Data);
                if (AdvancedEntity::POSE_COOL == player.getPose())
                {
                    if (timeGetTime() - player.getLastCoolShow() > 3000) // 3s
                    {
                        // TODO: cool effect
                        if (true)//(isAllNonsuchEquip())
                            mInfo->Data |= (player.getProfession() * 0x00010000 + 0x01000000);
                        else if (true)//(% 10 == 9)
                            mInfo->Data |= (player.getProfession() * 0x010000);

                        player.setLastCoolShow(timeGetTime());
                    }
                }

                player.broadcastRoomMsg(this, true);
                break;
            }
        case ACTION_CHG_MAP:
            {
                if (player.getUID() != mInfo->UniqId)
                {
                    client.disconnect();
                    return;
                }

                const Database& db = Database::getInstance();
                const MapManager& mgr = MapManager::getInstance();
                const GameMap* map = mgr.getMap(player.getMapId());

                if (map != nullptr)
                {
                    uint16_t passageX = (uint16_t)mInfo->Data;
                    uint16_t passageY = (uint16_t)(mInfo->Data >> 16);

                    // if requested with a big range, it's a hack, else we consider that it's a lag...
                    if (GameMap::distance(player.getPosX(), player.getPosY(), passageX, passageY) > 5)
                    {
                         // TODO crime, send to jail
                         return;
                    }

                    uint32_t mapId = 0;
                    uint16_t posX = 0, posY = 0;

                    int passageId = map->getPassage(passageX, passageY);
                    if (passageId != -1 &&
                        IS_SUCCESS(db.getPasswayInfo(mapId, posX, posY, player.getMapId(), (uint8_t)passageId)))
                    {
                        player.move(mapId, posX, posY);
                    }
                    else
                    {
                        player.kickBack();
                    }
                }
                else
                {
                    // invalid map...
                    client.disconnect();
                }
                break;
            }
EglConfig* pixelFormatToConfig(EGLNativeDisplayType dpy,int renderableType,EGLNativePixelFormatType* frmt){

    int  bSize,red,green,blue,alpha,depth,stencil;
    int  supportedSurfaces,visualType,visualId;
    int  caveat,transparentType,samples;
    int  tRed=0,tGreen=0,tBlue=0;
    int  pMaxWidth,pMaxHeight,pMaxPixels;
    int  tmp;
    int  configId,level,renderable;
    int  doubleBuffer;

    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_TRANSPARENT_TYPE,&tmp));
    if(tmp == GLX_TRANSPARENT_INDEX) {
        return NULL; // not supporting transparent index
    } else if( tmp == GLX_NONE) {
        transparentType = EGL_NONE;
    } else {
        transparentType = EGL_TRANSPARENT_RGB;

        IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_TRANSPARENT_RED_VALUE,&tRed));
        IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_TRANSPARENT_GREEN_VALUE,&tGreen));
        IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_TRANSPARENT_BLUE_VALUE,&tBlue));
    }


    //
    // filter out single buffer configurations
    //
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_DOUBLEBUFFER,&doubleBuffer));
    if (!doubleBuffer) return NULL;

    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_BUFFER_SIZE,&bSize));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_RED_SIZE,&red));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_GREEN_SIZE,&green));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_BLUE_SIZE,&blue));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_ALPHA_SIZE,&alpha));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_DEPTH_SIZE,&depth));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_STENCIL_SIZE,&stencil));


    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_X_RENDERABLE,&renderable));

    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_X_VISUAL_TYPE,&visualType));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_VISUAL_ID,&visualId));

    //supported surfaces types
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_DRAWABLE_TYPE,&tmp));
    supportedSurfaces = 0;
    if(tmp & GLX_WINDOW_BIT && visualId != 0) {
        supportedSurfaces |= EGL_WINDOW_BIT;
    } else {
        visualId = 0;
        visualType = EGL_NONE;
    }
    if(tmp & GLX_PBUFFER_BIT) supportedSurfaces |= EGL_PBUFFER_BIT;

    caveat = 0;
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_CONFIG_CAVEAT,&tmp));
    if     (tmp == GLX_NONE) caveat = EGL_NONE;
    else if(tmp == GLX_SLOW_CONFIG) caveat = EGL_SLOW_CONFIG;
    else if(tmp == GLX_NON_CONFORMANT_CONFIG) caveat = EGL_NON_CONFORMANT_CONFIG;
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_MAX_PBUFFER_WIDTH,&pMaxWidth));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_MAX_PBUFFER_HEIGHT,&pMaxHeight));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_MAX_PBUFFER_HEIGHT,&pMaxPixels));

    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_LEVEL,&level));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_FBCONFIG_ID,&configId));
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_SAMPLES,&samples));
    //Filter out configs that does not support RGBA
    IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_RENDER_TYPE,&tmp));
    if (!(tmp & GLX_RGBA_BIT)) {
        return NULL;
    }

    return new EglConfig(red,green,blue,alpha,caveat,configId,depth,level,pMaxWidth,pMaxHeight,
                              pMaxPixels,renderable,renderableType,visualId,visualType,samples,stencil,
                              supportedSurfaces,transparentType,tRed,tGreen,tBlue,*frmt);
}