view libcoding/gsm7_pack.c @ 22:8a2038c6a156

LICENSE: same as FC host tools and FC SIM tools The present code is mostly pieced together from FC User Phone Tools (freecalypso-tools/uptools) and fc-sim-tools, hence it makes no rational sense for it to be subject to any different license terms than those two major packages - but make it explicit.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Aug 2023 23:03:38 +0000
parents 2d0082216916
children
line wrap: on
line source

/*
 * This library module implements the function for packing septets into octets.
 */

#include <sys/types.h>

gsm7_pack(inbuf, outbuf, noctets)
	u_char *inbuf, *outbuf;
	unsigned noctets;
{
	u_char *ip = inbuf, *op = outbuf;
	unsigned n, c;

	for (n = 0; n < noctets; n++) {
		c = n % 7;
		*op++ = ((ip[1] << 7) | ip[0]) >> c;
		if (c == 6)
			ip += 2;
		else
			ip += 1;
	}
}