* [PATCH 1/4] gprs: Add 'stk' gprs context type
2011-05-04 17:26 [PATCH 0/4] Introduce new gprs APIs to setup STK PDP context Philippe Nunes
@ 2011-05-04 17:26 ` Philippe Nunes
2011-05-04 17:26 ` [PATCH 2/4] gprs: Add new external APIs to create, activate and remove a PDP context Philippe Nunes
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Philippe Nunes @ 2011-05-04 17:26 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1405 bytes --]
---
include/gprs-context.h | 1 +
src/gprs.c | 7 +++++++
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/include/gprs-context.h b/include/gprs-context.h
index f82fcaa..e7976a1 100644
--- a/include/gprs-context.h
+++ b/include/gprs-context.h
@@ -46,6 +46,7 @@ enum ofono_gprs_context_type {
OFONO_GPRS_CONTEXT_TYPE_MMS,
OFONO_GPRS_CONTEXT_TYPE_WAP,
OFONO_GPRS_CONTEXT_TYPE_IMS,
+ OFONO_GPRS_CONTEXT_TYPE_STK,
};
struct ofono_gprs_primary_context {
diff --git a/src/gprs.c b/src/gprs.c
index deffeb8..9657a3e 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -188,6 +188,8 @@ static const char *gprs_context_default_name(enum ofono_gprs_context_type type)
return "WAP";
case OFONO_GPRS_CONTEXT_TYPE_IMS:
return "IMS";
+ case OFONO_GPRS_CONTEXT_TYPE_STK:
+ return "STK";
}
return NULL;
@@ -207,6 +209,8 @@ static const char *gprs_context_type_to_string(
return "wap";
case OFONO_GPRS_CONTEXT_TYPE_IMS:
return "ims";
+ case OFONO_GPRS_CONTEXT_TYPE_STK:
+ return "stk";
}
return NULL;
@@ -227,6 +231,9 @@ static gboolean gprs_context_string_to_type(const char *str,
} else if (g_str_equal(str, "ims")) {
*out = OFONO_GPRS_CONTEXT_TYPE_IMS;
return TRUE;
+ } else if (g_str_equal(str, "stk")) {
+ *out = OFONO_GPRS_CONTEXT_TYPE_STK;
+ return TRUE;
}
return FALSE;
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/4] gprs: Add new external APIs to create, activate and remove a PDP context
2011-05-04 17:26 [PATCH 0/4] Introduce new gprs APIs to setup STK PDP context Philippe Nunes
2011-05-04 17:26 ` [PATCH 1/4] gprs: Add 'stk' gprs context type Philippe Nunes
@ 2011-05-04 17:26 ` Philippe Nunes
2011-05-05 3:42 ` Denis Kenzior
2011-05-04 17:26 ` [PATCH 3/4] stk: Use gprs APIs to create, activate and remove a dedicated " Philippe Nunes
2011-05-04 17:26 ` [PATCH 4/4] gprs: Add a host route for STK context type Philippe Nunes
3 siblings, 1 reply; 8+ messages in thread
From: Philippe Nunes @ 2011-05-04 17:26 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 9493 bytes --]
---
include/gprs.h | 16 ++++
src/gprs.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 246 insertions(+), 4 deletions(-)
diff --git a/include/gprs.h b/include/gprs.h
index 157a6f9..0bb37f7 100644
--- a/include/gprs.h
+++ b/include/gprs.h
@@ -36,6 +36,10 @@ typedef void (*ofono_gprs_status_cb_t)(const struct ofono_error *error,
typedef void (*ofono_gprs_cb_t)(const struct ofono_error *error, void *data);
+typedef void (*ofono_gprs_add_pdp_context_cb_t)(int error, char *interface,
+ char *ipv4, char *ipv6,
+ void *data);
+
struct ofono_gprs_driver {
const char *name;
int (*probe)(struct ofono_gprs *gprs, unsigned int vendor,
@@ -77,7 +81,19 @@ void ofono_gprs_set_cid_range(struct ofono_gprs *gprs,
unsigned int min, unsigned int max);
void ofono_gprs_add_context(struct ofono_gprs *gprs,
struct ofono_gprs_context *gc);
+unsigned int ofono_gprs_add_pdp_context(struct ofono_gprs *gprs,
+ const char *type,
+ const char *protocol,
+ const char *apn,
+ const char *username,
+ const char *password,
+ const char *host);
+
+int ofono_gprs_remove_pdp_context(struct ofono_gprs *gprs, unsigned int id);
+int ofono_gprs_activate_pdp_context(struct ofono_gprs *gprs, unsigned int id,
+ ofono_gprs_add_pdp_context_cb_t cb,
+ void *data);
#ifdef __cplusplus
}
#endif
diff --git a/src/gprs.c b/src/gprs.c
index 9657a3e..2b88324 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -147,6 +147,8 @@ struct pri_context {
struct ofono_gprs_primary_context context;
struct ofono_gprs_context *context_driver;
struct ofono_gprs *gprs;
+ void *notify;
+ void *notify_data;
};
static void gprs_netreg_update(struct ofono_gprs *gprs);
@@ -356,6 +358,35 @@ static struct pri_context *gprs_context_by_path(struct ofono_gprs *gprs,
return NULL;
}
+static struct pri_context *gprs_context_by_id(struct ofono_gprs *gprs,
+ unsigned int id)
+{
+ GSList *l;
+
+ for (l = gprs->contexts; l; l = l->next) {
+ struct pri_context *ctx = l->data;
+
+ if (ctx->id == id)
+ return ctx;
+ }
+
+ return NULL;
+}
+
+static struct pri_context *gprs_get_default_context(struct ofono_gprs *gprs)
+{
+ GSList *l;
+
+ for (l = gprs->contexts; l; l = l->next) {
+ struct pri_context *ctx = l->data;
+
+ if (ctx->type == OFONO_GPRS_CONTEXT_TYPE_INTERNET)
+ return ctx;
+ }
+
+ return NULL;
+}
+
static void context_settings_free(struct context_settings *settings)
{
if (settings->ipv4) {
@@ -870,15 +901,21 @@ static void pri_activate_callback(const struct ofono_error *error, void *data)
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
DBG("Activating context failed with error: %s",
telephony_error_to_str(error));
- __ofono_dbus_pending_reply(&ctx->pending,
+ if (ctx->pending)
+ __ofono_dbus_pending_reply(&ctx->pending,
__ofono_error_failed(ctx->pending));
context_settings_free(ctx->context_driver->settings);
release_context(ctx);
+
+ if (ctx->notify)
+ ((ofono_gprs_add_pdp_context_cb_t) ctx->notify)
+ (-ENOSYS, NULL, NULL, NULL, ctx->notify_data);
return;
}
ctx->active = TRUE;
- __ofono_dbus_pending_reply(&ctx->pending,
+ if (ctx->pending)
+ __ofono_dbus_pending_reply(&ctx->pending,
dbus_message_new_method_return(ctx->pending));
if (gc->settings->interface != NULL) {
@@ -896,6 +933,20 @@ static void pri_activate_callback(const struct ofono_error *error, void *data)
ofono_dbus_signal_property_changed(conn, ctx->path,
OFONO_CONNECTION_CONTEXT_INTERFACE,
"Active", DBUS_TYPE_BOOLEAN, &value);
+
+ if (ctx->notify) {
+ char *ipv4 = NULL;
+ char *ipv6 = NULL;
+
+ if (gc->settings->ipv4)
+ ipv4 = gc->settings->ipv4->ip;
+ else if (gc->settings->ipv6)
+ ipv6 = gc->settings->ipv6->ip;
+
+ ((ofono_gprs_add_pdp_context_cb_t) ctx->notify)
+ (0, gc->settings->interface, ipv4, ipv6,
+ ctx->notify_data);
+ }
}
static void pri_deactivate_callback(const struct ofono_error *error, void *data)
@@ -1844,7 +1895,8 @@ static void gprs_deactivate_for_remove(const struct ofono_error *error,
DBG("Removing context failed with error: %s",
telephony_error_to_str(error));
- __ofono_dbus_pending_reply(&gprs->pending,
+ if (gprs->pending)
+ __ofono_dbus_pending_reply(&gprs->pending,
__ofono_error_failed(gprs->pending));
return;
}
@@ -1863,7 +1915,8 @@ static void gprs_deactivate_for_remove(const struct ofono_error *error,
context_dbus_unregister(ctx);
gprs->contexts = g_slist_remove(gprs->contexts, ctx);
- __ofono_dbus_pending_reply(&gprs->pending,
+ if (gprs->pending)
+ __ofono_dbus_pending_reply(&gprs->pending,
dbus_message_new_method_return(gprs->pending));
atompath = __ofono_atom_get_path(gprs->atom);
@@ -2968,3 +3021,176 @@ void *ofono_gprs_get_data(struct ofono_gprs *gprs)
{
return gprs->driver_data;
}
+
+unsigned int ofono_gprs_add_pdp_context(struct ofono_gprs *gprs,
+ const char *type,
+ const char *protocol,
+ const char *apn,
+ const char *username,
+ const char *password,
+ const char *host)
+{
+ unsigned int id;
+ struct pri_context *context;
+ struct pri_context *default_ctx = NULL;
+ const char *name;
+ enum ofono_gprs_proto proto;
+ enum ofono_gprs_context_type context_type;
+
+ /* Sanity check */
+ if (apn && strlen(apn) > OFONO_GPRS_MAX_APN_LENGTH)
+ return 0;
+
+ if (username && strlen(username) > OFONO_GPRS_MAX_USERNAME_LENGTH)
+ return 0;
+
+ if (password && strlen(password) > OFONO_GPRS_MAX_PASSWORD_LENGTH)
+ return 0;
+
+ if (apn == NULL || (username == NULL && password == NULL)) {
+ /* take the default primary internet context */
+ default_ctx = gprs_get_default_context(gprs);
+
+ if (default_ctx == NULL && apn == NULL)
+ return 0;
+ }
+
+ if (apn && is_valid_apn(apn) == FALSE)
+ return 0;
+
+ if (gprs_proto_from_string(protocol, &proto) == FALSE)
+ return 0;
+
+ if (gprs_context_string_to_type(type, &context_type) == FALSE)
+ return 0;
+
+ name = gprs_context_default_name(context_type);
+ if (name == NULL)
+ return 0;
+
+ if (gprs->last_context_id)
+ id = idmap_alloc_next(gprs->pid_map, gprs->last_context_id);
+ else
+ id = idmap_alloc(gprs->pid_map);
+
+ if (id > idmap_get_max(gprs->pid_map))
+ return 0;
+
+ context = pri_context_create(gprs, name, context_type);
+ if (context == NULL) {
+ idmap_put(gprs->pid_map, id);
+ return 0;
+ }
+
+ context->id = id;
+
+ if (username != NULL)
+ strcpy(context->context.username, username);
+
+ if (password != NULL)
+ strcpy(context->context.password, password);
+
+ if (username == NULL && password == NULL && default_ctx) {
+ if (default_ctx->context.username)
+ strcpy(context->context.username,
+ default_ctx->context.username);
+ if (default_ctx->context.password)
+ strcpy(context->context.password,
+ default_ctx->context.password);
+ }
+
+ if (apn)
+ strcpy(context->context.apn, apn);
+ else if (default_ctx) {
+ strcpy(context->context.apn, default_ctx->context.apn);
+ if (default_ctx->context.username)
+ strcpy(context->context.username,
+ default_ctx->context.username);
+ if (default_ctx->context.password)
+ strcpy(context->context.password,
+ default_ctx->context.password);
+ }
+
+ context->context.proto = proto;
+
+ if (context_dbus_register(context) == FALSE)
+ return 0;
+
+ gprs->last_context_id = id;
+
+ if (gprs->settings) {
+ write_context_settings(gprs, context);
+ storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
+ }
+
+ gprs->contexts = g_slist_append(gprs->contexts, context);
+
+ return id;
+}
+
+int ofono_gprs_activate_pdp_context(struct ofono_gprs *gprs, unsigned int id,
+ ofono_gprs_add_pdp_context_cb_t cb,
+ void *data)
+{
+ struct pri_context *ctx;
+ struct ofono_gprs_context *gc;
+
+ ctx = gprs_context_by_id(gprs, id);
+ if (ctx == NULL)
+ return -EINVAL;
+
+ if (ctx->active == TRUE)
+ return 0;
+
+ if (assign_context(ctx) == FALSE)
+ return -ENOSYS;
+
+ gc = ctx->context_driver;
+
+ ctx->notify = cb;
+ ctx->notify_data = data;
+
+ gc->driver->activate_primary(gc, &ctx->context, pri_activate_callback,
+ ctx);
+ return 0;
+}
+
+int ofono_gprs_remove_pdp_context(struct ofono_gprs *gprs, unsigned int id)
+{
+ struct pri_context *ctx;
+ DBusConnection *conn;
+ char *path;
+ const char *atompath;
+
+ ctx = gprs_context_by_id(gprs, id);
+ if (ctx == NULL)
+ return -EINVAL;
+
+ if (ctx->active) {
+ struct ofono_gprs_context *gc = ctx->context_driver;
+
+ gc->driver->deactivate_primary(gc, ctx->context.cid,
+ gprs_deactivate_for_remove, ctx);
+ return 0;
+ }
+
+ if (gprs->settings) {
+ g_key_file_remove_group(gprs->settings, ctx->key, NULL);
+ storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
+ }
+
+ path = g_strdup(ctx->path);
+
+ DBG("Unregistering context: %s", ctx->path);
+ context_dbus_unregister(ctx);
+ gprs->contexts = g_slist_remove(gprs->contexts, ctx);
+
+ atompath = __ofono_atom_get_path(gprs->atom);
+ conn = ofono_dbus_get_connection();
+ g_dbus_emit_signal(conn, atompath, OFONO_CONNECTION_MANAGER_INTERFACE,
+ "ContextRemoved", DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+ g_free(path);
+
+ return 0;
+}
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/4] gprs: Add new external APIs to create, activate and remove a PDP context
2011-05-04 17:26 ` [PATCH 2/4] gprs: Add new external APIs to create, activate and remove a PDP context Philippe Nunes
@ 2011-05-05 3:42 ` Denis Kenzior
2011-05-05 16:38 ` Philippe Nunes
0 siblings, 1 reply; 8+ messages in thread
From: Denis Kenzior @ 2011-05-05 3:42 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1794 bytes --]
Hi Philippe,
On 05/04/2011 12:26 PM, Philippe Nunes wrote:
> ---
> include/gprs.h | 16 ++++
> src/gprs.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 246 insertions(+), 4 deletions(-)
>
> diff --git a/include/gprs.h b/include/gprs.h
> index 157a6f9..0bb37f7 100644
> --- a/include/gprs.h
> +++ b/include/gprs.h
> @@ -36,6 +36,10 @@ typedef void (*ofono_gprs_status_cb_t)(const struct ofono_error *error,
>
> typedef void (*ofono_gprs_cb_t)(const struct ofono_error *error, void *data);
>
> +typedef void (*ofono_gprs_add_pdp_context_cb_t)(int error, char *interface,
> + char *ipv4, char *ipv6,
> + void *data);
> +
> struct ofono_gprs_driver {
> const char *name;
> int (*probe)(struct ofono_gprs *gprs, unsigned int vendor,
> @@ -77,7 +81,19 @@ void ofono_gprs_set_cid_range(struct ofono_gprs *gprs,
> unsigned int min, unsigned int max);
> void ofono_gprs_add_context(struct ofono_gprs *gprs,
> struct ofono_gprs_context *gc);
> +unsigned int ofono_gprs_add_pdp_context(struct ofono_gprs *gprs,
> + const char *type,
> + const char *protocol,
> + const char *apn,
> + const char *username,
> + const char *password,
> + const char *host);
> +
> +int ofono_gprs_remove_pdp_context(struct ofono_gprs *gprs, unsigned int id);
>
> +int ofono_gprs_activate_pdp_context(struct ofono_gprs *gprs, unsigned int id,
> + ofono_gprs_add_pdp_context_cb_t cb,
> + void *data);
Why do you want to expose STK activated contexts over D-Bus and try to
deal with the consequences of this decision? Having oFono handle them
completely internally would simplify the design quite a bit, no?
Regards,
-Denis
> #ifdef __cplusplus
> }
> #endif
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/4] gprs: Add new external APIs to create, activate and remove a PDP context
2011-05-05 3:42 ` Denis Kenzior
@ 2011-05-05 16:38 ` Philippe Nunes
2011-05-05 10:47 ` Denis Kenzior
0 siblings, 1 reply; 8+ messages in thread
From: Philippe Nunes @ 2011-05-05 16:38 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2908 bytes --]
Hi Denis,
On 05/05/2011 05:42 AM, Denis Kenzior wrote:
> Hi Philippe,
>
> On 05/04/2011 12:26 PM, Philippe Nunes wrote:
>> ---
>> include/gprs.h | 16 ++++
>> src/gprs.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>> 2 files changed, 246 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/gprs.h b/include/gprs.h
>> index 157a6f9..0bb37f7 100644
>> --- a/include/gprs.h
>> +++ b/include/gprs.h
>> @@ -36,6 +36,10 @@ typedef void (*ofono_gprs_status_cb_t)(const struct ofono_error *error,
>>
>> typedef void (*ofono_gprs_cb_t)(const struct ofono_error *error, void *data);
>>
>> +typedef void (*ofono_gprs_add_pdp_context_cb_t)(int error, char *interface,
>> + char *ipv4, char *ipv6,
>> + void *data);
>> +
>> struct ofono_gprs_driver {
>> const char *name;
>> int (*probe)(struct ofono_gprs *gprs, unsigned int vendor,
>> @@ -77,7 +81,19 @@ void ofono_gprs_set_cid_range(struct ofono_gprs *gprs,
>> unsigned int min, unsigned int max);
>> void ofono_gprs_add_context(struct ofono_gprs *gprs,
>> struct ofono_gprs_context *gc);
>> +unsigned int ofono_gprs_add_pdp_context(struct ofono_gprs *gprs,
>> + const char *type,
>> + const char *protocol,
>> + const char *apn,
>> + const char *username,
>> + const char *password,
>> + const char *host);
>> +
>> +int ofono_gprs_remove_pdp_context(struct ofono_gprs *gprs, unsigned int id);
>>
>> +int ofono_gprs_activate_pdp_context(struct ofono_gprs *gprs, unsigned int id,
>> + ofono_gprs_add_pdp_context_cb_t cb,
>> + void *data);
>
> Why do you want to expose STK activated contexts over D-Bus and try to
> deal with the consequences of this decision? Having oFono handle them
> completely internally would simplify the design quite a bit, no?
Yes, indeed. I thought that the PDP context created by and for oFono
should be however visible from outside. But I agree,
STK PDP context should not be handled from outside. So, I will remove
the D-BUS interface registration for this kind of context.
Should I also consider to not add this context to the gprs->contexts list?
As you can see, I'm using a callback to notify the STK atom when the
context is activated. Since the context is no more subject to D-BUS
handling, do you think I could map this callback directly as the
callback for the gprs_context driver (id
ofono_stk_activate_pdp_context_cb = ofono_gprs_context_cb_t)?
It implies that I need to setup the interface directly in the STK atom
but so far, I don't know if you agree with the modifications I did in
gprs.c regarding how this interface is updated when this is linked to a
STK PDP context (particularly for the host route).
Perhaps, even if it duplicates some code, you would prefer to see the
STK atom updating the interface directly?
Regards
Philippe.
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/4] gprs: Add new external APIs to create, activate and remove a PDP context
2011-05-05 16:38 ` Philippe Nunes
@ 2011-05-05 10:47 ` Denis Kenzior
0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2011-05-05 10:47 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1559 bytes --]
Hi Philippe,
>> Why do you want to expose STK activated contexts over D-Bus and try to
>> deal with the consequences of this decision? Having oFono handle them
>> completely internally would simplify the design quite a bit, no?
>
> Yes, indeed. I thought that the PDP context created by and for oFono
> should be however visible from outside. But I agree,
> STK PDP context should not be handled from outside. So, I will remove
> the D-BUS interface registration for this kind of context.
>
> Should I also consider to not add this context to the gprs->contexts list?
I don't know yet ;)
>
> As you can see, I'm using a callback to notify the STK atom when the
> context is activated. Since the context is no more subject to D-BUS
> handling, do you think I could map this callback directly as the
> callback for the gprs_context driver (id
> ofono_stk_activate_pdp_context_cb = ofono_gprs_context_cb_t)?
>
> It implies that I need to setup the interface directly in the STK atom
> but so far, I don't know if you agree with the modifications I did in
> gprs.c regarding how this interface is updated when this is linked to a
> STK PDP context (particularly for the host route).
> Perhaps, even if it duplicates some code, you would prefer to see the
> STK atom updating the interface directly?
Do not do that. I suggest you look into how STK Send SMS is implemented
and model this somewhat after that. GPRS atom needs to manage the
contexts and provide private API for activating 'hidden' ones.
Regards,
-Denis
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/4] stk: Use gprs APIs to create, activate and remove a dedicated PDP context
2011-05-04 17:26 [PATCH 0/4] Introduce new gprs APIs to setup STK PDP context Philippe Nunes
2011-05-04 17:26 ` [PATCH 1/4] gprs: Add 'stk' gprs context type Philippe Nunes
2011-05-04 17:26 ` [PATCH 2/4] gprs: Add new external APIs to create, activate and remove a PDP context Philippe Nunes
@ 2011-05-04 17:26 ` Philippe Nunes
2011-05-04 17:26 ` [PATCH 4/4] gprs: Add a host route for STK context type Philippe Nunes
3 siblings, 0 replies; 8+ messages in thread
From: Philippe Nunes @ 2011-05-04 17:26 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 5797 bytes --]
---
src/stk.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 116 insertions(+), 16 deletions(-)
diff --git a/src/stk.c b/src/stk.c
index dec0439..fe74cb5 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -85,6 +85,7 @@ struct ofono_stk {
struct stk_channel_data tx_buffer;
gboolean link_on_demand;
struct ofono_gprs *gprs;
+ struct stk_bearer_description bearer_desc;
};
struct envelope_op {
@@ -489,13 +490,10 @@ static void emit_menu_changed(struct ofono_stk *stk)
static void stk_close_channel(struct ofono_stk *stk)
{
- /*
- * TODO
- * Deactivate and remove PDP context
- * Send the Terminal Response once the PDP context is deactivated
- */
+ int err;
+
+ err = ofono_gprs_remove_pdp_context(stk->gprs, stk->channel.id);
- /* Temporary implementation */
g_free(stk->rx_buffer.data.array);
g_free(stk->tx_buffer.data.array);
stk->rx_buffer.data.array = NULL;
@@ -504,6 +502,9 @@ static void stk_close_channel(struct ofono_stk *stk)
stk->channel.id = 0;
stk->channel.status = STK_CHANNEL_PACKET_DATA_SERVICE_NOT_ACTIVATED;
+ if (err < 0)
+ return;
+
if (stk->pending_cmd &&
stk->pending_cmd->type ==
STK_COMMAND_TYPE_CLOSE_CHANNEL)
@@ -560,12 +561,65 @@ static void stk_alpha_id_unset(struct ofono_stk *stk)
stk_agent_request_cancel(stk->current_agent);
}
+static void ofono_stk_activate_pdp_context_cb(int error, char *interface,
+ char *ipv4, char *ipv6,
+ void *data)
+{
+ struct ofono_stk *stk = data;
+ struct stk_response rsp;
+ struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+
+ DBG("");
+
+ memset(&rsp, 0, sizeof(rsp));
+
+ if (error != 0) {
+ rsp.result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+ goto out;
+ }
+
+ if (stk->pending_cmd == NULL) {
+ /* TODO
+ * send the event channel status
+ * insert local address if dynamic local address is requested
+ * insert bearer description if Open channel in background mode
+ */
+ return;
+ }
+
+ DBG("Interface %s, ipv4 = %s, ipv6 = %s", interface, ipv4, ipv6);
+
+ stk->channel.status = STK_CHANNEL_PACKET_DATA_SERVICE_ACTIVATED;
+
+ if (stk->pending_cmd->type == STK_COMMAND_TYPE_OPEN_CHANNEL) {
+ rsp.open_channel.channel.id = stk->channel.id;
+ rsp.open_channel.channel.status = stk->channel.status;
+ rsp.open_channel.buf_size = stk->rx_buffer.data.len;
+ memcpy(&rsp.open_channel.bearer_desc, &stk->bearer_desc,
+ sizeof(struct stk_bearer_description));
+ } else if (stk->pending_cmd->type == STK_COMMAND_TYPE_SEND_DATA &&
+ stk->link_on_demand) {
+ /*
+ * TODO
+ * send the data immediately, flush the tx buffer
+ */
+ stk->tx_buffer.tx_avail = stk->tx_buffer.data.len;
+ rsp.send_data.tx_avail = stk->tx_buffer.tx_avail;
+ }
+
+out:
+ if (stk_respond(stk, &rsp, stk_command_cb))
+ stk_command_cb(&failure, stk);
+}
static void stk_open_channel(struct ofono_stk *stk)
{
const struct stk_command_open_channel *oc;
struct stk_response rsp;
struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+ char *host = NULL;
+ unsigned int id;
+ int err;
if (stk->pending_cmd == NULL ||
stk->pending_cmd->type != STK_COMMAND_TYPE_OPEN_CHANNEL)
@@ -592,13 +646,52 @@ static void stk_open_channel(struct ofono_stk *stk)
stk->tx_buffer.data.len = oc->buf_size;
stk->link_on_demand = (stk->pending_cmd->qualifier &
STK_OPEN_CHANNEL_FLAG_IMMEDIATE) ? FALSE : TRUE;
-
+ memcpy(&stk->bearer_desc, &oc->bearer_desc,
+ sizeof(struct stk_bearer_description));
/*
- * TODO
* Add a new primary PDP context based on the provided settings
- * Send the Terminal Response or wait until the PDP context is activated
- * in case of immediate link establishment not in background.
+ * According 3GPP TS 31.111, the packet data protocol type is set to 02
+ * '02' = IP (Internet Protocol, IETF STD 5)
*/
+
+ id = ofono_gprs_add_pdp_context(stk->gprs, "stk", "ip", oc->apn,
+ oc->text_usr, oc->text_passwd, host);
+
+ if (id == 0) {
+ rsp.result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+ goto out;
+ }
+
+ stk->channel.id = id;
+
+ if (stk->link_on_demand) {
+ rsp.open_channel.channel.id = id;
+ rsp.open_channel.channel.status =
+ STK_CHANNEL_PACKET_DATA_SERVICE_NOT_ACTIVATED;
+ rsp.open_channel.buf_size = oc->buf_size;
+ goto out;
+ }
+
+ err = ofono_gprs_activate_pdp_context(stk->gprs, id,
+ ofono_stk_activate_pdp_context_cb, stk);
+
+ if (err < 0) {
+ rsp.result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+ goto out;
+ }
+
+ /* In background mode, send the terminal response now */
+ if (stk->pending_cmd->qualifier & STK_OPEN_CHANNEL_FLAG_BACKGROUND) {
+ rsp.open_channel.channel.id = id;
+ rsp.open_channel.channel.status =
+ STK_CHANNEL_PACKET_DATA_SERVICE_NOT_ACTIVATED;
+ rsp.open_channel.buf_size = oc->buf_size;
+ goto out;
+ }
+
+ /* wait for the PDP context activation to send the Terminal Response */
+ return;
+
out:
if (stk_respond(stk, &rsp, stk_command_cb))
stk_command_cb(&failure, stk);
@@ -642,12 +735,19 @@ static void stk_send_data(struct ofono_stk *stk,
if (stk->channel.status == STK_CHANNEL_PACKET_DATA_SERVICE_NOT_ACTIVATED
&& stk->link_on_demand == TRUE) {
- /*
- * TODO
- * activate the context, update the channel status
- * once the context is activated, send the data immediately
- * and flush the tx buffer
- */
+ int err;
+
+ err = ofono_gprs_activate_pdp_context(stk->gprs,
+ stk->channel.id,
+ ofono_stk_activate_pdp_context_cb,
+ stk);
+
+ if (err < 0) {
+ rsp.result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+ goto out;
+ }
+
+ return;
} else {
/*
* TODO
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/4] gprs: Add a host route for STK context type.
2011-05-04 17:26 [PATCH 0/4] Introduce new gprs APIs to setup STK PDP context Philippe Nunes
` (2 preceding siblings ...)
2011-05-04 17:26 ` [PATCH 3/4] stk: Use gprs APIs to create, activate and remove a dedicated " Philippe Nunes
@ 2011-05-04 17:26 ` Philippe Nunes
3 siblings, 0 replies; 8+ messages in thread
From: Philippe Nunes @ 2011-05-04 17:26 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 4715 bytes --]
---
src/gprs.c | 51 ++++++++++++++++++++++++++++-----------------------
1 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/src/gprs.c b/src/gprs.c
index 2b88324..9618d7a 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -141,8 +141,8 @@ struct pri_context {
unsigned int id;
char *path;
char *key;
- char *proxy_host;
- uint16_t proxy_port;
+ char *host;
+ uint16_t port;
DBusMessage *pending;
struct ofono_gprs_primary_context context;
struct ofono_gprs_context *context_driver;
@@ -613,16 +613,16 @@ static void pri_parse_proxy(struct pri_context *ctx, const char *proxy)
host += 3;
if (strcasecmp(scheme, "https") == 0)
- ctx->proxy_port = 443;
+ ctx->port = 443;
else if (strcasecmp(scheme, "http") == 0)
- ctx->proxy_port = 80;
+ ctx->port = 80;
else {
g_free(scheme);
return;
}
} else {
host = scheme;
- ctx->proxy_port = 80;
+ ctx->port = 80;
}
path = strchr(host, '/');
@@ -636,12 +636,12 @@ static void pri_parse_proxy(struct pri_context *ctx, const char *proxy)
if (*end == '\0') {
*port = '\0';
- ctx->proxy_port = tmp;
+ ctx->port = tmp;
}
}
- g_free(ctx->proxy_host);
- ctx->proxy_host = g_strdup(host);
+ g_free(ctx->host);
+ ctx->host = g_strdup(host);
g_free(scheme);
}
@@ -725,7 +725,7 @@ done:
close(sk);
}
-static void pri_setproxy(const char *interface, const char *proxy)
+static void pri_add_host_route(const char *interface, const char *host)
{
struct rtentry rt;
struct sockaddr_in addr;
@@ -744,7 +744,7 @@ static void pri_setproxy(const char *interface, const char *proxy)
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr(proxy);
+ addr.sin_addr.s_addr = inet_addr(host);
memcpy(&rt.rt_dst, &addr, sizeof(rt.rt_dst));
memset(&addr, 0, sizeof(addr));
@@ -758,7 +758,7 @@ static void pri_setproxy(const char *interface, const char *proxy)
memcpy(&rt.rt_genmask, &addr, sizeof(rt.rt_genmask));
if (ioctl(sk, SIOCADDRT, &rt) < 0)
- ofono_error("Failed to add proxy host route");
+ ofono_error("Failed to add host route");
close(sk);
}
@@ -785,12 +785,13 @@ static void pri_reset_context_settings(struct pri_context *ctx)
pri_context_signal_settings(ctx, signal_ipv4, signal_ipv6);
- if (ctx->type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
+ if (ctx->type == OFONO_GPRS_CONTEXT_TYPE_MMS ||
+ ctx->type == OFONO_GPRS_CONTEXT_TYPE_STK) {
pri_set_ipv4_addr(interface, NULL);
- g_free(ctx->proxy_host);
- ctx->proxy_host = NULL;
- ctx->proxy_port = 0;
+ g_free(ctx->host);
+ ctx->host = NULL;
+ ctx->port = 0;
}
pri_ifupdown(interface, FALSE);
@@ -798,7 +799,7 @@ static void pri_reset_context_settings(struct pri_context *ctx)
g_free(interface);
}
-static void pri_update_mms_context_settings(struct pri_context *ctx)
+static void pri_update_interface(struct pri_context *ctx)
{
struct ofono_gprs_context *gc = ctx->context_driver;
struct context_settings *settings = gc->settings;
@@ -808,12 +809,12 @@ static void pri_update_mms_context_settings(struct pri_context *ctx)
pri_parse_proxy(ctx, ctx->message_proxy);
- DBG("proxy %s port %u", ctx->proxy_host, ctx->proxy_port);
+ DBG("host %s port %u", ctx->host, ctx->port);
pri_set_ipv4_addr(settings->interface, settings->ipv4->ip);
- if (ctx->proxy_host)
- pri_setproxy(settings->interface, ctx->proxy_host);
+ if (ctx->host)
+ pri_add_host_route(settings->interface, ctx->host);
}
static void append_context_properties(struct pri_context *ctx,
@@ -921,9 +922,10 @@ static void pri_activate_callback(const struct ofono_error *error, void *data)
if (gc->settings->interface != NULL) {
pri_ifupdown(gc->settings->interface, TRUE);
- if (ctx->type == OFONO_GPRS_CONTEXT_TYPE_MMS &&
- gc->settings->ipv4)
- pri_update_mms_context_settings(ctx);
+ if ((ctx->type == OFONO_GPRS_CONTEXT_TYPE_MMS &&
+ gc->settings->ipv4) ||
+ ctx->type == OFONO_GPRS_CONTEXT_TYPE_STK)
+ pri_update_interface(ctx);
pri_context_signal_settings(ctx, gc->settings->ipv4 != NULL,
gc->settings->ipv6 != NULL);
@@ -1383,7 +1385,7 @@ static void pri_context_destroy(gpointer userdata)
{
struct pri_context *ctx = userdata;
- g_free(ctx->proxy_host);
+ g_free(ctx->host);
g_free(ctx->path);
g_free(ctx);
}
@@ -3113,6 +3115,9 @@ unsigned int ofono_gprs_add_pdp_context(struct ofono_gprs *gprs,
context->context.proto = proto;
+ if (host)
+ context->host = g_strdup(host);
+
if (context_dbus_register(context) == FALSE)
return 0;
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread