Commit Graph

128 Commits (feature-lorawan-1-1)

Author SHA1 Message Date
Roman Volosatovs 69ed8ed1a9
Avoid sending DeviceModeInd twice 2020-04-06 12:48:19 +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 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
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
Hasnain Virk 72c25df1e3 _rx_ready flag is now atomic since #9245
_rx_ready boolean is not used anymore. We set/unset it using core util
atomic flag set test.
2020-02-06 18:37:24 +02:00
Hasnain Virk 7fb75500e3 Removing multiple attachment of LinkCheckRequest
A rebase error perhaps. We need to attach Link Check request only once
to the outgoing message.
2020-02-06 18:37:24 +02:00
Hasnain Virk 86eb300c35 Fixing multiple UL Fcnt increment
While post processing a transmission in case of no reception, we already
take care of frame counters. We must not kick post processing step once
again.
2020-02-06 18:37:24 +02:00
Antti Kauppila af04a7a638 astyle fixes 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
Antti Kauppila 27f26f2327 Auto merge problem fixed 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 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 ed93d7e026 Stopping multiple RX slot opening
Yet another rebase issue. RX processing was supposed to happen after
state setup and only once not twice.
2020-02-06 18:37:24 +02:00
Kimmo Vaisanen 09f3259d94 Enable RekeyInd again 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
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
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
Kevin Bracey 6f757a5824 LoRAWAN: volatile bool -> atomic_flag
Now we have a proper atomic flag API, use it rather than a volatile
cheat.
2019-01-14 11:59:25 +02: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 5c79ba5189 lorawan: fix coding style 2018-11-07 08:56:32 +00:00
Hasnain Virk 9e4487c850 TX post-process for CONFIRMED UL in no-reception case
The idea behind the method post_process_no_reception() is to post
process any outgoing TX but we shouldn't do that if a CONFIRMED message
is outgoing and there are still some retries left.
2018-10-16 12:23:21 +03:00
Hasnain Virk 8d4cda11f7 Making sure that RX slots open after state change
After transmission we should change the state before invoking opening of
slots as we may start receiving in the rx slots and the state would
suddenly change from SENDING to RECEIVING without going through the
ACK_WAIT state (in case of CONFIRMED messages). Tests show that after
this slight adjustment, our number of ack retries have significantly
reduced.
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
Hasnain Virk dc702c2df9 Adding check for ongoing automatic-uplink
Before going after an automatic uplink, we should check if there was an
automatic uplink already ongoing, i.e., the ack for the previous
automatic uplink cycle has not been received.
If there is we shouldn't queue the new automatic uplink and wait for
the previous Ack cycle to complete.
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 a54c271814 cmake Paths corrected 2018-09-27 11:30:52 +03:00
Antti Kauppila bd9066431f LoRaWANStack unit tested 2018-09-27 11:30:52 +03:00
Hasnain Virk 19e87ceab9 TX post-process for CONFIRMED UL in no-reception case
The idea behind the method post_process_no_reception() is to post
process any outgoing TX but we shouldn't do that if a CONFIRMED message
is outgoing and there are still some retries left.
2018-09-21 15:55:30 +03:00
Hasnain Virk c9d6741212 Making sure that RX slots open after state change
After transmission we should change the state before invoking opening of
slots as we may start receiving in the rx slots and the state would
suddenly change from SENDING to RECEIVING without going through the
ACK_WAIT state (in case of CONFIRMED messages). Tests show that after
this slight adjustment, our number of ack retries have significantly
reduced.
2018-09-21 15:55:30 +03:00
Hasnain Virk 94eb4c0bc0 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-09-21 15:55:30 +03:00
Hasnain Virk 5bfa7c03ba Adding check for ongoing automatic-uplink
Before going after an automatic uplink, we should check if there was an
automatic uplink already ongoing, i.e., the ack for the previous
automatic uplink cycle has not been received.
If there is we shouldn't queue the new automatic uplink and wait for
the previous Ack cycle to complete.
2018-09-21 15:55:30 +03:00
Hasnain Virk e110856941 LoRaWAN: Refactoring compliance test code
While performing compliance tests with an industry tester, we realized
that there was no need for any extra handling code for the compliance
tests. The tests would run fine, if we only have a handling application.
However, in normal operation we wouldn't like the network to send us any
traffic on compliance testing port. To mitigate that, on the reception
path we filter out any traffic on compliance testing port if compliance
testing is not underway. User should define LORAWAN_COMPLIANCE_TEST macro
in mbed_app.json to enable traffic on compliance test port.
2018-09-11 11:26:31 +03:00
Kimmo Vaisanen 6dc83dd737 Lora: Remove duplicate LinkCheckReq MAC command
When application requests link check request with add_link_check_request()
it was added to MAC command buffer. Again when actual TX was started,
stack cherry-picked the request into MAC buffer again resulting in a duplicate
entry in the buffer.

Functionality is changed now so that add_link_check_request() does not add
the request into MAC command buffer but it is cherry-picked into the buffer when
TX is issued.
2018-08-27 13:45:21 +03:00
Martin Kojtal 81f5decf8f
Merge pull request #7785 from kivaisan/fix_join_accept_failure_handling
Lora: Fix join-response failure handling
2018-08-22 14:05:24 +02:00
Cruz Monrreal 36ee9b98d6
Merge pull request #7767 from kivaisan/fix_tx_error_if_corrupter_msg_received
Lora: Fix TX_ERROR event if corrupted msg is received for CONFIRMED request
2018-08-21 10:20:23 -05:00
Cruz Monrreal 4ce0d9066e
Merge pull request #7719 from kivaisan/document_lorawan_return_values
Lora: Document all possible error codes for LoRaWANBase methods
2018-08-16 09:04:39 -05:00
Kimmo Vaisanen aa0c61b2b2 Lora: send and receive methods return LORAWAN_STATUS_NOT_INITIALIZED if not initialized
In order have a consistent return value for all methods in case of system is uninitialized
now also send and receive methods can return LORAWAN_STATUS_NOT_INITIALIZED.
2018-08-14 10:03:11 +03:00
Kimmo Vaisanen efeeb095c5 Lora: Fix join-response failure handling
Thix commit fixes a bug where stack was resending join-accept already
after RX1 if received join-response was invalid.

Stack should wait for RX2 before resending the join-accept.
2018-08-13 16:11:33 +03:00
Kimmo Vaisanen 07f4ca83f7 Lora: Fix TX_ERROR event if corrupted msg is received for CONFIRMED request
When node sends a CONFIRMED message and gateway sends ACK in RX1 window but the
message gets corrupted during the transmission (e.g. MIC fails), currently
our stack already checks for retransmission after RX1 and if retries attemps are
exhausted, TX_ERROR event is sent to application. This is wrong as MAC layer
will still attempt reception in RX2 window.

This commit fixes the behaviour so that TX_ERROR is not sent until RX2 window
has been closed.
2018-08-10 13:38:57 +03:00
Cruz Monrreal 40ff622711
Merge pull request #7601 from hasnainvirk/abp_auto_fix
LoRaWAN: Reduced priority for automatic uplinks & higher data rate usage for connection establishment
2018-08-07 09:13:45 -05:00