2 * (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 char *rr_state_names
[] = {
32 static void new_rr_state(struct gsm_rrlayer
*rr
, int state
)
34 if (state
< 0 || state
>= (sizeof(rr_state_names
) / sizeof(char *)))
37 if (state
== GSM_RRSTATE_IDLE
) {
40 /* free establish message, if any */
43 msgb_free(rr
->rr_est_msg
);
44 rr
->rr_est_msg
= NULL
;
46 /* free all pending messages */
47 while((msg
= msgb_dequeue(&rr
->downqueue
)))
51 DEBUGP(DRR
, "new state %s -> %s\n",
52 rr_state_names
[rr
->state
], rr_state_names
[state
]);
61 static void start_rr_t3122(struct gsm_rrlayer
*rr
, int sec
, int micro
)
63 DEBUGP(DRR
, "starting T3122 with %d seconds\n", current
, sec
);
64 rr
->t3122
.cb
= timeout_rr_t3122
;
66 bsc_schedule_timer(&rr
->t3122
, sec
, micro
);
69 static void start_rr_t3126(struct gsm_rrlayer
*rr
, int sec
, int micro
)
71 DEBUGP(DRR
, "starting T3126 with %d seconds\n", current
, sec
);
72 rr
->t3126
.cb
= timeout_rr_t3126
;
74 bsc_schedule_timer(&rr
->t3126
, sec
, micro
);
77 static void stop_rr_t3122(struct gsm_rrlayer
*rr
)
79 if (timer_pending(rr
->t3122
)) {
80 DEBUGP(DRR
, "stopping pending timer T3122\n");
81 bsc_del_timer(&rr
->t3122
);
83 rr
->t3122_running
= 0;
86 static void stop_rr_t3126(struct gsm_rrlayer
*rr
)
88 if (bsc_timer_pending(rr
->t3126
)) {
89 DEBUGP(DRR
, "stopping pending timer T3126\n");
90 bsc_del_timer(&rr
->t3126
);
94 static void timeout_rr_t3122(void *arg
)
98 static void timeout_rr_t3126(void *arg
)
100 struct gsm_rrlayer
*rr
= arg
;
102 if (rr
->rr_est_req
) {
103 struct msgb
*msg
= gsm48_mm_msgb_alloc();
104 struct gsm_mm_hdr
*mmh
;
108 mmh
= (struct gsm_mm_hdr
*)msg
->data
;
109 mmh
->msg_type RR_REL_IND
;
110 mmh
->cause
= GSM_MM_CAUSE_RA_FAILURE
;
114 new_rr_state(rr
, GSM_RRSTATE_IDLE
);
121 /* send rr status request */
122 static int gsm_rr_tx_rr_status(struct osmocom_ms
*ms
, uint8_t cause
)
124 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
125 struct msgb
*msg
= gsm48_rr_msgb_alloc();
126 struct gsm48_hdr
*gh
;
127 struct gsm48_rr_status
*st
;
131 gh
= (struct gsm48_hdr
*) msgb_put(msg
, sizeof(*gh
));
132 st
= (struct gsm48_rr_status
*) msgb_put(msg
, sizeof(*st
));
134 gh
->proto
= GSM48_PDISC_RR
;
135 gh
->msg_type
= GSM48_MT_RR_CIPH_M_COMPL
;
138 st
->rr_cause
= cause
;
140 return rslms_data_req(ms
, msg
, 0);
147 /* send chiperhing mode complete */
148 static int gsm_rr_tx_cip_mode_cpl(struct osmocom_ms
*ms
, uint8_t cr
)
150 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
151 struct gsm_subscriber
*subcr
= ms
->subscr
;
152 struct msgb
*msg
= gsm48_rr_msgb_alloc();
153 struct gsm48_hdr
*gh
;
154 u_int8_t buf
[11], *ie
;
158 gh
= (struct gsm48_hdr
*) msgb_put(msg
, sizeof(*gh
));
160 gh
->proto
= GSM48_PDISC_RR
;
161 gh
->msg_type
= GSM48_MT_RR_CIPH_M_COMPL
;
165 gsm48_generate_mid_from_imsi(ie
, subscr
->imei
);
166 ie
= msgb_put(msg
, 1 + buf
[1]);
167 memcpy(ie
, buf
+ 1, 1 + buf
[1]);
170 return rslms_data_req(ms
, msg
, 0);
173 /* receive ciphering mode command */
174 static int gsm_rr_rx_cip_mode_cmd(struct osmocom_ms
*ms
, struct msgb
*msg
)
176 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
177 struct gsm48_hdr
*gh
= msgb_l3(msg
);
178 struct gsm48_cip_mode_cmd
*cm
= (struct gsm48_cip_mode_cmd
*)gh
->data
;
179 int payload_len
= msgb_l3len(msg
) - sizeof(*gh
) - sizeof(*cm
);
180 uint8_t sc
, alg_id
, cr
;
182 if (payload_len
< 0) {
183 DEBUGP(DRR
, "Short read of CIPHERING MODE COMMAND message.\n");
184 return gsm_rr_tx_rr_status(ms
, GSM48_RR_CAUSE_PROT_ERROR_UNSPC
);
187 /* cipher mode setting */
190 /* cipher mode response */
195 return gsm_rr_tx_rr_status(ms
, GSM48_RR_CAUSE_PROT_ERROR_UNSPC
);
197 /* change to ciphering */
198 tx_ph_cipher_req(ms
, sc
, alg_id
);
199 rr
->sc
= sc
, rr
->alg_id
= alg_id
;
202 return gsm_rr_tx_cip_mode_cpl(ms
, cr
);
209 /* Encode "Classmark 3" (10.5.2.20) */
210 static int gsm_rr_enc_cm3(struct osmocom_sm
*ms
, uint8_t *buf
, uint8_t *len
)
212 struct gsm_support
*sup
= ms
->support
;
215 memset(&bv
, 0, sizeof(bv
));
220 bitvec_set_bit(&bv
, 0);
221 /* band 3 supported */
223 bitvec_set_bit(&bv
, ONE
);
225 bitvec_set_bit(&bv
, ZERO
);
226 /* band 2 supported */
227 if (sup
->e_gsm
|| sup
->r_gsm
)
228 bitvec_set_bit(&bv
, ONE
);
230 bitvec_set_bit(&bv
, ZERO
);
231 /* band 1 supported */
232 if (sup
->p_gsm
&& !(sup
->e_gsm
|| sup
->r_gsm
))
233 bitvec_set_bit(&bv
, ONE
);
235 bitvec_set_bit(&bv
, ZERO
);
238 bitvec_set_bit(&bv
, ONE
);
240 bitvec_set_bit(&bv
, ZERO
);
242 bitvec_set_bit(&bv
, ONE
);
244 bitvec_set_bit(&bv
, ZERO
);
246 bitvec_set_bit(&bv
, ONE
);
248 bitvec_set_bit(&bv
, ZERO
);
250 bitvec_set_bit(&bv
, ONE
);
252 bitvec_set_bit(&bv
, ZERO
);
253 /* radio capability */
254 if (sup
->dcs_1800
&& !sup
->p_gsm
&& !(sup
->e_gsm
|| sup
->r_gsm
)) {
256 bitvec_set_uint(&bv
, 0, 4);
257 bitvec_set_uint(&bv
, sup
->dcs_capa
, 4);
259 if (sup
->dcs_1800
&& (sup
->p_gsm
|| (sup
->e_gsm
|| sup
->r_gsm
))) {
261 bitvec_set_uint(&bv
, sup
->dcs_capa
, 4);
263 bitvec_set_uint(&bv
, sup
->low_capa
, 4);
266 bitvec_set_uint(&bv
, 0, 4);
267 bitvec_set_uint(&bv
, sup
->low_capa
, 4);
271 bitvec_set_bit(&bv
, ONE
);
272 bitvec_set_uint(&bv
, sup
->r_capa
, 3);
274 bitvec_set_bit(&bv
, ZERO
);
276 /* multi slot support */
278 bitvec_set_bit(&bv
, ONE
);
279 bitvec_set_uint(&bv
, sup
->ms_capa
, 5);
281 bitvec_set_bit(&bv
, ZERO
);
284 if (sup
->ucs2_treat
) {
285 bitvec_set_bit(&bv
, ONE
);
287 bitvec_set_bit(&bv
, ZERO
);
289 /* support extended measurements */
291 bitvec_set_bit(&bv
, ONE
);
293 bitvec_set_bit(&bv
, ZERO
);
295 /* support measurement capability */
297 bitvec_set_bit(&bv
, ONE
);
298 bitvec_set_uint(&bv
, sup
->sms_val
, 4);
299 bitvec_set_uint(&bv
, sup
->sm_val
, 4);
301 bitvec_set_bit(&bv
, ZERO
);
303 /* positioning method capability */
305 bitvec_set_bit(&bv
, ONE
);
306 bitvec_set_bit(&bv
, sup
->e_otd_ass
== 1);
307 bitvec_set_bit(&bv
, sup
->e_otd_based
== 1);
308 bitvec_set_bit(&bv
, sup
->gps_ass
== 1);
309 bitvec_set_bit(&bv
, sup
->gps_based
== 1);
310 bitvec_set_bit(&bv
, sup
->gps_conv
== 1);
312 bitvec_set_bit(&bv
, ZERO
);
315 /* partitial bytes will be completed */
316 *len
= (bv
.cur_bit
+ 7) >> 3;
317 bitvec_spare_padding(&bv
, (*len
* 8) - 1);
322 /* encode classmark 2 */
323 static int gsm_rr_enc_cm2(struct osmocom_sm
*ms
, struct gsm48_classmark2
*cm
)
325 struct gsm_support
*sup
= ms
->support
;
327 cm
->pwr_lev
= sup
->pwr_lev
;
328 cm
->a5_1
= sup
->a5_1
;
329 cm
->es_ind
= sup
->es_ind
;
330 cm
->rev_lev
= sup
->rev_lev
;
331 cm
->fc
= (sup
->r_gsm
|| sup
->e_gsm
);
332 cm
->vgcs
= sup
->vgcs
;
334 cm
->sm
= sup
->sms_ptp
;
335 cm
->ss_ind
= sup
->ss_ind
;
336 cm
->ps_cap
= sup
->ps_cap
;
337 cm
->a5_2
= sup
->a5_2
;
338 cm
->a5_3
= sup
->a5_3
;
339 cm
->cmsp
= sup
->cmsp
;
340 cm
->solsa
= sup
->solsa
;
341 cm
->lcsva
= sup
->lcsva
;
344 /* send classmark change */
345 static int gsm_rr_tx_cm_change(struct osmocom_ms
*ms
)
347 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
348 struct gsm_support
*sup
= ms
->support
;
349 struct msgb
*msg
= gsm48_rr_msgb_alloc();
350 struct gsm48_hdr
*gh
;
351 struct gsm48_cm_change
*cc
;
357 gh
= (struct gsm48_hdr
*) msgb_put(msg
, sizeof(*gh
));
358 cc
= (struct gsm48_cm_change
*) msgb_put(msg
, sizeof(*cc
));
360 gh
->proto
= GSM48_PDISC_RR
;
361 gh
->msg_type
= GSM48_MT_RR_CLSM_CHG
;
364 cc
->cm_len
= sizeof(cm
->cm2
);
365 gsm_rr_enc_cm2(ms
, &cc
->cm2
)
368 if (sup
->dcs_1800
|| sup
->e_gsm
|| sup
->r_gsm
369 || sup
->a5_7
|| sup
->a5_6
|| sup
->a5_5
|| sup
->a5_4
372 || sup
->ext_meas
|| sup
->meas_cap
375 buf
[0] = GSM48_IE_CLASSMARK2
;
376 gsm_rr_enc_cm3(ms
, buf
+ 2, &buf
[1]);
379 return rslms_data_req(ms
, msg
, 0);
382 /* receiving classmark enquiry */
383 static int gsm_rr_rx_cm_enq(struct osmocom_ms
*ms
, struct msgb
*msg
)
385 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
386 struct gsm48_hdr
*gh
= msgb_l3(msg
);
387 int payload_len
= msgb_l3len(msg
) - sizeof(*gh
);
390 return gsm_rr_tx_cm_change(ms
);
397 /* send channel request burst message */
398 static int gsm_rr_tx_chan_req(struct osmocom_ms
*ms
, int cause
)
400 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
402 struct gsm_mm_hdr
*mmh
;
406 new_rr_state(rr
, GSM_RRSTATE_CONN_PEND
);
408 /* number of retransmissions (without first transmission) */
409 rr
->n_chan_req
= ms
->si
.max_retrans
;
411 /* generate CHAN REQ (9.1.8) */
414 case RR_EST_CAUSE_EMERGENCY
:
418 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (Emergency call)\n", chan_req
);
420 case RR_EST_CAUSE_REESTAB_TCH_F
:
423 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (re-establish TCH/F)\n", chan_req
);
425 case RR_EST_CAUSE_REESTAB_TCH_H
:
429 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (re-establish TCH/H with NECI)\n", chan_req
);
433 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (re-establish TCH/H no NECI)\n", chan_req
);
436 case RR_EST_CAUSE_REESTAB_2_TCH_H
:
440 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (re-establish TCH/H+TCH/H with NECI)\n", chan_req
);
444 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (re-establish TCH/H+TCH/H no NECI)\n", chan_req
);
447 case RR_EST_CAUSE_ANS_PAG_ANY
:
450 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (PAGING Any channel)\n", chan_req
);
452 case RR_EST_CAUSE_ANS_PAG_SDCCH
:
455 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (PAGING SDCCH)\n", chan_req
);
457 case RR_EST_CAUSE_ANS_PAG_TCH_F
:
458 /* ms supports no dual rate */
461 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (PAGING TCH/F)\n", chan_req
);
463 case RR_EST_CAUSE_ANS_PAG_TCH_ANY
:
464 /* ms supports no dual rate */
467 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (PAGING TCH/H or TCH/F)\n", chan_req
);
469 case RR_EST_CAUSE_ORIG_TCHF
:
470 /* ms supports no dual rate */
473 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (Orig TCH/F)\n", chan_req
);
475 case RR_EST_CAUSE_LOC_UPD
:
479 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (Location Update with NECI)\n", chan_req
);
483 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (Location Update no NECI)\n", chan_req
);
486 case RR_EST_CAUSE_OTHER_SDCCH
:
490 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (OHTER with NECI)\n", chan_req
);
494 DEBUGP(DRR
, "CHANNEL REQUEST: %02x (OTHER no NECI)\n", chan_req
);
498 if (!rr
->rr_est_req
) /* no request from MM */
501 DEBUGP(DRR
, "CHANNEL REQUEST: with unknown establishment cause: %d\n", rrmsg
->cause
);
502 msg
= gsm48_mm_msgb_alloc();
505 mmh
= (struct gsm_mm_hdr
*)msg
->data
;
506 mmh
->msg_type RR_REL_IND
;
507 mmh
->cause
= GSM_MM_CAUSE_UNDEFINED
;
509 new_rr_state(rr
, GSM_RRSTATE_IDLE
);
515 /* create and send RACH msg */
516 msg
= msgb_alloc_headroom(20, 16, "CHAN_REQ");
519 *msgb_put(msg
, 1) = chan_req
;
520 rr
->chan_req
= chan_req
;
521 t
= ms
->si
.tx_integer
;
524 *msgb_put(msg
, 1) = random() % t
; /* delay */
527 rr
->cr_hist
[1] = chan_req
;
529 return rslms_tx_rll_req_l3(ms
, RSL_MT_RAND_ACC_REQ
, chan_nr
, 0, msg
);
532 /* send next channel request in conn pend state */
533 static int gsm_rr_rand_acc_cnf(struct osmocom_ms
*ms
, struct msgb
*msg
)
535 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
539 if (!rr
->n_chan_req
) {
540 if (!timer_pending(rr
->t3126
))
541 start_rr_t3126(rr
, GSM_T3126_MS
);
547 switch(ms
->si
.tx_integer
) {
548 case 3: case 8: case 14: case 50:
549 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
553 case 4: case 9: case 16:
554 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
558 case 5: case 10: case 20:
559 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
563 case 6: case 11: case 25:
564 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
569 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
574 /* resend chan_req */
575 newmsg
= msgb_alloc_headroom(20, 16, "CHAN_REQ");
578 *msgb_put(newmsg
, 1) = rr
->chan_req
;
579 *msgb_put(newmsg
, 1) = (random() % ms
->si
.tx_integer
) + s
; /* delay */
580 rr
->cr_hist
[3] = rr
->cr_hist
[2];
581 rr
->cr_hist
[2] = rr
->cr_hist
[1];
582 rr
->cr_hist
[1] = chan_req
;
583 return rslms_tx_rll_req_l3(ms
, RSL_MT_RAND_ACC_REQ
, chan_nr
, 0, newmsg
);
590 /* paging channel request */
591 static int gsm_rr_chan2cause
[4] = {
592 RR_EST_CAUSE_ANS_PAG_ANY
,
593 RR_EST_CAUSE_ANS_PAG_SDCCH
,
594 RR_EST_CAUSE_ANS_PAG_TCH_F
,
595 RR_EST_CAUSE_ANS_PAG_TCH_ANY
598 /* given LV of mobile identity is checked agains ms */
599 static int gsm_match_mi(struct osmocom_ms
*ms
, u_int8_t mi
)
606 mi_type
= mi
[1] & GSM_MI_TYPE_MASK
;
608 case GSM_MI_TYPE_TMSI
:
611 memcpy(&tmsi
, mi
+2, 4);
612 if (ms
->subscr
.tmsi
== ntohl(tmsi
)
613 && ms
->subscr
.tmsi_valid
)
616 case GSM_MI_TYPE_IMSI
:
617 gsm48_mi_to_string(imsi
, sizeof(imsi
), mi
+ 1, mi
[0]);
618 if (!strcmp(imsi
, ms
->subscr
.imsi
))
622 DEBUGP(DRR
, "paging with unsupported MI type %d.\n", mi_type
);
628 /* paging request 1 message */
629 static int gsm_rr_rx_pag_req_1(struct osmocom_ms
*ms
, struct msgb
*msg
)
631 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
632 struct gsm48_rr_paging1
*pa
= msgb_l3(msg
);
633 int payload_len
= msgb_l3len(msg
) - sizeof(*pa
);
634 int chan_first
, chan_second
;
637 /* 3.3.1.1.2: ignore paging while establishing */
638 if (rr
->state
!= GSM_RRSTATE_IDLE
)
641 if (payload_len
< 2) {
643 DEBUGP(DRR
, "Short read of paging request 1 message .\n");
648 chan_first
= pa
->cneed1
;
649 chan_second
= pa
->cneed2
;
652 if (payload_len
< mi
[0] + 1)
654 if (gsm_match_mi(ms
, mi
) > 0)
655 return gsm_rr_tx_chan_req(ms
, gsm_rr_chan2cause
[chan_first
]);
657 payload_len
-= mi
[0] + 1;
658 mi
= pa
->data
+ mi
[0] + 1;
661 if (mi
[0] != GSM48_IE_MOBILE_ID
)
663 if (payload_len
< mi
[1] + 2)
665 if (gsm_match_mi(ms
, mi
+ 1) > 0)
666 return gsm_rr_tx_chan_req(ms
, gsm_rr_chan2cause
[chan_second
]);
671 /* paging request 2 message */
672 static int gsm_rr_rx_pag_req_2(struct osmocom_ms
*ms
, struct gsm_msgb
*msg
)
674 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
675 struct gsm48_rr_paging2
*pa
= msgb_l3(msg
);
676 int payload_len
= msgb_l3len(msg
) - sizeof(*pa
);
678 int chan_first
, chan_second
, chan_third
;
680 /* 3.3.1.1.2: ignore paging while establishing */
681 if (rr
->state
!= GSM_RRSTATE_IDLE
)
684 if (payload_len
< 0) {
686 DEBUGP(DRR
, "Short read of paging request 2 message .\n");
691 chan_first
= pa
->cneed1
;
692 chan_second
= pa
->cneed2
;
694 if (ms
->subscr
.tmsi
== ntohl(pa
->tmsi1
)
695 && ms
->subscr
.tmsi_valid
)
696 return gsm_rr_tx_chan_req(ms
, gsm_rr_chan2cause
[chan_first
]);
698 if (ms
->subscr
.tmsi
== ntohl(pa
->tmsi2
)
699 && ms
->subscr
.tmsi_valid
)
700 return gsm_rr_tx_chan_req(ms
, gsm_rr_chan2cause
[chan_second
]);
705 if (mi
[0] != GSM48_IE_MOBILE_ID
)
707 if (payload_len
< mi
[1] + 2 + 1) /* must include "channel needed" */
709 chan_third
= mi
[mi
[1] + 2] & 0x03; /* channel needed */
710 if (gsm_match_mi(ms
, mi
+ 1) > 0)
711 return gsm_rr_tx_chan_req(ms
, gsm_rr_chan2cause
[chan_third
]);
716 /* paging request 3 message */
717 static int gsm_rr_rx_pag_req_3(struct osmocom_ms
*ms
, struct gsm_msgb
*msg
)
719 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
720 struct gsm48_rr_paging3
*pa
= msgb_l3(msg
);
721 int payload_len
= msgb_l3len(msg
) - sizeof(*pa
);
723 int chan_first
, chan_second
, chan_third
, chan_fourth
;
725 /* 3.3.1.1.2: ignore paging while establishing */
726 if (rr
->state
!= GSM_RRSTATE_IDLE
)
729 if (payload_len
< 0) { /* must include "channel needed", part of *pa */
731 DEBUGP(DRR
, "Short read of paging request 3 message .\n");
736 chan_first
= pa
->cneed1
;
737 chan_second
= pa
->cneed2
;
738 chan_third
= pa
->cneed3
;
739 chan_fourth
= pa
->cneed4
;
741 if (ms
->subscr
.tmsi
== ntohl(pa
->tmsi1
)
742 && ms
->subscr
.tmsi_valid
)
743 return gsm_rr_tx_chan_req(ms
, gsm_rr_chan2cause
[chan_first
]);
745 if (ms
->subscr
.tmsi
== ntohl(pa
->tmsi2
)
746 && ms
->subscr
.tmsi_valid
)
747 return gsm_rr_tx_chan_req(ms
, gsm_rr_chan2cause
[chan_second
]);
749 if (ms
->subscr
.tmsi
== ntohl(pa
->tmsi3
)
750 && ms
->subscr
.tmsi_valid
)
751 return gsm_rr_tx_chan_req(ms
, gsm_rr_chan2cause
[chan_third
]);
753 if (ms
->subscr
.tmsi
== ntohl(pa
->tmsi4
)
754 && ms
->subscr
.tmsi_valid
)
755 return gsm_rr_tx_chan_req(ms
, gsm_rr_chan2cause
[chan_fourth
]);
761 * (immediate) assignment
764 /* match request reference agains request history */
765 static int gsm_match_ra(struct osmocom_ms
*ms
, struct gsm48_req_ref
*req
)
767 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
770 for (i
= 0; i
< 3; i
++) {
771 if (rr
->cr_hist
[i
] >= 0
772 && ref
->ra
== rr
->cr_hist
[i
]) {
773 // todo: match timeslot
781 /* transmit assignment complete after establishing link */
782 static int gsm_rr_tx_ass_cpl(struct osmocom_ms
*ms
, uint8_t cause
)
784 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
785 struct msgb
*msg
= gsm48_rr_msgb_alloc();
786 struct gsm48_hdr
*gh
;
787 struct gsm48_ass_cpl
*ac
;
791 gh
= (struct gsm48_hdr
*) msgb_put(msg
, sizeof(*gh
));
792 ac
= (struct gsm48_ass_cpl
*) msgb_put(msg
, sizeof(*ac
));
794 gh
->proto
= GSM48_PDISC_RR
;
795 gh
->msg_type
= GSM48_MT_RR_ASS_COMPL
;
798 ac
->rr_cause
= cause
;
800 return rslms_data_req(ms
, msg
, 0);
803 /* transmit failure to old link */
804 static int gsm_rr_tx_ass_fail(struct osmocom_ms
*ms
, uint8_t cause
)
806 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
807 struct msgb
*msg
= gsm48_rr_msgb_alloc();
808 struct gsm48_hdr
*gh
;
809 struct gsm48_ass_fail
*ac
;
813 gh
= (struct gsm48_hdr
*) msgb_put(msg
, sizeof(*gh
));
814 af
= (struct gsm48_ass_fail
*) msgb_put(msg
, sizeof(*af
));
816 gh
->proto
= GSM48_PDISC_RR
;
817 gh
->msg_type
= GSM48_MT_RR_ASS_COMPL
;
820 af
->rr_cause
= cause
;
822 return rslms_data_req(ms
, msg
, 0);
825 /* receive immediate assignment */
826 static int gsm_rr_rx_imm_ass(struct osmocom_ms
*ms
, struct gsm_msgb
*msg
)
828 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
829 struct gsm48_imm_ass
*ia
= msgb_l3(msg
);
830 int payload_len
= msgb_l3len(msg
) - sizeof(*ia
);
832 /* 3.3.1.1.2: ignore assignment while idle */
833 if (rr
->state
!= GSM_RRSTATE_CONN_PEND
|| !rr
->wait_assign
)
836 if (payload_len
< 1 /* mobile allocation IE must be included */
837 || *gh
->data
+ 1 > payload_len
) { /* short read of IE */
838 DEBUGP(DRR
, "Short read of immediate assignment message.\n");
842 DEBUGP(DRR
, "moble allocation in immediate assignment too large.\n");
847 if (gsm_match_ra(ms
, ia
->req_ref
)) {
848 /* channel description */
849 memset(&rr
->chan_desc
, 0, sizeof(cd
));
850 memcpy(rr
->chan_desc
.chan_desc
, ia
->chan_desc
, 3);
852 rr
->timing_advance
= ia
->timing_advance
;
853 /* mobile allocation */
854 memcpy(rr
->mobile_alloc_lv
, gh
->data
, *gh
->data
+ 1);
856 return gsm_rr_dl_est(ms
);
862 /* receive immediate assignment extended */
863 static int gsm_rr_rx_imm_ass_ext(struct osmocom_ms
*ms
, struct gsm_msgb
*msg
)
865 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
866 struct gsm48_imm_ass_ext
*ia
= msgb_l3(msg
);
867 int payload_len
= msgb_l3len(msg
) - sizeof(*ia
);
869 /* 3.3.1.1.2: ignore assignment while idle */
870 if (rr
->state
!= GSM_RRSTATE_CONN_PEND
|| !rr
->wait_assign
)
873 if (payload_len
< 1 /* mobile allocation IE must be included */
874 || *gh
->data
+ 1 > payload_len
) { /* short read of IE */
875 DEBUGP(DRR
, "Short read of immediate assignment extended message.\n");
879 DEBUGP(DRR
, "moble allocation in immediate assignment extended too large.\n");
884 if (gsm_match_ra(ms
, ia
->req_ref1
)) {
885 /* channel description */
886 memset(&rr
->chan_desc
, 0, sizeof(cd
));
887 memcpy(rr
->chan_desc
.chan_desc
, ia
->chan_desc1
, 3);
889 rr
->timing_advance
= ia
->timing_advance1
;
890 /* mobile allocation */
891 memcpy(rr
->mobile_alloc_lv
, gh
->data
, *gh
->data
+ 1);
893 return gsm_rr_dl_est(ms
);
896 if (gsm_match_ra(ms
, ia
->req_ref2
)) {
897 /* channel description */
898 memset(&rr
->chan_desc
, 0, sizeof(cd
));
899 memcpy(rr
->chan_desc
.chan_desc
, ia
->chan_desc2
, 3);
901 rr
->timing_advance
= ia
->timing_advance2
;
902 /* mobile allocation */
903 memcpy(rr
->mobile_alloc_lv
, gh
->data
, *gh
->data
+ 1);
905 return gsm_rr_dl_est(ms
);
911 /* receive immediate assignment reject */
912 static int gsm_rr_rx_imm_ass_rej(struct osmocom_ms
*ms
, struct gsm_msgb
*msg
)
914 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
915 struct gsm48_imm_ass_rej
*ia
= msgb_l3(msg
);
916 int payload_len
= msgb_l3len(msg
) - sizeof(*ia
);
918 struct gsm48_req_ref
*req_ref
;
921 /* 3.3.1.1.2: ignore assignment while idle */
922 if (rr
->state
!= GSM_RRSTATE_CONN_PEND
|| !rr
->wait_assign
)
925 if (payload_len
< 0) {
927 DEBUGP(DRR
, "Short read of immediate assignment reject message.\n");
931 for (i
= 0; i
< 4; i
++) {
932 /* request reference */
933 req_ref
= (struct gsm48_req_ref
*)(((uint8_t *)&ia
->req_ref1
) + i
* 4);
934 if (gsm_match_ra(ms
, req_ref
)) {
935 /* wait indication */
936 t3122_value
= ((uint8_t *)&ia
->wait_ind1
) + i
* 4;
938 start_rr_t3122(rr
, t3122_value
, 0);
939 /* start timer 3126 if not already */
940 if (!timer_pending(rr
->t3126
))
941 start_rr_t3126(rr
, GSM_T3126_MS
);
942 /* stop assignmnet requests */
945 /* wait until timer 3126 expires, then release
946 * or wait for channel assignment */
954 /* receive additional assignment */
955 static int gsm_rr_rx_add_ass(struct osmocom_ms
*ms
, struct msgb
*msg
)
957 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
958 struct gsm48_hdr
*gh
= msgb_l3(msg
);
959 struct gsm48_add_ass
*aa
= (struct gsm48_add_ass
*)gh
->data
;
960 int payload_len
= msgb_l3len(msg
) - sizeof(*gh
) - sizeof(*aa
);
962 if (payload_len
< 0) {
963 DEBUGP(DRR
, "Short read of ADDITIONAL ASSIGNMENT message.\n");
964 return gsm_rr_tx_rr_status(ms
, GSM48_RR_CAUSE_PROT_ERROR_UNSPC
);
966 tlv_parse(&tp
, &rsl_att_tlvdef
, aa
->data
, payload_len
, 0, 0);
968 return gsm_rr_tx_rr_status(ms
, GSM48_RR_CAUSE_PROT_ERROR_UNSPC
);
972 * measturement reports
975 static int gsm_rr_tx_meas_rep(struct osmocom_ms
*ms
)
977 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
978 struct gsm_rr_meas
*meas
= &rr
->meas
;
979 struct msgb
*msg
= gsm48_rr_msgb_alloc();
980 struct gsm48_hdr
*gh
;
981 struct gsm48_meas_res
*mr
;
985 gh
= (struct gsm48_hdr
*) msgb_put(msg
, sizeof(*gh
));
986 mr
= (struct gsm48_meas_res
*) msgb_put(msg
, sizeof(*mr
));
988 gh
->proto
= GSM48_PDISC_RR
;
989 gh
->msg_type
= GSM48_MT_RR_MEAS_RES
;
991 /* measurement results */
992 mr
->rxlev_full
= meas
->rxlev_full
;
993 mr
->rxlev_sub
= meas
->rxlev_sub
;
994 mr
->rxqual_full
= meas
->rxqual_full
;
995 mr
->rxqual_sub
= meas
->rxqual_sub
;
998 mr
->meas_valid
= meas
->meas_valid
;
999 if (meas
->ncell_na
) {
1000 /* no results for serving cells */
1004 mr
->no_n_hi
= meas
->count
>> 2;
1005 mr
->no_n_lo
= meas
->count
& 3;
1007 rxlev_nc1
= meas
->rxlev_nc
[0];
1008 rxlev_nc2_hi
= meas
->rxlev_nc
[1] >> 1;
1009 rxlev_nc2_lo
= meas
->rxlev_nc
[1] & 1;
1010 rxlev_nc3_hi
= meas
->rxlev_nc
[2] >> 2;
1011 rxlev_nc3_lo
= meas
->rxlev_nc
[2] & 3;
1012 rxlev_nc4_hi
= meas
->rxlev_nc
[3] >> 3;
1013 rxlev_nc4_lo
= meas
->rxlev_nc
[3] & 7;
1014 rxlev_nc5_hi
= meas
->rxlev_nc
[4] >> 4;
1015 rxlev_nc5_lo
= meas
->rxlev_nc
[4] & 15;
1016 rxlev_nc6_hi
= meas
->rxlev_nc
[5] >> 5;
1017 rxlev_nc6_lo
= meas
->rxlev_nc
[5] & 31;
1018 bsic_nc1_hi
= meas
->bsic_nc
[0] >> 3;
1019 bsic_nc1_lo
= meas
->bsic_nc
[0] & 7;
1020 bsic_nc2_hi
= meas
->bsic_nc
[1] >> 4;
1021 bsic_nc2_lo
= meas
->bsic_nc
[1] & 15;
1022 bsic_nc3_hi
= meas
->bsic_nc
[2] >> 5;
1023 bsic_nc3_lo
= meas
->bsic_nc
[2] & 31;
1024 bsic_nc4
= meas
->bsic_nc
[3];
1025 bsic_nc5
= meas
->bsic_nc
[4];
1026 bsic_nc6
= meas
->bsic_nc
[5];
1027 bcch_f_nc1
= meas
->bcch_f_nc
[0];
1028 bcch_f_nc2
= meas
->bcch_f_nc
[1];
1029 bcch_f_nc3
= meas
->bcch_f_nc
[2];
1030 bcch_f_nc4
= meas
->bcch_f_nc
[3];
1031 bcch_f_nc5_hi
= meas
->bcch_f_nc
[4] >> 1;
1032 bcch_f_nc5_lo
= meas
->bcch_f_nc
[4] & 1;
1033 bcch_f_nc6_hi
= meas
->bcch_f_nc
[5] >> 2;
1034 bcch_f_nc6_lo
= meas
->bcch_f_nc
[5] & 3;
1036 //todo return rslms_data_req(ms, msg, 0);
1040 * link establishment and release
1043 /* activate link and send establish request */
1044 static int gsm_rr_dl_est(struct osmocom_ms
*ms
)
1046 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
1047 struct gsm_subscriber
*subcr
= ms
->subscr
;
1049 struct gsm48_hdr
*gh
;
1050 struct gsm48_pag_rsp
*pa
;
1055 /* flush pending RACH requests */
1056 rr
->n_chan_req
= 0; // just to be safe
1057 msg
= msgb_alloc_headroom(20, 16, "RAND_FLUSH");
1060 rslms_tx_rll_req_l3(ms
, RSL_MT_RAND_ACC_FLSH
, chan_nr
, 0, msg
);
1062 /* send DL_EST_REQ */
1063 if (rr
->rr_est_msg
) {
1064 /* use queued message */
1065 msg
= rr
->rr_est_msg
;
1070 /* create paging response */
1071 msg
= gsm48_rr_msgb_alloc();
1074 gh
= (struct gsm48_hdr
*) msgb_put(msg
, sizeof(*gh
));
1075 pr
= (struct gsm48_pag_rsp
*) msgb_put(msg
, sizeof(*pr
));
1077 if (subscr
->key_valid
)
1078 pr
->key_seq
= subscr
->key_seq
;
1082 cc
->cm_len
= sizeof(cm
->cm2
);
1083 gsm_rr_enc_cm2(ms
, &cc
->cm2
)
1084 /* mobile identity */
1085 if (ms
->subscr
.tmsi_valid
) {
1086 gsm48_generate_mid_from_tmsi(mi
, subscr
->tmsi
);
1087 } else if (subscr
->imsi
[0])
1088 gsm48_generate_mid_from_imsi(mi
, subscr
->imsi
);
1091 mi
[2] = 0xf0 | GSM_MI_TYPE_NONE
;
1093 msgb_put(msg
, 1 + mi
[1]);
1094 memcpy(cm
->data
, mi
+ 1, 1 + mi
[1]);
1097 /* activate channel */
1098 tx_ph_dm_est_req(ms
, arfcn
, rr
->chan_desc
.chan_desc
.chan_nr
);
1100 /* start establishmnet */
1101 return rslms_tx_rll_req_l3(ms
, RSL_MT_EST_REQ
, rr
->chan_desc
.chan_desc
.chan_nr
, 0, msg
);
1104 /* the link is established */
1105 static int gsm_rr_estab_cnf(struct osmocom_ms
*ms
, struct msgb
*msg
)
1107 struct msgb
*newmsg
;
1108 struct gsm_mm_hdr
*newmmh
;
1110 /* if MM has releases before confirm, we start release */
1111 if (rr
->state
== GSM_RRSTATE_IDLE
) {
1112 /* release message */
1113 newmsg
= gsm48_rr_msgb_alloc();
1117 return rslms_tx_rll_req_l3(ms
, RSL_MT_REL_REQ
, 0, 0, newmsg
);
1121 new_rr_state(rr
, GSM_RRSTATE_DEDICATED
);
1123 /* send confirm to upper layer */
1124 newmsg
= gsm48_mm_msgb_alloc();
1127 newmmh
= (struct gsm_mm_hdr
*)newmsg
->data
;
1128 newmmh
->msg_type
= (rr
->rr_est_req
) ? RR_EST_CNF
: RR_EST_IND
;
1129 return rr_rcvmsg(ms
, newmsg
);
1132 /* the link is released */
1133 static int gsm_rr_rel_cnf(struct osmocom_ms
*ms
, struct gsm_dl
*dlmsg
)
1135 /* deactivate channel */
1136 tx_ph_dm_rel_req(ms
, arfcn
, rr
->chan_desc
.chan_desc
.chan_nr
);
1138 /* do nothing, because we aleady IDLE
1139 * or we received the rel cnf of the last connection
1140 * while already requesting a new one (CONN PEND)
1147 * radio ressource requests
1150 /* establish request for dedicated mode */
1151 static int gsm_rr_est_req(struct osmocom_ms
*ms
, struct msgb
*msg
)
1153 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
1154 struct gsm_mm_hdr
*mmh
= msgb
->data
;
1155 struct gsm48_hdr
*gh
= msgb_l3(msg
);
1158 if (timer_pending(rr
->t3122
)) {
1159 if (rrmsg
->cause
!= RR_EST_CAUSE_EMERGENCY
) {
1160 struct msgb
*newmsg
;
1161 struct gsm_mm_hdr
*newmmh
;
1163 newmsg
= gsm48_mm_msgb_alloc();
1166 newmmh
= (struct gsm_mm_hdr
*)newmsg
->data
;
1167 newmmh
->msg_type RR_REL_IND
;
1168 newmmh
->cause
= GSM_MM_CAUSE_T3122_PEND
;
1169 return rr_rcvmsg(ms
, newmsg
);
1175 if (rrmsg
->cause
!= RR_EST_CAUSE_EMERGENCY
) {
1176 if (!(ms
->access_class
& ms
->si
.access_class
)) {
1178 if (!ms
->opt
.access_class_override
) {
1179 struct msgb
*newmsg
;
1180 struct gsm_mm_hdr
*newmmh
;
1182 newmsg
= gsm48_mm_msgb_alloc();
1185 newmmh
= (struct gsm_mm_hdr
*)newmsg
->data
;
1186 newmmh
->msg_type RR_REL_IND
;
1187 newmmh
->cause
= GSM_MM_CAUSE_NOT_AUTHORIZED
;
1188 return rr_rcvmsg(ms
, newmsg
);
1192 if (!(ms
->access_class
& ms
->si
.access_class
)
1193 && !ms
->si
.emergency
)
1197 /* requested by RR */
1200 /* clone and store REQUEST message */
1202 printf("Error, missing l3 message\n");
1205 rr
->rr_est_msg
= msgb_alloc_headroom(256, 16, "EST_REQ");
1206 if (!rr
->rr_est_msg
)
1208 memcpy(msgb_put(rr_est_msg
, msgb_l3len(msg
)),
1209 msgb_l3(msg
), msgb_l3len(msg
));
1211 /* request channel */
1212 return gsm_rr_tx_chan_req(ms
, mmh
->cause
);
1215 /* send all queued messages down to layer 2 */
1216 static int gsm_rr_dequeue_down(struct osmocom_ms
*ms
)
1218 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
1221 while((msg
= msgb_dequeue(&rr
->downqueue
))) {
1222 rslms_tx_rll_req_l3(ms
, RSL_MT_DATA_REQ
, chan_nr
, 0, msg
);
1228 /* 3.4.2 transfer data in dedicated mode */
1229 static int gsm_rr_data_req(struct osmocom_ms
*ms
, struct msgb
*msg
)
1231 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
1233 if (rr
->state
!= GSM_RRSTATE_DEDICATED
) {
1239 msgb_pull(msg
, sizeof(struct gsm_mm_hdr
));
1241 /* queue message, during handover or assignment procedure */
1242 if (rr
->hando_susp_state
|| rr
->assign_susp_state
) {
1243 msgb_enqueue(&rr
->downqueue
, msg
);
1247 /* forward message */
1248 return rslms_tx_rll_req_l3(ms
, RSL_MT_DATA_REQ
, chan_nr
, 0, msg
);
1252 * data indications from data link
1255 /* 3.4.2 data from layer 2 to RR and upper layer*/
1256 static int gsm_rr_data_ind(struct osmocom_ms
*ms
, struct msbg
*msg
)
1258 struct gsm48_hdr
*gh
= msgb_l3(msg
);
1259 u_int8_t pdisc
= gh
->proto_discr
& 0x0f;
1261 if (pdisc
== GSM48_PDISC_RR
) {
1264 switch(gh
->msg_type
) {
1265 case GSM48_MT_RR_ADD_ASS
:
1266 rc
= gsm_rr_rx_add_ass(ms
, msg
);
1268 case GSM48_MT_RR_ASS_CMD
:
1269 rc
= gsm_rr_rx_ass_cmd(ms
, msg
);
1271 case GSM48_MT_RR_CIP_MODE_CMD
:
1272 rc
= gsm_rr_rx_cip_mode_cmd(ms
, msg
);
1274 case GSM48_MT_RR_CLSM_ENQ
:
1275 rc
= gsm_rr_rx_cm_enq(ms
, msg
);
1277 case GSM48_MT_RR_HANDO_CMD
:
1278 rc
= gsm_rr_rx_hando_cmd(ms
, msg
);
1280 case GSM48_MT_RR_FREQ_REDEF
:
1281 rc
= gsm_rr_rx_freq_redef(ms
, msg
);
1284 DEBUGP(DRR
, "Message type 0x%02x unknown.\n", gh
->msg_type
);
1292 msgb_push(msg
, sizeof(struct gsm_mm_hdr
));
1293 mmh
= (struct gsm_mm_hdr
*)msg
->data
;
1294 mmh
->msg_type
= RR_DATA_IND
;
1295 /* forward message */
1296 return rr_rcvmsg(ms
, msg
);
1299 /* unit data from layer 2 to RR layer */
1300 static int gsm_rr_unit_data_ind(struct osmocom_ms
*ms
, struct msgb
*msg
)
1302 struct gsm48_hdr
*gh
= msgb_l3(msg
);
1304 switch (gh
->msg_type
) {
1305 case GSM48_MT_RR_PAG_REQ_1
:
1306 return gsm_rr_rx_pag_req_1(ms
, dlmsg
->msg
);
1307 case GSM48_MT_RR_PAG_REQ_2
:
1308 return gsm_rr_rx_pag_req_2(ms
, dlmsg
->msg
);
1309 case GSM48_MT_RR_PAG_REQ_3
:
1310 return gsm_rr_rx_pag_req_3(ms
, dlmsg
->msg
);
1311 case GSM48_MT_RR_IMM_ASS
:
1312 return gsm_rr_rx_imm_ass(ms
, dlmsg
->msg
);
1313 case GSM48_MT_RR_IMM_ASS_EXT
:
1314 return gsm_rr_rx_imm_ass_ext(ms
, dlmsg
->msg
);
1315 case GSM48_MT_RR_IMM_ASS_REJ
:
1316 return gsm_rr_rx_imm_ass_rej(ms
, dlmsg
->msg
);
1318 DEBUGP(DRR
, "Message type 0x%02x unknown.\n", gh
->msg_type
);
1326 -------------------------------------------------------------------------------
1346 * system information
1349 /* decode "Cell Channel Description" (10.5.2.1b) and other frequency lists */
1350 static int gsm48_decode_freq_list(struct gsm_sysinfo_freq
*f
, uint8_t *cd
, uint8_t len
, uint8_t mask
, uint8_t frqt
)
1356 * The Range format uses "SMOD" computation.
1357 * e.g. "n SMOD m" equals "((n - 1) % m) + 1"
1358 * A cascade of multiple SMOD computations is simpified:
1359 * "(n SMOD m) SMOD o" equals "(((n - 1) % m) % o) + 1"
1361 * The Range format uses 16 octets of data in SYSTEM INFORMATION.
1362 * When used in dedicated messages, the length can be less.
1363 * In this case the ranges are decoded for all frequencies that
1364 * fit in the block of given length.
1368 for (i
= 0; i
< 1024; i
++)
1372 if ((cd
[0] & 0xc0 & mask
) == 0x00) {
1373 /* Bit map 0 format */
1376 for (i
= 1; i
<= 124; i
++)
1377 if ((cd
[15 - ((i
-1) >> 3)] & (1 << ((i
-1) & 7))))
1383 /* only Bit map 0 format for P-GSM */
1384 if (ms
->support
.p_gsm
&& !ms
->support
.e_gsm
1385 && !ms
->support
.r_gsm
&& !ms
->support
.dcs_1800
)
1389 if ((cd
[0] & 0xc8 & mask
) == 0x80) {
1390 /* Range 1024 format */
1391 uint16_t w
[17]; /* 1..16 */
1392 struct gsm_range_1024
*r
= (struct gsm_range_1024
*)cd
;
1396 memset(w
, 0, sizeof(w
));
1399 w
[1] = (r
->w1_hi
<< 8) | r
->w1_lo
;
1401 w
[2] = (r
->w2_hi
<< 1) | r
->w2_lo
;
1403 w
[3] = (r
->w3_hi
<< 2) | r
->w3_lo
;
1405 w
[4] = (r
->w4_hi
<< 2) | r
->w4_lo
;
1407 w
[5] = (r
->w5_hi
<< 2) | r
->w5_lo
;
1409 w
[6] = (r
->w6_hi
<< 2) | r
->w6_lo
;
1411 w
[7] = (r
->w7_hi
<< 2) | r
->w7_lo
;
1413 w
[8] = (r
->w8_hi
<< 1) | r
->w8_lo
;
1419 w
[11] = (r
->w11_hi
<< 6) | r
->w11_lo
;
1421 w
[12] = (r
->w12_hi
<< 5) | r
->w12_lo
;
1423 w
[13] = (r
->w13_hi
<< 4) | r
->w13_lo
;
1425 w
[14] = (r
->w14_hi
<< 3) | r
->w14_lo
;
1427 w
[15] = (r
->w15_hi
<< 2) | r
->w15_lo
;
1431 f
[w
[1]].mask
|= frqt
;
1433 f
[((w
[1] - 512 + w
[2] - 1) % 1023) + 1].mask
|= frqt
;
1435 f
[((w
[1] + w
[3] - 1) % 1023) + 1].mask
|= frqt
;
1437 f
[((w
[1] - 512 + ((w
[2] - 256 + w
[4] - 1) % 511)) % 1023) + 1].mask
|= frqt
;
1439 f
[((w
[1] + ((w
[3] - 256 - w
[5] - 1) % 511)) % 1023) + 1].mask
|= frqt
;
1441 f
[((w
[1] - 512 + ((w
[2] + w
[6] - 1) % 511)) % 1023) + 1].mask
|= frqt
;
1443 f
[((w
[1] + ((w
[3] + w
[7] - 1) % 511)) % 1023) + 1].mask
|= frqt
;
1445 f
[((w
[1] - 512 + ((w
[2] - 256 + ((w
[4] - 128 + w
[8] - 1) % 255)) % 511)) % 1023) + 1].mask
|= frqt
;
1447 f
[((w
[1] + ((w
[3] - 256 + ((w
[5] - 128 + w
[9] - 1) % 255)) % 511)) % 1023) + 1].mask
|= frqt
;
1449 f
[((w
[1] - 512 + ((w
[2] + ((w
[6] - 128 + w
[10] - 1) % 255)) % 511)) % 1023) + 1].mask
|= frqt
;
1451 f
[((w
[1] + ((w
[3] + ((w
[7] - 128 + w
[11] - 1) % 255)) % 511)) % 1023) + 1].mask
|= frqt
;
1453 f
[((w
[1] - 512 + ((w
[2] - 256 + ((w
[4] + w
[12] - 1) % 255)) % 511)) % 1023) + 1].mask
|= frqt
;
1455 f
[((w
[1] + ((w
[3] - 256 + ((w
[5] + w
[13] - 1) % 255)) % 511)) % 1023) + 1].mask
|= frqt
;
1457 f
[((w
[1] - 512 + ((w
[2] + ((w
[6] + w
[14] - 1) % 255)) % 511)) % 1023) + 1].mask
|= frqt
;
1459 f
[((w
[1] + ((w
[3] + ((w
[7] + w
[15] - 1) % 255)) % 511)) % 1023) + 1].mask
|= frqt
;
1461 f
[((w
[1] - 512 + ((w
[2] - 256 + ((w
[4] - 128 + ((w
[8] - 64 + w
[16] - 1) % 127)) % 255)) % 511)) % 1023) + 1].mask
|= frqt
;
1466 if ((cd
[0] & 0xce & mask
) == 0x88) {
1467 /* Range 512 format */
1468 uint16_t w
[18]; /* 1..17 */
1469 struct gsm_range_512
*r
= (struct gsm_range_512
*)cd
;
1473 memset(w
, 0, sizeof(w
));
1474 w
[0] = (r
->orig_arfcn_hi
<< 9) || (r
->orig_arfcn_mid
<< 1) || r
->orig_arfcn_lo
;
1475 w
[1] = (r
->w1_hi
<< 2) || r
->w1_lo
;
1477 w
[2] = (r
->w2_hi
<< 2) || r
->w2_lo
;
1479 w
[3] = (r
->w3_hi
<< 2) || r
->w3_lo
;
1481 w
[4] = (r
->w4_hi
<< 1) || r
->w4_lo
;
1487 w
[7] = (r
->w7_hi
<< 6) || r
->w7_lo
;
1489 w
[8] = (r
->w8_hi
<< 4) || r
->w8_lo
;
1491 w
[9] = (r
->w9_hi
<< 2) || r
->w9_lo
;
1497 w
[12] = (r
->w12_hi
<< 4) || r
->w12_lo
;
1499 w
[13] = (r
->w13_hi
<< 2) || r
->w13_lo
;
1505 w
[16] = (r
->w16_hi
<< 3) || r
->w16_lo
;
1509 f
[w
[0]].mask
|= frqt
;
1511 f
[(w
[0] + w
[1]) % 1024].mask
|= frqt
;
1513 f
[(w
[0] + ((w
[1] - 256 + w
[2] - 1) % 511) + 1) % 1024].mask
|= frqt
;
1515 f
[(w
[0] + ((w
[1] + w
[3] - 1) % 511) + 1) % 1024].mask
|= frqt
;
1517 f
[(w
[0] + ((w
[1] - 256 + ((w
[2] - 128 + w
[4] - 1) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1519 f
[(w
[0] + ((w
[1] + ((w
[3] - 128 + w
[5] - 1) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1521 f
[(w
[0] + ((w
[1] - 256 + ((w
[2] + w
[6] - 1) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1523 f
[(w
[0] + ((w
[1] + ((w
[3] + w
[7] - 1) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1525 f
[(w
[0] + ((w
[1] - 256 + ((w
[2] - 128 + ((w
[4] - 64 + w
[8] - 1) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1527 f
[(w
[0] + ((w
[1] + ((w
[3] - 128 + ((w
[5] - 64 + w
[9] - 1) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1529 f
[(w
[0] + ((w
[1] - 256 + ((w
[2] + ((w
[6] - 64 + w
[10] - 1) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1531 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] - 64 + w
[11] - 1) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1533 f
[(w
[0] + ((w
[1] - 256 + ((w
[2] - 128 + ((w
[4] + w
[12] - 1) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1535 f
[(w
[0] + ((w
[1] + ((w
[3] - 128 + ((w
[5] + w
[13] - 1) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1537 f
[(w
[0] + ((w
[1] - 256 + ((w
[2] + ((w
[6] + w
[14] - 1) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1539 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] + w
[15] - 1) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1541 f
[(w
[0] + ((w
[1] - 256 + ((w
[2] - 128 + ((w
[4] - 64 + ((w
[8] - 32 + w
[16] - 1) % 63)) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1543 f
[(w
[0] + ((w
[1] + ((w
[3] - 128 + ((w
[5] - 64 + ((w
[9] - 32 + w
[17] - 1) % 63)) % 127)) % 255)) % 511) + 1) % 1024].mask
|= frqt
;
1548 if ((cd
[0] & & mask
0xce) == 0x8a) {
1549 /* Range 256 format */
1550 uint16_t w
[22]; /* 1..21 */
1551 struct gsm_range_256
*r
= (struct gsm_range_256
*)cd
;
1555 memset(w
, 0, sizeof(w
));
1556 w
[0] = (r
->orig_arfcn_hi
<< 9) || (r
->orig_arfcn_mid
<< 1) || r
->orig_arfcn_lo
;
1557 w
[1] = (r
->w1_hi
<< 1) || r
->w1_lo
;
1563 w
[4] = (r
->w4_hi
<< 5) || r
->w4_lo
;
1565 w
[5] = (r
->w5_hi
<< 3) || r
->w5_lo
;
1567 w
[6] = (r
->w6_hi
<< 1) || r
->w6_lo
;
1571 w
[8] = (r
->w8_hi
<< 4) || r
->w8_lo
;
1573 w
[9] = (r
->w9_hi
<< 1) || r
->w9_lo
;
1577 w
[11] = (r
->w11_hi
<< 3) || r
->w11_lo
;
1585 w
[15] = (r
->w14_hi
<< 2) || r
->w14_lo
;
1587 w
[16] = (r
->w16_hi
<< 3) || r
->w16_lo
;
1593 w
[19] = (r
->w18_hi
<< 3) || r
->w18_lo
;
1595 w
[20] = (r
->w20_hi
<< 3) || r
->w20_lo
;
1599 f
[w
[0]].mask
|= frqt
;
1601 f
[(w
[0] + w
[1]) % 1024].mask
|= frqt
;
1603 f
[(w
[0] + ((w
[1] - 128 + w
[2] - 1) % 255) + 1) % 1024].mask
|= frqt
;
1605 f
[(w
[0] + ((w
[1] + w
[3] - 1) % 255) + 1) % 1024].mask
|= frqt
;
1607 f
[(w
[0] + ((w
[1] - 128 + ((w
[2] - 64 + w
[4] - 1) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1609 f
[(w
[0] + ((w
[1] + ((w
[3] - 64 + w
[5] - 1) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1611 f
[(w
[0] + ((w
[1] - 128 + ((w
[2] + w
[6] - 1) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1613 f
[(w
[0] + ((w
[1] + ((w
[3] + w
[7] - 1) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1615 f
[(w
[0] + ((w
[1] - 128 + ((w
[2] - 64 + ((w
[4] - 32 + w
[8] - 1) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1617 f
[(w
[0] + ((w
[1] + ((w
[3] - 64 + ((w
[5] - 32 + w
[9] - 1) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1619 f
[(w
[0] + ((w
[1] - 128 + ((w
[2] + ((w
[6] - 32 + w
[10] - 1) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1621 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] - 32 + w
[11] - 1) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1623 f
[(w
[0] + ((w
[1] - 128 + ((w
[2] - 64 + ((w
[4] + w
[12] - 1) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1625 f
[(w
[0] + ((w
[1] + ((w
[3] - 64 + ((w
[5] + w
[13] - 1) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1627 f
[(w
[0] + ((w
[1] - 128 + ((w
[2] + ((w
[6] + w
[14] - 1) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1629 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] + w
[15] - 1) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1631 f
[(w
[0] + ((w
[1] - 128 + ((w
[2] - 64 + ((w
[4] - 32 + ((w
[8] - 16 + w
[16] - 1) % 31)) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1633 f
[(w
[0] + ((w
[1] + ((w
[3] - 64 + ((w
[5] - 32 + ((w
[9] - 16 + w
[17] - 1) % 31)) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1635 f
[(w
[0] + ((w
[1] - 128 + ((w
[2] + ((w
[6] - 32 + ((w
[10] - 16 + w
[18] - 1) % 31)) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1637 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] - 32 + ((w
[11] - 16 + w
[19] - 1) % 31)) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1639 f
[(w
[0] + ((w
[1] - 128 + ((w
[2] - 64 + ((w
[4] + ((w
[12] - 16 + w
[20] - 1) % 31)) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1641 f
[(w
[0] + ((w
[1] + ((w
[3] - 64 + ((w
[5] + ((w
[13] - 16 + w
[21] - 1) % 31)) % 63)) % 127)) % 255) + 1) % 1024].mask
|= frqt
;
1646 if ((cd
[0] & 0xce & mask
) == 0x8c) {
1647 /* Range 128 format */
1648 uint16_t w
[29]; /* 1..28 */
1649 struct gsm_range_128
*r
= (struct gsm_range_128
*)cd
;
1653 memset(w
, 0, sizeof(w
));
1654 w
[0] = (r
->orig_arfcn_hi
<< 9) || (r
->orig_arfcn_mid
<< 1) || r
->orig_arfcn_lo
;
1659 w
[3] = (r
->w3_hi
<< 4) || r
->w3_lo
;
1661 w
[4] = (r
->w4_hi
<< 1) || r
->w4_lo
;
1665 w
[6] = (r
->w6_hi
<< 3) || r
->w6_lo
;
1689 w
[18] = (r
->w18_hi
<< 1) || r
->w18_lo
;
1695 w
[21] = (r
->w21_hi
<< 2) || r
->w21_lo
;
1705 w
[26] = (r
->w26_hi
<< 1) || r
->w26_lo
;
1711 f
[w
[0]].mask
|= frqt
;
1713 f
[(w
[0] + w
[1]) % 1024].mask
|= frqt
;
1715 f
[(w
[0] + ((w
[1] - 64 + w
[2] - 1) % 127) + 1) % 1024].mask
|= frqt
;
1717 f
[(w
[0] + ((w
[1] + w
[3] - 1) % 127) + 1) % 1024].mask
|= frqt
;
1719 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] - 32 + w
[4] - 1) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1721 f
[(w
[0] + ((w
[1] + ((w
[3] - 32 + w
[5] - 1) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1723 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] + w
[6] - 1) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1725 f
[(w
[0] + ((w
[1] + ((w
[3] + w
[7] - 1) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1727 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] - 32 + ((w
[4] - 16 + w
[8] - 1) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1729 f
[(w
[0] + ((w
[1] + ((w
[3] - 32 + ((w
[5] - 16 + w
[9] - 1) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1731 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] + ((w
[6] - 16 + w
[10] - 1) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1733 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] - 16 + w
[11] - 1) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1735 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] - 32 + ((w
[4] + w
[12] - 1) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1737 f
[(w
[0] + ((w
[1] + ((w
[3] - 32 + ((w
[5] + w
[13] - 1) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1739 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] + ((w
[6] + w
[14] - 1) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1741 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] + w
[15] - 1) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1743 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] - 32 + ((w
[4] - 16 + ((w
[8] - 8 + w
[16] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1745 f
[(w
[0] + ((w
[1] + ((w
[3] - 32 + ((w
[5] - 16 + ((w
[9] - 8 + w
[17] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1747 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] + ((w
[6] - 16 + ((w
[10] - 8 + w
[18] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1749 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] - 16 + ((w
[11] - 8 + w
[19] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1751 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] - 32 + ((w
[4] + ((w
[12] - 8 + w
[20] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1753 f
[(w
[0] + ((w
[1] + ((w
[3] - 32 + ((w
[5] + ((w
[13] - 8 + w
[21] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1755 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] + ((w
[6] + ((w
[14] - 8 + w
[22] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1757 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] + ((w
[15] - 8 + w
[23] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1759 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] - 32 + ((w
[4] - 16 + ((w
[8] + w
[24] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1761 f
[(w
[0] + ((w
[1] + ((w
[3] - 32 + ((w
[5] - 16 + ((w
[9] + w
[25] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1763 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] + ((w
[6] - 16 + ((w
[10] + w
[26] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1765 f
[(w
[0] + ((w
[1] + ((w
[3] + ((w
[7] - 16 + ((w
[11] + w
[27] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1767 f
[(w
[0] + ((w
[1] - 64 + ((w
[2] - 32 + ((w
[4] + ((w
[12] + w
[28] - 1) % 15)) % 31)) % 63)) % 127) + 1) % 1024].mask
|= frqt
;
1772 if ((cd
[0] & 0xce & mask
) == 0x8e) {
1773 /* Variable bitmap format (can be any length >= 3) */
1775 struct gsm_var_bit
*r
= (struct gsm_var_bit
*)cd
;
1779 orig
= (r
->orig_arfcn_hi
<< 9) || (r
->orig_arfcn_mid
<< 1) || r
->orig_arfcn_lo
;
1780 f
[orig
].mask
|= frqt
;
1781 for (i
= 1; 2 + (i
>> 3) < len
; i
++)
1782 if ((cd
[2 + (i
>> 3)] & (0x80 >> (i
& 7))))
1783 f
[(orig
+ 1) % 1024].mask
|= frqt
;
1790 /* decode "Cell Options (BCCH)" (10.5.2.3) */
1791 static int gsm48_decode_cell_sel_param(struct gsm48_sysinfo
*s
, struct gsm48_cell_sel_par
*cs
)
1793 s
->radio_link_timeout
= (cs
->radio_link_timeout
+ 1) * 4;
1798 /* decode "Cell Options (BCCH)" (10.5.2.3) */
1799 static int gsm48_decode_cellopt(struct gsm48_sysinfo
*s
, struct gsm48_cell_options
*co
)
1801 s
->ms_txpwr_max_ccch
= co
->ms_txpwr_max_ccch
;
1802 s
->cell_resel_hyst_db
= co
->cell_resel_hyst
* 2;
1803 s
->rxlev_acc_min_db
= co
->rxlev_acc_min
- 110;
1808 /* decode "Cell Channel Description" (10.5.2.11) */
1809 static int gsm48_decode_ccd(struct gsm48_sysinfo
*s
, struct gsm48_control_channel_desc
*cc
)
1811 s
->ccch_conf
= cc
->ccch_conf
;
1812 s
->bs_ag_blks_res
= cc
->bs_ag_blks_res
;
1813 s
->att_allowed
= cc
->att
;
1814 s
->pag_mf_periods
= cc
->bs_pa_mfrms
+ 2;
1815 s
->t3212
= cc
->t3212
* 360; /* convert deci-hours to seconds */
1818 /* Rach Control decode tables */
1819 static uint8_t gsm48_max_retrans
[4] = {
1822 static uint8_t gsm48_tx_integer
[16] = {
1823 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 25, 32, 50
1826 /* decode "RACH Control Parameter" (10.5.2.29) */
1827 static int gsm48_decode_rach_ctl_param(struct gsm48_sysinfo
*s
, struct gsm48_rach_ctl
*rc
)
1831 s
->reest_denied
= rc
->re
;
1832 s
->cell_barred
= rc
->cell_barr
;
1833 s
->tx_integer
= gsm48_tx_integer
[rc
->tx_int
];
1834 s
->max_retrans
= gsm48_max_retrans
[rc
->max_retr
];
1835 for (i
= 0, i
<= 15, i
++)
1836 if ((rc
->ac
[1 - (i
>> 3)] & (1 << (i
& 7))))
1837 s
->class_barr
[i
] = 1;
1839 s
->class_barr
[i
] = 0;
1843 static int gsm48_decode_rach_ctl_neigh(struct gsm48_sysinfo
*s
, struct gsm48_rach_ctl
*rc
)
1847 s
->nb_reest_denied
= rc
->re
;
1848 s
->nb_cell_barred
= rc
->cell_barr
;
1849 s
->nb_tx_integer
= gsm48_tx_integer
[rc
->tx_int
];
1850 s
->nb_max_retrans
= gsm48_max_retrans
[rc
->max_retr
];
1851 for (i
= 0, i
<= 15, i
++)
1852 if ((rc
->ac
[1 - (i
>> 3)] & (1 << (i
& 7))))
1853 s
->nb_class_barr
[i
] = 1;
1855 s
->nb_class_barr
[i
] = 0;
1860 /* decode "SI 1 Rest Octets" (10.5.2.32) */
1861 static int gsm48_decode_si1_rest(struct gsm48_sysinfo
*s
, uint8_t *si
, uint8_t len
)
1865 /* decode "SI 3 Rest Octets" (10.5.2.34) */
1866 static int gsm48_decode_si3_rest(struct gsm48_sysinfo
*s
, uint8_t *si
, uint8_t len
)
1871 todo
: add to unit data ind
switch-case state
1872 /* receive "SYSTEM INFORMATION 1" message (9.1.31) */
1873 static int gsm_rr_rx_sysinfo1(struct osmocom_ms
*ms
, struct msgb
*msg
)
1875 struct gsm48_system_information_type_1
*si
= msgb_l3(msg
);
1876 struct gsm48_sysinfo
*s
= ms
->sysinfo
;
1877 int payload_len
= msgb_l3len(msg
) - sizeof(*si
);
1879 if (payload_len
< 0) {
1880 DEBUGP(DRR
, "Short read of SYSTEM INFORMATION 1 message.\n");
1883 /* Cell Channel Description */
1884 gsm48_decode_freq_list(s
->freq
, si
->cell_channel_description
,
1885 sizeof(si
->cell_channel_description
), 0xce, FREQ_TYPE_SERV
);
1886 /* RACH Control Parameter */
1887 gsm48_decode_rach_ctl_param(s
, si
->rach_control
);
1888 /* SI 1 Rest Octets */
1890 gsm48_decode_si1_rest(si
->rest_octets
, payload_len
);
1896 todo
: add to unit data ind
switch-case state
1897 /* receive "SYSTEM INFORMATION 2" message (9.1.32) */
1898 static int gsm_rr_rx_sysinfo2(struct osmocom_ms
*ms
, struct msgb
*msg
)
1900 struct gsm48_system_information_type_2
*si
= msgb_l3(msg
);
1901 struct gsm48_sysinfo
*s
= ms
->sysinfo
;
1902 int payload_len
= msgb_l3len(msg
) - sizeof(*si
);
1904 if (payload_len
< 0) {
1905 DEBUGP(DRR
, "Short read of SYSTEM INFORMATION 2 message.\n");
1908 /* Neighbor Cell Description */
1909 gsm48_decode_freq_list(s
->freq
, si
->bcch_frequency_list
,
1910 sizeof(si
->bcch_frequency_list
), 0xce, FREQ_TYPE_NCELL
);
1912 s
->ncc_permitted
= si
->ncc_permitted
;
1913 /* RACH Control Parameter */
1914 gsm48_decode_rach_ctl_neigh(s
, si
->rach_control
);
1920 todo
: add to unit data ind
switch-case state
1921 /* receive "SYSTEM INFORMATION 2bis" message (9.1.33) */
1922 static int gsm_rr_rx_sysinfo2bis(struct osmocom_ms
*ms
, struct msgb
*msg
)
1924 struct gsm48_system_information_type_2bis
*si
= msgb_l3(msg
);
1925 struct gsm48_sysinfo
*s
= ms
->sysinfo
;
1926 int payload_len
= msgb_l3len(msg
) - sizeof(*si
);
1928 if (payload_len
< 0) {
1929 DEBUGP(DRR
, "Short read of SYSTEM INFORMATION 2bis message.\n");
1932 /* Neighbor Cell Description */
1933 s
->ext_ind
= (si
->bcch_frequency_list
[0] >> 6) & 1;
1934 s
->ba_ind
= (si
->bcch_frequency_list
[0] >> 5) & 1;
1935 gsm48_decode_freq_list(s
->freq
, si
->ext_bcch_frequency_list
,
1936 sizeof(si
->ext_bcch_frequency_list
), 0x8e, FREQ_TYPE_NCELL
);
1937 /* RACH Control Parameter */
1938 gsm48_decode_rach_ctl_neigh(s
, si
->rach_control
);
1944 todo
: add to unit data ind
switch-case state
1945 /* receive "SYSTEM INFORMATION 2ter" message (9.1.34) */
1946 static int gsm_rr_rx_sysinfo2ter(struct osmocom_ms
*ms
, struct msgb
*msg
)
1948 struct gsm48_system_information_type_2ter
*si
= msgb_l3(msg
);
1949 struct gsm48_sysinfo
*s
= ms
->sysinfo
;
1950 int payload_len
= msgb_l3len(msg
) - sizeof(*si
);
1952 if (payload_len
< 0) {
1953 DEBUGP(DRR
, "Short read of SYSTEM INFORMATION 2ter message.\n");
1956 /* Neighbor Cell Description 2 */
1957 s
->multi_rep
= (si
->bcch_frequency_list
[0] >> 6) & 3;
1958 gsm48_decode_freq_list(s
->freq
, si
->ext_bcch_frequency_list
,
1959 sizeof(si
->ext_bcch_frequency_list
), 0x8e, FREQ_TYPE_NCELL
);
1964 todo
: add to unit data ind
switch-case state
1965 /* receive "SYSTEM INFORMATION 3" message (9.1.35) */
1966 static int gsm_rr_rx_sysinfo3(struct osmocom_ms
*ms
, struct msgb
*msg
)
1968 struct gsm48_system_information_type_3
*si
= msgb_l3(msg
);
1969 struct gsm48_sysinfo
*s
= ms
->sysinfo
;
1970 int payload_len
= msgb_l3len(msg
) - sizeof(*si
);
1972 if (payload_len
< 0) {
1973 DEBUGP(DRR
, "Short read of SYSTEM INFORMATION 3 message.\n");
1977 s
->cell_identity
= ntohl(si
->cell_identity
);
1979 gsm48_decode_lai(si
->lai
, s
->mcc
, s
->mnc
, s
->lac
);
1980 /* Control Channel Description */
1981 gsm48_decode_ccd(s
, si
->control_channel_desc
);
1982 /* Cell Options (BCCH) */
1983 gsm48_decode_cellopt(s
, si
->control_channel_desc
);
1984 /* Cell Selection Parameters */
1985 gsm48_decode_cell_sel_param(s
, si
->cell_sel_par
);
1986 /* RACH Control Parameter */
1987 gsm48_decode_rach_ctl_param(s
, si
->rach_control
);
1988 /* SI 1 Rest Octets */
1989 if (payload_len
>= 4)
1990 gsm48_decode_si3_rest(si
->rest_octets
, payload_len
);
1995 todo
: add to unit data ind
switch-case state
1996 /* receive "SYSTEM INFORMATION 4" message (9.1.36) */
1997 static int gsm_rr_rx_sysinfo4(struct osmocom_ms
*ms
, struct msgb
*msg
)
1999 struct gsm48_system_information_type_4
*si
= msgb_l3(msg
);
2000 struct gsm48_sysinfo
*s
= ms
->sysinfo
;
2001 int payload_len
= msgb_l3len(msg
) - sizeof(*si
);
2003 if (payload_len
< 0) {
2004 DEBUGP(DRR
, "Short read of SYSTEM INFORMATION 4 message.\n");
2008 gsm48_decode_lai(si
->lai
, s
->mcc
, s
->mnc
, s
->lac
);
2009 /* Cell Selection Parameters */
2010 gsm48_decode_cell_sel_param(s
, si
->cell_sel_par
);
2011 /* RACH Control Parameter */
2012 gsm48_decode_rach_ctl_param(s
, si
->rach_control
);
2013 /* CBCH Channel Description */
2014 if (payload_len
>= 4 && si
->data
[0] == GSM48_IE_CBCH_CHAN_DES
) {
2015 memcpy(&s
->chan_desc
, si
->data
+ 1, sizeof(s
->chan_desc
));
2016 /* CBCH Mobile Allocation */
2017 if (payload_len
>= 6 && si
->data
[4] == GSM48_IE_CBCH_MOB_ALLOC
)
2018 && payload_len
>= 6 + si
->data
[5])
2019 gsm48_decode_mobile_alloc(&ma
, si
->data
+ 5);
2022 /* Cell Options (BCCH) */
2023 gsm48_decode_cellopt(s
, si
->control_channel_desc
);
2024 /* SI 1 Rest Octets */
2025 if (payload_len
>= 4)
2026 gsm48_decode_si3_rest(si
->rest_octets
, payload_len
);
2031 today
: decode mobile alloc
1-8 binary masks
2038 add support structure
2039 initialize support structure
2041 queue
messages (rslms_data_req
) if channel changes
2043 flush rach msg in all cases
: during sending
, after its done
, and when aborted
2044 stop timers on abort
2045 debugging
. (wenn dies todo erledigt ist
, bitte in den anderen code moven
)
2046 wird beim abbruch immer der gepufferte cm
-service
-request entfernt
, auch beim verschicken
?:
2048 todo rr_sync_ind when receiving ciph
, re ass
, channel mode modify
2050 todo change procedures
, release procedure
2052 during procedures
, like
"channel assignment" or "handover", rr requests must be queued
2053 they must be dequeued when complete
2054 they queue must be flushed when rr fails
2056 #include <osmocore/protocol/gsm_04_08.h>
2057 #include <osmocore/msgb.h>
2058 #include <osmocore/gsm48.h>
2060 static struct rr_names
{
2064 { "RR_EST_REQ", RR_EST_REQ
},
2065 { "RR_EST_IND", RR_EST_IND
},
2066 { "RR_EST_CNF", RR_EST_CNF
},
2067 { "RR_REL_IND", RR_REL_IND
},
2068 { "RR_SYNC_IND", RR_SYNC_IND
},
2069 { "RR_DATA_REQ", RR_DATA_REQ
},
2070 { "RR_DATA_IND", RR_DATA_IND
},
2071 { "RR_UNIT_DATA_IND", RR_UNIT_DATA_IND
},
2072 { "RR_ABORT_REQ", RR_ABORT_REQ
},
2073 { "RR_ABORT_IND", RR_ABORT_IND
},
2074 { "RR_ACT_REQ", RR_ACT_REQ
},
2079 char *get_rr_name(int value
)
2083 for (i
= 0; rr_names
[i
].name
; i
++) {
2084 if (rr_names
[i
].value
== value
)
2085 return rr_names
[i
].name
;
2088 return "RR_Unknown";
2091 static int rr_rcvmsg(struct osmocom_ms
*ms
,
2092 int msg_type
, struct gsm_mncc
*rrmsg
)
2096 DEBUGP(DRR
, "(MS %s) Sending '%s' to MM.\n", ms
->name
,
2097 get_rr_name(msg_type
));
2099 rrmsg
->msg_type
= msg_type
;
2101 msg
= msgb_alloc(sizeof(struct gsm_rr
), "RR");
2104 memcpy(msg
->data
, rrmsg
, sizeof(struct gsm_rr
));
2105 msgb_enqueue(&ms
->rr
.upqueue
, msg
);
2110 static int gsm_rr_abort_req(struct osmocom_ms
*ms
, struct gsm_rr
*rrmsg
)
2112 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
2114 if (rr
->state
== GSM_RRSTATE_DEDICATED
) {
2115 struct gsm_dl dlmsg
;
2117 memset(&dlmsg
, 0, sizeof(dlmsg
));
2118 return gsm_send_dl(ms
, DL_RELEASE_REQ
, dlmsg
);
2120 new_rr_state(rr
, GSM_RRSTATE_IDLE
);
2123 static int gsm_rr_act_req(struct osmocom_ms
*ms
, struct gsm_rr
*rrmsg
)
2127 /* state trasitions for radio ressource messages (upper layer) */
2128 static struct rrdownstate
{
2131 int (*rout
) (struct osmocom_ms
*ms
, struct gsm_dl
*rrmsg
);
2132 } rrdownstatelist
[] = {
2133 {SBIT(GSM_RRSTATE_IDLE
), /* 3.3.1.1 */
2134 RR_EST_REQ
, gsm_rr_est_req
},
2135 {SBIT(GSM_RRSTATE_DEDICATED
), /* 3.4.2 */
2136 RR_DATA_REQ
, gsm_rr_data_req
},
2137 {SBIT(GSM_RRSTATE_CONN_PEND
) | SBIT(GSM_RRSTATE_DEDICATED
),
2138 RR_ABORT_REQ
, gsm_rr_abort_req
},
2139 {SBIT(GSM_RRSTATE_DEDICATED
),
2140 RR_ACT_REQ
, gsm_rr_act_req
},
2143 #define RRDOWNSLLEN \
2144 (sizeof(rrdownstatelist) / sizeof(struct rrdownstate))
2146 static int gsm_send_rr(struct osmocom_ms
*ms
, struct gsm_rr
*msg
)
2148 struct gsm_mm_hdr
*mmh
= msgb
->data
;
2149 int msg_type
= mmh
->msg_type
;
2151 DEBUGP(DRR
, "(ms %s) Sending '%s' to DL in state %s\n", ms
->name
,
2152 gsm0408_rr_msg_names
[msg_type
], mm_state_names
[mm
->state
]);
2154 /* find function for current state and message */
2155 for (i
= 0; i
< RRDOWNSLLEN
; i
++)
2156 if ((msg_type
== rrdownstatelist
[i
].type
)
2157 && ((1 << mm
->state
) & rrdownstatelist
[i
].states
))
2159 if (i
== RRDOWNSLLEN
) {
2160 DEBUGP(DRR
, "Message unhandled at this state.\n");
2164 rc
= rrdownstatelist
[i
].rout(ms
, dlmsg
);
2166 /* free msgb uless it is forwarded */
2167 if (rrdownstatelist
[i
].rout
!= gsm_rr_data_req
)
2174 /* channel description */
2175 rsl_dec_chan_nr(aa
->chan_desc
.chan_nr
, &ch_type
, &ch_subch
, &ch_ts
);
2176 h
= aa
->chan_desc
.h0
.h
;
2178 rsl_dec_chan_h1(&aa
->chan_desc
, &tsc
, &maio
, &hsn
);
2180 rsl_dec_chan_h0(&aa
->chan_desc
, &tsc
, &arfcn
);
2181 /* mobile allocation */
2183 if (!TLVP_PRESENT(&tp
, GSM48_IE_MOBILE_ALLOC
))
2184 return gsm_rr_tx_rr_status(ms
, ...);
2185 gsm48_decode_mobile_alloc(&ma
,
2186 TLVP_VAL(&tp
, GSM48_IE_MOBILE_ALLOC
)-1);
2189 if (TLVP_PRESENT(&tp
, GSM48_IE_START_TIME
)) {
2190 gsm48_decode_start_time(&frame
,
2191 TLVP_VAL(&tp
, GSM48_IE_START_TIME
)-1);
2196 /* memcopy of LV of given IE from tlv_parsed structure */
2197 static int tlv_copy(void *dest
, int dest_len
, struct tlv_parsed
*tp
, uint8_t ie
)
2206 if (!TLVP_PRESENT(tp
, ie
))
2209 len
= TLVP_LEN(tp
, ie
);
2212 if (len
+ 1 > dest_len
)
2215 memcpy(dest
, TLVP_VAL(tp
, ie
) - 1, len
+ 1);
2219 - flush
/send when leaving
this state (or completion
or if back on old channel
)
2220 static int gsm_rr_rx_ass_cmd(struct osmocom_ms
*ms
, struct msgb
*msg
)
2222 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
2223 struct gsm48_hdr
*gh
= msgb_l3(msg
);
2224 struct gsm48_ass_cmd
*ac
= (struct gsm48_ass_cmd
*)gh
->data
;
2225 int payload_len
= msgb_l3len(msg
) - sizeof(*gh
) - sizeof(*ac
);
2226 struct tlv_parsed tp
;
2227 struct gsm_rr_chan_desc cd
;
2229 memset(&cd
, 0, sizeof(cd
));
2231 if (payload_len
< 0) {
2232 DEBUGP(DRR
, "Short read of ASSIGNMENT COMMAND message.\n");
2233 return gsm_rr_tx_rr_status(ms
, GSM48_RR_CAUSE_PROT_ERROR_UNSPC
);
2235 tlv_parse(&tp
, &rsl_att_tlvdef
, ac
->data
, payload_len
, 0, 0);
2237 /* channel description */
2238 memcpy(&cd
.chan_desc
, &ac
->chan_desc
, sizeof(chan_desc
));
2240 cd
.power_command
= ac
->power_command
;
2241 /* frequency list, after timer */
2242 tlv_copy(&cd
.fl
, sizeof(fl_after
), &tp
, GSM48_IE_FRQLIST_AFTER
);
2243 /* cell channel description */
2244 tlv_copy(&cd
.ccd
, sizeof(ccd
), &tp
, GSM48_IE_CELL_CH_DESC
);
2245 /* multislot allocation */
2246 tlv_copy(&cd
.multia
, sizeof(ma
), &tp
, GSM48_IE_MSLOT_DESC
);
2248 tlv_copy(&cd
.chanmode
, sizeof(chanmode
), &tp
, GSM48_IE_CHANMODE_1
);
2249 /* mobile allocation, after time */
2250 tlv_copy(&cd
.moba_after
, sizeof(moba_after
), &tp
, GSM48_IE_MOB_AL_AFTER
);
2252 tlv_copy(&cd
.start
, sizeof(start
), &tp
, GSM_IE_START_TIME
);
2253 /* frequency list, before time */
2254 tlv_copy(&cd
.fl_before
, sizeof(fl_before
), &tp
, GSM48_IE_FRQLIST_BEFORE
);
2255 /* channel description, before time */
2256 tlv_copy(&cd
.chan_desc_before
, sizeof(cd_before
), &tp
, GSM48_IE_CHDES_1_BEFORE
);
2257 /* frequency channel sequence, before time */
2258 tlv_copy(&cd
.fcs_before
, sizeof(fcs_before
), &tp
, GSM48_IE_FRQSEQ_BEFORE
);
2259 /* mobile allocation, before time */
2260 tlv_copy(&cd
.moba_before
, sizeof(moba_before
), &tp
, GSM48_IE_MOB_AL_BEFORE
);
2261 /* cipher mode setting */
2262 if (TLVP_PRESENT(&tp
, GSM48_IE_CIP_MODE_SET
))
2263 cd
.cipher
= *TLVP_VAL(&tp
, GSM48_IE_CIP_MODE_SET
);
2268 DEBUGP(DRR
, "No current cell allocation available.\n");
2269 return gsm_rr_tx_rr_status(ms
, GSM48_RR_CAUSE_NO_CELL_ALLOC_A
);
2272 if (not supported
) {
2273 DEBUGP(DRR
, "New channel is not supported.\n");
2274 return gsm_rr_tx_rr_status(ms
, RR_CAUSE_CHAN_MODE_UNACCEPT
);
2277 if (freq
not supported
) {
2278 DEBUGP(DRR
, "New frequency is not supported.\n");
2279 return gsm_rr_tx_rr_status(ms
, RR_CAUSE_FREQ_NOT_IMPLEMENTED
);
2282 /* store current channel descriptions, to return in case of failure */
2283 memcpy(&rr
->chan_last
, &rr
->chan_desc
, sizeof(*cd
));
2284 /* copy new description */
2285 memcpy(&rr
->chan_desc
, cd
, sizeof(cd
));
2287 /* start suspension of current link */
2288 newmsg
= gsm48_rr_msgb_alloc();
2291 rslms_tx_rll_req_l3(ms
, RSL_MT_SUSP_REQ
, rr
->chan_desc
.chan_nr
, 0, msg
);
2293 /* change into special assignment suspension state */
2294 rr
->assign_susp_state
= 1;
2295 rr
->resume_last_state
= 0;
2300 - queue messages during
this state
2301 - flush
/send when leaving
this state
2302 static int gsm_rr_rx_hando_cmd(struct osmocom_ms
*ms
, struct msgb
*msg
)
2304 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
2305 struct gsm48_hdr
*gh
= msgb_l3(msg
);
2306 int payload_len
= msgb_l3len(msg
) - sizeof(*gh
);
2312 /* change into special handover suspension state */
2313 rr
->hando_susp_state
= 1;
2314 rr
->resume_last_state
= 0;
2317 static int gsm_rr_rx_hando_cmd(struct osmocom_ms
*ms
, struct msgb
*msg
)
2319 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
2320 struct gsm48_hdr
*gh
= msgb_l3(msg
);
2321 int payload_len
= msgb_l3len(msg
) - sizeof(*gh
);
2323 static int gsm_rr_estab_cnf_dedicated(struct osmocom_ms
*ms
, struct msgb
*msg
)
2325 if (rr
->hando_susp_state
|| rr
->assign_susp_state
) {
2326 if (rr
->resume_last_state
) {
2327 rr
->resume_last_state
= 0;
2328 gsm_rr_tx_ass_cpl(ms
, cause
);
2329 flush queued radio ressource messages
2333 gsm_rr_tx_ass_fail(ms
, RR_CAUSE_PROTO_ERR_UNSPEC
);
2339 static int gsm_rr_connect_cnf(struct osmocom_ms
*ms
, struct msgbl
*msg
)
2343 static int gsm_rr_rel_ind(struct osmocom_ms
*ms
, struct msgb
*msg
)
2347 static int gsm_rr_rel_cnf_dedicated(struct osmocom_ms
*ms
, struct msgb
*msg
)
2349 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
2351 if (rr
->hando_susp_state
|| rr
->assign_susp_state
) {
2354 /* change radio to new channel */
2355 tx_ph_dm_est_req(ms
, arfcn
, rr
->chan_desc
.chan_desc
.chan_nr
);
2357 newmsg
= gsm48_rr_msgb_alloc();
2360 /* send DL-ESTABLISH REQUEST */
2361 rslms_tx_rll_req_l3(ms
, RSL_MT_EST_REQ
, rr
->chan_desc
.chan_desc
.chan_nr
, 0, newmsg
);
2364 if (rr
->hando_susp_state
) {
2365 send HANDOVER ACCESS via DL_RANDOM_ACCESS_REQ
2366 rr
->hando_acc_left
= 3;
2371 static int gsm_rr_mdl_error_ind(struct osmocom_ms
*ms
, struct msgb
*msg
)
2373 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
2374 struct msgb
*newmsg
;
2375 struct gsm_mm_hdr
*newmmh
;
2377 if (rr
->hando_susp_state
|| rr
->assign_susp_state
) {
2378 if (!rr
->resume_last_state
) {
2379 rr
->resume_last_state
= 1;
2381 /* get old channel description */
2382 memcpy(&rr
->chan_desc
, &rr
->chan_last
, sizeof(*cd
));
2384 /* change radio to old channel */
2385 tx_ph_dm_est_req(ms
, arfcn
, rr
->chan_desc
.chan_desc
.chan_nr
);
2389 rr
->resume_last_state
= 0;
2392 /* deactivate channel */
2393 tx_ph_dm_rel_req(ms
, arfcn
, rr
->chan_desc
.chan_desc
.chan_nr
);
2395 /* send abort ind to upper layer */
2396 newmsg
= gsm48_mm_msgb_alloc();
2400 newmmh
= (struct gsm_mm_hdr
*)newmsg
->data
;
2401 newmmh
->msg_type
= RR_ABORT_IND
;
2402 newmmh
->cause
= GSM_MM_CAUSE_LINK_FAILURE
;
2403 return rr_rcvmsg(ms
, msg
);
2406 /* state trasitions for link layer messages (lower layer) */
2407 static struct dldatastate
{
2410 int (*rout
) (struct osmocom_ms
*ms
, struct gsm_dl
*dlmsg
);
2411 } dldatastatelist
[] = {
2412 {SBIT(GSM_RRSTATE_IDLE
) | SBIT(GSM_RRSTATE_CONN_PEND
),
2413 DL_UNIT_DATA_IND
, gsm_rr_unit_data_ind
},
2414 {SBIT(GSM_RRSTATE_DEDICATED
), /* 3.4.2 */
2415 DL_DATA_IND
, gsm_rr_data_ind
},
2416 {SBIT(GSM_RRSTATE_IDLE
) | SBIT(GSM_RRSTATE_CONN_PEND
),
2417 DL_ESTABLISH_CNF
, gsm_rr_estab_cnf
},
2418 {SBIT(GSM_RRSTATE_DEDICATED
),
2419 DL_ESTABLISH_CNF
, gsm_rr_estab_cnf_dedicated
},
2421 DL_CONNECT_CNF
, gsm_rr_connect_cnf
},
2423 DL_RELEASE_IND
, gsm_rr_rel_ind
},
2424 {SBIT(GSM_RRSTATE_IDLE
) | SBIT(GSM_RRSTATE_CONN_PENDING
),
2425 DL_RELEASE_CNF
, gsm_rr_rel_cnf
},
2426 {SBIT(GSM_RRSTATE_DEDICATED
),
2427 DL_RELEASE_CNF
, gsm_rr_rel_cnf_dedicated
},
2428 {SBIT(GSM_RRSTATE_CONN_PEND
), /* 3.3.1.1.2 */
2429 DL_RANDOM_ACCESS_CNF
, gsm_rr_rand_acc_cnf
},
2430 {SBIT(GSM_RRSTATE_DEDICATED
),
2431 DL_RANDOM_ACCESS_CNF
, gsm_rr_rand_acc_cnf_dedicated
},
2433 MDL_ERROR_IND
, gsm_rr_mdl_error_ind
},
2436 #define DLDATASLLEN \
2437 (sizeof(dldatastatelist) / sizeof(struct dldatastate))
2439 static int gsm_rcv_dl(struct osmocom_ms
*ms
, struct gsm_dl
*dlmsg
)
2441 int msg_type
= dlmsg
->msg_type
;
2443 DEBUGP(DRR
, "(ms %s) Received '%s' from DL in state %s\n", ms
->name
,
2444 gsm0408_dl_msg_names
[msg_type
], mm_state_names
[mm
->state
]);
2446 /* find function for current state and message */
2447 for (i
= 0; i
< DLDATASLLEN
; i
++)
2448 if ((msg_type
== dldatastatelist
[i
].type
)
2449 && ((1 << mm
->state
) & dldatastatelist
[i
].states
))
2451 if (i
== DLDATASLLEN
) {
2452 DEBUGP(DRR
, "Message unhandled at this state.\n");
2456 rc
= dldatastatelist
[i
].rout(ms
, dlmsg
);
2458 /* free msgb uless it is forwarded */
2459 if (dldatastatelist
[i
].rout
!= gsm_rr_data_ind
)
2465 static void timeout_rr_t3124(void *arg
)
2467 struct gsm_rrlayer
*rr
= arg
;
2472 struct gsm_rrlayer
*gsm_new_rr(struct osmocom_ms
*ms
)
2474 struct gsm_rrlayer
*rr
;
2476 rr
= calloc(1, sizeof(struct gsm_rrlayer
));
2488 void gsm_destroy_rr(struct gsm_rrlayer
*rr
)
2494 alle timer gestoppt
?:
2495 todo stop t3122 when cell change
2497 memset(rr
, 0, sizeof(struct gsm_rrlayer
));
2503 /* send next channel request in dedicated state */
2504 static int gsm_rr_rand_acc_cnf_dedicated(struct osmocom_ms
*ms
, struct msgb
*msg
)
2506 struct gsm_rrlayer
*rr
= ms
->rrlayer
;
2507 struct msgb
*newmsg
;
2510 if (!rr
->hando_susp_state
) {
2511 DEBUGP(DRR
, "Random acces confirm, but not in handover state.\n");
2515 /* send up to four handover access bursts */
2516 if (rr
->hando_acc_left
) {
2517 rr
->hando_acc_left
--;
2518 send HANDOVER ACCESS via DL_RANDOM_ACCESS_REQ
;
2522 if (!timer
3124 running
) {
2523 if (allocated channel is SDCCH
)
2524 start_rr_t3124(rr
, GSM_T3124_675
);
2526 start_rr_t3124(rr
, GSM_T3124_320
);
2527 if (!rr
->n_chan_req
) {
2528 start_rr_t3126(rr
, GSM_T3126_MS
);
2534 switch(ms
->si
.tx_integer
) {
2535 case 3: case 8: case 14: case 50:
2536 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
2540 case 4: case 9: case 16:
2541 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
2545 case 5: case 10: case 20:
2546 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
2550 case 6: case 11: case 25:
2551 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
2556 if (ms
->si
.bcch_type
== GSM_NON_COMBINED_CCCH
)
2561 /* resend chan_req */
2562 newmsg
= msgb_alloc_headroom(20, 16, "CHAN_REQ");
2565 *msgb_put(newmsg
, 1) = rr
->chan_req
;
2566 *msgb_put(newmsg
, 1) = (random() % ms
->si
.tx_integer
) + s
; /* delay */
2567 rr
->cr_hist
[3] = rr
->cr_hist
[2];
2568 rr
->cr_hist
[2] = rr
->cr_hist
[1];
2569 rr
->cr_hist
[1] = chan_req
;
2570 return rslms_tx_rll_req_l3(ms
, RSL_MT_RAND_ACC_REQ
, chan_nr
, 0, newmsg
);