home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / phrack2 / p48_10.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  38.5 KB  |  1,041 lines

  1.                               ==Phrack Magazine==
  2.  
  3.                  Volume Seven, Issue Forty-Eight, File 10 of 18
  4.  
  5.  
  6.               Electronic Telephone Cards: How to make your own!
  7.               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8.  
  9. I guess that Sweden is not the only country that employs the electronic
  10. phone card systems from Schlumberger Technologies. This article will
  11. explain a bit about the cards they use, and how they work. In the end of
  12. this article you will also find an UUEncoded file which contains source
  13. code for a PIC16C84 micro-controller program that completely emulates a
  14. Schlumberger Telephone card and of course printed circuit board layouts
  15. + a component list... But before we begin talking seriously of this
  16. matter I must first make it completely clear that whatever you use this
  17. information for, is entirely YOUR responsibility, and I cannot be held
  18. liable for any problems that the use of this information can cause for
  19. you or for anybody else. In other words: I give this away FOR FREE, and
  20. I don't expect to get ANYTHING back in return!
  21.  
  22. The Original Telephone Card:
  23. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. Since I probably would have had a hard time writing a better article
  25. than the one Stephane Bausson from France wrote a while ago, I will not
  26. attempt to give a better explanation than that one; I will instead
  27. incorporate it in this phile, but I do want to make it clear that the
  28. following part about the cards technical specification was not written
  29. by me: Merely the parts in quotes are things added by me... Instead I
  30. will concentrate on explaining how to build your own telephone card
  31. emulator and how the security measures in the payphone system created by
  32. Schlumberger Technologies work, and how to trick it... But first, let's
  33. have a look at the technical specifications of the various "smart memory
  34. card" systems used for the payphones.
  35.  
  36.  
  37. <Start of text quoted from Stephane Bausson (sbausson@ensem.u-nancy.fr)>
  38. ------------------------------------------------------------------------------
  39.  
  40. ===============================================================================
  41.           What you need to know about electronics telecards
  42. ===============================================================================
  43.  
  44. (C) 10-07-1993 / 03-1994
  45. Version 1.06
  46. Stephane BAUSSON
  47.  
  48. Email: sbausson@ensem.u-nancy.fr
  49. Smail: 4, Rue de Grand; F-88630 CHERMISEY; France
  50. Phone: (33)-29-06-09-89
  51. -------------------------------------------------------------------------------
  52.     Any suggestions or comments about phonecards and smart-cards are welcome
  53. -------------------------------------------------------------------------------
  54.  
  55.                   Content
  56.                  ---------
  57.  
  58. I ) The cards from Gemplus, Solaic, Schlumberger, Oberthur:
  59.  
  60.     I-1) Introduction:
  61.     I-2) SCHEMATICS of the chip:
  62.     I-3) PINOUT of the connector:
  63.     I-4) Main features:
  64.     I-5) TIME DIAGRAMS:
  65.     I-6) Memory MAP of cards from France and Monaco:
  66.     I-5) Memory MAP of cards from other countries:
  67.  
  68. II ) The cards from ODS: (German cards)
  69.  
  70.     II-1) Introduction:
  71.     II-2) Pinout:
  72.     II-3) Main features:
  73.     II-4) Time Diagrams:
  74.     II-5) Memory Map:
  75.     II-6) Electrical features:
  76.  
  77.  
  78. III) The Reader Schematic:
  79.  
  80. IV) The program:
  81.  
  82. -------------------------------------------------------------------------------
  83.  
  84. I ) The cards from Gemplus, Solaic, Schlumberger, Oberthur: (French cards)
  85.     ======================================================================
  86.  
  87.     I-1) Introduction:
  88.      ------------
  89.  
  90.        You must not think that the electronics phone-cards are
  91. completely secret things, and that you can not read the information that
  92. is inside. It is quite false, since in fact an electronic phonecard does
  93. not contain any secret information like credit cards, and an electronic
  94. phonecard is nothing else than a 256 bit EPROM with serial output.
  95.  
  96.        Besides do not think that you are going to refill them when you
  97. understand how they work, since for that you should reset the 256 bits
  98. of the cards by erasing the whole card. But the chip is coated in UV
  99. opaqued resin even if sometimes you can see it as transparent! Even if
  100. you were smart enough to erase the 256 bits of the card you should
  101. program the manufacturer area, but this is quite impossible since these
  102. first 96 bits are write protected by a lock-out fuse that is fused after
  103. the card programming in factory.
  104.  
  105.        Nevertheless it can be very interesting to study how these cards
  106. work, to see which kind of data are inside and how the data are mapped
  107. inside or to see how many units are left inside for example. Besides
  108. there are a great number of applications of these cards when there are
  109. used (only for personal usage of course) , since you can use them as key
  110. to open a door, or you can also use them as key to secure a program,
  111. etc...
  112.  
  113.        These Telecards have been created in 1984 and at this time
  114. constructors decided to build these cards in NMOS technology but now,
  115. they plan to change by 1994 all readers in the public to booths and use
  116. CMOS technology. Also they plan to use EEPROM to secure the cards and to
  117. add many useful informations in, and you will perhaps use phone cards to
  118. buy you bread or any thing else.
  119.  
  120. These cards are called Second Generation Telecards.
  121.  
  122.  
  123.     I-2) SCHEMATICS of the chip:
  124.      ----------------------
  125.  
  126.             .-------------------.
  127.             |                   |
  128.           --|> Clk              |
  129.             | _                 |
  130.           --| R/W               |
  131.             |                   |
  132.           --| Reset             |
  133.             |                   |
  134.           --| Fuse              |
  135.             |                   |
  136.           --| Vpp               |
  137.             |                   |
  138.             |                   |
  139.             '-.               .-'
  140.               |               |
  141.             .-------------------.
  142.             |               Out |-- serial output
  143.             '-------------------'
  144.  
  145.  
  146.     I-3) PINOUT of the connector:
  147.     -------------------------
  148.  
  149.  
  150.       AFNOR CHIP                                   ISO CHIP
  151.       ----------                                   --------
  152.  
  153.  -------------+-------------                 -------------+-------------
  154. |   8         |         4   |               |   1         |         5   |
  155. |             |             |               |             |             |
  156. +-------\     |     /-------+               +-------\     |     /-------+
  157. |   7    +----+----+    3   |               |   2    +----+    +    6   |
  158. |        |         |        |               |        |         |        |
  159. +--------|         |--------+               +--------|         |--------+
  160. |   6    |         |    2   |               |   3    |         |    7   |
  161. |        +    +----+        |               |        +----+----+        |
  162. +-------/     |     \-------+               +-------/     |     \-------+
  163. |   5         |         1   |               |   4         |         8   |
  164. |             |             |               |             |             |
  165.  -------------+-------------                 -------------+-------------
  166.  
  167.                      NB: only the position of the chip is ISO
  168.                      standardized and not the pinout
  169.  
  170. PINOUT:    1 : Vcc = 5V        5 : Gnd
  171. ------     2 : R/W             6 : Vpp = 21V
  172.        3 : Clock           7 : I/O
  173.        4 : Reset           8 : Fuse
  174.  
  175.     I-4) Main features:
  176.     ---------------
  177.  
  178.     - Synchronous protocol.
  179.     - N-MOS technology.
  180.     - 256x1 bit organization.
  181.     - 96 written protected by a lock-out fuse.
  182.     - Low power 85mW in read mode.
  183.     - 21 V programming voltage.
  184.     - Access time: 500ns
  185.     - Operating range: -100C +700C
  186.     - Ten year data retention.
  187.  
  188.  
  189.     I-5) TIME DIAGRAMS:
  190.     ---------------
  191.  
  192. +21V                                     _____________
  193. +5V ____________________________________|             |_________________ Vpp
  194.                     :             :
  195. +5V                  ___________________:_____________:_________________ Reset
  196. 0V  ________________|                   :             :
  197.             :                   :             :
  198. +5V     ____        :      ____         :       ______:______
  199. 0V  ___|    |_______:_____|    |________:______|      :      |__________ Clock
  200.        :    :       :     :    :        :      :      :      :
  201. +5V    :    :       :     :    :        :______:______:      :           _
  202. 0V  ___:____:_______:_____:____:________|      :      |______:__________ R/W
  203.        :    :       :     :    :        :      :      :      :
  204. +5V    :    :       :_____:    :________:      :      :      :__________
  205. 0V  XXXXXXXXXXXXXXXXX_____XXXXXX________XXXXXXXXXXXXXXXXXXXXXX__________ Out
  206.        :    :       :     :    :        :<-----><---->:      :
  207.        :    :       :     :    :        :10 to   10 to       :
  208.        :    :       :     :    :        :50 ms   50ms        :
  209.     Reset        Bit 1        Bit2                           Bit 3
  210.     card        reading      reading  Bit2 writing to 1     reading
  211.  
  212.  
  213.  
  214.     I-6) MEMORY MAP of cards from France and Monaco:
  215.     --------------------------------------------
  216.  
  217. Bytes       Bits      Binary     Hexa
  218.  
  219.             +-----------+-----+
  220.   1        1 --> 8  |           |     | ---> Builder code.
  221.             +-----------+-----+
  222.   2       9 --> 16  | 0000 0011 | $03 | ---> a French telecard
  223.             +-----------+-----+
  224.   3      17 --> 24  |           |     |
  225.             +-----------+-----+
  226.   4      25 --> 32  |           |     |
  227.             +-----------+-----+
  228.   5      33 --> 40  |           |     |
  229.             +-----------+-----+
  230.   6      41 --> 48  |           |     |
  231.             +-----------+-----+
  232.   7      49 --> 56  |           |     |
  233.             +-----------+-----+
  234.   8      57 --> 64  |           |     |
  235.             +-----------+-----+
  236.   9      65 --> 72  |           |     |
  237.             +-----------+-----+
  238.  10      73 --> 80  |           |     |
  239.             +-----------+-----+
  240.  11      81 --> 88  |           |     |
  241.             +-----------+-----+
  242.  12      33 --> 40  | 0001 0011 | $13 | ---> 120 units card
  243.             | 0000 0110 | $06 | --->  50 units card
  244.             | 0000 0101 | $05 | --->  40 units card
  245.             +-----------+-----+
  246.  13-31  97 --> 248  |           |     | ---> The units area: each time a unit
  247.             |           |     |      is used, then a bit is set to "1";
  248.                     |           |     |      Generally the first ten units are
  249.             |           |     |      fused in factory as test.
  250.             |           |     |
  251.             |           |     |
  252.             |           |     |
  253.             +-----------+-----+
  254.  32    249 --> 256  | 1111 1111 | $FF | ---> the card is empty
  255.             +-----------+-----+
  256.  
  257.  
  258.  
  259.     I-7) MEMORY MAP of the other cards:
  260.     -------------------------------
  261.  
  262. Bytes       Bits      Binary     Hexa
  263.  
  264.             +-----------+-----+
  265.   1        1 --> 8  |           |     |
  266.             +-----------+-----+
  267.   2       9 --> 16  | 1000 0011 | $83 | ---> a telecard
  268.             +-----------+-----+-----------+-----+
  269. 3-4      17 --> 32  | 1000 0000 | $80 | 0001 0010 | $12 | ---> 10 units card
  270.             |           |     | 0010 0100 | $24 | ---> 22 units card
  271.             |           |     | 0010 0111 | $27 | ---> 25 units card
  272.             |           |     | 0011 0010 | $32 | ---> 30 units card
  273.             |           |     | 0101 0010 | $52 | ---> 50 units card
  274.             |           |     | 1000 0010 | $82 | ---> 80 units card
  275.             | 1000 0001 | $81 | 0000 0010 | $02 | ---> 100 units card
  276.             |           |     | 0101 0010 | $52 | ---> 150 units card
  277.             +-----------+-----+-----------+-----+
  278.   5      33 --> 40  |           |     |
  279.             +-----------+-----+
  280.   6      41 --> 48  |           |     |
  281.             +-----------+-----+
  282.   7      49 --> 56  |           |     |
  283.             +-----------+-----+
  284.   8      57 --> 64  |           |     |
  285.             +-----------+-----+
  286.   9      65 --> 72  |           |     |
  287.             +-----------+-----+
  288.  10      73 --> 80  |           |     |
  289.             +-----------+-----+
  290.  11      81 --> 88  |           |     |
  291.             +-----------+-----+
  292.  12      89 --> 96  | 0001 1110 | $1E | ---> Sweden
  293.             | 0010 0010 | $22 | ---> Spain
  294.             | 0011 0000 | $30 | ---> Norway
  295.             | 0011 0011 | $33 | ---> Andorra
  296.             | 0011 1100 | $3C | ---> Ireland
  297.             | 0100 0111 | $47 | ---> Portugal
  298.             | 0101 0101 | $55 | ---> Czech Republic
  299.             | 0101 1111 | $5F | ---> Gabon
  300.             | 0110 0101 | $65 | ---> Finland
  301.             +-----------+-----+
  302.  13-31  97 --> 248  |           |     | ---> The units area: each time a unit
  303.             |           |     |      is used, then a bit is set to "1";
  304.             |           |     |
  305.             |           |     |      Generally the first two units are
  306.             |           |     |      fused in factory as test.
  307.             |           |     |
  308.             |           |     |
  309.             +-----------+-----+
  310.  32    249 --> 256  | 0000 0000 | $00 |
  311.             +-----------+-----+
  312.  
  313.  
  314.  
  315. II ) The cards from ODS, Giesecke & Devrient, ORGA Karten systeme,
  316.      =============================================================
  317.      Uniqua, Gemplus, Schlumberger and Oldenbourg Kartensysteme:
  318.      ===========================================================
  319.  
  320.     II-1) Introduction:
  321.       ------------
  322.  
  323.         These cards are in fact 128 bit memory in NMOS technology, and
  324. the map of these cards are the following:
  325.  
  326.            64 bit EPROM written protected (manufacturer area).
  327.            40 bit EEPROM (5x8 bits).
  328.            24 bits set to "1".
  329.  
  330.  
  331.     II-2) Pinout:
  332.      --------
  333.  
  334.        ISO 7816-2
  335.  
  336.   -------------+-------------
  337.  |   1         |         5   |        Pinout:
  338.  |             |             |        -------
  339.  +-------\     |     /-------+
  340.  |   2    +----+    +    6   |          1 : Vcc = 5V    5 : Gnd
  341.  |        |         |        |          2 : Reset       6 : n.c.
  342.  +--------|         |--------+          3 : Clock       7 : I/O
  343.  |   3    |         |    7   |          4 : n.c.        8 : n.c.
  344.  |        +----+----+        |
  345.  +-------/     |     \-------+      n.c. : not connected
  346.  |   4         |         8   |
  347.  |             |             |
  348.   -------------+-------------
  349.  
  350.  
  351.     II-3) Main features:
  352.      ---------------
  353.  
  354.     - ISO 7816- 1/2 compatible.
  355.     - use a single 5V power supply.
  356.     - low power consumption.
  357.     - NMOS technology.
  358.  
  359.     II-4) Time Diagrams:
  360.     ----------------
  361.  
  362. Reset:
  363. ------
  364.   The address counter is reset to 0 when the clock line CLK is raised
  365. while the control line R is high. Note that the address counter can not
  366. be reset when it is in the range 0 to 7.
  367.  
  368.       __________________
  369. _____|                  |_____________________________________________ Reset
  370.      :                  :
  371.      :        _____     :  _____       _____       _____       _____
  372. _____:_______|     |____:_|     |_____|     |_____|     |_____|     |_ Clk
  373.      :       :          : :     :     :     :     :     :     :     :
  374. _____:_______:__________:_:_____:_____:_____:_____:_____:_____:_____:_
  375. _____:___n___|_____0____:_|_____1_____|_____2_____|_____3_____|___4_:_ (Address)
  376.      :                  :       :           :           :           :
  377. _____:                  :_______:___________:___________:___________:_
  378. _____XXXXXXXXXXXXXXXXXXXX_______|___________|___________|___________|_ Data
  379. Bit n                      Bit 0    Bit 1        Bit2       Bit3
  380.  
  381.    The address counter is incremented by 1 with each rising edge of the
  382. clock signal Clk, for as long as the control line R remains low. The
  383. data held in each addressed bit is output to I/O contact each time Clk
  384. falls. It is not impossible to decrement the address counter, therefore
  385. to address an earlier bit, the address counter must be reset then
  386. incremented to require value.
  387.  
  388.  
  389. Write:
  390. ------
  391.    All unwritten or erased bits in the address 64-104 may be unwritten
  392. to. When a memory cell is unwritten to, it is set to 0. The addressed
  393. cell is unwritten to by the following sequence.
  394.  
  395. 1- R is raised while Clk is low, to disable address counter increment
  396. for one clock pulse.
  397.  
  398. 2- Clk is then raised for a minimum of 10ms to write to the address bit.
  399.  
  400. When to write operation ends, and Clk falls, the address counter is
  401. unlocked, and the content of the written cell, which is now 0, is output
  402. to I/O contact if the operation is correct.
  403.  
  404. The next Clk pulse will increment the address by one, then the write
  405. sequence can be repeated to write the next bit.
  406.  
  407.           _____                                _____
  408. ____________|     |______________________________|     |_______________ Reset
  409.             :                                    :
  410.     ___     :           _____           ___      :           _____
  411. ___|   |____:__________|     |_________|   |_____:__________|     |____ Clk
  412.    :        :          :     :         :   :     :          :     :
  413. ___:________:__________:_____:_________:___:_____:__________:_____:_____
  414. n  |      n+1          |     n+2       |   :    n+3         |     :      (Addr)
  415. ---'--------:----------'-----:---------'---:-----:----------'-----:-----
  416.             :          :     :             :     :          :     :
  417. ________   _:          :     : ____________:  ___:          :     :
  418. ________XXX_XXXXXXXXXXXXXXXXXXX____________ XX___XXXXXXXXXXXXXXXXXXXXXXX I/O
  419.   n      n+1           :     :     n+1        n+2           :     :
  420.                        :     :                              :     :
  421.                         write                                write
  422.  
  423.  
  424. WriteCarry:
  425. -----------
  426.  
  427.    A counter is erased by performing the WRITECARRY sequence on the
  428. stage of the next highest weighing to that to be erased.
  429.  
  430. The writecarry sequence is as follows:
  431.  
  432. 1 - Set the address counter to an unwritten bit in the next highest
  433. counter stage to that to be erased.
  434.  
  435. 2 - Increment is disabled on the following rising edge of R where Clk
  436. remains low.
  437.  
  438. 3 - Clk is then raised for a minimum of 10ms, while R is low, to write
  439. to the next address bit.
  440.  
  441. 4 - R is the raised again while Clk remains low to disable increment a
  442. second time.
  443.  
  444. 5 - Clk is the raised for a minimum of 1ms, while R is low, to write to
  445. the addressed bit a second time, erasing the counter level immediately
  446. below that the addressed bit.
  447.  
  448.        _____                      _____
  449. ______|     |____________________|     |_________________________________  Rst
  450.       :                          :
  451.       :            _______       :              _______        ___
  452. ______:___________|       |______:_____________|       |______|   |______  Clk
  453.       :           :       :      :             :       :      :   :
  454.       :           :       :      :             :       :      :   :
  455. <------------------------- address n ------------------------>:<--- n+1 ------
  456.       :           :       :      :             :       :          :
  457.       :           :       :      :             :       :          :
  458. ______:           :       :______:             :       :__________: _____
  459. ______XXXXXXXXXXXXXXXXXXXXX______XXXXXXXXXXXXXXXXXXXXXXX__________XX_____  I/O
  460.           :       :  n                 :       :     n        n+1
  461.           :       :                    :       :
  462.             Write                        Erase
  463.  
  464.      II-5) Memory Map:
  465.      -------------
  466.  
  467. Bytes       Bits      Binary     Hexa
  468.  
  469.             +-----------+-----+
  470.   1       1 -->   8 |           |     |
  471.             +-----------+-----+
  472.   2       9 -->  16 | 0010 1111 | $2F | ---> Germany
  473.             | 0011 0111 | $37 | ---> Netherland
  474.             | 0011 1011 | $3B | ---> Greece
  475.             +-----------+-----+
  476.   3      17 -->  24 |           |     |
  477.   4      25 -->  32 |           |     | ---> Issuer area (written protected)
  478.   5      33 -->  40 |           |     |
  479.   6      41 -->  48 |           |     |
  480.   7      49 -->  56 |           |     |
  481.   8      57 -->  64 |           |     |
  482.             +-----------+-----+
  483.   9      65 -->  72 |           |     | ---> c4096  )
  484.  10      73 -->  80 |           |     | --->  c512  )
  485.  11      81 -->  88 |           |     | --->   c64  ) 5 stage octal counter
  486.  12      89 -->  96 |           |     | --->    c8  )
  487.  13      97 --> 104 |           |     | --->    c0  )
  488.             +-----------+-----+
  489.  14     105 --> 112 | 1111 1111 | $FF |
  490.  15     113 --> 120 | 1111 1111 | $FF | ---> area of bits set to "1"
  491.  16     120 --> 128 | 1111 1111 | $FF |
  492.             +-----------+-----+
  493.  
  494. The Issuer area:
  495. ----------------
  496.  
  497.     This issuer consists of 40 bits. The contents of the issuer area are
  498. specified by the card issuer, and are fixed during the manufacturing
  499. process. The contents of the issuer area will include data such as
  500. serial numbers, dates, and distribution centers.
  501.  
  502. This area may only be read.
  503.  
  504. The Counter area:
  505. -----------------
  506.  
  507.    The counter area stores the card's units. Its initial value is
  508. specified by the card issuer and set during manufacturing.
  509.  
  510. The counter area is divided into a 5 stage abacus.
  511.  
  512. Note that you can only decrease the counter and it is not authorized to
  513. write in the counter a value greater than the old value.
  514.  
  515.  
  516.     I-6) Electrical features:
  517.     --------------------
  518.  
  519. Maximum ratings:
  520. ----------------
  521.  
  522.                +--------+------+------+------+
  523.                | Symbol | Min  |  Max | Unit |
  524. +----------------------+--------+------+------+------+
  525. | Supply voltage       |   Vcc  | -0.3 |    6 |   V  |
  526. +----------------------+--------+------+------+------+
  527. | Input voltage        |   Vss  | -0.3 |    6 |   V  |
  528. +----------------------+--------+------+------+------+
  529. | Storage temperature  |  Tstg  |  -20 |  +55 |  0C  |
  530. +----------------------+--------+------+------+------+
  531. | Power dissipation   |    Pd  |   -  |   50 |  mW  |
  532. +----------------------+--------+------+------+------+
  533.  
  534.  
  535. DC characteristics:
  536. ------------------
  537.                 +--------+-----+-----+-----+------+
  538.                 | Symbol | Min.| Typ.| Max.| Unit |
  539. +---------------------------+--------+-----+-----+-----+------+
  540. | Supply current            |   Icc  |  -  |  -  |   5 |   mA |
  541. +---------------------------+--------+-----+-----+-----+------+
  542. | Input Voltage (low)       |    Vl  |   0 |  -  | 0.8 |    V |
  543. +---------------------------+--------+-----+-----+-----+------+
  544. | Input voltage (high)      |    Vh  | 3.5 |  -  | Vcc |    V |
  545. +---------------------------+--------+-----+-----+-----+------+
  546. | Input current R           |    Ih  |  -  |  -  | 100 |   uA |
  547. +---------------------------+--------+-----+-----+-----+------+
  548. | Input current Clk         |    Il  |  -  |  -  | 100 |   uA |
  549. +---------------------------+--------+-----+-----+-----+------+
  550. | Output current (Vol=0.5V) |   Iol  |  -  |  -  |  10 |   uA |
  551. +---------------------------+--------+-----+-----+-----+------+
  552. | Output current (Voh=5V)   |   Ioh  |  -  |  -  | 0.5 |   mA |
  553. +---------------------------+--------+-----+-----+-----+------+
  554.  
  555. AC characteristics:
  556. ------------------     +--------+------+------+------+
  557.                | Symbol | Min. | Max. | Unit |
  558. +----------------------+--------+------+------+------+
  559. | Pulse duration       |    tr  |   50 |   -  |  us  |
  560. | R address reset      |        |      |      |      |
  561. +----------------------+--------+------+------+------+
  562. | Pulse duration       |    ts  |   10 |   -  |  us  |
  563. | R write              |        |      |      |      |
  564. +----------------------+--------+------+------+------+
  565. | High level Clk       |    th  |    8 |   -  |  us  |
  566. +----------------------+--------+------+------+------+
  567. | Low level Clk        |    tl  |   12 |   -  |  us  |
  568. +----------------------+--------+------+------+------+
  569. | Write window         | Twrite |   10 |   -  |  ms  |
  570. +----------------------+--------+------+------+------+
  571. | Erase window         | Terase |   10 |   -  |  ms  |
  572. +----------------------+--------+------+------+------+
  573. |                      |   tv1  |    5 |   -  |  us  |
  574. +----------------------+--------+------+------+------+
  575. |                      |   tv2  |  3.5 |   -  |  us  |
  576. +----------------------+--------+------+------+------+
  577. |                      |   tv3  |  3.5 |   -  |  us  |
  578. +----------------------+--------+------+------+------+
  579. |                      |   tv4  |  3.5 |   -  |  us  |
  580. +----------------------+--------+------+------+------+
  581. |                      |   tv5  |  3.5 |   -  |  us  |
  582. +----------------------+--------+------+------+------+
  583. |                      |   tv6  |    5 |   -  |  us  |
  584. +----------------------+--------+------+------+------+
  585. |                      |   tv7  |    5 |   -  |  us  |
  586. +----------------------+--------+------+------+------+
  587. |                      |   tv8  |   10 |   -  |  us  |
  588. +----------------------+--------+------+------+------+
  589.  
  590.  
  591.  
  592. III) The Reader Schematic:
  593.     ======================
  594.  
  595.    External 5V (Optional)
  596.  
  597. 5V o------,
  598.       |                 /             T2  PNP      d13  r7 10
  599. 0V o--,   |                /               BC 177     |\ |  _____
  600.       |   |      ,-------o/   o--*------. E      C .--| >+-[_____]--------,
  601.     __+__ |      |               |       \        /   |/ |                |
  602.     \\\\\ |    __|__ Battery     |         \    /                         |
  603.       |      -   22.5V       |       ---------                        |
  604. .......   |      |               |   _____   |   _____                    |
  605.        :  |    __+__             +--[_____]--*--[_____]--,                |
  606.    D2  :  |    \\\\\                r6 150k     r5 15k   |                |
  607. 4 o-------|---------------------------*------------------|-------------,  |
  608.        :  |                           |   r3 220k       / C            |  |
  609.    Ack :  |                           |   _____      |/    T1 - NPN    |  |
  610. 10 o------|--------.                  '--[_____]-*---|      BC107      |  |
  611.        :  |        |                      _____  |   |\                |  |
  612.        : ,-,      ,-,                 +--[_____]-'      \ E            |  |
  613.        : | |r2    | |r1               |  r4 390k         |             |  |
  614.        : | |220   | |22k            __+__              __+__           |  |
  615.        : |_|      |_|               \\\\\              \\\\\           |  |
  616.        :  |  |\ |  |                                                   |  |
  617.        :  *--| >+--|----------------*----------------------------------|--*
  618.        :  |  |/ |  |          ,-----|-----------------------------,    |  |
  619.        :  |  d1    |          |     |   ,----------,----------,   |    |  |
  620.        :  |        |          |     *---|--*  Fuse | Reset *--|---'    |  |
  621.        :  |        |          |     |   |----------|----------|        |  |
  622.    D0  :  |        |          |   ,-|---|--*   I/O | Clk   *--|---,    |  |
  623. 2 o-------|--------|----------'   | |   |----------|----------|   |    |  |
  624.        :  |        |              | '---|--*   Vpp | R/W   *--|---|----'  |
  625.   Busy :  |        |              |     |----------|----------|   |       |
  626. 11 o------|--------|--------------' ,---|--*   Gnd | 5V    *  |   |       |
  627.        :  |        |                |   '----------'-------|--'   |       |
  628.    D1  :  |        |              __+__    Chip connector  |      |       |
  629. 3 o-------|--------|--------,     \\\\\                    |      |       |
  630.        :  |        |        '------------------------------|------'       |
  631.   Str  :  |  |\ |  |                                       |              |
  632. 1 o-------*--| >+--*----*----*----*----*-------------------'              |
  633.        :   d2|/ |  |d3  |d4  |d5  |d6  |d7                                |
  634.        :          -+-  -+-  -+-  -+-  -+-                                 |
  635.        :          /_\  /_\  /_\  /_\  /_\                                 |
  636.    D3  :           |    |    |    |    |   |\ | d8                        |
  637. 5 o----------------*----|----|----|----|---| >+-------*-------------------'
  638.        :                |    |    |    |   |/ |       |
  639.        :                |    |    |    |              |
  640.    D4  :                |    |    |    |   |\ | d9    |
  641. 6 o---------------------*----|----|----|---| >+-------*
  642.        :                     |    |    |   |/ |       |
  643.        :                     |    |    |              |
  644.    D5  :                     |    |    |   |\ | d10   |
  645. 7 o--------------------------*----|----|---| >+-------*
  646.        :                          |    |   |/ |       |
  647.        :                          |    |              |
  648.    D6  :                          |    |   |\ | d11   |
  649. 8 o-------------------------------*----|---| >+-------*
  650.        :                               |   |/ |       |
  651.        :                               |              |
  652.    D7  :                               |   |\ | d12   |
  653. 9 o------------------------------------*---| >+-------'
  654.        :                                   |/ |
  655.        :
  656.        :
  657. 25 o------.
  658.        :  |
  659. .......:  |                                 d1 to d13: 1N4148
  660.     __+__
  661.     \\\\\
  662.  
  663. Centronics port
  664.  
  665.  
  666.  
  667.  
  668. IV) The program:
  669.     ===========
  670.  
  671.     The following program will enable you to read telecards on you PC if you
  672. build the reader.
  673.  
  674. --------------- cut here (begin)
  675. {*****************************************************************************}
  676. {                             T E L E C A R D . PAS                           }
  677. {*****************************************************************************}
  678. {   This program enable you to dumb the memory of electronics phonecards      }
  679. {   from all over the world, so that you will be able to see which country    }
  680. {   the card is from how many units are left and so on ....                   }
  681. {*****************************************************************************}
  682. {                                                                             }
  683. {                        Written by Stephane BAUSSON (1993)                   }
  684. {                                                                             }
  685. {                         Email: sbausson@ensem.u-nancy.fr                    }
  686. {                                                                             }
  687. {                       Snail Mail Address: 4, Rue de Grand                   }
  688. {                                           F-88630 CHERMISEY                 }
  689. {                                           France                            }
  690. {                                                                             }
  691. {*****************************************************************************}
  692. {* Thanks to: Tomi Engdahl (Tomi.Engdahl@hut.fi)                             *}
  693. {*****************************************************************************}
  694.  
  695. USES crt,dos;
  696.  
  697. CONST port_address=$378;     { lpr1 chosen }
  698.  
  699. TYPE string8=string[8];
  700.      string2=string[2];
  701.  
  702. VAR reg         : registers;
  703.     i,j         : integer;
  704.     Data        : array[1..32] of byte;
  705.     car         : char;
  706.     byte_number : integer;
  707.     displaying  : char;
  708.  
  709. {-----------------------------------------------------------------------------}
  710.  
  711. PROCEDURE Send(b:byte);
  712.  
  713.   BEGIN port[port_address]:=b;
  714.   END;
  715.  
  716. {-----------------------------------------------------------------------------}
  717.  
  718. FUNCTION Get:byte;
  719.  
  720.   BEGIN get:=port[port_address+1];
  721.   END;
  722.  
  723. {-----------------------------------------------------------------------------}
  724. { FUNCTION dec2hexa_one(decimal_value):hexa_character_representation;         }
  725. {                                                                             }
  726. {       - convert a 4 bit long decimal number to hexadecimal.                 }
  727. {-----------------------------------------------------------------------------}
  728.  
  729. FUNCTION dec2hexa_one(value:byte):char;
  730.  
  731.   BEGIN case value of
  732.       0..9   : dec2hexa_one:=chr(value+$30);
  733.       10..15 : dec2hexa_one:=chr(value+$37);
  734.     END;
  735.   END;
  736.  
  737. {-----------------------------------------------------------------------------}
  738. { FUNCTION d2h(decimal_byte):string2;                                         }
  739. {                                                                             }
  740. {       - convert a decimal byte to its hexadecimal representation.           }
  741. {-----------------------------------------------------------------------------}
  742.  
  743. FUNCTION d2h(value:byte):string2;
  744.  
  745.   VAR msbb,lsbb:byte;
  746.  
  747.   BEGIN msbb:=0;
  748.     if ( value >= $80 ) then
  749.     BEGIN msbb:=msbb+8;
  750.           value:=value-$80;
  751.     END;
  752.     if ( value >= $40 ) then
  753.     BEGIN msbb:=msbb+4;
  754.           value:=value-$40;
  755.     END;
  756.     if ( value >= $20 ) then
  757.     BEGIN msbb:=msbb+2;
  758.           value:=value-$20;
  759.     END;
  760.     if ( value >= $10 ) then
  761.     BEGIN msbb:=msbb+1;
  762.           value:=value-$10;
  763.     END;
  764.  
  765.     lsbb:=0;
  766.     if ( value >= $08 ) then
  767.     BEGIN lsbb:=lsbb+8;
  768.           value:=value-$08;
  769.     END;
  770.     if ( value >= $04 ) then
  771.     BEGIN lsbb:=lsbb+4;
  772.           value:=value-$04;
  773.     END;
  774.     if ( value >= $02 ) then
  775.     BEGIN lsbb:=lsbb+2;
  776.           value:=value-$02;
  777.     END;
  778.     if ( value >= $01 ) then
  779.     BEGIN lsbb:=lsbb+1;
  780.           value:=value-$01;
  781.     END;
  782.     d2h := dec2hexa_one(msbb) + dec2hexa_one(lsbb);
  783.   END;
  784.  
  785. {-----------------------------------------------------------------------------}
  786.  
  787. Function Binary( b : byte):string8;
  788.  
  789.   var weight : byte;
  790.       s      : string8;
  791.  
  792.   BEGIN weight:=$80;
  793.     s:='';
  794.     while (weight > 0) do
  795.     BEGIN if ((b and weight) = weight) then s:=s+'1'
  796.           else s:=s+'0';
  797.           weight:=weight div $02;
  798.     END;
  799.     Binary:=s;
  800.   END;
  801.  
  802. {-----------------------------------------------------------------------------}
  803.  
  804. FUNCTION Units:byte;
  805.  
  806.   VAR  u, i : integer;
  807.        s    : string8;
  808.  
  809.   BEGIN u:=0;
  810.     i:=13;
  811.     while (Data[i] = $FF) do
  812.     BEGIN u:=u+8;
  813.           i:=i+1;
  814.     END;
  815.     s:=Binary(Data[i]);
  816.     while(s[1]='1') do
  817.           BEGIN inc(u);
  818.           s:=copy(s,2,length(s));
  819.     END;
  820.     units:=u;
  821.   END;
  822.  
  823. {-----------------------------------------------------------------------------}
  824.  
  825. function Units_2:LongInt;
  826.  
  827.   BEGIN Units_2:=4096*Data[9]+512*Data[10]+64*Data[11]+8*Data[12]+Data[13];
  828.   END;
  829.  
  830. {-----------------------------------------------------------------------------}
  831.  
  832. PROCEDURE Card_Type;
  833.  
  834.   BEGIN case Data[2] of
  835.      $03: BEGIN write('Telecard - France - ');
  836.             case Data[12] of
  837.              $13: write('120 Units - ',units-130,' Units left');
  838.              $06: write('50 Units - ',units-60,' Units left');
  839.              $15: write('40 Units - ',units-40,' Units left');
  840.             END;
  841.           END;
  842.      $2F:BEGIN write('Telecard - Germany - ', Units_2, ' Units left');
  843.          END;
  844.      $3B:BEGIN write('Telecard - Greece - ', Units_2, ' Units left');
  845.          END;
  846.      $83:BEGIN write('Telecard');
  847.            case Data[12] of
  848.              $1E: write(' - Sweden');
  849.              $30: write(' - Norway');
  850.              $33: write(' - Andorra');
  851.              $3C: write(' - Ireland');
  852.              $47: write(' - Portugal');
  853.              $55: write(' - Czech Republic');
  854.              $5F: write(' - Gabon');
  855.              $65: write(' - Finland');
  856.            END;
  857.            if (Data[12] in [$30,$33,$3C,$47,$55,$65]) then
  858.            BEGIN case ((Data[3] and $0F)*$100+Data[4]) of
  859.               $012: write (' - 10 Units - ',units-12,' Units left');
  860.               $024: write (' - 22 Units - ',units-24,' Units left');
  861.               $027: write (' - 25 Units - ',units-27,' Units left');
  862.               $032: write (' - 30 Units - ',units-32,' Units left');
  863.               $052: write (' - 50 Units - ',units-52,' Units left');
  864.               $067: write (' - 65 Units - ',units-62,' Units left');
  865.               $070: write (' - 70 Units - ',units-70,' Units left');
  866.               $102: write (' - 100 Units - ',units-102,' Units left');
  867.               $152: write (' - 150 Units -  ',units-152,' Units left');
  868.              END;
  869.             END;
  870. {                    write(' - N0 ',Data[5]*$100+Data[6]);}
  871.           END;
  872.     END;
  873.   END;
  874.  
  875. {-----------------------------------------------------------------------------}
  876.  
  877. PROCEDURE waiting;
  878.  
  879.   BEGIN send($00);
  880.     write('Enter a card in the reader and press a key ...');
  881.     repeat until key pressed;
  882.     gotoxy(1, wherey);
  883.     clreol;
  884.   END;
  885.  
  886. {-----------------------------------------------------------------------------}
  887.  
  888. PROCEDURE Full_Displaying;
  889.  
  890.   BEGIN writeln('Memory dump:');
  891.     for i:=1 to 80 do write('-');
  892.     for i:=1 to (byte_number div 6 + 1) do
  893.     BEGIN for j:=1 to 6 do
  894.           BEGIN if j+6*(i-1) <= byte_number then write(binary(Data[j+6*(i-1)]):9);
  895.           END;
  896.           gotoxy(60,wherey);
  897.           for j:=1 to 6 do
  898.           if j+6*(i-1) <= byte_number then write(d2h(Data[j+6*(i-1)]),' ');
  899.           writeln;
  900.     END;
  901.     for i:=1 to 80 do write('-');
  902.     Card_Type;
  903.     writeln;
  904.   END;
  905.  
  906. {-----------------------------------------------------------------------------}
  907.  
  908. PROCEDURE Short_Displaying;
  909.  
  910.   VAR j : integer;
  911.  
  912.   BEGIN for j:=1 to byte_number do
  913.     BEGIN write(d2h(Data[j]),' ');
  914.     END;
  915.     writeln;
  916.   END;
  917.  
  918. {-----------------------------------------------------------------------------}
  919.  
  920. PROCEDURE Reading;
  921.  
  922.   VAR i, j  : integer;
  923.       Value : byte;
  924.  
  925.   BEGIN send($FE);
  926.     send($F8);
  927.     for i:=1 to 32 do
  928.     BEGIN Value:=0;
  929.           for j:=1 to 8 do
  930.           BEGIN Value:=Value*$02 + ((get and $08) div $08);
  931.             send($FB);
  932.             delay(1);
  933.             send($F8);
  934.           END;
  935.           Data[i]:=Value;
  936.     END;
  937.     case displaying of
  938.       'F':full_displaying;
  939.       'S':short_displaying;
  940.     END;
  941.   END;
  942.  
  943. {-----------------------------------------------------------------------------}
  944.  
  945. PROCEDURE writing;
  946.  
  947.   VAR i,n:integer;
  948.       car:char;
  949.  
  950.   BEGIN write('Which bit do you want to set to "1" : ');
  951.     readln(n);
  952.  
  953.     waiting;
  954.     car:=readkey;
  955.  
  956.     send($FA);
  957.     send($F8);
  958.     for i:=1 to n do
  959.     BEGIN send($F9);
  960.           if i=n then
  961.           BEGIN send($FD);
  962.             delay(20);
  963.             send($FF);
  964.             delay(20);
  965.           END;
  966.           send($FB);
  967.     END;
  968.     reading;
  969.   END;
  970.  
  971. {-----------------------------------------------------------------------------}
  972.  
  973. PROCEDURE Saving;
  974.  
  975.   VAR filename : string;
  976.       f        : text;
  977.       i        : word;
  978.  
  979.   BEGIN write('Enter the filename: ');
  980.     readln(filename);
  981.     assign(f, filename);
  982.     rewrite(f);
  983.     for i:=1 to byte_number do write(f,d2h(Data[i]),' ');
  984.     close(f);
  985.   END;
  986.  
  987. {-----------------------------------------------------------------------------}
  988.  
  989. PROCEDURE initialize;
  990.  
  991.   VAR i : integer;
  992.  
  993.   BEGIN byte_number:=32;
  994.     displaying:='F';
  995.     clrscr;
  996.     writeln(' 1 - to dump a 256 bits card');
  997.     writeln(' 2 - to dump a 128 bits card');
  998.     writeln(' F - to display in full format');
  999.     window(41,1,80,25);
  1000.     writeln(' S  - to display in short format');
  1001.     writeln(' F2 - to save in a file');
  1002.     writeln(' Q  - to exit the program');
  1003.     window(1,4,80,25);
  1004.     for i:=1 to 80 do write('=');
  1005.     window(1,5,80,25);
  1006.   END;
  1007.  
  1008. {=============================================================================}
  1009.  
  1010. BEGIN initialize;
  1011.       repeat waiting;
  1012.          car:=upcase(readkey);
  1013.          case car of
  1014.           'W':writing;
  1015.           'Q':;
  1016.           '1':byte_number:=32;
  1017.           '2':byte_number:=16;
  1018.           'F','S':displaying:=car;
  1019.           #00: BEGIN car:=readkey;
  1020.              if car=#60 then saving;
  1021.            END;
  1022.           else reading;
  1023.          END;
  1024.       until car='Q';
  1025. END.
  1026. --------------- cut here (end)
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.     _/_/_/_/_/               Stephane BAUSSON
  1033.        _/_/_/_/_/    Engineering student at ENSEM (Nancy - France)
  1034.       _/_/_/_/_/   Smail: 4, Rue de Grand, F-88630 CHERMISEY, France
  1035.      _/_/_/_/_/
  1036.     _/_/_/_/_/            Email: sbausson@ensem.u-nancy.fr
  1037.  
  1038. ------------------------------------------------------------------------------
  1039. <End of text quoted from Stephane Bausson's text about the telephone cards>.
  1040.  
  1041.