[MERGED] osmocom-bb[master]: mobile: Send SMS through the primitive interface

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sat Dec 30 20:01:20 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: mobile: Send SMS through the primitive interface
......................................................................


mobile: Send SMS through the primitive interface

Make this symmetric and send the SMS through the primitive
interface. Construct and copy the sms into the prim, store
the SCA in the prim as well. In 04.11 we see we can store
2*10 digits in the destination address and a NUL.

Change-Id: I91d7537f4f6ce5ba00218c58f3456947ec7bc662
---
M src/host/layer23/include/osmocom/bb/mobile/gsm411_sms.h
M src/host/layer23/include/osmocom/bb/mobile/primitives.h
M src/host/layer23/src/mobile/gsm411_sms.c
M src/host/layer23/src/mobile/primitives.c
M src/host/layer23/src/mobile/script_lua.c
5 files changed, 39 insertions(+), 4 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/host/layer23/include/osmocom/bb/mobile/gsm411_sms.h b/src/host/layer23/include/osmocom/bb/mobile/gsm411_sms.h
index d3074fb..3ed6710 100644
--- a/src/host/layer23/include/osmocom/bb/mobile/gsm411_sms.h
+++ b/src/host/layer23/include/osmocom/bb/mobile/gsm411_sms.h
@@ -35,5 +35,7 @@
 int gsm411_rcv_sms(struct osmocom_ms *ms, struct msgb *msg);
 int sms_send(struct osmocom_ms *ms, const char *sms_sca, const char *number,
 	const char *text, uint8_t msg_ref);
+int gsm411_tx_sms_submit(struct osmocom_ms *ms, const char *sms_sca,
+	struct gsm_sms *sms);
 
 #endif /* _GSM411_SMS_H */
diff --git a/src/host/layer23/include/osmocom/bb/mobile/primitives.h b/src/host/layer23/include/osmocom/bb/mobile/primitives.h
index 39b4945..034b202 100644
--- a/src/host/layer23/include/osmocom/bb/mobile/primitives.h
+++ b/src/host/layer23/include/osmocom/bb/mobile/primitives.h
@@ -62,6 +62,8 @@
 struct mobile_sms_param {
 	struct gsm_sms sms;
 
+	char sca[20+1]; /*<! Service Centre Address. For SubmitMS */
+
 	bool cause_valid;
 	int cause;
 };
diff --git a/src/host/layer23/src/mobile/gsm411_sms.c b/src/host/layer23/src/mobile/gsm411_sms.c
index 6d9d56e..9090697 100644
--- a/src/host/layer23/src/mobile/gsm411_sms.c
+++ b/src/host/layer23/src/mobile/gsm411_sms.c
@@ -624,7 +624,7 @@
 }
 
 /* Take a SMS in gsm_sms structure and send it. */
-static int gsm411_tx_sms_submit(struct osmocom_ms *ms, const char *sms_sca,
+int gsm411_tx_sms_submit(struct osmocom_ms *ms, const char *sms_sca,
 	struct gsm_sms *sms)
 {
 	struct msgb *msg;
diff --git a/src/host/layer23/src/mobile/primitives.c b/src/host/layer23/src/mobile/primitives.c
index fd486ea..c3f28a5 100644
--- a/src/host/layer23/src/mobile/primitives.c
+++ b/src/host/layer23/src/mobile/primitives.c
@@ -173,6 +173,19 @@
 	return -1;
 }
 
+static int send_sms(struct mobile_prim_intf *intf, struct mobile_sms_param *param)
+{
+	struct gsm_sms *sms;
+
+	sms = sms_alloc();
+	*sms = param->sms;
+
+	/* Force a NUL at the end of the string */
+	param->sca[sizeof(param->sca) - 1] = '\0';
+
+	return gsm411_tx_sms_submit(intf->ms, param->sca, sms);
+}
+
 int mobile_prim_intf_req(struct mobile_prim_intf *intf, struct mobile_prim *prim)
 {
 	int rc = 0;
@@ -184,6 +197,9 @@
 	case OSMO_PRIM(PRIM_MOB_TIMER_CANCEL, PRIM_OP_REQUEST):
 		rc = cancel_timer(intf, &prim->u.timer);
 		break;
+	case OSMO_PRIM(PRIM_MOB_SMS, PRIM_OP_REQUEST):
+		rc = send_sms(intf, &prim->u.sms);
+		break;
 	default:
 		LOGP(DPRIM, LOGL_ERROR, "Unknown primitive: %d\n", OSMO_PRIM_HDR(&prim->hdr));
 		break;
diff --git a/src/host/layer23/src/mobile/script_lua.c b/src/host/layer23/src/mobile/script_lua.c
index 1b80c48..14ab58f 100644
--- a/src/host/layer23/src/mobile/script_lua.c
+++ b/src/host/layer23/src/mobile/script_lua.c
@@ -372,7 +372,9 @@
 static int lua_ms_sms_send_simple(lua_State *L)
 {
 	const char *sms_sca, *number, *text;
-	int msg_ref, rc;
+	struct mobile_prim *prim;
+	struct gsm_sms *sms;
+	int msg_ref;
 
 	luaL_argcheck(L, lua_isnumber(L, -1), 4, "msg_ref needs to be a number");
 	luaL_argcheck(L, lua_isstring(L, -2), 3, "text must be a string");
@@ -384,8 +386,21 @@
 	number = lua_tostring(L, -3);
 	sms_sca = lua_tostring(L, -4);
 
-	rc = sms_send(get_primitive(L)->ms, sms_sca, number, text, msg_ref);
-	lua_pushinteger(L, rc);
+	prim = mobile_prim_alloc(PRIM_MOB_SMS, PRIM_OP_REQUEST);
+
+	sms = sms_from_text(number, 0, text);
+	if (!sms) {
+		lua_pushinteger(L, -ENOMEM);
+		msgb_free(prim->hdr.msg);
+		return 1;
+	}
+
+	prim->u.sms.sms = *sms;
+	prim->u.sms.sms.msg_ref = msg_ref;
+	osmo_strlcpy(prim->u.sms.sca, sms_sca, sizeof(prim->u.sms.sca));
+	mobile_prim_intf_req(get_primitive(L), prim);
+
+	lua_pushinteger(L, 0);
 	return 1;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/5594
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I91d7537f4f6ce5ba00218c58f3456947ec7bc662
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list