summaryrefslogtreecommitdiff
path: root/gsm-receiver/src/lib/decoder/openbtsstuff/GSMTDMA.h
blob: 3b55b9422229cadbc08a074a9cee88220d189b4f (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/**@file Common-use GSM declarations, most from the GSM 04.xx and 05.xx series. */
/*
* Copyright 2008 Free Software Foundation, Inc.
*
* This software is distributed under the terms of the GNU Public License.
* See the COPYING file in the main directory for details.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/



#ifndef GSMTDMA_H
#define GSMTDMA_H


#include "GSMCommon.h"


namespace GSM {


/**
	A description of a channel's multiplexing pattern.
	From GSM 05.02 Clause 7.
	This object encodes a line from tables 1-4 in the spec.
	The columns of interest in this encoding are:
		- 1, Channel Designation
		- 2, Subchannel
		- 3, Direction
		- 4, Allowable Time Slot Assignments
		- 5, Allowable RF Channel Assignments
		- 7, Repeat Length in TDMA Frames
		- 8, Interleaved Block TDMA Frame Mapping

	Col 6, Burst Type, is implied by 1 & 2 and encoded into the transcevier source code.
*/
class TDMAMapping {

	public:

	/// The longest "repeat length" of any channel we support is 104 for the SACCH/TF.
	static const unsigned mMaxRepeatLength = 104;

	private:

	TypeAndOffset mTypeAndOffset;				///< col 1, 2, encoded as per GSM 04.08 10.5.2.5
	bool mDownlink;								///< col 3, true for downlink channels
	bool mUplink;								///< col 3, true for uplink channels
	char mAllowedSlots;							///< col 4, an 8-bit mask
	bool mC0Only;								///< col 5, true if channel is limited to C0
	unsigned mRepeatLength;						///< col 7
	unsigned mNumFrames;						///< number of occupied frames in col 8
	const unsigned *mFrameMapping;				///< col 8
	unsigned mReverseMapping[mMaxRepeatLength];	///< index reversal of mapping, -1 means unused


	public:


	/**
		Construct a TDMAMapping, encoding one line of GSM 05.02 Clause 7 Tables 1-4.
		@param wTypeAndOffset Encoding of "Channel designnation".  See GSM 04.08 10.5.2.5.
		@param wDownlink True for downlink and bidirectional hannels
		@param wUplink True for uplink and bidirectional channels
		@param wRepeatLength "Repeat Length in TDMA Frames"
		@param wNumFrames Number of occupied TDMA frames in frame mapping.
		@param wFrameMapping "Interleaved Block TDMA Frame Mapping" -- MUST PERSIST!!
	*/
	TDMAMapping(TypeAndOffset wTypeAndOffset,
		bool wDownlink, bool wUplink, char wAllowedSlots, bool wC0Only,
		unsigned wRepeatLength, unsigned wNumFrames, const unsigned *wFrameMapping);

	/** Given a count of frames sent, return the corresponding frame number. */
	unsigned frameMapping(unsigned count) const
		{ return mFrameMapping[count % mNumFrames]; }

	/** Given a frame number, return the corresponding count, modulo patten length. */
	int reverseMapping(unsigned FN) const
		{ return mReverseMapping[FN % mRepeatLength]; }

	/**@name Simple accessors. */
	//@{
	unsigned numFrames() const { return mNumFrames; }

	unsigned repeatLength() const { return mRepeatLength; }

	TypeAndOffset typeAndOffset() const { return mTypeAndOffset; }

	bool uplink() const { return mUplink; }

	bool downlink() const { return mDownlink; }

	bool C0Only() const { return mC0Only; }
	//@}

	///< Return true if this channel is allowed on this slot.
	bool allowedSlot(unsigned slot) const
		{ return mAllowedSlots & (1<<slot); }
};



/**@name Mux parameters for standard channels, from GSM 05.03 Clause 7 Tables 1-4. */
//@{
/**@name Beacon channels */
//@{
extern const TDMAMapping gFCCHMapping;		///< GSM 05.02 Clause 7 Table 3 Line 1 B0-B4
extern const TDMAMapping gSCHMapping;		///< GSM 05.02 Clause 7 Table 3 Line 2 B0-B4
extern const TDMAMapping gBCCHMapping;		///< GSM 05.02 Clause 7 Table 3 Line 3
/// GSM 05.02 Clause 7 Table 3 Line 7 B0-B50, excluding C-V SDCCH parts (SDCCH/4 and SCCH/C4)
extern const TDMAMapping gRACHC5Mapping;
extern const TDMAMapping gCCCH_0Mapping;	///< GSM 05.02 Clause 7 Table 3 Line 5 B0
extern const TDMAMapping gCCCH_1Mapping;	///< GSM 05.02 Clause 7 Table 3 Line 5 B1
extern const TDMAMapping gCCCH_2Mapping;	///< GSM 05.02 Clause 7 Table 3 Line 5 B2
extern const TDMAMapping gCCCH_3Mapping;	///< GSM 05.02 Clause 7 Table 3 Line 5 B3
extern const TDMAMapping gCCCH_4Mapping;	///< GSM 05.02 Clause 7 Table 3 Line 5 B4
extern const TDMAMapping gCCCH_5Mapping;	///< GSM 05.02 Clause 7 Table 3 Line 5 B5
extern const TDMAMapping gCCCH_6Mapping;	///< GSM 05.02 Clause 7 Table 3 Line 5 B6
extern const TDMAMapping gCCCH_7Mapping;	///< GSM 05.02 Clause 7 Table 3 Line 5 B7
extern const TDMAMapping gCCCH_8Mapping;	///< GSM 05.02 Clause 7 Table 3 Line 5 B8
//@}
/**@name SDCCH */
//@{
///@name For Combination V
//@{
extern const TDMAMapping gSDCCH_4_0DMapping;	///< GSM 05.02 Clause 7 Table 3 Line 10/0D
extern const TDMAMapping gSDCCH_4_0UMapping;	///< GSM 05.02 Clause 7 Table 3 Line 10/0U
extern const TDMAMapping gSDCCH_4_1DMapping;
extern const TDMAMapping gSDCCH_4_1UMapping;
extern const TDMAMapping gSDCCH_4_2DMapping;
extern const TDMAMapping gSDCCH_4_2UMapping;
extern const TDMAMapping gSDCCH_4_3DMapping;
extern const TDMAMapping gSDCCH_4_3UMapping;
//@}
///@name For Combination VII
//@{
extern const TDMAMapping gSDCCH_8_0DMapping;
extern const TDMAMapping gSDCCH_8_0UMapping;
extern const TDMAMapping gSDCCH_8_1DMapping;
extern const TDMAMapping gSDCCH_8_1UMapping;
extern const TDMAMapping gSDCCH_8_2DMapping;
extern const TDMAMapping gSDCCH_8_2UMapping;
extern const TDMAMapping gSDCCH_8_3DMapping;
extern const TDMAMapping gSDCCH_8_3UMapping;
extern const TDMAMapping gSDCCH_8_4DMapping;
extern const TDMAMapping gSDCCH_8_4UMapping;
extern const TDMAMapping gSDCCH_8_5DMapping;
extern const TDMAMapping gSDCCH_8_5UMapping;
extern const TDMAMapping gSDCCH_8_6DMapping;
extern const TDMAMapping gSDCCH_8_6UMapping;
extern const TDMAMapping gSDCCH_8_7DMapping;
extern const TDMAMapping gSDCCH_8_7UMapping;
//@}
//@}
/**@name SACCH */
//@{
/**name SACCH for SDCCH */
//@{
///@name For Combination V
//@{
extern const TDMAMapping gSACCH_C4_0DMapping;
extern const TDMAMapping gSACCH_C4_0UMapping;
extern const TDMAMapping gSACCH_C4_1DMapping;
extern const TDMAMapping gSACCH_C4_1UMapping;
extern const TDMAMapping gSACCH_C4_2DMapping;
extern const TDMAMapping gSACCH_C4_2UMapping;
extern const TDMAMapping gSACCH_C4_3DMapping;
extern const TDMAMapping gSACCH_C4_3UMapping;
//@}
///@name For Combination VII
//@{
extern const TDMAMapping gSACCH_C8_0DMapping;
extern const TDMAMapping gSACCH_C8_0UMapping;
extern const TDMAMapping gSACCH_C8_1DMapping;
extern const TDMAMapping gSACCH_C8_1UMapping;
extern const TDMAMapping gSACCH_C8_2DMapping;
extern const TDMAMapping gSACCH_C8_2UMapping;
extern const TDMAMapping gSACCH_C8_3DMapping;
extern const TDMAMapping gSACCH_C8_3UMapping;
extern const TDMAMapping gSACCH_C8_4DMapping;
extern const TDMAMapping gSACCH_C8_4UMapping;
extern const TDMAMapping gSACCH_C8_5DMapping;
extern const TDMAMapping gSACCH_C8_5UMapping;
extern const TDMAMapping gSACCH_C8_6DMapping;
extern const TDMAMapping gSACCH_C8_6UMapping;
extern const TDMAMapping gSACCH_C8_7DMapping;
extern const TDMAMapping gSACCH_C8_7UMapping;
//@}
//@}
/**@name SACCH for TCH/F on different timeslots. */
//@{
extern const TDMAMapping gSACCH_TF_T0Mapping;
extern const TDMAMapping gSACCH_TF_T1Mapping;
extern const TDMAMapping gSACCH_TF_T2Mapping;
extern const TDMAMapping gSACCH_TF_T3Mapping;
extern const TDMAMapping gSACCH_TF_T4Mapping;
extern const TDMAMapping gSACCH_TF_T5Mapping;
extern const TDMAMapping gSACCH_TF_T6Mapping;
extern const TDMAMapping gSACCH_TF_T7Mapping;
//@}
//@}
/**name FACCH+TCH/F placement */
//@{
extern const TDMAMapping gFACCH_TCHFMapping;
//@}
/**@name Test fixtures. */
extern const TDMAMapping gLoopbackTestFullMapping;
extern const TDMAMapping gLoopbackTestHalfUMapping;
extern const TDMAMapping gLoopbackTestHalfDMapping;
//@}


/** Combined uplink/downlink information. */
class MappingPair {

	private:

	const TDMAMapping& mDownlink;
	const TDMAMapping& mUplink;

	public:

	MappingPair(const TDMAMapping& wDownlink, const TDMAMapping& wUplink)
		:mDownlink(wDownlink), mUplink(wUplink)
	{}

	MappingPair(const TDMAMapping& wMapping)
		:mDownlink(wMapping), mUplink(wMapping)
	{}

	const TDMAMapping& downlink() const { return mDownlink; }
	const TDMAMapping& uplink() const { return mUplink; }

};


/**@name Common placement pairs. */
//@{
/**@ SDCCH placement pairs. */
//@{
extern const MappingPair gSDCCH_4_0Pair;
extern const MappingPair gSDCCH_4_1Pair;
extern const MappingPair gSDCCH_4_2Pair;
extern const MappingPair gSDCCH_4_3Pair;
extern const MappingPair gSDCCH_8_0Pair;
extern const MappingPair gSDCCH_8_1Pair;
extern const MappingPair gSDCCH_8_2Pair;
extern const MappingPair gSDCCH_8_3Pair;
extern const MappingPair gSDCCH_8_4Pair;
extern const MappingPair gSDCCH_8_5Pair;
extern const MappingPair gSDCCH_8_6Pair;
extern const MappingPair gSDCCH_8_7Pair;
//@}
/**@ SACCH-for-SDCCH placement pairs. */
//@{
extern const MappingPair gSACCH_C4_0Pair;
extern const MappingPair gSACCH_C4_1Pair;
extern const MappingPair gSACCH_C4_2Pair;
extern const MappingPair gSACCH_C4_3Pair;
extern const MappingPair gSACCH_C8_0Pair;
extern const MappingPair gSACCH_C8_1Pair;
extern const MappingPair gSACCH_C8_2Pair;
extern const MappingPair gSACCH_C8_3Pair;
extern const MappingPair gSACCH_C8_4Pair;
extern const MappingPair gSACCH_C8_5Pair;
extern const MappingPair gSACCH_C8_6Pair;
extern const MappingPair gSACCH_C8_7Pair;
//@}
/**@name Traffic channels. */
//@{
extern const MappingPair gFACCH_TCHFPair;
extern const MappingPair gSACCH_FT_T0Pair;
extern const MappingPair gSACCH_FT_T1Pair;
extern const MappingPair gSACCH_FT_T2Pair;
extern const MappingPair gSACCH_FT_T3Pair;
extern const MappingPair gSACCH_FT_T4Pair;
extern const MappingPair gSACCH_FT_T5Pair;
extern const MappingPair gSACCH_FT_T6Pair;
extern const MappingPair gSACCH_FT_T7Pair;
//@}
//@}



/** A CompleteMapping includes uplink, downlink and the SACCH. */
class CompleteMapping {

	private:

	const MappingPair& mLCH;
	const MappingPair& mSACCH;

	public:

	CompleteMapping(const MappingPair& wLCH, const MappingPair& wSACCH)
		:mLCH(wLCH), mSACCH(wSACCH)
	{}

	const MappingPair& LCH() const { return mLCH; }
	const MappingPair& SACCH() const { return mSACCH; }

};



/**@name Complete placements for common channel types. */
//@{
/**@name SDCCH/4 */
//@{
extern const CompleteMapping gSDCCH_4_0;
extern const CompleteMapping gSDCCH_4_1;
extern const CompleteMapping gSDCCH_4_2;
extern const CompleteMapping gSDCCH_4_3;
//@}
/**@name SDCCH/8 */
//@{
extern const CompleteMapping gSDCCH_8_0;
extern const CompleteMapping gSDCCH_8_1;
extern const CompleteMapping gSDCCH_8_2;
extern const CompleteMapping gSDCCH_8_3;
extern const CompleteMapping gSDCCH_8_4;
extern const CompleteMapping gSDCCH_8_5;
extern const CompleteMapping gSDCCH_8_6;
extern const CompleteMapping gSDCCH_8_7;
//@}
/**@name TCH/F on different slots. */
//@{
extern const CompleteMapping gTCHF_T0;
extern const CompleteMapping gTCHF_T1;
extern const CompleteMapping gTCHF_T2;
extern const CompleteMapping gTCHF_T3;
extern const CompleteMapping gTCHF_T4;
extern const CompleteMapping gTCHF_T5;
extern const CompleteMapping gTCHF_T6;
extern const CompleteMapping gTCHF_T7;
//@}
//@}


}; 	// namespace GSM


#endif

// vim: ts=4 sw=4
personal git repositories of Harald Welte. Your mileage may vary