[PATCH 2/3] [mobile] replace 3 different gsm322_makesend_* functions with one

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/baseband-devel@lists.osmocom.org/.

Harald Welte laforge at gnumonks.org
Sun Jan 30 19:43:38 UTC 2011


The new function is gsm322_event_input() and uses the event type
as a function argument.
---
 .../layer23/include/osmocom/bb/mobile/gsm322.h     |   12 +++-
 src/host/layer23/src/mobile/app_mobile.c           |    8 ++--
 src/host/layer23/src/mobile/gsm322.c               |   56 +++++---------------
 src/host/layer23/src/mobile/gsm48_mm.c             |   34 +++++++-----
 src/host/layer23/src/mobile/gsm48_rr.c             |    9 ++--
 src/host/layer23/src/mobile/vty_interface.c        |    9 ++--
 6 files changed, 57 insertions(+), 71 deletions(-)

diff --git a/src/host/layer23/include/osmocom/bb/mobile/gsm322.h b/src/host/layer23/include/osmocom/bb/mobile/gsm322.h
index 3cd275f..30d96ee 100644
--- a/src/host/layer23/include/osmocom/bb/mobile/gsm322.h
+++ b/src/host/layer23/include/osmocom/bb/mobile/gsm322.h
@@ -32,6 +32,13 @@
 #define GSM322_PLMN_SEARCH		10
 #define GSM322_HPLMN_SEARCH		11
 
+/* GSM 03.22 event types */
+enum gsm322_evt_type {
+	GSM322_EVT_C,		/* direct cell event, no queue */
+	GSM322_EVT_CS,		/* enqueue cs->event_queue */
+	GSM322_EVT_PLMN,	/* enqueue plmn->event_queue */
+};
+
 /* GSM 03.22 events */
 #define	GSM322_EVENT_SWITCH_ON		1
 #define	GSM322_EVENT_SWITCH_OFF		2	
@@ -172,9 +179,8 @@ struct gsm322_msg {
 
 int gsm322_init(struct osmocom_ms *ms);
 int gsm322_exit(struct osmocom_ms *ms);
-int gsm322_makesend_plmn_msg(struct osmocom_ms *ms, int msg_type, uint8_t *data, unsigned int len);
-int gsm322_makesend_cs_event(struct osmocom_ms *ms, int msg_type, uint8_t *data, unsigned int len);
-int gsm322_makesend_c_event(struct osmocom_ms *ms, int msg_type, uint8_t *data, unsigned int len);
+int gsm322_event_input(struct osmocom_ms *ms, enum gsm322_evt_type type,
+		       int msg_type, uint8_t *data, unsigned int len);
 int gsm322_plmn_dequeue(struct osmocom_ms *ms);
 int gsm322_cs_dequeue(struct osmocom_ms *ms);
 int gsm322_add_forbidden_la(struct osmocom_ms *ms, uint16_t mcc,
diff --git a/src/host/layer23/src/mobile/app_mobile.c b/src/host/layer23/src/mobile/app_mobile.c
index 3d2100c..b3c3284 100644
--- a/src/host/layer23/src/mobile/app_mobile.c
+++ b/src/host/layer23/src/mobile/app_mobile.c
@@ -104,10 +104,10 @@ int mobile_signal_cb(unsigned int subsys, unsigned int signal,
 			break;
 		default:
 			/* no SIM, trigger PLMN selection process */
-			gsm322_makesend_plmn_msg(ms, GSM322_EVENT_SWITCH_ON,
-						 NULL, 0);
-			gsm322_makesend_cs_event(ms, GSM322_EVENT_SWITCH_ON,
-						 NULL, 0);
+			gsm322_event_input(ms, GSM322_EVT_PLMN,
+					   GSM322_EVENT_SWITCH_ON, NULL, 0);
+			gsm322_event_input(ms, GSM322_EVT_CS,
+					   GSM322_EVENT_SWITCH_ON, NULL, 0);
 		}
 
 		ms->started = 1;
diff --git a/src/host/layer23/src/mobile/gsm322.c b/src/host/layer23/src/mobile/gsm322.c
index 1429737..3243afc 100644
--- a/src/host/layer23/src/mobile/gsm322.c
+++ b/src/host/layer23/src/mobile/gsm322.c
@@ -3604,8 +3604,8 @@ int gsm322_exit(struct osmocom_ms *ms)
 	return 0;
 }
 
-int gsm322_makesend_c_event(struct osmocom_ms *ms, int msg_type,
-			    uint8_t *data, unsigned int len)
+int gsm322_event_input(struct osmocom_ms *ms, enum gsm322_evt_type type,
+		       int msg_type, uint8_t *data, unsigned int len)
 {
 	struct msgb *nmsg = gsm322_msgb_alloc(msg_type);
 	int rc;
@@ -3621,46 +3621,18 @@ int gsm322_makesend_c_event(struct osmocom_ms *ms, int msg_type,
 		}
 		memcpy(cur, data, len);
 	}
-	rc = gsm322_c_event(ms, nmsg);
-	msgb_free(nmsg);
-
-	return rc;
-}
-
-int gsm322_makesend_cs_event(struct osmocom_ms *ms, int msg_type,
-			     uint8_t *data, unsigned int len)
-{
-	struct msgb *nmsg = gsm322_msgb_alloc(msg_type);
-
-	if (!nmsg)
-		return -ENOMEM;
-
-	if (data && len) {
-		uint8_t *cur = msgb_push(nmsg, len);
-		if (!cur) {
-			msgb_free(nmsg);
-			return -EIO;
-		}
-		memcpy(cur, data, len);
+	switch (type) {
+	case GSM322_EVT_C:
+		rc = gsm322_c_event(ms, nmsg);
+		msgb_free(nmsg);
+		break;
+	case GSM322_EVT_CS:
+		rc = gsm322_cs_sendmsg(ms, nmsg);
+		break;
+	case GSM322_EVT_PLMN:
+		rc = gsm322_plmn_sendmsg(ms, nmsg);
+		break;
 	}
-	return  gsm322_cs_sendmsg(ms, nmsg);
-}
-
-int gsm322_makesend_plmn_msg(struct osmocom_ms *ms, int msg_type,
-			     uint8_t *data, unsigned int len)
-{
-	struct msgb *nmsg = gsm322_msgb_alloc(msg_type);
-
-	if (!nmsg)
-		return -ENOMEM;
 
-	if (data && len) {
-		uint8_t *cur = msgb_push(nmsg, len);
-		if (!cur) {
-			msgb_free(nmsg);
-			return -EIO;
-		}
-		memcpy(cur, data, len);
-	}
-	return gsm322_plmn_sendmsg(ms, nmsg);
+	return rc;
 }
diff --git a/src/host/layer23/src/mobile/gsm48_mm.c b/src/host/layer23/src/mobile/gsm48_mm.c
index 58253bd..4652f34 100644
--- a/src/host/layer23/src/mobile/gsm48_mm.c
+++ b/src/host/layer23/src/mobile/gsm48_mm.c
@@ -1123,8 +1123,8 @@ static int gsm48_mm_cell_selected(struct osmocom_ms *ms, struct msgb *msg)
 				GSM48_MM_SST_NORMAL_SERVICE);
 
 			/* send message to PLMN search process */
-			gsm322_makesend_plmn_msg(ms, GSM322_EVENT_REG_SUCCESS,
-						 NULL, 0);
+			gsm322_event_input(ms, GSM322_EVT_PLMN,
+					   GSM322_EVENT_REG_SUCCESS, NULL, 0);
 			return 0;
 		}
 		if (!s->att_allowed) {
@@ -1133,8 +1133,8 @@ static int gsm48_mm_cell_selected(struct osmocom_ms *ms, struct msgb *msg)
 				GSM48_MM_SST_NORMAL_SERVICE);
 
 			/* send message to PLMN search process */
-			gsm322_makesend_plmn_msg(ms, GSM322_EVENT_REG_SUCCESS,
-						 NULL, 0);
+			gsm322_event_input(ms, GSM322_EVT_PLMN,
+					   GSM322_EVENT_REG_SUCCESS, NULL, 0);
 			return 0;
 		}
 		/* else, continue */
@@ -1150,8 +1150,8 @@ static int gsm48_mm_cell_selected(struct osmocom_ms *ms, struct msgb *msg)
 			GSM48_MM_SST_LIMITED_SERVICE);
 
 		/* send message to PLMN search process */
-		gsm322_makesend_plmn_msg(ms, GSM322_EVENT_ROAMING_NA,
-					 NULL, 0);
+		gsm322_event_input(ms, GSM322_EVT_PLMN,
+				   GSM322_EVENT_ROAMING_NA, NULL, 0);
 
 		return 0;
 	}
@@ -1165,7 +1165,8 @@ static int gsm48_mm_cell_selected(struct osmocom_ms *ms, struct msgb *msg)
 			GSM48_MM_SST_LIMITED_SERVICE);
 
 		/* send message to PLMN search process */
-		gsm322_makesend_plmn_msg(ms, GSM322_EVENT_REG_FAILED, NULL, 0);
+		gsm322_event_input(ms, GSM322_EVT_PLMN,
+				   GSM322_EVENT_REG_FAILED, NULL, 0);
 
 		return 0;
 	}
@@ -1733,7 +1734,8 @@ static int gsm48_mm_imsi_detach_end(struct osmocom_ms *ms, struct msgb *msg)
 	}
 
 	/* send SIM remove event to gsm322 */
-	gsm322_makesend_plmn_msg(ms, GSM322_EVENT_SIM_REMOVE, NULL, 0);
+	gsm322_event_input(ms, GSM322_EVT_PLMN,
+			   GSM322_EVENT_SIM_REMOVE, NULL, 0);
 
 	/* CS process will trigger return to MM IDLE / No SIM */
 	return 0;
@@ -1993,7 +1995,7 @@ static int gsm48_mm_loc_upd(struct osmocom_ms *ms, struct msgb *msg)
 		_stop:
 		mm->lupd_pending = 0;
 		/* send message to PLMN search process */
-		gsm322_makesend_plmn_msg(ms, msg_type, NULL, 0);
+		gsm322_event_input(ms, GSM322_EVT_PLMN, msg_type, NULL, 0);
 		return 0;
 	}
 
@@ -2062,7 +2064,8 @@ static int gsm48_mm_loc_upd_normal(struct osmocom_ms *ms, struct msgb *msg)
 		LOGP(DMM, LOGL_INFO, "Loc. upd. not allowed.\n");
 
 		/* send message to PLMN search process */
-		gsm322_makesend_plmn_msg(ms, GSM322_EVENT_REG_FAILED, NULL, 0);
+		gsm322_event_input(ms, GSM322_EVT_PLMN,
+				   GSM322_EVENT_REG_FAILED, NULL, 0);
 
 		return 0;
 	}
@@ -2083,7 +2086,8 @@ static int gsm48_mm_loc_upd_normal(struct osmocom_ms *ms, struct msgb *msg)
 				GSM48_MM_SST_NORMAL_SERVICE);
 
 		/* send message to PLMN search process */
-		gsm322_makesend_plmn_msg(ms, GSM322_EVENT_REG_SUCCESS, NULL, 0);
+		gsm322_event_input(ms, GSM322_EVT_PLMN,
+				   GSM322_EVENT_REG_SUCCESS, NULL, 0);
 
 		return 0;
 	}
@@ -2318,7 +2322,8 @@ static int gsm48_mm_rx_loc_upd_acc(struct osmocom_ms *ms, struct msgb *msg)
 	}
 
 	/* send message to PLMN search process */
-	gsm322_makesend_plmn_msg(ms, GSM322_EVENT_REG_SUCCESS, NULL, 0);
+	gsm322_event_input(ms, GSM322_EVT_PLMN,
+			   GSM322_EVENT_REG_SUCCESS, NULL, 0);
 
 	/* follow on proceed */
 	if (TLVP_PRESENT(&tp, GSM48_IE_MOBILE_ID))
@@ -2426,7 +2431,7 @@ static int gsm48_mm_rel_loc_upd_rej(struct osmocom_ms *ms, struct msgb *msg)
 	}
 	memset(&ngm, 0, sizeof(ngm));
 	ngm.reject = mm->lupd_rej_cause;
-	gsm322_makesend_plmn_msg(ms, msg_type, NULL, 0);
+	gsm322_event_input(ms, GSM322_EVT_PLMN, msg_type, &ngm, sizeof(ngm));
 
 	/* forbidden list */
 	switch (mm->lupd_rej_cause) {
@@ -4068,7 +4073,8 @@ static int gsm48_mmr_reg_req(struct osmocom_ms *ms)
 	struct gsm48_mmlayer *mm = &ms->mmlayer;
 
 	/* schedule insertion of SIM */
-	gsm322_makesend_plmn_msg(ms, GSM322_EVENT_SIM_INSERT, NULL, 0);
+	gsm322_event_input(ms, GSM322_EVT_PLMN,
+			   GSM322_EVENT_SIM_INSERT, NULL, 0);
 
 	/* 4.2.1.2 SIM is inserted in state NO IMSI */
 	if (mm->state == GSM48_MM_ST_MM_IDLE
diff --git a/src/host/layer23/src/mobile/gsm48_rr.c b/src/host/layer23/src/mobile/gsm48_rr.c
index 4a48dc8..177b272 100644
--- a/src/host/layer23/src/mobile/gsm48_rr.c
+++ b/src/host/layer23/src/mobile/gsm48_rr.c
@@ -408,8 +408,8 @@ static void new_rr_state(struct gsm48_rrlayer *rr, int state)
 			memset(&em, 0, sizeof(em));
 			em.same_cell = 1;
 		}
-		gsm322_makesend_c_event(rr->ms, GSM322_EVENT_RET_IDLE,
-					(uint8_t *)&em, sizeof(em));
+		gsm322_event_input(rr->ms, GSM322_EVT_C, GSM322_EVENT_RET_IDLE,
+				   (uint8_t *)&em, sizeof(em));
 		/* reset any BA range */
 		rr->ba_ranges = 0;
 	}
@@ -1189,7 +1189,8 @@ static int gsm48_rr_chan_req(struct osmocom_ms *ms, int cause, int paging)
 	 * NOTE: this must be sent unbuffered, because the state may not
 	 * change until idle mode is left
 	 */
-	rc = gsm322_makesend_c_event(ms, GSM322_EVENT_LEAVE_IDLE, NULL, 0);
+	rc = gsm322_event_input(ms, GSM322_EVT_C, GSM322_EVENT_LEAVE_IDLE,
+				NULL, 0);
 	if (rc) {
 		if (paging)
 			return rc;
@@ -1595,7 +1596,7 @@ static int gsm48_new_sysinfo(struct osmocom_ms *ms, uint8_t type)
 	/* send sysinfo event to other layers */
 	memset(&em, 0, sizeof(em));
 	em.sysinfo = type;
-	gsm322_makesend_cs_event(ms, GSM322_EVENT_SYSINFO,
+	gsm322_event_input(ms, GSM322_EVT_CS, GSM322_EVENT_SYSINFO,
 				 (uint8_t *)&em, sizeof(em));
 
 	/* send timer info to location update process */
diff --git a/src/host/layer23/src/mobile/vty_interface.c b/src/host/layer23/src/mobile/vty_interface.c
index e3e7c47..d83dae8 100644
--- a/src/host/layer23/src/mobile/vty_interface.c
+++ b/src/host/layer23/src/mobile/vty_interface.c
@@ -689,8 +689,8 @@ DEFUN(network_select, network_select_cmd, "network select MS_NAME MCC MNC",
 	memset(&ngm, 0, sizeof(ngm));
 	ngm.mcc = mcc;
 	ngm.mnc = mnc;
-	gsm322_makesend_plmn_msg(ms, GSM322_EVENT_CHOOSE_PLMN,
-				 (uint8_t *)&ngm, sizeof(ngm));
+	gsm322_event_input(ms, GSM322_EVT_PLMN, GSM322_EVENT_CHOOSE_PLMN,
+			   (uint8_t *)&ngm, sizeof(ngm));
 
 	return CMD_SUCCESS;
 }
@@ -820,7 +820,8 @@ DEFUN(network_search, network_search_cmd, "network search MS_NAME",
 	if (!ms)
 		return CMD_WARNING;
 
-	gsm322_makesend_plmn_msg(ms, GSM322_EVENT_USER_RESEL, NULL, 0);
+	gsm322_event_input(ms, GSM322_EVT_PLMN,
+			   GSM322_EVENT_USER_RESEL, NULL, 0);
 
 	return CMD_SUCCESS;
 }
@@ -1265,7 +1266,7 @@ DEFUN(cfg_ms_mode, cfg_ms_mode_cmd, "network-selection-mode (auto|manual)",
 		msg_type = GSM322_EVENT_SEL_MANUAL;
 	if (msg_type < 0)
 		return CMD_WARNING;
-	gsm322_makesend_plmn_msg(ms, msg_type, NULL, 0);
+	gsm322_event_input(ms, GSM322_EVT_PLMN, msg_type, NULL, 0);
 
 	return CMD_SUCCESS;
 }
-- 
1.7.2.3


--Kj7319i9nmIyA2yE
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0003-mobile-introduce-and-use-gsm48_mmevevent_input.patch"



More information about the baseband-devel mailing list