mirror of git://git.sysmocom.de/ofono
Parse and use Address and Port options from modem.conf
This commit is contained in:
parent
a05c9f173d
commit
9b3a8183f3
|
@ -24,6 +24,7 @@
|
|||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
|
@ -34,6 +35,28 @@
|
|||
|
||||
static GSList *modem_list = NULL;
|
||||
|
||||
static int set_address(struct ofono_modem *modem,
|
||||
GKeyFile *keyfile, const char *group)
|
||||
{
|
||||
char *address, *port;
|
||||
|
||||
address = g_key_file_get_string(keyfile, group, "Address", NULL);
|
||||
if (address) {
|
||||
ofono_modem_set_string(modem, "Address", address);
|
||||
g_free(address);
|
||||
} else
|
||||
ofono_modem_set_string(modem, "Address", "127.0.0.1");
|
||||
|
||||
port = g_key_file_get_string(keyfile, group, "Port", NULL);
|
||||
if (port) {
|
||||
ofono_modem_set_integer(modem, "Port", atoi(port));
|
||||
g_free(port);
|
||||
} else
|
||||
ofono_modem_set_integer(modem, "Port", 12345);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_device(struct ofono_modem *modem,
|
||||
GKeyFile *keyfile, const char *group)
|
||||
{
|
||||
|
@ -61,6 +84,9 @@ static struct ofono_modem *create_modem(GKeyFile *keyfile, const char *group)
|
|||
|
||||
modem = ofono_modem_create(driver);
|
||||
|
||||
if (!g_strcmp0(driver, "phonesim"))
|
||||
set_address(modem, keyfile, group);
|
||||
|
||||
if (!g_strcmp0(driver, "g1") || !g_strcmp0(driver, "mbm"))
|
||||
set_device(modem, keyfile, group);
|
||||
|
||||
|
|
|
@ -72,18 +72,27 @@ static int phonesim_enable(struct ofono_modem *modem)
|
|||
GAtChat *chat;
|
||||
GAtSyntax *syntax;
|
||||
struct sockaddr_in addr;
|
||||
int sk, err;
|
||||
const char *address;
|
||||
int sk, err, port;
|
||||
|
||||
DBG("%p", modem);
|
||||
|
||||
address = ofono_modem_get_string(modem, "Address");
|
||||
if (!address)
|
||||
return -EINVAL;
|
||||
|
||||
port = ofono_modem_get_integer(modem, "Port");
|
||||
if (port < 0)
|
||||
return -EINVAL;
|
||||
|
||||
sk = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (sk < 0)
|
||||
return -EINVAL;
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
addr.sin_port = htons(12345);
|
||||
addr.sin_addr.s_addr = inet_addr(address);
|
||||
addr.sin_port = htons(port);
|
||||
|
||||
err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
|
||||
if (err < 0) {
|
||||
|
|
Loading…
Reference in New Issue