Files
simtrace2/host/include/osmocom/simtrace2/apdu_dispatch.h
T
Alexander Couzens 63a61bfdaf Add osmo_apdu_segment_in2() to ensure correct parsing of GP GET DATA
osmo_apdu_segment_in() doesn't have the context of the previous APDU,
for nearly all calls this is fine, except for GP GET DATA, which can be
a case 2 or case 4 APDU.
GP GET DATA defines the Le field as 0x00 which is used by osmo_apdu_segment_in
to detect if it is a case 2 or case 4.
However a card can respond with the SW 6cXX, which means the previous
command must be resend with a Le field XX, which got misinterpreted by
the osmo_apdu_segment_in() as a case 4 resulting in a timeout waiting for
more data.

Modem <-> Card
81cadf2000 ->
 <- 6c0b
81cadf200b ->
 -- Simtrace waits for more data because it wrongly decodes it as APDU case 4
    instead of case 2.

Related: SYS#8147
Change-Id: Ie238662e7e6a10dd4283ede0c8d8d73bc375c247
2026-08-18 15:31:43 +00:00

51 lines
1.4 KiB
C

/* apdu_dispatch - State machine to determine Rx/Tx phases of APDU
*
* (C) 2016-2019 by Harald Welte <hwelte@hmw-consulting.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <osmocom/sim/sim.h>
struct osmo_apdu_context {
struct osim_apdu_cmd_hdr hdr;
uint8_t dc[256];
uint8_t de[256];
uint8_t sw[2];
uint8_t apdu_case;
struct {
uint8_t tot;
uint8_t cur;
} lc;
struct {
uint8_t tot;
uint8_t cur;
} le;
};
enum osmo_apdu_action {
APDU_ACT_TX_CAPDU_TO_CARD = 0x0001,
APDU_ACT_RX_MORE_CAPDU_FROM_READER = 0x0002,
};
const char *osmo_apdu_dump_context_buf(char *buf, unsigned int buf_len,
const struct osmo_apdu_context *ac);
int osmo_apdu_segment_in(struct osmo_apdu_context *ac, const uint8_t *apdu_buf,
unsigned int apdu_len, bool new_apdu);
int osmo_apdu_segment_in2(struct osmo_apdu_context *ac, struct osmo_apdu_context *prev_ac,
const uint8_t *apdu_buf, unsigned int apdu_len, bool new_apdu);