Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant / Control interface (shared code for all backends) |
| 3 | * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi> |
| 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" |
| 13 | #include "common/version.h" |
| 14 | #include "common/ieee802_11_defs.h" |
| 15 | #include "common/wpa_ctrl.h" |
| 16 | #include "eap_peer/eap.h" |
| 17 | #include "eapol_supp/eapol_supp_sm.h" |
| 18 | #include "rsn_supp/wpa.h" |
| 19 | #include "rsn_supp/preauth.h" |
| 20 | #include "rsn_supp/pmksa_cache.h" |
| 21 | #include "l2_packet/l2_packet.h" |
| 22 | #include "wps/wps.h" |
| 23 | #include "config.h" |
| 24 | #include "wpa_supplicant_i.h" |
| 25 | #include "driver_i.h" |
| 26 | #include "wps_supplicant.h" |
| 27 | #include "ibss_rsn.h" |
| 28 | #include "ap.h" |
| 29 | #include "p2p_supplicant.h" |
| 30 | #include "p2p/p2p.h" |
| 31 | #include "notify.h" |
| 32 | #include "bss.h" |
| 33 | #include "scan.h" |
| 34 | #include "ctrl_iface.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 35 | #include "interworking.h" |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 36 | #include "blacklist.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 37 | #include "wpas_glue.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 38 | |
| 39 | extern struct wpa_driver_ops *wpa_drivers[]; |
| 40 | |
| 41 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
| 42 | char *buf, int len); |
| 43 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
| 44 | char *buf, int len); |
| 45 | |
| 46 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 47 | static int pno_start(struct wpa_supplicant *wpa_s) |
| 48 | { |
| 49 | int ret; |
| 50 | size_t i, num_ssid; |
| 51 | struct wpa_ssid *ssid; |
| 52 | struct wpa_driver_scan_params params; |
| 53 | |
| 54 | if (wpa_s->pno) |
| 55 | return 0; |
| 56 | |
| 57 | os_memset(¶ms, 0, sizeof(params)); |
| 58 | |
| 59 | num_ssid = 0; |
| 60 | ssid = wpa_s->conf->ssid; |
| 61 | while (ssid) { |
| 62 | if (!ssid->disabled) |
| 63 | num_ssid++; |
| 64 | ssid = ssid->next; |
| 65 | } |
| 66 | if (num_ssid > WPAS_MAX_SCAN_SSIDS) { |
| 67 | wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from " |
| 68 | "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid); |
| 69 | num_ssid = WPAS_MAX_SCAN_SSIDS; |
| 70 | } |
| 71 | |
| 72 | if (num_ssid == 0) { |
| 73 | wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs"); |
| 74 | return -1; |
| 75 | } |
| 76 | |
| 77 | params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) * |
| 78 | num_ssid); |
| 79 | if (params.filter_ssids == NULL) |
| 80 | return -1; |
| 81 | i = 0; |
| 82 | ssid = wpa_s->conf->ssid; |
| 83 | while (ssid) { |
| 84 | if (!ssid->disabled) { |
| 85 | params.ssids[i].ssid = ssid->ssid; |
| 86 | params.ssids[i].ssid_len = ssid->ssid_len; |
| 87 | params.num_ssids++; |
| 88 | os_memcpy(params.filter_ssids[i].ssid, ssid->ssid, |
| 89 | ssid->ssid_len); |
| 90 | params.filter_ssids[i].ssid_len = ssid->ssid_len; |
| 91 | params.num_filter_ssids++; |
| 92 | i++; |
| 93 | if (i == num_ssid) |
| 94 | break; |
| 95 | } |
| 96 | ssid = ssid->next; |
| 97 | } |
| 98 | |
| 99 | ret = wpa_drv_sched_scan(wpa_s, ¶ms, 10 * 1000); |
| 100 | os_free(params.filter_ssids); |
| 101 | if (ret == 0) |
| 102 | wpa_s->pno = 1; |
| 103 | return ret; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | static int pno_stop(struct wpa_supplicant *wpa_s) |
| 108 | { |
| 109 | if (wpa_s->pno) { |
| 110 | wpa_s->pno = 0; |
| 111 | return wpa_drv_stop_sched_scan(wpa_s); |
| 112 | } |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 117 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
| 118 | char *cmd) |
| 119 | { |
| 120 | char *value; |
| 121 | int ret = 0; |
| 122 | |
| 123 | value = os_strchr(cmd, ' '); |
| 124 | if (value == NULL) |
| 125 | return -1; |
| 126 | *value++ = '\0'; |
| 127 | |
| 128 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); |
| 129 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { |
| 130 | eapol_sm_configure(wpa_s->eapol, |
| 131 | atoi(value), -1, -1, -1); |
| 132 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { |
| 133 | eapol_sm_configure(wpa_s->eapol, |
| 134 | -1, atoi(value), -1, -1); |
| 135 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { |
| 136 | eapol_sm_configure(wpa_s->eapol, |
| 137 | -1, -1, atoi(value), -1); |
| 138 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { |
| 139 | eapol_sm_configure(wpa_s->eapol, |
| 140 | -1, -1, -1, atoi(value)); |
| 141 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { |
| 142 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, |
| 143 | atoi(value))) |
| 144 | ret = -1; |
| 145 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == |
| 146 | 0) { |
| 147 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, |
| 148 | atoi(value))) |
| 149 | ret = -1; |
| 150 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { |
| 151 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value))) |
| 152 | ret = -1; |
| 153 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
| 154 | wpa_s->wps_fragment_size = atoi(value); |
| 155 | #ifdef CONFIG_WPS_TESTING |
| 156 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { |
| 157 | long int val; |
| 158 | val = strtol(value, NULL, 0); |
| 159 | if (val < 0 || val > 0xff) { |
| 160 | ret = -1; |
| 161 | wpa_printf(MSG_DEBUG, "WPS: Invalid " |
| 162 | "wps_version_number %ld", val); |
| 163 | } else { |
| 164 | wps_version_number = val; |
| 165 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " |
| 166 | "version %u.%u", |
| 167 | (wps_version_number & 0xf0) >> 4, |
| 168 | wps_version_number & 0x0f); |
| 169 | } |
| 170 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { |
| 171 | wps_testing_dummy_cred = atoi(value); |
| 172 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", |
| 173 | wps_testing_dummy_cred); |
| 174 | #endif /* CONFIG_WPS_TESTING */ |
| 175 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
| 176 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) |
| 177 | ret = -1; |
| 178 | #ifdef CONFIG_TDLS_TESTING |
| 179 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { |
| 180 | extern unsigned int tdls_testing; |
| 181 | tdls_testing = strtol(value, NULL, 0); |
| 182 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); |
| 183 | #endif /* CONFIG_TDLS_TESTING */ |
| 184 | #ifdef CONFIG_TDLS |
| 185 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { |
| 186 | int disabled = atoi(value); |
| 187 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); |
| 188 | if (disabled) { |
| 189 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) |
| 190 | ret = -1; |
| 191 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) |
| 192 | ret = -1; |
| 193 | wpa_tdls_enable(wpa_s->wpa, !disabled); |
| 194 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 195 | } else if (os_strcasecmp(cmd, "pno") == 0) { |
| 196 | if (atoi(value)) |
| 197 | ret = pno_start(wpa_s); |
| 198 | else |
| 199 | ret = pno_stop(wpa_s); |
Jouni Malinen | 21d6bc8 | 2012-04-10 16:17:59 -0700 | [diff] [blame] | 200 | } else if (os_strcasecmp(cmd, "ps") == 0) { |
| 201 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 202 | } else { |
| 203 | value[-1] = '='; |
| 204 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 205 | if (ret == 0) |
| 206 | wpa_supplicant_update_config(wpa_s); |
| 207 | } |
| 208 | |
| 209 | return ret; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
| 214 | char *cmd, char *buf, size_t buflen) |
| 215 | { |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 216 | int res = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 217 | |
| 218 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); |
| 219 | |
| 220 | if (os_strcmp(cmd, "version") == 0) { |
| 221 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 222 | } else if (os_strcasecmp(cmd, "country") == 0) { |
| 223 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) |
| 224 | res = os_snprintf(buf, buflen, "%c%c", |
| 225 | wpa_s->conf->country[0], |
| 226 | wpa_s->conf->country[1]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 229 | if (res < 0 || (unsigned int) res >= buflen) |
| 230 | return -1; |
| 231 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | |
| 235 | #ifdef IEEE8021X_EAPOL |
| 236 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
| 237 | char *addr) |
| 238 | { |
| 239 | u8 bssid[ETH_ALEN]; |
| 240 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 241 | |
| 242 | if (hwaddr_aton(addr, bssid)) { |
| 243 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " |
| 244 | "'%s'", addr); |
| 245 | return -1; |
| 246 | } |
| 247 | |
| 248 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); |
| 249 | rsn_preauth_deinit(wpa_s->wpa); |
| 250 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) |
| 251 | return -1; |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | #endif /* IEEE8021X_EAPOL */ |
| 256 | |
| 257 | |
| 258 | #ifdef CONFIG_PEERKEY |
| 259 | /* MLME-STKSTART.request(peer) */ |
| 260 | static int wpa_supplicant_ctrl_iface_stkstart( |
| 261 | struct wpa_supplicant *wpa_s, char *addr) |
| 262 | { |
| 263 | u8 peer[ETH_ALEN]; |
| 264 | |
| 265 | if (hwaddr_aton(addr, peer)) { |
| 266 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid " |
| 267 | "address '%s'", addr); |
| 268 | return -1; |
| 269 | } |
| 270 | |
| 271 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR, |
| 272 | MAC2STR(peer)); |
| 273 | |
| 274 | return wpa_sm_stkstart(wpa_s->wpa, peer); |
| 275 | } |
| 276 | #endif /* CONFIG_PEERKEY */ |
| 277 | |
| 278 | |
| 279 | #ifdef CONFIG_TDLS |
| 280 | |
| 281 | static int wpa_supplicant_ctrl_iface_tdls_discover( |
| 282 | struct wpa_supplicant *wpa_s, char *addr) |
| 283 | { |
| 284 | u8 peer[ETH_ALEN]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 285 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 286 | |
| 287 | if (hwaddr_aton(addr, peer)) { |
| 288 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " |
| 289 | "address '%s'", addr); |
| 290 | return -1; |
| 291 | } |
| 292 | |
| 293 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, |
| 294 | MAC2STR(peer)); |
| 295 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 296 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 297 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); |
| 298 | else |
| 299 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); |
| 300 | |
| 301 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | |
| 305 | static int wpa_supplicant_ctrl_iface_tdls_setup( |
| 306 | struct wpa_supplicant *wpa_s, char *addr) |
| 307 | { |
| 308 | u8 peer[ETH_ALEN]; |
| 309 | int ret; |
| 310 | |
| 311 | if (hwaddr_aton(addr, peer)) { |
| 312 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " |
| 313 | "address '%s'", addr); |
| 314 | return -1; |
| 315 | } |
| 316 | |
| 317 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, |
| 318 | MAC2STR(peer)); |
| 319 | |
| 320 | ret = wpa_tdls_reneg(wpa_s->wpa, peer); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 321 | if (ret) { |
| 322 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 323 | ret = wpa_tdls_start(wpa_s->wpa, peer); |
| 324 | else |
| 325 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); |
| 326 | } |
| 327 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 328 | return ret; |
| 329 | } |
| 330 | |
| 331 | |
| 332 | static int wpa_supplicant_ctrl_iface_tdls_teardown( |
| 333 | struct wpa_supplicant *wpa_s, char *addr) |
| 334 | { |
| 335 | u8 peer[ETH_ALEN]; |
| 336 | |
| 337 | if (hwaddr_aton(addr, peer)) { |
| 338 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " |
| 339 | "address '%s'", addr); |
| 340 | return -1; |
| 341 | } |
| 342 | |
| 343 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, |
| 344 | MAC2STR(peer)); |
| 345 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 346 | return wpa_tdls_teardown_link(wpa_s->wpa, peer, |
| 347 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | #endif /* CONFIG_TDLS */ |
| 351 | |
| 352 | |
| 353 | #ifdef CONFIG_IEEE80211R |
| 354 | static int wpa_supplicant_ctrl_iface_ft_ds( |
| 355 | struct wpa_supplicant *wpa_s, char *addr) |
| 356 | { |
| 357 | u8 target_ap[ETH_ALEN]; |
| 358 | struct wpa_bss *bss; |
| 359 | const u8 *mdie; |
| 360 | |
| 361 | if (hwaddr_aton(addr, target_ap)) { |
| 362 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " |
| 363 | "address '%s'", addr); |
| 364 | return -1; |
| 365 | } |
| 366 | |
| 367 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); |
| 368 | |
| 369 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
| 370 | if (bss) |
| 371 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
| 372 | else |
| 373 | mdie = NULL; |
| 374 | |
| 375 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); |
| 376 | } |
| 377 | #endif /* CONFIG_IEEE80211R */ |
| 378 | |
| 379 | |
| 380 | #ifdef CONFIG_WPS |
| 381 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, |
| 382 | char *cmd) |
| 383 | { |
| 384 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 385 | #ifdef CONFIG_P2P |
| 386 | u8 p2p_dev_addr[ETH_ALEN]; |
| 387 | #endif /* CONFIG_P2P */ |
| 388 | #ifdef CONFIG_AP |
| 389 | u8 *_p2p_dev_addr = NULL; |
| 390 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 391 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 392 | if (cmd == NULL || os_strcmp(cmd, "any") == 0) { |
| 393 | _bssid = NULL; |
| 394 | #ifdef CONFIG_P2P |
| 395 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { |
| 396 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { |
| 397 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " |
| 398 | "P2P Device Address '%s'", |
| 399 | cmd + 13); |
| 400 | return -1; |
| 401 | } |
| 402 | _p2p_dev_addr = p2p_dev_addr; |
| 403 | #endif /* CONFIG_P2P */ |
| 404 | } else if (hwaddr_aton(cmd, bssid)) { |
| 405 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
| 406 | cmd); |
| 407 | return -1; |
| 408 | } |
| 409 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 410 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 411 | if (wpa_s->ap_iface) |
| 412 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
| 413 | #endif /* CONFIG_AP */ |
| 414 | |
| 415 | return wpas_wps_start_pbc(wpa_s, _bssid, 0); |
| 416 | } |
| 417 | |
| 418 | |
| 419 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, |
| 420 | char *cmd, char *buf, |
| 421 | size_t buflen) |
| 422 | { |
| 423 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
| 424 | char *pin; |
| 425 | int ret; |
| 426 | |
| 427 | pin = os_strchr(cmd, ' '); |
| 428 | if (pin) |
| 429 | *pin++ = '\0'; |
| 430 | |
| 431 | if (os_strcmp(cmd, "any") == 0) |
| 432 | _bssid = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 433 | else if (os_strcmp(cmd, "get") == 0) { |
| 434 | ret = wps_generate_pin(); |
| 435 | goto done; |
| 436 | } else if (hwaddr_aton(cmd, bssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 437 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
| 438 | cmd); |
| 439 | return -1; |
| 440 | } |
| 441 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 442 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 443 | if (wpa_s->ap_iface) |
| 444 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, |
| 445 | buf, buflen); |
| 446 | #endif /* CONFIG_AP */ |
| 447 | |
| 448 | if (pin) { |
| 449 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
| 450 | DEV_PW_DEFAULT); |
| 451 | if (ret < 0) |
| 452 | return -1; |
| 453 | ret = os_snprintf(buf, buflen, "%s", pin); |
| 454 | if (ret < 0 || (size_t) ret >= buflen) |
| 455 | return -1; |
| 456 | return ret; |
| 457 | } |
| 458 | |
| 459 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
| 460 | if (ret < 0) |
| 461 | return -1; |
| 462 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 463 | done: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 464 | /* Return the generated PIN */ |
| 465 | ret = os_snprintf(buf, buflen, "%08d", ret); |
| 466 | if (ret < 0 || (size_t) ret >= buflen) |
| 467 | return -1; |
| 468 | return ret; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
| 473 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 474 | { |
| 475 | char pin[9]; |
| 476 | size_t len; |
| 477 | char *pos; |
| 478 | int ret; |
| 479 | |
| 480 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", |
| 481 | (u8 *) cmd, os_strlen(cmd)); |
| 482 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { |
| 483 | if (*pos < '0' || *pos > '9') |
| 484 | continue; |
| 485 | pin[len++] = *pos; |
| 486 | if (len == 9) { |
| 487 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); |
| 488 | return -1; |
| 489 | } |
| 490 | } |
| 491 | if (len != 4 && len != 8) { |
| 492 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); |
| 493 | return -1; |
| 494 | } |
| 495 | pin[len] = '\0'; |
| 496 | |
| 497 | if (len == 8) { |
| 498 | unsigned int pin_val; |
| 499 | pin_val = atoi(pin); |
| 500 | if (!wps_pin_valid(pin_val)) { |
| 501 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); |
| 502 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); |
| 503 | if (ret < 0 || (size_t) ret >= buflen) |
| 504 | return -1; |
| 505 | return ret; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | ret = os_snprintf(buf, buflen, "%s", pin); |
| 510 | if (ret < 0 || (size_t) ret >= buflen) |
| 511 | return -1; |
| 512 | |
| 513 | return ret; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | #ifdef CONFIG_WPS_OOB |
| 518 | static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s, |
| 519 | char *cmd) |
| 520 | { |
| 521 | char *path, *method, *name; |
| 522 | |
| 523 | path = os_strchr(cmd, ' '); |
| 524 | if (path == NULL) |
| 525 | return -1; |
| 526 | *path++ = '\0'; |
| 527 | |
| 528 | method = os_strchr(path, ' '); |
| 529 | if (method == NULL) |
| 530 | return -1; |
| 531 | *method++ = '\0'; |
| 532 | |
| 533 | name = os_strchr(method, ' '); |
| 534 | if (name != NULL) |
| 535 | *name++ = '\0'; |
| 536 | |
| 537 | return wpas_wps_start_oob(wpa_s, cmd, path, method, name); |
| 538 | } |
| 539 | #endif /* CONFIG_WPS_OOB */ |
| 540 | |
| 541 | |
| 542 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
| 543 | char *cmd) |
| 544 | { |
| 545 | u8 bssid[ETH_ALEN]; |
| 546 | char *pin; |
| 547 | char *new_ssid; |
| 548 | char *new_auth; |
| 549 | char *new_encr; |
| 550 | char *new_key; |
| 551 | struct wps_new_ap_settings ap; |
| 552 | |
| 553 | pin = os_strchr(cmd, ' '); |
| 554 | if (pin == NULL) |
| 555 | return -1; |
| 556 | *pin++ = '\0'; |
| 557 | |
| 558 | if (hwaddr_aton(cmd, bssid)) { |
| 559 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
| 560 | cmd); |
| 561 | return -1; |
| 562 | } |
| 563 | |
| 564 | new_ssid = os_strchr(pin, ' '); |
| 565 | if (new_ssid == NULL) |
| 566 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
| 567 | *new_ssid++ = '\0'; |
| 568 | |
| 569 | new_auth = os_strchr(new_ssid, ' '); |
| 570 | if (new_auth == NULL) |
| 571 | return -1; |
| 572 | *new_auth++ = '\0'; |
| 573 | |
| 574 | new_encr = os_strchr(new_auth, ' '); |
| 575 | if (new_encr == NULL) |
| 576 | return -1; |
| 577 | *new_encr++ = '\0'; |
| 578 | |
| 579 | new_key = os_strchr(new_encr, ' '); |
| 580 | if (new_key == NULL) |
| 581 | return -1; |
| 582 | *new_key++ = '\0'; |
| 583 | |
| 584 | os_memset(&ap, 0, sizeof(ap)); |
| 585 | ap.ssid_hex = new_ssid; |
| 586 | ap.auth = new_auth; |
| 587 | ap.encr = new_encr; |
| 588 | ap.key_hex = new_key; |
| 589 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
| 590 | } |
| 591 | |
| 592 | |
| 593 | #ifdef CONFIG_AP |
| 594 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, |
| 595 | char *cmd, char *buf, |
| 596 | size_t buflen) |
| 597 | { |
| 598 | int timeout = 300; |
| 599 | char *pos; |
| 600 | const char *pin_txt; |
| 601 | |
| 602 | if (!wpa_s->ap_iface) |
| 603 | return -1; |
| 604 | |
| 605 | pos = os_strchr(cmd, ' '); |
| 606 | if (pos) |
| 607 | *pos++ = '\0'; |
| 608 | |
| 609 | if (os_strcmp(cmd, "disable") == 0) { |
| 610 | wpas_wps_ap_pin_disable(wpa_s); |
| 611 | return os_snprintf(buf, buflen, "OK\n"); |
| 612 | } |
| 613 | |
| 614 | if (os_strcmp(cmd, "random") == 0) { |
| 615 | if (pos) |
| 616 | timeout = atoi(pos); |
| 617 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); |
| 618 | if (pin_txt == NULL) |
| 619 | return -1; |
| 620 | return os_snprintf(buf, buflen, "%s", pin_txt); |
| 621 | } |
| 622 | |
| 623 | if (os_strcmp(cmd, "get") == 0) { |
| 624 | pin_txt = wpas_wps_ap_pin_get(wpa_s); |
| 625 | if (pin_txt == NULL) |
| 626 | return -1; |
| 627 | return os_snprintf(buf, buflen, "%s", pin_txt); |
| 628 | } |
| 629 | |
| 630 | if (os_strcmp(cmd, "set") == 0) { |
| 631 | char *pin; |
| 632 | if (pos == NULL) |
| 633 | return -1; |
| 634 | pin = pos; |
| 635 | pos = os_strchr(pos, ' '); |
| 636 | if (pos) { |
| 637 | *pos++ = '\0'; |
| 638 | timeout = atoi(pos); |
| 639 | } |
| 640 | if (os_strlen(pin) > buflen) |
| 641 | return -1; |
| 642 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) |
| 643 | return -1; |
| 644 | return os_snprintf(buf, buflen, "%s", pin); |
| 645 | } |
| 646 | |
| 647 | return -1; |
| 648 | } |
| 649 | #endif /* CONFIG_AP */ |
| 650 | |
| 651 | |
| 652 | #ifdef CONFIG_WPS_ER |
| 653 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, |
| 654 | char *cmd) |
| 655 | { |
| 656 | char *uuid = cmd, *pin, *pos; |
| 657 | u8 addr_buf[ETH_ALEN], *addr = NULL; |
| 658 | pin = os_strchr(uuid, ' '); |
| 659 | if (pin == NULL) |
| 660 | return -1; |
| 661 | *pin++ = '\0'; |
| 662 | pos = os_strchr(pin, ' '); |
| 663 | if (pos) { |
| 664 | *pos++ = '\0'; |
| 665 | if (hwaddr_aton(pos, addr_buf) == 0) |
| 666 | addr = addr_buf; |
| 667 | } |
| 668 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); |
| 669 | } |
| 670 | |
| 671 | |
| 672 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, |
| 673 | char *cmd) |
| 674 | { |
| 675 | char *uuid = cmd, *pin; |
| 676 | pin = os_strchr(uuid, ' '); |
| 677 | if (pin == NULL) |
| 678 | return -1; |
| 679 | *pin++ = '\0'; |
| 680 | return wpas_wps_er_learn(wpa_s, uuid, pin); |
| 681 | } |
| 682 | |
| 683 | |
| 684 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
| 685 | struct wpa_supplicant *wpa_s, char *cmd) |
| 686 | { |
| 687 | char *uuid = cmd, *id; |
| 688 | id = os_strchr(uuid, ' '); |
| 689 | if (id == NULL) |
| 690 | return -1; |
| 691 | *id++ = '\0'; |
| 692 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); |
| 693 | } |
| 694 | |
| 695 | |
| 696 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
| 697 | struct wpa_supplicant *wpa_s, char *cmd) |
| 698 | { |
| 699 | char *pin; |
| 700 | char *new_ssid; |
| 701 | char *new_auth; |
| 702 | char *new_encr; |
| 703 | char *new_key; |
| 704 | struct wps_new_ap_settings ap; |
| 705 | |
| 706 | pin = os_strchr(cmd, ' '); |
| 707 | if (pin == NULL) |
| 708 | return -1; |
| 709 | *pin++ = '\0'; |
| 710 | |
| 711 | new_ssid = os_strchr(pin, ' '); |
| 712 | if (new_ssid == NULL) |
| 713 | return -1; |
| 714 | *new_ssid++ = '\0'; |
| 715 | |
| 716 | new_auth = os_strchr(new_ssid, ' '); |
| 717 | if (new_auth == NULL) |
| 718 | return -1; |
| 719 | *new_auth++ = '\0'; |
| 720 | |
| 721 | new_encr = os_strchr(new_auth, ' '); |
| 722 | if (new_encr == NULL) |
| 723 | return -1; |
| 724 | *new_encr++ = '\0'; |
| 725 | |
| 726 | new_key = os_strchr(new_encr, ' '); |
| 727 | if (new_key == NULL) |
| 728 | return -1; |
| 729 | *new_key++ = '\0'; |
| 730 | |
| 731 | os_memset(&ap, 0, sizeof(ap)); |
| 732 | ap.ssid_hex = new_ssid; |
| 733 | ap.auth = new_auth; |
| 734 | ap.encr = new_encr; |
| 735 | ap.key_hex = new_key; |
| 736 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); |
| 737 | } |
| 738 | #endif /* CONFIG_WPS_ER */ |
| 739 | |
| 740 | #endif /* CONFIG_WPS */ |
| 741 | |
| 742 | |
| 743 | #ifdef CONFIG_IBSS_RSN |
| 744 | static int wpa_supplicant_ctrl_iface_ibss_rsn( |
| 745 | struct wpa_supplicant *wpa_s, char *addr) |
| 746 | { |
| 747 | u8 peer[ETH_ALEN]; |
| 748 | |
| 749 | if (hwaddr_aton(addr, peer)) { |
| 750 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " |
| 751 | "address '%s'", addr); |
| 752 | return -1; |
| 753 | } |
| 754 | |
| 755 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, |
| 756 | MAC2STR(peer)); |
| 757 | |
| 758 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); |
| 759 | } |
| 760 | #endif /* CONFIG_IBSS_RSN */ |
| 761 | |
| 762 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 763 | int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant *wpa_s, |
| 764 | struct wpa_ssid *ssid, |
| 765 | const char *field, |
| 766 | const char *value) |
| 767 | { |
| 768 | #ifdef IEEE8021X_EAPOL |
| 769 | struct eap_peer_config *eap = &ssid->eap; |
| 770 | |
| 771 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: response handle field=%s", field); |
| 772 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: response value", |
| 773 | (const u8 *) value, os_strlen(value)); |
| 774 | |
| 775 | switch (wpa_supplicant_ctrl_req_from_string(field)) { |
| 776 | case WPA_CTRL_REQ_EAP_IDENTITY: |
| 777 | os_free(eap->identity); |
| 778 | eap->identity = (u8 *) os_strdup(value); |
| 779 | eap->identity_len = os_strlen(value); |
| 780 | eap->pending_req_identity = 0; |
| 781 | if (ssid == wpa_s->current_ssid) |
| 782 | wpa_s->reassociate = 1; |
| 783 | break; |
| 784 | case WPA_CTRL_REQ_EAP_PASSWORD: |
| 785 | os_free(eap->password); |
| 786 | eap->password = (u8 *) os_strdup(value); |
| 787 | eap->password_len = os_strlen(value); |
| 788 | eap->pending_req_password = 0; |
| 789 | if (ssid == wpa_s->current_ssid) |
| 790 | wpa_s->reassociate = 1; |
| 791 | break; |
| 792 | case WPA_CTRL_REQ_EAP_NEW_PASSWORD: |
| 793 | os_free(eap->new_password); |
| 794 | eap->new_password = (u8 *) os_strdup(value); |
| 795 | eap->new_password_len = os_strlen(value); |
| 796 | eap->pending_req_new_password = 0; |
| 797 | if (ssid == wpa_s->current_ssid) |
| 798 | wpa_s->reassociate = 1; |
| 799 | break; |
| 800 | case WPA_CTRL_REQ_EAP_PIN: |
| 801 | os_free(eap->pin); |
| 802 | eap->pin = os_strdup(value); |
| 803 | eap->pending_req_pin = 0; |
| 804 | if (ssid == wpa_s->current_ssid) |
| 805 | wpa_s->reassociate = 1; |
| 806 | break; |
| 807 | case WPA_CTRL_REQ_EAP_OTP: |
| 808 | os_free(eap->otp); |
| 809 | eap->otp = (u8 *) os_strdup(value); |
| 810 | eap->otp_len = os_strlen(value); |
| 811 | os_free(eap->pending_req_otp); |
| 812 | eap->pending_req_otp = NULL; |
| 813 | eap->pending_req_otp_len = 0; |
| 814 | break; |
| 815 | case WPA_CTRL_REQ_EAP_PASSPHRASE: |
| 816 | os_free(eap->private_key_passwd); |
| 817 | eap->private_key_passwd = (u8 *) os_strdup(value); |
| 818 | eap->pending_req_passphrase = 0; |
| 819 | if (ssid == wpa_s->current_ssid) |
| 820 | wpa_s->reassociate = 1; |
| 821 | break; |
| 822 | default: |
| 823 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", field); |
| 824 | return -1; |
| 825 | } |
| 826 | |
| 827 | return 0; |
| 828 | #else /* IEEE8021X_EAPOL */ |
| 829 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: IEEE 802.1X not included"); |
| 830 | return -1; |
| 831 | #endif /* IEEE8021X_EAPOL */ |
| 832 | } |
| 833 | |
| 834 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 835 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
| 836 | char *rsp) |
| 837 | { |
| 838 | #ifdef IEEE8021X_EAPOL |
| 839 | char *pos, *id_pos; |
| 840 | int id; |
| 841 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 842 | |
| 843 | pos = os_strchr(rsp, '-'); |
| 844 | if (pos == NULL) |
| 845 | return -1; |
| 846 | *pos++ = '\0'; |
| 847 | id_pos = pos; |
| 848 | pos = os_strchr(pos, ':'); |
| 849 | if (pos == NULL) |
| 850 | return -1; |
| 851 | *pos++ = '\0'; |
| 852 | id = atoi(id_pos); |
| 853 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); |
| 854 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 855 | (u8 *) pos, os_strlen(pos)); |
| 856 | |
| 857 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 858 | if (ssid == NULL) { |
| 859 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 860 | "to update", id); |
| 861 | return -1; |
| 862 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 863 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 864 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, |
| 865 | pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 866 | #else /* IEEE8021X_EAPOL */ |
| 867 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); |
| 868 | return -1; |
| 869 | #endif /* IEEE8021X_EAPOL */ |
| 870 | } |
| 871 | |
| 872 | |
| 873 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, |
| 874 | const char *params, |
| 875 | char *buf, size_t buflen) |
| 876 | { |
| 877 | char *pos, *end, tmp[30]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 878 | int res, verbose, wps, ret; |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 879 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 880 | verbose = os_strcmp(params, "-VERBOSE") == 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 881 | wps = os_strcmp(params, "-WPS") == 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 882 | pos = buf; |
| 883 | end = buf + buflen; |
| 884 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { |
| 885 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 886 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", |
| 887 | MAC2STR(wpa_s->bssid)); |
| 888 | if (ret < 0 || ret >= end - pos) |
| 889 | return pos - buf; |
| 890 | pos += ret; |
| 891 | if (ssid) { |
| 892 | u8 *_ssid = ssid->ssid; |
| 893 | size_t ssid_len = ssid->ssid_len; |
| 894 | u8 ssid_buf[MAX_SSID_LEN]; |
| 895 | if (ssid_len == 0) { |
| 896 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); |
| 897 | if (_res < 0) |
| 898 | ssid_len = 0; |
| 899 | else |
| 900 | ssid_len = _res; |
| 901 | _ssid = ssid_buf; |
| 902 | } |
| 903 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", |
| 904 | wpa_ssid_txt(_ssid, ssid_len), |
| 905 | ssid->id); |
| 906 | if (ret < 0 || ret >= end - pos) |
| 907 | return pos - buf; |
| 908 | pos += ret; |
| 909 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 910 | if (wps && ssid->passphrase && |
| 911 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && |
| 912 | (ssid->mode == WPAS_MODE_AP || |
| 913 | ssid->mode == WPAS_MODE_P2P_GO)) { |
| 914 | ret = os_snprintf(pos, end - pos, |
| 915 | "passphrase=%s\n", |
| 916 | ssid->passphrase); |
| 917 | if (ret < 0 || ret >= end - pos) |
| 918 | return pos - buf; |
| 919 | pos += ret; |
| 920 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 921 | if (ssid->id_str) { |
| 922 | ret = os_snprintf(pos, end - pos, |
| 923 | "id_str=%s\n", |
| 924 | ssid->id_str); |
| 925 | if (ret < 0 || ret >= end - pos) |
| 926 | return pos - buf; |
| 927 | pos += ret; |
| 928 | } |
| 929 | |
| 930 | switch (ssid->mode) { |
| 931 | case WPAS_MODE_INFRA: |
| 932 | ret = os_snprintf(pos, end - pos, |
| 933 | "mode=station\n"); |
| 934 | break; |
| 935 | case WPAS_MODE_IBSS: |
| 936 | ret = os_snprintf(pos, end - pos, |
| 937 | "mode=IBSS\n"); |
| 938 | break; |
| 939 | case WPAS_MODE_AP: |
| 940 | ret = os_snprintf(pos, end - pos, |
| 941 | "mode=AP\n"); |
| 942 | break; |
| 943 | case WPAS_MODE_P2P_GO: |
| 944 | ret = os_snprintf(pos, end - pos, |
| 945 | "mode=P2P GO\n"); |
| 946 | break; |
| 947 | case WPAS_MODE_P2P_GROUP_FORMATION: |
| 948 | ret = os_snprintf(pos, end - pos, |
| 949 | "mode=P2P GO - group " |
| 950 | "formation\n"); |
| 951 | break; |
| 952 | default: |
| 953 | ret = 0; |
| 954 | break; |
| 955 | } |
| 956 | if (ret < 0 || ret >= end - pos) |
| 957 | return pos - buf; |
| 958 | pos += ret; |
| 959 | } |
| 960 | |
| 961 | #ifdef CONFIG_AP |
| 962 | if (wpa_s->ap_iface) { |
| 963 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, |
| 964 | end - pos, |
| 965 | verbose); |
| 966 | } else |
| 967 | #endif /* CONFIG_AP */ |
| 968 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| 969 | } |
| 970 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", |
| 971 | wpa_supplicant_state_txt(wpa_s->wpa_state)); |
| 972 | if (ret < 0 || ret >= end - pos) |
| 973 | return pos - buf; |
| 974 | pos += ret; |
| 975 | |
| 976 | if (wpa_s->l2 && |
| 977 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { |
| 978 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); |
| 979 | if (ret < 0 || ret >= end - pos) |
| 980 | return pos - buf; |
| 981 | pos += ret; |
| 982 | } |
| 983 | |
| 984 | #ifdef CONFIG_P2P |
| 985 | if (wpa_s->global->p2p) { |
| 986 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
| 987 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); |
| 988 | if (ret < 0 || ret >= end - pos) |
| 989 | return pos - buf; |
| 990 | pos += ret; |
| 991 | } |
| 992 | #endif /* CONFIG_P2P */ |
| 993 | |
| 994 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", |
| 995 | MAC2STR(wpa_s->own_addr)); |
| 996 | if (ret < 0 || ret >= end - pos) |
| 997 | return pos - buf; |
| 998 | pos += ret; |
| 999 | |
| 1000 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
| 1001 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 1002 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
| 1003 | verbose); |
| 1004 | if (res >= 0) |
| 1005 | pos += res; |
| 1006 | } |
| 1007 | |
| 1008 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| 1009 | if (res >= 0) |
| 1010 | pos += res; |
| 1011 | |
Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 1012 | #ifdef ANDROID |
| 1013 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE |
Irfan Sheriff | f20a443 | 2012-04-16 16:48:34 -0700 | [diff] [blame] | 1014 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", |
Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 1015 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, |
Irfan Sheriff | f20a443 | 2012-04-16 16:48:34 -0700 | [diff] [blame] | 1016 | wpa_s->wpa_state, |
| 1017 | MAC2STR(wpa_s->pending_bssid), |
Irfan Sheriff | 1029477 | 2012-05-11 11:23:35 -0700 | [diff] [blame] | 1018 | wpa_s->current_ssid ? wpa_ssid_txt(wpa_s->current_ssid->ssid, |
| 1019 | wpa_s->current_ssid->ssid_len) : ""); |
Irfan Sheriff | bf5edf4 | 2012-01-11 16:54:57 -0800 | [diff] [blame] | 1020 | if (wpa_s->wpa_state == WPA_COMPLETED) { |
| 1021 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1022 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- connection to " |
| 1023 | MACSTR " completed %s [id=%d id_str=%s]", |
| 1024 | MAC2STR(wpa_s->bssid), wpa_s->reassociated_connection ? |
| 1025 | "(reauth)" : "(auth)", |
| 1026 | ssid ? ssid->id : -1, |
| 1027 | ssid && ssid->id_str ? ssid->id_str : ""); |
| 1028 | } |
Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 1029 | #endif /* ANDROID */ |
| 1030 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1031 | return pos - buf; |
| 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, |
| 1036 | char *cmd) |
| 1037 | { |
| 1038 | char *pos; |
| 1039 | int id; |
| 1040 | struct wpa_ssid *ssid; |
| 1041 | u8 bssid[ETH_ALEN]; |
| 1042 | |
| 1043 | /* cmd: "<network id> <BSSID>" */ |
| 1044 | pos = os_strchr(cmd, ' '); |
| 1045 | if (pos == NULL) |
| 1046 | return -1; |
| 1047 | *pos++ = '\0'; |
| 1048 | id = atoi(cmd); |
| 1049 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); |
| 1050 | if (hwaddr_aton(pos, bssid)) { |
| 1051 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); |
| 1052 | return -1; |
| 1053 | } |
| 1054 | |
| 1055 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 1056 | if (ssid == NULL) { |
| 1057 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 1058 | "to update", id); |
| 1059 | return -1; |
| 1060 | } |
| 1061 | |
| 1062 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); |
| 1063 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
| 1064 | |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
| 1068 | |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1069 | static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1070 | char *cmd, char *buf, |
| 1071 | size_t buflen) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1072 | { |
| 1073 | u8 bssid[ETH_ALEN]; |
| 1074 | struct wpa_blacklist *e; |
| 1075 | char *pos, *end; |
| 1076 | int ret; |
| 1077 | |
| 1078 | /* cmd: "BLACKLIST [<BSSID>]" */ |
| 1079 | if (*cmd == '\0') { |
| 1080 | pos = buf; |
| 1081 | end = buf + buflen; |
| 1082 | e = wpa_s->blacklist; |
| 1083 | while (e) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1084 | ret = os_snprintf(pos, end - pos, MACSTR "\n", |
| 1085 | MAC2STR(e->bssid)); |
| 1086 | if (ret < 0 || ret >= end - pos) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1087 | return pos - buf; |
| 1088 | pos += ret; |
| 1089 | e = e->next; |
| 1090 | } |
| 1091 | return pos - buf; |
| 1092 | } |
| 1093 | |
| 1094 | cmd++; |
| 1095 | if (os_strncmp(cmd, "clear", 5) == 0) { |
| 1096 | wpa_blacklist_clear(wpa_s); |
| 1097 | os_memcpy(buf, "OK\n", 3); |
| 1098 | return 3; |
| 1099 | } |
| 1100 | |
| 1101 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); |
| 1102 | if (hwaddr_aton(cmd, bssid)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1103 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1104 | return -1; |
| 1105 | } |
| 1106 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1107 | /* |
| 1108 | * Add the BSSID twice, so its count will be 2, causing it to be |
| 1109 | * skipped when processing scan results. |
| 1110 | */ |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1111 | ret = wpa_blacklist_add(wpa_s, bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1112 | if (ret != 0) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1113 | return -1; |
| 1114 | ret = wpa_blacklist_add(wpa_s, bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1115 | if (ret != 0) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 1116 | return -1; |
| 1117 | os_memcpy(buf, "OK\n", 3); |
| 1118 | return 3; |
| 1119 | } |
| 1120 | |
| 1121 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1122 | extern int wpa_debug_level; |
| 1123 | extern int wpa_debug_timestamp; |
| 1124 | |
| 1125 | static const char * debug_level_str(int level) |
| 1126 | { |
| 1127 | switch (level) { |
| 1128 | case MSG_EXCESSIVE: |
| 1129 | return "EXCESSIVE"; |
| 1130 | case MSG_MSGDUMP: |
| 1131 | return "MSGDUMP"; |
| 1132 | case MSG_DEBUG: |
| 1133 | return "DEBUG"; |
| 1134 | case MSG_INFO: |
| 1135 | return "INFO"; |
| 1136 | case MSG_WARNING: |
| 1137 | return "WARNING"; |
| 1138 | case MSG_ERROR: |
| 1139 | return "ERROR"; |
| 1140 | default: |
| 1141 | return "?"; |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | |
| 1146 | static int str_to_debug_level(const char *s) |
| 1147 | { |
| 1148 | if (os_strcasecmp(s, "EXCESSIVE") == 0) |
| 1149 | return MSG_EXCESSIVE; |
| 1150 | if (os_strcasecmp(s, "MSGDUMP") == 0) |
| 1151 | return MSG_MSGDUMP; |
| 1152 | if (os_strcasecmp(s, "DEBUG") == 0) |
| 1153 | return MSG_DEBUG; |
| 1154 | if (os_strcasecmp(s, "INFO") == 0) |
| 1155 | return MSG_INFO; |
| 1156 | if (os_strcasecmp(s, "WARNING") == 0) |
| 1157 | return MSG_WARNING; |
| 1158 | if (os_strcasecmp(s, "ERROR") == 0) |
| 1159 | return MSG_ERROR; |
| 1160 | return -1; |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, |
| 1165 | char *cmd, char *buf, |
| 1166 | size_t buflen) |
| 1167 | { |
| 1168 | char *pos, *end, *stamp; |
| 1169 | int ret; |
| 1170 | |
| 1171 | if (cmd == NULL) { |
| 1172 | return -1; |
| 1173 | } |
| 1174 | |
| 1175 | /* cmd: "LOG_LEVEL [<level>]" */ |
| 1176 | if (*cmd == '\0') { |
| 1177 | pos = buf; |
| 1178 | end = buf + buflen; |
| 1179 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" |
| 1180 | "Timestamp: %d\n", |
| 1181 | debug_level_str(wpa_debug_level), |
| 1182 | wpa_debug_timestamp); |
| 1183 | if (ret < 0 || ret >= end - pos) |
| 1184 | ret = 0; |
| 1185 | |
| 1186 | return ret; |
| 1187 | } |
| 1188 | |
| 1189 | while (*cmd == ' ') |
| 1190 | cmd++; |
| 1191 | |
| 1192 | stamp = os_strchr(cmd, ' '); |
| 1193 | if (stamp) { |
| 1194 | *stamp++ = '\0'; |
| 1195 | while (*stamp == ' ') { |
| 1196 | stamp++; |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | if (cmd && os_strlen(cmd)) { |
| 1201 | int level = str_to_debug_level(cmd); |
| 1202 | if (level < 0) |
| 1203 | return -1; |
| 1204 | wpa_debug_level = level; |
| 1205 | } |
| 1206 | |
| 1207 | if (stamp && os_strlen(stamp)) |
| 1208 | wpa_debug_timestamp = atoi(stamp); |
| 1209 | |
| 1210 | os_memcpy(buf, "OK\n", 3); |
| 1211 | return 3; |
| 1212 | } |
| 1213 | |
| 1214 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1215 | static int wpa_supplicant_ctrl_iface_list_networks( |
| 1216 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 1217 | { |
| 1218 | char *pos, *end; |
| 1219 | struct wpa_ssid *ssid; |
| 1220 | int ret; |
| 1221 | |
| 1222 | pos = buf; |
| 1223 | end = buf + buflen; |
| 1224 | ret = os_snprintf(pos, end - pos, |
| 1225 | "network id / ssid / bssid / flags\n"); |
| 1226 | if (ret < 0 || ret >= end - pos) |
| 1227 | return pos - buf; |
| 1228 | pos += ret; |
| 1229 | |
| 1230 | ssid = wpa_s->conf->ssid; |
| 1231 | while (ssid) { |
| 1232 | ret = os_snprintf(pos, end - pos, "%d\t%s", |
| 1233 | ssid->id, |
| 1234 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
| 1235 | if (ret < 0 || ret >= end - pos) |
| 1236 | return pos - buf; |
| 1237 | pos += ret; |
| 1238 | if (ssid->bssid_set) { |
| 1239 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, |
| 1240 | MAC2STR(ssid->bssid)); |
| 1241 | } else { |
| 1242 | ret = os_snprintf(pos, end - pos, "\tany"); |
| 1243 | } |
| 1244 | if (ret < 0 || ret >= end - pos) |
| 1245 | return pos - buf; |
| 1246 | pos += ret; |
| 1247 | ret = os_snprintf(pos, end - pos, "\t%s%s%s", |
| 1248 | ssid == wpa_s->current_ssid ? |
| 1249 | "[CURRENT]" : "", |
| 1250 | ssid->disabled ? "[DISABLED]" : "", |
| 1251 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : |
| 1252 | ""); |
| 1253 | if (ret < 0 || ret >= end - pos) |
| 1254 | return pos - buf; |
| 1255 | pos += ret; |
| 1256 | ret = os_snprintf(pos, end - pos, "\n"); |
| 1257 | if (ret < 0 || ret >= end - pos) |
| 1258 | return pos - buf; |
| 1259 | pos += ret; |
| 1260 | |
| 1261 | ssid = ssid->next; |
| 1262 | } |
| 1263 | |
| 1264 | return pos - buf; |
| 1265 | } |
| 1266 | |
| 1267 | |
| 1268 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) |
| 1269 | { |
| 1270 | int first = 1, ret; |
| 1271 | ret = os_snprintf(pos, end - pos, "-"); |
| 1272 | if (ret < 0 || ret >= end - pos) |
| 1273 | return pos; |
| 1274 | pos += ret; |
| 1275 | if (cipher & WPA_CIPHER_NONE) { |
| 1276 | ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+"); |
| 1277 | if (ret < 0 || ret >= end - pos) |
| 1278 | return pos; |
| 1279 | pos += ret; |
| 1280 | first = 0; |
| 1281 | } |
| 1282 | if (cipher & WPA_CIPHER_WEP40) { |
| 1283 | ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+"); |
| 1284 | if (ret < 0 || ret >= end - pos) |
| 1285 | return pos; |
| 1286 | pos += ret; |
| 1287 | first = 0; |
| 1288 | } |
| 1289 | if (cipher & WPA_CIPHER_WEP104) { |
| 1290 | ret = os_snprintf(pos, end - pos, "%sWEP104", |
| 1291 | first ? "" : "+"); |
| 1292 | if (ret < 0 || ret >= end - pos) |
| 1293 | return pos; |
| 1294 | pos += ret; |
| 1295 | first = 0; |
| 1296 | } |
| 1297 | if (cipher & WPA_CIPHER_TKIP) { |
| 1298 | ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+"); |
| 1299 | if (ret < 0 || ret >= end - pos) |
| 1300 | return pos; |
| 1301 | pos += ret; |
| 1302 | first = 0; |
| 1303 | } |
| 1304 | if (cipher & WPA_CIPHER_CCMP) { |
| 1305 | ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+"); |
| 1306 | if (ret < 0 || ret >= end - pos) |
| 1307 | return pos; |
| 1308 | pos += ret; |
| 1309 | first = 0; |
| 1310 | } |
| 1311 | return pos; |
| 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, |
| 1316 | const u8 *ie, size_t ie_len) |
| 1317 | { |
| 1318 | struct wpa_ie_data data; |
| 1319 | int first, ret; |
| 1320 | |
| 1321 | ret = os_snprintf(pos, end - pos, "[%s-", proto); |
| 1322 | if (ret < 0 || ret >= end - pos) |
| 1323 | return pos; |
| 1324 | pos += ret; |
| 1325 | |
| 1326 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { |
| 1327 | ret = os_snprintf(pos, end - pos, "?]"); |
| 1328 | if (ret < 0 || ret >= end - pos) |
| 1329 | return pos; |
| 1330 | pos += ret; |
| 1331 | return pos; |
| 1332 | } |
| 1333 | |
| 1334 | first = 1; |
| 1335 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { |
| 1336 | ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+"); |
| 1337 | if (ret < 0 || ret >= end - pos) |
| 1338 | return pos; |
| 1339 | pos += ret; |
| 1340 | first = 0; |
| 1341 | } |
| 1342 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { |
| 1343 | ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+"); |
| 1344 | if (ret < 0 || ret >= end - pos) |
| 1345 | return pos; |
| 1346 | pos += ret; |
| 1347 | first = 0; |
| 1348 | } |
| 1349 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { |
| 1350 | ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+"); |
| 1351 | if (ret < 0 || ret >= end - pos) |
| 1352 | return pos; |
| 1353 | pos += ret; |
| 1354 | first = 0; |
| 1355 | } |
| 1356 | #ifdef CONFIG_IEEE80211R |
| 1357 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { |
| 1358 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", |
| 1359 | first ? "" : "+"); |
| 1360 | if (ret < 0 || ret >= end - pos) |
| 1361 | return pos; |
| 1362 | pos += ret; |
| 1363 | first = 0; |
| 1364 | } |
| 1365 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { |
| 1366 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", |
| 1367 | first ? "" : "+"); |
| 1368 | if (ret < 0 || ret >= end - pos) |
| 1369 | return pos; |
| 1370 | pos += ret; |
| 1371 | first = 0; |
| 1372 | } |
| 1373 | #endif /* CONFIG_IEEE80211R */ |
| 1374 | #ifdef CONFIG_IEEE80211W |
| 1375 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { |
| 1376 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", |
| 1377 | first ? "" : "+"); |
| 1378 | if (ret < 0 || ret >= end - pos) |
| 1379 | return pos; |
| 1380 | pos += ret; |
| 1381 | first = 0; |
| 1382 | } |
| 1383 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { |
| 1384 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", |
| 1385 | first ? "" : "+"); |
| 1386 | if (ret < 0 || ret >= end - pos) |
| 1387 | return pos; |
| 1388 | pos += ret; |
| 1389 | first = 0; |
| 1390 | } |
| 1391 | #endif /* CONFIG_IEEE80211W */ |
| 1392 | |
| 1393 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); |
| 1394 | |
| 1395 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { |
| 1396 | ret = os_snprintf(pos, end - pos, "-preauth"); |
| 1397 | if (ret < 0 || ret >= end - pos) |
| 1398 | return pos; |
| 1399 | pos += ret; |
| 1400 | } |
| 1401 | |
| 1402 | ret = os_snprintf(pos, end - pos, "]"); |
| 1403 | if (ret < 0 || ret >= end - pos) |
| 1404 | return pos; |
| 1405 | pos += ret; |
| 1406 | |
| 1407 | return pos; |
| 1408 | } |
| 1409 | |
| 1410 | |
| 1411 | #ifdef CONFIG_WPS |
| 1412 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
| 1413 | char *pos, char *end, |
| 1414 | struct wpabuf *wps_ie) |
| 1415 | { |
| 1416 | int ret; |
| 1417 | const char *txt; |
| 1418 | |
| 1419 | if (wps_ie == NULL) |
| 1420 | return pos; |
| 1421 | if (wps_is_selected_pbc_registrar(wps_ie)) |
| 1422 | txt = "[WPS-PBC]"; |
| 1423 | #ifdef CONFIG_WPS2 |
| 1424 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
| 1425 | txt = "[WPS-AUTH]"; |
| 1426 | #endif /* CONFIG_WPS2 */ |
| 1427 | else if (wps_is_selected_pin_registrar(wps_ie)) |
| 1428 | txt = "[WPS-PIN]"; |
| 1429 | else |
| 1430 | txt = "[WPS]"; |
| 1431 | |
| 1432 | ret = os_snprintf(pos, end - pos, "%s", txt); |
| 1433 | if (ret >= 0 && ret < end - pos) |
| 1434 | pos += ret; |
| 1435 | wpabuf_free(wps_ie); |
| 1436 | return pos; |
| 1437 | } |
| 1438 | #endif /* CONFIG_WPS */ |
| 1439 | |
| 1440 | |
| 1441 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
| 1442 | char *pos, char *end, |
| 1443 | const struct wpa_bss *bss) |
| 1444 | { |
| 1445 | #ifdef CONFIG_WPS |
| 1446 | struct wpabuf *wps_ie; |
| 1447 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| 1448 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
| 1449 | #else /* CONFIG_WPS */ |
| 1450 | return pos; |
| 1451 | #endif /* CONFIG_WPS */ |
| 1452 | } |
| 1453 | |
| 1454 | |
| 1455 | /* Format one result on one text line into a buffer. */ |
| 1456 | static int wpa_supplicant_ctrl_iface_scan_result( |
| 1457 | struct wpa_supplicant *wpa_s, |
| 1458 | const struct wpa_bss *bss, char *buf, size_t buflen) |
| 1459 | { |
| 1460 | char *pos, *end; |
| 1461 | int ret; |
| 1462 | const u8 *ie, *ie2, *p2p; |
| 1463 | |
| 1464 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
| 1465 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && |
| 1466 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == |
| 1467 | 0) |
| 1468 | return 0; /* Do not show P2P listen discovery results here */ |
| 1469 | |
| 1470 | pos = buf; |
| 1471 | end = buf + buflen; |
| 1472 | |
| 1473 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", |
| 1474 | MAC2STR(bss->bssid), bss->freq, bss->level); |
| 1475 | if (ret < 0 || ret >= end - pos) |
| 1476 | return -1; |
| 1477 | pos += ret; |
| 1478 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 1479 | if (ie) |
| 1480 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); |
| 1481 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 1482 | if (ie2) |
| 1483 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]); |
| 1484 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
| 1485 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { |
| 1486 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
| 1487 | if (ret < 0 || ret >= end - pos) |
| 1488 | return -1; |
| 1489 | pos += ret; |
| 1490 | } |
| 1491 | if (bss->caps & IEEE80211_CAP_IBSS) { |
| 1492 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
| 1493 | if (ret < 0 || ret >= end - pos) |
| 1494 | return -1; |
| 1495 | pos += ret; |
| 1496 | } |
| 1497 | if (bss->caps & IEEE80211_CAP_ESS) { |
| 1498 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
| 1499 | if (ret < 0 || ret >= end - pos) |
| 1500 | return -1; |
| 1501 | pos += ret; |
| 1502 | } |
| 1503 | if (p2p) { |
| 1504 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
| 1505 | if (ret < 0 || ret >= end - pos) |
| 1506 | return -1; |
| 1507 | pos += ret; |
| 1508 | } |
| 1509 | |
| 1510 | ret = os_snprintf(pos, end - pos, "\t%s", |
| 1511 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
| 1512 | if (ret < 0 || ret >= end - pos) |
| 1513 | return -1; |
| 1514 | pos += ret; |
| 1515 | |
| 1516 | ret = os_snprintf(pos, end - pos, "\n"); |
| 1517 | if (ret < 0 || ret >= end - pos) |
| 1518 | return -1; |
| 1519 | pos += ret; |
| 1520 | |
| 1521 | return pos - buf; |
| 1522 | } |
| 1523 | |
| 1524 | |
| 1525 | static int wpa_supplicant_ctrl_iface_scan_results( |
| 1526 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 1527 | { |
| 1528 | char *pos, *end; |
| 1529 | struct wpa_bss *bss; |
| 1530 | int ret; |
| 1531 | |
| 1532 | pos = buf; |
| 1533 | end = buf + buflen; |
| 1534 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " |
| 1535 | "flags / ssid\n"); |
| 1536 | if (ret < 0 || ret >= end - pos) |
| 1537 | return pos - buf; |
| 1538 | pos += ret; |
| 1539 | |
| 1540 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
| 1541 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
| 1542 | end - pos); |
| 1543 | if (ret < 0 || ret >= end - pos) |
| 1544 | return pos - buf; |
| 1545 | pos += ret; |
| 1546 | } |
| 1547 | |
| 1548 | return pos - buf; |
| 1549 | } |
| 1550 | |
| 1551 | |
| 1552 | static int wpa_supplicant_ctrl_iface_select_network( |
| 1553 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1554 | { |
| 1555 | int id; |
| 1556 | struct wpa_ssid *ssid; |
| 1557 | |
| 1558 | /* cmd: "<network id>" or "any" */ |
| 1559 | if (os_strcmp(cmd, "any") == 0) { |
| 1560 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); |
| 1561 | ssid = NULL; |
| 1562 | } else { |
| 1563 | id = atoi(cmd); |
| 1564 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); |
| 1565 | |
| 1566 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 1567 | if (ssid == NULL) { |
| 1568 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 1569 | "network id=%d", id); |
| 1570 | return -1; |
| 1571 | } |
| 1572 | if (ssid->disabled == 2) { |
| 1573 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 1574 | "SELECT_NETWORK with persistent P2P group"); |
| 1575 | return -1; |
| 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | wpa_supplicant_select_network(wpa_s, ssid); |
| 1580 | |
| 1581 | return 0; |
| 1582 | } |
| 1583 | |
| 1584 | |
| 1585 | static int wpa_supplicant_ctrl_iface_enable_network( |
| 1586 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1587 | { |
| 1588 | int id; |
| 1589 | struct wpa_ssid *ssid; |
| 1590 | |
| 1591 | /* cmd: "<network id>" or "all" */ |
| 1592 | if (os_strcmp(cmd, "all") == 0) { |
| 1593 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); |
| 1594 | ssid = NULL; |
| 1595 | } else { |
| 1596 | id = atoi(cmd); |
| 1597 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); |
| 1598 | |
| 1599 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 1600 | if (ssid == NULL) { |
| 1601 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 1602 | "network id=%d", id); |
| 1603 | return -1; |
| 1604 | } |
| 1605 | if (ssid->disabled == 2) { |
| 1606 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 1607 | "ENABLE_NETWORK with persistent P2P group"); |
| 1608 | return -1; |
| 1609 | } |
| 1610 | } |
| 1611 | wpa_supplicant_enable_network(wpa_s, ssid); |
| 1612 | |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
| 1616 | |
| 1617 | static int wpa_supplicant_ctrl_iface_disable_network( |
| 1618 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1619 | { |
| 1620 | int id; |
| 1621 | struct wpa_ssid *ssid; |
| 1622 | |
| 1623 | /* cmd: "<network id>" or "all" */ |
| 1624 | if (os_strcmp(cmd, "all") == 0) { |
| 1625 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); |
| 1626 | ssid = NULL; |
| 1627 | } else { |
| 1628 | id = atoi(cmd); |
| 1629 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); |
| 1630 | |
| 1631 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 1632 | if (ssid == NULL) { |
| 1633 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 1634 | "network id=%d", id); |
| 1635 | return -1; |
| 1636 | } |
| 1637 | if (ssid->disabled == 2) { |
| 1638 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 1639 | "DISABLE_NETWORK with persistent P2P " |
| 1640 | "group"); |
| 1641 | return -1; |
| 1642 | } |
| 1643 | } |
| 1644 | wpa_supplicant_disable_network(wpa_s, ssid); |
| 1645 | |
| 1646 | return 0; |
| 1647 | } |
| 1648 | |
| 1649 | |
| 1650 | static int wpa_supplicant_ctrl_iface_add_network( |
| 1651 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 1652 | { |
| 1653 | struct wpa_ssid *ssid; |
| 1654 | int ret; |
| 1655 | |
| 1656 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); |
| 1657 | |
| 1658 | ssid = wpa_config_add_network(wpa_s->conf); |
| 1659 | if (ssid == NULL) |
| 1660 | return -1; |
| 1661 | |
| 1662 | wpas_notify_network_added(wpa_s, ssid); |
| 1663 | |
| 1664 | ssid->disabled = 1; |
| 1665 | wpa_config_set_network_defaults(ssid); |
| 1666 | |
| 1667 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); |
| 1668 | if (ret < 0 || (size_t) ret >= buflen) |
| 1669 | return -1; |
| 1670 | return ret; |
| 1671 | } |
| 1672 | |
| 1673 | |
| 1674 | static int wpa_supplicant_ctrl_iface_remove_network( |
| 1675 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1676 | { |
| 1677 | int id; |
| 1678 | struct wpa_ssid *ssid; |
| 1679 | |
| 1680 | /* cmd: "<network id>" or "all" */ |
| 1681 | if (os_strcmp(cmd, "all") == 0) { |
| 1682 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); |
| 1683 | ssid = wpa_s->conf->ssid; |
| 1684 | while (ssid) { |
| 1685 | struct wpa_ssid *remove_ssid = ssid; |
| 1686 | id = ssid->id; |
| 1687 | ssid = ssid->next; |
| 1688 | wpas_notify_network_removed(wpa_s, remove_ssid); |
| 1689 | wpa_config_remove_network(wpa_s->conf, id); |
| 1690 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1691 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1692 | if (wpa_s->current_ssid) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1693 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 1694 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1695 | wpa_supplicant_disassociate(wpa_s, |
| 1696 | WLAN_REASON_DEAUTH_LEAVING); |
| 1697 | } |
| 1698 | return 0; |
| 1699 | } |
| 1700 | |
| 1701 | id = atoi(cmd); |
| 1702 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); |
| 1703 | |
| 1704 | ssid = wpa_config_get_network(wpa_s->conf, id); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1705 | if (ssid) |
| 1706 | wpas_notify_network_removed(wpa_s, ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1707 | if (ssid == NULL || |
| 1708 | wpa_config_remove_network(wpa_s->conf, id) < 0) { |
| 1709 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
| 1710 | "id=%d", id); |
| 1711 | return -1; |
| 1712 | } |
| 1713 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1714 | if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1715 | /* |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1716 | * Invalidate the EAP session cache if the current or |
| 1717 | * previously used network is removed. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1718 | */ |
| 1719 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | if (ssid == wpa_s->current_ssid) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1723 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 1724 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1725 | |
| 1726 | wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 1727 | } |
| 1728 | |
| 1729 | return 0; |
| 1730 | } |
| 1731 | |
| 1732 | |
| 1733 | static int wpa_supplicant_ctrl_iface_set_network( |
| 1734 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1735 | { |
| 1736 | int id; |
| 1737 | struct wpa_ssid *ssid; |
| 1738 | char *name, *value; |
| 1739 | |
| 1740 | /* cmd: "<network id> <variable name> <value>" */ |
| 1741 | name = os_strchr(cmd, ' '); |
| 1742 | if (name == NULL) |
| 1743 | return -1; |
| 1744 | *name++ = '\0'; |
| 1745 | |
| 1746 | value = os_strchr(name, ' '); |
| 1747 | if (value == NULL) |
| 1748 | return -1; |
| 1749 | *value++ = '\0'; |
| 1750 | |
| 1751 | id = atoi(cmd); |
| 1752 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", |
| 1753 | id, name); |
| 1754 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 1755 | (u8 *) value, os_strlen(value)); |
| 1756 | |
| 1757 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 1758 | if (ssid == NULL) { |
| 1759 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
| 1760 | "id=%d", id); |
| 1761 | return -1; |
| 1762 | } |
| 1763 | |
| 1764 | if (wpa_config_set(ssid, name, value, 0) < 0) { |
| 1765 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " |
| 1766 | "variable '%s'", name); |
| 1767 | return -1; |
| 1768 | } |
| 1769 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1770 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
| 1771 | |
| 1772 | if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1773 | /* |
| 1774 | * Invalidate the EAP session cache if anything in the current |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1775 | * or previously used configuration changes. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1776 | */ |
| 1777 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
| 1778 | } |
| 1779 | |
| 1780 | if ((os_strcmp(name, "psk") == 0 && |
| 1781 | value[0] == '"' && ssid->ssid_len) || |
| 1782 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) |
| 1783 | wpa_config_update_psk(ssid); |
| 1784 | else if (os_strcmp(name, "priority") == 0) |
| 1785 | wpa_config_update_prio_list(wpa_s->conf); |
| 1786 | |
| 1787 | return 0; |
| 1788 | } |
| 1789 | |
| 1790 | |
| 1791 | static int wpa_supplicant_ctrl_iface_get_network( |
| 1792 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 1793 | { |
| 1794 | int id; |
| 1795 | size_t res; |
| 1796 | struct wpa_ssid *ssid; |
| 1797 | char *name, *value; |
| 1798 | |
| 1799 | /* cmd: "<network id> <variable name>" */ |
| 1800 | name = os_strchr(cmd, ' '); |
| 1801 | if (name == NULL || buflen == 0) |
| 1802 | return -1; |
| 1803 | *name++ = '\0'; |
| 1804 | |
| 1805 | id = atoi(cmd); |
| 1806 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", |
| 1807 | id, name); |
| 1808 | |
| 1809 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 1810 | if (ssid == NULL) { |
| 1811 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
| 1812 | "id=%d", id); |
| 1813 | return -1; |
| 1814 | } |
| 1815 | |
| 1816 | value = wpa_config_get_no_key(ssid, name); |
| 1817 | if (value == NULL) { |
| 1818 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " |
| 1819 | "variable '%s'", name); |
| 1820 | return -1; |
| 1821 | } |
| 1822 | |
| 1823 | res = os_strlcpy(buf, value, buflen); |
| 1824 | if (res >= buflen) { |
| 1825 | os_free(value); |
| 1826 | return -1; |
| 1827 | } |
| 1828 | |
| 1829 | os_free(value); |
| 1830 | |
| 1831 | return res; |
| 1832 | } |
| 1833 | |
| 1834 | |
| 1835 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 1836 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) |
| 1837 | { |
| 1838 | int ret; |
| 1839 | |
| 1840 | if (!wpa_s->conf->update_config) { |
| 1841 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " |
| 1842 | "to update configuration (update_config=0)"); |
| 1843 | return -1; |
| 1844 | } |
| 1845 | |
| 1846 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); |
| 1847 | if (ret) { |
| 1848 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " |
| 1849 | "update configuration"); |
| 1850 | } else { |
| 1851 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" |
| 1852 | " updated"); |
| 1853 | } |
| 1854 | |
| 1855 | return ret; |
| 1856 | } |
| 1857 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 1858 | |
| 1859 | |
| 1860 | static int ctrl_iface_get_capability_pairwise(int res, char *strict, |
| 1861 | struct wpa_driver_capa *capa, |
| 1862 | char *buf, size_t buflen) |
| 1863 | { |
| 1864 | int ret, first = 1; |
| 1865 | char *pos, *end; |
| 1866 | size_t len; |
| 1867 | |
| 1868 | pos = buf; |
| 1869 | end = pos + buflen; |
| 1870 | |
| 1871 | if (res < 0) { |
| 1872 | if (strict) |
| 1873 | return 0; |
| 1874 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); |
| 1875 | if (len >= buflen) |
| 1876 | return -1; |
| 1877 | return len; |
| 1878 | } |
| 1879 | |
| 1880 | if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) { |
| 1881 | ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " "); |
| 1882 | if (ret < 0 || ret >= end - pos) |
| 1883 | return pos - buf; |
| 1884 | pos += ret; |
| 1885 | first = 0; |
| 1886 | } |
| 1887 | |
| 1888 | if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) { |
| 1889 | ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " "); |
| 1890 | if (ret < 0 || ret >= end - pos) |
| 1891 | return pos - buf; |
| 1892 | pos += ret; |
| 1893 | first = 0; |
| 1894 | } |
| 1895 | |
| 1896 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { |
| 1897 | ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " "); |
| 1898 | if (ret < 0 || ret >= end - pos) |
| 1899 | return pos - buf; |
| 1900 | pos += ret; |
| 1901 | first = 0; |
| 1902 | } |
| 1903 | |
| 1904 | return pos - buf; |
| 1905 | } |
| 1906 | |
| 1907 | |
| 1908 | static int ctrl_iface_get_capability_group(int res, char *strict, |
| 1909 | struct wpa_driver_capa *capa, |
| 1910 | char *buf, size_t buflen) |
| 1911 | { |
| 1912 | int ret, first = 1; |
| 1913 | char *pos, *end; |
| 1914 | size_t len; |
| 1915 | |
| 1916 | pos = buf; |
| 1917 | end = pos + buflen; |
| 1918 | |
| 1919 | if (res < 0) { |
| 1920 | if (strict) |
| 1921 | return 0; |
| 1922 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); |
| 1923 | if (len >= buflen) |
| 1924 | return -1; |
| 1925 | return len; |
| 1926 | } |
| 1927 | |
| 1928 | if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) { |
| 1929 | ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " "); |
| 1930 | if (ret < 0 || ret >= end - pos) |
| 1931 | return pos - buf; |
| 1932 | pos += ret; |
| 1933 | first = 0; |
| 1934 | } |
| 1935 | |
| 1936 | if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) { |
| 1937 | ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " "); |
| 1938 | if (ret < 0 || ret >= end - pos) |
| 1939 | return pos - buf; |
| 1940 | pos += ret; |
| 1941 | first = 0; |
| 1942 | } |
| 1943 | |
| 1944 | if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) { |
| 1945 | ret = os_snprintf(pos, end - pos, "%sWEP104", |
| 1946 | first ? "" : " "); |
| 1947 | if (ret < 0 || ret >= end - pos) |
| 1948 | return pos - buf; |
| 1949 | pos += ret; |
| 1950 | first = 0; |
| 1951 | } |
| 1952 | |
| 1953 | if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) { |
| 1954 | ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " "); |
| 1955 | if (ret < 0 || ret >= end - pos) |
| 1956 | return pos - buf; |
| 1957 | pos += ret; |
| 1958 | first = 0; |
| 1959 | } |
| 1960 | |
| 1961 | return pos - buf; |
| 1962 | } |
| 1963 | |
| 1964 | |
| 1965 | static int ctrl_iface_get_capability_key_mgmt(int res, char *strict, |
| 1966 | struct wpa_driver_capa *capa, |
| 1967 | char *buf, size_t buflen) |
| 1968 | { |
| 1969 | int ret; |
| 1970 | char *pos, *end; |
| 1971 | size_t len; |
| 1972 | |
| 1973 | pos = buf; |
| 1974 | end = pos + buflen; |
| 1975 | |
| 1976 | if (res < 0) { |
| 1977 | if (strict) |
| 1978 | return 0; |
| 1979 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " |
| 1980 | "NONE", buflen); |
| 1981 | if (len >= buflen) |
| 1982 | return -1; |
| 1983 | return len; |
| 1984 | } |
| 1985 | |
| 1986 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); |
| 1987 | if (ret < 0 || ret >= end - pos) |
| 1988 | return pos - buf; |
| 1989 | pos += ret; |
| 1990 | |
| 1991 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 1992 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { |
| 1993 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); |
| 1994 | if (ret < 0 || ret >= end - pos) |
| 1995 | return pos - buf; |
| 1996 | pos += ret; |
| 1997 | } |
| 1998 | |
| 1999 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | |
| 2000 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
| 2001 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); |
| 2002 | if (ret < 0 || ret >= end - pos) |
| 2003 | return pos - buf; |
| 2004 | pos += ret; |
| 2005 | } |
| 2006 | |
| 2007 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { |
| 2008 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); |
| 2009 | if (ret < 0 || ret >= end - pos) |
| 2010 | return pos - buf; |
| 2011 | pos += ret; |
| 2012 | } |
| 2013 | |
| 2014 | return pos - buf; |
| 2015 | } |
| 2016 | |
| 2017 | |
| 2018 | static int ctrl_iface_get_capability_proto(int res, char *strict, |
| 2019 | struct wpa_driver_capa *capa, |
| 2020 | char *buf, size_t buflen) |
| 2021 | { |
| 2022 | int ret, first = 1; |
| 2023 | char *pos, *end; |
| 2024 | size_t len; |
| 2025 | |
| 2026 | pos = buf; |
| 2027 | end = pos + buflen; |
| 2028 | |
| 2029 | if (res < 0) { |
| 2030 | if (strict) |
| 2031 | return 0; |
| 2032 | len = os_strlcpy(buf, "RSN WPA", buflen); |
| 2033 | if (len >= buflen) |
| 2034 | return -1; |
| 2035 | return len; |
| 2036 | } |
| 2037 | |
| 2038 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | |
| 2039 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
| 2040 | ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " "); |
| 2041 | if (ret < 0 || ret >= end - pos) |
| 2042 | return pos - buf; |
| 2043 | pos += ret; |
| 2044 | first = 0; |
| 2045 | } |
| 2046 | |
| 2047 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 2048 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { |
| 2049 | ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " "); |
| 2050 | if (ret < 0 || ret >= end - pos) |
| 2051 | return pos - buf; |
| 2052 | pos += ret; |
| 2053 | first = 0; |
| 2054 | } |
| 2055 | |
| 2056 | return pos - buf; |
| 2057 | } |
| 2058 | |
| 2059 | |
| 2060 | static int ctrl_iface_get_capability_auth_alg(int res, char *strict, |
| 2061 | struct wpa_driver_capa *capa, |
| 2062 | char *buf, size_t buflen) |
| 2063 | { |
| 2064 | int ret, first = 1; |
| 2065 | char *pos, *end; |
| 2066 | size_t len; |
| 2067 | |
| 2068 | pos = buf; |
| 2069 | end = pos + buflen; |
| 2070 | |
| 2071 | if (res < 0) { |
| 2072 | if (strict) |
| 2073 | return 0; |
| 2074 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); |
| 2075 | if (len >= buflen) |
| 2076 | return -1; |
| 2077 | return len; |
| 2078 | } |
| 2079 | |
| 2080 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { |
| 2081 | ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " "); |
| 2082 | if (ret < 0 || ret >= end - pos) |
| 2083 | return pos - buf; |
| 2084 | pos += ret; |
| 2085 | first = 0; |
| 2086 | } |
| 2087 | |
| 2088 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { |
| 2089 | ret = os_snprintf(pos, end - pos, "%sSHARED", |
| 2090 | first ? "" : " "); |
| 2091 | if (ret < 0 || ret >= end - pos) |
| 2092 | return pos - buf; |
| 2093 | pos += ret; |
| 2094 | first = 0; |
| 2095 | } |
| 2096 | |
| 2097 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { |
| 2098 | ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " "); |
| 2099 | if (ret < 0 || ret >= end - pos) |
| 2100 | return pos - buf; |
| 2101 | pos += ret; |
| 2102 | first = 0; |
| 2103 | } |
| 2104 | |
| 2105 | return pos - buf; |
| 2106 | } |
| 2107 | |
| 2108 | |
| 2109 | static int wpa_supplicant_ctrl_iface_get_capability( |
| 2110 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, |
| 2111 | size_t buflen) |
| 2112 | { |
| 2113 | struct wpa_driver_capa capa; |
| 2114 | int res; |
| 2115 | char *strict; |
| 2116 | char field[30]; |
| 2117 | size_t len; |
| 2118 | |
| 2119 | /* Determine whether or not strict checking was requested */ |
| 2120 | len = os_strlcpy(field, _field, sizeof(field)); |
| 2121 | if (len >= sizeof(field)) |
| 2122 | return -1; |
| 2123 | strict = os_strchr(field, ' '); |
| 2124 | if (strict != NULL) { |
| 2125 | *strict++ = '\0'; |
| 2126 | if (os_strcmp(strict, "strict") != 0) |
| 2127 | return -1; |
| 2128 | } |
| 2129 | |
| 2130 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", |
| 2131 | field, strict ? strict : ""); |
| 2132 | |
| 2133 | if (os_strcmp(field, "eap") == 0) { |
| 2134 | return eap_get_names(buf, buflen); |
| 2135 | } |
| 2136 | |
| 2137 | res = wpa_drv_get_capa(wpa_s, &capa); |
| 2138 | |
| 2139 | if (os_strcmp(field, "pairwise") == 0) |
| 2140 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, |
| 2141 | buf, buflen); |
| 2142 | |
| 2143 | if (os_strcmp(field, "group") == 0) |
| 2144 | return ctrl_iface_get_capability_group(res, strict, &capa, |
| 2145 | buf, buflen); |
| 2146 | |
| 2147 | if (os_strcmp(field, "key_mgmt") == 0) |
| 2148 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, |
| 2149 | buf, buflen); |
| 2150 | |
| 2151 | if (os_strcmp(field, "proto") == 0) |
| 2152 | return ctrl_iface_get_capability_proto(res, strict, &capa, |
| 2153 | buf, buflen); |
| 2154 | |
| 2155 | if (os_strcmp(field, "auth_alg") == 0) |
| 2156 | return ctrl_iface_get_capability_auth_alg(res, strict, &capa, |
| 2157 | buf, buflen); |
| 2158 | |
| 2159 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", |
| 2160 | field); |
| 2161 | |
| 2162 | return -1; |
| 2163 | } |
| 2164 | |
| 2165 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2166 | #ifdef CONFIG_INTERWORKING |
| 2167 | static char * anqp_add_hex(char *pos, char *end, const char *title, |
| 2168 | struct wpabuf *data) |
| 2169 | { |
| 2170 | char *start = pos; |
| 2171 | size_t i; |
| 2172 | int ret; |
| 2173 | const u8 *d; |
| 2174 | |
| 2175 | if (data == NULL) |
| 2176 | return start; |
| 2177 | |
| 2178 | ret = os_snprintf(pos, end - pos, "%s=", title); |
| 2179 | if (ret < 0 || ret >= end - pos) |
| 2180 | return start; |
| 2181 | pos += ret; |
| 2182 | |
| 2183 | d = wpabuf_head_u8(data); |
| 2184 | for (i = 0; i < wpabuf_len(data); i++) { |
| 2185 | ret = os_snprintf(pos, end - pos, "%02x", *d++); |
| 2186 | if (ret < 0 || ret >= end - pos) |
| 2187 | return start; |
| 2188 | pos += ret; |
| 2189 | } |
| 2190 | |
| 2191 | ret = os_snprintf(pos, end - pos, "\n"); |
| 2192 | if (ret < 0 || ret >= end - pos) |
| 2193 | return start; |
| 2194 | pos += ret; |
| 2195 | |
| 2196 | return pos; |
| 2197 | } |
| 2198 | #endif /* CONFIG_INTERWORKING */ |
| 2199 | |
| 2200 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 2201 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 2202 | unsigned long mask, char *buf, size_t buflen) |
| 2203 | { |
| 2204 | size_t i; |
| 2205 | int ret; |
| 2206 | char *pos, *end; |
| 2207 | const u8 *ie, *ie2; |
| 2208 | struct os_time now; |
| 2209 | |
| 2210 | os_get_time(&now); |
| 2211 | pos = buf; |
| 2212 | end = buf + buflen; |
| 2213 | |
| 2214 | if (mask & WPA_BSS_MASK_ID) { |
| 2215 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); |
| 2216 | if (ret < 0 || ret >= end - pos) |
| 2217 | return 0; |
| 2218 | pos += ret; |
| 2219 | } |
| 2220 | |
| 2221 | if (mask & WPA_BSS_MASK_BSSID) { |
| 2222 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", |
| 2223 | MAC2STR(bss->bssid)); |
| 2224 | if (ret < 0 || ret >= end - pos) |
| 2225 | return 0; |
| 2226 | pos += ret; |
| 2227 | } |
| 2228 | |
| 2229 | if (mask & WPA_BSS_MASK_FREQ) { |
| 2230 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); |
| 2231 | if (ret < 0 || ret >= end - pos) |
| 2232 | return 0; |
| 2233 | pos += ret; |
| 2234 | } |
| 2235 | |
| 2236 | if (mask & WPA_BSS_MASK_BEACON_INT) { |
| 2237 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", |
| 2238 | bss->beacon_int); |
| 2239 | if (ret < 0 || ret >= end - pos) |
| 2240 | return 0; |
| 2241 | pos += ret; |
| 2242 | } |
| 2243 | |
| 2244 | if (mask & WPA_BSS_MASK_CAPABILITIES) { |
| 2245 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", |
| 2246 | bss->caps); |
| 2247 | if (ret < 0 || ret >= end - pos) |
| 2248 | return 0; |
| 2249 | pos += ret; |
| 2250 | } |
| 2251 | |
| 2252 | if (mask & WPA_BSS_MASK_QUAL) { |
| 2253 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); |
| 2254 | if (ret < 0 || ret >= end - pos) |
| 2255 | return 0; |
| 2256 | pos += ret; |
| 2257 | } |
| 2258 | |
| 2259 | if (mask & WPA_BSS_MASK_NOISE) { |
| 2260 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); |
| 2261 | if (ret < 0 || ret >= end - pos) |
| 2262 | return 0; |
| 2263 | pos += ret; |
| 2264 | } |
| 2265 | |
| 2266 | if (mask & WPA_BSS_MASK_LEVEL) { |
| 2267 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); |
| 2268 | if (ret < 0 || ret >= end - pos) |
| 2269 | return 0; |
| 2270 | pos += ret; |
| 2271 | } |
| 2272 | |
| 2273 | if (mask & WPA_BSS_MASK_TSF) { |
| 2274 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", |
| 2275 | (unsigned long long) bss->tsf); |
| 2276 | if (ret < 0 || ret >= end - pos) |
| 2277 | return 0; |
| 2278 | pos += ret; |
| 2279 | } |
| 2280 | |
| 2281 | if (mask & WPA_BSS_MASK_AGE) { |
| 2282 | ret = os_snprintf(pos, end - pos, "age=%d\n", |
| 2283 | (int) (now.sec - bss->last_update.sec)); |
| 2284 | if (ret < 0 || ret >= end - pos) |
| 2285 | return 0; |
| 2286 | pos += ret; |
| 2287 | } |
| 2288 | |
| 2289 | if (mask & WPA_BSS_MASK_IE) { |
| 2290 | ret = os_snprintf(pos, end - pos, "ie="); |
| 2291 | if (ret < 0 || ret >= end - pos) |
| 2292 | return 0; |
| 2293 | pos += ret; |
| 2294 | |
| 2295 | ie = (const u8 *) (bss + 1); |
| 2296 | for (i = 0; i < bss->ie_len; i++) { |
| 2297 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); |
| 2298 | if (ret < 0 || ret >= end - pos) |
| 2299 | return 0; |
| 2300 | pos += ret; |
| 2301 | } |
| 2302 | |
| 2303 | ret = os_snprintf(pos, end - pos, "\n"); |
| 2304 | if (ret < 0 || ret >= end - pos) |
| 2305 | return 0; |
| 2306 | pos += ret; |
| 2307 | } |
| 2308 | |
| 2309 | if (mask & WPA_BSS_MASK_FLAGS) { |
| 2310 | ret = os_snprintf(pos, end - pos, "flags="); |
| 2311 | if (ret < 0 || ret >= end - pos) |
| 2312 | return 0; |
| 2313 | pos += ret; |
| 2314 | |
| 2315 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 2316 | if (ie) |
| 2317 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, |
| 2318 | 2 + ie[1]); |
| 2319 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 2320 | if (ie2) |
| 2321 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, |
| 2322 | 2 + ie2[1]); |
| 2323 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
| 2324 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { |
| 2325 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
| 2326 | if (ret < 0 || ret >= end - pos) |
| 2327 | return 0; |
| 2328 | pos += ret; |
| 2329 | } |
| 2330 | if (bss->caps & IEEE80211_CAP_IBSS) { |
| 2331 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
| 2332 | if (ret < 0 || ret >= end - pos) |
| 2333 | return 0; |
| 2334 | pos += ret; |
| 2335 | } |
| 2336 | if (bss->caps & IEEE80211_CAP_ESS) { |
| 2337 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
| 2338 | if (ret < 0 || ret >= end - pos) |
| 2339 | return 0; |
| 2340 | pos += ret; |
| 2341 | } |
| 2342 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) { |
| 2343 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
| 2344 | if (ret < 0 || ret >= end - pos) |
| 2345 | return 0; |
| 2346 | pos += ret; |
| 2347 | } |
| 2348 | |
| 2349 | ret = os_snprintf(pos, end - pos, "\n"); |
| 2350 | if (ret < 0 || ret >= end - pos) |
| 2351 | return 0; |
| 2352 | pos += ret; |
| 2353 | } |
| 2354 | |
| 2355 | if (mask & WPA_BSS_MASK_SSID) { |
| 2356 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", |
| 2357 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
| 2358 | if (ret < 0 || ret >= end - pos) |
| 2359 | return 0; |
| 2360 | pos += ret; |
| 2361 | } |
| 2362 | |
| 2363 | #ifdef CONFIG_WPS |
| 2364 | if (mask & WPA_BSS_MASK_WPS_SCAN) { |
| 2365 | ie = (const u8 *) (bss + 1); |
| 2366 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); |
| 2367 | if (ret < 0 || ret >= end - pos) |
| 2368 | return 0; |
| 2369 | pos += ret; |
| 2370 | } |
| 2371 | #endif /* CONFIG_WPS */ |
| 2372 | |
| 2373 | #ifdef CONFIG_P2P |
| 2374 | if (mask & WPA_BSS_MASK_P2P_SCAN) { |
| 2375 | ie = (const u8 *) (bss + 1); |
| 2376 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); |
| 2377 | if (ret < 0 || ret >= end - pos) |
| 2378 | return 0; |
| 2379 | pos += ret; |
| 2380 | } |
| 2381 | #endif /* CONFIG_P2P */ |
| 2382 | |
| 2383 | #ifdef CONFIG_INTERWORKING |
| 2384 | if (mask & WPA_BSS_MASK_INTERNETW) { |
| 2385 | pos = anqp_add_hex(pos, end, "anqp_venue_name", |
| 2386 | bss->anqp_venue_name); |
| 2387 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", |
| 2388 | bss->anqp_network_auth_type); |
| 2389 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", |
| 2390 | bss->anqp_roaming_consortium); |
| 2391 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", |
| 2392 | bss->anqp_ip_addr_type_availability); |
| 2393 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", |
| 2394 | bss->anqp_nai_realm); |
| 2395 | pos = anqp_add_hex(pos, end, "anqp_3gpp", bss->anqp_3gpp); |
| 2396 | pos = anqp_add_hex(pos, end, "anqp_domain_name", |
| 2397 | bss->anqp_domain_name); |
| 2398 | } |
| 2399 | #endif /* CONFIG_INTERWORKING */ |
| 2400 | |
| 2401 | return pos - buf; |
| 2402 | } |
| 2403 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2404 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, |
| 2405 | const char *cmd, char *buf, |
| 2406 | size_t buflen) |
| 2407 | { |
| 2408 | u8 bssid[ETH_ALEN]; |
| 2409 | size_t i; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 2410 | struct wpa_bss *bss = NULL; |
| 2411 | struct wpa_bss *bsslast = NULL; |
| 2412 | struct dl_list *next; |
| 2413 | int ret = 0; |
| 2414 | int len; |
| 2415 | char *ctmp; |
| 2416 | unsigned long mask = WPA_BSS_MASK_ALL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2417 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 2418 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { |
| 2419 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { |
| 2420 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, |
| 2421 | list_id); |
| 2422 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, |
| 2423 | list_id); |
| 2424 | } else { /* N1-N2 */ |
| 2425 | if ((ctmp = os_strchr(cmd + 6, '-')) != NULL) { |
| 2426 | int id1, id2; |
| 2427 | id1 = atoi(cmd + 6); |
| 2428 | bss = wpa_bss_get_id(wpa_s, id1); |
| 2429 | id2 = atoi(ctmp + 1); |
| 2430 | if (id2 == 0) |
| 2431 | bsslast = dl_list_last(&wpa_s->bss_id, |
| 2432 | struct wpa_bss, |
| 2433 | list_id); |
| 2434 | else |
| 2435 | bsslast = wpa_bss_get_id(wpa_s, id2); |
| 2436 | } else { |
| 2437 | wpa_printf(MSG_ERROR, "Wrong range format"); |
| 2438 | return 0; |
| 2439 | } |
| 2440 | } |
| 2441 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { |
| 2442 | mask = strtoul(ctmp + 5, NULL, 0x10); |
| 2443 | if (mask == 0) |
| 2444 | mask = WPA_BSS_MASK_ALL; |
| 2445 | } |
| 2446 | } else if (os_strcmp(cmd, "FIRST") == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2447 | bss = dl_list_first(&wpa_s->bss, struct wpa_bss, list); |
| 2448 | else if (os_strncmp(cmd, "ID-", 3) == 0) { |
| 2449 | i = atoi(cmd + 3); |
| 2450 | bss = wpa_bss_get_id(wpa_s, i); |
| 2451 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { |
| 2452 | i = atoi(cmd + 5); |
| 2453 | bss = wpa_bss_get_id(wpa_s, i); |
| 2454 | if (bss) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 2455 | next = bss->list_id.next; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2456 | if (next == &wpa_s->bss_id) |
| 2457 | bss = NULL; |
| 2458 | else |
| 2459 | bss = dl_list_entry(next, struct wpa_bss, |
| 2460 | list_id); |
| 2461 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2462 | #ifdef CONFIG_P2P |
| 2463 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { |
| 2464 | if (hwaddr_aton(cmd + 13, bssid) == 0) |
| 2465 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); |
| 2466 | else |
| 2467 | bss = NULL; |
| 2468 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2469 | } else if (hwaddr_aton(cmd, bssid) == 0) |
| 2470 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 2471 | else { |
| 2472 | struct wpa_bss *tmp; |
| 2473 | i = atoi(cmd); |
| 2474 | bss = NULL; |
| 2475 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) |
| 2476 | { |
| 2477 | if (i-- == 0) { |
| 2478 | bss = tmp; |
| 2479 | break; |
| 2480 | } |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | if (bss == NULL) |
| 2485 | return 0; |
| 2486 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 2487 | if (bsslast == NULL) |
| 2488 | bsslast = bss; |
| 2489 | do { |
| 2490 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); |
| 2491 | ret += len; |
| 2492 | buf += len; |
| 2493 | buflen -= len; |
| 2494 | if (bss == bsslast) |
| 2495 | break; |
| 2496 | next = bss->list_id.next; |
| 2497 | if (next == &wpa_s->bss_id) |
| 2498 | break; |
| 2499 | bss = dl_list_entry(next, struct wpa_bss, list_id); |
| 2500 | } while (bss && len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2501 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 2502 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | |
| 2506 | static int wpa_supplicant_ctrl_iface_ap_scan( |
| 2507 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2508 | { |
| 2509 | int ap_scan = atoi(cmd); |
| 2510 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
| 2511 | } |
| 2512 | |
| 2513 | |
| 2514 | static int wpa_supplicant_ctrl_iface_scan_interval( |
| 2515 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2516 | { |
| 2517 | int scan_int = atoi(cmd); |
| 2518 | if (scan_int < 0) |
| 2519 | return -1; |
| 2520 | wpa_s->scan_interval = scan_int; |
| 2521 | return 0; |
| 2522 | } |
| 2523 | |
| 2524 | |
| 2525 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
| 2526 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2527 | { |
| 2528 | int expire_age = atoi(cmd); |
| 2529 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); |
| 2530 | } |
| 2531 | |
| 2532 | |
| 2533 | static int wpa_supplicant_ctrl_iface_bss_expire_count( |
| 2534 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2535 | { |
| 2536 | int expire_count = atoi(cmd); |
| 2537 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); |
| 2538 | } |
| 2539 | |
| 2540 | |
| 2541 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
| 2542 | { |
| 2543 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
| 2544 | /* MLME-DELETEKEYS.request */ |
| 2545 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0); |
| 2546 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0); |
| 2547 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0); |
| 2548 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0); |
| 2549 | #ifdef CONFIG_IEEE80211W |
| 2550 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0); |
| 2551 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0); |
| 2552 | #endif /* CONFIG_IEEE80211W */ |
| 2553 | |
| 2554 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, |
| 2555 | 0); |
| 2556 | /* MLME-SETPROTECTION.request(None) */ |
| 2557 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, |
| 2558 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, |
| 2559 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); |
| 2560 | wpa_sm_drop_sa(wpa_s->wpa); |
| 2561 | } |
| 2562 | |
| 2563 | |
| 2564 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
| 2565 | char *addr) |
| 2566 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2567 | #ifdef CONFIG_NO_SCAN_PROCESSING |
| 2568 | return -1; |
| 2569 | #else /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2570 | u8 bssid[ETH_ALEN]; |
| 2571 | struct wpa_bss *bss; |
| 2572 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 2573 | |
| 2574 | if (hwaddr_aton(addr, bssid)) { |
| 2575 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " |
| 2576 | "address '%s'", addr); |
| 2577 | return -1; |
| 2578 | } |
| 2579 | |
| 2580 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); |
| 2581 | |
| 2582 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 2583 | if (!bss) { |
| 2584 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " |
| 2585 | "from BSS table"); |
| 2586 | return -1; |
| 2587 | } |
| 2588 | |
| 2589 | /* |
| 2590 | * TODO: Find best network configuration block from configuration to |
| 2591 | * allow roaming to other networks |
| 2592 | */ |
| 2593 | |
| 2594 | if (!ssid) { |
| 2595 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " |
| 2596 | "configuration known for the target AP"); |
| 2597 | return -1; |
| 2598 | } |
| 2599 | |
| 2600 | wpa_s->reassociate = 1; |
| 2601 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 2602 | |
| 2603 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2604 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | |
| 2608 | #ifdef CONFIG_P2P |
| 2609 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) |
| 2610 | { |
| 2611 | unsigned int timeout = atoi(cmd); |
| 2612 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2613 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; |
| 2614 | char *pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2615 | |
| 2616 | if (os_strstr(cmd, "type=social")) |
| 2617 | type = P2P_FIND_ONLY_SOCIAL; |
| 2618 | else if (os_strstr(cmd, "type=progressive")) |
| 2619 | type = P2P_FIND_PROGRESSIVE; |
| 2620 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2621 | pos = os_strstr(cmd, "dev_id="); |
| 2622 | if (pos) { |
| 2623 | pos += 7; |
| 2624 | if (hwaddr_aton(pos, dev_id)) |
| 2625 | return -1; |
| 2626 | _dev_id = dev_id; |
| 2627 | } |
| 2628 | |
| 2629 | return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | |
| 2633 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, |
| 2634 | char *buf, size_t buflen) |
| 2635 | { |
| 2636 | u8 addr[ETH_ALEN]; |
| 2637 | char *pos, *pos2; |
| 2638 | char *pin = NULL; |
| 2639 | enum p2p_wps_method wps_method; |
| 2640 | int new_pin; |
| 2641 | int ret; |
| 2642 | int persistent_group; |
| 2643 | int join; |
| 2644 | int auth; |
| 2645 | int go_intent = -1; |
| 2646 | int freq = 0; |
| 2647 | |
| 2648 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad] [persistent] |
| 2649 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] */ |
| 2650 | |
| 2651 | if (hwaddr_aton(cmd, addr)) |
| 2652 | return -1; |
| 2653 | |
| 2654 | pos = cmd + 17; |
| 2655 | if (*pos != ' ') |
| 2656 | return -1; |
| 2657 | pos++; |
| 2658 | |
| 2659 | persistent_group = os_strstr(pos, " persistent") != NULL; |
| 2660 | join = os_strstr(pos, " join") != NULL; |
| 2661 | auth = os_strstr(pos, " auth") != NULL; |
| 2662 | |
| 2663 | pos2 = os_strstr(pos, " go_intent="); |
| 2664 | if (pos2) { |
| 2665 | pos2 += 11; |
| 2666 | go_intent = atoi(pos2); |
| 2667 | if (go_intent < 0 || go_intent > 15) |
| 2668 | return -1; |
| 2669 | } |
| 2670 | |
| 2671 | pos2 = os_strstr(pos, " freq="); |
| 2672 | if (pos2) { |
| 2673 | pos2 += 6; |
| 2674 | freq = atoi(pos2); |
| 2675 | if (freq <= 0) |
| 2676 | return -1; |
| 2677 | } |
| 2678 | |
| 2679 | if (os_strncmp(pos, "pin", 3) == 0) { |
| 2680 | /* Request random PIN (to be displayed) and enable the PIN */ |
| 2681 | wps_method = WPS_PIN_DISPLAY; |
| 2682 | } else if (os_strncmp(pos, "pbc", 3) == 0) { |
| 2683 | wps_method = WPS_PBC; |
| 2684 | } else { |
| 2685 | pin = pos; |
| 2686 | pos = os_strchr(pin, ' '); |
| 2687 | wps_method = WPS_PIN_KEYPAD; |
| 2688 | if (pos) { |
| 2689 | *pos++ = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2690 | if (os_strncmp(pos, "display", 7) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2691 | wps_method = WPS_PIN_DISPLAY; |
| 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, |
| 2696 | persistent_group, join, auth, go_intent, |
| 2697 | freq); |
| 2698 | if (new_pin == -2) { |
| 2699 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); |
| 2700 | return 25; |
| 2701 | } |
| 2702 | if (new_pin == -3) { |
| 2703 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); |
| 2704 | return 25; |
| 2705 | } |
| 2706 | if (new_pin < 0) |
| 2707 | return -1; |
| 2708 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { |
| 2709 | ret = os_snprintf(buf, buflen, "%08d", new_pin); |
| 2710 | if (ret < 0 || (size_t) ret >= buflen) |
| 2711 | return -1; |
| 2712 | return ret; |
| 2713 | } |
| 2714 | |
| 2715 | os_memcpy(buf, "OK\n", 3); |
| 2716 | return 3; |
| 2717 | } |
| 2718 | |
| 2719 | |
| 2720 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) |
| 2721 | { |
| 2722 | unsigned int timeout = atoi(cmd); |
| 2723 | return wpas_p2p_listen(wpa_s, timeout); |
| 2724 | } |
| 2725 | |
| 2726 | |
| 2727 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) |
| 2728 | { |
| 2729 | u8 addr[ETH_ALEN]; |
| 2730 | char *pos; |
| 2731 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2732 | /* <addr> <config method> [join] */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2733 | |
| 2734 | if (hwaddr_aton(cmd, addr)) |
| 2735 | return -1; |
| 2736 | |
| 2737 | pos = cmd + 17; |
| 2738 | if (*pos != ' ') |
| 2739 | return -1; |
| 2740 | pos++; |
| 2741 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2742 | return wpas_p2p_prov_disc(wpa_s, addr, pos, |
| 2743 | os_strstr(pos, "join") != NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | |
| 2747 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, |
| 2748 | size_t buflen) |
| 2749 | { |
| 2750 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 2751 | |
| 2752 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 2753 | ssid->passphrase == NULL) |
| 2754 | return -1; |
| 2755 | |
| 2756 | os_strlcpy(buf, ssid->passphrase, buflen); |
| 2757 | return os_strlen(buf); |
| 2758 | } |
| 2759 | |
| 2760 | |
| 2761 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, |
| 2762 | char *buf, size_t buflen) |
| 2763 | { |
| 2764 | u64 ref; |
| 2765 | int res; |
| 2766 | u8 dst_buf[ETH_ALEN], *dst; |
| 2767 | struct wpabuf *tlvs; |
| 2768 | char *pos; |
| 2769 | size_t len; |
| 2770 | |
| 2771 | if (hwaddr_aton(cmd, dst_buf)) |
| 2772 | return -1; |
| 2773 | dst = dst_buf; |
| 2774 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && |
| 2775 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) |
| 2776 | dst = NULL; |
| 2777 | pos = cmd + 17; |
| 2778 | if (*pos != ' ') |
| 2779 | return -1; |
| 2780 | pos++; |
| 2781 | |
| 2782 | if (os_strncmp(pos, "upnp ", 5) == 0) { |
| 2783 | u8 version; |
| 2784 | pos += 5; |
| 2785 | if (hexstr2bin(pos, &version, 1) < 0) |
| 2786 | return -1; |
| 2787 | pos += 2; |
| 2788 | if (*pos != ' ') |
| 2789 | return -1; |
| 2790 | pos++; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2791 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2792 | } else { |
| 2793 | len = os_strlen(pos); |
| 2794 | if (len & 1) |
| 2795 | return -1; |
| 2796 | len /= 2; |
| 2797 | tlvs = wpabuf_alloc(len); |
| 2798 | if (tlvs == NULL) |
| 2799 | return -1; |
| 2800 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { |
| 2801 | wpabuf_free(tlvs); |
| 2802 | return -1; |
| 2803 | } |
| 2804 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2805 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2806 | wpabuf_free(tlvs); |
| 2807 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2808 | if (ref == 0) |
| 2809 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2810 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); |
| 2811 | if (res < 0 || (unsigned) res >= buflen) |
| 2812 | return -1; |
| 2813 | return res; |
| 2814 | } |
| 2815 | |
| 2816 | |
| 2817 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, |
| 2818 | char *cmd) |
| 2819 | { |
| 2820 | long long unsigned val; |
| 2821 | u64 req; |
| 2822 | if (sscanf(cmd, "%llx", &val) != 1) |
| 2823 | return -1; |
| 2824 | req = val; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2825 | return wpas_p2p_sd_cancel_request(wpa_s, req); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | |
| 2829 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) |
| 2830 | { |
| 2831 | int freq; |
| 2832 | u8 dst[ETH_ALEN]; |
| 2833 | u8 dialog_token; |
| 2834 | struct wpabuf *resp_tlvs; |
| 2835 | char *pos, *pos2; |
| 2836 | size_t len; |
| 2837 | |
| 2838 | pos = os_strchr(cmd, ' '); |
| 2839 | if (pos == NULL) |
| 2840 | return -1; |
| 2841 | *pos++ = '\0'; |
| 2842 | freq = atoi(cmd); |
| 2843 | if (freq == 0) |
| 2844 | return -1; |
| 2845 | |
| 2846 | if (hwaddr_aton(pos, dst)) |
| 2847 | return -1; |
| 2848 | pos += 17; |
| 2849 | if (*pos != ' ') |
| 2850 | return -1; |
| 2851 | pos++; |
| 2852 | |
| 2853 | pos2 = os_strchr(pos, ' '); |
| 2854 | if (pos2 == NULL) |
| 2855 | return -1; |
| 2856 | *pos2++ = '\0'; |
| 2857 | dialog_token = atoi(pos); |
| 2858 | |
| 2859 | len = os_strlen(pos2); |
| 2860 | if (len & 1) |
| 2861 | return -1; |
| 2862 | len /= 2; |
| 2863 | resp_tlvs = wpabuf_alloc(len); |
| 2864 | if (resp_tlvs == NULL) |
| 2865 | return -1; |
| 2866 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { |
| 2867 | wpabuf_free(resp_tlvs); |
| 2868 | return -1; |
| 2869 | } |
| 2870 | |
| 2871 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); |
| 2872 | wpabuf_free(resp_tlvs); |
| 2873 | return 0; |
| 2874 | } |
| 2875 | |
| 2876 | |
| 2877 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, |
| 2878 | char *cmd) |
| 2879 | { |
| 2880 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); |
| 2881 | return 0; |
| 2882 | } |
| 2883 | |
| 2884 | |
| 2885 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, |
| 2886 | char *cmd) |
| 2887 | { |
| 2888 | char *pos; |
| 2889 | size_t len; |
| 2890 | struct wpabuf *query, *resp; |
| 2891 | |
| 2892 | pos = os_strchr(cmd, ' '); |
| 2893 | if (pos == NULL) |
| 2894 | return -1; |
| 2895 | *pos++ = '\0'; |
| 2896 | |
| 2897 | len = os_strlen(cmd); |
| 2898 | if (len & 1) |
| 2899 | return -1; |
| 2900 | len /= 2; |
| 2901 | query = wpabuf_alloc(len); |
| 2902 | if (query == NULL) |
| 2903 | return -1; |
| 2904 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { |
| 2905 | wpabuf_free(query); |
| 2906 | return -1; |
| 2907 | } |
| 2908 | |
| 2909 | len = os_strlen(pos); |
| 2910 | if (len & 1) { |
| 2911 | wpabuf_free(query); |
| 2912 | return -1; |
| 2913 | } |
| 2914 | len /= 2; |
| 2915 | resp = wpabuf_alloc(len); |
| 2916 | if (resp == NULL) { |
| 2917 | wpabuf_free(query); |
| 2918 | return -1; |
| 2919 | } |
| 2920 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { |
| 2921 | wpabuf_free(query); |
| 2922 | wpabuf_free(resp); |
| 2923 | return -1; |
| 2924 | } |
| 2925 | |
| 2926 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { |
| 2927 | wpabuf_free(query); |
| 2928 | wpabuf_free(resp); |
| 2929 | return -1; |
| 2930 | } |
| 2931 | return 0; |
| 2932 | } |
| 2933 | |
| 2934 | |
| 2935 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) |
| 2936 | { |
| 2937 | char *pos; |
| 2938 | u8 version; |
| 2939 | |
| 2940 | pos = os_strchr(cmd, ' '); |
| 2941 | if (pos == NULL) |
| 2942 | return -1; |
| 2943 | *pos++ = '\0'; |
| 2944 | |
| 2945 | if (hexstr2bin(cmd, &version, 1) < 0) |
| 2946 | return -1; |
| 2947 | |
| 2948 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); |
| 2949 | } |
| 2950 | |
| 2951 | |
| 2952 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 2953 | { |
| 2954 | char *pos; |
| 2955 | |
| 2956 | pos = os_strchr(cmd, ' '); |
| 2957 | if (pos == NULL) |
| 2958 | return -1; |
| 2959 | *pos++ = '\0'; |
| 2960 | |
| 2961 | if (os_strcmp(cmd, "bonjour") == 0) |
| 2962 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); |
| 2963 | if (os_strcmp(cmd, "upnp") == 0) |
| 2964 | return p2p_ctrl_service_add_upnp(wpa_s, pos); |
| 2965 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 2966 | return -1; |
| 2967 | } |
| 2968 | |
| 2969 | |
| 2970 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, |
| 2971 | char *cmd) |
| 2972 | { |
| 2973 | size_t len; |
| 2974 | struct wpabuf *query; |
| 2975 | int ret; |
| 2976 | |
| 2977 | len = os_strlen(cmd); |
| 2978 | if (len & 1) |
| 2979 | return -1; |
| 2980 | len /= 2; |
| 2981 | query = wpabuf_alloc(len); |
| 2982 | if (query == NULL) |
| 2983 | return -1; |
| 2984 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { |
| 2985 | wpabuf_free(query); |
| 2986 | return -1; |
| 2987 | } |
| 2988 | |
| 2989 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); |
| 2990 | wpabuf_free(query); |
| 2991 | return ret; |
| 2992 | } |
| 2993 | |
| 2994 | |
| 2995 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) |
| 2996 | { |
| 2997 | char *pos; |
| 2998 | u8 version; |
| 2999 | |
| 3000 | pos = os_strchr(cmd, ' '); |
| 3001 | if (pos == NULL) |
| 3002 | return -1; |
| 3003 | *pos++ = '\0'; |
| 3004 | |
| 3005 | if (hexstr2bin(cmd, &version, 1) < 0) |
| 3006 | return -1; |
| 3007 | |
| 3008 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); |
| 3009 | } |
| 3010 | |
| 3011 | |
| 3012 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) |
| 3013 | { |
| 3014 | char *pos; |
| 3015 | |
| 3016 | pos = os_strchr(cmd, ' '); |
| 3017 | if (pos == NULL) |
| 3018 | return -1; |
| 3019 | *pos++ = '\0'; |
| 3020 | |
| 3021 | if (os_strcmp(cmd, "bonjour") == 0) |
| 3022 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); |
| 3023 | if (os_strcmp(cmd, "upnp") == 0) |
| 3024 | return p2p_ctrl_service_del_upnp(wpa_s, pos); |
| 3025 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 3026 | return -1; |
| 3027 | } |
| 3028 | |
| 3029 | |
| 3030 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) |
| 3031 | { |
| 3032 | u8 addr[ETH_ALEN]; |
| 3033 | |
| 3034 | /* <addr> */ |
| 3035 | |
| 3036 | if (hwaddr_aton(cmd, addr)) |
| 3037 | return -1; |
| 3038 | |
| 3039 | return wpas_p2p_reject(wpa_s, addr); |
| 3040 | } |
| 3041 | |
| 3042 | |
| 3043 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) |
| 3044 | { |
| 3045 | char *pos; |
| 3046 | int id; |
| 3047 | struct wpa_ssid *ssid; |
| 3048 | u8 peer[ETH_ALEN]; |
| 3049 | |
| 3050 | id = atoi(cmd); |
| 3051 | pos = os_strstr(cmd, " peer="); |
| 3052 | if (pos) { |
| 3053 | pos += 6; |
| 3054 | if (hwaddr_aton(pos, peer)) |
| 3055 | return -1; |
| 3056 | } |
| 3057 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3058 | if (ssid == NULL || ssid->disabled != 2) { |
| 3059 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 3060 | "for persistent P2P group", |
| 3061 | id); |
| 3062 | return -1; |
| 3063 | } |
| 3064 | |
| 3065 | return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL); |
| 3066 | } |
| 3067 | |
| 3068 | |
| 3069 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) |
| 3070 | { |
| 3071 | char *pos; |
| 3072 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; |
| 3073 | |
| 3074 | pos = os_strstr(cmd, " peer="); |
| 3075 | if (!pos) |
| 3076 | return -1; |
| 3077 | |
| 3078 | *pos = '\0'; |
| 3079 | pos += 6; |
| 3080 | if (hwaddr_aton(pos, peer)) { |
| 3081 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); |
| 3082 | return -1; |
| 3083 | } |
| 3084 | |
| 3085 | pos = os_strstr(pos, " go_dev_addr="); |
| 3086 | if (pos) { |
| 3087 | pos += 13; |
| 3088 | if (hwaddr_aton(pos, go_dev_addr)) { |
| 3089 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", |
| 3090 | pos); |
| 3091 | return -1; |
| 3092 | } |
| 3093 | go_dev = go_dev_addr; |
| 3094 | } |
| 3095 | |
| 3096 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); |
| 3097 | } |
| 3098 | |
| 3099 | |
| 3100 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) |
| 3101 | { |
| 3102 | if (os_strncmp(cmd, "persistent=", 11) == 0) |
| 3103 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); |
| 3104 | if (os_strncmp(cmd, "group=", 6) == 0) |
| 3105 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); |
| 3106 | |
| 3107 | return -1; |
| 3108 | } |
| 3109 | |
| 3110 | |
| 3111 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, |
| 3112 | char *cmd, int freq) |
| 3113 | { |
| 3114 | int id; |
| 3115 | struct wpa_ssid *ssid; |
| 3116 | |
| 3117 | id = atoi(cmd); |
| 3118 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3119 | if (ssid == NULL || ssid->disabled != 2) { |
| 3120 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 3121 | "for persistent P2P group", |
| 3122 | id); |
| 3123 | return -1; |
| 3124 | } |
| 3125 | |
| 3126 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq); |
| 3127 | } |
| 3128 | |
| 3129 | |
| 3130 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 3131 | { |
| 3132 | int freq = 0; |
| 3133 | char *pos; |
| 3134 | |
| 3135 | pos = os_strstr(cmd, "freq="); |
| 3136 | if (pos) |
| 3137 | freq = atoi(pos + 5); |
| 3138 | |
| 3139 | if (os_strncmp(cmd, "persistent=", 11) == 0) |
| 3140 | return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq); |
| 3141 | if (os_strcmp(cmd, "persistent") == 0 || |
| 3142 | os_strncmp(cmd, "persistent ", 11) == 0) |
| 3143 | return wpas_p2p_group_add(wpa_s, 1, freq); |
| 3144 | if (os_strncmp(cmd, "freq=", 5) == 0) |
| 3145 | return wpas_p2p_group_add(wpa_s, 0, freq); |
| 3146 | |
| 3147 | wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'", |
| 3148 | cmd); |
| 3149 | return -1; |
| 3150 | } |
| 3151 | |
| 3152 | |
| 3153 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, |
| 3154 | char *buf, size_t buflen) |
| 3155 | { |
| 3156 | u8 addr[ETH_ALEN], *addr_ptr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3157 | int next, res; |
| 3158 | const struct p2p_peer_info *info; |
| 3159 | char *pos, *end; |
| 3160 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
| 3161 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3162 | |
| 3163 | if (!wpa_s->global->p2p) |
| 3164 | return -1; |
| 3165 | |
| 3166 | if (os_strcmp(cmd, "FIRST") == 0) { |
| 3167 | addr_ptr = NULL; |
| 3168 | next = 0; |
| 3169 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { |
| 3170 | if (hwaddr_aton(cmd + 5, addr) < 0) |
| 3171 | return -1; |
| 3172 | addr_ptr = addr; |
| 3173 | next = 1; |
| 3174 | } else { |
| 3175 | if (hwaddr_aton(cmd, addr) < 0) |
| 3176 | return -1; |
| 3177 | addr_ptr = addr; |
| 3178 | next = 0; |
| 3179 | } |
| 3180 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3181 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); |
| 3182 | if (info == NULL) |
| 3183 | return -1; |
| 3184 | |
| 3185 | pos = buf; |
| 3186 | end = buf + buflen; |
| 3187 | |
| 3188 | res = os_snprintf(pos, end - pos, MACSTR "\n" |
| 3189 | "pri_dev_type=%s\n" |
| 3190 | "device_name=%s\n" |
| 3191 | "manufacturer=%s\n" |
| 3192 | "model_name=%s\n" |
| 3193 | "model_number=%s\n" |
| 3194 | "serial_number=%s\n" |
| 3195 | "config_methods=0x%x\n" |
| 3196 | "dev_capab=0x%x\n" |
| 3197 | "group_capab=0x%x\n" |
| 3198 | "level=%d\n", |
| 3199 | MAC2STR(info->p2p_device_addr), |
| 3200 | wps_dev_type_bin2str(info->pri_dev_type, |
| 3201 | devtype, sizeof(devtype)), |
| 3202 | info->device_name, |
| 3203 | info->manufacturer, |
| 3204 | info->model_name, |
| 3205 | info->model_number, |
| 3206 | info->serial_number, |
| 3207 | info->config_methods, |
| 3208 | info->dev_capab, |
| 3209 | info->group_capab, |
| 3210 | info->level); |
| 3211 | if (res < 0 || res >= end - pos) |
| 3212 | return pos - buf; |
| 3213 | pos += res; |
| 3214 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3215 | 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] | 3216 | if (ssid) { |
| 3217 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); |
| 3218 | if (res < 0 || res >= end - pos) |
| 3219 | return pos - buf; |
| 3220 | pos += res; |
| 3221 | } |
| 3222 | |
| 3223 | res = p2p_get_peer_info_txt(info, pos, end - pos); |
| 3224 | if (res < 0) |
| 3225 | return pos - buf; |
| 3226 | pos += res; |
| 3227 | |
| 3228 | return pos - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | |
| 3232 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) |
| 3233 | { |
| 3234 | char *param; |
| 3235 | |
| 3236 | if (wpa_s->global->p2p == NULL) |
| 3237 | return -1; |
| 3238 | |
| 3239 | param = os_strchr(cmd, ' '); |
| 3240 | if (param == NULL) |
| 3241 | return -1; |
| 3242 | *param++ = '\0'; |
| 3243 | |
| 3244 | if (os_strcmp(cmd, "discoverability") == 0) { |
| 3245 | p2p_set_client_discoverability(wpa_s->global->p2p, |
| 3246 | atoi(param)); |
| 3247 | return 0; |
| 3248 | } |
| 3249 | |
| 3250 | if (os_strcmp(cmd, "managed") == 0) { |
| 3251 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); |
| 3252 | return 0; |
| 3253 | } |
| 3254 | |
| 3255 | if (os_strcmp(cmd, "listen_channel") == 0) { |
| 3256 | return p2p_set_listen_channel(wpa_s->global->p2p, 81, |
| 3257 | atoi(param)); |
| 3258 | } |
| 3259 | |
| 3260 | if (os_strcmp(cmd, "ssid_postfix") == 0) { |
| 3261 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, |
| 3262 | os_strlen(param)); |
| 3263 | } |
| 3264 | |
| 3265 | if (os_strcmp(cmd, "noa") == 0) { |
| 3266 | char *pos; |
| 3267 | int count, start, duration; |
| 3268 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ |
| 3269 | count = atoi(param); |
| 3270 | pos = os_strchr(param, ','); |
| 3271 | if (pos == NULL) |
| 3272 | return -1; |
| 3273 | pos++; |
| 3274 | start = atoi(pos); |
| 3275 | pos = os_strchr(pos, ','); |
| 3276 | if (pos == NULL) |
| 3277 | return -1; |
| 3278 | pos++; |
| 3279 | duration = atoi(pos); |
| 3280 | if (count < 0 || count > 255 || start < 0 || duration < 0) |
| 3281 | return -1; |
| 3282 | if (count == 0 && duration > 0) |
| 3283 | return -1; |
| 3284 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " |
| 3285 | "start=%d duration=%d", count, start, duration); |
| 3286 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
| 3287 | } |
| 3288 | |
| 3289 | if (os_strcmp(cmd, "ps") == 0) |
| 3290 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); |
| 3291 | |
| 3292 | if (os_strcmp(cmd, "oppps") == 0) |
| 3293 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); |
| 3294 | |
| 3295 | if (os_strcmp(cmd, "ctwindow") == 0) |
| 3296 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); |
| 3297 | |
| 3298 | if (os_strcmp(cmd, "disabled") == 0) { |
| 3299 | wpa_s->global->p2p_disabled = atoi(param); |
| 3300 | wpa_printf(MSG_DEBUG, "P2P functionality %s", |
| 3301 | wpa_s->global->p2p_disabled ? |
| 3302 | "disabled" : "enabled"); |
| 3303 | if (wpa_s->global->p2p_disabled) { |
| 3304 | wpas_p2p_stop_find(wpa_s); |
| 3305 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
| 3306 | p2p_flush(wpa_s->global->p2p); |
| 3307 | } |
| 3308 | return 0; |
| 3309 | } |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 3310 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 3311 | if (os_strcmp(cmd, "conc_pref") == 0) { |
| 3312 | if (os_strcmp(param, "sta") == 0) |
| 3313 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; |
| 3314 | else if (os_strcmp(param, "p2p") == 0) |
| 3315 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 3316 | else { |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 3317 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 3318 | return -1; |
| 3319 | } |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 3320 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " |
| 3321 | "%s", param); |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 3322 | return 0; |
| 3323 | } |
| 3324 | #endif |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3325 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
| 3326 | wpa_s->force_long_sd = atoi(param); |
| 3327 | return 0; |
| 3328 | } |
| 3329 | |
| 3330 | if (os_strcmp(cmd, "peer_filter") == 0) { |
| 3331 | u8 addr[ETH_ALEN]; |
| 3332 | if (hwaddr_aton(param, addr)) |
| 3333 | return -1; |
| 3334 | p2p_set_peer_filter(wpa_s->global->p2p, addr); |
| 3335 | return 0; |
| 3336 | } |
| 3337 | |
| 3338 | if (os_strcmp(cmd, "cross_connect") == 0) |
| 3339 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); |
| 3340 | |
| 3341 | if (os_strcmp(cmd, "go_apsd") == 0) { |
| 3342 | if (os_strcmp(param, "disable") == 0) |
| 3343 | wpa_s->set_ap_uapsd = 0; |
| 3344 | else { |
| 3345 | wpa_s->set_ap_uapsd = 1; |
| 3346 | wpa_s->ap_uapsd = atoi(param); |
| 3347 | } |
| 3348 | return 0; |
| 3349 | } |
| 3350 | |
| 3351 | if (os_strcmp(cmd, "client_apsd") == 0) { |
| 3352 | if (os_strcmp(param, "disable") == 0) |
| 3353 | wpa_s->set_sta_uapsd = 0; |
| 3354 | else { |
| 3355 | int be, bk, vi, vo; |
| 3356 | char *pos; |
| 3357 | /* format: BE,BK,VI,VO;max SP Length */ |
| 3358 | be = atoi(param); |
| 3359 | pos = os_strchr(param, ','); |
| 3360 | if (pos == NULL) |
| 3361 | return -1; |
| 3362 | pos++; |
| 3363 | bk = atoi(pos); |
| 3364 | pos = os_strchr(pos, ','); |
| 3365 | if (pos == NULL) |
| 3366 | return -1; |
| 3367 | pos++; |
| 3368 | vi = atoi(pos); |
| 3369 | pos = os_strchr(pos, ','); |
| 3370 | if (pos == NULL) |
| 3371 | return -1; |
| 3372 | pos++; |
| 3373 | vo = atoi(pos); |
| 3374 | /* ignore max SP Length for now */ |
| 3375 | |
| 3376 | wpa_s->set_sta_uapsd = 1; |
| 3377 | wpa_s->sta_uapsd = 0; |
| 3378 | if (be) |
| 3379 | wpa_s->sta_uapsd |= BIT(0); |
| 3380 | if (bk) |
| 3381 | wpa_s->sta_uapsd |= BIT(1); |
| 3382 | if (vi) |
| 3383 | wpa_s->sta_uapsd |= BIT(2); |
| 3384 | if (vo) |
| 3385 | wpa_s->sta_uapsd |= BIT(3); |
| 3386 | } |
| 3387 | return 0; |
| 3388 | } |
| 3389 | |
| 3390 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
| 3391 | cmd); |
| 3392 | |
| 3393 | return -1; |
| 3394 | } |
| 3395 | |
| 3396 | |
| 3397 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) |
| 3398 | { |
| 3399 | char *pos, *pos2; |
| 3400 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; |
| 3401 | |
| 3402 | if (cmd[0]) { |
| 3403 | pos = os_strchr(cmd, ' '); |
| 3404 | if (pos == NULL) |
| 3405 | return -1; |
| 3406 | *pos++ = '\0'; |
| 3407 | dur1 = atoi(cmd); |
| 3408 | |
| 3409 | pos2 = os_strchr(pos, ' '); |
| 3410 | if (pos2) |
| 3411 | *pos2++ = '\0'; |
| 3412 | int1 = atoi(pos); |
| 3413 | } else |
| 3414 | pos2 = NULL; |
| 3415 | |
| 3416 | if (pos2) { |
| 3417 | pos = os_strchr(pos2, ' '); |
| 3418 | if (pos == NULL) |
| 3419 | return -1; |
| 3420 | *pos++ = '\0'; |
| 3421 | dur2 = atoi(pos2); |
| 3422 | int2 = atoi(pos); |
| 3423 | } |
| 3424 | |
| 3425 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); |
| 3426 | } |
| 3427 | |
| 3428 | |
| 3429 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) |
| 3430 | { |
| 3431 | char *pos; |
| 3432 | unsigned int period = 0, interval = 0; |
| 3433 | |
| 3434 | if (cmd[0]) { |
| 3435 | pos = os_strchr(cmd, ' '); |
| 3436 | if (pos == NULL) |
| 3437 | return -1; |
| 3438 | *pos++ = '\0'; |
| 3439 | period = atoi(cmd); |
| 3440 | interval = atoi(pos); |
| 3441 | } |
| 3442 | |
| 3443 | return wpas_p2p_ext_listen(wpa_s, period, interval); |
| 3444 | } |
| 3445 | |
| 3446 | #endif /* CONFIG_P2P */ |
| 3447 | |
| 3448 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3449 | #ifdef CONFIG_INTERWORKING |
| 3450 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst) |
| 3451 | { |
| 3452 | u8 bssid[ETH_ALEN]; |
| 3453 | struct wpa_bss *bss; |
| 3454 | |
| 3455 | if (hwaddr_aton(dst, bssid)) { |
| 3456 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); |
| 3457 | return -1; |
| 3458 | } |
| 3459 | |
| 3460 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 3461 | if (bss == NULL) { |
| 3462 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, |
| 3463 | MAC2STR(bssid)); |
| 3464 | return -1; |
| 3465 | } |
| 3466 | |
| 3467 | return interworking_connect(wpa_s, bss); |
| 3468 | } |
| 3469 | |
| 3470 | |
| 3471 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) |
| 3472 | { |
| 3473 | u8 dst_addr[ETH_ALEN]; |
| 3474 | int used; |
| 3475 | char *pos; |
| 3476 | #define MAX_ANQP_INFO_ID 100 |
| 3477 | u16 id[MAX_ANQP_INFO_ID]; |
| 3478 | size_t num_id = 0; |
| 3479 | |
| 3480 | used = hwaddr_aton2(dst, dst_addr); |
| 3481 | if (used < 0) |
| 3482 | return -1; |
| 3483 | pos = dst + used; |
| 3484 | while (num_id < MAX_ANQP_INFO_ID) { |
| 3485 | id[num_id] = atoi(pos); |
| 3486 | if (id[num_id]) |
| 3487 | num_id++; |
| 3488 | pos = os_strchr(pos + 1, ','); |
| 3489 | if (pos == NULL) |
| 3490 | break; |
| 3491 | pos++; |
| 3492 | } |
| 3493 | |
| 3494 | if (num_id == 0) |
| 3495 | return -1; |
| 3496 | |
| 3497 | return anqp_send_req(wpa_s, dst_addr, id, num_id); |
| 3498 | } |
| 3499 | #endif /* CONFIG_INTERWORKING */ |
| 3500 | |
| 3501 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3502 | static int wpa_supplicant_ctrl_iface_sta_autoconnect( |
| 3503 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3504 | { |
| 3505 | wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0; |
| 3506 | return 0; |
| 3507 | } |
| 3508 | |
| 3509 | |
| 3510 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
| 3511 | size_t buflen) |
| 3512 | { |
| 3513 | struct wpa_signal_info si; |
| 3514 | int ret; |
| 3515 | |
| 3516 | ret = wpa_drv_signal_poll(wpa_s, &si); |
| 3517 | if (ret) |
| 3518 | return -1; |
| 3519 | |
| 3520 | ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n" |
| 3521 | "NOISE=%d\nFREQUENCY=%u\n", |
| 3522 | si.current_signal, si.current_txrate / 1000, |
| 3523 | si.current_noise, si.frequency); |
| 3524 | if (ret < 0 || (unsigned int) ret > buflen) |
| 3525 | return -1; |
| 3526 | return ret; |
| 3527 | } |
| 3528 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3529 | #ifdef ANDROID |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 3530 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
| 3531 | char *buf, size_t buflen) |
| 3532 | { |
| 3533 | int ret; |
| 3534 | |
| 3535 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); |
| 3536 | if (ret == 0) |
| 3537 | ret = sprintf(buf, "%s\n", "OK"); |
| 3538 | return ret; |
| 3539 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3540 | #endif |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 3541 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3542 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
| 3543 | char *buf, size_t *resp_len) |
| 3544 | { |
| 3545 | char *reply; |
| 3546 | const int reply_size = 4096; |
| 3547 | int ctrl_rsp = 0; |
| 3548 | int reply_len; |
| 3549 | |
| 3550 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || |
| 3551 | os_strncmp(buf, "SET_NETWORK ", 12) == 0) { |
| 3552 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", |
| 3553 | (const u8 *) buf, os_strlen(buf)); |
| 3554 | } else { |
| 3555 | int level = MSG_DEBUG; |
| 3556 | if (os_strcmp(buf, "PING") == 0) |
| 3557 | level = MSG_EXCESSIVE; |
| 3558 | wpa_hexdump_ascii(level, "RX ctrl_iface", |
| 3559 | (const u8 *) buf, os_strlen(buf)); |
| 3560 | } |
| 3561 | |
| 3562 | reply = os_malloc(reply_size); |
| 3563 | if (reply == NULL) { |
| 3564 | *resp_len = 1; |
| 3565 | return NULL; |
| 3566 | } |
| 3567 | |
| 3568 | os_memcpy(reply, "OK\n", 3); |
| 3569 | reply_len = 3; |
| 3570 | |
| 3571 | if (os_strcmp(buf, "PING") == 0) { |
| 3572 | os_memcpy(reply, "PONG\n", 5); |
| 3573 | reply_len = 5; |
| 3574 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
| 3575 | if (wpa_debug_reopen_file() < 0) |
| 3576 | reply_len = -1; |
| 3577 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
| 3578 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); |
| 3579 | } else if (os_strcmp(buf, "MIB") == 0) { |
| 3580 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); |
| 3581 | if (reply_len >= 0) { |
| 3582 | int res; |
| 3583 | res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len, |
| 3584 | reply_size - reply_len); |
| 3585 | if (res < 0) |
| 3586 | reply_len = -1; |
| 3587 | else |
| 3588 | reply_len += res; |
| 3589 | } |
| 3590 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { |
| 3591 | reply_len = wpa_supplicant_ctrl_iface_status( |
| 3592 | wpa_s, buf + 6, reply, reply_size); |
| 3593 | } else if (os_strcmp(buf, "PMKSA") == 0) { |
| 3594 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply, |
| 3595 | reply_size); |
| 3596 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
| 3597 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) |
| 3598 | reply_len = -1; |
| 3599 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
| 3600 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, |
| 3601 | reply, reply_size); |
| 3602 | } else if (os_strcmp(buf, "LOGON") == 0) { |
| 3603 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); |
| 3604 | } else if (os_strcmp(buf, "LOGOFF") == 0) { |
| 3605 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); |
| 3606 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3607 | wpa_s->normal_scans = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3608 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 3609 | reply_len = -1; |
| 3610 | else { |
| 3611 | wpa_s->disconnected = 0; |
| 3612 | wpa_s->reassociate = 1; |
| 3613 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 3614 | } |
| 3615 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3616 | wpa_s->normal_scans = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3617 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 3618 | reply_len = -1; |
| 3619 | else if (wpa_s->disconnected) { |
| 3620 | wpa_s->disconnected = 0; |
| 3621 | wpa_s->reassociate = 1; |
| 3622 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 3623 | } |
| 3624 | #ifdef IEEE8021X_EAPOL |
| 3625 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
| 3626 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) |
| 3627 | reply_len = -1; |
| 3628 | #endif /* IEEE8021X_EAPOL */ |
| 3629 | #ifdef CONFIG_PEERKEY |
| 3630 | } else if (os_strncmp(buf, "STKSTART ", 9) == 0) { |
| 3631 | if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9)) |
| 3632 | reply_len = -1; |
| 3633 | #endif /* CONFIG_PEERKEY */ |
| 3634 | #ifdef CONFIG_IEEE80211R |
| 3635 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { |
| 3636 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) |
| 3637 | reply_len = -1; |
| 3638 | #endif /* CONFIG_IEEE80211R */ |
| 3639 | #ifdef CONFIG_WPS |
| 3640 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { |
| 3641 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
| 3642 | if (res == -2) { |
| 3643 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 3644 | reply_len = 17; |
| 3645 | } else if (res) |
| 3646 | reply_len = -1; |
| 3647 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { |
| 3648 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
| 3649 | if (res == -2) { |
| 3650 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 3651 | reply_len = 17; |
| 3652 | } else if (res) |
| 3653 | reply_len = -1; |
| 3654 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { |
| 3655 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, |
| 3656 | reply, |
| 3657 | reply_size); |
| 3658 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
| 3659 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( |
| 3660 | wpa_s, buf + 14, reply, reply_size); |
| 3661 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
| 3662 | if (wpas_wps_cancel(wpa_s)) |
| 3663 | reply_len = -1; |
| 3664 | #ifdef CONFIG_WPS_OOB |
| 3665 | } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) { |
| 3666 | if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8)) |
| 3667 | reply_len = -1; |
| 3668 | #endif /* CONFIG_WPS_OOB */ |
| 3669 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
| 3670 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) |
| 3671 | reply_len = -1; |
| 3672 | #ifdef CONFIG_AP |
| 3673 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { |
| 3674 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( |
| 3675 | wpa_s, buf + 11, reply, reply_size); |
| 3676 | #endif /* CONFIG_AP */ |
| 3677 | #ifdef CONFIG_WPS_ER |
| 3678 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
| 3679 | if (wpas_wps_er_start(wpa_s, NULL)) |
| 3680 | reply_len = -1; |
| 3681 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { |
| 3682 | if (wpas_wps_er_start(wpa_s, buf + 13)) |
| 3683 | reply_len = -1; |
| 3684 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { |
| 3685 | if (wpas_wps_er_stop(wpa_s)) |
| 3686 | reply_len = -1; |
| 3687 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
| 3688 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) |
| 3689 | reply_len = -1; |
| 3690 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
| 3691 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
| 3692 | if (ret == -2) { |
| 3693 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 3694 | reply_len = 17; |
| 3695 | } else if (ret == -3) { |
| 3696 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); |
| 3697 | reply_len = 18; |
| 3698 | } else if (ret == -4) { |
| 3699 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); |
| 3700 | reply_len = 20; |
| 3701 | } else if (ret) |
| 3702 | reply_len = -1; |
| 3703 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
| 3704 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) |
| 3705 | reply_len = -1; |
| 3706 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
| 3707 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, |
| 3708 | buf + 18)) |
| 3709 | reply_len = -1; |
| 3710 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
| 3711 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) |
| 3712 | reply_len = -1; |
| 3713 | #endif /* CONFIG_WPS_ER */ |
| 3714 | #endif /* CONFIG_WPS */ |
| 3715 | #ifdef CONFIG_IBSS_RSN |
| 3716 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { |
| 3717 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) |
| 3718 | reply_len = -1; |
| 3719 | #endif /* CONFIG_IBSS_RSN */ |
| 3720 | #ifdef CONFIG_P2P |
| 3721 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { |
| 3722 | if (p2p_ctrl_find(wpa_s, buf + 9)) |
| 3723 | reply_len = -1; |
| 3724 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { |
| 3725 | if (p2p_ctrl_find(wpa_s, "")) |
| 3726 | reply_len = -1; |
| 3727 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { |
| 3728 | wpas_p2p_stop_find(wpa_s); |
| 3729 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { |
| 3730 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, |
| 3731 | reply_size); |
| 3732 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { |
| 3733 | if (p2p_ctrl_listen(wpa_s, buf + 11)) |
| 3734 | reply_len = -1; |
| 3735 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { |
| 3736 | if (p2p_ctrl_listen(wpa_s, "")) |
| 3737 | reply_len = -1; |
| 3738 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { |
| 3739 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) |
| 3740 | reply_len = -1; |
| 3741 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { |
| 3742 | if (wpas_p2p_group_add(wpa_s, 0, 0)) |
| 3743 | reply_len = -1; |
| 3744 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { |
| 3745 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) |
| 3746 | reply_len = -1; |
| 3747 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { |
| 3748 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) |
| 3749 | reply_len = -1; |
| 3750 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { |
| 3751 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); |
| 3752 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { |
| 3753 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, |
| 3754 | reply_size); |
| 3755 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { |
| 3756 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) |
| 3757 | reply_len = -1; |
| 3758 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { |
| 3759 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) |
| 3760 | reply_len = -1; |
| 3761 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { |
| 3762 | wpas_p2p_sd_service_update(wpa_s); |
| 3763 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { |
| 3764 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) |
| 3765 | reply_len = -1; |
| 3766 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { |
| 3767 | wpas_p2p_service_flush(wpa_s); |
| 3768 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { |
| 3769 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) |
| 3770 | reply_len = -1; |
| 3771 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { |
| 3772 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) |
| 3773 | reply_len = -1; |
| 3774 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { |
| 3775 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) |
| 3776 | reply_len = -1; |
| 3777 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { |
| 3778 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) |
| 3779 | reply_len = -1; |
| 3780 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { |
| 3781 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, |
| 3782 | reply_size); |
| 3783 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { |
| 3784 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) |
| 3785 | reply_len = -1; |
| 3786 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { |
| 3787 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
| 3788 | wpa_s->force_long_sd = 0; |
| 3789 | if (wpa_s->global->p2p) |
| 3790 | p2p_flush(wpa_s->global->p2p); |
| 3791 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
| 3792 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) |
| 3793 | reply_len = -1; |
| 3794 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
| 3795 | if (wpas_p2p_cancel(wpa_s)) |
| 3796 | reply_len = -1; |
| 3797 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
| 3798 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) |
| 3799 | reply_len = -1; |
| 3800 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { |
| 3801 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) |
| 3802 | reply_len = -1; |
| 3803 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { |
| 3804 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) |
| 3805 | reply_len = -1; |
| 3806 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { |
| 3807 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) |
| 3808 | reply_len = -1; |
| 3809 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3810 | #ifdef CONFIG_INTERWORKING |
| 3811 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { |
| 3812 | if (interworking_fetch_anqp(wpa_s) < 0) |
| 3813 | reply_len = -1; |
| 3814 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { |
| 3815 | interworking_stop_fetch_anqp(wpa_s); |
| 3816 | } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) { |
| 3817 | if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") != |
| 3818 | NULL) < 0) |
| 3819 | reply_len = -1; |
| 3820 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { |
| 3821 | if (ctrl_interworking_connect(wpa_s, buf + 21) < 0) |
| 3822 | reply_len = -1; |
| 3823 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { |
| 3824 | if (get_anqp(wpa_s, buf + 9) < 0) |
| 3825 | reply_len = -1; |
| 3826 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3827 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
| 3828 | { |
| 3829 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( |
| 3830 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) |
| 3831 | reply_len = -1; |
| 3832 | else |
| 3833 | ctrl_rsp = 1; |
| 3834 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { |
| 3835 | if (wpa_supplicant_reload_configuration(wpa_s)) |
| 3836 | reply_len = -1; |
| 3837 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
| 3838 | wpa_supplicant_terminate_proc(wpa_s->global); |
| 3839 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
| 3840 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) |
| 3841 | reply_len = -1; |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 3842 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3843 | reply_len = wpa_supplicant_ctrl_iface_blacklist( |
| 3844 | wpa_s, buf + 9, reply, reply_size); |
| 3845 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { |
| 3846 | reply_len = wpa_supplicant_ctrl_iface_log_level( |
| 3847 | wpa_s, buf + 9, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3848 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { |
| 3849 | reply_len = wpa_supplicant_ctrl_iface_list_networks( |
| 3850 | wpa_s, reply, reply_size); |
| 3851 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { |
| 3852 | wpa_s->reassociate = 0; |
| 3853 | wpa_s->disconnected = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3854 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3855 | wpa_supplicant_deauthenticate(wpa_s, |
| 3856 | WLAN_REASON_DEAUTH_LEAVING); |
| 3857 | } else if (os_strcmp(buf, "SCAN") == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3858 | wpa_s->normal_scans = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3859 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 3860 | reply_len = -1; |
| 3861 | else { |
| 3862 | if (!wpa_s->scanning && |
| 3863 | ((wpa_s->wpa_state <= WPA_SCANNING) || |
| 3864 | (wpa_s->wpa_state == WPA_COMPLETED))) { |
| 3865 | wpa_s->scan_req = 2; |
| 3866 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 3867 | } else { |
| 3868 | wpa_printf(MSG_DEBUG, "Ongoing scan action - " |
| 3869 | "reject new request"); |
| 3870 | reply_len = os_snprintf(reply, reply_size, |
| 3871 | "FAIL-BUSY\n"); |
| 3872 | } |
| 3873 | } |
| 3874 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
| 3875 | reply_len = wpa_supplicant_ctrl_iface_scan_results( |
| 3876 | wpa_s, reply, reply_size); |
| 3877 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { |
| 3878 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) |
| 3879 | reply_len = -1; |
| 3880 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { |
| 3881 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) |
| 3882 | reply_len = -1; |
| 3883 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { |
| 3884 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) |
| 3885 | reply_len = -1; |
| 3886 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { |
| 3887 | reply_len = wpa_supplicant_ctrl_iface_add_network( |
| 3888 | wpa_s, reply, reply_size); |
| 3889 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { |
| 3890 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) |
| 3891 | reply_len = -1; |
| 3892 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { |
| 3893 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) |
| 3894 | reply_len = -1; |
| 3895 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { |
| 3896 | reply_len = wpa_supplicant_ctrl_iface_get_network( |
| 3897 | wpa_s, buf + 12, reply, reply_size); |
| 3898 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 3899 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { |
| 3900 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) |
| 3901 | reply_len = -1; |
| 3902 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 3903 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { |
| 3904 | reply_len = wpa_supplicant_ctrl_iface_get_capability( |
| 3905 | wpa_s, buf + 15, reply, reply_size); |
| 3906 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { |
| 3907 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) |
| 3908 | reply_len = -1; |
| 3909 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
| 3910 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) |
| 3911 | reply_len = -1; |
| 3912 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
| 3913 | reply_len = wpa_supplicant_global_iface_list( |
| 3914 | wpa_s->global, reply, reply_size); |
| 3915 | } else if (os_strcmp(buf, "INTERFACES") == 0) { |
| 3916 | reply_len = wpa_supplicant_global_iface_interfaces( |
| 3917 | wpa_s->global, reply, reply_size); |
| 3918 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { |
| 3919 | reply_len = wpa_supplicant_ctrl_iface_bss( |
| 3920 | wpa_s, buf + 4, reply, reply_size); |
| 3921 | #ifdef CONFIG_AP |
| 3922 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { |
| 3923 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); |
| 3924 | } else if (os_strncmp(buf, "STA ", 4) == 0) { |
| 3925 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, |
| 3926 | reply_size); |
| 3927 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { |
| 3928 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, |
| 3929 | reply_size); |
| 3930 | #endif /* CONFIG_AP */ |
| 3931 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
| 3932 | wpas_notify_suspend(wpa_s->global); |
| 3933 | } else if (os_strcmp(buf, "RESUME") == 0) { |
| 3934 | wpas_notify_resume(wpa_s->global); |
| 3935 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
| 3936 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); |
| 3937 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
| 3938 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) |
| 3939 | reply_len = -1; |
| 3940 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
| 3941 | if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16)) |
| 3942 | reply_len = -1; |
| 3943 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
| 3944 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) |
| 3945 | reply_len = -1; |
| 3946 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { |
| 3947 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, |
| 3948 | buf + 17)) |
| 3949 | reply_len = -1; |
| 3950 | #ifdef CONFIG_TDLS |
| 3951 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { |
| 3952 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) |
| 3953 | reply_len = -1; |
| 3954 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { |
| 3955 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) |
| 3956 | reply_len = -1; |
| 3957 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { |
| 3958 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) |
| 3959 | reply_len = -1; |
| 3960 | #endif /* CONFIG_TDLS */ |
| 3961 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
| 3962 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, |
| 3963 | reply_size); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3964 | #ifdef ANDROID |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 3965 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { |
| 3966 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, |
| 3967 | reply_size); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3968 | #endif |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3969 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { |
| 3970 | eapol_sm_request_reauth(wpa_s->eapol); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3971 | } else { |
| 3972 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 3973 | reply_len = 16; |
| 3974 | } |
| 3975 | |
| 3976 | if (reply_len < 0) { |
| 3977 | os_memcpy(reply, "FAIL\n", 5); |
| 3978 | reply_len = 5; |
| 3979 | } |
| 3980 | |
| 3981 | if (ctrl_rsp) |
| 3982 | eapol_sm_notify_ctrl_response(wpa_s->eapol); |
| 3983 | |
| 3984 | *resp_len = reply_len; |
| 3985 | return reply; |
| 3986 | } |
| 3987 | |
| 3988 | |
| 3989 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, |
| 3990 | char *cmd) |
| 3991 | { |
| 3992 | struct wpa_interface iface; |
| 3993 | char *pos; |
| 3994 | |
| 3995 | /* |
| 3996 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> |
| 3997 | * TAB<bridge_ifname> |
| 3998 | */ |
| 3999 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); |
| 4000 | |
| 4001 | os_memset(&iface, 0, sizeof(iface)); |
| 4002 | |
| 4003 | do { |
| 4004 | iface.ifname = pos = cmd; |
| 4005 | pos = os_strchr(pos, '\t'); |
| 4006 | if (pos) |
| 4007 | *pos++ = '\0'; |
| 4008 | if (iface.ifname[0] == '\0') |
| 4009 | return -1; |
| 4010 | if (pos == NULL) |
| 4011 | break; |
| 4012 | |
| 4013 | iface.confname = pos; |
| 4014 | pos = os_strchr(pos, '\t'); |
| 4015 | if (pos) |
| 4016 | *pos++ = '\0'; |
| 4017 | if (iface.confname[0] == '\0') |
| 4018 | iface.confname = NULL; |
| 4019 | if (pos == NULL) |
| 4020 | break; |
| 4021 | |
| 4022 | iface.driver = pos; |
| 4023 | pos = os_strchr(pos, '\t'); |
| 4024 | if (pos) |
| 4025 | *pos++ = '\0'; |
| 4026 | if (iface.driver[0] == '\0') |
| 4027 | iface.driver = NULL; |
| 4028 | if (pos == NULL) |
| 4029 | break; |
| 4030 | |
| 4031 | iface.ctrl_interface = pos; |
| 4032 | pos = os_strchr(pos, '\t'); |
| 4033 | if (pos) |
| 4034 | *pos++ = '\0'; |
| 4035 | if (iface.ctrl_interface[0] == '\0') |
| 4036 | iface.ctrl_interface = NULL; |
| 4037 | if (pos == NULL) |
| 4038 | break; |
| 4039 | |
| 4040 | iface.driver_param = pos; |
| 4041 | pos = os_strchr(pos, '\t'); |
| 4042 | if (pos) |
| 4043 | *pos++ = '\0'; |
| 4044 | if (iface.driver_param[0] == '\0') |
| 4045 | iface.driver_param = NULL; |
| 4046 | if (pos == NULL) |
| 4047 | break; |
| 4048 | |
| 4049 | iface.bridge_ifname = pos; |
| 4050 | pos = os_strchr(pos, '\t'); |
| 4051 | if (pos) |
| 4052 | *pos++ = '\0'; |
| 4053 | if (iface.bridge_ifname[0] == '\0') |
| 4054 | iface.bridge_ifname = NULL; |
| 4055 | if (pos == NULL) |
| 4056 | break; |
| 4057 | } while (0); |
| 4058 | |
| 4059 | if (wpa_supplicant_get_iface(global, iface.ifname)) |
| 4060 | return -1; |
| 4061 | |
| 4062 | return wpa_supplicant_add_iface(global, &iface) ? 0 : -1; |
| 4063 | } |
| 4064 | |
| 4065 | |
| 4066 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, |
| 4067 | char *cmd) |
| 4068 | { |
| 4069 | struct wpa_supplicant *wpa_s; |
| 4070 | |
| 4071 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); |
| 4072 | |
| 4073 | wpa_s = wpa_supplicant_get_iface(global, cmd); |
| 4074 | if (wpa_s == NULL) |
| 4075 | return -1; |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 4076 | return wpa_supplicant_remove_iface(global, wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | |
| 4080 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
| 4081 | { |
| 4082 | struct wpa_interface_info *prev; |
| 4083 | |
| 4084 | while (iface) { |
| 4085 | prev = iface; |
| 4086 | iface = iface->next; |
| 4087 | |
| 4088 | os_free(prev->ifname); |
| 4089 | os_free(prev->desc); |
| 4090 | os_free(prev); |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | |
| 4095 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
| 4096 | char *buf, int len) |
| 4097 | { |
| 4098 | int i, res; |
| 4099 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; |
| 4100 | char *pos, *end; |
| 4101 | |
| 4102 | for (i = 0; wpa_drivers[i]; i++) { |
| 4103 | struct wpa_driver_ops *drv = wpa_drivers[i]; |
| 4104 | if (drv->get_interfaces == NULL) |
| 4105 | continue; |
| 4106 | tmp = drv->get_interfaces(global->drv_priv[i]); |
| 4107 | if (tmp == NULL) |
| 4108 | continue; |
| 4109 | |
| 4110 | if (last == NULL) |
| 4111 | iface = last = tmp; |
| 4112 | else |
| 4113 | last->next = tmp; |
| 4114 | while (last->next) |
| 4115 | last = last->next; |
| 4116 | } |
| 4117 | |
| 4118 | pos = buf; |
| 4119 | end = buf + len; |
| 4120 | for (tmp = iface; tmp; tmp = tmp->next) { |
| 4121 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", |
| 4122 | tmp->drv_name, tmp->ifname, |
| 4123 | tmp->desc ? tmp->desc : ""); |
| 4124 | if (res < 0 || res >= end - pos) { |
| 4125 | *pos = '\0'; |
| 4126 | break; |
| 4127 | } |
| 4128 | pos += res; |
| 4129 | } |
| 4130 | |
| 4131 | wpa_free_iface_info(iface); |
| 4132 | |
| 4133 | return pos - buf; |
| 4134 | } |
| 4135 | |
| 4136 | |
| 4137 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
| 4138 | char *buf, int len) |
| 4139 | { |
| 4140 | int res; |
| 4141 | char *pos, *end; |
| 4142 | struct wpa_supplicant *wpa_s; |
| 4143 | |
| 4144 | wpa_s = global->ifaces; |
| 4145 | pos = buf; |
| 4146 | end = buf + len; |
| 4147 | |
| 4148 | while (wpa_s) { |
| 4149 | res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname); |
| 4150 | if (res < 0 || res >= end - pos) { |
| 4151 | *pos = '\0'; |
| 4152 | break; |
| 4153 | } |
| 4154 | pos += res; |
| 4155 | wpa_s = wpa_s->next; |
| 4156 | } |
| 4157 | return pos - buf; |
| 4158 | } |
| 4159 | |
| 4160 | |
| 4161 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, |
| 4162 | char *buf, size_t *resp_len) |
| 4163 | { |
| 4164 | char *reply; |
| 4165 | const int reply_size = 2048; |
| 4166 | int reply_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4167 | int level = MSG_DEBUG; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4168 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4169 | if (os_strcmp(buf, "PING") == 0) |
| 4170 | level = MSG_EXCESSIVE; |
| 4171 | wpa_hexdump_ascii(level, "RX global ctrl_iface", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4172 | (const u8 *) buf, os_strlen(buf)); |
| 4173 | |
| 4174 | reply = os_malloc(reply_size); |
| 4175 | if (reply == NULL) { |
| 4176 | *resp_len = 1; |
| 4177 | return NULL; |
| 4178 | } |
| 4179 | |
| 4180 | os_memcpy(reply, "OK\n", 3); |
| 4181 | reply_len = 3; |
| 4182 | |
| 4183 | if (os_strcmp(buf, "PING") == 0) { |
| 4184 | os_memcpy(reply, "PONG\n", 5); |
| 4185 | reply_len = 5; |
| 4186 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { |
| 4187 | if (wpa_supplicant_global_iface_add(global, buf + 14)) |
| 4188 | reply_len = -1; |
| 4189 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { |
| 4190 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) |
| 4191 | reply_len = -1; |
| 4192 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
| 4193 | reply_len = wpa_supplicant_global_iface_list( |
| 4194 | global, reply, reply_size); |
| 4195 | } else if (os_strcmp(buf, "INTERFACES") == 0) { |
| 4196 | reply_len = wpa_supplicant_global_iface_interfaces( |
| 4197 | global, reply, reply_size); |
| 4198 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
| 4199 | wpa_supplicant_terminate_proc(global); |
| 4200 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
| 4201 | wpas_notify_suspend(global); |
| 4202 | } else if (os_strcmp(buf, "RESUME") == 0) { |
| 4203 | wpas_notify_resume(global); |
| 4204 | } else { |
| 4205 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 4206 | reply_len = 16; |
| 4207 | } |
| 4208 | |
| 4209 | if (reply_len < 0) { |
| 4210 | os_memcpy(reply, "FAIL\n", 5); |
| 4211 | reply_len = 5; |
| 4212 | } |
| 4213 | |
| 4214 | *resp_len = reply_len; |
| 4215 | return reply; |
| 4216 | } |