static void ieee80211_status(prop_dictionary_t env, prop_dictionary_t oenv) { int i, nwkey_verbose; struct ieee80211_nwid nwid; struct ieee80211_nwkey nwkey; struct ieee80211_power power; u_int8_t keybuf[IEEE80211_WEP_NKID][16]; struct ieee80211_bssid bssid; struct ieee80211chanreq channel; struct ieee80211req ireq; struct ether_addr ea; static const u_int8_t zero_macaddr[IEEE80211_ADDR_LEN]; enum ieee80211_opmode opmode = get80211opmode(env); memset(&bssid, 0, sizeof(bssid)); memset(&nwkey, 0, sizeof(nwkey)); memset(&nwid, 0, sizeof(nwid)); memset(&nwid, 0, sizeof(nwid)); if (indirect_ioctl(env, SIOCG80211NWID, &nwid) == -1) return; if (nwid.i_len > IEEE80211_NWID_LEN) { errx(EXIT_FAILURE, "SIOCG80211NWID: wrong length of nwid (%d)", nwid.i_len); } printf("\tssid "); print_string(nwid.i_nwid, nwid.i_len); if (opmode == IEEE80211_M_HOSTAP) { ireq.i_type = IEEE80211_IOC_HIDESSID; if (direct_ioctl(env, SIOCG80211, &ireq) != -1) { if (ireq.i_val) printf(" [hidden]"); else if (vflag) printf(" [shown]"); } ireq.i_type = IEEE80211_IOC_APBRIDGE; if (direct_ioctl(env, SIOCG80211, &ireq) != -1) { if (ireq.i_val) printf(" apbridge"); else if (vflag) printf(" -apbridge"); } } ireq.i_type = IEEE80211_IOC_RTSTHRESHOLD; if (direct_ioctl(env, SIOCG80211, &ireq) == -1) ; else if (ireq.i_val < IEEE80211_RTS_MAX) printf(" rts %d", ireq.i_val); else if (vflag) printf(" -rts"); ireq.i_type = IEEE80211_IOC_FRAGTHRESHOLD; if (direct_ioctl(env, SIOCG80211, &ireq) == -1) ; else if (ireq.i_val < IEEE80211_FRAG_MAX) printf(" frag %d", ireq.i_val); else if (vflag) printf(" -frag"); memset(&nwkey, 0, sizeof(nwkey)); /* show nwkey only when WEP is enabled */ if (direct_ioctl(env, SIOCG80211NWKEY, &nwkey) == -1 || nwkey.i_wepon == 0) { printf("\n"); goto skip_wep; } printf(" nwkey "); /* try to retrieve WEP keys */ for (i = 0; i < IEEE80211_WEP_NKID; i++) { nwkey.i_key[i].i_keydat = keybuf[i]; nwkey.i_key[i].i_keylen = sizeof(keybuf[i]); } if (direct_ioctl(env, SIOCG80211NWKEY, &nwkey) == -1) { printf("*****"); } else { nwkey_verbose = 0; /* check to see non default key or multiple keys defined */ if (nwkey.i_defkid != 1) { nwkey_verbose = 1; } else { for (i = 1; i < IEEE80211_WEP_NKID; i++) { if (nwkey.i_key[i].i_keylen != 0) { nwkey_verbose = 1; break; } } } /* check extra ambiguity with keywords */ if (!nwkey_verbose) { if (nwkey.i_key[0].i_keylen >= 2 && isdigit(nwkey.i_key[0].i_keydat[0]) && nwkey.i_key[0].i_keydat[1] == ':') nwkey_verbose = 1; else if (nwkey.i_key[0].i_keylen >= 7 && strncasecmp("persist", (const char *)nwkey.i_key[0].i_keydat, 7) == 0) nwkey_verbose = 1; } if (nwkey_verbose) printf("%d:", nwkey.i_defkid); for (i = 0; i < IEEE80211_WEP_NKID; i++) { if (i > 0) printf(","); if (nwkey.i_key[i].i_keylen < 0) printf("persist"); else print_string(nwkey.i_key[i].i_keydat, nwkey.i_key[i].i_keylen); if (!nwkey_verbose) break; } } printf("\n"); skip_wep: if (direct_ioctl(env, SIOCG80211POWER, &power) == -1) goto skip_power; printf("\tpowersave "); if (power.i_enabled) printf("on (%dms sleep)", power.i_maxsleep); else printf("off"); printf("\n"); skip_power: if (direct_ioctl(env, SIOCG80211BSSID, &bssid) == -1) return; if (direct_ioctl(env, SIOCG80211CHANNEL, &channel) == -1) return; if (memcmp(bssid.i_bssid, zero_macaddr, IEEE80211_ADDR_LEN) == 0) { if (channel.i_channel != (u_int16_t)-1) printf("\tchan %d\n", channel.i_channel); } else { memcpy(ea.ether_addr_octet, bssid.i_bssid, sizeof(ea.ether_addr_octet)); printf("\tbssid %s", ether_ntoa(&ea)); if (channel.i_channel != IEEE80211_CHAN_ANY) printf(" chan %d", channel.i_channel); printf("\n"); } }
static void * wpa_driver_bsd_init(void *ctx, const char *ifname) { #define GETPARAM(drv, param, v) \ (((v) = get80211param(drv, param)) != -1) struct bsd_driver_data *drv; drv = os_zalloc(sizeof(*drv)); if (drv == NULL) return NULL; /* * NB: We require the interface name be mappable to an index. * This implies we do not support having wpa_supplicant * wait for an interface to appear. This seems ok; that * doesn't belong here; it's really the job of devd. */ drv->ifindex = if_nametoindex(ifname); if (drv->ifindex == 0) { wpa_printf(MSG_DEBUG, "%s: interface %s does not exist", __func__, ifname); goto fail1; } drv->sock = socket(PF_INET, SOCK_DGRAM, 0); if (drv->sock < 0) goto fail1; os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname)); /* Down interface during setup. */ if (bsd_ctrl_iface(drv, 0) < 0) goto fail; drv->route = socket(PF_ROUTE, SOCK_RAW, 0); if (drv->route < 0) goto fail; eloop_register_read_sock(drv->route, wpa_driver_bsd_event_receive, ctx, drv); drv->ctx = ctx; if (!GETPARAM(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming)) { wpa_printf(MSG_DEBUG, "%s: failed to get roaming state: %s", __func__, strerror(errno)); goto fail; } if (!GETPARAM(drv, IEEE80211_IOC_PRIVACY, drv->prev_privacy)) { wpa_printf(MSG_DEBUG, "%s: failed to get privacy state: %s", __func__, strerror(errno)); goto fail; } if (!GETPARAM(drv, IEEE80211_IOC_WPA, drv->prev_wpa)) { wpa_printf(MSG_DEBUG, "%s: failed to get wpa state: %s", __func__, strerror(errno)); goto fail; } if (wpa_driver_bsd_capa(drv)) goto fail; drv->opmode = get80211opmode(drv); return drv; fail: close(drv->sock); fail1: os_free(drv); return NULL; #undef GETPARAM }