Commit Graph

375 Commits

Author SHA1 Message Date
Harald Welte 3598c58eb8 server: Send ConfigClientBankReq with bankd_port == 0 on map delete
If a slotmap is deleted via the REST API, don't only remove it from
the bankd, but also remove it from the client.

Change-Id: Ia2fc2a098471add56cb35e74639417d865704989
Closes: OS#4399
2020-02-16 15:46:19 +01:00
Harald Welte ea3eefe433 server: don't dereference map before OSMO_ASSERT() in _update_client_for_slotmap()
Change-Id: Ib36d2ba7928ea17a508cb68748e6c50f22784227
2020-02-16 15:46:19 +01:00
Harald Welte a9caad86e0 client: Split into remsim_client.c and remsim_client_main.c
Change-Id: Ie1d21c2cd84756d5c8aa2c41bcc37f5951a3a285
2020-02-16 15:41:56 +01:00
Harald Welte 879ee414f0 client: Remove g_client completely; separate 'main' code
We may want to use the entire client code independent of the current
'main' portion, so let's introduce separation via API.

Change-Id: I6456317c3968551cd69ba379c746e4dd9690d02d
2020-02-16 15:41:56 +01:00
Harald Welte 8e46ab6755 client: Work without global g_client variable
We may want to develop programs that include multiple instances of
a remsim_client.  Let's remove the global variable 'g_client' and
instead de-reference the bankd_client using container_of() macros

Change-Id: I456fb633561b88912be2f78c3e0264794d921255
2020-02-16 15:41:56 +01:00
Harald Welte 1200c820f0 client: Add new osmo-remsim-client-shell binary
This is a remsim-client with an interactive 'shell', where the user
can type in C-APDUs in hex formats, which will be sent to the bankd /
SIM-card.  Responses received from SIM Card via bankd will be printed
in return.

Change-Id: I636505fd9741833ccf5cbd1bcac30f7b9aa94425
2020-02-16 15:41:56 +01:00
Harald Welte d5a8729291 client: Adjust to API changes; enable build of remsim-client again
There were quite a bit of API changes that hadn't yet been applied
to remsim_client.c (which was disabled and hence not compiled for
quite some time).

Change-Id: I0b3733f6851a951ee24ae87aa5db0ee8daa7a841
2020-02-16 15:41:56 +01:00
Harald Welte 55c7f44194 remsim-client: Call an external script in specific situations
There are some situations where remsim-client would want to make its
surrounding system aware of, e.g. to take specific action.

This is particularly important on platforms where the simtrace2 firmware
doesn't have direct control over modem reset/poweron or the like.

Change-Id: I61cf4d93c669db137de801f8b147dcffaa6f3abd
Depends: libosmocore.git Ib24ac8a083db32e55402ce496a5eabd8749cc888
Closes: OS#4332
2020-02-16 15:41:56 +01:00
Harald Welte 499e1d90b5 remsim-client: Query + Store the USB device path
While the user may have specified a USB path at the command line
(or not), let's make sure we obtain the actual path after opening
the respective USB device.

Change-Id: I7e707c74647f4c5db06d495d369b2e69e2fc7c97
2020-02-16 15:41:56 +01:00
Harald Welte 943ae6286a remsim-client: store last 'status'
Keep a local copy of the last status message of the cardem
firmware.

Change-Id: I5b348035da8f0905364b67f21f5c7be112b20e70
2020-02-16 15:41:56 +01:00
Harald Welte 6a0248b224 remsim-client: Move client_config from .c to .h file
Change-Id: I158fe0f2791c164adc74cf851d5a139990bce852
2020-02-16 15:41:56 +01:00
Harald Welte 5ed4693a84 remsim-client: Avoid using 'ci' global variable
Rather, pass it around between functions and attach it to other state.

Also, make it a talloc contxt so other objects can be allocated off it.

Change-Id: I25f592581382238d5640c1f6326dec745f8d1d40
2020-02-16 15:41:56 +01:00
Harald Welte a9bc4de83b remsim-client: Fix the -k/ --keep-running option
When introducing asynchronous USB support in Change-Id
Ic18690b3c2cbc5e99de0665c0b68b7555433b3cd, we accidentially
broke the --keep-running behavior, where even a disappearing USB
device will not terminate the remsim-client process.

Change-Id: I19cca9f7953d61058a36856b2fc4c97a3b93e15d
2020-02-16 15:41:56 +01:00
Harald Welte f7598fe417 remsim-client: move from common 'src' directory to 'src/client'
As both the bankd and the server already are in src/bankd and
src/server, respectively: Let's unify this and have the client
also in its own sub-directory.

Change-Id: I67a3a5941434f09f7099c2cdb19c126cea305a73
2020-02-16 15:41:12 +01:00
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 b90fc443f3 require minimum version 1.3.0 of libosmocore
Finally, a libosmocore version with per-thread select loop fd sets
has been released, so we can update our version requirement here.

Change-Id: Ic2654b18fd1f00aa4c1ab01892ecaa48ad2ba29f
Closes: OS#4250
2020-01-12 19:41:36 +01:00
Harald Welte 25bcbbe3cc fix the package we depend on: libosmosimtrace2-dev
Change-Id: If7d4f8c5901ea1e34fb6c85bc6e6f1211c7f7bf7
2019-12-18 12:33:47 +00:00
Harald Welte 3e66be5986 debian/control: Add missing Build-Requires libosmo-simtrace2
In Change-Id Idf5a861f4dacbec3c664f4ced6e03d8662c73112 we introduced
the use of libosmo-simtrace2 (from simtrace2.git).  Our configure
script checks for it properly, but the debian/control wasn't updated.

Change-Id: I875f9d6d06d806fb9f9264840a65934fb0e99972
2019-12-17 15:38:48 +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 8c1ca1bb87 jenkins.sh: don't verify (possibly outdated) deps
When we call a script for verification of our source code, let'sn
not check the (old, previous) code from the ./deps directory, too.

We should either only verify our own code (solution implemented here)
or alternatively verify only after we updated all dependencies to the
latest stage.

Change-Id: I20e6a3b7b4109b99c91a4921285cacb168c5796b
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 4b75f0dc3c add missing debian/libosmo-rspro1.install
In Change-Id I77c86455f9c36c16271bc8e7f8f3f72d682d23fd for some
reason libosmo-rspro0.install was not renamed/moved but deleted,
causing failures to build debian packages

Change-Id: I825d70abbbd067955d7038377692beea87545ce0
2019-12-05 08:56:26 +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