All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Prestwood <james.prestwood@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 5/8] simfs: read files from specific AID's
Date: Wed, 01 Nov 2017 10:33:45 -0700	[thread overview]
Message-ID: <1509557628-15121-5-git-send-email-james.prestwood@linux.intel.com> (raw)
In-Reply-To: <1509557628-15121-1-git-send-email-james.prestwood@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 3901 bytes --]

The simfs atom could not read EF's that did not exist on the
'default' ADF directory. This implements a new way to read EF's
that exist on a given AID. A new fs object/context can be
initialized for a given AID. Using this fs context with
the existing read file API will read from that AID rather than
the default ADF.
---
 src/simfs.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 src/simfs.h |  3 +++
 2 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/src/simfs.c b/src/simfs.c
index 37a232a..6b70df0 100644
--- a/src/simfs.c
+++ b/src/simfs.c
@@ -124,6 +124,7 @@ struct file_watch {
 struct ofono_sim_context {
 	struct sim_fs *fs;
 	struct ofono_watchlist *file_watches;
+	unsigned char *aid;
 };
 
 struct sim_fs *sim_fs_new(struct ofono_sim *sim,
@@ -156,6 +157,19 @@ struct ofono_sim_context *sim_fs_context_new(struct sim_fs *fs)
 	return context;
 }
 
+struct ofono_sim_context *sim_fs_context_new_with_aid(struct sim_fs *fs,
+		unsigned char *aid)
+{
+	struct ofono_sim_context *context = sim_fs_context_new(fs);
+
+	if (context == NULL)
+		return NULL;
+
+	context->aid = g_memdup(aid, 16);
+
+	return context;
+}
+
 void sim_fs_context_free(struct ofono_sim_context *context)
 {
 	struct sim_fs *fs = context->fs;
@@ -181,6 +195,9 @@ void sim_fs_context_free(struct ofono_sim_context *context)
 		}
 	}
 
+	if (context->aid)
+		g_free(context->aid);
+
 	if (context->file_watches)
 		__ofono_watchlist_free(context->file_watches);
 
@@ -805,6 +822,43 @@ error:
 	return FALSE;
 }
 
+static void sim_fs_read_session_cb(const struct ofono_error *error,
+		const unsigned char *sdata, int length, void *data)
+{
+	struct sim_fs *fs = data;
+	struct sim_fs_op *op = g_queue_peek_head(fs->op_q);
+	ofono_sim_file_read_cb_t cb;
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+		sim_fs_op_error(fs);
+		return;
+	}
+
+	cb = op->cb;
+	cb(TRUE, length, 0, sdata, length, op->userdata);
+}
+
+static void get_session_cb(int session_id, void *data)
+{
+	struct sim_fs *fs = data;
+	struct sim_fs_op *op;
+
+	if (session_id == -1) {
+		sim_fs_op_error(fs);
+		return;
+	}
+
+	fs->op_source = 0;
+
+	op = g_queue_peek_head(fs->op_q);
+
+	fs->driver->read_file_session(fs->sim, session_id, op->id, op->offset,
+			op->num_bytes, op->path, op->path_len,
+			sim_fs_read_session_cb, fs);
+
+	ofono_sim_release_session(fs->sim, session_id);
+}
+
 static gboolean sim_fs_op_next(gpointer user_data)
 {
 	struct sim_fs *fs = user_data;
@@ -827,10 +881,20 @@ static gboolean sim_fs_op_next(gpointer user_data)
 		if (sim_fs_op_check_cached(fs))
 			return FALSE;
 
-		driver->read_file_info(fs->sim, op->id,
-					op->path_len ? op->path : NULL,
-					op->path_len,
-					sim_fs_op_info_cb, fs);
+		if (op->context->aid == NULL) {
+			driver->read_file_info(fs->sim, op->id,
+						op->path_len ? op->path : NULL,
+						op->path_len,
+						sim_fs_op_info_cb, fs);
+		} else {
+			if (!ofono_sim_get_session(fs->sim, op->context->aid,
+					get_session_cb, fs)) {
+				ofono_sim_file_read_cb_t cb = op->cb;
+
+				DBG("Could not get session for AID");
+				cb(FALSE, 0, 0, NULL, 0, op->userdata);
+			}
+		}
 	} else {
 		switch (op->structure) {
 		case OFONO_SIM_FILE_STRUCTURE_TRANSPARENT:
diff --git a/src/simfs.h b/src/simfs.h
index bb3ab0f..39af6a3 100644
--- a/src/simfs.h
+++ b/src/simfs.h
@@ -29,6 +29,9 @@ struct sim_fs *sim_fs_new(struct ofono_sim *sim,
 				const struct ofono_sim_driver *driver);
 struct ofono_sim_context *sim_fs_context_new(struct sim_fs *fs);
 
+struct ofono_sim_context *sim_fs_context_new_with_aid(struct sim_fs *fs,
+		unsigned char *aid);
+
 unsigned int sim_fs_file_watch_add(struct ofono_sim_context *context,
 					int id, ofono_sim_file_changed_cb_t cb,
 					void *userdata,
-- 
2.7.4


  parent reply	other threads:[~2017-11-01 17:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-01 17:33 [PATCH 1/8] simutil: Added ISIM elementary file ID's James Prestwood
2017-11-01 17:33 ` [PATCH 2/8] sim: header definitions for AID session APIs James Prestwood
2017-11-02 16:55   ` Denis Kenzior
2017-11-01 17:33 ` [PATCH 3/8] sim: AID session management James Prestwood
2017-11-02 17:10   ` Denis Kenzior
2017-11-01 17:33 ` [PATCH 4/8] atmodem: implement new driver APIs for AID sessions James Prestwood
2017-11-01 17:33 ` James Prestwood [this message]
2017-11-01 17:33 ` [PATCH 6/8] sim: header definitions for AID sim context API James Prestwood
2017-11-01 17:33 ` [PATCH 7/8] sim: implement create context with AID James Prestwood
2017-11-01 17:33 ` [PATCH 8/8] sim: added NetworkAccessIdentifier to SimManager James Prestwood
2017-11-02 16:40 ` [PATCH 1/8] simutil: Added ISIM elementary file ID's Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1509557628-15121-5-git-send-email-james.prestwood@linux.intel.com \
    --to=james.prestwood@linux.intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.