apdu.h(3)

📦
version 2.2.0 · 2 versions
, in fedora 44

okay so bestie, you've opened apdu.h(3) — it lives in the Library Functions Manual (section 3, the library-functions one, iykyk) and it's literally the whole blueprint for talking to smart cards. Smart card commands and responses?? 💳 obsessed. Let's get into it. ✨


🎀 NAME 🎀

apdu.h — smart card commands and responses. That's the whole vibe. 🫶


✨ SYNOPSIS ✨

#include 'bee2/defs.h'

🌈 Classes

  • struct apdu_cmd_t — an APDU command 🫡
  • struct apdu_resp_t — an APDU response 💌

🌸 Functions

  • bool_t apduCmdIsValid(const apdu_cmd_t *cmd) — is this command valid or not?
  • size_t apduCmdEnc(octet apdu[], const apdu_cmd_t *cmd) — encode a command
  • size_t apduCmdDec(apdu_cmd_t *cmd, const octet apdu[], size_t count) — decode a command
  • bool_t apduRespIsValid(const apdu_resp_t *resp) — is this response valid or not?
  • size_t apduRespEnc(octet apdu[], const apdu_resp_t *resp) — encode a response
  • size_t apduRespDec(apdu_resp_t *resp, const octet apdu[], size_t count) — decode a response

📖 DETAILED DESCRIPTION 📖

👑 APDU commands

The following rules are implemented (see СТБ 34.101.79, п. 12.1):

  1. The mandatory components of a command are:
    • CLA — the command class (1 octet);
    • INS — the command instruction (1 octet);
    • P1 and P2 — the command parameters (1 octet each).
  2. The optional part of a command is the CDF component (an array of octets), which holds the command data. If the CDF component is present, then the command must also contain the optional Lc component, which defines the length of CDF.
  3. If executing the command is expected to produce a response containing the RDF component (more on that below), then the command must contain the optional Le component, which defines the maximum possible length of the RDF component in the expected response.
  4. If the command contains both the Lc and Le components, they can be represented in short or extended form. The form of Le must match the form of Lc. no cap, they have to match 🫠
  5. The short and extended forms are defined like this:
    • Lc in short form consists of a single octet, different from 0x00, defining values from 1 to 255;
    • Lc in extended form consists of three octets, where the first octet equals 0x00, and the remaining two octets are different from 0x0000 and define values from 1 to 65535;
    • Le in short form consists of a single octet defining values from 1 to 256 (the value 256 corresponds to 0x00);
    • if the Lc component is present in the command, then Le in extended form consists of two octets, which define values from 1 to 65536 (the value 65536 corresponds to 0x0000);
    • if the Lc component is absent from the command, then Le in extended form consists of three octets, where the first octet equals 0x00, and the following two octets define values from 1 to 65536 (the value 65536 corresponds to 0x0000).
  6. big-endian conventions are used when encoding lengths. 💅

🦋 APDU responses

The following rules are implemented (see СТБ 34.101.79, п. 12.1):

  1. The mandatory components of a response are the command processing statuses SW1 and SW2 (1 octet each).
  2. The optional part of a response is the RDF component (an array of octets), which contains the response data.

🔥 FUNCTIONS 🔥

🌟 size_t apduCmdDec(apdu_cmd_t *cmd, const octet apdu[], size_t count)

The length of the memory buffer for placing the command represented by the code [count]apdu is determined. If cmd != 0, then the command is placed at this address.

Precondition

  • The buffer [count]apdu is valid.
  • If the address cmd != 0, then apduCmdDer(0, apdu, count) octets are reserved at this address.
  • The buffers apdu and cmd do not overlap.

Returns

The number of octets for placing the command, or SIZE_MAX in case of an error. 😭

Arguments

  • cmd — command
  • apdu — command code
  • count — length of apdu in octets

🌟 size_t apduCmdEnc(octet apdu[], const apdu_cmd_t *cmd)

The number of octets in the code of the command cmd is determined. If apdu != 0, then the code is placed at this address.

Precondition

  • The command cmd is valid.
  • If the address apdu != 0, then apduCmdEnc(0, cmd) octets are reserved at this address.

Note

  • The buffers apdu and cmd do not overlap.

Returns

The number of octets in the code, or SIZE_MAX in case of an error.

Arguments

  • apdu — command code
  • cmd — command

🌟 bool_t apduCmdIsValid(const apdu_cmd_t *cmd)

The validity of the command cmd is checked.

Returns

The validity flag. ✅

Arguments

  • cmd — command

🌟 size_t apduRespDec(apdu_resp_t *resp, const octet apdu[], size_t count)

The length of the memory buffer for placing the response represented by the code [count]apdu is determined. If resp != 0, then the response is placed at this address.

Precondition

  • The buffer [count]apdu is valid.
  • If the address resp != 0, then apduRespDer(0, apdu, count) octets are reserved at this address.

Note

  • The buffers apdu and resp do not overlap.

Returns

The number of octets for placing the response, or SIZE_MAX in case of an error.

Arguments

  • resp — response
  • apdu — response code
  • count — length of apdu in octets

🌟 size_t apduRespEnc(octet apdu[], const apdu_resp_t *resp)

The number of octets in the code of the response resp is determined. If apdu != 0, then the code is placed at this address.

Precondition

  • The response resp is valid.
  • If the address apdu != 0, then apduRespEnc(0, resp) octets are reserved at this address.

Note

  • The buffers apdu and resp do not overlap.

Returns

The number of octets in the code, or SIZE_MAX in case of an error.

Arguments

  • apdu — response code
  • resp — response

🌟 bool_t apduRespIsValid(const apdu_resp_t *resp)

The validity of the response resp is checked.

Returns

The validity flag. ✅

Arguments

  • resp — response

🫶 AUTHOR 🫶

Automatically generated by Doxygen for the Библиотека Bee2 from the source text. (Not a human author, just a robot doing its little thing 🤖💖)


and that's a wrap, bestie 🎀 — this page came to you courtesy of Библиотека Bee2, stamped Вс 25 Янв 2026 00:00:00 (yes, that's Sun 25 Jan 2026, 00:00:00, we love a precise timestamp). go forth and slay your smart card comms. 💅✨🦋

📦 where this page comes from