1 /* 2 * Control interface for shared AP commands 3 * Copyright (c) 2004-2009, Jouni Malinen <j (at) 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 "utils/includes.h" 10 11 #include "utils/common.h" 12 #include "hostapd.h" 13 #include "ieee802_1x.h" 14 #include "wpa_auth.h" 15 #include "ieee802_11.h" 16 #include "sta_info.h" 17 #include "wps_hostapd.h" 18 #include "p2p_hostapd.h" 19 #include "ctrl_iface_ap.h" 20 21 22 static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd, 23 struct sta_info *sta, 24 char *buf, size_t buflen) 25 { 26 int len, res, ret; 27 28 if (sta == NULL) { 29 ret = os_snprintf(buf, buflen, "FAIL\n"); 30 if (ret < 0 || (size_t) ret >= buflen) 31 return 0; 32 return ret; 33 } 34 35 len = 0; 36 ret = os_snprintf(buf + len, buflen - len, MACSTR "\n", 37 MAC2STR(sta->addr)); 38 if (ret < 0 || (size_t) ret >= buflen - len) 39 return len; 40 len += ret; 41 42 res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len); 43 if (res >= 0) 44 len += res; 45 res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len); 46 if (res >= 0) 47 len += res; 48 res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len); 49 if (res >= 0) 50 len += res; 51 res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len, 52 buflen - len); 53 if (res >= 0) 54 len += res; 55 res = hostapd_p2p_get_mib_sta(hapd, sta, buf + len, buflen - len); 56 if (res >= 0) 57 len += res; 58 59 return len; 60 } 61 62 63 int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd, 64 char *buf, size_t buflen) 65 { 66 return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen); 67 } 68 69 70 int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr, 71 char *buf, size_t buflen) 72 { 73 u8 addr[ETH_ALEN]; 74 int ret; 75 76 if (hwaddr_aton(txtaddr, addr)) { 77 ret = os_snprintf(buf, buflen, "FAIL\n"); 78 if (ret < 0 || (size_t) ret >= buflen) 79 return 0; 80 return ret; 81 } 82 return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr), 83 buf, buflen); 84 } 85 86 87 int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr, 88 char *buf, size_t buflen) 89 { 90 u8 addr[ETH_ALEN]; 91 struct sta_info *sta; 92 int ret; 93 94 if (hwaddr_aton(txtaddr, addr) || 95 (sta = ap_get_sta(hapd, addr)) == NULL) { 96 ret = os_snprintf(buf, buflen, "FAIL\n"); 97 if (ret < 0 || (size_t) ret >= buflen) 98 return 0; 99 return ret; 100 } 101 return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen); 102 } 103