mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-19 14:58:35 +03:00
octsimtest: most code for support of this new board
* code for controlling the Card slot + frequencyt divider muxes * put everything in place to build cardem application for it Change-Id: I7e03e0c0f2999a1ce2dad966d98e22033fa58465
This commit is contained in:
@@ -57,7 +57,7 @@
|
|||||||
/* Phone USIM slot 1 VCC pin (VCC_PHONE in schematic) */
|
/* Phone USIM slot 1 VCC pin (VCC_PHONE in schematic) */
|
||||||
#define PIN_USIM1_VCC {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
#define PIN_USIM1_VCC {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||||
/* Phone USIM slot 1 RST pin (active low; RST_PHONE in schematic) */
|
/* Phone USIM slot 1 RST pin (active low; RST_PHONE in schematic) */
|
||||||
#define PIN_USIM1_nRST {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_IT_RISE_EDGE | PIO_DEGLITCH }
|
#define PIN_USIM1_nRST {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_IT_EDGE | PIO_DEGLITCH }
|
||||||
/* Phone I/O data signal input/output (I/O_PHONE in schematic) */
|
/* Phone I/O data signal input/output (I/O_PHONE in schematic) */
|
||||||
#define PIN_PHONE_IO {PIO_PA22A_TXD1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
#define PIN_PHONE_IO {PIO_PA22A_TXD1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||||
/* Phone CLK clock input (CLK_PHONE in schematic) */
|
/* Phone CLK clock input (CLK_PHONE in schematic) */
|
||||||
@@ -102,13 +102,15 @@
|
|||||||
/* Indicate SIMtrace is bus power in USB attributes */
|
/* Indicate SIMtrace is bus power in USB attributes */
|
||||||
#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
|
#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
|
||||||
|
|
||||||
|
#define DETECT_VCC_BY_ADC
|
||||||
|
|
||||||
/** Supported modes */
|
/** Supported modes */
|
||||||
/* SIMtrace board supports sniffer mode */
|
/* SIMtrace board supports sniffer mode */
|
||||||
//#define HAVE_SNIFFER
|
//#define HAVE_SNIFFER
|
||||||
/* SIMtrace board supports CCID mode */
|
/* SIMtrace board supports CCID mode */
|
||||||
//#define HAVE_CCID
|
//#define HAVE_CCID
|
||||||
/* SIMtrace board supports card emulation mode */
|
/* SIMtrace board supports card emulation mode */
|
||||||
//#define HAVE_CARDEM
|
#define HAVE_CARDEM
|
||||||
/* SIMtrace board supports man-in-the-middle mode */
|
/* SIMtrace board supports man-in-the-middle mode */
|
||||||
//#define HAVE_MITM
|
//#define HAVE_MITM
|
||||||
/* octsimtest board supports gpio_test mode */
|
/* octsimtest board supports gpio_test mode */
|
||||||
|
|||||||
16
firmware/libboard/octsimtest/include/mux.h
Normal file
16
firmware/libboard/octsimtest/include/mux.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void mux_init(void);
|
||||||
|
void mux_set_slot(uint8_t s);
|
||||||
|
void mux_set_freq(uint8_t s);
|
||||||
|
|
||||||
|
/* this reflects the wiring between U5 and U4 */
|
||||||
|
#define MUX_FREQ_DIV_2 0
|
||||||
|
#define MUX_FREQ_DIV_4 1
|
||||||
|
#define MUX_FREQ_DIV_16 2
|
||||||
|
#define MUX_FREQ_DIV_32 3
|
||||||
|
#define MUX_FREQ_DIV_32 3
|
||||||
|
#define MUX_FREQ_DIV_128 4
|
||||||
|
#define MUX_FREQ_DIV_512 5
|
||||||
|
#define MUX_FREQ_DIV_2048 6
|
||||||
|
#define MUX_FREQ_DIV_4096 7
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "usb_buf.h"
|
#include "usb_buf.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "mcp23017.h"
|
#include "mcp23017.h"
|
||||||
|
#include "mux.h"
|
||||||
|
|
||||||
void board_exec_dbg_cmd(int ch)
|
void board_exec_dbg_cmd(int ch)
|
||||||
{
|
{
|
||||||
@@ -34,7 +35,16 @@ void board_exec_dbg_cmd(int ch)
|
|||||||
printf("\tR\treset SAM3\n\r");
|
printf("\tR\treset SAM3\n\r");
|
||||||
printf("\tm\trun mcp23017 test\n\r");
|
printf("\tm\trun mcp23017 test\n\r");
|
||||||
printf("\tR\ttoggle MSB of gpio on mcp23017\n\r");
|
printf("\tR\ttoggle MSB of gpio on mcp23017\n\r");
|
||||||
|
printf("\t0-8\tselect physical SIM slot\n\r");
|
||||||
break;
|
break;
|
||||||
|
case '0': mux_set_slot(0); break;
|
||||||
|
case '1': mux_set_slot(1); break;
|
||||||
|
case '2': mux_set_slot(2); break;
|
||||||
|
case '3': mux_set_slot(3); break;
|
||||||
|
case '4': mux_set_slot(4); break;
|
||||||
|
case '5': mux_set_slot(5); break;
|
||||||
|
case '6': mux_set_slot(6); break;
|
||||||
|
case '7': mux_set_slot(7); break;
|
||||||
case 'R':
|
case 'R':
|
||||||
printf("Asking NVIC to reset us\n\r");
|
printf("Asking NVIC to reset us\n\r");
|
||||||
USBD_Disconnect();
|
USBD_Disconnect();
|
||||||
@@ -57,6 +67,7 @@ void board_main_top(void)
|
|||||||
#ifndef APPLICATION_dfu
|
#ifndef APPLICATION_dfu
|
||||||
usb_buf_init();
|
usb_buf_init();
|
||||||
|
|
||||||
|
mux_init();
|
||||||
i2c_pin_init();
|
i2c_pin_init();
|
||||||
if (!mcp23017_init(MCP23017_ADDRESS))
|
if (!mcp23017_init(MCP23017_ADDRESS))
|
||||||
printf("mcp23017 not found!\n\r");
|
printf("mcp23017 not found!\n\r");
|
||||||
|
|||||||
99
firmware/libboard/octsimtest/source/mux.c
Normal file
99
firmware/libboard/octsimtest/source/mux.c
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
/* sysmoOCTSIMTEST support for multiplexers
|
||||||
|
*
|
||||||
|
* (C) 2021 by Harald Welte <laforge@gnumonks.org>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "board.h"
|
||||||
|
#include "mux.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/* 3-bit S0..S2 signal for slot selection */
|
||||||
|
static const Pin pin_in_sel[3] = {
|
||||||
|
{ PIO_PA1, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
|
||||||
|
{ PIO_PA2, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
|
||||||
|
{ PIO_PA3, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 3-bit S0..S2 signal for frequency divider selection */
|
||||||
|
static const Pin pin_freq_sel[3] = {
|
||||||
|
{ PIO_PA16, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
|
||||||
|
{ PIO_PA17, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
|
||||||
|
{ PIO_PA18, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* low-active output enable for all muxes */
|
||||||
|
static const Pin pin_oe = { PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT };
|
||||||
|
|
||||||
|
/* initialize the external 1:8 multiplexers */
|
||||||
|
void mux_init(void)
|
||||||
|
{
|
||||||
|
PIO_Configure(&pin_oe, PIO_LISTSIZE(pin_oe));
|
||||||
|
PIO_Configure(pin_in_sel, PIO_LISTSIZE(pin_in_sel));
|
||||||
|
PIO_Configure(pin_freq_sel, PIO_LISTSIZE(pin_freq_sel));
|
||||||
|
|
||||||
|
mux_set_slot(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the slot selection mux */
|
||||||
|
void mux_set_slot(uint8_t s)
|
||||||
|
{
|
||||||
|
printf("%s(%u)\r\n", __func__, s);
|
||||||
|
|
||||||
|
/* !OE = H: disconnect input and output of muxes */
|
||||||
|
PIO_Set(&pin_oe);
|
||||||
|
|
||||||
|
if (s & 1)
|
||||||
|
PIO_Set(&pin_in_sel[0]);
|
||||||
|
else
|
||||||
|
PIO_Clear(&pin_in_sel[0]);
|
||||||
|
if (s & 2)
|
||||||
|
PIO_Set(&pin_in_sel[1]);
|
||||||
|
else
|
||||||
|
PIO_Clear(&pin_in_sel[1]);
|
||||||
|
if (s & 4)
|
||||||
|
PIO_Set(&pin_in_sel[2]);
|
||||||
|
else
|
||||||
|
PIO_Clear(&pin_in_sel[2]);
|
||||||
|
|
||||||
|
/* !OE = L: (re-)enable the output of muxes */
|
||||||
|
PIO_Clear(&pin_oe);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the frequency divider mux */
|
||||||
|
void mux_set_freq(uint8_t s)
|
||||||
|
{
|
||||||
|
printf("%s(%u)\r\n", __func__, s);
|
||||||
|
|
||||||
|
/* no need for 'break before make' here, this would also affect
|
||||||
|
* the SIM card I/O signals which we don't want to disturb */
|
||||||
|
|
||||||
|
if (s & 1)
|
||||||
|
PIO_Set(&pin_freq_sel[0]);
|
||||||
|
else
|
||||||
|
PIO_Clear(&pin_freq_sel[0]);
|
||||||
|
if (s & 2)
|
||||||
|
PIO_Set(&pin_freq_sel[1]);
|
||||||
|
else
|
||||||
|
PIO_Clear(&pin_freq_sel[1]);
|
||||||
|
if (s & 4)
|
||||||
|
PIO_Set(&pin_freq_sel[2]);
|
||||||
|
else
|
||||||
|
PIO_Clear(&pin_freq_sel[2]);
|
||||||
|
|
||||||
|
/* !OE = L: ensure enable the output of muxes */
|
||||||
|
PIO_Clear(&pin_oe);
|
||||||
|
}
|
||||||
37
firmware/libboard/octsimtest/source/sim_switch.c
Normal file
37
firmware/libboard/octsimtest/source/sim_switch.c
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/* Code to switch between local (physical) and remote (emulated) SIM
|
||||||
|
*
|
||||||
|
* (C) 2021 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
#include "board.h"
|
||||||
|
#include "trace.h"
|
||||||
|
#include "sim_switch.h"
|
||||||
|
|
||||||
|
int sim_switch_use_physical(unsigned int nr, int physical)
|
||||||
|
{
|
||||||
|
if (physical) {
|
||||||
|
TRACE_ERROR("%u: Use local/physical SIM - UNSUPPORTED!\r\n", nr);
|
||||||
|
} else {
|
||||||
|
TRACE_INFO("%u: Use remote/emulated SIM\r\n", nr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sim_switch_init(void)
|
||||||
|
{
|
||||||
|
return 1; // SIMtrace hardware has only one switchable interface
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user