All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] sim800: add support for sim800 modem.
@ 2018-10-15 17:27 Clement Viel
  2018-10-15 17:27 ` [PATCH 2/3] sim800: add documentation and modify AUTHORS file Clement Viel
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Clement Viel @ 2018-10-15 17:27 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4267 bytes --]

---
 plugins/sim900.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 80 insertions(+), 9 deletions(-)

diff --git a/plugins/sim900.c b/plugins/sim900.c
index a7728cd..9f3f334 100644
--- a/plugins/sim900.c
+++ b/plugins/sim900.c
@@ -24,6 +24,7 @@
 #endif
 
 #include <errno.h>
+#include <string.h>
 #include <stdlib.h>
 #include <glib.h>
 #include <gatchat.h>
@@ -60,13 +61,59 @@ static char *dlc_prefixes[NUM_DLC] = { "Voice: ", "Net: ", "SMS: ",
 
 static const char *none_prefix[] = { NULL };
 
+typedef enum type {
+	SIM800,
+	SIM900,
+	SIM_UNKNOWN,
+} type_t;
+
 struct sim900_data {
 	GIOChannel *device;
 	GAtMux *mux;
 	GAtChat * dlcs[NUM_DLC];
 	guint frame_size;
+	type_t modem_type;
 };
 
+static void set_modem_type (struct ofono_modem *modem)
+{
+	struct sim900_data *data = ofono_modem_get_data(modem);
+	const char *path = ofono_modem_get_path(modem);
+
+	if (strstr(path, "sim800"))
+		data->modem_type = SIM800;
+	else if (strstr(path, "sim900"))
+		data->modem_type = SIM900;
+	else
+		data->modem_type = SIM_UNKNOWN;
+
+}
+
+static void mux_ready_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct sim900_data *data = ofono_modem_get_data(modem);
+	struct ofono_gprs *gprs = NULL;
+	struct ofono_gprs_context *gc;
+	static int notified = 0;
+
+	if (!notified) {
+	ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
+						data->dlcs[SMS_DLC]);
+
+
+	gprs = ofono_gprs_create(modem, 0, "atmodem", data->dlcs[GPRS_DLC]);
+	if (gprs == NULL)
+		return;
+
+	gc = ofono_gprs_context_create(modem, OFONO_VENDOR_SIMCOM,
+					"atmodem", data->dlcs[GPRS_DLC]);
+	if (gc)
+		ofono_gprs_add_context(gprs, gc);
+	}
+
+}
+
 static int sim900_probe(struct ofono_modem *modem)
 {
 	struct sim900_data *data;
@@ -79,6 +126,7 @@ static int sim900_probe(struct ofono_modem *modem)
 
 	ofono_modem_set_data(modem, data);
 
+	set_modem_type(modem);
 	return 0;
 }
 
@@ -111,6 +159,7 @@ static GAtChat *open_device(struct ofono_modem *modem,
 	GHashTable *options;
 
 	device = ofono_modem_get_string(modem, key);
+
 	if (device == NULL)
 		return NULL;
 
@@ -232,6 +281,11 @@ static void setup_internal_mux(struct ofono_modem *modem)
 			goto error;
 		}
 	}
+	if (data->modem_type == SIM800) {
+		for (i = 0; i<NUM_DLC; i++) {
+			g_at_chat_register(data->dlcs[i], "SMS Ready", mux_ready_notify, FALSE, modem, NULL);
+		}
+	}
 
 	ofono_modem_set_powered(modem, TRUE);
 
@@ -353,18 +407,20 @@ static void sim900_post_sim(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
-	ofono_phonebook_create(modem, 0, "atmodem", data->dlcs[VOICE_DLC]);
-	ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
+	if (data->modem_type != SIM800) {
+		ofono_phonebook_create(modem, 0, "atmodem", data->dlcs[VOICE_DLC]);
+		ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
 						data->dlcs[SMS_DLC]);
 
-	gprs = ofono_gprs_create(modem, 0, "atmodem", data->dlcs[GPRS_DLC]);
-	if (gprs == NULL)
-		return;
+		gprs = ofono_gprs_create(modem, 0, "atmodem", data->dlcs[GPRS_DLC]);
+		if (gprs == NULL)
+			return;
 
-	gc = ofono_gprs_context_create(modem, OFONO_VENDOR_SIMCOM_SIM900,
+		gc = ofono_gprs_context_create(modem, OFONO_VENDOR_SIMCOM_SIM900,
 					"atmodem", data->dlcs[GPRS_DLC]);
-	if (gc)
-		ofono_gprs_add_context(gprs, gc);
+		if (gc)
+			ofono_gprs_add_context(gprs, gc);
+	}
 }
 
 static void sim900_post_online(struct ofono_modem *modem)
@@ -391,9 +447,24 @@ static struct ofono_modem_driver sim900_driver = {
 	.post_online	= sim900_post_online,
 };
 
+
+static struct ofono_modem_driver sim800_driver = {
+	.name		= "sim800",
+	.probe		= sim900_probe,
+	.remove		= sim900_remove,
+	.enable		= sim900_enable,
+	.disable	= sim900_disable,
+	.pre_sim	= sim900_pre_sim,
+	.post_sim	= sim900_post_sim,
+	.post_online	= sim900_post_online,
+};
+
 static int sim900_init(void)
 {
-	return ofono_modem_driver_register(&sim900_driver);
+	int ret = 0;
+	ret = ofono_modem_driver_register(&sim800_driver);
+	ret += ofono_modem_driver_register(&sim900_driver);
+	return ret;
 }
 
 static void sim900_exit(void)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH 1/3] sim800: add support for sim800 modem.
@ 2018-11-07 10:14 Clement Viel
  2018-11-07 13:47 ` Jonas Bonn
  0 siblings, 1 reply; 11+ messages in thread
From: Clement Viel @ 2018-11-07 10:14 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 5154 bytes --]

---
 plugins/sim900.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 98 insertions(+), 10 deletions(-)

diff --git a/plugins/sim900.c b/plugins/sim900.c
index a7728cd..c12576d 100644
--- a/plugins/sim900.c
+++ b/plugins/sim900.c
@@ -24,6 +24,7 @@
 #endif
 
 #include <errno.h>
+#include <string.h>
 #include <stdlib.h>
 #include <glib.h>
 #include <gatchat.h>
@@ -60,13 +61,73 @@ static char *dlc_prefixes[NUM_DLC] = { "Voice: ", "Net: ", "SMS: ",
 
 static const char *none_prefix[] = { NULL };
 
+typedef enum type {
+	SIM800,
+	SIM900,
+	SIM_UNKNOWN,
+} type_t;
+
 struct sim900_data {
 	GIOChannel *device;
 	GAtMux *mux;
 	GAtChat * dlcs[NUM_DLC];
 	guint frame_size;
+	type_t modem_type;
 };
 
+static void set_modem_type (const char *type, struct ofono_modem *modem)
+{
+	struct sim900_data *data = ofono_modem_get_data(modem);
+
+	if (strcmp(type, "sim800") == 0)
+		data->modem_type = SIM800;
+	else if (strcmp(type, "sim900") == 0)
+		data->modem_type = SIM900;
+	else
+		data->modem_type = SIM_UNKNOWN;
+	DBG("modem type is %d",data->modem_type);
+}
+
+static void mux_ready_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct sim900_data *data = ofono_modem_get_data(modem);
+	struct ofono_gprs *gprs = NULL;
+	struct ofono_gprs_context *gc;
+
+	ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
+				data->dlcs[SMS_DLC]);
+
+	gprs = ofono_gprs_create(modem, 0, "atmodem", data->dlcs[GPRS_DLC]);
+	if (gprs == NULL)
+		return;
+
+	gc = ofono_gprs_context_create(modem, OFONO_VENDOR_SIMCOM,
+					"atmodem", data->dlcs[GPRS_DLC]);
+	if (gc)
+		ofono_gprs_add_context(gprs, gc);
+
+}
+
+static void check_model(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	GAtResultIter iter;
+	char const *model;
+
+	g_at_result_iter_init(&iter, result);
+
+	while (g_at_result_iter_next(&iter, NULL)) {
+		if (!g_at_result_iter_next_unquoted_string(&iter, &model))
+			continue;
+
+		if (strstr(model, "SIM800"))
+			set_modem_type("sim800", modem);
+		else if (strstr(model, "SIM900"))
+			set_modem_type("sim900", modem);
+	}
+}
+
 static int sim900_probe(struct ofono_modem *modem)
 {
 	struct sim900_data *data;
@@ -78,7 +139,6 @@ static int sim900_probe(struct ofono_modem *modem)
 		return -ENOMEM;
 
 	ofono_modem_set_data(modem, data);
-
 	return 0;
 }
 
@@ -111,6 +171,7 @@ static GAtChat *open_device(struct ofono_modem *modem,
 	GHashTable *options;
 
 	device = ofono_modem_get_string(modem, key);
+
 	if (device == NULL)
 		return NULL;
 
@@ -232,6 +293,11 @@ static void setup_internal_mux(struct ofono_modem *modem)
 			goto error;
 		}
 	}
+	if (data->modem_type == SIM800) {
+		for (i = 0; i<NUM_DLC; i++) {
+			g_at_chat_register(data->dlcs[i], "SMS Ready", mux_ready_notify, FALSE, modem, NULL);
+		}
+	}
 
 	ofono_modem_set_powered(modem, TRUE);
 
@@ -294,6 +360,7 @@ static int sim900_enable(struct ofono_modem *modem)
 		return -EINVAL;
 
 	g_at_chat_send(data->dlcs[SETUP_DLC], "ATE0", NULL, NULL, NULL, NULL);
+	g_at_chat_send(data->dlcs[SETUP_DLC], "AT+CGMM", NULL,check_model, modem, NULL);
 
 	/* For obtain correct sms service number */
 	g_at_chat_send(data->dlcs[SETUP_DLC], "AT+CSCS=\"GSM\"", NULL,
@@ -353,18 +420,20 @@ static void sim900_post_sim(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
-	ofono_phonebook_create(modem, 0, "atmodem", data->dlcs[VOICE_DLC]);
-	ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
+	if (data->modem_type != SIM800) {
+		ofono_phonebook_create(modem, 0, "atmodem", data->dlcs[VOICE_DLC]);
+		ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
 						data->dlcs[SMS_DLC]);
 
-	gprs = ofono_gprs_create(modem, 0, "atmodem", data->dlcs[GPRS_DLC]);
-	if (gprs == NULL)
-		return;
+		gprs = ofono_gprs_create(modem, 0, "atmodem", data->dlcs[GPRS_DLC]);
+		if (gprs == NULL)
+			return;
 
-	gc = ofono_gprs_context_create(modem, OFONO_VENDOR_SIMCOM_SIM900,
+		gc = ofono_gprs_context_create(modem, OFONO_VENDOR_SIMCOM_SIM900,
 					"atmodem", data->dlcs[GPRS_DLC]);
-	if (gc)
-		ofono_gprs_add_context(gprs, gc);
+		if (gc)
+			ofono_gprs_add_context(gprs, gc);
+	}
 }
 
 static void sim900_post_online(struct ofono_modem *modem)
@@ -391,9 +460,28 @@ static struct ofono_modem_driver sim900_driver = {
 	.post_online	= sim900_post_online,
 };
 
+
+static struct ofono_modem_driver sim800_driver = {
+	.name		= "sim800",
+	.probe		= sim900_probe,
+	.remove		= sim900_remove,
+	.enable		= sim900_enable,
+	.disable	= sim900_disable,
+	.pre_sim	= sim900_pre_sim,
+	.post_sim	= sim900_post_sim,
+	.post_online	= sim900_post_online,
+};
+
 static int sim900_init(void)
 {
-	return ofono_modem_driver_register(&sim900_driver);
+	int ret = 0;
+	ret = ofono_modem_driver_register(&sim800_driver);
+	if (!ret)
+		return ret;
+	ret = ofono_modem_driver_register(&sim900_driver);
+	if (!ret)
+		return ret;
+	return ret;
 }
 
 static void sim900_exit(void)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH 1/3] sim800: add support for sim800 modem.
@ 2018-10-03 13:28 Clement Viel
  0 siblings, 0 replies; 11+ messages in thread
From: Clement Viel @ 2018-10-03 13:28 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4267 bytes --]

---
 plugins/sim900.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 80 insertions(+), 9 deletions(-)

diff --git a/plugins/sim900.c b/plugins/sim900.c
index a7728cd..9f3f334 100644
--- a/plugins/sim900.c
+++ b/plugins/sim900.c
@@ -24,6 +24,7 @@
 #endif
 
 #include <errno.h>
+#include <string.h>
 #include <stdlib.h>
 #include <glib.h>
 #include <gatchat.h>
@@ -60,13 +61,59 @@ static char *dlc_prefixes[NUM_DLC] = { "Voice: ", "Net: ", "SMS: ",
 
 static const char *none_prefix[] = { NULL };
 
+typedef enum type {
+	SIM800,
+	SIM900,
+	SIM_UNKNOWN,
+} type_t;
+
 struct sim900_data {
 	GIOChannel *device;
 	GAtMux *mux;
 	GAtChat * dlcs[NUM_DLC];
 	guint frame_size;
+	type_t modem_type;
 };
 
+static void set_modem_type (struct ofono_modem *modem)
+{
+	struct sim900_data *data = ofono_modem_get_data(modem);
+	const char *path = ofono_modem_get_path(modem);
+
+	if (strstr(path, "sim800"))
+		data->modem_type = SIM800;
+	else if (strstr(path, "sim900"))
+		data->modem_type = SIM900;
+	else
+		data->modem_type = SIM_UNKNOWN;
+
+}
+
+static void mux_ready_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct sim900_data *data = ofono_modem_get_data(modem);
+	struct ofono_gprs *gprs = NULL;
+	struct ofono_gprs_context *gc;
+	static int notified = 0;
+
+	if (!notified) {
+	ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
+						data->dlcs[SMS_DLC]);
+
+
+	gprs = ofono_gprs_create(modem, 0, "atmodem", data->dlcs[GPRS_DLC]);
+	if (gprs == NULL)
+		return;
+
+	gc = ofono_gprs_context_create(modem, OFONO_VENDOR_SIMCOM,
+					"atmodem", data->dlcs[GPRS_DLC]);
+	if (gc)
+		ofono_gprs_add_context(gprs, gc);
+	}
+
+}
+
 static int sim900_probe(struct ofono_modem *modem)
 {
 	struct sim900_data *data;
@@ -79,6 +126,7 @@ static int sim900_probe(struct ofono_modem *modem)
 
 	ofono_modem_set_data(modem, data);
 
+	set_modem_type(modem);
 	return 0;
 }
 
@@ -111,6 +159,7 @@ static GAtChat *open_device(struct ofono_modem *modem,
 	GHashTable *options;
 
 	device = ofono_modem_get_string(modem, key);
+
 	if (device == NULL)
 		return NULL;
 
@@ -232,6 +281,11 @@ static void setup_internal_mux(struct ofono_modem *modem)
 			goto error;
 		}
 	}
+	if (data->modem_type == SIM800) {
+		for (i = 0; i<NUM_DLC; i++) {
+			g_at_chat_register(data->dlcs[i], "SMS Ready", mux_ready_notify, FALSE, modem, NULL);
+		}
+	}
 
 	ofono_modem_set_powered(modem, TRUE);
 
@@ -353,18 +407,20 @@ static void sim900_post_sim(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
-	ofono_phonebook_create(modem, 0, "atmodem", data->dlcs[VOICE_DLC]);
-	ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
+	if (data->modem_type != SIM800) {
+		ofono_phonebook_create(modem, 0, "atmodem", data->dlcs[VOICE_DLC]);
+		ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
 						data->dlcs[SMS_DLC]);
 
-	gprs = ofono_gprs_create(modem, 0, "atmodem", data->dlcs[GPRS_DLC]);
-	if (gprs == NULL)
-		return;
+		gprs = ofono_gprs_create(modem, 0, "atmodem", data->dlcs[GPRS_DLC]);
+		if (gprs == NULL)
+			return;
 
-	gc = ofono_gprs_context_create(modem, OFONO_VENDOR_SIMCOM_SIM900,
+		gc = ofono_gprs_context_create(modem, OFONO_VENDOR_SIMCOM_SIM900,
 					"atmodem", data->dlcs[GPRS_DLC]);
-	if (gc)
-		ofono_gprs_add_context(gprs, gc);
+		if (gc)
+			ofono_gprs_add_context(gprs, gc);
+	}
 }
 
 static void sim900_post_online(struct ofono_modem *modem)
@@ -391,9 +447,24 @@ static struct ofono_modem_driver sim900_driver = {
 	.post_online	= sim900_post_online,
 };
 
+
+static struct ofono_modem_driver sim800_driver = {
+	.name		= "sim800",
+	.probe		= sim900_probe,
+	.remove		= sim900_remove,
+	.enable		= sim900_enable,
+	.disable	= sim900_disable,
+	.pre_sim	= sim900_pre_sim,
+	.post_sim	= sim900_post_sim,
+	.post_online	= sim900_post_online,
+};
+
 static int sim900_init(void)
 {
-	return ofono_modem_driver_register(&sim900_driver);
+	int ret = 0;
+	ret = ofono_modem_driver_register(&sim800_driver);
+	ret += ofono_modem_driver_register(&sim900_driver);
+	return ret;
 }
 
 static void sim900_exit(void)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-11-07 13:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-15 17:27 [PATCH 1/3] sim800: add support for sim800 modem Clement Viel
2018-10-15 17:27 ` [PATCH 2/3] sim800: add documentation and modify AUTHORS file Clement Viel
2018-11-01 14:48   ` Denis Kenzior
2018-11-02 23:36     ` Clement Viel
2018-10-15 17:27 ` [PATCH 3/3] sim800: add udev detection Clement Viel
2018-10-31 15:16 ` [PATCH 1/3] sim800: add support for sim800 modem =?unknown-8bit?q?Cl=C3=A9ment?= VIEL
2018-11-01 14:53 ` Denis Kenzior
2018-11-02 23:31   ` Clement Viel
  -- strict thread matches above, loose matches on Subject: below --
2018-11-07 10:14 Clement Viel
2018-11-07 13:47 ` Jonas Bonn
2018-10-03 13:28 Clement Viel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.