Lines Matching refs:ctrl
87 struct wpa_ctrl *ctrl; in wpa_ctrl_open() local
97 ctrl = os_malloc(sizeof(*ctrl)); in wpa_ctrl_open()
98 if (ctrl == NULL) in wpa_ctrl_open()
100 os_memset(ctrl, 0, sizeof(*ctrl)); in wpa_ctrl_open()
102 ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0); in wpa_ctrl_open()
103 if (ctrl->s < 0) { in wpa_ctrl_open()
104 os_free(ctrl); in wpa_ctrl_open()
108 ctrl->local.sun_family = AF_UNIX; in wpa_ctrl_open()
111 ret = os_snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path), in wpa_ctrl_open()
115 if (ret < 0 || (size_t) ret >= sizeof(ctrl->local.sun_path)) { in wpa_ctrl_open()
116 close(ctrl->s); in wpa_ctrl_open()
117 os_free(ctrl); in wpa_ctrl_open()
121 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local, in wpa_ctrl_open()
122 sizeof(ctrl->local)) < 0) { in wpa_ctrl_open()
130 unlink(ctrl->local.sun_path); in wpa_ctrl_open()
133 close(ctrl->s); in wpa_ctrl_open()
134 os_free(ctrl); in wpa_ctrl_open()
139 chmod(ctrl->local.sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); in wpa_ctrl_open()
140 chown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI); in wpa_ctrl_open()
144 ctrl->s, ctrl_path + 9, in wpa_ctrl_open()
147 close(ctrl->s); in wpa_ctrl_open()
148 unlink(ctrl->local.sun_path); in wpa_ctrl_open()
149 os_free(ctrl); in wpa_ctrl_open()
152 return ctrl; in wpa_ctrl_open()
165 ctrl->s, buf, in wpa_ctrl_open()
168 close(ctrl->s); in wpa_ctrl_open()
169 unlink(ctrl->local.sun_path); in wpa_ctrl_open()
170 os_free(ctrl); in wpa_ctrl_open()
173 return ctrl; in wpa_ctrl_open()
177 ctrl->dest.sun_family = AF_UNIX; in wpa_ctrl_open()
179 ctrl->dest.sun_path[0] = '\0'; in wpa_ctrl_open()
180 os_strlcpy(ctrl->dest.sun_path + 1, ctrl_path + 10, in wpa_ctrl_open()
181 sizeof(ctrl->dest.sun_path) - 1); in wpa_ctrl_open()
183 res = os_strlcpy(ctrl->dest.sun_path, ctrl_path, in wpa_ctrl_open()
184 sizeof(ctrl->dest.sun_path)); in wpa_ctrl_open()
185 if (res >= sizeof(ctrl->dest.sun_path)) { in wpa_ctrl_open()
186 close(ctrl->s); in wpa_ctrl_open()
187 os_free(ctrl); in wpa_ctrl_open()
191 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest, in wpa_ctrl_open()
192 sizeof(ctrl->dest)) < 0) { in wpa_ctrl_open()
193 close(ctrl->s); in wpa_ctrl_open()
194 unlink(ctrl->local.sun_path); in wpa_ctrl_open()
195 os_free(ctrl); in wpa_ctrl_open()
203 flags = fcntl(ctrl->s, F_GETFL); in wpa_ctrl_open()
206 if (fcntl(ctrl->s, F_SETFL, flags) < 0) { in wpa_ctrl_open()
212 return ctrl; in wpa_ctrl_open()
216 void wpa_ctrl_close(struct wpa_ctrl *ctrl) in wpa_ctrl_close() argument
218 if (ctrl == NULL) in wpa_ctrl_close()
220 unlink(ctrl->local.sun_path); in wpa_ctrl_close()
221 if (ctrl->s >= 0) in wpa_ctrl_close()
222 close(ctrl->s); in wpa_ctrl_close()
223 os_free(ctrl); in wpa_ctrl_close()
279 struct wpa_ctrl *ctrl; in wpa_ctrl_open() local
286 ctrl = os_malloc(sizeof(*ctrl)); in wpa_ctrl_open()
287 if (ctrl == NULL) in wpa_ctrl_open()
289 os_memset(ctrl, 0, sizeof(*ctrl)); in wpa_ctrl_open()
292 ctrl->s = socket(PF_INET6, SOCK_DGRAM, 0); in wpa_ctrl_open()
294 ctrl->s = socket(PF_INET, SOCK_DGRAM, 0); in wpa_ctrl_open()
296 if (ctrl->s < 0) { in wpa_ctrl_open()
298 os_free(ctrl); in wpa_ctrl_open()
303 ctrl->local.sin6_family = AF_INET6; in wpa_ctrl_open()
305 ctrl->local.sin6_addr = in6addr_any; in wpa_ctrl_open()
307 inet_pton(AF_INET6, "::1", &ctrl->local.sin6_addr); in wpa_ctrl_open()
310 ctrl->local.sin_family = AF_INET; in wpa_ctrl_open()
312 ctrl->local.sin_addr.s_addr = INADDR_ANY; in wpa_ctrl_open()
314 ctrl->local.sin_addr.s_addr = htonl((127 << 24) | 1); in wpa_ctrl_open()
318 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local, in wpa_ctrl_open()
319 sizeof(ctrl->local)) < 0) { in wpa_ctrl_open()
320 close(ctrl->s); in wpa_ctrl_open()
321 os_free(ctrl); in wpa_ctrl_open()
326 ctrl->dest.sin6_family = AF_INET6; in wpa_ctrl_open()
327 inet_pton(AF_INET6, "::1", &ctrl->dest.sin6_addr); in wpa_ctrl_open()
328 ctrl->dest.sin6_port = htons(WPA_CTRL_IFACE_PORT); in wpa_ctrl_open()
330 ctrl->dest.sin_family = AF_INET; in wpa_ctrl_open()
331 ctrl->dest.sin_addr.s_addr = htonl((127 << 24) | 1); in wpa_ctrl_open()
332 ctrl->dest.sin_port = htons(WPA_CTRL_IFACE_PORT); in wpa_ctrl_open()
346 close(ctrl->s); in wpa_ctrl_open()
347 os_free(ctrl); in wpa_ctrl_open()
372 ctrl->remote_ip = os_strdup(name); in wpa_ctrl_open()
376 close(ctrl->s); in wpa_ctrl_open()
377 os_free(ctrl->remote_ip); in wpa_ctrl_open()
378 os_free(ctrl); in wpa_ctrl_open()
382 ctrl->dest.sin6_scope_id = scope_id; in wpa_ctrl_open()
383 ctrl->dest.sin6_port = htons(port_id); in wpa_ctrl_open()
384 os_memcpy(&ctrl->dest.sin6_addr, h->h_addr, h->h_length); in wpa_ctrl_open()
386 ctrl->dest.sin_port = htons(port_id); in wpa_ctrl_open()
387 os_memcpy(&ctrl->dest.sin_addr.s_addr, h->h_addr, h->h_length); in wpa_ctrl_open()
390 ctrl->remote_ip = os_strdup("localhost"); in wpa_ctrl_open()
393 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest, in wpa_ctrl_open()
394 sizeof(ctrl->dest)) < 0) { in wpa_ctrl_open()
398 inet_ntop(AF_INET6, &ctrl->dest.sin6_addr, addr, in wpa_ctrl_open()
399 sizeof(ctrl->dest)), in wpa_ctrl_open()
400 ntohs(ctrl->dest.sin6_port), in wpa_ctrl_open()
404 inet_ntoa(ctrl->dest.sin_addr), in wpa_ctrl_open()
405 ntohs(ctrl->dest.sin_port), in wpa_ctrl_open()
408 close(ctrl->s); in wpa_ctrl_open()
409 os_free(ctrl->remote_ip); in wpa_ctrl_open()
410 os_free(ctrl); in wpa_ctrl_open()
415 if (wpa_ctrl_request(ctrl, "GET_COOKIE", 10, buf, &len, NULL) == 0) { in wpa_ctrl_open()
417 ctrl->cookie = os_strdup(buf); in wpa_ctrl_open()
420 if (wpa_ctrl_request(ctrl, "IFNAME", 6, buf, &len, NULL) == 0) { in wpa_ctrl_open()
422 ctrl->remote_ifname = os_strdup(buf); in wpa_ctrl_open()
425 return ctrl; in wpa_ctrl_open()
429 char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl) in wpa_ctrl_get_remote_ifname() argument
434 ctrl->remote_ip, ctrl->remote_ifname); in wpa_ctrl_get_remote_ifname()
439 void wpa_ctrl_close(struct wpa_ctrl *ctrl) in wpa_ctrl_close() argument
441 close(ctrl->s); in wpa_ctrl_close()
442 os_free(ctrl->cookie); in wpa_ctrl_close()
443 os_free(ctrl->remote_ifname); in wpa_ctrl_close()
444 os_free(ctrl->remote_ip); in wpa_ctrl_close()
445 os_free(ctrl); in wpa_ctrl_close()
452 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len, in wpa_ctrl_request() argument
465 if (ctrl->cookie) { in wpa_ctrl_request()
467 _cmd_len = os_strlen(ctrl->cookie) + 1 + cmd_len; in wpa_ctrl_request()
473 os_strlcpy(pos, ctrl->cookie, _cmd_len); in wpa_ctrl_request()
474 pos += os_strlen(ctrl->cookie); in wpa_ctrl_request()
488 if (send(ctrl->s, _cmd, _cmd_len, 0) < 0) { in wpa_ctrl_request()
517 FD_SET(ctrl->s, &rfds); in wpa_ctrl_request()
518 res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv); in wpa_ctrl_request()
521 if (FD_ISSET(ctrl->s, &rfds)) { in wpa_ctrl_request()
522 res = recv(ctrl->s, reply, *reply_len, 0); in wpa_ctrl_request()
551 static int wpa_ctrl_attach_helper(struct wpa_ctrl *ctrl, int attach) in wpa_ctrl_attach_helper() argument
557 ret = wpa_ctrl_request(ctrl, attach ? "ATTACH" : "DETACH", 6, in wpa_ctrl_attach_helper()
567 int wpa_ctrl_attach(struct wpa_ctrl *ctrl) in wpa_ctrl_attach() argument
569 return wpa_ctrl_attach_helper(ctrl, 1); in wpa_ctrl_attach()
573 int wpa_ctrl_detach(struct wpa_ctrl *ctrl) in wpa_ctrl_detach() argument
575 return wpa_ctrl_attach_helper(ctrl, 0); in wpa_ctrl_detach()
581 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len) in wpa_ctrl_recv() argument
585 res = recv(ctrl->s, reply, *reply_len, 0); in wpa_ctrl_recv()
593 int wpa_ctrl_pending(struct wpa_ctrl *ctrl) in wpa_ctrl_pending() argument
600 FD_SET(ctrl->s, &rfds); in wpa_ctrl_pending()
601 select(ctrl->s + 1, &rfds, NULL, NULL, &tv); in wpa_ctrl_pending()
602 return FD_ISSET(ctrl->s, &rfds); in wpa_ctrl_pending()
606 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl) in wpa_ctrl_get_fd() argument
608 return ctrl->s; in wpa_ctrl_get_fd()
623 struct wpa_ctrl *ctrl; in wpa_ctrl_open() local
628 ctrl = os_malloc(sizeof(*ctrl)); in wpa_ctrl_open()
629 if (ctrl == NULL) in wpa_ctrl_open()
631 os_memset(ctrl, 0, sizeof(*ctrl)); in wpa_ctrl_open()
647 os_free(ctrl); in wpa_ctrl_open()
652 ctrl->pipe = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0, in wpa_ctrl_open()
661 if (ctrl->pipe != INVALID_HANDLE_VALUE || in wpa_ctrl_open()
666 if (ctrl->pipe == INVALID_HANDLE_VALUE) { in wpa_ctrl_open()
667 os_free(ctrl); in wpa_ctrl_open()
672 if (!SetNamedPipeHandleState(ctrl->pipe, &mode, NULL, NULL)) { in wpa_ctrl_open()
673 CloseHandle(ctrl->pipe); in wpa_ctrl_open()
674 os_free(ctrl); in wpa_ctrl_open()
678 return ctrl; in wpa_ctrl_open()
682 void wpa_ctrl_close(struct wpa_ctrl *ctrl) in wpa_ctrl_close() argument
684 CloseHandle(ctrl->pipe); in wpa_ctrl_close()
685 os_free(ctrl); in wpa_ctrl_close()
689 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len, in wpa_ctrl_request() argument
696 if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL)) in wpa_ctrl_request()
699 if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL)) in wpa_ctrl_request()
707 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len) in wpa_ctrl_recv() argument
710 if (!ReadFile(ctrl->pipe, reply, *reply_len, &len, NULL)) in wpa_ctrl_recv()
717 int wpa_ctrl_pending(struct wpa_ctrl *ctrl) in wpa_ctrl_pending() argument
721 if (!PeekNamedPipe(ctrl->pipe, NULL, 0, NULL, &left, NULL)) in wpa_ctrl_pending()
727 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl) in wpa_ctrl_get_fd() argument