1 /* Layer1 control code, talking L1CTL protocol with L1 on the phone */
3 /* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2010 by Harald Welte <laforge@gnumonks.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <arpa/inet.h>
31 #include <l1ctl_proto.h>
33 #include <osmocom/core/signal.h>
34 #include <osmocom/core/logging.h>
35 #include <osmocom/core/timer.h>
36 #include <osmocom/core/msgb.h>
37 #include <osmocom/gsm/tlv.h>
38 #include <osmocom/gsm/gsm_utils.h>
39 #include <osmocom/core/gsmtap_util.h>
40 #include <osmocom/gsm/protocol/gsm_04_08.h>
41 #include <osmocom/gsm/protocol/gsm_08_58.h>
42 #include <osmocom/gsm/rsl.h>
44 #include <osmocom/bb/common/l1ctl.h>
45 #include <osmocom/bb/common/osmocom_data.h>
46 #include <osmocom/bb/common/l1l2_interface.h>
47 #include <osmocom/bb/common/lapdm.h>
48 #include <osmocom/bb/common/logging.h>
50 extern struct gsmtap_inst *gsmtap_inst;
52 static struct msgb *osmo_l1_alloc(uint8_t msg_type)
54 struct l1ctl_hdr *l1h;
55 struct msgb *msg = msgb_alloc_headroom(256, 4, "osmo_l1");
58 LOGP(DL1C, LOGL_ERROR, "Failed to allocate memory.\n");
62 msg->l1h = msgb_put(msg, sizeof(*l1h));
63 l1h = (struct l1ctl_hdr *) msg->l1h;
64 l1h->msg_type = msg_type;
70 static int osmo_make_band_arfcn(struct osmocom_ms *ms, uint16_t arfcn)
72 /* TODO: Include the band */
76 static int rx_l1_fbsb_conf(struct osmocom_ms *ms, struct msgb *msg)
78 struct l1ctl_info_dl *dl;
79 struct l1ctl_fbsb_conf *sb;
81 struct osmobb_fbsb_res fr;
83 if (msgb_l3len(msg) < sizeof(*dl) + sizeof(*sb)) {
84 LOGP(DL1C, LOGL_ERROR, "FBSB RESP: MSG too short %u\n",
89 dl = (struct l1ctl_info_dl *) msg->l1h;
90 sb = (struct l1ctl_fbsb_conf *) dl->payload;
92 LOGP(DL1C, LOGL_INFO, "snr=%04x, arfcn=%u result=%u\n", dl->snr,
93 ntohs(dl->band_arfcn), sb->result);
95 if (sb->result != 0) {
96 LOGP(DL1C, LOGL_ERROR, "FBSB RESP: result=%u\n", sb->result);
98 fr.band_arfcn = ntohs(dl->band_arfcn);
99 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_FBSB_ERR, &fr);
103 gsm_fn2gsmtime(&tm, ntohl(dl->frame_nr));
104 DEBUGP(DL1C, "SCH: SNR: %u TDMA: (%.4u/%.2u/%.2u) bsic: %d\n",
105 dl->snr, tm.t1, tm.t2, tm.t3, sb->bsic);
109 fr.band_arfcn = ntohs(dl->band_arfcn);
110 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_FBSB_RESP, &fr);
115 static int rx_l1_rach_conf(struct osmocom_ms *ms, struct msgb *msg)
117 struct lapdm_entity *le = &ms->lapdm_channel.lapdm_dcch;
118 struct osmo_phsap_prim pp;
119 struct l1ctl_info_dl *dl;
121 if (msgb_l2len(msg) < sizeof(*dl)) {
122 LOGP(DL1C, LOGL_ERROR, "RACH CONF: MSG too short %u\n",
128 dl = (struct l1ctl_info_dl *) msg->l1h;
130 osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RACH,
131 PRIM_OP_CONFIRM, msg);
132 pp.u.rach_ind.fn = ntohl(dl->frame_nr);
134 return lapdm_phsap_up(&pp.oph, le);
137 /* Receive L1CTL_DATA_IND (Data Indication from L1) */
138 static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
140 struct osmo_phsap_prim pp;
141 struct l1ctl_info_dl *dl;
142 struct l1ctl_data_ind *ccch;
143 struct lapdm_entity *le;
144 struct rx_meas_stat *meas = &ms->meas;
145 uint8_t chan_type, chan_ts, chan_ss;
146 uint8_t gsmtap_chan_type;
149 if (msgb_l3len(msg) < sizeof(*ccch)) {
150 LOGP(DL1C, LOGL_ERROR, "MSG too short Data Ind: %u\n",
156 dl = (struct l1ctl_info_dl *) msg->l1h;
157 msg->l2h = dl->payload;
158 ccch = (struct l1ctl_data_ind *) msg->l2h;
160 gsm_fn2gsmtime(&tm, ntohl(dl->frame_nr));
161 rsl_dec_chan_nr(dl->chan_nr, &chan_type, &chan_ss, &chan_ts);
162 DEBUGP(DL1C, "%s (%.4u/%.2u/%.2u) %d dBm: %s\n",
163 rsl_chan_nr_str(dl->chan_nr), tm.t1, tm.t2, tm.t3,
164 (int)dl->rx_level-110,
165 osmo_hexdump(ccch->data, sizeof(ccch->data)));
167 meas->last_fn = ntohl(dl->frame_nr);
169 meas->snr += dl->snr;
170 meas->berr += dl->num_biterr;
171 meas->rxlev += dl->rx_level;
173 /* counting loss criteria */
174 if (!(dl->link_id & 0x40)) {
176 case RSL_CHAN_PCH_AGCH:
179 if (dl->fire_crc >= 2)
183 if (meas->dsc > meas->ds_fail)
184 meas->dsc = meas->ds_fail;
185 if (meas->dsc < meas->ds_fail)
186 printf("LOSS counter for CCCH %d\n", meas->dsc);
190 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_LOSS_IND, ms);
195 case RSL_CHAN_Bm_ACCHs:
196 case RSL_CHAN_Lm_ACCHs:
197 case RSL_CHAN_SDCCH4_ACCH:
198 case RSL_CHAN_SDCCH8_ACCH:
201 if (dl->fire_crc >= 2)
205 if (meas->s > meas->rl_fail)
206 meas->s = meas->rl_fail;
207 if (meas->s < meas->rl_fail)
208 printf("LOSS counter for ACCH %d\n", meas->s);
212 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_LOSS_IND, ms);
217 if (dl->fire_crc >= 2) {
218 printf("Dropping frame with %u bit errors\n", dl->num_biterr);
219 LOGP(DL1C, LOGL_NOTICE, "Dropping frame with %u bit errors\n",
225 /* send CCCH data via GSMTAP */
226 gsmtap_chan_type = chantype_rsl2gsmtap(chan_type, dl->link_id);
227 gsmtap_send(gsmtap_inst, ntohs(dl->band_arfcn), chan_ts,
228 gsmtap_chan_type, chan_ss, tm.fn, dl->rx_level-110,
229 dl->snr, ccch->data, sizeof(ccch->data));
231 /* determine LAPDm entity based on SACCH or not */
232 if (dl->link_id & 0x40)
233 le = &ms->lapdm_channel.lapdm_acch;
235 le = &ms->lapdm_channel.lapdm_dcch;
237 /* pull the L1 header from the msgb */
238 msgb_pull(msg, msg->l2h - (msg->l1h-sizeof(struct l1ctl_hdr)));
241 osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_DATA,
242 PRIM_OP_INDICATION, msg);
243 pp.u.data.chan_nr = dl->chan_nr;
244 pp.u.data.link_id = dl->link_id;
246 /* send it up into LAPDm */
247 return lapdm_phsap_up(&pp.oph, le);
250 /* Receive L1CTL_DATA_CONF (Data Confirm from L1) */
251 static int rx_ph_data_conf(struct osmocom_ms *ms, struct msgb *msg)
253 struct osmo_phsap_prim pp;
254 struct l1ctl_info_dl *dl = (struct l1ctl_info_dl *) msg->l1h;
255 struct lapdm_entity *le;
257 osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RTS,
258 PRIM_OP_INDICATION, msg);
260 /* determine LAPDm entity based on SACCH or not */
261 if (dl->link_id & 0x40)
262 le = &ms->lapdm_channel.lapdm_acch;
264 le = &ms->lapdm_channel.lapdm_dcch;
266 /* send it up into LAPDm */
267 return lapdm_phsap_up(&pp.oph, le);
270 /* Transmit L1CTL_DATA_REQ */
271 int l1ctl_tx_data_req(struct osmocom_ms *ms, struct msgb *msg,
272 uint8_t chan_nr, uint8_t link_id)
274 struct l1ctl_hdr *l1h;
275 struct l1ctl_info_ul *l1i_ul;
276 uint8_t chan_type, chan_ts, chan_ss;
277 uint8_t gsmtap_chan_type;
279 DEBUGP(DL1C, "(%s)\n", osmo_hexdump(msg->l2h, msgb_l2len(msg)));
281 if (msgb_l2len(msg) > 23) {
282 LOGP(DL1C, LOGL_ERROR, "L1 cannot handle message length "
283 "> 23 (%u)\n", msgb_l2len(msg));
286 } else if (msgb_l2len(msg) < 23)
287 LOGP(DL1C, LOGL_ERROR, "L1 message length < 23 (%u) "
288 "doesn't seem right!\n", msgb_l2len(msg));
290 /* send copy via GSMTAP */
291 rsl_dec_chan_nr(chan_nr, &chan_type, &chan_ss, &chan_ts);
292 gsmtap_chan_type = chantype_rsl2gsmtap(chan_type, link_id);
293 gsmtap_send(gsmtap_inst, 0|0x4000, chan_ts, gsmtap_chan_type,
294 chan_ss, 0, 127, 255, msg->l2h, msgb_l2len(msg));
296 /* prepend uplink info header */
297 l1i_ul = (struct l1ctl_info_ul *) msgb_push(msg, sizeof(*l1i_ul));
299 l1i_ul->chan_nr = chan_nr;
300 l1i_ul->link_id = link_id;
302 /* prepend l1 header */
303 msg->l1h = msgb_push(msg, sizeof(*l1h));
304 l1h = (struct l1ctl_hdr *) msg->l1h;
305 l1h->msg_type = L1CTL_DATA_REQ;
307 return osmo_send_l1(ms, msg);
310 /* Transmit FBSB_REQ */
311 int l1ctl_tx_fbsb_req(struct osmocom_ms *ms, uint16_t arfcn,
312 uint8_t flags, uint16_t timeout, uint8_t sync_info_idx,
316 struct l1ctl_fbsb_req *req;
318 LOGP(DL1C, LOGL_INFO, "Sync Req\n");
320 msg = osmo_l1_alloc(L1CTL_FBSB_REQ);
324 req = (struct l1ctl_fbsb_req *) msgb_put(msg, sizeof(*req));
325 req->band_arfcn = htons(osmo_make_band_arfcn(ms, arfcn));
326 req->timeout = htons(timeout);
327 /* Threshold when to consider FB_MODE1: 4kHz - 1kHz */
328 req->freq_err_thresh1 = htons(11000 - 1000);
329 /* Threshold when to consider SCH: 1kHz - 200Hz */
330 req->freq_err_thresh2 = htons(1000 - 200);
332 req->num_freqerr_avg = 3;
334 req->sync_info_idx = sync_info_idx;
335 req->ccch_mode = ccch_mode;
337 return osmo_send_l1(ms, msg);
340 /* Transmit L1CTL_CCCH_MODE_REQ */
341 int l1ctl_tx_ccch_mode_req(struct osmocom_ms *ms, uint8_t ccch_mode)
344 struct l1ctl_ccch_mode_req *req;
346 LOGP(DL1C, LOGL_INFO, "CCCH Mode Req\n");
348 msg = osmo_l1_alloc(L1CTL_CCCH_MODE_REQ);
352 req = (struct l1ctl_ccch_mode_req *) msgb_put(msg, sizeof(*req));
353 req->ccch_mode = ccch_mode;
355 return osmo_send_l1(ms, msg);
358 /* Transmit L1CTL_TCH_MODE_REQ */
359 int l1ctl_tx_tch_mode_req(struct osmocom_ms *ms, uint8_t tch_mode)
362 struct l1ctl_tch_mode_req *req;
364 LOGP(DL1C, LOGL_INFO, "TCH Mode Req\n");
366 msg = osmo_l1_alloc(L1CTL_TCH_MODE_REQ);
370 req = (struct l1ctl_tch_mode_req *) msgb_put(msg, sizeof(*req));
371 req->tch_mode = tch_mode;
373 return osmo_send_l1(ms, msg);
376 /* Transmit L1CTL_PARAM_REQ */
377 int l1ctl_tx_param_req(struct osmocom_ms *ms, uint8_t ta, uint8_t tx_power)
380 struct l1ctl_info_ul *ul;
381 struct l1ctl_par_req *req;
383 msg = osmo_l1_alloc(L1CTL_PARAM_REQ);
387 DEBUGP(DL1C, "PARAM Req. ta=%d, tx_power=%d\n", ta, tx_power);
388 ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
389 req = (struct l1ctl_par_req *) msgb_put(msg, sizeof(*req));
390 req->tx_power = tx_power;
393 return osmo_send_l1(ms, msg);
396 /* Transmit L1CTL_CRYPTO_REQ */
397 int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t algo, uint8_t *key,
401 struct l1ctl_info_ul *ul;
402 struct l1ctl_crypto_req *req;
404 msg = osmo_l1_alloc(L1CTL_CRYPTO_REQ);
408 DEBUGP(DL1C, "CRYPTO Req. algo=%d, len=%d\n", algo, len);
409 ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
410 req = (struct l1ctl_crypto_req *) msgb_put(msg, sizeof(*req) + len);
413 memcpy(req->key, key, len);
415 return osmo_send_l1(ms, msg);
418 /* Transmit L1CTL_RACH_REQ */
419 int l1ctl_tx_rach_req(struct osmocom_ms *ms, uint8_t ra, uint16_t offset,
423 struct l1ctl_info_ul *ul;
424 struct l1ctl_rach_req *req;
426 msg = osmo_l1_alloc(L1CTL_RACH_REQ);
430 DEBUGP(DL1C, "RACH Req. offset=%d combined=%d\n", offset, combined);
431 ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
432 req = (struct l1ctl_rach_req *) msgb_put(msg, sizeof(*req));
434 req->offset = htons(offset);
435 req->combined = combined;
437 return osmo_send_l1(ms, msg);
440 /* Transmit L1CTL_DM_EST_REQ */
441 int l1ctl_tx_dm_est_req_h0(struct osmocom_ms *ms, uint16_t band_arfcn,
442 uint8_t chan_nr, uint8_t tsc, uint8_t tch_mode)
445 struct l1ctl_info_ul *ul;
446 struct l1ctl_dm_est_req *req;
448 msg = osmo_l1_alloc(L1CTL_DM_EST_REQ);
452 LOGP(DL1C, LOGL_INFO, "Tx Dedic.Mode Est Req (arfcn=%u, "
453 "chan_nr=0x%02x)\n", band_arfcn, chan_nr);
455 ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
456 ul->chan_nr = chan_nr;
459 req = (struct l1ctl_dm_est_req *) msgb_put(msg, sizeof(*req));
462 req->h0.band_arfcn = htons(band_arfcn);
463 req->tch_mode = tch_mode;
465 return osmo_send_l1(ms, msg);
468 int l1ctl_tx_dm_est_req_h1(struct osmocom_ms *ms, uint8_t maio, uint8_t hsn,
469 uint16_t *ma, uint8_t ma_len,
470 uint8_t chan_nr, uint8_t tsc, uint8_t tch_mode)
473 struct l1ctl_info_ul *ul;
474 struct l1ctl_dm_est_req *req;
477 msg = osmo_l1_alloc(L1CTL_DM_EST_REQ);
481 LOGP(DL1C, LOGL_INFO, "Tx Dedic.Mode Est Req (maio=%u, hsn=%u, "
482 "chan_nr=0x%02x)\n", maio, hsn, chan_nr);
484 ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
485 ul->chan_nr = chan_nr;
488 req = (struct l1ctl_dm_est_req *) msgb_put(msg, sizeof(*req));
494 for (i = 0; i < ma_len; i++)
495 req->h1.ma[i] = htons(ma[i]);
496 req->tch_mode = tch_mode;
498 return osmo_send_l1(ms, msg);
501 /* Transmit L1CTL_DM_FREQ_REQ */
502 int l1ctl_tx_dm_freq_req_h0(struct osmocom_ms *ms, uint16_t band_arfcn,
503 uint8_t tsc, uint16_t fn)
506 struct l1ctl_info_ul *ul;
507 struct l1ctl_dm_freq_req *req;
509 msg = osmo_l1_alloc(L1CTL_DM_FREQ_REQ);
513 LOGP(DL1C, LOGL_INFO, "Tx Dedic.Mode Freq Req (arfcn=%u, fn=%d)\n",
516 ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
520 req = (struct l1ctl_dm_freq_req *) msgb_put(msg, sizeof(*req));
524 req->h0.band_arfcn = htons(band_arfcn);
526 return osmo_send_l1(ms, msg);
529 int l1ctl_tx_dm_freq_req_h1(struct osmocom_ms *ms, uint8_t maio, uint8_t hsn,
530 uint16_t *ma, uint8_t ma_len,
531 uint8_t tsc, uint16_t fn)
534 struct l1ctl_info_ul *ul;
535 struct l1ctl_dm_freq_req *req;
538 msg = osmo_l1_alloc(L1CTL_DM_FREQ_REQ);
542 LOGP(DL1C, LOGL_INFO, "Tx Dedic.Mode Freq Req (maio=%u, hsn=%u, "
543 "fn=%d)\n", maio, hsn, fn);
545 ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
549 req = (struct l1ctl_dm_freq_req *) msgb_put(msg, sizeof(*req));
556 for (i = 0; i < ma_len; i++)
557 req->h1.ma[i] = htons(ma[i]);
559 return osmo_send_l1(ms, msg);
562 /* Transmit L1CTL_DM_REL_REQ */
563 int l1ctl_tx_dm_rel_req(struct osmocom_ms *ms)
566 struct l1ctl_info_ul *ul;
568 msg = osmo_l1_alloc(L1CTL_DM_REL_REQ);
572 LOGP(DL1C, LOGL_INFO, "Tx Dedic.Mode Rel Req\n");
574 ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
576 return osmo_send_l1(ms, msg);
579 int l1ctl_tx_echo_req(struct osmocom_ms *ms, unsigned int len)
585 msg = osmo_l1_alloc(L1CTL_ECHO_REQ);
589 data = msgb_put(msg, len);
590 for (i = 0; i < len; i++)
593 return osmo_send_l1(ms, msg);
596 int l1ctl_tx_sim_req(struct osmocom_ms *ms, uint8_t *data, uint16_t length)
601 msg = osmo_l1_alloc(L1CTL_SIM_REQ);
605 dat = msgb_put(msg, length);
606 memcpy(dat, data, length);
608 return osmo_send_l1(ms, msg);
611 /* just forward the SIM response to the SIM handler */
612 static int rx_l1_sim_conf(struct osmocom_ms *ms, struct msgb *msg)
614 uint16_t len = msg->len - sizeof(struct l1ctl_hdr);
615 uint8_t *data = msg->data + sizeof(struct l1ctl_hdr);
617 LOGP(DL1C, LOGL_INFO, "SIM %s\n", osmo_hexdump(data, len));
619 /* pull the L1 header from the msgb */
620 msgb_pull(msg, sizeof(struct l1ctl_hdr));
623 sim_apdu_resp(ms, msg);
628 /* Transmit L1CTL_PM_REQ */
629 int l1ctl_tx_pm_req_range(struct osmocom_ms *ms, uint16_t arfcn_from,
633 struct l1ctl_pm_req *pm;
635 msg = osmo_l1_alloc(L1CTL_PM_REQ);
639 LOGP(DL1C, LOGL_INFO, "Tx PM Req (%u-%u)\n", arfcn_from, arfcn_to);
640 pm = (struct l1ctl_pm_req *) msgb_put(msg, sizeof(*pm));
642 pm->range.band_arfcn_from = htons(arfcn_from);
643 pm->range.band_arfcn_to = htons(arfcn_to);
645 return osmo_send_l1(ms, msg);
648 /* Transmit L1CTL_RESET_REQ */
649 int l1ctl_tx_reset_req(struct osmocom_ms *ms, uint8_t type)
652 struct l1ctl_reset *res;
654 msg = osmo_l1_alloc(L1CTL_RESET_REQ);
658 LOGP(DL1C, LOGL_INFO, "Tx Reset Req (%u)\n", type);
659 res = (struct l1ctl_reset *) msgb_put(msg, sizeof(*res));
662 return osmo_send_l1(ms, msg);
665 /* Receive L1CTL_RESET_IND */
666 static int rx_l1_reset(struct osmocom_ms *ms)
668 LOGP(DL1C, LOGL_INFO, "Layer1 Reset indication\n");
669 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_RESET, ms);
674 /* Receive L1CTL_PM_CONF */
675 static int rx_l1_pm_conf(struct osmocom_ms *ms, struct msgb *msg)
677 struct l1ctl_pm_conf *pmr;
679 for (pmr = (struct l1ctl_pm_conf *) msg->l1h;
680 (uint8_t *) pmr < msg->tail; pmr++) {
681 struct osmobb_meas_res mr;
682 DEBUGP(DL1C, "PM MEAS: ARFCN: %4u RxLev: %3d %3d\n",
683 ntohs(pmr->band_arfcn), pmr->pm[0], pmr->pm[1]);
684 mr.band_arfcn = ntohs(pmr->band_arfcn);
685 mr.rx_lev = pmr->pm[0];
687 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_PM_RES, &mr);
692 /* Receive L1CTL_CCCH_MODE_CONF */
693 static int rx_l1_ccch_mode_conf(struct osmocom_ms *ms, struct msgb *msg)
695 struct osmobb_ccch_mode_conf mc;
696 struct l1ctl_ccch_mode_conf *conf;
698 if (msgb_l3len(msg) < sizeof(*conf)) {
699 LOGP(DL1C, LOGL_ERROR, "CCCH MODE CONF: MSG too short %u\n",
704 conf = (struct l1ctl_ccch_mode_conf *) msg->l1h;
706 LOGP(DL1C, LOGL_INFO, "CCCH MODE CONF: mode=%u\n", conf->ccch_mode);
708 mc.ccch_mode = conf->ccch_mode;
710 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_CCCH_MODE_CONF, &mc);
715 /* Receive L1CTL_TCH_MODE_CONF */
716 static int rx_l1_tch_mode_conf(struct osmocom_ms *ms, struct msgb *msg)
718 struct osmobb_tch_mode_conf mc;
719 struct l1ctl_tch_mode_conf *conf;
721 if (msgb_l3len(msg) < sizeof(*conf)) {
722 LOGP(DL1C, LOGL_ERROR, "TCH MODE CONF: MSG too short %u\n",
727 conf = (struct l1ctl_tch_mode_conf *) msg->l1h;
729 LOGP(DL1C, LOGL_INFO, "TCH MODE CONF: mode=%u\n", conf->tch_mode);
731 mc.tch_mode = conf->tch_mode;
733 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_TCH_MODE_CONF, &mc);
738 /* Transmit L1CTL_NEIGH_PM_REQ */
739 int l1ctl_tx_neigh_pm_req(struct osmocom_ms *ms, int num, uint16_t *arfcn)
742 struct l1ctl_neigh_pm_req *pm_req;
745 msg = osmo_l1_alloc(L1CTL_NEIGH_PM_REQ);
749 LOGP(DL1C, LOGL_INFO, "Tx NEIGH PM Req (num %u)\n", num);
750 pm_req = (struct l1ctl_neigh_pm_req *) msgb_put(msg, sizeof(*pm_req));
752 for (i = 0; i < num; i++)
753 pm_req->band_arfcn[i] = htons(*arfcn++);
755 return osmo_send_l1(ms, msg);
758 /* Receive L1CTL_NEIGH_PM_IND */
759 static int rx_l1_neigh_pm_ind(struct osmocom_ms *ms, struct msgb *msg)
761 struct l1ctl_neigh_pm_ind *pm_ind;
763 for (pm_ind = (struct l1ctl_neigh_pm_ind *) msg->l1h;
764 (uint8_t *) pm_ind < msg->tail; pm_ind++) {
765 struct osmobb_neigh_pm_ind mi;
766 DEBUGP(DL1C, "NEIGH_PM IND: ARFCN: %4u RxLev: %3d %3d\n",
767 ntohs(pm_ind->band_arfcn), pm_ind->pm[0],
769 mi.band_arfcn = ntohs(pm_ind->band_arfcn);
770 mi.rx_lev = pm_ind->pm[0];
772 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_NEIGH_PM_IND, &mi);
777 /* Receive incoming data from L1 using L1CTL format */
778 int l1ctl_recv(struct osmocom_ms *ms, struct msgb *msg)
781 struct l1ctl_hdr *l1h;
782 struct l1ctl_info_dl *dl;
784 if (msgb_l2len(msg) < sizeof(*dl)) {
785 LOGP(DL1C, LOGL_ERROR, "Short Layer2 message: %u\n",
791 l1h = (struct l1ctl_hdr *) msg->l1h;
793 /* move the l1 header pointer to point _BEHIND_ l1ctl_hdr,
794 as the l1ctl header is of no interest to subsequent code */
795 msg->l1h = l1h->data;
797 switch (l1h->msg_type) {
798 case L1CTL_FBSB_CONF:
799 rc = rx_l1_fbsb_conf(ms, msg);
803 rc = rx_ph_data_ind(ms, msg);
805 case L1CTL_DATA_CONF:
806 rc = rx_ph_data_conf(ms, msg);
808 case L1CTL_RESET_IND:
809 case L1CTL_RESET_CONF:
810 rc = rx_l1_reset(ms);
814 rc = rx_l1_pm_conf(ms, msg);
815 if (l1h->flags & L1CTL_F_DONE)
816 osmo_signal_dispatch(SS_L1CTL, S_L1CTL_PM_DONE, ms);
819 case L1CTL_RACH_CONF:
820 rc = rx_l1_rach_conf(ms, msg);
822 case L1CTL_CCCH_MODE_CONF:
823 rc = rx_l1_ccch_mode_conf(ms, msg);
826 case L1CTL_TCH_MODE_CONF:
827 rc = rx_l1_tch_mode_conf(ms, msg);
831 rc = rx_l1_sim_conf(ms, msg);
833 case L1CTL_NEIGH_PM_IND:
834 rc = rx_l1_neigh_pm_ind(ms, msg);
838 LOGP(DL1C, LOGL_ERROR, "Unknown MSG: %u\n", l1h->msg_type);