blob: 6ff30b7486dbecb895a9ad7c1e67c7d5cbba597f [file] [log] [blame]
Harald Welteeab84a12009-12-13 10:53:12 +01001/* Radio Resource LCS (Location) Protocol, GMS TS 04.31 */
Harald Welte (local)b8afe812009-08-16 13:18:51 +02002
3/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01008 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
Harald Welte (local)b8afe812009-08-16 13:18:51 +020010 * (at your option) any later version.
11 *
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
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte (local)b8afe812009-08-16 13:18:51 +020016 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte (local)b8afe812009-08-16 13:18:51 +020019 *
20 */
21
Vadim Yanitskiy096be502018-08-04 01:06:46 +070022#include <stdint.h>
Harald Welte (local)b8afe812009-08-16 13:18:51 +020023
Vadim Yanitskiy1b891302018-08-04 01:33:08 +070024#include <osmocom/core/utils.h>
25
Neels Hofmeyr90843962017-09-04 15:04:35 +020026#include <osmocom/msc/gsm_04_08.h>
27#include <osmocom/msc/signal.h>
Vadim Yanitskiy6cc377d2018-08-04 01:37:50 +070028#include <osmocom/msc/debug.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020029#include <osmocom/msc/gsm_subscriber.h>
Neels Hofmeyra8945ce2018-11-30 00:44:32 +010030#include <osmocom/msc/ran_conn.h>
Harald Welte (local)b8afe812009-08-16 13:18:51 +020031
Harald Welteeab84a12009-12-13 10:53:12 +010032/* RRLP msPositionReq, nsBased,
33 * Accuracy=60, Method=gps, ResponseTime=2, oneSet */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020034static const uint8_t ms_based_pos_req[] = { 0x40, 0x01, 0x78, 0xa8 };
Harald Welte (local)b8afe812009-08-16 13:18:51 +020035
Harald Welteeab84a12009-12-13 10:53:12 +010036/* RRLP msPositionReq, msBasedPref,
37 Accuracy=60, Method=gpsOrEOTD, ResponseTime=5, multipleSets */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020038static const uint8_t ms_pref_pos_req[] = { 0x40, 0x02, 0x79, 0x50 };
Harald Welteeab84a12009-12-13 10:53:12 +010039
40/* RRLP msPositionReq, msAssistedPref,
41 Accuracy=60, Method=gpsOrEOTD, ResponseTime=5, multipleSets */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020042static const uint8_t ass_pref_pos_req[] = { 0x40, 0x03, 0x79, 0x50 };
Harald Welteeab84a12009-12-13 10:53:12 +010043
Vadim Yanitskiy1b891302018-08-04 01:33:08 +070044static const struct value_string rrlp_mode_names[] = {
45 { RRLP_MODE_NONE, "none" },
46 { RRLP_MODE_MS_BASED, "ms-based" },
47 { RRLP_MODE_MS_PREF, "ms-preferred" },
48 { RRLP_MODE_ASS_PREF, "ass-preferred" },
49 { 0, NULL }
50};
51
52enum rrlp_mode msc_rrlp_mode_parse(const char *arg)
53{
54 return get_string_value(rrlp_mode_names, arg);
55}
56
57const char *msc_rrlp_mode_name(enum rrlp_mode mode)
58{
59 return get_value_string(rrlp_mode_names, mode);
60}
61
Neels Hofmeyrc036b792018-11-29 22:37:51 +010062static int send_rrlp_req(struct ran_conn *conn)
Harald Welteeab84a12009-12-13 10:53:12 +010063{
Neels Hofmeyra9f2bb52016-05-09 21:09:47 +020064 struct gsm_network *net = conn->network;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020065 const uint8_t *req;
Harald Welteeab84a12009-12-13 10:53:12 +010066
67 switch (net->rrlp.mode) {
68 case RRLP_MODE_MS_BASED:
69 req = ms_based_pos_req;
70 break;
71 case RRLP_MODE_MS_PREF:
72 req = ms_pref_pos_req;
73 break;
74 case RRLP_MODE_ASS_PREF:
75 req = ass_pref_pos_req;
76 break;
77 case RRLP_MODE_NONE:
78 default:
79 return 0;
80 }
81
Vadim Yanitskiy6cc377d2018-08-04 01:37:50 +070082 LOGP(DRR, LOGL_INFO, "Sending '%s' RRLP position request\n",
83 msc_rrlp_mode_name(net->rrlp.mode));
84
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +080085 return gsm48_send_rr_app_info(conn, 0x00,
Harald Welteeab84a12009-12-13 10:53:12 +010086 sizeof(ms_based_pos_req), req);
87}
88
Harald Welte (local)b8afe812009-08-16 13:18:51 +020089static int subscr_sig_cb(unsigned int subsys, unsigned int signal,
90 void *handler_data, void *signal_data)
91{
Harald Welte2483f1b2016-06-19 18:06:02 +020092 struct vlr_subscr *vsub;
Neels Hofmeyrc036b792018-11-29 22:37:51 +010093 struct ran_conn *conn;
Harald Welte (local)b8afe812009-08-16 13:18:51 +020094
95 switch (signal) {
96 case S_SUBSCR_ATTACHED:
97 /* A subscriber has attached. */
Harald Welte2483f1b2016-06-19 18:06:02 +020098 vsub = signal_data;
99 conn = connection_for_subscr(vsub);
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +0800100 if (!conn)
Harald Welte (local)b8afe812009-08-16 13:18:51 +0200101 break;
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +0800102 send_rrlp_req(conn);
Harald Welte (local)b8afe812009-08-16 13:18:51 +0200103 break;
104 }
105 return 0;
106}
107
108static int paging_sig_cb(unsigned int subsys, unsigned int signal,
109 void *handler_data, void *signal_data)
110{
111 struct paging_signal_data *psig_data = signal_data;
112
113 switch (signal) {
Sylvain Munautef24dff2009-12-19 12:38:10 +0100114 case S_PAGING_SUCCEEDED:
Harald Welte (local)b8afe812009-08-16 13:18:51 +0200115 /* A subscriber has attached. */
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +0800116 send_rrlp_req(psig_data->conn);
Harald Welte (local)b8afe812009-08-16 13:18:51 +0200117 break;
Sylvain Munautef24dff2009-12-19 12:38:10 +0100118 case S_PAGING_EXPIRED:
119 break;
Harald Welte (local)b8afe812009-08-16 13:18:51 +0200120 }
121 return 0;
122}
123
Vadim Yanitskiyd01b5942018-08-04 01:13:49 +0700124void msc_rrlp_init(void)
Harald Welte (local)b8afe812009-08-16 13:18:51 +0200125{
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +0200126 osmo_signal_register_handler(SS_SUBSCR, subscr_sig_cb, NULL);
127 osmo_signal_register_handler(SS_PAGING, paging_sig_cb, NULL);
Harald Welte (local)b8afe812009-08-16 13:18:51 +0200128}