Commit Graph

156 Commits (3f4d30de567ff3351004c7c88d26dae7d0e4b2bd)

Author SHA1 Message Date
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 ed9048f79c Correcting unit for timeout
timeout unit should be ms not micro second.
2018-07-12 13:28:21 +03:00
Hasnain Virk 9a77b5d05f FRMPayload size validity
It was pointed out in #7432 and #7232 that the stack was comparing frame payload size
with the allowed payload size in a wrong manner in shcedule_tx().
We must strip the overhead from the frame before comparison.

We did have a similar check in prepare_ongoing_tx() API which would correctly analyse
the situation but a check was needed in schedule_tx() as well. The reason is that the
schedule_tx() API can be called automatically by the stack if the user intiated requested
was not promptly entertained because of duty cycle restriction. Now, the datarate can change
here (for CONFIRMED messages if the ack was not received after retries max out). That's why
a test for validity was needed.

We now perform a comparison using _ongoing_tx_message structure which contains the actual
FRMPayload size.

For proprietary type of messages only MHDR and Port field is used so we shouldn't add MAC commands
and other overhead into them.

In order to have consistent frame overhead, we have opted to always include Port field in the
frame.
2018-07-12 13:28:15 +03: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
Hasnain Virk 51f92b0efd LoRaWAN: Handling re-joining when already Joined
This is a remedy for the issue #7230.
While the device is joining, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned.
However, if the device is already joined, we will return LORAWAN_STATUS_ALREADY_CONNECTED.
2018-07-09 12:59:54 +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
Kimmo Vaisanen 50004ca89a Lora: Add initialize() method to set LoRaWANTimeHandler class for phy
Instead of giving LoRaWANTimeHandler object as parameter for constructor,
object is now given via own initialize() method.

This change is needed for future refactoring where application can give own
PHY object for LoRa stack.
2018-07-06 10:04:44 +03:00
Hasnain Virk bf78e264c8 Bug fix for receive windows
In rx_config(params) API we shouldn't check for radio state as radio may never get
idle for a class C device. That check made sense only for class A. As the PHY layer
have no conecpt of receive windows which is a MAC layer construct, we should remove the
state check.
The API will be changed later to void rx_config(params).

In addition to that another bug is fixed in the open_rx2_windows() API. We should set the rx slot
first before instantiating a test based on its value.
2018-07-02 18:42:21 +03:00
Martin Kojtal 3ee8f3214f
Merge pull request #7348 from hasnainvirk/doc_fix
LoRaWAN: Correcting doxygen
2018-07-02 17:24:52 +02:00
Amanda Butler aa53ee6204
Copy edit LoRaWANBase.h
Copy edit for precise language and comma use.
2018-06-29 14:28:44 -05:00
Amanda Butler 563d742872
Copy edit LoRaWANinterface.h
Copy edit for precise language and comma use.
2018-06-29 14:27:45 -05:00
Cruz Monrreal d06826b2a4
Merge pull request #7335 from hasnainvirk/recieve_api_change
LoRaWAN: Refactoring LoRaRadio::receive(uint32_t) API
2018-06-28 19:41:39 -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 7ce434b274 LoRaWAN: Fixing transport of fatal TX timeout event
This commit fixes the issue reported in #7285.
If the radio is unable to transmit, its a fatal error and can happen
both while joining or sending a normal packet. In the case of such
a catastrophy we ought to tell the application that this happened.

A fix for the radio driver will also be patched.
2018-06-27 11:41:30 +03:00
Hasnain Virk 10c3019e06 Refactoring LoRaRadio::receive(uint32_t) API
receive(uint32_t) API in the LoRaRadio class (base class for the radio drivers) should
not take any argument as we decided to take hardware timers for RX timeout interrupts
instead of software timers. It is being refactored to receive(void).
This is an API change, but as it is not an application interface, we will not put a
deprecation notice. Only user of this API is our stack (LoRaPHY layer) which has been updated
accordingly.
Actual driver comes out of the tree and a PR is open there to update the drivers:
https://github.com/ARMmbed/mbed-semtech-lora-rf-drivers/pull/22

In addition to this an internal API belonging to LoRaPHY class is refactored.
set_rx_window(parameters) is refactored to handle_receive(void) which is more consistent with
handle_send().
2018-06-26 15:47:51 +03:00
Hasnain Virk d335f82440 Remaining style fixes 2018-06-14 14:52:46 +03:00
Hasnain Virk 27290bb12f Adding valid frequency check for RXParamSetup cmd
We must check for a valid value of a frequency being sent
by the network server.
2018-06-14 14:52:46 +03:00
Hasnain Virk ffb0698ce7 Adding port in trace & streamlining continuous RX2 2018-06-14 14:52:45 +03:00
Hasnain Virk eab2bad593 Queuing the automatic uplink
If the automatic uplink is sent directly the call-stack becomes larger than 1K
which may cause serious problems in debug builds. Just to have a respite between
RX and TX we queue an event for the automatic uplink rather than directly undergoing
an automatic uplink.
2018-06-14 14:52:38 +03:00
Hasnain Virk 828815c7e3 Adding precise timing for receive delays
RX1 and 2 delays needed to be more precise and aggregate tx time was
drifiting because of timing difference between actual tx interrupt and
our processing of that interrupt ever so slightly.

We now take a timestamp of the tx interrupt and take a time diff while
instantiating delay timers. The timestamp is then used to update the aggregate
tx time.

Two new methods are introduced in the LoRaMac class which provide current
timing and current receive slot. These functions are used by LoRaWANStack
for its processing.
2018-06-12 12:32:13 +03:00
Kimmo Vaisanen 0f0b3be7e9 Lora: Check for valid ABP params
Check that ABP dev_addr and nwk_id is non-zero and keys are not null.
2018-06-01 12:41:16 +03:00
Hasnain Virk 493ae2bd91 dr_range bitfield should be unsigned integer
If the value is an integer, the 4th bit is used for sign, so you can store
values upto 7 only whereas the datarate values could go upto 15. That's why
we need to turn this to an unsigned integer so that the last bit can also be used.
2018-06-01 12:41:15 +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 e438846c2d Moving missing public data structures
A few of the structures were missing from the storage space which is
visible topublic APIs. Suc structures are now being added.
2018-06-01 12:30:07 +03:00
Kimmo Vaisanen d3327c3f5a Lora: All API methods should check if stack has been initialized 2018-06-01 12:29:25 +03:00
Hasnain Virk 9973eb3e79 Stability improvements & CRYPTO_ERROR addition
General stability improvements are performed.
A flag is added if a Class C RX2 window is open.
We shouldn't open it again if its already opened.

TX_CRYPTO_ERROR is renamed to CRYPTO_ERROR.
Keeping TX_CRYPTO_ERROR for backwards compatibility.
2018-05-24 15:59:07 +03:00
Hasnain Virk 0feb0efb89 Adding checks for stack initialization
Metadata APIs should return an error if the stack is not initialized yet.
2018-05-24 15:54:32 +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 2bc8e4e847 Adding ack expiry handling for class C
In Class C, rx timeout does not take place for RX2 windows, so if we have
not received anything, we would be retrying but if the no. of retries are
maxed out, and we have not recieved anything yet, we need a mechanism to
tell the upper layer that this has happened.
2018-05-24 15:54:32 +03:00
Hasnain Virk b0ce443f5b Doing away with rx_abort()
rx_abort() was sort of dead code as it was doing essentially nothing.
It might have actually meddled with the state machine if it was hit by
invoking on_ack_timeout_timer_event().

State machine and corresponding processors now take care of the ack timeout,
retries and all other bits, so we don't need abort_rx().
2018-05-24 15:54:32 +03:00
Hasnain Virk 375e1b711d Adding useful trace and setting no. of retries
MCPS confirmation should be filled with the current number of retries
if the ack is not recieved for a CONFIRMED message.

Ack retry number needs to be incremented after the retry is made not before
that.

A few traces are added at the crucial junctions of the code just to tally with
the conceptual flow for debug purposes.
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
Cruz Monrreal 863259e48b
Merge pull request #6960 from hasnainvirk/msg_flags
LoRaWAN: Message flags correction
2018-05-23 22:22:53 -05:00
Hasnain Virk 71348f7d65 Message flags correction
Uplink multicast is not allowed. Proprietary messages cannot be
of type unconfirmed and unconfirmed.
2018-05-21 16:16:58 +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
Cruz Monrreal 80e109370d
Merge pull request #6892 from hasnainvirk/bug_fix
LoRaWAN: Wrong type of message check
2018-05-14 17:35:32 -05:00
Cruz Monrreal 9fd04c4a37
Merge pull request #6839 from kivaisan/fix_lora_au915_build
Lora: fix AU915 build
2018-05-14 10:52:18 -05:00
Hasnain Virk d270105fa8 LoRaWAN: Wrong type of message check
In the reception data path, we needed to check the MCPS CONFIRMATION type
not the MCPS INDICATION type. Indication message type is for downlink message type
which can be UNCONFIRMED even if we have sent a CONFIRMED one, e.g., an ACK.
2018-05-14 13:36:38 +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 be04a57ecf Removing abort from rx in case of FL discrepency
If the frame length is not what we are expecting, it is
found to be a good practise to actually continue with what we
have received rather than aborting. As we have already demodulated
the packet and RX slots are used up, ther is not so much benefit in
dropping that packet.
2018-05-08 16:45:27 +03:00
Hasnain Virk ac6fb71c90 Datarate bug fix in rx windows configs
While configuring RX parameters for the radio, we need to feed in
rx windows 1 and 2 parameters which are computed when we do the transmission.
We are actually setting the physical value of the data rate rather than
data rate table index and the expectation was to set the data rate index.
2018-05-08 16:45:26 +03:00
Hasnain Virk cc09e44cfb Moving msg flags to lorawan_types.h
Message flags are used in the application so the logical place for
them is in lorawan_types.h and not in lorawan_data_structures.h
2018-05-08 16:45:26 +03:00
Hasnain Virk 1a0d90555e Doc fix
Structure naming in the docs was wrong.
2018-05-08 16:45:25 +03:00
Hasnain Virk f63ed86cfc Adding custom channel plan support in AS923
The asia pacific region supports custom channel planning and
downlink channel request. By virtue of a mistake, this information
was missing and hence a custom channel support was not working.
Fixes issue #6783.
2018-05-08 16:45:25 +03:00
Hasnain Virk 9f36baab1b State Machine rework
There had been essentially two state machines running in our stack
which was too cumbersome and was not alligned in any symmetry.

In this work we make sure that:
 * There are no callbacks from the MAC layer to Stack controller layer.
 * Primitives are made local to the mac layer and are presented as
   read-only to the stack controller layer.
 * Interrupt handling and processing is moved to the stack controller layer.
 * Reception is divided into smaller units, seperating handling of Join Accept
   and normal data frames. MIC gets its own unit.
 * Extraction of data and MAC commands from the payload is also being done now in
   its own method.
 * To ensure integrity of the stack, and sanctity of the radio payload, we copy the
   radio payload buffer immediately in the rx interrupt and hoist a flag that prevents
   another interrupt from happening for a short while when we are processing the previous
   packet.
 * If an automatic uplink is on going, we do not send a TX_DONE event to application
   anymore as that is logically incorrect.
 * state_controller() is the central engine for the state machine. To save code space and
   memory, we are not handling each and every state in the state_controller(). Some of the states
   which have no processing to be done, are explicitely set.
 * For all the states who need special processing, seperate methods are added.
 * Class A always run to completion to IDLE and CLass C always runs to completion as RECEIVING.
2018-05-08 16:45:18 +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