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