Commit Graph

220 Commits

Author SHA1 Message Date
Harald Welte a86e6b73d8 remsim_client: Move body of main() loop to separate function
I rally don't like the existing spaghetti-style code.

Change-Id: I85c166e8aa95bb3f2e5d60d14f60caa94f3116fb
2020-01-12 19:41:36 +01:00
Harald Welte f918748208 client: Enable talloc NULL context tracking
Change-Id: I41ac5437e9262cf9e5a6e92db9b733902c91755b
2020-01-12 19:41:36 +01:00
Harald Welte 9636d2b090 remsim-client: Introduce 'struct client_config'
Introduce a dedicated structure for the parsed command line options
converted into the configuration for the client.  This reduces the
amount of spaghetti code and paves the way for a later VTY / config
file.

Change-Id: I59980a78f0344602f9fa5b2277c99dfbf0b7815c
2020-01-12 19:41:36 +01:00
Harald Welte bbd18bd7fe bankd: Implement card reset based on clientSlotStatusInd
If a client is sending us a clientSlotStatusInd indicating that
the modem has switched off VCC or activated RST, bankd will
now issue a respective PC/SC command to perform a cold or warm
reset of the card.

Change-Id: Ifa615d239ec3ad6daebd8e99e4f7d5b99d32c0e1
Closes: OS#4330
2019-12-17 13:31:20 +01:00
Harald Welte 0e0e932ce9 client: generate clientSlotStatusInd to bankd
* enable generation of CEMU_USB_MSGT_DO_STATUS on IRQ endpoint
* translate that to clientSlotStatusInd towards bankd

This will allow bankd to understand when to reset the card as
requested by the modem.

Change-Id: Ibe2266ffa473823e925d4e3afcf168353b11cdd8
Related: OS#4330
2019-12-17 13:31:20 +01:00
Harald Welte a9bf5c24c0 rspro_util: Add functions generating {Bank,Client}SlotStatusInd
Change-Id: Ib07d397d80310f94dd6357b895455a1897e01cf3
2019-12-17 13:31:20 +01:00
Harald Welte 32e2e006b1 remsim_client: Port to async libosmousb select loop
By using the non-blocking / asynchronous libusb via the newly-
introduced libosmousb (integration to libosmocore select loop),
we can not only get a cleaner code-base, but we also get a
considerable speed-up.

In my tests with a Quectel E25 and a sysmoUSIM-SJS1 card,
I am down from 41.4s to 4.7s for the initial reading of the SIM
at start-up.

Change-Id: Ic18690b3c2cbc5e99de0665c0b68b7555433b3cd
Closes: OS#4299
Depends: libosmocore.git I656a1a38cbb5b1f3a9145d2869d3b4d0adefcae3
2019-12-17 13:31:20 +01:00
Harald Welte fd5dafc2a2 remsim-client: Port from local copy to libosmousb + libosmo-simtrace2
We originally imported a copy of [most of] the code of
simtrace2.git/host into this repository.  That was a quick hack to get
things going, but now that simtrace2.git is providing a shared library
of simtrace2 utility functions, let's migrate over to it.

At the same time, some functions (libusb_util) have been migrated to
libosmousb (a new library in libosmocore.git), so we must add that
as new dependency, too.

This performs the minimally required changes and is *not* a proper
port to the libosmousb osmocore select loop integration, whcih will
follow in a separate patch.

Change-Id: Idf5a861f4dacbec3c664f4ced6e03d8662c73112
Closes: OS#4298
Related: OS#4299
Depends: libosmocore.git I656a1a38cbb5b1f3a9145d2869d3b4d0adefcae3
2019-12-17 11:56:21 +01:00
Harald Welte 0fd77a5790 bankd: Introduce SIGMAPADD to tell worker about new mapping
So far the wokrer used to sleep 10s and only check in those intervals
if [finally] a mapping had arrived.  Using SIGMAPADD, we can
directly break the worker out of its select() call and hence make
it pick up a new mapping instantaneously.

This also makes RemsimBankd_Tests.TC_removeMapping_connected() pass

Change-Id: If0130ab4b49ffcae6ab7a8b9926a6d9477eb3981
2019-12-15 00:11:43 +01:00
Harald Welte a49678309d bankd: Factor out signal-sending from bankd_srvc_remove_mapping()
This way we can also deliver other signals to workers.

Change-Id: I86744554187d5bcee75592427990d404889f29fe
2019-12-15 00:11:43 +01:00
Harald Welte b8ec65ae8f rspro_client_fsm: Fix handling of IPA keepalive
We cannot rely on the implicit IPA keepalive FSM termination, as that
somehow gets the termination order wrong and we end up accessing free'd
memory.

Let's handle the termination explicitly:  We register a callback with
the IPA keepalive FSM, and once that callback gets hit, we ask the
core to *not* terminate the FSM implicitly.  We are anyway terminating
it explicitly in st_reestablish_onenter().

Change-Id: Ia745ccb44c0d0224d1e7ab6b6da3713474111d41
2019-12-15 00:11:43 +01:00
Harald Welte 9cdd094516 rspro_client_fsm: Fix uninitialized return variable use
rspro_client_fsm.c:180:9: warning: ‘rc’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  180 |  return rc;
      |         ^~

Change-Id: I64b275b06b2aa40bd7c6e1dd42afba5ffebd7b00
2019-12-15 00:11:43 +01:00
Harald Welte 071892974a rspro_client_fsm(): Remove outdated/wrong comment from code
Since Change-Id I55d5d61922053fd94e2b5a8cdf0d799b29feec98,
rspro_dec_msg() is no longer taking ownership of the msgb.

Change-Id: Ic1e9f35a2ae82b28dbb4b2ba850c257fa9629cbf
2019-12-15 00:06:09 +01:00
Harald Welte 6d61b166c8 rspro_client_fsm: Mark ipa_client_conn_send_rspro() as static
Change-Id: Icc2f9e984dee4a2f1f604beee6c9081ecf032dd2
2019-12-15 00:06:09 +01:00
Harald Welte 82194454b3 remsim-client: Differentiate the two rspro_client_fsm instances by name
They were both called "server", which can be confusing.  Now the
bankd-facing FSM has the identity of "bankd"

Change-Id: I2626f92202717880c678ce219a14872538713f4e
2019-12-15 00:06:09 +01:00
Harald Welte 3e9860bb77 Replace bankd_client_fsm with rspro_client_fsm
There was a lot of similarity between the bankd_client_fsm (for the
client->bankd RSPRO connection) and the rspro_client_fsm (for the
client->server and the bankd->server RSPRO connections).

With the last few commits introducing the missing features to
rspro_client_fsm, we can completely obsolete bankd_client_fsm and
further simplify the codebase.

Change-Id: Icbe9881a0391fcd0c47e5d930dc764fc0cb1dfbf
2019-12-15 00:06:09 +01:00
Harald Welte a3b14d1890 rspro_client_fsm: Make RSPRO transmit use FSM event
This way we can easily guarantee that RSPRO transmit will only happen
in the fully established state, and that violations of that rule will
generate error logs by means of osmo_fsm core logging code.

Change-Id: I3c403507fa11c068d7503107857fbd5676ce135f
2019-12-05 08:56:27 +01:00
Harald Welte d2192e27ce rspro_client_fsm: Disable automatic connect on FSM allocation
So far, the rspor_client_fsm immediately attempted to establish a
TCP connection to the RSPRO server when calling server_conn_fsm_alloc().

Let's make this implicit auto-connect an explicit request to connect
using the newly-introduced SRVC_E_ESTABLISH.

Let's also change all three existing users of server_conn_fsm_alloc()
to send SRVC_E_ESTABLISH after calling it.

The rationale of this change is to use the same rspro_client_fsm also
for the client->bankd RSPRO connection, where we don't want to
automatically connect at startup, but connect only at a later point, after the
server a has told us to do so.

Change-Id: Icd882405f2ef54e10a66054829c089e4985f1d1f
2019-12-05 08:56:27 +01:00
Harald Welte a8d945e191 bankd: No need to handle SIGMAPDEL if we're not mapped yet
Change-Id: I187b833a9b7ec3d3763e21b5c88a3fa39ba0c4c7
2019-12-04 22:25:37 +01:00
Harald Welte f34fb79cc1 bankd: Implement new ResetStateReq
Change-Id: Ib794e605162903a2b2c4f4516887ec91fc8d139a
2019-12-04 22:25:37 +01:00
Harald Welte cd7fcd717c Add "--version" to all executables to print compile-time version info
Change-Id: I9ae504ff95beeefb9e90e02a576861351ea9e143
2019-12-04 21:13:24 +00:00
Harald Welte 3f9663215f RSPRO: Add new ResetState{Req,Res}
These commands are introduced to enable the server to request the
full reset of all state in a client or bankd.  This is particularly
useful in TTCN-3 tests, where we typically want to reset the state
between tests.

Change-Id: I442bab523486bbdf2faa8028f8972cd0af795303
2019-12-04 21:52:58 +01:00
Harald Welte 602b6f7763 bankd: initialize bank_id/slot_nr to 0xffff for unmapped workers
Otherwise the loop for SIGMAPDEL delivery code will match any
unused worker for bank_id=0/slot_nr=0, which is not what we want.

This also makes repeated RemsimBankd_Tests.TC_removeMapping_connected
runs work reliably.

Change-Id: I6976eb96feae6a3b66bacf787e436a2df29f9ce0
2019-12-04 21:52:58 +01:00
Harald Welte d9fb93991b bankd: Reject removeSlotmap when ClientID doesn't match
It's a bit of a matter of taste whether we should simply log + ignore
if the Client of a removeMappingReq doesn't match what the bankd
currently has configured.  I chose to reject it, as a new createMapping
for the same bandk+slot will overwrite any existing mapping anyway,
at least as of I83e319d22896b881c0d882542842f500075aa546

Change-Id: I892282821f4650614d1d08ed4bdf11eaabf947c0
2019-12-04 21:24:10 +01:00
Harald Welte e6fa46acd5 bankd: createMapping should implicitly delete existing mappings
As explained in OS#4278, a remsim-bankd currently doesn't recover after
a remsim-server resetart, since old mappings remain in the bankd, and
the server has no chance of removing them.

To avoid this problem, a createMapping now always implicitly removes
any existing mapping that may exist for the given bankdSlot.

Change-Id: I83e319d22896b881c0d882542842f500075aa546
Closes: OS#4278
2019-12-04 21:24:10 +01:00
Harald Welte 550b2958d3 bankd: Fix log print during removeMapping
We need to dereference 'rreq' nor 'creq' in the remove handling.

Change-Id: I04e9e2447336f7d1aaeb932928a79bb705aa0c5a
2019-12-04 21:24:10 +01:00
Harald Welte c650a4daec bankd_main: Refactor code: bankd_srvc_remove_mapping()
Change-Id: Iceb1d015e0ea760cce2cd99bc22ae0149bdb42f1
2019-12-04 15:08:10 +01:00
Harald Welte b2a00776a0 Bump version: 0.2.1.10-35d9-dirty → 0.2.2
Change-Id: I77c86455f9c36c16271bc8e7f8f3f72d682d23fd
2019-12-03 20:38:18 +01:00
Harald Welte 667d694a38 bankd: send IPA CCM ID_ACK after receiving ID_ACK
It is customary in the IPA protocol that a a server side
responds with an ID_ACK if the client sends an ID_ACK.  Due
to the lack of any protocol specification, it's unclear why
exactly, but we know it does happen.

osmo-remsim-bankd so far failed to implement this, which is
not directly a problem as the only user (osmo-remsim-client)
didn't care.  However, when executing TTCN3 test cases,
the IPA_Emulation expects that ID_ACK and related test fail.

Change-Id: Ie55c9d5c435df786e97ec3900837bb21ab80140a
2019-12-03 16:42:47 +01:00
Harald Welte 0a68497324 cosmetic: more comments; spelling fixes in comments
Change-Id: I4939a386ac48e4e66bce9784d9a1539426c41aae
2019-12-02 23:10:31 +01:00
Harald Welte 4ccd2fca84 Check for osmo_fsm_register() error return value
Change-Id: Idda1a4050cf9d285225ae48a4ba6f48c04f9598b
2019-12-01 13:34:32 +01:00
Harald Welte 13ebf436ac bankd_client_fsm: close IPA client connection before re-establishing it
ipa_client_conn_destroy() really only destroys the object, but not close
the underlying file descriptor.  This leads to old connections
lingering around, which in turn (in case of the remsim client) will
occupy banksim worker threads.

Change-Id: If87f4bbc133e4dc812fa96a75e8495bad65275aa
2019-11-07 13:00:39 +01:00
Kevin Redon da1854c2d7 client: fix help strings
for the osmo-remsim-client-st2 client,
the command line arguments bankd-port and slot-nr have been renamed
to server-port and client-slot in the opts options, but not in the
help output.
this is now fixed.

Change-Id: Ie23fdc443f2f90f4baf36f8aca237c9994cce8ad
2019-09-17 14:17:14 +02:00
Harald Welte 573a5b9ed9 rspro_dec_msg: Simplify msgb ownership handling
Initially it seemed like a good idea that rspro_dec_msg() takes care
of freeing the input msgb when generating a new decoded output
structure.  However, in reality this made the implementation of
every caller more complicated, as it had to treat messages going into
rspro_dec_msg() differently than messages going elsewhere.

Adding to that, not every caller got it right, and the comments were
disagreeing about what happens to msgb ownership in erroneous cases.

Change-Id: I55d5d61922053fd94e2b5a8cdf0d799b29feec98
2019-09-12 20:27:58 +02:00
Harald Welte cacbc2b37d rspro_client_fsm: Fix another memory leak
We basically must ensure that all code paths *except* the path leading
to rspro_dec_msg() must call msgb_free(msg).  This was not the case
in two situations, as fixed now.

Change-Id: I29f8413bb43b3ebf827be0bceda1a4db1e6e2b7c
2019-07-24 18:42:02 +02:00
Harald Welte 9392e08011 rspro_client_fsm/remsim_client: Fix double-free
respro_dec_msg() takes ownership of the input msgb in both
successful and unsuccessful cases, so we must not call talloc_free
on the resulting msgb.

Change-Id: Id54d1b73395da1329a998d213c190da49eb90a93
2019-07-23 18:16:40 +02:00
Harald Welte 3591382ffa server: rest_api: Fix memory leak in slotmap post
We need to decrement the refcount on the json_req object.

Change-Id: I1a550eff76e6a72013ab47ef8f240a72d7a7d9cb
2019-07-21 20:42:21 +02:00
Harald Welte 0c50c34f18 track libulfius and jansson memory allocations with talloc
Change-Id: I0ad63a79a806b420ea0de42b67726da36ebac828
2019-07-21 20:42:15 +02:00
Harald Welte 1b86ba81a0 rspro_client_fsm: Fix memory leak processing RSPRO
Change-Id: I2c3710d152ce31d293a3693a70718c8712e2ac2b
Closes: OS#4097
2019-07-18 19:05:33 +02:00
Harald Welte 80df20e055 remsim_client: Fix memory leak receiving RSPRO messages
Change-Id: Ic3b5b7b03d557557a245fcd5c31bd687e11c7477
Closes: OS#4119
2019-07-18 19:02:31 +02:00
Harald Welte 6b990f914f rspro_server.c: Fix memory leak in processing inbound RSPRO
We need to unconditionally free the msgb that gets handed into
sock_read_cb() by the ipa server.

Closes: OS#4096
Change-Id: I12b4a22854eea79c9e9c3e565dd4803e4dc0ed5a
2019-07-18 19:02:31 +02:00
Harald Welte f7442b5125 remsim_client: Enable talloc tracking of msgb allocations
Change-Id: I45f90f1a841b5b1f29bdb41671085eeebf934a6f
2019-07-18 19:02:31 +02:00
Harald Welte 92fd7343e3 remsim_server: Enable talloc tracking of msgb allocations
Change-Id: Ia8c729756da6bb85e61a65addae4d4c83e7b6fde
2019-07-18 19:02:31 +02:00
Martin Hauke 4e87bebcc7 Fix common misspellings and typos
Change-Id: I8152acaccd33a4b646d56cba0748aeefa0c16b35
2019-07-17 22:11:52 +02:00
Joachim Steiger 9c963dca66 osmo-remsim-bankd: Fix typo in help for --num-slots
Change-Id: If09833f0d0ba46d7bb204ac9b3b7f8128b4b3799
2019-05-25 00:49:32 +02:00
Harald Welte e89fecda6a bankd: Don't read CSV file until _after_ handling options
Otherwise "--help" won't work if the CSV cannot be found/read.

Change-Id: I162c40e267ea64a52baf2b5c819d9d2658daf77d
2019-05-08 17:23:58 +02:00
Harald Welte d7468e0b8c configure.ac: Add --disable-remsim-bankd
This allows builds on small/embedded platforms to avoid all the
dependencies required by remsim-bankd, including libpcsc-lite

Change-Id: I29a1a0131fdfea6742ec12d81228879066b1ff7e
2019-04-03 13:11:57 +02:00
Harald Welte 9353c607fc configure.ac: Add --disable-remsim-server
This allows builds on small/embedded platforms to avoid all the
dependencies required by remsim-server, including ulfius, yder, etc.

Closes: OS#3896
Change-Id: I2b1ec8a9a88b931ac56a63df88886e37c580a92b
2019-04-03 12:49:10 +02:00
Harald Welte 51cfec03b1 rename executables to include osmo- name prefix
Change-Id: I4498a004519499cc4b897a68c7f33efe29a63425
2019-04-03 09:50:04 +02:00
Harald Welte 5345f3d43f Makefile.am: Fix dependency of server on libosmo-rspro.la
Change-Id: I0a1badfa44479ff771be7062a19fd842f3d56b41
2019-04-03 08:42:47 +02:00