Commit Graph

44 Commits (feature-lorawan-1-1)

Author SHA1 Message Date
Roman Volosatovs caa8abfc7b
Fix handling of DeviceModeInd and BeaconFreqAns 2020-04-06 12:47:56 +02:00
Roman Volosatovs 75cc50e853 Fix handling of 1.1 MAC commands 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 4e11aa0bcc Astyle format ting
99.9% white space changes
2020-02-06 18:38:36 +02:00
Unknown 7656e91630 Fix PingSlotInfoReq parsing
PingSlotInfoReq 1 byte payload
2020-02-06 18:38:36 +02:00
Unknown ff16ddd8c3 Add Class B related MAC Commands
-  PingSlotInfoReq & PingSlotInfoAns 
-  PingSlotChannelReq & PingSlotChannelAns
-  BeaconFreqReq & BeaconFreqAns

Switch to millisecond computation for  device time handling
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
Antti Kauppila de9e292bf9 fixed include problem 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
Hasnain Virk 6f42adf8e5 Handling DevTimeAns mac cmd properly
DevTimeAns mac command will carry number of seconds since the GPS epoch
in the first four bytes and the fifth byte is the fractional part.
After extracting the time from the command fields, we need to adjust
this time according to the unix time, so we add the Unix to GPS time
diff to it. After that we account for leap seconds and set the time
using standard set_time() call.

We have removed the method time_received() fom LoRaPHY as it is not
important nor required. It doesn't fit into the LoRaPHY context.

Stubs are therefore updated to reflect the change.

mbed_lib.json now contains the configurable parameters for TAI to UTC
and GPS TAI to UTC differences in seconds needed for leap second
correction. They are loaded with values as of 2018.
2020-02-06 18:37:24 +02:00
Antti Kauppila af04a7a638 astyle fixes 2020-02-06 18:37:24 +02:00
Hasnain Virk 2dbbc84da4 RekeyInd mac command handling
RekeyInd Mac command was being handled incorrectly.
parse_mac_commnad_to_repeat() was missing handling for RekeyInd mac
command. Plus it is a sticky mac command as the spec says that it needs
to persist until we receive a RekeyConf mac command.
2020-02-06 18:37:24 +02:00
Antti Kauppila 78a04ec77c 1.0.3 flag added and add_device_time_req updated to not support 1.0.2 2020-02-06 18:37:24 +02:00
Antti Kauppila 1fbeb58b85 Auto merge problems solved 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
Hasnain Virk 726eff9305 Proper size checking for link ADR commands
In a specific branch path 'adr_settings' in link_adr_request() API, the
structure adr_settings of type link_adr_params_t will be rendered
uninitialized. To prevent this we initialize the construct as zero.
In addition to that, to handle the case properly we should check for the
command identifier and the command payload length anticipating contiguous
blocks of adr commands. If we find a discrepency in size, we should
abort.
2019-02-14 17:15:42 +02:00
Martin Kojtal 884a7748b2 lorawan: fix astyle coding style 2018-11-07 08:56:36 +00:00
Hasnain Virk 1fa2589c1e Style correction
LinkADRReq parameters and certain parameters used camel case
which is not the recommended style.
2018-10-16 12:23:21 +03: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
Antti Kauppila a54c271814 cmake Paths corrected 2018-09-27 11:30:52 +03:00
Antti Kauppila 0f83f08043 More lorawan unit tests added 2018-09-27 10:49:07 +03:00
Hasnain Virk 76814d4847 Style correction
LinkADRReq parameters and certain parameters used camel case
which is not the recommended style.
2018-09-21 15:55:30 +03:00
Martin Kojtal 0c8aa2823d
Merge pull request #8096 from kivaisan/fix_mac_command_retransmission
Lora: Fix sticky MAC command retransmissions
2018-09-21 09:47:47 +02:00
Kimmo Vaisanen 19d90bd25e Lora: Fix sticky MAC command retransmission
This commit fixes the bug where sticky MAC commands were duplicated in
send buffer everytime send() was called.
2018-09-20 12:20:17 +03:00
Kimmo Vaisanen f24623af97 LoRa: Stop processing MAC commands if command id is unknown
The length of a MAC command is not explicitly given and must be
implicitly known by the MAC implementation. Therefore unknown MAC
commands cannot be skipped and the first unknown MAC command
terminates the processing of the MAC command sequence.

This commit fixes the bug where MAC command processing was not
terminated when unknown MAC command was received.
2018-08-30 15:43:54 +03:00
Kimmo Vaisanen 3094327e12 Lora: Remove obsolete FEATURE_COMMON_PAL flags
mbed-trace no longer requires COMMON_PAL to be enabled.
2018-05-15 16:08:30 +03:00
Kimmo Vaisanen 9915478645 Lora: Fix battery_level callback
Application can give battery_level callback method what Lora stack
uses to query battery level for DevStatusReq MAC command response.
The problem was that this callback was never called.

This commit fixes this problem and if application does not set
battery_level callback at all, value 255 (= The end-device was not able to
measure the battery level.) will be returned to lora gateway.
2018-05-11 09:50:24 +03:00
Hasnain Virk 73e433e4e5 Immutable payload pointer to LoRaMacCommand class 2018-05-08 16:24:34 +03:00
Kimmo Vaisanen e7f01e3ccc Lora: Split add_mac_command() into separate methods
In order to have smaller and better testable methods, instead of having a big
switch-case -style add_mac_command(), each MAC command is now separated to an
own method.
2018-04-25 08:42:02 +03:00
Antti Kauppila 67157fc3bd LoRa: Internal include paths corrected 2018-04-10 14:04:18 +03:00
Antti Kauppila dc98228139 LoRa: Struct cleanups
- Unneeded structs removed and replaced by variables in functions
2018-03-21 08:54:42 +02:00
Kimmo Vaisanen 65b2dbc7dc Update DevStatusAnd format
In the DevStatusAns format, the protocol requires RFU(7:6) value = 0
2018-03-21 08:54:42 +02:00
Antti Kauppila 32257858d0 Added missing mac_cmd_buf_idx_to_repeat to LoRaMacCommand class
- Reordered LoRaWANStack internal variables for more compact code
2018-03-16 18:00:02 +02:00
Antti Kauppila 3c7bd1b794 LoRa: LoRaMac need removed from LoRaMacCommand class
- LoRaMacCommand does not have any external dependencies anymore
- Also LoRaMacMlme is not using LoRaMacCommand anymore
2018-03-16 17:58:44 +02:00
Hasnain Virk 7224fbae1c Style Changes in MAC layer
Style changed according to Mbed-OS guidelines.
2018-02-11 00:31:47 +02:00
Hasnain Virk 4432ad9ae7 Major PHY layer modifications
The PHY layer had a lot of duplicated code in various geographic regions.
In this commit we have tried to concentrate all common functionaliy into
one single class which LoRaPHY that provides three kind of methods:

i) Non virtual base methods which are there for upper layer use, e.g.,
   providing access to driver or generic PHY layer functionality which
   needs to be exposed to upper layers.

ii) Virtual methods (no hard limit on implementation) that can be overriden
    in derived classes. Some PHY implementations will need that as they may
    come with very peculiar channel schemes, e.g., dynamic channel schemes
    in US bands.

iii) Protected methods which are only available for the derived PHYs

We have adopted a mechanism for the dervied PHYs to announce their differenmtiating
parameters in their constructors by filling up a data structure known as lora_phy_params_t
which exists at base level. Access modifier for this data structure is protected so it can only be
used by the base or derived classes, i.e., no exposure to upper layers.

For extra functionality and differentiating controls, a derived PHY can override any virual method as necessary.

In addition to that we have adopted the Mbed-OS style guide and have changed data structures and code to reflect that.
Some data structures are removed.

* Algorithm to get alternate DR is modified. Current scheme, works as multiples of 6 as EU and EU like PHYs
provide 6 datarates. We make sure that we try a datarate at least once. If nuber of join retries is a multiple
of 6, we may try multiple times on each data rate.

* Most of the PHYs with dynamic channel plans, always override the above mentioned algorithm as the rules governing
  this algorithm do not hild in their case.

* band_t data structure is enhanced with lower band frequency and higher band frequency. That enables us to validate
  frequency based upon the band and hence we can have a single function for all PHYs to validate frequency.

* In some PHYs, there were some extra channel masks were defined which were not being used. Hence removed.

* EIRP table corrected in some PHYs based upon spec.

* PHY functions in response to Mac commands are renamed to reflect what they exactly do.
  for example accept_rx_param_setup_req() because that's what they do. they can either accept
  the mac command or reject it.# Please enter the commit message for your changes.
2018-02-11 00:31:47 +02:00
Kimmo Vaisanen 5d98839092 Improve error handling & robustness
This commit also introduces API change for disconnect(). disconnect() will
now return LORAWAN_STATUS_DEVICE_OFF for successfull disconnect.

 * LoRaWANStack::handle_tx() can be called with NULL buffer when length is 0.
   This commit fixes the case where user has provided NULL buffer and length
   is > max_possible_size.

handle_tx() now always returns LORAWAN_STATUS_PARAMETER_INVALID if given
buffer is NULL pointer and length > 0.

General error checking is added and some asserts are added for events.
2018-02-11 00:31:47 +02:00
Hasnain Virk c02774343a [IOTCELL-282] Code cleanup/simplification and rules
Baseline is changed to use a single set of data structures that simplifies the
code in the LoRaWANStack and Mac layer. We are now following certian rules for naming
data structures.

- All structures visible outside their domain are prefixed as 'lorawan_'
- All mac structures are prefixed as 'loramac_'
- All subsystem or module strucutures carry their name in prefix, like 'mcps_'

PHY layer still have legacy camel case data structures which will be entertained
later while we will be simplifying PHY layer.
Test cases are also updated with the new data structure naming conventions.

One major difference from the previous baseline is the removal of static buffer
from mcps indication. And we do not copy data from stack buffer to rx_msg buffer.
This saves at least 512 bytes.

It may look like now that if we have received something but the user have not read
from the buffer, then the buffer will be overwritten and we will lose previous frame.
Yes, we will. But the same will happen even if we would have copied the buffer into rx_msg
because then the rx_msg gets overwritten. So we decide to abandon copying the buffer at
multiple locations. We inform the user about reception, if the user doesn't read and
the data gets overwritten, then so be it.
2018-02-11 00:31:47 +02:00
Hasnain Virk a100ab0226 [IOTCELL-289] Adding Mlme class handle
MAC layer will services will be broken down into independent
subsystems. This is the first of those efforts. We have introduced
LoRaMacMlme class that handles everything related to MLME subsystem or
subservice. To accomodate subsystems we have grouped all protocol level
variables into one big data structure. A pointer to that data structure
will be passed around the subsystems in order to regulate the entire
system.

LoRaMac::Send() and LoRaMac::SetTxContWave*() APIs are made public as
they are needed to be accessed by the subsystems.
2018-02-11 00:31:47 +02:00
Hasnain Virk b634ca49dd Architecture rework, bug fixing & missing features
MAC layer is now a class rather than being a blob.
In addition to that Mac commands are now being handled in
a seperate subsystem (a class of its own). In future we
will do the same with othe sublayers of MAC like MLME, MCPS etc.

The drive behind this exercise is to make MAC and supporting layers
into an object oriented system.

Major bug fixes include:

- last join time inclusion in band parameters
- disabling rx2 window if we missed the slot already
- MLME uplink schdule hook
- nbRep according to spec
- maintaining datarate after successful joining
- suppressing MLME requests if MAC is in TX_DELAYED state
- Uplink dwell time verification

Some missing features are implemented. Details are as follows.

Support for LinkCheckRequet:

An application API is added, add_link_check_request() to delegate a
request for Link Check Request MAC command.

* Application provides a callback function that needs to be called on reception of
  link check response.

* Mac command is piggybacked with data frames.

This API makes the sticky MAC command stick with the application payloads until/unless
the application un-sticks the said mac command using remove_link_check_request() API.

Handling fPending bit:

If in the Downlink, we get the fPending bit set in fctrl octet,
we attempt to send an empty message back to Network Server to
open additional Receive windows. This operation is independent
of the application. An RX_DONE event is queued bedore generating
the said empty message. Specification does not mention what can be the
type of that empty message. We have decided it to be of CONFIRMED
type as it gives us an added benefit of retries if the corresponding
RX slots are missed.

Radio event callbacks as Mbed callbacks:

radio_events_t structure has been carrying C-style callbacks which was
inherited from the legacy code. These callbacks has now been changed to
Mbed Callbacks that makes sure that we can be object oriented from now
on.
2018-02-11 00:31:47 +02:00