dbg("Sending %s", (result == TRUE) ? "OK" : "FAIL");
}
-static void notify_context_deactivated(CoreObject *co_ps,
- CoreObject *ps_context)
+static void notify_context_deactivated(CoreObject *co_ps, unsigned int cid)
{
struct tnoti_ps_call_status data_resp = {0};
- unsigned int cid = tcore_context_get_id(ps_context);
- Server *server;
+ TcorePlugin *p = tcore_object_ref_plugin(co_ps);
+ Server *server = tcore_plugin_ref_server(p);
dbg("Enter");
data_resp.context_id = cid;
data_resp.state = PS_DATA_CALL_NOT_CONNECTED;
- server = tcore_plugin_ref_server(tcore_object_ref_plugin(co_ps));
-
tcore_server_send_notification(server, co_ps, TNOTI_PS_CALL_STATUS,
sizeof(struct tnoti_ps_call_status),
&data_resp);
dbg("Exit");
}
+static void on_response_set_pdp_context_deactivate(TcorePending *p,
+ int data_len,
+ const void *data,
+ void *user_data)
+{
+ CoreObject *co_ps = tcore_pending_ref_core_object(p);
+ const TcoreATResponse *resp = data;
+ CoreObject *ps_context = user_data;
+ unsigned int cid = tcore_context_get_id(ps_context);
+
+ dbg("Enter");
+
+ /*
+ * AT+CGACT = 0 is returning NO CARRIER or an error. Just test if the
+ * response contains NO CARRIER else decode CME error.
+ */
+ if (resp->lines != NULL) {
+ const char *line;
+
+ line = (const char *)resp->lines->data;
+ if (g_strcmp0(line, "NO CARRIER") != 0) {
+ /* TODO: Decode CME error */
+ err("%s", line);
+ err("Context %d has not been deactivated", cid);
+
+ goto out;
+ }
+
+ }
+
+ notify_context_deactivated(co_ps, cid);
+
+out:
+ dbg("Exit");
+}
+
static void on_response_set_pdp_context_activate(TcorePending *p, int data_len,
const void *data,
void *user_data)
dbg("Response OK");
get_pdp_address(co_ps, ps_context);
} else {
+ unsigned int cid = tcore_context_get_id(ps_context);
+
/* TODO: Manage CME errors */
err("Response NOK");
- notify_context_deactivated(co_ps, ps_context);
+ notify_context_deactivated(co_ps, cid);
}
dbg("Exit");
if (activate == TRUE)
cb = on_response_set_pdp_context_activate;
else
- return TCORE_RETURN_ENOSYS;
+ cb = on_response_set_pdp_context_deactivate;
cmd_str = g_strdup_printf("AT+CGACT=%d,%d", activate ? 1 : 0, cid);
on_confirmation_ps_message_send, NULL)
!= TCORE_RETURN_SUCCESS) {
err("Failed to prepare and send AT request");
- notify_context_deactivated(co_ps, ps_context);
+ notify_context_deactivated(co_ps, cid);
ret = TCORE_RETURN_FAILURE;
}
dbg("Response OK");
set_pdp_context(co_ps, ps_context, ACTIVATE);
} else {
+ unsigned int cid = tcore_context_get_id(ps_context);
err("Response NOK");
- notify_context_deactivated(co_ps, ps_context);
+ notify_context_deactivated(co_ps, cid);
}
dbg("Exit");
err("Failed to prepare and send AT request");
error:
- notify_context_deactivated(co_ps, ps_context);
+ notify_context_deactivated(co_ps, cid);
out:
return ret;
}
+
+static gboolean on_cgev_notification(CoreObject *co_ps, const void *data,
+ void *user_data)
+{
+ GSList *tokens = NULL;
+ GSList *lines = (GSList *)data;
+ const char *line = lines->data;
+ char *noti_data = NULL;
+ unsigned int cid;
+
+ dbg("Enter");
+
+ if (NULL == line)
+ goto out;
+
+ dbg("Lines->data :%s", line);
+
+ tokens = tcore_at_tok_new(line);
+ if (g_slist_length(tokens) != 3)
+ goto out;
+
+ noti_data = g_slist_nth_data(tokens, 0);
+
+ /* Only care about NW context deactivation */
+ if (g_str_has_prefix(noti_data, "NW DEACT") == FALSE)
+ goto out;
+
+ noti_data = g_slist_nth_data(tokens, 1);
+ dbg("PDP Address: %s", noti_data);
+
+ noti_data = g_slist_nth_data(tokens, 2);
+ cid = (unsigned int)atoi(noti_data);
+ dbg("Context %d deactivated", cid);
+
+ notify_context_deactivated(co_ps, cid);
+
+out:
+ if (tokens != NULL)
+ tcore_at_tok_free(tokens);
+
+ dbg("Exit");
+
+ return TRUE;
+}
+
static TReturn activate_ps_context(CoreObject *co_ps, CoreObject *ps_context,
void *user_data)
{
static TReturn deactivate_ps_context(CoreObject *co_ps, CoreObject *ps_context,
void *user_data)
{
- return TCORE_RETURN_ENOSYS;
+ return set_pdp_context(co_ps, ps_context, DEACTIVATE);
}
static struct tcore_ps_operations ps_ops = {
if (NULL == co_ps)
return FALSE;
+ tcore_object_add_callback(co_ps, "+CGEV", on_cgev_notification, NULL);
+
return TRUE;
}