Skip to content

Commit e619b94

Browse files
committed
WiFi: add const-correctness to ssid
1 parent ef2eb29 commit e619b94

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

libraries/WiFi/src/WiFi.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "WiFi.h"
22

3-
bool arduino::WiFiClass::isVisible(char* ssid) {
3+
bool arduino::WiFiClass::isVisible(const char* ssid) {
44
for (int i=0; i<10; i++) {
55
if (strncmp(ap_list[i].get_ssid(), ssid, 32) == 0) {
66
connected_ap = i;
@@ -15,7 +15,7 @@ arduino::IPAddress arduino::WiFiClass::ipAddressFromSocketAddress(SocketAddress
1515
return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]);
1616
}
1717

18-
int arduino::WiFiClass::begin(char* ssid, const char *passphrase) {
18+
int arduino::WiFiClass::begin(const char* ssid, const char *passphrase) {
1919
if (_ssid) free(_ssid);
2020

2121
_ssid = (char*)malloc(33);
@@ -30,18 +30,18 @@ int arduino::WiFiClass::begin(char* ssid, const char *passphrase) {
3030
if(wifi_if == nullptr) return WL_CONNECT_FAILED;
3131
}
3232

33-
// too long? break it off
34-
if (strlen(ssid) > 32) ssid[32] = 0;
3533
memcpy(_ssid, ssid, 33);
34+
// too long? break it off
35+
if (strlen(ssid) > 32) _ssid[32] = 0;
3636

3737
scanNetworks();
3838
// use scan result to populate security field
39-
if (!isVisible(ssid)) {
39+
if (!isVisible(_ssid)) {
4040
_currentNetworkStatus = WL_CONNECT_FAILED;
4141
return _currentNetworkStatus;
4242
}
4343

44-
nsapi_error_t ret = wifi_if->connect(ssid, passphrase, ap_list[connected_ap].get_security());
44+
nsapi_error_t ret = wifi_if->connect(_ssid, passphrase, ap_list[connected_ap].get_security());
4545

4646
_currentNetworkStatus = ret == NSAPI_ERROR_OK ? WL_CONNECTED : WL_CONNECT_FAILED;
4747
return _currentNetworkStatus;

libraries/WiFi/src/WiFi.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class WiFiClass
7878
*
7979
* param ssid: Pointer to the SSID string.
8080
*/
81-
int begin(char* ssid);
81+
int begin(const char* ssid);
8282

8383
/* Start Wifi connection with WEP encryption.
8484
* Configure a key into the device. The key type (WEP-40, WEP-104)
@@ -88,7 +88,7 @@ class WiFiClass
8888
* param key_idx: The key index to set. Valid values are 0-3.
8989
* param key: Key input buffer.
9090
*/
91-
int begin(char* ssid, uint8_t key_idx, const char* key);
91+
int begin(const char* ssid, uint8_t key_idx, const char* key);
9292

9393
/* Start Wifi connection with passphrase
9494
* the most secure supported mode will be automatically selected
@@ -97,7 +97,7 @@ class WiFiClass
9797
* param passphrase: Passphrase. Valid characters in a passphrase
9898
* must be between ASCII 32-126 (decimal).
9999
*/
100-
int begin(char* ssid, const char *passphrase);
100+
int begin(const char* ssid, const char *passphrase);
101101

102102
int beginAP(const char *ssid, const char* passphrase, uint8_t channel = DEFAULT_AP_CHANNEL);
103103

@@ -309,7 +309,7 @@ class WiFiClass
309309
uint8_t connected_ap;
310310

311311
void ensureDefaultAPNetworkConfiguration();
312-
bool isVisible(char* ssid);
312+
bool isVisible(const char* ssid);
313313
arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress);
314314
};
315315

0 commit comments

Comments
 (0)