Home | History | Annotate | Download | only in common

Lines Matching defs:ctrl

75 	struct wpa_ctrl *ctrl;
81 ctrl = os_malloc(sizeof(*ctrl));
82 if (ctrl == NULL)
84 os_memset(ctrl, 0, sizeof(*ctrl));
86 ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0);
87 if (ctrl->s < 0) {
88 os_free(ctrl);
92 ctrl->local.sun_family = AF_UNIX;
95 ret = os_snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path),
102 if (ret < 0 || (size_t) ret >= sizeof(ctrl->local.sun_path)) {
103 close(ctrl->s);
104 os_free(ctrl);
108 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
109 sizeof(ctrl->local)) < 0) {
117 unlink(ctrl->local.sun_path);
120 close(ctrl->s);
121 os_free(ctrl);
126 chmod(ctrl->local.sun_path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
127 chown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI);
135 os_snprintf(ctrl->dest.sun_path, sizeof(ctrl->dest.sun_path), "wpa_%s",
137 if (socket_local_client_connect(ctrl->s,
138 ctrl->dest.sun_path,
141 close(ctrl->s);
142 unlink(ctrl->local.sun_path);
143 os_free(ctrl);
146 return ctrl;
149 ctrl->dest.sun_family = AF_UNIX;
150 res = os_strlcpy(ctrl->dest.sun_path, ctrl_path,
151 sizeof(ctrl->dest.sun_path));
152 if (res >= sizeof(ctrl->dest.sun_path)) {
153 close(ctrl->s);
154 os_free(ctrl);
157 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
158 sizeof(ctrl->dest)) < 0) {
159 close(ctrl->s);
160 unlink(ctrl->local.sun_path);
161 os_free(ctrl);
165 return ctrl;
169 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
171 if (ctrl == NULL)
173 unlink(ctrl->local.sun_path);
174 if (ctrl->s >= 0)
175 close(ctrl->s);
176 os_free(ctrl);
231 struct wpa_ctrl *ctrl;
235 ctrl = os_malloc(sizeof(*ctrl));
236 if (ctrl == NULL)
238 os_memset(ctrl, 0, sizeof(*ctrl));
240 ctrl->s = socket(PF_INET, SOCK_DGRAM, 0);
241 if (ctrl->s < 0) {
243 os_free(ctrl);
247 ctrl->local.sin_family = AF_INET;
248 ctrl->local.sin_addr.s_addr = htonl((127 << 24) | 1);
249 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
250 sizeof(ctrl->local)) < 0) {
251 close(ctrl->s);
252 os_free(ctrl);
256 ctrl->dest.sin_family = AF_INET;
257 ctrl->dest.sin_addr.s_addr = htonl((127 << 24) | 1);
258 ctrl->dest.sin_port = htons(WPA_CTRL_IFACE_PORT);
259 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
260 sizeof(ctrl->dest)) < 0) {
262 close(ctrl->s);
263 os_free(ctrl);
268 if (wpa_ctrl_request(ctrl, "GET_COOKIE", 10, buf, &len, NULL) == 0) {
270 ctrl->cookie = os_strdup(buf);
273 return ctrl;
277 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
279 close(ctrl->s);
280 os_free(ctrl->cookie);
281 os_free(ctrl);
288 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
300 if (ctrl->cookie) {
302 _cmd_len = os_strlen(ctrl->cookie) + 1 + cmd_len;
308 os_strlcpy(pos, ctrl->cookie, _cmd_len);
309 pos += os_strlen(ctrl->cookie);
319 if (send(ctrl->s, _cmd, _cmd_len, 0) < 0) {
333 FD_SET(ctrl->s, &rfds);
334 res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
335 if (FD_ISSET(ctrl->s, &rfds)) {
336 res = recv(ctrl->s, reply, *reply_len, 0);
365 static int wpa_ctrl_attach_helper(struct wpa_ctrl *ctrl, int attach)
371 ret = wpa_ctrl_request(ctrl, attach ? "ATTACH" : "DETACH", 6,
381 int wpa_ctrl_attach(struct wpa_ctrl *ctrl)
383 return wpa_ctrl_attach_helper(ctrl, 1);
387 int wpa_ctrl_detach(struct wpa_ctrl *ctrl)
389 return wpa_ctrl_attach_helper(ctrl, 0);
395 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
399 res = recv(ctrl->s, reply, *reply_len, 0);
407 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
414 FD_SET(ctrl->s, &rfds);
415 select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
416 return FD_ISSET(ctrl->s, &rfds);
420 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
422 return ctrl->s;
437 struct wpa_ctrl *ctrl;
442 ctrl = os_malloc(sizeof(*ctrl));
443 if (ctrl == NULL)
445 os_memset(ctrl, 0, sizeof(*ctrl));
461 os_free(ctrl);
466 ctrl->pipe = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0,
475 if (ctrl->pipe != INVALID_HANDLE_VALUE ||
480 if (ctrl->pipe == INVALID_HANDLE_VALUE) {
481 os_free(ctrl);
486 if (!SetNamedPipeHandleState(ctrl->pipe, &mode, NULL, NULL)) {
487 CloseHandle(ctrl->pipe);
488 os_free(ctrl);
492 return ctrl;
496 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
498 CloseHandle(ctrl->pipe);
499 os_free(ctrl);
503 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
510 if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL))
513 if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL))
521 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
524 if (!ReadFile(ctrl->pipe, reply, *reply_len, &len, NULL))
531 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
535 if (!PeekNamedPipe(ctrl->pipe, NULL, 0, NULL, &left, NULL))
541 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
543 return ctrl->pipe;