Lines Matching refs: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);
310 struct wpa_ctrl *ctrl;
317 ctrl = os_zalloc(sizeof(*ctrl));
318 if (ctrl == NULL)
322 ctrl->s = socket(PF_INET6, SOCK_DGRAM, 0);
324 ctrl->s = socket(PF_INET, SOCK_DGRAM, 0);
326 if (ctrl->s < 0) {
328 os_free(ctrl);
333 ctrl->local.sin6_family = AF_INET6;
335 ctrl->local.sin6_addr = in6addr_any;
337 inet_pton(AF_INET6, "::1", &ctrl->local.sin6_addr);
340 ctrl->local.sin_family = AF_INET;
342 ctrl->local.sin_addr.s_addr = INADDR_ANY;
344 ctrl->local.sin_addr.s_addr = htonl((127 << 24) | 1);
348 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
349 sizeof(ctrl->local)) < 0) {
350 close(ctrl->s);
351 os_free(ctrl);
356 ctrl->dest.sin6_family = AF_INET6;
357 inet_pton(AF_INET6, "::1", &ctrl->dest.sin6_addr);
358 ctrl->dest.sin6_port = htons(WPA_CTRL_IFACE_PORT);
360 ctrl->dest.sin_family = AF_INET;
361 ctrl->dest.sin_addr.s_addr = htonl((127 << 24) | 1);
362 ctrl->dest.sin_port = htons(WPA_CTRL_IFACE_PORT);
376 close(ctrl->s);
377 os_free(ctrl);
402 ctrl->remote_ip = os_strdup(name);
406 close(ctrl->s);
407 os_free(ctrl->remote_ip);
408 os_free(ctrl);
412 ctrl->dest.sin6_scope_id = scope_id;
413 ctrl->dest.sin6_port = htons(port_id);
414 os_memcpy(&ctrl->dest.sin6_addr, h->h_addr, h->h_length);
416 ctrl->dest.sin_port = htons(port_id);
417 os_memcpy(&ctrl->dest.sin_addr.s_addr, h->h_addr, h->h_length);
420 ctrl->remote_ip = os_strdup("localhost");
423 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
424 sizeof(ctrl->dest)) < 0) {
428 inet_ntop(AF_INET6, &ctrl->dest.sin6_addr, addr,
429 sizeof(ctrl->dest)),
430 ntohs(ctrl->dest.sin6_port),
434 inet_ntoa(ctrl->dest.sin_addr),
435 ntohs(ctrl->dest.sin_port),
438 close(ctrl->s);
439 os_free(ctrl->remote_ip);
440 os_free(ctrl);
445 if (wpa_ctrl_request(ctrl, "GET_COOKIE", 10, buf, &len, NULL) == 0) {
447 ctrl->cookie = os_strdup(buf);
450 if (wpa_ctrl_request(ctrl, "IFNAME", 6, buf, &len, NULL) == 0) {
452 ctrl->remote_ifname = os_strdup(buf);
455 return ctrl;
459 char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl)
464 ctrl->remote_ip, ctrl->remote_ifname);
469 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
471 close(ctrl->s);
472 os_free(ctrl->cookie);
473 os_free(ctrl->remote_ifname);
474 os_free(ctrl->remote_ip);
475 os_free(ctrl);
482 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
495 if (ctrl->cookie) {
497 _cmd_len = os_strlen(ctrl->cookie) + 1 + cmd_len;
503 os_strlcpy(pos, ctrl->cookie, _cmd_len);
504 pos += os_strlen(ctrl->cookie);
518 if (send(ctrl->s, _cmd, _cmd_len, 0) < 0) {
547 FD_SET(ctrl->s, &rfds);
548 res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
553 if (FD_ISSET(ctrl->s, &rfds)) {
554 res = recv(ctrl->s, reply, *reply_len, 0);
584 static int wpa_ctrl_attach_helper(struct wpa_ctrl *ctrl, int attach)
590 ret = wpa_ctrl_request(ctrl, attach ? "ATTACH" : "DETACH", 6,
600 int wpa_ctrl_attach(struct wpa_ctrl *ctrl)
602 return wpa_ctrl_attach_helper(ctrl, 1);
606 int wpa_ctrl_detach(struct wpa_ctrl *ctrl)
608 return wpa_ctrl_attach_helper(ctrl, 0);
614 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
618 res = recv(ctrl->s, reply, *reply_len, 0);
626 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
633 FD_SET(ctrl->s, &rfds);
634 select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
635 return FD_ISSET(ctrl->s, &rfds);
639 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
641 return ctrl->s;
656 struct wpa_ctrl *ctrl;
661 ctrl = os_malloc(sizeof(*ctrl));
662 if (ctrl == NULL)
664 os_memset(ctrl, 0, sizeof(*ctrl));
680 os_free(ctrl);
685 ctrl->pipe = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0,
694 if (ctrl->pipe != INVALID_HANDLE_VALUE ||
699 if (ctrl->pipe == INVALID_HANDLE_VALUE) {
700 os_free(ctrl);
705 if (!SetNamedPipeHandleState(ctrl->pipe, &mode, NULL, NULL)) {
706 CloseHandle(ctrl->pipe);
707 os_free(ctrl);
711 return ctrl;
715 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
717 CloseHandle(ctrl->pipe);
718 os_free(ctrl);
722 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
729 if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL))
732 if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL))
740 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
743 if (!ReadFile(ctrl->pipe, reply, *reply_len, &len, NULL))
750 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
754 if (!PeekNamedPipe(ctrl->pipe, NULL, 0, NULL, &left, NULL))
760 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)