summaryrefslogtreecommitdiff
path: root/drivers/ifxmodem
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2019-03-04 13:34:13 -0600
committerDenis Kenzior <denkenz@gmail.com>2019-03-04 13:34:13 -0600
commit54b8639c0e8cad483f879ac591e6e5aceb970c8f (patch)
tree0f604c79294d097024303de4f04b680e7406e67f /drivers/ifxmodem
parentb51c1a23c018ba63a40f1c9ad81cf80e712cfe1d (diff)
downloadofono-54b8639c0e8cad483f879ac591e6e5aceb970c8f.tar.gz
ifxmodem: Clean up the previous commit slightly
The if statements were over 80 characters and breaking them up made the code look a bit uglier. So refactor the if statements to just figure out the data path 'n' parameter or return an error. On success, form the datapath string and return it. Also bump the buffer size and use snprintf to be safe(r).
Diffstat (limited to 'drivers/ifxmodem')
-rw-r--r--drivers/ifxmodem/gprs-context.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/drivers/ifxmodem/gprs-context.c b/drivers/ifxmodem/gprs-context.c
index b36740d0..6042004d 100644
--- a/drivers/ifxmodem/gprs-context.c
+++ b/drivers/ifxmodem/gprs-context.c
@@ -276,18 +276,27 @@ static void cgdata_cb(gboolean ok, GAtResult *result, gpointer user_data)
CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
}
-static void get_datapath(struct ofono_modem *modem, const char *interface,
- char* datapath)
+static const char *get_datapath(struct ofono_modem *modem,
+ const char *interface)
{
- if (!datapath)
- return;
+ static char datapath[256];
+ char n;
+
+ if (!strcmp(interface,
+ ofono_modem_get_string(modem, "NetworkInterface")))
+ n = '0';
+ else if (!strcmp(interface,
+ ofono_modem_get_string(modem, "NetworkInterface2")))
+ n = '1';
+ else if (!strcmp(interface,
+ ofono_modem_get_string(modem, "NetworkInterface3")))
+ n = '2';
+ else
+ return NULL;
- if (!strcmp(interface, ofono_modem_get_string(modem, "NetworkInterface")))
- sprintf(datapath, "%s0", ofono_modem_get_string(modem, "DataPath"));
- else if (!strcmp(interface, ofono_modem_get_string(modem, "NetworkInterface2")))
- sprintf(datapath, "%s1", ofono_modem_get_string(modem, "DataPath"));
- else if (!strcmp(interface, ofono_modem_get_string(modem, "NetworkInterface3")))
- sprintf(datapath, "%s2", ofono_modem_get_string(modem, "DataPath"));
+ snprintf(datapath, sizeof(datapath), "%s%c",
+ ofono_modem_get_string(modem, "DataPath"), n);
+ return datapath;
}
static void cgcontrdp_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -301,8 +310,8 @@ static void cgcontrdp_cb(gboolean ok, GAtResult *result, gpointer user_data)
const char *gw = NULL;
const char *dns[3];
const char *ctrlpath;
- char datapath[50];
- char buf[100];
+ const char *datapath;
+ char buf[512];
const char *interface;
DBG("ok %d", ok);
@@ -362,7 +371,7 @@ static void cgcontrdp_cb(gboolean ok, GAtResult *result, gpointer user_data)
ctrlpath = ofono_modem_get_string(modem, "CtrlPath");
interface = ofono_gprs_context_get_interface(gc);
- get_datapath(modem, interface, datapath);
+ datapath = get_datapath(modem, interface);
ofono_gprs_context_set_ipv4_address(gc, gcd->address, TRUE);
@@ -374,10 +383,11 @@ static void cgcontrdp_cb(gboolean ok, GAtResult *result, gpointer user_data)
ofono_gprs_context_set_ipv4_dns_servers(gc, dns);
- sprintf(buf, "AT+XDATACHANNEL=1,1,\"%s\",\"%s\",2,%u", ctrlpath,
- datapath, gcd->active_context);
+ snprintf(buf, sizeof(buf), "AT+XDATACHANNEL=1,1,\"%s\",\"%s\",2,%u",
+ ctrlpath, datapath, gcd->active_context);
g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
- sprintf(buf, "AT+CGDATA=\"M-RAW_IP\",%u", gcd->active_context);
+ snprintf(buf, sizeof(buf), "AT+CGDATA=\"M-RAW_IP\",%u",
+ gcd->active_context);
if (g_at_chat_send(gcd->chat, buf, none_prefix, cgdata_cb,
gc, NULL) > 0)