Change in osmo-hnodeb[master]: Use osmocom logging in non-main files

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.org
Tue Nov 2 12:00:40 UTC 2021


pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-hnodeb/+/26017 )

Change subject: Use osmocom logging in non-main files
......................................................................

Use osmocom logging in non-main files

Change-Id: I649b17803aeffd20354aa76dde61094959f08e43
---
M include/osmocom/hnodeb/hnodeb.h
M src/osmo-hnodeb/debug.c
M src/osmo-hnodeb/hnb.c
M src/osmo-hnodeb/hnbap.c
M src/osmo-hnodeb/nas.c
M src/osmo-hnodeb/ranap.c
M src/osmo-hnodeb/rua.c
7 files changed, 64 insertions(+), 58 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, approved
  laforge: Looks good to me, but someone else must approve
  fixeria: Looks good to me, but someone else must approve



diff --git a/include/osmocom/hnodeb/hnodeb.h b/include/osmocom/hnodeb/hnodeb.h
index fb0c0fb..9da6044 100644
--- a/include/osmocom/hnodeb/hnodeb.h
+++ b/include/osmocom/hnodeb/hnodeb.h
@@ -31,6 +31,7 @@
 	DHNBAP,
 	DRUA,
 	DRANAP,
+	DNAS,
 };
 extern const struct log_info hnb_log_info;
 
diff --git a/src/osmo-hnodeb/debug.c b/src/osmo-hnodeb/debug.c
index 69c369e..f50d8b0 100644
--- a/src/osmo-hnodeb/debug.c
+++ b/src/osmo-hnodeb/debug.c
@@ -23,25 +23,30 @@
 
 static const struct log_info_cat log_cat[] = {
 	[DMAIN] = {
-		.name = "DMAIN", .loglevel = LOGL_INFO, .enabled = 1,
+		.name = "DMAIN", .loglevel = LOGL_NOTICE, .enabled = 1,
 		.color = "",
 		.description = "Main program",
 	},
 	[DHNBAP] = {
-		.name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1,
-		.color = "",
+		.name = "DHNBAP", .loglevel = LOGL_NOTICE, .enabled = 1,
+		.color = "\033[1;33m",
 		.description = "Home Node B Application Part",
 	},
 	[DRANAP] = {
-		.name = "RANAP", .loglevel = LOGL_DEBUG, .enabled = 1,
-		.color = "",
+		.name = "RANAP", .loglevel = LOGL_NOTICE, .enabled = 1,
+		.color = "\033[1;34m",
 		.description = "RAN Application Part",
 	},
 	[DRUA] = {
-		.name = "RUA", .loglevel = LOGL_DEBUG, .enabled = 1,
-		.color = "",
+		.name = "RUA", .loglevel = LOGL_NOTICE, .enabled = 1,
+		.color = "\033[1;35m",
 		.description = "RANAP User Adaptation",
 	},
+	[DNAS] = {
+		.name = "NAS", .loglevel = LOGL_NOTICE, .enabled = 1,
+		.color = "\033[1;32m",
+		.description = "Non-Access Stratum",
+	},
 };
 
 const struct log_info hnb_log_info = {
diff --git a/src/osmo-hnodeb/hnb.c b/src/osmo-hnodeb/hnb.c
index 145c021..9a86019 100644
--- a/src/osmo-hnodeb/hnb.c
+++ b/src/osmo-hnodeb/hnb.c
@@ -89,11 +89,11 @@
 
 	switch (sinfo.sinfo_ppid) {
 	case IUH_PPI_HNBAP:
-		printf("HNBAP message received\n");
+		LOGP(DHNBAP, LOGL_INFO, "HNBAP message received\n");
 		rc = hnb_hnbap_rx(hnb, msg);
 		break;
 	case IUH_PPI_RUA:
-		printf("RUA message received\n");
+		LOGP(DRUA, LOGL_INFO, "RUA message received\n");
 		rc = hnb_rua_rx(hnb, msg);
 		break;
 	case IUH_PPI_SABP:
@@ -123,7 +123,7 @@
 	};
 	int rc;
 
-	printf("Sending: %s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg)));
+	LOGP(DMAIN, LOGL_DEBUG, "Sending: %s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg)));
 	rc = sctp_send(fd->fd, msgb_data(msg), msgb_length(msg),
 			&sinfo, 0);
 	/* we don't need to msgb_free(), write_queue does this for us */
diff --git a/src/osmo-hnodeb/hnbap.c b/src/osmo-hnodeb/hnbap.c
index 7cd9cd6..eaa51a4 100644
--- a/src/osmo-hnodeb/hnbap.c
+++ b/src/osmo-hnodeb/hnbap.c
@@ -43,7 +43,7 @@
 	}
 
 	hnb->rnc_id = accept.rnc_id;
-	printf("HNB Register accept with RNC ID %u\n", hnb->rnc_id);
+	LOGP(DHNBAP, LOGL_INFO, "HNB Register accept with RNC ID %u\n", hnb->rnc_id);
 
 	hnbap_free_hnbregisteraccepties(&accept);
 	return 0;
@@ -62,7 +62,7 @@
 	}
 
 	if (accept.uE_Identity.present != HNBAP_UE_Identity_PR_iMSI) {
-		printf("Wrong type in UE register accept\n");
+		LOGP(DHNBAP, LOGL_ERROR, "Wrong type in UE register accept\n");
 		return -1;
 	}
 
@@ -70,7 +70,7 @@
 
 	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);
+	LOGP(DHNBAP, LOGL_INFO, "UE Register accept for IMSI %s, context %u\n", imsi, ctx_id);
 
 	hnb->ctx_id = ctx_id;
 	hnbap_free_ueregisteraccepties(&accept);
@@ -93,7 +93,7 @@
 	}
 
 	if (pdu->present != HNBAP_HNBAP_PDU_PR_successfulOutcome) {
-		printf("Unexpected HNBAP message received\n");
+		LOGP(DHNBAP, LOGL_ERROR, "Unexpected HNBAP message received\n");
 	}
 
 	switch (pdu->choice.successfulOutcome.procedureCode) {
@@ -183,7 +183,7 @@
 	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");
+		LOGP(DHNBAP, LOGL_ERROR, "Could not encode HNB register request IEs\n");
 	}
 
 	msg = hnbap_generate_initiating_message(HNBAP_ProcedureCode_id_HNBRegister,
@@ -212,7 +212,7 @@
 	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");
+		LOGP(DHNBAP, LOGL_ERROR, "Could not encode HNB deregister request IEs\n");
 	}
 
 	msg = hnbap_generate_initiating_message(HNBAP_ProcedureCode_id_HNBDe_Register,
diff --git a/src/osmo-hnodeb/nas.c b/src/osmo-hnodeb/nas.c
index 163f458..293c46e 100644
--- a/src/osmo-hnodeb/nas.c
+++ b/src/osmo-hnodeb/nas.c
@@ -87,7 +87,7 @@
 	parse_res = tlv_parse(&tp, &gsm48_mm_att_tlvdef, &gh->data[0], len, 0, 0);
 	if (parse_res <= 0) {
 		uint8_t msg_type = gsm48_hdr_msg_type(gh);
-		printf("Error parsing MM message 0x%hhx: %d\n", msg_type, parse_res);
+		LOGP(DNAS, LOGL_ERROR, "Error parsing MM message 0x%hhx: %d\n", msg_type, parse_res);
 		return NULL;
 	}
 
@@ -96,14 +96,14 @@
 
 int hnb_nas_rx_lu_accept(struct gsm48_hdr *gh, int len, int *sent_tmsi)
 {
-	printf(" :D Location Update Accept :D\n");
+	LOGP(DNAS, LOGL_INFO, " :D Location Update Accept :D\n");
 	struct gsm48_loc_area_id *lai;
 
 	lai = (struct gsm48_loc_area_id *)&gh->data[0];
 
 	struct osmo_location_area_id laid;
 	gsm48_decode_lai2(lai, &laid);
-	printf("LU: mcc %s  mnc %s  lac %hd\n",
+	LOGP(DNAS, LOGL_INFO, "LU: mcc %s  mnc %s  lac %hd\n",
 	       osmo_mcc_name(laid.plmn.mcc), osmo_mnc_name(laid.plmn.mnc, laid.plmn.mnc_3_digits),
 	       laid.lac);
 
@@ -113,7 +113,7 @@
 	len -= (const char *)&gh->data[0] - (const char *)gh;
 	parse_res = tlv_parse(&tp, &gsm48_mm_att_tlvdef, &gh->data[0], len, 0, 0);
 	if (parse_res <= 0) {
-		printf("Error parsing Location Update Accept message: %d\n", parse_res);
+		LOGP(DNAS, LOGL_ERROR, "Error parsing Location Update Accept message: %d\n", parse_res);
 		return -1;
 	}
 
@@ -128,7 +128,7 @@
 
 void hnb_nas_rx_mm_info(struct gsm48_hdr *gh, int len)
 {
-	printf(" :) MM Info :)\n");
+	LOGP(DNAS, LOGL_INFO, " :) MM Info :)\n");
 	struct tlv_parsed *tp = parse_mm(gh, len);
 	if (!tp)
 		return;
@@ -138,7 +138,7 @@
 		gsm_7bit_decode_n(name, 127,
 				  TLVP_VAL(tp, GSM48_IE_NAME_SHORT)+1,
 				  (TLVP_LEN(tp, GSM48_IE_NAME_SHORT)-1)*8/7);
-		printf("Info: Short Network Name: %s\n", name);
+		LOGP(DNAS, LOGL_INFO, "Info: Short Network Name: %s\n", name);
 	}
 
 	if (TLVP_PRESENT(tp, GSM48_IE_NAME_LONG)) {
@@ -146,7 +146,7 @@
 		gsm_7bit_decode_n(name, 127,
 				  TLVP_VAL(tp, GSM48_IE_NAME_LONG)+1,
 				  (TLVP_LEN(tp, GSM48_IE_NAME_LONG)-1)*8/7);
-		printf("Info: Long Network Name: %s\n", name);
+		LOGP(DNAS, LOGL_INFO, "Info: Long Network Name: %s\n", name);
 	}
 }
 
@@ -158,11 +158,11 @@
 	len -= (const char *)&gh->data[0] - (const char *)gh;
 
 	if (len < sizeof(*ar)) {
-		printf("GSM48 Auth Req does not fit.\n");
+		LOGP(DNAS, LOGL_ERROR, "GSM48 Auth Req does not fit.\n");
 		return -1;
 	}
 
-	printf(" :) Authentication Request :)\n");
+	LOGP(DNAS, LOGL_INFO, " :) Authentication Request :)\n");
 
 	ar = (struct gsm48_auth_req*) &gh->data[0];
 	int seq = ar->key_seq;
@@ -183,9 +183,9 @@
 	memset(&vec, 0, sizeof(vec));
 	osmo_auth_gen_vec(&vec, &auth, ar->rand);
 
-	printf("seq %d rand %s",
+	LOGP(DNAS, LOGL_DEBUG, "seq %d rand %s",
 	       seq, osmo_hexdump(ar->rand, sizeof(ar->rand)));
-	printf(" --> sres %s\n",
+	LOGP(DNAS, LOGL_DEBUG, " --> sres %s\n",
 	       osmo_hexdump(vec.sres, 4));
 
 	return hnb_tx_dt(hnb, gen_nas_auth_resp(vec.sres));
@@ -197,7 +197,7 @@
 
 	chan = hnb->cs.chan;
 	if (!chan) {
-		printf("hnb_nas_rx_mm(): No CS channel established yet.\n");
+		LOGP(DNAS, LOGL_ERROR, "hnb_nas_rx_mm(): No CS channel established yet.\n");
 		return -1;
 	}
 
@@ -219,7 +219,7 @@
 			return 0;
 
 	case GSM48_MT_MM_LOC_UPD_REJECT:
-		printf("Received Location Update Reject\n");
+		LOGP(DNAS, LOGL_INFO, "Received Location Update Reject\n");
 		return 0;
 
 	case GSM48_MT_MM_INFO:
@@ -231,7 +231,7 @@
 		return hnb_nas_rx_auth_req(hnb, gh, len);
 
 	default:
-		printf("04.08 message type not handled by hnb-test: 0x%x\n",
+		LOGP(DNAS, LOGL_INFO, "04.08 message type not handled by hnb-test: 0x%x\n",
 		       msg_type);
 		return 0;
 	}
@@ -241,14 +241,14 @@
 void hnb_nas_rx_dtap(struct hnb *hnb, void *data, int len)
 {
 	int rc;
-	printf("got %d bytes: %s\n", len, osmo_hexdump(data, len));
+	LOGP(DNAS, LOGL_INFO, "got %d bytes: %s\n", len, osmo_hexdump(data, len));
 
 	// nas_pdu == '05 08 12' ==> IMEI Identity request
 	//            '05 04 0d' ==> LU reject
 
 	struct gsm48_hdr *gh = data;
 	if (len < sizeof(*gh)) {
-		printf("hnb_nas_rx_dtap(): NAS PDU is too short: %d. Ignoring.\n",
+		LOGP(DNAS, LOGL_ERROR, "hnb_nas_rx_dtap(): NAS PDU is too short: %d. Ignoring.\n",
 		       len);
 		return;
 	}
@@ -258,10 +258,10 @@
 	case GSM48_PDISC_MM:
 		rc = hnb_nas_rx_mm(hnb, gh, len);
 		if (rc != 0)
-			printf("Error receiving MM message: %d\n", rc);
+			LOGP(DNAS, LOGL_ERROR, "Error receiving MM message: %d\n", rc);
 		return;
 	default:
-		printf("04.08 discriminator not handled by hnb-test: %d\n",
+		LOGP(DNAS, LOGL_NOTICE, "04.08 discriminator not handled by hnb-test: %d\n",
 		       pdisc);
 		return;
 	}
diff --git a/src/osmo-hnodeb/ranap.c b/src/osmo-hnodeb/ranap.c
index 8f1b9c0..fae87b7 100644
--- a/src/osmo-hnodeb/ranap.c
+++ b/src/osmo-hnodeb/ranap.c
@@ -35,7 +35,7 @@
 }
 
 #define PP(octet_string_t) \
-	printf(#octet_string_t " = %s\n",\
+	LOGP(DRANAP, LOGL_INFO, #octet_string_t " = %s\n",\
 	       printstr(&octet_string_t))
 
 void hnb_rua_dt_handle_ranap(struct hnb *hnb,
@@ -46,12 +46,12 @@
 	RANAP_PermittedIntegrityProtectionAlgorithms_t *algs;
 	RANAP_IntegrityProtectionAlgorithm_t *first_alg;
 
-	printf("rx ranap_msg->procedureCode %d\n",
+	LOGP(DRANAP, LOGL_INFO, "rx ranap_msg->procedureCode %d\n",
 	       ranap_msg->procedureCode);
 
 	switch (ranap_msg->procedureCode) {
 	case RANAP_ProcedureCode_id_DirectTransfer:
-		printf("rx DirectTransfer: presence = %hx\n",
+		LOGP(DRANAP, LOGL_INFO, "rx DirectTransfer: presence = %hx\n",
 		       ranap_msg->msg.directTransferIEs.presenceMask);
 		PP(ranap_msg->msg.directTransferIEs.nas_pdu);
 
@@ -62,14 +62,14 @@
 		return;
 
 	case RANAP_ProcedureCode_id_SecurityModeControl:
-		printf("rx SecurityModeControl: presence = %hx\n",
+		LOGP(DRANAP, LOGL_INFO, "rx SecurityModeControl: presence = %hx\n",
 		       ranap_msg->msg.securityModeCommandIEs.presenceMask);
 
 		/* Just pick the first available IP alg, don't care about
 		 * encryption (yet?) */
 		algs = &ranap_msg->msg.securityModeCommandIEs.integrityProtectionInformation.permittedAlgorithms;
 		if (algs->list.count < 1) {
-			printf("Security Mode Command: No permitted algorithms.\n");
+			LOGP(DRANAP, LOGL_INFO, "Security Mode Command: No permitted algorithms.\n");
 			return;
 		}
 		first_alg = *algs->list.array;
@@ -88,7 +88,7 @@
 {
 	char imsi[16];
 
-	printf("rx ranap_msg->procedureCode %d\n",
+	LOGP(DRANAP, LOGL_INFO, "rx ranap_msg->procedureCode %d\n",
 	       ranap_msg->procedureCode);
 
 	switch (ranap_msg->procedureCode) {
@@ -99,7 +99,7 @@
 					 ranap_msg->msg.pagingIEs.permanentNAS_UE_ID.choice.iMSI.size);
 		} else imsi[0] = '\0';
 
-		printf("rx Paging: presence=%hx  domain=%ld  IMSI=%s\n",
+		LOGP(DRANAP, LOGL_INFO, "rx Paging: presence=%hx  domain=%ld  IMSI=%s\n",
 		       ranap_msg->msg.pagingIEs.presenceMask,
 		       ranap_msg->msg.pagingIEs.cN_DomainIndicator,
 		       imsi
@@ -158,7 +158,7 @@
 
 void hnb_rx_secmode_cmd(struct hnb *hnb, long ip_alg)
 {
-	printf(" :) Security Mode Command :)\n");
+	LOGP(DRANAP, LOGL_INFO, " :) Security Mode Command :)\n");
 	/* not caring about encryption yet, just pass 0 for No Encryption. */
 	hnb_tx_dt(hnb, ranap_new_msg_sec_mod_compl(ip_alg, 0));
 }
@@ -170,6 +170,6 @@
 
 void hnb_rx_paging(struct hnb *hnb, const char *imsi)
 {
-	printf(" :) Paging Request for %s :)\n", imsi);
+	LOGP(DRANAP, LOGL_INFO, " :) Paging Request for %s :)\n", imsi);
 	/* TODO reply */
 }
diff --git a/src/osmo-hnodeb/rua.c b/src/osmo-hnodeb/rua.c
index d7352b6..0dd8c3a 100644
--- a/src/osmo-hnodeb/rua.c
+++ b/src/osmo-hnodeb/rua.c
@@ -36,7 +36,7 @@
 
 	chan = hnb->cs.chan;
 	if (!chan) {
-		printf("hnb_nas_tx_tmsi_realloc_compl(): No CS channel established yet.\n");
+		LOGP(DRUA, LOGL_INFO, "hnb_nas_tx_tmsi_realloc_compl(): No CS channel established yet.\n");
 		return -1;
 	}
 
@@ -52,7 +52,7 @@
 
 	rc = rua_decode_directtransferies(&ies, in);
 	if (rc < 0) {
-		printf("failed to decode RUA DT IEs\n");
+		LOGP(DRUA, LOGL_INFO, "failed to decode RUA DT IEs\n");
 		return;
 	}
 
@@ -69,7 +69,7 @@
 
 	rc = rua_decode_connectionlesstransferies(&ies, in);
 	if (rc < 0) {
-		printf("failed to decode RUA CL IEs\n");
+		LOGP(DRUA, LOGL_INFO, "failed to decode RUA CL IEs\n");
 		return;
 	}
 
@@ -94,45 +94,45 @@
 
 	switch (pdu->present) {
 	case RUA_RUA_PDU_PR_successfulOutcome:
-		printf("RUA_RUA_PDU_PR_successfulOutcome\n");
+		LOGP(DRUA, LOGL_INFO, "RUA_RUA_PDU_PR_successfulOutcome\n");
 		break;
 	case RUA_RUA_PDU_PR_initiatingMessage:
-		printf("RUA_RUA_PDU_PR_initiatingMessage\n");
+		LOGP(DRUA, LOGL_INFO, "RUA_RUA_PDU_PR_initiatingMessage\n");
 		break;
 	case RUA_RUA_PDU_PR_NOTHING:
-		printf("RUA_RUA_PDU_PR_NOTHING\n");
+		LOGP(DRUA, LOGL_INFO, "RUA_RUA_PDU_PR_NOTHING\n");
 		break;
 	case RUA_RUA_PDU_PR_unsuccessfulOutcome:
-		printf("RUA_RUA_PDU_PR_unsuccessfulOutcome\n");
+		LOGP(DRUA, LOGL_INFO, "RUA_RUA_PDU_PR_unsuccessfulOutcome\n");
 		break;
 	default:
-		printf("Unexpected RUA message received\n");
+		LOGP(DRUA, LOGL_INFO, "Unexpected RUA message received\n");
 		break;
 	}
 
 	switch (pdu->choice.successfulOutcome.procedureCode) {
 	case RUA_ProcedureCode_id_ConnectionlessTransfer:
-		printf("RUA rx Connectionless Transfer\n");
+		LOGP(DRUA, LOGL_INFO, "RUA rx Connectionless Transfer\n");
 		hnb_rua_cl_handle(hnb, &pdu->choice.successfulOutcome.value);
 		break;
 	case RUA_ProcedureCode_id_Connect:
-		printf("RUA rx Connect\n");
+		LOGP(DRUA, LOGL_INFO, "RUA rx Connect\n");
 		break;
 	case RUA_ProcedureCode_id_DirectTransfer:
-		printf("RUA rx DirectTransfer\n");
+		LOGP(DRUA, LOGL_INFO, "RUA rx DirectTransfer\n");
 		hnb_rua_dt_handle(hnb, &pdu->choice.successfulOutcome.value);
 		break;
 	case RUA_ProcedureCode_id_Disconnect:
-		printf("RUA rx Disconnect\n");
+		LOGP(DRUA, LOGL_INFO, "RUA rx Disconnect\n");
 		break;
 	case RUA_ProcedureCode_id_ErrorIndication:
-		printf("RUA rx ErrorIndication\n");
+		LOGP(DRUA, LOGL_INFO, "RUA rx ErrorIndication\n");
 		break;
 	case RUA_ProcedureCode_id_privateMessage:
-		printf("RUA rx privateMessage\n");
+		LOGP(DRUA, LOGL_INFO, "RUA rx privateMessage\n");
 		break;
 	default:
-		printf("RUA rx unknown message\n");
+		LOGP(DRUA, LOGL_INFO, "RUA rx unknown message\n");
 		break;
 	}
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-hnodeb/+/26017
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnodeb
Gerrit-Branch: master
Gerrit-Change-Id: I649b17803aeffd20354aa76dde61094959f08e43
Gerrit-Change-Number: 26017
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211102/8d61860f/attachment.htm>


More information about the gerrit-log mailing list