1 /* CBCH passive sniffer */
3 /* (C) 2010 by Holger Hans Peter Freyther
4 * (C) 2010 by Harald Welte <laforge@gnumonks.org>
5 * (C) 2010 by Alex Badea <vamposdecampos@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <osmocom/bb/common/osmocom_data.h>
26 #include <osmocom/bb/common/l1ctl.h>
27 #include <osmocom/bb/common/lapdm.h>
28 #include <osmocom/bb/common/logging.h>
29 #include <osmocom/bb/misc/layer3.h>
31 #include <osmocore/msgb.h>
32 #include <osmocore/talloc.h>
33 #include <osmocore/select.h>
34 #include <osmocore/signal.h>
35 #include <osmocore/rsl.h>
37 struct osmocom_ms *g_ms;
38 struct gsm48_sysinfo g_sysinfo = {};
40 static int try_cbch(struct osmocom_ms *ms, struct gsm48_sysinfo *s)
42 if (!s->si1 || !s->si4)
45 LOGP(DRR, LOGL_INFO, "no CBCH chan_nr found\n");
50 LOGP(DRR, LOGL_INFO, "chan_nr = 0x%02x TSC = %d MAIO = %d "
51 "HSN = %d hseq (%d): %s\n",
52 s->chan_nr, s->tsc, s->maio, s->hsn,
54 hexdump((unsigned char *) s->hopping, s->hopp_len * 2));
55 return l1ctl_tx_dm_est_req_h1(ms,
56 s->maio, s->hsn, s->hopping, s->hopp_len,
60 LOGP(DRR, LOGL_INFO, "chan_nr = 0x%02x TSC = %d ARFCN = %d\n",
61 s->chan_nr, s->tsc, s->arfcn);
62 return l1ctl_tx_dm_est_req_h0(ms, s->arfcn,
63 s->chan_nr, s->tsc, GSM48_CMODE_SIGN);
68 /* receive BCCH at RR layer */
69 static int bcch(struct osmocom_ms *ms, struct msgb *msg)
71 struct gsm48_system_information_type_header *sih = msgb_l3(msg);
72 struct gsm48_sysinfo *s = &g_sysinfo;
74 if (msgb_l3len(msg) != 23) {
75 LOGP(DRR, LOGL_NOTICE, "Invalid BCCH message length\n");
78 switch (sih->system_information) {
79 case GSM48_MT_RR_SYSINFO_1:
80 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 1\n");
81 gsm48_decode_sysinfo1(s,
82 (struct gsm48_system_information_type_1 *) sih,
84 return try_cbch(ms, s);
85 case GSM48_MT_RR_SYSINFO_4:
86 LOGP(DRR, LOGL_INFO, "New SYSTEM INFORMATION 4\n");
87 gsm48_decode_sysinfo4(s,
88 (struct gsm48_system_information_type_4 *) sih,
90 return try_cbch(ms, s);
96 static int unit_data_ind(struct osmocom_ms *ms, struct msgb *msg)
98 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
100 uint8_t ch_type, ch_subch, ch_ts;
102 DEBUGP(DRSL, "RSLms UNIT DATA IND chan_nr=0x%02x link_id=0x%02x\n",
103 rllh->chan_nr, rllh->link_id);
105 rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh));
106 if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) {
107 DEBUGP(DRSL, "UNIT_DATA_IND without L3 INFO ?!?\n");
110 msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO);
112 rsl_dec_chan_nr(rllh->chan_nr, &ch_type, &ch_subch, &ch_ts);
115 return bcch(ms, msg);
121 static int rcv_rll(struct osmocom_ms *ms, struct msgb *msg)
123 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
124 int msg_type = rllh->c.msg_type;
126 if (msg_type == RSL_MT_UNIT_DATA_IND) {
127 unit_data_ind(ms, msg);
129 LOGP(DRSL, LOGL_NOTICE, "RSLms message unhandled\n");
136 static int rcv_rsl(struct msgb *msg, struct osmocom_ms *ms)
138 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
141 switch (rslh->msg_discr & 0xfe) {
142 case ABIS_RSL_MDISC_RLL:
143 rc = rcv_rll(ms, msg);
146 LOGP(DRSL, LOGL_NOTICE, "unknown RSLms msg_discr 0x%02x\n",
156 static int signal_cb(unsigned int subsys, unsigned int signal,
157 void *handler_data, void *signal_data)
159 struct osmocom_ms *ms;
161 if (subsys != SS_L1CTL)
166 case S_L1CTL_FBSB_ERR:
168 return l1ctl_tx_fbsb_req(ms, ms->test_arfcn,
169 L1CTL_FBSB_F_FB01SB, 100, 0, CCCH_MODE_COMBINED);
170 case S_L1CTL_FBSB_RESP:
176 int l23_app_init(struct osmocom_ms *ms)
178 /* don't do layer3_init() as we don't want an actualy L3 */
181 osmol2_register_handler(ms, &rcv_rsl);
183 l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL);
184 /* FIXME: L1CTL_RES_T_FULL doesn't reset dedicated mode
185 * (if previously set), so we release it here. */
186 l1ctl_tx_dm_rel_req(ms);
187 return register_signal_handler(SS_L1CTL, &signal_cb, NULL);