2015-10-06 20:07:04 +00:00
|
|
|
/* common RUA (RANAP User Adaption) Code */
|
|
|
|
|
|
|
|
/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2015-09-10 16:33:47 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
|
2016-08-26 21:56:44 +00:00
|
|
|
#include <osmocom/rua/rua_common.h>
|
2015-09-10 16:33:47 +00:00
|
|
|
|
|
|
|
extern int asn1_xer_print;
|
|
|
|
|
2022-01-04 16:23:47 +00:00
|
|
|
int _rua_DRUA = 0;
|
|
|
|
#define DRUA _rua_DRUA
|
|
|
|
|
2015-09-10 21:49:45 +00:00
|
|
|
static const struct value_string rua_cause_radio_vals[] = {
|
|
|
|
{ RUA_CauseRadioNetwork_normal, "normal" },
|
|
|
|
{ RUA_CauseRadioNetwork_connect_failed, "connect failed" },
|
|
|
|
{ RUA_CauseRadioNetwork_network_release, "network release" },
|
|
|
|
{ RUA_CauseRadioNetwork_unspecified, "unspecified" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct value_string rua_cause_transp_vals[] = {
|
|
|
|
{ RUA_CauseTransport_transport_resource_unavailable, "resource unavailable" },
|
|
|
|
{ RUA_CauseTransport_unspecified, "unspecified" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct value_string rua_cause_prot_vals[] = {
|
|
|
|
{ RUA_CauseProtocol_transfer_syntax_error, "syntax error" },
|
|
|
|
{ RUA_CauseProtocol_abstract_syntax_error_reject,
|
|
|
|
"abstract syntax error; reject" },
|
|
|
|
{ RUA_CauseProtocol_abstract_syntax_error_ignore_and_notify,
|
|
|
|
"abstract syntax error; ignore and notify" },
|
|
|
|
{ RUA_CauseProtocol_message_not_compatible_with_receiver_state,
|
|
|
|
"message not compatible with receiver state" },
|
|
|
|
{ RUA_CauseProtocol_semantic_error, "semantic error" },
|
|
|
|
{ RUA_CauseProtocol_unspecified, "unspecified" },
|
|
|
|
{ RUA_CauseProtocol_abstract_syntax_error_falsely_constructed_message,
|
|
|
|
"falsely constructed message" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct value_string rua_cause_misc_vals[] = {
|
|
|
|
{ RUA_CauseMisc_processing_overload, "processing overload" },
|
|
|
|
{ RUA_CauseMisc_hardware_failure, "hardware failure" },
|
|
|
|
{ RUA_CauseMisc_o_and_m_intervention, "OAM intervention" },
|
|
|
|
{ RUA_CauseMisc_unspecified, "unspecified" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
char *rua_cause_str(RUA_Cause_t *cause)
|
|
|
|
{
|
|
|
|
static char buf[32];
|
|
|
|
|
|
|
|
switch (cause->present) {
|
|
|
|
case RUA_Cause_PR_radioNetwork:
|
|
|
|
snprintf(buf, sizeof(buf), "radio(%s)",
|
|
|
|
get_value_string(rua_cause_radio_vals,
|
|
|
|
cause->choice.radioNetwork));
|
|
|
|
break;
|
|
|
|
case RUA_Cause_PR_transport:
|
|
|
|
snprintf(buf, sizeof(buf), "transport(%s)",
|
|
|
|
get_value_string(rua_cause_transp_vals,
|
|
|
|
cause->choice.transport));
|
|
|
|
break;
|
|
|
|
case RUA_Cause_PR_protocol:
|
|
|
|
snprintf(buf, sizeof(buf), "protocol(%s)",
|
|
|
|
get_value_string(rua_cause_prot_vals,
|
|
|
|
cause->choice.protocol));
|
|
|
|
break;
|
|
|
|
case RUA_Cause_PR_misc:
|
|
|
|
snprintf(buf, sizeof(buf), "misc(%s)",
|
|
|
|
get_value_string(rua_cause_misc_vals,
|
|
|
|
cause->choice.misc));
|
|
|
|
break;
|
2015-12-25 09:17:17 +00:00
|
|
|
default:
|
|
|
|
strcpy(buf, "unknown");
|
|
|
|
break;
|
2015-09-10 21:49:45 +00:00
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-10 16:33:47 +00:00
|
|
|
static struct msgb *rua_msgb_alloc(void)
|
|
|
|
{
|
|
|
|
return msgb_alloc(1024, "RUA Tx");
|
|
|
|
}
|
|
|
|
|
2015-12-16 19:27:14 +00:00
|
|
|
static struct msgb *_rua_gen_msg(RUA_RUA_PDU_t *pdu)
|
|
|
|
{
|
|
|
|
struct msgb *msg = rua_msgb_alloc();
|
|
|
|
asn_enc_rval_t rval;
|
|
|
|
|
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
rval = aper_encode_to_buffer(&asn_DEF_RUA_RUA_PDU, pdu,
|
|
|
|
msg->data, msgb_tailroom(msg));
|
|
|
|
if (rval.encoded < 0) {
|
2015-12-23 14:36:31 +00:00
|
|
|
LOGP(DRUA, LOGL_ERROR, "Error encoding type: %s\n",
|
2015-12-16 19:27:14 +00:00
|
|
|
rval.failed_type->name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
msgb_put(msg, rval.encoded/8);
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-10 21:49:45 +00:00
|
|
|
struct msgb *rua_generate_initiating_message(
|
2015-09-10 16:33:47 +00:00
|
|
|
e_RUA_ProcedureCode procedureCode,
|
|
|
|
RUA_Criticality_t criticality,
|
|
|
|
asn_TYPE_descriptor_t * td, void *sptr)
|
|
|
|
{
|
|
|
|
RUA_RUA_PDU_t pdu;
|
2015-12-16 19:27:14 +00:00
|
|
|
int rc;
|
2015-09-10 16:33:47 +00:00
|
|
|
|
|
|
|
memset(&pdu, 0, sizeof(pdu));
|
2015-12-16 19:27:14 +00:00
|
|
|
|
2015-09-10 16:33:47 +00:00
|
|
|
pdu.present = RUA_RUA_PDU_PR_initiatingMessage;
|
|
|
|
pdu.choice.initiatingMessage.procedureCode = procedureCode;
|
|
|
|
pdu.choice.initiatingMessage.criticality = criticality;
|
2015-12-16 19:27:14 +00:00
|
|
|
rc = ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr);
|
|
|
|
if (rc < 0) {
|
2020-07-29 18:11:36 +00:00
|
|
|
LOGP(DRUA, LOGL_ERROR, "Error in ANY_fromType_aper (%s)\n", td->name);
|
2015-09-10 21:49:45 +00:00
|
|
|
return NULL;
|
2015-09-10 16:33:47 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 19:27:14 +00:00
|
|
|
return _rua_gen_msg(&pdu);
|
2015-09-10 16:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct msgb *rua_generate_successful_outcome(
|
|
|
|
e_RUA_ProcedureCode procedureCode,
|
|
|
|
RUA_Criticality_t criticality,
|
|
|
|
asn_TYPE_descriptor_t * td,
|
|
|
|
void *sptr)
|
|
|
|
{
|
|
|
|
RUA_RUA_PDU_t pdu;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
memset(&pdu, 0, sizeof(pdu));
|
2015-12-16 19:27:14 +00:00
|
|
|
|
2015-09-10 16:33:47 +00:00
|
|
|
pdu.present = RUA_RUA_PDU_PR_successfulOutcome;
|
|
|
|
pdu.choice.successfulOutcome.procedureCode = procedureCode;
|
|
|
|
pdu.choice.successfulOutcome.criticality = criticality;
|
|
|
|
rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr);
|
|
|
|
if (rc < 0) {
|
2020-07-29 18:11:36 +00:00
|
|
|
LOGP(DRUA, LOGL_ERROR, "Error in ANY_fromType_aper (%s)\n", td->name);
|
2015-09-10 16:33:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-16 19:27:14 +00:00
|
|
|
return _rua_gen_msg(&pdu);
|
2015-09-10 16:33:47 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 19:17:26 +00:00
|
|
|
struct msgb *rua_generate_unsuccessful_outcome(
|
|
|
|
e_RUA_ProcedureCode procedureCode,
|
|
|
|
RUA_Criticality_t criticality,
|
|
|
|
asn_TYPE_descriptor_t * td,
|
|
|
|
void *sptr)
|
2015-09-10 16:33:47 +00:00
|
|
|
{
|
|
|
|
RUA_RUA_PDU_t pdu;
|
2015-12-16 19:17:26 +00:00
|
|
|
int rc;
|
2015-09-10 16:33:47 +00:00
|
|
|
|
|
|
|
memset(&pdu, 0, sizeof(pdu));
|
2015-12-16 19:27:14 +00:00
|
|
|
|
2015-09-10 16:33:47 +00:00
|
|
|
pdu.present = RUA_RUA_PDU_PR_unsuccessfulOutcome;
|
2015-12-16 19:17:26 +00:00
|
|
|
pdu.choice.unsuccessfulOutcome.procedureCode = procedureCode;
|
|
|
|
pdu.choice.unsuccessfulOutcome.criticality = criticality;
|
|
|
|
rc = ANY_fromType_aper(&pdu.choice.unsuccessfulOutcome.value, td, sptr);
|
|
|
|
if (rc < 0) {
|
2020-07-29 18:11:36 +00:00
|
|
|
LOGP(DRUA, LOGL_ERROR, "Error in ANY_fromType_aper (%s)\n", td->name);
|
2015-12-16 19:17:26 +00:00
|
|
|
return NULL;
|
2015-09-10 16:33:47 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 19:27:14 +00:00
|
|
|
return _rua_gen_msg(&pdu);
|
2015-09-10 16:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RUA_IE_t *rua_new_ie(RUA_ProtocolIE_ID_t id,
|
|
|
|
RUA_Criticality_t criticality,
|
|
|
|
asn_TYPE_descriptor_t * type, void *sptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
RUA_IE_t *buff;
|
2015-12-18 14:17:21 +00:00
|
|
|
int rc;
|
2015-09-10 16:33:47 +00:00
|
|
|
|
2015-12-18 12:41:39 +00:00
|
|
|
if ((buff = CALLOC(1, sizeof(*buff))) == NULL) {
|
2015-09-10 16:33:47 +00:00
|
|
|
// Possible error on malloc
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
buff->id = id;
|
|
|
|
buff->criticality = criticality;
|
|
|
|
|
2015-12-18 14:17:21 +00:00
|
|
|
rc = ANY_fromType_aper(&buff->value, type, sptr);
|
|
|
|
if (rc < 0) {
|
2020-07-29 18:11:36 +00:00
|
|
|
LOGP(DRUA, LOGL_ERROR, "Error in ANY_fromType_aper (%s)\n", type->name);
|
2015-12-18 14:17:21 +00:00
|
|
|
FREEMEM(buff);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-10 16:33:47 +00:00
|
|
|
|
|
|
|
if (asn1_xer_print)
|
|
|
|
if (xer_fprint(stdout, &asn_DEF_RUA_IE, buff) < 0) {
|
2015-12-18 13:57:04 +00:00
|
|
|
FREEMEM(buff);
|
2015-09-10 16:33:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
2022-01-04 16:23:47 +00:00
|
|
|
|
|
|
|
void rua_set_log_area(int log_area)
|
|
|
|
{
|
|
|
|
_rua_DRUA = log_area;
|
|
|
|
}
|