comparison gsm-fw/g23m-gsm/rr/rr_datg.c @ 673:2f7df7a314f8

gsm-fw/g23m-gsm subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 28 Sep 2014 23:20:04 +0000
parents
children
comparison
equal deleted inserted replaced
672:0dc6f9e8e980 673:2f7df7a314f8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul :
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 module holds the functions for handling primitives
18 | sent from entity GRR to entity RR and vice versa.
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef RR_DATG_C
23 #define RR_DATG_C
24
25 #ifdef GPRS
26
27 #define ENTITY_RR
28
29 /*==== INCLUDES ===================================================*/
30
31 #include <string.h>
32 #include <stddef.h>
33 #include "typedefs.h"
34 #include "pcm.h"
35 #include "pconst.cdg"
36 #include "mconst.cdg"
37 #include "message.h"
38 #include "ccdapi.h"
39 #include "vsi.h"
40 #include "custom.h"
41 #include "gsm.h"
42 #include "prim.h"
43 #include "pei.h"
44 #include "tok.h"
45 #include "rr_gprs.h"
46 #include "rr.h"
47
48 static UBYTE get_r_bit (void);
49 static void handle_non_gprs_param(T_non_gprs* non_gprs);
50 static void dat_rrgrr_rr_est_ind (void);
51 static void dat_build_rr_initialisation_request (void);
52
53 /*
54 +-----------------------------------------------------------------------------+
55 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
56 | STATE : code ROUTINE : dat_rrgrr_channel_req |
57 +-----------------------------------------------------------------------------+
58
59 PURPOSE : Process the primitive RRGRR_CHANNEL_REQ received from GRR.
60 This primitive indicates to the RR to send a channel request
61
62 */
63
64 void dat_rrgrr_channel_req (T_RRGRR_CHANNEL_REQ *chan_req)
65 {
66 GET_INSTANCE_DATA;
67 USHORT req = (USHORT) (chan_req->req_data + 0x0400);
68 TRACE_FUNCTION ("gprs_rrgrr_channel_req()");
69
70 /*
71 * check availability of GPRS
72 */
73 switch (GET_STATE(STATE_GPRS)) /* rr_data->gprs_data.gprs_avail) */
74 {
75 case GPRS_PIM_BCCH:
76 case GPRS_PAM_BCCH:
77 case GPRS_PTM_BCCH:
78 if (GET_STATE(STATE_DAT) NEQ DAT_NULL)
79 {
80 switch (req)
81 {
82 case ESTCS_GPRS_1P:
83 case ESTCS_GPRS_SB:
84 case ESTCS_PAGING:
85 /*
86 * reset values used in the Packet Access
87 * Procedure
88 */
89 if (IS_TIMER_ACTIVE(T3126))
90 {
91 TIMERSTOP(T3126);
92 }
93 memset(rr_data->gprs_data.rr_sdu, NOT_PRESENT_8BIT,
94 sizeof(rr_data->gprs_data.rr_sdu));
95 rr_data->gprs_data.tma_in_progress = FALSE;
96 rr_data->gprs_data.fn = NOT_PRESENT_32BIT;
97 rr_data->gprs_data.req_ref_idx = NOT_PRESENT_8BIT;
98 rr_data->sc_data.first_attempt = TRUE;
99 rr_data->repeat_est = FALSE;
100 /* start procedure */
101 dat_start_immediate_assign((USHORT)(req EQ
102 ESTCS_PAGING ? ESTCS_GPRS_PAGING : req));
103 SET_STATE(STATE_GPRS, GPRS_PAM_BCCH);
104 break;
105 default:
106 TRACE_EVENT("channel request with wrong value");
107 break;
108 }
109 }
110 else
111 {
112 TRACE_EVENT ("store channel req");
113 if(! srv_store_prim((T_PRIM *)D2P(chan_req)))
114 {
115 TRACE_EVENT("prim store full");
116 PFREE(chan_req);
117 }
118 return;
119 }
120 break;
121 case GPRS_PIM_PBCCH:
122 case GPRS_PAM_PBCCH:
123 case GPRS_PTM_PBCCH:
124 TRACE_EVENT ("chan_req w/ PBCCH!");
125 break;
126 case GPRS_ACTIVATED:
127 TRACE_EVENT ("no cell selected yet, or cell supports no GPRS");
128 break;
129 case GPRS_SUSPENDED_BCCH:
130 case GPRS_SUSPENDED_PBCCH:
131 TRACE_EVENT ("GPRS is suspended!");
132 break;
133 default:
134 TRACE_EVENT ("GPRS not supported");
135 break;
136 }
137 PFREE (chan_req);
138 }
139
140 /*
141 +-----------------------------------------------------------------------------+
142 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
143 | STATE : code ROUTINE : dat_check_gprs_imm_ass |
144 +-----------------------------------------------------------------------------+
145
146 PURPOSE : checks an incoming immediate assignment message and forwards
147 it to GRR if necessary.
148
149 */
150
151 GLOBAL BOOL dat_check_gprs_imm_ass (T_MPH_UNITDATA_IND * unitdata,
152 T_D_IMM_ASSIGN * imm_assign,
153 UBYTE index)
154 {
155 GET_INSTANCE_DATA;
156 BOOL ret = FALSE;
157 int send_indication = 0;
158
159 TRACE_FUNCTION ("dat_check_gprs_imm_ass()");
160
161 if (GET_STATE(STATE_GPRS) NEQ GPRS_PAM_BCCH)
162 return FALSE; /* normal circuit switched handling */
163
164 TRACE_EVENT_P7 ("fn=%u tma=%u ri=%x d_t=%u (tmaip=%u fn=%d ri=%d)",
165 unitdata->fn, imm_assign->tma, index, imm_assign->d_t,
166 rr_data->gprs_data.tma_in_progress, rr_data->gprs_data.fn,
167 rr_data->gprs_data.req_ref_idx);
168
169 if (imm_assign->tma EQ TMA_1)
170 {
171 /* Message indicates to be the first message of two in a
172 * two-message assignment of a downlink TBF.
173 */
174 if (rr_data->gprs_data.tma_in_progress)
175 {
176 TRACE_ERROR ("more than one TMA after another!");
177 TRACE_EVENT_P4 ("ri=%x?%x(old) fn=%u?%u(old)",
178 index, rr_data->gprs_data.req_ref_idx,
179 unitdata->fn, rr_data->gprs_data.fn);
180 }
181
182 rr_data->gprs_data.tma_in_progress = TRUE;
183
184 /*
185 * store message, framenumber and burst index
186 */
187 gprs_rrgrr_store_sdu(rr_data->gprs_data.rr_sdu, &unitdata->sdu);
188 rr_data->gprs_data.fn = unitdata->fn;
189 rr_data->gprs_data.req_ref_idx = index;
190 ret = TRUE; /* further treatment by GRR */
191 }
192 else
193 {
194 if (rr_data->gprs_data.tma_in_progress)
195 { /*
196 * MS awaits the second message of two in a two-message assignment
197 * of a downlink TBF.
198 * The message must belong to the same channel request
199 * and the time difference must be less than two multiframes.
200 */
201 BOOL in_time, same_reference_index;
202 U32 delta_fn;
203
204 if (rr_data->gprs_data.fn > unitdata->fn)
205 delta_fn = unitdata->fn + HYPERFRAME - rr_data->gprs_data.fn;
206 else
207 delta_fn = unitdata->fn - rr_data->gprs_data.fn;
208
209 in_time = (delta_fn/51) < 2;
210 same_reference_index = rr_data->gprs_data.req_ref_idx EQ index;
211
212 TRACE_EVENT_P6 ("TMA:delta_fn=%u %s time, %sequal ref idx(%x?%x): %s",
213 delta_fn, in_time?"in":"out of", same_reference_index?"":"un",
214 rr_data->gprs_data.req_ref_idx, index,
215 (in_time AND same_reference_index)?"OK":"not ok");
216
217 if (in_time AND same_reference_index)
218 { /* This is the matching second message of a tma.
219 * -> Send both immediate assignments
220 */
221 send_indication = 2;
222 ret = TRUE; /* further treatment by GRR */
223 }
224 else
225 {
226 TRACE_ERROR ("MS awaits second message of a tma, this is not the right one!");
227
228 if (!in_time)
229 {
230 /*
231 * If the MS does not received the second IMMEDIATE ASSIGNMENT message
232 * in a two-message assignment within two multiframe periods following
233 * the first message, the MS shall discard the IA message received.
234 */
235 rr_data->gprs_data.tma_in_progress = FALSE;
236 rr_data->gprs_data.fn = NOT_PRESENT_32BIT;
237 rr_data->gprs_data.req_ref_idx = NOT_PRESENT_8BIT;
238 }
239
240 if(imm_assign->d_t EQ D_T_TBF)
241 {
242 /*
243 * stop timer and set RR state
244 * the handling of PDCH is done by GPRS
245 */
246 ret = TRUE; /* further treatment by GPRS */
247 }
248 else
249 {
250 /*
251 * allocation on SDCCH for GPRS
252 * normal RR establishment
253 */
254 ret = FALSE;
255 }
256 }
257 }
258 else
259 { /*
260 * MS donīt await the second message of two in a two-message assignment
261 * of a downlink TBF and the message isnīt the first message of a tma.
262 *
263 * -> Send one indication to GRR
264 */
265 send_indication = 1;
266
267 if(imm_assign->d_t EQ D_T_TBF)
268 {
269 /*
270 * stop timer and set RR state
271 * the handling of PDCH is done by GPRS
272 */
273 ret = TRUE; /* further treatment by GRR */
274 }
275 else
276 /*
277 * allocation on SDCCH for GPRS
278 * normal RR establishment
279 */
280 ret = FALSE;
281 }
282 }
283
284 if (send_indication)
285 {
286 if (send_indication EQ 2)
287 {
288 PALLOC_SDU ( rrgrr_ia_ind, RRGRR_IA_IND, MAX_L2_FRAME_SIZE * BITS_PER_BYTE); /* T_RRGRR_IA_IND */
289 /*
290 * indicate first immediate assignment
291 */
292 gprs_rrgrr_fill_from_stored_sdu(&rrgrr_ia_ind->sdu, rr_data->gprs_data.rr_sdu);
293 rrgrr_ia_ind->fn = 0; /* not valid */
294 rrgrr_ia_ind->r_bit = 0; /* not valid */
295 PSENDX (GRR, rrgrr_ia_ind);
296 }
297 {
298 PALLOC_SDU ( rrgrr_ia_ind2, RRGRR_IA_IND, MAX_L2_FRAME_SIZE * BITS_PER_BYTE); /* T_RRGRR_IA_IND */
299 /*
300 * indicate second or sole immediate assignment
301 */
302 if (unitdata->sdu.o_buf >= 8)
303 {
304 unitdata->sdu.o_buf -= 8;
305 unitdata->sdu.l_buf += 8;
306 }
307 else
308 {
309 TRACE_ERROR("dat_check_gprs_imm_ass(), not able to move offset o_buf");
310 }
311 gprs_rrgrr_fill_from_stored_sdu(&rrgrr_ia_ind2->sdu,
312 &unitdata->sdu.buf[unitdata->sdu.o_buf/8]);
313 rrgrr_ia_ind2->fn = unitdata->fn;
314 rrgrr_ia_ind2->r_bit = get_r_bit ();
315 PSENDX (GRR, rrgrr_ia_ind2);
316 }
317 }
318
319 TRACE_EVENT_P1 ("dat_check_gprs_imm_ass() returns %u", ret);
320 return ret;
321 }
322
323
324 /*
325 +-----------------------------------------------------------------------------+
326 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
327 | STATE : code ROUTINE : gprs_check_immediate_assignment_ext |
328 +-----------------------------------------------------------------------------+
329
330 PURPOSE : checks an incoming immediate assignment extended message
331 and forwards it to GRR if necessary.
332
333 */
334
335 GLOBAL void dat_check_imm_ass_ext (T_MPH_UNITDATA_IND * unitdata,
336 UBYTE index)
337 {
338 GET_INSTANCE_DATA;
339 TRACE_FUNCTION ("grps_check_immediate_assignment_ext()");
340
341 /*switch (rr_data->ms_data.establish_cause)
342 {
343 case ESTCS_GPRS_1P:
344 case ESTCS_GPRS_SB:
345 case ESTCS_GPRS_PAGING:*/
346 switch (GET_STATE(STATE_GPRS))
347 {
348 case GPRS_PAM_BCCH:
349 /*
350 * Immediate Assignment Extended received on AGCH during connection
351 * establishment
352 */
353 {
354 PALLOC_SDU (rrgrr_iaext_ind, RRGRR_IAEXT_IND, MAX_L2_FRAME_SIZE * BITS_PER_BYTE);
355 gprs_rrgrr_store_sdu(rr_data->gprs_data.rr_sdu, &unitdata->sdu);
356 gprs_rrgrr_fill_from_stored_sdu(&rrgrr_iaext_ind->sdu, rr_data->gprs_data.rr_sdu);
357
358 rrgrr_iaext_ind->ia_index = index;
359 rrgrr_iaext_ind->fn = unitdata->fn;
360 rrgrr_iaext_ind->r_bit = get_r_bit();
361
362 PSENDX (GRR, rrgrr_iaext_ind);
363 }
364 break;
365 default:
366 break;
367 }
368 }
369
370 /*
371 +-----------------------------------------------------------------------------+
372 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
373 | STATE : code ROUTINE : att_check_imm_ass_rej |
374 +-----------------------------------------------------------------------------+
375
376 PURPOSE : checks an incoming immediate assignment reject message and forwards
377 it to GRR if necessary.
378
379 */
380
381 GLOBAL UBYTE dat_check_imm_ass_rej (UBYTE wait_ind)
382 {
383 GET_INSTANCE_DATA;
384 UBYTE ret = FALSE;
385
386 TRACE_FUNCTION ("att_check_imm_ass_rej()");
387
388 /*
389 switch (rr_data->ms_data.establish_cause)
390 {
391 case ESTCS_GPRS_1P:
392 case ESTCS_GPRS_SB:
393 case ESTCS_GPRS_PAGING:
394 */
395 switch (GET_STATE(STATE_GPRS))
396 {
397 case GPRS_PAM_BCCH:
398 /*
399 * Immediate Assignment Reject received on AGCH during connection
400 * establishment
401 */
402 {
403 PALLOC( rrgrr_assignment_rej_ind, RRGRR_ASSIGNMENT_REJ_IND);
404
405 rrgrr_assignment_rej_ind->wait_ind = wait_ind;
406 rrgrr_assignment_rej_ind->r_bit = get_r_bit ();
407
408 PSENDX (GRR, rrgrr_assignment_rej_ind);
409 }
410 ret = TRUE;
411 break;
412 /* return TRUE; */
413 default:
414 break;
415 }
416 return ret;
417 /* return FALSE; */
418 }
419
420 /*
421 +-----------------------------------------------------------------------------+
422 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
423 | STATE : code ROUTINE : dat_check_imm_assign_pch |
424 +-----------------------------------------------------------------------------+
425
426 PURPOSE : checks an incoming immediate assignment message in idle mode on
427 PCH
428
429 */
430
431 GLOBAL UBYTE dat_check_imm_assign_pch (T_MPH_UNITDATA_IND * unitdata,
432 T_D_IMM_ASSIGN * imm_assign)
433 {
434 GET_INSTANCE_DATA;
435 TRACE_FUNCTION ("dat_check_imm_assign_pch()");
436 TRACE_EVENT("check dl ass");
437 if(imm_assign->d_t EQ D_T_TBF AND
438 imm_assign->dl EQ DL_1)
439 {
440 PALLOC_SDU ( rrgrr_ia_ind, RRGRR_IA_DOWNLINK_IND, MAX_L2_FRAME_SIZE * BITS_PER_BYTE);
441 switch(GET_STATE(STATE_GPRS))
442 {
443 case GPRS_NULL:
444 case GPRS_ACTIVATED:
445 /*
446 * here it would be possible to store it if we are in
447 * cell reselection
448 * but i think this does not make sense:
449 * -> this is not page (ia_dl is only cell wide),
450 * -> we dont know if its actually for us.
451 * -> first we have to do a Cell Update.
452 */
453 case GPRS_SUSPENDED_BCCH:
454 case GPRS_SUSPENDED_PBCCH:
455 TRACE_EVENT_P1("dl ass in state %d", GET_STATE(STATE_GPRS) );
456 PFREE(rrgrr_ia_ind);
457 return TRUE;
458 case GPRS_PIM_BCCH:
459 case GPRS_PAM_BCCH:
460 /*
461 * Immediate Assignment received in idle mode and it is a PDCH
462 */
463 TRACE_EVENT("dl ass");
464 rr_data->start_cell_reselection = FALSE;
465 TRACE_EVENT_P1("start_cell_reselection %d", rr_data->start_cell_reselection);
466 gprs_rrgrr_store_sdu(rr_data->gprs_data.rr_sdu, &unitdata->sdu);
467 gprs_rrgrr_fill_from_stored_sdu(&rrgrr_ia_ind->sdu, rr_data->gprs_data.rr_sdu);
468 rrgrr_ia_ind->fn = unitdata->fn;
469 rrgrr_ia_ind->r_bit = NOT_PRESENT_8BIT;
470
471 PSENDX (GRR, rrgrr_ia_ind);
472 return TRUE;
473 default:
474 PFREE(rrgrr_ia_ind);
475 return FALSE;
476 }
477 }
478 return FALSE;
479 }
480
481
482
483 /*
484 +-----------------------------------------------------------------------------+
485 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
486 | STATE : code ROUTINE : dat_check_packet_paging_ind |
487 +-----------------------------------------------------------------------------+
488
489 PURPOSE : checks an incoming paging whether it is for GPRS.
490
491 */
492
493 UBYTE dat_check_packet_paging_ind (T_MPH_PAGING_IND * pag_ind)
494 {
495 GET_INSTANCE_DATA;
496 UBYTE ret=2;
497 TRACE_FUNCTION ("dat_check_packet_paging_ind ()");
498
499 if (pag_ind->channel_needed EQ CN_PACKET)
500 {
501 switch(GET_STATE(STATE_GPRS))
502 {
503 case GPRS_PIM_BCCH:
504 {
505 /*
506 * Inform GRR about packet paging
507 */
508 PALLOC ( rrgrr_packet_paging_ind, RRGRR_PACKET_PAGING_IND );
509 switch (pag_ind->identity_type)
510 {
511 case ID_IMSI:
512 rrgrr_packet_paging_ind->pg_type = RRGRR_IMSI;
513 break;
514 case ID_PTMSI:
515 rrgrr_packet_paging_ind->pg_type = RRGRR_PTMSI;
516 break;
517 default:
518 TRACE_EVENT("packet paging with TMSI");
519 break;
520 }
521 PSENDX (GRR, rrgrr_packet_paging_ind);
522 }
523 ret = 2;
524 break;
525 case GPRS_NULL:
526 case GPRS_ACTIVATED:
527 /*strange cases, ignore it */
528 break;
529 case GPRS_SUSPENDED_BCCH:
530 case GPRS_SUSPENDED_PBCCH:
531 /*is is a packet paging but we are suspended so ignore it*/
532 ret = 2;
533 break;
534 default:
535 break;
536 }
537 }
538 else
539 {
540 /* normal CS paging */
541 switch(GET_STATE(STATE_GPRS))
542 {
543 case GPRS_SUSPENDED_BCCH:
544 case GPRS_SUSPENDED_PBCCH:
545 case GPRS_NULL:
546 case GPRS_ACTIVATED:
547 /* we are already suspended so just react to the paging */
548 /* or GPRS is not activated */
549 ret = 0;
550 break;
551 default:
552 /* ask GRR */
553 ret = 1;
554 break;
555 }
556 }
557 return ret;
558 }
559
560
561 /*
562 +-----------------------------------------------------------------------------+
563 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
564 | STATE : code ROUTINE : gprs_start_sabm |
565 +-----------------------------------------------------------------------------+
566
567 PURPOSE : starts connection establishment if a packet service is requested.
568
569 */
570
571 BOOL dat_gprs_start_sabm(void)
572 {
573 GET_INSTANCE_DATA;
574 TRACE_FUNCTION ("gprs_start_sabm()");
575
576 switch (GET_STATE(STATE_GPRS))
577 {
578 /*
579 * Mobile originated packet connection
580 */
581 case GPRS_PAM_BCCH:
582 dat_build_rr_initialisation_request ();
583 return TRUE;
584 default:
585 return FALSE;
586 }
587 }
588
589
590 /*
591 +-----------------------------------------------------------------------------+
592 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
593 | STATE : code ROUTINE : gprs_build_rr_initialisation_request|
594 +-----------------------------------------------------------------------------+
595
596 PURPOSE : starts connection establishment if a mobile originated packet
597 service is requested and it builds
598
599 */
600
601 static void dat_build_rr_initialisation_request (void)
602 {
603 GET_INSTANCE_DATA;
604 MCAST (rr_init_req, D_RR_INIT_REQ);
605 PALLOC_MSG (establish_req, DL_ESTABLISH_REQ, D_RR_INIT_REQ);
606
607 TRACE_FUNCTION ("grps_build_rr_initialisation_request()");
608 TRACE_EVENT ("POWER CLASS: grps_build_rr_initialisation_request()");
609
610 dat_code_prr_channel (&establish_req->ch_type,
611 &establish_req->sapi,
612 rr_data->sc_data.chan_desc.chan_type);
613
614 /*
615 * fill message parameter
616 */
617 rr_init_req->msg_type = D_RR_INIT_REQ;
618 rr_init_req->ciph_key_num.key_seq = rr_data->ms_data.cksn;
619 memcpy(&rr_init_req->mob_class_2, &rr_data->ms_data.classmark2,
620 sizeof(rr_init_req->mob_class_2));
621
622 /*
623 * set power classes
624 */
625 rr_init_req->mob_class_2.rf_pow_cap = att_get_power ();
626
627 /*
628 * set all other parameter
629 */
630 rr_init_req->chan_coding.mac_mode = rr_data->gprs_data.mac_req;
631 rr_init_req->chan_coding.cod_scheme = rr_data->gprs_data.cs_req;
632
633 /*
634 * store tlli independent from the used binary format
635 */
636 rr_init_req->ded_tlli.l_ded_tlli = 32;
637 rr_init_req->ded_tlli.o_ded_tlli = 0;
638 ccd_codeByte (rr_init_req->ded_tlli.b_ded_tlli, 0, 8, (UBYTE)(rr_data->gprs_data.tlli >> 24));
639 ccd_codeByte (rr_init_req->ded_tlli.b_ded_tlli, 8, 8, (UBYTE)(rr_data->gprs_data.tlli >> 16));
640 ccd_codeByte (rr_init_req->ded_tlli.b_ded_tlli, 16, 8, (UBYTE)(rr_data->gprs_data.tlli >> 8));
641 ccd_codeByte (rr_init_req->ded_tlli.b_ded_tlli, 24, 8, (UBYTE)rr_data->gprs_data.tlli);
642
643 rr_init_req->chan_req_desc.or_ty = rr_data->gprs_data.p_chan_req_des.mo_mt;
644
645 if (rr_init_req->chan_req_desc.or_ty)
646 {
647 rr_init_req->chan_req_desc.v_crd_prio = 1;
648 rr_init_req->chan_req_desc.crd_prio = rr_data->gprs_data.p_chan_req_des.prio;
649 rr_init_req->chan_req_desc.v_rlc_mode = 1;
650 rr_init_req->chan_req_desc.rlc_mode = rr_data->gprs_data.p_chan_req_des.rlc_mode_req;
651 rr_init_req->chan_req_desc.v_llc_fr_type = 1;
652 rr_init_req->chan_req_desc.llc_fr_type = rr_data->gprs_data.p_chan_req_des.llc_type;
653 rr_init_req->chan_req_desc.v_rbw = 1;
654 rr_init_req->chan_req_desc.rbw = rr_data->gprs_data.p_chan_req_des.req_bwd;
655 rr_init_req->chan_req_desc.v_rlc_c_oct = 1;
656 rr_init_req->chan_req_desc.rlc_c_oct = rr_data->gprs_data.p_chan_req_des.rlc_octets;
657 }
658
659 rr_init_req->gprs_meas_res.c_val = rr_data->gprs_data.gprs_meas_results.c_value;
660 rr_init_req->gprs_meas_res.rxqual = rr_data->gprs_data.gprs_meas_results.rxqual;
661 rr_init_req->gprs_meas_res.sign_var = rr_data->gprs_data.gprs_meas_results.sign_var;
662
663 for_dat_est_req_content (establish_req);
664 }
665
666
667 /*
668 +-----------------------------------------------------------------------------+
669 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
670 | STATE : code ROUTINE : gprs_stop_dcch_ind |
671 +-----------------------------------------------------------------------------+
672
673 PURPOSE : inform GRR about failed layer 2 establishment.
674
675 */
676 void dat_stop_dcch_ind (UBYTE stop_cause)
677 {
678 GET_INSTANCE_DATA;
679 PALLOC(stop, RRGRR_STOP_DCCH_IND);
680 TRACE_FUNCTION ("gprs_stop_dcch_ind()");
681 stop->stop_cause = stop_cause;
682 /* we will do a CR anyway */
683 SET_STATE(STATE_GPRS, GPRS_ACTIVATED);
684 PSENDX(GRR, stop);
685 }
686
687
688
689 /*
690 +-----------------------------------------------------------------------------+
691 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
692 | STATE : code ROUTINE : gprs_rrgrr_gprs_data_req |
693 +-----------------------------------------------------------------------------+
694
695 PURPOSE : The primitive RRGRR_GPRS_DATA_REQ contains various parameters from
696 GRR. Layer 1 is configured and some data are stored.
697 */
698
699 void dat_rrgrr_gprs_data_req (T_RRGRR_GPRS_DATA_REQ *data_req)
700 {
701 GET_INSTANCE_DATA;
702 /*
703 * store parameter
704 */
705
706 rr_data->gprs_data.tlli = data_req->tlli;
707 rr_data->gprs_data.p_chan_req_des = data_req->p_chan_req_des;
708 rr_data->gprs_data.gprs_meas_results = data_req->gprs_meas_results;
709 rr_data->gprs_data.mac_req = data_req->mac_req;
710 rr_data->gprs_data.cs_req = data_req->cs_req;
711 rr_data->gprs_data.current_rai = data_req->rai;
712
713 if(rr_data->gprs_data.ptmsi NEQ data_req->old_ptmsi OR
714 rr_data->gprs_data.ptmsi2 NEQ data_req->new_ptmsi)
715 {
716 rr_data->gprs_data.ptmsi = data_req->old_ptmsi;
717 rr_data->gprs_data.ptmsi2 = data_req->new_ptmsi;
718 att_mph_identity_req ();
719 }
720
721 PFREE (data_req);
722 }
723
724
725 /*
726 +-----------------------------------------------------------------------------+
727 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
728 | STATE : code ROUTINE : dat_rrgrr_data_ind |
729 +-----------------------------------------------------------------------------+
730
731 PURPOSE : Send the primitive rrgrr_data_ind to GRR.
732 This primitive indicates to the GRR that a
733 CTRL Message on DCCH for RR was received.
734 IN : frame_number
735 OUT : rrgrr_data_ind
736
737 */
738
739 void dat_rrgrr_data_ind (T_DL_DATA_IND* dl_data_ind)
740 {
741 USHORT soff,doff;
742 PALLOC_SDU ( rrgrr_data_ind, RRGRR_DATA_IND, dl_data_ind->sdu.l_buf );
743
744 TRACE_EVENT ("dat_rrgrr_data_ind ()");
745
746 /*
747 * compute byte offsets (soff,doff) into message streams,
748 * assume that o_buf is multiple of 8
749 */
750
751 doff = (USHORT)(rrgrr_data_ind->sdu.o_buf / BITS_PER_BYTE);
752 soff = (USHORT)( dl_data_ind->sdu.o_buf / BITS_PER_BYTE);
753
754 memcpy ( &rrgrr_data_ind->sdu.buf[doff],
755 & dl_data_ind->sdu.buf[soff], BYTELEN ( dl_data_ind->sdu.l_buf ) );
756
757 rrgrr_data_ind->fn = NOT_PRESENT_32BIT;
758
759 PFREE ( dl_data_ind );
760 PSENDX (GRR, rrgrr_data_ind);
761 }
762
763 /*
764 +-----------------------------------------------------------------------------+
765 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
766 | STATE : code ROUTINE : gprs_rrgrr_data_req |
767 +-----------------------------------------------------------------------------+
768
769 PURPOSE : Process the primitive RRGRR_DATA_REQ received from GRR.
770 This primitive indicates to the RR to send a block on DCCH.
771 IN :
772 OUT :
773
774 */
775
776 void dat_rrgrr_data_req (T_RRGRR_DATA_REQ *rrgrr_data_req)
777 {
778 GET_INSTANCE_DATA;
779 TRACE_EVENT ("dat_rrgrr_data_req ()");
780
781 switch(GET_STATE(STATE_GPRS))
782 {
783 case GPRS_DEDI_SDCCH:
784 {
785 PPASS (rrgrr_data_req, dl_data_req, DL_DATA_REQ);
786
787 dat_code_prr_channel (&dl_data_req->ch_type,
788 &dl_data_req->sapi,
789 rr_data->sc_data.chan_desc.chan_type);
790 dat_vsd_bit_set ((T_L3_SDU *)&dl_data_req->sdu, SET_ONLY);
791 for_dat_l3_data_req (dl_data_req);
792 }
793 break;
794 default:
795 break;
796 }
797
798 PFREE (rrgrr_data_req);
799 }
800
801 /*
802 +-----------------------------------------------------------------------------+
803 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
804 | STATE : code ROUTINE : dat_rgrr_suspend_dcch_req |
805 +-----------------------------------------------------------------------------+
806
807 PURPOSE : Process the primitive RRGRR_SUSPEND_DCCH_REQ received from GRR.
808 This primitive is used by GRR to order RR to stop the
809 dedicated channel. It is only a trigger.
810 IN : RRGRR-SUSPEND-DCCH-REQ
811 OUT : DL-SUSPEND-REQ and MPH-DEDICATED-REQ
812
813 */
814 void dat_rrgrr_suspend_dcch_req( T_RRGRR_SUSPEND_DCCH_REQ *suspend_dcch_req)
815 {
816 GET_INSTANCE_DATA;
817 PALLOC (dedicated_req, MPH_DEDICATED_REQ);
818
819 TRACE_EVENT ("dat_rrgrr_suspend_dcch_req ()");
820
821 for_suspend_layer_2();
822
823 memset (dedicated_req, 0, sizeof (T_MPH_DEDICATED_REQ));
824 dedicated_req->mod = MODE_PDCH_ASSIGN;
825 PSENDX (PL, dedicated_req);
826
827 SET_STATE (STATE_DAT, DAT_PDCH_ASS);
828
829 PFREE (suspend_dcch_req);
830 }
831
832 /*
833 +-----------------------------------------------------------------------------+
834 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
835 | STATE : code ROUTINE : dat_rrgrr_suspend_dcch_cnf |
836 +-----------------------------------------------------------------------------+
837
838 PURPOSE : Create the primitive RRGRR_SUSPEND_DCCH_CNF and send it to GRR.
839 As a response GRR will start the establishment of a TBF.
840 IN : nothing
841 OUT : RRGRR_SUSPEND_DCCH_CNF
842
843 */
844 void dat_rrgrr_suspend_dcch_cnf( void )
845 {
846 PALLOC (suspend_dcch_cnf, RRGRR_SUSPEND_DCCH_CNF);
847 PSENDX (GRR, suspend_dcch_cnf);
848 }
849
850
851 /*
852 +-----------------------------------------------------------------------------+
853 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
854 | STATE : code ROUTINE : dat_rrgrr_reconnect_dcch_req |
855 +-----------------------------------------------------------------------------+
856
857 PURPOSE : Process the primitive RRGRR-RECONNECT-DCCH-REQ received from GRR.
858 This primitive is used by GRR during a PDCH Assignment procedure
859 and RR Network Controlled Cell Change Order to order RR to
860 continue with the dedicated channel.
861 IN : T-RRGRR-RECONNECT-DCCH-REQ
862 OUT : DL-DATA-REQ(u-assign-fail) or MPH_DEDICATED_FAIL_REQ
863
864 */
865 void dat_rrgrr_reconnect_dcch_req (T_RRGRR_RECONNECT_DCCH_REQ *reconnect_dcch_req)
866 {
867 GET_INSTANCE_DATA;
868 TRACE_EVENT ("dat_rrgrr_reconnect_dcch_req()");
869
870 if ( rr_data->gprs_data.tbf_est EQ TBF_EST_PDCH OR
871 rr_data->gprs_data.tbf_est EQ TBF_EST_CCO )
872 {
873 UBYTE next_state;
874
875 if ( rr_data->gprs_data.tbf_est EQ TBF_EST_PDCH )
876 next_state = DAT_PDCH_ASS_3;
877 else
878 next_state = DAT_CCO_3;
879
880 /*
881 * The dedicated channel has been suspended at PL and DL.
882 * However RR could not established the TBF.
883 */
884
885 rr_data->gprs_data.tbf_est = TBF_EST_NONE;
886 dat_code_mph_old_chan_req();
887 rr_data->gprs_data.reconn_cause = reconnect_dcch_req->reconn_cause;
888 rr_data->gprs_data.cco_need_reconnect_cnf = TRUE;
889 SET_STATE (STATE_DAT, next_state);
890 }
891 else /* Any other state assuming D_PDCH_ASS_CMD has been sent to GRR.
892 GRR cannot evaluate the message. */
893 {
894 MCAST (u_assign_fail, U_ASSIGN_FAIL);
895 PALLOC_MSG (dl_data_req, DL_DATA_REQ, U_ASSIGN_FAIL);
896
897 /*
898 * set channel type and SAPI
899 */
900 dat_code_prr_channel (&dl_data_req->ch_type,
901 &dl_data_req->sapi,
902 rr_data->sc_data.chan_desc.chan_type);
903
904 u_assign_fail->msg_type = U_ASSIGN_FAIL;
905 u_assign_fail->rr_cause = reconnect_dcch_req->reconn_cause;
906 for_dat_data_req (dl_data_req);
907
908 dat_rrgrr_reconnect_dcch_cnf (RECONN_OK);
909 }
910 PFREE (reconnect_dcch_req);
911 }
912
913 /*
914 +-----------------------------------------------------------------------------+
915 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
916 | STATE : code ROUTINE : dat_rrgrr_reconnect_dcch_cnf |
917 +-----------------------------------------------------------------------------+
918
919 PURPOSE : Create the primitive RRGRR_RECONNECT_DCCH_CNF and send it to GRR.
920 This indicates the outcome of the Reconnection procedure to GRR.
921 IN : nothing
922 OUT : RRGRR-RECONNECT-DCCH-CNF
923
924 */
925 void dat_rrgrr_reconnect_dcch_cnf( UBYTE reconn_state )
926 {
927 PALLOC (reconnect_dcch_cnf, RRGRR_RECONNECT_DCCH_CNF);
928 TRACE_EVENT ("dat_rrgrr_reconnect_dcch_cnf()");
929 reconnect_dcch_cnf->reconn_state = reconn_state;
930 PSENDX (GRR, reconnect_dcch_cnf);
931 }
932
933 /*
934 +-----------------------------------------------------------------------------+
935 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
936 | STATE : code ROUTINE : dat_rgrr_resumed_tbf_req |
937 +-----------------------------------------------------------------------------+
938
939 PURPOSE : Process the primitive RRGRR-RESUMED-TBF-REQ received from GRR.
940 This primitive is used by GRR to order RR to indicate the
941 successful outcome of a TBF establishment at GRR.
942 This is applicable during PDCH Assignment and RR Network Contolled
943 Cell Change Order.
944 IN : RRGRR-RESUMED-TBF-REQ
945 OUT : MPH-IDLE-REQ and DL-RELEASE-REQ
946
947 */
948 void dat_rrgrr_resumed_tbf_req( T_RRGRR_RESUMED_TBF_REQ *resumed_tbf_req )
949 {
950 GET_INSTANCE_DATA;
951 TRACE_EVENT ("dat_rrgrr_resumed_tbf_req ()");
952
953 if ( rr_data->gprs_data.tbf_est EQ TBF_EST_PDCH OR
954 rr_data->gprs_data.tbf_est EQ TBF_EST_CCO )
955 {
956 PALLOC (dl_release_req, DL_RELEASE_REQ);
957
958 rr_data->gprs_data.tbf_est = TBF_EST_NONE;
959
960 att_build_idle_req(SC_INDEX, MODE_PACKET_TRANSFER);
961
962 /*
963 * Note that also during a Cell Change Order the states DAT_PDCH* are used.
964 */
965
966 SET_STATE (STATE_GPRS, GPRS_PTM_BCCH);
967 SET_STATE (STATE_DAT, DAT_PDCH_ASS_2);
968
969 dat_code_prr_channel (&dl_release_req->ch_type,
970 &dl_release_req->sapi,
971 rr_data->sc_data.chan_desc.chan_type);
972
973 dl_release_req->mode = DL_NORMAL_RELEASE;
974 PSENDX (DL, dl_release_req);
975 }
976 PFREE (resumed_tbf_req);
977 }
978
979 /*
980 +-----------------------------------------------------------------------------+
981 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
982 | STATE : code ROUTINE : dat_rrgrr_resumed_tbf_cnf |
983 +-----------------------------------------------------------------------------+
984
985 PURPOSE : Create a primitive RGRR_RESUMED_TBF_CNF and send it to GRR.
986 This indicates the successful outcome of the release of the DCCH
987 which was in use before the TBF was established.
988 IN : nothing
989 OUT : RGRR-RESUMED-TBF-CNF
990
991 */
992 void dat_rrgrr_resumed_tbf_cnf( void )
993 {
994 GET_INSTANCE_DATA;
995 PALLOC (rrgrr_resumed_tbf_cnf, RRGRR_RESUMED_TBF_CNF);
996
997 TRACE_EVENT ("dat_rrgrr_resumed_tbf_cnf ()");
998
999 SET_STATE(STATE_GPRS, GPRS_PTM_BCCH);
1000 SET_STATE(STATE_DAT, DAT_IDLE);
1001 SET_STATE(STATE_ATT, ATT_IDLE);
1002
1003 PSENDX (GRR, rrgrr_resumed_tbf_cnf);
1004 }
1005
1006 /*
1007 +-----------------------------------------------------------------------------+
1008 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1009 | STATE : code ROUTINE : dat_rrgrr_change_order |
1010 +-----------------------------------------------------------------------------+
1011
1012 PURPOSE : Handle the message RR Network Controlled Cell Change Order.
1013 IN : DL-DATA-IND
1014 OUT : RRGRR-DATA-IND
1015
1016 */
1017 void dat_rrgrr_change_order (T_DL_DATA_IND *dl_data_ind, T_D_CHANGE_ORDER *d_change_order)
1018 {
1019 GET_INSTANCE_DATA;
1020 for_check_cell_descr (&d_change_order->cell_desc); /* check if the BCCH is ok */
1021
1022 if ( rr_data->ms_data.error.cs EQ 0 ) /* '0' indicates successful message decoding */
1023 {
1024 T_cell_desc *cell_desc;
1025
1026 for_suspend_layer_2();
1027
1028 if ( rr_data->gprs_data.dl_data_ind NEQ NULL )
1029 {
1030 PFREE ( rr_data->gprs_data.dl_data_ind );
1031 }
1032 rr_data->gprs_data.dl_data_ind = dl_data_ind;
1033
1034 dat_att_null();
1035 cs_set_all();
1036
1037 cell_desc = &d_change_order->cell_desc;
1038 rr_data->gprs_data.bsic = (UBYTE)(( cell_desc->ncc << 3 ) + cell_desc->bcc);
1039 rr_data->gprs_data.arfcn = (USHORT)(( cell_desc->bcch_arfcn_hi << 8 ) +
1040 cell_desc->bcch_arfcn_lo);
1041 TIMERSTOP(T_DEDICATED_MODE);
1042 rr_data->mode_after_dedi = MODE_CELL_CHANGE_ORDER;
1043 att_stop_dedicated();
1044 }
1045 else
1046 {
1047 MCAST (handov_fail, U_HANDOV_FAIL);
1048 PALLOC_MSG (dl_data_req, DL_DATA_REQ, U_HANDOV_FAIL);
1049
1050 handov_fail->msg_type = U_HANDOV_FAIL;
1051 handov_fail->rr_cause = RRC_PROT_UNSPECIFIED;
1052 dat_code_prr_channel (&dl_data_req->ch_type,
1053 &dl_data_req->sapi,
1054 rr_data->sc_data.chan_desc.chan_type);
1055 for_dat_data_req (dl_data_req);
1056 PFREE ( dl_data_ind );
1057 }
1058 }
1059
1060
1061 /*
1062 +-----------------------------------------------------------------------------+
1063 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1064 | STATE : code ROUTINE : dat_check_packet_access |
1065 +-----------------------------------------------------------------------------+
1066
1067 PURPOSE : change state from conn. establishment to dedicated
1068 IN :
1069 OUT :
1070
1071 */
1072
1073 BOOL dat_check_packet_access(void)
1074 {
1075 GET_INSTANCE_DATA;
1076 if(GET_STATE(STATE_GPRS) EQ GPRS_PAM_BCCH)
1077 {
1078 SET_STATE(STATE_GPRS, GPRS_DEDI_SDCCH);
1079 return TRUE;
1080 }
1081 else return FALSE;
1082 }
1083
1084 /*
1085 +-----------------------------------------------------------------------------+
1086 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1087 | STATE : code ROUTINE : dat_ask_paging_ind |
1088 +-----------------------------------------------------------------------------+
1089
1090 PURPOSE : Ask GRR if paging should be processed. Answer will come in
1091 RRGRR_RR_EST_RSP primitive
1092
1093 */
1094
1095 void dat_ask_paging_ind (T_MPH_PAGING_IND *pag_ind)
1096 {
1097 GET_INSTANCE_DATA;
1098 TRACE_FUNCTION ("dat_ask_paging_ind ()");
1099
1100 rr_data->gprs_data.pag_dat.id_type = pag_ind->identity_type;
1101 rr_data->gprs_data.pag_dat.chan_need = pag_ind->channel_needed;
1102
1103 rr_data->start_cell_reselection = FALSE;
1104 TRACE_EVENT_P1("start_cell_reselection %d", rr_data->start_cell_reselection);
1105 /* ask GRR if paging should be processed */
1106 dat_rrgrr_rr_est_ind ();
1107 }
1108
1109 /*
1110 +-----------------------------------------------------------------------------+
1111 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1112 | STATE : code ROUTINE : dat_ask_paging_ind_pa_only |
1113 +-----------------------------------------------------------------------------+
1114
1115 PURPOSE : Ask GRR if paging should be processed. Answer will come in
1116 RRGRR_RR_EST_RSP primitive. Only applicable in state GPRS_PA.
1117
1118 */
1119
1120 void dat_ask_paging_ind_pa_only (T_MPH_PAGING_IND *pag_ind)
1121 {
1122 GET_INSTANCE_DATA;
1123 if ( GET_STATE(STATE_GPRS) EQ GPRS_PAM_BCCH AND pag_ind->channel_needed NEQ CN_PACKET )
1124 dat_ask_paging_ind ( pag_ind );
1125 }
1126
1127 /*
1128 +-----------------------------------------------------------------------------+
1129 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1130 | STATE : code ROUTINE : dat_rrgrr_rr_est_ind |
1131 +-----------------------------------------------------------------------------+
1132
1133 PURPOSE : Send the primitive rrgrr_est_ind to GRR.
1134 This primitive indicates to the GRR that an RR connection
1135 establishment was received from the network via paging.
1136 It is only a trigger.
1137 IN :
1138 OUT : rrgrr_rr_est_ind
1139
1140 */
1141
1142 static void dat_rrgrr_rr_est_ind (void)
1143 {
1144 PALLOC ( rrgrr_est_ind, RRGRR_RR_EST_IND );
1145 TRACE_EVENT ("dat_rrgrr_est_ind ()");
1146 PSENDX (GRR, rrgrr_est_ind);
1147 }
1148
1149 /*
1150 +-----------------------------------------------------------------------------+
1151 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1152 | STATE : code ROUTINE : dat_rrgrr_rr_est_req |
1153 +-----------------------------------------------------------------------------+
1154
1155 PURPOSE : Process the primitive RRGRR_RR_EST_REQ received from GRR.
1156 This primitive indicates to the RR a RR connection establishment
1157 was received on paging channel (PCCCH or PACCH). RR has to start
1158 a RR connection as if it has received a connection establishment
1159 on CCCH.
1160 IN :
1161 OUT :
1162
1163 */
1164
1165 void dat_rrgrr_rr_est_req (T_RRGRR_RR_EST_REQ *est_req)
1166 {
1167 GET_INSTANCE_DATA;
1168 TRACE_EVENT ("dat_rrgrr_rr_est_req ()");
1169
1170 switch(GET_STATE(STATE_GPRS))
1171 {
1172 case GPRS_PTM_BCCH:
1173 case GPRS_PAM_BCCH:
1174 case GPRS_PTM_PBCCH:
1175 case GPRS_PAM_PBCCH:
1176 case GPRS_PIM_PBCCH:
1177 rr_data->gprs_data.gprs_suspend = est_req->susp_req;
1178 rr_data->gprs_data.gprs_resump = GPRS_RESUMPTION_ACK;
1179
1180 if(est_req->non_gprs.v_non_gprs)
1181 {
1182 handle_non_gprs_param(&est_req->non_gprs);
1183 }
1184
1185 switch(GET_STATE(STATE_GPRS))
1186 {
1187 case GPRS_PIM_BCCH:
1188 case GPRS_PAM_BCCH:
1189 case GPRS_PTM_BCCH:
1190 SET_STATE(STATE_GPRS, GPRS_SUSPENDED_BCCH);
1191 break;
1192 case GPRS_PIM_PBCCH:
1193 case GPRS_PAM_PBCCH:
1194 case GPRS_PTM_PBCCH:
1195 SET_STATE(STATE_GPRS, GPRS_SUSPENDED_PBCCH);
1196 break;
1197 default:
1198 break;
1199 }
1200
1201 dat_begin_start_immediate_assign (est_req->ident_type,
1202 est_req->ch_needed);
1203 break;
1204 default:
1205 break;
1206 }
1207 PFREE (est_req);
1208 }
1209
1210 /*
1211 +-----------------------------------------------------------------------------+
1212 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1213 | STATE : code ROUTINE : handle_non_gprs_param |
1214 +-----------------------------------------------------------------------------+
1215
1216 PURPOSE : Processes RGRR_RR_EST_REQ parameters received from GRR.
1217 IN : Non GPRS parameter structure of the RRGRR_RR_EST_REQ primitive.
1218 OUT :
1219
1220 */
1221
1222 static void handle_non_gprs_param(T_non_gprs* non_gprs)
1223 {
1224 GET_INSTANCE_DATA;
1225 rr_data->nc_data[SC_INDEX].control_descr.att = non_gprs->att;
1226 rr_data->nc_data[SC_INDEX].control_descr.bs_ag_blks_res = non_gprs->bs_ag_blks_res;
1227 rr_data->nc_data[SC_INDEX].control_descr.ccch_conf = non_gprs->ccch_conf;
1228 rr_data->nc_data[SC_INDEX].control_descr.bs_pa_mfrms = non_gprs->bs_pa_mfrms;
1229 rr_data->nc_data[SC_INDEX].rach.max_retrans = non_gprs->max_retrans;
1230 rr_data->nc_data[SC_INDEX].rach.tx_integer = non_gprs->tx_integer;
1231 rr_data->nc_data[SC_INDEX].select_para.ms_txpwr_max_cch = non_gprs->gprs_ms_txpwr_max_cch;
1232 rr_data->nc_data[SC_INDEX].select_para.neci = non_gprs->neci;
1233 rr_data->sc_data.cd.cell_options.pow_ctrl = non_gprs->pwrc;
1234
1235 if(non_gprs->dtx EQ 2)
1236 rr_data->sc_data.cd.dtx = DTX_NOT_USED;
1237 else
1238 rr_data->sc_data.cd.dtx = DTX_USED;
1239
1240 rr_data->sc_data.cd.dtx_half = rr_data->sc_data.cd.dtx_full =
1241 rr_data->sc_data.cd.dtx;
1242
1243 rr_data->sc_data.cd.cell_options.rlt = non_gprs->radio_link_timeout;
1244
1245 if(non_gprs->ec)
1246 rr_data->nc_data[SC_INDEX].rach.ac &= 0x0400;
1247 if(non_gprs->v_T3212)
1248 rr_data->nc_data[SC_INDEX].control_descr.t3212 = non_gprs->T3212;
1249
1250 #ifdef REL99
1251 /*Copy Early Classmark Sending Control flag received in PSI2 by GRR*/
1252 rr_data->nc_data[SC_INDEX].c2_par.ecsc = non_gprs->ecsc;
1253 #endif
1254 }
1255 /*
1256 +-----------------------------------------------------------------------------+
1257 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1258 | STATE : code ROUTINE : dat_rrgrr_rr_est_rsp |
1259 +-----------------------------------------------------------------------------+
1260
1261 PURPOSE : Process the primitive RRGRR_RR_EST_RSP received from GRR.
1262 This primitive indicates to the RR whether an establishment of
1263 RR connection is allowed or not. This primitive is an answer
1264 to the RRGRR_RR_EST_IND primitive.
1265 IN :
1266 OUT :
1267
1268 */
1269
1270 void dat_rrgrr_rr_est_rsp (T_RRGRR_RR_EST_RSP *est_rsp)
1271 {
1272 GET_INSTANCE_DATA;
1273 TRACE_EVENT ("dat_rrgrr_rr_est_rsp ()");
1274
1275 rr_data->start_cell_reselection = TRUE;
1276 TRACE_EVENT_P1("start_cell_reselection %d", rr_data->start_cell_reselection);
1277
1278 /* establishment allowed */
1279 if (est_rsp->rr_est)
1280 {
1281 rr_data->gprs_data.gprs_suspend = est_rsp->susp_req;
1282 rr_data->gprs_data.gprs_resump = GPRS_RESUMPTION_ACK;
1283 switch(GET_STATE(STATE_GPRS))
1284 {
1285 case GPRS_PIM_BCCH:
1286 case GPRS_PAM_BCCH:
1287 case GPRS_PTM_BCCH:
1288 SET_STATE(STATE_GPRS, GPRS_SUSPENDED_BCCH);
1289 break;
1290 case GPRS_PIM_PBCCH:
1291 case GPRS_PAM_PBCCH:
1292 case GPRS_PTM_PBCCH:
1293 SET_STATE(STATE_GPRS, GPRS_SUSPENDED_PBCCH);
1294 break;
1295 default:
1296 break;
1297 }
1298 dat_begin_start_immediate_assign (rr_data->gprs_data.pag_dat.id_type,
1299 rr_data->gprs_data.pag_dat.chan_need);
1300 }
1301
1302 rr_data->gprs_data.pag_dat.id_type = 0;
1303 rr_data->gprs_data.pag_dat.chan_need = 0;
1304
1305 PFREE (est_rsp);
1306 }
1307
1308
1309 /*
1310 +-----------------------------------------------------------------------------+
1311 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1312 | STATE : code ROUTINE : dat_gprs_suspend_req |
1313 +-----------------------------------------------------------------------------+
1314
1315 PURPOSE : Builds GPRS suspension request message.
1316 IN :
1317 OUT :
1318
1319 */
1320
1321 void dat_gprs_suspend_req (void)
1322 {
1323 GET_INSTANCE_DATA;
1324 if(rr_data->gprs_data.gprs_suspend)
1325 {
1326 /*
1327 * building of the GPRS Suspension Request message
1328 */
1329 MCAST (susp_req, U_GPRS_SUSP_REQ);
1330 PALLOC_MSG (dl_data_req, DL_DATA_REQ, U_GPRS_SUSP_REQ);
1331
1332 /*
1333 * set channel type and SAPI for layer 2
1334 */
1335 dat_code_prr_channel (&dl_data_req->ch_type,
1336 &dl_data_req->sapi,
1337 rr_data->sc_data.chan_desc.chan_type);
1338 susp_req->msg_type = U_GPRS_SUSP_REQ;
1339
1340 /*
1341 * store tlli independent from the used binary format
1342 */
1343 susp_req->ded_tlli.l_ded_tlli = 32;
1344 susp_req->ded_tlli.o_ded_tlli = 0;
1345 ccd_codeByte (susp_req->ded_tlli.b_ded_tlli, 0, 8,
1346 (UBYTE)(rr_data->gprs_data.tlli >> 24));
1347 ccd_codeByte (susp_req->ded_tlli.b_ded_tlli, 8, 8,
1348 (UBYTE)(rr_data->gprs_data.tlli >> 16));
1349 ccd_codeByte (susp_req->ded_tlli.b_ded_tlli, 16, 8,
1350 (UBYTE)(rr_data->gprs_data.tlli >> 8));
1351 ccd_codeByte (susp_req->ded_tlli.b_ded_tlli, 24, 8,
1352 (UBYTE) rr_data->gprs_data.tlli);
1353
1354
1355 switch(rr_data->ms_data.establish_cause)
1356 {
1357 case ESTCS_SERV_REQ_BY_MM:
1358 susp_req->susp_cause = SUSP_C_LU;
1359 break;
1360 case ESTCS_EMRG_CAL:
1361 case ESTCS_CAL_REEST:
1362 case ESTCS_MOB_ORIG_SPCH_CAL_BY_CC:
1363 case ESTCS_MOB_ORIG_DATA_CAL_BY_CC:
1364 case ESTCS_MOB_ORIG_DATA_CAL_BY_CC_HR_SUFF:
1365 case ESTCS_PAGING:
1366 susp_req->susp_cause = SUSP_C_CALL;
1367 break;
1368 case ESTCS_MOB_ORIG_CAL_BY_SS_SMS:
1369 susp_req->susp_cause = SUSP_C_SMS; /* SUSP_C_SS */
1370 break;
1371 default:
1372 break;
1373 }
1374
1375 memcpy(susp_req->rout_area_id.mcc,rr_data->gprs_data.current_rai.plmn.mcc, SIZE_MCC);
1376 memcpy(susp_req->rout_area_id.mnc,rr_data->gprs_data.current_rai.plmn.mnc, SIZE_MNC);
1377 if (susp_req->rout_area_id.mnc[2] EQ 0x0f)
1378 susp_req->rout_area_id.c_mnc = 2;
1379 else
1380 susp_req->rout_area_id.c_mnc = SIZE_MNC;
1381
1382 susp_req->rout_area_id.rac = rr_data->gprs_data.current_rai.rac;
1383 susp_req->rout_area_id.lac = rr_data->gprs_data.current_rai.lac;
1384
1385 rr_data->gprs_data.gprs_resump = GPRS_RESUMPTION_NOT_ACK;
1386 /*
1387 * send to layer 2
1388 */
1389 for_dat_data_req (dl_data_req);
1390 }
1391
1392 }
1393
1394 /*
1395 +-----------------------------------------------------------------------------+
1396 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1397 | STATE : code ROUTINE : gprs_rrgrr_stop_task |
1398 +-----------------------------------------------------------------------------+
1399
1400 PURPOSE : Process the primitive RRGRR_STOP_TASK_REQ received from GRR.
1401 This primitive indicates to the RR that a specific task on RR side
1402 should be stopped.
1403 IN :
1404 OUT :
1405
1406 */
1407
1408 void gprs_rrgrr_stop_task( T_RRGRR_STOP_TASK_REQ *stop_task)
1409 {
1410 GET_INSTANCE_DATA;
1411 TRACE_EVENT ("gprs_rrgrr_stop_task");
1412
1413 switch(stop_task->ctrl_task)
1414 {
1415 case RR_TASK_1:
1416 {
1417 switch(GET_STATE(STATE_GPRS))
1418 {
1419 case GPRS_PAM_BCCH:
1420 rr_data->start_cell_reselection = TRUE;
1421 TRACE_EVENT_P1("start_cell_reselection %d", rr_data->start_cell_reselection);
1422 if(stop_task->task.v_stop_ccch NEQ INVALID_MSG)
1423 {
1424 att_build_idle_req(SC_INDEX, MODE_PACKET_TRANSFER);
1425 TIMERSTOP(T3126);
1426 SET_STATE(STATE_GPRS, GPRS_PTM_BCCH);
1427 SET_STATE(STATE_DAT, DAT_IDLE);
1428 SET_STATE(STATE_ATT, ATT_IDLE);
1429 {
1430 PALLOC(stop_cnf, RRGRR_STOP_TASK_CNF);
1431 PSENDX(GRR, stop_cnf);
1432 }
1433 }
1434 break;
1435 case GPRS_PIM_BCCH:
1436 if(stop_task->task.v_stop_ccch NEQ INVALID_MSG)
1437 {
1438 /*
1439 * XXX we still have a problem if the search terminates
1440 * and we want to select to the HPLMN cell just in the moment
1441 * after we have sent the IA_DOWNLINK_IND but before receiving
1442 * the STOP_TASK_REQ. But we should not stop the search
1443 * before, because maybe the IA_DOWNLINK was not actually
1444 * addressing us.
1445 */
1446
1447 if (rr_data->ms_data.req_mm_service EQ FUNC_NET_SRCH_BY_MMI)
1448 {
1449 /*inform MM and stop everything*/
1450 /*
1451 * send Please Retry to the MMI
1452 */
1453 rr_data->sc_data.found_entries = 0;
1454 att_code_rr_abort_ind (RRCS_ABORT_CEL_SEL_FAIL);
1455 }
1456 att_build_idle_req(SC_INDEX, MODE_PACKET_TRANSFER);
1457 SET_STATE(STATE_GPRS, GPRS_PTM_BCCH);
1458 SET_STATE(STATE_DAT, DAT_IDLE);
1459 SET_STATE(STATE_ATT, ATT_IDLE);
1460 {
1461 PALLOC(stop_cnf, RRGRR_STOP_TASK_CNF);
1462 PSENDX(GRR, stop_cnf);
1463 }
1464 }
1465 /*
1466 * If a search is active in idle this is set to false
1467 * it is also set to false on sending the IA_DL to GRR
1468 * If the IA_DL is for us we abort the search and enter TBF
1469 * that means that the start_cr flag is always set to true
1470 * If the IA_DL is not for us then the start_cr flag should only be
1471 * reset if no search is ongoing.
1472 */
1473 if (rr_data->ms_data.req_mm_service NEQ FUNC_NET_SRCH_BY_MMI)
1474 {
1475 rr_data->start_cell_reselection = TRUE;
1476 TRACE_EVENT_P1("start_cell_reselection %d", rr_data->start_cell_reselection);
1477 }
1478 break;
1479 default:
1480 break;
1481 }
1482 }
1483 break;
1484 case LEAVE_PIM_PBCCH:
1485 {
1486 TRACE_EVENT("LEAVE PIM");
1487 /* stop CCCH reading if running */
1488 /* SET_STATE(STATE_DAT, DAT_NULL); avoid reacting to crossing prim */
1489 /* stop CBCH reading if running */
1490 /* stop active ncell procedures */
1491 if (rr_data->ms_data.req_mm_service EQ FUNC_NET_SRCH_BY_MMI)
1492 {
1493 /*inform MM and stop everything*/
1494 /*
1495 * send Please Retry to the MMI
1496 */
1497 rr_data->sc_data.found_entries = 0;
1498 att_code_rr_abort_ind (RRCS_ABORT_CEL_SEL_FAIL);
1499 }
1500 {
1501 PALLOC(mph_mon_ctrl_req, MPH_MON_CTRL_REQ );
1502 mph_mon_ctrl_req->action = LEAVING_PIM_PBCCH;
1503 PSENDX (PL, mph_mon_ctrl_req);
1504 }
1505 {
1506 PALLOC(stop_cnf, RRGRR_STOP_TASK_CNF);
1507 PSENDX(GRR, stop_cnf);
1508 }
1509 /* XXX stop PLMN scan ? */
1510 }
1511 break;
1512 case LEAVE_PAM_PBCCH:
1513 {
1514 PALLOC(mph_mon_ctrl_req, MPH_MON_CTRL_REQ );
1515 TRACE_EVENT("LEAVE PAM");
1516 mph_mon_ctrl_req->action = LEAVING_PAM_PBCCH;
1517 PSENDX (PL, mph_mon_ctrl_req);
1518 {
1519 PALLOC(stop_cnf, RRGRR_STOP_TASK_CNF);
1520 PSENDX(GRR, stop_cnf);
1521 }
1522 }
1523 break;
1524 case LEAVE_PTM_PBCCH:
1525
1526 {
1527 PALLOC(mph_mon_ctrl_req, MPH_MON_CTRL_REQ );
1528 TRACE_EVENT("LEAVE PTM");
1529 mph_mon_ctrl_req->action = LEAVING_PTM_PBCCH;
1530 PSENDX (PL, mph_mon_ctrl_req);
1531
1532 {
1533 PALLOC(stop_cnf, RRGRR_STOP_TASK_CNF);
1534 PSENDX(GRR, stop_cnf);
1535 }
1536 }
1537 break;
1538 default:
1539 break;
1540
1541 }
1542 PFREE(stop_task);
1543 }
1544
1545 /*
1546 +-----------------------------------------------------------------------------+
1547 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1548 | STATE : code ROUTINE : dat_rrgrr_activate_req |
1549 +-----------------------------------------------------------------------------+
1550
1551 PURPOSE : Process the primitive RRGRR_ACTIVATE_REQ received from GRR.
1552 This primitive activates RR. RR acts as if the MS is only
1553 GSM service mobile. Monitor CCCH and BCCH.
1554 IN :
1555 OUT :
1556
1557 */
1558
1559 void dat_rrgrr_activate_req (T_RRGRR_ACTIVATE_REQ *act_req)
1560 {
1561 GET_INSTANCE_DATA;
1562 TRACE_EVENT ("dat_rrgrr_activate_req ()");
1563
1564 rr_data->gprs_data.gprs_suspend = act_req->susp_req;
1565 rr_data->gprs_data.rac = act_req->rac;
1566 rr_data->gprs_data.gprs_resump = GPRS_RESUMPTION_ACK;
1567
1568 switch(GET_STATE(STATE_GPRS))
1569 {
1570 case GPRS_PIM_PBCCH:
1571 case GPRS_PAM_PBCCH:
1572 case GPRS_PTM_PBCCH:
1573
1574 /* we need the parameters from GRR to make
1575 * a MO call
1576 */
1577 if(act_req->non_gprs.v_non_gprs)
1578 {
1579 handle_non_gprs_param(&act_req->non_gprs);
1580 }
1581 break;
1582 case GPRS_PIM_BCCH:
1583 /* nothing to do, just wait for MM to start with RR_ESTABLISH_REQ */
1584 /*SET_STATE(STATE_GPRS, GPRS_SUSPENDED_BCCH); do this on
1585 RR_ESTABLISH_REQ */
1586 break;
1587 case GPRS_PAM_BCCH:
1588 case GPRS_PTM_BCCH:
1589 /*
1590 * abort procedures we are doing for GPRS
1591 * and go back to idle mode to wait for the
1592 * RR_ESTABLISH_REQ
1593 */
1594 rr_data->gprs_data.page_mode = PAG_MODE_DEFAULT;
1595 #ifdef REL99
1596 #else
1597 att_return_to_idle();
1598 #endif
1599 SET_STATE(STATE_GPRS, GPRS_PIM_BCCH);
1600 #ifdef REL99
1601 att_return_to_idle();
1602 #endif
1603 break;
1604 default:
1605 break;
1606 }
1607
1608 PFREE (act_req);
1609 }
1610
1611 /*
1612 +-----------------------------------------------------------------------------+
1613 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1614 | STATE : code ROUTINE : dat_set_gprs_resump |
1615 +-----------------------------------------------------------------------------+
1616
1617 PURPOSE : Sets stored GPRS resumption value to the RR_RELEASE_IND primitive
1618 to send.
1619 IN : Pointer to RR_RELEASE_IND primitive.
1620 OUT :
1621
1622 */
1623
1624 void dat_set_gprs_resump (T_RR_RELEASE_IND* rr_release_ind)
1625 {
1626 GET_INSTANCE_DATA;
1627 rr_release_ind->gprs_resumption = rr_data->gprs_data.gprs_resump;
1628 }
1629
1630
1631
1632 /*
1633 +-----------------------------------------------------------------------------+
1634 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1635 | STATE : code ROUTINE : dat_gprs_set_suspended |
1636 +-----------------------------------------------------------------------------+
1637
1638 PURPOSE : Sets state to GPRS_SUSPENDED_PBCCH or GPRS_SUSPENDED_BCCH
1639 IN :
1640 OUT :
1641
1642 */
1643
1644
1645 void dat_gprs_set_suspended(void)
1646 {
1647 GET_INSTANCE_DATA;
1648 switch(GET_STATE(STATE_GPRS))
1649 {
1650 case GPRS_PIM_PBCCH:
1651 case GPRS_PAM_PBCCH:
1652 case GPRS_PTM_PBCCH:
1653 SET_STATE(STATE_GPRS, GPRS_SUSPENDED_PBCCH);
1654 break;
1655 case GPRS_PIM_BCCH:
1656 case GPRS_PAM_BCCH:
1657 case GPRS_PTM_BCCH:
1658 SET_STATE(STATE_GPRS, GPRS_SUSPENDED_BCCH);
1659 break;
1660 default:
1661 break;
1662 }
1663 }
1664
1665 #ifdef REL99
1666 /*
1667 +-----------------------------------------------------------------------------+
1668 | PROJECT : GSM-GPRS (6147) MODULE : RR_GPRS |
1669 | STATE : code ROUTINE : dat_gprs_set_suspended |
1670 +-----------------------------------------------------------------------------+
1671
1672 PURPOSE : Sets state to GPRS_SUSPENDED_PBCCH or GPRS_SUSPENDED_BCCH
1673 IN :
1674 OUT :
1675
1676 */
1677 BOOL dat_gprs_cell_in_ptm(void)
1678 {
1679 GET_INSTANCE_DATA;
1680 switch(GET_STATE(STATE_GPRS))
1681 {
1682 case GPRS_PTM_PBCCH:
1683 case GPRS_PTM_BCCH:
1684 return TRUE;
1685 default:
1686 return FALSE;
1687 }
1688 }
1689 #endif
1690
1691 /*===========================================================================*/
1692 /*
1693 * L O C A L S
1694 */
1695 /*===========================================================================*/
1696 /*
1697 +-----------------------------------------------------------------------------+
1698 | PROJECT : GSM-GPRS (??6147) MODULE : RR_GPRS |
1699 | STATE : code ROUTINE : get_r_bit |
1700 +-----------------------------------------------------------------------------+
1701
1702 PURPOSE : R-bit for the IA-prims
1703 IN : access counter
1704 OUT : r_bit
1705
1706 */
1707
1708 static UBYTE get_r_bit (void)
1709 {
1710 GET_INSTANCE_DATA;
1711 UBYTE r_bit;
1712
1713 switch (rr_data->ms_data.access_counter)
1714 {
1715 case 0:
1716 r_bit = NOT_PRESENT_8BIT;
1717 break;
1718 case 1:
1719 r_bit = CHAN_REQ_SENT_ONCE;
1720 break;
1721 default:
1722 r_bit = CHAN_REQ_SENT_MORE;
1723 break;
1724 }
1725 return r_bit;
1726 }
1727
1728 #endif /* GPRS */
1729 #endif /* RR_DATG_C */