Hello,

Henrik Hartz wrote:
> 
> I have made two cardservices. The two cardservices is used by two
> different cards. How can I utilize one CardServiceFactory, and make
> it select the right CardService, depending on wich card is inserted?

You should first have a look at the section named "CardServiceFactory"
in the OCF 1.2 Programmer's Guide:

 http://www.opencard.org/docs/pguide/PGuide.html#HDRCARDSERVICEFACTORY

This section explains briefly how the two functions "getCardType" and
"getClasses" are used to tell the framework that this factory has
recognized the card and that the inserted card can be used by a such
a set of CardServices (for example, a GPK card can be used by a
GPKSignatureService but also by a simple file access components such
as GPKFileAccessService, GPKFileSystemService, GPKFileUtilityService,
and also GPKAdministrativeService, GPKKeyGenerationService,
GPKKeyImportService, and GPKKeyManagementService !

So a factory can indicate several types of CardServices for one
type of card (and the framework will use this information to
actually create the objects when they are requested by the
application). This information is given by "getClasses", which
needs a CardType object in order to know which card we are dealing
with and so to which set of classes it is associated.

Also a factory can manage several "types" of cards, this is the
job of "getCardType" that finds the type of the card, and then
returns a relevant CardType object. For example, the GPK CardService
Factory can manage both MPCOS, GPK4000, and GPK8000 cards.

Now, a last question could be: but how can the factory decide
what kind of card is currently inserted? OCF offers two methods
for this:

 1) the factory can access the CardID object, basically an abstraction
    for the returned "Answer To Reset" (ATR), or if this is not
    sufficient:

 2) the factory can have a temporary communication channel with the
    card (actually a SlotChannel object) and communicate APDU commands
    in order to try to guess. For example, an EMV card has nothing
    special in the ATR and so one needs to try to select and read
    its "application file" (with a select df by name or something
    like this) to ensure it is actually an EMV card. Note that PC/SC
    is going to introduce a similar mechanism but only in version 2.0!

Also, in the case a factory manages several types of cards, this
method is becoming a big "switch" and this is not a very object-
oriented design, so we recommend to move this code to a static
method of the relevant CardService class for each type of card,
and then the "getCardType" method can call for each managed type
a knows method (e.g., if (MyCardServiceType.knows) {...}).

There is such an example in your OCF 1.2 distribution sources
that makes use of this naming pattern, and also uses the temporary
slot channel to check the card: it is the default basic implementation
for Database cards (SCQL) factories. You can find in the:

OCF1.2/components/base-opt/src/opencard/opt/database/ directory:

BasicDatabaseFactory.java ("getCardType" and "getClasses" functions)
and BasicDatabase.java ("knows" function).

And in the "knows" method:
   * a temporary SlotChannel is allocated,
   * a 'PRESENT USER ("PUBLIC")' command w/o password is sent, and
   * the response is analyzed (it should be 9000 for an SCQL card).

Hope it'll help you create your own factory.

Cheers,
Christophe.

 = "If an undetectable error occurs, the processor continues as if =
 = no error had occurred."    -- IBM S/360 Principles of Operation =
--
-------------------------------------------------------------
[EMAIL PROTECTED] - Gemplus Research Lab
Phone: +33 4-42-36-57-83 | Disclaimer: I don't speak for Gemplus
Gemplus doesn't speak for me... it is better that way!
-------------------------------------------------------------


---
> Visit the OpenCard web site at http://www.opencard.org/ for more
> information on OpenCard---binaries, source code, documents.
> This list is being archived at http://www.opencard.org/archive/opencard/

! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
!                           [EMAIL PROTECTED]
! containing the word
!                           unsubscribe 
! in the body.

Reply via email to