Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lora: Make automatic uplink message configurable #6628

Merged
merged 1 commit into from Apr 19, 2018
Merged

Lora: Make automatic uplink message configurable #6628

merged 1 commit into from Apr 19, 2018

Conversation

kivaisan
Copy link
Contributor

Description

Currently lora stack will automatically send an empty uplink message to lora gateway in case of:

  • Node received message with pending bit set.
  • Node received MAC command which requires instant response (sticky MAC command)
  • Node received confirmed message in class C mode

This commit makes this configurable via config item

    "automatic-uplink-message": {
        "help": "In case of pending bit, class c confirmed message or sticky MAC command, stack will automatically send empty uplink message",
        "value": true
    }

Default value is true. If sending an empty message fails, stack will send event AUTOMATIC_UPLINK_ERROR application.

If automatic uplink sending is disabled, stack will send application UPLINK_REQUIRED -event to indicate
application should issue a new uplink to gateway as soon as possible.

Pull request type

[ ] Fix
[ ] Refactor
[ ] New target
[X] Feature
[ ] Breaking change

@kivaisan
Copy link
Contributor Author

@hasnainvirk @AnttiKauppila @kjbracey-arm please review.

Copy link
Contributor

@hasnainvirk hasnainvirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good to me. Only a minor textual change in the help field of json is required.

@@ -60,6 +60,10 @@
"lbt-on": {
"help": "Enables/disables LBT. NOTE: [This feature is not yet integrated].",
"value": false
},
"automatic-uplink-message": {
"help": "In case of pending bit, class c confirmed message or sticky MAC command, stack will automatically send empty uplink message",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the code I can see that even in Class A an automatic uplink can be generated. The help field should therefore be changed.

0xc0170
0xc0170 previously approved these changes Apr 13, 2018
@kivaisan
Copy link
Contributor Author

@hasnainvirk Please review again. I removed the possible scenarios from help completely and made the description more generic.

@@ -61,7 +61,7 @@ using namespace events;
bool LoRaWANStack::is_port_valid(uint8_t port)
{
//Application should not use reserved and illegal port numbers.
if (port >= 224 || port == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it like opening a backdoor for application to invoke a network level function without the stack noticing it ?
Port 0 is like a control channel, application should not have access to it. What do you think @kivaisan @janjongboom ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually Semtech has removed the same check already some time ago from their stack. And if someone would like to use port 0 to something suspicious, what would prevent them from removing this check anyway from their source.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say the only reason to bar it is if it would fundamentally break the stack in some way. As long as the stack doesn't get fundamentally confused by port-0 messages it didn't generate, should be fine.

This is quite analogous to ICMP in IP, where the stack normally generates and processes ICMP messages, but applications can also generate and process them. (eg ping).

By symmetry, if an app can send port 0 messages, it should also be able to receive them - does this ensure that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On "backdoor", if this was Unix or something, conceivably port 0 might be limited to privileged applications. Eg ping does have to run setuid root because of that.

But in an OS without privilege levels, anyone can send raw IP/ICMP messages, and that makes sense here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traffic on port 0 is intended for network stacks, i.e., they act upon requests made by the network on port 0 and they respond to the network against those requests on port 0. That's why we had barred any user traffic on it previously. I am not sure what useful thing a user can retrieve by receiving at port 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things which spring to mind are traffic monitor/logging applications, and applications that want to send some sort of higher-level network command they know but the stack core doesn't. Eg some sort of vendor extension in the command space.

On a higher-level API I'd be inclined to have some sort of gating - eg SOCK_RAW allowing any port, but SOCK_DGRAM only using proper user ones. This is a pretty low-level API though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, in our email conversation from yesterday night it was stated that multicast / data frag should apparently be a separate library. You cannot do that if you can't do things on port 224/225.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently implement lorawan 1.0.2 which clearly states 224 is reserved for compliance testing and 225-255 for future standardized application extensions. So I think our current check (allowing only ports 0-223 for application) is correct for the spec version we support at the moment. Of course future spec version can/and probably will change this, so we also change the check accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kivaisan Yes, application extensions. The Multicast and data frag spec are extensions on top of LoRaWAN 1.02 and use these port numbers. So if you do it like this no-one can implement these extensions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the network layer's job to act as police for whether applications are using known valid port IDs. Its default behaviour should always be to just pass stuff through unless it's actually invalid, or explicitly defined to be "not for applications". From the specs, only port 0 is "special MAC internal" - everything else is application layer, even if reserved for future standards, and even the port 224 test protocol is explicitly stated as being an application protocol.

Given the current "single-user" API, it would make sense to give it all incoming traffic except for port 0, and let it send any outgoing traffic except for port 0.

I'm reminded of a horrible PCI hard drive controller I once encountered that stopped us using large discs - it had built-in knowledge of which ATA commands were DMA commands, and would only let you request DMA with those known commands. Which meant when extended the filing system to use LBA48 commands to access large discs, we found we couldn't do DMA transfers on that machine - the chip refused to start DMA because we were using a new command it hadn't heard of. If it had just passed through commands to the drive and started DMA when requested, rather than trying to put checks in, it would have worked fine.

If you ever do want the network layer to function as police for application ports or whatever - as a firewall - it's still not the network layer's job to have built-in knowledge of application ports and protocols. It should provide an API for filters to be set up by system management code.

@kivaisan
Copy link
Contributor Author

Changed is_port_valid to only block port 0 from application. Please review again.

Currently lora stack will automatically send an empty uplink message to lora gateway in case of:
- Node received message with pending bit set.
- Node received MAC command which requires instant response (sticky MAC command)
- Node received confirmed message in class C mode

This commit makes this configurable via config item

        "automatic-uplink-message": {
            "help": "In case of pending bit, class c confirmed message or sticky MAC command, stack will automatically send empty uplink message",
            "value": true
        }

Default value is true. If sending an empty message fails, stack will send event AUTOMATIC_UPLINK_ERROR application.

If automatic uplink sending is disabled, stack will send application UPLINK_REQUIRED -event to indicate
application should issue a new uplink to gateway as soon as possible.
@kivaisan
Copy link
Contributor Author

Rebased against the latest mbed-os.

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 18, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Apr 18, 2018

Build : SUCCESS

Build number : 1782
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6628/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 18, 2018

/morph uvisor-test

@mbed-ci
Copy link

mbed-ci commented Apr 18, 2018

@mbed-ci
Copy link

mbed-ci commented Apr 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants