| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * WPA Supplicant / Control interface (shared code for all backends) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3 | * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi> | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. | 
|  | 6 | * See README for more details. | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ | 
|  | 8 |  | 
|  | 9 | #include "utils/includes.h" | 
|  | 10 |  | 
|  | 11 | #include "utils/common.h" | 
|  | 12 | #include "utils/eloop.h" | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 13 | #include "utils/uuid.h" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14 | #include "common/version.h" | 
|  | 15 | #include "common/ieee802_11_defs.h" | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 16 | #include "common/ieee802_11_common.h" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 17 | #include "common/wpa_ctrl.h" | 
|  | 18 | #include "eap_peer/eap.h" | 
|  | 19 | #include "eapol_supp/eapol_supp_sm.h" | 
|  | 20 | #include "rsn_supp/wpa.h" | 
|  | 21 | #include "rsn_supp/preauth.h" | 
|  | 22 | #include "rsn_supp/pmksa_cache.h" | 
|  | 23 | #include "l2_packet/l2_packet.h" | 
|  | 24 | #include "wps/wps.h" | 
|  | 25 | #include "config.h" | 
|  | 26 | #include "wpa_supplicant_i.h" | 
|  | 27 | #include "driver_i.h" | 
|  | 28 | #include "wps_supplicant.h" | 
|  | 29 | #include "ibss_rsn.h" | 
|  | 30 | #include "ap.h" | 
|  | 31 | #include "p2p_supplicant.h" | 
|  | 32 | #include "p2p/p2p.h" | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 33 | #include "hs20_supplicant.h" | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 34 | #include "wifi_display.h" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "notify.h" | 
|  | 36 | #include "bss.h" | 
|  | 37 | #include "scan.h" | 
|  | 38 | #include "ctrl_iface.h" | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 39 | #include "interworking.h" | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 40 | #include "blacklist.h" | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 41 | #include "autoscan.h" | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 42 | #include "wnm_sta.h" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 43 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 44 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, | 
|  | 45 | char *buf, int len); | 
|  | 46 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, | 
|  | 47 | char *buf, int len); | 
|  | 48 |  | 
|  | 49 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 50 | static int pno_start(struct wpa_supplicant *wpa_s) | 
|  | 51 | { | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 52 | int ret, interval; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 53 | size_t i, num_ssid; | 
|  | 54 | struct wpa_ssid *ssid; | 
|  | 55 | struct wpa_driver_scan_params params; | 
|  | 56 |  | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 57 | if (wpa_s->pno || wpa_s->pno_sched_pending) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 58 | return 0; | 
|  | 59 |  | 
| Dmitry Shmidt | 4d9ecd8 | 2013-11-05 18:08:27 -0800 | [diff] [blame] | 60 | if ((wpa_s->wpa_state > WPA_SCANNING) && | 
|  | 61 | (wpa_s->wpa_state <= WPA_COMPLETED)) { | 
|  | 62 | wpa_printf(MSG_ERROR, "PNO: In assoc process"); | 
|  | 63 | return -EAGAIN; | 
|  | 64 | } | 
|  | 65 |  | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 66 | if (wpa_s->wpa_state == WPA_SCANNING) { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 67 | wpa_supplicant_cancel_scan(wpa_s); | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 68 | if (wpa_s->sched_scanning) { | 
|  | 69 | wpa_printf(MSG_DEBUG, "Schedule PNO on completion of " | 
|  | 70 | "ongoing sched scan"); | 
|  | 71 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
|  | 72 | wpa_s->pno_sched_pending = 1; | 
|  | 73 | return 0; | 
|  | 74 | } | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 75 | } | 
|  | 76 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 77 | os_memset(¶ms, 0, sizeof(params)); | 
|  | 78 |  | 
|  | 79 | num_ssid = 0; | 
|  | 80 | ssid = wpa_s->conf->ssid; | 
|  | 81 | while (ssid) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 82 | if (!wpas_network_disabled(wpa_s, ssid)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 83 | num_ssid++; | 
|  | 84 | ssid = ssid->next; | 
|  | 85 | } | 
|  | 86 | if (num_ssid > WPAS_MAX_SCAN_SSIDS) { | 
|  | 87 | wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from " | 
|  | 88 | "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid); | 
|  | 89 | num_ssid = WPAS_MAX_SCAN_SSIDS; | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | if (num_ssid == 0) { | 
|  | 93 | wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs"); | 
|  | 94 | return -1; | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) * | 
|  | 98 | num_ssid); | 
|  | 99 | if (params.filter_ssids == NULL) | 
|  | 100 | return -1; | 
|  | 101 | i = 0; | 
|  | 102 | ssid = wpa_s->conf->ssid; | 
|  | 103 | while (ssid) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 104 | if (!wpas_network_disabled(wpa_s, ssid)) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 105 | params.ssids[i].ssid = ssid->ssid; | 
|  | 106 | params.ssids[i].ssid_len = ssid->ssid_len; | 
|  | 107 | params.num_ssids++; | 
|  | 108 | os_memcpy(params.filter_ssids[i].ssid, ssid->ssid, | 
|  | 109 | ssid->ssid_len); | 
|  | 110 | params.filter_ssids[i].ssid_len = ssid->ssid_len; | 
|  | 111 | params.num_filter_ssids++; | 
|  | 112 | i++; | 
|  | 113 | if (i == num_ssid) | 
|  | 114 | break; | 
|  | 115 | } | 
|  | 116 | ssid = ssid->next; | 
|  | 117 | } | 
|  | 118 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 119 | if (wpa_s->conf->filter_rssi) | 
|  | 120 | params.filter_rssi = wpa_s->conf->filter_rssi; | 
|  | 121 |  | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 122 | interval = wpa_s->conf->sched_scan_interval ? | 
|  | 123 | wpa_s->conf->sched_scan_interval : 10; | 
|  | 124 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 125 | ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms, interval); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 126 | os_free(params.filter_ssids); | 
|  | 127 | if (ret == 0) | 
|  | 128 | wpa_s->pno = 1; | 
|  | 129 | return ret; | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 |  | 
|  | 133 | static int pno_stop(struct wpa_supplicant *wpa_s) | 
|  | 134 | { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 135 | int ret = 0; | 
|  | 136 |  | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 137 | if (wpa_s->pno || wpa_s->sched_scanning) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 138 | wpa_s->pno = 0; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 139 | ret = wpa_supplicant_stop_sched_scan(wpa_s); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 140 | } | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 141 |  | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 142 | wpa_s->pno_sched_pending = 0; | 
|  | 143 |  | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 144 | if (wpa_s->wpa_state == WPA_SCANNING) | 
|  | 145 | wpa_supplicant_req_scan(wpa_s, 0, 0); | 
|  | 146 |  | 
|  | 147 | return ret; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 148 | } | 
|  | 149 |  | 
|  | 150 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 151 | static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) | 
|  | 152 | { | 
|  | 153 | char *pos; | 
|  | 154 | u8 addr[ETH_ALEN], *filter = NULL, *n; | 
|  | 155 | size_t count = 0; | 
|  | 156 |  | 
|  | 157 | pos = val; | 
|  | 158 | while (pos) { | 
|  | 159 | if (*pos == '\0') | 
|  | 160 | break; | 
|  | 161 | if (hwaddr_aton(pos, addr)) { | 
|  | 162 | os_free(filter); | 
|  | 163 | return -1; | 
|  | 164 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 165 | n = os_realloc_array(filter, count + 1, ETH_ALEN); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 166 | if (n == NULL) { | 
|  | 167 | os_free(filter); | 
|  | 168 | return -1; | 
|  | 169 | } | 
|  | 170 | filter = n; | 
|  | 171 | os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); | 
|  | 172 | count++; | 
|  | 173 |  | 
|  | 174 | pos = os_strchr(pos, ' '); | 
|  | 175 | if (pos) | 
|  | 176 | pos++; | 
|  | 177 | } | 
|  | 178 |  | 
|  | 179 | wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); | 
|  | 180 | os_free(wpa_s->bssid_filter); | 
|  | 181 | wpa_s->bssid_filter = filter; | 
|  | 182 | wpa_s->bssid_filter_count = count; | 
|  | 183 |  | 
|  | 184 | return 0; | 
|  | 185 | } | 
|  | 186 |  | 
|  | 187 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 188 | static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val) | 
|  | 189 | { | 
|  | 190 | char *pos; | 
|  | 191 | u8 addr[ETH_ALEN], *bssid = NULL, *n; | 
|  | 192 | struct wpa_ssid_value *ssid = NULL, *ns; | 
|  | 193 | size_t count = 0, ssid_count = 0; | 
|  | 194 | struct wpa_ssid *c; | 
|  | 195 |  | 
|  | 196 | /* | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 197 | * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | "" | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 198 | * SSID_SPEC ::= ssid <SSID_HEX> | 
|  | 199 | * BSSID_SPEC ::= bssid <BSSID_HEX> | 
|  | 200 | */ | 
|  | 201 |  | 
|  | 202 | pos = val; | 
|  | 203 | while (pos) { | 
|  | 204 | if (*pos == '\0') | 
|  | 205 | break; | 
|  | 206 | if (os_strncmp(pos, "bssid ", 6) == 0) { | 
|  | 207 | int res; | 
|  | 208 | pos += 6; | 
|  | 209 | res = hwaddr_aton2(pos, addr); | 
|  | 210 | if (res < 0) { | 
|  | 211 | os_free(ssid); | 
|  | 212 | os_free(bssid); | 
|  | 213 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | 
|  | 214 | "BSSID value '%s'", pos); | 
|  | 215 | return -1; | 
|  | 216 | } | 
|  | 217 | pos += res; | 
|  | 218 | n = os_realloc_array(bssid, count + 1, ETH_ALEN); | 
|  | 219 | if (n == NULL) { | 
|  | 220 | os_free(ssid); | 
|  | 221 | os_free(bssid); | 
|  | 222 | return -1; | 
|  | 223 | } | 
|  | 224 | bssid = n; | 
|  | 225 | os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN); | 
|  | 226 | count++; | 
|  | 227 | } else if (os_strncmp(pos, "ssid ", 5) == 0) { | 
|  | 228 | char *end; | 
|  | 229 | pos += 5; | 
|  | 230 |  | 
|  | 231 | end = pos; | 
|  | 232 | while (*end) { | 
|  | 233 | if (*end == '\0' || *end == ' ') | 
|  | 234 | break; | 
|  | 235 | end++; | 
|  | 236 | } | 
|  | 237 |  | 
|  | 238 | ns = os_realloc_array(ssid, ssid_count + 1, | 
|  | 239 | sizeof(struct wpa_ssid_value)); | 
|  | 240 | if (ns == NULL) { | 
|  | 241 | os_free(ssid); | 
|  | 242 | os_free(bssid); | 
|  | 243 | return -1; | 
|  | 244 | } | 
|  | 245 | ssid = ns; | 
|  | 246 |  | 
|  | 247 | if ((end - pos) & 0x01 || end - pos > 2 * 32 || | 
|  | 248 | hexstr2bin(pos, ssid[ssid_count].ssid, | 
|  | 249 | (end - pos) / 2) < 0) { | 
|  | 250 | os_free(ssid); | 
|  | 251 | os_free(bssid); | 
|  | 252 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | 
|  | 253 | "SSID value '%s'", pos); | 
|  | 254 | return -1; | 
|  | 255 | } | 
|  | 256 | ssid[ssid_count].ssid_len = (end - pos) / 2; | 
|  | 257 | wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID", | 
|  | 258 | ssid[ssid_count].ssid, | 
|  | 259 | ssid[ssid_count].ssid_len); | 
|  | 260 | ssid_count++; | 
|  | 261 | pos = end; | 
|  | 262 | } else { | 
|  | 263 | wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value " | 
|  | 264 | "'%s'", pos); | 
|  | 265 | os_free(ssid); | 
|  | 266 | os_free(bssid); | 
|  | 267 | return -1; | 
|  | 268 | } | 
|  | 269 |  | 
|  | 270 | pos = os_strchr(pos, ' '); | 
|  | 271 | if (pos) | 
|  | 272 | pos++; | 
|  | 273 | } | 
|  | 274 |  | 
|  | 275 | wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN); | 
|  | 276 | os_free(wpa_s->disallow_aps_bssid); | 
|  | 277 | wpa_s->disallow_aps_bssid = bssid; | 
|  | 278 | wpa_s->disallow_aps_bssid_count = count; | 
|  | 279 |  | 
|  | 280 | wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count); | 
|  | 281 | os_free(wpa_s->disallow_aps_ssid); | 
|  | 282 | wpa_s->disallow_aps_ssid = ssid; | 
|  | 283 | wpa_s->disallow_aps_ssid_count = ssid_count; | 
|  | 284 |  | 
|  | 285 | if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING) | 
|  | 286 | return 0; | 
|  | 287 |  | 
|  | 288 | c = wpa_s->current_ssid; | 
|  | 289 | if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS) | 
|  | 290 | return 0; | 
|  | 291 |  | 
|  | 292 | if (!disallowed_bssid(wpa_s, wpa_s->bssid) && | 
|  | 293 | !disallowed_ssid(wpa_s, c->ssid, c->ssid_len)) | 
|  | 294 | return 0; | 
|  | 295 |  | 
|  | 296 | wpa_printf(MSG_DEBUG, "Disconnect and try to find another network " | 
|  | 297 | "because current AP was marked disallowed"); | 
|  | 298 |  | 
|  | 299 | #ifdef CONFIG_SME | 
|  | 300 | wpa_s->sme.prev_bssid_set = 0; | 
|  | 301 | #endif /* CONFIG_SME */ | 
|  | 302 | wpa_s->reassociate = 1; | 
|  | 303 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | 
|  | 304 | wpa_supplicant_req_scan(wpa_s, 0, 0); | 
|  | 305 |  | 
|  | 306 | return 0; | 
|  | 307 | } | 
|  | 308 |  | 
|  | 309 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 310 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, | 
|  | 311 | char *cmd) | 
|  | 312 | { | 
|  | 313 | char *value; | 
|  | 314 | int ret = 0; | 
|  | 315 |  | 
|  | 316 | value = os_strchr(cmd, ' '); | 
|  | 317 | if (value == NULL) | 
|  | 318 | return -1; | 
|  | 319 | *value++ = '\0'; | 
|  | 320 |  | 
|  | 321 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); | 
|  | 322 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { | 
|  | 323 | eapol_sm_configure(wpa_s->eapol, | 
|  | 324 | atoi(value), -1, -1, -1); | 
|  | 325 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { | 
|  | 326 | eapol_sm_configure(wpa_s->eapol, | 
|  | 327 | -1, atoi(value), -1, -1); | 
|  | 328 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { | 
|  | 329 | eapol_sm_configure(wpa_s->eapol, | 
|  | 330 | -1, -1, atoi(value), -1); | 
|  | 331 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { | 
|  | 332 | eapol_sm_configure(wpa_s->eapol, | 
|  | 333 | -1, -1, -1, atoi(value)); | 
|  | 334 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { | 
|  | 335 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, | 
|  | 336 | atoi(value))) | 
|  | 337 | ret = -1; | 
|  | 338 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == | 
|  | 339 | 0) { | 
|  | 340 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, | 
|  | 341 | atoi(value))) | 
|  | 342 | ret = -1; | 
|  | 343 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { | 
|  | 344 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value))) | 
|  | 345 | ret = -1; | 
|  | 346 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { | 
|  | 347 | wpa_s->wps_fragment_size = atoi(value); | 
|  | 348 | #ifdef CONFIG_WPS_TESTING | 
|  | 349 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { | 
|  | 350 | long int val; | 
|  | 351 | val = strtol(value, NULL, 0); | 
|  | 352 | if (val < 0 || val > 0xff) { | 
|  | 353 | ret = -1; | 
|  | 354 | wpa_printf(MSG_DEBUG, "WPS: Invalid " | 
|  | 355 | "wps_version_number %ld", val); | 
|  | 356 | } else { | 
|  | 357 | wps_version_number = val; | 
|  | 358 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " | 
|  | 359 | "version %u.%u", | 
|  | 360 | (wps_version_number & 0xf0) >> 4, | 
|  | 361 | wps_version_number & 0x0f); | 
|  | 362 | } | 
|  | 363 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { | 
|  | 364 | wps_testing_dummy_cred = atoi(value); | 
|  | 365 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", | 
|  | 366 | wps_testing_dummy_cred); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 367 | } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) { | 
|  | 368 | wps_corrupt_pkhash = atoi(value); | 
|  | 369 | wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d", | 
|  | 370 | wps_corrupt_pkhash); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 371 | #endif /* CONFIG_WPS_TESTING */ | 
|  | 372 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { | 
|  | 373 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) | 
|  | 374 | ret = -1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 375 | #ifdef CONFIG_TDLS | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 376 | #ifdef CONFIG_TDLS_TESTING | 
|  | 377 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { | 
|  | 378 | extern unsigned int tdls_testing; | 
|  | 379 | tdls_testing = strtol(value, NULL, 0); | 
|  | 380 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); | 
|  | 381 | #endif /* CONFIG_TDLS_TESTING */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 382 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { | 
|  | 383 | int disabled = atoi(value); | 
|  | 384 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); | 
|  | 385 | if (disabled) { | 
|  | 386 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) | 
|  | 387 | ret = -1; | 
|  | 388 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) | 
|  | 389 | ret = -1; | 
|  | 390 | wpa_tdls_enable(wpa_s->wpa, !disabled); | 
|  | 391 | #endif /* CONFIG_TDLS */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 392 | } else if (os_strcasecmp(cmd, "pno") == 0) { | 
|  | 393 | if (atoi(value)) | 
|  | 394 | ret = pno_start(wpa_s); | 
|  | 395 | else | 
|  | 396 | ret = pno_stop(wpa_s); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 397 | } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { | 
|  | 398 | int disabled = atoi(value); | 
|  | 399 | if (wpa_drv_radio_disable(wpa_s, disabled) < 0) | 
|  | 400 | ret = -1; | 
|  | 401 | else if (disabled) | 
|  | 402 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | 
|  | 403 | } else if (os_strcasecmp(cmd, "uapsd") == 0) { | 
|  | 404 | if (os_strcmp(value, "disable") == 0) | 
|  | 405 | wpa_s->set_sta_uapsd = 0; | 
|  | 406 | else { | 
|  | 407 | int be, bk, vi, vo; | 
|  | 408 | char *pos; | 
|  | 409 | /* format: BE,BK,VI,VO;max SP Length */ | 
|  | 410 | be = atoi(value); | 
|  | 411 | pos = os_strchr(value, ','); | 
|  | 412 | if (pos == NULL) | 
|  | 413 | return -1; | 
|  | 414 | pos++; | 
|  | 415 | bk = atoi(pos); | 
|  | 416 | pos = os_strchr(pos, ','); | 
|  | 417 | if (pos == NULL) | 
|  | 418 | return -1; | 
|  | 419 | pos++; | 
|  | 420 | vi = atoi(pos); | 
|  | 421 | pos = os_strchr(pos, ','); | 
|  | 422 | if (pos == NULL) | 
|  | 423 | return -1; | 
|  | 424 | pos++; | 
|  | 425 | vo = atoi(pos); | 
|  | 426 | /* ignore max SP Length for now */ | 
|  | 427 |  | 
|  | 428 | wpa_s->set_sta_uapsd = 1; | 
|  | 429 | wpa_s->sta_uapsd = 0; | 
|  | 430 | if (be) | 
|  | 431 | wpa_s->sta_uapsd |= BIT(0); | 
|  | 432 | if (bk) | 
|  | 433 | wpa_s->sta_uapsd |= BIT(1); | 
|  | 434 | if (vi) | 
|  | 435 | wpa_s->sta_uapsd |= BIT(2); | 
|  | 436 | if (vo) | 
|  | 437 | wpa_s->sta_uapsd |= BIT(3); | 
|  | 438 | } | 
| Jouni Malinen | 21d6bc8 | 2012-04-10 16:17:59 -0700 | [diff] [blame] | 439 | } else if (os_strcasecmp(cmd, "ps") == 0) { | 
|  | 440 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 441 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 442 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | 
| Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 443 | int enabled = !!atoi(value); | 
|  | 444 | if (enabled && !wpa_s->global->p2p) | 
|  | 445 | ret = -1; | 
|  | 446 | else | 
|  | 447 | wifi_display_enable(wpa_s->global, enabled); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 448 | #endif /* CONFIG_WIFI_DISPLAY */ | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 449 | } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { | 
|  | 450 | ret = set_bssid_filter(wpa_s, value); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 451 | } else if (os_strcasecmp(cmd, "disallow_aps") == 0) { | 
|  | 452 | ret = set_disallow_aps(wpa_s, value); | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 453 | } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) { | 
|  | 454 | wpa_s->no_keep_alive = !!atoi(value); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 455 | } else { | 
|  | 456 | value[-1] = '='; | 
|  | 457 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); | 
|  | 458 | if (ret == 0) | 
|  | 459 | wpa_supplicant_update_config(wpa_s); | 
|  | 460 | } | 
|  | 461 |  | 
|  | 462 | return ret; | 
|  | 463 | } | 
|  | 464 |  | 
|  | 465 |  | 
|  | 466 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, | 
|  | 467 | char *cmd, char *buf, size_t buflen) | 
|  | 468 | { | 
| Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 469 | int res = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 470 |  | 
|  | 471 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); | 
|  | 472 |  | 
|  | 473 | if (os_strcmp(cmd, "version") == 0) { | 
|  | 474 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); | 
| Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 475 | } else if (os_strcasecmp(cmd, "country") == 0) { | 
|  | 476 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) | 
|  | 477 | res = os_snprintf(buf, buflen, "%c%c", | 
|  | 478 | wpa_s->conf->country[0], | 
|  | 479 | wpa_s->conf->country[1]); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 480 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 481 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | 
| Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 482 | int enabled; | 
|  | 483 | if (wpa_s->global->p2p == NULL || | 
|  | 484 | wpa_s->global->p2p_disabled) | 
|  | 485 | enabled = 0; | 
|  | 486 | else | 
|  | 487 | enabled = wpa_s->global->wifi_display; | 
|  | 488 | res = os_snprintf(buf, buflen, "%d", enabled); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 489 | if (res < 0 || (unsigned int) res >= buflen) | 
|  | 490 | return -1; | 
|  | 491 | return res; | 
|  | 492 | #endif /* CONFIG_WIFI_DISPLAY */ | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 493 | #ifdef CONFIG_TESTING_GET_GTK | 
|  | 494 | } else if (os_strcmp(cmd, "gtk") == 0) { | 
|  | 495 | if (wpa_s->last_gtk_len == 0) | 
|  | 496 | return -1; | 
|  | 497 | res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk, | 
|  | 498 | wpa_s->last_gtk_len); | 
|  | 499 | return res; | 
|  | 500 | #endif /* CONFIG_TESTING_GET_GTK */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 501 | } | 
|  | 502 |  | 
| Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 503 | if (res < 0 || (unsigned int) res >= buflen) | 
|  | 504 | return -1; | 
|  | 505 | return res; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 506 | } | 
|  | 507 |  | 
|  | 508 |  | 
|  | 509 | #ifdef IEEE8021X_EAPOL | 
|  | 510 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, | 
|  | 511 | char *addr) | 
|  | 512 | { | 
|  | 513 | u8 bssid[ETH_ALEN]; | 
|  | 514 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
|  | 515 |  | 
|  | 516 | if (hwaddr_aton(addr, bssid)) { | 
|  | 517 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " | 
|  | 518 | "'%s'", addr); | 
|  | 519 | return -1; | 
|  | 520 | } | 
|  | 521 |  | 
|  | 522 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); | 
|  | 523 | rsn_preauth_deinit(wpa_s->wpa); | 
|  | 524 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) | 
|  | 525 | return -1; | 
|  | 526 |  | 
|  | 527 | return 0; | 
|  | 528 | } | 
|  | 529 | #endif /* IEEE8021X_EAPOL */ | 
|  | 530 |  | 
|  | 531 |  | 
|  | 532 | #ifdef CONFIG_PEERKEY | 
|  | 533 | /* MLME-STKSTART.request(peer) */ | 
|  | 534 | static int wpa_supplicant_ctrl_iface_stkstart( | 
|  | 535 | struct wpa_supplicant *wpa_s, char *addr) | 
|  | 536 | { | 
|  | 537 | u8 peer[ETH_ALEN]; | 
|  | 538 |  | 
|  | 539 | if (hwaddr_aton(addr, peer)) { | 
|  | 540 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid " | 
|  | 541 | "address '%s'", addr); | 
|  | 542 | return -1; | 
|  | 543 | } | 
|  | 544 |  | 
|  | 545 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR, | 
|  | 546 | MAC2STR(peer)); | 
|  | 547 |  | 
|  | 548 | return wpa_sm_stkstart(wpa_s->wpa, peer); | 
|  | 549 | } | 
|  | 550 | #endif /* CONFIG_PEERKEY */ | 
|  | 551 |  | 
|  | 552 |  | 
|  | 553 | #ifdef CONFIG_TDLS | 
|  | 554 |  | 
|  | 555 | static int wpa_supplicant_ctrl_iface_tdls_discover( | 
|  | 556 | struct wpa_supplicant *wpa_s, char *addr) | 
|  | 557 | { | 
|  | 558 | u8 peer[ETH_ALEN]; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 559 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 560 |  | 
|  | 561 | if (hwaddr_aton(addr, peer)) { | 
|  | 562 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " | 
|  | 563 | "address '%s'", addr); | 
|  | 564 | return -1; | 
|  | 565 | } | 
|  | 566 |  | 
|  | 567 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, | 
|  | 568 | MAC2STR(peer)); | 
|  | 569 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 570 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | 
|  | 571 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); | 
|  | 572 | else | 
|  | 573 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); | 
|  | 574 |  | 
|  | 575 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 576 | } | 
|  | 577 |  | 
|  | 578 |  | 
|  | 579 | static int wpa_supplicant_ctrl_iface_tdls_setup( | 
|  | 580 | struct wpa_supplicant *wpa_s, char *addr) | 
|  | 581 | { | 
|  | 582 | u8 peer[ETH_ALEN]; | 
|  | 583 | int ret; | 
|  | 584 |  | 
|  | 585 | if (hwaddr_aton(addr, peer)) { | 
|  | 586 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " | 
|  | 587 | "address '%s'", addr); | 
|  | 588 | return -1; | 
|  | 589 | } | 
|  | 590 |  | 
|  | 591 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, | 
|  | 592 | MAC2STR(peer)); | 
|  | 593 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 594 | if ((wpa_s->conf->tdls_external_control) && | 
|  | 595 | wpa_tdls_is_external_setup(wpa_s->wpa)) | 
|  | 596 | return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | 
|  | 597 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 598 | wpa_tdls_remove(wpa_s->wpa, peer); | 
|  | 599 |  | 
|  | 600 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | 
|  | 601 | ret = wpa_tdls_start(wpa_s->wpa, peer); | 
|  | 602 | else | 
|  | 603 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 604 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 605 | return ret; | 
|  | 606 | } | 
|  | 607 |  | 
|  | 608 |  | 
|  | 609 | static int wpa_supplicant_ctrl_iface_tdls_teardown( | 
|  | 610 | struct wpa_supplicant *wpa_s, char *addr) | 
|  | 611 | { | 
|  | 612 | u8 peer[ETH_ALEN]; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 613 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 614 |  | 
|  | 615 | if (hwaddr_aton(addr, peer)) { | 
|  | 616 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " | 
|  | 617 | "address '%s'", addr); | 
|  | 618 | return -1; | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, | 
|  | 622 | MAC2STR(peer)); | 
|  | 623 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 624 | if ((wpa_s->conf->tdls_external_control) && | 
|  | 625 | wpa_tdls_is_external_setup(wpa_s->wpa)) | 
|  | 626 | return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | 
|  | 627 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 628 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | 
|  | 629 | ret = wpa_tdls_teardown_link( | 
|  | 630 | wpa_s->wpa, peer, | 
|  | 631 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); | 
|  | 632 | else | 
|  | 633 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | 
|  | 634 |  | 
|  | 635 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 636 | } | 
|  | 637 |  | 
|  | 638 | #endif /* CONFIG_TDLS */ | 
|  | 639 |  | 
|  | 640 |  | 
|  | 641 | #ifdef CONFIG_IEEE80211R | 
|  | 642 | static int wpa_supplicant_ctrl_iface_ft_ds( | 
|  | 643 | struct wpa_supplicant *wpa_s, char *addr) | 
|  | 644 | { | 
|  | 645 | u8 target_ap[ETH_ALEN]; | 
|  | 646 | struct wpa_bss *bss; | 
|  | 647 | const u8 *mdie; | 
|  | 648 |  | 
|  | 649 | if (hwaddr_aton(addr, target_ap)) { | 
|  | 650 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " | 
|  | 651 | "address '%s'", addr); | 
|  | 652 | return -1; | 
|  | 653 | } | 
|  | 654 |  | 
|  | 655 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); | 
|  | 656 |  | 
|  | 657 | bss = wpa_bss_get_bssid(wpa_s, target_ap); | 
|  | 658 | if (bss) | 
|  | 659 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); | 
|  | 660 | else | 
|  | 661 | mdie = NULL; | 
|  | 662 |  | 
|  | 663 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); | 
|  | 664 | } | 
|  | 665 | #endif /* CONFIG_IEEE80211R */ | 
|  | 666 |  | 
|  | 667 |  | 
|  | 668 | #ifdef CONFIG_WPS | 
|  | 669 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, | 
|  | 670 | char *cmd) | 
|  | 671 | { | 
|  | 672 | u8 bssid[ETH_ALEN], *_bssid = bssid; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 673 | #ifdef CONFIG_P2P | 
|  | 674 | u8 p2p_dev_addr[ETH_ALEN]; | 
|  | 675 | #endif /* CONFIG_P2P */ | 
|  | 676 | #ifdef CONFIG_AP | 
|  | 677 | u8 *_p2p_dev_addr = NULL; | 
|  | 678 | #endif /* CONFIG_AP */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 679 |  | 
| Dmitry Shmidt | c0a8db0 | 2013-11-08 11:18:33 -0800 | [diff] [blame] | 680 | if (cmd == NULL || os_strcmp(cmd, "any") == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 681 | _bssid = NULL; | 
|  | 682 | #ifdef CONFIG_P2P | 
|  | 683 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | 
|  | 684 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { | 
|  | 685 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " | 
|  | 686 | "P2P Device Address '%s'", | 
|  | 687 | cmd + 13); | 
|  | 688 | return -1; | 
|  | 689 | } | 
|  | 690 | _p2p_dev_addr = p2p_dev_addr; | 
|  | 691 | #endif /* CONFIG_P2P */ | 
|  | 692 | } else if (hwaddr_aton(cmd, bssid)) { | 
|  | 693 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", | 
|  | 694 | cmd); | 
|  | 695 | return -1; | 
|  | 696 | } | 
|  | 697 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 698 | #ifdef CONFIG_AP | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 699 | if (wpa_s->ap_iface) | 
|  | 700 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); | 
|  | 701 | #endif /* CONFIG_AP */ | 
|  | 702 |  | 
|  | 703 | return wpas_wps_start_pbc(wpa_s, _bssid, 0); | 
|  | 704 | } | 
|  | 705 |  | 
|  | 706 |  | 
|  | 707 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, | 
|  | 708 | char *cmd, char *buf, | 
|  | 709 | size_t buflen) | 
|  | 710 | { | 
|  | 711 | u8 bssid[ETH_ALEN], *_bssid = bssid; | 
|  | 712 | char *pin; | 
|  | 713 | int ret; | 
|  | 714 |  | 
|  | 715 | pin = os_strchr(cmd, ' '); | 
|  | 716 | if (pin) | 
|  | 717 | *pin++ = '\0'; | 
|  | 718 |  | 
|  | 719 | if (os_strcmp(cmd, "any") == 0) | 
|  | 720 | _bssid = NULL; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 721 | else if (os_strcmp(cmd, "get") == 0) { | 
|  | 722 | ret = wps_generate_pin(); | 
|  | 723 | goto done; | 
|  | 724 | } else if (hwaddr_aton(cmd, bssid)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 725 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", | 
|  | 726 | cmd); | 
|  | 727 | return -1; | 
|  | 728 | } | 
|  | 729 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 730 | #ifdef CONFIG_AP | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 731 | if (wpa_s->ap_iface) { | 
|  | 732 | int timeout = 0; | 
|  | 733 | char *pos; | 
|  | 734 |  | 
|  | 735 | if (pin) { | 
|  | 736 | pos = os_strchr(pin, ' '); | 
|  | 737 | if (pos) { | 
|  | 738 | *pos++ = '\0'; | 
|  | 739 | timeout = atoi(pos); | 
|  | 740 | } | 
|  | 741 | } | 
|  | 742 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 743 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 744 | buf, buflen, timeout); | 
|  | 745 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 746 | #endif /* CONFIG_AP */ | 
|  | 747 |  | 
|  | 748 | if (pin) { | 
|  | 749 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, | 
|  | 750 | DEV_PW_DEFAULT); | 
|  | 751 | if (ret < 0) | 
|  | 752 | return -1; | 
|  | 753 | ret = os_snprintf(buf, buflen, "%s", pin); | 
|  | 754 | if (ret < 0 || (size_t) ret >= buflen) | 
|  | 755 | return -1; | 
|  | 756 | return ret; | 
|  | 757 | } | 
|  | 758 |  | 
|  | 759 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); | 
|  | 760 | if (ret < 0) | 
|  | 761 | return -1; | 
|  | 762 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 763 | done: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 764 | /* Return the generated PIN */ | 
|  | 765 | ret = os_snprintf(buf, buflen, "%08d", ret); | 
|  | 766 | if (ret < 0 || (size_t) ret >= buflen) | 
|  | 767 | return -1; | 
|  | 768 | return ret; | 
|  | 769 | } | 
|  | 770 |  | 
|  | 771 |  | 
|  | 772 | static int wpa_supplicant_ctrl_iface_wps_check_pin( | 
|  | 773 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | 
|  | 774 | { | 
|  | 775 | char pin[9]; | 
|  | 776 | size_t len; | 
|  | 777 | char *pos; | 
|  | 778 | int ret; | 
|  | 779 |  | 
|  | 780 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", | 
|  | 781 | (u8 *) cmd, os_strlen(cmd)); | 
|  | 782 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { | 
|  | 783 | if (*pos < '0' || *pos > '9') | 
|  | 784 | continue; | 
|  | 785 | pin[len++] = *pos; | 
|  | 786 | if (len == 9) { | 
|  | 787 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); | 
|  | 788 | return -1; | 
|  | 789 | } | 
|  | 790 | } | 
|  | 791 | if (len != 4 && len != 8) { | 
|  | 792 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); | 
|  | 793 | return -1; | 
|  | 794 | } | 
|  | 795 | pin[len] = '\0'; | 
|  | 796 |  | 
|  | 797 | if (len == 8) { | 
|  | 798 | unsigned int pin_val; | 
|  | 799 | pin_val = atoi(pin); | 
|  | 800 | if (!wps_pin_valid(pin_val)) { | 
|  | 801 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); | 
|  | 802 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); | 
|  | 803 | if (ret < 0 || (size_t) ret >= buflen) | 
|  | 804 | return -1; | 
|  | 805 | return ret; | 
|  | 806 | } | 
|  | 807 | } | 
|  | 808 |  | 
|  | 809 | ret = os_snprintf(buf, buflen, "%s", pin); | 
|  | 810 | if (ret < 0 || (size_t) ret >= buflen) | 
|  | 811 | return -1; | 
|  | 812 |  | 
|  | 813 | return ret; | 
|  | 814 | } | 
|  | 815 |  | 
|  | 816 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 817 | #ifdef CONFIG_WPS_NFC | 
|  | 818 |  | 
|  | 819 | static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, | 
|  | 820 | char *cmd) | 
|  | 821 | { | 
|  | 822 | u8 bssid[ETH_ALEN], *_bssid = bssid; | 
|  | 823 |  | 
|  | 824 | if (cmd == NULL || cmd[0] == '\0') | 
|  | 825 | _bssid = NULL; | 
|  | 826 | else if (hwaddr_aton(cmd, bssid)) | 
|  | 827 | return -1; | 
|  | 828 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 829 | return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL, | 
|  | 830 | 0, 0); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 831 | } | 
|  | 832 |  | 
|  | 833 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 834 | static int wpa_supplicant_ctrl_iface_wps_nfc_config_token( | 
|  | 835 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | 
|  | 836 | { | 
|  | 837 | int ndef; | 
|  | 838 | struct wpabuf *buf; | 
|  | 839 | int res; | 
| Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 840 | char *pos; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 841 |  | 
| Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 842 | pos = os_strchr(cmd, ' '); | 
|  | 843 | if (pos) | 
|  | 844 | *pos++ = '\0'; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 845 | if (os_strcmp(cmd, "WPS") == 0) | 
|  | 846 | ndef = 0; | 
|  | 847 | else if (os_strcmp(cmd, "NDEF") == 0) | 
|  | 848 | ndef = 1; | 
|  | 849 | else | 
|  | 850 | return -1; | 
|  | 851 |  | 
| Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 852 | buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 853 | if (buf == NULL) | 
|  | 854 | return -1; | 
|  | 855 |  | 
|  | 856 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | 
|  | 857 | wpabuf_len(buf)); | 
|  | 858 | reply[res++] = '\n'; | 
|  | 859 | reply[res] = '\0'; | 
|  | 860 |  | 
|  | 861 | wpabuf_free(buf); | 
|  | 862 |  | 
|  | 863 | return res; | 
|  | 864 | } | 
|  | 865 |  | 
|  | 866 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 867 | static int wpa_supplicant_ctrl_iface_wps_nfc_token( | 
|  | 868 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | 
|  | 869 | { | 
|  | 870 | int ndef; | 
|  | 871 | struct wpabuf *buf; | 
|  | 872 | int res; | 
|  | 873 |  | 
|  | 874 | if (os_strcmp(cmd, "WPS") == 0) | 
|  | 875 | ndef = 0; | 
|  | 876 | else if (os_strcmp(cmd, "NDEF") == 0) | 
|  | 877 | ndef = 1; | 
|  | 878 | else | 
|  | 879 | return -1; | 
|  | 880 |  | 
|  | 881 | buf = wpas_wps_nfc_token(wpa_s, ndef); | 
|  | 882 | if (buf == NULL) | 
|  | 883 | return -1; | 
|  | 884 |  | 
|  | 885 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | 
|  | 886 | wpabuf_len(buf)); | 
|  | 887 | reply[res++] = '\n'; | 
|  | 888 | reply[res] = '\0'; | 
|  | 889 |  | 
|  | 890 | wpabuf_free(buf); | 
|  | 891 |  | 
|  | 892 | return res; | 
|  | 893 | } | 
|  | 894 |  | 
|  | 895 |  | 
|  | 896 | static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( | 
|  | 897 | struct wpa_supplicant *wpa_s, char *pos) | 
|  | 898 | { | 
|  | 899 | size_t len; | 
|  | 900 | struct wpabuf *buf; | 
|  | 901 | int ret; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 902 | char *freq; | 
|  | 903 | int forced_freq = 0; | 
|  | 904 |  | 
|  | 905 | freq = strstr(pos, " freq="); | 
|  | 906 | if (freq) { | 
|  | 907 | *freq = '\0'; | 
|  | 908 | freq += 6; | 
|  | 909 | forced_freq = atoi(freq); | 
|  | 910 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 911 |  | 
|  | 912 | len = os_strlen(pos); | 
|  | 913 | if (len & 0x01) | 
|  | 914 | return -1; | 
|  | 915 | len /= 2; | 
|  | 916 |  | 
|  | 917 | buf = wpabuf_alloc(len); | 
|  | 918 | if (buf == NULL) | 
|  | 919 | return -1; | 
|  | 920 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | 
|  | 921 | wpabuf_free(buf); | 
|  | 922 | return -1; | 
|  | 923 | } | 
|  | 924 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 925 | ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 926 | wpabuf_free(buf); | 
|  | 927 |  | 
|  | 928 | return ret; | 
|  | 929 | } | 
|  | 930 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 931 |  | 
|  | 932 | static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 933 | char *reply, size_t max_len, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 934 | int ndef) | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 935 | { | 
|  | 936 | struct wpabuf *buf; | 
|  | 937 | int res; | 
|  | 938 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 939 | buf = wpas_wps_nfc_handover_req(wpa_s, ndef); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 940 | if (buf == NULL) | 
|  | 941 | return -1; | 
|  | 942 |  | 
|  | 943 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | 
|  | 944 | wpabuf_len(buf)); | 
|  | 945 | reply[res++] = '\n'; | 
|  | 946 | reply[res] = '\0'; | 
|  | 947 |  | 
|  | 948 | wpabuf_free(buf); | 
|  | 949 |  | 
|  | 950 | return res; | 
|  | 951 | } | 
|  | 952 |  | 
|  | 953 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 954 | static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s, | 
|  | 955 | char *reply, size_t max_len, | 
|  | 956 | int ndef) | 
|  | 957 | { | 
|  | 958 | struct wpabuf *buf; | 
|  | 959 | int res; | 
|  | 960 |  | 
|  | 961 | buf = wpas_p2p_nfc_handover_req(wpa_s, ndef); | 
|  | 962 | if (buf == NULL) { | 
|  | 963 | wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request"); | 
|  | 964 | return -1; | 
|  | 965 | } | 
|  | 966 |  | 
|  | 967 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | 
|  | 968 | wpabuf_len(buf)); | 
|  | 969 | reply[res++] = '\n'; | 
|  | 970 | reply[res] = '\0'; | 
|  | 971 |  | 
|  | 972 | wpabuf_free(buf); | 
|  | 973 |  | 
|  | 974 | return res; | 
|  | 975 | } | 
|  | 976 |  | 
|  | 977 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 978 | static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, | 
|  | 979 | char *cmd, char *reply, | 
|  | 980 | size_t max_len) | 
|  | 981 | { | 
|  | 982 | char *pos; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 983 | int ndef; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 984 |  | 
|  | 985 | pos = os_strchr(cmd, ' '); | 
|  | 986 | if (pos == NULL) | 
|  | 987 | return -1; | 
|  | 988 | *pos++ = '\0'; | 
|  | 989 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 990 | if (os_strcmp(cmd, "WPS") == 0) | 
|  | 991 | ndef = 0; | 
|  | 992 | else if (os_strcmp(cmd, "NDEF") == 0) | 
|  | 993 | ndef = 1; | 
|  | 994 | else | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 995 | return -1; | 
|  | 996 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 997 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 998 | if (!ndef) | 
|  | 999 | return -1; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1000 | return wpas_ctrl_nfc_get_handover_req_wps( | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1001 | wpa_s, reply, max_len, ndef); | 
|  | 1002 | } | 
|  | 1003 |  | 
|  | 1004 | if (os_strcmp(pos, "P2P-CR") == 0) { | 
|  | 1005 | return wpas_ctrl_nfc_get_handover_req_p2p( | 
|  | 1006 | wpa_s, reply, max_len, ndef); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1007 | } | 
|  | 1008 |  | 
|  | 1009 | return -1; | 
|  | 1010 | } | 
|  | 1011 |  | 
|  | 1012 |  | 
|  | 1013 | static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1014 | char *reply, size_t max_len, | 
| Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1015 | int ndef, int cr, char *uuid) | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1016 | { | 
|  | 1017 | struct wpabuf *buf; | 
|  | 1018 | int res; | 
|  | 1019 |  | 
| Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1020 | buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1021 | if (buf == NULL) | 
|  | 1022 | return -1; | 
|  | 1023 |  | 
|  | 1024 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | 
|  | 1025 | wpabuf_len(buf)); | 
|  | 1026 | reply[res++] = '\n'; | 
|  | 1027 | reply[res] = '\0'; | 
|  | 1028 |  | 
|  | 1029 | wpabuf_free(buf); | 
|  | 1030 |  | 
|  | 1031 | return res; | 
|  | 1032 | } | 
|  | 1033 |  | 
|  | 1034 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1035 | static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s, | 
|  | 1036 | char *reply, size_t max_len, | 
|  | 1037 | int ndef, int tag) | 
|  | 1038 | { | 
|  | 1039 | struct wpabuf *buf; | 
|  | 1040 | int res; | 
|  | 1041 |  | 
|  | 1042 | buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag); | 
|  | 1043 | if (buf == NULL) | 
|  | 1044 | return -1; | 
|  | 1045 |  | 
|  | 1046 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | 
|  | 1047 | wpabuf_len(buf)); | 
|  | 1048 | reply[res++] = '\n'; | 
|  | 1049 | reply[res] = '\0'; | 
|  | 1050 |  | 
|  | 1051 | wpabuf_free(buf); | 
|  | 1052 |  | 
|  | 1053 | return res; | 
|  | 1054 | } | 
|  | 1055 |  | 
|  | 1056 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1057 | static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, | 
|  | 1058 | char *cmd, char *reply, | 
|  | 1059 | size_t max_len) | 
|  | 1060 | { | 
| Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1061 | char *pos, *pos2; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1062 | int ndef; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1063 |  | 
|  | 1064 | pos = os_strchr(cmd, ' '); | 
|  | 1065 | if (pos == NULL) | 
|  | 1066 | return -1; | 
|  | 1067 | *pos++ = '\0'; | 
|  | 1068 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1069 | if (os_strcmp(cmd, "WPS") == 0) | 
|  | 1070 | ndef = 0; | 
|  | 1071 | else if (os_strcmp(cmd, "NDEF") == 0) | 
|  | 1072 | ndef = 1; | 
|  | 1073 | else | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1074 | return -1; | 
|  | 1075 |  | 
| Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1076 | pos2 = os_strchr(pos, ' '); | 
|  | 1077 | if (pos2) | 
|  | 1078 | *pos2++ = '\0'; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1079 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1080 | if (!ndef) | 
|  | 1081 | return -1; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1082 | return wpas_ctrl_nfc_get_handover_sel_wps( | 
|  | 1083 | wpa_s, reply, max_len, ndef, | 
| Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1084 | os_strcmp(pos, "WPS-CR") == 0, pos2); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1085 | } | 
|  | 1086 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1087 | if (os_strcmp(pos, "P2P-CR") == 0) { | 
|  | 1088 | return wpas_ctrl_nfc_get_handover_sel_p2p( | 
|  | 1089 | wpa_s, reply, max_len, ndef, 0); | 
|  | 1090 | } | 
|  | 1091 |  | 
|  | 1092 | if (os_strcmp(pos, "P2P-CR-TAG") == 0) { | 
|  | 1093 | return wpas_ctrl_nfc_get_handover_sel_p2p( | 
|  | 1094 | wpa_s, reply, max_len, ndef, 1); | 
|  | 1095 | } | 
|  | 1096 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1097 | return -1; | 
|  | 1098 | } | 
|  | 1099 |  | 
|  | 1100 |  | 
|  | 1101 | static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant *wpa_s, | 
|  | 1102 | char *cmd, char *reply, | 
|  | 1103 | size_t max_len) | 
|  | 1104 | { | 
|  | 1105 | size_t len; | 
|  | 1106 | struct wpabuf *buf; | 
|  | 1107 | int ret; | 
|  | 1108 |  | 
|  | 1109 | len = os_strlen(cmd); | 
|  | 1110 | if (len & 0x01) | 
|  | 1111 | return -1; | 
|  | 1112 | len /= 2; | 
|  | 1113 |  | 
|  | 1114 | buf = wpabuf_alloc(len); | 
|  | 1115 | if (buf == NULL) | 
|  | 1116 | return -1; | 
|  | 1117 | if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) { | 
|  | 1118 | wpabuf_free(buf); | 
|  | 1119 | return -1; | 
|  | 1120 | } | 
|  | 1121 |  | 
|  | 1122 | ret = wpas_wps_nfc_rx_handover_req(wpa_s, buf); | 
|  | 1123 | wpabuf_free(buf); | 
|  | 1124 |  | 
|  | 1125 | return ret; | 
|  | 1126 | } | 
|  | 1127 |  | 
|  | 1128 |  | 
|  | 1129 | static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s, | 
|  | 1130 | char *cmd) | 
|  | 1131 | { | 
|  | 1132 | size_t len; | 
|  | 1133 | struct wpabuf *buf; | 
|  | 1134 | int ret; | 
|  | 1135 |  | 
|  | 1136 | len = os_strlen(cmd); | 
|  | 1137 | if (len & 0x01) | 
|  | 1138 | return -1; | 
|  | 1139 | len /= 2; | 
|  | 1140 |  | 
|  | 1141 | buf = wpabuf_alloc(len); | 
|  | 1142 | if (buf == NULL) | 
|  | 1143 | return -1; | 
|  | 1144 | if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) { | 
|  | 1145 | wpabuf_free(buf); | 
|  | 1146 | return -1; | 
|  | 1147 | } | 
|  | 1148 |  | 
|  | 1149 | ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf); | 
|  | 1150 | wpabuf_free(buf); | 
|  | 1151 |  | 
|  | 1152 | return ret; | 
|  | 1153 | } | 
|  | 1154 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1155 |  | 
|  | 1156 | static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s, | 
|  | 1157 | char *cmd) | 
|  | 1158 | { | 
|  | 1159 | size_t len; | 
|  | 1160 | struct wpabuf *req, *sel; | 
|  | 1161 | int ret; | 
|  | 1162 | char *pos, *role, *type, *pos2; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1163 | char *freq; | 
|  | 1164 | int forced_freq = 0; | 
|  | 1165 |  | 
|  | 1166 | freq = strstr(cmd, " freq="); | 
|  | 1167 | if (freq) { | 
|  | 1168 | *freq = '\0'; | 
|  | 1169 | freq += 6; | 
|  | 1170 | forced_freq = atoi(freq); | 
|  | 1171 | } | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1172 |  | 
|  | 1173 | role = cmd; | 
|  | 1174 | pos = os_strchr(role, ' '); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1175 | if (pos == NULL) { | 
|  | 1176 | wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1177 | return -1; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1178 | } | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1179 | *pos++ = '\0'; | 
|  | 1180 |  | 
|  | 1181 | type = pos; | 
|  | 1182 | pos = os_strchr(type, ' '); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1183 | if (pos == NULL) { | 
|  | 1184 | wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1185 | return -1; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1186 | } | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1187 | *pos++ = '\0'; | 
|  | 1188 |  | 
|  | 1189 | pos2 = os_strchr(pos, ' '); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1190 | if (pos2 == NULL) { | 
|  | 1191 | wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1192 | return -1; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1193 | } | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1194 | *pos2++ = '\0'; | 
|  | 1195 |  | 
|  | 1196 | len = os_strlen(pos); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1197 | if (len & 0x01) { | 
|  | 1198 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1199 | return -1; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1200 | } | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1201 | len /= 2; | 
|  | 1202 |  | 
|  | 1203 | req = wpabuf_alloc(len); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1204 | if (req == NULL) { | 
|  | 1205 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1206 | return -1; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1207 | } | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1208 | if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1209 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1210 | wpabuf_free(req); | 
|  | 1211 | return -1; | 
|  | 1212 | } | 
|  | 1213 |  | 
|  | 1214 | len = os_strlen(pos2); | 
|  | 1215 | if (len & 0x01) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1216 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1217 | wpabuf_free(req); | 
|  | 1218 | return -1; | 
|  | 1219 | } | 
|  | 1220 | len /= 2; | 
|  | 1221 |  | 
|  | 1222 | sel = wpabuf_alloc(len); | 
|  | 1223 | if (sel == NULL) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1224 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1225 | wpabuf_free(req); | 
|  | 1226 | return -1; | 
|  | 1227 | } | 
|  | 1228 | if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1229 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1230 | wpabuf_free(req); | 
|  | 1231 | wpabuf_free(sel); | 
|  | 1232 | return -1; | 
|  | 1233 | } | 
|  | 1234 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1235 | wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d", | 
|  | 1236 | role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel)); | 
|  | 1237 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1238 | if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) { | 
|  | 1239 | ret = wpas_wps_nfc_report_handover(wpa_s, req, sel); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1240 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) | 
|  | 1241 | { | 
|  | 1242 | ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel); | 
|  | 1243 | if (ret < 0) | 
|  | 1244 | ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel); | 
|  | 1245 | } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0) | 
|  | 1246 | { | 
|  | 1247 | ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0); | 
|  | 1248 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0) | 
|  | 1249 | { | 
|  | 1250 | ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel, | 
|  | 1251 | forced_freq); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1252 | } else { | 
|  | 1253 | wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover " | 
|  | 1254 | "reported: role=%s type=%s", role, type); | 
|  | 1255 | ret = -1; | 
|  | 1256 | } | 
|  | 1257 | wpabuf_free(req); | 
|  | 1258 | wpabuf_free(sel); | 
|  | 1259 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1260 | if (ret) | 
|  | 1261 | wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages"); | 
|  | 1262 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1263 | return ret; | 
|  | 1264 | } | 
|  | 1265 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1266 | #endif /* CONFIG_WPS_NFC */ | 
|  | 1267 |  | 
|  | 1268 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1269 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, | 
|  | 1270 | char *cmd) | 
|  | 1271 | { | 
|  | 1272 | u8 bssid[ETH_ALEN]; | 
|  | 1273 | char *pin; | 
|  | 1274 | char *new_ssid; | 
|  | 1275 | char *new_auth; | 
|  | 1276 | char *new_encr; | 
|  | 1277 | char *new_key; | 
|  | 1278 | struct wps_new_ap_settings ap; | 
|  | 1279 |  | 
|  | 1280 | pin = os_strchr(cmd, ' '); | 
|  | 1281 | if (pin == NULL) | 
|  | 1282 | return -1; | 
|  | 1283 | *pin++ = '\0'; | 
|  | 1284 |  | 
|  | 1285 | if (hwaddr_aton(cmd, bssid)) { | 
|  | 1286 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", | 
|  | 1287 | cmd); | 
|  | 1288 | return -1; | 
|  | 1289 | } | 
|  | 1290 |  | 
|  | 1291 | new_ssid = os_strchr(pin, ' '); | 
|  | 1292 | if (new_ssid == NULL) | 
|  | 1293 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); | 
|  | 1294 | *new_ssid++ = '\0'; | 
|  | 1295 |  | 
|  | 1296 | new_auth = os_strchr(new_ssid, ' '); | 
|  | 1297 | if (new_auth == NULL) | 
|  | 1298 | return -1; | 
|  | 1299 | *new_auth++ = '\0'; | 
|  | 1300 |  | 
|  | 1301 | new_encr = os_strchr(new_auth, ' '); | 
|  | 1302 | if (new_encr == NULL) | 
|  | 1303 | return -1; | 
|  | 1304 | *new_encr++ = '\0'; | 
|  | 1305 |  | 
|  | 1306 | new_key = os_strchr(new_encr, ' '); | 
|  | 1307 | if (new_key == NULL) | 
|  | 1308 | return -1; | 
|  | 1309 | *new_key++ = '\0'; | 
|  | 1310 |  | 
|  | 1311 | os_memset(&ap, 0, sizeof(ap)); | 
|  | 1312 | ap.ssid_hex = new_ssid; | 
|  | 1313 | ap.auth = new_auth; | 
|  | 1314 | ap.encr = new_encr; | 
|  | 1315 | ap.key_hex = new_key; | 
|  | 1316 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); | 
|  | 1317 | } | 
|  | 1318 |  | 
|  | 1319 |  | 
|  | 1320 | #ifdef CONFIG_AP | 
|  | 1321 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, | 
|  | 1322 | char *cmd, char *buf, | 
|  | 1323 | size_t buflen) | 
|  | 1324 | { | 
|  | 1325 | int timeout = 300; | 
|  | 1326 | char *pos; | 
|  | 1327 | const char *pin_txt; | 
|  | 1328 |  | 
|  | 1329 | if (!wpa_s->ap_iface) | 
|  | 1330 | return -1; | 
|  | 1331 |  | 
|  | 1332 | pos = os_strchr(cmd, ' '); | 
|  | 1333 | if (pos) | 
|  | 1334 | *pos++ = '\0'; | 
|  | 1335 |  | 
|  | 1336 | if (os_strcmp(cmd, "disable") == 0) { | 
|  | 1337 | wpas_wps_ap_pin_disable(wpa_s); | 
|  | 1338 | return os_snprintf(buf, buflen, "OK\n"); | 
|  | 1339 | } | 
|  | 1340 |  | 
|  | 1341 | if (os_strcmp(cmd, "random") == 0) { | 
|  | 1342 | if (pos) | 
|  | 1343 | timeout = atoi(pos); | 
|  | 1344 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); | 
|  | 1345 | if (pin_txt == NULL) | 
|  | 1346 | return -1; | 
|  | 1347 | return os_snprintf(buf, buflen, "%s", pin_txt); | 
|  | 1348 | } | 
|  | 1349 |  | 
|  | 1350 | if (os_strcmp(cmd, "get") == 0) { | 
|  | 1351 | pin_txt = wpas_wps_ap_pin_get(wpa_s); | 
|  | 1352 | if (pin_txt == NULL) | 
|  | 1353 | return -1; | 
|  | 1354 | return os_snprintf(buf, buflen, "%s", pin_txt); | 
|  | 1355 | } | 
|  | 1356 |  | 
|  | 1357 | if (os_strcmp(cmd, "set") == 0) { | 
|  | 1358 | char *pin; | 
|  | 1359 | if (pos == NULL) | 
|  | 1360 | return -1; | 
|  | 1361 | pin = pos; | 
|  | 1362 | pos = os_strchr(pos, ' '); | 
|  | 1363 | if (pos) { | 
|  | 1364 | *pos++ = '\0'; | 
|  | 1365 | timeout = atoi(pos); | 
|  | 1366 | } | 
|  | 1367 | if (os_strlen(pin) > buflen) | 
|  | 1368 | return -1; | 
|  | 1369 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) | 
|  | 1370 | return -1; | 
|  | 1371 | return os_snprintf(buf, buflen, "%s", pin); | 
|  | 1372 | } | 
|  | 1373 |  | 
|  | 1374 | return -1; | 
|  | 1375 | } | 
|  | 1376 | #endif /* CONFIG_AP */ | 
|  | 1377 |  | 
|  | 1378 |  | 
|  | 1379 | #ifdef CONFIG_WPS_ER | 
|  | 1380 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, | 
|  | 1381 | char *cmd) | 
|  | 1382 | { | 
|  | 1383 | char *uuid = cmd, *pin, *pos; | 
|  | 1384 | u8 addr_buf[ETH_ALEN], *addr = NULL; | 
|  | 1385 | pin = os_strchr(uuid, ' '); | 
|  | 1386 | if (pin == NULL) | 
|  | 1387 | return -1; | 
|  | 1388 | *pin++ = '\0'; | 
|  | 1389 | pos = os_strchr(pin, ' '); | 
|  | 1390 | if (pos) { | 
|  | 1391 | *pos++ = '\0'; | 
|  | 1392 | if (hwaddr_aton(pos, addr_buf) == 0) | 
|  | 1393 | addr = addr_buf; | 
|  | 1394 | } | 
|  | 1395 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); | 
|  | 1396 | } | 
|  | 1397 |  | 
|  | 1398 |  | 
|  | 1399 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, | 
|  | 1400 | char *cmd) | 
|  | 1401 | { | 
|  | 1402 | char *uuid = cmd, *pin; | 
|  | 1403 | pin = os_strchr(uuid, ' '); | 
|  | 1404 | if (pin == NULL) | 
|  | 1405 | return -1; | 
|  | 1406 | *pin++ = '\0'; | 
|  | 1407 | return wpas_wps_er_learn(wpa_s, uuid, pin); | 
|  | 1408 | } | 
|  | 1409 |  | 
|  | 1410 |  | 
|  | 1411 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( | 
|  | 1412 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 1413 | { | 
|  | 1414 | char *uuid = cmd, *id; | 
|  | 1415 | id = os_strchr(uuid, ' '); | 
|  | 1416 | if (id == NULL) | 
|  | 1417 | return -1; | 
|  | 1418 | *id++ = '\0'; | 
|  | 1419 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); | 
|  | 1420 | } | 
|  | 1421 |  | 
|  | 1422 |  | 
|  | 1423 | static int wpa_supplicant_ctrl_iface_wps_er_config( | 
|  | 1424 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 1425 | { | 
|  | 1426 | char *pin; | 
|  | 1427 | char *new_ssid; | 
|  | 1428 | char *new_auth; | 
|  | 1429 | char *new_encr; | 
|  | 1430 | char *new_key; | 
|  | 1431 | struct wps_new_ap_settings ap; | 
|  | 1432 |  | 
|  | 1433 | pin = os_strchr(cmd, ' '); | 
|  | 1434 | if (pin == NULL) | 
|  | 1435 | return -1; | 
|  | 1436 | *pin++ = '\0'; | 
|  | 1437 |  | 
|  | 1438 | new_ssid = os_strchr(pin, ' '); | 
|  | 1439 | if (new_ssid == NULL) | 
|  | 1440 | return -1; | 
|  | 1441 | *new_ssid++ = '\0'; | 
|  | 1442 |  | 
|  | 1443 | new_auth = os_strchr(new_ssid, ' '); | 
|  | 1444 | if (new_auth == NULL) | 
|  | 1445 | return -1; | 
|  | 1446 | *new_auth++ = '\0'; | 
|  | 1447 |  | 
|  | 1448 | new_encr = os_strchr(new_auth, ' '); | 
|  | 1449 | if (new_encr == NULL) | 
|  | 1450 | return -1; | 
|  | 1451 | *new_encr++ = '\0'; | 
|  | 1452 |  | 
|  | 1453 | new_key = os_strchr(new_encr, ' '); | 
|  | 1454 | if (new_key == NULL) | 
|  | 1455 | return -1; | 
|  | 1456 | *new_key++ = '\0'; | 
|  | 1457 |  | 
|  | 1458 | os_memset(&ap, 0, sizeof(ap)); | 
|  | 1459 | ap.ssid_hex = new_ssid; | 
|  | 1460 | ap.auth = new_auth; | 
|  | 1461 | ap.encr = new_encr; | 
|  | 1462 | ap.key_hex = new_key; | 
|  | 1463 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); | 
|  | 1464 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1465 |  | 
|  | 1466 |  | 
|  | 1467 | #ifdef CONFIG_WPS_NFC | 
|  | 1468 | static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | 
|  | 1469 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | 
|  | 1470 | { | 
|  | 1471 | int ndef; | 
|  | 1472 | struct wpabuf *buf; | 
|  | 1473 | int res; | 
|  | 1474 | char *uuid; | 
|  | 1475 |  | 
|  | 1476 | uuid = os_strchr(cmd, ' '); | 
|  | 1477 | if (uuid == NULL) | 
|  | 1478 | return -1; | 
|  | 1479 | *uuid++ = '\0'; | 
|  | 1480 |  | 
|  | 1481 | if (os_strcmp(cmd, "WPS") == 0) | 
|  | 1482 | ndef = 0; | 
|  | 1483 | else if (os_strcmp(cmd, "NDEF") == 0) | 
|  | 1484 | ndef = 1; | 
|  | 1485 | else | 
|  | 1486 | return -1; | 
|  | 1487 |  | 
|  | 1488 | buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); | 
|  | 1489 | if (buf == NULL) | 
|  | 1490 | return -1; | 
|  | 1491 |  | 
|  | 1492 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | 
|  | 1493 | wpabuf_len(buf)); | 
|  | 1494 | reply[res++] = '\n'; | 
|  | 1495 | reply[res] = '\0'; | 
|  | 1496 |  | 
|  | 1497 | wpabuf_free(buf); | 
|  | 1498 |  | 
|  | 1499 | return res; | 
|  | 1500 | } | 
|  | 1501 | #endif /* CONFIG_WPS_NFC */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1502 | #endif /* CONFIG_WPS_ER */ | 
|  | 1503 |  | 
|  | 1504 | #endif /* CONFIG_WPS */ | 
|  | 1505 |  | 
|  | 1506 |  | 
|  | 1507 | #ifdef CONFIG_IBSS_RSN | 
|  | 1508 | static int wpa_supplicant_ctrl_iface_ibss_rsn( | 
|  | 1509 | struct wpa_supplicant *wpa_s, char *addr) | 
|  | 1510 | { | 
|  | 1511 | u8 peer[ETH_ALEN]; | 
|  | 1512 |  | 
|  | 1513 | if (hwaddr_aton(addr, peer)) { | 
|  | 1514 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " | 
|  | 1515 | "address '%s'", addr); | 
|  | 1516 | return -1; | 
|  | 1517 | } | 
|  | 1518 |  | 
|  | 1519 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, | 
|  | 1520 | MAC2STR(peer)); | 
|  | 1521 |  | 
|  | 1522 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); | 
|  | 1523 | } | 
|  | 1524 | #endif /* CONFIG_IBSS_RSN */ | 
|  | 1525 |  | 
|  | 1526 |  | 
|  | 1527 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, | 
|  | 1528 | char *rsp) | 
|  | 1529 | { | 
|  | 1530 | #ifdef IEEE8021X_EAPOL | 
|  | 1531 | char *pos, *id_pos; | 
|  | 1532 | int id; | 
|  | 1533 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1534 |  | 
|  | 1535 | pos = os_strchr(rsp, '-'); | 
|  | 1536 | if (pos == NULL) | 
|  | 1537 | return -1; | 
|  | 1538 | *pos++ = '\0'; | 
|  | 1539 | id_pos = pos; | 
|  | 1540 | pos = os_strchr(pos, ':'); | 
|  | 1541 | if (pos == NULL) | 
|  | 1542 | return -1; | 
|  | 1543 | *pos++ = '\0'; | 
|  | 1544 | id = atoi(id_pos); | 
|  | 1545 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); | 
|  | 1546 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | 
|  | 1547 | (u8 *) pos, os_strlen(pos)); | 
|  | 1548 |  | 
|  | 1549 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 1550 | if (ssid == NULL) { | 
|  | 1551 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | 
|  | 1552 | "to update", id); | 
|  | 1553 | return -1; | 
|  | 1554 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1555 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1556 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, | 
|  | 1557 | pos); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1558 | #else /* IEEE8021X_EAPOL */ | 
|  | 1559 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); | 
|  | 1560 | return -1; | 
|  | 1561 | #endif /* IEEE8021X_EAPOL */ | 
|  | 1562 | } | 
|  | 1563 |  | 
|  | 1564 |  | 
|  | 1565 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, | 
|  | 1566 | const char *params, | 
|  | 1567 | char *buf, size_t buflen) | 
|  | 1568 | { | 
|  | 1569 | char *pos, *end, tmp[30]; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1570 | int res, verbose, wps, ret; | 
| Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1571 |  | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1572 | if (os_strcmp(params, "-DRIVER") == 0) | 
|  | 1573 | return wpa_drv_status(wpa_s, buf, buflen); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1574 | verbose = os_strcmp(params, "-VERBOSE") == 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1575 | wps = os_strcmp(params, "-WPS") == 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1576 | pos = buf; | 
|  | 1577 | end = buf + buflen; | 
|  | 1578 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { | 
|  | 1579 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
|  | 1580 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | 
|  | 1581 | MAC2STR(wpa_s->bssid)); | 
|  | 1582 | if (ret < 0 || ret >= end - pos) | 
|  | 1583 | return pos - buf; | 
|  | 1584 | pos += ret; | 
|  | 1585 | if (ssid) { | 
|  | 1586 | u8 *_ssid = ssid->ssid; | 
|  | 1587 | size_t ssid_len = ssid->ssid_len; | 
|  | 1588 | u8 ssid_buf[MAX_SSID_LEN]; | 
|  | 1589 | if (ssid_len == 0) { | 
|  | 1590 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); | 
|  | 1591 | if (_res < 0) | 
|  | 1592 | ssid_len = 0; | 
|  | 1593 | else | 
|  | 1594 | ssid_len = _res; | 
|  | 1595 | _ssid = ssid_buf; | 
|  | 1596 | } | 
|  | 1597 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", | 
|  | 1598 | wpa_ssid_txt(_ssid, ssid_len), | 
|  | 1599 | ssid->id); | 
|  | 1600 | if (ret < 0 || ret >= end - pos) | 
|  | 1601 | return pos - buf; | 
|  | 1602 | pos += ret; | 
|  | 1603 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1604 | if (wps && ssid->passphrase && | 
|  | 1605 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && | 
|  | 1606 | (ssid->mode == WPAS_MODE_AP || | 
|  | 1607 | ssid->mode == WPAS_MODE_P2P_GO)) { | 
|  | 1608 | ret = os_snprintf(pos, end - pos, | 
|  | 1609 | "passphrase=%s\n", | 
|  | 1610 | ssid->passphrase); | 
|  | 1611 | if (ret < 0 || ret >= end - pos) | 
|  | 1612 | return pos - buf; | 
|  | 1613 | pos += ret; | 
|  | 1614 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1615 | if (ssid->id_str) { | 
|  | 1616 | ret = os_snprintf(pos, end - pos, | 
|  | 1617 | "id_str=%s\n", | 
|  | 1618 | ssid->id_str); | 
|  | 1619 | if (ret < 0 || ret >= end - pos) | 
|  | 1620 | return pos - buf; | 
|  | 1621 | pos += ret; | 
|  | 1622 | } | 
|  | 1623 |  | 
|  | 1624 | switch (ssid->mode) { | 
|  | 1625 | case WPAS_MODE_INFRA: | 
|  | 1626 | ret = os_snprintf(pos, end - pos, | 
|  | 1627 | "mode=station\n"); | 
|  | 1628 | break; | 
|  | 1629 | case WPAS_MODE_IBSS: | 
|  | 1630 | ret = os_snprintf(pos, end - pos, | 
|  | 1631 | "mode=IBSS\n"); | 
|  | 1632 | break; | 
|  | 1633 | case WPAS_MODE_AP: | 
|  | 1634 | ret = os_snprintf(pos, end - pos, | 
|  | 1635 | "mode=AP\n"); | 
|  | 1636 | break; | 
|  | 1637 | case WPAS_MODE_P2P_GO: | 
|  | 1638 | ret = os_snprintf(pos, end - pos, | 
|  | 1639 | "mode=P2P GO\n"); | 
|  | 1640 | break; | 
|  | 1641 | case WPAS_MODE_P2P_GROUP_FORMATION: | 
|  | 1642 | ret = os_snprintf(pos, end - pos, | 
|  | 1643 | "mode=P2P GO - group " | 
|  | 1644 | "formation\n"); | 
|  | 1645 | break; | 
|  | 1646 | default: | 
|  | 1647 | ret = 0; | 
|  | 1648 | break; | 
|  | 1649 | } | 
|  | 1650 | if (ret < 0 || ret >= end - pos) | 
|  | 1651 | return pos - buf; | 
|  | 1652 | pos += ret; | 
|  | 1653 | } | 
|  | 1654 |  | 
|  | 1655 | #ifdef CONFIG_AP | 
|  | 1656 | if (wpa_s->ap_iface) { | 
|  | 1657 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, | 
|  | 1658 | end - pos, | 
|  | 1659 | verbose); | 
|  | 1660 | } else | 
|  | 1661 | #endif /* CONFIG_AP */ | 
|  | 1662 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); | 
|  | 1663 | } | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1664 | #ifdef CONFIG_SAE | 
|  | 1665 | if (wpa_s->wpa_state >= WPA_ASSOCIATED && | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1666 | #ifdef CONFIG_AP | 
|  | 1667 | !wpa_s->ap_iface && | 
|  | 1668 | #endif /* CONFIG_AP */ | 
|  | 1669 | wpa_s->sme.sae.state == SAE_ACCEPTED) { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1670 | ret = os_snprintf(pos, end - pos, "sae_group=%d\n", | 
|  | 1671 | wpa_s->sme.sae.group); | 
|  | 1672 | if (ret < 0 || ret >= end - pos) | 
|  | 1673 | return pos - buf; | 
|  | 1674 | pos += ret; | 
|  | 1675 | } | 
|  | 1676 | #endif /* CONFIG_SAE */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1677 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", | 
|  | 1678 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | 
|  | 1679 | if (ret < 0 || ret >= end - pos) | 
|  | 1680 | return pos - buf; | 
|  | 1681 | pos += ret; | 
|  | 1682 |  | 
|  | 1683 | if (wpa_s->l2 && | 
|  | 1684 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { | 
|  | 1685 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); | 
|  | 1686 | if (ret < 0 || ret >= end - pos) | 
|  | 1687 | return pos - buf; | 
|  | 1688 | pos += ret; | 
|  | 1689 | } | 
|  | 1690 |  | 
|  | 1691 | #ifdef CONFIG_P2P | 
|  | 1692 | if (wpa_s->global->p2p) { | 
|  | 1693 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR | 
|  | 1694 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); | 
|  | 1695 | if (ret < 0 || ret >= end - pos) | 
|  | 1696 | return pos - buf; | 
|  | 1697 | pos += ret; | 
|  | 1698 | } | 
|  | 1699 | #endif /* CONFIG_P2P */ | 
|  | 1700 |  | 
|  | 1701 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", | 
|  | 1702 | MAC2STR(wpa_s->own_addr)); | 
|  | 1703 | if (ret < 0 || ret >= end - pos) | 
|  | 1704 | return pos - buf; | 
|  | 1705 | pos += ret; | 
|  | 1706 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1707 | #ifdef CONFIG_HS20 | 
|  | 1708 | if (wpa_s->current_bss && | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1709 | wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) && | 
|  | 1710 | wpa_s->wpa_proto == WPA_PROTO_RSN && | 
|  | 1711 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1712 | ret = os_snprintf(pos, end - pos, "hs20=1\n"); | 
|  | 1713 | if (ret < 0 || ret >= end - pos) | 
|  | 1714 | return pos - buf; | 
|  | 1715 | pos += ret; | 
|  | 1716 | } | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1717 |  | 
|  | 1718 | if (wpa_s->current_ssid) { | 
|  | 1719 | struct wpa_cred *cred; | 
|  | 1720 | char *type; | 
|  | 1721 |  | 
|  | 1722 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1723 | size_t i; | 
|  | 1724 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1725 | if (wpa_s->current_ssid->parent_cred != cred) | 
|  | 1726 | continue; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1727 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1728 | for (i = 0; cred->domain && i < cred->num_domain; i++) { | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1729 | ret = os_snprintf(pos, end - pos, | 
|  | 1730 | "home_sp=%s\n", | 
|  | 1731 | cred->domain[i]); | 
|  | 1732 | if (ret < 0 || ret >= end - pos) | 
|  | 1733 | return pos - buf; | 
|  | 1734 | pos += ret; | 
|  | 1735 | } | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1736 |  | 
|  | 1737 | if (wpa_s->current_bss == NULL || | 
|  | 1738 | wpa_s->current_bss->anqp == NULL) | 
|  | 1739 | res = -1; | 
|  | 1740 | else | 
|  | 1741 | res = interworking_home_sp_cred( | 
|  | 1742 | wpa_s, cred, | 
|  | 1743 | wpa_s->current_bss->anqp->domain_name); | 
|  | 1744 | if (res > 0) | 
|  | 1745 | type = "home"; | 
|  | 1746 | else if (res == 0) | 
|  | 1747 | type = "roaming"; | 
|  | 1748 | else | 
|  | 1749 | type = "unknown"; | 
|  | 1750 |  | 
|  | 1751 | ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); | 
|  | 1752 | if (ret < 0 || ret >= end - pos) | 
|  | 1753 | return pos - buf; | 
|  | 1754 | pos += ret; | 
|  | 1755 |  | 
|  | 1756 | break; | 
|  | 1757 | } | 
|  | 1758 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1759 | #endif /* CONFIG_HS20 */ | 
|  | 1760 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1761 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || | 
|  | 1762 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | 
|  | 1763 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, | 
|  | 1764 | verbose); | 
|  | 1765 | if (res >= 0) | 
|  | 1766 | pos += res; | 
|  | 1767 | } | 
|  | 1768 |  | 
|  | 1769 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); | 
|  | 1770 | if (res >= 0) | 
|  | 1771 | pos += res; | 
|  | 1772 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1773 | #ifdef CONFIG_WPS | 
|  | 1774 | { | 
|  | 1775 | char uuid_str[100]; | 
|  | 1776 | uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); | 
|  | 1777 | ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); | 
|  | 1778 | if (ret < 0 || ret >= end - pos) | 
|  | 1779 | return pos - buf; | 
|  | 1780 | pos += ret; | 
|  | 1781 | } | 
|  | 1782 | #endif /* CONFIG_WPS */ | 
|  | 1783 |  | 
| Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 1784 | #ifdef ANDROID | 
|  | 1785 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE | 
| Irfan Sheriff | f20a443 | 2012-04-16 16:48:34 -0700 | [diff] [blame] | 1786 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", | 
| Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 1787 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, | 
| Irfan Sheriff | f20a443 | 2012-04-16 16:48:34 -0700 | [diff] [blame] | 1788 | wpa_s->wpa_state, | 
| Irfan Sheriff | e78e767 | 2012-08-01 11:10:15 -0700 | [diff] [blame] | 1789 | MAC2STR(wpa_s->bssid), | 
| andy2_kuo | 5b5fb02 | 2012-05-22 11:53:07 -0700 | [diff] [blame] | 1790 | wpa_s->current_ssid && wpa_s->current_ssid->ssid ? | 
|  | 1791 | wpa_ssid_txt(wpa_s->current_ssid->ssid, | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1792 | wpa_s->current_ssid->ssid_len) : ""); | 
| Irfan Sheriff | bf5edf4 | 2012-01-11 16:54:57 -0800 | [diff] [blame] | 1793 | if (wpa_s->wpa_state == WPA_COMPLETED) { | 
|  | 1794 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1795 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED | 
|  | 1796 | "- connection to " MACSTR | 
|  | 1797 | " completed %s [id=%d id_str=%s]", | 
|  | 1798 | MAC2STR(wpa_s->bssid), "(auth)", | 
|  | 1799 | ssid ? ssid->id : -1, | 
|  | 1800 | ssid && ssid->id_str ? ssid->id_str : ""); | 
| Irfan Sheriff | bf5edf4 | 2012-01-11 16:54:57 -0800 | [diff] [blame] | 1801 | } | 
| Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 1802 | #endif /* ANDROID */ | 
|  | 1803 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1804 | return pos - buf; | 
|  | 1805 | } | 
|  | 1806 |  | 
|  | 1807 |  | 
|  | 1808 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, | 
|  | 1809 | char *cmd) | 
|  | 1810 | { | 
|  | 1811 | char *pos; | 
|  | 1812 | int id; | 
|  | 1813 | struct wpa_ssid *ssid; | 
|  | 1814 | u8 bssid[ETH_ALEN]; | 
|  | 1815 |  | 
|  | 1816 | /* cmd: "<network id> <BSSID>" */ | 
|  | 1817 | pos = os_strchr(cmd, ' '); | 
|  | 1818 | if (pos == NULL) | 
|  | 1819 | return -1; | 
|  | 1820 | *pos++ = '\0'; | 
|  | 1821 | id = atoi(cmd); | 
|  | 1822 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); | 
|  | 1823 | if (hwaddr_aton(pos, bssid)) { | 
|  | 1824 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); | 
|  | 1825 | return -1; | 
|  | 1826 | } | 
|  | 1827 |  | 
|  | 1828 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 1829 | if (ssid == NULL) { | 
|  | 1830 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | 
|  | 1831 | "to update", id); | 
|  | 1832 | return -1; | 
|  | 1833 | } | 
|  | 1834 |  | 
|  | 1835 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); | 
|  | 1836 | ssid->bssid_set = !is_zero_ether_addr(bssid); | 
|  | 1837 |  | 
|  | 1838 | return 0; | 
|  | 1839 | } | 
|  | 1840 |  | 
|  | 1841 |  | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1842 | static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1843 | char *cmd, char *buf, | 
|  | 1844 | size_t buflen) | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1845 | { | 
|  | 1846 | u8 bssid[ETH_ALEN]; | 
|  | 1847 | struct wpa_blacklist *e; | 
|  | 1848 | char *pos, *end; | 
|  | 1849 | int ret; | 
|  | 1850 |  | 
|  | 1851 | /* cmd: "BLACKLIST [<BSSID>]" */ | 
|  | 1852 | if (*cmd == '\0') { | 
|  | 1853 | pos = buf; | 
|  | 1854 | end = buf + buflen; | 
|  | 1855 | e = wpa_s->blacklist; | 
|  | 1856 | while (e) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1857 | ret = os_snprintf(pos, end - pos, MACSTR "\n", | 
|  | 1858 | MAC2STR(e->bssid)); | 
|  | 1859 | if (ret < 0 || ret >= end - pos) | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1860 | return pos - buf; | 
|  | 1861 | pos += ret; | 
|  | 1862 | e = e->next; | 
|  | 1863 | } | 
|  | 1864 | return pos - buf; | 
|  | 1865 | } | 
|  | 1866 |  | 
|  | 1867 | cmd++; | 
|  | 1868 | if (os_strncmp(cmd, "clear", 5) == 0) { | 
|  | 1869 | wpa_blacklist_clear(wpa_s); | 
|  | 1870 | os_memcpy(buf, "OK\n", 3); | 
|  | 1871 | return 3; | 
|  | 1872 | } | 
|  | 1873 |  | 
|  | 1874 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); | 
|  | 1875 | if (hwaddr_aton(cmd, bssid)) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1876 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1877 | return -1; | 
|  | 1878 | } | 
|  | 1879 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1880 | /* | 
|  | 1881 | * Add the BSSID twice, so its count will be 2, causing it to be | 
|  | 1882 | * skipped when processing scan results. | 
|  | 1883 | */ | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1884 | ret = wpa_blacklist_add(wpa_s, bssid); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1885 | if (ret != 0) | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1886 | return -1; | 
|  | 1887 | ret = wpa_blacklist_add(wpa_s, bssid); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1888 | if (ret != 0) | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1889 | return -1; | 
|  | 1890 | os_memcpy(buf, "OK\n", 3); | 
|  | 1891 | return 3; | 
|  | 1892 | } | 
|  | 1893 |  | 
|  | 1894 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1895 | static const char * debug_level_str(int level) | 
|  | 1896 | { | 
|  | 1897 | switch (level) { | 
|  | 1898 | case MSG_EXCESSIVE: | 
|  | 1899 | return "EXCESSIVE"; | 
|  | 1900 | case MSG_MSGDUMP: | 
|  | 1901 | return "MSGDUMP"; | 
|  | 1902 | case MSG_DEBUG: | 
|  | 1903 | return "DEBUG"; | 
|  | 1904 | case MSG_INFO: | 
|  | 1905 | return "INFO"; | 
|  | 1906 | case MSG_WARNING: | 
|  | 1907 | return "WARNING"; | 
|  | 1908 | case MSG_ERROR: | 
|  | 1909 | return "ERROR"; | 
|  | 1910 | default: | 
|  | 1911 | return "?"; | 
|  | 1912 | } | 
|  | 1913 | } | 
|  | 1914 |  | 
|  | 1915 |  | 
|  | 1916 | static int str_to_debug_level(const char *s) | 
|  | 1917 | { | 
|  | 1918 | if (os_strcasecmp(s, "EXCESSIVE") == 0) | 
|  | 1919 | return MSG_EXCESSIVE; | 
|  | 1920 | if (os_strcasecmp(s, "MSGDUMP") == 0) | 
|  | 1921 | return MSG_MSGDUMP; | 
|  | 1922 | if (os_strcasecmp(s, "DEBUG") == 0) | 
|  | 1923 | return MSG_DEBUG; | 
|  | 1924 | if (os_strcasecmp(s, "INFO") == 0) | 
|  | 1925 | return MSG_INFO; | 
|  | 1926 | if (os_strcasecmp(s, "WARNING") == 0) | 
|  | 1927 | return MSG_WARNING; | 
|  | 1928 | if (os_strcasecmp(s, "ERROR") == 0) | 
|  | 1929 | return MSG_ERROR; | 
|  | 1930 | return -1; | 
|  | 1931 | } | 
|  | 1932 |  | 
|  | 1933 |  | 
|  | 1934 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, | 
|  | 1935 | char *cmd, char *buf, | 
|  | 1936 | size_t buflen) | 
|  | 1937 | { | 
|  | 1938 | char *pos, *end, *stamp; | 
|  | 1939 | int ret; | 
|  | 1940 |  | 
|  | 1941 | if (cmd == NULL) { | 
|  | 1942 | return -1; | 
|  | 1943 | } | 
|  | 1944 |  | 
|  | 1945 | /* cmd: "LOG_LEVEL [<level>]" */ | 
|  | 1946 | if (*cmd == '\0') { | 
|  | 1947 | pos = buf; | 
|  | 1948 | end = buf + buflen; | 
|  | 1949 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" | 
|  | 1950 | "Timestamp: %d\n", | 
|  | 1951 | debug_level_str(wpa_debug_level), | 
|  | 1952 | wpa_debug_timestamp); | 
|  | 1953 | if (ret < 0 || ret >= end - pos) | 
|  | 1954 | ret = 0; | 
|  | 1955 |  | 
|  | 1956 | return ret; | 
|  | 1957 | } | 
|  | 1958 |  | 
|  | 1959 | while (*cmd == ' ') | 
|  | 1960 | cmd++; | 
|  | 1961 |  | 
|  | 1962 | stamp = os_strchr(cmd, ' '); | 
|  | 1963 | if (stamp) { | 
|  | 1964 | *stamp++ = '\0'; | 
|  | 1965 | while (*stamp == ' ') { | 
|  | 1966 | stamp++; | 
|  | 1967 | } | 
|  | 1968 | } | 
|  | 1969 |  | 
|  | 1970 | if (cmd && os_strlen(cmd)) { | 
|  | 1971 | int level = str_to_debug_level(cmd); | 
|  | 1972 | if (level < 0) | 
|  | 1973 | return -1; | 
|  | 1974 | wpa_debug_level = level; | 
|  | 1975 | } | 
|  | 1976 |  | 
|  | 1977 | if (stamp && os_strlen(stamp)) | 
|  | 1978 | wpa_debug_timestamp = atoi(stamp); | 
|  | 1979 |  | 
|  | 1980 | os_memcpy(buf, "OK\n", 3); | 
|  | 1981 | return 3; | 
|  | 1982 | } | 
|  | 1983 |  | 
|  | 1984 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1985 | static int wpa_supplicant_ctrl_iface_list_networks( | 
|  | 1986 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | 
|  | 1987 | { | 
|  | 1988 | char *pos, *end; | 
|  | 1989 | struct wpa_ssid *ssid; | 
|  | 1990 | int ret; | 
|  | 1991 |  | 
|  | 1992 | pos = buf; | 
|  | 1993 | end = buf + buflen; | 
|  | 1994 | ret = os_snprintf(pos, end - pos, | 
|  | 1995 | "network id / ssid / bssid / flags\n"); | 
|  | 1996 | if (ret < 0 || ret >= end - pos) | 
|  | 1997 | return pos - buf; | 
|  | 1998 | pos += ret; | 
|  | 1999 |  | 
|  | 2000 | ssid = wpa_s->conf->ssid; | 
|  | 2001 | while (ssid) { | 
|  | 2002 | ret = os_snprintf(pos, end - pos, "%d\t%s", | 
|  | 2003 | ssid->id, | 
|  | 2004 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | 
|  | 2005 | if (ret < 0 || ret >= end - pos) | 
|  | 2006 | return pos - buf; | 
|  | 2007 | pos += ret; | 
|  | 2008 | if (ssid->bssid_set) { | 
|  | 2009 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, | 
|  | 2010 | MAC2STR(ssid->bssid)); | 
|  | 2011 | } else { | 
|  | 2012 | ret = os_snprintf(pos, end - pos, "\tany"); | 
|  | 2013 | } | 
|  | 2014 | if (ret < 0 || ret >= end - pos) | 
|  | 2015 | return pos - buf; | 
|  | 2016 | pos += ret; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2017 | ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2018 | ssid == wpa_s->current_ssid ? | 
|  | 2019 | "[CURRENT]" : "", | 
|  | 2020 | ssid->disabled ? "[DISABLED]" : "", | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2021 | ssid->disabled_until.sec ? | 
|  | 2022 | "[TEMP-DISABLED]" : "", | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2023 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : | 
|  | 2024 | ""); | 
|  | 2025 | if (ret < 0 || ret >= end - pos) | 
|  | 2026 | return pos - buf; | 
|  | 2027 | pos += ret; | 
|  | 2028 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 2029 | if (ret < 0 || ret >= end - pos) | 
|  | 2030 | return pos - buf; | 
|  | 2031 | pos += ret; | 
|  | 2032 |  | 
|  | 2033 | ssid = ssid->next; | 
|  | 2034 | } | 
|  | 2035 |  | 
|  | 2036 | return pos - buf; | 
|  | 2037 | } | 
|  | 2038 |  | 
|  | 2039 |  | 
|  | 2040 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) | 
|  | 2041 | { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2042 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2043 | ret = os_snprintf(pos, end - pos, "-"); | 
|  | 2044 | if (ret < 0 || ret >= end - pos) | 
|  | 2045 | return pos; | 
|  | 2046 | pos += ret; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2047 | ret = wpa_write_ciphers(pos, end, cipher, "+"); | 
|  | 2048 | if (ret < 0) | 
|  | 2049 | return pos; | 
|  | 2050 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2051 | return pos; | 
|  | 2052 | } | 
|  | 2053 |  | 
|  | 2054 |  | 
|  | 2055 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, | 
|  | 2056 | const u8 *ie, size_t ie_len) | 
|  | 2057 | { | 
|  | 2058 | struct wpa_ie_data data; | 
|  | 2059 | int first, ret; | 
|  | 2060 |  | 
|  | 2061 | ret = os_snprintf(pos, end - pos, "[%s-", proto); | 
|  | 2062 | if (ret < 0 || ret >= end - pos) | 
|  | 2063 | return pos; | 
|  | 2064 | pos += ret; | 
|  | 2065 |  | 
|  | 2066 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { | 
|  | 2067 | ret = os_snprintf(pos, end - pos, "?]"); | 
|  | 2068 | if (ret < 0 || ret >= end - pos) | 
|  | 2069 | return pos; | 
|  | 2070 | pos += ret; | 
|  | 2071 | return pos; | 
|  | 2072 | } | 
|  | 2073 |  | 
|  | 2074 | first = 1; | 
|  | 2075 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { | 
|  | 2076 | ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+"); | 
|  | 2077 | if (ret < 0 || ret >= end - pos) | 
|  | 2078 | return pos; | 
|  | 2079 | pos += ret; | 
|  | 2080 | first = 0; | 
|  | 2081 | } | 
|  | 2082 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { | 
|  | 2083 | ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+"); | 
|  | 2084 | if (ret < 0 || ret >= end - pos) | 
|  | 2085 | return pos; | 
|  | 2086 | pos += ret; | 
|  | 2087 | first = 0; | 
|  | 2088 | } | 
|  | 2089 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { | 
|  | 2090 | ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+"); | 
|  | 2091 | if (ret < 0 || ret >= end - pos) | 
|  | 2092 | return pos; | 
|  | 2093 | pos += ret; | 
|  | 2094 | first = 0; | 
|  | 2095 | } | 
|  | 2096 | #ifdef CONFIG_IEEE80211R | 
|  | 2097 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { | 
|  | 2098 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", | 
|  | 2099 | first ? "" : "+"); | 
|  | 2100 | if (ret < 0 || ret >= end - pos) | 
|  | 2101 | return pos; | 
|  | 2102 | pos += ret; | 
|  | 2103 | first = 0; | 
|  | 2104 | } | 
|  | 2105 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { | 
|  | 2106 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", | 
|  | 2107 | first ? "" : "+"); | 
|  | 2108 | if (ret < 0 || ret >= end - pos) | 
|  | 2109 | return pos; | 
|  | 2110 | pos += ret; | 
|  | 2111 | first = 0; | 
|  | 2112 | } | 
|  | 2113 | #endif /* CONFIG_IEEE80211R */ | 
|  | 2114 | #ifdef CONFIG_IEEE80211W | 
|  | 2115 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { | 
|  | 2116 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", | 
|  | 2117 | first ? "" : "+"); | 
|  | 2118 | if (ret < 0 || ret >= end - pos) | 
|  | 2119 | return pos; | 
|  | 2120 | pos += ret; | 
|  | 2121 | first = 0; | 
|  | 2122 | } | 
|  | 2123 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { | 
|  | 2124 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", | 
|  | 2125 | first ? "" : "+"); | 
|  | 2126 | if (ret < 0 || ret >= end - pos) | 
|  | 2127 | return pos; | 
|  | 2128 | pos += ret; | 
|  | 2129 | first = 0; | 
|  | 2130 | } | 
|  | 2131 | #endif /* CONFIG_IEEE80211W */ | 
|  | 2132 |  | 
|  | 2133 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); | 
|  | 2134 |  | 
|  | 2135 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { | 
|  | 2136 | ret = os_snprintf(pos, end - pos, "-preauth"); | 
|  | 2137 | if (ret < 0 || ret >= end - pos) | 
|  | 2138 | return pos; | 
|  | 2139 | pos += ret; | 
|  | 2140 | } | 
|  | 2141 |  | 
|  | 2142 | ret = os_snprintf(pos, end - pos, "]"); | 
|  | 2143 | if (ret < 0 || ret >= end - pos) | 
|  | 2144 | return pos; | 
|  | 2145 | pos += ret; | 
|  | 2146 |  | 
|  | 2147 | return pos; | 
|  | 2148 | } | 
|  | 2149 |  | 
|  | 2150 |  | 
|  | 2151 | #ifdef CONFIG_WPS | 
|  | 2152 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, | 
|  | 2153 | char *pos, char *end, | 
|  | 2154 | struct wpabuf *wps_ie) | 
|  | 2155 | { | 
|  | 2156 | int ret; | 
|  | 2157 | const char *txt; | 
|  | 2158 |  | 
|  | 2159 | if (wps_ie == NULL) | 
|  | 2160 | return pos; | 
|  | 2161 | if (wps_is_selected_pbc_registrar(wps_ie)) | 
|  | 2162 | txt = "[WPS-PBC]"; | 
|  | 2163 | #ifdef CONFIG_WPS2 | 
|  | 2164 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) | 
|  | 2165 | txt = "[WPS-AUTH]"; | 
|  | 2166 | #endif /* CONFIG_WPS2 */ | 
|  | 2167 | else if (wps_is_selected_pin_registrar(wps_ie)) | 
|  | 2168 | txt = "[WPS-PIN]"; | 
|  | 2169 | else | 
|  | 2170 | txt = "[WPS]"; | 
|  | 2171 |  | 
|  | 2172 | ret = os_snprintf(pos, end - pos, "%s", txt); | 
|  | 2173 | if (ret >= 0 && ret < end - pos) | 
|  | 2174 | pos += ret; | 
|  | 2175 | wpabuf_free(wps_ie); | 
|  | 2176 | return pos; | 
|  | 2177 | } | 
|  | 2178 | #endif /* CONFIG_WPS */ | 
|  | 2179 |  | 
|  | 2180 |  | 
|  | 2181 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, | 
|  | 2182 | char *pos, char *end, | 
|  | 2183 | const struct wpa_bss *bss) | 
|  | 2184 | { | 
|  | 2185 | #ifdef CONFIG_WPS | 
|  | 2186 | struct wpabuf *wps_ie; | 
|  | 2187 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); | 
|  | 2188 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); | 
|  | 2189 | #else /* CONFIG_WPS */ | 
|  | 2190 | return pos; | 
|  | 2191 | #endif /* CONFIG_WPS */ | 
|  | 2192 | } | 
|  | 2193 |  | 
|  | 2194 |  | 
|  | 2195 | /* Format one result on one text line into a buffer. */ | 
|  | 2196 | static int wpa_supplicant_ctrl_iface_scan_result( | 
|  | 2197 | struct wpa_supplicant *wpa_s, | 
|  | 2198 | const struct wpa_bss *bss, char *buf, size_t buflen) | 
|  | 2199 | { | 
|  | 2200 | char *pos, *end; | 
|  | 2201 | int ret; | 
|  | 2202 | const u8 *ie, *ie2, *p2p; | 
|  | 2203 |  | 
|  | 2204 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2205 | if (!p2p) | 
|  | 2206 | p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2207 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && | 
|  | 2208 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == | 
|  | 2209 | 0) | 
|  | 2210 | return 0; /* Do not show P2P listen discovery results here */ | 
|  | 2211 |  | 
|  | 2212 | pos = buf; | 
|  | 2213 | end = buf + buflen; | 
|  | 2214 |  | 
|  | 2215 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", | 
|  | 2216 | MAC2STR(bss->bssid), bss->freq, bss->level); | 
|  | 2217 | if (ret < 0 || ret >= end - pos) | 
|  | 2218 | return -1; | 
|  | 2219 | pos += ret; | 
|  | 2220 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | 
|  | 2221 | if (ie) | 
|  | 2222 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); | 
|  | 2223 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); | 
|  | 2224 | if (ie2) | 
|  | 2225 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]); | 
|  | 2226 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); | 
|  | 2227 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { | 
|  | 2228 | ret = os_snprintf(pos, end - pos, "[WEP]"); | 
|  | 2229 | if (ret < 0 || ret >= end - pos) | 
|  | 2230 | return -1; | 
|  | 2231 | pos += ret; | 
|  | 2232 | } | 
|  | 2233 | if (bss->caps & IEEE80211_CAP_IBSS) { | 
|  | 2234 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | 
|  | 2235 | if (ret < 0 || ret >= end - pos) | 
|  | 2236 | return -1; | 
|  | 2237 | pos += ret; | 
|  | 2238 | } | 
|  | 2239 | if (bss->caps & IEEE80211_CAP_ESS) { | 
|  | 2240 | ret = os_snprintf(pos, end - pos, "[ESS]"); | 
|  | 2241 | if (ret < 0 || ret >= end - pos) | 
|  | 2242 | return -1; | 
|  | 2243 | pos += ret; | 
|  | 2244 | } | 
|  | 2245 | if (p2p) { | 
|  | 2246 | ret = os_snprintf(pos, end - pos, "[P2P]"); | 
|  | 2247 | if (ret < 0 || ret >= end - pos) | 
|  | 2248 | return -1; | 
|  | 2249 | pos += ret; | 
|  | 2250 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2251 | #ifdef CONFIG_HS20 | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2252 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2253 | ret = os_snprintf(pos, end - pos, "[HS20]"); | 
|  | 2254 | if (ret < 0 || ret >= end - pos) | 
|  | 2255 | return -1; | 
|  | 2256 | pos += ret; | 
|  | 2257 | } | 
|  | 2258 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2259 |  | 
|  | 2260 | ret = os_snprintf(pos, end - pos, "\t%s", | 
|  | 2261 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | 
|  | 2262 | if (ret < 0 || ret >= end - pos) | 
|  | 2263 | return -1; | 
|  | 2264 | pos += ret; | 
|  | 2265 |  | 
|  | 2266 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 2267 | if (ret < 0 || ret >= end - pos) | 
|  | 2268 | return -1; | 
|  | 2269 | pos += ret; | 
|  | 2270 |  | 
|  | 2271 | return pos - buf; | 
|  | 2272 | } | 
|  | 2273 |  | 
|  | 2274 |  | 
|  | 2275 | static int wpa_supplicant_ctrl_iface_scan_results( | 
|  | 2276 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | 
|  | 2277 | { | 
|  | 2278 | char *pos, *end; | 
|  | 2279 | struct wpa_bss *bss; | 
|  | 2280 | int ret; | 
|  | 2281 |  | 
|  | 2282 | pos = buf; | 
|  | 2283 | end = buf + buflen; | 
|  | 2284 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " | 
|  | 2285 | "flags / ssid\n"); | 
|  | 2286 | if (ret < 0 || ret >= end - pos) | 
|  | 2287 | return pos - buf; | 
|  | 2288 | pos += ret; | 
|  | 2289 |  | 
|  | 2290 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { | 
|  | 2291 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, | 
|  | 2292 | end - pos); | 
|  | 2293 | if (ret < 0 || ret >= end - pos) | 
|  | 2294 | return pos - buf; | 
|  | 2295 | pos += ret; | 
|  | 2296 | } | 
|  | 2297 |  | 
|  | 2298 | return pos - buf; | 
|  | 2299 | } | 
|  | 2300 |  | 
|  | 2301 |  | 
|  | 2302 | static int wpa_supplicant_ctrl_iface_select_network( | 
|  | 2303 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 2304 | { | 
|  | 2305 | int id; | 
|  | 2306 | struct wpa_ssid *ssid; | 
|  | 2307 |  | 
|  | 2308 | /* cmd: "<network id>" or "any" */ | 
|  | 2309 | if (os_strcmp(cmd, "any") == 0) { | 
|  | 2310 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); | 
|  | 2311 | ssid = NULL; | 
|  | 2312 | } else { | 
|  | 2313 | id = atoi(cmd); | 
|  | 2314 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); | 
|  | 2315 |  | 
|  | 2316 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 2317 | if (ssid == NULL) { | 
|  | 2318 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
|  | 2319 | "network id=%d", id); | 
|  | 2320 | return -1; | 
|  | 2321 | } | 
|  | 2322 | if (ssid->disabled == 2) { | 
|  | 2323 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | 
|  | 2324 | "SELECT_NETWORK with persistent P2P group"); | 
|  | 2325 | return -1; | 
|  | 2326 | } | 
|  | 2327 | } | 
|  | 2328 |  | 
|  | 2329 | wpa_supplicant_select_network(wpa_s, ssid); | 
|  | 2330 |  | 
|  | 2331 | return 0; | 
|  | 2332 | } | 
|  | 2333 |  | 
|  | 2334 |  | 
|  | 2335 | static int wpa_supplicant_ctrl_iface_enable_network( | 
|  | 2336 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 2337 | { | 
|  | 2338 | int id; | 
|  | 2339 | struct wpa_ssid *ssid; | 
|  | 2340 |  | 
|  | 2341 | /* cmd: "<network id>" or "all" */ | 
|  | 2342 | if (os_strcmp(cmd, "all") == 0) { | 
|  | 2343 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); | 
|  | 2344 | ssid = NULL; | 
|  | 2345 | } else { | 
|  | 2346 | id = atoi(cmd); | 
|  | 2347 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); | 
|  | 2348 |  | 
|  | 2349 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 2350 | if (ssid == NULL) { | 
|  | 2351 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
|  | 2352 | "network id=%d", id); | 
|  | 2353 | return -1; | 
|  | 2354 | } | 
|  | 2355 | if (ssid->disabled == 2) { | 
|  | 2356 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | 
|  | 2357 | "ENABLE_NETWORK with persistent P2P group"); | 
|  | 2358 | return -1; | 
|  | 2359 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2360 |  | 
|  | 2361 | if (os_strstr(cmd, " no-connect")) { | 
|  | 2362 | ssid->disabled = 0; | 
|  | 2363 | return 0; | 
|  | 2364 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2365 | } | 
|  | 2366 | wpa_supplicant_enable_network(wpa_s, ssid); | 
|  | 2367 |  | 
|  | 2368 | return 0; | 
|  | 2369 | } | 
|  | 2370 |  | 
|  | 2371 |  | 
|  | 2372 | static int wpa_supplicant_ctrl_iface_disable_network( | 
|  | 2373 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 2374 | { | 
|  | 2375 | int id; | 
|  | 2376 | struct wpa_ssid *ssid; | 
|  | 2377 |  | 
|  | 2378 | /* cmd: "<network id>" or "all" */ | 
|  | 2379 | if (os_strcmp(cmd, "all") == 0) { | 
|  | 2380 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); | 
|  | 2381 | ssid = NULL; | 
|  | 2382 | } else { | 
|  | 2383 | id = atoi(cmd); | 
|  | 2384 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); | 
|  | 2385 |  | 
|  | 2386 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 2387 | if (ssid == NULL) { | 
|  | 2388 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
|  | 2389 | "network id=%d", id); | 
|  | 2390 | return -1; | 
|  | 2391 | } | 
|  | 2392 | if (ssid->disabled == 2) { | 
|  | 2393 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | 
|  | 2394 | "DISABLE_NETWORK with persistent P2P " | 
|  | 2395 | "group"); | 
|  | 2396 | return -1; | 
|  | 2397 | } | 
|  | 2398 | } | 
|  | 2399 | wpa_supplicant_disable_network(wpa_s, ssid); | 
|  | 2400 |  | 
|  | 2401 | return 0; | 
|  | 2402 | } | 
|  | 2403 |  | 
|  | 2404 |  | 
|  | 2405 | static int wpa_supplicant_ctrl_iface_add_network( | 
|  | 2406 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | 
|  | 2407 | { | 
|  | 2408 | struct wpa_ssid *ssid; | 
|  | 2409 | int ret; | 
|  | 2410 |  | 
|  | 2411 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); | 
|  | 2412 |  | 
|  | 2413 | ssid = wpa_config_add_network(wpa_s->conf); | 
|  | 2414 | if (ssid == NULL) | 
|  | 2415 | return -1; | 
|  | 2416 |  | 
|  | 2417 | wpas_notify_network_added(wpa_s, ssid); | 
|  | 2418 |  | 
|  | 2419 | ssid->disabled = 1; | 
|  | 2420 | wpa_config_set_network_defaults(ssid); | 
|  | 2421 |  | 
|  | 2422 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); | 
|  | 2423 | if (ret < 0 || (size_t) ret >= buflen) | 
|  | 2424 | return -1; | 
|  | 2425 | return ret; | 
|  | 2426 | } | 
|  | 2427 |  | 
|  | 2428 |  | 
|  | 2429 | static int wpa_supplicant_ctrl_iface_remove_network( | 
|  | 2430 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 2431 | { | 
|  | 2432 | int id; | 
|  | 2433 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2434 | int was_disabled; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2435 |  | 
|  | 2436 | /* cmd: "<network id>" or "all" */ | 
|  | 2437 | if (os_strcmp(cmd, "all") == 0) { | 
|  | 2438 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); | 
| Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2439 | if (wpa_s->sched_scanning) | 
|  | 2440 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
|  | 2441 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2442 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2443 | if (wpa_s->current_ssid) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2444 | #ifdef CONFIG_SME | 
|  | 2445 | wpa_s->sme.prev_bssid_set = 0; | 
|  | 2446 | #endif /* CONFIG_SME */ | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2447 | wpa_sm_set_config(wpa_s->wpa, NULL); | 
|  | 2448 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2449 | wpa_supplicant_deauthenticate( | 
|  | 2450 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2451 | } | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2452 | ssid = wpa_s->conf->ssid; | 
|  | 2453 | while (ssid) { | 
|  | 2454 | struct wpa_ssid *remove_ssid = ssid; | 
|  | 2455 | id = ssid->id; | 
|  | 2456 | ssid = ssid->next; | 
|  | 2457 | wpas_notify_network_removed(wpa_s, remove_ssid); | 
|  | 2458 | wpa_config_remove_network(wpa_s->conf, id); | 
|  | 2459 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2460 | return 0; | 
|  | 2461 | } | 
|  | 2462 |  | 
|  | 2463 | id = atoi(cmd); | 
|  | 2464 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); | 
|  | 2465 |  | 
|  | 2466 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2467 | if (ssid) | 
|  | 2468 | wpas_notify_network_removed(wpa_s, ssid); | 
| Deepthi Gowri | a831d78 | 2012-09-03 11:55:38 +0300 | [diff] [blame] | 2469 | if (ssid == NULL) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2470 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | 
|  | 2471 | "id=%d", id); | 
|  | 2472 | return -1; | 
|  | 2473 | } | 
|  | 2474 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2475 | if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2476 | #ifdef CONFIG_SME | 
|  | 2477 | wpa_s->sme.prev_bssid_set = 0; | 
|  | 2478 | #endif /* CONFIG_SME */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2479 | /* | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2480 | * Invalidate the EAP session cache if the current or | 
|  | 2481 | * previously used network is removed. | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2482 | */ | 
|  | 2483 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2484 | } | 
|  | 2485 |  | 
|  | 2486 | if (ssid == wpa_s->current_ssid) { | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2487 | wpa_sm_set_config(wpa_s->wpa, NULL); | 
|  | 2488 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2489 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2490 | wpa_supplicant_deauthenticate(wpa_s, | 
|  | 2491 | WLAN_REASON_DEAUTH_LEAVING); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2492 | } | 
|  | 2493 |  | 
| Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2494 | was_disabled = ssid->disabled; | 
|  | 2495 |  | 
| Deepthi Gowri | a831d78 | 2012-09-03 11:55:38 +0300 | [diff] [blame] | 2496 | if (wpa_config_remove_network(wpa_s->conf, id) < 0) { | 
|  | 2497 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the " | 
|  | 2498 | "network id=%d", id); | 
|  | 2499 | return -1; | 
|  | 2500 | } | 
|  | 2501 |  | 
| Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2502 | if (!was_disabled && wpa_s->sched_scanning) { | 
|  | 2503 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove " | 
|  | 2504 | "network from filters"); | 
|  | 2505 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
|  | 2506 | wpa_supplicant_req_scan(wpa_s, 0, 0); | 
|  | 2507 | } | 
|  | 2508 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2509 | return 0; | 
|  | 2510 | } | 
|  | 2511 |  | 
|  | 2512 |  | 
|  | 2513 | static int wpa_supplicant_ctrl_iface_set_network( | 
|  | 2514 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 2515 | { | 
|  | 2516 | int id; | 
|  | 2517 | struct wpa_ssid *ssid; | 
|  | 2518 | char *name, *value; | 
|  | 2519 |  | 
|  | 2520 | /* cmd: "<network id> <variable name> <value>" */ | 
|  | 2521 | name = os_strchr(cmd, ' '); | 
|  | 2522 | if (name == NULL) | 
|  | 2523 | return -1; | 
|  | 2524 | *name++ = '\0'; | 
|  | 2525 |  | 
|  | 2526 | value = os_strchr(name, ' '); | 
|  | 2527 | if (value == NULL) | 
|  | 2528 | return -1; | 
|  | 2529 | *value++ = '\0'; | 
|  | 2530 |  | 
|  | 2531 | id = atoi(cmd); | 
|  | 2532 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", | 
|  | 2533 | id, name); | 
|  | 2534 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | 
|  | 2535 | (u8 *) value, os_strlen(value)); | 
|  | 2536 |  | 
|  | 2537 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 2538 | if (ssid == NULL) { | 
|  | 2539 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | 
|  | 2540 | "id=%d", id); | 
|  | 2541 | return -1; | 
|  | 2542 | } | 
|  | 2543 |  | 
|  | 2544 | if (wpa_config_set(ssid, name, value, 0) < 0) { | 
|  | 2545 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " | 
|  | 2546 | "variable '%s'", name); | 
|  | 2547 | return -1; | 
|  | 2548 | } | 
|  | 2549 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2550 | if (os_strcmp(name, "bssid") != 0 && | 
|  | 2551 | os_strcmp(name, "priority") != 0) | 
|  | 2552 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2553 |  | 
|  | 2554 | if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2555 | /* | 
|  | 2556 | * Invalidate the EAP session cache if anything in the current | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2557 | * or previously used configuration changes. | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2558 | */ | 
|  | 2559 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | 
|  | 2560 | } | 
|  | 2561 |  | 
|  | 2562 | if ((os_strcmp(name, "psk") == 0 && | 
|  | 2563 | value[0] == '"' && ssid->ssid_len) || | 
|  | 2564 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) | 
|  | 2565 | wpa_config_update_psk(ssid); | 
|  | 2566 | else if (os_strcmp(name, "priority") == 0) | 
|  | 2567 | wpa_config_update_prio_list(wpa_s->conf); | 
|  | 2568 |  | 
|  | 2569 | return 0; | 
|  | 2570 | } | 
|  | 2571 |  | 
|  | 2572 |  | 
|  | 2573 | static int wpa_supplicant_ctrl_iface_get_network( | 
|  | 2574 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | 
|  | 2575 | { | 
|  | 2576 | int id; | 
|  | 2577 | size_t res; | 
|  | 2578 | struct wpa_ssid *ssid; | 
|  | 2579 | char *name, *value; | 
|  | 2580 |  | 
|  | 2581 | /* cmd: "<network id> <variable name>" */ | 
|  | 2582 | name = os_strchr(cmd, ' '); | 
|  | 2583 | if (name == NULL || buflen == 0) | 
|  | 2584 | return -1; | 
|  | 2585 | *name++ = '\0'; | 
|  | 2586 |  | 
|  | 2587 | id = atoi(cmd); | 
|  | 2588 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", | 
|  | 2589 | id, name); | 
|  | 2590 |  | 
|  | 2591 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 2592 | if (ssid == NULL) { | 
|  | 2593 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | 
|  | 2594 | "id=%d", id); | 
|  | 2595 | return -1; | 
|  | 2596 | } | 
|  | 2597 |  | 
|  | 2598 | value = wpa_config_get_no_key(ssid, name); | 
|  | 2599 | if (value == NULL) { | 
|  | 2600 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " | 
|  | 2601 | "variable '%s'", name); | 
|  | 2602 | return -1; | 
|  | 2603 | } | 
|  | 2604 |  | 
|  | 2605 | res = os_strlcpy(buf, value, buflen); | 
|  | 2606 | if (res >= buflen) { | 
|  | 2607 | os_free(value); | 
|  | 2608 | return -1; | 
|  | 2609 | } | 
|  | 2610 |  | 
|  | 2611 | os_free(value); | 
|  | 2612 |  | 
|  | 2613 | return res; | 
|  | 2614 | } | 
|  | 2615 |  | 
|  | 2616 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2617 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, | 
|  | 2618 | char *buf, size_t buflen) | 
|  | 2619 | { | 
|  | 2620 | char *pos, *end; | 
|  | 2621 | struct wpa_cred *cred; | 
|  | 2622 | int ret; | 
|  | 2623 |  | 
|  | 2624 | pos = buf; | 
|  | 2625 | end = buf + buflen; | 
|  | 2626 | ret = os_snprintf(pos, end - pos, | 
|  | 2627 | "cred id / realm / username / domain / imsi\n"); | 
|  | 2628 | if (ret < 0 || ret >= end - pos) | 
|  | 2629 | return pos - buf; | 
|  | 2630 | pos += ret; | 
|  | 2631 |  | 
|  | 2632 | cred = wpa_s->conf->cred; | 
|  | 2633 | while (cred) { | 
|  | 2634 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", | 
|  | 2635 | cred->id, cred->realm ? cred->realm : "", | 
|  | 2636 | cred->username ? cred->username : "", | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2637 | cred->domain ? cred->domain[0] : "", | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2638 | cred->imsi ? cred->imsi : ""); | 
|  | 2639 | if (ret < 0 || ret >= end - pos) | 
|  | 2640 | return pos - buf; | 
|  | 2641 | pos += ret; | 
|  | 2642 |  | 
|  | 2643 | cred = cred->next; | 
|  | 2644 | } | 
|  | 2645 |  | 
|  | 2646 | return pos - buf; | 
|  | 2647 | } | 
|  | 2648 |  | 
|  | 2649 |  | 
|  | 2650 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, | 
|  | 2651 | char *buf, size_t buflen) | 
|  | 2652 | { | 
|  | 2653 | struct wpa_cred *cred; | 
|  | 2654 | int ret; | 
|  | 2655 |  | 
|  | 2656 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); | 
|  | 2657 |  | 
|  | 2658 | cred = wpa_config_add_cred(wpa_s->conf); | 
|  | 2659 | if (cred == NULL) | 
|  | 2660 | return -1; | 
|  | 2661 |  | 
|  | 2662 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); | 
|  | 2663 | if (ret < 0 || (size_t) ret >= buflen) | 
|  | 2664 | return -1; | 
|  | 2665 | return ret; | 
|  | 2666 | } | 
|  | 2667 |  | 
|  | 2668 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2669 | static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s, | 
|  | 2670 | struct wpa_cred *cred) | 
|  | 2671 | { | 
|  | 2672 | struct wpa_ssid *ssid; | 
|  | 2673 | char str[20]; | 
|  | 2674 |  | 
|  | 2675 | if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) { | 
|  | 2676 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); | 
|  | 2677 | return -1; | 
|  | 2678 | } | 
|  | 2679 |  | 
|  | 2680 | /* Remove any network entry created based on the removed credential */ | 
|  | 2681 | ssid = wpa_s->conf->ssid; | 
|  | 2682 | while (ssid) { | 
|  | 2683 | if (ssid->parent_cred == cred) { | 
|  | 2684 | wpa_printf(MSG_DEBUG, "Remove network id %d since it " | 
|  | 2685 | "used the removed credential", ssid->id); | 
|  | 2686 | os_snprintf(str, sizeof(str), "%d", ssid->id); | 
|  | 2687 | ssid = ssid->next; | 
|  | 2688 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, str); | 
|  | 2689 | } else | 
|  | 2690 | ssid = ssid->next; | 
|  | 2691 | } | 
|  | 2692 |  | 
|  | 2693 | return 0; | 
|  | 2694 | } | 
|  | 2695 |  | 
|  | 2696 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2697 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, | 
|  | 2698 | char *cmd) | 
|  | 2699 | { | 
|  | 2700 | int id; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2701 | struct wpa_cred *cred, *prev; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2702 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2703 | /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */ | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2704 | if (os_strcmp(cmd, "all") == 0) { | 
|  | 2705 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); | 
|  | 2706 | cred = wpa_s->conf->cred; | 
|  | 2707 | while (cred) { | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2708 | prev = cred; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2709 | cred = cred->next; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2710 | wpas_ctrl_remove_cred(wpa_s, prev); | 
|  | 2711 | } | 
|  | 2712 | return 0; | 
|  | 2713 | } | 
|  | 2714 |  | 
|  | 2715 | if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) { | 
|  | 2716 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'", | 
|  | 2717 | cmd + 8); | 
|  | 2718 | cred = wpa_s->conf->cred; | 
|  | 2719 | while (cred) { | 
|  | 2720 | prev = cred; | 
|  | 2721 | cred = cred->next; | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2722 | if (prev->domain) { | 
|  | 2723 | size_t i; | 
|  | 2724 | for (i = 0; i < prev->num_domain; i++) { | 
|  | 2725 | if (os_strcmp(prev->domain[i], cmd + 8) | 
|  | 2726 | != 0) | 
|  | 2727 | continue; | 
|  | 2728 | wpas_ctrl_remove_cred(wpa_s, prev); | 
|  | 2729 | break; | 
|  | 2730 | } | 
|  | 2731 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2732 | } | 
|  | 2733 | return 0; | 
|  | 2734 | } | 
|  | 2735 |  | 
|  | 2736 | id = atoi(cmd); | 
|  | 2737 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); | 
|  | 2738 |  | 
|  | 2739 | cred = wpa_config_get_cred(wpa_s->conf, id); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2740 | return wpas_ctrl_remove_cred(wpa_s, cred); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2741 | } | 
|  | 2742 |  | 
|  | 2743 |  | 
|  | 2744 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, | 
|  | 2745 | char *cmd) | 
|  | 2746 | { | 
|  | 2747 | int id; | 
|  | 2748 | struct wpa_cred *cred; | 
|  | 2749 | char *name, *value; | 
|  | 2750 |  | 
|  | 2751 | /* cmd: "<cred id> <variable name> <value>" */ | 
|  | 2752 | name = os_strchr(cmd, ' '); | 
|  | 2753 | if (name == NULL) | 
|  | 2754 | return -1; | 
|  | 2755 | *name++ = '\0'; | 
|  | 2756 |  | 
|  | 2757 | value = os_strchr(name, ' '); | 
|  | 2758 | if (value == NULL) | 
|  | 2759 | return -1; | 
|  | 2760 | *value++ = '\0'; | 
|  | 2761 |  | 
|  | 2762 | id = atoi(cmd); | 
|  | 2763 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", | 
|  | 2764 | id, name); | 
|  | 2765 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | 
|  | 2766 | (u8 *) value, os_strlen(value)); | 
|  | 2767 |  | 
|  | 2768 | cred = wpa_config_get_cred(wpa_s->conf, id); | 
|  | 2769 | if (cred == NULL) { | 
|  | 2770 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | 
|  | 2771 | id); | 
|  | 2772 | return -1; | 
|  | 2773 | } | 
|  | 2774 |  | 
|  | 2775 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { | 
|  | 2776 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " | 
|  | 2777 | "variable '%s'", name); | 
|  | 2778 | return -1; | 
|  | 2779 | } | 
|  | 2780 |  | 
|  | 2781 | return 0; | 
|  | 2782 | } | 
|  | 2783 |  | 
|  | 2784 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2785 | #ifndef CONFIG_NO_CONFIG_WRITE | 
|  | 2786 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) | 
|  | 2787 | { | 
|  | 2788 | int ret; | 
|  | 2789 |  | 
|  | 2790 | if (!wpa_s->conf->update_config) { | 
|  | 2791 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " | 
|  | 2792 | "to update configuration (update_config=0)"); | 
|  | 2793 | return -1; | 
|  | 2794 | } | 
|  | 2795 |  | 
|  | 2796 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); | 
|  | 2797 | if (ret) { | 
|  | 2798 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " | 
|  | 2799 | "update configuration"); | 
|  | 2800 | } else { | 
|  | 2801 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" | 
|  | 2802 | " updated"); | 
|  | 2803 | } | 
|  | 2804 |  | 
|  | 2805 | return ret; | 
|  | 2806 | } | 
|  | 2807 | #endif /* CONFIG_NO_CONFIG_WRITE */ | 
|  | 2808 |  | 
|  | 2809 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2810 | struct cipher_info { | 
|  | 2811 | unsigned int capa; | 
|  | 2812 | const char *name; | 
|  | 2813 | int group_only; | 
|  | 2814 | }; | 
|  | 2815 |  | 
|  | 2816 | static const struct cipher_info ciphers[] = { | 
|  | 2817 | { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 }, | 
|  | 2818 | { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 }, | 
|  | 2819 | { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 }, | 
|  | 2820 | { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 }, | 
|  | 2821 | { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 }, | 
|  | 2822 | { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 }, | 
|  | 2823 | { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 }, | 
|  | 2824 | { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 } | 
|  | 2825 | }; | 
|  | 2826 |  | 
|  | 2827 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2828 | static int ctrl_iface_get_capability_pairwise(int res, char *strict, | 
|  | 2829 | struct wpa_driver_capa *capa, | 
|  | 2830 | char *buf, size_t buflen) | 
|  | 2831 | { | 
|  | 2832 | int ret, first = 1; | 
|  | 2833 | char *pos, *end; | 
|  | 2834 | size_t len; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2835 | unsigned int i; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2836 |  | 
|  | 2837 | pos = buf; | 
|  | 2838 | end = pos + buflen; | 
|  | 2839 |  | 
|  | 2840 | if (res < 0) { | 
|  | 2841 | if (strict) | 
|  | 2842 | return 0; | 
|  | 2843 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); | 
|  | 2844 | if (len >= buflen) | 
|  | 2845 | return -1; | 
|  | 2846 | return len; | 
|  | 2847 | } | 
|  | 2848 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2849 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { | 
|  | 2850 | if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) { | 
|  | 2851 | ret = os_snprintf(pos, end - pos, "%s%s", | 
|  | 2852 | first ? "" : " ", ciphers[i].name); | 
|  | 2853 | if (ret < 0 || ret >= end - pos) | 
|  | 2854 | return pos - buf; | 
|  | 2855 | pos += ret; | 
|  | 2856 | first = 0; | 
|  | 2857 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2858 | } | 
|  | 2859 |  | 
|  | 2860 | return pos - buf; | 
|  | 2861 | } | 
|  | 2862 |  | 
|  | 2863 |  | 
|  | 2864 | static int ctrl_iface_get_capability_group(int res, char *strict, | 
|  | 2865 | struct wpa_driver_capa *capa, | 
|  | 2866 | char *buf, size_t buflen) | 
|  | 2867 | { | 
|  | 2868 | int ret, first = 1; | 
|  | 2869 | char *pos, *end; | 
|  | 2870 | size_t len; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2871 | unsigned int i; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2872 |  | 
|  | 2873 | pos = buf; | 
|  | 2874 | end = pos + buflen; | 
|  | 2875 |  | 
|  | 2876 | if (res < 0) { | 
|  | 2877 | if (strict) | 
|  | 2878 | return 0; | 
|  | 2879 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); | 
|  | 2880 | if (len >= buflen) | 
|  | 2881 | return -1; | 
|  | 2882 | return len; | 
|  | 2883 | } | 
|  | 2884 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2885 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { | 
|  | 2886 | if (capa->enc & ciphers[i].capa) { | 
|  | 2887 | ret = os_snprintf(pos, end - pos, "%s%s", | 
|  | 2888 | first ? "" : " ", ciphers[i].name); | 
|  | 2889 | if (ret < 0 || ret >= end - pos) | 
|  | 2890 | return pos - buf; | 
|  | 2891 | pos += ret; | 
|  | 2892 | first = 0; | 
|  | 2893 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2894 | } | 
|  | 2895 |  | 
|  | 2896 | return pos - buf; | 
|  | 2897 | } | 
|  | 2898 |  | 
|  | 2899 |  | 
|  | 2900 | static int ctrl_iface_get_capability_key_mgmt(int res, char *strict, | 
|  | 2901 | struct wpa_driver_capa *capa, | 
|  | 2902 | char *buf, size_t buflen) | 
|  | 2903 | { | 
|  | 2904 | int ret; | 
|  | 2905 | char *pos, *end; | 
|  | 2906 | size_t len; | 
|  | 2907 |  | 
|  | 2908 | pos = buf; | 
|  | 2909 | end = pos + buflen; | 
|  | 2910 |  | 
|  | 2911 | if (res < 0) { | 
|  | 2912 | if (strict) | 
|  | 2913 | return 0; | 
|  | 2914 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " | 
|  | 2915 | "NONE", buflen); | 
|  | 2916 | if (len >= buflen) | 
|  | 2917 | return -1; | 
|  | 2918 | return len; | 
|  | 2919 | } | 
|  | 2920 |  | 
|  | 2921 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); | 
|  | 2922 | if (ret < 0 || ret >= end - pos) | 
|  | 2923 | return pos - buf; | 
|  | 2924 | pos += ret; | 
|  | 2925 |  | 
|  | 2926 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | 
|  | 2927 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { | 
|  | 2928 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); | 
|  | 2929 | if (ret < 0 || ret >= end - pos) | 
|  | 2930 | return pos - buf; | 
|  | 2931 | pos += ret; | 
|  | 2932 | } | 
|  | 2933 |  | 
|  | 2934 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | 
|  | 2935 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | 
|  | 2936 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); | 
|  | 2937 | if (ret < 0 || ret >= end - pos) | 
|  | 2938 | return pos - buf; | 
|  | 2939 | pos += ret; | 
|  | 2940 | } | 
|  | 2941 |  | 
|  | 2942 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | 
|  | 2943 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); | 
|  | 2944 | if (ret < 0 || ret >= end - pos) | 
|  | 2945 | return pos - buf; | 
|  | 2946 | pos += ret; | 
|  | 2947 | } | 
|  | 2948 |  | 
|  | 2949 | return pos - buf; | 
|  | 2950 | } | 
|  | 2951 |  | 
|  | 2952 |  | 
|  | 2953 | static int ctrl_iface_get_capability_proto(int res, char *strict, | 
|  | 2954 | struct wpa_driver_capa *capa, | 
|  | 2955 | char *buf, size_t buflen) | 
|  | 2956 | { | 
|  | 2957 | int ret, first = 1; | 
|  | 2958 | char *pos, *end; | 
|  | 2959 | size_t len; | 
|  | 2960 |  | 
|  | 2961 | pos = buf; | 
|  | 2962 | end = pos + buflen; | 
|  | 2963 |  | 
|  | 2964 | if (res < 0) { | 
|  | 2965 | if (strict) | 
|  | 2966 | return 0; | 
|  | 2967 | len = os_strlcpy(buf, "RSN WPA", buflen); | 
|  | 2968 | if (len >= buflen) | 
|  | 2969 | return -1; | 
|  | 2970 | return len; | 
|  | 2971 | } | 
|  | 2972 |  | 
|  | 2973 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | 
|  | 2974 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | 
|  | 2975 | ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " "); | 
|  | 2976 | if (ret < 0 || ret >= end - pos) | 
|  | 2977 | return pos - buf; | 
|  | 2978 | pos += ret; | 
|  | 2979 | first = 0; | 
|  | 2980 | } | 
|  | 2981 |  | 
|  | 2982 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | 
|  | 2983 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { | 
|  | 2984 | ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " "); | 
|  | 2985 | if (ret < 0 || ret >= end - pos) | 
|  | 2986 | return pos - buf; | 
|  | 2987 | pos += ret; | 
|  | 2988 | first = 0; | 
|  | 2989 | } | 
|  | 2990 |  | 
|  | 2991 | return pos - buf; | 
|  | 2992 | } | 
|  | 2993 |  | 
|  | 2994 |  | 
|  | 2995 | static int ctrl_iface_get_capability_auth_alg(int res, char *strict, | 
|  | 2996 | struct wpa_driver_capa *capa, | 
|  | 2997 | char *buf, size_t buflen) | 
|  | 2998 | { | 
|  | 2999 | int ret, first = 1; | 
|  | 3000 | char *pos, *end; | 
|  | 3001 | size_t len; | 
|  | 3002 |  | 
|  | 3003 | pos = buf; | 
|  | 3004 | end = pos + buflen; | 
|  | 3005 |  | 
|  | 3006 | if (res < 0) { | 
|  | 3007 | if (strict) | 
|  | 3008 | return 0; | 
|  | 3009 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); | 
|  | 3010 | if (len >= buflen) | 
|  | 3011 | return -1; | 
|  | 3012 | return len; | 
|  | 3013 | } | 
|  | 3014 |  | 
|  | 3015 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { | 
|  | 3016 | ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " "); | 
|  | 3017 | if (ret < 0 || ret >= end - pos) | 
|  | 3018 | return pos - buf; | 
|  | 3019 | pos += ret; | 
|  | 3020 | first = 0; | 
|  | 3021 | } | 
|  | 3022 |  | 
|  | 3023 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { | 
|  | 3024 | ret = os_snprintf(pos, end - pos, "%sSHARED", | 
|  | 3025 | first ? "" : " "); | 
|  | 3026 | if (ret < 0 || ret >= end - pos) | 
|  | 3027 | return pos - buf; | 
|  | 3028 | pos += ret; | 
|  | 3029 | first = 0; | 
|  | 3030 | } | 
|  | 3031 |  | 
|  | 3032 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { | 
|  | 3033 | ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " "); | 
|  | 3034 | if (ret < 0 || ret >= end - pos) | 
|  | 3035 | return pos - buf; | 
|  | 3036 | pos += ret; | 
|  | 3037 | first = 0; | 
|  | 3038 | } | 
|  | 3039 |  | 
|  | 3040 | return pos - buf; | 
|  | 3041 | } | 
|  | 3042 |  | 
|  | 3043 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3044 | static int ctrl_iface_get_capability_modes(int res, char *strict, | 
|  | 3045 | struct wpa_driver_capa *capa, | 
|  | 3046 | char *buf, size_t buflen) | 
|  | 3047 | { | 
|  | 3048 | int ret, first = 1; | 
|  | 3049 | char *pos, *end; | 
|  | 3050 | size_t len; | 
|  | 3051 |  | 
|  | 3052 | pos = buf; | 
|  | 3053 | end = pos + buflen; | 
|  | 3054 |  | 
|  | 3055 | if (res < 0) { | 
|  | 3056 | if (strict) | 
|  | 3057 | return 0; | 
|  | 3058 | len = os_strlcpy(buf, "IBSS AP", buflen); | 
|  | 3059 | if (len >= buflen) | 
|  | 3060 | return -1; | 
|  | 3061 | return len; | 
|  | 3062 | } | 
|  | 3063 |  | 
|  | 3064 | if (capa->flags & WPA_DRIVER_FLAGS_IBSS) { | 
|  | 3065 | ret = os_snprintf(pos, end - pos, "%sIBSS", first ? "" : " "); | 
|  | 3066 | if (ret < 0 || ret >= end - pos) | 
|  | 3067 | return pos - buf; | 
|  | 3068 | pos += ret; | 
|  | 3069 | first = 0; | 
|  | 3070 | } | 
|  | 3071 |  | 
|  | 3072 | if (capa->flags & WPA_DRIVER_FLAGS_AP) { | 
|  | 3073 | ret = os_snprintf(pos, end - pos, "%sAP", first ? "" : " "); | 
|  | 3074 | if (ret < 0 || ret >= end - pos) | 
|  | 3075 | return pos - buf; | 
|  | 3076 | pos += ret; | 
|  | 3077 | first = 0; | 
|  | 3078 | } | 
|  | 3079 |  | 
|  | 3080 | return pos - buf; | 
|  | 3081 | } | 
|  | 3082 |  | 
|  | 3083 |  | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3084 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, | 
|  | 3085 | char *buf, size_t buflen) | 
|  | 3086 | { | 
|  | 3087 | struct hostapd_channel_data *chnl; | 
|  | 3088 | int ret, i, j; | 
|  | 3089 | char *pos, *end, *hmode; | 
|  | 3090 |  | 
|  | 3091 | pos = buf; | 
|  | 3092 | end = pos + buflen; | 
|  | 3093 |  | 
|  | 3094 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | 
|  | 3095 | switch (wpa_s->hw.modes[j].mode) { | 
|  | 3096 | case HOSTAPD_MODE_IEEE80211B: | 
|  | 3097 | hmode = "B"; | 
|  | 3098 | break; | 
|  | 3099 | case HOSTAPD_MODE_IEEE80211G: | 
|  | 3100 | hmode = "G"; | 
|  | 3101 | break; | 
|  | 3102 | case HOSTAPD_MODE_IEEE80211A: | 
|  | 3103 | hmode = "A"; | 
|  | 3104 | break; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3105 | case HOSTAPD_MODE_IEEE80211AD: | 
|  | 3106 | hmode = "AD"; | 
|  | 3107 | break; | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3108 | default: | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3109 | continue; | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3110 | } | 
|  | 3111 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); | 
|  | 3112 | if (ret < 0 || ret >= end - pos) | 
|  | 3113 | return pos - buf; | 
|  | 3114 | pos += ret; | 
|  | 3115 | chnl = wpa_s->hw.modes[j].channels; | 
|  | 3116 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3117 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | 
|  | 3118 | continue; | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3119 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); | 
|  | 3120 | if (ret < 0 || ret >= end - pos) | 
|  | 3121 | return pos - buf; | 
|  | 3122 | pos += ret; | 
|  | 3123 | } | 
|  | 3124 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 3125 | if (ret < 0 || ret >= end - pos) | 
|  | 3126 | return pos - buf; | 
|  | 3127 | pos += ret; | 
|  | 3128 | } | 
|  | 3129 |  | 
|  | 3130 | return pos - buf; | 
|  | 3131 | } | 
|  | 3132 |  | 
|  | 3133 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3134 | static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s, | 
|  | 3135 | char *buf, size_t buflen) | 
|  | 3136 | { | 
|  | 3137 | struct hostapd_channel_data *chnl; | 
|  | 3138 | int ret, i, j; | 
|  | 3139 | char *pos, *end, *hmode; | 
|  | 3140 |  | 
|  | 3141 | pos = buf; | 
|  | 3142 | end = pos + buflen; | 
|  | 3143 |  | 
|  | 3144 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | 
|  | 3145 | switch (wpa_s->hw.modes[j].mode) { | 
|  | 3146 | case HOSTAPD_MODE_IEEE80211B: | 
|  | 3147 | hmode = "B"; | 
|  | 3148 | break; | 
|  | 3149 | case HOSTAPD_MODE_IEEE80211G: | 
|  | 3150 | hmode = "G"; | 
|  | 3151 | break; | 
|  | 3152 | case HOSTAPD_MODE_IEEE80211A: | 
|  | 3153 | hmode = "A"; | 
|  | 3154 | break; | 
|  | 3155 | case HOSTAPD_MODE_IEEE80211AD: | 
|  | 3156 | hmode = "AD"; | 
|  | 3157 | break; | 
|  | 3158 | default: | 
|  | 3159 | continue; | 
|  | 3160 | } | 
|  | 3161 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", | 
|  | 3162 | hmode); | 
|  | 3163 | if (ret < 0 || ret >= end - pos) | 
|  | 3164 | return pos - buf; | 
|  | 3165 | pos += ret; | 
|  | 3166 | chnl = wpa_s->hw.modes[j].channels; | 
|  | 3167 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | 
|  | 3168 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | 
|  | 3169 | continue; | 
| Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame^] | 3170 | ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n", | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3171 | chnl[i].chan, chnl[i].freq, | 
|  | 3172 | chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ? | 
| Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame^] | 3173 | " (NO_IBSS)" : "", | 
|  | 3174 | chnl[i].flag & HOSTAPD_CHAN_RADAR ? | 
|  | 3175 | " (DFS)" : ""); | 
|  | 3176 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3177 | if (ret < 0 || ret >= end - pos) | 
|  | 3178 | return pos - buf; | 
|  | 3179 | pos += ret; | 
|  | 3180 | } | 
|  | 3181 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 3182 | if (ret < 0 || ret >= end - pos) | 
|  | 3183 | return pos - buf; | 
|  | 3184 | pos += ret; | 
|  | 3185 | } | 
|  | 3186 |  | 
|  | 3187 | return pos - buf; | 
|  | 3188 | } | 
|  | 3189 |  | 
|  | 3190 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3191 | static int wpa_supplicant_ctrl_iface_get_capability( | 
|  | 3192 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, | 
|  | 3193 | size_t buflen) | 
|  | 3194 | { | 
|  | 3195 | struct wpa_driver_capa capa; | 
|  | 3196 | int res; | 
|  | 3197 | char *strict; | 
|  | 3198 | char field[30]; | 
|  | 3199 | size_t len; | 
|  | 3200 |  | 
|  | 3201 | /* Determine whether or not strict checking was requested */ | 
|  | 3202 | len = os_strlcpy(field, _field, sizeof(field)); | 
|  | 3203 | if (len >= sizeof(field)) | 
|  | 3204 | return -1; | 
|  | 3205 | strict = os_strchr(field, ' '); | 
|  | 3206 | if (strict != NULL) { | 
|  | 3207 | *strict++ = '\0'; | 
|  | 3208 | if (os_strcmp(strict, "strict") != 0) | 
|  | 3209 | return -1; | 
|  | 3210 | } | 
|  | 3211 |  | 
|  | 3212 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", | 
|  | 3213 | field, strict ? strict : ""); | 
|  | 3214 |  | 
|  | 3215 | if (os_strcmp(field, "eap") == 0) { | 
|  | 3216 | return eap_get_names(buf, buflen); | 
|  | 3217 | } | 
|  | 3218 |  | 
|  | 3219 | res = wpa_drv_get_capa(wpa_s, &capa); | 
|  | 3220 |  | 
|  | 3221 | if (os_strcmp(field, "pairwise") == 0) | 
|  | 3222 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, | 
|  | 3223 | buf, buflen); | 
|  | 3224 |  | 
|  | 3225 | if (os_strcmp(field, "group") == 0) | 
|  | 3226 | return ctrl_iface_get_capability_group(res, strict, &capa, | 
|  | 3227 | buf, buflen); | 
|  | 3228 |  | 
|  | 3229 | if (os_strcmp(field, "key_mgmt") == 0) | 
|  | 3230 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, | 
|  | 3231 | buf, buflen); | 
|  | 3232 |  | 
|  | 3233 | if (os_strcmp(field, "proto") == 0) | 
|  | 3234 | return ctrl_iface_get_capability_proto(res, strict, &capa, | 
|  | 3235 | buf, buflen); | 
|  | 3236 |  | 
|  | 3237 | if (os_strcmp(field, "auth_alg") == 0) | 
|  | 3238 | return ctrl_iface_get_capability_auth_alg(res, strict, &capa, | 
|  | 3239 | buf, buflen); | 
|  | 3240 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3241 | if (os_strcmp(field, "modes") == 0) | 
|  | 3242 | return ctrl_iface_get_capability_modes(res, strict, &capa, | 
|  | 3243 | buf, buflen); | 
|  | 3244 |  | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3245 | if (os_strcmp(field, "channels") == 0) | 
|  | 3246 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); | 
|  | 3247 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3248 | if (os_strcmp(field, "freq") == 0) | 
|  | 3249 | return ctrl_iface_get_capability_freq(wpa_s, buf, buflen); | 
|  | 3250 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3251 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", | 
|  | 3252 | field); | 
|  | 3253 |  | 
|  | 3254 | return -1; | 
|  | 3255 | } | 
|  | 3256 |  | 
|  | 3257 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3258 | #ifdef CONFIG_INTERWORKING | 
|  | 3259 | static char * anqp_add_hex(char *pos, char *end, const char *title, | 
|  | 3260 | struct wpabuf *data) | 
|  | 3261 | { | 
|  | 3262 | char *start = pos; | 
|  | 3263 | size_t i; | 
|  | 3264 | int ret; | 
|  | 3265 | const u8 *d; | 
|  | 3266 |  | 
|  | 3267 | if (data == NULL) | 
|  | 3268 | return start; | 
|  | 3269 |  | 
|  | 3270 | ret = os_snprintf(pos, end - pos, "%s=", title); | 
|  | 3271 | if (ret < 0 || ret >= end - pos) | 
|  | 3272 | return start; | 
|  | 3273 | pos += ret; | 
|  | 3274 |  | 
|  | 3275 | d = wpabuf_head_u8(data); | 
|  | 3276 | for (i = 0; i < wpabuf_len(data); i++) { | 
|  | 3277 | ret = os_snprintf(pos, end - pos, "%02x", *d++); | 
|  | 3278 | if (ret < 0 || ret >= end - pos) | 
|  | 3279 | return start; | 
|  | 3280 | pos += ret; | 
|  | 3281 | } | 
|  | 3282 |  | 
|  | 3283 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 3284 | if (ret < 0 || ret >= end - pos) | 
|  | 3285 | return start; | 
|  | 3286 | pos += ret; | 
|  | 3287 |  | 
|  | 3288 | return pos; | 
|  | 3289 | } | 
|  | 3290 | #endif /* CONFIG_INTERWORKING */ | 
|  | 3291 |  | 
|  | 3292 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3293 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, | 
|  | 3294 | unsigned long mask, char *buf, size_t buflen) | 
|  | 3295 | { | 
|  | 3296 | size_t i; | 
|  | 3297 | int ret; | 
|  | 3298 | char *pos, *end; | 
|  | 3299 | const u8 *ie, *ie2; | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3300 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3301 | pos = buf; | 
|  | 3302 | end = buf + buflen; | 
|  | 3303 |  | 
|  | 3304 | if (mask & WPA_BSS_MASK_ID) { | 
|  | 3305 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); | 
|  | 3306 | if (ret < 0 || ret >= end - pos) | 
|  | 3307 | return 0; | 
|  | 3308 | pos += ret; | 
|  | 3309 | } | 
|  | 3310 |  | 
|  | 3311 | if (mask & WPA_BSS_MASK_BSSID) { | 
|  | 3312 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | 
|  | 3313 | MAC2STR(bss->bssid)); | 
|  | 3314 | if (ret < 0 || ret >= end - pos) | 
|  | 3315 | return 0; | 
|  | 3316 | pos += ret; | 
|  | 3317 | } | 
|  | 3318 |  | 
|  | 3319 | if (mask & WPA_BSS_MASK_FREQ) { | 
|  | 3320 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); | 
|  | 3321 | if (ret < 0 || ret >= end - pos) | 
|  | 3322 | return 0; | 
|  | 3323 | pos += ret; | 
|  | 3324 | } | 
|  | 3325 |  | 
|  | 3326 | if (mask & WPA_BSS_MASK_BEACON_INT) { | 
|  | 3327 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", | 
|  | 3328 | bss->beacon_int); | 
|  | 3329 | if (ret < 0 || ret >= end - pos) | 
|  | 3330 | return 0; | 
|  | 3331 | pos += ret; | 
|  | 3332 | } | 
|  | 3333 |  | 
|  | 3334 | if (mask & WPA_BSS_MASK_CAPABILITIES) { | 
|  | 3335 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", | 
|  | 3336 | bss->caps); | 
|  | 3337 | if (ret < 0 || ret >= end - pos) | 
|  | 3338 | return 0; | 
|  | 3339 | pos += ret; | 
|  | 3340 | } | 
|  | 3341 |  | 
|  | 3342 | if (mask & WPA_BSS_MASK_QUAL) { | 
|  | 3343 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); | 
|  | 3344 | if (ret < 0 || ret >= end - pos) | 
|  | 3345 | return 0; | 
|  | 3346 | pos += ret; | 
|  | 3347 | } | 
|  | 3348 |  | 
|  | 3349 | if (mask & WPA_BSS_MASK_NOISE) { | 
|  | 3350 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); | 
|  | 3351 | if (ret < 0 || ret >= end - pos) | 
|  | 3352 | return 0; | 
|  | 3353 | pos += ret; | 
|  | 3354 | } | 
|  | 3355 |  | 
|  | 3356 | if (mask & WPA_BSS_MASK_LEVEL) { | 
|  | 3357 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); | 
|  | 3358 | if (ret < 0 || ret >= end - pos) | 
|  | 3359 | return 0; | 
|  | 3360 | pos += ret; | 
|  | 3361 | } | 
|  | 3362 |  | 
|  | 3363 | if (mask & WPA_BSS_MASK_TSF) { | 
|  | 3364 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", | 
|  | 3365 | (unsigned long long) bss->tsf); | 
|  | 3366 | if (ret < 0 || ret >= end - pos) | 
|  | 3367 | return 0; | 
|  | 3368 | pos += ret; | 
|  | 3369 | } | 
|  | 3370 |  | 
|  | 3371 | if (mask & WPA_BSS_MASK_AGE) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3372 | struct os_reltime now; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3373 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3374 | os_get_reltime(&now); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3375 | ret = os_snprintf(pos, end - pos, "age=%d\n", | 
|  | 3376 | (int) (now.sec - bss->last_update.sec)); | 
|  | 3377 | if (ret < 0 || ret >= end - pos) | 
|  | 3378 | return 0; | 
|  | 3379 | pos += ret; | 
|  | 3380 | } | 
|  | 3381 |  | 
|  | 3382 | if (mask & WPA_BSS_MASK_IE) { | 
|  | 3383 | ret = os_snprintf(pos, end - pos, "ie="); | 
|  | 3384 | if (ret < 0 || ret >= end - pos) | 
|  | 3385 | return 0; | 
|  | 3386 | pos += ret; | 
|  | 3387 |  | 
|  | 3388 | ie = (const u8 *) (bss + 1); | 
|  | 3389 | for (i = 0; i < bss->ie_len; i++) { | 
|  | 3390 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | 
|  | 3391 | if (ret < 0 || ret >= end - pos) | 
|  | 3392 | return 0; | 
|  | 3393 | pos += ret; | 
|  | 3394 | } | 
|  | 3395 |  | 
|  | 3396 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 3397 | if (ret < 0 || ret >= end - pos) | 
|  | 3398 | return 0; | 
|  | 3399 | pos += ret; | 
|  | 3400 | } | 
|  | 3401 |  | 
|  | 3402 | if (mask & WPA_BSS_MASK_FLAGS) { | 
|  | 3403 | ret = os_snprintf(pos, end - pos, "flags="); | 
|  | 3404 | if (ret < 0 || ret >= end - pos) | 
|  | 3405 | return 0; | 
|  | 3406 | pos += ret; | 
|  | 3407 |  | 
|  | 3408 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | 
|  | 3409 | if (ie) | 
|  | 3410 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, | 
|  | 3411 | 2 + ie[1]); | 
|  | 3412 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); | 
|  | 3413 | if (ie2) | 
|  | 3414 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, | 
|  | 3415 | 2 + ie2[1]); | 
|  | 3416 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); | 
|  | 3417 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { | 
|  | 3418 | ret = os_snprintf(pos, end - pos, "[WEP]"); | 
|  | 3419 | if (ret < 0 || ret >= end - pos) | 
|  | 3420 | return 0; | 
|  | 3421 | pos += ret; | 
|  | 3422 | } | 
|  | 3423 | if (bss->caps & IEEE80211_CAP_IBSS) { | 
|  | 3424 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | 
|  | 3425 | if (ret < 0 || ret >= end - pos) | 
|  | 3426 | return 0; | 
|  | 3427 | pos += ret; | 
|  | 3428 | } | 
|  | 3429 | if (bss->caps & IEEE80211_CAP_ESS) { | 
|  | 3430 | ret = os_snprintf(pos, end - pos, "[ESS]"); | 
|  | 3431 | if (ret < 0 || ret >= end - pos) | 
|  | 3432 | return 0; | 
|  | 3433 | pos += ret; | 
|  | 3434 | } | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 3435 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || | 
|  | 3436 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3437 | ret = os_snprintf(pos, end - pos, "[P2P]"); | 
|  | 3438 | if (ret < 0 || ret >= end - pos) | 
|  | 3439 | return 0; | 
|  | 3440 | pos += ret; | 
|  | 3441 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3442 | #ifdef CONFIG_HS20 | 
|  | 3443 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { | 
|  | 3444 | ret = os_snprintf(pos, end - pos, "[HS20]"); | 
|  | 3445 | if (ret < 0 || ret >= end - pos) | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 3446 | return 0; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3447 | pos += ret; | 
|  | 3448 | } | 
|  | 3449 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3450 |  | 
|  | 3451 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 3452 | if (ret < 0 || ret >= end - pos) | 
|  | 3453 | return 0; | 
|  | 3454 | pos += ret; | 
|  | 3455 | } | 
|  | 3456 |  | 
|  | 3457 | if (mask & WPA_BSS_MASK_SSID) { | 
|  | 3458 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", | 
|  | 3459 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | 
|  | 3460 | if (ret < 0 || ret >= end - pos) | 
|  | 3461 | return 0; | 
|  | 3462 | pos += ret; | 
|  | 3463 | } | 
|  | 3464 |  | 
|  | 3465 | #ifdef CONFIG_WPS | 
|  | 3466 | if (mask & WPA_BSS_MASK_WPS_SCAN) { | 
|  | 3467 | ie = (const u8 *) (bss + 1); | 
|  | 3468 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); | 
|  | 3469 | if (ret < 0 || ret >= end - pos) | 
|  | 3470 | return 0; | 
|  | 3471 | pos += ret; | 
|  | 3472 | } | 
|  | 3473 | #endif /* CONFIG_WPS */ | 
|  | 3474 |  | 
|  | 3475 | #ifdef CONFIG_P2P | 
|  | 3476 | if (mask & WPA_BSS_MASK_P2P_SCAN) { | 
|  | 3477 | ie = (const u8 *) (bss + 1); | 
|  | 3478 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); | 
|  | 3479 | if (ret < 0 || ret >= end - pos) | 
|  | 3480 | return 0; | 
|  | 3481 | pos += ret; | 
|  | 3482 | } | 
|  | 3483 | #endif /* CONFIG_P2P */ | 
|  | 3484 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3485 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 3486 | if (mask & WPA_BSS_MASK_WIFI_DISPLAY) { | 
|  | 3487 | struct wpabuf *wfd; | 
|  | 3488 | ie = (const u8 *) (bss + 1); | 
|  | 3489 | wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len, | 
|  | 3490 | WFD_IE_VENDOR_TYPE); | 
|  | 3491 | if (wfd) { | 
|  | 3492 | ret = os_snprintf(pos, end - pos, "wfd_subelems="); | 
|  | 3493 | if (ret < 0 || ret >= end - pos) | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 3494 | return 0; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3495 | pos += ret; | 
|  | 3496 |  | 
|  | 3497 | pos += wpa_snprintf_hex(pos, end - pos, | 
|  | 3498 | wpabuf_head(wfd), | 
|  | 3499 | wpabuf_len(wfd)); | 
|  | 3500 | wpabuf_free(wfd); | 
|  | 3501 |  | 
|  | 3502 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 3503 | if (ret < 0 || ret >= end - pos) | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 3504 | return 0; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3505 | pos += ret; | 
|  | 3506 | } | 
|  | 3507 | } | 
|  | 3508 | #endif /* CONFIG_WIFI_DISPLAY */ | 
|  | 3509 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3510 | #ifdef CONFIG_INTERWORKING | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3511 | if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) { | 
|  | 3512 | struct wpa_bss_anqp *anqp = bss->anqp; | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3513 | pos = anqp_add_hex(pos, end, "anqp_venue_name", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3514 | anqp->venue_name); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3515 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3516 | anqp->network_auth_type); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3517 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3518 | anqp->roaming_consortium); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3519 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3520 | anqp->ip_addr_type_availability); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3521 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3522 | anqp->nai_realm); | 
|  | 3523 | pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3524 | pos = anqp_add_hex(pos, end, "anqp_domain_name", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3525 | anqp->domain_name); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3526 | #ifdef CONFIG_HS20 | 
|  | 3527 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3528 | anqp->hs20_operator_friendly_name); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3529 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3530 | anqp->hs20_wan_metrics); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3531 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3532 | anqp->hs20_connection_capability); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3533 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3534 | } | 
|  | 3535 | #endif /* CONFIG_INTERWORKING */ | 
|  | 3536 |  | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 3537 | if (mask & WPA_BSS_MASK_DELIM) { | 
|  | 3538 | ret = os_snprintf(pos, end - pos, "====\n"); | 
|  | 3539 | if (ret < 0 || ret >= end - pos) | 
|  | 3540 | return 0; | 
|  | 3541 | pos += ret; | 
|  | 3542 | } | 
| Irfan Sheriff | e2ea008 | 2012-08-13 10:56:16 -0700 | [diff] [blame] | 3543 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3544 | return pos - buf; | 
|  | 3545 | } | 
|  | 3546 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3547 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3548 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, | 
|  | 3549 | const char *cmd, char *buf, | 
|  | 3550 | size_t buflen) | 
|  | 3551 | { | 
|  | 3552 | u8 bssid[ETH_ALEN]; | 
|  | 3553 | size_t i; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3554 | struct wpa_bss *bss; | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3555 | struct wpa_bss *bsslast = NULL; | 
|  | 3556 | struct dl_list *next; | 
|  | 3557 | int ret = 0; | 
|  | 3558 | int len; | 
|  | 3559 | char *ctmp; | 
|  | 3560 | unsigned long mask = WPA_BSS_MASK_ALL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3561 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3562 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { | 
|  | 3563 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { | 
|  | 3564 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3565 | list_id); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3566 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, | 
|  | 3567 | list_id); | 
|  | 3568 | } else { /* N1-N2 */ | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3569 | unsigned int id1, id2; | 
|  | 3570 |  | 
|  | 3571 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { | 
|  | 3572 | wpa_printf(MSG_INFO, "Wrong BSS range " | 
|  | 3573 | "format"); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3574 | return 0; | 
|  | 3575 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3576 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3577 | if (*(cmd + 6) == '-') | 
|  | 3578 | id1 = 0; | 
|  | 3579 | else | 
|  | 3580 | id1 = atoi(cmd + 6); | 
|  | 3581 | ctmp++; | 
|  | 3582 | if (*ctmp >= '0' && *ctmp <= '9') | 
|  | 3583 | id2 = atoi(ctmp); | 
|  | 3584 | else | 
|  | 3585 | id2 = (unsigned int) -1; | 
|  | 3586 | bss = wpa_bss_get_id_range(wpa_s, id1, id2); | 
|  | 3587 | if (id2 == (unsigned int) -1) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3588 | bsslast = dl_list_last(&wpa_s->bss_id, | 
|  | 3589 | struct wpa_bss, | 
|  | 3590 | list_id); | 
|  | 3591 | else { | 
|  | 3592 | bsslast = wpa_bss_get_id(wpa_s, id2); | 
|  | 3593 | if (bsslast == NULL && bss && id2 > id1) { | 
|  | 3594 | struct wpa_bss *tmp = bss; | 
|  | 3595 | for (;;) { | 
|  | 3596 | next = tmp->list_id.next; | 
|  | 3597 | if (next == &wpa_s->bss_id) | 
|  | 3598 | break; | 
|  | 3599 | tmp = dl_list_entry( | 
|  | 3600 | next, struct wpa_bss, | 
|  | 3601 | list_id); | 
|  | 3602 | if (tmp->id > id2) | 
|  | 3603 | break; | 
|  | 3604 | bsslast = tmp; | 
|  | 3605 | } | 
|  | 3606 | } | 
|  | 3607 | } | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3608 | } | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3609 | } else if (os_strncmp(cmd, "FIRST", 5) == 0) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3610 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id); | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3611 | else if (os_strncmp(cmd, "LAST", 4) == 0) | 
|  | 3612 | bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3613 | else if (os_strncmp(cmd, "ID-", 3) == 0) { | 
|  | 3614 | i = atoi(cmd + 3); | 
|  | 3615 | bss = wpa_bss_get_id(wpa_s, i); | 
|  | 3616 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | 
|  | 3617 | i = atoi(cmd + 5); | 
|  | 3618 | bss = wpa_bss_get_id(wpa_s, i); | 
|  | 3619 | if (bss) { | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3620 | next = bss->list_id.next; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3621 | if (next == &wpa_s->bss_id) | 
|  | 3622 | bss = NULL; | 
|  | 3623 | else | 
|  | 3624 | bss = dl_list_entry(next, struct wpa_bss, | 
|  | 3625 | list_id); | 
|  | 3626 | } | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3627 | #ifdef CONFIG_P2P | 
|  | 3628 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | 
|  | 3629 | if (hwaddr_aton(cmd + 13, bssid) == 0) | 
|  | 3630 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); | 
|  | 3631 | else | 
|  | 3632 | bss = NULL; | 
|  | 3633 | #endif /* CONFIG_P2P */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3634 | } else if (hwaddr_aton(cmd, bssid) == 0) | 
|  | 3635 | bss = wpa_bss_get_bssid(wpa_s, bssid); | 
|  | 3636 | else { | 
|  | 3637 | struct wpa_bss *tmp; | 
|  | 3638 | i = atoi(cmd); | 
|  | 3639 | bss = NULL; | 
|  | 3640 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) | 
|  | 3641 | { | 
|  | 3642 | if (i-- == 0) { | 
|  | 3643 | bss = tmp; | 
|  | 3644 | break; | 
|  | 3645 | } | 
|  | 3646 | } | 
|  | 3647 | } | 
|  | 3648 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3649 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { | 
|  | 3650 | mask = strtoul(ctmp + 5, NULL, 0x10); | 
|  | 3651 | if (mask == 0) | 
|  | 3652 | mask = WPA_BSS_MASK_ALL; | 
|  | 3653 | } | 
|  | 3654 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3655 | if (bss == NULL) | 
|  | 3656 | return 0; | 
|  | 3657 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3658 | if (bsslast == NULL) | 
|  | 3659 | bsslast = bss; | 
|  | 3660 | do { | 
|  | 3661 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); | 
|  | 3662 | ret += len; | 
|  | 3663 | buf += len; | 
|  | 3664 | buflen -= len; | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 3665 | if (bss == bsslast) { | 
|  | 3666 | if ((mask & WPA_BSS_MASK_DELIM) && len && | 
|  | 3667 | (bss == dl_list_last(&wpa_s->bss_id, | 
|  | 3668 | struct wpa_bss, list_id))) | 
|  | 3669 | os_snprintf(buf - 5, 5, "####\n"); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3670 | break; | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 3671 | } | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3672 | next = bss->list_id.next; | 
|  | 3673 | if (next == &wpa_s->bss_id) | 
|  | 3674 | break; | 
|  | 3675 | bss = dl_list_entry(next, struct wpa_bss, list_id); | 
|  | 3676 | } while (bss && len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3677 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 3678 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3679 | } | 
|  | 3680 |  | 
|  | 3681 |  | 
|  | 3682 | static int wpa_supplicant_ctrl_iface_ap_scan( | 
|  | 3683 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3684 | { | 
|  | 3685 | int ap_scan = atoi(cmd); | 
|  | 3686 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); | 
|  | 3687 | } | 
|  | 3688 |  | 
|  | 3689 |  | 
|  | 3690 | static int wpa_supplicant_ctrl_iface_scan_interval( | 
|  | 3691 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3692 | { | 
|  | 3693 | int scan_int = atoi(cmd); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3694 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3695 | } | 
|  | 3696 |  | 
|  | 3697 |  | 
|  | 3698 | static int wpa_supplicant_ctrl_iface_bss_expire_age( | 
|  | 3699 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3700 | { | 
|  | 3701 | int expire_age = atoi(cmd); | 
|  | 3702 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); | 
|  | 3703 | } | 
|  | 3704 |  | 
|  | 3705 |  | 
|  | 3706 | static int wpa_supplicant_ctrl_iface_bss_expire_count( | 
|  | 3707 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3708 | { | 
|  | 3709 | int expire_count = atoi(cmd); | 
|  | 3710 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); | 
|  | 3711 | } | 
|  | 3712 |  | 
|  | 3713 |  | 
| Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 3714 | static int wpa_supplicant_ctrl_iface_bss_flush( | 
|  | 3715 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3716 | { | 
|  | 3717 | int flush_age = atoi(cmd); | 
|  | 3718 |  | 
|  | 3719 | if (flush_age == 0) | 
|  | 3720 | wpa_bss_flush(wpa_s); | 
|  | 3721 | else | 
|  | 3722 | wpa_bss_flush_by_age(wpa_s, flush_age); | 
|  | 3723 | return 0; | 
|  | 3724 | } | 
|  | 3725 |  | 
|  | 3726 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3727 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) | 
|  | 3728 | { | 
|  | 3729 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); | 
|  | 3730 | /* MLME-DELETEKEYS.request */ | 
|  | 3731 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0); | 
|  | 3732 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0); | 
|  | 3733 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0); | 
|  | 3734 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0); | 
|  | 3735 | #ifdef CONFIG_IEEE80211W | 
|  | 3736 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0); | 
|  | 3737 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0); | 
|  | 3738 | #endif /* CONFIG_IEEE80211W */ | 
|  | 3739 |  | 
|  | 3740 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, | 
|  | 3741 | 0); | 
|  | 3742 | /* MLME-SETPROTECTION.request(None) */ | 
|  | 3743 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, | 
|  | 3744 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, | 
|  | 3745 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); | 
|  | 3746 | wpa_sm_drop_sa(wpa_s->wpa); | 
|  | 3747 | } | 
|  | 3748 |  | 
|  | 3749 |  | 
|  | 3750 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, | 
|  | 3751 | char *addr) | 
|  | 3752 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3753 | #ifdef CONFIG_NO_SCAN_PROCESSING | 
|  | 3754 | return -1; | 
|  | 3755 | #else /* CONFIG_NO_SCAN_PROCESSING */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3756 | u8 bssid[ETH_ALEN]; | 
|  | 3757 | struct wpa_bss *bss; | 
|  | 3758 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
|  | 3759 |  | 
|  | 3760 | if (hwaddr_aton(addr, bssid)) { | 
|  | 3761 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " | 
|  | 3762 | "address '%s'", addr); | 
|  | 3763 | return -1; | 
|  | 3764 | } | 
|  | 3765 |  | 
|  | 3766 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); | 
|  | 3767 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3768 | if (!ssid) { | 
|  | 3769 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " | 
|  | 3770 | "configuration known for the target AP"); | 
|  | 3771 | return -1; | 
|  | 3772 | } | 
|  | 3773 |  | 
|  | 3774 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3775 | if (!bss) { | 
|  | 3776 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " | 
|  | 3777 | "from BSS table"); | 
|  | 3778 | return -1; | 
|  | 3779 | } | 
|  | 3780 |  | 
|  | 3781 | /* | 
|  | 3782 | * TODO: Find best network configuration block from configuration to | 
|  | 3783 | * allow roaming to other networks | 
|  | 3784 | */ | 
|  | 3785 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3786 | wpa_s->reassociate = 1; | 
|  | 3787 | wpa_supplicant_connect(wpa_s, bss, ssid); | 
|  | 3788 |  | 
|  | 3789 | return 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3790 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3791 | } | 
|  | 3792 |  | 
|  | 3793 |  | 
|  | 3794 | #ifdef CONFIG_P2P | 
|  | 3795 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3796 | { | 
|  | 3797 | unsigned int timeout = atoi(cmd); | 
|  | 3798 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3799 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3800 | u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3801 | char *pos; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3802 | unsigned int search_delay; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3803 |  | 
|  | 3804 | if (os_strstr(cmd, "type=social")) | 
|  | 3805 | type = P2P_FIND_ONLY_SOCIAL; | 
|  | 3806 | else if (os_strstr(cmd, "type=progressive")) | 
|  | 3807 | type = P2P_FIND_PROGRESSIVE; | 
|  | 3808 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3809 | pos = os_strstr(cmd, "dev_id="); | 
|  | 3810 | if (pos) { | 
|  | 3811 | pos += 7; | 
|  | 3812 | if (hwaddr_aton(pos, dev_id)) | 
|  | 3813 | return -1; | 
|  | 3814 | _dev_id = dev_id; | 
|  | 3815 | } | 
|  | 3816 |  | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3817 | pos = os_strstr(cmd, "dev_type="); | 
|  | 3818 | if (pos) { | 
|  | 3819 | pos += 9; | 
|  | 3820 | if (wps_dev_type_str2bin(pos, dev_type) < 0) | 
|  | 3821 | return -1; | 
|  | 3822 | _dev_type = dev_type; | 
|  | 3823 | } | 
|  | 3824 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3825 | pos = os_strstr(cmd, "delay="); | 
|  | 3826 | if (pos) { | 
|  | 3827 | pos += 6; | 
|  | 3828 | search_delay = atoi(pos); | 
|  | 3829 | } else | 
|  | 3830 | search_delay = wpas_p2p_search_delay(wpa_s); | 
|  | 3831 |  | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3832 | return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type, | 
|  | 3833 | _dev_id, search_delay); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3834 | } | 
|  | 3835 |  | 
|  | 3836 |  | 
|  | 3837 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 3838 | char *buf, size_t buflen) | 
|  | 3839 | { | 
|  | 3840 | u8 addr[ETH_ALEN]; | 
|  | 3841 | char *pos, *pos2; | 
|  | 3842 | char *pin = NULL; | 
|  | 3843 | enum p2p_wps_method wps_method; | 
|  | 3844 | int new_pin; | 
|  | 3845 | int ret; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3846 | int persistent_group, persistent_id = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3847 | int join; | 
|  | 3848 | int auth; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3849 | int automatic; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3850 | int go_intent = -1; | 
|  | 3851 | int freq = 0; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3852 | int pd; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3853 | int ht40, vht; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3854 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3855 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad] | 
|  | 3856 | * [persistent|persistent=<network id>] | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3857 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3858 | * [ht40] [vht] */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3859 |  | 
|  | 3860 | if (hwaddr_aton(cmd, addr)) | 
|  | 3861 | return -1; | 
|  | 3862 |  | 
|  | 3863 | pos = cmd + 17; | 
|  | 3864 | if (*pos != ' ') | 
|  | 3865 | return -1; | 
|  | 3866 | pos++; | 
|  | 3867 |  | 
|  | 3868 | persistent_group = os_strstr(pos, " persistent") != NULL; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3869 | pos2 = os_strstr(pos, " persistent="); | 
|  | 3870 | if (pos2) { | 
|  | 3871 | struct wpa_ssid *ssid; | 
|  | 3872 | persistent_id = atoi(pos2 + 12); | 
|  | 3873 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); | 
|  | 3874 | if (ssid == NULL || ssid->disabled != 2 || | 
|  | 3875 | ssid->mode != WPAS_MODE_P2P_GO) { | 
|  | 3876 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
|  | 3877 | "SSID id=%d for persistent P2P group (GO)", | 
|  | 3878 | persistent_id); | 
|  | 3879 | return -1; | 
|  | 3880 | } | 
|  | 3881 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3882 | join = os_strstr(pos, " join") != NULL; | 
|  | 3883 | auth = os_strstr(pos, " auth") != NULL; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3884 | automatic = os_strstr(pos, " auto") != NULL; | 
|  | 3885 | pd = os_strstr(pos, " provdisc") != NULL; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3886 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; | 
|  | 3887 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | 
|  | 3888 | vht; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3889 |  | 
|  | 3890 | pos2 = os_strstr(pos, " go_intent="); | 
|  | 3891 | if (pos2) { | 
|  | 3892 | pos2 += 11; | 
|  | 3893 | go_intent = atoi(pos2); | 
|  | 3894 | if (go_intent < 0 || go_intent > 15) | 
|  | 3895 | return -1; | 
|  | 3896 | } | 
|  | 3897 |  | 
|  | 3898 | pos2 = os_strstr(pos, " freq="); | 
|  | 3899 | if (pos2) { | 
|  | 3900 | pos2 += 6; | 
|  | 3901 | freq = atoi(pos2); | 
|  | 3902 | if (freq <= 0) | 
|  | 3903 | return -1; | 
|  | 3904 | } | 
|  | 3905 |  | 
|  | 3906 | if (os_strncmp(pos, "pin", 3) == 0) { | 
|  | 3907 | /* Request random PIN (to be displayed) and enable the PIN */ | 
|  | 3908 | wps_method = WPS_PIN_DISPLAY; | 
|  | 3909 | } else if (os_strncmp(pos, "pbc", 3) == 0) { | 
|  | 3910 | wps_method = WPS_PBC; | 
|  | 3911 | } else { | 
|  | 3912 | pin = pos; | 
|  | 3913 | pos = os_strchr(pin, ' '); | 
|  | 3914 | wps_method = WPS_PIN_KEYPAD; | 
|  | 3915 | if (pos) { | 
|  | 3916 | *pos++ = '\0'; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3917 | if (os_strncmp(pos, "display", 7) == 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3918 | wps_method = WPS_PIN_DISPLAY; | 
|  | 3919 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3920 | if (!wps_pin_str_valid(pin)) { | 
|  | 3921 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); | 
|  | 3922 | return 17; | 
|  | 3923 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3924 | } | 
|  | 3925 |  | 
|  | 3926 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3927 | persistent_group, automatic, join, | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3928 | auth, go_intent, freq, persistent_id, pd, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3929 | ht40, vht); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3930 | if (new_pin == -2) { | 
|  | 3931 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); | 
|  | 3932 | return 25; | 
|  | 3933 | } | 
|  | 3934 | if (new_pin == -3) { | 
|  | 3935 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); | 
|  | 3936 | return 25; | 
|  | 3937 | } | 
|  | 3938 | if (new_pin < 0) | 
|  | 3939 | return -1; | 
|  | 3940 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { | 
|  | 3941 | ret = os_snprintf(buf, buflen, "%08d", new_pin); | 
|  | 3942 | if (ret < 0 || (size_t) ret >= buflen) | 
|  | 3943 | return -1; | 
|  | 3944 | return ret; | 
|  | 3945 | } | 
|  | 3946 |  | 
|  | 3947 | os_memcpy(buf, "OK\n", 3); | 
|  | 3948 | return 3; | 
|  | 3949 | } | 
|  | 3950 |  | 
|  | 3951 |  | 
|  | 3952 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3953 | { | 
|  | 3954 | unsigned int timeout = atoi(cmd); | 
|  | 3955 | return wpas_p2p_listen(wpa_s, timeout); | 
|  | 3956 | } | 
|  | 3957 |  | 
|  | 3958 |  | 
|  | 3959 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3960 | { | 
|  | 3961 | u8 addr[ETH_ALEN]; | 
|  | 3962 | char *pos; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3963 | enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3964 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3965 | /* <addr> <config method> [join|auto] */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3966 |  | 
|  | 3967 | if (hwaddr_aton(cmd, addr)) | 
|  | 3968 | return -1; | 
|  | 3969 |  | 
|  | 3970 | pos = cmd + 17; | 
|  | 3971 | if (*pos != ' ') | 
|  | 3972 | return -1; | 
|  | 3973 | pos++; | 
|  | 3974 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3975 | if (os_strstr(pos, " join") != NULL) | 
|  | 3976 | use = WPAS_P2P_PD_FOR_JOIN; | 
|  | 3977 | else if (os_strstr(pos, " auto") != NULL) | 
|  | 3978 | use = WPAS_P2P_PD_AUTO; | 
|  | 3979 |  | 
|  | 3980 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3981 | } | 
|  | 3982 |  | 
|  | 3983 |  | 
|  | 3984 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, | 
|  | 3985 | size_t buflen) | 
|  | 3986 | { | 
|  | 3987 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
|  | 3988 |  | 
|  | 3989 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | 
|  | 3990 | ssid->passphrase == NULL) | 
|  | 3991 | return -1; | 
|  | 3992 |  | 
|  | 3993 | os_strlcpy(buf, ssid->passphrase, buflen); | 
|  | 3994 | return os_strlen(buf); | 
|  | 3995 | } | 
|  | 3996 |  | 
|  | 3997 |  | 
|  | 3998 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 3999 | char *buf, size_t buflen) | 
|  | 4000 | { | 
|  | 4001 | u64 ref; | 
|  | 4002 | int res; | 
|  | 4003 | u8 dst_buf[ETH_ALEN], *dst; | 
|  | 4004 | struct wpabuf *tlvs; | 
|  | 4005 | char *pos; | 
|  | 4006 | size_t len; | 
|  | 4007 |  | 
|  | 4008 | if (hwaddr_aton(cmd, dst_buf)) | 
|  | 4009 | return -1; | 
|  | 4010 | dst = dst_buf; | 
|  | 4011 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && | 
|  | 4012 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) | 
|  | 4013 | dst = NULL; | 
|  | 4014 | pos = cmd + 17; | 
|  | 4015 | if (*pos != ' ') | 
|  | 4016 | return -1; | 
|  | 4017 | pos++; | 
|  | 4018 |  | 
|  | 4019 | if (os_strncmp(pos, "upnp ", 5) == 0) { | 
|  | 4020 | u8 version; | 
|  | 4021 | pos += 5; | 
|  | 4022 | if (hexstr2bin(pos, &version, 1) < 0) | 
|  | 4023 | return -1; | 
|  | 4024 | pos += 2; | 
|  | 4025 | if (*pos != ' ') | 
|  | 4026 | return -1; | 
|  | 4027 | pos++; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4028 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4029 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 4030 | } else if (os_strncmp(pos, "wifi-display ", 13) == 0) { | 
|  | 4031 | ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13); | 
|  | 4032 | #endif /* CONFIG_WIFI_DISPLAY */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4033 | } else { | 
|  | 4034 | len = os_strlen(pos); | 
|  | 4035 | if (len & 1) | 
|  | 4036 | return -1; | 
|  | 4037 | len /= 2; | 
|  | 4038 | tlvs = wpabuf_alloc(len); | 
|  | 4039 | if (tlvs == NULL) | 
|  | 4040 | return -1; | 
|  | 4041 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { | 
|  | 4042 | wpabuf_free(tlvs); | 
|  | 4043 | return -1; | 
|  | 4044 | } | 
|  | 4045 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4046 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4047 | wpabuf_free(tlvs); | 
|  | 4048 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4049 | if (ref == 0) | 
|  | 4050 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4051 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); | 
|  | 4052 | if (res < 0 || (unsigned) res >= buflen) | 
|  | 4053 | return -1; | 
|  | 4054 | return res; | 
|  | 4055 | } | 
|  | 4056 |  | 
|  | 4057 |  | 
|  | 4058 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, | 
|  | 4059 | char *cmd) | 
|  | 4060 | { | 
|  | 4061 | long long unsigned val; | 
|  | 4062 | u64 req; | 
|  | 4063 | if (sscanf(cmd, "%llx", &val) != 1) | 
|  | 4064 | return -1; | 
|  | 4065 | req = val; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4066 | return wpas_p2p_sd_cancel_request(wpa_s, req); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4067 | } | 
|  | 4068 |  | 
|  | 4069 |  | 
|  | 4070 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4071 | { | 
|  | 4072 | int freq; | 
|  | 4073 | u8 dst[ETH_ALEN]; | 
|  | 4074 | u8 dialog_token; | 
|  | 4075 | struct wpabuf *resp_tlvs; | 
|  | 4076 | char *pos, *pos2; | 
|  | 4077 | size_t len; | 
|  | 4078 |  | 
|  | 4079 | pos = os_strchr(cmd, ' '); | 
|  | 4080 | if (pos == NULL) | 
|  | 4081 | return -1; | 
|  | 4082 | *pos++ = '\0'; | 
|  | 4083 | freq = atoi(cmd); | 
|  | 4084 | if (freq == 0) | 
|  | 4085 | return -1; | 
|  | 4086 |  | 
|  | 4087 | if (hwaddr_aton(pos, dst)) | 
|  | 4088 | return -1; | 
|  | 4089 | pos += 17; | 
|  | 4090 | if (*pos != ' ') | 
|  | 4091 | return -1; | 
|  | 4092 | pos++; | 
|  | 4093 |  | 
|  | 4094 | pos2 = os_strchr(pos, ' '); | 
|  | 4095 | if (pos2 == NULL) | 
|  | 4096 | return -1; | 
|  | 4097 | *pos2++ = '\0'; | 
|  | 4098 | dialog_token = atoi(pos); | 
|  | 4099 |  | 
|  | 4100 | len = os_strlen(pos2); | 
|  | 4101 | if (len & 1) | 
|  | 4102 | return -1; | 
|  | 4103 | len /= 2; | 
|  | 4104 | resp_tlvs = wpabuf_alloc(len); | 
|  | 4105 | if (resp_tlvs == NULL) | 
|  | 4106 | return -1; | 
|  | 4107 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { | 
|  | 4108 | wpabuf_free(resp_tlvs); | 
|  | 4109 | return -1; | 
|  | 4110 | } | 
|  | 4111 |  | 
|  | 4112 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); | 
|  | 4113 | wpabuf_free(resp_tlvs); | 
|  | 4114 | return 0; | 
|  | 4115 | } | 
|  | 4116 |  | 
|  | 4117 |  | 
|  | 4118 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, | 
|  | 4119 | char *cmd) | 
|  | 4120 | { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4121 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) | 
|  | 4122 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4123 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); | 
|  | 4124 | return 0; | 
|  | 4125 | } | 
|  | 4126 |  | 
|  | 4127 |  | 
|  | 4128 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, | 
|  | 4129 | char *cmd) | 
|  | 4130 | { | 
|  | 4131 | char *pos; | 
|  | 4132 | size_t len; | 
|  | 4133 | struct wpabuf *query, *resp; | 
|  | 4134 |  | 
|  | 4135 | pos = os_strchr(cmd, ' '); | 
|  | 4136 | if (pos == NULL) | 
|  | 4137 | return -1; | 
|  | 4138 | *pos++ = '\0'; | 
|  | 4139 |  | 
|  | 4140 | len = os_strlen(cmd); | 
|  | 4141 | if (len & 1) | 
|  | 4142 | return -1; | 
|  | 4143 | len /= 2; | 
|  | 4144 | query = wpabuf_alloc(len); | 
|  | 4145 | if (query == NULL) | 
|  | 4146 | return -1; | 
|  | 4147 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | 
|  | 4148 | wpabuf_free(query); | 
|  | 4149 | return -1; | 
|  | 4150 | } | 
|  | 4151 |  | 
|  | 4152 | len = os_strlen(pos); | 
|  | 4153 | if (len & 1) { | 
|  | 4154 | wpabuf_free(query); | 
|  | 4155 | return -1; | 
|  | 4156 | } | 
|  | 4157 | len /= 2; | 
|  | 4158 | resp = wpabuf_alloc(len); | 
|  | 4159 | if (resp == NULL) { | 
|  | 4160 | wpabuf_free(query); | 
|  | 4161 | return -1; | 
|  | 4162 | } | 
|  | 4163 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { | 
|  | 4164 | wpabuf_free(query); | 
|  | 4165 | wpabuf_free(resp); | 
|  | 4166 | return -1; | 
|  | 4167 | } | 
|  | 4168 |  | 
|  | 4169 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { | 
|  | 4170 | wpabuf_free(query); | 
|  | 4171 | wpabuf_free(resp); | 
|  | 4172 | return -1; | 
|  | 4173 | } | 
|  | 4174 | return 0; | 
|  | 4175 | } | 
|  | 4176 |  | 
|  | 4177 |  | 
|  | 4178 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4179 | { | 
|  | 4180 | char *pos; | 
|  | 4181 | u8 version; | 
|  | 4182 |  | 
|  | 4183 | pos = os_strchr(cmd, ' '); | 
|  | 4184 | if (pos == NULL) | 
|  | 4185 | return -1; | 
|  | 4186 | *pos++ = '\0'; | 
|  | 4187 |  | 
|  | 4188 | if (hexstr2bin(cmd, &version, 1) < 0) | 
|  | 4189 | return -1; | 
|  | 4190 |  | 
|  | 4191 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); | 
|  | 4192 | } | 
|  | 4193 |  | 
|  | 4194 |  | 
|  | 4195 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4196 | { | 
|  | 4197 | char *pos; | 
|  | 4198 |  | 
|  | 4199 | pos = os_strchr(cmd, ' '); | 
|  | 4200 | if (pos == NULL) | 
|  | 4201 | return -1; | 
|  | 4202 | *pos++ = '\0'; | 
|  | 4203 |  | 
|  | 4204 | if (os_strcmp(cmd, "bonjour") == 0) | 
|  | 4205 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); | 
|  | 4206 | if (os_strcmp(cmd, "upnp") == 0) | 
|  | 4207 | return p2p_ctrl_service_add_upnp(wpa_s, pos); | 
|  | 4208 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | 
|  | 4209 | return -1; | 
|  | 4210 | } | 
|  | 4211 |  | 
|  | 4212 |  | 
|  | 4213 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, | 
|  | 4214 | char *cmd) | 
|  | 4215 | { | 
|  | 4216 | size_t len; | 
|  | 4217 | struct wpabuf *query; | 
|  | 4218 | int ret; | 
|  | 4219 |  | 
|  | 4220 | len = os_strlen(cmd); | 
|  | 4221 | if (len & 1) | 
|  | 4222 | return -1; | 
|  | 4223 | len /= 2; | 
|  | 4224 | query = wpabuf_alloc(len); | 
|  | 4225 | if (query == NULL) | 
|  | 4226 | return -1; | 
|  | 4227 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | 
|  | 4228 | wpabuf_free(query); | 
|  | 4229 | return -1; | 
|  | 4230 | } | 
|  | 4231 |  | 
|  | 4232 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); | 
|  | 4233 | wpabuf_free(query); | 
|  | 4234 | return ret; | 
|  | 4235 | } | 
|  | 4236 |  | 
|  | 4237 |  | 
|  | 4238 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4239 | { | 
|  | 4240 | char *pos; | 
|  | 4241 | u8 version; | 
|  | 4242 |  | 
|  | 4243 | pos = os_strchr(cmd, ' '); | 
|  | 4244 | if (pos == NULL) | 
|  | 4245 | return -1; | 
|  | 4246 | *pos++ = '\0'; | 
|  | 4247 |  | 
|  | 4248 | if (hexstr2bin(cmd, &version, 1) < 0) | 
|  | 4249 | return -1; | 
|  | 4250 |  | 
|  | 4251 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); | 
|  | 4252 | } | 
|  | 4253 |  | 
|  | 4254 |  | 
|  | 4255 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4256 | { | 
|  | 4257 | char *pos; | 
|  | 4258 |  | 
|  | 4259 | pos = os_strchr(cmd, ' '); | 
|  | 4260 | if (pos == NULL) | 
|  | 4261 | return -1; | 
|  | 4262 | *pos++ = '\0'; | 
|  | 4263 |  | 
|  | 4264 | if (os_strcmp(cmd, "bonjour") == 0) | 
|  | 4265 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); | 
|  | 4266 | if (os_strcmp(cmd, "upnp") == 0) | 
|  | 4267 | return p2p_ctrl_service_del_upnp(wpa_s, pos); | 
|  | 4268 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | 
|  | 4269 | return -1; | 
|  | 4270 | } | 
|  | 4271 |  | 
|  | 4272 |  | 
|  | 4273 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4274 | { | 
|  | 4275 | u8 addr[ETH_ALEN]; | 
|  | 4276 |  | 
|  | 4277 | /* <addr> */ | 
|  | 4278 |  | 
|  | 4279 | if (hwaddr_aton(cmd, addr)) | 
|  | 4280 | return -1; | 
|  | 4281 |  | 
|  | 4282 | return wpas_p2p_reject(wpa_s, addr); | 
|  | 4283 | } | 
|  | 4284 |  | 
|  | 4285 |  | 
|  | 4286 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4287 | { | 
|  | 4288 | char *pos; | 
|  | 4289 | int id; | 
|  | 4290 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4291 | u8 *_peer = NULL, peer[ETH_ALEN]; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 4292 | int freq = 0, pref_freq = 0; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4293 | int ht40, vht; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4294 |  | 
|  | 4295 | id = atoi(cmd); | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4296 | pos = os_strstr(cmd, " peer="); | 
|  | 4297 | if (pos) { | 
|  | 4298 | pos += 6; | 
|  | 4299 | if (hwaddr_aton(pos, peer)) | 
|  | 4300 | return -1; | 
|  | 4301 | _peer = peer; | 
|  | 4302 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4303 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 4304 | if (ssid == NULL || ssid->disabled != 2) { | 
|  | 4305 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | 
|  | 4306 | "for persistent P2P group", | 
|  | 4307 | id); | 
|  | 4308 | return -1; | 
|  | 4309 | } | 
|  | 4310 |  | 
| Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 4311 | pos = os_strstr(cmd, " freq="); | 
|  | 4312 | if (pos) { | 
|  | 4313 | pos += 6; | 
|  | 4314 | freq = atoi(pos); | 
|  | 4315 | if (freq <= 0) | 
|  | 4316 | return -1; | 
|  | 4317 | } | 
|  | 4318 |  | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 4319 | pos = os_strstr(cmd, " pref="); | 
|  | 4320 | if (pos) { | 
|  | 4321 | pos += 6; | 
|  | 4322 | pref_freq = atoi(pos); | 
|  | 4323 | if (pref_freq <= 0) | 
|  | 4324 | return -1; | 
|  | 4325 | } | 
|  | 4326 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4327 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; | 
|  | 4328 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | 
|  | 4329 | vht; | 
| Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 4330 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4331 | return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht, | 
|  | 4332 | pref_freq); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4333 | } | 
|  | 4334 |  | 
|  | 4335 |  | 
|  | 4336 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4337 | { | 
|  | 4338 | char *pos; | 
|  | 4339 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; | 
|  | 4340 |  | 
|  | 4341 | pos = os_strstr(cmd, " peer="); | 
|  | 4342 | if (!pos) | 
|  | 4343 | return -1; | 
|  | 4344 |  | 
|  | 4345 | *pos = '\0'; | 
|  | 4346 | pos += 6; | 
|  | 4347 | if (hwaddr_aton(pos, peer)) { | 
|  | 4348 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); | 
|  | 4349 | return -1; | 
|  | 4350 | } | 
|  | 4351 |  | 
|  | 4352 | pos = os_strstr(pos, " go_dev_addr="); | 
|  | 4353 | if (pos) { | 
|  | 4354 | pos += 13; | 
|  | 4355 | if (hwaddr_aton(pos, go_dev_addr)) { | 
|  | 4356 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", | 
|  | 4357 | pos); | 
|  | 4358 | return -1; | 
|  | 4359 | } | 
|  | 4360 | go_dev = go_dev_addr; | 
|  | 4361 | } | 
|  | 4362 |  | 
|  | 4363 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); | 
|  | 4364 | } | 
|  | 4365 |  | 
|  | 4366 |  | 
|  | 4367 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4368 | { | 
|  | 4369 | if (os_strncmp(cmd, "persistent=", 11) == 0) | 
|  | 4370 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); | 
|  | 4371 | if (os_strncmp(cmd, "group=", 6) == 0) | 
|  | 4372 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); | 
|  | 4373 |  | 
|  | 4374 | return -1; | 
|  | 4375 | } | 
|  | 4376 |  | 
|  | 4377 |  | 
|  | 4378 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4379 | char *cmd, int freq, int ht40, | 
|  | 4380 | int vht) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4381 | { | 
|  | 4382 | int id; | 
|  | 4383 | struct wpa_ssid *ssid; | 
|  | 4384 |  | 
|  | 4385 | id = atoi(cmd); | 
|  | 4386 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 4387 | if (ssid == NULL || ssid->disabled != 2) { | 
|  | 4388 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | 
|  | 4389 | "for persistent P2P group", | 
|  | 4390 | id); | 
|  | 4391 | return -1; | 
|  | 4392 | } | 
|  | 4393 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4394 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40, vht, | 
|  | 4395 | NULL, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4396 | } | 
|  | 4397 |  | 
|  | 4398 |  | 
|  | 4399 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4400 | { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4401 | int freq = 0, ht40, vht; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4402 | char *pos; | 
|  | 4403 |  | 
|  | 4404 | pos = os_strstr(cmd, "freq="); | 
|  | 4405 | if (pos) | 
|  | 4406 | freq = atoi(pos + 5); | 
|  | 4407 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4408 | vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht; | 
|  | 4409 | ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | 
|  | 4410 | vht; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4411 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4412 | if (os_strncmp(cmd, "persistent=", 11) == 0) | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4413 | return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4414 | ht40, vht); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4415 | if (os_strcmp(cmd, "persistent") == 0 || | 
|  | 4416 | os_strncmp(cmd, "persistent ", 11) == 0) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4417 | return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4418 | if (os_strncmp(cmd, "freq=", 5) == 0) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4419 | return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4420 | if (ht40) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4421 | return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4422 |  | 
|  | 4423 | wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'", | 
|  | 4424 | cmd); | 
|  | 4425 | return -1; | 
|  | 4426 | } | 
|  | 4427 |  | 
|  | 4428 |  | 
|  | 4429 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 4430 | char *buf, size_t buflen) | 
|  | 4431 | { | 
|  | 4432 | u8 addr[ETH_ALEN], *addr_ptr; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4433 | int next, res; | 
|  | 4434 | const struct p2p_peer_info *info; | 
|  | 4435 | char *pos, *end; | 
|  | 4436 | char devtype[WPS_DEV_TYPE_BUFSIZE]; | 
|  | 4437 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4438 | size_t i; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4439 |  | 
|  | 4440 | if (!wpa_s->global->p2p) | 
|  | 4441 | return -1; | 
|  | 4442 |  | 
|  | 4443 | if (os_strcmp(cmd, "FIRST") == 0) { | 
|  | 4444 | addr_ptr = NULL; | 
|  | 4445 | next = 0; | 
|  | 4446 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | 
|  | 4447 | if (hwaddr_aton(cmd + 5, addr) < 0) | 
|  | 4448 | return -1; | 
|  | 4449 | addr_ptr = addr; | 
|  | 4450 | next = 1; | 
|  | 4451 | } else { | 
|  | 4452 | if (hwaddr_aton(cmd, addr) < 0) | 
|  | 4453 | return -1; | 
|  | 4454 | addr_ptr = addr; | 
|  | 4455 | next = 0; | 
|  | 4456 | } | 
|  | 4457 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4458 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); | 
|  | 4459 | if (info == NULL) | 
|  | 4460 | return -1; | 
|  | 4461 |  | 
|  | 4462 | pos = buf; | 
|  | 4463 | end = buf + buflen; | 
|  | 4464 |  | 
|  | 4465 | res = os_snprintf(pos, end - pos, MACSTR "\n" | 
|  | 4466 | "pri_dev_type=%s\n" | 
|  | 4467 | "device_name=%s\n" | 
|  | 4468 | "manufacturer=%s\n" | 
|  | 4469 | "model_name=%s\n" | 
|  | 4470 | "model_number=%s\n" | 
|  | 4471 | "serial_number=%s\n" | 
|  | 4472 | "config_methods=0x%x\n" | 
|  | 4473 | "dev_capab=0x%x\n" | 
|  | 4474 | "group_capab=0x%x\n" | 
|  | 4475 | "level=%d\n", | 
|  | 4476 | MAC2STR(info->p2p_device_addr), | 
|  | 4477 | wps_dev_type_bin2str(info->pri_dev_type, | 
|  | 4478 | devtype, sizeof(devtype)), | 
|  | 4479 | info->device_name, | 
|  | 4480 | info->manufacturer, | 
|  | 4481 | info->model_name, | 
|  | 4482 | info->model_number, | 
|  | 4483 | info->serial_number, | 
|  | 4484 | info->config_methods, | 
|  | 4485 | info->dev_capab, | 
|  | 4486 | info->group_capab, | 
|  | 4487 | info->level); | 
|  | 4488 | if (res < 0 || res >= end - pos) | 
|  | 4489 | return pos - buf; | 
|  | 4490 | pos += res; | 
|  | 4491 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4492 | for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++) | 
|  | 4493 | { | 
|  | 4494 | const u8 *t; | 
|  | 4495 | t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN]; | 
|  | 4496 | res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n", | 
|  | 4497 | wps_dev_type_bin2str(t, devtype, | 
|  | 4498 | sizeof(devtype))); | 
|  | 4499 | if (res < 0 || res >= end - pos) | 
|  | 4500 | return pos - buf; | 
|  | 4501 | pos += res; | 
|  | 4502 | } | 
|  | 4503 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4504 | ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4505 | if (ssid) { | 
|  | 4506 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); | 
|  | 4507 | if (res < 0 || res >= end - pos) | 
|  | 4508 | return pos - buf; | 
|  | 4509 | pos += res; | 
|  | 4510 | } | 
|  | 4511 |  | 
|  | 4512 | res = p2p_get_peer_info_txt(info, pos, end - pos); | 
|  | 4513 | if (res < 0) | 
|  | 4514 | return pos - buf; | 
|  | 4515 | pos += res; | 
|  | 4516 |  | 
|  | 4517 | return pos - buf; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4518 | } | 
|  | 4519 |  | 
|  | 4520 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4521 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, | 
|  | 4522 | const char *param) | 
|  | 4523 | { | 
| Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 4524 | unsigned int i; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4525 |  | 
|  | 4526 | if (wpa_s->global->p2p == NULL) | 
|  | 4527 | return -1; | 
|  | 4528 |  | 
| Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 4529 | if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0) | 
|  | 4530 | return -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4531 |  | 
| Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 4532 | for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) { | 
|  | 4533 | struct wpa_freq_range *freq; | 
|  | 4534 | freq = &wpa_s->global->p2p_disallow_freq.range[i]; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4535 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", | 
| Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 4536 | freq->min, freq->max); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4537 | } | 
|  | 4538 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4539 | wpas_p2p_update_channel_list(wpa_s); | 
|  | 4540 | return 0; | 
|  | 4541 | } | 
|  | 4542 |  | 
|  | 4543 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4544 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4545 | { | 
|  | 4546 | char *param; | 
|  | 4547 |  | 
|  | 4548 | if (wpa_s->global->p2p == NULL) | 
|  | 4549 | return -1; | 
|  | 4550 |  | 
|  | 4551 | param = os_strchr(cmd, ' '); | 
|  | 4552 | if (param == NULL) | 
|  | 4553 | return -1; | 
|  | 4554 | *param++ = '\0'; | 
|  | 4555 |  | 
|  | 4556 | if (os_strcmp(cmd, "discoverability") == 0) { | 
|  | 4557 | p2p_set_client_discoverability(wpa_s->global->p2p, | 
|  | 4558 | atoi(param)); | 
|  | 4559 | return 0; | 
|  | 4560 | } | 
|  | 4561 |  | 
|  | 4562 | if (os_strcmp(cmd, "managed") == 0) { | 
|  | 4563 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); | 
|  | 4564 | return 0; | 
|  | 4565 | } | 
|  | 4566 |  | 
|  | 4567 | if (os_strcmp(cmd, "listen_channel") == 0) { | 
|  | 4568 | return p2p_set_listen_channel(wpa_s->global->p2p, 81, | 
|  | 4569 | atoi(param)); | 
|  | 4570 | } | 
|  | 4571 |  | 
|  | 4572 | if (os_strcmp(cmd, "ssid_postfix") == 0) { | 
|  | 4573 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, | 
|  | 4574 | os_strlen(param)); | 
|  | 4575 | } | 
|  | 4576 |  | 
|  | 4577 | if (os_strcmp(cmd, "noa") == 0) { | 
|  | 4578 | char *pos; | 
|  | 4579 | int count, start, duration; | 
|  | 4580 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ | 
|  | 4581 | count = atoi(param); | 
|  | 4582 | pos = os_strchr(param, ','); | 
|  | 4583 | if (pos == NULL) | 
|  | 4584 | return -1; | 
|  | 4585 | pos++; | 
|  | 4586 | start = atoi(pos); | 
|  | 4587 | pos = os_strchr(pos, ','); | 
|  | 4588 | if (pos == NULL) | 
|  | 4589 | return -1; | 
|  | 4590 | pos++; | 
|  | 4591 | duration = atoi(pos); | 
|  | 4592 | if (count < 0 || count > 255 || start < 0 || duration < 0) | 
|  | 4593 | return -1; | 
|  | 4594 | if (count == 0 && duration > 0) | 
|  | 4595 | return -1; | 
|  | 4596 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " | 
|  | 4597 | "start=%d duration=%d", count, start, duration); | 
|  | 4598 | return wpas_p2p_set_noa(wpa_s, count, start, duration); | 
|  | 4599 | } | 
|  | 4600 |  | 
|  | 4601 | if (os_strcmp(cmd, "ps") == 0) | 
|  | 4602 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); | 
|  | 4603 |  | 
|  | 4604 | if (os_strcmp(cmd, "oppps") == 0) | 
|  | 4605 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); | 
|  | 4606 |  | 
|  | 4607 | if (os_strcmp(cmd, "ctwindow") == 0) | 
|  | 4608 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); | 
|  | 4609 |  | 
|  | 4610 | if (os_strcmp(cmd, "disabled") == 0) { | 
|  | 4611 | wpa_s->global->p2p_disabled = atoi(param); | 
|  | 4612 | wpa_printf(MSG_DEBUG, "P2P functionality %s", | 
|  | 4613 | wpa_s->global->p2p_disabled ? | 
|  | 4614 | "disabled" : "enabled"); | 
|  | 4615 | if (wpa_s->global->p2p_disabled) { | 
|  | 4616 | wpas_p2p_stop_find(wpa_s); | 
|  | 4617 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | 
|  | 4618 | p2p_flush(wpa_s->global->p2p); | 
|  | 4619 | } | 
|  | 4620 | return 0; | 
|  | 4621 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4622 |  | 
| Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 4623 | if (os_strcmp(cmd, "conc_pref") == 0) { | 
|  | 4624 | if (os_strcmp(param, "sta") == 0) | 
|  | 4625 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; | 
|  | 4626 | else if (os_strcmp(param, "p2p") == 0) | 
|  | 4627 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; | 
| Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 4628 | else { | 
| Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 4629 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); | 
| Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 4630 | return -1; | 
|  | 4631 | } | 
| Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 4632 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4633 | "%s", param); | 
| Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 4634 | return 0; | 
|  | 4635 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4636 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4637 | if (os_strcmp(cmd, "force_long_sd") == 0) { | 
|  | 4638 | wpa_s->force_long_sd = atoi(param); | 
|  | 4639 | return 0; | 
|  | 4640 | } | 
|  | 4641 |  | 
|  | 4642 | if (os_strcmp(cmd, "peer_filter") == 0) { | 
|  | 4643 | u8 addr[ETH_ALEN]; | 
|  | 4644 | if (hwaddr_aton(param, addr)) | 
|  | 4645 | return -1; | 
|  | 4646 | p2p_set_peer_filter(wpa_s->global->p2p, addr); | 
|  | 4647 | return 0; | 
|  | 4648 | } | 
|  | 4649 |  | 
|  | 4650 | if (os_strcmp(cmd, "cross_connect") == 0) | 
|  | 4651 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); | 
|  | 4652 |  | 
|  | 4653 | if (os_strcmp(cmd, "go_apsd") == 0) { | 
|  | 4654 | if (os_strcmp(param, "disable") == 0) | 
|  | 4655 | wpa_s->set_ap_uapsd = 0; | 
|  | 4656 | else { | 
|  | 4657 | wpa_s->set_ap_uapsd = 1; | 
|  | 4658 | wpa_s->ap_uapsd = atoi(param); | 
|  | 4659 | } | 
|  | 4660 | return 0; | 
|  | 4661 | } | 
|  | 4662 |  | 
|  | 4663 | if (os_strcmp(cmd, "client_apsd") == 0) { | 
|  | 4664 | if (os_strcmp(param, "disable") == 0) | 
|  | 4665 | wpa_s->set_sta_uapsd = 0; | 
|  | 4666 | else { | 
|  | 4667 | int be, bk, vi, vo; | 
|  | 4668 | char *pos; | 
|  | 4669 | /* format: BE,BK,VI,VO;max SP Length */ | 
|  | 4670 | be = atoi(param); | 
|  | 4671 | pos = os_strchr(param, ','); | 
|  | 4672 | if (pos == NULL) | 
|  | 4673 | return -1; | 
|  | 4674 | pos++; | 
|  | 4675 | bk = atoi(pos); | 
|  | 4676 | pos = os_strchr(pos, ','); | 
|  | 4677 | if (pos == NULL) | 
|  | 4678 | return -1; | 
|  | 4679 | pos++; | 
|  | 4680 | vi = atoi(pos); | 
|  | 4681 | pos = os_strchr(pos, ','); | 
|  | 4682 | if (pos == NULL) | 
|  | 4683 | return -1; | 
|  | 4684 | pos++; | 
|  | 4685 | vo = atoi(pos); | 
|  | 4686 | /* ignore max SP Length for now */ | 
|  | 4687 |  | 
|  | 4688 | wpa_s->set_sta_uapsd = 1; | 
|  | 4689 | wpa_s->sta_uapsd = 0; | 
|  | 4690 | if (be) | 
|  | 4691 | wpa_s->sta_uapsd |= BIT(0); | 
|  | 4692 | if (bk) | 
|  | 4693 | wpa_s->sta_uapsd |= BIT(1); | 
|  | 4694 | if (vi) | 
|  | 4695 | wpa_s->sta_uapsd |= BIT(2); | 
|  | 4696 | if (vo) | 
|  | 4697 | wpa_s->sta_uapsd |= BIT(3); | 
|  | 4698 | } | 
|  | 4699 | return 0; | 
|  | 4700 | } | 
|  | 4701 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4702 | if (os_strcmp(cmd, "disallow_freq") == 0) | 
|  | 4703 | return p2p_ctrl_disallow_freq(wpa_s, param); | 
|  | 4704 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4705 | if (os_strcmp(cmd, "disc_int") == 0) { | 
|  | 4706 | int min_disc_int, max_disc_int, max_disc_tu; | 
|  | 4707 | char *pos; | 
|  | 4708 |  | 
|  | 4709 | pos = param; | 
|  | 4710 |  | 
|  | 4711 | min_disc_int = atoi(pos); | 
|  | 4712 | pos = os_strchr(pos, ' '); | 
|  | 4713 | if (pos == NULL) | 
|  | 4714 | return -1; | 
|  | 4715 | *pos++ = '\0'; | 
|  | 4716 |  | 
|  | 4717 | max_disc_int = atoi(pos); | 
|  | 4718 | pos = os_strchr(pos, ' '); | 
|  | 4719 | if (pos == NULL) | 
|  | 4720 | return -1; | 
|  | 4721 | *pos++ = '\0'; | 
|  | 4722 |  | 
|  | 4723 | max_disc_tu = atoi(pos); | 
|  | 4724 |  | 
|  | 4725 | return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int, | 
|  | 4726 | max_disc_int, max_disc_tu); | 
|  | 4727 | } | 
|  | 4728 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4729 | if (os_strcmp(cmd, "per_sta_psk") == 0) { | 
|  | 4730 | wpa_s->global->p2p_per_sta_psk = !!atoi(param); | 
|  | 4731 | return 0; | 
|  | 4732 | } | 
|  | 4733 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 4734 | #ifdef CONFIG_WPS_NFC | 
|  | 4735 | if (os_strcmp(cmd, "nfc_tag") == 0) | 
|  | 4736 | return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param)); | 
|  | 4737 | #endif /* CONFIG_WPS_NFC */ | 
|  | 4738 |  | 
|  | 4739 | if (os_strcmp(cmd, "disable_ip_addr_req") == 0) { | 
|  | 4740 | wpa_s->p2p_disable_ip_addr_req = !!atoi(param); | 
|  | 4741 | return 0; | 
|  | 4742 | } | 
|  | 4743 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4744 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", | 
|  | 4745 | cmd); | 
|  | 4746 |  | 
|  | 4747 | return -1; | 
|  | 4748 | } | 
|  | 4749 |  | 
|  | 4750 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 4751 | static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s) | 
|  | 4752 | { | 
|  | 4753 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | 
|  | 4754 | wpa_s->force_long_sd = 0; | 
|  | 4755 | if (wpa_s->global->p2p) | 
|  | 4756 | p2p_flush(wpa_s->global->p2p); | 
|  | 4757 | } | 
|  | 4758 |  | 
|  | 4759 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4760 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4761 | { | 
|  | 4762 | char *pos, *pos2; | 
|  | 4763 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; | 
|  | 4764 |  | 
|  | 4765 | if (cmd[0]) { | 
|  | 4766 | pos = os_strchr(cmd, ' '); | 
|  | 4767 | if (pos == NULL) | 
|  | 4768 | return -1; | 
|  | 4769 | *pos++ = '\0'; | 
|  | 4770 | dur1 = atoi(cmd); | 
|  | 4771 |  | 
|  | 4772 | pos2 = os_strchr(pos, ' '); | 
|  | 4773 | if (pos2) | 
|  | 4774 | *pos2++ = '\0'; | 
|  | 4775 | int1 = atoi(pos); | 
|  | 4776 | } else | 
|  | 4777 | pos2 = NULL; | 
|  | 4778 |  | 
|  | 4779 | if (pos2) { | 
|  | 4780 | pos = os_strchr(pos2, ' '); | 
|  | 4781 | if (pos == NULL) | 
|  | 4782 | return -1; | 
|  | 4783 | *pos++ = '\0'; | 
|  | 4784 | dur2 = atoi(pos2); | 
|  | 4785 | int2 = atoi(pos); | 
|  | 4786 | } | 
|  | 4787 |  | 
|  | 4788 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); | 
|  | 4789 | } | 
|  | 4790 |  | 
|  | 4791 |  | 
|  | 4792 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4793 | { | 
|  | 4794 | char *pos; | 
|  | 4795 | unsigned int period = 0, interval = 0; | 
|  | 4796 |  | 
|  | 4797 | if (cmd[0]) { | 
|  | 4798 | pos = os_strchr(cmd, ' '); | 
|  | 4799 | if (pos == NULL) | 
|  | 4800 | return -1; | 
|  | 4801 | *pos++ = '\0'; | 
|  | 4802 | period = atoi(cmd); | 
|  | 4803 | interval = atoi(pos); | 
|  | 4804 | } | 
|  | 4805 |  | 
|  | 4806 | return wpas_p2p_ext_listen(wpa_s, period, interval); | 
|  | 4807 | } | 
|  | 4808 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4809 |  | 
|  | 4810 | static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd) | 
|  | 4811 | { | 
|  | 4812 | const char *pos; | 
|  | 4813 | u8 peer[ETH_ALEN]; | 
|  | 4814 | int iface_addr = 0; | 
|  | 4815 |  | 
|  | 4816 | pos = cmd; | 
|  | 4817 | if (os_strncmp(pos, "iface=", 6) == 0) { | 
|  | 4818 | iface_addr = 1; | 
|  | 4819 | pos += 6; | 
|  | 4820 | } | 
|  | 4821 | if (hwaddr_aton(pos, peer)) | 
|  | 4822 | return -1; | 
|  | 4823 |  | 
|  | 4824 | wpas_p2p_remove_client(wpa_s, peer, iface_addr); | 
|  | 4825 | return 0; | 
|  | 4826 | } | 
|  | 4827 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4828 | #endif /* CONFIG_P2P */ | 
|  | 4829 |  | 
|  | 4830 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4831 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val) | 
|  | 4832 | { | 
|  | 4833 | struct wpa_freq_range_list ranges; | 
|  | 4834 | int *freqs = NULL; | 
|  | 4835 | struct hostapd_hw_modes *mode; | 
|  | 4836 | u16 i; | 
|  | 4837 |  | 
|  | 4838 | if (wpa_s->hw.modes == NULL) | 
|  | 4839 | return NULL; | 
|  | 4840 |  | 
|  | 4841 | os_memset(&ranges, 0, sizeof(ranges)); | 
|  | 4842 | if (freq_range_list_parse(&ranges, val) < 0) | 
|  | 4843 | return NULL; | 
|  | 4844 |  | 
|  | 4845 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | 
|  | 4846 | int j; | 
|  | 4847 |  | 
|  | 4848 | mode = &wpa_s->hw.modes[i]; | 
|  | 4849 | for (j = 0; j < mode->num_channels; j++) { | 
|  | 4850 | unsigned int freq; | 
|  | 4851 |  | 
|  | 4852 | if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED) | 
|  | 4853 | continue; | 
|  | 4854 |  | 
|  | 4855 | freq = mode->channels[j].freq; | 
|  | 4856 | if (!freq_range_list_includes(&ranges, freq)) | 
|  | 4857 | continue; | 
|  | 4858 |  | 
|  | 4859 | int_array_add_unique(&freqs, freq); | 
|  | 4860 | } | 
|  | 4861 | } | 
|  | 4862 |  | 
|  | 4863 | os_free(ranges.range); | 
|  | 4864 | return freqs; | 
|  | 4865 | } | 
|  | 4866 |  | 
|  | 4867 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4868 | #ifdef CONFIG_INTERWORKING | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4869 |  | 
|  | 4870 | static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param) | 
|  | 4871 | { | 
|  | 4872 | int auto_sel = 0; | 
|  | 4873 | int *freqs = NULL; | 
|  | 4874 |  | 
|  | 4875 | if (param) { | 
|  | 4876 | char *pos; | 
|  | 4877 |  | 
|  | 4878 | auto_sel = os_strstr(param, "auto") != NULL; | 
|  | 4879 |  | 
|  | 4880 | pos = os_strstr(param, "freq="); | 
|  | 4881 | if (pos) { | 
|  | 4882 | freqs = freq_range_to_channel_list(wpa_s, pos + 5); | 
|  | 4883 | if (freqs == NULL) | 
|  | 4884 | return -1; | 
|  | 4885 | } | 
|  | 4886 |  | 
|  | 4887 | } | 
|  | 4888 |  | 
|  | 4889 | return interworking_select(wpa_s, auto_sel, freqs); | 
|  | 4890 | } | 
|  | 4891 |  | 
|  | 4892 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4893 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst) | 
|  | 4894 | { | 
|  | 4895 | u8 bssid[ETH_ALEN]; | 
|  | 4896 | struct wpa_bss *bss; | 
|  | 4897 |  | 
|  | 4898 | if (hwaddr_aton(dst, bssid)) { | 
|  | 4899 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); | 
|  | 4900 | return -1; | 
|  | 4901 | } | 
|  | 4902 |  | 
|  | 4903 | bss = wpa_bss_get_bssid(wpa_s, bssid); | 
|  | 4904 | if (bss == NULL) { | 
|  | 4905 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, | 
|  | 4906 | MAC2STR(bssid)); | 
|  | 4907 | return -1; | 
|  | 4908 | } | 
|  | 4909 |  | 
|  | 4910 | return interworking_connect(wpa_s, bss); | 
|  | 4911 | } | 
|  | 4912 |  | 
|  | 4913 |  | 
|  | 4914 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) | 
|  | 4915 | { | 
|  | 4916 | u8 dst_addr[ETH_ALEN]; | 
|  | 4917 | int used; | 
|  | 4918 | char *pos; | 
|  | 4919 | #define MAX_ANQP_INFO_ID 100 | 
|  | 4920 | u16 id[MAX_ANQP_INFO_ID]; | 
|  | 4921 | size_t num_id = 0; | 
|  | 4922 |  | 
|  | 4923 | used = hwaddr_aton2(dst, dst_addr); | 
|  | 4924 | if (used < 0) | 
|  | 4925 | return -1; | 
|  | 4926 | pos = dst + used; | 
|  | 4927 | while (num_id < MAX_ANQP_INFO_ID) { | 
|  | 4928 | id[num_id] = atoi(pos); | 
|  | 4929 | if (id[num_id]) | 
|  | 4930 | num_id++; | 
|  | 4931 | pos = os_strchr(pos + 1, ','); | 
|  | 4932 | if (pos == NULL) | 
|  | 4933 | break; | 
|  | 4934 | pos++; | 
|  | 4935 | } | 
|  | 4936 |  | 
|  | 4937 | if (num_id == 0) | 
|  | 4938 | return -1; | 
|  | 4939 |  | 
|  | 4940 | return anqp_send_req(wpa_s, dst_addr, id, num_id); | 
|  | 4941 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4942 |  | 
|  | 4943 |  | 
|  | 4944 | static int gas_request(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 4945 | { | 
|  | 4946 | u8 dst_addr[ETH_ALEN]; | 
|  | 4947 | struct wpabuf *advproto, *query = NULL; | 
|  | 4948 | int used, ret = -1; | 
|  | 4949 | char *pos, *end; | 
|  | 4950 | size_t len; | 
|  | 4951 |  | 
|  | 4952 | used = hwaddr_aton2(cmd, dst_addr); | 
|  | 4953 | if (used < 0) | 
|  | 4954 | return -1; | 
|  | 4955 |  | 
|  | 4956 | pos = cmd + used; | 
|  | 4957 | while (*pos == ' ') | 
|  | 4958 | pos++; | 
|  | 4959 |  | 
|  | 4960 | /* Advertisement Protocol ID */ | 
|  | 4961 | end = os_strchr(pos, ' '); | 
|  | 4962 | if (end) | 
|  | 4963 | len = end - pos; | 
|  | 4964 | else | 
|  | 4965 | len = os_strlen(pos); | 
|  | 4966 | if (len & 0x01) | 
|  | 4967 | return -1; | 
|  | 4968 | len /= 2; | 
|  | 4969 | if (len == 0) | 
|  | 4970 | return -1; | 
|  | 4971 | advproto = wpabuf_alloc(len); | 
|  | 4972 | if (advproto == NULL) | 
|  | 4973 | return -1; | 
|  | 4974 | if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0) | 
|  | 4975 | goto fail; | 
|  | 4976 |  | 
|  | 4977 | if (end) { | 
|  | 4978 | /* Optional Query Request */ | 
|  | 4979 | pos = end + 1; | 
|  | 4980 | while (*pos == ' ') | 
|  | 4981 | pos++; | 
|  | 4982 |  | 
|  | 4983 | len = os_strlen(pos); | 
|  | 4984 | if (len) { | 
|  | 4985 | if (len & 0x01) | 
|  | 4986 | goto fail; | 
|  | 4987 | len /= 2; | 
|  | 4988 | if (len == 0) | 
|  | 4989 | goto fail; | 
|  | 4990 | query = wpabuf_alloc(len); | 
|  | 4991 | if (query == NULL) | 
|  | 4992 | goto fail; | 
|  | 4993 | if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0) | 
|  | 4994 | goto fail; | 
|  | 4995 | } | 
|  | 4996 | } | 
|  | 4997 |  | 
|  | 4998 | ret = gas_send_request(wpa_s, dst_addr, advproto, query); | 
|  | 4999 |  | 
|  | 5000 | fail: | 
|  | 5001 | wpabuf_free(advproto); | 
|  | 5002 | wpabuf_free(query); | 
|  | 5003 |  | 
|  | 5004 | return ret; | 
|  | 5005 | } | 
|  | 5006 |  | 
|  | 5007 |  | 
|  | 5008 | static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf, | 
|  | 5009 | size_t buflen) | 
|  | 5010 | { | 
|  | 5011 | u8 addr[ETH_ALEN]; | 
|  | 5012 | int dialog_token; | 
|  | 5013 | int used; | 
|  | 5014 | char *pos; | 
|  | 5015 | size_t resp_len, start, requested_len; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5016 | struct wpabuf *resp; | 
|  | 5017 | int ret; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5018 |  | 
|  | 5019 | used = hwaddr_aton2(cmd, addr); | 
|  | 5020 | if (used < 0) | 
|  | 5021 | return -1; | 
|  | 5022 |  | 
|  | 5023 | pos = cmd + used; | 
|  | 5024 | while (*pos == ' ') | 
|  | 5025 | pos++; | 
|  | 5026 | dialog_token = atoi(pos); | 
|  | 5027 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5028 | if (wpa_s->last_gas_resp && | 
|  | 5029 | os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 && | 
|  | 5030 | dialog_token == wpa_s->last_gas_dialog_token) | 
|  | 5031 | resp = wpa_s->last_gas_resp; | 
|  | 5032 | else if (wpa_s->prev_gas_resp && | 
|  | 5033 | os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 && | 
|  | 5034 | dialog_token == wpa_s->prev_gas_dialog_token) | 
|  | 5035 | resp = wpa_s->prev_gas_resp; | 
|  | 5036 | else | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5037 | return -1; | 
|  | 5038 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5039 | resp_len = wpabuf_len(resp); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5040 | start = 0; | 
|  | 5041 | requested_len = resp_len; | 
|  | 5042 |  | 
|  | 5043 | pos = os_strchr(pos, ' '); | 
|  | 5044 | if (pos) { | 
|  | 5045 | start = atoi(pos); | 
|  | 5046 | if (start > resp_len) | 
|  | 5047 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | 
|  | 5048 | pos = os_strchr(pos, ','); | 
|  | 5049 | if (pos == NULL) | 
|  | 5050 | return -1; | 
|  | 5051 | pos++; | 
|  | 5052 | requested_len = atoi(pos); | 
|  | 5053 | if (start + requested_len > resp_len) | 
|  | 5054 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | 
|  | 5055 | } | 
|  | 5056 |  | 
|  | 5057 | if (requested_len * 2 + 1 > buflen) | 
|  | 5058 | return os_snprintf(buf, buflen, "FAIL-Too long response"); | 
|  | 5059 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5060 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start, | 
|  | 5061 | requested_len); | 
|  | 5062 |  | 
|  | 5063 | if (start + requested_len == resp_len) { | 
|  | 5064 | /* | 
|  | 5065 | * Free memory by dropping the response after it has been | 
|  | 5066 | * fetched. | 
|  | 5067 | */ | 
|  | 5068 | if (resp == wpa_s->prev_gas_resp) { | 
|  | 5069 | wpabuf_free(wpa_s->prev_gas_resp); | 
|  | 5070 | wpa_s->prev_gas_resp = NULL; | 
|  | 5071 | } else { | 
|  | 5072 | wpabuf_free(wpa_s->last_gas_resp); | 
|  | 5073 | wpa_s->last_gas_resp = NULL; | 
|  | 5074 | } | 
|  | 5075 | } | 
|  | 5076 |  | 
|  | 5077 | return ret; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5078 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5079 | #endif /* CONFIG_INTERWORKING */ | 
|  | 5080 |  | 
|  | 5081 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5082 | #ifdef CONFIG_HS20 | 
|  | 5083 |  | 
|  | 5084 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) | 
|  | 5085 | { | 
|  | 5086 | u8 dst_addr[ETH_ALEN]; | 
|  | 5087 | int used; | 
|  | 5088 | char *pos; | 
|  | 5089 | u32 subtypes = 0; | 
|  | 5090 |  | 
|  | 5091 | used = hwaddr_aton2(dst, dst_addr); | 
|  | 5092 | if (used < 0) | 
|  | 5093 | return -1; | 
|  | 5094 | pos = dst + used; | 
|  | 5095 | for (;;) { | 
|  | 5096 | int num = atoi(pos); | 
|  | 5097 | if (num <= 0 || num > 31) | 
|  | 5098 | return -1; | 
|  | 5099 | subtypes |= BIT(num); | 
|  | 5100 | pos = os_strchr(pos + 1, ','); | 
|  | 5101 | if (pos == NULL) | 
|  | 5102 | break; | 
|  | 5103 | pos++; | 
|  | 5104 | } | 
|  | 5105 |  | 
|  | 5106 | if (subtypes == 0) | 
|  | 5107 | return -1; | 
|  | 5108 |  | 
|  | 5109 | return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0); | 
|  | 5110 | } | 
|  | 5111 |  | 
|  | 5112 |  | 
|  | 5113 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, | 
|  | 5114 | const u8 *addr, const char *realm) | 
|  | 5115 | { | 
|  | 5116 | u8 *buf; | 
|  | 5117 | size_t rlen, len; | 
|  | 5118 | int ret; | 
|  | 5119 |  | 
|  | 5120 | rlen = os_strlen(realm); | 
|  | 5121 | len = 3 + rlen; | 
|  | 5122 | buf = os_malloc(len); | 
|  | 5123 | if (buf == NULL) | 
|  | 5124 | return -1; | 
|  | 5125 | buf[0] = 1; /* NAI Home Realm Count */ | 
|  | 5126 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ | 
|  | 5127 | buf[2] = rlen; | 
|  | 5128 | os_memcpy(buf + 3, realm, rlen); | 
|  | 5129 |  | 
|  | 5130 | ret = hs20_anqp_send_req(wpa_s, addr, | 
|  | 5131 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | 
|  | 5132 | buf, len); | 
|  | 5133 |  | 
|  | 5134 | os_free(buf); | 
|  | 5135 |  | 
|  | 5136 | return ret; | 
|  | 5137 | } | 
|  | 5138 |  | 
|  | 5139 |  | 
|  | 5140 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, | 
|  | 5141 | char *dst) | 
|  | 5142 | { | 
|  | 5143 | struct wpa_cred *cred = wpa_s->conf->cred; | 
|  | 5144 | u8 dst_addr[ETH_ALEN]; | 
|  | 5145 | int used; | 
|  | 5146 | u8 *buf; | 
|  | 5147 | size_t len; | 
|  | 5148 | int ret; | 
|  | 5149 |  | 
|  | 5150 | used = hwaddr_aton2(dst, dst_addr); | 
|  | 5151 | if (used < 0) | 
|  | 5152 | return -1; | 
|  | 5153 |  | 
|  | 5154 | while (dst[used] == ' ') | 
|  | 5155 | used++; | 
|  | 5156 | if (os_strncmp(dst + used, "realm=", 6) == 0) | 
|  | 5157 | return hs20_nai_home_realm_list(wpa_s, dst_addr, | 
|  | 5158 | dst + used + 6); | 
|  | 5159 |  | 
|  | 5160 | len = os_strlen(dst + used); | 
|  | 5161 |  | 
|  | 5162 | if (len == 0 && cred && cred->realm) | 
|  | 5163 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); | 
|  | 5164 |  | 
|  | 5165 | if (len % 1) | 
|  | 5166 | return -1; | 
|  | 5167 | len /= 2; | 
|  | 5168 | buf = os_malloc(len); | 
|  | 5169 | if (buf == NULL) | 
|  | 5170 | return -1; | 
|  | 5171 | if (hexstr2bin(dst + used, buf, len) < 0) { | 
|  | 5172 | os_free(buf); | 
|  | 5173 | return -1; | 
|  | 5174 | } | 
|  | 5175 |  | 
|  | 5176 | ret = hs20_anqp_send_req(wpa_s, dst_addr, | 
|  | 5177 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | 
|  | 5178 | buf, len); | 
|  | 5179 | os_free(buf); | 
|  | 5180 |  | 
|  | 5181 | return ret; | 
|  | 5182 | } | 
|  | 5183 |  | 
|  | 5184 | #endif /* CONFIG_HS20 */ | 
|  | 5185 |  | 
|  | 5186 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5187 | static int wpa_supplicant_ctrl_iface_sta_autoconnect( | 
|  | 5188 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5189 | { | 
|  | 5190 | wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0; | 
|  | 5191 | return 0; | 
|  | 5192 | } | 
|  | 5193 |  | 
|  | 5194 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5195 | #ifdef CONFIG_AUTOSCAN | 
|  | 5196 |  | 
|  | 5197 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, | 
|  | 5198 | char *cmd) | 
|  | 5199 | { | 
|  | 5200 | enum wpa_states state = wpa_s->wpa_state; | 
|  | 5201 | char *new_params = NULL; | 
|  | 5202 |  | 
|  | 5203 | if (os_strlen(cmd) > 0) { | 
|  | 5204 | new_params = os_strdup(cmd); | 
|  | 5205 | if (new_params == NULL) | 
|  | 5206 | return -1; | 
|  | 5207 | } | 
|  | 5208 |  | 
|  | 5209 | os_free(wpa_s->conf->autoscan); | 
|  | 5210 | wpa_s->conf->autoscan = new_params; | 
|  | 5211 |  | 
|  | 5212 | if (wpa_s->conf->autoscan == NULL) | 
|  | 5213 | autoscan_deinit(wpa_s); | 
|  | 5214 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) | 
|  | 5215 | autoscan_init(wpa_s, 1); | 
|  | 5216 | else if (state == WPA_SCANNING) | 
|  | 5217 | wpa_supplicant_reinit_autoscan(wpa_s); | 
|  | 5218 |  | 
|  | 5219 | return 0; | 
|  | 5220 | } | 
|  | 5221 |  | 
|  | 5222 | #endif /* CONFIG_AUTOSCAN */ | 
|  | 5223 |  | 
|  | 5224 |  | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5225 | #ifdef CONFIG_WNM | 
|  | 5226 |  | 
|  | 5227 | static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5228 | { | 
|  | 5229 | int enter; | 
|  | 5230 | int intval = 0; | 
|  | 5231 | char *pos; | 
|  | 5232 | int ret; | 
|  | 5233 | struct wpabuf *tfs_req = NULL; | 
|  | 5234 |  | 
|  | 5235 | if (os_strncmp(cmd, "enter", 5) == 0) | 
|  | 5236 | enter = 1; | 
|  | 5237 | else if (os_strncmp(cmd, "exit", 4) == 0) | 
|  | 5238 | enter = 0; | 
|  | 5239 | else | 
|  | 5240 | return -1; | 
|  | 5241 |  | 
|  | 5242 | pos = os_strstr(cmd, " interval="); | 
|  | 5243 | if (pos) | 
|  | 5244 | intval = atoi(pos + 10); | 
|  | 5245 |  | 
|  | 5246 | pos = os_strstr(cmd, " tfs_req="); | 
|  | 5247 | if (pos) { | 
|  | 5248 | char *end; | 
|  | 5249 | size_t len; | 
|  | 5250 | pos += 9; | 
|  | 5251 | end = os_strchr(pos, ' '); | 
|  | 5252 | if (end) | 
|  | 5253 | len = end - pos; | 
|  | 5254 | else | 
|  | 5255 | len = os_strlen(pos); | 
|  | 5256 | if (len & 1) | 
|  | 5257 | return -1; | 
|  | 5258 | len /= 2; | 
|  | 5259 | tfs_req = wpabuf_alloc(len); | 
|  | 5260 | if (tfs_req == NULL) | 
|  | 5261 | return -1; | 
|  | 5262 | if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) { | 
|  | 5263 | wpabuf_free(tfs_req); | 
|  | 5264 | return -1; | 
|  | 5265 | } | 
|  | 5266 | } | 
|  | 5267 |  | 
|  | 5268 | ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER : | 
|  | 5269 | WNM_SLEEP_MODE_EXIT, intval, | 
|  | 5270 | tfs_req); | 
|  | 5271 | wpabuf_free(tfs_req); | 
|  | 5272 |  | 
|  | 5273 | return ret; | 
|  | 5274 | } | 
|  | 5275 |  | 
| Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 5276 |  | 
|  | 5277 | static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5278 | { | 
|  | 5279 | int query_reason; | 
|  | 5280 |  | 
|  | 5281 | query_reason = atoi(cmd); | 
|  | 5282 |  | 
|  | 5283 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d", | 
|  | 5284 | query_reason); | 
|  | 5285 |  | 
|  | 5286 | return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason); | 
|  | 5287 | } | 
|  | 5288 |  | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5289 | #endif /* CONFIG_WNM */ | 
|  | 5290 |  | 
|  | 5291 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5292 | /* Get string representation of channel width */ | 
|  | 5293 | static const char * channel_width_name(enum chan_width width) | 
|  | 5294 | { | 
|  | 5295 | switch (width) { | 
|  | 5296 | case CHAN_WIDTH_20_NOHT: | 
|  | 5297 | return "20 MHz (no HT)"; | 
|  | 5298 | case CHAN_WIDTH_20: | 
|  | 5299 | return "20 MHz"; | 
|  | 5300 | case CHAN_WIDTH_40: | 
|  | 5301 | return "40 MHz"; | 
|  | 5302 | case CHAN_WIDTH_80: | 
|  | 5303 | return "80 MHz"; | 
|  | 5304 | case CHAN_WIDTH_80P80: | 
|  | 5305 | return "80+80 MHz"; | 
|  | 5306 | case CHAN_WIDTH_160: | 
|  | 5307 | return "160 MHz"; | 
|  | 5308 | default: | 
|  | 5309 | return "unknown"; | 
|  | 5310 | } | 
|  | 5311 | } | 
|  | 5312 |  | 
|  | 5313 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5314 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, | 
|  | 5315 | size_t buflen) | 
|  | 5316 | { | 
|  | 5317 | struct wpa_signal_info si; | 
|  | 5318 | int ret; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5319 | char *pos, *end; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5320 |  | 
|  | 5321 | ret = wpa_drv_signal_poll(wpa_s, &si); | 
|  | 5322 | if (ret) | 
|  | 5323 | return -1; | 
|  | 5324 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5325 | pos = buf; | 
|  | 5326 | end = buf + buflen; | 
|  | 5327 |  | 
|  | 5328 | ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5329 | "NOISE=%d\nFREQUENCY=%u\n", | 
|  | 5330 | si.current_signal, si.current_txrate / 1000, | 
|  | 5331 | si.current_noise, si.frequency); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5332 | if (ret < 0 || ret > end - pos) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5333 | return -1; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5334 | pos += ret; | 
|  | 5335 |  | 
|  | 5336 | if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { | 
|  | 5337 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", | 
|  | 5338 | channel_width_name(si.chanwidth)); | 
|  | 5339 | if (ret < 0 || ret > end - pos) | 
|  | 5340 | return -1; | 
|  | 5341 | pos += ret; | 
|  | 5342 | } | 
|  | 5343 |  | 
|  | 5344 | if (si.center_frq1 > 0 && si.center_frq2 > 0) { | 
|  | 5345 | ret = os_snprintf(pos, end - pos, | 
|  | 5346 | "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n", | 
|  | 5347 | si.center_frq1, si.center_frq2); | 
|  | 5348 | if (ret < 0 || ret > end - pos) | 
|  | 5349 | return -1; | 
|  | 5350 | pos += ret; | 
|  | 5351 | } | 
|  | 5352 |  | 
|  | 5353 | if (si.avg_signal) { | 
|  | 5354 | ret = os_snprintf(pos, end - pos, | 
|  | 5355 | "AVG_RSSI=%d\n", si.avg_signal); | 
|  | 5356 | if (ret < 0 || ret >= end - pos) | 
|  | 5357 | return -1; | 
|  | 5358 | pos += ret; | 
|  | 5359 | } | 
|  | 5360 |  | 
|  | 5361 | return pos - buf; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5362 | } | 
|  | 5363 |  | 
| Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5364 |  | 
| Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 5365 | static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf, | 
|  | 5366 | size_t buflen) | 
|  | 5367 | { | 
|  | 5368 | struct hostap_sta_driver_data sta; | 
|  | 5369 | int ret; | 
|  | 5370 |  | 
|  | 5371 | ret = wpa_drv_pktcnt_poll(wpa_s, &sta); | 
|  | 5372 | if (ret) | 
|  | 5373 | return -1; | 
|  | 5374 |  | 
|  | 5375 | ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n", | 
| Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5376 | sta.tx_packets, sta.tx_retry_failed, sta.rx_packets); | 
|  | 5377 | if (ret < 0 || (size_t) ret > buflen) | 
| Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 5378 | return -1; | 
|  | 5379 | return ret; | 
|  | 5380 | } | 
|  | 5381 |  | 
|  | 5382 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5383 | #ifdef ANDROID | 
| Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 5384 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 5385 | char *buf, size_t buflen) | 
|  | 5386 | { | 
|  | 5387 | int ret; | 
|  | 5388 |  | 
|  | 5389 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); | 
| Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 5390 | if (ret == 0) { | 
|  | 5391 | if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { | 
|  | 5392 | struct p2p_data *p2p = wpa_s->global->p2p; | 
|  | 5393 | if (p2p) { | 
|  | 5394 | char country[3]; | 
|  | 5395 | country[0] = cmd[8]; | 
|  | 5396 | country[1] = cmd[9]; | 
|  | 5397 | country[2] = 0x04; | 
|  | 5398 | p2p_set_country(p2p, country); | 
|  | 5399 | } | 
|  | 5400 | } | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 5401 | ret = os_snprintf(buf, buflen, "%s\n", "OK"); | 
| Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 5402 | } | 
| Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 5403 | return ret; | 
|  | 5404 | } | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 5405 | #endif /* ANDROID */ | 
| Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 5406 |  | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5407 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5408 | static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) | 
|  | 5409 | { | 
|  | 5410 | wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state"); | 
|  | 5411 |  | 
|  | 5412 | #ifdef CONFIG_P2P | 
|  | 5413 | wpas_p2p_stop_find(wpa_s); | 
|  | 5414 | p2p_ctrl_flush(wpa_s); | 
|  | 5415 | wpas_p2p_group_remove(wpa_s, "*"); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5416 | wpas_p2p_service_flush(wpa_s); | 
|  | 5417 | wpa_s->global->p2p_disabled = 0; | 
|  | 5418 | wpa_s->global->p2p_per_sta_psk = 0; | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5419 | wpa_s->conf->num_sec_device_types = 0; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5420 | wpa_s->p2p_disable_ip_addr_req = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5421 | #endif /* CONFIG_P2P */ | 
|  | 5422 |  | 
|  | 5423 | #ifdef CONFIG_WPS_TESTING | 
|  | 5424 | wps_version_number = 0x20; | 
|  | 5425 | wps_testing_dummy_cred = 0; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5426 | wps_corrupt_pkhash = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5427 | #endif /* CONFIG_WPS_TESTING */ | 
|  | 5428 | #ifdef CONFIG_WPS | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5429 | wpa_s->wps_fragment_size = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5430 | wpas_wps_cancel(wpa_s); | 
|  | 5431 | #endif /* CONFIG_WPS */ | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5432 | wpa_s->after_wps = 0; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5433 | wpa_s->known_wps_freq = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5434 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5435 | #ifdef CONFIG_TDLS | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5436 | #ifdef CONFIG_TDLS_TESTING | 
|  | 5437 | extern unsigned int tdls_testing; | 
|  | 5438 | tdls_testing = 0; | 
|  | 5439 | #endif /* CONFIG_TDLS_TESTING */ | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5440 | wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL); | 
|  | 5441 | wpa_tdls_enable(wpa_s->wpa, 1); | 
|  | 5442 | #endif /* CONFIG_TDLS */ | 
|  | 5443 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5444 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); | 
|  | 5445 | wpa_supplicant_stop_countermeasures(wpa_s, NULL); | 
|  | 5446 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5447 | wpa_s->no_keep_alive = 0; | 
|  | 5448 |  | 
|  | 5449 | os_free(wpa_s->disallow_aps_bssid); | 
|  | 5450 | wpa_s->disallow_aps_bssid = NULL; | 
|  | 5451 | wpa_s->disallow_aps_bssid_count = 0; | 
|  | 5452 | os_free(wpa_s->disallow_aps_ssid); | 
|  | 5453 | wpa_s->disallow_aps_ssid = NULL; | 
|  | 5454 | wpa_s->disallow_aps_ssid_count = 0; | 
|  | 5455 |  | 
|  | 5456 | wpa_s->set_sta_uapsd = 0; | 
|  | 5457 | wpa_s->sta_uapsd = 0; | 
|  | 5458 |  | 
|  | 5459 | wpa_drv_radio_disable(wpa_s, 0); | 
|  | 5460 |  | 
|  | 5461 | wpa_bss_flush(wpa_s); | 
|  | 5462 | wpa_blacklist_clear(wpa_s); | 
| Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 5463 | wpa_s->extra_blacklist_count = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5464 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all"); | 
|  | 5465 | wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all"); | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5466 | wpa_config_flush_blobs(wpa_s->conf); | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 5467 | wpa_s->conf->auto_interworking = 0; | 
|  | 5468 | wpa_s->conf->okc = 0; | 
|  | 5469 | wpa_s->conf->pmf = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5470 |  | 
|  | 5471 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200); | 
|  | 5472 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70); | 
|  | 5473 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60); | 
|  | 5474 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); | 
|  | 5475 |  | 
|  | 5476 | radio_remove_unstarted_work(wpa_s, NULL); | 
|  | 5477 | } | 
|  | 5478 |  | 
|  | 5479 |  | 
|  | 5480 | static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s, | 
|  | 5481 | char *buf, size_t buflen) | 
|  | 5482 | { | 
|  | 5483 | struct wpa_radio_work *work; | 
|  | 5484 | char *pos, *end; | 
|  | 5485 | struct os_reltime now, diff; | 
|  | 5486 |  | 
|  | 5487 | pos = buf; | 
|  | 5488 | end = buf + buflen; | 
|  | 5489 |  | 
|  | 5490 | os_get_reltime(&now); | 
|  | 5491 |  | 
|  | 5492 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | 
|  | 5493 | { | 
|  | 5494 | int ret; | 
|  | 5495 |  | 
|  | 5496 | os_reltime_sub(&now, &work->time, &diff); | 
|  | 5497 | ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n", | 
|  | 5498 | work->type, work->wpa_s->ifname, work->freq, | 
|  | 5499 | work->started, diff.sec, diff.usec); | 
|  | 5500 | if (ret < 0 || ret >= end - pos) | 
|  | 5501 | break; | 
|  | 5502 | pos += ret; | 
|  | 5503 | } | 
|  | 5504 |  | 
|  | 5505 | return pos - buf; | 
|  | 5506 | } | 
|  | 5507 |  | 
|  | 5508 |  | 
|  | 5509 | static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx) | 
|  | 5510 | { | 
|  | 5511 | struct wpa_radio_work *work = eloop_ctx; | 
|  | 5512 | struct wpa_external_work *ework = work->ctx; | 
|  | 5513 |  | 
|  | 5514 | wpa_dbg(work->wpa_s, MSG_DEBUG, | 
|  | 5515 | "Timing out external radio work %u (%s)", | 
|  | 5516 | ework->id, work->type); | 
|  | 5517 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id); | 
|  | 5518 | os_free(ework); | 
|  | 5519 | radio_work_done(work); | 
|  | 5520 | } | 
|  | 5521 |  | 
|  | 5522 |  | 
|  | 5523 | static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit) | 
|  | 5524 | { | 
|  | 5525 | struct wpa_external_work *ework = work->ctx; | 
|  | 5526 |  | 
|  | 5527 | if (deinit) { | 
|  | 5528 | os_free(ework); | 
|  | 5529 | return; | 
|  | 5530 | } | 
|  | 5531 |  | 
|  | 5532 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)", | 
|  | 5533 | ework->id, ework->type); | 
|  | 5534 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id); | 
|  | 5535 | if (!ework->timeout) | 
|  | 5536 | ework->timeout = 10; | 
|  | 5537 | eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout, | 
|  | 5538 | work, NULL); | 
|  | 5539 | } | 
|  | 5540 |  | 
|  | 5541 |  | 
|  | 5542 | static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 5543 | char *buf, size_t buflen) | 
|  | 5544 | { | 
|  | 5545 | struct wpa_external_work *ework; | 
|  | 5546 | char *pos, *pos2; | 
|  | 5547 | size_t type_len; | 
|  | 5548 | int ret; | 
|  | 5549 | unsigned int freq = 0; | 
|  | 5550 |  | 
|  | 5551 | /* format: <name> [freq=<MHz>] [timeout=<seconds>] */ | 
|  | 5552 |  | 
|  | 5553 | ework = os_zalloc(sizeof(*ework)); | 
|  | 5554 | if (ework == NULL) | 
|  | 5555 | return -1; | 
|  | 5556 |  | 
|  | 5557 | pos = os_strchr(cmd, ' '); | 
|  | 5558 | if (pos) { | 
|  | 5559 | type_len = pos - cmd; | 
|  | 5560 | pos++; | 
|  | 5561 |  | 
|  | 5562 | pos2 = os_strstr(pos, "freq="); | 
|  | 5563 | if (pos2) | 
|  | 5564 | freq = atoi(pos2 + 5); | 
|  | 5565 |  | 
|  | 5566 | pos2 = os_strstr(pos, "timeout="); | 
|  | 5567 | if (pos2) | 
|  | 5568 | ework->timeout = atoi(pos2 + 8); | 
|  | 5569 | } else { | 
|  | 5570 | type_len = os_strlen(cmd); | 
|  | 5571 | } | 
|  | 5572 | if (4 + type_len >= sizeof(ework->type)) | 
|  | 5573 | type_len = sizeof(ework->type) - 4 - 1; | 
|  | 5574 | os_strlcpy(ework->type, "ext:", sizeof(ework->type)); | 
|  | 5575 | os_memcpy(ework->type + 4, cmd, type_len); | 
|  | 5576 | ework->type[4 + type_len] = '\0'; | 
|  | 5577 |  | 
|  | 5578 | wpa_s->ext_work_id++; | 
|  | 5579 | if (wpa_s->ext_work_id == 0) | 
|  | 5580 | wpa_s->ext_work_id++; | 
|  | 5581 | ework->id = wpa_s->ext_work_id; | 
|  | 5582 |  | 
|  | 5583 | if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb, | 
|  | 5584 | ework) < 0) { | 
|  | 5585 | os_free(ework); | 
|  | 5586 | return -1; | 
|  | 5587 | } | 
|  | 5588 |  | 
|  | 5589 | ret = os_snprintf(buf, buflen, "%u", ework->id); | 
|  | 5590 | if (ret < 0 || (size_t) ret >= buflen) | 
|  | 5591 | return -1; | 
|  | 5592 | return ret; | 
|  | 5593 | } | 
|  | 5594 |  | 
|  | 5595 |  | 
|  | 5596 | static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5597 | { | 
|  | 5598 | struct wpa_radio_work *work; | 
|  | 5599 | unsigned int id = atoi(cmd); | 
|  | 5600 |  | 
|  | 5601 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | 
|  | 5602 | { | 
|  | 5603 | struct wpa_external_work *ework; | 
|  | 5604 |  | 
|  | 5605 | if (os_strncmp(work->type, "ext:", 4) != 0) | 
|  | 5606 | continue; | 
|  | 5607 | ework = work->ctx; | 
|  | 5608 | if (id && ework->id != id) | 
|  | 5609 | continue; | 
|  | 5610 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 5611 | "Completed external radio work %u (%s)", | 
|  | 5612 | ework->id, ework->type); | 
|  | 5613 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL); | 
|  | 5614 | os_free(ework); | 
|  | 5615 | radio_work_done(work); | 
|  | 5616 | return 3; /* "OK\n" */ | 
|  | 5617 | } | 
|  | 5618 |  | 
|  | 5619 | return -1; | 
|  | 5620 | } | 
|  | 5621 |  | 
|  | 5622 |  | 
|  | 5623 | static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 5624 | char *buf, size_t buflen) | 
|  | 5625 | { | 
|  | 5626 | if (os_strcmp(cmd, "show") == 0) | 
|  | 5627 | return wpas_ctrl_radio_work_show(wpa_s, buf, buflen); | 
|  | 5628 | if (os_strncmp(cmd, "add ", 4) == 0) | 
|  | 5629 | return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen); | 
|  | 5630 | if (os_strncmp(cmd, "done ", 5) == 0) | 
|  | 5631 | return wpas_ctrl_radio_work_done(wpa_s, cmd + 4); | 
|  | 5632 | return -1; | 
|  | 5633 | } | 
|  | 5634 |  | 
|  | 5635 |  | 
|  | 5636 | void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) | 
|  | 5637 | { | 
|  | 5638 | struct wpa_radio_work *work, *tmp; | 
|  | 5639 |  | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 5640 | if (!wpa_s || !wpa_s->radio) | 
|  | 5641 | return; | 
|  | 5642 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5643 | dl_list_for_each_safe(work, tmp, &wpa_s->radio->work, | 
|  | 5644 | struct wpa_radio_work, list) { | 
|  | 5645 | struct wpa_external_work *ework; | 
|  | 5646 |  | 
|  | 5647 | if (os_strncmp(work->type, "ext:", 4) != 0) | 
|  | 5648 | continue; | 
|  | 5649 | ework = work->ctx; | 
|  | 5650 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 5651 | "Flushing %sexternal radio work %u (%s)", | 
|  | 5652 | work->started ? " started" : "", ework->id, | 
|  | 5653 | ework->type); | 
|  | 5654 | if (work->started) | 
|  | 5655 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | 
|  | 5656 | work, NULL); | 
|  | 5657 | os_free(ework); | 
|  | 5658 | radio_work_done(work); | 
|  | 5659 | } | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5660 | } | 
|  | 5661 |  | 
|  | 5662 |  | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5663 | static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx) | 
|  | 5664 | { | 
|  | 5665 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 5666 | eapol_sm_notify_ctrl_response(wpa_s->eapol); | 
|  | 5667 | } | 
|  | 5668 |  | 
|  | 5669 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5670 | static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val) | 
|  | 5671 | { | 
|  | 5672 | int *freqs = NULL; | 
|  | 5673 |  | 
|  | 5674 | freqs = freq_range_to_channel_list(wpa_s, val); | 
|  | 5675 | if (freqs == NULL) | 
|  | 5676 | return -1; | 
|  | 5677 |  | 
|  | 5678 | os_free(wpa_s->manual_scan_freqs); | 
|  | 5679 | wpa_s->manual_scan_freqs = freqs; | 
|  | 5680 |  | 
|  | 5681 | return 0; | 
|  | 5682 | } | 
|  | 5683 |  | 
|  | 5684 |  | 
|  | 5685 | static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params, | 
|  | 5686 | char *reply, int reply_size, int *reply_len) | 
|  | 5687 | { | 
|  | 5688 | char *pos; | 
|  | 5689 |  | 
|  | 5690 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | 
|  | 5691 | *reply_len = -1; | 
|  | 5692 | return; | 
|  | 5693 | } | 
|  | 5694 |  | 
|  | 5695 | wpa_s->manual_scan_passive = 0; | 
|  | 5696 | wpa_s->manual_scan_use_id = 0; | 
|  | 5697 | wpa_s->manual_scan_only_new = 0; | 
|  | 5698 |  | 
|  | 5699 | if (params) { | 
|  | 5700 | if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0) | 
|  | 5701 | wpa_s->scan_res_handler = scan_only_handler; | 
|  | 5702 |  | 
|  | 5703 | pos = os_strstr(params, "freq="); | 
|  | 5704 | if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) { | 
|  | 5705 | *reply_len = -1; | 
|  | 5706 | return; | 
|  | 5707 | } | 
|  | 5708 |  | 
|  | 5709 | pos = os_strstr(params, "passive="); | 
|  | 5710 | if (pos) | 
|  | 5711 | wpa_s->manual_scan_passive = !!atoi(pos + 8); | 
|  | 5712 |  | 
|  | 5713 | pos = os_strstr(params, "use_id="); | 
|  | 5714 | if (pos) | 
|  | 5715 | wpa_s->manual_scan_use_id = atoi(pos + 7); | 
|  | 5716 |  | 
|  | 5717 | pos = os_strstr(params, "only_new=1"); | 
|  | 5718 | if (pos) | 
|  | 5719 | wpa_s->manual_scan_only_new = 1; | 
|  | 5720 | } else { | 
|  | 5721 | os_free(wpa_s->manual_scan_freqs); | 
|  | 5722 | wpa_s->manual_scan_freqs = NULL; | 
|  | 5723 | if (wpa_s->scan_res_handler == scan_only_handler) | 
|  | 5724 | wpa_s->scan_res_handler = NULL; | 
|  | 5725 | } | 
|  | 5726 |  | 
|  | 5727 | if (!wpa_s->sched_scanning && !wpa_s->scanning && | 
|  | 5728 | ((wpa_s->wpa_state <= WPA_SCANNING) || | 
|  | 5729 | (wpa_s->wpa_state == WPA_COMPLETED))) { | 
|  | 5730 | wpa_s->normal_scans = 0; | 
|  | 5731 | wpa_s->scan_req = MANUAL_SCAN_REQ; | 
|  | 5732 | wpa_s->after_wps = 0; | 
|  | 5733 | wpa_s->known_wps_freq = 0; | 
|  | 5734 | wpa_supplicant_req_scan(wpa_s, 0, 0); | 
|  | 5735 | if (wpa_s->manual_scan_use_id) { | 
|  | 5736 | wpa_s->manual_scan_id++; | 
|  | 5737 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | 
|  | 5738 | wpa_s->manual_scan_id); | 
|  | 5739 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | 
|  | 5740 | wpa_s->manual_scan_id); | 
|  | 5741 | } | 
|  | 5742 | } else if (wpa_s->sched_scanning) { | 
|  | 5743 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed"); | 
|  | 5744 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
|  | 5745 | wpa_s->scan_req = MANUAL_SCAN_REQ; | 
|  | 5746 | wpa_supplicant_req_scan(wpa_s, 0, 0); | 
|  | 5747 | if (wpa_s->manual_scan_use_id) { | 
|  | 5748 | wpa_s->manual_scan_id++; | 
|  | 5749 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | 
|  | 5750 | wpa_s->manual_scan_id); | 
|  | 5751 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | 
|  | 5752 | wpa_s->manual_scan_id); | 
|  | 5753 | } | 
|  | 5754 | } else { | 
|  | 5755 | wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request"); | 
|  | 5756 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | 
|  | 5757 | } | 
|  | 5758 | } | 
|  | 5759 |  | 
|  | 5760 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5761 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, | 
|  | 5762 | char *buf, size_t *resp_len) | 
|  | 5763 | { | 
|  | 5764 | char *reply; | 
|  | 5765 | const int reply_size = 4096; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5766 | int reply_len; | 
|  | 5767 |  | 
|  | 5768 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5769 | os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | 
|  | 5770 | if (wpa_debug_show_keys) | 
|  | 5771 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 5772 | "Control interface command '%s'", buf); | 
|  | 5773 | else | 
|  | 5774 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 5775 | "Control interface command '%s [REMOVED]'", | 
|  | 5776 | os_strncmp(buf, WPA_CTRL_RSP, | 
|  | 5777 | os_strlen(WPA_CTRL_RSP)) == 0 ? | 
|  | 5778 | WPA_CTRL_RSP : "SET_NETWORK"); | 
|  | 5779 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 || | 
|  | 5780 | os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 || | 
|  | 5781 | os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5782 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", | 
|  | 5783 | (const u8 *) buf, os_strlen(buf)); | 
|  | 5784 | } else { | 
|  | 5785 | int level = MSG_DEBUG; | 
|  | 5786 | if (os_strcmp(buf, "PING") == 0) | 
|  | 5787 | level = MSG_EXCESSIVE; | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5788 | wpa_dbg(wpa_s, level, "Control interface command '%s'", buf); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5789 | } | 
|  | 5790 |  | 
|  | 5791 | reply = os_malloc(reply_size); | 
|  | 5792 | if (reply == NULL) { | 
|  | 5793 | *resp_len = 1; | 
|  | 5794 | return NULL; | 
|  | 5795 | } | 
|  | 5796 |  | 
|  | 5797 | os_memcpy(reply, "OK\n", 3); | 
|  | 5798 | reply_len = 3; | 
|  | 5799 |  | 
|  | 5800 | if (os_strcmp(buf, "PING") == 0) { | 
|  | 5801 | os_memcpy(reply, "PONG\n", 5); | 
|  | 5802 | reply_len = 5; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5803 | } else if (os_strcmp(buf, "IFNAME") == 0) { | 
|  | 5804 | reply_len = os_strlen(wpa_s->ifname); | 
|  | 5805 | os_memcpy(reply, wpa_s->ifname, reply_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5806 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { | 
|  | 5807 | if (wpa_debug_reopen_file() < 0) | 
|  | 5808 | reply_len = -1; | 
|  | 5809 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { | 
|  | 5810 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); | 
|  | 5811 | } else if (os_strcmp(buf, "MIB") == 0) { | 
|  | 5812 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); | 
|  | 5813 | if (reply_len >= 0) { | 
|  | 5814 | int res; | 
|  | 5815 | res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len, | 
|  | 5816 | reply_size - reply_len); | 
|  | 5817 | if (res < 0) | 
|  | 5818 | reply_len = -1; | 
|  | 5819 | else | 
|  | 5820 | reply_len += res; | 
|  | 5821 | } | 
|  | 5822 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { | 
|  | 5823 | reply_len = wpa_supplicant_ctrl_iface_status( | 
|  | 5824 | wpa_s, buf + 6, reply, reply_size); | 
|  | 5825 | } else if (os_strcmp(buf, "PMKSA") == 0) { | 
|  | 5826 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply, | 
|  | 5827 | reply_size); | 
|  | 5828 | } else if (os_strncmp(buf, "SET ", 4) == 0) { | 
|  | 5829 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) | 
|  | 5830 | reply_len = -1; | 
|  | 5831 | } else if (os_strncmp(buf, "GET ", 4) == 0) { | 
|  | 5832 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, | 
|  | 5833 | reply, reply_size); | 
|  | 5834 | } else if (os_strcmp(buf, "LOGON") == 0) { | 
|  | 5835 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); | 
|  | 5836 | } else if (os_strcmp(buf, "LOGOFF") == 0) { | 
|  | 5837 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); | 
|  | 5838 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { | 
|  | 5839 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) | 
|  | 5840 | reply_len = -1; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5841 | else | 
|  | 5842 | wpas_request_connection(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5843 | } else if (os_strcmp(buf, "RECONNECT") == 0) { | 
|  | 5844 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) | 
|  | 5845 | reply_len = -1; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5846 | else if (wpa_s->disconnected) | 
|  | 5847 | wpas_request_connection(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5848 | #ifdef IEEE8021X_EAPOL | 
|  | 5849 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { | 
|  | 5850 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) | 
|  | 5851 | reply_len = -1; | 
|  | 5852 | #endif /* IEEE8021X_EAPOL */ | 
|  | 5853 | #ifdef CONFIG_PEERKEY | 
|  | 5854 | } else if (os_strncmp(buf, "STKSTART ", 9) == 0) { | 
|  | 5855 | if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9)) | 
|  | 5856 | reply_len = -1; | 
|  | 5857 | #endif /* CONFIG_PEERKEY */ | 
|  | 5858 | #ifdef CONFIG_IEEE80211R | 
|  | 5859 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { | 
|  | 5860 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) | 
|  | 5861 | reply_len = -1; | 
|  | 5862 | #endif /* CONFIG_IEEE80211R */ | 
|  | 5863 | #ifdef CONFIG_WPS | 
|  | 5864 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { | 
|  | 5865 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); | 
|  | 5866 | if (res == -2) { | 
|  | 5867 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | 
|  | 5868 | reply_len = 17; | 
|  | 5869 | } else if (res) | 
|  | 5870 | reply_len = -1; | 
|  | 5871 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { | 
|  | 5872 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); | 
|  | 5873 | if (res == -2) { | 
|  | 5874 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | 
|  | 5875 | reply_len = 17; | 
|  | 5876 | } else if (res) | 
|  | 5877 | reply_len = -1; | 
|  | 5878 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { | 
|  | 5879 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, | 
|  | 5880 | reply, | 
|  | 5881 | reply_size); | 
|  | 5882 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { | 
|  | 5883 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( | 
|  | 5884 | wpa_s, buf + 14, reply, reply_size); | 
|  | 5885 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { | 
|  | 5886 | if (wpas_wps_cancel(wpa_s)) | 
|  | 5887 | reply_len = -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5888 | #ifdef CONFIG_WPS_NFC | 
|  | 5889 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { | 
|  | 5890 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) | 
|  | 5891 | reply_len = -1; | 
|  | 5892 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { | 
|  | 5893 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) | 
|  | 5894 | reply_len = -1; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5895 | } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) { | 
|  | 5896 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token( | 
|  | 5897 | wpa_s, buf + 21, reply, reply_size); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5898 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { | 
|  | 5899 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( | 
|  | 5900 | wpa_s, buf + 14, reply, reply_size); | 
|  | 5901 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { | 
|  | 5902 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, | 
|  | 5903 | buf + 17)) | 
|  | 5904 | reply_len = -1; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5905 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) { | 
|  | 5906 | reply_len = wpas_ctrl_nfc_get_handover_req( | 
|  | 5907 | wpa_s, buf + 21, reply, reply_size); | 
|  | 5908 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) { | 
|  | 5909 | reply_len = wpas_ctrl_nfc_get_handover_sel( | 
|  | 5910 | wpa_s, buf + 21, reply, reply_size); | 
|  | 5911 | } else if (os_strncmp(buf, "NFC_RX_HANDOVER_REQ ", 20) == 0) { | 
|  | 5912 | reply_len = wpas_ctrl_nfc_rx_handover_req( | 
|  | 5913 | wpa_s, buf + 20, reply, reply_size); | 
|  | 5914 | } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) { | 
|  | 5915 | if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20)) | 
|  | 5916 | reply_len = -1; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5917 | } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) { | 
|  | 5918 | if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20)) | 
|  | 5919 | reply_len = -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5920 | #endif /* CONFIG_WPS_NFC */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5921 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { | 
|  | 5922 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) | 
|  | 5923 | reply_len = -1; | 
|  | 5924 | #ifdef CONFIG_AP | 
|  | 5925 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { | 
|  | 5926 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( | 
|  | 5927 | wpa_s, buf + 11, reply, reply_size); | 
|  | 5928 | #endif /* CONFIG_AP */ | 
|  | 5929 | #ifdef CONFIG_WPS_ER | 
|  | 5930 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { | 
|  | 5931 | if (wpas_wps_er_start(wpa_s, NULL)) | 
|  | 5932 | reply_len = -1; | 
|  | 5933 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { | 
|  | 5934 | if (wpas_wps_er_start(wpa_s, buf + 13)) | 
|  | 5935 | reply_len = -1; | 
|  | 5936 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { | 
|  | 5937 | if (wpas_wps_er_stop(wpa_s)) | 
|  | 5938 | reply_len = -1; | 
|  | 5939 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { | 
|  | 5940 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) | 
|  | 5941 | reply_len = -1; | 
|  | 5942 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { | 
|  | 5943 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); | 
|  | 5944 | if (ret == -2) { | 
|  | 5945 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | 
|  | 5946 | reply_len = 17; | 
|  | 5947 | } else if (ret == -3) { | 
|  | 5948 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); | 
|  | 5949 | reply_len = 18; | 
|  | 5950 | } else if (ret == -4) { | 
|  | 5951 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); | 
|  | 5952 | reply_len = 20; | 
|  | 5953 | } else if (ret) | 
|  | 5954 | reply_len = -1; | 
|  | 5955 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { | 
|  | 5956 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) | 
|  | 5957 | reply_len = -1; | 
|  | 5958 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { | 
|  | 5959 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, | 
|  | 5960 | buf + 18)) | 
|  | 5961 | reply_len = -1; | 
|  | 5962 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { | 
|  | 5963 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) | 
|  | 5964 | reply_len = -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5965 | #ifdef CONFIG_WPS_NFC | 
|  | 5966 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { | 
|  | 5967 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | 
|  | 5968 | wpa_s, buf + 24, reply, reply_size); | 
|  | 5969 | #endif /* CONFIG_WPS_NFC */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5970 | #endif /* CONFIG_WPS_ER */ | 
|  | 5971 | #endif /* CONFIG_WPS */ | 
|  | 5972 | #ifdef CONFIG_IBSS_RSN | 
|  | 5973 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { | 
|  | 5974 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) | 
|  | 5975 | reply_len = -1; | 
|  | 5976 | #endif /* CONFIG_IBSS_RSN */ | 
|  | 5977 | #ifdef CONFIG_P2P | 
|  | 5978 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { | 
|  | 5979 | if (p2p_ctrl_find(wpa_s, buf + 9)) | 
|  | 5980 | reply_len = -1; | 
|  | 5981 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { | 
|  | 5982 | if (p2p_ctrl_find(wpa_s, "")) | 
|  | 5983 | reply_len = -1; | 
|  | 5984 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { | 
|  | 5985 | wpas_p2p_stop_find(wpa_s); | 
|  | 5986 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { | 
|  | 5987 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, | 
|  | 5988 | reply_size); | 
|  | 5989 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { | 
|  | 5990 | if (p2p_ctrl_listen(wpa_s, buf + 11)) | 
|  | 5991 | reply_len = -1; | 
|  | 5992 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { | 
|  | 5993 | if (p2p_ctrl_listen(wpa_s, "")) | 
|  | 5994 | reply_len = -1; | 
|  | 5995 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { | 
|  | 5996 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) | 
|  | 5997 | reply_len = -1; | 
|  | 5998 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5999 | if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6000 | reply_len = -1; | 
|  | 6001 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { | 
|  | 6002 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) | 
|  | 6003 | reply_len = -1; | 
|  | 6004 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { | 
|  | 6005 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) | 
|  | 6006 | reply_len = -1; | 
|  | 6007 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { | 
|  | 6008 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); | 
|  | 6009 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { | 
|  | 6010 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, | 
|  | 6011 | reply_size); | 
|  | 6012 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { | 
|  | 6013 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) | 
|  | 6014 | reply_len = -1; | 
|  | 6015 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { | 
|  | 6016 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) | 
|  | 6017 | reply_len = -1; | 
|  | 6018 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { | 
|  | 6019 | wpas_p2p_sd_service_update(wpa_s); | 
|  | 6020 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { | 
|  | 6021 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) | 
|  | 6022 | reply_len = -1; | 
|  | 6023 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { | 
|  | 6024 | wpas_p2p_service_flush(wpa_s); | 
|  | 6025 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { | 
|  | 6026 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) | 
|  | 6027 | reply_len = -1; | 
|  | 6028 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { | 
|  | 6029 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) | 
|  | 6030 | reply_len = -1; | 
|  | 6031 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { | 
|  | 6032 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) | 
|  | 6033 | reply_len = -1; | 
|  | 6034 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { | 
|  | 6035 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) | 
|  | 6036 | reply_len = -1; | 
|  | 6037 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { | 
|  | 6038 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, | 
|  | 6039 | reply_size); | 
|  | 6040 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { | 
|  | 6041 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) | 
|  | 6042 | reply_len = -1; | 
|  | 6043 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6044 | p2p_ctrl_flush(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6045 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { | 
|  | 6046 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) | 
|  | 6047 | reply_len = -1; | 
|  | 6048 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { | 
|  | 6049 | if (wpas_p2p_cancel(wpa_s)) | 
|  | 6050 | reply_len = -1; | 
|  | 6051 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { | 
|  | 6052 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) | 
|  | 6053 | reply_len = -1; | 
|  | 6054 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { | 
|  | 6055 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) | 
|  | 6056 | reply_len = -1; | 
|  | 6057 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { | 
|  | 6058 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) | 
|  | 6059 | reply_len = -1; | 
|  | 6060 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { | 
|  | 6061 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) | 
|  | 6062 | reply_len = -1; | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6063 | } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) { | 
|  | 6064 | if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0) | 
|  | 6065 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6066 | #endif /* CONFIG_P2P */ | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6067 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 6068 | } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) { | 
|  | 6069 | if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0) | 
|  | 6070 | reply_len = -1; | 
|  | 6071 | } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) { | 
|  | 6072 | reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16, | 
|  | 6073 | reply, reply_size); | 
|  | 6074 | #endif /* CONFIG_WIFI_DISPLAY */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6075 | #ifdef CONFIG_INTERWORKING | 
|  | 6076 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { | 
|  | 6077 | if (interworking_fetch_anqp(wpa_s) < 0) | 
|  | 6078 | reply_len = -1; | 
|  | 6079 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { | 
|  | 6080 | interworking_stop_fetch_anqp(wpa_s); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6081 | } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) { | 
|  | 6082 | if (ctrl_interworking_select(wpa_s, NULL) < 0) | 
|  | 6083 | reply_len = -1; | 
|  | 6084 | } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) { | 
|  | 6085 | if (ctrl_interworking_select(wpa_s, buf + 20) < 0) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6086 | reply_len = -1; | 
|  | 6087 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { | 
|  | 6088 | if (ctrl_interworking_connect(wpa_s, buf + 21) < 0) | 
|  | 6089 | reply_len = -1; | 
|  | 6090 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { | 
|  | 6091 | if (get_anqp(wpa_s, buf + 9) < 0) | 
|  | 6092 | reply_len = -1; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6093 | } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) { | 
|  | 6094 | if (gas_request(wpa_s, buf + 12) < 0) | 
|  | 6095 | reply_len = -1; | 
|  | 6096 | } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) { | 
|  | 6097 | reply_len = gas_response_get(wpa_s, buf + 17, reply, | 
|  | 6098 | reply_size); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6099 | #endif /* CONFIG_INTERWORKING */ | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6100 | #ifdef CONFIG_HS20 | 
|  | 6101 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { | 
|  | 6102 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) | 
|  | 6103 | reply_len = -1; | 
|  | 6104 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { | 
|  | 6105 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) | 
|  | 6106 | reply_len = -1; | 
|  | 6107 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6108 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) | 
|  | 6109 | { | 
|  | 6110 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( | 
|  | 6111 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) | 
|  | 6112 | reply_len = -1; | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6113 | else { | 
|  | 6114 | /* | 
|  | 6115 | * Notify response from timeout to allow the control | 
|  | 6116 | * interface response to be sent first. | 
|  | 6117 | */ | 
|  | 6118 | eloop_register_timeout(0, 0, wpas_ctrl_eapol_response, | 
|  | 6119 | wpa_s, NULL); | 
|  | 6120 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6121 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { | 
|  | 6122 | if (wpa_supplicant_reload_configuration(wpa_s)) | 
|  | 6123 | reply_len = -1; | 
|  | 6124 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | 
|  | 6125 | wpa_supplicant_terminate_proc(wpa_s->global); | 
|  | 6126 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { | 
|  | 6127 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) | 
|  | 6128 | reply_len = -1; | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 6129 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6130 | reply_len = wpa_supplicant_ctrl_iface_blacklist( | 
|  | 6131 | wpa_s, buf + 9, reply, reply_size); | 
|  | 6132 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { | 
|  | 6133 | reply_len = wpa_supplicant_ctrl_iface_log_level( | 
|  | 6134 | wpa_s, buf + 9, reply, reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6135 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { | 
|  | 6136 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | 
|  | 6137 | wpa_s, reply, reply_size); | 
|  | 6138 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6139 | #ifdef CONFIG_SME | 
|  | 6140 | wpa_s->sme.prev_bssid_set = 0; | 
|  | 6141 | #endif /* CONFIG_SME */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6142 | wpa_s->reassociate = 0; | 
|  | 6143 | wpa_s->disconnected = 1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6144 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6145 | wpa_supplicant_cancel_scan(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6146 | wpa_supplicant_deauthenticate(wpa_s, | 
|  | 6147 | WLAN_REASON_DEAUTH_LEAVING); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6148 | } else if (os_strcmp(buf, "SCAN") == 0) { | 
|  | 6149 | wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len); | 
|  | 6150 | } else if (os_strncmp(buf, "SCAN ", 5) == 0) { | 
|  | 6151 | wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6152 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { | 
|  | 6153 | reply_len = wpa_supplicant_ctrl_iface_scan_results( | 
|  | 6154 | wpa_s, reply, reply_size); | 
|  | 6155 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { | 
|  | 6156 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) | 
|  | 6157 | reply_len = -1; | 
|  | 6158 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { | 
|  | 6159 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) | 
|  | 6160 | reply_len = -1; | 
|  | 6161 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { | 
|  | 6162 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) | 
|  | 6163 | reply_len = -1; | 
|  | 6164 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { | 
|  | 6165 | reply_len = wpa_supplicant_ctrl_iface_add_network( | 
|  | 6166 | wpa_s, reply, reply_size); | 
|  | 6167 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { | 
|  | 6168 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) | 
|  | 6169 | reply_len = -1; | 
|  | 6170 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | 
|  | 6171 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) | 
|  | 6172 | reply_len = -1; | 
|  | 6173 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { | 
|  | 6174 | reply_len = wpa_supplicant_ctrl_iface_get_network( | 
|  | 6175 | wpa_s, buf + 12, reply, reply_size); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6176 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { | 
|  | 6177 | reply_len = wpa_supplicant_ctrl_iface_list_creds( | 
|  | 6178 | wpa_s, reply, reply_size); | 
|  | 6179 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { | 
|  | 6180 | reply_len = wpa_supplicant_ctrl_iface_add_cred( | 
|  | 6181 | wpa_s, reply, reply_size); | 
|  | 6182 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { | 
|  | 6183 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) | 
|  | 6184 | reply_len = -1; | 
|  | 6185 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { | 
|  | 6186 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) | 
|  | 6187 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6188 | #ifndef CONFIG_NO_CONFIG_WRITE | 
|  | 6189 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | 
|  | 6190 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) | 
|  | 6191 | reply_len = -1; | 
|  | 6192 | #endif /* CONFIG_NO_CONFIG_WRITE */ | 
|  | 6193 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { | 
|  | 6194 | reply_len = wpa_supplicant_ctrl_iface_get_capability( | 
|  | 6195 | wpa_s, buf + 15, reply, reply_size); | 
|  | 6196 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { | 
|  | 6197 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) | 
|  | 6198 | reply_len = -1; | 
|  | 6199 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { | 
|  | 6200 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) | 
|  | 6201 | reply_len = -1; | 
|  | 6202 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { | 
|  | 6203 | reply_len = wpa_supplicant_global_iface_list( | 
|  | 6204 | wpa_s->global, reply, reply_size); | 
|  | 6205 | } else if (os_strcmp(buf, "INTERFACES") == 0) { | 
|  | 6206 | reply_len = wpa_supplicant_global_iface_interfaces( | 
|  | 6207 | wpa_s->global, reply, reply_size); | 
|  | 6208 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { | 
|  | 6209 | reply_len = wpa_supplicant_ctrl_iface_bss( | 
|  | 6210 | wpa_s, buf + 4, reply, reply_size); | 
|  | 6211 | #ifdef CONFIG_AP | 
|  | 6212 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { | 
|  | 6213 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); | 
|  | 6214 | } else if (os_strncmp(buf, "STA ", 4) == 0) { | 
|  | 6215 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, | 
|  | 6216 | reply_size); | 
|  | 6217 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { | 
|  | 6218 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, | 
|  | 6219 | reply_size); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6220 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { | 
|  | 6221 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) | 
|  | 6222 | reply_len = -1; | 
|  | 6223 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { | 
|  | 6224 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) | 
|  | 6225 | reply_len = -1; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6226 | } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) { | 
|  | 6227 | if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12)) | 
|  | 6228 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6229 | #endif /* CONFIG_AP */ | 
|  | 6230 | } else if (os_strcmp(buf, "SUSPEND") == 0) { | 
|  | 6231 | wpas_notify_suspend(wpa_s->global); | 
|  | 6232 | } else if (os_strcmp(buf, "RESUME") == 0) { | 
|  | 6233 | wpas_notify_resume(wpa_s->global); | 
|  | 6234 | } else if (os_strcmp(buf, "DROP_SA") == 0) { | 
|  | 6235 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); | 
|  | 6236 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { | 
|  | 6237 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) | 
|  | 6238 | reply_len = -1; | 
|  | 6239 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { | 
|  | 6240 | if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16)) | 
|  | 6241 | reply_len = -1; | 
|  | 6242 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { | 
|  | 6243 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) | 
|  | 6244 | reply_len = -1; | 
|  | 6245 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { | 
|  | 6246 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, | 
|  | 6247 | buf + 17)) | 
|  | 6248 | reply_len = -1; | 
| Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 6249 | } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) { | 
|  | 6250 | if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10)) | 
|  | 6251 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6252 | #ifdef CONFIG_TDLS | 
|  | 6253 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { | 
|  | 6254 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) | 
|  | 6255 | reply_len = -1; | 
|  | 6256 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { | 
|  | 6257 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) | 
|  | 6258 | reply_len = -1; | 
|  | 6259 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { | 
|  | 6260 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) | 
|  | 6261 | reply_len = -1; | 
|  | 6262 | #endif /* CONFIG_TDLS */ | 
|  | 6263 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { | 
|  | 6264 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, | 
|  | 6265 | reply_size); | 
| Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 6266 | } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) { | 
|  | 6267 | reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply, | 
|  | 6268 | reply_size); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6269 | #ifdef CONFIG_AUTOSCAN | 
|  | 6270 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { | 
|  | 6271 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) | 
|  | 6272 | reply_len = -1; | 
|  | 6273 | #endif /* CONFIG_AUTOSCAN */ | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6274 | #ifdef ANDROID | 
| Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 6275 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { | 
|  | 6276 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, | 
|  | 6277 | reply_size); | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 6278 | #endif /* ANDROID */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6279 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6280 | pmksa_cache_clear_current(wpa_s->wpa); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6281 | eapol_sm_request_reauth(wpa_s->eapol); | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6282 | #ifdef CONFIG_WNM | 
|  | 6283 | } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) { | 
|  | 6284 | if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10)) | 
|  | 6285 | reply_len = -1; | 
| Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 6286 | } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) { | 
|  | 6287 | if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10)) | 
|  | 6288 | reply_len = -1; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6289 | #endif /* CONFIG_WNM */ | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6290 | } else if (os_strcmp(buf, "FLUSH") == 0) { | 
|  | 6291 | wpa_supplicant_ctrl_iface_flush(wpa_s); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6292 | } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) { | 
|  | 6293 | reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply, | 
|  | 6294 | reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6295 | } else { | 
|  | 6296 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | 
|  | 6297 | reply_len = 16; | 
|  | 6298 | } | 
|  | 6299 |  | 
|  | 6300 | if (reply_len < 0) { | 
|  | 6301 | os_memcpy(reply, "FAIL\n", 5); | 
|  | 6302 | reply_len = 5; | 
|  | 6303 | } | 
|  | 6304 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6305 | *resp_len = reply_len; | 
|  | 6306 | return reply; | 
|  | 6307 | } | 
|  | 6308 |  | 
|  | 6309 |  | 
|  | 6310 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, | 
|  | 6311 | char *cmd) | 
|  | 6312 | { | 
|  | 6313 | struct wpa_interface iface; | 
|  | 6314 | char *pos; | 
|  | 6315 |  | 
|  | 6316 | /* | 
|  | 6317 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> | 
|  | 6318 | * TAB<bridge_ifname> | 
|  | 6319 | */ | 
|  | 6320 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); | 
|  | 6321 |  | 
|  | 6322 | os_memset(&iface, 0, sizeof(iface)); | 
|  | 6323 |  | 
|  | 6324 | do { | 
|  | 6325 | iface.ifname = pos = cmd; | 
|  | 6326 | pos = os_strchr(pos, '\t'); | 
|  | 6327 | if (pos) | 
|  | 6328 | *pos++ = '\0'; | 
|  | 6329 | if (iface.ifname[0] == '\0') | 
|  | 6330 | return -1; | 
|  | 6331 | if (pos == NULL) | 
|  | 6332 | break; | 
|  | 6333 |  | 
|  | 6334 | iface.confname = pos; | 
|  | 6335 | pos = os_strchr(pos, '\t'); | 
|  | 6336 | if (pos) | 
|  | 6337 | *pos++ = '\0'; | 
|  | 6338 | if (iface.confname[0] == '\0') | 
|  | 6339 | iface.confname = NULL; | 
|  | 6340 | if (pos == NULL) | 
|  | 6341 | break; | 
|  | 6342 |  | 
|  | 6343 | iface.driver = pos; | 
|  | 6344 | pos = os_strchr(pos, '\t'); | 
|  | 6345 | if (pos) | 
|  | 6346 | *pos++ = '\0'; | 
|  | 6347 | if (iface.driver[0] == '\0') | 
|  | 6348 | iface.driver = NULL; | 
|  | 6349 | if (pos == NULL) | 
|  | 6350 | break; | 
|  | 6351 |  | 
|  | 6352 | iface.ctrl_interface = pos; | 
|  | 6353 | pos = os_strchr(pos, '\t'); | 
|  | 6354 | if (pos) | 
|  | 6355 | *pos++ = '\0'; | 
|  | 6356 | if (iface.ctrl_interface[0] == '\0') | 
|  | 6357 | iface.ctrl_interface = NULL; | 
|  | 6358 | if (pos == NULL) | 
|  | 6359 | break; | 
|  | 6360 |  | 
|  | 6361 | iface.driver_param = pos; | 
|  | 6362 | pos = os_strchr(pos, '\t'); | 
|  | 6363 | if (pos) | 
|  | 6364 | *pos++ = '\0'; | 
|  | 6365 | if (iface.driver_param[0] == '\0') | 
|  | 6366 | iface.driver_param = NULL; | 
|  | 6367 | if (pos == NULL) | 
|  | 6368 | break; | 
|  | 6369 |  | 
|  | 6370 | iface.bridge_ifname = pos; | 
|  | 6371 | pos = os_strchr(pos, '\t'); | 
|  | 6372 | if (pos) | 
|  | 6373 | *pos++ = '\0'; | 
|  | 6374 | if (iface.bridge_ifname[0] == '\0') | 
|  | 6375 | iface.bridge_ifname = NULL; | 
|  | 6376 | if (pos == NULL) | 
|  | 6377 | break; | 
|  | 6378 | } while (0); | 
|  | 6379 |  | 
|  | 6380 | if (wpa_supplicant_get_iface(global, iface.ifname)) | 
|  | 6381 | return -1; | 
|  | 6382 |  | 
|  | 6383 | return wpa_supplicant_add_iface(global, &iface) ? 0 : -1; | 
|  | 6384 | } | 
|  | 6385 |  | 
|  | 6386 |  | 
|  | 6387 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, | 
|  | 6388 | char *cmd) | 
|  | 6389 | { | 
|  | 6390 | struct wpa_supplicant *wpa_s; | 
|  | 6391 |  | 
|  | 6392 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); | 
|  | 6393 |  | 
|  | 6394 | wpa_s = wpa_supplicant_get_iface(global, cmd); | 
|  | 6395 | if (wpa_s == NULL) | 
|  | 6396 | return -1; | 
| Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 6397 | return wpa_supplicant_remove_iface(global, wpa_s, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6398 | } | 
|  | 6399 |  | 
|  | 6400 |  | 
|  | 6401 | static void wpa_free_iface_info(struct wpa_interface_info *iface) | 
|  | 6402 | { | 
|  | 6403 | struct wpa_interface_info *prev; | 
|  | 6404 |  | 
|  | 6405 | while (iface) { | 
|  | 6406 | prev = iface; | 
|  | 6407 | iface = iface->next; | 
|  | 6408 |  | 
|  | 6409 | os_free(prev->ifname); | 
|  | 6410 | os_free(prev->desc); | 
|  | 6411 | os_free(prev); | 
|  | 6412 | } | 
|  | 6413 | } | 
|  | 6414 |  | 
|  | 6415 |  | 
|  | 6416 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, | 
|  | 6417 | char *buf, int len) | 
|  | 6418 | { | 
|  | 6419 | int i, res; | 
|  | 6420 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; | 
|  | 6421 | char *pos, *end; | 
|  | 6422 |  | 
|  | 6423 | for (i = 0; wpa_drivers[i]; i++) { | 
|  | 6424 | struct wpa_driver_ops *drv = wpa_drivers[i]; | 
|  | 6425 | if (drv->get_interfaces == NULL) | 
|  | 6426 | continue; | 
|  | 6427 | tmp = drv->get_interfaces(global->drv_priv[i]); | 
|  | 6428 | if (tmp == NULL) | 
|  | 6429 | continue; | 
|  | 6430 |  | 
|  | 6431 | if (last == NULL) | 
|  | 6432 | iface = last = tmp; | 
|  | 6433 | else | 
|  | 6434 | last->next = tmp; | 
|  | 6435 | while (last->next) | 
|  | 6436 | last = last->next; | 
|  | 6437 | } | 
|  | 6438 |  | 
|  | 6439 | pos = buf; | 
|  | 6440 | end = buf + len; | 
|  | 6441 | for (tmp = iface; tmp; tmp = tmp->next) { | 
|  | 6442 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", | 
|  | 6443 | tmp->drv_name, tmp->ifname, | 
|  | 6444 | tmp->desc ? tmp->desc : ""); | 
|  | 6445 | if (res < 0 || res >= end - pos) { | 
|  | 6446 | *pos = '\0'; | 
|  | 6447 | break; | 
|  | 6448 | } | 
|  | 6449 | pos += res; | 
|  | 6450 | } | 
|  | 6451 |  | 
|  | 6452 | wpa_free_iface_info(iface); | 
|  | 6453 |  | 
|  | 6454 | return pos - buf; | 
|  | 6455 | } | 
|  | 6456 |  | 
|  | 6457 |  | 
|  | 6458 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, | 
|  | 6459 | char *buf, int len) | 
|  | 6460 | { | 
|  | 6461 | int res; | 
|  | 6462 | char *pos, *end; | 
|  | 6463 | struct wpa_supplicant *wpa_s; | 
|  | 6464 |  | 
|  | 6465 | wpa_s = global->ifaces; | 
|  | 6466 | pos = buf; | 
|  | 6467 | end = buf + len; | 
|  | 6468 |  | 
|  | 6469 | while (wpa_s) { | 
|  | 6470 | res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname); | 
|  | 6471 | if (res < 0 || res >= end - pos) { | 
|  | 6472 | *pos = '\0'; | 
|  | 6473 | break; | 
|  | 6474 | } | 
|  | 6475 | pos += res; | 
|  | 6476 | wpa_s = wpa_s->next; | 
|  | 6477 | } | 
|  | 6478 | return pos - buf; | 
|  | 6479 | } | 
|  | 6480 |  | 
|  | 6481 |  | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6482 | static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global, | 
|  | 6483 | const char *ifname, | 
|  | 6484 | char *cmd, size_t *resp_len) | 
|  | 6485 | { | 
|  | 6486 | struct wpa_supplicant *wpa_s; | 
|  | 6487 |  | 
|  | 6488 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 6489 | if (os_strcmp(ifname, wpa_s->ifname) == 0) | 
|  | 6490 | break; | 
|  | 6491 | } | 
|  | 6492 |  | 
|  | 6493 | if (wpa_s == NULL) { | 
|  | 6494 | char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n"); | 
|  | 6495 | if (resp) | 
|  | 6496 | *resp_len = os_strlen(resp); | 
|  | 6497 | else | 
|  | 6498 | *resp_len = 1; | 
|  | 6499 | return resp; | 
|  | 6500 | } | 
|  | 6501 |  | 
|  | 6502 | return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len); | 
|  | 6503 | } | 
|  | 6504 |  | 
|  | 6505 |  | 
|  | 6506 | static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global, | 
|  | 6507 | char *buf, size_t *resp_len) | 
|  | 6508 | { | 
|  | 6509 | #ifdef CONFIG_P2P | 
|  | 6510 | static const char * cmd[] = { | 
| Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 6511 | "LIST_NETWORKS", | 
|  | 6512 | "SAVE_CONFIG", | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6513 | "P2P_FIND", | 
|  | 6514 | "P2P_STOP_FIND", | 
|  | 6515 | "P2P_LISTEN", | 
|  | 6516 | "P2P_GROUP_ADD", | 
|  | 6517 | "P2P_GET_PASSPHRASE", | 
|  | 6518 | "P2P_SERVICE_UPDATE", | 
|  | 6519 | "P2P_SERVICE_FLUSH", | 
|  | 6520 | "P2P_FLUSH", | 
|  | 6521 | "P2P_CANCEL", | 
|  | 6522 | "P2P_PRESENCE_REQ", | 
|  | 6523 | "P2P_EXT_LISTEN", | 
|  | 6524 | NULL | 
|  | 6525 | }; | 
|  | 6526 | static const char * prefix[] = { | 
| Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 6527 | #ifdef ANDROID | 
| Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 6528 | "DRIVER ", | 
| Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 6529 | #endif /* ANDROID */ | 
| Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 6530 | "GET_NETWORK ", | 
|  | 6531 | "REMOVE_NETWORK ", | 
|  | 6532 | "SET ", | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6533 | "P2P_FIND ", | 
|  | 6534 | "P2P_CONNECT ", | 
|  | 6535 | "P2P_LISTEN ", | 
|  | 6536 | "P2P_GROUP_REMOVE ", | 
|  | 6537 | "P2P_GROUP_ADD ", | 
|  | 6538 | "P2P_PROV_DISC ", | 
|  | 6539 | "P2P_SERV_DISC_REQ ", | 
|  | 6540 | "P2P_SERV_DISC_CANCEL_REQ ", | 
|  | 6541 | "P2P_SERV_DISC_RESP ", | 
|  | 6542 | "P2P_SERV_DISC_EXTERNAL ", | 
|  | 6543 | "P2P_SERVICE_ADD ", | 
|  | 6544 | "P2P_SERVICE_DEL ", | 
|  | 6545 | "P2P_REJECT ", | 
|  | 6546 | "P2P_INVITE ", | 
|  | 6547 | "P2P_PEER ", | 
|  | 6548 | "P2P_SET ", | 
|  | 6549 | "P2P_UNAUTHORIZE ", | 
|  | 6550 | "P2P_PRESENCE_REQ ", | 
|  | 6551 | "P2P_EXT_LISTEN ", | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6552 | "P2P_REMOVE_CLIENT ", | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6553 | NULL | 
|  | 6554 | }; | 
|  | 6555 | int found = 0; | 
|  | 6556 | int i; | 
|  | 6557 |  | 
|  | 6558 | if (global->p2p_init_wpa_s == NULL) | 
|  | 6559 | return NULL; | 
|  | 6560 |  | 
|  | 6561 | for (i = 0; !found && cmd[i]; i++) { | 
|  | 6562 | if (os_strcmp(buf, cmd[i]) == 0) | 
|  | 6563 | found = 1; | 
|  | 6564 | } | 
|  | 6565 |  | 
|  | 6566 | for (i = 0; !found && prefix[i]; i++) { | 
|  | 6567 | if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0) | 
|  | 6568 | found = 1; | 
|  | 6569 | } | 
|  | 6570 |  | 
|  | 6571 | if (found) | 
|  | 6572 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | 
|  | 6573 | buf, resp_len); | 
|  | 6574 | #endif /* CONFIG_P2P */ | 
|  | 6575 | return NULL; | 
|  | 6576 | } | 
|  | 6577 |  | 
|  | 6578 |  | 
|  | 6579 | static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global, | 
|  | 6580 | char *buf, size_t *resp_len) | 
|  | 6581 | { | 
|  | 6582 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 6583 | if (global->p2p_init_wpa_s == NULL) | 
|  | 6584 | return NULL; | 
|  | 6585 | if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 || | 
|  | 6586 | os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) | 
|  | 6587 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | 
|  | 6588 | buf, resp_len); | 
|  | 6589 | #endif /* CONFIG_WIFI_DISPLAY */ | 
|  | 6590 | return NULL; | 
|  | 6591 | } | 
|  | 6592 |  | 
|  | 6593 |  | 
|  | 6594 | static char * wpas_global_ctrl_iface_redir(struct wpa_global *global, | 
|  | 6595 | char *buf, size_t *resp_len) | 
|  | 6596 | { | 
|  | 6597 | char *ret; | 
|  | 6598 |  | 
|  | 6599 | ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len); | 
|  | 6600 | if (ret) | 
|  | 6601 | return ret; | 
|  | 6602 |  | 
|  | 6603 | ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len); | 
|  | 6604 | if (ret) | 
|  | 6605 | return ret; | 
|  | 6606 |  | 
|  | 6607 | return NULL; | 
|  | 6608 | } | 
|  | 6609 |  | 
|  | 6610 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6611 | static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd) | 
|  | 6612 | { | 
|  | 6613 | char *value; | 
|  | 6614 |  | 
|  | 6615 | value = os_strchr(cmd, ' '); | 
|  | 6616 | if (value == NULL) | 
|  | 6617 | return -1; | 
|  | 6618 | *value++ = '\0'; | 
|  | 6619 |  | 
|  | 6620 | wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value); | 
|  | 6621 |  | 
|  | 6622 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 6623 | if (os_strcasecmp(cmd, "wifi_display") == 0) { | 
|  | 6624 | wifi_display_enable(global, !!atoi(value)); | 
|  | 6625 | return 0; | 
|  | 6626 | } | 
|  | 6627 | #endif /* CONFIG_WIFI_DISPLAY */ | 
|  | 6628 |  | 
|  | 6629 | return -1; | 
|  | 6630 | } | 
|  | 6631 |  | 
|  | 6632 |  | 
|  | 6633 | #ifndef CONFIG_NO_CONFIG_WRITE | 
|  | 6634 | static int wpas_global_ctrl_iface_save_config(struct wpa_global *global) | 
|  | 6635 | { | 
|  | 6636 | int ret = 0; | 
|  | 6637 | struct wpa_supplicant *wpa_s; | 
|  | 6638 |  | 
|  | 6639 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 6640 | if (!wpa_s->conf->update_config) { | 
|  | 6641 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)"); | 
|  | 6642 | continue; | 
|  | 6643 | } | 
|  | 6644 |  | 
|  | 6645 | if (wpa_config_write(wpa_s->confname, wpa_s->conf)) { | 
|  | 6646 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration"); | 
|  | 6647 | ret = 1; | 
|  | 6648 | } else { | 
|  | 6649 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated"); | 
|  | 6650 | } | 
|  | 6651 | } | 
|  | 6652 |  | 
|  | 6653 | return ret; | 
|  | 6654 | } | 
|  | 6655 | #endif /* CONFIG_NO_CONFIG_WRITE */ | 
|  | 6656 |  | 
|  | 6657 |  | 
|  | 6658 | static int wpas_global_ctrl_iface_status(struct wpa_global *global, | 
|  | 6659 | char *buf, size_t buflen) | 
|  | 6660 | { | 
|  | 6661 | char *pos, *end; | 
|  | 6662 | int ret; | 
|  | 6663 | struct wpa_supplicant *wpa_s; | 
|  | 6664 |  | 
|  | 6665 | pos = buf; | 
|  | 6666 | end = buf + buflen; | 
|  | 6667 |  | 
|  | 6668 | #ifdef CONFIG_P2P | 
|  | 6669 | if (global->p2p && !global->p2p_disabled) { | 
|  | 6670 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR | 
|  | 6671 | "\n" | 
|  | 6672 | "p2p_state=%s\n", | 
|  | 6673 | MAC2STR(global->p2p_dev_addr), | 
|  | 6674 | p2p_get_state_txt(global->p2p)); | 
|  | 6675 | if (ret < 0 || ret >= end - pos) | 
|  | 6676 | return pos - buf; | 
|  | 6677 | pos += ret; | 
|  | 6678 | } else if (global->p2p) { | 
|  | 6679 | ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n"); | 
|  | 6680 | if (ret < 0 || ret >= end - pos) | 
|  | 6681 | return pos - buf; | 
|  | 6682 | pos += ret; | 
|  | 6683 | } | 
|  | 6684 | #endif /* CONFIG_P2P */ | 
|  | 6685 |  | 
|  | 6686 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 6687 | ret = os_snprintf(pos, end - pos, "wifi_display=%d\n", | 
|  | 6688 | !!global->wifi_display); | 
|  | 6689 | if (ret < 0 || ret >= end - pos) | 
|  | 6690 | return pos - buf; | 
|  | 6691 | pos += ret; | 
|  | 6692 | #endif /* CONFIG_WIFI_DISPLAY */ | 
|  | 6693 |  | 
|  | 6694 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 6695 | ret = os_snprintf(pos, end - pos, "ifname=%s\n" | 
|  | 6696 | "address=" MACSTR "\n", | 
|  | 6697 | wpa_s->ifname, MAC2STR(wpa_s->own_addr)); | 
|  | 6698 | if (ret < 0 || ret >= end - pos) | 
|  | 6699 | return pos - buf; | 
|  | 6700 | pos += ret; | 
|  | 6701 | } | 
|  | 6702 |  | 
|  | 6703 | return pos - buf; | 
|  | 6704 | } | 
|  | 6705 |  | 
|  | 6706 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6707 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, | 
|  | 6708 | char *buf, size_t *resp_len) | 
|  | 6709 | { | 
|  | 6710 | char *reply; | 
|  | 6711 | const int reply_size = 2048; | 
|  | 6712 | int reply_len; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6713 | int level = MSG_DEBUG; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6714 |  | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6715 | if (os_strncmp(buf, "IFNAME=", 7) == 0) { | 
|  | 6716 | char *pos = os_strchr(buf + 7, ' '); | 
|  | 6717 | if (pos) { | 
|  | 6718 | *pos++ = '\0'; | 
|  | 6719 | return wpas_global_ctrl_iface_ifname(global, | 
|  | 6720 | buf + 7, pos, | 
|  | 6721 | resp_len); | 
|  | 6722 | } | 
|  | 6723 | } | 
|  | 6724 |  | 
|  | 6725 | reply = wpas_global_ctrl_iface_redir(global, buf, resp_len); | 
|  | 6726 | if (reply) | 
|  | 6727 | return reply; | 
|  | 6728 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6729 | if (os_strcmp(buf, "PING") == 0) | 
|  | 6730 | level = MSG_EXCESSIVE; | 
|  | 6731 | wpa_hexdump_ascii(level, "RX global ctrl_iface", | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6732 | (const u8 *) buf, os_strlen(buf)); | 
|  | 6733 |  | 
|  | 6734 | reply = os_malloc(reply_size); | 
|  | 6735 | if (reply == NULL) { | 
|  | 6736 | *resp_len = 1; | 
|  | 6737 | return NULL; | 
|  | 6738 | } | 
|  | 6739 |  | 
|  | 6740 | os_memcpy(reply, "OK\n", 3); | 
|  | 6741 | reply_len = 3; | 
|  | 6742 |  | 
|  | 6743 | if (os_strcmp(buf, "PING") == 0) { | 
|  | 6744 | os_memcpy(reply, "PONG\n", 5); | 
|  | 6745 | reply_len = 5; | 
|  | 6746 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { | 
|  | 6747 | if (wpa_supplicant_global_iface_add(global, buf + 14)) | 
|  | 6748 | reply_len = -1; | 
|  | 6749 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { | 
|  | 6750 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) | 
|  | 6751 | reply_len = -1; | 
|  | 6752 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { | 
|  | 6753 | reply_len = wpa_supplicant_global_iface_list( | 
|  | 6754 | global, reply, reply_size); | 
|  | 6755 | } else if (os_strcmp(buf, "INTERFACES") == 0) { | 
|  | 6756 | reply_len = wpa_supplicant_global_iface_interfaces( | 
|  | 6757 | global, reply, reply_size); | 
|  | 6758 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | 
|  | 6759 | wpa_supplicant_terminate_proc(global); | 
|  | 6760 | } else if (os_strcmp(buf, "SUSPEND") == 0) { | 
|  | 6761 | wpas_notify_suspend(global); | 
|  | 6762 | } else if (os_strcmp(buf, "RESUME") == 0) { | 
|  | 6763 | wpas_notify_resume(global); | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6764 | } else if (os_strncmp(buf, "SET ", 4) == 0) { | 
|  | 6765 | if (wpas_global_ctrl_iface_set(global, buf + 4)) | 
|  | 6766 | reply_len = -1; | 
|  | 6767 | #ifndef CONFIG_NO_CONFIG_WRITE | 
|  | 6768 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | 
|  | 6769 | if (wpas_global_ctrl_iface_save_config(global)) | 
|  | 6770 | reply_len = -1; | 
|  | 6771 | #endif /* CONFIG_NO_CONFIG_WRITE */ | 
|  | 6772 | } else if (os_strcmp(buf, "STATUS") == 0) { | 
|  | 6773 | reply_len = wpas_global_ctrl_iface_status(global, reply, | 
|  | 6774 | reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6775 | } else { | 
|  | 6776 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | 
|  | 6777 | reply_len = 16; | 
|  | 6778 | } | 
|  | 6779 |  | 
|  | 6780 | if (reply_len < 0) { | 
|  | 6781 | os_memcpy(reply, "FAIL\n", 5); | 
|  | 6782 | reply_len = 5; | 
|  | 6783 | } | 
|  | 6784 |  | 
|  | 6785 | *resp_len = reply_len; | 
|  | 6786 | return reply; | 
|  | 6787 | } |