2010-01-26 20:13:27 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
2011-10-10 20:39:48 +00:00
|
|
|
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
|
|
|
|
* Copyright (C) 2010 ST-Ericsson AB.
|
2010-01-26 20:13:27 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2010-12-15 21:49:27 +00:00
|
|
|
#include <errno.h>
|
2010-01-26 20:13:27 +00:00
|
|
|
|
2019-05-16 20:10:09 +00:00
|
|
|
#include <ell/ell.h>
|
2010-01-26 20:13:27 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <ofono/log.h>
|
|
|
|
#include <ofono/modem.h>
|
|
|
|
#include <ofono/gprs-context.h>
|
|
|
|
#include <ofono/gprs.h>
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include "gatchat.h"
|
|
|
|
#include "gatresult.h"
|
|
|
|
#include "stemodem.h"
|
|
|
|
#include "caif_socket.h"
|
|
|
|
#include "if_caif.h"
|
2010-12-15 21:49:28 +00:00
|
|
|
#include "caif_rtnl.h"
|
2011-01-14 11:17:21 +00:00
|
|
|
#include "common.h"
|
2010-01-26 20:13:27 +00:00
|
|
|
|
|
|
|
#define MAX_DNS 2
|
2010-11-12 15:02:38 +00:00
|
|
|
#define IP_ADDR_LEN 20
|
2010-01-26 20:13:27 +00:00
|
|
|
|
|
|
|
#define AUTH_BUF_LENGTH (OFONO_GPRS_MAX_USERNAME_LENGTH + \
|
|
|
|
OFONO_GPRS_MAX_PASSWORD_LENGTH + 128)
|
|
|
|
|
|
|
|
static const char *none_prefix[] = { NULL };
|
|
|
|
|
|
|
|
struct gprs_context_data {
|
|
|
|
GAtChat *chat;
|
|
|
|
unsigned int active_context;
|
2010-12-15 21:49:27 +00:00
|
|
|
/* Id used by CAIF and EPPSD to identify the CAIF channel*/
|
2010-01-26 20:13:27 +00:00
|
|
|
unsigned int channel_id;
|
2010-12-15 21:49:27 +00:00
|
|
|
/* Linux Interface Id */
|
|
|
|
unsigned int ifindex;
|
|
|
|
/* Linux Interface name */
|
|
|
|
char interface[IF_NAMESIZE];
|
|
|
|
gboolean created;
|
2010-01-26 20:13:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct eppsd_response {
|
2010-01-27 18:33:11 +00:00
|
|
|
char *current;
|
2010-11-12 15:02:38 +00:00
|
|
|
char ip_address[IP_ADDR_LEN];
|
|
|
|
char subnet_mask[IP_ADDR_LEN];
|
|
|
|
char mtu[IP_ADDR_LEN];
|
|
|
|
char dns_server1[IP_ADDR_LEN];
|
|
|
|
char dns_server2[IP_ADDR_LEN];
|
|
|
|
char p_cscf_server[IP_ADDR_LEN];
|
2010-01-26 20:13:27 +00:00
|
|
|
};
|
|
|
|
|
2010-01-27 18:41:49 +00:00
|
|
|
static void start_element_handler(GMarkupParseContext *context,
|
2010-01-26 20:13:27 +00:00
|
|
|
const gchar *element_name, const gchar **attribute_names,
|
|
|
|
const gchar **attribute_values, gpointer user_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
struct eppsd_response *rsp = user_data;
|
2010-01-27 18:33:11 +00:00
|
|
|
rsp->current = NULL;
|
2010-01-26 20:13:27 +00:00
|
|
|
|
|
|
|
if (!strcmp(element_name, "ip_address"))
|
2010-01-27 18:33:11 +00:00
|
|
|
rsp->current = rsp->ip_address;
|
2010-01-26 20:13:27 +00:00
|
|
|
else if (!strcmp(element_name, "subnet_mask"))
|
2010-01-27 18:33:11 +00:00
|
|
|
rsp->current = rsp->subnet_mask;
|
2010-01-26 20:13:27 +00:00
|
|
|
else if (!strcmp(element_name, "mtu"))
|
2010-01-27 18:33:11 +00:00
|
|
|
rsp->current = rsp->mtu;
|
2010-01-26 20:13:27 +00:00
|
|
|
else if (!strcmp(element_name, "dns_server") &&
|
2010-10-30 17:09:59 +00:00
|
|
|
rsp->dns_server1[0] == '\0')
|
2010-01-27 18:33:11 +00:00
|
|
|
rsp->current = rsp->dns_server1;
|
2010-01-26 20:13:27 +00:00
|
|
|
else if (!strcmp(element_name, "dns_server"))
|
2010-01-27 18:33:11 +00:00
|
|
|
rsp->current = rsp->dns_server2;
|
2010-01-26 20:13:27 +00:00
|
|
|
else if (!strcmp(element_name, "p_cscf_server"))
|
2010-01-27 18:33:11 +00:00
|
|
|
rsp->current = rsp->p_cscf_server;
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-27 18:41:49 +00:00
|
|
|
static void end_element_handler(GMarkupParseContext *context,
|
2010-01-27 18:45:20 +00:00
|
|
|
const gchar *element_name, gpointer user_data,
|
|
|
|
GError **error)
|
2010-01-26 20:13:27 +00:00
|
|
|
{
|
|
|
|
struct eppsd_response *rsp = user_data;
|
2010-01-27 18:33:11 +00:00
|
|
|
rsp->current = NULL;
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-27 18:41:49 +00:00
|
|
|
static void text_handler(GMarkupParseContext *context,
|
2010-01-27 18:45:20 +00:00
|
|
|
const gchar *text, gsize text_len,
|
|
|
|
gpointer user_data, GError **error)
|
2010-01-26 20:13:27 +00:00
|
|
|
{
|
|
|
|
struct eppsd_response *rsp = user_data;
|
|
|
|
|
2010-01-27 18:33:11 +00:00
|
|
|
if (rsp->current) {
|
2010-11-12 15:02:38 +00:00
|
|
|
strncpy(rsp->current, text, IP_ADDR_LEN);
|
2010-12-15 21:49:27 +00:00
|
|
|
rsp->current[IP_ADDR_LEN] = '\0';
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-27 18:41:49 +00:00
|
|
|
static void error_handler(GMarkupParseContext *context,
|
2010-01-27 18:45:20 +00:00
|
|
|
GError *error, gpointer user_data)
|
2010-01-26 20:13:27 +00:00
|
|
|
{
|
2010-11-25 10:51:03 +00:00
|
|
|
DBG("Error parsing xml response from eppsd: %s",
|
2010-01-26 20:13:27 +00:00
|
|
|
error->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GMarkupParser parser = {
|
|
|
|
start_element_handler,
|
|
|
|
end_element_handler,
|
|
|
|
text_handler,
|
|
|
|
NULL,
|
|
|
|
error_handler
|
|
|
|
};
|
|
|
|
|
2010-12-15 21:49:28 +00:00
|
|
|
static void rtnl_callback(int ifindex, const char *ifname, void *user_data)
|
2010-01-26 20:13:27 +00:00
|
|
|
{
|
2011-02-21 11:59:11 +00:00
|
|
|
struct gprs_context_data *gcd = user_data;
|
2010-12-15 21:49:28 +00:00
|
|
|
|
|
|
|
if (ifindex < 0) {
|
2011-02-21 11:59:11 +00:00
|
|
|
gcd->created = FALSE;
|
|
|
|
ofono_error("Failed to create caif interface");
|
2010-12-15 21:49:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-16 20:10:09 +00:00
|
|
|
l_strlcpy(gcd->interface, ifname, sizeof(gcd->interface));
|
2011-02-21 11:59:11 +00:00
|
|
|
gcd->ifindex = ifindex;
|
|
|
|
gcd->created = TRUE;
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-27 18:45:20 +00:00
|
|
|
static void ste_eppsd_down_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
2010-01-26 20:13:27 +00:00
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
ofono_gprs_context_cb_t cb = cbd->cb;
|
|
|
|
struct ofono_gprs_context *gc = cbd->user;
|
|
|
|
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
|
|
|
|
|
2010-11-12 15:02:38 +00:00
|
|
|
if (!ok) {
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
return;
|
|
|
|
}
|
2010-01-26 20:13:27 +00:00
|
|
|
|
2011-02-21 11:59:11 +00:00
|
|
|
gcd->active_context = 0;
|
2010-12-15 21:49:27 +00:00
|
|
|
CALLBACK_WITH_SUCCESS(cb, cbd->data);
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ste_eppsd_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
2011-03-07 14:02:38 +00:00
|
|
|
ofono_gprs_context_cb_t cb = cbd->cb;
|
2010-01-26 20:13:27 +00:00
|
|
|
struct ofono_gprs_context *gc = cbd->user;
|
|
|
|
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
|
|
|
|
GAtResultIter iter;
|
|
|
|
int i;
|
|
|
|
gsize length;
|
2010-11-12 15:02:38 +00:00
|
|
|
const char *res_string;
|
2010-01-26 20:13:27 +00:00
|
|
|
const char *dns[MAX_DNS + 1];
|
|
|
|
struct eppsd_response rsp;
|
2010-12-15 21:49:27 +00:00
|
|
|
GMarkupParseContext *context;
|
2010-01-26 20:13:27 +00:00
|
|
|
|
2010-11-12 15:02:38 +00:00
|
|
|
if (!ok) {
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
gcd->active_context = 0;
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
2011-03-07 14:02:38 +00:00
|
|
|
cb(&error, cbd->data);
|
2010-11-12 15:02:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-26 20:13:27 +00:00
|
|
|
|
2010-01-27 18:33:11 +00:00
|
|
|
rsp.current = NULL;
|
2010-01-26 20:13:27 +00:00
|
|
|
context = g_markup_parse_context_new(&parser, 0, &rsp, NULL);
|
|
|
|
memset(&rsp, 0, sizeof(rsp));
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
2010-01-27 18:45:20 +00:00
|
|
|
|
2010-01-26 20:13:27 +00:00
|
|
|
for (i = 0; i < g_at_result_num_response_lines(result); i++) {
|
|
|
|
g_at_result_iter_next(&iter, NULL);
|
2010-11-12 15:02:38 +00:00
|
|
|
res_string = g_at_result_iter_raw_line(&iter);
|
2010-01-26 20:13:27 +00:00
|
|
|
length = strlen(res_string);
|
|
|
|
|
|
|
|
if (!g_markup_parse_context_parse(context, res_string,
|
2010-01-27 19:46:12 +00:00
|
|
|
length, NULL))
|
|
|
|
goto error;
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_markup_parse_context_end_parse(context, NULL))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
g_markup_parse_context_free(context);
|
|
|
|
|
|
|
|
dns[0] = rsp.dns_server1;
|
|
|
|
dns[1] = rsp.dns_server2;
|
|
|
|
dns[2] = NULL;
|
|
|
|
|
2011-03-07 14:02:38 +00:00
|
|
|
ofono_gprs_context_set_interface(gc, gcd->interface);
|
|
|
|
ofono_gprs_context_set_ipv4_address(gc, rsp.ip_address, TRUE);
|
|
|
|
ofono_gprs_context_set_ipv4_netmask(gc, rsp.subnet_mask);
|
|
|
|
ofono_gprs_context_set_ipv4_dns_servers(gc, dns);
|
|
|
|
|
|
|
|
CALLBACK_WITH_SUCCESS(cb, cbd->data);
|
2010-01-26 20:13:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2011-02-21 11:59:11 +00:00
|
|
|
DBG("ste_eppsd_up_cb error");
|
|
|
|
|
2010-01-26 20:13:27 +00:00
|
|
|
if (context)
|
|
|
|
g_markup_parse_context_free(context);
|
|
|
|
|
2010-12-15 21:49:27 +00:00
|
|
|
gcd->active_context = 0;
|
2011-03-07 14:02:38 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, cbd->data);
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ste_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
2011-03-07 14:02:38 +00:00
|
|
|
ofono_gprs_context_cb_t cb = cbd->cb;
|
2010-01-26 20:13:27 +00:00
|
|
|
struct ofono_gprs_context *gc = cbd->user;
|
|
|
|
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
|
2010-12-15 21:49:27 +00:00
|
|
|
struct cb_data *ncbd;
|
2010-01-27 19:56:44 +00:00
|
|
|
char buf[128];
|
2010-12-15 21:49:27 +00:00
|
|
|
|
2010-01-26 20:13:27 +00:00
|
|
|
if (!ok) {
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
gcd->active_context = 0;
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
2011-03-07 14:02:38 +00:00
|
|
|
cb(&error, cbd->data);
|
2010-01-26 20:13:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-21 11:59:11 +00:00
|
|
|
snprintf(buf, sizeof(buf), "AT*EPPSD=1,%x,%u",
|
|
|
|
gcd->channel_id, gcd->active_context);
|
|
|
|
|
2010-12-15 21:49:27 +00:00
|
|
|
ncbd = g_memdup(cbd, sizeof(struct cb_data));
|
2010-01-26 20:13:27 +00:00
|
|
|
|
|
|
|
if (g_at_chat_send(gcd->chat, buf, NULL,
|
|
|
|
ste_eppsd_up_cb, ncbd, g_free) > 0)
|
|
|
|
return;
|
2010-01-27 19:56:44 +00:00
|
|
|
|
2010-08-16 20:11:21 +00:00
|
|
|
g_free(ncbd);
|
2010-01-26 20:13:27 +00:00
|
|
|
gcd->active_context = 0;
|
2011-03-07 14:02:38 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, cbd->data);
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ste_gprs_activate_primary(struct ofono_gprs_context *gc,
|
|
|
|
const struct ofono_gprs_primary_context *ctx,
|
2011-03-07 14:02:38 +00:00
|
|
|
ofono_gprs_context_cb_t cb, void *data)
|
2010-01-26 20:13:27 +00:00
|
|
|
{
|
|
|
|
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
2010-01-27 19:56:44 +00:00
|
|
|
char buf[AUTH_BUF_LENGTH];
|
2010-01-26 20:13:27 +00:00
|
|
|
|
2011-03-07 14:02:38 +00:00
|
|
|
/* IPv6 support not implemented */
|
|
|
|
if (ctx->proto != OFONO_GPRS_PROTO_IP)
|
|
|
|
goto error;
|
|
|
|
|
2010-01-26 20:13:27 +00:00
|
|
|
gcd->active_context = ctx->cid;
|
|
|
|
cbd->user = gc;
|
|
|
|
|
2011-02-21 11:59:11 +00:00
|
|
|
if (!gcd->created) {
|
2010-12-15 21:49:27 +00:00
|
|
|
DBG("CAIF interface not created (rtnl error?)");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2019-04-29 19:09:11 +00:00
|
|
|
snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IP\",\"%s\"",
|
|
|
|
ctx->cid, ctx->apn);
|
2010-01-26 20:13:27 +00:00
|
|
|
|
|
|
|
if (g_at_chat_send(gcd->chat, buf, none_prefix,
|
2010-02-05 18:20:45 +00:00
|
|
|
ste_cgdcont_cb, cbd, g_free) == 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set username and password, this should be done after CGDCONT
|
|
|
|
* or an error can occur. We don't bother with error checking
|
|
|
|
* here
|
2010-11-12 15:02:38 +00:00
|
|
|
*/
|
2010-02-05 18:20:45 +00:00
|
|
|
snprintf(buf, sizeof(buf), "AT*EIAAUW=%d,1,\"%s\",\"%s\"",
|
|
|
|
ctx->cid, ctx->username, ctx->password);
|
|
|
|
|
|
|
|
g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
return;
|
2010-01-27 18:45:20 +00:00
|
|
|
|
2010-01-26 20:13:27 +00:00
|
|
|
error:
|
2010-11-12 15:02:38 +00:00
|
|
|
gcd->active_context = 0;
|
2010-08-16 20:11:21 +00:00
|
|
|
g_free(cbd);
|
2010-01-26 20:13:27 +00:00
|
|
|
|
2011-03-07 14:02:38 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ste_gprs_deactivate_primary(struct ofono_gprs_context *gc,
|
|
|
|
unsigned int id,
|
|
|
|
ofono_gprs_context_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
cbd->user = gc;
|
|
|
|
|
2011-02-21 11:59:11 +00:00
|
|
|
snprintf(buf, sizeof(buf), "AT*EPPSD=0,%x,%u", gcd->channel_id, id);
|
2010-01-26 20:13:27 +00:00
|
|
|
|
|
|
|
if (g_at_chat_send(gcd->chat, buf, none_prefix,
|
|
|
|
ste_eppsd_down_cb, cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
2010-08-16 20:11:21 +00:00
|
|
|
g_free(cbd);
|
2010-01-26 20:13:27 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cgev_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_gprs_context *gc = user_data;
|
|
|
|
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
|
|
|
|
GAtResultIter iter;
|
|
|
|
const char *event;
|
2011-02-21 11:59:11 +00:00
|
|
|
int cid;
|
2010-01-26 20:13:27 +00:00
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CGEV:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_unquoted_string(&iter, &event))
|
|
|
|
return;
|
|
|
|
|
2011-02-21 11:59:11 +00:00
|
|
|
if (g_str_has_prefix(event, "NW DEACT") == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_skip_next(&iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &cid))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((unsigned int) cid != gcd->active_context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ofono_gprs_context_deactivated(gc, gcd->active_context);
|
|
|
|
gcd->active_context = 0;
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ste_gprs_context_probe(struct ofono_gprs_context *gc,
|
|
|
|
unsigned int vendor, void *data)
|
|
|
|
{
|
|
|
|
GAtChat *chat = data;
|
|
|
|
struct gprs_context_data *gcd;
|
2011-02-21 11:59:11 +00:00
|
|
|
int err;
|
2010-01-26 20:13:27 +00:00
|
|
|
|
|
|
|
gcd = g_new0(struct gprs_context_data, 1);
|
2010-08-13 04:44:07 +00:00
|
|
|
gcd->chat = g_at_chat_clone(chat);
|
2010-01-26 20:13:27 +00:00
|
|
|
|
|
|
|
g_at_chat_register(gcd->chat, "+CGEV:", cgev_notify, FALSE, gc, NULL);
|
|
|
|
|
2011-02-21 11:59:11 +00:00
|
|
|
/* Need a unique channel id */
|
|
|
|
gcd->channel_id = (unsigned int)(unsigned long)gc;
|
|
|
|
|
2010-01-26 20:13:27 +00:00
|
|
|
ofono_gprs_context_set_data(gc, gcd);
|
|
|
|
|
2011-02-21 11:59:11 +00:00
|
|
|
err = caif_rtnl_create_interface(IFLA_CAIF_IPV4_CONNID,
|
|
|
|
gcd->channel_id, FALSE,
|
|
|
|
rtnl_callback, gcd);
|
|
|
|
if (err < 0) {
|
|
|
|
DBG("Failed to create IP interface for CAIF");
|
|
|
|
return err;
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ste_gprs_context_remove(struct ofono_gprs_context *gc)
|
|
|
|
{
|
|
|
|
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
|
|
|
|
|
2011-02-21 11:59:11 +00:00
|
|
|
/*
|
|
|
|
* Removes IP interface for CAIF.
|
|
|
|
*/
|
|
|
|
if (!gcd->created)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (caif_rtnl_delete_interface(gcd->ifindex) < 0) {
|
|
|
|
ofono_error("Failed to delete caif interface %s",
|
|
|
|
gcd->interface);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG("removed CAIF interface ch:%d ifname:%s ifindex:%d\n",
|
|
|
|
gcd->channel_id, gcd->interface, gcd->ifindex);
|
2010-01-26 20:13:27 +00:00
|
|
|
|
2011-02-21 11:59:11 +00:00
|
|
|
out:
|
2010-01-26 20:13:27 +00:00
|
|
|
ofono_gprs_context_set_data(gc, NULL);
|
2010-08-13 04:44:07 +00:00
|
|
|
|
|
|
|
g_at_chat_unref(gcd->chat);
|
2010-01-26 20:13:27 +00:00
|
|
|
g_free(gcd);
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:36:10 +00:00
|
|
|
static const struct ofono_gprs_context_driver driver = {
|
2010-01-26 20:13:27 +00:00
|
|
|
.name = "stemodem",
|
|
|
|
.probe = ste_gprs_context_probe,
|
|
|
|
.remove = ste_gprs_context_remove,
|
|
|
|
.activate_primary = ste_gprs_activate_primary,
|
|
|
|
.deactivate_primary = ste_gprs_deactivate_primary,
|
|
|
|
};
|
|
|
|
|
2011-01-12 10:52:09 +00:00
|
|
|
void ste_gprs_context_init(void)
|
2010-01-26 20:13:27 +00:00
|
|
|
{
|
2010-12-15 21:49:28 +00:00
|
|
|
caif_rtnl_init();
|
2010-01-26 20:13:27 +00:00
|
|
|
ofono_gprs_context_driver_register(&driver);
|
|
|
|
}
|
|
|
|
|
2011-01-12 10:52:09 +00:00
|
|
|
void ste_gprs_context_exit(void)
|
2010-01-26 20:13:27 +00:00
|
|
|
{
|
|
|
|
ofono_gprs_context_driver_unregister(&driver);
|
2010-12-15 21:49:28 +00:00
|
|
|
caif_rtnl_exit();
|
2010-01-26 20:13:27 +00:00
|
|
|
}
|