Lines Matching defs:ctrl

78 	struct wpa_ctrl *ctrl;
85 ctrl = os_malloc(sizeof(*ctrl));
86 if (ctrl == NULL)
88 os_memset(ctrl, 0, sizeof(*ctrl));
90 ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0);
91 if (ctrl->s < 0) {
92 os_free(ctrl);
96 ctrl->local.sun_family = AF_UNIX;
99 ret = os_snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path),
103 if (ret < 0 || (size_t) ret >= sizeof(ctrl->local.sun_path)) {
104 close(ctrl->s);
105 os_free(ctrl);
109 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
110 sizeof(ctrl->local)) < 0) {
118 unlink(ctrl->local.sun_path);
121 close(ctrl->s);
122 os_free(ctrl);
127 chmod(ctrl->local.sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
128 chown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI);
139 ctrl->s, buf,
142 close(ctrl->s);
143 unlink(ctrl->local.sun_path);
144 os_free(ctrl);
147 return ctrl;
151 ctrl->dest.sun_family = AF_UNIX;
152 res = os_strlcpy(ctrl->dest.sun_path, ctrl_path,
153 sizeof(ctrl->dest.sun_path));
154 if (res >= sizeof(ctrl->dest.sun_path)) {
155 close(ctrl->s);
156 os_free(ctrl);
159 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
160 sizeof(ctrl->dest)) < 0) {
161 close(ctrl->s);
162 unlink(ctrl->local.sun_path);
163 os_free(ctrl);
171 flags = fcntl(ctrl->s, F_GETFL);
174 if (fcntl(ctrl->s, F_SETFL, flags) < 0) {
175 perror("fcntl(ctrl->s, O_NONBLOCK)");
180 return ctrl;
184 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
186 if (ctrl == NULL)
188 unlink(ctrl->local.sun_path);
189 if (ctrl->s >= 0)
190 close(ctrl->s);
191 os_free(ctrl);
251 struct wpa_ctrl *ctrl;
258 ctrl = os_malloc(sizeof(*ctrl));
259 if (ctrl == NULL)
261 os_memset(ctrl, 0, sizeof(*ctrl));
263 ctrl->s = socket(PF_INET, SOCK_DGRAM, 0);
264 if (ctrl->s < 0) {
266 os_free(ctrl);
270 ctrl->local.sin_family = AF_INET;
272 ctrl->local.sin_addr.s_addr = INADDR_ANY;
274 ctrl->local.sin_addr.s_addr = htonl((127 << 24) | 1);
276 if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
277 sizeof(ctrl->local)) < 0) {
278 close(ctrl->s);
279 os_free(ctrl);
283 ctrl->dest.sin_family = AF_INET;
284 ctrl->dest.sin_addr.s_addr = htonl((127 << 24) | 1);
285 ctrl->dest.sin_port = htons(WPA_CTRL_IFACE_PORT);
294 close(ctrl->s);
295 os_free(ctrl);
307 ctrl->remote_ip = os_strdup(name);
311 close(ctrl->s);
312 os_free(ctrl->remote_ip);
313 os_free(ctrl);
316 ctrl->dest.sin_port = htons(port_id);
317 os_memcpy(h->h_addr, (char *) &ctrl->dest.sin_addr.s_addr,
320 ctrl->remote_ip = os_strdup("localhost");
323 if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
324 sizeof(ctrl->dest)) < 0) {
326 close(ctrl->s);
327 os_free(ctrl->remote_ip);
328 os_free(ctrl);
333 if (wpa_ctrl_request(ctrl, "GET_COOKIE", 10, buf, &len, NULL) == 0) {
335 ctrl->cookie = os_strdup(buf);
338 if (wpa_ctrl_request(ctrl, "IFNAME", 6, buf, &len, NULL) == 0) {
340 ctrl->remote_ifname = os_strdup(buf);
343 return ctrl;
347 char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl)
352 ctrl->remote_ip, ctrl->remote_ifname);
357 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
359 close(ctrl->s);
360 os_free(ctrl->cookie);
361 os_free(ctrl->remote_ifname);
362 os_free(ctrl->remote_ip);
363 os_free(ctrl);
370 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
383 if (ctrl->cookie) {
385 _cmd_len = os_strlen(ctrl->cookie) + 1 + cmd_len;
391 os_strlcpy(pos, ctrl->cookie, _cmd_len);
392 pos += os_strlen(ctrl->cookie);
406 if (send(ctrl->s, _cmd, _cmd_len, 0) < 0) {
435 FD_SET(ctrl->s, &rfds);
436 res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
439 if (FD_ISSET(ctrl->s, &rfds)) {
440 res = recv(ctrl->s, reply, *reply_len, 0);
469 static int wpa_ctrl_attach_helper(struct wpa_ctrl *ctrl, int attach)
475 ret = wpa_ctrl_request(ctrl, attach ? "ATTACH" : "DETACH", 6,
485 int wpa_ctrl_attach(struct wpa_ctrl *ctrl)
487 return wpa_ctrl_attach_helper(ctrl, 1);
491 int wpa_ctrl_detach(struct wpa_ctrl *ctrl)
493 return wpa_ctrl_attach_helper(ctrl, 0);
499 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
503 res = recv(ctrl->s, reply, *reply_len, 0);
511 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
518 FD_SET(ctrl->s, &rfds);
519 select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
520 return FD_ISSET(ctrl->s, &rfds);
524 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
526 return ctrl->s;
541 struct wpa_ctrl *ctrl;
546 ctrl = os_malloc(sizeof(*ctrl));
547 if (ctrl == NULL)
549 os_memset(ctrl, 0, sizeof(*ctrl));
565 os_free(ctrl);
570 ctrl->pipe = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0,
579 if (ctrl->pipe != INVALID_HANDLE_VALUE ||
584 if (ctrl->pipe == INVALID_HANDLE_VALUE) {
585 os_free(ctrl);
590 if (!SetNamedPipeHandleState(ctrl->pipe, &mode, NULL, NULL)) {
591 CloseHandle(ctrl->pipe);
592 os_free(ctrl);
596 return ctrl;
600 void wpa_ctrl_close(struct wpa_ctrl *ctrl)
602 CloseHandle(ctrl->pipe);
603 os_free(ctrl);
607 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
614 if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL))
617 if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL))
625 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
628 if (!ReadFile(ctrl->pipe, reply, *reply_len, &len, NULL))
635 int wpa_ctrl_pending(struct wpa_ctrl *ctrl)
639 if (!PeekNamedPipe(ctrl->pipe, NULL, 0, NULL, &left, NULL))
645 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)