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