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.
Fork of mbed-dev by
Diff: targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp
- Revision:
- 180:96ed750bd169
- Parent:
- 174:b96e65c34a4d
--- a/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp Thu Dec 07 14:01:42 2017 +0000
+++ b/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp Wed Jan 17 15:23:54 2018 +0000
@@ -36,14 +36,16 @@
#define MAX_SCAN_TIMEOUT (15000)
+static bool _inited = false;
+
static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
{
wifi_scan_hdl *scan_handler = (wifi_scan_hdl *)malloced_scan_result->user_data;
if (malloced_scan_result->scan_complete != RTW_TRUE) {
if(scan_handler->ap_details && scan_handler->scan_num > scan_handler->ap_num){
- nsapi_wifi_ap_t ap;
+ nsapi_wifi_ap_t ap;
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
- record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
+ record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
memset((void*)&ap, 0x00, sizeof(nsapi_wifi_ap_t));
memcpy(ap.ssid, record->SSID.val, record->SSID.len);
memcpy(ap.bssid, record->BSSID.octet, 6);
@@ -88,7 +90,7 @@
{
emac_interface_t *emac;
int ret;
- extern u32 GlobalDebugEnable;
+ extern u32 GlobalDebugEnable;
GlobalDebugEnable = debug?1:0;
emac = wlan_emac_init_interface();
@@ -97,10 +99,13 @@
return;
}
emac->ops.power_up(emac);
- ret = mbed_lwip_init(emac);
- if (ret != 0) {
- printf("Error init RTWInterface!(%d)\r\n", ret);
- return;
+ if (_inited == false) {
+ ret = mbed_lwip_init(emac);
+ if (ret != 0) {
+ printf("Error init RTWInterface!(%d)\r\n", ret);
+ return;
+ }
+ _inited = true;
}
}
@@ -130,6 +135,25 @@
*/
nsapi_error_t RTWInterface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
{
+ if(!ssid) {
+ return NSAPI_ERROR_PARAMETER;
+ }
+
+ switch (security) {
+ case NSAPI_SECURITY_WPA:
+ case NSAPI_SECURITY_WPA2:
+ case NSAPI_SECURITY_WPA_WPA2:
+ case NSAPI_SECURITY_WEP:
+ if((strlen(pass) < 8) || (strlen(pass) > 63)) { // 802.11 password 8-63 characters
+ return NSAPI_ERROR_PARAMETER;
+ }
+ break;
+ case NSAPI_SECURITY_NONE:
+ break;
+ default:
+ return NSAPI_ERROR_PARAMETER;
+ }
+
strncpy(_ssid, ssid, 255);
strncpy(_pass, pass, 255);
_security = security;
@@ -158,7 +182,7 @@
break;
case NSAPI_SECURITY_NONE:
sec = RTW_SECURITY_OPEN;
- break;
+ break;
default:
return NSAPI_ERROR_PARAMETER;
}
@@ -167,7 +191,7 @@
uint8_t pscan_config = PSCAN_ENABLE;
wifi_set_pscan_chan(&_channel, &pscan_config, 1);
}
-
+
ret = wifi_connect(_ssid, sec, _pass, strlen(_ssid), strlen(_pass), 0, (void *)NULL);
if (ret != RTW_SUCCESS) {
printf("failed: %d\r\n", ret);
@@ -218,7 +242,7 @@
}
nsapi_error_t RTWInterface::connect(const char *ssid, const char *pass,
- nsapi_security_t security, uint8_t channel)
+ nsapi_security_t security, uint8_t channel)
{
set_credentials(ssid, pass, security);
set_channel(channel);
@@ -230,9 +254,10 @@
char essid[33];
wlan_emac_link_change(false);
+ mbed_lwip_bringdown();
if(wifi_is_connected_to_ap() != RTW_SUCCESS)
return NSAPI_ERROR_NO_CONNECTION;
- if(wifi_disconnect()<0){
+ if(wifi_disconnect()<0){
return NSAPI_ERROR_DEVICE_ERROR;
}
while(1){
@@ -281,4 +306,4 @@
NetworkStack *RTWInterface::get_stack()
{
return nsapi_create_stack(&lwip_stack);
-}
\ No newline at end of file
+}
