diff mbox

[v3,14/26] hostapd: add INTERFACES ctrl command

Message ID 1455711269-12929-15-git-send-email-janusz.dziedzic@tieto.com
State Changes Requested
Headers show

Commit Message

Janusz.Dziedzic@tieto.com Feb. 17, 2016, 12:14 p.m. UTC
Print available interfaces with ctrl_iface.
This is useful in case we using UDP CTRL and add
interface using ADD command. After that we need to
know which udp port we should use for this new
added interface.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
---
 hostapd/ctrl_iface.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Jouni Malinen Feb. 20, 2016, 3:29 p.m. UTC | #1
On Wed, Feb 17, 2016 at 01:14:17PM +0100, Janusz Dziedzic wrote:
> Print available interfaces with ctrl_iface.
> This is useful in case we using UDP CTRL and add
> interface using ADD command. After that we need to
> know which udp port we should use for this new
> added interface.

> diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
> +hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces *interfaces,

> +	for (i = 0; i < interfaces->count; i++) {
> +		iface = interfaces->iface[i];
> +
> +		res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
> +				  iface->conf->bss[0]->iface,
> +				  iface->conf->bss[0]->ctrl_interface);

This does not look at iface->conf->num_bss at all nor check whether
ctrl_interface is NULL. I'm not sure what this command is supposed to
return in multi-BSS configuration or if control interface is disabled,
but in any case, the current design does not look correct.
Janusz.Dziedzic@tieto.com Feb. 21, 2016, 12:53 p.m. UTC | #2
On 20 February 2016 at 16:29, Jouni Malinen <j@w1.fi> wrote:
> On Wed, Feb 17, 2016 at 01:14:17PM +0100, Janusz Dziedzic wrote:
>> Print available interfaces with ctrl_iface.
>> This is useful in case we using UDP CTRL and add
>> interface using ADD command. After that we need to
>> know which udp port we should use for this new
>> added interface.
>
>> diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
>> +hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces *interfaces,
>
>> +     for (i = 0; i < interfaces->count; i++) {
>> +             iface = interfaces->iface[i];
>> +
>> +             res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
>> +                               iface->conf->bss[0]->iface,
>> +                               iface->conf->bss[0]->ctrl_interface);
>
> This does not look at iface->conf->num_bss at all nor check whether
> ctrl_interface is NULL. I'm not sure what this command is supposed to
> return in multi-BSS configuration or if control interface is disabled,
> but in any case, the current design does not look correct.
>
I added this patch while I need map:
host/interface host/udp_port that will be used in wpaspy.Ctrl()
How multi-BSS is handled currently in hwsim version?
As I understand /some_path/interface_name is used. Do we need
something more here?

BR
Janusz

> --
> Jouni Malinen                                            PGP id EFC895FA
Janusz.Dziedzic@tieto.com Feb. 21, 2016, 5:07 p.m. UTC | #3
On 21 February 2016 at 13:53, Janusz Dziedzic <janusz.dziedzic@tieto.com> wrote:
> On 20 February 2016 at 16:29, Jouni Malinen <j@w1.fi> wrote:
>> On Wed, Feb 17, 2016 at 01:14:17PM +0100, Janusz Dziedzic wrote:
>>> Print available interfaces with ctrl_iface.
>>> This is useful in case we using UDP CTRL and add
>>> interface using ADD command. After that we need to
>>> know which udp port we should use for this new
>>> added interface.
>>
>>> diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
>>> +hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces *interfaces,
>>
>>> +     for (i = 0; i < interfaces->count; i++) {
>>> +             iface = interfaces->iface[i];
>>> +
>>> +             res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
>>> +                               iface->conf->bss[0]->iface,
>>> +                               iface->conf->bss[0]->ctrl_interface);
>>
>> This does not look at iface->conf->num_bss at all nor check whether
>> ctrl_interface is NULL. I'm not sure what this command is supposed to
>> return in multi-BSS configuration or if control interface is disabled,
>> but in any case, the current design does not look correct.
>>
> I added this patch while I need map:
> host/interface host/udp_port that will be used in wpaspy.Ctrl()
> How multi-BSS is handled currently in hwsim version?
> As I understand /some_path/interface_name is used. Do we need
> something more here?
>
I think I can add:
for (j = 0; j < iface->num_bss; j++) {} here.
and don't check ctrl_interface and leave "%s", NULL.
Will be that fine?

BR
Janusz

> BR
> Janusz
>
>> --
>> Jouni Malinen                                            PGP id EFC895FA
diff mbox

Patch

diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 5ba01c3..d24e075 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -2852,6 +2852,33 @@  error_return:
 
 
 static int
+hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces *interfaces,
+				     char *reply, int reply_size)
+{
+	int i, res;
+	char *pos, *end;
+	struct hostapd_iface *iface;
+
+	pos = reply;
+	end = reply + reply_size;
+
+	for (i = 0; i < interfaces->count; i++) {
+		iface = interfaces->iface[i];
+
+		res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
+				  iface->conf->bss[0]->iface,
+				  iface->conf->bss[0]->ctrl_interface);
+		if (os_snprintf_error(end - pos, res)) {
+			*pos = '\0';
+			break;
+		}
+		pos += res;
+	}
+
+	return pos - reply;
+}
+
+static int
 hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces *interfaces,
 				      char *cmd)
 {
@@ -3053,6 +3080,10 @@  static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
 			reply_len = os_snprintf(reply, reply_size, "OK\n");
 		else
 			reply_len = -1;
+	} else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
+		reply_len = hostapd_global_ctrl_iface_interfaces(interfaces,
+								 reply,
+								 sizeof(buffer));
 	} else {
 		wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
 			   "ignored");