bankd_pcsc: Add CSV based mapping of bank-id/slot-nr to PC/SC reader name

In the PC/SC world, each slot is associated with a string name. In the
bankd for PC/SC readers, we need to establish a mapping which
bank_id/slot_nr maps to which given string name.  We use a minimalistic
CSV file for defining those mappings.  The file is read only once at
bankd startup time.

Change-Id: Ifd2caab670625e2e3fbc57b966dce2f43b690417
diff --git a/src/bankd_main.c b/src/bankd_main.c
index 96eee0e..7cb46d2 100644
--- a/src/bankd_main.c
+++ b/src/bankd_main.c
@@ -38,6 +38,12 @@
 	pthread_rwlock_init(&bankd->slot_mappings_rwlock, NULL);
 	INIT_LLIST_HEAD(&bankd->workers);
 	pthread_mutex_init(&bankd->workers_mutex, NULL);
+
+	/* Np lock or mutex required for the pcsc_slot_names list, as this is only
+	 * read once during bankd initialization, when the worker threads haven't
+	 * started yet */
+	INIT_LLIST_HEAD(&bankd->pcsc_slot_names);
+	OSMO_ASSERT(bankd_pcsc_read_slotnames(bankd, "bankd_pcsc_slots.csv") == 0);
 }
 
 /* create + start a new bankd_worker thread */
@@ -154,6 +160,12 @@
 {
 	long rc;
 
+	/* resolve PC/SC reader name from slot_id -> name map */
+	worker->reader.name = bankd_pcsc_get_slot_name(worker->bankd, &worker->slot);
+	OSMO_ASSERT(worker->reader.name);
+
+	LOGW(worker, "Attempting to open card/slot '%s'\n", worker->reader.name);
+
 	/* The PC/SC context must be created inside the thread where we'll later use it */
 	rc = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &worker->reader.pcsc.hContext);
 	PCSC_ERROR(worker, rc, "SCardEstablishContext")