Title: Problems with CT-API ChipDrive

I am having a problem wiith the Chipdrive CT-API for Linux. There is a test program called tester that I have wrapped with python to quickly prototype my application. I tested my modified WriteData function and received a successful return code. When I tride to read the data, I don't get back the data that I've written. Enclosed please find my code changes to tester.c application:


tester.c - Function WriteData

char
WriteData (unsigned short ctn, char data[])
{
  unsigned char select_file[7] = { 0x00, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00 };
  unsigned char * update_binary;
  unsigned char * tmp_file;
  int address=0;
  int x, size, total_size;
  unsigned char buffer[255]={0};
  unsigned char res[256];
  unsigned char dad;
  unsigned char sad;
  unsigned short lr, lc;
  int dummy;
  char ret;

  printf("data="" len[%d]\n", data, strlen(data));
/*  printf ("Address: ");
  scanf ("%d", &address);
  dummy = getchar (); */

  size  = GetMemoryLength(ct_list[ctn].atr, ct_list[ctn].atr_size);
  printf("Size =%d\n", size);

/*  printf ("Size (0..%d): ", total_size);
  scanf ("%d", &size);
  dummy = getchar (); */

/*  printf ("Data: ");
  scanf ("%X", (unsigned int *) buffer);
  dummy = getchar (); */


  snprintf(buffer,sizeof(unsigned int)*strlen(data),"%X" ,data);
 
/*  printf("buffer=[%s]\n", buffer); */

  if  (size < 256)
  {
        update_binary = calloc (size +5, sizeof (unsigned char));

        if (update_binary == NULL)
                return(-1);

        update_binary[0] = 0x00;
        update_binary[1] = 0xD6;
        update_binary[2] = (unsigned char) (address >> 8);
        update_binary[3] = (unsigned char) (address & 0x00FF);
        update_binary[4] = size;
/*      memset (update_binary+5, buffer[0], size); */
      memcpy(update_binary+5,data, sizeof(unsigned char)*strlen(data));
        printf("update_binary=%X", update_binary);
/*      lc = size + 5; */
        lc = strlen(data) + 5;
  }
  else
  {
        update_binary = calloc (size +7, sizeof (unsigned char));

        if (update_binary == NULL)
                return(-1);

        update_binary[0] = 0x00;
        update_binary[1] = 0xD6;
        update_binary[2] = (unsigned char) (address >> 8);
        update_binary[3] = (unsigned char) (address & 0x00FF);
        update_binary[4] = 0;
        update_binary[5] = (unsigned char) (size >> 8);
        update_binary[6] = (unsigned char) (size & 0x00FF);
/*      memset (update_binary+7, buffer[0], size); */
        memcpy(update_binary+7,data,sizeof(unsigned char)*strlen(data));
/*      lc = size +7; */
        lc = strlen(data) + 7;
        printf("update_binary=%u", update_binary);
  }

  printf ("Command: ");
  PrintArray (select_file, 7);

  dad = 0;
  sad = 2;
  lr = 256;

  /* Select MF */
  ret = CT_data (ctn, &dad, &sad, 7, select_file, &lr, res);

  if (ret != OK)
    {
      fprintf (stderr, "Error on SELECT FILE: %d\n", ret);
      free (update_binary);
      return(ret);
    }

  printf ("Response: ");
  PrintArray (res, lr);

  printf ("Command: ");
  PrintArray (update_binary, lc);

  dad = 0;
  sad = 2;
  lr = 256;

  /* Update binary */
  ret = CT_data (ctn, &dad, &sad, lc, update_binary, &lr, res);

  free (update_binary);

  if (ret != OK)
    {
      fprintf (stderr, "Error on UPDATE BINARY: %d\n", ret);
      return(ret);
    }

  printf ("Response: ");
  PrintArray (res, lr);
}


Here is the message traffic:

>>> import pyct
>>> pyct.Initialize("com1")
Initializing terminal at COM1...
Initializing terminal at ctn 0...pn 1
Activating card...
0
>>> pyct.WriteData(0, "test")
data="" len[4]
Size =256
update_binary=135630480Command: 00 A4 00 00 02 3F 00
Response: 90 00
Command: 00 D6 00 00 00 01 00 74 65 73 74
Response: 90 00
'\x08'
>>> pyct.ReadData(0)
Address: 0
Size (0..256): 256
Command: 00 A4 00 00 02 3F 00
Response: 90 00
Command: 00 B0 00 00 00 01 00
Response:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
90 00

Reply via email to