driver_privsep.c revision 6c0da2bb83f6915d8260912362692d1a742e057b
1/* 2 * WPA Supplicant - privilege separated driver interface 3 * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9#include "includes.h" 10#include <sys/un.h> 11 12#include "common.h" 13#include "driver.h" 14#include "eloop.h" 15#include "common/privsep_commands.h" 16 17 18struct wpa_driver_privsep_data { 19 void *ctx; 20 u8 own_addr[ETH_ALEN]; 21 int priv_socket; 22 char *own_socket_path; 23 int cmd_socket; 24 char *own_cmd_path; 25 struct sockaddr_un priv_addr; 26 char ifname[16]; 27}; 28 29 30static int wpa_priv_reg_cmd(struct wpa_driver_privsep_data *drv, int cmd) 31{ 32 int res; 33 34 res = sendto(drv->priv_socket, &cmd, sizeof(cmd), 0, 35 (struct sockaddr *) &drv->priv_addr, 36 sizeof(drv->priv_addr)); 37 if (res < 0) 38 wpa_printf(MSG_ERROR, "sendto: %s", strerror(errno)); 39 return res < 0 ? -1 : 0; 40} 41 42 43static int wpa_priv_cmd(struct wpa_driver_privsep_data *drv, int cmd, 44 const void *data, size_t data_len, 45 void *reply, size_t *reply_len) 46{ 47 struct msghdr msg; 48 struct iovec io[2]; 49 50 io[0].iov_base = &cmd; 51 io[0].iov_len = sizeof(cmd); 52 io[1].iov_base = (u8 *) data; 53 io[1].iov_len = data_len; 54 55 os_memset(&msg, 0, sizeof(msg)); 56 msg.msg_iov = io; 57 msg.msg_iovlen = data ? 2 : 1; 58 msg.msg_name = &drv->priv_addr; 59 msg.msg_namelen = sizeof(drv->priv_addr); 60 61 if (sendmsg(drv->cmd_socket, &msg, 0) < 0) { 62 wpa_printf(MSG_ERROR, "sendmsg(cmd_socket): %s", 63 strerror(errno)); 64 return -1; 65 } 66 67 if (reply) { 68 fd_set rfds; 69 struct timeval tv; 70 int res; 71 72 FD_ZERO(&rfds); 73 FD_SET(drv->cmd_socket, &rfds); 74 tv.tv_sec = 5; 75 tv.tv_usec = 0; 76 res = select(drv->cmd_socket + 1, &rfds, NULL, NULL, &tv); 77 if (res < 0 && errno != EINTR) { 78 wpa_printf(MSG_ERROR, "select: %s", strerror(errno)); 79 return -1; 80 } 81 82 if (FD_ISSET(drv->cmd_socket, &rfds)) { 83 res = recv(drv->cmd_socket, reply, *reply_len, 0); 84 if (res < 0) { 85 wpa_printf(MSG_ERROR, "recv: %s", 86 strerror(errno)); 87 return -1; 88 } 89 *reply_len = res; 90 } else { 91 wpa_printf(MSG_DEBUG, "PRIVSEP: Timeout while waiting " 92 "for reply (cmd=%d)", cmd); 93 return -1; 94 } 95 } 96 97 return 0; 98} 99 100 101static int wpa_driver_privsep_scan(void *priv, 102 struct wpa_driver_scan_params *params) 103{ 104 struct wpa_driver_privsep_data *drv = priv; 105 const u8 *ssid = params->ssids[0].ssid; 106 size_t ssid_len = params->ssids[0].ssid_len; 107 wpa_printf(MSG_DEBUG, "%s: priv=%p", __func__, priv); 108 return wpa_priv_cmd(drv, PRIVSEP_CMD_SCAN, ssid, ssid_len, 109 NULL, NULL); 110} 111 112 113static struct wpa_scan_results * 114wpa_driver_privsep_get_scan_results2(void *priv) 115{ 116 struct wpa_driver_privsep_data *drv = priv; 117 int res, num; 118 u8 *buf, *pos, *end; 119 size_t reply_len = 60000; 120 struct wpa_scan_results *results; 121 struct wpa_scan_res *r; 122 123 buf = os_malloc(reply_len); 124 if (buf == NULL) 125 return NULL; 126 res = wpa_priv_cmd(drv, PRIVSEP_CMD_GET_SCAN_RESULTS, 127 NULL, 0, buf, &reply_len); 128 if (res < 0) { 129 os_free(buf); 130 return NULL; 131 } 132 133 wpa_printf(MSG_DEBUG, "privsep: Received %lu bytes of scan results", 134 (unsigned long) reply_len); 135 if (reply_len < sizeof(int)) { 136 wpa_printf(MSG_DEBUG, "privsep: Invalid scan result len %lu", 137 (unsigned long) reply_len); 138 os_free(buf); 139 return NULL; 140 } 141 142 pos = buf; 143 end = buf + reply_len; 144 os_memcpy(&num, pos, sizeof(int)); 145 if (num < 0 || num > 1000) { 146 os_free(buf); 147 return NULL; 148 } 149 pos += sizeof(int); 150 151 results = os_zalloc(sizeof(*results)); 152 if (results == NULL) { 153 os_free(buf); 154 return NULL; 155 } 156 157 results->res = os_calloc(num, sizeof(struct wpa_scan_res *)); 158 if (results->res == NULL) { 159 os_free(results); 160 os_free(buf); 161 return NULL; 162 } 163 164 while (results->num < (size_t) num && pos + sizeof(int) < end) { 165 int len; 166 os_memcpy(&len, pos, sizeof(int)); 167 pos += sizeof(int); 168 if (len < 0 || len > 10000 || pos + len > end) 169 break; 170 171 r = os_malloc(len); 172 if (r == NULL) 173 break; 174 os_memcpy(r, pos, len); 175 pos += len; 176 if (sizeof(*r) + r->ie_len > (size_t) len) { 177 os_free(r); 178 break; 179 } 180 181 results->res[results->num++] = r; 182 } 183 184 os_free(buf); 185 return results; 186} 187 188 189static int wpa_driver_privsep_set_key(const char *ifname, void *priv, 190 enum wpa_alg alg, const u8 *addr, 191 int key_idx, int set_tx, 192 const u8 *seq, size_t seq_len, 193 const u8 *key, size_t key_len) 194{ 195 struct wpa_driver_privsep_data *drv = priv; 196 struct privsep_cmd_set_key cmd; 197 198 wpa_printf(MSG_DEBUG, "%s: priv=%p alg=%d key_idx=%d set_tx=%d", 199 __func__, priv, alg, key_idx, set_tx); 200 201 os_memset(&cmd, 0, sizeof(cmd)); 202 cmd.alg = alg; 203 if (addr) 204 os_memcpy(cmd.addr, addr, ETH_ALEN); 205 else 206 os_memset(cmd.addr, 0xff, ETH_ALEN); 207 cmd.key_idx = key_idx; 208 cmd.set_tx = set_tx; 209 if (seq && seq_len > 0 && seq_len < sizeof(cmd.seq)) { 210 os_memcpy(cmd.seq, seq, seq_len); 211 cmd.seq_len = seq_len; 212 } 213 if (key && key_len > 0 && key_len < sizeof(cmd.key)) { 214 os_memcpy(cmd.key, key, key_len); 215 cmd.key_len = key_len; 216 } 217 218 return wpa_priv_cmd(drv, PRIVSEP_CMD_SET_KEY, &cmd, sizeof(cmd), 219 NULL, NULL); 220} 221 222 223static int wpa_driver_privsep_associate( 224 void *priv, struct wpa_driver_associate_params *params) 225{ 226 struct wpa_driver_privsep_data *drv = priv; 227 struct privsep_cmd_associate *data; 228 int res; 229 size_t buflen; 230 231 wpa_printf(MSG_DEBUG, "%s: priv=%p freq=%d pairwise_suite=%d " 232 "group_suite=%d key_mgmt_suite=%d auth_alg=%d mode=%d", 233 __func__, priv, params->freq.freq, params->pairwise_suite, 234 params->group_suite, params->key_mgmt_suite, 235 params->auth_alg, params->mode); 236 237 buflen = sizeof(*data) + params->wpa_ie_len; 238 data = os_zalloc(buflen); 239 if (data == NULL) 240 return -1; 241 242 if (params->bssid) 243 os_memcpy(data->bssid, params->bssid, ETH_ALEN); 244 os_memcpy(data->ssid, params->ssid, params->ssid_len); 245 data->ssid_len = params->ssid_len; 246 data->hwmode = params->freq.mode; 247 data->freq = params->freq.freq; 248 data->channel = params->freq.channel; 249 data->pairwise_suite = params->pairwise_suite; 250 data->group_suite = params->group_suite; 251 data->key_mgmt_suite = params->key_mgmt_suite; 252 data->auth_alg = params->auth_alg; 253 data->mode = params->mode; 254 data->wpa_ie_len = params->wpa_ie_len; 255 if (params->wpa_ie) 256 os_memcpy(data + 1, params->wpa_ie, params->wpa_ie_len); 257 /* TODO: add support for other assoc parameters */ 258 259 res = wpa_priv_cmd(drv, PRIVSEP_CMD_ASSOCIATE, data, buflen, 260 NULL, NULL); 261 os_free(data); 262 263 return res; 264} 265 266 267static int wpa_driver_privsep_get_bssid(void *priv, u8 *bssid) 268{ 269 struct wpa_driver_privsep_data *drv = priv; 270 int res; 271 size_t len = ETH_ALEN; 272 273 res = wpa_priv_cmd(drv, PRIVSEP_CMD_GET_BSSID, NULL, 0, bssid, &len); 274 if (res < 0 || len != ETH_ALEN) 275 return -1; 276 return 0; 277} 278 279 280static int wpa_driver_privsep_get_ssid(void *priv, u8 *ssid) 281{ 282 struct wpa_driver_privsep_data *drv = priv; 283 int res, ssid_len; 284 u8 reply[sizeof(int) + 32]; 285 size_t len = sizeof(reply); 286 287 res = wpa_priv_cmd(drv, PRIVSEP_CMD_GET_SSID, NULL, 0, reply, &len); 288 if (res < 0 || len < sizeof(int)) 289 return -1; 290 os_memcpy(&ssid_len, reply, sizeof(int)); 291 if (ssid_len < 0 || ssid_len > 32 || sizeof(int) + ssid_len > len) { 292 wpa_printf(MSG_DEBUG, "privsep: Invalid get SSID reply"); 293 return -1; 294 } 295 os_memcpy(ssid, &reply[sizeof(int)], ssid_len); 296 return ssid_len; 297} 298 299 300static int wpa_driver_privsep_deauthenticate(void *priv, const u8 *addr, 301 int reason_code) 302{ 303 //struct wpa_driver_privsep_data *drv = priv; 304 wpa_printf(MSG_DEBUG, "%s addr=" MACSTR " reason_code=%d", 305 __func__, MAC2STR(addr), reason_code); 306 wpa_printf(MSG_DEBUG, "%s - TODO", __func__); 307 return 0; 308} 309 310 311static void wpa_driver_privsep_event_assoc(void *ctx, 312 enum wpa_event_type event, 313 u8 *buf, size_t len) 314{ 315 union wpa_event_data data; 316 int inc_data = 0; 317 u8 *pos, *end; 318 int ie_len; 319 320 os_memset(&data, 0, sizeof(data)); 321 322 pos = buf; 323 end = buf + len; 324 325 if (end - pos < (int) sizeof(int)) 326 return; 327 os_memcpy(&ie_len, pos, sizeof(int)); 328 pos += sizeof(int); 329 if (ie_len < 0 || ie_len > end - pos) 330 return; 331 if (ie_len) { 332 data.assoc_info.req_ies = pos; 333 data.assoc_info.req_ies_len = ie_len; 334 pos += ie_len; 335 inc_data = 1; 336 } 337 338 wpa_supplicant_event(ctx, event, inc_data ? &data : NULL); 339} 340 341 342static void wpa_driver_privsep_event_interface_status(void *ctx, u8 *buf, 343 size_t len) 344{ 345 union wpa_event_data data; 346 int ievent; 347 348 if (len < sizeof(int) || 349 len - sizeof(int) > sizeof(data.interface_status.ifname)) 350 return; 351 352 os_memcpy(&ievent, buf, sizeof(int)); 353 354 os_memset(&data, 0, sizeof(data)); 355 data.interface_status.ievent = ievent; 356 os_memcpy(data.interface_status.ifname, buf + sizeof(int), 357 len - sizeof(int)); 358 wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &data); 359} 360 361 362static void wpa_driver_privsep_event_michael_mic_failure( 363 void *ctx, u8 *buf, size_t len) 364{ 365 union wpa_event_data data; 366 367 if (len != sizeof(int)) 368 return; 369 370 os_memset(&data, 0, sizeof(data)); 371 os_memcpy(&data.michael_mic_failure.unicast, buf, sizeof(int)); 372 wpa_supplicant_event(ctx, EVENT_MICHAEL_MIC_FAILURE, &data); 373} 374 375 376static void wpa_driver_privsep_event_pmkid_candidate(void *ctx, u8 *buf, 377 size_t len) 378{ 379 union wpa_event_data data; 380 381 if (len != sizeof(struct pmkid_candidate)) 382 return; 383 384 os_memset(&data, 0, sizeof(data)); 385 os_memcpy(&data.pmkid_candidate, buf, len); 386 wpa_supplicant_event(ctx, EVENT_PMKID_CANDIDATE, &data); 387} 388 389 390static void wpa_driver_privsep_event_stkstart(void *ctx, u8 *buf, size_t len) 391{ 392 union wpa_event_data data; 393 394 if (len != ETH_ALEN) 395 return; 396 397 os_memset(&data, 0, sizeof(data)); 398 os_memcpy(data.stkstart.peer, buf, ETH_ALEN); 399 wpa_supplicant_event(ctx, EVENT_STKSTART, &data); 400} 401 402 403static void wpa_driver_privsep_event_ft_response(void *ctx, u8 *buf, 404 size_t len) 405{ 406 union wpa_event_data data; 407 408 if (len < sizeof(int) + ETH_ALEN) 409 return; 410 411 os_memset(&data, 0, sizeof(data)); 412 os_memcpy(&data.ft_ies.ft_action, buf, sizeof(int)); 413 os_memcpy(data.ft_ies.target_ap, buf + sizeof(int), ETH_ALEN); 414 data.ft_ies.ies = buf + sizeof(int) + ETH_ALEN; 415 data.ft_ies.ies_len = len - sizeof(int) - ETH_ALEN; 416 wpa_supplicant_event(ctx, EVENT_FT_RESPONSE, &data); 417} 418 419 420static void wpa_driver_privsep_event_rx_eapol(void *ctx, u8 *buf, size_t len) 421{ 422 if (len < ETH_ALEN) 423 return; 424 drv_event_eapol_rx(ctx, buf, buf + ETH_ALEN, len - ETH_ALEN); 425} 426 427 428static void wpa_driver_privsep_receive(int sock, void *eloop_ctx, 429 void *sock_ctx) 430{ 431 struct wpa_driver_privsep_data *drv = eloop_ctx; 432 u8 *buf, *event_buf; 433 size_t event_len; 434 int res, event; 435 enum privsep_event e; 436 struct sockaddr_un from; 437 socklen_t fromlen = sizeof(from); 438 const size_t buflen = 2000; 439 440 buf = os_malloc(buflen); 441 if (buf == NULL) 442 return; 443 res = recvfrom(sock, buf, buflen, 0, 444 (struct sockaddr *) &from, &fromlen); 445 if (res < 0) { 446 wpa_printf(MSG_ERROR, "recvfrom(priv_socket): %s", 447 strerror(errno)); 448 os_free(buf); 449 return; 450 } 451 452 wpa_printf(MSG_DEBUG, "privsep_driver: received %u bytes", res); 453 454 if (res < (int) sizeof(int)) { 455 wpa_printf(MSG_DEBUG, "Too short event message (len=%d)", res); 456 return; 457 } 458 459 os_memcpy(&event, buf, sizeof(int)); 460 event_buf = &buf[sizeof(int)]; 461 event_len = res - sizeof(int); 462 wpa_printf(MSG_DEBUG, "privsep: Event %d received (len=%lu)", 463 event, (unsigned long) event_len); 464 465 e = event; 466 switch (e) { 467 case PRIVSEP_EVENT_SCAN_RESULTS: 468 wpa_supplicant_event(drv->ctx, EVENT_SCAN_RESULTS, NULL); 469 break; 470 case PRIVSEP_EVENT_ASSOC: 471 wpa_driver_privsep_event_assoc(drv->ctx, EVENT_ASSOC, 472 event_buf, event_len); 473 break; 474 case PRIVSEP_EVENT_DISASSOC: 475 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL); 476 break; 477 case PRIVSEP_EVENT_ASSOCINFO: 478 wpa_driver_privsep_event_assoc(drv->ctx, EVENT_ASSOCINFO, 479 event_buf, event_len); 480 break; 481 case PRIVSEP_EVENT_MICHAEL_MIC_FAILURE: 482 wpa_driver_privsep_event_michael_mic_failure( 483 drv->ctx, event_buf, event_len); 484 break; 485 case PRIVSEP_EVENT_INTERFACE_STATUS: 486 wpa_driver_privsep_event_interface_status(drv->ctx, event_buf, 487 event_len); 488 break; 489 case PRIVSEP_EVENT_PMKID_CANDIDATE: 490 wpa_driver_privsep_event_pmkid_candidate(drv->ctx, event_buf, 491 event_len); 492 break; 493 case PRIVSEP_EVENT_STKSTART: 494 wpa_driver_privsep_event_stkstart(drv->ctx, event_buf, 495 event_len); 496 break; 497 case PRIVSEP_EVENT_FT_RESPONSE: 498 wpa_driver_privsep_event_ft_response(drv->ctx, event_buf, 499 event_len); 500 break; 501 case PRIVSEP_EVENT_RX_EAPOL: 502 wpa_driver_privsep_event_rx_eapol(drv->ctx, event_buf, 503 event_len); 504 break; 505 } 506 507 os_free(buf); 508} 509 510 511static void * wpa_driver_privsep_init(void *ctx, const char *ifname) 512{ 513 struct wpa_driver_privsep_data *drv; 514 515 drv = os_zalloc(sizeof(*drv)); 516 if (drv == NULL) 517 return NULL; 518 drv->ctx = ctx; 519 drv->priv_socket = -1; 520 drv->cmd_socket = -1; 521 os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname)); 522 523 return drv; 524} 525 526 527static void wpa_driver_privsep_deinit(void *priv) 528{ 529 struct wpa_driver_privsep_data *drv = priv; 530 531 if (drv->priv_socket >= 0) { 532 wpa_priv_reg_cmd(drv, PRIVSEP_CMD_UNREGISTER); 533 eloop_unregister_read_sock(drv->priv_socket); 534 close(drv->priv_socket); 535 } 536 537 if (drv->own_socket_path) { 538 unlink(drv->own_socket_path); 539 os_free(drv->own_socket_path); 540 } 541 542 if (drv->cmd_socket >= 0) { 543 eloop_unregister_read_sock(drv->cmd_socket); 544 close(drv->cmd_socket); 545 } 546 547 if (drv->own_cmd_path) { 548 unlink(drv->own_cmd_path); 549 os_free(drv->own_cmd_path); 550 } 551 552 os_free(drv); 553} 554 555 556static int wpa_driver_privsep_set_param(void *priv, const char *param) 557{ 558 struct wpa_driver_privsep_data *drv = priv; 559 const char *pos; 560 char *own_dir, *priv_dir; 561 static unsigned int counter = 0; 562 size_t len; 563 struct sockaddr_un addr; 564 565 wpa_printf(MSG_DEBUG, "%s: param='%s'", __func__, param); 566 if (param == NULL) 567 pos = NULL; 568 else 569 pos = os_strstr(param, "own_dir="); 570 if (pos) { 571 char *end; 572 own_dir = os_strdup(pos + 8); 573 if (own_dir == NULL) 574 return -1; 575 end = os_strchr(own_dir, ' '); 576 if (end) 577 *end = '\0'; 578 } else { 579 own_dir = os_strdup("/tmp"); 580 if (own_dir == NULL) 581 return -1; 582 } 583 584 if (param == NULL) 585 pos = NULL; 586 else 587 pos = os_strstr(param, "priv_dir="); 588 if (pos) { 589 char *end; 590 priv_dir = os_strdup(pos + 9); 591 if (priv_dir == NULL) { 592 os_free(own_dir); 593 return -1; 594 } 595 end = os_strchr(priv_dir, ' '); 596 if (end) 597 *end = '\0'; 598 } else { 599 priv_dir = os_strdup("/var/run/wpa_priv"); 600 if (priv_dir == NULL) { 601 os_free(own_dir); 602 return -1; 603 } 604 } 605 606 len = os_strlen(own_dir) + 50; 607 drv->own_socket_path = os_malloc(len); 608 if (drv->own_socket_path == NULL) { 609 os_free(priv_dir); 610 os_free(own_dir); 611 return -1; 612 } 613 os_snprintf(drv->own_socket_path, len, "%s/wpa_privsep-%d-%d", 614 own_dir, getpid(), counter++); 615 616 len = os_strlen(own_dir) + 50; 617 drv->own_cmd_path = os_malloc(len); 618 if (drv->own_cmd_path == NULL) { 619 os_free(drv->own_socket_path); 620 drv->own_socket_path = NULL; 621 os_free(priv_dir); 622 os_free(own_dir); 623 return -1; 624 } 625 os_snprintf(drv->own_cmd_path, len, "%s/wpa_privsep-%d-%d", 626 own_dir, getpid(), counter++); 627 628 os_free(own_dir); 629 630 drv->priv_addr.sun_family = AF_UNIX; 631 os_snprintf(drv->priv_addr.sun_path, sizeof(drv->priv_addr.sun_path), 632 "%s/%s", priv_dir, drv->ifname); 633 os_free(priv_dir); 634 635 drv->priv_socket = socket(PF_UNIX, SOCK_DGRAM, 0); 636 if (drv->priv_socket < 0) { 637 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno)); 638 os_free(drv->own_socket_path); 639 drv->own_socket_path = NULL; 640 return -1; 641 } 642 643 os_memset(&addr, 0, sizeof(addr)); 644 addr.sun_family = AF_UNIX; 645 os_strlcpy(addr.sun_path, drv->own_socket_path, sizeof(addr.sun_path)); 646 if (bind(drv->priv_socket, (struct sockaddr *) &addr, sizeof(addr)) < 647 0) { 648 wpa_printf(MSG_ERROR, 649 "privsep-set-params priv-sock: bind(PF_UNIX): %s", 650 strerror(errno)); 651 close(drv->priv_socket); 652 drv->priv_socket = -1; 653 unlink(drv->own_socket_path); 654 os_free(drv->own_socket_path); 655 drv->own_socket_path = NULL; 656 return -1; 657 } 658 659 eloop_register_read_sock(drv->priv_socket, wpa_driver_privsep_receive, 660 drv, NULL); 661 662 drv->cmd_socket = socket(PF_UNIX, SOCK_DGRAM, 0); 663 if (drv->cmd_socket < 0) { 664 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno)); 665 os_free(drv->own_cmd_path); 666 drv->own_cmd_path = NULL; 667 return -1; 668 } 669 670 os_memset(&addr, 0, sizeof(addr)); 671 addr.sun_family = AF_UNIX; 672 os_strlcpy(addr.sun_path, drv->own_cmd_path, sizeof(addr.sun_path)); 673 if (bind(drv->cmd_socket, (struct sockaddr *) &addr, sizeof(addr)) < 0) 674 { 675 wpa_printf(MSG_ERROR, 676 "privsep-set-params cmd-sock: bind(PF_UNIX): %s", 677 strerror(errno)); 678 close(drv->cmd_socket); 679 drv->cmd_socket = -1; 680 unlink(drv->own_cmd_path); 681 os_free(drv->own_cmd_path); 682 drv->own_cmd_path = NULL; 683 return -1; 684 } 685 686 if (wpa_priv_reg_cmd(drv, PRIVSEP_CMD_REGISTER) < 0) { 687 wpa_printf(MSG_ERROR, "Failed to register with wpa_priv"); 688 return -1; 689 } 690 691 return 0; 692} 693 694 695static int wpa_driver_privsep_get_capa(void *priv, 696 struct wpa_driver_capa *capa) 697{ 698 struct wpa_driver_privsep_data *drv = priv; 699 int res; 700 size_t len = sizeof(*capa); 701 702 res = wpa_priv_cmd(drv, PRIVSEP_CMD_GET_CAPA, NULL, 0, capa, &len); 703 if (res < 0 || len != sizeof(*capa)) 704 return -1; 705 return 0; 706} 707 708 709static const u8 * wpa_driver_privsep_get_mac_addr(void *priv) 710{ 711 struct wpa_driver_privsep_data *drv = priv; 712 wpa_printf(MSG_DEBUG, "%s", __func__); 713 return drv->own_addr; 714} 715 716 717static int wpa_driver_privsep_set_country(void *priv, const char *alpha2) 718{ 719 struct wpa_driver_privsep_data *drv = priv; 720 wpa_printf(MSG_DEBUG, "%s country='%s'", __func__, alpha2); 721 return wpa_priv_cmd(drv, PRIVSEP_CMD_SET_COUNTRY, alpha2, 722 os_strlen(alpha2), NULL, NULL); 723} 724 725 726struct wpa_driver_ops wpa_driver_privsep_ops = { 727 "privsep", 728 "wpa_supplicant privilege separated driver", 729 .get_bssid = wpa_driver_privsep_get_bssid, 730 .get_ssid = wpa_driver_privsep_get_ssid, 731 .set_key = wpa_driver_privsep_set_key, 732 .init = wpa_driver_privsep_init, 733 .deinit = wpa_driver_privsep_deinit, 734 .set_param = wpa_driver_privsep_set_param, 735 .scan2 = wpa_driver_privsep_scan, 736 .deauthenticate = wpa_driver_privsep_deauthenticate, 737 .associate = wpa_driver_privsep_associate, 738 .get_capa = wpa_driver_privsep_get_capa, 739 .get_mac_addr = wpa_driver_privsep_get_mac_addr, 740 .get_scan_results2 = wpa_driver_privsep_get_scan_results2, 741 .set_country = wpa_driver_privsep_set_country, 742}; 743 744 745struct wpa_driver_ops *wpa_drivers[] = 746{ 747 &wpa_driver_privsep_ops, 748 NULL 749}; 750