219
223
char *buf, size_t buflen)
221
225
char *pos, *end, tmp[30];
226
int res, verbose, ret;
224
228
verbose = strcmp(params, "-VERBOSE") == 0;
226
230
end = buf + buflen;
227
231
if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
228
232
struct wpa_ssid *ssid = wpa_s->current_ssid;
229
pos += snprintf(pos, end - pos, "bssid=" MACSTR "\n",
230
MAC2STR(wpa_s->bssid));
233
ret = snprintf(pos, end - pos, "bssid=" MACSTR "\n",
234
MAC2STR(wpa_s->bssid));
235
if (ret < 0 || ret >= end - pos)
232
pos += snprintf(pos, end - pos,
234
wpa_ssid_txt(ssid->ssid,
238
pos += snprintf(pos, end - pos, "id_str=%s\n",
239
u8 *_ssid = ssid->ssid;
240
size_t ssid_len = ssid->ssid_len;
241
u8 ssid_buf[MAX_SSID_LEN];
243
int res = wpa_drv_get_ssid(wpa_s, ssid_buf);
250
ret = snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
251
wpa_ssid_txt(_ssid, ssid_len),
253
if (ret < 0 || ret >= end - pos)
258
ret = snprintf(pos, end - pos, "id_str=%s\n",
260
if (ret < 0 || ret >= end - pos)
242
266
pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
244
pos += snprintf(pos, end - pos, "wpa_state=%s\n",
245
wpa_supplicant_state_txt(wpa_s->wpa_state));
268
ret = snprintf(pos, end - pos, "wpa_state=%s\n",
269
wpa_supplicant_state_txt(wpa_s->wpa_state));
270
if (ret < 0 || ret >= end - pos)
248
l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0)
249
pos += snprintf(pos, end - pos, "ip_address=%s\n", tmp);
275
l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
276
ret = snprintf(pos, end - pos, "ip_address=%s\n", tmp);
277
if (ret < 0 || ret >= end - pos)
251
282
if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
252
283
wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
307
338
struct wpa_ssid *ssid;
310
342
end = buf + buflen;
311
pos += snprintf(pos, end - pos, "network id / ssid / bssid / flags\n");
343
ret = snprintf(pos, end - pos, "network id / ssid / bssid / flags\n");
344
if (ret < 0 || ret >= end - pos)
313
348
ssid = wpa_s->conf->ssid;
315
pos += snprintf(pos, end - pos, "%d\t%s",
317
wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
350
ret = snprintf(pos, end - pos, "%d\t%s",
352
wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
353
if (ret < 0 || ret >= end - pos)
318
356
if (ssid->bssid_set) {
319
pos += snprintf(pos, end - pos, "\t" MACSTR,
320
MAC2STR(ssid->bssid));
357
ret = snprintf(pos, end - pos, "\t" MACSTR,
358
MAC2STR(ssid->bssid));
322
pos += snprintf(pos, end - pos, "\tany");
360
ret = snprintf(pos, end - pos, "\tany");
324
pos += snprintf(pos, end - pos, "\t%s%s",
325
ssid == wpa_s->current_ssid ? "[CURRENT]" : "",
326
ssid->disabled ? "[DISABLED]" : "");
327
pos += snprintf(pos, end - pos, "\n");
362
if (ret < 0 || ret >= end - pos)
365
ret = snprintf(pos, end - pos, "\t%s%s",
366
ssid == wpa_s->current_ssid ? "[CURRENT]" : "",
367
ssid->disabled ? "[DISABLED]" : "");
368
if (ret < 0 || ret >= end - pos)
371
ret = snprintf(pos, end - pos, "\n");
372
if (ret < 0 || ret >= end - pos)
329
376
ssid = ssid->next;
336
383
static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
339
pos += snprintf(pos, end - pos, "-");
386
ret = snprintf(pos, end - pos, "-");
387
if (ret < 0 || ret >= end - pos)
340
390
if (cipher & WPA_CIPHER_NONE) {
341
pos += snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
391
ret = snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
392
if (ret < 0 || ret >= end - pos)
344
397
if (cipher & WPA_CIPHER_WEP40) {
345
pos += snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
398
ret = snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
399
if (ret < 0 || ret >= end - pos)
348
404
if (cipher & WPA_CIPHER_WEP104) {
349
pos += snprintf(pos, end - pos, "%sWEP104", first ? "" : "+");
405
ret = snprintf(pos, end - pos, "%sWEP104", first ? "" : "+");
406
if (ret < 0 || ret >= end - pos)
352
411
if (cipher & WPA_CIPHER_TKIP) {
353
pos += snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
412
ret = snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
413
if (ret < 0 || ret >= end - pos)
356
418
if (cipher & WPA_CIPHER_CCMP) {
357
pos += snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
419
ret = snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
420
if (ret < 0 || ret >= end - pos)
365
430
const u8 *ie, size_t ie_len)
367
432
struct wpa_ie_data data;
370
pos += snprintf(pos, end - pos, "[%s-", proto);
435
ret = snprintf(pos, end - pos, "[%s-", proto);
436
if (ret < 0 || ret >= end - pos)
372
440
if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
373
pos += snprintf(pos, end - pos, "?]");
441
ret = snprintf(pos, end - pos, "?]");
442
if (ret < 0 || ret >= end - pos)
378
449
if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
379
pos += snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
450
ret = snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
451
if (ret < 0 || ret >= end - pos)
382
456
if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
383
pos += snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
457
ret = snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
458
if (ret < 0 || ret >= end - pos)
386
463
if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
387
pos += snprintf(pos, end - pos, "%sNone", first ? "" : "+");
464
ret = snprintf(pos, end - pos, "%sNone", first ? "" : "+");
465
if (ret < 0 || ret >= end - pos)
391
471
pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
393
if (data.capabilities & WPA_CAPABILITY_PREAUTH)
394
pos += snprintf(pos, end - pos, "-preauth");
473
if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
474
ret = snprintf(pos, end - pos, "-preauth");
475
if (ret < 0 || ret >= end - pos)
396
pos += snprintf(pos, end - pos, "]");
480
ret = snprintf(pos, end - pos, "]");
481
if (ret < 0 || ret >= end - pos)
414
501
end = buf + buflen;
415
pos += snprintf(pos, end - pos, "bssid / frequency / signal level / "
502
ret = snprintf(pos, end - pos, "bssid / frequency / signal level / "
504
if (ret < 0 || ret >= end - pos)
418
508
for (i = 0; i < wpa_s->num_scan_results; i++) {
419
509
res = &wpa_s->scan_results[i];
420
pos += snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
421
MAC2STR(res->bssid), res->freq, res->level);
510
ret = snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
511
MAC2STR(res->bssid), res->freq, res->level);
512
if (ret < 0 || ret >= end - pos)
422
515
if (res->wpa_ie_len) {
423
516
pos = wpa_supplicant_ie_txt(pos, end, "WPA",
430
523
res->rsn_ie_len);
432
525
if (!res->wpa_ie_len && !res->rsn_ie_len &&
433
res->caps & IEEE80211_CAP_PRIVACY)
434
pos += snprintf(pos, end - pos, "[WEP]");
435
if (res->caps & IEEE80211_CAP_IBSS)
436
pos += snprintf(pos, end - pos, "[IBSS]");
438
pos += snprintf(pos, end - pos, "\t%s",
439
wpa_ssid_txt(res->ssid, res->ssid_len));
441
pos += snprintf(pos, end - pos, "\n");
526
res->caps & IEEE80211_CAP_PRIVACY) {
527
ret = snprintf(pos, end - pos, "[WEP]");
528
if (ret < 0 || ret >= end - pos)
532
if (res->caps & IEEE80211_CAP_IBSS) {
533
ret = snprintf(pos, end - pos, "[IBSS]");
534
if (ret < 0 || ret >= end - pos)
539
ret = snprintf(pos, end - pos, "\t%s",
540
wpa_ssid_txt(res->ssid, res->ssid_len));
541
if (ret < 0 || ret >= end - pos)
545
ret = snprintf(pos, end - pos, "\n");
546
if (ret < 0 || ret >= end - pos)
444
551
return pos - buf;
697
809
static int wpa_supplicant_ctrl_iface_get_capability(
698
struct wpa_supplicant *wpa_s, const char *field, char *buf,
810
struct wpa_supplicant *wpa_s, const char *_field, char *buf,
701
813
struct wpa_driver_capa capa;
705
wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'", field);
814
int res, first = 1, ret;
815
char *pos, *end, *strict;
818
/* Determine whether or not strict checking was requested */
819
snprintf(field, sizeof(field), "%s", _field);
820
field[sizeof(field) - 1] = '\0';
821
strict = strchr(field, ' ');
822
if (strict != NULL) {
824
if (strcmp(strict, "strict") != 0) {
830
wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
831
field, strict ? strict : "");
707
833
if (strcmp(field, "eap") == 0) {
708
834
return eap_get_names(buf, buflen);
714
840
end = pos + buflen;
716
842
if (strcmp(field, "pairwise") == 0) {
718
return snprintf(buf, buflen, "CCMP TKIP NONE");
846
ret = snprintf(buf, buflen, "CCMP TKIP NONE");
847
if (ret < 0 || (size_t) ret >= buflen)
720
852
if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
721
pos += snprintf(pos, end - pos, "%sCCMP",
853
ret = snprintf(pos, end - pos, "%sCCMP",
855
if (ret < 0 || ret >= end - pos)
726
861
if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
727
pos += snprintf(pos, end - pos, "%sTKIP",
862
ret = snprintf(pos, end - pos, "%sTKIP",
864
if (ret < 0 || ret >= end - pos)
732
870
if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
733
pos += snprintf(pos, end - pos, "%sNONE",
871
ret = snprintf(pos, end - pos, "%sNONE",
873
if (ret < 0 || ret >= end - pos)
741
882
if (strcmp(field, "group") == 0) {
743
return snprintf(buf, buflen, "CCMP TKIP WEP104 WEP40");
886
ret = snprintf(buf, buflen, "CCMP TKIP WEP104 WEP40");
887
if (ret < 0 || (size_t) ret >= buflen)
745
892
if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
746
pos += snprintf(pos, end - pos, "%sCCMP",
893
ret = snprintf(pos, end - pos, "%sCCMP",
895
if (ret < 0 || ret >= end - pos)
751
901
if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
752
pos += snprintf(pos, end - pos, "%sTKIP",
902
ret = snprintf(pos, end - pos, "%sTKIP",
904
if (ret < 0 || ret >= end - pos)
757
910
if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
758
pos += snprintf(pos, end - pos, "%sWEP104",
911
ret = snprintf(pos, end - pos, "%sWEP104",
913
if (ret < 0 || ret >= end - pos)
763
919
if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
764
pos += snprintf(pos, end - pos, "%sWEP40",
920
ret = snprintf(pos, end - pos, "%sWEP40",
922
if (ret < 0 || ret >= end - pos)
772
931
if (strcmp(field, "key_mgmt") == 0) {
774
return snprintf(buf, buflen, "WPA-PSK WPA-EAP "
775
"IEEE8021X WPA-NONE NONE");
935
ret = snprintf(buf, buflen, "WPA-PSK WPA-EAP "
936
"IEEE8021X WPA-NONE NONE");
937
if (ret < 0 || (size_t) ret >= buflen)
778
pos += snprintf(pos, end - pos, "NONE IEEE8021X");
942
ret = snprintf(pos, end - pos, "NONE IEEE8021X");
943
if (ret < 0 || ret >= end - pos)
780
947
if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
781
WPA_DRIVER_CAPA_KEY_MGMT_WPA2))
782
pos += snprintf(pos, end - pos, " WPA-EAP");
948
WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
949
ret = snprintf(pos, end - pos, " WPA-EAP");
950
if (ret < 0 || ret >= end - pos)
784
955
if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
785
WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK))
786
pos += snprintf(pos, end - pos, " WPA-PSK");
956
WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
957
ret = snprintf(pos, end - pos, " WPA-PSK");
958
if (ret < 0 || ret >= end - pos)
788
if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE)
789
pos += snprintf(pos, end - pos, " WPA-NONE");
963
if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
964
ret = snprintf(pos, end - pos, " WPA-NONE");
965
if (ret < 0 || ret >= end - pos)
791
970
return pos - buf;
794
973
if (strcmp(field, "proto") == 0) {
796
return snprintf(buf, buflen, "RSN WPA");
977
ret = snprintf(buf, buflen, "RSN WPA");
978
if (ret < 0 || (size_t) ret >= buflen)
798
983
if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
799
984
WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
800
pos += snprintf(pos, end - pos, "%sRSN",
985
ret = snprintf(pos, end - pos, "%sRSN",
987
if (ret < 0 || ret >= end - pos)
805
993
if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
806
994
WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
807
pos += snprintf(pos, end - pos, "%sWPA",
995
ret = snprintf(pos, end - pos, "%sWPA",
997
if (ret < 0 || ret >= end - pos)
815
1006
if (strcmp(field, "auth_alg") == 0) {
817
return snprintf(buf, buflen, "OPEN SHARED LEAP");
1010
ret = snprintf(buf, buflen, "OPEN SHARED LEAP");
1011
if (ret < 0 || (size_t) ret >= buflen)
819
1016
if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
820
pos += snprintf(pos, end - pos, "%sOPEN",
1017
ret = snprintf(pos, end - pos, "%sOPEN",
1019
if (ret < 0 || ret >= end - pos)
825
1025
if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
826
pos += snprintf(pos, end - pos, "%sSHARED",
1026
ret = snprintf(pos, end - pos, "%sSHARED",
1028
if (ret < 0 || ret >= end - pos)
831
1034
if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
832
pos += snprintf(pos, end - pos, "%sLEAP",
1035
ret = snprintf(pos, end - pos, "%sLEAP",
1037
if (ret < 0 || ret >= end - pos)
981
1187
} else if (strncmp(buf, "AP_SCAN ", 8) == 0) {
982
1188
if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
1190
} else if (strcmp(buf, "INTERFACES") == 0) {
1191
reply_len = wpa_supplicant_global_iface_interfaces(
1192
wpa_s->global, reply, reply_size);
985
1194
memcpy(reply, "UNKNOWN COMMAND\n", 16);
1302
static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
1307
struct wpa_supplicant *wpa_s;
1309
wpa_s = global->ifaces;
1314
res = snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
1315
if (res < 0 || res >= end - pos) {
1320
wpa_s = wpa_s->next;
1093
1326
char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
1094
1327
char *buf, size_t *resp_len)
1118
1351
} else if (strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
1119
1352
if (wpa_supplicant_global_iface_remove(global, buf + 17))
1120
1353
reply_len = -1;
1354
} else if (strcmp(buf, "INTERFACES") == 0) {
1355
reply_len = wpa_supplicant_global_iface_interfaces(
1356
global, reply, reply_size);
1122
1358
memcpy(reply, "UNKNOWN COMMAND\n", 16);
1123
1359
reply_len = 16;