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