view libutil/gsm7_encode.c @ 99:97ba63d9361a

scripts/fcsim1-sst: turn off STK & OTA services In the initial unprogrammed state of the cards from Grcard, SST has services 25 through 29 set to allocated and activated. However, these cards appear to not actually support OTA, ENVELOPE commands do nothing (just return SW 9000), and they were never observed issuing any proactive SIM commands, even after a feature-generous TERMINAL PROFILE. Therefore, let's list these STK & OTA services as allocated, but not activated in our FCSIM1 SST.
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 05 May 2021 04:26:07 +0000
parents 1b905e730abd
children
line wrap: on
line source

/*
 * This module implements functions for parsing quoted string
 * arguments intended for GSM7 string encoding, and actually
 * encoding them into GSM7 binary strings.
 */

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

extern u_char gsm7_encode_table[256];

qstring_arg_to_gsm7(arg, record, maxlen)
	char *arg;
	u_char *record;
	unsigned maxlen;
{
	unsigned acclen, nadd;
	char *cp;
	int c;

	cp = arg;
	for (acclen = 0; *cp; ) {
		c = *cp++;
		if (c == '\\') {
			if (*cp == '\0') {
				fprintf(stderr,
					"error: dangling backslash escape\n");
				return(-1);
			}
			c = *cp++;
			if (c >= '0' && c <= '7' && isxdigit(*cp)) {
				c = ((c - '0') << 4) | decode_hex_digit(*cp++);
				goto bypass_encoding;
			}
			switch (c) {
			case 'n':
				c = '\n';
				goto bypass_encoding;
			case 'r':
				c = '\r';
				goto bypass_encoding;
			case 'e':
				c = 0x1B;
				goto bypass_encoding;
			case 'E':		/* Euro currency symbol */
				c = 0xE5;
				goto bypass_encoding;
			case '"':
			case '\\':
				break;
			default:
				fprintf(stderr,
				"error: non-understood backslash escape\n");
				return(-1);
			}
		}
		c = gsm7_encode_table[c];
		if (c == 0xFF) {
			fprintf(stderr,
	"error: character in alpha tag string cannot be encoded in GSM7\n");
			return(-1);
		}
bypass_encoding:
		if (c & 0x80)
			nadd = 2;
		else
			nadd = 1;
		if (acclen + nadd > maxlen) {
			fprintf(stderr,
			"error: alpha tag string is longer than SIM limit\n");
			return(-1);
		}
		if (c & 0x80)
			record[acclen++] = 0x1B;
		record[acclen++] = c & 0x7F;
	}
	return(acclen);
}