Commit graph

450 commits

Author SHA1 Message Date
Andrei Emeltchenko b48a8c3247 usb: device: Add composite status callback
Add new status callback with usb_cfg_data parameter to be able to
identify instance callback.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-08 11:23:04 -05:00
Andrei Emeltchenko 9ef8ad412f usb: Refactor usb_interface_config callback
Add interface parameter to interface configuration callback to be able
to configure several instances of the same class.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-08 11:23:04 -05:00
Andrei Emeltchenko b5786aded7 usb: cdc_acm: Correct debug logging
Remove extra newline characters.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-08 11:23:04 -05:00
Andrei Emeltchenko eb86b5ccc5 usb: cdc_acm: Allow to create several CDC ACM devices
Change global device pointer to device list where every device
registers.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-08 11:23:04 -05:00
Andrzej Puzdrowski 40da5f3f40 usb/class/usb_dfu: use predefined string for image descriptors
Use predefined string for images string descriptors instead
of from DTS build-time generated labels.
This labels will be deprecated.

String content are kept the same as before.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-02-08 09:13:09 -06:00
Andrzej Puzdrowski ee7dfc1b34 usb/class/usb_dfu: use flash_map data instead of macro labels
Now flash_map is proper place to obtain all information about
flash-areas boundaries.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-02-08 09:13:09 -06:00
Findlay Feng 6199e97836 usb/class/usb_dfu: align to changes in dfu subsys'es
Changes in flash_map API makes flash_area structure proper
interface for point the image area instead of direct flash-bank-offsets.

This patch align code to changed APIa and allows to support operation
on the partition in any flash device.

Signed-off-by: Findlay Feng <i@fengch.me>
2019-02-08 09:13:09 -06:00
Andrei Emeltchenko f9293a0db3 usb: Remove unused variable
Cleanup code removing unused variable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-05 11:08:24 -05:00
Aurelien Jarno 192fe2a528 usb: class: dfu: always provide payload_data
Given the device can be enumerated as both legacy and composite, we
always need to provide the payload_data buffer.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-02-04 18:46:05 -05:00
Aurelien Jarno b613864c8e usb: class: dfu: fix USB descriptors in composite mode
In composite mode the request handler buffer is common to all functions,
and its size is defined by CONFIG_USB_COMPOSITE_BUFFER_SIZE.

Given the device is enumerated as composite in runtime mode and
as legacy in download mode, we need to define wTransferSize as
the minimum of the two.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-02-04 18:46:05 -05:00
Aurelien Jarno ef2871dec9 usb: class: dfu: use the request handler provided buffer
The upload code assumes the buffer to use is the DFU provide one, and
not the one provided by the request handler, which is different in
composite mode.

This is only a theoretical issue, as this function is only executed
once the device has been re-enumerated in legacy mode, but that is a
required step before unifying legacy and composite code.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-02-04 18:46:05 -05:00
Aurelien Jarno 9550f9c358 usb: class: dfu: fix firmware upload
The flash_read() function takes an offset from beginning of the flash.
This patch subtract FLASH_BASE_ADDRESS from the absolute address. This
fixes DFU firmware upload.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-02-04 18:46:05 -05:00
Aurelien Jarno d77b1c843d usb: class: dfu: fix support for SPI based flash
With an SPI based flash, CONFIG_FLASH_BASE_ADDRESS is not defined. In
that case it is safe to assume that the base address is 0.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-02-04 18:46:05 -05:00
Nicolas LANTZ 766101cf09 usb: netusb: Align NETUSB_MTU & wMaxSegmentSize and increase it to 1522
As rx_buf & tx_buf are defined with a NETUSB_MTU size, this cause
that the frames over 1500 bytes can not be received and are discarded.

Secondly, as fragmentation is not supported (for UDP and TCP datagram),
increase NETUSB_MTU to the maximum possible ethernet frame size :1522

Signed-off-by: Nicolas LANTZ <nicolas.lantz@ubicore.net>
2019-02-04 17:52:35 +01:00
Andrei Emeltchenko bf9c6d72e8 usb: Add instance parameter to descriptors definitions
This allows to place instances of the class one after another in the
linker section.

Fixes #12908

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-01 19:11:32 -05:00
Andrei Emeltchenko 372fb5da51 usb: cdc_acm: Fix composite build
Fixes bug below:
subsys/usb/class/cdc_acm.c:554:15: error: ‘dev_data’ undeclared (first
use in this function) k_work_init(&dev_data->cb_work,
cdc_acm_irq_callback_work_handler); ^~~~~~~~

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-01-24 08:37:16 -05:00
Aurelien Jarno 7f334c84d6 usb: cdc_acm: call the IRQ callback from the system work queue
The IRQ callback function of the USB CDC ACM driver can currently be
called from:
- the USB thread when a bulk in or a bulk out interrupt has been
  triggered
- the thread calling cdc_acm_irq_rx_enable or cdc_acm_irq_tx_enable when
  enabling the interrupt fires an irq (ie if there is data to read or if
  there is no pending data to send)

This causes some issues with at least the shell uart backend, as the
IRQ callback function ends up being called twice concurrently in case a
USB driver sends the requested data almost instantaneously. This is the
case for example of the USB nRF driver which uses DMA. In turn this
cause ring_buf_item_get to be called concurrently, leading to data
corruption:

  uart:~$ help
  Please press the <Tab> button to see all available commandands.
  You can also use the e <Tab> button to prompt or auto-coomplelete all
  commands or its subcommands.
  You can try toto call commands with <-h> or <--help> parameter for
  more informatation.
  uart:~$

Fix that by always calling the IRQ callback function through the system
work queue.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-09 07:47:43 -06:00
Savinay Dharmappa 0fb1a8a836 usb: class: dfu: Add a worker thread to flash data from usb to flash
The bulk of implementation in the current DFU arch is done in the ISR.
This works well when the Flash device is memory mapped as these writes
get done comparatively quickly. However, in case of platforms where
the flash device is sitting on the SPI Bus, this was observed to
cause an exception. This exception may be because there are multiple
function calls consuming larger processing time inside the ISR. The
ISR stack may also end up going deeper and risk stack corruption on
devices with low RAM. To resolve this, we deferred flash write to a
worker thread. Also, some handshaking was added to have synchronization
with the host in accordance with the Host-Device DFU protocol.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-12-30 16:24:33 -05:00
Savinay Dharmappa b9b8daa3bc samples: subsys: usb: dfu: Fix build error for intel_s1000
intel_s1000 uses DT_SPI_NOR_DRV_NAME instead of DT_FLASH_DEV_NAME
for device binding of flash device.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-12-30 16:24:33 -05:00
Marcin Szymczyk 801b54edb9 usb: hid: boot protocol
Set_Protocol and Get_Protocol requests are handled now.
Tested with USB3CV.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-19 07:36:18 -06:00
Aurelien Jarno a1c3b0aad3 usb: fix CDC ACM breakage with CONFIG_USB_DEVICE_SOF
Commit e4c447aac3 ("usb: add SoF event") added support for calling the
status callback with the USB_DC_SOF value for each SoF when
CONFIG_USB_DEVICE_SOF is enabled. The CDC ACM driver saves the latest
received status and compares it USB_DC_CONFIGURED to decide if it can
send data to the host. This therefore doesn't work any more when the
status callback is called regulary with USB_DC_SOF.

Fix that by ignoring USB_DC_SOF when saving the latest received status.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-17 08:16:49 -06:00
Tomasz Bursztyka e97a543e9b net/pkt: Remove parameters to "reserve" some headroom
Such parameter is not used anymore, it was defaulted to 0 previously.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 01a5238ee8 usb/netusb: Let's remove the use for ll reserve
It's useless now.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Marcin Szymczyk c6d5d09d70 usb: hid: allow hid_ops to be null
Allows for hid_ops argument in usb_hid_register_device() to be NULL.
In that case, application does not implement any custom callbacks.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-14 13:19:04 +01:00
Aurelien Jarno 46a1bb7cdd usb: cdc_acm: select SERIAL_HAS_DRIVER and SERIAL_SUPPORT_INTERRUPT
USB CDC ACM is a serial driver like another. Therefore select both
SERIAL_HAS_DRIVER and SERIAL_SUPPORT_INTERRUPT. This allows one to
enable the console driver without having to enable another serial
driver.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-05 08:53:15 -05:00
Aurelien Jarno 3eda3b61f8 usb: cdc_acm: fix interrupt mode
The CDC ACM driver has to emulate the TX and RX interrupts from the USB
ones. However it does not correctly emulate them as "TX buffer empty"
and "RX buffer not empty" interrupts.

For "TX buffer empty" interrupt:
- Reading the interrupt status should not clear the interrupt
- Enabling the interrupt should fire an interrupt if the TX buffer is
  empty
- An interrupt should be triggered when the USB device get configured

For "RX buffer not empty" interrupt:
- Reading the interrupt status should not clear the interrupt
- Enabling the interrupt should fire an interrupt if the RX buffer is
  not empty

This make the a console on the USB CDC ACM port usable for the shell
and the logs.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-05 08:53:15 -05:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Marcin Szymczyk d5b79ff42c usb: hid: implement idle rate
Idle rate functionality has been implemented for HID USB class.
Bassed on Device Class Definition for Human Interface Devices 1.11.
Tested with USB3CV and host with idle rate.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-04 15:58:19 -05:00
Marcin Szymczyk 6a4ddffaf9 usb: hid: default request handlers
HID class now defaults to universal request callbacks in case they
are not provided by the application. This applies to following,
class-specific requests: Get_Report, Set_Report, Get_Idle, Set_Idle,
Get_Protocol and Set_Protocol.
Tested with USB3CV.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-04 15:58:19 -05:00
Tomasz Bursztyka 9464ec3343 net/iface: Switch fully to a one-pass sending logic in net_if
Now instead of such path:

net_if_send_data -> L2's send -> net_if tx_queue -> net_if_tx -> driver
net_if's send

It will be:

net_if_send_data -> net_if tx_queue -> net_if_tx -> L2's send -> driver
net_if's send

Only Ethernet is adapted, but 15.4 and bt will follow up.
All Ethernet drivers are made compatible with that new scheme also.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Andrei Emeltchenko e209ebe05a usb: device: Use sys_le16_to_cpu conversion
USB protocol is Little Endian so make conversions.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-30 07:58:31 -08:00
Flavio Ceolin 98d03266f1 serial: Change poll_out signature
poll_out function was returning the character that was sent. It
happens that it is always constant and the return of this functions is
never tested. Changing it to be a void function.

MISRA-C rule 17.7

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-29 10:18:59 -08:00
Andrei Emeltchenko 575bd0bbc9 usb: Fix unaligned access
Use sys_put_le16() for unaligned access, this is refactored work of
PR #8495
PR #11432

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-26 09:13:56 -08:00
Marcin Szymczyk e4c447aac3 usb: add SoF event
Start of Frame events can now be accessed from USB classes.
This will be useful when implementing idle rate functionality.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-11-23 09:18:41 -05:00
Savinay Dharmappa 0576f93ff8 usb: class: hid: Fix fault due to unaligned access
patch fix fault due to unaligned access while setting hid
report size on xtensa platform.

Fixes #11266

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-11-21 12:25:22 -05:00
Anas Nashif 065903f3c7 usb: netusb: fix log level macro
Using the wrong Kconfig for log level.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-15 15:24:32 -05:00
Andrei Emeltchenko db42716cde usb: msc: Check input parameters for class handle
Fixes USB Certification tests for class requests.

Fixes #11359

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-14 23:54:08 -05:00
Andrei Emeltchenko 5bf12356e2 usb: msc: Do not give warning after SET_INTERFACE
Add USB_DC_INTERFACE 'handling'.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-14 23:54:08 -05:00
Andrei Emeltchenko 3f698494bb usb: msc: Set default Serial Number string
According to the "USB Mass Storage Class" Spec. the serial
number shall contain at least 12 valid digits, represented
as a UNICODE string.

Fixes: #11336

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-14 23:54:08 -05:00
Andrzej Głąbek 20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
These changes were obtained by running a script  created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:

1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
   #define X Y)
3. Check if that name is also the name of a Kconfig option
   3.a If it is, then do nothing
   3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
       has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
   (.c, .h, .ld)

Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.

Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Kumar Gala e8587f4493 usb: Make USB_VBUS_GPIO a Kconfig option
Previously we had a set of magic #define's in board.h that would both
enable and set the GPIO controller & pin if a given board used a GPIO
for USB VBUS.  Now we make it a proper Kconfig set of options that
specify if the feature is needed, the GPIO controller device name, and
pin number.  In the future this should move to devicetree.

Updated the related boards that used this feature to set the Kconfig
options in the Kconfig.defconfig

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-13 07:10:04 -06:00
Andrei Emeltchenko 40f7a49ffe usb: hid: Trivial syntax fix
Fix typo

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-13 12:41:39 +01:00
Andrei Emeltchenko 85cfe33262 usb: hid: Define helper definitions and cleanup code
Use newly defined definitions for cleaning the code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-13 12:41:39 +01:00
Andrei Emeltchenko f6a20b83d6 usb: hid: Implement Return HID Descriptor
Resolves certification USB tests.
Fixes #11321

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-13 12:41:39 +01:00
Krzysztof Chruscinski 97345dbb1b logging: Fix errors in log usage
Couple of findings which were revealed after changing
LOG_MODULE_REGISTER macro:
- missing semicolons after LOG_MODULE_REGISTER()
- missing LOG_LEVEL defines
- other

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Andrei Emeltchenko 93bd26343e usb: logs: Rename USB_WRN to LOG_WRN
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko f22060cdbe usb: logs: Rename USB_INF to LOG_INF
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko 17f7abd3dc usb: logs: Rename USB_ERR to LOG_ERR
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko 92c7ab74c0 usb: logs: Rename USB_DBG to LOG_DBG
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Aurelien Jarno fdfa975b9d usb: device: fix wrong direction in usb_transfer_ep_callback
In case no transfer is ongoing, the usb_transfer_ep_callback consumes
the received data. This is however associated with the wrong test. USB
is host centric, so data reception on the device is signaled by
USB_DC_EP_DATA_OUT and not USB_DC_EP_DATA_IN.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-05 16:33:01 +01:00
Kumar Gala f05888446d subsys: usb_device: Fix removal of board.h
Restore including board.h to get USB_VUSB_EN_GPIO and associate defines
if the board.h sets them.  This should move to device tree in the
future.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-02 14:55:53 -04:00
Kumar Gala cabdf5e9dd subsys: Remove board.h include
The subsys code doesn't need anything from board.h so lets remove the
include.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:15:18 +01:00
Kumar Gala 42dc4e9b51 usb: device: Fix compile warning
/home/galak/git/zephyr/subsys/usb/usb_device.c: In function ‘usb_transfer_work’:
/home/galak/git/zephyr/subsys/usb/usb_device.c:1156:58: error: passing argument 4 of ‘usb_dc_ep_write’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   ret = usb_dc_ep_write(ep, trans->buffer, trans->bsize, &bytes);
                                                          ^
In file included from /home/galak/git/zephyr/include/usb/usb_device.h:39:0,
                 from /home/galak/git/zephyr/subsys/usb/usb_device.c:68:
/home/galak/git/zephyr/include/drivers/usb/usb_dc.h:270:5: note: expected ‘u32_t * const {aka long unsigned int * const}’ but argument is of type ‘int *’
 int usb_dc_ep_write(const u8_t ep, const u8_t *const data,
     ^~~~~~~~~~~~~~~
/home/galak/git/zephyr/subsys/usb/usb_device.c:1168:8: error: passing argument 4 of ‘usb_dc_ep_read_wait’ from incompatible pointer type [-Werror=incompatible-pointer-types]
        &bytes);
        ^
In file included from /home/galak/git/zephyr/include/usb/usb_device.h:39:0,
                 from /home/galak/git/zephyr/subsys/usb/usb_device.c:68:
/home/galak/git/zephyr/include/drivers/usb/usb_dc.h:328:5: note: expected ‘u32_t * {aka long unsigned int *}’ but argument is of type ‘int *’
 int usb_dc_ep_read_wait(u8_t ep, u8_t *data, u32_t max_data_len,
     ^~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-10-29 10:52:00 -04:00
Pawel Dunaj 8d55b03414 subsys: usb: class: hid: Allow control of USB poll interval
This closes issue #10807

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2018-10-25 12:54:24 +01:00
Andrei Emeltchenko a6340c588d usb: loopback: Add documentation markers
Add markers to the code to be included in the USB documentation.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-24 11:18:12 +01:00
Andrei Emeltchenko 4bec02019b usb: logs: Remove newlines from the logs
Fixes double newline in the logger output.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-18 09:45:29 -04:00
Andrei Emeltchenko 557f0ed72e usb: Enable log level menu after enabling module
This makes menuconfig much more readable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-15 12:58:27 -04:00
Andrei Emeltchenko cfa04c318e netusb: Remove ifdef registration for functions
netusb functions are now registered when interface is selected or
configured.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko 216b1457ed netusb: Move init() to separate functions
Move init() invocation to function code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko 91fc0bcd50 netusb: Register each function
Register each function found in the linker USB data cfg section.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko 6b3c096a95 netusb: Refactor RNDIS code
Move RNDIS functionality from netusb to function_rndis.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko 0db9062cdb netusb: Refactor EEM code
Move EEM functionality from netusb to function_eem.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko fd1ac0f209 netusb: Refactor ECM code
Move ECM functionality from netusb to function_ecm making defines not
needed in many cases.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Aurelien Jarno 124f5776a7 usb: device: fix the log level of a debug message
When using composite devices, an error is printed during the
initialization:

| [00:00:00.000,000] <err> usb_device: set cb, ep: 0x81
|
| [00:00:00.000,000] <err> usb_device: set cb, ep: 0x1
|
| [00:00:00.000,000] <err> usb_device: set cb, ep: 0x82
|
| [00:00:00.000,000] <err> usb_device: set cb, ep: 0x2

This is actually not an error, but rather a debug message. In addition
it should not contain a new line as it is automatically added by the
logger subsystem.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-10-10 17:48:55 -04:00
Andrei Emeltchenko 1eb6a01723 usb: Use const for status_callback parameter
usb_dc_status_callback() parameters are interface or configuration
numbers and should be const.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-10 09:21:55 -04:00
Andrei Emeltchenko adf056dc92 usb: Use always single callback definition
Use one callback type, remove duplicates.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-10 09:21:55 -04:00
Andrei Emeltchenko 82a5ee0cad usb: hid: General code cleanup
Trivial style cleanup.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-10 09:21:55 -04:00
Andrei Emeltchenko 3288da9c0b usb: hid: Add status_cb to hid ops
Adding status callback allows to control report sending only when i.e.
device is connected or configured.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-10 09:21:55 -04:00
Paweł Zadrożniak a6134a374e subsys: usb: Change the buffer fragmentation for IN transfers.
USB controller was performing the fragmentation by itself and the driver
was not aware if current chunk is the last one if data size is equal to
maximum chunk size. Some hardware controllers (i.e. in nRF52840) handle
the status stage by hardware which must be triggered after the last data
chunk.
Currently, the whole remaining data is passed to the driver, and the
driver decides whether to fragment the data internally, or send only
the chunk and report back to the stack.

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2018-10-09 21:37:51 +02:00
Yannis Damigos d1a655a624 subsys/usb: Move to new logger subsystem
Move to new logger subsystem.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-08 12:54:57 -04:00
Jukka Rissanen 009e4dafa7 net: Make Kconfig template variables prettier
Adding spaces around "=" when definining Kconfig template so
that is more consistent with overall style of these template
variables.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-05 09:01:37 -04:00
Jukka Rissanen ac88baca02 usb: net: Convert to use new logging
Convert the USB networking to use the new logging system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 4851e2ea1b usb: Fix net_hexdump_frags() parameters
One parameter was missing when calling net_hexdump_frags() which
caused compile error.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Savinay Dharmappa 6b44a00336 subsys: usb: class: hid: Add OUT interrupt endpoint
patch add a OUT interrupt endpoint descriptor and registers a
corresponding notification callback with usb driver, which is invoked
when data is sent to device from host.

Implement the read ready notification as suggesteed by
Aurelien Jarno <aurelien@aurel32.net>

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-08-27 18:59:58 -04:00
Flavio Ceolin 0866d18d03 irq: Fix irq_lock api usage
irq_lock returns an unsigned int, though, several places was using
signed int. This commit fix this behaviour.

In order to avoid this error happens again, a coccinelle script was
added and can be used to check violations.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-16 19:47:41 -07:00
Ulf Magnusson 8cf8db3a73 Kconfig: Use a short, consistent style for prompts
Consistently use

    config FOO
            bool/int/hex/string "Prompt text"

instead of

    config FOO
            bool/int/hex/string
            prompt "Prompt text"

(...and a bunch of other variations that e.g. swapped the order of the
type and the 'prompt', or put other properties between them).

The shorthand is fully equivalent to using 'prompt'. It saves lines and
avoids tricking people into thinking there is some semantic difference.

Most of the grunt work was done by a modified version of
https://unix.stackexchange.com/questions/26284/
how-can-i-use-sed-to-replace-a-multi-line-string/26290#26290, but some
of the rarer variations had to be converted manually.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-15 04:10:10 -07:00
Oleg Zhurakivskyy ac92a01f5a net: ipv6: Refactor IPv6 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-13 13:53:14 +03:00
Ulf Magnusson ec3eff57e0 Kconfig: Use the first default with a satisfied condition
Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

  1. It's inconsistent with how Kconfig works in other projects, which
     might confuse newcomers.

  2. Due to oversights, earlier 'range' properties are still preferred,
     as well as earlier 'default' properties on choices.

     In addition to being inconsistent, this makes it impossible to
     override 'range' properties and choice 'default' properties if the
     base definition of the symbol/choice already has 'range'/'default'
     properties.

     I've seen errors caused by the inconsistency, and I suspect there
     are more.

  3. A fork of Kconfiglib that adds the patch needs to be maintained.

Get rid of the patch and go back to standard Kconfig behavior, as
follows:

  1. Include the Kconfig.defconfig files first instead of last in
     Kconfig.zephyr.

  2. Include boards/Kconfig and arch/<arch>/Kconfig first instead of
     last in arch/Kconfig.

  3. Include arch/<arch>/soc/*/Kconfig first instead of last in
     arch/<arch>/Kconfig.

  4. Swap a few other 'source's to preserve behavior for some scattered
     symbols with multiple definitions.

     Swap 'source's in some no-op cases too, where it might match the
     intent.

  5. Reverse the defaults on symbol definitions that have more than one
     default.

     Skip defaults that are mutually exclusive, e.g. where each default
     has an 'if <some board>' condition. They are already safe.

  6. Remove the prefer-later-defaults patch from Kconfiglib.

Testing was done with a Python script that lists all Kconfig
symbols/choices with multiple defaults, along with a whitelist of fixed
symbols. The script also verifies that there are no "unreachable"
defaults hidden by defaults without conditions

As an additional test, zephyr/.config was generated before and after the
change for several samples and checked to be identical (after sorting).

This commit includes some default-related cleanups as well:

  - Simplify some symbol definitions, e.g. where a default has 'if FOO'
    when the symbol already has 'depends on FOO'.

  - Remove some redundant 'default ""' for string symbols. This is the
    implicit default.

Piggyback fixes for swapped ranges on BT_L2CAP_RX_MTU and
BT_L2CAP_TX_MTU (caused by confusing inconsistency).

Piggyback some fixes for style nits too, e.g. unindented help texts.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-10 12:38:28 -07:00
Oleg Zhurakivskyy fbac80bb94 net: ipv4: Refactor IPv4 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-09 16:25:17 +03:00
Paul Sokolovsky 57286afdd6 drivers: uart: Allow to pass arbitrary user data to irq callback
Zephyr UART drivers offer very low-level functionality. Oftentimes,
it would be useful to provide higher-level wrappers around UART
device which would offer additional functionality. However, UART
driver irq callback routine receives just a pointer to (low-level)
UART device, and it's not possible to get to a wrapper structure
(without introducing expensive external mapping structures). This
is an indirect reason why the current UARt wrappers - uart_pipe,
console - are instantiated statically just for one underlying UART
device and cannot be reused for multiple devices.

Solve this by allowing to pass an arbitrary user data to irq
callback, set by new uart_irq_callback_user_data_set() function.
Existing uart_irq_callback_set() keeps setting a callback which
will receive pointer to the device.

While public API maintains compatibility, drivers themselves need
to be updated to support arbitrary user data storage/passing (as
legacy uart_irq_callback_set() functionality is now implemented in
terms of it).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-02 19:20:12 +02:00
Ulf Magnusson d1684a83a4 Kconfig: Clean up some symbol definitions
- Remove redundant 'n' defaults. 'n' is the default value for bool
  symbols.

  This makes the auto-generated documentation clearer as well: You get
  "implicitly defaults to n" instead of
  "- n if <propagated dependencies>".

- Shorten

      <type>
      prompt "foo"

  to

      <type> "foo"

  This works for all types, not just bool.

- Various formatting nits.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-01 12:47:17 -04:00
qianfan Zhao 32e6d0ca87 usb: set SN string descriptor at runtime
implement a method that can set SN string descriptor at runtime.
but runtime SN and default SN configured in Kconfig must has the
same length.

Fixes: #6593

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-07-16 17:20:58 +02:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Andrei Emeltchenko c8af08e5d4 usb: osdesc: Use definition for string descriptor index
Use definition and add description block.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 25afcc574f usb: device: Refactor vendor_handler
Since vendor commands cannot assume that wIndex keeps interface number
we change logic trying to call every vendor handler which should check
input parameters.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko c2fdfbb835 usb: rndis: Use RFC 7042 Doc value for Host MAC
Use similar RFC 7042 Documentation value like it is in CDC ECM.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 7b0e9d7c53 usb: composite: Add handling osdesc feature
Add handling osdesc feature also for composite configuration.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko d8da50a30d usb: rndis: Set subCompatibleID parameter for exact MS driver
Set subCompatibleID value according to "C:\Windows\INF\rndiscmp.inf"
file. The exact matching part is:
"USB\MS_COMP_RNDIS&MS_SUBCOMP_5162001"

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 93dd1b99c2 usb: rndis: Add MS OS v1 descriptors to RNDIS
This should allow automatic driver loading in MS Windows.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 59e9cd0f13 usb: osdesc: Add MS OS Descriptors version 1 support
Add support for MS OS Descriptors. The patch structures already
existing code for webusb to the single place to be easy added to other
places.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko a19b469ae3 usb: Cleanup code style for usb_device
Make usb_device code consistent with the rest of the code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 44b7076c22 usb: Correct include path
This makes possible to include headers from subsys/usb

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Johann Fischer 25b0212fc3 subsys: usb: class: add loopback function
Add loopback function. This function can be used to test
USB device drivers and device stack connected to linux host
and has the similar interface as "Gadget Zero" [1] of the Linux
kernel.

Use modprobe usbtest to load the module, see also [2] for the
description of the tests and for Vendor and Product ID of the
"Gadget Zero". The userspace tool testusb [3] is needed to start
the tests.

[1] linux/drivers/usb/gadget/function/f_loopback.c
[2] linux/drivers/usb/misc/usbtest.c
[3] linux/tools/usb/testusb.c

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-07-06 11:56:16 -05:00
Johann Fischer 3a471e3240 subsys: usb: stall if there is no data buffer
Return a STALL in the setup or data stage if there is no data buffer.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-07-06 11:56:16 -05:00
Johann Fischer 1b5775249d usb: add callback codes for Set/Clear Feature ENDPOINT_HALT
Add callback codes for Set/Clear Feature ENDPOINT_HALT.
These can be used to inform a function that the device stack has
received Set/Clear Feature request ENDPOINT_HALT. The function can
then abort or restart the transfer accordingly.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-07-06 11:56:16 -05:00
Andrei Emeltchenko 7cb8689397 usb: netusb: Add ethernet_init()
After PR #8608 every driver should call ethernet_init(), fixes missing
chunks of that PR.

Fixes: #8752

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-05 09:56:53 -04:00
Johann Fischer 06ac62ed32 usb: usb_descriptor: fix null pointer dereference
Fix possible null pointer dereference if the device
descriptor is not complete.

Fixes: #8700
Coverity-ID: 186841

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-07-03 14:28:46 -04:00
Anas Nashif 964979f539 usb: mark unused arguments correctly
use ARG_UNUSED instead of making variable equal itself.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-07-01 22:58:23 +02:00
Paweł Zadrożniak f3d1b22487 subsys: usb: Fixes USB DFU class by updating the bcdUSB value.
bcdUSB has been previously updated from 1.1 to 2.0 in default
device descriptor, but not in DFU class. After USB bus reset
performed by dfu-util, alternative descriptor is registered
with bcdUSB set to 1.1. This mismatch causes communication failure.
DFU descriptor's bcdUSB has been updated to match default one.

Relates to #7570

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2018-06-27 13:38:12 +02:00
Johann Fischer c36e800e8e usb: remove all CONFIG_*_EP_ADDR options
Remove all CONFIG_*_EP_ADDR options but keep the default
values for it, as they are necessary to find ep_addr in
usb_ep_cfg_data associated with bEndpointAddress in
interface descriptor.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-22 12:30:55 -04:00
Andrei Emeltchenko c1724f65bf usb: bos: Add USB BOS descriptors API
Add API for USB BOS Descriptors.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-06-20 15:47:00 -04:00
Andrei Emeltchenko f07275e6e6 usb: trivial: Remove unneeded braces
Clean up the code

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-06-20 15:47:00 -04:00
Andrei Emeltchenko b25567eab8 usb: Allow to enable stack on native_posix arch
At the moment USB Device stack is not possible to enable for
native_posix architecture since there is not USB controller.
The patch allows to enable stack making possible to use it in unit
tests.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-06-20 15:47:00 -04:00
Sathish Kuttan a3095087aa subsys: usb: Make HID payload size configurable
The payload size was hardcoded to 64.
This commit adds a configuration option to choose > 64 bytes
when the device allows larger packets.
A configuration option USB_HID_MAX_PAYLOAD_SIZE is added in
subsys/usb/class/hid/Kconfig
The default value is set to 64

Signed-off-by: Sathish Kuttan <sathish.k.kuttan@intel.com>
2018-06-19 20:16:18 -04:00
Johann Fischer 085a8b75c5 usb: hid: fix write to interrupt IN endpoint
A HID application can no longer write to the default
interrupt IN endpoint because the addresses are assigned
dynamically. Add hid_int_ep_write() function  and leave
it to the hid-core to call the usb_write() with the correct
endpoint address.

fixes: #8424

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-16 11:46:56 +02:00
Johann Fischer 32cac08e55 usb: class: adapt functions for new composite interface
Adapt functions for new composite interface.

Assign bInterfaceNumber and similar variables of a Interface
default values, these should be valid values for non-composite
configuration. For the case of the composite configuration,
these variables must be set by the interface configuration
function (interface_config) accordingly.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 1383dad8a7 subsys: usb: rework composite device support
This patch reworks composite device support. It allows the
functions to be modular and the user to combine its own
functions with the USB functions of the Zephyr OS.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 1237549082 subsys: usb: configure Interface descriptor at runtime
Introduce function to configure interface descriptor at runtime.
It is simple to leave the corresponding function to configure the
interface descriptor and fix bInterfaceNumber and iInterface values,
for example.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer bf332d0004 subsys: usb: validate and update endpoint address
Add the routine to validate endpoint address and update the endpoint
descriptors and usb_ep_cfg_data at runtime.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 18b27b7f9d subsys: usb: fetch endpoint address from usb_ep_cfg_data
This patch changes all class functions so that the endpoint
address will be retrieved from the usb_ep_cfg_data at runtime.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 6807f3a826 subsys: usb: move descriptor parts to the class drivers
This patch moves the descriptor parts to related class
and function drivers and extends the usb_fix_descriptor
function so that the wTotalLength and bNumInterfaces
are corrected before enumeration.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 589dbc4cd8 subsys: usb: add function to find and fix USB descriptors
This patch introduces a function to find and correct all string
descriptor.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 0fca16443a subsys: usb: rework usb string descriptor fixup
This patch simplifies the handling of the string descriptors.
It introduces common macro for all string descriptors to
calculate the length of the bString.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Aurelien Jarno a55c72d35f subsys: usb/class/hid: make interrupt endpoint size configurable
The Kconfig option HID_INTERRUPT_EP_MPS does not have a prompt entry,
so it is not configurable in practice. Fix that.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-06-13 21:07:09 -04:00
Johann Fischer 1ce6a6eaa8 subsys: usb: update bcdUSB to 2.00
Update bcdUSB to 2.00

resolves #7570

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-11 17:31:15 -04:00
Loic Poulain 452cb61844 usb: bluetooth: Use transfer API for ACL packets
Use transfer API for ACL out transfers. No extra buffer is requested,
directly use the net buf and update its len on transfer completion.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-06-11 17:28:27 -04:00
Loic Poulain 00a6b4c5ae usb: bluetooth: Fix assert due to unreserved headroom
Bluetooth net buffers have 1-byte reserve, which can be used by HCI bus
driver (uart, spi...) to set packet type (H4).
This fixes assert when building hci_usb with CONFIG_NET_BUF_SIMPLE_LOG.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-06-11 17:28:27 -04:00
Loic Poulain 51fecf80d9 usb: bluetooth: Add TX thread
Calling bt_send from IRQ context is not safe, at least in HCI SPI case.
In the same way as hci_core, create a thread for TX.
This fixes hci_usb sample for 96b_carbon board.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-06-11 17:28:27 -04:00
Andrei Emeltchenko 73009d05ce usb: cdc_acm: Set bInterfaceProtocol to No Protocol (0)
Do not set protocol in interface descriptor. Although this field has
been ignored by major OSs during the last decades, this creates a big
deal of problems with ModemManager sending unexpected AT commands when
plugging in a dev board.

Fixes: #6646

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-30 09:05:40 -04:00
Johann Fischer cb0dd0cc93 usb: function_eem: fix eem_read_cb
This patch prevents eem_read_cb from trying to allocate a lot of memory.

It may happen that EEM payload size is zero, the eem_read_cb then tries
to allocate a buffer which is 0xfffc bytes large and luckily blocks.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-28 12:47:32 -04:00
Andrei Emeltchenko fc8bcb9a1b usb: netusb: Refactor function's status callbacks
Refactor functions status callbacks for netusb ECM, EEM and RNDIS.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 7a6f1c9884 usb: netusb: Implement status callback for RNDIS
Implement status callback

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 1d5692a7b6 usb: netusb: Implement status callback for EEM
Implement status callback.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 851195bfe3 usb: netusb: Implement status callback for ECM
Implement status callback.

Fixes: #7364

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 3497791372 usb: netusb: Use function - defined status callbacks
Allow functions to define status callbacks

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 5135a73391 usb: netusb: Add subsys/usb to include list
This helps to source files without ../../ etc paths.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Kumar Gala b0e697cc43 subsys: usb: Remove undefined CONFIG_USB_DEVICE_HID_BOOTP
The Kconfig symbol CONFIG_USB_DEVICE_HID_BOOTP isn't defined anywhere,
so remove dead code associated with it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-05-25 08:04:36 -05:00
Kumar Gala 5013cca676 usb: rndis: Rename CONFIG_RNDIS_TX_BUF_* and CONFIG_RNDIS_CMD_BUF_*
Rename CONFIG_RNDIS_TX_BUF_* to CFG_RNDIS_TX_BUF_* and rename
CONFIG_RNDIS_CMD_BUF_* to CFG_RNDIS_CMD_BUF_*.  The CONFIG options where
not exposed in Kconfig so limit use of CONFIG_ to Kconfig only symbols.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-05-23 17:57:06 -04:00
Johann Fischer 4b0b65c1b8 subsys: usb: check for invalid descriptor type request
Implementation of Get Descriptor Request should not return interface
or endpoint descriptors in a single request without configuration
descriptor, see USB Spec. Revision 2.0, 9.4.3 Get Descriptor

This patch fixes linux kernel usbtest subtest 7 and subtest 11 errors.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-14 17:24:52 -04:00
qianfan Zhao 63ffbe9dcb usb: usb_device.c: rewrite if condition judgment
The 'if condition' in usb_handle_control_transfer is diffcult
to understand. So I rewrite another version.

Fixes #7340

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-05-14 17:23:21 -04:00
qianfan Zhao 4e324e2171 usb: dfu: fix 'this area can not be overwritten'
fix issue #7336

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-05-10 16:26:38 -07:00
Ramakrishna Pallala 2b5b7da9f3 subsys: disk: Add support for multiple disk interfaces
Add support for enabling multiple disk interfaces (Flash, RAM)
simultaneously in Zephyr by introducing a simple disk interface
framework where we can register multiple disks which would
interface with different storage devices. This would enable us
to have multiple instances of FATFS in Zephyr.

Add support for mass storage drive disk name which will be
used as an argument when calling the disk interface API's.

Enable multiple volumes support configuration in
ELM FAT library.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-08 08:53:01 -04:00
Johann Fischer b2ca5ee5bc subsys: usb: rework USB DFU class driver
This patch moves USB DFU class driver to subsys/usb/class.

For the first the USB DFU class driver depends on DFU image
manager and partition layout and is limited to use as an
application for the bootloader. The driver fetches the
information about the flash, erase block size, write block
size and partitions offset from the DT now. The driver has
two interfaces associated with the two partitions "SLOT-0"
and "SLOT-1". The "SLOT-0" can only be read.

In the following work the class driver can be extended so
that it can be used from the bootloader and update a flash
region directly from the bootloader.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-04-30 17:42:40 -04:00
Andrei Emeltchenko 222aa6009c netusb: rndis: Fix RNDIS always disabled state
Fix regression with RNDIS due to different USB configuration method.
RNDIS drivers in Windows never call Set Interface and netusb is always
disabled. Change to enable netusb upon USB Set Configuration.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-26 16:30:29 +03:00
Andrei Emeltchenko 185f2be681 netusb: rndis: Add more debugs
Add debug for enable / disable callbacks

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-26 16:30:29 +03:00
Andrei Emeltchenko 7e067414cd usb: Remove unneeded header include
The should be included from sources

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-25 07:17:42 +05:30
qianfan Zhao b7862eb832 hid: core: truncated wLength if it doesn't match report descriptor size
Some buggy system may be pass a larger wLength when it try read
HID report descriptor, although we had already tell it the right
descriptor size.

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-04-21 07:01:36 -07:00
Andrei Emeltchenko 53410af994 usb: Add Bluetooth device class core functionality
Implement Bluetooth over USB functionality through Bluetooth raw
access to the Bluetooth controller. Most devices with Bluetooth and
USB controllers supported by Zephyr can export themselves as USB
Bluetooth dongles.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 0322af5896 usb: Add Bluetooth device decriptors
Add USB Bluetooth device descriptors to usb_descriptor table.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 4d703b1e14 usb: Add Bluetooth USB Device configuration options
Add USB_DEVICE_BLUETOOTH option

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 1653254924 usb: mass_storage: Use simpler header include
Use searched dirs for descriptor headers

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 6239341add usb: Add subsys/usb for device descriptor header
Support device descriptor header easy access

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 773f3e18bb usb: Add sys_cpu_to_le16() conversion for USB field
Add missing conversion.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Michael Hope dbb2264454 usb: hid: implement set_report()
set_report() is used by the host to set a feature on the device such
as turning a LED on or off.

This is also used by protocols such as FIDO U2F to transfer data to
the device.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-04-06 23:06:07 -04:00
Michael Hope 0d04aef6fe usb: hid: add a INT IN transfer complete callback.
int_in_ready is an optional callback that is called when the current
interrupt IN transfer has completed.  This can be used to wait for the
endpoint to go idle or to trigger the next transfer.

This is needed for protocols like FIDO U2F that use the interrupt
endpoint for transfers.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-04-06 23:06:07 -04:00
Loic Poulain d80ae8aeeb usb: netusb: Add CDC EEM network usb function
Add CDC Ethernet Emulation Model function driver. This usb network
function can be used for ethernet over USB. Ethernet packet are
encapsulated within EEM packets. An EEM pkt contains 2-byte header
and 4-byte sentinel (or crc).

Note that EEM packets can be split across USB packets but shall not
be split across USB transfers.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-04-06 06:50:34 -04:00
Loic Poulain 992e32842b usb: netusb: Rework netusb media connect/disconnect
Consider media connected when interface is selected by the host and
disconnected on device diconnection.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-04-06 06:50:34 -04:00
Jukka Rissanen de13e979fc net: if: vlan: Add virtual lan support
This allows creation of virtual lan (VLAN) networks. VLAN support is
only available for ethernet network technology.

Fixes #3234

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 08:54:19 -04:00
Andrei Emeltchenko 4291fb67a3 usb: Remove duplicated CDC_ECM_SUBCLASS definition
Use ECM_SUBCLASS instead.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-04 08:21:06 -04:00
Andrei Emeltchenko 75397485ba usb: hid: Fix setting report size for composite configuration
Fixes usb_set_hid_report_size() not called for composite configuration

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-03 15:58:33 -04:00
Michael Hope 29f4e18af4 cdc_acm: fix interrupt handling, API registration, and propgate errors.
As per uart_pipe.c, irq_is_pending should only return true if any
*unmasked* interrupts are pending.

The device_get_binding() code only checks devices that have an API.
Set the API at compile time so that other devices can refer to the CDC
ACM driver.

usb_write() may return EBUSY if the endpoint is full.  Propagate this
for future use.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-28 11:17:14 +02:00
Michael Hope 4e7deb49b9 usb: netusb: implement the ethernet interface.
net_eth_get_hw_capabilities() calls .get_capabilities() which is part
of the ethernet API but not the net_if_api that netusb implements.
This causes a fault as .get_capabilities() was past the end of the
struct and resolved to a random address.

Also, make the API const and give it a unique name.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-28 09:36:55 +03:00
Anas Nashif 993c350b92 cleanup: replace old jira numbers with GH issues
Replace all references to old JIRA issues (ZEP) with the corrosponding
Github issue ID.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-03-26 13:13:04 -04:00
Michael Hope 4d6d04d3ea hid: change the API table to const.
A minor change to put the API function table into flash.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-21 19:45:11 -04:00
Johann Fischer c0c4dfc6ea subsys: usb: usb_descriptor: fix style and function declaration
Fix style and function declaration

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-03-21 15:39:56 -04:00
Loic Poulain ccf0b46a31 usb: usbnet: ecm: Use transfer API
Replace low-level usb_read/usb_write with transfer functions.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain c97d9c6c27 usb: netusb: consider media connected on interface selection event
The interface and its enpoints are only enabled once interface is
selected by the host.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain b4d305d752 usb: call status_callback on interface set
Add new status event indicating an interface has been selected.
Interface and its endpoint(s) are enabled.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain ddb1b8f6c7 usb: usbnet: Add USBNET_MTU definition
This value can be used in sub-functions for buffer mgmt.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain 16921b0698 usb: Add transfer management API
The transfer API provides 'high' level functions to manage sending and
reception of USB data. A USB (class) driver has to register the generic
usb_transfer_ep_callback as endpoint status callback in order to use
the API.

With this API, the class driver does not need to take care of low-level
usb transfer management (packet splitting, ZLP, synchronization...).
The usb_transfer methods will split transfer into multiple transactions
depending endpoint max size and controller capabilities.

Once the transfer is completed, class driver is notified by a callback.
The usb_transfer method can be executed in IRQ/atomic context.
A usb_transfer synchronous helper exists which block-waits until
transfer completion.

In write case, a transfer is complete when all data has been sent.
In read case, a transfer is complete when the exact amount of data
requested has been received or if a short-pkt (including ZLP) is
received.

transfer methods are thread-safe.

A transfer can be cancelled at any time.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Andrei Emeltchenko 65db8e1e0f usb: cdc_acm: Fix typo
Fix typo in callback debug message

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-03-15 15:58:02 -07:00
Iván Sánchez Ortega fa57ebd5b7 usb: Rename unicode into UTF16LE
In order to avoid confusion between "Unicode", UTF8, UTF16, UTF32,
and endianess of these encodings, rename all instances of "Unicode"
in the USB subsystem and samples into "UTF16LE".

Signed-off-by: Iván Sánchez Ortega <ivan@sanchezortega.es>
2018-03-14 13:40:59 +01:00
Iván Sánchez Ortega 0186b0731a usb: provide different USB product strings in the USB samples
Make it possible to change USB manufacturer, product and
serial number strings by forcing prompt in the kconfig files.

Signed-off-by: Iván Sánchez Ortega <ivan@sanchezortega.es>
2018-03-14 11:25:56 +01:00
Andrei Emeltchenko 42e94c73c7 usb: msc: Cleanup USB write
This makes code more readable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-03-03 10:27:21 +01:00
Andrei Emeltchenko c857c20f88 usb: msc: Fix USB write check
Fix checking error code when write to USB endpoint.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-03-03 10:27:21 +01:00
Michael Hope 2262ed7b18 netusb: drop the extra byte added for multiple-of-64-byte packets.
This fixes a bug in the cdc_ecm Ethernet over USB driver.  The ECM
spec (section 3.3.1) says that the end of an Ethernet frame is marked
using the USB short packet mechanisim, where the last packet is less
than the maximum packet size.  If the Ethernet frame is a multiple of
the USB maximum packet size then a final zero length packet must be
sent.

Linux however sends a one byte packet (usbnet.c:1393) to work
around hardware issues with zero length packets.

The current Zephyr driver works most of the time except when you send
an Ethernet frame of the right length where the last byte is zero,
such as:

$ ping 192.0.2.1 -s 23 -p 0

Zephyr then drops the last byte, creating a short frame which gets
dropped higher up in the stack.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-02 07:34:53 +01:00
Anas Nashif 8949233390 kconfig: fix more help spacing issues
Fix Kconfig help sections and add spacing to be consistent across all
Kconfig file. In a previous run we missed a few.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-15 23:20:55 -05:00
Andrei Emeltchenko e8ccb16986 usb: hid: Add Human Interface Device (HID) class
Add support for Human Interface Device USB class.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Andrei Emeltchenko 8f21a37861 usb: Clean up code to meet Zephyr standard
Add missing "{}" braces and remove unneeded "()" braces.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Andrei Emeltchenko 60f8c6e272 usb: usbnet: Clean up code
Use common logging method and correct braces.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Andrei Emeltchenko 17735e8a04 usb: netusb: Remove USB custom_handler()
Custom handler is not used, cleaning code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Andrei Emeltchenko 6e2e2dbb1b usb: msc: Clean up comment
Trivial cleaning

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Johann Fischer daa83f8823 usb: mass_storage: rework and cleanup logging
This patch reworked logging so that the logging levels are more
finely graded and the locations with non-critical error handling
(below usb_ep_set_stall's) are logged with SYS_LOG_WRN.
Also cleanup, add log domain and fix indents.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-01-26 08:35:08 +05:30
Andrei Emeltchenko ca9c3ad8f1 usb: rndis: Use offsetof macro to ease offset calculations
Use macro offsetof() for calculating offset inside structure.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko be1d865409 usb: Add RNDIS packet boundary check
Add check for rndis_set_handle() packet.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko cd4cea0527 usb: netusb: Add Networking logging debug level
Adding Networking USB Device Debug level allows to fine-tune
logging.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 6d61c2cf24 usb: rndis: Select USB_COMPOSITE_DEVICE for RNDIS
Windows works better with this option.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 2a1bdc2549 usb: Set Class Handler buffer size to 256 for RNDIS
Set default value for RNDIS.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 33e9851254 usb: rndis: Add Remote NDIS protocol handling
Add implementation of Microsoft Remote NDIS USB Ethernet protocol.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 337601b42f usb: rndis: Add RNDIS device descriptors to the table
Add needed descriptors for USB Remote NDIS Ethernet Network.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko b4ae3ec32f usb: Add init() callback to network device functions
Add init() callback needed for RNDIS and maybe others functions.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 2615658027 usb: Use standard SYS_LOG_USB_DEVICE_LEVEL for log level
Change hardcoded value to configuration defined.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 7e80f41162 usb: Rename SYS_LOG_USB to SYS_LOG_USB_DEVICE
At the moment CONFIG_SYS_LOG_USB_LEVEL name does not specify that this
is log level for the Device Stack. Make it clear renaming to the
proper name.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 42d160a315 usb: netusb: Remove unneeded debug
Remove old unneeded debug statements.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Patrik Flykt 010fb40b95 subsys: usb: Set Zephyr project USB Vendor and Product IDs
Document USB Vendor and Product IDs and their intended usage.
Set the Vendor and Product IDs and define the USB bcdDevice
Device Descriptor Device Release Number to be the binary
coded decimal representation of the Zephyr major and minor
kernel version number.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-01-15 15:47:53 -05:00
Andrei Emeltchenko af0bf06aa3 usb: Fix USB Device dependency
USB Device stack should depend on supported drivers not on menuconfig
option.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-12 07:46:28 -05:00
Carles Cufi 7d764b35f3 cmake: Use path-corrected version of ZEPHYR_BASE
Instead of accessing the environment variable ZEPHYR_BASE every time we
require accessing the source code root, use an intermediate variable
that has OS path separators correctly set to '/' to avoid issues on
Windows.

Note: This removes the ZEPHYR_SOURCE_DIR CMake variable. External
applications using that will need to change to use the new ZEPHYR_BASE
variable.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-11 14:59:03 -05:00
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Loic Poulain f38482a8fd usb: netusb: Use lower addresses for default endpoint config
Even if endpoint addresses are configurable by each platform,
it would be better to make the default configuration compatible
with a larger board range.

e.g. STM32 OTG FS device has only four endpoints (0x84 is out).

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-10 13:10:00 -05:00
Loic Poulain 94c6e47667 usb: netusb: Fix CMakeLists
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-10 11:27:50 -05:00
Sebastian Bøe 5630ccfc23 cmake: Introduce a default VID and PID
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Andrei Emeltchenko 6f52e2d911 usb: Allow to select Endpoint addresses for CDC ACM
Sometimes we need to select Endpoint addresses manually to get it
working with certain USB controllers having limit for endpoints. In
this case default values break endpoint limit check. The proper
solution would be automatic endpoint allocation.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-08 15:09:47 -05:00
Johann Fischer 8ff9b6350f subsys: netusb: use usb_cdc.h header
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-11-07 15:31:02 -05:00
Andrei Emeltchenko 641f867adf usb: netusb: Allow to select Endpoint numbers
Add support for selecting Endpoint numbers and move it under USB
Device Networking menu.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-07 14:00:58 -05:00
Loic Poulain 35d0592a39 usb: netusb: Change 'conf' to 'configured'
conf member represents the configuration state of the device.
Change its type from u8 to bool and clean related functions.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 3fc83fd180 usb: netusb: ecm: Make in_pkt static
This reassembly buffer is local.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 41891849c9 usb: netusb: remove ecm struct
Remove unused iface member and move out skip variable.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain c82d1446bd usb: netusb: Remove ecm_register_function
The only access to the function is now the function interface.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 5f1c6d0999 usb: netusb: Move endpoint specific config to function interface
netusb endpoint config is specific to the function (ECM, RNDIS, EEM..).
Move this config to the function interface.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 3c47817a98 usb: netusb: Abstract netusb function specific methods
Move class_handler and send_pkt to netusb function interface.
This makes netusb 'function' agnostic.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 3870fc5928 usb: netusb: Remove multi-function array
Today, we support/use only one USB configuration descriptor.
Moreover I assume multi-config support should be managed at
usb core level and not by each class driver.
Let's track one netusb function per netusb instance for now.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 0188881599 usb: netusb: Add netusb_recv method
This method can be use by netusb functions on pkt reception.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 53d8389a6c usb: netusb: Remove eth_emu
Move network device creation/mgmt to netusb.
Add iface reference to netusb instance.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Andrei Emeltchenko 35a263374e usb: netusb: Fix handling no data case
In a case we get packet without fragments return -ENODATA.
The bug was discovered by Coverity.

Fixes #4637
Coverity-CID: 178334

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-01 10:00:02 +02:00
Andrei Emeltchenko f69b85e05c usb: netusb: Select NET_L2_ETHERNET when choosing Device Networking
Select automatically NET_L2_ETHERNET.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-30 11:50:42 -04:00
Andrei Emeltchenko a226d58716 usb: Use RFC 7042 Documentation values for MAC strings
Use documentation defined values for virtual devices MAC addresses in
Zephyr and Host OS.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko c93578e608 usb: netusb: Add composite device with ECM function
Add composite device skeleton with ECM function implemented.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko 38e010136d usb: netusb: Add ethernet emulation device
Ethernet emulation device allows to use networking interface for
interaction with USB endpoints.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko bbd3b4d749 usb: Add CDC ECM composite configuration
Add USB device configuration for CDC ECM

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko 91a4397e16 usb: Add extra debug information
Add extra debug information to USB commands.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko 44a3cca2e2 usb: Remove default Vendor and Product ID
Vendor ID and Product ID should be assigned on build time by
respective process.

For sanity check we assign some random values which are only used for
build tests and should not be used for real products.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-19 09:30:58 -04:00
Johann Fischer f67f6b0fdb subsys: mass_storage: add composite device configuration
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 09:18:14 -04:00
Johann Fischer 6fd0afa027 subsys: cdc_acm: add composite device configuration
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 09:18:14 -04:00
Johann Fischer 9b0da3bc0a subsys: usb: add composite device support
This patch adds composite support for USB class drivers.
It acts as a relay between the usb_device stack and
class or function drivers.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 09:18:14 -04:00
Johann Fischer deeb61f97b subsys: mass_storage: rework to use MSC header and common descriptor
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Johann Fischer 2e78a8fd6a subsys: cdc_acm: rework to use CDC header and common descriptor
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Johann Fischer f0832da1e0 subsys: usb: add common device descriptor
Add common device descriptor for USB class devices.
The common descriptor allows easy configuration of Manufacturer,
Product, SerialNumber strings and PID/VID.
It also allows future support for composite devices.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Johann Fischer 74137432c0 subsys: usb: add endpoint configuration for USB MSC
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Johann Fischer ad4c89ca2e subsys: usb: add endpoint configuration for CDC ACM driver
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Anas Nashif 71a927955e usb: move headers to include/usb/class
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-03 14:50:14 -04:00
Anas Nashif 18a33edd39 usb: fix local includes and add usb namespace
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-03 14:50:14 -04:00
Andrei Emeltchenko 4efaefba5c usb: Allow to select configuration for composite devices
Composite multifunction USB devices should be able to know about
configuration change, implement it through existing callback.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Andrei Emeltchenko d5486e2e73 usb: Add CDC Class specific request definitions
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Andrei Emeltchenko e4b62aec7f usb: cdc: Add Ethernet Networking Descriptor definitions
Add definitions for Ethernet Networking Functional Descriptor
implementation.

Change-Id: I5b6a28e844c1e765da6230b6e1a01b008251b549
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Andrei Emeltchenko 799e9e6594 usb: trivial: Clean up tabulation
Make code look consistent.

Change-Id: Ic10b2e0f3df09b225ad4e556a0b0860348f8d598
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Andrei Emeltchenko 36b4a5c64d usb: Handle SET_INTERFACE request
Handle SET_INTERFACE USB request making it possible to implement
complex devices.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Anas Nashif 09bcd8ee74 Kconfig: make all syslog variables depend on SYS_LOG
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-08-04 14:34:54 -05:00
Andrew Boie 567c6c7683 misc: use K_THREAD_STACK_DEFINE macros
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-06-09 18:53:28 -04:00
Youvedeep Singh 1da0a9eebd cdc_acm : Restrict writing more than 4 bytes into TX USB Endpoint.
Sometime it is observed on the Arduino 101 that when we write more than
4 bytes into TX USB Endpoint, first 4 bytes are getting repeated
(frequency of occurrence ~1/3000).

This patch does following :-

1. In sample application "cdc_acm", it adds capability to
handle partial transfer data incase data is transferred partially
if exceeds maximum data transfer size.
2. It restricts write of more than  4 bytes into TX USB Endpoint.
This is work around to  avoid issue occarance.

Jira: ZEP-2074

Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-05-13 15:12:27 -04:00
Andrew Boie b4e3799831 usb: mass_storage: use k_thread_create()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
Christer Weinigel cc93aceb83 usb: cdc_acm: Use 2 instead of 4 for IN BULK endpoint
The highest endpoint number supported by the STM32F4xx USB device
controller is 3.  Change the cdc_acm driver to use endpoint 2
instead of endpoint 4 so that it will work with this platform.

Change-Id: I4a3cd08f546a7fe01558528de0990156f642d93b
Signed-off-by: Christer Weinigel <christer@weinigel.se>
2017-04-28 18:48:58 +00:00
David B. Kinder 61de8f892b spell: Kconfig help typos: /kernel /misc /subsys
Fix misspellings in Kconfig help text

Change-Id: I6eda081c7b6f38287ace8c0a741e65df92d6817b
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-22 01:04:56 +00:00
Kumar Gala 6da829690f subsys: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: Icbf9e542b23208890a3a32358447d44cdc274ef1
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:36:22 -05:00
David B. Kinder 0ffb648210 spell: fix doxygen comment typos: /subsys
Fix doxygen comment typos used to generate API docs

Change-Id: I3efff6f5fa26f87d1e658d6336fef01ce45f5bb0
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-19 18:44:06 +00:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Jithu Joseph 89f4bf7c7e subsys: disk: Refactor disk_access stuff into a directory
Disk IO functions are used by both FS and USB Mass Storage.
This patch refactors those from FS directory to a separate one.
In addition existing, config options were modified to make
stuff meaningful.

Jira: ZEP-1276

Change-Id: Ia2a2e18f3dbbbdb964c3dc0427d8138ad86134cd
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2017-01-08 20:58:05 +00:00
Flavio Santes d8083e92ab arch/arc, usb, ztest: Add the ARG_UNUSED macro
Add the ARG_UNUSED macro to avoid compiler warnings.

Change-Id: Ie07f52e742bdb93fb35301bd50cce3865f229623
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-21 12:54:54 +00:00
Anas Nashif a9e879e273 logging: move sys_log to subsys/logging
Move logging out of misc/ to its own subsystem. Anything related to
logging and any new logging features or backends could be added here
instead of the generic location in misc/ which is overcrowded with
options that are not related to eachother.

Jira: ZEP-1467
Change-Id: If6a3ea625c3a3562a7a61a0ba5fd7e6ca75518ba
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:58:39 +00:00
Jithu Joseph 1dc41f515f usb :mass_storage: correct the license details
Certain structures and defines in this file are from
from mbed's implementation. The file header is updated
as per this.

Change-Id: I688917cdd17cfc8b27d5b78181ced90df73c9efd
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-12-02 02:11:34 +00:00
Baohong Liu 100e141a25 subsys: usb: use unified kernel API
Change-Id: I3eb70333cbfce17ccf1345a94f0f63148c9a3e7e
Signed-off-by: Baohong Liu <baohong.liu@intel.com>
2016-12-01 00:40:46 +00:00
Tomasz Bursztyka 44daf98e27 usb: cdc_acm: Various style fixes
- {} are always required on if/for/while
- no break line before an if, if condition is testing previous
  assignment
- parameters indentation etc...

Change-Id: I83f217c02733b9e63ef1e752f55937f3d7dc03e1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-11-30 15:23:42 +00:00
Tomasz Bursztyka b6e04720c8 usb: cdc_acm: Drop legacy API for unified one
s/nano_sem/k_sem + some necessary changes for the k_sem to work.

Change-Id: I96377083f5e17631b63d6da1a0546966ec95ff8b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-11-30 15:23:42 +00:00
Jithu Joseph fca0add22b console : usb: USB UART console output support
Add support for console output via the USB UART.
Note that console input via the USB UART doesnt work.

Adds a simulated poll method for UART interface exposed by USB.

Jira : ZEP-775

Change-Id: I357827ea52c027eb000baed80225f422df1f3358
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-11-12 01:39:30 +00:00
Sergio Rodriguez 6044f05f8a usb: class: Using unified kernel thread spawn API
Change-Id: I1e46a3414b71493875cf7f3f05af4ba4750df7c6
Signed-off-by: Sergio Rodriguez <sergio.sf.rodriguez@intel.com>
2016-11-11 02:50:49 +00:00
Jithu Joseph 63b4e2134f usb: class: Add USB mass storage class support.
This patch implements USB Mass Storage device Class,
which allows the  Zephyr target Board to appear
as a USB drive to a host.

This code would invoke disk_read() /disk_write()
hooks which are to be provided by the storage
layer.

The Mass Storage protocol state machine is based on
mbed's implementation. We augment it by adding Zephyr's
USB transport and Storage APIs, and offload disk ops
to a fiber context rather than in the USB irq context.

origin: https://developer.mbed.org/users/mbed_official/code/USBDevice/file/01321bd6ff89/USBMSD

Jira: ZEP-233

Change-Id: I8199598c76da20ab20012d81dac7615f6a366303
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-11-09 02:45:46 +00:00
Jithu Joseph 7eab305593 usb: Add end-point stall APIs and flow control APIS
USB class drivers may need to offload some work from
upcall interrupt context to a background fiber. This
requires some way to defer taking more data from host
till the offloaded work completes. Two APIs are added to
achieve this.

Further USB class drivers sometimes need to set STALL condition
on end-points to signal errors to host.These too are
added.

Change-Id: Ic973522c3394e23d7f9c4c67affc0cd050afc20f
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-11-09 02:45:46 +00:00
Anas Nashif 4d090e09d6 usb: move usb subsystem to subsys/usb and cleanup header inclusion
Change-Id: I5bdfd2cf5fee62af2ca772d778477f4f378a6a55
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-10-31 19:21:42 +00:00