1 /* RSLms - GSM 08.58 like protocol between L2 and L3 of GSM Um interface */
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
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.
27 #include <osmocore/msgb.h>
28 #include <osmocore/rsl.h>
29 #include <osmocore/tlv.h>
30 #include <osmocore/protocol/gsm_04_08.h>
32 #include <osmocom/bb/common/logging.h>
33 #include <osmocom/bb/common/lapdm.h>
34 #include <osmocom/bb/misc/rslms.h>
35 #include <osmocom/bb/misc/layer3.h>
36 #include <osmocom/bb/common/osmocom_data.h>
37 #include <osmocom/bb/common/l1ctl.h>
39 /* Send a 'simple' RLL request to L2 */
40 int rslms_tx_rll_req(struct osmocom_ms *ms, uint8_t msg_type,
41 uint8_t chan_nr, uint8_t link_id)
45 msg = rsl_rll_simple(msg_type, chan_nr, link_id, 1);
47 return rslms_recvmsg(msg, ms);
50 /* Send a RLL request (including L3 info) to L2 */
51 int rslms_tx_rll_req_l3(struct osmocom_ms *ms, uint8_t msg_type,
52 uint8_t chan_nr, uint8_t link_id, struct msgb *msg)
54 rsl_rll_push_l3(msg, msg_type, chan_nr, link_id, 1);
56 return rslms_recvmsg(msg, ms);
59 static int ccch_enabled = 0;
60 static int rach_count = 0;
62 static int rslms_rx_udata_ind(struct msgb *msg, struct osmocom_ms *ms)
64 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
68 DEBUGP(DRSL, "RSLms UNIT DATA IND chan_nr=0x%02x link_id=0x%02x\n",
69 rllh->chan_nr, rllh->link_id);
71 rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh));
72 if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) {
73 DEBUGP(DRSL, "UNIT_DATA_IND without L3 INFO ?!?\n");
76 msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO);
78 if (rllh->chan_nr == RSL_CHAN_PCH_AGCH) {
79 rc = gsm48_rx_ccch(msg, ms);
81 } else if (rllh->chan_nr == RSL_CHAN_BCCH) {
82 rc = gsm48_rx_bcch(msg, ms);
83 if (ccch_enabled && (rach_count < 2)) {
84 l1ctl_tx_rach_req(ms, rach_count, 27, 0);
92 static int rslms_rx_rll(struct msgb *msg, struct osmocom_ms *ms)
94 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
97 switch (rllh->c.msg_type) {
99 DEBUGP(DRSL, "RSLms DATA IND\n");
100 /* FIXME: implement this */
102 case RSL_MT_UNIT_DATA_IND:
103 rc = rslms_rx_udata_ind(msg, ms);
106 DEBUGP(DRSL, "RSLms EST IND\n");
107 /* FIXME: implement this */
109 case RSL_MT_EST_CONF:
110 DEBUGP(DRSL, "RSLms EST CONF\n");
111 /* FIXME: implement this */
113 case RSL_MT_REL_CONF:
114 DEBUGP(DRSL, "RSLms REL CONF\n");
115 /* FIXME: implement this */
117 case RSL_MT_ERROR_IND:
118 DEBUGP(DRSL, "RSLms ERR IND\n");
119 /* FIXME: implement this */
122 LOGP(DRSL, LOGL_NOTICE, "unknown RSLms message type "
123 "0x%02x\n", rllh->c.msg_type);
131 /* input function that L2 calls when sending messages up to L3 */
132 static int layer3_from_layer2(struct msgb *msg, struct osmocom_ms *ms)
134 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
137 switch (rslh->msg_discr & 0xfe) {
138 case ABIS_RSL_MDISC_RLL:
139 rc = rslms_rx_rll(msg, ms);
142 /* FIXME: implement this */
143 LOGP(DRSL, LOGL_NOTICE, "unknown RSLms msg_discr 0x%02x\n",
153 int layer3_init(struct osmocom_ms *ms)
155 return osmol2_register_handler(ms, &layer3_from_layer2);