2018-08-14 21:47:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include <wintypes.h>
|
|
|
|
#include <winscard.h>
|
|
|
|
|
|
|
|
#include <osmocom/core/linuxlist.h>
|
|
|
|
|
2018-09-24 12:54:23 +00:00
|
|
|
#include "rspro_util.h"
|
2019-03-03 18:02:38 +00:00
|
|
|
#include "slotmap.h"
|
2018-10-14 15:44:25 +00:00
|
|
|
#include "debug.h"
|
2018-09-25 13:04:21 +00:00
|
|
|
|
2018-08-14 21:47:30 +00:00
|
|
|
struct bankd;
|
|
|
|
|
2018-08-15 21:36:46 +00:00
|
|
|
enum bankd_worker_state {
|
|
|
|
/* just started*/
|
|
|
|
BW_ST_INIT,
|
|
|
|
/* blocking in the accept() call on the server socket fd */
|
|
|
|
BW_ST_ACCEPTING,
|
|
|
|
/* TCP established, but peer not yet identified itself */
|
|
|
|
BW_ST_CONN_WAIT_ID,
|
|
|
|
/* TCP established, client has identified itself, no mapping */
|
|
|
|
BW_ST_CONN_CLIENT,
|
2018-08-17 20:10:05 +00:00
|
|
|
/* TCP established, client has identified itself, waiting for mapping */
|
|
|
|
BW_ST_CONN_CLIENT_WAIT_MAP,
|
2018-08-15 21:36:46 +00:00
|
|
|
/* TCP established, client has identified itself, mapping exists */
|
|
|
|
BW_ST_CONN_CLIENT_MAPPED,
|
|
|
|
/* TCP established, client identified, mapping exists, card opened */
|
|
|
|
BW_ST_CONN_CLIENT_MAPPED_CARD,
|
|
|
|
};
|
|
|
|
|
2018-08-14 21:47:30 +00:00
|
|
|
|
|
|
|
/* bankd worker instance; one per card/slot, includes thread */
|
|
|
|
struct bankd_worker {
|
|
|
|
/* global list of workers */
|
|
|
|
struct llist_head list;
|
|
|
|
/* back-pointer to bankd */
|
|
|
|
struct bankd *bankd;
|
|
|
|
|
2018-08-15 21:36:46 +00:00
|
|
|
/* thread number */
|
|
|
|
unsigned int num;
|
|
|
|
/* worker thread state */
|
|
|
|
enum bankd_worker_state state;
|
2018-10-03 20:47:52 +00:00
|
|
|
/* timeout to use for blocking read */
|
|
|
|
unsigned int timeout;
|
2018-08-15 21:36:46 +00:00
|
|
|
|
2018-08-14 21:47:30 +00:00
|
|
|
/* slot number we are representing */
|
|
|
|
struct bank_slot slot;
|
|
|
|
|
|
|
|
/* thread of this worker. */
|
|
|
|
pthread_t thread;
|
|
|
|
|
|
|
|
/* File descriptor of the TCP connection to the remsim-client (modem) */
|
|
|
|
struct {
|
|
|
|
int fd;
|
|
|
|
struct sockaddr_storage peer_addr;
|
|
|
|
socklen_t peer_addr_len;
|
2018-08-16 13:23:58 +00:00
|
|
|
struct client_slot clslot;
|
2018-08-14 21:47:30 +00:00
|
|
|
} client;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const char *name;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
/* PC/SC context / application handle */
|
|
|
|
SCARDCONTEXT hContext;
|
|
|
|
/* PC/SC card handle */
|
|
|
|
SCARDHANDLE hCard;
|
|
|
|
} pcsc;
|
|
|
|
};
|
|
|
|
} reader;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* global bank deamon */
|
|
|
|
struct bankd {
|
|
|
|
struct {
|
|
|
|
uint16_t bank_id;
|
|
|
|
} cfg;
|
|
|
|
|
2018-09-24 12:54:23 +00:00
|
|
|
struct app_comp_id comp_id;
|
|
|
|
|
2018-08-14 21:47:30 +00:00
|
|
|
/* TCP socket at which we are listening */
|
|
|
|
int accept_fd;
|
|
|
|
|
2019-03-03 18:02:38 +00:00
|
|
|
/* list of slot mappings. only ever modified in main thread! */
|
|
|
|
struct slotmaps *slotmaps;
|
2018-08-14 21:47:30 +00:00
|
|
|
|
|
|
|
/* list of bankd_workers. accessed/modified by multiple threads; protected by mutex */
|
|
|
|
struct llist_head workers;
|
|
|
|
pthread_mutex_t workers_mutex;
|
2018-09-23 17:26:52 +00:00
|
|
|
|
|
|
|
struct llist_head pcsc_slot_names;
|
2018-08-14 21:47:30 +00:00
|
|
|
};
|
2018-09-23 17:26:52 +00:00
|
|
|
|
|
|
|
int bankd_pcsc_read_slotnames(struct bankd *bankd, const char *csv_file);
|
|
|
|
const char *bankd_pcsc_get_slot_name(struct bankd *bankd, const struct bank_slot *slot);
|