SIM: several fixes

This commit is contained in:
Andreas Eversberg
2020-05-28 19:01:42 +02:00
parent 0cbabc39b1
commit a98b05beb0
4 changed files with 32 additions and 21 deletions

View File

@@ -28,6 +28,7 @@
#include <errno.h>
#include <math.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/time.h>
#include "../libdebug/debug.h"
#include "../liboptions/options.h"
@@ -101,7 +102,7 @@ void print_help(const char *arg0)
printf(" -A --authenticate 0x...\n");
printf(" Give 64 Bit value for authentication response. (default = all bits 1)\n");
printf("\nCommands are:\n");
printf(" sniff - To passively sniff ATR and message\n");
printf(" sniff - To passively sniff SIM card communication\n");
printf(" sim - To simulate a SIM card\n");
}
@@ -225,7 +226,7 @@ size_t eeprom_length(void)
int main_loop(serial_t *serial, int sniffer)
{
int rc, cts, last_cts = 0;
int rc, cts = 0, last_cts = 0;
uint8_t byte;
int skip_bytes = 0;
int work = 0;
@@ -333,7 +334,7 @@ int main(int argc, char *argv[])
debuglevel = DEBUG_INFO;
add_options();
rc = options_config_file("~/.osmocom/analog/simsim.conf", handle_options);
rc = options_config_file("~/.osmocom/analog/sim.conf", handle_options);
if (rc < 0)
return 0;
@@ -423,7 +424,7 @@ int main(int argc, char *argv[])
} else if (!strcmp(argv[argi], "sim")) {
sniffer = 0;
} else {
fprintf(stderr, "Unknown command '%s', use '-h' for help!\n", argv[argi]);
print_help(argv[0]);
return -EINVAL;
}
@@ -441,6 +442,13 @@ int main(int argc, char *argv[])
print_image();
decode_ebdt(ebdt_data, temp[0], temp[1], temp[2], temp[3], temp[4]);
printf("FUTLN=%s, Sicherungscode=%s, Kartekennung=%s, Sonderheitenschluessel=%s, Wartungsschluessel=%s\n", temp[0], temp[1], temp[2], temp[3], temp[4]);
for (i = 0; i < 8; i++)
temp[0][i] = eeprom_read(EEPROM_PIN_DATA + i);
temp[0][(eeprom_read(EEPROM_FLAGS) >> EEPROM_FLAG_PIN_LEN) & 0xf] = '\0';
uint64_t auth_value = 0;
for (i = 0; i < 8; i++)
auth_value |= eeprom_read(EEPROM_AUTH_DATA + i) << (8 * (7 - i));
printf("PIN=%s, auth response=0x%016" PRIx64 "\n", temp[0], auth_value);
printf("Telephone directory has %d entries.\n", directory_size() - 1);
for (i = 0; i < directory_size() - 1; i++) {
uint8_t data[24];

View File

@@ -472,21 +472,21 @@ static void sl_appl(sim_sim_t *sim, uint8_t *data, int length)
PDEBUG(DSIM7, DEBUG_INFO, " SL-APPL app %d\n", app);
/* if PIN is required */
if (sim->pin_required) {
return_pin_not_ok(sim);
return;
}
/* check application */
/* check and set application */
if (app != APP_NETZ_C && app != APP_RUFN_GEBZ) {
PDEBUG(DSIM7, DEBUG_NOTICE, "SL-APPL invalid app %d\n", sim->app);
return_error(sim);
return;
}
sim->app = app;
/* if PIN is required, we request it, but we've already selected the app */
if (sim->pin_required) {
return_pin_not_ok(sim);
return;
}
/* respond */
sim->app = app;
data = alloc_msg(sim, 0);
tx_sdu(sim, 0, data, 0);
}
@@ -913,7 +913,7 @@ static void aut_1(sim_sim_t *sim)
uint8_t *data;
int i;
PDEBUG(DSIM7, DEBUG_INFO, " RD-EBDT\n");
PDEBUG(DSIM7, DEBUG_INFO, " AUTH-1\n");
/* respond */
data = alloc_msg(sim, 1);
@@ -1337,7 +1337,10 @@ int sim_init_eeprom(void)
eeprom_write(EEPROM_FLAGS, (strlen(PIN_DEFAULT) << EEPROM_FLAG_PIN_LEN) | (MAX_PIN_TRY << EEPROM_FLAG_PIN_TRY));
for (i = 0; i < (int)strlen(PIN_DEFAULT); i++)
eeprom_write(EEPROM_PIN_DATA + i, PIN_DEFAULT[i]);
for (i = 0; i < 8; i++)
eeprom_write(EEPROM_AUTH_DATA + i, AUTH_DEFAULT >> ((7 - i) * 8));
/* now write magic characters to identify virgin or initialized EEPROM */
eeprom_write(EEPROM_MAGIC + 0, 'C');
eeprom_write(EEPROM_MAGIC + 1, '0' + EEPROM_VERSION);

View File

@@ -5,7 +5,7 @@
#define SONDER_DEFAULT "0"
#define WARTUNG_DEFAULT "65535"
#define PIN_DEFAULT "0000"
#define AUTH_DEFAULT "0xffffffffffffffff"
#define AUTH_DEFAULT ((uint64_t)0x000000000badefee)
enum l1_state {
L1_STATE_RESET = 0, /* reset is held */