Commit Graph

157 Commits (feature-lorawan-1-1)

Author SHA1 Message Date
Roman Volosatovs e90fc00176
Fix MIC calculation in LoRaWAN 1.1 2020-04-10 16:02:01 +02:00
Antti Kauppila 7fb6efa9cd Unittests fixed 2020-02-06 18:38:36 +02:00
Unknown 694790f5fe Class B feature branch rebase conflict fixes
Picked the wrong diff a few times while resolving rebase conflicts.
2020-02-06 18:38:36 +02:00
Unknown 6e59fb8ad0 Move class B resume and close rx window improvement
Use close_rx_window  callback to disable active class b window. This change protects against disabling the radio during class A transmit 
Move class B resume notification to one location in LoRaMac::set_tx_ongoing()
2020-02-06 18:38:36 +02:00
Shaun Nelson 833b0e1f4f Radio not put to sleep after class A Rx windows.
The Rx done/timeout event handler now checks if the radio is currently
transmitting before putting the radio to sleep. This test returns true in
class A rx window event handlers, so the radio is not not put to sleep.

Now to accurately test if transmitting, a mod ongoing flag is set true on send
and false on tx done/timeout.
2020-02-06 18:38:36 +02:00
Unknown edd9b5c40b mbed-os style update: Add LoRaMacClassBInterface
Make class function names lower case. Previously, class b's public  interface was part of the class and to avoid function name conflicts the static API was being distinguished from instance methods  by upper-casing the first letter. 
Fixed by moving the public interface to new LoRaMacClassBInterface
2020-02-06 18:38:36 +02:00
Unknown 002f7fc306 Moved Beacon GPS time set
Moved from stack to class b beacon handler
2020-02-06 18:38:36 +02:00
Unknown 75b588412a Reorder class b slot types by priority 2020-02-06 18:38:36 +02:00
Unknown 78b55c3ffc Stack Class B support
- Switched to millisecond gps time
- Updated process rx/rx_timeout events for  class B windows
- Added beacon event callback
2020-02-06 18:38:36 +02:00
Hasnain Virk d7a57fb0f3 Fixing DevTimeAns handling
As per discussion with Nicolas Sornin, any device time synchronization
value must be handled as is (monotonically increasing GPS epoch time guaranteed to be monotonic with granularity 1 second).

Once we receive a response to DevTimeReq (i.e., DevTimeAns is received)
we immediately set our local gps time stamp and take a snapshot of our
local monotonic (ticker or equivalent) clock. This is achieved by
calling 'set_gps_time(...)' API in the LoRaWANTimer module.
After that an event is generated to let the application know that a
device time has been synched.
2020-02-06 18:38:36 +02:00
Hasnain Virk ef6bc1d0a4 Adding network assisted GPS time acquisition
LoRaWANTimer class is responsible for providing time base for the
LoRaWAN stack in Mbed OS. It derives its core monotonic clock from the
EventQueue which is essentially a millisecond ticker or equivalent (in
tickless mode). LoRaWAN network can assist the device for device level
time synchronization using ClockSynchronization protocol (for v1.0.2) or
by replying to DevTimeReq MAC command (for v1.0.3 and above). The time
base used for device synchronization using above methods is purely
based on GPS epoch and needs no conversion to UTC or TAI etc (no
adjustment for leap seconds either).
Therefore we have extended the LoRaWANTimer APIs to account for GPS time
base if assisted by the network.
get_gps_time() is the API to use to acquire GPS time base from the
stack. If the network never assisted the device with a time stamp, a
value of zero is returned which means GPS time base is not available.
set_gps_time(time) API is used to set a given GPS time-stamp when the
network sends it.
These APIs are hooked via LoRaMAC to LoRaWANInterface which exposes the
access to the application.
2020-02-06 18:38:36 +02:00
Antti Kauppila e76a55681f astyle fixes 2020-02-06 18:38:15 +02:00
Hasnain Virk 623436d726 Hooking up DeviceTimeReq generation for application
The application can use add_device_time_request() API to attach
DeviceTimeRequest mac command for the next outgoing packet.
It is a non-stick mac command, so if there is no response, the app can
retry. The API indicates if the mac command was queued successfully or
not. The actual indication of successful time and date update will come
through an event 'DEVICE_TIME_SYNCHED'.
2020-02-06 18:38:15 +02:00
Antti Kauppila af04a7a638 astyle fixes 2020-02-06 18:37:24 +02:00
Antti Kauppila 4fadc1e773 Increment app DL counter correctly 2020-02-06 18:37:24 +02:00
Antti Kauppila 0c7f5684bb LoRaWAN: Moved keys to LoRaMacCrypto class
- Unittests updated to reflect LoRaWAN 1.1 changes
2020-02-06 18:37:24 +02:00
Hasnain Virk 80f3b842d7 Bug fixing for Rejoins
* While starting timer for rejoin request type 0, we should multiply max
time with 1000 as the timer APIs take ms values as parameters.

* RJCountX are incremented every time a Rejoin request is sent. For MIC
calculation we need to take the previous RJCnt value in account.

* Rejoin process should start against an event otherwise it will meddle
with state machine and any ongoing traffic.

* If a Type 1 rejoin is ongoing, we should not trigger a Type 0 rejoin.

* Some bug fixes after Triage with Antti.
2020-02-06 18:37:24 +02:00
Hasnain Virk 341b5e1566 Managing Confirmed traffic based on NbTrans
In 1.1, NbTrans governs both unconfirmed and confirmed traffic.
We cannot set number of retries ourselves. Based upon NbTrans received
in linkADRReq command, we will retry. If NbTrans is 1, we will send only
one message and if ack is not received we will generate TX error event.
Its the NS now which controls how many retransmission a device can do
without incrementing Frame counter. When we fail with TX error after not
receiving an ack, we increment the frame counter. This is necessary as
the NS will drop anything with the  previous counter and it can happen
that the NS may have sent an ack but we didn't receive it.
2020-02-06 18:37:24 +02:00
Hasnain Virk 749b3d459c Adding resets in lieu to Section 6.2.3 of Spec 1.1
Rejoin requests and presence/absence of CFlist demand different
handling.
If a Rejoin request was sent we shall use RJCountX (0,1) instead of dev
nonce for key derivation.
If a Rejoin request is not of type 2, we reset mac, phy parameters
alongwith frame counters. However, if it is type 2, we reset frame
counters only.

If cflist i present, we shall always apply it as it is.
If it's not and rejoin type is not type 2, we restore default channels.
Otherwise the local channels do not change.
2020-02-06 18:37:24 +02:00
Hasnain Virk 475fe0b47f Implementing CR-FcntDwn-usage-in-FOpts-encryption
LoRaWAN specification 1.1.0 is incorrect in handling of FOpts encrytpion.
A CR was made by STMicroelectronics which correctly addresses the issue.
We have taken that CR and implemented in our code base.
2020-02-06 18:37:24 +02:00
Hasnain Virk e490fbf991 Adding handling of packets with no fport field
Although we always add a port field for Uplink traffic, the spec allows
for fport field to be excluded. So there can be network server instances
which would exclude fport field from downlinks. We are now adding
handling for such situations.
2020-02-06 18:37:24 +02:00
Antti Kauppila 1fbeb58b85 Auto merge problems solved 2020-02-06 18:37:24 +02:00
Kimmo Vaisanen a8dbad926c Fix MIC calculation 2020-02-06 18:37:24 +02:00
Kimmo Vaisanen 6e60f2e161 MAC commands wip 2020-02-06 18:37:24 +02:00
Kimmo Vaisanen 88781d067c Fix uplink 2020-02-06 18:37:24 +02:00
Kimmo Vaisanen d48aae3692 Uplink (unstable) 2020-02-06 18:37:24 +02:00
Kimmo Vaisanen 1acb5a891e 1.1 join works 2020-02-06 18:37:24 +02:00
Antti Kauppila ccc3675a6a Rejoin logic added
BE to LE fixes, missing MLME types added

LoRaWAN 1.1 Features added (Some LoRaPhy impl missing still + some TODOs in code)

- MLME confirm handling refactored
- Rejoin handling missing
- new CF_LIST mechanism missing (+resets involved)
- NVM handling missing

Rejoin logic added
2020-02-06 18:37:24 +02:00
Antti Kauppila 0d3283e3a0 LoRaWAN 1.1 Features added (Some LoRaPhy impl missing still + some TODOs in code)
- MLME confirm handling refactored
- Rejoin handling missing
- new CF_LIST mechanism missing (+resets involved)
- NVM handling missing

Fixed automerge issue
2020-02-06 18:37:24 +02:00
Kevin Bracey 8b02c4ed1c Add missing <string.h> includes 2020-01-09 14:52:54 +02:00
Kimmo Vaisanen 4da74b6619 LoRa: Fix build warning about _ongoing_tx_msg
_ongoing_tx_msg was incorrectly initialized before _mlme_confirmation.

Fixes following build warning:
[Warning] LoRaMac.h@691,26: 'LoRaMac::_ongoing_tx_msg' will be initialized after [-Wreorder]
[Warning] LoRaMac.h@689,28:   'loramac_mlme_confirm_t LoRaMac::_mlme_confirmation' [-Wreorder]
[Warning] LoRaMac.cpp@68,1:   when initialized here [-Wreorder]
2019-09-30 12:36:55 +03:00
Hugues Kamba a306ad758d Avoid non-trivial copy when initializing lorastack struct
Using memset generates a warning about the non-trivial operation.
Use member-initializer-list instead to initialise the structs members.
2019-09-03 11:08:04 +01:00
Teijo Kinnunen 10c0f20317 LoRaWAN: Terminate RX when receiving uplink messages
This prevents RX2 window to be enabled at the same time when repeating
transmission, when QoS repeated TX is in effect. Failure to do so
seems to place the LoRaWAN stack in a state where send() always fails
with WOULD_BLOCK error.
2019-08-16 12:56:58 +03:00
Hasnain Virk 8fd791db49 Adding TOA and Channel info in RX metadata
We provide now downlink channel frequency and time on air for the
received frame in the RX metadata.
Previously the channel information in both TX and RX metada contained
the index number of the channel. That information wasn't very useful
except the index numbers of default channels. To make more sense of the
meta data, we now store the channel frequency in the channel parameter
rather than the index number of the channel.

RX time on air is collected from the radio driver and it is assumed that
the downlink frame had 8 downlink preamble symbols (plus 4.25 of the
preambles added by the chip) for LoRa modulation.

This commit also include a bit of tidying of RX frequency storage in rx
configuration parameters storage. Previously we were missing filling in
the RX1 frequency correctly.
2019-03-27 10:23:43 +02:00
Cruz Monrreal a0a265ad84
Merge pull request #10196 from hasnainvirk/premature_rx2_fix
LoRaWAN: Fixing premature RX2 closure
2019-03-27 00:26:12 -05:00
Hasnain Virk 2691b83c4e Fixing premature RX2 abort
A bug while setting up RX start timers would result in premature closusre
of RX2 window. The 'ack_Timeout_timer' would be invoked prematurely and
at that time RX2 window may be being demodulating. This resulted in
massive instability with any test that relied on Confirmed traffic or
lower data rates.

To fix the issue, we must know the length of the RX window in
milliseconds and for this purpose we have extended the
'get_rx_window_params(...)' API. The length of the time the window
may remain open must be accounted for while setting up
'ack_timeout_timer'.
2019-03-22 15:15:51 +02:00
itziar 4c1fedd72a Applied suggested astyle fix(es) 2019-03-19 10:11:15 +01:00
itziar 5beef7405c Bug related to downlink sequence counter rollover 2019-03-19 10:11:14 +01:00
Hasnain Virk f4077af5b1 UL FCnt increment in case of retry exhaustion
Previously we had been incrementing UL frame counter for a CONFIRMED
message only when the transmission was deemed successful i.e., we would
have received an ack before all the retries would have exhausted.
Now we have opted to increment the frame counter if all the retries are
exhausted considering the fact that we essentially treat the next
message after retry exhaustion as a new packet so we should also
increment the frame counter.
2018-12-10 08:53:30 +02:00
Antti Kauppila cf53494f2e Compliance test errors fixed 2018-11-14 09:46:38 +02:00
Martin Kojtal 884a7748b2 lorawan: fix astyle coding style 2018-11-07 08:56:36 +00:00
Antti Kauppila f0864be1c5 Fixed lorawan unittests valgrind issues 2018-10-17 15:25:53 +03:00
Hasnain Virk 0a9417299b Fixing coverity findings
A couple of the coverity analysis findings are being treated here. For
the rest there will be a separate PR.
2018-10-16 12:23:21 +03:00
Hasnain Virk 7818733728 Proper handling of RX1 frequency in rx_config
Previously, we weren't filling in RX1 frequecny in rx_window1_config
structure. However, everything worked as in LoRaPHY::rx_config() API
there was a check which filled in correct RX1 frequency.
Now we are filling in RX1 freq. properly while we are computing
parameters for RX1 window.
2018-10-16 12:23:21 +03:00
Hasnain Virk d5ce0cc96f Adding QOS handling and fixing bugs for Class C
LinkADRReq mac command can be used by the network server to set a
certain level of QOS using NbTrans field which is applicable to
Unconfirmed traffic only for 1.0.2 spec.
This commit introduces mechanisms to facilitate this QOS. It means to
repeat an outgoing unconfirmed message NbTrans times without changing
its frame counter.

For class C, we have retired the ack_expiry_timer_for_class_c and have
replaced it with another timer which mimics the RX2 closure as in Class
A but doesn't actually close RX2 window. It's just a mechanism by which
the state machine is informed that the you can proceed forward, we have
not received anything in RX2 window either. This is needed as RX2
doesn't timeout in class C (i.e., the radio remains in continuous mode).
In addition to that we need to close any pending timers for Receive
windows after the MIC has passed and the Duplicate counter check has
also been passed.
2018-10-16 12:23:21 +03:00
Cruz Monrreal b666cd68dc
Merge pull request #8299 from hasnainvirk/issue_8285
Making cancel_sending() API robust
2018-10-15 10:12:27 -05:00
Cruz Monrreal II dd8e9bb954 Revert "Merge pull request #8183 from hasnainvirk/QOS_impl"
This reverts commit 5c675d3688, reversing
changes made to 2b04a02eb2.
2018-10-11 16:51:46 -05:00
Cruz Monrreal 5c675d3688
Merge pull request #8183 from hasnainvirk/QOS_impl
Adding QOS in response to LinkADRReq and fixing class C bugs
2018-10-11 10:09:37 -05:00
Hasnain Virk 603ee28098 Making cancel_sending() API robust
If the packet is already handed over to the PHY layer, we shouldn't be
able to cancel that particular transmission. In addition to that if the
backoff timer is either not applied or has been deactivated, should end
up in no-op rather than having normal termination. A new error code has
been introduced to cover no-op cases. This error code replaces the
compliance test related error code which is no longer relevant.
clear_tx_pipe() does nothing if:
	- The stack cannot cancel TX (already handed over to PHY)
        - The backoff timer is not active at all
        - The event is disaptched to schedule

stop_sending() will only post process ongoin TX if the pipe was
definitely cleared.
2018-10-02 14:07:52 +03:00
Antti Kauppila f6ecb319d0 LoRaMac unittested 2018-09-27 11:30:52 +03:00