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