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

📄 mu_sci.c

📁 IBM source for pallas/vulcan/vesta
💻 C
📖 第 1 页 / 共 3 页
字号:
                printf("Historical bytes in hexadecimal:\r\n");                for (i = 0; i < historical_size; i++)                {                    if (ATR[i + historical_offset] < 0x10)                    {                        printf("0", ATR[i + historical_offset]);                    }                    printf("%x ", ATR[i + historical_offset]);                }                printf("\r\n");                printf                    ("T      (Current Protocol):                     %d\r\n",                     sc_parameters.T);                printf("All T  (Mask of All Offered Protocols 15:0):   ");                for (i = 0; i < 16; i++)                {                    if (((sc_parameters.maskT) & (0x8000 >> i)) ==                        (0x8000 >> i))                    {                        printf("1");                    }                    else                    {                        printf("0");                    }                }                printf("\r\n");                printf                    ("F      (Current Clock Rate Conversion Factor): %d\r\n",                     sc_parameters.F);                printf                    ("D      (Current Baud Rate Adjustment Factor):  %d\r\n",                     sc_parameters.D);                printf                    ("FI     (Card Clock Rate Conversion Factor):    %d\r\n",                     sc_parameters.FI);                printf                    ("DI     (Card Baud Rate Adjustment Factor):     %d\r\n",                     sc_parameters.DI);                printf                    ("II     (Maximum Programming Current Factor):   %d\r\n",                     sc_parameters.II);                printf                    ("PI1    (Programming Voltage-volts):            %d\r\n",                     sc_parameters.PI1);                printf                    ("PI2    (Programming Voltage-decivolts):        %d\r\n",                     sc_parameters.PI2);                printf                    ("WI     (Work Waiting Time Factor):             %d\r\n",                     sc_parameters.WI);                printf                    ("XI     (Clock Stop Indicator):                 %d\r\n",                     sc_parameters.XI);                printf                    ("UI     (Class Indicator):                      %d\r\n",                     sc_parameters.UI);                printf                    ("N      (Extra Guardtime Factor):               %d\r\n",                     sc_parameters.N);                printf                    ("CWI    (Character Waiting Time Factor):        %d\r\n",                     sc_parameters.CWI);                printf                    ("BWI    (Block Waiting Time Factor):            %d\r\n",                     sc_parameters.BWI);                printf                    ("IFSC   (Information Field Size of the Card):   %d\r\n",                     sc_parameters.IFSC);                printf                    ("checks (1=LRC 2=CRC):                          %d\r\n",                     sc_parameters.check);            }            else            {                print_error("sc_get_parameters", rc);            }        }        else        {            print_error("sc_get_atr", rc);        }    }    else    {        printf("Smart Card not activated- a cold reset must be done\r\n");    }}/****************************************************************************** Function:    get_parms**** Purpose:     Print all current communication parameters. **** Parameters:  sci_id: zero-based number to identify smart card controller****************************************************************************/void get_parms(unsigned long sci_id){    int rc = SCI_ERROR_OK;    SCI_PARAMETERS sci_parameters;    unsigned long ioctl_param;    ioctl(fd[sci_id], IOCTL_GET_IS_CARD_ACTIVATED, &ioctl_param);    if (ioctl_param == 1)    {        /* get the Smart Card's default parameters */        if (ioctl(fd[sci_id], IOCTL_GET_PARAMETERS, &sci_parameters) == 0)        {            printf("Smart Card %d Communication Parameters:\r\n", sci_id);            printf("------------------------------------");            printf("------------------------------------\n\r");            printf("T      (Protocol):                           %d\r\n",                   sci_parameters.T);            printf("f      (Clock Frequency in Hz):              %d\r\n",                   sci_parameters.f);            printf("ETU    (Clocks per Bit):                     %d\r\n",                   sci_parameters.ETU);            printf("WWT    (Work Waiting Time in ETUs):          %d\r\n",                   sci_parameters.WWT);            printf("CWT    (Character Waiting Time in ETUs):     %d\r\n",                   sci_parameters.CWT);            printf("BWT    (Block Waiting Time in ETUs):         %d\r\n",                   sci_parameters.BWT);            printf("EGT    (Extra Guard Time in ETUs):           %d\r\n",                   sci_parameters.EGT);            printf("checks (1=LRC 2=CRC):                        %d\r\n",                   sci_parameters.check);            printf("Clock Stop Polarity:                         %d\r\n",                   sci_parameters.clock_stop_polarity);            printf("------------------------------------");            printf("------------------------------------\n\r");        }        else        {            print_error("sc_get_parameters", rc);        }    }    else    {        printf("Smart Card not activated- a cold reset must be done\r\n");    }}/****************************************************************************** Function:    set_parms**** Purpose:     Set communication parameters, overriding ATR values**** Parameters:  sci_id: zero-based number to identify smart card controller**** NOTE:        The changing of these parameters may result in undesirable**              effects due to invalid parameter settings or conbinations of**              settings, therefore we have removed this option from the menu.**              However, we are leaving the code here as a test vechile for**              experienced users.****************************************************************************/#ifdef SET_PARAMETERSvoid set_parms(unsigned long sci_id){    int rc = SCI_ERROR_OK;    char read_data[80];    SCI_PARAMETERS sci_parameters;    unsigned long ioctl_param;    ioctl(fd[sci_id], IOCTL_GET_IS_CARD_ACTIVATED, &ioctl_param);    if (ioctl_param == 1)    {        /* get the current Smart Card parameters */        if (ioctl(fd[sci_id], IOCTL_GET_PARAMETERS, &sci_parameters) == 0)        {            /* display current parameters */            get_parms(sci_id);            printf("Hit enter to keep current value.\r\n");            printf("Enter Protocol (0 or 1):\r\n");            scanf("%s", read_data);            if (isdigit((int) read_data[0]))            {                sci_parameters.T = (unsigned char) atol(read_data);            }            printf("Enter Clock Frequency in Hz (%u to %u):\r\n", SCI_MIN_F,                   SCI_MAX_F);            scanf("%s", read_data);            if (isdigit((int) read_data[0]))            {                sci_parameters.f = atol(read_data);            }            printf("Enter Clocks per Bit (ETU) (%u to %u):\r\n", SCI_MIN_ETU,                   SCI_MAX_ETU);            scanf("%s", read_data);            if (isdigit((int) read_data[0]))            {                sci_parameters.ETU = atol(read_data);            }            printf("Enter Work Waiting Time (WWT) in ETUs (%u to %u):\r\n",                   SCI_MIN_WWT, SCI_MAX_WWT);            scanf("%s", read_data);            if (isdigit((int) read_data[0]))            {                sci_parameters.WWT = atol(read_data);            }            printf                ("Enter Character Waiting Time (CWT) in ETUs (%u to %u):\r\n",                 SCI_MIN_CWT, SCI_MAX_CWT);            scanf("%s", read_data);            if (isdigit((int) read_data[0]))            {                sci_parameters.CWT = atol(read_data);            }            printf("Enter Block Waiting Time (BWT) in ETUs (%u to %u):\r\n",                   SCI_MIN_BWT, SCI_MAX_BWT);            scanf("%s", read_data);            if (isdigit((int) read_data[0]))            {                sci_parameters.BWT = atol(read_data);            }            printf("Enter Extra Guard Time (EGT) in ETUs (%u to %u):\r\n",                   SCI_MIN_EGT, SCI_MAX_EGT);            scanf("%s", read_data);            if (isdigit((int) read_data[0]))            {                sci_parameters.EGT = atol(read_data);            }            printf("Enter Error Check Type (1=LRC 2=CRC):\r\n");            scanf("%s", read_data);            if (isdigit((int) read_data[0]))            {                sci_parameters.check = (unsigned char) atol(read_data);            }            printf("Enter Clock Stop Polarity (0=NEG 1=POS):\r\n");            scanf("%s", read_data);            if (isdigit((int) read_data[0]))            {                sci_parameters.clock_stop_polarity = atol(read_data);            }            /* set the new Smart Card parameters */            if (ioctl(fd[sci_id], IOCTL_SET_PARAMETERS, &sci_parameters) == 0)            {                printf("Parameters set successfully.\r\n");            }            else            {                print_error("sci_set_parameters", rc);            }        }        else        {            print_error("sci_get_parameters", rc);        }    }    else    {        printf("Smart Card not activated- a cold reset must be done\r\n");    }}#endif/****************************************************************************** Function:    get_parms**** Purpose:     Print the current IFSD (Information Field Size for the Device). **** Parameters:  sci_id: zero-based number to identify smart card controller****************************************************************************/void get_ifsd(unsigned long sci_id){    SCI_ERROR rc = SCI_ERROR_OK;    unsigned char ifsd = 0;    unsigned long ioctl_param;    ioctl(fd[sci_id], IOCTL_GET_IS_CARD_ACTIVATED, &ioctl_param);    if (ioctl_param == 1)    {        if ((rc = sc_get_ifsd(sci_id, &ifsd)) == SCI_ERROR_OK)        {            printf("IFSD (Information Field Size of the Device): %u\r\n",                   ifsd);        }        else        {            print_error("sc_get_ifsd", rc);        }    }    else    {        printf("Smart Card not activated- a cold reset must be done\r\n");    }}/****************************************************************************** Function:    set_ifsd**** Purpose:     Set the current IFSD (Information Field Size for the Device).**** Parameters:  sci_id: zero-based number to identify smart card controller****************************************************************************/void set_ifsd(unsigned long sci_id){    SCI_ERROR rc = SCI_ERROR_OK;    unsigned char ifsd = 0;    char read_data[80];    unsigned long ioctl_param;    ioctl(fd[sci_id], IOCTL_GET_IS_CARD_ACTIVATED, &ioctl_param);    if (ioctl_param == 1)    {        get_ifsd(sci_id);        printf("Hit enter to keep current value.\r\n");        printf("Enter IFSD (%u to %u):\r\n", SC_MIN_IFSD, SC_MAX_IFSD);        scanf("%s", read_data);        if (isdigit((int) read_data[0]))        {            if ((atol(read_data) >= SC_MIN_IFSD)                && (atol(read_data) <= SC_MAX_IFSD))            {                ifsd = (unsigned char) atol(read_data);                if ((rc = sc_set_ifsd(sci_id, ifsd)) == SCI_ERROR_OK)                {                    printf("IFSD set successfully.\r\n");                }                else                {                    print_error("sc_set_ifsd", rc);                }            }            else            {                printf("IFSD set failed- value out of valid range.\r\n");            }        }    }    else    {        printf("Smart Card not activated- a cold reset must be done\r\n");    }}/****************************************************************************** Function:    get_modes**** Purpose:     Print all current SCI driver modes**** Parameters:  sci_id: zero-based number to identify smart card controller****************************************************************************/void get_modes(unsigned long sci_id){    int rc = SCI_ERROR_OK;    SCI_MODES sci_modes;    /* get the Smart Card's default parameters */    if (ioctl(fd[sci_id], IOCTL_GET_MODES, &sci_modes) == 0)    {        printf("\r\n");        printf("Smart Card %d Driver Modes:\r\n", sci_id);        printf("------------------------------------");        printf("------------------------------------\n\r");        printf("Specification Compliance: ");        if (sci_modes.emv2000 == 1)        {            printf("EMV2000-Book1\r\n");        }        else        {            printf("ISO/IEC 7816\r\n");        }        printf("Activation:               ");        if (sci_modes.man_act == 1)        {            printf("Manual\r\n");        }        else        {            printf("Automatic\r\n");        }        printf("------------------------------------");        printf("------------------------------------\n\r");        printf("\r\n");    }    else    {        print_error("sci_get_modes", rc);    }}/****************************************************************************** Function:    set_modes**** Purpose:     Set SCI driver modes**** Parameters:  sci_id: zero-based number to identify smart card controller****************************************************************************/void set_modes(unsigned long sci_id){    int rc = SCI_ERROR_OK;    char read_data[80];    SCI_MODES sci_modes;    /* get the current Smart Card driver modes */    if (ioctl(fd[sci_id], IOCTL_GET_MODES, &sci_modes) == 0)    {        /* display current modes */        get_modes(sci_id);        printf("EMV2000-Book1? (0=disable 1=enable):\r\n");        scanf("%s", read_data);        if (isdigit((int) read_data[0]))        {            sci_modes.emv2000 = atoi(read_data);        }        printf("Manual Activation? (0=disable 1=enable):\r\n");        scanf("%s", read_data);        if (isdigit((int) read_data[0]))        {            sci_modes.man_act = atoi(read_data);        }        /* set the new Smart Card parameters */        if (ioctl(fd[sci_id], IOCTL_SET_MODES, &sci_modes) == 0)        {            printf("Modes set successfully.\r\n");        }        else        {            print_error("sci_set_modes", rc);        }    }    else    {        print_error("sci_get_modes", rc);    }}

⌨️ 快捷键说明

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