Lines Matching full:ctrl

97 	struct wpa_ctrl *ctrl;
107 ctrl = os_zalloc(sizeof(*ctrl));
108 if (ctrl == NULL)
111 ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0);
112 if (ctrl->s < 0) {
113 os_free(ctrl);
117 ctrl->local.sun_family = AF_UNIX;
121 ret = os_snprintf(ctrl->local.sun_path,
122 sizeof(ctrl->local.sun_path),
126 ret = os_snprintf(ctrl->local.sun_path,
127 sizeof(ctrl->local.sun_path),
132 if (os_snprintf_error(sizeof(ctrl->local.sun_path), ret)) {
133 close(ctrl->s);
134 os_free(ctrl);
149 fchmod(ctrl->s, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
151 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
152 sizeof(ctrl->local)) < 0) {
160 unlink(ctrl->local.sun_path);
163 close(ctrl->s);
164 os_free(ctrl);
170 lchown(ctrl->local.sun_path, -1, AID_WIFI);
171 lchown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI);
175 ctrl->s, ctrl_path + 9,
178 close(ctrl->s);
179 unlink(ctrl->local.sun_path);
180 os_free(ctrl);
183 return ctrl;
196 ctrl->s, buf,
199 close(ctrl->s);
200 unlink(ctrl->local.sun_path);
201 os_free(ctrl);
204 return ctrl;
208 ctrl->dest.sun_family = AF_UNIX;
210 ctrl->dest.sun_path[0] = '\0';
211 os_strlcpy(ctrl->dest.sun_path + 1, ctrl_path + 10,
212 sizeof(ctrl->dest.sun_path) - 1);
214 res = os_strlcpy(ctrl->dest.sun_path, ctrl_path,
215 sizeof(ctrl->dest.sun_path));
216 if (res >= sizeof(ctrl->dest.sun_path)) {
217 close(ctrl->s);
218 os_free(ctrl);
222 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
223 sizeof(ctrl->dest)) < 0) {
224 close(ctrl->s);
225 unlink(ctrl->local.sun_path);
226 os_free(ctrl);
234 flags = fcntl(ctrl->s, F_GETFL);
237 if (fcntl(ctrl->s, F_SETFL, flags) < 0) {
238 perror("fcntl(ctrl->s, O_NONBLOCK)");
243 return ctrl;
247 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
249 if (ctrl == NULL)
251 unlink(ctrl->local.sun_path);
252 if (ctrl->s >= 0)
253 close(ctrl->s);
254 os_free(ctrl);
309 struct wpa_ctrl *ctrl;
316 ctrl = os_zalloc(sizeof(*ctrl));
317 if (ctrl == NULL)
321 ctrl->s = socket(PF_INET6, SOCK_DGRAM, 0);
323 ctrl->s = socket(PF_INET, SOCK_DGRAM, 0);
325 if (ctrl->s < 0) {
327 os_free(ctrl);
332 ctrl->local.sin6_family = AF_INET6;
334 ctrl->local.sin6_addr = in6addr_any;
336 inet_pton(AF_INET6, "::1", &ctrl->local.sin6_addr);
339 ctrl->local.sin_family = AF_INET;
341 ctrl->local.sin_addr.s_addr = INADDR_ANY;
343 ctrl->local.sin_addr.s_addr = htonl((127 << 24) | 1);
347 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
348 sizeof(ctrl->local)) < 0) {
349 close(ctrl->s);
350 os_free(ctrl);
355 ctrl->dest.sin6_family = AF_INET6;
356 inet_pton(AF_INET6, "::1", &ctrl->dest.sin6_addr);
357 ctrl->dest.sin6_port = htons(WPA_CTRL_IFACE_PORT);
359 ctrl->dest.sin_family = AF_INET;
360 ctrl->dest.sin_addr.s_addr = htonl((127 << 24) | 1);
361 ctrl->dest.sin_port = htons(WPA_CTRL_IFACE_PORT);
375 close(ctrl->s);
376 os_free(ctrl);
401 ctrl->remote_ip = os_strdup(name);
405 close(ctrl->s);
406 os_free(ctrl->remote_ip);
407 os_free(ctrl);
411 ctrl->dest.sin6_scope_id = scope_id;
412 ctrl->dest.sin6_port = htons(port_id);
413 os_memcpy(&ctrl->dest.sin6_addr, h->h_addr, h->h_length);
415 ctrl->dest.sin_port = htons(port_id);
416 os_memcpy(&ctrl->dest.sin_addr.s_addr, h->h_addr, h->h_length);
419 ctrl->remote_ip = os_strdup("localhost");
422 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
423 sizeof(ctrl->dest)) < 0) {
427 inet_ntop(AF_INET6, &ctrl->dest.sin6_addr, addr,
428 sizeof(ctrl->dest)),
429 ntohs(ctrl->dest.sin6_port),
433 inet_ntoa(ctrl->dest.sin_addr),
434 ntohs(ctrl->dest.sin_port),
437 close(ctrl->s);
438 os_free(ctrl->remote_ip);
439 os_free(ctrl);
444 if (wpa_ctrl_request(ctrl, "GET_COOKIE", 10, buf, &len, NULL) == 0) {
446 ctrl->cookie = os_strdup(buf);
449 if (wpa_ctrl_request(ctrl, "IFNAME", 6, buf, &len, NULL) == 0) {
451 ctrl->remote_ifname = os_strdup(buf);
454 return ctrl;
458 char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl)
463 ctrl->remote_ip, ctrl->remote_ifname);
468 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
470 close(ctrl->s);
471 os_free(ctrl->cookie);
472 os_free(ctrl->remote_ifname);
473 os_free(ctrl->remote_ip);
474 os_free(ctrl);
481 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
494 if (ctrl->cookie) {
496 _cmd_len = os_strlen(ctrl->cookie) + 1 + cmd_len;
502 os_strlcpy(pos, ctrl->cookie, _cmd_len);
503 pos += os_strlen(ctrl->cookie);
517 if (send(ctrl->s, _cmd, _cmd_len, 0) < 0) {
556 FD_SET(ctrl->s, &rfds);
557 res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
562 if (FD_ISSET(ctrl->s, &rfds)) {
563 res = recv(ctrl->s, reply, *reply_len, 0);
593 static int wpa_ctrl_attach_helper(struct wpa_ctrl *ctrl, int attach)
599 ret = wpa_ctrl_request(ctrl, attach ? "ATTACH" : "DETACH", 6,
609 int wpa_ctrl_attach(struct wpa_ctrl *ctrl)
611 return wpa_ctrl_attach_helper(ctrl, 1);
615 int wpa_ctrl_detach(struct wpa_ctrl *ctrl)
617 return wpa_ctrl_attach_helper(ctrl, 0);
623 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
627 res = recv(ctrl->s, reply, *reply_len, 0);
635 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
642 FD_SET(ctrl->s, &rfds);
643 select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
644 return FD_ISSET(ctrl->s, &rfds);
648 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
650 return ctrl->s;
665 struct wpa_ctrl *ctrl;
670 ctrl = os_malloc(sizeof(*ctrl));
671 if (ctrl == NULL)
673 os_memset(ctrl, 0, sizeof(*ctrl));
689 os_free(ctrl);
694 ctrl->pipe = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0,
703 if (ctrl->pipe != INVALID_HANDLE_VALUE ||
708 if (ctrl->pipe == INVALID_HANDLE_VALUE) {
709 os_free(ctrl);
714 if (!SetNamedPipeHandleState(ctrl->pipe, &mode, NULL, NULL)) {
715 CloseHandle(ctrl->pipe);
716 os_free(ctrl);
720 return ctrl;
724 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
726 CloseHandle(ctrl->pipe);
727 os_free(ctrl);
731 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
738 if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL))
741 if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL))
749 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
752 if (!ReadFile(ctrl->pipe, reply, *reply_len, &len, NULL))
759 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
763 if (!PeekNamedPipe(ctrl->pipe, NULL, 0, NULL, &left, NULL))
769 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)