sim-mbim: coding style fixes in the EID loading
This commit is contained in:
@@ -31,26 +31,6 @@
|
||||
#include "mm-modem-helpers-mbim.h"
|
||||
#include "mm-sim-mbim.h"
|
||||
|
||||
typedef enum {
|
||||
ESIM_CHECK_STEP_UICC_OPEN_CHANNEL,
|
||||
ESIM_CHECK_STEP_UICC_GET_APDU,
|
||||
ESIM_CHECK_STEP_UICC_CLOSE_CHANNEL,
|
||||
ESIM_CHECK_STEP_UICC_STEP_LAST
|
||||
} EsimCheckStep;
|
||||
|
||||
typedef struct {
|
||||
EsimCheckStep step;
|
||||
guint32 channel;
|
||||
guint32 channel_grp;
|
||||
gchar *eid;
|
||||
}EsimCheckContext;
|
||||
|
||||
void esim_check_step (MbimDevice *device, GTask *task);
|
||||
|
||||
void esim_check_step_free (EsimCheckContext *ctx);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
G_DEFINE_TYPE (MMSimMbim, mm_sim_mbim, MM_TYPE_BASE_SIM)
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -223,28 +203,59 @@ load_imsi (MMBaseSim *self,
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Load EID */
|
||||
|
||||
#define UICC_STATUS_OK 144
|
||||
#define EID_APDU_HEADER 5
|
||||
|
||||
typedef enum {
|
||||
ESIM_CHECK_STEP_FIRST,
|
||||
ESIM_CHECK_STEP_UICC_OPEN_CHANNEL,
|
||||
ESIM_CHECK_STEP_UICC_GET_APDU,
|
||||
ESIM_CHECK_STEP_UICC_CLOSE_CHANNEL,
|
||||
ESIM_CHECK_STEP_LAST
|
||||
} EsimCheckStep;
|
||||
|
||||
typedef struct {
|
||||
EsimCheckStep step;
|
||||
guint32 channel;
|
||||
guint32 channel_grp;
|
||||
gchar *eid;
|
||||
} EsimCheckContext;
|
||||
|
||||
static void
|
||||
check_uicc_close_channel_ready (MbimDevice *device,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
esim_check_context_free (EsimCheckContext *ctx)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(MbimMessage) response = NULL;
|
||||
guint32 status;
|
||||
EsimCheckContext *ctx;
|
||||
g_free (ctx->eid);
|
||||
g_free (ctx);
|
||||
}
|
||||
|
||||
static gchar *
|
||||
load_eid_finish (MMBaseSim *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return g_task_propagate_pointer (G_TASK (res), error);
|
||||
}
|
||||
|
||||
static void esim_check_step (MbimDevice *device,
|
||||
GTask *task);
|
||||
|
||||
static void
|
||||
check_uicc_close_channel_ready (MbimDevice *device,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
g_autoptr(MbimMessage) response = NULL;
|
||||
GError *error = NULL;
|
||||
guint32 status;
|
||||
EsimCheckContext *ctx;
|
||||
|
||||
response = mbim_device_command_finish (device, res, &error);
|
||||
if (!response ||
|
||||
!mbim_message_response_get_result (response,
|
||||
MBIM_MESSAGE_TYPE_COMMAND_DONE,
|
||||
&error) ||
|
||||
!mbim_message_ms_uicc_low_level_access_close_channel_response_parse (
|
||||
response, &status, &error)) {
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
!mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error) ||
|
||||
!mbim_message_ms_uicc_low_level_access_close_channel_response_parse (response, &status, &error)) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
@@ -255,62 +266,57 @@ check_uicc_close_channel_ready (MbimDevice *device,
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
/* If ESIM_CHECK_STEP_UICC_CLOSE_CHANNEL is successful,
|
||||
* go on to next step.
|
||||
*/
|
||||
ctx->step++;
|
||||
esim_check_step (device, task);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
check_uicc_apdu_ready (MbimDevice *device,
|
||||
check_uicc_apdu_ready (MbimDevice *device,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
GTask *task)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(MbimMessage) response = NULL;
|
||||
guint32 status;
|
||||
guint32 response_size;
|
||||
const guint8 *out_response = NULL;
|
||||
EsimCheckContext *ctx;
|
||||
g_autoptr(MbimMessage) response = NULL;
|
||||
GError *error = NULL;
|
||||
guint32 status;
|
||||
guint32 apdu_response_size;
|
||||
const guint8 *apdu_response = NULL;
|
||||
EsimCheckContext *ctx;
|
||||
|
||||
response = mbim_device_command_finish (device, res, &error);
|
||||
if (!response ||
|
||||
!mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE,&error) ||
|
||||
!mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error) ||
|
||||
!mbim_message_ms_uicc_low_level_access_apdu_response_parse (
|
||||
response,
|
||||
&status,
|
||||
&response_size,
|
||||
&out_response,
|
||||
&apdu_response_size,
|
||||
&apdu_response,
|
||||
&error)) {
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Store results */
|
||||
ctx = g_task_get_task_data (task);
|
||||
ctx->eid = mm_decode_eid ((const gchar *)(out_response + EID_APDU_HEADER),
|
||||
response_size - EID_APDU_HEADER);
|
||||
ctx->eid = mm_decode_eid ((const gchar *)(apdu_response + EID_APDU_HEADER),
|
||||
apdu_response_size - EID_APDU_HEADER);
|
||||
|
||||
/* If ESIM_CHECK_STEP_UICC_GET_APDU is successful, go on to next step */
|
||||
ctx->step++;
|
||||
esim_check_step (device, task);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
check_uicc_open_channel_ready (MbimDevice *device,
|
||||
check_uicc_open_channel_ready (MbimDevice *device,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
GTask *task)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(MbimMessage) response = NULL;
|
||||
guint32 status;
|
||||
guint32 channel;
|
||||
EsimCheckContext *ctx;
|
||||
g_autoptr(MbimMessage) response = NULL;
|
||||
GError *error = NULL;
|
||||
guint32 status;
|
||||
guint32 channel;
|
||||
EsimCheckContext *ctx;
|
||||
|
||||
response = mbim_device_command_finish (device, res, &error);
|
||||
if (!response ||
|
||||
@@ -322,40 +328,31 @@ check_uicc_open_channel_ready (MbimDevice *device,
|
||||
NULL,
|
||||
NULL,
|
||||
&error)) {
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
if (status != UICC_STATUS_OK) {
|
||||
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"UICC open channel failed");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
if (status != UICC_STATUS_OK) {
|
||||
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"UICC open channel failed");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
ctx->channel = channel;
|
||||
/* If ESIM_CHECK_STEP_UICC_OPEN_CHANNEL is successful, go on to next step */
|
||||
|
||||
ctx->step++;
|
||||
esim_check_step (device, task);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
esim_check_step_free (EsimCheckContext *ctx)
|
||||
{
|
||||
g_free (ctx->eid);
|
||||
g_free (ctx);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
esim_check_step (MbimDevice *device,
|
||||
GTask *task)
|
||||
GTask *task)
|
||||
{
|
||||
EsimCheckContext *ctx;
|
||||
g_autoptr(MbimMessage) message = NULL;
|
||||
EsimCheckContext *ctx;
|
||||
g_autoptr(MbimMessage) message = NULL;
|
||||
|
||||
/* Don't run new steps if we're cancelled */
|
||||
if (g_task_return_error_if_cancelled (task)) {
|
||||
@@ -365,11 +362,16 @@ esim_check_step (MbimDevice *device,
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
switch (ctx->step) {
|
||||
case ESIM_CHECK_STEP_UICC_OPEN_CHANNEL: {
|
||||
const guint8 app_id[16] = {0xa0, 0x00, 0x00, 0x05, 0x59, 0x10, 0x10, 0xff,
|
||||
0xff, 0xff, 0xff, 0x89, 0x00, 0x00, 0x01, 0x00};
|
||||
case ESIM_CHECK_STEP_FIRST:
|
||||
ctx->step++;
|
||||
/* fall through */
|
||||
|
||||
/* Channel group is used to bundle all logical channels opened and for future reference to close */
|
||||
case ESIM_CHECK_STEP_UICC_OPEN_CHANNEL: {
|
||||
const guint8 app_id[] = {0xa0, 0x00, 0x00, 0x05, 0x59, 0x10, 0x10, 0xff,
|
||||
0xff, 0xff, 0xff, 0x89, 0x00, 0x00, 0x01, 0x00};
|
||||
|
||||
/* Channel group is used to bundle all logical channels opened and for
|
||||
* future reference to close */
|
||||
ctx->channel_grp = 1;
|
||||
message = mbim_message_ms_uicc_low_level_access_open_channel_set_new (
|
||||
sizeof (app_id),
|
||||
@@ -385,11 +387,12 @@ esim_check_step (MbimDevice *device,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)check_uicc_open_channel_ready,
|
||||
task);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
case ESIM_CHECK_STEP_UICC_GET_APDU: {
|
||||
const guint8 apdu_cmd[12] = {0x81, 0xe2, 0x91, 0x00, 0x06, 0xbf,
|
||||
0x3e, 0x03, 0x5c, 0x01, 0x5a, 0x00};
|
||||
const guint8 apdu_cmd[] = {0x81, 0xe2, 0x91, 0x00, 0x06, 0xbf,
|
||||
0x3e, 0x03, 0x5c, 0x01, 0x5a, 0x00};
|
||||
|
||||
message = mbim_message_ms_uicc_low_level_access_apdu_set_new (
|
||||
ctx->channel,
|
||||
@@ -404,9 +407,10 @@ esim_check_step (MbimDevice *device,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)check_uicc_apdu_ready,
|
||||
task);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case ESIM_CHECK_STEP_UICC_CLOSE_CHANNEL: {
|
||||
|
||||
case ESIM_CHECK_STEP_UICC_CLOSE_CHANNEL:
|
||||
message = mbim_message_ms_uicc_low_level_access_close_channel_set_new (
|
||||
ctx->channel,
|
||||
ctx->channel_grp,
|
||||
@@ -417,46 +421,38 @@ esim_check_step (MbimDevice *device,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)check_uicc_close_channel_ready,
|
||||
task);
|
||||
break;
|
||||
}
|
||||
case ESIM_CHECK_STEP_UICC_STEP_LAST:
|
||||
return;
|
||||
|
||||
case ESIM_CHECK_STEP_LAST:
|
||||
/* We are done without errors! */
|
||||
g_task_return_pointer (task, g_strdup (ctx->eid), g_free);
|
||||
g_task_return_pointer (task, g_steal_pointer (&ctx->eid), g_free);
|
||||
g_object_unref (task);
|
||||
break;
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Load EID */
|
||||
|
||||
static gchar *
|
||||
load_eid_finish (MMBaseSim *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return g_task_propagate_pointer (G_TASK (res), error);
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
static void
|
||||
load_eid (MMBaseSim *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
load_eid (MMBaseSim *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MbimDevice *device;
|
||||
GTask *task;
|
||||
EsimCheckContext *esim_ctx;
|
||||
MbimDevice *device;
|
||||
GTask *task;
|
||||
EsimCheckContext *ctx;
|
||||
|
||||
if (!peek_device (self, &device, callback, user_data))
|
||||
return;
|
||||
|
||||
task = g_task_new (self, NULL, callback, user_data);
|
||||
|
||||
esim_ctx = g_new0 (EsimCheckContext, 1);
|
||||
esim_ctx->step = ESIM_CHECK_STEP_UICC_OPEN_CHANNEL;
|
||||
g_task_set_task_data (task, esim_ctx, (GDestroyNotify)esim_check_step_free);
|
||||
ctx = g_new0 (EsimCheckContext, 1);
|
||||
ctx->step = ESIM_CHECK_STEP_FIRST;
|
||||
g_task_set_task_data (task, esim_ctx, (GDestroyNotify)esim_check_context_free);
|
||||
esim_check_step (device, task);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user