Home | History | Annotate | Download | only in common

Lines Matching defs:ctrl

95 	struct wpa_ctrl *ctrl;
105 ctrl = os_zalloc(sizeof(*ctrl));
106 if (ctrl == NULL)
109 ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0);
110 if (ctrl->s < 0) {
111 os_free(ctrl);
115 ctrl->local.sun_family = AF_UNIX;
119 ret = os_snprintf(ctrl->local.sun_path,
120 sizeof(ctrl->local.sun_path),
124 ret = os_snprintf(ctrl->local.sun_path,
125 sizeof(ctrl->local.sun_path),
130 if (os_snprintf_error(sizeof(ctrl->local.sun_path), ret)) {
131 close(ctrl->s);
132 os_free(ctrl);
136 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
137 sizeof(ctrl->local)) < 0) {
145 unlink(ctrl->local.sun_path);
148 close(ctrl->s);
149 os_free(ctrl);
154 chmod(ctrl->local.sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
156 chown(ctrl->local.sun_path, -1, AID_WIFI);
157 chown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI);
161 ctrl->s, ctrl_path + 9,
164 close(ctrl->s);
165 unlink(ctrl->local.sun_path);
166 os_free(ctrl);
169 return ctrl;
182 ctrl->s, buf,
185 close(ctrl->s);
186 unlink(ctrl->local.sun_path);
187 os_free(ctrl);
190 return ctrl;
194 ctrl->dest.sun_family = AF_UNIX;
196 ctrl->dest.sun_path[0] = '\0';
197 os_strlcpy(ctrl->dest.sun_path + 1, ctrl_path + 10,
198 sizeof(ctrl->dest.sun_path) - 1);
200 res = os_strlcpy(ctrl->dest.sun_path, ctrl_path,
201 sizeof(ctrl->dest.sun_path));
202 if (res >= sizeof(ctrl->dest.sun_path)) {
203 close(ctrl->s);
204 os_free(ctrl);
208 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
209 sizeof(ctrl->dest)) < 0) {
210 close(ctrl->s);
211 unlink(ctrl->local.sun_path);
212 os_free(ctrl);
220 flags = fcntl(ctrl->s, F_GETFL);
223 if (fcntl(ctrl->s, F_SETFL, flags) < 0) {
224 perror("fcntl(ctrl->s, O_NONBLOCK)");
229 return ctrl;
233 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
235 if (ctrl == NULL)
237 unlink(ctrl->local.sun_path);
238 if (ctrl->s >= 0)
239 close(ctrl->s);
240 os_free(ctrl);
296 struct wpa_ctrl *ctrl;
303 ctrl = os_zalloc(sizeof(*ctrl));
304 if (ctrl == NULL)
308 ctrl->s = socket(PF_INET6, SOCK_DGRAM, 0);
310 ctrl->s = socket(PF_INET, SOCK_DGRAM, 0);
312 if (ctrl->s < 0) {
314 os_free(ctrl);
319 ctrl->local.sin6_family = AF_INET6;
321 ctrl->local.sin6_addr = in6addr_any;
323 inet_pton(AF_INET6, "::1", &ctrl->local.sin6_addr);
326 ctrl->local.sin_family = AF_INET;
328 ctrl->local.sin_addr.s_addr = INADDR_ANY;
330 ctrl->local.sin_addr.s_addr = htonl((127 << 24) | 1);
334 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
335 sizeof(ctrl->local)) < 0) {
336 close(ctrl->s);
337 os_free(ctrl);
342 ctrl->dest.sin6_family = AF_INET6;
343 inet_pton(AF_INET6, "::1", &ctrl->dest.sin6_addr);
344 ctrl->dest.sin6_port = htons(WPA_CTRL_IFACE_PORT);
346 ctrl->dest.sin_family = AF_INET;
347 ctrl->dest.sin_addr.s_addr = htonl((127 << 24) | 1);
348 ctrl->dest.sin_port = htons(WPA_CTRL_IFACE_PORT);
362 close(ctrl->s);
363 os_free(ctrl);
388 ctrl->remote_ip = os_strdup(name);
392 close(ctrl->s);
393 os_free(ctrl->remote_ip);
394 os_free(ctrl);
398 ctrl->dest.sin6_scope_id = scope_id;
399 ctrl->dest.sin6_port = htons(port_id);
400 os_memcpy(&ctrl->dest.sin6_addr, h->h_addr, h->h_length);
402 ctrl->dest.sin_port = htons(port_id);
403 os_memcpy(&ctrl->dest.sin_addr.s_addr, h->h_addr, h->h_length);
406 ctrl->remote_ip = os_strdup("localhost");
409 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
410 sizeof(ctrl->dest)) < 0) {
414 inet_ntop(AF_INET6, &ctrl->dest.sin6_addr, addr,
415 sizeof(ctrl->dest)),
416 ntohs(ctrl->dest.sin6_port),
420 inet_ntoa(ctrl->dest.sin_addr),
421 ntohs(ctrl->dest.sin_port),
424 close(ctrl->s);
425 os_free(ctrl->remote_ip);
426 os_free(ctrl);
431 if (wpa_ctrl_request(ctrl, "GET_COOKIE", 10, buf, &len, NULL) == 0) {
433 ctrl->cookie = os_strdup(buf);
436 if (wpa_ctrl_request(ctrl, "IFNAME", 6, buf, &len, NULL) == 0) {
438 ctrl->remote_ifname = os_strdup(buf);
441 return ctrl;
445 char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl)
450 ctrl->remote_ip, ctrl->remote_ifname);
455 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
457 close(ctrl->s);
458 os_free(ctrl->cookie);
459 os_free(ctrl->remote_ifname);
460 os_free(ctrl->remote_ip);
461 os_free(ctrl);
468 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
481 if (ctrl->cookie) {
483 _cmd_len = os_strlen(ctrl->cookie) + 1 + cmd_len;
489 os_strlcpy(pos, ctrl->cookie, _cmd_len);
490 pos += os_strlen(ctrl->cookie);
504 if (send(ctrl->s, _cmd, _cmd_len, 0) < 0) {
533 FD_SET(ctrl->s, &rfds);
534 res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
539 if (FD_ISSET(ctrl->s, &rfds)) {
540 res = recv(ctrl->s, reply, *reply_len, 0);
569 static int wpa_ctrl_attach_helper(struct wpa_ctrl *ctrl, int attach)
575 ret = wpa_ctrl_request(ctrl, attach ? "ATTACH" : "DETACH", 6,
585 int wpa_ctrl_attach(struct wpa_ctrl *ctrl)
587 return wpa_ctrl_attach_helper(ctrl, 1);
591 int wpa_ctrl_detach(struct wpa_ctrl *ctrl)
593 return wpa_ctrl_attach_helper(ctrl, 0);
599 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
603 res = recv(ctrl->s, reply, *reply_len, 0);
611 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
618 FD_SET(ctrl->s, &rfds);
619 select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
620 return FD_ISSET(ctrl->s, &rfds);
624 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
626 return ctrl->s;
641 struct wpa_ctrl *ctrl;
646 ctrl = os_malloc(sizeof(*ctrl));
647 if (ctrl == NULL)
649 os_memset(ctrl, 0, sizeof(*ctrl));
665 os_free(ctrl);
670 ctrl->pipe = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0,
679 if (ctrl->pipe != INVALID_HANDLE_VALUE ||
684 if (ctrl->pipe == INVALID_HANDLE_VALUE) {
685 os_free(ctrl);
690 if (!SetNamedPipeHandleState(ctrl->pipe, &mode, NULL, NULL)) {
691 CloseHandle(ctrl->pipe);
692 os_free(ctrl);
696 return ctrl;
700 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
702 CloseHandle(ctrl->pipe);
703 os_free(ctrl);
707 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
714 if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL))
717 if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL))
725 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
728 if (!ReadFile(ctrl->pipe, reply, *reply_len, &len, NULL))
735 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
739 if (!PeekNamedPipe(ctrl->pipe, NULL, 0, NULL, &left, NULL))
745 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)