Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LWIPBP3595Interface_STA_for_mbed-os
Fork of LWIPBP3595Interface by
Diff: LWIPBP3595Interface.cpp
- Revision:
- 3:2ff2514e4fca
- Parent:
- 2:c7e325599570
- Child:
- 4:b49b4b36aaa4
diff -r c7e325599570 -r 2ff2514e4fca LWIPBP3595Interface.cpp --- a/LWIPBP3595Interface.cpp Tue Sep 13 09:31:41 2016 +0000 +++ b/LWIPBP3595Interface.cpp Thu Oct 27 09:30:15 2016 +0000 @@ -22,10 +22,10 @@ static void _wlan_inf_callback(uint8_t ucType, uint16_t usWid, uint16_t usSize, uint8_t *pucData) { if ((ucType == 'I') && (usWid == 0x0005)) { if (pucData[0] == 0x01) { // CONNECTED - /* Notify the EthernetInterface driver that WLAN was connected */ + /* Notify the LWIPBP3595Interface driver that WLAN was connected */ WlanBP3595_Connected(); } else { - /* Notify the EthernetInterface driver that WLAN was disconnected */ + /* Notify the LWIPBP3595Interface driver that WLAN was disconnected */ WlanBP3595_Disconnected(); } } @@ -122,30 +122,131 @@ } /* Interface implementation */ -int LWIPBP3595Interface::connect(const char *ssid, const char *pass, nsapi_security_t security) +LWIPBP3595Interface::LWIPBP3595Interface() + : _dhcp(true), _ip_address(), _netmask(), _gateway(), _ssid(NULL), _pass(NULL), _security() +{ +} + +LWIPBP3595Interface::~LWIPBP3595Interface() { + if (_ssid != NULL) { + delete []_ssid; + } + if (_pass != NULL) { + delete []_pass; + } +} + +int LWIPBP3595Interface::set_network(const char *ip_address, const char *netmask, const char *gateway) +{ + _dhcp = false; + strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address)); + strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask)); + strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway)); + return 0; +} + +int LWIPBP3595Interface::set_dhcp(bool dhcp) +{ + _dhcp = dhcp; + return 0; +} + +int LWIPBP3595Interface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security) +{ + if (_ssid != NULL) { + delete []_ssid; + } + _ssid = new char[strlen(ssid) + 1]; + if (_ssid != NULL) { + strcpy(_ssid, ssid); + } + + if (_pass != NULL) { + delete []_pass; + } + _pass = new char[strlen(pass) + 1]; + if (_pass != NULL) { + strcpy(_pass, pass); + } + + _security = security; + + if ((_ssid == NULL) || (_pass == NULL)) { + return -1; + } + return 0; +} + +int LWIPBP3595Interface::set_channel(uint8_t channel) +{ + return 0; +} + +int8_t LWIPBP3595Interface::get_rssi() +{ + return 0; +} + +int LWIPBP3595Interface::connect(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel) +{ + set_credentials(ssid, pass, security); + set_channel(channel); + return connect(); +} + +int LWIPBP3595Interface::connect() { _wlan_init(); - if (lwip_wifi_init() == 0) { - _wlan_setting(ssid, pass, security); + if (mbed_lwip_wifi_init(NULL) == 0) { + _wlan_setting(_ssid, _pass, _security); } - return lwip_wifi_bringup(); + return mbed_lwip_wifi_bringup(_dhcp, + _ip_address[0] ? _ip_address : 0, + _netmask[0] ? _netmask : 0, + _gateway[0] ? _gateway : 0); } int LWIPBP3595Interface::disconnect() { - lwip_wifi_bringdown(); - return 0; + return mbed_lwip_wifi_bringdown(); +} + +int LWIPBP3595Interface::scan(WiFiAccessPoint *res, unsigned count) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +const char *LWIPBP3595Interface::get_mac_address() +{ + return mbed_lwip_wifi_get_mac_address(); } const char *LWIPBP3595Interface::get_ip_address() { - return lwip_wifi_get_ip_address(); + if (mbed_lwip_wifi_get_ip_address(_ip_address, sizeof _ip_address)) { + return _ip_address; + } + + return 0; } -const char *LWIPBP3595Interface::get_mac_address() +const char *LWIPBP3595Interface::get_netmask() { - return lwip_wifi_get_mac_address(); + if (mbed_lwip_wifi_get_netmask(_netmask, sizeof _netmask)) { + return _netmask; + } + + return 0; +} + +const char *LWIPBP3595Interface::get_gateway() +{ + if (mbed_lwip_wifi_get_gateway(_gateway, sizeof _gateway)) { + return _gateway; + } + + return 0; } NetworkStack *LWIPBP3595Interface::get_stack()