Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOSTPAD driver changes for PAC #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions debian/config/hostapd/linux
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,10 @@ CONFIG_SAE=y
# Override default value for the wpa_disable_eapol_key_retries configuration
# parameter. See that parameter in hostapd.conf for more details.
#CFLAGS += -DDEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES=1
#
# SONIC HOSTAPD
CONFIG_SONIC_HOSTAPD=y

# SONIC RADIUS attribute parser
CONFIG_SONIC_RADIUS=y
# #
8 changes: 8 additions & 0 deletions hostapd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,21 @@ CFLAGS += -DHOSTAPD_DUMP_STATE
OBJS += ../src/eapol_auth/eapol_auth_dump.o
endif

ifdef CONFIG_SONIC_HOSTAPD
CFLAGS += -DCONFIG_SONIC_HOSTAPD
endif

ifdef CONFIG_NO_RADIUS
CFLAGS += -DCONFIG_NO_RADIUS
CONFIG_NO_ACCOUNTING=y
else
OBJS += ../src/radius/radius.o
OBJS += ../src/radius/radius_client.o
OBJS += ../src/radius/radius_das.o
ifdef CONFIG_SONIC_RADIUS
CFLAGS += -DCONFIG_SONIC_RADIUS
OBJS += ../src/radius/radius_attr_parse.o
endif
endif

ifdef CONFIG_NO_ACCOUNTING
Expand Down
118 changes: 117 additions & 1 deletion hostapd/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "ap/wpa_auth.h"
#include "ap/ap_config.h"
#include "config_file.h"

#ifdef CONFIG_SONIC_HOSTAPD
#include "utils/json.h"
#endif

#ifndef CONFIG_NO_VLAN
static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
Expand Down Expand Up @@ -4694,3 +4696,117 @@ int hostapd_set_iface(struct hostapd_config *conf,

return 0;
}

#ifdef CONFIG_SONIC_HOSTAPD
int hostapd_sonic_json_file_read(hostapd_json_data_t *parsed_data)
{
FILE *f;
long len;
char *content = NULL;
struct json_token *root, *deleted_interfaces, *modified_interfaces, *new_interfaces;
struct json_token *elem, *if_name, *if_path;
int rc = 0;
int i;

/* open the config file and read the content */
f=fopen(HOSTAPD_SONIC_JSON_PATH,"rb");
fseek(f,0,SEEK_END);
len=ftell(f);
fseek(f,0,SEEK_SET);

content=(char*)malloc(len+1);
if (!content) {
return -1;
}

fread(content,1,len,f);
fclose(f);

/* delete the json file */

if (remove (HOSTAPD_SONIC_JSON_PATH))
{
wpa_printf(MSG_ERROR, "json file delete failed");
}
else
{
wpa_printf(MSG_DEBUG, "json file delete successful");
}

root=json_parse(content, len);
if (!root) {
wpa_printf(MSG_ERROR, "Error parsing JSON !!");
rc = -1;
goto clean_up;
}

/* Obtain deleted interfaces */
deleted_interfaces = json_get_member(root, "deleted_interfaces");
if (NULL != deleted_interfaces)
{
/* Read the deleted interfaces */
parsed_data->deleted_count = json_get_array_size(deleted_interfaces);

for (i = 0; i < parsed_data->deleted_count; i++)
{
elem = json_get_array_item(deleted_interfaces, i);
if (elem)
{
if_name = json_get_member(elem, "if_name");
strncpy (&parsed_data->deleted_intf[i].if_name[0], if_name->string, strlen(if_name->string));
}
}
}

/* Obtain modified interfaces */
modified_interfaces = json_get_member(root, "modified_interfaces");
if (NULL != modified_interfaces)
{
parsed_data->modified_count = json_get_array_size(modified_interfaces);

/* Read the modified interfaces */
for (i = 0; i < parsed_data->modified_count; i++)
{
elem = json_get_array_item(modified_interfaces, i);
if (elem)
{
if_name = json_get_member(elem, "if_name");
strncpy (&parsed_data->modified_intf[i].if_name[0], if_name->string, strlen(if_name->string));
if_path = json_get_member(elem, "path");
strncpy (&parsed_data->modified_intf[i].file_path[0], if_path->string, strlen(if_path->string));
}
}
}

/* Obtain new interfaces */
new_interfaces = json_get_member(root, "new_interfaces");
if (NULL != new_interfaces)
{
/* Read the new interfaces */
parsed_data->new_count = json_get_array_size(new_interfaces);

/* Read the modified interfaces */
for (i = 0; i < parsed_data->new_count; i++)
{
elem = json_get_array_item(new_interfaces, i);
if (elem)
{
if_name = json_get_member(elem, "if_name");
strncpy (&parsed_data->new_intf[i].if_name[0], if_name->string, strlen(if_name->string));
if_path = json_get_member(elem, "path");
strncpy (&parsed_data->new_intf[i].file_path[0], if_path->string, strlen(if_path->string));
}
}
}

clean_up:

if (root)
json_free(root);

if (content)
free (content);

return rc;
}
#endif
27 changes: 27 additions & 0 deletions hostapd/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@
#ifndef CONFIG_FILE_H
#define CONFIG_FILE_H

#ifdef CONFIG_SONIC_HOSTAPD

#define HOSTAPD_JSON_MAX_INTF 512
#define HOSTAPD_SONIC_JSON_PATH "/etc/hostapd/hostapd_config.json"

typedef struct hostapd_intf_json_s
{
char if_name[64];
char file_path[64];
}hostapd_intf_json_t;

typedef struct hostapd_json_data_s
{
hostapd_intf_json_t deleted_intf[HOSTAPD_JSON_MAX_INTF];
unsigned int deleted_count;

hostapd_intf_json_t modified_intf[HOSTAPD_JSON_MAX_INTF];
unsigned int modified_count;

hostapd_intf_json_t new_intf[HOSTAPD_JSON_MAX_INTF];
unsigned int new_count;
}hostapd_json_data_t;

int hostapd_sonic_json_file_read(hostapd_json_data_t *parsed_data);

#endif

struct hostapd_config * hostapd_config_read(const char *fname);
int hostapd_set_iface(struct hostapd_config *conf,
struct hostapd_bss_config *bss, const char *field,
Expand Down
103 changes: 103 additions & 0 deletions hostapd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ static int handle_reload_iface(struct hostapd_iface *iface, void *ctx)
/**
* handle_reload - SIGHUP handler to reload configuration
*/
#ifndef CONFIG_SONIC_HOSTAPD

static void handle_reload(int sig, void *signal_ctx)
{
struct hapd_interfaces *interfaces = signal_ctx;
Expand All @@ -323,6 +325,97 @@ static void handle_reload(int sig, void *signal_ctx)
hostapd_for_each_interface(interfaces, handle_reload_iface, NULL);
}

#else

static void handle_reload(int sig, void *signal_ctx)
{
int i;
struct hostapd_data *hapd;
struct hostapd_iface *hapd_iface = NULL;
struct hostapd_iface **tmp;
struct hapd_interfaces *interfaces = signal_ctx;
hostapd_json_data_t *intf_changed = (hostapd_json_data_t *)malloc(sizeof(hostapd_json_data_t));

wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration", sig);

if (!intf_changed)
{
wpa_printf(MSG_DEBUG, "couldn't allocate memory while reloading configuration");
return;
}
memset(intf_changed, 0, sizeof(*intf_changed));

/* read the sonic json file */

if (!hostapd_sonic_json_file_read(intf_changed))
{
/* purge the deleted interfaces */
for (i = 0; i < intf_changed->deleted_count; i++) {
hapd = hostapd_get_iface(interfaces, intf_changed->deleted_intf[i].if_name);

/* skip already deleted interface*/
if (!hapd)
continue;

if (hostapd_disable_iface(hapd->iface))
wpa_printf(MSG_DEBUG, "Could not disable iface");

if (hostapd_remove_iface(interfaces, hapd->conf->iface))
wpa_printf(MSG_DEBUG, "Could not remove iface");
}

unsigned int j = 0;
/* now reload the interfaces that are modified */
/*hostapd_for_each_interface(interfaces, handle_reload_iface, NULL); */
for (i = 0; i < intf_changed->modified_count; i++) {
for (j = 0; j < interfaces->count; j++)
{
hapd_iface = interfaces->iface[j];
if (0 == strcmp(hapd_iface->conf->bss[0]->iface, intf_changed->modified_intf[i].if_name))
{
wpa_printf(MSG_DEBUG, "Reloading iface %s", intf_changed->modified_intf[i].if_name);
handle_reload_iface(interfaces->iface[j], NULL);
}
}
}


for (i = 0; i < intf_changed->new_count; i++)
{
/* append the new interfaces and start them*/
hapd_iface = hostapd_interface_init(interfaces,
intf_changed->new_intf[i].if_name, intf_changed->new_intf[i].file_path, 0);
if (!hapd_iface)
goto clean_up;

tmp = os_realloc_array(interfaces->iface,
interfaces->count + 1,
sizeof(struct hostapd_iface *));
if (!tmp) {
hostapd_interface_deinit_free(hapd_iface);
goto clean_up;
}
interfaces->iface = tmp;
interfaces->iface[interfaces->count++] = hapd_iface;
if (interfaces->driver_init(hapd_iface))
goto clean_up;

if (hostapd_setup_interface(hapd_iface)) {
hostapd_deinit_driver(
hapd_iface->bss[0]->driver,
hapd_iface->bss[0]->drv_priv,
hapd_iface);
goto clean_up;
}
}
}

clean_up:
free(intf_changed);

return;
}
#endif

static void handle_dump_state(int sig, void *signal_ctx)
{
Expand Down Expand Up @@ -442,6 +535,16 @@ static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize,
}
}

#ifdef CONFIG_SONIC_HOSTAPD
if (pid_file) {
FILE *f = fopen(pid_file, "w");
if (f) {
fprintf(f, "%u\n", getpid());
fclose(f);
}
}
#endif

eloop_run();

return 0;
Expand Down
Loading
Loading