automake build system
[mech_eap.orig] / src / ap / ctrl_iface_ap.c
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 "p2p_hostapd.h"
25 #include "ctrl_iface_ap.h"
26
27
28 static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
29                                       struct sta_info *sta,
30                                       char *buf, size_t buflen)
31 {
32         int len, res, ret;
33
34         if (sta == NULL) {
35                 ret = os_snprintf(buf, buflen, "FAIL\n");
36                 if (ret < 0 || (size_t) ret >= buflen)
37                         return 0;
38                 return ret;
39         }
40
41         len = 0;
42         ret = os_snprintf(buf + len, buflen - len, MACSTR "\n",
43                           MAC2STR(sta->addr));
44         if (ret < 0 || (size_t) ret >= buflen - len)
45                 return len;
46         len += ret;
47
48         res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len);
49         if (res >= 0)
50                 len += res;
51         res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len);
52         if (res >= 0)
53                 len += res;
54         res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
55         if (res >= 0)
56                 len += res;
57         res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len,
58                                       buflen - len);
59         if (res >= 0)
60                 len += res;
61         res = hostapd_p2p_get_mib_sta(hapd, sta, buf + len, buflen - len);
62         if (res >= 0)
63                 len += res;
64
65         return len;
66 }
67
68
69 int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
70                                  char *buf, size_t buflen)
71 {
72         return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
73 }
74
75
76 int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
77                            char *buf, size_t buflen)
78 {
79         u8 addr[ETH_ALEN];
80         int ret;
81
82         if (hwaddr_aton(txtaddr, addr)) {
83                 ret = os_snprintf(buf, buflen, "FAIL\n");
84                 if (ret < 0 || (size_t) ret >= buflen)
85                         return 0;
86                 return ret;
87         }
88         return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr),
89                                           buf, buflen);
90 }
91
92
93 int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
94                                 char *buf, size_t buflen)
95 {
96         u8 addr[ETH_ALEN];
97         struct sta_info *sta;
98         int ret;
99
100         if (hwaddr_aton(txtaddr, addr) ||
101             (sta = ap_get_sta(hapd, addr)) == NULL) {
102                 ret = os_snprintf(buf, buflen, "FAIL\n");
103                 if (ret < 0 || (size_t) ret >= buflen)
104                         return 0;
105                 return ret;
106         }               
107         return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
108 }