Commit Graph

75 Commits

Author SHA1 Message Date
Sylvain Munaut 3729f8f90e mux_demux: In RAW mode, fill with dummy until first TX
Until the remote side sends the first byte, we send fill
data since it can take it some time after the mode change
and the file descriptor is open for data to show up.

Previously due to a bug, the warning about short read was
not printed, but now that it's fixed, you get a bunch of
fairly "useless" warning at the beginning of the timeslot.

This fixes that since reported data by _e1_tx_raw is "faked"
until the pipe is active. (Fill data is actually added upstream)

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Iaa6268e9b4a7bce5ea3027a29c48c147499373be
2022-01-09 15:09:11 +01:00
Sylvain Munaut e945a897f7 mux_demux: Shuffle functions around for consistency
No functional changes, just making things a bit more organized
for the next patch adding an _e1_tx_raw.

The order after the patch is :

_e1_tx_hdlcfs
_e1_ts_read
_e1_line_mux_out_channelized
_e1_line_mux_out_superchan
e1_line_mux_out

_e1_rx_raw
_e1_rx_hdlcfs
_e1_ts_write
_e1_line_demux_in_channelized
_e1_line_demux_in_superchan
_e1_line_demux_in_ts0
e1_line_demux_in

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I2ced3a5ba3cf3cc1f212d8f3e46cfefa15e4af0c
2022-01-09 15:09:11 +01:00
Sylvain Munaut 0d2a42bc12 usb: Add warning for error during interrupt transfers
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Id4d2c95a2d934700f817e971aa4ce29e4bd85675
2022-01-09 11:43:03 +01:00
Sylvain Munaut 73d7184088 Fix a bunch of warning raised by the new build warning options
A lot of them are related to signedness or type range limitation.
A lot are not actual issues and work find in practice, but a few
lead to actual bad behavior.

This makes all the conversion explicit to mark intent.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I992b9bc51659e85966651b1146091501b8f149f5
2022-01-09 11:43:01 +01:00
Sylvain Munaut 35a9cf0b99 build: Increase warnings
Go with -Wextra but removing some of the obnoxious options it brings with
it.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Iaafd35ba39e272d5900b31b14d2651e0ecb8a84a
2022-01-09 11:42:41 +01:00
Sylvain Munaut 3bea0bcedc e1d/usb: Use wMaxPacketSize to know maximum number of frames to send
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I9595cba39377e45303d41a06753861bf72d5a93a
2022-01-06 16:10:28 +01:00
Sylvain Munaut 4b1226f5ac e1d/usb: Limit feedback EP transfer size to 3
Newer descriptors have the max packet size set to 3 to save on
isochronous bandwidth.

By specs, the feed back endpoints transfer are 24 bits anyway,
so no point is using anything larger.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I09e259db539e62571fd17fc16ffaa317564ba257
2022-01-06 16:10:26 +01:00
Harald Welte d1d6d93f2e Add support for icE1usb RAI interrupt error flag
In osmo-e1-hardware.git Change-Id Ic4f57cf79bd32cf75f81ef3073cb8d4a2d1857d8
we added support for passing RAI (remote alarm indication) as a flag via
the USB interrupt messages; let's add support for this here.

osmo-e1d already internally parses TS0 to determine the same
information, and we have to keep this for backwards-compatibility with
older firmware builds.  But maybe at some future point we can remove
our own TS0 scanning code here and rely on the USB device to inform
us about remote alarms.

Change-Id: Ie1994968e792c37f9272b9854547db95a41cab5b
2022-01-02 13:04:09 +01:00
Harald Welte fb1293ccea Use the error counters for remote alarm + remote CRC error
Some time ago we added various error counters, but for two of them
we missed to actually ever increment them at all.

Change-Id: Ieb83a2e2e83e334c543bee83726f04f83b19227a
2022-01-02 13:02:37 +01:00
Harald Welte 890e153170 update ice1usb_proto.h to current master
Copy from firmware source code repo at
https://git.osmocom.org/osmo-e1-hardware/tree/firmware/ice40-riscv/icE1usb/ice1usb_proto.h
as of d376b2e852fbf26a60ac4d6f66e54bb85f0b7204

Change-Id: I8f7b9462482421993e3516aa9d0794bb8076b65b
2021-12-31 20:35:19 +01:00
Harald Welte 8ddb22f8c6 e1d: Add watchdog timer to detect dead lines / USB devices
We just found a bug in icE1usb (likely firmware) which was hard to find
as there was zero notification from osmo-e1d that it actually never
received any data from the icE1usb hardware/firmware anymore.

Change-Id: Id22e4110b9067f50b1818eb12295b2d4eb9cdc12
2021-12-31 17:20:32 +01:00
Harald Welte d4700da1e8 e1d-ts-pipe: Don't write more HDLC bytes than e1d supports
This avoids truncation and the following error message when operating
in HDLC-FCS mode:

<0001> mux_demux.c:91 (I0:L0:T16) Truncated message: Client tried to send 320 bytes but our buffer is limited to 264

Change-Id: I836d8b98ce5b831b0498c4650263ec3b3d4f2c45
2021-12-31 16:47:15 +01:00
Harald Welte 50b121cfc4 Introduce a #define for the maximum HDLC buffer size (264)
The purpose of turning the magic number into a #define is to allow
clients to use it.

Change-Id: I9281a4cd85d79823d06860ffaaa09b6d67bc0de3
2021-12-31 16:47:12 +01:00
Harald Welte 383782396f e1d: reliably detect EOF (HDLC-FCS mode)
This patch makes e1d reliably detect EOF on client sockets while in
HDLC-FCS mode.

Change-Id: I0260360643f723f7c721ae67c47dce8df7778694
2021-12-31 16:46:06 +01:00
Harald Welte d8e37c8b56 e1d: reliably detect EOF in _e1_ts_{read,write} (RAW mode)
This allows us to reliably detect client disconnection at least in
the case of RAW mode channels.  Even with this patch applied, e1d
still fails to reliably detect client disconnect on HDLC-FCS channels.

Change-Id: Ifb8b91d39b394f9c10c859f3adac85ea47b7653f
2021-12-31 16:45:54 +01:00
Harald Welte 5e0dfdcfe4 make compile-time default logging configuration less verbose
As Keith pointed out we shouldn't spam the stderr with debug level
logging by default.

Change-Id: I909affb3b798c13950f95628275a6ec3a38c76ca
2021-11-12 21:34:34 +01:00
Pau Espin 6a3a2aa9a7 Use new stat item/ctr getter APIs
Change-Id: Ib1bf9a6e5d2743522f888e7ef4815283b82ef809
2021-06-04 18:05:25 +02:00
Harald Welte ee9d62bb51 ctl: properly set the timeslot mode in E1DP_CMD_TS_QUERY
Change-Id: Ie7bfec19e37f748d44f4a90d296ea232bbd76b12
2021-05-10 23:33:54 -05:00
Harald Welte 67b6f40201 e1d: fix ASSERT during "write terminal"
There was some wrong ordering in config_write_e1d() regarding
resolving the vpair 'peer' devices.  We can only call
e1d_vpair_intf_peer() _after_  we have established that the
given interface actually is of type VPAIR.

Assert failed intf->drv == E1_DRIVER_VPAIR vpair.c:96

Change-Id: If494d77ed1df5cda655d3b4a60868154dc2b355e
2021-03-26 09:29:15 +01:00
Pau Espin 807364dcae Bump version: 0.1.1.33-4292-dirty → 0.2.0
Change-Id: I5353aee666d88e3d439e465dd06e34a9ea4d8b29
2021-02-24 14:07:28 +01:00
Harald Welte 1e30f0dab7 Add new "osmo-e1gen" program.
osmo-e1gen is a program that re-uses large parts of osmo-e1d, but whose
main purpose is to generate a variety of error conditions in order to
test a remote E1 implementation.

Instead of using the automatisms of the icE1usb transmit IP core, it
switches it to transparent mode and uses a host-software based E1 framer
"osmo_e1f", over which we have more control than the firmware.

Change-Id: I53a86d6730eb76a9cff9eb3f4786139015c91230
2021-01-05 23:46:05 +01:00
Harald Welte 31ac0bea55 Evaluate received E and A bits in TS0
Related: OS#4917
Change-Id: I7e1c919518b3418e973b7ae5bedd5a6dd1c2adec
2021-01-05 23:46:02 +01:00
Harald Welte 868c94b704 vty: export vty_e1d + move e1d_vty_node to header file
This will be required by osmo-e1gen

Change-Id: I5be0278bc07aadd154fc54a74b08fc7e3b5d6483
2020-12-20 11:46:19 +01:00
Harald Welte e07bbb5037 Move e1d_find_intf + e1_intf_find_line to intf_line.c
Those are generic helper functions not really related to the ctl
interface.

Change-Id: Ibbda172aa425ca1e4702bacc7e595cd73a52929d
2020-12-20 11:46:19 +01:00
Harald Welte 1923b4d832 move usb.c function declarations to newly-created usb.h
Change-Id: Icab91d73e37119960ca3c953bf91c2ec9d821311
2020-12-20 11:45:54 +01:00
Harald Welte d270f73d66 usb.c: Mark _e1_usb_open_device() as static
Change-Id: Ic4ac2b77f12479daa52392cc31ca1e7d9ed96567
2020-12-20 11:45:44 +01:00
Harald Welte 929a5a7588 e1_line.c: Split multiplex + demultiplex into separate mux_demux.c
The remaining intf_line.c really only manages the data structures.

This is useful for building other programs than osmo-e1d, such as
an upcoming E1 test utility called osmo-e1gen which will also use
the USB interface and icE1usb hardware, but not any of the mux/demux/ctl
code.

Change-Id: I1ceaea85a15e2fae1d2e041173be9d758c6d0b78
2020-12-20 11:45:44 +01:00
Harald Welte 9408fc3839 support for control endpoint requests to icE1usb to switch Rx/Tx mode
Change-Id: I62f3175a216eb5db0847f4b16c91bc23697a7623
2020-12-20 11:45:44 +01:00
Harald Welte 8f3064a2c8 Add per-line rate counter group to count various errors
Change-Id: I766b717843d7cd8ac00d4ce18c38773ac50ec3e6
2020-12-20 11:45:44 +01:00
Harald Welte a74aaf172c Add support for icE1usb interrupt endpoint error reporting
Related: OS#4674
Change-Id: I5b0bf3cf40c623c17f2e88292e880b545c36b7b6
Depends: osmo-e1-hardware If157fde9d4ca05910b09537e19f37603c6d925f0
2020-12-20 11:29:59 +01:00
Harald Welte 515be330cb usb: Increase number of transfers from 2 to 4
Experimentally this has shown a much lower probability of
USB related overruns/underruns, at least on my system.

Change-Id: I5c73b29462a4870d3c86fd7f46e1574daae6f93f
2020-12-19 18:27:41 +01:00
Harald Welte ba6336c675 vpair: fix writing config file with vpairs configured
prior to this patch, the configured vpair interfaces would not
be saved to the config file on 'write file'.

Change-Id: Iff6551318534a3717c374060082147f17b925a21
2020-12-19 18:27:37 +01:00
Harald Welte e542b30f44 Use OSMO_FD_* instead of deprecated BSC_FD_*
Change-Id: I7d0972705e898fd75cda3e92104c67c56ec166d5
2020-10-18 22:36:34 +02:00
Harald Welte 9e137aff1d make sure a given timeslot can only be opened once (by default)
Align the behavior of osmo-e1d with that of DAHDI:  If a timeslot is
opened once, it cannot be opened again by anyone until it is closed
by the current owner.  This way we'd have the same failure semantics
in DAHDI vs. osmo-e1d, which is very useful in case of misconfiguration
when osmo-bsc + osmo-mgw would "fight" over a timeslot.

Add a osmo_e1dp_client_ts_open_force() function that allows to override
and get back the original behavior.

Closes: OS#4654
Change-Id: Ib25adf827ec41e74de15e0e4fdcfc9bcc9a32e58
2020-09-20 11:55:14 +02:00
Harald Welte d5ea3eb9c1 src/ctl.c: Log NOTICE messages whenever client send unexpected requests
Change-Id: Icd47de13ab84b89ce5fb21c24713bae760611d32
2020-09-11 12:56:18 +02:00
Harald Welte 51e12ad603 usb: Don't pass negative length values to e1_line_demux_in()
every so often, the USB transfer completes without data (due to
"unlucky" time alignment between E1 and USB frame clock).  Don't
call the demuxer in that case.

Otherwise the user is confused by error messages like

<0001> intf_line.c:467 (I0:L0) IN ERROR: -4

Change-Id: Ia99f97c2cca44d15a83a54cebe884b343ec44f46
2020-09-01 09:37:33 +02:00
Harald Welte 569726a72f make RAW read buffer size configurable (instead of hard-coded 160)
When opening a timeslot, the client can now specify the (from
application perspective) timeslot read buffer size.  This breaks
ABI, but then we're still at a point where only prototype hardware
exists, so we can get away with it.

Change-Id: I6d603778cce14c5d72fe5f54904905ea7e66d7ff
2020-07-22 09:42:56 +02:00
Harald Welte f99270acf7 implement buffering to chunks in E1->application direction
Existing applications (such as those written for DAHDI) expect to
be reading data in buffer/chunk sizes.  For example OsmoNITB: It
doesn't want to execute an expensive read/recv syscall to receive 11
bytes, if it needs at least 160 bytes.

Change-Id: I807671bc6f2acaef740ce215b8d8abcb5dce2640
2020-07-22 09:40:41 +02:00
Harald Welte 77683c810d cosmetic: create HDLC specific sub-structure within e1_ts
This groups all HDLC-specific members together, in preparation
of adding more fields for other modes.

Change-Id: Ide0577c25836252862153b4f24da550bee013687
2020-07-20 22:37:10 +02:00
Harald Welte 5d5e47ff3b Add new E1DP_CMD_LINE_CONFIG for switching channelized/superchannel
This adds the related code to the server and client side of the CTL
interface to switch a line between CHANNELIZED and SUPERCHANNEL.

Change-Id: I765b5c3bc9e07b2353f8647e8260ff95df3727e6
2020-07-15 10:26:15 +00:00
Harald Welte 17c80e1f55 actually implement the superchannel mode
In superchannel mode, all 31 TS are grouped together.

There is no way to enable it yet, see next patch.

Change-Id: Id340b1925471f427deb6cda7eb54e80dfc71faec
2020-07-14 14:40:10 +02:00
Harald Welte 6473bf0fe0 introduce concept of superchannel to data structures
We treat the superchannel as an extra, separate timeslot.  Initially
I thought of simply re-using TS1, but keeping the superchannel
separate ensures that it doesn't inherit any state (like half-sent
HDLC frames) from another timeslot when we switch between the modes
at runtime.

Change-Id: I0aacf251e155de2bb6ad03ffc4181067b22f1c90
2020-07-14 14:40:09 +02:00
Harald Welte 5706083138 _e1_rx_hdlcfs: const-ify input buffer argument
Change-Id: If772487124e26bafea23b451536b3b556d4c088c
2020-07-12 23:47:10 +02:00
Harald Welte 1b75abe5ce Fix HDLC-FCS transmit side
If we are not able to read more packets from the user application,
the recv/read call will return 0 and set errno = EAGAIN.  In this
situation we cannot bail out but still ask the HDLC code to generate
output (sequences of flag octets).  If we fail to do that, we will
transmit all-ones pattern instaed of all-flag octets.

Change-Id: Id3bc76f1956138dcd9cb7b499f7251cd94af1329
2020-07-12 23:47:10 +02:00
Harald Welte 73f248fd74 Use SOCK_STREAM sockets for E1_TS_MODE_RAW
SEQPACKET is great for preserving message boundaries on signaling
channels that use HDLC.  However, its semantics, particularly regarding
truncation, are sub-optimal for RAW slots containing raw user
bitstreams (typically TRAU frames or PCM audio data).

So let's use SOCK_STREAM for RAW and keep SEQPACKET for HDLCFCS.

Closes: OS#4663
Change-Id: I1767ceaa5d2a008db0009b8027667a71c0fdc0f1
2020-07-11 13:21:14 +02:00
Harald Welte 9fbd4e819e print E1DP Mode as string, not in numeric format
Change-Id: I4d221a45bdd5d85b3ab6eaa35d67683b50bea21f
2020-07-11 13:20:13 +02:00
Harald Welte f5962496d4 Detect truncated reads on SOCK_SEQPACKET sockets
Related: OS#4663
Change-Id: Ie143d3d56a68fda97cb9f5107a27f9beb043a2a4
2020-07-11 10:33:18 +02:00
Harald Welte 80df1a9fb2 usb.c: Fix error introducing Tx underflows
In Change-Id I7d4d4ab39cb3e7e6a7eb8e738a367122eb3fbee2 I inroduced
a bug that would cause e1_usb_xfer_out() to return four bytes too
little, which in turn causes E1 Tx underflows to happen in the device
firmware.

Change-Id: I71675d4de781421286f0d1febedfdb1f7b523c38
2020-07-09 20:57:07 +00:00
Harald Welte c5c5a1e7c5 add missing call to logging_vty_add_cmds() during startup
Otherwise, the usual logging related VTY commands are absent.

Change-Id: I07038dfb204301bb1696ca312b2ec29671b86ae5
2020-07-09 20:57:01 +00:00
Harald Welte 3e5741352e migrate to proper allocated USB Product ID
The 0xe1e1 was a neat hack in the early days, but now 0x6145 has been
allocated within the Openmoko USB VendorID.    The current device
firmware already uses the new ProductID, let's change it here, too.

Change-Id: Iea6087ce02c931c796d9c9cae89cdf5b5e0b28c5
2020-07-09 20:54:50 +00:00