title: iOS: Reading contactless VISA smart card data with Grabba
body: <p>I have a Grabba smart card reader. I am trying to get card information with APDU commands. I have read a lot about EMV standards and related ISO 7816-4 standard but I am not able to execute simple select command with success. Here is some details:</p>
  
  <p>I have successfully powered my VISA card and get its attributes:</p>
  
  <pre><code>NSError *error = nil;
  GRGrabbaSmartcardSession *session = [GRGrabba.sharedGrabba.smartcard startSession:&amp;error];
  NSLog(@"EMV : smartCardInsertedEvent : Attribute : %@", [session getATR]);
  </code></pre>
  
  <p>Result: <code>3b690000 8072a445 6400ff00 10</code></p>
  
  <p>When I parse this attribute on <a href="http://www.ruimtools.com/atr.php" rel="nofollow noreferrer">here</a> I get this information for my card:</p>
  
  <p><a href="https://i.stack.imgur.com/iY8Ei.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iY8Ei.png" alt="Attribute parser result"></a></p>
  
  <p>My contactless card is a credit card from Akbank from Turkey but it is listed as a Denizbank card from Turkey in <a href="http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt" rel="nofollow noreferrer">this list</a>.</p>
  
  <p>Now I am tring to run a select command on card like this:</p>
  
  <pre><code>NSError *error = nil;
  GRGrabbaSmartcardSession *session = [GRGrabba.sharedGrabba.smartcard startSession:&amp;error];
  NSLog(@"EMV : smartCardInsertedEvent : Attribute : %@", [session getATR]);
  session.protocol = 1;
  uint8_t aid[] = {'2', 'P', 'A', 'Y', '.', 'S', 'Y', 'S', '.', 'D', 'D', 'F', '0', '1'};
  NSData *data = [NSData dataWithBytes:aid length:sizeof(aid)];
  NSError *err = nil;
  GRGrabbaCommandAPDU *apduCMD =
          [[GRGrabbaCommandAPDU alloc]
                  initWithCLA:0x00
                          INS:0xA4
                           P1:0x04
                           P2:0x00
                         Data:data
                           Le:0x00
                        Error:&amp;err];
  
  GRGrabbaResponseAPDU *response = [[GRGrabbaResponseAPDU alloc] initWithData:nil SW1:0 SW2:0];
  BOOL success = [session exchangeAPDUCommand:apduCMD withResponse:response error:&amp;error];
  
  if (!success) {
      NSLog(@"EMV : smartCardInsertedEvent : ERROR: Could not read ADF");
      return;
  }
  </code></pre>
  
  <p>But it is failing with could not read ADF error. Can anyone show me what am I doing wrong?</p>
  
  <p>UPDATE:</p>
  
  <p>I have tried following combinations but still not able to run select command with success:</p>
  
  <pre><code>PROTOCOL DATA           CLA     LE   STATUS
  0        1PAY.SYS.DDF01 0x00    -    unrecognised SW in response: SW1 = 61, SW2 = 52
  0        1PAY.SYS.DDF01 0x00    0x00 Smartcard protocol error.
  0        2PAY.SYS.DDF01 0x00    -    unrecognised SW in response: SW1 = 61, SW2 = 66
  0        2PAY.SYS.DDF01 0x00    0x00 Smartcard protocol error.
  0        1PAY.SYS.DDF01 0x80    -    card returned Incorrect application CLA - SW1 = 6E, SW2 = 00
  0        1PAY.SYS.DDF01 0x80    0x00 card returned Incorrect application CLA - SW1 = 6E, SW2 = 00
  0        2PAY.SYS.DDF01 0x80    -    card returned Incorrect application CLA - SW1 = 6E, SW2 = 00
  0        2PAY.SYS.DDF01 0x80    0x00 card returned Incorrect application CLA - SW1 = 6E, SW2 = 00
  1        1PAY.SYS.DDF01 0x00    -    unrecognised SW in response: SW1 = 00, SW2 = 00
  1        1PAY.SYS.DDF01 0x00    0x00 unrecognised SW in response: SW1 = 00, SW2 = 00
  1        2PAY.SYS.DDF01 0x00    -    unrecognised SW in response: SW1 = 00, SW2 = 00
  1        2PAY.SYS.DDF01 0x00    0x00 unrecognised SW in response: SW1 = 00, SW2 = 00
  1        1PAY.SYS.DDF01 0x80    -    unrecognised SW in response: SW1 = 00, SW2 = 00 
  1        1PAY.SYS.DDF01 0x80    0x00 unrecognised SW in response: SW1 = 00, SW2 = 00
  1        2PAY.SYS.DDF01 0x80    -    unrecognised SW in response: SW1 = 00, SW2 = 00
  1        2PAY.SYS.DDF01 0x80    0x00 unrecognised SW in response: SW1 = 00, SW2 = 00
  </code></pre>