TRX: Cleanup of channel transcoding

This commit is contained in:
Andreas Eversberg 2013-02-24 10:12:09 +01:00 committed by Harald Welte
parent 801c182c02
commit 89e36c0e64
26 changed files with 1111 additions and 1314 deletions

View File

@ -2,10 +2,10 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
AM_CFLAGS = -Wall -fno-strict-aliasing $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOABIS_CFLAGS)
LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) -lortp
EXTRA_DIST = trx_if.h l1_if.h scheduler.h xcch.h rach.h sch.h pxxch.h tch_fr.h
EXTRA_DIST = trx_if.h l1_if.h scheduler.h gsm0503_parity.h gsm0503_conv.h gsm0503_interleaving.h gsm0503_mapping.h gsm0503_coding.h gsm0503_tables.h
bin_PROGRAMS = osmobts-trx
osmobts_trx_SOURCES = main.c trx_if.c l1_if.c scheduler.c trx_vty.c xcch.c rach.c sch.c pxxch.c tch_fr.c
osmobts_trx_SOURCES = main.c trx_if.c l1_if.c scheduler.c trx_vty.c gsm0503_parity.c gsm0503_conv.c gsm0503_interleaving.c gsm0503_mapping.c gsm0503_coding.c gsm0503_tables.c
osmobts_trx_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD)

View File

@ -0,0 +1,571 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/conv.h>
#include <osmocom/core/crcgen.h>
#include "gsm0503_conv.h"
#include "gsm0503_parity.h"
#include "gsm0503_mapping.h"
#include "gsm0503_interleaving.h"
#include "gsm0503_tables.h"
#include "gsm0503_coding.h"
static int _xcch_decode_cB(uint8_t *l2_data, sbit_t *cB)
{
ubit_t conv[224];
int rv;
osmo_conv_decode(&gsm0503_conv_xcch, cB, conv);
rv = osmo_crc64gen_check_bits(&gsm0503_fire_crc40, conv, 184, conv+184);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 0, 184, 1);
return 0;
}
static int _xcch_encode_cB(ubit_t *cB, uint8_t *l2_data)
{
ubit_t conv[224];
osmo_pbit2ubit_ext(conv, 0, l2_data, 0, 184, 1);
osmo_crc64gen_set_bits(&gsm0503_fire_crc40, conv, 184, conv+184);
osmo_conv_encode(&gsm0503_conv_xcch, conv, cB);
return 0;
}
/*
* GSM xCCH block transcoding
*/
int xcch_decode(uint8_t *l2_data, sbit_t *bursts)
{
sbit_t iB[456], cB[456];
int i;
for (i=0; i<4; i++)
gsm0503_xcch_burst_unmap(&iB[i * 114], &bursts[i * 116], NULL,
NULL);
gsm0503_xcch_deinterleave(cB, iB);
return _xcch_decode_cB(l2_data, cB);
}
int xcch_encode(ubit_t *bursts, uint8_t *l2_data)
{
ubit_t iB[456], cB[456], hl = 1, hn = 1;
int i;
_xcch_encode_cB(cB, l2_data);
gsm0503_xcch_interleave(cB, iB);
for (i=0; i<4; i++)
gsm0503_xcch_burst_map(&iB[i * 114], &bursts[i * 116], &hl,
&hn);
return 0;
}
/*
* GSM PDTCH block transcoding
*/
int pdtch_decode(uint8_t *l2_data, sbit_t *bursts, uint8_t *usf_p)
{
sbit_t iB[456], cB[676], hl_hn[8];
ubit_t conv[456];
int i, j, k, rv, best = 0, cs = 0, usf = 0; /* make GCC happy */
for (i=0; i<4; i++)
gsm0503_xcch_burst_unmap(&iB[i * 114], &bursts[i * 116],
hl_hn + i*2, hl_hn + i*2 + 1);
for (i=0; i<4; i++) {
for (j=0, k=0; j<8; j++)
k += abs(((int)gsm0503_pdtch_hl_hn_sbit[i][j]) -
((int)hl_hn[j]));
if (i == 0 || k < best) {
best = k;
cs = i+1;
}
}
gsm0503_xcch_deinterleave(cB, iB);
switch (cs) {
case 1:
osmo_conv_decode(&gsm0503_conv_xcch, cB, conv);
rv = osmo_crc64gen_check_bits(&gsm0503_fire_crc40, conv, 184,
conv+184);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 0, 184, 1);
return 23;
case 2:
for (i=587, j=455; i>=0; i--)
if (!gsm0503_puncture_cs2[i])
cB[i] = cB[j--];
else
cB[i] = 0;
osmo_conv_decode(&gsm0503_conv_cs2, cB, conv);
for (i=0; i<8; i++) {
for (j=0, k=0; j<6; j++)
k += abs(((int)gsm0503_usf2six[i][j]) -
((int)conv[j]));
if (i == 0 || k < best) {
best = k;
usf = i;
}
}
conv[3] = usf & 1;
conv[4] = (usf >> 1) & 1;
conv[5] = (usf >> 2) & 1;
if (usf_p)
*usf_p = usf;
rv = osmo_crc16gen_check_bits(&gsm0503_cs234_crc16, conv+3, 271,
conv+3+271);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 3, 271, 1);
return 34;
case 3:
for (i=675, j=455; i>=0; i--)
if (!gsm0503_puncture_cs3[i])
cB[i] = cB[j--];
else
cB[i] = 0;
osmo_conv_decode(&gsm0503_conv_cs3, cB, conv);
for (i=0; i<8; i++) {
for (j=0, k=0; j<6; j++)
k += abs(((int)gsm0503_usf2six[i][j]) -
((int)conv[j]));
if (i == 0 || k < best) {
best = k;
usf = i;
}
}
conv[3] = usf & 1;
conv[4] = (usf >> 1) & 1;
conv[5] = (usf >> 2) & 1;
if (usf_p)
*usf_p = usf;
rv = osmo_crc16gen_check_bits(&gsm0503_cs234_crc16, conv+3, 315,
conv+3+315);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 3, 315, 1);
return 40;
case 4:
for (i=12; i<456;i++)
conv[i] = (cB[i] < 0) ? 1:0;
for (i=0; i<8; i++) {
for (j=0, k=0; j<12; j++)
k += abs(((int)gsm0503_usf2twelve_sbit[i][j]) -
((int)cB[j]));
if (i == 0 || k < best) {
best = k;
usf = i;
}
}
conv[9] = usf & 1;
conv[10] = (usf >> 1) & 1;
conv[11] = (usf >> 2) & 1;
if (usf_p)
*usf_p = usf;
rv = osmo_crc16gen_check_bits(&gsm0503_cs234_crc16, conv+9, 431,
conv+9+431);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 9, 431, 1);
return 54;
}
return -1;
}
int pdtch_encode(ubit_t *bursts, uint8_t *l2_data, uint8_t l2_len)
{
ubit_t iB[456], cB[676];
const ubit_t *hl_hn;
ubit_t conv[334];
int i, j, usf;
switch (l2_len) {
case 23:
osmo_pbit2ubit_ext(conv, 0, l2_data, 0, 184, 1);
osmo_crc64gen_set_bits(&gsm0503_fire_crc40, conv, 184,
conv+184);
osmo_conv_encode(&gsm0503_conv_xcch, conv, cB);
hl_hn = gsm0503_pdtch_hl_hn_ubit[0];
break;
case 34:
osmo_pbit2ubit_ext(conv, 3, l2_data, 0, 271, 1);
usf = l2_data[0] & 0x7;
osmo_crc16gen_set_bits(&gsm0503_cs234_crc16, conv+3, 271,
conv+3+271);
memcpy(conv, gsm0503_usf2six[usf], 6);
osmo_conv_encode(&gsm0503_conv_cs2, conv, cB);
for (i=0, j=0; i<588; i++)
if (!gsm0503_puncture_cs2[i])
cB[j++] = cB[i];
hl_hn = gsm0503_pdtch_hl_hn_ubit[1];
break;
case 40:
osmo_pbit2ubit_ext(conv, 3, l2_data, 0, 315, 1);
usf = l2_data[0] & 0x7;
osmo_crc16gen_set_bits(&gsm0503_cs234_crc16, conv+3, 315,
conv+3+315);
memcpy(conv, gsm0503_usf2six[usf], 6);
osmo_conv_encode(&gsm0503_conv_cs3, conv, cB);
for (i=0, j=0; i<676; i++)
if (!gsm0503_puncture_cs3[i])
cB[j++] = cB[i];
hl_hn = gsm0503_pdtch_hl_hn_ubit[2];
break;
case 54:
osmo_pbit2ubit_ext(cB, 9, l2_data, 0, 431, 1);
usf = l2_data[0] & 0x7;
osmo_crc16gen_set_bits(&gsm0503_cs234_crc16, cB+9, 431,
cB+9+431);
memcpy(cB, gsm0503_usf2twelve_ubit[usf], 12);
hl_hn = gsm0503_pdtch_hl_hn_ubit[3];
break;
default:
return -1;
}
gsm0503_xcch_interleave(cB, iB);
for (i=0; i<4; i++)
gsm0503_xcch_burst_map(&iB[i * 114], &bursts[i * 116],
hl_hn + i*2, hl_hn + i*2 + 1);
return 0;
}
/*
* GSM TCH/F FR transcoding
*/
static void tch_fr_reassemble(uint8_t *tch_data, ubit_t *b_bits)
{
int i, j, k, l, o;
tch_data[0] = 0xd << 4;
memset(tch_data + 1, 0, 32);
/* reassemble d-bits */
i = 0; /* counts bits */
j = 4; /* counts output bits */
k = gsm0503_gsm_fr_map[0]-1; /* current number bit in element */
l = 0; /* counts element bits */
o = 0; /* offset input bits */
while (i < 260) {
tch_data[j>>3] |= (b_bits[k+o] << (7-(j&7)));
if (--k < 0) {
o += gsm0503_gsm_fr_map[l];
k = gsm0503_gsm_fr_map[++l]-1;
}
i++;
j++;
}
/* rearrange according to Table 2 of TS 05.03 */
}
static void tch_fr_disassemble(ubit_t *b_bits, uint8_t *tch_data)
{
int i, j, k, l, o;
i = 0; /* counts bits */
j = 4; /* counts input bits */
k = gsm0503_gsm_fr_map[0]-1; /* current number bit in element */
l = 0; /* counts element bits */
o = 0; /* offset output bits */
while (i < 260) {
b_bits[k+o] = (tch_data[j>>3] >> (7-(j&7))) & 1;
if (--k < 0) {
o += gsm0503_gsm_fr_map[l];
k = gsm0503_gsm_fr_map[++l]-1;
}
i++;
j++;
}
}
static void tch_fr_d_to_b(ubit_t *b_bits, ubit_t *d_bits)
{
int i;
for (i = 0; i < 260; i++)
b_bits[gsm0503_d_to_b_index[i]] = d_bits[i];
}
static void tch_fr_b_to_d(ubit_t *d_bits, ubit_t *b_bits)
{
int i;
for (i = 0; i < 260; i++)
d_bits[i] = b_bits[gsm0503_d_to_b_index[i]];
}
static void tch_fr_unreorder(ubit_t *d, ubit_t *p, ubit_t *u)
{
int i;
for (i=0; i<91; i++) {
d[i<<1] = u[i];
d[(i<<1)+1] = u[184-i];
}
for (i=0; i<3; i++)
p[i] = u[91+i];
}
static void tch_fr_reorder(ubit_t *u, ubit_t *d, ubit_t *p)
{
int i;
for (i=0; i<91; i++) {
u[i] = d[i<<1];
u[184-i] = d[(i<<1)+1];
}
for (i=0; i<3; i++)
u[91+i] = p[i];
}
int tch_fr_decode(uint8_t *tch_data, sbit_t *bursts, int net_order)
{
sbit_t iB[912], cB[456], h;
ubit_t conv[185], b[260], d[260], p[3];
int i, rv, len, steal = 0;
for (i=0; i<8; i++) {
gsm0503_tch_fr_burst_unmap(&iB[i * 114], &bursts[i * 116], &h,
i>>2);
steal -= h;
}
gsm0503_tch_fr_deinterleave(cB, iB);
if (steal <= 0) {
osmo_conv_decode(&gsm0503_conv_tch_fr, cB, conv);
tch_fr_unreorder(d, p, conv);
for (i=0; i<78; i++)
d[i+182] = (cB[i+378] < 0) ? 1:0;
rv = osmo_crc8gen_check_bits(&gsm0503_tch_fr_crc3, d, 50, p);
if (rv)
return -1;
if (net_order) {
tch_fr_d_to_b(b, d);
tch_fr_reassemble(tch_data, b);
} else
tch_fr_d_to_b(tch_data, d);
len = 33;
} else {
rv = _xcch_decode_cB(tch_data, cB);
if (rv)
return -1;
len = 23;
}
return len;
}
int tch_fr_encode(ubit_t *bursts, uint8_t *tch_data, int len, int net_order)
{
ubit_t iB[912], cB[456], h;
ubit_t conv[185], b[260], d[260], p[3];
int i;
switch (len) {
case 33: /* TCH FR */
if (net_order) {
tch_fr_disassemble(b, tch_data);
tch_fr_b_to_d(d, b);
} else
tch_fr_b_to_d(d, tch_data);
osmo_crc8gen_set_bits(&gsm0503_tch_fr_crc3, d, 50, p);
tch_fr_reorder(conv, d, p);
memcpy(cB+378, d+182, 78);
osmo_conv_encode(&gsm0503_conv_tch_fr, conv, cB);
h = 0;
break;
case 23: /* FACCH */
_xcch_encode_cB(cB, tch_data);
h = 1;
break;
default:
return -1;
}
gsm0503_tch_fr_interleave(cB, iB);
for (i=0; i<8; i++)
gsm0503_tch_fr_burst_map(&iB[i * 114], &bursts[i * 116], &h,
i>>2);
return 0;
}
/*
* GSM RACH transcoding
*/
/*
* GSM RACH apply BSIC to parity
*
* p(j) = p(j) xor b(j) j = 0, ..., 5
* b(0) = MSB of PLMN colour code
* b(5) = LSB of BS colour code
*/
static int rach_apply_bsic(ubit_t *d, uint8_t bsic)
{
int i;
/* Apply it */
for (i=0; i<6; i++)
d[8+i] ^= ((bsic >> (5-i)) & 1);
return 0;
}
int rach_decode(uint8_t *ra, sbit_t *burst, uint8_t bsic)
{
ubit_t conv[14];
int rv;
osmo_conv_decode(&gsm0503_conv_rach, burst, conv);
rach_apply_bsic(conv, bsic);
rv = osmo_crc8gen_check_bits(&gsm0503_rach_crc6, conv, 8, conv+8);
if (rv)
return -1;
osmo_ubit2pbit_ext(ra, 0, conv, 0, 8, 1);
return 0;
}
int rach_encode(ubit_t *burst, uint8_t *ra, uint8_t bsic)
{
ubit_t conv[14];
osmo_pbit2ubit_ext(conv, 0, ra, 0, 8, 1);
osmo_crc8gen_set_bits(&gsm0503_rach_crc6, conv, 8, conv+8);
rach_apply_bsic(conv, bsic);
osmo_conv_encode(&gsm0503_conv_rach, conv, burst);
return 0;
}
/*
* GSM SCH transcoding
*/
int sch_decode(uint8_t *sb_info, sbit_t *burst)
{
ubit_t conv[35];
int rv;
osmo_conv_decode(&gsm0503_conv_sch, burst, conv);
rv = osmo_crc16gen_check_bits(&gsm0503_sch_crc10, conv, 25, conv+25);
if (rv)
return -1;
osmo_ubit2pbit_ext(sb_info, 0, conv, 0, 25, 1);
return 0;
}
int sch_encode(ubit_t *burst, uint8_t *sb_info)
{
ubit_t conv[35];
osmo_pbit2ubit_ext(conv, 0, sb_info, 0, 25, 1);
osmo_crc16gen_set_bits(&gsm0503_sch_crc10, conv, 25, conv+25);
osmo_conv_encode(&gsm0503_conv_sch, conv, burst);
return 0;
}

View File

@ -0,0 +1,15 @@
#ifndef _0503_CODING_H
#define _0503_CODING_H
int xcch_decode(uint8_t *l2_data, sbit_t *bursts);
int xcch_encode(ubit_t *bursts, uint8_t *l2_data);
int pdtch_decode(uint8_t *l2_data, sbit_t *bursts, uint8_t *usf_p);
int pdtch_encode(ubit_t *bursts, uint8_t *l2_data, uint8_t l2_len);
int tch_fr_decode(uint8_t *tch_data, sbit_t *bursts, int net_order);
int tch_fr_encode(ubit_t *bursts, uint8_t *tch_data, int len, int net_order);
int rach_decode(uint8_t *ra, sbit_t *burst, uint8_t bsic);
int rach_encode(ubit_t *burst, uint8_t *ra, uint8_t bsic);
int sch_decode(uint8_t *sb_info, sbit_t *burst);
int sch_encode(ubit_t *burst, uint8_t *sb_info);
#endif /* _0503_CODING_H */

View File

@ -0,0 +1,83 @@
#include <stdint.h>
#include <osmocom/core/conv.h>
#include "gsm0503_conv.h"
/*
* GSM convolutional coding
*
* G_0 = 1 + x^3 + x^4
* G_1 = 1 + x + x^3 + x^4
*/
static const uint8_t conv_xcch_next_output[][2] = {
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
};
static const uint8_t conv_xcch_next_state[][2] = {
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
};
const struct osmo_conv_code gsm0503_conv_xcch = {
.N = 2,
.K = 5,
.len = 224,
.next_output = conv_xcch_next_output,
.next_state = conv_xcch_next_state,
};
const struct osmo_conv_code gsm0503_conv_cs2 = {
.N = 2,
.K = 5,
.len = 290,
.next_output = conv_xcch_next_output,
.next_state = conv_xcch_next_state,
};
const struct osmo_conv_code gsm0503_conv_cs3 = {
.N = 2,
.K = 5,
.len = 334,
.next_output = conv_xcch_next_output,
.next_state = conv_xcch_next_state,
};
const struct osmo_conv_code gsm0503_conv_rach = {
.N = 2,
.K = 5,
.len = 14,
.next_output = conv_xcch_next_output,
.next_state = conv_xcch_next_state,
};
const struct osmo_conv_code gsm0503_conv_sch = {
.N = 2,
.K = 5,
.len = 35,
.next_output = conv_xcch_next_output,
.next_state = conv_xcch_next_state,
};
const struct osmo_conv_code gsm0503_conv_tch_fr = {
.N = 2,
.K = 5,
.len = 185,
.next_output = conv_xcch_next_output,
.next_state = conv_xcch_next_state,
};

View File

@ -0,0 +1,11 @@
#ifndef _0503_CONV_H
#define _0503_CONV_H
extern const struct osmo_conv_code gsm0503_conv_xcch;
extern const struct osmo_conv_code gsm0503_conv_cs2;
extern const struct osmo_conv_code gsm0503_conv_cs3;
extern const struct osmo_conv_code gsm0503_conv_rach;
extern const struct osmo_conv_code gsm0503_conv_sch;
extern const struct osmo_conv_code gsm0503_conv_tch_fr;
#endif /* _0503_CONV_H */

View File

@ -0,0 +1,97 @@
#include <stdint.h>
#include <osmocom/core/bits.h>
#include "gsm0503_interleaving.h"
/*
* GSM xCCH interleaving and burst mapping
*
* Interleaving:
*
* Given 456 coded input bits, form 4 blocks of 114 bits:
*
* i(B, j) = c(n, k) k = 0, ..., 455
* n = 0, ..., N, N + 1, ...
* B = B_0 + 4n + (k mod 4)
* j = 2(49k mod 57) + ((k mod 8) div 4)
*
* Mapping on Burst:
*
* e(B, j) = i(B, j)
* e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
* e(B, 57) = h_l(B)
* e(B, 58) = h_n(B)
*
* Where hl(B) and hn(B) are bits in burst B indicating flags.
*/
void gsm0503_xcch_deinterleave(sbit_t *cB, sbit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 3;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
cB[k] = iB[B * 114 + j];
}
}
void gsm0503_xcch_interleave(ubit_t *cB, ubit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 3;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
iB[B * 114 + j] = cB[k];
}
}
/*
* GSM TCH FR/EFR interleaving and burst mapping
*
* Interleaving:
*
* Given 456 coded input bits, form 8 blocks of 114 bits,
* where event bits of the first 4 block and off bits of the last 4 block
* are used:
*
* i(B, j) = c(n, k) k = 0, ..., 455
* n = 0, ..., N, N + 1, ...
* B = B_0 + 4n + (k mod 8)
* j = 2(49k mod 57) + ((k mod 8) div 4)
*
* Mapping on Burst:
*
* e(B, j) = i(B, j)
* e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
* e(B, 57) = h_l(B)
* e(B, 58) = h_n(B)
*
* Where hl(B) and hn(B) are bits in burst B indicating flags.
*/
void gsm0503_tch_fr_deinterleave(sbit_t *cB, sbit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 7;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
cB[k] = iB[B * 114 + j];
}
}
void gsm0503_tch_fr_interleave(ubit_t *cB, ubit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 7;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
iB[B * 114 + j] = cB[k];
}
}

View File

@ -0,0 +1,9 @@
#ifndef _0503_INTERLEAVING_H
#define _0503_INTERLEAVING_H
void gsm0503_xcch_deinterleave(sbit_t *cB, sbit_t *iB);
void gsm0503_xcch_interleave(ubit_t *cB, ubit_t *iB);
void gsm0503_tch_fr_deinterleave(sbit_t *cB, sbit_t *iB);
void gsm0503_tch_fr_interleave(ubit_t *cB, ubit_t *iB);
#endif /* _0503_INTERLEAVING_H */

View File

@ -0,0 +1,65 @@
#include <stdint.h>
#include <string.h>
#include <osmocom/core/bits.h>
#include "gsm0503_mapping.h"
void gsm0503_xcch_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *hl, sbit_t *hn)
{
memcpy(iB, eB, 57);
memcpy(iB+57, eB+59, 57);
if (hl)
*hl = eB[57];
if (hn)
*hn = eB[58];
}
void gsm0503_xcch_burst_map(ubit_t *iB, ubit_t *eB, const ubit_t *hl,
const ubit_t *hn)
{
memcpy(eB, iB, 57);
memcpy(eB+59, iB+57, 57);
if (hl)
eB[57] = *hl;
if (hn)
eB[58] = *hn;
}
void gsm0503_tch_fr_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *h, int odd)
{
int i;
/* brainfuck: only copy even or odd bits */
for (i=odd; i<57; i+=2)
iB[i] = eB[i];
for (i=58-odd; i<114; i+=2)
iB[i] = eB[i+2];
if (h && !odd)
*h = eB[58];
if (h && odd)
*h = eB[57];
}
void gsm0503_tch_fr_burst_map(ubit_t *iB, ubit_t *eB, const ubit_t *h, int odd)
{
int i;
/* brainfuck: only copy even or odd bits */
for (i=odd; i<57; i+=2)
eB[i] = iB[i];
for (i=58-odd; i<114; i+=2)
eB[i+2] = iB[i];
if (h && !odd)
eB[58] = *h;
if (h && odd)
eB[57] = *h;
}

View File

@ -0,0 +1,10 @@
#ifndef _0503_MAPPING_H
#define _0503_MAPPING_H
void gsm0503_xcch_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *hl, sbit_t *hn);
void gsm0503_xcch_burst_map(ubit_t *iB, ubit_t *eB, const ubit_t *hl,
const ubit_t *hn);
void gsm0503_tch_fr_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *h, int odd);
void gsm0503_tch_fr_burst_map(ubit_t *iB, ubit_t *eB, const ubit_t *h, int odd);
#endif /* _0503_INTERLEAVING_H */

View File

@ -0,0 +1,77 @@
#include <stdint.h>
#include <osmocom/core/crcgen.h>
#include "gsm0503_parity.h"
/*
* GSM (SACCH) parity (FIRE code)
*
* g(x) = (x^23 + 1)(x^17 + x^3 + 1)
* = x^40 + x^26 + x^23 + x^17 + x^3 + a1
*/
const struct osmo_crc64gen_code gsm0503_fire_crc40 = {
.bits = 40,
.poly = 0x0004820009ULL,
.init = 0x0000000000ULL,
.remainder = 0xffffffffffULL,
};
/*
* GSM PDTCH CS-2, CS-3, CS-4 parity
*
* g(x) = x^16 + x^12 + x^5 + 1
*/
const struct osmo_crc16gen_code gsm0503_cs234_crc16 = {
.bits = 16,
.poly = 0x1021,
.init = 0x0000,
.remainder = 0xffff,
};
/*
* GSM RACH parity
*
* g(x) = x^6 + x^5 + x^3 + x^2 + x^1 + 1
*/
const struct osmo_crc8gen_code gsm0503_rach_crc6 = {
.bits = 6,
.poly = 0x2f,
.init = 0x00,
.remainder = 0x3f,
};
/*
* GSM SCH parity
*
* g(x) = x^10 + x^8 + x^6 + x^5 + x^4 + x^2 + 1
*/
const struct osmo_crc16gen_code gsm0503_sch_crc10 = {
.bits = 10,
.poly = 0x175,
.init = 0x000,
.remainder = 0x3ff,
};
/*
* GSM TCH FR/EFR parity
*
* g(x) = x^3 + x + 1
*/
const struct osmo_crc8gen_code gsm0503_tch_fr_crc3 = {
.bits = 3,
.poly = 0x3,
.init = 0x0,
.remainder = 0x7,
};

View File

@ -0,0 +1,10 @@
#ifndef _0503_PARITY_H
#define _0503_PARITY_H
const struct osmo_crc64gen_code gsm0503_fire_crc40;
const struct osmo_crc16gen_code gsm0503_cs234_crc16;
const struct osmo_crc8gen_code gsm0503_rach_crc6;
const struct osmo_crc16gen_code gsm0503_sch_crc10;
const struct osmo_crc8gen_code gsm0503_tch_fr_crc3;
#endif /* _0503_PARITY_H */

View File

@ -0,0 +1,139 @@
#include <stdint.h>
#include <osmocom/core/bits.h>
#include "gsm0503_tables.h"
const ubit_t gsm0503_pdtch_hl_hn_ubit[4][8] = {
{ 1,1, 1,1, 1,1, 1,1 },
{ 1,1, 0,0, 1,0, 0,0 },
{ 0,0, 1,0, 0,0, 0,1 },
{ 0,0, 0,1, 0,1, 1,0 },
};
const sbit_t gsm0503_pdtch_hl_hn_sbit[4][8] = {
{ -127,-127, -127,-127, -127,-127, -127,-127 },
{ -127,-127, 127, 127, -127, 127, 127, 127 },
{ 127, 127, -127, 127, 127, 127, 127,-127 },
{ 127, 127, 127,-127, 127,-127, -127, 127 },
};
const ubit_t gsm0503_usf2six[8][6] = {
{ 0,0,0, 0,0,0 },
{ 1,0,0, 1,0,1 },
{ 0,1,0, 1,1,0 },
{ 1,1,0, 0,1,1 },
{ 0,0,1, 0,1,1 },
{ 1,0,1, 1,1,0 },
{ 0,1,1, 1,0,1 },
{ 1,1,1, 0,0,0 },
};
const ubit_t gsm0503_usf2twelve_ubit[8][12] = {
{ 0,0,0, 0,0,0, 0,0,0, 0,0,0 },
{ 1,1,0, 1,0,0, 0,0,1, 0,1,1 },
{ 0,0,1, 1,0,1, 1,1,0, 1,1,0 },
{ 1,1,1, 0,0,1, 1,1,1, 1,0,1 },
{ 0,0,0, 0,1,1, 0,1,1, 1,0,1 },
{ 1,1,0, 1,1,1, 0,1,0, 1,1,0 },
{ 0,0,1, 1,1,0, 1,0,1, 0,1,1 },
{ 1,1,1, 0,1,0, 1,0,0, 0,0,0 },
};
const sbit_t gsm0503_usf2twelve_sbit[8][12] = {
{ 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127 },
{ -127,-127, 127, -127, 127, 127, 127, 127,-127, 127,-127,-127 },
{ 127, 127,-127, -127, 127,-127, -127,-127, 127, -127,-127, 127 },
{ -127,-127,-127, 127, 127,-127, -127,-127,-127, -127, 127,-127 },
{ 127, 127, 127, 127,-127,-127, 127,-127,-127, -127, 127,-127 },
{ -127,-127, 127, -127,-127,-127, 127,-127, 127, -127,-127, 127 },
{ 127, 127,-127, -127,-127, 127, -127, 127,-127, 127,-127,-127 },
{ -127,-127,-127, 127,-127, 127, -127, 127, 127, 127, 127, 127 },
};
const uint8_t gsm0503_puncture_cs2[588] = {
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0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,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,0
};
/* this corresponds to the bit-lengths of the individual codec
* parameters as indicated in Table 1.1 of TS 06.10 */
const uint8_t gsm0503_gsm_fr_map[76] = {
6, 6, 5, 5, 4, 4, 3, 3,
7, 2, 2, 6, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 7, 2, 2, 6, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 7, 2, 2, 6, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 7, 2, 2, 6, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3
};
/* b(0..259) from d(0..259) according to (corrected) Table 2 of T 05.03 */
const uint16_t gsm0503_d_to_b_index[260] = {
5, 52,108,164,220, 4, 11, 16, 3, 10, 15, 21, 42, 98,154,210,
51,107,163,219, 9, 25, 29, 41, 97,153,209, 40, 96,152,208, 39,
95,151,207, 38, 94,150,206, 50,106,162,218, 2, 20, 32, 37, 93,
149,205, 24, 28, 44,100,156,212, 36, 92,148,204, 46,102,158,214,
1, 8, 14, 35, 19, 23, 31, 43, 99,155,211, 49,105,161,217, 55,
58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91,111,114,117,120,
123,126,129,132,135,138,141,144,147,167,170,173,176,179,182,185,
188,191,194,197,200,203,223,226,229,232,235,238,241,244,247,250,
253,256,259, 45,101,157,213, 48,104,160,216, 54, 57, 60, 63, 66,
69, 72, 75, 78, 81, 84, 87, 90,110,113,116,119,122,125,128,131,
134,137,140,143,146,166,169,172,175,178,181,184,187,190,193,196,
199,202,222,225,228,231,234,237,240,243,246,249,252,255,258, 0,
7, 13, 27, 30, 34, 33, 12, 18, 17, 22, 47,103,159,215, 53, 56,
59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89,109,112,115,118,121,
124,127,130,133,136,139,142,145,165,168,171,174,177,180,183,186,
189,192,195,198,201,221,224,227,230,233,236,239,242,245,248,251,
254,257, 6, 26,
};

View File

@ -0,0 +1,14 @@
#ifndef _0503_TABLES_H
#define _0503_TABLES_H
extern const ubit_t gsm0503_pdtch_hl_hn_ubit[4][8];
extern const sbit_t gsm0503_pdtch_hl_hn_sbit[4][8];
extern const ubit_t gsm0503_usf2six[8][6];
extern const ubit_t gsm0503_usf2twelve_ubit[8][12];
extern const sbit_t gsm0503_usf2twelve_sbit[8][12];
extern const uint8_t gsm0503_puncture_cs2[588];
extern const uint8_t gsm0503_puncture_cs3[676];
extern const uint8_t gsm0503_gsm_fr_map[76];
extern const uint16_t gsm0503_d_to_b_index[260];
#endif /* _0503_TABLES_H */

View File

@ -1,493 +0,0 @@
/*
* pxxch.c
*
* Copyright (c) 2013 Andreas Eversberg <jolly@eversberg.eu>
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/conv.h>
#include <osmocom/core/crcgen.h>
#include "pxxch.h"
/*
* GSM PDTCH parity (FIRE code)
*
* g(x) = (x^23 + 1)(x^17 + x^3 + 1)
* = x^40 + x^26 + x^23 + x^17 + x^3 + 1
*/
const struct osmo_crc64gen_code pxxch_crc40 = {
.bits = 40,
.poly = 0x0004820009ULL,
.init = 0x0000000000ULL,
.remainder = 0xffffffffffULL,
};
/*
* GSM PDTCH CS-2, CS-3, CS-4 parity
*
* g(x) = x^16 + x^12 + x^5 + 1
*/
const struct osmo_crc16gen_code pdtch_crc16 = {
.bits = 16,
.poly = 0x1021,
.init = 0x0000,
.remainder = 0xffff,
};
/*
* GSM PDTCH convolutional coding
*
* G_0 = 1 + x^3 + x^4
* G_1 = 1 + x + x^3 + x^4
*/
static const uint8_t conv_cs1_next_output[][2] = {
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
};
static const uint8_t conv_cs1_next_state[][2] = {
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
};
static const struct osmo_conv_code conv_cs1 = {
.N = 2,
.K = 5,
.len = 224,
.next_output = conv_cs1_next_output,
.next_state = conv_cs1_next_state,
};
static const uint8_t conv_cs2_next_output[][2] = {
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
};
static const uint8_t conv_cs2_next_state[][2] = {
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
};
static const struct osmo_conv_code conv_cs2 = {
.N = 2,
.K = 5,
.len = 290,
.next_output = conv_cs2_next_output,
.next_state = conv_cs2_next_state,
};
static const uint8_t conv_cs3_next_output[][2] = {
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
};
static const uint8_t conv_cs3_next_state[][2] = {
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
};
static const struct osmo_conv_code conv_cs3 = {
.N = 2,
.K = 5,
.len = 334,
.next_output = conv_cs3_next_output,
.next_state = conv_cs3_next_state,
};
/*
* GSM PxxCH interleaving and burst mapping
*
* Interleaving:
*
* Given 456 coded input bits, form 4 blocks of 114 bits:
*
* i(B, j) = c(n, k) k = 0, ..., 455
* n = 0, ..., N, N + 1, ...
* B = B_0 + 4n + (k mod 4)
* j = 2(49k mod 57) + ((k mod 8) div 4)
*
* Mapping on Burst:
*
* e(B, j) = i(B, j)
* e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
* e(B, 57) = h_l(B)
* e(B, 58) = h_n(B)
*
* Where hl(B) and hn(B) are bits in burst B indicating flags.
*/
static void
pxxch_deinterleave(sbit_t *cB, sbit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 3;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
cB[k] = iB[B * 114 + j];
}
}
static void
pxxch_interleave(ubit_t *cB, ubit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 3;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
iB[B * 114 + j] = cB[k];
}
}
static void
pxxch_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *hl, sbit_t *hn)
{
memcpy(iB, eB, 57);
memcpy(iB+57, eB+59, 57);
if (hl)
*hl = eB[57];
if (hn)
*hn = eB[58];
}
static void
pxxch_burst_map(ubit_t *iB, ubit_t *eB, ubit_t *hl, ubit_t *hn)
{
memcpy(eB, iB, 57);
memcpy(eB+59, iB+57, 57);
if (hl)
eB[57] = *hl;
if (hn)
eB[58] = *hn;
}
static ubit_t pdtch_hl_hn_ubit[4][8] = {
{ 1,1, 1,1, 1,1, 1,1 },
{ 1,1, 0,0, 1,0, 0,0 },
{ 0,0, 1,0, 0,0, 0,1 },
{ 0,0, 0,1, 0,1, 1,0 },
};
static sbit_t pdtch_hl_hn_sbit[4][8] = {
{ -127,-127, -127,-127, -127,-127, -127,-127 },
{ -127,-127, 127, 127, -127, 127, 127, 127 },
{ 127, 127, -127, 127, 127, 127, 127,-127 },
{ 127, 127, 127,-127, 127,-127, -127, 127 },
};
static ubit_t usf2six[8][6] = {
{ 0,0,0, 0,0,0 },
{ 1,0,0, 1,0,1 },
{ 0,1,0, 1,1,0 },
{ 1,1,0, 0,1,1 },
{ 0,0,1, 0,1,1 },
{ 1,0,1, 1,1,0 },
{ 0,1,1, 1,0,1 },
{ 1,1,1, 0,0,0 },
};
static ubit_t usf2twelve_ubit[8][12] = {
{ 0,0,0, 0,0,0, 0,0,0, 0,0,0 },
{ 1,1,0, 1,0,0, 0,0,1, 0,1,1 },
{ 0,0,1, 1,0,1, 1,1,0, 1,1,0 },
{ 1,1,1, 0,0,1, 1,1,1, 1,0,1 },
{ 0,0,0, 0,1,1, 0,1,1, 1,0,1 },
{ 1,1,0, 1,1,1, 0,1,0, 1,1,0 },
{ 0,0,1, 1,1,0, 1,0,1, 0,1,1 },
{ 1,1,1, 0,1,0, 1,0,0, 0,0,0 },
};
static sbit_t usf2twelve_sbit[8][12] = {
{ 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127 },
{ -127,-127, 127, -127, 127, 127, 127, 127,-127, 127,-127,-127 },
{ 127, 127,-127, -127, 127,-127, -127,-127, 127, -127,-127, 127 },
{ -127,-127,-127, 127, 127,-127, -127,-127,-127, -127, 127,-127 },
{ 127, 127, 127, 127,-127,-127, 127,-127,-127, -127, 127,-127 },
{ -127,-127, 127, -127,-127,-127, 127,-127, 127, -127,-127, 127 },
{ 127, 127,-127, -127,-127, 127, -127, 127,-127, 127,-127,-127 },
{ -127,-127,-127, 127,-127, 127, -127, 127, 127, 127, 127, 127 },
};
static uint8_t puncture_cs2[588] = {
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
0,0,0,1, 0,0,0,1, 0,0,0,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,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,0
};
int
pdtch_decode(uint8_t *l2_data, sbit_t *bursts, uint8_t *usf_p)
{
sbit_t iB[456], cB[676], hl_hn[8];
ubit_t conv[456];
int i, j, k, rv, best = 0, cs = 0, usf = 0; /* make GCC happy */
for (i=0; i<4; i++)
pxxch_burst_unmap(&iB[i * 114], &bursts[i * 116], hl_hn + i*2,
hl_hn + i*2 + 1);
for (i=0; i<4; i++) {
for (j=0, k=0; j<8; j++)
k += abs(((int)pdtch_hl_hn_sbit[i][j]) - ((int)hl_hn[j]));
if (i == 0 || k < best) {
best = k;
cs = i+1;
}
}
pxxch_deinterleave(cB, iB);
switch (cs) {
case 1:
osmo_conv_decode(&conv_cs1, cB, conv);
rv = osmo_crc64gen_check_bits(&pxxch_crc40, conv, 184,
conv+184);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 0, 184, 1);
return 23;
case 2:
for (i=587, j=455; i>=0; i--)
if (!puncture_cs2[i])
cB[i] = cB[j--];
else
cB[i] = 0;
osmo_conv_decode(&conv_cs2, cB, conv);
for (i=0; i<8; i++) {
for (j=0, k=0; j<6; j++)
k += abs(((int)usf2six[i][j]) - ((int)conv[j]));
if (i == 0 || k < best) {
best = k;
usf = i;
}
}
conv[3] = usf & 1;
conv[4] = (usf >> 1) & 1;
conv[5] = (usf >> 2) & 1;
if (usf_p)
*usf_p = usf;
rv = osmo_crc16gen_check_bits(&pdtch_crc16, conv+3, 271,
conv+3+271);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 3, 271, 1);
return 34;
case 3:
for (i=675, j=455; i>=0; i--)
if (!puncture_cs3[i])
cB[i] = cB[j--];
else
cB[i] = 0;
osmo_conv_decode(&conv_cs3, cB, conv);
for (i=0; i<8; i++) {
for (j=0, k=0; j<6; j++)
k += abs(((int)usf2six[i][j]) - ((int)conv[j]));
if (i == 0 || k < best) {
best = k;
usf = i;
}
}
conv[3] = usf & 1;
conv[4] = (usf >> 1) & 1;
conv[5] = (usf >> 2) & 1;
if (usf_p)
*usf_p = usf;
rv = osmo_crc16gen_check_bits(&pdtch_crc16, conv+3, 315,
conv+3+315);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 3, 315, 1);
return 40;
case 4:
for (i=12; i<456;i++)
conv[i] = (cB[i] < 0) ? 1:0;
for (i=0; i<8; i++) {
for (j=0, k=0; j<12; j++)
k += abs(((int)usf2twelve_sbit[i][j]) -
((int)cB[j]));
if (i == 0 || k < best) {
best = k;
usf = i;
}
}
conv[9] = usf & 1;
conv[10] = (usf >> 1) & 1;
conv[11] = (usf >> 2) & 1;
if (usf_p)
*usf_p = usf;
rv = osmo_crc16gen_check_bits(&pdtch_crc16, conv+9, 431,
conv+9+431);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 9, 431, 1);
return 54;
}
return -1;
}
int
pdtch_encode(ubit_t *bursts, uint8_t *l2_data, uint8_t l2_len)
{
ubit_t iB[456], cB[676], *hl_hn;
ubit_t conv[334];
int i, j, usf;
switch (l2_len) {
case 23:
osmo_pbit2ubit_ext(conv, 0, l2_data, 0, 184, 1);
osmo_crc64gen_set_bits(&pxxch_crc40, conv, 184, conv+184);
osmo_conv_encode(&conv_cs1, conv, cB);
hl_hn = pdtch_hl_hn_ubit[0];
break;
case 34:
osmo_pbit2ubit_ext(conv, 3, l2_data, 0, 271, 1);
usf = l2_data[0] & 0x7;
osmo_crc16gen_set_bits(&pdtch_crc16, conv+3, 271, conv+3+271);
memcpy(conv, usf2six[usf], 6);
osmo_conv_encode(&conv_cs2, conv, cB);
for (i=0, j=0; i<588; i++)
if (!puncture_cs2[i])
cB[j++] = cB[i];
hl_hn = pdtch_hl_hn_ubit[1];
break;
case 40:
osmo_pbit2ubit_ext(conv, 3, l2_data, 0, 315, 1);
usf = l2_data[0] & 0x7;
osmo_crc16gen_set_bits(&pdtch_crc16, conv+3, 315, conv+3+315);
memcpy(conv, usf2six[usf], 6);
osmo_conv_encode(&conv_cs3, conv, cB);
for (i=0, j=0; i<676; i++)
if (!puncture_cs3[i])
cB[j++] = cB[i];
hl_hn = pdtch_hl_hn_ubit[2];
break;
case 54:
osmo_pbit2ubit_ext(cB, 9, l2_data, 0, 431, 1);
usf = l2_data[0] & 0x7;
osmo_crc16gen_set_bits(&pdtch_crc16, cB+9, 431, cB+9+431);
memcpy(cB, usf2twelve_ubit[usf], 12);
hl_hn = pdtch_hl_hn_ubit[3];
break;
default:
return -1;
}
pxxch_interleave(cB, iB);
for (i=0; i<4; i++)
pxxch_burst_map(&iB[i * 114], &bursts[i * 116], hl_hn + i*2,
hl_hn + i*2 + 1);
return 0;
}

View File

@ -1,7 +0,0 @@
#ifndef _PXXCH_H
#define _PXXCH_H
int pdtch_decode(uint8_t *l2_data, sbit_t *bursts, uint8_t *usf_p);
int pdtch_encode(ubit_t *bursts, uint8_t *l2_data, uint8_t l2_len);
#endif /* _PXXCH_H */

View File

@ -1,118 +0,0 @@
/*
* conv_rach.c
*
* Convolutional code tables for RACH channels
*
* Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/conv.h>
#include <osmocom/core/crcgen.h>
#include "rach.h"
/*
* GSM RACH parity
*
* g(x) = x^6 + x^5 + x^3 + x^2 + x^1 + 1
*/
static const struct osmo_crc8gen_code rach_crc6 = {
.bits = 6,
.poly = 0x2f,
.init = 0x00,
.remainder = 0x3f,
};
/*
* GSM RACH convolutional coding
*
* G_0 = 1 + x^3 + x^4
* G_1 = 1 + x + x^3 + x^4
*/
static const uint8_t conv_rach_next_output[][2] = {
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
};
static const uint8_t conv_rach_next_state[][2] = {
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
};
const struct osmo_conv_code conv_rach = {
.N = 2,
.K = 5,
.len = 14,
.next_output = conv_rach_next_output,
.next_state = conv_rach_next_state,
};
/*
* GSM RACH apply BSIC to parity
*
* p(j) = p(j) xor b(j) j = 0, ..., 5
* b(0) = MSB of PLMN colour code
* b(5) = LSB of BS colour code
*/
static int
rach_apply_bsic(ubit_t *d, uint8_t bsic)
{
int i;
/* Apply it */
for (i=0; i<6; i++)
d[8+i] ^= ((bsic >> (5-i)) & 1);
return 0;
}
int
rach_decode(uint8_t *ra, sbit_t *burst, uint8_t bsic)
{
ubit_t conv[14];
int rv;
osmo_conv_decode(&conv_rach, burst, conv);
rach_apply_bsic(conv, bsic);
rv = osmo_crc8gen_check_bits(&rach_crc6, conv, 8, conv+8);
if (rv)
return -1;
osmo_ubit2pbit_ext(ra, 0, conv, 0, 8, 1);
return 0;
}
int
rach_encode(ubit_t *burst, uint8_t *ra, uint8_t bsic)
{
ubit_t conv[14];
osmo_pbit2ubit_ext(conv, 0, ra, 0, 8, 1);
osmo_crc8gen_set_bits(&rach_crc6, conv, 8, conv+8);
rach_apply_bsic(conv, bsic);
osmo_conv_encode(&conv_rach, conv, burst);
return 0;
}

View File

@ -1,7 +0,0 @@
#ifndef _RACH_H
#define _RACH_H
int rach_decode(uint8_t *ra, sbit_t *burst, uint8_t bsic);
int rach_encode(ubit_t *burst, uint8_t *ra, uint8_t bsic);
#endif /* _RACH_H */

View File

@ -1,89 +0,0 @@
/*
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/conv.h>
#include <osmocom/core/crcgen.h>
#include "sch.h"
/*
* GSM SCH parity
*
* g(x) = x^10 + x^8 + x^6 + x^5 + x^4 + x^2 + 1
*/
const struct osmo_crc16gen_code sch_crc10 = {
.bits = 10,
.poly = 0x175,
.init = 0x000,
.remainder = 0x3ff,
};
/*
* GSM SCH convolutional coding
*
* G_0 = 1 + x^3 + x^4
* G_1 = 1 + x + x^3 + x^4
*/
static const uint8_t conv_rach_next_output[][2] = {
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
};
static const uint8_t conv_rach_next_state[][2] = {
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
};
static const struct osmo_conv_code conv_sch = {
.N = 2,
.K = 5,
.len = 35,
.next_output = conv_rach_next_output,
.next_state = conv_rach_next_state,
};
int
sch_decode(uint8_t *sb_info, sbit_t *burst)
{
ubit_t conv[35];
int rv;
osmo_conv_decode(&conv_sch, burst, conv);
rv = osmo_crc16gen_check_bits(&sch_crc10, conv, 25, conv+25);
if (rv)
return -1;
osmo_ubit2pbit_ext(sb_info, 0, conv, 0, 25, 1);
return 0;
}
int
sch_encode(ubit_t *burst, uint8_t *sb_info)
{
ubit_t conv[35];
osmo_pbit2ubit_ext(conv, 0, sb_info, 0, 25, 1);
osmo_crc16gen_set_bits(&sch_crc10, conv, 25, conv+25);
osmo_conv_encode(&conv_sch, conv, burst);
return 0;
}

View File

@ -1,7 +0,0 @@
#ifndef _SCH_H
#define _SCH_H
int sch_decode(uint8_t *sb_info, sbit_t *burst);
int sch_encode(ubit_t *burst, uint8_t *sb_info);
#endif /* _SCH_H */

View File

@ -35,11 +35,7 @@
#include "l1_if.h"
#include "scheduler.h"
#include "xcch.h"
#include "tch_fr.h"
#include "rach.h"
#include "sch.h"
#include "pxxch.h"
#include "gsm0503_coding.h"
#include "trx_if.h"
/* Enable this to multiply TOA of RACH by 10.

View File

@ -1,365 +0,0 @@
/*
* tch_fr.c
*
* Copyright (c) 2013 Andreas Eversberg <jolly@eversberg.eu>
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/conv.h>
#include <osmocom/core/crcgen.h>
#include "xcch.h"
#include "tch_fr.h"
/*
* GSM TCH FR/EFR parity
*
* g(x) = x^3 + x + 1
*/
const struct osmo_crc8gen_code tch_fr_crc3 = {
.bits = 3,
.poly = 0x3,
.init = 0x0,
.remainder = 0x7,
};
/*
* GSM TCH FR/EFR convolutional coding
*
* G_0 = 1 + x^3 + x^4
* G_1 = 1 + x + x^3 + x^4
*/
static const uint8_t conv_tch_fr_next_output[][2] = {
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
};
static const uint8_t conv_tch_fr_next_state[][2] = {
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
};
static const struct osmo_conv_code conv_tch_fr = {
.N = 2,
.K = 5,
.len = 185,
.next_output = conv_tch_fr_next_output,
.next_state = conv_tch_fr_next_state,
};
/*
* GSM TCH FR/EFR interleaving and burst mapping
*
* Interleaving:
*
* Given 456 coded input bits, form 8 blocks of 114 bits,
* where event bits of the first 4 block and off bits of the last 4 block
* are used:
*
* i(B, j) = c(n, k) k = 0, ..., 455
* n = 0, ..., N, N + 1, ...
* B = B_0 + 4n + (k mod 8)
* j = 2(49k mod 57) + ((k mod 8) div 4)
*
* Mapping on Burst:
*
* e(B, j) = i(B, j)
* e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
* e(B, 57) = h_l(B)
* e(B, 58) = h_n(B)
*
* Where hl(B) and hn(B) are bits in burst B indicating flags.
*/
static void
tch_fr_deinterleave(sbit_t *cB, sbit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 7;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
cB[k] = iB[B * 114 + j];
}
}
static void
tch_fr_interleave(ubit_t *cB, ubit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 7;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
iB[B * 114 + j] = cB[k];
}
}
static void
tch_fr_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *h, int odd)
{
int i;
/* brainfuck: only copy even or odd bits */
for (i=odd; i<57; i+=2)
iB[i] = eB[i];
for (i=58-odd; i<114; i+=2)
iB[i] = eB[i+2];
if (h && !odd)
*h = eB[58];
if (h && odd)
*h = eB[57];
}
static void
tch_fr_burst_map(ubit_t *iB, ubit_t *eB, ubit_t *h, int odd)
{
int i;
/* brainfuck: only copy even or odd bits */
for (i=odd; i<57; i+=2)
eB[i] = iB[i];
for (i=58-odd; i<114; i+=2)
eB[i+2] = iB[i];
if (h && !odd)
eB[58] = *h;
if (h && odd)
eB[57] = *h;
}
/* this corresponds to the bit-lengths of the individual codec
* parameters as indicated in Table 1.1 of TS 06.10 */
static const uint8_t gsm_fr_map[] = {
6, 6, 5, 5, 4, 4, 3, 3,
7, 2, 2, 6, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 7, 2, 2, 6, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 7, 2, 2, 6, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 7, 2, 2, 6, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3
};
static void
tch_fr_reassemble(uint8_t *tch_data, ubit_t *b_bits)
{
int i, j, k, l, o;
tch_data[0] = 0xd << 4;
memset(tch_data + 1, 0, 32);
/* reassemble d-bits */
i = 0; /* counts bits */
j = 4; /* counts output bits */
k = gsm_fr_map[0]-1; /* current number bit in element */
l = 0; /* counts element bits */
o = 0; /* offset input bits */
while (i < 260) {
tch_data[j>>3] |= (b_bits[k+o] << (7-(j&7)));
if (--k < 0) {
o += gsm_fr_map[l];
k = gsm_fr_map[++l]-1;
}
i++;
j++;
}
/* rearrange according to Table 2 of TS 05.03 */
}
static void
tch_fr_disassemble(ubit_t *b_bits, uint8_t *tch_data)
{
int i, j, k, l, o;
i = 0; /* counts bits */
j = 4; /* counts input bits */
k = gsm_fr_map[0]-1; /* current number bit in element */
l = 0; /* counts element bits */
o = 0; /* offset output bits */
while (i < 260) {
b_bits[k+o] = (tch_data[j>>3] >> (7-(j&7))) & 1;
if (--k < 0) {
o += gsm_fr_map[l];
k = gsm_fr_map[++l]-1;
}
i++;
j++;
}
}
/* b(0..259) from d(0..259) according to (corrected) Table 2 of T 05.03 */
static uint16_t d_to_b_index[260] = {
5, 52,108,164,220, 4, 11, 16, 3, 10, 15, 21, 42, 98,154,210,
51,107,163,219, 9, 25, 29, 41, 97,153,209, 40, 96,152,208, 39,
95,151,207, 38, 94,150,206, 50,106,162,218, 2, 20, 32, 37, 93,
149,205, 24, 28, 44,100,156,212, 36, 92,148,204, 46,102,158,214,
1, 8, 14, 35, 19, 23, 31, 43, 99,155,211, 49,105,161,217, 55,
58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91,111,114,117,120,
123,126,129,132,135,138,141,144,147,167,170,173,176,179,182,185,
188,191,194,197,200,203,223,226,229,232,235,238,241,244,247,250,
253,256,259, 45,101,157,213, 48,104,160,216, 54, 57, 60, 63, 66,
69, 72, 75, 78, 81, 84, 87, 90,110,113,116,119,122,125,128,131,
134,137,140,143,146,166,169,172,175,178,181,184,187,190,193,196,
199,202,222,225,228,231,234,237,240,243,246,249,252,255,258, 0,
7, 13, 27, 30, 34, 33, 12, 18, 17, 22, 47,103,159,215, 53, 56,
59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89,109,112,115,118,121,
124,127,130,133,136,139,142,145,165,168,171,174,177,180,183,186,
189,192,195,198,201,221,224,227,230,233,236,239,242,245,248,251,
254,257, 6, 26,
};
static void
tch_fr_d_to_b(ubit_t *b_bits, ubit_t *d_bits)
{
int i;
for (i = 0; i < 260; i++)
b_bits[d_to_b_index[i]] = d_bits[i];
}
static void
tch_fr_b_to_d(ubit_t *d_bits, ubit_t *b_bits)
{
int i;
for (i = 0; i < 260; i++)
d_bits[i] = b_bits[d_to_b_index[i]];
}
static void
tch_fr_unreorder(ubit_t *d, ubit_t *p, ubit_t *u)
{
int i;
for (i=0; i<91; i++) {
d[i<<1] = u[i];
d[(i<<1)+1] = u[184-i];
}
for (i=0; i<3; i++)
p[i] = u[91+i];
}
static void
tch_fr_reorder(ubit_t *u, ubit_t *d, ubit_t *p)
{
int i;
for (i=0; i<91; i++) {
u[i] = d[i<<1];
u[184-i] = d[(i<<1)+1];
}
for (i=0; i<3; i++)
u[91+i] = p[i];
}
int
tch_fr_decode(uint8_t *tch_data, sbit_t *bursts, int network_order)
{
sbit_t iB[912], cB[456], h;
ubit_t conv[185], b[260], d[260], p[3];
int i, rv, len, steal = 0;
for (i=0; i<8; i++) {
tch_fr_burst_unmap(&iB[i * 114], &bursts[i * 116], &h, i>>2);
if (h < 0)
steal++;
}
tch_fr_deinterleave(cB, iB);
if (steal < 4) {
osmo_conv_decode(&conv_tch_fr, cB, conv);
tch_fr_unreorder(d, p, conv);
for (i=0; i<78; i++)
d[i+182] = (cB[i+378] < 0) ? 1:0;
rv = osmo_crc8gen_check_bits(&tch_fr_crc3, d, 50, p);
if (rv)
return -1;
if (network_order) {
tch_fr_d_to_b(b, d);
tch_fr_reassemble(tch_data, b);
} else
tch_fr_d_to_b(tch_data, d);
len = 33;
} else {
rv = xcch_decode_cB(tch_data, cB);
if (rv)
return -1;
len = 23;
}
return len;
}
int
tch_fr_encode(ubit_t *bursts, uint8_t *tch_data, int len, int network_order)
{
ubit_t iB[912], cB[456], h;
ubit_t conv[185], b[260], d[260], p[3];
int i;
switch (len) {
case 33: /* TCH FR */
if (network_order) {
tch_fr_disassemble(b, tch_data);
tch_fr_b_to_d(d, b);
} else
tch_fr_b_to_d(d, tch_data);
osmo_crc8gen_set_bits(&tch_fr_crc3, d, 50, p);
tch_fr_reorder(conv, d, p);
memcpy(cB+378, d+182, 78);
osmo_conv_encode(&conv_tch_fr, conv, cB);
h = 0;
break;
case 23: /* FACCH */
xcch_encode_cB(cB, tch_data);
h = 1;
break;
default:
return -1;
}
tch_fr_interleave(cB, iB);
for (i=0; i<8; i++)
tch_fr_burst_map(&iB[i * 114], &bursts[i * 116], &h, i>>2);
return 0;
}

View File

@ -1,8 +0,0 @@
#ifndef _TCH_FR_H
#define _TCH_FR_H
int tch_fr_decode(uint8_t *tch_data, sbit_t *bursts, int network_order);
int tch_fr_encode(ubit_t *bursts, uint8_t *tch_data, int len,
int network_order);
#endif /* _TCH_FR_H */

View File

@ -1,193 +0,0 @@
/*
* xcch.c
*
* Copyright (c) 2011 Sylvain Munaut <tnt@246tNt.com>
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/conv.h>
#include <osmocom/core/crcgen.h>
#include "xcch.h"
/*
* GSM xCCH parity (FIRE code)
*
* g(x) = (x^23 + 1)(x^17 + x^3 + 1)
* = x^40 + x^26 + x^23 + x^17 + x^3 + 1
*/
const struct osmo_crc64gen_code xcch_crc40 = {
.bits = 40,
.poly = 0x0004820009ULL,
.init = 0x0000000000ULL,
.remainder = 0xffffffffffULL,
};
/*
* GSM xCCH convolutional coding
*
* G_0 = 1 + x^3 + x^4
* G_1 = 1 + x + x^3 + x^4
*/
static const uint8_t conv_xcch_next_output[][2] = {
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
{ 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
};
static const uint8_t conv_xcch_next_state[][2] = {
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
{ 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
};
static const struct osmo_conv_code conv_xcch = {
.N = 2,
.K = 5,
.len = 224,
.next_output = conv_xcch_next_output,
.next_state = conv_xcch_next_state,
};
/*
* GSM xCCH interleaving and burst mapping
*
* Interleaving:
*
* Given 456 coded input bits, form 4 blocks of 114 bits:
*
* i(B, j) = c(n, k) k = 0, ..., 455
* n = 0, ..., N, N + 1, ...
* B = B_0 + 4n + (k mod 4)
* j = 2(49k mod 57) + ((k mod 8) div 4)
*
* Mapping on Burst:
*
* e(B, j) = i(B, j)
* e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
* e(B, 57) = h_l(B)
* e(B, 58) = h_n(B)
*
* Where hl(B) and hn(B) are bits in burst B indicating flags.
*/
static void
xcch_deinterleave(sbit_t *cB, sbit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 3;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
cB[k] = iB[B * 114 + j];
}
}
static void
xcch_interleave(ubit_t *cB, ubit_t *iB)
{
int j, k, B;
for (k=0; k<456; k++) {
B = k & 3;
j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
iB[B * 114 + j] = cB[k];
}
}
static void
xcch_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *hl, sbit_t *hn)
{
memcpy(iB, eB, 57);
memcpy(iB+57, eB+59, 57);
if (hl)
*hl = eB[57];
if (hn)
*hn = eB[58];
}
static void
xcch_burst_map(ubit_t *iB, ubit_t *eB, ubit_t *hl, ubit_t *hn)
{
memcpy(eB, iB, 57);
memcpy(eB+59, iB+57, 57);
if (hl)
eB[57] = *hl;
if (hn)
eB[58] = *hn;
}
int
xcch_decode_cB(uint8_t *l2_data, sbit_t *cB)
{
ubit_t conv[224];
int rv;
osmo_conv_decode(&conv_xcch, cB, conv);
rv = osmo_crc64gen_check_bits(&xcch_crc40, conv, 184, conv+184);
if (rv)
return -1;
osmo_ubit2pbit_ext(l2_data, 0, conv, 0, 184, 1);
return 0;
}
int
xcch_decode(uint8_t *l2_data, sbit_t *bursts)
{
sbit_t iB[456], cB[456];
int i;
for (i=0; i<4; i++)
xcch_burst_unmap(&iB[i * 114], &bursts[i * 116], NULL, NULL);
xcch_deinterleave(cB, iB);
return xcch_decode_cB(l2_data, cB);
}
int
xcch_encode_cB(ubit_t *cB, uint8_t *l2_data)
{
ubit_t conv[224];
osmo_pbit2ubit_ext(conv, 0, l2_data, 0, 184, 1);
osmo_crc64gen_set_bits(&xcch_crc40, conv, 184, conv+184);
osmo_conv_encode(&conv_xcch, conv, cB);
return 0;
}
int
xcch_encode(ubit_t *bursts, uint8_t *l2_data)
{
ubit_t iB[456], cB[456], hl = 1, hn = 1;
int i;
xcch_encode_cB(cB, l2_data);
xcch_interleave(cB, iB);
for (i=0; i<4; i++)
xcch_burst_map(&iB[i * 114], &bursts[i * 116], &hl, &hn);
return 0;
}

View File

@ -1,10 +0,0 @@
#ifndef _XCCH_H
#define _XCCH_H
int xcch_decode_cB(uint8_t *l2_data, sbit_t *cB);
int xcch_decode(uint8_t *l2_data, sbit_t *bursts);
int xcch_encode_cB(ubit_t *cB, uint8_t *l2_data);
int xcch_encode(ubit_t *bursts, uint8_t *l2_data);
#endif /* _XCCH_H */

View File

@ -5,9 +5,10 @@ noinst_PROGRAMS = bursts_test
EXTRA_DIST = bursts_test.ok
bursts_test_SOURCES = bursts_test.c \
$(top_builddir)/src/osmo-bts-trx/xcch.c \
$(top_builddir)/src/osmo-bts-trx/rach.c \
$(top_builddir)/src/osmo-bts-trx/sch.c \
$(top_builddir)/src/osmo-bts-trx/tch_fr.c \
$(top_builddir)/src/osmo-bts-trx/pxxch.c
$(top_builddir)/src/osmo-bts-trx/gsm0503_coding.c \
$(top_builddir)/src/osmo-bts-trx/gsm0503_conv.c \
$(top_builddir)/src/osmo-bts-trx/gsm0503_interleaving.c \
$(top_builddir)/src/osmo-bts-trx/gsm0503_mapping.c \
$(top_builddir)/src/osmo-bts-trx/gsm0503_tables.c \
$(top_builddir)/src/osmo-bts-trx/gsm0503_parity.c
bursts_test_LDADD = $(LDADD)

View File

@ -26,11 +26,7 @@
#include <osmocom/core/bits.h>
#include <osmocom/core/utils.h>
#include "../../src/osmo-bts-trx/xcch.h"
#include "../../src/osmo-bts-trx/rach.h"
#include "../../src/osmo-bts-trx/sch.h"
#include "../../src/osmo-bts-trx/tch_fr.h"
#include "../../src/osmo-bts-trx/pxxch.h"
#include "../../src/osmo-bts-trx/gsm0503_coding.h"
#define ASSERT_TRUE(rc) \