Skip to content

nsapi - Add optional API for static configuration of network interfaces #2664

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

Merged
merged 2 commits into from
Sep 24, 2016

Conversation

geky
Copy link
Contributor

@geky geky commented Sep 12, 2016

This is a proposal to add static configuration to network interfaces.

This accomplishes two things:

  1. Provides a simple route for adding static IP address support to the base NetworkInterface
  2. Provides a simple route for adding configurability to network interfaces and unifies the network interface to consistent connect call, allowing network interfaces to be passed around abstractly

Additional functions:

int NetworkInterface::set_network(const char *ip_address, const char *netmask, const char *gateway);
int NetworkInterface::set_dhcp(bool dhcp);
int WiFiInterface::set_credentials(const char *ssid, const char *pass);
int CellularInterface::set_credentials(const char *apn, const char *user, const char *pass);

Let me know any concerns

related discussion #2627
should resolve #2649
cc @bulislaw, @sg-, @c1728p9

return NSAPI_ERROR_PARAMETER;
}

return connect(_ssid, _pass, _security);
Copy link
Member

Choose a reason for hiding this comment

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

User can still provide credential directly to the connect, which is all right, but in case user calls set_credentials first and then 'full' connect we won't update credentials data in the object (_ssid, _pass, _security) ending up, correctly, connected to different network than we have info stored. We could call the set_credentials in the connect to update network info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good idea. Unfortunately we can't control the connect function since it is overriden by the WiFi implementation. I'm open to ideas if you think we can work around this.

It would be better if the set_credentials was overridden by the interface (similarly to the set_network function), but this would break existing implementations.

@sg-
Copy link
Contributor

sg- commented Sep 22, 2016

@geky needs some conflicts resolved.

@sg-
Copy link
Contributor

sg- commented Sep 22, 2016

Looks like dhcp defaults to false, is that right? That would be a breaking change for all existing applications unless dhcp happens when mask and gateway are null?

@geky
Copy link
Contributor Author

geky commented Sep 22, 2016

Looks like dhcp defaults to false, is that right?

You are absolutely correct, dhcp should default to true. Not sure how this was missed.

…aces

This accomplishes two things:
1. Provides a simple route for adding static IP address support to the
   base NetworkInterface
2. Provides a simple route for adding configurability to network
   interfaces and unifies the network interface to consistent connect
   call, allowing network interfaces to be passed around abstractly

NetworkInterface
 - set_network
 - set_dhcp

WiFiInterface
 - set_credentials

CellularInterface
 - set_credentials
Provided through the config options added to the network interface:
- EthernetInterface::set_network(ip_address, netmask, gateway)
- EthernetInterface::set_dhcp(dhcp)
@geky geky force-pushed the nsapi-static-config branch from 561a89e to 64ac210 Compare September 23, 2016 09:41
@geky
Copy link
Contributor Author

geky commented Sep 23, 2016

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 933

All builds and test passed!

@kristofmulier
Copy link

Does anyone have an example code to get a simple UDP packet transferred to a PC, with static IP addresses?

@bridadan
Copy link
Contributor

@kristofmulier you can start with the sockets example here: https://github.com/ARMmbed/mbed-os-example-sockets

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.

Cannot use static IP addresses with new EthernetInterface API
6 participants