1*e28a4053SRui Paulo /* 2*e28a4053SRui Paulo * Control interface for shared AP commands 3*e28a4053SRui Paulo * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi> 4*e28a4053SRui Paulo * 5*e28a4053SRui Paulo * This program is free software; you can redistribute it and/or modify 6*e28a4053SRui Paulo * it under the terms of the GNU General Public License version 2 as 7*e28a4053SRui Paulo * published by the Free Software Foundation. 8*e28a4053SRui Paulo * 9*e28a4053SRui Paulo * Alternatively, this software may be distributed under the terms of BSD 10*e28a4053SRui Paulo * license. 11*e28a4053SRui Paulo * 12*e28a4053SRui Paulo * See README and COPYING for more details. 13*e28a4053SRui Paulo */ 14*e28a4053SRui Paulo 15*e28a4053SRui Paulo #include "utils/includes.h" 16*e28a4053SRui Paulo 17*e28a4053SRui Paulo #include "utils/common.h" 18*e28a4053SRui Paulo #include "hostapd.h" 19*e28a4053SRui Paulo #include "ieee802_1x.h" 20*e28a4053SRui Paulo #include "wpa_auth.h" 21*e28a4053SRui Paulo #include "ieee802_11.h" 22*e28a4053SRui Paulo #include "sta_info.h" 23*e28a4053SRui Paulo #include "wps_hostapd.h" 24*e28a4053SRui Paulo #include "ctrl_iface_ap.h" 25*e28a4053SRui Paulo 26*e28a4053SRui Paulo 27*e28a4053SRui Paulo static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd, 28*e28a4053SRui Paulo struct sta_info *sta, 29*e28a4053SRui Paulo char *buf, size_t buflen) 30*e28a4053SRui Paulo { 31*e28a4053SRui Paulo int len, res, ret; 32*e28a4053SRui Paulo 33*e28a4053SRui Paulo if (sta == NULL) { 34*e28a4053SRui Paulo ret = os_snprintf(buf, buflen, "FAIL\n"); 35*e28a4053SRui Paulo if (ret < 0 || (size_t) ret >= buflen) 36*e28a4053SRui Paulo return 0; 37*e28a4053SRui Paulo return ret; 38*e28a4053SRui Paulo } 39*e28a4053SRui Paulo 40*e28a4053SRui Paulo len = 0; 41*e28a4053SRui Paulo ret = os_snprintf(buf + len, buflen - len, MACSTR "\n", 42*e28a4053SRui Paulo MAC2STR(sta->addr)); 43*e28a4053SRui Paulo if (ret < 0 || (size_t) ret >= buflen - len) 44*e28a4053SRui Paulo return len; 45*e28a4053SRui Paulo len += ret; 46*e28a4053SRui Paulo 47*e28a4053SRui Paulo res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len); 48*e28a4053SRui Paulo if (res >= 0) 49*e28a4053SRui Paulo len += res; 50*e28a4053SRui Paulo res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len); 51*e28a4053SRui Paulo if (res >= 0) 52*e28a4053SRui Paulo len += res; 53*e28a4053SRui Paulo res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len); 54*e28a4053SRui Paulo if (res >= 0) 55*e28a4053SRui Paulo len += res; 56*e28a4053SRui Paulo res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len, 57*e28a4053SRui Paulo buflen - len); 58*e28a4053SRui Paulo if (res >= 0) 59*e28a4053SRui Paulo len += res; 60*e28a4053SRui Paulo 61*e28a4053SRui Paulo return len; 62*e28a4053SRui Paulo } 63*e28a4053SRui Paulo 64*e28a4053SRui Paulo 65*e28a4053SRui Paulo int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd, 66*e28a4053SRui Paulo char *buf, size_t buflen) 67*e28a4053SRui Paulo { 68*e28a4053SRui Paulo return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen); 69*e28a4053SRui Paulo } 70*e28a4053SRui Paulo 71*e28a4053SRui Paulo 72*e28a4053SRui Paulo int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr, 73*e28a4053SRui Paulo char *buf, size_t buflen) 74*e28a4053SRui Paulo { 75*e28a4053SRui Paulo u8 addr[ETH_ALEN]; 76*e28a4053SRui Paulo int ret; 77*e28a4053SRui Paulo 78*e28a4053SRui Paulo if (hwaddr_aton(txtaddr, addr)) { 79*e28a4053SRui Paulo ret = os_snprintf(buf, buflen, "FAIL\n"); 80*e28a4053SRui Paulo if (ret < 0 || (size_t) ret >= buflen) 81*e28a4053SRui Paulo return 0; 82*e28a4053SRui Paulo return ret; 83*e28a4053SRui Paulo } 84*e28a4053SRui Paulo return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr), 85*e28a4053SRui Paulo buf, buflen); 86*e28a4053SRui Paulo } 87*e28a4053SRui Paulo 88*e28a4053SRui Paulo 89*e28a4053SRui Paulo int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr, 90*e28a4053SRui Paulo char *buf, size_t buflen) 91*e28a4053SRui Paulo { 92*e28a4053SRui Paulo u8 addr[ETH_ALEN]; 93*e28a4053SRui Paulo struct sta_info *sta; 94*e28a4053SRui Paulo int ret; 95*e28a4053SRui Paulo 96*e28a4053SRui Paulo if (hwaddr_aton(txtaddr, addr) || 97*e28a4053SRui Paulo (sta = ap_get_sta(hapd, addr)) == NULL) { 98*e28a4053SRui Paulo ret = os_snprintf(buf, buflen, "FAIL\n"); 99*e28a4053SRui Paulo if (ret < 0 || (size_t) ret >= buflen) 100*e28a4053SRui Paulo return 0; 101*e28a4053SRui Paulo return ret; 102*e28a4053SRui Paulo } 103*e28a4053SRui Paulo return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen); 104*e28a4053SRui Paulo } 105