Harald Welte | 3dcdd20 | 2019-03-09 13:06:46 +0100 | [diff] [blame] | 1 | /* (C) 2018-2019 by Harald Welte <laforge@gnumonks.org> |
| 2 | * |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
Harald Welte | 31c9eca | 2018-10-03 21:03:34 +0200 | [diff] [blame] | 23 | #define _GNU_SOURCE |
| 24 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <stdint.h> |
| 28 | #include <unistd.h> |
Harald Welte | 707c85a | 2019-03-09 12:56:35 +0100 | [diff] [blame] | 29 | #include <errno.h> |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 30 | |
| 31 | #include <pthread.h> |
| 32 | |
| 33 | #include <wintypes.h> |
| 34 | #include <winscard.h> |
| 35 | #include <pcsclite.h> |
| 36 | |
Harald Welte | d6dfb8c | 2018-08-16 14:46:53 +0200 | [diff] [blame] | 37 | #include <sys/socket.h> |
| 38 | #include <netdb.h> |
| 39 | |
Harald Welte | 12534e7 | 2018-08-15 23:37:29 +0200 | [diff] [blame] | 40 | #include <osmocom/core/socket.h> |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 41 | #include <osmocom/core/linuxlist.h> |
Harald Welte | f94b9ee | 2018-09-25 15:04:21 +0200 | [diff] [blame] | 42 | #include <osmocom/core/logging.h> |
| 43 | #include <osmocom/core/application.h> |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 44 | |
| 45 | #include <osmocom/gsm/ipa.h> |
| 46 | #include <osmocom/gsm/protocol/ipaccess.h> |
| 47 | |
Kévin Redon | ff5db6e | 2018-10-11 17:16:18 +0200 | [diff] [blame] | 48 | #include <asn_application.h> |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 49 | #include <osmocom/rspro/RsproPDU.h> |
| 50 | |
| 51 | #include "bankd.h" |
Harald Welte | 3cded63 | 2019-03-09 12:59:41 +0100 | [diff] [blame] | 52 | #include "rspro_client_fsm.h" |
Harald Welte | 61d98e9 | 2019-03-03 15:43:07 +0100 | [diff] [blame] | 53 | #include "debug.h" |
Harald Welte | 796a749 | 2018-09-23 19:31:28 +0200 | [diff] [blame] | 54 | #include "rspro_util.h" |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 55 | |
| 56 | __thread void *talloc_asn1_ctx; |
Harald Welte | f4b16f1 | 2019-03-09 20:58:17 +0100 | [diff] [blame] | 57 | struct bankd *g_bankd; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 58 | |
| 59 | static void *worker_main(void *arg); |
| 60 | |
| 61 | /*********************************************************************** |
| 62 | * bankd core / main thread |
| 63 | ***********************************************************************/ |
| 64 | |
Harald Welte | 43ab79f | 2018-10-03 23:34:21 +0200 | [diff] [blame] | 65 | int asn_debug; |
| 66 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 67 | static void bankd_init(struct bankd *bankd) |
| 68 | { |
Harald Welte | f94b9ee | 2018-09-25 15:04:21 +0200 | [diff] [blame] | 69 | void *g_tall_ctx = talloc_named_const(NULL, 0, "global"); |
| 70 | osmo_init_logging2(g_tall_ctx, &log_info); |
| 71 | |
Harald Welte | 43ab79f | 2018-10-03 23:34:21 +0200 | [diff] [blame] | 72 | asn_debug = 0; |
| 73 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 74 | /* intialize members of 'bankd' */ |
Harald Welte | cbd1896 | 2019-03-03 19:02:38 +0100 | [diff] [blame] | 75 | bankd->slotmaps = slotmap_init(bankd); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 76 | INIT_LLIST_HEAD(&bankd->workers); |
| 77 | pthread_mutex_init(&bankd->workers_mutex, NULL); |
Harald Welte | 45c948c | 2018-09-23 19:26:52 +0200 | [diff] [blame] | 78 | |
Harald Welte | a0f3950 | 2019-03-09 20:59:34 +0100 | [diff] [blame^] | 79 | /* set some defaults, overridden by commandline/config */ |
| 80 | bankd->cfg.bank_id = 1; |
| 81 | bankd->cfg.num_slots = 8; |
| 82 | |
Harald Welte | f1dd162 | 2018-09-24 14:54:23 +0200 | [diff] [blame] | 83 | bankd->comp_id.type = ComponentType_remsimBankd; |
| 84 | OSMO_STRLCPY_ARRAY(bankd->comp_id.name, "fixme-name"); |
| 85 | OSMO_STRLCPY_ARRAY(bankd->comp_id.software, "remsim-bankd"); |
| 86 | OSMO_STRLCPY_ARRAY(bankd->comp_id.sw_version, PACKAGE_VERSION); |
| 87 | /* FIXME: other members of app_comp_id */ |
| 88 | |
Harald Welte | 45c948c | 2018-09-23 19:26:52 +0200 | [diff] [blame] | 89 | /* Np lock or mutex required for the pcsc_slot_names list, as this is only |
| 90 | * read once during bankd initialization, when the worker threads haven't |
| 91 | * started yet */ |
| 92 | INIT_LLIST_HEAD(&bankd->pcsc_slot_names); |
| 93 | OSMO_ASSERT(bankd_pcsc_read_slotnames(bankd, "bankd_pcsc_slots.csv") == 0); |
Harald Welte | e72e573 | 2018-09-23 19:31:55 +0200 | [diff] [blame] | 94 | |
| 95 | /* HACK HACK HACK */ |
| 96 | { |
| 97 | struct bank_slot bs = { .bank_id = 1, }; |
| 98 | struct client_slot cs = { .client_id = 23, }; |
| 99 | int i; |
| 100 | for (i = 0; i < 5; i++) { |
| 101 | bs.slot_nr = cs.slot_nr = i; |
Harald Welte | cbd1896 | 2019-03-03 19:02:38 +0100 | [diff] [blame] | 102 | slotmap_add(bankd->slotmaps, &bs, &cs); |
Harald Welte | e72e573 | 2018-09-23 19:31:55 +0200 | [diff] [blame] | 103 | } |
| 104 | } |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* create + start a new bankd_worker thread */ |
Harald Welte | 8d85829 | 2018-08-15 23:36:46 +0200 | [diff] [blame] | 108 | static struct bankd_worker *bankd_create_worker(struct bankd *bankd, unsigned int i) |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 109 | { |
| 110 | struct bankd_worker *worker; |
| 111 | int rc; |
| 112 | |
| 113 | worker = talloc_zero(bankd, struct bankd_worker); |
| 114 | if (!worker) |
| 115 | return NULL; |
| 116 | |
| 117 | worker->bankd = bankd; |
Harald Welte | 8d85829 | 2018-08-15 23:36:46 +0200 | [diff] [blame] | 118 | worker->num = i; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 119 | |
| 120 | /* in the initial state, the worker has no client.fd, bank_slot or pcsc handle yet */ |
| 121 | |
| 122 | rc = pthread_create(&worker->thread, NULL, worker_main, worker); |
| 123 | if (rc != 0) { |
| 124 | talloc_free(worker); |
| 125 | return NULL; |
| 126 | } |
| 127 | |
| 128 | pthread_mutex_lock(&bankd->workers_mutex); |
| 129 | llist_add_tail(&worker->list, &bankd->workers); |
| 130 | pthread_mutex_unlock(&bankd->workers_mutex); |
| 131 | |
| 132 | return worker; |
| 133 | } |
| 134 | |
| 135 | static bool terminate = false; |
| 136 | |
Harald Welte | 707c85a | 2019-03-09 12:56:35 +0100 | [diff] [blame] | 137 | /* handle incoming messages from server */ |
| 138 | static int bankd_srvc_handle_rx(struct rspro_server_conn *srvc, const RsproPDU_t *pdu) |
| 139 | { |
| 140 | struct RsproPDU_t *resp; |
| 141 | |
| 142 | switch (pdu->msg.present) { |
| 143 | case RsproPDUchoice_PR_connectBankRes: |
| 144 | /* Store 'identity' of server in srvc->peer_comp_id */ |
| 145 | rspro_comp_id_retrieve(&srvc->peer_comp_id, &pdu->msg.choice.connectBankRes.identity); |
| 146 | osmo_fsm_inst_dispatch(srvc->fi, SRVC_E_CLIENT_CONN_RES, (void *) pdu); |
| 147 | break; |
| 148 | default: |
| 149 | fprintf(stderr, "Unknown/Unsupported RSPRO PDU type: %u\n", pdu->msg.present); |
| 150 | return -1; |
| 151 | } |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | void handle_options(int argc, char **argv) |
| 157 | { |
| 158 | } |
| 159 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 160 | int main(int argc, char **argv) |
| 161 | { |
Harald Welte | f4b16f1 | 2019-03-09 20:58:17 +0100 | [diff] [blame] | 162 | struct rspro_server_conn *srvc; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 163 | int i, rc; |
| 164 | |
Harald Welte | f4b16f1 | 2019-03-09 20:58:17 +0100 | [diff] [blame] | 165 | g_bankd = talloc_zero(NULL, struct bankd); |
| 166 | OSMO_ASSERT(g_bankd); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 167 | |
Harald Welte | f4b16f1 | 2019-03-09 20:58:17 +0100 | [diff] [blame] | 168 | bankd_init(g_bankd); |
| 169 | |
| 170 | srvc = &g_bankd->srvc; |
Harald Welte | 707c85a | 2019-03-09 12:56:35 +0100 | [diff] [blame] | 171 | srvc->server_host = "localhost"; |
| 172 | srvc->server_port = 9998; |
| 173 | srvc->handle_rx = bankd_srvc_handle_rx; |
| 174 | srvc->own_comp_id.type = ComponentType_remsimBankd; |
| 175 | OSMO_STRLCPY_ARRAY(srvc->own_comp_id.name, "fixme-name"); |
| 176 | OSMO_STRLCPY_ARRAY(srvc->own_comp_id.software, "remsim-bankd"); |
| 177 | OSMO_STRLCPY_ARRAY(srvc->own_comp_id.sw_version, PACKAGE_VERSION); |
| 178 | |
| 179 | handle_options(argc, argv); |
| 180 | |
| 181 | /* Connection towards remsim-server */ |
Harald Welte | f4b16f1 | 2019-03-09 20:58:17 +0100 | [diff] [blame] | 182 | rc = server_conn_fsm_alloc(g_bankd, srvc); |
Harald Welte | 707c85a | 2019-03-09 12:56:35 +0100 | [diff] [blame] | 183 | if (rc < 0) { |
| 184 | fprintf(stderr, "Unable to create Server conn FSM: %s\n", strerror(errno)); |
| 185 | exit(1); |
| 186 | } |
| 187 | |
| 188 | /* create listening socket for inbound client connections */ |
Harald Welte | 12534e7 | 2018-08-15 23:37:29 +0200 | [diff] [blame] | 189 | rc = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 9999, OSMO_SOCK_F_BIND); |
| 190 | if (rc < 0) |
| 191 | exit(1); |
Harald Welte | f4b16f1 | 2019-03-09 20:58:17 +0100 | [diff] [blame] | 192 | g_bankd->accept_fd = rc; |
Harald Welte | 12534e7 | 2018-08-15 23:37:29 +0200 | [diff] [blame] | 193 | |
Harald Welte | a0f3950 | 2019-03-09 20:59:34 +0100 | [diff] [blame^] | 194 | /* create worker threads: One per reader/slot! */ |
| 195 | for (i = 0; i < g_bankd->cfg.num_slots; i++) { |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 196 | struct bankd_worker *w; |
Harald Welte | f4b16f1 | 2019-03-09 20:58:17 +0100 | [diff] [blame] | 197 | w = bankd_create_worker(g_bankd, i); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 198 | if (!w) |
| 199 | exit(21); |
| 200 | } |
| 201 | |
| 202 | while (1) { |
| 203 | if (terminate) |
| 204 | break; |
Harald Welte | 8f893ff | 2018-10-03 23:21:10 +0200 | [diff] [blame] | 205 | /* FIXME: Connect to remsim-server from the main thread, register with |
| 206 | * it and await + process any slot mapping or other configuration commands. |
| 207 | * Ensure to re-connect as needed. */ |
Harald Welte | 7f684a0 | 2018-08-16 14:43:50 +0200 | [diff] [blame] | 208 | sleep(1); |
Harald Welte | 707c85a | 2019-03-09 12:56:35 +0100 | [diff] [blame] | 209 | osmo_select_main(0); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Harald Welte | f4b16f1 | 2019-03-09 20:58:17 +0100 | [diff] [blame] | 212 | talloc_free(g_bankd); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 213 | exit(0); |
| 214 | } |
| 215 | |
| 216 | |
| 217 | |
| 218 | /*********************************************************************** |
| 219 | * bankd worker thread |
| 220 | ***********************************************************************/ |
| 221 | |
Harald Welte | 8d85829 | 2018-08-15 23:36:46 +0200 | [diff] [blame] | 222 | struct value_string worker_state_names[] = { |
| 223 | { BW_ST_INIT, "INIT" }, |
| 224 | { BW_ST_ACCEPTING, "ACCEPTING" }, |
| 225 | { BW_ST_CONN_WAIT_ID, "CONN_WAIT_ID" }, |
| 226 | { BW_ST_CONN_CLIENT, "CONN_CLIENT" }, |
Harald Welte | af61473 | 2018-08-17 22:10:05 +0200 | [diff] [blame] | 227 | { BW_ST_CONN_CLIENT_WAIT_MAP, "CONN_CLIENT_WAIT_MAP" }, |
Harald Welte | 8d85829 | 2018-08-15 23:36:46 +0200 | [diff] [blame] | 228 | { BW_ST_CONN_CLIENT_MAPPED, "CONN_CLIENT_MAPPED" }, |
| 229 | { BW_ST_CONN_CLIENT_MAPPED_CARD,"CONN_CLIENT_MAPPED_CARD" }, |
| 230 | { 0, NULL } |
| 231 | }; |
| 232 | |
Harald Welte | ceb3e68 | 2018-08-16 14:47:11 +0200 | [diff] [blame] | 233 | #define LOGW(w, fmt, args...) \ |
| 234 | printf("[%03u %s] %s:%u " fmt, (w)->num, get_value_string(worker_state_names, (w)->state), \ |
| 235 | __FILE__, __LINE__, ## args) |
| 236 | |
Harald Welte | af61473 | 2018-08-17 22:10:05 +0200 | [diff] [blame] | 237 | #define PCSC_ERROR(w, rv, text) \ |
| 238 | if (rv != SCARD_S_SUCCESS) { \ |
| 239 | LOGW((w), text ": %s (0x%lX)\n", pcsc_stringify_error(rv), rv); \ |
| 240 | goto end; \ |
| 241 | } else { \ |
Harald Welte | 7b41d9c | 2018-10-03 23:15:10 +0200 | [diff] [blame] | 242 | LOGW((w), ": OK\n"); \ |
Harald Welte | af61473 | 2018-08-17 22:10:05 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Harald Welte | 8d85829 | 2018-08-15 23:36:46 +0200 | [diff] [blame] | 245 | static void worker_set_state(struct bankd_worker *worker, enum bankd_worker_state new_state) |
| 246 | { |
| 247 | LOGW(worker, "Changing state to %s\n", get_value_string(worker_state_names, new_state)); |
| 248 | worker->state = new_state; |
Harald Welte | 150d6d6 | 2018-10-03 23:07:47 +0200 | [diff] [blame] | 249 | worker->timeout = 0; |
| 250 | } |
| 251 | |
| 252 | static void worker_set_state_timeout(struct bankd_worker *worker, enum bankd_worker_state new_state, |
| 253 | unsigned int timeout_secs) |
| 254 | { |
| 255 | LOGW(worker, "Changing state to %s (timeout=%u)\n", |
| 256 | get_value_string(worker_state_names, new_state), timeout_secs); |
| 257 | worker->state = new_state; |
| 258 | worker->timeout = timeout_secs; |
Harald Welte | 8d85829 | 2018-08-15 23:36:46 +0200 | [diff] [blame] | 259 | } |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 260 | |
| 261 | static void worker_cleanup(void *arg) |
| 262 | { |
| 263 | struct bankd_worker *worker = (struct bankd_worker *) arg; |
| 264 | struct bankd *bankd = worker->bankd; |
| 265 | |
| 266 | /* FIXME: should we still do this? in the thread ?!? */ |
| 267 | pthread_mutex_lock(&bankd->workers_mutex); |
| 268 | llist_del(&worker->list); |
| 269 | talloc_free(worker); /* FIXME: is this safe? */ |
| 270 | pthread_mutex_unlock(&bankd->workers_mutex); |
| 271 | } |
| 272 | |
| 273 | |
Harald Welte | af61473 | 2018-08-17 22:10:05 +0200 | [diff] [blame] | 274 | static int worker_open_card(struct bankd_worker *worker) |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 275 | { |
Harald Welte | af61473 | 2018-08-17 22:10:05 +0200 | [diff] [blame] | 276 | long rc; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 277 | |
Harald Welte | 150d6d6 | 2018-10-03 23:07:47 +0200 | [diff] [blame] | 278 | OSMO_ASSERT(worker->state == BW_ST_CONN_CLIENT_MAPPED); |
| 279 | |
Harald Welte | 694df83 | 2018-10-03 22:47:52 +0200 | [diff] [blame] | 280 | if (!worker->reader.name) { |
| 281 | /* resolve PC/SC reader name from slot_id -> name map */ |
| 282 | worker->reader.name = bankd_pcsc_get_slot_name(worker->bankd, &worker->slot); |
| 283 | if (!worker->reader.name) { |
| 284 | LOGW(worker, "No PC/SC reader name configured for %u/%u, fix your config\n", |
| 285 | worker->slot.bank_id, worker->slot.slot_nr); |
| 286 | rc = -1; |
| 287 | goto end; |
| 288 | } |
| 289 | } |
Harald Welte | 45c948c | 2018-09-23 19:26:52 +0200 | [diff] [blame] | 290 | OSMO_ASSERT(worker->reader.name); |
| 291 | |
Harald Welte | 694df83 | 2018-10-03 22:47:52 +0200 | [diff] [blame] | 292 | if (!worker->reader.pcsc.hContext) { |
| 293 | LOGW(worker, "Attempting to open PC/SC context\n"); |
| 294 | /* The PC/SC context must be created inside the thread where we'll later use it */ |
| 295 | rc = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &worker->reader.pcsc.hContext); |
| 296 | PCSC_ERROR(worker, rc, "SCardEstablishContext") |
| 297 | } |
Harald Welte | 45c948c | 2018-09-23 19:26:52 +0200 | [diff] [blame] | 298 | |
Harald Welte | 694df83 | 2018-10-03 22:47:52 +0200 | [diff] [blame] | 299 | if (!worker->reader.pcsc.hCard) { |
| 300 | LOGW(worker, "Attempting to open card/slot '%s'\n", worker->reader.name); |
| 301 | DWORD dwActiveProtocol; |
| 302 | rc = SCardConnect(worker->reader.pcsc.hContext, worker->reader.name, SCARD_SHARE_SHARED, |
| 303 | SCARD_PROTOCOL_T0, &worker->reader.pcsc.hCard, &dwActiveProtocol); |
| 304 | PCSC_ERROR(worker, rc, "SCardConnect") |
| 305 | } |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 306 | |
Harald Welte | 57593f0 | 2018-09-23 19:30:31 +0200 | [diff] [blame] | 307 | worker_set_state(worker, BW_ST_CONN_CLIENT_MAPPED_CARD); |
Harald Welte | 150d6d6 | 2018-10-03 23:07:47 +0200 | [diff] [blame] | 308 | /* FIXME: notify client about this state change */ |
Harald Welte | 57593f0 | 2018-09-23 19:30:31 +0200 | [diff] [blame] | 309 | |
Harald Welte | af61473 | 2018-08-17 22:10:05 +0200 | [diff] [blame] | 310 | return 0; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 311 | end: |
Harald Welte | af61473 | 2018-08-17 22:10:05 +0200 | [diff] [blame] | 312 | return rc; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 313 | } |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 314 | |
| 315 | |
| 316 | static int blocking_ipa_read(int fd, uint8_t *buf, unsigned int buf_size) |
| 317 | { |
| 318 | struct ipaccess_head *hh; |
| 319 | uint16_t len; |
| 320 | int needed, rc; |
| 321 | |
| 322 | if (buf_size < sizeof(*hh)) |
| 323 | return -1; |
| 324 | |
| 325 | hh = (struct ipaccess_head *) buf; |
| 326 | |
| 327 | /* 1) blocking read from the socket (IPA header) */ |
| 328 | rc = read(fd, buf, sizeof(*hh)); |
| 329 | if (rc < sizeof(*hh)) |
| 330 | return -2; |
| 331 | |
| 332 | len = ntohs(hh->len); |
| 333 | needed = len; //- sizeof(*hh); |
| 334 | |
| 335 | /* 2) blocking read from the socket (payload) */ |
| 336 | rc = read(fd, buf+sizeof(*hh), needed); |
| 337 | if (rc < needed) |
| 338 | return -3; |
| 339 | |
| 340 | return len; |
| 341 | } |
| 342 | |
Harald Welte | 796a749 | 2018-09-23 19:31:28 +0200 | [diff] [blame] | 343 | static int worker_send_rspro(struct bankd_worker *worker, RsproPDU_t *pdu) |
| 344 | { |
| 345 | struct msgb *msg = rspro_enc_msg(pdu); |
| 346 | int rc; |
| 347 | |
| 348 | if (!msg) { |
| 349 | LOGW(worker, "error encoding RSPRO\n"); |
| 350 | return -1; |
| 351 | } |
| 352 | |
Harald Welte | fd47119 | 2018-09-24 14:51:14 +0200 | [diff] [blame] | 353 | msg->l2h = msg->data; |
Harald Welte | 796a749 | 2018-09-23 19:31:28 +0200 | [diff] [blame] | 354 | /* prepend the header */ |
| 355 | ipa_prepend_header_ext(msg, IPAC_PROTO_EXT_RSPRO); |
Harald Welte | fd47119 | 2018-09-24 14:51:14 +0200 | [diff] [blame] | 356 | ipa_prepend_header(msg, IPAC_PROTO_OSMO); |
Harald Welte | 796a749 | 2018-09-23 19:31:28 +0200 | [diff] [blame] | 357 | |
| 358 | /* actually send it through the socket */ |
| 359 | rc = write(worker->client.fd, msgb_data(msg), msgb_length(msg)); |
| 360 | if (rc == msgb_length(msg)) |
| 361 | rc = 0; |
| 362 | else { |
| 363 | LOGW(worker, "error during write: %d != %d\n", rc, msgb_length(msg)); |
| 364 | rc = -1; |
| 365 | } |
| 366 | |
| 367 | msgb_free(msg); |
| 368 | |
| 369 | return rc; |
| 370 | } |
| 371 | |
Harald Welte | 150d6d6 | 2018-10-03 23:07:47 +0200 | [diff] [blame] | 372 | /* attempt to obtain slot-map */ |
| 373 | static int worker_try_slotmap(struct bankd_worker *worker) |
| 374 | { |
Harald Welte | cbd1896 | 2019-03-03 19:02:38 +0100 | [diff] [blame] | 375 | struct slot_mapping *slmap; |
Harald Welte | 150d6d6 | 2018-10-03 23:07:47 +0200 | [diff] [blame] | 376 | |
Harald Welte | cbd1896 | 2019-03-03 19:02:38 +0100 | [diff] [blame] | 377 | slmap = slotmap_by_client(worker->bankd->slotmaps, &worker->client.clslot); |
Harald Welte | 150d6d6 | 2018-10-03 23:07:47 +0200 | [diff] [blame] | 378 | if (!slmap) { |
| 379 | LOGW(worker, "No slotmap (yet) for client C(%u:%u)\n", |
| 380 | worker->client.clslot.client_id, worker->client.clslot.slot_nr); |
| 381 | /* check in 10s if the map has been installed meanwhile by main thread */ |
| 382 | worker_set_state_timeout(worker, BW_ST_CONN_CLIENT_WAIT_MAP, 10); |
| 383 | return -1; |
| 384 | } else { |
| 385 | LOGW(worker, "slotmap found: C(%u:%u) -> B(%u:%u)\n", |
| 386 | slmap->client.client_id, slmap->client.slot_nr, |
| 387 | slmap->bank.bank_id, slmap->bank.slot_nr); |
| 388 | worker->slot = slmap->bank; |
| 389 | worker_set_state_timeout(worker, BW_ST_CONN_CLIENT_MAPPED, 10); |
| 390 | return worker_open_card(worker); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 395 | static int worker_handle_connectClientReq(struct bankd_worker *worker, const RsproPDU_t *pdu) |
| 396 | { |
Harald Welte | af61473 | 2018-08-17 22:10:05 +0200 | [diff] [blame] | 397 | const struct ComponentIdentity *cid = &pdu->msg.choice.connectClientReq.identity; |
Harald Welte | 3e68987 | 2018-09-24 14:52:56 +0200 | [diff] [blame] | 398 | e_ResultCode res; |
| 399 | RsproPDU_t *resp; |
Harald Welte | af61473 | 2018-08-17 22:10:05 +0200 | [diff] [blame] | 400 | |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 401 | OSMO_ASSERT(pdu->msg.present == RsproPDUchoice_PR_connectClientReq); |
| 402 | |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 403 | LOGW(worker, "connectClientReq(T=%lu, N='%s', SW='%s', VER='%s')\n", |
| 404 | cid->type, cid->name.buf, cid->software.buf, cid->swVersion.buf); |
| 405 | /* FIXME: store somewhere? */ |
| 406 | |
| 407 | if (worker->state != BW_ST_CONN_WAIT_ID) { |
| 408 | LOGW(worker, "Unexpected connectClientReq\n"); |
| 409 | return -102; |
| 410 | } |
| 411 | |
Harald Welte | 371d026 | 2018-08-16 15:23:58 +0200 | [diff] [blame] | 412 | if (!pdu->msg.choice.connectClientReq.clientSlot) { |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 413 | LOGW(worker, "missing clientID, aborting\n"); |
| 414 | return -103; |
| 415 | } |
Harald Welte | 371d026 | 2018-08-16 15:23:58 +0200 | [diff] [blame] | 416 | worker->client.clslot.client_id = pdu->msg.choice.connectClientReq.clientSlot->clientId; |
| 417 | worker->client.clslot.slot_nr = pdu->msg.choice.connectClientReq.clientSlot->slotNr; |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 418 | worker_set_state(worker, BW_ST_CONN_CLIENT); |
| 419 | |
Harald Welte | 150d6d6 | 2018-10-03 23:07:47 +0200 | [diff] [blame] | 420 | if (worker_try_slotmap(worker) >= 0) |
| 421 | res = ResultCode_ok; |
| 422 | else |
Harald Welte | 3e68987 | 2018-09-24 14:52:56 +0200 | [diff] [blame] | 423 | res = ResultCode_cardNotPresent; |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 424 | |
Harald Welte | 3e68987 | 2018-09-24 14:52:56 +0200 | [diff] [blame] | 425 | resp = rspro_gen_ConnectClientRes(&worker->bankd->comp_id, res); |
| 426 | return worker_send_rspro(worker, resp); |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 427 | } |
| 428 | |
Harald Welte | 796a749 | 2018-09-23 19:31:28 +0200 | [diff] [blame] | 429 | static int worker_handle_tpduModemToCard(struct bankd_worker *worker, const RsproPDU_t *pdu) |
| 430 | { |
| 431 | const struct TpduModemToCard *mdm2sim = &pdu->msg.choice.tpduModemToCard; |
| 432 | const SCARD_IO_REQUEST *pioSendPci = SCARD_PCI_T0; |
| 433 | SCARD_IO_REQUEST pioRecvPci; |
| 434 | uint8_t rx_buf[1024]; |
| 435 | DWORD rx_buf_len = sizeof(rx_buf); |
| 436 | RsproPDU_t *pdu_resp; |
| 437 | long rc; |
| 438 | |
| 439 | LOGW(worker, "tpduModemToCard(%s)\n", osmo_hexdump_nospc(mdm2sim->data.buf, mdm2sim->data.size)); |
| 440 | |
| 441 | if (worker->state != BW_ST_CONN_CLIENT_MAPPED_CARD) { |
| 442 | LOGW(worker, "Unexpected tpduModemToCaard\n"); |
| 443 | return -104; |
| 444 | } |
| 445 | |
| 446 | /* FIXME: Validate that toBankSlot / fromClientSlot match our expectations */ |
| 447 | |
| 448 | rc = SCardTransmit(worker->reader.pcsc.hCard, |
| 449 | pioSendPci, mdm2sim->data.buf, mdm2sim->data.size, |
| 450 | &pioRecvPci, rx_buf, &rx_buf_len); |
| 451 | PCSC_ERROR(worker, rc, "SCardTransmit"); |
| 452 | |
| 453 | /* encode response PDU and send it */ |
| 454 | pdu_resp = rspro_gen_TpduCard2Modem(&mdm2sim->toBankSlot, &mdm2sim->fromClientSlot, |
| 455 | rx_buf, rx_buf_len); |
| 456 | worker_send_rspro(worker, pdu_resp); |
| 457 | |
| 458 | return 0; |
| 459 | end: |
| 460 | return rc; |
| 461 | } |
| 462 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 463 | /* handle one incoming RSPRO message from a client inside a worker thread */ |
| 464 | static int worker_handle_rspro(struct bankd_worker *worker, const RsproPDU_t *pdu) |
| 465 | { |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 466 | int rc = -100; |
| 467 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 468 | switch (pdu->msg.present) { |
| 469 | case RsproPDUchoice_PR_connectClientReq: |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 470 | rc = worker_handle_connectClientReq(worker, pdu); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 471 | break; |
| 472 | case RsproPDUchoice_PR_tpduModemToCard: |
Harald Welte | 796a749 | 2018-09-23 19:31:28 +0200 | [diff] [blame] | 473 | rc = worker_handle_tpduModemToCard(worker, pdu); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 474 | break; |
| 475 | case RsproPDUchoice_PR_clientSlotStatusInd: |
| 476 | /* FIXME */ |
| 477 | break; |
| 478 | default: |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 479 | rc = -101; |
| 480 | break; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 481 | } |
| 482 | |
Harald Welte | cce2aad | 2018-08-16 14:44:37 +0200 | [diff] [blame] | 483 | return rc; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 484 | } |
| 485 | |
Harald Welte | 694df83 | 2018-10-03 22:47:52 +0200 | [diff] [blame] | 486 | static int wait_for_fd_or_timeout(int fd, unsigned int timeout_secs) |
| 487 | { |
| 488 | struct timeval tout = { timeout_secs, 0 }; |
| 489 | fd_set readset; |
| 490 | |
| 491 | FD_ZERO(&readset); |
| 492 | FD_SET(fd, &readset); |
| 493 | return select(fd + 1, &readset, NULL, NULL, timeout_secs ? &tout : NULL); |
| 494 | } |
| 495 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 496 | /* body of the main transceive loop */ |
| 497 | static int worker_transceive_loop(struct bankd_worker *worker) |
| 498 | { |
| 499 | struct ipaccess_head *hh; |
| 500 | struct ipaccess_head_ext *hh_ext; |
| 501 | uint8_t buf[65536]; /* maximum length expressed in 16bit length field */ |
| 502 | asn_dec_rval_t rval; |
| 503 | int data_len, rc; |
Harald Welte | 9ebbacc | 2018-09-24 17:43:39 +0200 | [diff] [blame] | 504 | RsproPDU_t *pdu = NULL; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 505 | |
Harald Welte | 694df83 | 2018-10-03 22:47:52 +0200 | [diff] [blame] | 506 | rc = wait_for_fd_or_timeout(worker->client.fd, worker->timeout); |
| 507 | if (rc == 0) { |
| 508 | /* TIMEOUT case */ |
Harald Welte | 150d6d6 | 2018-10-03 23:07:47 +0200 | [diff] [blame] | 509 | switch (worker->state) { |
| 510 | case BW_ST_CONN_CLIENT_WAIT_MAP: |
| 511 | /* re-check if mapping exists meanwhile? */ |
| 512 | worker_try_slotmap(worker); |
| 513 | break; |
| 514 | case BW_ST_CONN_CLIENT_MAPPED: |
| 515 | /* re-check if reader/card can be opened meanwhile? */ |
| 516 | worker_open_card(worker); |
| 517 | break; |
| 518 | default: |
| 519 | OSMO_ASSERT(0); |
| 520 | } |
| 521 | /* return early, so we do another select rather than the blocking read below */ |
Harald Welte | 694df83 | 2018-10-03 22:47:52 +0200 | [diff] [blame] | 522 | return 0; |
| 523 | }; |
| 524 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 525 | /* 1) blocking read of entire IPA message from the socket */ |
| 526 | rc = blocking_ipa_read(worker->client.fd, buf, sizeof(buf)); |
| 527 | if (rc < 0) |
| 528 | return rc; |
| 529 | data_len = rc; |
| 530 | |
| 531 | hh = (struct ipaccess_head *) buf; |
Harald Welte | 5a3613a | 2018-10-11 12:56:21 +0200 | [diff] [blame] | 532 | if (hh->proto != IPAC_PROTO_OSMO && hh->proto != IPAC_PROTO_IPACCESS) { |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 533 | LOGW(worker, "Received unsupported IPA protocol != OSMO: 0x%02x\n", hh->proto); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 534 | return -4; |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 535 | } |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 536 | |
Harald Welte | 5a3613a | 2018-10-11 12:56:21 +0200 | [diff] [blame] | 537 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 538 | LOGW(worker, "IPA CCM not implemented yet\n"); |
| 539 | return 0; |
| 540 | } |
| 541 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 542 | hh_ext = (struct ipaccess_head_ext *) buf + sizeof(*hh); |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 543 | if (data_len < sizeof(*hh_ext)) { |
| 544 | LOGW(worker, "Received short message\n"); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 545 | return -5; |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 546 | } |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 547 | data_len -= sizeof(*hh_ext); |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 548 | if (hh_ext->proto != IPAC_PROTO_EXT_RSPRO) { |
| 549 | LOGW(worker, "Received unsupported IPA EXT protocol != RSPRO: 0x%02x\n", hh_ext->proto); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 550 | return -6; |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 551 | } |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 552 | |
| 553 | /* 2) ASN1 BER decode of the message */ |
| 554 | rval = ber_decode(NULL, &asn_DEF_RsproPDU, (void **) &pdu, hh_ext->data, data_len); |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 555 | if (rval.code != RC_OK) { |
| 556 | LOGW(worker, "Error during BER decode of RSPRO\n"); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 557 | return -7; |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 558 | } |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 559 | |
| 560 | /* 3) handling of the message, possibly resulting in PCSC commands */ |
| 561 | rc = worker_handle_rspro(worker, pdu); |
| 562 | ASN_STRUCT_FREE(asn_DEF_RsproPDU, pdu); |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 563 | if (rc < 0) { |
| 564 | LOGW(worker, "Error handling RSPRO\n"); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 565 | return rc; |
Harald Welte | e1176cf | 2018-09-24 14:54:58 +0200 | [diff] [blame] | 566 | } |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 567 | |
| 568 | /* everything OK if we reach here */ |
| 569 | return 0; |
| 570 | } |
| 571 | |
Harald Welte | d6dfb8c | 2018-08-16 14:46:53 +0200 | [diff] [blame] | 572 | /* obtain an ascii representation of the client IP/port */ |
| 573 | static int worker_client_addrstr(char *out, unsigned int outlen, const struct bankd_worker *worker) |
| 574 | { |
| 575 | char hostbuf[32], portbuf[32]; |
| 576 | int rc; |
| 577 | |
| 578 | rc = getnameinfo((const struct sockaddr *)&worker->client.peer_addr, |
| 579 | worker->client.peer_addr_len, hostbuf, sizeof(hostbuf), |
| 580 | portbuf, sizeof(portbuf), NI_NUMERICHOST | NI_NUMERICSERV); |
| 581 | if (rc != 0) { |
| 582 | out[0] = '\0'; |
| 583 | return -1; |
| 584 | } |
| 585 | snprintf(out, outlen, "%s:%s", hostbuf, portbuf); |
| 586 | return 0; |
| 587 | } |
| 588 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 589 | /* worker thread main function */ |
| 590 | static void *worker_main(void *arg) |
| 591 | { |
| 592 | struct bankd_worker *worker = (struct bankd_worker *) arg; |
| 593 | void *top_ctx; |
| 594 | int rc; |
Harald Welte | 31c9eca | 2018-10-03 21:03:34 +0200 | [diff] [blame] | 595 | char worker_name[32]; |
| 596 | |
| 597 | /* set the thread name */ |
| 598 | snprintf(worker_name, sizeof(worker_name), "bankd-worker(%u)", worker->num); |
| 599 | pthread_setname_np(pthread_self(), worker_name); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 600 | |
Harald Welte | 8d85829 | 2018-08-15 23:36:46 +0200 | [diff] [blame] | 601 | worker_set_state(worker, BW_ST_INIT); |
| 602 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 603 | /* not permitted in multithreaded environment */ |
| 604 | talloc_disable_null_tracking(); |
| 605 | top_ctx = talloc_named_const(NULL, 0, "top"); |
| 606 | talloc_asn1_ctx = talloc_named_const(top_ctx, 0, "asn1"); |
| 607 | |
| 608 | /* push cleanup helper */ |
| 609 | pthread_cleanup_push(&worker_cleanup, worker); |
| 610 | |
| 611 | /* we continuously perform the same loop here, recycling the worker thread |
| 612 | * once the client connection is gone or we have some trouble with the card/reader */ |
| 613 | while (1) { |
Harald Welte | d6dfb8c | 2018-08-16 14:46:53 +0200 | [diff] [blame] | 614 | char buf[128]; |
| 615 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 616 | worker->client.peer_addr_len = sizeof(worker->client.peer_addr); |
| 617 | |
Harald Welte | 8d85829 | 2018-08-15 23:36:46 +0200 | [diff] [blame] | 618 | worker_set_state(worker, BW_ST_ACCEPTING); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 619 | /* first wait for an incoming TCP connection */ |
| 620 | rc = accept(worker->bankd->accept_fd, (struct sockaddr *) &worker->client.peer_addr, |
| 621 | &worker->client.peer_addr_len); |
| 622 | if (rc < 0) { |
| 623 | continue; |
| 624 | } |
| 625 | worker->client.fd = rc; |
Harald Welte | d6dfb8c | 2018-08-16 14:46:53 +0200 | [diff] [blame] | 626 | worker_client_addrstr(buf, sizeof(buf), worker); |
| 627 | LOGW(worker, "Accepted connection from %s\n", buf); |
Harald Welte | 8d85829 | 2018-08-15 23:36:46 +0200 | [diff] [blame] | 628 | worker_set_state(worker, BW_ST_CONN_WAIT_ID); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 629 | |
| 630 | /* run the main worker transceive loop body until there was some error */ |
| 631 | while (1) { |
| 632 | rc = worker_transceive_loop(worker); |
| 633 | if (rc < 0) |
| 634 | break; |
| 635 | } |
| 636 | |
Harald Welte | d6dfb8c | 2018-08-16 14:46:53 +0200 | [diff] [blame] | 637 | LOGW(worker, "Error %d occurred: Cleaning up state\n", rc); |
| 638 | |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 639 | /* clean-up: reset to sane state */ |
| 640 | if (worker->reader.pcsc.hCard) { |
| 641 | SCardDisconnect(worker->reader.pcsc.hCard, SCARD_UNPOWER_CARD); |
| 642 | worker->reader.pcsc.hCard = 0; |
| 643 | } |
| 644 | if (worker->reader.pcsc.hContext) { |
| 645 | SCardReleaseContext(worker->reader.pcsc.hContext); |
| 646 | worker->reader.pcsc.hContext = 0; |
| 647 | } |
Harald Welte | 694df83 | 2018-10-03 22:47:52 +0200 | [diff] [blame] | 648 | if (worker->reader.name) |
| 649 | worker->reader.name = NULL; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 650 | if (worker->client.fd >= 0) |
| 651 | close(worker->client.fd); |
Harald Welte | 415e8f6 | 2018-08-16 14:47:38 +0200 | [diff] [blame] | 652 | memset(&worker->client.peer_addr, 0, sizeof(worker->client.peer_addr)); |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 653 | worker->client.fd = -1; |
Harald Welte | 371d026 | 2018-08-16 15:23:58 +0200 | [diff] [blame] | 654 | worker->client.clslot.client_id = worker->client.clslot.slot_nr = 0; |
Harald Welte | 77911b0 | 2018-08-14 23:47:30 +0200 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | pthread_cleanup_pop(1); |
| 658 | talloc_free(top_ctx); |
| 659 | pthread_exit(NULL); |
| 660 | } |