summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2019-05-31 11:05:17 -0500
committerDenis Kenzior <denkenz@gmail.com>2019-05-31 11:58:36 -0500
commit630e48465cf8becca9307f098817d5da3d13a6a2 (patch)
treedd7cb1a2a14b4dd3b56ba374d8eff83b62bcf92a /drivers
parent06de60a8fdfba80709c0f68f908da95b07e5bb02 (diff)
downloadofono-630e48465cf8becca9307f098817d5da3d13a6a2.tar.gz
atutil: Introduce at_util_open_device
Diffstat (limited to 'drivers')
-rw-r--r--drivers/atmodem/atutil.c55
-rw-r--r--drivers/atmodem/atutil.h8
2 files changed, 61 insertions, 2 deletions
diff --git a/drivers/atmodem/atutil.c b/drivers/atmodem/atutil.c
index adcca85b..1db524e3 100644
--- a/drivers/atmodem/atutil.c
+++ b/drivers/atmodem/atutil.c
@@ -24,15 +24,17 @@
#include <config.h>
#endif
-#include <glib.h>
-#include <gatchat.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include <glib.h>
+#include <gattty.h>
+
#define OFONO_API_SUBJECT_TO_CHANGE
#include <ofono/log.h>
#include <ofono/types.h>
+#include <ofono/modem.h>
#include "atutil.h"
#include "vendor.h"
@@ -736,3 +738,52 @@ char *at_util_get_cgdcont_command(guint cid, enum ofono_gprs_proto proto,
return g_strdup_printf("AT+CGDCONT=%u,\"%s\",\"%s\"", cid, pdp_type,
apn);
}
+
+GAtChat *at_util_open_device(struct ofono_modem *modem, const char *key,
+ GAtDebugFunc debug_func, char *debug_prefix,
+ char *tty_option, ...)
+{
+ const char *device;
+ va_list args;
+ GIOChannel *channel;
+ GAtSyntax *syntax;
+ GAtChat *chat;
+ GHashTable *options = NULL;
+
+ device = ofono_modem_get_string(modem, key);
+ if (device == NULL)
+ return NULL;
+
+ if (tty_option) {
+ options = g_hash_table_new(g_str_hash, g_str_equal);
+ if (options == NULL)
+ return NULL;
+
+ va_start(args, tty_option);
+ while (tty_option) {
+ gpointer value = (gpointer) va_arg(args, const char *);
+
+ g_hash_table_insert(options, tty_option, value);
+ tty_option = (gpointer) va_arg(args, const char *);
+ }
+ }
+
+ channel = g_at_tty_open(device, options);
+ g_hash_table_destroy(options);
+
+ if (channel == NULL)
+ return NULL;
+
+ syntax = g_at_syntax_new_gsm_permissive();
+ chat = g_at_chat_new(channel, syntax);
+ g_at_syntax_unref(syntax);
+ g_io_channel_unref(channel);
+
+ if (chat == NULL)
+ return NULL;
+
+ if (getenv("OFONO_AT_DEBUG"))
+ g_at_chat_set_debug(chat, debug_func, debug_prefix);
+
+ return chat;
+}
diff --git a/drivers/atmodem/atutil.h b/drivers/atmodem/atutil.h
index 61800ff4..fe2acb39 100644
--- a/drivers/atmodem/atutil.h
+++ b/drivers/atmodem/atutil.h
@@ -20,6 +20,10 @@
*
*/
+#include <gatchat.h>
+
+struct ofono_modem;
+
enum at_util_sms_store {
AT_UTIL_SMS_STORE_SM = 0,
AT_UTIL_SMS_STORE_ME = 1,
@@ -169,3 +173,7 @@ static inline int at_util_convert_signal_strength(int strength)
e.error = 0; \
f(&e, ##args); \
} while (0)
+
+GAtChat *at_util_open_device(struct ofono_modem *modem, const char *key,
+ GAtDebugFunc debug_func, char *debug_prefix,
+ char *tty_option, ...);