mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Issue #589. Addition of authMode to createAP.
The `createAP` method allows us to become an access point. This commit adds the ability to specify an `authMode` to allow us to define the incoming authentication mode to be used.
This commit is contained in:
parent
dcd5b34f23
commit
d754fa33cd
@ -399,6 +399,8 @@ void jswrap_ESP8266_wifi_scan(
|
||||
]
|
||||
}
|
||||
* Create a logical access point allowing WiFi stations to connect.
|
||||
* The `options` object can contain the following properties.
|
||||
* * authMode - The authentication mode to use. Can be one of "open", "wpa2", "wpa", "wpa_wpa2".
|
||||
*/
|
||||
void jswrap_ESP8266_wifi_createAP(
|
||||
JsVar *jsSsid, //!< The network SSID that we will use to listen as.
|
||||
@ -425,16 +427,60 @@ void jswrap_ESP8266_wifi_createAP(
|
||||
struct softap_config softApConfig;
|
||||
memset(&softApConfig, 0, sizeof(softApConfig));
|
||||
|
||||
softApConfig.authmode = (AUTH_MODE)-1;
|
||||
|
||||
// Handle any options that may have been supplied.
|
||||
if (jsOptions != NULL && jsvIsObject(jsOptions)) {
|
||||
|
||||
// Handle "authMode" processing. Here we check that "authMode", if supplied, is
|
||||
// one of the allowed values and set the softApConfig object property appropriately.
|
||||
JsVar *jsAuth = jsvObjectGetChild(jsOptions, "authMode", 0);
|
||||
if (jsAuth != NULL) {
|
||||
if (jsvIsString(jsAuth)) {
|
||||
if (jsvIsStringEqual(jsAuth, "open")) {
|
||||
softApConfig.authmode = AUTH_OPEN;
|
||||
} else if (jsvIsStringEqual(jsAuth, "wpa2")) {
|
||||
softApConfig.authmode = AUTH_WPA2_PSK;
|
||||
} else if (jsvIsStringEqual(jsAuth, "wpa")) {
|
||||
softApConfig.authmode = AUTH_WPA_PSK;
|
||||
} else if (jsvIsStringEqual(jsAuth, "wpa_wpa2")) {
|
||||
softApConfig.authmode = AUTH_WPA_WPA2_PSK;
|
||||
} else {
|
||||
jsvUnLock(jsAuth);
|
||||
jsExceptionHere(JSET_ERROR, "Unknown authMode value.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
jsvUnLock(jsAuth);
|
||||
jsExceptionHere(JSET_ERROR, "The authMode must be a string.");
|
||||
return;
|
||||
}
|
||||
jsvUnLock(jsAuth);
|
||||
assert(softApConfig.authmode != (AUTH_MODE)-1);
|
||||
} // End of jsAuth is present.
|
||||
} // End of jsOptions is present
|
||||
|
||||
// If no password has been supplied, then be open. Otherwise, use WPA2 and the
|
||||
// password supplied. Also check that the password is at least 8 characters long.
|
||||
if (jsPassword == NULL || !jsvIsString(jsPassword)) {
|
||||
softApConfig.authmode = AUTH_OPEN;
|
||||
if (softApConfig.authmode == (AUTH_MODE)-1) {
|
||||
softApConfig.authmode = AUTH_OPEN;
|
||||
}
|
||||
if (softApConfig.authmode != AUTH_OPEN) {
|
||||
jsExceptionHere(JSET_ERROR, "Password not set but authMode not 'open'.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (jsvGetStringLength(jsPassword) < 8) {
|
||||
jsExceptionHere(JSET_ERROR, "Password must be 8 characters or more in length.");
|
||||
return;
|
||||
}
|
||||
softApConfig.authmode = AUTH_WPA2_PSK;
|
||||
if (softApConfig.authmode == (AUTH_MODE)-1) {
|
||||
softApConfig.authmode = AUTH_WPA2_PSK;
|
||||
}
|
||||
if (softApConfig.authmode == AUTH_OPEN) {
|
||||
jsWarn("wifi.connection: Auth mode set to open but password supplied!");
|
||||
}
|
||||
int len = jsvGetString(jsPassword, (char *)softApConfig.password, sizeof(softApConfig.password)-1);
|
||||
softApConfig.password[len]='\0';
|
||||
}
|
||||
|
||||
@ -359,14 +359,16 @@ The status is a JS integer that describes the current connection status which wi
|
||||
|
||||
Become an access point.
|
||||
|
||||
`ESP8266WiFi.beAccessPoint(ssid [,password] [,options] [,callback])`
|
||||
`wifi.createAP(ssid [,password] [,options] [,callback])`
|
||||
|
||||
Become an access point for the network supplied by `ssid` with a password of `password`. If no
|
||||
password is supplied or is null, then the access point is considered open and be connected to by
|
||||
a station that need not supply a password. If a password is supplied, it must be at least
|
||||
eight characters in size.
|
||||
|
||||
The `options` allows us to supply options. None are currently defined.
|
||||
The `options` allows us to supply options.
|
||||
|
||||
* `authMode` - The authentication mode to use. Can be one of `open`, `wpa2`, `wpa` or `wpa_wpa2`. If not supplied then the value will be `wpa2` if a password is supplied and `open` if no password is supplied.
|
||||
|
||||
The `callback` is a a function with the following signature:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user