Amicus18 Board & Shields

Smart card

A forum for Amicus18 hardware topics

Smart card

Postby be80be » Wed Jul 28, 2010 3:52 pm

I've been playing with a hacked card reader I found the data sheet for a TDA8004T
http://www.datasheetcatalog.org/datashe ... 004T_2.pdf
You can get them for almost free. There in a lot of old Philips Satellite Receivers
Be good if I could make own. I hope to find some more info.
I was thinking reprogram a card and use it for something like a lock key.
I found this to http://www.epanorama.net/links/smartcar ... #smartcard
I'll post a pic as soon as i can.
User avatar
be80be
Loyal Member
Loyal Member
 
Posts: 331
Joined: Fri Feb 13, 2009 3:46 pm

Re: Smart card

Postby Graham » Wed Jul 28, 2010 9:46 pm

Interesting stuff be80be - looking forward to more info
User avatar
Graham
Moderator
Moderator
 
Posts: 618
Joined: Wed Apr 01, 2009 10:34 pm

Re: Smart card

Postby be80be » Sun Aug 01, 2010 11:43 am

Well I think I have most of what I need to give this a try ordering some of parallax smart cards and going to turn one of my card readers in to one like this

Image

I been reading some of the stamp code for it to get a grip on how it works.
I'm not as smart as Graham But i bet I love programming just as much Lol
I'm going to use my baby's 18f1220 and swordfish basic. Graham I sure hope
David Baker doesn't give up on swordfish I sure do like it. But if he did I have
more then a enough pic chips to last me a life time and I'm sure I can keep me something to run swordfish on this is being type on a old dell optiplex with super fast 500 mhz cpu
LOL.
User avatar
be80be
Loyal Member
Loyal Member
 
Posts: 331
Joined: Fri Feb 13, 2009 3:46 pm

Re: Smart card

Postby be80be » Mon Aug 02, 2010 1:34 pm

Here my hacked card reader front and back picture now for the fun
part let me write the code hope to post some in a day or to.
Hope so
front_card.JPG
front_card.JPG (88.95 KiB) Viewed 256 times
back_card.JPG
back_card.JPG (80.73 KiB) Viewed 256 times
User avatar
be80be
Loyal Member
Loyal Member
 
Posts: 331
Joined: Fri Feb 13, 2009 3:46 pm

Re: Smart card

Postby Graham » Mon Aug 02, 2010 8:08 pm

That's a pretty clean hack be80be.

Looks like there's some definite work making the routines to interface with the card - sounds like you've got some source code to work with, hopefully that will ease the workload ;)
User avatar
Graham
Moderator
Moderator
 
Posts: 618
Joined: Wed Apr 01, 2009 10:34 pm

Re: Smart card

Postby be80be » Tue Aug 03, 2010 5:28 am

I have this sample from Parallax it's for the stamp2 which is what I started programming with. But then I found that I could use Pic chips been picking ever since LOL.
I'm going to learn how it works with my picbasic pro and then try my luck with swordfish basic and my own code hopefully.
I don't think Parallax will mine the post maybe send them some more people there way. They have a lot of good sensors that are easy to use and code in basic that not hard to learn from.http://www.parallax.com/tabid/760/List/ ... fault.aspx
Code: Select all
' SC4442_Demo.bs2

' {$STAMP BS2}
' {$PBASIC 2.5}

' This program demonstrates the basics of reading and writing data to the
' IS23SC4442 smart card.  Since this card has a Programmable Security Code
' (PSC), the user is required to enter a password before writing data to
' the card.

' This program simply declares the password as a constant (default $FFFFFF)
' and when 'authenticate' is selected, it compares that password to the one
' on this card.  This MUST be selected before the user is able to write
' data to the card.

' -----[ I/O Definitions ]-------------------------------------------------

IO                 PIN    3                   ' Serial Data IO
CD                 PIN    2                   ' Card Detect
CLK                PIN    1                   ' Serial Data Clock
RST                PIN    0                   ' Reset

' -----[ Constants ]-------------------------------------------------------

ReadMain           CON    $30                 ' Read main memory
ReadProtection     CON    $34                 ' Read protection bit
ReadSecurity       CON    $31                 ' Read PSC
UpdateMain         CON    $38                 ' Update main memory
UpdateSecurity     CON    $39                 ' Update PSC
UpdateProtection   CON    $3C                 ' Update Protection bits
CompareData        CON    $33                 ' Compare Verification Data

' Programmable Security Code - REMEMBER TO CHANGE IF PASSWORD IS UPDATED!!
Password1          CON    $FF                 ' 1st byte of PSC
Password2          CON    $FF                 ' 2nd byte of PSC
Password3          CON    $FF                 ' 3rd byte of PSC

' -----[ Variables ]-------------------------------------------------------

index              VAR    Byte                ' Variable space for FOR...NEXT loop
command            VAR    Byte                ' Command format
dat                VAR    Byte                ' Variable space for data
address            VAR    Byte                ' Address location in memory

PSW1               VAR    Byte                ' Variable space for PSC comparison
PSW2               VAR    Byte
PSW3               VAR    Byte

temp               VAR    Byte
errCounter         VAR    Byte                ' Error counter for PSC
choice             VAR    Nib                 ' Main menu selection
keyboard           VAR    Bit                 ' Input from keyboard

' -----[ Initialization ]--------------------------------------------------
' Declares PSC and waits for a smart card to be inserted
Program_Start:
  DEBUG CLS

  DO                                             ' Check for smart card,
    DEBUG HOME, "No card inserted!"              ' loop until card detected
  LOOP UNTIL(CD = 1)

  GOSUB Reset                                    ' Reset smart card

' -----[ Program Code ]----------------------------------------------------
Main:
  DO
    DEBUG HOME, "Remember to authenticate before writing data to the card!", CR,
          CR, "Select:", CR,
          "  1) Read Data from the card", CR,
          "  2) Authenticate", CR,
          "  3) Write Data to the card", CR, CR,
          "Selection: ", CLREOL
    DEBUGIN DEC Choice

    SELECT Choice
      CASE 1: GOSUB Read_Data_From_Card
      CASE 2: GOSUB Authenticate
      CASE 3: GOSUB Write_Data_To_Card
    ENDSELECT
  LOOP

' -----[ Subroutine - Read_Data_From_Card ]--------------------------------
' Reads all data from memory
Read_Data_From_Card:
  ' Display memory map heading
  DEBUG HOME, 0, 13, REP "-"\36, "[   DATA   ]", REP "-"\36,
        CR, "Addr.  *0   *1   *2   *3   *4   *5   *6   *7   *8   *9   *A   *B   *C   *D   *E   *F",
        CR, REP "_"\84

  address = 0                                    ' Set address location to 0
  command = ReadMain                             ' Set command format to read main memory
  GOSUB Read_Main                                ' Call the Read_Main subroutine

  DEBUG CR, REP "_"\84, CR                       ' Finish memory map "box"
  DEBUG "Press any key to return to menu..."
  DEBUGIN keyboard                               ' Receive input from user
  DEBUG CLS
RETURN

' -----[ Subroutine - Authenticate ]---------------------------------------
' Compares password delcared in 'Constants' to PSC in memory
Authenticate:
  DEBUG CLS, "Authenticating...", CR
  GOSUB Compare
  SELECT errCounter
    CASE %000: DEBUG HOME, "Card is locked.", CLREOL, CR, CLREOL
    CASE %001: DEBUG HOME, "Invalid PSC, one try remaining."
    CASE %011: DEBUG HOME, "Invalid PSC, two tries remaining."
    CASE %111: DEBUG HOME, "PSC verified, you may now write data to the card."
  ENDSELECT

  DEBUG CR, CR, "Press any key to return to menu..."
  DEBUGIN keyboard                               ' Receive input from user
  DEBUG CLS
RETURN

' -----[ Subroutine - Write_Data_To_Card ]---------------------------------
' Writes data to specified address location
Write_Data_To_Card:
  DEBUG CLS, "Write Data to Address", CR, REP "-"\25, CR, CR,
        "Input address location (HEX): ", CLREOL
  DEBUGIN HEX address                            ' Receive address location from user
  DEBUG "Input data (HEX): ", CLREOL
  DEBUGIN HEX Dat                                ' Receive data from user

  command = UpdateMain                           ' Set command format to update main memory
  GOSUB Update_Main                              ' Call the Update_Main subroutine
  GOSUB Read_Data_From_Card                      ' Display memory map for verification
RETURN


' -----[ Subroutine - Read_Main ]------------------------------------------
' Call I2C protocol to read main memory
Read_Main:
  GOSUB Send_Command
    FOR index = 0 TO 255
      IF (index//16 = 0) THEN DEBUG CR, HEX1 index/16, "*  |"
      GOSUB Recieve_Byte
      DEBUG "  ", HEX2 Temp, " "
    NEXT
RETURN

' -----[ Subroutine - Update_Main ]----------------------------------------
' Calls I2C protocol to update main memory
Update_Main:
  GOSUB Send_Command
  GOSUB Process
RETURN

' -----[ Subroutine - Compare ]--------------------------------------------
' Calls I2C protocol to compare PSC
Compare:
  command = ReadSecurity                        ' Set command format to read protection memory
  address = 0                                   ' Reset address to 0
  dat = 0                                       ' Reset dat to 0
  GOSUB Read_Security                           ' Call Read_Security subroutine

  command = UpdateSecurity                      ' Updates error counter if PSC is invalid
  address = 0
   IF(errCounter = %111) THEN dat = %011
   IF(errCounter = $011) THEN dat = $001
   IF(errCounter = $001) THEN dat = $000
  GOSUB Send_Command
  GOSUB Process

  Command = CompareData                         ' Set command format to compare data

  Address = $01                                 ' Compare 1st byte of PSC
  Dat = PassWord1
  GOSUB Send_Command
  GOSUB Process

  Address = $02                                 ' Compare 2nd byte of PSC
  Dat = PassWord2
  GOSUB Send_Command
  GOSUB Process

  Address = $03                                 ' Compare 3rd byte of PSC
  Dat = PassWord3
  GOSUB Send_Command
  GOSUB Process

'   Command=UpdateSecurity                                ' Erase Error Counter
'   Address=$00
'   Dat=$07                                               ' If password match then the counter restore
'   GOSUB Send_Command
'   GOSUB Process
RETURN

' -----[ Subroutine - Read_Security ]--------------------------------------
' Collects 3 byte PSC from protection memory
Read_Security:
   GOSUB Send_Command                            ' Call Send_Command subroutine
   GOSUB Recieve_Byte                            ' Retrieve error counter value &
   errCounter = Temp                             ' store in errCounter variable
   GOSUB Recieve_Byte                            ' Retrieve 1st byte of PSC &
   PSW1 = Temp                                   ' store in PSW1 variable
   GOSUB Recieve_Byte                            ' Retrieve 2nd byte of PSC &
   PSW2 = Temp                                   ' store in PSW2 variable
   GOSUB Recieve_Byte                            ' Retrieve 3rd byte of PSC &
   PSW3 = Temp                                   ' store in PSW3 variable
RETURN

' -----[ Subroutine - DeviceStart ]----------------------------------------
DeviceStart:                                     ' I2C start bit sequence
  INPUT IO
  INPUT CLK
  LOW   IO
RETURN

' -----[ Subroutine - DeviceStop ]-----------------------------------------
DeviceStop:                                      ' I2C stop bit sequence
  LOW   IO
  INPUT CLK
  INPUT IO
RETURN

' -----[ Subroutine - Send_Command ]---------------------------------------
Send_Command:                                    ' Send command format to smart card
  GOSUB DeviceStart
  SHIFTOUT IO, CLK, LSBFIRST, [Command\8, Address\8, Dat\8]
  GOSUB DeviceStop
RETURN

' -----[ Subroutine - Receive_Byte ]---------------------------------------
Recieve_Byte:                                    ' I2C receive data from smart card
  SHIFTIN IO, CLK, LSBPRE, [Temp\8]
RETURN

' -----[ Subroutine - Process ]--------------------------------------------
Process:
  DO
    HIGH CLK
    LOW  CLK
  LOOP UNTIL(IO = 1)
RETURN

' -----[ Subroutine - Reset ]----------------------------------------------
' Resets internal address counter to zero
Reset:
  LOW   CLK
  HIGH  RST
  HIGH  CLK
  LOW   CLK
  LOW   RST
  FOR index = 0 TO 3
    GOSUB Recieve_Byte
  NEXT
RETURN
User avatar
be80be
Loyal Member
Loyal Member
 
Posts: 331
Joined: Fri Feb 13, 2009 3:46 pm


Return to Amicus18 Board & Shields

Site Login