driver_bsd.c (214501) | driver_bsd.c (252190) |
---|---|
1/* 2 * WPA Supplicant - driver interaction with BSD net80211 layer 3 * Copyright (c) 2004, Sam Leffler <sam@errno.com> 4 * Copyright (c) 2004, 2Wire, Inc 5 * | 1/* 2 * WPA Supplicant - driver interaction with BSD net80211 layer 3 * Copyright (c) 2004, Sam Leffler <sam@errno.com> 4 * Copyright (c) 2004, 2Wire, Inc 5 * |
6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 * 10 * Alternatively, this software may be distributed under the terms of BSD 11 * license. 12 * 13 * See README and COPYING for more details. | 6 * This software may be distributed under the terms of the BSD license. 7 * See README for more details. |
14 */ 15 16#include "includes.h" 17#include <sys/ioctl.h> | 8 */ 9 10#include "includes.h" 11#include <sys/ioctl.h> |
12#include <sys/sysctl.h> |
|
18 19#include "common.h" 20#include "driver.h" 21#include "eloop.h" 22#include "common/ieee802_11_defs.h" | 13 14#include "common.h" 15#include "driver.h" 16#include "eloop.h" 17#include "common/ieee802_11_defs.h" |
18#include "common/wpa_common.h" |
|
23 24#include <net/if.h> 25#include <net/if_media.h> 26 27#ifdef __NetBSD__ 28#include <net/if_ether.h> 29#else 30#include <net/ethernet.h> --- 259 unchanged lines hidden (view full) --- 290 struct ieee80211req_key wk; 291 292 wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%p key_idx=%d set_tx=%d " 293 "seq_len=%zu key_len=%zu", __func__, alg, addr, key_idx, 294 set_tx, seq_len, key_len); 295 296 if (alg == WPA_ALG_NONE) { 297#ifndef HOSTAPD | 19 20#include <net/if.h> 21#include <net/if_media.h> 22 23#ifdef __NetBSD__ 24#include <net/if_ether.h> 25#else 26#include <net/ethernet.h> --- 259 unchanged lines hidden (view full) --- 286 struct ieee80211req_key wk; 287 288 wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%p key_idx=%d set_tx=%d " 289 "seq_len=%zu key_len=%zu", __func__, alg, addr, key_idx, 290 set_tx, seq_len, key_len); 291 292 if (alg == WPA_ALG_NONE) { 293#ifndef HOSTAPD |
298 if (addr == NULL || 299 os_memcmp(addr, "\xff\xff\xff\xff\xff\xff", 300 IEEE80211_ADDR_LEN) == 0) | 294 if (addr == NULL || is_broadcast_ether_addr(addr)) |
301 return bsd_del_key(priv, NULL, key_idx); 302 else 303#endif /* HOSTAPD */ 304 return bsd_del_key(priv, addr, key_idx); 305 } 306 307 os_memset(&wk, 0, sizeof(wk)); 308 switch (alg) { --- 20 unchanged lines hidden (view full) --- 329 wk.ik_keyix = key_idx; 330 } else { 331 os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); 332 /* 333 * Deduce whether group/global or unicast key by checking 334 * the address (yech). Note also that we can only mark global 335 * keys default; doing this for a unicast key is an error. 336 */ | 295 return bsd_del_key(priv, NULL, key_idx); 296 else 297#endif /* HOSTAPD */ 298 return bsd_del_key(priv, addr, key_idx); 299 } 300 301 os_memset(&wk, 0, sizeof(wk)); 302 switch (alg) { --- 20 unchanged lines hidden (view full) --- 323 wk.ik_keyix = key_idx; 324 } else { 325 os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); 326 /* 327 * Deduce whether group/global or unicast key by checking 328 * the address (yech). Note also that we can only mark global 329 * keys default; doing this for a unicast key is an error. 330 */ |
337 if (os_memcmp(addr, "\xff\xff\xff\xff\xff\xff", 338 IEEE80211_ADDR_LEN) == 0) { | 331 if (is_broadcast_ether_addr(addr)) { |
339 wk.ik_flags |= IEEE80211_KEY_GROUP; 340 wk.ik_keyix = key_idx; 341 } else { 342 wk.ik_keyix = key_idx == 0 ? IEEE80211_KEYIX_NONE : 343 key_idx; 344 } 345 } 346 if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx) 347 wk.ik_flags |= IEEE80211_KEY_DEFAULT; 348 wk.ik_keylen = key_len; | 332 wk.ik_flags |= IEEE80211_KEY_GROUP; 333 wk.ik_keyix = key_idx; 334 } else { 335 wk.ik_keyix = key_idx == 0 ? IEEE80211_KEYIX_NONE : 336 key_idx; 337 } 338 } 339 if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx) 340 wk.ik_flags |= IEEE80211_KEY_DEFAULT; 341 wk.ik_keylen = key_len; |
349 os_memcpy(&wk.ik_keyrsc, seq, seq_len); | 342 if (seq) { 343#ifdef WORDS_BIGENDIAN 344 /* 345 * wk.ik_keyrsc is in host byte order (big endian), need to 346 * swap it to match with the byte order used in WPA. 347 */ 348 int i; 349 u8 *keyrsc = (u8 *) &wk.ik_keyrsc; 350 for (i = 0; i < seq_len; i++) 351 keyrsc[WPA_KEY_RSC_LEN - i - 1] = seq[i]; 352#else /* WORDS_BIGENDIAN */ 353 os_memcpy(&wk.ik_keyrsc, seq, seq_len); 354#endif /* WORDS_BIGENDIAN */ 355 } |
350 os_memcpy(wk.ik_keydata, key, key_len); 351 352 return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)); 353} 354 355static int 356bsd_configure_wpa(void *priv, struct wpa_bss_params *params) 357{ --- 148 unchanged lines hidden (view full) --- 506 iebuf = ie.wpa_ie; 507 ielen = ie.wpa_ie[1]; 508 if (ielen == 0) 509 iebuf = NULL; 510 else 511 ielen += 2; 512 513no_ie: | 356 os_memcpy(wk.ik_keydata, key, key_len); 357 358 return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)); 359} 360 361static int 362bsd_configure_wpa(void *priv, struct wpa_bss_params *params) 363{ --- 148 unchanged lines hidden (view full) --- 512 iebuf = ie.wpa_ie; 513 ielen = ie.wpa_ie[1]; 514 if (ielen == 0) 515 iebuf = NULL; 516 else 517 ielen += 2; 518 519no_ie: |
514 drv_event_assoc(ctx, addr, iebuf, ielen); | 520 drv_event_assoc(ctx, addr, iebuf, ielen, 0); |
515} 516 517static int 518bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len, | 521} 522 523static int 524bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len, |
519 int encrypt, const u8 *own_addr) | 525 int encrypt, const u8 *own_addr, u32 flags) |
520{ 521 struct bsd_driver_data *drv = priv; 522 523 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", data, data_len); 524 525 return l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, data, 526 data_len); 527} 528 529static int | 526{ 527 struct bsd_driver_data *drv = priv; 528 529 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", data, data_len); 530 531 return l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, data, 532 data_len); 533} 534 535static int |
530bsd_set_freq(void *priv, u16 channel) | 536bsd_set_freq(void *priv, struct hostapd_freq_params *freq) |
531{ 532 struct bsd_driver_data *drv = priv; 533#ifdef SIOCS80211CHANNEL 534 struct ieee80211chanreq creq; 535#endif /* SIOCS80211CHANNEL */ 536 u32 mode; | 537{ 538 struct bsd_driver_data *drv = priv; 539#ifdef SIOCS80211CHANNEL 540 struct ieee80211chanreq creq; 541#endif /* SIOCS80211CHANNEL */ 542 u32 mode; |
543 int channel = freq->channel; |
|
537 | 544 |
538 if (channel < 14) 539 mode = IFM_IEEE80211_11G; 540 else if (channel == 14) | 545 if (channel < 14) { 546 mode = 547#ifdef CONFIG_IEEE80211N 548 freq->ht_enabled ? IFM_IEEE80211_11NG : 549#endif /* CONFIG_IEEE80211N */ 550 IFM_IEEE80211_11G; 551 } else if (channel == 14) { |
541 mode = IFM_IEEE80211_11B; | 552 mode = IFM_IEEE80211_11B; |
542 else 543 mode = IFM_IEEE80211_11A; | 553 } else { 554 mode = 555#ifdef CONFIG_IEEE80211N 556 freq->ht_enabled ? IFM_IEEE80211_11NA : 557#endif /* CONFIG_IEEE80211N */ 558 IFM_IEEE80211_11A; 559 } |
544 if (bsd_set_mediaopt(drv, IFM_MMASK, mode) < 0) { 545 wpa_printf(MSG_ERROR, "%s: failed to set modulation mode", 546 __func__); 547 return -1; 548 } 549 550#ifdef SIOCS80211CHANNEL 551 os_memset(&creq, 0, sizeof(creq)); 552 os_strlcpy(creq.i_name, drv->ifname, sizeof(creq.i_name)); | 560 if (bsd_set_mediaopt(drv, IFM_MMASK, mode) < 0) { 561 wpa_printf(MSG_ERROR, "%s: failed to set modulation mode", 562 __func__); 563 return -1; 564 } 565 566#ifdef SIOCS80211CHANNEL 567 os_memset(&creq, 0, sizeof(creq)); 568 os_strlcpy(creq.i_name, drv->ifname, sizeof(creq.i_name)); |
553 creq.i_channel = channel; | 569 creq.i_channel = (u_int16_t)channel; |
554 return ioctl(drv->sock, SIOCS80211CHANNEL, &creq); 555#else /* SIOCS80211CHANNEL */ 556 return set80211param(priv, IEEE80211_IOC_CHANNEL, channel); 557#endif /* SIOCS80211CHANNEL */ 558} 559 560static int 561bsd_set_opt_ie(void *priv, const u8 *ie, size_t ie_len) 562{ 563#ifdef IEEE80211_IOC_APPIE 564 wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %lu)", __func__, 565 (unsigned long)ie_len); 566 return bsd_set80211(priv, IEEE80211_IOC_APPIE, IEEE80211_APPIE_WPA, 567 ie, ie_len); 568#endif /* IEEE80211_IOC_APPIE */ 569 return 0; 570} 571 | 570 return ioctl(drv->sock, SIOCS80211CHANNEL, &creq); 571#else /* SIOCS80211CHANNEL */ 572 return set80211param(priv, IEEE80211_IOC_CHANNEL, channel); 573#endif /* SIOCS80211CHANNEL */ 574} 575 576static int 577bsd_set_opt_ie(void *priv, const u8 *ie, size_t ie_len) 578{ 579#ifdef IEEE80211_IOC_APPIE 580 wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %lu)", __func__, 581 (unsigned long)ie_len); 582 return bsd_set80211(priv, IEEE80211_IOC_APPIE, IEEE80211_APPIE_WPA, 583 ie, ie_len); 584#endif /* IEEE80211_IOC_APPIE */ 585 return 0; 586} 587 |
588static int 589rtbuf_len(void) 590{ 591 size_t len; |
|
572 | 592 |
593 int mib[6] = {CTL_NET, AF_ROUTE, 0, AF_INET, NET_RT_DUMP, 0}; 594 595 if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { 596 wpa_printf(MSG_WARNING, "%s failed: %s\n", __func__, 597 strerror(errno)); 598 len = 2048; 599 } 600 601 return len; 602} 603 |
|
573#ifdef HOSTAPD 574 575/* 576 * Avoid conflicts with hostapd definitions by undefining couple of defines 577 * from net80211 header files. 578 */ 579#undef RSN_VERSION 580#undef WPA_VERSION --- 105 unchanged lines hidden (view full) --- 686 return bsd_send_mlme_param(priv, IEEE80211_MLME_DISASSOC, reason_code, 687 addr); 688} 689 690static void 691bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx) 692{ 693 struct bsd_driver_data *drv = ctx; | 604#ifdef HOSTAPD 605 606/* 607 * Avoid conflicts with hostapd definitions by undefining couple of defines 608 * from net80211 header files. 609 */ 610#undef RSN_VERSION 611#undef WPA_VERSION --- 105 unchanged lines hidden (view full) --- 717 return bsd_send_mlme_param(priv, IEEE80211_MLME_DISASSOC, reason_code, 718 addr); 719} 720 721static void 722bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx) 723{ 724 struct bsd_driver_data *drv = ctx; |
694 char buf[2048]; | 725 char *buf; |
695 struct if_announcemsghdr *ifan; 696 struct rt_msghdr *rtm; 697 struct ieee80211_michael_event *mic; 698 struct ieee80211_join_event *join; 699 struct ieee80211_leave_event *leave; | 726 struct if_announcemsghdr *ifan; 727 struct rt_msghdr *rtm; 728 struct ieee80211_michael_event *mic; 729 struct ieee80211_join_event *join; 730 struct ieee80211_leave_event *leave; |
700 int n; | 731 int n, len; |
701 union wpa_event_data data; 702 | 732 union wpa_event_data data; 733 |
703 n = read(sock, buf, sizeof(buf)); | 734 len = rtbuf_len(); 735 736 buf = os_malloc(len); 737 if (buf == NULL) { 738 wpa_printf(MSG_ERROR, "%s os_malloc() failed\n", __func__); 739 return; 740 } 741 742 n = read(sock, buf, len); |
704 if (n < 0) { 705 if (errno != EINTR && errno != EAGAIN) | 743 if (n < 0) { 744 if (errno != EINTR && errno != EAGAIN) |
706 perror("read(PF_ROUTE)"); | 745 wpa_printf(MSG_ERROR, "%s read() failed: %s\n", 746 __func__, strerror(errno)); 747 os_free(buf); |
707 return; 708 } 709 710 rtm = (struct rt_msghdr *) buf; 711 if (rtm->rtm_version != RTM_VERSION) { | 748 return; 749 } 750 751 rtm = (struct rt_msghdr *) buf; 752 if (rtm->rtm_version != RTM_VERSION) { |
712 wpa_printf(MSG_DEBUG, "Routing message version %d not " 713 "understood\n", rtm->rtm_version); | 753 wpa_printf(MSG_DEBUG, "Invalid routing message version=%d", 754 rtm->rtm_version); 755 os_free(buf); |
714 return; 715 } 716 ifan = (struct if_announcemsghdr *) rtm; 717 switch (rtm->rtm_type) { 718 case RTM_IEEE80211: 719 switch (ifan->ifan_what) { 720 case RTM_IEEE80211_ASSOC: 721 case RTM_IEEE80211_REASSOC: --- 24 unchanged lines hidden (view full) --- 746 data.michael_mic_failure.unicast = 1; 747 data.michael_mic_failure.src = mic->iev_src; 748 wpa_supplicant_event(drv->hapd, 749 EVENT_MICHAEL_MIC_FAILURE, &data); 750 break; 751 } 752 break; 753 } | 756 return; 757 } 758 ifan = (struct if_announcemsghdr *) rtm; 759 switch (rtm->rtm_type) { 760 case RTM_IEEE80211: 761 switch (ifan->ifan_what) { 762 case RTM_IEEE80211_ASSOC: 763 case RTM_IEEE80211_REASSOC: --- 24 unchanged lines hidden (view full) --- 788 data.michael_mic_failure.unicast = 1; 789 data.michael_mic_failure.src = mic->iev_src; 790 wpa_supplicant_event(drv->hapd, 791 EVENT_MICHAEL_MIC_FAILURE, &data); 792 break; 793 } 794 break; 795 } |
796 os_free(buf); |
|
754} 755 756static void 757handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) 758{ 759 struct bsd_driver_data *drv = ctx; 760 drv_event_eapol_rx(drv->hapd, src_addr, buf, len); 761} 762 | 797} 798 799static void 800handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) 801{ 802 struct bsd_driver_data *drv = ctx; 803 drv_event_eapol_rx(drv->hapd, src_addr, buf, len); 804} 805 |
763static int 764hostapd_bsd_set_freq(void *priv, struct hostapd_freq_params *freq) 765{ 766 return bsd_set_freq(priv, freq->channel); 767} 768 | |
769static void * 770bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params) 771{ 772 struct bsd_driver_data *drv; 773 774 drv = os_zalloc(sizeof(struct bsd_driver_data)); 775 if (drv == NULL) { 776 printf("Could not allocate memory for bsd driver data\n"); --- 154 unchanged lines hidden (view full) --- 931static int 932wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code) 933{ 934 return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code, 935 addr); 936} 937 938static int | 806static void * 807bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params) 808{ 809 struct bsd_driver_data *drv; 810 811 drv = os_zalloc(sizeof(struct bsd_driver_data)); 812 if (drv == NULL) { 813 printf("Could not allocate memory for bsd driver data\n"); --- 154 unchanged lines hidden (view full) --- 968static int 969wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code) 970{ 971 return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code, 972 addr); 973} 974 975static int |
939wpa_driver_bsd_disassociate(void *priv, const u8 *addr, int reason_code) 940{ 941 return bsd_send_mlme_param(priv, IEEE80211_MLME_DISASSOC, reason_code, 942 addr); 943} 944 945static int | |
946wpa_driver_bsd_set_auth_alg(void *priv, int auth_alg) 947{ 948 int authmode; 949 950 if ((auth_alg & WPA_AUTH_ALG_OPEN) && 951 (auth_alg & WPA_AUTH_ALG_SHARED)) 952 authmode = IEEE80211_AUTH_AUTO; 953 else if (auth_alg & WPA_AUTH_ALG_SHARED) --- 13 unchanged lines hidden (view full) --- 967} 968 969static int 970wpa_driver_bsd_associate(void *priv, struct wpa_driver_associate_params *params) 971{ 972 struct bsd_driver_data *drv = priv; 973 struct ieee80211req_mlme mlme; 974 u32 mode; | 976wpa_driver_bsd_set_auth_alg(void *priv, int auth_alg) 977{ 978 int authmode; 979 980 if ((auth_alg & WPA_AUTH_ALG_OPEN) && 981 (auth_alg & WPA_AUTH_ALG_SHARED)) 982 authmode = IEEE80211_AUTH_AUTO; 983 else if (auth_alg & WPA_AUTH_ALG_SHARED) --- 13 unchanged lines hidden (view full) --- 997} 998 999static int 1000wpa_driver_bsd_associate(void *priv, struct wpa_driver_associate_params *params) 1001{ 1002 struct bsd_driver_data *drv = priv; 1003 struct ieee80211req_mlme mlme; 1004 u32 mode; |
975 u16 channel; | |
976 int privacy; 977 int ret = 0; 978 979 wpa_printf(MSG_DEBUG, 980 "%s: ssid '%.*s' wpa ie len %u pairwise %u group %u key mgmt %u" 981 , __func__ 982 , (unsigned int) params->ssid_len, params->ssid 983 , (unsigned int) params->wpa_ie_len --- 18 unchanged lines hidden (view full) --- 1002 } 1003 if (bsd_set_mediaopt(drv, IFM_OMASK, mode) < 0) { 1004 wpa_printf(MSG_ERROR, "%s: failed to set operation mode", 1005 __func__); 1006 return -1; 1007 } 1008 1009 if (params->mode == IEEE80211_MODE_AP) { | 1005 int privacy; 1006 int ret = 0; 1007 1008 wpa_printf(MSG_DEBUG, 1009 "%s: ssid '%.*s' wpa ie len %u pairwise %u group %u key mgmt %u" 1010 , __func__ 1011 , (unsigned int) params->ssid_len, params->ssid 1012 , (unsigned int) params->wpa_ie_len --- 18 unchanged lines hidden (view full) --- 1031 } 1032 if (bsd_set_mediaopt(drv, IFM_OMASK, mode) < 0) { 1033 wpa_printf(MSG_ERROR, "%s: failed to set operation mode", 1034 __func__); 1035 return -1; 1036 } 1037 1038 if (params->mode == IEEE80211_MODE_AP) { |
1010 if (params->freq >= 2412 && params->freq <= 2472) 1011 channel = (params->freq - 2407) / 5; 1012 else if (params->freq == 2484) 1013 channel = 14; 1014 else if ((params->freq >= 5180 && params->freq <= 5240) || 1015 (params->freq >= 5745 && params->freq <= 5825)) 1016 channel = (params->freq - 5000) / 5; 1017 else 1018 channel = 0; 1019 if (bsd_set_freq(drv, channel) < 0) 1020 return -1; 1021 | |
1022 drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL, 1023 handle_read, drv, 0); 1024 if (drv->sock_xmit == NULL) 1025 return -1; 1026 drv->is_ap = 1; 1027 return 0; 1028 } 1029 --- 99 unchanged lines hidden (view full) --- 1129 return set80211param(drv, IEEE80211_IOC_SCAN_REQ, 0); 1130#endif /* IEEE80211_IOC_SCAN_MAX_SSID */ 1131} 1132 1133static void 1134wpa_driver_bsd_event_receive(int sock, void *ctx, void *sock_ctx) 1135{ 1136 struct bsd_driver_data *drv = sock_ctx; | 1039 drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL, 1040 handle_read, drv, 0); 1041 if (drv->sock_xmit == NULL) 1042 return -1; 1043 drv->is_ap = 1; 1044 return 0; 1045 } 1046 --- 99 unchanged lines hidden (view full) --- 1146 return set80211param(drv, IEEE80211_IOC_SCAN_REQ, 0); 1147#endif /* IEEE80211_IOC_SCAN_MAX_SSID */ 1148} 1149 1150static void 1151wpa_driver_bsd_event_receive(int sock, void *ctx, void *sock_ctx) 1152{ 1153 struct bsd_driver_data *drv = sock_ctx; |
1137 char buf[2048]; | 1154 char *buf; |
1138 struct if_announcemsghdr *ifan; 1139 struct if_msghdr *ifm; 1140 struct rt_msghdr *rtm; 1141 union wpa_event_data event; 1142 struct ieee80211_michael_event *mic; 1143 struct ieee80211_leave_event *leave; 1144 struct ieee80211_join_event *join; | 1155 struct if_announcemsghdr *ifan; 1156 struct if_msghdr *ifm; 1157 struct rt_msghdr *rtm; 1158 union wpa_event_data event; 1159 struct ieee80211_michael_event *mic; 1160 struct ieee80211_leave_event *leave; 1161 struct ieee80211_join_event *join; |
1145 int n; | 1162 int n, len; |
1146 | 1163 |
1147 n = read(sock, buf, sizeof(buf)); | 1164 len = rtbuf_len(); 1165 1166 buf = os_malloc(len); 1167 if (buf == NULL) { 1168 wpa_printf(MSG_ERROR, "%s os_malloc() failed\n", __func__); 1169 return; 1170 } 1171 1172 n = read(sock, buf, len); |
1148 if (n < 0) { 1149 if (errno != EINTR && errno != EAGAIN) | 1173 if (n < 0) { 1174 if (errno != EINTR && errno != EAGAIN) |
1150 perror("read(PF_ROUTE)"); | 1175 wpa_printf(MSG_ERROR, "%s read() failed: %s\n", 1176 __func__, strerror(errno)); 1177 os_free(buf); |
1151 return; 1152 } 1153 1154 rtm = (struct rt_msghdr *) buf; 1155 if (rtm->rtm_version != RTM_VERSION) { | 1178 return; 1179 } 1180 1181 rtm = (struct rt_msghdr *) buf; 1182 if (rtm->rtm_version != RTM_VERSION) { |
1156 wpa_printf(MSG_DEBUG, "Routing message version %d not " 1157 "understood\n", rtm->rtm_version); | 1183 wpa_printf(MSG_DEBUG, "Invalid routing message version=%d", 1184 rtm->rtm_version); 1185 os_free(buf); |
1158 return; 1159 } 1160 os_memset(&event, 0, sizeof(event)); 1161 switch (rtm->rtm_type) { 1162 case RTM_IFANNOUNCE: 1163 ifan = (struct if_announcemsghdr *) rtm; 1164 if (ifan->ifan_index != drv->ifindex) 1165 break; 1166 os_strlcpy(event.interface_status.ifname, drv->ifname, 1167 sizeof(event.interface_status.ifname)); 1168 switch (ifan->ifan_what) { 1169 case IFAN_DEPARTURE: 1170 event.interface_status.ievent = EVENT_INTERFACE_REMOVED; 1171 default: | 1186 return; 1187 } 1188 os_memset(&event, 0, sizeof(event)); 1189 switch (rtm->rtm_type) { 1190 case RTM_IFANNOUNCE: 1191 ifan = (struct if_announcemsghdr *) rtm; 1192 if (ifan->ifan_index != drv->ifindex) 1193 break; 1194 os_strlcpy(event.interface_status.ifname, drv->ifname, 1195 sizeof(event.interface_status.ifname)); 1196 switch (ifan->ifan_what) { 1197 case IFAN_DEPARTURE: 1198 event.interface_status.ievent = EVENT_INTERFACE_REMOVED; 1199 default: |
1200 os_free(buf); |
|
1172 return; 1173 } 1174 wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: Interface '%s' %s", 1175 event.interface_status.ifname, 1176 ifan->ifan_what == IFAN_DEPARTURE ? 1177 "removed" : "added"); 1178 wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event); 1179 break; --- 56 unchanged lines hidden (view full) --- 1236 sizeof(event.interface_status.ifname)); 1237 event.interface_status.ievent = EVENT_INTERFACE_REMOVED; 1238 wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' DOWN", 1239 event.interface_status.ifname); 1240 wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event); 1241 } 1242 break; 1243 } | 1201 return; 1202 } 1203 wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: Interface '%s' %s", 1204 event.interface_status.ifname, 1205 ifan->ifan_what == IFAN_DEPARTURE ? 1206 "removed" : "added"); 1207 wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event); 1208 break; --- 56 unchanged lines hidden (view full) --- 1265 sizeof(event.interface_status.ifname)); 1266 event.interface_status.ievent = EVENT_INTERFACE_REMOVED; 1267 wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' DOWN", 1268 event.interface_status.ifname); 1269 wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event); 1270 } 1271 break; 1272 } |
1273 os_free(buf); |
|
1244} 1245 1246static void 1247wpa_driver_bsd_add_scan_entry(struct wpa_scan_results *res, 1248 struct ieee80211req_scan_result *sr) 1249{ 1250 struct wpa_scan_res *result, **tmp; 1251 size_t extra_len; --- 34 unchanged lines hidden (view full) --- 1286 *pos++ = 1; 1287 *pos++ = sr->isr_erp; 1288 1289 os_memcpy(pos, (u8 *)(sr + 1) + sr->isr_ssid_len, sr->isr_ie_len); 1290 pos += sr->isr_ie_len; 1291 1292 result->ie_len = pos - (u8 *)(result + 1); 1293 | 1274} 1275 1276static void 1277wpa_driver_bsd_add_scan_entry(struct wpa_scan_results *res, 1278 struct ieee80211req_scan_result *sr) 1279{ 1280 struct wpa_scan_res *result, **tmp; 1281 size_t extra_len; --- 34 unchanged lines hidden (view full) --- 1316 *pos++ = 1; 1317 *pos++ = sr->isr_erp; 1318 1319 os_memcpy(pos, (u8 *)(sr + 1) + sr->isr_ssid_len, sr->isr_ie_len); 1320 pos += sr->isr_ie_len; 1321 1322 result->ie_len = pos - (u8 *)(result + 1); 1323 |
1294 tmp = os_realloc(res->res, 1295 (res->num + 1) * sizeof(struct wpa_scan_res *)); | 1324 tmp = os_realloc_array(res->res, res->num + 1, 1325 sizeof(struct wpa_scan_res *)); |
1296 if (tmp == NULL) { 1297 os_free(result); 1298 return; 1299 } 1300 tmp[res->num++] = result; 1301 res->res = tmp; 1302} 1303 --- 209 unchanged lines hidden (view full) --- 1513 .hapd_init = bsd_init, 1514 .hapd_deinit = bsd_deinit, 1515 .set_privacy = bsd_set_privacy, 1516 .get_seqnum = bsd_get_seqnum, 1517 .flush = bsd_flush, 1518 .read_sta_data = bsd_read_sta_driver_data, 1519 .sta_disassoc = bsd_sta_disassoc, 1520 .sta_deauth = bsd_sta_deauth, | 1326 if (tmp == NULL) { 1327 os_free(result); 1328 return; 1329 } 1330 tmp[res->num++] = result; 1331 res->res = tmp; 1332} 1333 --- 209 unchanged lines hidden (view full) --- 1543 .hapd_init = bsd_init, 1544 .hapd_deinit = bsd_deinit, 1545 .set_privacy = bsd_set_privacy, 1546 .get_seqnum = bsd_get_seqnum, 1547 .flush = bsd_flush, 1548 .read_sta_data = bsd_read_sta_driver_data, 1549 .sta_disassoc = bsd_sta_disassoc, 1550 .sta_deauth = bsd_sta_deauth, |
1521 .set_freq = hostapd_bsd_set_freq, | |
1522#else /* HOSTAPD */ 1523 .init = wpa_driver_bsd_init, 1524 .deinit = wpa_driver_bsd_deinit, 1525 .get_bssid = wpa_driver_bsd_get_bssid, 1526 .get_ssid = wpa_driver_bsd_get_ssid, 1527 .set_countermeasures = wpa_driver_bsd_set_countermeasures, 1528 .scan2 = wpa_driver_bsd_scan, 1529 .get_scan_results2 = wpa_driver_bsd_get_scan_results2, 1530 .deauthenticate = wpa_driver_bsd_deauthenticate, | 1551#else /* HOSTAPD */ 1552 .init = wpa_driver_bsd_init, 1553 .deinit = wpa_driver_bsd_deinit, 1554 .get_bssid = wpa_driver_bsd_get_bssid, 1555 .get_ssid = wpa_driver_bsd_get_ssid, 1556 .set_countermeasures = wpa_driver_bsd_set_countermeasures, 1557 .scan2 = wpa_driver_bsd_scan, 1558 .get_scan_results2 = wpa_driver_bsd_get_scan_results2, 1559 .deauthenticate = wpa_driver_bsd_deauthenticate, |
1531 .disassociate = wpa_driver_bsd_disassociate, | |
1532 .associate = wpa_driver_bsd_associate, 1533 .get_capa = wpa_driver_bsd_get_capa, 1534#endif /* HOSTAPD */ | 1560 .associate = wpa_driver_bsd_associate, 1561 .get_capa = wpa_driver_bsd_get_capa, 1562#endif /* HOSTAPD */ |
1563 .set_freq = bsd_set_freq, |
|
1535 .set_key = bsd_set_key, 1536 .set_ieee8021x = bsd_set_ieee8021x, 1537 .hapd_set_ssid = bsd_set_ssid, 1538 .hapd_get_ssid = bsd_get_ssid, 1539 .hapd_send_eapol = bsd_send_eapol, 1540 .sta_set_flags = bsd_set_sta_authorized, 1541 .set_generic_elem = bsd_set_opt_ie, 1542}; | 1564 .set_key = bsd_set_key, 1565 .set_ieee8021x = bsd_set_ieee8021x, 1566 .hapd_set_ssid = bsd_set_ssid, 1567 .hapd_get_ssid = bsd_get_ssid, 1568 .hapd_send_eapol = bsd_send_eapol, 1569 .sta_set_flags = bsd_set_sta_authorized, 1570 .set_generic_elem = bsd_set_opt_ie, 1571}; |