Change in osmo-ccid-firmware[master]: Add various SIM card related debug command

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Kévin Redon gerrit-no-reply at lists.osmocom.org
Wed Feb 27 13:46:17 UTC 2019


Kévin Redon has submitted this change and it was merged. ( https://gerrit.osmocom.org/13037 )

Change subject: Add various SIM card related debug command
......................................................................

Add various SIM card related debug command

this allows commands like
 sim-status 0		# read the status
 sim-voltage 0 5	# set voltage to 5V
 sim-clkdiv 0 2		# set clock-divider to 2 (10 MHz)
 sim-reset 0 0		# disable reset
 sim-power 0 1		# enable power

Change-Id: Id6131be60d37cba769c79952fa44f3ec6c976a38
---
M sysmoOCTSIM/main.c
M sysmoOCTSIM/ncn8025.c
M sysmoOCTSIM/ncn8025.h
3 files changed, 193 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Kévin Redon: Looks good to me, approved



diff --git a/sysmoOCTSIM/main.c b/sysmoOCTSIM/main.c
index ef87162..dc67406 100644
--- a/sysmoOCTSIM/main.c
+++ b/sysmoOCTSIM/main.c
@@ -16,6 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
 
+#include <stdlib.h>
+#include <stdio.h>
 #include <parts.h>
 #include <hal_cache.h>
 #include <hri_port_e54.h>
@@ -55,6 +57,163 @@
 	printf("Hello World!\r\n");
 }
 
+static int validate_slotnr(int argc, char **argv, int idx)
+{
+	int slotnr;
+	if (argc < idx+1) {
+		printf("You have to specify the slot number (0..7)\r\n");
+		return -1;
+	}
+	slotnr = atoi(argv[idx]);
+	if (slotnr < 0 || slotnr > 7) {
+		printf("You have to specify the slot number (0..7)\r\n");
+		return -1;
+	}
+	return slotnr;
+}
+
+DEFUN(sim_status, cmd_sim_status, "sim-status", "Get state of specified NCN8025")
+{
+	struct ncn8025_settings settings;
+	int slotnr = validate_slotnr(argc, argv, 1);
+	if (slotnr < 0)
+		return;
+	ncn8025_get(slotnr, &settings);
+	printf("SIM%d: ", slotnr);
+	ncn8025_dump(&settings);
+	printf("\r\n");
+}
+
+DEFUN(sim_power, cmd_sim_power, "sim-power", "Enable/disable SIM card power")
+{
+	struct ncn8025_settings settings;
+	int slotnr = validate_slotnr(argc, argv, 1);
+	int enable;
+
+	if (slotnr < 0)
+		return;
+
+	if (argc < 3) {
+		printf("You have to specify 0=disable or 1=enable\r\n");
+		return;
+	}
+	enable = atoi(argv[2]);
+	ncn8025_get(slotnr, &settings);
+	if (enable)
+		settings.cmdvcc = true;
+	else
+		settings.cmdvcc = false;
+	ncn8025_set(slotnr, &settings);
+}
+
+DEFUN(sim_reset, cmd_sim_reset, "sim-reset", "Enable/disable SIM reset")
+{
+	struct ncn8025_settings settings;
+	int slotnr = validate_slotnr(argc, argv, 1);
+	int enable;
+
+	if (slotnr < 0)
+		return;
+
+	if (argc < 3) {
+		printf("You have to specify 0=disable or 1=enable\r\n");
+		return;
+	}
+	enable = atoi(argv[2]);
+	ncn8025_get(slotnr, &settings);
+	if (enable)
+		settings.rstin = true;
+	else
+		settings.rstin = false;
+	ncn8025_set(slotnr, &settings);
+}
+
+DEFUN(sim_clkdiv, cmd_sim_clkdiv, "sim-clkdiv", "Set SIM clock divider (1,2,4,8)")
+{
+	struct ncn8025_settings settings;
+	int slotnr = validate_slotnr(argc, argv, 1);
+	int clkdiv;
+
+	if (slotnr < 0)
+		return;
+
+	if (argc < 3) {
+		printf("You have to specify a valid divider (1,2,4,8)\r\n");
+		return;
+	}
+	clkdiv = atoi(argv[2]);
+	if (clkdiv != 1 && clkdiv != 2 && clkdiv != 4 && clkdiv != 8) {
+		printf("You have to specify a valid divider (1,2,4,8)\r\n");
+		return;
+	}
+	ncn8025_get(slotnr, &settings);
+	switch (clkdiv) {
+	case 1:
+		settings.clkdiv = SIM_CLKDIV_1;
+		break;
+	case 2:
+		settings.clkdiv = SIM_CLKDIV_2;
+		break;
+	case 4:
+		settings.clkdiv = SIM_CLKDIV_4;
+		break;
+	case 8:
+		settings.clkdiv = SIM_CLKDIV_8;
+		break;
+	}
+	ncn8025_set(slotnr, &settings);
+}
+
+DEFUN(sim_voltage, cmd_sim_voltage, "sim-voltage", "Set SIM voltage (5/3/1.8)")
+{
+	struct ncn8025_settings settings;
+	int slotnr = validate_slotnr(argc, argv, 1);
+
+	if (slotnr < 0)
+		return;
+
+	if (argc < 3) {
+		printf("You have to specify a valid voltage (5/3/1.8)\r\n");
+		return;
+	}
+	ncn8025_get(slotnr, &settings);
+	if (!strcmp(argv[2], "5"))
+		settings.vsel = SIM_VOLT_5V0;
+	else if (!strcmp(argv[2], "3"))
+		settings.vsel = SIM_VOLT_3V0;
+	else if (!strcmp(argv[2], "1.8"))
+		settings.vsel = SIM_VOLT_1V8;
+	else {
+		printf("You have to specify a valid voltage (5/3/1.8)\r\n");
+		return;
+	}
+	ncn8025_set(slotnr, &settings);
+}
+
+DEFUN(sim_led, cmd_sim_led, "sim-led", "Set SIM LED (1=on, 0=off)")
+{
+	struct ncn8025_settings settings;
+	int slotnr = validate_slotnr(argc, argv, 1);
+
+	if (slotnr < 0)
+		return;
+
+	if (argc < 3) {
+		printf("You have to specify 0=disable or 1=enable\r\n");
+		return;
+	}
+	ncn8025_get(slotnr, &settings);
+	if (atoi(argv[2]))
+		settings.led = true;
+	else
+		settings.led = false;
+	ncn8025_set(slotnr, &settings);
+}
+
+
+
+
+
 int main(void)
 {
 	atmel_start_init();
@@ -66,6 +225,12 @@
 	board_init();
 	command_init("sysmoOCTSIM> ");
 	command_register(&cmd_hello);
+	command_register(&cmd_sim_status);
+	command_register(&cmd_sim_power);
+	command_register(&cmd_sim_reset);
+	command_register(&cmd_sim_clkdiv);
+	command_register(&cmd_sim_voltage);
+	command_register(&cmd_sim_led);
 
 	printf("\r\n\r\nsysmocom sysmoOCTSIM\r\n");
 	while (true) { // main loop
diff --git a/sysmoOCTSIM/ncn8025.c b/sysmoOCTSIM/ncn8025.c
index 99b93b8..5f9b03d 100644
--- a/sysmoOCTSIM/ncn8025.c
+++ b/sysmoOCTSIM/ncn8025.c
@@ -8,6 +8,7 @@
 
 #include <stdint.h>
 #include <string.h>
+#include <stdio.h>
 #include <utils_assert.h>
 #include <utils.h>
 #include "octsim_i2c.h"
@@ -134,3 +135,29 @@
 		return rc;
 	return ncn8025_set(slot, &def_settings);
 }
+
+static const char *volt_str[] = {
+	[SIM_VOLT_3V0] = "3.0",
+	[SIM_VOLT_5V0] = "5.0",
+	[SIM_VOLT_1V8] = "1.8",
+};
+
+static const unsigned int div_val[] = {
+	[SIM_CLKDIV_1] = 1,
+	[SIM_CLKDIV_2] = 2,
+	[SIM_CLKDIV_4] = 4,
+	[SIM_CLKDIV_8] = 8,
+};
+
+void ncn8025_dump(const struct ncn8025_settings *set)
+{
+	printf("VOLT=%s, CLKDIV=%u", volt_str[set->vsel], div_val[set->clkdiv]);
+	if (set->rstin)
+		printf(", RST");
+	if (set->cmdvcc)
+		printf(", VCC");
+	if (set->simpres)
+		printf(", SIMPRES");
+	if (set->led)
+		printf(", LED");
+}
diff --git a/sysmoOCTSIM/ncn8025.h b/sysmoOCTSIM/ncn8025.h
index a392c5d..79e8b60 100644
--- a/sysmoOCTSIM/ncn8025.h
+++ b/sysmoOCTSIM/ncn8025.h
@@ -26,3 +26,4 @@
 int ncn8025_set(uint8_t slot, const struct ncn8025_settings *set);
 int ncn8025_get(uint8_t slot, struct ncn8025_settings *set);
 int ncn8025_init(unsigned int slot);
+void ncn8025_dump(const struct ncn8025_settings *set);

-- 
To view, visit https://gerrit.osmocom.org/13037
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ccid-firmware
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id6131be60d37cba769c79952fa44f3ec6c976a38
Gerrit-Change-Number: 13037
Gerrit-PatchSet: 4
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Kévin Redon <kredon at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190227/4b55e265/attachment.htm>


More information about the gerrit-log mailing list