Commit graph

2591 commits

Author SHA1 Message Date
Ravi kumar Veeramally
18422de8da net: tcp: Provide local address in TCP reset message preparation
If context is bound to IPv6 unspecified addresss and some port
number, then unspecified address is passed in TCP reset packet
message preparation. Eventually packet dropped at the peer.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Ravi kumar Veeramally
1f20111ef3 net: tcp: Do not handle packet re-transmission in TCP ACK
Zephyr doesn't have luxury to create re-transmit timer per packet. So
it has different methods to handle packets in queue. But re-sending
packets on valid ack messages causing issues.

E.g. A TCP node sent two packets (packet-1, packet-2). Peer replied
two ACKs (ACK-1 and ACK-2), and these two ACK's are at rx_thread
queue. Now ACK-1 is handled and reference of packet-1 is freed
from sent list. Then if condiftion (valid ACK and connection
state is ESTABLISHED) notices that, sent list is not empty.
Restart the timer, modify sent flag and resend packets in a
list. Here packet-2 is sent again, even though ACK-2 is already
received. Situation is worse if there are more packets in the
list.

So only start the re-transmit timer in-case queue is not empty. It
allows rx_thread to handle all incoming packets (in this e.g ACKs).
When the re-trasmit timer expires, it sends the packets which
are left in queue.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Ravi kumar Veeramally
e059e8b379 net: context: Handle failure case of tcp backlog entry
In case of failed to get source address from the net packet,
release the assgined tcp backlog entry. Otherwise it will
never be freed.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Ravi kumar Veeramally
7dc72c3ca6 net: context: Remove duplicate call
k_delayed_work_cancel(&context->tcp->fin_timer) called twice
immediately one after other.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Luiz Augusto von Dentz
800bfaf9a7 Bluetooth: UUID: Remove macros defining 16 bit values
Application should normally declare a bt_uuid with proper type and then
use bt_uuid_cmp.

Fixes #5162

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-02-13 13:33:48 +02:00
Robert Chou
6f466cd7e5 net: coap: retransmission for four times
RFC 7252, sec 4.8 [https://tools.ietf.org/html/rfc7252#section-4.8]
The default MAX_RETRANSMIT is 4, current implementation only
retry 3 times. Update next_timeout() to return one more retry.

Also, add a TODO for random generated initial ACK timeout

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-02-13 13:06:15 +02:00
Paul Sokolovsky
ede25c12a3 net: sockets: getaddrinfo() buffer overflow, etc. fixes
The existing implementation assumed DNS resolv callback will be
called just once, but that's not always the case (apparently,
for multi-homes hosts or something). So, apply array bounds
checking (and do pointer arithmetic only after it, as the C
standard otherwise warns of "undefined behavior"). In such a case,
the port number wasn't set in each entry too, so rework how it's
done.

The issues discovered while resolving archive.ubuntu.com.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-02-12 20:17:26 -05:00
Anas Nashif
ff42bdd0a0 debug: remove option GDB_INFO
This feature is X86 only and is not used or being tested. It is legacy
feature and no one can prove it actually works. Remove it until we have
proper documentation and samples and multi architecture support.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-12 13:58:28 -08:00
Vinayak Kariappa Chettimada
4eedb5067f Bluetooth: mesh: Account for scan window delaying adv events
New advertising started while scanning is already enabled
would delay the first advertisement event until the end of
the current overlapping scan window in the Zephyr native BLE
controller implementation. Hence, consider this scan window
duration when calculating the advertising stop.

Relates to: #6083

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada
af13d6d581 Bluetooth: controller: Fix soft latencies in periodic ticker
Fix, add the missing code for the removal of any accumulated
soft latencies or negative drift ticks when scheduling next
interval expiry with added laziness.

Typically a first interval would accumulate soft latencies
and this has to be removed if the interval is rescheduled
with any added laziness (scheduled to the next soft real
time interval).

Example, scan windows block any new scheduling until the end
of the window, adding latencies to any soft real time ticker
expiry which should try to execute as early as possible after
the scan window.

Fixes: #6083

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada
57e49b1f03 Bluetooth: controller: Refactor BT_CTLR_ADV_INDICATION feature
Refactor BT_CTLR_ADV_INDICATION feature by moving the
implementation closer to the implementation that is closing
the advertisement event so that in the future new members
can be added as necessary (example, advertised channels).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada
baf05409f8 Bluetooth: controller: Fix BT_CTLR_XTAL_ADVANCED cond. compilation
Fix compile warnings when BT_CTLR_XTAL_ADVANCED Kconfig
option is disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Johan Hedberg
5ded8d8d49 Bluetooth: Remove useless BT_L2CAP_TX_USER_DATA_SIZE Kconfig variable
No one was setting this to any other value than its default, which
happens to be the same as BT_BUF_USER_DATA_MIN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-12 09:48:32 +02:00
Johan Hedberg
c14c2692e2 net: buf: Set default user data size to 4
Since all in-tree users are good with 4 bytes of user data, reduce the
default to 4. Also fix the default and rage values where apparently
'0' and '8' had been swapped.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-12 09:48:32 +02:00
Johan Hedberg
0ad6dbd80d Bluetooth: Move HCI command buffer user data into separate array
The HCI command buffers are the only ones with more than 4 bytes of
required user data. Move the user data into a separate array and do
the mapping with the help of net_buf_id(). After this, it will be
possible to reduce the default net_buf user data size from 8 to 4.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-12 09:48:32 +02:00
Johan Hedberg
a7518ba30f Bluetooth: Mesh: Fix coverity warning with unchecked error return
This fixes Coverity CID 182769.

Fixes #6102

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 21:38:02 +02:00
Vinayak Kariappa Chettimada
a152109eb1 Bluetooth: controller: Fix nRF52840 radio timings for Coded PHY
Fix incorrect radio timing for Tx chain delay for S2 and S8
coding. Regression introduced  in commit 55d3ce111c
("Bluetooth: controller: Refactoring nRF5 radio driver").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-11 20:33:02 +01:00
Johan Hedberg
d5f27b70cc Bluetooth: Remove bogus return statements for BR/EDR connections
Having these in the beginning of a switch statement without any case
statement makes no sense.

Fixes #6135

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 18:29:57 +02:00
Johan Hedberg
7aeb1fa136 net: buf: Remove incorrect dependency for NET_BUF_POOL_USAGE
NET_BUF_POOL_USAGE was never supposed to depend on NET_BUF_LOG.

Fixes #6127

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 13:37:09 +02:00
Johan Hedberg
5008ec7a06 net: buf: Introduce variable data length allocators
Introduce two new "standard" data allocators to net_buf. There are now
three in total:

NET_BUF_POOL_FIXED_DEFINE: This is the closes to the old
implementation, i.e. fixed size chunks.  It's also what the old
NET_BUF_POOL_DEFINE macro maps to.

NET_BUF_POOL_HEAP_DEFINE: uses the OS heap

NET_BUF_POOL_VAR_DEFINE: defines a variable sized allocator using
k_mem_pool (this is all that there was in my first draft of this
feature)

Currently the variable length allocators (HEAP & VAR) support
reference counted data payloads, i.e. cheap cloning. The FIXED
allocator does not currentlty support this to allow for the simplest
possible implementation, but the support can be added later if
desired.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Johan Hedberg
dd09cbc1c4 net: buf: Redesigned API with split data and meta-data
Redesign of the net_buf_simple and net_buf structs, where the data
payload portion is split to a separately allocated chunk of memory. In
practice this means that buf->__buf becomes a pointer from having just
been a marker (empty array) for where the payload begins right after
the meta-data.

Fixes #3283

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Vinayak Kariappa Chettimada
18f366ca07 Bluetooth: controller: Fix disabling of Coded PHY feature
Fix conditional compilation in nRF5 radio interface so that
when Coded PHY feature is not selected then it does not use
the PPIs required for supporting the feature.

This will allow pwm_nrf5_sw driver to use PPI channels 14 to
19 and support 3 PWM channels. Without the Coded PHY feature
disabled, only PPI 14, 15, 18 and 19 are available for PWM.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-09 14:41:44 +01:00
Ravi kumar Veeramally
b22ab26b10 net: app: Add a new API to get net pkt based on dst
Added a new API to get net pkt based on dst address. Destination
address will be used to find correct net_context.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:45:53 +02:00
Ravi kumar Veeramally
09b361deed net: app: Fix get_server_ctx helper function
When net_app_ctx has multiple net_contexts, selecting net_context
based on dst address has some glitches.

E.g. One net_app_ctx and two net_contexts (net_ctx1, net_ctx2).
     Both net_contexts are mapped to net_app_ctx.
     When a caller looking for net_ctx (e.g. net_ctx2) with
     matching dst address. Loop goes through net_ctx1 and dst
     doesn't match. But another if condition checks does this
     net_context mapped to net_app_ctx, yes it matches.
     So return net_ctx1, which is wrong.

So first go through all elements in array of net_contexts for
matching dst address, if it fails to find then go for matching
net_app_ctx.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:45:53 +02:00
Ravi kumar Veeramally
0055e007d0 net: if: Provide a Kconfig to select default network interface
Default network interface is the first interface if there are multiple
interfaces exist. But this creates an issue when different parts of
the network subsystem wants to choose particular default interface.
At-least with this Kconfig option user can select default network
interface.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:44:15 +02:00
Christopher Collins
aa8850b42a subsys: storage: flash_map - Use correct macro
Prior to this commit, the old `FLASH_DRIVER_NAME` macro was being used
in the definition of the flash drivers array.  This caused the array to
have a size of 0.

This commit changes the code to use the newer `FLASH_DEV_NAME` macro,
causing the configured flash device to be present in the table.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-08 23:29:23 -05:00
Michael Scott
83978e6264 net: lwm2m: add max device power source config option
The code in the LwM2M "Device" object was checking for this max
power source config value, except that it was never added as a
Kconfig option.  Let's go ahead and add it so apps can set the
value appropriately.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-02-08 09:49:01 +02:00
Michael Scott
c1e180b6ee net: lwm2m: return NOT_FOUND for unused multi-value resources
When attempting to read an unused multi-value resource such as
"Available Power Sources", lwm2m client return a successful coap packet
w/o any values.  This looks like a timeout to any lwm2m servers which
make sure a valid response is returned.

Let's fix this by returning the correct NOT_FOUND error code instead.

NOTE: To test this I commented out the portion of the lwm2m client
sample which initializes the LWM2M_DEVICE_PWR_SRC_TYPE_BAT_INT and
LWM2M_DEVICE_PWR_SRC_TYPE_USB values.  By default, the sample will
setup dummy values to be returned by the client.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-02-08 09:48:45 +02:00
Robert Chou
228bf05af6 net: lwm2m: update internal API select_writer() and select_reader()
As per review of PR #5893, this is a follow up patch to update
select_writer() API to match the behavior of select_reader() API.

Quote from OMA-TS-LightweightM2M-V1_0_1-20170704-A. 8.2.5
"An Object Instance or Resource is Read by sending a CoAP GET to the
 corresponding path. The response includes the value in the
 corresponding Plain Text, Opaque, TLV or JSON format according to
 the specified Content-Format (see section 6.4).The request MAY
 specify an Accept option containing the preferred Content-Format
 to receive. When the specified Content-Format is not supported by
 the LwM2M Client, the request MUST be rejected."

Therefore, we do not attempt to assign a content-format when the
requested one is not supported. Instead, we return an error code.

0 is returned when reader or writer has been successfully selected by
select_reader() or select_writer()

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-02-07 22:12:48 -05:00
Andrzej Puzdrowski
b3614c0b17 subsys: fs: fcb: remove f_area_id from fcb structure
It is faster to operate directly on flash_area pointer instead
of fetch it all the time using the fcb flash area id.
Also as f_area_id was needed only for get appropriate flash_area
pointer, so it is better to pass it only while initialization
the fcb and not store it in fcb instance data at all.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-02-07 09:51:26 -05:00
Andrzej Puzdrowski
95a9dbc4b3 subsys: fs: fcb: rework fcb_walk and its callback
Previously flash_area structure was the parameter for the callback
function for transferring sector location info.
Now flash_sector is used so relevant flash_area is missing for
the callback.

This patch introduces structure fcb_entry_ctx which incorporates
entries' location and relevant flash area. It is used to pass complete
information to the callback. Additional  pointer to the flash_area fcb
speeds up operations.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-02-07 09:51:26 -05:00
Christopher Collins
e3cd915d8f fs: Convert FCB to use sectors (not areas)
Prior to this commit: `struct fcb` contained a pointer to an array of
`struct flash_area`.  Each entry in the array represented a flash sector
that the fcb comprised.

After commit: `struct fcb` contains a pointer to an array of `struct
flash_sector`, not `struct flash_area`.

Rationale: The FCB needs to know which sectors it occupies for its
rotate operation.  However, the `flash_area` type is meant to represent
a collection of sectors, not a single sector.  `struct flash_area`
contains information that the fcb does not need (e.g., area ID and
device ID).  Furthermore, the flash_map API provides a means of
converting a flash area ID to an array of sectors
(`flash_area_get_sectors()`), but no way to convert to an array of
areas.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-07 09:51:26 -05:00
Christopher Collins
ffc90dd496 subsys: storage: flash_map - Remove some code duplication
This patch cleans up flash_map code.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-07 09:51:26 -05:00
Christopher Collins
ffef30d39a storage: flash_map - Fix typo
get_flah_dev_from_id --> get_flash_dev_from_id

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-07 09:51:26 -05:00
Ding Tao
75a3590d20 fs: Kconfig: Fix warning on undefined choice NO_FILE_SYSTEM
Fix this by replace "NO_FS" with "NO_FILE_SYSTEM".

Signed-off-by: Ding Tao <miyatsu@qq.com>
2018-02-07 08:35:29 -05:00
Vinayak Kariappa Chettimada
f54f2ceb95 Bluetooth: controller: Rename a microsecond variable
Rename incorrectly named variable storing microseconds, from
ticks_slot to slot_us.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 12:26:34 +01:00
Vinayak Kariappa Chettimada
a02606cbf9 Bluetooth: controller: Fix missing ticks to us conversion
Fixed a missing ticks unit to microsecond unit conversion
potentially caused incorrect window offsets being used while
establishing connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:57:26 +01:00
Vinayak Kariappa Chettimada
978652e7b5 Bluetooth: controller: Remove redundant whitespace
Removed redundant whitespace when dereferencing struct
members.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:57:26 +01:00
Vinayak Kariappa Chettimada
bb84be2c5c Bluetooth: controller: Fix ticker to use u32_t ticks_slot
ticker timespace reservation can range up to 10.24 seconds,
needing 19-bits to represent in 32KHz clock units. Hence,
fix controller implementation to use u32_t to store ticks
slot values.

Without this fix, the controller is asserting in scan_adv
sample when using continuous scanning with 2 second interval
and window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:48:27 +01:00
Vinayak Kariappa Chettimada
ad7c9d3d76 Bluetooth: controller: Improved continuous scanning
Refactored the high frequency clock preparation advanced
feature to improve radio utilization during continuous
scanning.

The inter-event timespace value now considers the reserved
timespace while determining if the high frequency clock
will be retained. This reduces the preparation time, hence
increased radio use inside scan window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:23:10 +01:00
Vinayak Kariappa Chettimada
fa724b2bba Bluetooth: controller: Refactor invalid ctrl PDU handling
Refactor the invalid control PDU handling so as to reuse the
switch-case and hence, reduce code size and CPU time used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:20:48 +01:00
Erwan Gouriou
c734c2972f flash: remove obsolete FLASH_DRIVER_NAME
Replace seldom occurrences of FLASH_DRIVER_NAME by equivalent
and commonly used FLASH_DEV_NAME.

Fixes #5919.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-02-06 11:48:53 -06:00
Vinayak Kariappa Chettimada
8f239cd363 Bluetooth: controller: Rename radio_*_is_enabled to ll_*_is_enabled
In preparation towards a refactored controller, rename the
old radio_*_is_enabled() function to ll_*_is_enabled().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-06 10:49:25 +01:00
Vinayak Kariappa Chettimada
122a644d03 Bluetooth: controller: Fix handling of invalid Ctrl PDU lengths
Fix the controller implementation to handle Control PDUs
with invalid lengths by responding with Unknown Response
PDU.

Fixes LL.TS.5.0.2 conformance tests:
LL/PAC/SLA/BI-01-C [Control PDUs with Invalid Length from
	Master]
LL/PAC/MAS/BI-01-C [Control PDUs with Invalid Length from
	Slave]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
2800a9cb27 Bluetooth: controller: Minor cleanup of macros
Removed redundant macro definitions and rearranged code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
947bcba3d3 Bluetooth: controller: Use shorter (void *) for typecasts
Refactor and clean up code to use (void *) typecasts
consistently.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
4cd9ba7813 Bluetooth: controller: Use anonymous structs and unions in PDUs
Take advantage to cleanup code by using anonymous struct and
union definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
b7819ccab6 Bluetooth: controller: Add missing PDU struct definitions
Add missing PDU struct definitions in pdu.h file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
b521d50adc Bluetooth: controller: Refactor pdu_adv_payload_* to pdu_adv_*
Refactor PDU type names pdu_adv_payload_* to a shorter
pdu_adv_* struct names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
c4ba30cb1a Bluetooth: controller: Cleanup radio_pdu_node_rx/tx variables
Cleanup the use of long radio_pdu_node_rx and
radio_pdu_node_tx variable to shorter node_rx and node_tx
names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
fe0cebedcf Bluetooth: controller: Refactor phy req/rsp PDU struct
Refactor the pdu_data_llctrl_phy_req_rsp struct into
pdu_data_llctrl_phy_req and pdu_data_llctrl_phy_req structs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
9abf8ce0a0 Bluetooth: controller: Refactor length req/rsp PDU struct
Refactor the pdu_data_llctrl_length_req_rsp struct into
pdu_data_llctrl_length_req and pdu_data_llctrl_length_req
structs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Ioannis Glaropoulos
d09baafe64 Bluetooth: controller: inline implementation of radio-enable-on-tIFS
This commit implements a minor refactoring of the implementation
for enabling the Radio on TIFS expiration. It inlines a function
that is defined in the local radio_nrf5_ppi header file.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos
2764084561 Bluetooth: controller: implement sw-switch with the event timer
This commit contributes the implementation of the sw-switch for
tIFS in nRF5 Radio using the EVENT_TIMER instead of a dedicated
TIMER instance. A Kconfig configuration is added so the user can
select whether to use the EVENT_TIMER for the tIFS switch or use
a dedicated TIMER instance.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos
0ec1095dd6 Bluetooth: controller: sw-switch with the event timer (prepare commit)
This commit implements minor refactoring of radio.c and ctrl.c,
to prepare for adding the implementation of sw-switch based on
the event timer.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos
9c4dc04ba5 Bluetooth: controller: conditionally reuse CC for ISR profiling
This commit adds the option of conditionally reuse an existing
CC register of the event timer for timer sampling used in ISR
profiling, in case SW tIFS switching is implemented based on the
event timer.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos
2a85dda206 Bluetooth: controller: symbolic name for CC used in ISR profiling
This commit adds a symbolic name for the event timer
CC offset that is used to sample the event timer during
ISR profiling.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Vinayak Kariappa Chettimada
d4cc46c453 Bluetooth: controller: refactor radio_nrf5* headers
Refactor radio_nrf5* header files to group together
definitions and have less #if-#else-#endif.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Marti Bolivar
e2c9be1a18 dfu: mcuboot: add boot_read_bank_header()
This is an accessor function for the MCUboot image header of an image
bank. The interface may seem a little cumbersome, but it is
future-proof against MCUboot feature and incompatible header version
changes.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-02-05 06:42:15 -08:00
Marti Bolivar
01aa12bffd dfu: mcuboot: add boot_is_img_confirmed()
Applications chainloaded by MCUboot may want to change their behavior
based on whether or not they are confirmed.

Here are some examples:

  - performing a built-in self test (BIST) if the image is not yet
    confirmed, and marking it OK if it passes (this enables reverting
    to an older working image if the BIST fails, and allows future
    resets to skip the BIST if it passes to improve boot time)

  - interacting with persistent metadata related to image state on
    other flash partitions during test upgrades (these are required in
    cases when the update source provides runtime metadata, such as
    monotonic counters, related to an upgrade attempt which must be
    used to report results)

To enable these use cases, add boot_is_img_confirmed(), which reads
the "image OK" field for the current firmware image and returns true
if and only if it is set.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-02-05 06:42:15 -08:00
Marti Bolivar
4877dd22ea dfu: mcuboot: delete misleading comment
There is more information in the trailer than indicated by this comment.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-02-05 06:42:15 -08:00
Marti Bolivar
389060fb00 dfu: mcuboot: don't use magic when confirming image
The current implementation of boot_write_img_confirmed() does not
write the image OK byte in flash bank 0 if the magic "request upgrade"
bytes in that bank are "good". This is not robust behavior.

The MCUboot design document has this to say about the image OK byte:

   Upgrading an old image with a new one by swapping can be a two-step
   process. In this process, mcuboot performs a "test" swap of image
   data in flash and boots the new image. The new image can then
   update the contents of flash at runtime to mark itself "OK", and
   mcuboot will then still choose to run it during the next boot.

   [...]

    4. Image OK: A single byte indicating whether the image in this
       slot has been confirmed as good by the user (0x01=confirmed;
       0xff=not confirmed).

This says nothing about the magic bytes, so it'd be better not to make
assumptions about their effect here.

Further, MCUboot itself does not use the magic field when marking the
only known-good image on flash "OK" after either reverting a failed
upgrade or refusing to boot an upgrade iamge with an invalid
signature: instead, it unconditionally ensures the Image OK byte is
set to 0x01.

For consistency with MCUboot's design and implementation, remove the
lines that look at the magic bytes from boot_write_img_confirmed().

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-02-05 06:42:15 -08:00
Johan Hedberg
2ff98636a5 Bluetooth: Mesh: Add support for OOB info and URI in provisioning data
Until now the OOB info and URI fields in unprovisioned beacons were
generally ignored by the implementation. Add fields for these to
bt_mesh_prov and make sure to take them into account when encoding
advertising data, both for PB-ADV and PB-GATT. For PB-ADV the URI goes
out in a separate beacon, whereas for PB-GATT it is placed in the scan
response data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-05 12:46:05 +02:00
Robert Chou
54d7207e09 net: lwm2m: check content-format and respond with error if not support
Currently, we always set the content-format as "plain/text" when
it is unrecognized. This is wrong for it's possible that payload
is actually something else.

For example, we don't support JSON as incoming format right now.
But if I send a PUT request to /1/0/1 (server objectinstance/lifetime
resource) with value 3200 in JSON format: {"e":[{"n":"","v":3200}]}.
The client will still handle the request and respond with changed (2.04)
except the lifetime resource is updated incorrectly due to parsing
error.

Correct the behavior by not setting a default format and respond with
content-format-not-support error code (4.15)

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-02-05 09:05:00 +02:00
Alberto Escolar Piedras
bfabdf1de5 shell: Added noprompt command
Added noprompt command to shell. It will disable printing
the prompt.
For the native port, when feeding commands from a file or
pipe the prompt reprinting after each command (without echoing)
just confuses the user.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-02 07:48:46 -08:00
Alberto Escolar Piedras
e3f727cc6e native: added stdin handling for shell
Now the native console driver also handles stdin
so we can drive the shell from the command line,
a pipe or a file

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-02 07:48:46 -08:00
Ravi kumar Veeramally
9489fa54cc net: http: Fix http_prepare_and_send
net_pkt_append() has been changed. If payload reached max value
of 'data_len' in net packet, net_pkt_append will not append.
So the caller has to create new packet and append remaining payload.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
d6ca4decea net: Unlink the neighbor after unref
Unlinking of neighbor also needed after nbr_unref. Otherwise
neighbor id is still in use and can not be linked further.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
82f23bc276 net: rpl: Fix handling of DAO message
When a node receives DIO message from peer then node adds peer as
a neighbor (nbr with linklayer address). But when a node receives
DAO message from different peer (chances are peer selected
different route to reach this node), remove peer with previous
link layer address and add as a neighbor with new link layer address
with new route information. Now node can properly route packets to
peer from neighbor table or based on nexthop information from
routing table.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
6245dd68d9 net: rpl: Ignore parents with lower rank
When a node joins in DAG network, it chooses neighbor (node or border
router) as its parent. But if it receives DIO message from another
peer, it can only act as a neighbor, not as a parent. If peer rank
is better than current preferred parent rank then node will select
new peer as it's best parent.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
cfc8749133 net: rpl: Fix debug information and alignment issues
RPL prints lot of debug information which is difficult to track.
Minimized debugs in timer specific information and parsing of
DIO and DAO options. Also fixed alignment issues (no changes in
functionality)

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
ebf56ed1a6 net: mgmt: Fix mgmt push event
Do not even consider the push event if CONFIG_NET_MGMT_EVENT_INFO
enabled and info length is more than NET_EVENT_INFO_MAX_SIZE.
Print error message and ignore the event.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
ed2fcaeb8a net: rpl: Change default value for NET_RPL_INIT_LINK_METRIC
Current default value for NET_RPL_INIT_LINK_METRIC is 2, changing it
to 1.

e.g. NET_RPL_MIN_HOP_RANK_INC is 256 and NET_RPL_MC_ETX_DIVISOR is 256.
     Rank calculation for nodes is
     rank_increase = CONFIG_NET_RPL_INIT_LINK_METRIC *
                             NET_RPL_MC_ETX_DIVISOR;

     Which gives 768 for first set of child nodes. It would be good if
     CONFIG_NET_RPL_INIT_LINK_METRIC value is 1 and nodes ranks will be
     245, 512, 768 based on the path they choose.

User can absolutely change their configuration to maintain proper ranks.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
e567ca4f44 net: rpl: Do not run IPv6 DAD for global addresses
When CONFIG_NET_RPL enabled, do not run DAD (duplicate address
detection) for global addresses. In RPL mesh network global addresses
for nodes are determined by prefix from Border Router. DAD is not
necessary in this case.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
83bda0f037 net: Add IPv6 route add and delete event with info
If CONFIG_NET_MGMT_EVENT_INFO is enabled then provide mgmt info
about the route, which is added or deleted.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
9010def93e net: Add IPv6 neighbor add and delete event with info
If CONFIG_NET_MGMT_EVENT_INFO is enabled then provide mgmt info
about the neighbor, which is added or deleted.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
5e65444d04 net: ipv6: Remove route information before deleting neighbor
Remove any routes with neighbor as a nexthop first and then remove
neighbor from neighbor table.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
49894b98e4 net: Improve net management event information
Provided separate event information structs based on events. This way
user will know what kind of information will be received to that
particular event.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
ef36088608 net: Fix RPL header update
When net_ipv6_prepare_for_send() needs to route packets, it missed
updating of RPL header.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen
182b054a9f net: rpl: Setup DAG prefix into network interface
This is needed in routing if we are acting as border router.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen
6167f0f70c net: rpl: Do not do neighbor discovery for RPL network
Doing neighbor discovery in RPL network is not necessary and
that can be disabled in RPL nodes. Unfortunately the border
router needs to have ND enabled as it has also non-RPL network
interfaces in use. So in this case, mark RPL node as always
reachable.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen
d4d0ddd4f7 net: ipv6: Add some extra debug when updating link address length
As this is very specialized info which is not normally needed,
do not print it by default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen
e5b9e4d6ad net: ipv6: Add routing support between interfaces
Introduce CONFIG_NET_ROUTING option that allows the IP stack
to route IPv6 packets between multiple network interfaces.
No support for IPv4 routing is implemented by this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Juan Manuel Torres Palma
ff7f1bf9db net: arp: remove shadowing variable
Removes variable shadowing another declared
previously but does not change anything
functionally.

Signed-off-by: Juan Manuel Torres Palma <j.m.torrespalma@gmail.com>
2018-02-02 16:48:53 +02:00
Vinayak Kariappa Chettimada
258c7ccff1 Bluetooth: controller: Fix HCI LE Set PHY invalid behavior check
Fix HCI LE Set PHY command for invalid behavior testing for
invalid parameters and unsupported features.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-02 10:41:46 +01:00
Vinayak Kariappa Chettimada
a1f12eb238 Bluetooth: controller: Fix redundant length update event
Fix generation of redundant length update event when no
change in effective octets or time.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-73-C [Master Data Length Update - Responding
	to Data Length Update Procedure; LE 1M PHY]
LL/CON/MAS/BV-74-C [Master Data Length Update - Initiating
	Data Length Update Procedure; LE 1M PHY]
LL/CON/MAS/BV-76-C [Master Data Length Update - Responding
	to Data Length Update Procedure; LE 2M PHY]
LL/CON/MAS/BV-77-C [Master Data Length Update - Initiating
	Data Length Update Procedure; LE 2M PHY]
LL/CON/SLA/BV-77-C [Slave Data Length Update - Responding
	to Data Length Update Procedure; LE 1M PHY]
LL/CON/SLA/BV-78-C [Slave Data Length Update - Initiating
	Data Length Update Procedure; LE 1M PHY]
LL/CON/SLA/BV-80-C [Slave Data Length Update - Responding
	to Data Length Update Procedure; LE 2M PHY]
LL/CON/SLA/BV-81-C [Slave Data Length Update - Initiating
	Data Length Update Procedure; LE 2M PHY]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-02 10:40:52 +01:00
Johan Hedberg
0b7ac73eb6 Bluetooth: Mesh: fix BT_MESH_LPN_POLL_TIMEOUT description
The calculation was off by a factor of 10.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-01 12:37:09 -08:00
Vinayak Kariappa Chettimada
5c57027f53 Bluetooth: controller: Fix to use CPR preferred periodicity value
Fixed implementation to use Connection Parameter Request
Procedure Preferred Periodicity value in calculating the new
connection interval used by the master role in Connection
Update Indication.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-32-C [Accepting Connection Parameter Request –
	Preferred_Periodicity]
LL/CON/MAS/BV-33-C [Accepting Connection Parameter Request –
	Preferred_Periodicity and preferred anchor points]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-01 16:51:54 +01:00
Paul Sokolovsky
fbaa3b1724 net: tcp: prepare_segment: Return detailed error codes.
prepare_segment() returned NULL in case of any error, which then
net_context_send() translated into -EINVAL. That's highly confusing
though, because a common case of failure for prepare_segment() is
being unable to allocate data fragment(s) (for TCP header, etc.)
So, return output pkt by reference, and detailed error status as
a return value.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-02-01 13:13:32 +01:00
Johan Hedberg
d6b905910b Bluetooth: Mesh: Fix passing CID to model publication messages
The vendor variants of the model publication client messages were not
passing onward the CID, rather passing CID_NVAL which is clearly not
right.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 13:35:36 -08:00
Vinayak Kariappa Chettimada
9acfc7fb5c Bluetooth: controller: Fix to restrict addr set in initiator
Fix controller implementation to restrict HCI LE Set Random
Address command when advertising and/or active scanning
and/or initiator state is enable.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/INI/BV-01-C [Connection Initiation]
LL/SEC/ADV/BV-01-C [Advertising With Static Address]
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 10:54:26 -08:00
Vinayak Kariappa Chettimada
7af9c7108f Bluetooth: controller: Fix for CPR with/without Feature Exchange
Fix implementation to support Connection Parameter Request
Procedure initiation with and without use of Feature
Exchange Procedure being performed in a connection.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-81-C [Initiating Connection Parameter Request
	- Unsupported Without Feature Exchange]
LL/CON/MAS/BV-82-C [Initiating Connection Parameter Request
	- Unsupported With Feature Exchange]
LL/CON/SLA/BV-85-C [Initiating Connection Parameter Request
	- Unsupported Without Feature Exchange]
LL/CON/SLA/BV-86-C [Initiating Connection Parameter Request
	- Unsupported With Feature Exchange]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 16:02:14 +01:00
Johan Hedberg
8fc4c99496 Bluetooth: Remove redundant AD parsing check
A few lines earlier the code bails out in case len is 0. Checking for
buf->len < 1 is the same as checking for buf->len == 0. Since len is
guaranteed to be > 0 here the check len > buf->len implicitly checks
for buf->len == 0, i.e. the second test can be removed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 07:01:10 -08:00
Johan Hedberg
7ae78c9928 Bluetooth: Mesh: Fix segment transmission timeout
The timeout was hard-coded to 400ms, but the spec actually states:

"This timer shall be set to a minimum of 200 + 50 * TTL milliseconds."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg
1150858d8f Bluetooth: Mesh: Fix ack timeout calculation
The caculation was wrong since the value may be BT_MESH_TTL_DEFAULT,
i.e. 0xff, leading to much too large values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg
fee8734874 Bluetooth: Mesh: Clear segment rx context when incomplete timer expires
https://www.bluetooth.org/errata/errata_view.cfm?errata_id=10321

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg
fde013b254 Bluetooth: Mesh: Take advantage of K_SECONDS macro
This makes the code slightly more readable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg
a0ab6086e3 Bluetooth: Mesh: Fix ignoring old SeqAuth values
Replay protection is not enforced at the Lower Transport Layer, so it
is possible to get an old replayed segment here. In such a case
cleanly discard it instead of causing a valid existing transaction
from being discarded.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
cff16051bb disk: delete the GET_DISK_SIZE IOCTL.
The argument is a u32_t which limits the maximum disk size to 4 GiB.
Rather than fix this, delete the ioctl and switch the only use to
GET_SECTOR_COUNT instead.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-01-31 09:14:40 -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