/*! \fn int __init ifxdeu_init_aes (void)
 *  \ingroup IFX_AES_FUNCTIONS
 *  \brief function to initialize AES driver   
 *  \return ret 
*/                                 
int __init ifxdeu_init_aes (void)
{
    int ret = -ENOSYS;

#ifdef CONFIG_CRYPTO_DEV_PWR_SAVE_MODE    
#define IFX_DEU_DRV_VERSION  "2.0.0"
    printk(KERN_INFO "Lantiq Technologies DEU Driver version %s\n", IFX_DEU_DRV_VERSION);

#if 0
    deu_dma_init();
#endif

#endif /* CONFIG_CRYPTO_DEV_PWR_SAVE_MODE */

 
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20))
    if (!disable_multiblock) {
        ifxdeu_aes_alg.cra_u.cipher.cia_max_nbytes = AES_BLOCK_SIZE;    //(size_t)-1;
        ifxdeu_aes_alg.cra_u.cipher.cia_req_align = 16;
        ifxdeu_aes_alg.cra_u.cipher.cia_ecb = ifx_deu_aes_ecb;
        ifxdeu_aes_alg.cra_u.cipher.cia_cbc = ifx_deu_aes_cbc;
        ifxdeu_aes_alg.cra_u.cipher.cia_cfb = ifx_deu_aes_cfb;
        ifxdeu_aes_alg.cra_u.cipher.cia_ofb = ifx_deu_aes_ofb;
    }
#endif

    if ((ret = crypto_register_alg(&ifxdeu_aes_alg)))
        goto aes_err;

    if ((ret = crypto_register_alg(&ifxdeu_ecb_aes_alg)))
        goto ecb_aes_err;

    if ((ret = crypto_register_alg(&ifxdeu_cbc_aes_alg)))
        goto cbc_aes_err;

    if ((ret = crypto_register_alg(&ifxdeu_ctr_basic_aes_alg)))
        goto ctr_basic_aes_err;

    if ((ret = crypto_register_alg(&ifxdeu_ctr_rfc3686_aes_alg)))
        goto ctr_rfc3686_aes_err;

#ifndef CONFIG_CRYPTO_DEV_PWR_SAVE_MODE
    aes_chip_init ();
#endif

    CRTCL_SECT_INIT;

#ifdef CONFIG_CRYPTO_DEV_DMA
    if (ALLOCATE_MEMORY(BUFFER_IN, AES_ALGO) < 0) {
        printk(KERN_ERR "[%s %s %d]: malloc memory fail!\n", __FILE__, __func__, __LINE__);
        goto ctr_rfc3686_aes_err;
    }
    if (ALLOCATE_MEMORY(BUFFER_OUT, AES_ALGO) < 0) {
        printk(KERN_ERR "[%s %s %d]: malloc memory fail!\n", __FILE__, __func__, __LINE__);
        goto ctr_rfc3686_aes_err;
    }
#endif

    printk (KERN_NOTICE "IFX DEU AES initialized%s%s.\n", disable_multiblock ? "" : " (multiblock)", disable_deudma ? "" : " (DMA)");
    return ret;

ctr_rfc3686_aes_err:
    crypto_unregister_alg(&ifxdeu_ctr_rfc3686_aes_alg);
    printk (KERN_ERR "IFX ctr_rfc3686_aes initialization failed!\n");
    return ret;
ctr_basic_aes_err:
    crypto_unregister_alg(&ifxdeu_ctr_basic_aes_alg);
    printk (KERN_ERR "IFX ctr_basic_aes initialization failed!\n");
    return ret;
cbc_aes_err:
    crypto_unregister_alg(&ifxdeu_cbc_aes_alg);
    printk (KERN_ERR "IFX cbc_aes initialization failed!\n");
    return ret;
ecb_aes_err:
    crypto_unregister_alg(&ifxdeu_ecb_aes_alg);
    printk (KERN_ERR "IFX aes initialization failed!\n");
    return ret;
aes_err:
    printk(KERN_ERR "IFX DEU AES initialization failed!\n");

    return ret;
}
Exemplo n.º 2
0
void CA_PRODUCT_EXTENDED_PRODUCT_ListReplyMsg(const CA_SCELL_MSG *pstSCellMsg)
{
	ia_msg_handle pvMsg;

	msg_extended_product_list_reply_st stExProductListReply;
	msg_extended_product_list_sector_st stExProdcutSector;
	msg_extended_product_list_product_st stExProducts;
	ia_sint16 i, j, m;

	/*allocate the memeory of message and get extended product list message*/
	pvMsg = IA_OpenInputMessage(pstSCellMsg->pvMessage, pstSCellMsg->wLength);
	if (pvMsg == 0)
		return ;
	if (IA_ReadFromMessage(pvMsg, &stExProductListReply, sizeof
		(msg_extended_product_list_reply_st)) == 0)
	{
		IA_CloseMessage(pvMsg, IA_FALSE);
		return ;
	}

	for (m = 0; m < SC_SLOT_MAX; m++)
	{
		if (astCaExProductList[m].wResourceId ==
			stExProductListReply.wResourceId)
			break;
	}
	if (m == SC_SLOT_MAX)
		/* cann't find the resource id */
	{
		IA_CloseMessage(pvMsg, IA_FALSE);
		return ;
	}


	CA_EXTENDED_PRODUCT_ListFreeMemory(stExProductListReply.wResourceId);

	astCaExProductList[m].bSectorCount = stExProductListReply.bSectorCount;
	astCaExProductList[m].wOrgSizeSectorProducts =
		stExProductListReply.bSectorCount;
	astCaExProductList[m].pstSectorProducts = (CA_SECTOR_EXTEND_SECTOR_T*)
		ALLOCATE_MEMORY(CA_SECTOR_EXTEND_SECTOR_T,
		stExProductListReply.bSectorCount);
	if (astCaExProductList[m].pstSectorProducts == 0 && stExProductListReply.bSectorCount > 0)
	{
		IA_CloseMessage(pvMsg, IA_FALSE);
		CA_ERROR(("CA_PRODUCT_EXTENDED_PRODUCT_ListReplyMsg: Memory allocate failed.\n"));
		CA_ERROR_Notify(CA_ERROR_SOURCE_ECT, CA_ERROR_MEMORY);
		return ;
	}

	CA_DBG_V(("<ca_product> allocate extended sector 0x40 : address %0#10x\n", astCaExProductList[m].pstSectorProducts));

	for (i = 0; i < stExProductListReply.bSectorCount; i++)
	{
		IA_ReadFromMessage(pvMsg, &stExProdcutSector, sizeof
			(msg_extended_product_list_sector_st));

		astCaExProductList[m].pstSectorProducts[i].bProductCount =
			stExProdcutSector.bProductCount;
		astCaExProductList[m].pstSectorProducts[i].bSector =
			stExProdcutSector.bSector;
		astCaExProductList[m].pstSectorProducts[i].bSectorStatus =
			(ia_byte)stExProdcutSector.fSectorValid;
		astCaExProductList[m].pstSectorProducts[i].wSectorDateCode =
			stExProdcutSector.wSectorDateCode;
		astCaExProductList[m].pstSectorProducts[i].wMaxSizeExtendProducts =
			stExProdcutSector.bProductCount;
		astCaExProductList[m].pstSectorProducts[i].pstExtendProducts = 0;

		/* jyou: SCR Allocate memory error */
		if (stExProdcutSector.fSectorValid == IA_TRUE && stExProdcutSector.bProductCount > 0 )
		{
			astCaExProductList[m].pstSectorProducts[i].pstExtendProducts =
				(CA_SECTOR_EXTEND_PRODUCT_T*)ALLOCATE_MEMORY
				(CA_SECTOR_EXTEND_PRODUCT_T, stExProdcutSector.bProductCount);
			if (astCaExProductList[m].pstSectorProducts[i].pstExtendProducts == 0)
			{
				IA_CloseMessage(pvMsg, IA_FALSE);
				CA_ERROR(("CA_PRODUCT_EXTENDED_PRODUCT_ListReplyMsg: Memory allocate failed.\n"));
				CA_ERROR_Notify(CA_ERROR_SOURCE_ECT, CA_ERROR_MEMORY);
				return ;
			}
			CA_DBG_V(("<ca_product> allocate extended sector 0x6: sector %d: address %0#10x\n", i, astCaExProductList[m].pstSectorProducts[i].pstExtendProducts));

			for (j = 0; j < stExProdcutSector.bProductCount; j++)
			{
				IA_ReadFromMessage(pvMsg, &stExProducts, sizeof
					(msg_extended_product_list_product_st));
				astCaExProductList[m].pstSectorProducts[i].pstExtendProducts[j].wProduct = stExProducts.wProductId;
				astCaExProductList[m].pstSectorProducts[i].pstExtendProducts[j].wStartDate = stExProducts.wStartDate;
				astCaExProductList[m].pstSectorProducts[i].pstExtendProducts[j].bDuration = stExProducts.bDuration;
			}
		}
	}

	/* send the extended productlist to CA client */
	CA_CLIENT_Notify(stExProductListReply.wResourceId,
		CA_QC_EXTENDED_PRODUCT_LIST, (ia_word32)
		astCaExProductList[m].bSectorCount);

	IA_CloseMessage(pvMsg, IA_FALSE);
}