Skip to content

Commit 1422379

Browse files
committed
Realtek-rtl8195am-Network Socket Updates
This PR addresses the issue of #8124. It updates and enriches the wifi connection error type to adapt the Network Socket test plan requirement. In the meantime, it increases the heap size that allows the transmission of larger packet size. Description 1. Increase heap size in lwipstack\mbed_lib.json to fulfill bursty TCP and UDP transmission requirement. 2. Modify and enrich wifi connection error types in TARGET_AMEBA\RTWInterface.cpp to adapt the decision logic of the wifi test cases. 3. Add new static constants in TARGET_AMEBA\RTWInterface.h, including 'SSID_MAX_LENGTH', 'PASSPHRASE_MAX_LENGTH' and 'PASSPHRASE_MIN_LENGTH' to help verifying the validity of ssid and passphrase. Pull request type [x] Fix [ ] Refactor [ ] Target update [ ] Functionality change [ ] Docs update [ ] Test update [ ] Breaking change
1 parent 27e1bc3 commit 1422379

File tree

3 files changed

+56
-34
lines changed

3 files changed

+56
-34
lines changed

features/lwipstack/mbed_lib.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@
115115
},
116116
"target_overrides": {
117117
"REALTEK_RTL8195AM": {
118-
"tcpip-thread-stacksize": 1600
118+
"tcpip-thread-stacksize": 1600,
119+
"mem-size": 12800
119120
},
120121
"UBLOX_EVK_ODIN_W2": {
121122
"pbuf-pool-size" : 10

targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,38 @@ RTWInterface::~RTWInterface()
104104
*/
105105
nsapi_error_t RTWInterface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
106106
{
107-
if (!ssid) {
107+
_security = security;
108+
// Check if ssid is empty
109+
if (!ssid) {
108110
return NSAPI_ERROR_PARAMETER;
109111
}
110112

111-
switch (security) {
112-
case NSAPI_SECURITY_WPA:
113-
case NSAPI_SECURITY_WPA2:
114-
case NSAPI_SECURITY_WPA_WPA2:
115-
case NSAPI_SECURITY_WEP:
116-
if ((strlen(pass) < 8) || (strlen(pass) > 63)) { // 802.11 password 8-63 characters
117-
return NSAPI_ERROR_PARAMETER;
118-
}
119-
break;
120-
case NSAPI_SECURITY_NONE:
121-
break;
122-
default:
123-
return NSAPI_ERROR_PARAMETER;
124-
}
113+
// Check if ssid is too long
114+
int ssid_length = strlen(ssid);
125115

126-
strncpy(_ssid, ssid, 255);
127-
strncpy(_pass, pass, 255);
128-
_security = security;
116+
if (ssid_length > 0 && ssid_length <= SSID_MAX_LENGTH) {
117+
memset(_ssid, 0, sizeof(_ssid));
118+
strncpy(_ssid, ssid, sizeof(_ssid));
119+
} else {
120+
return NSAPI_ERROR_PARAMETER;
121+
}
129122

123+
// Check if it is an open access point
124+
if (_security != NSAPI_SECURITY_NONE) {
125+
// Check if passphase is empty
126+
if (!pass) {
127+
return NSAPI_ERROR_PARAMETER;
128+
}
129+
// Check if passphase too long
130+
if (strlen(pass) >= PASSPHRASE_MIN_LENGTH && strlen(pass) <= PASSPHRASE_MAX_LENGTH ) {
131+
memset(_pass, 0, sizeof(_pass));
132+
strncpy(_pass, pass, sizeof(_pass));
133+
} else {
134+
return NSAPI_ERROR_PARAMETER;
135+
}
136+
} else { // It is an open access point
137+
memset(_pass, 0, sizeof(_pass));
138+
}
130139
return NSAPI_ERROR_OK;
131140
}
132141

@@ -135,11 +144,15 @@ nsapi_error_t RTWInterface::connect()
135144
int ret;
136145
rtw_security_t sec;
137146

138-
if (!_ssid || (!_pass && _security != NSAPI_SECURITY_NONE)) {
139-
printf("Invalid credentials\r\n");
140-
return NSAPI_ERROR_PARAMETER;
147+
// Check if the ssid is empty
148+
if (strlen(_ssid) == 0) {
149+
return NSAPI_ERROR_NO_SSID;
141150
}
142-
151+
// Check the security is empty and the passphase is valid
152+
if ((_security != NSAPI_SECURITY_NONE) && (strlen(_pass) < PASSPHRASE_MIN_LENGTH)) {
153+
return NSAPI_ERROR_PARAMETER;
154+
}
155+
// Based on security type set, adapt to Ameba SDK format
143156
switch (_security) {
144157
case NSAPI_SECURITY_WPA:
145158
case NSAPI_SECURITY_WPA2:
@@ -155,22 +168,24 @@ nsapi_error_t RTWInterface::connect()
155168
default:
156169
return NSAPI_ERROR_PARAMETER;
157170
}
158-
171+
// Check if channel number is valid
159172
if (_channel > 0 && _channel < 14) {
160173
uint8_t pscan_config = PSCAN_ENABLE;
161-
wifi_set_pscan_chan(&_channel, &pscan_config, 1);
174+
wifi_set_pscan_chan(&_channel, &pscan_config, 1); // Indicate which channel will be scanned
162175
}
163-
164-
ret = wifi_connect(_ssid, sec, _pass, strlen(_ssid), strlen(_pass), 0, (void *)NULL);
176+
ret = wifi_connect(_ssid, sec, _pass, strlen(_ssid), strlen(_pass), 0, (void *)NULL); // Join a WiFi network
177+
// Check if the WiFi is connected. Return RTW_SUCCESS for succeful; Return RTW_ERROR for error
165178
if (ret != RTW_SUCCESS) {
166-
printf("failed: %d\r\n", ret);
167-
return NSAPI_ERROR_NO_CONNECTION;
179+
if(_ssid == "NULL"){
180+
return NSAPI_ERROR_PARAMETER;
181+
}
182+
else{
183+
printf("failed: %d\r\n", ret);
184+
return NSAPI_ERROR_NO_CONNECTION;
185+
}
168186
}
169-
170187
rtw_emac.wlan_emac_link_change(true);
171-
172188
ret = EMACInterface::connect();
173-
174189
return ret;
175190
}
176191

@@ -200,7 +215,7 @@ nsapi_error_t RTWInterface::scan(WiFiAccessPoint *res, unsigned count)
200215
nsapi_error_t RTWInterface::set_channel(uint8_t channel)
201216
{
202217
_channel = channel;
203-
return NSAPI_ERROR_OK;
218+
return NSAPI_ERROR_UNSUPPORTED;
204219
}
205220

206221
int8_t RTWInterface::get_rssi()
@@ -215,8 +230,11 @@ int8_t RTWInterface::get_rssi()
215230
nsapi_error_t RTWInterface::connect(const char *ssid, const char *pass,
216231
nsapi_security_t security, uint8_t channel)
217232
{
218-
set_credentials(ssid, pass, security);
219233
set_channel(channel);
234+
int err = set_credentials(ssid, pass, security);
235+
if(err) {
236+
return err;
237+
}
220238
return connect();
221239
}
222240

targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,8 @@ class RTWInterface: public WiFiInterface, public EMACInterface
112112
char _pass[256];
113113
nsapi_security_t _security;
114114
uint8_t _channel;
115+
static const int SSID_MAX_LENGTH = 32; //The longest ssid
116+
static const int PASSPHRASE_MAX_LENGTH = 63; //The longest passphrase
117+
static const int PASSPHRASE_MIN_LENGTH = 8; // The shortest passphrase
115118
};
116119
#endif

0 commit comments

Comments
 (0)