Skip to content

Commit

Permalink
Merge pull request #18 from Niek/master
Browse files Browse the repository at this point in the history
Add support for WPA Enterprise (PEAP/TTLS only)
  • Loading branch information
xoseperez authored Dec 29, 2019
2 parents 8bb2c16 + d1479a3 commit 637297c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
39 changes: 38 additions & 1 deletion src/JustWifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,37 @@ uint8_t JustWifi::_doSTA(uint8_t id) {
_doCallback(MESSAGE_CONNECTING, buffer);
}

#ifdef JUSTWIFI_ENABLE_ENTERPRISE
if (entry.enterprise_username && entry.enterprise_password) {
// Create config
struct station_config wifi_config;
memset(&wifi_config, 0, sizeof(wifi_config));
strcpy((char*)wifi_config.ssid, entry.ssid);
wifi_config.bssid_set = 0;
*wifi_config.password = 0;

// Set some defaults
wifi_set_opmode(STATION_MODE);
wifi_station_set_config_current(&wifi_config);
wifi_station_set_enterprise_disable_time_check(1);
wifi_station_clear_cert_key();
wifi_station_clear_enterprise_ca_cert();
wifi_station_set_wpa2_enterprise_auth(1);

// Set user/pass
wifi_station_set_enterprise_identity((uint8*)entry.enterprise_username, strlen(entry.enterprise_username));
wifi_station_set_enterprise_username((uint8*)entry.enterprise_username, strlen(entry.enterprise_username));
wifi_station_set_enterprise_password((uint8*)entry.enterprise_password, strlen(entry.enterprise_password));

// Connect, free resources after
wifi_station_connect();
wifi_station_clear_enterprise_identity();
wifi_station_clear_enterprise_username();
wifi_station_clear_enterprise_password();
wifi_station_clear_cert_key();
wifi_station_clear_enterprise_ca_cert();
} else
#endif
if (entry.channel == 0) {
WiFi.begin(entry.ssid, entry.pass);
} else {
Expand Down Expand Up @@ -628,7 +659,9 @@ bool JustWifi::addNetwork(
const char * gw,
const char * netmask,
const char * dns,
bool front
bool front,
const char * enterprise_username,
const char * enterprise_password
) {

network_t new_network;
Expand Down Expand Up @@ -672,6 +705,10 @@ bool JustWifi::addNetwork(
if (dns && *dns != 0x00) {
new_network.dns.fromString(dns);
}
if (enterprise_username && enterprise_password && *enterprise_username != 0x00 && *enterprise_password != 0x00) {
new_network.enterprise_username = strdup(enterprise_username);
new_network.enterprise_password = strdup(enterprise_password);
}

// Defaults
new_network.rssi = 0;
Expand Down
10 changes: 9 additions & 1 deletion src/JustWifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ along with the JustWifi library. If not, see <http://www.gnu.org/licenses/>.
#include <vector>
#include <ESP8266WiFi.h>

#ifdef JUSTWIFI_ENABLE_ENTERPRISE
#include "wpa2_enterprise.h"
#endif

extern "C" {
#include "user_interface.h"
}
Expand Down Expand Up @@ -66,6 +70,8 @@ typedef struct {
uint8_t channel;
uint8_t bssid[6];
uint8_t next;
char * enterprise_username;
char * enterprise_password;
} network_t;

typedef enum {
Expand Down Expand Up @@ -138,7 +144,9 @@ class JustWifi {
const char * gw = NULL,
const char * netmask = NULL,
const char * dns = NULL,
bool front = false
bool front = false,
const char * enterprise_username = NULL,
const char * enterprise_password = NULL
);
bool setSoftAP(
const char * ssid,
Expand Down

0 comments on commit 637297c

Please sign in to comment.