diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index 1f1cea111..00febc30f 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -1326,6 +1326,33 @@ static void hostapd_disassoc_deny_mac(struct hostapd_data *hapd) } } + +static int hostapd_ctrl_iface_set_band(struct hostapd_data *hapd, + const char *band) +{ + union wpa_event_data event; + enum set_band setband; + + if (os_strcmp(band, "AUTO") == 0) + setband = WPA_SETBAND_AUTO; + else if (os_strcmp(band, "5G") == 0) + setband = WPA_SETBAND_5G; + else if (os_strcmp(band, "2G") == 0) + setband = WPA_SETBAND_2G; + else + return -1; + + if (hostapd_drv_set_band(hapd, setband) == 0) { + os_memset(&event, 0, sizeof(event)); + event.channel_list_changed.initiator = REGDOM_SET_BY_USER; + event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN; + wpa_supplicant_event(hapd, EVENT_CHANNEL_LIST_CHANGED, &event); + } + + return 0; +} + + static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd) { char *value; @@ -1409,6 +1436,8 @@ static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd) os_free(hapd->dpp_configurator_params); hapd->dpp_configurator_params = os_strdup(value); #endif /* CONFIG_DPP */ + } else if (os_strcasecmp(cmd, "setband") == 0) { + ret = hostapd_ctrl_iface_set_band(hapd, value); } else { ret = hostapd_set_iface(hapd->iconf, hapd->conf, cmd, value); if (ret) diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h index 79b1302ac..fa413df08 100644 --- a/src/ap/ap_drv_ops.h +++ b/src/ap/ap_drv_ops.h @@ -382,4 +382,12 @@ hostapd_drv_send_external_auth_status(struct hostapd_data *hapd, return hapd->driver->send_external_auth_status(hapd->drv_priv, params); } +static inline int +hostapd_drv_set_band(struct hostapd_data *hapd, enum set_band band) +{ + if (!hapd->driver || !hapd->drv_priv || !hapd->driver->set_band) + return -1; + return hapd->driver->set_band(hapd->drv_priv, band); +} + #endif /* AP_DRV_OPS */