Commit Graph

36 Commits (0da589e6e725c3757c6b3ecbf973732e48879ceb)

Author SHA1 Message Date
Hasnain Virk 5fb383c27a Doxygen corrections
Adding group identidier so that LoRaWANInterface class goes to the class
hierarchy section rather than data-structures.

Adding missing documentation for a couple of public functions.

Adding \code and \endcode modifiers for the example code in the
documentation.

Adding compile time NO_DOXYGEN flag for the implementations of the
LoRaPHY Class.

Adding documentation for some of the private structures.
2019-01-10 16:14:19 +02:00
Hasnain Virk 2b95fd3e3a Removing virtual modifier from LoRaWANInterface
Doing away with virtual modifier from LoRaWANInterface, gets rid of
vtable for LoRaWANInterface.
2019-01-10 16:14:19 +02:00
Hasnain Virk b9b414a690 Retiring LoRaWANBase class
It was decided within the team to retire LoRaWANBase class which served
as a pure virtual interface class from which LoRaWAN network stack
implementations would get inherited. However, the current view is that
we may be the only user of it so we could retire LoRaWANBase.
2019-01-10 16:14:18 +02:00
Kimmo Vaisanen 17d02d949f Lora: Document all possible error codes for LoRaWANBase methods
Also duplicate documentation is removed from LoRaWANInterface which
inherits LoRaWANBase class.
2018-08-07 15:25:44 +03:00
Cruz Monrreal c5ba97fbe0
Merge pull request #7445 from hasnainvirk/issue_7230
LoRaWAN: Remedy for issue #7230
2018-07-13 11:48:13 -05:00
Hasnain Virk f0844b4cfc Streamlining connect() API with posix like retcodes
For ABP: First call to connect() or connect(params) will return LORAWAN_STATUS_OK
         and a CONNECTED event will be sent. Any subsequent call will return
         LORAWAN_STATUS_ALREADY_CONNECTED (posix EISCONN) and no event is generated.

FOR OTAA: First call to connect() or connect(params) will return LORAWAN_STATUS_CONNECT_IN_PROGRESS
          and a CONNECTED event will be sent whenever the JoinAccept is received. If the application
          calls connect again before receiving the CONNECTED event, LORAWAN_STATUS_BUSY will be returned.
          After the CONNECTED event is dispatched, any subsequent call to connect() or connect(params) API
          will be returned with LORWAN_STATUS_ALREADY_CONNECTED.

No new parameters are accepted after the first call. The application must disconnect before making
a connect() call with new parameters.
2018-07-10 13:31:50 +03:00
Hasnain Virk 24db1c81ec Updating docs
API documentation is updated to clear how the connection related return codes will
work from now on.
2018-07-09 13:00:01 +03:00
Kimmo Vaisanen 0397b0b292 Lora: Support user provided LoRaPHY object
To support custom PHY object, a new LoRaWANInterface constructor was
added.
2018-07-06 15:11:10 +03:00
Amanda Butler 563d742872
Copy edit LoRaWANinterface.h
Copy edit for precise language and comma use.
2018-06-29 14:27:45 -05:00
Hasnain Virk ce1e210e4a Correcting doxygen
Use of MSG_FLAGS was updated in previous PRs but the doc was not updated
accordingly.
2018-06-27 15:25:22 +03:00
Hasnain Virk 9ac7f21140 Style changes only
Travis astyle check pointed out some of the style mismatches in the code.
Not all of them are worth changing as they make the code unreadable and
some of them are semantically wrong.

So in this commit, we have attempted to pick the most important style
mismatches and rectify.
2018-06-01 12:41:09 +03:00
Hasnain Virk 3020d658bf Travis astyle corrections
The scope of style corrections is local to this PR only.
2018-05-24 15:54:32 +03:00
Hasnain Virk 26b28f78af Adding ability to cancel outgoing transmission
Application can use cancel_sending() API to stop any outstanding, outgoing
transmission (a TX which is not already queued for transmission). This can
potentially enable use cases where the application could cancel a transmission
and go to sleep if the backoff period is long enough rather than waiting for
the transmission to happen.
2018-05-24 15:54:32 +03:00
Hasnain Virk 8363311c7a Adding acquisition of backoff time value
This API enables the application to get hold of remaining time after which
the transmission will take place. User can query the backoff time whenever
there is a packet in the TX pipe. If the event for the backoff expiry is
already queued, the stack does not provide backoff metadata.
2018-05-24 15:54:32 +03:00
Hasnain Virk 387f56c738 Adding acquisition of RX meta data
User can now inquire about any RX meta data available after a
successful reception.
2018-05-24 15:54:32 +03:00
Hasnain Virk 555d945a42 Adding acquisition of TX Meta-data
An API is added to fetch any meta-data available after a succesful
transmission. The stack will make the meta data available after the
TX interrupt is processed. User can get the tx meta data after receiving
TX_DONE event.
2018-05-24 15:54:32 +03:00
Hasnain Virk 1a0d90555e Doc fix
Structure naming in the docs was wrong.
2018-05-08 16:45:25 +03:00
Hasnain Virk a75af9799e Adding thread safety
Making our LoRaWAN stack thread safe. If RTOS is not present, locks
don't do anything. ScopedLock is used to automate the lock release on
context expiry.
2018-05-08 16:24:34 +03:00
Kimmo Vaisanen 2b2ce300ea Lora: Remove singleton construction of LoRaWANStack
After changing LoRaMacCrypto as C++ class, we no longer have static variables
in LoRa implementation. Therefore singleton pattern can be removed.
2018-04-20 16:01:55 +03:00
Hasnain Virk c34b5e6d6f [IOTCELL-741] Separating public data structures
Any data structure used in LoRaWANBase class should be available
in a separate header in order to make the code easy to port and
easy to read as the developer doesn't need to know about all the
internal data structures being used in Mbed LoRaWAN stack.
2018-04-13 10:41:06 +03:00
Cruz Monrreal 94103f9306
Merge pull request #6586 from kivaisan/new_receive_method
Lora: Introduce new receive API which returns port and flags
2018-04-12 18:32:12 -05:00
Antti Kauppila 67157fc3bd LoRa: Internal include paths corrected 2018-04-10 14:04:18 +03:00
Kimmo Vaisanen 19883f12f8 Lora: Introduce new receive API which returns port and flags
This is a fix for issue #6389.

Currently when application receives RX_DONE event from stack, it has to provide the correct port
value to receive method in order to read the received message. The problem is that current
API does not provide any way to know in to which port message was received.

This commit introduces a new receive() method, which instead of checking these values, will return
them to application.
2018-04-10 13:04:23 +03:00
Kimmo Vaisanen a26fca8bf5 Add set_device_class API to change active device class
This API can be used to runtime change device class.

Please note that only class A and C are supported at the moment.
Trying to set class B will return LORAWAN_STATUS_UNSUPPORTED.

Fix set_device_class documentation

fix documentation
2018-03-21 08:54:42 +02:00
Antti Kauppila a294aa028d LoRa: LoRaWANInterface refactored.
- Only internal changes, no functionality changes
- Some minor improvements to LoRaWanStack
2018-03-21 08:54:42 +02:00
Antti Kauppila 2ac73a6cac LoRa: LoRaMacMcps refactored to remove dependency to LoRaMac.
- This is internal logic only and there are no functionality changes
- Some compliance test stuff have been moved to end of files
- Some internal data structures removed as useless after refactor
2018-03-16 18:00:02 +02:00
Antti Kauppila d232d3bb52 LoRa: Removed LoRaMac dependency from MIB and MLME classes
- Internal refactoring only, no functional changes
2018-03-16 18:00:02 +02:00
Hasnain Virk f0fe1229cf Moving LoRaRadio and LoRaWANBAse to lorawan
LoRaRadio and LoRaWANBase use to exist under netsocket/.
However, their logical location should be where the actual stack exists.
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 6ea541c054 [IOTCELL-286] Adding Channel Plan subsystem
Channel planning was distributed over LoRaWANStack and LoRaMac previously.
We now centralize it by allocating the service to its own class.

Thus making the workflow consistent, i.e.,

Request for channel plan = Application->Interface->stack->Mac->ChannelPlan

Major change apart from adding the channel plan subsystem are the API changes
in LoRaMac class.
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
Hasnain Virk 05e2d29238 Reworking callback API
Application should be able to add some optional callbacks if it needs to.
Ofcourse there is a penalty of 8-12 bytes per callback, but there can be
certain needs of the application that needs to be met for example setting
up a link check request etc.

We have introduced a structure that contains callbacks for the application use.

 - 'events' callback is mandatory, user must assign it. Because this callback brings
   state changes for the application. We cannot segregate this into individual handlers
   because of RAM penalty.
- Other calbacks (none of them are implemented yet are optional).

Example of using the API is provided with doxygen
2018-02-09 11:00:56 -06:00
Hasnain Virk e60227cf4d Receive API typo fix
Receive API should return the length of data written to the user buffer
as the Posix APIs suggest rather than sending the pending length of data
back.
That has actually been a typo mistake which actually wnt in even with doicumentation :)
2018-02-09 11:00:56 -06:00
Hasnain Virk 6281073d8b [IOTCELL-279] Using Application provided EventQueue
The EventQueue thread in LoRaMac.cpp is disbanded and the LoRaWAN
protocol is redesigned to store a pointer for an application
provided EventQueue. It means that now the stack runs in the
same thread as application. Application provided EventQueue is used
to defer ISRs from radio driver and timer callbacks as well as the
application events are queued to the same event loop.
2018-02-09 11:00:56 -06:00
Hasnain Virk f33ef6528b Adding LoRaWANInterface - implementing, LoRaWANBase
This class is the doorway for the user application into the
Mbed-OS implementation of LoRaWAN protocol. It implements LoRaWANBase
and hence would work with any stack implementation underneath, ensuring
seemless portability for applications.

It takes a pre-constructed object of LoRaRadio and delegates it in the
downward direction. Before calling connect() user must call initialize() function
in order to initialize stack and mac layers.

connect() APIs can be used to either provide relevent keys and connection method at
runtime or compile time (using Mbed config system).

enable_adaptive_datarate() and disable_adaptive_datarate() are used to turn on/off
automatic rate control. Otherwisem set_datarate() could be used to set a particular
data rate on the current channel.

set_confirmed_msg_retries() is valid only for CONFIRMED messages. It means that the stack will
retry for a given number of times before timing out.

set_channel_plan() and get_channel_plan() are used to set or get a particular channel plan.
These APIs are particularly useful in case of ABP (activation by personalization). Because
in case of OTAA(over the air activation), by default the stack takes in a CF List (carrier frequency list)
sent by the base station in conjunction with Network server. This list overwrites all user configured
channels or channel plan. set_channel_plan() can be used to set a single channel as well by setting the
parameter for number of channels to 1.

remove_channel_plan() or remove_channel() are used to remove a currently active channel plan or a specific
channel.

send() and receive() APIs follow posix design except the socket descriptor is replaced with port number here.

lora_event_callback() API is used to set a callback function from the application side which is used by the stack
to inform user of particular events like CONNECTED, DISCONNECTED, CRYPTO_FAILURE, TX_TIMEOUT etc.
2018-02-09 11:00:56 -06:00