2015-10-06 20:07:04 +00:00
|
|
|
/* HNBAP common 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-08-30 20:47:18 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
|
2016-08-26 21:56:44 +00:00
|
|
|
#include <osmocom/hnbap/hnbap_common.h>
|
2022-01-04 16:23:47 +00:00
|
|
|
|
|
|
|
int _hnbap_DHNBAP = 0;
|
|
|
|
#define DHNBAP _hnbap_DHNBAP
|
2015-08-30 20:47:18 +00:00
|
|
|
|
2015-09-11 15:03:16 +00:00
|
|
|
static const struct value_string hnbap_cause_radio_vals[] = {
|
2021-10-22 23:29:46 +00:00
|
|
|
{ HNBAP_CauseRadioNetwork_overload, "overload" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_unauthorised_Location, "unauthorized location" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_unauthorised_HNB, "unauthorized HNB" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_hNB_parameter_mismatch, "HNB parameter mismatch" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_invalid_UE_identity, "invalid UE identity" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_uE_not_allowed_on_this_HNB,
|
2015-09-11 15:03:16 +00:00
|
|
|
"UE not allowed on this HNB" },
|
2021-10-22 23:29:46 +00:00
|
|
|
{ HNBAP_CauseRadioNetwork_uE_unauthorised, "unauthorised UE" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_connection_with_UE_lost, "connection with UE lost" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_ue_RRC_release, "UE RRC release" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_hNB_not_registered, "HNB not registered" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_unspecified, "unspecified" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_normal, "normal" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_uE_relocated, "UE relocated" },
|
|
|
|
{ HNBAP_CauseRadioNetwork_ue_registered_in_another_HNB,
|
2015-09-11 15:03:16 +00:00
|
|
|
"UE registered in another HNB" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct value_string hnbap_cause_transp_vals[] = {
|
2021-10-22 23:29:46 +00:00
|
|
|
{ HNBAP_CauseTransport_transport_resource_unavailable,
|
2015-09-11 15:03:16 +00:00
|
|
|
"transport resource unavailable" },
|
2021-10-22 23:29:46 +00:00
|
|
|
{ HNBAP_CauseTransport_unspecified, "unspecified" },
|
2015-09-11 15:03:16 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct value_string hnbap_cause_prot_vals[] = {
|
2021-10-22 23:29:46 +00:00
|
|
|
{ HNBAP_CauseProtocol_transfer_syntax_error, "syntax error" },
|
|
|
|
{ HNBAP_CauseProtocol_abstract_syntax_error_reject,
|
2015-09-11 15:03:16 +00:00
|
|
|
"abstract syntax error; reject" },
|
2021-10-22 23:29:46 +00:00
|
|
|
{ HNBAP_CauseProtocol_abstract_syntax_error_ignore_and_notify,
|
2015-09-11 15:03:16 +00:00
|
|
|
"abstract syntax error; ignore and notify" },
|
2021-10-22 23:29:46 +00:00
|
|
|
{ HNBAP_CauseProtocol_message_not_compatible_with_receiver_state,
|
2015-09-11 15:03:16 +00:00
|
|
|
"message not compatible with receiver state" },
|
2021-10-22 23:29:46 +00:00
|
|
|
{ HNBAP_CauseProtocol_semantic_error, "semantic error" },
|
|
|
|
{ HNBAP_CauseProtocol_unspecified, "unspecified" },
|
|
|
|
{ HNBAP_CauseProtocol_abstract_syntax_error_falsely_constructed_message,
|
2015-09-11 15:03:16 +00:00
|
|
|
"falsely constructed message" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct value_string hnbap_cause_misc_vals[] = {
|
2021-10-22 23:29:46 +00:00
|
|
|
{ HNBAP_CauseMisc_processing_overload, "processing overload" },
|
|
|
|
{ HNBAP_CauseMisc_hardware_failure, "hardware failure" },
|
|
|
|
{ HNBAP_CauseMisc_o_and_m_intervention, "OAM intervention" },
|
|
|
|
{ HNBAP_CauseMisc_unspecified, "unspecified" },
|
2015-09-11 15:03:16 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
char *hnbap_cause_str(HNBAP_Cause_t *cause)
|
2015-09-11 15:03:16 +00:00
|
|
|
{
|
|
|
|
static char buf[32];
|
|
|
|
|
|
|
|
switch (cause->present) {
|
2021-10-22 23:29:46 +00:00
|
|
|
case HNBAP_Cause_PR_radioNetwork:
|
2015-09-11 15:03:16 +00:00
|
|
|
snprintf(buf, sizeof(buf), "radio(%s)",
|
|
|
|
get_value_string(hnbap_cause_radio_vals,
|
|
|
|
cause->choice.radioNetwork));
|
|
|
|
break;
|
2021-10-22 23:29:46 +00:00
|
|
|
case HNBAP_Cause_PR_transport:
|
2015-09-11 15:03:16 +00:00
|
|
|
snprintf(buf, sizeof(buf), "transport(%s)",
|
|
|
|
get_value_string(hnbap_cause_transp_vals,
|
|
|
|
cause->choice.transport));
|
|
|
|
break;
|
2021-10-22 23:29:46 +00:00
|
|
|
case HNBAP_Cause_PR_protocol:
|
2015-09-11 15:03:16 +00:00
|
|
|
snprintf(buf, sizeof(buf), "protocol(%s)",
|
|
|
|
get_value_string(hnbap_cause_prot_vals,
|
|
|
|
cause->choice.protocol));
|
|
|
|
break;
|
2021-10-22 23:29:46 +00:00
|
|
|
case HNBAP_Cause_PR_misc:
|
2015-09-11 15:03:16 +00:00
|
|
|
snprintf(buf, sizeof(buf), "misc(%s)",
|
|
|
|
get_value_string(hnbap_cause_misc_vals,
|
|
|
|
cause->choice.misc));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2015-08-30 20:47:18 +00:00
|
|
|
static struct msgb *hnbap_msgb_alloc(void)
|
|
|
|
{
|
|
|
|
return msgb_alloc(1024, "HNBAP Tx");
|
|
|
|
}
|
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
static struct msgb *_hnbap_gen_msg(HNBAP_HNBAP_PDU_t *pdu)
|
2015-12-16 19:27:14 +00:00
|
|
|
{
|
2015-12-16 22:06:59 +00:00
|
|
|
struct msgb *msg = hnbap_msgb_alloc();
|
2015-12-16 19:27:14 +00:00
|
|
|
asn_enc_rval_t rval;
|
|
|
|
|
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
rval = aper_encode_to_buffer(&asn_DEF_HNBAP_HNBAP_PDU, pdu,
|
2015-12-16 19:27:14 +00:00
|
|
|
msg->data, msgb_tailroom(msg));
|
|
|
|
if (rval.encoded < 0) {
|
2015-12-23 14:36:31 +00:00
|
|
|
LOGP(DHNBAP, 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-12-07 16:19:40 +00:00
|
|
|
struct msgb *hnbap_generate_initiating_message(
|
2021-10-22 23:29:46 +00:00
|
|
|
e_HNBAP_ProcedureCode procedureCode,
|
|
|
|
HNBAP_Criticality_t criticality,
|
2015-08-30 20:47:18 +00:00
|
|
|
asn_TYPE_descriptor_t * td, void *sptr)
|
|
|
|
{
|
2015-12-17 16:56:56 +00:00
|
|
|
struct msgb *msg;
|
2021-10-22 23:29:46 +00:00
|
|
|
HNBAP_HNBAP_PDU_t pdu;
|
2015-12-07 16:19:40 +00:00
|
|
|
int rc;
|
2015-08-30 20:47:18 +00:00
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
memset(&pdu, 0, sizeof(HNBAP_HNBAP_PDU_t));
|
2015-08-30 20:47:18 +00:00
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
pdu.present = HNBAP_HNBAP_PDU_PR_initiatingMessage;
|
2015-08-30 20:47:18 +00:00
|
|
|
pdu.choice.initiatingMessage.procedureCode = procedureCode;
|
|
|
|
pdu.choice.initiatingMessage.criticality = criticality;
|
2015-12-07 16:19:40 +00:00
|
|
|
rc = ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr);
|
|
|
|
if (rc < 0) {
|
2015-12-23 14:36:31 +00:00
|
|
|
LOGP(DHNBAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
|
2015-12-07 16:19:40 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-30 20:47:18 +00:00
|
|
|
|
2015-12-17 16:56:56 +00:00
|
|
|
msg = _hnbap_gen_msg(&pdu);
|
2021-10-22 23:29:46 +00:00
|
|
|
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_HNBAP_PDU, &pdu);
|
2015-12-17 16:56:56 +00:00
|
|
|
|
|
|
|
return msg;
|
2015-08-30 20:47:18 +00:00
|
|
|
}
|
|
|
|
|
2015-08-30 21:08:32 +00:00
|
|
|
struct msgb *hnbap_generate_successful_outcome(
|
2021-10-22 23:29:46 +00:00
|
|
|
e_HNBAP_ProcedureCode procedureCode,
|
|
|
|
HNBAP_Criticality_t criticality,
|
2015-08-30 20:47:18 +00:00
|
|
|
asn_TYPE_descriptor_t * td,
|
|
|
|
void *sptr)
|
|
|
|
{
|
2015-12-17 16:56:56 +00:00
|
|
|
struct msgb *msg;
|
2021-10-22 23:29:46 +00:00
|
|
|
HNBAP_HNBAP_PDU_t pdu;
|
2015-09-07 20:40:41 +00:00
|
|
|
int rc;
|
2015-08-30 20:47:18 +00:00
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
memset(&pdu, 0, sizeof(HNBAP_HNBAP_PDU_t));
|
2015-12-16 19:27:14 +00:00
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
pdu.present = HNBAP_HNBAP_PDU_PR_successfulOutcome;
|
2015-08-30 20:47:18 +00:00
|
|
|
pdu.choice.successfulOutcome.procedureCode = procedureCode;
|
|
|
|
pdu.choice.successfulOutcome.criticality = criticality;
|
2015-09-07 20:40:41 +00:00
|
|
|
rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr);
|
|
|
|
if (rc < 0) {
|
2015-12-23 14:36:31 +00:00
|
|
|
LOGP(DHNBAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
|
2015-08-30 20:47:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:56:56 +00:00
|
|
|
msg = _hnbap_gen_msg(&pdu);
|
2021-10-22 23:29:46 +00:00
|
|
|
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_HNBAP_PDU, &pdu);
|
2015-12-17 16:56:56 +00:00
|
|
|
|
|
|
|
return msg;
|
2015-08-30 20:47:18 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 19:17:26 +00:00
|
|
|
struct msgb *hnbap_generate_unsuccessful_outcome(
|
2021-10-22 23:29:46 +00:00
|
|
|
e_HNBAP_ProcedureCode procedureCode,
|
|
|
|
HNBAP_Criticality_t criticality,
|
2015-12-16 19:17:26 +00:00
|
|
|
asn_TYPE_descriptor_t * td,
|
|
|
|
void *sptr)
|
2015-08-30 20:47:18 +00:00
|
|
|
{
|
2015-12-17 16:56:56 +00:00
|
|
|
struct msgb *msg;
|
2021-10-22 23:29:46 +00:00
|
|
|
HNBAP_HNBAP_PDU_t pdu;
|
2015-12-16 19:17:26 +00:00
|
|
|
int rc;
|
2015-08-30 20:47:18 +00:00
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
memset(&pdu, 0, sizeof(HNBAP_HNBAP_PDU_t));
|
2015-12-16 19:27:14 +00:00
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
pdu.present = HNBAP_HNBAP_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) {
|
2015-12-23 14:36:31 +00:00
|
|
|
LOGP(DHNBAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
|
2015-12-16 19:17:26 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-30 20:47:18 +00:00
|
|
|
|
2015-12-17 16:56:56 +00:00
|
|
|
msg = _hnbap_gen_msg(&pdu);
|
2021-10-22 23:29:46 +00:00
|
|
|
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_HNBAP_PDU, &pdu);
|
2015-12-17 16:56:56 +00:00
|
|
|
|
|
|
|
return msg;
|
2015-08-30 20:47:18 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
HNBAP_IE_t *hnbap_new_ie(HNBAP_ProtocolIE_ID_t id,
|
|
|
|
HNBAP_Criticality_t criticality,
|
2015-08-30 20:47:18 +00:00
|
|
|
asn_TYPE_descriptor_t * type, void *sptr)
|
|
|
|
{
|
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
HNBAP_IE_t *buff;
|
2015-12-18 14:17:21 +00:00
|
|
|
int rc;
|
2015-08-30 20:47:18 +00:00
|
|
|
|
2021-10-22 23:29:46 +00:00
|
|
|
if ((buff = CALLOC(1, sizeof(HNBAP_IE_t))) == NULL) {
|
2015-08-30 20:47:18 +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) {
|
2015-12-23 14:36:31 +00:00
|
|
|
LOGP(DHNBAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
|
2015-12-18 14:17:21 +00:00
|
|
|
FREEMEM(buff);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-30 20:47:18 +00:00
|
|
|
|
|
|
|
if (asn1_xer_print)
|
2021-10-22 23:29:46 +00:00
|
|
|
if (xer_fprint(stdout, &asn_DEF_HNBAP_IE, buff) < 0) {
|
2015-12-18 13:57:04 +00:00
|
|
|
FREEMEM(buff);
|
2015-08-30 20:47:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
2022-01-04 16:23:47 +00:00
|
|
|
|
|
|
|
void hnbap_set_log_area(int log_area)
|
|
|
|
{
|
|
|
|
_hnbap_DHNBAP = log_area;
|
|
|
|
}
|