title: Generate "GET PROCESSING OPTIONS" (GPO) for EMV card (APDU) by PDOL
body: <p>GPO Command is defined like this as an APDU command:</p>
  
  <pre><code>CLA INS P1 P2 Lc Data Le
  80  A8  00 00 Lc Data 00
  </code></pre>
  
  <p>So the missing parts is <strong>Lc</strong> &amp; <strong>Data</strong> which we have to compute from the <strong>PDOL</strong> (if it is given). If it is not given, we can use:</p>
  
  <pre><code>80 A8 00 00 02 8300 00
  </code></pre>
  
  <p>That works for mastercards, but for VISA I am given a PDOL &amp; trying to construct the missing APDU part (Lc &amp; Data).</p>
  
  <p><strong>STEP 1 - I get this PDOL from my EMV card:</strong></p>
  
  <pre><code>9F66049F02069F03069F1A0295055F2A029A039C019F3704
  </code></pre>
  
  <p><strong>STEP 2 - Splitting it up by commands:</strong></p>
  
  <pre><code>9F6604 9F0206 9F0306 9F1A02 9505 5F2A02 9A03 9C01 9F3704
  </code></pre>
  
  <p><strong>STEP 3 - Splitting it again by byte length:</strong></p>
  
  <pre><code>9F66 04 | 9F02 06 | 9F03 06 | 9F1A 02 | 95 05 | 5F2A 02 | 9A 03 | 9C 01 | 9F37 04
  </code></pre>
  
  <p><strong>STEP 4 - Gives the following commands (remove length):</strong></p>
  
  <p>Describes "What to be inserted"</p>
  
  <pre><code>9F66 | 9F02 | 9F03 | 9F1A | 95 | 5F2A | 9A | 9C | 9F37
  </code></pre>
  
  <p><strong>STEP 5 - And the following length for commands (remove commands):</strong></p>
  
  <p>Describes "Length for each command"</p>
  
  <pre><code>04 | 06 | 06 | 02 | 05 | 02 | 03 | 01 | 04
  </code></pre>
  
  <p><strong>STEP 6 - Assuming that length is given as 2-bit's will make us double this:</strong></p>
  
  <pre><code>8 | 12 | 12 | 4 | 10 | 4 | 6 | 2 | 8
  </code></pre>
  
  <p><strong>STEP 7 - Expected output should now look like:</strong></p>
  
  <pre><code>aaaaaaaa bbbbbbbbbbbb cccccccccccc dddd eeeeeeeeee ffff gggggg hh iiiiiiii
  </code></pre>
  
  <p><strong>STEP 8 - Looking up commands to find values:</strong></p>
  
  <pre><code>9F66 | 9F02 | 9F03 | 9F1A | 95 | 5F2A | 9A | 9C | 9F37
  </code></pre>
  
  <p><a href="https://www.emvlab.org/emvtags/show/t9F66/" rel="noreferrer">https://www.emvlab.org/emvtags/show/t9F66/</a> = Unknown (I Googled and found it is: 'Terminal Transaction Qualifiers' = TTQ)</p>
  
  <p><a href="https://www.emvlab.org/emvtags/show/t9F02/" rel="noreferrer">https://www.emvlab.org/emvtags/show/t9F02/</a> = Authorized amount</p>
  
  <p><a href="https://www.emvlab.org/emvtags/show/t9F03/" rel="noreferrer">https://www.emvlab.org/emvtags/show/t9F03/</a> = Secondary / cashback amount</p>
  
  <p><a href="https://www.emvlab.org/emvtags/show/t9F1A/" rel="noreferrer">https://www.emvlab.org/emvtags/show/t9F1A/</a> = ISO 3166 Terminal Country Code (TCC)</p>
  
  <p><a href="https://www.emvlab.org/emvtags/show/t95/" rel="noreferrer">https://www.emvlab.org/emvtags/show/t95/</a> = Terminal verification results (TVR)</p>
  
  <p><a href="https://www.emvlab.org/emvtags/show/t5F2A/" rel="noreferrer">https://www.emvlab.org/emvtags/show/t5F2A/</a> = ISO 4217 Currency Code (CC)</p>
  
  <p><a href="https://www.emvlab.org/emvtags/show/t9A/" rel="noreferrer">https://www.emvlab.org/emvtags/show/t9A/</a> = Transaction date YYMMDD</p>
  
  <p><a href="https://www.emvlab.org/emvtags/show/t9C/" rel="noreferrer">https://www.emvlab.org/emvtags/show/t9C/</a> = ISO 8583:1987 first 2 digits (type of transaction - TT)</p>
  
  <p><a href="https://www.emvlab.org/emvtags/show/t9F37/" rel="noreferrer">https://www.emvlab.org/emvtags/show/t9F37/</a> = Unpredictable Number (Random number for cryptogram - UN)</p>
  
  <p><strong>STEP 9 - Inserting obvios data:</strong></p>
  
  <pre><code>9F66 aaaaaaaa     TTQ      
  9F02 bbbbbbbbbbbb Amount   000000001000
  9F03 cccccccccccc Cashback 000000000000
  9F1A dddd         TCC
  95   eeeeeeeeee   TVR
  5F2A ffff         CC
  9A   gggggg       YYMMDD   190325
  9C   hh           TT
  9F37 iiiiiiii     UN       12121212
  </code></pre>
  
  <p><strong>STEP 10 - Terminal Transaction Qualifiers (TTQ):</strong></p>
  
  <p>(Supported terminal function settings)</p>
  
  <pre><code>9F66 a1 a2 a3 a4   
  
  A. a1 - Hex to binary -&gt; 00000000
  B. a2 - Hex to binary -&gt; 00000000
  C. a3 - Hex to binary -&gt; 00000000
  D. a4 - Hex to binary -&gt; 00000000 - RFU (Reserved Future Use)
  </code></pre>
  
  <p>Each zero can be switched on or off.</p>
  
  <pre><code>A. a1 (hex to binary gives 8 numbers)
  
    8. 0 - Contactless MSD          - Example: 0 - false
    7. 0 - Contactless VSDC         - Example: 1 - true
    6. 0 - Contactless qVSDC        - Example: 0 - false
    5. 0 - EMV contact chip         - Example: 1 - true
    4. 0 - Offline-only reader      - Example: 0 - false
    3. 0 - Online PIN               - Example: 0 - false
    2. 0 - Signature                - Example: 0 - false
    1. 0 - Offline data auth (ODA)  - Example: 1 - true
  </code></pre>
  
  <p>Example gives: 01010001. Binary to HEX -> <strong>51</strong></p>
  
  <pre><code>B. a2 (hex to binary gives 8 numbers)
  
    8. 0 - Require Online Crypt     - Example: 0 - false
    7. 0 - CVM required .           - Example: 0 - false
    6. 0 - Offline PIN support      - Example: 0 - false
    5. 0 - RFU(Reserved Future Use) - Example: 0 - false
    4. 0 - RFU(Reserved Future Use) - Example: 0 - false
    3. 0 - RFU(Reserved Future Use) - Example: 0 - false
    2. 0 - RFU(Reserved Future Use) - Example: 0 - false
    1. 0 - RFU(Reserved Future Use) - Example: 0 - false
  </code></pre>
  
  <p>Example gives: 00000000. Binary to HEX -> <strong>00</strong></p>
  
  <pre><code>C. a3 (hex to binary gives 8 numbers)
  
    8. 0 - Issuer update process    - Example: 0 - false
    7. 0 - Mobile functionality     - Example: 1 - true
    6. 0 - RFU(Reserved Future Use) - Example: 0 - false
    5. 0 - RFU(Reserved Future Use) - Example: 0 - false
    4. 0 - RFU(Reserved Future Use) - Example: 0 - false
    3. 0 - RFU(Reserved Future Use) - Example: 0 - false
    2. 0 - RFU(Reserved Future Use) - Example: 0 - false
    1. 0 - RFU(Reserved Future Use) - Example: 0 - false
  </code></pre>
  
  <p>Example gives: 01000000. Binary to HEX -> <strong>40</strong></p>
  
  <pre><code>D. a4 = RFU(Reserved Future Use) = 00000000 = 00
  </code></pre>
  
  <p>Gives: 00000000. Binary to HEX -> <strong>00</strong></p>
  
  <p>Putting HEX values together returns: TTQ = <strong>51004000</strong></p>
  
  <p><strong>STEP 11 - Update ISO values (Google it) and insert TTQ:</strong></p>
  
  <p>Ref: <a href="https://en.wikipedia.org/wiki/ISO_8583" rel="noreferrer">https://en.wikipedia.org/wiki/ISO_8583</a></p>
  
  <pre><code>TT
  Authorization:   00
  Balance inquiry: 31
  Sale:            00
  Cash:            01
  Void:            02
  Mobile topup:    57
  
  9F66 aaaaaaaa     TTQ      51004000     TTQ
  9F02 bbbbbbbbbbbb Amount   000000001000
  9F03 cccccccccccc Cashback 000000000000
  9F1A dddd         TCC      0578         ISO 3166 Norway (not same as phone)
  95   eeeeeeeeee   TVR
  5F2A ffff         CC       0978         ISO 4217 Euro
  9A   gggggg       YYMMDD   190325
  9C   hh           TT       00           ISO 8583:1987 first 2 digits
  9F37 iiiiiiii     UN       12121212
  </code></pre>
  
  <p><strong>STEP 12 - Terminal verification results (TVR):</strong></p>
  
  <p><a href="https://en.wikipedia.org/wiki/Terminal_verification_results" rel="noreferrer">https://en.wikipedia.org/wiki/Terminal_verification_results</a></p>
  
  <pre><code>9F66 e1 e2 e3 e4 e5 
  
  A. e1 - Hex to binary -&gt; 00000000
  B. e2 - Hex to binary -&gt; 00000000
  C. e3 - Hex to binary -&gt; 00000000
  D. e4 - Hex to binary -&gt; 00000000
  E. e5 - Hex to binary -&gt; 00000000
  </code></pre>
  
  <p>Each zero can be switched on or off.</p>
  
  <pre><code>A. e1 (hex to binary gives 8 numbers)
  
    8. 0 - Offline process not performed - Example: 0 - false
    7. 0 - SDA failed                    - Example: 0 - false
    6. 0 - ICC data missing              - Example: 0 - false
    5. 0 - Card number on hotlist        - Example: 0 - false
    4. 0 - DDA failed                    - Example: 0 - false
    3. 0 - CDA failed                    - Example: 0 - false
    2. 0 - RFU (SDA was selected)        - Example: 0 - false
    1. 0 - RFU                           - Example: 0 - false
  </code></pre>
  
  <p>Example gives: 00000000. Binary to HEX -> <strong>00</strong></p>
  
  <pre><code>B. e2 (hex to binary gives 8 numbers)
  
    8. 0 - Card/terminal version differ. - Example: 0 - false
    7. 0 - Expired app                   - Example: 0 - false
    6. 0 - App not yet effective         - Example: 0 - false
    5. 0 - Service not allowed for card  - Example: 0 - false
    4. 0 - New card                      - Example: 0 - false
    3. 0 - RFU(Reserved Future Use)      - Example: 0 - false
    2. 0 - RFU(Reserved Future Use)      - Example: 0 - false
    1. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  </code></pre>
  
  <p>Example gives: 00000000. Binary to HEX -> <strong>00</strong></p>
  
  <pre><code>C. e3 (hex to binary gives 8 numbers)
  
    8. 0 - Cardholder verification fail  - Example: 0 - false
    7. 0 - Unrecognised CVM              - Example: 0 - false
    6. 0 - PIN try limit exceeded        - Example: 0 - false
    5. 0 - PIN required, but no pinpad   - Example: 0 - false
    4. 0 - PIN req. &amp; present &amp; missing  - Example: 0 - false
    3. 0 - On-line PIN entered           - Example: 0 - false
    2. 0 - RFU(Reserved Future Use)      - Example: 0 - false
    1. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  </code></pre>
  
  <p>Example gives: 00000000. Binary to HEX -> <strong>00</strong></p>
  
  <pre><code>D. e4 (hex to binary gives 8 numbers)
  
    8. 0 - Transact. exceeds floor limit - Example: 0 - false
    7. 0 - Lower offline limit exceeded  - Example: 0 - false
    6. 0 - Upper offline limit exceeded  - Example: 0 - false
    5. 0 - Transa. randomly sele. online - Example: 0 - false
    4. 0 - Merch. forced online transac. - Example: 0 - false
    3. 0 - RFU(Reserved Future Use)      - Example: 0 - false
    2. 0 - RFU(Reserved Future Use)      - Example: 0 - false
    1. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  </code></pre>
  
  <p>Example gives: 00000000. Binary to HEX -> <strong>00</strong></p>
  
  <pre><code>E. e5 (hex to binary gives 8 numbers)
  
    8. 0 - Default TDOL Used             - Example: 0 - false
    7. 0 - Issuer authentication failed  - Example: 0 - false
    6. 0 - Script fail before final GAC  - Example: 0 - false
    5. 0 - Script fail after final GAC   - Example: 0 - false
    4. 0 - RFU(Reserved Future Use)      - Example: 0 - false
    3. 0 - RFU(Reserved Future Use)      - Example: 0 - false
    2. 0 - RFU(Reserved Future Use)      - Example: 0 - false
    1. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  </code></pre>
  
  <p>Example gives: 00000000. Binary to HEX -> <strong>00</strong></p>
  
  <p>Putting all HEX values together gives: TVR = <strong>0000000000</strong></p>
  
  <p><strong>STEP 13 - Final Command:</strong></p>
  
  <pre><code>9F66 aaaaaaaa     TTQ      51004000
  9F02 bbbbbbbbbbbb Amount   000000001000
  9F03 cccccccccccc Cashback 000000000000
  9F1A dddd         TCC      0578
  95   eeeeeeeeee   TVR      0000000000
  5F2A ffff         CC       0978
  9A   gggggg       YYMMDD   190325
  9C   hh           TT       00
  9F37 iiiiiiii     UN       12121212
  </code></pre>
  
  <p>Results in:</p>
  
  <pre><code>51004000 000000001000 000000000000 0578 0000000000 0978 190325 00 12121212
  </code></pre>
  
  <p><strong>STEP 14 - Get tag length value:</strong></p>
  
  <p>Get length of results:
      510040000000000010000000000000000578000000000009781903250012121212
      = 66 numbers
      It is 2-bits, so:
      66 / 2 = 33 characters</p>
  
  <pre><code>Convert 33 to HEX = 21
  </code></pre>
  
  <p>tlv = <strong>21</strong></p>
  
  <p>tlv should be applied before the results from step 13:</p>
  
  <pre><code>21 510040000000000010000000000000000578000000000009781903250012121212
  </code></pre>
  
  <p><strong>STEP 15 - Add the GPO Tag which is "83":</strong></p>
  
  <pre><code>83 21 510040000000000010000000000000000578000000000009781903250012121212
  </code></pre>
  
  <p>So, <strong>Data</strong> = <strong>8321510040000000000010000000000010000578000000000009781903250012121212</strong></p>
  
  <p><strong>STEP 16 - Get tag length value for whole command (Lc):</strong></p>
  
  <p>Get length of results:</p>
  
  <pre><code>8321510040000000000010000000000000000578000000000009781903250012121212
  = 70 numbers
  It is 2-bits, so:
  70 / 2 = 35 characters
  
  Convert 35 to HEX = 23
  
  Lc = 23
  </code></pre>
  
  <p><strong>STEP 17 - Putting it all together:</strong></p>
  
  <p>Remember that the missing part is <em>Lc</em> &amp; <em>Data</em></p>
  
  <pre><code>CLA INS P1 P2 Lc Data Le
  80  A8  00 00 Lc Data 00
  80  A8  00 00 23 Data 00
  </code></pre>
  
  <p>Adding Data:</p>
  
  <pre><code>APDU =
  80A8000023832151004000000000001000000000000000057800000000000978190325001212121200
  </code></pre>
  
  <p><strong>QUESTION</strong></p>
  
  <p>The final apdu command I generated returns <strong>no value</strong>.
  Does anyone know at which step I fall out or can see what I am doing wrong?</p>
  
  <p><strong>Resources:</strong></p>
  
  <p><a href="https://www.emvlab.org/emvtags/" rel="noreferrer">https://www.emvlab.org/emvtags/</a></p>
  
  <p><a href="https://en.wikipedia.org/wiki/Terminal_verification_results" rel="noreferrer">https://en.wikipedia.org/wiki/Terminal_verification_results</a></p>
  
  <p><a href="https://www.rapidtables.com/convert/number/decimal-to-hex.html" rel="noreferrer">https://www.rapidtables.com/convert/number/decimal-to-hex.html</a></p>
  
  <p><a href="https://tvr-decoder.appspot.com/t/home" rel="noreferrer">https://tvr-decoder.appspot.com/t/home</a></p>
  
  <p><a href="https://stackoverflow.com/questions/34519566/parsing-pdol-for-get-processing-options-command-in-emv-transaction">Parsing PDOL for GET PROCESSING OPTIONS command in EMV transaction</a></p>
  
  <p><a href="https://stackoverflow.com/questions/23590256/getting-parser-error-on-request-for-gpo-command-for-emv-card/23591064#23591064">Getting Parser error on request for GPO command for EMV card</a></p>
  
  <p><a href="https://www.iban.com/currency-codes" rel="noreferrer">https://www.iban.com/currency-codes</a></p>
  
  <p><a href="https://www.iban.com/country-codes" rel="noreferrer">https://www.iban.com/country-codes</a></p>
  
  <p><a href="http://www.emvlab.org/tlvutils/" rel="noreferrer">http://www.emvlab.org/tlvutils/</a></p>