Home | History | Annotate | Download | only in wpa_supplicant

Lines Matching defs:ctrl

73 	struct wpa_ctrl *ctrl;
76 ctrl = os_malloc(sizeof(*ctrl));
77 if (ctrl == NULL)
79 os_memset(ctrl, 0, sizeof(*ctrl));
81 ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0);
82 if (ctrl->s < 0) {
83 os_free(ctrl);
87 ctrl->local.sun_family = AF_UNIX;
88 os_snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path),
95 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
96 sizeof(ctrl->local)) < 0) {
97 close(ctrl->s);
98 os_free(ctrl);
103 chmod(ctrl->local.sun_path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
104 chown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI);
112 os_snprintf(ctrl->dest.sun_path, sizeof(ctrl->dest.sun_path), "wpa_%s",
114 if (socket_local_client_connect(ctrl->s,
115 ctrl->dest.sun_path,
118 close(ctrl->s);
119 unlink(ctrl->local.sun_path);
120 os_free(ctrl);
123 return ctrl;
126 ctrl->dest.sun_family = AF_UNIX;
127 os_snprintf(ctrl->dest.sun_path, sizeof(ctrl->dest.sun_path), "%s",
129 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
130 sizeof(ctrl->dest)) < 0) {
131 close(ctrl->s);
132 unlink(ctrl->local.sun_path);
133 os_free(ctrl);
137 return ctrl;
141 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
143 if (ctrl == NULL)
145 unlink(ctrl->local.sun_path);
146 if (ctrl->s >= 0)
147 close(ctrl->s);
148 os_free(ctrl);
203 struct wpa_ctrl *ctrl;
207 ctrl = os_malloc(sizeof(*ctrl));
208 if (ctrl == NULL)
210 os_memset(ctrl, 0, sizeof(*ctrl));
212 ctrl->s = socket(PF_INET, SOCK_DGRAM, 0);
213 if (ctrl->s < 0) {
215 os_free(ctrl);
219 ctrl->local.sin_family = AF_INET;
220 ctrl->local.sin_addr.s_addr = htonl((127 << 24) | 1);
221 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
222 sizeof(ctrl->local)) < 0) {
223 close(ctrl->s);
224 os_free(ctrl);
228 ctrl->dest.sin_family = AF_INET;
229 ctrl->dest.sin_addr.s_addr = htonl((127 << 24) | 1);
230 ctrl->dest.sin_port = htons(WPA_CTRL_IFACE_PORT);
231 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
232 sizeof(ctrl->dest)) < 0) {
234 close(ctrl->s);
235 os_free(ctrl);
240 if (wpa_ctrl_request(ctrl, "GET_COOKIE", 10, buf, &len, NULL) == 0) {
242 ctrl->cookie = strdup(buf);
245 return ctrl;
249 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
251 close(ctrl->s);
252 os_free(ctrl->cookie);
253 os_free(ctrl);
260 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
272 if (ctrl->cookie) {
274 _cmd_len = strlen(ctrl->cookie) + 1 + cmd_len;
280 strcpy(pos, ctrl->cookie);
281 pos += strlen(ctrl->cookie);
291 if (send(ctrl->s, _cmd, _cmd_len, 0) < 0) {
305 FD_SET(ctrl->s, &rfds);
306 res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
307 if (FD_ISSET(ctrl->s, &rfds)) {
308 res = recv(ctrl->s, reply, *reply_len, 0);
337 static int wpa_ctrl_attach_helper(struct wpa_ctrl *ctrl, int attach)
343 ret = wpa_ctrl_request(ctrl, attach ? "ATTACH" : "DETACH", 6,
353 int wpa_ctrl_attach(struct wpa_ctrl *ctrl)
355 return wpa_ctrl_attach_helper(ctrl, 1);
359 int wpa_ctrl_detach(struct wpa_ctrl *ctrl)
361 return wpa_ctrl_attach_helper(ctrl, 0);
367 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
371 res = recv(ctrl->s, reply, *reply_len, 0);
379 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
386 FD_SET(ctrl->s, &rfds);
387 select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
388 return FD_ISSET(ctrl->s, &rfds);
392 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
394 return ctrl->s;
409 struct wpa_ctrl *ctrl;
414 ctrl = os_malloc(sizeof(*ctrl));
415 if (ctrl == NULL)
417 os_memset(ctrl, 0, sizeof(*ctrl));
434 ctrl->pipe = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0,
443 if (ctrl->pipe != INVALID_HANDLE_VALUE ||
448 if (ctrl->pipe == INVALID_HANDLE_VALUE) {
449 os_free(ctrl);
454 if (!SetNamedPipeHandleState(ctrl->pipe, &mode, NULL, NULL)) {
455 CloseHandle(ctrl->pipe);
456 os_free(ctrl);
460 return ctrl;
464 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
466 CloseHandle(ctrl->pipe);
467 os_free(ctrl);
471 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
478 if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL))
481 if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL))
489 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
492 if (!ReadFile(ctrl->pipe, reply, *reply_len, &len, NULL))
499 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
503 if (!PeekNamedPipe(ctrl->pipe, NULL, 0, NULL, &left, NULL))
509 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
511 return ctrl->pipe;