@@ -133,24 +133,29 @@ struct ResponseApdu
133133 }
134134};
135135
136- /* * Struct that wraps command APDUs. */
136+ /* *
137+ * Struct that wraps command APDUs.
138+ *
139+ * See for example http://cardwerk.com/iso-7816-smart-card-standard/ for a good overview of the
140+ * ISO 7816 part 4 standard that defines command APDUs.
141+ */
137142struct CommandApdu
138143{
139144 static constexpr size_t MAX_DATA_SIZE = 255 ;
140145
141- // Case 1
146+ // ISO 7816 part 4, Annex B.1, Case 1
142147 PCSC_CPP_CONSTEXPR_VECTOR CommandApdu (byte_type cls, byte_type ins, byte_type p1,
143148 byte_type p2) : d {cls, ins, p1, p2}
144149 {
145150 }
146151
147- // Case 2
152+ // ISO 7816 part 4, Annex B.1, Case 2
148153 PCSC_CPP_CONSTEXPR_VECTOR CommandApdu (byte_type cls, byte_type ins, byte_type p1, byte_type p2,
149154 byte_type le) : d {cls, ins, p1, p2, le}
150155 {
151156 }
152157
153- // Case 3
158+ // ISO 7816 part 4, Annex B.1, Case 3
154159 PCSC_CPP_CONSTEXPR_VECTOR CommandApdu (byte_type cls, byte_type ins, byte_type p1, byte_type p2,
155160 byte_vector data) : d {std::move (data)}
156161 {
@@ -160,7 +165,7 @@ struct CommandApdu
160165 d.insert (d.begin (), {cls, ins, p1, p2, static_cast <byte_type>(d.size ())});
161166 }
162167
163- // Case 4
168+ // ISO 7816 part 4, Annex B.1, Case 4
164169 PCSC_CPP_CONSTEXPR_VECTOR CommandApdu (byte_type cls, byte_type ins, byte_type p1, byte_type p2,
165170 byte_vector data, byte_type le) :
166171 CommandApdu {cls, ins, p1, p2, std::move (data)}
@@ -170,6 +175,23 @@ struct CommandApdu
170175
171176 constexpr operator const byte_vector&() const { return d; }
172177
178+ /* *
179+ * A helper function to create a SELECT command APDU.
180+ *
181+ * The ISO 7816-4 Section 6.11 SELECT command has the form:
182+ * CLA = 0x00
183+ * INS = 0xA4
184+ * P1 = varies, see below.
185+ * P2 = here hard-coded to 0x0C, no FCI (file control information) returned.
186+ * Lc and Data field = the file/path/AID identifier bytes.
187+ *
188+ * The P1 parameter for the SELECT command controls the selection mode,
189+ * we use the following modes:
190+ * 0x04 = Select AID (application identifier),
191+ * direct selection by DF (dedicated file, directory) name.
192+ * 0x08 = Select from MF (master file, root directory).
193+ * 0x09 = Select from current DF.
194+ */
173195 static PCSC_CPP_CONSTEXPR_VECTOR CommandApdu select (byte_type p1, byte_vector file)
174196 {
175197 return {0x00 , 0xA4 , p1, 0x0C , std::move (file)};
0 commit comments