Commit graph

761 commits

Author SHA1 Message Date
Johann Fischer c51744c6ee usb: device_next: use consistent nil descriptor name
Use a consistent nil_desc name for the descriptor that
terminates a class (function) descriptor.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-02-24 14:02:37 +01:00
Zachary J. Fields 66aff25396 usb: usb_transfer.c: Address -Wextra warnings
Changed incrementing `for` loop counters to `size_t` from `int` to
eliminate warning, "warning: comparison of integer expressions of
different signedness: 'uint32_t' {aka 'unsigned int'} and 'int'
[-Wsign-compare]"

Signed-off-by: Zachary J. Fields <zachary_fields@yahoo.com>
2023-02-24 09:39:01 +01:00
Johann Fischer d17119c612 usb: device_next: add feature endpoint halt/clear state update API
Add USB device class API to notify class instances that an endpoint
has been halted or cleared due to a feature request.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-02-24 09:15:55 +01:00
Andrei Emeltchenko 8e84d840b5 usb: Fix build for 64 bit platforms
Use proper format for size_t type eliminating warnings of type:

...
error: format '%u' expects argument of type 'unsigned int', but
argument 2 has type 'size_t' {aka 'long unsigned int'}
[-Werror=format=]
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-02-23 17:51:31 +01:00
Sam Hurst df117e563a usb_c: Add super state to handle Sender Response Timer
Any Power Delivery message state that expects a reply must
start a sender response timer. This change addes a super
state that implements the Sender Response Timer
functionality, from which Power Deleiver messages states
can inherit from.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-02-21 18:04:04 -05:00
Sam Hurst 2d510fef8d usb_c: Notify DPM of Unsupported message reception
Notify the Device Policy Manager when an unsupported
message is received.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-02-20 11:24:07 +01:00
Georgij Cernysiov d7cf297d98 usb: device: class: rndis: remove CDC descriptors
RNDIS is not a CDC class.

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-02-11 08:19:32 +09:00
Georgij Cernysiov 3055a8326d usb: device: class: rndis: correct IAD and IF0 descriptors
Use descriptors as dictated by Microsoft and USB-IF.
That allows the RNDIS device to be correctly detected on Windows.

* Microsoft: https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/supported-usb-classes
* USB-IF Defined Class Codes: https://www.usb.org/defined-class-codes

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2023-02-11 08:19:32 +09:00
Georgij Cernysiov fd1f28efb6 usb: device: class: rndis: correct packet reception
Allows receive packets that are bigger than
CONFIG_RNDIS_BULK_EP_MPS.

Considering:
* MaxPacketsPerTransfer is 1
* MaxTransferSize is 1558
* PacketAlignmentFactor is 0 (20=1)

The rndis_bulk_out shall be able to receive transfer
up to 1558 bytes (inclusive).

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2023-02-10 15:34:05 +01:00
Johann Fischer 9ea25d85cf usb: device_next: update bMaxPacketSize0 based on controller capability
Update bMaxPacketSize0 field of the device descriptor based on
controller capability.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-27 16:11:20 +01:00
Johann Fischer 5c60209e79 usb: device_next: trigger dequeue of control IN endpoint on reset event
There might be pending data stage transfer not finished
while host performs a bus reset.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-27 16:11:20 +01:00
Johann Fischer a06d9769ce usb: device_next: update IAD during CDC ACM initialization
Set bFirstInterface of IAD and update CDC Union descriptor
during class initialization.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-26 09:37:03 -08:00
Johann Fischer 5c077d72b5 usb: device_next: add BT HCI USB transport layer
Add Bluetooth HCI USB transport layer implementation for the new
experimental USB device support based on the existing implementation
subsys/usb/device/class/bluetooth.c.

This implementation, unlike existing one, contains the interface
descriptors for isochronous endpoints. Since we do not support voice
channels, these are just there to avoid issues with Linux kernel btusb
driver when this implementation is part of a composite configuration.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-27 00:57:22 +09:00
Tomasz Moń 7608f54433 usb: device_next: Do not leak memory on set address
USB stack did leak memory on every SET ADDRESS request. UDC control
allocator could cope with up to 13 leaked allocations. Therefore,
issuing bus reset 13 times in a row (in addition to automatic reset
after connecting the USB cable) was enough to exhaust memory and
thus drive USB stack inoperable.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2023-01-24 09:43:00 +01:00
Sam Hurst ee9903005a usb_c: Refactor Sink common code
Move non-sink specific code into common code

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-20 12:17:44 +01:00
Tomasz Moń e326c58399 usb: device: Do not cancel transfers on suspend
Cancelling transfers on suspend contradicts Universal Serial Bus
Specification Revision 2.0, 9.1.1.6 Suspended:
  * When suspended, the USB device maintains any internal status,
    including its address and configuration.

The internal status definitely includes any pending USB transfers.
If there is a class that wants to cancel transfer on suspend, then the
cancel should be initiated by the class, not the device stack itself.

Update hal_nordic to a version that does not abort all endpoints at
suspend. It seems that aborting endpoints on suspend in nrfx driver was
the actual reason why transfers were canceled on suspend.

Remove transfer retriggering on resume from CDC ACM and Bluetooth class
implementations because transfers are no longer cancelled on suspend.
Other classes do not have any suspend related workarounds implemented.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2023-01-18 11:48:13 +01:00
Sam Hurst d9c4ec31fc usb_c: Fix comments before "else" statements
Move comments that precede an "else" into the "else"
statement.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-11 18:55:18 +01:00
Sam Hurst f84ee58abd usb_c: Add protocol error flag
Use a flag to report a protocol error to the states. This keeps
state specific actions in the state. Currently, those state
specific actions are handled in the pe_report_error function.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-11 18:55:18 +01:00
Johann Fischer 98770caf2a usb: device_next: remove workaround for the UDC enqueue bug
Remove workaround for the UDC enqueue bug in experimental
CDC ACM implementation.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-11 17:44:50 +01:00
Johann Fischer e9bab613cc usb: device_next: rename Kconfig template instances count
The name and wording used in template can be misleading.
Use more accurate word instance instead of device since
an implementation does not necessarily have to implement
a device (in the sense of Zephyr device model), and if it
does then devicetree should be used to describe number of
instances as in the case of CDC ACM implementation.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-11 17:44:27 +01:00
Johann Fischer 7a90b221a5 usb: device: bluetooth: remove USB_TRANS_NO_ZLP for OUT transfers
USB_TRANS_NO_ZLP flag has no meaning for usb_transfer() in
host-to-device direction (USB_TRANS_READ).

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-10 10:30:46 +01:00
Sam Hurst 983b693198 usb_c: Stop chunking_not_supported timer on exit
Stop chunking_not_supported timer on exit

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 0ed5c886c9 usb_c: Remove unnecessary PE_FLAGS_PROTOCOL_ERROR flag
Remove unnecessary PE_FLAGS_PROTOCOL_ERROR flag

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 77c7a51e4d usb_c: Remove unnecessary code from PE_Send_Soft_Reset
Remove unnecessary code from PE_Send_Soft_Reset

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 3af2752680 usb_c: Transition to Sink Ready on sender response timeout
Transition to pe_snk_ready state from pe_drs_send_swap_run,
on sender response timeout

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 24e18d46f1 usb_c: Properly handle Protocol Errors during DRS
From 8.3.3.4.2.1 PE_SNK_Send_Soft_Reset State, Error Recovery
should be performed if a Protocol Error happens during a Data
Role Swap.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst c27a3a31d3 usb_c: Fix DPM request handlers
Processing the common DPM request handler in the
Sink DPM request handler.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst f04da7f7ab usb_c: Check state machine array of states
Build time check that the number of states initialized
in the state machine array matches the number of enums
used to index said array.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 5b3155ff90 usb_c: Use atomic arrays for PE flags
Use atomic arrays for PE flags because the total number
of Policy Engine flags could exceed 32

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 914fed36d5 usb_c: run clang-format
Run clang-format

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 7910c617be usb-c: Refactor USB-C Subsystem Sink
Refactor USB-C Subsystem Sink so that Power Delivery
Source support and be easily added.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Tomasz Moń 73e3fcabc0 usb: dfu: Schedule timer handler from USB workqueue
Use k_work_delayable instead of k_timer in order to execute timeout in
USB workqueue context instead of ISR context. This fixes Will-Detach on
targets where usb_dc_detach() uses functions not allowed in ISR context,
e.g. nrfx usb_dc_detach() acquires mutex.

Fixes: c27d48c89a ("usb: dfu: Support DFU with WinUSB on Windows")

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2023-01-04 10:33:35 +01:00
Ryan McClelland 34cfba73b4 usb: device: hid: correct bcdHID to v1.11 spec
bcdHID is intended for the spec version of USB HID. It was pointing to the
v1.1 bcdUSB define which happens to be the same value for the v1.10 hid
spec version. This corrects it to use the v1.11 HID spec.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2022-12-21 12:20:55 +01:00
Erwan Gouriou 66d4c64966 all: Fix "#if IS_ENABLED(CONFIG_FOO)" occurrences
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-21 10:09:23 +01:00
Mateusz Wielgos 217987f1b5 usb: host: add port power and port reset USB hub features
Add port power and port reset USB hub features.

Signed-off-by: Mateusz Wielgos <mateusz.wielgos@emerson.com>
2022-12-16 13:21:12 +01:00
Johann Fischer 7c1ef35027 usb: add initial USB host support
This is initial support. Necessary to test the UHC driver API,
for the USB support test implementations, and upcoming USBIP support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-16 13:21:12 +01:00
Tomasz Moń 21975231e2 usb: device: cdc_acm: Prevent recursive logging loop
Allow enabling CDC ACM logging only if CDC ACM is not used as logging
backend. This prevents endless recursive logging loop, especially
visible when minimal footprint logging is enabled.

Fixes: #52981

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-12-15 14:54:24 +01:00
Tomasz Moń fed6bde788 usb: device: cdc_acm: send more than 1 byte in poll out
Schedule CDC ACM tx work to happen 1 ms after first unprocessed data
write. This gives enough leeway for the task writing to the queue to
write more than 1 byte before USB workqueue preempts and schedules IN
transfer. Sending more than 1 byte at a time increases data throughput
because transaction overhead remains the same regardless of packet size.

Prior to this change, virtually every IN transaction carried only one
character when CDC ACM was used as a console.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-12-14 12:07:33 +01:00
Witold Lukasik c7acd98bf4 usb: device: update logging module registration
Update logging module registration and remove LOG_LEVEL macro
for USB device classes.

Signed-off-by: Witold Lukasik <witold.lukasik@nordicsemi.no>
2022-12-12 15:57:35 +01:00
Madhurima Paruchuri fa738b0f74 usb-c: Generate USB-C connector VIF policies XML file
Generates XML file containing VIF policies by reading the device tree
using EDT.pickle generated during build
This script writes a subset of general and sink-pdo VIF policies in
output file
This script gets invoked during build if enabled through kconfig
The generated XML containing USB-C VIF policies could be used by
USB PD/Type-C analysers/testers to understand USB-C properties and
perform tests accordingly

Signed-off-by: Madhurima Paruchuri <mparuchuri@google.com>
2022-12-02 08:46:04 -06:00
Johann Fischer fcd21f10d5 usb: device_next: add experimental CDC ACM implementation
Add experimental CDC ACM implementation for new USB device stack.
It currently implements only UART IRQ API support and is WIP.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-02 12:55:18 +01:00
Johann Fischer cb8b9ad38a usb: add new experimental USB device stack
The device supprt brings support for multiple stack instances,
multiple configuration, asynchronous transfer model, ability to
change most of the properties of a device at runtime and
the composition of configuration and classes at runtime.

The stack requires new UDC driver API and is not compatible
with old driver API (usb_dc_). The classes (functions) of old
(current) USB device stack cannot be used with new ones and must
be ported.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-02 12:55:18 +01:00
Tomasz Moń f8ac6b6d66 usb: device: Disable all endpoints on stack disable
Disable all enabled endpoints on stack disable to allow re-enabling USB
device stack.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-11-25 20:02:42 +01:00
Milind Paranjpe cf91f1873b usb: disable previously enabled endpoint before re-enabling
When switching between alternate settings of an interface, it is
currently possible to call set_endpoint() multiple times on an endpoint
without first calling reset_endpoint(). For these situations, it is
beneficial to track endpoints for which set_endpoint() has previously
been called, and then reset them to properly terminate any transfers,
and to return the HAL to the correct state

Signed-off-by: Milind Paranjpe <mparanjpe@yahoo.com>
2022-11-23 12:59:40 +01:00
Johann Fischer 1c4011ff6e usb: remove usb_pid.Kconfig file
Remove Kconfig file samples/subsys/usb/usb_pid.Kconfig added in
the commit e5cbe6a9e7 ("usb: cdc: Add unique PIDs for each sample")
with the motivation to have a separate ID for each sample supposedly
to be recognizable by the host.

The new USB support does not use the options, VID/PID is set
directly in the application. As a note, it is not necessary to have
unique PID for each sample, especially for the well known USB classes.

Replace the individual Kconfig options in the documentation
by a table with the references to the samples and PIDs.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-11-22 11:09:21 +01:00
Tomasz Moń a9bfe0a423 usb: dfu: Reduce default bwPollTimeout value
The bwPollTimeout name is somewhat confusing as it refers to minimum
polling period. The bwPollTImeout is essentially a mechanism allowing
device to ratelimit DFU_GETSTATUS requests from host.

Setting bwPollTimeout to relatively high values effectively slows down
DFU download process. The slowdown is not observed if the time between
DFU_DNLOAD and DFU_GETSTATUS is enough for the device to process the
write. That is, the bwPollTimeout does not effect DFU download if the
first DFU_GETSTATUS after DFU_DNLOAD reports dfuDNLOAD-IDLE state.
Otherwise the host must wait bwPollTimeout ms before issuing next
DFU_GETSTATUS, which slows the communicaiton to not more than 1 download
block (CONFIG_USB_REQUEST_BUFFER_SIZE) every bwPollTimeout ms.

The bwPollTimeout ideally should report an estimate how much longer the
download operation will take. Zephyr does not have such estimate and
therefore defaults to using fixed value. Reduce default bwPollTimeout
from 256 to 8 ms to allow significantly faster DFU downloads on devices
where the time between DFU_DNLOAD and DFU_GETSTATUS is too short to
process download block at the expense of unnecessary bus traffic if
processing download block takes longer than 8 ms.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-11-22 13:03:11 +09:00
Chun-Chieh Li 59f3316d33 usb: audio: do not discard usb_transfer result in usb_audio_send()
Pass result of usb_transfer() as return value to the user,
and allow user to react accordingly, e.g. release net_buf on error.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2022-11-21 20:11:24 +01:00
Sam Hurst 37e6f15f34 usb-c: Fix unsupported message reporting
When operating in PD2.x mode, PD_CTRL_REJECT should be
transmitted to the port partner when an unsupported message
is received.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2022-11-08 10:46:40 +01:00
Tomasz Moń 04059ec8a7 usb: device: msc: synchronize cache after writes
Flush disk cache when write command finishes.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-11-02 10:31:58 +01:00
Sam Hurst c2677cef57 usb-c: Correct spelling error in comment
Correct spelling error in comment

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2022-10-27 11:00:14 +02:00
Sam Hurst cc393f24af usb-c: Fix policy callback function assertion
Fix the assertion check that's performed on a non-existing
callback.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2022-10-27 11:00:14 +02:00
Sam Hurst e90f1b66d8 usb-c: Add USB-C Subsystem with Sink PD Support
This USB-C Subsystem enables an application to include
USB-C Power Delivery Sink functionality.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2022-10-22 18:38:35 -04:00
Robert Lubos 942800784c net: netusb: Align netusb driver with iface state upgrade
Align netusb driver with interface state handling update. Instead of
bringing the interface up/down from the driver level, use carrier on/off
notification to update the inteface state.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 10:00:31 +02:00
Gerard Marull-Paretas b959ab25a9 include: add missing sys/slist.h include
Some headers makes use of slists w/o including sys/slist.h

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:05:17 +02:00
Tomasz Moń c27d48c89a usb: dfu: Support DFU with WinUSB on Windows
DFU on Windows with WinUSB driver failed with "Lost device after RESET?"
error because WinUSB does not support host initiated resets. USB Device
Firmware Upgrade Specification Revision 1.1 attribute bitWillDetach can
be used to overcome WinUSB reset limitation. When bitWillDetach is set,
it is the device responsibility to detach and reattach itself to the bus
after receiving DFU_DETACH request.

Add and enable by default USB_DFU_WILL_DETACH configuration option,
because it is the only way to support WinUSB driver. WinUSB driver is
preferable because it can be automatically installed on Windows 8 and
later if USB device implements WCID descriptors.

Fixes: #49821

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-10-06 09:12:34 +00:00
Dominik Ermel f762fc7a2c usb: dfu: Switch from FLASH_AREA_ to FIXED_PARTITION_
The commit switches flash area access from FLASH_AREA_ macros
to FIXED_PARTITION_ macros and to usage of DTS node labels,
to identify partitions, instead of label property.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-06 09:56:37 +02:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Kumar Gala a96eaf25f9 usb: device: cdc: Update Kconfig
Utilize DT_HAS_<COMPAT>_ENABLED for devicetree based driver

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-09-02 10:59:32 +00:00
Daniel DeGrasse 575a8e116c usb: Increase mass storage stack size when SD stack is enabled
SD stack requires a larger stack size than the default value for the
mass storage stack thread. Increase the default stack size to 768 when
the SD stack is enabled.

Fixes #49057

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-08-17 12:09:17 +02:00
Johann Fischer 6130417212 usb: device: add dummy configure API
We cannot implement configure API because there is
no notification of configuration changes provided
for the Abstract Control Model and the UART controller
is only emulated.
However, it allows us to use CDC ACM UART together with
subsystems like Modbus which require configure API for
real controllers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-07-13 11:36:59 +02:00
Pawel Osypiuk 7fcfd54423 usb: device: cdc_acm: suspend transfers when RX path runs out of buffer
Suspend CDC ACM class OUT transfers when RX path runs out
of ring buffer.

Signed-off-by: Pawel Osypiuk <pawelosyp@gmail.com>
2022-07-11 10:31:12 +02:00
Aurelien Jarno 77ef1b715a usb: cdc_acm: implement uart_config_get() API
Implement the uart_config_get() API by converting the existing
line coding structure to the struct uart_config format.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-07-05 18:00:24 +02:00
Kumar Gala c880dc908f usb: device: Update to use gpio_dt_spec
Move to use gpio_dt_spec for GPIO access.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-04 15:34:13 +02:00
Corey Wharton 4a87ae07bf netusb: allocate packets from RX pool for incoming frames
Allocate packets and buffers from the RX slab/pool when handling
incoming frames.

Signed-off-by: Corey Wharton <xodus7@cwharton.com>
2022-07-01 16:26:13 +00:00
Julien D'Ascenzio fdf5dc384d usb: cdc_acm: fix bug on transmission
In the function tx_work_handler, a pointer to ring buffer data is given
to usb_transfer then the ring_buf_get_finish is called. So, the data is
mark as read (by ring_buf_get_finish) while the data are not yet
transferred to usb. If later a user send data, the pointer hold by usb
stack could be rewrite.

Signed-off-by: Julien D'Ascenzio <julien.dascenzio@paratronic.fr>
2022-06-28 16:58:51 +02:00
Rubin Gerritsen 77b8252da6 usb: bt_h4: Set stack sizes using Kconfig
The previously used stack sizes where in many cases too small.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2022-06-23 14:40:01 +02:00
Keith Packard abac6ccfaf subsys/usb: Fix use of 'abs' in computing when to report on_idle
idle_rate is uint8_t, sof_cnt is uint32_t. The result is uint32_t, which
is the wrong type for 'abs'. Explicitly cast idle_rate to uint32_t,
subtract sof_cnt and then explicitly cast to int32_t and then use abs,
storing the result in another int32_t which matches the return type for
abs.

This quiets clang warnings about passing unsigned values to abs.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-14 01:50:36 +09:00
Daniel DeGrasse e36c31a001 usb: dfu: Enable progressive erase for MCUX FlexSPI flash
Devices using the MCUX FlexSPI flash driver erase their flash too
slowly, causing the usb stack to freeze, and USB DFU utilities to
report a timeout. Enable IMG_ERASE_PROGRESSIVELY for SOCs using the
MCUX FlexSPI driver to prevent this error.

Fixes #45359

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-05-09 08:54:30 -05:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Yuval Peress 53ef68d459 include: Prefix includes to use a scope
Move include paths and add new target_include_directories to support
backwards compatibility:
* /include -> /include/zephyr
  example: <irq.h> -> <zephyr/irq.h>

Issue #41543

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-08 19:03:32 +02:00
Johann Fischer 6be45c2a18 usb: move USB device stack code to own directory
Until now the whole USB device stack code is located
in the top subsys/usb directory. Move it to own directory
in preparation for upcoming extension and rework of USB support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-03-31 18:30:14 +02:00
Martijn Stommels 49cb6537be usb: dfu: add permanent download and automatic reboot
This commit adds the USB_DFU_PERMANENT_DOWNLOAD and USB_DFU_REBOOT and
symbols.When the permanent download symbol is enabled, slot 1 will be
marked as confirmed. With the reboot symbol enabled, the devices
automatically reboots after the download is completed.

The functionality is split into two symbols to allow the automatic
reboot without confirming the image. This enables image confirmation via
another channel. For example via the shell’s Mcuboot commands.

This functionality allows downloading an image to the device without the
user having to interact with the device. It is useful in cases where
ease of use is more important then safety. For example  when using USB
download for daily development. This is especially applicable for
devices with a closed case.

The changes were tested on an nrf52840dk. The following line can be used
to build the USB DFU example with the symbols enabled.

west build -b nrf52840dk_nrf52840 zephyr/samples/subsys/usb/dfu \
-d build-dfu -- -DCONFIG_BOOTLOADER_MCUBOOT=y \
-DOVERLAY_CONFIG=overlay-reboot-permanent.conf \
-DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE\
=\"bootloader/mcuboot/root-rsa-2048.pem\"

Fixes #41921

Signed-off-by: Martijn Stommels <martijn@martijnpc.nl>
2022-03-31 15:33:16 +02:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Krzysztof Chruscinski 47ae656cc1 all: Deprecate UTIL_LISTIFY and replace with LISTIFY
UTIL_LISTIFY is deprecated. Replacing it with LISTIFY.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-08 11:03:30 +01:00
Johann Fischer 3b7807cc9b usb: dfu: disable USB DFU uploading by default
Firmware uploading to the host may not always be desired,
disable it by default.

Enable it for existing USB DFU sample to keep
the usual behavior, add note about new option to README.rst.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-02-18 09:32:22 -08:00
Johann Fischer 09f48c9a4f usb: dfu: rename FLASH_AREA_ID macro
Rename confusing UPLOAD_FLASH_AREA_ID to DOWNLOAD_FLASH_AREA_ID
as it is area where firmware image is downloaded.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-02-18 09:32:22 -08:00
Johann Fischer c51cfee4bf usb: do not add ZLP if lenght to be transmitted is just zero
It is possible that the actual data stage length of
the control transfer is zero, in that case we do not
need an additional ZLP packet.

This fixes a problem with USB DFU, where after an upload
the device is no longer responsive if upload size is
multiple of control endpoint MPS.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-02-18 09:32:22 -08:00
Johann Fischer 1e3f7ca433 usb: add option to initialize USB device support at boot
Possibility to initialize USB device support is useful when
only CDC ACM class is enabled and CDC ACM UART is used as
backend for console, shell, or logging.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-02-07 13:06:35 +01:00
Jacob Caughfield 2abc8cf3b2 usb: Handle USB_DC_RESET event notifications
This patch fixes an issue where mcux usb devices may stop
functioning after a reset event, because they do not
provide a USB_DC_DISCONNECTED event and USB_DC_RESET
events were not handled by the forward status callback.

Signed-off-by: Jacob Caughfield <mlsvrts@protonmail.com>
2022-02-04 22:58:06 +01:00
Alexander Mihajlovic bd4ddec0c8 usb: Add macro for user defined string descriptors
The new macro USBD_STRING_DESCR_USER_DEFINE works like
USBD_STRING_DESCR_DEFINE with the exception of being
ordered strictly after it. The new macro is needed to
ensures that user defined string descriptors can be added
without disturbing the order of string descriptors
defined by the usb subsystem.

Signed-off-by: Alexander Mihajlovic <a@abxy.se>
2022-02-03 14:57:42 +01:00
Johann Fischer 388001456c usb: bluetooth: check buffer tailroom before copying
If HCI packet length is greater than endpoint MPS or currently
received data block (over USB), next block could be larger
than allocated net_buf buffer.

Check buffer tailroom before copying data using net_buf_add_mem().

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-01-26 11:54:31 +01:00
Johann Fischer 0be729de8a bluetooth: hci_raw: avoid possible memory overflow in bt_buf_get_tx()
Function bt_buf_get_tx(), which is used to allocate buffer from
fixed-size pool, does not check size argument before copying
the data with the length size into fixed-size buffer, wich may
not be large enough.

Check immediately before copying if the tailroom of the buffer
is large enough.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-01-26 11:54:31 +01:00
Gerard Marull-Paretas 22a7a5badf usb: class: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Daniel Leung c955a44f13 usb: remove @return doc for void functions
For functions returning nothing, there is no need to document
with @return, as Doxgen complains about "documented empty
return type of ...".

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-01-12 16:02:16 -05:00
Johann Fischer 9bf4fcb673 usb: bluetooth: do not start transfers when USB bus is suspended
Rework suspended to be a shared atomic variable between
bluetooth_status_cb() and hci_tx_thread().
If the bus is suspended, initiate remote-wakeup and
wait until the bus is operational.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-12-14 09:08:58 -05:00
Johann Fischer 5296339fde usb: rework to use macro STRUCT_SECTION_FOREACH
Replace deprecated macro USBD_CFG_DATA_DEFINE by
USBD_DEFINE_CFG_DATA which places usb_cfg_data structures
in specific iterable section.

Replace __usb_data_start, __usb_data_end usage patterns
  size_t size = (__usb_data_end - __usb_data_start);
  for (size_t i = 0; i < size; i++) {...}
by
  STRUCT_SECTION_FOREACH(usb_cfg_data, ...) {...}

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-12-10 07:22:15 -06:00
Jordan Yates df327eeb58 net: buf: POOL_FIXED_DEFINE explicit user data
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Johann Fischer cf8d7764da usb: fix bulk endpoint configuration for high-speed capable device
In the current USB device support, the sizes of bulk endpoint
are mostly configure through Kconfig and do not care if a device
is high-speed capable. The information if a USB device controller
supports high-speed comes from devicetree. Add a Kconfig option to
map this information and configure bulk endpoint sizes
accordingly.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-24 12:28:02 +01:00
Johann Fischer 4151f42710 usb: cdc_acm: use same init level and priority as serial drivers
Use same init level and priority as serial drivers.
Align priority to the changes in
commit ad1450510a ("drivers: serial: Refactor drivers
to use shared init priority Kconfig")

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-18 14:29:18 +01:00
Christopher Friedt 3e86c627f7 kernel: atomics: update print specifiers for atomic_t
The print specifier for `atomic_t` should be updated
to `%ld`, `%lu`, or `%lx` to account for the type
change of `atomic_t` to `long`.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-11-15 09:59:01 -05:00
Emil Gydesen 12decc70d0 Bluetooth: ISO: Add bitmask for retrieving iso header lenght
Add a macro to retrieve the iso data load length (the
length stored in the iso header) with a bit mask that
ensures that we only take the first 14 bits.

This is to remove any RFU bits that may have been set.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-11-12 14:52:33 +01:00
Emil Gydesen 08b1dfb4a2 Bluetooth: ISO: Fix incorrect struct for ISO hdr data
There were a few cases where bt_hci_iso_data_hdr was used
instead of the proper struct bt_hci_iso_hdr.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-11-12 14:52:33 +01:00
Emil Obalski 75c0f52cca usb: Add API for getting status of remote wakeup
This change adds a posibility to check the status of
remote wakeup feature.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2021-11-09 13:50:03 +01:00
Johann Fischer 02c32d4474 usb: move USB_DEVICE_REMOTE_WAKEUP option to drivers
Kconfig USB_DEVICE_REMOTE_WAKEUP option depends only on
USB device controller capability, but is not controlled
by the USB device controller drivers configuration.
Move USB_DEVICE_REMOTE_WAKEUP option to drivers and
make it promptless.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-08 17:01:32 +01:00
Johann Fischer 14c28c45f1 usb: remove USB_SCD_ATTRIBUTES macro
USB_SCD_ATTRIBUTES is a configuration dependent macro
that does not map any part of the spec and does not
belong to usb_ch9 header.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-08 17:01:32 +01:00
Johann Fischer b92ce9a6c1 usb: function_rndis: do not force USB_COMPOSITE_DEVICE for IAD
Just always prove interface association descriptor for RNDIS
function instead of forcing it via Kconfig USB_COMPOSITE_DEVICE
option.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-10-27 11:56:00 +02:00
Johann Fischer 70c25119d1 usb: function_rndis: align rndis_cmd_pool to request buffer size
Set reasonable range for the request buffer in case RNDIS
function is used. Align net_buf size from rndis_cmd_pool to
request buffer size since request is copied there before
it is queued.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-10-27 11:56:00 +02:00
Kumar Gala a3480cf87c usb: Fix building error in usb_descriptor with misra test
When we build tests/kernel/common/kernel.common.misra on
bl654_usb we get the following error:

subsys/usb/usb_descriptor.c:313:2: error: ISO C90 forbids array
'hwid' whose size cannot be evaluated [-Werror=vla]

Fix by removing use of usblen variable in array.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-09-01 12:34:01 -05:00
Eric Johnson 20b710a78e usb: class: cdc_acm: Add check for tx_irq_ena in tx_ready function
cdc_acm_irq_tx_ready was not checking if its interrupt was enabled.
This causes spurious tx irq handler calls.

Signed-off-by: Eric Johnson <eric@liveathos.com>
2021-09-01 11:50:59 +02:00
Johann Fischer 797d8d6a44 usb: dfu: add __fallghrough to DFU_UPLOAD/dfuIDLE case
Add __fallghrough to DFU_UPLOAD/dfuIDLE case.

Coverity-CID: 239607

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-30 13:40:46 -04:00
Johann Fischer 9d45581735 usb: cdc_acm: prefix ringbuffers with cdc_acm
Prefix ringbuffers with cdc_acm because it is not possible
to use static specifier with RING_BUF_*_DECLARE_* macros
to avoid conflicts.

Fixes: #36608

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-30 09:33:09 -04:00
Grixa Yrev 6a8abcb225 usb: cdc_acm: trigger TX IRQ when CDC ACM class is ready
Before commit 4f2682bd79
("usb: cdc_acm: avoid spurious interrupt on configured or resume
events") spurious rx-interrupt provided start to read shell tx ring
buffer by CDC ACM UART. Now shell log backend not transmit data,
until CDC ACM UART received data from host.

This PR added invoking interrupt callback if tx interrupt is enable,
when CDC ACM class go to configured state, and flag tx_ready go to true.

Signed-off-by: Grixa Yrev <GrixaYrev@yandex.ru>
2021-08-26 09:13:42 -04:00
Johann Fischer 1de84d2208 usb: cdc_acm: configure CDC ACM UART instances using devicetree only
Remove the possibility to configure number of CDC ACM UART
instances in Kconfig.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-23 18:53:47 -04:00
Johann Fischer 5e3319f091 usb: cdc_acm: allow to configure CDC ACM UART device from devicetree
Add hidden Kconfig option to Kconfig.cdc and allow
to configure CDC ACM UART device from devicetree.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-23 18:53:47 -04:00
Johann Fischer eb4b9b9cbd usb: finally remove Kconfig option CONFIG_USB
After the modules are adapted for the revised
USB device stack configuration, and it seems that
it was only necessary for MCUboot, we can finally
remove Kconfig option CONFIG_USB.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-17 16:58:58 +02:00
Johann Fischer 4f2682bd79 usb: cdc_acm: avoid spurious interrupt on configured or resume events
Do not submit k_work on on configured or resume events and
avoid spurious interrupt.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-12 16:57:12 -04:00
Johann Fischer 37f4d9ba63 usb: cdc_acm: rework cdc_acm_poll_out to non-blocking
Change cdc_acm_poll_out to do the best to mimic behavior
of a hardware UART controller without flow control.

With this patch, if the USB subsystem is not ready,
no data is transfered to the buffer, that is, new character
is dropped. If the USB subsystem is ready and the buffer is full,
the first character from the tx_ringbuf is removed to
make room for the new character.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-12 16:57:12 -04:00
Johann Fischer 5a35745b44 usb: fix SetInterface handling for interfaces without any endpoints
With the last changes in USB device stack it was unfortunately
not considered that an interface can have no endpoints.
This caused the USB DFU class to stop working in DFU mode.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-05 16:13:10 +02:00
Johann Fischer 3aa48613b1 usb: cdc_acm: add support for poll in to UART driver
Use cdc_acm_fifo_read() to support poll in.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-05 16:08:39 +02:00
Johann Fischer 9973314ea2 usb: cdc_acm: fix CDC ACM IAD initialization
CONFIG_CDC_ACM_IAD option should also be considered.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-05 16:08:39 +02:00
Johann Fischer ef18329051 usb: cdc_acm: rework descriptors, config, and data definitions macros
Simplify and rearrange the macros, remove unnecessary arguments.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-05 16:08:39 +02:00
Johann Fischer 4b79912dc7 usb: check request direction in request handlers
Check request direction in standard device,
interface, and endpoint request handlers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer af3e1096f5 usb: cleanup standard interfave request handler
Cleanup standard device request handler.
Pass pointer to setup packet as argument where
it is reasonable.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 49745250e4 usb: cleanup standard endpoing request handler
Cleanup standard endpoint request handler.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer d2ff6f4fdc usb: cleanup standard device request handler
Cleanup standard device request handler.
Pass pointer to setup packet as argument where
it is reasonable.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 961d4a63fd usb: hid: obtain the requested length from wLength
Obtain the requested length from wLength and assign the
possible length to len argument.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 315e148864 usb: dfu: halt endpoint on flash API error or block mismatch
Halt endpoint on flash API error or block mismatch.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer d6e2c8afa1 usb: dfu: check control request direction
Check control request direction and split class request handler
by request direction.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 7aeed96e5d usb: msc: additionally check control request direction
Rework class control request handler and add control
request direction check.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 4e6bf5b567 usb: bt_h4: return -ENOTSUP on vendor requests
This class does not handle any vendor request,
therefore just return -ENOTSUP on any vendor request.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 4adde81b43 usb: bluetooth: additionally check control request direction
HCI commands are always directed to controller and should be
host-to-device class control requests.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 78b9acf852 usb: audio: additionally check control request direction
Rework mute request handling and add checks for
control request direction.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 37d8236be4 usb: rndis: return error on incorrect/unsupported request
Return ENOTSUP if request is unsupported and pass on the error
from encapsulated command/response functions.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer a5493a5c71 usb: cdc_ecm: return error on incorrect/unsupported request
Control request handler from CDC ECM implementation does not
care at all about returning errors when a request is not supported.
Return EINVAL/ENOTSUP if request is incorrect/unsupported.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer e9f9138997 usb: loopback: use class internal buffer to store request data
Use internal buffer to store request data and not
the data OUT stage buffer.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 5698e17aa0 usb: cdc_acm: enhance verification of the class control requests
Rework CDC ACM class control request handling and
check the control transfer direction.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 781c367730 usb: set data stage length variable to zero by default
Set data stage length variable to zero as a precaution
so that no trouble happens if control request handler
does not check the request values sufficiently.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer ae074e81d4 usb: remove Kconfig option CONFIG_USB
The USB configuration option is actually a global switch
to enable USB drivers in general, but currently only
the device controller drivers are meant.

USB device controller drivers also have USB_DEVICE_DRIVER option.
Thus the option USB is actually redundant and can be replaced
by the self-explanatory option USB_DEVICE_DRIVER.
The name USB itself is not unique and should not be used as an
configuration option.

With these changes the option USB_DEVICE_DRIVER generally
enables USB device controller drivers. The option USB_DEVICE_STACK
enables USB device support. It is sufficient to enable only option
USB_DEVICE_STACK because it selects USB_DEVICE_DRIVER.

CONFIG_USB Kconfig option is temporary added to subsys/usb/Kconfig.
This is necessary to pass CI and will be removed again
when the USB configuration has been adapted in modules.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:00:12 -04:00
Johann Fischer 6408d40fd6 usb: use new USB framework header
Replace all macros and types with the new ones from
usb/usb_ch9.h header.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 13:20:07 +02:00
Aurelien Jarno 0cd3daacba usb: truncate the most significant part of the serial number
When the Hardware Information Driver (HWINFO) provides a device ID
longer than the configured USB serial number, truncate the most
significant part instead of the least significant part. The lower part
is usually having more entropy, e.g. on STM32.

Fixes #34550

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2021-07-24 21:26:06 -04:00
Johann Fischer 244f69d1df usb: audio: prevent unaligned memory access
Prevent unaligned memory access.

Fixes #36873

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-07-20 16:56:26 +03:00
Johann Fischer 8b37c62b35 usb: remove useless len argument from usb_data_to_host()
The len argument always has the same value as
usb_dev.setup.wLength, which is also the last received
USB device request.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-07-19 04:01:22 -04:00
Johann Fischer 7ec174df0d usb: fix request hijack through Audio class workaround
Because it is not always possible to determine whether
a request is for Audio class or not, all requests are passed
to it. This can lead to the requests, to e.g. HID interface,
being hijacked by Audio class.
Ignore return value of Audio custom handler as it is not relevant here.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-06-17 12:41:33 +02:00
Johann Fischer afecdc97ef usb: audio: rework custom request handler callback
Since the settings are stored in the core now,
we can remove REQ_GET_INTERFACE part from custom handler
and simplify the code. Return value is no longer relevant
since custom callback does not need to interfere with the
request handling process.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-06-17 12:41:33 +02:00
Johann Fischer 1e71cef151 usb: store alternate interface settings
Store alternate interface settings and
return alternate on GetInterface request.

Fixes: #24200

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-06-17 12:41:33 +02:00
Johann Fischer 8999c30cee usb: hid: remove get_protocol/set_protocol from USB HID class API
The USB HID class API offers the possibility to register callbacks
for Get/SetIdle, Get/SetProtocol to the application.
Rules for these callbacks are neither obvious nor documented.

This patch remove this possibility to register Get/SetProtocol
and Get/SetIdle callbacks for the following reasons:

The possibility to call unknown application code while processing
control requests should be avoided or reduced to a minimum.

The Get/SetProtocol callbacks are redundant and do not provide any
additional value since the way to inform the application
about the change of the protocol exists via the callback
hid_protocol_cb_t protocol_change.

The core provides implementation to handle Get/SetIdle requests and
on idle reports. If this is not suitable in any way then the application
should implement everything itself.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-05-07 13:14:47 +02:00
Joakim Andersson 6483e12a8a Bluetooth: Refactor bluetooth buffer configuration for simplification
Refactor and simplify the bluetooth buffer configurations to improve the
easy of configurations and eliminate invalid ones.
By moving configurations out of host and controller specific
configurations and into a common one it becomes easier to configure
the host and controller separately as the same configurations can be
used as would be for a combined build.

All HCI configurations are now given exluding the matching HCI header,
which eases the configuration as the application don't have to know the
different header sizes.
The BT_RX_BUF_LEN is split into ACL and Event, as well as the suprising
use of Command size.
BT_L2CAP_RX_MTU is removed as the stack does not support reassembling of
HCI ACL data to larger L2CAP PDUs. The application will have to set
ACL RX size and account for the L2CAP PDU header itself.
BT_EATT_RX_MTU was removed as it is only used for setting a different
default value for another option which leads to the stuck kconfig symbol
problem.

The configurations can be updated according to the table below:

** New configuration         | ** Old configuration
All configurations
BT_BUF_ACL_RX_SIZE           | BT_L2CAP_RX_MTU + 4
BT_BUF_ACL_RX_SIZE           | BT_RX_BUF_LEN - 4
BT_BUF_EVT_RX_SIZE           | BT_RX_BUF_LEN - 2
BT_BUF_CMD_TX_SIZE           | BT_RX_BUF_LEN - 3
BT_BUF_CMD_TX_COUNT          | BT_HCI_CMD_COUNT
BT_BUF_EVT_RX_COUNT          | BT_RX_BUF_COUNT
BT_BUF_ACL_RX_COUNT          | BT_RX_BUF_COUNT
BT_BUF_ACL_RX_COUNT          | BT_ACL_RX_COUNT
BT_BUF_EVT_DISCARDABLE_SIZE  | BT_DISCARDABLE_BUF_SIZE - 2
BT_BUF_EVT_DISCARDABLE_COUNT | BT_DISCARDABLE_BUF_COUNT
Controller-build
BT_BUF_ACL_TX_SIZE           | BT_CTLR_TX_BUFFERS_SIZE
BT_BUF_ACL_TX_COUNT          | BT_CTLR_TX_BUFFER
HCI-bridge
BT_BUF_ACL_TX_SIZE           | BT_HCI_ACL_DATA_SIZE
BT_BUF_ACL_TX_COUNT          | 6

Fixed invalid configurations setting either BT_L2CAP_RX_MTU or
BT_CTLR_DATA_LENGTH_MAX larger than BT_RX_BUF_LEN could lead to buffer
overruns.

Fix advertising report max data length calculation.
This always used the BT_DISCARDABLE_BUF_SIZE macro but this feature
can be turned off and advertising reports will be allocated from the RX
buffer in that case. Also controller-build does not have this buffer
(in hci_raw.c). Also the wrong HCI header was used in the calculation,
HCI event header should have been used instead of HCI ACL header.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-06 14:56:18 +02:00
Aurelien Jarno b61c23943c usb: netusb: rndis: fix a typo
asemble => assemble

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2021-05-01 14:17:39 -04:00
Jennifer Williams a3c7e45a73 usb: usb_device: fix missing final else
set_endpoint() and reset_endpoint() were missing final
else statement in the if else if construct. This commit
adds a final else {} with assert to comply with coding
guideline 15.7.

Signed-off-by: Jennifer Williams <jennifer.m.williams@intel.com>
2021-04-27 17:31:59 -04:00
Gerard Marull-Paretas d7da2a31f0 usb: remove usage of device_pm_control_nop
If device PM is not implemented just use NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-27 16:28:49 -04:00
Trond Einar Snekvik 6976658719 usb: dfu: convert z_timeout_end_calc to sys_clock_timeout_end_calc
The z_timeout_end_calc function was replaced by
sys_clock_timeout_end_calc in #33302. A reference to the old function
snuck into master through #30015.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-26 13:40:29 +02:00
Peter Bigot 2ac596b91a usb: conversion of k_work API
Replace all existing deprecated API with the recommended alternative.

Be aware that this does not address architectural errors in the use
of the work API.

Fixes #34092

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-04-15 12:29:34 -04:00
Dominik Ermel f4b6231a9d usb/dfu: Pick DFU target image label from DTS
Instead of defining the string, that will be reported by DFU
as a name for DFU target, in code, pick it from the DTS label that
will be the DFU target.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-30 09:01:20 -05:00
Dominik Ermel 73b29d68e7 usb/dfu: Removed unused NUMOF_ALTERNATE_SETTINGS
Alternative settings are determined by number of flash partitions
available for DFU from DTS.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-30 09:01:20 -05:00
Johann Fischer f205e94f9e include: move disk_access.h to storage
Zephyr already has a directory for storage API relevant headers.
Move disk_access.h header to include/storage where it fits better
structurally.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-23 12:16:01 +01:00
Josh Gao 16d2ab790c usb: dfu: give wait_for_usb_dfu an argument
Allow callers to wait for an arbitrary amount of time, instead of always
waiting for a compile-time fixed period.

Signed-off-by: Josh Gao <josh@jmgao.dev>
2021-03-22 12:55:56 +01:00
Johann Fischer 91ddb8c9fe usb: hid: allow boot interface Protocol Code to be set per device
Kconfig option USB_HID_PROTOCOL_CODE does not allow to set
boot interface protocol code for specific HID device but
only to set the same value for all device.
Add new API function to allow the application to set
Protocol Code per device. Deprecate USB_HID_PROTOCOL_CODE option.

Fixes: #32778

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-19 09:51:21 -04:00
Johann Fischer 4516ad0bde usb: hid: rework idle report implementation
HID core implementation has support for Get/Set Idle requests and
on idle report processing. Basically it has little use.
Also, it has no users in the tree except samples/subsys/usb/hid,
which does not have it turned on.
There are several issues with the idle report implementation:
- Core calls hid_ops.on_idle callback with Report ID 0,
  but this ID is reserved and should not be used.
  Report descriptors do not use Report ID index zero.
- Calling hid_ops.on_idle with Report ID 0 cann only
  be turned off by calling SetIdle(Duration = 0, Report ID = 0),
  but not by SetIdle with Report ID not equal zero.
- GetIdle with Report Id not equal zero returns wrong
  value after SetIdle(Duration = n, Report ID = 0)
- It may happen that hid_ops.on_idle is called for
  different Report ID during one and the same SoF event.
  But there can be only one hid_int_ep_write() during a frame.

This patch fixes listed issues and revises Get/Set Idle request,
and hid_sof_handler() implementation.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-17 11:34:42 +01:00
Johann Fischer 5533c7ed21 usb: hid: clarify USB_HID_REPORTS configuration
Clarify USB_HID_REPORTS configuration.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-17 11:34:42 +01:00