VHL.Setup

This command creates a VHL file dynamically and transfers it to the reader's RAM. The VHL file specifies the card-specific memory structure required to call VHL.Read or VHL.Write. You need to run VHL.Setup if you don't want to configure the readers with a static VHL file ( learn more ).

To run VHL.Format, you cannot use a dynamic VHL file. In this case, you have to follow the standard VHL implementation with a static VHL file.

To describe the memory structure, provide a list of parameters depending on the card type (see optional fields in the Parameters table below). If you omit a parameter, the reader will use the default value. To fill in the parameter values, please refer to the card specification. For LEGIC or MIFARE cards, you can also analyze the card structure using BALTECH ID-engine Explorer.

The card type description is lost after a reboot or when you run VHL.Select, VHL.Read, or VHL.Write with a static VHL file.

Properties

Parameters (request frame)

Name Type/Size Description
ConsideredCardType Enumeration (8 bits)

Type of card to consider. The default value is 0x00, i.e. the reader will use the card type detected by VHL.Select . To handle the card as a different type (e.g. handle a DESFire card as an inter-industry ISO 14443-4 card), set this value to the desired card type.

Not all card types support all VHL commands. For details, see our overview of supported commands

Values:
  • Default (0x00)
    See description above
  • MifareClassic (0x10)
    MIFARE Classic (1k and 4k variants)
  • Iso14443aGeneric (0x11)
    Generic ISO 14443-4 Type A without ISO 7816-4 support
  • Iso14443aInterIndustry (0x12)
    ISO 14443-4 Type A compliant with ISO7816-4 and MIFARE L3
  • MifareUltraLight (0x13)
    MIFARE Ultralight
  • MifareDesfire (0x14)
    MIFARE DESFire (2k, 4k, and 8k variants)
  • InfineonSle55 (0x15)
    Infineon my-d proximity (SLE55)
  • Iso14443aIntIndustryMif (0x16)
    ISO 14443 Type A (NXP SmartMX/inter-industry)
  • MifarePlusL2 (0x17)
    MIFARE Plus L2 (2k and 4k variants)
  • LEGICAdvantIso14443a (0x18)
    LEGIC advant ISO 14443 Type A
  • MifarePlusL3 (0x19)
    MIFARE Plus L3
  • LEGICPrimeLegacy (0x20)
    LEGIC prime; this is a legacy value - it has been replaced by LEGICPrime .
  • LEGICAdvantLegacy (0x21)
    LEGIC advant (ISO 14443 Type A/ISO 15693); this is a legacy value - it has been replaced by LEGICAdvantIso14443a and LEGICAdvantIso15693.
  • Iso15693 (0x30)
    ISO-15693-compliant label
  • LEGICAdvantIso15693 (0x32)
    LEGIC advant ISO 15693
  • Iso14443bUnknown (0x40)
    ISO 14443-4 Type B without ISO 7816-4 support
  • Iso14443bIntIndustry (0x41)
    ISO 14443-4 Type B with ISO 7816-4 support
  • IClassIso14B (0x42)
    iCLASS via standard-compliant ISO 14443 Type B protocol (Level 3 compatible)
  • IClassIso14B2 (0x50)
    iCLASS via proprietary ISO 14443 Type B protocol derivate (Level 2 compatible)
  • IClass (0x60)
    iCLASS via ISO 15693
  • Felica (0x70)
    FeliCa
  • EM4205 (0x80)
    EM 4205/EM 4305
  • EM4100 (0x81)
    EM 4100/EM 4102
  • EM4450 (0x83)
    EM 4450
  • Pyramid (0x84)
    HID Pyramid
  • HidProx32 (0x85)
    HID Prox32
  • Keri (0x86)
    Keri
  • Quadrakey (0x87)
    QuadraKey
  • HidIndala (0x88)
    HID Indala ASP
  • HidAwid (0x89)
    AWID
  • HidProx (0x8A)
    HID Proximity
  • HidIoprox (0x8B)
    ioProx
  • Hitag1S (0x8C)
    HITAG 1 or S
  • Hitag2M (0x8D)
    HITAG 2 Manchester
  • Hitag2B (0x8E)
    HITAG 2 Biphase
  • TTF (0x8F)
    Low-level card type/programmable decoder
  • STSRIX (0x90)
    ST SRIX
  • SecuraKey (0xA0)
    SecuraKey
  • GProx (0xA1)
    G-Prox
  • HidIndalaSecure (0xA2)
    HID Indala ASP+
  • Cotag (0xA3)
    Cotag
  • Idteck (0xA4)
    IDTECK
  • BluetoothMce (0xB0)
    Bluetooth MCE; Mobile Card Emulation over Bluetooth
  • LEGICPrime (0xC0)
    LEGIC prime
  • HidSio (0xE0)
    Abstract card type for reading SIO Elements
RFU Raw data (length 1 Byte) Fixed value 0x00
Optional field, condition: ConsideredCardType == ConsideredCardType.MifareClassic
MifareKeyLen Raw data (length 1 Byte) Fixed value 0x06
MifareKey Raw data (length 6 Bytes) Encryption key to access the card.
AsKeyALen Raw data (length 1 Byte) Fixed value 0x01
AsKeyA Boolean (8 bits) If true, Key A is used to access the card.
If false, Key B is used.
MadIdLen Raw data (length 1 Byte) Fixed value 0x02
MadId Integer (16 bits)

2-byte application ID (AID) that identifies the sectors to access. If specified, only the payload of that application will be accessed. If not specified, the payload of all sectors will be accessed.

All sector trailer blocks and block 0 will be omitted, i.e. the following block order is used: 1,2,4,5,6,8, etc. (0,3,7, etc. are omitted).
Optional field, condition: ConsideredCardType == ConsideredCardType.MifareDesfire
AppIdLen Raw data (length 1 Byte) Fixed value 0x04
AppId Integer (32 bits) Application ID, ranging from 0 to 0x00FFFFFF (big-endian)
DesfireFileDescLen Raw data (length 1 Byte) Fixed value 0x10
DesfireFileDesc.FileNo Integer (8 bits) The DESFire file number to access
(Minimum value: 0, maximum value: 31)
DesfireFileDesc.FileCommunicationSecurity Enumeration (8 bits) Communication settings that define if data is to be MAC'ed or encrypted before it's transmitted to the host system.
Values:
  • Plain (0x00)
  • Mac (0x01)
  • Encrypted (0x03)
DesfireFileDesc.FileType Enumeration (8 bits) Type of file to read Only Standard and Backup files are supported. There's no support for Cyclic, Record, or Value files.
Values:
  • Standard (0x00)
  • Backup (0x01)
    Commit will be performed automatically.
  • BackupManualCommit (0x02)
    Commit will be performed when writing to address 0xFFFF.
DesfireFileDesc.ReadKeyNo Integer (8 bits)

ReadKeyNo, i.e. the index of the read key within the DESFire application key table

The value 14 allows unencrypted access.
(Minimum value: 0, maximum value: 14)
DesfireFileDesc.WriteKeyNo Integer (8 bits)

WriteKeyNo, i.e. the index of the write key within the DESFire application key table

The value 14 allows unencrypted access.
(Minimum value: 0, maximum value: 14)
DesfireFileDesc.Offset Integer (16 bits) Number of the first byte in the DESFire file to map into the VHL file.
(Minimum value: 0, maximum value: 0xFFFF)
DesfireFileDesc.Length Integer (16 bits) Length of byte sequence within the DESFire file to map into the VHL file.
(Minimum value: 0, maximum value: 0x7FFF)
DesfireFileDesc.ReadKeyIdx Integer (8 bits) Index of the read key on the reader
  1. 0x00-0x7F refer to an index in a SAM (key version has to be 0).
  2. 0x80-0xBF refer to an index in Crypto Key.
  3. 0xC0-0xCB refer to an index in VhlCfg/File/DesfireKeyList.
DesfireFileDesc.WriteKeyIdx Integer (8 bits) Index of the write key on the reader
If omitted and WriteKeyNo is equal to ReadKeyNo, it defaults to ReadKeyIdx. Otherwise it defaults to ReadKeyIdx + 1.
  1. 0x00-0x7F refer to an index in a SAM (key version has to be 0).
  2. 0x80-0xBF refer to an index in Crypto Key.
  3. 0xC0-0xCB refers to an index in VhlCfg/File/DesfireKeyList.
DesfireFileDesc.AccessRightsLowByte Integer (8 bits) Only needed to run VHL.Format.

This byte is composed of a high nibble ( ReadWriteKeyNo ) and a low nibble ( ChangeKeyNo ). It corresponds to the low byte of the access rights (see DESFire spec 3.5; chapter 8.3) of the DESFire file. The high byte is composed implicitly of ReadKeyNo and WriteKeyNo.

DesfireFileDesc.ChangeKeyIdx Integer (8 bits) Only needed to run VHL.Format.

Index of the key on the reader that is used to change a key when running VHL.Format. If ChangeKeyNo (see AccessRightsLowByte ) is equal to WriteKeyNo, this value defaults to WriteKeyIdx. Otherwise, it defaults to WriteKeyIdx + 1.

  1. 0x00-0x7F refer to an index in a SAM (key version has to be 0).
  2. 0x80-0xBF refer to an index in Crypto Key.
  3. 0xC0-0xCB refer to an index in VhlCfg/File/DesfireKeyList.
DesfireFileDesc.FileSize Integer (16 bits) Only needed to run VHL.Format.

The size of the DESfire file. It's usually Offset + Len.

DesfireFileDesc.IsoFid Integer (16 bits) Only needed to run VHL.Format.

ISO file identifier (ISO FID). If the card already contains a DESFire file with the same ISO FID, the existing file will be replaced. If this value is not specified (or 0x3F00), no ISO FID will be used.

Length of Key Integer (8 bits) Length of Key in byte
Key Raw data Key with preceding crypto byte. Please refer to Device / CryptoKey SubKey for more details.
Optional field, condition: (ConsideredCardType == ConsideredCardType.LEGICPrimeLegacy) or (ConsideredCardType == ConsideredCardType.LEGICAdvantLegacy) or (ConsideredCardType == ConsideredCardType.LEGICPrime) or (ConsideredCardType == ConsideredCardType.LEGICAdvantIso14443a) or (ConsideredCardType == ConsideredCardType.LEGICAdvantIso15693)
Length of SegmentInfo Integer (8 bits) Length of SegmentInfo in byte
SegmentInfo Raw data Either segment number or stamp, as defined in the EnStamp parameter. By default, the first segment will be accessed using its segment number.
EnStampLen Raw data (length 1 Byte) Fixed value 0x01
EnStamp Boolean (8 bits)

If true, SegmentInfo contains a stamp, i.e. the identifier of the application.
If false, it contains a segment number.

This parameter will only be evaluated if SegmentInfo has a length of 1. In this case, the reader can't distinguish between ID and stamp as a valid segment number always has length 1.
AdrModeLen Raw data (length 1 Byte) Fixed value 0x01
AdrMode Enumeration (8 bits)

Specifies the addressing mode. This parameter is only available on readers supporting LEGIC advant. LEGIC prime readers ignore it.

To allow for backward compatibility with LEGIC prime readers, omitting this parameter will not result in the default value, but in the following behavior: VHL address 0 is mapped to protocol header address 25, starting with the first data byte after the longest possible LEGIC prime stamp.
Values:
  • ProtocolHeader (0)

    To read the segment stamp, use this mode.

    VHL address 0 corresponds to protocol header address 18, starting with the first stamp data byte. The stamp, which has a length between 1 and 12 bytes, is followed by the application data.

  • Advant (1)

    To only read the application data of the segment, use this mode.

    VHL address 0 corresponds to address 0 in the user-specific application data area ("DATA area" according to the LEGIC documentation).

    For LEGIC prime cards, this addressing mode is available only with restrictions: Here, the stamp length is undefined - the card doesn't know it. So, when accessing the card using VHL.Setup, the stamp in SegmentInfo with the given length will be applied.

    If the actual stamp is longer, the reader assigns the remaining part of the stamp to the application data area (DATA). If the segment is accessed via segment number, no stamp length information is available at all. In this case, the application data area (DATA) contains the complete stamp (this is equivalent to the ProtocolHeader addressing mode).

    See the following table for examples.

    SegmentInfo EnStamp AdrMode Result of VHL.Read(Id=0xFF, Adr=0, Len=5)
    1 False ProtocolHeader 0x11 22 33 44 01
    0x11 22 33 True ProtocolHeader 0x11 22 33 44 01
    1 False Advant 0x11 22 33 44 01
    0x11 22 33 44 False Advant 0x01 02 03 04 05
    0x11 22 True Advant 0x33 44 01 02 03
Optional field, condition: ConsideredCardType == ConsideredCardType.Iso15693
FirstBlockLen Raw data (length 1 Byte) Fixed value 0x01
FirstBlock Integer (8 bits) First block of the application data
BlockCountLen Raw data (length 1 Byte) Fixed value 0x01
BlockCount Integer (8 bits) Number of blocks occupied by the application data
Optional field, condition: (ConsideredCardType == ConsideredCardType.Iso14443aInterIndustry) or (ConsideredCardType == ConsideredCardType.Iso14443aIntIndustryMif)
FileLenLength Raw data (length 1 Byte) Fixed value 0x04
FileLen Integer (32 bits) File length
SelectFileCmdList Array (until end of frame) -
FileSpecifierLen Raw data (length 1 Byte) Fixed value 0x01
FileSpecifier Enumeration (8 bits) The method to select the file.
Values:
  • SelectByPath (0x00)

    Select the file by path, i.e. a list of 16-bit file IDs
    If a single file ID is used, a MF, DF, or EF can be specified -> P1 is set to 0
    If a list of file ID is used, the path without the MF has to be specified -> P1 is set to 8

  • SelectByName (0x01)
    Select the file by DF name (1..16 bytes)
  • SelectByAPDU (0x02)
    Select the file using an APDU command
Length of FileDescriptor Integer (8 bits) Length of FileDescriptor in byte
FileDescriptor Raw data The path, filename, or APDU command by which to select the file. Depends on the method specified in FileSpecifier.

Returned values (response frame)

None