Add Linux TAP
This commit is contained in:
+16
-7
@@ -8,7 +8,6 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
static const char *TAG = "ping";
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -16,7 +15,7 @@ typedef struct
|
||||
SemaphoreHandle_t finished;
|
||||
} ping_context_t;
|
||||
|
||||
static bool parse_mac_address(const char *text, struct eth_addr * mac);
|
||||
static bool parse_mac_address(const char *text, struct eth_addr *mac);
|
||||
static void ping_device(device_info_t *device);
|
||||
void ping_selected_devices(const char *query);
|
||||
static void ping_success_callback(esp_ping_handle_t handle, void *arguments);
|
||||
@@ -25,11 +24,11 @@ static void ping_end_callback(esp_ping_handle_t handle, void *arguments);
|
||||
|
||||
static bool parse_mac_address(const char *text, struct eth_addr *mac)
|
||||
{
|
||||
if ((text == NULL) || (mac == NULL))
|
||||
if ((text == NULL) || (mac == NULL) || (strlen(text) != 12))
|
||||
return false;
|
||||
|
||||
return (sscanf(text,
|
||||
"%2hhX:%2hhX:%2hhX:%2hhX:%2hhX:%2hhX",
|
||||
"%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX",
|
||||
&mac->addr[0],
|
||||
&mac->addr[1],
|
||||
&mac->addr[2],
|
||||
@@ -40,6 +39,9 @@ static bool parse_mac_address(const char *text, struct eth_addr *mac)
|
||||
|
||||
void ping_selected_devices(const char *query)
|
||||
{
|
||||
if (query == NULL)
|
||||
return;
|
||||
|
||||
const char *current = query;
|
||||
|
||||
while ((current = strstr(current, "mac=")) != NULL)
|
||||
@@ -47,7 +49,7 @@ void ping_selected_devices(const char *query)
|
||||
struct eth_addr mac;
|
||||
device_info_t *device;
|
||||
|
||||
char mac_string[18];
|
||||
char mac_string[13];
|
||||
size_t length;
|
||||
current += 4;
|
||||
|
||||
@@ -110,10 +112,17 @@ static void ping_device(device_info_t *device)
|
||||
if (esp_ping_new_session(&config, &callbacks, &ping) != ESP_OK)
|
||||
{
|
||||
vSemaphoreDelete(context.finished);
|
||||
device->active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
esp_ping_start(ping);
|
||||
if (esp_ping_start(ping) != ESP_OK)
|
||||
{
|
||||
esp_ping_delete_session(ping);
|
||||
vSemaphoreDelete(context.finished);
|
||||
device->active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
xSemaphoreTake(context.finished, portMAX_DELAY);
|
||||
|
||||
@@ -135,4 +144,4 @@ static void ping_end_callback(esp_ping_handle_t handle, void *args)
|
||||
{
|
||||
ping_context_t *context = (ping_context_t *)args;
|
||||
xSemaphoreGive(context->finished);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user