Ignore:
Timestamp:
01/11/10 19:30:52 (12 years ago)
Author:
alno
Message:

WebIf:

  • Merging revisions 1180-1185 of trunk
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/monitor-improvement/csctapi/ifd_cool.c

    r1177 r1189  
    77#include <stdio.h>
    88#include <time.h>
     9#include <string.h>
    910#include"ifd_cool.h"
    10 /*
    11 #include "io_serial.h"
    12 #include "sci_global.h"
    13 #include "sci_ioctl.h"
    14 */
    15 
    16 // these should be called from icc, t0, cardterminal etc. like this:
    17 // switch (reader[ridx].type) {
    18 //   case INTERN:
    19 // #ifdef COOL
    20 //       Cool_Init();
    21 //       break;
    22 // #endif
    23 // #ifdef SCI_DEV
    24 // //still in towitoko shit
    25 // #endif
    26 //   case SMART:
    27 //   case MOUSE:
    28 //       IFD_Towitoko_Init(ifd, io, slot);
    29 //       break;
    30 //   default:
    31 //       return ERROR;
    32 // }
    33 // all other IFD_Towitoko functions should be
    34 // -eliminated (like SetLed or administrative jobs)
    35 // -rewritten eg. setparity should become a call to getproperties, setproperties
    36 // ActivateICC should call ResetICC automagically
    37 // DeactivateICC for symmetry and cleanup
    38 //
    3911
    4012#define OK      1
     
    4820int Cool_Init ()
    4921{
    50     //initialize properties(input_bitrate, output_bitrate, bits, stopbits, parity,dtr, rts) of device to default values
    51     //initialize ifd settings
    52     //and get reader info
    5322    if (cnxt_kal_initialize ())
    5423        return FALSE;
     
    7039}
    7140
    72 /*
    73 int Cool_GetStatus (BYTE * result)
    74 {
    75 // return status : 0 -start, 1 - card, 2- no card
    7641
    77     //extern int cnxt_smc_get_state();
     42int Cool_GetStatus (int * in)
     43{
     44    int state;
     45    if (cnxt_smc_get_state(handle, &state))
     46        return ERROR;
     47    //state = 0 no card, 1 = not ready, 2 = ready
     48    if (state)
     49        *in = 1; //CARD, even if not ready report card is in, or it will never get activated
     50    else
     51        *in = 0; //NOCARD
    7852    return OK;
    7953}
    80 */
     54
    8155int Cool_Reset (ATR ** atr)
    8256{
    83 printf("Entering coolreset");
    84 fflush(stdout);
    85     //reset needs clock to be reset by hand
    86     typedef unsigned long u_int32;
    87     u_int32 clk;
    88     clk = 357*10000; // MHZ
    89     if (cnxt_smc_set_clock_freq(handle, clk))
     57    if (!Cool_SetBaudrate(357))
    9058        return ERROR;
    9159
     
    9664
    9765    int n = 40;
    98     //int atr_len = 40;
    9966    unsigned char buf[40];
    10067    if (cnxt_smc_get_atr (handle, buf, &n))
    10168        return ERROR;
    102     //atr_len = n;
    103 //  atr = buf;
    104     /////////////
    105         (*atr) = ATR_New ();
    106         if(ATR_InitFromArray ((*atr), buf, n) == ATR_OK)
    107         {
    108             struct timespec req_ts;
    109             req_ts.tv_sec = 0;
    110             req_ts.tv_nsec = 50000000;
    111             nanosleep (&req_ts, NULL);
    112 #ifdef SCI_DEV
    113             if (ioctl(ifd->io->fd, IOCTL_SET_ATR_READY)<0)
    114                 return ERROR;
    115 #endif
    116             return OK;
    117         }
    118         else
    119         {
    120             ATR_Delete (*atr);
    121             (*atr) = NULL;
    122             return ERROR;
    123         }
    124     ///////////
     69       
     70    (*atr) = ATR_New ();
     71    if(ATR_InitFromArray ((*atr), buf, n) == ATR_OK)
     72    {
     73        struct timespec req_ts;
     74        req_ts.tv_sec = 0;
     75        req_ts.tv_nsec = 50000000;
     76        nanosleep (&req_ts, NULL);
     77        return OK;
     78    }
     79    else
     80    {
     81        ATR_Delete (*atr);
     82        (*atr) = NULL;
     83        return ERROR;
     84    }
    12585}
    126 /*
    127 int Cool_DeactivateICC ()
    128 {
    129 #ifdef DEBUG_IFD
    130     printf ("IFD: Deactivating card\n");
    131 #endif
    132 /*
    133         int in;
    134        
    135 #if defined(TUXBOX) && (defined(MIPSEL) || defined(PPC) || defined(SH4))
    136         if(ioctl(ifd->io->fd, IOCTL_GET_IS_CARD_PRESENT, &in)<0)
    137 #else
    138         if(ioctl(ifd->io->fd, IOCTL_GET_IS_CARD_ACTIVATED, &in)<0)
    139 #endif
    140             return IFD_TOWITOKO_IO_ERROR;
    141            
    142         if(in)
    143         {
    144             if(ioctl(ifd->io->fd, IOCTL_SET_DEACTIVATE)<0)
    145                 return IFD_TOWITOKO_IO_ERROR;
    146         }
    147 */     
    148 /*
    149     return OK;
    150 }
    151 */
    15286
    15387int Cool_Transmit (BYTE * sent, unsigned size)
     
    15589#define TIMEOUT 4000 //max 4294
    15690    cardbuflen = 256;//it needs to know max buffer size to respond?
    157   int rc = cnxt_smc_read_write(handle, FALSE, sent, size, cardbuffer, &cardbuflen, TIMEOUT, 0);
     91    if (cnxt_smc_read_write(handle, FALSE, sent, size, cardbuffer, &cardbuflen, TIMEOUT, 0))
     92        return ERROR;
    15893
    15994#ifdef DEBUG_IFD
    160   //usually done in IFD_Towitoko, for COOL do it here
     95    //usually done in IFD_Towitoko, for COOL do it here
    16196    printf ("COOLIFD: Transmit: ");
    16297    int i;
    16398    for (i = 0; i < size; i++)
    164       printf ("%X ", sent[i]);
     99        printf ("%X ", sent[i]);
    165100    printf ("\n");
    166101#endif
    167 
    168     //FIXME implement rc
     102    return OK;
    169103}
    170104
    171 int Cool_Receive (BYTE * buffer, unsigned size)
    172 { //receive buffer to SC
    173     //memcpy(buffer,cardbuffer,cardbuflen);
    174     //size = cardbuflen;
     105int Cool_Receive (BYTE * data, unsigned size)
     106{
     107    if (size > cardbuflen)
     108        size = cardbuflen; //never read past end of buffer
     109    memcpy(data,cardbuffer,size);
     110    cardbuflen -= size;
     111    memmove(cardbuffer,cardbuffer+size,cardbuflen);
    175112
    176113#ifdef DEBUG_IFD
    177114    int i;
    178     printf ("IFD: Receive: "); //I think
     115    printf ("COOLIFD: Receive: "); //I think
    179116    for (i = 0; i < size; i++)
    180         printf ("%X ", buffer[i]);
     117        printf ("%X ", data[i]);
    181118    printf ("\n");
     119    fflush(stdout);
    182120#endif
    183 
    184121    return OK;
    185122}   
     
    189126    typedef unsigned long u_int32;
    190127    u_int32 clk;
    191     //clk = 357 * 10000;        // MHZ
    192     clk = mhz * 10000;  // MHZ
     128    clk = mhz * 10000;
    193129    if (cnxt_smc_set_clock_freq (handle, clk))
    194130        return ERROR;
Note: See TracChangeset for help on using the changeset viewer.