summaryrefslogtreecommitdiffstats
path: root/plugins/ste.c
diff options
context:
space:
mode:
authorHelen Clemson <helen.clemson@stericsson.com>2010-12-02 12:05:40 +0100
committerDenis Kenzior <denkenz@gmail.com>2010-12-03 08:01:10 -0600
commit6befb8290d72bfa037be697e27008cbb9749f862 (patch)
tree18f5c8df14c3b63f94bca2bfc59beab801ceb110 /plugins/ste.c
parenta67c5cf4c5493ceb17167bda641ddbff597c16a0 (diff)
downloadofono-6befb8290d72bfa037be697e27008cbb9749f862.tar.bz2
ste: Restructure caif channel creation
This is restructuring the caif channel creation, so that at a later date multiple AT channels can be supported. This effectively moves the channel creation from ste_enable, into its own function, ste_create_channel.
Diffstat (limited to 'plugins/ste.c')
-rw-r--r--plugins/ste.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/plugins/ste.c b/plugins/ste.c
index ecdc326f..8bebfa48 100644
--- a/plugins/ste.c
+++ b/plugins/ste.c
@@ -64,8 +64,12 @@
#include <drivers/stemodem/caif_socket.h>
#include <drivers/stemodem/if_caif.h>
+#define NUM_CHAT 1
+
static const char *cpin_prefix[] = { "+CPIN:", NULL };
+static char *chat_prefixes[NUM_CHAT] = { "Default: " };
+
struct ste_data {
GAtChat *chat;
guint cpin_poll_source;
@@ -162,11 +166,9 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
init_simpin_check(modem);
}
-static int ste_enable(struct ofono_modem *modem)
+static GIOChannel *ste_create_channel(struct ofono_modem *modem)
{
- struct ste_data *data = ofono_modem_get_data(modem);
GIOChannel *channel;
- GAtSyntax *syntax;
const char *device;
int fd;
@@ -182,7 +184,7 @@ static int ste_enable(struct ofono_modem *modem)
fd = socket(AF_CAIF, SOCK_STREAM, CAIFPROTO_AT);
if (fd < 0) {
ofono_error("Failed to create CAIF socket for AT");
- return -EIO;
+ return NULL;
}
/* Bind CAIF socket to specified interface */
@@ -197,7 +199,7 @@ static int ste_enable(struct ofono_modem *modem)
ofono_error("Failed to bind caif socket "
"to interface");
close(fd);
- return err;
+ return NULL;
}
}
@@ -210,37 +212,51 @@ static int ste_enable(struct ofono_modem *modem)
if (err < 0) {
ofono_error("Failed to connect CAIF socket for AT");
close(fd);
- return err;
+ return NULL;
}
} else {
fd = open(device, O_RDWR);
if (fd < 0) {
ofono_error("Failed to open device %s", device);
- return -EIO;
+ return NULL;
}
}
channel = g_io_channel_unix_new(fd);
if (channel == NULL) {
close(fd);
- return -EIO;
+ return NULL;
}
g_io_channel_set_close_on_unref(channel, TRUE);
+ return channel;
+}
+
+static int ste_enable(struct ofono_modem *modem)
+{
+ struct ste_data *data = ofono_modem_get_data(modem);
+ GIOChannel *channel;
+ GAtSyntax *syntax;
+
syntax = g_at_syntax_new_gsm_permissive();
+ channel = ste_create_channel(modem);
+ if (!channel)
+ return -EIO;
+
data->chat = g_at_chat_new_blocking(channel, syntax);
- g_at_syntax_unref(syntax);
+ g_at_chat_send(data->chat, "AT&F E0 V1 X4 &C1 +CMEE=1",
+ NULL, NULL, NULL, NULL);
+
g_io_channel_unref(channel);
+ g_at_syntax_unref(syntax);
if (data->chat == NULL)
return -ENOMEM;
if (getenv("OFONO_AT_DEBUG"))
- g_at_chat_set_debug(data->chat, ste_debug, "");
+ g_at_chat_set_debug(data->chat, ste_debug, chat_prefixes[0]);
- g_at_chat_send(data->chat, "AT&F E0 V1 X4 &C1 +CMEE=1",
- NULL, NULL, NULL, NULL);
g_at_chat_send(data->chat, "AT+CFUN=4", NULL, cfun_enable, modem, NULL);
return -EINPROGRESS;