1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "gsmstack.h"
#include "cch.h"
#include "tch.h"
/* convert an 18byte 8-bit-per-byte burst to a 142byte 1bit-per-byte */
static void bit_per_byte(unsigned char *dest, const unsigned char *src)
{
int bit, byte;
for (byte = 0; byte < BURST_BYTES; src++) {
for (bit = 0; bit < 8; bit++) {
if (src[byte] >> bit &= 0x01)
*dest++ = 0x01;
else
*dest++ = 0x00;
}
}
}
static int add_burst_to_lchan(struct gsm_logi_chan *lchan,
struct gsm_burst *burst)
{
struct gsm_phys_chan *pchan = burst->pchan;
int rc = 0;
/* copy burst to burst buffer */
memcpy(lchan->burst_buf[lchan->next_burst], burst, sizeof(*burst));
lchan->next_burst++;
if (lchan->next_burst == 4) {
lchan->next_burst = 0;
/* decode the four bursts into a MAC block */
switch (pchan->config) {
case GSM_PCHAN_TCH_H:
/* FIXME */
break;
case GSM_PCHAN_TCH_F:
rc = tch_decode();
break;
case GSM_PCHAN_CCCH:
case GSM_PCHAN_SDCCH8_SACCH8C:
rc = cch_decode();
break;
default:
fprintf(stderr, "unknown pchan config %u\n",
pchan->config);
}
/* pass the resulting MAC block up the stack */
if (rc)
rc = gsm_lchan_macblock()
}
return rc;
}
static int gsm_rx_sdcch8(struct gsm_burst *burst)
{
struct gsm_phys_chan *pchan = burst->gsm_pchan;
int rc = -EINVAL;
if (burst_type == GSM_BURST_DUMMY)
return;
if (burst->type != GSM_BURST_NORMAL) {
fprintf(stderr, "Burst type %u not allowed in SDCCH8\n",
burst->type);
/* FIXME: statistics */
return rc;
}
lchan = get_lchan(pchan, burst->fnr);
return add_burst_to_lchan(lchan, burst);
}
static int gsm_rx_tch_f(struct gsm_burst *burst)
{
struct gsm_phys_chan *pchan = burst->gsm_pchan;
struct gsm_logi_chan *lchan;
int rc = -EINVAL;
if (burst->type != GSM_BURST_NORMAL)
return rc;
lchan = get_lchan(pchan, fnr);
return add_burst_to_lchan(lchan, burst);
}
/* input a new GSM Um burst on a CCCH */
static int gsm_rx_ccch(struct gsm_burst *burst)
{
struct gsm_phys_chan *pchan = burst->gsm_pchan;
struct gsm_logi_chan *lchan;
int rc = -EINVAL;
switch (burst->type) {
case GSM_BURST_FCCH:
/* FIXME */
/* obtain the frequency offset and report to caller */
break;
case GSM_BURST_SCH:
/* obtain the RFN from the SCH burst */
/* FIXME */
break;
case GSM_BURST_NORMAL:
/* determine logical channel and append burst */
lchan = get_lchan(pchan, burst->fnr);
rc = add_burst_to_lchan(lchan, burst);
break;
default:
break;
};
return rc;
}
/* input a new GSM Um interface burst into the stack */
int gsm_rx_burst(struct gsm_burst *burst, int bits)
{
struct gsm_phys_chan *pchan;
int rc = -EINVAL;
/* we assume the following fields have already been
* filled-in by the caller:
* phys_chan, rx_time, rx_frame_nr, decoded/decoded_bits */
pchan = burst->phys_chan;
if (!bits)
bit_per_byte(burst->decoded_bits, burst->decoded);
pchan->stats.rx_total++;
pchan->stats.rx_type[burst->type]++;
switch (pchan->config) {
case GSM_PCHAN_CCCH:
rc = gsm_rx_ccch(burst);
break;
case GSM_PCHAN_SDCCH8_SACCH8C:
rc = gsm_rx_sdcch8(burst);
break;
case GSM_PCHAN_TCH_F:
rc = gsm_rx_tch_h(burst);
break;
case GSM_PCHAN_TCH_H:
case GSM_PCHAN_UNKNOWN:
default:
fprintf(stderr, "unknown pchan config (ts=%u\n)\n",
pchan->timeslot);
return;
break;
}
}
|