This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
pespin gerrit-no-reply at lists.osmocom.orgpespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnodeb/+/26000 )
Change subject: Move hnbap related code to hnbap.c/h
......................................................................
Move hnbap related code to hnbap.c/h
Change-Id: I8356421169bebe1d411b05b19241ea639dc3f733
---
M include/osmocom/hnodeb/Makefile.am
A include/osmocom/hnodeb/hnbap.h
M include/osmocom/hnodeb/hnodeb.h
M src/osmo-hnodeb/Makefile.am
A src/osmo-hnodeb/hnbap.c
M src/osmo-hnodeb/main.c
M src/osmo-hnodeb/vty.c
7 files changed, 261 insertions(+), 197 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-hnodeb refs/changes/00/26000/1
diff --git a/include/osmocom/hnodeb/Makefile.am b/include/osmocom/hnodeb/Makefile.am
index 339f8a3..f6c91b4 100644
--- a/include/osmocom/hnodeb/Makefile.am
+++ b/include/osmocom/hnodeb/Makefile.am
@@ -1,4 +1,5 @@
noinst_HEADERS = \
+ hnbap.h \
hnodeb.h \
ranap.h \
rua.h \
diff --git a/include/osmocom/hnodeb/hnbap.h b/include/osmocom/hnodeb/hnbap.h
new file mode 100644
index 0000000..22f6d25
--- /dev/null
+++ b/include/osmocom/hnodeb/hnbap.h
@@ -0,0 +1,31 @@
+/* (C) 2015 by Daniel Willmann <dwillmann at sysmocom.de>
+ * (C) 2021 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
+ * Author: Pau Espin Pedrol <pespin at sysmocom.de>
+ * 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/lienses/>.
+ *
+ */
+#pragma once
+
+#include <asn1c/ANY.h>
+
+struct hnb;
+struct msg;
+
+int hnb_hnbap_rx(struct hnb *hnb, struct msgb *msg);
+
+int hnb_ue_register_tx(struct hnb *hnb, const char *imsi_str);
+void hnb_send_register_req(struct hnb *hnb);
+void hnb_send_deregister_req(struct hnb *hnb);
diff --git a/include/osmocom/hnodeb/hnodeb.h b/include/osmocom/hnodeb/hnodeb.h
index e36311e..b283145 100644
--- a/include/osmocom/hnodeb/hnodeb.h
+++ b/include/osmocom/hnodeb/hnodeb.h
@@ -103,9 +103,6 @@
void hnb_nas_rx_dtap(struct hnb *hnb, void *data, int len);
void hnb_rx_secmode_cmd(struct hnb *hnb, long ip_alg);
-int hnb_ue_register_tx(struct hnb *hnb, const char *imsi_str);
-void hnb_send_register_req(struct hnb *hnb);
-void hnb_send_deregister_req(struct hnb *hnb);
struct msgb *gen_initue_lu(int is_ps, uint32_t conn_id, const char *imsi);
extern void *tall_hnb_ctx;
diff --git a/src/osmo-hnodeb/Makefile.am b/src/osmo-hnodeb/Makefile.am
index 7526c28..d782a4a 100644
--- a/src/osmo-hnodeb/Makefile.am
+++ b/src/osmo-hnodeb/Makefile.am
@@ -31,6 +31,7 @@
osmo_hnodeb_SOURCES = \
main.c \
debug.c \
+ hnbap.c \
ranap.c \
rua.c \
vty.c \
diff --git a/src/osmo-hnodeb/hnbap.c b/src/osmo-hnodeb/hnbap.c
new file mode 100644
index 0000000..7e54004
--- /dev/null
+++ b/src/osmo-hnodeb/hnbap.c
@@ -0,0 +1,226 @@
+/* (C) 2015 by Daniel Willmann <dwillmann at sysmocom.de>
+ * (C) 2021 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
+ * Author: Pau Espin Pedrol <pespin at sysmocom.de>
+ * 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/lienses/>.
+ *
+ */
+
+#include <errno.h>
+
+#include <asn1c/ANY.h>
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/netif/stream.h>
+
+#include <osmocom/hnbap/hnbap_common.h>
+#include <osmocom/hnbap/hnbap_ies_defs.h>
+
+#include <osmocom/ranap/iu_helpers.h> /* ranap_bcd_decode() */
+
+#include <osmocom/hnodeb/hnbap.h>
+#include <osmocom/hnodeb/hnodeb.h>
+
+static int hnb_rx_hnb_register_acc(struct hnb *hnb, ANY_t *in)
+{
+ int rc;
+ HNBAP_HNBRegisterAcceptIEs_t accept;
+
+ rc = hnbap_decode_hnbregisteraccepties(&accept, in);
+ if (rc < 0) {
+ }
+
+ hnb->rnc_id = accept.rnc_id;
+ printf("HNB Register accept with RNC ID %u\n", hnb->rnc_id);
+
+ hnbap_free_hnbregisteraccepties(&accept);
+ return 0;
+}
+
+static int hnb_rx_ue_register_acc(struct hnb *hnb, ANY_t *in)
+{
+ int rc;
+ uint32_t ctx_id;
+ HNBAP_UERegisterAcceptIEs_t accept;
+ char imsi[16];
+
+ rc = hnbap_decode_ueregisteraccepties(&accept, in);
+ if (rc < 0) {
+ return rc;
+ }
+
+ if (accept.uE_Identity.present != HNBAP_UE_Identity_PR_iMSI) {
+ printf("Wrong type in UE register accept\n");
+ return -1;
+ }
+
+ ctx_id = asn1bitstr_to_u24(&accept.context_ID);
+
+ ranap_bcd_decode(imsi, sizeof(imsi), accept.uE_Identity.choice.iMSI.buf,
+ accept.uE_Identity.choice.iMSI.size);
+ printf("UE Register accept for IMSI %s, context %u\n", imsi, ctx_id);
+
+ hnb->ctx_id = ctx_id;
+ hnbap_free_ueregisteraccepties(&accept);
+
+ return 0;
+}
+
+int hnb_hnbap_rx(struct hnb *hnb, struct msgb *msg)
+{
+ HNBAP_HNBAP_PDU_t _pdu, *pdu = &_pdu;
+ asn_dec_rval_t dec_ret;
+ int rc;
+
+ memset(pdu, 0, sizeof(*pdu));
+ dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_HNBAP_PDU, (void **) &pdu,
+ msg->data, msgb_length(msg), 0, 0);
+ if (dec_ret.code != RC_OK) {
+ LOGP(DMAIN, LOGL_ERROR, "Error in ASN.1 decode\n");
+ return -EINVAL;
+ }
+
+ if (pdu->present != HNBAP_HNBAP_PDU_PR_successfulOutcome) {
+ printf("Unexpected HNBAP message received\n");
+ }
+
+ switch (pdu->choice.successfulOutcome.procedureCode) {
+ case HNBAP_ProcedureCode_id_HNBRegister:
+ /* Get HNB id and send UE Register request */
+ rc = hnb_rx_hnb_register_acc(hnb, &pdu->choice.successfulOutcome.value);
+ break;
+ case HNBAP_ProcedureCode_id_UERegister:
+ rc = hnb_rx_ue_register_acc(hnb, &pdu->choice.successfulOutcome.value);
+ break;
+ default:
+ rc = -ENOSPC;
+ break;
+ }
+
+ return rc;
+}
+
+int hnb_ue_register_tx(struct hnb *hnb, const char *imsi_str)
+{
+ struct msgb *msg;
+ int rc, imsi_len;
+
+ uint8_t imsi_buf[16];
+
+ HNBAP_UERegisterRequest_t request_out;
+ HNBAP_UERegisterRequestIEs_t request;
+ memset(&request, 0, sizeof(request));
+
+ request.uE_Identity.present = HNBAP_UE_Identity_PR_iMSI;
+
+ imsi_len = ranap_imsi_encode(imsi_buf, sizeof(imsi_buf), imsi_str);
+ OCTET_STRING_fromBuf(&request.uE_Identity.choice.iMSI, (const char*)imsi_buf, imsi_len);
+
+ request.registration_Cause = HNBAP_Registration_Cause_normal;
+ request.uE_Capabilities.access_stratum_release_indicator = HNBAP_Access_stratum_release_indicator_rel_6;
+ request.uE_Capabilities.csg_capability = HNBAP_CSG_Capability_not_csg_capable;
+
+ memset(&request_out, 0, sizeof(request_out));
+ rc = hnbap_encode_ueregisterrequesties(&request_out, &request);
+ OSMO_ASSERT(rc == 0);
+
+ msg = hnbap_generate_initiating_message(HNBAP_ProcedureCode_id_UERegister,
+ HNBAP_Criticality_reject,
+ &asn_DEF_HNBAP_UERegisterRequest,
+ &request_out);
+
+ ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_UERegisterRequest, &request_out);
+
+ msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
+
+ return osmo_wqueue_enqueue(&hnb->wqueue, msg);
+}
+
+void hnb_send_register_req(struct hnb *hnb)
+{
+ HNBAP_HNBRegisterRequest_t request_out;
+ struct msgb *msg;
+ int rc;
+ uint16_t lac, sac;
+ uint8_t rac;
+ uint32_t cid;
+ uint8_t plmn[] = {0x09, 0xf1, 0x99};
+ char identity[50] = "ATestHNB@";
+
+ HNBAP_HNBRegisterRequestIEs_t request;
+ memset(&request, 0, sizeof(request));
+
+ lac = 0xc0fe;
+ sac = 0xabab;
+ rac = 0x42;
+ cid = 0xadceaab;
+
+ asn1_u16_to_str(&request.lac, &lac, lac);
+ asn1_u16_to_str(&request.sac, &sac, sac);
+ asn1_u8_to_str(&request.rac, &rac, rac);
+ asn1_u28_to_bitstring(&request.cellIdentity, &cid, cid);
+
+ request.hnB_Identity.hNB_Identity_Info.buf = (uint8_t*) identity;
+ request.hnB_Identity.hNB_Identity_Info.size = strlen(identity);
+
+ request.plmNidentity.buf = plmn;
+ request.plmNidentity.size = 3;
+
+
+
+ memset(&request_out, 0, sizeof(request_out));
+ rc = hnbap_encode_hnbregisterrequesties(&request_out, &request);
+ if (rc < 0) {
+ printf("Could not encode HNB register request IEs\n");
+ }
+
+ msg = hnbap_generate_initiating_message(HNBAP_ProcedureCode_id_HNBRegister,
+ HNBAP_Criticality_reject,
+ &asn_DEF_HNBAP_HNBRegisterRequest,
+ &request_out);
+
+
+ msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
+
+ osmo_wqueue_enqueue(&hnb->wqueue, msg);
+}
+
+void hnb_send_deregister_req(struct hnb *hnb)
+{
+ struct msgb *msg;
+ int rc;
+
+ HNBAP_HNBDe_RegisterIEs_t request;
+ memset(&request, 0, sizeof(request));
+
+ request.cause.present = HNBAP_Cause_PR_misc;
+ request.cause.choice.misc = HNBAP_CauseMisc_o_and_m_intervention;
+
+ HNBAP_HNBDe_Register_t request_out;
+ memset(&request_out, 0, sizeof(request_out));
+ rc = hnbap_encode_hnbde_registeries(&request_out, &request);
+ if (rc < 0) {
+ printf("Could not encode HNB deregister request IEs\n");
+ }
+
+ msg = hnbap_generate_initiating_message(HNBAP_ProcedureCode_id_HNBDe_Register,
+ HNBAP_Criticality_reject,
+ &asn_DEF_HNBAP_HNBDe_Register,
+ &request_out);
+
+ msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
+
+ osmo_wqueue_enqueue(&hnb->wqueue, msg);
+}
diff --git a/src/osmo-hnodeb/main.c b/src/osmo-hnodeb/main.c
index 0fcb909..3abfc7c 100644
--- a/src/osmo-hnodeb/main.c
+++ b/src/osmo-hnodeb/main.c
@@ -51,8 +51,6 @@
#include <osmocom/crypt/auth.h>
-#include <osmocom/hnbap/hnbap_common.h>
-#include <osmocom/hnbap/hnbap_ies_defs.h>
#include <osmocom/rua/rua_msg_factory.h>
#include <osmocom/ranap/iu_helpers.h>
@@ -67,6 +65,7 @@
#include <osmocom/ranap/RANAP_DirectTransfer.h>
#include <osmocom/ranap/ranap_common.h>
+#include <osmocom/hnodeb/hnbap.h>
#include <osmocom/hnodeb/rua.h>
#include <osmocom/hnodeb/ranap.h>
#include <osmocom/hnodeb/vty.h>
@@ -81,87 +80,6 @@
struct msgb *rua_new_udt(struct msgb *inmsg);
-int hnb_ue_register_tx(struct hnb *hnb, const char *imsi_str)
-{
- struct msgb *msg;
- int rc, imsi_len;
-
- uint8_t imsi_buf[16];
-
- HNBAP_UERegisterRequest_t request_out;
- HNBAP_UERegisterRequestIEs_t request;
- memset(&request, 0, sizeof(request));
-
- request.uE_Identity.present = HNBAP_UE_Identity_PR_iMSI;
-
- imsi_len = ranap_imsi_encode(imsi_buf, sizeof(imsi_buf), imsi_str);
- OCTET_STRING_fromBuf(&request.uE_Identity.choice.iMSI, (const char*)imsi_buf, imsi_len);
-
- request.registration_Cause = HNBAP_Registration_Cause_normal;
- request.uE_Capabilities.access_stratum_release_indicator = HNBAP_Access_stratum_release_indicator_rel_6;
- request.uE_Capabilities.csg_capability = HNBAP_CSG_Capability_not_csg_capable;
-
- memset(&request_out, 0, sizeof(request_out));
- rc = hnbap_encode_ueregisterrequesties(&request_out, &request);
- OSMO_ASSERT(rc == 0);
-
- msg = hnbap_generate_initiating_message(HNBAP_ProcedureCode_id_UERegister,
- HNBAP_Criticality_reject,
- &asn_DEF_HNBAP_UERegisterRequest,
- &request_out);
-
- ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_UERegisterRequest, &request_out);
-
- msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
-
- return osmo_wqueue_enqueue(&hnb->wqueue, msg);
-}
-
-static int hnb_rx_hnb_register_acc(struct hnb *hnb, ANY_t *in)
-{
- int rc;
- HNBAP_HNBRegisterAcceptIEs_t accept;
-
- rc = hnbap_decode_hnbregisteraccepties(&accept, in);
- if (rc < 0) {
- }
-
- hnb->rnc_id = accept.rnc_id;
- printf("HNB Register accept with RNC ID %u\n", hnb->rnc_id);
-
- hnbap_free_hnbregisteraccepties(&accept);
- return 0;
-}
-
-static int hnb_rx_ue_register_acc(struct hnb *hnb, ANY_t *in)
-{
- int rc;
- uint32_t ctx_id;
- HNBAP_UERegisterAcceptIEs_t accept;
- char imsi[16];
-
- rc = hnbap_decode_ueregisteraccepties(&accept, in);
- if (rc < 0) {
- return rc;
- }
-
- if (accept.uE_Identity.present != HNBAP_UE_Identity_PR_iMSI) {
- printf("Wrong type in UE register accept\n");
- return -1;
- }
-
- ctx_id = asn1bitstr_to_u24(&accept.context_ID);
-
- ranap_bcd_decode(imsi, sizeof(imsi), accept.uE_Identity.choice.iMSI.buf,
- accept.uE_Identity.choice.iMSI.size);
- printf("UE Register accept for IMSI %s, context %u\n", imsi, ctx_id);
-
- hnb->ctx_id = ctx_id;
- hnbap_free_ueregisteraccepties(&accept);
-
- return 0;
-}
-
static struct msgb *gen_nas_id_resp()
{
uint8_t id_resp[] = {
@@ -440,40 +358,6 @@
/* TODO reply */
}
-int hnb_hnbap_rx(struct hnb *hnb, struct msgb *msg)
-{
- HNBAP_HNBAP_PDU_t _pdu, *pdu = &_pdu;
- asn_dec_rval_t dec_ret;
- int rc;
-
- memset(pdu, 0, sizeof(*pdu));
- dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_HNBAP_PDU, (void **) &pdu,
- msg->data, msgb_length(msg), 0, 0);
- if (dec_ret.code != RC_OK) {
- LOGP(DMAIN, LOGL_ERROR, "Error in ASN.1 decode\n");
- return -EINVAL;
- }
-
- if (pdu->present != HNBAP_HNBAP_PDU_PR_successfulOutcome) {
- printf("Unexpected HNBAP message received\n");
- }
-
- switch (pdu->choice.successfulOutcome.procedureCode) {
- case HNBAP_ProcedureCode_id_HNBRegister:
- /* Get HNB id and send UE Register request */
- rc = hnb_rx_hnb_register_acc(hnb, &pdu->choice.successfulOutcome.value);
- break;
- case HNBAP_ProcedureCode_id_UERegister:
- rc = hnb_rx_ue_register_acc(hnb, &pdu->choice.successfulOutcome.value);
- break;
- default:
- rc = -ENOSPC;
- break;
- }
-
- return rc;
-}
-
extern void direct_transfer_nas_pdu_print(ANY_t *in);
static int hnb_read_cb(struct osmo_fd *fd)
@@ -557,83 +441,6 @@
return rc;
}
-void hnb_send_register_req(struct hnb *hnb)
-{
- HNBAP_HNBRegisterRequest_t request_out;
- struct msgb *msg;
- int rc;
- uint16_t lac, sac;
- uint8_t rac;
- uint32_t cid;
- uint8_t plmn[] = {0x09, 0xf1, 0x99};
- char identity[50] = "ATestHNB@";
-
- HNBAP_HNBRegisterRequestIEs_t request;
- memset(&request, 0, sizeof(request));
-
- lac = 0xc0fe;
- sac = 0xabab;
- rac = 0x42;
- cid = 0xadceaab;
-
- asn1_u16_to_str(&request.lac, &lac, lac);
- asn1_u16_to_str(&request.sac, &sac, sac);
- asn1_u8_to_str(&request.rac, &rac, rac);
- asn1_u28_to_bitstring(&request.cellIdentity, &cid, cid);
-
- request.hnB_Identity.hNB_Identity_Info.buf = (uint8_t*) identity;
- request.hnB_Identity.hNB_Identity_Info.size = strlen(identity);
-
- request.plmNidentity.buf = plmn;
- request.plmNidentity.size = 3;
-
-
-
- memset(&request_out, 0, sizeof(request_out));
- rc = hnbap_encode_hnbregisterrequesties(&request_out, &request);
- if (rc < 0) {
- printf("Could not encode HNB register request IEs\n");
- }
-
- msg = hnbap_generate_initiating_message(HNBAP_ProcedureCode_id_HNBRegister,
- HNBAP_Criticality_reject,
- &asn_DEF_HNBAP_HNBRegisterRequest,
- &request_out);
-
-
- msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
-
- osmo_wqueue_enqueue(&hnb->wqueue, msg);
-}
-
-void hnb_send_deregister_req(struct hnb *hnb)
-{
- struct msgb *msg;
- int rc;
-
- HNBAP_HNBDe_RegisterIEs_t request;
- memset(&request, 0, sizeof(request));
-
- request.cause.present = HNBAP_Cause_PR_misc;
- request.cause.choice.misc = HNBAP_CauseMisc_o_and_m_intervention;
-
- HNBAP_HNBDe_Register_t request_out;
- memset(&request_out, 0, sizeof(request_out));
- rc = hnbap_encode_hnbde_registeries(&request_out, &request);
- if (rc < 0) {
- printf("Could not encode HNB deregister request IEs\n");
- }
-
- msg = hnbap_generate_initiating_message(HNBAP_ProcedureCode_id_HNBDe_Register,
- HNBAP_Criticality_reject,
- &asn_DEF_HNBAP_HNBDe_Register,
- &request_out);
-
- msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
-
- osmo_wqueue_enqueue(&hnb->wqueue, msg);
-}
-
static struct vty_app_info vty_info = {
.name = "OsmohNodeB",
.version = "0",
diff --git a/src/osmo-hnodeb/vty.c b/src/osmo-hnodeb/vty.c
index ccca6d0..a1bb885 100644
--- a/src/osmo-hnodeb/vty.c
+++ b/src/osmo-hnodeb/vty.c
@@ -32,6 +32,7 @@
#include <osmocom/ranap/ranap_common.h>
#include <osmocom/ranap/ranap_msg_factory.h>
+#include <osmocom/hnodeb/hnbap.h>
#include <osmocom/hnodeb/vty.h>
#include <osmocom/hnodeb/hnodeb.h>
--
To view, visit https://gerrit.osmocom.org/c/osmo-hnodeb/+/26000
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-hnodeb
Gerrit-Branch: master
Gerrit-Change-Id: I8356421169bebe1d411b05b19241ea639dc3f733
Gerrit-Change-Number: 26000
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211027/8be318f7/attachment.htm>