view serial/spenh.c @ 93:6041c601304d

fcsim1-mkprov: revert OTA key addition It appears that GrcardSIM2 cards (which is what we got for FCSIM1) do not support OTA after all, contrary to what we were previously led to believe by some tech support emails from Grcard - apparently those support emails and OTA descriptions referred to some other card model(s).
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 21 Apr 2021 05:38:39 +0000
parents fbedb67d234f
children
line wrap: on
line source

/*
 * This module implements speed enhancement logic for our serial
 * SIM interface back end.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>

extern u_char atr_buf[];
extern unsigned baud_spenh, spenh_host_max;
extern int inverse_coding;

void
spenh_logic()
{
	unsigned spenh_sim_max, use_spenh;
	u_char pts_req[4], pts_resp[4];
	int rc;

	if (!(atr_buf[1] & 0x10)) {
no_spenh:	printf("X SIM does not support speed enhancement\n");
		return;
	}
	switch (atr_buf[2]) {
	case 0x94:
		spenh_sim_max = 1;
		break;
	case 0x95:
		spenh_sim_max = 2;
		break;
	case 0x96:
		spenh_sim_max = 4;
		break;
	case 0x97:
		spenh_sim_max = 8;
		break;
	default:
		goto no_spenh;
	}
	use_spenh = spenh_sim_max;
	if (use_spenh > spenh_host_max)
		use_spenh = spenh_host_max;
	pts_req[0] = 0xFF;
	pts_req[1] = 0x10;
	switch (use_spenh) {
	case 1:
		pts_req[2] = 0x94;
		break;
	case 2:
		pts_req[2] = 0x95;
		break;
	case 4:
		pts_req[2] = 0x96;
		break;
	case 8:
		pts_req[2] = 0x97;
		break;
	}
	pts_req[3] = pts_req[0] ^ pts_req[1] ^ pts_req[2];
	rc = send_bytes_to_sim(pts_req, 4);
	if (rc < 0)
		exit(1);
	rc = collect_bytes_from_sim(pts_resp, 4);
	if (rc < 0)
		exit(1);
	if (bcmp(pts_req, pts_resp, 4)) {
		fprintf(stderr, "error: PTS response does not match request\n");
		exit(1);
	}
	set_serial_params(baud_spenh * use_spenh, inverse_coding);
	printf("X Using F=512 D=%u speed enhancement\n", use_spenh * 8);
}