Jump to content

using a smart card to control windows applications?

manikyath

i'm working on a very understated media pc, and among other silly ideas i've got the thought to make "cartridges" to control which application is running on the computer.

 

the most sensible choice seems to be smart cards, for a number of reasons:

- the cards are cheap

- they contain at least enough storage for what i want to do

- the readers are cheap enough.

 

unfortunately i have no idea how to implement it. the rough idea i have in mind:

 

The card contains a list of commands to execute when plugged in, and a list of commands to execute when unplugged.

On the computer is a piece of software that constantly checks if a card is inserted.

When a card is inserted, the program runs the commands stored in the "commands to execute when plugged in" section,

and locally stores the commands in the "commands to be executed when unplugged" section.

then when that card is unplugged, it runs the buffered commands.

 

example: the card for google chrome:

plugged in command:

- start <path to google chrome executable>

unplugged command:

- taskkill /im "google chrome"

 

down to the issue at hand: how could i achieve this?

is there any programs or libraries i can use for this? am i overlooking simpler ideas? has anyone done anything similar to this in the past?

 

i'm looking for some input on this, google's showing up as pretty mcuh a dead end for me, and i have no idea how to do this from scratch.

Link to comment
Share on other sites

Link to post
Share on other sites

The lazy way would be to have each smart card login as a different account, then auto run what ever you want, and log out on removal. You can set this up in ad + gpo with some time.

 

Could also just use auto run on cheap usb/floppy/cd drives to run a script to run what ever program you want.

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Electronics Wizardy said:

The lazy way would be to have each smart card login as a different account, then auto run what ever you want, and log out on removal. You can set this up in ad + gpo with some time.

 

Could also just use auto run on cheap usb/floppy/cd drives to run a script to run what ever program you want.

i've considered floppies actually, but they've gotten really hard to find these days (as if that's unexpected... ?)

EDIT: and other options are kind of above the preferred price range, as well as a multi-GB flash drive feeling like kind of a waste to contain only pointers to the appropriate software.

Link to comment
Share on other sites

Link to post
Share on other sites

that moment when you create a thread, continue googling, and there's so little information that your thread becomes the third hit on google... :/

Link to comment
Share on other sites

Link to post
Share on other sites

I would suggest something different

 

Get a microcontroller with USB built in, like the PIC18f micros, or some cortex m0 / m4 chips ... program them to work as serial using CDC so basically when you plug in the usb port, the card shows up as a serial port/device/whatever and your application can monitor any newly created serial ports and send commands to your micro and get replies and all that.

 

You can add a small eeprom or flash and read it using SPI or i2c if you need more data then you can stick in the built in eeprom.

 

See https://pic-microcontroller.com/a-minimal-usb-cdc-acm-aka-virtual-serial-port/

or https://www.studentcompanion.co.za/usb-serial-communication-with-pic-microcontroller-flowcode/

or https://github.com/jgeisler0303/PIC16F1454_USB2Serial

 

The application on the computer can send commands like  GET DATA SIZE (reply with number of bytes) then program can say GET CHUNK 0 and micro sends 128/256/1024/whatever bytes at something like 192000 bps (24 KB/s) optionally along with 2-4 bytes as a checksum to make sure the data was read correctly correctly.

 

Alternatively, you could make the micro with mass storage device class, and report to OS that the micro is a read only usb stick formatted with fat16 or fat32 (free existing libraries exist) that has a few files on it - your micro only has to implement a bunch of read requests to send "sectors" to the OS. 

see app note 1003 USB Mass Storage Device Using a PIC® MCU http://www.t-es-t.hu/download/microchip/an1003a.pdf

book : https://books.google.ro/books? [ long google books url ]

 

https://pic-microcontroller.com/simple-mass-storage-for-your-microcontroller-project/

 

you could have a simple file on the file system with a unique signature that would tell you it's your usb stick and not some random stick, or your app could try to write a file on the usb stick and if it manages then it's not your read only usb stick.

 

Cost would be very small ... under 2$ for microcontroller and usb connector.  programmer is 15$ or so and you only need one... and you learn to program microcontrollers

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, mariushm said:

I would suggest something different

 

Get a microcontroller with USB built in, like the PIC18f micros, or some cortex m0 / m4 chips ... program them to work as serial using CDC so basically when you plug in the usb port, the card shows up as a serial port/device/whatever and your application can monitor any newly created serial ports and send commands to your micro and get replies and all that.

 

You can add a small eeprom or flash and read it using SPI or i2c if you need more data then you can stick in the built in eeprom.

 

See https://pic-microcontroller.com/a-minimal-usb-cdc-acm-aka-virtual-serial-port/

or https://www.studentcompanion.co.za/usb-serial-communication-with-pic-microcontroller-flowcode/

or https://github.com/jgeisler0303/PIC16F1454_USB2Serial

 

The application on the computer can send commands like  GET DATA SIZE (reply with number of bytes) then program can say GET CHUNK 0 and micro sends 128/256/1024/whatever bytes at something like 192000 bps (24 KB/s) optionally along with 2-4 bytes as a checksum to make sure the data was read correctly correctly.

 

Alternatively, you could make the micro with mass storage device class, and report to OS that the micro is a read only usb stick formatted with fat16 or fat32 (free existing libraries exist) that has a few files on it - your micro only has to implement a bunch of read requests to send "sectors" to the OS. 

see app note 1003 USB Mass Storage Device Using a PIC® MCU http://www.t-es-t.hu/download/microchip/an1003a.pdf

book : https://books.google.ro/books? [ long google books url ]

 

https://pic-microcontroller.com/simple-mass-storage-for-your-microcontroller-project/

 

you could have a simple file on the file system with a unique signature that would tell you it's your usb stick and not some random stick, or your app could try to write a file on the usb stick and if it manages then it's not your read only usb stick.

 

Cost would be very small ... under 2$ for microcontroller and usb connector.  programmer is 15$ or so and you only need one... and you learn to program microcontrollers

 

 

i like the idea.. but once you add up part cost, work for assembling each "cartridge", then programming of the cartridge, and then the programming on the computer end, compiled into the end result.. i may as well just go for €4 usb sticks and completely rely on windows' autorun stuff.

Link to comment
Share on other sites

Link to post
Share on other sites

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Windows7ge said:

Have you ever heard of rubber-ducky?

aware of it, but its WAY out of the pricerange for the "cartridge".

 

i'm looking for something that'll go below the price of a simple usb stick on the "cartridge" side. the smartcard idea would drop it below the €1 range, but it seems like no one never tried to do what i'm intending to use them for.

Link to comment
Share on other sites

Link to post
Share on other sites

well yeah, you can go on aliexpress/alibaba and order 128MB - 1 GB sticks for 0.5$ each... but what's the fun in that?

microcontroller with cdc (serial) would allow to pass commands back and fort

 

but fine ... i guess you could make your own "card reader" ... an arduino with a serial to usb adapter would be cheapest to make

You could make your "smart cards" with a simple i2c/spi eeprom chip... ex a 256 byte i2c eeprom is 2-3 cents in quantity: https://lcsc.com/product-detail/EEPROM_PUOLOP-PT24C02_C351425.html

you can make custom circuit boards as your card surface, have a small rectangle cut in the circuit board to fit the body of the chip inside the hole and have the pins soldered to the circuit board... you only need 4-5 contacts (voltage, ground, data and clock and possibly a 5th pad to detect when card is inserted if you don't build some optical detection or a switch inside the card reader)

The rest of the pins on the ic are for i2c address and can be hard wired to a particular address/default on the card

 

Your card reader can simply read the bytes and signal your application that card was inserted and send it the data

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, mariushm said:

well yeah, you can go on aliexpress/alibaba and order 128MB - 1 GB sticks for 0.5$ each... but what's the fun in that?

microcontroller with cdc (serial) would allow to pass commands back and fort

 

but fine ... i guess you could make your own "card reader" ... an arduino with a serial to usb adapter would be cheapest to make

You could make your "smart cards" with a simple i2c/spi eeprom chip... ex a 256 byte i2c eeprom is 2-3 cents in quantity: https://lcsc.com/product-detail/EEPROM_PUOLOP-PT24C02_C351425.html

you can make custom circuit boards as your card surface, have a small rectangle cut in the circuit board to fit the body of the chip inside the hole and have the pins soldered to the circuit board... you only need 4-5 contacts (voltage, ground, data and clock and possibly a 5th pad to detect when card is inserted if you don't build some optical detection or a switch inside the card reader)

The rest of the pins on the ic are for i2c address and can be hard wired to a particular address/default on the card

 

Your card reader can simply read the bytes and signal your application that card was inserted and send it the data

 

look... you're poking in completely the wrong direction here..

 

i want to set this up in a way that adding more cards is cheap, easy, and quick. adding layers of complexity isnt making the process cheaper, easier, or more reliable. my main issue is that i'm not nearly good enough of a programmer to start messing with smartcards.

 

in the meantime i've done some fiddling on google, and got the idea i could maybe find a way to turn the serial port on my motherboard into a terminal which i can use to run commands from an arduino, that it can then load from whatever storage source i hook up to it. i'm comfortable with CMD, and somewhat familiar with powershell. what i'm gonna make the arduino read from is a different case again, unfortunately..

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, manikyath said:

aware of it, but its WAY out of the pricerange for the "cartridge".

 

i'm looking for something that'll go below the price of a simple usb stick on the "cartridge" side. the smartcard idea would drop it below the €1 range, but it seems like no one never tried to do what i'm intending to use them for.

As far as I've read you can find clones of it for as low as €1.36 from china. So I would say it's not out of the question.

 

If the SmartCard has a micro-controller though you should be able to reverse engineer it to do whatever you like within the hardware's limitations provided you have a SmartCard programmer. Then you'd need a smart card reader for the computer. I'm not sure what either of those go for though.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Windows7ge said:

As far as I've read you can find clones of it for as low as €1.36 from china. So I would say it's not out of the question.

 

If the SmartCard has a micro-controller though you should be able to reverse engineer it to do whatever you like within the hardware's limitations provided you have a SmartCard programmer. Then you'd need a smart card reader for the computer. I'm not sure what either of those go for though.

the cards i'm looking at are 97 cents for a card that's basicly a 256 byte i²c eeprom. i'm just now considering they may just be as easy to interface with as just a normal eeprom chip.

 

also, ordering stuff from china is out of the question, i'd like to finish this project before the end of the year, and not get nailed by customs.

 

here's what i'm considering at the moment:

- making my own programmer with an arduino, i got plenty of those laying around, and i'm comfortable enough with them that a stand-alone programmer wouldnt be an issue.

 

- the "receiving end" computer would be set up as such:

> an arduino set up to read the i²c eeprom cards, the card reader has a microswitch that detects wether a card is present or not, this switch is tied into two functions on the arduino: if it goes from low to high it launches "cardInserted", and when it goes from high to low it launches "cardRemoved"

> the cardInserted function would read the i²c eeprom, deduct the launch command and close command

> the arduino sends the launch command over serial to the computer, that then executes it, it stores the close command in arduino memory

> the cardRemoved function sends the close command over serial, and clears the stored command from arduino memory.

 

i could technically even make a "programmer" card, that sets the "receiving" computer up to program new cards, essentially cutting out the need for a seperate programmer.

 

now, to delve into i²c eeprom...

Link to comment
Share on other sites

Link to post
Share on other sites

12 hours ago, manikyath said:

i could technically even make a "programmer" card, that sets the "receiving" computer up to program new cards, essentially cutting out the need for a seperate programmer.

 

now, to delve into i²c eeprom...

Any particular reason to store commands on the cards themselves?

 

Since you will have a program running on the PC why not just send the card ID number via arduino over serial, and then just find the corresponding cardInserted and cardRemoved commands in and XML or JSON file. It would make much easier to add new cards, or reprogram existing ones.

CPU: i7 3770K | MB: EVGA Z77 FTW | RAM: HyperX Savage 2400Mhz 16GB | GPU: R9 280X Toxic | Cooler: Scythe Fuma | PSU: CoolerMaster B600

SSD: Crucial MX300 525GB | HDD: Seagate Barracuda 7200.12 500GB - Toshiba DT01ACA300 3TB

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, G27Racer_188 said:

Any particular reason to store commands on the cards themselves?

 

Since you will have a program running on the PC why not just send the card ID number via arduino over serial, and then just find the corresponding cardInserted and cardRemoved commands in and XML or JSON file. It would make much easier to add new cards, or reprogram existing ones.

because i'd prefer a system that doesnt require a "library" that translates the card ID to a specific command. the idea is that the card could contain a pointer to just about anything, and the device itself doesnt need to be modified as long as it can access whatever the pointer is directing it to.

 

if i'd go for the ID & library system i'd go for a 9 pin header, and make it an 8-bit ID system. the whole reason i'm diving into this is i dont *want* an ID & library system.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×