sim: allow subclassing pin/puk sending operations
This commit is contained in:
@@ -397,7 +397,6 @@ unlock_check_ready (MMIfaceModem *self,
|
|||||||
|
|
||||||
mm_sim_send_pin (sim,
|
mm_sim_send_pin (sim,
|
||||||
mm_common_connect_properties_get_pin (ctx->properties),
|
mm_common_connect_properties_get_pin (ctx->properties),
|
||||||
NULL,
|
|
||||||
(GAsyncReadyCallback)send_pin_ready,
|
(GAsyncReadyCallback)send_pin_ready,
|
||||||
ctx);
|
ctx);
|
||||||
g_object_unref (sim);
|
g_object_unref (sim);
|
||||||
|
160
src/mm-sim.c
160
src/mm-sim.c
@@ -174,7 +174,82 @@ handle_enable_pin (MMSim *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* SEND PIN/PUK */
|
/* SEND PIN/PUK (Generic implementation) */
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
common_send_pin_puk_finish (MMSim *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
send_pin_puk_ready (MMBaseModem *modem,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GSimpleAsyncResult *simple)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
mm_base_modem_at_command_finish (modem, res, &error);
|
||||||
|
if (error)
|
||||||
|
g_simple_async_result_take_error (simple, error);
|
||||||
|
else
|
||||||
|
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
|
||||||
|
g_simple_async_result_complete (simple);
|
||||||
|
g_object_unref (simple);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
common_send_pin_puk (MMSim *self,
|
||||||
|
const gchar *pin,
|
||||||
|
const gchar *puk,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *result;
|
||||||
|
gchar *command;
|
||||||
|
|
||||||
|
result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
|
callback,
|
||||||
|
user_data,
|
||||||
|
common_send_pin_puk);
|
||||||
|
|
||||||
|
command = (puk ?
|
||||||
|
g_strdup_printf ("+CPIN=\"%s\",\"%s\"", puk, pin) :
|
||||||
|
g_strdup_printf ("+CPIN=\"%s\"", pin));
|
||||||
|
|
||||||
|
mm_base_modem_at_command (MM_BASE_MODEM (self->priv->modem),
|
||||||
|
command,
|
||||||
|
3,
|
||||||
|
FALSE,
|
||||||
|
NULL, /* cancellable */
|
||||||
|
(GAsyncReadyCallback)send_pin_puk_ready,
|
||||||
|
result);
|
||||||
|
g_free (command);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
send_puk (MMSim *self,
|
||||||
|
const gchar *puk,
|
||||||
|
const gchar *new_pin,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
common_send_pin_puk (self, new_pin, puk, callback, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
send_pin (MMSim *self,
|
||||||
|
const gchar *pin,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
common_send_pin_puk (self, pin, NULL, callback, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* SEND PIN/PUK (common logic) */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MMSim *self;
|
MMSim *self;
|
||||||
@@ -232,6 +307,14 @@ mm_sim_send_pin_finish (MMSim *self,
|
|||||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mm_sim_send_puk_finish (MMSim *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
unlock_check_ready (MMIfaceModem *modem,
|
unlock_check_ready (MMIfaceModem *modem,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -264,14 +347,27 @@ unlock_check_ready (MMIfaceModem *modem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
send_pin_puk_ready (MMBaseModem *modem,
|
send_pin_ready (MMSim *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
SendPinPukContext *ctx)
|
SendPinPukContext *ctx)
|
||||||
{
|
{
|
||||||
mm_base_modem_at_command_finish (modem, res, &ctx->save_error);
|
MM_SIM_GET_CLASS (self)->send_pin_finish (self, res, &ctx->save_error);
|
||||||
|
|
||||||
/* Once pin/puk has been sent, recheck lock */
|
/* Once pin/puk has been sent, recheck lock */
|
||||||
mm_iface_modem_unlock_check (MM_IFACE_MODEM (modem),
|
mm_iface_modem_unlock_check (MM_IFACE_MODEM (self->priv->modem),
|
||||||
|
(GAsyncReadyCallback)unlock_check_ready,
|
||||||
|
ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
send_puk_ready (MMSim *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
SendPinPukContext *ctx)
|
||||||
|
{
|
||||||
|
MM_SIM_GET_CLASS (self)->send_puk_finish (self, res, &ctx->save_error);
|
||||||
|
|
||||||
|
/* Once pin/puk has been sent, recheck lock */
|
||||||
|
mm_iface_modem_unlock_check (MM_IFACE_MODEM (self->priv->modem),
|
||||||
(GAsyncReadyCallback)unlock_check_ready,
|
(GAsyncReadyCallback)unlock_check_ready,
|
||||||
ctx);
|
ctx);
|
||||||
}
|
}
|
||||||
@@ -279,12 +375,10 @@ send_pin_puk_ready (MMBaseModem *modem,
|
|||||||
void
|
void
|
||||||
mm_sim_send_pin (MMSim *self,
|
mm_sim_send_pin (MMSim *self,
|
||||||
const gchar *pin,
|
const gchar *pin,
|
||||||
const gchar *puk,
|
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
SendPinPukContext *ctx;
|
SendPinPukContext *ctx;
|
||||||
gchar *command;
|
|
||||||
|
|
||||||
ctx = g_new0 (SendPinPukContext, 1);
|
ctx = g_new0 (SendPinPukContext, 1);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
@@ -293,22 +387,37 @@ mm_sim_send_pin (MMSim *self,
|
|||||||
user_data,
|
user_data,
|
||||||
mm_sim_send_pin);
|
mm_sim_send_pin);
|
||||||
|
|
||||||
command = (puk ?
|
MM_SIM_GET_CLASS (self)->send_pin (self,
|
||||||
g_strdup_printf ("+CPIN=\"%s\",\"%s\"", puk, pin) :
|
pin,
|
||||||
g_strdup_printf ("+CPIN=\"%s\"", pin));
|
(GAsyncReadyCallback)send_pin_ready,
|
||||||
|
ctx);
|
||||||
mm_base_modem_at_command (MM_BASE_MODEM (self->priv->modem),
|
}
|
||||||
command,
|
|
||||||
3,
|
void
|
||||||
FALSE,
|
mm_sim_send_puk (MMSim *self,
|
||||||
NULL, /* cancellable */
|
const gchar *puk,
|
||||||
(GAsyncReadyCallback)send_pin_puk_ready,
|
const gchar *new_pin,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
SendPinPukContext *ctx;
|
||||||
|
|
||||||
|
ctx = g_new0 (SendPinPukContext, 1);
|
||||||
|
ctx->self = g_object_ref (self);
|
||||||
|
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
|
callback,
|
||||||
|
user_data,
|
||||||
|
mm_sim_send_puk);
|
||||||
|
|
||||||
|
MM_SIM_GET_CLASS (self)->send_puk (self,
|
||||||
|
puk,
|
||||||
|
new_pin,
|
||||||
|
(GAsyncReadyCallback)send_puk_ready,
|
||||||
ctx);
|
ctx);
|
||||||
g_free (command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* SEND PIN */
|
/* SEND PIN (DBus call handling) */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_send_pin_ready (MMSim *self,
|
handle_send_pin_ready (MMSim *self,
|
||||||
@@ -332,7 +441,6 @@ handle_send_pin (MMSim *self,
|
|||||||
{
|
{
|
||||||
mm_sim_send_pin (self,
|
mm_sim_send_pin (self,
|
||||||
pin,
|
pin,
|
||||||
NULL,
|
|
||||||
(GAsyncReadyCallback)handle_send_pin_ready,
|
(GAsyncReadyCallback)handle_send_pin_ready,
|
||||||
dbus_call_context_new (self,
|
dbus_call_context_new (self,
|
||||||
invocation));
|
invocation));
|
||||||
@@ -340,7 +448,7 @@ handle_send_pin (MMSim *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* SEND PUK */
|
/* SEND PUK (DBus call handling) */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_send_puk_ready (MMSim *self,
|
handle_send_puk_ready (MMSim *self,
|
||||||
@@ -349,7 +457,7 @@ handle_send_puk_ready (MMSim *self,
|
|||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!mm_sim_send_pin_finish (self, res, &error))
|
if (!mm_sim_send_puk_finish (self, res, &error))
|
||||||
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
else
|
else
|
||||||
mm_gdbus_sim_complete_send_puk (MM_GDBUS_SIM (self), ctx->invocation);
|
mm_gdbus_sim_complete_send_puk (MM_GDBUS_SIM (self), ctx->invocation);
|
||||||
@@ -361,11 +469,11 @@ static gboolean
|
|||||||
handle_send_puk (MMSim *self,
|
handle_send_puk (MMSim *self,
|
||||||
GDBusMethodInvocation *invocation,
|
GDBusMethodInvocation *invocation,
|
||||||
const gchar *puk,
|
const gchar *puk,
|
||||||
const gchar *pin)
|
const gchar *new_pin)
|
||||||
{
|
{
|
||||||
mm_sim_send_pin (self,
|
mm_sim_send_puk (self,
|
||||||
pin,
|
|
||||||
puk,
|
puk,
|
||||||
|
new_pin,
|
||||||
(GAsyncReadyCallback)handle_send_puk_ready,
|
(GAsyncReadyCallback)handle_send_puk_ready,
|
||||||
dbus_call_context_new (self,
|
dbus_call_context_new (self,
|
||||||
invocation));
|
invocation));
|
||||||
@@ -1306,6 +1414,10 @@ mm_sim_class_init (MMSimClass *klass)
|
|||||||
klass->load_operator_identifier_finish = load_operator_identifier_finish;
|
klass->load_operator_identifier_finish = load_operator_identifier_finish;
|
||||||
klass->load_operator_name = load_operator_name;
|
klass->load_operator_name = load_operator_name;
|
||||||
klass->load_operator_name_finish = load_operator_name_finish;
|
klass->load_operator_name_finish = load_operator_name_finish;
|
||||||
|
klass->send_pin = send_pin;
|
||||||
|
klass->send_pin_finish = common_send_pin_puk_finish;
|
||||||
|
klass->send_puk = send_puk;
|
||||||
|
klass->send_puk_finish = common_send_pin_puk_finish;
|
||||||
|
|
||||||
properties[PROP_CONNECTION] =
|
properties[PROP_CONNECTION] =
|
||||||
g_param_spec_object (MM_SIM_CONNECTION,
|
g_param_spec_object (MM_SIM_CONNECTION,
|
||||||
|
29
src/mm-sim.h
29
src/mm-sim.h
@@ -81,6 +81,25 @@ struct _MMSimClass {
|
|||||||
gchar * (* load_operator_name_finish) (MMSim *self,
|
gchar * (* load_operator_name_finish) (MMSim *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
/* Send PIN (async) */
|
||||||
|
void (* send_pin) (MMSim *self,
|
||||||
|
const gchar *pin,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
gboolean (* send_pin_finish) (MMSim *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
/* Send PUK (async) */
|
||||||
|
void (* send_puk) (MMSim *self,
|
||||||
|
const gchar *puk,
|
||||||
|
const gchar *new_pin,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
gboolean (* send_puk_finish) (MMSim *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error);
|
||||||
};
|
};
|
||||||
|
|
||||||
GType mm_sim_get_type (void);
|
GType mm_sim_get_type (void);
|
||||||
@@ -103,13 +122,21 @@ gboolean mm_sim_initialize_finish (MMSim *self,
|
|||||||
|
|
||||||
void mm_sim_send_pin (MMSim *self,
|
void mm_sim_send_pin (MMSim *self,
|
||||||
const gchar *pin,
|
const gchar *pin,
|
||||||
const gchar *puk,
|
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean mm_sim_send_pin_finish (MMSim *self,
|
gboolean mm_sim_send_pin_finish (MMSim *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
void mm_sim_send_puk (MMSim *self,
|
||||||
|
const gchar *puk,
|
||||||
|
const gchar *new_pin,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
gboolean mm_sim_send_puk_finish (MMSim *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
void mm_sim_export (MMSim *self);
|
void mm_sim_export (MMSim *self);
|
||||||
|
|
||||||
const gchar *mm_sim_get_path (MMSim *sim);
|
const gchar *mm_sim_get_path (MMSim *sim);
|
||||||
|
Reference in New Issue
Block a user