Project

General

Profile

Bug #1854 ยป rach_test.c

fixeria, 04/21/2019 08:50 PM

 
1
/**
2
 * Simple 8-bit vs 11-bit RACH collision test for libosmocoding.
3
 * cc rach_test.c `pkg-config --libs libosmocoding --cflags libosmocoding` -o rach_test
4
 */
5

    
6
#include <stdbool.h>
7
#include <stdint.h>
8
#include <stdio.h>
9

    
10
#include <osmocom/core/bits.h>
11
#include <osmocom/core/utils.h>
12
#include <osmocom/coding/gsm0503_coding.h>
13

    
14
#define RACH_PAYLOAD_LEN 36
15

    
16
static unsigned int count_11b28b_collisions = 0;
17
static unsigned int count_8b211b_collisions = 0;
18

    
19
/* Encoding as 11-bit, decoding as 8-bit */
20
static void test_11b28b_collisions(uint16_t ra11, uint8_t bsic)
21
{
22
	ubit_t ubuf[RACH_PAYLOAD_LEN];
23
	sbit_t sbuf[RACH_PAYLOAD_LEN];
24
	uint16_t _ra11;
25
	uint8_t ra8;
26
	int rc;
27

    
28
	/* Encode an extended (11-bit) RACH */
29
	rc = gsm0503_rach_ext_encode(ubuf, ra11, bsic, true);
30
	OSMO_ASSERT(rc == 0);
31

    
32
	/* Convert hard-bits to soft-bits */
33
	osmo_ubit2sbit(sbuf, ubuf, RACH_PAYLOAD_LEN);
34

    
35
	/* Self-test: attempt to decode as extended (11-bit) RACH */
36
	rc = gsm0503_rach_ext_decode_ber(&_ra11, sbuf, bsic, NULL, NULL);
37
	OSMO_ASSERT(rc == 0 && ra11 == _ra11);
38

    
39
	/* Attempt to decode as a regular (8-bit) RACH */
40
	rc = gsm0503_rach_decode_ber(&ra8, sbuf, bsic, NULL, NULL);
41
	if (rc == 0) {
42
		printf("Successfully decoded 11-bit (0x%04x) RACH as 8-bit (0x%02x): bsic=0x%02x\n",
43
		       ra11, ra8, bsic);
44
		count_11b28b_collisions++;
45
	}
46
}
47

    
48
/* Encoding as 8-bit, decoding as 11-bit */
49
static int test_8b11b_collisions(uint8_t ra8, uint8_t bsic)
50
{
51
	ubit_t ubuf[RACH_PAYLOAD_LEN];
52
	sbit_t sbuf[RACH_PAYLOAD_LEN];
53
	uint16_t ra11;
54
	uint8_t _ra8;
55
	int rc;
56

    
57
	/* Encode a regular (8-bit) RACH */
58
	rc = gsm0503_rach_ext_encode(ubuf, ra8, bsic, false);
59
	OSMO_ASSERT(rc == 0);
60

    
61
	/* Convert hard-bits to soft-bits */
62
	osmo_ubit2sbit(sbuf, ubuf, RACH_PAYLOAD_LEN);
63

    
64
	/* Self-test: attempt to decode as regular (8-bit) RACH */
65
	rc = gsm0503_rach_decode_ber(&_ra8, sbuf, bsic, NULL, NULL);
66
	OSMO_ASSERT(rc == 0 && ra8 == _ra8);
67

    
68
	/* Attempt to decode as an extended (11-bit) RACH */
69
	rc = gsm0503_rach_ext_decode_ber(&ra11, sbuf, bsic, NULL, NULL);
70
	if (rc == 0) {
71
		printf("Successfully decoded 8-bit (0x%02x) RACH as 11-bit (0x%04x): bsic=0x%02x\n",
72
		       ra8, ra11, bsic);
73
		count_8b211b_collisions++;
74
	}
75
}
76

    
77
int main(int argc, char **argv)
78
{
79
	uint8_t bsic;
80
	int i, rc;
81

    
82
	printf("=== Looking for possible collisions: decoding 8-bit RACH as 11-bit\n");
83
	for (bsic = 0; bsic <= 63; bsic++)
84
		for (i = 0; i <= 0xff; i++)
85
			test_8b11b_collisions((uint8_t) i, bsic);
86

    
87
	puts("");
88

    
89
	printf("=== Looking for possible collisions: decoding 11-bit RACH as 8-bit\n");
90
	for (bsic = 0; bsic <= 63; bsic++)
91
		for (i = 0; i <= 0x7ff; i++)
92
			test_11b28b_collisions((uint16_t) i, bsic);
93

    
94
	puts("");
95

    
96
	printf("=== Results: \n");
97
	printf(" - decoding 8-bit RACH as 11-bit: %u\n", count_8b211b_collisions);
98
	printf(" - decoding 11-bit RACH as 8-bit: %u\n", count_11b28b_collisions);
99

    
100
	return 0;
101
}
    (1-1/1)
    Add picture from clipboard (Maximum size: 48.8 MB)