diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index 9b53b2c7..461b98ec 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -990,6 +990,106 @@ int setAnalogWrite(const uint8_t command[], uint8_t response[]) } +#include "esp_wpa2.h" + +int wpa2EntSetIdentity(const uint8_t command[], uint8_t response[]) { + char identity[32 + 1]; + + memset(identity, 0x00, sizeof(identity)); + memcpy(identity, &command[4], command[3]); + + esp_wifi_sta_wpa2_ent_set_identity((const unsigned char*)identity, strlen(identity)); + + response[2] = 1; // number of parameters + response[3] = 1; // parameter 1 length + response[4] = 1; + + return 6; +} + +int wpa2EntSetUsername(const uint8_t command[], uint8_t response[]) { + char username[32 + 1]; + + memset(username, 0x00, sizeof(username)); + memcpy(username, &command[4], command[3]); + + esp_wifi_sta_wpa2_ent_set_username((const unsigned char*)username, strlen(username)); + + response[2] = 1; // number of parameters + response[3] = 1; // parameter 1 length + response[4] = 1; + + return 6; +} + +int wpa2EntSetPassword(const uint8_t command[], uint8_t response[]) { + char password[32 + 1]; + + memset(password, 0x00, sizeof(password)); + memcpy(password, &command[4], command[3]); + + esp_wifi_sta_wpa2_ent_set_password((const unsigned char*)password, strlen(password)); + + response[2] = 1; // number of parameters + response[3] = 1; // parameter 1 length + response[4] = 1; + + return 6; +} + +int wpa2EntSetCACert(const uint8_t command[], uint8_t response[]) { + + // Add +1 for \0 termination + size_t ca_cert_buf_size = (command[3] << 8 | command[4]); + uint8_t* ca_cert_buf = (uint8_t*)malloc(ca_cert_buf_size + 1); + + memset(ca_cert_buf, 0x00, ca_cert_buf_size + 1); + memcpy(ca_cert_buf, &command[6], ca_cert_buf_size); + + esp_wifi_sta_wpa2_ent_set_ca_cert(ca_cert_buf, ca_cert_buf_size + 1); + + response[2] = 1; // number of parameters + response[3] = 1; // parameter 1 length + response[4] = 1; + + return 6; +} + +int wpa2EntSetCertKey(const uint8_t command[], uint8_t response[]) { + + // Add +1 for \0 termination + size_t client_crt_buf_size = (command[3] << 8 | command[4]); + size_t client_key_buf_size = (command[5] << 8 | command[6]); + uint8_t* client_crt_buf = (uint8_t*)malloc(client_crt_buf_size + 1); + uint8_t* client_key_buf = (uint8_t*)malloc(client_key_buf_size + 1); + + memset(client_crt_buf, 0x00, client_crt_buf_size + 1); + memset(client_key_buf, 0x00, client_key_buf_size + 1); + + memcpy(client_crt_buf, &command[8], client_crt_buf_size); + memcpy(client_key_buf, &command[9 + client_crt_buf_size], client_key_buf_size); + + esp_wifi_sta_wpa2_ent_set_cert_key(client_crt_buf, client_crt_buf_size + 1, client_key_buf, client_key_buf_size + 1, NULL, 0); + + response[2] = 1; // number of parameters + response[3] = 1; // parameter 1 length + response[4] = 1; + + return 6; +} + +int wpa2EntEnable(const uint8_t command[], uint8_t response[]) { + + esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); + esp_wifi_sta_wpa2_ent_enable(&config); + + response[2] = 1; // number of parameters + response[3] = 1; // parameter 1 length + response[4] = 1; + + return 6; +} + typedef int (*CommandHandlerType)(const uint8_t command[], uint8_t response[]); const CommandHandlerType commandHandlers[] = { @@ -1006,7 +1106,7 @@ const CommandHandlerType commandHandlers[] = { disconnect, NULL, getIdxRSSI, getIdxEnct, reqHostByName, getHostByName, startScanNetworks, getFwVersion, NULL, sendUDPdata, getRemoteData, getTime, getIdxBSSID, getIdxChannel, ping, getSocket, // 0x40 -> 0x4f - NULL, NULL, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, wpa2EntSetIdentity, wpa2EntSetUsername, wpa2EntSetPassword, wpa2EntSetCACert, wpa2EntSetCertKey, wpa2EntEnable, // 0x50 -> 0x5f setPinMode, setDigitalWrite, setAnalogWrite,