summaryrefslogtreecommitdiffstats
path: root/src/target/firmware/layer1/l23_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/target/firmware/layer1/l23_api.c')
-rw-r--r--src/target/firmware/layer1/l23_api.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/src/target/firmware/layer1/l23_api.c b/src/target/firmware/layer1/l23_api.c
index ae39e634..4bf8a83a 100644
--- a/src/target/firmware/layer1/l23_api.c
+++ b/src/target/firmware/layer1/l23_api.c
@@ -20,7 +20,8 @@
*
*/
-#define DEBUG
+/* Uncomment to debug */
+/* #define DEBUG */
#include <stdint.h>
#include <stdio.h>
@@ -571,7 +572,7 @@ static void l1ctl_sim_req(struct msgb *msg)
uint16_t len = msg->len - sizeof(struct l1ctl_hdr);
uint8_t *data = msg->data + sizeof(struct l1ctl_hdr);
-#if 1 /* for debugging only */
+#ifdef DEBUG /* for debugging only */
{
int i;
printf("SIM Request (%u): ", len);
@@ -584,6 +585,53 @@ static void l1ctl_sim_req(struct msgb *msg)
sim_apdu(len, data);
}
+void l1ctl_tx_sim_up(uint8_t* atr, uint8_t atrLength)
+{
+ struct msgb *msg = l1ctl_msgb_alloc(L1CTL_SIM_ATR);
+ uint8_t *data;
+ data = (uint8_t*) msgb_put(msg, atrLength);
+ memcpy(data, atr, atrLength);
+ msg->len += atrLength;
+
+ l1_queue_for_l2(msg);
+}
+
+static int powered_up = 0;
+
+static void l1ctl_rx_sim_powerup()
+{
+ uint8_t atr[20];
+ uint8_t atrLength = 0;
+
+ if (powered_up) {
+ puts("SIM: sim is already powered up, calling power down first!\n");
+ calypso_sim_powerdown();
+ }
+
+ memset(atr,0,sizeof(atr));
+
+ atrLength = calypso_sim_powerup(atr);
+ l1ctl_tx_sim_up(atr, atrLength);
+ powered_up = 1;
+}
+
+static void l1ctl_rx_sim_powerdown()
+{
+ calypso_sim_powerdown();
+ powered_up = 0;
+}
+
+static void l1ctl_rx_sim_reset()
+{
+ uint8_t atr[20];
+ uint8_t atrLength = 0;
+
+ memset(atr,0,sizeof(atr));
+
+ atrLength = calypso_sim_reset(atr);
+ l1ctl_tx_sim_up(atr, atrLength);
+}
+
static struct llist_head l23_rx_queue = LLIST_HEAD_INIT(l23_rx_queue);
/* callback from SERCOMM when L2 sends a message to L1 */
@@ -675,6 +723,15 @@ void l1a_l23_handler(void)
case L1CTL_SIM_REQ:
l1ctl_sim_req(msg);
break;
+ case L1CTL_SIM_POWERUP:
+ l1ctl_rx_sim_powerup();
+ break;
+ case L1CTL_SIM_POWERDOWN:
+ l1ctl_rx_sim_powerdown();
+ break;
+ case L1CTL_SIM_RESET:
+ l1ctl_rx_sim_reset();
+ break;
}
exit_msgbfree: