blob: 24710fabdbb44da3640276826a1ee5e483f38769 [file] [log] [blame]
Holger Hans Peter Freyther5bb874d2010-11-05 11:21:18 +01001/* (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
2 * (C) 2009-2010 by On-Waves
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <openbsc/osmo_bsc.h>
Holger Hans Peter Freyther52d42ab2010-11-05 18:41:04 +010022#include <openbsc/osmo_msc_data.h>
23#include <openbsc/gsm_04_80.h>
Holger Hans Peter Freytherd65305f2010-11-05 11:31:08 +010024#include <openbsc/debug.h>
25
26static void handle_lu_request(struct gsm_subscriber_connection *conn,
27 struct msgb *msg)
28{
29 struct gsm48_hdr *gh;
30 struct gsm48_loc_upd_req *lu;
31 struct gsm48_loc_area_id lai;
32 struct gsm_network *net;
33
34 if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*lu)) {
35 LOGP(DMSC, LOGL_ERROR, "LU too small to look at: %u\n", msgb_l3len(msg));
36 return;
37 }
38
39 net = conn->bts->network;
40
41 gh = msgb_l3(msg);
42 lu = (struct gsm48_loc_upd_req *) gh->data;
43
44 gsm48_generate_lai(&lai, net->country_code, net->network_code,
45 conn->bts->location_area_code);
46
47 if (memcmp(&lai, &lu->lai, sizeof(lai)) != 0) {
48 LOGP(DMSC, LOGL_DEBUG, "Marking con for welcome USSD.\n");
49 conn->sccp_con->new_subscriber = 1;
50 }
51}
Holger Hans Peter Freyther5bb874d2010-11-05 11:21:18 +010052
53/**
54 * This is used to scan a message for extra functionality of the BSC. This
55 * includes scanning for location updating requests/acceptd and then send
56 * a welcome USSD message to the subscriber.
57 */
58int bsc_scan_bts_msg(struct gsm_subscriber_connection *conn, struct msgb *msg)
59{
Holger Hans Peter Freytherd65305f2010-11-05 11:31:08 +010060 struct gsm48_hdr *gh = msgb_l3(msg);
61 uint8_t pdisc = gh->proto_discr & 0x0f;
62 uint8_t mtype = gh->msg_type & 0xbf;
63
64 if (pdisc == GSM48_PDISC_MM) {
65 if (mtype == GSM48_MT_MM_LOC_UPD_REQUEST)
66 handle_lu_request(conn, msg);
67 }
68
Holger Hans Peter Freyther5bb874d2010-11-05 11:21:18 +010069 return 0;
70}
Holger Hans Peter Freythera54732d2010-11-05 18:11:19 +010071
Holger Hans Peter Freyther52d42ab2010-11-05 18:41:04 +010072static void send_welcome_ussd(struct gsm_subscriber_connection *conn)
73{
74 struct gsm_network *net;
75 net = conn->bts->network;
76
77 if (!net->msc_data->ussd_welcome_txt)
78 return;
79
80 gsm0480_send_ussdNotify(conn, 1, net->msc_data->ussd_welcome_txt);
81 gsm0480_send_releaseComplete(conn);
82}
83
Holger Hans Peter Freythera54732d2010-11-05 18:11:19 +010084/**
85 * Messages coming back from the MSC.
86 */
87int bsc_scan_msc_msg(struct gsm_subscriber_connection *conn, struct msgb *msg)
88{
Holger Hans Peter Freyther52d42ab2010-11-05 18:41:04 +010089 struct gsm_network *net;
90 struct gsm48_loc_area_id *lai;
91 struct gsm48_hdr *gh;
92 uint8_t mtype;
93
94 if (msgb_l3len(msg) < sizeof(*gh)) {
95 LOGP(DMSC, LOGL_ERROR, "GSM48 header does not fit.\n");
96 return -1;
97 }
98
99 gh = (struct gsm48_hdr *) msgb_l3(msg);
100 mtype = gh->msg_type & 0xbf;
101 net = conn->bts->network;
102
103 if (mtype == GSM48_MT_MM_LOC_UPD_ACCEPT) {
Holger Hans Peter Freyther2a8675e2010-11-05 19:43:07 +0100104 if (net->msc_data->core_ncc != -1 ||
105 net->msc_data->core_mcc != -1) {
Holger Hans Peter Freyther52d42ab2010-11-05 18:41:04 +0100106 if (msgb_l3len(msg) >= sizeof(*gh) + sizeof(*lai)) {
107 lai = (struct gsm48_loc_area_id *) &gh->data[0];
108 gsm48_generate_lai(lai, net->country_code,
109 net->network_code,
110 conn->bts->location_area_code);
111 }
112 }
113
114 if (conn->sccp_con->new_subscriber)
115 send_welcome_ussd(conn);
116 }
117
Holger Hans Peter Freythera54732d2010-11-05 18:11:19 +0100118 return 0;
119}