1 #warning rr on MDL error handling (as specified in 04.08 / 04.06)
3 * (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /* Very short description of some of the procedures:
25 * A radio ressource request causes sendig a channel request on RACH.
26 * After receiving of an immediate assignment the link will be establised.
27 * After the link is established, the dedicated mode is entered and confirmed.
29 * A Paging request also triggers the channel request as above...
30 * After the link is established, the dedicated mode is entered and indicated.
32 * During dedicated mode, messages are transferred.
34 * When an assignment command or a handover command is received, the current
35 * link is released. After release, the new channel is activated and the
36 * link is established again. After link is establised, pending messages from
37 * radio ressource are sent.
39 * When the assignment or handover fails, the old channel is activate and the
40 * link is established again. Also pending messages are sent.
49 #include <arpa/inet.h>
51 #include <osmocore/msgb.h>
52 #include <osmocore/utils.h>
53 #include <osmocore/rsl.h>
54 #include <osmocore/gsm48.h>
55 #include <osmocore/bitvec.h>
57 #include <osmocom/bb/common/osmocom_data.h>
58 #include <osmocom/bb/common/l1l2_interface.h>
59 #include <osmocom/bb/common/logging.h>
60 #include <osmocom/bb/common/networks.h>
61 #include <osmocom/bb/common/l1ctl.h>
62 #include <osmocom/bb/mobile/vty.h>
64 static void start_rr_t_monitor(struct gsm48_rrlayer *rr, int sec, int micro);
65 static void stop_rr_t_monitor(struct gsm48_rrlayer *rr);
66 static int gsm48_rcv_rsl(struct osmocom_ms *ms, struct msgb *msg);
67 static int gsm48_rr_dl_est(struct osmocom_ms *ms);
73 #define MIN(a, b) ((a < b) ? a : b)
75 int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc,
76 uint16_t *mnc, uint16_t *lac)
78 *mcc = ((lai->digits[0] & 0x0f) << 8)
79 | (lai->digits[0] & 0xf0)
80 | (lai->digits[1] & 0x0f);
81 *mnc = ((lai->digits[2] & 0x0f) << 8)
82 | (lai->digits[2] & 0xf0)
83 | ((lai->digits[1] & 0xf0) >> 4);
84 *lac = ntohs(lai->lac);
89 static int gsm48_encode_chan_h0(struct gsm48_chan_desc *cd, uint8_t tsc,
94 cd->h0.arfcn_low = arfcn & 0xff;
95 cd->h0.arfcn_high = arfcn >> 8;
100 static int gsm48_encode_chan_h1(struct gsm48_chan_desc *cd, uint8_t tsc,
101 uint8_t maio, uint8_t hsn)
105 cd->h1.maio_low = maio & 0x03;
106 cd->h1.maio_high = maio >> 2;
113 static int gsm48_decode_chan_h0(struct gsm48_chan_desc *cd, uint8_t *tsc,
117 *arfcn = cd->h0.arfcn_low | (cd->h0.arfcn_high << 8);
122 static int gsm48_decode_chan_h1(struct gsm48_chan_desc *cd, uint8_t *tsc,
123 uint8_t *maio, uint8_t *hsn)
126 *maio = cd->h1.maio_low | (cd->h1.maio_high << 2);
132 /* 10.5.2.38 decode Starting time IE */
133 static int gsm48_decode_start_time(struct gsm48_rr_cd *cd,
134 struct gsm48_start_time *st)
136 cd->start_t1 = st->t1;
137 cd->start_t2 = st->t2;
138 cd->start_t3 = (st->t3_high << 3) | st->t3_low;
143 /* decode "BA Range" (10.5.2.1a) */
144 static int gsm48_decode_ba_range(const uint8_t *ba, uint8_t ba_len,
145 uint32_t *range, uint8_t *ranges, int max_ranges)
147 /* ba = pointer to IE without IE type and length octets
148 * ba_len = number of octets
149 * range = pointer to store decoded range
150 * ranges = number of ranges decoded
151 * max_ranges = maximum number of decoded ranges that can be stored
153 uint16_t lower, higher;
154 int i, n, required_octets;
156 /* find out how much ba ranges will be decoded */
159 required_octets = 5 * (n >> 1) + 3 * (n & 1);
160 if (required_octets > ba_len) {
161 LOGP(DRR, LOGL_NOTICE, "BA range IE too short: %d ranges "
162 "require %d octets, but only %d octets remain.\n",
163 n, required_octets, ba_len);
168 LOGP(DRR, LOGL_NOTICE, "BA range %d exceed the maximum number "
169 "of ranges supported by this mobile (%d).\n",
174 for (i = 0; i < n; i++) {
176 /* decode even range number */
179 higher = (*ba++ & 0x3f) << 4;
182 lower = (*ba++ & 0x0f) << 6;
184 higher = (*ba++ & 0x03) << 8;
186 /* decode odd range number */
188 *range++ = (higher << 16) | lower;
195 /* 3.1.4.3 set sequence number and increment */
196 static int gsm48_apply_v_sd(struct gsm48_rrlayer *rr, struct msgb *msg)
198 struct gsm48_hdr *gh = msgb_l3(msg);
199 uint8_t pdisc = gh->proto_discr & 0x0f;
205 case GSM48_PDISC_NC_SS:
206 /* all thre pdiscs share the same V(SD) */
207 pdisc = GSM48_PDISC_MM;
209 case GSM48_PDISC_GROUP_CC:
210 case GSM48_PDISC_BCAST_CC:
211 case GSM48_PDISC_PDSS1:
212 case GSM48_PDISC_PDSS2:
213 /* extract v_sd(pdisc) */
214 v_sd = (rr->v_sd >> pdisc) & 1;
216 /* replace bit 7 vy v_sd */
217 gh->msg_type &= 0xbf;
218 gh->msg_type |= (v_sd << 6);
220 /* increment V(SD) */
221 rr->v_sd ^= (1 << pdisc);
222 LOGP(DRR, LOGL_INFO, "Using and incrementing V(SD) = %d "
223 "(pdisc %x)\n", v_sd, pdisc);
226 case GSM48_PDISC_SMS:
227 /* no V(VSD) is required */
230 LOGP(DRR, LOGL_ERROR, "Error, V(SD) of pdisc %x not handled\n",
242 const char *gsm48_rr_state_names[] = {
244 "connection pending",
249 static void new_rr_state(struct gsm48_rrlayer *rr, int state)
251 if (state < 0 || state >=
252 (sizeof(gsm48_rr_state_names) / sizeof(char *)))
255 /* must check against equal state */
256 if (rr->state == state) {
257 LOGP(DRR, LOGL_INFO, "equal state ? %s\n",
258 gsm48_rr_state_names[rr->state]);
262 LOGP(DRR, LOGL_INFO, "new state %s -> %s\n",
263 gsm48_rr_state_names[rr->state], gsm48_rr_state_names[state]);
267 if (state == GSM48_RR_ST_IDLE) {
268 struct msgb *msg, *nmsg;
269 struct gsm322_msg *em;
271 /* release dedicated mode, if any */
272 l1ctl_tx_dm_rel_req(rr->ms);
273 l1ctl_tx_reset_req(rr->ms, L1CTL_RES_T_FULL);
274 /* free establish message, if any */
276 if (rr->rr_est_msg) {
277 msgb_free(rr->rr_est_msg);
278 rr->rr_est_msg = NULL;
280 /* free all pending messages */
281 while((msg = msgb_dequeue(&rr->downqueue)))
283 /* clear all descriptions of last channel */
284 memset(&rr->cd_now, 0, sizeof(rr->cd_now));
287 /* tell cell selection process to return to idle mode
288 * NOTE: this must be sent unbuffered, because it will
289 * leave camping state, so it locks against subsequent
290 * establishment of dedicated channel, before the
291 * cell selection process returned to camping state
292 * again. (after cell reselection)
294 nmsg = gsm322_msgb_alloc(GSM322_EVENT_RET_IDLE);
297 /* return to same cell after LOC.UPD. */
298 if (rr->est_cause == RR_EST_CAUSE_LOC_UPD) {
299 em = (struct gsm322_msg *) nmsg->data;
302 gsm322_c_event(rr->ms, nmsg);
304 /* reset any BA range */
313 /* names of RR-SAP */
314 static const struct value_string gsm48_rr_msg_names[] = {
315 { GSM48_RR_EST_REQ, "RR_EST_REQ" },
316 { GSM48_RR_EST_IND, "RR_EST_IND" },
317 { GSM48_RR_EST_CNF, "RR_EST_CNF" },
318 { GSM48_RR_REL_IND, "RR_REL_IND" },
319 { GSM48_RR_SYNC_IND, "RR_SYNC_IND" },
320 { GSM48_RR_DATA_REQ, "RR_DATA_REQ" },
321 { GSM48_RR_DATA_IND, "RR_DATA_IND" },
322 { GSM48_RR_UNIT_DATA_IND, "RR_UNIT_DATA_IND" },
323 { GSM48_RR_ABORT_REQ, "RR_ABORT_REQ" },
324 { GSM48_RR_ABORT_IND, "RR_ABORT_IND" },
325 { GSM48_RR_ACT_REQ, "RR_ACT_REQ" },
329 const char *get_rr_name(int value)
331 return get_value_string(gsm48_rr_msg_names, value);
334 /* allocate GSM 04.08 layer 3 message */
335 struct msgb *gsm48_l3_msgb_alloc(void)
339 msg = msgb_alloc_headroom(L3_ALLOC_SIZE+L3_ALLOC_HEADROOM,
340 L3_ALLOC_HEADROOM, "GSM 04.08 L3");
343 msg->l3h = msg->data;
348 /* allocate GSM 04.06 layer 2 RSL message */
349 struct msgb *gsm48_rsl_msgb_alloc(void)
353 msg = msgb_alloc_headroom(RSL_ALLOC_SIZE+RSL_ALLOC_HEADROOM,
354 RSL_ALLOC_HEADROOM, "GSM 04.06 RSL");
357 msg->l2h = msg->data;
362 /* allocate GSM 04.08 message (RR-SAP) */
363 struct msgb *gsm48_rr_msgb_alloc(int msg_type)
366 struct gsm48_rr_hdr *rrh;
368 msg = msgb_alloc_headroom(RR_ALLOC_SIZE+RR_ALLOC_HEADROOM,
369 RR_ALLOC_HEADROOM, "GSM 04.08 RR");
373 rrh = (struct gsm48_rr_hdr *) msgb_put(msg, sizeof(*rrh));
374 rrh->msg_type = msg_type;
379 /* queue message (RR-SAP) */
380 int gsm48_rr_upmsg(struct osmocom_ms *ms, struct msgb *msg)
382 struct gsm48_mmlayer *mm = &ms->mmlayer;
384 msgb_enqueue(&mm->rr_upqueue, msg);
389 /* push rsl header and send (RSL-SAP) */
390 static int gsm48_send_rsl(struct osmocom_ms *ms, uint8_t msg_type,
393 struct gsm48_rrlayer *rr = &ms->rrlayer;
399 rsl_rll_push_l3(msg, msg_type, rr->cd_now.chan_nr,
400 rr->cd_now.link_id, 1);
402 return rslms_recvmsg(msg, ms);
405 /* push rsl header + release mode and send (RSL-SAP) */
406 static int gsm48_send_rsl_rel(struct osmocom_ms *ms, uint8_t msg_type,
409 struct gsm48_rrlayer *rr = &ms->rrlayer;
411 rsl_rll_push_hdr(msg, msg_type, rr->cd_now.chan_nr,
412 rr->cd_now.link_id, 1);
414 return rslms_recvmsg(msg, ms);
417 /* enqueue messages (RSL-SAP) */
418 static int gsm48_rx_rsl(struct msgb *msg, struct osmocom_ms *ms)
420 struct gsm48_rrlayer *rr = &ms->rrlayer;
422 msgb_enqueue(&rr->rsl_upqueue, msg);
427 /* dequeue messages (RSL-SAP) */
428 int gsm48_rsl_dequeue(struct osmocom_ms *ms)
430 struct gsm48_rrlayer *rr = &ms->rrlayer;
434 while ((msg = msgb_dequeue(&rr->rsl_upqueue))) {
435 /* msg is freed there */
436 gsm48_rcv_rsl(ms, msg);
437 work = 1; /* work done */
443 int gsm48_rr_start_monitor(struct osmocom_ms *ms)
445 ms->rrlayer.monitor = 1;
446 memset(&ms->meas, 0, sizeof(&ms->meas));
447 start_rr_t_monitor(&ms->rrlayer, 1, 0);
452 int gsm48_rr_stop_monitor(struct osmocom_ms *ms)
454 ms->rrlayer.monitor = 0;
455 memset(&ms->meas, 0, sizeof(&ms->meas));
456 stop_rr_t_monitor(&ms->rrlayer);
465 /* special timer to monitor measurements */
466 static void timeout_rr_monitor(void *arg)
468 struct gsm48_rrlayer *rr = arg;
469 struct gsm322_cellsel *cs = &rr->ms->cellsel;
470 struct rx_meas_stat *meas = &rr->ms->meas;
471 struct gsm_settings *set = &rr->ms->settings;
473 uint8_t ch_type, ch_subch, ch_ts;
477 sprintf(text, "MON: no cell selected");
478 } else if (!meas->frames) {
479 sprintf(text, "MON: no cell info");
481 rxlev = meas->rxlev / meas->frames;
482 berr = meas->berr / meas->frames;
483 sprintf(text, "MON: arfcn=%d lev=%s ber=%2d LAI=%s %s %04x "
484 "ID=%04x", cs->sel_arfcn, gsm_print_rxlev(rxlev),
485 berr, gsm_print_mcc(cs->sel_mcc),
486 gsm_print_mnc(cs->sel_mnc), cs->sel_lac, cs->sel_id);
487 if (rr->state == GSM48_RR_ST_DEDICATED) {
488 rsl_dec_chan_nr(rr->cd_now.chan_nr, &ch_type,
490 sprintf(text + strlen(text), " TA=%d pwr=%d TS=%d",
491 rr->ind_ta - set->alter_delay,
492 (set->alter_tx_power) ? set->alter_tx_power_value
493 : rr->ind_tx_power, ch_ts);
494 if (ch_type == RSL_CHAN_SDCCH8_ACCH
495 || ch_type == RSL_CHAN_SDCCH4_ACCH)
496 sprintf(text + strlen(text), "/%d", ch_subch);
499 vty_notify(rr->ms, "%s\n", text);
501 memset(meas, 0, sizeof(*meas));
502 start_rr_t_monitor(rr, 1, 0);
505 /* special timer to ensure that UA is sent before disconnecting channel */
506 static void timeout_rr_t_rel_wait(void *arg)
508 struct gsm48_rrlayer *rr = arg;
510 LOGP(DRR, LOGL_INFO, "L2 release timer has fired, done waiting\n");
512 /* return to idle now */
513 new_rr_state(rr, GSM48_RR_ST_IDLE);
516 /* 3.4.13.1.1: Timeout of T3110 */
517 static void timeout_rr_t3110(void *arg)
519 struct gsm48_rrlayer *rr = arg;
520 struct osmocom_ms *ms = rr->ms;
524 LOGP(DRR, LOGL_INFO, "timer T3110 has fired, release locally\n");
526 new_rr_state(rr, GSM48_RR_ST_REL_PEND);
528 /* disconnect the main signalling link */
529 nmsg = gsm48_l3_msgb_alloc();
532 mode = msgb_put(nmsg, 2);
533 mode[0] = RSL_IE_RELEASE_MODE;
534 mode[1] = 1; /* local release */
535 gsm48_send_rsl_rel(ms, RSL_MT_REL_REQ, nmsg);
540 static void timeout_rr_t3122(void *arg)
542 LOGP(DRR, LOGL_INFO, "timer T3122 has fired\n");
545 static void timeout_rr_t3126(void *arg)
547 struct gsm48_rrlayer *rr = arg;
548 struct osmocom_ms *ms = rr->ms;
550 LOGP(DRR, LOGL_INFO, "timer T3126 has fired\n");
551 if (rr->rr_est_req) {
552 struct msgb *msg = gsm48_rr_msgb_alloc(GSM48_RR_REL_IND);
553 struct gsm48_rr_hdr *rrh;
555 LOGP(DSUM, LOGL_INFO, "Requesting channel failed\n");
558 rrh = (struct gsm48_rr_hdr *)msg->data;
559 rrh->cause = RR_REL_CAUSE_RA_FAILURE;
560 gsm48_rr_upmsg(ms, msg);
563 new_rr_state(rr, GSM48_RR_ST_IDLE);
566 static void start_rr_t_monitor(struct gsm48_rrlayer *rr, int sec, int micro)
568 rr->t_monitor.cb = timeout_rr_monitor;
569 rr->t_monitor.data = rr;
570 bsc_schedule_timer(&rr->t_monitor, sec, micro);
573 static void start_rr_t_rel_wait(struct gsm48_rrlayer *rr, int sec, int micro)
575 LOGP(DRR, LOGL_INFO, "starting T_rel_wait with %d seconds\n", sec);
576 rr->t_rel_wait.cb = timeout_rr_t_rel_wait;
577 rr->t_rel_wait.data = rr;
578 bsc_schedule_timer(&rr->t_rel_wait, sec, micro);
581 static void start_rr_t3110(struct gsm48_rrlayer *rr, int sec, int micro)
583 LOGP(DRR, LOGL_INFO, "starting T3110 with %d seconds\n", sec);
584 rr->t3110.cb = timeout_rr_t3110;
586 bsc_schedule_timer(&rr->t3110, sec, micro);
589 static void start_rr_t3122(struct gsm48_rrlayer *rr, int sec, int micro)
591 LOGP(DRR, LOGL_INFO, "starting T3122 with %d seconds\n", sec);
592 rr->t3122.cb = timeout_rr_t3122;
594 bsc_schedule_timer(&rr->t3122, sec, micro);
597 static void start_rr_t3126(struct gsm48_rrlayer *rr, int sec, int micro)
599 LOGP(DRR, LOGL_INFO, "starting T3126 with %d seconds\n", sec);
600 rr->t3126.cb = timeout_rr_t3126;
602 bsc_schedule_timer(&rr->t3126, sec, micro);
605 static void stop_rr_t_monitor(struct gsm48_rrlayer *rr)
607 if (bsc_timer_pending(&rr->t_monitor)) {
608 LOGP(DRR, LOGL_INFO, "stopping pending timer T_monitor\n");
609 bsc_del_timer(&rr->t_monitor);
613 static void stop_rr_t_rel_wait(struct gsm48_rrlayer *rr)
615 if (bsc_timer_pending(&rr->t_rel_wait)) {
616 LOGP(DRR, LOGL_INFO, "stopping pending timer T_rel_wait\n");
617 bsc_del_timer(&rr->t_rel_wait);
621 static void stop_rr_t3110(struct gsm48_rrlayer *rr)
623 if (bsc_timer_pending(&rr->t3110)) {
624 LOGP(DRR, LOGL_INFO, "stopping pending timer T3110\n");
625 bsc_del_timer(&rr->t3110);
629 static void stop_rr_t3122(struct gsm48_rrlayer *rr)
631 if (bsc_timer_pending(&rr->t3122)) {
632 LOGP(DRR, LOGL_INFO, "stopping pending timer T3122\n");
633 bsc_del_timer(&rr->t3122);
637 static void stop_rr_t3126(struct gsm48_rrlayer *rr)
639 if (bsc_timer_pending(&rr->t3126)) {
640 LOGP(DRR, LOGL_INFO, "stopping pending timer T3126\n");
641 bsc_del_timer(&rr->t3126);
649 /* send rr status request */
650 static int gsm48_rr_tx_rr_status(struct osmocom_ms *ms, uint8_t cause)
653 struct gsm48_hdr *gh;
654 struct gsm48_rr_status *st;
656 LOGP(DRR, LOGL_INFO, "RR STATUS (cause #%d)\n", cause);
658 nmsg = gsm48_l3_msgb_alloc();
661 gh = (struct gsm48_hdr *) msgb_put(nmsg, sizeof(*gh));
662 st = (struct gsm48_rr_status *) msgb_put(nmsg, sizeof(*st));
664 gh->proto_discr = GSM48_PDISC_RR;
665 gh->msg_type = GSM48_MT_RR_CIPH_M_COMPL;
668 st->rr_cause = cause;
670 return gsm48_send_rsl(ms, RSL_MT_DATA_REQ, nmsg);
677 /* send chiperhing mode complete */
678 static int gsm48_rr_tx_cip_mode_cpl(struct osmocom_ms *ms, uint8_t cr)
680 struct gsm_settings *set = &ms->settings;
682 struct gsm48_hdr *gh;
683 uint8_t buf[11], *tlv;
685 LOGP(DRR, LOGL_INFO, "CIPHERING MODE COMPLETE (cr %d)\n", cr);
687 nmsg = gsm48_l3_msgb_alloc();
690 gh = (struct gsm48_hdr *) msgb_put(nmsg, sizeof(*gh));
692 gh->proto_discr = GSM48_PDISC_RR;
693 gh->msg_type = GSM48_MT_RR_CIPH_M_COMPL;
697 gsm48_generate_mid_from_imsi(buf, set->imeisv);
698 tlv = msgb_put(nmsg, 2 + buf[1]);
699 memcpy(tlv, buf, 2 + buf[1]);
702 return gsm48_send_rsl(ms, RSL_MT_DATA_REQ, nmsg);
705 /* receive ciphering mode command */
706 static int gsm48_rr_rx_cip_mode_cmd(struct osmocom_ms *ms, struct msgb *msg)
708 struct gsm48_rrlayer *rr = &ms->rrlayer;
709 struct gsm_support *sup = &ms->support;
710 struct gsm48_hdr *gh = msgb_l3(msg);
711 struct gsm48_cip_mode_cmd *cm = (struct gsm48_cip_mode_cmd *)gh->data;
712 int payload_len = msgb_l3len(msg) - sizeof(*gh) - sizeof(*cm);
713 uint8_t sc, alg_id, cr;
715 if (payload_len < 0) {
716 LOGP(DRR, LOGL_NOTICE, "Short read of CIPHERING MODE COMMAND "
718 return gsm48_rr_tx_rr_status(ms,
719 GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
722 /* cipher mode setting */
725 /* cipher mode response */
729 LOGP(DRR, LOGL_INFO, "CIPHERING MODE COMMAND (sc=%u, cr=%u)",
732 LOGP(DRR, LOGL_INFO, "CIPHERING MODE COMMAND (sc=%u, "
733 "algo=A5/%d cr=%u)", sc, alg_id + 1, cr);
736 if (rr->cipher_on && sc) {
737 LOGP(DRR, LOGL_INFO, "cipering already applied.\n");
738 return gsm48_rr_tx_rr_status(ms,
739 GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
742 /* check if we actually support this cipher */
743 if ((alg_id == GSM_CIPHER_A5_1 && !sup->a5_1)
744 || (alg_id == GSM_CIPHER_A5_2 && !sup->a5_2)
745 || (alg_id == GSM_CIPHER_A5_3 && !sup->a5_3)
746 || (alg_id == GSM_CIPHER_A5_4 && !sup->a5_4)
747 || (alg_id == GSM_CIPHER_A5_5 && !sup->a5_5)
748 || (alg_id == GSM_CIPHER_A5_6 && !sup->a5_6)
749 || (alg_id == GSM_CIPHER_A5_7 && !sup->a5_7))
750 return gsm48_rr_tx_rr_status(ms,
751 GSM48_RR_CAUSE_CHAN_MODE_UNACCT);
753 /* change to ciphering */
755 rsl command to activate ciperhing
757 rr->cipher_on = sc, rr->cipher_type = alg_id;
760 return gsm48_rr_tx_cip_mode_cpl(ms, cr);
767 /* Encode "Classmark 3" (10.5.1.7) */
768 static int gsm48_rr_enc_cm3(struct osmocom_ms *ms, uint8_t *buf, uint8_t *len)
770 struct gsm_support *sup = &ms->support;
773 memset(&bv, 0, sizeof(bv));
778 bitvec_set_bit(&bv, 0);
779 /* band 3 supported */
781 bitvec_set_bit(&bv, ONE);
783 bitvec_set_bit(&bv, ZERO);
784 /* band 2 supported */
785 if (sup->e_gsm || sup->r_gsm)
786 bitvec_set_bit(&bv, ONE);
788 bitvec_set_bit(&bv, ZERO);
789 /* band 1 supported */
790 if (sup->p_gsm && !(sup->e_gsm || sup->r_gsm))
791 bitvec_set_bit(&bv, ONE);
793 bitvec_set_bit(&bv, ZERO);
796 bitvec_set_bit(&bv, ONE);
798 bitvec_set_bit(&bv, ZERO);
800 bitvec_set_bit(&bv, ONE);
802 bitvec_set_bit(&bv, ZERO);
804 bitvec_set_bit(&bv, ONE);
806 bitvec_set_bit(&bv, ZERO);
808 bitvec_set_bit(&bv, ONE);
810 bitvec_set_bit(&bv, ZERO);
811 /* radio capability */
812 if (sup->dcs_1800 && !sup->p_gsm && !(sup->e_gsm || sup->r_gsm)) {
814 bitvec_set_uint(&bv, 0, 4);
815 bitvec_set_uint(&bv, sup->dcs_capa, 4);
817 if (sup->dcs_1800 && (sup->p_gsm || (sup->e_gsm || sup->r_gsm))) {
819 bitvec_set_uint(&bv, sup->dcs_capa, 4);
821 bitvec_set_uint(&bv, sup->low_capa, 4);
824 bitvec_set_uint(&bv, 0, 4);
825 bitvec_set_uint(&bv, sup->low_capa, 4);
829 bitvec_set_bit(&bv, ONE);
830 bitvec_set_uint(&bv, sup->r_capa, 3);
832 bitvec_set_bit(&bv, ZERO);
834 /* multi slot support */
836 bitvec_set_bit(&bv, ONE);
837 bitvec_set_uint(&bv, sup->ms_sup, 5);
839 bitvec_set_bit(&bv, ZERO);
842 if (sup->ucs2_treat) {
843 bitvec_set_bit(&bv, ONE);
845 bitvec_set_bit(&bv, ZERO);
847 /* support extended measurements */
849 bitvec_set_bit(&bv, ONE);
851 bitvec_set_bit(&bv, ZERO);
853 /* support measurement capability */
855 bitvec_set_bit(&bv, ONE);
856 bitvec_set_uint(&bv, sup->sms_val, 4);
857 bitvec_set_uint(&bv, sup->sm_val, 4);
859 bitvec_set_bit(&bv, ZERO);
861 /* positioning method capability */
863 bitvec_set_bit(&bv, ONE);
864 bitvec_set_bit(&bv, sup->e_otd_ass == 1);
865 bitvec_set_bit(&bv, sup->e_otd_based == 1);
866 bitvec_set_bit(&bv, sup->gps_ass == 1);
867 bitvec_set_bit(&bv, sup->gps_based == 1);
868 bitvec_set_bit(&bv, sup->gps_conv == 1);
870 bitvec_set_bit(&bv, ZERO);
873 /* partitial bytes will be completed */
874 *len = (bv.cur_bit + 7) >> 3;
875 bitvec_spare_padding(&bv, (*len * 8) - 1);
880 /* encode classmark 2 */
881 int gsm48_rr_enc_cm2(struct osmocom_ms *ms, struct gsm48_classmark2 *cm)
883 struct gsm48_rrlayer *rr = &ms->rrlayer;
884 struct gsm_support *sup = &ms->support;
886 if (rr->cd_now.arfcn >= 512 && rr->cd_now.arfcn <= 885)
887 cm->pwr_lev = sup->pwr_lev_1800;
889 cm->pwr_lev = sup->pwr_lev_900;
890 cm->a5_1 = sup->a5_1;
891 cm->es_ind = sup->es_ind;
892 cm->rev_lev = sup->rev_lev;
893 cm->fc = (sup->r_gsm || sup->e_gsm);
894 cm->vgcs = sup->vgcs;
896 cm->sm_cap = sup->sms_ptp;
897 cm->ss_scr = sup->ss_ind;
898 cm->ps_cap = sup->ps_cap;
899 cm->a5_2 = sup->a5_2;
900 cm->a5_3 = sup->a5_3;
901 cm->cmsp = sup->cmsp;
902 cm->solsa = sup->solsa;
903 cm->lcsva_cap = sup->lcsva;
908 /* send classmark change */
909 static int gsm48_rr_tx_cm_change(struct osmocom_ms *ms)
911 struct gsm_support *sup = &ms->support;
913 struct gsm48_hdr *gh;
914 struct gsm48_cm_change *cc;
915 uint8_t cm3[14], *tlv;
917 LOGP(DRR, LOGL_INFO, "CLASSMARK CHANGE\n");
919 nmsg = gsm48_l3_msgb_alloc();
922 gh = (struct gsm48_hdr *) msgb_put(nmsg, sizeof(*gh));
923 cc = (struct gsm48_cm_change *) msgb_put(nmsg, sizeof(*cc));
925 gh->proto_discr = GSM48_PDISC_RR;
926 gh->msg_type = GSM48_MT_RR_CLSM_CHG;
929 cc->cm2_len = sizeof(cc->cm2);
930 gsm48_rr_enc_cm2(ms, &cc->cm2);
933 if (sup->dcs_1800 || sup->e_gsm || sup->r_gsm
934 || sup->a5_7 || sup->a5_6 || sup->a5_5 || sup->a5_4
937 || sup->ext_meas || sup->meas_cap
940 cm3[0] = GSM48_IE_CLASSMARK3;
941 gsm48_rr_enc_cm3(ms, cm3 + 2, &cm3[1]);
942 tlv = msgb_put(nmsg, 2 + cm3[1]);
943 memcpy(tlv, cm3, 2 + cm3[1]);
946 return gsm48_send_rsl(ms, RSL_MT_DATA_REQ, nmsg);
949 /* receiving classmark enquiry */
950 static int gsm48_rr_rx_cm_enq(struct osmocom_ms *ms, struct msgb *msg)
953 return gsm48_rr_tx_cm_change(ms);
960 /* start random access */
961 static int gsm48_rr_chan_req(struct osmocom_ms *ms, int cause, int paging)
963 struct gsm_support *sup = &ms->support;
964 struct gsm48_rrlayer *rr = &ms->rrlayer;
965 struct gsm322_cellsel *cs = &ms->cellsel;
966 struct gsm48_sysinfo *s = cs->si;
968 struct gsm48_rr_hdr *nrrh;
969 uint8_t chan_req_val, chan_req_mask;
972 LOGP(DSUM, LOGL_INFO, "Establish radio link due to %s request\n",
973 (paging) ? "paging" : "mobility management");
975 /* ignore paging, if not camping */
977 && (!cs->selected || (cs->state != GSM322_C3_CAMPED_NORMALLY
978 && cs->state != GSM322_C7_CAMPED_ANY_CELL))) {
979 LOGP(DRR, LOGL_INFO, "Paging, but not camping, ignore.\n");
983 /* tell cell selection process to leave idle mode
984 * NOTE: this must be sent unbuffered, because the state may not
985 * change until idle mode is left
987 nmsg = gsm322_msgb_alloc(GSM322_EVENT_LEAVE_IDLE);
990 rc = gsm322_c_event(ms, nmsg);
995 LOGP(DRR, LOGL_INFO, "Failed to leave IDLE mode.\n");
1000 new_rr_state(rr, GSM48_RR_ST_CONN_PEND);
1002 /* set assignment state */
1003 rr->wait_assign = 0;
1005 /* number of retransmissions (with first transmission) */
1006 rr->n_chan_req = s->max_retrans + 1;
1008 /* generate CHAN REQ (9.1.8) */
1010 case RR_EST_CAUSE_EMERGENCY:
1012 chan_req_mask = 0x1f;
1013 chan_req_val = 0xa0;
1014 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (Emergency call)\n",
1017 case RR_EST_CAUSE_REESTAB_TCH_F:
1018 chan_req_mask = 0x1f;
1019 chan_req_val = 0xc0;
1020 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (re-establish "
1021 "TCH/F)\n", chan_req_val);
1023 case RR_EST_CAUSE_REESTAB_TCH_H:
1025 chan_req_mask = 0x03;
1026 chan_req_val = 0x68;
1027 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x "
1028 "(re-establish TCH/H with NECI)\n",
1031 chan_req_mask = 0x1f;
1032 chan_req_val = 0xc0;
1033 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x "
1034 "(re-establish TCH/H no NECI)\n", chan_req_val);
1037 case RR_EST_CAUSE_REESTAB_2_TCH_H:
1039 chan_req_mask = 0x03;
1040 chan_req_val = 0x6c;
1041 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x "
1042 "(re-establish TCH/H+TCH/H with NECI)\n",
1045 chan_req_mask = 0x1f;
1046 chan_req_val = 0xc0;
1047 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x "
1048 "(re-establish TCH/H+TCH/H no NECI)\n",
1052 case RR_EST_CAUSE_ANS_PAG_ANY:
1053 chan_req_mask = 0x1f;
1054 chan_req_val = 0x80;
1055 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (PAGING "
1056 "Any channel)\n", chan_req_val);
1058 case RR_EST_CAUSE_ANS_PAG_SDCCH:
1059 chan_req_mask = 0x0f;
1060 chan_req_val = 0x10;
1061 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (PAGING SDCCH)\n",
1064 case RR_EST_CAUSE_ANS_PAG_TCH_F:
1065 switch (sup->ch_cap) {
1067 chan_req_mask = 0x0f;
1068 chan_req_val = 0x10;
1070 case GSM_CAP_SDCCH_TCHF:
1071 chan_req_mask = 0x1f;
1072 chan_req_val = 0x80;
1075 chan_req_mask = 0x0f;
1076 chan_req_val = 0x20;
1079 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (PAGING TCH/F)\n",
1082 case RR_EST_CAUSE_ANS_PAG_TCH_ANY:
1083 switch (sup->ch_cap) {
1085 chan_req_mask = 0x0f;
1086 chan_req_val = 0x10;
1088 case GSM_CAP_SDCCH_TCHF:
1089 chan_req_mask = 0x1f;
1090 chan_req_val = 0x80;
1093 chan_req_mask = 0x0f;
1094 chan_req_val = 0x30;
1097 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (PAGING TCH/H or "
1098 "TCH/F)\n", chan_req_val);
1100 case RR_EST_CAUSE_ORIG_TCHF:
1101 /* ms supports no dual rate */
1102 chan_req_mask = 0x1f;
1103 chan_req_val = 0xe0;
1104 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (Orig TCH/F)\n",
1107 case RR_EST_CAUSE_LOC_UPD:
1109 chan_req_mask = 0x0f;
1110 chan_req_val = 0x00;
1111 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (Location "
1112 "Update with NECI)\n", chan_req_val);
1114 chan_req_mask = 0x1f;
1115 chan_req_val = 0x00;
1116 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (Location "
1117 "Update no NECI)\n", chan_req_val);
1120 case RR_EST_CAUSE_OTHER_SDCCH:
1122 chan_req_mask = 0x0f;
1123 chan_req_val = 0x01;
1124 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (OHTER "
1125 "with NECI)\n", chan_req_val);
1127 chan_req_mask = 0x1f;
1128 chan_req_val = 0xe0;
1129 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: %02x (OTHER "
1130 "no NECI)\n", chan_req_val);
1134 if (!rr->rr_est_req) /* no request from MM */
1137 LOGP(DRR, LOGL_INFO, "CHANNEL REQUEST: with unknown "
1138 "establishment cause: %d\n", cause);
1140 LOGP(DSUM, LOGL_INFO, "Requesting channel failed\n");
1142 nmsg = gsm48_rr_msgb_alloc(GSM48_RR_REL_IND);
1145 nrrh = (struct gsm48_rr_hdr *)nmsg->data;
1146 nrrh->cause = RR_REL_CAUSE_UNDEFINED;
1147 gsm48_rr_upmsg(ms, nmsg);
1148 new_rr_state(rr, GSM48_RR_ST_IDLE);
1152 /* store value, mask and history */
1153 rr->chan_req_val = chan_req_val;
1154 rr->chan_req_mask = chan_req_mask;
1155 rr->cr_hist[2].valid = 0;
1156 rr->cr_hist[1].valid = 0;
1157 rr->cr_hist[0].valid = 0;
1159 /* store establishment cause, so 'choose cell' selects the last cell
1160 * after location updating */
1161 rr->est_cause = cause;
1163 /* if channel is already active somehow */
1164 if (cs->ccch_state == GSM322_CCCH_ST_DATA)
1165 return gsm48_rr_tx_rand_acc(ms, NULL);
1170 /* send first/next channel request in conn pend state */
1171 int gsm48_rr_tx_rand_acc(struct osmocom_ms *ms, struct msgb *msg)
1173 struct gsm48_rrlayer *rr = &ms->rrlayer;
1174 struct gsm322_cellsel *cs = &ms->cellsel;
1175 struct gsm48_sysinfo *s = &ms->cellsel.sel_si;
1176 struct gsm_settings *set = &ms->settings;
1178 struct abis_rsl_cchan_hdr *ncch;
1183 /* already assigned */
1184 if (rr->wait_assign == 2)
1187 /* store frame number */
1189 struct abis_rsl_cchan_hdr *ch = msgb_l2(msg);
1190 struct gsm48_req_ref *ref =
1191 (struct gsm48_req_ref *) (ch->data + 1);
1193 if (msgb_l2len(msg) < sizeof(*ch) + sizeof(*ref)) {
1194 LOGP(DRR, LOGL_ERROR, "CHAN_CNF too slort\n");
1198 /* shift history and store */
1199 memcpy(&(rr->cr_hist[2]), &(rr->cr_hist[1]),
1200 sizeof(struct gsm48_cr_hist));
1201 memcpy(&(rr->cr_hist[1]), &(rr->cr_hist[0]),
1202 sizeof(struct gsm48_cr_hist));
1203 rr->cr_hist[0].valid = 1;
1204 rr->cr_hist[0].ref.ra = rr->cr_ra;
1205 rr->cr_hist[0].ref.t1 = ref->t1;
1206 rr->cr_hist[0].ref.t2 = ref->t2;
1207 rr->cr_hist[0].ref.t3_low = ref->t3_low;
1208 rr->cr_hist[0].ref.t3_high = ref->t3_high;
1211 if (cs->ccch_state != GSM322_CCCH_ST_DATA) {
1212 LOGP(DRR, LOGL_INFO, "CCCH channel activation failed.\n");
1214 if (rr->rr_est_req) {
1216 gsm48_rr_msgb_alloc(GSM48_RR_REL_IND);
1217 struct gsm48_rr_hdr *rrh;
1219 LOGP(DSUM, LOGL_INFO, "Requesting channel failed\n");
1222 rrh = (struct gsm48_rr_hdr *)msg->data;
1223 rrh->cause = RR_REL_CAUSE_RA_FAILURE;
1224 gsm48_rr_upmsg(ms, msg);
1227 new_rr_state(rr, GSM48_RR_ST_IDLE);
1232 if (rr->state == GSM48_RR_ST_IDLE) {
1233 LOGP(DRR, LOGL_INFO, "MM already released RR.\n");
1238 LOGP(DRR, LOGL_INFO, "RANDOM ACCESS (requests left %d)\n",
1241 if (!rr->n_chan_req) {
1242 LOGP(DRR, LOGL_INFO, "Done with sending RANDOM ACCESS "
1244 if (!bsc_timer_pending(&rr->t3126))
1245 start_rr_t3126(rr, 5, 0); /* TODO improve! */
1250 if (rr->wait_assign == 0) {
1251 /* first random acces, without delay of slots */
1253 rr->wait_assign = 1;
1255 /* subsequent random acces, with slots from table 3.1 */
1256 switch(s->tx_integer) {
1257 case 3: case 8: case 14: case 50:
1258 if (s->ccch_conf != 1) /* not combined CCCH */
1263 case 4: case 9: case 16:
1264 if (s->ccch_conf != 1)
1269 case 5: case 10: case 20:
1270 if (s->ccch_conf != 1)
1275 case 6: case 11: case 25:
1276 if (s->ccch_conf != 1)
1282 if (s->ccch_conf != 1)
1290 chan_req = random();
1291 chan_req &= rr->chan_req_mask;
1292 chan_req |= rr->chan_req_val;
1294 LOGP(DRR, LOGL_INFO, "RANDOM ACCESS (Tx-integer %d combined %s "
1295 "S(lots) %d ra 0x%02x)\n", s->tx_integer,
1296 (s->ccch_conf == 1) ? "yes": "no", slots, chan_req);
1298 /* (re)send CHANNEL RQD with new randiom */
1299 nmsg = gsm48_rsl_msgb_alloc();
1302 ncch = (struct abis_rsl_cchan_hdr *) msgb_put(nmsg, sizeof(*ncch)
1304 rsl_init_cchan_hdr(ncch, RSL_MT_CHAN_RQD);
1305 ncch->chan_nr = RSL_CHAN_RACH;
1306 ncch->data[0] = RSL_IE_REQ_REFERENCE;
1307 ncch->data[1] = chan_req;
1308 #warning HACK: fn51 and fn_off
1309 ncch->data[2] = (s->ccch_conf == 1) ? 27 : 50;
1310 ncch->data[3] = 1 + ((random() % s->tx_integer) + slots) / 51;
1311 ncch->data[4] = RSL_IE_ACCESS_DELAY;
1312 ncch->data[5] = set->alter_delay; /* (-)=earlier (+)=later */
1313 ncch->data[6] = RSL_IE_MS_POWER;
1314 if (set->alter_tx_power) {
1315 tx_power = set->alter_tx_power_value;
1316 LOGP(DRR, LOGL_INFO, "Use alternative tx-power %d (%d dBm)\n",
1318 ms_pwr_dbm(gsm_arfcn2band(cs->arfcn), tx_power));
1320 tx_power = s->ms_txpwr_max_cch;
1321 /* power offset in case of DCS1800 */
1322 if (s->po && cs->arfcn >= 512 && cs->arfcn <= 885) {
1323 LOGP(DRR, LOGL_INFO, "Use MS-TXPWR-MAX-CCH power value "
1324 "%d (%d dBm) with offset %d dBm\n", tx_power,
1325 ms_pwr_dbm(gsm_arfcn2band(cs->arfcn), tx_power),
1327 /* use reserved bits 7,8 for offset (+ X * 2dB) */
1328 tx_power |= s->po_value << 6;
1330 LOGP(DRR, LOGL_INFO, "Use MS-TXPWR-MAX-CCH power value "
1331 "%d (%d dBm)\n", tx_power,
1332 ms_pwr_dbm(gsm_arfcn2band(cs->arfcn),
1335 ncch->data[7] = tx_power;
1337 /* set initial indications */
1338 rr->ind_tx_power = s->ms_txpwr_max_cch;
1339 rr->ind_ta = set->alter_delay;
1341 /* store ra until confirmed, then copy it with time into cr_hist */
1342 rr->cr_ra = chan_req;
1344 return rslms_recvmsg(nmsg, ms);
1348 * system information
1351 /* decode "Cell Channel Description" (10.5.2.1b) and other frequency lists */
1352 static int decode_freq_list(struct gsm_support *sup,
1353 struct gsm_sysinfo_freq *f, uint8_t *cd, uint8_t len, uint8_t mask,
1356 /* only Bit map 0 format for P-GSM */
1357 if ((cd[0] & 0xc0 & mask) != 0x00 &&
1358 (sup->p_gsm && !sup->e_gsm && !sup->r_gsm && !sup->dcs_1800))
1361 return gsm48_decode_freq_list(f, cd, len, mask, frqt);
1364 /* decode "Cell Selection Parameters" (10.5.2.4) */
1365 static int gsm48_decode_cell_sel_param(struct gsm48_sysinfo *s,
1366 struct gsm48_cell_sel_par *cs)
1369 convert ms_txpwr_max_ccch dependant on the current frequenc and support
1370 to the right powe level
1372 s->ms_txpwr_max_cch = cs->ms_txpwr_max_ccch;
1373 s->cell_resel_hyst_db = cs->cell_resel_hyst * 2;
1374 s->rxlev_acc_min_db = cs->rxlev_acc_min - 110;
1381 /* decode "Cell Options (BCCH)" (10.5.2.3) */
1382 static int gsm48_decode_cellopt_bcch(struct gsm48_sysinfo *s,
1383 struct gsm48_cell_options *co)
1385 s->bcch_radio_link_timeout = (co->radio_link_timeout + 1) * 4;
1386 s->bcch_dtx = co->dtx;
1387 s->bcch_pwrc = co->pwrc;
1392 /* decode "Cell Options (SACCH)" (10.5.2.3a) */
1393 static int gsm48_decode_cellopt_sacch(struct gsm48_sysinfo *s,
1394 struct gsm48_cell_options *co)
1396 s->sacch_radio_link_timeout = (co->radio_link_timeout + 1) * 4;
1397 s->sacch_dtx = co->dtx;
1398 s->sacch_pwrc = co->pwrc;
1403 /* decode "Control Channel Description" (10.5.2.11) */
1404 static int gsm48_decode_ccd(struct gsm48_sysinfo *s,
1405 struct gsm48_control_channel_descr *cc)
1407 s->ccch_conf = cc->ccch_conf;
1408 s->bs_ag_blks_res = cc->bs_ag_blks_res;
1409 s->att_allowed = cc->att;
1410 s->pag_mf_periods = cc->bs_pa_mfrms + 2;
1411 s->t3212 = cc->t3212 * 360; /* convert deci-hours to seconds */
1416 /* decode "Mobile Allocation" (10.5.2.21) */
1417 static int gsm48_decode_mobile_alloc(struct gsm48_sysinfo *s,
1418 uint8_t *ma, uint8_t len, uint16_t *hopping, uint8_t *hopp_len, int si4)
1421 uint16_t f[len << 3];
1423 /* not more than 64 hopping indexes allowed in IE */
1430 for (i = 0; i < 1024; i++)
1431 s->freq[i].mask &= ~FREQ_TYPE_HOPP;
1434 /* generating list of all frequencies (1..1023,0) */
1435 for (i = 1; i <= 1024; i++) {
1436 if ((s->freq[i & 1023].mask & FREQ_TYPE_SERV)) {
1437 LOGP(DRR, LOGL_INFO, "Serving cell ARFCN #%d: %d\n",
1440 if (j == (len << 3))
1445 /* fill hopping table with frequency index given by IE
1446 * and set hopping type bits
1448 for (i = 0; i < (len << 3); i++) {
1449 /* if bit is set, this frequency index is used for hopping */
1450 if ((ma[len - 1 - (i >> 3)] & (1 << (i & 7)))) {
1451 LOGP(DRR, LOGL_INFO, "Hopping ARFCN: %d (bit %d)\n",
1453 /* index higher than entries in list ? */
1455 LOGP(DRR, LOGL_NOTICE, "Mobile Allocation "
1456 "hopping index %d exceeds maximum "
1457 "number of cell frequencies. (%d)\n",
1461 hopping[(*hopp_len)++] = f[i];
1463 s->freq[f[i]].mask |= FREQ_TYPE_HOPP;
1470 /* Rach Control decode tables */
1471 static uint8_t gsm48_max_retrans[4] = {
1474 static uint8_t gsm48_tx_integer[16] = {
1475 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 25, 32, 50
1478 /* decode "RACH Control Parameter" (10.5.2.29) */
1479 static int gsm48_decode_rach_ctl_param(struct gsm48_sysinfo *s,
1480 struct gsm48_rach_control *rc)
1482 s->reest_denied = rc->re;
1483 s->cell_barr = rc->cell_bar;
1484 s->tx_integer = gsm48_tx_integer[rc->tx_integer];
1485 s->max_retrans = gsm48_max_retrans[rc->max_trans];
1486 s->class_barr = (rc->t2 << 8) | rc->t3;
1490 static int gsm48_decode_rach_ctl_neigh(struct gsm48_sysinfo *s,
1491 struct gsm48_rach_control *rc)
1493 s->nb_reest_denied = rc->re;
1494 s->nb_cell_barr = rc->cell_bar;
1495 s->nb_tx_integer = gsm48_tx_integer[rc->tx_integer];
1496 s->nb_max_retrans = gsm48_max_retrans[rc->max_trans];
1497 s->nb_class_barr = (rc->t2 << 8) | rc->t3;
1502 /* decode "SI 1 Rest Octets" (10.5.2.32) */
1503 static int gsm48_decode_si1_rest(struct gsm48_sysinfo *s, uint8_t *si,
1509 /* decode "SI 3 Rest Octets" (10.5.2.34) */
1510 static int gsm48_decode_si3_rest(struct gsm48_sysinfo *s, uint8_t *si,
1515 memset(&bv, 0, sizeof(bv));
1519 /* Optional Selection Parameters */
1520 if (bitvec_get_bit_high(&bv) == H) {
1522 s->sp_cbq = bitvec_get_uint(&bv, 1);
1523 s->sp_cro = bitvec_get_uint(&bv, 6);
1524 s->sp_to = bitvec_get_uint(&bv, 3);
1525 s->sp_pt = bitvec_get_uint(&bv, 5);
1527 /* Optional Power Offset */
1528 if (bitvec_get_bit_high(&bv) == H) {
1530 s->po_value = bitvec_get_uint(&bv, 3);
1532 /* System Onformation 2ter Indicator */
1533 if (bitvec_get_bit_high(&bv) == H)
1535 /* Early Classark Sending Control */
1536 if (bitvec_get_bit_high(&bv) == H)
1538 /* Scheduling if and where */
1539 if (bitvec_get_bit_high(&bv) == H) {
1541 s->sched_where = bitvec_get_uint(&bv, 3);
1543 /* GPRS Indicator */
1544 s->gi_ra_colour = bitvec_get_uint(&bv, 3);
1545 s->gi_si13_pos = bitvec_get_uint(&bv, 1);
1549 /* decode "SI 4 Rest Octets" (10.5.2.35) */
1550 static int gsm48_decode_si4_rest(struct gsm48_sysinfo *s, uint8_t *si,
1556 /* decode "SI 6 Rest Octets" (10.5.2.35a) */
1557 static int gsm48_decode_si6_rest(struct gsm48_sysinfo *s, uint8_t *si,
1563 /* send sysinfo event to other layers */
1564 static int gsm48_send_sysinfo(struct osmocom_ms *ms, uint8_t type)
1567 struct gsm322_msg *em;
1569 nmsg = gsm322_msgb_alloc(GSM322_EVENT_SYSINFO);
1572 em = (struct gsm322_msg *) nmsg->data;
1574 gsm322_cs_sendmsg(ms, nmsg);
1576 /* send timer info to location update process */
1577 nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_SYSINFO);
1580 gsm48_mmevent_msg(ms, nmsg);
1585 /* receive "SYSTEM INFORMATION 1" message (9.1.31) */
1586 static int gsm48_rr_rx_sysinfo1(struct osmocom_ms *ms, struct msgb *msg)
1588 struct gsm48_system_information_type_1 *si = msgb_l3(msg);
1589 struct gsm48_sysinfo *s = ms->cellsel.si;
1590 int payload_len = msgb_l3len(msg) - sizeof(*si);
1593 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 1 "
1598 if (payload_len < 0) {
1599 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 1 "
1604 if (!memcmp(si, s->si1_msg, MIN(msgb_l3len(msg), sizeof(s->si1_msg))))
1606 memcpy(s->si1_msg, si, MIN(msgb_l3len(msg), sizeof(s->si1_msg)));
1608 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 1\n");
1610 /* Cell Channel Description */
1611 decode_freq_list(&ms->support, s->freq,
1612 si->cell_channel_description,
1613 sizeof(si->cell_channel_description), 0xce, FREQ_TYPE_SERV);
1614 /* RACH Control Parameter */
1615 gsm48_decode_rach_ctl_param(s, &si->rach_control);
1616 /* SI 1 Rest Octets */
1618 gsm48_decode_si1_rest(s, si->rest_octets, payload_len);
1622 return gsm48_send_sysinfo(ms, si->header.system_information);
1625 /* receive "SYSTEM INFORMATION 2" message (9.1.32) */
1626 static int gsm48_rr_rx_sysinfo2(struct osmocom_ms *ms, struct msgb *msg)
1628 struct gsm48_system_information_type_2 *si = msgb_l3(msg);
1629 struct gsm48_sysinfo *s = ms->cellsel.si;
1630 int payload_len = msgb_l3len(msg) - sizeof(*si);
1633 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 2 "
1638 if (payload_len < 0) {
1639 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 2 "
1643 //printf("len = %d\n", MIN(msgb_l3len(msg), sizeof(s->si2_msg)));
1645 if (!memcmp(si, s->si2_msg, MIN(msgb_l3len(msg), sizeof(s->si2_msg))))
1647 memcpy(s->si2_msg, si, MIN(msgb_l3len(msg), sizeof(s->si2_msg)));
1649 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 2\n");
1651 /* Neighbor Cell Description */
1652 s->nb_ext_ind_si2 = (si->bcch_frequency_list[0] >> 6) & 1;
1653 s->nb_ba_ind_si2 = (si->bcch_frequency_list[0] >> 5) & 1;
1654 decode_freq_list(&ms->support, s->freq, si->bcch_frequency_list,
1655 sizeof(si->bcch_frequency_list), 0xce, FREQ_TYPE_NCELL_2);
1657 s->nb_ncc_permitted = si->ncc_permitted;
1658 /* RACH Control Parameter */
1659 gsm48_decode_rach_ctl_neigh(s, &si->rach_control);
1663 return gsm48_send_sysinfo(ms, si->header.system_information);
1666 /* receive "SYSTEM INFORMATION 2bis" message (9.1.33) */
1667 static int gsm48_rr_rx_sysinfo2bis(struct osmocom_ms *ms, struct msgb *msg)
1669 struct gsm48_system_information_type_2bis *si = msgb_l3(msg);
1670 struct gsm48_sysinfo *s = ms->cellsel.si;
1671 int payload_len = msgb_l3len(msg) - sizeof(*si);
1674 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 2bis"
1679 if (payload_len < 0) {
1680 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 2bis "
1685 if (!memcmp(si, s->si2b_msg, MIN(msgb_l3len(msg),
1686 sizeof(s->si2b_msg))))
1688 memcpy(s->si2b_msg, si, MIN(msgb_l3len(msg), sizeof(s->si2b_msg)));
1690 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 2bis\n");
1692 /* Neighbor Cell Description */
1693 s->nb_ext_ind_si2bis = (si->bcch_frequency_list[0] >> 6) & 1;
1694 s->nb_ba_ind_si2bis = (si->bcch_frequency_list[0] >> 5) & 1;
1695 decode_freq_list(&ms->support, s->freq,
1696 si->bcch_frequency_list,
1697 sizeof(si->bcch_frequency_list), 0x8e,
1698 FREQ_TYPE_NCELL_2bis);
1699 /* RACH Control Parameter */
1700 gsm48_decode_rach_ctl_neigh(s, &si->rach_control);
1704 return gsm48_send_sysinfo(ms, si->header.system_information);
1707 /* receive "SYSTEM INFORMATION 2ter" message (9.1.34) */
1708 static int gsm48_rr_rx_sysinfo2ter(struct osmocom_ms *ms, struct msgb *msg)
1710 struct gsm48_system_information_type_2ter *si = msgb_l3(msg);
1711 struct gsm48_sysinfo *s = ms->cellsel.si;
1712 int payload_len = msgb_l3len(msg) - sizeof(*si);
1715 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 2ter"
1720 if (payload_len < 0) {
1721 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 2ter "
1726 if (!memcmp(si, s->si2t_msg, MIN(msgb_l3len(msg),
1727 sizeof(s->si2t_msg))))
1729 memcpy(s->si2t_msg, si, MIN(msgb_l3len(msg), sizeof(s->si2t_msg)));
1731 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 2ter\n");
1733 /* Neighbor Cell Description 2 */
1734 s->nb_multi_rep_si2ter = (si->ext_bcch_frequency_list[0] >> 6) & 3;
1735 decode_freq_list(&ms->support, s->freq,
1736 si->ext_bcch_frequency_list,
1737 sizeof(si->ext_bcch_frequency_list), 0x8e,
1738 FREQ_TYPE_NCELL_2ter);
1742 return gsm48_send_sysinfo(ms, si->header.system_information);
1745 /* receive "SYSTEM INFORMATION 3" message (9.1.35) */
1746 static int gsm48_rr_rx_sysinfo3(struct osmocom_ms *ms, struct msgb *msg)
1748 struct gsm48_system_information_type_3 *si = msgb_l3(msg);
1749 struct gsm322_cellsel *cs = &ms->cellsel;
1750 struct gsm48_sysinfo *s = cs->si;
1751 int payload_len = msgb_l3len(msg) - sizeof(*si);
1754 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 3 "
1759 if (payload_len < 0) {
1760 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 3 "
1765 if (!memcmp(si, s->si3_msg, MIN(msgb_l3len(msg), sizeof(s->si3_msg))))
1767 memcpy(s->si3_msg, si, MIN(msgb_l3len(msg), sizeof(s->si3_msg)));
1770 s->cell_id = ntohs(si->cell_identity);
1772 gsm48_decode_lai(&si->lai, &s->mcc, &s->mnc, &s->lac);
1773 /* Control Channel Description */
1774 gsm48_decode_ccd(s, &si->control_channel_desc);
1775 /* Cell Options (BCCH) */
1776 gsm48_decode_cellopt_bcch(s, &si->cell_options);
1777 /* Cell Selection Parameters */
1778 gsm48_decode_cell_sel_param(s, &si->cell_sel_par);
1779 /* RACH Control Parameter */
1780 gsm48_decode_rach_ctl_param(s, &si->rach_control);
1781 /* SI 3 Rest Octets */
1782 if (payload_len >= 4)
1783 gsm48_decode_si3_rest(s, si->rest_octets, payload_len);
1785 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 3 (mcc %s mnc %s "
1786 "lac 0x%04x)\n", gsm_print_mcc(s->mcc),
1787 gsm_print_mnc(s->mnc), s->lac);
1791 if (cs->ccch_mode == CCCH_MODE_NONE) {
1792 cs->ccch_mode = (s->ccch_conf == 1) ? CCCH_MODE_COMBINED :
1793 CCCH_MODE_NON_COMBINED;
1794 LOGP(DRR, LOGL_NOTICE, "Changing CCCH_MODE to %d\n",
1796 l1ctl_tx_ccch_mode_req(ms, cs->ccch_mode);
1799 return gsm48_send_sysinfo(ms, si->header.system_information);
1802 /* receive "SYSTEM INFORMATION 4" message (9.1.36) */
1803 static int gsm48_rr_rx_sysinfo4(struct osmocom_ms *ms, struct msgb *msg)
1805 /* NOTE: pseudo length is not in this structure, so we skip */
1806 struct gsm48_system_information_type_4 *si = msgb_l3(msg);
1807 struct gsm48_sysinfo *s = ms->cellsel.si;
1808 int payload_len = msgb_l3len(msg) - sizeof(*si);
1809 uint8_t *data = si->data;
1810 struct gsm48_chan_desc *cd;
1813 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 4 "
1818 if (payload_len < 0) {
1820 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 4 "
1826 LOGP(DRR, LOGL_NOTICE, "Ignoring SYSTEM INFORMATION 4 "
1827 "until SI 1 is received.\n");
1831 if (!memcmp(si, s->si4_msg, MIN(msgb_l3len(msg), sizeof(s->si4_msg))))
1833 memcpy(s->si4_msg, si, MIN(msgb_l3len(msg), sizeof(s->si4_msg)));
1836 gsm48_decode_lai(&si->lai, &s->mcc, &s->mnc, &s->lac);
1837 /* Cell Selection Parameters */
1838 gsm48_decode_cell_sel_param(s, &si->cell_sel_par);
1839 /* RACH Control Parameter */
1840 gsm48_decode_rach_ctl_param(s, &si->rach_control);
1841 /* CBCH Channel Description */
1842 if (payload_len >= 1 && data[0] == GSM48_IE_CBCH_CHAN_DESC) {
1843 if (payload_len < 4)
1845 cd = (struct gsm48_chan_desc *) (data + 1);
1848 gsm48_decode_chan_h1(cd, &s->tsc, &s->maio, &s->hsn);
1851 gsm48_decode_chan_h0(cd, &s->tsc, &s->arfcn);
1856 /* CBCH Mobile Allocation */
1857 if (payload_len >= 1 && data[0] == GSM48_IE_CBCH_MOB_AL) {
1858 if (payload_len < 1 || payload_len < 2 + data[1])
1860 gsm48_decode_mobile_alloc(s, data + 2, si->data[1], s->hopping,
1862 payload_len -= 2 + data[1];
1863 data += 2 + data[1];
1865 /* SI 4 Rest Octets */
1866 if (payload_len > 0)
1867 gsm48_decode_si4_rest(s, data, payload_len);
1869 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 4 (mcc %s mnc %s "
1870 "lac 0x%04x)\n", gsm_print_mcc(s->mcc),
1871 gsm_print_mnc(s->mnc), s->lac);
1875 return gsm48_send_sysinfo(ms, si->header.system_information);
1878 /* receive "SYSTEM INFORMATION 5" message (9.1.37) */
1879 static int gsm48_rr_rx_sysinfo5(struct osmocom_ms *ms, struct msgb *msg)
1881 /* NOTE: pseudo length is not in this structure, so we skip */
1882 struct gsm48_system_information_type_5 *si = msgb_l3(msg) + 1;
1883 struct gsm48_sysinfo *s = ms->cellsel.si;
1884 int payload_len = msgb_l3len(msg) - sizeof(*si) - 1;
1887 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 5 "
1892 if (payload_len < 0) {
1893 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 5 "
1898 if (!memcmp(si, s->si5_msg, MIN(msgb_l3len(msg), sizeof(s->si5_msg))))
1900 memcpy(s->si5_msg, si, MIN(msgb_l3len(msg), sizeof(s->si5_msg)));
1902 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 5\n");
1904 /* Neighbor Cell Description */
1905 s->nb_ext_ind_si5 = (si->bcch_frequency_list[0] >> 6) & 1;
1906 s->nb_ba_ind_si5 = (si->bcch_frequency_list[0] >> 5) & 1;
1907 decode_freq_list(&ms->support, s->freq, si->bcch_frequency_list,
1908 sizeof(si->bcch_frequency_list), 0xce, FREQ_TYPE_REP_5);
1912 return gsm48_send_sysinfo(ms, si->system_information);
1915 /* receive "SYSTEM INFORMATION 5bis" message (9.1.38) */
1916 static int gsm48_rr_rx_sysinfo5bis(struct osmocom_ms *ms, struct msgb *msg)
1918 /* NOTE: pseudo length is not in this structure, so we skip */
1919 struct gsm48_system_information_type_5bis *si = msgb_l3(msg) + 1;
1920 struct gsm48_sysinfo *s = ms->cellsel.si;
1921 int payload_len = msgb_l3len(msg) - sizeof(*si) - 1;
1924 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 5bis"
1929 if (payload_len < 0) {
1930 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 5bis "
1935 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 5bis\n");
1937 if (!memcmp(si, s->si5b_msg, MIN(msgb_l3len(msg),
1938 sizeof(s->si5b_msg))))
1940 memcpy(s->si5b_msg, si, MIN(msgb_l3len(msg), sizeof(s->si5b_msg)));
1942 /* Neighbor Cell Description */
1943 s->nb_ext_ind_si5bis = (si->bcch_frequency_list[0] >> 6) & 1;
1944 s->nb_ba_ind_si5bis = (si->bcch_frequency_list[0] >> 5) & 1;
1945 decode_freq_list(&ms->support, s->freq, si->bcch_frequency_list,
1946 sizeof(si->bcch_frequency_list), 0xce, FREQ_TYPE_REP_5bis);
1950 return gsm48_send_sysinfo(ms, si->system_information);
1953 /* receive "SYSTEM INFORMATION 5ter" message (9.1.39) */
1954 static int gsm48_rr_rx_sysinfo5ter(struct osmocom_ms *ms, struct msgb *msg)
1956 /* NOTE: pseudo length is not in this structure, so we skip */
1957 struct gsm48_system_information_type_5ter *si = msgb_l3(msg) + 1;
1958 struct gsm48_sysinfo *s = ms->cellsel.si;
1959 int payload_len = msgb_l3len(msg) - sizeof(*si) - 1;
1962 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 5ter"
1967 if (payload_len < 0) {
1968 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 5ter "
1973 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 5ter\n");
1975 if (!memcmp(si, s->si5t_msg, MIN(msgb_l3len(msg),
1976 sizeof(s->si5t_msg))))
1978 memcpy(s->si5t_msg, si, MIN(msgb_l3len(msg), sizeof(s->si5t_msg)));
1980 /* Neighbor Cell Description */
1981 decode_freq_list(&ms->support, s->freq, si->bcch_frequency_list,
1982 sizeof(si->bcch_frequency_list), 0xce, FREQ_TYPE_REP_5ter);
1986 return gsm48_send_sysinfo(ms, si->system_information);
1989 /* receive "SYSTEM INFORMATION 6" message (9.1.39) */
1990 static int gsm48_rr_rx_sysinfo6(struct osmocom_ms *ms, struct msgb *msg)
1992 /* NOTE: pseudo length is not in this structure, so we skip */
1993 struct gsm48_system_information_type_6 *si = msgb_l3(msg) + 1;
1994 struct gsm48_sysinfo *s = ms->cellsel.si;
1995 int payload_len = msgb_l3len(msg) - sizeof(*si) - 1;
1998 LOGP(DRR, LOGL_INFO, "No cell selected, SYSTEM INFORMATION 6 "
2003 if (payload_len < 0) {
2004 LOGP(DRR, LOGL_NOTICE, "Short read of SYSTEM INFORMATION 6 "
2009 if (!memcmp(si, s->si6_msg, MIN(msgb_l3len(msg), sizeof(s->si6_msg))))
2011 memcpy(s->si6_msg, si, MIN(msgb_l3len(msg), sizeof(s->si6_msg)));
2014 if (s->si6 && s->cell_id != ntohs(si->cell_identity))
2015 LOGP(DRR, LOGL_INFO, "Cell ID on SI 6 differs from previous "
2017 s->cell_id = ntohs(si->cell_identity);
2019 gsm48_decode_lai(&si->lai, &s->mcc, &s->mnc, &s->lac);
2020 /* Cell Options (SACCH) */
2021 gsm48_decode_cellopt_sacch(s, &si->cell_options);
2023 s->nb_ncc_permitted = si->ncc_permitted;
2024 /* SI 6 Rest Octets */
2025 if (payload_len >= 4)
2026 gsm48_decode_si6_rest(s, si->rest_octets, payload_len);
2028 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 6 (mcc %s mnc %s "
2029 "lac 0x%04x SACCH-timeout %d)\n", gsm_print_mcc(s->mcc),
2030 gsm_print_mnc(s->mnc), s->lac, s->sacch_radio_link_timeout);
2034 return gsm48_send_sysinfo(ms, si->system_information);
2041 /* paging channel request */
2042 static int gsm48_rr_chan2cause[4] = {
2043 RR_EST_CAUSE_ANS_PAG_ANY,
2044 RR_EST_CAUSE_ANS_PAG_SDCCH,
2045 RR_EST_CAUSE_ANS_PAG_TCH_F,
2046 RR_EST_CAUSE_ANS_PAG_TCH_ANY
2049 /* given LV of mobile identity is checked agains ms */
2050 static int gsm_match_mi(struct osmocom_ms *ms, uint8_t *mi)
2058 mi_type = mi[1] & GSM_MI_TYPE_MASK;
2060 case GSM_MI_TYPE_TMSI:
2063 memcpy(&tmsi, mi+2, 4);
2064 if (ms->subscr.tmsi == ntohl(tmsi)
2065 && ms->subscr.tmsi_valid) {
2066 LOGP(DPAG, LOGL_INFO, "TMSI %08x matches\n",
2071 LOGP(DPAG, LOGL_INFO, "TMSI %08x (not for us)\n",
2074 case GSM_MI_TYPE_IMSI:
2075 gsm48_mi_to_string(imsi, sizeof(imsi), mi + 1, mi[0]);
2076 if (!strcmp(imsi, ms->subscr.imsi)) {
2077 LOGP(DPAG, LOGL_INFO, "IMSI %s matches\n", imsi);
2081 LOGP(DPAG, LOGL_INFO, "IMSI %s (not for us)\n", imsi);
2084 LOGP(DPAG, LOGL_NOTICE, "Paging with unsupported MI type %d.\n",
2091 /* 9.1.22 PAGING REQUEST 1 message received */
2092 static int gsm48_rr_rx_pag_req_1(struct osmocom_ms *ms, struct msgb *msg)
2094 struct gsm48_rrlayer *rr = &ms->rrlayer;
2095 struct gsm322_cellsel *cs = &ms->cellsel;
2096 struct gsm48_paging1 *pa = msgb_l3(msg);
2097 int payload_len = msgb_l3len(msg) - sizeof(*pa);
2101 /* empty paging request */
2102 if (payload_len >= 2 && (pa->data[1] & GSM_MI_TYPE_MASK) == 0)
2105 /* 3.3.1.1.2: ignore paging while not camping on a cell */
2106 if (rr->state != GSM48_RR_ST_IDLE || !cs->selected
2107 || (cs->state != GSM322_C3_CAMPED_NORMALLY
2108 && cs->state != GSM322_C7_CAMPED_ANY_CELL)) {
2109 LOGP(DRR, LOGL_INFO, "PAGING ignored, we are not camping.\n");
2113 LOGP(DPAG, LOGL_INFO, "PAGING REQUEST 1\n");
2115 if (payload_len < 2) {
2117 LOGP(DRR, LOGL_NOTICE, "Short read of PAGING REQUEST 1 "
2123 /* channel needed */
2124 chan_1 = pa->cneed1;
2125 chan_2 = pa->cneed2;
2128 if (payload_len < mi[0] + 1)
2130 if (gsm_match_mi(ms, mi) > 0)
2131 return gsm48_rr_chan_req(ms, gsm48_rr_chan2cause[chan_1], 1);
2133 payload_len -= mi[0] + 1;
2134 mi = pa->data + mi[0] + 1;
2135 if (payload_len < 2)
2137 if (mi[0] != GSM48_IE_MOBILE_ID)
2139 if (payload_len < mi[1] + 2)
2141 if (gsm_match_mi(ms, mi + 1) > 0)
2142 return gsm48_rr_chan_req(ms, gsm48_rr_chan2cause[chan_2], 1);
2147 /* 9.1.23 PAGING REQUEST 2 message received */
2148 static int gsm48_rr_rx_pag_req_2(struct osmocom_ms *ms, struct msgb *msg)
2150 struct gsm48_rrlayer *rr = &ms->rrlayer;
2151 struct gsm322_cellsel *cs = &ms->cellsel;
2152 struct gsm48_paging2 *pa = msgb_l3(msg);
2153 int payload_len = msgb_l3len(msg) - sizeof(*pa);
2155 int chan_1, chan_2, chan_3;
2157 /* 3.3.1.1.2: ignore paging while not camping on a cell */
2158 if (rr->state != GSM48_RR_ST_IDLE || !cs->selected
2159 || (cs->state != GSM322_C3_CAMPED_NORMALLY
2160 && cs->state != GSM322_C7_CAMPED_ANY_CELL)) {
2161 LOGP(DRR, LOGL_INFO, "PAGING ignored, we are not camping.\n");
2165 LOGP(DPAG, LOGL_INFO, "PAGING REQUEST 2\n");
2167 if (payload_len < 0) {
2169 LOGP(DRR, LOGL_NOTICE, "Short read of PAGING REQUEST 2 "
2175 /* channel needed */
2176 chan_1 = pa->cneed1;
2177 chan_2 = pa->cneed2;
2179 if (ms->subscr.tmsi == ntohl(pa->tmsi1)
2180 && ms->subscr.tmsi_valid) {
2181 LOGP(DPAG, LOGL_INFO, "TMSI %08x matches\n", ntohl(pa->tmsi1));
2182 return gsm48_rr_chan_req(ms, gsm48_rr_chan2cause[chan_1], 1);
2184 LOGP(DPAG, LOGL_INFO, "TMSI %08x (not for us)\n",
2187 if (ms->subscr.tmsi == ntohl(pa->tmsi2)
2188 && ms->subscr.tmsi_valid) {
2189 LOGP(DPAG, LOGL_INFO, "TMSI %08x matches\n", ntohl(pa->tmsi2));
2190 return gsm48_rr_chan_req(ms, gsm48_rr_chan2cause[chan_2], 1);
2192 LOGP(DPAG, LOGL_INFO, "TMSI %08x (not for us)\n",
2196 if (payload_len < 2)
2198 if (mi[0] != GSM48_IE_MOBILE_ID)
2200 if (payload_len < mi[1] + 2 + 1) /* must include "channel needed" */
2202 chan_3 = mi[mi[1] + 2] & 0x03; /* channel needed */
2203 if (gsm_match_mi(ms, mi + 1) > 0)
2204 return gsm48_rr_chan_req(ms, gsm48_rr_chan2cause[chan_3], 1);
2209 /* 9.1.24 PAGING REQUEST 3 message received */
2210 static int gsm48_rr_rx_pag_req_3(struct osmocom_ms *ms, struct msgb *msg)
2212 struct gsm48_rrlayer *rr = &ms->rrlayer;
2213 struct gsm322_cellsel *cs = &ms->cellsel;
2214 struct gsm48_paging3 *pa = msgb_l3(msg);
2215 int payload_len = msgb_l3len(msg) - sizeof(*pa);
2216 int chan_1, chan_2, chan_3, chan_4;
2218 /* 3.3.1.1.2: ignore paging while not camping on a cell */
2219 if (rr->state != GSM48_RR_ST_IDLE || !cs->selected
2220 || (cs->state != GSM322_C3_CAMPED_NORMALLY
2221 && cs->state != GSM322_C7_CAMPED_ANY_CELL)) {
2222 LOGP(DRR, LOGL_INFO, "PAGING ignored, we are not camping.\n");
2226 LOGP(DPAG, LOGL_INFO, "PAGING REQUEST 3\n");
2228 if (payload_len < 0) { /* must include "channel needed", part of *pa */
2229 LOGP(DRR, LOGL_NOTICE, "Short read of PAGING REQUEST 3 "
2235 /* channel needed */
2236 chan_1 = pa->cneed1;
2237 chan_2 = pa->cneed2;
2238 chan_3 = pa->cneed3;
2239 chan_4 = pa->cneed4;
2241 if (ms->subscr.tmsi == ntohl(pa->tmsi1)
2242 && ms->subscr.tmsi_valid) {
2243 LOGP(DPAG, LOGL_INFO, "TMSI %08x matches\n", ntohl(pa->tmsi1));
2244 return gsm48_rr_chan_req(ms, gsm48_rr_chan2cause[chan_1], 1);
2246 LOGP(DPAG, LOGL_INFO, "TMSI %08x (not for us)\n",
2249 if (ms->subscr.tmsi == ntohl(pa->tmsi2)
2250 && ms->subscr.tmsi_valid) {
2251 LOGP(DPAG, LOGL_INFO, "TMSI %08x matches\n", ntohl(pa->tmsi2));
2252 return gsm48_rr_chan_req(ms, gsm48_rr_chan2cause[chan_2], 1);
2254 LOGP(DPAG, LOGL_INFO, "TMSI %08x (not for us)\n",
2257 if (ms->subscr.tmsi == ntohl(pa->tmsi3)
2258 && ms->subscr.tmsi_valid) {
2259 LOGP(DPAG, LOGL_INFO, "TMSI %08x matches\n", ntohl(pa->tmsi3));
2260 return gsm48_rr_chan_req(ms, gsm48_rr_chan2cause[chan_3], 1);
2262 LOGP(DPAG, LOGL_INFO, "TMSI %08x (not for us)\n",
2265 if (ms->subscr.tmsi == ntohl(pa->tmsi4)
2266 && ms->subscr.tmsi_valid) {
2267 LOGP(DPAG, LOGL_INFO, "TMSI %08x matches\n", ntohl(pa->tmsi4));
2268 return gsm48_rr_chan_req(ms, gsm48_rr_chan2cause[chan_4], 1);
2270 LOGP(DPAG, LOGL_INFO, "TMSI %08x (not for us)\n",
2277 * (immediate) assignment
2280 /* match request reference agains request history */
2281 static int gsm48_match_ra(struct osmocom_ms *ms, struct gsm48_req_ref *ref)
2283 struct gsm48_rrlayer *rr = &ms->rrlayer;
2285 uint8_t ia_t1, ia_t2, ia_t3;
2286 uint8_t cr_t1, cr_t2, cr_t3;
2288 for (i = 0; i < 3; i++) {
2289 /* filter confirmed RACH requests only */
2290 if (rr->cr_hist[i].valid && ref->ra == rr->cr_hist[i].ref.ra) {
2293 ia_t3 = (ref->t3_high << 3) | ref->t3_low;
2294 ref = &rr->cr_hist[i].ref;
2297 cr_t3 = (ref->t3_high << 3) | ref->t3_low;
2298 if (ia_t1 == cr_t1 && ia_t2 == cr_t2
2299 && ia_t3 == cr_t3) {
2300 LOGP(DRR, LOGL_INFO, "request %02x matches "
2301 "(fn=%d,%d,%d)\n", ref->ra, ia_t1,
2305 LOGP(DRR, LOGL_INFO, "request %02x matches "
2306 "but not frame number (IMM.ASS "
2307 "fn=%d,%d,%d != RACH fn=%d,%d,%d)\n",
2308 ref->ra, ia_t1, ia_t2, ia_t3,
2309 cr_t1, cr_t2, cr_t3);
2316 /* 9.1.18 IMMEDIATE ASSIGNMENT is received */
2317 static int gsm48_rr_rx_imm_ass(struct osmocom_ms *ms, struct msgb *msg)
2319 struct gsm48_rrlayer *rr = &ms->rrlayer;
2320 struct gsm48_imm_ass *ia = msgb_l3(msg);
2321 int ma_len = msgb_l3len(msg) - sizeof(*ia);
2322 uint8_t ch_type, ch_subch, ch_ts;
2323 struct gsm48_rr_cd cd;
2324 uint8_t *st, st_len;
2326 memset(&cd, 0, sizeof(cd));
2328 if (ma_len < 0 /* mobile allocation IE must be included */
2329 || ia->mob_alloc_len > ma_len) { /* short read of IE */
2330 LOGP(DRR, LOGL_NOTICE, "Short read of IMMEDIATE ASSIGNMENT "
2334 if (ia->mob_alloc_len > 8) {
2335 LOGP(DRR, LOGL_NOTICE, "Moble allocation in IMMEDIATE "
2336 "ASSIGNMENT too large.\n");
2341 st_len = ma_len - ia->mob_alloc_len;
2342 st = ia->mob_alloc + ia->mob_alloc_len;
2343 if (st_len >= 3 && st[0] == GSM48_IE_START_TIME)
2344 gsm48_decode_start_time(&cd, (struct gsm48_start_time *)(st+1));
2346 /* decode channel description */
2347 LOGP(DRR, LOGL_INFO, "IMMEDIATE ASSIGNMENT:\n");
2348 cd.chan_nr = ia->chan_desc.chan_nr;
2349 rsl_dec_chan_nr(cd.chan_nr, &ch_type, &ch_subch, &ch_ts);
2350 if (ia->chan_desc.h0.h) {
2352 gsm48_decode_chan_h1(&ia->chan_desc, &cd.tsc, &cd.maio,
2354 LOGP(DRR, LOGL_INFO, " (ta %d/%dm ra 0x%02x chan_nr 0x%02x "
2355 "MAIO %u HSN %u TS %u SS %u TSC %u)\n",
2357 ia->timing_advance * GSM_TA_CM / 100,
2358 ia->req_ref.ra, ia->chan_desc.chan_nr, cd.maio,
2359 cd.hsn, ch_ts, ch_subch, cd.tsc);
2362 gsm48_decode_chan_h0(&ia->chan_desc, &cd.tsc, &cd.arfcn);
2363 LOGP(DRR, LOGL_INFO, " (ta %d/%dm ra 0x%02x chan_nr 0x%02x "
2364 "ARFCN %u TS %u SS %u TSC %u)\n",
2366 ia->timing_advance * GSM_TA_CM / 100,
2367 ia->req_ref.ra, ia->chan_desc.chan_nr, cd.arfcn,
2368 ch_ts, ch_subch, cd.tsc);
2371 /* 3.3.1.1.2: ignore assignment while idle */
2372 if (rr->state != GSM48_RR_ST_CONN_PEND || rr->wait_assign == 0) {
2373 LOGP(DRR, LOGL_INFO, "Not for us, no request.\n");
2377 if (rr->wait_assign == 2) {
2378 LOGP(DRR, LOGL_INFO, "Ignoring, channel already assigned.\n");
2383 if (gsm48_match_ra(ms, &ia->req_ref)) {
2384 /* channel description */
2385 memcpy(&rr->cd_now, &cd, sizeof(rr->cd_now));
2386 /* timing advance */
2387 rr->cd_now.ta = ia->timing_advance;
2388 /* mobile allocation */
2389 memcpy(&rr->cd_now.mob_alloc_lv, &ia->mob_alloc_len,
2390 ia->mob_alloc_len + 1);
2391 rr->wait_assign = 2;
2392 return gsm48_rr_dl_est(ms);
2394 LOGP(DRR, LOGL_INFO, "Request, but not for us.\n");
2399 /* 9.1.19 IMMEDIATE ASSIGNMENT EXTENDED is received */
2400 static int gsm48_rr_rx_imm_ass_ext(struct osmocom_ms *ms, struct msgb *msg)
2402 struct gsm48_rrlayer *rr = &ms->rrlayer;
2403 struct gsm48_imm_ass_ext *ia = msgb_l3(msg);
2404 int ma_len = msgb_l3len(msg) - sizeof(*ia);
2405 uint8_t ch_type, ch_subch, ch_ts;
2406 struct gsm48_rr_cd cd1, cd2;
2407 uint8_t *st, st_len;
2409 memset(&cd1, 0, sizeof(cd1));
2410 memset(&cd2, 0, sizeof(cd2));
2412 if (ma_len < 0 /* mobile allocation IE must be included */
2413 || ia->mob_alloc_len > ma_len) { /* short read of IE */
2414 LOGP(DRR, LOGL_NOTICE, "Short read of IMMEDIATE ASSIGNMENT "
2415 "EXTENDED message.\n");
2418 if (ia->mob_alloc_len > 4) {
2419 LOGP(DRR, LOGL_NOTICE, "Moble allocation in IMMEDIATE "
2420 "ASSIGNMENT EXTENDED too large.\n");
2425 st_len = ma_len - ia->mob_alloc_len;
2426 st = ia->mob_alloc + ia->mob_alloc_len;
2427 if (st_len >= 3 && st[0] == GSM48_IE_START_TIME) {
2428 gsm48_decode_start_time(&cd1,
2429 (struct gsm48_start_time *)(st+1));
2430 memcpy(&cd2, &cd1, sizeof(cd2));
2433 /* decode channel description */
2434 LOGP(DRR, LOGL_INFO, "IMMEDIATE ASSIGNMENT EXTENDED:\n");
2435 cd2.chan_nr = ia->chan_desc1.chan_nr;
2436 rsl_dec_chan_nr(cd1.chan_nr, &ch_type, &ch_subch, &ch_ts);
2437 if (ia->chan_desc1.h0.h) {
2439 gsm48_decode_chan_h1(&ia->chan_desc1, &cd1.tsc, &cd1.maio,
2441 LOGP(DRR, LOGL_INFO, " assignment 1 (ta %d/%dm ra 0x%02x "
2442 "chan_nr 0x%02x MAIO %u HSN %u TS %u SS %u TSC %u)\n",
2443 ia->timing_advance1,
2444 ia->timing_advance1 * GSM_TA_CM / 100,
2445 ia->req_ref1.ra, ia->chan_desc1.chan_nr, cd1.maio,
2446 cd1.hsn, ch_ts, ch_subch, cd1.tsc);
2449 gsm48_decode_chan_h0(&ia->chan_desc1, &cd1.tsc, &cd1.arfcn);
2450 LOGP(DRR, LOGL_INFO, " assignment 1 (ta %d/%dm ra 0x%02x "
2451 "chan_nr 0x%02x ARFCN %u TS %u SS %u TSC %u)\n",
2452 ia->timing_advance1,
2453 ia->timing_advance1 * GSM_TA_CM / 100,
2454 ia->req_ref1.ra, ia->chan_desc1.chan_nr, cd1.arfcn,
2455 ch_ts, ch_subch, cd1.tsc);
2457 cd2.chan_nr = ia->chan_desc2.chan_nr;
2458 rsl_dec_chan_nr(cd2.chan_nr, &ch_type, &ch_subch, &ch_ts);
2459 if (ia->chan_desc2.h0.h) {
2461 gsm48_decode_chan_h1(&ia->chan_desc2, &cd2.tsc, &cd2.maio,
2463 LOGP(DRR, LOGL_INFO, " assignment 2 (ta %d/%dm ra 0x%02x "
2464 "chan_nr 0x%02x MAIO %u HSN %u TS %u SS %u TSC %u)\n",
2465 ia->timing_advance2,
2466 ia->timing_advance2 * GSM_TA_CM / 100,
2467 ia->req_ref2.ra, ia->chan_desc2.chan_nr, cd2.maio,
2468 cd2.hsn, ch_ts, ch_subch, cd2.tsc);
2471 gsm48_decode_chan_h0(&ia->chan_desc2, &cd2.tsc, &cd2.arfcn);
2472 LOGP(DRR, LOGL_INFO, " assignment 2 (ta %d/%dm ra 0x%02x "
2473 "chan_nr 0x%02x ARFCN %u TS %u SS %u TSC %u)\n",
2474 ia->timing_advance2,
2475 ia->timing_advance2 * GSM_TA_CM / 100,
2476 ia->req_ref2.ra, ia->chan_desc2.chan_nr, cd2.arfcn,
2477 ch_ts, ch_subch, cd2.tsc);
2480 /* 3.3.1.1.2: ignore assignment while idle */
2481 if (rr->state != GSM48_RR_ST_CONN_PEND || rr->wait_assign == 0) {
2482 LOGP(DRR, LOGL_INFO, "Not for us, no request.\n");
2486 if (rr->wait_assign == 2) {
2487 LOGP(DRR, LOGL_INFO, "Ignoring, channel already assigned.\n");
2492 if (gsm48_match_ra(ms, &ia->req_ref1)) {
2493 /* channel description */
2494 memcpy(&rr->cd_now, &cd1, sizeof(rr->cd_now));
2495 /* timing advance */
2496 rr->cd_now.ta = ia->timing_advance1;
2497 /* mobile allocation */
2498 memcpy(&rr->cd_now.mob_alloc_lv, &ia->mob_alloc_len,
2499 ia->mob_alloc_len + 1);
2500 rr->wait_assign = 2;
2501 return gsm48_rr_dl_est(ms);
2504 if (gsm48_match_ra(ms, &ia->req_ref2)) {
2505 /* channel description */
2506 memcpy(&rr->cd_now, &cd2, sizeof(rr->cd_now));
2507 /* timing advance */
2508 rr->cd_now.ta = ia->timing_advance2;
2509 /* mobile allocation */
2510 memcpy(&rr->cd_now.mob_alloc_lv, &ia->mob_alloc_len,
2511 ia->mob_alloc_len + 1);
2512 rr->wait_assign = 2;
2513 return gsm48_rr_dl_est(ms);
2515 LOGP(DRR, LOGL_INFO, "Request, but not for us.\n");
2520 /* 9.1.20 IMMEDIATE ASSIGNMENT REJECT is received */
2521 static int gsm48_rr_rx_imm_ass_rej(struct osmocom_ms *ms, struct msgb *msg)
2523 struct gsm48_rrlayer *rr = &ms->rrlayer;
2524 struct gsm48_imm_ass_rej *ia = msgb_l3(msg);
2525 int payload_len = msgb_l3len(msg) - sizeof(*ia);
2527 struct gsm48_req_ref *req_ref;
2528 uint8_t t3122_value;
2530 /* 3.3.1.1.2: ignore assignment while idle */
2531 if (rr->state != GSM48_RR_ST_CONN_PEND || rr->wait_assign == 0)
2534 if (rr->wait_assign == 2) {
2538 if (payload_len < 0) {
2539 LOGP(DRR, LOGL_NOTICE, "Short read of IMMEDIATE ASSIGNMENT "
2540 "REJECT message.\n");
2544 for (i = 0; i < 4; i++) {
2545 /* request reference */
2546 req_ref = (struct gsm48_req_ref *)
2547 (((uint8_t *)&ia->req_ref1) + i * 4);
2548 LOGP(DRR, LOGL_INFO, "IMMEDIATE ASSIGNMENT REJECT "
2549 "(ref 0x%02x)\n", req_ref->ra);
2550 if (gsm48_match_ra(ms, req_ref)) {
2551 /* wait indication */
2552 t3122_value = *(((uint8_t *)&ia->wait_ind1) + i * 4);
2554 start_rr_t3122(rr, t3122_value, 0);
2555 /* start timer 3126 if not already */
2556 if (!bsc_timer_pending(&rr->t3126))
2557 start_rr_t3126(rr, 5, 0); /* TODO improve! */
2558 /* stop assignmnet requests */
2561 /* wait until timer 3126 expires, then release
2562 * or wait for channel assignment */
2570 /* 9.1.1 ADDITIONAL ASSIGMENT is received */
2571 static int gsm48_rr_rx_add_ass(struct osmocom_ms *ms, struct msgb *msg)
2573 struct gsm48_hdr *gh = msgb_l3(msg);
2574 struct gsm48_add_ass *aa = (struct gsm48_add_ass *)gh->data;
2575 int payload_len = msgb_l3len(msg) - sizeof(*gh) - sizeof(*aa);
2576 struct tlv_parsed tp;
2578 if (payload_len < 0) {
2579 LOGP(DRR, LOGL_NOTICE, "Short read of ADDITIONAL ASSIGNMENT "
2581 return gsm48_rr_tx_rr_status(ms,
2582 GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2584 tlv_parse(&tp, &gsm48_rr_att_tlvdef, aa->data, payload_len, 0, 0);
2586 return gsm48_rr_tx_rr_status(ms, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2590 * measturement reports
2593 static int gsm48_rr_tx_meas_rep(struct osmocom_ms *ms)
2595 struct gsm48_rrlayer *rr = &ms->rrlayer;
2596 struct gsm48_rr_meas *meas = &rr->meas;
2598 struct gsm48_hdr *gh;
2599 struct gsm48_meas_res *mr;
2601 nmsg = gsm48_l3_msgb_alloc();
2604 gh = (struct gsm48_hdr *) msgb_put(nmsg, sizeof(*gh));
2605 mr = (struct gsm48_meas_res *) msgb_put(nmsg, sizeof(*mr));
2607 gh->proto_discr = GSM48_PDISC_RR;
2608 gh->msg_type = GSM48_MT_RR_MEAS_REP;
2610 /* measurement results */
2611 mr->rxlev_full = meas->rxlev_full;
2612 mr->rxlev_sub = meas->rxlev_sub;
2613 mr->rxqual_full = meas->rxqual_full;
2614 mr->rxqual_sub = meas->rxqual_sub;
2615 mr->dtx_used = meas->dtx;
2616 mr->ba_used = meas->ba;
2617 mr->meas_valid = meas->meas_valid;
2618 if (meas->ncell_na) {
2619 /* no results for serving cells */
2623 mr->no_nc_n_hi = meas->count >> 2;
2624 mr->no_nc_n_lo = meas->count & 3;
2626 mr->rxlev_nc1 = meas->rxlev_nc[0];
2627 mr->rxlev_nc2_hi = meas->rxlev_nc[1] >> 1;
2628 mr->rxlev_nc2_lo = meas->rxlev_nc[1] & 1;
2629 mr->rxlev_nc3_hi = meas->rxlev_nc[2] >> 2;
2630 mr->rxlev_nc3_lo = meas->rxlev_nc[2] & 3;
2631 mr->rxlev_nc4_hi = meas->rxlev_nc[3] >> 3;
2632 mr->rxlev_nc4_lo = meas->rxlev_nc[3] & 7;
2633 mr->rxlev_nc5_hi = meas->rxlev_nc[4] >> 4;
2634 mr->rxlev_nc5_lo = meas->rxlev_nc[4] & 15;
2635 mr->rxlev_nc6_hi = meas->rxlev_nc[5] >> 5;
2636 mr->rxlev_nc6_lo = meas->rxlev_nc[5] & 31;
2637 mr->bsic_nc1_hi = meas->bsic_nc[0] >> 3;
2638 mr->bsic_nc1_lo = meas->bsic_nc[0] & 7;
2639 mr->bsic_nc2_hi = meas->bsic_nc[1] >> 4;
2640 mr->bsic_nc2_lo = meas->bsic_nc[1] & 15;
2641 mr->bsic_nc3_hi = meas->bsic_nc[2] >> 5;
2642 mr->bsic_nc3_lo = meas->bsic_nc[2] & 31;
2643 mr->bsic_nc4 = meas->bsic_nc[3];
2644 mr->bsic_nc5 = meas->bsic_nc[4];
2645 mr->bsic_nc6 = meas->bsic_nc[5];
2646 mr->bcch_f_nc1 = meas->bcch_f_nc[0];
2647 mr->bcch_f_nc2 = meas->bcch_f_nc[1];
2648 mr->bcch_f_nc3 = meas->bcch_f_nc[2];
2649 mr->bcch_f_nc4 = meas->bcch_f_nc[3];
2650 mr->bcch_f_nc5_hi = meas->bcch_f_nc[4] >> 1;
2651 mr->bcch_f_nc5_lo = meas->bcch_f_nc[4] & 1;
2652 mr->bcch_f_nc6_hi = meas->bcch_f_nc[5] >> 2;
2653 mr->bcch_f_nc6_lo = meas->bcch_f_nc[5] & 3;
2655 return gsm48_send_rsl(ms, RSL_MT_UNIT_DATA_REQ, nmsg);
2659 * link establishment and release
2662 /* process "Loss Of Signal" */
2663 int gsm48_rr_los(struct osmocom_ms *ms)
2665 struct gsm48_rrlayer *rr = &ms->rrlayer;
2668 struct gsm48_rr_hdr *nrrh;
2670 LOGP(DSUM, LOGL_INFO, "Radio link lost signal\n");
2672 /* stop T3211 if running */
2676 case GSM48_RR_ST_CONN_PEND:
2677 LOGP(DRR, LOGL_INFO, "LOS during RACH request\n");
2679 /* stop pending RACH timer */
2682 case GSM48_RR_ST_DEDICATED:
2683 LOGP(DRR, LOGL_INFO, "LOS during dedicated mode, release "
2686 new_rr_state(rr, GSM48_RR_ST_REL_PEND);
2688 /* release message */
2690 nmsg = gsm48_l3_msgb_alloc();
2693 mode = msgb_put(nmsg, 2);
2694 mode[0] = RSL_IE_RELEASE_MODE;
2695 mode[1] = 1; /* local release */
2697 return gsm48_send_rsl_rel(ms, RSL_MT_REL_REQ, nmsg);
2698 case GSM48_RR_ST_REL_PEND:
2699 LOGP(DRR, LOGL_INFO, "LOS during RR release procedure, release "
2702 /* stop pending RACH timer */
2705 /* release locally */
2708 /* this should not happen */
2709 LOGP(DRR, LOGL_ERROR, "LOS in IDLE state, ignoring\n");
2713 /* send inication to upper layer */
2714 nmsg = gsm48_rr_msgb_alloc(GSM48_RR_REL_IND);
2717 nrrh = (struct gsm48_rr_hdr *)nmsg->data;
2718 nrrh->cause = RR_REL_CAUSE_LOST_SIGNAL;
2719 gsm48_rr_upmsg(ms, nmsg);
2722 new_rr_state(rr, GSM48_RR_ST_IDLE);
2726 /* activate link and send establish request */
2727 static int gsm48_rr_dl_est(struct osmocom_ms *ms)
2729 struct gsm48_rrlayer *rr = &ms->rrlayer;
2730 struct gsm_subscriber *subscr = &ms->subscr;
2731 struct gsm322_cellsel *cs = &ms->cellsel;
2732 struct gsm48_sysinfo *s = cs->si;
2733 struct gsm_settings *set = &ms->settings;
2735 struct gsm48_hdr *gh;
2736 struct gsm48_pag_rsp *pr;
2738 uint8_t ch_type, ch_subch, ch_ts;
2743 gsm48_decode_mobile_alloc(s, rr->cd_now.mob_alloc_lv + 1,
2744 rr->cd_now.mob_alloc_lv[0], ma, &ma_len, 0);
2746 LOGP(DRR, LOGL_NOTICE, "Hopping, but no allocation\n");
2754 /* clear all sequence numbers for all possible PDs */
2757 /* send DL_EST_REQ */
2758 if (rr->rr_est_msg) {
2759 LOGP(DRR, LOGL_INFO, "sending establish message\n");
2761 /* use queued message */
2762 nmsg = rr->rr_est_msg;
2765 /* set sequence number and increment */
2766 gsm48_apply_v_sd(rr, nmsg);
2768 /* create paging response */
2769 nmsg = gsm48_l3_msgb_alloc();
2772 gh = (struct gsm48_hdr *) msgb_put(nmsg, sizeof(*gh));
2773 gh->proto_discr = GSM48_PDISC_RR;
2774 gh->msg_type = GSM48_MT_RR_PAG_RESP;
2775 pr = (struct gsm48_pag_rsp *) msgb_put(nmsg, sizeof(*pr));
2777 pr->key_seq = subscr->key_seq;
2779 pr->cm2_len = sizeof(pr->cm2);
2780 gsm48_rr_enc_cm2(ms, &pr->cm2);
2781 /* mobile identity */
2782 if (ms->subscr.tmsi_valid) {
2783 gsm48_generate_mid_from_tmsi(mi, subscr->tmsi);
2784 LOGP(DRR, LOGL_INFO, "sending paging response with "
2786 } else if (subscr->imsi[0]) {
2787 gsm48_generate_mid_from_imsi(mi, subscr->imsi);
2788 LOGP(DRR, LOGL_INFO, "sending paging response with "
2792 mi[2] = 0xf0 | GSM_MI_TYPE_NONE;
2793 LOGP(DRR, LOGL_INFO, "sending paging response without "
2796 msgb_put(nmsg, 1 + mi[1]);
2797 memcpy(pr->data, mi + 1, 1 + mi[1]);
2800 /* reset scheduler */
2801 LOGP(DRR, LOGL_INFO, "resetting scheduler\n");
2802 l1ctl_tx_reset_req(ms, L1CTL_RES_T_SCHED);
2804 /* setting (new) timing advance */
2805 rr->ind_ta = rr->cd_now.ta;
2806 LOGP(DRR, LOGL_INFO, "setting indicated TA %d (actual TA %d)\n",
2807 rr->ind_ta, rr->ind_ta - set->alter_delay);
2808 l1ctl_tx_param_req(ms, rr->ind_ta - set->alter_delay,
2809 (set->alter_tx_power) ? set->alter_tx_power_value
2810 : rr->ind_tx_power);
2812 /* activate channel */
2813 LOGP(DRR, LOGL_INFO, "activating channel\n");
2815 RSL_MT_ to activate channel with all the cd_now informations
2817 rsl_dec_chan_nr(rr->cd_now.chan_nr, &ch_type, &ch_subch, &ch_ts);
2818 if ((ch_type != RSL_CHAN_SDCCH8_ACCH
2819 && ch_type != RSL_CHAN_SDCCH4_ACCH
2820 && ch_type != RSL_CHAN_Bm_ACCHs) /*|| ch_ts > 4*/ || ch_subch >= 4) {
2821 printf("Channel type %d, subch %d, ts %d not supported, "
2822 "exitting.\n", ch_type, ch_subch, ch_ts);
2826 l1ctl_tx_dm_est_req_h1(ms, rr->cd_now.maio, rr->cd_now.hsn,
2827 ma, ma_len, rr->cd_now.chan_nr, rr->cd_now.tsc);
2829 l1ctl_tx_dm_est_req_h0(ms, rr->cd_now.arfcn, rr->cd_now.chan_nr,
2833 /* start establishmnet */
2834 return gsm48_send_rsl(ms, RSL_MT_EST_REQ, nmsg);
2837 /* the link is established */
2838 static int gsm48_rr_estab_cnf(struct osmocom_ms *ms, struct msgb *msg)
2840 struct gsm48_rrlayer *rr = &ms->rrlayer;
2844 /* if MM has releases before confirm, we start release */
2845 if (rr->state == GSM48_RR_ST_REL_PEND) {
2846 LOGP(DRR, LOGL_INFO, "MM already released RR.\n");
2847 /* release message */
2848 nmsg = gsm48_l3_msgb_alloc();
2851 mode = msgb_put(nmsg, 2);
2852 mode[0] = RSL_IE_RELEASE_MODE;
2853 mode[1] = 0; /* normal release */
2855 return gsm48_send_rsl_rel(ms, RSL_MT_REL_REQ, nmsg);
2859 new_rr_state(rr, GSM48_RR_ST_DEDICATED);
2861 /* send confirm to upper layer */
2862 nmsg = gsm48_rr_msgb_alloc(
2863 (rr->rr_est_req) ? GSM48_RR_EST_CNF : GSM48_RR_EST_IND);
2866 return gsm48_rr_upmsg(ms, nmsg);
2869 /* the link is released in pending state (by l2) */
2870 static int gsm48_rr_rel_ind(struct osmocom_ms *ms, struct msgb *msg)
2872 struct gsm48_rrlayer *rr = &ms->rrlayer;
2874 struct gsm48_rr_hdr *nrrh;
2876 LOGP(DSUM, LOGL_INFO, "Radio link is released\n");
2878 /* send inication to upper layer */
2879 nmsg = gsm48_rr_msgb_alloc(GSM48_RR_REL_IND);
2882 nrrh = (struct gsm48_rr_hdr *)nmsg->data;
2883 nrrh->cause = RR_REL_CAUSE_NORMAL;
2884 gsm48_rr_upmsg(ms, nmsg);
2886 /* start release timer, so UA will be transmitted */
2887 start_rr_t_rel_wait(rr, 1, 500000);
2889 /* pending release */
2890 new_rr_state(rr, GSM48_RR_ST_REL_PEND);
2895 /* 9.1.7 CHANNEL RELEASE is received */
2896 static int gsm48_rr_rx_chan_rel(struct osmocom_ms *ms, struct msgb *msg)
2898 struct gsm48_rrlayer *rr = &ms->rrlayer;
2899 struct gsm48_hdr *gh = msgb_l3(msg);
2900 struct gsm48_chan_rel *cr = (struct gsm48_chan_rel *)gh->data;
2901 int payload_len = msgb_l3len(msg) - sizeof(*gh) - sizeof(*cr);
2902 struct tlv_parsed tp;
2906 if (payload_len < 0) {
2907 LOGP(DRR, LOGL_NOTICE, "Short read of CHANNEL RELEASE "
2909 return gsm48_rr_tx_rr_status(ms,
2910 GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2912 tlv_parse(&tp, &gsm48_rr_att_tlvdef, cr->data, payload_len, 0, 0);
2914 LOGP(DRR, LOGL_INFO, "channel release request with cause 0x%02x)\n",
2918 if (TLVP_PRESENT(&tp, GSM48_IE_BA_RANGE)) {
2919 gsm48_decode_ba_range(TLVP_VAL(&tp, GSM48_IE_BA_RANGE),
2920 *(TLVP_VAL(&tp, GSM48_IE_BA_RANGE) - 1), rr->ba_range,
2922 sizeof(rr->ba_range) / sizeof(rr->ba_range[0]));
2923 /* NOTE: the ranges are kept until IDLE state is returned
2924 * (see new_rr_state)
2928 new_rr_state(rr, GSM48_RR_ST_REL_PEND);
2930 /* start T3110, so that two DISCs can be sent due to T200 timeout */
2931 start_rr_t3110(rr, 1, 500000);
2933 /* disconnect the main signalling link */
2934 nmsg = gsm48_l3_msgb_alloc();
2937 mode = msgb_put(nmsg, 2);
2938 mode[0] = RSL_IE_RELEASE_MODE;
2939 mode[1] = 0; /* normal release */
2940 return gsm48_send_rsl_rel(ms, RSL_MT_REL_REQ, nmsg);
2944 * chanel mode modify, assignment, and handover
2947 /* 9.1.6 sending CHANNEL MODE MODIFY ACKNOWLEDGE */
2948 static int gsm48_rr_tx_chan_modify_ack(struct osmocom_ms *ms,
2949 struct gsm48_chan_desc *cd, uint8_t mode)
2952 struct gsm48_hdr *gh;
2953 struct gsm48_chan_mode_modify *cm;
2955 LOGP(DRR, LOGL_INFO, "CHAN.MODE.MOD ACKNOWLEDGE\n");
2957 nmsg = gsm48_l3_msgb_alloc();
2960 gh = (struct gsm48_hdr *) msgb_put(nmsg, sizeof(*gh));
2961 cm = (struct gsm48_chan_mode_modify *) msgb_put(nmsg, sizeof(*cm));
2963 gh->proto_discr = GSM48_PDISC_RR;
2964 gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF_ACK;
2967 memcpy(&cm->chan_desc, cd, sizeof(struct gsm48_chan_desc));
2971 return gsm48_send_rsl(ms, RSL_MT_DATA_REQ, nmsg);
2974 /* 9.1.5 CHANNEL MODE MODIFY is received */
2975 static int gsm48_rr_rx_chan_modify(struct osmocom_ms *ms, struct msgb *msg)
2977 struct gsm48_rrlayer *rr = &ms->rrlayer;
2978 struct gsm48_hdr *gh = msgb_l3(msg);
2979 struct gsm48_chan_mode_modify *cm =
2980 (struct gsm48_chan_mode_modify *)gh->data;
2981 int payload_len = msgb_l3len(msg) - sizeof(*gh) - sizeof(*cm);
2982 struct gsm48_rr_cd *cd = &rr->cd_now;
2983 uint8_t ch_type, ch_subch, ch_ts;
2986 LOGP(DRR, LOGL_INFO, "CHANNEL MODE MODIFY\n");
2989 if (payload_len < 0) {
2990 LOGP(DRR, LOGL_NOTICE, "Short read of CHANNEL MODE MODIFY "
2992 return gsm48_rr_tx_rr_status(ms,
2993 GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2996 /* decode channel description */
2997 cd->chan_nr = cm->chan_desc.chan_nr;
2998 rsl_dec_chan_nr(cd->chan_nr, &ch_type, &ch_subch, &ch_ts);
2999 if (cm->chan_desc.h0.h) {
3001 gsm48_decode_chan_h1(&cm->chan_desc, &cd->tsc, &cd->maio,
3003 LOGP(DRR, LOGL_INFO, " (chan_nr 0x%02x MAIO %u HSN %u TS %u "
3004 "SS %u TSC %u mode %u)\n", cm->chan_desc.chan_nr,
3005 cd->maio, cd->hsn, ch_ts, ch_subch, cd->tsc, cm->mode);
3008 gsm48_decode_chan_h0(&cm->chan_desc, &cd->tsc, &cd->arfcn);
3009 LOGP(DRR, LOGL_INFO, " (chan_nr 0x%02x ARFCN %u TS %u SS %u "
3010 "TSC %u mode %u)\n", cm->chan_desc.chan_nr, cd->arfcn,
3011 ch_ts, ch_subch, cd->tsc, cm->mode);
3016 case GSM48_CMODE_SIGN:
3017 LOGP(DRR, LOGL_INFO, "Mode set to signalling.\n");
3019 case GSM48_CMODE_SPEECH_V1:
3020 LOGP(DRR, LOGL_INFO, "Mode set to GSM full-rate codec.\n");
3023 LOGP(DRR, LOGL_ERROR, "Mode %u not supported!\n", mode);
3026 return gsm48_rr_tx_chan_modify_ack(ms, &cm->chan_desc, mode);
3029 /* 9.1.3 sending ASSIGNMENT COMPLETE */
3030 static int gsm48_rr_tx_ass_cpl(struct osmocom_ms *ms, uint8_t cause)
3033 struct gsm48_hdr *gh;
3034 struct gsm48_ass_cpl *ac;
3036 LOGP(DRR, LOGL_INFO, "ASSIGNMENT COMPLETE (cause #%d)\n", cause);
3038 nmsg = gsm48_l3_msgb_alloc();
3041 gh = (struct gsm48_hdr *) msgb_put(nmsg, sizeof(*gh));
3042 ac = (struct gsm48_ass_cpl *) msgb_put(nmsg, sizeof(*ac));
3044 gh->proto_discr = GSM48_PDISC_RR;
3045 gh->msg_type = GSM48_MT_RR_ASS_COMPL;
3048 ac->rr_cause = cause;
3050 return gsm48_send_rsl(ms, RSL_MT_DATA_REQ, nmsg);
3053 /* 9.1.4 sending ASSIGNMENT FAILURE */
3054 static int gsm48_rr_tx_ass_fail(struct osmocom_ms *ms, uint8_t cause)
3057 struct gsm48_hdr *gh;
3058 struct gsm48_ass_fail *af;
3060 LOGP(DRR, LOGL_INFO, "ASSIGNMENT FAILURE (cause #%d)\n", cause);
3062 nmsg = gsm48_l3_msgb_alloc();
3065 gh = (struct gsm48_hdr *) msgb_put(nmsg, sizeof(*gh));
3066 af = (struct gsm48_ass_fail *) msgb_put(nmsg, sizeof(*af));
3068 gh->proto_discr = GSM48_PDISC_RR;
3069 gh->msg_type = GSM48_MT_RR_ASS_COMPL;
3072 af->rr_cause = cause;
3074 return gsm48_send_rsl(ms, RSL_MT_DATA_REQ, nmsg);
3077 /* 9.1.2 ASSIGNMENT COMMAND is received */
3078 static int gsm48_rr_rx_ass_cmd(struct osmocom_ms *ms, struct msgb *msg)
3080 // struct gsm48_rrlayer *rr = &ms->rrlayer;
3081 struct gsm48_hdr *gh = msgb_l3(msg);
3082 struct gsm48_ass_cmd *ac = (struct gsm48_ass_cmd *)gh->data;
3083 int payload_len = msgb_l3len(msg) - sizeof(*gh) - sizeof(*ac);
3084 struct tlv_parsed tp;
3085 struct gsm48_rr_cd cd;
3087 LOGP(DRR, LOGL_INFO, "ASSIGNMENT COMMAND\n");
3089 memset(&cd, 0, sizeof(cd));
3091 if (payload_len < 0) {
3092 LOGP(DRR, LOGL_NOTICE, "Short read of ASSIGNMENT COMMAND "
3094 return gsm48_rr_tx_rr_status(ms,
3095 GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
3097 tlv_parse(&tp, &gsm48_rr_att_tlvdef, ac->data, payload_len, 0, 0);
3100 /* channel description */
3101 memcpy(&cd.chan_desc, &ac->chan_desc, sizeof(chan_desc));
3103 cd.power_command = ac->power_command;
3104 /* frequency list, after timer */
3105 tlv_copy(&cd.fl, sizeof(fl_after), &tp, GSM48_IE_FRQLIST_AFTER);
3106 /* cell channel description */
3107 tlv_copy(&cd.ccd, sizeof(ccd), &tp, GSM48_IE_CELL_CH_DESC);
3108 /* multislot allocation */
3109 tlv_copy(&cd.multia, sizeof(ma), &tp, GSM48_IE_MSLOT_DESC);
3111 tlv_copy(&cd.chanmode, sizeof(chanmode), &tp, GSM48_IE_CHANMODE_1);
3112 /* mobile allocation, after time */
3113 tlv_copy(&cd.moba_after, sizeof(moba_after), &tp, GSM48_IE_MOB_AL_AFTER);
3115 tlv_copy(&cd.start, sizeof(start), &tp, GSM_IE_START_TIME);
3116 /* frequency list, before time */
3117 tlv_copy(&cd.fl_before, sizeof(fl_before), &tp, GSM48_IE_FRQLIST_BEFORE);
3118 /* channel description, before time */
3119 tlv_copy(&cd.chan_desc_before, sizeof(cd_before), &tp, GSM48_IE_CHDES_1_BEFORE);
3120 /* frequency channel sequence, before time */
3121 tlv_copy(&cd.fcs_before, sizeof(fcs_before), &tp, GSM48_IE_FRQSEQ_BEFORE);
3122 /* mobile allocation, before time */
3123 tlv_copy(&cd.moba_before, sizeof(moba_before), &tp, GSM48_IE_MOB_AL_BEFORE);
3124 /* cipher mode setting */
3125 if (TLVP_PRESENT(&tp, GSM48_IE_CIP_MODE_SET))
3126 cd.cipher = *TLVP_VAL(&tp, GSM48_IE_CIP_MODE_SET);
3131 LOGP(DRR, LOGL_INFO, "No current cell allocation available.\n");
3132 return gsm48_rr_tx_ass_fail(ms, GSM48_GSM48_RR_CAUSE_NO_CELL_ALLOC_A);
3135 if (not supported) {
3136 LOGP(DRR, LOGL_INFO, "New channel is not supported.\n");
3137 return gsm48_rr_tx_ass_fail(ms, GSM48_RR_CAUSE_CHAN_MODE_UNACCEPT);
3140 if (freq not supported) {
3141 LOGP(DRR, LOGL_INFO, "New frequency is not supported.\n");
3142 return gsm48_rr_tx_ass_fail(ms, GSM48_RR_CAUSE_FREQ_NOT_IMPL);
3145 /* store current channel descriptions, to return in case of failure */
3146 memcpy(&rr->chan_last, &rr->chan_desc, sizeof(*cd));
3147 /* copy new description */
3148 memcpy(&rr->chan_desc, cd, sizeof(cd));
3150 /* start suspension of current link */
3151 nmsg = gsm48_l3_msgb_alloc();
3154 gsm48_send_rsl(ms, RSL_MT_SUSP_REQ, msg);
3156 /* change into special assignment suspension state */
3157 rr->assign_susp_state = 1;
3158 rr->resume_last_state = 0;
3160 return gsm48_rr_tx_ass_fail(ms, GSM48_RR_CAUSE_FREQ_NOT_IMPL);
3167 * radio ressource requests
3170 /* establish request for dedicated mode */
3171 static int gsm48_rr_est_req(struct osmocom_ms *ms, struct msgb *msg)
3173 struct gsm48_rrlayer *rr = &ms->rrlayer;
3174 struct gsm322_cellsel *cs = &ms->cellsel;
3175 struct gsm48_sysinfo *s = cs->si;
3176 struct gsm_subscriber *subscr = &ms->subscr;
3177 struct gsm48_rr_hdr *rrh = (struct gsm48_rr_hdr *) msg->data;
3178 struct gsm48_hdr *gh = msgb_l3(msg);
3181 struct gsm48_rr_hdr *nrrh;
3185 if (bsc_timer_pending(&rr->t3122)) {
3186 if (rrh->cause != RR_EST_CAUSE_EMERGENCY) {
3187 LOGP(DRR, LOGL_INFO, "T3122 running, rejecting!\n");
3188 cause = RR_REL_CAUSE_T3122;
3190 LOGP(DSUM, LOGL_INFO, "Establishing radio link not "
3192 nmsg = gsm48_rr_msgb_alloc(GSM48_RR_REL_IND);
3195 nrrh = (struct gsm48_rr_hdr *)nmsg->data;
3196 nrrh->cause = cause;
3197 return gsm48_rr_upmsg(ms, nmsg);
3199 LOGP(DRR, LOGL_INFO, "T3122 running, but emergency call\n");
3203 /* if state is not idle */
3204 if (rr->state != GSM48_RR_ST_IDLE) {
3205 LOGP(DRR, LOGL_INFO, "We are not IDLE yet, rejecting!\n");
3206 cause = RR_REL_CAUSE_TRY_LATER;
3211 if (!cs->selected) {
3212 LOGP(DRR, LOGL_INFO, "No cell selected, rejecting!\n");
3213 cause = RR_REL_CAUSE_TRY_LATER;
3217 /* check if camping */
3218 if (cs->state != GSM322_C3_CAMPED_NORMALLY
3219 && rrh->cause != RR_EST_CAUSE_EMERGENCY) {
3220 LOGP(DRR, LOGL_INFO, "Not camping normally, rejecting!\n");
3221 cause = RR_REL_CAUSE_EMERGENCY_ONLY;
3224 if (cs->state != GSM322_C3_CAMPED_NORMALLY
3225 && cs->state != GSM322_C7_CAMPED_ANY_CELL) {
3226 LOGP(DRR, LOGL_INFO, "Not camping, rejecting!\n");
3227 cause = RR_REL_CAUSE_TRY_LATER;
3231 /* check for relevant informations */
3233 LOGP(DRR, LOGL_INFO, "Not enough SI, rejecting!\n");
3234 cause = RR_REL_CAUSE_TRY_LATER;
3239 if (!subscr->acc_barr && s->cell_barr) {
3240 LOGP(DRR, LOGL_INFO, "Cell barred, rejecting!\n");
3241 cause = RR_REL_CAUSE_NOT_AUTHORIZED;
3244 if (rrh->cause == RR_EST_CAUSE_EMERGENCY)
3245 acc_class = subscr->acc_class | 0x0400;
3247 acc_class = subscr->acc_class & 0xfbff;
3248 if (!subscr->acc_barr && !(acc_class & (s->class_barr ^ 0xffff))) {
3249 LOGP(DRR, LOGL_INFO, "Cell barred for our access class (access "
3250 "%04x barred %04x)!\n", acc_class, s->class_barr);
3251 cause = RR_REL_CAUSE_NOT_AUTHORIZED;
3255 /* requested by RR */
3258 /* clone and store REQUEST message */
3260 LOGP(DRR, LOGL_ERROR, "Error, missing l3 message\n");
3263 rr->rr_est_msg = gsm48_l3_msgb_alloc();
3264 if (!rr->rr_est_msg)
3266 memcpy(msgb_put(rr->rr_est_msg, msgb_l3len(msg)),
3267 msgb_l3(msg), msgb_l3len(msg));
3269 /* request channel */
3270 return gsm48_rr_chan_req(ms, rrh->cause, 0);
3273 /* send all queued messages down to layer 2 */
3274 static int gsm48_rr_dequeue_down(struct osmocom_ms *ms)
3276 struct gsm48_rrlayer *rr = &ms->rrlayer;
3279 while((msg = msgb_dequeue(&rr->downqueue))) {
3280 LOGP(DRR, LOGL_INFO, "Sending queued message.\n");
3281 gsm48_send_rsl(ms, RSL_MT_DATA_REQ, msg);
3287 /* 3.4.2 transfer data in dedicated mode */
3288 static int gsm48_rr_data_req(struct osmocom_ms *ms, struct msgb *msg)
3290 struct gsm48_rrlayer *rr = &ms->rrlayer;
3292 if (rr->state != GSM48_RR_ST_DEDICATED) {
3297 /* pull RR header */
3298 msgb_pull(msg, sizeof(struct gsm48_rr_hdr));
3300 /* set sequence number and increment */
3301 gsm48_apply_v_sd(rr, msg);
3303 /* queue message, during handover or assignment procedure */
3304 if (rr->hando_susp_state || rr->assign_susp_state) {
3305 LOGP(DRR, LOGL_INFO, "Queueing message during suspend.\n");
3306 msgb_enqueue(&rr->downqueue, msg);
3310 /* forward message */
3311 return gsm48_send_rsl(ms, RSL_MT_DATA_REQ, msg);
3315 * data indications from data link
3318 /* 3.4.2 data from layer 2 to RR and upper layer*/
3319 static int gsm48_rr_data_ind(struct osmocom_ms *ms, struct msgb *msg)
3321 struct gsm48_hdr *gh = msgb_l3(msg);
3322 struct gsm48_rr_hdr *rrh;
3323 uint8_t pdisc = gh->proto_discr & 0x0f;
3325 if (pdisc == GSM48_PDISC_RR) {
3327 uint8_t skip_ind = (gh->proto_discr & 0xf0) >> 4;
3329 /* ignore if skip indicator is not B'0000' */
3333 switch(gh->msg_type) {
3334 case GSM48_MT_RR_ADD_ASS:
3335 rc = gsm48_rr_rx_add_ass(ms, msg);
3337 case GSM48_MT_RR_ASS_CMD:
3338 rc = gsm48_rr_rx_ass_cmd(ms, msg);
3341 case GSM48_MT_RR_CIP_MODE_CMD:
3342 rc = gsm48_rr_rx_cip_mode_cmd(ms, msg);
3345 case GSM48_MT_RR_CLSM_ENQ:
3346 rc = gsm48_rr_rx_cm_enq(ms, msg);
3348 case GSM48_MT_RR_CHAN_MODE_MODIF:
3349 rc = gsm48_rr_rx_chan_modify(ms, msg);
3352 case GSM48_MT_RR_HANDO_CMD:
3353 rc = gsm48_rr_rx_hando_cmd(ms, msg);
3355 case GSM48_MT_RR_FREQ_REDEF:
3356 rc = gsm48_rr_rx_freq_redef(ms, msg);
3359 case GSM48_MT_RR_CHAN_REL:
3360 rc = gsm48_rr_rx_chan_rel(ms, msg);
3363 LOGP(DRR, LOGL_NOTICE, "Message type 0x%02x unknown.\n",
3366 /* status message */
3367 gsm48_rr_tx_rr_status(ms, GSM48_RR_CAUSE_MSG_TYPE_N);
3374 /* pull off RSL header up to L3 message */
3375 msgb_pull(msg, (long)msgb_l3(msg) - (long)msg->data);
3377 /* push RR header */
3378 msgb_push(msg, sizeof(struct gsm48_rr_hdr));
3379 rrh = (struct gsm48_rr_hdr *)msg->data;
3380 rrh->msg_type = GSM48_RR_DATA_IND;
3382 return gsm48_rr_upmsg(ms, msg);
3385 /* receive BCCH at RR layer */
3386 static int gsm48_rr_rx_bcch(struct osmocom_ms *ms, struct msgb *msg)
3388 struct gsm48_system_information_type_header *sih = msgb_l3(msg);
3390 switch (sih->system_information) {
3391 case GSM48_MT_RR_SYSINFO_1:
3392 return gsm48_rr_rx_sysinfo1(ms, msg);
3393 case GSM48_MT_RR_SYSINFO_2:
3394 return gsm48_rr_rx_sysinfo2(ms, msg);
3395 case GSM48_MT_RR_SYSINFO_2bis:
3396 return gsm48_rr_rx_sysinfo2bis(ms, msg);
3397 case GSM48_MT_RR_SYSINFO_2ter:
3398 return gsm48_rr_rx_sysinfo2ter(ms, msg);
3399 case GSM48_MT_RR_SYSINFO_3:
3400 return gsm48_rr_rx_sysinfo3(ms, msg);
3401 case GSM48_MT_RR_SYSINFO_4:
3402 return gsm48_rr_rx_sysinfo4(ms, msg);
3405 LOGP(DRR, LOGL_NOTICE, "BCCH message type 0x%02x not sup.\n",
3406 sih->system_information);
3412 /* receive CCCH at RR layer */
3413 static int gsm48_rr_rx_pch_agch(struct osmocom_ms *ms, struct msgb *msg)
3415 struct gsm48_system_information_type_header *sih = msgb_l3(msg);
3417 switch (sih->system_information) {
3418 case GSM48_MT_RR_PAG_REQ_1:
3419 return gsm48_rr_rx_pag_req_1(ms, msg);
3420 case GSM48_MT_RR_PAG_REQ_2:
3421 return gsm48_rr_rx_pag_req_2(ms, msg);
3422 case GSM48_MT_RR_PAG_REQ_3:
3423 return gsm48_rr_rx_pag_req_3(ms, msg);
3425 case GSM48_MT_RR_IMM_ASS:
3426 return gsm48_rr_rx_imm_ass(ms, msg);
3427 case GSM48_MT_RR_IMM_ASS_EXT:
3428 return gsm48_rr_rx_imm_ass_ext(ms, msg);
3429 case GSM48_MT_RR_IMM_ASS_REJ:
3430 return gsm48_rr_rx_imm_ass_rej(ms, msg);
3433 LOGP(DRR, LOGL_NOTICE, "CCCH message type 0x%02x unknown.\n",
3434 sih->system_information);
3440 /* receive ACCH at RR layer */
3441 static int gsm48_rr_rx_acch(struct osmocom_ms *ms, struct msgb *msg)
3443 struct gsm48_rrlayer *rr = &ms->rrlayer;
3444 struct gsm_settings *set = &ms->settings;
3445 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
3446 struct gsm48_system_information_type_header *sih = msgb_l3(msg);
3447 uint8_t ind_ta, ind_tx_power;
3449 if (msgb_l2len(msg) < sizeof(*rllh) + 2 + 2) {
3450 LOGP(DRR, LOGL_ERROR, "Missing TA and TX_POWER IEs\n");
3454 ind_ta = rllh->data[1];
3455 ind_tx_power = rllh->data[3];
3456 LOGP(DRR, LOGL_INFO, "Indicated ta %d (actual ta %d)\n",
3457 ind_ta, ind_ta - set->alter_delay);
3458 LOGP(DRR, LOGL_INFO, "Indicated tx_power %d\n",
3460 if (ind_ta != rr->ind_ta || ind_tx_power != rr->ind_tx_power) {
3461 LOGP(DRR, LOGL_INFO, "setting new ta and tx_power\n");
3462 l1ctl_tx_param_req(ms, ind_ta - set->alter_delay,
3463 (set->alter_tx_power) ? set->alter_tx_power_value
3465 rr->ind_ta = ind_ta;
3466 rr->ind_tx_power = ind_tx_power;
3469 switch (sih->system_information) {
3470 case GSM48_MT_RR_SYSINFO_5:
3471 return gsm48_rr_rx_sysinfo5(ms, msg);
3472 case GSM48_MT_RR_SYSINFO_5bis:
3473 return gsm48_rr_rx_sysinfo5bis(ms, msg);
3474 case GSM48_MT_RR_SYSINFO_5ter:
3475 return gsm48_rr_rx_sysinfo5ter(ms, msg);
3476 case GSM48_MT_RR_SYSINFO_6:
3477 return gsm48_rr_rx_sysinfo6(ms, msg);
3479 LOGP(DRR, LOGL_NOTICE, "ACCH message type 0x%02x unknown.\n",
3480 sih->system_information);
3485 /* unit data from layer 2 to RR layer */
3486 static int gsm48_rr_unit_data_ind(struct osmocom_ms *ms, struct msgb *msg)
3488 struct gsm48_rrlayer *rr = &ms->rrlayer;
3489 struct gsm322_cellsel *cs = &ms->cellsel;
3490 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
3491 struct tlv_parsed tv;
3492 uint8_t ch_type, ch_subch, ch_ts;
3494 DEBUGP(DRSL, "RSLms UNIT DATA IND chan_nr=0x%02x link_id=0x%02x\n",
3495 rllh->chan_nr, rllh->link_id);
3497 rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh));
3498 if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) {
3499 DEBUGP(DRSL, "UNIT_DATA_IND without L3 INFO ?!?\n");
3502 msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO);
3504 if (cs->ccch_state != GSM322_CCCH_ST_SYNC
3505 && cs->ccch_state != GSM322_CCCH_ST_DATA)
3508 /* when camping, start/reset loss timer */
3509 if (cs->state == GSM322_C3_CAMPED_NORMALLY
3510 || cs->state == GSM322_C7_CAMPED_ANY_CELL) {
3511 struct gsm48_sysinfo *s = &ms->cellsel.sel_si;
3513 set radio link timeout on layer 1
3514 it is the number of subsequent BCCH blocks. (about 1/4 seconds)
3516 /* use maximu loss timer, if to value is not available yet */
3517 start_loss_timer(cs, ((rr->state == GSM48_RR_ST_DEDICATED)
3518 ? ((s->sacch_radio_link_timeout) ? : 64)
3519 : s->bcch_radio_link_timeout) / 4, 0);
3523 /* temporary moved here until confirm is fixed */
3524 if (cs->ccch_state != GSM322_CCCH_ST_DATA) {
3525 LOGP(DCS, LOGL_INFO, "Channel provides data.\n");
3526 cs->ccch_state = GSM322_CCCH_ST_DATA;
3528 /* in dedicated mode */
3529 if (ms->rrlayer.state == GSM48_RR_ST_CONN_PEND)
3530 return gsm48_rr_tx_rand_acc(ms, NULL);
3532 /* set timer for reading BCCH */
3533 if (cs->state == GSM322_C2_STORED_CELL_SEL
3534 || cs->state == GSM322_C1_NORMAL_CELL_SEL
3535 || cs->state == GSM322_C6_ANY_CELL_SEL
3536 || cs->state == GSM322_C4_NORMAL_CELL_RESEL
3537 || cs->state == GSM322_C8_ANY_CELL_RESEL
3538 || cs->state == GSM322_C5_CHOOSE_CELL
3539 || cs->state == GSM322_C9_CHOOSE_ANY_CELL
3540 || cs->state == GSM322_PLMN_SEARCH
3541 || cs->state == GSM322_HPLMN_SEARCH)
3542 start_cs_timer(cs, ms->support.scan_to, 0);
3543 // TODO: timer depends on BCCH config
3546 rsl_dec_chan_nr(rllh->chan_nr, &ch_type, &ch_subch, &ch_ts);
3548 case RSL_CHAN_PCH_AGCH:
3549 return gsm48_rr_rx_pch_agch(ms, msg);
3551 return gsm48_rr_rx_bcch(ms, msg);
3552 case RSL_CHAN_SDCCH4_ACCH:
3553 return gsm48_rr_rx_acch(ms, msg);
3554 case RSL_CHAN_SDCCH8_ACCH:
3555 return gsm48_rr_rx_acch(ms, msg);
3557 LOGP(DRSL, LOGL_NOTICE, "RSL with chan_nr 0x%02x unknown.\n",
3563 /* 3.4.13.3 RR abort in dedicated mode (also in conn. pending mode) */
3564 static int gsm48_rr_abort_req(struct osmocom_ms *ms, struct msgb *msg)
3566 struct gsm48_rrlayer *rr = &ms->rrlayer;
3569 /* stop pending RACH timer */
3572 /* release "normally" if we are in dedicated mode */
3573 if (rr->state == GSM48_RR_ST_DEDICATED) {
3576 LOGP(DRR, LOGL_INFO, "Abort in dedicated state, send release "
3579 new_rr_state(rr, GSM48_RR_ST_REL_PEND);
3581 /* release message */
3582 nmsg = gsm48_l3_msgb_alloc();
3585 mode = msgb_put(nmsg, 2);
3586 mode[0] = RSL_IE_RELEASE_MODE;
3587 mode[1] = 0; /* normal release */
3588 return gsm48_send_rsl_rel(ms, RSL_MT_REL_REQ, nmsg);
3591 LOGP(DRR, LOGL_INFO, "Abort in connection pending state, return to "
3594 new_rr_state(rr, GSM48_RR_ST_IDLE);
3599 /* release confirm in dedicated mode */
3600 static int gsm48_rr_susp_cnf_dedicated(struct osmocom_ms *ms, struct msgb *msg)
3602 struct gsm48_rrlayer *rr = &ms->rrlayer;
3604 if (rr->hando_susp_state || rr->assign_susp_state) {
3607 /* change radio to new channel */
3608 //todo tx_ph_dm_est_req(ms, rr->cd_now.arfcn, rr->cd_now.chan_nr,
3611 /* send DL-ESTABLISH REQUEST */
3612 nmsg = gsm48_l3_msgb_alloc();
3615 gsm48_send_rsl(ms, RSL_MT_EST_REQ, nmsg);
3619 if (rr->hando_susp_state) {
3620 gsm48_rr_tx_hando_access(ms);
3621 rr->hando_acc_left = 3;
3628 /* release confirm */
3629 static int gsm48_rr_rel_cnf(struct osmocom_ms *ms, struct msgb *msg)
3631 struct gsm48_rrlayer *rr = &ms->rrlayer;
3633 struct gsm48_rr_hdr *nrrh;
3635 LOGP(DSUM, LOGL_INFO, "Requesting channel aborted\n");
3637 /* stop T3211 if running */
3640 /* send release indication */
3641 nmsg = gsm48_rr_msgb_alloc(GSM48_RR_REL_IND);
3644 nrrh = (struct gsm48_rr_hdr *)nmsg->data;
3645 nrrh->cause = RR_REL_CAUSE_NORMAL;
3646 gsm48_rr_upmsg(ms, nmsg);
3649 new_rr_state(rr, GSM48_RR_ST_IDLE);
3657 /* state trasitions for link layer messages (lower layer) */
3658 static struct dldatastate {
3661 int (*rout) (struct osmocom_ms *ms, struct msgb *msg);
3662 } dldatastatelist[] = {
3664 {SBIT(GSM48_RR_ST_IDLE) |
3665 SBIT(GSM48_RR_ST_CONN_PEND) |
3666 SBIT(GSM48_RR_ST_DEDICATED) |
3667 SBIT(GSM48_RR_ST_REL_PEND),
3668 RSL_MT_UNIT_DATA_IND, gsm48_rr_unit_data_ind},
3670 {SBIT(GSM48_RR_ST_DEDICATED), /* 3.4.2 */
3671 RSL_MT_DATA_IND, gsm48_rr_data_ind},
3674 {SBIT(GSM48_RR_ST_IDLE) |
3675 SBIT(GSM48_RR_ST_CONN_PEND) |
3676 SBIT(GSM48_RR_ST_REL_PEND),
3677 RSL_MT_EST_CONF, gsm48_rr_estab_cnf},
3680 {SBIT(GSM48_RR_ST_DEDICATED),
3681 RSL_MT_EST_CONF, gsm48_rr_estab_cnf_dedicated},
3684 RSL_MT_CONNECT_CNF, gsm48_rr_connect_cnf},
3689 {SBIT(GSM48_RR_ST_CONN_PEND) |
3690 SBIT(GSM48_RR_ST_DEDICATED),
3691 RSL_MT_REL_IND, gsm48_rr_rel_ind},
3693 {SBIT(GSM48_RR_ST_REL_PEND),
3694 RSL_MT_REL_CONF, gsm48_rr_rel_cnf},
3697 {SBIT(GSM48_RR_ST_DEDICATED),
3698 RSL_MT_SUSP_CONF, gsm48_rr_susp_cnf_dedicated},
3701 {SBIT(GSM48_RR_ST_DEDICATED),
3702 RSL_MT_CHAN_CNF, gsm48_rr_rand_acc_cnf_dedicated},
3705 RSL_MT_MDL_ERROR_IND, gsm48_rr_mdl_error_ind},
3709 #define DLDATASLLEN \
3710 (sizeof(dldatastatelist) / sizeof(struct dldatastate))
3712 static int gsm48_rcv_rll(struct osmocom_ms *ms, struct msgb *msg)
3714 struct gsm48_rrlayer *rr = &ms->rrlayer;
3715 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
3716 int msg_type = rllh->c.msg_type;
3720 if (msg_type != RSL_MT_UNIT_DATA_IND) {
3721 LOGP(DRSL, LOGL_INFO, "(ms %s) Received '%s' from L2 in state "
3722 "%s\n", ms->name, get_rsl_name(msg_type),
3723 gsm48_rr_state_names[rr->state]);
3726 /* find function for current state and message */
3727 for (i = 0; i < DLDATASLLEN; i++)
3728 if ((msg_type == dldatastatelist[i].type)
3729 && ((1 << rr->state) & dldatastatelist[i].states))
3731 if (i == DLDATASLLEN) {
3732 LOGP(DRSL, LOGL_NOTICE, "RSLms message unhandled\n");
3737 rc = dldatastatelist[i].rout(ms, msg);
3739 /* free msgb unless it is forwarded */
3740 if (dldatastatelist[i].rout != gsm48_rr_data_ind)
3746 static int gsm48_rcv_cch(struct osmocom_ms *ms, struct msgb *msg)
3748 struct gsm48_rrlayer *rr = &ms->rrlayer;
3749 struct abis_rsl_cchan_hdr *ch = msgb_l2(msg);
3750 int msg_type = ch->c.msg_type;
3753 LOGP(DRSL, LOGL_INFO, "(ms %s) Received '%s' from L2 in state "
3754 "%s\n", ms->name, get_rsl_name(msg_type),
3755 gsm48_rr_state_names[rr->state]);
3757 if (rr->state == GSM48_RR_ST_CONN_PEND
3758 && msg_type == RSL_MT_CHAN_CONF) {
3759 rc = gsm48_rr_tx_rand_acc(ms, msg);
3764 LOGP(DRSL, LOGL_NOTICE, "RSLms message unhandled\n");
3770 /* input function for L2 messags up to L3 */
3771 static int gsm48_rcv_rsl(struct osmocom_ms *ms, struct msgb *msg)
3773 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
3776 switch (rslh->msg_discr & 0xfe) {
3777 case ABIS_RSL_MDISC_RLL:
3778 rc = gsm48_rcv_rll(ms, msg);
3780 case ABIS_RSL_MDISC_COM_CHAN:
3781 rc = gsm48_rcv_cch(ms, msg);
3784 /* FIXME: implement this */
3785 LOGP(DRSL, LOGL_NOTICE, "unknown RSLms msg_discr 0x%02x\n",
3795 /* state trasitions for RR-SAP messages from up */
3796 static struct rrdownstate {
3799 int (*rout) (struct osmocom_ms *ms, struct msgb *msg);
3800 } rrdownstatelist[] = {
3801 /* NOTE: If not IDLE, it is rejected there. */
3802 {ALL_STATES, /* 3.3.1.1 */
3803 GSM48_RR_EST_REQ, gsm48_rr_est_req},
3805 {SBIT(GSM48_RR_ST_DEDICATED), /* 3.4.2 */
3806 GSM48_RR_DATA_REQ, gsm48_rr_data_req},
3808 {SBIT(GSM48_RR_ST_CONN_PEND) |
3809 SBIT(GSM48_RR_ST_DEDICATED), /* 3.4.13.3 */
3810 GSM48_RR_ABORT_REQ, gsm48_rr_abort_req},
3813 {SBIT(GSM48_RR_ST_DEDICATED),
3814 GSM48_RR_ACT_REQ, gsm48_rr_act_req},
3818 #define RRDOWNSLLEN \
3819 (sizeof(rrdownstatelist) / sizeof(struct rrdownstate))
3821 int gsm48_rr_downmsg(struct osmocom_ms *ms, struct msgb *msg)
3823 struct gsm48_rrlayer *rr = &ms->rrlayer;
3824 struct gsm48_rr_hdr *rrh = (struct gsm48_rr_hdr *) msg->data;
3825 int msg_type = rrh->msg_type;
3829 LOGP(DRR, LOGL_INFO, "(ms %s) Message '%s' received in state %s\n",
3830 ms->name, get_rr_name(msg_type),
3831 gsm48_rr_state_names[rr->state]);
3833 /* find function for current state and message */
3834 for (i = 0; i < RRDOWNSLLEN; i++)
3835 if ((msg_type == rrdownstatelist[i].type)
3836 && ((1 << rr->state) & rrdownstatelist[i].states))
3838 if (i == RRDOWNSLLEN) {
3839 LOGP(DRR, LOGL_NOTICE, "Message unhandled at this state.\n");
3844 rc = rrdownstatelist[i].rout(ms, msg);
3846 /* free msgb uless it is forwarded */
3847 if (rrdownstatelist[i].rout != gsm48_rr_data_req)
3857 int gsm48_rr_init(struct osmocom_ms *ms)
3859 struct gsm48_rrlayer *rr = &ms->rrlayer;
3861 memset(rr, 0, sizeof(*rr));
3864 LOGP(DRR, LOGL_INFO, "init Radio Ressource process\n");
3866 INIT_LLIST_HEAD(&rr->rsl_upqueue);
3867 INIT_LLIST_HEAD(&rr->downqueue);
3868 /* downqueue is handled here, so don't add_work */
3870 osmol2_register_handler(ms, &gsm48_rx_rsl);
3875 int gsm48_rr_exit(struct osmocom_ms *ms)
3877 struct gsm48_rrlayer *rr = &ms->rrlayer;
3880 LOGP(DRR, LOGL_INFO, "exit Radio Ressource process\n");
3883 while ((msg = msgb_dequeue(&rr->rsl_upqueue)))
3885 while ((msg = msgb_dequeue(&rr->downqueue)))
3888 if (rr->rr_est_msg) {
3889 msgb_free(rr->rr_est_msg);
3890 rr->rr_est_msg = NULL;
3893 stop_rr_t_monitor(rr);
3894 stop_rr_t_rel_wait(rr);
3904 the process above is complete
3905 ------------------------------------------------------------------------------
3928 stop timers on abort
3929 wird beim abbruch immer der gepufferte cm-service-request entfernt, auch beim verschicken?:
3931 todo rr_sync_ind when receiving ciph, re ass, channel mode modify
3933 todo change procedures, release procedure
3935 static int gsm48_rr_act_req(struct osmocom_ms *ms, struct gsm48_rr *rrmsg)
3942 /* memcopy of LV of given IE from tlv_parsed structure */
3943 static int tlv_copy(void *dest, int dest_len, struct tlv_parsed *tp, uint8_t ie)
3952 if (!TLVP_PRESENT(tp, ie))
3955 len = TLVP_LEN(tp, ie);
3958 if (len + 1 > dest_len)
3961 memcpy(dest, TLVP_VAL(tp, ie) - 1, len + 1);
3966 /* decode "Cell Description" (10.5.2.2) */
3967 static int gsm48_decode_cell_desc(struct gsm48_cell_desc *cd, uint16_t *arfcn, uint8_t *ncc uint8_t *bcc)
3969 *arfcn = (cd->bcch_hi << 8) + cd->bcch_lo;
3974 /* decode "Power Command" (10.5.2.28) and (10.5.2.28a) */
3975 static int gsm48_decode_power_cmd_acc(struct gsm48_power_cmd *pc, uint8_t *power_level uint8_t *atc)
3977 *power_level = pc->power_level;
3978 if (atc) /* only in case of 10.5.2.28a */
3982 /* decode "Synchronization Indication" (10.5.2.39) */
3983 static int gsm48_decode_power_cmd_acc(struct gsm48_rrlayer *rr, struct gsm48_rr_sync_ind *si)
3985 rr->ho_sync_ind = si->si;
3986 rr->ho_rot = si->rot;
3987 rr->ho_nci = si->nci;
3990 /* receiving HANDOVER COMMAND message (9.1.15) */
3991 static int gsm48_rr_rx_hando_cmd(struct osmocom_ms *ms, struct msgb *msg)
3993 struct gsm48_rrlayer *rr = ms->rrlayer;
3994 struct gsm48_hdr *gh = msgb_l3(msg);
3995 struct gsm48_ho_cmd *ho = (struct gsm48_ho_cmd *)gh->data;
3996 int payload_len = msgb_l3len(msg) - sizeof(*gh) - wirklich sizeof(*ho);
3997 struct tlv_parsed tp;
3998 struct gsm48_rr_cd cd;
4001 memset(&cd, 0, sizeof(cd));
4003 if (payload_len < 0) {
4004 LOGP(DRR, LOGL_NOTICE, "Short read of HANDOVER COMMAND message.\n");
4005 return gsm48_rr_tx_rr_status(ms, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
4007 tlv_parse(&tp, &gsm48_rr_att_tlvdef, ho->data, payload_len, 0, 0);
4009 /* decode Cell Description */
4010 gsm_decode_cell_desc(&ho->cell_desc, &cd.bcch_arfcn, &cd.ncc, &cd.bcc);
4011 /* Channel Description */
4012 memcpy(&rr->chan_desc.chan_desc, ho->chan_desc, 3);
4013 /* Handover Reference */
4014 rr->hando_ref = ho->ho_ref;
4015 /* Power Command and access type */
4016 gsm_decode_power_cmd_acc((struct gsm48_power_cmd *)&ho->power_command,
4017 &cd.power_level, cd.atc);
4018 /* Synchronization Indication */
4019 if (TLVP_PRESENT(&tp, GSM48_IE_SYNC_IND))
4020 gsm48_decode_sync_ind(rr,
4021 TLVP_VAL(&tp, GSM48_IE_SYNC_IND)-1, &cd);
4022 /* Frequency Sort List */
4023 if (TLVP_PRESENT(&tp, GSM48_IE_FREQ_SHORT_LIST))
4024 decode_freq_list(&ms->support, s->freq,
4025 TLVP_VAL(&tp, GSM48_IE_FREQ_SHORT_LIST),
4026 *(TLVP_VAL(&tp, GSM48_IE_FREQ_SHORT_LIST)-1),
4027 0xce, FREQ_TYPE_SERV);
4030 today: more IE parsing
4032 /* store current channel descriptions, to return in case of failure */
4033 memcpy(&rr->chan_last, &rr->chan_desc, sizeof(*cd));
4034 /* copy new description */
4035 memcpy(&rr->chan_desc, cd, sizeof(cd));
4037 /* start suspension of current link */
4038 nmsg = gsm48_l3_msgb_alloc();
4041 gsm48_send_rsl(ms, RSL_MT_SUSP_REQ, msg);
4043 /* change into special handover suspension state */
4044 rr->hando_susp_state = 1;
4045 rr->resume_last_state = 0;
4050 static int gsm48_rr_estab_cnf_dedicated(struct osmocom_ms *ms, struct msgb *msg)
4052 if (rr->hando_susp_state || rr->assign_susp_state) {
4053 if (rr->resume_last_state) {
4054 rr->resume_last_state = 0;
4055 gsm48_rr_tx_ass_cpl(ms, GSM48_RR_CAUSE_NORMAL);
4057 gsm48_rr_tx_ass_fail(ms, GSM48_RR_CAUSE_PROTO_ERR_UNSPEC);
4059 /* transmit queued frames during ho / ass transition */
4060 gsm48_rr_dequeue_down(ms);
4066 static int gsm48_rr_connect_cnf(struct osmocom_ms *ms, struct msgbl *msg)
4070 static int gsm48_rr_mdl_error_ind(struct osmocom_ms *ms, struct msgb *msg)
4072 struct gsm48_rrlayer *rr = ms->rrlayer;
4073 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
4075 uint8_t cause = rllh->data[2];
4077 printing of the cause
4080 case RLL_CAUSE_SEQ_ERR:
4081 case RLL_CAUSE_UNSOL_DM_RESP_MF:
4082 einige muessen ignoriert werden
4083 andere gelten als release
4086 if (rr->hando_susp_state || rr->assign_susp_state) {
4087 if (!rr->resume_last_state) {
4088 rr->resume_last_state = 1;
4090 /* get old channel description */
4091 memcpy(&rr->chan_desc, &rr->chan_last, sizeof(*cd));
4093 /* change radio to old channel */
4094 tx_ph_dm_est_req(ms, rr->cd_now.arfcn,
4095 rr->cd_now.chan_nr, rr->cd_now.tsc);
4097 /* re-establish old link */
4098 nmsg = gsm48_l3_msgb_alloc();
4101 return gsm48_send_rsl(ms, RSL_MT_RECON_REQ, nmsg);
4103 rr->resume_last_state = 0;
4106 /* deactivate channel */
4107 l1ctl_tx_dm_rel_req(ms, arfcn, rr->chan_desc.chan_desc.chan_nr);
4109 /* send abort ind to upper layer */
4110 nmsg = gsm48_mm_msgb_alloc();
4114 nrrh = (struct gsm_mm_hdr *)nmsg->data;
4115 nrrh->msg_type = RR_ABORT_IND;
4116 nrrh->cause = GSM_MM_CAUSE_LINK_FAILURE;
4117 return gsm48_rr_upmsg(ms, msg);
4120 static void timeout_rr_t3124(void *arg)
4122 struct gsm48_rrlayer *rr = arg;
4125 /* stop sending more access bursts when timer expired */
4128 /* get old channel description */
4129 memcpy(&rr->chan_desc, &rr->chan_last, sizeof(*cd));
4131 /* change radio to old channel */
4132 tx_ph_dm_est_req(ms, rr->cd_now.arfcn, rr->cd_now.chan_nr,
4135 /* re-establish old link */
4136 nmsg = gsm48_l3_msgb_alloc();
4139 return gsm48_send_rsl(ms, RSL_MT_REEST_REQ, nmsg);
4144 /* send HANDOVER ACCESS burst (9.1.14) */
4145 static int gsm48_rr_tx_hando_access(struct osmocom_ms *ms)
4147 nmsg = msgb_alloc_headroom(20, 16, "HAND_ACCESS");
4150 *msgb_put(nmsg, 1) = rr->hando_ref;
4152 return gsm48_send_rsl(ms, RSL_MT_RAND_ACC_REQ, nmsg);
4155 /* send next channel request in dedicated state */
4156 static int gsm48_rr_rand_acc_cnf_dedicated(struct osmocom_ms *ms, struct msgb *msg)
4158 struct gsm48_rrlayer *rr = &ms->rrlayer;
4162 if (!rr->hando_susp_state) {
4163 LOGP(DRR, LOGL_NOTICE, "Random acces confirm, but not in handover state.\n");
4167 /* send up to four handover access bursts */
4168 if (rr->hando_acc_left) {
4169 rr->hando_acc_left--;
4170 gsm48_rr_tx_hando_access(ms);
4174 /* start timer for sending next HANDOVER ACCESS bursts afterwards */
4175 if (!bsc_timer_pending(&rr->t3124)) {
4176 if (allocated channel is SDCCH)
4177 start_rr_t3124(rr, GSM_T3124_675);
4179 start_rr_t3124(rr, GSM_T3124_320);
4180 if (!rr->n_chan_req) {
4181 start_rr_t3126(rr, 5, 0); /* TODO improve! */
4186 /* wait for PHYSICAL INFORMATION message or T3124 timeout */