[PATCH v2] wifi: support ap-mode with wpa_supplicant
- From: Jan Luebbe <jlu pengutronix de>
- To: networkmanager-list gnome org
- Subject: [PATCH v2] wifi: support ap-mode with wpa_supplicant
- Date: Fri, 6 Jul 2012 14:47:48 +0200
A new value for NM80211Mode is introduced (NM_802_11_MODE_AP) and the
new mode is passed to wpa_supplicant analogous to adhoc-mode.
The places which need to know the interface mode have been extended to
handle the new mode.
If the configuration does not contain a fixed frequency, a channel is
selected the same way as with adhoc-mode before.
---
Hi,
I've updated the patch to the current master. Dan Williams' comments
have been incorporated.
For the basic AP mode functionality it worked fine during my testing.
Note that I don't have the GUI interface on my target system, so there may
still be something missing.
Thanks!
Jan
cli/src/devices.c | 5 ++-
examples/C/glib/get-ap-info-libnm-glib.c | 5 ++-
include/NetworkManager.h | 4 ++-
introspection/generic-types.xml | 3 ++
libnm-glib/nm-access-point.c | 5 ++-
libnm-util/nm-setting-wireless.c | 8 ++---
libnm-util/nm-setting-wireless.h | 7 ++++
src/nm-device-wifi.c | 34 ++++++++++++++------
src/nm-wifi-ap-utils.c | 6 ++++
src/nm-wifi-ap.c | 7 ++++
src/supplicant-manager/nm-supplicant-config.c | 34 ++++++++++++--------
.../nm-supplicant-settings-verify.c | 2 +-
src/wifi/wifi-utils-nl80211.c | 3 ++
src/wifi/wifi-utils-wext.c | 5 +++
src/wifi/wifi-utils.c | 4 ++-
test/nm-tool.c | 5 ++-
16 files changed, 103 insertions(+), 34 deletions(-)
diff --git a/cli/src/devices.c b/cli/src/devices.c
index 6b9367b..70f0f4c 100644
--- a/cli/src/devices.c
+++ b/cli/src/devices.c
@@ -407,7 +407,10 @@ detail_access_point (gpointer data, gpointer user_data)
info->nmc->allowed_fields[0].value = ap_name;
info->nmc->allowed_fields[1].value = ssid_str;
info->nmc->allowed_fields[2].value = bssid;
- info->nmc->allowed_fields[3].value = mode == NM_802_11_MODE_ADHOC ? _("Ad-Hoc") : mode == NM_802_11_MODE_INFRA ? _("Infrastructure") : _("Unknown");
+ info->nmc->allowed_fields[3].value = mode == NM_802_11_MODE_ADHOC ? _("Ad-Hoc")
+ : mode == NM_802_11_MODE_AP ? _("AP")
+ : mode == NM_802_11_MODE_INFRA ? _("Infrastructure")
+ : _("Unknown");
info->nmc->allowed_fields[4].value = freq_str;
info->nmc->allowed_fields[5].value = bitrate_str;
info->nmc->allowed_fields[6].value = strength_str;
diff --git a/examples/C/glib/get-ap-info-libnm-glib.c b/examples/C/glib/get-ap-info-libnm-glib.c
index 316bce0..67ee78d 100644
--- a/examples/C/glib/get-ap-info-libnm-glib.c
+++ b/examples/C/glib/get-ap-info-libnm-glib.c
@@ -133,7 +133,10 @@ show_access_point_info (NMAccessPoint *ap)
printf ("SSID: %s\n", ssid_str);
printf ("BSSID: %s\n", hwaddr);
- printf ("Mode: %s\n", mode == NM_802_11_MODE_ADHOC ? "Ad-Hoc" : mode == NM_802_11_MODE_INFRA ? "Infrastructure" : "Unknown");
+ printf ("Mode: %s\n", mode == NM_802_11_MODE_ADHOC ? "Ad-Hoc"
+ : mode == NM_802_11_MODE_AP ? "AP"
+ : mode == NM_802_11_MODE_INFRA ? "Infrastructure"
+ : "Unknown");
printf ("Freq: %s\n", freq_str);
printf ("Bitrate: %s\n", bitrate_str);
printf ("Strength: %s\n", strength_str);
diff --git a/include/NetworkManager.h b/include/NetworkManager.h
index 96b132e..90e571e 100644
--- a/include/NetworkManager.h
+++ b/include/NetworkManager.h
@@ -230,13 +230,15 @@ typedef enum {
* @NM_802_11_MODE_UNKNOWN: the device or access point mode is unknown
* @NM_802_11_MODE_ADHOC: the device or access point is in Ad-Hoc mode
* @NM_802_11_MODE_INFRA: the device or access point is in infrastructure mode
+ * @NM_802_11_MODE_AP: the device or access point is in access point mode
*
* Indicates the 802.11 mode an access point or device is currently in.
**/
typedef enum {
NM_802_11_MODE_UNKNOWN = 0,
NM_802_11_MODE_ADHOC,
- NM_802_11_MODE_INFRA
+ NM_802_11_MODE_INFRA,
+ NM_802_11_MODE_AP
} NM80211Mode;
/**
diff --git a/introspection/generic-types.xml b/introspection/generic-types.xml
index 1a9e316..e260032 100644
--- a/introspection/generic-types.xml
+++ b/introspection/generic-types.xml
@@ -31,5 +31,8 @@
<tp:enumvalue suffix="INFRA" value="2">
<tp:docstring>Coordinated network with one or more central controllers.</tp:docstring>
</tp:enumvalue>
+ <tp:enumvalue suffix="AP" value="3">
+ <tp:docstring>Central controller of a coordinated network.</tp:docstring>
+ </tp:enumvalue>
</tp:enum>
</tp:generic-types>
diff --git a/libnm-glib/nm-access-point.c b/libnm-glib/nm-access-point.c
index fef6557..76f7fd6 100644
--- a/libnm-glib/nm-access-point.c
+++ b/libnm-glib/nm-access-point.c
@@ -347,6 +347,9 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection)
return FALSE;
if (!strcmp (setting_mode, "adhoc") && (ap_mode != NM_802_11_MODE_ADHOC))
return FALSE;
+ if (!strcmp (setting_mode, "ap") && (ap_mode != NM_802_11_MODE_AP)) {
+ return FALSE;
+ }
}
/* Band and Channel/Frequency */
@@ -665,7 +668,7 @@ nm_access_point_class_init (NMAccessPointClass *ap_class)
g_param_spec_uint (NM_ACCESS_POINT_MODE,
"Mode",
"Mode",
- NM_802_11_MODE_ADHOC, NM_802_11_MODE_INFRA, NM_802_11_MODE_INFRA,
+ NM_802_11_MODE_ADHOC, NM_802_11_MODE_AP, NM_802_11_MODE_INFRA,
G_PARAM_READABLE));
/**
diff --git a/libnm-util/nm-setting-wireless.c b/libnm-util/nm-setting-wireless.c
index f9ed310..b7eed96 100644
--- a/libnm-util/nm-setting-wireless.c
+++ b/libnm-util/nm-setting-wireless.c
@@ -584,7 +584,7 @@ static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
- const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, NM_SETTING_WIRELESS_MODE_ADHOC, NULL };
+ const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, NM_SETTING_WIRELESS_MODE_ADHOC, NM_SETTING_WIRELESS_MODE_AP, NULL };
const char *valid_bands[] = { "a", "bg", NULL };
GSList *iter;
@@ -881,15 +881,15 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class)
/**
* NMSettingWireless:mode:
*
- * WiFi network mode; one of 'infrastructure' or 'adhoc'. If blank,
+ * WiFi network mode; one of 'infrastructure', 'adhoc' or 'ap'. If blank,
* infrastructure is assumed.
**/
g_object_class_install_property
(object_class, PROP_MODE,
g_param_spec_string (NM_SETTING_WIRELESS_MODE,
"Mode",
- "WiFi network mode; one of 'infrastructure' or "
- "'adhoc'. If blank, infrastructure is assumed.",
+ "WiFi network mode; one of 'infrastructure', "
+ "'adhoc' or 'ap'. If blank, infrastructure is assumed.",
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
diff --git a/libnm-util/nm-setting-wireless.h b/libnm-util/nm-setting-wireless.h
index abbf231..88e2013 100644
--- a/libnm-util/nm-setting-wireless.h
+++ b/libnm-util/nm-setting-wireless.h
@@ -86,6 +86,13 @@ GQuark nm_setting_wireless_error_quark (void);
#define NM_SETTING_WIRELESS_MODE_ADHOC "adhoc"
/**
+ * NM_SETTING_WIRELESS_MODE_AP:
+ *
+ * Indicates AP/master mode where this device is the access point.
+ */
+#define NM_SETTING_WIRELESS_MODE_AP "ap"
+
+/**
* NM_SETTING_WIRELESS_MODE_INFRA:
*
* Indicates infrastructure mode where an access point is expected to be present
diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c
index e2ff77e..97b64b9 100644
--- a/src/nm-device-wifi.c
+++ b/src/nm-device-wifi.c
@@ -716,6 +716,10 @@ periodic_update (gpointer user_data)
if (nm_supplicant_interface_get_scanning (priv->supplicant.iface))
return TRUE;
+ /* In AP mode we currently have nothing to do. */
+ if (priv->current_ap && (nm_ap_get_mode (priv->current_ap) == NM_802_11_MODE_AP))
+ return;
+
/* In IBSS mode, most newer firmware/drivers do "BSS coalescing" where
* multiple IBSS stations using the same SSID will eventually switch to
* using the same BSSID to avoid network segmentation. When this happens,
@@ -1062,6 +1066,15 @@ real_check_connection_compatible (NMDevice *device,
return FALSE;
}
+ if ( (g_strcmp0 (nm_setting_wireless_get_mode (s_wireless), NM_SETTING_WIRELESS_MODE_AP) == 0)
+ && !(priv->capabilities & NM_WIFI_DEVICE_CAP_AP)) {
+ g_set_error_literal (error,
+ NM_WIFI_ERROR,
+ NM_WIFI_ERROR_CONNECTION_INCOMPATIBLE,
+ "Access Point (AP) mode is not supported by this device.");
+ return FALSE;
+ }
+
// FIXME: check channel/freq/band against bands the hardware supports
// FIXME: check encryption against device capabilities
// FIXME: check bitrate against device capabilities
@@ -2601,7 +2614,7 @@ build_supplicant_config (NMDeviceWifi *self,
NMSupplicantConfig *config = NULL;
NMSettingWireless *s_wireless;
NMSettingWirelessSecurity *s_wireless_sec;
- guint32 adhoc_freq = 0;
+ guint32 fixed_freq = 0;
g_return_val_if_fail (self != NULL, NULL);
@@ -2616,31 +2629,32 @@ build_supplicant_config (NMDeviceWifi *self,
* didn't specify one and we didn't find an AP that matched the connection,
* just pick a frequency the device supports.
*/
- if (nm_ap_get_mode (ap) == NM_802_11_MODE_ADHOC) {
+ if ( nm_ap_get_mode (ap) == NM_802_11_MODE_ADHOC
+ || nm_ap_get_mode (ap) == NM_802_11_MODE_AP) {
const char *band = nm_setting_wireless_get_band (s_wireless);
const guint32 a_freqs[] = { 5180, 5200, 5220, 5745, 5765, 5785, 5805, 0 };
const guint32 bg_freqs[] = { 2412, 2437, 2462, 2472, 0 };
- adhoc_freq = nm_ap_get_freq (ap);
- if (!adhoc_freq) {
+ fixed_freq = nm_ap_get_freq (ap);
+ if (!fixed_freq) {
if (g_strcmp0 (band, "a") == 0)
- adhoc_freq = wifi_utils_find_freq (priv->wifi_data, a_freqs);
+ fixed_freq = wifi_utils_find_freq (priv->wifi_data, a_freqs);
else
- adhoc_freq = wifi_utils_find_freq (priv->wifi_data, bg_freqs);
+ fixed_freq = wifi_utils_find_freq (priv->wifi_data, bg_freqs);
}
- if (!adhoc_freq) {
+ if (!fixed_freq) {
if (g_strcmp0 (band, "a") == 0)
- adhoc_freq = 5180;
+ fixed_freq = 5180;
else
- adhoc_freq = 2462;
+ fixed_freq = 2462;
}
}
if (!nm_supplicant_config_add_setting_wireless (config,
s_wireless,
nm_ap_get_broadcast (ap),
- adhoc_freq,
+ fixed_freq,
wifi_utils_can_scan_ssid (priv->wifi_data))) {
nm_log_err (LOGD_WIFI, "Couldn't add 802-11-wireless setting to supplicant config.");
goto error;
diff --git a/src/nm-wifi-ap-utils.c b/src/nm-wifi-ap-utils.c
index 215c493..639d233 100644
--- a/src/nm-wifi-ap-utils.c
+++ b/src/nm-wifi-ap-utils.c
@@ -521,6 +521,10 @@ nm_ap_utils_complete_connection (const GByteArray *ap_ssid,
if (ap_mode == NM_802_11_MODE_ADHOC)
valid = TRUE;
adhoc = TRUE;
+ } else if (!strcmp (mode, NM_SETTING_WIRELESS_MODE_AP)) {
+ if (ap_mode == NM_802_11_MODE_AP) {
+ valid = TRUE;
+ }
}
if (valid == FALSE) {
@@ -535,6 +539,8 @@ nm_ap_utils_complete_connection (const GByteArray *ap_ssid,
if (ap_mode == NM_802_11_MODE_ADHOC) {
mode = NM_SETTING_WIRELESS_MODE_ADHOC;
adhoc = TRUE;
+ } else if (ap_mode == NM_802_11_MODE_AP) {
+ mode = NM_SETTING_WIRELESS_MODE_AP;
}
g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_MODE, mode, NULL);
}
diff --git a/src/nm-wifi-ap.c b/src/nm-wifi-ap.c
index 6a60796..0ded56e 100644
--- a/src/nm-wifi-ap.c
+++ b/src/nm-wifi-ap.c
@@ -492,6 +492,8 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
nm_ap_set_mode (ap, NM_802_11_MODE_INFRA);
else if (strcmp (val, "ad-hoc") == 0)
nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC);
+ else if (strcmp (val, "ap") == 0)
+ nm_ap_set_mode (ap, NM_802_11_MODE_AP);
}
} else if (G_VALUE_HOLDS_BOOLEAN (variant)) {
gboolean val = g_value_get_boolean (variant);
@@ -650,6 +652,8 @@ nm_ap_new_fake_from_connection (NMConnection *connection)
nm_ap_set_mode (ap, NM_802_11_MODE_INFRA);
else if (!strcmp (mode, "adhoc"))
nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC);
+ else if (!strcmp (mode, "ap"))
+ nm_ap_set_mode (ap, NM_802_11_MODE_AP);
else
goto error;
} else {
@@ -965,6 +969,7 @@ void nm_ap_set_mode (NMAccessPoint *ap, const NM80211Mode mode)
g_return_if_fail (NM_IS_AP (ap));
g_return_if_fail ( mode == NM_802_11_MODE_ADHOC
+ || mode == NM_802_11_MODE_AP
|| mode == NM_802_11_MODE_INFRA);
priv = NM_AP_GET_PRIVATE (ap);
@@ -1160,6 +1165,8 @@ nm_ap_check_compatible (NMAccessPoint *self,
return FALSE;
if (!strcmp (mode, "adhoc") && (priv->mode != NM_802_11_MODE_ADHOC))
return FALSE;
+ if (!strcmp (mode, "ap") && (priv->mode != NM_802_11_MODE_AP))
+ return FALSE;
}
band = nm_setting_wireless_get_band (s_wireless);
diff --git a/src/supplicant-manager/nm-supplicant-config.c b/src/supplicant-manager/nm-supplicant-config.c
index a8e4ab9..950e4b7 100644
--- a/src/supplicant-manager/nm-supplicant-config.c
+++ b/src/supplicant-manager/nm-supplicant-config.c
@@ -363,11 +363,11 @@ gboolean
nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self,
NMSettingWireless * setting,
gboolean is_broadcast,
- guint32 adhoc_freq,
+ guint32 fixed_freq,
gboolean has_scan_capa_ssid)
{
NMSupplicantConfigPrivate *priv;
- gboolean is_adhoc;
+ gboolean is_adhoc, is_ap;
const char *mode;
const GByteArray *id;
@@ -378,7 +378,8 @@ nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self,
mode = nm_setting_wireless_get_mode (setting);
is_adhoc = (mode && !strcmp (mode, "adhoc")) ? TRUE : FALSE;
- if (is_adhoc)
+ is_ap = (mode && !strcmp (mode, "ap")) ? TRUE : FALSE;
+ if (is_adhoc || is_ap)
priv->ap_scan = 2;
else if (is_broadcast == FALSE) {
/* drivers that support scanning specific SSIDs should use
@@ -395,27 +396,34 @@ nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self,
if (is_adhoc) {
if (!nm_supplicant_config_add_option (self, "mode", "1", -1, FALSE)) {
- nm_log_warn (LOGD_SUPPLICANT, "Error adding mode to supplicant config.");
+ nm_log_warn (LOGD_SUPPLICANT, "Error adding mode=1 (adhoc) to supplicant config.");
return FALSE;
}
+ }
+
+ if (is_ap) {
+ if (!nm_supplicant_config_add_option (self, "mode", "2", -1, FALSE)) {
+ nm_log_warn (LOGD_SUPPLICANT, "Error adding mode=2 (ap) to supplicant config.");
+ return FALSE;
+ }
+ }
- if (adhoc_freq) {
- char *str_freq;
+ if ((is_adhoc || is_ap) && fixed_freq) {
+ char *str_freq;
- str_freq = g_strdup_printf ("%u", adhoc_freq);
- if (!nm_supplicant_config_add_option (self, "frequency", str_freq, -1, FALSE)) {
- g_free (str_freq);
- nm_log_warn (LOGD_SUPPLICANT, "Error adding Ad-Hoc frequency to supplicant config.");
- return FALSE;
- }
+ str_freq = g_strdup_printf ("%u", fixed_freq);
+ if (!nm_supplicant_config_add_option (self, "frequency", str_freq, -1, FALSE)) {
g_free (str_freq);
+ nm_log_warn (LOGD_SUPPLICANT, "Error adding Ad-Hoc/AP frequency to supplicant config.");
+ return FALSE;
}
+ g_free (str_freq);
}
/* Except for Ad-Hoc networks, request that the driver probe for the
* specific SSID we want to associate with.
*/
- if (!is_adhoc) {
+ if (!(is_adhoc || is_ap)) {
if (!nm_supplicant_config_add_option (self, "scan_ssid", "1", -1, FALSE))
return FALSE;
}
diff --git a/src/supplicant-manager/nm-supplicant-settings-verify.c b/src/supplicant-manager/nm-supplicant-settings-verify.c
index 76de84d..143e51a 100644
--- a/src/supplicant-manager/nm-supplicant-settings-verify.c
+++ b/src/supplicant-manager/nm-supplicant-settings-verify.c
@@ -91,7 +91,7 @@ static const struct Opt opt_table[] = {
{ "ssid", TYPE_BYTES, 0, 32,FALSE, NULL },
{ "bssid", TYPE_KEYWORD, 0, 0, FALSE, NULL },
{ "scan_ssid", TYPE_INT, 0, 1, FALSE, NULL },
- { "mode", TYPE_INT, 0, 1, FALSE, NULL },
+ { "mode", TYPE_INT, 0, 2, FALSE, NULL },
{ "frequency", TYPE_INT, 2412, 5825, FALSE, NULL },
{ "auth_alg", TYPE_KEYWORD, 0, 0, FALSE, auth_alg_allowed },
{ "psk", TYPE_BYTES, 0, 0, FALSE, NULL },
diff --git a/src/wifi/wifi-utils-nl80211.c b/src/wifi/wifi-utils-nl80211.c
index 663cbc2..1269268 100644
--- a/src/wifi/wifi-utils-nl80211.c
+++ b/src/wifi/wifi-utils-nl80211.c
@@ -187,6 +187,9 @@ static int nl80211_iface_info_handler (struct nl_msg *msg, void *arg)
case NL80211_IFTYPE_ADHOC:
info->mode = NM_802_11_MODE_ADHOC;
break;
+ case NL80211_IFTYPE_AP:
+ info->mode = NM_802_11_MODE_AP;
+ break;
case NL80211_IFTYPE_STATION:
info->mode = NM_802_11_MODE_INFRA;
break;
diff --git a/src/wifi/wifi-utils-wext.c b/src/wifi/wifi-utils-wext.c
index 75d00f4..37cd94e 100644
--- a/src/wifi/wifi-utils-wext.c
+++ b/src/wifi/wifi-utils-wext.c
@@ -118,6 +118,8 @@ wifi_wext_get_mode (WifiData *data)
switch (wrq.u.mode) {
case IW_MODE_ADHOC:
return NM_802_11_MODE_ADHOC;
+ case IW_MODE_MASTER:
+ return NM_802_11_MODE_AP;
case IW_MODE_INFRA:
return NM_802_11_MODE_INFRA;
default:
@@ -140,6 +142,9 @@ wifi_wext_set_mode (WifiData *data, const NM80211Mode mode)
case NM_802_11_MODE_ADHOC:
wrq.u.mode = IW_MODE_ADHOC;
break;
+ case NM_802_11_MODE_AP:
+ wrq.u.mode = IW_MODE_MASTER;
+ break;
case NM_802_11_MODE_INFRA:
wrq.u.mode = IW_MODE_INFRA;
break;
diff --git a/src/wifi/wifi-utils.c b/src/wifi/wifi-utils.c
index a99a4b7..fc491ec 100644
--- a/src/wifi/wifi-utils.c
+++ b/src/wifi/wifi-utils.c
@@ -96,7 +96,9 @@ gboolean
wifi_utils_set_mode (WifiData *data, const NM80211Mode mode)
{
g_return_val_if_fail (data != NULL, FALSE);
- g_return_val_if_fail ((mode == NM_802_11_MODE_INFRA) || (mode == NM_802_11_MODE_ADHOC), FALSE);
+ g_return_val_if_fail ( (mode == NM_802_11_MODE_INFRA)
+ || (mode == NM_802_11_MODE_AP)
+ || (mode == NM_802_11_MODE_ADHOC), FALSE);
/* nl80211 probably doesn't need this */
return data->set_mode ? data->set_mode (data, mode) : TRUE;
diff --git a/test/nm-tool.c b/test/nm-tool.c
index d8c75ce..eda31e2 100644
--- a/test/nm-tool.c
+++ b/test/nm-tool.c
@@ -161,7 +161,10 @@ detail_access_point (gpointer data, gpointer user_data)
str = g_string_new (NULL);
g_string_append_printf (str,
"%s, %s, Freq %d MHz, Rate %d Mb/s, Strength %d",
- (nm_access_point_get_mode (ap) == NM_802_11_MODE_INFRA) ? "Infra" : "Ad-Hoc",
+ nm_access_point_get_mode (ap) == NM_802_11_MODE_ADHOC ? "Ad-Hoc"
+ : nm_access_point_get_mode (ap) == NM_802_11_MODE_AP ? "AP"
+ : nm_access_point_get_mode (ap) == NM_802_11_MODE_INFRA ? "Infra"
+ : "Unknown",
nm_access_point_get_hw_address (ap),
nm_access_point_get_frequency (ap),
nm_access_point_get_max_bitrate (ap) / 1000,
--
1.7.10
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]