Harald Welte | 77847ad | 2015-10-06 22:07:04 +0200 | [diff] [blame] | 1 | /* hnb-gw specific code for RANAP */ |
| 2 | |
| 3 | /* (C) 2015 by Harald Welte <laforge@gnumonks.org> |
| 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 Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 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 Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 23 | #include <osmocom/core/msgb.h> |
| 24 | #include <osmocom/core/utils.h> |
| 25 | |
| 26 | #include <unistd.h> |
| 27 | #include <errno.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | #include "asn1helpers.h" |
| 31 | |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 32 | #include <osmocom/iuh/hnbgw.h> |
| 33 | #include <osmocom/iuh/hnbgw_rua.h> |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 34 | #include <osmocom/ranap/ranap_common.h> |
| 35 | #include <osmocom/ranap/ranap_ies_defs.h> |
Neels Hofmeyr | f168a3b | 2016-04-25 15:09:20 +0200 | [diff] [blame] | 36 | #include <osmocom/ranap/ranap_msg_factory.h> |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 37 | |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 38 | static int ranap_tx_reset_ack(struct hnb_context *hnb, |
| 39 | RANAP_CN_DomainIndicator_t domain) |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 40 | { |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 41 | struct msgb *msg; |
| 42 | int rc; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 43 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 44 | msg = ranap_new_msg_reset_ack(domain, NULL); |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 45 | if (!msg) |
| 46 | return -1; |
| 47 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 48 | rc = rua_tx_udt(hnb, msg->data, msgb_length(msg)); |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 49 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 50 | msgb_free(msg); |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 51 | |
| 52 | return rc; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 53 | } |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 54 | |
| 55 | static int ranap_rx_init_reset(struct hnb_context *hnb, ANY_t *in) |
| 56 | { |
| 57 | RANAP_ResetIEs_t ies; |
Harald Welte | ea98b6f | 2015-12-24 15:09:06 +0100 | [diff] [blame] | 58 | int rc, is_ps = 0; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 59 | |
| 60 | rc = ranap_decode_reseties(&ies, in); |
| 61 | if (rc < 0) |
| 62 | return rc; |
| 63 | |
Harald Welte | ea98b6f | 2015-12-24 15:09:06 +0100 | [diff] [blame] | 64 | if (ies.cN_DomainIndicator == RANAP_CN_DomainIndicator_ps_domain) |
| 65 | is_ps=1; |
| 66 | |
Harald Welte | 23058e1 | 2015-12-25 10:25:01 +0100 | [diff] [blame] | 67 | LOGP(DRANAP, LOGL_INFO, "Rx RESET.req(%s,%s)\n", is_ps ? "ps" : "cs", |
| 68 | ranap_cause_str(&ies.cause)); |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 69 | |
Harald Welte | 80401ad | 2015-09-11 19:48:06 +0200 | [diff] [blame] | 70 | /* FIXME: Actually we have to wait for some guard time? */ |
| 71 | /* FIXME: Reset all resources related to this HNB/RNC */ |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 72 | ranap_tx_reset_ack(hnb, ies.cN_DomainIndicator); |
| 73 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | |
Harald Welte | 23058e1 | 2015-12-25 10:25:01 +0100 | [diff] [blame] | 77 | static int ranap_rx_error_ind(struct hnb_context *hnb, ANY_t *in) |
| 78 | { |
| 79 | RANAP_ErrorIndicationIEs_t ies; |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 80 | int rc; |
Harald Welte | 23058e1 | 2015-12-25 10:25:01 +0100 | [diff] [blame] | 81 | |
| 82 | rc = ranap_decode_errorindicationies(&ies, in); |
| 83 | if (rc < 0) |
| 84 | return rc; |
| 85 | |
| 86 | if (ies.presenceMask & ERRORINDICATIONIES_RANAP_CAUSE_PRESENT) { |
| 87 | LOGP(DRANAP, LOGL_ERROR, "Rx ERROR.ind(%s)\n", |
| 88 | ranap_cause_str(&ies.cause)); |
| 89 | } else |
| 90 | LOGP(DRANAP, LOGL_ERROR, "Rx ERROR.ind\n"); |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 95 | static int ranap_rx_initiating_msg(struct hnb_context *hnb, RANAP_InitiatingMessage_t *imsg) |
| 96 | { |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 97 | int rc = 0; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 98 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 99 | /* according tot the spec, we can primarily receive Overload, |
| 100 | * Reset, Reset ACK, Error Indication, reset Resource, Reset |
| 101 | * Resurce Acknowledge as connecitonless RANAP. There are some |
| 102 | * more messages regarding Information Transfer, Direct |
| 103 | * Information Transfer and Uplink Information Trnansfer that we |
| 104 | * can ignore. In either case, it is RANAP that we need to |
| 105 | * decode... */ |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 106 | switch (imsg->procedureCode) { |
| 107 | case RANAP_ProcedureCode_id_Reset: |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 108 | /* Reset request */ |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 109 | rc = ranap_rx_init_reset(hnb, &imsg->value); |
| 110 | break; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 111 | case RANAP_ProcedureCode_id_OverloadControl: /* Overload ind */ |
Harald Welte | 80401ad | 2015-09-11 19:48:06 +0200 | [diff] [blame] | 112 | break; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 113 | case RANAP_ProcedureCode_id_ErrorIndication: /* Error ind */ |
Harald Welte | 23058e1 | 2015-12-25 10:25:01 +0100 | [diff] [blame] | 114 | rc = ranap_rx_error_ind(hnb, &imsg->value); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 115 | break; |
| 116 | case RANAP_ProcedureCode_id_ResetResource: /* request */ |
| 117 | case RANAP_ProcedureCode_id_InformationTransfer: |
| 118 | case RANAP_ProcedureCode_id_DirectInformationTransfer: |
| 119 | case RANAP_ProcedureCode_id_UplinkInformationExchange: |
| 120 | LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP " |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 121 | "Procedure %lu from HNB, ignoring\n", imsg->procedureCode); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 122 | break; |
| 123 | default: |
| 124 | LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP " |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 125 | "Procedure %lu from HNB, ignoring\n", imsg->procedureCode); |
Harald Welte | 1c2ada0 | 2015-09-11 20:10:17 +0200 | [diff] [blame] | 126 | break; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 127 | } |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 128 | |
| 129 | return rc; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 130 | } |
| 131 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 132 | static int ranap_rx_successful_msg(struct hnb_context *hnb, RANAP_SuccessfulOutcome_t *imsg) |
| 133 | { |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 134 | /* according tot the spec, we can primarily receive Overload, |
| 135 | * Reset, Reset ACK, Error Indication, reset Resource, Reset |
| 136 | * Resurce Acknowledge as connecitonless RANAP. There are some |
| 137 | * more messages regarding Information Transfer, Direct |
| 138 | * Information Transfer and Uplink Information Trnansfer that we |
| 139 | * can ignore. In either case, it is RANAP that we need to |
| 140 | * decode... */ |
| 141 | switch (imsg->procedureCode) { |
| 142 | case RANAP_ProcedureCode_id_Reset: /* Reset acknowledge */ |
| 143 | break; |
| 144 | case RANAP_ProcedureCode_id_ResetResource: /* response */ |
| 145 | case RANAP_ProcedureCode_id_InformationTransfer: |
| 146 | case RANAP_ProcedureCode_id_DirectInformationTransfer: |
| 147 | case RANAP_ProcedureCode_id_UplinkInformationExchange: |
| 148 | LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP " |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 149 | "Procedure %lu from HNB, ignoring\n", imsg->procedureCode); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 150 | break; |
| 151 | default: |
| 152 | LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP " |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 153 | "Procedure %lu from HNB, ignoring\n", imsg->procedureCode); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 154 | break; |
| 155 | } |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 156 | |
| 157 | return 0; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
| 161 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 162 | static int _hnbgw_ranap_rx(struct hnb_context *hnb, RANAP_RANAP_PDU_t *pdu) |
| 163 | { |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 164 | int rc = 0; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 165 | |
| 166 | switch (pdu->present) { |
| 167 | case RANAP_RANAP_PDU_PR_initiatingMessage: |
| 168 | rc = ranap_rx_initiating_msg(hnb, &pdu->choice.initiatingMessage); |
| 169 | break; |
| 170 | case RANAP_RANAP_PDU_PR_successfulOutcome: |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 171 | rc = ranap_rx_successful_msg(hnb, &pdu->choice.successfulOutcome); |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 172 | break; |
| 173 | case RANAP_RANAP_PDU_PR_unsuccessfulOutcome: |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 174 | LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP " |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 175 | "unsuccessful outcome procedure %lu from HNB, ignoring\n", |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 176 | pdu->choice.unsuccessfulOutcome.procedureCode); |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 177 | break; |
| 178 | default: |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 179 | LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP " |
| 180 | "presence %u from HNB, ignoring\n", pdu->present); |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 181 | break; |
| 182 | } |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 183 | |
| 184 | return rc; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
| 188 | int hnbgw_ranap_rx(struct msgb *msg, uint8_t *data, size_t len) |
| 189 | { |
| 190 | RANAP_RANAP_PDU_t _pdu, *pdu = &_pdu; |
| 191 | asn_dec_rval_t dec_ret; |
| 192 | int rc; |
| 193 | |
| 194 | memset(pdu, 0, sizeof(*pdu)); |
| 195 | dec_ret = aper_decode(NULL,&asn_DEF_RANAP_RANAP_PDU, (void **) &pdu, |
| 196 | data, len, 0, 0); |
| 197 | if (dec_ret.code != RC_OK) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 198 | LOGP(DRANAP, LOGL_ERROR, "Error in RANAP ASN.1 decode\n"); |
Neels Hofmeyr | a6a68e6 | 2016-11-25 13:21:02 +0100 | [diff] [blame] | 199 | return -1; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | rc = _hnbgw_ranap_rx(msg->dst, pdu); |
| 203 | |
| 204 | return rc; |
| 205 | } |
| 206 | |
| 207 | int hnbgw_ranap_init(void) |
| 208 | { |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 209 | return 0; |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 210 | } |