blob: 6ca535bd0e7d8f841f994669790c90e46fe6c294 [file] [log] [blame]
Holger Hans Peter Freyther98753bd2010-11-09 23:28:33 +01001/* GSM 08.08 BSSMAP handling */
2/* (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * (C) 2009-2010 by On-Waves
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include <openbsc/osmo_bsc.h>
Holger Hans Peter Freytherde2bb072010-11-10 09:24:37 +010023#include <openbsc/osmo_bsc_grace.h>
Holger Hans Peter Freyther98753bd2010-11-09 23:28:33 +010024#include <openbsc/debug.h>
25
Holger Hans Peter Freytherde2bb072010-11-10 09:24:37 +010026#include <osmocore/gsm0808.h>
Holger Hans Peter Freyther98753bd2010-11-09 23:28:33 +010027#include <osmocore/protocol/gsm_08_08.h>
28
Holger Hans Peter Freytherde2bb072010-11-10 09:24:37 +010029#include <arpa/inet.h>
30
31static uint16_t read_data16(const uint8_t *data)
32{
33 uint16_t res;
34
35 memcpy(&res, data, sizeof(res));
36 return res;
37}
38
39static int bssmap_handle_reset_ack(struct gsm_network *net,
40 struct msgb *msg, unsigned int length)
41{
42 LOGP(DMSC, LOGL_NOTICE, "Reset ACK from MSC\n");
43 return 0;
44}
45
46/* GSM 08.08 ยง 3.2.1.19 */
47static int bssmap_handle_paging(struct gsm_network *net,
48 struct msgb *msg, unsigned int payload_length)
49{
50 struct tlv_parsed tp;
51 char mi_string[GSM48_MI_SIZE];
52 uint32_t tmsi = GSM_RESERVED_TMSI;
53 unsigned int lac = GSM_LAC_RESERVED_ALL_BTS;
54 uint8_t data_length;
55 const uint8_t *data;
56 uint8_t chan_needed = RSL_CHANNEED_ANY;
57
58 tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l4h + 1, payload_length - 1, 0, 0);
59
60 if (!TLVP_PRESENT(&tp, GSM0808_IE_IMSI)) {
61 LOGP(DMSC, LOGL_ERROR, "Mandantory IMSI not present.\n");
62 return -1;
63 } else if ((TLVP_VAL(&tp, GSM0808_IE_IMSI)[0] & GSM_MI_TYPE_MASK) != GSM_MI_TYPE_IMSI) {
64 LOGP(DMSC, LOGL_ERROR, "Wrong content in the IMSI\n");
65 return -1;
66 }
67
68 if (!TLVP_PRESENT(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST)) {
69 LOGP(DMSC, LOGL_ERROR, "Mandantory CELL IDENTIFIER LIST not present.\n");
70 return -1;
71 }
72
73 if (TLVP_PRESENT(&tp, GSM0808_IE_TMSI)) {
74 gsm48_mi_to_string(mi_string, sizeof(mi_string),
75 TLVP_VAL(&tp, GSM0808_IE_TMSI), TLVP_LEN(&tp, GSM0808_IE_TMSI));
76 tmsi = strtoul(mi_string, NULL, 10);
77 }
78
79
80 /*
81 * parse the IMSI
82 */
83 gsm48_mi_to_string(mi_string, sizeof(mi_string),
84 TLVP_VAL(&tp, GSM0808_IE_IMSI), TLVP_LEN(&tp, GSM0808_IE_IMSI));
85
86 /*
87 * parse the cell identifier list
88 */
89 data_length = TLVP_LEN(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
90 data = TLVP_VAL(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
91
92 /*
93 * Support paging to all network or one BTS at one LAC
94 */
95 if (data_length == 3 && data[0] == CELL_IDENT_LAC) {
96 lac = ntohs(read_data16(&data[1]));
97 } else if (data_length > 1 || (data[0] & 0x0f) != CELL_IDENT_BSS) {
98 LOGP(DMSC, LOGL_ERROR, "Unsupported Cell Identifier List: %s\n", hexdump(data, data_length));
99 return -1;
100 }
101
102 if (TLVP_PRESENT(&tp, GSM0808_IE_CHANNEL_NEEDED) && TLVP_LEN(&tp, GSM0808_IE_CHANNEL_NEEDED) == 1)
103 chan_needed = TLVP_VAL(&tp, GSM0808_IE_CHANNEL_NEEDED)[0] & 0x03;
104
105 if (TLVP_PRESENT(&tp, GSM0808_IE_EMLPP_PRIORITY)) {
106 LOGP(DMSC, LOGL_ERROR, "eMLPP is not handled\n");
107 }
108
109 LOGP(DMSC, LOGL_DEBUG, "Paging request from MSC IMSI: '%s' TMSI: '0x%x/%u' LAC: 0x%x\n", mi_string, tmsi, tmsi, lac);
110 LOGP(DMSC, LOGL_ERROR, "Paging is not implemented...\n");
111 return -1;
112}
113
114static int bssmap_rcvmsg_udt(struct gsm_network *net,
115 struct msgb *msg, unsigned int length)
116{
117 int ret = 0;
118
119 if (length < 1) {
120 LOGP(DMSC, LOGL_ERROR, "Not enough room: %d\n", length);
121 return -1;
122 }
123
124 switch (msg->l4h[0]) {
125 case BSS_MAP_MSG_RESET_ACKNOWLEDGE:
126 ret = bssmap_handle_reset_ack(net, msg, length);
127 break;
128 case BSS_MAP_MSG_PAGING:
129 if (bsc_grace_allow_new_connection(net))
130 ret = bssmap_handle_paging(net, msg, length);
131 break;
132 }
133
134 return ret;
135}
136
137static int bssmap_rcvmsg_dt1(struct osmo_bsc_sccp_con *conn,
138 struct msgb *msg, unsigned int length)
139{
140 return -1;
141}
142
143static int dtap_rcvmsg(struct osmo_bsc_sccp_con *conn,
144 struct msgb *msg, unsigned int length)
145{
146 return -1;
147}
148
Holger Hans Peter Freyther98753bd2010-11-09 23:28:33 +0100149int bsc_handle_udt(struct gsm_network *network,
150 struct bsc_msc_connection *conn,
151 struct msgb *msgb, unsigned int length)
152{
153 struct bssmap_header *bs;
154
155 LOGP(DMSC, LOGL_DEBUG, "Incoming SCCP message ftom MSC: %s\n",
156 hexdump(msgb->l3h, length));
157
158 if (length < sizeof(*bs)) {
159 LOGP(DMSC, LOGL_ERROR, "The header is too short.\n");
160 return -1;
161 }
162
163 bs = (struct bssmap_header *) msgb->l3h;
164 if (bs->length < length - sizeof(*bs))
165 return -1;
166
167 switch (bs->type) {
168 case BSSAP_MSG_BSS_MANAGEMENT:
Holger Hans Peter Freytherde2bb072010-11-10 09:24:37 +0100169 msgb->l4h = &msgb->l3h[sizeof(*bs)];
170 bssmap_rcvmsg_udt(network, msgb, length - sizeof(*bs));
Holger Hans Peter Freyther98753bd2010-11-09 23:28:33 +0100171 break;
172 default:
173 LOGP(DMSC, LOGL_ERROR, "Unimplemented msg type: %d\n", bs->type);
174 }
175
176 return 0;
177}
178
179int bsc_handle_dt1(struct osmo_bsc_sccp_con *conn,
180 struct msgb *msg, unsigned int len)
181{
Holger Hans Peter Freytherde2bb072010-11-10 09:24:37 +0100182 if (len < sizeof(struct bssmap_header)) {
183 LOGP(DMSC, LOGL_ERROR, "The header is too short.\n");
184 }
185
186 switch (msg->l3h[0]) {
187 case BSSAP_MSG_BSS_MANAGEMENT:
188 msg->l4h = &msg->l3h[sizeof(struct bssmap_header)];
189 bssmap_rcvmsg_dt1(conn, msg, len - sizeof(struct bssmap_header));
190 break;
191 case BSSAP_MSG_DTAP:
192 dtap_rcvmsg(conn, msg, len);
193 break;
194 default:
195 LOGP(DMSC, LOGL_DEBUG, "Unimplemented msg type: %d\n", msg->l3h[0]);
196 }
197
Holger Hans Peter Freyther98753bd2010-11-09 23:28:33 +0100198 return -1;
199}