Skip to content

Commit 637297c

Browse files
authored
Merge pull request #18 from Niek/master
Add support for WPA Enterprise (PEAP/TTLS only)
2 parents 8bb2c16 + d1479a3 commit 637297c

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/JustWifi.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,37 @@ uint8_t JustWifi::_doSTA(uint8_t id) {
251251
_doCallback(MESSAGE_CONNECTING, buffer);
252252
}
253253

254+
#ifdef JUSTWIFI_ENABLE_ENTERPRISE
255+
if (entry.enterprise_username && entry.enterprise_password) {
256+
// Create config
257+
struct station_config wifi_config;
258+
memset(&wifi_config, 0, sizeof(wifi_config));
259+
strcpy((char*)wifi_config.ssid, entry.ssid);
260+
wifi_config.bssid_set = 0;
261+
*wifi_config.password = 0;
262+
263+
// Set some defaults
264+
wifi_set_opmode(STATION_MODE);
265+
wifi_station_set_config_current(&wifi_config);
266+
wifi_station_set_enterprise_disable_time_check(1);
267+
wifi_station_clear_cert_key();
268+
wifi_station_clear_enterprise_ca_cert();
269+
wifi_station_set_wpa2_enterprise_auth(1);
270+
271+
// Set user/pass
272+
wifi_station_set_enterprise_identity((uint8*)entry.enterprise_username, strlen(entry.enterprise_username));
273+
wifi_station_set_enterprise_username((uint8*)entry.enterprise_username, strlen(entry.enterprise_username));
274+
wifi_station_set_enterprise_password((uint8*)entry.enterprise_password, strlen(entry.enterprise_password));
275+
276+
// Connect, free resources after
277+
wifi_station_connect();
278+
wifi_station_clear_enterprise_identity();
279+
wifi_station_clear_enterprise_username();
280+
wifi_station_clear_enterprise_password();
281+
wifi_station_clear_cert_key();
282+
wifi_station_clear_enterprise_ca_cert();
283+
} else
284+
#endif
254285
if (entry.channel == 0) {
255286
WiFi.begin(entry.ssid, entry.pass);
256287
} else {
@@ -628,7 +659,9 @@ bool JustWifi::addNetwork(
628659
const char * gw,
629660
const char * netmask,
630661
const char * dns,
631-
bool front
662+
bool front,
663+
const char * enterprise_username,
664+
const char * enterprise_password
632665
) {
633666

634667
network_t new_network;
@@ -672,6 +705,10 @@ bool JustWifi::addNetwork(
672705
if (dns && *dns != 0x00) {
673706
new_network.dns.fromString(dns);
674707
}
708+
if (enterprise_username && enterprise_password && *enterprise_username != 0x00 && *enterprise_password != 0x00) {
709+
new_network.enterprise_username = strdup(enterprise_username);
710+
new_network.enterprise_password = strdup(enterprise_password);
711+
}
675712

676713
// Defaults
677714
new_network.rssi = 0;

src/JustWifi.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ along with the JustWifi library. If not, see <http://www.gnu.org/licenses/>.
2828
#include <vector>
2929
#include <ESP8266WiFi.h>
3030

31+
#ifdef JUSTWIFI_ENABLE_ENTERPRISE
32+
#include "wpa2_enterprise.h"
33+
#endif
34+
3135
extern "C" {
3236
#include "user_interface.h"
3337
}
@@ -66,6 +70,8 @@ typedef struct {
6670
uint8_t channel;
6771
uint8_t bssid[6];
6872
uint8_t next;
73+
char * enterprise_username;
74+
char * enterprise_password;
6975
} network_t;
7076

7177
typedef enum {
@@ -138,7 +144,9 @@ class JustWifi {
138144
const char * gw = NULL,
139145
const char * netmask = NULL,
140146
const char * dns = NULL,
141-
bool front = false
147+
bool front = false,
148+
const char * enterprise_username = NULL,
149+
const char * enterprise_password = NULL
142150
);
143151
bool setSoftAP(
144152
const char * ssid,

0 commit comments

Comments
 (0)