-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from gjroots/dev
v1.2.0
- Loading branch information
Showing
28 changed files
with
494 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
idf_component_register(SRCS utils.c initialization.c nvm.c mac_generator.c | ||
idf_component_register(SRCS utils.c initialization.c nvm.c mac_generator.c mac_filter.c | ||
|
||
INCLUDE_DIRS include | ||
REQUIRES cmd_router cmd_nvs nvs_flash json esp_http_server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @author Jaya Satish | ||
* | ||
*@copyright Copyright (c) 2023 | ||
*Licensed under MIT | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
#include <stdbool.h> | ||
#include <esp_err.h> | ||
#include <cJSON.h> | ||
|
||
#define MAX_MAC_ADDRESSES 10 | ||
#define NVS_KEY "stored_macs" | ||
|
||
|
||
esp_err_t store_mac_address_in_nvs(const char *macAddress); | ||
esp_err_t remove_mac_address_from_nvs(const char *macAddress); | ||
bool check_mac_address_in_nvs(const char *macAddress); | ||
cJSON *retrieve_mac_addresses_as_json(); | ||
void mac_filter(const uint8_t mac[6],uint8_t aid); | ||
void refresh_mac_filter(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @author Jaya Satish | ||
* @license | ||
* this software licensed under MIT | ||
* | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <nvs_flash.h> | ||
#include <cJSON.h> | ||
#include <string.h> | ||
#include <esp_log.h> | ||
#include <esp_wifi.h> | ||
#include <esp_netif.h> | ||
#include <esp_wifi_types.h> | ||
|
||
#include "mac_filter.h" | ||
#include "initialization.h" | ||
|
||
|
||
bool check_mac_address_in_nvs(const char *macAddress) { | ||
cJSON *json = retrieve_mac_addresses_as_json(); | ||
if (json == NULL) return false; | ||
|
||
int numMacs = cJSON_GetArraySize(json); | ||
for (int i = 0; i < numMacs; i++) { | ||
if (strcmp(cJSON_GetArrayItem(json, i)->valuestring, macAddress) == 0) { | ||
cJSON_Delete(json); | ||
return true; | ||
} | ||
} | ||
|
||
cJSON_Delete(json); | ||
return false; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void mac_filter(const uint8_t mac[6], uint8_t aid) { | ||
char mac_address[18]; | ||
sprintf(mac_address, MACSTR, MAC2STR(mac)); | ||
if (IsMacFilterEnable) { | ||
if ((IsAllowList && !check_mac_address_in_nvs(mac_address)) || | ||
(!IsAllowList && check_mac_address_in_nvs(mac_address))) { | ||
ESP_LOGI("MAC Filter","MAC Address %s not allowed, disconnecting...\n", IsAllowList ? "NOT found in Allow List" : "found in Deny List"); | ||
esp_wifi_deauth_sta(aid); | ||
} | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
esp_err_t check_in_filter_list(const uint8_t mac[6]) { | ||
uint16_t aid; | ||
esp_err_t err = esp_wifi_ap_get_sta_aid(mac, &aid); | ||
if (err == ESP_OK) { | ||
mac_filter(mac, aid); | ||
} else { | ||
printf("Failed to get AID for MAC address\n"); | ||
} | ||
return err; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void refresh_mac_filter() { | ||
wifi_sta_list_t wifi_sta_list; | ||
tcpip_adapter_sta_list_t adapter_sta_list; | ||
memset(&wifi_sta_list, 0, sizeof(wifi_sta_list)); | ||
memset(&adapter_sta_list, 0, sizeof(adapter_sta_list)); | ||
ESP_ERROR_CHECK(esp_wifi_ap_get_sta_list(&wifi_sta_list)); | ||
ESP_ERROR_CHECK(tcpip_adapter_get_sta_list(&wifi_sta_list, &adapter_sta_list)); | ||
|
||
for (int i = 0; i < adapter_sta_list.num; i++) { | ||
tcpip_adapter_sta_info_t station = adapter_sta_list.sta[i]; | ||
esp_err_t result = check_in_filter_list(station.mac); | ||
if (result != ESP_OK) { | ||
//printf("Error processing MAC address at index %d\n", i); | ||
} | ||
|
||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ sass: | |
|
||
|
||
jekyll-minifier: | ||
compress_javascript: false | ||
exclude: "*.json" | ||
uglifier_args: | ||
harmony: true | ||
|
Oops, something went wrong.