Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 1 | /* Radio Resource LCS (Location) Protocol, GMS TS 04.31 */ |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 2 | |
| 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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * 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) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 10 | * (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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * 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) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
Vadim Yanitskiy | 096be50 | 2018-08-04 01:06:46 +0700 | [diff] [blame] | 22 | #include <stdint.h> |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 23 | |
Vadim Yanitskiy | 1b89130 | 2018-08-04 01:33:08 +0700 | [diff] [blame] | 24 | #include <osmocom/core/utils.h> |
| 25 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 26 | #include <osmocom/msc/gsm_04_08.h> |
| 27 | #include <osmocom/msc/signal.h> |
Vadim Yanitskiy | 6cc377d | 2018-08-04 01:37:50 +0700 | [diff] [blame] | 28 | #include <osmocom/msc/debug.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 29 | #include <osmocom/msc/gsm_subscriber.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 30 | #include <osmocom/msc/msc_a.h> |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 31 | |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 32 | /* RRLP msPositionReq, nsBased, |
| 33 | * Accuracy=60, Method=gps, ResponseTime=2, oneSet */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 34 | static const uint8_t ms_based_pos_req[] = { 0x40, 0x01, 0x78, 0xa8 }; |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 35 | |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 36 | /* RRLP msPositionReq, msBasedPref, |
| 37 | Accuracy=60, Method=gpsOrEOTD, ResponseTime=5, multipleSets */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 38 | static const uint8_t ms_pref_pos_req[] = { 0x40, 0x02, 0x79, 0x50 }; |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 39 | |
| 40 | /* RRLP msPositionReq, msAssistedPref, |
| 41 | Accuracy=60, Method=gpsOrEOTD, ResponseTime=5, multipleSets */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 42 | static const uint8_t ass_pref_pos_req[] = { 0x40, 0x03, 0x79, 0x50 }; |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 43 | |
Vadim Yanitskiy | 1b89130 | 2018-08-04 01:33:08 +0700 | [diff] [blame] | 44 | static 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 | |
| 52 | enum rrlp_mode msc_rrlp_mode_parse(const char *arg) |
| 53 | { |
| 54 | return get_string_value(rrlp_mode_names, arg); |
| 55 | } |
| 56 | |
| 57 | const char *msc_rrlp_mode_name(enum rrlp_mode mode) |
| 58 | { |
| 59 | return get_value_string(rrlp_mode_names, mode); |
| 60 | } |
| 61 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 62 | static int send_rrlp_req(struct msc_a *msc_a) |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 63 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 64 | struct gsm_network *net = msc_a_net(msc_a); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 65 | const uint8_t *req; |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 66 | |
| 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 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 82 | LOG_MSC_A_CAT(msc_a, DRR, LOGL_INFO, "Sending '%s' RRLP position request\n", msc_rrlp_mode_name(net->rrlp.mode)); |
Vadim Yanitskiy | 6cc377d | 2018-08-04 01:37:50 +0700 | [diff] [blame] | 83 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 84 | return gsm48_send_rr_app_info(msc_a, 0x00, sizeof(ms_based_pos_req), req); |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 87 | static int subscr_sig_cb(unsigned int subsys, unsigned int signal, |
| 88 | void *handler_data, void *signal_data) |
| 89 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 90 | struct vlr_subscr *vsub; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 91 | struct msc_a *msc_a; |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 92 | |
| 93 | switch (signal) { |
| 94 | case S_SUBSCR_ATTACHED: |
| 95 | /* A subscriber has attached. */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 96 | vsub = signal_data; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 97 | msc_a = msc_a_for_vsub(vsub, true); |
| 98 | if (!msc_a) |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 99 | break; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 100 | send_rrlp_req(msc_a); |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 101 | break; |
| 102 | } |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static int paging_sig_cb(unsigned int subsys, unsigned int signal, |
| 107 | void *handler_data, void *signal_data) |
| 108 | { |
| 109 | struct paging_signal_data *psig_data = signal_data; |
| 110 | |
| 111 | switch (signal) { |
Sylvain Munaut | ef24dff | 2009-12-19 12:38:10 +0100 | [diff] [blame] | 112 | case S_PAGING_SUCCEEDED: |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 113 | /* A subscriber has attached. */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 114 | send_rrlp_req(psig_data->msc_a); |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 115 | break; |
Sylvain Munaut | ef24dff | 2009-12-19 12:38:10 +0100 | [diff] [blame] | 116 | case S_PAGING_EXPIRED: |
| 117 | break; |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 118 | } |
| 119 | return 0; |
| 120 | } |
| 121 | |
Vadim Yanitskiy | d01b594 | 2018-08-04 01:13:49 +0700 | [diff] [blame] | 122 | void msc_rrlp_init(void) |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 123 | { |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 124 | osmo_signal_register_handler(SS_SUBSCR, subscr_sig_cb, NULL); |
| 125 | osmo_signal_register_handler(SS_PAGING, paging_sig_cb, NULL); |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 126 | } |