⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testall.c

📁 freescale ppc sec2加解密单元驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************** * testAll.c - Top-level known-answer test manager for SEC2 device driver **************************************************************************** * Copyright (c) 2004-2005 Freescale Semiconductor * All Rights Reserved. Proprietary and Confidential. * * NOTICE: The information contained in this file is proprietary * to Freescale Semiconductor, and is being made available to * Freescale's customers under strict license agreements. * Use or disclosure of this information is permissible only * under the terms of the existing license agreement. ***************************************************************************//* Revision History: *  1.1.0 Dec 05,2004 sec - prep for linux-compatible driver release *  1.1.1 Dec 15,2004 sec - bring DES and PKHA cases in *  1.2   02-Feb-2005 sec - clean up notifier handling */#include <taskLib.h>#include <stdio.h>#include "sec2drvTest.h"#include "Sec2.h"#ifdef __KERNEL__#define MODULE#define MODVERSIONS#define EXPORT_SYMTAB#include <linux/config.h>#include <linux/module.h>#include <linux/sched.h>#include <asm/atomic.h>#include <asm/semaphore.h>#endif#define TESTALL_IPSEC#define TESTALL_HMAC#define TESTALL_HASH#define TESTALL_AES#define TESTALL_RNG#define TESTALL_RC4#define TESTALL_DES#define TESTALL_PKHA#define TESTALL_CCMP#ifndef _LINUX_USERMODE_#define TESTALL_SCATTER#endifint testPKHA(int);int testIPSEC(int);int testAesa(int);int testAfha(int);int testAFHActx(int);int testDes(int, int, int);int testDesECB(int, int, int);int testHmac(int);int testKea(int);int testRng(int);int testSG(int);int testccmp(int);/* * This next block of code comprises some common synchronization, memory service, * and event handing functionality common to the entire test series */ /* * If it's VxWorks or Linux in kernel mode, we'll use a semaphore as a request * interlock. If it's a Linux user-mode test, we'll use a signal instead */#ifdef __KERNEL__static DECLARE_MUTEX(notifySemId);#else/*static int fd;*/static volatile char proceed;#endif/* Normal and error completion handlers */static void notifyDone(void){#ifdef __KERNEL__    semGive(notifySemId);#else    proceed++;#endif    return;}static void notifyError(void){#ifdef __KERNEL__    semGive(notifySemId);#else    proceed++;#endif    return;}static const char errstrMemAlloc[]    = { "MEMORY_ALLOCATION" };static const char errstrInvChn[]      = { "INVALID_CHANNEL" };static const char errstrInvCha[]      = { "INVALID_CHA_TYPE" };static const char errstrInvOpId[]     = { "INVALID_OPERATION_ID" };static const char errstrChnNotAvail[] = { "CHANNEL_NOT_AVAILABLE" };static const char errstrChaNotAvail[] = { "CHA_NOT_AVAILABLE" };static const char errstrInvLen[]      = { "INVALID_LENGTH" };static const char errstrAlign[]       = { "OUTPUT_BUFFER_ALIGNMENT" };static const char errstrAddr[]        = { "ADDRESS_PROBLEM" };static const char errstrNoReqs[]      = { "INSUFFICIENT_REQS" };static const char errstrChaErr[]      = { "CHA_ERROR" };static const char errstrNullRq[]      = { "NULL_REQUEST" };static const char errstrTimeOut[]     = { "REQUEST_TIMED_OUT" };static const char errstrMalloc[]      = { "MALLOC_FAILED" };static const char errstrFree[]        = { "FREE_FAILED" };static const char errstrParity[]      = { "PARITY_SYSTEM_ERROR" };static const char errstrIncomp[]      = { "INCOMPLETE_POINTER" };static const char errstrTEA[]         = { "TEA_ERROR" };static const char errstrFrag[]        = { "FRAGMENT_POOL_EXHAUSTED" };static const char errstrFIFO[]        = { "FETCH_FIFO_OVERFLOW" };static const char errstrBus[]         = { "BUS_MASTER_ERROR" };static const char errstrScatter[]     = { "SCATTER_LIST_ERROR" };static const char errstrUnknown[]     = { "UNKNOWN_ERROR" };static const char errstrNotFound[]    = { "IO_CARD_NOT_FOUND" };static const char errstrIOalloc[]     = { "IO_MEMORY_ALLOCATE_ERROR" };static const char errstrIOIO[]        = { "IO_IO_ERROR" };static const char errstrDrvTable[]    = { "IO_VXWORKS_DRIVER_TABLE_ADD_ERROR" };static const char errstrIntAlloc[]    = { "IO_INTERRUPT_ALLOCATE_ERROR" };static const char errstrBAR0[]        = { "CANNOT_SETUP_BAR0_ERROR" };static const char errstrQueue[]       = { "VXWORKS_CANNOT_CREATE_QUEUE" };static const char errstrCancel[]      = { "CANCELLED_REQUEST" };static const char errstrInvAddr[]     = { "INVALID_ADDRESS" };static const char *mapErrStr(int status){    switch(status)    {        case SEC2_MEMORY_ALLOCATION:            return(errstrMemAlloc);        case SEC2_INVALID_CHANNEL:            return(errstrInvChn);        case SEC2_INVALID_CHA_TYPE:            return(errstrInvCha);        case SEC2_INVALID_OPERATION_ID:            return(errstrInvOpId);        case SEC2_CHANNEL_NOT_AVAILABLE:            return(errstrChnNotAvail);        case SEC2_CHA_NOT_AVAILABLE:            return(errstrChaNotAvail);        case SEC2_INVALID_LENGTH:            return(errstrInvLen);        case SEC2_OUTPUT_BUFFER_ALIGNMENT:            return(errstrAlign);        case SEC2_ADDRESS_PROBLEM:            return(errstrAddr);        case SEC2_INSUFFICIENT_REQS:            return(errstrNoReqs);        case SEC2_CHA_ERROR:            return(errstrChaErr);        case SEC2_NULL_REQUEST:            return(errstrNullRq);        case SEC2_REQUEST_TIMED_OUT:            return(errstrTimeOut);        case SEC2_MALLOC_FAILED:            return(errstrMalloc);        case SEC2_FREE_FAILED:            return(errstrFree);        case SEC2_PARITY_SYSTEM_ERROR:            return(errstrParity);        case SEC2_INCOMPLETE_POINTER:            return(errstrIncomp);        case SEC2_TEA_ERROR:            return(errstrTEA);        case SEC2_FRAGMENT_POOL_EXHAUSTED:            return(errstrFrag);        case SEC2_FETCH_FIFO_OVERFLOW:            return(errstrFIFO);        case SEC2_BUS_MASTER_ERROR:            return(errstrBus);        case SEC2_SCATTER_LIST_ERROR:            return(errstrScatter);        case SEC2_IO_CARD_NOT_FOUND:            return(errstrNotFound);        case SEC2_IO_MEMORY_ALLOCATE_ERROR:            return(errstrIOalloc);        case SEC2_IO_IO_ERROR:            return(errstrIOIO);        case SEC2_IO_VXWORKS_DRIVER_TABLE_ADD_ERROR:            return(errstrDrvTable);        case SEC2_IO_INTERRUPT_ALLOCATE_ERROR:            return(errstrIntAlloc);        case SEC2_CANNOT_SETUP_BAR0_ERROR:            return(errstrBAR0);        case SEC2_VXWORKS_CANNOT_CREATE_QUEUE:            return(errstrQueue);        case SEC2_CANCELLED_REQUEST:            return(errstrCancel);        case SEC2_INVALID_ADDRESS:            return(errstrInvAddr);        case SEC2_UNKNOWN_ERROR:        default:            return(errstrUnknown);    }}/* Basic "completion init" request. The idea is to set up handers in the user's request *//* block as appropriate, either signal handlers for user mode, or a semaphore release *//* otherwise */void armCompletion(void *req){    GENERIC_REQ *rq;        rq = req;#ifdef __KERNEL__    rq->notify          = (void (*)())notifyDone;    rq->notify_on_error = (void (*)())notifyError;    rq->notifyFlags     = 0;#else    rq->notify          = (void *)getpid();    rq->notify_on_error = (void *)getpid();    rq->notifyFlags     = (NOTIFY_IS_PID | NOTIFY_ERROR_IS_PID);    signal(SIGUSR1, (void (*)())notifyDone);    signal(SIGUSR2, (void (*)())notifyError);    proceed = 0;#endif}#ifdef __KERNEL__/* substitute the 3-arg form for a direct call to the 4-arg form */int subIoctl(int fd, unsigned long code, unsigned long param){    return SEC2_ioctl(NULL, NULL, code, param);}#endif/* * Basic "wait" block, assuming that armCompletion() was already called to * set things up before the ioctl() call to the driver to process the * request block. This gets called with 3 arguments: * * testname - points to a string to be printed with the error information *            in the event of a late error having been posted to the  *            user's request block * * iostat   - error code returned from prior ioctl call *  * req      - points to the user's request block, the status field will *            be checked for any error following the driver's interrupt *            service. */int waitCompletion(char *testname, int iostat, void *req){    GENERIC_REQ *rq;    /*int          timestat;*/    unsigned int timeout = 0;            rq = req;        /* firstly, check for obvious processing errors either from the OS or */    /* the driver, which would have precluded kicking off any processing  */    if (iostat != SEC2_SUCCESS) {        if (iostat == -1)            printf("%s ioctl failed\n", testname);        else            printf ("%s, driver error 0x%08x processing request\n", testname, iostat);        return iostat;    }    /* If we got this far, then the driver will have triggered some kind of */    /* processing. Wait for the ioctl() call completion with whatever the   */    /* right mechanism is for the mode we're using                          */#ifdef __KERNEL__    if (iostat = semTake(notifySemId, 300)) {        printf("Request Timeout\n");        return iostat;    }#else    while(!proceed)      {        usleep(100);        if (++timeout >= 30000) {            printf("Request Timeout\n");            return -1;        }    } #endif        /* If an error occurred as a consequence of a the request (i.e. something a */    /* problem for the hardware), then the status in the request header will    */    /* be updated with it, so show this                                         */    if (rq->status != SEC2_SUCCESS)    {        printf("%s, error 0x%08x (%s) reported post-request\n", testname, rq->status, mapErrStr(rq->status));        return rq->status;    }    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -