2 * WPA Supplicant / UDP socket -based control interface
3 * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
14 #include "eapol_supp/eapol_supp_sm.h"
15 #include "wpa_supplicant_i.h"
16 #include "ctrl_iface.h"
17 #include "common/wpa_ctrl.h"
22 /* Per-interface ctrl_iface */
25 * struct wpa_ctrl_dst - Internal data structure of control interface monitors
27 * This structure is used to store information about registered control
28 * interface monitors into struct wpa_supplicant. This data is private to
29 * ctrl_iface_udp.c and should not be touched directly from other files.
32 struct wpa_ctrl_dst
*next
;
33 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
34 struct sockaddr_in6 addr
;
35 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
36 struct sockaddr_in addr
;
37 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
44 struct ctrl_iface_priv
{
45 struct wpa_supplicant
*wpa_s
;
47 struct wpa_ctrl_dst
*ctrl_dst
;
48 u8 cookie
[COOKIE_LEN
];
51 struct ctrl_iface_global_priv
{
53 struct wpa_ctrl_dst
*ctrl_dst
;
54 u8 cookie
[COOKIE_LEN
];
58 static void wpa_supplicant_ctrl_iface_send(struct wpa_supplicant
*wpa_s
,
59 const char *ifname
, int sock
,
60 struct wpa_ctrl_dst
**head
,
61 int level
, const char *buf
,
65 static void wpas_ctrl_iface_free_dst(struct wpa_ctrl_dst
*dst
)
67 struct wpa_ctrl_dst
*prev
;
77 static int wpa_supplicant_ctrl_iface_attach(struct wpa_ctrl_dst
**head
,
78 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
79 struct sockaddr_in6
*from
,
80 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
81 struct sockaddr_in
*from
,
82 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
85 struct wpa_ctrl_dst
*dst
;
86 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
87 char addr
[INET6_ADDRSTRLEN
];
88 #endif /* CONFIG_UDP_IPV6 */
90 dst
= os_zalloc(sizeof(*dst
));
93 os_memcpy(&dst
->addr
, from
, sizeof(*from
));
94 dst
->addrlen
= fromlen
;
95 dst
->debug_level
= MSG_INFO
;
98 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
99 wpa_printf(MSG_DEBUG
, "CTRL_IFACE monitor attached %s:%d",
100 inet_ntop(AF_INET6
, &from
->sin6_addr
, addr
, sizeof(*from
)),
101 ntohs(from
->sin6_port
));
102 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
103 wpa_printf(MSG_DEBUG
, "CTRL_IFACE monitor attached %s:%d",
104 inet_ntoa(from
->sin_addr
), ntohs(from
->sin_port
));
105 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
110 static int wpa_supplicant_ctrl_iface_detach(struct wpa_ctrl_dst
**head
,
111 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
112 struct sockaddr_in6
*from
,
113 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
114 struct sockaddr_in
*from
,
115 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
118 struct wpa_ctrl_dst
*dst
, *prev
= NULL
;
119 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
120 char addr
[INET6_ADDRSTRLEN
];
121 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
125 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
126 if (from
->sin6_port
== dst
->addr
.sin6_port
&&
127 !os_memcmp(&from
->sin6_addr
, &dst
->addr
.sin6_addr
,
128 sizeof(from
->sin6_addr
))) {
129 wpa_printf(MSG_DEBUG
, "CTRL_IFACE monitor detached %s:%d",
130 inet_ntop(AF_INET6
, &from
->sin6_addr
, addr
,
132 ntohs(from
->sin6_port
));
133 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
134 if (from
->sin_addr
.s_addr
== dst
->addr
.sin_addr
.s_addr
&&
135 from
->sin_port
== dst
->addr
.sin_port
) {
136 wpa_printf(MSG_DEBUG
, "CTRL_IFACE monitor detached "
137 "%s:%d", inet_ntoa(from
->sin_addr
),
138 ntohs(from
->sin_port
));
139 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
143 prev
->next
= dst
->next
;
154 static int wpa_supplicant_ctrl_iface_level(struct ctrl_iface_priv
*priv
,
155 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
156 struct sockaddr_in6
*from
,
157 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
158 struct sockaddr_in
*from
,
159 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
163 struct wpa_ctrl_dst
*dst
;
164 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
165 char addr
[INET6_ADDRSTRLEN
];
166 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
168 wpa_printf(MSG_DEBUG
, "CTRL_IFACE LEVEL %s", level
);
170 dst
= priv
->ctrl_dst
;
172 #if CONFIG_CTRL_IFACE_UDP_IPV6
173 if (from
->sin6_port
== dst
->addr
.sin6_port
&&
174 !os_memcmp(&from
->sin6_addr
, &dst
->addr
.sin6_addr
,
175 sizeof(from
->sin6_addr
))) {
176 wpa_printf(MSG_DEBUG
, "CTRL_IFACE changed monitor level %s:%d",
177 inet_ntop(AF_INET6
, &from
->sin6_addr
, addr
,
179 ntohs(from
->sin6_port
));
180 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
181 if (from
->sin_addr
.s_addr
== dst
->addr
.sin_addr
.s_addr
&&
182 from
->sin_port
== dst
->addr
.sin_port
) {
183 wpa_printf(MSG_DEBUG
, "CTRL_IFACE changed monitor "
184 "level %s:%d", inet_ntoa(from
->sin_addr
),
185 ntohs(from
->sin_port
));
186 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
187 dst
->debug_level
= atoi(level
);
198 wpa_supplicant_ctrl_iface_get_cookie(struct ctrl_iface_priv
*priv
,
202 reply
= os_malloc(7 + 2 * COOKIE_LEN
+ 1);
208 os_memcpy(reply
, "COOKIE=", 7);
209 wpa_snprintf_hex(reply
+ 7, 2 * COOKIE_LEN
+ 1,
210 priv
->cookie
, COOKIE_LEN
);
212 *reply_len
= 7 + 2 * COOKIE_LEN
;
217 static void wpa_supplicant_ctrl_iface_receive(int sock
, void *eloop_ctx
,
220 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
221 struct ctrl_iface_priv
*priv
= sock_ctx
;
222 char buf
[4096], *pos
;
224 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
225 struct sockaddr_in6 from
;
226 #ifndef CONFIG_CTRL_IFACE_UDP_REMOTE
227 char addr
[INET6_ADDRSTRLEN
];
228 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
229 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
230 struct sockaddr_in from
;
231 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
232 socklen_t fromlen
= sizeof(from
);
234 size_t reply_len
= 0;
235 int new_attached
= 0;
236 u8 cookie
[COOKIE_LEN
];
238 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
239 (struct sockaddr
*) &from
, &fromlen
);
241 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
246 #ifndef CONFIG_CTRL_IFACE_UDP_REMOTE
247 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
248 inet_ntop(AF_INET6
, &from
.sin6_addr
, addr
, sizeof(from
));
249 if (os_strcmp(addr
, "::1")) {
250 wpa_printf(MSG_DEBUG
, "CTRL: Drop packet from unexpected source %s",
253 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
254 if (from
.sin_addr
.s_addr
!= htonl((127 << 24) | 1)) {
256 * The OS networking stack is expected to drop this kind of
257 * frames since the socket is bound to only localhost address.
258 * Just in case, drop the frame if it is coming from any other
261 wpa_printf(MSG_DEBUG
, "CTRL: Drop packet from unexpected "
262 "source %s", inet_ntoa(from
.sin_addr
));
265 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
266 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
270 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
271 reply
= wpa_supplicant_ctrl_iface_get_cookie(priv
, &reply_len
);
276 * Require that the client includes a prefix with the 'cookie' value
277 * fetched with GET_COOKIE command. This is used to verify that the
278 * client has access to a bidirectional link over UDP in order to
279 * avoid attacks using forged localhost IP address even if the OS does
280 * not block such frames from remote destinations.
282 if (os_strncmp(buf
, "COOKIE=", 7) != 0) {
283 wpa_printf(MSG_DEBUG
, "CTLR: No cookie in the request - "
288 if (hexstr2bin(buf
+ 7, cookie
, COOKIE_LEN
) < 0) {
289 wpa_printf(MSG_DEBUG
, "CTLR: Invalid cookie format in the "
290 "request - drop request");
294 if (os_memcmp(cookie
, priv
->cookie
, COOKIE_LEN
) != 0) {
295 wpa_printf(MSG_DEBUG
, "CTLR: Invalid cookie in the request - "
300 pos
= buf
+ 7 + 2 * COOKIE_LEN
;
304 if (os_strcmp(pos
, "ATTACH") == 0) {
305 if (wpa_supplicant_ctrl_iface_attach(&priv
->ctrl_dst
,
312 } else if (os_strcmp(pos
, "DETACH") == 0) {
313 if (wpa_supplicant_ctrl_iface_detach(&priv
->ctrl_dst
,
318 } else if (os_strncmp(pos
, "LEVEL ", 6) == 0) {
319 if (wpa_supplicant_ctrl_iface_level(priv
, &from
, fromlen
,
325 reply
= wpa_supplicant_ctrl_iface_process(wpa_s
, pos
,
331 sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
334 } else if (reply_len
== 1) {
335 sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
337 } else if (reply_len
== 2) {
338 sendto(sock
, "OK\n", 3, 0, (struct sockaddr
*) &from
,
343 eapol_sm_notify_ctrl_attached(wpa_s
->eapol
);
347 static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx
, int level
,
348 enum wpa_msg_type type
,
349 const char *txt
, size_t len
)
351 struct wpa_supplicant
*wpa_s
= ctx
;
356 if (type
!= WPA_MSG_NO_GLOBAL
&& wpa_s
->global
->ctrl_iface
) {
357 struct ctrl_iface_global_priv
*priv
= wpa_s
->global
->ctrl_iface
;
359 if (priv
->ctrl_dst
) {
360 wpa_supplicant_ctrl_iface_send(
362 type
!= WPA_MSG_PER_INTERFACE
?
363 NULL
: wpa_s
->ifname
,
364 priv
->sock
, &priv
->ctrl_dst
, level
, txt
, len
);
368 if (type
== WPA_MSG_ONLY_GLOBAL
|| !wpa_s
->ctrl_iface
)
371 wpa_supplicant_ctrl_iface_send(wpa_s
, NULL
, wpa_s
->ctrl_iface
->sock
,
372 &wpa_s
->ctrl_iface
->ctrl_dst
,
377 struct ctrl_iface_priv
*
378 wpa_supplicant_ctrl_iface_init(struct wpa_supplicant
*wpa_s
)
380 struct ctrl_iface_priv
*priv
;
382 int port
= WPA_CTRL_IFACE_PORT
;
384 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
385 struct sockaddr_in6 addr
;
386 int domain
= PF_INET6
;
387 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
388 struct sockaddr_in addr
;
389 int domain
= PF_INET
;
390 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
392 priv
= os_zalloc(sizeof(*priv
));
397 os_get_random(priv
->cookie
, COOKIE_LEN
);
399 if (wpa_s
->conf
->ctrl_interface
== NULL
)
402 pos
= os_strstr(wpa_s
->conf
->ctrl_interface
, "udp:");
407 wpa_printf(MSG_ERROR
, "Invalid ctrl_iface UDP port: %s",
408 wpa_s
->conf
->ctrl_interface
);
413 priv
->sock
= socket(domain
, SOCK_DGRAM
, 0);
414 if (priv
->sock
< 0) {
415 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
419 os_memset(&addr
, 0, sizeof(addr
));
420 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
421 addr
.sin6_family
= AF_INET6
;
422 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
423 addr
.sin6_addr
= in6addr_any
;
424 #else /* CONFIG_CTRL_IFACE_UDP_REMOTE */
425 inet_pton(AF_INET6
, "::1", &addr
.sin6_addr
);
426 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
427 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
428 addr
.sin_family
= AF_INET
;
429 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
430 addr
.sin_addr
.s_addr
= INADDR_ANY
;
431 #else /* CONFIG_CTRL_IFACE_UDP_REMOTE */
432 addr
.sin_addr
.s_addr
= htonl((127 << 24) | 1);
433 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
434 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
436 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
437 addr
.sin6_port
= htons(port
);
438 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
439 addr
.sin_port
= htons(port
);
440 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
441 if (bind(priv
->sock
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
443 if ((WPA_CTRL_IFACE_PORT
- port
) < WPA_CTRL_IFACE_PORT_LIMIT
)
445 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
449 /* Update the ctrl_interface value to match the selected port */
450 os_snprintf(port_str
, sizeof(port_str
), "udp:%d", port
);
451 os_free(wpa_s
->conf
->ctrl_interface
);
452 wpa_s
->conf
->ctrl_interface
= os_strdup(port_str
);
453 if (!wpa_s
->conf
->ctrl_interface
) {
454 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to malloc ctrl_interface");
458 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
459 wpa_msg(wpa_s
, MSG_DEBUG
, "ctrl_iface_init UDP port: %d", port
);
460 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
462 eloop_register_read_sock(priv
->sock
, wpa_supplicant_ctrl_iface_receive
,
464 wpa_msg_register_cb(wpa_supplicant_ctrl_iface_msg_cb
);
476 void wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv
*priv
)
478 if (priv
->sock
> -1) {
479 eloop_unregister_read_sock(priv
->sock
);
480 if (priv
->ctrl_dst
) {
482 * Wait before closing the control socket if
483 * there are any attached monitors in order to allow
484 * them to receive any pending messages.
486 wpa_printf(MSG_DEBUG
, "CTRL_IFACE wait for attached "
487 "monitors to receive messages");
494 wpas_ctrl_iface_free_dst(priv
->ctrl_dst
);
499 static void wpa_supplicant_ctrl_iface_send(struct wpa_supplicant
*wpa_s
,
500 const char *ifname
, int sock
,
501 struct wpa_ctrl_dst
**head
,
502 int level
, const char *buf
,
505 struct wpa_ctrl_dst
*dst
, *next
;
510 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
511 char addr
[INET6_ADDRSTRLEN
];
512 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
515 if (sock
< 0 || dst
== NULL
)
519 os_snprintf(levelstr
, sizeof(levelstr
), "IFNAME=%s <%d>",
522 os_snprintf(levelstr
, sizeof(levelstr
), "<%d>", level
);
524 llen
= os_strlen(levelstr
);
525 sbuf
= os_malloc(llen
+ len
);
529 os_memcpy(sbuf
, levelstr
, llen
);
530 os_memcpy(sbuf
+ llen
, buf
, len
);
535 if (level
>= dst
->debug_level
) {
536 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
537 wpa_printf(MSG_DEBUG
, "CTRL_IFACE monitor send %s:%d",
538 inet_ntop(AF_INET6
, &dst
->addr
.sin6_addr
,
539 addr
, sizeof(dst
->addr
)),
540 ntohs(dst
->addr
.sin6_port
));
541 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
542 wpa_printf(MSG_DEBUG
, "CTRL_IFACE monitor send %s:%d",
543 inet_ntoa(dst
->addr
.sin_addr
),
544 ntohs(dst
->addr
.sin_port
));
545 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
546 if (sendto(sock
, sbuf
, llen
+ len
, 0,
547 (struct sockaddr
*) &dst
->addr
,
548 sizeof(dst
->addr
)) < 0) {
549 wpa_printf(MSG_ERROR
,
550 "sendto(CTRL_IFACE monitor): %s",
553 if (dst
->errors
> 10) {
554 wpa_supplicant_ctrl_iface_detach(
568 void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv
*priv
)
570 wpa_printf(MSG_DEBUG
, "CTRL_IFACE - %s - wait for monitor",
571 priv
->wpa_s
->ifname
);
572 eloop_wait_for_read_sock(priv
->sock
);
576 /* Global ctrl_iface */
579 wpa_supplicant_global_get_cookie(struct ctrl_iface_global_priv
*priv
,
583 reply
= os_malloc(7 + 2 * COOKIE_LEN
+ 1);
589 os_memcpy(reply
, "COOKIE=", 7);
590 wpa_snprintf_hex(reply
+ 7, 2 * COOKIE_LEN
+ 1,
591 priv
->cookie
, COOKIE_LEN
);
593 *reply_len
= 7 + 2 * COOKIE_LEN
;
598 static void wpa_supplicant_global_ctrl_iface_receive(int sock
, void *eloop_ctx
,
601 struct wpa_global
*global
= eloop_ctx
;
602 struct ctrl_iface_global_priv
*priv
= sock_ctx
;
603 char buf
[4096], *pos
;
605 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
606 struct sockaddr_in6 from
;
607 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
608 struct sockaddr_in from
;
609 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
610 socklen_t fromlen
= sizeof(from
);
613 u8 cookie
[COOKIE_LEN
];
615 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
616 (struct sockaddr
*) &from
, &fromlen
);
618 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
623 #ifndef CONFIG_CTRL_IFACE_UDP_REMOTE
624 #ifndef CONFIG_CTRL_IFACE_UDP_IPV6
625 if (from
.sin_addr
.s_addr
!= htonl((127 << 24) | 1)) {
627 * The OS networking stack is expected to drop this kind of
628 * frames since the socket is bound to only localhost address.
629 * Just in case, drop the frame if it is coming from any other
632 wpa_printf(MSG_DEBUG
, "CTRL: Drop packet from unexpected "
633 "source %s", inet_ntoa(from
.sin_addr
));
636 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
637 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
641 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
642 reply
= wpa_supplicant_global_get_cookie(priv
, &reply_len
);
646 if (os_strncmp(buf
, "COOKIE=", 7) != 0) {
647 wpa_printf(MSG_DEBUG
, "CTLR: No cookie in the request - "
652 if (hexstr2bin(buf
+ 7, cookie
, COOKIE_LEN
) < 0) {
653 wpa_printf(MSG_DEBUG
, "CTLR: Invalid cookie format in the "
654 "request - drop request");
658 if (os_memcmp(cookie
, priv
->cookie
, COOKIE_LEN
) != 0) {
659 wpa_printf(MSG_DEBUG
, "CTLR: Invalid cookie in the request - "
664 pos
= buf
+ 7 + 2 * COOKIE_LEN
;
668 if (os_strcmp(pos
, "ATTACH") == 0) {
669 if (wpa_supplicant_ctrl_iface_attach(&priv
->ctrl_dst
,
674 } else if (os_strcmp(pos
, "DETACH") == 0) {
675 if (wpa_supplicant_ctrl_iface_detach(&priv
->ctrl_dst
,
681 reply
= wpa_supplicant_global_ctrl_iface_process(global
, pos
,
687 sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
690 } else if (reply_len
== 1) {
691 sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
693 } else if (reply_len
== 2) {
694 sendto(sock
, "OK\n", 3, 0, (struct sockaddr
*) &from
,
700 struct ctrl_iface_global_priv
*
701 wpa_supplicant_global_ctrl_iface_init(struct wpa_global
*global
)
703 struct ctrl_iface_global_priv
*priv
;
704 struct sockaddr_in addr
;
706 int port
= WPA_GLOBAL_CTRL_IFACE_PORT
;
708 priv
= os_zalloc(sizeof(*priv
));
712 os_get_random(priv
->cookie
, COOKIE_LEN
);
714 if (global
->params
.ctrl_interface
== NULL
)
717 wpa_printf(MSG_DEBUG
, "Global control interface '%s'",
718 global
->params
.ctrl_interface
);
720 pos
= os_strstr(global
->params
.ctrl_interface
, "udp:");
725 wpa_printf(MSG_ERROR
, "Invalid global ctrl UDP port %s",
726 global
->params
.ctrl_interface
);
731 priv
->sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
732 if (priv
->sock
< 0) {
733 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
737 os_memset(&addr
, 0, sizeof(addr
));
738 addr
.sin_family
= AF_INET
;
739 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
740 addr
.sin_addr
.s_addr
= INADDR_ANY
;
741 #else /* CONFIG_CTRL_IFACE_UDP_REMOTE */
742 addr
.sin_addr
.s_addr
= htonl((127 << 24) | 1);
743 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
745 addr
.sin_port
= htons(port
);
746 if (bind(priv
->sock
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
748 if ((port
- WPA_GLOBAL_CTRL_IFACE_PORT
) <
749 WPA_GLOBAL_CTRL_IFACE_PORT_LIMIT
&& !pos
)
751 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
755 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
756 wpa_printf(MSG_DEBUG
, "global_ctrl_iface_init UDP port: %d", port
);
757 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
759 eloop_register_read_sock(priv
->sock
,
760 wpa_supplicant_global_ctrl_iface_receive
,
762 wpa_msg_register_cb(wpa_supplicant_ctrl_iface_msg_cb
);
775 wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv
*priv
)
777 if (priv
->sock
>= 0) {
778 eloop_unregister_read_sock(priv
->sock
);
782 wpas_ctrl_iface_free_dst(priv
->ctrl_dst
);