comparison src/g23m-gsm/alr/alr_rach.c @ 1:fa8dc04885d8

src/g23m-*: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e78acac3d88 1:fa8dc04885d8
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 LOCAL void rach_send_mphc_ra_req (T_MPH_RANDOM_ACCESS_REQ *random_req);
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 GET_INSTANCE_DATA;
92 alr_data->state[STATE_RA] = RA_NULL;
93 }
94
95 /*
96 +--------------------------------------------------------------------+
97 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
98 | STATE : code ROUTINE : rach_configure_class |
99 +--------------------------------------------------------------------+
100
101 PURPOSE : Process signal rach_configure_class from SDL process
102 Main_Control.
103
104 */
105 GLOBAL void rach_configure_class (UBYTE ms_class,
106 UBYTE dcs_class)
107 {
108 GET_INSTANCE_DATA;
109 /*
110 * +1 because of interface difference between RR and TI
111 */
112 alr_data->rach_data.ms_class = (UBYTE)(ms_class + 1);
113 alr_data->rach_data.dcs_class = (UBYTE)(dcs_class + 1);
114
115 ALR_TRACE_RACH_CLASS (alr_data->rach_data.ms_class);
116 }
117
118 /*
119 +--------------------------------------------------------------------+
120 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
121 | STATE : code ROUTINE : rach_configure_power |
122 +--------------------------------------------------------------------+
123
124 PURPOSE : Process signal rach_configure_power from SDL process
125 Main_Control.
126
127 */
128
129 GLOBAL void rach_configure_power (UBYTE power)
130 {
131 GET_INSTANCE_DATA;
132 ALR_TRACE_RACH_POWER(power);
133
134 alr_data->rach_data.max_tx_pwr_ccch = power;
135 }
136 /*
137 +--------------------------------------------------------------------+
138 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
139 | STATE : code ROUTINE : rach_stop |
140 +--------------------------------------------------------------------+
141
142 PURPOSE : Process signal rach_stop from SDL process
143 Main_Control.
144 */
145
146 GLOBAL void rach_stop (void)
147 {
148 GET_INSTANCE_DATA;
149 switch (GET_STATE (STATE_RA))
150 {
151 case RA_ACTIVE:
152 ma_rach_stop_ra_req ();
153 /*lint -fallthrough*/
154 case RA_LISTEN_TO_CCCH:
155 SET_STATE (STATE_RA, RA_NULL);
156 break;
157
158 default:
159 break;
160 }
161 }
162
163
164 /*
165 +--------------------------------------------------------------------+
166 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
167 | STATE : code ROUTINE : rach_random_req |
168 +--------------------------------------------------------------------+
169
170 PURPOSE : Process signal rach_random_req from SDL process
171 Main_Control.
172
173 */
174
175 GLOBAL void rach_random_req (T_MPH_RANDOM_ACCESS_REQ *random_req)
176 {
177 GET_INSTANCE_DATA;
178 switch (GET_STATE (STATE_RA))
179 {
180 case RA_NULL:
181 if (random_req->send_mode.no NEQ 0)
182 {
183 rach_send_mphc_ra_req (random_req);
184 }
185 break;
186
187 case RA_ACTIVE:
188 if (random_req->send_mode.no EQ 0)
189 {
190
191 ALR_EM_STOP_CONNECTION_ESTABLISHMENT;
192
193 SET_STATE (STATE_RA, RA_LISTEN_TO_CCCH);
194 ma_rach_stop_ra_req ();
195 }
196 else
197 {
198 /*stop to be safe */
199 ma_rach_stop_ra_req ();
200 {
201 rach_send_mphc_ra_req (random_req);
202 } /*PALLOC*/
203 } /* if */
204 break;
205 default:
206 break;
207 }
208 }
209
210 /*
211 +--------------------------------------------------------------------+
212 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
213 | STATE : code ROUTINE : rach_ra_cnf |
214 +--------------------------------------------------------------------+
215
216 PURPOSE : Process signal rach_ra_cnf from SDL process
217 Main_Control.
218
219 */
220
221 GLOBAL void rach_ra_cnf (T_MPHC_RA_CON *ra_cnf)
222 {
223 GET_INSTANCE_DATA;
224 UBYTE c_burst = alr_data->rach_data.c_burst-1; /* confirmed index */
225
226 switch (GET_STATE (STATE_RA))
227 {
228 case RA_ACTIVE:
229 {
230 PALLOC (random_cnf, MPH_RANDOM_ACCESS_CNF);
231
232 ra_cnf->fn %= 42432L;
233 #ifdef GPRS
234 alr_data->rach_data.t1[c_burst] =
235 random_cnf->frame_no.t1=
236 (UBYTE)((ra_cnf->fn / 1326) % 32);
237 alr_data->rach_data.t2[c_burst] =
238 random_cnf->frame_no.t2=
239 (UBYTE)(ra_cnf->fn % 26);
240 alr_data->rach_data.t3[c_burst] =
241 random_cnf->frame_no.t3=
242 (UBYTE)(ra_cnf->fn % 51);
243 #else
244 random_cnf->frame_no.t1= (UBYTE)((ra_cnf->fn / 1326) % 32);
245 random_cnf->frame_no.t2= (UBYTE)(ra_cnf->fn % 26);
246 random_cnf->frame_no.t3= (UBYTE)(ra_cnf->fn % 51);
247 #endif
248 ma_rach_random_cnf (random_cnf);
249
250 c_burst++; /* next index */
251 if (c_burst >= alr_data->rach_data.max_bursts)
252 {/* last index ? */
253 SET_STATE (STATE_RA, RA_LISTEN_TO_CCCH);
254 ma_rach_stop_ra_req ();
255 #if !defined(TNNN_WITH_TIMER)
256 ma_fake_rr_report();
257 #endif /* !TNNN_WITH_TIMER */
258 }
259 else
260 {
261 PALLOC (ra_req, MPHC_RA_REQ);
262
263 /*
264 * power limitation
265 */
266 ra_req->txpwr = cut_power_value (alr_data->rach_data.max_tx_pwr_ccch, NULL);
267 #ifndef TI_PS_FF_QUAD_BAND_SUPPORT
268 ra_req->powerclass_gsm = alr_data->rach_data.ms_class;
269 ra_req->powerclass_dcs = alr_data->rach_data.dcs_class;
270 #endif
271
272 /*
273 * Modification: Add 1 to the time of RR !!!!
274 */
275 ra_req->rand = (UBYTE)(alr_data->rach_data.delta[c_burst]+1);
276 ra_req->channel_request = alr_data->rach_data.channel_request[c_burst];
277 ma_rach_ra_req (ra_req);
278 alr_data->rach_data.c_burst++; /* the next index */
279 }
280 break;
281 }
282 default:
283 break;
284 }
285 }
286
287
288
289 /*
290 +--------------------------------------------------------------------+
291 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
292 | STATE : code ROUTINE : cut_power_value |
293 +--------------------------------------------------------------------+
294
295 PURPOSE : Cut the nominal maximum output power to the
296 associated power class.
297 (Reference for the tables with the associated
298 power classes, control levels and nominal output power
299 is 3GPP TS 05.05, 4.1)
300
301 */
302
303 GLOBAL UBYTE cut_power_value (UBYTE power, T_MPH_DEDICATED_REQ *mph_dedicated_req)
304 {
305 GET_INSTANCE_DATA;
306 UBYTE new_power = power;
307 UBYTE sc_band;
308
309 if(mph_dedicated_req == NULL)
310 {
311 sc_band = alr_data->sc_band;
312 }
313 else
314 {
315 if(mph_dedicated_req->ch_type.h)
316 sc_band = get_band(mph_dedicated_req->ch_type.ma[0]);
317 else
318 sc_band = get_band(mph_dedicated_req->ch_type.arfcn);
319 }
320
321 switch (sc_band)
322 {
323 case BAND_GSM_900:
324 case BAND_E_GSM:
325 case BAND_GSM_850:
326 switch (alr_data->rach_data.ms_class)
327 {
328 case POW_CLASS_1: /* doesn´t exist */
329 case POW_CLASS_2: /* power class 2, 8W, 39 dBm, level 0..2 */
330 /* highest level allowed => no cut necessary */
331 break;
332 case POW_CLASS_3: /* power class 3, 5W, 37 dBm, level 3 */
333 if (new_power < 3)
334 new_power = 3;
335 break;
336 case POW_CLASS_4: /* power class 4, 2W, 33 dBm, level 5 */
337 if (new_power < 5)
338 new_power = 5;
339 break;
340 case POW_CLASS_5: /* power class 5, 0.8W, 29 dBm, level 7 */
341 if (new_power < 7)
342 new_power = 7;
343 break;
344 }
345 break;
346 case BAND_DCS_1800:
347 switch (alr_data->rach_data.dcs_class)
348 {
349 case POW_CLASS_1: /* power class 1, 1W, 30 dBm, level 0 */
350 if (new_power > 28)
351 new_power = 0;
352 break;
353 case POW_CLASS_2: /* power class 2, 0.25W, 24 dBm, level 3 */
354 if (!INRANGE (3, new_power, 28))
355 new_power = 3;
356 break;
357 case POW_CLASS_3: /* power class 3, 4W, 36 dBm , level 29 */
358 /* highest level allowed => no cut necessary */
359 break;
360 }
361 break;
362 case BAND_PCS_1900:
363 switch (alr_data->rach_data.dcs_class)
364 {
365 case POW_CLASS_1: /* power class 1, 1W, 30 dBm, level 0 */
366 if (!INRANGE (0, new_power, 15))
367 new_power = 0;
368 break;
369 case POW_CLASS_2: /* power class 2, 0.25W, 24 dBm, level 3 */
370 if (!INRANGE (3, new_power, 15))
371 new_power = 3;
372 break;
373 default:
374 case POW_CLASS_3: /* power class 3, 2W, 33 dBm , level 30 */
375 /* highest level allowed => no cut necessary */
376 break;
377 }
378 break;
379 }
380 return new_power;
381 }
382
383 /*
384 +--------------------------------------------------------------------+
385 | PROJECT : MODULE : ALR_RACH |
386 | STATE : code ROUTINE : rach_send_mphc_ra_req |
387 +--------------------------------------------------------------------+
388
389 PURPOSE : Function to send the MPHC_RA_REQ primitive.
390 Called from function 'rach_random_req'
391 This function handles:
392 1) Starts Random Burst Sending.
393 2) Power limitation.
394 3) Adds 1 to the time of RR.
395 */
396 LOCAL void rach_send_mphc_ra_req (T_MPH_RANDOM_ACCESS_REQ *random_req)
397 {
398 GET_INSTANCE_DATA;
399 PALLOC (ra_req, MPHC_RA_REQ);
400 ALR_TRACE_RACH("rach_send_mphc_ra_req");
401 ALR_EM_START_CONNECTION_ESTABLISHMENT;
402
403 /*
404 * Start Random Burst Sending
405 */
406 memcpy (alr_data->rach_data.delta, random_req->send_mode.delta,
407 sizeof (alr_data->rach_data.delta));
408 memcpy (alr_data->rach_data.channel_request, random_req->send_mode.rach,
409 sizeof (alr_data->rach_data.channel_request));
410 alr_data->rach_data.max_bursts = random_req->send_mode.no;
411 alr_data->rach_data.c_burst = 0;
412 /*
413 * power limitation
414 */
415 ra_req->txpwr = cut_power_value (alr_data->rach_data.max_tx_pwr_ccch, NULL);
416 #ifndef TI_PS_FF_QUAD_BAND_SUPPORT
417 ra_req->powerclass_gsm = alr_data->rach_data.ms_class;
418 ra_req->powerclass_dcs = alr_data->rach_data.dcs_class;
419 #endif
420
421 /*
422 * Modification: Add 1 to the time of RR !!!!
423 */
424 ra_req->rand = (UBYTE)(alr_data->rach_data.delta[alr_data->rach_data.c_burst]+1);
425 ra_req->channel_request = alr_data->rach_data.channel_request[alr_data->rach_data.c_burst++];
426 SET_STATE (STATE_RA, RA_ACTIVE);
427 ma_rach_ra_req (ra_req);
428 }
429
430 #endif