comparison src/aci2/alr/alr_rach.c @ 3:93999a60b835

src/aci2, src/condat2: import of g23m/condat source pieces from TCS211
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2016 00:29:36 +0000
parents
children
comparison
equal deleted inserted replaced
2:c41a534f33c6 3:93999a60b835
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-PS
4 | Modul : ALR_RACH
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This Modul defines the SDL process RACH_Control.
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef ALR_RACH_C
22 #define ALR_RACH_C
23
24 #define ENTITY_PL
25
26 /*==== INCLUDES ===================================================*/
27 #include <string.h>
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include "typedefs.h"
31 #include "pconst.cdg"
32 #include "mconst.cdg"
33 #include "message.h"
34 #include "ccdapi.h"
35 #include "vsi.h"
36 #include "custom.h"
37 #include "gsm.h"
38 #include "prim.h"
39 #include "cnf_alr.h"
40 #include "mon_alr.h"
41 #include "pei.h"
42 #include "tok.h"
43 #include "pcm.h"
44 #ifdef GPRS
45 #include "alr_gprs.h"
46 #endif
47
48 #include "alr.h"
49 #include "alr_em.h"
50
51 /*==== EXPORT =====================================================*/
52 /*==== PRIVAT =====================================================*/
53
54 /*==== VARIABLES ==================================================*/
55 #if defined (WIN32)
56 #define TRACING
57 #endif
58
59 #if defined (TRACING)
60 #define ALR_TRACE_RACH(a) ALR_TRACE(a)
61 #else
62 #define ALR_TRACE_RACH(a)
63 #endif
64
65 #if defined (TRACING)
66
67 #define ALR_TRACE_RACH_CLASS(x) TRACE_EVENT_P1 ("class %d",x)
68 #define ALR_TRACE_RACH_POWER(p) TRACE_EVENT_P1 ("configured power = %d", p)
69
70 #else
71
72 #define ALR_TRACE_RACH_CLASS(x)
73 #define ALR_TRACE_RACH_POWER(p)
74
75 #endif
76
77 /*==== FUNCTIONS ==================================================*/
78
79 /*
80 +--------------------------------------------------------------------+
81 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
82 | STATE : code ROUTINE : rach_init |
83 +--------------------------------------------------------------------+
84
85 PURPOSE : Initialize RACH Control Process.
86
87 */
88
89 GLOBAL void rach_init (void)
90 {
91 alr_data->state[STATE_RA] = RA_NULL;
92 }
93
94 /*
95 +--------------------------------------------------------------------+
96 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
97 | STATE : code ROUTINE : rach_configure_class |
98 +--------------------------------------------------------------------+
99
100 PURPOSE : Process signal rach_configure_class from SDL process
101 Main_Control.
102
103 */
104 GLOBAL void rach_configure_class (UBYTE ms_class,
105 UBYTE dcs_class)
106 {
107 /*
108 * +1 because of interface difference between RR and TI
109 */
110 alr_data->rach_data.ms_class = (UBYTE)(ms_class + 1);
111 alr_data->rach_data.dcs_class = (UBYTE)(dcs_class + 1);
112
113 ALR_TRACE_RACH_CLASS (alr_data->rach_data.ms_class);
114 }
115
116 /*
117 +--------------------------------------------------------------------+
118 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
119 | STATE : code ROUTINE : rach_configure_power |
120 +--------------------------------------------------------------------+
121
122 PURPOSE : Process signal rach_configure_power from SDL process
123 Main_Control.
124
125 */
126
127 GLOBAL void rach_configure_power (UBYTE power)
128 {
129 ALR_TRACE_RACH_POWER(power);
130
131 alr_data->rach_data.max_tx_pwr_ccch = power;
132 }
133 /*
134 +--------------------------------------------------------------------+
135 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
136 | STATE : code ROUTINE : rach_stop |
137 +--------------------------------------------------------------------+
138
139 PURPOSE : Process signal rach_stop from SDL process
140 Main_Control.
141 */
142
143 GLOBAL void rach_stop (void)
144 {
145 switch (GET_STATE (STATE_RA))
146 {
147 case RA_ACTIVE:
148 ma_rach_stop_ra_req ();
149 /*lint -fallthrough*/
150 case RA_LISTEN_TO_CCCH:
151 SET_STATE (STATE_RA, RA_NULL);
152 break;
153
154 default:
155 break;
156 }
157 }
158
159
160 /*
161 +--------------------------------------------------------------------+
162 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
163 | STATE : code ROUTINE : rach_random_req |
164 +--------------------------------------------------------------------+
165
166 PURPOSE : Process signal rach_random_req from SDL process
167 Main_Control.
168
169 */
170
171 GLOBAL void rach_random_req (T_MPH_RANDOM_ACCESS_REQ *random_req)
172 {
173 switch (GET_STATE (STATE_RA))
174 {
175 case RA_NULL:
176 if (random_req->send_mode.no NEQ 0)
177 {
178 PALLOC (ra_req, MPHC_RA_REQ);
179
180 ALR_EM_START_CONNECTION_ESTABLISHMENT;
181
182 /*
183 * Start Random Burst Sending
184 */
185 memcpy (alr_data->rach_data.delta, random_req->send_mode.delta,
186 sizeof (alr_data->rach_data.delta));
187 memcpy (alr_data->rach_data.channel_request,
188 random_req->send_mode.rach,
189 sizeof (alr_data->rach_data.channel_request));
190 alr_data->rach_data.max_bursts = random_req->send_mode.no;
191 alr_data->rach_data.c_burst = 0;
192 /*
193 * power limitation
194 */
195 ra_req->txpwr = cut_power_value (alr_data->rach_data.max_tx_pwr_ccch, NULL);
196 ra_req->powerclass_gsm = alr_data->rach_data.ms_class;
197 ra_req->powerclass_dcs = alr_data->rach_data.dcs_class;
198
199 /*
200 * Modification: Add 1 to the time of RR !!!!
201 */
202 ra_req->rand = (UBYTE)(alr_data->rach_data.delta[alr_data->rach_data.c_burst]+1);
203 ra_req->channel_request = alr_data->rach_data.channel_request[alr_data->rach_data.c_burst++];
204 SET_STATE (STATE_RA, RA_ACTIVE);
205 ma_rach_ra_req (ra_req);
206 }
207 break;
208
209 case RA_ACTIVE:
210 if (random_req->send_mode.no EQ 0)
211 {
212
213 ALR_EM_STOP_CONNECTION_ESTABLISHMENT;
214
215 SET_STATE (STATE_RA, RA_LISTEN_TO_CCCH);
216 ma_rach_stop_ra_req ();
217 }
218 else
219 {
220 /*stop to be safe */
221 ma_rach_stop_ra_req ();
222 {
223 PALLOC (ra_req, MPHC_RA_REQ);
224
225 ALR_EM_START_CONNECTION_ESTABLISHMENT;
226
227 /*
228 * Start Random Burst Sending
229 */
230 memcpy (alr_data->rach_data.delta, random_req->send_mode.delta,
231 sizeof (alr_data->rach_data.delta));
232 memcpy (alr_data->rach_data.channel_request,
233 random_req->send_mode.rach,
234 sizeof (alr_data->rach_data.channel_request));
235 alr_data->rach_data.max_bursts = random_req->send_mode.no;
236 alr_data->rach_data.c_burst = 0;
237 /*
238 * power limitation
239 */
240 ra_req->txpwr = cut_power_value (alr_data->rach_data.max_tx_pwr_ccch, NULL);
241 ra_req->powerclass_gsm = alr_data->rach_data.ms_class;
242 ra_req->powerclass_dcs = alr_data->rach_data.dcs_class;
243
244 /*
245 * Modification: Add 1 to the time of RR !!!!
246 */
247 ra_req->rand = (UBYTE)(alr_data->rach_data.delta[alr_data->rach_data.c_burst]+1);
248 ra_req->channel_request = alr_data->rach_data.channel_request[alr_data->rach_data.c_burst++];
249 SET_STATE (STATE_RA, RA_ACTIVE);
250 ma_rach_ra_req (ra_req);
251 } /*PALLOC*/
252 } /* if */
253 break;
254 default:
255 break;
256 }
257 }
258
259 /*
260 +--------------------------------------------------------------------+
261 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
262 | STATE : code ROUTINE : rach_ra_cnf |
263 +--------------------------------------------------------------------+
264
265 PURPOSE : Process signal rach_ra_cnf from SDL process
266 Main_Control.
267
268 */
269
270 GLOBAL void rach_ra_cnf (T_MPHC_RA_CON *ra_cnf)
271 {
272 UBYTE c_burst = alr_data->rach_data.c_burst-1; /* confirmed index */
273
274 switch (GET_STATE (STATE_RA))
275 {
276 case RA_ACTIVE:
277 {
278 PALLOC (random_cnf, MPH_RANDOM_ACCESS_CNF);
279
280 ra_cnf->fn %= 42432L;
281 #ifdef GPRS
282 alr_data->rach_data.t1[c_burst] =
283 random_cnf->frame_no.t1=
284 (UBYTE)((ra_cnf->fn / 1326) % 32);
285 alr_data->rach_data.t2[c_burst] =
286 random_cnf->frame_no.t2=
287 (UBYTE)(ra_cnf->fn % 26);
288 alr_data->rach_data.t3[c_burst] =
289 random_cnf->frame_no.t3=
290 (UBYTE)(ra_cnf->fn % 51);
291 #else
292 random_cnf->frame_no.t1= (UBYTE)((ra_cnf->fn / 1326) % 32);
293 random_cnf->frame_no.t2= (UBYTE)(ra_cnf->fn % 26);
294 random_cnf->frame_no.t3= (UBYTE)(ra_cnf->fn % 51);
295 #endif
296 ma_rach_random_cnf (random_cnf);
297
298 c_burst++; /* next index */
299 if (c_burst >= alr_data->rach_data.max_bursts)
300 {/* last index ? */
301 SET_STATE (STATE_RA, RA_LISTEN_TO_CCCH);
302 ma_rach_stop_ra_req ();
303 #if !defined(TNNN_WITH_TIMER)
304 ma_fake_rr_report();
305 #endif /* !TNNN_WITH_TIMER */
306 }
307 else
308 {
309 PALLOC (ra_req, MPHC_RA_REQ);
310
311 /*
312 * power limitation
313 */
314 ra_req->txpwr = cut_power_value (alr_data->rach_data.max_tx_pwr_ccch, NULL);
315 ra_req->powerclass_gsm = alr_data->rach_data.ms_class;
316 ra_req->powerclass_dcs = alr_data->rach_data.dcs_class;
317
318 /*
319 * Modification: Add 1 to the time of RR !!!!
320 */
321 ra_req->rand = (UBYTE)(alr_data->rach_data.delta[c_burst]+1);
322 ra_req->channel_request = alr_data->rach_data.channel_request[c_burst];
323 ma_rach_ra_req (ra_req);
324 alr_data->rach_data.c_burst++; /* the next index */
325 }
326 break;
327 }
328 default:
329 break;
330 }
331 }
332
333
334
335 /*
336 +--------------------------------------------------------------------+
337 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
338 | STATE : code ROUTINE : cut_power_value |
339 +--------------------------------------------------------------------+
340
341 PURPOSE : Cut the nominal maximum output power to the
342 associated power class.
343 (Reference for the tables with the associated
344 power classes, control levels and nominal output power
345 is 3GPP TS 05.05, 4.1)
346
347 */
348
349 GLOBAL UBYTE cut_power_value (UBYTE power, T_MPH_DEDICATED_REQ *mph_dedicated_req)
350 {
351 UBYTE new_power = power;
352 UBYTE sc_band;
353
354 if(mph_dedicated_req == NULL)
355 {
356 sc_band = alr_data->sc_band;
357 }
358 else
359 {
360 if(mph_dedicated_req->ch_type.h)
361 sc_band = get_band(mph_dedicated_req->ch_type.ma[0]);
362 else
363 sc_band = get_band(mph_dedicated_req->ch_type.arfcn);
364 }
365
366 switch (sc_band)
367 {
368 case BAND_GSM_900:
369 case BAND_E_GSM:
370 case BAND_GSM_850:
371 switch (alr_data->rach_data.ms_class)
372 {
373 case POW_CLASS_1: /* doesn´t exist */
374 case POW_CLASS_2: /* power class 2, 8W, 39 dBm, level 0..2 */
375 /* highest level allowed => no cut necessary */
376 break;
377 case POW_CLASS_3: /* power class 3, 5W, 37 dBm, level 3 */
378 if (new_power < 3)
379 new_power = 3;
380 break;
381 case POW_CLASS_4: /* power class 4, 2W, 33 dBm, level 5 */
382 if (new_power < 5)
383 new_power = 5;
384 break;
385 case POW_CLASS_5: /* power class 5, 0.8W, 29 dBm, level 7 */
386 if (new_power < 7)
387 new_power = 7;
388 break;
389 }
390 break;
391 case BAND_DCS_1800:
392 switch (alr_data->rach_data.dcs_class)
393 {
394 case POW_CLASS_1: /* power class 1, 1W, 30 dBm, level 0 */
395 if (new_power > 28)
396 new_power = 0;
397 break;
398 case POW_CLASS_2: /* power class 2, 0.25W, 24 dBm, level 3 */
399 if (!INRANGE (3, new_power, 28))
400 new_power = 3;
401 break;
402 case POW_CLASS_3: /* power class 3, 4W, 36 dBm , level 29 */
403 /* highest level allowed => no cut necessary */
404 break;
405 }
406 break;
407 case BAND_PCS_1900:
408 switch (alr_data->rach_data.dcs_class)
409 {
410 case POW_CLASS_1: /* power class 1, 1W, 30 dBm, level 0 */
411 if (!INRANGE (0, new_power, 15))
412 new_power = 0;
413 break;
414 case POW_CLASS_2: /* power class 2, 0.25W, 24 dBm, level 3 */
415 if (!INRANGE (3, new_power, 15))
416 new_power = 3;
417 break;
418 default:
419 case POW_CLASS_3: /* power class 3, 2W, 33 dBm , level 30 */
420 /* highest level allowed => no cut necessary */
421 break;
422 }
423 break;
424 }
425 return new_power;
426 }
427 #endif