apdu.h(3)
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 commandsize_t apduCmdDec(apdu_cmd_t *cmd, const octet apdu[], size_t count)— decode a commandbool_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 responsesize_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):
- The mandatory components of a command are:
CLA— the command class (1 octet);INS— the command instruction (1 octet);P1andP2— the command parameters (1 octet each).
- The optional part of a command is the
CDFcomponent (an array of octets), which holds the command data. If theCDFcomponent is present, then the command must also contain the optionalLccomponent, which defines the length ofCDF. - If executing the command is expected to produce a response containing the
RDFcomponent (more on that below), then the command must contain the optionalLecomponent, which defines the maximum possible length of theRDFcomponent in the expected response. - If the command contains both the
LcandLecomponents, they can be represented in short or extended form. The form ofLemust match the form ofLc. no cap, they have to match 🫠 - The short and extended forms are defined like this:
Lcin short form consists of a single octet, different from0x00, defining values from 1 to 255;Lcin extended form consists of three octets, where the first octet equals0x00, and the remaining two octets are different from0x0000and define values from 1 to 65535;Lein short form consists of a single octet defining values from 1 to 256 (the value 256 corresponds to0x00);- if the
Lccomponent is present in the command, thenLein extended form consists of two octets, which define values from 1 to 65536 (the value 65536 corresponds to0x0000); - if the
Lccomponent is absent from the command, thenLein extended form consists of three octets, where the first octet equals0x00, and the following two octets define values from 1 to 65536 (the value 65536 corresponds to0x0000).
- big-endian conventions are used when encoding lengths. 💅
🦋 APDU responses
The following rules are implemented (see СТБ 34.101.79, п. 12.1):
- The mandatory components of a response are the command processing statuses
SW1andSW2(1 octet each). - The optional part of a response is the
RDFcomponent (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]apduis valid. - If the address
cmd != 0, thenapduCmdDer(0, apdu, count)octets are reserved at this address. - The buffers
apduandcmddo not overlap.
Returns
The number of octets for placing the command, or SIZE_MAX in case of an error. 😭
Arguments
cmd— commandapdu— command codecount— length ofapduin 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
cmdis valid. - If the address
apdu != 0, thenapduCmdEnc(0, cmd)octets are reserved at this address.
Note
- The buffers
apduandcmddo not overlap.
Returns
The number of octets in the code, or SIZE_MAX in case of an error.
Arguments
apdu— command codecmd— 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]apduis valid. - If the address
resp != 0, thenapduRespDer(0, apdu, count)octets are reserved at this address.
Note
- The buffers
apduandrespdo not overlap.
Returns
The number of octets for placing the response, or SIZE_MAX in case of an error.
Arguments
resp— responseapdu— response codecount— length ofapduin 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
respis valid. - If the address
apdu != 0, thenapduRespEnc(0, resp)octets are reserved at this address.
Note
- The buffers
apduandrespdo not overlap.
Returns
The number of octets in the code, or SIZE_MAX in case of an error.
Arguments
apdu— response coderesp— 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
- fedora 44: bee2-devel 2.2.0-1.fc44 · GPL-3.0-only and GPL-3.0-or-later
- fedora 44: bee2-devel 2.2.0-1.fc44 · GPL-3.0-only and GPL-3.0-or-later
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms