Lines Matching full:ctrl
78 struct wpa_ctrl *ctrl;
88 ctrl = os_malloc(sizeof(*ctrl));
89 if (ctrl == NULL)
91 os_memset(ctrl, 0, sizeof(*ctrl));
93 ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0);
94 if (ctrl->s < 0) {
95 os_free(ctrl);
99 ctrl->local.sun_family = AF_UNIX;
102 ret = os_snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path),
106 if (ret < 0 || (size_t) ret >= sizeof(ctrl->local.sun_path)) {
107 close(ctrl->s);
108 os_free(ctrl);
112 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
113 sizeof(ctrl->local)) < 0) {
121 unlink(ctrl->local.sun_path);
124 close(ctrl->s);
125 os_free(ctrl);
130 chmod(ctrl->local.sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
131 chown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI);
135 ctrl->s, ctrl_path + 9,
138 close(ctrl->s);
139 unlink(ctrl->local.sun_path);
140 os_free(ctrl);
143 return ctrl;
156 ctrl->s, buf,
159 close(ctrl->s);
160 unlink(ctrl->local.sun_path);
161 os_free(ctrl);
164 return ctrl;
168 ctrl->dest.sun_family = AF_UNIX;
170 ctrl->dest.sun_path[0] = '\0';
171 os_strlcpy(ctrl->dest.sun_path + 1, ctrl_path + 10,
172 sizeof(ctrl->dest.sun_path) - 1);
174 res = os_strlcpy(ctrl->dest.sun_path, ctrl_path,
175 sizeof(ctrl->dest.sun_path));
176 if (res >= sizeof(ctrl->dest.sun_path)) {
177 close(ctrl->s);
178 os_free(ctrl);
182 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
183 sizeof(ctrl->dest)) < 0) {
184 close(ctrl->s);
185 unlink(ctrl->local.sun_path);
186 os_free(ctrl);
194 flags = fcntl(ctrl->s, F_GETFL);
197 if (fcntl(ctrl->s, F_SETFL, flags) < 0) {
198 perror("fcntl(ctrl->s, O_NONBLOCK)");
203 return ctrl;
207 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
209 if (ctrl == NULL)
211 unlink(ctrl->local.sun_path);
212 if (ctrl->s >= 0)
213 close(ctrl->s);
214 os_free(ctrl);
270 struct wpa_ctrl *ctrl;
277 ctrl = os_malloc(sizeof(*ctrl));
278 if (ctrl == NULL)
280 os_memset(ctrl, 0, sizeof(*ctrl));
282 ctrl->s = socket(PF_INET, SOCK_DGRAM, 0);
283 if (ctrl->s < 0) {
285 os_free(ctrl);
289 ctrl->local.sin_family = AF_INET;
291 ctrl->local.sin_addr.s_addr = INADDR_ANY;
293 ctrl->local.sin_addr.s_addr = htonl((127 << 24) | 1);
295 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
296 sizeof(ctrl->local)) < 0) {
297 close(ctrl->s);
298 os_free(ctrl);
302 ctrl->dest.sin_family = AF_INET;
303 ctrl->dest.sin_addr.s_addr = htonl((127 << 24) | 1);
304 ctrl->dest.sin_port = htons(WPA_CTRL_IFACE_PORT);
313 close(ctrl->s);
314 os_free(ctrl);
326 ctrl->remote_ip = os_strdup(name);
330 close(ctrl->s);
331 os_free(ctrl->remote_ip);
332 os_free(ctrl);
335 ctrl->dest.sin_port = htons(port_id);
336 os_memcpy(h->h_addr, (char *) &ctrl->dest.sin_addr.s_addr,
339 ctrl->remote_ip = os_strdup("localhost");
342 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
343 sizeof(ctrl->dest)) < 0) {
345 close(ctrl->s);
346 os_free(ctrl->remote_ip);
347 os_free(ctrl);
352 if (wpa_ctrl_request(ctrl, "GET_COOKIE", 10, buf, &len, NULL) == 0) {
354 ctrl->cookie = os_strdup(buf);
357 if (wpa_ctrl_request(ctrl, "IFNAME", 6, buf, &len, NULL) == 0) {
359 ctrl->remote_ifname = os_strdup(buf);
362 return ctrl;
366 char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl)
371 ctrl->remote_ip, ctrl->remote_ifname);
376 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
378 close(ctrl->s);
379 os_free(ctrl->cookie);
380 os_free(ctrl->remote_ifname);
381 os_free(ctrl->remote_ip);
382 os_free(ctrl);
389 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
402 if (ctrl->cookie) {
404 _cmd_len = os_strlen(ctrl->cookie) + 1 + cmd_len;
410 os_strlcpy(pos, ctrl->cookie, _cmd_len);
411 pos += os_strlen(ctrl->cookie);
425 if (send(ctrl->s, _cmd, _cmd_len, 0) < 0) {
454 FD_SET(ctrl->s, &rfds);
455 res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
458 if (FD_ISSET(ctrl->s, &rfds)) {
459 res = recv(ctrl->s, reply, *reply_len, 0);
488 static int wpa_ctrl_attach_helper(struct wpa_ctrl *ctrl, int attach)
494 ret = wpa_ctrl_request(ctrl, attach ? "ATTACH" : "DETACH", 6,
504 int wpa_ctrl_attach(struct wpa_ctrl *ctrl)
506 return wpa_ctrl_attach_helper(ctrl, 1);
510 int wpa_ctrl_detach(struct wpa_ctrl *ctrl)
512 return wpa_ctrl_attach_helper(ctrl, 0);
518 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
522 res = recv(ctrl->s, reply, *reply_len, 0);
530 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
537 FD_SET(ctrl->s, &rfds);
538 select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
539 return FD_ISSET(ctrl->s, &rfds);
543 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
545 return ctrl->s;
560 struct wpa_ctrl *ctrl;
565 ctrl = os_malloc(sizeof(*ctrl));
566 if (ctrl == NULL)
568 os_memset(ctrl, 0, sizeof(*ctrl));
584 os_free(ctrl);
589 ctrl->pipe = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0,
598 if (ctrl->pipe != INVALID_HANDLE_VALUE ||
603 if (ctrl->pipe == INVALID_HANDLE_VALUE) {
604 os_free(ctrl);
609 if (!SetNamedPipeHandleState(ctrl->pipe, &mode, NULL, NULL)) {
610 CloseHandle(ctrl->pipe);
611 os_free(ctrl);
615 return ctrl;
619 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
621 CloseHandle(ctrl->pipe);
622 os_free(ctrl);
626 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
633 if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL))
636 if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL))
644 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
647 if (!ReadFile(ctrl->pipe, reply, *reply_len, &len, NULL))
654 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
658 if (!PeekNamedPipe(ctrl->pipe, NULL, 0, NULL, &left, NULL))
664 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)